From 37ae554f9f2bf67c54639751a4989ac0d5e231b1 Mon Sep 17 00:00:00 2001 From: Joseph Aquino Date: Tue, 30 Dec 2025 18:25:28 -0500 Subject: [PATCH] start using submodules --- flac/AUTHORS | 60 - flac/COPYING.FDL | 397 - flac/COPYING.GPL | 339 - flac/COPYING.LGPL | 504 - flac/COPYING.Xiph | 29 - flac/README.md | 278 - flac/build-flac.lua | 66 - flac/include/FLAC++/Makefile.am | 39 - flac/include/FLAC++/all.h | 49 - flac/include/FLAC++/decoder.h | 248 - flac/include/FLAC++/encoder.h | 265 - flac/include/FLAC++/export.h | 100 - flac/include/FLAC++/metadata.h | 1234 - flac/include/FLAC/Makefile.am | 43 - flac/include/FLAC/all.h | 450 - flac/include/FLAC/assert.h | 51 - flac/include/FLAC/callback.h | 190 - flac/include/FLAC/export.h | 115 - flac/include/FLAC/format.h | 1032 - flac/include/FLAC/metadata.h | 2234 - flac/include/FLAC/ordinals.h | 55 - flac/include/FLAC/stream_decoder.h | 1584 - flac/include/FLAC/stream_encoder.h | 1837 - flac/include/Makefile.am | 23 - flac/include/share/Makefile.am | 17 - flac/include/share/alloc.h | 318 - flac/include/share/compat.h | 240 - flac/include/share/endswap.h | 84 - flac/include/share/getopt.h | 184 - flac/include/share/grabbag.h | 30 - flac/include/share/grabbag/Makefile.am | 8 - flac/include/share/grabbag/cuesheet.h | 43 - flac/include/share/grabbag/file.h | 65 - flac/include/share/grabbag/picture.h | 54 - flac/include/share/grabbag/replaygain.h | 73 - flac/include/share/grabbag/seektable.h | 39 - flac/include/share/macros.h | 45 - flac/include/share/private.h | 54 - flac/include/share/replaygain_analysis.h | 59 - flac/include/share/replaygain_synthesis.h | 52 - flac/include/share/safe_str.h | 71 - flac/include/share/utf8.h | 25 - flac/include/share/win_utf8_io.h | 71 - flac/include/test_libs_common/Makefile.am | 5 - .../test_libs_common/file_utils_flac.h | 36 - .../include/test_libs_common/metadata_utils.h | 71 - flac/m4/Makefile.am | 26 - flac/m4/add_cflags.m4 | 15 - flac/m4/add_cxxflags.m4 | 16 - flac/m4/ax_add_fortify_source.m4 | 53 - flac/m4/ax_check_compile_flag.m4 | 53 - flac/m4/ax_check_enable_debug.m4 | 124 - flac/m4/bswap.m4 | 66 - flac/m4/c_attribute.m4 | 18 - flac/m4/clang.m4 | 28 - flac/m4/codeset.m4 | 23 - flac/m4/endian.m4 | 169 - flac/m4/gcc_version.m4 | 34 - flac/m4/iconv.m4 | 268 - flac/m4/lib-ld.m4 | 119 - flac/m4/lib-link.m4 | 777 - flac/m4/lib-prefix.m4 | 224 - flac/m4/ogg.m4 | 114 - flac/m4/really_gcc.m4 | 29 - flac/m4/stack_protect.m4 | 67 - flac/man/Makefile.am | 34 - flac/man/flac.md | 760 - flac/man/metaflac.md | 299 - flac/microbench/CMakeLists.txt | 17 - flac/microbench/Makefile.am | 42 - flac/microbench/benchmark_residual.c | 151 - flac/microbench/util.c | 205 - flac/microbench/util.h | 43 - flac/oss-fuzz/Makefile.am | 104 - flac/oss-fuzz/Readme.md | 13 - flac/oss-fuzz/common.h | 2 - flac/oss-fuzz/decoder.cc | 408 - flac/oss-fuzz/empty.cc | 0 flac/oss-fuzz/encoder.cc | 257 - flac/oss-fuzz/encoder_v2.cc | 352 - flac/oss-fuzz/fuzzer_decoder.dict | 6 - flac/oss-fuzz/fuzzer_encoder.dict | 18 - flac/oss-fuzz/fuzzer_reencoder.dict | 6 - flac/oss-fuzz/fuzzer_tool_flac.dict | 19 - .../fuzzing/datasource/datasource.hpp | 190 - flac/oss-fuzz/fuzzing/datasource/id.hpp | 75 - flac/oss-fuzz/fuzzing/exception.hpp | 67 - flac/oss-fuzz/fuzzing/memory.hpp | 96 - flac/oss-fuzz/fuzzing/types.hpp | 158 - flac/oss-fuzz/metadata.cc | 526 - flac/oss-fuzz/reencoder.cc | 304 - .../aiff-with-foreign-metadata-8bps.fuzz | Bin 475 -> 0 bytes .../flac-foreign-metadata-aiff-8bps.fuzz | Bin 684 -> 0 bytes .../flac-foreign-metadata-wav-8bps.fuzz | Bin 715 -> 0 bytes .../replaygain-which-is-not-lossless-ogg.fuzz | Bin 15406 -> 0 bytes .../replaygain-which-is-not-lossless.fuzz | Bin 15852 -> 0 bytes .../wav-with-foreign-metadata-8bps.fuzz | Bin 559 -> 0 bytes flac/oss-fuzz/seek.cc | 195 - flac/oss-fuzz/tool_flac.c | 117 - flac/oss-fuzz/tool_metaflac.c | 136 - flac/src/CMakeLists.txt | 36 - flac/src/Makefile.am | 40 - flac/src/flac/CMakeLists.txt | 25 - flac/src/flac/Makefile.am | 69 - flac/src/flac/analyze.c | 252 - flac/src/flac/analyze.h | 32 - flac/src/flac/decode.c | 1674 - flac/src/flac/decode.h | 73 - flac/src/flac/encode.c | 2852 - flac/src/flac/encode.h | 116 - flac/src/flac/foreign_metadata.c | 952 - flac/src/flac/foreign_metadata.h | 83 - flac/src/flac/iffscan.c | 129 - flac/src/flac/local_string_utils.c | 109 - flac/src/flac/local_string_utils.h | 28 - flac/src/flac/main.c | 2442 - flac/src/flac/utils.c | 439 - flac/src/flac/utils.h | 77 - flac/src/flac/version.rc | 38 - flac/src/flac/vorbiscomment.c | 254 - flac/src/flac/vorbiscomment.h | 27 - flac/src/libFLAC++/CMakeLists.txt | 41 - flac/src/libFLAC++/Makefile.am | 68 - flac/src/libFLAC++/flac++.pc.in | 11 - flac/src/libFLAC++/libFLAC++.m4 | 114 - flac/src/libFLAC++/metadata.cpp | 1745 - flac/src/libFLAC++/stream_decoder.cpp | 394 - flac/src/libFLAC++/stream_encoder.cpp | 519 - flac/src/libFLAC++/version.rc | 40 - flac/src/libFLAC/CMakeLists.txt | 126 - flac/src/libFLAC/Makefile.am | 123 - flac/src/libFLAC/bitmath.c | 73 - flac/src/libFLAC/bitreader.c | 1052 - flac/src/libFLAC/bitwriter.c | 955 - flac/src/libFLAC/cpu.c | 255 - flac/src/libFLAC/crc.c | 436 - .../bitreader_read_rice_signed_block.c | 143 - .../lpc_compute_autocorrelation_intrin.c | 14 - .../lpc_compute_autocorrelation_intrin_neon.c | 70 - .../lpc_compute_autocorrelation_intrin_sse2.c | 81 - flac/src/libFLAC/fixed.c | 667 - flac/src/libFLAC/fixed_intrin_avx2.c | 343 - flac/src/libFLAC/fixed_intrin_sse2.c | 194 - flac/src/libFLAC/fixed_intrin_sse42.c | 223 - flac/src/libFLAC/fixed_intrin_ssse3.c | 179 - flac/src/libFLAC/flac.pc.in | 12 - flac/src/libFLAC/float.c | 302 - flac/src/libFLAC/format.c | 608 - flac/src/libFLAC/include/Makefile.am | 32 - flac/src/libFLAC/include/private/Makefile.am | 53 - flac/src/libFLAC/include/private/all.h | 50 - flac/src/libFLAC/include/private/bitmath.h | 210 - flac/src/libFLAC/include/private/bitreader.h | 101 - flac/src/libFLAC/include/private/bitwriter.h | 104 - flac/src/libFLAC/include/private/cpu.h | 198 - flac/src/libFLAC/include/private/crc.h | 60 - flac/src/libFLAC/include/private/fixed.h | 117 - flac/src/libFLAC/include/private/float.h | 95 - flac/src/libFLAC/include/private/format.h | 47 - flac/src/libFLAC/include/private/lpc.h | 238 - flac/src/libFLAC/include/private/macros.h | 74 - flac/src/libFLAC/include/private/md5.h | 50 - flac/src/libFLAC/include/private/memory.h | 58 - flac/src/libFLAC/include/private/metadata.h | 46 - .../include/private/ogg_decoder_aspect.h | 80 - .../include/private/ogg_encoder_aspect.h | 63 - flac/src/libFLAC/include/private/ogg_helper.h | 44 - .../src/libFLAC/include/private/ogg_mapping.h | 64 - .../libFLAC/include/private/stream_encoder.h | 67 - .../include/private/stream_encoder_framing.h | 46 - flac/src/libFLAC/include/private/window.h | 74 - .../src/libFLAC/include/protected/Makefile.am | 35 - flac/src/libFLAC/include/protected/all.h | 39 - .../include/protected/stream_decoder.h | 60 - .../include/protected/stream_encoder.h | 124 - flac/src/libFLAC/libFLAC.m4 | 114 - flac/src/libFLAC/lpc.c | 1629 - flac/src/libFLAC/lpc_intrin_avx2.c | 1122 - flac/src/libFLAC/lpc_intrin_fma.c | 73 - flac/src/libFLAC/lpc_intrin_neon.c | 1273 - flac/src/libFLAC/lpc_intrin_sse2.c | 966 - flac/src/libFLAC/lpc_intrin_sse41.c | 950 - flac/src/libFLAC/md5.c | 517 - flac/src/libFLAC/memory.c | 219 - flac/src/libFLAC/metadata_iterators.c | 3554 - flac/src/libFLAC/metadata_object.c | 2018 - flac/src/libFLAC/ogg_decoder_aspect.c | 251 - flac/src/libFLAC/ogg_encoder_aspect.c | 228 - flac/src/libFLAC/ogg_helper.c | 210 - flac/src/libFLAC/ogg_mapping.c | 48 - flac/src/libFLAC/stream_decoder.c | 3731 - flac/src/libFLAC/stream_encoder.c | 4738 - flac/src/libFLAC/stream_encoder_framing.c | 594 - flac/src/libFLAC/stream_encoder_intrin_avx2.c | 146 - flac/src/libFLAC/stream_encoder_intrin_sse2.c | 159 - .../src/libFLAC/stream_encoder_intrin_ssse3.c | 148 - flac/src/libFLAC/version.rc | 40 - flac/src/libFLAC/window.c | 308 - flac/src/metaflac/CMakeLists.txt | 18 - flac/src/metaflac/Makefile.am | 65 - flac/src/metaflac/main.c | 75 - flac/src/metaflac/operations.c | 823 - flac/src/metaflac/operations.h | 27 - flac/src/metaflac/operations_shorthand.h | 26 - .../metaflac/operations_shorthand_cuesheet.c | 226 - .../metaflac/operations_shorthand_picture.c | 184 - .../metaflac/operations_shorthand_seektable.c | 220 - .../operations_shorthand_streaminfo.c | 127 - .../operations_shorthand_vorbiscomment.c | 430 - flac/src/metaflac/options.c | 1146 - flac/src/metaflac/options.h | 221 - flac/src/metaflac/usage.c | 349 - flac/src/metaflac/usage.h | 26 - flac/src/metaflac/utils.c | 282 - flac/src/metaflac/utils.h | 47 - flac/src/metaflac/version.rc | 38 - flac/src/share/Makefile.am | 73 - flac/src/share/README | 5 - flac/src/share/getopt/CMakeLists.txt | 13 - flac/src/share/getopt/getopt.c | 1053 - flac/src/share/getopt/getopt1.c | 189 - flac/src/share/grabbag/CMakeLists.txt | 14 - flac/src/share/grabbag/alloc.c | 48 - flac/src/share/grabbag/cuesheet.c | 681 - flac/src/share/grabbag/file.c | 207 - flac/src/share/grabbag/picture.c | 515 - flac/src/share/grabbag/replaygain.c | 669 - flac/src/share/grabbag/seektable.c | 105 - flac/src/share/grabbag/snprintf.c | 101 - .../share/replaygain_analysis/CMakeLists.txt | 2 - .../replaygain_analysis/replaygain_analysis.c | 575 - .../share/replaygain_synthesis/CMakeLists.txt | 2 - .../replaygain_synthesis.c | 429 - flac/src/share/utf8/CMakeLists.txt | 8 - flac/src/share/utf8/charmaps.h | 57 - flac/src/share/utf8/charset.c | 534 - flac/src/share/utf8/charset.h | 72 - flac/src/share/utf8/charset_test.c | 263 - flac/src/share/utf8/iconvert.c | 257 - flac/src/share/utf8/iconvert.h | 49 - flac/src/share/utf8/makemap.c | 81 - flac/src/share/utf8/utf8.c | 202 - flac/src/share/win_utf8_io/win_utf8_io.c | 398 - flac/src/test_grabbag/CMakeLists.txt | 2 - flac/src/test_grabbag/Makefile.am | 22 - flac/src/test_grabbag/cuesheet/CMakeLists.txt | 5 - flac/src/test_grabbag/cuesheet/Makefile.am | 37 - flac/src/test_grabbag/cuesheet/main.c | 147 - flac/src/test_grabbag/picture/CMakeLists.txt | 5 - flac/src/test_grabbag/picture/Makefile.am | 37 - flac/src/test_grabbag/picture/main.c | 222 - flac/src/test_libFLAC++/CMakeLists.txt | 10 - flac/src/test_libFLAC++/Makefile.am | 50 - flac/src/test_libFLAC++/decoders.cpp | 1179 - flac/src/test_libFLAC++/decoders.h | 25 - flac/src/test_libFLAC++/encoders.cpp | 576 - flac/src/test_libFLAC++/encoders.h | 25 - flac/src/test_libFLAC++/main.cpp | 42 - flac/src/test_libFLAC++/metadata.cpp | 41 - flac/src/test_libFLAC++/metadata.h | 25 - flac/src/test_libFLAC++/metadata_manip.cpp | 2241 - flac/src/test_libFLAC++/metadata_object.cpp | 2099 - flac/src/test_libFLAC/CMakeLists.txt | 25 - flac/src/test_libFLAC/Makefile.am | 63 - flac/src/test_libFLAC/bitreader.c | 355 - flac/src/test_libFLAC/bitreader.h | 27 - flac/src/test_libFLAC/bitwriter.c | 688 - flac/src/test_libFLAC/bitwriter.h | 27 - flac/src/test_libFLAC/crc.c | 274 - flac/src/test_libFLAC/crc.h | 26 - flac/src/test_libFLAC/decoders.c | 1054 - flac/src/test_libFLAC/decoders.h | 27 - flac/src/test_libFLAC/encoders.c | 530 - flac/src/test_libFLAC/encoders.h | 27 - flac/src/test_libFLAC/endswap.c | 111 - flac/src/test_libFLAC/endswap.h | 26 - flac/src/test_libFLAC/format.c | 260 - flac/src/test_libFLAC/format.h | 27 - flac/src/test_libFLAC/main.c | 64 - flac/src/test_libFLAC/matrix | 69 - flac/src/test_libFLAC/md5.c | 221 - flac/src/test_libFLAC/md5.h | 26 - flac/src/test_libFLAC/metadata.c | 41 - flac/src/test_libFLAC/metadata.h | 29 - flac/src/test_libFLAC/metadata_manip.c | 2146 - flac/src/test_libFLAC/metadata_object.c | 2291 - flac/src/test_libs_common/CMakeLists.txt | 4 - flac/src/test_libs_common/Makefile.am | 29 - flac/src/test_libs_common/README | 2 - flac/src/test_libs_common/file_utils_flac.c | 155 - flac/src/test_libs_common/metadata_utils.c | 636 - flac/src/test_seeking/CMakeLists.txt | 5 - flac/src/test_seeking/Makefile.am | 39 - flac/src/test_seeking/main.c | 473 - flac/src/test_streams/CMakeLists.txt | 2 - flac/src/test_streams/Makefile.am | 29 - flac/src/test_streams/main.c | 1398 - flac/src/utils/Makefile.am | 19 - flac/src/utils/flacdiff/CMakeLists.txt | 5 - flac/src/utils/flacdiff/Makefile.am | 21 - flac/src/utils/flacdiff/main.cpp | 230 - flac/src/utils/flactimer/CMakeLists.txt | 2 - flac/src/utils/flactimer/Makefile.am | 21 - flac/src/utils/flactimer/main.cpp | 175 - flac/src/utils/loudness/loudness.sci | 115 - freetype/LICENSE.TXT | 46 - freetype/README | 107 - freetype/README.git | 102 - freetype/build-freetype.lua | 96 - freetype/builds/amiga/README | 110 - .../builds/amiga/include/config/ftconfig.h | 55 - .../builds/amiga/include/config/ftmodule.h | 158 - freetype/builds/amiga/makefile.os4 | 297 - freetype/builds/amiga/smakefile | 299 - freetype/builds/amiga/src/base/ftdebug.c | 348 - freetype/builds/amiga/src/base/ftsystem.c | 530 - freetype/builds/ansi/ansi-def.mk | 77 - freetype/builds/ansi/ansi.mk | 21 - freetype/builds/atari/ATARI.H | 20 - freetype/builds/atari/FNames.SIC | 37 - freetype/builds/atari/FREETYPE.PRJ | 32 - freetype/builds/atari/README.TXT | 51 - freetype/builds/atari/deflinejoiner.awk | 181 - freetype/builds/atari/gen-purec-patch.sh | 40 - freetype/builds/beos/beos-def.mk | 79 - freetype/builds/beos/beos.mk | 19 - freetype/builds/beos/detect.mk | 41 - freetype/builds/cmake/FindBrotliDec.cmake | 52 - freetype/builds/cmake/FindHarfBuzz.cmake | 203 - freetype/builds/cmake/iOS.cmake | 270 - freetype/builds/cmake/testbuild.sh | 157 - freetype/builds/compiler/ansi-cc.mk | 80 - freetype/builds/compiler/bcc-dev.mk | 86 - freetype/builds/compiler/bcc.mk | 86 - freetype/builds/compiler/emx.mk | 77 - freetype/builds/compiler/gcc-dev.mk | 96 - freetype/builds/compiler/gcc.mk | 77 - freetype/builds/compiler/intelc.mk | 85 - freetype/builds/compiler/unix-lcc.mk | 83 - freetype/builds/compiler/visualage.mk | 76 - freetype/builds/compiler/visualc.mk | 82 - freetype/builds/compiler/watcom.mk | 81 - freetype/builds/compiler/win-lcc.mk | 81 - freetype/builds/detect.mk | 128 - freetype/builds/dos/detect.mk | 152 - freetype/builds/dos/dos-def.mk | 48 - freetype/builds/dos/dos-emx.mk | 21 - freetype/builds/dos/dos-gcc.mk | 21 - freetype/builds/dos/dos-wat.mk | 20 - freetype/builds/exports.mk | 80 - freetype/builds/freetype.mk | 385 - freetype/builds/link_dos.mk | 42 - freetype/builds/link_std.mk | 42 - .../builds/mac/FreeType.m68k_cfm.make.txt | 209 - .../builds/mac/FreeType.m68k_far.make.txt | 208 - .../builds/mac/FreeType.ppc_carbon.make.txt | 212 - .../builds/mac/FreeType.ppc_classic.make.txt | 213 - freetype/builds/mac/README | 393 - freetype/builds/mac/ascii2mpw.py | 24 - freetype/builds/mac/freetype-Info.plist | 36 - freetype/builds/mac/ftlib.prj.xml | 1194 - freetype/builds/mac/ftmac.c | 1542 - .../builds/meson/extract_freetype_version.py | 117 - .../builds/meson/extract_libtool_version.py | 115 - .../builds/meson/generate_reference_docs.py | 89 - freetype/builds/meson/parse_modules_cfg.py | 177 - freetype/builds/meson/process_ftoption_h.py | 115 - freetype/builds/modules.mk | 79 - freetype/builds/os2/detect.mk | 81 - freetype/builds/os2/os2-def.mk | 48 - freetype/builds/os2/os2-dev.mk | 30 - freetype/builds/os2/os2-gcc.mk | 26 - freetype/builds/symbian/bld.inf | 72 - freetype/builds/symbian/freetype.mmp | 146 - freetype/builds/toplevel.mk | 317 - freetype/builds/unix/.gitignore | 18 - freetype/builds/unix/ax_compare_version.m4 | 177 - .../builds/unix/ax_prog_python_version.m4 | 66 - freetype/builds/unix/ax_pthread.m4 | 522 - freetype/builds/unix/configure.raw | 1179 - freetype/builds/unix/detect.mk | 99 - freetype/builds/unix/freetype-config.in | 211 - freetype/builds/unix/freetype2.in | 14 - freetype/builds/unix/freetype2.m4 | 194 - freetype/builds/unix/ft-munmap.m4 | 32 - freetype/builds/unix/ftconfig.h.in | 52 - freetype/builds/unix/ftsystem.c | 436 - freetype/builds/unix/install.mk | 102 - freetype/builds/unix/pkg.m4 | 199 - freetype/builds/unix/unix-cc.in | 130 - freetype/builds/unix/unix-def.in | 163 - freetype/builds/unix/unix-dev.mk | 26 - freetype/builds/unix/unix-lcc.mk | 24 - freetype/builds/unix/unix.mk | 62 - freetype/builds/unix/unixddef.mk | 46 - freetype/builds/vms/apinames_vms.bash | 2 - freetype/builds/vms/ftconfig.h | 58 - freetype/builds/vms/ftsystem.c | 328 - freetype/builds/wince/ftdebug.c | 353 - .../builds/wince/vc2005-ce/freetype.vcproj | 878 - freetype/builds/wince/vc2005-ce/index.html | 47 - .../builds/wince/vc2008-ce/freetype.vcproj | 3517 - freetype/builds/wince/vc2008-ce/index.html | 47 - freetype/builds/windows/.gitignore | 5 - freetype/builds/windows/detect.mk | 202 - freetype/builds/windows/ftdebug.c | 698 - freetype/builds/windows/ftsystem.c | 499 - .../builds/windows/vc2010/freetype.user.props | 68 - freetype/builds/windows/vc2010/index.html | 40 - freetype/builds/windows/visualc/freetype.dsp | 354 - freetype/builds/windows/visualc/freetype.dsw | 29 - .../builds/windows/visualc/freetype.vcproj | 587 - freetype/builds/windows/visualc/index.html | 38 - freetype/builds/windows/visualce/freetype.dsp | 391 - freetype/builds/windows/visualce/freetype.dsw | 29 - .../builds/windows/visualce/freetype.vcproj | 3706 - freetype/builds/windows/visualce/index.html | 47 - freetype/builds/windows/w32-bcc.mk | 28 - freetype/builds/windows/w32-bccd.mk | 26 - freetype/builds/windows/w32-dev.mk | 32 - freetype/builds/windows/w32-gcc.mk | 31 - freetype/builds/windows/w32-icc.mk | 28 - freetype/builds/windows/w32-intl.mk | 28 - freetype/builds/windows/w32-lcc.mk | 24 - freetype/builds/windows/w32-mingw32.mk | 33 - freetype/builds/windows/w32-vcc.mk | 28 - freetype/builds/windows/w32-wat.mk | 28 - freetype/builds/windows/win32-def.mk | 51 - freetype/devel/ft2build.h | 41 - freetype/devel/ftoption.h | 1014 - freetype/docs/.gitignore | 12 - freetype/docs/CHANGES | 5686 - freetype/docs/CMAKE | 2 - freetype/docs/CUSTOMIZE | 152 - freetype/docs/DEBUG | 310 - freetype/docs/DOCGUIDE | 298 - freetype/docs/FTL.TXT | 169 - freetype/docs/GPLv2.TXT | 340 - freetype/docs/INSTALL | 114 - freetype/docs/INSTALL.ANY | 157 - freetype/docs/INSTALL.CROSS | 177 - freetype/docs/INSTALL.GNU | 181 - freetype/docs/INSTALL.MAC | 32 - freetype/docs/INSTALL.UNIX | 139 - freetype/docs/INSTALL.VMS | 69 - freetype/docs/MAKEPP | 5 - freetype/docs/PROBLEMS | 90 - freetype/docs/README | 33 - freetype/docs/TODO | 40 - freetype/docs/VERSIONS.TXT | 137 - freetype/docs/formats.txt | 223 - freetype/docs/freetype-config.1 | 146 - freetype/docs/markdown/images/favico.ico | Bin 5430 -> 0 bytes freetype/docs/markdown/javascripts/extra.js | 54 - freetype/docs/markdown/stylesheets/extra.css | 177 - freetype/docs/oldlogs/ChangeLog.20 | 2613 - freetype/docs/oldlogs/ChangeLog.21 | 9438 -- freetype/docs/oldlogs/ChangeLog.210 | 7815 -- freetype/docs/oldlogs/ChangeLog.22 | 2837 - freetype/docs/oldlogs/ChangeLog.23 | 7948 -- freetype/docs/oldlogs/ChangeLog.24 | 6360 -- freetype/docs/oldlogs/ChangeLog.25 | 5161 - freetype/docs/oldlogs/ChangeLog.26 | 5711 - freetype/docs/oldlogs/ChangeLog.27 | 2106 - freetype/docs/oldlogs/ChangeLog.28 | 3136 - freetype/docs/oldlogs/ChangeLog.29 | 2352 - freetype/docs/raster.txt | 635 - freetype/docs/release | 223 - freetype/include/freetype/config/ftconfig.h | 51 - freetype/include/freetype/config/ftheader.h | 836 - freetype/include/freetype/config/ftmodule.h | 33 - freetype/include/freetype/config/ftoption.h | 1014 - freetype/include/freetype/config/ftstdlib.h | 185 - .../include/freetype/config/integer-types.h | 250 - .../include/freetype/config/mac-support.h | 49 - .../include/freetype/config/public-macros.h | 138 - freetype/include/freetype/freetype.h | 5337 - freetype/include/freetype/ftadvanc.h | 188 - freetype/include/freetype/ftbbox.h | 101 - freetype/include/freetype/ftbdf.h | 212 - freetype/include/freetype/ftbitmap.h | 329 - freetype/include/freetype/ftbzip2.h | 102 - freetype/include/freetype/ftcache.h | 1087 - freetype/include/freetype/ftchapters.h | 168 - freetype/include/freetype/ftcid.h | 167 - freetype/include/freetype/ftcolor.h | 1667 - freetype/include/freetype/ftdriver.h | 1246 - freetype/include/freetype/fterrdef.h | 283 - freetype/include/freetype/fterrors.h | 296 - freetype/include/freetype/ftfntfmt.h | 93 - freetype/include/freetype/ftgasp.h | 143 - freetype/include/freetype/ftglyph.h | 750 - freetype/include/freetype/ftgxval.h | 354 - freetype/include/freetype/ftgzip.h | 151 - freetype/include/freetype/ftimage.h | 1284 - freetype/include/freetype/ftincrem.h | 348 - freetype/include/freetype/ftlcdfil.h | 323 - freetype/include/freetype/ftlist.h | 296 - freetype/include/freetype/ftlogging.h | 184 - freetype/include/freetype/ftlzw.h | 100 - freetype/include/freetype/ftmac.h | 289 - freetype/include/freetype/ftmm.h | 805 - freetype/include/freetype/ftmodapi.h | 807 - freetype/include/freetype/ftmoderr.h | 204 - freetype/include/freetype/ftotval.h | 206 - freetype/include/freetype/ftoutln.h | 588 - freetype/include/freetype/ftparams.h | 218 - freetype/include/freetype/ftpfr.h | 179 - freetype/include/freetype/ftrender.h | 244 - freetype/include/freetype/ftsizes.h | 159 - freetype/include/freetype/ftsnames.h | 272 - freetype/include/freetype/ftstroke.h | 773 - freetype/include/freetype/ftsynth.h | 104 - freetype/include/freetype/ftsystem.h | 350 - freetype/include/freetype/fttrigon.h | 350 - freetype/include/freetype/fttypes.h | 617 - freetype/include/freetype/ftwinfnt.h | 276 - freetype/include/freetype/internal/autohint.h | 234 - .../include/freetype/internal/cffotypes.h | 107 - freetype/include/freetype/internal/cfftypes.h | 416 - .../freetype/internal/compiler-macros.h | 343 - freetype/include/freetype/internal/ftcalc.h | 581 - freetype/include/freetype/internal/ftdebug.h | 442 - freetype/include/freetype/internal/ftdrv.h | 289 - freetype/include/freetype/internal/ftgloadr.h | 147 - freetype/include/freetype/internal/fthash.h | 135 - freetype/include/freetype/internal/ftmemory.h | 398 - .../include/freetype/internal/ftmmtypes.h | 91 - freetype/include/freetype/internal/ftobjs.h | 1238 - freetype/include/freetype/internal/ftpsprop.h | 47 - freetype/include/freetype/internal/ftrfork.h | 245 - freetype/include/freetype/internal/ftserv.h | 495 - freetype/include/freetype/internal/ftstream.h | 570 - freetype/include/freetype/internal/fttrace.h | 172 - freetype/include/freetype/internal/ftvalid.h | 160 - freetype/include/freetype/internal/psaux.h | 1434 - freetype/include/freetype/internal/pshints.h | 699 - .../freetype/internal/services/svbdf.h | 66 - .../freetype/internal/services/svcfftl.h | 90 - .../freetype/internal/services/svcid.h | 69 - .../freetype/internal/services/svfntfmt.h | 55 - .../freetype/internal/services/svgldict.h | 72 - .../freetype/internal/services/svgxval.h | 72 - .../freetype/internal/services/svkern.h | 51 - .../freetype/internal/services/svmetric.h | 131 - .../include/freetype/internal/services/svmm.h | 214 - .../freetype/internal/services/svotval.h | 55 - .../freetype/internal/services/svpfr.h | 65 - .../freetype/internal/services/svpostnm.h | 65 - .../freetype/internal/services/svprop.h | 66 - .../freetype/internal/services/svpscmap.h | 145 - .../freetype/internal/services/svpsinfo.h | 86 - .../freetype/internal/services/svsfnt.h | 88 - .../freetype/internal/services/svttcmap.h | 90 - .../freetype/internal/services/svtteng.h | 53 - .../freetype/internal/services/svttglyf.h | 56 - .../freetype/internal/services/svwinfnt.h | 50 - freetype/include/freetype/internal/sfnt.h | 1092 - .../include/freetype/internal/svginterface.h | 46 - freetype/include/freetype/internal/t1types.h | 259 - freetype/include/freetype/internal/tttypes.h | 1741 - .../include/freetype/internal/wofftypes.h | 312 - freetype/include/freetype/otsvg.h | 336 - freetype/include/freetype/t1tables.h | 793 - freetype/include/freetype/ttnameid.h | 1235 - freetype/include/freetype/tttables.h | 855 - freetype/include/freetype/tttags.h | 124 - freetype/include/ft2build.h | 42 - freetype/src/autofit/afblue.c | 779 - freetype/src/autofit/afblue.cin | 39 - freetype/src/autofit/afblue.dat | 1121 - freetype/src/autofit/afblue.h | 429 - freetype/src/autofit/afblue.hin | 146 - freetype/src/autofit/afcjk.c | 2383 - freetype/src/autofit/afcjk.h | 141 - freetype/src/autofit/afcover.h | 105 - freetype/src/autofit/afdummy.c | 77 - freetype/src/autofit/afdummy.h | 40 - freetype/src/autofit/aferrors.h | 42 - freetype/src/autofit/afglobal.c | 513 - freetype/src/autofit/afglobal.h | 173 - freetype/src/autofit/afhints.c | 1796 - freetype/src/autofit/afhints.h | 467 - freetype/src/autofit/afindic.c | 157 - freetype/src/autofit/afindic.h | 41 - freetype/src/autofit/aflatin.c | 3644 - freetype/src/autofit/aflatin.h | 194 - freetype/src/autofit/afloader.c | 706 - freetype/src/autofit/afloader.h | 91 - freetype/src/autofit/afmodule.c | 527 - freetype/src/autofit/afmodule.h | 55 - freetype/src/autofit/afranges.c | 1072 - freetype/src/autofit/afranges.h | 47 - freetype/src/autofit/afscript.h | 408 - freetype/src/autofit/afshaper.c | 690 - freetype/src/autofit/afshaper.h | 71 - freetype/src/autofit/afstyles.h | 487 - freetype/src/autofit/aftypes.h | 511 - freetype/src/autofit/afws-decl.h | 33 - freetype/src/autofit/afws-iter.h | 31 - freetype/src/autofit/autofit.c | 35 - freetype/src/autofit/ft-hb.c | 115 - freetype/src/autofit/ft-hb.h | 48 - freetype/src/autofit/module.mk | 23 - freetype/src/autofit/rules.mk | 88 - freetype/src/base/ftadvanc.c | 174 - freetype/src/base/ftbase.c | 41 - freetype/src/base/ftbase.h | 82 - freetype/src/base/ftbbox.c | 542 - freetype/src/base/ftbdf.c | 90 - freetype/src/base/ftbitmap.c | 1144 - freetype/src/base/ftcalc.c | 1127 - freetype/src/base/ftcid.c | 117 - freetype/src/base/ftcolor.c | 156 - freetype/src/base/ftdbgmem.c | 971 - freetype/src/base/ftdebug.c | 644 - freetype/src/base/fterrors.c | 45 - freetype/src/base/ftfntfmt.c | 54 - freetype/src/base/ftfstype.c | 61 - freetype/src/base/ftgasp.c | 60 - freetype/src/base/ftgloadr.c | 392 - freetype/src/base/ftglyph.c | 911 - freetype/src/base/ftgxval.c | 141 - freetype/src/base/fthash.c | 338 - freetype/src/base/ftinit.c | 263 - freetype/src/base/ftlcdfil.c | 437 - freetype/src/base/ftmac.c | 1090 - freetype/src/base/ftmm.c | 704 - freetype/src/base/ftobjs.c | 5914 - freetype/src/base/ftotval.c | 90 - freetype/src/base/ftoutln.c | 1118 - freetype/src/base/ftpatent.c | 50 - freetype/src/base/ftpfr.c | 152 - freetype/src/base/ftpsprop.c | 284 - freetype/src/base/ftrfork.c | 934 - freetype/src/base/ftsnames.c | 185 - freetype/src/base/ftstream.c | 872 - freetype/src/base/ftstroke.c | 2403 - freetype/src/base/ftsynth.c | 180 - freetype/src/base/ftsystem.c | 338 - freetype/src/base/fttrigon.c | 517 - freetype/src/base/fttype1.c | 126 - freetype/src/base/ftutil.c | 442 - freetype/src/base/ftver.rc | 61 - freetype/src/base/ftwinfnt.c | 52 - freetype/src/base/md5.c | 291 - freetype/src/base/md5.h | 45 - freetype/src/base/rules.mk | 108 - freetype/src/bdf/README | 152 - freetype/src/bdf/bdf.c | 34 - freetype/src/bdf/bdf.h | 253 - freetype/src/bdf/bdfdrivr.c | 1013 - freetype/src/bdf/bdfdrivr.h | 72 - freetype/src/bdf/bdferror.h | 45 - freetype/src/bdf/bdflib.c | 2387 - freetype/src/bdf/module.mk | 34 - freetype/src/bdf/rules.mk | 84 - freetype/src/bzip2/ftbzip2.c | 535 - freetype/src/bzip2/rules.mk | 64 - freetype/src/cache/ftcache.c | 31 - freetype/src/cache/ftcbasic.c | 638 - freetype/src/cache/ftccache.c | 599 - freetype/src/cache/ftccache.h | 355 - freetype/src/cache/ftccback.h | 93 - freetype/src/cache/ftccmap.c | 323 - freetype/src/cache/ftcerror.h | 42 - freetype/src/cache/ftcglyph.c | 204 - freetype/src/cache/ftcglyph.h | 315 - freetype/src/cache/ftcimage.c | 164 - freetype/src/cache/ftcimage.h | 106 - freetype/src/cache/ftcmanag.c | 696 - freetype/src/cache/ftcmanag.h | 175 - freetype/src/cache/ftcmru.c | 352 - freetype/src/cache/ftcmru.h | 248 - freetype/src/cache/ftcsbits.c | 414 - freetype/src/cache/ftcsbits.h | 91 - freetype/src/cache/rules.mk | 85 - freetype/src/cff/cff.c | 28 - freetype/src/cff/cffcmap.c | 230 - freetype/src/cff/cffcmap.h | 67 - freetype/src/cff/cffdrivr.c | 1263 - freetype/src/cff/cffdrivr.h | 35 - freetype/src/cff/cfferrs.h | 42 - freetype/src/cff/cffgload.c | 762 - freetype/src/cff/cffgload.h | 62 - freetype/src/cff/cffload.c | 2579 - freetype/src/cff/cffload.h | 124 - freetype/src/cff/cffobjs.c | 1204 - freetype/src/cff/cffobjs.h | 84 - freetype/src/cff/cffparse.c | 1513 - freetype/src/cff/cffparse.h | 143 - freetype/src/cff/cfftoken.h | 150 - freetype/src/cff/module.mk | 23 - freetype/src/cff/rules.mk | 75 - freetype/src/cid/ciderrs.h | 41 - freetype/src/cid/cidgload.c | 618 - freetype/src/cid/cidgload.h | 58 - freetype/src/cid/cidload.c | 950 - freetype/src/cid/cidload.h | 52 - freetype/src/cid/cidobjs.c | 543 - freetype/src/cid/cidobjs.h | 154 - freetype/src/cid/cidparse.c | 286 - freetype/src/cid/cidparse.h | 130 - freetype/src/cid/cidriver.c | 274 - freetype/src/cid/cidriver.h | 36 - freetype/src/cid/cidtoken.h | 115 - freetype/src/cid/module.mk | 23 - freetype/src/cid/rules.mk | 73 - freetype/src/cid/type1cid.c | 28 - freetype/src/dlg/dlgwrap.c | 32 - freetype/src/dlg/rules.mk | 70 - freetype/src/gxvalid/README | 532 - freetype/src/gxvalid/gxvalid.c | 46 - freetype/src/gxvalid/gxvalid.h | 107 - freetype/src/gxvalid/gxvbsln.c | 334 - freetype/src/gxvalid/gxvcommn.c | 1747 - freetype/src/gxvalid/gxvcommn.h | 584 - freetype/src/gxvalid/gxverror.h | 51 - freetype/src/gxvalid/gxvfeat.c | 339 - freetype/src/gxvalid/gxvfeat.h | 173 - freetype/src/gxvalid/gxvfgen.c | 484 - freetype/src/gxvalid/gxvjust.c | 721 - freetype/src/gxvalid/gxvkern.c | 920 - freetype/src/gxvalid/gxvlcar.c | 224 - freetype/src/gxvalid/gxvmod.c | 288 - freetype/src/gxvalid/gxvmod.h | 46 - freetype/src/gxvalid/gxvmort.c | 301 - freetype/src/gxvalid/gxvmort.h | 99 - freetype/src/gxvalid/gxvmort0.c | 152 - freetype/src/gxvalid/gxvmort1.c | 260 - freetype/src/gxvalid/gxvmort2.c | 312 - freetype/src/gxvalid/gxvmort4.c | 126 - freetype/src/gxvalid/gxvmort5.c | 234 - freetype/src/gxvalid/gxvmorx.c | 199 - freetype/src/gxvalid/gxvmorx.h | 73 - freetype/src/gxvalid/gxvmorx0.c | 112 - freetype/src/gxvalid/gxvmorx1.c | 278 - freetype/src/gxvalid/gxvmorx2.c | 331 - freetype/src/gxvalid/gxvmorx4.c | 56 - freetype/src/gxvalid/gxvmorx5.c | 226 - freetype/src/gxvalid/gxvopbd.c | 218 - freetype/src/gxvalid/gxvprop.c | 330 - freetype/src/gxvalid/gxvtrak.c | 288 - freetype/src/gxvalid/module.mk | 23 - freetype/src/gxvalid/rules.mk | 98 - freetype/src/gzip/README.freetype | 23 - freetype/src/gzip/adler32.c | 192 - freetype/src/gzip/crc32.c | 1135 - freetype/src/gzip/crc32.h | 9446 -- freetype/src/gzip/ftgzip.c | 805 - freetype/src/gzip/ftzconf.h | 547 - freetype/src/gzip/gzguts.h | 219 - freetype/src/gzip/inffast.c | 323 - freetype/src/gzip/inffast.h | 11 - freetype/src/gzip/inffixed.h | 94 - freetype/src/gzip/inflate.c | 1605 - freetype/src/gzip/inflate.h | 131 - freetype/src/gzip/inftrees.c | 304 - freetype/src/gzip/inftrees.h | 67 - freetype/src/gzip/patches/freetype-zlib.diff | 469 - freetype/src/gzip/rules.mk | 81 - freetype/src/gzip/zlib.h | 1971 - freetype/src/gzip/zutil.c | 334 - freetype/src/gzip/zutil.h | 281 - freetype/src/lzw/ftlzw.c | 415 - freetype/src/lzw/ftzopen.c | 429 - freetype/src/lzw/ftzopen.h | 174 - freetype/src/lzw/rules.mk | 72 - freetype/src/otvalid/module.mk | 23 - freetype/src/otvalid/otvalid.c | 31 - freetype/src/otvalid/otvalid.h | 77 - freetype/src/otvalid/otvbase.c | 345 - freetype/src/otvalid/otvcommn.c | 1099 - freetype/src/otvalid/otvcommn.h | 468 - freetype/src/otvalid/otverror.h | 42 - freetype/src/otvalid/otvgdef.c | 303 - freetype/src/otvalid/otvgpos.c | 1051 - freetype/src/otvalid/otvgpos.h | 36 - freetype/src/otvalid/otvgsub.c | 627 - freetype/src/otvalid/otvjstf.c | 259 - freetype/src/otvalid/otvmath.c | 453 - freetype/src/otvalid/otvmod.c | 281 - freetype/src/otvalid/otvmod.h | 38 - freetype/src/otvalid/rules.mk | 81 - freetype/src/pcf/README | 96 - freetype/src/pcf/module.mk | 34 - freetype/src/pcf/pcf.c | 35 - freetype/src/pcf/pcf.h | 251 - freetype/src/pcf/pcfdrivr.c | 836 - freetype/src/pcf/pcfdrivr.h | 44 - freetype/src/pcf/pcferror.h | 41 - freetype/src/pcf/pcfread.c | 1731 - freetype/src/pcf/pcfread.h | 44 - freetype/src/pcf/pcfutil.c | 119 - freetype/src/pcf/pcfutil.h | 55 - freetype/src/pcf/rules.mk | 82 - freetype/src/pfr/module.mk | 23 - freetype/src/pfr/pfr.c | 29 - freetype/src/pfr/pfrcmap.c | 188 - freetype/src/pfr/pfrcmap.h | 45 - freetype/src/pfr/pfrdrivr.c | 212 - freetype/src/pfr/pfrdrivr.h | 36 - freetype/src/pfr/pfrerror.h | 41 - freetype/src/pfr/pfrgload.c | 849 - freetype/src/pfr/pfrgload.h | 49 - freetype/src/pfr/pfrload.c | 1062 - freetype/src/pfr/pfrload.h | 123 - freetype/src/pfr/pfrobjs.c | 603 - freetype/src/pfr/pfrobjs.h | 96 - freetype/src/pfr/pfrsbit.c | 813 - freetype/src/pfr/pfrsbit.h | 37 - freetype/src/pfr/pfrtypes.h | 331 - freetype/src/pfr/rules.mk | 76 - freetype/src/psaux/afmparse.c | 1094 - freetype/src/psaux/afmparse.h | 88 - freetype/src/psaux/cffdecode.c | 2423 - freetype/src/psaux/cffdecode.h | 63 - freetype/src/psaux/module.mk | 23 - freetype/src/psaux/psarrst.c | 240 - freetype/src/psaux/psarrst.h | 99 - freetype/src/psaux/psaux.c | 40 - freetype/src/psaux/psauxerr.h | 42 - freetype/src/psaux/psauxmod.c | 190 - freetype/src/psaux/psauxmod.h | 60 - freetype/src/psaux/psblues.c | 583 - freetype/src/psaux/psblues.h | 185 - freetype/src/psaux/psconv.c | 610 - freetype/src/psaux/psconv.h | 70 - freetype/src/psaux/pserror.c | 52 - freetype/src/psaux/pserror.h | 120 - freetype/src/psaux/psfixed.h | 94 - freetype/src/psaux/psfont.c | 566 - freetype/src/psaux/psfont.h | 134 - freetype/src/psaux/psft.c | 895 - freetype/src/psaux/psft.h | 167 - freetype/src/psaux/psglue.h | 144 - freetype/src/psaux/pshints.c | 1952 - freetype/src/psaux/pshints.h | 288 - freetype/src/psaux/psintrp.c | 3059 - freetype/src/psaux/psintrp.h | 83 - freetype/src/psaux/psobjs.c | 2562 - freetype/src/psaux/psobjs.h | 312 - freetype/src/psaux/psread.c | 112 - freetype/src/psaux/psread.h | 68 - freetype/src/psaux/psstack.c | 329 - freetype/src/psaux/psstack.h | 122 - freetype/src/psaux/pstypes.h | 77 - freetype/src/psaux/rules.mk | 89 - freetype/src/psaux/t1cmap.c | 393 - freetype/src/psaux/t1cmap.h | 104 - freetype/src/psaux/t1decode.c | 2159 - freetype/src/psaux/t1decode.h | 73 - freetype/src/pshinter/module.mk | 23 - freetype/src/pshinter/pshalgo.c | 2191 - freetype/src/pshinter/pshalgo.h | 233 - freetype/src/pshinter/pshglob.c | 795 - freetype/src/pshinter/pshglob.h | 196 - freetype/src/pshinter/pshinter.c | 27 - freetype/src/pshinter/pshmod.c | 125 - freetype/src/pshinter/pshmod.h | 38 - freetype/src/pshinter/pshnterr.h | 41 - freetype/src/pshinter/pshrec.c | 1224 - freetype/src/pshinter/pshrec.h | 171 - freetype/src/pshinter/rules.mk | 75 - freetype/src/psnames/module.mk | 23 - freetype/src/psnames/psmodule.c | 621 - freetype/src/psnames/psmodule.h | 37 - freetype/src/psnames/psnamerr.h | 42 - freetype/src/psnames/psnames.c | 24 - freetype/src/psnames/pstables.h | 4238 - freetype/src/psnames/rules.mk | 73 - freetype/src/raster/ftmisc.h | 139 - freetype/src/raster/ftraster.c | 3294 - freetype/src/raster/ftraster.h | 47 - freetype/src/raster/ftrend1.c | 209 - freetype/src/raster/ftrend1.h | 37 - freetype/src/raster/module.mk | 23 - freetype/src/raster/raster.c | 25 - freetype/src/raster/rasterrs.h | 42 - freetype/src/raster/rules.mk | 72 - freetype/src/sdf/ftbsdf.c | 1350 - freetype/src/sdf/ftsdf.c | 3932 - freetype/src/sdf/ftsdf.h | 97 - freetype/src/sdf/ftsdfcommon.c | 147 - freetype/src/sdf/ftsdfcommon.h | 141 - freetype/src/sdf/ftsdferrs.h | 37 - freetype/src/sdf/ftsdfrend.c | 603 - freetype/src/sdf/ftsdfrend.h | 118 - freetype/src/sdf/module.mk | 29 - freetype/src/sdf/rules.mk | 78 - freetype/src/sdf/sdf.c | 29 - freetype/src/sfnt/module.mk | 23 - freetype/src/sfnt/pngshim.c | 462 - freetype/src/sfnt/pngshim.h | 50 - freetype/src/sfnt/rules.mk | 86 - freetype/src/sfnt/sfdriver.c | 1369 - freetype/src/sfnt/sfdriver.h | 35 - freetype/src/sfnt/sferrors.h | 41 - freetype/src/sfnt/sfnt.c | 40 - freetype/src/sfnt/sfobjs.c | 1535 - freetype/src/sfnt/sfobjs.h | 58 - freetype/src/sfnt/sfwoff.c | 434 - freetype/src/sfnt/sfwoff.h | 43 - freetype/src/sfnt/sfwoff2.c | 2392 - freetype/src/sfnt/sfwoff2.h | 78 - freetype/src/sfnt/ttbdf.c | 257 - freetype/src/sfnt/ttbdf.h | 49 - freetype/src/sfnt/ttcmap.c | 3902 - freetype/src/sfnt/ttcmap.h | 126 - freetype/src/sfnt/ttcmapc.h | 56 - freetype/src/sfnt/ttcolr.c | 1921 - freetype/src/sfnt/ttcolr.h | 83 - freetype/src/sfnt/ttcpal.c | 310 - freetype/src/sfnt/ttcpal.h | 48 - freetype/src/sfnt/ttkern.c | 317 - freetype/src/sfnt/ttkern.h | 51 - freetype/src/sfnt/ttload.c | 1496 - freetype/src/sfnt/ttload.h | 111 - freetype/src/sfnt/ttmtx.c | 338 - freetype/src/sfnt/ttmtx.h | 54 - freetype/src/sfnt/ttpost.c | 484 - freetype/src/sfnt/ttpost.h | 46 - freetype/src/sfnt/ttsbit.c | 1685 - freetype/src/sfnt/ttsbit.h | 62 - freetype/src/sfnt/ttsvg.c | 413 - freetype/src/sfnt/ttsvg.h | 43 - freetype/src/sfnt/woff2tags.c | 119 - freetype/src/sfnt/woff2tags.h | 41 - freetype/src/smooth/ftgrays.c | 2244 - freetype/src/smooth/ftgrays.h | 57 - freetype/src/smooth/ftsmerrs.h | 42 - freetype/src/smooth/ftsmooth.c | 605 - freetype/src/smooth/ftsmooth.h | 37 - freetype/src/smooth/module.mk | 23 - freetype/src/smooth/rules.mk | 73 - freetype/src/smooth/smooth.c | 25 - freetype/src/svg/ftsvg.c | 355 - freetype/src/svg/ftsvg.h | 35 - freetype/src/svg/module.mk | 23 - freetype/src/svg/rules.mk | 70 - freetype/src/svg/svg.c | 24 - freetype/src/svg/svgtypes.h | 42 - freetype/src/tools/afblue.pl | 551 - freetype/src/tools/apinames.c | 556 - freetype/src/tools/chktrcmp.py | 119 - freetype/src/tools/cordic.py | 32 - freetype/src/tools/ftrandom/README | 69 - freetype/src/tools/ftrandom/ftrandom.c | 720 - freetype/src/tools/glnames.py | 5533 - .../src/tools/make_distribution_archives.py | 208 - freetype/src/tools/no-copyright | 66 - freetype/src/tools/test_afm.c | 156 - freetype/src/tools/test_bbox.c | 187 - freetype/src/tools/test_trig.c | 257 - freetype/src/tools/update-copyright | 14 - freetype/src/tools/update-copyright-year | 157 - freetype/src/tools/vms_shorten_symbol.c | 250 - freetype/src/truetype/module.mk | 23 - freetype/src/truetype/rules.mk | 75 - freetype/src/truetype/truetype.c | 29 - freetype/src/truetype/ttdriver.c | 691 - freetype/src/truetype/ttdriver.h | 35 - freetype/src/truetype/tterrors.h | 42 - freetype/src/truetype/ttgload.c | 2743 - freetype/src/truetype/ttgload.h | 61 - freetype/src/truetype/ttgxvar.c | 4661 - freetype/src/truetype/ttgxvar.h | 453 - freetype/src/truetype/ttinterp.c | 7753 -- freetype/src/truetype/ttinterp.h | 465 - freetype/src/truetype/ttobjs.c | 1539 - freetype/src/truetype/ttobjs.h | 426 - freetype/src/truetype/ttpload.c | 665 - freetype/src/truetype/ttpload.h | 74 - freetype/src/type1/module.mk | 23 - freetype/src/type1/rules.mk | 76 - freetype/src/type1/t1afm.c | 413 - freetype/src/type1/t1afm.h | 53 - freetype/src/type1/t1driver.c | 813 - freetype/src/type1/t1driver.h | 35 - freetype/src/type1/t1errors.h | 41 - freetype/src/type1/t1gload.c | 606 - freetype/src/type1/t1gload.h | 52 - freetype/src/type1/t1load.c | 2761 - freetype/src/type1/t1load.h | 126 - freetype/src/type1/t1objs.c | 655 - freetype/src/type1/t1objs.h | 160 - freetype/src/type1/t1parse.c | 487 - freetype/src/type1/t1parse.h | 137 - freetype/src/type1/t1tokens.h | 143 - freetype/src/type1/type1.c | 29 - freetype/src/type42/module.mk | 23 - freetype/src/type42/rules.mk | 73 - freetype/src/type42/t42drivr.c | 248 - freetype/src/type42/t42drivr.h | 36 - freetype/src/type42/t42error.h | 41 - freetype/src/type42/t42objs.c | 698 - freetype/src/type42/t42objs.h | 123 - freetype/src/type42/t42parse.c | 1355 - freetype/src/type42/t42parse.h | 91 - freetype/src/type42/t42types.h | 56 - freetype/src/type42/type42.c | 26 - freetype/src/winfonts/fnterrs.h | 42 - freetype/src/winfonts/module.mk | 23 - freetype/src/winfonts/rules.mk | 68 - freetype/src/winfonts/winfnt.c | 1219 - freetype/src/winfonts/winfnt.h | 164 - freetype/subprojects/harfbuzz.wrap | 12 - freetype/subprojects/libpng.wrap | 13 - freetype/subprojects/zlib.wrap | 13 - imgui-sfml/LICENSE | 23 - imgui-sfml/LICENSE.txt | 21 - imgui-sfml/README.md | 284 - imgui-sfml/build-imgui-sfml.lua | 35 - imgui-sfml/imconfig-SFML.h | 36 - imgui-sfml/imconfig.h | 143 - imgui-sfml/imgui-SFML.cpp | 1468 - imgui-sfml/imgui-SFML.h | 134 - imgui-sfml/imgui-SFML_export.h | 25 - imgui-sfml/imgui.cpp | 17061 --- imgui-sfml/imgui.h | 3770 - imgui-sfml/imgui_demo.cpp | 10686 -- imgui-sfml/imgui_draw.cpp | 4828 - imgui-sfml/imgui_internal.h | 3636 - imgui-sfml/imgui_tables.cpp | 4525 - imgui-sfml/imgui_widgets.cpp | 10451 -- imgui-sfml/imstb_rectpack.h | 627 - imgui-sfml/imstb_textedit.h | 1469 - imgui-sfml/imstb_truetype.h | 5085 - imgui-sfml/misc/README.txt | 23 - imgui-sfml/misc/cpp/README.txt | 13 - imgui-sfml/misc/cpp/imgui_stdlib.cpp | 88 - imgui-sfml/misc/cpp/imgui_stdlib.h | 25 - imgui-sfml/misc/debuggers/README.txt | 16 - imgui-sfml/misc/debuggers/imgui.gdb | 12 - imgui-sfml/misc/debuggers/imgui.natstepfilter | 31 - imgui-sfml/misc/debuggers/imgui.natvis | 58 - imgui-sfml/misc/fonts/Cousine-Regular.ttf | Bin 43912 -> 0 bytes imgui-sfml/misc/fonts/DroidSans.ttf | Bin 190044 -> 0 bytes imgui-sfml/misc/fonts/Karla-Regular.ttf | Bin 16848 -> 0 bytes imgui-sfml/misc/fonts/ProggyClean.ttf | Bin 41208 -> 0 bytes imgui-sfml/misc/fonts/ProggyTiny.ttf | Bin 35656 -> 0 bytes imgui-sfml/misc/fonts/Roboto-Medium.ttf | Bin 162588 -> 0 bytes .../misc/fonts/binary_to_compressed_c.cpp | 424 - imgui-sfml/misc/freetype/README.md | 54 - imgui-sfml/misc/freetype/imgui_freetype.cpp | 969 - imgui-sfml/misc/freetype/imgui_freetype.h | 58 - .../misc/single_file/imgui_single_file.h | 29 - ogg/AUTHORS | 7 - ogg/COPYING | 28 - ogg/README.md | 160 - ogg/build-ogg.lua | 28 - ogg/include/Makefile.am | 3 - ogg/include/ogg/Makefile.am | 6 - ogg/include/ogg/config_types.h.in | 26 - ogg/include/ogg/ogg.h | 209 - ogg/include/ogg/os_types.h | 158 - ogg/libogg.spec.in | 109 - ogg/ogg-uninstalled.pc.in | 14 - ogg/ogg.m4 | 116 - ogg/ogg.pc.in | 14 - ogg/releases.sha2 | 40 - ogg/src/Makefile.am | 28 - ogg/src/bitwise.c | 1087 - ogg/src/crctable.h | 278 - ogg/src/framing.c | 2114 - project.lua | 55 - sfml/build-sfml.lua | 105 - sfml/extlibs/headers/glad/include/glad/egl.h | 1530 - sfml/extlibs/headers/glad/include/glad/gl.h | 12248 -- sfml/extlibs/headers/glad/include/glad/glx.h | 1043 - sfml/extlibs/headers/glad/include/glad/wgl.h | 572 - sfml/extlibs/headers/mingw/_mingw_dxhelper.h | 117 - sfml/extlibs/headers/mingw/dinput.h | 2467 - sfml/extlibs/headers/miniaudio/miniaudio.h | 92621 ---------------- sfml/extlibs/headers/minimp3/minimp3.h | 1855 - sfml/extlibs/headers/minimp3/minimp3_ex.h | 1397 - sfml/extlibs/headers/stb_image/stb_image.h | 7988 -- .../headers/stb_image/stb_image_write.h | 1724 - sfml/extlibs/headers/vulkan/vk_icd.h | 170 - sfml/extlibs/headers/vulkan/vk_layer.h | 195 - sfml/extlibs/headers/vulkan/vk_platform.h | 92 - sfml/extlibs/headers/vulkan/vk_sdk_platform.h | 69 - sfml/extlibs/headers/vulkan/vulkan.h | 79 - sfml/extlibs/headers/vulkan/vulkan_android.h | 126 - sfml/extlibs/headers/vulkan/vulkan_core.h | 7801 -- sfml/extlibs/headers/vulkan/vulkan_ios.h | 58 - sfml/extlibs/headers/vulkan/vulkan_macos.h | 58 - sfml/extlibs/headers/vulkan/vulkan_mir.h | 65 - sfml/extlibs/headers/vulkan/vulkan_vi.h | 58 - sfml/extlibs/headers/vulkan/vulkan_wayland.h | 65 - sfml/extlibs/headers/vulkan/vulkan_win32.h | 276 - sfml/extlibs/headers/vulkan/vulkan_xcb.h | 66 - sfml/extlibs/headers/vulkan/vulkan_xlib.h | 66 - .../headers/vulkan/vulkan_xlib_xrandr.h | 54 - sfml/include/SFML/Audio.hpp | 55 - sfml/include/SFML/Audio/AudioResource.hpp | 93 - sfml/include/SFML/Audio/Export.hpp | 44 - sfml/include/SFML/Audio/InputSoundFile.hpp | 336 - sfml/include/SFML/Audio/Listener.hpp | 234 - sfml/include/SFML/Audio/Music.hpp | 377 - sfml/include/SFML/Audio/OutputSoundFile.hpp | 147 - sfml/include/SFML/Audio/PlaybackDevice.hpp | 110 - sfml/include/SFML/Audio/Sound.hpp | 284 - sfml/include/SFML/Audio/SoundBuffer.hpp | 451 - .../SFML/Audio/SoundBufferRecorder.hpp | 149 - sfml/include/SFML/Audio/SoundChannel.hpp | 65 - sfml/include/SFML/Audio/SoundFileFactory.hpp | 200 - sfml/include/SFML/Audio/SoundFileFactory.inl | 96 - sfml/include/SFML/Audio/SoundFileReader.hpp | 167 - sfml/include/SFML/Audio/SoundFileWriter.hpp | 130 - sfml/include/SFML/Audio/SoundRecorder.hpp | 362 - sfml/include/SFML/Audio/SoundSource.hpp | 686 - sfml/include/SFML/Audio/SoundStream.hpp | 385 - sfml/include/SFML/Config.hpp | 164 - sfml/include/SFML/GpuPreference.hpp | 70 - sfml/include/SFML/Graphics.hpp | 67 - sfml/include/SFML/Graphics/BlendMode.hpp | 220 - sfml/include/SFML/Graphics/CircleShape.hpp | 165 - sfml/include/SFML/Graphics/Color.hpp | 274 - sfml/include/SFML/Graphics/Color.inl | 156 - sfml/include/SFML/Graphics/ConvexShape.hpp | 155 - sfml/include/SFML/Graphics/CoordinateType.hpp | 43 - sfml/include/SFML/Graphics/Drawable.hpp | 120 - sfml/include/SFML/Graphics/Export.hpp | 44 - sfml/include/SFML/Graphics/Font.hpp | 529 - sfml/include/SFML/Graphics/Glsl.hpp | 224 - sfml/include/SFML/Graphics/Glsl.inl | 177 - sfml/include/SFML/Graphics/Glyph.hpp | 67 - sfml/include/SFML/Graphics/Image.hpp | 417 - sfml/include/SFML/Graphics/PrimitiveType.hpp | 48 - sfml/include/SFML/Graphics/Rect.hpp | 203 - sfml/include/SFML/Graphics/Rect.inl | 130 - sfml/include/SFML/Graphics/RectangleShape.hpp | 143 - sfml/include/SFML/Graphics/RenderStates.hpp | 191 - sfml/include/SFML/Graphics/RenderTarget.hpp | 606 - sfml/include/SFML/Graphics/RenderTexture.hpp | 342 - sfml/include/SFML/Graphics/RenderWindow.hpp | 308 - sfml/include/SFML/Graphics/Shader.hpp | 1023 - sfml/include/SFML/Graphics/Shape.hpp | 357 - sfml/include/SFML/Graphics/Sprite.hpp | 278 - sfml/include/SFML/Graphics/StencilMode.hpp | 256 - sfml/include/SFML/Graphics/Text.hpp | 486 - sfml/include/SFML/Graphics/Texture.hpp | 874 - sfml/include/SFML/Graphics/Transform.hpp | 393 - sfml/include/SFML/Graphics/Transform.inl | 236 - sfml/include/SFML/Graphics/Transformable.hpp | 340 - sfml/include/SFML/Graphics/Vertex.hpp | 122 - sfml/include/SFML/Graphics/VertexArray.hpp | 221 - sfml/include/SFML/Graphics/VertexBuffer.hpp | 414 - sfml/include/SFML/Graphics/View.hpp | 357 - sfml/include/SFML/Main.hpp | 39 - sfml/include/SFML/Network.hpp | 51 - sfml/include/SFML/Network/Export.hpp | 44 - sfml/include/SFML/Network/Ftp.hpp | 629 - sfml/include/SFML/Network/Http.hpp | 480 - sfml/include/SFML/Network/IpAddress.hpp | 297 - sfml/include/SFML/Network/Packet.hpp | 548 - sfml/include/SFML/Network/Socket.hpp | 229 - sfml/include/SFML/Network/SocketHandle.hpp | 52 - sfml/include/SFML/Network/SocketSelector.hpp | 273 - sfml/include/SFML/Network/TcpListener.hpp | 166 - sfml/include/SFML/Network/TcpSocket.hpp | 317 - sfml/include/SFML/Network/UdpSocket.hpp | 293 - sfml/include/SFML/OpenGL.hpp | 78 - sfml/include/SFML/System.hpp | 55 - sfml/include/SFML/System/Angle.hpp | 511 - sfml/include/SFML/System/Angle.inl | 274 - sfml/include/SFML/System/Clock.hpp | 196 - sfml/include/SFML/System/Err.hpp | 77 - sfml/include/SFML/System/Exception.hpp | 46 - sfml/include/SFML/System/Export.hpp | 44 - sfml/include/SFML/System/FileInputStream.hpp | 212 - sfml/include/SFML/System/InputStream.hpp | 166 - .../include/SFML/System/MemoryInputStream.hpp | 139 - sfml/include/SFML/System/NativeActivity.hpp | 58 - sfml/include/SFML/System/Sleep.hpp | 57 - sfml/include/SFML/System/String.hpp | 700 - sfml/include/SFML/System/String.inl | 64 - .../include/SFML/System/SuspendAwareClock.hpp | 76 - sfml/include/SFML/System/Time.hpp | 500 - sfml/include/SFML/System/Time.inl | 284 - sfml/include/SFML/System/Utf.hpp | 764 - sfml/include/SFML/System/Utf.inl | 732 - sfml/include/SFML/System/Vector2.hpp | 435 - sfml/include/SFML/System/Vector2.inl | 217 - sfml/include/SFML/System/Vector3.hpp | 356 - sfml/include/SFML/System/Vector3.inl | 214 - sfml/include/SFML/Window.hpp | 55 - sfml/include/SFML/Window/Clipboard.hpp | 114 - sfml/include/SFML/Window/Context.hpp | 224 - sfml/include/SFML/Window/ContextSettings.hpp | 125 - sfml/include/SFML/Window/Cursor.hpp | 303 - sfml/include/SFML/Window/Event.hpp | 442 - sfml/include/SFML/Window/Event.inl | 78 - sfml/include/SFML/Window/Export.hpp | 44 - sfml/include/SFML/Window/GlResource.hpp | 122 - sfml/include/SFML/Window/Joystick.hpp | 213 - sfml/include/SFML/Window/Keyboard.hpp | 475 - sfml/include/SFML/Window/Mouse.hpp | 183 - sfml/include/SFML/Window/Sensor.hpp | 139 - sfml/include/SFML/Window/Touch.hpp | 131 - sfml/include/SFML/Window/VideoMode.hpp | 224 - sfml/include/SFML/Window/Vulkan.hpp | 112 - sfml/include/SFML/Window/Window.hpp | 422 - sfml/include/SFML/Window/WindowBase.hpp | 653 - sfml/include/SFML/Window/WindowBase.inl | 112 - sfml/include/SFML/Window/WindowEnums.hpp | 60 - sfml/include/SFML/Window/WindowHandle.hpp | 98 - sfml/license.md | 9 - sfml/readme.md | 77 - sfml/src/SFML/Audio/AudioDevice.cpp | 599 - sfml/src/SFML/Audio/AudioDevice.hpp | 392 - sfml/src/SFML/Audio/AudioResource.cpp | 62 - sfml/src/SFML/Audio/InputSoundFile.cpp | 320 - sfml/src/SFML/Audio/Listener.cpp | 117 - sfml/src/SFML/Audio/Miniaudio.cpp | 33 - sfml/src/SFML/Audio/MiniaudioUtils.cpp | 411 - sfml/src/SFML/Audio/MiniaudioUtils.hpp | 111 - sfml/src/SFML/Audio/Music.cpp | 338 - sfml/src/SFML/Audio/OutputSoundFile.cpp | 97 - sfml/src/SFML/Audio/PlaybackDevice.cpp | 83 - sfml/src/SFML/Audio/Sound.cpp | 398 - sfml/src/SFML/Audio/SoundBuffer.cpp | 310 - sfml/src/SFML/Audio/SoundBufferRecorder.cpp | 83 - sfml/src/SFML/Audio/SoundFileFactory.cpp | 164 - sfml/src/SFML/Audio/SoundFileReaderFlac.cpp | 404 - sfml/src/SFML/Audio/SoundFileReaderFlac.hpp | 126 - sfml/src/SFML/Audio/SoundFileReaderMp3.cpp | 182 - sfml/src/SFML/Audio/SoundFileReaderMp3.hpp | 133 - sfml/src/SFML/Audio/SoundFileReaderOgg.cpp | 229 - sfml/src/SFML/Audio/SoundFileReaderOgg.hpp | 119 - sfml/src/SFML/Audio/SoundFileReaderWav.cpp | 201 - sfml/src/SFML/Audio/SoundFileReaderWav.hpp | 113 - sfml/src/SFML/Audio/SoundFileWriterFlac.cpp | 188 - sfml/src/SFML/Audio/SoundFileWriterFlac.hpp | 99 - sfml/src/SFML/Audio/SoundFileWriterOgg.cpp | 285 - sfml/src/SFML/Audio/SoundFileWriterOgg.hpp | 115 - sfml/src/SFML/Audio/SoundFileWriterWav.cpp | 330 - sfml/src/SFML/Audio/SoundFileWriterWav.hpp | 114 - sfml/src/SFML/Audio/SoundRecorder.cpp | 476 - sfml/src/SFML/Audio/SoundSource.cpp | 377 - sfml/src/SFML/Audio/SoundStream.cpp | 415 - sfml/src/SFML/Graphics/BlendMode.cpp | 98 - sfml/src/SFML/Graphics/CircleShape.cpp | 85 - sfml/src/SFML/Graphics/ConvexShape.cpp | 73 - sfml/src/SFML/Graphics/Font.cpp | 765 - sfml/src/SFML/Graphics/GLCheck.cpp | 83 - sfml/src/SFML/Graphics/GLCheck.hpp | 91 - sfml/src/SFML/Graphics/GLExtensions.cpp | 144 - sfml/src/SFML/Graphics/GLExtensions.hpp | 411 - sfml/src/SFML/Graphics/GLExtensions.txt | 23 - sfml/src/SFML/Graphics/Glsl.cpp | 72 - sfml/src/SFML/Graphics/Image.cpp | 626 - sfml/src/SFML/Graphics/RectangleShape.cpp | 86 - sfml/src/SFML/Graphics/RenderStates.cpp | 91 - sfml/src/SFML/Graphics/RenderTarget.cpp | 960 - sfml/src/SFML/Graphics/RenderTexture.cpp | 213 - sfml/src/SFML/Graphics/RenderTextureImpl.hpp | 115 - .../Graphics/RenderTextureImplDefault.cpp | 98 - .../Graphics/RenderTextureImplDefault.hpp | 125 - .../SFML/Graphics/RenderTextureImplFBO.cpp | 647 - .../SFML/Graphics/RenderTextureImplFBO.hpp | 163 - sfml/src/SFML/Graphics/RenderWindow.cpp | 128 - sfml/src/SFML/Graphics/Shader.cpp | 1323 - sfml/src/SFML/Graphics/Shape.cpp | 342 - sfml/src/SFML/Graphics/Sprite.cpp | 149 - sfml/src/SFML/Graphics/StencilMode.cpp | 61 - sfml/src/SFML/Graphics/Text.cpp | 520 - sfml/src/SFML/Graphics/Texture.cpp | 1079 - sfml/src/SFML/Graphics/TextureSaver.cpp | 46 - sfml/src/SFML/Graphics/TextureSaver.hpp | 65 - sfml/src/SFML/Graphics/Transform.cpp | 70 - sfml/src/SFML/Graphics/Transformable.cpp | 162 - sfml/src/SFML/Graphics/VertexArray.cpp | 142 - sfml/src/SFML/Graphics/VertexBuffer.cpp | 360 - sfml/src/SFML/Graphics/View.cpp | 199 - sfml/src/SFML/Main/MainWin32.cpp | 53 - sfml/src/SFML/Network/Ftp.cpp | 643 - sfml/src/SFML/Network/Http.cpp | 399 - sfml/src/SFML/Network/IpAddress.cpp | 253 - sfml/src/SFML/Network/Packet.cpp | 596 - sfml/src/SFML/Network/Socket.cpp | 175 - sfml/src/SFML/Network/SocketImpl.hpp | 123 - sfml/src/SFML/Network/SocketSelector.cpp | 209 - sfml/src/SFML/Network/TcpListener.cpp | 132 - sfml/src/SFML/Network/TcpSocket.cpp | 429 - sfml/src/SFML/Network/UdpSocket.cpp | 223 - sfml/src/SFML/Network/Unix/SocketImpl.cpp | 111 - sfml/src/SFML/Network/Win32/SocketImpl.cpp | 110 - sfml/src/SFML/PCH.hpp | 65 - sfml/src/SFML/System/Clock.cpp | 88 - sfml/src/SFML/System/EnumArray.hpp | 75 - sfml/src/SFML/System/Err.cpp | 109 - sfml/src/SFML/System/FileInputStream.cpp | 167 - sfml/src/SFML/System/MemoryInputStream.cpp | 92 - sfml/src/SFML/System/Sleep.cpp | 50 - sfml/src/SFML/System/String.cpp | 477 - sfml/src/SFML/System/Unix/SleepImpl.cpp | 57 - sfml/src/SFML/System/Unix/SleepImpl.hpp | 48 - sfml/src/SFML/System/Utils.cpp | 64 - sfml/src/SFML/System/Utils.hpp | 58 - sfml/src/SFML/System/Vector2.cpp | 124 - sfml/src/SFML/System/Vector3.cpp | 65 - sfml/src/SFML/System/Win32/SleepImpl.cpp | 57 - sfml/src/SFML/System/Win32/SleepImpl.hpp | 48 - sfml/src/SFML/System/Win32/WindowsHeader.hpp | 55 - sfml/src/SFML/Window/Clipboard.cpp | 49 - sfml/src/SFML/Window/ClipboardImpl.hpp | 47 - sfml/src/SFML/Window/Context.cpp | 152 - sfml/src/SFML/Window/Cursor.cpp | 118 - sfml/src/SFML/Window/CursorImpl.hpp | 47 - sfml/src/SFML/Window/EGLCheck.cpp | 122 - sfml/src/SFML/Window/EGLCheck.hpp | 94 - sfml/src/SFML/Window/EglContext.cpp | 429 - sfml/src/SFML/Window/EglContext.hpp | 194 - sfml/src/SFML/Window/GlContext.cpp | 1073 - sfml/src/SFML/Window/GlContext.hpp | 322 - sfml/src/SFML/Window/GlResource.cpp | 69 - sfml/src/SFML/Window/InputImpl.hpp | 176 - sfml/src/SFML/Window/Joystick.cpp | 85 - sfml/src/SFML/Window/JoystickImpl.hpp | 96 - sfml/src/SFML/Window/JoystickManager.cpp | 124 - sfml/src/SFML/Window/JoystickManager.hpp | 132 - sfml/src/SFML/Window/Keyboard.cpp | 72 - sfml/src/SFML/Window/Mouse.cpp | 68 - sfml/src/SFML/Window/Sensor.cpp | 53 - sfml/src/SFML/Window/SensorImpl.hpp | 55 - sfml/src/SFML/Window/SensorManager.cpp | 138 - sfml/src/SFML/Window/SensorManager.hpp | 141 - sfml/src/SFML/Window/Touch.cpp | 54 - sfml/src/SFML/Window/Unix/ClipboardImpl.cpp | 389 - sfml/src/SFML/Window/Unix/ClipboardImpl.hpp | 150 - sfml/src/SFML/Window/Unix/CursorImpl.cpp | 224 - sfml/src/SFML/Window/Unix/CursorImpl.hpp | 128 - sfml/src/SFML/Window/Unix/Display.cpp | 143 - sfml/src/SFML/Window/Unix/Display.hpp | 67 - sfml/src/SFML/Window/Unix/GlxContext.cpp | 762 - sfml/src/SFML/Window/Unix/GlxContext.hpp | 185 - sfml/src/SFML/Window/Unix/InputImpl.cpp | 213 - sfml/src/SFML/Window/Unix/JoystickImpl.cpp | 677 - sfml/src/SFML/Window/Unix/JoystickImpl.hpp | 114 - .../SFML/Window/Unix/KeySymToKeyMapping.cpp | 262 - .../SFML/Window/Unix/KeySymToKeyMapping.hpp | 57 - .../Window/Unix/KeySymToUnicodeMapping.cpp | 1400 - .../Window/Unix/KeySymToUnicodeMapping.hpp | 54 - sfml/src/SFML/Window/Unix/KeyboardImpl.cpp | 814 - sfml/src/SFML/Window/Unix/KeyboardImpl.hpp | 93 - sfml/src/SFML/Window/Unix/SensorImpl.cpp | 84 - sfml/src/SFML/Window/Unix/SensorImpl.hpp | 92 - sfml/src/SFML/Window/Unix/Utils.hpp | 61 - sfml/src/SFML/Window/Unix/VideoModeImpl.cpp | 192 - sfml/src/SFML/Window/Unix/VulkanImplX11.cpp | 215 - sfml/src/SFML/Window/Unix/WindowImplX11.cpp | 2169 - sfml/src/SFML/Window/Unix/WindowImplX11.hpp | 341 - sfml/src/SFML/Window/VideoMode.cpp | 125 - sfml/src/SFML/Window/VideoModeImpl.hpp | 61 - sfml/src/SFML/Window/Vulkan.cpp | 106 - sfml/src/SFML/Window/VulkanImpl.hpp | 90 - sfml/src/SFML/Window/Win32/ClipboardImpl.cpp | 104 - sfml/src/SFML/Window/Win32/ClipboardImpl.hpp | 68 - sfml/src/SFML/Window/Win32/CursorImpl.cpp | 184 - sfml/src/SFML/Window/Win32/CursorImpl.hpp | 106 - sfml/src/SFML/Window/Win32/InputImpl.cpp | 757 - sfml/src/SFML/Window/Win32/JoystickImpl.cpp | 1156 - sfml/src/SFML/Window/Win32/JoystickImpl.hpp | 227 - sfml/src/SFML/Window/Win32/SensorImpl.cpp | 84 - sfml/src/SFML/Window/Win32/SensorImpl.hpp | 97 - sfml/src/SFML/Window/Win32/Utils.hpp | 53 - sfml/src/SFML/Window/Win32/VideoModeImpl.cpp | 71 - .../src/SFML/Window/Win32/VulkanImplWin32.cpp | 209 - sfml/src/SFML/Window/Win32/WglContext.cpp | 849 - sfml/src/SFML/Window/Win32/WglContext.hpp | 197 - .../src/SFML/Window/Win32/WindowImplWin32.cpp | 1332 - .../src/SFML/Window/Win32/WindowImplWin32.hpp | 315 - sfml/src/SFML/Window/Window.cpp | 230 - sfml/src/SFML/Window/WindowBase.cpp | 400 - sfml/src/SFML/Window/WindowImpl.cpp | 401 - sfml/src/SFML/Window/WindowImpl.hpp | 375 - vorbis/AUTHORS | 3 - vorbis/COPYING | 28 - vorbis/README.md | 147 - vorbis/build-vorbis.lua | 80 - vorbis/contrib/oss-fuzz/build.sh | 23 - vorbis/contrib/oss-fuzz/decode_fuzzer.cc | 48 - vorbis/debian/changelog | 208 - vorbis/debian/control | 60 - vorbis/debian/copyright | 38 - vorbis/debian/libvorbis-dev.docs | 1 - vorbis/debian/libvorbis-dev.examples | 2 - vorbis/debian/libvorbis-dev.install | 16 - vorbis/debian/libvorbis0a.install | 1 - vorbis/debian/libvorbisenc2.install | 1 - vorbis/debian/libvorbisfile3.install | 1 - vorbis/debian/rules | 154 - vorbis/debian/watch | 3 - vorbis/include/Makefile.am | 3 - vorbis/include/vorbis/Makefile.am | 7 - vorbis/include/vorbis/codec.h | 242 - vorbis/include/vorbis/vorbisenc.h | 435 - vorbis/include/vorbis/vorbisfile.h | 205 - vorbis/lib/Makefile.am | 63 - vorbis/lib/analysis.c | 119 - vorbis/lib/backends.h | 143 - vorbis/lib/barkmel.c | 63 - vorbis/lib/bitrate.c | 252 - vorbis/lib/bitrate.h | 58 - vorbis/lib/block.c | 1046 - vorbis/lib/books/Makefile.am | 3 - vorbis/lib/books/coupled/Makefile.am | 3 - vorbis/lib/books/coupled/res_books_51.h | 12273 -- vorbis/lib/books/coupled/res_books_stereo.h | 15782 --- vorbis/lib/books/floor/Makefile.am | 3 - vorbis/lib/books/floor/floor_books.h | 1546 - vorbis/lib/books/uncoupled/Makefile.am | 3 - .../lib/books/uncoupled/res_books_uncoupled.h | 7757 -- vorbis/lib/codebook.c | 461 - vorbis/lib/codebook.h | 117 - vorbis/lib/codec_internal.h | 166 - vorbis/lib/envelope.c | 374 - vorbis/lib/envelope.h | 79 - vorbis/lib/floor0.c | 223 - vorbis/lib/floor1.c | 1086 - vorbis/lib/highlevel.h | 57 - vorbis/lib/info.c | 687 - vorbis/lib/lookup.c | 93 - vorbis/lib/lookup.h | 31 - vorbis/lib/lookup_data.h | 191 - vorbis/lib/lookups.pl | 141 - vorbis/lib/lpc.c | 159 - vorbis/lib/lpc.h | 28 - vorbis/lib/lsp.c | 454 - vorbis/lib/lsp.h | 27 - vorbis/lib/mapping0.c | 808 - vorbis/lib/masking.h | 784 - vorbis/lib/mdct.c | 562 - vorbis/lib/mdct.h | 70 - vorbis/lib/misc.c | 216 - vorbis/lib/misc.h | 57 - vorbis/lib/modes/Makefile.am | 6 - vorbis/lib/modes/floor_all.h | 259 - vorbis/lib/modes/psych_11.h | 50 - vorbis/lib/modes/psych_16.h | 132 - vorbis/lib/modes/psych_44.h | 641 - vorbis/lib/modes/psych_8.h | 100 - vorbis/lib/modes/residue_16.h | 162 - vorbis/lib/modes/residue_44.h | 291 - vorbis/lib/modes/residue_44p51.h | 450 - vorbis/lib/modes/residue_44u.h | 317 - vorbis/lib/modes/residue_8.h | 108 - vorbis/lib/modes/setup_11.h | 142 - vorbis/lib/modes/setup_16.h | 152 - vorbis/lib/modes/setup_22.h | 127 - vorbis/lib/modes/setup_32.h | 131 - vorbis/lib/modes/setup_44.h | 116 - vorbis/lib/modes/setup_44p51.h | 73 - vorbis/lib/modes/setup_44u.h | 73 - vorbis/lib/modes/setup_8.h | 148 - vorbis/lib/modes/setup_X.h | 224 - vorbis/lib/os.h | 189 - vorbis/lib/psy.c | 1209 - vorbis/lib/psy.h | 153 - vorbis/lib/psytune.c | 523 - vorbis/lib/registry.c | 44 - vorbis/lib/registry.h | 31 - vorbis/lib/res0.c | 886 - vorbis/lib/scales.h | 89 - vorbis/lib/sharedbook.c | 604 - vorbis/lib/smallft.c | 1254 - vorbis/lib/smallft.h | 33 - vorbis/lib/synthesis.c | 179 - vorbis/lib/tone.c | 54 - vorbis/lib/vorbisenc.c | 1224 - vorbis/lib/vorbisfile.c | 2427 - vorbis/lib/window.c | 2135 - vorbis/lib/window.h | 25 - vorbis/symbian/bld.inf | 35 - vorbis/symbian/config.h | 54 - vorbis/symbian/vorbis.mmp | 43 - vorbis/test/Makefile.am | 19 - vorbis/test/test.c | 99 - vorbis/test/util.c | 52 - vorbis/test/util.h | 23 - vorbis/test/write_read.c | 297 - vorbis/test/write_read.h | 27 - vorbis/vq/16.vqs | 74 - vorbis/vq/16u.vqs | 69 - vorbis/vq/44c-1.vqs | 63 - vorbis/vq/44c0.vqs | 65 - vorbis/vq/44c1.vqs | 66 - vorbis/vq/44c2.vqs | 37 - vorbis/vq/44c3.vqs | 36 - vorbis/vq/44c4.vqs | 36 - vorbis/vq/44c5.vqs | 37 - vorbis/vq/44c6.vqs | 37 - vorbis/vq/44c7.vqs | 38 - vorbis/vq/44c8.vqs | 39 - vorbis/vq/44c9.vqs | 37 - vorbis/vq/44p-1.vqs | 49 - vorbis/vq/44p0.vqs | 49 - vorbis/vq/44p1.vqs | 49 - vorbis/vq/44p2.vqs | 52 - vorbis/vq/44p3.vqs | 52 - vorbis/vq/44p4.vqs | 52 - vorbis/vq/44p5.vqs | 52 - vorbis/vq/44p6.vqs | 52 - vorbis/vq/44p7.vqs | 52 - vorbis/vq/44p8.vqs | 52 - vorbis/vq/44p9.vqs | 52 - vorbis/vq/44u0.vqs | 33 - vorbis/vq/44u1.vqs | 33 - vorbis/vq/44u2.vqs | 32 - vorbis/vq/44u3.vqs | 33 - vorbis/vq/44u4.vqs | 33 - vorbis/vq/44u5.vqs | 35 - vorbis/vq/44u6.vqs | 35 - vorbis/vq/44u7.vqs | 34 - vorbis/vq/44u8.vqs | 35 - vorbis/vq/44u9.vqs | 36 - vorbis/vq/8.vqs | 43 - vorbis/vq/8u.vqs | 41 - vorbis/vq/Makefile.am | 36 - vorbis/vq/bookutil.c | 476 - vorbis/vq/bookutil.h | 42 - vorbis/vq/distribution.c | 247 - vorbis/vq/floor_11.vqs | 10 - vorbis/vq/floor_22.vqs | 27 - vorbis/vq/floor_44.vqs | 83 - vorbis/vq/huffbuild.c | 197 - vorbis/vq/latticebuild.c | 176 - vorbis/vq/latticetune.c | 163 - vorbis/vq/localcodebook.h | 120 - vorbis/vq/make_floor_books.pl | 108 - vorbis/vq/make_residue_books.pl | 177 - vorbis/vq/metrics.c | 294 - vorbis/vq/vqgen.c | 566 - vorbis/vq/vqgen.h | 84 - workspace.lua | 58 - 1537 files changed, 776720 deletions(-) delete mode 100644 flac/AUTHORS delete mode 100644 flac/COPYING.FDL delete mode 100644 flac/COPYING.GPL delete mode 100644 flac/COPYING.LGPL delete mode 100644 flac/COPYING.Xiph delete mode 100644 flac/README.md delete mode 100644 flac/build-flac.lua delete mode 100644 flac/include/FLAC++/Makefile.am delete mode 100644 flac/include/FLAC++/all.h delete mode 100644 flac/include/FLAC++/decoder.h delete mode 100644 flac/include/FLAC++/encoder.h delete mode 100644 flac/include/FLAC++/export.h delete mode 100644 flac/include/FLAC++/metadata.h delete mode 100644 flac/include/FLAC/Makefile.am delete mode 100644 flac/include/FLAC/all.h delete mode 100644 flac/include/FLAC/assert.h delete mode 100644 flac/include/FLAC/callback.h delete mode 100644 flac/include/FLAC/export.h delete mode 100644 flac/include/FLAC/format.h delete mode 100644 flac/include/FLAC/metadata.h delete mode 100644 flac/include/FLAC/ordinals.h delete mode 100644 flac/include/FLAC/stream_decoder.h delete mode 100644 flac/include/FLAC/stream_encoder.h delete mode 100644 flac/include/Makefile.am delete mode 100644 flac/include/share/Makefile.am delete mode 100644 flac/include/share/alloc.h delete mode 100644 flac/include/share/compat.h delete mode 100644 flac/include/share/endswap.h delete mode 100644 flac/include/share/getopt.h delete mode 100644 flac/include/share/grabbag.h delete mode 100644 flac/include/share/grabbag/Makefile.am delete mode 100644 flac/include/share/grabbag/cuesheet.h delete mode 100644 flac/include/share/grabbag/file.h delete mode 100644 flac/include/share/grabbag/picture.h delete mode 100644 flac/include/share/grabbag/replaygain.h delete mode 100644 flac/include/share/grabbag/seektable.h delete mode 100644 flac/include/share/macros.h delete mode 100644 flac/include/share/private.h delete mode 100644 flac/include/share/replaygain_analysis.h delete mode 100644 flac/include/share/replaygain_synthesis.h delete mode 100644 flac/include/share/safe_str.h delete mode 100644 flac/include/share/utf8.h delete mode 100644 flac/include/share/win_utf8_io.h delete mode 100644 flac/include/test_libs_common/Makefile.am delete mode 100644 flac/include/test_libs_common/file_utils_flac.h delete mode 100644 flac/include/test_libs_common/metadata_utils.h delete mode 100644 flac/m4/Makefile.am delete mode 100644 flac/m4/add_cflags.m4 delete mode 100644 flac/m4/add_cxxflags.m4 delete mode 100644 flac/m4/ax_add_fortify_source.m4 delete mode 100644 flac/m4/ax_check_compile_flag.m4 delete mode 100644 flac/m4/ax_check_enable_debug.m4 delete mode 100644 flac/m4/bswap.m4 delete mode 100644 flac/m4/c_attribute.m4 delete mode 100644 flac/m4/clang.m4 delete mode 100644 flac/m4/codeset.m4 delete mode 100644 flac/m4/endian.m4 delete mode 100644 flac/m4/gcc_version.m4 delete mode 100644 flac/m4/iconv.m4 delete mode 100644 flac/m4/lib-ld.m4 delete mode 100644 flac/m4/lib-link.m4 delete mode 100644 flac/m4/lib-prefix.m4 delete mode 100644 flac/m4/ogg.m4 delete mode 100644 flac/m4/really_gcc.m4 delete mode 100644 flac/m4/stack_protect.m4 delete mode 100644 flac/man/Makefile.am delete mode 100644 flac/man/flac.md delete mode 100644 flac/man/metaflac.md delete mode 100644 flac/microbench/CMakeLists.txt delete mode 100644 flac/microbench/Makefile.am delete mode 100644 flac/microbench/benchmark_residual.c delete mode 100644 flac/microbench/util.c delete mode 100644 flac/microbench/util.h delete mode 100644 flac/oss-fuzz/Makefile.am delete mode 100644 flac/oss-fuzz/Readme.md delete mode 100644 flac/oss-fuzz/common.h delete mode 100644 flac/oss-fuzz/decoder.cc delete mode 100644 flac/oss-fuzz/empty.cc delete mode 100644 flac/oss-fuzz/encoder.cc delete mode 100644 flac/oss-fuzz/encoder_v2.cc delete mode 100644 flac/oss-fuzz/fuzzer_decoder.dict delete mode 100644 flac/oss-fuzz/fuzzer_encoder.dict delete mode 100644 flac/oss-fuzz/fuzzer_reencoder.dict delete mode 100644 flac/oss-fuzz/fuzzer_tool_flac.dict delete mode 100644 flac/oss-fuzz/fuzzing/datasource/datasource.hpp delete mode 100644 flac/oss-fuzz/fuzzing/datasource/id.hpp delete mode 100644 flac/oss-fuzz/fuzzing/exception.hpp delete mode 100644 flac/oss-fuzz/fuzzing/memory.hpp delete mode 100644 flac/oss-fuzz/fuzzing/types.hpp delete mode 100644 flac/oss-fuzz/metadata.cc delete mode 100644 flac/oss-fuzz/reencoder.cc delete mode 100644 flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/aiff-with-foreign-metadata-8bps.fuzz delete mode 100644 flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/flac-foreign-metadata-aiff-8bps.fuzz delete mode 100644 flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/flac-foreign-metadata-wav-8bps.fuzz delete mode 100644 flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/replaygain-which-is-not-lossless-ogg.fuzz delete mode 100644 flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/replaygain-which-is-not-lossless.fuzz delete mode 100644 flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/wav-with-foreign-metadata-8bps.fuzz delete mode 100644 flac/oss-fuzz/seek.cc delete mode 100644 flac/oss-fuzz/tool_flac.c delete mode 100644 flac/oss-fuzz/tool_metaflac.c delete mode 100644 flac/src/CMakeLists.txt delete mode 100644 flac/src/Makefile.am delete mode 100644 flac/src/flac/CMakeLists.txt delete mode 100644 flac/src/flac/Makefile.am delete mode 100644 flac/src/flac/analyze.c delete mode 100644 flac/src/flac/analyze.h delete mode 100644 flac/src/flac/decode.c delete mode 100644 flac/src/flac/decode.h delete mode 100644 flac/src/flac/encode.c delete mode 100644 flac/src/flac/encode.h delete mode 100644 flac/src/flac/foreign_metadata.c delete mode 100644 flac/src/flac/foreign_metadata.h delete mode 100644 flac/src/flac/iffscan.c delete mode 100644 flac/src/flac/local_string_utils.c delete mode 100644 flac/src/flac/local_string_utils.h delete mode 100644 flac/src/flac/main.c delete mode 100644 flac/src/flac/utils.c delete mode 100644 flac/src/flac/utils.h delete mode 100644 flac/src/flac/version.rc delete mode 100644 flac/src/flac/vorbiscomment.c delete mode 100644 flac/src/flac/vorbiscomment.h delete mode 100644 flac/src/libFLAC++/CMakeLists.txt delete mode 100644 flac/src/libFLAC++/Makefile.am delete mode 100644 flac/src/libFLAC++/flac++.pc.in delete mode 100644 flac/src/libFLAC++/libFLAC++.m4 delete mode 100644 flac/src/libFLAC++/metadata.cpp delete mode 100644 flac/src/libFLAC++/stream_decoder.cpp delete mode 100644 flac/src/libFLAC++/stream_encoder.cpp delete mode 100644 flac/src/libFLAC++/version.rc delete mode 100644 flac/src/libFLAC/CMakeLists.txt delete mode 100644 flac/src/libFLAC/Makefile.am delete mode 100644 flac/src/libFLAC/bitmath.c delete mode 100644 flac/src/libFLAC/bitreader.c delete mode 100644 flac/src/libFLAC/bitwriter.c delete mode 100644 flac/src/libFLAC/cpu.c delete mode 100644 flac/src/libFLAC/crc.c delete mode 100644 flac/src/libFLAC/deduplication/bitreader_read_rice_signed_block.c delete mode 100644 flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin.c delete mode 100644 flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_neon.c delete mode 100644 flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_sse2.c delete mode 100644 flac/src/libFLAC/fixed.c delete mode 100644 flac/src/libFLAC/fixed_intrin_avx2.c delete mode 100644 flac/src/libFLAC/fixed_intrin_sse2.c delete mode 100644 flac/src/libFLAC/fixed_intrin_sse42.c delete mode 100644 flac/src/libFLAC/fixed_intrin_ssse3.c delete mode 100644 flac/src/libFLAC/flac.pc.in delete mode 100644 flac/src/libFLAC/float.c delete mode 100644 flac/src/libFLAC/format.c delete mode 100644 flac/src/libFLAC/include/Makefile.am delete mode 100644 flac/src/libFLAC/include/private/Makefile.am delete mode 100644 flac/src/libFLAC/include/private/all.h delete mode 100644 flac/src/libFLAC/include/private/bitmath.h delete mode 100644 flac/src/libFLAC/include/private/bitreader.h delete mode 100644 flac/src/libFLAC/include/private/bitwriter.h delete mode 100644 flac/src/libFLAC/include/private/cpu.h delete mode 100644 flac/src/libFLAC/include/private/crc.h delete mode 100644 flac/src/libFLAC/include/private/fixed.h delete mode 100644 flac/src/libFLAC/include/private/float.h delete mode 100644 flac/src/libFLAC/include/private/format.h delete mode 100644 flac/src/libFLAC/include/private/lpc.h delete mode 100644 flac/src/libFLAC/include/private/macros.h delete mode 100644 flac/src/libFLAC/include/private/md5.h delete mode 100644 flac/src/libFLAC/include/private/memory.h delete mode 100644 flac/src/libFLAC/include/private/metadata.h delete mode 100644 flac/src/libFLAC/include/private/ogg_decoder_aspect.h delete mode 100644 flac/src/libFLAC/include/private/ogg_encoder_aspect.h delete mode 100644 flac/src/libFLAC/include/private/ogg_helper.h delete mode 100644 flac/src/libFLAC/include/private/ogg_mapping.h delete mode 100644 flac/src/libFLAC/include/private/stream_encoder.h delete mode 100644 flac/src/libFLAC/include/private/stream_encoder_framing.h delete mode 100644 flac/src/libFLAC/include/private/window.h delete mode 100644 flac/src/libFLAC/include/protected/Makefile.am delete mode 100644 flac/src/libFLAC/include/protected/all.h delete mode 100644 flac/src/libFLAC/include/protected/stream_decoder.h delete mode 100644 flac/src/libFLAC/include/protected/stream_encoder.h delete mode 100644 flac/src/libFLAC/libFLAC.m4 delete mode 100644 flac/src/libFLAC/lpc.c delete mode 100644 flac/src/libFLAC/lpc_intrin_avx2.c delete mode 100644 flac/src/libFLAC/lpc_intrin_fma.c delete mode 100644 flac/src/libFLAC/lpc_intrin_neon.c delete mode 100644 flac/src/libFLAC/lpc_intrin_sse2.c delete mode 100644 flac/src/libFLAC/lpc_intrin_sse41.c delete mode 100644 flac/src/libFLAC/md5.c delete mode 100644 flac/src/libFLAC/memory.c delete mode 100644 flac/src/libFLAC/metadata_iterators.c delete mode 100644 flac/src/libFLAC/metadata_object.c delete mode 100644 flac/src/libFLAC/ogg_decoder_aspect.c delete mode 100644 flac/src/libFLAC/ogg_encoder_aspect.c delete mode 100644 flac/src/libFLAC/ogg_helper.c delete mode 100644 flac/src/libFLAC/ogg_mapping.c delete mode 100644 flac/src/libFLAC/stream_decoder.c delete mode 100644 flac/src/libFLAC/stream_encoder.c delete mode 100644 flac/src/libFLAC/stream_encoder_framing.c delete mode 100644 flac/src/libFLAC/stream_encoder_intrin_avx2.c delete mode 100644 flac/src/libFLAC/stream_encoder_intrin_sse2.c delete mode 100644 flac/src/libFLAC/stream_encoder_intrin_ssse3.c delete mode 100644 flac/src/libFLAC/version.rc delete mode 100644 flac/src/libFLAC/window.c delete mode 100644 flac/src/metaflac/CMakeLists.txt delete mode 100644 flac/src/metaflac/Makefile.am delete mode 100644 flac/src/metaflac/main.c delete mode 100644 flac/src/metaflac/operations.c delete mode 100644 flac/src/metaflac/operations.h delete mode 100644 flac/src/metaflac/operations_shorthand.h delete mode 100644 flac/src/metaflac/operations_shorthand_cuesheet.c delete mode 100644 flac/src/metaflac/operations_shorthand_picture.c delete mode 100644 flac/src/metaflac/operations_shorthand_seektable.c delete mode 100644 flac/src/metaflac/operations_shorthand_streaminfo.c delete mode 100644 flac/src/metaflac/operations_shorthand_vorbiscomment.c delete mode 100644 flac/src/metaflac/options.c delete mode 100644 flac/src/metaflac/options.h delete mode 100644 flac/src/metaflac/usage.c delete mode 100644 flac/src/metaflac/usage.h delete mode 100644 flac/src/metaflac/utils.c delete mode 100644 flac/src/metaflac/utils.h delete mode 100644 flac/src/metaflac/version.rc delete mode 100644 flac/src/share/Makefile.am delete mode 100644 flac/src/share/README delete mode 100644 flac/src/share/getopt/CMakeLists.txt delete mode 100644 flac/src/share/getopt/getopt.c delete mode 100644 flac/src/share/getopt/getopt1.c delete mode 100644 flac/src/share/grabbag/CMakeLists.txt delete mode 100644 flac/src/share/grabbag/alloc.c delete mode 100644 flac/src/share/grabbag/cuesheet.c delete mode 100644 flac/src/share/grabbag/file.c delete mode 100644 flac/src/share/grabbag/picture.c delete mode 100644 flac/src/share/grabbag/replaygain.c delete mode 100644 flac/src/share/grabbag/seektable.c delete mode 100644 flac/src/share/grabbag/snprintf.c delete mode 100644 flac/src/share/replaygain_analysis/CMakeLists.txt delete mode 100644 flac/src/share/replaygain_analysis/replaygain_analysis.c delete mode 100644 flac/src/share/replaygain_synthesis/CMakeLists.txt delete mode 100644 flac/src/share/replaygain_synthesis/replaygain_synthesis.c delete mode 100644 flac/src/share/utf8/CMakeLists.txt delete mode 100644 flac/src/share/utf8/charmaps.h delete mode 100644 flac/src/share/utf8/charset.c delete mode 100644 flac/src/share/utf8/charset.h delete mode 100644 flac/src/share/utf8/charset_test.c delete mode 100644 flac/src/share/utf8/iconvert.c delete mode 100644 flac/src/share/utf8/iconvert.h delete mode 100644 flac/src/share/utf8/makemap.c delete mode 100644 flac/src/share/utf8/utf8.c delete mode 100644 flac/src/share/win_utf8_io/win_utf8_io.c delete mode 100644 flac/src/test_grabbag/CMakeLists.txt delete mode 100644 flac/src/test_grabbag/Makefile.am delete mode 100644 flac/src/test_grabbag/cuesheet/CMakeLists.txt delete mode 100644 flac/src/test_grabbag/cuesheet/Makefile.am delete mode 100644 flac/src/test_grabbag/cuesheet/main.c delete mode 100644 flac/src/test_grabbag/picture/CMakeLists.txt delete mode 100644 flac/src/test_grabbag/picture/Makefile.am delete mode 100644 flac/src/test_grabbag/picture/main.c delete mode 100644 flac/src/test_libFLAC++/CMakeLists.txt delete mode 100644 flac/src/test_libFLAC++/Makefile.am delete mode 100644 flac/src/test_libFLAC++/decoders.cpp delete mode 100644 flac/src/test_libFLAC++/decoders.h delete mode 100644 flac/src/test_libFLAC++/encoders.cpp delete mode 100644 flac/src/test_libFLAC++/encoders.h delete mode 100644 flac/src/test_libFLAC++/main.cpp delete mode 100644 flac/src/test_libFLAC++/metadata.cpp delete mode 100644 flac/src/test_libFLAC++/metadata.h delete mode 100644 flac/src/test_libFLAC++/metadata_manip.cpp delete mode 100644 flac/src/test_libFLAC++/metadata_object.cpp delete mode 100644 flac/src/test_libFLAC/CMakeLists.txt delete mode 100644 flac/src/test_libFLAC/Makefile.am delete mode 100644 flac/src/test_libFLAC/bitreader.c delete mode 100644 flac/src/test_libFLAC/bitreader.h delete mode 100644 flac/src/test_libFLAC/bitwriter.c delete mode 100644 flac/src/test_libFLAC/bitwriter.h delete mode 100644 flac/src/test_libFLAC/crc.c delete mode 100644 flac/src/test_libFLAC/crc.h delete mode 100644 flac/src/test_libFLAC/decoders.c delete mode 100644 flac/src/test_libFLAC/decoders.h delete mode 100644 flac/src/test_libFLAC/encoders.c delete mode 100644 flac/src/test_libFLAC/encoders.h delete mode 100644 flac/src/test_libFLAC/endswap.c delete mode 100644 flac/src/test_libFLAC/endswap.h delete mode 100644 flac/src/test_libFLAC/format.c delete mode 100644 flac/src/test_libFLAC/format.h delete mode 100644 flac/src/test_libFLAC/main.c delete mode 100644 flac/src/test_libFLAC/matrix delete mode 100644 flac/src/test_libFLAC/md5.c delete mode 100644 flac/src/test_libFLAC/md5.h delete mode 100644 flac/src/test_libFLAC/metadata.c delete mode 100644 flac/src/test_libFLAC/metadata.h delete mode 100644 flac/src/test_libFLAC/metadata_manip.c delete mode 100644 flac/src/test_libFLAC/metadata_object.c delete mode 100644 flac/src/test_libs_common/CMakeLists.txt delete mode 100644 flac/src/test_libs_common/Makefile.am delete mode 100644 flac/src/test_libs_common/README delete mode 100644 flac/src/test_libs_common/file_utils_flac.c delete mode 100644 flac/src/test_libs_common/metadata_utils.c delete mode 100644 flac/src/test_seeking/CMakeLists.txt delete mode 100644 flac/src/test_seeking/Makefile.am delete mode 100644 flac/src/test_seeking/main.c delete mode 100644 flac/src/test_streams/CMakeLists.txt delete mode 100644 flac/src/test_streams/Makefile.am delete mode 100644 flac/src/test_streams/main.c delete mode 100644 flac/src/utils/Makefile.am delete mode 100644 flac/src/utils/flacdiff/CMakeLists.txt delete mode 100644 flac/src/utils/flacdiff/Makefile.am delete mode 100644 flac/src/utils/flacdiff/main.cpp delete mode 100644 flac/src/utils/flactimer/CMakeLists.txt delete mode 100644 flac/src/utils/flactimer/Makefile.am delete mode 100644 flac/src/utils/flactimer/main.cpp delete mode 100644 flac/src/utils/loudness/loudness.sci delete mode 100644 freetype/LICENSE.TXT delete mode 100644 freetype/README delete mode 100644 freetype/README.git delete mode 100644 freetype/build-freetype.lua delete mode 100644 freetype/builds/amiga/README delete mode 100644 freetype/builds/amiga/include/config/ftconfig.h delete mode 100644 freetype/builds/amiga/include/config/ftmodule.h delete mode 100644 freetype/builds/amiga/makefile.os4 delete mode 100644 freetype/builds/amiga/smakefile delete mode 100644 freetype/builds/amiga/src/base/ftdebug.c delete mode 100644 freetype/builds/amiga/src/base/ftsystem.c delete mode 100644 freetype/builds/ansi/ansi-def.mk delete mode 100644 freetype/builds/ansi/ansi.mk delete mode 100644 freetype/builds/atari/ATARI.H delete mode 100644 freetype/builds/atari/FNames.SIC delete mode 100644 freetype/builds/atari/FREETYPE.PRJ delete mode 100644 freetype/builds/atari/README.TXT delete mode 100644 freetype/builds/atari/deflinejoiner.awk delete mode 100644 freetype/builds/atari/gen-purec-patch.sh delete mode 100644 freetype/builds/beos/beos-def.mk delete mode 100644 freetype/builds/beos/beos.mk delete mode 100644 freetype/builds/beos/detect.mk delete mode 100644 freetype/builds/cmake/FindBrotliDec.cmake delete mode 100644 freetype/builds/cmake/FindHarfBuzz.cmake delete mode 100644 freetype/builds/cmake/iOS.cmake delete mode 100644 freetype/builds/cmake/testbuild.sh delete mode 100644 freetype/builds/compiler/ansi-cc.mk delete mode 100644 freetype/builds/compiler/bcc-dev.mk delete mode 100644 freetype/builds/compiler/bcc.mk delete mode 100644 freetype/builds/compiler/emx.mk delete mode 100644 freetype/builds/compiler/gcc-dev.mk delete mode 100644 freetype/builds/compiler/gcc.mk delete mode 100644 freetype/builds/compiler/intelc.mk delete mode 100644 freetype/builds/compiler/unix-lcc.mk delete mode 100644 freetype/builds/compiler/visualage.mk delete mode 100644 freetype/builds/compiler/visualc.mk delete mode 100644 freetype/builds/compiler/watcom.mk delete mode 100644 freetype/builds/compiler/win-lcc.mk delete mode 100644 freetype/builds/detect.mk delete mode 100644 freetype/builds/dos/detect.mk delete mode 100644 freetype/builds/dos/dos-def.mk delete mode 100644 freetype/builds/dos/dos-emx.mk delete mode 100644 freetype/builds/dos/dos-gcc.mk delete mode 100644 freetype/builds/dos/dos-wat.mk delete mode 100644 freetype/builds/exports.mk delete mode 100644 freetype/builds/freetype.mk delete mode 100644 freetype/builds/link_dos.mk delete mode 100644 freetype/builds/link_std.mk delete mode 100644 freetype/builds/mac/FreeType.m68k_cfm.make.txt delete mode 100644 freetype/builds/mac/FreeType.m68k_far.make.txt delete mode 100644 freetype/builds/mac/FreeType.ppc_carbon.make.txt delete mode 100644 freetype/builds/mac/FreeType.ppc_classic.make.txt delete mode 100644 freetype/builds/mac/README delete mode 100644 freetype/builds/mac/ascii2mpw.py delete mode 100644 freetype/builds/mac/freetype-Info.plist delete mode 100644 freetype/builds/mac/ftlib.prj.xml delete mode 100644 freetype/builds/mac/ftmac.c delete mode 100644 freetype/builds/meson/extract_freetype_version.py delete mode 100644 freetype/builds/meson/extract_libtool_version.py delete mode 100644 freetype/builds/meson/generate_reference_docs.py delete mode 100644 freetype/builds/meson/parse_modules_cfg.py delete mode 100644 freetype/builds/meson/process_ftoption_h.py delete mode 100644 freetype/builds/modules.mk delete mode 100644 freetype/builds/os2/detect.mk delete mode 100644 freetype/builds/os2/os2-def.mk delete mode 100644 freetype/builds/os2/os2-dev.mk delete mode 100644 freetype/builds/os2/os2-gcc.mk delete mode 100644 freetype/builds/symbian/bld.inf delete mode 100644 freetype/builds/symbian/freetype.mmp delete mode 100644 freetype/builds/toplevel.mk delete mode 100644 freetype/builds/unix/.gitignore delete mode 100644 freetype/builds/unix/ax_compare_version.m4 delete mode 100644 freetype/builds/unix/ax_prog_python_version.m4 delete mode 100644 freetype/builds/unix/ax_pthread.m4 delete mode 100644 freetype/builds/unix/configure.raw delete mode 100644 freetype/builds/unix/detect.mk delete mode 100644 freetype/builds/unix/freetype-config.in delete mode 100644 freetype/builds/unix/freetype2.in delete mode 100644 freetype/builds/unix/freetype2.m4 delete mode 100644 freetype/builds/unix/ft-munmap.m4 delete mode 100644 freetype/builds/unix/ftconfig.h.in delete mode 100644 freetype/builds/unix/ftsystem.c delete mode 100644 freetype/builds/unix/install.mk delete mode 100644 freetype/builds/unix/pkg.m4 delete mode 100644 freetype/builds/unix/unix-cc.in delete mode 100644 freetype/builds/unix/unix-def.in delete mode 100644 freetype/builds/unix/unix-dev.mk delete mode 100644 freetype/builds/unix/unix-lcc.mk delete mode 100644 freetype/builds/unix/unix.mk delete mode 100644 freetype/builds/unix/unixddef.mk delete mode 100644 freetype/builds/vms/apinames_vms.bash delete mode 100644 freetype/builds/vms/ftconfig.h delete mode 100644 freetype/builds/vms/ftsystem.c delete mode 100644 freetype/builds/wince/ftdebug.c delete mode 100644 freetype/builds/wince/vc2005-ce/freetype.vcproj delete mode 100644 freetype/builds/wince/vc2005-ce/index.html delete mode 100644 freetype/builds/wince/vc2008-ce/freetype.vcproj delete mode 100644 freetype/builds/wince/vc2008-ce/index.html delete mode 100644 freetype/builds/windows/.gitignore delete mode 100644 freetype/builds/windows/detect.mk delete mode 100644 freetype/builds/windows/ftdebug.c delete mode 100644 freetype/builds/windows/ftsystem.c delete mode 100644 freetype/builds/windows/vc2010/freetype.user.props delete mode 100644 freetype/builds/windows/vc2010/index.html delete mode 100644 freetype/builds/windows/visualc/freetype.dsp delete mode 100644 freetype/builds/windows/visualc/freetype.dsw delete mode 100644 freetype/builds/windows/visualc/freetype.vcproj delete mode 100644 freetype/builds/windows/visualc/index.html delete mode 100644 freetype/builds/windows/visualce/freetype.dsp delete mode 100644 freetype/builds/windows/visualce/freetype.dsw delete mode 100644 freetype/builds/windows/visualce/freetype.vcproj delete mode 100644 freetype/builds/windows/visualce/index.html delete mode 100644 freetype/builds/windows/w32-bcc.mk delete mode 100644 freetype/builds/windows/w32-bccd.mk delete mode 100644 freetype/builds/windows/w32-dev.mk delete mode 100644 freetype/builds/windows/w32-gcc.mk delete mode 100644 freetype/builds/windows/w32-icc.mk delete mode 100644 freetype/builds/windows/w32-intl.mk delete mode 100644 freetype/builds/windows/w32-lcc.mk delete mode 100644 freetype/builds/windows/w32-mingw32.mk delete mode 100644 freetype/builds/windows/w32-vcc.mk delete mode 100644 freetype/builds/windows/w32-wat.mk delete mode 100644 freetype/builds/windows/win32-def.mk delete mode 100644 freetype/devel/ft2build.h delete mode 100644 freetype/devel/ftoption.h delete mode 100644 freetype/docs/.gitignore delete mode 100644 freetype/docs/CHANGES delete mode 100644 freetype/docs/CMAKE delete mode 100644 freetype/docs/CUSTOMIZE delete mode 100644 freetype/docs/DEBUG delete mode 100644 freetype/docs/DOCGUIDE delete mode 100644 freetype/docs/FTL.TXT delete mode 100644 freetype/docs/GPLv2.TXT delete mode 100644 freetype/docs/INSTALL delete mode 100644 freetype/docs/INSTALL.ANY delete mode 100644 freetype/docs/INSTALL.CROSS delete mode 100644 freetype/docs/INSTALL.GNU delete mode 100644 freetype/docs/INSTALL.MAC delete mode 100644 freetype/docs/INSTALL.UNIX delete mode 100644 freetype/docs/INSTALL.VMS delete mode 100644 freetype/docs/MAKEPP delete mode 100644 freetype/docs/PROBLEMS delete mode 100644 freetype/docs/README delete mode 100644 freetype/docs/TODO delete mode 100644 freetype/docs/VERSIONS.TXT delete mode 100644 freetype/docs/formats.txt delete mode 100644 freetype/docs/freetype-config.1 delete mode 100644 freetype/docs/markdown/images/favico.ico delete mode 100644 freetype/docs/markdown/javascripts/extra.js delete mode 100644 freetype/docs/markdown/stylesheets/extra.css delete mode 100644 freetype/docs/oldlogs/ChangeLog.20 delete mode 100644 freetype/docs/oldlogs/ChangeLog.21 delete mode 100644 freetype/docs/oldlogs/ChangeLog.210 delete mode 100644 freetype/docs/oldlogs/ChangeLog.22 delete mode 100644 freetype/docs/oldlogs/ChangeLog.23 delete mode 100644 freetype/docs/oldlogs/ChangeLog.24 delete mode 100644 freetype/docs/oldlogs/ChangeLog.25 delete mode 100644 freetype/docs/oldlogs/ChangeLog.26 delete mode 100644 freetype/docs/oldlogs/ChangeLog.27 delete mode 100644 freetype/docs/oldlogs/ChangeLog.28 delete mode 100644 freetype/docs/oldlogs/ChangeLog.29 delete mode 100644 freetype/docs/raster.txt delete mode 100644 freetype/docs/release delete mode 100644 freetype/include/freetype/config/ftconfig.h delete mode 100644 freetype/include/freetype/config/ftheader.h delete mode 100644 freetype/include/freetype/config/ftmodule.h delete mode 100644 freetype/include/freetype/config/ftoption.h delete mode 100644 freetype/include/freetype/config/ftstdlib.h delete mode 100644 freetype/include/freetype/config/integer-types.h delete mode 100644 freetype/include/freetype/config/mac-support.h delete mode 100644 freetype/include/freetype/config/public-macros.h delete mode 100644 freetype/include/freetype/freetype.h delete mode 100644 freetype/include/freetype/ftadvanc.h delete mode 100644 freetype/include/freetype/ftbbox.h delete mode 100644 freetype/include/freetype/ftbdf.h delete mode 100644 freetype/include/freetype/ftbitmap.h delete mode 100644 freetype/include/freetype/ftbzip2.h delete mode 100644 freetype/include/freetype/ftcache.h delete mode 100644 freetype/include/freetype/ftchapters.h delete mode 100644 freetype/include/freetype/ftcid.h delete mode 100644 freetype/include/freetype/ftcolor.h delete mode 100644 freetype/include/freetype/ftdriver.h delete mode 100644 freetype/include/freetype/fterrdef.h delete mode 100644 freetype/include/freetype/fterrors.h delete mode 100644 freetype/include/freetype/ftfntfmt.h delete mode 100644 freetype/include/freetype/ftgasp.h delete mode 100644 freetype/include/freetype/ftglyph.h delete mode 100644 freetype/include/freetype/ftgxval.h delete mode 100644 freetype/include/freetype/ftgzip.h delete mode 100644 freetype/include/freetype/ftimage.h delete mode 100644 freetype/include/freetype/ftincrem.h delete mode 100644 freetype/include/freetype/ftlcdfil.h delete mode 100644 freetype/include/freetype/ftlist.h delete mode 100644 freetype/include/freetype/ftlogging.h delete mode 100644 freetype/include/freetype/ftlzw.h delete mode 100644 freetype/include/freetype/ftmac.h delete mode 100644 freetype/include/freetype/ftmm.h delete mode 100644 freetype/include/freetype/ftmodapi.h delete mode 100644 freetype/include/freetype/ftmoderr.h delete mode 100644 freetype/include/freetype/ftotval.h delete mode 100644 freetype/include/freetype/ftoutln.h delete mode 100644 freetype/include/freetype/ftparams.h delete mode 100644 freetype/include/freetype/ftpfr.h delete mode 100644 freetype/include/freetype/ftrender.h delete mode 100644 freetype/include/freetype/ftsizes.h delete mode 100644 freetype/include/freetype/ftsnames.h delete mode 100644 freetype/include/freetype/ftstroke.h delete mode 100644 freetype/include/freetype/ftsynth.h delete mode 100644 freetype/include/freetype/ftsystem.h delete mode 100644 freetype/include/freetype/fttrigon.h delete mode 100644 freetype/include/freetype/fttypes.h delete mode 100644 freetype/include/freetype/ftwinfnt.h delete mode 100644 freetype/include/freetype/internal/autohint.h delete mode 100644 freetype/include/freetype/internal/cffotypes.h delete mode 100644 freetype/include/freetype/internal/cfftypes.h delete mode 100644 freetype/include/freetype/internal/compiler-macros.h delete mode 100644 freetype/include/freetype/internal/ftcalc.h delete mode 100644 freetype/include/freetype/internal/ftdebug.h delete mode 100644 freetype/include/freetype/internal/ftdrv.h delete mode 100644 freetype/include/freetype/internal/ftgloadr.h delete mode 100644 freetype/include/freetype/internal/fthash.h delete mode 100644 freetype/include/freetype/internal/ftmemory.h delete mode 100644 freetype/include/freetype/internal/ftmmtypes.h delete mode 100644 freetype/include/freetype/internal/ftobjs.h delete mode 100644 freetype/include/freetype/internal/ftpsprop.h delete mode 100644 freetype/include/freetype/internal/ftrfork.h delete mode 100644 freetype/include/freetype/internal/ftserv.h delete mode 100644 freetype/include/freetype/internal/ftstream.h delete mode 100644 freetype/include/freetype/internal/fttrace.h delete mode 100644 freetype/include/freetype/internal/ftvalid.h delete mode 100644 freetype/include/freetype/internal/psaux.h delete mode 100644 freetype/include/freetype/internal/pshints.h delete mode 100644 freetype/include/freetype/internal/services/svbdf.h delete mode 100644 freetype/include/freetype/internal/services/svcfftl.h delete mode 100644 freetype/include/freetype/internal/services/svcid.h delete mode 100644 freetype/include/freetype/internal/services/svfntfmt.h delete mode 100644 freetype/include/freetype/internal/services/svgldict.h delete mode 100644 freetype/include/freetype/internal/services/svgxval.h delete mode 100644 freetype/include/freetype/internal/services/svkern.h delete mode 100644 freetype/include/freetype/internal/services/svmetric.h delete mode 100644 freetype/include/freetype/internal/services/svmm.h delete mode 100644 freetype/include/freetype/internal/services/svotval.h delete mode 100644 freetype/include/freetype/internal/services/svpfr.h delete mode 100644 freetype/include/freetype/internal/services/svpostnm.h delete mode 100644 freetype/include/freetype/internal/services/svprop.h delete mode 100644 freetype/include/freetype/internal/services/svpscmap.h delete mode 100644 freetype/include/freetype/internal/services/svpsinfo.h delete mode 100644 freetype/include/freetype/internal/services/svsfnt.h delete mode 100644 freetype/include/freetype/internal/services/svttcmap.h delete mode 100644 freetype/include/freetype/internal/services/svtteng.h delete mode 100644 freetype/include/freetype/internal/services/svttglyf.h delete mode 100644 freetype/include/freetype/internal/services/svwinfnt.h delete mode 100644 freetype/include/freetype/internal/sfnt.h delete mode 100644 freetype/include/freetype/internal/svginterface.h delete mode 100644 freetype/include/freetype/internal/t1types.h delete mode 100644 freetype/include/freetype/internal/tttypes.h delete mode 100644 freetype/include/freetype/internal/wofftypes.h delete mode 100644 freetype/include/freetype/otsvg.h delete mode 100644 freetype/include/freetype/t1tables.h delete mode 100644 freetype/include/freetype/ttnameid.h delete mode 100644 freetype/include/freetype/tttables.h delete mode 100644 freetype/include/freetype/tttags.h delete mode 100644 freetype/include/ft2build.h delete mode 100644 freetype/src/autofit/afblue.c delete mode 100644 freetype/src/autofit/afblue.cin delete mode 100644 freetype/src/autofit/afblue.dat delete mode 100644 freetype/src/autofit/afblue.h delete mode 100644 freetype/src/autofit/afblue.hin delete mode 100644 freetype/src/autofit/afcjk.c delete mode 100644 freetype/src/autofit/afcjk.h delete mode 100644 freetype/src/autofit/afcover.h delete mode 100644 freetype/src/autofit/afdummy.c delete mode 100644 freetype/src/autofit/afdummy.h delete mode 100644 freetype/src/autofit/aferrors.h delete mode 100644 freetype/src/autofit/afglobal.c delete mode 100644 freetype/src/autofit/afglobal.h delete mode 100644 freetype/src/autofit/afhints.c delete mode 100644 freetype/src/autofit/afhints.h delete mode 100644 freetype/src/autofit/afindic.c delete mode 100644 freetype/src/autofit/afindic.h delete mode 100644 freetype/src/autofit/aflatin.c delete mode 100644 freetype/src/autofit/aflatin.h delete mode 100644 freetype/src/autofit/afloader.c delete mode 100644 freetype/src/autofit/afloader.h delete mode 100644 freetype/src/autofit/afmodule.c delete mode 100644 freetype/src/autofit/afmodule.h delete mode 100644 freetype/src/autofit/afranges.c delete mode 100644 freetype/src/autofit/afranges.h delete mode 100644 freetype/src/autofit/afscript.h delete mode 100644 freetype/src/autofit/afshaper.c delete mode 100644 freetype/src/autofit/afshaper.h delete mode 100644 freetype/src/autofit/afstyles.h delete mode 100644 freetype/src/autofit/aftypes.h delete mode 100644 freetype/src/autofit/afws-decl.h delete mode 100644 freetype/src/autofit/afws-iter.h delete mode 100644 freetype/src/autofit/autofit.c delete mode 100644 freetype/src/autofit/ft-hb.c delete mode 100644 freetype/src/autofit/ft-hb.h delete mode 100644 freetype/src/autofit/module.mk delete mode 100644 freetype/src/autofit/rules.mk delete mode 100644 freetype/src/base/ftadvanc.c delete mode 100644 freetype/src/base/ftbase.c delete mode 100644 freetype/src/base/ftbase.h delete mode 100644 freetype/src/base/ftbbox.c delete mode 100644 freetype/src/base/ftbdf.c delete mode 100644 freetype/src/base/ftbitmap.c delete mode 100644 freetype/src/base/ftcalc.c delete mode 100644 freetype/src/base/ftcid.c delete mode 100644 freetype/src/base/ftcolor.c delete mode 100644 freetype/src/base/ftdbgmem.c delete mode 100644 freetype/src/base/ftdebug.c delete mode 100644 freetype/src/base/fterrors.c delete mode 100644 freetype/src/base/ftfntfmt.c delete mode 100644 freetype/src/base/ftfstype.c delete mode 100644 freetype/src/base/ftgasp.c delete mode 100644 freetype/src/base/ftgloadr.c delete mode 100644 freetype/src/base/ftglyph.c delete mode 100644 freetype/src/base/ftgxval.c delete mode 100644 freetype/src/base/fthash.c delete mode 100644 freetype/src/base/ftinit.c delete mode 100644 freetype/src/base/ftlcdfil.c delete mode 100644 freetype/src/base/ftmac.c delete mode 100644 freetype/src/base/ftmm.c delete mode 100644 freetype/src/base/ftobjs.c delete mode 100644 freetype/src/base/ftotval.c delete mode 100644 freetype/src/base/ftoutln.c delete mode 100644 freetype/src/base/ftpatent.c delete mode 100644 freetype/src/base/ftpfr.c delete mode 100644 freetype/src/base/ftpsprop.c delete mode 100644 freetype/src/base/ftrfork.c delete mode 100644 freetype/src/base/ftsnames.c delete mode 100644 freetype/src/base/ftstream.c delete mode 100644 freetype/src/base/ftstroke.c delete mode 100644 freetype/src/base/ftsynth.c delete mode 100644 freetype/src/base/ftsystem.c delete mode 100644 freetype/src/base/fttrigon.c delete mode 100644 freetype/src/base/fttype1.c delete mode 100644 freetype/src/base/ftutil.c delete mode 100644 freetype/src/base/ftver.rc delete mode 100644 freetype/src/base/ftwinfnt.c delete mode 100644 freetype/src/base/md5.c delete mode 100644 freetype/src/base/md5.h delete mode 100644 freetype/src/base/rules.mk delete mode 100644 freetype/src/bdf/README delete mode 100644 freetype/src/bdf/bdf.c delete mode 100644 freetype/src/bdf/bdf.h delete mode 100644 freetype/src/bdf/bdfdrivr.c delete mode 100644 freetype/src/bdf/bdfdrivr.h delete mode 100644 freetype/src/bdf/bdferror.h delete mode 100644 freetype/src/bdf/bdflib.c delete mode 100644 freetype/src/bdf/module.mk delete mode 100644 freetype/src/bdf/rules.mk delete mode 100644 freetype/src/bzip2/ftbzip2.c delete mode 100644 freetype/src/bzip2/rules.mk delete mode 100644 freetype/src/cache/ftcache.c delete mode 100644 freetype/src/cache/ftcbasic.c delete mode 100644 freetype/src/cache/ftccache.c delete mode 100644 freetype/src/cache/ftccache.h delete mode 100644 freetype/src/cache/ftccback.h delete mode 100644 freetype/src/cache/ftccmap.c delete mode 100644 freetype/src/cache/ftcerror.h delete mode 100644 freetype/src/cache/ftcglyph.c delete mode 100644 freetype/src/cache/ftcglyph.h delete mode 100644 freetype/src/cache/ftcimage.c delete mode 100644 freetype/src/cache/ftcimage.h delete mode 100644 freetype/src/cache/ftcmanag.c delete mode 100644 freetype/src/cache/ftcmanag.h delete mode 100644 freetype/src/cache/ftcmru.c delete mode 100644 freetype/src/cache/ftcmru.h delete mode 100644 freetype/src/cache/ftcsbits.c delete mode 100644 freetype/src/cache/ftcsbits.h delete mode 100644 freetype/src/cache/rules.mk delete mode 100644 freetype/src/cff/cff.c delete mode 100644 freetype/src/cff/cffcmap.c delete mode 100644 freetype/src/cff/cffcmap.h delete mode 100644 freetype/src/cff/cffdrivr.c delete mode 100644 freetype/src/cff/cffdrivr.h delete mode 100644 freetype/src/cff/cfferrs.h delete mode 100644 freetype/src/cff/cffgload.c delete mode 100644 freetype/src/cff/cffgload.h delete mode 100644 freetype/src/cff/cffload.c delete mode 100644 freetype/src/cff/cffload.h delete mode 100644 freetype/src/cff/cffobjs.c delete mode 100644 freetype/src/cff/cffobjs.h delete mode 100644 freetype/src/cff/cffparse.c delete mode 100644 freetype/src/cff/cffparse.h delete mode 100644 freetype/src/cff/cfftoken.h delete mode 100644 freetype/src/cff/module.mk delete mode 100644 freetype/src/cff/rules.mk delete mode 100644 freetype/src/cid/ciderrs.h delete mode 100644 freetype/src/cid/cidgload.c delete mode 100644 freetype/src/cid/cidgload.h delete mode 100644 freetype/src/cid/cidload.c delete mode 100644 freetype/src/cid/cidload.h delete mode 100644 freetype/src/cid/cidobjs.c delete mode 100644 freetype/src/cid/cidobjs.h delete mode 100644 freetype/src/cid/cidparse.c delete mode 100644 freetype/src/cid/cidparse.h delete mode 100644 freetype/src/cid/cidriver.c delete mode 100644 freetype/src/cid/cidriver.h delete mode 100644 freetype/src/cid/cidtoken.h delete mode 100644 freetype/src/cid/module.mk delete mode 100644 freetype/src/cid/rules.mk delete mode 100644 freetype/src/cid/type1cid.c delete mode 100644 freetype/src/dlg/dlgwrap.c delete mode 100644 freetype/src/dlg/rules.mk delete mode 100644 freetype/src/gxvalid/README delete mode 100644 freetype/src/gxvalid/gxvalid.c delete mode 100644 freetype/src/gxvalid/gxvalid.h delete mode 100644 freetype/src/gxvalid/gxvbsln.c delete mode 100644 freetype/src/gxvalid/gxvcommn.c delete mode 100644 freetype/src/gxvalid/gxvcommn.h delete mode 100644 freetype/src/gxvalid/gxverror.h delete mode 100644 freetype/src/gxvalid/gxvfeat.c delete mode 100644 freetype/src/gxvalid/gxvfeat.h delete mode 100644 freetype/src/gxvalid/gxvfgen.c delete mode 100644 freetype/src/gxvalid/gxvjust.c delete mode 100644 freetype/src/gxvalid/gxvkern.c delete mode 100644 freetype/src/gxvalid/gxvlcar.c delete mode 100644 freetype/src/gxvalid/gxvmod.c delete mode 100644 freetype/src/gxvalid/gxvmod.h delete mode 100644 freetype/src/gxvalid/gxvmort.c delete mode 100644 freetype/src/gxvalid/gxvmort.h delete mode 100644 freetype/src/gxvalid/gxvmort0.c delete mode 100644 freetype/src/gxvalid/gxvmort1.c delete mode 100644 freetype/src/gxvalid/gxvmort2.c delete mode 100644 freetype/src/gxvalid/gxvmort4.c delete mode 100644 freetype/src/gxvalid/gxvmort5.c delete mode 100644 freetype/src/gxvalid/gxvmorx.c delete mode 100644 freetype/src/gxvalid/gxvmorx.h delete mode 100644 freetype/src/gxvalid/gxvmorx0.c delete mode 100644 freetype/src/gxvalid/gxvmorx1.c delete mode 100644 freetype/src/gxvalid/gxvmorx2.c delete mode 100644 freetype/src/gxvalid/gxvmorx4.c delete mode 100644 freetype/src/gxvalid/gxvmorx5.c delete mode 100644 freetype/src/gxvalid/gxvopbd.c delete mode 100644 freetype/src/gxvalid/gxvprop.c delete mode 100644 freetype/src/gxvalid/gxvtrak.c delete mode 100644 freetype/src/gxvalid/module.mk delete mode 100644 freetype/src/gxvalid/rules.mk delete mode 100644 freetype/src/gzip/README.freetype delete mode 100644 freetype/src/gzip/adler32.c delete mode 100644 freetype/src/gzip/crc32.c delete mode 100644 freetype/src/gzip/crc32.h delete mode 100644 freetype/src/gzip/ftgzip.c delete mode 100644 freetype/src/gzip/ftzconf.h delete mode 100644 freetype/src/gzip/gzguts.h delete mode 100644 freetype/src/gzip/inffast.c delete mode 100644 freetype/src/gzip/inffast.h delete mode 100644 freetype/src/gzip/inffixed.h delete mode 100644 freetype/src/gzip/inflate.c delete mode 100644 freetype/src/gzip/inflate.h delete mode 100644 freetype/src/gzip/inftrees.c delete mode 100644 freetype/src/gzip/inftrees.h delete mode 100644 freetype/src/gzip/patches/freetype-zlib.diff delete mode 100644 freetype/src/gzip/rules.mk delete mode 100644 freetype/src/gzip/zlib.h delete mode 100644 freetype/src/gzip/zutil.c delete mode 100644 freetype/src/gzip/zutil.h delete mode 100644 freetype/src/lzw/ftlzw.c delete mode 100644 freetype/src/lzw/ftzopen.c delete mode 100644 freetype/src/lzw/ftzopen.h delete mode 100644 freetype/src/lzw/rules.mk delete mode 100644 freetype/src/otvalid/module.mk delete mode 100644 freetype/src/otvalid/otvalid.c delete mode 100644 freetype/src/otvalid/otvalid.h delete mode 100644 freetype/src/otvalid/otvbase.c delete mode 100644 freetype/src/otvalid/otvcommn.c delete mode 100644 freetype/src/otvalid/otvcommn.h delete mode 100644 freetype/src/otvalid/otverror.h delete mode 100644 freetype/src/otvalid/otvgdef.c delete mode 100644 freetype/src/otvalid/otvgpos.c delete mode 100644 freetype/src/otvalid/otvgpos.h delete mode 100644 freetype/src/otvalid/otvgsub.c delete mode 100644 freetype/src/otvalid/otvjstf.c delete mode 100644 freetype/src/otvalid/otvmath.c delete mode 100644 freetype/src/otvalid/otvmod.c delete mode 100644 freetype/src/otvalid/otvmod.h delete mode 100644 freetype/src/otvalid/rules.mk delete mode 100644 freetype/src/pcf/README delete mode 100644 freetype/src/pcf/module.mk delete mode 100644 freetype/src/pcf/pcf.c delete mode 100644 freetype/src/pcf/pcf.h delete mode 100644 freetype/src/pcf/pcfdrivr.c delete mode 100644 freetype/src/pcf/pcfdrivr.h delete mode 100644 freetype/src/pcf/pcferror.h delete mode 100644 freetype/src/pcf/pcfread.c delete mode 100644 freetype/src/pcf/pcfread.h delete mode 100644 freetype/src/pcf/pcfutil.c delete mode 100644 freetype/src/pcf/pcfutil.h delete mode 100644 freetype/src/pcf/rules.mk delete mode 100644 freetype/src/pfr/module.mk delete mode 100644 freetype/src/pfr/pfr.c delete mode 100644 freetype/src/pfr/pfrcmap.c delete mode 100644 freetype/src/pfr/pfrcmap.h delete mode 100644 freetype/src/pfr/pfrdrivr.c delete mode 100644 freetype/src/pfr/pfrdrivr.h delete mode 100644 freetype/src/pfr/pfrerror.h delete mode 100644 freetype/src/pfr/pfrgload.c delete mode 100644 freetype/src/pfr/pfrgload.h delete mode 100644 freetype/src/pfr/pfrload.c delete mode 100644 freetype/src/pfr/pfrload.h delete mode 100644 freetype/src/pfr/pfrobjs.c delete mode 100644 freetype/src/pfr/pfrobjs.h delete mode 100644 freetype/src/pfr/pfrsbit.c delete mode 100644 freetype/src/pfr/pfrsbit.h delete mode 100644 freetype/src/pfr/pfrtypes.h delete mode 100644 freetype/src/pfr/rules.mk delete mode 100644 freetype/src/psaux/afmparse.c delete mode 100644 freetype/src/psaux/afmparse.h delete mode 100644 freetype/src/psaux/cffdecode.c delete mode 100644 freetype/src/psaux/cffdecode.h delete mode 100644 freetype/src/psaux/module.mk delete mode 100644 freetype/src/psaux/psarrst.c delete mode 100644 freetype/src/psaux/psarrst.h delete mode 100644 freetype/src/psaux/psaux.c delete mode 100644 freetype/src/psaux/psauxerr.h delete mode 100644 freetype/src/psaux/psauxmod.c delete mode 100644 freetype/src/psaux/psauxmod.h delete mode 100644 freetype/src/psaux/psblues.c delete mode 100644 freetype/src/psaux/psblues.h delete mode 100644 freetype/src/psaux/psconv.c delete mode 100644 freetype/src/psaux/psconv.h delete mode 100644 freetype/src/psaux/pserror.c delete mode 100644 freetype/src/psaux/pserror.h delete mode 100644 freetype/src/psaux/psfixed.h delete mode 100644 freetype/src/psaux/psfont.c delete mode 100644 freetype/src/psaux/psfont.h delete mode 100644 freetype/src/psaux/psft.c delete mode 100644 freetype/src/psaux/psft.h delete mode 100644 freetype/src/psaux/psglue.h delete mode 100644 freetype/src/psaux/pshints.c delete mode 100644 freetype/src/psaux/pshints.h delete mode 100644 freetype/src/psaux/psintrp.c delete mode 100644 freetype/src/psaux/psintrp.h delete mode 100644 freetype/src/psaux/psobjs.c delete mode 100644 freetype/src/psaux/psobjs.h delete mode 100644 freetype/src/psaux/psread.c delete mode 100644 freetype/src/psaux/psread.h delete mode 100644 freetype/src/psaux/psstack.c delete mode 100644 freetype/src/psaux/psstack.h delete mode 100644 freetype/src/psaux/pstypes.h delete mode 100644 freetype/src/psaux/rules.mk delete mode 100644 freetype/src/psaux/t1cmap.c delete mode 100644 freetype/src/psaux/t1cmap.h delete mode 100644 freetype/src/psaux/t1decode.c delete mode 100644 freetype/src/psaux/t1decode.h delete mode 100644 freetype/src/pshinter/module.mk delete mode 100644 freetype/src/pshinter/pshalgo.c delete mode 100644 freetype/src/pshinter/pshalgo.h delete mode 100644 freetype/src/pshinter/pshglob.c delete mode 100644 freetype/src/pshinter/pshglob.h delete mode 100644 freetype/src/pshinter/pshinter.c delete mode 100644 freetype/src/pshinter/pshmod.c delete mode 100644 freetype/src/pshinter/pshmod.h delete mode 100644 freetype/src/pshinter/pshnterr.h delete mode 100644 freetype/src/pshinter/pshrec.c delete mode 100644 freetype/src/pshinter/pshrec.h delete mode 100644 freetype/src/pshinter/rules.mk delete mode 100644 freetype/src/psnames/module.mk delete mode 100644 freetype/src/psnames/psmodule.c delete mode 100644 freetype/src/psnames/psmodule.h delete mode 100644 freetype/src/psnames/psnamerr.h delete mode 100644 freetype/src/psnames/psnames.c delete mode 100644 freetype/src/psnames/pstables.h delete mode 100644 freetype/src/psnames/rules.mk delete mode 100644 freetype/src/raster/ftmisc.h delete mode 100644 freetype/src/raster/ftraster.c delete mode 100644 freetype/src/raster/ftraster.h delete mode 100644 freetype/src/raster/ftrend1.c delete mode 100644 freetype/src/raster/ftrend1.h delete mode 100644 freetype/src/raster/module.mk delete mode 100644 freetype/src/raster/raster.c delete mode 100644 freetype/src/raster/rasterrs.h delete mode 100644 freetype/src/raster/rules.mk delete mode 100644 freetype/src/sdf/ftbsdf.c delete mode 100644 freetype/src/sdf/ftsdf.c delete mode 100644 freetype/src/sdf/ftsdf.h delete mode 100644 freetype/src/sdf/ftsdfcommon.c delete mode 100644 freetype/src/sdf/ftsdfcommon.h delete mode 100644 freetype/src/sdf/ftsdferrs.h delete mode 100644 freetype/src/sdf/ftsdfrend.c delete mode 100644 freetype/src/sdf/ftsdfrend.h delete mode 100644 freetype/src/sdf/module.mk delete mode 100644 freetype/src/sdf/rules.mk delete mode 100644 freetype/src/sdf/sdf.c delete mode 100644 freetype/src/sfnt/module.mk delete mode 100644 freetype/src/sfnt/pngshim.c delete mode 100644 freetype/src/sfnt/pngshim.h delete mode 100644 freetype/src/sfnt/rules.mk delete mode 100644 freetype/src/sfnt/sfdriver.c delete mode 100644 freetype/src/sfnt/sfdriver.h delete mode 100644 freetype/src/sfnt/sferrors.h delete mode 100644 freetype/src/sfnt/sfnt.c delete mode 100644 freetype/src/sfnt/sfobjs.c delete mode 100644 freetype/src/sfnt/sfobjs.h delete mode 100644 freetype/src/sfnt/sfwoff.c delete mode 100644 freetype/src/sfnt/sfwoff.h delete mode 100644 freetype/src/sfnt/sfwoff2.c delete mode 100644 freetype/src/sfnt/sfwoff2.h delete mode 100644 freetype/src/sfnt/ttbdf.c delete mode 100644 freetype/src/sfnt/ttbdf.h delete mode 100644 freetype/src/sfnt/ttcmap.c delete mode 100644 freetype/src/sfnt/ttcmap.h delete mode 100644 freetype/src/sfnt/ttcmapc.h delete mode 100644 freetype/src/sfnt/ttcolr.c delete mode 100644 freetype/src/sfnt/ttcolr.h delete mode 100644 freetype/src/sfnt/ttcpal.c delete mode 100644 freetype/src/sfnt/ttcpal.h delete mode 100644 freetype/src/sfnt/ttkern.c delete mode 100644 freetype/src/sfnt/ttkern.h delete mode 100644 freetype/src/sfnt/ttload.c delete mode 100644 freetype/src/sfnt/ttload.h delete mode 100644 freetype/src/sfnt/ttmtx.c delete mode 100644 freetype/src/sfnt/ttmtx.h delete mode 100644 freetype/src/sfnt/ttpost.c delete mode 100644 freetype/src/sfnt/ttpost.h delete mode 100644 freetype/src/sfnt/ttsbit.c delete mode 100644 freetype/src/sfnt/ttsbit.h delete mode 100644 freetype/src/sfnt/ttsvg.c delete mode 100644 freetype/src/sfnt/ttsvg.h delete mode 100644 freetype/src/sfnt/woff2tags.c delete mode 100644 freetype/src/sfnt/woff2tags.h delete mode 100644 freetype/src/smooth/ftgrays.c delete mode 100644 freetype/src/smooth/ftgrays.h delete mode 100644 freetype/src/smooth/ftsmerrs.h delete mode 100644 freetype/src/smooth/ftsmooth.c delete mode 100644 freetype/src/smooth/ftsmooth.h delete mode 100644 freetype/src/smooth/module.mk delete mode 100644 freetype/src/smooth/rules.mk delete mode 100644 freetype/src/smooth/smooth.c delete mode 100644 freetype/src/svg/ftsvg.c delete mode 100644 freetype/src/svg/ftsvg.h delete mode 100644 freetype/src/svg/module.mk delete mode 100644 freetype/src/svg/rules.mk delete mode 100644 freetype/src/svg/svg.c delete mode 100644 freetype/src/svg/svgtypes.h delete mode 100644 freetype/src/tools/afblue.pl delete mode 100644 freetype/src/tools/apinames.c delete mode 100644 freetype/src/tools/chktrcmp.py delete mode 100644 freetype/src/tools/cordic.py delete mode 100644 freetype/src/tools/ftrandom/README delete mode 100644 freetype/src/tools/ftrandom/ftrandom.c delete mode 100644 freetype/src/tools/glnames.py delete mode 100644 freetype/src/tools/make_distribution_archives.py delete mode 100644 freetype/src/tools/no-copyright delete mode 100644 freetype/src/tools/test_afm.c delete mode 100644 freetype/src/tools/test_bbox.c delete mode 100644 freetype/src/tools/test_trig.c delete mode 100644 freetype/src/tools/update-copyright delete mode 100644 freetype/src/tools/update-copyright-year delete mode 100644 freetype/src/tools/vms_shorten_symbol.c delete mode 100644 freetype/src/truetype/module.mk delete mode 100644 freetype/src/truetype/rules.mk delete mode 100644 freetype/src/truetype/truetype.c delete mode 100644 freetype/src/truetype/ttdriver.c delete mode 100644 freetype/src/truetype/ttdriver.h delete mode 100644 freetype/src/truetype/tterrors.h delete mode 100644 freetype/src/truetype/ttgload.c delete mode 100644 freetype/src/truetype/ttgload.h delete mode 100644 freetype/src/truetype/ttgxvar.c delete mode 100644 freetype/src/truetype/ttgxvar.h delete mode 100644 freetype/src/truetype/ttinterp.c delete mode 100644 freetype/src/truetype/ttinterp.h delete mode 100644 freetype/src/truetype/ttobjs.c delete mode 100644 freetype/src/truetype/ttobjs.h delete mode 100644 freetype/src/truetype/ttpload.c delete mode 100644 freetype/src/truetype/ttpload.h delete mode 100644 freetype/src/type1/module.mk delete mode 100644 freetype/src/type1/rules.mk delete mode 100644 freetype/src/type1/t1afm.c delete mode 100644 freetype/src/type1/t1afm.h delete mode 100644 freetype/src/type1/t1driver.c delete mode 100644 freetype/src/type1/t1driver.h delete mode 100644 freetype/src/type1/t1errors.h delete mode 100644 freetype/src/type1/t1gload.c delete mode 100644 freetype/src/type1/t1gload.h delete mode 100644 freetype/src/type1/t1load.c delete mode 100644 freetype/src/type1/t1load.h delete mode 100644 freetype/src/type1/t1objs.c delete mode 100644 freetype/src/type1/t1objs.h delete mode 100644 freetype/src/type1/t1parse.c delete mode 100644 freetype/src/type1/t1parse.h delete mode 100644 freetype/src/type1/t1tokens.h delete mode 100644 freetype/src/type1/type1.c delete mode 100644 freetype/src/type42/module.mk delete mode 100644 freetype/src/type42/rules.mk delete mode 100644 freetype/src/type42/t42drivr.c delete mode 100644 freetype/src/type42/t42drivr.h delete mode 100644 freetype/src/type42/t42error.h delete mode 100644 freetype/src/type42/t42objs.c delete mode 100644 freetype/src/type42/t42objs.h delete mode 100644 freetype/src/type42/t42parse.c delete mode 100644 freetype/src/type42/t42parse.h delete mode 100644 freetype/src/type42/t42types.h delete mode 100644 freetype/src/type42/type42.c delete mode 100644 freetype/src/winfonts/fnterrs.h delete mode 100644 freetype/src/winfonts/module.mk delete mode 100644 freetype/src/winfonts/rules.mk delete mode 100644 freetype/src/winfonts/winfnt.c delete mode 100644 freetype/src/winfonts/winfnt.h delete mode 100644 freetype/subprojects/harfbuzz.wrap delete mode 100644 freetype/subprojects/libpng.wrap delete mode 100644 freetype/subprojects/zlib.wrap delete mode 100644 imgui-sfml/LICENSE delete mode 100644 imgui-sfml/LICENSE.txt delete mode 100644 imgui-sfml/README.md delete mode 100644 imgui-sfml/build-imgui-sfml.lua delete mode 100644 imgui-sfml/imconfig-SFML.h delete mode 100644 imgui-sfml/imconfig.h delete mode 100644 imgui-sfml/imgui-SFML.cpp delete mode 100644 imgui-sfml/imgui-SFML.h delete mode 100644 imgui-sfml/imgui-SFML_export.h delete mode 100644 imgui-sfml/imgui.cpp delete mode 100644 imgui-sfml/imgui.h delete mode 100644 imgui-sfml/imgui_demo.cpp delete mode 100644 imgui-sfml/imgui_draw.cpp delete mode 100644 imgui-sfml/imgui_internal.h delete mode 100644 imgui-sfml/imgui_tables.cpp delete mode 100644 imgui-sfml/imgui_widgets.cpp delete mode 100644 imgui-sfml/imstb_rectpack.h delete mode 100644 imgui-sfml/imstb_textedit.h delete mode 100644 imgui-sfml/imstb_truetype.h delete mode 100644 imgui-sfml/misc/README.txt delete mode 100644 imgui-sfml/misc/cpp/README.txt delete mode 100644 imgui-sfml/misc/cpp/imgui_stdlib.cpp delete mode 100644 imgui-sfml/misc/cpp/imgui_stdlib.h delete mode 100644 imgui-sfml/misc/debuggers/README.txt delete mode 100644 imgui-sfml/misc/debuggers/imgui.gdb delete mode 100644 imgui-sfml/misc/debuggers/imgui.natstepfilter delete mode 100644 imgui-sfml/misc/debuggers/imgui.natvis delete mode 100644 imgui-sfml/misc/fonts/Cousine-Regular.ttf delete mode 100644 imgui-sfml/misc/fonts/DroidSans.ttf delete mode 100644 imgui-sfml/misc/fonts/Karla-Regular.ttf delete mode 100644 imgui-sfml/misc/fonts/ProggyClean.ttf delete mode 100644 imgui-sfml/misc/fonts/ProggyTiny.ttf delete mode 100644 imgui-sfml/misc/fonts/Roboto-Medium.ttf delete mode 100644 imgui-sfml/misc/fonts/binary_to_compressed_c.cpp delete mode 100644 imgui-sfml/misc/freetype/README.md delete mode 100644 imgui-sfml/misc/freetype/imgui_freetype.cpp delete mode 100644 imgui-sfml/misc/freetype/imgui_freetype.h delete mode 100644 imgui-sfml/misc/single_file/imgui_single_file.h delete mode 100644 ogg/AUTHORS delete mode 100644 ogg/COPYING delete mode 100644 ogg/README.md delete mode 100644 ogg/build-ogg.lua delete mode 100644 ogg/include/Makefile.am delete mode 100644 ogg/include/ogg/Makefile.am delete mode 100644 ogg/include/ogg/config_types.h.in delete mode 100644 ogg/include/ogg/ogg.h delete mode 100644 ogg/include/ogg/os_types.h delete mode 100644 ogg/libogg.spec.in delete mode 100644 ogg/ogg-uninstalled.pc.in delete mode 100644 ogg/ogg.m4 delete mode 100644 ogg/ogg.pc.in delete mode 100644 ogg/releases.sha2 delete mode 100644 ogg/src/Makefile.am delete mode 100644 ogg/src/bitwise.c delete mode 100644 ogg/src/crctable.h delete mode 100644 ogg/src/framing.c delete mode 100644 project.lua delete mode 100644 sfml/build-sfml.lua delete mode 100644 sfml/extlibs/headers/glad/include/glad/egl.h delete mode 100644 sfml/extlibs/headers/glad/include/glad/gl.h delete mode 100644 sfml/extlibs/headers/glad/include/glad/glx.h delete mode 100644 sfml/extlibs/headers/glad/include/glad/wgl.h delete mode 100644 sfml/extlibs/headers/mingw/_mingw_dxhelper.h delete mode 100644 sfml/extlibs/headers/mingw/dinput.h delete mode 100644 sfml/extlibs/headers/miniaudio/miniaudio.h delete mode 100644 sfml/extlibs/headers/minimp3/minimp3.h delete mode 100644 sfml/extlibs/headers/minimp3/minimp3_ex.h delete mode 100644 sfml/extlibs/headers/stb_image/stb_image.h delete mode 100644 sfml/extlibs/headers/stb_image/stb_image_write.h delete mode 100644 sfml/extlibs/headers/vulkan/vk_icd.h delete mode 100644 sfml/extlibs/headers/vulkan/vk_layer.h delete mode 100644 sfml/extlibs/headers/vulkan/vk_platform.h delete mode 100644 sfml/extlibs/headers/vulkan/vk_sdk_platform.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_android.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_core.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_ios.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_macos.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_mir.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_vi.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_wayland.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_win32.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_xcb.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_xlib.h delete mode 100644 sfml/extlibs/headers/vulkan/vulkan_xlib_xrandr.h delete mode 100644 sfml/include/SFML/Audio.hpp delete mode 100644 sfml/include/SFML/Audio/AudioResource.hpp delete mode 100644 sfml/include/SFML/Audio/Export.hpp delete mode 100644 sfml/include/SFML/Audio/InputSoundFile.hpp delete mode 100644 sfml/include/SFML/Audio/Listener.hpp delete mode 100644 sfml/include/SFML/Audio/Music.hpp delete mode 100644 sfml/include/SFML/Audio/OutputSoundFile.hpp delete mode 100644 sfml/include/SFML/Audio/PlaybackDevice.hpp delete mode 100644 sfml/include/SFML/Audio/Sound.hpp delete mode 100644 sfml/include/SFML/Audio/SoundBuffer.hpp delete mode 100644 sfml/include/SFML/Audio/SoundBufferRecorder.hpp delete mode 100644 sfml/include/SFML/Audio/SoundChannel.hpp delete mode 100644 sfml/include/SFML/Audio/SoundFileFactory.hpp delete mode 100644 sfml/include/SFML/Audio/SoundFileFactory.inl delete mode 100644 sfml/include/SFML/Audio/SoundFileReader.hpp delete mode 100644 sfml/include/SFML/Audio/SoundFileWriter.hpp delete mode 100644 sfml/include/SFML/Audio/SoundRecorder.hpp delete mode 100644 sfml/include/SFML/Audio/SoundSource.hpp delete mode 100644 sfml/include/SFML/Audio/SoundStream.hpp delete mode 100644 sfml/include/SFML/Config.hpp delete mode 100644 sfml/include/SFML/GpuPreference.hpp delete mode 100644 sfml/include/SFML/Graphics.hpp delete mode 100644 sfml/include/SFML/Graphics/BlendMode.hpp delete mode 100644 sfml/include/SFML/Graphics/CircleShape.hpp delete mode 100644 sfml/include/SFML/Graphics/Color.hpp delete mode 100644 sfml/include/SFML/Graphics/Color.inl delete mode 100644 sfml/include/SFML/Graphics/ConvexShape.hpp delete mode 100644 sfml/include/SFML/Graphics/CoordinateType.hpp delete mode 100644 sfml/include/SFML/Graphics/Drawable.hpp delete mode 100644 sfml/include/SFML/Graphics/Export.hpp delete mode 100644 sfml/include/SFML/Graphics/Font.hpp delete mode 100644 sfml/include/SFML/Graphics/Glsl.hpp delete mode 100644 sfml/include/SFML/Graphics/Glsl.inl delete mode 100644 sfml/include/SFML/Graphics/Glyph.hpp delete mode 100644 sfml/include/SFML/Graphics/Image.hpp delete mode 100644 sfml/include/SFML/Graphics/PrimitiveType.hpp delete mode 100644 sfml/include/SFML/Graphics/Rect.hpp delete mode 100644 sfml/include/SFML/Graphics/Rect.inl delete mode 100644 sfml/include/SFML/Graphics/RectangleShape.hpp delete mode 100644 sfml/include/SFML/Graphics/RenderStates.hpp delete mode 100644 sfml/include/SFML/Graphics/RenderTarget.hpp delete mode 100644 sfml/include/SFML/Graphics/RenderTexture.hpp delete mode 100644 sfml/include/SFML/Graphics/RenderWindow.hpp delete mode 100644 sfml/include/SFML/Graphics/Shader.hpp delete mode 100644 sfml/include/SFML/Graphics/Shape.hpp delete mode 100644 sfml/include/SFML/Graphics/Sprite.hpp delete mode 100644 sfml/include/SFML/Graphics/StencilMode.hpp delete mode 100644 sfml/include/SFML/Graphics/Text.hpp delete mode 100644 sfml/include/SFML/Graphics/Texture.hpp delete mode 100644 sfml/include/SFML/Graphics/Transform.hpp delete mode 100644 sfml/include/SFML/Graphics/Transform.inl delete mode 100644 sfml/include/SFML/Graphics/Transformable.hpp delete mode 100644 sfml/include/SFML/Graphics/Vertex.hpp delete mode 100644 sfml/include/SFML/Graphics/VertexArray.hpp delete mode 100644 sfml/include/SFML/Graphics/VertexBuffer.hpp delete mode 100644 sfml/include/SFML/Graphics/View.hpp delete mode 100644 sfml/include/SFML/Main.hpp delete mode 100644 sfml/include/SFML/Network.hpp delete mode 100644 sfml/include/SFML/Network/Export.hpp delete mode 100644 sfml/include/SFML/Network/Ftp.hpp delete mode 100644 sfml/include/SFML/Network/Http.hpp delete mode 100644 sfml/include/SFML/Network/IpAddress.hpp delete mode 100644 sfml/include/SFML/Network/Packet.hpp delete mode 100644 sfml/include/SFML/Network/Socket.hpp delete mode 100644 sfml/include/SFML/Network/SocketHandle.hpp delete mode 100644 sfml/include/SFML/Network/SocketSelector.hpp delete mode 100644 sfml/include/SFML/Network/TcpListener.hpp delete mode 100644 sfml/include/SFML/Network/TcpSocket.hpp delete mode 100644 sfml/include/SFML/Network/UdpSocket.hpp delete mode 100644 sfml/include/SFML/OpenGL.hpp delete mode 100644 sfml/include/SFML/System.hpp delete mode 100644 sfml/include/SFML/System/Angle.hpp delete mode 100644 sfml/include/SFML/System/Angle.inl delete mode 100644 sfml/include/SFML/System/Clock.hpp delete mode 100644 sfml/include/SFML/System/Err.hpp delete mode 100644 sfml/include/SFML/System/Exception.hpp delete mode 100644 sfml/include/SFML/System/Export.hpp delete mode 100644 sfml/include/SFML/System/FileInputStream.hpp delete mode 100644 sfml/include/SFML/System/InputStream.hpp delete mode 100644 sfml/include/SFML/System/MemoryInputStream.hpp delete mode 100644 sfml/include/SFML/System/NativeActivity.hpp delete mode 100644 sfml/include/SFML/System/Sleep.hpp delete mode 100644 sfml/include/SFML/System/String.hpp delete mode 100644 sfml/include/SFML/System/String.inl delete mode 100644 sfml/include/SFML/System/SuspendAwareClock.hpp delete mode 100644 sfml/include/SFML/System/Time.hpp delete mode 100644 sfml/include/SFML/System/Time.inl delete mode 100644 sfml/include/SFML/System/Utf.hpp delete mode 100644 sfml/include/SFML/System/Utf.inl delete mode 100644 sfml/include/SFML/System/Vector2.hpp delete mode 100644 sfml/include/SFML/System/Vector2.inl delete mode 100644 sfml/include/SFML/System/Vector3.hpp delete mode 100644 sfml/include/SFML/System/Vector3.inl delete mode 100644 sfml/include/SFML/Window.hpp delete mode 100644 sfml/include/SFML/Window/Clipboard.hpp delete mode 100644 sfml/include/SFML/Window/Context.hpp delete mode 100644 sfml/include/SFML/Window/ContextSettings.hpp delete mode 100644 sfml/include/SFML/Window/Cursor.hpp delete mode 100644 sfml/include/SFML/Window/Event.hpp delete mode 100644 sfml/include/SFML/Window/Event.inl delete mode 100644 sfml/include/SFML/Window/Export.hpp delete mode 100644 sfml/include/SFML/Window/GlResource.hpp delete mode 100644 sfml/include/SFML/Window/Joystick.hpp delete mode 100644 sfml/include/SFML/Window/Keyboard.hpp delete mode 100644 sfml/include/SFML/Window/Mouse.hpp delete mode 100644 sfml/include/SFML/Window/Sensor.hpp delete mode 100644 sfml/include/SFML/Window/Touch.hpp delete mode 100644 sfml/include/SFML/Window/VideoMode.hpp delete mode 100644 sfml/include/SFML/Window/Vulkan.hpp delete mode 100644 sfml/include/SFML/Window/Window.hpp delete mode 100644 sfml/include/SFML/Window/WindowBase.hpp delete mode 100644 sfml/include/SFML/Window/WindowBase.inl delete mode 100644 sfml/include/SFML/Window/WindowEnums.hpp delete mode 100644 sfml/include/SFML/Window/WindowHandle.hpp delete mode 100644 sfml/license.md delete mode 100644 sfml/readme.md delete mode 100644 sfml/src/SFML/Audio/AudioDevice.cpp delete mode 100644 sfml/src/SFML/Audio/AudioDevice.hpp delete mode 100644 sfml/src/SFML/Audio/AudioResource.cpp delete mode 100644 sfml/src/SFML/Audio/InputSoundFile.cpp delete mode 100644 sfml/src/SFML/Audio/Listener.cpp delete mode 100644 sfml/src/SFML/Audio/Miniaudio.cpp delete mode 100644 sfml/src/SFML/Audio/MiniaudioUtils.cpp delete mode 100644 sfml/src/SFML/Audio/MiniaudioUtils.hpp delete mode 100644 sfml/src/SFML/Audio/Music.cpp delete mode 100644 sfml/src/SFML/Audio/OutputSoundFile.cpp delete mode 100644 sfml/src/SFML/Audio/PlaybackDevice.cpp delete mode 100644 sfml/src/SFML/Audio/Sound.cpp delete mode 100644 sfml/src/SFML/Audio/SoundBuffer.cpp delete mode 100644 sfml/src/SFML/Audio/SoundBufferRecorder.cpp delete mode 100644 sfml/src/SFML/Audio/SoundFileFactory.cpp delete mode 100644 sfml/src/SFML/Audio/SoundFileReaderFlac.cpp delete mode 100644 sfml/src/SFML/Audio/SoundFileReaderFlac.hpp delete mode 100644 sfml/src/SFML/Audio/SoundFileReaderMp3.cpp delete mode 100644 sfml/src/SFML/Audio/SoundFileReaderMp3.hpp delete mode 100644 sfml/src/SFML/Audio/SoundFileReaderOgg.cpp delete mode 100644 sfml/src/SFML/Audio/SoundFileReaderOgg.hpp delete mode 100644 sfml/src/SFML/Audio/SoundFileReaderWav.cpp delete mode 100644 sfml/src/SFML/Audio/SoundFileReaderWav.hpp delete mode 100644 sfml/src/SFML/Audio/SoundFileWriterFlac.cpp delete mode 100644 sfml/src/SFML/Audio/SoundFileWriterFlac.hpp delete mode 100644 sfml/src/SFML/Audio/SoundFileWriterOgg.cpp delete mode 100644 sfml/src/SFML/Audio/SoundFileWriterOgg.hpp delete mode 100644 sfml/src/SFML/Audio/SoundFileWriterWav.cpp delete mode 100644 sfml/src/SFML/Audio/SoundFileWriterWav.hpp delete mode 100644 sfml/src/SFML/Audio/SoundRecorder.cpp delete mode 100644 sfml/src/SFML/Audio/SoundSource.cpp delete mode 100644 sfml/src/SFML/Audio/SoundStream.cpp delete mode 100644 sfml/src/SFML/Graphics/BlendMode.cpp delete mode 100644 sfml/src/SFML/Graphics/CircleShape.cpp delete mode 100644 sfml/src/SFML/Graphics/ConvexShape.cpp delete mode 100644 sfml/src/SFML/Graphics/Font.cpp delete mode 100644 sfml/src/SFML/Graphics/GLCheck.cpp delete mode 100644 sfml/src/SFML/Graphics/GLCheck.hpp delete mode 100644 sfml/src/SFML/Graphics/GLExtensions.cpp delete mode 100644 sfml/src/SFML/Graphics/GLExtensions.hpp delete mode 100644 sfml/src/SFML/Graphics/GLExtensions.txt delete mode 100644 sfml/src/SFML/Graphics/Glsl.cpp delete mode 100644 sfml/src/SFML/Graphics/Image.cpp delete mode 100644 sfml/src/SFML/Graphics/RectangleShape.cpp delete mode 100644 sfml/src/SFML/Graphics/RenderStates.cpp delete mode 100644 sfml/src/SFML/Graphics/RenderTarget.cpp delete mode 100644 sfml/src/SFML/Graphics/RenderTexture.cpp delete mode 100644 sfml/src/SFML/Graphics/RenderTextureImpl.hpp delete mode 100644 sfml/src/SFML/Graphics/RenderTextureImplDefault.cpp delete mode 100644 sfml/src/SFML/Graphics/RenderTextureImplDefault.hpp delete mode 100644 sfml/src/SFML/Graphics/RenderTextureImplFBO.cpp delete mode 100644 sfml/src/SFML/Graphics/RenderTextureImplFBO.hpp delete mode 100644 sfml/src/SFML/Graphics/RenderWindow.cpp delete mode 100644 sfml/src/SFML/Graphics/Shader.cpp delete mode 100644 sfml/src/SFML/Graphics/Shape.cpp delete mode 100644 sfml/src/SFML/Graphics/Sprite.cpp delete mode 100644 sfml/src/SFML/Graphics/StencilMode.cpp delete mode 100644 sfml/src/SFML/Graphics/Text.cpp delete mode 100644 sfml/src/SFML/Graphics/Texture.cpp delete mode 100644 sfml/src/SFML/Graphics/TextureSaver.cpp delete mode 100644 sfml/src/SFML/Graphics/TextureSaver.hpp delete mode 100644 sfml/src/SFML/Graphics/Transform.cpp delete mode 100644 sfml/src/SFML/Graphics/Transformable.cpp delete mode 100644 sfml/src/SFML/Graphics/VertexArray.cpp delete mode 100644 sfml/src/SFML/Graphics/VertexBuffer.cpp delete mode 100644 sfml/src/SFML/Graphics/View.cpp delete mode 100644 sfml/src/SFML/Main/MainWin32.cpp delete mode 100644 sfml/src/SFML/Network/Ftp.cpp delete mode 100644 sfml/src/SFML/Network/Http.cpp delete mode 100644 sfml/src/SFML/Network/IpAddress.cpp delete mode 100644 sfml/src/SFML/Network/Packet.cpp delete mode 100644 sfml/src/SFML/Network/Socket.cpp delete mode 100644 sfml/src/SFML/Network/SocketImpl.hpp delete mode 100644 sfml/src/SFML/Network/SocketSelector.cpp delete mode 100644 sfml/src/SFML/Network/TcpListener.cpp delete mode 100644 sfml/src/SFML/Network/TcpSocket.cpp delete mode 100644 sfml/src/SFML/Network/UdpSocket.cpp delete mode 100644 sfml/src/SFML/Network/Unix/SocketImpl.cpp delete mode 100644 sfml/src/SFML/Network/Win32/SocketImpl.cpp delete mode 100644 sfml/src/SFML/PCH.hpp delete mode 100644 sfml/src/SFML/System/Clock.cpp delete mode 100644 sfml/src/SFML/System/EnumArray.hpp delete mode 100644 sfml/src/SFML/System/Err.cpp delete mode 100644 sfml/src/SFML/System/FileInputStream.cpp delete mode 100644 sfml/src/SFML/System/MemoryInputStream.cpp delete mode 100644 sfml/src/SFML/System/Sleep.cpp delete mode 100644 sfml/src/SFML/System/String.cpp delete mode 100644 sfml/src/SFML/System/Unix/SleepImpl.cpp delete mode 100644 sfml/src/SFML/System/Unix/SleepImpl.hpp delete mode 100644 sfml/src/SFML/System/Utils.cpp delete mode 100644 sfml/src/SFML/System/Utils.hpp delete mode 100644 sfml/src/SFML/System/Vector2.cpp delete mode 100644 sfml/src/SFML/System/Vector3.cpp delete mode 100644 sfml/src/SFML/System/Win32/SleepImpl.cpp delete mode 100644 sfml/src/SFML/System/Win32/SleepImpl.hpp delete mode 100644 sfml/src/SFML/System/Win32/WindowsHeader.hpp delete mode 100644 sfml/src/SFML/Window/Clipboard.cpp delete mode 100644 sfml/src/SFML/Window/ClipboardImpl.hpp delete mode 100644 sfml/src/SFML/Window/Context.cpp delete mode 100644 sfml/src/SFML/Window/Cursor.cpp delete mode 100644 sfml/src/SFML/Window/CursorImpl.hpp delete mode 100644 sfml/src/SFML/Window/EGLCheck.cpp delete mode 100644 sfml/src/SFML/Window/EGLCheck.hpp delete mode 100644 sfml/src/SFML/Window/EglContext.cpp delete mode 100644 sfml/src/SFML/Window/EglContext.hpp delete mode 100644 sfml/src/SFML/Window/GlContext.cpp delete mode 100644 sfml/src/SFML/Window/GlContext.hpp delete mode 100644 sfml/src/SFML/Window/GlResource.cpp delete mode 100644 sfml/src/SFML/Window/InputImpl.hpp delete mode 100644 sfml/src/SFML/Window/Joystick.cpp delete mode 100644 sfml/src/SFML/Window/JoystickImpl.hpp delete mode 100644 sfml/src/SFML/Window/JoystickManager.cpp delete mode 100644 sfml/src/SFML/Window/JoystickManager.hpp delete mode 100644 sfml/src/SFML/Window/Keyboard.cpp delete mode 100644 sfml/src/SFML/Window/Mouse.cpp delete mode 100644 sfml/src/SFML/Window/Sensor.cpp delete mode 100644 sfml/src/SFML/Window/SensorImpl.hpp delete mode 100644 sfml/src/SFML/Window/SensorManager.cpp delete mode 100644 sfml/src/SFML/Window/SensorManager.hpp delete mode 100644 sfml/src/SFML/Window/Touch.cpp delete mode 100644 sfml/src/SFML/Window/Unix/ClipboardImpl.cpp delete mode 100644 sfml/src/SFML/Window/Unix/ClipboardImpl.hpp delete mode 100644 sfml/src/SFML/Window/Unix/CursorImpl.cpp delete mode 100644 sfml/src/SFML/Window/Unix/CursorImpl.hpp delete mode 100644 sfml/src/SFML/Window/Unix/Display.cpp delete mode 100644 sfml/src/SFML/Window/Unix/Display.hpp delete mode 100644 sfml/src/SFML/Window/Unix/GlxContext.cpp delete mode 100644 sfml/src/SFML/Window/Unix/GlxContext.hpp delete mode 100644 sfml/src/SFML/Window/Unix/InputImpl.cpp delete mode 100644 sfml/src/SFML/Window/Unix/JoystickImpl.cpp delete mode 100644 sfml/src/SFML/Window/Unix/JoystickImpl.hpp delete mode 100644 sfml/src/SFML/Window/Unix/KeySymToKeyMapping.cpp delete mode 100644 sfml/src/SFML/Window/Unix/KeySymToKeyMapping.hpp delete mode 100644 sfml/src/SFML/Window/Unix/KeySymToUnicodeMapping.cpp delete mode 100644 sfml/src/SFML/Window/Unix/KeySymToUnicodeMapping.hpp delete mode 100644 sfml/src/SFML/Window/Unix/KeyboardImpl.cpp delete mode 100644 sfml/src/SFML/Window/Unix/KeyboardImpl.hpp delete mode 100644 sfml/src/SFML/Window/Unix/SensorImpl.cpp delete mode 100644 sfml/src/SFML/Window/Unix/SensorImpl.hpp delete mode 100644 sfml/src/SFML/Window/Unix/Utils.hpp delete mode 100644 sfml/src/SFML/Window/Unix/VideoModeImpl.cpp delete mode 100644 sfml/src/SFML/Window/Unix/VulkanImplX11.cpp delete mode 100644 sfml/src/SFML/Window/Unix/WindowImplX11.cpp delete mode 100644 sfml/src/SFML/Window/Unix/WindowImplX11.hpp delete mode 100644 sfml/src/SFML/Window/VideoMode.cpp delete mode 100644 sfml/src/SFML/Window/VideoModeImpl.hpp delete mode 100644 sfml/src/SFML/Window/Vulkan.cpp delete mode 100644 sfml/src/SFML/Window/VulkanImpl.hpp delete mode 100644 sfml/src/SFML/Window/Win32/ClipboardImpl.cpp delete mode 100644 sfml/src/SFML/Window/Win32/ClipboardImpl.hpp delete mode 100644 sfml/src/SFML/Window/Win32/CursorImpl.cpp delete mode 100644 sfml/src/SFML/Window/Win32/CursorImpl.hpp delete mode 100644 sfml/src/SFML/Window/Win32/InputImpl.cpp delete mode 100644 sfml/src/SFML/Window/Win32/JoystickImpl.cpp delete mode 100644 sfml/src/SFML/Window/Win32/JoystickImpl.hpp delete mode 100644 sfml/src/SFML/Window/Win32/SensorImpl.cpp delete mode 100644 sfml/src/SFML/Window/Win32/SensorImpl.hpp delete mode 100644 sfml/src/SFML/Window/Win32/Utils.hpp delete mode 100644 sfml/src/SFML/Window/Win32/VideoModeImpl.cpp delete mode 100644 sfml/src/SFML/Window/Win32/VulkanImplWin32.cpp delete mode 100644 sfml/src/SFML/Window/Win32/WglContext.cpp delete mode 100644 sfml/src/SFML/Window/Win32/WglContext.hpp delete mode 100644 sfml/src/SFML/Window/Win32/WindowImplWin32.cpp delete mode 100644 sfml/src/SFML/Window/Win32/WindowImplWin32.hpp delete mode 100644 sfml/src/SFML/Window/Window.cpp delete mode 100644 sfml/src/SFML/Window/WindowBase.cpp delete mode 100644 sfml/src/SFML/Window/WindowImpl.cpp delete mode 100644 sfml/src/SFML/Window/WindowImpl.hpp delete mode 100644 vorbis/AUTHORS delete mode 100644 vorbis/COPYING delete mode 100644 vorbis/README.md delete mode 100644 vorbis/build-vorbis.lua delete mode 100644 vorbis/contrib/oss-fuzz/build.sh delete mode 100644 vorbis/contrib/oss-fuzz/decode_fuzzer.cc delete mode 100644 vorbis/debian/changelog delete mode 100644 vorbis/debian/control delete mode 100644 vorbis/debian/copyright delete mode 100644 vorbis/debian/libvorbis-dev.docs delete mode 100644 vorbis/debian/libvorbis-dev.examples delete mode 100644 vorbis/debian/libvorbis-dev.install delete mode 100644 vorbis/debian/libvorbis0a.install delete mode 100644 vorbis/debian/libvorbisenc2.install delete mode 100644 vorbis/debian/libvorbisfile3.install delete mode 100644 vorbis/debian/rules delete mode 100644 vorbis/debian/watch delete mode 100644 vorbis/include/Makefile.am delete mode 100644 vorbis/include/vorbis/Makefile.am delete mode 100644 vorbis/include/vorbis/codec.h delete mode 100644 vorbis/include/vorbis/vorbisenc.h delete mode 100644 vorbis/include/vorbis/vorbisfile.h delete mode 100644 vorbis/lib/Makefile.am delete mode 100644 vorbis/lib/analysis.c delete mode 100644 vorbis/lib/backends.h delete mode 100644 vorbis/lib/barkmel.c delete mode 100644 vorbis/lib/bitrate.c delete mode 100644 vorbis/lib/bitrate.h delete mode 100644 vorbis/lib/block.c delete mode 100644 vorbis/lib/books/Makefile.am delete mode 100644 vorbis/lib/books/coupled/Makefile.am delete mode 100644 vorbis/lib/books/coupled/res_books_51.h delete mode 100644 vorbis/lib/books/coupled/res_books_stereo.h delete mode 100644 vorbis/lib/books/floor/Makefile.am delete mode 100644 vorbis/lib/books/floor/floor_books.h delete mode 100644 vorbis/lib/books/uncoupled/Makefile.am delete mode 100644 vorbis/lib/books/uncoupled/res_books_uncoupled.h delete mode 100644 vorbis/lib/codebook.c delete mode 100644 vorbis/lib/codebook.h delete mode 100644 vorbis/lib/codec_internal.h delete mode 100644 vorbis/lib/envelope.c delete mode 100644 vorbis/lib/envelope.h delete mode 100644 vorbis/lib/floor0.c delete mode 100644 vorbis/lib/floor1.c delete mode 100644 vorbis/lib/highlevel.h delete mode 100644 vorbis/lib/info.c delete mode 100644 vorbis/lib/lookup.c delete mode 100644 vorbis/lib/lookup.h delete mode 100644 vorbis/lib/lookup_data.h delete mode 100644 vorbis/lib/lookups.pl delete mode 100644 vorbis/lib/lpc.c delete mode 100644 vorbis/lib/lpc.h delete mode 100644 vorbis/lib/lsp.c delete mode 100644 vorbis/lib/lsp.h delete mode 100644 vorbis/lib/mapping0.c delete mode 100644 vorbis/lib/masking.h delete mode 100644 vorbis/lib/mdct.c delete mode 100644 vorbis/lib/mdct.h delete mode 100644 vorbis/lib/misc.c delete mode 100644 vorbis/lib/misc.h delete mode 100644 vorbis/lib/modes/Makefile.am delete mode 100644 vorbis/lib/modes/floor_all.h delete mode 100644 vorbis/lib/modes/psych_11.h delete mode 100644 vorbis/lib/modes/psych_16.h delete mode 100644 vorbis/lib/modes/psych_44.h delete mode 100644 vorbis/lib/modes/psych_8.h delete mode 100644 vorbis/lib/modes/residue_16.h delete mode 100644 vorbis/lib/modes/residue_44.h delete mode 100644 vorbis/lib/modes/residue_44p51.h delete mode 100644 vorbis/lib/modes/residue_44u.h delete mode 100644 vorbis/lib/modes/residue_8.h delete mode 100644 vorbis/lib/modes/setup_11.h delete mode 100644 vorbis/lib/modes/setup_16.h delete mode 100644 vorbis/lib/modes/setup_22.h delete mode 100644 vorbis/lib/modes/setup_32.h delete mode 100644 vorbis/lib/modes/setup_44.h delete mode 100644 vorbis/lib/modes/setup_44p51.h delete mode 100644 vorbis/lib/modes/setup_44u.h delete mode 100644 vorbis/lib/modes/setup_8.h delete mode 100644 vorbis/lib/modes/setup_X.h delete mode 100644 vorbis/lib/os.h delete mode 100644 vorbis/lib/psy.c delete mode 100644 vorbis/lib/psy.h delete mode 100644 vorbis/lib/psytune.c delete mode 100644 vorbis/lib/registry.c delete mode 100644 vorbis/lib/registry.h delete mode 100644 vorbis/lib/res0.c delete mode 100644 vorbis/lib/scales.h delete mode 100644 vorbis/lib/sharedbook.c delete mode 100644 vorbis/lib/smallft.c delete mode 100644 vorbis/lib/smallft.h delete mode 100644 vorbis/lib/synthesis.c delete mode 100644 vorbis/lib/tone.c delete mode 100644 vorbis/lib/vorbisenc.c delete mode 100644 vorbis/lib/vorbisfile.c delete mode 100644 vorbis/lib/window.c delete mode 100644 vorbis/lib/window.h delete mode 100644 vorbis/symbian/bld.inf delete mode 100644 vorbis/symbian/config.h delete mode 100644 vorbis/symbian/vorbis.mmp delete mode 100644 vorbis/test/Makefile.am delete mode 100644 vorbis/test/test.c delete mode 100644 vorbis/test/util.c delete mode 100644 vorbis/test/util.h delete mode 100644 vorbis/test/write_read.c delete mode 100644 vorbis/test/write_read.h delete mode 100644 vorbis/vq/16.vqs delete mode 100644 vorbis/vq/16u.vqs delete mode 100644 vorbis/vq/44c-1.vqs delete mode 100644 vorbis/vq/44c0.vqs delete mode 100644 vorbis/vq/44c1.vqs delete mode 100644 vorbis/vq/44c2.vqs delete mode 100644 vorbis/vq/44c3.vqs delete mode 100644 vorbis/vq/44c4.vqs delete mode 100644 vorbis/vq/44c5.vqs delete mode 100644 vorbis/vq/44c6.vqs delete mode 100644 vorbis/vq/44c7.vqs delete mode 100644 vorbis/vq/44c8.vqs delete mode 100644 vorbis/vq/44c9.vqs delete mode 100644 vorbis/vq/44p-1.vqs delete mode 100644 vorbis/vq/44p0.vqs delete mode 100644 vorbis/vq/44p1.vqs delete mode 100644 vorbis/vq/44p2.vqs delete mode 100644 vorbis/vq/44p3.vqs delete mode 100644 vorbis/vq/44p4.vqs delete mode 100644 vorbis/vq/44p5.vqs delete mode 100644 vorbis/vq/44p6.vqs delete mode 100644 vorbis/vq/44p7.vqs delete mode 100644 vorbis/vq/44p8.vqs delete mode 100644 vorbis/vq/44p9.vqs delete mode 100644 vorbis/vq/44u0.vqs delete mode 100644 vorbis/vq/44u1.vqs delete mode 100644 vorbis/vq/44u2.vqs delete mode 100644 vorbis/vq/44u3.vqs delete mode 100644 vorbis/vq/44u4.vqs delete mode 100644 vorbis/vq/44u5.vqs delete mode 100644 vorbis/vq/44u6.vqs delete mode 100644 vorbis/vq/44u7.vqs delete mode 100644 vorbis/vq/44u8.vqs delete mode 100644 vorbis/vq/44u9.vqs delete mode 100644 vorbis/vq/8.vqs delete mode 100644 vorbis/vq/8u.vqs delete mode 100644 vorbis/vq/Makefile.am delete mode 100644 vorbis/vq/bookutil.c delete mode 100644 vorbis/vq/bookutil.h delete mode 100644 vorbis/vq/distribution.c delete mode 100644 vorbis/vq/floor_11.vqs delete mode 100644 vorbis/vq/floor_22.vqs delete mode 100644 vorbis/vq/floor_44.vqs delete mode 100644 vorbis/vq/huffbuild.c delete mode 100644 vorbis/vq/latticebuild.c delete mode 100644 vorbis/vq/latticetune.c delete mode 100644 vorbis/vq/localcodebook.h delete mode 100644 vorbis/vq/make_floor_books.pl delete mode 100644 vorbis/vq/make_residue_books.pl delete mode 100644 vorbis/vq/metrics.c delete mode 100644 vorbis/vq/vqgen.c delete mode 100644 vorbis/vq/vqgen.h delete mode 100644 workspace.lua diff --git a/flac/AUTHORS b/flac/AUTHORS deleted file mode 100644 index 34c5f89..0000000 --- a/flac/AUTHORS +++ /dev/null @@ -1,60 +0,0 @@ -/* FLAC - Free Lossless Audio Codec - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * This file is part the FLAC project. FLAC is comprised of several - * components distributed under different licenses. The codec libraries - * are distributed under Xiph.Org's BSD-like license (see the file - * COPYING.Xiph in this distribution). All other programs, libraries, and - * plugins are distributed under the GPL (see COPYING.GPL). The documentation - * is distributed under the Gnu FDL (see COPYING.FDL). Each file in the - * FLAC distribution contains at the top the terms under which it may be - * distributed. - * - * Since this particular file is relevant to all components of FLAC, - * it may be distributed under the Xiph.Org license, which is the least - * restrictive of those mentioned above. See the file COPYING.Xiph in this - * distribution. - */ - -This file lists major contributors to the FLAC project. This list is not -exhaustive. For an exhaustive list, run the command `git shortlog -s` on -the git repo or visit https://gitlab.xiph.org/xiph/flac/-/graphs/master - -For a complete list of contributions, run the command `git log` on the -git repo, visit https://github.com/xiph/flac/commits or visit -https://gitlab.xiph.org/xiph/flac/commits - -Original author: Josh Coalson -Maintainer 2012-2020: Erik de Castro Lopo -Maintainer from 2022: Martijn van Beurden - -Website : https://www.xiph.org/flac/ - -Other major contributors and their contributions: - -"lvqcl" -* Visual Studio build system. -* Optimisations in the encoder and decoder. - -"Janne Hyvärinen" -* Visual Studio build system. -* Unicode handling on Windows. - -"Andrey Astafiev" -* Russian translation of the HTML documentation - -"Miroslav Lichvar" -* IA-32 assembly versions of several libFLAC routines - -"Brady Patterson" -* AIFF file support, PPC assembly versions of libFLAC routines - -"Daisuke Shimamura" -* i18n support in the XMMS plugin - -"X-Fixer" -* Configuration system, tag editing, and file info in the Winamp2 plugin - -"Matt Zimmerman" -* Libtool/autoconf/automake make system, flac man page diff --git a/flac/COPYING.FDL b/flac/COPYING.FDL deleted file mode 100644 index 4a0fe1c..0000000 --- a/flac/COPYING.FDL +++ /dev/null @@ -1,397 +0,0 @@ - GNU Free Documentation License - Version 1.2, November 2002 - - - Copyright (C) 2000,2001,2002 Free Software Foundation, Inc. - 51 Franklin St, 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. - - -0. PREAMBLE - -The purpose of this License is to make a manual, textbook, or other -functional and useful document "free" in the sense of freedom: to -assure everyone the effective freedom to copy and redistribute it, -with or without modifying it, either commercially or noncommercially. -Secondarily, this License preserves for the author and publisher a way -to get credit for their work, while not being considered responsible -for modifications made by others. - -This License is a kind of "copyleft", which means that derivative -works of the document must themselves be free in the same sense. It -complements the GNU General Public License, which is a copyleft -license designed for free software. - -We have designed this License in order to use it for manuals for free -software, because free software needs free documentation: a free -program should come with manuals providing the same freedoms that the -software does. But this License is not limited to software manuals; -it can be used for any textual work, regardless of subject matter or -whether it is published as a printed book. We recommend this License -principally for works whose purpose is instruction or reference. - - -1. APPLICABILITY AND DEFINITIONS - -This License applies to any manual or other work, in any medium, that -contains a notice placed by the copyright holder saying it can be -distributed under the terms of this License. Such a notice grants a -world-wide, royalty-free license, unlimited in duration, to use that -work under the conditions stated herein. The "Document", below, -refers to any such manual or work. Any member of the public is a -licensee, and is addressed as "you". You accept the license if you -copy, modify or distribute the work in a way requiring permission -under copyright law. - -A "Modified Version" of the Document means any work containing the -Document or a portion of it, either copied verbatim, or with -modifications and/or translated into another language. - -A "Secondary Section" is a named appendix or a front-matter section of -the Document that deals exclusively with the relationship of the -publishers or authors of the Document to the Document's overall subject -(or to related matters) and contains nothing that could fall directly -within that overall subject. (Thus, if the Document is in part a -textbook of mathematics, a Secondary Section may not explain any -mathematics.) The relationship could be a matter of historical -connection with the subject or with related matters, or of legal, -commercial, philosophical, ethical or political position regarding -them. - -The "Invariant Sections" are certain Secondary Sections whose titles -are designated, as being those of Invariant Sections, in the notice -that says that the Document is released under this License. If a -section does not fit the above definition of Secondary then it is not -allowed to be designated as Invariant. The Document may contain zero -Invariant Sections. If the Document does not identify any Invariant -Sections then there are none. - -The "Cover Texts" are certain short passages of text that are listed, -as Front-Cover Texts or Back-Cover Texts, in the notice that says that -the Document is released under this License. A Front-Cover Text may -be at most 5 words, and a Back-Cover Text may be at most 25 words. - -A "Transparent" copy of the Document means a machine-readable copy, -represented in a format whose specification is available to the -general public, that is suitable for revising the document -straightforwardly with generic text editors or (for images composed of -pixels) generic paint programs or (for drawings) some widely available -drawing editor, and that is suitable for input to text formatters or -for automatic translation to a variety of formats suitable for input -to text formatters. A copy made in an otherwise Transparent file -format whose markup, or absence of markup, has been arranged to thwart -or discourage subsequent modification by readers is not Transparent. -An image format is not Transparent if used for any substantial amount -of text. A copy that is not "Transparent" is called "Opaque". - -Examples of suitable formats for Transparent copies include plain -ASCII without markup, Texinfo input format, LaTeX input format, SGML -or XML using a publicly available DTD, and standard-conforming simple -HTML, PostScript or PDF designed for human modification. Examples of -transparent image formats include PNG, XCF and JPG. Opaque formats -include proprietary formats that can be read and edited only by -proprietary word processors, SGML or XML for which the DTD and/or -processing tools are not generally available, and the -machine-generated HTML, PostScript or PDF produced by some word -processors for output purposes only. - -The "Title Page" means, for a printed book, the title page itself, -plus such following pages as are needed to hold, legibly, the material -this License requires to appear in the title page. For works in -formats which do not have any title page as such, "Title Page" means -the text near the most prominent appearance of the work's title, -preceding the beginning of the body of the text. - -A section "Entitled XYZ" means a named subunit of the Document whose -title either is precisely XYZ or contains XYZ in parentheses following -text that translates XYZ in another language. (Here XYZ stands for a -specific section name mentioned below, such as "Acknowledgements", -"Dedications", "Endorsements", or "History".) To "Preserve the Title" -of such a section when you modify the Document means that it remains a -section "Entitled XYZ" according to this definition. - -The Document may include Warranty Disclaimers next to the notice which -states that this License applies to the Document. These Warranty -Disclaimers are considered to be included by reference in this -License, but only as regards disclaiming warranties: any other -implication that these Warranty Disclaimers may have is void and has -no effect on the meaning of this License. - - -2. VERBATIM COPYING - -You may copy and distribute the Document in any medium, either -commercially or noncommercially, provided that this License, the -copyright notices, and the license notice saying this License applies -to the Document are reproduced in all copies, and that you add no other -conditions whatsoever to those of this License. You may not use -technical measures to obstruct or control the reading or further -copying of the copies you make or distribute. However, you may accept -compensation in exchange for copies. If you distribute a large enough -number of copies you must also follow the conditions in section 3. - -You may also lend copies, under the same conditions stated above, and -you may publicly display copies. - - -3. COPYING IN QUANTITY - -If you publish printed copies (or copies in media that commonly have -printed covers) of the Document, numbering more than 100, and the -Document's license notice requires Cover Texts, you must enclose the -copies in covers that carry, clearly and legibly, all these Cover -Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on -the back cover. Both covers must also clearly and legibly identify -you as the publisher of these copies. The front cover must present -the full title with all words of the title equally prominent and -visible. You may add other material on the covers in addition. -Copying with changes limited to the covers, as long as they preserve -the title of the Document and satisfy these conditions, can be treated -as verbatim copying in other respects. - -If the required texts for either cover are too voluminous to fit -legibly, you should put the first ones listed (as many as fit -reasonably) on the actual cover, and continue the rest onto adjacent -pages. - -If you publish or distribute Opaque copies of the Document numbering -more than 100, you must either include a machine-readable Transparent -copy along with each Opaque copy, or state in or with each Opaque copy -a computer-network location from which the general network-using -public has access to download using public-standard network protocols -a complete Transparent copy of the Document, free of added material. -If you use the latter option, you must take reasonably prudent steps, -when you begin distribution of Opaque copies in quantity, to ensure -that this Transparent copy will remain thus accessible at the stated -location until at least one year after the last time you distribute an -Opaque copy (directly or through your agents or retailers) of that -edition to the public. - -It is requested, but not required, that you contact the authors of the -Document well before redistributing any large number of copies, to give -them a chance to provide you with an updated version of the Document. - - -4. MODIFICATIONS - -You may copy and distribute a Modified Version of the Document under -the conditions of sections 2 and 3 above, provided that you release -the Modified Version under precisely this License, with the Modified -Version filling the role of the Document, thus licensing distribution -and modification of the Modified Version to whoever possesses a copy -of it. In addition, you must do these things in the Modified Version: - -A. Use in the Title Page (and on the covers, if any) a title distinct - from that of the Document, and from those of previous versions - (which should, if there were any, be listed in the History section - of the Document). You may use the same title as a previous version - if the original publisher of that version gives permission. -B. List on the Title Page, as authors, one or more persons or entities - responsible for authorship of the modifications in the Modified - Version, together with at least five of the principal authors of the - Document (all of its principal authors, if it has fewer than five), - unless they release you from this requirement. -C. State on the Title page the name of the publisher of the - Modified Version, as the publisher. -D. Preserve all the copyright notices of the Document. -E. Add an appropriate copyright notice for your modifications - adjacent to the other copyright notices. -F. Include, immediately after the copyright notices, a license notice - giving the public permission to use the Modified Version under the - terms of this License, in the form shown in the Addendum below. -G. Preserve in that license notice the full lists of Invariant Sections - and required Cover Texts given in the Document's license notice. -H. Include an unaltered copy of this License. -I. Preserve the section Entitled "History", Preserve its Title, and add - to it an item stating at least the title, year, new authors, and - publisher of the Modified Version as given on the Title Page. If - there is no section Entitled "History" in the Document, create one - stating the title, year, authors, and publisher of the Document as - given on its Title Page, then add an item describing the Modified - Version as stated in the previous sentence. -J. Preserve the network location, if any, given in the Document for - public access to a Transparent copy of the Document, and likewise - the network locations given in the Document for previous versions - it was based on. These may be placed in the "History" section. - You may omit a network location for a work that was published at - least four years before the Document itself, or if the original - publisher of the version it refers to gives permission. -K. For any section Entitled "Acknowledgements" or "Dedications", - Preserve the Title of the section, and preserve in the section all - the substance and tone of each of the contributor acknowledgements - and/or dedications given therein. -L. Preserve all the Invariant Sections of the Document, - unaltered in their text and in their titles. Section numbers - or the equivalent are not considered part of the section titles. -M. Delete any section Entitled "Endorsements". Such a section - may not be included in the Modified Version. -N. Do not retitle any existing section to be Entitled "Endorsements" - or to conflict in title with any Invariant Section. -O. Preserve any Warranty Disclaimers. - -If the Modified Version includes new front-matter sections or -appendices that qualify as Secondary Sections and contain no material -copied from the Document, you may at your option designate some or all -of these sections as invariant. To do this, add their titles to the -list of Invariant Sections in the Modified Version's license notice. -These titles must be distinct from any other section titles. - -You may add a section Entitled "Endorsements", provided it contains -nothing but endorsements of your Modified Version by various -parties--for example, statements of peer review or that the text has -been approved by an organization as the authoritative definition of a -standard. - -You may add a passage of up to five words as a Front-Cover Text, and a -passage of up to 25 words as a Back-Cover Text, to the end of the list -of Cover Texts in the Modified Version. Only one passage of -Front-Cover Text and one of Back-Cover Text may be added by (or -through arrangements made by) any one entity. If the Document already -includes a cover text for the same cover, previously added by you or -by arrangement made by the same entity you are acting on behalf of, -you may not add another; but you may replace the old one, on explicit -permission from the previous publisher that added the old one. - -The author(s) and publisher(s) of the Document do not by this License -give permission to use their names for publicity for or to assert or -imply endorsement of any Modified Version. - - -5. COMBINING DOCUMENTS - -You may combine the Document with other documents released under this -License, under the terms defined in section 4 above for modified -versions, provided that you include in the combination all of the -Invariant Sections of all of the original documents, unmodified, and -list them all as Invariant Sections of your combined work in its -license notice, and that you preserve all their Warranty Disclaimers. - -The combined work need only contain one copy of this License, and -multiple identical Invariant Sections may be replaced with a single -copy. If there are multiple Invariant Sections with the same name but -different contents, make the title of each such section unique by -adding at the end of it, in parentheses, the name of the original -author or publisher of that section if known, or else a unique number. -Make the same adjustment to the section titles in the list of -Invariant Sections in the license notice of the combined work. - -In the combination, you must combine any sections Entitled "History" -in the various original documents, forming one section Entitled -"History"; likewise combine any sections Entitled "Acknowledgements", -and any sections Entitled "Dedications". You must delete all sections -Entitled "Endorsements". - - -6. COLLECTIONS OF DOCUMENTS - -You may make a collection consisting of the Document and other documents -released under this License, and replace the individual copies of this -License in the various documents with a single copy that is included in -the collection, provided that you follow the rules of this License for -verbatim copying of each of the documents in all other respects. - -You may extract a single document from such a collection, and distribute -it individually under this License, provided you insert a copy of this -License into the extracted document, and follow this License in all -other respects regarding verbatim copying of that document. - - -7. AGGREGATION WITH INDEPENDENT WORKS - -A compilation of the Document or its derivatives with other separate -and independent documents or works, in or on a volume of a storage or -distribution medium, is called an "aggregate" if the copyright -resulting from the compilation is not used to limit the legal rights -of the compilation's users beyond what the individual works permit. -When the Document is included in an aggregate, this License does not -apply to the other works in the aggregate which are not themselves -derivative works of the Document. - -If the Cover Text requirement of section 3 is applicable to these -copies of the Document, then if the Document is less than one half of -the entire aggregate, the Document's Cover Texts may be placed on -covers that bracket the Document within the aggregate, or the -electronic equivalent of covers if the Document is in electronic form. -Otherwise they must appear on printed covers that bracket the whole -aggregate. - - -8. TRANSLATION - -Translation is considered a kind of modification, so you may -distribute translations of the Document under the terms of section 4. -Replacing Invariant Sections with translations requires special -permission from their copyright holders, but you may include -translations of some or all Invariant Sections in addition to the -original versions of these Invariant Sections. You may include a -translation of this License, and all the license notices in the -Document, and any Warranty Disclaimers, provided that you also include -the original English version of this License and the original versions -of those notices and disclaimers. In case of a disagreement between -the translation and the original version of this License or a notice -or disclaimer, the original version will prevail. - -If a section in the Document is Entitled "Acknowledgements", -"Dedications", or "History", the requirement (section 4) to Preserve -its Title (section 1) will typically require changing the actual -title. - - -9. TERMINATION - -You may not copy, modify, sublicense, or distribute the Document except -as expressly provided for under this License. Any other attempt to -copy, modify, sublicense or distribute the Document 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. - - -10. FUTURE REVISIONS OF THIS LICENSE - -The Free Software Foundation may publish new, revised versions -of the GNU Free Documentation 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. See -http://www.gnu.org/copyleft/. - -Each version of the License is given a distinguishing version number. -If the Document specifies that a particular numbered version of this -License "or any later version" applies to it, you have the option of -following the terms and conditions either of that specified version or -of any later version that has been published (not as a draft) by the -Free Software Foundation. If the Document does not specify a version -number of this License, you may choose any version ever published (not -as a draft) by the Free Software Foundation. - - -ADDENDUM: How to use this License for your documents - -To use this License in a document you have written, include a copy of -the License in the document and put the following copyright and -license notices just after the title page: - - Copyright (c) YEAR YOUR NAME. - Permission is granted to copy, distribute and/or modify this document - under the terms of the GNU Free Documentation License, Version 1.2 - or any later version published by the Free Software Foundation; - with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. - A copy of the license is included in the section entitled "GNU - Free Documentation License". - -If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, -replace the "with...Texts." line with this: - - with the Invariant Sections being LIST THEIR TITLES, with the - Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. - -If you have Invariant Sections without Cover Texts, or some other -combination of the three, merge those two alternatives to suit the -situation. - -If your document contains nontrivial examples of program code, we -recommend releasing these examples in parallel under your choice of -free software license, such as the GNU General Public License, -to permit their use in free software. diff --git a/flac/COPYING.GPL b/flac/COPYING.GPL deleted file mode 100644 index d159169..0000000 --- a/flac/COPYING.GPL +++ /dev/null @@ -1,339 +0,0 @@ - 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. - - - Copyright (C) - - 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. - - , 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/flac/COPYING.LGPL b/flac/COPYING.LGPL deleted file mode 100644 index 5ab7695..0000000 --- a/flac/COPYING.LGPL +++ /dev/null @@ -1,504 +0,0 @@ - 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. - - - Copyright (C) - - 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.1 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 - -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. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/flac/COPYING.Xiph b/flac/COPYING.Xiph deleted file mode 100644 index 86629af..0000000 --- a/flac/COPYING.Xiph +++ /dev/null @@ -1,29 +0,0 @@ -Copyright (C) 2000-2009 Josh Coalson -Copyright (C) 2011-2023 Xiph.Org Foundation - -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 Xiph.Org Foundation 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 FOUNDATION 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/flac/README.md b/flac/README.md deleted file mode 100644 index 2979862..0000000 --- a/flac/README.md +++ /dev/null @@ -1,278 +0,0 @@ - - -# Free Lossless Audio Codec (FLAC) - -FLAC is open source software that can reduce the amount of storage space -needed to store digital audio signals without needing to remove -information in doing so. - -The files read and produced by this software are called FLAC files. As -these files (which follow the [FLAC format](https://xiph.org/flac/format.html)) -can be read from and written to by other software as well, this software -is often referred to as the FLAC reference implementation. - -FLAC has been developed by volunteers. If you want to help out, see -CONTRIBUTING.md for more information. - -## Components - -FLAC is comprised of - * libFLAC, a library which implements reference encoders and - decoders for native FLAC and Ogg FLAC, and a metadata interface - * libFLAC++, a C++ object wrapper library around libFLAC - * `flac`, a command-line program for encoding and decoding files - * `metaflac`, a command-line program for viewing and editing FLAC - metadata - * user and API documentation - -The libraries (libFLAC, libFLAC++) are licensed under Xiph.org's -BSD-like license (see COPYING.Xiph). All other programs and plugins are -licensed under the GNU General Public License (see COPYING.GPL). The -documentation is licensed under the GNU Free Documentation License -(see COPYING.FDL). - -## Documentation - -For documentation of the `flac` and `metaflac` command line tools, see -the directory man, which contains the files flac.md and metaflac.md - -The API documentation is in html and is generated by Doxygen. It can be -found in the directory doc/html/api. It is included in a release tarball -and must be build with Doxygen when the source is taken directly from -git. - -The directory examples contains example source code on using libFLAC and -libFLAC++. - -Documentation concerning the FLAC format itself (which can be used to -create software reading and writing FLAC software independent from -libFLAC) was included in previous releases, but can now be found on -https://datatracker.ietf.org/doc/draft-ietf-cellar-flac/ Additionally -a set of files for conformance testing called the FLAC decoder testbench -can be found at https://github.com/ietf-wg-cellar/flac-test-files - -If you have questions about FLAC that this document does not answer, -please submit them at the following tracker so this document can be -improved: - -https://github.com/xiph/flac/issues - -## Building FLAC - -All components of the FLAC project can be build with a variety of -compilers (including GCC, Clang, Visual Studio, Intel C++ Compiler) on -many architectures (inluding x86, x86_64, ARMv7, ARMv8 and PowerPC) -for many different operating systems. - -To do this, FLAC provides two build systems: one using GNU's autotools -and one with CMake. Both differ slighly in configuration options, but -should be considered equivalent for most use cases. - -FLAC used to provide files specifically for building with Visual Studio, -but these have been removed in favor of using CMake. - -## Building with CMake - -CMake is a cross-platform build system. FLAC can be built on Windows, -Linux, Mac OS X using CMake. - -You can use either CMake's CLI or GUI. We recommend you to have a -separate build folder outside the repository in order to not spoil it -with generated files. It is possible however to do a so-called in-tree -build, in that case /path/to/flac-build in the following examples is -equal to /path/to/flac-source. - -### CMake CLI - -Go to your build folder and run something like this: - -``` -/path/to/flac-build$ cmake /path/to/flac-source -``` - -or e.g. in Windows shell - -``` -C:\path\to\flac-build> cmake \path\to\flac-source -``` - -(provided that cmake is in your %PATH% variable) - -That will generate build scripts for the default build system (e.g. -Makefiles for UNIX). After that you start build with a command like -this: - -``` -/path/to/flac-build$ make -``` - -And afterwards you can run tests or install the built libraries and -headers - -``` -/path/to/flac-build$ make test -/path/to/flac-build$ make install -``` - -If you want use a build system other than default add -G flag to cmake, -e.g.: - -``` -/path/to/flac-build$ cmake /path/to/flac-source -GNinja -/path/to/flac-build$ ninja -``` - -or: - -``` -/path/to/flac-build$ cmake /path/to/flac-source -GXcode -``` - -Use cmake --help to see the list of available generators. - -By default CMake will search for OGG. If CMake fails to find it you can -help CMake by specifying the exact path: - -``` -/path/to/flac-build$ cmake /path/to/flac-source -DOGG_ROOT=/path/to/ogg -``` - -If you would like CMake to build OGG alongside FLAC, you can place the -ogg sources directly in the flac source directory as a subdirectory with -the name ogg, for example: - -``` -/path/to/flac-source/ogg -``` - -If you don't want to build flac with OGG support you can tell CMake not -to look for OGG: - -``` -/path/to/flac-build$ cmake /path/to/flac-source -DWITH_OGG=OFF -``` - -Other FLAC's options (e.g. building C++ lib or docs) can also be put to -cmake through -D flag. If you want to know what options are available, -use -LH: - -``` -/path/to/flac-build$ cmake /path/to/flac-source -LH -``` - -### CMake GUI (for Visual Studio) -It is likely that you would prefer to use the CMake GUI if you use -Visual Studio to build FLAC. It's in essence the same process as -building using CLI. - -Open cmake-gui. In the window select a source directory (the -repository's root), a build directory (some other directory outside the -repository). Then press button "Configure". CMake will ask you which -build system you prefer. Choose that version of Visual Studio which you -have on your system, choose whether you want to build for Win32 or x64. -Press OK. - -After CMake finishes you can change the configuration to your liking and -if you change anything, run Configure again. With the "Generate" button, -CMake creates Visual Studio files, which can be opened from Visual -Studio. With the button "Open Project" CMake will launch Visual Studio -and open the generated solution. You can use the project files as usual -but remember that they were generated by CMake. That means that your -changes (e.g. some additional compile flags) will be lost when you run -CMake next time. - -CMake searches by default for OGG on your system and returns an error -if it cannot find it. If you want to build OGG alongside FLAC, you can -download the OGG sources and extract them in a subdirectory of the FLAC -source directory with the name ogg (i.e. /path/to/flac-source/ogg) -before running CMake. If you don't want to build FLAC with OGG support, -untick the box following WITH_OGG flag in the list of variables in -cmake-gui window and run "Configure" again. - -If CMake fails to find MSVC compiler then running cmake-gui from MS -Developer comand prompt should help. - -## Building with GNU autotools - -FLAC uses autoconf and libtool for configuring and building. To -configure a build, open a commmand line/terminal and run `./configure` -You can provide options to this command, which are listed by running -`./configure --help`. - -In case the configure script is not present (for example when building -from git and not from a release tarball), it can be generated by running -`./autogen.sh`. This may require a libtool development package though. - -After configuration, build with `make`, verify the build with -`make check` and install with `make install`. Installation might require -administrator priviledged, i.e. `sudo make install`. - -The 'make check' step is optional; omit it to skip all the tests, which -can take about an hour to complete. Even though it will stop with an -explicit message on any failure, it does print out a lot of stuff so you -might want to capture the output to a file if you're having a problem. -Also, don't run 'make check' as root because it confuses some of the -tests. - -Summarizing: - -``` -./configure -make && make check -sudo make install -``` - -## Note to embedded developers - -libFLAC has grown larger over time as more functionality has been -included, but much of it may be unnecessary for a particular embedded -implementation. Unused parts may be pruned by some simple editing of -configure.ac and src/libFLAC/Makefile.am; the following dependency -graph shows which modules may be pruned without breaking things -further down: - -``` -metadata.h - stream_decoder.h - format.h - -stream_encoder.h - stream_decoder.h - format.h - -stream_decoder.h - format.h -``` - -In other words, for pure decoding applications, both the stream encoder -and metadata editing interfaces can be safely removed. Note that this -is specific to building the libraries for embedded use. The command line -tools do not provide such compartmentalization, and require a complete -libFLAC build to function. - -There is a section dedicated to embedded use in the libFLAC API -HTML documentation (see doc/html/api/index.html). - -Also, there are several places in the libFLAC code with comments marked -with "OPT:" where a #define can be changed to enable code that might be -faster on a specific platform. Experimenting with these can yield -faster binaries. diff --git a/flac/build-flac.lua b/flac/build-flac.lua deleted file mode 100644 index e7c7594..0000000 --- a/flac/build-flac.lua +++ /dev/null @@ -1,66 +0,0 @@ -local m = {} - -local scriptdir = path.getabsolute(path.getdirectory(_SCRIPT)) -local ogg = require("vendor/ogg/build-ogg") -function m.generateproject(liboutdir, intdir) - project"flac" - language"C" -- c++ will mangle names and sfml wont build - kind"staticLib" - targetdir (liboutdir) - objdir(intdir) - warnings"Off" - - ogg.link() - - defines - { - "FLAC__NO_DLL", - "CPU_IS_BIG_ENDIAN=0", - "FLAC__HAS_OGG=1", - "PACKAGE_VERSION=\"\"", - } - - filter"system:linux" - defines - { - "HAVE_LROUND",--fix error in lpc.c - "HAVE_STDINT_H", --fix error in alloc.h <# error> - } - - includedirs - { - path.join(scriptdir, "include"), - path.join(scriptdir, "src/libFLAC/include"), - } - - files - { - path.join(scriptdir, "src/libFLAC/**.c"), - } - - removefiles - { - path.join(scriptdir, "src/libFLAC/deduplication/**"), - } - - filter"system:windows" - files - { - path.join(scriptdir, "src/share/win_utf8_io/**.c"), - } - - filter"" - -end - -function m.link() - externalincludedirs - { - path.join(scriptdir, "include"), - path.join(scriptdir, "src/libFLAC/include"), - path.join(scriptdir, "../ogg/include") - } - links {"flac", "ogg"} -end - -return m diff --git a/flac/include/FLAC++/Makefile.am b/flac/include/FLAC++/Makefile.am deleted file mode 100644 index ba5daa5..0000000 --- a/flac/include/FLAC++/Makefile.am +++ /dev/null @@ -1,39 +0,0 @@ -# libFLAC++ - Free Lossless Audio Codec library -# Copyright (C) 2002-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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 Xiph.org Foundation 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 FOUNDATION 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. - -flaccppincludedir = $(includedir)/FLAC++ -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include -flaccppinclude_HEADERS = \ - all.h \ - decoder.h \ - encoder.h \ - export.h \ - metadata.h diff --git a/flac/include/FLAC++/all.h b/flac/include/FLAC++/all.h deleted file mode 100644 index fa5bd41..0000000 --- a/flac/include/FLAC++/all.h +++ /dev/null @@ -1,49 +0,0 @@ -/* libFLAC++ - Free Lossless Audio Codec library - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLACPP__ALL_H -#define FLACPP__ALL_H - -#include "export.h" - -#include "encoder.h" -#include "decoder.h" -#include "metadata.h" - -/** \defgroup flacpp FLAC C++ API - * - * The FLAC C++ API is the interface to libFLAC++, a set of classes - * that encapsulate the encoders, decoders, and metadata interfaces - * in libFLAC. - */ - -#endif diff --git a/flac/include/FLAC++/decoder.h b/flac/include/FLAC++/decoder.h deleted file mode 100644 index 6f0bda9..0000000 --- a/flac/include/FLAC++/decoder.h +++ /dev/null @@ -1,248 +0,0 @@ -/* libFLAC++ - Free Lossless Audio Codec library - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLACPP__DECODER_H -#define FLACPP__DECODER_H - -#include "export.h" - -#include -#include "FLAC/stream_decoder.h" - - -/** \file include/FLAC++/decoder.h - * - * \brief - * This module contains the classes which implement the various - * decoders. - * - * See the detailed documentation in the - * \link flacpp_decoder decoder \endlink module. - */ - -/** \defgroup flacpp_decoder FLAC++/decoder.h: decoder classes - * \ingroup flacpp - * - * \brief - * This module describes the decoder layers provided by libFLAC++. - * - * The libFLAC++ decoder classes are object wrappers around their - * counterparts in libFLAC. All decoding layers available in - * libFLAC are also provided here. The interface is very similar; - * make sure to read the \link flac_decoder libFLAC decoder module \endlink. - * - * There are only two significant differences here. First, instead of - * passing in C function pointers for callbacks, you inherit from the - * decoder class and provide implementations for the callbacks in your - * derived class; because of this there is no need for a 'client_data' - * property. - * - * Second, there are two stream decoder classes. FLAC::Decoder::Stream - * is used for the same cases that FLAC__stream_decoder_init_stream() / - * FLAC__stream_decoder_init_ogg_stream() are used, and FLAC::Decoder::File - * is used for the same cases that - * FLAC__stream_decoder_init_FILE() and FLAC__stream_decoder_init_file() / - * FLAC__stream_decoder_init_ogg_FILE() and FLAC__stream_decoder_init_ogg_file() - * are used. - */ - -namespace FLAC { - namespace Decoder { - - /** \ingroup flacpp_decoder - * \brief - * This class wraps the ::FLAC__StreamDecoder. If you are - * decoding from a file, FLAC::Decoder::File may be more - * convenient. - * - * The usage of this class is similar to FLAC__StreamDecoder, - * except instead of providing callbacks to - * FLAC__stream_decoder_init*_stream(), you will inherit from this - * class and override the virtual callback functions with your - * own implementations, then call init() or init_ogg(). The rest - * of the calls work the same as in the C layer. - * - * Only the read, write, and error callbacks are mandatory. The - * others are optional; this class provides default - * implementations that do nothing. In order for seeking to work - * you must override seek_callback(), tell_callback(), - * length_callback(), and eof_callback(). - */ - class FLACPP_API Stream { - public: - /** This class is a wrapper around FLAC__StreamDecoderState. - */ - class FLACPP_API State { - public: - inline State(::FLAC__StreamDecoderState state): state_(state) { } - inline operator ::FLAC__StreamDecoderState() const { return state_; } - inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; } - inline const char *resolved_as_cstring(const Stream &decoder) const { return ::FLAC__stream_decoder_get_resolved_state_string(decoder.decoder_); } - protected: - ::FLAC__StreamDecoderState state_; - }; - - Stream(); - virtual ~Stream(); - - //@{ - /** Call after construction to check that the object was created - * successfully. If not, use get_state() to find out why not. - */ - virtual bool is_valid() const; - inline operator bool() const { return is_valid(); } ///< See is_valid() - //@} - - virtual bool set_ogg_serial_number(long value); ///< See FLAC__stream_decoder_set_ogg_serial_number() - virtual bool set_md5_checking(bool value); ///< See FLAC__stream_decoder_set_md5_checking() - virtual bool set_metadata_respond(::FLAC__MetadataType type); ///< See FLAC__stream_decoder_set_metadata_respond() - virtual bool set_metadata_respond_application(const FLAC__byte id[4]); ///< See FLAC__stream_decoder_set_metadata_respond_application() - virtual bool set_metadata_respond_all(); ///< See FLAC__stream_decoder_set_metadata_respond_all() - virtual bool set_metadata_ignore(::FLAC__MetadataType type); ///< See FLAC__stream_decoder_set_metadata_ignore() - virtual bool set_metadata_ignore_application(const FLAC__byte id[4]); ///< See FLAC__stream_decoder_set_metadata_ignore_application() - virtual bool set_metadata_ignore_all(); ///< See FLAC__stream_decoder_set_metadata_ignore_all() - - /* get_state() is not virtual since we want subclasses to be able to return their own state */ - State get_state() const; ///< See FLAC__stream_decoder_get_state() - virtual bool get_md5_checking() const; ///< See FLAC__stream_decoder_get_md5_checking() - virtual FLAC__uint64 get_total_samples() const; ///< See FLAC__stream_decoder_get_total_samples() - virtual uint32_t get_channels() const; ///< See FLAC__stream_decoder_get_channels() - virtual ::FLAC__ChannelAssignment get_channel_assignment() const; ///< See FLAC__stream_decoder_get_channel_assignment() - virtual uint32_t get_bits_per_sample() const; ///< See FLAC__stream_decoder_get_bits_per_sample() - virtual uint32_t get_sample_rate() const; ///< See FLAC__stream_decoder_get_sample_rate() - virtual uint32_t get_blocksize() const; ///< See FLAC__stream_decoder_get_blocksize() - virtual bool get_decode_position(FLAC__uint64 *position) const; ///< See FLAC__stream_decoder_get_decode_position() - - virtual ::FLAC__StreamDecoderInitStatus init(); ///< Seek FLAC__stream_decoder_init_stream() - virtual ::FLAC__StreamDecoderInitStatus init_ogg(); ///< Seek FLAC__stream_decoder_init_ogg_stream() - - virtual bool finish(); ///< See FLAC__stream_decoder_finish() - - virtual bool flush(); ///< See FLAC__stream_decoder_flush() - virtual bool reset(); ///< See FLAC__stream_decoder_reset() - - virtual bool process_single(); ///< See FLAC__stream_decoder_process_single() - virtual bool process_until_end_of_metadata(); ///< See FLAC__stream_decoder_process_until_end_of_metadata() - virtual bool process_until_end_of_stream(); ///< See FLAC__stream_decoder_process_until_end_of_stream() - virtual bool skip_single_frame(); ///< See FLAC__stream_decoder_skip_single_frame() - - virtual bool seek_absolute(FLAC__uint64 sample); ///< See FLAC__stream_decoder_seek_absolute() - protected: - /// see FLAC__StreamDecoderReadCallback - virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) = 0; - - /// see FLAC__StreamDecoderSeekCallback - virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset); - - /// see FLAC__StreamDecoderTellCallback - virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset); - - /// see FLAC__StreamDecoderLengthCallback - virtual ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length); - - /// see FLAC__StreamDecoderEofCallback - virtual bool eof_callback(); - - /// see FLAC__StreamDecoderWriteCallback - virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0; - - /// see FLAC__StreamDecoderMetadataCallback - virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata); - - /// see FLAC__StreamDecoderErrorCallback - virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0; - -#if (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC) - // lame hack: some compilers can't see a protected decoder_ from nested State::resolved_as_cstring() - friend State; -#endif - ::FLAC__StreamDecoder *decoder_; - - static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); - static ::FLAC__StreamDecoderSeekStatus seek_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); - static ::FLAC__StreamDecoderTellStatus tell_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); - static ::FLAC__StreamDecoderLengthStatus length_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); - static FLAC__bool eof_callback_(const ::FLAC__StreamDecoder *decoder, void *client_data); - static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); - static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data); - static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data); - private: - // Private and undefined so you can't use them: - Stream(const Stream &); - void operator=(const Stream &); - }; - - /** \ingroup flacpp_decoder - * \brief - * This class wraps the ::FLAC__StreamDecoder. If you are - * not decoding from a file, you may need to use - * FLAC::Decoder::Stream. - * - * The usage of this class is similar to FLAC__StreamDecoder, - * except instead of providing callbacks to - * FLAC__stream_decoder_init*_FILE() or - * FLAC__stream_decoder_init*_file(), you will inherit from this - * class and override the virtual callback functions with your - * own implementations, then call init() or init_off(). The rest - * of the calls work the same as in the C layer. - * - * Only the write, and error callbacks from FLAC::Decoder::Stream - * are mandatory. The others are optional; this class provides - * full working implementations for all other callbacks and - * supports seeking. - */ - class FLACPP_API File: public Stream { - public: - File(); - virtual ~File(); - - using Stream::init; - virtual ::FLAC__StreamDecoderInitStatus init(FILE *file); ///< See FLAC__stream_decoder_init_FILE() - virtual ::FLAC__StreamDecoderInitStatus init(const char *filename); ///< See FLAC__stream_decoder_init_file() - virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename); ///< See FLAC__stream_decoder_init_file() - using Stream::init_ogg; - virtual ::FLAC__StreamDecoderInitStatus init_ogg(FILE *file); ///< See FLAC__stream_decoder_init_ogg_FILE() - virtual ::FLAC__StreamDecoderInitStatus init_ogg(const char *filename); ///< See FLAC__stream_decoder_init_ogg_file() - virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename); ///< See FLAC__stream_decoder_init_ogg_file() - protected: - // this is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer - virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes); - private: - // Private and undefined so you can't use them: - File(const File &); - void operator=(const File &); - }; - - } -} - -#endif diff --git a/flac/include/FLAC++/encoder.h b/flac/include/FLAC++/encoder.h deleted file mode 100644 index 2400823..0000000 --- a/flac/include/FLAC++/encoder.h +++ /dev/null @@ -1,265 +0,0 @@ -/* libFLAC++ - Free Lossless Audio Codec library - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLACPP__ENCODER_H -#define FLACPP__ENCODER_H - -#include "export.h" - -#include "FLAC/stream_encoder.h" -#include "decoder.h" -#include "metadata.h" - - -/** \file include/FLAC++/encoder.h - * - * \brief - * This module contains the classes which implement the various - * encoders. - * - * See the detailed documentation in the - * \link flacpp_encoder encoder \endlink module. - */ - -/** \defgroup flacpp_encoder FLAC++/encoder.h: encoder classes - * \ingroup flacpp - * - * \brief - * This module describes the encoder layers provided by libFLAC++. - * - * The libFLAC++ encoder classes are object wrappers around their - * counterparts in libFLAC. All encoding layers available in - * libFLAC are also provided here. The interface is very similar; - * make sure to read the \link flac_encoder libFLAC encoder module \endlink. - * - * There are only two significant differences here. First, instead of - * passing in C function pointers for callbacks, you inherit from the - * encoder class and provide implementations for the callbacks in your - * derived class; because of this there is no need for a 'client_data' - * property. - * - * Second, there are two stream encoder classes. FLAC::Encoder::Stream - * is used for the same cases that FLAC__stream_encoder_init_stream() / - * FLAC__stream_encoder_init_ogg_stream() are used, and FLAC::Encoder::File - * is used for the same cases that - * FLAC__stream_encoder_init_FILE() and FLAC__stream_encoder_init_file() / - * FLAC__stream_encoder_init_ogg_FILE() and FLAC__stream_encoder_init_ogg_file() - * are used. - */ - -namespace FLAC { - namespace Encoder { - - /** \ingroup flacpp_encoder - * \brief - * This class wraps the ::FLAC__StreamEncoder. If you are - * encoding to a file, FLAC::Encoder::File may be more - * convenient. - * - * The usage of this class is similar to FLAC__StreamEncoder, - * except instead of providing callbacks to - * FLAC__stream_encoder_init*_stream(), you will inherit from this - * class and override the virtual callback functions with your - * own implementations, then call init() or init_ogg(). The rest of - * the calls work the same as in the C layer. - * - * Only the write callback is mandatory. The others are - * optional; this class provides default implementations that do - * nothing. In order for some STREAMINFO and SEEKTABLE data to - * be written properly, you must override seek_callback() and - * tell_callback(); see FLAC__stream_encoder_init_stream() as to - * why. - */ - class FLACPP_API Stream { - public: - /** This class is a wrapper around FLAC__StreamEncoderState. - */ - class FLACPP_API State { - public: - inline State(::FLAC__StreamEncoderState state): state_(state) { } - inline operator ::FLAC__StreamEncoderState() const { return state_; } - inline const char *as_cstring() const { return ::FLAC__StreamEncoderStateString[state_]; } - inline const char *resolved_as_cstring(const Stream &encoder) const { return ::FLAC__stream_encoder_get_resolved_state_string(encoder.encoder_); } - protected: - ::FLAC__StreamEncoderState state_; - }; - - Stream(); - virtual ~Stream(); - - //@{ - /** Call after construction to check that the object was created - * successfully. If not, use get_state() to find out why not. - * - */ - virtual bool is_valid() const; - inline operator bool() const { return is_valid(); } ///< See is_valid() - //@} - - virtual bool set_ogg_serial_number(long value); ///< See FLAC__stream_encoder_set_ogg_serial_number() - virtual bool set_verify(bool value); ///< See FLAC__stream_encoder_set_verify() - virtual bool set_streamable_subset(bool value); ///< See FLAC__stream_encoder_set_streamable_subset() - virtual bool set_channels(uint32_t value); ///< See FLAC__stream_encoder_set_channels() - virtual bool set_bits_per_sample(uint32_t value); ///< See FLAC__stream_encoder_set_bits_per_sample() - virtual bool set_sample_rate(uint32_t value); ///< See FLAC__stream_encoder_set_sample_rate() - virtual bool set_compression_level(uint32_t value); ///< See FLAC__stream_encoder_set_compression_level() - virtual bool set_blocksize(uint32_t value); ///< See FLAC__stream_encoder_set_blocksize() - virtual bool set_do_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_do_mid_side_stereo() - virtual bool set_loose_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_loose_mid_side_stereo() - virtual bool set_apodization(const char *specification); ///< See FLAC__stream_encoder_set_apodization() - virtual bool set_max_lpc_order(uint32_t value); ///< See FLAC__stream_encoder_set_max_lpc_order() - virtual bool set_qlp_coeff_precision(uint32_t value); ///< See FLAC__stream_encoder_set_qlp_coeff_precision() - virtual bool set_do_qlp_coeff_prec_search(bool value); ///< See FLAC__stream_encoder_set_do_qlp_coeff_prec_search() - virtual bool set_do_escape_coding(bool value); ///< See FLAC__stream_encoder_set_do_escape_coding() - virtual bool set_do_exhaustive_model_search(bool value); ///< See FLAC__stream_encoder_set_do_exhaustive_model_search() - virtual bool set_min_residual_partition_order(uint32_t value); ///< See FLAC__stream_encoder_set_min_residual_partition_order() - virtual bool set_max_residual_partition_order(uint32_t value); ///< See FLAC__stream_encoder_set_max_residual_partition_order() - virtual bool set_rice_parameter_search_dist(uint32_t value); ///< See FLAC__stream_encoder_set_rice_parameter_search_dist() - virtual bool set_total_samples_estimate(FLAC__uint64 value); ///< See FLAC__stream_encoder_set_total_samples_estimate() - virtual bool set_metadata(::FLAC__StreamMetadata **metadata, uint32_t num_blocks); ///< See FLAC__stream_encoder_set_metadata() - virtual bool set_metadata(FLAC::Metadata::Prototype **metadata, uint32_t num_blocks); ///< See FLAC__stream_encoder_set_metadata() - virtual bool set_limit_min_bitrate(bool value); ///< See FLAC__stream_encoder_set_limit_min_bitrate() - - /* get_state() is not virtual since we want subclasses to be able to return their own state */ - State get_state() const; ///< See FLAC__stream_encoder_get_state() - virtual Decoder::Stream::State get_verify_decoder_state() const; ///< See FLAC__stream_encoder_get_verify_decoder_state() - virtual void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, uint32_t *frame_number, uint32_t *channel, uint32_t *sample, FLAC__int32 *expected, FLAC__int32 *got); ///< See FLAC__stream_encoder_get_verify_decoder_error_stats() - virtual bool get_verify() const; ///< See FLAC__stream_encoder_get_verify() - virtual bool get_streamable_subset() const; ///< See FLAC__stream_encoder_get_streamable_subset() - virtual bool get_do_mid_side_stereo() const; ///< See FLAC__stream_encoder_get_do_mid_side_stereo() - virtual bool get_loose_mid_side_stereo() const; ///< See FLAC__stream_encoder_get_loose_mid_side_stereo() - virtual uint32_t get_channels() const; ///< See FLAC__stream_encoder_get_channels() - virtual uint32_t get_bits_per_sample() const; ///< See FLAC__stream_encoder_get_bits_per_sample() - virtual uint32_t get_sample_rate() const; ///< See FLAC__stream_encoder_get_sample_rate() - virtual uint32_t get_blocksize() const; ///< See FLAC__stream_encoder_get_blocksize() - virtual uint32_t get_max_lpc_order() const; ///< See FLAC__stream_encoder_get_max_lpc_order() - virtual uint32_t get_qlp_coeff_precision() const; ///< See FLAC__stream_encoder_get_qlp_coeff_precision() - virtual bool get_do_qlp_coeff_prec_search() const; ///< See FLAC__stream_encoder_get_do_qlp_coeff_prec_search() - virtual bool get_do_escape_coding() const; ///< See FLAC__stream_encoder_get_do_escape_coding() - virtual bool get_do_exhaustive_model_search() const; ///< See FLAC__stream_encoder_get_do_exhaustive_model_search() - virtual uint32_t get_min_residual_partition_order() const; ///< See FLAC__stream_encoder_get_min_residual_partition_order() - virtual uint32_t get_max_residual_partition_order() const; ///< See FLAC__stream_encoder_get_max_residual_partition_order() - virtual uint32_t get_rice_parameter_search_dist() const; ///< See FLAC__stream_encoder_get_rice_parameter_search_dist() - virtual FLAC__uint64 get_total_samples_estimate() const; ///< See FLAC__stream_encoder_get_total_samples_estimate() - virtual bool get_limit_min_bitrate() const; ///< See FLAC__stream_encoder_get_limit_min_bitrate() - - virtual ::FLAC__StreamEncoderInitStatus init(); ///< See FLAC__stream_encoder_init_stream() - virtual ::FLAC__StreamEncoderInitStatus init_ogg(); ///< See FLAC__stream_encoder_init_ogg_stream() - - virtual bool finish(); ///< See FLAC__stream_encoder_finish() - - virtual bool process(const FLAC__int32 * const buffer[], uint32_t samples); ///< See FLAC__stream_encoder_process() - virtual bool process_interleaved(const FLAC__int32 buffer[], uint32_t samples); ///< See FLAC__stream_encoder_process_interleaved() - protected: - /// See FLAC__StreamEncoderReadCallback - virtual ::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes); - - /// See FLAC__StreamEncoderWriteCallback - virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame) = 0; - - /// See FLAC__StreamEncoderSeekCallback - virtual ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset); - - /// See FLAC__StreamEncoderTellCallback - virtual ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset); - - /// See FLAC__StreamEncoderMetadataCallback - virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata); - -#if (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC) - // lame hack: some compilers can't see a protected encoder_ from nested State::resolved_as_cstring() - friend State; -#endif - ::FLAC__StreamEncoder *encoder_; - - static ::FLAC__StreamEncoderReadStatus read_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data); - static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data); - static ::FLAC__StreamEncoderSeekStatus seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); - static ::FLAC__StreamEncoderTellStatus tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data); - static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data); - private: - // Private and undefined so you can't use them: - Stream(const Stream &); - void operator=(const Stream &); - }; - - /** \ingroup flacpp_encoder - * \brief - * This class wraps the ::FLAC__StreamEncoder. If you are - * not encoding to a file, you may need to use - * FLAC::Encoder::Stream. - * - * The usage of this class is similar to FLAC__StreamEncoder, - * except instead of providing callbacks to - * FLAC__stream_encoder_init*_FILE() or - * FLAC__stream_encoder_init*_file(), you will inherit from this - * class and override the virtual callback functions with your - * own implementations, then call init() or init_ogg(). The rest - * of the calls work the same as in the C layer. - * - * There are no mandatory callbacks; all the callbacks from - * FLAC::Encoder::Stream are implemented here fully and support - * full post-encode STREAMINFO and SEEKTABLE updating. There is - * only an optional progress callback which you may override to - * get periodic reports on the progress of the encode. - */ - class FLACPP_API File: public Stream { - public: - File(); - virtual ~File(); - - using Stream::init; - virtual ::FLAC__StreamEncoderInitStatus init(FILE *file); ///< See FLAC__stream_encoder_init_FILE() - virtual ::FLAC__StreamEncoderInitStatus init(const char *filename); ///< See FLAC__stream_encoder_init_file() - virtual ::FLAC__StreamEncoderInitStatus init(const std::string &filename); ///< See FLAC__stream_encoder_init_file() - using Stream::init_ogg; - virtual ::FLAC__StreamEncoderInitStatus init_ogg(FILE *file); ///< See FLAC__stream_encoder_init_ogg_FILE() - virtual ::FLAC__StreamEncoderInitStatus init_ogg(const char *filename); ///< See FLAC__stream_encoder_init_ogg_file() - virtual ::FLAC__StreamEncoderInitStatus init_ogg(const std::string &filename); ///< See FLAC__stream_encoder_init_ogg_file() - protected: - /// See FLAC__StreamEncoderProgressCallback - virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate); - - /// This is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer - virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame); - private: - static void progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate, void *client_data); - - // Private and undefined so you can't use them: - File(const Stream &); - void operator=(const Stream &); - }; - - } -} - -#endif diff --git a/flac/include/FLAC++/export.h b/flac/include/FLAC++/export.h deleted file mode 100644 index 21d9d8b..0000000 --- a/flac/include/FLAC++/export.h +++ /dev/null @@ -1,100 +0,0 @@ -/* libFLAC++ - Free Lossless Audio Codec library - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLACPP__EXPORT_H -#define FLACPP__EXPORT_H - -/** \file include/FLAC++/export.h - * - * \brief - * This module contains \#defines and symbols for exporting function - * calls, and providing version information and compiled-in features. - * - * See the \link flacpp_export export \endlink module. - */ - -/** \defgroup flacpp_export FLAC++/export.h: export symbols - * \ingroup flacpp - * - * \brief - * This module contains \#defines and symbols for exporting function - * calls, and providing version information and compiled-in features. - * - * If you are compiling for Windows (with Visual Studio or MinGW for - * example) and will link to the static library (libFLAC++.lib) you - * should define FLAC__NO_DLL in your project to make sure the symbols - * are exported properly. - * - * \{ - */ - -/** This \#define is used internally in libFLAC and its headers to make - * sure the correct symbols are exported when working with shared - * libraries. On Windows, this \#define is set to __declspec(dllexport) - * when compiling libFLAC into a library and to __declspec(dllimport) - * when the headers are used to link to that DLL. On non-Windows systems - * it is used to set symbol visibility. - * - * Because of this, the define FLAC__NO_DLL must be defined when linking - * to libFLAC statically or linking will fail. - */ -/* This has grown quite complicated. FLAC__NO_DLL is used by MSVC sln - * files and CMake, which build either static or shared. autotools can - * build static, shared or **both**. Therefore, DLL_EXPORT, which is set - * by libtool, must override FLAC__NO_DLL on building shared components - */ -#if defined(_WIN32) -#if defined(FLAC__NO_DLL) && !(defined(DLL_EXPORT)) -#define FLACPP_API -#else -#ifdef FLACPP_API_EXPORTS -#define FLACPP_API __declspec(dllexport) -#else -#define FLACPP_API __declspec(dllimport) -#endif -#endif -#elif defined(FLAC__USE_VISIBILITY_ATTR) -#define FLACPP_API __attribute__ ((visibility ("default"))) -#else -#define FLACPP_API -#endif - -/** These \#defines will mirror the libtool-based library version number, see - * http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning - */ -#define FLACPP_API_VERSION_CURRENT 10 -#define FLACPP_API_VERSION_REVISION 1 /**< see above */ -#define FLACPP_API_VERSION_AGE 0 /**< see above */ - -/* \} */ - -#endif diff --git a/flac/include/FLAC++/metadata.h b/flac/include/FLAC++/metadata.h deleted file mode 100644 index 26bc476..0000000 --- a/flac/include/FLAC++/metadata.h +++ /dev/null @@ -1,1234 +0,0 @@ -/* libFLAC++ - Free Lossless Audio Codec library - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLACPP__METADATA_H -#define FLACPP__METADATA_H - -#include "export.h" - -#include "FLAC/metadata.h" - -// =============================================================== -// -// Full documentation for the metadata interface can be found -// in the C layer in include/FLAC/metadata.h -// -// =============================================================== - -/** \file include/FLAC++/metadata.h - * - * \brief - * This module provides classes for creating and manipulating FLAC - * metadata blocks in memory, and three progressively more powerful - * interfaces for traversing and editing metadata in FLAC files. - * - * See the detailed documentation for each interface in the - * \link flacpp_metadata metadata \endlink module. - */ - -/** \defgroup flacpp_metadata FLAC++/metadata.h: metadata interfaces - * \ingroup flacpp - * - * \brief - * This module provides classes for creating and manipulating FLAC - * metadata blocks in memory, and three progressively more powerful - * interfaces for traversing and editing metadata in FLAC files. - * - * The behavior closely mimics the C layer interface; be sure to read - * the detailed description of the - * \link flac_metadata C metadata module \endlink. Note that like the - * C layer, currently only the Chain interface (level 2) supports Ogg - * FLAC files, and it is read-only i.e. no writing back changed - * metadata to file. - */ - - -namespace FLAC { - namespace Metadata { - - // ============================================================ - // - // Metadata objects - // - // ============================================================ - - /** \defgroup flacpp_metadata_object FLAC++/metadata.h: metadata object classes - * \ingroup flacpp_metadata - * - * This module contains classes representing FLAC metadata - * blocks in memory. - * - * The behavior closely mimics the C layer interface; be - * sure to read the detailed description of the - * \link flac_metadata_object C metadata object module \endlink. - * - * Any time a metadata object is constructed or assigned, you - * should check is_valid() to make sure the underlying - * ::FLAC__StreamMetadata object was able to be created. - * - * \warning - * When the get_*() methods of any metadata object method - * return you a const pointer, DO NOT disobey and write into it. - * Always use the set_*() methods. - * - * \{ - */ - - /** Base class for all metadata block types. - * See the \link flacpp_metadata_object overview \endlink for more. - */ - class FLACPP_API Prototype { - protected: - //@{ - /** Constructs a copy of the given object. This form - * always performs a deep copy. - */ - Prototype(const Prototype &); - Prototype(const ::FLAC__StreamMetadata &); - Prototype(const ::FLAC__StreamMetadata *); - //@} - - /** Constructs an object with copy control. When \a copy - * is \c true, behaves identically to - * FLAC::Metadata::Prototype::Prototype(const ::FLAC__StreamMetadata *object). - * When \a copy is \c false, the instance takes ownership of - * the pointer and the ::FLAC__StreamMetadata object will - * be freed by the destructor. - * - * \assert - * \code object != NULL \endcode - */ - Prototype(::FLAC__StreamMetadata *object, bool copy); - - //@{ - /** Assign from another object. Always performs a deep copy. */ - Prototype &operator=(const Prototype &); - Prototype &operator=(const ::FLAC__StreamMetadata &); - Prototype &operator=(const ::FLAC__StreamMetadata *); - //@} - - /** Assigns an object with copy control. See - * Prototype(::FLAC__StreamMetadata *object, bool copy). - */ - Prototype &assign_object(::FLAC__StreamMetadata *object, bool copy); - - /** Deletes the underlying ::FLAC__StreamMetadata object. - */ - virtual void clear(); - - ::FLAC__StreamMetadata *object_; - public: - /** Deletes the underlying ::FLAC__StreamMetadata object. - */ - virtual ~Prototype(); - - //@{ - /** Check for equality, performing a deep compare by following pointers. - */ - inline bool operator==(const Prototype &) const; - inline bool operator==(const ::FLAC__StreamMetadata &) const; - inline bool operator==(const ::FLAC__StreamMetadata *) const; - //@} - - //@{ - /** Check for inequality, performing a deep compare by following pointers. */ - inline bool operator!=(const Prototype &) const; - inline bool operator!=(const ::FLAC__StreamMetadata &) const; - inline bool operator!=(const ::FLAC__StreamMetadata *) const; - //@} - - friend class SimpleIterator; - friend class Iterator; - - /** Returns \c true if the object was correctly constructed - * (i.e. the underlying ::FLAC__StreamMetadata object was - * properly allocated), else \c false. - */ - inline bool is_valid() const; - - /** Returns \c true if this block is the last block in a - * stream, else \c false. - * - * \assert - * \code is_valid() \endcode - */ - bool get_is_last() const; - - /** Returns the type of the block. - * - * \assert - * \code is_valid() \endcode - */ - ::FLAC__MetadataType get_type() const; - - /** Returns the stream length of the metadata block. - * - * \note - * The length does not include the metadata block header, - * per spec. - * - * \assert - * \code is_valid() \endcode - */ - uint32_t get_length() const; - - /** Sets the "is_last" flag for the block. When using the iterators - * it is not necessary to set this flag; they will do it for you. - * - * \assert - * \code is_valid() \endcode - */ - void set_is_last(bool); - - /** Returns a pointer to the underlying ::FLAC__StreamMetadata - * object. This can be useful for plugging any holes between - * the C++ and C interfaces. - * - * \assert - * \code is_valid() \endcode - */ - inline operator const ::FLAC__StreamMetadata *() const; - private: - /** Private and undefined so you can't use it. */ - Prototype(); - - // These are used only by Iterator - bool is_reference_; - inline void set_reference(bool x) { is_reference_ = x; } - }; - - // local utility routines - - namespace local { - - /** Construct a new object of the type provided in object->type and return it. */ - Prototype *construct_block(::FLAC__StreamMetadata *object); - - } - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - - inline bool Prototype::operator==(const Prototype &object) const - { return (bool)::FLAC__metadata_object_is_equal(object_, object.object_); } - - inline bool Prototype::operator==(const ::FLAC__StreamMetadata &object) const - { return (bool)::FLAC__metadata_object_is_equal(object_, &object); } - - inline bool Prototype::operator==(const ::FLAC__StreamMetadata *object) const - { return (bool)::FLAC__metadata_object_is_equal(object_, object); } - -#ifdef _MSC_VER -#pragma warning ( default : 4800 ) -#endif - - inline bool Prototype::operator!=(const Prototype &object) const - { return !operator==(object); } - - inline bool Prototype::operator!=(const ::FLAC__StreamMetadata &object) const - { return !operator==(object); } - - inline bool Prototype::operator!=(const ::FLAC__StreamMetadata *object) const - { return !operator==(object); } - - inline bool Prototype::is_valid() const - { return 0 != object_; } - - inline Prototype::operator const ::FLAC__StreamMetadata *() const - { return object_; } - - /** Create a deep copy of an object and return it. */ - FLACPP_API Prototype *clone(const Prototype *); - - - /** STREAMINFO metadata block. - * See the \link flacpp_metadata_object overview \endlink for more, - * and the format specification. - */ - class FLACPP_API StreamInfo : public Prototype { - public: - StreamInfo(); - - //@{ - /** Constructs a copy of the given object. This form - * always performs a deep copy. - */ - inline StreamInfo(const StreamInfo &object): Prototype(object) { } - inline StreamInfo(const ::FLAC__StreamMetadata &object): Prototype(object) { } - inline StreamInfo(const ::FLAC__StreamMetadata *object): Prototype(object) { } - //@} - - /** Constructs an object with copy control. See - * Prototype(::FLAC__StreamMetadata *object, bool copy). - */ - inline StreamInfo(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } - - ~StreamInfo(); - - //@{ - /** Assign from another object. Always performs a deep copy. */ - inline StreamInfo &operator=(const StreamInfo &object) { Prototype::operator=(object); return *this; } - inline StreamInfo &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; } - inline StreamInfo &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; } - //@} - - /** Assigns an object with copy control. See - * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy). - */ - inline StreamInfo &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; } - - //@{ - /** Check for equality, performing a deep compare by following pointers. */ - inline bool operator==(const StreamInfo &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } - //@} - - //@{ - /** Check for inequality, performing a deep compare by following pointers. */ - inline bool operator!=(const StreamInfo &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } - //@} - - //@{ - /** See format specification. */ - uint32_t get_min_blocksize() const; - uint32_t get_max_blocksize() const; - uint32_t get_min_framesize() const; - uint32_t get_max_framesize() const; - uint32_t get_sample_rate() const; - uint32_t get_channels() const; - uint32_t get_bits_per_sample() const; - FLAC__uint64 get_total_samples() const; - const FLAC__byte *get_md5sum() const; - - void set_min_blocksize(uint32_t value); - void set_max_blocksize(uint32_t value); - void set_min_framesize(uint32_t value); - void set_max_framesize(uint32_t value); - void set_sample_rate(uint32_t value); - void set_channels(uint32_t value); - void set_bits_per_sample(uint32_t value); - void set_total_samples(FLAC__uint64 value); - void set_md5sum(const FLAC__byte value[16]); - //@} - }; - - /** PADDING metadata block. - * See the \link flacpp_metadata_object overview \endlink for more, - * and the format specification. - */ - class FLACPP_API Padding : public Prototype { - public: - Padding(); - - //@{ - /** Constructs a copy of the given object. This form - * always performs a deep copy. - */ - inline Padding(const Padding &object): Prototype(object) { } - inline Padding(const ::FLAC__StreamMetadata &object): Prototype(object) { } - inline Padding(const ::FLAC__StreamMetadata *object): Prototype(object) { } - //@} - - /** Constructs an object with copy control. See - * Prototype(::FLAC__StreamMetadata *object, bool copy). - */ - inline Padding(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } - - /** Constructs an object with the given length. - */ - Padding(uint32_t length); - - ~Padding(); - - //@{ - /** Assign from another object. Always performs a deep copy. */ - inline Padding &operator=(const Padding &object) { Prototype::operator=(object); return *this; } - inline Padding &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; } - inline Padding &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; } - //@} - - /** Assigns an object with copy control. See - * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy). - */ - inline Padding &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; } - - //@{ - /** Check for equality, performing a deep compare by following pointers. */ - inline bool operator==(const Padding &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } - //@} - - //@{ - /** Check for inequality, performing a deep compare by following pointers. */ - inline bool operator!=(const Padding &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } - //@} - - /** Sets the length in bytes of the padding block. - */ - void set_length(uint32_t length); - }; - - /** APPLICATION metadata block. - * See the \link flacpp_metadata_object overview \endlink for more, - * and the format specification. - */ - class FLACPP_API Application : public Prototype { - public: - Application(); - // - //@{ - /** Constructs a copy of the given object. This form - * always performs a deep copy. - */ - inline Application(const Application &object): Prototype(object) { } - inline Application(const ::FLAC__StreamMetadata &object): Prototype(object) { } - inline Application(const ::FLAC__StreamMetadata *object): Prototype(object) { } - //@} - - /** Constructs an object with copy control. See - * Prototype(::FLAC__StreamMetadata *object, bool copy). - */ - inline Application(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } - - ~Application(); - - //@{ - /** Assign from another object. Always performs a deep copy. */ - inline Application &operator=(const Application &object) { Prototype::operator=(object); return *this; } - inline Application &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; } - inline Application &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; } - //@} - - /** Assigns an object with copy control. See - * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy). - */ - inline Application &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; } - - //@{ - /** Check for equality, performing a deep compare by following pointers. */ - inline bool operator==(const Application &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } - //@} - - //@{ - /** Check for inequality, performing a deep compare by following pointers. */ - inline bool operator!=(const Application &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } - //@} - - const FLAC__byte *get_id() const; - const FLAC__byte *get_data() const; - - void set_id(const FLAC__byte value[4]); - //! This form always copies \a data - bool set_data(const FLAC__byte *data, uint32_t length); - bool set_data(FLAC__byte *data, uint32_t length, bool copy); - }; - - /** SEEKTABLE metadata block. - * See the \link flacpp_metadata_object overview \endlink for more, - * and the format specification. - */ - class FLACPP_API SeekTable : public Prototype { - public: - SeekTable(); - - //@{ - /** Constructs a copy of the given object. This form - * always performs a deep copy. - */ - inline SeekTable(const SeekTable &object): Prototype(object) { } - inline SeekTable(const ::FLAC__StreamMetadata &object): Prototype(object) { } - inline SeekTable(const ::FLAC__StreamMetadata *object): Prototype(object) { } - //@} - - /** Constructs an object with copy control. See - * Prototype(::FLAC__StreamMetadata *object, bool copy). - */ - inline SeekTable(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } - - ~SeekTable(); - - //@{ - /** Assign from another object. Always performs a deep copy. */ - inline SeekTable &operator=(const SeekTable &object) { Prototype::operator=(object); return *this; } - inline SeekTable &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; } - inline SeekTable &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; } - //@} - - /** Assigns an object with copy control. See - * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy). - */ - inline SeekTable &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; } - - //@{ - /** Check for equality, performing a deep compare by following pointers. */ - inline bool operator==(const SeekTable &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } - //@} - - //@{ - /** Check for inequality, performing a deep compare by following pointers. */ - inline bool operator!=(const SeekTable &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } - //@} - - uint32_t get_num_points() const; - ::FLAC__StreamMetadata_SeekPoint get_point(uint32_t index) const; - - //! See FLAC__metadata_object_seektable_resize_points() - bool resize_points(uint32_t new_num_points); - - //! See FLAC__metadata_object_seektable_set_point() - void set_point(uint32_t index, const ::FLAC__StreamMetadata_SeekPoint &point); - - //! See FLAC__metadata_object_seektable_insert_point() - bool insert_point(uint32_t index, const ::FLAC__StreamMetadata_SeekPoint &point); - - //! See FLAC__metadata_object_seektable_delete_point() - bool delete_point(uint32_t index); - - //! See FLAC__metadata_object_seektable_is_legal() - bool is_legal() const; - - //! See FLAC__metadata_object_seektable_template_append_placeholders() - bool template_append_placeholders(uint32_t num); - - //! See FLAC__metadata_object_seektable_template_append_point() - bool template_append_point(FLAC__uint64 sample_number); - - //! See FLAC__metadata_object_seektable_template_append_points() - bool template_append_points(FLAC__uint64 sample_numbers[], uint32_t num); - - //! See FLAC__metadata_object_seektable_template_append_spaced_points() - bool template_append_spaced_points(uint32_t num, FLAC__uint64 total_samples); - - //! See FLAC__metadata_object_seektable_template_append_spaced_points_by_samples() - bool template_append_spaced_points_by_samples(uint32_t samples, FLAC__uint64 total_samples); - - //! See FLAC__metadata_object_seektable_template_sort() - bool template_sort(bool compact); - }; - - /** VORBIS_COMMENT metadata block. - * See the \link flacpp_metadata_object overview \endlink for more, - * and the format specification. - */ - class FLACPP_API VorbisComment : public Prototype { - public: - /** Convenience class for encapsulating Vorbis comment - * entries. An entry is a vendor string or a comment - * field. In the case of a vendor string, the field - * name is undefined; only the field value is relevant. - * - * A \a field as used in the methods refers to an - * entire 'NAME=VALUE' string; for convenience the - * string is NUL-terminated. A length field is - * required in the unlikely event that the value - * contains contain embedded NULs. - * - * A \a field_name is what is on the left side of the - * first '=' in the \a field. By definition it is ASCII - * and so is NUL-terminated and does not require a - * length to describe it. \a field_name is undefined - * for a vendor string entry. - * - * A \a field_value is what is on the right side of the - * first '=' in the \a field. By definition, this may - * contain embedded NULs and so a \a field_value_length - * is required to describe it. However in practice, - * embedded NULs are not known to be used, so it is - * generally safe to treat field values as NUL- - * terminated UTF-8 strings. - * - * Always check is_valid() after the constructor or operator= - * to make sure memory was properly allocated and that the - * Entry conforms to the Vorbis comment specification. - */ - class FLACPP_API Entry { - public: - Entry(); - - Entry(const char *field, uint32_t field_length); - Entry(const char *field); // assumes \a field is NUL-terminated - - Entry(const char *field_name, const char *field_value, uint32_t field_value_length); - Entry(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated - - Entry(const Entry &entry); - - Entry &operator=(const Entry &entry); - - virtual ~Entry(); - - virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed. - - uint32_t get_field_length() const; - uint32_t get_field_name_length() const; - uint32_t get_field_value_length() const; - - ::FLAC__StreamMetadata_VorbisComment_Entry get_entry() const; - const char *get_field() const; - const char *get_field_name() const; - const char *get_field_value() const; - - bool set_field(const char *field, uint32_t field_length); - bool set_field(const char *field); // assumes \a field is NUL-terminated - bool set_field_name(const char *field_name); - bool set_field_value(const char *field_value, uint32_t field_value_length); - bool set_field_value(const char *field_value); // assumes \a field_value is NUL-terminated - protected: - bool is_valid_; - ::FLAC__StreamMetadata_VorbisComment_Entry entry_; - char *field_name_; - uint32_t field_name_length_; - char *field_value_; - uint32_t field_value_length_; - private: - void zero(); - void clear(); - void clear_entry(); - void clear_field_name(); - void clear_field_value(); - void construct(const char *field, uint32_t field_length); - void construct(const char *field); // assumes \a field is NUL-terminated - void construct(const char *field_name, const char *field_value, uint32_t field_value_length); - void construct(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated - void compose_field(); - void parse_field(); - }; - - VorbisComment(); - - //@{ - /** Constructs a copy of the given object. This form - * always performs a deep copy. - */ - inline VorbisComment(const VorbisComment &object): Prototype(object) { } - inline VorbisComment(const ::FLAC__StreamMetadata &object): Prototype(object) { } - inline VorbisComment(const ::FLAC__StreamMetadata *object): Prototype(object) { } - //@} - - /** Constructs an object with copy control. See - * Prototype(::FLAC__StreamMetadata *object, bool copy). - */ - inline VorbisComment(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } - - ~VorbisComment(); - - //@{ - /** Assign from another object. Always performs a deep copy. */ - inline VorbisComment &operator=(const VorbisComment &object) { Prototype::operator=(object); return *this; } - inline VorbisComment &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; } - inline VorbisComment &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; } - //@} - - /** Assigns an object with copy control. See - * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy). - */ - inline VorbisComment &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; } - - //@{ - /** Check for equality, performing a deep compare by following pointers. */ - inline bool operator==(const VorbisComment &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } - //@} - - //@{ - /** Check for inequality, performing a deep compare by following pointers. */ - inline bool operator!=(const VorbisComment &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } - //@} - - uint32_t get_num_comments() const; - const FLAC__byte *get_vendor_string() const; // NUL-terminated UTF-8 string - Entry get_comment(uint32_t index) const; - - //! See FLAC__metadata_object_vorbiscomment_set_vendor_string() - bool set_vendor_string(const FLAC__byte *string); // NUL-terminated UTF-8 string - - //! See FLAC__metadata_object_vorbiscomment_resize_comments() - bool resize_comments(uint32_t new_num_comments); - - //! See FLAC__metadata_object_vorbiscomment_set_comment() - bool set_comment(uint32_t index, const Entry &entry); - - //! See FLAC__metadata_object_vorbiscomment_insert_comment() - bool insert_comment(uint32_t index, const Entry &entry); - - //! See FLAC__metadata_object_vorbiscomment_append_comment() - bool append_comment(const Entry &entry); - - //! See FLAC__metadata_object_vorbiscomment_replace_comment() - bool replace_comment(const Entry &entry, bool all); - - //! See FLAC__metadata_object_vorbiscomment_delete_comment() - bool delete_comment(uint32_t index); - - //! See FLAC__metadata_object_vorbiscomment_find_entry_from() - int find_entry_from(uint32_t offset, const char *field_name); - - //! See FLAC__metadata_object_vorbiscomment_remove_entry_matching() - int remove_entry_matching(const char *field_name); - - //! See FLAC__metadata_object_vorbiscomment_remove_entries_matching() - int remove_entries_matching(const char *field_name); - }; - - /** CUESHEET metadata block. - * See the \link flacpp_metadata_object overview \endlink for more, - * and the format specification. - */ - class FLACPP_API CueSheet : public Prototype { - public: - /** Convenience class for encapsulating a cue sheet - * track. - * - * Always check is_valid() after the constructor or operator= - * to make sure memory was properly allocated. - */ - class FLACPP_API Track { - protected: - ::FLAC__StreamMetadata_CueSheet_Track *object_; - public: - Track(); - Track(const ::FLAC__StreamMetadata_CueSheet_Track *track); - Track(const Track &track); - Track &operator=(const Track &track); - - virtual ~Track(); - - virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed. - - - inline FLAC__uint64 get_offset() const { return object_->offset; } - inline FLAC__byte get_number() const { return object_->number; } - inline const char *get_isrc() const { return object_->isrc; } - inline uint32_t get_type() const { return object_->type; } - inline bool get_pre_emphasis() const { return object_->pre_emphasis; } - - inline FLAC__byte get_num_indices() const { return object_->num_indices; } - ::FLAC__StreamMetadata_CueSheet_Index get_index(uint32_t i) const; - - inline const ::FLAC__StreamMetadata_CueSheet_Track *get_track() const { return object_; } - - inline void set_offset(FLAC__uint64 value) { object_->offset = value; } - inline void set_number(FLAC__byte value) { object_->number = value; } - void set_isrc(const char value[12]); - void set_type(uint32_t value); - inline void set_pre_emphasis(bool value) { object_->pre_emphasis = value? 1 : 0; } - - void set_index(uint32_t i, const ::FLAC__StreamMetadata_CueSheet_Index &index); - //@@@ It's awkward but to insert/delete index points - //@@@ you must use the routines in the CueSheet class. - }; - - CueSheet(); - - //@{ - /** Constructs a copy of the given object. This form - * always performs a deep copy. - */ - inline CueSheet(const CueSheet &object): Prototype(object) { } - inline CueSheet(const ::FLAC__StreamMetadata &object): Prototype(object) { } - inline CueSheet(const ::FLAC__StreamMetadata *object): Prototype(object) { } - //@} - - /** Constructs an object with copy control. See - * Prototype(::FLAC__StreamMetadata *object, bool copy). - */ - inline CueSheet(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } - - ~CueSheet(); - - //@{ - /** Assign from another object. Always performs a deep copy. */ - inline CueSheet &operator=(const CueSheet &object) { Prototype::operator=(object); return *this; } - inline CueSheet &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; } - inline CueSheet &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; } - //@} - - /** Assigns an object with copy control. See - * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy). - */ - inline CueSheet &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; } - - //@{ - /** Check for equality, performing a deep compare by following pointers. */ - inline bool operator==(const CueSheet &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } - //@} - - //@{ - /** Check for inequality, performing a deep compare by following pointers. */ - inline bool operator!=(const CueSheet &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } - //@} - - const char *get_media_catalog_number() const; - FLAC__uint64 get_lead_in() const; - bool get_is_cd() const; - - uint32_t get_num_tracks() const; - Track get_track(uint32_t i) const; - - void set_media_catalog_number(const char value[128]); - void set_lead_in(FLAC__uint64 value); - void set_is_cd(bool value); - - void set_index(uint32_t track_num, uint32_t index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index); - - //! See FLAC__metadata_object_cuesheet_track_resize_indices() - bool resize_indices(uint32_t track_num, uint32_t new_num_indices); - - //! See FLAC__metadata_object_cuesheet_track_insert_index() - bool insert_index(uint32_t track_num, uint32_t index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index); - - //! See FLAC__metadata_object_cuesheet_track_insert_blank_index() - bool insert_blank_index(uint32_t track_num, uint32_t index_num); - - //! See FLAC__metadata_object_cuesheet_track_delete_index() - bool delete_index(uint32_t track_num, uint32_t index_num); - - //! See FLAC__metadata_object_cuesheet_resize_tracks() - bool resize_tracks(uint32_t new_num_tracks); - - //! See FLAC__metadata_object_cuesheet_set_track() - bool set_track(uint32_t i, const Track &track); - - //! See FLAC__metadata_object_cuesheet_insert_track() - bool insert_track(uint32_t i, const Track &track); - - //! See FLAC__metadata_object_cuesheet_insert_blank_track() - bool insert_blank_track(uint32_t i); - - //! See FLAC__metadata_object_cuesheet_delete_track() - bool delete_track(uint32_t i); - - //! See FLAC__metadata_object_cuesheet_is_legal() - bool is_legal(bool check_cd_da_subset = false, const char **violation = 0) const; - - //! See FLAC__metadata_object_cuesheet_calculate_cddb_id() - FLAC__uint32 calculate_cddb_id() const; - }; - - /** PICTURE metadata block. - * See the \link flacpp_metadata_object overview \endlink for more, - * and the format specification. - */ - class FLACPP_API Picture : public Prototype { - public: - Picture(); - - //@{ - /** Constructs a copy of the given object. This form - * always performs a deep copy. - */ - inline Picture(const Picture &object): Prototype(object) { } - inline Picture(const ::FLAC__StreamMetadata &object): Prototype(object) { } - inline Picture(const ::FLAC__StreamMetadata *object): Prototype(object) { } - //@} - - /** Constructs an object with copy control. See - * Prototype(::FLAC__StreamMetadata *object, bool copy). - */ - inline Picture(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } - - ~Picture(); - - //@{ - /** Assign from another object. Always performs a deep copy. */ - inline Picture &operator=(const Picture &object) { Prototype::operator=(object); return *this; } - inline Picture &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; } - inline Picture &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; } - //@} - - /** Assigns an object with copy control. See - * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy). - */ - inline Picture &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; } - - //@{ - /** Check for equality, performing a deep compare by following pointers. */ - inline bool operator==(const Picture &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } - //@} - - //@{ - /** Check for inequality, performing a deep compare by following pointers. */ - inline bool operator!=(const Picture &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } - //@} - - ::FLAC__StreamMetadata_Picture_Type get_type() const; - const char *get_mime_type() const; // NUL-terminated printable ASCII string - const FLAC__byte *get_description() const; // NUL-terminated UTF-8 string - FLAC__uint32 get_width() const; - FLAC__uint32 get_height() const; - FLAC__uint32 get_depth() const; - FLAC__uint32 get_colors() const; ///< a return value of \c 0 means true-color, i.e. 2^depth colors - FLAC__uint32 get_data_length() const; - const FLAC__byte *get_data() const; - - void set_type(::FLAC__StreamMetadata_Picture_Type type); - - //! See FLAC__metadata_object_picture_set_mime_type() - bool set_mime_type(const char *string); // NUL-terminated printable ASCII string - - //! See FLAC__metadata_object_picture_set_description() - bool set_description(const FLAC__byte *string); // NUL-terminated UTF-8 string - - void set_width(FLAC__uint32 value) const; - void set_height(FLAC__uint32 value) const; - void set_depth(FLAC__uint32 value) const; - void set_colors(FLAC__uint32 value) const; ///< a value of \c 0 means true-color, i.e. 2^depth colors - - //! See FLAC__metadata_object_picture_set_data() - bool set_data(const FLAC__byte *data, FLAC__uint32 data_length); - - //! See FLAC__metadata_object_picture_is_legal() - bool is_legal(const char **violation); - }; - - /** Opaque metadata block for storing unknown types. - * This should not be used unless you know what you are doing; - * it is currently used only internally to support forward - * compatibility of metadata blocks. - * See the \link flacpp_metadata_object overview \endlink for more, - */ - class FLACPP_API Unknown : public Prototype { - public: - Unknown(); - // - //@{ - /** Constructs a copy of the given object. This form - * always performs a deep copy. - */ - inline Unknown(const Unknown &object): Prototype(object) { } - inline Unknown(const ::FLAC__StreamMetadata &object): Prototype(object) { } - inline Unknown(const ::FLAC__StreamMetadata *object): Prototype(object) { } - //@} - - /** Constructs an object with copy control. See - * Prototype(::FLAC__StreamMetadata *object, bool copy). - */ - inline Unknown(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } - - ~Unknown(); - - //@{ - /** Assign from another object. Always performs a deep copy. */ - inline Unknown &operator=(const Unknown &object) { Prototype::operator=(object); return *this; } - inline Unknown &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; } - inline Unknown &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; } - //@} - - /** Assigns an object with copy control. See - * Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy). - */ - inline Unknown &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; } - - //@{ - /** Check for equality, performing a deep compare by following pointers. */ - inline bool operator==(const Unknown &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } - inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } - //@} - - //@{ - /** Check for inequality, performing a deep compare by following pointers. */ - inline bool operator!=(const Unknown &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } - inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } - //@} - - const FLAC__byte *get_data() const; - - //! This form always copies \a data - bool set_data(const FLAC__byte *data, uint32_t length); - bool set_data(FLAC__byte *data, uint32_t length, bool copy); - }; - - /* \} */ - - - /** \defgroup flacpp_metadata_level0 FLAC++/metadata.h: metadata level 0 interface - * \ingroup flacpp_metadata - * - * \brief - * Level 0 metadata iterators. - * - * See the \link flac_metadata_level0 C layer equivalent \endlink - * for more. - * - * \{ - */ - - FLACPP_API bool get_streaminfo(const char *filename, StreamInfo &streaminfo); ///< See FLAC__metadata_get_streaminfo(). - - FLACPP_API bool get_tags(const char *filename, VorbisComment *&tags); ///< See FLAC__metadata_get_tags(). - FLACPP_API bool get_tags(const char *filename, VorbisComment &tags); ///< See FLAC__metadata_get_tags(). - - FLACPP_API bool get_cuesheet(const char *filename, CueSheet *&cuesheet); ///< See FLAC__metadata_get_cuesheet(). - FLACPP_API bool get_cuesheet(const char *filename, CueSheet &cuesheet); ///< See FLAC__metadata_get_cuesheet(). - - FLACPP_API bool get_picture(const char *filename, Picture *&picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors); ///< See FLAC__metadata_get_picture(). - FLACPP_API bool get_picture(const char *filename, Picture &picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors); ///< See FLAC__metadata_get_picture(). - - /* \} */ - - - /** \defgroup flacpp_metadata_level1 FLAC++/metadata.h: metadata level 1 interface - * \ingroup flacpp_metadata - * - * \brief - * Level 1 metadata iterator. - * - * The flow through the iterator in the C++ layer is similar - * to the C layer: - * - Create a SimpleIterator instance - * - Check SimpleIterator::is_valid() - * - Call SimpleIterator::init() and check the return - * - Traverse and/or edit. Edits are written to file - * immediately. - * - Destroy the SimpleIterator instance - * - * The ownership of pointers in the C++ layer follows that in - * the C layer, i.e. - * - The objects returned by get_block() are yours to - * modify, but changes are not reflected in the FLAC file - * until you call set_block(). The objects are also - * yours to delete; they are not automatically deleted - * when passed to set_block() or insert_block_after(). - * - * See the \link flac_metadata_level1 C layer equivalent \endlink - * for more. - * - * \{ - */ - - /** This class is a wrapper around the FLAC__metadata_simple_iterator - * structures and methods; see the - * \link flacpp_metadata_level1 usage guide \endlink and - * ::FLAC__Metadata_SimpleIterator. - */ - class FLACPP_API SimpleIterator { - public: - /** This class is a wrapper around FLAC__Metadata_SimpleIteratorStatus. - */ - class FLACPP_API Status { - public: - inline Status(::FLAC__Metadata_SimpleIteratorStatus status): status_(status) { } - inline operator ::FLAC__Metadata_SimpleIteratorStatus() const { return status_; } - inline const char *as_cstring() const { return ::FLAC__Metadata_SimpleIteratorStatusString[status_]; } - protected: - ::FLAC__Metadata_SimpleIteratorStatus status_; - }; - - SimpleIterator(); - virtual ~SimpleIterator(); - - bool is_valid() const; ///< Returns \c true iff object was properly constructed. - - bool init(const char *filename, bool read_only, bool preserve_file_stats); ///< See FLAC__metadata_simple_iterator_init(). - - Status status(); ///< See FLAC__metadata_simple_iterator_status(). - bool is_writable() const; ///< See FLAC__metadata_simple_iterator_is_writable(). - - bool next(); ///< See FLAC__metadata_simple_iterator_next(). - bool prev(); ///< See FLAC__metadata_simple_iterator_prev(). - bool is_last() const; ///< See FLAC__metadata_simple_iterator_is_last(). - - off_t get_block_offset() const; ///< See FLAC__metadata_simple_iterator_get_block_offset(). - ::FLAC__MetadataType get_block_type() const; ///< See FLAC__metadata_simple_iterator_get_block_type(). - uint32_t get_block_length() const; ///< See FLAC__metadata_simple_iterator_get_block_length(). - bool get_application_id(FLAC__byte *id); ///< See FLAC__metadata_simple_iterator_get_application_id(). - Prototype *get_block(); ///< See FLAC__metadata_simple_iterator_get_block(). - bool set_block(Prototype *block, bool use_padding = true); ///< See FLAC__metadata_simple_iterator_set_block(). - bool insert_block_after(Prototype *block, bool use_padding = true); ///< See FLAC__metadata_simple_iterator_insert_block_after(). - bool delete_block(bool use_padding = true); ///< See FLAC__metadata_simple_iterator_delete_block(). - - protected: - ::FLAC__Metadata_SimpleIterator *iterator_; - void clear(); - - private: // Do not use. - SimpleIterator(const SimpleIterator&); - SimpleIterator&operator=(const SimpleIterator&); - }; - - /* \} */ - - - /** \defgroup flacpp_metadata_level2 FLAC++/metadata.h: metadata level 2 interface - * \ingroup flacpp_metadata - * - * \brief - * Level 2 metadata iterator. - * - * The flow through the iterator in the C++ layer is similar - * to the C layer: - * - Create a Chain instance - * - Check Chain::is_valid() - * - Call Chain::read() and check the return - * - Traverse and/or edit with an Iterator or with - * Chain::merge_padding() or Chain::sort_padding() - * - Write changes back to FLAC file with Chain::write() - * - Destroy the Chain instance - * - * The ownership of pointers in the C++ layer is slightly - * different than in the C layer, i.e. - * - The objects returned by Iterator::get_block() are NOT - * owned by the iterator and should be deleted by the - * caller when finished, BUT, when you modify the block, - * it will directly edit what's in the chain and you do - * not need to call Iterator::set_block(). However the - * changes will not be reflected in the FLAC file until - * the chain is written with Chain::write(). - * - When you pass an object to Iterator::set_block(), - * Iterator::insert_block_before(), or - * Iterator::insert_block_after(), the iterator takes - * ownership of the block and it will be deleted by the - * chain. - * - * See the \link flac_metadata_level2 C layer equivalent \endlink - * for more. - * - * \{ - */ - - /** This class is a wrapper around the FLAC__metadata_chain - * structures and methods; see the - * \link flacpp_metadata_level2 usage guide \endlink and - * ::FLAC__Metadata_Chain. - */ - class FLACPP_API Chain { - public: - /** This class is a wrapper around FLAC__Metadata_ChainStatus. - */ - class FLACPP_API Status { - public: - inline Status(::FLAC__Metadata_ChainStatus status): status_(status) { } - inline operator ::FLAC__Metadata_ChainStatus() const { return status_; } - inline const char *as_cstring() const { return ::FLAC__Metadata_ChainStatusString[status_]; } - protected: - ::FLAC__Metadata_ChainStatus status_; - }; - - Chain(); - virtual ~Chain(); - - friend class Iterator; - - bool is_valid() const; ///< Returns \c true iff object was properly constructed. - - Status status(); ///< See FLAC__metadata_chain_status(). - - bool read(const char *filename, bool is_ogg = false); ///< See FLAC__metadata_chain_read(), FLAC__metadata_chain_read_ogg(). - bool read(FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, bool is_ogg = false); ///< See FLAC__metadata_chain_read_with_callbacks(), FLAC__metadata_chain_read_ogg_with_callbacks(). - - bool check_if_tempfile_needed(bool use_padding); ///< See FLAC__metadata_chain_check_if_tempfile_needed(). - - bool write(bool use_padding = true, bool preserve_file_stats = false); ///< See FLAC__metadata_chain_write(). - bool write(bool use_padding, ::FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks); ///< See FLAC__metadata_chain_write_with_callbacks(). - bool write(bool use_padding, ::FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks, ::FLAC__IOHandle temp_handle, ::FLAC__IOCallbacks temp_callbacks); ///< See FLAC__metadata_chain_write_with_callbacks_and_tempfile(). - - void merge_padding(); ///< See FLAC__metadata_chain_merge_padding(). - void sort_padding(); ///< See FLAC__metadata_chain_sort_padding(). - - protected: - ::FLAC__Metadata_Chain *chain_; - virtual void clear(); - - private: // Do not use. - Chain(const Chain&); - Chain&operator=(const Chain&); - }; - - /** This class is a wrapper around the FLAC__metadata_iterator - * structures and methods; see the - * \link flacpp_metadata_level2 usage guide \endlink and - * ::FLAC__Metadata_Iterator. - */ - class FLACPP_API Iterator { - public: - Iterator(); - virtual ~Iterator(); - - bool is_valid() const; ///< Returns \c true iff object was properly constructed. - - - void init(Chain &chain); ///< See FLAC__metadata_iterator_init(). - - bool next(); ///< See FLAC__metadata_iterator_next(). - bool prev(); ///< See FLAC__metadata_iterator_prev(). - - ::FLAC__MetadataType get_block_type() const; ///< See FLAC__metadata_iterator_get_block_type(). - Prototype *get_block(); ///< See FLAC__metadata_iterator_get_block(). - bool set_block(Prototype *block); ///< See FLAC__metadata_iterator_set_block(). - bool delete_block(bool replace_with_padding); ///< See FLAC__metadata_iterator_delete_block(). - bool insert_block_before(Prototype *block); ///< See FLAC__metadata_iterator_insert_block_before(). - bool insert_block_after(Prototype *block); ///< See FLAC__metadata_iterator_insert_block_after(). - - protected: - ::FLAC__Metadata_Iterator *iterator_; - virtual void clear(); - - private: // Do not use. - Iterator(const Iterator&); - Iterator&operator=(const Iterator&); - }; - - /* \} */ - - } -} - -#endif diff --git a/flac/include/FLAC/Makefile.am b/flac/include/FLAC/Makefile.am deleted file mode 100644 index 80ded61..0000000 --- a/flac/include/FLAC/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -# libFLAC - Free Lossless Audio Codec library -# Copyright (C) 2000-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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 Xiph.org Foundation 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 FOUNDATION 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. - -flaccincludedir = $(includedir)/FLAC - -flaccinclude_HEADERS = \ - all.h \ - assert.h \ - callback.h \ - export.h \ - format.h \ - metadata.h \ - ordinals.h \ - stream_decoder.h \ - stream_encoder.h diff --git a/flac/include/FLAC/all.h b/flac/include/FLAC/all.h deleted file mode 100644 index 277dcbc..0000000 --- a/flac/include/FLAC/all.h +++ /dev/null @@ -1,450 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__ALL_H -#define FLAC__ALL_H - -#include "export.h" - -#include "assert.h" -#include "callback.h" -#include "format.h" -#include "metadata.h" -#include "ordinals.h" -#include "stream_decoder.h" -#include "stream_encoder.h" - -/** \mainpage - * - * \section intro Introduction - * - * This is the documentation for the FLAC C and C++ APIs. It is - * highly interconnected; this introduction should give you a top - * level idea of the structure and how to find the information you - * need. As a prerequisite you should have at least a basic - * knowledge of the FLAC format, documented - * here. - * - * \section c_api FLAC C API - * - * The FLAC C API is the interface to libFLAC, a set of structures - * describing the components of FLAC streams, and functions for - * encoding and decoding streams, as well as manipulating FLAC - * metadata in files. The public include files will be installed - * in your include area (for example /usr/include/FLAC/...). - * - * By writing a little code and linking against libFLAC, it is - * relatively easy to add FLAC support to another program. The - * library is licensed under Xiph's BSD license. - * Complete source code of libFLAC as well as the command-line - * encoder and plugins is available and is a useful source of - * examples. - * - * Aside from encoders and decoders, libFLAC provides a powerful - * metadata interface for manipulating metadata in FLAC files. It - * allows the user to add, delete, and modify FLAC metadata blocks - * and it can automatically take advantage of PADDING blocks to avoid - * rewriting the entire FLAC file when changing the size of the - * metadata. - * - * libFLAC usually only requires the standard C library and C math - * library. In particular, threading is not used so there is no - * dependency on a thread library. However, libFLAC does not use - * global variables and should be thread-safe. - * - * libFLAC also supports encoding to and decoding from Ogg FLAC. - * However the metadata editing interfaces currently have limited - * read-only support for Ogg FLAC files. - * - * \section cpp_api FLAC C++ API - * - * The FLAC C++ API is a set of classes that encapsulate the - * structures and functions in libFLAC. They provide slightly more - * functionality with respect to metadata but are otherwise - * equivalent. For the most part, they share the same usage as - * their counterparts in libFLAC, and the FLAC C API documentation - * can be used as a supplement. The public include files - * for the C++ API will be installed in your include area (for - * example /usr/include/FLAC++/...). - * - * libFLAC++ is also licensed under - * Xiph's BSD license. - * - * \section getting_started Getting Started - * - * A good starting point for learning the API is to browse through - * the modules. Modules are logical - * groupings of related functions or classes, which correspond roughly - * to header files or sections of header files. Each module includes a - * detailed description of the general usage of its functions or - * classes. - * - * From there you can go on to look at the documentation of - * individual functions. You can see different views of the individual - * functions through the links in top bar across this page. - * - * If you prefer a more hands-on approach, you can jump right to some - * example code. - * - * \section porting_guide Porting Guide - * - * Starting with FLAC 1.1.3 a \link porting Porting Guide \endlink - * has been introduced which gives detailed instructions on how to - * port your code to newer versions of FLAC. - * - * \section embedded_developers Embedded Developers - * - * libFLAC has grown larger over time as more functionality has been - * included, but much of it may be unnecessary for a particular embedded - * implementation. Unused parts may be pruned by some simple editing of - * src/libFLAC/Makefile.am. In general, the decoders, encoders, and - * metadata interface are all independent from each other. - * - * It is easiest to just describe the dependencies: - * - * - All modules depend on the \link flac_format Format \endlink module. - * - The decoders and encoders depend on the bitbuffer. - * - The decoder is independent of the encoder. The encoder uses the - * decoder because of the verify feature, but this can be removed if - * not needed. - * - Parts of the metadata interface require the stream decoder (but not - * the encoder). - * - Ogg support is selectable through the compile time macro - * \c FLAC__HAS_OGG. - * - * For example, if your application only requires the stream decoder, no - * encoder, and no metadata interface, you can remove the stream encoder - * and the metadata interface, which will greatly reduce the size of the - * library. - * - * Also, there are several places in the libFLAC code with comments marked - * with "OPT:" where a \#define can be changed to enable code that might be - * faster on a specific platform. Experimenting with these can yield faster - * binaries. - */ - -/** \defgroup porting Porting Guide for New Versions - * - * This module describes differences in the library interfaces from - * version to version. It assists in the porting of code that uses - * the libraries to newer versions of FLAC. - * - * One simple facility for making porting easier that has been added - * in FLAC 1.1.3 is a set of \#defines in \c export.h of each - * library's includes (e.g. \c include/FLAC/export.h). The - * \#defines mirror the libraries' - * libtool version numbers, - * e.g. in libFLAC there are \c FLAC_API_VERSION_CURRENT, - * \c FLAC_API_VERSION_REVISION, and \c FLAC_API_VERSION_AGE. - * These can be used to support multiple versions of an API during the - * transition phase, e.g. - * - * \code - * #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 - * legacy code - * #else - * new code - * #endif - * \endcode - * - * The source will work for multiple versions and the legacy code can - * easily be removed when the transition is complete. - * - * Another available symbol is FLAC_API_SUPPORTS_OGG_FLAC (defined in - * include/FLAC/export.h), which can be used to determine whether or not - * the library has been compiled with support for Ogg FLAC. This is - * simpler than trying to call an Ogg init function and catching the - * error. - */ - -/** \defgroup porting_1_1_2_to_1_1_3 Porting from FLAC 1.1.2 to 1.1.3 - * \ingroup porting - * - * \brief - * This module describes porting from FLAC 1.1.2 to FLAC 1.1.3. - * - * The main change between the APIs in 1.1.2 and 1.1.3 is that they have - * been simplified. First, libOggFLAC has been merged into libFLAC and - * libOggFLAC++ has been merged into libFLAC++. Second, both the three - * decoding layers and three encoding layers have been merged into a - * single stream decoder and stream encoder. That is, the functionality - * of FLAC__SeekableStreamDecoder and FLAC__FileDecoder has been merged - * into FLAC__StreamDecoder, and FLAC__SeekableStreamEncoder and - * FLAC__FileEncoder into FLAC__StreamEncoder. Only the - * FLAC__StreamDecoder and FLAC__StreamEncoder remain. What this means - * is there is now a single API that can be used to encode or decode - * streams to/from native FLAC or Ogg FLAC and the single API can work - * on both seekable and non-seekable streams. - * - * Instead of creating an encoder or decoder of a certain layer, now the - * client will always create a FLAC__StreamEncoder or - * FLAC__StreamDecoder. The old layers are now differentiated by the - * initialization function. For example, for the decoder, - * FLAC__stream_decoder_init() has been replaced by - * FLAC__stream_decoder_init_stream(). This init function takes - * callbacks for the I/O, and the seeking callbacks are optional. This - * allows the client to use the same object for seekable and - * non-seekable streams. For decoding a FLAC file directly, the client - * can use FLAC__stream_decoder_init_file() and pass just a filename - * and fewer callbacks; most of the other callbacks are supplied - * internally. For situations where fopen()ing by filename is not - * possible (e.g. Unicode filenames on Windows) the client can instead - * open the file itself and supply the FILE* to - * FLAC__stream_decoder_init_FILE(). The init functions now returns a - * FLAC__StreamDecoderInitStatus instead of FLAC__StreamDecoderState. - * Since the callbacks and client data are now passed to the init - * function, the FLAC__stream_decoder_set_*_callback() functions and - * FLAC__stream_decoder_set_client_data() are no longer needed. The - * rest of the calls to the decoder are the same as before. - * - * There are counterpart init functions for Ogg FLAC, e.g. - * FLAC__stream_decoder_init_ogg_stream(). All the rest of the calls - * and callbacks are the same as for native FLAC. - * - * As an example, in FLAC 1.1.2 a seekable stream decoder would have - * been set up like so: - * - * \code - * FLAC__SeekableStreamDecoder *decoder = FLAC__seekable_stream_decoder_new(); - * if(decoder == NULL) do_something; - * FLAC__seekable_stream_decoder_set_md5_checking(decoder, true); - * [... other settings ...] - * FLAC__seekable_stream_decoder_set_read_callback(decoder, my_read_callback); - * FLAC__seekable_stream_decoder_set_seek_callback(decoder, my_seek_callback); - * FLAC__seekable_stream_decoder_set_tell_callback(decoder, my_tell_callback); - * FLAC__seekable_stream_decoder_set_length_callback(decoder, my_length_callback); - * FLAC__seekable_stream_decoder_set_eof_callback(decoder, my_eof_callback); - * FLAC__seekable_stream_decoder_set_write_callback(decoder, my_write_callback); - * FLAC__seekable_stream_decoder_set_metadata_callback(decoder, my_metadata_callback); - * FLAC__seekable_stream_decoder_set_error_callback(decoder, my_error_callback); - * FLAC__seekable_stream_decoder_set_client_data(decoder, my_client_data); - * if(FLAC__seekable_stream_decoder_init(decoder) != FLAC__SEEKABLE_STREAM_DECODER_OK) do_something; - * \endcode - * - * In FLAC 1.1.3 it is like this: - * - * \code - * FLAC__StreamDecoder *decoder = FLAC__stream_decoder_new(); - * if(decoder == NULL) do_something; - * FLAC__stream_decoder_set_md5_checking(decoder, true); - * [... other settings ...] - * if(FLAC__stream_decoder_init_stream( - * decoder, - * my_read_callback, - * my_seek_callback, // or NULL - * my_tell_callback, // or NULL - * my_length_callback, // or NULL - * my_eof_callback, // or NULL - * my_write_callback, - * my_metadata_callback, // or NULL - * my_error_callback, - * my_client_data - * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something; - * \endcode - * - * or you could do; - * - * \code - * [...] - * FILE *file = fopen("somefile.flac","rb"); - * if(file == NULL) do_somthing; - * if(FLAC__stream_decoder_init_FILE( - * decoder, - * file, - * my_write_callback, - * my_metadata_callback, // or NULL - * my_error_callback, - * my_client_data - * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something; - * \endcode - * - * or just: - * - * \code - * [...] - * if(FLAC__stream_decoder_init_file( - * decoder, - * "somefile.flac", - * my_write_callback, - * my_metadata_callback, // or NULL - * my_error_callback, - * my_client_data - * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something; - * \endcode - * - * Another small change to the decoder is in how it handles unparseable - * streams. Before, when the decoder found an unparseable stream - * (reserved for when the decoder encounters a stream from a future - * encoder that it can't parse), it changed the state to - * \c FLAC__STREAM_DECODER_UNPARSEABLE_STREAM. Now the decoder instead - * drops sync and calls the error callback with a new error code - * \c FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM. This is - * more robust. If your error callback does not discriminate on the the - * error state, your code does not need to be changed. - * - * The encoder now has a new setting: - * FLAC__stream_encoder_set_apodization(). This is for setting the - * method used to window the data before LPC analysis. You only need to - * add a call to this function if the default is not suitable. There - * are also two new convenience functions that may be useful: - * FLAC__metadata_object_cuesheet_calculate_cddb_id() and - * FLAC__metadata_get_cuesheet(). - * - * The \a bytes parameter to FLAC__StreamDecoderReadCallback, - * FLAC__StreamEncoderReadCallback, and FLAC__StreamEncoderWriteCallback - * is now \c size_t instead of \c uint32_t. - */ - -/** \defgroup porting_1_1_3_to_1_1_4 Porting from FLAC 1.1.3 to 1.1.4 - * \ingroup porting - * - * \brief - * This module describes porting from FLAC 1.1.3 to FLAC 1.1.4. - * - * There were no changes to any of the interfaces from 1.1.3 to 1.1.4. - * There was a slight change in the implementation of - * FLAC__stream_encoder_set_metadata(); the function now makes a copy - * of the \a metadata array of pointers so the client no longer needs - * to maintain it after the call. The objects themselves that are - * pointed to by the array are still not copied though and must be - * maintained until the call to FLAC__stream_encoder_finish(). - */ - -/** \defgroup porting_1_1_4_to_1_2_0 Porting from FLAC 1.1.4 to 1.2.0 - * \ingroup porting - * - * \brief - * This module describes porting from FLAC 1.1.4 to FLAC 1.2.0. - * - * There were only very minor changes to the interfaces from 1.1.4 to 1.2.0. - * In libFLAC, \c FLAC__format_sample_rate_is_subset() was added. - * In libFLAC++, \c FLAC::Decoder::Stream::get_decode_position() was added. - * - * Finally, value of the constant \c FLAC__FRAME_HEADER_RESERVED_LEN - * has changed to reflect the conversion of one of the reserved bits - * into active use. It used to be \c 2 and now is \c 1. However the - * FLAC frame header length has not changed, so to skip the proper - * number of bits, use \c FLAC__FRAME_HEADER_RESERVED_LEN + - * \c FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN - */ - -/** \defgroup porting_1_3_4_to_1_4_0 Porting from FLAC 1.3.4 to 1.4.0 - * \ingroup porting - * - * \brief - * This module describes porting from FLAC 1.3.4 to FLAC 1.4.0. - * - * \section porting_1_3_4_to_1_4_0_summary Summary - * - * Between FLAC 1.3.4 and FLAC 1.4.0, there have four breaking changes - * - the function get_client_data_from_decoder has been renamed to - * FLAC__get_decoder_client_data - * - some data types in the FLAC__Frame struct have changed - * - all functions resizing metadata blocks now return the object - * untouched if memory allocation fails, whereas previously the - * handling varied and was more or less undefined - * - all functions accepting a filename now take UTF-8 encoded filenames - * on Windows instead of filenames in the current codepage - * - * Furthermore, there have been the following additions - * - the functions FLAC__stream_encoder_set_limit_min_bitrate, - * FLAC__stream_encoder_get_limit_min_bitrate, - * FLAC::encoder::file::set_limit_min_bitrate() and - * FLAC::encoder::file::get_limit_min_bitrate() have been added - * - Added FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA to the - * FLAC__StreamDecoderErrorStatus enum - * - * \section porting_1_3_4_to_1_4_0_breaking Breaking changes - * - * The function \b get_client_data_from_decoder was added in FLAC 1.3.3 - * but did not follow the API naming convention and was not properly - * exported. The function is now renamed and properly integrated as - * FLAC__stream_decoder_get_client_data - * - * To accomodate encoding and decoding 32-bit int PCM, some data types - * in the \b FLAC__frame struct were changed. Specifically, warmup - * in both the FLAC__Subframe_Fixed struc and the FLAC__Subframe_LPC - * struct is changed from FLAC__int32 to FLAC__int64. Also, value - * in the FLAC__Subframe_Constant is changed from FLAC__int32 to - * FLAC__int64. Finally, in FLAC__Subframe_Verbatim struct data is - * changes from a FLAC__int32 array to a union containing a FLAC__int32 - * array and a FLAC__int64 array. Also, a new member is added, - * data_type, which clarifies whether the FLAC__int32 or FLAC__int64 - * array is in use. - * - * Furthermore, the following functions now return the object untouched - * if memory allocation fails, whereas previously the handling varied - * and was more or less undefined - * - * - FLAC__metadata_object_seektable_resize_points - * - FLAC__metadata_object_vorbiscomment_resize_comments - * - FLAC__metadata_object_cuesheet_track_resize_indices - * - FLAC__metadata_object_cuesheet_resize_tracks - * - * The last breaking change is that all API functions taking a filename - * as an argument now, on Windows, must be supplied with that filename - * in the UTF-8 character encoding instead of using the current code - * page. libFLAC internally translates these UTF-8 encoded filenames to - * an appropriate representation to use with _wfopen. On all other - * systems, filename is passed to fopen without any translation, as it - * in libFLAC 1.3.4 and earlier. - * - * \section porting_1_3_4_to_1_4_0_additions Additions - * - * To aid in creating properly streamable FLAC files, a set of functions - * was added to make it possible to enfore a minimum bitrate to files - * created through libFLAC's stream_encoder.h interface. With this - * function enabled the resulting FLAC files have a minimum bitrate of - * 1bit/sample independent of the number of channels, i.e. 48kbit/s for - * 48kHz. This can be beneficial for streaming, as very low bitrates for - * silent sections compressed with 'constant' subframes can result in a - * bitrate of 1kbit/s, creating problems with clients that aren't aware - * of this possibility and buffer too much data. - * - * Finally, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA was added to - * the FLAC__StreamDecoderErrorStatus enum to signal that the decoder - * encountered unreadable metadata. - * - */ - -/** \defgroup flac FLAC C API - * - * The FLAC C API is the interface to libFLAC, a set of structures - * describing the components of FLAC streams, and functions for - * encoding and decoding streams, as well as manipulating FLAC - * metadata in files. - * - * You should start with the format components as all other modules - * are dependent on it. - */ - -#endif diff --git a/flac/include/FLAC/assert.h b/flac/include/FLAC/assert.h deleted file mode 100644 index ee3ee08..0000000 --- a/flac/include/FLAC/assert.h +++ /dev/null @@ -1,51 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__ASSERT_H -#define FLAC__ASSERT_H - -/* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */ -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -#define FLAC__ASSERT(x) if(!(x)) __builtin_abort(); -#define FLAC__ASSERT_DECLARATION(x) x -#else -#ifndef NDEBUG -#include -#define FLAC__ASSERT(x) assert(x) -#define FLAC__ASSERT_DECLARATION(x) x -#else -#define FLAC__ASSERT(x) -#define FLAC__ASSERT_DECLARATION(x) -#endif -#endif - -#endif diff --git a/flac/include/FLAC/callback.h b/flac/include/FLAC/callback.h deleted file mode 100644 index 4babcd3..0000000 --- a/flac/include/FLAC/callback.h +++ /dev/null @@ -1,190 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__CALLBACK_H -#define FLAC__CALLBACK_H - -#include "ordinals.h" -#include /* for size_t */ - -/** \file include/FLAC/callback.h - * - * \brief - * This module defines the structures for describing I/O callbacks - * to the other FLAC interfaces. - * - * See the detailed documentation for callbacks in the - * \link flac_callbacks callbacks \endlink module. - */ - -/** \defgroup flac_callbacks FLAC/callback.h: I/O callback structures - * \ingroup flac - * - * \brief - * This module defines the structures for describing I/O callbacks - * to the other FLAC interfaces. - * - * The purpose of the I/O callback functions is to create a common way - * for the metadata interfaces to handle I/O. - * - * Originally the metadata interfaces required filenames as the way of - * specifying FLAC files to operate on. This is problematic in some - * environments so there is an additional option to specify a set of - * callbacks for doing I/O on the FLAC file, instead of the filename. - * - * In addition to the callbacks, a FLAC__IOHandle type is defined as an - * opaque structure for a data source. - * - * The callback function prototypes are similar (but not identical) to the - * stdio functions fread, fwrite, fseek, ftell, feof, and fclose. If you use - * stdio streams to implement the callbacks, you can pass fread, fwrite, and - * fclose anywhere a FLAC__IOCallback_Read, FLAC__IOCallback_Write, or - * FLAC__IOCallback_Close is required, and a FILE* anywhere a FLAC__IOHandle - * is required. \warning You generally CANNOT directly use fseek or ftell - * for FLAC__IOCallback_Seek or FLAC__IOCallback_Tell since on most systems - * these use 32-bit offsets and FLAC requires 64-bit offsets to deal with - * large files. You will have to find an equivalent function (e.g. ftello), - * or write a wrapper. The same is true for feof() since this is usually - * implemented as a macro, not as a function whose address can be taken. - * - * \{ - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** This is the opaque handle type used by the callbacks. Typically - * this is a \c FILE* or address of a file descriptor. - */ -typedef void* FLAC__IOHandle; - -/** Signature for the read callback. - * The signature and semantics match POSIX fread() implementations - * and can generally be used interchangeably. Note that the global - * variable errno from errno.h is read by some libFLAC functions to - * detect read errors. - * - * \param ptr The address of the read buffer. - * \param size The size of the records to be read. - * \param nmemb The number of records to be read. - * \param handle The handle to the data source. - * \retval size_t - * The number of records read. - */ -typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle); - -/** Signature for the write callback. - * The signature and semantics match POSIX fwrite() implementations - * and can generally be used interchangeably. - * - * \param ptr The address of the write buffer. - * \param size The size of the records to be written. - * \param nmemb The number of records to be written. - * \param handle The handle to the data source. - * \retval size_t - * The number of records written. - */ -typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle); - -/** Signature for the seek callback. - * The signature and semantics mostly match POSIX fseek() WITH ONE IMPORTANT - * EXCEPTION: the offset is a 64-bit type whereas fseek() is generally 'long' - * and 32-bits wide. - * - * \param handle The handle to the data source. - * \param offset The new position, relative to \a whence - * \param whence \c SEEK_SET, \c SEEK_CUR, or \c SEEK_END - * \retval int - * \c 0 on success, \c -1 on error. - */ -typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence); - -/** Signature for the tell callback. - * The signature and semantics mostly match POSIX ftell() WITH ONE IMPORTANT - * EXCEPTION: the offset is a 64-bit type whereas ftell() is generally 'long' - * and 32-bits wide. - * - * \param handle The handle to the data source. - * \retval FLAC__int64 - * The current position on success, \c -1 on error. - */ -typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle); - -/** Signature for the EOF callback. - * The signature and semantics mostly match POSIX feof() but WATCHOUT: - * on many systems, feof() is a macro, so in this case a wrapper function - * must be provided instead. - * - * \param handle The handle to the data source. - * \retval int - * \c 0 if not at end of file, nonzero if at end of file. - */ -typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle); - -/** Signature for the close callback. - * The signature and semantics match POSIX fclose() implementations - * and can generally be used interchangeably. - * - * \param handle The handle to the data source. - * \retval int - * \c 0 on success, \c EOF on error. - */ -typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle); - -/** A structure for holding a set of callbacks. - * Each FLAC interface that requires a FLAC__IOCallbacks structure will - * describe which of the callbacks are required. The ones that are not - * required may be set to NULL. - * - * If the seek requirement for an interface is optional, you can signify that - * a data source is not seekable by setting the \a seek field to \c NULL. - * - * See the detailed documentation for callbacks in the - * \link flac_callbacks callbacks \endlink module. - */ -typedef struct { - FLAC__IOCallback_Read read; /**< See FLAC__IOCallbacks */ - FLAC__IOCallback_Write write; /**< See FLAC__IOCallbacks */ - FLAC__IOCallback_Seek seek; /**< See FLAC__IOCallbacks */ - FLAC__IOCallback_Tell tell; /**< See FLAC__IOCallbacks */ - FLAC__IOCallback_Eof eof; /**< See FLAC__IOCallbacks */ - FLAC__IOCallback_Close close; /**< See FLAC__IOCallbacks */ -} FLAC__IOCallbacks; - -/* \} */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flac/include/FLAC/export.h b/flac/include/FLAC/export.h deleted file mode 100644 index d14728a..0000000 --- a/flac/include/FLAC/export.h +++ /dev/null @@ -1,115 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__EXPORT_H -#define FLAC__EXPORT_H - -/** \file include/FLAC/export.h - * - * \brief - * This module contains \#defines and symbols for exporting function - * calls, and providing version information and compiled-in features. - * - * See the \link flac_export export \endlink module. - */ - -/** \defgroup flac_export FLAC/export.h: export symbols - * \ingroup flac - * - * \brief - * This module contains \#defines and symbols for exporting function - * calls, and providing version information and compiled-in features. - * - * If you are compiling for Windows (with Visual Studio or MinGW for - * example) and will link to the static library (libFLAC++.lib) you - * should define FLAC__NO_DLL in your project to make sure the symbols - * are exported properly. - * - * \{ - */ - -/** This \#define is used internally in libFLAC and its headers to make - * sure the correct symbols are exported when working with shared - * libraries. On Windows, this \#define is set to __declspec(dllexport) - * when compiling libFLAC into a library and to __declspec(dllimport) - * when the headers are used to link to that DLL. On non-Windows systems - * it is used to set symbol visibility. - * - * Because of this, the define FLAC__NO_DLL must be defined when linking - * to libFLAC statically or linking will fail. - */ -/* This has grown quite complicated. FLAC__NO_DLL is used by MSVC sln - * files and CMake, which build either static or shared. autotools can - * build static, shared or **both**. Therefore, DLL_EXPORT, which is set - * by libtool, must override FLAC__NO_DLL on building shared components - */ -#if defined(_WIN32) - -#if defined(FLAC__NO_DLL) && !(defined(DLL_EXPORT)) -#define FLAC_API -#else -#ifdef FLAC_API_EXPORTS -#define FLAC_API __declspec(dllexport) -#else -#define FLAC_API __declspec(dllimport) -#endif -#endif - -#elif defined(FLAC__USE_VISIBILITY_ATTR) -#define FLAC_API __attribute__ ((visibility ("default"))) - -#else -#define FLAC_API - -#endif - -/** These \#defines will mirror the libtool-based library version number, see - * http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning - */ -#define FLAC_API_VERSION_CURRENT 13 -#define FLAC_API_VERSION_REVISION 0 /**< see above */ -#define FLAC_API_VERSION_AGE 1 /**< see above */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** \c 1 if the library has been compiled with support for Ogg FLAC, else \c 0. */ -extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC; - -#ifdef __cplusplus -} -#endif - -/* \} */ - -#endif diff --git a/flac/include/FLAC/format.h b/flac/include/FLAC/format.h deleted file mode 100644 index ef7c8b2..0000000 --- a/flac/include/FLAC/format.h +++ /dev/null @@ -1,1032 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__FORMAT_H -#define FLAC__FORMAT_H - -#include "export.h" -#include "ordinals.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** \file include/FLAC/format.h - * - * \brief - * This module contains structure definitions for the representation - * of FLAC format components in memory. These are the basic - * structures used by the rest of the interfaces. - * - * See the detailed documentation in the - * \link flac_format format \endlink module. - */ - -/** \defgroup flac_format FLAC/format.h: format components - * \ingroup flac - * - * \brief - * This module contains structure definitions for the representation - * of FLAC format components in memory. These are the basic - * structures used by the rest of the interfaces. - * - * First, you should be familiar with the - * FLAC format. Many of the values here - * follow directly from the specification. As a user of libFLAC, the - * interesting parts really are the structures that describe the frame - * header and metadata blocks. - * - * The format structures here are very primitive, designed to store - * information in an efficient way. Reading information from the - * structures is easy but creating or modifying them directly is - * more complex. For the most part, as a user of a library, editing - * is not necessary; however, for metadata blocks it is, so there are - * convenience functions provided in the \link flac_metadata metadata - * module \endlink to simplify the manipulation of metadata blocks. - * - * \note - * It's not the best convention, but symbols ending in _LEN are in bits - * and _LENGTH are in bytes. _LENGTH symbols are \#defines instead of - * global variables because they are usually used when declaring byte - * arrays and some compilers require compile-time knowledge of array - * sizes when declared on the stack. - * - * \{ - */ - - -/* - Most of the values described in this file are defined by the FLAC - format specification. There is nothing to tune here. -*/ - -/** The largest legal metadata type code. */ -#define FLAC__MAX_METADATA_TYPE_CODE (126u) - -/** The minimum block size, in samples, permitted by the format. */ -#define FLAC__MIN_BLOCK_SIZE (16u) - -/** The maximum block size, in samples, permitted by the format. */ -#define FLAC__MAX_BLOCK_SIZE (65535u) - -/** The maximum block size, in samples, permitted by the FLAC subset for - * sample rates up to 48kHz. */ -#define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u) - -/** The maximum number of channels permitted by the format. */ -#define FLAC__MAX_CHANNELS (8u) - -/** The minimum sample resolution permitted by the format. */ -#define FLAC__MIN_BITS_PER_SAMPLE (4u) - -/** The maximum sample resolution permitted by the format. */ -#define FLAC__MAX_BITS_PER_SAMPLE (32u) - -/** The maximum sample resolution permitted by libFLAC. - * - * FLAC__MAX_BITS_PER_SAMPLE is the limit of the FLAC format. However, - * the reference encoder/decoder used to be limited to 24 bits. This - * value was used to signal that limit. - */ -#define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (32u) - -/** The maximum sample rate permitted by the format. The value is - * ((2 ^ 20) - 1) - */ -#define FLAC__MAX_SAMPLE_RATE (1048575u) - -/** The maximum LPC order permitted by the format. */ -#define FLAC__MAX_LPC_ORDER (32u) - -/** The maximum LPC order permitted by the FLAC subset for sample rates - * up to 48kHz. */ -#define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u) - -/** The minimum quantized linear predictor coefficient precision - * permitted by the format. - */ -#define FLAC__MIN_QLP_COEFF_PRECISION (5u) - -/** The maximum quantized linear predictor coefficient precision - * permitted by the format. - */ -#define FLAC__MAX_QLP_COEFF_PRECISION (15u) - -/** The maximum order of the fixed predictors permitted by the format. */ -#define FLAC__MAX_FIXED_ORDER (4u) - -/** The maximum Rice partition order permitted by the format. */ -#define FLAC__MAX_RICE_PARTITION_ORDER (15u) - -/** The maximum Rice partition order permitted by the FLAC Subset. */ -#define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u) - -/** The version string of the release, stamped onto the libraries and binaries. - * - * \note - * This does not correspond to the shared library version number, which - * is used to determine binary compatibility. - */ -extern FLAC_API const char *FLAC__VERSION_STRING; - -/** The vendor string inserted by the encoder into the VORBIS_COMMENT block. - * This is a NUL-terminated ASCII string; when inserted into the - * VORBIS_COMMENT the trailing null is stripped. - */ -extern FLAC_API const char *FLAC__VENDOR_STRING; - -/** The byte string representation of the beginning of a FLAC stream. */ -extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */ - -/** The 32-bit integer big-endian representation of the beginning of - * a FLAC stream. - */ -extern FLAC_API const uint32_t FLAC__STREAM_SYNC; /* = 0x664C6143 */ - -/** The length of the FLAC signature in bits. */ -extern FLAC_API const uint32_t FLAC__STREAM_SYNC_LEN; /* = 32 bits */ - -/** The length of the FLAC signature in bytes. */ -#define FLAC__STREAM_SYNC_LENGTH (4u) - - -/***************************************************************************** - * - * Subframe structures - * - *****************************************************************************/ - -/*****************************************************************************/ - -/** An enumeration of the available entropy coding methods. */ -typedef enum { - FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0, - /**< Residual is coded by partitioning into contexts, each with it's own - * 4-bit Rice parameter. */ - - FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1 - /**< Residual is coded by partitioning into contexts, each with it's own - * 5-bit Rice parameter. */ -} FLAC__EntropyCodingMethodType; - -/** Maps a FLAC__EntropyCodingMethodType to a C string. - * - * Using a FLAC__EntropyCodingMethodType as the index to this array will - * give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[]; - - -/** Contents of a Rice partitioned residual - */ -typedef struct { - - uint32_t *parameters; - /**< The Rice parameters for each context. */ - - uint32_t *raw_bits; - /**< Widths for escape-coded partitions. Will be non-zero for escaped - * partitions and zero for unescaped partitions. - */ - - uint32_t capacity_by_order; - /**< The capacity of the \a parameters and \a raw_bits arrays - * specified as an order, i.e. the number of array elements - * allocated is 2 ^ \a capacity_by_order. - */ -} FLAC__EntropyCodingMethod_PartitionedRiceContents; - -/** Header for a Rice partitioned residual. (c.f. format specification) - */ -typedef struct { - - uint32_t order; - /**< The partition order, i.e. # of contexts = 2 ^ \a order. */ - - const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents; - /**< The context's Rice parameters and/or raw bits. */ - -} FLAC__EntropyCodingMethod_PartitionedRice; - -extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */ -extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */ -extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */ -extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */ - -extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER; -/**< == (1<format specification) - */ -typedef struct { - FLAC__EntropyCodingMethodType type; - union { - FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice; - } data; -} FLAC__EntropyCodingMethod; - -extern FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */ - -/*****************************************************************************/ - -/** An enumeration of the available subframe types. */ -typedef enum { - FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */ - FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */ - FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */ - FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */ -} FLAC__SubframeType; - -/** Maps a FLAC__SubframeType to a C string. - * - * Using a FLAC__SubframeType as the index to this array will - * give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__SubframeTypeString[]; - - -/** CONSTANT subframe. (c.f. format specification) - */ -typedef struct { - FLAC__int64 value; /**< The constant signal value. */ -} FLAC__Subframe_Constant; - -/** An enumeration of the possible verbatim subframe data types. */ -typedef enum { - FLAC__VERBATIM_SUBFRAME_DATA_TYPE_INT32, /**< verbatim subframe has 32-bit int */ - FLAC__VERBATIM_SUBFRAME_DATA_TYPE_INT64 /**< verbatim subframe has 64-bit int */ -} FLAC__VerbatimSubframeDataType; - - -/** VERBATIM subframe. (c.f. format specification) - */ -typedef struct { - union { - const FLAC__int32 *int32; /**< A FLAC__int32 pointer to verbatim signal. */ - const FLAC__int64 *int64; /**< A FLAC__int64 pointer to verbatim signal. */ - } data; - FLAC__VerbatimSubframeDataType data_type; -} FLAC__Subframe_Verbatim; - - -/** FIXED subframe. (c.f. format specification) - */ -typedef struct { - FLAC__EntropyCodingMethod entropy_coding_method; - /**< The residual coding method. */ - - uint32_t order; - /**< The polynomial order. */ - - FLAC__int64 warmup[FLAC__MAX_FIXED_ORDER]; - /**< Warmup samples to prime the predictor, length == order. */ - - const FLAC__int32 *residual; - /**< The residual signal, length == (blocksize minus order) samples. */ -} FLAC__Subframe_Fixed; - - -/** LPC subframe. (c.f. format specification) - */ -typedef struct { - FLAC__EntropyCodingMethod entropy_coding_method; - /**< The residual coding method. */ - - uint32_t order; - /**< The FIR order. */ - - uint32_t qlp_coeff_precision; - /**< Quantized FIR filter coefficient precision in bits. */ - - int quantization_level; - /**< The qlp coeff shift needed. */ - - FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER]; - /**< FIR filter coefficients. */ - - FLAC__int64 warmup[FLAC__MAX_LPC_ORDER]; - /**< Warmup samples to prime the predictor, length == order. */ - - const FLAC__int32 *residual; - /**< The residual signal, length == (blocksize minus order) samples. */ -} FLAC__Subframe_LPC; - -extern FLAC_API const uint32_t FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */ -extern FLAC_API const uint32_t FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */ - - -/** FLAC subframe structure. (c.f. format specification) - */ -typedef struct { - FLAC__SubframeType type; - union { - FLAC__Subframe_Constant constant; - FLAC__Subframe_Fixed fixed; - FLAC__Subframe_LPC lpc; - FLAC__Subframe_Verbatim verbatim; - } data; - uint32_t wasted_bits; -} FLAC__Subframe; - -/** == 1 (bit) - * - * This used to be a zero-padding bit (hence the name - * FLAC__SUBFRAME_ZERO_PAD_LEN) but is now a reserved bit. It still has a - * mandatory value of \c 0 but in the future may take on the value \c 0 or \c 1 - * to mean something else. - */ -extern FLAC_API const uint32_t FLAC__SUBFRAME_ZERO_PAD_LEN; -extern FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */ -extern FLAC_API const uint32_t FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */ - -extern FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */ -extern FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */ -extern FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */ -extern FLAC_API const uint32_t FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */ - -/*****************************************************************************/ - - -/***************************************************************************** - * - * Frame structures - * - *****************************************************************************/ - -/** An enumeration of the available channel assignments. */ -typedef enum { - FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */ - FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */ - FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */ - FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */ -} FLAC__ChannelAssignment; - -/** Maps a FLAC__ChannelAssignment to a C string. - * - * Using a FLAC__ChannelAssignment as the index to this array will - * give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__ChannelAssignmentString[]; - -/** An enumeration of the possible frame numbering methods. */ -typedef enum { - FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */ - FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */ -} FLAC__FrameNumberType; - -/** Maps a FLAC__FrameNumberType to a C string. - * - * Using a FLAC__FrameNumberType as the index to this array will - * give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__FrameNumberTypeString[]; - - -/** FLAC frame header structure. (c.f. format specification) - */ -typedef struct { - uint32_t blocksize; - /**< The number of samples per subframe. */ - - uint32_t sample_rate; - /**< The sample rate in Hz. */ - - uint32_t channels; - /**< The number of channels (== number of subframes). */ - - FLAC__ChannelAssignment channel_assignment; - /**< The channel assignment for the frame. */ - - uint32_t bits_per_sample; - /**< The sample resolution. */ - - FLAC__FrameNumberType number_type; - /**< The numbering scheme used for the frame. As a convenience, the - * decoder will always convert a frame number to a sample number because - * the rules are complex. */ - - union { - FLAC__uint32 frame_number; - FLAC__uint64 sample_number; - } number; - /**< The frame number or sample number of first sample in frame; - * use the \a number_type value to determine which to use. */ - - FLAC__uint8 crc; - /**< CRC-8 (polynomial = x^8 + x^2 + x^1 + x^0, initialized with 0) - * of the raw frame header bytes, meaning everything before the CRC byte - * including the sync code. - */ -} FLAC__FrameHeader; - -extern FLAC_API const uint32_t FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */ -extern FLAC_API const uint32_t FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */ -extern FLAC_API const uint32_t FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */ -extern FLAC_API const uint32_t FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */ -extern FLAC_API const uint32_t FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */ -extern FLAC_API const uint32_t FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */ -extern FLAC_API const uint32_t FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */ -extern FLAC_API const uint32_t FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */ -extern FLAC_API const uint32_t FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */ -extern FLAC_API const uint32_t FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */ - - -/** FLAC frame footer structure. (c.f. format specification) - */ -typedef struct { - FLAC__uint16 crc; - /**< CRC-16 (polynomial = x^16 + x^15 + x^2 + x^0, initialized with - * 0) of the bytes before the crc, back to and including the frame header - * sync code. - */ -} FLAC__FrameFooter; - -extern FLAC_API const uint32_t FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */ - - -/** FLAC frame structure. (c.f. format specification) - */ -typedef struct { - FLAC__FrameHeader header; - FLAC__Subframe subframes[FLAC__MAX_CHANNELS]; - FLAC__FrameFooter footer; -} FLAC__Frame; - -/*****************************************************************************/ - - -/***************************************************************************** - * - * Meta-data structures - * - *****************************************************************************/ - -/** An enumeration of the available metadata block types. */ -typedef enum { - - FLAC__METADATA_TYPE_STREAMINFO = 0, - /**< STREAMINFO block */ - - FLAC__METADATA_TYPE_PADDING = 1, - /**< PADDING block */ - - FLAC__METADATA_TYPE_APPLICATION = 2, - /**< APPLICATION block */ - - FLAC__METADATA_TYPE_SEEKTABLE = 3, - /**< SEEKTABLE block */ - - FLAC__METADATA_TYPE_VORBIS_COMMENT = 4, - /**< VORBISCOMMENT block (a.k.a. FLAC tags) */ - - FLAC__METADATA_TYPE_CUESHEET = 5, - /**< CUESHEET block */ - - FLAC__METADATA_TYPE_PICTURE = 6, - /**< PICTURE block */ - - FLAC__METADATA_TYPE_UNDEFINED = 7, - /**< marker to denote beginning of undefined type range; this number will increase as new metadata types are added */ - - FLAC__MAX_METADATA_TYPE = FLAC__MAX_METADATA_TYPE_CODE, - /**< No type will ever be greater than this. There is not enough room in the protocol block. */ -} FLAC__MetadataType; - -/** Maps a FLAC__MetadataType to a C string. - * - * Using a FLAC__MetadataType as the index to this array will - * give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__MetadataTypeString[]; - - -/** FLAC STREAMINFO structure. (c.f. format specification) - */ -typedef struct { - uint32_t min_blocksize, max_blocksize; - uint32_t min_framesize, max_framesize; - uint32_t sample_rate; - uint32_t channels; - uint32_t bits_per_sample; - FLAC__uint64 total_samples; - FLAC__byte md5sum[16]; -} FLAC__StreamMetadata_StreamInfo; - -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */ - -/** The total stream length of the STREAMINFO block in bytes. */ -#define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u) - -/** FLAC PADDING structure. (c.f. format specification) - */ -typedef struct { - int dummy; - /**< Conceptually this is an empty struct since we don't store the - * padding bytes. Empty structs are not allowed by some C compilers, - * hence the dummy. - */ -} FLAC__StreamMetadata_Padding; - - -/** FLAC APPLICATION structure. (c.f. format specification) - */ -typedef struct { - FLAC__byte id[4]; - FLAC__byte *data; -} FLAC__StreamMetadata_Application; - -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */ - -/** SeekPoint structure used in SEEKTABLE blocks. (c.f. format specification) - */ -typedef struct { - FLAC__uint64 sample_number; - /**< The sample number of the target frame. */ - - FLAC__uint64 stream_offset; - /**< The offset, in bytes, of the target frame with respect to - * beginning of the first frame. */ - - uint32_t frame_samples; - /**< The number of samples in the target frame. */ -} FLAC__StreamMetadata_SeekPoint; - -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */ - -/** The total stream length of a seek point in bytes. */ -#define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u) - -/** The value used in the \a sample_number field of - * FLAC__StreamMetadataSeekPoint used to indicate a placeholder - * point (== 0xffffffffffffffff). - */ -extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - - -/** FLAC SEEKTABLE structure. (c.f. format specification) - * - * \note From the format specification: - * - The seek points must be sorted by ascending sample number. - * - Each seek point's sample number must be the first sample of the - * target frame. - * - Each seek point's sample number must be unique within the table. - * - Existence of a SEEKTABLE block implies a correct setting of - * total_samples in the stream_info block. - * - Behavior is undefined when more than one SEEKTABLE block is - * present in a stream. - */ -typedef struct { - uint32_t num_points; - FLAC__StreamMetadata_SeekPoint *points; -} FLAC__StreamMetadata_SeekTable; - - -/** Vorbis comment entry structure used in VORBIS_COMMENT blocks. (c.f. format specification) - * - * For convenience, the APIs maintain a trailing NUL character at the end of - * \a entry which is not counted toward \a length, i.e. - * \code strlen(entry) == length \endcode - */ -typedef struct { - FLAC__uint32 length; - FLAC__byte *entry; -} FLAC__StreamMetadata_VorbisComment_Entry; - -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */ - - -/** FLAC VORBIS_COMMENT structure. (c.f. format specification) - */ -typedef struct { - FLAC__StreamMetadata_VorbisComment_Entry vendor_string; - FLAC__uint32 num_comments; - FLAC__StreamMetadata_VorbisComment_Entry *comments; -} FLAC__StreamMetadata_VorbisComment; - -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */ - - -/** FLAC CUESHEET track index structure. (See the - * format specification for - * the full description of each field.) - */ -typedef struct { - FLAC__uint64 offset; - /**< Offset in samples, relative to the track offset, of the index - * point. - */ - - FLAC__byte number; - /**< The index point number. */ -} FLAC__StreamMetadata_CueSheet_Index; - -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */ - - -/** FLAC CUESHEET track structure. (See the - * format specification for - * the full description of each field.) - */ -typedef struct { - FLAC__uint64 offset; - /**< Track offset in samples, relative to the beginning of the FLAC audio stream. */ - - FLAC__byte number; - /**< The track number. */ - - char isrc[13]; - /**< Track ISRC. This is a 12-digit alphanumeric code plus a trailing \c NUL byte */ - - uint32_t type:1; - /**< The track type: 0 for audio, 1 for non-audio. */ - - uint32_t pre_emphasis:1; - /**< The pre-emphasis flag: 0 for no pre-emphasis, 1 for pre-emphasis. */ - - FLAC__byte num_indices; - /**< The number of track index points. */ - - FLAC__StreamMetadata_CueSheet_Index *indices; - /**< NULL if num_indices == 0, else pointer to array of index points. */ - -} FLAC__StreamMetadata_CueSheet_Track; - -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */ - - -/** FLAC CUESHEET structure. (See the - * format specification - * for the full description of each field.) - */ -typedef struct { - char media_catalog_number[129]; - /**< Media catalog number, in ASCII printable characters 0x20-0x7e. In - * general, the media catalog number may be 0 to 128 bytes long; any - * unused characters should be right-padded with NUL characters. - */ - - FLAC__uint64 lead_in; - /**< The number of lead-in samples. */ - - FLAC__bool is_cd; - /**< \c true if CUESHEET corresponds to a Compact Disc, else \c false. */ - - uint32_t num_tracks; - /**< The number of tracks. */ - - FLAC__StreamMetadata_CueSheet_Track *tracks; - /**< NULL if num_tracks == 0, else pointer to array of tracks. */ - -} FLAC__StreamMetadata_CueSheet; - -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */ - - -/** An enumeration of the PICTURE types (see FLAC__StreamMetadataPicture and id3 v2.4 APIC tag). */ -typedef enum { - FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */ - FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */ - FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */ - FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */ - FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */ - FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */ - FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */ - FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */ - FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */ - FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */ - FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */ - FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */ - FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */ - FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */ - FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */ - FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */ - FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */ - FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */ - FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */ - FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */ - FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */ - FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED -} FLAC__StreamMetadata_Picture_Type; - -/** Maps a FLAC__StreamMetadata_Picture_Type to a C string. - * - * Using a FLAC__StreamMetadata_Picture_Type as the index to this array - * will give the string equivalent. The contents should not be - * modified. - */ -extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[]; - -/** FLAC PICTURE structure. (See the - * format specification - * for the full description of each field.) - */ -typedef struct { - FLAC__StreamMetadata_Picture_Type type; - /**< The kind of picture stored. */ - - char *mime_type; - /**< Picture data's MIME type, in ASCII printable characters - * 0x20-0x7e, NUL terminated. For best compatibility with players, - * use picture data of MIME type \c image/jpeg or \c image/png. A - * MIME type of '-->' is also allowed, in which case the picture - * data should be a complete URL. In file storage, the MIME type is - * stored as a 32-bit length followed by the ASCII string with no NUL - * terminator, but is converted to a plain C string in this structure - * for convenience. - */ - - FLAC__byte *description; - /**< Picture's description in UTF-8, NUL terminated. In file storage, - * the description is stored as a 32-bit length followed by the UTF-8 - * string with no NUL terminator, but is converted to a plain C string - * in this structure for convenience. - */ - - FLAC__uint32 width; - /**< Picture's width in pixels. */ - - FLAC__uint32 height; - /**< Picture's height in pixels. */ - - FLAC__uint32 depth; - /**< Picture's color depth in bits-per-pixel. */ - - FLAC__uint32 colors; - /**< For indexed palettes (like GIF), picture's number of colors (the - * number of palette entries), or \c 0 for non-indexed (i.e. 2^depth). - */ - - FLAC__uint32 data_length; - /**< Length of binary picture data in bytes. */ - - FLAC__byte *data; - /**< Binary picture data. */ - -} FLAC__StreamMetadata_Picture; - -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */ - - -/** Structure that is used when a metadata block of unknown type is loaded. - * The contents are opaque. The structure is used only internally to - * correctly handle unknown metadata. - */ -typedef struct { - FLAC__byte *data; -} FLAC__StreamMetadata_Unknown; - - -/** FLAC metadata block structure. (c.f. format specification) - */ -typedef struct FLAC__StreamMetadata { - FLAC__MetadataType type; - /**< The type of the metadata block; used determine which member of the - * \a data union to dereference. If type >= FLAC__METADATA_TYPE_UNDEFINED - * then \a data.unknown must be used. */ - - FLAC__bool is_last; - /**< \c true if this metadata block is the last, else \a false */ - - uint32_t length; - /**< Length, in bytes, of the block data as it appears in the stream. */ - - union { - FLAC__StreamMetadata_StreamInfo stream_info; - FLAC__StreamMetadata_Padding padding; - FLAC__StreamMetadata_Application application; - FLAC__StreamMetadata_SeekTable seek_table; - FLAC__StreamMetadata_VorbisComment vorbis_comment; - FLAC__StreamMetadata_CueSheet cue_sheet; - FLAC__StreamMetadata_Picture picture; - FLAC__StreamMetadata_Unknown unknown; - } data; - /**< Polymorphic block data; use the \a type value to determine which - * to use. */ -} FLAC__StreamMetadata; - -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */ -extern FLAC_API const uint32_t FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */ - -/** The total stream length of a metadata block header in bytes. */ -#define FLAC__STREAM_METADATA_HEADER_LENGTH (4u) - -/*****************************************************************************/ - - -/***************************************************************************** - * - * Utility functions - * - *****************************************************************************/ - -/** Tests that a sample rate is valid for FLAC. - * - * \param sample_rate The sample rate to test for compliance. - * \retval FLAC__bool - * \c true if the given sample rate conforms to the specification, else - * \c false. - */ -FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(uint32_t sample_rate); - -/** Tests that a blocksize at the given sample rate is valid for the FLAC - * subset. - * - * \param blocksize The blocksize to test for compliance. - * \param sample_rate The sample rate is needed, since the valid subset - * blocksize depends on the sample rate. - * \retval FLAC__bool - * \c true if the given blocksize conforms to the specification for the - * subset at the given sample rate, else \c false. - */ -FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(uint32_t blocksize, uint32_t sample_rate); - -/** Tests that a sample rate is valid for the FLAC subset. The subset rules - * for valid sample rates are slightly more complex since the rate has to - * be expressible completely in the frame header. - * - * \param sample_rate The sample rate to test for compliance. - * \retval FLAC__bool - * \c true if the given sample rate conforms to the specification for the - * subset, else \c false. - */ -FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(uint32_t sample_rate); - -/** Check a Vorbis comment entry name to see if it conforms to the Vorbis - * comment specification. - * - * Vorbis comment names must be composed only of characters from - * [0x20-0x3C,0x3E-0x7D]. - * - * \param name A NUL-terminated string to be checked. - * \assert - * \code name != NULL \endcode - * \retval FLAC__bool - * \c false if entry name is illegal, else \c true. - */ -FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name); - -/** Check a Vorbis comment entry value to see if it conforms to the Vorbis - * comment specification. - * - * Vorbis comment values must be valid UTF-8 sequences. - * - * \param value A string to be checked. - * \param length A the length of \a value in bytes. May be - * \c (uint32_t)(-1) to indicate that \a value is a plain - * UTF-8 NUL-terminated string. - * \assert - * \code value != NULL \endcode - * \retval FLAC__bool - * \c false if entry name is illegal, else \c true. - */ -FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, uint32_t length); - -/** Check a Vorbis comment entry to see if it conforms to the Vorbis - * comment specification. - * - * Vorbis comment entries must be of the form 'name=value', and 'name' and - * 'value' must be legal according to - * FLAC__format_vorbiscomment_entry_name_is_legal() and - * FLAC__format_vorbiscomment_entry_value_is_legal() respectively. - * - * \param entry An entry to be checked. - * \param length The length of \a entry in bytes. - * \assert - * \code value != NULL \endcode - * \retval FLAC__bool - * \c false if entry name is illegal, else \c true. - */ -FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, uint32_t length); - -/** Check a seek table to see if it conforms to the FLAC specification. - * See the format specification for limits on the contents of the - * seek table. - * - * \param seek_table A pointer to a seek table to be checked. - * \assert - * \code seek_table != NULL \endcode - * \retval FLAC__bool - * \c false if seek table is illegal, else \c true. - */ -FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table); - -/** Sort a seek table's seek points according to the format specification. - * This includes a "unique-ification" step to remove duplicates, i.e. - * seek points with identical \a sample_number values. Duplicate seek - * points are converted into placeholder points and sorted to the end of - * the table. - * - * \param seek_table A pointer to a seek table to be sorted. - * \assert - * \code seek_table != NULL \endcode - * \retval uint32_t - * The number of duplicate seek points converted into placeholders. - */ -FLAC_API uint32_t FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table); - -/** Check a cue sheet to see if it conforms to the FLAC specification. - * See the format specification for limits on the contents of the - * cue sheet. - * - * \param cue_sheet A pointer to an existing cue sheet to be checked. - * \param check_cd_da_subset If \c true, check CUESHEET against more - * stringent requirements for a CD-DA (audio) disc. - * \param violation Address of a pointer to a string. If there is a - * violation, a pointer to a string explanation of the - * violation will be returned here. \a violation may be - * \c NULL if you don't need the returned string. Do not - * free the returned string; it will always point to static - * data. - * \assert - * \code cue_sheet != NULL \endcode - * \retval FLAC__bool - * \c false if cue sheet is illegal, else \c true. - */ -FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation); - -/** Check picture data to see if it conforms to the FLAC specification. - * See the format specification for limits on the contents of the - * PICTURE block. - * - * \param picture A pointer to existing picture data to be checked. - * \param violation Address of a pointer to a string. If there is a - * violation, a pointer to a string explanation of the - * violation will be returned here. \a violation may be - * \c NULL if you don't need the returned string. Do not - * free the returned string; it will always point to static - * data. - * \assert - * \code picture != NULL \endcode - * \retval FLAC__bool - * \c false if picture data is illegal, else \c true. - */ -FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation); - -/* \} */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flac/include/FLAC/metadata.h b/flac/include/FLAC/metadata.h deleted file mode 100644 index 4747a5f..0000000 --- a/flac/include/FLAC/metadata.h +++ /dev/null @@ -1,2234 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__METADATA_H -#define FLAC__METADATA_H - -#include /* for off_t */ -#include "export.h" -#include "callback.h" -#include "format.h" - -/* -------------------------------------------------------------------- - (For an example of how all these routines are used, see the source - code for the unit tests in src/test_libFLAC/metadata_*.c, or - metaflac in src/metaflac/) - ------------------------------------------------------------------*/ - -/** \file include/FLAC/metadata.h - * - * \brief - * This module provides functions for creating and manipulating FLAC - * metadata blocks in memory, and three progressively more powerful - * interfaces for traversing and editing metadata in FLAC files. - * - * See the detailed documentation for each interface in the - * \link flac_metadata metadata \endlink module. - */ - -/** \defgroup flac_metadata FLAC/metadata.h: metadata interfaces - * \ingroup flac - * - * \brief - * This module provides functions for creating and manipulating FLAC - * metadata blocks in memory, and three progressively more powerful - * interfaces for traversing and editing metadata in native FLAC files. - * Note that currently only the Chain interface (level 2) supports Ogg - * FLAC files, and it is read-only i.e. no writing back changed - * metadata to file. - * - * There are three metadata interfaces of increasing complexity: - * - * Level 0: - * Read-only access to the STREAMINFO, VORBIS_COMMENT, CUESHEET, and - * PICTURE blocks. - * - * Level 1: - * Read-write access to all metadata blocks. This level is write- - * efficient in most cases (more on this below), and uses less memory - * than level 2. - * - * Level 2: - * Read-write access to all metadata blocks. This level is write- - * efficient in all cases, but uses more memory since all metadata for - * the whole file is read into memory and manipulated before writing - * out again. - * - * What do we mean by efficient? Since FLAC metadata appears at the - * beginning of the file, when writing metadata back to a FLAC file - * it is possible to grow or shrink the metadata such that the entire - * file must be rewritten. However, if the size remains the same during - * changes or PADDING blocks are utilized, only the metadata needs to be - * overwritten, which is much faster. - * - * Efficient means the whole file is rewritten at most one time, and only - * when necessary. Level 1 is not efficient only in the case that you - * cause more than one metadata block to grow or shrink beyond what can - * be accommodated by padding. In this case you should probably use level - * 2, which allows you to edit all the metadata for a file in memory and - * write it out all at once. - * - * All levels know how to skip over and not disturb an ID3v2 tag at the - * front of the file. - * - * All levels access files via their filenames. In addition, level 2 - * has additional alternative read and write functions that take an I/O - * handle and callbacks, for situations where access by filename is not - * possible. - * - * In addition to the three interfaces, this module defines functions for - * creating and manipulating various metadata objects in memory. As we see - * from the Format module, FLAC metadata blocks in memory are very primitive - * structures for storing information in an efficient way. Reading - * information from the structures is easy but creating or modifying them - * directly is more complex. The metadata object routines here facilitate - * this by taking care of the consistency and memory management drudgery. - * - * Unless you will be using the level 1 or 2 interfaces to modify existing - * metadata however, you will not probably not need these. - * - * From a dependency standpoint, none of the encoders or decoders require - * the metadata module. This is so that embedded users can strip out the - * metadata module from libFLAC to reduce the size and complexity. - */ - -#ifdef __cplusplus -extern "C" { -#endif - - -/** \defgroup flac_metadata_level0 FLAC/metadata.h: metadata level 0 interface - * \ingroup flac_metadata - * - * \brief - * The level 0 interface consists of individual routines to read the - * STREAMINFO, VORBIS_COMMENT, CUESHEET, and PICTURE blocks, requiring - * only a filename. - * - * On Windows, filename must be a UTF-8 encoded filename, which libFLAC - * internally translates to an appropriate representation to use with - * _wfopen. On all other systems, filename is passed to fopen without - * any translation. - * - * They try to skip any ID3v2 tag at the head of the file. - * - * \{ - */ - -/** Read the STREAMINFO metadata block of the given FLAC file. This function - * will try to skip any ID3v2 tag at the head of the file. - * - * \param filename The path to the FLAC file to read. - * \param streaminfo A pointer to space for the STREAMINFO block. Since - * FLAC__StreamMetadata is a simple structure with no - * memory allocation involved, you pass the address of - * an existing structure. It need not be initialized. - * \assert - * \code filename != NULL \endcode - * \code streaminfo != NULL \endcode - * \retval FLAC__bool - * \c true if a valid STREAMINFO block was read from \a filename. Returns - * \c false if there was a memory allocation error, a file decoder error, - * or the file contained no STREAMINFO block. (A memory allocation error - * is possible because this function must set up a file decoder.) - */ -FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo); - -/** Read the VORBIS_COMMENT metadata block of the given FLAC file. This - * function will try to skip any ID3v2 tag at the head of the file. - * - * \param filename The path to the FLAC file to read. - * \param tags The address where the returned pointer will be - * stored. The \a tags object must be deleted by - * the caller using FLAC__metadata_object_delete(). - * \assert - * \code filename != NULL \endcode - * \code tags != NULL \endcode - * \retval FLAC__bool - * \c true if a valid VORBIS_COMMENT block was read from \a filename, - * and \a *tags will be set to the address of the metadata structure. - * Returns \c false if there was a memory allocation error, a file - * decoder error, or the file contained no VORBIS_COMMENT block, and - * \a *tags will be set to \c NULL. - */ -FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags); - -/** Read the CUESHEET metadata block of the given FLAC file. This - * function will try to skip any ID3v2 tag at the head of the file. - * - * \param filename The path to the FLAC file to read. - * \param cuesheet The address where the returned pointer will be - * stored. The \a cuesheet object must be deleted by - * the caller using FLAC__metadata_object_delete(). - * \assert - * \code filename != NULL \endcode - * \code cuesheet != NULL \endcode - * \retval FLAC__bool - * \c true if a valid CUESHEET block was read from \a filename, - * and \a *cuesheet will be set to the address of the metadata - * structure. Returns \c false if there was a memory allocation - * error, a file decoder error, or the file contained no CUESHEET - * block, and \a *cuesheet will be set to \c NULL. - */ -FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet); - -/** Read a PICTURE metadata block of the given FLAC file. This - * function will try to skip any ID3v2 tag at the head of the file. - * Since there can be more than one PICTURE block in a file, this - * function takes a number of parameters that act as constraints to - * the search. The PICTURE block with the largest area matching all - * the constraints will be returned, or \a *picture will be set to - * \c NULL if there was no such block. - * - * \param filename The path to the FLAC file to read. - * \param picture The address where the returned pointer will be - * stored. The \a picture object must be deleted by - * the caller using FLAC__metadata_object_delete(). - * \param type The desired picture type. Use \c -1 to mean - * "any type". - * \param mime_type The desired MIME type, e.g. "image/jpeg". The - * string will be matched exactly. Use \c NULL to - * mean "any MIME type". - * \param description The desired description. The string will be - * matched exactly. Use \c NULL to mean "any - * description". - * \param max_width The maximum width in pixels desired. Use - * \c (uint32_t)(-1) to mean "any width". - * \param max_height The maximum height in pixels desired. Use - * \c (uint32_t)(-1) to mean "any height". - * \param max_depth The maximum color depth in bits-per-pixel desired. - * Use \c (uint32_t)(-1) to mean "any depth". - * \param max_colors The maximum number of colors desired. Use - * \c (uint32_t)(-1) to mean "any number of colors". - * \assert - * \code filename != NULL \endcode - * \code picture != NULL \endcode - * \retval FLAC__bool - * \c true if a valid PICTURE block was read from \a filename, - * and \a *picture will be set to the address of the metadata - * structure. Returns \c false if there was a memory allocation - * error, a file decoder error, or the file contained no PICTURE - * block, and \a *picture will be set to \c NULL. - */ -FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors); - -/* \} */ - - -/** \defgroup flac_metadata_level1 FLAC/metadata.h: metadata level 1 interface - * \ingroup flac_metadata - * - * \brief - * The level 1 interface provides read-write access to FLAC file metadata and - * operates directly on the FLAC file. - * - * The general usage of this interface is: - * - * - Create an iterator using FLAC__metadata_simple_iterator_new() - * - Attach it to a file using FLAC__metadata_simple_iterator_init() and check - * the exit code. Call FLAC__metadata_simple_iterator_is_writable() to - * see if the file is writable, or only read access is allowed. - * - Use FLAC__metadata_simple_iterator_next() and - * FLAC__metadata_simple_iterator_prev() to traverse the blocks. - * This is does not read the actual blocks themselves. - * FLAC__metadata_simple_iterator_next() is relatively fast. - * FLAC__metadata_simple_iterator_prev() is slower since it needs to search - * forward from the front of the file. - * - Use FLAC__metadata_simple_iterator_get_block_type() or - * FLAC__metadata_simple_iterator_get_block() to access the actual data at - * the current iterator position. The returned object is yours to modify - * and free. - * - Use FLAC__metadata_simple_iterator_set_block() to write a modified block - * back. You must have write permission to the original file. Make sure to - * read the whole comment to FLAC__metadata_simple_iterator_set_block() - * below. - * - Use FLAC__metadata_simple_iterator_insert_block_after() to add new blocks. - * Use the object creation functions from - * \link flac_metadata_object here \endlink to generate new objects. - * - Use FLAC__metadata_simple_iterator_delete_block() to remove the block - * currently referred to by the iterator, or replace it with padding. - * - Destroy the iterator with FLAC__metadata_simple_iterator_delete() when - * finished. - * - * \note - * The FLAC file remains open the whole time between - * FLAC__metadata_simple_iterator_init() and - * FLAC__metadata_simple_iterator_delete(), so make sure you are not altering - * the file during this time. - * - * \note - * Do not modify the \a is_last, \a length, or \a type fields of returned - * FLAC__StreamMetadata objects. These are managed automatically. - * - * \note - * If any of the modification functions - * (FLAC__metadata_simple_iterator_set_block(), - * FLAC__metadata_simple_iterator_delete_block(), - * FLAC__metadata_simple_iterator_insert_block_after(), etc.) return \c false, - * you should delete the iterator as it may no longer be valid. - * - * \{ - */ - -struct FLAC__Metadata_SimpleIterator; -/** The opaque structure definition for the level 1 iterator type. - * See the - * \link flac_metadata_level1 metadata level 1 module \endlink - * for a detailed description. - */ -typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator; - -/** Status type for FLAC__Metadata_SimpleIterator. - * - * The iterator's current status can be obtained by calling FLAC__metadata_simple_iterator_status(). - */ -typedef enum { - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0, - /**< The iterator is in the normal OK state */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT, - /**< The data passed into a function violated the function's usage criteria */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE, - /**< The iterator could not open the target file */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE, - /**< The iterator could not find the FLAC signature at the start of the file */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE, - /**< The iterator tried to write to a file that was not writable */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA, - /**< The iterator encountered input that does not conform to the FLAC metadata specification */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR, - /**< The iterator encountered an error while reading the FLAC file */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR, - /**< The iterator encountered an error while seeking in the FLAC file */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR, - /**< The iterator encountered an error while writing the FLAC file */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR, - /**< The iterator encountered an error renaming the FLAC file */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR, - /**< The iterator encountered an error removing the temporary file */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR, - /**< Memory allocation failed */ - - FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR - /**< The caller violated an assertion or an unexpected error occurred */ - -} FLAC__Metadata_SimpleIteratorStatus; - -/** Maps a FLAC__Metadata_SimpleIteratorStatus to a C string. - * - * Using a FLAC__Metadata_SimpleIteratorStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[]; - - -/** Create a new iterator instance. - * - * \retval FLAC__Metadata_SimpleIterator* - * \c NULL if there was an error allocating memory, else the new instance. - */ -FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void); - -/** Free an iterator instance. Deletes the object pointed to by \a iterator. - * - * \param iterator A pointer to an existing iterator. - * \assert - * \code iterator != NULL \endcode - */ -FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator); - -/** Get the current status of the iterator. Call this after a function - * returns \c false to get the reason for the error. Also resets the status - * to FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK. - * - * \param iterator A pointer to an existing iterator. - * \assert - * \code iterator != NULL \endcode - * \retval FLAC__Metadata_SimpleIteratorStatus - * The current status of the iterator. - */ -FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator); - -/** Initialize the iterator to point to the first metadata block in the - * given FLAC file. - * - * On Windows, filename must be a UTF-8 encoded filename, which libFLAC - * internally translates to an appropriate representation to use with - * _wfopen. On all other systems, filename is passed to fopen without - * any translation. - * - * \param iterator A pointer to an existing iterator. - * \param filename The path to the FLAC file. - * \param read_only If \c true, the FLAC file will be opened - * in read-only mode; if \c false, the FLAC - * file will be opened for edit even if no - * edits are performed. - * \param preserve_file_stats If \c true, the owner and modification - * time will be preserved even if the FLAC - * file is written to. - * \assert - * \code iterator != NULL \endcode - * \code filename != NULL \endcode - * \retval FLAC__bool - * \c false if a memory allocation error occurs, the file can't be - * opened, or another error occurs, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool read_only, FLAC__bool preserve_file_stats); - -/** Returns \c true if the FLAC file is writable. If \c false, calls to - * FLAC__metadata_simple_iterator_set_block() and - * FLAC__metadata_simple_iterator_insert_block_after() will fail. - * - * \param iterator A pointer to an existing iterator. - * \assert - * \code iterator != NULL \endcode - * \retval FLAC__bool - * See above. - */ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator); - -/** Moves the iterator forward one metadata block, returning \c false if - * already at the end. - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \retval FLAC__bool - * \c false if already at the last metadata block of the chain, else - * \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator); - -/** Moves the iterator backward one metadata block, returning \c false if - * already at the beginning. - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \retval FLAC__bool - * \c false if already at the first metadata block of the chain, else - * \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator); - -/** Returns a flag telling if the current metadata block is the last. - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \retval FLAC__bool - * \c true if the current metadata block is the last in the file, - * else \c false. - */ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator); - -/** Get the offset of the metadata block at the current position. This - * avoids reading the actual block data which can save time for large - * blocks. - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \retval off_t - * The offset of the metadata block at the current iterator position. - * This is the byte offset relative to the beginning of the file of - * the current metadata block's header. - */ -FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator); - -/** Get the type of the metadata block at the current position. This - * avoids reading the actual block data which can save time for large - * blocks. - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \retval FLAC__MetadataType - * The type of the metadata block at the current iterator position. - */ -FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator); - -/** Get the length of the metadata block at the current position. This - * avoids reading the actual block data which can save time for large - * blocks. - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \retval uint32_t - * The length of the metadata block at the current iterator position. - * The is same length as that in the - * metadata block header, - * i.e. the length of the metadata body that follows the header. - */ -FLAC_API uint32_t FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator); - -/** Get the application ID of the \c APPLICATION block at the current - * position. This avoids reading the actual block data which can save - * time for large blocks. - * - * \param iterator A pointer to an existing initialized iterator. - * \param id A pointer to a buffer of at least \c 4 bytes where - * the ID will be stored. - * \assert - * \code iterator != NULL \endcode - * \code id != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \retval FLAC__bool - * \c true if the ID was successfully read, else \c false, in which - * case you should check FLAC__metadata_simple_iterator_status() to - * find out why. If the status is - * \c FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT, then the - * current metadata block is not an \c APPLICATION block. Otherwise - * if the status is - * \c FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR or - * \c FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR, an I/O error - * occurred and the iterator can no longer be used. - */ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id); - -/** Get the metadata block at the current position. You can modify the - * block but must use FLAC__metadata_simple_iterator_set_block() to - * write it back to the FLAC file. - * - * You must call FLAC__metadata_object_delete() on the returned object - * when you are finished with it. - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \retval FLAC__StreamMetadata* - * The current metadata block, or \c NULL if there was a memory - * allocation error. - */ -FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator); - -/** Write a block back to the FLAC file. This function tries to be - * as efficient as possible; how the block is actually written is - * shown by the following: - * - * Existing block is a STREAMINFO block and the new block is a - * STREAMINFO block: the new block is written in place. Make sure - * you know what you're doing when changing the values of a - * STREAMINFO block. - * - * Existing block is a STREAMINFO block and the new block is a - * not a STREAMINFO block: this is an error since the first block - * must be a STREAMINFO block. Returns \c false without altering the - * file. - * - * Existing block is not a STREAMINFO block and the new block is a - * STREAMINFO block: this is an error since there may be only one - * STREAMINFO block. Returns \c false without altering the file. - * - * Existing block and new block are the same length: the existing - * block will be replaced by the new block, written in place. - * - * Existing block is longer than new block: if use_padding is \c true, - * the existing block will be overwritten in place with the new - * block followed by a PADDING block, if possible, to make the total - * size the same as the existing block. Remember that a padding - * block requires at least four bytes so if the difference in size - * between the new block and existing block is less than that, the - * entire file will have to be rewritten, using the new block's - * exact size. If use_padding is \c false, the entire file will be - * rewritten, replacing the existing block by the new block. - * - * Existing block is shorter than new block: if use_padding is \c true, - * the function will try and expand the new block into the following - * PADDING block, if it exists and doing so won't shrink the PADDING - * block to less than 4 bytes. If there is no following PADDING - * block, or it will shrink to less than 4 bytes, or use_padding is - * \c false, the entire file is rewritten, replacing the existing block - * with the new block. Note that in this case any following PADDING - * block is preserved as is. - * - * After writing the block, the iterator will remain in the same - * place, i.e. pointing to the new block. - * - * \param iterator A pointer to an existing initialized iterator. - * \param block The block to set. - * \param use_padding See above. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \code block != NULL \endcode - * \retval FLAC__bool - * \c true if successful, else \c false. - */ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding); - -/** This is similar to FLAC__metadata_simple_iterator_set_block() - * except that instead of writing over an existing block, it appends - * a block after the existing block. \a use_padding is again used to - * tell the function to try an expand into following padding in an - * attempt to avoid rewriting the entire file. - * - * This function will fail and return \c false if given a STREAMINFO - * block. - * - * After writing the block, the iterator will be pointing to the - * new block. - * - * \param iterator A pointer to an existing initialized iterator. - * \param block The block to set. - * \param use_padding See above. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \code block != NULL \endcode - * \retval FLAC__bool - * \c true if successful, else \c false. - */ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding); - -/** Deletes the block at the current position. This will cause the - * entire FLAC file to be rewritten, unless \a use_padding is \c true, - * in which case the block will be replaced by an equal-sized PADDING - * block. The iterator will be left pointing to the block before the - * one just deleted. - * - * You may not delete the STREAMINFO block. - * - * \param iterator A pointer to an existing initialized iterator. - * \param use_padding See above. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_simple_iterator_init() - * \retval FLAC__bool - * \c true if successful, else \c false. - */ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding); - -/* \} */ - - -/** \defgroup flac_metadata_level2 FLAC/metadata.h: metadata level 2 interface - * \ingroup flac_metadata - * - * \brief - * The level 2 interface provides read-write access to FLAC file metadata; - * all metadata is read into memory, operated on in memory, and then written - * to file, which is more efficient than level 1 when editing multiple blocks. - * - * Currently Ogg FLAC is supported for read only, via - * FLAC__metadata_chain_read_ogg() but a subsequent - * FLAC__metadata_chain_write() will fail. - * - * The general usage of this interface is: - * - * - Create a new chain using FLAC__metadata_chain_new(). A chain is a - * linked list of FLAC metadata blocks. - * - Read all metadata into the chain from a FLAC file using - * FLAC__metadata_chain_read() or FLAC__metadata_chain_read_ogg() and - * check the status. - * - Optionally, consolidate the padding using - * FLAC__metadata_chain_merge_padding() or - * FLAC__metadata_chain_sort_padding(). - * - Create a new iterator using FLAC__metadata_iterator_new() - * - Initialize the iterator to point to the first element in the chain - * using FLAC__metadata_iterator_init() - * - Traverse the chain using FLAC__metadata_iterator_next and - * FLAC__metadata_iterator_prev(). - * - Get a block for reading or modification using - * FLAC__metadata_iterator_get_block(). The pointer to the object - * inside the chain is returned, so the block is yours to modify. - * Changes will be reflected in the FLAC file when you write the - * chain. You can also add and delete blocks (see functions below). - * - When done, write out the chain using FLAC__metadata_chain_write(). - * Make sure to read the whole comment to the function below. - * - Delete the chain using FLAC__metadata_chain_delete(). - * - * \note - * Even though the FLAC file is not open while the chain is being - * manipulated, you must not alter the file externally during - * this time. The chain assumes the FLAC file will not change - * between the time of FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg() - * and FLAC__metadata_chain_write(). - * - * \note - * Do not modify the is_last, length, or type fields of returned - * FLAC__StreamMetadata objects. These are managed automatically. - * - * \note - * The metadata objects returned by FLAC__metadata_iterator_get_block() - * are owned by the chain; do not FLAC__metadata_object_delete() them. - * In the same way, blocks passed to FLAC__metadata_iterator_set_block() - * become owned by the chain and they will be deleted when the chain is - * deleted. - * - * \{ - */ - -struct FLAC__Metadata_Chain; -/** The opaque structure definition for the level 2 chain type. - */ -typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain; - -struct FLAC__Metadata_Iterator; -/** The opaque structure definition for the level 2 iterator type. - */ -typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator; - -typedef enum { - FLAC__METADATA_CHAIN_STATUS_OK = 0, - /**< The chain is in the normal OK state */ - - FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT, - /**< The data passed into a function violated the function's usage criteria */ - - FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE, - /**< The chain could not open the target file */ - - FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE, - /**< The chain could not find the FLAC signature at the start of the file */ - - FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE, - /**< The chain tried to write to a file that was not writable */ - - FLAC__METADATA_CHAIN_STATUS_BAD_METADATA, - /**< The chain encountered input that does not conform to the FLAC metadata specification */ - - FLAC__METADATA_CHAIN_STATUS_READ_ERROR, - /**< The chain encountered an error while reading the FLAC file */ - - FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR, - /**< The chain encountered an error while seeking in the FLAC file */ - - FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR, - /**< The chain encountered an error while writing the FLAC file */ - - FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR, - /**< The chain encountered an error renaming the FLAC file */ - - FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR, - /**< The chain encountered an error removing the temporary file */ - - FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR, - /**< Memory allocation failed */ - - FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR, - /**< The caller violated an assertion or an unexpected error occurred */ - - FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS, - /**< One or more of the required callbacks was NULL */ - - FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH, - /**< FLAC__metadata_chain_write() was called on a chain read by - * FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(), - * or - * FLAC__metadata_chain_write_with_callbacks()/FLAC__metadata_chain_write_with_callbacks_and_tempfile() - * was called on a chain read by - * FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(). - * Matching read/write methods must always be used. */ - - FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL - /**< FLAC__metadata_chain_write_with_callbacks() was called when the - * chain write requires a tempfile; use - * FLAC__metadata_chain_write_with_callbacks_and_tempfile() instead. - * Or, FLAC__metadata_chain_write_with_callbacks_and_tempfile() was - * called when the chain write does not require a tempfile; use - * FLAC__metadata_chain_write_with_callbacks() instead. - * Always check FLAC__metadata_chain_check_if_tempfile_needed() - * before writing via callbacks. */ - -} FLAC__Metadata_ChainStatus; - -/** Maps a FLAC__Metadata_ChainStatus to a C string. - * - * Using a FLAC__Metadata_ChainStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[]; - -/*********** FLAC__Metadata_Chain ***********/ - -/** Create a new chain instance. - * - * \retval FLAC__Metadata_Chain* - * \c NULL if there was an error allocating memory, else the new instance. - */ -FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void); - -/** Free a chain instance. Deletes the object pointed to by \a chain. - * - * \param chain A pointer to an existing chain. - * \assert - * \code chain != NULL \endcode - */ -FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain); - -/** Get the current status of the chain. Call this after a function - * returns \c false to get the reason for the error. Also resets the - * status to FLAC__METADATA_CHAIN_STATUS_OK. - * - * \param chain A pointer to an existing chain. - * \assert - * \code chain != NULL \endcode - * \retval FLAC__Metadata_ChainStatus - * The current status of the chain. - */ -FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain); - -/** Read all metadata from a FLAC file into the chain. - * - * On Windows, filename must be a UTF-8 encoded filename, which libFLAC - * internally translates to an appropriate representation to use with - * _wfopen. On all other systems, filename is passed to fopen without - * any translation. - * - * \param chain A pointer to an existing chain. - * \param filename The path to the FLAC file to read. - * \assert - * \code chain != NULL \endcode - * \code filename != NULL \endcode - * \retval FLAC__bool - * \c true if a valid list of metadata blocks was read from - * \a filename, else \c false. On failure, check the status with - * FLAC__metadata_chain_status(). - */ -FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename); - -/** Read all metadata from an Ogg FLAC file into the chain. - * - * On Windows, filename must be a UTF-8 encoded filename, which libFLAC - * internally translates to an appropriate representation to use with - * _wfopen. On all other systems, filename is passed to fopen without - * any translation. - * - * \note Ogg FLAC metadata data writing is not supported yet and - * FLAC__metadata_chain_write() will fail. - * - * \param chain A pointer to an existing chain. - * \param filename The path to the Ogg FLAC file to read. - * \assert - * \code chain != NULL \endcode - * \code filename != NULL \endcode - * \retval FLAC__bool - * \c true if a valid list of metadata blocks was read from - * \a filename, else \c false. On failure, check the status with - * FLAC__metadata_chain_status(). - */ -FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename); - -/** Read all metadata from a FLAC stream into the chain via I/O callbacks. - * - * The \a handle need only be open for reading, but must be seekable. - * The equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb" - * for Windows). - * - * \param chain A pointer to an existing chain. - * \param handle The I/O handle of the FLAC stream to read. The - * handle will NOT be closed after the metadata is read; - * that is the duty of the caller. - * \param callbacks - * A set of callbacks to use for I/O. The mandatory - * callbacks are \a read, \a seek, and \a tell. - * \assert - * \code chain != NULL \endcode - * \retval FLAC__bool - * \c true if a valid list of metadata blocks was read from - * \a handle, else \c false. On failure, check the status with - * FLAC__metadata_chain_status(). - */ -FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks); - -/** Read all metadata from an Ogg FLAC stream into the chain via I/O callbacks. - * - * The \a handle need only be open for reading, but must be seekable. - * The equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb" - * for Windows). - * - * \note Ogg FLAC metadata data writing is not supported yet and - * FLAC__metadata_chain_write() will fail. - * - * \param chain A pointer to an existing chain. - * \param handle The I/O handle of the Ogg FLAC stream to read. The - * handle will NOT be closed after the metadata is read; - * that is the duty of the caller. - * \param callbacks - * A set of callbacks to use for I/O. The mandatory - * callbacks are \a read, \a seek, and \a tell. - * \assert - * \code chain != NULL \endcode - * \retval FLAC__bool - * \c true if a valid list of metadata blocks was read from - * \a handle, else \c false. On failure, check the status with - * FLAC__metadata_chain_status(). - */ -FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks); - -/** Checks if writing the given chain would require the use of a - * temporary file, or if it could be written in place. - * - * Under certain conditions, padding can be utilized so that writing - * edited metadata back to the FLAC file does not require rewriting the - * entire file. If rewriting is required, then a temporary workfile is - * required. When writing metadata using callbacks, you must check - * this function to know whether to call - * FLAC__metadata_chain_write_with_callbacks() or - * FLAC__metadata_chain_write_with_callbacks_and_tempfile(). When - * writing with FLAC__metadata_chain_write(), the temporary file is - * handled internally. - * - * \param chain A pointer to an existing chain. - * \param use_padding - * Whether or not padding will be allowed to be used - * during the write. The value of \a use_padding given - * here must match the value later passed to - * FLAC__metadata_chain_write_with_callbacks() or - * FLAC__metadata_chain_write_with_callbacks_with_tempfile(). - * \assert - * \code chain != NULL \endcode - * \retval FLAC__bool - * \c true if writing the current chain would require a tempfile, or - * \c false if metadata can be written in place. - */ -FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding); - -/** Write all metadata out to the FLAC file. This function tries to be as - * efficient as possible; how the metadata is actually written is shown by - * the following: - * - * If the current chain is the same size as the existing metadata, the new - * data is written in place. - * - * If the current chain is longer than the existing metadata, and - * \a use_padding is \c true, and the last block is a PADDING block of - * sufficient length, the function will truncate the final padding block - * so that the overall size of the metadata is the same as the existing - * metadata, and then just rewrite the metadata. Otherwise, if not all of - * the above conditions are met, the entire FLAC file must be rewritten. - * If you want to use padding this way it is a good idea to call - * FLAC__metadata_chain_sort_padding() first so that you have the maximum - * amount of padding to work with, unless you need to preserve ordering - * of the PADDING blocks for some reason. - * - * If the current chain is shorter than the existing metadata, and - * \a use_padding is \c true, and the final block is a PADDING block, the padding - * is extended to make the overall size the same as the existing data. If - * \a use_padding is \c true and the last block is not a PADDING block, a new - * PADDING block is added to the end of the new data to make it the same - * size as the existing data (if possible, see the note to - * FLAC__metadata_simple_iterator_set_block() about the four byte limit) - * and the new data is written in place. If none of the above apply or - * \a use_padding is \c false, the entire FLAC file is rewritten. - * - * If \a preserve_file_stats is \c true, the owner and modification time will - * be preserved even if the FLAC file is written. - * - * For this write function to be used, the chain must have been read with - * FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(), not - * FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(). - * - * \param chain A pointer to an existing chain. - * \param use_padding See above. - * \param preserve_file_stats See above. - * \assert - * \code chain != NULL \endcode - * \retval FLAC__bool - * \c true if the write succeeded, else \c false. On failure, - * check the status with FLAC__metadata_chain_status(). - */ -FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats); - -/** Write all metadata out to a FLAC stream via callbacks. - * - * (See FLAC__metadata_chain_write() for the details on how padding is - * used to write metadata in place if possible.) - * - * The \a handle must be open for updating and be seekable. The - * equivalent minimum stdio fopen() file mode is \c "r+" (or \c "r+b" - * for Windows). - * - * For this write function to be used, the chain must have been read with - * FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(), - * not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(). - * Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned - * \c false. - * - * \param chain A pointer to an existing chain. - * \param use_padding See FLAC__metadata_chain_write() - * \param handle The I/O handle of the FLAC stream to write. The - * handle will NOT be closed after the metadata is - * written; that is the duty of the caller. - * \param callbacks A set of callbacks to use for I/O. The mandatory - * callbacks are \a write and \a seek. - * \assert - * \code chain != NULL \endcode - * \retval FLAC__bool - * \c true if the write succeeded, else \c false. On failure, - * check the status with FLAC__metadata_chain_status(). - */ -FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks); - -/** Write all metadata out to a FLAC stream via callbacks. - * - * (See FLAC__metadata_chain_write() for the details on how padding is - * used to write metadata in place if possible.) - * - * This version of the write-with-callbacks function must be used when - * FLAC__metadata_chain_check_if_tempfile_needed() returns true. In - * this function, you must supply an I/O handle corresponding to the - * FLAC file to edit, and a temporary handle to which the new FLAC - * file will be written. It is the caller's job to move this temporary - * FLAC file on top of the original FLAC file to complete the metadata - * edit. - * - * The \a handle must be open for reading and be seekable. The - * equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb" - * for Windows). - * - * The \a temp_handle must be open for writing. The - * equivalent minimum stdio fopen() file mode is \c "w" (or \c "wb" - * for Windows). It should be an empty stream, or at least positioned - * at the start-of-file (in which case it is the caller's duty to - * truncate it on return). - * - * For this write function to be used, the chain must have been read with - * FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(), - * not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(). - * Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned - * \c true. - * - * \param chain A pointer to an existing chain. - * \param use_padding See FLAC__metadata_chain_write() - * \param handle The I/O handle of the original FLAC stream to read. - * The handle will NOT be closed after the metadata is - * written; that is the duty of the caller. - * \param callbacks A set of callbacks to use for I/O on \a handle. - * The mandatory callbacks are \a read, \a seek, and - * \a eof. - * \param temp_handle The I/O handle of the FLAC stream to write. The - * handle will NOT be closed after the metadata is - * written; that is the duty of the caller. - * \param temp_callbacks - * A set of callbacks to use for I/O on temp_handle. - * The only mandatory callback is \a write. - * \assert - * \code chain != NULL \endcode - * \retval FLAC__bool - * \c true if the write succeeded, else \c false. On failure, - * check the status with FLAC__metadata_chain_status(). - */ -FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__IOHandle temp_handle, FLAC__IOCallbacks temp_callbacks); - -/** Merge adjacent PADDING blocks into a single block. - * - * \note This function does not write to the FLAC file, it only - * modifies the chain. - * - * \warning Any iterator on the current chain will become invalid after this - * call. You should delete the iterator and get a new one. - * - * \param chain A pointer to an existing chain. - * \assert - * \code chain != NULL \endcode - */ -FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain); - -/** This function will move all PADDING blocks to the end on the metadata, - * then merge them into a single block. - * - * \note This function does not write to the FLAC file, it only - * modifies the chain. - * - * \warning Any iterator on the current chain will become invalid after this - * call. You should delete the iterator and get a new one. - * - * \param chain A pointer to an existing chain. - * \assert - * \code chain != NULL \endcode - */ -FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain); - - -/*********** FLAC__Metadata_Iterator ***********/ - -/** Create a new iterator instance. - * - * \retval FLAC__Metadata_Iterator* - * \c NULL if there was an error allocating memory, else the new instance. - */ -FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void); - -/** Free an iterator instance. Deletes the object pointed to by \a iterator. - * - * \param iterator A pointer to an existing iterator. - * \assert - * \code iterator != NULL \endcode - */ -FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator); - -/** Initialize the iterator to point to the first metadata block in the - * given chain. - * - * \param iterator A pointer to an existing iterator. - * \param chain A pointer to an existing and initialized (read) chain. - * \assert - * \code iterator != NULL \endcode - * \code chain != NULL \endcode - */ -FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain); - -/** Moves the iterator forward one metadata block, returning \c false if - * already at the end. - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_iterator_init() - * \retval FLAC__bool - * \c false if already at the last metadata block of the chain, else - * \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator); - -/** Moves the iterator backward one metadata block, returning \c false if - * already at the beginning. - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_iterator_init() - * \retval FLAC__bool - * \c false if already at the first metadata block of the chain, else - * \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator); - -/** Get the type of the metadata block at the current position. - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_iterator_init() - * \retval FLAC__MetadataType - * The type of the metadata block at the current iterator position. - */ -FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator); - -/** Get the metadata block at the current position. You can modify - * the block in place but must write the chain before the changes - * are reflected to the FLAC file. You do not need to call - * FLAC__metadata_iterator_set_block() to reflect the changes; - * the pointer returned by FLAC__metadata_iterator_get_block() - * points directly into the chain. - * - * \warning - * Do not call FLAC__metadata_object_delete() on the returned object; - * to delete a block use FLAC__metadata_iterator_delete_block(). - * - * \param iterator A pointer to an existing initialized iterator. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_iterator_init() - * \retval FLAC__StreamMetadata* - * The current metadata block. - */ -FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator); - -/** Set the metadata block at the current position, replacing the existing - * block. The new block passed in becomes owned by the chain and it will be - * deleted when the chain is deleted. - * - * \param iterator A pointer to an existing initialized iterator. - * \param block A pointer to a metadata block. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_iterator_init() - * \code block != NULL \endcode - * \retval FLAC__bool - * \c false if the conditions in the above description are not met, or - * a memory allocation error occurs, otherwise \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block); - -/** Removes the current block from the chain. If \a replace_with_padding is - * \c true, the block will instead be replaced with a padding block of equal - * size. You can not delete the STREAMINFO block. The iterator will be - * left pointing to the block before the one just "deleted", even if - * \a replace_with_padding is \c true. - * - * \param iterator A pointer to an existing initialized iterator. - * \param replace_with_padding See above. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_iterator_init() - * \retval FLAC__bool - * \c false if the conditions in the above description are not met, - * otherwise \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding); - -/** Insert a new block before the current block. You cannot insert a block - * before the first STREAMINFO block. You cannot insert a STREAMINFO block - * as there can be only one, the one that already exists at the head when you - * read in a chain. The chain takes ownership of the new block and it will be - * deleted when the chain is deleted. The iterator will be left pointing to - * the new block. - * - * \param iterator A pointer to an existing initialized iterator. - * \param block A pointer to a metadata block to insert. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_iterator_init() - * \retval FLAC__bool - * \c false if the conditions in the above description are not met, or - * a memory allocation error occurs, otherwise \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block); - -/** Insert a new block after the current block. You cannot insert a STREAMINFO - * block as there can be only one, the one that already exists at the head when - * you read in a chain. The chain takes ownership of the new block and it will - * be deleted when the chain is deleted. The iterator will be left pointing to - * the new block. - * - * \param iterator A pointer to an existing initialized iterator. - * \param block A pointer to a metadata block to insert. - * \assert - * \code iterator != NULL \endcode - * \a iterator has been successfully initialized with - * FLAC__metadata_iterator_init() - * \retval FLAC__bool - * \c false if the conditions in the above description are not met, or - * a memory allocation error occurs, otherwise \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block); - -/* \} */ - - -/** \defgroup flac_metadata_object FLAC/metadata.h: metadata object methods - * \ingroup flac_metadata - * - * \brief - * This module contains methods for manipulating FLAC metadata objects. - * - * Since many are variable length we have to be careful about the memory - * management. We decree that all pointers to data in the object are - * owned by the object and memory-managed by the object. - * - * Use the FLAC__metadata_object_new() and FLAC__metadata_object_delete() - * functions to create all instances. When using the - * FLAC__metadata_object_set_*() functions to set pointers to data, set - * \a copy to \c true to have the function make it's own copy of the data, or - * to \c false to give the object ownership of your data. In the latter case - * your pointer must be freeable by free() and will be free()d when the object - * is FLAC__metadata_object_delete()d. It is legal to pass a null pointer as - * the data pointer to a FLAC__metadata_object_set_*() function as long as - * the length argument is 0 and the \a copy argument is \c false. - * - * The FLAC__metadata_object_new() and FLAC__metadata_object_clone() function - * will return \c NULL in the case of a memory allocation error, otherwise a new - * object. The FLAC__metadata_object_set_*() functions return \c false in the - * case of a memory allocation error. - * - * We don't have the convenience of C++ here, so note that the library relies - * on you to keep the types straight. In other words, if you pass, for - * example, a FLAC__StreamMetadata* that represents a STREAMINFO block to - * FLAC__metadata_object_application_set_data(), you will get an assertion - * failure. - * - * For convenience the FLAC__metadata_object_vorbiscomment_*() functions - * maintain a trailing NUL on each Vorbis comment entry. This is not counted - * toward the length or stored in the stream, but it can make working with plain - * comments (those that don't contain embedded-NULs in the value) easier. - * Entries passed into these functions have trailing NULs added if missing, and - * returned entries are guaranteed to have a trailing NUL. - * - * The FLAC__metadata_object_vorbiscomment_*() functions that take a Vorbis - * comment entry/name/value will first validate that it complies with the Vorbis - * comment specification and return false if it does not. - * - * There is no need to recalculate the length field on metadata blocks you - * have modified. They will be calculated automatically before they are - * written back to a file. - * - * \{ - */ - - -/** Create a new metadata object instance of the given type. - * - * The object will be "empty"; i.e. values and data pointers will be \c 0, - * with the exception of FLAC__METADATA_TYPE_VORBIS_COMMENT, which will have - * the vendor string set (but zero comments). - * - * Do not pass in a value greater than or equal to - * \a FLAC__METADATA_TYPE_UNDEFINED unless you really know what you're - * doing. - * - * \param type Type of object to create - * \retval FLAC__StreamMetadata* - * \c NULL if there was an error allocating memory or the type code is - * greater than FLAC__MAX_METADATA_TYPE_CODE, else the new instance. - */ -FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type); - -/** Create a copy of an existing metadata object. - * - * The copy is a "deep" copy, i.e. dynamically allocated data within the - * object is also copied. The caller takes ownership of the new block and - * is responsible for freeing it with FLAC__metadata_object_delete(). - * - * \param object Pointer to object to copy. - * \assert - * \code object != NULL \endcode - * \retval FLAC__StreamMetadata* - * \c NULL if there was an error allocating memory, else the new instance. - */ -FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object); - -/** Free a metadata object. Deletes the object pointed to by \a object. - * - * The delete is a "deep" delete, i.e. dynamically allocated data within the - * object is also deleted. - * - * \param object A pointer to an existing object. - * \assert - * \code object != NULL \endcode - */ -FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object); - -/** Compares two metadata objects. - * - * The compare is "deep", i.e. dynamically allocated data within the - * object is also compared. - * - * \param block1 A pointer to an existing object. - * \param block2 A pointer to an existing object. - * \assert - * \code block1 != NULL \endcode - * \code block2 != NULL \endcode - * \retval FLAC__bool - * \c true if objects are identical, else \c false. - */ -FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2); - -/** Sets the application data of an APPLICATION block. - * - * If \a copy is \c true, a copy of the data is stored; otherwise, the object - * takes ownership of the pointer. The existing data will be freed if this - * function is successful, otherwise the original data will remain if \a copy - * is \c true and malloc() fails. - * - * \note It is safe to pass a const pointer to \a data if \a copy is \c true. - * - * \param object A pointer to an existing APPLICATION object. - * \param data A pointer to the data to set. - * \param length The length of \a data in bytes. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_APPLICATION \endcode - * \code (data != NULL && length > 0) || - * (data == NULL && length == 0 && copy == false) \endcode - * \retval FLAC__bool - * \c false if \a copy is \c true and malloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, uint32_t length, FLAC__bool copy); - -/** Resize the seekpoint array. - * - * If the size shrinks, elements will truncated; if it grows, new placeholder - * points will be added to the end. If this function returns false, the - * object is left untouched. - * - * \param object A pointer to an existing SEEKTABLE object. - * \param new_num_points The desired length of the array; may be \c 0. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \code (object->data.seek_table.points == NULL && object->data.seek_table.num_points == 0) || - * (object->data.seek_table.points != NULL && object->data.seek_table.num_points > 0) \endcode - * \retval FLAC__bool - * \c false if memory allocation error, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, uint32_t new_num_points); - -/** Set a seekpoint in a seektable. - * - * \param object A pointer to an existing SEEKTABLE object. - * \param point_num Index into seekpoint array to set. - * \param point The point to set. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \code object->data.seek_table.num_points > point_num \endcode - */ -FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, uint32_t point_num, FLAC__StreamMetadata_SeekPoint point); - -/** Insert a seekpoint into a seektable. - * - * \param object A pointer to an existing SEEKTABLE object. - * \param point_num Index into seekpoint array to set. - * \param point The point to set. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \code object->data.seek_table.num_points >= point_num \endcode - * \retval FLAC__bool - * \c false if memory allocation error, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, uint32_t point_num, FLAC__StreamMetadata_SeekPoint point); - -/** Delete a seekpoint from a seektable. - * - * \param object A pointer to an existing SEEKTABLE object. - * \param point_num Index into seekpoint array to set. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \code object->data.seek_table.num_points > point_num \endcode - * \retval FLAC__bool - * \c false if memory allocation error, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, uint32_t point_num); - -/** Check a seektable to see if it conforms to the FLAC specification. - * See the format specification for limits on the contents of the - * seektable. - * - * \param object A pointer to an existing SEEKTABLE object. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \retval FLAC__bool - * \c false if seek table is illegal, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object); - -/** Append a number of placeholder points to the end of a seek table. - * - * \note - * As with the other ..._seektable_template_... functions, you should - * call FLAC__metadata_object_seektable_template_sort() when finished - * to make the seek table legal. - * - * \param object A pointer to an existing SEEKTABLE object. - * \param num The number of placeholder points to append. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \retval FLAC__bool - * \c false if memory allocation fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, uint32_t num); - -/** Append a specific seek point template to the end of a seek table. - * - * \note - * As with the other ..._seektable_template_... functions, you should - * call FLAC__metadata_object_seektable_template_sort() when finished - * to make the seek table legal. - * - * \param object A pointer to an existing SEEKTABLE object. - * \param sample_number The sample number of the seek point template. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \retval FLAC__bool - * \c false if memory allocation fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number); - -/** Append specific seek point templates to the end of a seek table. - * - * \note - * As with the other ..._seektable_template_... functions, you should - * call FLAC__metadata_object_seektable_template_sort() when finished - * to make the seek table legal. - * - * \param object A pointer to an existing SEEKTABLE object. - * \param sample_numbers An array of sample numbers for the seek points. - * \param num The number of seek point templates to append. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \retval FLAC__bool - * \c false if memory allocation fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], uint32_t num); - -/** Append a set of evenly-spaced seek point templates to the end of a - * seek table. - * - * \note - * As with the other ..._seektable_template_... functions, you should - * call FLAC__metadata_object_seektable_template_sort() when finished - * to make the seek table legal. - * - * \param object A pointer to an existing SEEKTABLE object. - * \param num The number of placeholder points to append. - * \param total_samples The total number of samples to be encoded; - * the seekpoints will be spaced approximately - * \a total_samples / \a num samples apart. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \code total_samples > 0 \endcode - * \retval FLAC__bool - * \c false if memory allocation fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, uint32_t num, FLAC__uint64 total_samples); - -/** Append a set of evenly-spaced seek point templates to the end of a - * seek table. - * - * \note - * As with the other ..._seektable_template_... functions, you should - * call FLAC__metadata_object_seektable_template_sort() when finished - * to make the seek table legal. - * - * \param object A pointer to an existing SEEKTABLE object. - * \param samples The number of samples apart to space the placeholder - * points. The first point will be at sample \c 0, the - * second at sample \a samples, then 2*\a samples, and - * so on. As long as \a samples and \a total_samples - * are greater than \c 0, there will always be at least - * one seekpoint at sample \c 0. - * \param total_samples The total number of samples to be encoded; - * the seekpoints will be spaced - * \a samples samples apart. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \code samples > 0 \endcode - * \code total_samples > 0 \endcode - * \retval FLAC__bool - * \c false if memory allocation fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, uint32_t samples, FLAC__uint64 total_samples); - -/** Sort a seek table's seek points according to the format specification, - * removing duplicates. - * - * \param object A pointer to a seek table to be sorted. - * \param compact If \c false, behaves like FLAC__format_seektable_sort(). - * If \c true, duplicates are deleted and the seek table is - * shrunk appropriately; the number of placeholder points - * present in the seek table will be the same after the call - * as before. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_SEEKTABLE \endcode - * \retval FLAC__bool - * \c false if realloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact); - -/** Sets the vendor string in a VORBIS_COMMENT block. - * - * For convenience, a trailing NUL is added to the entry if it doesn't have - * one already. - * - * If \a copy is \c true, a copy of the entry is stored; otherwise, the object - * takes ownership of the \c entry.entry pointer. - * - * \note If this function returns \c false, the caller still owns the - * pointer. - * - * \param object A pointer to an existing VORBIS_COMMENT object. - * \param entry The entry to set the vendor string to. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode - * \code (entry.entry != NULL && entry.length > 0) || - * (entry.entry == NULL && entry.length == 0) \endcode - * \retval FLAC__bool - * \c false if memory allocation fails or \a entry does not comply with the - * Vorbis comment specification, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy); - -/** Resize the comment array. - * - * If the size shrinks, elements will truncated; if it grows, new empty - * fields will be added to the end. If this function returns false, the - * object is left untouched. - * - * \param object A pointer to an existing VORBIS_COMMENT object. - * \param new_num_comments The desired length of the array; may be \c 0. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode - * \code (object->data.vorbis_comment.comments == NULL && object->data.vorbis_comment.num_comments == 0) || - * (object->data.vorbis_comment.comments != NULL && object->data.vorbis_comment.num_comments > 0) \endcode - * \retval FLAC__bool - * \c false if memory allocation fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, uint32_t new_num_comments); - -/** Sets a comment in a VORBIS_COMMENT block. - * - * For convenience, a trailing NUL is added to the entry if it doesn't have - * one already. - * - * If \a copy is \c true, a copy of the entry is stored; otherwise, the object - * takes ownership of the \c entry.entry pointer. - * - * \note If this function returns \c false, the caller still owns the - * pointer. - * - * \param object A pointer to an existing VORBIS_COMMENT object. - * \param comment_num Index into comment array to set. - * \param entry The entry to set the comment to. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode - * \code comment_num < object->data.vorbis_comment.num_comments \endcode - * \code (entry.entry != NULL && entry.length > 0) || - * (entry.entry == NULL && entry.length == 0) \endcode - * \retval FLAC__bool - * \c false if memory allocation fails or \a entry does not comply with the - * Vorbis comment specification, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, uint32_t comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy); - -/** Insert a comment in a VORBIS_COMMENT block at the given index. - * - * For convenience, a trailing NUL is added to the entry if it doesn't have - * one already. - * - * If \a copy is \c true, a copy of the entry is stored; otherwise, the object - * takes ownership of the \c entry.entry pointer. - * - * \note If this function returns \c false, the caller still owns the - * pointer. - * - * \param object A pointer to an existing VORBIS_COMMENT object. - * \param comment_num The index at which to insert the comment. The comments - * at and after \a comment_num move right one position. - * To append a comment to the end, set \a comment_num to - * \c object->data.vorbis_comment.num_comments . - * \param entry The comment to insert. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode - * \code object->data.vorbis_comment.num_comments >= comment_num \endcode - * \code (entry.entry != NULL && entry.length > 0) || - * (entry.entry == NULL && entry.length == 0 && copy == false) \endcode - * \retval FLAC__bool - * \c false if memory allocation fails or \a entry does not comply with the - * Vorbis comment specification, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, uint32_t comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy); - -/** Appends a comment to a VORBIS_COMMENT block. - * - * For convenience, a trailing NUL is added to the entry if it doesn't have - * one already. - * - * If \a copy is \c true, a copy of the entry is stored; otherwise, the object - * takes ownership of the \c entry.entry pointer. - * - * \note If this function returns \c false, the caller still owns the - * pointer. - * - * \param object A pointer to an existing VORBIS_COMMENT object. - * \param entry The comment to insert. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode - * \code (entry.entry != NULL && entry.length > 0) || - * (entry.entry == NULL && entry.length == 0 && copy == false) \endcode - * \retval FLAC__bool - * \c false if memory allocation fails or \a entry does not comply with the - * Vorbis comment specification, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy); - -/** Replaces comments in a VORBIS_COMMENT block with a new one. - * - * For convenience, a trailing NUL is added to the entry if it doesn't have - * one already. - * - * Depending on the value of \a all, either all or just the first comment - * whose field name(s) match the given entry's name will be replaced by the - * given entry. If no comments match, \a entry will simply be appended. - * - * If \a copy is \c true, a copy of the entry is stored; otherwise, the object - * takes ownership of the \c entry.entry pointer. - * - * \note If this function returns \c false, the caller still owns the - * pointer. - * - * \param object A pointer to an existing VORBIS_COMMENT object. - * \param entry The comment to insert. - * \param all If \c true, all comments whose field name matches - * \a entry's field name will be removed, and \a entry will - * be inserted at the position of the first matching - * comment. If \c false, only the first comment whose - * field name matches \a entry's field name will be - * replaced with \a entry. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode - * \code (entry.entry != NULL && entry.length > 0) || - * (entry.entry == NULL && entry.length == 0 && copy == false) \endcode - * \retval FLAC__bool - * \c false if memory allocation fails or \a entry does not comply with the - * Vorbis comment specification, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy); - -/** Delete a comment in a VORBIS_COMMENT block at the given index. - * - * \param object A pointer to an existing VORBIS_COMMENT object. - * \param comment_num The index of the comment to delete. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode - * \code object->data.vorbis_comment.num_comments > comment_num \endcode - * \retval FLAC__bool - * \c false if realloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, uint32_t comment_num); - -/** Creates a Vorbis comment entry from NUL-terminated name and value strings. - * - * On return, the filled-in \a entry->entry pointer will point to malloc()ed - * memory and shall be owned by the caller. For convenience the entry will - * have a terminating NUL. - * - * \param entry A pointer to a Vorbis comment entry. The entry's - * \c entry pointer should not point to allocated - * memory as it will be overwritten. - * \param field_name The field name in ASCII, \c NUL terminated. - * \param field_value The field value in UTF-8, \c NUL terminated. - * \assert - * \code entry != NULL \endcode - * \code field_name != NULL \endcode - * \code field_value != NULL \endcode - * \retval FLAC__bool - * \c false if malloc() fails, or if \a field_name or \a field_value does - * not comply with the Vorbis comment specification, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field_name, const char *field_value); - -/** Splits a Vorbis comment entry into NUL-terminated name and value strings. - * - * The returned pointers to name and value will be allocated by malloc() - * and shall be owned by the caller. - * - * \param entry An existing Vorbis comment entry. - * \param field_name The address of where the returned pointer to the - * field name will be stored. - * \param field_value The address of where the returned pointer to the - * field value will be stored. - * \assert - * \code (entry.entry != NULL && entry.length > 0) \endcode - * \code memchr(entry.entry, '=', entry.length) != NULL \endcode - * \code field_name != NULL \endcode - * \code field_value != NULL \endcode - * \retval FLAC__bool - * \c false if memory allocation fails or \a entry does not comply with the - * Vorbis comment specification, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(const FLAC__StreamMetadata_VorbisComment_Entry entry, char **field_name, char **field_value); - -/** Check if the given Vorbis comment entry's field name matches the given - * field name. - * - * \param entry An existing Vorbis comment entry. - * \param field_name The field name to check. - * \param field_name_length The length of \a field_name, not including the - * terminating \c NUL. - * \assert - * \code (entry.entry != NULL && entry.length > 0) \endcode - * \retval FLAC__bool - * \c true if the field names match, else \c false - */ -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, uint32_t field_name_length); - -/** Find a Vorbis comment with the given field name. - * - * The search begins at entry number \a offset; use an offset of 0 to - * search from the beginning of the comment array. - * - * \param object A pointer to an existing VORBIS_COMMENT object. - * \param offset The offset into the comment array from where to start - * the search. - * \param field_name The field name of the comment to find. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode - * \code field_name != NULL \endcode - * \retval int - * The offset in the comment array of the first comment whose field - * name matches \a field_name, or \c -1 if no match was found. - */ -FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, uint32_t offset, const char *field_name); - -/** Remove first Vorbis comment matching the given field name. - * - * \param object A pointer to an existing VORBIS_COMMENT object. - * \param field_name The field name of comment to delete. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode - * \retval int - * \c -1 for memory allocation error, \c 0 for no matching entries, - * \c 1 for one matching entry deleted. - */ -FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name); - -/** Remove all Vorbis comments matching the given field name. - * - * \param object A pointer to an existing VORBIS_COMMENT object. - * \param field_name The field name of comments to delete. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT \endcode - * \retval int - * \c -1 for memory allocation error, \c 0 for no matching entries, - * else the number of matching entries deleted. - */ -FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name); - -/** Create a new CUESHEET track instance. - * - * The object will be "empty"; i.e. values and data pointers will be \c 0. - * - * \retval FLAC__StreamMetadata_CueSheet_Track* - * \c NULL if there was an error allocating memory, else the new instance. - */ -FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void); - -/** Create a copy of an existing CUESHEET track object. - * - * The copy is a "deep" copy, i.e. dynamically allocated data within the - * object is also copied. The caller takes ownership of the new object and - * is responsible for freeing it with - * FLAC__metadata_object_cuesheet_track_delete(). - * - * \param object Pointer to object to copy. - * \assert - * \code object != NULL \endcode - * \retval FLAC__StreamMetadata_CueSheet_Track* - * \c NULL if there was an error allocating memory, else the new instance. - */ -FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object); - -/** Delete a CUESHEET track object - * - * \param object A pointer to an existing CUESHEET track object. - * \assert - * \code object != NULL \endcode - */ -FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object); - -/** Resize a track's index point array. - * - * If the size shrinks, elements will truncated; if it grows, new blank - * indices will be added to the end. If this function returns false, the - * track object is left untouched. - * - * \param object A pointer to an existing CUESHEET object. - * \param track_num The index of the track to modify. NOTE: this is not - * necessarily the same as the track's \a number field. - * \param new_num_indices The desired length of the array; may be \c 0. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \code object->data.cue_sheet.num_tracks > track_num \endcode - * \code (object->data.cue_sheet.tracks[track_num].indices == NULL && object->data.cue_sheet.tracks[track_num].num_indices == 0) || - * (object->data.cue_sheet.tracks[track_num].indices != NULL && object->data.cue_sheet.tracks[track_num].num_indices > 0) \endcode - * \retval FLAC__bool - * \c false if memory allocation error, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t new_num_indices); - -/** Insert an index point in a CUESHEET track at the given index. - * - * \param object A pointer to an existing CUESHEET object. - * \param track_num The index of the track to modify. NOTE: this is not - * necessarily the same as the track's \a number field. - * \param index_num The index into the track's index array at which to - * insert the index point. NOTE: this is not necessarily - * the same as the index point's \a number field. The - * indices at and after \a index_num move right one - * position. To append an index point to the end, set - * \a index_num to - * \c object->data.cue_sheet.tracks[track_num].num_indices . - * \param index The index point to insert. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \code object->data.cue_sheet.num_tracks > track_num \endcode - * \code object->data.cue_sheet.tracks[track_num].num_indices >= index_num \endcode - * \retval FLAC__bool - * \c false if realloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num, FLAC__StreamMetadata_CueSheet_Index index); - -/** Insert a blank index point in a CUESHEET track at the given index. - * - * A blank index point is one in which all field values are zero. - * - * \param object A pointer to an existing CUESHEET object. - * \param track_num The index of the track to modify. NOTE: this is not - * necessarily the same as the track's \a number field. - * \param index_num The index into the track's index array at which to - * insert the index point. NOTE: this is not necessarily - * the same as the index point's \a number field. The - * indices at and after \a index_num move right one - * position. To append an index point to the end, set - * \a index_num to - * \c object->data.cue_sheet.tracks[track_num].num_indices . - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \code object->data.cue_sheet.num_tracks > track_num \endcode - * \code object->data.cue_sheet.tracks[track_num].num_indices >= index_num \endcode - * \retval FLAC__bool - * \c false if realloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num); - -/** Delete an index point in a CUESHEET track at the given index. - * - * \param object A pointer to an existing CUESHEET object. - * \param track_num The index into the track array of the track to - * modify. NOTE: this is not necessarily the same - * as the track's \a number field. - * \param index_num The index into the track's index array of the index - * to delete. NOTE: this is not necessarily the same - * as the index's \a number field. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \code object->data.cue_sheet.num_tracks > track_num \endcode - * \code object->data.cue_sheet.tracks[track_num].num_indices > index_num \endcode - * \retval FLAC__bool - * \c false if realloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num); - -/** Resize the track array. - * - * If the size shrinks, elements will truncated; if it grows, new blank - * tracks will be added to the end. If this function returns false, the - * object is left untouched. - * - * \param object A pointer to an existing CUESHEET object. - * \param new_num_tracks The desired length of the array; may be \c 0. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \code (object->data.cue_sheet.tracks == NULL && object->data.cue_sheet.num_tracks == 0) || - * (object->data.cue_sheet.tracks != NULL && object->data.cue_sheet.num_tracks > 0) \endcode - * \retval FLAC__bool - * \c false if memory allocation error, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, uint32_t new_num_tracks); - -/** Sets a track in a CUESHEET block. - * - * If \a copy is \c true, a copy of the track is stored; otherwise, the object - * takes ownership of the \a track pointer. - * - * \param object A pointer to an existing CUESHEET object. - * \param track_num Index into track array to set. NOTE: this is not - * necessarily the same as the track's \a number field. - * \param track The track to set the track to. You may safely pass in - * a const pointer if \a copy is \c true. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \code track_num < object->data.cue_sheet.num_tracks \endcode - * \code (track->indices != NULL && track->num_indices > 0) || - * (track->indices == NULL && track->num_indices == 0) \endcode - * \retval FLAC__bool - * \c false if \a copy is \c true and malloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, uint32_t track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy); - -/** Insert a track in a CUESHEET block at the given index. - * - * If \a copy is \c true, a copy of the track is stored; otherwise, the object - * takes ownership of the \a track pointer. - * - * \param object A pointer to an existing CUESHEET object. - * \param track_num The index at which to insert the track. NOTE: this - * is not necessarily the same as the track's \a number - * field. The tracks at and after \a track_num move right - * one position. To append a track to the end, set - * \a track_num to \c object->data.cue_sheet.num_tracks . - * \param track The track to insert. You may safely pass in a const - * pointer if \a copy is \c true. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \code object->data.cue_sheet.num_tracks >= track_num \endcode - * \retval FLAC__bool - * \c false if \a copy is \c true and malloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, uint32_t track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy); - -/** Insert a blank track in a CUESHEET block at the given index. - * - * A blank track is one in which all field values are zero. - * - * \param object A pointer to an existing CUESHEET object. - * \param track_num The index at which to insert the track. NOTE: this - * is not necessarily the same as the track's \a number - * field. The tracks at and after \a track_num move right - * one position. To append a track to the end, set - * \a track_num to \c object->data.cue_sheet.num_tracks . - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \code object->data.cue_sheet.num_tracks >= track_num \endcode - * \retval FLAC__bool - * \c false if \a copy is \c true and malloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, uint32_t track_num); - -/** Delete a track in a CUESHEET block at the given index. - * - * \param object A pointer to an existing CUESHEET object. - * \param track_num The index into the track array of the track to - * delete. NOTE: this is not necessarily the same - * as the track's \a number field. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \code object->data.cue_sheet.num_tracks > track_num \endcode - * \retval FLAC__bool - * \c false if realloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, uint32_t track_num); - -/** Check a cue sheet to see if it conforms to the FLAC specification. - * See the format specification for limits on the contents of the - * cue sheet. - * - * \param object A pointer to an existing CUESHEET object. - * \param check_cd_da_subset If \c true, check CUESHEET against more - * stringent requirements for a CD-DA (audio) disc. - * \param violation Address of a pointer to a string. If there is a - * violation, a pointer to a string explanation of the - * violation will be returned here. \a violation may be - * \c NULL if you don't need the returned string. Do not - * free the returned string; it will always point to static - * data. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \retval FLAC__bool - * \c false if cue sheet is illegal, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation); - -/** Calculate and return the CDDB/freedb ID for a cue sheet. The function - * assumes the cue sheet corresponds to a CD; the result is undefined - * if the cuesheet's is_cd bit is not set. - * - * \param object A pointer to an existing CUESHEET object. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_CUESHEET \endcode - * \retval FLAC__uint32 - * The unsigned integer representation of the CDDB/freedb ID - */ -FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object); - -/** Sets the MIME type of a PICTURE block. - * - * If \a copy is \c true, a copy of the string is stored; otherwise, the object - * takes ownership of the pointer. The existing string will be freed if this - * function is successful, otherwise the original string will remain if \a copy - * is \c true and malloc() fails. - * - * \note It is safe to pass a const pointer to \a mime_type if \a copy is \c true. - * - * \param object A pointer to an existing PICTURE object. - * \param mime_type A pointer to the MIME type string. The string must be - * ASCII characters 0x20-0x7e, NUL-terminated. No validation - * is done. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode - * \code (mime_type != NULL) \endcode - * \retval FLAC__bool - * \c false if \a copy is \c true and malloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy); - -/** Sets the description of a PICTURE block. - * - * If \a copy is \c true, a copy of the string is stored; otherwise, the object - * takes ownership of the pointer. The existing string will be freed if this - * function is successful, otherwise the original string will remain if \a copy - * is \c true and malloc() fails. - * - * \note It is safe to pass a const pointer to \a description if \a copy is \c true. - * - * \param object A pointer to an existing PICTURE object. - * \param description A pointer to the description string. The string must be - * valid UTF-8, NUL-terminated. No validation is done. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode - * \code (description != NULL) \endcode - * \retval FLAC__bool - * \c false if \a copy is \c true and malloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy); - -/** Sets the picture data of a PICTURE block. - * - * If \a copy is \c true, a copy of the data is stored; otherwise, the object - * takes ownership of the pointer. Also sets the \a data_length field of the - * metadata object to what is passed in as the \a length parameter. The - * existing data will be freed if this function is successful, otherwise the - * original data and data_length will remain if \a copy is \c true and - * malloc() fails. - * - * \note It is safe to pass a const pointer to \a data if \a copy is \c true. - * - * \param object A pointer to an existing PICTURE object. - * \param data A pointer to the data to set. - * \param length The length of \a data in bytes. - * \param copy See above. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode - * \code (data != NULL && length > 0) || - * (data == NULL && length == 0 && copy == false) \endcode - * \retval FLAC__bool - * \c false if \a copy is \c true and malloc() fails, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy); - -/** Check a PICTURE block to see if it conforms to the FLAC specification. - * See the format specification for limits on the contents of the - * PICTURE block. - * - * \param object A pointer to existing PICTURE block to be checked. - * \param violation Address of a pointer to a string. If there is a - * violation, a pointer to a string explanation of the - * violation will be returned here. \a violation may be - * \c NULL if you don't need the returned string. Do not - * free the returned string; it will always point to static - * data. - * \assert - * \code object != NULL \endcode - * \code object->type == FLAC__METADATA_TYPE_PICTURE \endcode - * \retval FLAC__bool - * \c false if PICTURE block is illegal, else \c true. - */ -FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation); - - -/** Get the raw (binary) representation of a FLAC__StreamMetadata objeect. - * After use, free() the returned buffer. The length of the buffer is - * the length of the input metadata object plus 4 bytes for the header. - * - * \param object A pointer to metadata block to be converted. - * \assert - * \code object != NULL \endcode - * \retval FLAC__byte* - * \c NULL if there was an error, else a pointer to a buffer holding - * the requested data. - */ -FLAC_API FLAC__byte * FLAC__metadata_object_get_raw(const FLAC__StreamMetadata *object); - - -/** Turn a raw (binary) representation into a FLAC__StreamMetadata objeect. - * The returned object must be deleted with FLAC__metadata_object_delete() - * after use. - * - * \param buffer A pointer to a buffer containing a binary representation - * to be converted to a FLAC__StreamMetadata object - * \param length The length of the supplied buffer - * \retval FLAC__StreamMetadata* - * \c NULL if there was an error, else a pointer to a FLAC__StreamMetadata - * holding the requested data. - */ - -FLAC_API FLAC__StreamMetadata * FLAC__metadata_object_set_raw(FLAC__byte *buffer, FLAC__uint32 length); -/* \} */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flac/include/FLAC/ordinals.h b/flac/include/FLAC/ordinals.h deleted file mode 100644 index d61aac5..0000000 --- a/flac/include/FLAC/ordinals.h +++ /dev/null @@ -1,55 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__ORDINALS_H -#define FLAC__ORDINALS_H - -/* This of course assumes C99 headers */ - -#include -#include - -typedef int8_t FLAC__int8; -typedef uint8_t FLAC__uint8; - -typedef int16_t FLAC__int16; -typedef int32_t FLAC__int32; -typedef int64_t FLAC__int64; -typedef uint16_t FLAC__uint16; -typedef uint32_t FLAC__uint32; -typedef uint64_t FLAC__uint64; - -typedef int FLAC__bool; - -typedef FLAC__uint8 FLAC__byte; - -#endif diff --git a/flac/include/FLAC/stream_decoder.h b/flac/include/FLAC/stream_decoder.h deleted file mode 100644 index 2272bca..0000000 --- a/flac/include/FLAC/stream_decoder.h +++ /dev/null @@ -1,1584 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__STREAM_DECODER_H -#define FLAC__STREAM_DECODER_H - -#include /* for FILE */ -#include "export.h" -#include "format.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -/** \file include/FLAC/stream_decoder.h - * - * \brief - * This module contains the functions which implement the stream - * decoder. - * - * See the detailed documentation in the - * \link flac_stream_decoder stream decoder \endlink module. - */ - -/** \defgroup flac_decoder FLAC/ \*_decoder.h: decoder interfaces - * \ingroup flac - * - * \brief - * This module describes the decoder layers provided by libFLAC. - * - * The stream decoder can be used to decode complete streams either from - * the client via callbacks, or directly from a file, depending on how - * it is initialized. When decoding via callbacks, the client provides - * callbacks for reading FLAC data and writing decoded samples, and - * handling metadata and errors. If the client also supplies seek-related - * callback, the decoder function for sample-accurate seeking within the - * FLAC input is also available. When decoding from a file, the client - * needs only supply a filename or open \c FILE* and write/metadata/error - * callbacks; the rest of the callbacks are supplied internally. For more - * info see the \link flac_stream_decoder stream decoder \endlink module. - */ - -/** \defgroup flac_stream_decoder FLAC/stream_decoder.h: stream decoder interface - * \ingroup flac_decoder - * - * \brief - * This module contains the functions which implement the stream - * decoder. - * - * The stream decoder can decode native FLAC, and optionally Ogg FLAC - * (check FLAC_API_SUPPORTS_OGG_FLAC) streams and files. - * - * The basic usage of this decoder is as follows: - * - The program creates an instance of a decoder using - * FLAC__stream_decoder_new(). - * - The program overrides the default settings using - * FLAC__stream_decoder_set_*() functions. - * - The program initializes the instance to validate the settings and - * prepare for decoding using - * - FLAC__stream_decoder_init_stream() or FLAC__stream_decoder_init_FILE() - * or FLAC__stream_decoder_init_file() for native FLAC, - * - FLAC__stream_decoder_init_ogg_stream() or FLAC__stream_decoder_init_ogg_FILE() - * or FLAC__stream_decoder_init_ogg_file() for Ogg FLAC - * - The program calls the FLAC__stream_decoder_process_*() functions - * to decode data, which subsequently calls the callbacks. - * - The program finishes the decoding with FLAC__stream_decoder_finish(), - * which flushes the input and output and resets the decoder to the - * uninitialized state. - * - The instance may be used again or deleted with - * FLAC__stream_decoder_delete(). - * - * In more detail, the program will create a new instance by calling - * FLAC__stream_decoder_new(), then call FLAC__stream_decoder_set_*() - * functions to override the default decoder options, and call - * one of the FLAC__stream_decoder_init_*() functions. - * - * There are three initialization functions for native FLAC, one for - * setting up the decoder to decode FLAC data from the client via - * callbacks, and two for decoding directly from a FLAC file. - * - * For decoding via callbacks, use FLAC__stream_decoder_init_stream(). - * You must also supply several callbacks for handling I/O. Some (like - * seeking) are optional, depending on the capabilities of the input. - * - * For decoding directly from a file, use FLAC__stream_decoder_init_FILE() - * or FLAC__stream_decoder_init_file(). Then you must only supply an open - * \c FILE* or filename and fewer callbacks; the decoder will handle - * the other callbacks internally. - * - * There are three similarly-named init functions for decoding from Ogg - * FLAC streams. Check \c FLAC_API_SUPPORTS_OGG_FLAC to find out if the - * library has been built with Ogg support. - * - * Once the decoder is initialized, your program will call one of several - * functions to start the decoding process: - * - * - FLAC__stream_decoder_process_single() - Tells the decoder to process at - * most one metadata block or audio frame and return, calling either the - * metadata callback or write callback, respectively, once. If the decoder - * loses sync it will return with only the error callback being called. - * - FLAC__stream_decoder_process_until_end_of_metadata() - Tells the decoder - * to process the stream from the current location and stop upon reaching - * the first audio frame. The client will get one metadata, write, or error - * callback per metadata block, audio frame, or sync error, respectively. - * - FLAC__stream_decoder_process_until_end_of_stream() - Tells the decoder - * to process the stream from the current location until the read callback - * returns FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM or - * FLAC__STREAM_DECODER_READ_STATUS_ABORT. The client will get one metadata, - * write, or error callback per metadata block, audio frame, or sync error, - * respectively. - * - * When the decoder has finished decoding (normally or through an abort), - * the instance is finished by calling FLAC__stream_decoder_finish(), which - * ensures the decoder is in the correct state and frees memory. Then the - * instance may be deleted with FLAC__stream_decoder_delete() or initialized - * again to decode another stream. - * - * Seeking is exposed through the FLAC__stream_decoder_seek_absolute() method. - * At any point after the stream decoder has been initialized, the client can - * call this function to seek to an exact sample within the stream. - * Subsequently, the first time the write callback is called it will be - * passed a (possibly partial) block starting at that sample. - * - * If the client cannot seek via the callback interface provided, but still - * has another way of seeking, it can flush the decoder using - * FLAC__stream_decoder_flush() and start feeding data from the new position - * through the read callback. - * - * The stream decoder also provides MD5 signature checking. If this is - * turned on before initialization, FLAC__stream_decoder_finish() will - * report when the decoded MD5 signature does not match the one stored - * in the STREAMINFO block. MD5 checking is automatically turned off - * (until the next FLAC__stream_decoder_reset()) if there is no signature - * in the STREAMINFO block or when a seek is attempted. - * - * The FLAC__stream_decoder_set_metadata_*() functions deserve special - * attention. By default, the decoder only calls the metadata_callback for - * the STREAMINFO block. These functions allow you to tell the decoder - * explicitly which blocks to parse and return via the metadata_callback - * and/or which to skip. Use a FLAC__stream_decoder_set_metadata_respond_all(), - * FLAC__stream_decoder_set_metadata_ignore() ... or FLAC__stream_decoder_set_metadata_ignore_all(), - * FLAC__stream_decoder_set_metadata_respond() ... sequence to exactly specify - * which blocks to return. Remember that metadata blocks can potentially - * be big (for example, cover art) so filtering out the ones you don't - * use can reduce the memory requirements of the decoder. Also note the - * special forms FLAC__stream_decoder_set_metadata_respond_application(id) - * and FLAC__stream_decoder_set_metadata_ignore_application(id) for - * filtering APPLICATION blocks based on the application ID. - * - * STREAMINFO and SEEKTABLE blocks are always parsed and used internally, but - * they still can legally be filtered from the metadata_callback. - * - * \note - * The "set" functions may only be called when the decoder is in the - * state FLAC__STREAM_DECODER_UNINITIALIZED, i.e. after - * FLAC__stream_decoder_new() or FLAC__stream_decoder_finish(), but - * before FLAC__stream_decoder_init_*(). If this is the case they will - * return \c true, otherwise \c false. - * - * \note - * FLAC__stream_decoder_finish() resets all settings to the constructor - * defaults, including the callbacks. - * - * \{ - */ - - -/** State values for a FLAC__StreamDecoder - * - * The decoder's state can be obtained by calling FLAC__stream_decoder_get_state(). - */ -typedef enum { - - FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0, - /**< The decoder is ready to search for metadata. */ - - FLAC__STREAM_DECODER_READ_METADATA, - /**< The decoder is ready to or is in the process of reading metadata. */ - - FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC, - /**< The decoder is ready to or is in the process of searching for the - * frame sync code. - */ - - FLAC__STREAM_DECODER_READ_FRAME, - /**< The decoder is ready to or is in the process of reading a frame. */ - - FLAC__STREAM_DECODER_END_OF_STREAM, - /**< The decoder has reached the end of the stream. */ - - FLAC__STREAM_DECODER_OGG_ERROR, - /**< An error occurred in the underlying Ogg layer. */ - - FLAC__STREAM_DECODER_SEEK_ERROR, - /**< An error occurred while seeking. The decoder must be flushed - * with FLAC__stream_decoder_flush() or reset with - * FLAC__stream_decoder_reset() before decoding can continue. - */ - - FLAC__STREAM_DECODER_ABORTED, - /**< The decoder was aborted by the read or write callback. */ - - FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR, - /**< An error occurred allocating memory. The decoder is in an invalid - * state and can no longer be used. - */ - - FLAC__STREAM_DECODER_UNINITIALIZED - /**< The decoder is in the uninitialized state; one of the - * FLAC__stream_decoder_init_*() functions must be called before samples - * can be processed. - */ - -} FLAC__StreamDecoderState; - -/** Maps a FLAC__StreamDecoderState to a C string. - * - * Using a FLAC__StreamDecoderState as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamDecoderStateString[]; - - -/** Possible return values for the FLAC__stream_decoder_init_*() functions. - */ -typedef enum { - - FLAC__STREAM_DECODER_INIT_STATUS_OK = 0, - /**< Initialization was successful. */ - - FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER, - /**< The library was not compiled with support for the given container - * format. - */ - - FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS, - /**< A required callback was not supplied. */ - - FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR, - /**< An error occurred allocating memory. */ - - FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE, - /**< fopen() failed in FLAC__stream_decoder_init_file() or - * FLAC__stream_decoder_init_ogg_file(). */ - - FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED - /**< FLAC__stream_decoder_init_*() was called when the decoder was - * already initialized, usually because - * FLAC__stream_decoder_finish() was not called. - */ - -} FLAC__StreamDecoderInitStatus; - -/** Maps a FLAC__StreamDecoderInitStatus to a C string. - * - * Using a FLAC__StreamDecoderInitStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[]; - - -/** Return values for the FLAC__StreamDecoder read callback. - */ -typedef enum { - - FLAC__STREAM_DECODER_READ_STATUS_CONTINUE, - /**< The read was OK and decoding can continue. */ - - FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM, - /**< The read was attempted while at the end of the stream. Note that - * the client must only return this value when the read callback was - * called when already at the end of the stream. Otherwise, if the read - * itself moves to the end of the stream, the client should still return - * the data and \c FLAC__STREAM_DECODER_READ_STATUS_CONTINUE, and then on - * the next read callback it should return - * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM with a byte count - * of \c 0. - */ - - FLAC__STREAM_DECODER_READ_STATUS_ABORT - /**< An unrecoverable error occurred. The decoder will return from the process call. */ - -} FLAC__StreamDecoderReadStatus; - -/** Maps a FLAC__StreamDecoderReadStatus to a C string. - * - * Using a FLAC__StreamDecoderReadStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[]; - - -/** Return values for the FLAC__StreamDecoder seek callback. - */ -typedef enum { - - FLAC__STREAM_DECODER_SEEK_STATUS_OK, - /**< The seek was OK and decoding can continue. */ - - FLAC__STREAM_DECODER_SEEK_STATUS_ERROR, - /**< An unrecoverable error occurred. The decoder will return from the process call. */ - - FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED - /**< Client does not support seeking. */ - -} FLAC__StreamDecoderSeekStatus; - -/** Maps a FLAC__StreamDecoderSeekStatus to a C string. - * - * Using a FLAC__StreamDecoderSeekStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[]; - - -/** Return values for the FLAC__StreamDecoder tell callback. - */ -typedef enum { - - FLAC__STREAM_DECODER_TELL_STATUS_OK, - /**< The tell was OK and decoding can continue. */ - - FLAC__STREAM_DECODER_TELL_STATUS_ERROR, - /**< An unrecoverable error occurred. The decoder will return from the process call. */ - - FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED - /**< Client does not support telling the position. */ - -} FLAC__StreamDecoderTellStatus; - -/** Maps a FLAC__StreamDecoderTellStatus to a C string. - * - * Using a FLAC__StreamDecoderTellStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[]; - - -/** Return values for the FLAC__StreamDecoder length callback. - */ -typedef enum { - - FLAC__STREAM_DECODER_LENGTH_STATUS_OK, - /**< The length call was OK and decoding can continue. */ - - FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR, - /**< An unrecoverable error occurred. The decoder will return from the process call. */ - - FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED - /**< Client does not support reporting the length. */ - -} FLAC__StreamDecoderLengthStatus; - -/** Maps a FLAC__StreamDecoderLengthStatus to a C string. - * - * Using a FLAC__StreamDecoderLengthStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[]; - - -/** Return values for the FLAC__StreamDecoder write callback. - */ -typedef enum { - - FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE, - /**< The write was OK and decoding can continue. */ - - FLAC__STREAM_DECODER_WRITE_STATUS_ABORT - /**< An unrecoverable error occurred. The decoder will return from the process call. */ - -} FLAC__StreamDecoderWriteStatus; - -/** Maps a FLAC__StreamDecoderWriteStatus to a C string. - * - * Using a FLAC__StreamDecoderWriteStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[]; - - -/** Possible values passed back to the FLAC__StreamDecoder error callback. - * \c FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC is the generic catch- - * all. The rest could be caused by bad sync (false synchronization on - * data that is not the start of a frame) or corrupted data. The error - * itself is the decoder's best guess at what happened assuming a correct - * sync. For example \c FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER - * could be caused by a correct sync on the start of a frame, but some - * data in the frame header was corrupted. Or it could be the result of - * syncing on a point the stream that looked like the starting of a frame - * but was not. \c FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM - * could be because the decoder encountered a valid frame made by a future - * version of the encoder which it cannot parse, or because of a false - * sync making it appear as though an encountered frame was generated by - * a future encoder. \c FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA is - * caused by finding data that doesn't fit a metadata block (too large - * or too small) or finding inconsistencies in the metadata, for example - * a PICTURE block with an image that exceeds the size of the metadata - * block. - */ -typedef enum { - - FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC, - /**< An error in the stream caused the decoder to lose synchronization. */ - - FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER, - /**< The decoder encountered a corrupted frame header. */ - - FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH, - /**< The frame's data did not match the CRC in the footer. */ - - FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM, - /**< The decoder encountered reserved fields in use in the stream. */ - - FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA - /**< The decoder encountered a corrupted metadata block. */ - -} FLAC__StreamDecoderErrorStatus; - -/** Maps a FLAC__StreamDecoderErrorStatus to a C string. - * - * Using a FLAC__StreamDecoderErrorStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[]; - - -/*********************************************************************** - * - * class FLAC__StreamDecoder - * - ***********************************************************************/ - -struct FLAC__StreamDecoderProtected; -struct FLAC__StreamDecoderPrivate; -/** The opaque structure definition for the stream decoder type. - * See the \link flac_stream_decoder stream decoder module \endlink - * for a detailed description. - */ -typedef struct { - struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */ - struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */ -} FLAC__StreamDecoder; - -/** Signature for the read callback. - * - * A function pointer matching this signature must be passed to - * FLAC__stream_decoder_init*_stream(). The supplied function will be - * called when the decoder needs more input data. The address of the - * buffer to be filled is supplied, along with the number of bytes the - * buffer can hold. The callback may choose to supply less data and - * modify the byte count but must be careful not to overflow the buffer. - * The callback then returns a status code chosen from - * FLAC__StreamDecoderReadStatus. - * - * Here is an example of a read callback for stdio streams: - * \code - * FLAC__StreamDecoderReadStatus read_cb(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) - * { - * FILE *file = ((MyClientData*)client_data)->file; - * if(*bytes > 0) { - * *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file); - * if(ferror(file)) - * return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - * else if(*bytes == 0) - * return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - * else - * return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - * } - * else - * return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - * } - * \endcode - * - * \note In general, FLAC__StreamDecoder functions which change the - * state should not be called on the \a decoder while in the callback. - * - * \param decoder The decoder instance calling the callback. - * \param buffer A pointer to a location for the callee to store - * data to be decoded. - * \param bytes A pointer to the size of the buffer. On entry - * to the callback, it contains the maximum number - * of bytes that may be stored in \a buffer. The - * callee must set it to the actual number of bytes - * stored (0 in case of error or end-of-stream) before - * returning. - * \param client_data The callee's client data set through - * FLAC__stream_decoder_init_*(). - * \retval FLAC__StreamDecoderReadStatus - * The callee's return status. Note that the callback should return - * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM if and only if - * zero bytes were read and there is no more data to be read. - */ -typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); - -/** Signature for the seek callback. - * - * A function pointer matching this signature may be passed to - * FLAC__stream_decoder_init*_stream(). The supplied function will be - * called when the decoder needs to seek the input stream. The decoder - * will pass the absolute byte offset to seek to, 0 meaning the - * beginning of the stream. - * - * Here is an example of a seek callback for stdio streams: - * \code - * FLAC__StreamDecoderSeekStatus seek_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) - * { - * FILE *file = ((MyClientData*)client_data)->file; - * if(file == stdin) - * return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; - * else if(fseeko(file, (off_t)absolute_byte_offset, SEEK_SET) < 0) - * return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - * else - * return FLAC__STREAM_DECODER_SEEK_STATUS_OK; - * } - * \endcode - * - * \note In general, FLAC__StreamDecoder functions which change the - * state should not be called on the \a decoder while in the callback. - * - * \param decoder The decoder instance calling the callback. - * \param absolute_byte_offset The offset from the beginning of the stream - * to seek to. - * \param client_data The callee's client data set through - * FLAC__stream_decoder_init_*(). - * \retval FLAC__StreamDecoderSeekStatus - * The callee's return status. - */ -typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); - -/** Signature for the tell callback. - * - * A function pointer matching this signature may be passed to - * FLAC__stream_decoder_init*_stream(). The supplied function will be - * called when the decoder wants to know the current position of the - * stream. The callback should return the byte offset from the - * beginning of the stream. - * - * Here is an example of a tell callback for stdio streams: - * \code - * FLAC__StreamDecoderTellStatus tell_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) - * { - * FILE *file = ((MyClientData*)client_data)->file; - * off_t pos; - * if(file == stdin) - * return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED; - * else if((pos = ftello(file)) < 0) - * return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - * else { - * *absolute_byte_offset = (FLAC__uint64)pos; - * return FLAC__STREAM_DECODER_TELL_STATUS_OK; - * } - * } - * \endcode - * - * \note In general, FLAC__StreamDecoder functions which change the - * state should not be called on the \a decoder while in the callback. - * - * \param decoder The decoder instance calling the callback. - * \param absolute_byte_offset A pointer to storage for the current offset - * from the beginning of the stream. - * \param client_data The callee's client data set through - * FLAC__stream_decoder_init_*(). - * \retval FLAC__StreamDecoderTellStatus - * The callee's return status. - */ -typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); - -/** Signature for the length callback. - * - * A function pointer matching this signature may be passed to - * FLAC__stream_decoder_init*_stream(). The supplied function will be - * called when the decoder wants to know the total length of the stream - * in bytes. - * - * Here is an example of a length callback for stdio streams: - * \code - * FLAC__StreamDecoderLengthStatus length_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) - * { - * FILE *file = ((MyClientData*)client_data)->file; - * struct stat filestats; - * - * if(file == stdin) - * return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; - * else if(fstat(fileno(file), &filestats) != 0) - * return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - * else { - * *stream_length = (FLAC__uint64)filestats.st_size; - * return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; - * } - * } - * \endcode - * - * \note In general, FLAC__StreamDecoder functions which change the - * state should not be called on the \a decoder while in the callback. - * - * \param decoder The decoder instance calling the callback. - * \param stream_length A pointer to storage for the length of the stream - * in bytes. - * \param client_data The callee's client data set through - * FLAC__stream_decoder_init_*(). - * \retval FLAC__StreamDecoderLengthStatus - * The callee's return status. - */ -typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); - -/** Signature for the EOF callback. - * - * A function pointer matching this signature may be passed to - * FLAC__stream_decoder_init*_stream(). The supplied function will be - * called when the decoder needs to know if the end of the stream has - * been reached. - * - * Here is an example of a EOF callback for stdio streams: - * FLAC__bool eof_cb(const FLAC__StreamDecoder *decoder, void *client_data) - * \code - * { - * FILE *file = ((MyClientData*)client_data)->file; - * return feof(file)? true : false; - * } - * \endcode - * - * \note In general, FLAC__StreamDecoder functions which change the - * state should not be called on the \a decoder while in the callback. - * - * \param decoder The decoder instance calling the callback. - * \param client_data The callee's client data set through - * FLAC__stream_decoder_init_*(). - * \retval FLAC__bool - * \c true if the currently at the end of the stream, else \c false. - */ -typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data); - -/** Signature for the write callback. - * - * A function pointer matching this signature must be passed to one of - * the FLAC__stream_decoder_init_*() functions. - * The supplied function will be called when the decoder has decoded a - * single audio frame. The decoder will pass the frame metadata as well - * as an array of pointers (one for each channel) pointing to the - * decoded audio. - * - * \note In general, FLAC__StreamDecoder functions which change the - * state should not be called on the \a decoder while in the callback. - * - * \param decoder The decoder instance calling the callback. - * \param frame The description of the decoded frame. See - * FLAC__Frame. - * \param buffer An array of pointers to decoded channels of data. - * Each pointer will point to an array of signed - * samples of length \a frame->header.blocksize. - * Channels will be ordered according to the FLAC - * specification; see the documentation for the - * frame header. - * \param client_data The callee's client data set through - * FLAC__stream_decoder_init_*(). - * \retval FLAC__StreamDecoderWriteStatus - * The callee's return status. - */ -typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); - -/** Signature for the metadata callback. - * - * A function pointer matching this signature must be passed to one of - * the FLAC__stream_decoder_init_*() functions. - * The supplied function will be called when the decoder has decoded a - * metadata block. In a valid FLAC file there will always be one - * \c STREAMINFO block, followed by zero or more other metadata blocks. - * These will be supplied by the decoder in the same order as they - * appear in the stream and always before the first audio frame (i.e. - * write callback). The metadata block that is passed in must not be - * modified, and it doesn't live beyond the callback, so you should make - * a copy of it with FLAC__metadata_object_clone() if you will need it - * elsewhere. Since metadata blocks can potentially be large, by - * default the decoder only calls the metadata callback for the - * \c STREAMINFO block; you can instruct the decoder to pass or filter - * other blocks with FLAC__stream_decoder_set_metadata_*() calls. - * - * \note In general, FLAC__StreamDecoder functions which change the - * state should not be called on the \a decoder while in the callback. - * - * \param decoder The decoder instance calling the callback. - * \param metadata The decoded metadata block. - * \param client_data The callee's client data set through - * FLAC__stream_decoder_init_*(). - */ -typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); - -/** Signature for the error callback. - * - * A function pointer matching this signature must be passed to one of - * the FLAC__stream_decoder_init_*() functions. - * The supplied function will be called whenever an error occurs during - * decoding. - * - * \note In general, FLAC__StreamDecoder functions which change the - * state should not be called on the \a decoder while in the callback. - * - * \param decoder The decoder instance calling the callback. - * \param status The error encountered by the decoder. - * \param client_data The callee's client data set through - * FLAC__stream_decoder_init_*(). - */ -typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); - - -/*********************************************************************** - * - * Class constructor/destructor - * - ***********************************************************************/ - -/** Create a new stream decoder instance. The instance is created with - * default settings; see the individual FLAC__stream_decoder_set_*() - * functions for each setting's default. - * - * \retval FLAC__StreamDecoder* - * \c NULL if there was an error allocating memory, else the new instance. - */ -FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void); - -/** Free a decoder instance. Deletes the object pointed to by \a decoder. - * - * \param decoder A pointer to an existing decoder. - * \assert - * \code decoder != NULL \endcode - */ -FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder); - - -/*********************************************************************** - * - * Public class method prototypes - * - ***********************************************************************/ - -/** Set the serial number for the FLAC stream within the Ogg container. - * The default behavior is to use the serial number of the first Ogg - * page. Setting a serial number here will explicitly specify which - * stream is to be decoded. - * - * \note - * This does not need to be set for native FLAC decoding. - * - * \default \c use serial number of first page - * \param decoder A decoder instance to set. - * \param serial_number See above. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number); - -/** Set the "MD5 signature checking" flag. If \c true, the decoder will - * compute the MD5 signature of the unencoded audio data while decoding - * and compare it to the signature from the STREAMINFO block, if it - * exists, during FLAC__stream_decoder_finish(). - * - * MD5 signature checking will be turned off (until the next - * FLAC__stream_decoder_reset()) if there is no signature in the - * STREAMINFO block or when a seek is attempted. - * - * Clients that do not use the MD5 check should leave this off to speed - * up decoding. - * - * \default \c false - * \param decoder A decoder instance to set. - * \param value Flag value (see above). - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value); - -/** Direct the decoder to pass on all metadata blocks of type \a type. - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \param type See above. - * \assert - * \code decoder != NULL \endcode - * \a type is valid - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type); - -/** Direct the decoder to pass on all APPLICATION metadata blocks of the - * given \a id. - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \param id See above. - * \assert - * \code decoder != NULL \endcode - * \code id != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]); - -/** Direct the decoder to pass on all metadata blocks of any type. - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder); - -/** Direct the decoder to filter out all metadata blocks of type \a type. - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \param type See above. - * \assert - * \code decoder != NULL \endcode - * \a type is valid - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type); - -/** Direct the decoder to filter out all APPLICATION metadata blocks of - * the given \a id. - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \param id See above. - * \assert - * \code decoder != NULL \endcode - * \code id != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]); - -/** Direct the decoder to filter out all metadata blocks of any type. - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder); - -/** Get the current decoder state. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__StreamDecoderState - * The current decoder state. - */ -FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder); - -/** Get the current decoder state as a C string. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval const char * - * The decoder state as a C string. Do not modify the contents. - */ -FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder); - -/** Get the "MD5 signature checking" flag. - * This is the value of the setting, not whether or not the decoder is - * currently checking the MD5 (remember, it can be turned off automatically - * by a seek). When the decoder is reset the flag will be restored to the - * value returned by this function. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * See above. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder); - -/** Get the total number of samples in the stream being decoded. - * Will only be valid after decoding has started and will contain the - * value from the \c STREAMINFO block. A value of \c 0 means "unknown". - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval uint32_t - * See above. - */ -FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder); - -/** Get the current number of channels in the stream being decoded. - * Will only be valid after decoding has started and will contain the - * value from the most recently decoded frame header. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval uint32_t - * See above. - */ -FLAC_API uint32_t FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder); - -/** Get the current channel assignment in the stream being decoded. - * Will only be valid after decoding has started and will contain the - * value from the most recently decoded frame header. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__ChannelAssignment - * See above. - */ -FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder); - -/** Get the current sample resolution in the stream being decoded. - * Will only be valid after decoding has started and will contain the - * value from the most recently decoded frame header. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval uint32_t - * See above. - */ -FLAC_API uint32_t FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder); - -/** Get the current sample rate in Hz of the stream being decoded. - * Will only be valid after decoding has started and will contain the - * value from the most recently decoded frame header. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval uint32_t - * See above. - */ -FLAC_API uint32_t FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder); - -/** Get the current blocksize of the stream being decoded. - * Will only be valid after decoding has started and will contain the - * value from the most recently decoded frame header. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval uint32_t - * See above. - */ -FLAC_API uint32_t FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder); - -/** Returns the decoder's current read position within the stream. - * The position is the byte offset from the start of the stream. - * Bytes before this position have been fully decoded. Note that - * there may still be undecoded bytes in the decoder's read FIFO. - * The returned position is correct even after a seek. - * - * \warning This function currently only works for native FLAC, - * not Ogg FLAC streams. - * - * \param decoder A decoder instance to query. - * \param position Address at which to return the desired position. - * \assert - * \code decoder != NULL \endcode - * \code position != NULL \endcode - * \retval FLAC__bool - * \c true if successful, \c false if the stream is not native FLAC, - * or there was an error from the 'tell' callback or it returned - * \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position); - -/** Return client_data from decoder. - * The data pointed to by the pointer should not be modified. - * - * \param decoder A decoder instance. - * \retval const void * - * The callee's client data set through FLAC__stream_decoder_init_*(). - * Do not modify the contents. - */ -FLAC_API const void *FLAC__stream_decoder_get_client_data(FLAC__StreamDecoder *decoder); - -/** Initialize the decoder instance to decode native FLAC streams. - * - * This flavor of initialization sets up the decoder to decode from a - * native FLAC stream. I/O is performed via callbacks to the client. - * For decoding from a plain file via filename or open FILE*, - * FLAC__stream_decoder_init_file() and FLAC__stream_decoder_init_FILE() - * provide a simpler interface. - * - * This function should be called after FLAC__stream_decoder_new() and - * FLAC__stream_decoder_set_*() but before any of the - * FLAC__stream_decoder_process_*() functions. Will set and return the - * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA - * if initialization succeeded. - * - * \param decoder An uninitialized decoder instance. - * \param read_callback See FLAC__StreamDecoderReadCallback. This - * pointer must not be \c NULL. - * \param seek_callback See FLAC__StreamDecoderSeekCallback. This - * pointer may be \c NULL if seeking is not - * supported. If \a seek_callback is not \c NULL then a - * \a tell_callback, \a length_callback, and \a eof_callback must also be supplied. - * Alternatively, a dummy seek callback that just - * returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param tell_callback See FLAC__StreamDecoderTellCallback. This - * pointer may be \c NULL if not supported by the client. If - * \a seek_callback is not \c NULL then a - * \a tell_callback must also be supplied. - * Alternatively, a dummy tell callback that just - * returns \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param length_callback See FLAC__StreamDecoderLengthCallback. This - * pointer may be \c NULL if not supported by the client. If - * \a seek_callback is not \c NULL then a - * \a length_callback must also be supplied. - * Alternatively, a dummy length callback that just - * returns \c FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param eof_callback See FLAC__StreamDecoderEofCallback. This - * pointer may be \c NULL if not supported by the client. If - * \a seek_callback is not \c NULL then a - * \a eof_callback must also be supplied. - * Alternatively, a dummy length callback that just - * returns \c false - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param write_callback See FLAC__StreamDecoderWriteCallback. This - * pointer must not be \c NULL. - * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param error_callback See FLAC__StreamDecoderErrorCallback. This - * pointer must not be \c NULL. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__StreamDecoderInitStatus - * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamDecoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream( - FLAC__StreamDecoder *decoder, - FLAC__StreamDecoderReadCallback read_callback, - FLAC__StreamDecoderSeekCallback seek_callback, - FLAC__StreamDecoderTellCallback tell_callback, - FLAC__StreamDecoderLengthCallback length_callback, - FLAC__StreamDecoderEofCallback eof_callback, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -); - -/** Initialize the decoder instance to decode Ogg FLAC streams. - * - * This flavor of initialization sets up the decoder to decode from a - * FLAC stream in an Ogg container. I/O is performed via callbacks to the - * client. For decoding from a plain file via filename or open FILE*, - * FLAC__stream_decoder_init_ogg_file() and FLAC__stream_decoder_init_ogg_FILE() - * provide a simpler interface. - * - * This function should be called after FLAC__stream_decoder_new() and - * FLAC__stream_decoder_set_*() but before any of the - * FLAC__stream_decoder_process_*() functions. Will set and return the - * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA - * if initialization succeeded. - * - * \note Support for Ogg FLAC in the library is optional. If this - * library has been built without support for Ogg FLAC, this function - * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER. - * - * \param decoder An uninitialized decoder instance. - * \param read_callback See FLAC__StreamDecoderReadCallback. This - * pointer must not be \c NULL. - * \param seek_callback See FLAC__StreamDecoderSeekCallback. This - * pointer may be \c NULL if seeking is not - * supported. If \a seek_callback is not \c NULL then a - * \a tell_callback, \a length_callback, and \a eof_callback must also be supplied. - * Alternatively, a dummy seek callback that just - * returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param tell_callback See FLAC__StreamDecoderTellCallback. This - * pointer may be \c NULL if not supported by the client. If - * \a seek_callback is not \c NULL then a - * \a tell_callback must also be supplied. - * Alternatively, a dummy tell callback that just - * returns \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param length_callback See FLAC__StreamDecoderLengthCallback. This - * pointer may be \c NULL if not supported by the client. If - * \a seek_callback is not \c NULL then a - * \a length_callback must also be supplied. - * Alternatively, a dummy length callback that just - * returns \c FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param eof_callback See FLAC__StreamDecoderEofCallback. This - * pointer may be \c NULL if not supported by the client. If - * \a seek_callback is not \c NULL then a - * \a eof_callback must also be supplied. - * Alternatively, a dummy length callback that just - * returns \c false - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param write_callback See FLAC__StreamDecoderWriteCallback. This - * pointer must not be \c NULL. - * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param error_callback See FLAC__StreamDecoderErrorCallback. This - * pointer must not be \c NULL. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__StreamDecoderInitStatus - * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamDecoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream( - FLAC__StreamDecoder *decoder, - FLAC__StreamDecoderReadCallback read_callback, - FLAC__StreamDecoderSeekCallback seek_callback, - FLAC__StreamDecoderTellCallback tell_callback, - FLAC__StreamDecoderLengthCallback length_callback, - FLAC__StreamDecoderEofCallback eof_callback, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -); - -/** Initialize the decoder instance to decode native FLAC files. - * - * This flavor of initialization sets up the decoder to decode from a - * plain native FLAC file. For non-stdio streams, you must use - * FLAC__stream_decoder_init_stream() and provide callbacks for the I/O. - * - * This function should be called after FLAC__stream_decoder_new() and - * FLAC__stream_decoder_set_*() but before any of the - * FLAC__stream_decoder_process_*() functions. Will set and return the - * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA - * if initialization succeeded. - * - * \param decoder An uninitialized decoder instance. - * \param file An open FLAC file. The file should have been - * opened with mode \c "rb" and rewound. The file - * becomes owned by the decoder and should not be - * manipulated by the client while decoding. - * Unless \a file is \c stdin, it will be closed - * when FLAC__stream_decoder_finish() is called. - * Note however that seeking will not work when - * decoding from \c stdin since it is not seekable. - * \param write_callback See FLAC__StreamDecoderWriteCallback. This - * pointer must not be \c NULL. - * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param error_callback See FLAC__StreamDecoderErrorCallback. This - * pointer must not be \c NULL. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code decoder != NULL \endcode - * \code file != NULL \endcode - * \retval FLAC__StreamDecoderInitStatus - * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamDecoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE( - FLAC__StreamDecoder *decoder, - FILE *file, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -); - -/** Initialize the decoder instance to decode Ogg FLAC files. - * - * This flavor of initialization sets up the decoder to decode from a - * plain Ogg FLAC file. For non-stdio streams, you must use - * FLAC__stream_decoder_init_ogg_stream() and provide callbacks for the I/O. - * - * This function should be called after FLAC__stream_decoder_new() and - * FLAC__stream_decoder_set_*() but before any of the - * FLAC__stream_decoder_process_*() functions. Will set and return the - * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA - * if initialization succeeded. - * - * \note Support for Ogg FLAC in the library is optional. If this - * library has been built without support for Ogg FLAC, this function - * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER. - * - * \param decoder An uninitialized decoder instance. - * \param file An open FLAC file. The file should have been - * opened with mode \c "rb" and rewound. The file - * becomes owned by the decoder and should not be - * manipulated by the client while decoding. - * Unless \a file is \c stdin, it will be closed - * when FLAC__stream_decoder_finish() is called. - * Note however that seeking will not work when - * decoding from \c stdin since it is not seekable. - * \param write_callback See FLAC__StreamDecoderWriteCallback. This - * pointer must not be \c NULL. - * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param error_callback See FLAC__StreamDecoderErrorCallback. This - * pointer must not be \c NULL. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code decoder != NULL \endcode - * \code file != NULL \endcode - * \retval FLAC__StreamDecoderInitStatus - * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamDecoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE( - FLAC__StreamDecoder *decoder, - FILE *file, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -); - -/** Initialize the decoder instance to decode native FLAC files. - * - * This flavor of initialization sets up the decoder to decode from a plain - * native FLAC file. If POSIX fopen() semantics are not sufficient, you must - * use FLAC__stream_decoder_init_FILE(), or FLAC__stream_decoder_init_stream() - * and provide callbacks for the I/O. - * - * On Windows, filename must be a UTF-8 encoded filename, which libFLAC - * internally translates to an appropriate representation to use with - * _wfopen. On all other systems, filename is passed to fopen without - * any translation. - * - * This function should be called after FLAC__stream_decoder_new() and - * FLAC__stream_decoder_set_*() but before any of the - * FLAC__stream_decoder_process_*() functions. Will set and return the - * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA - * if initialization succeeded. - * - * \param decoder An uninitialized decoder instance. - * \param filename The name of the file to decode from. The file will - * be opened with fopen(). Use \c NULL to decode from - * \c stdin. Note that \c stdin is not seekable. - * \param write_callback See FLAC__StreamDecoderWriteCallback. This - * pointer must not be \c NULL. - * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param error_callback See FLAC__StreamDecoderErrorCallback. This - * pointer must not be \c NULL. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__StreamDecoderInitStatus - * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamDecoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file( - FLAC__StreamDecoder *decoder, - const char *filename, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -); - -/** Initialize the decoder instance to decode Ogg FLAC files. - * - * This flavor of initialization sets up the decoder to decode from a plain - * Ogg FLAC file. If POSIX fopen() semantics are not sufficient, you must use - * FLAC__stream_decoder_init_ogg_FILE(), or FLAC__stream_decoder_init_ogg_stream() - * and provide callbacks for the I/O. - * - * On Windows, filename must be a UTF-8 encoded filename, which libFLAC - * internally translates to an appropriate representation to use with - * _wfopen. On all other systems, filename is passed to fopen without - * any translation. - * - * This function should be called after FLAC__stream_decoder_new() and - * FLAC__stream_decoder_set_*() but before any of the - * FLAC__stream_decoder_process_*() functions. Will set and return the - * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA - * if initialization succeeded. - * - * \note Support for Ogg FLAC in the library is optional. If this - * library has been built without support for Ogg FLAC, this function - * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER. - * - * \param decoder An uninitialized decoder instance. - * \param filename The name of the file to decode from. The file will - * be opened with fopen(). Use \c NULL to decode from - * \c stdin. Note that \c stdin is not seekable. - * \param write_callback See FLAC__StreamDecoderWriteCallback. This - * pointer must not be \c NULL. - * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param error_callback See FLAC__StreamDecoderErrorCallback. This - * pointer must not be \c NULL. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__StreamDecoderInitStatus - * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamDecoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file( - FLAC__StreamDecoder *decoder, - const char *filename, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -); - -/** Finish the decoding process. - * Flushes the decoding buffer, releases resources, resets the decoder - * settings to their defaults, and returns the decoder state to - * FLAC__STREAM_DECODER_UNINITIALIZED. - * - * In the event of a prematurely-terminated decode, it is not strictly - * necessary to call this immediately before FLAC__stream_decoder_delete() - * but it is good practice to match every FLAC__stream_decoder_init_*() - * with a FLAC__stream_decoder_finish(). - * - * \param decoder An uninitialized decoder instance. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if MD5 checking is on AND a STREAMINFO block was available - * AND the MD5 signature in the STREAMINFO block was non-zero AND the - * signature does not match the one computed by the decoder; else - * \c true. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder); - -/** Flush the stream input. - * The decoder's input buffer will be cleared and the state set to - * \c FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC. This will also turn - * off MD5 checking. - * - * \param decoder A decoder instance. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c true if successful, else \c false if a memory allocation - * error occurs (in which case the state will be set to - * \c FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR). - */ -FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder); - -/** Reset the decoding process. - * The decoder's input buffer will be cleared and the state set to - * \c FLAC__STREAM_DECODER_SEARCH_FOR_METADATA. This is similar to - * FLAC__stream_decoder_finish() except that the settings are - * preserved; there is no need to call FLAC__stream_decoder_init_*() - * before decoding again. MD5 checking will be restored to its original - * setting. - * - * If the decoder is seekable, or was initialized with - * FLAC__stream_decoder_init*_FILE() or FLAC__stream_decoder_init*_file(), - * the decoder will also attempt to seek to the beginning of the file. - * If this rewind fails, this function will return \c false. It follows - * that FLAC__stream_decoder_reset() cannot be used when decoding from - * \c stdin. - * - * If the decoder was initialized with FLAC__stream_encoder_init*_stream() - * and is not seekable (i.e. no seek callback was provided or the seek - * callback returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED), it - * is the duty of the client to start feeding data from the beginning of - * the stream on the next FLAC__stream_decoder_process_*() call. - * - * \param decoder A decoder instance. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c true if successful, else \c false if a memory allocation occurs - * (in which case the state will be set to - * \c FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR) or a seek error - * occurs (the state will be unchanged). - */ -FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder); - -/** Decode one metadata block or audio frame. - * This version instructs the decoder to decode a either a single metadata - * block or a single frame and stop, unless the callbacks return a fatal - * error or the read callback returns - * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM. - * - * As the decoder needs more input it will call the read callback. - * Depending on what was decoded, the metadata or write callback will be - * called with the decoded metadata block or audio frame. - * - * Unless there is a fatal read error or end of stream, this function - * will return once one whole frame is decoded. In other words, if the - * stream is not synchronized or points to a corrupt frame header, the - * decoder will continue to try and resync until it gets to a valid - * frame, then decode one frame, then return. If the decoder points to - * a frame whose frame CRC in the frame footer does not match the - * computed frame CRC, this function will issue a - * FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH error to the - * error callback, and return, having decoded one complete, although - * corrupt, frame. (Such corrupted frames are sent as silence of the - * correct length to the write callback.) - * - * \param decoder An initialized decoder instance. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if any fatal read, write, or memory allocation error - * occurred (meaning decoding must stop), else \c true; for more - * information about the decoder, check the decoder state with - * FLAC__stream_decoder_get_state(). - */ -FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder); - -/** Decode until the end of the metadata. - * This version instructs the decoder to decode from the current position - * and continue until all the metadata has been read, or until the - * callbacks return a fatal error or the read callback returns - * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM. - * - * As the decoder needs more input it will call the read callback. - * As each metadata block is decoded, the metadata callback will be called - * with the decoded metadata. - * - * \param decoder An initialized decoder instance. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if any fatal read, write, or memory allocation error - * occurred (meaning decoding must stop), else \c true; for more - * information about the decoder, check the decoder state with - * FLAC__stream_decoder_get_state(). - */ -FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder); - -/** Decode until the end of the stream. - * This version instructs the decoder to decode from the current position - * and continue until the end of stream (the read callback returns - * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM), or until the - * callbacks return a fatal error. - * - * As the decoder needs more input it will call the read callback. - * As each metadata block and frame is decoded, the metadata or write - * callback will be called with the decoded metadata or frame. - * - * \param decoder An initialized decoder instance. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if any fatal read, write, or memory allocation error - * occurred (meaning decoding must stop), else \c true; for more - * information about the decoder, check the decoder state with - * FLAC__stream_decoder_get_state(). - */ -FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder); - -/** Skip one audio frame. - * This version instructs the decoder to 'skip' a single frame and stop, - * unless the callbacks return a fatal error or the read callback returns - * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM. - * - * The decoding flow is the same as what occurs when - * FLAC__stream_decoder_process_single() is called to process an audio - * frame, except that this function does not decode the parsed data into - * PCM or call the write callback. The integrity of the frame is still - * checked the same way as in the other process functions. - * - * This function will return once one whole frame is skipped, in the - * same way that FLAC__stream_decoder_process_single() will return once - * one whole frame is decoded. - * - * This function can be used in more quickly determining FLAC frame - * boundaries when decoding of the actual data is not needed, for - * example when an application is separating a FLAC stream into frames - * for editing or storing in a container. To do this, the application - * can use FLAC__stream_decoder_skip_single_frame() to quickly advance - * to the next frame, then use - * FLAC__stream_decoder_get_decode_position() to find the new frame - * boundary. - * - * This function should only be called when the stream has advanced - * past all the metadata, otherwise it will return \c false. - * - * \param decoder An initialized decoder instance not in a metadata - * state. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if any fatal read, write, or memory allocation error - * occurred (meaning decoding must stop), or if the decoder - * is in the FLAC__STREAM_DECODER_SEARCH_FOR_METADATA or - * FLAC__STREAM_DECODER_READ_METADATA state, else \c true; for more - * information about the decoder, check the decoder state with - * FLAC__stream_decoder_get_state(). - */ -FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder); - -/** Flush the input and seek to an absolute sample. - * Decoding will resume at the given sample. Note that because of - * this, the next write callback may contain a partial block. The - * client must support seeking the input or this function will fail - * and return \c false. Furthermore, if the decoder state is - * \c FLAC__STREAM_DECODER_SEEK_ERROR, then the decoder must be flushed - * with FLAC__stream_decoder_flush() or reset with - * FLAC__stream_decoder_reset() before decoding can continue. - * - * \param decoder A decoder instance. - * \param sample The target sample number to seek to. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c true if successful, else \c false. - */ -FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample); - -/* \} */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flac/include/FLAC/stream_encoder.h b/flac/include/FLAC/stream_encoder.h deleted file mode 100644 index a0d0263..0000000 --- a/flac/include/FLAC/stream_encoder.h +++ /dev/null @@ -1,1837 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__STREAM_ENCODER_H -#define FLAC__STREAM_ENCODER_H - -#include /* for FILE */ -#include "export.h" -#include "format.h" -#include "stream_decoder.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -/** \file include/FLAC/stream_encoder.h - * - * \brief - * This module contains the functions which implement the stream - * encoder. - * - * See the detailed documentation in the - * \link flac_stream_encoder stream encoder \endlink module. - */ - -/** \defgroup flac_encoder FLAC/ \*_encoder.h: encoder interfaces - * \ingroup flac - * - * \brief - * This module describes the encoder layers provided by libFLAC. - * - * The stream encoder can be used to encode complete streams either to the - * client via callbacks, or directly to a file, depending on how it is - * initialized. When encoding via callbacks, the client provides a write - * callback which will be called whenever FLAC data is ready to be written. - * If the client also supplies a seek callback, the encoder will also - * automatically handle the writing back of metadata discovered while - * encoding, like stream info, seek points offsets, etc. When encoding to - * a file, the client needs only supply a filename or open \c FILE* and an - * optional progress callback for periodic notification of progress; the - * write and seek callbacks are supplied internally. For more info see the - * \link flac_stream_encoder stream encoder \endlink module. - */ - -/** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface - * \ingroup flac_encoder - * - * \brief - * This module contains the functions which implement the stream - * encoder. - * - * The stream encoder can encode to native FLAC, and optionally Ogg FLAC - * (check FLAC_API_SUPPORTS_OGG_FLAC) streams and files. - * - * The basic usage of this encoder is as follows: - * - The program creates an instance of an encoder using - * FLAC__stream_encoder_new(). - * - The program overrides the default settings using - * FLAC__stream_encoder_set_*() functions. At a minimum, the following - * functions should be called: - * - FLAC__stream_encoder_set_channels() - * - FLAC__stream_encoder_set_bits_per_sample() - * - FLAC__stream_encoder_set_sample_rate() - * - FLAC__stream_encoder_set_ogg_serial_number() (if encoding to Ogg FLAC) - * - FLAC__stream_encoder_set_total_samples_estimate() (if known) - * - If the application wants to control the compression level or set its own - * metadata, then the following should also be called: - * - FLAC__stream_encoder_set_compression_level() - * - FLAC__stream_encoder_set_verify() - * - FLAC__stream_encoder_set_metadata() - * - The rest of the set functions should only be called if the client needs - * exact control over how the audio is compressed; thorough understanding - * of the FLAC format is necessary to achieve good results. - * - The program initializes the instance to validate the settings and - * prepare for encoding using - * - FLAC__stream_encoder_init_stream() or FLAC__stream_encoder_init_FILE() - * or FLAC__stream_encoder_init_file() for native FLAC - * - FLAC__stream_encoder_init_ogg_stream() or FLAC__stream_encoder_init_ogg_FILE() - * or FLAC__stream_encoder_init_ogg_file() for Ogg FLAC - * - The program calls FLAC__stream_encoder_process() or - * FLAC__stream_encoder_process_interleaved() to encode data, which - * subsequently calls the callbacks when there is encoder data ready - * to be written. - * - The program finishes the encoding with FLAC__stream_encoder_finish(), - * which causes the encoder to encode any data still in its input pipe, - * update the metadata with the final encoding statistics if output - * seeking is possible, and finally reset the encoder to the - * uninitialized state. - * - The instance may be used again or deleted with - * FLAC__stream_encoder_delete(). - * - * In more detail, the stream encoder functions similarly to the - * \link flac_stream_decoder stream decoder \endlink, but has fewer - * callbacks and more options. Typically the client will create a new - * instance by calling FLAC__stream_encoder_new(), then set the necessary - * parameters with FLAC__stream_encoder_set_*(), and initialize it by - * calling one of the FLAC__stream_encoder_init_*() functions. - * - * Unlike the decoders, the stream encoder has many options that can - * affect the speed and compression ratio. When setting these parameters - * you should have some basic knowledge of the format (see the - * user-level documentation - * or the formal description). The - * FLAC__stream_encoder_set_*() functions themselves do not validate the - * values as many are interdependent. The FLAC__stream_encoder_init_*() - * functions will do this, so make sure to pay attention to the state - * returned by FLAC__stream_encoder_init_*() to make sure that it is - * FLAC__STREAM_ENCODER_INIT_STATUS_OK. Any parameters that are not set - * before FLAC__stream_encoder_init_*() will take on the defaults from - * the constructor. - * - * There are three initialization functions for native FLAC, one for - * setting up the encoder to encode FLAC data to the client via - * callbacks, and two for encoding directly to a file. - * - * For encoding via callbacks, use FLAC__stream_encoder_init_stream(). - * You must also supply a write callback which will be called anytime - * there is raw encoded data to write. If the client can seek the output - * it is best to also supply seek and tell callbacks, as this allows the - * encoder to go back after encoding is finished to write back - * information that was collected while encoding, like seek point offsets, - * frame sizes, etc. - * - * For encoding directly to a file, use FLAC__stream_encoder_init_FILE() - * or FLAC__stream_encoder_init_file(). Then you must only supply a - * filename or open \c FILE*; the encoder will handle all the callbacks - * internally. You may also supply a progress callback for periodic - * notification of the encoding progress. - * - * There are three similarly-named init functions for encoding to Ogg - * FLAC streams. Check \c FLAC_API_SUPPORTS_OGG_FLAC to find out if the - * library has been built with Ogg support. - * - * The call to FLAC__stream_encoder_init_*() currently will also immediately - * call the write callback several times, once with the \c fLaC signature, - * and once for each encoded metadata block. Note that for Ogg FLAC - * encoding you will usually get at least twice the number of callbacks than - * with native FLAC, one for the Ogg page header and one for the page body. - * - * After initializing the instance, the client may feed audio data to the - * encoder in one of two ways: - * - * - Channel separate, through FLAC__stream_encoder_process() - The client - * will pass an array of pointers to buffers, one for each channel, to - * the encoder, each of the same length. The samples need not be - * block-aligned, but each channel should have the same number of samples. - * - Channel interleaved, through - * FLAC__stream_encoder_process_interleaved() - The client will pass a single - * pointer to data that is channel-interleaved (i.e. channel0_sample0, - * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...). - * Again, the samples need not be block-aligned but they must be - * sample-aligned, i.e. the first value should be channel0_sample0 and - * the last value channelN_sampleM. - * - * Note that for either process call, each sample in the buffers should be a - * signed integer, right-justified to the resolution set by - * FLAC__stream_encoder_set_bits_per_sample(). For example, if the resolution - * is 16 bits per sample, the samples should all be in the range [-32768,32767]. - * - * When the client is finished encoding data, it calls - * FLAC__stream_encoder_finish(), which causes the encoder to encode any - * data still in its input pipe, and call the metadata callback with the - * final encoding statistics. Then the instance may be deleted with - * FLAC__stream_encoder_delete() or initialized again to encode another - * stream. - * - * For programs that write their own metadata, but that do not know the - * actual metadata until after encoding, it is advantageous to instruct - * the encoder to write a PADDING block of the correct size, so that - * instead of rewriting the whole stream after encoding, the program can - * just overwrite the PADDING block. If only the maximum size of the - * metadata is known, the program can write a slightly larger padding - * block, then split it after encoding. - * - * Make sure you understand how lengths are calculated. All FLAC metadata - * blocks have a 4 byte header which contains the type and length. This - * length does not include the 4 bytes of the header. See the format page - * for the specification of metadata blocks and their lengths. - * - * \note - * If you are writing the FLAC data to a file via callbacks, make sure it - * is open for update (e.g. mode "w+" for stdio streams). This is because - * after the first encoding pass, the encoder will try to seek back to the - * beginning of the stream, to the STREAMINFO block, to write some data - * there. (If using FLAC__stream_encoder_init*_file() or - * FLAC__stream_encoder_init*_FILE(), the file is managed internally.) - * - * \note - * The "set" functions may only be called when the encoder is in the - * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after - * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but - * before FLAC__stream_encoder_init_*(). If this is the case they will - * return \c true, otherwise \c false. - * - * \note - * FLAC__stream_encoder_finish() resets all settings to the constructor - * defaults. - * - * \{ - */ - - -/** State values for a FLAC__StreamEncoder. - * - * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state(). - * - * If the encoder gets into any other state besides \c FLAC__STREAM_ENCODER_OK - * or \c FLAC__STREAM_ENCODER_UNINITIALIZED, it becomes invalid for encoding and - * must be deleted with FLAC__stream_encoder_delete(). - */ -typedef enum { - - FLAC__STREAM_ENCODER_OK = 0, - /**< The encoder is in the normal OK state and samples can be processed. */ - - FLAC__STREAM_ENCODER_UNINITIALIZED, - /**< The encoder is in the uninitialized state; one of the - * FLAC__stream_encoder_init_*() functions must be called before samples - * can be processed. - */ - - FLAC__STREAM_ENCODER_OGG_ERROR, - /**< An error occurred in the underlying Ogg layer. */ - - FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR, - /**< An error occurred in the underlying verify stream decoder; - * check FLAC__stream_encoder_get_verify_decoder_state(). - */ - - FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA, - /**< The verify decoder detected a mismatch between the original - * audio signal and the decoded audio signal. - */ - - FLAC__STREAM_ENCODER_CLIENT_ERROR, - /**< One of the callbacks returned a fatal error. */ - - FLAC__STREAM_ENCODER_IO_ERROR, - /**< An I/O error occurred while opening/reading/writing a file. - * Check \c errno. - */ - - FLAC__STREAM_ENCODER_FRAMING_ERROR, - /**< An error occurred while writing the stream; usually, the - * write_callback returned an error. - */ - - FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR - /**< Memory allocation failed. */ - -} FLAC__StreamEncoderState; - -/** Maps a FLAC__StreamEncoderState to a C string. - * - * Using a FLAC__StreamEncoderState as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamEncoderStateString[]; - - -/** Possible return values for the FLAC__stream_encoder_init_*() functions. - */ -typedef enum { - - FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0, - /**< Initialization was successful. */ - - FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR, - /**< General failure to set up encoder; call FLAC__stream_encoder_get_state() for cause. */ - - FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER, - /**< The library was not compiled with support for the given container - * format. - */ - - FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS, - /**< A required callback was not supplied. */ - - FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS, - /**< The encoder has an invalid setting for number of channels. */ - - FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE, - /**< The encoder has an invalid setting for bits-per-sample. - * FLAC supports 4-32 bps. - */ - - FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE, - /**< The encoder has an invalid setting for the input sample rate. */ - - FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE, - /**< The encoder has an invalid setting for the block size. */ - - FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER, - /**< The encoder has an invalid setting for the maximum LPC order. */ - - FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION, - /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */ - - FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER, - /**< The specified block size is less than the maximum LPC order. */ - - FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE, - /**< The encoder is bound to the Subset but other settings violate it. */ - - FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA, - /**< The metadata input to the encoder is invalid, in one of the following ways: - * - FLAC__stream_encoder_set_metadata() was called with a null pointer but a block count > 0 - * - One of the metadata blocks contains an undefined type - * - It contains an illegal CUESHEET as checked by FLAC__format_cuesheet_is_legal() - * - It contains an illegal SEEKTABLE as checked by FLAC__format_seektable_is_legal() - * - It contains more than one SEEKTABLE block or more than one VORBIS_COMMENT block - */ - - FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED - /**< FLAC__stream_encoder_init_*() was called when the encoder was - * already initialized, usually because - * FLAC__stream_encoder_finish() was not called. - */ - -} FLAC__StreamEncoderInitStatus; - -/** Maps a FLAC__StreamEncoderInitStatus to a C string. - * - * Using a FLAC__StreamEncoderInitStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[]; - - -/** Return values for the FLAC__StreamEncoder read callback. - */ -typedef enum { - - FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE, - /**< The read was OK and decoding can continue. */ - - FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM, - /**< The read was attempted at the end of the stream. */ - - FLAC__STREAM_ENCODER_READ_STATUS_ABORT, - /**< An unrecoverable error occurred. */ - - FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED - /**< Client does not support reading back from the output. */ - -} FLAC__StreamEncoderReadStatus; - -/** Maps a FLAC__StreamEncoderReadStatus to a C string. - * - * Using a FLAC__StreamEncoderReadStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[]; - - -/** Return values for the FLAC__StreamEncoder write callback. - */ -typedef enum { - - FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0, - /**< The write was OK and encoding can continue. */ - - FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR - /**< An unrecoverable error occurred. The encoder will return from the process call. */ - -} FLAC__StreamEncoderWriteStatus; - -/** Maps a FLAC__StreamEncoderWriteStatus to a C string. - * - * Using a FLAC__StreamEncoderWriteStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[]; - - -/** Return values for the FLAC__StreamEncoder seek callback. - */ -typedef enum { - - FLAC__STREAM_ENCODER_SEEK_STATUS_OK, - /**< The seek was OK and encoding can continue. */ - - FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR, - /**< An unrecoverable error occurred. */ - - FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED - /**< Client does not support seeking. */ - -} FLAC__StreamEncoderSeekStatus; - -/** Maps a FLAC__StreamEncoderSeekStatus to a C string. - * - * Using a FLAC__StreamEncoderSeekStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[]; - - -/** Return values for the FLAC__StreamEncoder tell callback. - */ -typedef enum { - - FLAC__STREAM_ENCODER_TELL_STATUS_OK, - /**< The tell was OK and encoding can continue. */ - - FLAC__STREAM_ENCODER_TELL_STATUS_ERROR, - /**< An unrecoverable error occurred. */ - - FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED - /**< Client does not support seeking. */ - -} FLAC__StreamEncoderTellStatus; - -/** Maps a FLAC__StreamEncoderTellStatus to a C string. - * - * Using a FLAC__StreamEncoderTellStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[]; - - -/*********************************************************************** - * - * class FLAC__StreamEncoder - * - ***********************************************************************/ - -struct FLAC__StreamEncoderProtected; -struct FLAC__StreamEncoderPrivate; -/** The opaque structure definition for the stream encoder type. - * See the \link flac_stream_encoder stream encoder module \endlink - * for a detailed description. - */ -typedef struct { - struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */ - struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */ -} FLAC__StreamEncoder; - -/** Signature for the read callback. - * - * A function pointer matching this signature must be passed to - * FLAC__stream_encoder_init_ogg_stream() if seeking is supported. - * The supplied function will be called when the encoder needs to read back - * encoded data. This happens during the metadata callback, when the encoder - * has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered - * while encoding. The address of the buffer to be filled is supplied, along - * with the number of bytes the buffer can hold. The callback may choose to - * supply less data and modify the byte count but must be careful not to - * overflow the buffer. The callback then returns a status code chosen from - * FLAC__StreamEncoderReadStatus. - * - * Here is an example of a read callback for stdio streams: - * \code - * FLAC__StreamEncoderReadStatus read_cb(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data) - * { - * FILE *file = ((MyClientData*)client_data)->file; - * if(*bytes > 0) { - * *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file); - * if(ferror(file)) - * return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; - * else if(*bytes == 0) - * return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM; - * else - * return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; - * } - * else - * return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; - * } - * \endcode - * - * \note In general, FLAC__StreamEncoder functions which change the - * state should not be called on the \a encoder while in the callback. - * - * \param encoder The encoder instance calling the callback. - * \param buffer A pointer to a location for the callee to store - * data to be encoded. - * \param bytes A pointer to the size of the buffer. On entry - * to the callback, it contains the maximum number - * of bytes that may be stored in \a buffer. The - * callee must set it to the actual number of bytes - * stored (0 in case of error or end-of-stream) before - * returning. - * \param client_data The callee's client data set through - * FLAC__stream_encoder_set_client_data(). - * \retval FLAC__StreamEncoderReadStatus - * The callee's return status. - */ -typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data); - -/** Signature for the write callback. - * - * A function pointer matching this signature must be passed to - * FLAC__stream_encoder_init*_stream(). The supplied function will be called - * by the encoder anytime there is raw encoded data ready to write. It may - * include metadata mixed with encoded audio frames and the data is not - * guaranteed to be aligned on frame or metadata block boundaries. - * - * The only duty of the callback is to write out the \a bytes worth of data - * in \a buffer to the current position in the output stream. The arguments - * \a samples and \a current_frame are purely informational. If \a samples - * is greater than \c 0, then \a current_frame will hold the current frame - * number that is being written; otherwise it indicates that the write - * callback is being called to write metadata. - * - * \note - * Unlike when writing to native FLAC, when writing to Ogg FLAC the - * write callback will be called twice when writing each audio - * frame; once for the page header, and once for the page body. - * When writing the page header, the \a samples argument to the - * write callback will be \c 0. - * - * \note In general, FLAC__StreamEncoder functions which change the - * state should not be called on the \a encoder while in the callback. - * - * \param encoder The encoder instance calling the callback. - * \param buffer An array of encoded data of length \a bytes. - * \param bytes The byte length of \a buffer. - * \param samples The number of samples encoded by \a buffer. - * \c 0 has a special meaning; see above. - * \param current_frame The number of the current frame being encoded. - * \param client_data The callee's client data set through - * FLAC__stream_encoder_init_*(). - * \retval FLAC__StreamEncoderWriteStatus - * The callee's return status. - */ -typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data); - -/** Signature for the seek callback. - * - * A function pointer matching this signature may be passed to - * FLAC__stream_encoder_init*_stream(). The supplied function will be called - * when the encoder needs to seek the output stream. The encoder will pass - * the absolute byte offset to seek to, 0 meaning the beginning of the stream. - * - * Here is an example of a seek callback for stdio streams: - * \code - * FLAC__StreamEncoderSeekStatus seek_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) - * { - * FILE *file = ((MyClientData*)client_data)->file; - * if(file == stdin) - * return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED; - * else if(fseeko(file, (off_t)absolute_byte_offset, SEEK_SET) < 0) - * return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR; - * else - * return FLAC__STREAM_ENCODER_SEEK_STATUS_OK; - * } - * \endcode - * - * \note In general, FLAC__StreamEncoder functions which change the - * state should not be called on the \a encoder while in the callback. - * - * \param encoder The encoder instance calling the callback. - * \param absolute_byte_offset The offset from the beginning of the stream - * to seek to. - * \param client_data The callee's client data set through - * FLAC__stream_encoder_init_*(). - * \retval FLAC__StreamEncoderSeekStatus - * The callee's return status. - */ -typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); - -/** Signature for the tell callback. - * - * A function pointer matching this signature may be passed to - * FLAC__stream_encoder_init*_stream(). The supplied function will be called - * when the encoder needs to know the current position of the output stream. - * - * \warning - * The callback must return the true current byte offset of the output to - * which the encoder is writing. If you are buffering the output, make - * sure and take this into account. If you are writing directly to a - * FILE* from your write callback, ftell() is sufficient. If you are - * writing directly to a file descriptor from your write callback, you - * can use lseek(fd, SEEK_CUR, 0). The encoder may later seek back to - * these points to rewrite metadata after encoding. - * - * Here is an example of a tell callback for stdio streams: - * \code - * FLAC__StreamEncoderTellStatus tell_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) - * { - * FILE *file = ((MyClientData*)client_data)->file; - * off_t pos; - * if(file == stdin) - * return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED; - * else if((pos = ftello(file)) < 0) - * return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR; - * else { - * *absolute_byte_offset = (FLAC__uint64)pos; - * return FLAC__STREAM_ENCODER_TELL_STATUS_OK; - * } - * } - * \endcode - * - * \note In general, FLAC__StreamEncoder functions which change the - * state should not be called on the \a encoder while in the callback. - * - * \param encoder The encoder instance calling the callback. - * \param absolute_byte_offset The address at which to store the current - * position of the output. - * \param client_data The callee's client data set through - * FLAC__stream_encoder_init_*(). - * \retval FLAC__StreamEncoderTellStatus - * The callee's return status. - */ -typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data); - -/** Signature for the metadata callback. - * - * A function pointer matching this signature may be passed to - * FLAC__stream_encoder_init*_stream(). The supplied function will be called - * once at the end of encoding with the populated STREAMINFO structure. This - * is so the client can seek back to the beginning of the file and write the - * STREAMINFO block with the correct statistics after encoding (like - * minimum/maximum frame size and total samples). - * - * \note In general, FLAC__StreamEncoder functions which change the - * state should not be called on the \a encoder while in the callback. - * - * \param encoder The encoder instance calling the callback. - * \param metadata The final populated STREAMINFO block. - * \param client_data The callee's client data set through - * FLAC__stream_encoder_init_*(). - */ -typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data); - -/** Signature for the progress callback. - * - * A function pointer matching this signature may be passed to - * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE(). - * The supplied function will be called when the encoder has finished - * writing a frame. The \c total_frames_estimate argument to the - * callback will be based on the value from - * FLAC__stream_encoder_set_total_samples_estimate(). - * - * \note In general, FLAC__StreamEncoder functions which change the - * state should not be called on the \a encoder while in the callback. - * - * \param encoder The encoder instance calling the callback. - * \param bytes_written Bytes written so far. - * \param samples_written Samples written so far. - * \param frames_written Frames written so far. - * \param total_frames_estimate The estimate of the total number of - * frames to be written. - * \param client_data The callee's client data set through - * FLAC__stream_encoder_init_*(). - */ -typedef void (*FLAC__StreamEncoderProgressCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate, void *client_data); - - -/*********************************************************************** - * - * Class constructor/destructor - * - ***********************************************************************/ - -/** Create a new stream encoder instance. The instance is created with - * default settings; see the individual FLAC__stream_encoder_set_*() - * functions for each setting's default. - * - * \retval FLAC__StreamEncoder* - * \c NULL if there was an error allocating memory, else the new instance. - */ -FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void); - -/** Free an encoder instance. Deletes the object pointed to by \a encoder. - * - * \param encoder A pointer to an existing encoder. - * \assert - * \code encoder != NULL \endcode - */ -FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder); - - -/*********************************************************************** - * - * Public class method prototypes - * - ***********************************************************************/ - -/** Set the serial number for the FLAC stream to use in the Ogg container. - * - * \note - * This does not need to be set for native FLAC encoding. - * - * \note - * It is recommended to set a serial number explicitly as the default of '0' - * may collide with other streams. - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param serial_number See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number); - -/** Set the "verify" flag. If \c true, the encoder will verify it's own - * encoded output by feeding it through an internal decoder and comparing - * the original signal against the decoded signal. If a mismatch occurs, - * the process call will return \c false. Note that this will slow the - * encoding process by the extra time required for decoding and comparison. - * - * \default \c false - * \param encoder An encoder instance to set. - * \param value Flag value (see above). - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value); - -/** Set the Subset flag. If \c true, - * the encoder will comply with the Subset and will check the - * settings during FLAC__stream_encoder_init_*() to see if all settings - * comply. If \c false, the settings may take advantage of the full - * range that the format allows. - * - * Make sure you know what it entails before setting this to \c false. - * - * \default \c true - * \param encoder An encoder instance to set. - * \param value Flag value (see above). - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value); - -/** Set the number of channels to be encoded. - * - * \default \c 2 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, uint32_t value); - -/** Set the sample resolution of the input to be encoded. - * - * \warning - * Do not feed the encoder data that is wider than the value you - * set here or you will generate an invalid stream. - * - * \default \c 16 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, uint32_t value); - -/** Set the sample rate (in Hz) of the input to be encoded. - * - * \default \c 44100 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, uint32_t value); - -/** Set the compression level - * - * The compression level is roughly proportional to the amount of effort - * the encoder expends to compress the file. A higher level usually - * means more computation but higher compression. The default level is - * suitable for most applications. - * - * Currently the levels range from \c 0 (fastest, least compression) to - * \c 8 (slowest, most compression). A value larger than \c 8 will be - * treated as \c 8. - * - * This function automatically calls the following other \c _set_ - * functions with appropriate values, so the client does not need to - * unless it specifically wants to override them: - * - FLAC__stream_encoder_set_do_mid_side_stereo() - * - FLAC__stream_encoder_set_loose_mid_side_stereo() - * - FLAC__stream_encoder_set_apodization() - * - FLAC__stream_encoder_set_max_lpc_order() - * - FLAC__stream_encoder_set_qlp_coeff_precision() - * - FLAC__stream_encoder_set_do_qlp_coeff_prec_search() - * - FLAC__stream_encoder_set_do_escape_coding() - * - FLAC__stream_encoder_set_do_exhaustive_model_search() - * - FLAC__stream_encoder_set_min_residual_partition_order() - * - FLAC__stream_encoder_set_max_residual_partition_order() - * - FLAC__stream_encoder_set_rice_parameter_search_dist() - * - * The actual values set for each level are: - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
leveldo mid-side stereoloose mid-side stereoapodizationmax lpc orderqlp coeff precisionqlp coeff prec searchescape codingexhaustive model searchmin residual partition ordermax residual partition orderrice parameter search dist
0 false false tukey(0.5) 0 0 false false false 0 3 0
1 true true tukey(0.5) 0 0 false false false 0 3 0
2 true false tukey(0.5) 0 0 false false false 0 3 0
3 false false tukey(0.5) 6 0 false false false 0 4 0
4 true true tukey(0.5) 8 0 false false false 0 4 0
5 true false tukey(0.5) 8 0 false false false 0 5 0
6 true false subdivide_tukey(2) 8 0 false false false 0 6 0
7 true false subdivide_tukey(2) 12 0 false false false 0 6 0
8 true false subdivide_tukey(3) 12 0 false false false 0 6 0
- * - * \default \c 5 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, uint32_t value); - -/** Set the blocksize to use while encoding. - * - * The number of samples to use per frame. Use \c 0 to let the encoder - * estimate a blocksize; this is usually best. - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, uint32_t value); - -/** Set to \c true to enable mid-side encoding on stereo input. The - * number of channels must be 2 for this to have any effect. Set to - * \c false to use only independent channel coding. - * - * \default \c true - * \param encoder An encoder instance to set. - * \param value Flag value (see above). - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value); - -/** Set to \c true to enable adaptive switching between mid-side and - * left-right encoding on stereo input. Set to \c false to use - * exhaustive searching. Setting this to \c true requires - * FLAC__stream_encoder_set_do_mid_side_stereo() to also be set to - * \c true in order to have any effect. - * - * \default \c false - * \param encoder An encoder instance to set. - * \param value Flag value (see above). - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value); - -/** Sets the apodization function(s) the encoder will use when windowing - * audio data for LPC analysis. - * - * The \a specification is a plain ASCII string which specifies exactly - * which functions to use. There may be more than one (up to 32), - * separated by \c ';' characters. Some functions take one or more - * comma-separated arguments in parentheses. - * - * The available functions are \c bartlett, \c bartlett_hann, - * \c blackman, \c blackman_harris_4term_92db, \c connes, \c flattop, - * \c gauss(STDDEV), \c hamming, \c hann, \c kaiser_bessel, \c nuttall, - * \c rectangle, \c triangle, \c tukey(P), \c partial_tukey(n[/ov[/P]]), - * \c punchout_tukey(n[/ov[/P]]), \c subdivide_tukey(n[/P]), \c welch. - * - * For \c gauss(STDDEV), STDDEV specifies the standard deviation - * (0blocksize / (2 ^ order). - * - * Set both min and max values to \c 0 to force a single context, - * whose Rice parameter is based on the residual signal variance. - * Otherwise, set a min and max order, and the encoder will search - * all orders, using the mean of each context for its Rice parameter, - * and use the best. - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, uint32_t value); - -/** Set the maximum partition order to search when coding the residual. - * This is used in tandem with - * FLAC__stream_encoder_set_min_residual_partition_order(). - * - * The partition order determines the context size in the residual. - * The context size will be approximately blocksize / (2 ^ order). - * - * Set both min and max values to \c 0 to force a single context, - * whose Rice parameter is based on the residual signal variance. - * Otherwise, set a min and max order, and the encoder will search - * all orders, using the mean of each context for its Rice parameter, - * and use the best. - * - * \default \c 5 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, uint32_t value); - -/** Deprecated. Setting this value has no effect. - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, uint32_t value); - -/** Set an estimate of the total samples that will be encoded. - * This is merely an estimate and may be set to \c 0 if unknown. - * This value will be written to the STREAMINFO block before encoding, - * and can remove the need for the caller to rewrite the value later - * if the value is known before encoding. - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value); - -/** Set the metadata blocks to be emitted to the stream before encoding. - * A value of \c NULL, \c 0 implies no metadata; otherwise, supply an - * array of pointers to metadata blocks. The array is non-const since - * the encoder may need to change the \a is_last flag inside them, and - * in some cases update seek point offsets. Otherwise, the encoder will - * not modify or free the blocks. It is up to the caller to free the - * metadata blocks after encoding finishes. - * - * \note - * The encoder stores only copies of the pointers in the \a metadata array; - * the metadata blocks themselves must survive at least until after - * FLAC__stream_encoder_finish() returns. Do not free the blocks until then. - * - * \note - * The STREAMINFO block is always written and no STREAMINFO block may - * occur in the supplied array. - * - * \note - * By default the encoder does not create a SEEKTABLE. If one is supplied - * in the \a metadata array, but the client has specified that it does not - * support seeking, then the SEEKTABLE will be written verbatim. However - * by itself this is not very useful as the client will not know the stream - * offsets for the seekpoints ahead of time. In order to get a proper - * seektable the client must support seeking. See next note. - * - * \note - * SEEKTABLE blocks are handled specially. Since you will not know - * the values for the seek point stream offsets, you should pass in - * a SEEKTABLE 'template', that is, a SEEKTABLE object with the - * required sample numbers (or placeholder points), with \c 0 for the - * \a frame_samples and \a stream_offset fields for each point. If the - * client has specified that it supports seeking by providing a seek - * callback to FLAC__stream_encoder_init_stream() or both seek AND read - * callback to FLAC__stream_encoder_init_ogg_stream() (or by using - * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE()), - * then while it is encoding the encoder will fill the stream offsets in - * for you and when encoding is finished, it will seek back and write the - * real values into the SEEKTABLE block in the stream. There are helper - * routines for manipulating seektable template blocks; see metadata.h: - * FLAC__metadata_object_seektable_template_*(). If the client does - * not support seeking, the SEEKTABLE will have inaccurate offsets which - * will slow down or remove the ability to seek in the FLAC stream. - * - * \note - * The encoder instance \b will modify the first \c SEEKTABLE block - * as it transforms the template to a valid seektable while encoding, - * but it is still up to the caller to free all metadata blocks after - * encoding. - * - * \note - * A VORBIS_COMMENT block may be supplied. The vendor string in it - * will be ignored. libFLAC will use it's own vendor string. libFLAC - * will not modify the passed-in VORBIS_COMMENT's vendor string, it - * will simply write it's own into the stream. If no VORBIS_COMMENT - * block is present in the \a metadata array, libFLAC will write an - * empty one, containing only the vendor string. - * - * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be - * the second metadata block of the stream. The encoder already supplies - * the STREAMINFO block automatically. If \a metadata does not contain a - * VORBIS_COMMENT block, the encoder will supply that too. Otherwise, if - * \a metadata does contain a VORBIS_COMMENT block and it is not the - * first, the init function will reorder \a metadata by moving the - * VORBIS_COMMENT block to the front; the relative ordering of the other - * blocks will remain as they were. - * - * \note The Ogg FLAC mapping limits the number of metadata blocks per - * stream to \c 65535. If \a num_blocks exceeds this the function will - * return \c false. - * - * \default \c NULL, 0 - * \param encoder An encoder instance to set. - * \param metadata See above. - * \param num_blocks See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - * \c false if the encoder is already initialized, or if - * \a num_blocks > 65535 if encoding to Ogg FLAC, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, uint32_t num_blocks); - -/** Set to \c true to make the encoder not output frames which contain - * only constant subframes. This is beneficial for streaming - * applications: very small frames can cause problems with buffering - * as bitrates can drop as low 1kbit/s for CDDA audio encoded within - * subset. The minimum bitrate for a FLAC file encoded with this - * function used is raised to 1bit/sample (i.e. 48kbit/s for 48kHz - * material). - * - * \default \c false - * \param encoder An encoder instance to set. - * \param value Flag value (see above). - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_limit_min_bitrate(FLAC__StreamEncoder *encoder, FLAC__bool value); - -/** Get the current encoder state. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__StreamEncoderState - * The current encoder state. - */ -FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder); - -/** Get the state of the verify stream decoder. - * Useful when the stream encoder state is - * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__StreamDecoderState - * The verify stream decoder state. - */ -FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder); - -/** Get the current encoder state as a C string. - * This version automatically resolves - * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR by getting the - * verify decoder's state. - * - * \param encoder A encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval const char * - * The encoder state as a C string. Do not modify the contents. - */ -FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder); - -/** Get relevant values about the nature of a verify decoder error. - * Useful when the stream encoder state is - * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. The arguments should - * be addresses in which the stats will be returned, or NULL if value - * is not desired. - * - * \param encoder An encoder instance to query. - * \param absolute_sample The absolute sample number of the mismatch. - * \param frame_number The number of the frame in which the mismatch occurred. - * \param channel The channel in which the mismatch occurred. - * \param sample The number of the sample (relative to the frame) in - * which the mismatch occurred. - * \param expected The expected value for the sample in question. - * \param got The actual value returned by the decoder. - * \assert - * \code encoder != NULL \endcode - */ -FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, uint32_t *frame_number, uint32_t *channel, uint32_t *sample, FLAC__int32 *expected, FLAC__int32 *got); - -/** Get the "verify" flag. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See FLAC__stream_encoder_set_verify(). - */ -FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder); - -/** Get the Subset flag. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See FLAC__stream_encoder_set_streamable_subset(). - */ -FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder); - -/** Get the number of input channels being processed. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval uint32_t - * See FLAC__stream_encoder_set_channels(). - */ -FLAC_API uint32_t FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder); - -/** Get the input sample resolution setting. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval uint32_t - * See FLAC__stream_encoder_set_bits_per_sample(). - */ -FLAC_API uint32_t FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder); - -/** Get the input sample rate setting. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval uint32_t - * See FLAC__stream_encoder_set_sample_rate(). - */ -FLAC_API uint32_t FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder); - -/** Get the blocksize setting. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval uint32_t - * See FLAC__stream_encoder_set_blocksize(). - */ -FLAC_API uint32_t FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder); - -/** Get the "mid/side stereo coding" flag. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See FLAC__stream_encoder_get_do_mid_side_stereo(). - */ -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder); - -/** Get the "adaptive mid/side switching" flag. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See FLAC__stream_encoder_set_loose_mid_side_stereo(). - */ -FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder); - -/** Get the maximum LPC order setting. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval uint32_t - * See FLAC__stream_encoder_set_max_lpc_order(). - */ -FLAC_API uint32_t FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder); - -/** Get the quantized linear predictor coefficient precision setting. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval uint32_t - * See FLAC__stream_encoder_set_qlp_coeff_precision(). - */ -FLAC_API uint32_t FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder); - -/** Get the qlp coefficient precision search flag. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See FLAC__stream_encoder_set_do_qlp_coeff_prec_search(). - */ -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder); - -/** Get the "escape coding" flag. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See FLAC__stream_encoder_set_do_escape_coding(). - */ -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder); - -/** Get the exhaustive model search flag. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See FLAC__stream_encoder_set_do_exhaustive_model_search(). - */ -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder); - -/** Get the minimum residual partition order setting. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval uint32_t - * See FLAC__stream_encoder_set_min_residual_partition_order(). - */ -FLAC_API uint32_t FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder); - -/** Get maximum residual partition order setting. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval uint32_t - * See FLAC__stream_encoder_set_max_residual_partition_order(). - */ -FLAC_API uint32_t FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder); - -/** Get the Rice parameter search distance setting. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval uint32_t - * See FLAC__stream_encoder_set_rice_parameter_search_dist(). - */ -FLAC_API uint32_t FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder); - -/** Get the previously set estimate of the total samples to be encoded. - * The encoder merely mimics back the value given to - * FLAC__stream_encoder_set_total_samples_estimate() since it has no - * other way of knowing how many samples the client will encode. - * - * \param encoder An encoder instance to set. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__uint64 - * See FLAC__stream_encoder_get_total_samples_estimate(). - */ -FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder); - -/** Get the "limit_min_bitrate" flag. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See FLAC__stream_encoder_set_limit_min_bitrate(). - */ -FLAC_API FLAC__bool FLAC__stream_encoder_get_limit_min_bitrate(const FLAC__StreamEncoder *encoder); - -/** Initialize the encoder instance to encode native FLAC streams. - * - * This flavor of initialization sets up the encoder to encode to a - * native FLAC stream. I/O is performed via callbacks to the client. - * For encoding to a plain file via filename or open \c FILE*, - * FLAC__stream_encoder_init_file() and FLAC__stream_encoder_init_FILE() - * provide a simpler interface. - * - * This function should be called after FLAC__stream_encoder_new() and - * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() - * or FLAC__stream_encoder_process_interleaved(). - * initialization succeeded. - * - * The call to FLAC__stream_encoder_init_stream() currently will also - * immediately call the write callback several times, once with the \c fLaC - * signature, and once for each encoded metadata block. - * - * \param encoder An uninitialized encoder instance. - * \param write_callback See FLAC__StreamEncoderWriteCallback. This - * pointer must not be \c NULL. - * \param seek_callback See FLAC__StreamEncoderSeekCallback. This - * pointer may be \c NULL if seeking is not - * supported. The encoder uses seeking to go back - * and write some some stream statistics to the - * STREAMINFO block; this is recommended but not - * necessary to create a valid FLAC stream. If - * \a seek_callback is not \c NULL then a - * \a tell_callback must also be supplied. - * Alternatively, a dummy seek callback that just - * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the encoder. - * \param tell_callback See FLAC__StreamEncoderTellCallback. This - * pointer may be \c NULL if seeking is not - * supported. If \a seek_callback is \c NULL then - * this argument will be ignored. If - * \a seek_callback is not \c NULL then a - * \a tell_callback must also be supplied. - * Alternatively, a dummy tell callback that just - * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the encoder. - * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. If the client provides a seek callback, - * this function is not necessary as the encoder - * will automatically seek back and update the - * STREAMINFO block. It may also be \c NULL if the - * client does not support seeking, since it will - * have no way of going back to update the - * STREAMINFO. However the client can still supply - * a callback if it would like to know the details - * from the STREAMINFO. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__StreamEncoderInitStatus - * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamEncoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data); - -/** Initialize the encoder instance to encode Ogg FLAC streams. - * - * This flavor of initialization sets up the encoder to encode to a FLAC - * stream in an Ogg container. I/O is performed via callbacks to the - * client. For encoding to a plain file via filename or open \c FILE*, - * FLAC__stream_encoder_init_ogg_file() and FLAC__stream_encoder_init_ogg_FILE() - * provide a simpler interface. - * - * This function should be called after FLAC__stream_encoder_new() and - * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() - * or FLAC__stream_encoder_process_interleaved(). - * initialization succeeded. - * - * The call to FLAC__stream_encoder_init_ogg_stream() currently will also - * immediately call the write callback several times to write the metadata - * packets. - * - * \param encoder An uninitialized encoder instance. - * \param read_callback See FLAC__StreamEncoderReadCallback. This - * pointer must not be \c NULL if \a seek_callback - * is non-NULL since they are both needed to be - * able to write data back to the Ogg FLAC stream - * in the post-encode phase. - * \param write_callback See FLAC__StreamEncoderWriteCallback. This - * pointer must not be \c NULL. - * \param seek_callback See FLAC__StreamEncoderSeekCallback. This - * pointer may be \c NULL if seeking is not - * supported. The encoder uses seeking to go back - * and write some some stream statistics to the - * STREAMINFO block; this is recommended but not - * necessary to create a valid FLAC stream. If - * \a seek_callback is not \c NULL then a - * \a tell_callback must also be supplied. - * Alternatively, a dummy seek callback that just - * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the encoder. - * \param tell_callback See FLAC__StreamEncoderTellCallback. This - * pointer may be \c NULL if seeking is not - * supported. If \a seek_callback is \c NULL then - * this argument will be ignored. If - * \a seek_callback is not \c NULL then a - * \a tell_callback must also be supplied. - * Alternatively, a dummy tell callback that just - * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the encoder. - * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. If the client provides a seek callback, - * this function is not necessary as the encoder - * will automatically seek back and update the - * STREAMINFO block. It may also be \c NULL if the - * client does not support seeking, since it will - * have no way of going back to update the - * STREAMINFO. However the client can still supply - * a callback if it would like to know the details - * from the STREAMINFO. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__StreamEncoderInitStatus - * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamEncoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data); - -/** Initialize the encoder instance to encode native FLAC files. - * - * This flavor of initialization sets up the encoder to encode to a - * plain native FLAC file. For non-stdio streams, you must use - * FLAC__stream_encoder_init_stream() and provide callbacks for the I/O. - * - * This function should be called after FLAC__stream_encoder_new() and - * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() - * or FLAC__stream_encoder_process_interleaved(). - * initialization succeeded. - * - * \param encoder An uninitialized encoder instance. - * \param file An open file. The file should have been opened - * with mode \c "w+b" and rewound. The file - * becomes owned by the encoder and should not be - * manipulated by the client while encoding. - * Unless \a file is \c stdout, it will be closed - * when FLAC__stream_encoder_finish() is called. - * Note however that a proper SEEKTABLE cannot be - * created when encoding to \c stdout since it is - * not seekable. - * \param progress_callback See FLAC__StreamEncoderProgressCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code encoder != NULL \endcode - * \code file != NULL \endcode - * \retval FLAC__StreamEncoderInitStatus - * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamEncoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data); - -/** Initialize the encoder instance to encode Ogg FLAC files. - * - * This flavor of initialization sets up the encoder to encode to a - * plain Ogg FLAC file. For non-stdio streams, you must use - * FLAC__stream_encoder_init_ogg_stream() and provide callbacks for the I/O. - * - * This function should be called after FLAC__stream_encoder_new() and - * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() - * or FLAC__stream_encoder_process_interleaved(). - * initialization succeeded. - * - * \param encoder An uninitialized encoder instance. - * \param file An open file. The file should have been opened - * with mode \c "w+b" and rewound. The file - * becomes owned by the encoder and should not be - * manipulated by the client while encoding. - * Unless \a file is \c stdout, it will be closed - * when FLAC__stream_encoder_finish() is called. - * Note however that a proper SEEKTABLE cannot be - * created when encoding to \c stdout since it is - * not seekable. - * \param progress_callback See FLAC__StreamEncoderProgressCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code encoder != NULL \endcode - * \code file != NULL \endcode - * \retval FLAC__StreamEncoderInitStatus - * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamEncoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data); - -/** Initialize the encoder instance to encode native FLAC files. - * - * This flavor of initialization sets up the encoder to encode to a plain - * FLAC file. If POSIX fopen() semantics are not sufficient you must use - * FLAC__stream_encoder_init_FILE(), or FLAC__stream_encoder_init_stream() - * and provide callbacks for the I/O. - * - * On Windows, filename must be a UTF-8 encoded filename, which libFLAC - * internally translates to an appropriate representation to use with - * _wfopen. On all other systems, filename is passed to fopen without - * any translation. - * - * This function should be called after FLAC__stream_encoder_new() and - * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() - * or FLAC__stream_encoder_process_interleaved(). - * initialization succeeded. - * - * \param encoder An uninitialized encoder instance. - * \param filename The name of the file to encode to. The file will - * be opened with fopen(). Use \c NULL to encode to - * \c stdout. Note however that a proper SEEKTABLE - * cannot be created when encoding to \c stdout since - * it is not seekable. - * \param progress_callback See FLAC__StreamEncoderProgressCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__StreamEncoderInitStatus - * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamEncoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data); - -/** Initialize the encoder instance to encode Ogg FLAC files. - * - * This flavor of initialization sets up the encoder to encode to a plain - * Ogg FLAC file. If POSIX fopen() semantics are not sufficient, you must use - * FLAC__stream_encoder_init_ogg_FILE(), or FLAC__stream_encoder_init_ogg_stream() - * and provide callbacks for the I/O. - * - * On Windows, filename must be a UTF-8 encoded filename, which libFLAC - * internally translates to an appropriate representation to use with - * _wfopen. On all other systems, filename is passed to fopen without - * any translation. - * - * This function should be called after FLAC__stream_encoder_new() and - * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() - * or FLAC__stream_encoder_process_interleaved(). - * initialization succeeded. - * - * \param encoder An uninitialized encoder instance. - * \param filename The name of the file to encode to. The file will - * be opened with fopen(). Use \c NULL to encode to - * \c stdout. Note however that a proper SEEKTABLE - * cannot be created when encoding to \c stdout since - * it is not seekable. - * \param progress_callback See FLAC__StreamEncoderProgressCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__StreamEncoderInitStatus - * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamEncoderInitStatus for the meanings of other return values. - */ -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data); - -/** Finish the encoding process. - * Flushes the encoding buffer, releases resources, resets the encoder - * settings to their defaults, and returns the encoder state to - * FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate - * one or more write callbacks before returning, and will generate - * a metadata callback. - * - * Note that in the course of processing the last frame, errors can - * occur, so the caller should be sure to check the return value to - * ensure the file was encoded properly. - * - * In the event of a prematurely-terminated encode, it is not strictly - * necessary to call this immediately before FLAC__stream_encoder_delete() - * but it is good practice to match every FLAC__stream_encoder_init_*() - * with a FLAC__stream_encoder_finish(). - * - * \param encoder An uninitialized encoder instance. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if an error occurred processing the last frame; or if verify - * mode is set (see FLAC__stream_encoder_set_verify()), there was a - * verify mismatch; else \c true. If \c false, caller should check the - * state with FLAC__stream_encoder_get_state() for more information - * about the error. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder); - -/** Submit data for encoding. - * This version allows you to supply the input data via an array of - * pointers, each pointer pointing to an array of \a samples samples - * representing one channel. The samples need not be block-aligned, - * but each channel should have the same number of samples. Each sample - * should be a signed integer, right-justified to the resolution set by - * FLAC__stream_encoder_set_bits_per_sample(). For example, if the - * resolution is 16 bits per sample, the samples should all be in the - * range [-32768,32767]. - * - * For applications where channel order is important, channels must - * follow the order as described in the - * frame header. - * - * \param encoder An initialized encoder instance in the OK state. - * \param buffer An array of pointers to each channel's signal. - * \param samples The number of samples in one channel. - * \assert - * \code encoder != NULL \endcode - * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode - * \retval FLAC__bool - * \c true if successful, else \c false; in this case, check the - * encoder state with FLAC__stream_encoder_get_state() to see what - * went wrong. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], uint32_t samples); - -/** Submit data for encoding. - * This version allows you to supply the input data where the channels - * are interleaved into a single array (i.e. channel0_sample0, - * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...). - * The samples need not be block-aligned but they must be - * sample-aligned, i.e. the first value should be channel0_sample0 - * and the last value channelN_sampleM. Each sample should be a signed - * integer, right-justified to the resolution set by - * FLAC__stream_encoder_set_bits_per_sample(). For example, if the - * resolution is 16 bits per sample, the samples should all be in the - * range [-32768,32767]. - * - * For applications where channel order is important, channels must - * follow the order as described in the - * frame header. - * - * \param encoder An initialized encoder instance in the OK state. - * \param buffer An array of channel-interleaved data (see above). - * \param samples The number of samples in one channel, the same as for - * FLAC__stream_encoder_process(). For example, if - * encoding two channels, \c 1000 \a samples corresponds - * to a \a buffer of 2000 values. - * \assert - * \code encoder != NULL \endcode - * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode - * \retval FLAC__bool - * \c true if successful, else \c false; in this case, check the - * encoder state with FLAC__stream_encoder_get_state() to see what - * went wrong. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], uint32_t samples); - -/* \} */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flac/include/Makefile.am b/flac/include/Makefile.am deleted file mode 100644 index 01c5c9b..0000000 --- a/flac/include/Makefile.am +++ /dev/null @@ -1,23 +0,0 @@ -# FLAC - Free Lossless Audio Codec -# Copyright (C) 2001-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# This file is part the FLAC project. FLAC is comprised of several -# components distributed under different licenses. The codec libraries -# are distributed under Xiph.Org's BSD-like license (see the file -# COPYING.Xiph in this distribution). All other programs, libraries, and -# plugins are distributed under the GPL (see COPYING.GPL). The documentation -# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the -# FLAC distribution contains at the top the terms under which it may be -# distributed. -# -# Since this particular file is relevant to all components of FLAC, -# it may be distributed under the Xiph.Org license, which is the least -# restrictive of those mentioned above. See the file COPYING.Xiph in this -# distribution. - -if FLaC__WITH_CPPLIBS -CPPLIBS_DIRS = FLAC++ -endif - -SUBDIRS = FLAC $(CPPLIBS_DIRS) share test_libs_common diff --git a/flac/include/share/Makefile.am b/flac/include/share/Makefile.am deleted file mode 100644 index a6a3ca0..0000000 --- a/flac/include/share/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = grabbag - -EXTRA_DIST = \ - alloc.h \ - compat.h \ - endswap.h \ - getopt.h \ - grabbag.h \ - macros.h \ - private.h \ - replaygain_analysis.h \ - replaygain_synthesis.h \ - safe_str.h \ - utf8.h \ - win_utf8_io.h diff --git a/flac/include/share/alloc.h b/flac/include/share/alloc.h deleted file mode 100644 index b0da694..0000000 --- a/flac/include/share/alloc.h +++ /dev/null @@ -1,318 +0,0 @@ -/* alloc - Convenience routines for safely allocating memory - * Copyright (C) 2007-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__SHARE__ALLOC_H -#define FLAC__SHARE__ALLOC_H - -#ifdef HAVE_CONFIG_H -# include -#endif - -/* WATCHOUT: for c++ you may have to #define __STDC_LIMIT_MACROS 1 real early - * before #including this file, otherwise SIZE_MAX might not be defined - */ - -#include /* for SIZE_MAX */ -#ifdef HAVE_STDINT_H -#include /* for SIZE_MAX in case limits.h didn't get it */ -#endif -#include /* for size_t, malloc(), etc */ -#include "share/compat.h" - -#ifndef SIZE_MAX -# ifndef SIZE_T_MAX -# ifdef _MSC_VER -# ifdef _WIN64 -# define SIZE_T_MAX FLAC__U64L(0xffffffffffffffff) -# else -# define SIZE_T_MAX 0xffffffff -# endif -# else -# error -# endif -# endif -# define SIZE_MAX SIZE_T_MAX -#endif - -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -extern int alloc_check_threshold, alloc_check_counter; - -static inline int alloc_check() { - if(alloc_check_threshold == INT32_MAX) - return 0; - else if(alloc_check_counter++ == alloc_check_threshold) - return 1; - else - return 0; -} - -#endif - -/* avoid malloc()ing 0 bytes, see: - * https://www.securecoding.cert.org/confluence/display/seccode/MEM04-A.+Do+not+make+assumptions+about+the+result+of+allocating+0+bytes?focusedCommentId=5407003 -*/ - -static inline void *safe_malloc_(size_t size) -{ -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* Fail if requested */ - if(alloc_check()) - return NULL; -#endif - /* malloc(0) is undefined; FLAC src convention is to always allocate */ - if(!size) - size++; - return malloc(size); -} - -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -static inline void *malloc_(size_t size) -{ - /* Fail if requested */ - if(alloc_check()) - return NULL; - return malloc(size); -} -#else -#define malloc_ malloc -#endif - - - -static inline void *safe_calloc_(size_t nmemb, size_t size) -{ -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* Fail if requested */ - if(alloc_check()) - return NULL; -#endif - if(!nmemb || !size) - return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */ - return calloc(nmemb, size); -} - -/*@@@@ there's probably a better way to prevent overflows when allocating untrusted sums but this works for now */ - -static inline void *safe_malloc_add_2op_(size_t size1, size_t size2) -{ - size2 += size1; - if(size2 < size1) - return 0; - return safe_malloc_(size2); -} - -static inline void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3) -{ - size2 += size1; - if(size2 < size1) - return 0; - size3 += size2; - if(size3 < size2) - return 0; - return safe_malloc_(size3); -} - -static inline void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4) -{ - size2 += size1; - if(size2 < size1) - return 0; - size3 += size2; - if(size3 < size2) - return 0; - size4 += size3; - if(size4 < size3) - return 0; - return safe_malloc_(size4); -} - -void *safe_malloc_mul_2op_(size_t size1, size_t size2) ; - -static inline void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3) -{ - if(!size1 || !size2 || !size3) - return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */ - if(size1 > SIZE_MAX / size2) - return 0; - size1 *= size2; - if(size1 > SIZE_MAX / size3) - return 0; - return malloc_(size1*size3); -} - -/* size1*size2 + size3 */ -static inline void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3) -{ - if(!size1 || !size2) - return safe_malloc_(size3); - if(size1 > SIZE_MAX / size2) - return 0; - return safe_malloc_add_2op_(size1*size2, size3); -} - -/* size1 * (size2 + size3) */ -static inline void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3) -{ - if(!size1 || (!size2 && !size3)) - return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */ - size2 += size3; - if(size2 < size3) - return 0; - if(size1 > SIZE_MAX / size2) - return 0; - return malloc_(size1*size2); -} - -static inline void *safe_realloc_(void *ptr, size_t size) -{ - void *oldptr; - void *newptr; -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* Fail if requested */ - if(alloc_check() && size > 0) { - free(ptr); - return NULL; - } -#endif - oldptr = ptr; - newptr = realloc(ptr, size); - if(size > 0 && newptr == 0) - free(oldptr); - return newptr; -} - -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -static inline void *realloc_(void *ptr, size_t size) -{ - /* Fail if requested */ - if(alloc_check()) - return NULL; - return realloc(ptr, size); -} -#else -#define realloc_ realloc -#endif - - -static inline void *safe_realloc_nofree_add_2op_(void *ptr, size_t size1, size_t size2) -{ - size2 += size1; - if(size2 < size1) - return 0; - return realloc_(ptr, size2); -} - -static inline void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3) -{ - size2 += size1; - if(size2 < size1) { - free(ptr); - return 0; - } - size3 += size2; - if(size3 < size2) { - free(ptr); - return 0; - } - return safe_realloc_(ptr, size3); -} - -static inline void *safe_realloc_nofree_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3) -{ - size2 += size1; - if(size2 < size1) - return 0; - size3 += size2; - if(size3 < size2) - return 0; - return realloc_(ptr, size3); -} - -static inline void *safe_realloc_nofree_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4) -{ - size2 += size1; - if(size2 < size1) - return 0; - size3 += size2; - if(size3 < size2) - return 0; - size4 += size3; - if(size4 < size3) - return 0; - return realloc_(ptr, size4); -} - -static inline void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2) -{ - if(!size1 || !size2) - return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */ - if(size1 > SIZE_MAX / size2) { - free(ptr); - return 0; - } - return safe_realloc_(ptr, size1*size2); -} - -static inline void *safe_realloc_nofree_mul_2op_(void *ptr, size_t size1, size_t size2) -{ - if(!size1 || !size2) - return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */ - if(size1 > SIZE_MAX / size2) - return 0; - return realloc_(ptr, size1*size2); -} - -/* size1 * (size2 + size3) */ -static inline void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3) -{ - if(!size1 || (!size2 && !size3)) - return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */ - size2 += size3; - if(size2 < size3) { - free(ptr); - return 0; - } - return safe_realloc_mul_2op_(ptr, size1, size2); -} - -/* size1 * (size2 + size3) */ -static inline void *safe_realloc_nofree_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3) -{ - if(!size1 || (!size2 && !size3)) - return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */ - size2 += size3; - if(size2 < size3) - return 0; - return safe_realloc_nofree_mul_2op_(ptr, size1, size2); -} - -#endif diff --git a/flac/include/share/compat.h b/flac/include/share/compat.h deleted file mode 100644 index 6ce23a5..0000000 --- a/flac/include/share/compat.h +++ /dev/null @@ -1,240 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2012-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -/* This is the preferred location of all CPP hackery to make $random_compiler - * work like something approaching a C99 (or maybe more accurately GNU99) - * compiler. - * - * It is assumed that this header will be included after "config.h". - */ - -#ifndef FLAC__SHARE__COMPAT_H -#define FLAC__SHARE__COMPAT_H - -#include -#include - -#if defined _WIN32 && !defined __CYGWIN__ -/* where MSVC puts unlink() */ -# include -#else -# include -#endif - -#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ -#include /* for off_t */ -#define FLAC__off_t __int64 /* use this instead of off_t to fix the 2 GB limit */ -#define FLAC__OFF_T_MAX INT64_MAX -#if !defined __MINGW32__ -#define fseeko _fseeki64 -#define ftello _ftelli64 -#else /* MinGW */ -#if !defined(HAVE_FSEEKO) -#define fseeko fseeko64 -#define ftello ftello64 -#endif -#endif -#else -#define FLAC__off_t off_t -#define FLAC__OFF_T_MAX OFF_T_MAX -#endif - - - -#ifdef HAVE_INTTYPES_H -#define __STDC_FORMAT_MACROS -#include -#endif - -#if defined(_MSC_VER) -#define strtoll _strtoi64 -#define strtoull _strtoui64 -#endif - -#if defined(_MSC_VER) && !defined(__cplusplus) -#define inline __inline -#endif - -#if defined __INTEL_COMPILER || (defined _MSC_VER && defined _WIN64) -/* MSVS generates VERY slow 32-bit code with __restrict */ -#define flac_restrict __restrict -#elif defined __GNUC__ -#define flac_restrict __restrict__ -#else -#define flac_restrict -#endif - -#define FLAC__U64L(x) x##ULL - -#if defined _MSC_VER || defined __MINGW32__ -#define FLAC__STRCASECMP _stricmp -#define FLAC__STRNCASECMP _strnicmp -#elif defined __BORLANDC__ -#define FLAC__STRCASECMP stricmp -#define FLAC__STRNCASECMP strnicmp -#else -#define FLAC__STRCASECMP strcasecmp -#define FLAC__STRNCASECMP strncasecmp -#endif - -#if defined _MSC_VER || defined __MINGW32__ || defined __EMX__ -#include /* for _setmode(), chmod() */ -#include /* for _O_BINARY */ -#else -#include /* for chown(), unlink() */ -#endif - -#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ -#if defined __BORLANDC__ -#include /* for utime() */ -#else -#include /* for utime() */ -#endif -#else -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) -#include -#else -#include /* some flavors of BSD (like OS X) require this to get time_t */ -#include /* for utime() */ -#endif -#endif - -#if defined _MSC_VER -# if _MSC_VER >= 1800 -# include -# elif _MSC_VER >= 1600 -/* Visual Studio 2010 has decent C99 support */ -# include -# define PRIu64 "llu" -# define PRId64 "lld" -# define PRIx64 "llx" -# else -# include -# ifndef UINT32_MAX -# define UINT32_MAX _UI32_MAX -# endif -# define PRIu64 "I64u" -# define PRId64 "I64d" -# define PRIx64 "I64x" -# endif -# if defined(_USING_V110_SDK71_) && !defined(_DLL) -# pragma message("WARNING: This compile will NOT FUNCTION PROPERLY on Windows XP. See comments in include/share/compat.h for details") -#define FLAC__USE_FILELENGTHI64 -/* - ************************************************************************************* - * V110_SDK71, in MSVC 2017 also known as v141_xp, is a platform toolset that is supposed - * to target Windows XP. It turns out however that certain functions provided silently fail - * on Windows XP only, which makes debugging challenging. This only occurs when building with - * /MT. This problem has been reported to Microsoft, but there hasn't been a fix for years. See - * https://web.archive.org/web/20170327195018/https://connect.microsoft.com/VisualStudio/feedback/details/1557168/wstat64-returns-1-on-xp-always - * - * It is known that this problem affects the functions _wstat64 (used by flac_stat i.e. - * stat64_utf8) and _fstat64 (i.e. flac_fstat) and therefore affects both libFLAC in - * several places as well as the flac and metaflac command line tools - * - * As the extent of this problem is unknown and Microsoft seems unwilling to fix it, - * users of libFLAC building with Visual Studio are encouraged to not use the /MT compile - * switch when explicitly targeting Windows XP. When use of /MT is deemed necessary with - * this toolset, be sure to check whether your application works properly on Windows XP. - * It is also possible to build for Windows XP with MinGW instead. - ************************************************************************************* -*/ -# endif -#endif /* defined _MSC_VER */ - -#ifdef _WIN32 -/* All char* strings are in UTF-8 format. Added to support Unicode files on Windows */ - -#include "share/win_utf8_io.h" -#define flac_printf printf_utf8 -#define flac_fprintf fprintf_utf8 -#define flac_vfprintf vfprintf_utf8 -#define flac_fopen fopen_utf8 -#define flac_chmod chmod_utf8 -#define flac_utime utime_utf8 -#define flac_unlink unlink_utf8 -#define flac_rename rename_utf8 -#define flac_stat stat64_utf8 - -#else - -#define flac_printf printf -#define flac_fprintf fprintf -#define flac_vfprintf vfprintf - -#define flac_fopen fopen -#define flac_chmod chmod -#define flac_unlink unlink -#define flac_rename rename -#define flac_stat stat - -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) -#define flac_utime(a, b) utimensat (AT_FDCWD, a, *b, 0) -#else -#define flac_utime utime -#endif -#endif - -#ifdef _WIN32 -#define flac_stat_s __stat64 /* stat struct */ -#define flac_fstat _fstat64 -#else -#define flac_stat_s stat /* stat struct */ -#define flac_fstat fstat -#endif - -#ifdef ANDROID -#include -#endif - -#ifndef M_LN2 -#define M_LN2 0.69314718055994530942 -#endif -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -/* FLAC needs to compile and work correctly on systems with a normal ISO C99 - * snprintf as well as Microsoft Visual Studio which has an non-standards - * conformant snprint_s function. - * - * This function wraps the MS version to behave more like the ISO version. - */ -#ifdef __cplusplus -extern "C" { -#endif -int flac_snprintf(char *str, size_t size, const char *fmt, ...); -int flac_vsnprintf(char *str, size_t size, const char *fmt, va_list va); -#ifdef __cplusplus -}; -#endif - -#endif /* FLAC__SHARE__COMPAT_H */ diff --git a/flac/include/share/endswap.h b/flac/include/share/endswap.h deleted file mode 100644 index 8687b9d..0000000 --- a/flac/include/share/endswap.h +++ /dev/null @@ -1,84 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2012-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -/* It is assumed that this header will be included after "config.h". */ - -#ifdef HAVE_BSWAP32 /* GCC and Clang */ - -/* GCC prior to 4.8 didn't provide bswap16 on x86_64 */ -#ifndef HAVE_BSWAP16 -static inline unsigned short __builtin_bswap16(unsigned short a) -{ - return (a<<8)|(a>>8); -} -#endif - -#define ENDSWAP_16(x) (__builtin_bswap16 (x)) -#define ENDSWAP_32(x) (__builtin_bswap32 (x)) -#define ENDSWAP_64(x) (__builtin_bswap64 (x)) - -#elif defined _MSC_VER /* Windows */ - -#include - -#define ENDSWAP_16(x) (_byteswap_ushort (x)) -#define ENDSWAP_32(x) (_byteswap_ulong (x)) -#define ENDSWAP_64(x) (_byteswap_uint64 (x)) - -#elif defined HAVE_BYTESWAP_H /* Linux */ - -#include - -#define ENDSWAP_16(x) (bswap_16 (x)) -#define ENDSWAP_32(x) (bswap_32 (x)) -#define ENDSWAP_64(x) (bswap_64 (x)) - -#else - -#define ENDSWAP_16(x) ((((x) >> 8) & 0xFF) | (((x) & 0xFF) << 8)) -#define ENDSWAP_32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) & 0xFF00) << 8) | (((x) & 0xFF) << 24)) -#define ENDSWAP_64(x) ((ENDSWAP_32(((x) >> 32) & 0xFFFFFFFF)) | (ENDSWAP_32((x) & 0xFFFFFFFF) << 32)) - -#endif - - -/* Host to little-endian byte swapping (for MD5 calculation) */ -#if CPU_IS_BIG_ENDIAN - -#define H2LE_16(x) ENDSWAP_16 (x) -#define H2LE_32(x) ENDSWAP_32 (x) - -#else - -#define H2LE_16(x) (x) -#define H2LE_32(x) (x) - -#endif diff --git a/flac/include/share/getopt.h b/flac/include/share/getopt.h deleted file mode 100644 index 66aced0..0000000 --- a/flac/include/share/getopt.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - NOTE: - I cannot get the vanilla getopt code to work (i.e. compile only what - is needed and not duplicate symbols found in the standard library) - on all the platforms that FLAC supports. In particular the gating - of code with the ELIDE_CODE #define is not accurate enough on systems - that are POSIX but not glibc. If someone has a patch that works on - GNU/Linux, Darwin, AND Solaris please submit it on the project page: - https://sourceforge.net/p/flac/patches/ - - In the meantime I have munged the global symbols and removed gates - around code, while at the same time trying to touch the original as - little as possible. -*/ -/* Declarations for getopt. - Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ - -#ifndef SHARE__GETOPT_H -#define SHARE__GETOPT_H - -/*[JEC] was:#ifndef __need_getopt*/ -/*[JEC] was:# define _GETOPT_H 1*/ -/*[JEC] was:#endif*/ - -#ifdef __cplusplus -extern "C" { -#endif - -/* For communication from `share__getopt' to the caller. - When `share__getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -extern char *share__optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `share__getopt'. - - On entry to `share__getopt', zero means this is the first call; initialize. - - When `share__getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `share__optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -extern int share__optind; - -/* Callers store zero here to inhibit the error message `share__getopt' prints - for unrecognized options. */ - -extern int share__opterr; - -/* Set to an option character which was unrecognized. */ - -extern int share__optopt; - -/*[JEC] was:#ifndef __need_getopt */ -/* Describe the long-named options requested by the application. - The LONG_OPTIONS argument to share__getopt_long or share__getopt_long_only is a vector - of `struct share__option' terminated by an element containing a name which is - zero. - - The field `has_arg' is: - share__no_argument (or 0) if the option does not take an argument, - share__required_argument (or 1) if the option requires an argument, - share__optional_argument (or 2) if the option takes an optional argument. - - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `share__optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `share__getopt' - returns the contents of the `val' field. */ - -struct share__option -{ -# if defined __STDC__ && __STDC__ - const char *name; -# else - char *name; -# endif - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* Names for the values of the `has_arg' field of `struct share__option'. */ - -# define share__no_argument 0 -# define share__required_argument 1 -# define share__optional_argument 2 -/*[JEC] was:#endif*/ /* need getopt */ - - -/* Get definitions and prototypes for functions to process the - arguments in ARGV (ARGC of them, minus the program name) for - options given in OPTS. - - Return the option character from OPTS just read. Return -1 when - there are no more options. For unrecognized options, or options - missing arguments, `share__optopt' is set to the option letter, and '?' is - returned. - - The OPTS string is a list of characters which are recognized option - letters, optionally followed by colons, specifying that that letter - takes an argument, to be placed in `share__optarg'. - - If a letter in OPTS is followed by two colons, its argument is - optional. This behavior is specific to the GNU `share__getopt'. - - The argument `--' causes premature termination of argument - scanning, explicitly telling `share__getopt' that there are no more - options. - - If OPTS begins with `--', then non-option arguments are treated as - arguments to the option '\0'. This behavior is specific to the GNU - `share__getopt'. */ - -/*[JEC] was:#if defined __STDC__ && __STDC__*/ -/*[JEC] was:# ifdef __GNU_LIBRARY__*/ -/* Many other libraries have conflicting prototypes for getopt, with - differences in the consts, in stdlib.h. To avoid compilation - errors, only prototype getopt for the GNU C library. */ -extern int share__getopt (int argc, char *const *argv, const char *shortopts); -/*[JEC] was:# else*/ /* not __GNU_LIBRARY__ */ -/*[JEC] was:extern int getopt ();*/ -/*[JEC] was:# endif*/ /* __GNU_LIBRARY__ */ - -/*[JEC] was:# ifndef __need_getopt*/ -extern int share__getopt_long (int argc, char *const *argv, const char *shortopts, - const struct share__option *longopts, int *longind); -extern int share__getopt_long_only (int argc, char *const *argv, - const char *shortopts, - const struct share__option *longopts, int *longind); - -/* Internal only. Users should not call this directly. */ -extern int share___getopt_internal (int argc, char *const *argv, - const char *shortopts, - const struct share__option *longopts, int *longind, - int long_only); -/*[JEC] was:# endif*/ -/*[JEC] was:#else*/ /* not __STDC__ */ -/*[JEC] was:extern int getopt ();*/ -/*[JEC] was:# ifndef __need_getopt*/ -/*[JEC] was:extern int getopt_long ();*/ -/*[JEC] was:extern int getopt_long_only ();*/ - -/*[JEC] was:extern int _getopt_internal ();*/ -/*[JEC] was:# endif*/ -/*[JEC] was:#endif*/ /* __STDC__ */ - -#ifdef __cplusplus -} -#endif - -/* Make sure we later can get all the definitions and declarations. */ -/*[JEC] was:#undef __need_getopt*/ - -#endif /* getopt.h */ diff --git a/flac/include/share/grabbag.h b/flac/include/share/grabbag.h deleted file mode 100644 index 6424fa9..0000000 --- a/flac/include/share/grabbag.h +++ /dev/null @@ -1,30 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 - */ - -#ifndef SHARE__GRABBAG_H -#define SHARE__GRABBAG_H - -/* These can't be included by themselves, only from within grabbag.h */ -#include "grabbag/cuesheet.h" -#include "grabbag/file.h" -#include "grabbag/picture.h" -#include "grabbag/replaygain.h" -#include "grabbag/seektable.h" - -#endif diff --git a/flac/include/share/grabbag/Makefile.am b/flac/include/share/grabbag/Makefile.am deleted file mode 100644 index 22baa15..0000000 --- a/flac/include/share/grabbag/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -## Process this file with automake to produce Makefile.in - -EXTRA_DIST = \ - cuesheet.h \ - file.h \ - picture.h \ - replaygain.h \ - seektable.h diff --git a/flac/include/share/grabbag/cuesheet.h b/flac/include/share/grabbag/cuesheet.h deleted file mode 100644 index d0eb94d..0000000 --- a/flac/include/share/grabbag/cuesheet.h +++ /dev/null @@ -1,43 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 .h cannot be included by itself; #include "share/grabbag.h" instead. */ - -#ifndef GRABBAG__CUESHEET_H -#define GRABBAG__CUESHEET_H - -#include -#include "FLAC/metadata.h" - -#ifdef __cplusplus -extern "C" { -#endif - -uint32_t grabbag__cuesheet_msf_to_frame(uint32_t minutes, uint32_t seconds, uint32_t frames); -void grabbag__cuesheet_frame_to_msf(uint32_t frame, uint32_t *minutes, uint32_t *seconds, uint32_t *frames); - -FLAC__StreamMetadata *grabbag__cuesheet_parse(FILE *file, const char **error_message, uint32_t *last_line_read, uint32_t sample_rate, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset); - -void grabbag__cuesheet_emit(FILE *file, const FLAC__StreamMetadata *cuesheet, const char *file_reference); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flac/include/share/grabbag/file.h b/flac/include/share/grabbag/file.h deleted file mode 100644 index 9a2e086..0000000 --- a/flac/include/share/grabbag/file.h +++ /dev/null @@ -1,65 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 - */ - -/* Convenience routines for manipulating files */ - -/* This .h cannot be included by itself; #include "share/grabbag.h" instead. */ - -#ifndef GRABAG__FILE_H -#define GRABAG__FILE_H - -/* needed because of off_t */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#include /* for off_t */ -#include /* for FILE */ -#include "FLAC/ordinals.h" -#include "share/compat.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void grabbag__file_copy_metadata(const char *srcpath, const char *destpath); -FLAC__off_t grabbag__file_get_filesize(const char *srcpath); -const char *grabbag__file_get_basename(const char *srcpath); - -/* read_only == false means "make file writable by user" - * read_only == true means "make file read-only for everyone" - */ -FLAC__bool grabbag__file_change_stats(const char *filename, FLAC__bool read_only); - -/* returns true iff stat() succeeds for both files and they have the same device and inode. */ -/* on windows, uses GetFileInformationByHandle() to compare */ -FLAC__bool grabbag__file_are_same(const char *f1, const char *f2); - -/* attempts to make writable before unlinking */ -FLAC__bool grabbag__file_remove_file(const char *filename); - -/* these will forcibly set stdin/stdout to binary mode (for OSes that require it) */ -FILE *grabbag__file_get_binary_stdin(void); -FILE *grabbag__file_get_binary_stdout(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flac/include/share/grabbag/picture.h b/flac/include/share/grabbag/picture.h deleted file mode 100644 index 6bc4c39..0000000 --- a/flac/include/share/grabbag/picture.h +++ /dev/null @@ -1,54 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2006-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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. - */ - -/* This .h cannot be included by itself; #include "share/grabbag.h" instead. */ - -#ifndef GRABBAG__PICTURE_H -#define GRABBAG__PICTURE_H - -#include "FLAC/metadata.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* spec should be of the form "[TYPE]|MIME_TYPE|[DESCRIPTION]|[WIDTHxHEIGHTxDEPTH[/COLORS]]|FILE", e.g. - * "|image/jpeg|||cover.jpg" - * "4|image/jpeg||300x300x24|backcover.jpg" - * "|image/png|description|300x300x24/71|cover.png" - * "-->|image/gif||300x300x24/71|http://blah.blah.blah/cover.gif" - * - * empty type means default to FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER - * empty resolution spec means to get from the file (cannot get used with "-->" linked images) - * spec and error_message must not be NULL - */ -FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, const char **error_message); - -typedef struct PictureResolution -{ uint32_t width, height, depth, colors ; -} PictureResolution ; - -FLAC__StreamMetadata *grabbag__picture_from_specification(int type, const char *mime_type, const char * description, - const PictureResolution * res, const char * filepath, const char **error_message); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flac/include/share/grabbag/replaygain.h b/flac/include/share/grabbag/replaygain.h deleted file mode 100644 index 90e7a8c..0000000 --- a/flac/include/share/grabbag/replaygain.h +++ /dev/null @@ -1,73 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 wraps the replaygain_analysis lib, which is LGPL. This wrapper - * allows analysis of different input resolutions by automatically - * scaling the input signal - */ - -/* This .h cannot be included by itself; #include "share/grabbag.h" instead. */ - -#ifndef GRABBAG__REPLAYGAIN_H -#define GRABBAG__REPLAYGAIN_H - -#include "FLAC/metadata.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern const uint32_t GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED; - -extern const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_REFERENCE_LOUDNESS; /* = "REPLAYGAIN_REFERENCE_LOUDNESS" */ -extern const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN; /* = "REPLAYGAIN_TRACK_GAIN" */ -extern const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK; /* = "REPLAYGAIN_TRACK_PEAK" */ -extern const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN; /* = "REPLAYGAIN_ALBUM_GAIN" */ -extern const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK; /* = "REPLAYGAIN_ALBUM_PEAK" */ - -FLAC__bool grabbag__replaygain_is_valid_sample_frequency(uint32_t sample_frequency); - -FLAC__bool grabbag__replaygain_init(uint32_t sample_frequency); - -/* 'bps' must be valid for FLAC, i.e. >=4 and <= 32 */ -FLAC__bool grabbag__replaygain_analyze(const FLAC__int32 * const input[], FLAC__bool is_stereo, uint32_t bps, uint32_t samples); - -void grabbag__replaygain_get_album(float *gain, float *peak); -void grabbag__replaygain_get_title(float *gain, float *peak); - -/* These three functions return an error string on error, or NULL if successful */ -const char *grabbag__replaygain_analyze_file(const char *filename, float *title_gain, float *title_peak); -const char *grabbag__replaygain_store_to_vorbiscomment(FLAC__StreamMetadata *block, float album_gain, float album_peak, float title_gain, float title_peak); -const char *grabbag__replaygain_store_to_vorbiscomment_reference(FLAC__StreamMetadata *block); -const char *grabbag__replaygain_store_to_vorbiscomment_album(FLAC__StreamMetadata *block, float album_gain, float album_peak); -const char *grabbag__replaygain_store_to_vorbiscomment_title(FLAC__StreamMetadata *block, float title_gain, float title_peak); -const char *grabbag__replaygain_store_to_file(const char *filename, float album_gain, float album_peak, float title_gain, float title_peak, FLAC__bool preserve_modtime); -const char *grabbag__replaygain_store_to_file_reference(const char *filename, FLAC__bool preserve_modtime); -const char *grabbag__replaygain_store_to_file_album(const char *filename, float album_gain, float album_peak, FLAC__bool preserve_modtime); -const char *grabbag__replaygain_store_to_file_title(const char *filename, float title_gain, float title_peak, FLAC__bool preserve_modtime); - -FLAC__bool grabbag__replaygain_load_from_vorbiscomment(const FLAC__StreamMetadata *block, FLAC__bool album_mode, FLAC__bool strict, double *reference, double *gain, double *peak); -double grabbag__replaygain_compute_scale_factor(double peak, double gain, double preamp, FLAC__bool prevent_clipping); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flac/include/share/grabbag/seektable.h b/flac/include/share/grabbag/seektable.h deleted file mode 100644 index 751995b..0000000 --- a/flac/include/share/grabbag/seektable.h +++ /dev/null @@ -1,39 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 - */ - -/* Convenience routines for working with seek tables */ - -/* This .h cannot be included by itself; #include "share/grabbag.h" instead. */ - -#ifndef GRABAG__SEEKTABLE_H -#define GRABAG__SEEKTABLE_H - -#include "FLAC/format.h" - -#ifdef __cplusplus -extern "C" { -#endif - -FLAC__bool grabbag__seektable_convert_specification_to_template(const char *spec, FLAC__bool only_explicit_placeholders, FLAC__uint64 total_samples_to_encode, uint32_t sample_rate, FLAC__StreamMetadata *seektable_template, FLAC__bool *spec_has_real_points); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/flac/include/share/macros.h b/flac/include/share/macros.h deleted file mode 100644 index 3e7ee55..0000000 --- a/flac/include/share/macros.h +++ /dev/null @@ -1,45 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#include - -/* FLAC_CHECK_RETURN : Check the return value of the provided function and - * print an error message if it fails (ie returns a value < 0). - * - * Ideally, a library should not print anything, but this macro is only used - * for things that extremely unlikely to fail, like `chown` to a previoulsy - * saved `uid`. - */ - -#define FLAC_CHECK_RETURN(x) \ - { if ((x) < 0) \ - fprintf (stderr, "%s : %s\n", #x, strerror (errno)) ; \ - } diff --git a/flac/include/share/private.h b/flac/include/share/private.h deleted file mode 100644 index 5340d40..0000000 --- a/flac/include/share/private.h +++ /dev/null @@ -1,54 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__SHARE__PRIVATE_H -#define FLAC__SHARE__PRIVATE_H - -/* - * Unpublished debug routines from libFLAC. This should not be used from any - * client code other than code shipped with the FLAC sources. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_disable_instruction_set(FLAC__StreamEncoder *encoder, int value); -FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); -FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); -FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); -/* - * The following two routines were intended as debug routines and are not - * in the public headers, but SHOULD NOT CHANGE! It is known they are used - * in some non-audio projects needing every last bit of performance. - * See https://github.com/xiph/flac/issues/547 for details. These projects - * provide their own prototypes, so changing the signature of these - * functions would break building. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value); -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder); - -#endif /* FLAC__SHARE__PRIVATE_H */ diff --git a/flac/include/share/replaygain_analysis.h b/flac/include/share/replaygain_analysis.h deleted file mode 100644 index f06a9b2..0000000 --- a/flac/include/share/replaygain_analysis.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * ReplayGainAnalysis - analyzes input samples and give the recommended dB change - * Copyright (C) 2001 David Robinson and Glen Sawyer - * - * 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.1 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 - * - * concept and filter values by David Robinson (David@Robinson.org) - * -- blame him if you think the idea is flawed - * coding by Glen Sawyer (glensawyer@hotmail.com) 442 N 700 E, Provo, UT 84606 USA - * -- blame him if you think this runs too slowly, or the coding is otherwise flawed - * minor cosmetic tweaks to integrate with FLAC by Josh Coalson - * - * For an explanation of the concepts and the basic algorithms involved, go to: - * http://www.replaygain.org/ - */ - -#ifndef GAIN_ANALYSIS_H -#define GAIN_ANALYSIS_H - -#include - -#define GAIN_NOT_ENOUGH_SAMPLES -24601 -#define GAIN_ANALYSIS_ERROR 0 -#define GAIN_ANALYSIS_OK 1 - -#define INIT_GAIN_ANALYSIS_ERROR 0 -#define INIT_GAIN_ANALYSIS_OK 1 - -#ifdef __cplusplus -extern "C" { -#endif - -typedef float flac_float_t; /* Type used for filtering */ - -extern flac_float_t ReplayGainReferenceLoudness; /* in dB SPL, currently == 89.0 */ - -int InitGainAnalysis ( long samplefreq ); -int ValidGainFrequency ( long samplefreq ); -int AnalyzeSamples ( const flac_float_t* left_samples, const flac_float_t* right_samples, size_t num_samples, int num_channels ); -flac_float_t GetTitleGain ( void ); -flac_float_t GetAlbumGain ( void ); - -#ifdef __cplusplus -} -#endif - -#endif /* GAIN_ANALYSIS_H */ diff --git a/flac/include/share/replaygain_synthesis.h b/flac/include/share/replaygain_synthesis.h deleted file mode 100644 index 1701995..0000000 --- a/flac/include/share/replaygain_synthesis.h +++ /dev/null @@ -1,52 +0,0 @@ -/* replaygain_synthesis - Routines for applying ReplayGain to a signal - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 - */ - -#ifndef FLAC__SHARE__REPLAYGAIN_SYNTHESIS_H -#define FLAC__SHARE__REPLAYGAIN_SYNTHESIS_H - -#include /* for size_t */ -#include "FLAC/format.h" - -#define FLAC_SHARE__MAX_SUPPORTED_CHANNELS FLAC__MAX_CHANNELS - -typedef enum { - NOISE_SHAPING_NONE = 0, - NOISE_SHAPING_LOW = 1, - NOISE_SHAPING_MEDIUM = 2, - NOISE_SHAPING_HIGH = 3 -} NoiseShaping; - -typedef struct { - const float* FilterCoeff; - FLAC__uint64 Mask; - double Add; - float Dither; - float ErrorHistory [FLAC_SHARE__MAX_SUPPORTED_CHANNELS] [16]; /* 16th order Noise shaping */ - float DitherHistory [FLAC_SHARE__MAX_SUPPORTED_CHANNELS] [16]; - int LastRandomNumber [FLAC_SHARE__MAX_SUPPORTED_CHANNELS]; - unsigned LastHistoryIndex; - NoiseShaping ShapingType; -} DitherContext; - -void FLAC__replaygain_synthesis__init_dither_context(DitherContext *dither, int bits, int shapingtype); - -/* scale = (float) pow(10., (double)replaygain * 0.05); */ -size_t FLAC__replaygain_synthesis__apply_gain(FLAC__byte *data_out, FLAC__bool little_endian_data_out, FLAC__bool unsigned_data_out, const FLAC__int32 * const input[], uint32_t wide_samples, uint32_t channels, const uint32_t source_bps, const uint32_t target_bps, const double scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context); - -#endif diff --git a/flac/include/share/safe_str.h b/flac/include/share/safe_str.h deleted file mode 100644 index 85ecbda..0000000 --- a/flac/include/share/safe_str.h +++ /dev/null @@ -1,71 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -/* Safe string handling functions to replace things like strcpy, strncpy, - * strcat, strncat etc. - * All of these functions guarantee a correctly NUL terminated string but - * the string may be truncated if the destination buffer was too short. - */ - -#ifndef FLAC__SHARE_SAFE_STR_H -#define FLAC__SHARE_SAFE_STR_H - -static inline char * -safe_strncat(char *dest, const char *src, size_t dest_size) -{ - char * ret; - - if (dest_size < 1) - return dest; - - /* Assume dist has space for a term character .. */ - ret = strncat(dest, src, dest_size - strlen (dest)); - /* .. but set it explicitly. */ - dest [dest_size - 1] = 0; - - return ret; -} - -static inline char * -safe_strncpy(char *dest, const char *src, size_t dest_size) -{ - char * ret; - - if (dest_size < 1) - return dest; - - ret = strncpy(dest, src, dest_size - 1); - dest [dest_size - 1] = 0; - - return ret; -} - -#endif /* FLAC__SHARE_SAFE_STR_H */ diff --git a/flac/include/share/utf8.h b/flac/include/share/utf8.h deleted file mode 100644 index 7d6650d..0000000 --- a/flac/include/share/utf8.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SHARE__UTF8_H -#define SHARE__UTF8_H - -/* - * Convert a string between UTF-8 and the locale's charset. - * Invalid bytes are replaced by '#', and characters that are - * not available in the target encoding are replaced by '?'. - * - * If the locale's charset is not set explicitly then it is - * obtained using nl_langinfo(CODESET), where available, the - * environment variable CHARSET, or assumed to be US-ASCII. - * - * Return value of conversion functions: - * - * -1 : memory allocation failed - * 0 : data was converted exactly - * 1 : valid data was converted approximately (using '?') - * 2 : input was invalid (but still converted, using '#') - * 3 : unknown encoding (but still converted, using '?') - */ - -int utf8_encode(const char *from, char **to); -int utf8_decode(const char *from, char **to); - -#endif diff --git a/flac/include/share/win_utf8_io.h b/flac/include/share/win_utf8_io.h deleted file mode 100644 index ed07386..0000000 --- a/flac/include/share/win_utf8_io.h +++ /dev/null @@ -1,71 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef _WIN32 - -#ifndef flac__win_utf8_io_h -#define flac__win_utf8_io_h - -#include -#include -#include -#include -#include "FLAC/ordinals.h" - -#ifdef __cplusplus -extern "C" { -#endif - -size_t strlen_utf8(const char *str); -int win_get_console_width(void); - -int get_utf8_argv(int *argc, char ***argv); - -int printf_utf8(const char *format, ...); -int fprintf_utf8(FILE *stream, const char *format, ...); -int vfprintf_utf8(FILE *stream, const char *format, va_list argptr); - -FILE* fopen_utf8(const char *filename, const char *mode); -int stat64_utf8(const char *path, struct __stat64 *buffer); -int chmod_utf8(const char *filename, int pmode); -int utime_utf8(const char *filename, struct utimbuf *times); -int unlink_utf8(const char *filename); -int rename_utf8(const char *oldname, const char *newname); - -#include -HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif -#endif diff --git a/flac/include/test_libs_common/Makefile.am b/flac/include/test_libs_common/Makefile.am deleted file mode 100644 index af82b4d..0000000 --- a/flac/include/test_libs_common/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -## Process this file with automake to produce Makefile.in - -EXTRA_DIST = \ - file_utils_flac.h \ - metadata_utils.h diff --git a/flac/include/test_libs_common/file_utils_flac.h b/flac/include/test_libs_common/file_utils_flac.h deleted file mode 100644 index 5c59c98..0000000 --- a/flac/include/test_libs_common/file_utils_flac.h +++ /dev/null @@ -1,36 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLAC_FILE_UTILS_H -#define FLAC__TEST_LIBFLAC_FILE_UTILS_H - -/* needed because of off_t */ -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "FLAC/format.h" -#include /* for off_t */ -#include "share/compat.h" - -extern const long file_utils__ogg_serial_number; - -FLAC__bool file_utils__generate_flacfile(FLAC__bool is_ogg, const char *output_filename, FLAC__off_t *output_filesize, uint32_t length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, uint32_t num_metadata); - -#endif diff --git a/flac/include/test_libs_common/metadata_utils.h b/flac/include/test_libs_common/metadata_utils.h deleted file mode 100644 index 1ed923a..0000000 --- a/flac/include/test_libs_common/metadata_utils.h +++ /dev/null @@ -1,71 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBS_COMMON_METADATA_UTILS_H -#define FLAC__TEST_LIBS_COMMON_METADATA_UTILS_H - -/* - * These are not tests, just utility functions used by the metadata tests - */ - -#include "FLAC/format.h" - -FLAC__bool mutils__compare_block_data_streaminfo(const FLAC__StreamMetadata_StreamInfo *block, const FLAC__StreamMetadata_StreamInfo *blockcopy); - -FLAC__bool mutils__compare_block_data_padding(const FLAC__StreamMetadata_Padding *block, const FLAC__StreamMetadata_Padding *blockcopy, uint32_t block_length); - -FLAC__bool mutils__compare_block_data_application(const FLAC__StreamMetadata_Application *block, const FLAC__StreamMetadata_Application *blockcopy, uint32_t block_length); - -FLAC__bool mutils__compare_block_data_seektable(const FLAC__StreamMetadata_SeekTable *block, const FLAC__StreamMetadata_SeekTable *blockcopy); - -FLAC__bool mutils__compare_block_data_vorbiscomment(const FLAC__StreamMetadata_VorbisComment *block, const FLAC__StreamMetadata_VorbisComment *blockcopy); - -FLAC__bool mutils__compare_block_data_cuesheet(const FLAC__StreamMetadata_CueSheet *block, const FLAC__StreamMetadata_CueSheet *blockcopy); - -FLAC__bool mutils__compare_block_data_picture(const FLAC__StreamMetadata_Picture *block, const FLAC__StreamMetadata_Picture *blockcopy); - -FLAC__bool mutils__compare_block_data_unknown(const FLAC__StreamMetadata_Unknown *block, const FLAC__StreamMetadata_Unknown *blockcopy, uint32_t block_length); - -FLAC__bool mutils__compare_block(const FLAC__StreamMetadata *block, const FLAC__StreamMetadata *blockcopy); - -void mutils__init_metadata_blocks( - FLAC__StreamMetadata *streaminfo, - FLAC__StreamMetadata *padding, - FLAC__StreamMetadata *seektable, - FLAC__StreamMetadata *application1, - FLAC__StreamMetadata *application2, - FLAC__StreamMetadata *vorbiscomment, - FLAC__StreamMetadata *cuesheet, - FLAC__StreamMetadata *picture, - FLAC__StreamMetadata *unknown -); - -void mutils__free_metadata_blocks( - FLAC__StreamMetadata *streaminfo, - FLAC__StreamMetadata *padding, - FLAC__StreamMetadata *seektable, - FLAC__StreamMetadata *application1, - FLAC__StreamMetadata *application2, - FLAC__StreamMetadata *vorbiscomment, - FLAC__StreamMetadata *cuesheet, - FLAC__StreamMetadata *picture, - FLAC__StreamMetadata *unknown -); - -#endif diff --git a/flac/m4/Makefile.am b/flac/m4/Makefile.am deleted file mode 100644 index 1a25b7a..0000000 --- a/flac/m4/Makefile.am +++ /dev/null @@ -1,26 +0,0 @@ -# FLAC - Free Lossless Audio Codec -# Copyright (C) 2006-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# This file is part the FLAC project. FLAC is comprised of several -# components distributed under different licenses. The codec libraries -# are distributed under Xiph.Org's BSD-like license (see the file -# COPYING.Xiph in this distribution). All other programs, libraries, and -# plugins are distributed under the GPL (see COPYING.GPL). The documentation -# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the -# FLAC distribution contains at the top the terms under which it may be -# distributed. -# -# Since this particular file is relevant to all components of FLAC, -# it may be distributed under the Xiph.Org license, which is the least -# restrictive of those mentioned above. See the file COPYING.Xiph in this -# distribution. - -EXTRA_DIST = \ - add_cflags.m4 \ - add_cxxflags.m4 \ - bswap.m4 \ - endian.m4 \ - gcc_version.m4 \ - ogg.m4 \ - stack_protect.m4 diff --git a/flac/m4/add_cflags.m4 b/flac/m4/add_cflags.m4 deleted file mode 100644 index d9b633c..0000000 --- a/flac/m4/add_cflags.m4 +++ /dev/null @@ -1,15 +0,0 @@ -dnl @synopsis XIPH_ADD_CFLAGS -dnl -dnl Add the given option to CFLAGS, if it doesn't break the compiler - -AC_DEFUN([XIPH_ADD_CFLAGS], -[AC_MSG_CHECKING([if $CC accepts $1]) - ac_add_cflags__old_cflags="$CFLAGS" - CFLAGS="$1" - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #include - ]], [[puts("Hello, World!"); return 0;]])],[AC_MSG_RESULT(yes) - CFLAGS="$ac_add_cflags__old_cflags $1"],[AC_MSG_RESULT(no) - CFLAGS="$ac_add_cflags__old_cflags" - ]) -])# XIPH_ADD_CFLAGS diff --git a/flac/m4/add_cxxflags.m4 b/flac/m4/add_cxxflags.m4 deleted file mode 100644 index b76e710..0000000 --- a/flac/m4/add_cxxflags.m4 +++ /dev/null @@ -1,16 +0,0 @@ -dnl @synopsis XIPH_ADD_CXXFLAGS -dnl -dnl Add the given option to CXXFLAGS, if it doesn't break the compiler - -AC_DEFUN([XIPH_ADD_CXXFLAGS], -[AC_MSG_CHECKING([if $CXX accepts $1]) - AC_LANG_ASSERT([C++]) - ac_add_cxxflags__old_cxxflags="$CXXFLAGS" - CXXFLAGS="$1" - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #include - ]], [[puts("Hello, World!"); return 0;]])],[AC_MSG_RESULT(yes) - CXXFLAGS="$ac_add_cxxflags__old_cxxflags $1"],[AC_MSG_RESULT(no) - CXXFLAGS="$ac_add_cxxflags__old_cxxflags" - ]) -])# XIPH_ADD_CXXFLAGS diff --git a/flac/m4/ax_add_fortify_source.m4 b/flac/m4/ax_add_fortify_source.m4 deleted file mode 100644 index d443814..0000000 --- a/flac/m4/ax_add_fortify_source.m4 +++ /dev/null @@ -1,53 +0,0 @@ -# =========================================================================== -# http://www.gnu.org/software/autoconf-archive/ax_add_fortify_source.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_ADD_FORTIFY_SOURCE -# -# DESCRIPTION -# -# Check whether -D_FORTIFY_SOURCE=2 can be added to CPPFLAGS without macro -# redefinition warnings. Some distributions (such as Gentoo Linux) enable -# _FORTIFY_SOURCE globally in their compilers, leading to unnecessary -# warnings in the form of -# -# :0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] -# : note: this is the location of the previous definition -# -# which is a problem if -Werror is enabled. This macro checks whether -# _FORTIFY_SOURCE is already defined, and if not, adds -D_FORTIFY_SOURCE=2 -# to CPPFLAGS. -# -# LICENSE -# -# Copyright (c) 2017 David Seifert -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 1 - -AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[ - AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=2 to CPPFLAGS]) - AC_LINK_IFELSE([ - AC_LANG_SOURCE( - [[ - int main() { - #ifndef _FORTIFY_SOURCE - return 0; - #else - this_is_an_error; - #endif - } - ]] - )], [ - AC_MSG_RESULT([yes]) - CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2" - ], [ - AC_MSG_RESULT([no]) - ]) -]) diff --git a/flac/m4/ax_check_compile_flag.m4 b/flac/m4/ax_check_compile_flag.m4 deleted file mode 100644 index bd753b3..0000000 --- a/flac/m4/ax_check_compile_flag.m4 +++ /dev/null @@ -1,53 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) -# -# DESCRIPTION -# -# Check whether the given FLAG works with the current language's compiler -# or gives an error. (Warnings, however, are ignored) -# -# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on -# success/failure. -# -# If EXTRA-FLAGS is defined, it is added to the current language's default -# flags (e.g. CFLAGS) when the check is done. The check is thus made with -# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to -# force the compiler to issue an error when a bad flag is given. -# -# INPUT gives an alternative input source to AC_COMPILE_IFELSE. -# -# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this -# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. -# -# LICENSE -# -# Copyright (c) 2008 Guido U. Draheim -# Copyright (c) 2011 Maarten Bosmans -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 6 - -AC_DEFUN([AX_CHECK_COMPILE_FLAG], -[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF -AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl -AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ - ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS - _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" - AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], - [AS_VAR_SET(CACHEVAR,[yes])], - [AS_VAR_SET(CACHEVAR,[no])]) - _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) -AS_VAR_IF(CACHEVAR,yes, - [m4_default([$2], :)], - [m4_default([$3], :)]) -AS_VAR_POPDEF([CACHEVAR])dnl -])dnl AX_CHECK_COMPILE_FLAGS diff --git a/flac/m4/ax_check_enable_debug.m4 b/flac/m4/ax_check_enable_debug.m4 deleted file mode 100644 index f99d75f..0000000 --- a/flac/m4/ax_check_enable_debug.m4 +++ /dev/null @@ -1,124 +0,0 @@ -# =========================================================================== -# http://www.gnu.org/software/autoconf-archive/ax_check_enable_debug.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_CHECK_ENABLE_DEBUG([enable by default=yes/info/profile/no], [ENABLE DEBUG VARIABLES ...], [DISABLE DEBUG VARIABLES NDEBUG ...], [IS-RELEASE]) -# -# DESCRIPTION -# -# Check for the presence of an --enable-debug option to configure, with -# the specified default value used when the option is not present. Return -# the value in the variable $ax_enable_debug. -# -# Specifying 'yes' adds '-g -O0' to the compilation flags for all -# languages. Specifying 'info' adds '-g' to the compilation flags. -# Specifying 'profile' adds '-g -pg' to the compilation flags and '-pg' to -# the linking flags. Otherwise, nothing is added. -# -# Define the variables listed in the second argument if debug is enabled, -# defaulting to no variables. Defines the variables listed in the third -# argument if debug is disabled, defaulting to NDEBUG. All lists of -# variables should be space-separated. -# -# If debug is not enabled, ensure AC_PROG_* will not add debugging flags. -# Should be invoked prior to any AC_PROG_* compiler checks. -# -# IS-RELEASE can be used to change the default to 'no' when making a -# release. Set IS-RELEASE to 'yes' or 'no' as appropriate. By default, it -# uses the value of $ax_is_release, so if you are using the AX_IS_RELEASE -# macro, there is no need to pass this parameter. -# -# AX_IS_RELEASE([git-directory]) -# AX_CHECK_ENABLE_DEBUG() -# -# LICENSE -# -# Copyright (c) 2011 Rhys Ulerich -# Copyright (c) 2014, 2015 Philip Withnall -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. - -#serial 5 - -AC_DEFUN([AX_CHECK_ENABLE_DEBUG],[ - AC_BEFORE([$0],[AC_PROG_CC])dnl - AC_BEFORE([$0],[AC_PROG_CXX])dnl - AC_BEFORE([$0],[AC_PROG_F77])dnl - AC_BEFORE([$0],[AC_PROG_FC])dnl - - AC_MSG_CHECKING(whether to enable debugging) - - ax_enable_debug_default=m4_tolower(m4_normalize(ifelse([$1],,[no],[$1]))) - ax_enable_debug_is_release=m4_tolower(m4_normalize(ifelse([$4],, - [$ax_is_release], - [$4]))) - - # If this is a release, override the default. - AS_IF([test "$ax_enable_debug_is_release" = "yes"], - [ax_enable_debug_default="no"]) - - m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))]) - m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))]) - - AC_ARG_ENABLE(debug, - [AS_HELP_STRING([--enable-debug=]@<:@yes/info/profile/no@:>@,[compile with debugging])], - [],enable_debug=$ax_enable_debug_default) - - # empty mean debug yes - AS_IF([test "x$enable_debug" = "x"], - [enable_debug="yes"]) - - # case of debug - AS_CASE([$enable_debug], - [yes],[ - AC_MSG_RESULT(yes) - CFLAGS="${CFLAGS} -g -O0" - CXXFLAGS="${CXXFLAGS} -g -O0" - FFLAGS="${FFLAGS} -g -O0" - FCFLAGS="${FCFLAGS} -g -O0" - OBJCFLAGS="${OBJCFLAGS} -g -O0" - ], - [info],[ - AC_MSG_RESULT(info) - CFLAGS="${CFLAGS} -g" - CXXFLAGS="${CXXFLAGS} -g" - FFLAGS="${FFLAGS} -g" - FCFLAGS="${FCFLAGS} -g" - OBJCFLAGS="${OBJCFLAGS} -g" - ], - [profile],[ - AC_MSG_RESULT(profile) - CFLAGS="${CFLAGS} -g -pg" - CXXFLAGS="${CXXFLAGS} -g -pg" - FFLAGS="${FFLAGS} -g -pg" - FCFLAGS="${FCFLAGS} -g -pg" - OBJCFLAGS="${OBJCFLAGS} -g -pg" - LDFLAGS="${LDFLAGS} -pg" - ], - [ - AC_MSG_RESULT(no) - dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags - dnl by setting any unset environment flag variables - AS_IF([test "x${CFLAGS+set}" != "xset"], - [CFLAGS=""]) - AS_IF([test "x${CXXFLAGS+set}" != "xset"], - [CXXFLAGS=""]) - AS_IF([test "x${FFLAGS+set}" != "xset"], - [FFLAGS=""]) - AS_IF([test "x${FCFLAGS+set}" != "xset"], - [FCFLAGS=""]) - AS_IF([test "x${OBJCFLAGS+set}" != "xset"], - [OBJCFLAGS=""]) - ]) - - dnl Define various variables if debugging is disabled. - dnl assert.h is a NOP if NDEBUG is defined, so define it by default. - AS_IF([test "x$enable_debug" = "xyes"], - [m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])], - [m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])]) - ax_enable_debug=$enable_debug -]) diff --git a/flac/m4/bswap.m4 b/flac/m4/bswap.m4 deleted file mode 100644 index b1abae9..0000000 --- a/flac/m4/bswap.m4 +++ /dev/null @@ -1,66 +0,0 @@ -dnl Copyright (C) 2012-2023 Xiph.Org Foundation -dnl -dnl Redistribution and use in source and binary forms, with or without -dnl modification, are permitted provided that the following conditions -dnl are met: -dnl -dnl - Redistributions of source code must retain the above copyright -dnl notice, this list of conditions and the following disclaimer. -dnl -dnl - Redistributions in binary form must reproduce the above copyright -dnl notice, this list of conditions and the following disclaimer in the -dnl documentation and/or other materials provided with the distribution. -dnl -dnl - Neither the name of the Xiph.org Foundation nor the names of its -dnl contributors may be used to endorse or promote products derived from -dnl this software without specific prior written permission. -dnl -dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -dnl @synopsis XIPH_C_BSWAP32 -dnl -dnl @author Erik de Castro Lopo -dnl -dnl Dtermine whether the compiler has the __builtin_bswap32() intrinsic which -dnl is likely to be present for most versions of GCC as well as Clang. - -AC_DEFUN([XIPH_C_BSWAP32], -[AC_CACHE_CHECK(for bswap32 intrinsic, - ac_cv_c_bswap32, - - AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[return __builtin_bswap32 (0) ;]])],[ac_cv_c_bswap32=yes],[ac_cv_c_bswap32=no]) - if test $ac_cv_c_bswap32 = yes; then - AC_DEFINE_UNQUOTED(HAVE_BSWAP32, [1], [Compiler has the __builtin_bswap32 intrinsic]) - fi - )] -)# XIPH_C_BSWAP32 - - -dnl @synopsis XIPH_C_BSWAP16 -dnl -dnl @author Erik de Castro Lopo -dnl -dnl Dtermine whether the compiler has the __builtin_bswap16() intrinsic which -dnl is likely to be present for most versions of GCC as well as Clang. - -AC_DEFUN([XIPH_C_BSWAP16], -[AC_CACHE_CHECK(for bswap16 intrinsic, - ac_cv_c_bswap16, - - AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[return __builtin_bswap16 (0) ;]])],[ac_cv_c_bswap16=yes],[ac_cv_c_bswap16=no]) - if test $ac_cv_c_bswap16 = yes; then - AC_DEFINE_UNQUOTED(HAVE_BSWAP16, [1], [Compiler has the __builtin_bswap16 intrinsic]) - fi - )] -)# XIPH_C_BSWAP16 diff --git a/flac/m4/c_attribute.m4 b/flac/m4/c_attribute.m4 deleted file mode 100644 index 48aa622..0000000 --- a/flac/m4/c_attribute.m4 +++ /dev/null @@ -1,18 +0,0 @@ -# -# Check for supported __attribute__ features -# -# AC_C_ATTRIBUTE(FEATURE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) -# -AC_DEFUN([AC_C_ATTRIBUTE], -[AS_VAR_PUSHDEF([CACHEVAR], [ax_cv_c_attribute_$1])dnl -AC_CACHE_CHECK([for __attribute__ (($1))], - CACHEVAR,[ - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], - [[ void foo(void) __attribute__ (($1)); ]])], - [AS_VAR_SET(CACHEVAR, [yes])], - [AS_VAR_SET(CACHEVAR, [no])])]) -AS_VAR_IF(CACHEVAR,yes, - [m4_default([$2], :)], - [m4_default([$3], :)]) -AS_VAR_POPDEF([CACHEVAR])dnl -])dnl diff --git a/flac/m4/clang.m4 b/flac/m4/clang.m4 deleted file mode 100644 index 11326a4..0000000 --- a/flac/m4/clang.m4 +++ /dev/null @@ -1,28 +0,0 @@ -dnl @synopsis XIPH_C_COMPILER_IS_CLANG -dnl -dnl Find out if a compiler claiming to be gcc really is gcc (clang lies). -dnl @version 1.0 Oct 31 2013 -dnl @author Erik de Castro Lopo -dnl -dnl Permission to use, copy, modify, distribute, and sell this file for any -dnl purpose is hereby granted without fee, provided that the above copyright -dnl and this permission notice appear in all copies. No representations are -dnl made about the suitability of this software for any purpose. It is -dnl provided "as is" without express or implied warranty. -dnl - - -AC_DEFUN([XIPH_C_COMPILER_IS_CLANG], -[AC_CACHE_CHECK(whether we are using the CLANG C compiler, - xiph_cv_c_compiler_clang, - [ AC_LANG_ASSERT(C) - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #include - ]], [[ - #ifndef __clang__ - This is not clang! - #endif - ]])],[xiph_cv_c_compiler_clang=yes],[xiph_cv_c_compiler_clang=no - ])] - )] -) diff --git a/flac/m4/codeset.m4 b/flac/m4/codeset.m4 deleted file mode 100644 index cf53d24..0000000 --- a/flac/m4/codeset.m4 +++ /dev/null @@ -1,23 +0,0 @@ -# codeset.m4 serial 5 (gettext-0.18.2) -dnl Copyright (C) 2000-2002, 2006, 2008-2012 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_LANGINFO_CODESET], -[ - AC_CACHE_CHECK([for nl_langinfo and CODESET], [am_cv_langinfo_codeset], - [AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[#include ]], - [[char* cs = nl_langinfo(CODESET); return !cs;]])], - [am_cv_langinfo_codeset=yes], - [am_cv_langinfo_codeset=no]) - ]) - if test $am_cv_langinfo_codeset = yes; then - AC_DEFINE([HAVE_LANGINFO_CODESET], [1], - [Define if you have and nl_langinfo(CODESET).]) - fi -]) diff --git a/flac/m4/endian.m4 b/flac/m4/endian.m4 deleted file mode 100644 index 28fbf32..0000000 --- a/flac/m4/endian.m4 +++ /dev/null @@ -1,169 +0,0 @@ -dnl Copyright (C) 2012-2023 Xiph.Org Foundation -dnl -dnl Redistribution and use in source and binary forms, with or without -dnl modification, are permitted provided that the following conditions -dnl are met: -dnl -dnl - Redistributions of source code must retain the above copyright -dnl notice, this list of conditions and the following disclaimer. -dnl -dnl - Redistributions in binary form must reproduce the above copyright -dnl notice, this list of conditions and the following disclaimer in the -dnl documentation and/or other materials provided with the distribution. -dnl -dnl - Neither the name of the Xiph.org Foundation nor the names of its -dnl contributors may be used to endorse or promote products derived from -dnl this software without specific prior written permission. -dnl -dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -dnl @synopsis XIPH_C_FIND_ENDIAN -dnl -dnl Determine endian-ness of target processor. -dnl @version 1.1 Mar 03 2002 -dnl @author Erik de Castro Lopo -dnl -dnl Majority written from scratch to replace the standard autoconf macro -dnl AC_C_BIGENDIAN. Only part remaining from the original is the invocation -dnl of the AC_RUN_IFELSE([AC_LANG_SOURCE([[]])],[],[],[]) macro. -dnl -dnl Find endian-ness in the following way: -dnl 1) Look in . -dnl 2) If 1) fails, look in and . -dnl 3) If 1) and 2) fails and not cross compiling run a test program. -dnl 4) If 1) and 2) fails and cross compiling then guess based on target. - -AC_DEFUN([XIPH_C_FIND_ENDIAN], -[AC_CACHE_CHECK(processor byte ordering, - ac_cv_c_byte_order, - -# Initialize to unknown -ac_cv_c_byte_order=unknown - -if test x$ac_cv_header_endian_h = xyes ; then - - # First try which should set BYTE_ORDER. - - [AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #include - #if BYTE_ORDER != LITTLE_ENDIAN - not big endian - #endif - ]], [[return 0 ;]])],[ac_cv_c_byte_order=little - ],[])] - - [AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #include - #if BYTE_ORDER != BIG_ENDIAN - not big endian - #endif - ]], [[return 0 ;]])],[ac_cv_c_byte_order=big - ],[])] - - fi - -if test $ac_cv_c_byte_order = unknown ; then - - [AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #include - #include - #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN - bogus endian macros - #endif - ]], [[return 0 ;]])],[_au_m4_changequote([,])AC_TRY_LINK([ - #include - #include - #if BYTE_ORDER != LITTLE_ENDIAN - not big endian - #endif - ], return 0 ;, - ac_cv_c_byte_order=little - ) - - _au_m4_changequote([,])AC_TRY_LINK([ - #include - #include - #if BYTE_ORDER != LITTLE_ENDIAN - not big endian - #endif - ], return 0 ;, - ac_cv_c_byte_order=little - ) - - ],[])] - - fi - -if test $ac_cv_c_byte_order = unknown ; then - if test $cross_compiling = yes ; then - # This is the last resort. Try to guess the target processor endian-ness - # by looking at the target CPU type. - [ - case "$target_cpu" in - alpha* | i?86* | mipsel* | ia64*) - ac_cv_c_byte_order=little - ;; - - m68* | mips* | powerpc* | hppa* | sparc*) - ac_cv_c_byte_order=big - ;; - - esac - ] - else - AC_RUN_IFELSE([AC_LANG_SOURCE([[[ - int main (void) - { /* Are we little or big endian? From Harbison&Steele. */ - union - { long l ; - char c [sizeof (long)] ; - } u ; - u.l = 1 ; - return (u.c [sizeof (long) - 1] == 1); - } - ]]])],[],[ac_cv_c_byte_order=big],[]) - - AC_RUN_IFELSE([AC_LANG_SOURCE([[[int main (void) - { /* Are we little or big endian? From Harbison&Steele. */ - union - { long l ; - char c [sizeof (long)] ; - } u ; - u.l = 1 ; - return (u.c [0] == 1); - }]]])],[],[ac_cv_c_byte_order=little],[]) - fi - fi - -) - -if test $ac_cv_c_byte_order = big ; then - ac_cv_c_big_endian=1 - ac_cv_c_little_endian=0 -elif test $ac_cv_c_byte_order = little ; then - ac_cv_c_big_endian=0 - ac_cv_c_little_endian=1 -else - ac_cv_c_big_endian=0 - ac_cv_c_little_endian=0 - - AC_MSG_WARN([[*****************************************************************]]) - AC_MSG_WARN([[*** Not able to determine endian-ness of target processor. ]]) - AC_MSG_WARN([[*** The constants CPU_IS_BIG_ENDIAN and CPU_IS_LITTLE_ENDIAN in ]]) - AC_MSG_WARN([[*** config.h may need to be hand editied. ]]) - AC_MSG_WARN([[*****************************************************************]]) - fi - -] -)# XIPH_C_FIND_ENDIAN diff --git a/flac/m4/gcc_version.m4 b/flac/m4/gcc_version.m4 deleted file mode 100644 index e6aaa60..0000000 --- a/flac/m4/gcc_version.m4 +++ /dev/null @@ -1,34 +0,0 @@ -dnl @synopsis XIPH_GCC_VERSION -dnl -dnl Find the version of gcc. -dnl @version 1.0 Nov 05 2007 -dnl @version 1.1 Mar 10 2013 -dnl @author Erik de Castro Lopo -dnl -dnl Permission to use, copy, modify, distribute, and sell this file for any -dnl purpose is hereby granted without fee, provided that the above copyright -dnl and this permission notice appear in all copies. No representations are -dnl made about the suitability of this software for any purpose. It is -dnl provided "as is" without express or implied warranty. -dnl - -AC_DEFUN([XIPH_GCC_VERSION], -[ -if test "x$ac_cv_c_compiler_gnu" = "xyes" ; then - - AC_MSG_CHECKING([for version of $CC]) - GCC_VERSION=`$CC -dumpversion` - AC_MSG_RESULT($GCC_VERSION) - - GCC_MAJOR_VERSION=`echo $GCC_VERSION | cut -d. -f 1` - GCC_MINOR_VERSION=`echo $GCC_VERSION | cut -d. -f 2` -else - GCC_MAJOR_VERSION=0 - GCC_MINOR_VERSION=0 - fi - -AC_SUBST(GCC_VERSION) -AC_SUBST(GCC_MAJOR_VERSION) -AC_SUBST(GCC_MINOR_VERSION) - -])# XIPH_GCC_VERSION diff --git a/flac/m4/iconv.m4 b/flac/m4/iconv.m4 deleted file mode 100644 index 6a47236..0000000 --- a/flac/m4/iconv.m4 +++ /dev/null @@ -1,268 +0,0 @@ -# iconv.m4 serial 18 (gettext-0.18.2) -dnl Copyright (C) 2000-2002, 2007-2012 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). - AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - - 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_LINK_IFELSE will then fail, the second AC_LINK_IFELSE 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_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[ -#include -#include - ]], - [[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_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[ -#include -#include - ]], - [[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_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [ - dnl This tests against bugs in AIX 5.1, AIX 6.1..7.1, HP-UX 11.11, - dnl Solaris 10. - am_save_LIBS="$LIBS" - if test $am_cv_lib_iconv = yes; then - LIBS="$LIBS $LIBICONV" - fi - AC_RUN_IFELSE( - [AC_LANG_SOURCE([[ -#include -#include -int main () -{ - int result = 0; - /* Test against AIX 5.1 bug: Failures are not distinguishable from successful - returns. */ - { - iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8"); - if (cd_utf8_to_88591 != (iconv_t)(-1)) - { - static const char input[] = "\342\202\254"; /* EURO SIGN */ - char buf[10]; - const char *inptr = input; - size_t inbytesleft = strlen (input); - char *outptr = buf; - size_t outbytesleft = sizeof (buf); - size_t res = iconv (cd_utf8_to_88591, - (char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); - if (res == 0) - result |= 1; - iconv_close (cd_utf8_to_88591); - } - } - /* Test against Solaris 10 bug: Failures are not distinguishable from - successful returns. */ - { - iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646"); - if (cd_ascii_to_88591 != (iconv_t)(-1)) - { - static const char input[] = "\263"; - char buf[10]; - const char *inptr = input; - size_t inbytesleft = strlen (input); - char *outptr = buf; - size_t outbytesleft = sizeof (buf); - size_t res = iconv (cd_ascii_to_88591, - (char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); - if (res == 0) - result |= 2; - iconv_close (cd_ascii_to_88591); - } - } - /* Test against AIX 6.1..7.1 bug: Buffer overrun. */ - { - iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1"); - if (cd_88591_to_utf8 != (iconv_t)(-1)) - { - static const char input[] = "\304"; - static char buf[2] = { (char)0xDE, (char)0xAD }; - const char *inptr = input; - size_t inbytesleft = 1; - char *outptr = buf; - size_t outbytesleft = 1; - size_t res = iconv (cd_88591_to_utf8, - (char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); - if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD) - result |= 4; - iconv_close (cd_88591_to_utf8); - } - } -#if 0 /* This bug could be worked around by the caller. */ - /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */ - { - iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591"); - if (cd_88591_to_utf8 != (iconv_t)(-1)) - { - static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; - char buf[50]; - const char *inptr = input; - size_t inbytesleft = strlen (input); - char *outptr = buf; - size_t outbytesleft = sizeof (buf); - size_t res = iconv (cd_88591_to_utf8, - (char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); - if ((int)res > 0) - result |= 8; - iconv_close (cd_88591_to_utf8); - } - } -#endif - /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is - provided. */ - if (/* Try standardized names. */ - iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1) - /* Try IRIX, OSF/1 names. */ - && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1) - /* Try AIX names. */ - && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1) - /* Try HP-UX names. */ - && iconv_open ("utf8", "eucJP") == (iconv_t)(-1)) - result |= 16; - return result; -}]])], - [am_cv_func_iconv_works=yes], - [am_cv_func_iconv_works=no], - [ -changequote(,)dnl - case "$host_os" in - aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; - *) am_cv_func_iconv_works="guessing yes" ;; - esac -changequote([,])dnl - ]) - LIBS="$am_save_LIBS" - ]) - case "$am_cv_func_iconv_works" in - *no) am_func_iconv=no am_cv_lib_iconv=no ;; - *) am_func_iconv=yes ;; - esac - else - am_func_iconv=no am_cv_lib_iconv=no - fi - if test "$am_func_iconv" = yes; then - AC_DEFINE([HAVE_ICONV], [1], - [Define if you have the iconv() function and it works.]) - 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]) -]) - -dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to -dnl avoid warnings like -dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required". -dnl This is tricky because of the way 'aclocal' is implemented: -dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN. -dnl Otherwise aclocal's initial scan pass would miss the macro definition. -dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions. -dnl Otherwise aclocal would emit many "Use of uninitialized value $1" -dnl warnings. -m4_define([gl_iconv_AC_DEFUN], - m4_version_prereq([2.64], - [[AC_DEFUN_ONCE( - [$1], [$2])]], - [m4_ifdef([gl_00GNULIB], - [[AC_DEFUN_ONCE( - [$1], [$2])]], - [[AC_DEFUN( - [$1], [$2])]])])) -gl_iconv_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_COMPILE_IFELSE( - [AC_LANG_PROGRAM( - [[ -#include -#include -extern -#ifdef __cplusplus -"C" -#endif -#if defined(__STDC__) || defined(_MSC_VER) || 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([ - $am_cv_proto_iconv]) - AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1], - [Define as const if the declaration of iconv() needs const.]) - dnl Also substitute ICONV_CONST in the gnulib generated . - m4_ifdef([gl_ICONV_H_DEFAULTS], - [AC_REQUIRE([gl_ICONV_H_DEFAULTS]) - if test -n "$am_cv_proto_iconv_arg1"; then - ICONV_CONST="const" - fi - ]) - fi -]) diff --git a/flac/m4/lib-ld.m4 b/flac/m4/lib-ld.m4 deleted file mode 100644 index e1feab5..0000000 --- a/flac/m4/lib-ld.m4 +++ /dev/null @@ -1,119 +0,0 @@ -# lib-ld.m4 serial 6 -dnl Copyright (C) 1996-2003, 2009-2012 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 Subroutines of libtool.m4, -dnl with replacements s/_*LT_PATH/AC_LIB_PROG/ and s/lt_/acl_/ to avoid -dnl collision with libtool.m4. - -dnl From libtool-2.4. Sets the variable with_gnu_ld to yes or no. -AC_DEFUN([AC_LIB_PROG_LD_GNU], -[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], [acl_cv_prog_gnu_ld], -[# I'd rather use --version here, but apparently some GNU lds only accept -v. -case `$LD -v 2>&1 /dev/null 2>&1 \ - && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \ - || PATH_SEPARATOR=';' - } -fi - -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([acl_cv_path_LD], -[if test -z "$LD"; then - acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR - for ac_dir in $PATH; do - IFS="$acl_save_ifs" - test -z "$ac_dir" && ac_dir=. - if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then - acl_cv_path_LD="$ac_dir/$ac_prog" - # Check to see if the program is GNU ld. I'd rather use --version, - # but apparently some variants of GNU ld only accept -v. - # Break only if it was the GNU/non-GNU ld that we prefer. - case `"$acl_cv_path_LD" -v 2>&1 = 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" - acl_libext="$acl_cv_libext" - acl_shlibext="$acl_cv_shlibext" - acl_libname_spec="$acl_cv_libname_spec" - acl_library_names_spec="$acl_cv_library_names_spec" - acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" - acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" - acl_hardcode_direct="$acl_cv_hardcode_direct" - acl_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_FROMPACKAGE(name, package) -dnl declares that libname comes from the given package. The configure file -dnl will then not have a --with-libname-prefix option but a -dnl --with-package-prefix option. Several libraries can come from the same -dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar -dnl macro call that searches for libname. -AC_DEFUN([AC_LIB_FROMPACKAGE], -[ - pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], - [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) - define([acl_frompackage_]NAME, [$2]) - popdef([NAME]) - pushdef([PACK],[$2]) - pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-], - [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) - define([acl_libsinpackage_]PACKUP, - m4_ifdef([acl_libsinpackage_]PACKUP, [m4_defn([acl_libsinpackage_]PACKUP)[, ]],)[lib$1]) - popdef([PACKUP]) - popdef([PACK]) -]) - -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. -dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found -dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem. -AC_DEFUN([AC_LIB_LINKFLAGS_BODY], -[ - AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) - pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], - [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) - pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])]) - pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-], - [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) - pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])]) - dnl Autoconf >= 2.61 supports dots in --with options. - pushdef([P_A_C_K],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[m4_translit(PACK,[.],[_])],PACK)]) - 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_ARG_WITH(P_A_C_K[-prefix], -[[ --with-]]P_A_C_K[[-prefix[=DIR] search for ]PACKLIBS[ in DIR/include and DIR/lib - --without-]]P_A_C_K[[-prefix don't search for ]PACKLIBS[ 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" - if test "$acl_libdirstem2" != "$acl_libdirstem" \ - && ! test -d "$withval/$acl_libdirstem"; then - additional_libdir="$withval/$acl_libdirstem2" - fi - 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= - LIB[]NAME[]_PREFIX= - dnl HAVE_LIB${NAME} is an indicator that LIB${NAME}, LTLIB${NAME} have been - dnl computed. So it has to be reset here. - HAVE_LIB[]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= - eval libname=\"$acl_libname_spec\" # typically: libname=lib$name - if test -n "$acl_shlibext"; then - shrext=".$acl_shlibext" # typically: shrext=.so - else - shrext= - fi - if test $use_additional = yes; then - dir="$additional_libdir" - dnl The same code as in the loop below: - dnl First look for a shared library. - if test -n "$acl_shlibext"; then - if test -f "$dir/$libname$shrext"; then - found_dir="$dir" - found_so="$dir/$libname$shrext" - else - if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then - ver=`(cd "$dir" && \ - for f in "$libname$shrext".*; do echo "$f"; done \ - | sed -e "s,^$libname$shrext\\\\.,," \ - | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ - | sed 1q ) 2>/dev/null` - if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then - found_dir="$dir" - found_so="$dir/$libname$shrext.$ver" - fi - else - eval library_names=\"$acl_library_names_spec\" - for f in $library_names; do - if test -f "$dir/$f"; then - found_dir="$dir" - found_so="$dir/$f" - break - fi - done - fi - fi - fi - dnl Then look for a static library. - if test "X$found_dir" = "X"; then - if test -f "$dir/$libname.$acl_libext"; then - found_dir="$dir" - found_a="$dir/$libname.$acl_libext" - fi - fi - if test "X$found_dir" != "X"; then - if test -f "$dir/$libname.la"; then - found_la="$dir/$libname.la" - 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//'` - dnl First look for a shared library. - if test -n "$acl_shlibext"; then - if test -f "$dir/$libname$shrext"; then - found_dir="$dir" - found_so="$dir/$libname$shrext" - else - if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then - ver=`(cd "$dir" && \ - for f in "$libname$shrext".*; do echo "$f"; done \ - | sed -e "s,^$libname$shrext\\\\.,," \ - | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ - | sed 1q ) 2>/dev/null` - if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then - found_dir="$dir" - found_so="$dir/$libname$shrext.$ver" - fi - else - eval library_names=\"$acl_library_names_spec\" - for f in $library_names; do - if test -f "$dir/$f"; then - found_dir="$dir" - found_so="$dir/$f" - break - fi - done - fi - fi - fi - dnl Then look for a static library. - if test "X$found_dir" = "X"; then - if test -f "$dir/$libname.$acl_libext"; then - found_dir="$dir" - found_a="$dir/$libname.$acl_libext" - fi - fi - if test "X$found_dir" != "X"; then - if test -f "$dir/$libname.la"; then - found_la="$dir/$libname.la" - 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" \ - || test "X$found_dir" = "X/usr/$acl_libdirstem2"; 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 "$acl_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 "$acl_hardcode_libdir_flag_spec" && test "$acl_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 "$acl_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 $acl_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/"'*$,,'` - if test "$name" = '$1'; then - LIB[]NAME[]_PREFIX="$basedir" - fi - additional_includedir="$basedir/include" - ;; - */$acl_libdirstem2 | */$acl_libdirstem2/) - basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'` - if test "$name" = '$1'; then - LIB[]NAME[]_PREFIX="$basedir" - fi - 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" \ - && test "X$additional_libdir" != "X/usr/$acl_libdirstem2"; then - haveit= - if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem" \ - || test "X$additional_libdir" = "X/usr/local/$acl_libdirstem2"; 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 "$acl_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:+$acl_hardcode_libdir_separator}$found_dir" - done - dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl. - acl_save_libdir="$libdir" - libdir="$alldirs" - eval flag=\"$acl_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=\"$acl_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 - popdef([P_A_C_K]) - popdef([PACKLIBS]) - popdef([PACKUP]) - popdef([PACK]) - popdef([NAME]) -]) - -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 "$acl_hardcode_libdir_flag_spec" && test "$acl_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" \ - && test "X$dir" != "X/usr/$acl_libdirstem2"; 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" \ - && test "X$dir" != "X/usr/$acl_libdirstem2"; 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 "$acl_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:+$acl_hardcode_libdir_separator}$dir" - done - acl_save_libdir="$libdir" - libdir="$alldirs" - eval flag=\"$acl_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=\"$acl_hardcode_libdir_flag_spec\" - libdir="$acl_save_libdir" - $1="${$1}${$1:+ }$flag" - done - fi - fi - fi - fi - fi - AC_SUBST([$1]) -]) diff --git a/flac/m4/lib-prefix.m4 b/flac/m4/lib-prefix.m4 deleted file mode 100644 index 51687d3..0000000 --- a/flac/m4/lib-prefix.m4 +++ /dev/null @@ -1,224 +0,0 @@ -# lib-prefix.m4 serial 7 (gettext-0.18) -dnl Copyright (C) 2001-2005, 2008-2012 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_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 -dnl - a variable acl_libdirstem, containing the basename of the libdir, either -dnl "lib" or "lib64" or "lib/64", -dnl - a variable acl_libdirstem2, as a secondary possible value for -dnl acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or -dnl "lib/amd64". -AC_DEFUN([AC_LIB_PREPARE_MULTILIB], -[ - dnl There is no formal standard regarding lib and lib64. - dnl On glibc systems, the current practice is that on a system supporting - dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under - dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine - dnl the compiler's default mode by looking at the compiler's library search - dnl path. If at least one of its elements ends in /lib64 or points to a - dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI. - dnl Otherwise we use the default, namely "lib". - dnl On Solaris systems, the current practice is that on a system supporting - dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under - dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or - dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib. - AC_REQUIRE([AC_CANONICAL_HOST]) - acl_libdirstem=lib - acl_libdirstem2= - case "$host_os" in - solaris*) - dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment - dnl . - dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link." - dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the - dnl symlink is missing, so we set acl_libdirstem2 too. - AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit], - [AC_EGREP_CPP([sixtyfour bits], [ -#ifdef _LP64 -sixtyfour bits -#endif - ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no]) - ]) - if test $gl_cv_solaris_64bit = yes; then - acl_libdirstem=lib/64 - case "$host_cpu" in - sparc*) acl_libdirstem2=lib/sparcv9 ;; - i*86 | x86_64) acl_libdirstem2=lib/amd64 ;; - esac - fi - ;; - *) - 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 ;; - */../ | */.. ) - # Better ignore directories of this form. They are misleading. - ;; - *) searchdir=`cd "$searchdir" && pwd` - case "$searchdir" in - */lib64 ) acl_libdirstem=lib64 ;; - esac ;; - esac - fi - done - IFS="$acl_save_IFS" - fi - ;; - esac - test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem" -]) diff --git a/flac/m4/ogg.m4 b/flac/m4/ogg.m4 deleted file mode 100644 index 3b1a28a..0000000 --- a/flac/m4/ogg.m4 +++ /dev/null @@ -1,114 +0,0 @@ -# Configure paths for libogg -# Jack Moffitt 10-21-2000 -# Shamelessly stolen from Owen Taylor and Manish Singh - -dnl XIPH_PATH_OGG([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libogg, and define OGG_CFLAGS and OGG_LIBS -dnl -AC_DEFUN([XIPH_PATH_OGG], -[dnl -dnl Get the cflags and libraries -dnl -AC_ARG_WITH(ogg,AS_HELP_STRING([--with-ogg=PFX],[Prefix where libogg is installed (optional)]), ogg_prefix="$withval", ogg_prefix="") -AC_ARG_WITH(ogg-libraries,AS_HELP_STRING([--with-ogg-libraries=DIR],[Directory where libogg library is installed (optional)]), ogg_libraries="$withval", ogg_libraries="") -AC_ARG_WITH(ogg-includes,AS_HELP_STRING([--with-ogg-includes=DIR],[Directory where libogg header files are installed (optional)]), ogg_includes="$withval", ogg_includes="") -AC_ARG_ENABLE(oggtest,AS_HELP_STRING([--disable-oggtest],[Do not try to compile and run a test Ogg program]),, enable_oggtest=yes) - - if test "x$ogg_libraries" != "x" ; then - OGG_LIBS="-L$ogg_libraries" - elif test "x$ogg_prefix" = "xno" || test "x$ogg_prefix" = "xyes" ; then - OGG_LIBS="" - elif test "x$ogg_prefix" != "x" ; then - OGG_LIBS="-L$ogg_prefix/lib" - elif test "x$prefix" != "xNONE" ; then - OGG_LIBS="-L$prefix/lib" - fi - - if test "x$ogg_prefix" != "xno" ; then - OGG_LIBS="$OGG_LIBS -logg" - fi - - if test "x$ogg_includes" != "x" ; then - OGG_CFLAGS="-I$ogg_includes" - elif test "x$ogg_prefix" = "xno" || test "x$ogg_prefix" = "xyes" ; then - OGG_CFLAGS="" - elif test "x$ogg_prefix" != "x" ; then - OGG_CFLAGS="-I$ogg_prefix/include" - elif test "x$prefix" != "xNONE"; then - OGG_CFLAGS="-I$prefix/include" - fi - - AC_MSG_CHECKING(for Ogg) - if test "x$ogg_prefix" = "xno" ; then - no_ogg="disabled" - enable_oggtest="no" - else - no_ogg="" - fi - - - if test "x$enable_oggtest" = "xyes" ; then - ac_save_CFLAGS="$CFLAGS" - ac_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $OGG_CFLAGS" - LIBS="$LIBS $OGG_LIBS" -dnl -dnl Now check if the installed Ogg is sufficiently new. -dnl - rm -f conf.oggtest - AC_RUN_IFELSE([AC_LANG_SOURCE([[ -#include -#include -#include -#include - -int main () -{ - system("touch conf.oggtest"); - return 0; -} - -]])],[],[no_ogg=yes],[echo $ac_n "cross compiling; assumed OK... $ac_c"]) - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi - - if test "x$no_ogg" = "xdisabled" ; then - AC_MSG_RESULT(no) - ifelse([$2], , :, [$2]) - elif test "x$no_ogg" = "x" ; then - AC_MSG_RESULT(yes) - ifelse([$1], , :, [$1]) - else - AC_MSG_RESULT(no) - if test -f conf.oggtest ; then - : - else - echo "*** Could not run Ogg test program, checking why..." - CFLAGS="$CFLAGS $OGG_CFLAGS" - LIBS="$LIBS $OGG_LIBS" - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ -#include -#include -]], [[ return 0; ]])],[ echo "*** The test program compiled, but did not run. This usually means" - echo "*** that the run-time linker is not finding Ogg or finding the wrong" - echo "*** version of Ogg. If it is not finding Ogg, 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 occurred. This usually means Ogg was incorrectly installed" - echo "*** or that you have moved Ogg since it was installed." ]) - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi - OGG_CFLAGS="" - OGG_LIBS="" - ifelse([$2], , :, [$2]) - fi - AC_SUBST(OGG_CFLAGS) - AC_SUBST(OGG_LIBS) - rm -f conf.oggtest -]) diff --git a/flac/m4/really_gcc.m4 b/flac/m4/really_gcc.m4 deleted file mode 100644 index 8bc94d5..0000000 --- a/flac/m4/really_gcc.m4 +++ /dev/null @@ -1,29 +0,0 @@ -dnl @synopsis XIPH_GCC_REALLY_IS_GCC -dnl -dnl Find out if a compiler claiming to be gcc really is gcc (clang lies). -dnl @version 1.0 Oct 31 2013 -dnl @author Erik de Castro Lopo -dnl -dnl Permission to use, copy, modify, distribute, and sell this file for any -dnl purpose is hereby granted without fee, provided that the above copyright -dnl and this permission notice appear in all copies. No representations are -dnl made about the suitability of this software for any purpose. It is -dnl provided "as is" without express or implied warranty. -dnl - -# If the configure script has already detected GNU GCC, then make sure it -# isn't CLANG masquerading as GCC. - -AC_DEFUN([XIPH_GCC_REALLY_IS_GCC], -[ AC_LANG_ASSERT(C) - if test "x$ac_cv_c_compiler_gnu" = "xyes" ; then - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #include - ]], [[ - #ifdef __clang__ - This is clang! - #endif - ]])],[ac_cv_c_compiler_gnu=yes],[ac_cv_c_compiler_gnu=no - ]) - fi -]) diff --git a/flac/m4/stack_protect.m4 b/flac/m4/stack_protect.m4 deleted file mode 100644 index cf8af66..0000000 --- a/flac/m4/stack_protect.m4 +++ /dev/null @@ -1,67 +0,0 @@ -dnl Copyright (C) 2013-2023 Xiph.Org Foundation -dnl -dnl Redistribution and use in source and binary forms, with or without -dnl modification, are permitted provided that the following conditions -dnl are met: -dnl -dnl - Redistributions of source code must retain the above copyright -dnl notice, this list of conditions and the following disclaimer. -dnl -dnl - Redistributions in binary form must reproduce the above copyright -dnl notice, this list of conditions and the following disclaimer in the -dnl documentation and/or other materials provided with the distribution. -dnl -dnl - Neither the name of the Xiph.org Foundation nor the names of its -dnl contributors may be used to endorse or promote products derived from -dnl this software without specific prior written permission. -dnl -dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -dnl We want to know if GCC stack protector works, for the C and for the C++ -dnl compiler. -dnl -dnl Just checking if the compiler accepts the required CFLAGSs is not enough -dnl because we have seen at least one instance where this check was -dnl in-sufficient. -dnl -dnl Instead, try to compile and link a test program with the stack protector -dnl flags. If that works, we use it. - -AC_DEFUN([XIPH_GCC_STACK_PROTECTOR], -[AC_LANG_ASSERT(C) - AC_MSG_CHECKING([if $CC supports stack smash protection]) - xiph_stack_check_old_cflags="$CFLAGS" - SSP_FLAGS="-fstack-protector-strong" - CFLAGS=$SSP_FLAGS - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #include - ]], [[puts("Hello, World!"); return 0;]])],[AC_MSG_RESULT(yes) - CFLAGS="$xiph_stack_check_old_cflags $SSP_FLAGS"],[AC_MSG_RESULT(no) - CFLAGS="$xiph_stack_check_old_cflags" - ]) -])# XIPH_GCC_STACK_PROTECTOR - -AC_DEFUN([XIPH_GXX_STACK_PROTECTOR], -[AC_LANG_PUSH([C++]) - AC_MSG_CHECKING([if $CXX supports stack smash protection]) - xiph_stack_check_old_cxxflags="$CXXFLAGS" - SSP_FLAGS="-fstack-protector-strong" - CXXFLAGS=$SSP_FLAGS - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #include - ]], [[puts("Hello, World!"); return 0;]])],[AC_MSG_RESULT(yes) - CXXFLAGS="$xiph_stack_check_old_cxxflags $SSP_FLAGS"],[AC_MSG_RESULT(no) - CXXFLAGS="$xiph_stack_check_old_cxxflags" - ]) - AC_LANG_POP([C++]) -])# XIPH_GXX_STACK_PROTECTOR diff --git a/flac/man/Makefile.am b/flac/man/Makefile.am deleted file mode 100644 index 50bacae..0000000 --- a/flac/man/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -# flac - Command-line FLAC encoder/decoder -# Copyright (C) 2000-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -if FLaC__HAS_PANDOC -flac.1: flac.md - pandoc --standalone --to man $? > $@ - -metaflac.1: metaflac.md - pandoc --standalone --to man $? > $@ - -man_MANS = flac.1 metaflac.1 - -else -if FLaC__HAS_PREBUILT_MANPAGES -man_MANS = flac.1 metaflac.1 -endif -endif - -EXTRA_DIST = flac.1 metaflac.1 flac.md metaflac.md diff --git a/flac/man/flac.md b/flac/man/flac.md deleted file mode 100644 index b51ac69..0000000 --- a/flac/man/flac.md +++ /dev/null @@ -1,760 +0,0 @@ -% flac(1) Version 1.4.3 | Free Lossless Audio Codec conversion tool - -# NAME - -flac - Free Lossless Audio Codec - -# SYNOPSIS - -**flac** \[ *OPTIONS* \] \[ *infile.wav* \| *infile.rf64* \| -*infile.aiff* \| *infile.raw* \| *infile.flac* \| *infile.oga* \| -*infile.ogg* \| **-** *...* \] - -**flac** \[ **-d** \| **\--decode** \| **-t** \| **\--test** \| **-a** \| -**\--analyze** \] \[ *OPTIONS* \] \[ *infile.flac* \| *infile.oga* \| -*infile.ogg* \| **-** *...* \] - -# DESCRIPTION - -**flac** is a command-line tool for encoding, decoding, testing and -analyzing FLAC streams. - -# GENERAL USAGE - -**flac** supports as input RIFF WAVE, Wave64, RF64, AIFF, FLAC or Ogg -FLAC format, or raw interleaved samples. The decoder currently can output -to RIFF WAVE, Wave64, RF64, or AIFF format, or raw interleaved samples. -flac only supports linear PCM samples (in other words, no A-LAW, uLAW, -etc.), and the input must be between 4 and 32 bits per sample. - -flac assumes that files ending in ".wav" or that have the RIFF WAVE -header present are WAVE files, files ending in ".w64" or have the Wave64 -header present are Wave64 files, files ending in ".rf64" or have the -RF64 header present are RF64 files, files ending in ".aif" or ".aiff" or -have the AIFF header present are AIFF files, files ending in ".flac" -or have the FLAC header present are FLAC files and files ending in ".oga" -or ".ogg" or have the Ogg FLAC header present are Ogg FLAC files. - -Other than this, flac makes no assumptions about file extensions, though -the convention is that FLAC files have the extension ".flac" -(or ".fla" on ancient "8.3" file systems like FAT-16). - -Before going into the full command-line description, a few other things -help to sort it out: -1. flac encodes by default, so you must use -d to decode -2. the options -0 .. -8 (or --fast and --best) that control the - compression level actually are just synonyms for different groups of - specific encoding options (described later) and you can get the same - effect by using the same options. When specific options are specified - they take priority over the compression level no matter the order -3. flac behaves similarly to gzip in the way it handles input and output - files -4. the order in which options are specified is generally not important - -Skip to the examples below for examples of some common tasks. - -flac will be invoked one of four ways, depending on whether you are -encoding, decoding, testing, or analyzing. Encoding is the default -invocation, but can be switch to decoding with **-d**, analysis with -**-a** or testing with **-t**. Depending on which way is chosen, -encoding, decoding, analysis or testing options can be used, see section -OPTIONS for details. General options can be used for all. - -If only one inputfile is specified, it may be "-" for stdin. When stdin -is used as input, flac will write to stdout. Otherwise flac will perform -the desired operation on each input file to similarly named output files -(meaning for encoding, the extension will be replaced with ".flac", or -appended with ".flac" if the input file has no extension, and for -decoding, the extension will be ".wav" for WAVE output and ".raw" for raw -output). The original file is not deleted unless --delete-input-file is -specified. - -If you are encoding/decoding from stdin to a file, you should use the -o -option like so: - - flac [options] -o outputfile - flac -d [options] -o outputfile - -which are better than: - - flac [options] > outputfile - flac -d [options] > outputfile - -since the former allows flac to seek backwards to write the STREAMINFO or -RIFF WAVE header contents when necessary. - -Also, you can force output data to go to stdout using -c. - -To encode or decode files that start with a dash, use -- to signal the -end of options, to keep the filenames themselves from being treated as -options: - - flac -V -- -01-filename.wav - -The encoding options affect the compression ratio and encoding speed. The -format options are used to tell flac the arrangement of samples if the -input file (or output file when decoding) is a raw file. If it is a RIFF -WAVE, Wave64, RF64, or AIFF file the format options are not needed since -they are read from the file's header. - -In test mode, flac acts just like in decode mode, except no output file -is written. Both decode and test modes detect errors in the stream, but -they also detect when the MD5 signature of the decoded audio does not -match the stored MD5 signature, even when the bitstream is valid. - -flac can also re-encode FLAC files. In other words, you can specify a -FLAC or Ogg FLAC file as an input to the encoder and it will decoder it -and re-encode it according to the options you specify. It will also -preserve all the metadata unless you override it with other options (e.g. -specifying new tags, seekpoints, cuesheet, padding, etc.). - -flac has been tuned so that the default settings yield a good speed vs. -compression tradeoff for many kinds of input. However, if you are looking -to maximize the compression rate or speed, or want to use the full power -of FLAC's metadata system, see the page titled 'About the FLAC Format' on -the FLAC website. - -# EXAMPLES - -Some common **encoding** tasks using flac: - -`flac abc.wav` -: Encode abc.wav to abc.flac using the default compression setting. abc.wav is not deleted. - -`flac --delete-input-file abc.wav` -: Like above, except abc.wav is deleted if there were no errors. - -`flac --delete-input-file -w abc.wav` -: Like above, except abc.wav is deleted if there were no errors or warnings. - -`flac --best abc.wav` -: Encode abc.wav to abc.flac using the highest compression setting. - -`flac --verify abc.wav` -: Encode abc.wav to abc.flac and internally decode abc.flac to make sure it matches abc.wav. - -`flac -o my.flac abc.wav` -: Encode abc.wav to my.flac. - -`flac -T "TITLE=Bohemian Rhapsody" -T "ARTIST=Queen" abc.wav` -: Encode abc.wav and add some tags at the same time to abc.flac. - -`flac *.wav` -: Encode all .wav files in the current directory. - -`flac abc.aiff` -: Encode abc.aiff to abc.flac. - -`flac abc.rf64` -: Encode abc.rf64 to abc.flac. - -`flac abc.w64` -: Encode abc.w64 to abc.flac. - -`flac abc.flac --force` -: This one's a little tricky: notice that flac is in encode mode by - default (you have to specify -d to decode) so this command actually - recompresses abc.flac back to abc.flac. --force is needed to make - sure you really want to overwrite abc.flac with a new version. Why - would you want to do this? It allows you to recompress an existing - FLAC file with (usually) higher compression options or a newer - version of FLAC and preserve all the metadata like tags too. - -Some common **decoding** tasks using flac: - -`flac -d abc.flac` -: Decode abc.flac to abc.wav. abc.flac is not deleted. NOTE: Without - -d it means re-encode abc.flac to abc.flac (see above). - -`flac -d --force-aiff-format abc.flac` -`flac -d -o abc.aiff abc.flac` -: Two different ways of decoding abc.flac to abc.aiff (AIFF format). - abc.flac is not deleted. - -`flac -d --force-rf64-format abc.flac` -`flac -d -o abc.rf64 abc.flac` -: Two different ways of decoding abc.flac to abc.rf64 (RF64 format). - abc.flac is not deleted. - -`flac -d --force-wave64-format abc.flac` -`flac -d -o abc.w64 abc.flac` -: Two different ways of decoding abc.flac to abc.w64 (Wave64 format). - abc.flac is not deleted. - -`flac -d -F abc.flac` -: Decode abc.flac to abc.wav and don't abort if errors are found - (useful for recovering as much as possible from corrupted files). - - -# OPTIONS - -A summary of options is included below. For a complete description, see -the HTML documentation. - -## GENERAL OPTIONS - -**-v, \--version** -: Show the flac version number - -**-h, \--help** -: Show basic usage and a list of all options - -**-H, \--explain** -: Show detailed explanation of usage and all options - -**-d, \--decode** -: Decode (the default behavior is to encode) - -**-t, \--test** -: Test a flac encoded file (same as -d except no decoded file is written) - -**-a, \--analyze** -: Analyze a FLAC encoded file (same as -d except an analysis file is - written) - -**-c, \--stdout** -: Write output to stdout - -**-s, \--silent** -: Silent mode (do not write runtime encode/decode statistics to stderr) - -**\--totally-silent** -: Do not print anything of any kind, including warnings or errors. The - exit code will be the only way to determine successful completion. - -**\--no-utf8-convert** -: Do not convert tags from local charset to UTF-8. This is useful for - scripts, and setting tags in situations where the locale is wrong. - This option must appear before any tag options! - -**-w, \--warnings-as-errors** -: Treat all warnings as errors (which cause flac to terminate with a - non-zero exit code). - -**-f, \--force** -: Force overwriting of output files. By default, flac warns that the - output file already exists and continues to the next file. - -**-o** *filename***, \--output-name=***filename* -: Force the output file name (usually flac just changes the extension). - May only be used when encoding a single file. May not be used in - conjunction with \--output-prefix. - -**\--output-prefix=***string* -: Prefix each output file name with the given string. This can be - useful for encoding or decoding files to a different directory. Make - sure if your string is a path name that it ends with a trailing \`/' - (slash). - -**\--delete-input-file** -: Automatically delete the input file after a successful encode or - decode. If there was an error (including a verify error) the input - file is left intact. - -**\--preserve-modtime** -: Output files have their timestamps/permissions set to match those of - their inputs (this is default). Use \--no-preserve-modtime to make - output files have the current time and default permissions. - -**\--keep-foreign-metadata** -: If encoding, save WAVE, RF64, or AIFF non-audio chunks in FLAC - metadata. If decoding, restore any saved non-audio chunks from FLAC - metadata when writing the decoded file. Foreign metadata cannot be - transcoded, e.g. WAVE chunks saved in a FLAC file cannot be restored - when decoding to AIFF. Input and output must be regular files (not - stdin or stdout). With this option, FLAC will pick the right output - format on decoding. - -**\--keep-foreign-metadata-if-present** -: Like \--keep-foreign-metadata, but without throwing an error if - foreign metadata cannot be found or restored, instead printing a - warning. - -**\--skip={***\#***\|***mm:ss.ss***}** -: Skip over the first number of samples of the input. This works for - both encoding and decoding, but not testing. The alternative form - mm:ss.ss can be used to specify minutes, seconds, and fractions of a - second. - -**\--until={***\#***\|\[***+***\|***-***\]***mm:ss.ss***}** -: Stop at the given sample number for each input file. This works for - both encoding and decoding, but not testing. The given sample number - is not included in the decoded output. The alternative form mm:ss.ss - can be used to specify minutes, seconds, and fractions of a second. - If a \`+' (plus) sign is at the beginning, the \--until point is - relative to the \--skip point. If a \`-' (minus) sign is at the - beginning, the \--until point is relative to end of the audio. - -**\--ogg** -: When encoding, generate Ogg FLAC output instead of native FLAC. Ogg - FLAC streams are FLAC streams wrapped in an Ogg transport layer. The - resulting file should have an '.oga' extension and will still be - decodable by flac. When decoding, force the input to be treated as - Ogg FLAC. This is useful when piping input from stdin or when the - filename does not end in '.oga' or '.ogg'. - -**\--serial-number=***\#* -: When used with \--ogg, specifies the serial number to use for the - first Ogg FLAC stream, which is then incremented for each additional - stream. When encoding and no serial number is given, flac uses a - random number for the first stream, then increments it for each - additional stream. When decoding and no number is given, flac uses - the serial number of the first page. - -## ANALYSIS OPTIONS - -**\--residual-text** -: Includes the residual signal in the analysis file. This will make the - file very big, much larger than even the decoded file. - -**\--residual-gnuplot** -: Generates a gnuplot file for every subframe; each file will contain - the residual distribution of the subframe. This will create a lot of - files. - -## DECODING OPTIONS - -**\--cue=\[***\#.#***\]\[-\[***\#.#***\]\]** -: Set the beginning and ending cuepoints to decode. The optional first - \#.# is the track and index point at which decoding will start; the - default is the beginning of the stream. The optional second \#.# is - the track and index point at which decoding will end; the default is - the end of the stream. If the cuepoint does not exist, the closest - one before it (for the start point) or after it (for the end point) - will be used. If those don't exist, the start of the stream (for the - start point) or end of the stream (for the end point) will be used. - The cuepoints are merely translated into sample numbers then used as - \--skip and \--until. A CD track can always be cued by, for example, - \--cue=9.1-10.1 for track 9, even if the CD has no 10th track. - -**-F, \--decode-through-errors** -: By default flac stops decoding with an error and removes the - partially decoded file if it encounters a bitstream error. With -F, - errors are still printed but flac will continue decoding to - completion. Note that errors may cause the decoded audio to be - missing some samples or have silent sections. - -**\--apply-replaygain-which-is-not-lossless\[=\\]** -: Applies ReplayGain values while decoding. **WARNING: THIS IS NOT - LOSSLESS. DECODED AUDIO WILL NOT BE IDENTICAL TO THE ORIGINAL WITH - THIS OPTION.** This option is useful for example in transcoding - media servers, where the client does not support ReplayGain. For - details on the use of this option, see the section **ReplayGain - application specification**. - -## ENCODING OPTIONS - -**-V, \--verify** -: Verify a correct encoding by decoding the output in parallel and - comparing to the original - -**\--lax** -: Allow encoder to generate non-Subset files. The resulting FLAC file - may not be streamable or might have trouble being played in all - players (especially hardware devices), so you should only use this - option in combination with custom encoding options meant for - archival. - -**\--replay-gain** -: Calculate ReplayGain values and store them as FLAC tags, similar to - vorbisgain. Title gains/peaks will be computed for each input file, - and an album gain/peak will be computed for all files. All input - files must have the same resolution, sample rate, and number of - channels. Only mono and stereo files are allowed, and the sample - rate must be 8, 11.025, 12, 16, 18.9, 22.05, 24, 28, 32, 36, 37.8, - 44.1, 48, 56, 64, 72, 75.6, 88.2, 96, 112, 128, 144, 151.2, 176.4, - 192, 224, 256, 288, 302.4, 352.8, 384, 448, 512, 576, or 604.8 kHz. - Also note that this option may leave a few extra bytes in a PADDING - block as the exact size of the tags is not known until all files - are processed. Note that this option cannot be used when encoding - to standard output (stdout). - -**\--cuesheet=***filename* -: Import the given cuesheet file and store it in a CUESHEET metadata - block. This option may only be used when encoding a single file. A - seekpoint will be added for each index point in the cuesheet to the - SEEKTABLE unless \--no-cued-seekpoints is specified. - -**\--picture={***FILENAME***\|***SPECIFICATION***}** -: Import a picture and store it in a PICTURE metadata block. More than - one \--picture option can be specified. Either a filename for the - picture file or a more complete specification form can be used. The - SPECIFICATION is a string whose parts are separated by \| (pipe) - characters. Some parts may be left empty to invoke default values. - FILENAME is just shorthand for "\|\|\|\|FILENAME". For the format of - SPECIFICATION, see the section **picture specification**. - -**\--ignore-chunk-sizes** -: When encoding to flac, ignore the file size headers in WAV and AIFF - files to attempt to work around problems with over-sized or malformed - files. WAV and AIFF files both have an unsigned 32 bit numbers in - the file header which specifes the length of audio data. Since this - number is unsigned 32 bits, that limits the size of a valid file to - being just over 4 Gigabytes. Files larger than this are mal-formed, - but should be read correctly using this option. - -**-S {***\#***\|***X***\|***\#x***\|***\#s***}, \--seekpoint={***\#***\|***X***\|***\#x***\|***\#s***}** -: Include a point or points in a SEEKTABLE. Using \#, a seek point at - that sample number is added. Using X, a placeholder point is added at - the end of a the table. Using \#x, \# evenly spaced seek points will - be added, the first being at sample 0. Using \#s, a seekpoint will be - added every \# seconds (# does not have to be a whole number; it can - be, for example, 9.5, meaning a seekpoint every 9.5 seconds). You may - use many -S options; the resulting SEEKTABLE will be the unique-ified - union of all such values. With no -S options, flac defaults to - '-S 10s'. Use \--no-seektable for no SEEKTABLE. Note: '-S \#x' and - '-S \#s' will not work if the encoder can't determine the input size - before starting. Note: if you use '-S \#' and \# is \>= samples in - the input, there will be either no seek point entered (if the input - size is determinable before encoding starts) or a placeholder point - (if input size is not determinable). - -**-P** *\#***, \--padding=***\#* -: Tell the encoder to write a PADDING metadata block of the given - length (in bytes) after the STREAMINFO block. This is useful if you - plan to tag the file later with an APPLICATION block; instead of - having to rewrite the entire file later just to insert your block, - you can write directly over the PADDING block. Note that the total - length of the PADDING block will be 4 bytes longer than the length - given because of the 4 metadata block header bytes. You can force no - PADDING block at all to be written with \--no-padding. The encoder - writes a PADDING block of 8192 bytes by default (or 65536 bytes if - the input audio stream is more that 20 minutes long). - -**-T** *FIELD=VALUE***, \--tag=***FIELD=VALUE* -: Add a FLAC tag. The comment must adhere to the Vorbis comment spec; - i.e. the FIELD must contain only legal characters, terminated by an - 'equals' sign. Make sure to quote the comment if necessary. This - option may appear more than once to add several comments. NOTE: all - tags will be added to all encoded files. - -**\--tag-from-file=***FIELD=FILENAME* -: Like \--tag, except FILENAME is a file whose contents will be read - verbatim to set the tag value. The contents will be converted to - UTF-8 from the local charset. This can be used to store a cuesheet - in a tag (e.g. \--tag-from-file="CUESHEET=image.cue"). Do not try to - store binary data in tag fields! Use APPLICATION blocks for that. - -**-b** *\#***, \--blocksize=***\#* -: Specify the blocksize in samples. The default is 1152 for -l 0, - else 4096. For subset streams this must be \<= 4608 if the samplerate - \<= 48kHz, for subset streams with higher samplerates it must be \<= - 16384. - -**-m, \--mid-side** -: Try mid-side coding for each frame (stereo input only) - -**-M, \--adaptive-mid-side** -: Adaptive mid-side coding for all frames (stereo input only) - -**-0..-8, \--compression-level-0..\--compression-level-8** -: Fastest compression..highest compression (default is -5). These are - synonyms for other options: - -**-0, \--compression-level-0** -: Synonymous with -l 0 -b 1152 -r 3 \--no-mid-side - -**-1, \--compression-level-1** -: Synonymous with -l 0 -b 1152 -M -r 3 - -**-2, \--compression-level-2** -: Synonymous with -l 0 -b 1152 -m -r 3 - -**-3, \--compression-level-3** -: Synonymous with -l 6 -b 4096 -r 4 \--no-mid-side - -**-4, \--compression-level-4** -: Synonymous with -l 8 -b 4096 -M -r 4 - -**-5, \--compression-level-5** -: Synonymous with -l 8 -b 4096 -m -r 5 - -**-6, \--compression-level-6** -: Synonymous with -l 8 -b 4096 -m -r 6 -A subdivide_tukey(2) - -**-7, \--compression-level-7** -: Synonymous with -l 12 -b 4096 -m -r 6 -A subdivide_tukey(2) - -**-8, \--compression-level-8** -: Synonymous with -l 12 -b 4096 -m -r 6 -A subdivide_tukey(3) - -**\--fast** -: Fastest compression. Currently synonymous with -0. - -**\--best** -: Highest compression. Currently synonymous with -8. - -**-e, \--exhaustive-model-search** -: Do exhaustive model search (expensive!) - -**-A** *function***, \--apodization=***function* -: Window audio data with given the apodization function. See section - **Apodization functions** for details. - -**-l** *\#***, \--max-lpc-order=***\#* -: Specifies the maximum LPC order. This number must be \<= 32. For - subset streams, it must be \<=12 if the sample rate is \<=48kHz. If - 0, the encoder will not attempt generic linear prediction, and use - only fixed predictors. Using fixed predictors is faster but usually - results in files being 5-10% larger. - -**-p, \--qlp-coeff-precision-search** -: Do exhaustive search of LP coefficient quantization (expensive!). - Overrides -q; does nothing if using -l 0 - -**-q** *\#***, \--qlp-coeff-precision=***\#* -: Precision of the quantized linear-predictor coefficients, 0 =\> let - encoder decide (min is 5, default is 0) - -**-r \[***\#***,\]***\#***, \--rice-partition-order=\[***\#***,\]***\#* -: Set the \[min,\]max residual partition order (0..15). min defaults to - 0 if unspecified. Default is -r 5. - -## FORMAT OPTIONS - -**\--endian={***big***\|***little***}** -: Set the byte order for samples - -**\--channels=***\#* -: Set number of channels. - -**\--bps=***\#* -: Set bits per sample. - -**\--sample-rate=***\#* -: Set sample rate (in Hz). - -**\--sign={***signed***\|***unsigned***}** -: Set the sign of samples. - -**\--input-size=***\#* -: Specify the size of the raw input in bytes. If you are encoding raw - samples from stdin, you must set this option in order to be able to - use \--skip, \--until, \--cuesheet, or other options that need to - know the size of the input beforehand. If the size given is greater - than what is found in the input stream, the encoder will complain - about an unexpected end-of-file. If the size given is less, samples - will be truncated. - -**\--force-raw-format** -: Force input (when encoding) or output (when decoding) to be treated - as raw samples (even if filename ends in *.wav*). - -**\--force-aiff-format** -**\--force-rf64-format** -**\--force-wave64-format** -: Force the decoder to output AIFF/RF64/WAVE64 format respectively. - This option is not needed if the output filename (as set by -o) - ends with *.aif* or *.aiff*, *.rf64* and *.w64* respectively. Also, - this option has no effect when encoding since input is - auto-detected. When none of these options nor - --keep-foreign-metadata are given and no output filename is set, - the output format is WAV by default. - -**\--force-legacy-wave-format** -**\--force-extensible-wave-format** -: Instruct the decoder to output a WAVE file with WAVE_FORMAT_PCM and - WAVE_FORMAT_EXTENSIBLE respectively. If none of these options nor - --keep-foreign-metadata are given, FLAC outputs WAVE_FORMAT_PCM - for mono or stereo with a bit depth of 8 or 16 bits, and - WAVE_FORMAT_EXTENSIBLE for all other audio formats. - -**\--force-aiff-c-none-format** -**\--force-aiff-c-sowt-format** -: Instruct the decoder to output an AIFF-C file with format NONE and - sowt respectively. - -## NEGATIVE OPTIONS - -**\--no-adaptive-mid-side** -**\--no-cued-seekpoints** -**\--no-decode-through-errors** -**\--no-delete-input-file** -**\--no-preserve-modtime** -**\--no-keep-foreign-metadata** -**\--no-exhaustive-model-search** -**\--no-force** -**\--no-lax** -**\--no-mid-side** -**\--no-ogg** -**\--no-padding** -**\--no-qlp-coeff-prec-search** -**\--no-replay-gain** -**\--no-residual-gnuplot** -**\--no-residual-text** -**\--no-seektable** -**\--no-silent** -**\--no-verify** -**\--no-warnings-as-errors** - -These flags can be used to invert the sense of the corresponding normal -option. - -## ReplayGain application specification -The option \--apply-replaygain-which-is-not-lossless\[=\\]** -applies ReplayGain values while decoding. **WARNING: THIS IS NOT -LOSSLESS. DECODED AUDIO WILL NOT BE IDENTICAL TO THE ORIGINAL WITH THIS -OPTION.** This option is useful for example in transcoding media servers, -where the client does not support ReplayGain. - -The equals sign and \ is optional. If omitted, the -default specification is 0aLn1. - -The \ is a shorthand notation for describing how to apply -ReplayGain. All components are optional but order is important. '\[\]' -means 'optional'. '\|' means 'or'. '{}' means required. The format is: - -\[\\]\[a\|t\]\[l\|L\]\[n{0\|1\|2\|3}\] - -In which the following parameters are used: - -- **preamp**: A floating point number in dB. This is added to the - existing gain value. - -- **a\|t**: Specify 'a' to use the album gain, or 't' to use the track - gain. If tags for the preferred kind (album/track) do not exist but - tags for the other (track/album) do, those will be used instead. - -- **l\|L**: Specify 'l' to peak-limit the output, so that the - ReplayGain peak value is full-scale. Specify 'L' to use a 6dB hard - limiter that kicks in when the signal approaches full-scale. - -- **n{0\|1\|2\|3}**: Specify the amount of noise shaping. ReplayGain - synthesis happens in floating point; the result is dithered before - converting back to integer. This quantization adds noise. Noise - shaping tries to move the noise where you won't hear it as much. - 0 means no noise shaping, 1 means 'low', 2 means 'medium', 3 means - 'high'. - -For example, the default of 0aLn1 means 0dB preamp, use album gain, 6dB -hard limit, low noise shaping. \--apply-replaygain-which-is-not-lossless=3 -means 3dB preamp, use album gain, no limiting, no noise shaping. - -flac uses the ReplayGain tags for the calculation. If a stream does -not have the required tags or they can't be parsed, decoding will -continue with a warning, and no ReplayGain is applied to that stream. - -## Picture specification -This described the specification used for the **\--picture** option. -\[TYPE\]\|\[MIME-TYPE\]\|\[DESCRIPTION\]\|\[WIDTHxHEIGHTxDEPTH\[/COLORS\]\]\|FILE - -TYPE is optional; it is a number from one of: - -0. Other -1. 32x32 pixels 'file icon' (PNG only) -2. Other file icon -3. Cover (front) -4. Cover (back) -5. Leaflet page -6. Media (e.g. label side of CD) -7. Lead artist/lead performer/soloist -8. Artist/performer -9. Conductor -10. Band/Orchestra -11. Composer -12. Lyricist/text writer -13. Recording Location -14. During recording -15. During performance -16. Movie/video screen capture -17. A bright coloured fish -18. Illustration -19. Band/artist logotype -20. Publisher/Studio logotype - -The default is 3 (front cover). There may only be one picture each of -type 1 and 2 in a file. - -MIME-TYPE is optional; if left blank, it will be detected from the file. -For best compatibility with players, use pictures with MIME type -image/jpeg or image/png. The MIME type can also be \--\> to mean that -FILE is actually a URL to an image, though this use is discouraged. - -DESCRIPTION is optional; the default is an empty string. - -The next part specifies the resolution and color information. If the -MIME-TYPE is image/jpeg, image/png, or image/gif, you can usually leave -this empty and they can be detected from the file. Otherwise, you must -specify the width in pixels, height in pixels, and color depth in -bits-per-pixel. If the image has indexed colors you should also specify -the number of colors used. When manually specified, it is not checked -against the file for accuracy. - -FILE is the path to the picture file to be imported, or the URL if MIME -type is \--\> - -For example, "\|image/jpeg\|\|\|../cover.jpg" will embed the JPEG file -at ../cover.jpg, defaulting to type 3 (front cover) and an empty -description. The resolution and color info will be retrieved from the -file itself. - -The specification -"4\|\--\>\|CD\|320x300x24/173\|http://blah.blah/backcover.tiff" will -embed the given URL, with type 4 (back cover), description "CD", and a -manually specified resolution of 320x300, 24 bits-per-pixel, and 173 -colors. The file at the URL will not be fetched; the URL itself is -stored in the PICTURE metadata block. - -## Apodization functions -To improve LPC analysis, audio data is windowed . The window can be -selected with one or more **-A** options. Possible functions are: -bartlett, bartlett_hann, blackman, blackman_harris_4term_92db, -connes, flattop, gauss(STDDEV), hamming, hann, kaiser_bessel, nuttall, -rectangle, triangle, tukey(P), partial_tukey(n\[/ov\[/P\]\]), -punchout_tukey(n\[/ov\[/P\]\]), subdivide_tukey(n\[/P\]) welch. - -- For gauss(STDDEV), STDDEV is the standard deviation (0\ for the Debian GNU/Linux system (but may be used by -others). It has been kept up-to-date by the Xiph.org Foundation. diff --git a/flac/man/metaflac.md b/flac/man/metaflac.md deleted file mode 100644 index 8c049d7..0000000 --- a/flac/man/metaflac.md +++ /dev/null @@ -1,299 +0,0 @@ -% metaflac(1) Version 1.4.3 | Free Lossless Audio Codec metadata tool - -# NAME - -metaflac - program to list, add, remove, or edit metadata in one or more -FLAC files. - -# SYNOPSIS - -**metaflac** \[ *options* \] \[ *operations* \] *FLACfile ...* - -# DESCRIPTION - -Use **metaflac** to list, add, remove, or edit metadata in one or more -FLAC files. You may perform one major operation, or many shorthand -operations at a time. - -# GENERAL USAGE - -metaflac is the command-line .flac file metadata editor. You can use it -to list the contents of metadata blocks, edit, delete or insert blocks, -and manage padding. - -metaflac takes a set of "options" (though some are not optional) and a -set of FLAC files to operate on. There are three kinds of "options": - -- Major operations, which specify a mode of operation like listing - blocks, removing blocks, etc. These will have sub-operations describing - exactly what is to be done. - -- Shorthand operations, which are convenient synonyms for major - operations. For example, there is a shorthand operation - --show-sample-rate that shows just the sample rate field from the - STREAMINFO metadata block. - -- Global options, which affect all the operations. - -All of these are described in the tables below. At least one shorthand -or major operation must be supplied. You can use multiple shorthand -operations to do more than one thing to a file or set of files. Most of -the common things to do to metadata have shorthand operations. As an -example, here is how to show the MD5 signatures for a set of three FLAC -files: - -`metaflac --show-md5sum file1.flac file2.flac file3.flac` - -Another example; this removes all DESCRIPTION and COMMENT tags in a set -of FLAC files, and uses the --preserve-modtime global option to keep the -FLAC file modification times the same (usually when files are edited the -modification time is set to the current time): - -`metaflac --preserve-modtime --remove-tag=DESCRIPTION --remove-tag=COMMENT file1.flac file2.flac file3.flac` - -# OPTIONS - -**\--preserve-modtime** -: Preserve the original modification time in spite of edits. - -**\--with-filename** -: Prefix each output line with the FLAC file name (the default if more - than one FLAC file is specified). This option has no effect for - options exporting to a file, like --export-tags-to. - -**\--no-filename** -: Do not prefix each output line with the FLAC file name (the default - if only one FLAC file is specified). - -**\--no-utf8-convert** -: Do not convert tags from UTF-8 to local charset, or vice versa. This - is useful for scripts, and setting tags in situations where the - locale is wrong. - -**\--dont-use-padding** -: By default metaflac tries to use padding where possible to avoid - rewriting the entire file if the metadata size changes. Use this - option to tell metaflac to not take advantage of padding this way. - -# SHORTHAND OPERATIONS - -**\--show-md5sum** -: Show the MD5 signature from the STREAMINFO block. - -**\--show-min-blocksize** -: Show the minimum block size from the STREAMINFO block. - -**\--show-max-blocksize** -: Show the maximum block size from the STREAMINFO block. - -**\--show-min-framesize** -: Show the minimum frame size from the STREAMINFO block. - -**\--show-max-framesize** -: Show the maximum frame size from the STREAMINFO block. - -**\--show-sample-rate** -: Show the sample rate from the STREAMINFO block. - -**\--show-channels** -: Show the number of channels from the STREAMINFO block. - -**\--show-bps** -: Show the \# of bits per sample from the STREAMINFO block. - -**\--show-total-samples** -: Show the total \# of samples from the STREAMINFO block. - -**\--show-vendor-tag** -: Show the vendor string from the VORBIS_COMMENT block. - -**\--show-tag=name** -: Show all tags where the field name matches 'name'. - -**\--show-all-tags** -: Show all tags. This is an alias for --export-tags-to=-. - -**\--remove-tag=name** -: Remove all tags whose field name is 'name'. - -**\--remove-first-tag=name** -: Remove first tag whose field name is 'name'. - -**\--remove-all-tags** -: Remove all tags, leaving only the vendor string. - -**\--remove-all-tags-except=NAME1\[=NAME2\[=...\]\]** -: Remove all tags, except the vendor string and the tag names - specified. Tag names must be separated by an = character. - -**\--set-tag=field** -: Add a tag. The field must comply with the Vorbis comment spec, of the - form "NAME=VALUE". If there is currently no tag block, one will be - created. - -**\--set-tag-from-file=field** -: Like \--set-tag, except the VALUE is a filename whose contents will - be read verbatim to set the tag value. Unless \--no-utf8-convert is - specified, the contents will be converted to UTF-8 from the local - charset. This can be used to store a cuesheet in a tag (e.g. - \--set-tag-from-file="CUESHEET=image.cue"). Do not try to store - binary data in tag fields! Use APPLICATION blocks for that. - -**\--import-tags-from=file** -: Import tags from a file. Use '-' for stdin. Each line should be of - the form NAME=VALUE. Multi-line comments are currently not supported. - Specify \--remove-all-tags and/or \--no-utf8-convert before - \--import-tags-from if necessary. If FILE is '-' (stdin), only one - FLAC file may be specified. - -**\--export-tags-to=file** -: Export tags to a file. Use '-' for stdout. Each line will be of the - form NAME=VALUE. Specify \--no-utf8-convert if necessary. - -**\--import-cuesheet-from=file** -: Import a cuesheet from a file. Use '-' for stdin. Only one FLAC file - may be specified. A seekpoint will be added for each index point in - the cuesheet to the SEEKTABLE unless \--no-cued-seekpoints is - specified. - -**\--export-cuesheet-to=file** -: Export CUESHEET block to a cuesheet file, suitable for use by CD - authoring software. Use '-' for stdout. Only one FLAC file may be - specified on the command line. - -**\--import-picture-from={***FILENAME***\|***SPECIFICATION***}** -: Import a picture and store it in a PICTURE metadata block. More than - one \--import-picture-from command can be specified. Either a filename - for the picture file or a more complete specification form can be - used. The SPECIFICATION is a string whose parts are separated by \| - (pipe) characters. Some parts may be left empty to invoke default - values. FILENAME is just shorthand for "\|\|\|\|FILENAME". For - details on the specification, see the section **Picture - specification** in the **flac(1)** man page. - -**\--export-picture-to=file** -: Export PICTURE block to a file. Use '-' for stdout. Only one FLAC - file may be specified on the command line. The first PICTURE block - will be exported unless \--export-picture-to is preceded by a - \--block-number=# option to specify the exact metadata block to - extract. Note that the block number is the one shown by \--list. - -**\--add-replay-gain** -: Calculates the title and album gains/peaks of the given FLAC files as - if all the files were part of one album, then stores them as FLAC - tags. The tags are the same as those used by vorbisgain. Existing - ReplayGain tags will be replaced. If only one FLAC file is given, - the album and title gains will be the same. Since this operation - requires two passes, it is always executed last, after all other - operations have been completed and written to disk. All FLAC files - specified must have the same resolution, sample rate, and number of - channels. Only mono and stereo files are allowed, and the sample - rate must be 8, 11.025, 12, 16, 18.9, 22.05, 24, 28, 32, 36, 37.8, - 44.1, 48, 56, 64, 72, 75.6, 88.2, 96, 112, 128, 144, 151.2, 176.4, - 192, 224, 256, 288, 302.4, 352.8, 384, 448, 512, 576, or 604.8 kHz. - -**\--scan-replay-gain** -: Like \--add-replay-gain, but only analyzes the files rather than - writing them to the tags. - -**\--remove-replay-gain** -: Removes the ReplayGain tags. - -**\--add-seekpoint={***\#***\|***X***\|***\#x***\|***\#s***}** -: Add seek points to a SEEKTABLE block. Using \#, a seek point at that - sample number is added. Using X, a placeholder point is added at the - end of a the table. Using \#x, \# evenly spaced seek points will be - added, the first being at sample 0. Using \#s, a seekpoint will be - added every \# seconds (# does not have to be a whole number; it can - be, for example, 9.5, meaning a seekpoint every 9.5 seconds). If no - SEEKTABLE block exists, one will be created. If one already exists, - points will be added to the existing table, and any duplicates will - be turned into placeholder points. You may use many \--add-seekpoint - options; the resulting SEEKTABLE will be the unique-ified union of - all such values. Example: \--add-seekpoint=100x \--add-seekpoint=3.5s - will add 100 evenly spaced seekpoints and a seekpoint every 3.5 - seconds. - -**\--add-padding=length** -: Add a padding block of the given length (in bytes). The overall - length of the new block will be 4 + length; the extra 4 bytes is for - the metadata block header. - -# MAJOR OPERATIONS - -**\--list** -: List the contents of one or more metadata blocks to stdout. By - default, all metadata blocks are listed in text format. Use the - options **\--block-number**, **\--block-type** or - **\--except-block-type** to change this behavior. - -**\--remove** -: Remove one or more metadata blocks from the metadata. Use the options - **\--block-number**, **\--block-type** or **\--except-block-type** - to specify which blocks should be removed. Note that if both - \--block-number and \--[except-]block-type are specified, the result - is the logical AND of both arguments. Unless \--dont-use-padding - is specified, the blocks will be replaced with padding. You may not - remove the STREAMINFO block. - -**\--block-number=#\[,#\[...\]\]** -: An optional comma-separated list of block numbers to display. The - first block, the STREAMINFO block, is block 0. - -**\--block-type=type\[,type\[...\]\]** - -**\--except-block-type=type\[,type\[...\]\]** -: An optional comma-separated list of block types to be included or - ignored with this option. Use only one of \--block-type or - \--except-block-type. The valid block types are: STREAMINFO, PADDING, - APPLICATION, SEEKTABLE, VORBIS_COMMENT, PICTURE. You may narrow down - the types of APPLICATION blocks selected by appending APPLICATION - with a colon and the ID of the APPLICATION block in either ASCII - or hexadecimal representation. E.g. APPLICATION:abcd for the - APPLICATION block(s) whose textual representation of the 4-byte ID - is "abcd" or APPLICATION:0xXXXXXXXX for the APPLICATION block(s) - whose hexadecimal big- endian representation of the 4-byte ID - is "0xXXXXXXXX". For the example "abcd" above the hexadecimal - equivalalent is 0x61626364 - -**\--application-data-format=hexdump\|text** -: If the application block you are displaying contains binary data but - your \--data-format=text, you can display a hex dump of the - application data contents instead using - \--application-data-format=hexdump. - -**\--data-format=binary\|binary-headerless\|text** -: For use with --list. By default a human-readable text - representation of the data is isplayed. You may specify - --data-format=binary to dump the raw binary form of each metadata - block. Specify --data-format=binary-headerless to omit output of - metadata block headers, including the id of APPLICATION metadata - blocks. - -**\--append** -: Insert a metadata block from a file. This must be a binary block as - exported with --list --data-format=binary. The insertion point is - defined with --block-number=#. The new block will be added after the - given block number. This prevents the illegal insertion of a block - before the first STREAMINFO block. You may not --append another - STREAMINFO block. It is possible to copy a metadata block from one - file to another with this option. For example use - `metaflac --list --data-format=binary --block-number=6 file.flac > block` - to export the block, and then import it with - `metaflac --append anotherfile.flac < block` - -**\--remove-all** -: Remove all metadata blocks (except the STREAMINFO block) from the - metadata. Unless \--dont-use-padding is specified, the blocks will be - replaced with padding. - -**\--merge-padding** -: Merge adjacent PADDING blocks into single blocks. - -**\--sort-padding** -: Move all PADDING blocks to the end of the metadata and merge them - into a single block. - -# SEE ALSO - -**flac(1)** diff --git a/flac/microbench/CMakeLists.txt b/flac/microbench/CMakeLists.txt deleted file mode 100644 index 639915b..0000000 --- a/flac/microbench/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -if(MSVC) - return() -endif() - -set(CMAKE_REQUIRED_LIBRARIES rt) -check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) - -if(APPLE) - add_definitions(-DFLAC__SYS_DARWIN) -endif() - -add_executable(benchmark_residual benchmark_residual.c util.c) -target_include_directories(benchmark_residual PRIVATE - "$/include") -target_link_libraries(benchmark_residual - FLAC - $<$:rt>) diff --git a/flac/microbench/Makefile.am b/flac/microbench/Makefile.am deleted file mode 100644 index 81de3ad..0000000 --- a/flac/microbench/Makefile.am +++ /dev/null @@ -1,42 +0,0 @@ -# FLAC - Free Lossless Audio Codec -# Copyright (C) 2015-2023 Xiph.Org Foundation -# -# 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 Xiph.org Foundation 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 FOUNDATION 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. - - -AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src/libFLAC/include - -noinst_HEADERS = util.h - -noinst_PROGRAMS = benchmark_residual - -benchmark_residual_SOURCES = benchmark_residual.c util.c - -benchmark_residual_LDADD = @LIB_CLOCK_GETTIME@ - -EXTRA_DIST = CMakeLists.txt diff --git a/flac/microbench/benchmark_residual.c b/flac/microbench/benchmark_residual.c deleted file mode 100644 index d9b19d7..0000000 --- a/flac/microbench/benchmark_residual.c +++ /dev/null @@ -1,151 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include "FLAC/ordinals.h" -#include "share/compat.h" -#include "private/bitmath.h" -#include "private/fixed.h" -#include "private/macros.h" -#include "FLAC/assert.h" - -#include "util.h" - -static void FLAC__fixed_compute_residual_shift(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]) -{ - const int idata_len = (int) data_len; - int i; - - switch(order) { - case 0: - FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0])); - memcpy(residual, data, sizeof(residual[0])*data_len); - break; - case 1: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - data[i-1]; - break; - case 2: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - (data[i-1] << 1) + data[i-2]; - break; - case 3: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3]; - break; - case 4: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4]; - break; - default: - FLAC__ASSERT(0); - } -} - -static void FLAC__fixed_compute_residual_mult(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]) -{ - const int idata_len = (int)data_len; - int i; - - switch(order) { - case 0: - FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0])); - memcpy(residual, data, sizeof(residual[0])*data_len); - break; - case 1: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - data[i-1]; - break; - case 2: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - 2*data[i-1] + data[i-2]; - break; - case 3: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3]; - break; - case 4: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4]; - break; - default: - FLAC__ASSERT(0); - } -} - -static FLAC__int32 data [200000] ; -static FLAC__int32 residual [200000] ; - -static unsigned bench_order = 0 ; - -static void -bench_shift (void) -{ FLAC__fixed_compute_residual_shift (data, ARRAY_LEN (data), bench_order, residual) ; -} - -static void -bench_mult (void) -{ FLAC__fixed_compute_residual_mult (data, ARRAY_LEN (data), bench_order, residual) ; -} - -int -main (void) -{ bench_stats stats ; - - puts ("") ; - - for (bench_order = 2 ; bench_order <= 4 ; bench_order ++) { - memset (&stats, 0, sizeof (stats)) ; - stats.testfunc = bench_shift ; - stats.run_count = 100 ; - stats.loop_count = 10 ; - - benchmark_stats (&stats) ; - printf ("shift order %u : %f %f %f %f\n", bench_order, stats.min_time, stats.median_time, stats.mean_time, stats.max_time) ; - - memset (&stats, 0, sizeof (stats)) ; - stats.testfunc = bench_mult ; - stats.run_count = 100 ; - stats.loop_count = 10 ; - - benchmark_stats (&stats) ; - printf ("mult order %u : %f %f %f %f\n\n", bench_order, stats.min_time, stats.median_time, stats.mean_time, stats.max_time) ; - } - - return 0 ; -} diff --git a/flac/microbench/util.c b/flac/microbench/util.c deleted file mode 100644 index 2ecd4a3..0000000 --- a/flac/microbench/util.c +++ /dev/null @@ -1,205 +0,0 @@ -/* FLAC - Free Lossless Audio Codec - * Copyright (C) 2015-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include "util.h" - -#if defined _WIN32 - -#include - -static double -counter_diff (const LARGE_INTEGER * start, const LARGE_INTEGER * end) -{ - LARGE_INTEGER diff, freq; - - QueryPerformanceFrequency(&freq); - diff.QuadPart = end->QuadPart - start->QuadPart; - - return (double)diff.QuadPart/(double)freq.QuadPart; -} - -double -benchmark_function (void (*testfunc) (void), unsigned count) -{ - LARGE_INTEGER start, end; - unsigned k; - - QueryPerformanceCounter (&start) ; - - for (k = 0 ; k < count ; k++) - testfunc(); - - QueryPerformanceCounter (&end) ; - - return counter_diff (&start, &end) / count ; -} /* benchmark_function */ - -#elif defined FLAC__SYS_DARWIN - -#include - -static double -counter_diff (const uint64_t * start, const uint64_t * end) -{ - mach_timebase_info_data_t t_info; - mach_timebase_info(&t_info); - uint64_t duration = *end - *start; - - return duration * ((double)t_info.numer/(double)t_info.denom); -} - -double -benchmark_function (void (*testfunc) (void), unsigned count) -{ - uint64_t start, end; - unsigned k; - - start = mach_absolute_time(); - - for (k = 0 ; k < count ; k++) - testfunc(); - - end = mach_absolute_time(); - - return counter_diff (&start, &end) / count ; -} /* benchmark_function */ - -#elif defined HAVE_CLOCK_GETTIME - -#include -#include - -static double -timespec_diff (const struct timespec * start, const struct timespec * end) -{ struct timespec diff; - - if (end->tv_nsec - start->tv_nsec < 0) - { diff.tv_sec = end->tv_sec - start->tv_sec - 1 ; - diff.tv_nsec = 1000000000 + end->tv_nsec - start->tv_nsec ; - } - else - { diff.tv_sec = end->tv_sec - start->tv_sec ; - diff.tv_nsec = end->tv_nsec-start->tv_nsec ; - } ; - - return diff.tv_sec + 1e-9 * diff.tv_nsec ; -} - -double -benchmark_function (void (*testfunc) (void), unsigned count) -{ struct timespec start, end; - unsigned k ; - - clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &start) ; - - for (k = 0 ; k < count ; k++) - testfunc () ; - - clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &end) ; - - return timespec_diff (&start, &end) / count ; -} /* benchmark_function */ - -#else - -#include -#include - -static double -timeval_diff (const struct timeval * start, const struct timeval * end) -{ struct timeval diff; - - if (end->tv_usec - start->tv_usec < 0) - { diff.tv_sec = end->tv_sec - start->tv_sec - 1 ; - diff.tv_usec = 1000000 + end->tv_usec - start->tv_usec ; - } - else - { diff.tv_sec = end->tv_sec - start->tv_sec ; - diff.tv_usec = end->tv_usec-start->tv_usec ; - } ; - - return diff.tv_sec + 1e-6 * diff.tv_usec ; -} - -double -benchmark_function (void (*testfunc) (void), unsigned count) -{ struct timeval start, end; - unsigned k ; - - gettimeofday(&start, NULL); - - for (k = 0 ; k < count ; k++) - testfunc () ; - - gettimeofday(&end, NULL); - - return timeval_diff (&start, &end) / count ; -} /* benchmark_function */ - -#endif - -static int -double_cmp (const void * a, const void * b) -{ const double * pa = (double *) a ; - const double * pb = (double *) b ; - return pa [0] < pb [0] ; -} /* double_cmp */ - -void -benchmark_stats (bench_stats * stats) -{ double sum, times [stats->run_count] ; - unsigned k ; - - for (k = 0 ; k < stats->run_count ; k++) - times [k] = benchmark_function (stats->testfunc, stats->loop_count) ; - - qsort (times, stats->run_count, sizeof (times [0]), double_cmp) ; - - sum = 0.0 ; - stats->min_time = stats->max_time = times [0] ; - for (k = 0 ; k < stats->run_count ; k++) - { stats->min_time = stats->min_time < times [k] ? stats->min_time : times [k] ; - stats->max_time = stats->max_time > times [k] ? stats->max_time : times [k] ; - sum += times [k] ; - } - stats->mean_time = sum / stats->run_count ; - if (stats->run_count & 1) - stats->median_time = times [(stats->run_count + 1) / 2] ; - else - stats->median_time = 0.5 * (times [stats->run_count / 2] + times [(stats->run_count / 2) + 1]) ; - - return ; -} /* benchmark_stats */ diff --git a/flac/microbench/util.h b/flac/microbench/util.h deleted file mode 100644 index 1fba446..0000000 --- a/flac/microbench/util.h +++ /dev/null @@ -1,43 +0,0 @@ -/* FLAC - Free Lossless Audio Codec - * Copyright (C) 2015-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#define ARRAY_LEN(x) ((sizeof (x) / sizeof (x [0]))) - -typedef struct bench_stats -{ void (*testfunc) (void) ; - unsigned run_count ; - unsigned loop_count ; - double min_time, mean_time, median_time, max_time ; -} bench_stats ; - -double benchmark_function (void (*testfunc) (void), unsigned count) ; - -void benchmark_stats (bench_stats * stats) ; diff --git a/flac/oss-fuzz/Makefile.am b/flac/oss-fuzz/Makefile.am deleted file mode 100644 index bf669aa..0000000 --- a/flac/oss-fuzz/Makefile.am +++ /dev/null @@ -1,104 +0,0 @@ -# FLAC - Free Lossless Audio Codec -# Copyright (C) 2019-2023 Xiph.Org Foundation -# -# This file is part the FLAC project. FLAC is comprised of several -# components distributed under different licenses. The codec libraries -# are distributed under Xiph.Org's BSD-like license (see the file -# COPYING.Xiph in this distribution). All other programs, libraries, and -# plugins are distributed under the GPL (see COPYING.GPL). The documentation -# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the -# FLAC distribution contains at the top the terms under which it may be -# distributed. -# -# Since this particular file is relevant to all components of FLAC, -# it may be distributed under the Xiph.Org license, which is the least -# restrictive of those mentioned above. See the file COPYING.Xiph in this -# distribution. - -AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/oss-fuzz - -AM_CFLAGS = ${LIB_FUZZING_ENGINE} -AM_CXXFLAGS = -std=c++11 $(LIB_FUZZING_ENGINE) -LDADD = $(flac_libs) - - -EXTRA_DIST = \ - fuzzer_encoder.dict \ - common.h \ - Readme.md \ - fuzzing/datasource/datasource.hpp \ - fuzzing/datasource/id.hpp \ - fuzzing/exception.hpp \ - fuzzing/memory.hpp \ - fuzzing/types.hpp - -noinst_PROGRAMS = - -if USE_OSSFUZZERS -noinst_PROGRAMS += fuzzer_encoder fuzzer_encoder_v2 fuzzer_decoder fuzzer_seek fuzzer_metadata fuzzer_reencoder fuzzer_tool_flac fuzzer_tool_metaflac -endif - -fuzzer_encoder_SOURCES = encoder.cc -fuzzer_encoder_v2_SOURCES = encoder_v2.cc -fuzzer_decoder_SOURCES = decoder.cc -fuzzer_seek_SOURCES = seek.cc -fuzzer_metadata_SOURCES = metadata.cc -fuzzer_reencoder_SOURCES = reencoder.cc -fuzzer_tool_flac_SOURCES = ${flac_SOURCES} empty.cc tool_flac.c # empty.cc is to force use of C++ linker, which is mandated by oss-fuzz -fuzzer_tool_flac_LDADD = \ - $(top_builddir)/src/share/utf8/libutf8.la \ - $(top_builddir)/src/share/grabbag/libgrabbag.la \ - $(top_builddir)/src/share/getopt/libgetopt.la \ - $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/share/replaygain_synthesis/libreplaygain_synthesis.la \ - $(top_builddir)/src/libFLAC/libFLAC.la \ - @LTLIBICONV@ \ - -lm -fuzzer_tool_metaflac_SOURCES = ${metaflac_SOURCES} empty.cc tool_metaflac.c # empty.cc is to force use of C++ linker, which is mandated by oss-fuzz -fuzzer_tool_metaflac_LDADD = \ - $(top_builddir)/src/share/utf8/libutf8.la \ - $(top_builddir)/src/share/grabbag/libgrabbag.la \ - $(top_builddir)/src/share/getopt/libgetopt.la \ - $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/share/replaygain_synthesis/libreplaygain_synthesis.la \ - $(top_builddir)/src/libFLAC/libFLAC.la \ - @LTLIBICONV@ \ - -lm - -flac_libs = \ - $(top_builddir)/src/libFLAC/libFLAC-static.la \ - $(top_builddir)/src/libFLAC++/libFLAC++-static.la \ - @OGG_LIBS@ \ - -lm - -flac_SOURCES = \ - ${top_builddir}/src/flac/analyze.c \ - ${top_builddir}/src/flac/decode.c \ - ${top_builddir}/src/flac/encode.c \ - ${top_builddir}/src/flac/foreign_metadata.c \ - ${top_builddir}/src/flac/local_string_utils.c \ - ${top_builddir}/src/flac/utils.c \ - ${top_builddir}/src/flac/vorbiscomment.c \ - ${top_builddir}/src/flac/analyze.h \ - ${top_builddir}/src/flac/decode.h \ - ${top_builddir}/src/flac/encode.h \ - ${top_builddir}/src/flac/foreign_metadata.h \ - ${top_builddir}/src/flac/local_string_utils.h \ - ${top_builddir}/src/flac/utils.h \ - ${top_builddir}/src/flac/vorbiscomment.h - -metaflac_SOURCES = \ - ${top_builddir}/src/metaflac/operations.c \ - ${top_builddir}/src/metaflac/operations_shorthand_cuesheet.c \ - ${top_builddir}/src/metaflac/operations_shorthand_picture.c \ - ${top_builddir}/src/metaflac/operations_shorthand_seektable.c \ - ${top_builddir}/src/metaflac/operations_shorthand_streaminfo.c \ - ${top_builddir}/src/metaflac/operations_shorthand_vorbiscomment.c \ - ${top_builddir}/src/metaflac/options.c \ - ${top_builddir}/src/metaflac/usage.c \ - ${top_builddir}/src/metaflac/utils.c \ - ${top_builddir}/src/metaflac/operations.h \ - ${top_builddir}/src/metaflac/operations_shorthand.h \ - ${top_builddir}/src/metaflac/options.h \ - ${top_builddir}/src/metaflac/usage.h \ - ${top_builddir}/src/metaflac/utils.h diff --git a/flac/oss-fuzz/Readme.md b/flac/oss-fuzz/Readme.md deleted file mode 100644 index 90f2763..0000000 --- a/flac/oss-fuzz/Readme.md +++ /dev/null @@ -1,13 +0,0 @@ -Fuzzers fuzzer_decoder.cc and fuzzer_encoder.cc were taken from - - https://github.com/guidovranken/flac-fuzzers - -The header files in the directory fuzzing and below were taken from: - - https://github.com/guidovranken/fuzzing-headers.git - -Some minor modifications were made to make them build with the default C++ -warning flags. - -The code mentioned above, contributed by Guido Vranken, is licensed under -the MIT license. See the files themselves for details diff --git a/flac/oss-fuzz/common.h b/flac/oss-fuzz/common.h deleted file mode 100644 index 9545f95..0000000 --- a/flac/oss-fuzz/common.h +++ /dev/null @@ -1,2 +0,0 @@ -extern int alloc_check_threshold, alloc_check_counter; -int alloc_check_threshold = INT32_MAX, alloc_check_counter = 0; diff --git a/flac/oss-fuzz/decoder.cc b/flac/oss-fuzz/decoder.cc deleted file mode 100644 index b7ddf21..0000000 --- a/flac/oss-fuzz/decoder.cc +++ /dev/null @@ -1,408 +0,0 @@ -/* Copyright 2019 Guido Vranken - * - * 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 -#include - -#include -#include - -#include "FLAC++/decoder.h" -#include "FLAC++/metadata.h" -#include "common.h" - -template <> FLAC__MetadataType fuzzing::datasource::Base::Get(const uint64_t id) { - (void)id; - switch ( Get() ) { - case 0: - return FLAC__METADATA_TYPE_STREAMINFO; - case 1: - return FLAC__METADATA_TYPE_PADDING; - case 2: - return FLAC__METADATA_TYPE_APPLICATION; - case 3: - return FLAC__METADATA_TYPE_SEEKTABLE; - case 4: - return FLAC__METADATA_TYPE_VORBIS_COMMENT; - case 5: - return FLAC__METADATA_TYPE_CUESHEET; - case 6: - return FLAC__METADATA_TYPE_PICTURE; - case 7: - return FLAC__METADATA_TYPE_UNDEFINED; - case 8: - return FLAC__MAX_METADATA_TYPE; - default: - return FLAC__METADATA_TYPE_STREAMINFO; - } -} - -namespace FLAC { - namespace Decoder { - class FuzzerStream : public Stream { - private: - fuzzing::datasource::Datasource& ds; - public: - FuzzerStream(fuzzing::datasource::Datasource& dsrc) : - Stream(), ds(dsrc) { } - - ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) override { - try { - const size_t maxCopySize = *bytes; - - if ( maxCopySize > 0 ) { - /* memset just to test if this overwrites anything, and triggers ASAN */ - memset(buffer, 0, maxCopySize); - } - - const auto data = ds.GetData(0); - const auto dataSize = data.size(); - const auto copySize = std::min(maxCopySize, dataSize); - - if ( copySize > 0 ) { - memcpy(buffer, data.data(), copySize); - } - - *bytes = copySize; - - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } catch ( ... ) { - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - } - } - - ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) override { - { - fuzzing::memory::memory_test(&(frame->header), sizeof(frame->header)); - fuzzing::memory::memory_test(&(frame->footer), sizeof(frame->footer)); - } - - { - const auto numChannels = get_channels(); - const size_t bytesPerChannel = frame->header.blocksize * sizeof(FLAC__int32); - for (size_t i = 0; i < numChannels; i++) { - fuzzing::memory::memory_test(buffer[i], bytesPerChannel); - } - } - - try { - if ( ds.Get() == true ) { - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } catch ( ... ) { } - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; - } - - void error_callback(::FLAC__StreamDecoderErrorStatus status) override { - fuzzing::memory::memory_test(status); - } - - void metadata_callback(const ::FLAC__StreamMetadata *metadata) override { - Metadata::Prototype * cloned_object = nullptr; - fuzzing::memory::memory_test(metadata->type); - fuzzing::memory::memory_test(metadata->is_last); - fuzzing::memory::memory_test(metadata->length); - fuzzing::memory::memory_test(metadata->data); - if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) - cloned_object = new Metadata::StreamInfo(metadata); - else if (metadata->type == FLAC__METADATA_TYPE_PADDING) - cloned_object = new Metadata::Padding(metadata); - else if (metadata->type == FLAC__METADATA_TYPE_APPLICATION) - cloned_object = new Metadata::Application(metadata); - else if (metadata->type == FLAC__METADATA_TYPE_SEEKTABLE) - cloned_object = new Metadata::SeekTable(metadata); - else if (metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) - cloned_object = new Metadata::VorbisComment(metadata); - else if (metadata->type == FLAC__METADATA_TYPE_CUESHEET) - cloned_object = new Metadata::CueSheet(metadata); - else if (metadata->type == FLAC__METADATA_TYPE_PICTURE) - cloned_object = new Metadata::Picture(metadata); - else - return; - if (0 != cloned_object && *cloned_object == *metadata && cloned_object->is_valid()) { - if (cloned_object->get_type() == FLAC__METADATA_TYPE_SEEKTABLE) - dynamic_cast(cloned_object)->is_legal(); - if (cloned_object->get_type() == FLAC__METADATA_TYPE_PICTURE) - dynamic_cast(cloned_object)->is_legal(NULL); - if (cloned_object->get_type() == FLAC__METADATA_TYPE_CUESHEET) - dynamic_cast(cloned_object)->is_legal(true,NULL); - } - delete cloned_object; - } - - ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) override { - fuzzing::memory::memory_test(absolute_byte_offset); - - try { - if ( ds.Get() == true ) { - return FLAC__STREAM_DECODER_SEEK_STATUS_OK; - } else { - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - } - } catch ( ... ) { - return FLAC__STREAM_DECODER_SEEK_STATUS_OK; - } - } -#if 0 - ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) override { - fuzzing::memory::memory_test(*absolute_byte_offset); - - try { - if ( ds.Get() == true ) { - return FLAC__STREAM_DECODER_TELL_STATUS_OK; - } else { - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - } - } catch ( ... ) { - return FLAC__STREAM_DECODER_TELL_STATUS_OK; - } - } - - ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) override { - fuzzing::memory::memory_test(*stream_length); - - try { - if ( ds.Get() == true ) { - return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; - } else { - return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - } - } catch ( ... ) { - return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; - } - } -#endif - }; - } -} - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - fuzzing::datasource::Datasource ds(data, size); - FLAC::Decoder::FuzzerStream decoder(ds); - bool use_ogg = true; - - try { - if ( ds.Get() ) { - use_ogg = false; - } - if ( ds.Get() ) { -#ifdef FUZZER_DEBUG - printf("set_ogg_serial_number\n"); -#endif - decoder.set_ogg_serial_number(ds.Get()); - } - if ( ds.Get() ) { -#ifdef FUZZER_DEBUG - printf("set_md5_checking\n"); -#endif - decoder.set_md5_checking(ds.Get()); - } - if ( ds.Get() ) { -#ifdef FUZZER_DEBUG - printf("set_metadata_respond\n"); -#endif - decoder.set_metadata_respond(ds.Get<::FLAC__MetadataType>()); - } - if ( ds.Get() ) { - const auto idVector = ds.GetData(0); - unsigned char id[4]; - if ( idVector.size() >= sizeof(id) ) { - memcpy(id, idVector.data(), sizeof(id)); -#ifdef FUZZER_DEBUG - printf("set_metadata_respond_application\n"); -#endif - decoder.set_metadata_respond_application(id); - } - } - if ( ds.Get() ) { -#ifdef FUZZER_DEBUG - printf("set_metadata_respond_all\n"); -#endif - decoder.set_metadata_respond_all(); - } - if ( ds.Get() ) { -#ifdef FUZZER_DEBUG - printf("set_metadata_ignore\n"); -#endif - decoder.set_metadata_ignore(ds.Get<::FLAC__MetadataType>()); - } - if ( ds.Get() ) { - const auto idVector = ds.GetData(0); - unsigned char id[4]; - if ( idVector.size() >= sizeof(id) ) { - memcpy(id, idVector.data(), sizeof(id)); -#ifdef FUZZER_DEBUG - printf("set_metadata_ignore_application\n"); -#endif - decoder.set_metadata_ignore_application(id); - } - } - if ( ds.Get() ) { -#ifdef FUZZER_DEBUG - printf("set_metadata_ignore_all\n"); -#endif - decoder.set_metadata_ignore_all(); - } - { - ::FLAC__StreamDecoderInitStatus ret; - if ( !use_ogg ) { - ret = decoder.init(); - } else { - ret = decoder.init_ogg(); - } - - if ( ret != FLAC__STREAM_DECODER_INIT_STATUS_OK ) { - goto end; - } - } - - while ( ds.Get() ) { - switch ( ds.Get() ) { - case 0: - { -#ifdef FUZZER_DEBUG - printf("flush\n"); -#endif - const bool res = decoder.flush(); - fuzzing::memory::memory_test(res); - } - break; - case 1: - { -#ifdef FUZZER_DEBUG - printf("reset\n"); -#endif - const bool res = decoder.reset(); - fuzzing::memory::memory_test(res); - } - break; - case 2: - { -#ifdef FUZZER_DEBUG - printf("process_single\n"); -#endif - const bool res = decoder.process_single(); - fuzzing::memory::memory_test(res); - } - break; - case 3: - { -#ifdef FUZZER_DEBUG - printf("process_until_end_of_metadata\n"); -#endif - const bool res = decoder.process_until_end_of_metadata(); - fuzzing::memory::memory_test(res); - } - break; - case 4: - { -#ifdef FUZZER_DEBUG - printf("process_until_end_of_stream\n"); -#endif - const bool res = decoder.process_until_end_of_stream(); - fuzzing::memory::memory_test(res); - } - break; - case 5: - { -#ifdef FUZZER_DEBUG - printf("skip_single_frame\n"); -#endif - const bool res = decoder.skip_single_frame(); - fuzzing::memory::memory_test(res); - } - break; - case 6: - { -#ifdef FUZZER_DEBUG - printf("seek_absolute\n"); -#endif - const bool res = decoder.seek_absolute(ds.Get()); - fuzzing::memory::memory_test(res); - } - break; - case 7: - { -#ifdef FUZZER_DEBUG - printf("get_md5_checking\n"); -#endif - const bool res = decoder.get_md5_checking(); - fuzzing::memory::memory_test(res); - } - break; - case 8: - { -#ifdef FUZZER_DEBUG - printf("get_total_samples\n"); -#endif - const bool res = decoder.get_total_samples(); - fuzzing::memory::memory_test(res); - } - break; - case 9: - { -#ifdef FUZZER_DEBUG - printf("get_channels\n"); -#endif - const bool res = decoder.get_channels(); - fuzzing::memory::memory_test(res); - } - break; - case 10: - { -#ifdef FUZZER_DEBUG - printf("get_bits_per_sample\n"); -#endif - const bool res = decoder.get_bits_per_sample(); - fuzzing::memory::memory_test(res); - } - break; - case 11: - { -#ifdef FUZZER_DEBUG - printf("get_sample_rate\n"); -#endif - const bool res = decoder.get_sample_rate(); - fuzzing::memory::memory_test(res); - } - break; - case 12: - { -#ifdef FUZZER_DEBUG - printf("get_blocksize\n"); -#endif - const bool res = decoder.get_blocksize(); - fuzzing::memory::memory_test(res); - } - break; - } - } - } catch ( ... ) { } - -end: - { - const bool res = decoder.finish(); - fuzzing::memory::memory_test(res); - } - return 0; -} diff --git a/flac/oss-fuzz/empty.cc b/flac/oss-fuzz/empty.cc deleted file mode 100644 index e69de29..0000000 diff --git a/flac/oss-fuzz/encoder.cc b/flac/oss-fuzz/encoder.cc deleted file mode 100644 index 23cb397..0000000 --- a/flac/oss-fuzz/encoder.cc +++ /dev/null @@ -1,257 +0,0 @@ -/* Copyright 2019 Guido Vranken - * - * 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 -#include -#include - -#include -#include - -#include "FLAC++/encoder.h" -#include "common.h" - -namespace FLAC { - namespace Encoder { - class FuzzerStream : public Stream { - private: - // fuzzing::datasource::Datasource& ds; - public: - FuzzerStream(fuzzing::datasource::Datasource&) : - Stream() { } - - ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t /* samples */, uint32_t /* current_frame */) override { - fuzzing::memory::memory_test(buffer, bytes); -#if 0 - try { - if ( ds.Get() == true ) { - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - } catch ( ... ) { } -#endif - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; - } - }; - } -} - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - fuzzing::datasource::Datasource ds(data, size); - FLAC::Encoder::FuzzerStream encoder(ds); - - try { - const int channels = ds.Get(); - const int bps = ds.Get(); - encoder.set_channels(channels); - encoder.set_bits_per_sample(bps); - - { - const bool res = encoder.set_streamable_subset(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_ogg_serial_number(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_verify(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_compression_level(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_do_exhaustive_model_search(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_do_mid_side_stereo(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_loose_mid_side_stereo(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const auto s = ds.Get(); - const bool res = encoder.set_apodization(s.data()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_max_lpc_order(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_qlp_coeff_precision(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_do_qlp_coeff_prec_search(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_do_escape_coding(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_min_residual_partition_order(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_max_residual_partition_order(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_rice_parameter_search_dist(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_total_samples_estimate(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_blocksize(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_limit_min_bitrate(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_sample_rate(ds.Get()); - fuzzing::memory::memory_test(res); - } - - if ( size > 2 * 65535 * 4 ) { - /* With large inputs and expensive options enabled, the fuzzer can get *really* slow. - * Some combinations can make the fuzzer timeout (>60 seconds). However, while combining - * options makes the fuzzer slower, most options do not expose new code when combined. - * Therefore, combining slow options is disabled for large inputs. Any input containing - * more than 65536 * 2 samples of 32 bits each (max blocksize, stereo) is considered large - */ - encoder.set_do_qlp_coeff_prec_search(false); - encoder.set_do_exhaustive_model_search(false); - } - if ( size > 2 * 4096 * 4 + 250 ) { - /* With subdivide_tukey in the mix testing apodizations can get really expensive. Therefore - * this is disabled for inputs of more than one whole stereo block of 32-bit inputs plus a - * bit of overhead */ - encoder.set_apodization(""); - } - - { - ::FLAC__StreamEncoderInitStatus ret; - if ( ds.Get() ) { - ret = encoder.init(); - } else { - ret = encoder.init_ogg(); - } - - if ( ret != FLAC__STREAM_ENCODER_INIT_STATUS_OK ) { - goto end; - } - } - - /* These sets must fail, because encoder is already initialized */ - { - bool res = false; - res = res || encoder.set_streamable_subset(true); - res = res || encoder.set_ogg_serial_number(0); - res = res || encoder.set_verify(true); - res = res || encoder.set_compression_level(0); - res = res || encoder.set_do_exhaustive_model_search(true); - res = res || encoder.set_do_mid_side_stereo(true); - res = res || encoder.set_loose_mid_side_stereo(true); - res = res || encoder.set_apodization("test"); - res = res || encoder.set_max_lpc_order(0); - res = res || encoder.set_qlp_coeff_precision(0); - res = res || encoder.set_do_qlp_coeff_prec_search(true); - res = res || encoder.set_do_escape_coding(true); - res = res || encoder.set_min_residual_partition_order(0); - res = res || encoder.set_max_residual_partition_order(0); - res = res || encoder.set_rice_parameter_search_dist(0); - res = res || encoder.set_total_samples_estimate(0); - res = res || encoder.set_channels(channels); - res = res || encoder.set_bits_per_sample(16); - res = res || encoder.set_limit_min_bitrate(true); - res = res || encoder.set_blocksize(3021); - res = res || encoder.set_sample_rate(44100); - fuzzing::memory::memory_test(res); - if(res) - abort(); - } - - - { - /* XORing values as otherwise compiler will optimize, apparently */ - bool res = false; - res = res != encoder.get_streamable_subset(); - res = res != encoder.get_verify(); - res = res != encoder.get_do_exhaustive_model_search(); - res = res != encoder.get_do_mid_side_stereo(); - res = res != encoder.get_loose_mid_side_stereo(); - res = res != encoder.get_max_lpc_order(); - res = res != encoder.get_qlp_coeff_precision(); - res = res != encoder.get_do_qlp_coeff_prec_search(); - res = res != encoder.get_do_escape_coding(); - res = res != encoder.get_min_residual_partition_order(); - res = res != encoder.get_max_residual_partition_order(); - res = res != encoder.get_rice_parameter_search_dist(); - res = res != encoder.get_total_samples_estimate(); - res = res != encoder.get_channels(); - res = res != encoder.get_bits_per_sample(); - res = res != encoder.get_limit_min_bitrate(); - res = res != encoder.get_blocksize(); - res = res != encoder.get_sample_rate(); - fuzzing::memory::memory_test(res); - } - - - while ( ds.Get() ) { - { - auto dat = ds.GetVector(); - - if( ds.Get() ) - /* Mask */ - for (size_t i = 0; i < dat.size(); i++) - /* If we get here, bps is 4 or larger, or init will have failed */ - dat[i] = (int32_t)(((uint32_t)(dat[i]) << (32-bps)) >> (32-bps)); - - const uint32_t samples = dat.size() / channels; - if ( samples > 0 ) { - const int32_t* ptr = dat.data(); - const bool res = encoder.process_interleaved(ptr, samples); - fuzzing::memory::memory_test(res); - } - } - } - } catch ( ... ) { } - -end: - { - const bool res = encoder.finish(); - fuzzing::memory::memory_test(res); - } - return 0; -} diff --git a/flac/oss-fuzz/encoder_v2.cc b/flac/oss-fuzz/encoder_v2.cc deleted file mode 100644 index 6448346..0000000 --- a/flac/oss-fuzz/encoder_v2.cc +++ /dev/null @@ -1,352 +0,0 @@ -/* fuzzer_encoder_v2 - * Copyright (C) 2022-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#include -#include /* for memcpy */ -#include "FLAC/stream_encoder.h" -#include "FLAC/metadata.h" -extern "C" { -#include "share/private.h" -} -#include "common.h" - -/* This C++ fuzzer uses the FLAC and not FLAC++ because the latter lacks a few - * hidden functions like FLAC__stream_encoder_disable_constant_subframes. It - * is still processed by a C++ compiler because that's what oss-fuzz expects */ - - -static FLAC__StreamEncoderWriteStatus write_callback(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data) -{ - (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data; - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; -} - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - FLAC__bool encoder_valid = true; - FLAC__StreamEncoder *encoder = 0; - FLAC__StreamEncoderState state; - FLAC__StreamMetadata *metadata[16] = {NULL}; - unsigned num_metadata = 0; - FLAC__StreamMetadata_VorbisComment_Entry VorbisCommentField; - - unsigned sample_rate, channels, bps; - uint64_t samples_estimate, samples_in_input; - unsigned compression_level, input_data_width, blocksize, max_lpc_order, qlp_coeff_precision, min_residual_partition_order, max_residual_partition_order, metadata_mask, instruction_set_disable_mask; - FLAC__bool ogg, write_to_file, interleaved; - - FLAC__bool data_bools[24]; - - /* Set alloc threshold. This check was added later and no spare config - * bytes were left, so we're reusing the sample rate as that of little - * consequence to the encoder and decoder except reading the frame header */ - - if(size < 3) - return 0; - alloc_check_threshold = data[2]; - alloc_check_counter = 0; - - /* allocate the encoder */ - if((encoder = FLAC__stream_encoder_new()) == NULL) { - fprintf(stderr, "ERROR: allocating encoder\n"); - return 1; - } - - /* Use first 20 byte for configuration */ - if(size < 20){ - FLAC__stream_encoder_delete(encoder); - return 0; - } - - /* First 3 byte for sample rate, 4th byte for channels, 5th byte for bps */ - sample_rate = ((unsigned)data[0] << 16) + ((unsigned)data[1] << 8) + data[2]; - channels = data[3]; - bps = data[4]; - - /* Number of samples estimate, format accepts 36-bit max */ - samples_estimate = ((uint64_t)data[5] << 32) + ((unsigned)data[6] << 24) + ((unsigned)data[7] << 16) + ((unsigned)data[8] << 8) + data[9]; - - compression_level = data[10]&0b1111; - input_data_width = 1 + (data[10]>>4)%4; - samples_in_input = (size-20)/input_data_width; - blocksize = ((unsigned)data[11] << 8) + (unsigned)data[12]; - max_lpc_order = data[13]; - qlp_coeff_precision = data[14]; - min_residual_partition_order = data[15] & 0b1111; - max_residual_partition_order = data[15] & 0b11110000; - metadata_mask = data[16]; - instruction_set_disable_mask = data[17]; - - /* Get array of bools from configuration */ - for(int i = 0; i < 16; i++) - data_bools[i] = data[18+i/8] & (1 << (i % 8)); - - ogg = data_bools[0]; - interleaved = data_bools[1]; - write_to_file = data_bools[13]; - - /* Set input and process parameters */ - encoder_valid &= FLAC__stream_encoder_set_verify(encoder, data_bools[2]); - encoder_valid &= FLAC__stream_encoder_set_channels(encoder, channels); - encoder_valid &= FLAC__stream_encoder_set_bits_per_sample(encoder, bps); - encoder_valid &= FLAC__stream_encoder_set_sample_rate(encoder, sample_rate); - encoder_valid &= FLAC__stream_encoder_set_total_samples_estimate(encoder, samples_estimate); - encoder_valid &= FLAC__stream_encoder_disable_instruction_set(encoder, instruction_set_disable_mask); - encoder_valid &= FLAC__stream_encoder_set_limit_min_bitrate(encoder, data_bools[15]); - - /* Set compression related parameters */ - encoder_valid &= FLAC__stream_encoder_set_compression_level(encoder, compression_level); - if(data_bools[3]){ - /* Bias towards regular compression levels */ - encoder_valid &= FLAC__stream_encoder_set_blocksize(encoder, blocksize); - encoder_valid &= FLAC__stream_encoder_set_max_lpc_order(encoder, max_lpc_order); - encoder_valid &= FLAC__stream_encoder_set_qlp_coeff_precision(encoder, qlp_coeff_precision); - encoder_valid &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, min_residual_partition_order); - - /* With large inputs and expensive options enabled, the fuzzer can get *really* slow. - * Some combinations can make the fuzzer timeout (>60 seconds). However, while combining - * options makes the fuzzer slower, most options do not expose new code when combined. - * Therefore, combining slow options is disabled for large inputs. Any input containing - * more than 65536 * 2 samples (max blocksize, stereo) is considered large - */ - if(samples_in_input < (2*65536)) { - encoder_valid &= FLAC__stream_encoder_set_streamable_subset(encoder, data_bools[4]); - encoder_valid &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, data_bools[5]); - encoder_valid &= FLAC__stream_encoder_set_do_escape_coding(encoder, data_bools[6]); - encoder_valid &= FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, data_bools[7]); - /* Combining model search, precision search and a high residual partition order is especially - * expensive, so limit that even further. This high partition order can only be set on - * large blocksize and with streamable subset disabled */ - if(samples_in_input < (2 * 4609) || data_bools[4] || !data_bools[7] || !data_bools[5] || max_residual_partition_order < 9 || blocksize < 4609) - encoder_valid &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, max_residual_partition_order); - } - else { - if(!data_bools[4]) - encoder_valid &= FLAC__stream_encoder_set_streamable_subset(encoder, false); - else if(data_bools[6]) - encoder_valid &= FLAC__stream_encoder_set_do_escape_coding(encoder, true); - else if(data_bools[7]) - encoder_valid &= FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, true); - else if(data_bools[5]) - encoder_valid &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, true); - } - encoder_valid &= FLAC__stream_encoder_set_do_mid_side_stereo(encoder, data_bools[8]); - encoder_valid &= FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, data_bools[9]); - - encoder_valid &= FLAC__stream_encoder_disable_constant_subframes(encoder, data_bools[10]); - encoder_valid &= FLAC__stream_encoder_disable_fixed_subframes(encoder, data_bools[11]); - encoder_valid &= FLAC__stream_encoder_disable_verbatim_subframes(encoder, data_bools[12]); - } - - /* Disable alloc check if requested */ - if(encoder_valid && data_bools[14]) - alloc_check_threshold = INT32_MAX; - - /* add metadata */ - if(encoder_valid && (metadata_mask & 1)) { - if((metadata[num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO)) == NULL) - encoder_valid = false; - else - num_metadata++; - } - if(encoder_valid && (metadata_mask & 2) && size > 21){ - if((metadata[num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING)) == NULL) - encoder_valid = false; - else { - metadata[num_metadata++]->length = (((unsigned)data[20]) << 8) + (unsigned)(data[21]); - } - } - if(encoder_valid && (metadata_mask & 4) && size > 20){ - FLAC__byte * application_data = (FLAC__byte *)malloc(size-20); - if(0 != application_data && ((metadata[num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION)) == NULL)) - encoder_valid = false; - else { - memcpy(application_data,data+20,size-20); - FLAC__metadata_object_application_set_data(metadata[num_metadata++], application_data, size-20, 0); - } - } - if(encoder_valid && (metadata_mask & 8) && size > 25){ - if((metadata[num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE)) == NULL) - encoder_valid = false; - else { - unsigned seekpoint_spacing = ((unsigned)data[22] << 8) + data[23]; - unsigned total_samples_for_seekpoints = ((unsigned)data[24] << 8) + data[25]; - FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(metadata[num_metadata++], seekpoint_spacing, total_samples_for_seekpoints); - } - } - if(encoder_valid && (metadata_mask & 16)){ - if((metadata[num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT)) != NULL) { - bool vorbiscomment_valid = true; - /* Append a vorbis comment */ - if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&VorbisCommentField, "COMMENTARY", "Nothing to 🤔 report")) - vorbiscomment_valid = false; - else { - if(FLAC__metadata_object_vorbiscomment_append_comment(metadata[num_metadata], VorbisCommentField, false)) { - - /* Insert a vorbis comment at the first index */ - if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&VorbisCommentField, "COMMENTARY", "Still nothing to report 🤔🤣")) - vorbiscomment_valid = false; - else - if(!FLAC__metadata_object_vorbiscomment_insert_comment(metadata[num_metadata], 0, VorbisCommentField, false)) { - free(VorbisCommentField.entry); - vorbiscomment_valid = false; - } - } - else { - free(VorbisCommentField.entry); - vorbiscomment_valid = false; - } - } - if(!vorbiscomment_valid) { - FLAC__metadata_object_delete(metadata[num_metadata]); - metadata[num_metadata] = 0; - } - else - num_metadata++; - } - } - if(encoder_valid && (metadata_mask & 32)){ - if((metadata[num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET)) != NULL) { - if(!FLAC__metadata_object_cuesheet_insert_blank_track(metadata[num_metadata],0)) { - FLAC__metadata_object_delete(metadata[num_metadata]); - metadata[num_metadata] = 0; - } - else { - if(!FLAC__metadata_object_cuesheet_track_insert_blank_index(metadata[num_metadata],0,0)) { - FLAC__metadata_object_delete(metadata[num_metadata]); - metadata[num_metadata] = 0; - } - else { - metadata[num_metadata]->data.cue_sheet.tracks[0].number = 1; - num_metadata++; - } - } - } - } - if(encoder_valid && (metadata_mask & 64)){ - if((metadata[num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE)) != NULL) { - num_metadata++; - } - } - if(encoder_valid && (metadata_mask & 128)){ - if((metadata[num_metadata] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_UNDEFINED)) != NULL) { - metadata[num_metadata]->length = 24; - metadata[num_metadata]->data.unknown.data = (FLAC__byte *)calloc(24, 1); - num_metadata++; - } - } - - if(num_metadata && encoder_valid) - encoder_valid = FLAC__stream_encoder_set_metadata(encoder, metadata, num_metadata); - - /* initialize encoder */ - if(encoder_valid) { - FLAC__StreamEncoderInitStatus init_status; - if(ogg) - if(write_to_file) - init_status = FLAC__stream_encoder_init_ogg_file(encoder, "/tmp/tmp.flac", NULL, NULL); - else - init_status = FLAC__stream_encoder_init_ogg_stream(encoder, NULL, write_callback, NULL, NULL, NULL, NULL); - else - if(write_to_file) - init_status = FLAC__stream_encoder_init_file(encoder, "/tmp/tmp.flac", NULL, NULL); - else - init_status = FLAC__stream_encoder_init_stream(encoder, write_callback, NULL, NULL, NULL, NULL); - if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { - encoder_valid = false; - } - } - - - /* send samples to encoder */ - if(encoder_valid && size > (input_data_width*channels+26)) { - unsigned samples = (size - 26)/input_data_width/channels; - const uint8_t * pcm_data = data + 26; - int32_t * data_as_int32 = (int32_t *)malloc(4*samples*channels); - if(0 != data_as_int32){ - for(unsigned i = 0; i < samples*channels; i++) - if(input_data_width == 1) - data_as_int32[i] = (int32_t)pcm_data[i] - 0x80; - else if(input_data_width == 2) - data_as_int32[i] = (((int32_t)pcm_data[i*2] << 8) + pcm_data[i*2+1]) - 0x8000; - else if(input_data_width == 3) - data_as_int32[i] = (((int32_t)pcm_data[i*3] << 16) + ((int32_t)pcm_data[i*3+1] << 8) + pcm_data[i*3+2]) - 0x800000; - else if(input_data_width == 4) - data_as_int32[i] = (((int64_t)pcm_data[i*4] << 24) + ((int32_t)pcm_data[i*4+1] << 16) + ((int32_t)pcm_data[i*4+2] << 8) + pcm_data[i*4+3]) - 0x80000000; - - /* feed samples to encoder */ - if(interleaved) - encoder_valid = FLAC__stream_encoder_process_interleaved(encoder, data_as_int32, samples); - else { - encoder_valid = FLAC__stream_encoder_process(encoder, (const int32_t*[]){data_as_int32, - data_as_int32+samples, - data_as_int32+samples*2, - data_as_int32+samples*3, - data_as_int32+samples*4, data_as_int32+samples*5, data_as_int32+samples*6, data_as_int32+samples*7}, samples); - } - free(data_as_int32); - } - else { - encoder_valid = false; - } - } - - state = FLAC__stream_encoder_get_state(encoder); - if(!(state == FLAC__STREAM_ENCODER_OK || - state == FLAC__STREAM_ENCODER_UNINITIALIZED || - state == FLAC__STREAM_ENCODER_CLIENT_ERROR || - ((state == FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR || - state == FLAC__STREAM_ENCODER_FRAMING_ERROR || - (state == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR && - FLAC__stream_encoder_get_verify_decoder_state(encoder) == FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR)) && - alloc_check_threshold < INT32_MAX))) { - fprintf(stderr,"-----\nERROR: stream encoder returned %s\n-----\n",FLAC__stream_encoder_get_resolved_state_string(encoder)); - if(state == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) { - uint32_t frame_number, channel, sample_number; - FLAC__int32 expected, got; - FLAC__stream_encoder_get_verify_decoder_error_stats(encoder, NULL, &frame_number, &channel, &sample_number, &expected, &got); - fprintf(stderr,"Frame number %d\nChannel %d\n Sample number %d\nExpected value %d\nGot %d\n", frame_number, channel, sample_number, expected, got); - } - abort(); - } - - FLAC__stream_encoder_finish(encoder); - - /* now that encoding is finished, the metadata can be freed */ - for(unsigned i = 0; i < 16; i++) - if(0 != metadata[i]) - FLAC__metadata_object_delete(metadata[i]); - - FLAC__stream_encoder_delete(encoder); - - return 0; -} - diff --git a/flac/oss-fuzz/fuzzer_decoder.dict b/flac/oss-fuzz/fuzzer_decoder.dict deleted file mode 100644 index 0e79191..0000000 --- a/flac/oss-fuzz/fuzzer_decoder.dict +++ /dev/null @@ -1,6 +0,0 @@ -flac_stream_marker="fLaC" -ogg_stream_marker="OggS" -flac_in_ogg_marker="\x7fFLAC" - -synccode_fixed_blocksize="\xFF\xF8" -synccode_variable_blocksize="\xFF\xF9" diff --git a/flac/oss-fuzz/fuzzer_encoder.dict b/flac/oss-fuzz/fuzzer_encoder.dict deleted file mode 100644 index 9662137..0000000 --- a/flac/oss-fuzz/fuzzer_encoder.dict +++ /dev/null @@ -1,18 +0,0 @@ -"bartlett" -"bartlett_hann" -"blackman" -"blackman_harris_4term_92db" -"connes" -"flattop" -"gauss()" -"hamming" -"hann" -"kaiser_bessel" -"nuttall" -"rectangle" -"triangle" -"tukey(0)" -"partial_tukey(0)" -"punchout_tukey(0)" -"subdivide_tukey(0)" -"welch" diff --git a/flac/oss-fuzz/fuzzer_reencoder.dict b/flac/oss-fuzz/fuzzer_reencoder.dict deleted file mode 100644 index 0e79191..0000000 --- a/flac/oss-fuzz/fuzzer_reencoder.dict +++ /dev/null @@ -1,6 +0,0 @@ -flac_stream_marker="fLaC" -ogg_stream_marker="OggS" -flac_in_ogg_marker="\x7fFLAC" - -synccode_fixed_blocksize="\xFF\xF8" -synccode_variable_blocksize="\xFF\xF9" diff --git a/flac/oss-fuzz/fuzzer_tool_flac.dict b/flac/oss-fuzz/fuzzer_tool_flac.dict deleted file mode 100644 index 3ef9be5..0000000 --- a/flac/oss-fuzz/fuzzer_tool_flac.dict +++ /dev/null @@ -1,19 +0,0 @@ -"--keep-foreign-metadata-if-present" -"--replay-gain" -"--apply-replaygain-which-is-not-lossless" - -"--force-raw-format" -"--force-aiff-format" -"--force-rf64-format" -"--force-wave64-format" -"--force-aiff-c-sowt-format" -"--force-aiff-c-none-format" -"--force-legacy-wave-format" -"--force-extensible-wave-format" - -"--endian=big" -"--sample-rate=1" -"--channels=1" -"--bps=32" -"--sign=unsigned" - diff --git a/flac/oss-fuzz/fuzzing/datasource/datasource.hpp b/flac/oss-fuzz/fuzzing/datasource/datasource.hpp deleted file mode 100644 index 3c9484e..0000000 --- a/flac/oss-fuzz/fuzzing/datasource/datasource.hpp +++ /dev/null @@ -1,190 +0,0 @@ -/* Copyright 2019 Guido Vranken - * - * 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. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace fuzzing { -namespace datasource { - -class Base -{ - protected: - virtual std::vector get(const size_t min, const size_t max, const uint64_t id = 0) = 0; - public: - Base(void) = default; - virtual ~Base(void) = default; - - template T Get(const uint64_t id = 0); - uint16_t GetChoice(const uint64_t id = 0); - std::vector GetData(const uint64_t id, const size_t min = 0, const size_t max = 0); - template std::vector GetVector(const uint64_t id = 0); - - class OutOfData : public fuzzing::exception::FlowException { - public: - OutOfData() = default; - }; - - class DeserializationFailure : public fuzzing::exception::FlowException { - public: - DeserializationFailure() = default; - }; -}; - -#ifndef FUZZING_HEADERS_NO_IMPL -template T Base::Get(const uint64_t id) -{ - T ret; - const auto v = get(sizeof(ret), sizeof(ret), id); - memcpy(&ret, v.data(), sizeof(ret)); - return ret; -} - -template <> bool Base::Get(const uint64_t id) -{ - uint8_t ret; - const auto v = get(sizeof(ret), sizeof(ret), id); - memcpy(&ret, v.data(), sizeof(ret)); - return (ret % 2) ? true : false; -} - -template <> std::string Base::Get(const uint64_t id) -{ - auto data = GetData(id); - return std::string(data.data(), data.data() + data.size()); -} - -template <> std::vector Base::Get>(const uint64_t id) -{ - std::vector ret; - while ( true ) { - auto data = GetData(id); - ret.push_back( std::string(data.data(), data.data() + data.size()) ); - if ( Get(id) == false ) { - break; - } - } - return ret; -} - -uint16_t Base::GetChoice(const uint64_t id) -{ - return Get(id); -} - -std::vector Base::GetData(const uint64_t id, const size_t min, const size_t max) -{ - return get(min, max, id); -} - - -template <> types::String<> Base::Get>(const uint64_t id) { - const auto data = GetData(id); - types::String<> ret(data.data(), data.size()); - return ret; -} - -template <> types::Data<> Base::Get>(const uint64_t id) { - const auto data = GetData(id); - types::Data<> ret(data.data(), data.size()); - return ret; -} - -template -std::vector Base::GetVector(const uint64_t id) { - std::vector ret; - - while ( Get(id) == true ) { - ret.push_back( Get(id) ); - } - - return ret; -} -#endif - -class Datasource : public Base -{ - private: - const uint8_t* data; - const size_t size; - size_t idx; - size_t left; - std::vector get(const size_t min, const size_t max, const uint64_t id = 0) override; - - // Make copy constructor and assignment operator private. - Datasource(const Datasource &) : data(0), size(0), idx(0), left(0) {} - Datasource& operator=(const Datasource &) { return *this; } - public: - Datasource(const uint8_t* _data, const size_t _size); -}; - -#ifndef FUZZING_HEADERS_NO_IMPL -Datasource::Datasource(const uint8_t* _data, const size_t _size) : - Base(), data(_data), size(_size), idx(0), left(size) -{ -} - -std::vector Datasource::get(const size_t min, const size_t max, const uint64_t id) { - (void)id; - - uint32_t getSize; - if ( left < sizeof(getSize) ) { - throw OutOfData(); - } - memcpy(&getSize, data + idx, sizeof(getSize)); - idx += sizeof(getSize); - left -= sizeof(getSize); - - if ( getSize < min ) { - getSize = min; - } - if ( max && getSize > max ) { - getSize = max; - } - - if ( left < getSize ) { - throw OutOfData(); - } - - std::vector ret(getSize); - - if ( getSize > 0 ) { - memcpy(ret.data(), data + idx, getSize); - } - idx += getSize; - left -= getSize; - - return ret; -} -#endif - -} /* namespace datasource */ -} /* namespace fuzzing */ diff --git a/flac/oss-fuzz/fuzzing/datasource/id.hpp b/flac/oss-fuzz/fuzzing/datasource/id.hpp deleted file mode 100644 index 457c984..0000000 --- a/flac/oss-fuzz/fuzzing/datasource/id.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright 2019 Guido Vranken - * - * 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. - */ - -#pragma once - -#include -#include -#include -#include - -namespace fuzzing { -namespace datasource { - -/* From: https://gist.github.com/underscorediscovery/81308642d0325fd386237cfa3b44785c */ -inline uint64_t hash_64_fnv1a(const void* key, const uint64_t len) { - - const char* data = (char*)key; - uint64_t hash = 0xcbf29ce484222325; - uint64_t prime = 0x100000001b3; - - for(uint64_t i = 0; i < len; ++i) { - uint8_t value = data[i]; - hash = hash ^ value; - hash *= prime; - } - - return hash; - -} //hash_64_fnv1a - -// FNV1a c++11 constexpr compile time hash functions, 32 and 64 bit -// str should be a null terminated string literal, value should be left out -// e.g hash_32_fnv1a_const("example") -// code license: public domain or equivalent -// post: https://notes.underscorediscovery.com/constexpr-fnv1a/ - -constexpr uint32_t val_32_const = 0x811c9dc5; -constexpr uint32_t prime_32_const = 0x1000193; -constexpr uint64_t val_64_const = 0xcbf29ce484222325; -constexpr uint64_t prime_64_const = 0x100000001b3; - - -inline constexpr uint64_t ID(const char* const str, const uint64_t value = val_64_const) noexcept { - auto ret = (str[0] == '\0') ? value : ID(&str[1], (value ^ uint64_t(str[0])) * prime_64_const); - return ret; -} - -inline constexpr std::pair IDPair(const char* const str, const uint64_t value = val_64_const) noexcept { - return {str, ID(str, value)}; -} - -using IDMap = std::map; - -} /* namespace datasource */ -} /* namespace fuzzing */ diff --git a/flac/oss-fuzz/fuzzing/exception.hpp b/flac/oss-fuzz/fuzzing/exception.hpp deleted file mode 100644 index d1ec580..0000000 --- a/flac/oss-fuzz/fuzzing/exception.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright 2019 Guido Vranken - * - * 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. - */ - -#pragma once - -#include -#include - -namespace fuzzing { -namespace exception { - -class ExceptionBase : public std::exception { - public: - ExceptionBase(void) = default; - /* typeid(T).name */ -}; - -/* Recoverable exception */ -class FlowException : public ExceptionBase { - public: - FlowException(void) : ExceptionBase() { } -}; - -/* Error in this library, should never happen */ -class LogicException : public ExceptionBase { - private: - std::string reason; - public: - LogicException(const std::string r) : ExceptionBase(), reason(r) { } - virtual const char* what(void) const throw() { - return reason.c_str(); - } -}; - -/* Error in target application */ -class TargetException : public ExceptionBase { - private: - std::string reason; - public: - TargetException(const std::string r) : ExceptionBase(), reason(r) { } - virtual const char* what(void) const throw() { - return reason.c_str(); - } -}; - -} /* namespace exception */ -} /* namespace fuzzing */ diff --git a/flac/oss-fuzz/fuzzing/memory.hpp b/flac/oss-fuzz/fuzzing/memory.hpp deleted file mode 100644 index b324c36..0000000 --- a/flac/oss-fuzz/fuzzing/memory.hpp +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright 2019 Guido Vranken - * - * 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. - */ - -#pragma once - -#include -#include - -#ifndef ASAN -#define ASAN 0 -#endif - -#ifndef MSAN -#define MSAN 0 -#endif - -namespace fuzzing { -namespace memory { - -#ifndef FUZZING_HEADERS_NO_IMPL -#if ASAN == 1 -extern "C" void *__asan_region_is_poisoned(const void *beg, size_t size); -#endif - -#if MSAN == 1 -extern "C" void __msan_check_mem_is_initialized(const volatile void *x, size_t size); -#endif - -void memory_test_asan(const void* data, const size_t size) -{ - (void)data; - (void)size; - -#if ASAN == 1 - if ( __asan_region_is_poisoned(data, size) != NULL ) { - abort(); - } -#endif -} - -void memory_test_msan(const void* data, const size_t size) -{ - (void)data; - (void)size; - -#if MSAN == 1 - __msan_check_mem_is_initialized(data, size); -#endif -} - -void memory_test(const void* data, const size_t size) -{ - memory_test_asan(data, size); - memory_test_msan(data, size); -} - -template -void memory_test(const T& t) -{ - (void)t; -} - -template <> -void memory_test(const std::string& s) -{ - (void)s; - -#if MSAN == 1 - memory_test(s.data(), s.size()); -#endif -} - -#endif - -} /* namespace memory */ -} /* namespace fuzzing */ diff --git a/flac/oss-fuzz/fuzzing/types.hpp b/flac/oss-fuzz/fuzzing/types.hpp deleted file mode 100644 index 914e64f..0000000 --- a/flac/oss-fuzz/fuzzing/types.hpp +++ /dev/null @@ -1,158 +0,0 @@ -/* Copyright 2019 Guido Vranken - * - * 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. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace fuzzing { -namespace types { - -template -class Container { - private: - CoreType* InvalidAddress = (CoreType*)0x12; - - CoreType* _data = InvalidAddress; - size_t _size = 0; - -#ifndef FUZZING_HEADERS_NO_IMPL - void copy(const void* data, size_t size) { - if ( size > 0 ) { - std::memcpy(_data, data, size); - } - } - - void allocate(size_t size) { - if ( size > 0 ) { - _data = static_cast(malloc(size * sizeof(CoreType))); - } else { - _data = InvalidAddress; - } - }; - - void allocate_and_copy(const void* data, size_t size) { - allocate(size); - copy(data, size); - } - - void allocate_plus_1_and_copy(const void* data, size_t size) { - allocate(size+1); - copy(data, size); - } - - void access_hook(void) const { - if ( UseMSAN == true ) { - memory::memory_test_msan(_data, _size); - } - } - - void free(void) { - access_hook(); - - if ( _data != InvalidAddress ) { - std::free(_data); - _data = InvalidAddress; - _size = 0; - } - } - -#endif - - public: -#ifndef FUZZING_HEADERS_NO_IMPL - CoreType* data(void) { - access_hook(); - return _data; - } - - size_t size(void) const { - access_hook(); - return _size; - } -#endif - - Container(void) -#ifndef FUZZING_HEADERS_NO_IMPL - = default -#endif - ; - - Container(const void* data, const size_t size) -#ifndef FUZZING_HEADERS_NO_IMPL - { - if ( NullTerminated == false ) { - allocate_and_copy(data, size); - } else { - allocate_plus_1_and_copy(data, size); - _data[size] = 0; - } - - access_hook(); - } -#endif - ; - - template - Container(const T& t) -#ifndef FUZZING_HEADERS_NO_IMPL - { - Container(t.data(), t.size()); - } -#endif - ; - - ~Container(void) -#ifndef FUZZING_HEADERS_NO_IMPL - { - this->free(); - } -#endif - ; - - - - // The copy constructor was not originally explicitly supplied - // so it must have been incorrectly just copying the pointers. - Container(const Container &c) { - InvalidAddress = c.InvalidAddress; - allocate_and_copy(c._data, c._size); - } - - Container& operator=(Container &c) { - InvalidAddress = c.InvalidAddress; - allocate_and_copy(c._data, c._size); - } - -}; - -template using String = Container; -template using Data = Container; - -} /* namespace types */ -} /* namespace fuzzing */ diff --git a/flac/oss-fuzz/metadata.cc b/flac/oss-fuzz/metadata.cc deleted file mode 100644 index ad27fe9..0000000 --- a/flac/oss-fuzz/metadata.cc +++ /dev/null @@ -1,526 +0,0 @@ -/* fuzzer_metadata - * Copyright (C) 2022-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#include -#include -#include /* for memcpy */ -#include -#include "FLAC++/metadata.h" -#include "common.h" - -#define CONFIG_LENGTH 2 - -#define min(x,y) (x> 4; - - if(0)//data[1] < 128) /* Use MSB as on/off */ - alloc_check_threshold = data[1]; - else - alloc_check_threshold = INT32_MAX; - alloc_check_counter = 0; - - - /* Leave at least one byte as input */ - if(command_length >= size - 1 - CONFIG_LENGTH) - command_length = size - 1 - CONFIG_LENGTH; - - /* Dump input to file */ - { - int file_to_fuzz = mkstemps(filename, 5); - - if (file_to_fuzz < 0) - abort(); - write(file_to_fuzz,data+CONFIG_LENGTH+command_length,size-CONFIG_LENGTH-command_length); - close(file_to_fuzz); - } - - run_tests_with_level_0_interface(filename); - run_tests_with_level_1_interface(filename, init_bools[1], init_bools[2], data+CONFIG_LENGTH, command_length/2); - - /* Dump input to file, to start fresh for level 2 */ - if(!init_bools[1]){ - FILE * file_to_fuzz = fopen(filename,"w"); - fwrite(data+CONFIG_LENGTH+command_length,1,size-CONFIG_LENGTH-command_length,file_to_fuzz); - fclose(file_to_fuzz); - } - - run_tests_with_level_2_interface(filename, init_bools[0], init_bools[3], data+command_length/2+CONFIG_LENGTH, command_length/2); - - remove(filename); - - return 0; -} - -static void run_tests_with_level_0_interface(char filename[]) { - FLAC::Metadata::StreamInfo streaminfo; - FLAC::Metadata::VorbisComment vorbis_comment; - FLAC::Metadata::CueSheet cue_sheet; - FLAC::Metadata::Picture picture; - - FLAC::Metadata::get_streaminfo(filename,streaminfo); - FLAC::Metadata::get_tags(filename,vorbis_comment); - FLAC::Metadata::get_cuesheet(filename,cue_sheet); - FLAC::Metadata::get_picture(filename,picture, (FLAC__StreamMetadata_Picture_Type)(1), NULL, NULL, -1, -1, -1, -1); -} - -static void run_tests_with_level_1_interface(char filename[], bool readonly, bool preservestats, const uint8_t *data, size_t size) { - FLAC::Metadata::SimpleIterator iterator; - FLAC::Metadata::Prototype *metadata_block = nullptr; - uint8_t id[4] = {0}; - - if(!iterator.is_valid()) - return; - - if(!iterator.init(filename,readonly,preservestats)) - return; - - for(size_t i = 0; i < size && iterator.status() == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; i++) { - switch(data[i] & 7) { - case 0: - iterator.get_block_type(); - iterator.get_block_offset(); - iterator.get_block_length(); - iterator.get_application_id(id); - break; - case 1: - iterator.next(); - break; - case 2: - iterator.prev(); - break; - case 3: - iterator.delete_block(data[i] & 8); - break; - case 4: - if(metadata_block != 0) { - delete metadata_block; - metadata_block = nullptr; - } - metadata_block = iterator.get_block(); - break; - case 5: - if(metadata_block != 0) - iterator.set_block(metadata_block,data[i] & 8); - break; - case 6: - if(metadata_block != 0) - iterator.insert_block_after(metadata_block, data[i] & 8); - break; - case 7: - iterator.status(); - iterator.is_last(); - iterator.is_writable(); - break; - } - } - if(metadata_block != 0) { - delete metadata_block; - metadata_block = nullptr; - } - - -} - - -static void run_tests_with_level_2_interface(char filename[], bool ogg, bool use_padding, const uint8_t *data, size_t size) { - FLAC::Metadata::Chain chain; - FLAC::Metadata::Iterator iterator; - FLAC::Metadata::Prototype *metadata_block_get = nullptr; - FLAC::Metadata::Prototype *metadata_block_transfer = nullptr; - FLAC::Metadata::Prototype *metadata_block_put = nullptr; - - if(!chain.is_valid()) - return; - - if(!chain.read(filename, ogg)) - return; - - iterator.init(chain); - - for(size_t i = 0; i < size; i++) { - switch(data[i] & 15) { - case 0: - iterator.get_block_type(); - break; - case 1: - iterator.next(); - break; - case 2: - iterator.prev(); - break; - case 3: - iterator.delete_block(data[i] & 16); - break; - case 4: - metadata_block_get = iterator.get_block(); - if(metadata_block_get != 0 && metadata_block_get->is_valid()) { - if(metadata_block_transfer != 0 && metadata_block_transfer->is_valid()) { - if(metadata_block_transfer != metadata_block_get) { - delete metadata_block_transfer; - metadata_block_transfer = nullptr; - metadata_block_transfer = FLAC::Metadata::clone(metadata_block_get); - } - } - else { - metadata_block_transfer = FLAC::Metadata::clone(metadata_block_get); - } - } - delete metadata_block_get; - break; - case 5: - if(metadata_block_transfer != 0 && metadata_block_transfer->is_valid()) { - metadata_block_put = FLAC::Metadata::clone(metadata_block_transfer); - if(metadata_block_put != 0 && metadata_block_put->is_valid()) { - if(!iterator.insert_block_before(metadata_block_put)) - delete metadata_block_put; - } - else - if(metadata_block_put != 0) - delete metadata_block_put; - } - break; - case 6: - if(metadata_block_transfer != 0 && metadata_block_transfer->is_valid()) { - metadata_block_put = FLAC::Metadata::clone(metadata_block_transfer); - if(metadata_block_put != 0 && metadata_block_put->is_valid()) { - if(!iterator.insert_block_after(metadata_block_put)) - delete metadata_block_put; - } - else - if(metadata_block_put != 0) - delete metadata_block_put; - } - break; - case 7: - if(metadata_block_transfer != 0 && metadata_block_transfer->is_valid()) { - metadata_block_put = FLAC::Metadata::clone(metadata_block_transfer); - if(metadata_block_put != 0 && metadata_block_put->is_valid()) { - if(!iterator.set_block(metadata_block_put)) - delete metadata_block_put; - } - else - if(metadata_block_put != 0) - delete metadata_block_put; - } - break; - case 8: /* Examine block */ - if(metadata_block_transfer != 0 && metadata_block_transfer->is_valid()) { - switch(metadata_block_transfer->get_type()) { - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - { - uint32_t num_comments; - ::FLAC__StreamMetadata_VorbisComment_Entry entry; - FLAC::Metadata::VorbisComment::Entry entry_cpp; - FLAC::Metadata::VorbisComment * vorbiscomment = dynamic_cast(metadata_block_transfer); - const ::FLAC__StreamMetadata * metadata_c = *metadata_block_transfer; - if(vorbiscomment == 0) - abort(); - vorbiscomment->get_vendor_string(); - num_comments = vorbiscomment->get_num_comments(); - if(num_comments > 0) { - entry = metadata_c->data.vorbis_comment.comments[min(data[i]>>4,num_comments-1)]; - if(entry.entry == 0) - abort(); - if(vorbiscomment->get_comment(min(data[i]>>4,num_comments-1)).is_valid()) { - entry_cpp = vorbiscomment->get_comment(min(data[i]>>4,num_comments-1)); - if(entry_cpp.is_valid() && entry_cpp.get_field() == 0) - abort(); - vorbiscomment->find_entry_from(0,"TEST"); - } - } - - } - break; - case FLAC__METADATA_TYPE_CUESHEET: - { - uint32_t num_tracks, num_indices; - FLAC::Metadata::CueSheet * cuesheet = dynamic_cast(metadata_block_transfer); - if(cuesheet == 0 || !cuesheet->is_legal()) - break; - cuesheet->is_legal(true); /* check CDDA subset */ - cuesheet->calculate_cddb_id(); - cuesheet->get_media_catalog_number(); - cuesheet->get_lead_in(); - cuesheet->get_is_cd(); - num_tracks = cuesheet->get_num_tracks(); - if(num_tracks > 0) { - FLAC::Metadata::CueSheet::Track track = cuesheet->get_track(min(data[i]>>4,num_tracks-1)); - track.get_offset(); - track.get_number(); - track.get_isrc(); - track.get_pre_emphasis(); - num_indices = track.get_num_indices(); - if(num_indices > 0) { - FLAC__StreamMetadata_CueSheet_Index index = track.get_index(min(data[i]>>4,num_indices-1)); - (void)index; - } - } - } - break; - case FLAC__METADATA_TYPE_PICTURE: - { - char * violation = nullptr; - FLAC::Metadata::Picture * picture = dynamic_cast(metadata_block_transfer); - if(picture == 0 || !picture->is_legal((const char **)&violation)) - break; - picture->get_data(); - } - break; - default: - break; - } - - } - break; - case 9: /* Replace or add in block */ - if(metadata_block_transfer != 0 && metadata_block_transfer->is_valid()) { - switch(metadata_block_transfer->get_type()) { - case FLAC__METADATA_TYPE_SEEKTABLE: - { - uint32_t num_seekpoints; - FLAC__StreamMetadata_SeekPoint seekpoint; - FLAC::Metadata::SeekTable * seektable = dynamic_cast(metadata_block_transfer); - if(seektable == 0) - break; - if(seektable->is_valid() && seektable->is_legal()) { - num_seekpoints = seektable->get_num_points(); - if(num_seekpoints > 0) { - seekpoint = seektable->get_point(min(data[i]>>5,num_seekpoints-1)); - seektable->set_point(0,seekpoint); - seektable->insert_point(min(data[i]>>5,num_seekpoints-1),seekpoint); - } - seektable->template_append_placeholders(4); - seektable->template_append_point(111111); - seektable->template_append_points((FLAC__uint64[]){222222, 333333, 444444}, 3); - seektable->template_append_spaced_points(data[i]>>5, 1234567); - seektable->template_append_spaced_points_by_samples(data[i]>>5, 2468000); - seektable->template_sort(data[i] & 16); - } - } - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - { - uint32_t num_comments; - FLAC::Metadata::VorbisComment::Entry entry; - FLAC::Metadata::VorbisComment * vorbiscomment = dynamic_cast(metadata_block_transfer); - if(vorbiscomment == 0) - break; - num_comments = vorbiscomment->get_num_comments(); - if(num_comments > 0 && entry.is_valid()) { - if(vorbiscomment->get_comment(min(data[i]>>5,num_comments-1)).is_valid()) { - entry = vorbiscomment->get_comment(min(data[i]>>5,num_comments-1)); - if(entry.is_valid()) { - vorbiscomment->replace_comment(entry,data[i] & 16); - vorbiscomment->set_comment(0,entry); - vorbiscomment->append_comment(entry); - vorbiscomment->insert_comment(0,entry); - } - } - } - } - break; - case FLAC__METADATA_TYPE_CUESHEET: - { - uint32_t num_tracks, num_indices; - FLAC::Metadata::CueSheet * cuesheet = dynamic_cast(metadata_block_transfer); - if(cuesheet == 0 || !cuesheet->is_legal()) - break; - num_tracks = cuesheet->get_num_tracks(); - if(num_tracks > 0) { - FLAC::Metadata::CueSheet::Track track = cuesheet->get_track(min(data[i]>>4,num_tracks-1)); - num_indices = track.get_num_indices(); - if(num_indices > 0) { - FLAC__StreamMetadata_CueSheet_Index index = track.get_index(min(data[i]>>4,num_indices-1)); - track.set_index(0,index); - cuesheet->insert_index(0,0,index); - cuesheet->insert_blank_index(0,0); - } - cuesheet->insert_blank_track(0); - cuesheet->insert_track(0,track); - cuesheet->resize_indices(min(data[i]>>4,num_tracks-1),data[i]>>4); - } - } - break; - case FLAC__METADATA_TYPE_PICTURE: - { - FLAC::Metadata::Picture * picture = dynamic_cast(metadata_block_transfer); - const char testtext[] = "TEST"; - if(picture == 0 || !picture->is_legal(NULL)) - break; - picture->set_description((FLAC__byte *)&testtext); - picture->set_mime_type((const char *)&testtext); - picture->set_data((FLAC__byte *)&testtext,4); - } - break; - default: - break; - } - - } - break; - case 10: /* Delete from block */ - if(metadata_block_transfer != 0 && metadata_block_transfer->is_valid()) { - switch(metadata_block_transfer->get_type()) { - case FLAC__METADATA_TYPE_SEEKTABLE: - { - uint32_t num_seekpoints; - FLAC::Metadata::SeekTable * seektable = dynamic_cast(metadata_block_transfer); - if(seektable == 0) - break; - if(seektable->is_valid() && seektable->is_legal()) { - num_seekpoints = seektable->get_num_points(); - if(num_seekpoints > 0) - seektable->delete_point(min(data[i]>>4,num_seekpoints-1)); - } - } - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - { - uint32_t num_comments; - FLAC::Metadata::VorbisComment * vorbiscomment = dynamic_cast(metadata_block_transfer); - if(vorbiscomment == 0) - break; - num_comments = vorbiscomment->get_num_comments(); - if(num_comments > 0) - vorbiscomment->delete_comment(min(data[i]>>4,num_comments-1)); - vorbiscomment->remove_entry_matching("TEST"); - vorbiscomment->remove_entries_matching("TEST"); - } - break; - case FLAC__METADATA_TYPE_CUESHEET: - { - uint32_t num_tracks; - FLAC::Metadata::CueSheet * cuesheet = dynamic_cast(metadata_block_transfer); - if(cuesheet == 0 || !cuesheet->is_legal()) - break; - num_tracks = cuesheet->get_num_tracks(); - if(num_tracks > 0) { - FLAC::Metadata::CueSheet::Track track = cuesheet->get_track(min(data[i]>>4,num_tracks-1)); - if(track.get_num_indices() > 0) - cuesheet->delete_index(min(data[i]>>4,num_tracks-1),0); - cuesheet->delete_track(0); - } - } - break; - default: - break; - } - - } - break; - case 11: /* Resize block */ - if(metadata_block_transfer != 0 && metadata_block_transfer->is_valid()) { - switch(metadata_block_transfer->get_type()) { - case FLAC__METADATA_TYPE_PADDING: - { - FLAC::Metadata::Padding * padding = dynamic_cast(metadata_block_transfer); - if(padding == 0) - break; - padding->set_length(data[i]>>4); - } - break; - case FLAC__METADATA_TYPE_SEEKTABLE: - { - FLAC::Metadata::SeekTable * seektable = dynamic_cast(metadata_block_transfer); - if(seektable == 0) - break; - seektable->resize_points(data[i]>>4); - } - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - { - FLAC::Metadata::VorbisComment * vorbiscomment = dynamic_cast(metadata_block_transfer); - if(vorbiscomment == 0) - break; - vorbiscomment->resize_comments(data[i]>>4); - } - break; - case FLAC__METADATA_TYPE_CUESHEET: - { - uint32_t num_tracks; - FLAC::Metadata::CueSheet * cuesheet = dynamic_cast(metadata_block_transfer); - if(cuesheet == 0 || !cuesheet->is_legal()) - break; - num_tracks = cuesheet->get_num_tracks(); - if(num_tracks > 0) { - cuesheet->resize_indices(min(data[i]>>4,num_tracks-1),data[i]>>4); - } - cuesheet->resize_tracks(data[i]<<4); - } - break; - default: - break; - } - - } - break; - case 12: /* Prototype functions */ - if(metadata_block_transfer != 0 && metadata_block_transfer->is_valid()) { - const ::FLAC__StreamMetadata * metadata_compare = *metadata_block_transfer; - metadata_block_transfer->get_is_last(); - metadata_block_transfer->get_length(); - metadata_block_transfer->set_is_last(data[i] & 16); - FLAC__metadata_object_is_equal(metadata_compare, metadata_compare); - } - break; - } - } - if(metadata_block_transfer != 0) { - delete metadata_block_transfer; - metadata_block_transfer = nullptr; - } - - chain.status(); - chain.sort_padding(); - chain.merge_padding(); - - chain.check_if_tempfile_needed(!use_padding); - chain.write(use_padding); - -} diff --git a/flac/oss-fuzz/reencoder.cc b/flac/oss-fuzz/reencoder.cc deleted file mode 100644 index 457fbd4..0000000 --- a/flac/oss-fuzz/reencoder.cc +++ /dev/null @@ -1,304 +0,0 @@ -/* Copyright 2019 Guido Vranken - * - * 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 -#include -#include - -#include -#include - -#include "FLAC++/encoder.h" -#include "FLAC++/decoder.h" -#include "FLAC++/metadata.h" -#include "common.h" - -#define MAX_NUM_METADATA_BLOCKS 2048 - -namespace FLAC { - namespace Encoder { - class FuzzerStream : public Stream { - private: - // fuzzing::datasource::Datasource& ds; - public: - FuzzerStream(fuzzing::datasource::Datasource&) : - Stream() { } - - ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t /* samples */, uint32_t /* current_frame */) override { - fuzzing::memory::memory_test(buffer, bytes); - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; - } - }; - } - namespace Decoder { - class FuzzerDecoder : public Stream { - private: - fuzzing::datasource::Datasource& ds; - FLAC::Encoder::FuzzerStream& encoder; - public: - FuzzerDecoder(fuzzing::datasource::Datasource& dsrc, FLAC::Encoder::FuzzerStream& encoder_arg) : - Stream(), ds(dsrc), encoder(encoder_arg) { } - - ::FLAC__StreamMetadata * metadata_blocks[MAX_NUM_METADATA_BLOCKS] = {0}; - int num_metadata_blocks = 0; - - void metadata_callback(const ::FLAC__StreamMetadata *metadata) override { - if(num_metadata_blocks < MAX_NUM_METADATA_BLOCKS) - if((metadata_blocks[num_metadata_blocks] = FLAC__metadata_object_clone(metadata)) != NULL) - num_metadata_blocks++; - } - - ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) override { - try { - const size_t maxCopySize = *bytes; - - if ( maxCopySize > 0 ) { - /* memset just to test if this overwrites anything, and triggers ASAN */ - memset(buffer, 0, maxCopySize); - } - - const auto data = ds.GetData(0); - const auto dataSize = data.size(); - const auto copySize = std::min(maxCopySize, dataSize); - - if ( copySize > 0 ) { - memcpy(buffer, data.data(), copySize); - } - - *bytes = copySize; - - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } catch ( ... ) { - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - } - } - - ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) override { - { - fuzzing::memory::memory_test(&(frame->header), sizeof(frame->header)); - fuzzing::memory::memory_test(&(frame->footer), sizeof(frame->footer)); - } - - { - const auto numChannels = get_channels(); - const size_t bytesPerChannel = frame->header.blocksize * sizeof(FLAC__int32); - for (size_t i = 0; i < numChannels; i++) { - fuzzing::memory::memory_test(buffer[i], bytesPerChannel); - } - } - - /* Data is checked, now pass it towards encoder */ - if(encoder.get_state() == FLAC__STREAM_ENCODER_OK) { - if(encoder.get_channels() != get_channels()) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - if(encoder.get_bits_per_sample() != get_bits_per_sample()) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - encoder.process(buffer, frame->header.blocksize); - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; - } - else - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - void error_callback(::FLAC__StreamDecoderErrorStatus status) override { - fuzzing::memory::memory_test(status); - } - }; - } -} - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - fuzzing::datasource::Datasource ds(data, size); - FLAC::Encoder::FuzzerStream encoder(ds); - FLAC::Decoder::FuzzerDecoder decoder(ds, encoder); - - try { - const int channels = ds.Get(); - const int bps = ds.Get(); - encoder.set_channels(channels); - encoder.set_bits_per_sample(bps); - - { - const bool res = encoder.set_streamable_subset(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_ogg_serial_number(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_verify(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_compression_level(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_do_mid_side_stereo(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_loose_mid_side_stereo(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_max_lpc_order(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_qlp_coeff_precision(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_do_escape_coding(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_min_residual_partition_order(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_max_residual_partition_order(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_total_samples_estimate(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_blocksize(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_limit_min_bitrate(ds.Get()); - fuzzing::memory::memory_test(res); - } - { - const bool res = encoder.set_sample_rate(ds.Get()); - fuzzing::memory::memory_test(res); - } - - decoder.set_metadata_respond_all(); - - { - ::FLAC__StreamDecoderInitStatus ret; - if ( ds.Get() ) { - ret = decoder.init(); - } else { - ret = decoder.init_ogg(); - } - - if ( ret != FLAC__STREAM_DECODER_INIT_STATUS_OK ) { - goto end; - } - - decoder.process_until_end_of_metadata(); - if(decoder.num_metadata_blocks > 0) - encoder.set_metadata(decoder.metadata_blocks, decoder.num_metadata_blocks); - } - - { - ::FLAC__StreamEncoderInitStatus ret; - if ( ds.Get() ) { - ret = encoder.init(); - } else { - ret = encoder.init_ogg(); - } - - if ( ret != FLAC__STREAM_ENCODER_INIT_STATUS_OK ) { - goto end; - } - } - - /* These sets must fail, because encoder is already initialized */ - { - bool res = false; - res = res || encoder.set_streamable_subset(true); - res = res || encoder.set_ogg_serial_number(0); - res = res || encoder.set_verify(true); - res = res || encoder.set_compression_level(0); - res = res || encoder.set_do_exhaustive_model_search(true); - res = res || encoder.set_do_mid_side_stereo(true); - res = res || encoder.set_loose_mid_side_stereo(true); - res = res || encoder.set_apodization("test"); - res = res || encoder.set_max_lpc_order(0); - res = res || encoder.set_qlp_coeff_precision(0); - res = res || encoder.set_do_qlp_coeff_prec_search(true); - res = res || encoder.set_do_escape_coding(true); - res = res || encoder.set_min_residual_partition_order(0); - res = res || encoder.set_max_residual_partition_order(0); - res = res || encoder.set_rice_parameter_search_dist(0); - res = res || encoder.set_total_samples_estimate(0); - res = res || encoder.set_channels(channels); - res = res || encoder.set_bits_per_sample(16); - res = res || encoder.set_limit_min_bitrate(true); - res = res || encoder.set_blocksize(3021); - res = res || encoder.set_sample_rate(44100); - fuzzing::memory::memory_test(res); - if(res) - abort(); - } - - - { - /* XORing values as otherwise compiler will optimize, apparently */ - bool res = false; - res = res != encoder.get_streamable_subset(); - res = res != encoder.get_verify(); - res = res != encoder.get_do_exhaustive_model_search(); - res = res != encoder.get_do_mid_side_stereo(); - res = res != encoder.get_loose_mid_side_stereo(); - res = res != encoder.get_max_lpc_order(); - res = res != encoder.get_qlp_coeff_precision(); - res = res != encoder.get_do_qlp_coeff_prec_search(); - res = res != encoder.get_do_escape_coding(); - res = res != encoder.get_min_residual_partition_order(); - res = res != encoder.get_max_residual_partition_order(); - res = res != encoder.get_rice_parameter_search_dist(); - res = res != encoder.get_total_samples_estimate(); - res = res != encoder.get_channels(); - res = res != encoder.get_bits_per_sample(); - res = res != encoder.get_limit_min_bitrate(); - res = res != encoder.get_blocksize(); - res = res != encoder.get_sample_rate(); - fuzzing::memory::memory_test(res); - } - - decoder.process_until_end_of_stream(); - - } catch ( ... ) { } - -end: - { - const bool res = encoder.finish(); - fuzzing::memory::memory_test(res); - } - { - const bool res = decoder.finish(); - fuzzing::memory::memory_test(res); - } - for(int i = 0; i < decoder.num_metadata_blocks; i++) - FLAC__metadata_object_delete(decoder.metadata_blocks[i]); - - return 0; -} diff --git a/flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/aiff-with-foreign-metadata-8bps.fuzz b/flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/aiff-with-foreign-metadata-8bps.fuzz deleted file mode 100644 index 944c775a3914da040492eda056520cdbbe8cb2ec..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 475 zcmbu5%}T>S5XU#I1*KBKL!k;XM-PqEwp0&AvL+2Jwu!XsS=Ks@!88foMZstC349ho z5D%V;c+k@SoTd>fekQs!QSuTEJWZo;EH5JD zp664wEv`@@Xc;JwGXzor8kG*?Ad53a@T~}xPG&Md2xD;j+=kJ}%T(+TpLXu-Rf@*^ z_4(=XW&XBUE|$whKHqa1K<#((E6k#e0?O76DCF0U%DZA{pHQA7YQpwC@dVgkMwfkX$yz{#KQ-FH8H@6Kgoj|}6fNNV^=CSed8`%*_>xIH z6OO`ZZ)n-v+-h%`Y&J}@3Fx#1qN)mgzvqreM5VXZpw|Ppra9Xkfx{O{c-QDuXZcN6 z=ghON>j=jh?ZT{2!dN!B-EQ=sZ*psU`{oYkYCnx6N3FV!wC;O-L@ql?!B(0^;Y>{< zfww>RI*tqPE$^}9!i5TQR+%s+!-eEU7zg^Sr^LUf#CefqDi981p5G0%R&=e&#L-=@ z0doQWUGsx(i$Q#aUZf808o)YR;!64S?b?Pnw(r75Ff}~eb)c63eKCHf4kY)wW4)9L zfcdq4&87oW%YQWP-P>)V!a3mNa6D^x2jnVXCs8D`B1~dVeEy@Ufv2~43HbX8=mq{I hMEpa3d#tvZK3qDydi>Jb`3YPio(2E_ diff --git a/flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/flac-foreign-metadata-wav-8bps.fuzz b/flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/flac-foreign-metadata-wav-8bps.fuzz deleted file mode 100644 index 6f4ed9c59427f1ae44cfe4f7670b0bc05bb0dab3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 715 zcmbtSL2DC16n^P8qHWMnFlg=J(NhlHl4L_w5XpA8(WS{IYzMtMO=h=)o84u1R1kzx z?XT#;LJvjoroTY^1A6f$_!IOXp42xHksS2m?0(Gq-n{qb%{OD1V=&G8LS$x`=0Zk^ zIT4DFx#AG^xB~#IRjAT*h5m)Nos7(ydUx{b>xCl<0F` z!W1Pqt8*%PT{m0%RpX=PJ#UA-C+_*(f#=)(6|#3^BG$0oZrpynhStW$wX0b0NfwKO z;)a2{OfgOx$6};pnqV5D&cH|f;WWYynC`$&71~)A%Mss=1!X#Yc7yzEPZRUE$;JZGd z99#H>Jf3UKLx+@!h*U~gHqPCw)mh+d6Q8CqXW)~)NcdBdxq-geGC}X^4ElXCI|M!c z<1lQv)uaj+2(wZ#ySGWs%Y?tF%si%F0zI>TUDl6patse6IqM1$p8QV diff --git a/flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/replaygain-which-is-not-lossless-ogg.fuzz b/flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/replaygain-which-is-not-lossless-ogg.fuzz deleted file mode 100644 index e211fc6eae3c056933bb58ada15dc8e8b3217707..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15406 zcmeI2c`%#byTF5l*eW4*ZH0&+G*P?O5|IkA?`ug#ZEdYxsMZoH5lZYzN$g8ol$O?B zT0vV|RZFW2iuzV*RjZ3zzx$iHcjn%i`}du3X5M+9^Uiyo_sr)r^UQhA93FLbzp${- z3+fS+uu#7XC;fs>tDg%DIuWQI6sdmtOq6=)naIdcN@OHJ-5+3k@}whx8}RQIy)|@f zH#BYto#HxtnLsi%;{pJ90!V&lf1fIF0si*5Pynv`0{ytp0DwptXoq9uk^b(RkKfU% z$sfY0|4R4oWB|Z!y1yd;2cnDGxzIoW044vo7eNW2L{LtjpvZ>?k#|2KkJUJ=aadjx zgVo3AVYGIK|Ia+Tb6h@ic7scT2LKS=edoV7uK#7k-}eBSCu_psJO4*RBmm_9d$PTF zkH8**Jpy|K_6Y0|*dwq=D=_ut#8z zz#f4;0(%7Z2<#E~e@furCk_PubNag{7yh1C0IY^s?1$~N?A+RE+`0F!`)<^gI2ykuF{> z4Ct^TlvdYIUL~OVC}@VFI{)S0fO(>5%W|NYf1RG^Tj7N#{IL$pAEY1RqA zwm}~q4Iy|v2h&2PZ%$PFLk2<>rb%5$rr!5$RJZDh6}o76QRsP#+Hw;6+sbl5WXZE#iaa$tIyAYZ*(A zrtiU$iV5z8^5$1|m2sKj*1Fba2D(20eCeuCDhH{e0`_gC_W66f)zlCZH`Qc?E74N> z9PG{WsZuI=shl8Y0m0dUyslN54elSZGE>60tK)~1B<%f!fPpz~*}zeT3X@~b9=8A86=!XZ(V5mT50p(NRQD|Aov)K2=h=!=B<0-M$x3o3UCD2yIn*DVRgH)J0aJ~vI1LlIq_SIS7zNvNLJvUOBmk*#Vy zr!1oq4P1v_zvfl%heuB(|2$GBHXjpC*NS`Gv@d2Ulaw$@6gK6%sCcL~N&U7~cspn+ zF=4Vnu)U;wAG$PV4#NHUvl0KI<~NEesgvV#aKXhku&|`sR^CU{3^V^lP`HUs`cvHS z=*c$VR0!B1qqOtYH>iO+L|}H;7PlpS>(aN^-^^OIssq3FC`Mz2y^0w3pLyg94)zsT zOEgh%93fgVluSd}IiQddC>EZjqF||lsu(~Q+#7a;%D7k~Ydu=A(q37q{fumN4Rl5G zfQq0Rx72Zdx)^_!If7)xpNvR@(dkTwWOhTvD7CXRfzH$Ek&npEk#x_!8`h@jtYH&y zel{igDBh*==X~n=oLZk!P`~kUMWsG}Y;LK#kJ?RF`eg%)y5*M#7L>1jcU6c2!k;cx zdlH_eeIbbT$65T)xmqC{;?g~(|FYfM&Ut7kZR33XknC}rymxui+!e0t!p3c-u9VPQ zO=3$A3&k%cSU7$vM@HU6|B5Ys)m>@K-*a+%pX;Zi?GcKfX{Jl+X5JTS>|!q<#~@Fi zGM{N(#}3le!#t-6^SPT&z=G>``^5t;+dG#etLau)N*@q5I{UudUjOc;owbZqwHFcL^vpzVi90p4{jj=YNMCAINLXcKc~65)h$J3Dq9&$k(RlKmFBOi@{u1n zp9G{-Hjqd(x)L1Y=8mw3B~tBJFbNbIDFH*L2@=2q6{MPSpp-jx9&<&ERD7&lkz}=K z0d^g$s@s@!%mJNJoj%=i?d%I_`iqNd8bqttR79R<+D0%Y_DVzxvGv>OzRODK za=M4(7!-3g|#ueNnD5?qxYC5un-3KHWT6Hmob#5mzPU zT=`@3p5dR-di^KI(F}~wz;!N+SM1?u(aUK0PY*Zv=k^xxQCPEdyf*?QUqmneT(6H&nknn!Q)K-#uRZ$ z7DW&V#E>je?l_JqhGd>wHXnDK+PWyhql>=hS1CDomcSq3R69;lCO zlvPs415de}_YAdlX~aCHRidw|AaI_qg8ZTd!v?JipwGRKu%6FNt_IgxM7jav={HN^pHL2_QE5 zE{^2*_b3$4RXt5~N}_{{BL7fhI+PmNYUSdAZmID?Lg|T` zs7i{2m>7=Scpaz-rKh2-Ao+b@tbo$_{In?BZSmUeHXEodzhOcLgDf|2NjZAUTV(X> zaA!*UwU#@f_tzy?etqo6j{SnW%@)6V53URxuls0K{01X=9HiHn?e;>*dwi*Xv0*Ip ztnTLa*|dkppU%1%InVsF&%UU3aiXfO1Aq4Wv)27NGwIjtEtD>kHvha1Y8YZpuAehh z+PB6Iuv@lv{Z*>=MO3Wt?X1HiY;ep)ZeaBn<)76;VwI5^{CNs-VfAU1)+BVTf zh+Q(%=F>@a)bljqTbgLFBtgU#sDrl%JytiGKb$IcZAxzHmK)4Kuh; zrY;C8lh+;;MG$kxVgm`1=GoTf0yqo_iLewz*`wXO#Gn=|O-poJi#6IBzl`*N(`ebm z!9GoFP_CFcd1yck%rPe_$Vf2JIcS=>ggw!%DXdv^D~D_3)|kOhtvA+~8!<;bIXOYp zUgbltGMM^jJc2+4Y*C!5OzW?xR7v>=1mwY?zL(}-jzT8(KV04jxG9Nh*8UW%CwuE@ zSS8dStqBqW4So1r=oP5uuG&Pkm&n5Hce|jNUzv5=f)Sh6#VVPUN~mY#T*z}O=}Rt% z)6V0!CkH2%ydUdt=`%UNCjZYU+8V|z`>gAV?8hk z;(}#W|EkI5dK%!Q-$}pn30{Gb`dp;qP9G=ss z(0K}h6lC!kX9v02-B;ZycALzBk_q zE3zCKw(!a#k6Vf|5o}8wCmAl~j%v<*095e{Wt}#E?aYaWR^iY3Wacw1MDiNv6QvaO z(26w%8I!7G65QU0Cy3& z_2gZBNG;pxLU~u|oI3dzatO}1h{=3b#jW*xzjDps#<`T|GHIK+=jT-2D*V1VE4bD) zzhS#`vs2$n*6CB7d+hHg3(D7YDACDwSNt5V5v28Q4+nToR9h=3KZsMBSP&WngULYhme{c7=`ps-S4d9O0HGN|QjaOfhU!qZ!aQ1tEb%y?>7%Z%$`j?igN`0I);AyL zw|;VqFWtu_aeV7MA}ob}-#xKdYDD5noQy{nMk?8FoL&@w;a!=3R1%c|Ix%&}uD}gm zM2AMGrt<2_*9&!cJQz5jXM>rMS*@bw_wDF~7JXQDa}Z%s2A;23NZoXtvG=Jvoqb1h zdw8R*p(Y%j=GwLfKC8Mh(jz{-c}sxB!-Q7GOv)cg2H_e^PDWf5w+v~ojMO4o=L)rk zSlH&kd3-VAXNp7%Wv;GDH$WemK$45T;Hnr#=7LK8?-wblWooE`|xc9m1D-)8~)5KJ^e9i0DgVmwry;Tml?wIH^!w@a(wqY-3s}3=RTVD7DfQ*` zHmBIe;~h)&UuO^0dD{eHlhs~m+fN){$-sK5K z`uj}Ex6zF!*&{zRvo!}lKEHC32-K{qBVWS9gO{c!gWgYm{OM9;+ggfKh(&bzwy0*X zcn25Pg<`wP#uQenOX>HTe{3$0h*&jUqcU|J8O!jj_CJv;5*oZ6v1-zv~pI?v!F@cxA?_EpF_@+;@ zc7*l?UNHHDWe`@&8k#8OL9iewU=(3?g`#%NXbCFIp9D?zWiY)o&~1ewF5XlrWi~eE zMwE|7OM^#$M^k)8$mI1G(aa1eCO?XG!@o1IHVXWFKOt@MP(@vL*UTG)`LCLg{1^99 zb767|fbw~(i@}>JTKASBOCM$b$o}2+nqM#CgI3pyVbD8mki%rd!Qa$ErOW^gy2yRI z>(YOu4-VJ4E(Cod>oASagOmcp``{xnvj^3T)IXZ(s ze^%votFCq3Idbl6oXWFp-J11^Y^7&R+arNZV%tF|Klq_EX{m+&See9=BXP0or=qR2 z0_ElEI_|T(9%UVvqJ5mu895iL9IC2fCDvzqcxCur*D04u;$m_0r;?NbzC!xB1 zzYs&9Dc3uGJp}r$Fu`ct_LraIyVa9Q_;KIhRJ)OF>y0tb>haUK!gp$F1~z7?tM^q7 z9!_m5Xmcm~g%JetOtf8rs;CmwR1=n_;Af!3CL`JYW6}f&=kL{zm08aAo@78U5I@aH zR$zr4(}E6D1^K$s;R?O}b~Kt2G*QTsM&s0zr7{>+b0&O0lZ7Og#$gu3^>cOEA&Ga@ zgN7hXlBc6ryW(*3`REwojeV0wPfA-~xal+li2~Z656=FxY!{E#?US#A>Qq2a0exoZ z5vD+7p9RrqgXerER(bGxT-;d7m4+{1QS&DQk{bahUbYKKreWoPSZr~(cnbJ z3Ft&yYlRg)Pkf;K=#=p7`9yD@T16@GJ_{_@wKg3UrOi1YOmBNlntFDz@018B9JN^0ksbJk zd3FCqtN`|o@*FEd)ELR?M?PRIC#A}A0V9Pm2JyS-t&H$~t+e|3dkDYjiR(XOQuN5Pn;GJF)p&{huvr9zGl zRsXY=b<=aU-Yl-qz-vS8A6M@Rch{lUNT2qn<03DUp1I559wf8^=`A&>G@&Ny9DfcNQ)oeN}{ybxrIh zOR36qxY_s0jP+!~39A~V<=m*%D zFI6A(-YXqxeBe_+jO1>xyWV$2pu~4t=GS~q_CJ5*jlxXPM}3bKo}dc2B#Sv|@0ZU_ zQe!F|1|P3m3D`zJ0;%w@gUe)b z1{NR1Ij69!{mN){wb|XM#gX9XR1OSeKn5x$=`2Lf-$hBEr2wAFQlQ~R;nad!Rd;kj zIy`~b`KF@AAbC1n9qA}3p7ys)nqIw&-VTh~y2YIwZLZVW`PF6ZH~#Drj5lo9ZC1oP z!nSPd@aCc+DeuvKkNaLjF`Mo$V{0{i?3`z2kKJFJiCIPqa>SMVQ>1K|n;f&4@xfQR z%9(Q=l>@xQOI;OL`kxf4zgO}?toM6mszOiA7(RO7uv0YS-?{nyu+Z(dBgbzk!7>a) zc_mz-g|9!k-#jbem0~J3U(`AlA(Q{+c6$K$wSa{}0X!#wjBXNNKEM8L;7G(&;JRaD z_Zy`)W*m%Ot$u;kiqMt^W$}$_#%j^R9oJbG9o)X#DvQ|j z8sQTrs3@*9p^0vg$NNMpmUjwDp(24i3LNp9ETHR#CtWW+^B<=Fh_Fgch=K4yeCA9nRyJ zuMAG-eGG;Tj1L=ixGHK8kPU@oj9D^MDVd2P$~VJNsAOtypc@HFizx=YKmVCu=A?p8 znI}|cvT*=#++6^hb4gbO8T3u>(2xE?lue{|h^)ki2X0oP*G75AkPYHK8U~vEe-@4o z>o<;~=yr2DjD;Rg>e9>l@ag8sq+jyF7N3_Ojwg(*SMDCAV(;8FS*275&@+-1qjTz7 zWD5bKTb9nZMF*Qn92uYH{$>^1YsgyMyVwpS8EEoYgMl|M!#&~Unf9+uYOC1*`|(ER z^$OQiOT7-^uLOx)Yz!ZpyFd8hRWKl7I6V~)u3_d-h0Y{o$oe8sRB6dozhj8SFiXYZbvr9F~LU z-%MAWOOQY9chI!ZPOL>LX?9b2w&vh0`KTv9qqz>u=n1NtUf^*vFb9EO1~MsQ?>5Be z5_QD&yAmx0A=zg$`PyZU!-OMTgqjkBy*egXH~9~iu}1LBl`DD7Kh_Kk_2Jv-6fHu> z=L}h*gAV+@!}_}#smET+*uJkf4dVC!Bzd0P&*z6^6i7H(mB(zU`J#^DO_IZ@Lx Xp!(>_0lwf%N8kfz^rP_cKV$v_UpVLs diff --git a/flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/replaygain-which-is-not-lossless.fuzz b/flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/replaygain-which-is-not-lossless.fuzz deleted file mode 100644 index 9d97430ba5e9581907bda48c5306033c15696d56..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15852 zcmeI#`#TfY3ir4B$NN9Hugm+#*Y$q?^0=<&b-iEvG&KApB0>{1q6iV8{s|ZS ziD4RXLB#Vx8pLRgu<#g-(D3N!P(pMxpGE**AlBcKkB?7DfKPyrZ=V6*J}==ufKQN*52o_5}6>_5}6>_5}6>_5}6>_5}6>_5}6>_5}6> z_5}6>_5}6>_5}6>_5}6>_5}6>_5}6>_5}6>{(l$P-6)Xe`-7a9kLcIkDmKUN-iptQzDyC=`SaI8QbZ2V=v=#gfY6|T!6kZi* zcZg|!{hVG)C zz3$QVXhO3sz$Vh@u$98zpm|Y z>IZVvJ2GRkCkDGLc3|sFY~wujWw>dnGv+z#1ztMg)3K4vh8Xw(BYKlA8hm&nU~}Y< za@3RsdLT~QG6$YU=r#e|Vy}s}4b-t59qA)ZItrD2@rPHER5Lk3sYgXh`|XYZ8m z#T3PJD^r+<`=Ofs6~`7McYkEI($m8X=?2TNmP5DB-4To2XS5>v=GN`T{^9PEF9d~b zsBE{ZT@O`O&q@9Mcs58ZTTH(6kB;b1DUDeUwed2b6c<6uQ0+fP8Mq-JB<2tGkuA41Ca7UM2Ylsc-5i1n ziYpuxd_k7lGe1QRHqfv;MKw>KZ}D9W5puqHyYu63aT5)(9f5x>@lPSwul=61Z#Qd>(v2Uef&C585f0<(E6j=z3=nh>5q%}LLFsM#3QOJtCO2kw$| z-IO7NIg*kje+;BY6x@5K0WJczB9mEUTKDPhn@H^jX+ zw7@9S+B!e4X<7VqT($E|c2vru?){}B`)$hxhF=`bdR|dUd-doFhBHX||ddJGkQT4I}AeYWact^SbcNnIw|&Hh3}U?aH;F-uTSB^3ajBsBoiz{=0`s`zvsizb`&etB^JKd=KNN=Dm|uDmjxHT`YPagEbn$^^sNVL z6;no{yB34nf1+k=ra-ALz0%r$I^OxcYR^%;eOsl9Xm*|f^7{OsK4UN-J&tya3H^S(*2zwhuZPSvgce)a6%70?hY zAxgr!C{=gq*hl5Y6&JNmO0ssz?Aw?Qg#Fsj47PHD!N)0!CGn$pEjQP8R70qXWV656 z=+~t8OaICem_r>bKBy*I&&yRTlFSgqK<>0!i}beJXGE6of65 zVk)txWPzMMwhoBQ06VLQaTy*^8Ul(#G-J!4sPPn|+}>5nAQKZ&<*dqZrXh8m;yL+V zX?@MK{sR1{Ee4-WB~QD;Y6(ZAJoT}@b{;itN{v=JM_}1HlHha|FqtRJ1GAin`9%^( zsM(`AUJ@>6$_d zN-D4*_?jv;aUy9qB(9)eswbGLgpd%Nm9`wwj85jGdEXw)HuaXd1~)8y_3q&_F>+g? z;(C8l*U{-;SscN?x`j+8fmlL9PtpXR9jKR2_MIc=g9&)QGtJkn`C^ zk>qR2kfJmx&Kum=LAj(g`dPy?@aZn?_Qx2uj*!OL`8l_@C0FOV0fl6joodq)3RX3t{mO<{=wJ_zp{zT3QCbihzl?rk(eIS)qKcakNon0ybwq)72 zlRlT6jozQt+|4XF(eUiQdEu3vnnAy3h4C}m>CoJ?P0>kvxAy*hp$t{wfcOISdxI7N zQ9OVbBvLbFo859P4A29c5^2@xR~DKAZ#?`YJCjH*KmOO0+QkS|dD{2T^;?H{s@1ZU zvUA*V9T{8Q>KNw=X@Py?Jw)=2EqzmGMW6imm@^`&g=? zqFcfCy6*M%h#nJn-35a>hnTB&+bMdcbj{Rd`n@;>^7&SxVv|U`s={meZy&R-&YO81 zc{=~b^Mbz|NStumv7{(2&}|baB~ff`q`AvweIA5=d`Mn=W2HxK=DU{BB^Q-N554&^ z)2G7a{2VGPq(4xg*eEh575~b@fie|fnWfWT>JqQ&-jA%&trFTfsxDiR73lh}o_#;i zVoHZM4)-2TIc&x#^I`bX$VNC}~J6%96SB)zY+5XP>(a>?h)`DOp5&D+B@J^o^$-4@qb5ccPr<+c{Z$C>1fu zz)gAbo;j*ja|Mkv-3*3T-s#3O2xDzGZm&5gUd+aCcFigr8b61&Evi!e^rtJKd3N`x z8-80+wp^2#>LRCz=6~5Q^Vpbn$_bj81XDn-=Gar;B<;F`_@4JZe{54ODp}yJhPBzX zrDza2@%5|Q7V_aZqqo+?;-HbiZ=i@?X$|lJy?YS%7O+MZWn4-Gm0554j!^1gvmFiB06G2<`bZ2UPVm%`&O2DZN=&@i$Oq(P`3=1 zUz1m~2i`pGxv!R{)2#RQ8HHULBpAU0K)w_tW6t&3W`5oOUem27%?IE?j^Hb){nwG; z77EA_S{5?+TGz{W{ZWLtii#wHsa7?r8%(^n^`8$DTVSBB0nKh73Gm=rk!dP|4KNK5 zimDitZl&ZOm80f~t98}zj13r(_N}6361okE&9*`6XQAXqj{3Io2A-=Iy`kjfS3 zjLs1P=s9I&&X_VQ7B9z24eo5`tXx?jAt~I8AN9bpxD5oBmuF-YC!oj$)Hj{WDPyq^ zjlDXMM$)L16^oVaXH^Eb!V?B_h%vne0rMdPRgKg5$OyU`T#CeFK}0u19`Uls<>|+X z;`jWw_bUcEG_M?en=xK|&Q{CsUe8l6Rd-~orM||H6xt6Y>;OVpmjIK4HTKV!mws~_cHJmE${t_j3`3Lf)5$w$ zE}27ng?Mo;9c5jWSyx}XKAXj!qcpQ#DYVKm+~_tf_CvP-_D3fL-`8R;sBjL$6#PDH zCu~|wm$*nCdfuBQ(TShDeUxnT5b)+#siA9tMq)C=22{gcM~{VpCx%$vPn!u1e0JL50KWLc^Om#fYorS4^9SeKZe zdDKGW{_$K>Qf;)G5J6Thh=tw^7km0};UGw}Dq*9#TI;s2n-c%Gzj@|fo-=+hGeO>N z9!&mzryQoT?$hqs%?sXn1Uvl1c>C*aPelz>kJZa+>OrD@p^A~$f&1V7xZaBAm7(S| zTAtWw1Wg1paNks1T`+-LLYes{xSHYhS&J>h1_Go zuuYR!LwQi9RE-}K`&J?*c{ zjRa=pYbcR9wy<ThL8-rIIc4p?rMuXM)lO7JhZe*0YX?WfF5=62U4&?xGg ze%FF2aoPaj{HjKNn^d5Z6{tx&{LryPW=BSTsLFkoxP&*Z2P~FBPWZYVD7Sh`SS_Dc z7+lwNZtD!V`tu6KbyM1-)$!8Bj6_e(g{?&wIjbh%bB3P~{@KLJ(t9mXU2}Kh1fXtl z6uaT$lSt01_FNto=;+z?V;T1U`BR?rNbN`0eY3c=tMKuy6O}7mrpkD>gIQ36#1;|e zuc(zSBR$)9SvKXu@YTyJ7h~=8gB0YdIv#Smo-&S4P#4DxhvP1*hN{8sBzhh67KYlp zF1nRrz7{nu74LL&=1%534?WTQ7cvN#aKGu~?5@ z0495TRCrZ^WApNsxo`W_)NG!v0A+Kd_OCtmk6k@a2W@L`QNqBU@}$2+{YFwTa|MVhR9H#X(!2Gr%Fpc^=1A)=iX-n3 zExvnb+=U)kIC1{v|-haXS#7(Bx!d*|QOh4X<)KX5{|QRD6R>k0?W$3=KXE7!P| zpDEZbr>&F4XpfehM@<&sOJ%jP?N#Q2E~c?akCWkrD7%m?cykO}amxYUFzHbF{QFYV z@1T$OuWy|}XUyU}3L2j@cTXMa5%4V5)~fgy(Ec@)n3ot)ESOu7Em6_~f^pQqWDX`M zhc>{`u~uts3-+Ff1~Ffy`=jLSrkl?WMfS>}>CP-^F>&!r=%v z3_-ZBuhEvy6!y0z2Q@^hsx_fnz=3pbTC?*gs*mdhrh(X2;@TXjiV!amuHwvT zLpVs}4ca@0SbG(!@ob%0Y!nBBLZdnV3s;*Z1qVA1rw_PN#x<&2Ot!}GW;cEBMh2@% zfJh7o7>S0Zq(GDumB2_O4As{Wn4H%1q3YV?rtECzVDpI&%4IK;@*ohB?6 zZ7Xb7n!8?XHKJI4|E}+yD%j!kF7Xd+9wjWBY%^6E5t{mgJ=pOE(UGBi!QA02(j)fb zA%GES_};4Z{JX(rO$a%#LoFbzy;@cs%%*vaf=|&ren`9CV6Uf!Hnp>ipVJ)2Bu}cC zE7<;(V`+Rh7WT}}s5rLKV%|Io-fE_ex_O(nZ3Xn+=yYsc5UgeU6v~2c`@f0(KF6|K z-#w?LFM-(V_S1htA|`?~@8Z@9JY;&K{7n8oQ2z%ZSp#SayZrlg(a zn=X<~sqWtHKpU^SrX>c5%xv)QIKiJ+uBMN0Bjgp;B>gR=k60zl_}^@73^#yg`Q3C} zQKY$7SF$64FELtzxu0F0gQiXg*=hDI9y^%(*X_4^rh8I8=y6Z}^($$xGY5tFMckDy ztj`o)P^hN#BR9(51!cW@1SlTTwqAC&0QZQN>WLF5b#_lP@58_3HrddM$-Dd-eYs-n zhM9K^aKPC7Y4A!KzpwumH;BQ?zp0#1F7&ZfiL3g;`N00}Swq23U*6A5DWv&FFHE&- zB>*b?`4B?D^J~b!Fi~W=$~6Udf-<4}m>?k8bMtKF#hG6s)7ejZ6O0lmI;)UFMT)0I zJpzk2)DBo1Ax`}Z=fF?Y-U0MVHsonLZ1P&^%fnUc;J464j;ZuDYc@MR-9P6R3j#RGde zI}vd{B7K8>1dMKugz$hfITuY=13RPhIoY`ZSZ-@&i&HEiYIL@inC;7IOt(^jWmAz9 z7KAE}rXqbS_*y5;1gs1C^D3qKtXmK|r;kh^=>++V#{-2|Z;I?hLTx3Ao_RgtwJlG8 z`pVb%n=#b@_w<|ehEr`0QO`s5g_T$*o|PI$NKKg-R(-gHXi?Y|+UIO$A_#u-Vl1)t zg}>;<+Lxv>#J8MMHu@t$t#<#{)B5J4IiY=x2&S%eUQGjn=JIu*%CWWN2QWWbOwX=V zTs%muDLLu4jM}*+HM10Hi=x?j%V7AE6NSA*3(HRkxtO@6RpWIprgG8OjQAfvB{%3` zd<^pT6+z+p5*HpRe|2)ng&R&@gq@arDxja9ni!+!~XfwkL<^1Iz^ z1I(i&-7RyBl#eF|T@jKU^(#Ek`R3Yjt=GCaBuDuh;Z9q18&i);#Zuxi$E}o~*O+Lw zey&6~^j0!VHAU7YroIS1(ea1JUI~`}t0X)NOoV5rm@05iE>@kI?fw+hf9*cd`mHU+ zN_+n6#{2<~=4Q~55DvA%E_2{smrlL+>~#Pu6n(pe&*$ZAiq( zR9XSm>X*D)?vCn{hyvPltYwT({7qQN(N9qjzoQ>i?pT@Y0W1ub)@mG$t2UQYTkglq1DEg2{VhF4yI~RCC99<6 zIAdJ>JN_OEY(VN*iiZ;geLoX95=C0t;|1?JaPqxPu0MSxt>eOve^U4%@^|b`m=CVX z04E*Adhp=TAUVauwSV5QHKKAOu!~2m^#*AP9uS@yK&BHZW+8*?c>< zmiV!M(QEp)6q%-kf*=)1NEGCMTl*b0n8Lk#1XeiPIDePHY+*Cq)uFzgkzp_nSOthg zIc8PDK_Cjp*%K~WhO2^}ai*7oCsd(Y8fx6;HZBIQ3`F*G;7U%CU|TX=g`s=bT@&YU z#N*y++XIIW1%esFa6Lt26f$dO^{8qQ^`J2`jWnEwfspqp_Jc`x995K}$)Fu={t@}4 z4Xdtc>#kMrI#r7?zAI9PNB6B|iub?Z7W^KUIE<3f+r{4Z7`kx^Gp8q2Ykl%f!QMEfP3rjj(TQ0v2*IN%6qvN@=Usii0u47;t1I@64Ol z1eS#1U{Cpm+@Rm*-{#VeH?B%MD%U(;ahpUP{JFu&1S=cF%}Mzy4PO}ox5s?$EH&3> zp1mS7crA8p##;8NXBV5bW_J|NUkWuT>yN3Y(X1VSjZI+*U2=qq> zb1rkOI7fRFhZ5$VLREY8PXkhD9vAUf<*u>#XSpJ0e+iSsmMhtaQ~MK|ts`~+ zldtK|Rrl;i%Uh@($2hLOU zyfj!82QdLaV4@9u)qA1b(X$)tUTW(w z7ZDs%!xaH;Pb^hwbdC7aL)a*vzaZP@dhm&X(*VPN*mW;a(@^d7^=B`z> nXZ=`pY7TmgC@kT&=1FbBG6&Zv9N!`#$-(s8lfz1U2Rr@`SaQ~x diff --git a/flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/wav-with-foreign-metadata-8bps.fuzz b/flac/oss-fuzz/seedcorpus/fuzzer_tool_flac/wav-with-foreign-metadata-8bps.fuzz deleted file mode 100644 index d708a3cb80863e1cbb14be14f1dca30e42992491..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 559 zcmbtRO-sW-5ZzWQibXvY{5TArJTy?7Qay+?CXI$RscaWLuk9uV(mUaQegq}4)P^;C$14wu;4n%^wb82j%MvsC(bfh1J5V??6z#YGxDKyH`cQ}y*Esg`f z!>|ywvDugNY_7_VCVIHbXZ5skBDi_6HIO*ew!|{SQ(GE5r2Hr7r2*{od5s; diff --git a/flac/oss-fuzz/seek.cc b/flac/oss-fuzz/seek.cc deleted file mode 100644 index d3ccbe8..0000000 --- a/flac/oss-fuzz/seek.cc +++ /dev/null @@ -1,195 +0,0 @@ -/* fuzzer_seek - * Copyright (C) 2022-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#include -#include /* for memcpy */ -#include "FLAC/stream_decoder.h" -#include "common.h" - -int write_abort_check_counter = -1; - -#if 0 /* set to 1 to debug */ -#define FPRINTF_DEBUG_ONLY(...) fprintf(__VA_ARGS__) -#else -#define FPRINTF_DEBUG_ONLY(...) -#endif - -#define CONFIG_LENGTH 2 - -static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 *const buffer[], void *client_data) -{ - (void)decoder, (void)frame, (void)buffer, (void)client_data; - if(write_abort_check_counter > 0) { - write_abort_check_counter--; - if(write_abort_check_counter == 0) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } else if(write_abort_check_counter == 0) - /* This must not happen: write callback called after abort is returned */ - abort(); - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus error, void *client_data) -{ - (void)decoder, (void)error, (void)client_data; -} - - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - FLAC__bool decoder_valid = true; - FLAC__StreamDecoder *decoder; - uint8_t command_length; - FLAC__bool init_bools[16], ogg; - - if(size > 2 && data[1] < 128) /* Use MSB as on/off */ - alloc_check_threshold = data[1]; - else - alloc_check_threshold = INT32_MAX; - alloc_check_counter = 0; - - write_abort_check_counter = -1; - - /* allocate the decoder */ - if((decoder = FLAC__stream_decoder_new()) == NULL) { - fprintf(stderr, "ERROR: allocating decoder\n"); - return 1; - } - - /* Use first byte for configuration, leave at least one byte of input */ - if(size < 1 + CONFIG_LENGTH){ - FLAC__stream_decoder_delete(decoder); - return 0; - } - - /* First 4 bits for configuration bools, next 4 for length of command section */ - for(int i = 0; i < 4; i++) - init_bools[i] = data[i/8] & (1 << (i % 8)); - - command_length = data[0] >> 4; - - /* Leave at least one byte as input */ - if(command_length >= size - 1 - CONFIG_LENGTH) - command_length = size - 1 - CONFIG_LENGTH; - - /* Dump decoder input to file */ - { - FILE * file_to_decode = fopen("/tmp/tmp.flac","w"); - fwrite(data+CONFIG_LENGTH+command_length,1,size-CONFIG_LENGTH-command_length,file_to_decode); - fclose(file_to_decode); - } - - ogg = init_bools[0]; - - FLAC__stream_decoder_set_md5_checking(decoder,init_bools[1]); - if(init_bools[2]) - FLAC__stream_decoder_set_metadata_respond_all(decoder); - if(init_bools[3]) - FLAC__stream_decoder_set_metadata_ignore_all(decoder); - - /* initialize decoder */ - if(decoder_valid) { - FLAC__StreamDecoderInitStatus init_status; - if(ogg) - init_status = FLAC__stream_decoder_init_ogg_file(decoder, "/tmp/tmp.flac", write_callback, NULL, error_callback, NULL); - else - init_status = FLAC__stream_decoder_init_file(decoder, "/tmp/tmp.flac", write_callback, NULL, error_callback, NULL); - if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - decoder_valid = false; - } - } - - /* Run commands */ - for(uint8_t i = 0; decoder_valid && (i < command_length); i++){ - const uint8_t * command = data+CONFIG_LENGTH+i; - uint8_t shift = 1u << (command[0] >> 3); - FLAC__uint64 seekpos; - - switch(command[0] & 15){ - case 0: - FPRINTF_DEBUG_ONLY(stderr,"end_of_stream\n"); - decoder_valid = FLAC__stream_decoder_process_until_end_of_stream(decoder); - break; - case 1: - FPRINTF_DEBUG_ONLY(stderr,"end_of_metadata\n"); - decoder_valid = FLAC__stream_decoder_process_until_end_of_metadata(decoder); - break; - case 2: - FPRINTF_DEBUG_ONLY(stderr,"single\n"); - decoder_valid = FLAC__stream_decoder_process_single(decoder); - break; - case 3: - FPRINTF_DEBUG_ONLY(stderr,"skip_single\n"); - decoder_valid = FLAC__stream_decoder_skip_single_frame(decoder); - break; - case 4: - FPRINTF_DEBUG_ONLY(stderr,"reset\n"); - decoder_valid = FLAC__stream_decoder_reset(decoder); - break; - case 5: - FPRINTF_DEBUG_ONLY(stderr,"flush\n"); - decoder_valid = FLAC__stream_decoder_flush(decoder); - break; - case 6: - case 14: - shift = 1u << (command[0] >> 3); - FPRINTF_DEBUG_ONLY(stderr,"seek short %hhu\n",shift); - decoder_valid = FLAC__stream_decoder_seek_absolute(decoder,shift); - break; - case 7: - if(i+8 >= command_length) /* Not enough data available to do this */ - break; - seekpos = ((FLAC__uint64)command[1] << 56) + - ((FLAC__uint64)command[2] << 48) + - ((FLAC__uint64)command[3] << 40) + - ((FLAC__uint64)command[4] << 32) + - ((FLAC__uint64)command[5] << 24) + - ((FLAC__uint64)command[6] << 16) + - ((FLAC__uint64)command[7] << 8) + - command[8]; - i+=8; - FPRINTF_DEBUG_ONLY(stderr,"seek long %lu\n",seekpos); - decoder_valid = FLAC__stream_decoder_seek_absolute(decoder,seekpos); - break; - case 8: - /* Set abort on write callback */ - write_abort_check_counter = (command[0] >> 4) + 1; - break; - } - } - - FLAC__stream_decoder_finish(decoder); - - FLAC__stream_decoder_delete(decoder); - - return 0; -} - diff --git a/flac/oss-fuzz/tool_flac.c b/flac/oss-fuzz/tool_flac.c deleted file mode 100644 index ce10a07..0000000 --- a/flac/oss-fuzz/tool_flac.c +++ /dev/null @@ -1,117 +0,0 @@ -/* fuzzer_tool_flac - * Copyright (C) 2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#include -#include /* for memcpy */ -#define FUZZ_TOOL_FLAC -#define fprintf(...) -#define printf(...) -#include "../src/flac/main.c" -#include "common.h" - -int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); - -int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - size_t size_left = size; - size_t arglen; - char * argv[67]; - char exename[] = "flac"; - char filename[] = "/tmp/fuzzXXXXXX"; - int numarg = 0, maxarg; - int file_to_fuzz; - int tmp_stdout, tmp_stdin; - fpos_t pos_stdout; - bool use_stdin = false; - - /* reset global vars */ - flac__utils_verbosity_ = 0; - share__opterr = 0; - share__optind = 0; - - if(size < 2) - return 0; - - maxarg = data[0] & 63; - use_stdin = data[0] & 64; - size_left--; - - argv[0] = exename; - numarg++; - - /* Check whether input is zero delimited */ - while((arglen = strnlen((char *)data+(size-size_left),size_left)) < size_left && numarg < maxarg) { - argv[numarg++] = (char *)data+(size-size_left); - size_left -= arglen + 1; - } - - file_to_fuzz = mkstemp(filename); - - if (file_to_fuzz < 0) - abort(); - write(file_to_fuzz,data+(size-size_left),size_left); - close(file_to_fuzz); - - /* redirect stdout */ - fflush(stdout); - fgetpos(stdout,&pos_stdout); - tmp_stdout = dup(fileno(stdout)); - freopen("/dev/null","w",stdout); - - /* redirect stdin */ - tmp_stdin = dup(fileno(stdin)); - - if(use_stdin) - freopen(filename,"r",stdin); - else { - freopen("/dev/null","r",stdin); - argv[numarg++] = filename; - } - - main_to_fuzz(numarg,argv); - - /* restore stdout */ - fflush(stdout); - dup2(tmp_stdout, fileno(stdout)); - close(tmp_stdout); - clearerr(stdout); - fsetpos(stdout,&pos_stdout); - - /* restore stdin */ - dup2(tmp_stdin, fileno(stdin)); - close(tmp_stdin); - clearerr(stdin); - - unlink(filename); - - return 0; -} - diff --git a/flac/oss-fuzz/tool_metaflac.c b/flac/oss-fuzz/tool_metaflac.c deleted file mode 100644 index a6fafa2..0000000 --- a/flac/oss-fuzz/tool_metaflac.c +++ /dev/null @@ -1,136 +0,0 @@ -/* fuzzer_tool_flac - * Copyright (C) 2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#include -#include -#include /* for memcpy */ -#define FUZZ_TOOL_METAFLAC -#define fprintf(...) -#define printf(...) -#include "../src/metaflac/main.c" -#include "common.h" - -int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); - -int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - size_t size_left = size; - size_t arglen; - char * argv[64]; - char exename[] = "metaflac"; - char filename[] = "/tmp/fuzzXXXXXX"; - char filename_stdin[] = "/tmp/fuzzXXXXXX"; - int numarg = 0, maxarg; - int file_to_fuzz; - int tmp_stdout, tmp_stdin; - fpos_t pos_stdout; - bool use_stdin = false; - - share__opterr = 0; - share__optind = 0; - - - if(size < 2) - return 0; - - maxarg = data[0] & 15; - use_stdin = data[0] & 16; - size_left--; - - argv[0] = exename; - numarg++; - - /* Check whether input is zero delimited */ - while((arglen = strnlen((char *)data+(size-size_left),size_left)) < size_left && numarg < maxarg) { - argv[numarg++] = (char *)data+(size-size_left); - size_left -= arglen + 1; - } - - /* Create file to feed directly */ - file_to_fuzz = mkstemp(filename); - if (file_to_fuzz < 0) - abort(); - if(use_stdin) { - write(file_to_fuzz,data+(size-size_left),size_left/2); - size_left -= size_left/2; - } - else - write(file_to_fuzz,data+(size-size_left),size_left); - close(file_to_fuzz); - - argv[numarg++] = filename; - - /* Create file to feed to stdin */ - if(use_stdin) { - file_to_fuzz = mkstemp(filename_stdin); - if (file_to_fuzz < 0) - abort(); - write(file_to_fuzz,data+(size-size_left),size_left); - close(file_to_fuzz); - } - - /* redirect stdout */ - fflush(stdout); - fgetpos(stdout,&pos_stdout); - tmp_stdout = dup(fileno(stdout)); - freopen("/dev/null","w",stdout); - - /* redirect stdin */ - tmp_stdin = dup(fileno(stdin)); - if(use_stdin) - freopen(filename_stdin,"r",stdin); - else { - freopen("/dev/null","r",stdin); - argv[numarg++] = filename; - } - - main_to_fuzz(numarg,argv); - - /* restore stdout */ - fflush(stdout); - dup2(tmp_stdout, fileno(stdout)); - close(tmp_stdout); - clearerr(stdout); - fsetpos(stdout,&pos_stdout); - - /* restore stdin */ - dup2(tmp_stdin, fileno(stdin)); - close(tmp_stdin); - clearerr(stdin); - - unlink(filename); - - if(use_stdin) - unlink(filename_stdin); - - return 0; -} - diff --git a/flac/src/CMakeLists.txt b/flac/src/CMakeLists.txt deleted file mode 100644 index 262feea..0000000 --- a/flac/src/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_minimum_required(VERSION 3.11) - -option(ENABLE_64_BIT_WORDS "Set FLAC__BYTES_PER_WORD to 8, for 64-bit machines. For 32-bit machines, turning this off might give a tiny speed improvement" ON) -option(BUILD_UTILS "Build utils" OFF) - -add_subdirectory("libFLAC") -if(BUILD_CXXLIBS) - add_subdirectory("libFLAC++") -endif() -add_subdirectory("share/replaygain_analysis") -add_subdirectory("share/replaygain_synthesis") -add_subdirectory("share/getopt") -add_subdirectory("share/utf8") -add_subdirectory("share/grabbag") - -if(BUILD_PROGRAMS) - add_subdirectory("flac") - add_subdirectory("metaflac") -endif() -if(BUILD_UTILS) - add_subdirectory(utils/flacdiff) - if(WIN32) - add_subdirectory(utils/flactimer) - endif() -endif() - -if(BUILD_TESTING) - add_subdirectory("test_libs_common") - add_subdirectory("test_libFLAC") - if(BUILD_CXXLIBS) - add_subdirectory("test_libFLAC++") - endif() - add_subdirectory("test_grabbag") - add_subdirectory("test_seeking") - add_subdirectory("test_streams") -endif() diff --git a/flac/src/Makefile.am b/flac/src/Makefile.am deleted file mode 100644 index e9d60a9..0000000 --- a/flac/src/Makefile.am +++ /dev/null @@ -1,40 +0,0 @@ -# FLAC - Free Lossless Audio Codec -# Copyright (C) 2001-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# This file is part the FLAC project. FLAC is comprised of several -# components distributed under different licenses. The codec libraries -# are distributed under Xiph.Org's BSD-like license (see the file -# COPYING.Xiph in this distribution). All other programs, libraries, and -# plugins are distributed under the GPL (see COPYING.GPL). The documentation -# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the -# FLAC distribution contains at the top the terms under which it may be -# distributed. -# -# Since this particular file is relevant to all components of FLAC, -# it may be distributed under the Xiph.Org license, which is the least -# restrictive of those mentioned above. See the file COPYING.Xiph in this -# distribution. - -if FLaC__WITH_CPPLIBS -CPPLIBS_DIRS = libFLAC++ test_libFLAC++ -endif - -if FLaC__WITH_PROGRAMS -PROGRAMS_DIRS = flac metaflac -endif - -SUBDIRS = \ - libFLAC \ - share \ - $(PROGRAMS_DIRS) \ - test_grabbag \ - test_libs_common \ - test_libFLAC \ - test_seeking \ - test_streams \ - utils \ - $(CPPLIBS_DIRS) - -EXTRA_DIST = \ - CMakeLists.txt diff --git a/flac/src/flac/CMakeLists.txt b/flac/src/flac/CMakeLists.txt deleted file mode 100644 index da7ce8d..0000000 --- a/flac/src/flac/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H) -check_include_file("termios.h" HAVE_TERMIOS_H) - -add_executable(flacapp - analyze.c - decode.c - encode.c - foreign_metadata.c - main.c - local_string_utils.c - utils.c - vorbiscomment.c - version.rc - $<$:../../include/share/win_utf8_io.h> - $<$:../share/win_utf8_io/win_utf8_io.c>) -set_property(TARGET flacapp PROPERTY RUNTIME_OUTPUT_NAME flac) -set_property(TARGET flacapp PROPERTY PROJECT_LABEL "flac") -target_link_libraries(flacapp - FLAC - getopt - replaygain_synthesis - utf8) - -install(TARGETS flacapp EXPORT targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") diff --git a/flac/src/flac/Makefile.am b/flac/src/flac/Makefile.am deleted file mode 100644 index 279a7cb..0000000 --- a/flac/src/flac/Makefile.am +++ /dev/null @@ -1,69 +0,0 @@ -# flac - Command-line FLAC encoder/decoder -# Copyright (C) 2000-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -if OS_IS_WINDOWS -win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la -if HAVE_WINDRES -flac_DEPENDENCIES = version.o -windows_resource_link = -Wl,version.o -endif -endif - -bin_PROGRAMS = flac - -AM_CFLAGS = @OGG_CFLAGS@ -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include -EXTRA_DIST = \ - CMakeLists.txt \ - iffscan.c \ - version.rc - -flac_SOURCES = \ - analyze.c \ - decode.c \ - encode.c \ - foreign_metadata.c \ - main.c \ - local_string_utils.c \ - utils.c \ - vorbiscomment.c \ - analyze.h \ - decode.h \ - encode.h \ - foreign_metadata.h \ - local_string_utils.h \ - utils.h \ - vorbiscomment.h - -flac_LDADD = \ - $(top_builddir)/src/share/utf8/libutf8.la \ - $(top_builddir)/src/share/grabbag/libgrabbag.la \ - $(top_builddir)/src/share/getopt/libgetopt.la \ - $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/share/replaygain_synthesis/libreplaygain_synthesis.la \ - $(top_builddir)/src/libFLAC/libFLAC.la \ - $(win_utf8_lib) \ - @LTLIBICONV@ \ - -lm - -flac_LDFLAGS = $(AM_LDFLAGS) $(windows_resource_link) - -CLEANFILES = flac.exe - -.rc.o: - $(RC) $(AM_CPPFLAGS) $< $@ diff --git a/flac/src/flac/analyze.c b/flac/src/flac/analyze.c deleted file mode 100644 index 0a85565..0000000 --- a/flac/src/flac/analyze.c +++ /dev/null @@ -1,252 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include - -#include "FLAC/all.h" -#include "analyze.h" - -#include "share/compat.h" - -typedef struct { - FLAC__int32 residual; - uint32_t count; -} pair_t; - -typedef struct { - pair_t buckets[FLAC__MAX_BLOCK_SIZE]; - int peak_index; - uint32_t nbuckets; - uint32_t nsamples; - double sum, sos; - double variance; - double mean; - double stddev; -} subframe_stats_t; - -static subframe_stats_t all_; - -static void init_stats(subframe_stats_t *stats); -static void update_stats(subframe_stats_t *stats, FLAC__int32 residual, uint32_t incr); -static void compute_stats(subframe_stats_t *stats); -static FLAC__bool dump_stats(const subframe_stats_t *stats, const char *filename); - -void flac__analyze_init(analysis_options aopts) -{ - if(aopts.do_residual_gnuplot) { - init_stats(&all_); - } -} - -void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__uint64 frame_offset, FLAC__uint64 frame_bytes, analysis_options aopts, FILE *fout) -{ - const uint32_t channels = frame->header.channels; - char outfilename[1024]; - subframe_stats_t stats; - uint32_t i, channel, partitions; - - /* do the human-readable part first */ - fprintf(fout, "frame=%u\toffset=%" PRIu64 "\tbits=%" PRIu64 "\tblocksize=%u\tsample_rate=%u\tchannels=%u\tchannel_assignment=%s\n", frame_number, frame_offset, frame_bytes*8, frame->header.blocksize, frame->header.sample_rate, channels, FLAC__ChannelAssignmentString[frame->header.channel_assignment]); - for(channel = 0; channel < channels; channel++) { - const FLAC__Subframe *subframe = frame->subframes+channel; - const FLAC__bool is_rice2 = subframe->data.fixed.entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2; - const uint32_t pesc = is_rice2? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER; - fprintf(fout, "\tsubframe=%u\twasted_bits=%u\ttype=%s", channel, subframe->wasted_bits, FLAC__SubframeTypeString[subframe->type]); - switch(subframe->type) { - case FLAC__SUBFRAME_TYPE_CONSTANT: - fprintf(fout, "\tvalue=%" PRId64 "\n", subframe->data.constant.value); - break; - case FLAC__SUBFRAME_TYPE_FIXED: - FLAC__ASSERT(subframe->data.fixed.entropy_coding_method.type <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2); - fprintf(fout, "\torder=%u\tresidual_type=%s\tpartition_order=%u\n", subframe->data.fixed.order, is_rice2? "RICE2":"RICE", subframe->data.fixed.entropy_coding_method.data.partitioned_rice.order); - for(i = 0; i < subframe->data.fixed.order; i++) - fprintf(fout, "\t\twarmup[%u]=%" PRId64 "\n", i, subframe->data.fixed.warmup[i]); - partitions = (1u << subframe->data.fixed.entropy_coding_method.data.partitioned_rice.order); - for(i = 0; i < partitions; i++) { - uint32_t parameter = subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents->parameters[i]; - if(parameter == pesc) - fprintf(fout, "\t\tparameter[%u]=ESCAPE, raw_bits=%u\n", i, subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents->raw_bits[i]); - else - fprintf(fout, "\t\tparameter[%u]=%u\n", i, parameter); - } - if(aopts.do_residual_text) { - for(i = 0; i < frame->header.blocksize-subframe->data.fixed.order; i++) - fprintf(fout, "\t\tresidual[%u]=%d\n", i, subframe->data.fixed.residual[i]); - } - break; - case FLAC__SUBFRAME_TYPE_LPC: - FLAC__ASSERT(subframe->data.lpc.entropy_coding_method.type <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2); - fprintf(fout, "\torder=%u\tqlp_coeff_precision=%u\tquantization_level=%d\tresidual_type=%s\tpartition_order=%u\n", subframe->data.lpc.order, subframe->data.lpc.qlp_coeff_precision, subframe->data.lpc.quantization_level, is_rice2? "RICE2":"RICE", subframe->data.lpc.entropy_coding_method.data.partitioned_rice.order); - for(i = 0; i < subframe->data.lpc.order; i++) - fprintf(fout, "\t\tqlp_coeff[%u]=%d\n", i, subframe->data.lpc.qlp_coeff[i]); - for(i = 0; i < subframe->data.lpc.order; i++) - fprintf(fout, "\t\twarmup[%u]=%" PRId64 "\n", i, subframe->data.lpc.warmup[i]); - partitions = (1u << subframe->data.lpc.entropy_coding_method.data.partitioned_rice.order); - for(i = 0; i < partitions; i++) { - uint32_t parameter = subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents->parameters[i]; - if(parameter == pesc) - fprintf(fout, "\t\tparameter[%u]=ESCAPE, raw_bits=%u\n", i, subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents->raw_bits[i]); - else - fprintf(fout, "\t\tparameter[%u]=%u\n", i, parameter); - } - if(aopts.do_residual_text) { - for(i = 0; i < frame->header.blocksize-subframe->data.lpc.order; i++) - fprintf(fout, "\t\tresidual[%u]=%d\n", i, subframe->data.lpc.residual[i]); - } - break; - case FLAC__SUBFRAME_TYPE_VERBATIM: - fprintf(fout, "\n"); - break; - } - } - - /* now do the residual distributions if requested */ - if(aopts.do_residual_gnuplot) { - for(channel = 0; channel < channels; channel++) { - const FLAC__Subframe *subframe = frame->subframes+channel; - uint32_t residual_samples; - - init_stats(&stats); - - switch(subframe->type) { - case FLAC__SUBFRAME_TYPE_FIXED: - residual_samples = frame->header.blocksize - subframe->data.fixed.order; - for(i = 0; i < residual_samples; i++) - update_stats(&stats, subframe->data.fixed.residual[i], 1); - break; - case FLAC__SUBFRAME_TYPE_LPC: - residual_samples = frame->header.blocksize - subframe->data.lpc.order; - for(i = 0; i < residual_samples; i++) - update_stats(&stats, subframe->data.lpc.residual[i], 1); - break; - default: - break; - } - - /* update all_ */ - for(i = 0; i < stats.nbuckets; i++) { - update_stats(&all_, stats.buckets[i].residual, stats.buckets[i].count); - } - - if(stats.nsamples > 0) { - /* write the subframe */ - flac_snprintf(outfilename, sizeof (outfilename), "f%06u.s%u.gp", frame_number, channel); - compute_stats(&stats); - - (void)dump_stats(&stats, outfilename); - } - } - } -} - -void flac__analyze_finish(analysis_options aopts) -{ - if(aopts.do_residual_gnuplot && all_.nsamples > 0) { - compute_stats(&all_); - (void)dump_stats(&all_, "all"); - } -} - -void init_stats(subframe_stats_t *stats) -{ - stats->peak_index = -1; - stats->nbuckets = 0; - stats->nsamples = 0; - stats->sum = 0.0; - stats->sos = 0.0; -} - -void update_stats(subframe_stats_t *stats, FLAC__int32 residual, uint32_t incr) -{ - uint32_t i; - const double r = (double)residual, a = r*incr; - - stats->nsamples += incr; - stats->sum += a; - stats->sos += (a*r); - - for(i = 0; i < stats->nbuckets; i++) { - if(stats->buckets[i].residual == residual) { - stats->buckets[i].count += incr; - goto find_peak; - } - } - /* not found, make a new bucket */ - i = stats->nbuckets; - stats->buckets[i].residual = residual; - stats->buckets[i].count = incr; - stats->nbuckets++; -find_peak: - if(stats->peak_index < 0 || stats->buckets[i].count > stats->buckets[stats->peak_index].count) - stats->peak_index = i; -} - -void compute_stats(subframe_stats_t *stats) -{ - stats->mean = stats->sum / (double)stats->nsamples; - stats->variance = (stats->sos - (stats->sum * stats->sum / stats->nsamples)) / stats->nsamples; - stats->stddev = sqrt(stats->variance); -} - -FLAC__bool dump_stats(const subframe_stats_t *stats, const char *filename) -{ - FILE *outfile; - uint32_t i; - const double m = stats->mean; - const double s1 = stats->stddev, s2 = s1*2, s3 = s1*3, s4 = s1*4, s5 = s1*5, s6 = s1*6; - const double p = stats->buckets[stats->peak_index].count; - - outfile = flac_fopen(filename, "w"); - - if(0 == outfile) { - fprintf(stderr, "ERROR opening %s: %s\n", filename, strerror(errno)); - return false; - } - - fprintf(outfile, "plot '-' title 'PDF', '-' title 'mean' with impulses, '-' title '1-stddev' with histeps, '-' title '2-stddev' with histeps, '-' title '3-stddev' with histeps, '-' title '4-stddev' with histeps, '-' title '5-stddev' with histeps, '-' title '6-stddev' with histeps\n"); - - for(i = 0; i < stats->nbuckets; i++) { - fprintf(outfile, "%d %u\n", stats->buckets[i].residual, stats->buckets[i].count); - } - fprintf(outfile, "e\n"); - - fprintf(outfile, "%f %f\ne\n", stats->mean, p); - fprintf(outfile, "%f %f\n%f %f\ne\n", m-s1, p*0.8, m+s1, p*0.8); - fprintf(outfile, "%f %f\n%f %f\ne\n", m-s2, p*0.7, m+s2, p*0.7); - fprintf(outfile, "%f %f\n%f %f\ne\n", m-s3, p*0.6, m+s3, p*0.6); - fprintf(outfile, "%f %f\n%f %f\ne\n", m-s4, p*0.5, m+s4, p*0.5); - fprintf(outfile, "%f %f\n%f %f\ne\n", m-s5, p*0.4, m+s5, p*0.4); - fprintf(outfile, "%f %f\n%f %f\ne\n", m-s6, p*0.3, m+s6, p*0.3); - - fprintf(outfile, "pause -1 'waiting...'\n"); - - fclose(outfile); -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - unlink(filename); -#endif - return true; -} diff --git a/flac/src/flac/analyze.h b/flac/src/flac/analyze.h deleted file mode 100644 index ce07b14..0000000 --- a/flac/src/flac/analyze.h +++ /dev/null @@ -1,32 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 flac__analyze_h -#define flac__analyze_h - -typedef struct { - FLAC__bool do_residual_text; - FLAC__bool do_residual_gnuplot; -} analysis_options; - -void flac__analyze_init(analysis_options aopts); -void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__uint64 frame_offset, FLAC__uint64 frame_bytes, analysis_options aopts, FILE *fout); -void flac__analyze_finish(analysis_options aopts); - -#endif diff --git a/flac/src/flac/decode.c b/flac/src/flac/decode.c deleted file mode 100644 index 90f7a6c..0000000 --- a/flac/src/flac/decode.c +++ /dev/null @@ -1,1674 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include /* for floor() */ -#include /* for FILE etc. */ -#include /* for strcmp(), strerror() */ -#include /* for clock() */ -#include "FLAC/all.h" -#include "share/grabbag.h" -#include "share/replaygain_synthesis.h" -#include "share/compat.h" -#include "decode.h" - -typedef struct { -#if FLAC__HAS_OGG - FLAC__bool is_ogg; - FLAC__bool use_first_serial_number; - long serial_number; -#endif - - FileFormat format; - FileSubFormat subformat; - FLAC__bool treat_warnings_as_errors; - FLAC__bool continue_through_decode_errors; - FLAC__bool channel_map_none; - FLAC__bool relaxed_foreign_metadata_handling; - - struct { - replaygain_synthesis_spec_t spec; - FLAC__bool apply; /* 'spec.apply' is just a request; this 'apply' means we actually parsed the RG tags and are ready to go */ - double scale; - DitherContext dither_context; - } replaygain; - - FLAC__bool test_only; - FLAC__bool analysis_mode; - analysis_options aopts; - utils__SkipUntilSpecification *skip_specification; - utils__SkipUntilSpecification *until_specification; /* a canonicalized value of 0 mean end-of-stream (i.e. --until=-0) */ - utils__CueSpecification *cue_specification; - - const char *inbasefilename; - const char *infilename; - const char *outfilename; - - FLAC__uint64 samples_processed; - uint32_t frame_counter; - FLAC__bool abort_flag; - FLAC__bool aborting_due_to_until; /* true if we intentionally abort decoding prematurely because we hit the --until point */ - FLAC__bool aborting_due_to_unparseable; /* true if we abort decoding because we hit an unparseable frame */ - FLAC__bool error_callback_suppress_messages; /* turn on to prevent repeating messages from the error callback */ - FLAC__bool warn_user_about_foreign_metadata; /* to prevent more than one warning message per file */ - - FLAC__bool iff_headers_need_fixup; - - FLAC__bool is_big_endian; - FLAC__bool is_unsigned_samples; - FLAC__bool got_stream_info; - FLAC__bool has_md5sum; - FLAC__uint64 total_samples; - uint32_t bps; - uint32_t channels; - uint32_t sample_rate; - FLAC__uint32 channel_mask; - - /* these are used only in analyze mode */ - FLAC__uint64 decode_position; - - FLAC__StreamDecoder *decoder; - - FILE *fout; - - foreign_metadata_t *foreign_metadata; /* NULL unless --keep-foreign-metadata requested */ - FLAC__off_t fm_offset1, fm_offset2, fm_offset3; - - clock_t old_clock_t; -} DecoderSession; - - -static FLAC__bool is_big_endian_host_; - - -/* - * local routines - */ -static FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__bool use_first_serial_number, long serial_number, FileFormat format, FileSubFormat subformat, FLAC__bool treat_warnings_as_errors, FLAC__bool continue_through_decode_errors, FLAC__bool channel_map_none, FLAC__bool relaxed_foreign_metadata_handling, replaygain_synthesis_spec_t replaygain_synthesis_spec, FLAC__bool analysis_mode, analysis_options aopts, utils__SkipUntilSpecification *skip_specification, utils__SkipUntilSpecification *until_specification, utils__CueSpecification *cue_specification, foreign_metadata_t *foreign_metadata, const char *infilename, const char *outfilename); -static void DecoderSession_destroy(DecoderSession *d, FLAC__bool error_occurred); -static FLAC__bool DecoderSession_init_decoder(DecoderSession *d, const char *infilename); -static FLAC__bool DecoderSession_process(DecoderSession *d); -static int DecoderSession_finish_ok(DecoderSession *d); -static int DecoderSession_finish_error(DecoderSession *d); -static FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, uint32_t sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input); -static FLAC__bool write_iff_headers(FILE *f, DecoderSession *decoder_session, FLAC__uint64 samples); -static FLAC__bool write_riff_wave_fmt_chunk_body(FILE *f, FLAC__bool is_waveformatextensible, uint32_t bps, uint32_t channels, uint32_t sample_rate, FLAC__uint32 channel_mask); -static FLAC__bool write_aiff_form_comm_chunk(FILE *f, FLAC__uint64 samples, uint32_t bps, uint32_t channels, uint32_t sample_rate, FileFormat format, FileSubFormat subformat, FLAC__uint32 comm_length); -static FLAC__bool write_little_endian_uint16(FILE *f, FLAC__uint16 val); -static FLAC__bool write_little_endian_uint32(FILE *f, FLAC__uint32 val); -static FLAC__bool write_little_endian_uint64(FILE *f, FLAC__uint64 val); -static FLAC__bool write_big_endian_uint16(FILE *f, FLAC__uint16 val); -static FLAC__bool write_big_endian_uint32(FILE *f, FLAC__uint32 val); -static FLAC__bool write_sane_extended(FILE *f, uint32_t val); -static FLAC__bool fixup_iff_headers(DecoderSession *d); -static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); -static void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); -static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); -static void print_error_with_init_status(const DecoderSession *d, const char *message, FLAC__StreamDecoderInitStatus init_status); -static void print_error_with_state(const DecoderSession *d, const char *message); -static void print_stats(const DecoderSession *decoder_session); - - -/* - * public routines - */ -int flac__decode_file(const char *infilename, const char *outfilename, FLAC__bool analysis_mode, analysis_options aopts, decode_options_t options) -{ - DecoderSession decoder_session; - - FLAC__ASSERT( - options.format == FORMAT_WAVE || - options.format == FORMAT_WAVE64 || - options.format == FORMAT_RF64 || - options.format == FORMAT_AIFF || - options.format == FORMAT_AIFF_C || - options.format == FORMAT_RAW - ); - - if(options.format == FORMAT_RAW) { - decoder_session.is_big_endian = options.format_options.raw.is_big_endian; - decoder_session.is_unsigned_samples = options.format_options.raw.is_unsigned_samples; - } - - if(! - DecoderSession_construct( - &decoder_session, -#if FLAC__HAS_OGG - options.is_ogg, - options.use_first_serial_number, - options.serial_number, -#else - /*is_ogg=*/false, - /*use_first_serial_number=*/false, - /*serial_number=*/0, -#endif - options.format, - options.force_subformat, - options.treat_warnings_as_errors, - options.continue_through_decode_errors, - options.channel_map_none, - options.relaxed_foreign_metadata_handling, - options.replaygain_synthesis_spec, - analysis_mode, - aopts, - &options.skip_specification, - &options.until_specification, - options.has_cue_specification? &options.cue_specification : 0, - options.format == FORMAT_RAW? NULL : options.format_options.iff.foreign_metadata, - infilename, - outfilename - ) - ) - return 1; - - stats_new_file(); - if(!DecoderSession_init_decoder(&decoder_session, infilename)) - return DecoderSession_finish_error(&decoder_session); - - if(!DecoderSession_process(&decoder_session)) - return DecoderSession_finish_error(&decoder_session); - - return DecoderSession_finish_ok(&decoder_session); -} - -FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__bool use_first_serial_number, long serial_number, FileFormat format, FileSubFormat subformat, FLAC__bool treat_warnings_as_errors, FLAC__bool continue_through_decode_errors, FLAC__bool channel_map_none, FLAC__bool relaxed_foreign_metadata_handling, replaygain_synthesis_spec_t replaygain_synthesis_spec, FLAC__bool analysis_mode, analysis_options aopts, utils__SkipUntilSpecification *skip_specification, utils__SkipUntilSpecification *until_specification, utils__CueSpecification *cue_specification, foreign_metadata_t *foreign_metadata, const char *infilename, const char *outfilename) -{ -#if FLAC__HAS_OGG - d->is_ogg = is_ogg; - d->use_first_serial_number = use_first_serial_number; - d->serial_number = serial_number; -#else - (void)is_ogg; - (void)use_first_serial_number; - (void)serial_number; -#endif - - d->format = format; - d->subformat = subformat; - d->treat_warnings_as_errors = treat_warnings_as_errors; - d->continue_through_decode_errors = continue_through_decode_errors; - d->channel_map_none = channel_map_none; - d->relaxed_foreign_metadata_handling = relaxed_foreign_metadata_handling; - d->replaygain.spec = replaygain_synthesis_spec; - d->replaygain.apply = false; - d->replaygain.scale = 0.0; - /* d->replaygain.dither_context gets initialized later once we know the sample resolution */ - d->test_only = (0 == outfilename); - d->analysis_mode = analysis_mode; - d->aopts = aopts; - d->skip_specification = skip_specification; - d->until_specification = until_specification; - d->cue_specification = cue_specification; - - d->inbasefilename = grabbag__file_get_basename(infilename); - d->infilename = infilename; - d->outfilename = outfilename; - - d->samples_processed = 0; - d->frame_counter = 0; - d->abort_flag = false; - d->aborting_due_to_until = false; - d->aborting_due_to_unparseable = false; - d->error_callback_suppress_messages = false; - if(relaxed_foreign_metadata_handling) - d->warn_user_about_foreign_metadata = false; - else - d->warn_user_about_foreign_metadata = true; - - d->iff_headers_need_fixup = false; - - d->total_samples = 0; - d->got_stream_info = false; - d->has_md5sum = false; - d->bps = 0; - d->channels = 0; - d->sample_rate = UINT32_MAX; - d->channel_mask = 0; - - d->decode_position = 0; - - d->decoder = 0; - - d->fout = 0; /* initialized with an open file later if necessary */ - - d->foreign_metadata = foreign_metadata; - - d->old_clock_t = 0; - - FLAC__ASSERT(!(d->test_only && d->analysis_mode)); - - if(!d->test_only) { - if(0 == strcmp(outfilename, "-")) { - d->fout = grabbag__file_get_binary_stdout(); - } - else { - if(0 == (d->fout = flac_fopen(outfilename, "wb"))) { - flac__utils_printf(stderr, 1, "%s: ERROR: can't open output file %s: %s\n", d->inbasefilename, outfilename, strerror(errno)); - DecoderSession_destroy(d, /*error_occurred=*/true); - return false; - } - } - } - - if(analysis_mode) - flac__analyze_init(aopts); - - return true; -} - -void DecoderSession_destroy(DecoderSession *d, FLAC__bool error_occurred) -{ - if(0 != d->fout && d->fout != stdout) { -#if defined _WIN32 && !defined __CYGWIN__ - if(!error_occurred) { - FLAC__off_t written_size = ftello(d->fout); - if(written_size > 0) { - HANDLE fh = CreateFile_utf8(d->outfilename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if(fh != INVALID_HANDLE_VALUE) { - if(GetFileType(fh) == FILE_TYPE_DISK) { - LARGE_INTEGER size; - size.QuadPart = written_size; - if(SetFilePointerEx(fh, size, NULL, FILE_CURRENT)) /* correct the file size */ - SetEndOfFile(fh); - } - CloseHandle(fh); - } - } - } -#endif - fclose(d->fout); - -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* Always delete output file when fuzzing */ - if(error_occurred) -#endif - flac_unlink(d->outfilename); - } -} - -FLAC__bool DecoderSession_init_decoder(DecoderSession *decoder_session, const char *infilename) -{ - FLAC__StreamDecoderInitStatus init_status; - FLAC__uint32 test = 1; - - is_big_endian_host_ = (*((FLAC__byte*)(&test)))? false : true; - - if(decoder_session->test_only && strcmp(infilename, "-") != 0) { - /* When testing, we can be a little more pedantic, as long - * as we can seek properly */ - FLAC__byte buffer[3]; - FILE * f; - - if(0 == (f = flac_fopen(infilename, "rb"))) { - flac__utils_printf(stderr, 1, "ERROR: can't open input file %s: %s\n", infilename, strerror(errno)); - return false; - } - - if(fread(buffer, 1, 3, f) < 3) { - flac__utils_printf(stderr, 1, "%s: ERROR checking for ID3v2 tag\n", decoder_session->inbasefilename); - fclose(f); - return false; - } - if(memcmp(buffer, "ID3", 3) == 0){ - flac__utils_printf(stderr, 1, "%s: WARNING, ID3v2 tag found. This is non-standard and strongly discouraged\n", decoder_session->inbasefilename); - if(decoder_session->treat_warnings_as_errors) { - fclose(f); - return false; - } - } - fclose(f); - } - - decoder_session->decoder = FLAC__stream_decoder_new(); - - if(0 == decoder_session->decoder) { - flac__utils_printf(stderr, 1, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename); - return false; - } - - FLAC__stream_decoder_set_md5_checking(decoder_session->decoder, true); - if (0 != decoder_session->cue_specification) - FLAC__stream_decoder_set_metadata_respond(decoder_session->decoder, FLAC__METADATA_TYPE_CUESHEET); - if (decoder_session->replaygain.spec.apply || !decoder_session->channel_map_none) - FLAC__stream_decoder_set_metadata_respond(decoder_session->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); - - if(!decoder_session->analysis_mode && !decoder_session->test_only && decoder_session->foreign_metadata == NULL) { - /* Warn user if foreign metadata is found */ - uint32_t i; - for(i = 0; i < FLAC__FOREIGN_METADATA_NUMBER_OF_RECOGNIZED_APPLICATION_IDS; i++) - FLAC__stream_decoder_set_metadata_respond_application(decoder_session->decoder, (FLAC__byte *)FLAC__FOREIGN_METADATA_APPLICATION_ID[i]); - } - -#if FLAC__HAS_OGG - if(decoder_session->is_ogg) { - if(!decoder_session->use_first_serial_number) - FLAC__stream_decoder_set_ogg_serial_number(decoder_session->decoder, decoder_session->serial_number); - init_status = FLAC__stream_decoder_init_ogg_file(decoder_session->decoder, strcmp(infilename, "-")? infilename : 0, write_callback, metadata_callback, error_callback, /*client_data=*/decoder_session); - } - else -#endif - { - init_status = FLAC__stream_decoder_init_file(decoder_session->decoder, strcmp(infilename, "-")? infilename : 0, write_callback, metadata_callback, error_callback, /*client_data=*/decoder_session); - } - - if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - print_error_with_init_status(decoder_session, "ERROR initializing decoder", init_status); - return false; - } - - return true; -} - -FLAC__bool DecoderSession_process(DecoderSession *d) -{ - if(!FLAC__stream_decoder_process_until_end_of_metadata(d->decoder)) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR while decoding metadata"); - return false; - } - if(FLAC__stream_decoder_get_state(d->decoder) > FLAC__STREAM_DECODER_END_OF_STREAM) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR during metadata decoding"); - if(!d->continue_through_decode_errors) - return false; - } - - if(d->analysis_mode) - FLAC__stream_decoder_get_decode_position(d->decoder, &d->decode_position); - - if(d->abort_flag) - return false; - - /* set channel mapping */ - /* currently FLAC order matches SMPTE/WAVEFORMATEXTENSIBLE order, so no reordering is necessary; see encode.c */ - /* only the channel mask must be set if it was not already picked up from the WAVEFORMATEXTENSIBLE_CHANNEL_MASK tag */ - if(!d->channel_map_none && d->channel_mask == 0) { - if(d->channels == 1) { - d->channel_mask = 0x0004; - } - else if(d->channels == 2) { - d->channel_mask = 0x0003; - } - else if(d->channels == 3) { - d->channel_mask = 0x0007; - } - else if(d->channels == 4) { - d->channel_mask = 0x0033; - } - else if(d->channels == 5) { - d->channel_mask = 0x0607; - } - else if(d->channels == 6) { - d->channel_mask = 0x060f; - } - else if(d->channels == 7) { - d->channel_mask = 0x070f; - } - else if(d->channels == 8) { - d->channel_mask = 0x063f; - } - } - -#if defined _WIN32 && !defined __CYGWIN__ - if(!d->analysis_mode && !d->test_only && d->total_samples > 0 && d->fout != stdout) { - HANDLE fh = CreateFile_utf8(d->outfilename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if(fh != INVALID_HANDLE_VALUE) { - if (GetFileType(fh) == FILE_TYPE_DISK) { - LARGE_INTEGER size; - size.QuadPart = d->total_samples * d->channels * ((d->bps+7)/8); - if(d->format != FORMAT_RAW) { - size.QuadPart += 512; - if(d->foreign_metadata) { - size_t i; - for(i = d->format==FORMAT_RF64?2:1; i < d->foreign_metadata->num_blocks; i++) { - if(i != d->foreign_metadata->format_block && i != d->foreign_metadata->audio_block) - size.QuadPart += d->foreign_metadata->blocks[i].size; - } - } - } - - if(SetFilePointerEx(fh, size, NULL, FILE_CURRENT)) /* tell filesystem the expected filesize to eliminate fragmentation */ - SetEndOfFile(fh); - } - CloseHandle(fh); - } - } -#endif - - /* write the WAVE/AIFF headers if necessary */ - if(!d->analysis_mode && !d->test_only && d->format != FORMAT_RAW) { - if(!write_iff_headers(d->fout, d, d->total_samples)) { - d->abort_flag = true; - return false; - } - } - - if(d->skip_specification->value.samples > 0) { - const FLAC__uint64 skip = (FLAC__uint64)d->skip_specification->value.samples; - - if(!FLAC__stream_decoder_seek_absolute(d->decoder, skip)) { - print_error_with_state(d, "ERROR seeking while skipping bytes"); - return false; - } - } - if(!FLAC__stream_decoder_process_until_end_of_stream(d->decoder) && !d->aborting_due_to_until) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR while decoding data"); - if(!d->continue_through_decode_errors) - return false; - } - if( - (d->abort_flag && !(d->aborting_due_to_until || d->continue_through_decode_errors)) || - (FLAC__stream_decoder_get_state(d->decoder) > FLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) - ) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR during decoding"); - return false; - } - - /* write padding bytes for alignment if necessary */ - if(!d->analysis_mode && !d->test_only && d->format != FORMAT_RAW) { - const FLAC__uint64 data_size = d->total_samples * d->channels * ((d->bps+7)/8); - uint32_t padding; - if(d->format != FORMAT_WAVE64) { - padding = (uint32_t)(data_size & 1); - } - else { - /* 8-byte alignment for Wave64 */ - padding = (8 - (uint32_t)(data_size & 7)) & 7; - } - for( ; padding > 0; --padding) { - if(flac__utils_fwrite("\000", 1, 1, d->fout) != 1) { - print_error_with_state( - d, - d->format == FORMAT_WAVE? "ERROR writing pad byte to WAVE data chunk" : - d->format == FORMAT_WAVE64? "ERROR writing pad bytes to WAVE64 data chunk" : - d->format == FORMAT_RF64? "ERROR writing pad byte to RF64 data chunk" : - "ERROR writing pad byte to AIFF SSND chunk" - ); - return false; - } - } - } - - return true; -} - -int DecoderSession_finish_ok(DecoderSession *d) -{ - FLAC__bool ok = true, md5_failure = false; - - if(d->decoder) { - md5_failure = !FLAC__stream_decoder_finish(d->decoder) && !d->aborting_due_to_until; - print_stats(d); - FLAC__stream_decoder_delete(d->decoder); - } - if(d->analysis_mode) - flac__analyze_finish(d->aopts); - if(md5_failure) { - stats_print_name(1, d->inbasefilename); - flac__utils_printf(stderr, 1, "ERROR, MD5 signature mismatch\n"); - ok = d->continue_through_decode_errors; - } - else if(d->got_stream_info && d->total_samples && (d->total_samples > d->samples_processed)){ - stats_print_name(1, d->inbasefilename); - flac__utils_printf(stderr, 1, "ERROR, decoded number of samples is smaller than the total number of samples set in the STREAMINFO\n"); - ok = d->continue_through_decode_errors; - } - else { - if(!d->got_stream_info) { - stats_print_name(1, d->inbasefilename); - flac__utils_printf(stderr, 1, "WARNING, cannot check MD5 signature since there was no STREAMINFO\n"); - ok = !d->treat_warnings_as_errors; - } - else if(!d->has_md5sum) { - stats_print_name(1, d->inbasefilename); - flac__utils_printf(stderr, 1, "WARNING, cannot check MD5 signature since it was unset in the STREAMINFO\n"); - ok = !d->treat_warnings_as_errors; - } - else if(!d->total_samples) { - stats_print_name(1, d->inbasefilename); - flac__utils_printf(stderr, 1, "WARNING, cannot check total number of samples since it was unset in the STREAMINFO\n"); - ok = !d->treat_warnings_as_errors; - } - stats_print_name(2, d->inbasefilename); - flac__utils_printf(stderr, 2, "%s \n", d->test_only? "ok ":d->analysis_mode?"done ":"done"); - } - DecoderSession_destroy(d, /*error_occurred=*/!ok); - if(!d->analysis_mode && !d->test_only && d->format != FORMAT_RAW) { - if(d->iff_headers_need_fixup || (!d->got_stream_info && strcmp(d->outfilename, "-"))) { - if(!fixup_iff_headers(d)) - return 1; - } - if(d->foreign_metadata) { - const char *error; - if(!flac__foreign_metadata_write_to_iff(d->foreign_metadata, d->infilename, d->outfilename, d->fm_offset1, d->fm_offset2, d->fm_offset3, &error)) { - flac__utils_printf(stderr, 1, "ERROR updating foreign metadata from %s to %s: %s\n", d->infilename, d->outfilename, error); - return 1; - } - if(!flac__foreign_metadata_compare_with_iff(d->foreign_metadata, d->infilename, d->outfilename, d->fm_offset3, &error)) { - flac__utils_printf(stderr, 1, "ERROR verifying foreign metadata restore from %s to %s: %s\n", d->infilename, d->outfilename, error); - return 1; - } - } - } - return ok? 0 : 1; -} - -int DecoderSession_finish_error(DecoderSession *d) -{ - if(d->decoder) { - (void)FLAC__stream_decoder_finish(d->decoder); - FLAC__stream_decoder_delete(d->decoder); - } - if(d->analysis_mode) - flac__analyze_finish(d->aopts); - DecoderSession_destroy(d, /*error_occurred=*/true); - return 1; -} - -FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, uint32_t sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input) -{ - /* convert from mm:ss.sss to sample number if necessary */ - if(!flac__utils_canonicalize_skip_until_specification(spec, sample_rate)) { - flac__utils_printf(stderr, 1, "%s: ERROR, value of --until is too large\n", inbasefilename); - return false; - } - - /* special case: if "--until=-0", use the special value '0' to mean "end-of-stream" */ - if(spec->is_relative && spec->value.samples == 0) { - spec->is_relative = false; - return true; - } - - /* in any other case the total samples in the input must be known */ - if(total_samples_in_input == 0) { - flac__utils_printf(stderr, 1, "%s: ERROR, cannot use --until when FLAC metadata has total sample count of 0\n", inbasefilename); - return false; - } - - FLAC__ASSERT(spec->value_is_samples); - - /* convert relative specifications to absolute */ - if(spec->is_relative) { - if(spec->value.samples <= 0) - spec->value.samples += (FLAC__int64)total_samples_in_input; - else - spec->value.samples += skip; - spec->is_relative = false; - } - - /* error check */ - if(spec->value.samples < 0) { - flac__utils_printf(stderr, 1, "%s: ERROR, --until value is before beginning of input\n", inbasefilename); - return false; - } - if((FLAC__uint64)spec->value.samples <= skip) { - flac__utils_printf(stderr, 1, "%s: ERROR, --until value is before --skip point\n", inbasefilename); - return false; - } - if((FLAC__uint64)spec->value.samples > total_samples_in_input) { - flac__utils_printf(stderr, 1, "%s: ERROR, --until value is after end of input\n", inbasefilename); - return false; - } - - return true; -} - -FLAC__bool write_iff_headers(FILE *f, DecoderSession *decoder_session, FLAC__uint64 samples) -{ - const FileFormat format = decoder_session->format; - const FileSubFormat subformat = decoder_session->subformat; - const char *fmt_desc = - format==FORMAT_WAVE? "WAVE" : - format==FORMAT_WAVE64? "Wave64" : - format==FORMAT_RF64? "RF64" : - format==FORMAT_AIFF? "AIFF" : - "AIFC"; - const FLAC__bool is_waveformatextensible = - subformat == SUBFORMAT_WAVE_EXTENSIBLE || ( - (format == FORMAT_WAVE || format == FORMAT_WAVE64 || format == FORMAT_RF64) && - subformat != SUBFORMAT_WAVE_PCM && - ( - (decoder_session->channel_mask != 0 && decoder_session->channel_mask != 0x0004 && decoder_session->channel_mask != 0x0003) || - (decoder_session->bps != 8 && decoder_session->bps != 16) || - decoder_session->channels > 2 - )); - const FLAC__uint64 data_size = samples * decoder_session->channels * ((decoder_session->bps+7)/8); - const FLAC__uint64 aligned_data_size = - format == FORMAT_WAVE64? - (data_size+7) & (~(FLAC__uint64)7) : - (data_size+1) & (~(FLAC__uint64)1); - - FLAC__uint64 iff_size; - uint32_t foreign_metadata_size = 0; /* size of all non-audio non-fmt/COMM foreign metadata chunks */ - foreign_metadata_t *fm = decoder_session->foreign_metadata; - size_t i; - - FLAC__ASSERT( - format == FORMAT_WAVE || - format == FORMAT_WAVE64 || - format == FORMAT_RF64 || - format == FORMAT_AIFF || - format == FORMAT_AIFF_C - ); - - if(samples == 0) { - if(f == stdout) { - flac__utils_printf(stderr, 1, "%s: WARNING, don't have accurate sample count available for %s header.\n", decoder_session->inbasefilename, fmt_desc); - flac__utils_printf(stderr, 1, " Generated %s file will have a data chunk size of 0. Try\n", fmt_desc); - flac__utils_printf(stderr, 1, " decoding directly to a file instead.\n"); - if(decoder_session->treat_warnings_as_errors) - return false; - } - else { - decoder_session->iff_headers_need_fixup = true; - } - } - - if(fm) { - FLAC__ASSERT(fm->format_block); - FLAC__ASSERT(fm->audio_block); - FLAC__ASSERT(fm->format_block < fm->audio_block); - /* calc foreign metadata size; we always skip the first chunk, ds64 chunk, format chunk, and sound chunk since we write our own */ - for(i = format==FORMAT_RF64?2:1; i < fm->num_blocks; i++) { - if(i != fm->format_block && i != fm->audio_block) - foreign_metadata_size += fm->blocks[i].size; - } - } - - if(samples == 0) - iff_size = 0; - else if(format == FORMAT_WAVE || format == FORMAT_RF64) - /* 4 for WAVE form bytes */ - /* +{36,0} for ds64 chunk */ - /* +8+{40,16} for fmt chunk header and body */ - /* +8 for data chunk header */ - iff_size = 4 + (format==FORMAT_RF64?36:0) + 8+(is_waveformatextensible?40:16) + 8 + foreign_metadata_size + aligned_data_size; - else if(format == FORMAT_WAVE64) - /* 16+8 for RIFF GUID and size field */ - /* +16 for WAVE GUID */ - /* +16+8+{40,16} for fmt chunk header (GUID and size field) and body */ - /* +16+8 for data chunk header (GUID and size field) */ - iff_size = 16+8 + 16 + 16+8+(is_waveformatextensible?40:16) + 16+8 + foreign_metadata_size + aligned_data_size; - else if(format == FORMAT_AIFF) - iff_size = 46 + foreign_metadata_size + aligned_data_size; - else /* AIFF-C */ - iff_size = 16 + foreign_metadata_size + aligned_data_size + (fm?fm->aifc_comm_length:0); - - if(format != FORMAT_WAVE64 && format != FORMAT_RF64 && iff_size >= 0xFFFFFFF4) { - flac__utils_printf(stderr, 1, "%s: ERROR: stream is too big to fit in a single %s file\n", decoder_session->inbasefilename, fmt_desc); - return false; - } - - if(format == FORMAT_WAVE || format == FORMAT_WAVE64 || format == FORMAT_RF64) { - /* RIFF header */ - switch(format) { - case FORMAT_WAVE: - if(flac__utils_fwrite("RIFF", 1, 4, f) != 4) - return false; - if(!write_little_endian_uint32(f, (FLAC__uint32)iff_size)) /* filesize-8 */ - return false; - if(flac__utils_fwrite("WAVE", 1, 4, f) != 4) - return false; - break; - case FORMAT_WAVE64: - /* RIFF GUID 66666972-912E-11CF-A5D6-28DB04C10000 */ - if(flac__utils_fwrite("\x72\x69\x66\x66\x2E\x91\xCF\x11\xA5\xD6\x28\xDB\x04\xC1\x00\x00", 1, 16, f) != 16) - return false; - if(!write_little_endian_uint64(f, iff_size)) - return false; - /* WAVE GUID 65766177-ACF3-11D3-8CD1-00C04F8EDB8A */ - if(flac__utils_fwrite("\x77\x61\x76\x65\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) != 16) - return false; - break; - case FORMAT_RF64: - if(flac__utils_fwrite("RF64", 1, 4, f) != 4) - return false; - if(!write_little_endian_uint32(f, 0xffffffff)) - return false; - if(flac__utils_fwrite("WAVE", 1, 4, f) != 4) - return false; - break; - default: - return false; - } - - /* ds64 chunk for RF64 */ - if(format == FORMAT_RF64) { - if(flac__utils_fwrite("ds64", 1, 4, f) != 4) - return false; - - if(!write_little_endian_uint32(f, 28)) /* chunk size */ - return false; - - if(!write_little_endian_uint64(f, iff_size)) - return false; - - if(!write_little_endian_uint64(f, data_size)) - return false; - - if(!write_little_endian_uint64(f, samples)) /*@@@@@@ correct? */ - return false; - - if(!write_little_endian_uint32(f, 0)) /* table size */ - return false; - } - - decoder_session->fm_offset1 = ftello(f); - - if(fm) { - /* seek forward to {allocate} or {skip over already-written chunks} before "fmt " */ - for(i = format==FORMAT_RF64?2:1; i < fm->format_block; i++) { - if(fseeko(f, fm->blocks[i].size, SEEK_CUR) < 0) { - flac__utils_printf(stderr, 1, "%s: ERROR: allocating/skipping foreign metadata before \"fmt \"\n", decoder_session->inbasefilename); - return false; - } - } - } - - if(format != FORMAT_WAVE64) { - if(flac__utils_fwrite("fmt ", 1, 4, f) != 4) - return false; - if(!write_little_endian_uint32(f, is_waveformatextensible? 40 : 16)) /* chunk size */ - return false; - } - else { /* Wave64 */ - /* fmt GUID 20746D66-ACF3-11D3-8CD1-00C04F8EDB8A */ - if(flac__utils_fwrite("\x66\x6D\x74\x20\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) != 16) - return false; - /* chunk size (+16+8 for GUID and size fields) */ - if(!write_little_endian_uint64(f, 16+8+(is_waveformatextensible?40:16))) - return false; - } - - if(!write_riff_wave_fmt_chunk_body(f, is_waveformatextensible, decoder_session->bps, decoder_session->channels, decoder_session->sample_rate, decoder_session->channel_mask)) - return false; - - decoder_session->fm_offset2 = ftello(f); - - if(fm) { - /* seek forward to {allocate} or {skip over already-written chunks} after "fmt " but before "data" */ - for(i = fm->format_block+1; i < fm->audio_block; i++) { - if(fseeko(f, fm->blocks[i].size, SEEK_CUR) < 0) { - flac__utils_printf(stderr, 1, "%s: ERROR: allocating/skipping foreign metadata after \"fmt \"\n", decoder_session->inbasefilename); - return false; - } - } - } - - if(format != FORMAT_WAVE64) { - if(flac__utils_fwrite("data", 1, 4, f) != 4) - return false; - if(!write_little_endian_uint32(f, format==FORMAT_RF64? 0xffffffff : (FLAC__uint32)data_size)) - return false; - } - else { /* Wave64 */ - /* data GUID 61746164-ACF3-11D3-8CD1-00C04F8EDB8A */ - if(flac__utils_fwrite("\x64\x61\x74\x61\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) != 16) - return false; - /* +16+8 for GUID and size fields */ - if(!write_little_endian_uint64(f, 16+8 + data_size)) - return false; - } - - decoder_session->fm_offset3 = ftello(f) + aligned_data_size; - } - else { - if(flac__utils_fwrite("FORM", 1, 4, f) != 4) - return false; - - if(!write_big_endian_uint32(f, (FLAC__uint32)iff_size)) /* filesize-8 */ - return false; - - if(format == FORMAT_AIFF) { - if(flac__utils_fwrite("AIFF", 1, 4, f) != 4) - return false; - } - else - if(flac__utils_fwrite("AIFC", 1, 4, f) != 4) - return false; - - decoder_session->fm_offset1 = ftello(f); - - if(fm) { - /* seek forward to {allocate} or {skip over already-written chunks} before "COMM" */ - for(i = 1; i < fm->format_block; i++) { - if(fseeko(f, fm->blocks[i].size, SEEK_CUR) < 0) { - flac__utils_printf(stderr, 1, "%s: ERROR: allocating/skipping foreign metadata before \"COMM\"\n", decoder_session->inbasefilename); - return false; - } - } - } - - if(!write_aiff_form_comm_chunk(f, samples, decoder_session->bps, decoder_session->channels, decoder_session->sample_rate, format, subformat, fm?fm->aifc_comm_length:0)) - return false; - - decoder_session->fm_offset2 = ftello(f); - - if(fm) { - /* seek forward to {allocate} or {skip over already-written chunks} after "COMM" but before "SSND" */ - for(i = fm->format_block+1; i < fm->audio_block; i++) { - if(fseeko(f, fm->blocks[i].size, SEEK_CUR) < 0) { - flac__utils_printf(stderr, 1, "%s: ERROR: allocating/skipping foreign metadata after \"COMM\"\n", decoder_session->inbasefilename); - return false; - } - } - } - - if(flac__utils_fwrite("SSND", 1, 4, f) != 4) - return false; - - if(!write_big_endian_uint32(f, (FLAC__uint32)data_size + 8)) /* data size */ - return false; - - if(!write_big_endian_uint32(f, 0/*offset_size*/)) - return false; - - if(!write_big_endian_uint32(f, 0/*block_size*/)) - return false; - - decoder_session->fm_offset3 = ftello(f) + aligned_data_size; - } - - return true; -} - -FLAC__bool write_riff_wave_fmt_chunk_body(FILE *f, FLAC__bool is_waveformatextensible, uint32_t bps, uint32_t channels, uint32_t sample_rate, FLAC__uint32 channel_mask) -{ - if(!write_little_endian_uint16(f, (FLAC__uint16)(is_waveformatextensible? 65534 : 1))) /* compression code */ - return false; - - if(!write_little_endian_uint16(f, (FLAC__uint16)channels)) - return false; - - if(!write_little_endian_uint32(f, sample_rate)) - return false; - - if(!write_little_endian_uint32(f, sample_rate * channels * ((bps+7) / 8))) - return false; - - if(!write_little_endian_uint16(f, (FLAC__uint16)(channels * ((bps+7) / 8)))) /* block align */ - return false; - - if(!write_little_endian_uint16(f, (FLAC__uint16)(((bps+7)/8)*8))) /* bits per sample */ - return false; - - if(is_waveformatextensible) { - if(!write_little_endian_uint16(f, (FLAC__uint16)22)) /* cbSize */ - return false; - - if(!write_little_endian_uint16(f, (FLAC__uint16)bps)) /* validBitsPerSample */ - return false; - - if(!write_little_endian_uint32(f, channel_mask)) - return false; - - /* GUID = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} */ - if(flac__utils_fwrite("\x01\x00\x00\x00\x00\x00\x10\x00\x80\x00\x00\xaa\x00\x38\x9b\x71", 1, 16, f) != 16) - return false; - } - - return true; -} - -FLAC__bool write_aiff_form_comm_chunk(FILE *f, FLAC__uint64 samples, uint32_t bps, uint32_t channels, uint32_t sample_rate, FileFormat format, FileSubFormat subformat, FLAC__uint32 comm_length) -{ - FLAC__uint32 i; - FLAC__ASSERT(samples <= 0xffffffff); - - if(comm_length == 0) { - if(format == FORMAT_AIFF) - comm_length = 30; - else - comm_length = 36; - } - - if(flac__utils_fwrite("COMM", 1, 4, f) != 4) - return false; - - if(!write_big_endian_uint32(f, comm_length-12)) /* chunk size = 18 */ - return false; - - if(!write_big_endian_uint16(f, (FLAC__uint16)channels)) - return false; - - if(!write_big_endian_uint32(f, (FLAC__uint32)samples)) - return false; - - if(!write_big_endian_uint16(f, (FLAC__uint16)bps)) - return false; - - if(!write_sane_extended(f, sample_rate)) - return false; - - if(format == FORMAT_AIFF_C) { - if(subformat == SUBFORMAT_AIFF_C_NONE) { - if(flac__utils_fwrite("NONE", 1, 4, f) != 4) - return false; - } - else if(subformat == SUBFORMAT_AIFF_C_SOWT) { - if(flac__utils_fwrite("sowt", 1, 4, f) != 4) - return false; - } - for(i = 34; i < comm_length; i++) { - if(flac__utils_fwrite("\x00", 1, 1, f) != 1) - return false; - } - } - - - - return true; -} - -FLAC__bool write_little_endian_uint16(FILE *f, FLAC__uint16 val) -{ - FLAC__byte *b = (FLAC__byte*)(&val); - if(is_big_endian_host_) { - FLAC__byte tmp; - tmp = b[1]; b[1] = b[0]; b[0] = tmp; - } - return flac__utils_fwrite(b, 1, 2, f) == 2; -} - -FLAC__bool write_little_endian_uint32(FILE *f, FLAC__uint32 val) -{ - FLAC__byte *b = (FLAC__byte*)(&val); - if(is_big_endian_host_) { - FLAC__byte tmp; - tmp = b[3]; b[3] = b[0]; b[0] = tmp; - tmp = b[2]; b[2] = b[1]; b[1] = tmp; - } - return flac__utils_fwrite(b, 1, 4, f) == 4; -} - -FLAC__bool write_little_endian_uint64(FILE *f, FLAC__uint64 val) -{ - FLAC__byte *b = (FLAC__byte*)(&val); - if(is_big_endian_host_) { - FLAC__byte tmp; - tmp = b[7]; b[7] = b[0]; b[0] = tmp; - tmp = b[6]; b[6] = b[1]; b[1] = tmp; - tmp = b[5]; b[5] = b[2]; b[2] = tmp; - tmp = b[4]; b[4] = b[3]; b[3] = tmp; - } - return flac__utils_fwrite(b, 1, 8, f) == 8; -} - -FLAC__bool write_big_endian_uint16(FILE *f, FLAC__uint16 val) -{ - FLAC__byte *b = (FLAC__byte*)(&val); - if(!is_big_endian_host_) { - FLAC__byte tmp; - tmp = b[1]; b[1] = b[0]; b[0] = tmp; - } - return flac__utils_fwrite(b, 1, 2, f) == 2; -} - -FLAC__bool write_big_endian_uint32(FILE *f, FLAC__uint32 val) -{ - FLAC__byte *b = (FLAC__byte*)(&val); - if(!is_big_endian_host_) { - FLAC__byte tmp; - tmp = b[3]; b[3] = b[0]; b[0] = tmp; - tmp = b[2]; b[2] = b[1]; b[1] = tmp; - } - return flac__utils_fwrite(b, 1, 4, f) == 4; -} - -FLAC__bool write_sane_extended(FILE *f, uint32_t val) - /* Write to 'f' a SANE extended representation of 'val'. Return false if - * the write succeeds; return true otherwise. - * - * SANE extended is an 80-bit IEEE-754 representation with sign bit, 15 bits - * of exponent, and 64 bits of significand (mantissa). Unlike most IEEE-754 - * representations, it does not imply a 1 above the MSB of the significand. - * - */ -{ - uint32_t shift, exponent; - - if(val == 0U) { - if(!write_big_endian_uint16(f, 0)) - return false; - if(!write_big_endian_uint32(f, 0)) - return false; - if(!write_big_endian_uint32(f, 0)) - return false; - return true; - } - - for(shift= 0U; (val>>(31-shift))==0U; ++shift) - ; - val<<= shift; - exponent= 63U-(shift+32U); /* add 32 for unused second word */ - - if(!write_big_endian_uint16(f, (FLAC__uint16)(exponent+0x3FFF))) - return false; - if(!write_big_endian_uint32(f, val)) - return false; - if(!write_big_endian_uint32(f, 0)) /* unused second word */ - return false; - - return true; -} - -FLAC__bool fixup_iff_headers(DecoderSession *d) -{ - const char *fmt_desc = - d->format==FORMAT_WAVE? "WAVE" : - d->format==FORMAT_WAVE64? "Wave64" : - d->format==FORMAT_RF64? "RF64" : - "AIFF"; - FILE *f = flac_fopen(d->outfilename, "r+b"); /* stream is positioned at beginning of file */ - - if(0 == f) { - flac__utils_printf(stderr, 1, "ERROR, couldn't open file %s while fixing up %s chunk size: %s\n", d->outfilename, fmt_desc, strerror(errno)); - return false; - } - - if(!write_iff_headers(f, d, d->samples_processed)) { - fclose(f); - return false; - } - - fclose(f); - return true; -} - -FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - DecoderSession *decoder_session = (DecoderSession*)client_data; - FILE *fout = decoder_session->fout; - const uint32_t bps = frame->header.bits_per_sample, channels = frame->header.channels; - const uint32_t shift = (bps%8)? 8-(bps%8): 0; - FLAC__bool is_big_endian = ( - (decoder_session->format == FORMAT_AIFF || (decoder_session->format == FORMAT_AIFF_C && decoder_session->subformat == SUBFORMAT_AIFF_C_NONE)) ? true : ( - decoder_session->format == FORMAT_WAVE || decoder_session->format == FORMAT_WAVE64 || decoder_session->format == FORMAT_RF64 || (decoder_session->format == FORMAT_AIFF_C && decoder_session->subformat == SUBFORMAT_AIFF_C_SOWT) ? false : - decoder_session->is_big_endian - )); - FLAC__bool is_unsigned_samples = ( - decoder_session->format == FORMAT_AIFF || decoder_session->format == FORMAT_AIFF_C ? false : ( - decoder_session->format == FORMAT_WAVE || decoder_session->format == FORMAT_WAVE64 || decoder_session->format == FORMAT_RF64 ? bps<=8 : - decoder_session->is_unsigned_samples - )); - uint32_t wide_samples = frame->header.blocksize, wide_sample, sample, channel; - FLAC__uint64 frame_bytes = 0; - - static union - { /* The arrays defined within this union are all the same size. */ - FLAC__int8 s8buffer [FLAC__MAX_BLOCK_SIZE * FLAC__MAX_CHANNELS * sizeof(FLAC__int32)]; /* WATCHOUT: can be up to 2 megs */ - FLAC__uint8 u8buffer [FLAC__MAX_BLOCK_SIZE * FLAC__MAX_CHANNELS * sizeof(FLAC__int32)]; - FLAC__int16 s16buffer [FLAC__MAX_BLOCK_SIZE * FLAC__MAX_CHANNELS * sizeof(FLAC__int16)]; - FLAC__uint16 u16buffer [FLAC__MAX_BLOCK_SIZE * FLAC__MAX_CHANNELS * sizeof(FLAC__int16)]; - FLAC__int32 s32buffer [FLAC__MAX_BLOCK_SIZE * FLAC__MAX_CHANNELS]; - FLAC__uint32 u32buffer [FLAC__MAX_BLOCK_SIZE * FLAC__MAX_CHANNELS]; - } ubuf; - - size_t bytes_to_write = 0; - - (void)decoder; - - if(decoder_session->abort_flag) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - - /* sanity-check the bits-per-sample */ - if(decoder_session->bps) { - if(bps != decoder_session->bps) { - if(decoder_session->got_stream_info) - flac__utils_printf(stderr, 1, "%s: ERROR, bits-per-sample is %u in frame but %u in STREAMINFO\n", decoder_session->inbasefilename, bps, decoder_session->bps); - else - flac__utils_printf(stderr, 1, "%s: ERROR, bits-per-sample is %u in this frame but %u in previous frames\n", decoder_session->inbasefilename, bps, decoder_session->bps); - if(!decoder_session->continue_through_decode_errors) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } - else { - /* must not have gotten STREAMINFO, save the bps from the frame header */ - FLAC__ASSERT(!decoder_session->got_stream_info); - if(decoder_session->format == FORMAT_RAW && ((decoder_session->bps % 8) != 0 || decoder_session->bps < 4)) { - flac__utils_printf(stderr, 1, "%s: ERROR: bits per sample is %u, must be 8/16/24/32 for raw format output\n", decoder_session->inbasefilename, decoder_session->bps); - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - decoder_session->bps = bps; - } - - /* sanity-check the #channels */ - if(decoder_session->channels) { - if(channels != decoder_session->channels) { - if(decoder_session->got_stream_info) - flac__utils_printf(stderr, 1, "%s: ERROR, channels is %u in frame but %u in STREAMINFO\n", decoder_session->inbasefilename, channels, decoder_session->channels); - else - flac__utils_printf(stderr, 1, "%s: ERROR, channels is %u in this frame but %u in previous frames\n", decoder_session->inbasefilename, channels, decoder_session->channels); - if(!decoder_session->continue_through_decode_errors) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } - else { - /* must not have gotten STREAMINFO, save the #channels from the frame header */ - FLAC__ASSERT(!decoder_session->got_stream_info); - decoder_session->channels = channels; - } - - /* sanity-check the sample rate */ - if(decoder_session->sample_rate < UINT32_MAX) { - if(frame->header.sample_rate != decoder_session->sample_rate) { - if(decoder_session->got_stream_info) - flac__utils_printf(stderr, 1, "%s: ERROR, sample rate is %u in frame but %u in STREAMINFO\n", decoder_session->inbasefilename, frame->header.sample_rate, decoder_session->sample_rate); - else - flac__utils_printf(stderr, 1, "%s: ERROR, sample rate is %u in this frame but %u in previous frames\n", decoder_session->inbasefilename, frame->header.sample_rate, decoder_session->sample_rate); - if(!decoder_session->continue_through_decode_errors) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } - else { - /* must not have gotten STREAMINFO, save the sample rate from the frame header */ - FLAC__ASSERT(!decoder_session->got_stream_info); - decoder_session->sample_rate = frame->header.sample_rate; - } - - /* - * limit the number of samples to accept based on --until - */ - /* if we never got the total_samples from the metadata, the skip and until specs would never have been canonicalized, so protect against that: */ - if(decoder_session->skip_specification->is_relative || !decoder_session->got_stream_info) { - if(decoder_session->skip_specification->value.samples == 0) /* special case for when no --skip was given */ - decoder_session->skip_specification->is_relative = false; /* convert to our meaning of beginning-of-stream */ - else { - flac__utils_printf(stderr, 1, "%s: ERROR, cannot use --skip because the total sample count was not found in the metadata\n", decoder_session->inbasefilename); - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } - if(decoder_session->until_specification->is_relative || !decoder_session->got_stream_info) { - if(decoder_session->until_specification->value.samples == 0) /* special case for when no --until was given */ - decoder_session->until_specification->is_relative = false; /* convert to our meaning of end-of-stream */ - else { - flac__utils_printf(stderr, 1, "%s: ERROR, cannot use --until because the total sample count was not found in the metadata\n", decoder_session->inbasefilename); - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } - FLAC__ASSERT(decoder_session->skip_specification->value.samples >= 0); - FLAC__ASSERT(decoder_session->until_specification->value.samples >= 0); - if(decoder_session->until_specification->value.samples > 0) { - const FLAC__uint64 skip = (FLAC__uint64)decoder_session->skip_specification->value.samples; - const FLAC__uint64 until = (FLAC__uint64)decoder_session->until_specification->value.samples; - const FLAC__uint64 input_samples_passed = skip + decoder_session->samples_processed; - FLAC__ASSERT(until >= input_samples_passed); - if(input_samples_passed + wide_samples > until) - wide_samples = (uint32_t)(until - input_samples_passed); - if (wide_samples == 0) { - decoder_session->abort_flag = true; - decoder_session->aborting_due_to_until = true; - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } - - if(decoder_session->analysis_mode) { - FLAC__uint64 dpos; - FLAC__stream_decoder_get_decode_position(decoder_session->decoder, &dpos); - frame_bytes = (dpos-decoder_session->decode_position); - decoder_session->decode_position = dpos; - } - - if(wide_samples > 0) { - decoder_session->samples_processed += wide_samples; - decoder_session->frame_counter++; - -#if 0 /* in case time.h with clock() isn't available for some reason */ - if(!(decoder_session->frame_counter & 0x1ff)) - print_stats(decoder_session); -#else - if((clock() - decoder_session->old_clock_t) > (CLOCKS_PER_SEC/4)) { - print_stats(decoder_session); - decoder_session->old_clock_t = clock(); - } -#endif - - - if(decoder_session->analysis_mode) { - flac__analyze_frame(frame, decoder_session->frame_counter-1, decoder_session->decode_position-frame_bytes, frame_bytes, decoder_session->aopts, fout); - } - else if(!decoder_session->test_only) { - if(shift && !decoder_session->replaygain.apply) { - for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) - for(channel = 0; channel < channels; channel++) - ((uint32_t **)buffer)[channel][wide_sample] <<= shift;/*@@@@@@un-const'ing the buffer is hacky but safe*/ - } - if(decoder_session->replaygain.apply) { - bytes_to_write = FLAC__replaygain_synthesis__apply_gain( - ubuf.u8buffer, - !is_big_endian, - is_unsigned_samples, - buffer, - wide_samples, - channels, - bps, /* source_bps */ - bps+shift, /* target_bps */ - decoder_session->replaygain.scale, - decoder_session->replaygain.spec.limiter == RGSS_LIMIT__HARD, /* hard_limit */ - decoder_session->replaygain.spec.noise_shaping != NOISE_SHAPING_NONE, /* do_dithering */ - &decoder_session->replaygain.dither_context - ); - } - /* first some special code for common cases */ - else if(is_big_endian == is_big_endian_host_ && !is_unsigned_samples && channels == 2 && bps+shift == 16) { - FLAC__int16 *buf1_ = ubuf.s16buffer + 1; - if(is_big_endian) - memcpy(ubuf.s16buffer, ((FLAC__byte*)(buffer[0]))+2, sizeof(FLAC__int32) * wide_samples - 2); - else - memcpy(ubuf.s16buffer, buffer[0], sizeof(FLAC__int32) * wide_samples); - for(sample = 0; sample < wide_samples; sample++, buf1_+=2) - *buf1_ = (FLAC__int16)buffer[1][sample]; - bytes_to_write = 4 * sample; - } - else if(is_big_endian == is_big_endian_host_ && !is_unsigned_samples && channels == 1 && bps+shift == 16) { - FLAC__int16 *buf1_ = ubuf.s16buffer; - for(sample = 0; sample < wide_samples; sample++) - *buf1_++ = (FLAC__int16)buffer[0][sample]; - bytes_to_write = 2 * sample; - } - /* generic code for the rest */ - else if(bps+shift == 16) { - if(is_unsigned_samples) { - if(channels == 2) { - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) { - ubuf.u16buffer[sample++] = (FLAC__uint16)(buffer[0][wide_sample] + 0x8000); - ubuf.u16buffer[sample++] = (FLAC__uint16)(buffer[1][wide_sample] + 0x8000); - } - } - else if(channels == 1) { - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) - ubuf.u16buffer[sample++] = (FLAC__uint16)(buffer[0][wide_sample] + 0x8000); - } - else { /* works for any 'channels' but above flavors are faster for 1 and 2 */ - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) - for(channel = 0; channel < channels; channel++, sample++) - ubuf.u16buffer[sample] = (FLAC__uint16)(buffer[channel][wide_sample] + 0x8000); - } - } - else { - if(channels == 2) { - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) { - ubuf.s16buffer[sample++] = (FLAC__int16)(buffer[0][wide_sample]); - ubuf.s16buffer[sample++] = (FLAC__int16)(buffer[1][wide_sample]); - } - } - else if(channels == 1) { - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) - ubuf.s16buffer[sample++] = (FLAC__int16)(buffer[0][wide_sample]); - } - else { /* works for any 'channels' but above flavors are faster for 1 and 2 */ - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) - for(channel = 0; channel < channels; channel++, sample++) - ubuf.s16buffer[sample] = (FLAC__int16)(buffer[channel][wide_sample]); - } - } - if(is_big_endian != is_big_endian_host_) { - uint8_t tmp; - const uint32_t bytes = sample * 2; - uint32_t b; - for(b = 0; b < bytes; b += 2) { - tmp = ubuf.u8buffer[b]; - ubuf.u8buffer[b] = ubuf.u8buffer[b+1]; - ubuf.u8buffer[b+1] = tmp; - } - } - bytes_to_write = 2 * sample; - } - else if(bps+shift == 24) { - if(is_unsigned_samples) { - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) - for(channel = 0; channel < channels; channel++, sample++) - ubuf.u32buffer[sample] = buffer[channel][wide_sample] + 0x800000; - } - else { - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) - for(channel = 0; channel < channels; channel++, sample++) - ubuf.s32buffer[sample] = buffer[channel][wide_sample]; - } - if(is_big_endian != is_big_endian_host_) { - uint8_t tmp; - const uint32_t bytes = sample * 4; - uint32_t b; - for(b = 0; b < bytes; b += 4) { - tmp = ubuf.u8buffer[b]; - ubuf.u8buffer[b] = ubuf.u8buffer[b+3]; - ubuf.u8buffer[b+3] = tmp; - tmp = ubuf.u8buffer[b+1]; - ubuf.u8buffer[b+1] = ubuf.u8buffer[b+2]; - ubuf.u8buffer[b+2] = tmp; - } - } - if(is_big_endian) { - uint32_t b, lbyte; - const uint32_t bytes = sample * 4; - for(lbyte = b = 0; b < bytes; ) { - b++; - ubuf.u8buffer[lbyte++] = ubuf.u8buffer[b++]; - ubuf.u8buffer[lbyte++] = ubuf.u8buffer[b++]; - ubuf.u8buffer[lbyte++] = ubuf.u8buffer[b++]; - } - } - else { - uint32_t b, lbyte; - const uint32_t bytes = sample * 4; - for(lbyte = b = 0; b < bytes; ) { - ubuf.u8buffer[lbyte++] = ubuf.u8buffer[b++]; - ubuf.u8buffer[lbyte++] = ubuf.u8buffer[b++]; - ubuf.u8buffer[lbyte++] = ubuf.u8buffer[b++]; - b++; - } - } - bytes_to_write = 3 * sample; - } - else if(bps+shift == 8) { - if(is_unsigned_samples) { - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) - for(channel = 0; channel < channels; channel++, sample++) - ubuf.u8buffer[sample] = (FLAC__uint8)(buffer[channel][wide_sample] + 0x80); - } - else { - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) - for(channel = 0; channel < channels; channel++, sample++) - ubuf.s8buffer[sample] = (FLAC__int8)(buffer[channel][wide_sample]); - } - bytes_to_write = sample; - } - else if(bps+shift == 32) { - if(is_unsigned_samples) { - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) - for(channel = 0; channel < channels; channel++, sample++) - ubuf.u32buffer[sample] = buffer[channel][wide_sample]; - } - else { - for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++) - for(channel = 0; channel < channels; channel++, sample++) - ubuf.s32buffer[sample] = buffer[channel][wide_sample]; - } - if(is_big_endian != is_big_endian_host_) { - uint8_t tmp; - const uint32_t bytes = sample * 4; - uint32_t b; - for(b = 0; b < bytes; b += 4) { - tmp = ubuf.u8buffer[b]; - ubuf.u8buffer[b] = ubuf.u8buffer[b+3]; - ubuf.u8buffer[b+3] = tmp; - tmp = ubuf.u8buffer[b+1]; - ubuf.u8buffer[b+1] = ubuf.u8buffer[b+2]; - ubuf.u8buffer[b+2] = tmp; - } - } - bytes_to_write = 4 * sample; - } - else { - FLAC__ASSERT(0); - /* double protection */ - decoder_session->abort_flag = true; - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } - } - if(bytes_to_write > 0) { - if(flac__utils_fwrite(ubuf.u8buffer, 1, bytes_to_write, fout) != bytes_to_write) { - /* if a pipe closed when writing to stdout, we let it go without an error message */ - if(errno == EPIPE && decoder_session->fout == stdout) - decoder_session->aborting_due_to_until = true; - decoder_session->abort_flag = true; - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - DecoderSession *decoder_session = (DecoderSession*)client_data; - - (void)decoder; - - if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { - FLAC__uint64 skip, until; - - if(decoder_session->got_stream_info){ - /* There was already a STREAMINFO received */ - flac__utils_printf(stderr, 1, "%s: ERROR, more than one STREAMINFO found\n", decoder_session->inbasefilename); - if(!decoder_session->continue_through_decode_errors) - decoder_session->abort_flag = true; - return; - } - - decoder_session->got_stream_info = true; - decoder_session->has_md5sum = memcmp(metadata->data.stream_info.md5sum, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) != 0; - decoder_session->bps = metadata->data.stream_info.bits_per_sample; - decoder_session->channels = metadata->data.stream_info.channels; - decoder_session->sample_rate = metadata->data.stream_info.sample_rate; - - if(!flac__utils_canonicalize_skip_until_specification(decoder_session->skip_specification, decoder_session->sample_rate)) { - flac__utils_printf(stderr, 1, "%s: ERROR, value of --skip is too large\n", decoder_session->inbasefilename); - decoder_session->abort_flag = true; - return; - } - FLAC__ASSERT(decoder_session->skip_specification->value.samples >= 0); - skip = (FLAC__uint64)decoder_session->skip_specification->value.samples; - - /* remember, metadata->data.stream_info.total_samples can be 0, meaning 'unknown' */ - if(metadata->data.stream_info.total_samples > 0 && skip >= metadata->data.stream_info.total_samples) { - flac__utils_printf(stderr, 1, "%s: ERROR trying to --skip more samples than in stream\n", decoder_session->inbasefilename); - decoder_session->abort_flag = true; - return; - } - else if(metadata->data.stream_info.total_samples == 0 && skip > 0) { - flac__utils_printf(stderr, 1, "%s: ERROR, can't --skip when FLAC metadata has total sample count of 0\n", decoder_session->inbasefilename); - decoder_session->abort_flag = true; - return; - } - FLAC__ASSERT(skip == 0 || 0 == decoder_session->cue_specification); - decoder_session->total_samples = metadata->data.stream_info.total_samples - skip; - - /* note that we use metadata->data.stream_info.total_samples instead of decoder_session->total_samples */ - if(!canonicalize_until_specification(decoder_session->until_specification, decoder_session->inbasefilename, decoder_session->sample_rate, skip, metadata->data.stream_info.total_samples)) { - decoder_session->abort_flag = true; - return; - } - FLAC__ASSERT(decoder_session->until_specification->value.samples >= 0); - until = (FLAC__uint64)decoder_session->until_specification->value.samples; - - if(until > 0) { - FLAC__ASSERT(decoder_session->total_samples != 0); - FLAC__ASSERT(0 == decoder_session->cue_specification); - decoder_session->total_samples -= (metadata->data.stream_info.total_samples - until); - } - - if(decoder_session->format == FORMAT_RAW && ((decoder_session->bps % 8) != 0 || decoder_session->bps < 4)) { - flac__utils_printf(stderr, 1, "%s: ERROR: bits per sample is %u, must be 8/16/24/32 for raw format output\n", decoder_session->inbasefilename, decoder_session->bps); - decoder_session->abort_flag = true; - return; - } - - if(decoder_session->bps < 4 || decoder_session->bps > 32) { - flac__utils_printf(stderr, 1, "%s: ERROR: bits per sample is %u, must be 4-32\n", decoder_session->inbasefilename, decoder_session->bps); - decoder_session->abort_flag = true; - return; - } - } - else if(metadata->type == FLAC__METADATA_TYPE_CUESHEET) { - /* remember, at this point, decoder_session->total_samples can be 0, meaning 'unknown' */ - if(decoder_session->total_samples == 0) { - flac__utils_printf(stderr, 1, "%s: ERROR can't use --cue when FLAC metadata has total sample count of 0\n", decoder_session->inbasefilename); - decoder_session->abort_flag = true; - return; - } - - flac__utils_canonicalize_cue_specification(decoder_session->cue_specification, &metadata->data.cue_sheet, decoder_session->total_samples, decoder_session->skip_specification, decoder_session->until_specification); - - FLAC__ASSERT(!decoder_session->skip_specification->is_relative); - FLAC__ASSERT(decoder_session->skip_specification->value_is_samples); - - FLAC__ASSERT(!decoder_session->until_specification->is_relative); - FLAC__ASSERT(decoder_session->until_specification->value_is_samples); - - FLAC__ASSERT(decoder_session->skip_specification->value.samples >= 0); - FLAC__ASSERT(decoder_session->until_specification->value.samples >= 0); - FLAC__ASSERT((FLAC__uint64)decoder_session->until_specification->value.samples <= decoder_session->total_samples); - FLAC__ASSERT(decoder_session->skip_specification->value.samples <= decoder_session->until_specification->value.samples); - - decoder_session->total_samples = decoder_session->until_specification->value.samples - decoder_session->skip_specification->value.samples; - } - else if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { - if (decoder_session->replaygain.spec.apply) { - double reference, gain, peak; - if (!(decoder_session->replaygain.apply = grabbag__replaygain_load_from_vorbiscomment(metadata, decoder_session->replaygain.spec.use_album_gain, /*strict=*/false, &reference, &gain, &peak))) { - flac__utils_printf(stderr, 1, "%s: WARNING: can't get %s (or even %s) ReplayGain tags\n", decoder_session->inbasefilename, decoder_session->replaygain.spec.use_album_gain? "album":"track", decoder_session->replaygain.spec.use_album_gain? "track":"album"); - if(decoder_session->treat_warnings_as_errors) { - decoder_session->abort_flag = true; - return; - } - } - else if(decoder_session->bps == 0) { - flac__utils_printf(stderr, 1, "%s: WARNING: can't apply ReplayGain, bit-per-sample value is invalid\n", decoder_session->inbasefilename); - if(decoder_session->treat_warnings_as_errors) { - decoder_session->abort_flag = true; - return; - } - } - else { - const char *ls[] = { "no", "peak", "hard" }; - const char *ns[] = { "no", "low", "medium", "high" }; - decoder_session->replaygain.scale = grabbag__replaygain_compute_scale_factor(peak, gain, decoder_session->replaygain.spec.preamp, decoder_session->replaygain.spec.limiter == RGSS_LIMIT__PEAK); - FLAC__ASSERT(decoder_session->bps > 0 && decoder_session->bps <= 32); - FLAC__replaygain_synthesis__init_dither_context(&decoder_session->replaygain.dither_context, decoder_session->bps, decoder_session->replaygain.spec.noise_shaping); - flac__utils_printf(stderr, 1, "%s: INFO: applying %s ReplayGain (gain=%0.2fdB+preamp=%0.1fdB, %s noise shaping, %s limiting) to output\n", decoder_session->inbasefilename, decoder_session->replaygain.spec.use_album_gain? "album":"track", gain, decoder_session->replaygain.spec.preamp, ns[decoder_session->replaygain.spec.noise_shaping], ls[decoder_session->replaygain.spec.limiter]); - flac__utils_printf(stderr, 1, "%s: WARNING: applying ReplayGain is not lossless\n", decoder_session->inbasefilename); - /* don't check if(decoder_session->treat_warnings_as_errors) because the user explicitly asked for it */ - } - } - (void)flac__utils_get_channel_mask_tag(metadata, &decoder_session->channel_mask); - } - else if(metadata->type == FLAC__METADATA_TYPE_APPLICATION && decoder_session->warn_user_about_foreign_metadata) { - /* Foreign metadata signalling */ - flac__utils_printf(stderr, 1, "%s: WARNING: found foreign metadata, use --keep-foreign-metadata to restore\n", decoder_session->inbasefilename); - decoder_session->warn_user_about_foreign_metadata = false; - } -} - -void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - DecoderSession *decoder_session = (DecoderSession*)client_data; - (void)decoder; - if(!decoder_session->error_callback_suppress_messages) { - stats_print_name(1, decoder_session->inbasefilename); - flac__utils_printf(stderr, 1, "*** Got error code %d:%s\n", status, FLAC__StreamDecoderErrorStatusString[status]); - } - if(!decoder_session->continue_through_decode_errors) { - /* if we got a sync error while looking for metadata, either it's not a FLAC file (more likely) or the file is corrupted */ - if( - !decoder_session->error_callback_suppress_messages && - status == FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC && - FLAC__stream_decoder_get_state(decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA - ) { - flac__utils_printf(stderr, 1, - "\n" - "The input file is either not a FLAC file or is corrupted. If you are\n" - "convinced it is a FLAC file, you can rerun the same command and add the\n" - "-F parameter to try and recover as much as possible from the file.\n" - ); - decoder_session->error_callback_suppress_messages = true; - } - else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM) - decoder_session->aborting_due_to_unparseable = true; - decoder_session->abort_flag = true; - } -} - -void print_error_with_init_status(const DecoderSession *d, const char *message, FLAC__StreamDecoderInitStatus init_status) -{ - const int ilen = strlen(d->inbasefilename) + 1; - - flac__utils_printf(stderr, 1, "\n%s: %s\n", d->inbasefilename, message); - - flac__utils_printf(stderr, 1, "%*s init status = %s\n", ilen, "", FLAC__StreamDecoderInitStatusString[init_status]); - - /* print out some more info for some errors: */ - if (init_status == FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE) { - flac__utils_printf(stderr, 1, - "\n" -#ifdef _WIN32 - "An error occurred opening the input file; it is likely that it does not exist,\n" - "is not readable or has a filename that exceeds the path length limit.\n" -#else - "An error occurred opening the input file; it is likely that it does not exist\n" - "or is not readable.\n" -#endif - ); - } -} - -void print_error_with_state(const DecoderSession *d, const char *message) -{ - const int ilen = strlen(d->inbasefilename) + 1; - - flac__utils_printf(stderr, 1, "\n%s: %s\n", d->inbasefilename, message); - flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", FLAC__stream_decoder_get_resolved_state_string(d->decoder)); - - /* print out some more info for some errors: */ - if (d->aborting_due_to_unparseable) { - flac__utils_printf(stderr, 1, - "\n" - "The FLAC stream may have been created by a more advanced encoder. Try\n" - " metaflac --show-vendor-tag %s\n" - "If the version number is greater than %s, this decoder is probably\n" - "not able to decode the file. If the version number is not, the file\n" - "may be corrupted, or you may have found a bug. In this case please\n" - "submit a bug report to\n" - " https://github.com/xiph/flac/issues\n" - "Make sure to use the \"Monitor\" feature to monitor the bug status.\n", - d->inbasefilename, FLAC__VERSION_STRING - ); - } -} - -void print_stats(const DecoderSession *decoder_session) -{ - if(flac__utils_verbosity_ >= 2) { - const double progress = (double)decoder_session->samples_processed / (double)decoder_session->total_samples * 100.0; - - if(decoder_session->total_samples > 0) { - if ((uint32_t)floor(progress + 0.5) == 100) - return; - - stats_print_name(2, decoder_session->inbasefilename); - stats_print_info(2, "%s%u%% complete", - decoder_session->test_only? "testing, " : decoder_session->analysis_mode? "analyzing, " : "", - (uint32_t)floor(progress + 0.5) - ); - } - else { - stats_print_name(2, decoder_session->inbasefilename); - stats_print_info(2, "%s %" PRIu64 " samples", - decoder_session->test_only? "tested" : decoder_session->analysis_mode? "analyzed" : "wrote", - decoder_session->samples_processed - ); - } - } -} diff --git a/flac/src/flac/decode.h b/flac/src/flac/decode.h deleted file mode 100644 index 24f5723..0000000 --- a/flac/src/flac/decode.h +++ /dev/null @@ -1,73 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 flac__decode_h -#define flac__decode_h - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "analyze.h" -#include "foreign_metadata.h" -#include "utils.h" -#include "share/replaygain_synthesis.h" - - -typedef struct { - FLAC__bool apply; - FLAC__bool use_album_gain; /* false => use track gain */ - enum { RGSS_LIMIT__NONE, RGSS_LIMIT__PEAK, RGSS_LIMIT__HARD} limiter; - NoiseShaping noise_shaping; - double preamp; -} replaygain_synthesis_spec_t; - -typedef struct { - FLAC__bool treat_warnings_as_errors; - FLAC__bool continue_through_decode_errors; - replaygain_synthesis_spec_t replaygain_synthesis_spec; -#if FLAC__HAS_OGG - FLAC__bool is_ogg; - FLAC__bool use_first_serial_number; - long serial_number; -#endif - utils__SkipUntilSpecification skip_specification; - utils__SkipUntilSpecification until_specification; - FLAC__bool has_cue_specification; - utils__CueSpecification cue_specification; - FLAC__bool channel_map_none; /* --channel-map=none specified, eventually will expand to take actual channel map */ - FLAC__bool relaxed_foreign_metadata_handling; - FileSubFormat force_subformat; - - FileFormat format; - union { - struct { - FLAC__bool is_big_endian; - FLAC__bool is_unsigned_samples; - } raw; - struct { - foreign_metadata_t *foreign_metadata; /* NULL unless --keep-foreign-metadata requested */ - } iff; - } format_options; -} decode_options_t; - -/* outfile == 0 => test only */ -int flac__decode_file(const char *infilename, const char *outfilename, FLAC__bool analysis_mode, analysis_options aopts, decode_options_t options); - -#endif diff --git a/flac/src/flac/encode.c b/flac/src/flac/encode.c deleted file mode 100644 index a945b35..0000000 --- a/flac/src/flac/encode.c +++ /dev/null @@ -1,2852 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include /* for LONG_MAX */ -#include /* for floor() */ -#include /* for FILE etc. */ -#include /* for malloc */ -#include /* for strcmp(), strerror() */ -#include /* for clock() */ -#include -#include "FLAC/all.h" -#include "share/alloc.h" -#include "share/grabbag.h" -#include "share/compat.h" -#include "share/private.h" -#include "share/safe_str.h" -#include "share/endswap.h" -#include "encode.h" - -#ifdef min -#undef min -#endif -#define min(x,y) ((x)<(y)?(x):(y)) -#ifdef max -#undef max -#endif -#define max(x,y) ((x)>(y)?(x):(y)) - -/* this MUST be < 2^sizeof(size_t) / ( FLAC__MAX_CHANNELS * (FLAC__MAX_BITS_PER_SAMPLE/8) ) */ -#define CHUNK_OF_SAMPLES 2048 - -typedef struct { - uint32_t sample_rate; - uint32_t channels; - uint32_t bits_per_sample; /* width of sample point, including 'shift' bits, valid bps is bits_per_sample-shift */ - uint32_t shift; /* # of LSBs samples have been shifted left by */ - uint32_t bytes_per_wide_sample; /* for convenience, always == channels*((bps+7)/8), or 0 if N/A to input format (like FLAC) */ - FLAC__bool is_unsigned_samples; - FLAC__bool is_big_endian; - FLAC__uint32 channel_mask; -} SampleInfo; - -/* this is the client_data attached to the FLAC decoder when encoding from a FLAC file */ -typedef struct { - FLAC__off_t filesize; - const FLAC__byte *lookahead; - uint32_t lookahead_length; - size_t num_metadata_blocks; - FLAC__StreamMetadata *metadata_blocks[1024]; /*@@@ BAD MAGIC number */ - FLAC__uint64 samples_left_to_process; - FLAC__bool fatal_error; -} FLACDecoderData; - -typedef struct { -#if FLAC__HAS_OGG - FLAC__bool use_ogg; -#endif - FLAC__bool verify; - FLAC__bool is_stdout; - FLAC__bool outputfile_opened; /* true if we successfully opened the output file and we want it to be deleted if there is an error */ - const char *inbasefilename; - const char *infilename; - const char *outfilename; - - FLAC__bool treat_warnings_as_errors; - FLAC__bool continue_through_decode_errors; - FLAC__bool replay_gain; - FLAC__uint64 total_samples_to_encode; /* (i.e. "wide samples" aka "sample frames") WATCHOUT: may be 0 to mean 'unknown' */ - FLAC__uint64 unencoded_size; /* an estimate of the input size, only used in the progress indicator */ - FLAC__uint64 bytes_written; - FLAC__uint64 samples_written; -#if 0 /* in case time.h with clock() isn't available for some reason */ - uint32_t stats_frames_interval; - uint32_t old_frames_written; -#else - clock_t old_clock_t; -#endif - - SampleInfo info; - - FileFormat format; - union { - struct { - FLAC__uint64 data_bytes; - } iff; - struct { - FLAC__StreamDecoder *decoder; - FLACDecoderData client_data; - } flac; - } fmt; - - FLAC__StreamEncoder *encoder; - - FILE *fin; - FLAC__StreamMetadata *seek_table_template; - double progress, compression_ratio; -} EncoderSession; - -const int FLAC_ENCODE__DEFAULT_PADDING = 8192; - -static FLAC__bool is_big_endian_host_; - -#define UBUFFER_INT8_SIZE 0x10000 - -static union { - FLAC__int8 s8[UBUFFER_INT8_SIZE]; - FLAC__uint8 u8[UBUFFER_INT8_SIZE]; - FLAC__int16 s16[UBUFFER_INT8_SIZE/2]; - FLAC__uint16 u16[UBUFFER_INT8_SIZE/2]; - FLAC__int32 s32[UBUFFER_INT8_SIZE/4]; - FLAC__uint32 u32[UBUFFER_INT8_SIZE/4]; -} ubuffer; - - -static FLAC__int32 in_[FLAC__MAX_CHANNELS][CHUNK_OF_SAMPLES]; -static FLAC__int32 *input_[FLAC__MAX_CHANNELS]; - - -/* - * local routines - */ -static FLAC__bool EncoderSession_construct(EncoderSession *e, encode_options_t options, FLAC__off_t infilesize, FILE *infile, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, uint32_t lookahead_length); -static void EncoderSession_destroy(EncoderSession *e); -static int EncoderSession_finish_ok(EncoderSession *e, foreign_metadata_t *foreign_metadata, FLAC__bool error_on_compression_fail); -static int EncoderSession_finish_error(EncoderSession *e); -static FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t options); -static FLAC__bool EncoderSession_process(EncoderSession *e, const FLAC__int32 * const buffer[], uint32_t samples); -static FLAC__bool EncoderSession_format_is_iff(const EncoderSession *e); -static FLAC__bool convert_to_seek_table_template(const char *requested_seek_points, int num_requested_seek_points, FLAC__StreamMetadata *cuesheet, EncoderSession *e); -static FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, uint32_t sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input); -static FLAC__bool verify_metadata(const EncoderSession *e, FLAC__StreamMetadata **metadata, uint32_t num_metadata); -static FLAC__bool format_input(FLAC__int32 *dest[], uint32_t wide_samples, FLAC__bool is_big_endian, FLAC__bool is_unsigned_samples, uint32_t channels, uint32_t bps, uint32_t shift, size_t *channel_map); -static void encoder_progress_callback(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate, void *client_data); -static FLAC__StreamDecoderReadStatus flac_decoder_read_callback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); -static FLAC__StreamDecoderSeekStatus flac_decoder_seek_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); -static FLAC__StreamDecoderTellStatus flac_decoder_tell_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); -static FLAC__StreamDecoderLengthStatus flac_decoder_length_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); -static FLAC__bool flac_decoder_eof_callback(const FLAC__StreamDecoder *decoder, void *client_data); -static FLAC__StreamDecoderWriteStatus flac_decoder_write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); -static void flac_decoder_metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); -static void flac_decoder_error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); -static FLAC__bool parse_cuesheet(FLAC__StreamMetadata **cuesheet, const char *cuesheet_filename, const char *inbasefilename, uint32_t sample_rate, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset, FLAC__bool treat_warnings_as_errors); -static void print_stats(const EncoderSession *encoder_session); -static void print_error_with_init_status(const EncoderSession *e, const char *message, FLAC__StreamEncoderInitStatus init_status); -static void print_error_with_state(const EncoderSession *e, const char *message); -static void print_verify_error(EncoderSession *e); -static FLAC__bool read_bytes(FILE *f, FLAC__byte *buf, size_t n, FLAC__bool eof_ok, const char *fn); -static FLAC__bool read_uint16(FILE *f, FLAC__bool big_endian, FLAC__uint16 *val, const char *fn); -static FLAC__bool read_uint32(FILE *f, FLAC__bool big_endian, FLAC__uint32 *val, const char *fn); -static FLAC__bool read_uint64(FILE *f, FLAC__bool big_endian, FLAC__uint64 *val, const char *fn); -static FLAC__bool read_sane_extended(FILE *f, FLAC__uint32 *val, const char *fn); -static FLAC__bool fskip_ahead(FILE *f, FLAC__uint64 offset); -static uint32_t count_channel_mask_bits(FLAC__uint32 mask); - -static FLAC__bool get_sample_info_raw(EncoderSession *e, encode_options_t options) -{ - e->info.sample_rate = options.format_options.raw.sample_rate; - e->info.channels = options.format_options.raw.channels; - e->info.bits_per_sample = options.format_options.raw.bps; - e->info.shift = 0; - e->info.bytes_per_wide_sample = options.format_options.raw.channels * ((options.format_options.raw.bps+7)/8); - e->info.is_unsigned_samples = options.format_options.raw.is_unsigned_samples; - e->info.is_big_endian = options.format_options.raw.is_big_endian; - e->info.channel_mask = 0; - - return true; -} - -static FLAC__bool get_sample_info_wave(EncoderSession *e, encode_options_t options) -{ - FLAC__bool got_fmt_chunk = false, got_data_chunk = false, got_ds64_chunk = false; - uint32_t sample_rate = 0, channels = 0, bps = 0, shift = 0, block_align = 0; - FLAC__uint32 channel_mask = 0; - FLAC__uint64 ds64_data_size = 0; - - e->info.is_unsigned_samples = false; - e->info.is_big_endian = false; - - if(e->format == FORMAT_WAVE64) { - /* - * lookahead[] already has "riff\x2E\x91\xCF\x11\xA5\xD6\x28\xDB", skip over remaining header - */ - if(!fskip_ahead(e->fin, 16+8+16-12)) { /* riff GUID + riff size + WAVE GUID - lookahead */ - flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping over remaining \"riff\" header\n", e->inbasefilename); - return false; - } - } - /* else lookahead[] already has "RIFFxxxxWAVE" or "RF64xxxxWAVE" */ - - while(!feof(e->fin) && !got_data_chunk) { - /* chunk IDs are 4 bytes for WAVE/RF64, 16 for Wave64 */ - /* for WAVE/RF64 we want the 5th char zeroed so we can treat it like a C string */ - char chunk_id[16] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; - - if(!read_bytes(e->fin, (FLAC__byte*)chunk_id, e->format==FORMAT_WAVE64?16:4, /*eof_ok=*/true, e->inbasefilename)) { - flac__utils_printf(stderr, 1, "%s: ERROR: incomplete chunk identifier\n", e->inbasefilename); - return false; - } - if(feof(e->fin)) - break; - - if(e->format == FORMAT_RF64 && !memcmp(chunk_id, "ds64", 4)) { /* RF64 64-bit sizes chunk */ - FLAC__uint32 xx, data_bytes; - - if(got_ds64_chunk) { - flac__utils_printf(stderr, 1, "%s: ERROR: file has multiple 'ds64' chunks\n", e->inbasefilename); - return false; - } - if(got_fmt_chunk) { - flac__utils_printf(stderr, 1, "%s: ERROR: 'ds64' chunk appears after 'fmt ' or 'data' chunk\n", e->inbasefilename); - return false; - } - - /* ds64 chunk size */ - if(!read_uint32(e->fin, /*big_endian=*/false, &xx, e->inbasefilename)) - return false; - data_bytes = xx; - if(data_bytes < 28) { - flac__utils_printf(stderr, 1, "%s: ERROR: non-standard 'ds64' chunk has length = %u\n", e->inbasefilename, (uint32_t)data_bytes); - return false; - } - if(data_bytes & 1) /* should never happen, but enforce WAVE alignment rules */ - data_bytes++; - - /* RIFF 64-bit size, lo/hi */ - if(!read_uint32(e->fin, /*big_endian=*/false, &xx, e->inbasefilename)) - return false; - if(!read_uint32(e->fin, /*big_endian=*/false, &xx, e->inbasefilename)) - return false; - - /* 'data' 64-bit size */ - if(!read_uint64(e->fin, /*big_endian=*/false, &ds64_data_size, e->inbasefilename)) - return false; - - data_bytes -= 16; - - /* skip any extra data in the ds64 chunk */ - if(!fskip_ahead(e->fin, data_bytes)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping over extra 'ds64' data\n", e->inbasefilename); - return false; - } - - got_ds64_chunk = true; - } - else if( - !memcmp(chunk_id, "fmt ", 4) && - (e->format!=FORMAT_WAVE64 || !memcmp(chunk_id, "fmt \xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 16)) - ) { /* format chunk */ - FLAC__uint16 x; - FLAC__uint32 xx, data_bytes; - FLAC__uint16 wFormatTag; /* wFormatTag word from the 'fmt ' chunk */ - - if(got_fmt_chunk) { - flac__utils_printf(stderr, 1, "%s: ERROR: file has multiple 'fmt ' chunks\n", e->inbasefilename); - return false; - } - - /* see - * http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html - * http://windowssdk.msdn.microsoft.com/en-us/library/ms713497.aspx - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/audio_r/hh/Audio_r/aud-prop_d40f094e-44f9-4baa-8a15-03e4fb369501.xml.asp - * - * WAVEFORMAT is - * 4 byte: chunk size - * 2 byte: format type: 1 for WAVE_FORMAT_PCM, 65534 for WAVE_FORMAT_EXTENSIBLE - * 2 byte: # channels - * 4 byte: sample rate (Hz) - * 4 byte: avg bytes per sec - * 2 byte: block align - * 2 byte: bits per sample (not necessarily all significant) - * WAVEFORMATEX adds - * 2 byte: extension size in bytes (usually 0 for WAVEFORMATEX and 22 for WAVEFORMATEXTENSIBLE with PCM) - * WAVEFORMATEXTENSIBLE adds - * 2 byte: valid bits per sample - * 4 byte: channel mask - * 16 byte: subformat GUID, first 2 bytes have format type, 1 being PCM - * - * Current spec says WAVEFORMATEX with PCM must have bps == 8 or 16, or any multiple of 8 for WAVEFORMATEXTENSIBLE. - * Lots of old broken WAVEs/apps have don't follow it, e.g. 20 bps but a block align of 3/6 for mono/stereo. - * - * Block align for WAVE_FORMAT_PCM or WAVE_FORMAT_EXTENSIBLE is also supposed to be channels*bps/8 - * - * If the channel mask has more set bits than # of channels, the extra MSBs are ignored. - * If the channel mask has less set bits than # of channels, the extra channels are unassigned to any speaker. - * - * Data is supposed to be uint32_t for bps <= 8 else signed. - */ - - /* fmt chunk size */ - if(!read_uint32(e->fin, /*big_endian=*/false, &xx, e->inbasefilename)) - return false; - data_bytes = xx; - if(e->format == FORMAT_WAVE64) { - /* other half of the size field should be 0 */ - if(!read_uint32(e->fin, /*big_endian=*/false, &xx, e->inbasefilename)) - return false; - if(xx) { - flac__utils_printf(stderr, 1, "%s: ERROR: freakishly large Wave64 'fmt ' chunk has length = 0x%08X%08X\n", e->inbasefilename, (uint32_t)xx, (uint32_t)data_bytes); - return false; - } - /* subtract size of header */ - if (data_bytes < 16+8) { - flac__utils_printf(stderr, 1, "%s: ERROR: freakishly small Wave64 'fmt ' chunk has length = 0x%08X%08X\n", e->inbasefilename, (uint32_t)xx, (uint32_t)data_bytes); - return false; - } - data_bytes -= (16+8); - } - if(data_bytes < 16 || data_bytes > (UINT32_MAX-8)) { - flac__utils_printf(stderr, 1, "%s: ERROR: non-standard 'fmt ' chunk has length = %u\n", e->inbasefilename, (uint32_t)data_bytes); - return false; - } - if(e->format != FORMAT_WAVE64) { - if(data_bytes & 1) /* should never happen, but enforce WAVE alignment rules */ - data_bytes++; - } - else { /* Wave64 */ - data_bytes = (data_bytes+7) & (~7u); /* should never happen, but enforce Wave64 alignment rules */ - } - - /* format code */ - if(!read_uint16(e->fin, /*big_endian=*/false, &wFormatTag, e->inbasefilename)) - return false; - if(wFormatTag != 1 /*WAVE_FORMAT_PCM*/ && wFormatTag != 65534 /*WAVE_FORMAT_EXTENSIBLE*/) { - flac__utils_printf(stderr, 1, "%s: ERROR: unsupported format type %u\n", e->inbasefilename, (uint32_t)wFormatTag); - return false; - } - - /* number of channels */ - if(!read_uint16(e->fin, /*big_endian=*/false, &x, e->inbasefilename)) - return false; - channels = (uint32_t)x; - - /* sample rate */ - if(!read_uint32(e->fin, /*big_endian=*/false, &xx, e->inbasefilename)) - return false; - sample_rate = xx; - - /* avg bytes per second (ignored) */ - if(!read_uint32(e->fin, /*big_endian=*/false, &xx, e->inbasefilename)) - return false; - /* block align */ - if(!read_uint16(e->fin, /*big_endian=*/false, &x, e->inbasefilename)) - return false; - block_align = x; - /* bits per sample */ - if(!read_uint16(e->fin, /*big_endian=*/false, &x, e->inbasefilename)) - return false; - bps = (uint32_t)x; - - e->info.is_unsigned_samples = (bps <= 8); - - if(wFormatTag == 1) { - if(bps != 8 && bps != 16) { - if(bps == 24 || bps == 32) { - /* let these slide with a warning since they're unambiguous */ - flac__utils_printf(stderr, 1, "%s: WARNING: legacy WAVE file has format type %u but bits-per-sample=%u\n", e->inbasefilename, (uint32_t)wFormatTag, bps); - if(e->treat_warnings_as_errors) - return false; - } - else { - /* @@@ we could add an option to specify left- or right-justified blocks so we knew how to set 'shift' */ - flac__utils_printf(stderr, 1, "%s: ERROR: legacy WAVE file has format type %u but bits-per-sample=%u\n", e->inbasefilename, (uint32_t)wFormatTag, bps); - return false; - } - } - if((bps+7)/8 * channels != block_align) { - flac__utils_printf(stderr, 1, "%s: ERROR: legacy WAVE file has block alignment=%u, bits-per-sample=%u, channels=%u\n", e->inbasefilename, (uint32_t)wFormatTag, block_align, bps, channels); - return false; - } - if(channels > 2 && !options.channel_map_none) { - flac__utils_printf(stderr, 1, "%s: ERROR: WAVE has >2 channels but is not WAVE_FORMAT_EXTENSIBLE; cannot assign channels\n", e->inbasefilename); - return false; - } - FLAC__ASSERT(data_bytes >= 16); - data_bytes -= 16; - } - else { - if(data_bytes < 40) { - flac__utils_printf(stderr, 1, "%s: ERROR: invalid WAVEFORMATEXTENSIBLE chunk with size %u\n", e->inbasefilename, (uint32_t)data_bytes); - return false; - } - /* cbSize */ - if(!read_uint16(e->fin, /*big_endian=*/false, &x, e->inbasefilename)) - return false; - if(x < 22) { - flac__utils_printf(stderr, 1, "%s: ERROR: invalid WAVEFORMATEXTENSIBLE chunk with cbSize %u\n", e->inbasefilename, (uint32_t)x); - return false; - } - /* valid bps */ - if(!read_uint16(e->fin, /*big_endian=*/false, &x, e->inbasefilename)) - return false; - if((uint32_t)x > bps) { - flac__utils_printf(stderr, 1, "%s: ERROR: invalid WAVEFORMATEXTENSIBLE chunk with wValidBitsPerSample (%u) > wBitsPerSample (%u)\n", e->inbasefilename, (uint32_t)x, bps); - return false; - } - shift = bps - (uint32_t)x; - /* channel mask */ - if(!read_uint32(e->fin, /*big_endian=*/false, &channel_mask, e->inbasefilename)) - return false; - - if(count_channel_mask_bits(channel_mask) > channels) { - flac__utils_printf(stderr, 1, "%s: WARNING: WAVEFORMATEXTENSIBLE chunk: channel mask 0x%04X has extra bits for non-existant channels (#channels=%u)\n", e->inbasefilename, (uint32_t)channel_mask, channels); - if(e->treat_warnings_as_errors) - return false; - } - /* first part of GUID */ - if(!read_uint16(e->fin, /*big_endian=*/false, &x, e->inbasefilename)) - return false; - if(x != 1) { - flac__utils_printf(stderr, 1, "%s: ERROR: unsupported WAVEFORMATEXTENSIBLE chunk with non-PCM format %u\n", e->inbasefilename, (uint32_t)x); - return false; - } - data_bytes -= 26; - } - - e->info.bytes_per_wide_sample = channels * (bps / 8); - - /* skip any extra data in the fmt chunk */ - if(!fskip_ahead(e->fin, data_bytes)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping over extra 'fmt' data\n", e->inbasefilename); - return false; - } - - got_fmt_chunk = true; - } - else if( - !memcmp(chunk_id, "data", 4) && - (e->format!=FORMAT_WAVE64 || !memcmp(chunk_id, "data\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 16)) - ) { /* data chunk */ - FLAC__uint32 xx; - FLAC__uint64 data_bytes; - - if(!got_fmt_chunk) { - flac__utils_printf(stderr, 1, "%s: ERROR: got 'data' chunk before 'fmt' chunk\n", e->inbasefilename); - return false; - } - - /* data size */ - if(e->format != FORMAT_WAVE64) { - if(!read_uint32(e->fin, /*big_endian=*/false, &xx, e->inbasefilename)) - return false; - data_bytes = xx; - } - else { /* Wave64 */ - if(!read_uint64(e->fin, /*big_endian=*/false, &data_bytes, e->inbasefilename)) - return false; - /* subtract size of header */ - if (data_bytes < 16+8) { - flac__utils_printf(stderr, 1, "%s: ERROR: freakishly small Wave64 'data' chunk has length = 0x00000000%08X\n", e->inbasefilename, (uint32_t)data_bytes); - return false; - } - data_bytes -= (16+8); - } - if(e->format == FORMAT_RF64) { - if(!got_ds64_chunk) { - flac__utils_printf(stderr, 1, "%s: ERROR: RF64 file has no 'ds64' chunk before 'data' chunk\n", e->inbasefilename); - return false; - } - if(data_bytes == 0xffffffff) - data_bytes = ds64_data_size; - } - if(options.ignore_chunk_sizes) { - if(data_bytes) { - flac__utils_printf(stderr, 1, "%s: WARNING: 'data' chunk has non-zero size, using --ignore-chunk-sizes is probably a bad idea\n", e->inbasefilename, chunk_id); - if(e->treat_warnings_as_errors) - return false; - } - data_bytes = (FLAC__uint64)0 - (FLAC__uint64)e->info.bytes_per_wide_sample; /* max out data_bytes; we'll use EOF as signal to stop reading */ - } - else if(0 == data_bytes) { - flac__utils_printf(stderr, 1, "%s: ERROR: 'data' chunk has size of 0\n", e->inbasefilename); - return false; - } - - e->fmt.iff.data_bytes = data_bytes; - - got_data_chunk = true; - break; - } - else { - FLAC__uint32 xx; - FLAC__uint64 skip; - if(!options.format_options.iff.foreign_metadata) { - if(e->format != FORMAT_WAVE64) - flac__utils_printf(stderr, 1, "%s: WARNING: skipping unknown chunk '%s' (use --keep-foreign-metadata to keep)\n", e->inbasefilename, chunk_id); - else - flac__utils_printf(stderr, 1, "%s: WARNING: skipping unknown chunk %02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X (use --keep-foreign-metadata to keep)\n", - e->inbasefilename, - (uint32_t)((const uint8_t *)chunk_id)[3], - (uint32_t)((const uint8_t *)chunk_id)[2], - (uint32_t)((const uint8_t *)chunk_id)[1], - (uint32_t)((const uint8_t *)chunk_id)[0], - (uint32_t)((const uint8_t *)chunk_id)[5], - (uint32_t)((const uint8_t *)chunk_id)[4], - (uint32_t)((const uint8_t *)chunk_id)[7], - (uint32_t)((const uint8_t *)chunk_id)[6], - (uint32_t)((const uint8_t *)chunk_id)[9], - (uint32_t)((const uint8_t *)chunk_id)[8], - (uint32_t)((const uint8_t *)chunk_id)[10], - (uint32_t)((const uint8_t *)chunk_id)[11], - (uint32_t)((const uint8_t *)chunk_id)[12], - (uint32_t)((const uint8_t *)chunk_id)[13], - (uint32_t)((const uint8_t *)chunk_id)[14], - (uint32_t)((const uint8_t *)chunk_id)[15] - ); - if(e->treat_warnings_as_errors) - return false; - } - - /* chunk size */ - if(e->format != FORMAT_WAVE64) { - if(!read_uint32(e->fin, /*big_endian=*/false, &xx, e->inbasefilename)) - return false; - skip = xx; - skip += skip & 1; - } - else { /* Wave64 */ - if(!read_uint64(e->fin, /*big_endian=*/false, &skip, e->inbasefilename)) - return false; - skip = (skip+7) & (~(FLAC__uint64)7); - /* subtract size of header */ - if (skip < 16+8) { - flac__utils_printf(stderr, 1, "%s: ERROR: freakishly small Wave64 chunk has length = 0x00000000%08X\n", e->inbasefilename, (uint32_t)skip); - return false; - } - skip -= (16+8); - } - if(skip) { - if(!fskip_ahead(e->fin, skip)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping over chunk\n", e->inbasefilename); - return false; - } - } - } - } - - if(!got_fmt_chunk) { - flac__utils_printf(stderr, 1, "%s: ERROR: didn't find fmt chunk\n", e->inbasefilename); - return false; - } - if(!got_data_chunk) { - flac__utils_printf(stderr, 1, "%s: ERROR: didn't find data chunk\n", e->inbasefilename); - return false; - } - - e->info.sample_rate = sample_rate; - e->info.channels = channels; - e->info.bits_per_sample = bps; - e->info.shift = shift; - e->info.channel_mask = channel_mask; - - return true; -} - -static FLAC__bool get_sample_info_aiff(EncoderSession *e, encode_options_t options) -{ - FLAC__bool got_comm_chunk = false, got_ssnd_chunk = false; - uint32_t sample_rate = 0, channels = 0, bps = 0, shift = 0; - FLAC__uint64 sample_frames = 0; - FLAC__uint32 channel_mask = 0; - - e->info.is_unsigned_samples = false; - e->info.is_big_endian = true; - - /* - * lookahead[] already has "FORMxxxxAIFF", do chunks - */ - while(!feof(e->fin) && !got_ssnd_chunk) { - char chunk_id[5] = { '\0', '\0', '\0', '\0', '\0' }; /* one extra byte for terminating NUL so we can also treat it like a C string */ - if(!read_bytes(e->fin, (FLAC__byte*)chunk_id, 4, /*eof_ok=*/true, e->inbasefilename)) { - flac__utils_printf(stderr, 1, "%s: ERROR: incomplete chunk identifier\n", e->inbasefilename); - return false; - } - if(feof(e->fin)) - break; - - if(!memcmp(chunk_id, "COMM", 4)) { /* common chunk */ - FLAC__uint16 x; - FLAC__uint32 xx; - uint64_t skip; - const FLAC__bool is_aifc = e->format == FORMAT_AIFF_C; - const FLAC__uint32 minimum_comm_size = (is_aifc? 22 : 18); - - if(got_comm_chunk) { - flac__utils_printf(stderr, 1, "%s: ERROR: file has multiple 'COMM' chunks\n", e->inbasefilename); - return false; - } - - /* COMM chunk size */ - if(!read_uint32(e->fin, /*big_endian=*/true, &xx, e->inbasefilename)) - return false; - else if(xx < minimum_comm_size) { - flac__utils_printf(stderr, 1, "%s: ERROR: non-standard %s 'COMM' chunk has length = %u\n", e->inbasefilename, is_aifc? "AIFF-C" : "AIFF", (uint32_t)xx); - return false; - } - else if(!is_aifc && xx != minimum_comm_size) { - flac__utils_printf(stderr, 1, "%s: WARNING: non-standard %s 'COMM' chunk has length = %u, expected %u\n", e->inbasefilename, is_aifc? "AIFF-C" : "AIFF", (uint32_t)xx, minimum_comm_size); - if(e->treat_warnings_as_errors) - return false; - } - skip = (xx-minimum_comm_size)+(xx & 1); - - /* number of channels */ - if(!read_uint16(e->fin, /*big_endian=*/true, &x, e->inbasefilename)) - return false; - channels = (uint32_t)x; - if(channels > 2 && !options.channel_map_none) { - flac__utils_printf(stderr, 1, "%s: ERROR: unsupported number of channels %u for AIFF\n", e->inbasefilename, channels); - return false; - } - - /* number of sample frames */ - if(!read_uint32(e->fin, /*big_endian=*/true, &xx, e->inbasefilename)) - return false; - sample_frames = xx; - - /* bits per sample */ - if(!read_uint16(e->fin, /*big_endian=*/true, &x, e->inbasefilename)) - return false; - bps = (uint32_t)x; - shift = (bps%8)? 8-(bps%8) : 0; /* SSND data is always byte-aligned, left-justified but format_input() will double-check */ - bps += shift; - - /* sample rate */ - if(!read_sane_extended(e->fin, &xx, e->inbasefilename)) - return false; - sample_rate = xx; - - /* check compression type for AIFF-C */ - if(is_aifc) { - if(!read_uint32(e->fin, /*big_endian=*/true, &xx, e->inbasefilename)) - return false; - if(xx == 0x736F7774) /* "sowt" */ - e->info.is_big_endian = false; - else if(xx == 0x4E4F4E45) /* "NONE" */ - ; /* nothing to do, we already default to big-endian */ - else { - flac__utils_printf(stderr, 1, "%s: ERROR: can't handle AIFF-C compression type \"%c%c%c%c\"\n", e->inbasefilename, (char)(xx>>24), (char)((xx>>16)&8), (char)((xx>>8)&8), (char)(xx&8)); - return false; - } - } - - /* set channel mapping */ - /* FLAC order follows SMPTE and WAVEFORMATEXTENSIBLE but with fewer channels, which are: */ - /* front left, front right, center, LFE, back left, back right, surround left, surround right */ - /* specs say the channel ordering is: - * 1 2 3 4 5 6 - * ___________________________________________________ - * 2 stereo l r - * 3 l r c - * 4 l c r S - * quad (ambiguous with 4ch) Fl Fr Bl Br - * 5 Fl Fr Fc Sl Sr - * 6 l lc c r rc S - * l:left r:right c:center Fl:front-left Fr:front-right Bl:back-left Br:back-right Lc:left-center Rc:right-center S:surround - * so we only have unambiguous mappings for 2, 3, and 5 channels - */ - if( - options.channel_map_none || - channels == 1 || /* 1 channel: (mono) */ - channels == 2 || /* 2 channels: left, right */ - channels == 3 || /* 3 channels: left, right, center */ - channels == 5 /* 5 channels: front left, front right, center, surround left, surround right */ - ) { - /* keep default channel order */ - } - else { - flac__utils_printf(stderr, 1, "%s: ERROR: unsupported number of channels %u for AIFF\n", e->inbasefilename, channels); - return false; - } - - e->info.bytes_per_wide_sample = channels * (bps / 8); - - /* skip any extra data in the COMM chunk */ - if(!fskip_ahead(e->fin, skip)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping over extra COMM data\n", e->inbasefilename); - return false; - } - - got_comm_chunk = true; - } - else if(!memcmp(chunk_id, "SSND", 4) && !got_ssnd_chunk) { /* sound data chunk */ - FLAC__uint32 xx; - FLAC__uint64 data_bytes; - uint32_t offset = 0; - - if(!got_comm_chunk) { - flac__utils_printf(stderr, 1, "%s: ERROR: got 'SSND' chunk before 'COMM' chunk\n", e->inbasefilename); - return false; - } - - /* SSND chunk size */ - if(!read_uint32(e->fin, /*big_endian=*/true, &xx, e->inbasefilename)) - return false; - data_bytes = xx; - if(options.ignore_chunk_sizes) { - if(data_bytes) { - flac__utils_printf(stderr, 1, "%s: WARNING: 'SSND' chunk has non-zero size, using --ignore-chunk-sizes is probably a bad idea\n", e->inbasefilename, chunk_id); - if(e->treat_warnings_as_errors) - return false; - } - data_bytes = (FLAC__uint64)0 - (FLAC__uint64)e->info.bytes_per_wide_sample; /* max out data_bytes; we'll use EOF as signal to stop reading */ - } - else if(data_bytes <= 8) { - flac__utils_printf(stderr, 1, "%s: ERROR: 'SSND' chunk has size <= 8\n", e->inbasefilename); - return false; - } - else { - data_bytes -= 8; /* discount the offset and block size fields */ - } - - /* offset */ - if(!read_uint32(e->fin, /*big_endian=*/true, &xx, e->inbasefilename)) - return false; - offset = xx; - data_bytes -= offset; - - /* block size */ - if(!read_uint32(e->fin, /*big_endian=*/true, &xx, e->inbasefilename)) - return false; - if(xx && !options.ignore_chunk_sizes) - data_bytes -= (xx - (data_bytes % xx)); - if(options.ignore_chunk_sizes) { - if(xx) { - flac__utils_printf(stderr, 1, "%s: WARNING: 'SSND' chunk has non-zero blocksize, using --ignore-chunk-sizes is probably a bad idea\n", e->inbasefilename, chunk_id); - if(e->treat_warnings_as_errors) - return false; - } - } - - /* skip any SSND offset bytes */ - if(!fskip_ahead(e->fin, offset)) { - flac__utils_printf(stderr, 1, "%s: ERROR: skipping offset in SSND chunk\n", e->inbasefilename); - return false; - } - - e->fmt.iff.data_bytes = data_bytes; - - got_ssnd_chunk = true; - } - else { - FLAC__uint32 xx; - if(!options.format_options.iff.foreign_metadata) { - flac__utils_printf(stderr, 1, "%s: WARNING: skipping unknown chunk '%s' (use --keep-foreign-metadata to keep)\n", e->inbasefilename, chunk_id); - if(e->treat_warnings_as_errors) - return false; - } - - /* chunk size */ - if(!read_uint32(e->fin, /*big_endian=*/true, &xx, e->inbasefilename)) - return false; - else { - uint64_t skip = xx + (xx & 1); - - FLAC__ASSERT(skip <= LONG_MAX); - if(!fskip_ahead(e->fin, skip)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping over chunk\n", e->inbasefilename); - return false; - } - } - } - } - - if(!got_comm_chunk) { - flac__utils_printf(stderr, 1, "%s: ERROR: didn't find COMM chunk\n", e->inbasefilename); - return false; - } - if(!got_ssnd_chunk && sample_frames) { - flac__utils_printf(stderr, 1, "%s: ERROR: didn't find SSND chunk\n", e->inbasefilename); - return false; - } - - e->info.sample_rate = sample_rate; - e->info.channels = channels; - e->info.bits_per_sample = bps; - e->info.shift = shift; - e->info.channel_mask = channel_mask; - - return true; -} - -static FLAC__bool get_sample_info_flac(EncoderSession *e) -{ - if (!( - FLAC__stream_decoder_set_md5_checking(e->fmt.flac.decoder, false) && - FLAC__stream_decoder_set_metadata_respond_all(e->fmt.flac.decoder) - )) { - flac__utils_printf(stderr, 1, "%s: ERROR: setting up decoder for FLAC input\n", e->inbasefilename); - return false; - } - - if (e->format == FORMAT_OGGFLAC) { - if (FLAC__stream_decoder_init_ogg_stream(e->fmt.flac.decoder, flac_decoder_read_callback, flac_decoder_seek_callback, flac_decoder_tell_callback, flac_decoder_length_callback, flac_decoder_eof_callback, flac_decoder_write_callback, flac_decoder_metadata_callback, flac_decoder_error_callback, /*client_data=*/e) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - flac__utils_printf(stderr, 1, "%s: ERROR: initializing decoder for Ogg FLAC input, state = %s\n", e->inbasefilename, FLAC__stream_decoder_get_resolved_state_string(e->fmt.flac.decoder)); - return false; - } - } - else if (FLAC__stream_decoder_init_stream(e->fmt.flac.decoder, flac_decoder_read_callback, flac_decoder_seek_callback, flac_decoder_tell_callback, flac_decoder_length_callback, flac_decoder_eof_callback, flac_decoder_write_callback, flac_decoder_metadata_callback, flac_decoder_error_callback, /*client_data=*/e) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - flac__utils_printf(stderr, 1, "%s: ERROR: initializing decoder for FLAC input, state = %s\n", e->inbasefilename, FLAC__stream_decoder_get_resolved_state_string(e->fmt.flac.decoder)); - return false; - } - - if (!FLAC__stream_decoder_process_until_end_of_metadata(e->fmt.flac.decoder) || e->fmt.flac.client_data.fatal_error) { - if (e->fmt.flac.client_data.fatal_error) - flac__utils_printf(stderr, 1, "%s: ERROR: out of memory or too many metadata blocks while reading metadata in FLAC input\n", e->inbasefilename); - else - flac__utils_printf(stderr, 1, "%s: ERROR: reading metadata in FLAC input, state = %s\n", e->inbasefilename, FLAC__stream_decoder_get_resolved_state_string(e->fmt.flac.decoder)); - return false; - } - - if (e->fmt.flac.client_data.num_metadata_blocks == 0) { - flac__utils_printf(stderr, 1, "%s: ERROR: reading metadata in FLAC input, got no metadata blocks\n", e->inbasefilename); - return false; - } - else if (e->fmt.flac.client_data.metadata_blocks[0]->type != FLAC__METADATA_TYPE_STREAMINFO) { - flac__utils_printf(stderr, 1, "%s: ERROR: reading metadata in FLAC input, first metadata block is not STREAMINFO\n", e->inbasefilename); - return false; - } - else if (e->fmt.flac.client_data.metadata_blocks[0]->data.stream_info.total_samples == 0) { - flac__utils_printf(stderr, 1, "%s: ERROR: FLAC input has STREAMINFO with unknown total samples which is not supported\n", e->inbasefilename); - return false; - } - - e->info.sample_rate = e->fmt.flac.client_data.metadata_blocks[0]->data.stream_info.sample_rate; - e->info.channels = e->fmt.flac.client_data.metadata_blocks[0]->data.stream_info.channels; - e->info.bits_per_sample = e->fmt.flac.client_data.metadata_blocks[0]->data.stream_info.bits_per_sample; - e->info.shift = 0; - e->info.bytes_per_wide_sample = 0; - e->info.is_unsigned_samples = false; /* not applicable for FLAC input */ - e->info.is_big_endian = false; /* not applicable for FLAC input */ - e->info.channel_mask = 0; - - return true; -} - -/* - * public routines - */ -int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, uint32_t lookahead_length, encode_options_t options) -{ - EncoderSession encoder_session; - size_t channel_map[FLAC__MAX_CHANNELS]; - - if(!EncoderSession_construct(&encoder_session, options, infilesize, infile, infilename, outfilename, lookahead, lookahead_length)) - return 1; - - /* initialize default channel map that preserves channel order */ - { - size_t i; - for(i = 0; i < sizeof(channel_map)/sizeof(channel_map[0]); i++) - channel_map[i] = i; - } - - /* read foreign metadata if requested */ - if(EncoderSession_format_is_iff(&encoder_session) && options.format_options.iff.foreign_metadata) { - const char *error; - if(!( - options.format == FORMAT_WAVE || options.format == FORMAT_RF64? - flac__foreign_metadata_read_from_wave(options.format_options.iff.foreign_metadata, infilename, &error) : - options.format == FORMAT_WAVE64? - flac__foreign_metadata_read_from_wave64(options.format_options.iff.foreign_metadata, infilename, &error) : - flac__foreign_metadata_read_from_aiff(options.format_options.iff.foreign_metadata, infilename, &error) - )) { - if(options.relaxed_foreign_metadata_handling) { - flac__utils_printf(stderr, 1, "%s: WARNING reading foreign metadata: %s\n", encoder_session.inbasefilename, error); - if(encoder_session.treat_warnings_as_errors) - return EncoderSession_finish_error(&encoder_session); - } - else { - flac__utils_printf(stderr, 1, "%s: ERROR reading foreign metadata: %s\n", encoder_session.inbasefilename, error); - return EncoderSession_finish_error(&encoder_session); - } - } - } - - /* initialize encoder session with info about the audio (channels/bps/resolution/endianness/etc) */ - switch(options.format) { - case FORMAT_RAW: - if(!get_sample_info_raw(&encoder_session, options)) - return EncoderSession_finish_error(&encoder_session); - break; - case FORMAT_WAVE: - case FORMAT_WAVE64: - case FORMAT_RF64: - if(!get_sample_info_wave(&encoder_session, options)) - return EncoderSession_finish_error(&encoder_session); - break; - case FORMAT_AIFF: - case FORMAT_AIFF_C: - if(!get_sample_info_aiff(&encoder_session, options)) - return EncoderSession_finish_error(&encoder_session); - break; - case FORMAT_FLAC: - case FORMAT_OGGFLAC: - /* - * set up FLAC decoder for the input - */ - if (0 == (encoder_session.fmt.flac.decoder = FLAC__stream_decoder_new())) { - flac__utils_printf(stderr, 1, "%s: ERROR: creating decoder for FLAC input\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - if(!get_sample_info_flac(&encoder_session)) - return EncoderSession_finish_error(&encoder_session); - break; - default: - FLAC__ASSERT(0); - /* double protection */ - return EncoderSession_finish_error(&encoder_session); - } - - /* some more checks */ - if(encoder_session.info.channels == 0 || encoder_session.info.channels > FLAC__MAX_CHANNELS) { - flac__utils_printf(stderr, 1, "%s: ERROR: unsupported number of channels %u\n", encoder_session.inbasefilename, encoder_session.info.channels); - return EncoderSession_finish_error(&encoder_session); - } - if(!FLAC__format_sample_rate_is_valid(encoder_session.info.sample_rate)) { - flac__utils_printf(stderr, 1, "%s: ERROR: unsupported sample rate %u\n", encoder_session.inbasefilename, encoder_session.info.sample_rate); - return EncoderSession_finish_error(&encoder_session); - } - if(encoder_session.info.bits_per_sample-encoder_session.info.shift < 4 || encoder_session.info.bits_per_sample-encoder_session.info.shift > 32) { - flac__utils_printf(stderr, 1, "%s: ERROR: unsupported bits-per-sample %u\n", encoder_session.inbasefilename, encoder_session.info.bits_per_sample-encoder_session.info.shift); - return EncoderSession_finish_error(&encoder_session); - } - - { - FLAC__uint64 total_samples_in_input; /* WATCHOUT: may be 0 to mean "unknown" */ - FLAC__uint64 skip; - FLAC__uint64 until; /* a value of 0 mean end-of-stream (i.e. --until=-0) */ - uint32_t consecutive_eos_count = 0; - - switch(options.format) { - case FORMAT_RAW: - if(infilesize < 0) - total_samples_in_input = 0; - else - total_samples_in_input = (FLAC__uint64)infilesize / encoder_session.info.bytes_per_wide_sample; - break; - case FORMAT_WAVE: - case FORMAT_WAVE64: - case FORMAT_RF64: - case FORMAT_AIFF: - case FORMAT_AIFF_C: - /* truncation in the division removes any padding byte that was counted in encoder_session.fmt.iff.data_bytes */ - total_samples_in_input = encoder_session.fmt.iff.data_bytes / encoder_session.info.bytes_per_wide_sample; - - /* check for chunks trailing the audio data */ - if(!options.ignore_chunk_sizes && !options.format_options.iff.foreign_metadata - && infilesize != (FLAC__off_t)(-1)) { - FLAC__off_t current_position = ftello(encoder_session.fin); - if(current_position > 0) { - FLAC__uint64 end_of_data_chunk = current_position + encoder_session.fmt.iff.data_bytes; - if(end_of_data_chunk < (FLAC__uint64)infilesize) { - flac__utils_printf(stderr, 1, "%s: WARNING: there is data trailing the audio data. Use --keep-foreign-metadata or --ignore-chunk-sizes to keep it\n", encoder_session.inbasefilename); - if(encoder_session.treat_warnings_as_errors) - return EncoderSession_finish_error(&encoder_session); - } - else if(end_of_data_chunk > (FLAC__uint64)infilesize) { - flac__utils_printf(stderr, 1, "%s: WARNING: the length of the data chunk overruns the end of the file. Please consult the manual on the --ignore-chunk-sizes option\n", encoder_session.inbasefilename); - if(encoder_session.treat_warnings_as_errors) - return EncoderSession_finish_error(&encoder_session); - } - } - } - break; - case FORMAT_FLAC: - case FORMAT_OGGFLAC: - total_samples_in_input = encoder_session.fmt.flac.client_data.metadata_blocks[0]->data.stream_info.total_samples; - break; - default: - FLAC__ASSERT(0); - /* double protection */ - return EncoderSession_finish_error(&encoder_session); - } - - /* - * now that we know the sample rate, canonicalize the - * --skip string to an absolute sample number: - */ - if(!flac__utils_canonicalize_skip_until_specification(&options.skip_specification, encoder_session.info.sample_rate)) { - flac__utils_printf(stderr, 1, "%s: ERROR: value of --skip is too large\n", encoder_session.inbasefilename, encoder_session.info.bits_per_sample-encoder_session.info.shift); - return EncoderSession_finish_error(&encoder_session); - } - FLAC__ASSERT(options.skip_specification.value.samples >= 0); - skip = (FLAC__uint64)options.skip_specification.value.samples; - - /* - * now that we possibly know the input size, canonicalize the - * --until string to an absolute sample number: - */ - if(!canonicalize_until_specification(&options.until_specification, encoder_session.inbasefilename, encoder_session.info.sample_rate, skip, total_samples_in_input)) - return EncoderSession_finish_error(&encoder_session); - until = (FLAC__uint64)options.until_specification.value.samples; - - /* adjust encoding parameters based on skip and until values */ - switch(options.format) { - case FORMAT_RAW: - FLAC__ASSERT(sizeof(FLAC__off_t) == 8); - if(skip >= INT64_MAX / encoder_session.info.bytes_per_wide_sample) { - flac__utils_printf(stderr, 1, "%s: ERROR: value of --skip is too large\n", encoder_session.inbasefilename, encoder_session.info.bits_per_sample-encoder_session.info.shift); - return EncoderSession_finish_error(&encoder_session); - } - infilesize -= (FLAC__off_t)skip * encoder_session.info.bytes_per_wide_sample; - encoder_session.total_samples_to_encode = total_samples_in_input - skip; - break; - case FORMAT_WAVE: - case FORMAT_WAVE64: - case FORMAT_RF64: - case FORMAT_AIFF: - case FORMAT_AIFF_C: - FLAC__ASSERT(sizeof(FLAC__off_t) == 8); - if(skip >= INT64_MAX / encoder_session.info.bytes_per_wide_sample) { - flac__utils_printf(stderr, 1, "%s: ERROR: value of --skip is too large\n", encoder_session.inbasefilename, encoder_session.info.bits_per_sample-encoder_session.info.shift); - return EncoderSession_finish_error(&encoder_session); - } - encoder_session.fmt.iff.data_bytes -= skip * encoder_session.info.bytes_per_wide_sample; - if(options.ignore_chunk_sizes) { - encoder_session.total_samples_to_encode = 0; - FLAC__ASSERT(0 == until); - } - else { - encoder_session.total_samples_to_encode = total_samples_in_input - skip; - } - break; - case FORMAT_FLAC: - case FORMAT_OGGFLAC: - encoder_session.total_samples_to_encode = total_samples_in_input - skip; - break; - default: - FLAC__ASSERT(0); - /* double protection */ - return EncoderSession_finish_error(&encoder_session); - } - if(until > 0) { - const FLAC__uint64 trim = total_samples_in_input - until; - FLAC__ASSERT(total_samples_in_input > 0); - if(options.format == FORMAT_RAW) - infilesize -= (FLAC__off_t)trim * encoder_session.info.bytes_per_wide_sample; - else if(EncoderSession_format_is_iff(&encoder_session)) - encoder_session.fmt.iff.data_bytes -= trim * encoder_session.info.bytes_per_wide_sample; - encoder_session.total_samples_to_encode -= trim; - } - switch(options.format) { - case FORMAT_RAW: - encoder_session.unencoded_size = encoder_session.total_samples_to_encode * encoder_session.info.bytes_per_wide_sample; - break; - case FORMAT_WAVE: - /* +44 for the size of the WAVE headers; this is just an estimate for the progress indicator and doesn't need to be exact */ - encoder_session.unencoded_size = encoder_session.total_samples_to_encode * encoder_session.info.bytes_per_wide_sample + 44; - break; - case FORMAT_WAVE64: - /* +44 for the size of the WAVE headers; this is just an estimate for the progress indicator and doesn't need to be exact */ - encoder_session.unencoded_size = encoder_session.total_samples_to_encode * encoder_session.info.bytes_per_wide_sample + 104; - break; - case FORMAT_RF64: - /* +72 for the size of the RF64 headers; this is just an estimate for the progress indicator and doesn't need to be exact */ - encoder_session.unencoded_size = encoder_session.total_samples_to_encode * encoder_session.info.bytes_per_wide_sample + 80; - break; - case FORMAT_AIFF: - case FORMAT_AIFF_C: - /* +54 for the size of the AIFF headers; this is just an estimate for the progress indicator and doesn't need to be exact */ - encoder_session.unencoded_size = encoder_session.total_samples_to_encode * encoder_session.info.bytes_per_wide_sample + 54; - break; - case FORMAT_FLAC: - case FORMAT_OGGFLAC: - if(infilesize < 0) - /* if we don't know, use 0 as hint to progress indicator (which is the only place this is used): */ - encoder_session.unencoded_size = 0; - else if(skip == 0 && until == 0) - encoder_session.unencoded_size = (FLAC__uint64)infilesize; - else if(total_samples_in_input) - encoder_session.unencoded_size = (FLAC__uint64)infilesize * encoder_session.total_samples_to_encode / total_samples_in_input; - else - encoder_session.unencoded_size = (FLAC__uint64)infilesize; - break; - default: - FLAC__ASSERT(0); - /* double protection */ - return EncoderSession_finish_error(&encoder_session); - } - - if(encoder_session.total_samples_to_encode == 0) { - encoder_session.unencoded_size = 0; - flac__utils_printf(stderr, 2, "(No runtime statistics possible; please wait for encoding to finish...)\n"); - } - - if(options.format == FORMAT_FLAC || options.format == FORMAT_OGGFLAC) - encoder_session.fmt.flac.client_data.samples_left_to_process = encoder_session.total_samples_to_encode; - - stats_new_file(); - /* init the encoder */ - if(!EncoderSession_init_encoder(&encoder_session, options)) - return EncoderSession_finish_error(&encoder_session); - - /* skip over any samples as requested */ - if(skip > 0) { - switch(options.format) { - case FORMAT_RAW: - { - uint32_t skip_bytes = encoder_session.info.bytes_per_wide_sample * (uint32_t)skip; - if(skip_bytes > lookahead_length) { - skip_bytes -= lookahead_length; - lookahead_length = 0; - if(!fskip_ahead(encoder_session.fin, skip_bytes)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - } - else { - lookahead += skip_bytes; - lookahead_length -= skip_bytes; - } - } - break; - case FORMAT_WAVE: - case FORMAT_WAVE64: - case FORMAT_RF64: - case FORMAT_AIFF: - case FORMAT_AIFF_C: - if(!fskip_ahead(encoder_session.fin, skip * encoder_session.info.bytes_per_wide_sample)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - break; - case FORMAT_FLAC: - case FORMAT_OGGFLAC: - /* - * have to wait until the FLAC encoder is set up for writing - * before any seeking in the input FLAC file, because the seek - * itself will usually call the decoder's write callback, and - * our decoder's write callback passes samples to our FLAC - * encoder - */ - if(!FLAC__stream_decoder_seek_absolute(encoder_session.fmt.flac.decoder, skip)) { - flac__utils_printf(stderr, 1, "%s: ERROR while skipping samples, FLAC decoder state = %s\n", encoder_session.inbasefilename, FLAC__stream_decoder_get_resolved_state_string(encoder_session.fmt.flac.decoder)); - return EncoderSession_finish_error(&encoder_session); - } - break; - default: - FLAC__ASSERT(0); - /* double protection */ - return EncoderSession_finish_error(&encoder_session); - } - } - - /* - * now do samples from the file - */ - switch(options.format) { - case FORMAT_RAW: - if(infilesize < 0) { - size_t bytes_read; - while(!feof(infile)) { - if(lookahead_length > 0) { - FLAC__ASSERT(lookahead_length < CHUNK_OF_SAMPLES * encoder_session.info.bytes_per_wide_sample); - memcpy(ubuffer.u8, lookahead, lookahead_length); - bytes_read = fread(ubuffer.u8+lookahead_length, sizeof(uint8_t), CHUNK_OF_SAMPLES * encoder_session.info.bytes_per_wide_sample - lookahead_length, infile) + lookahead_length; - if(ferror(infile)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - lookahead_length = 0; - } - else - bytes_read = fread(ubuffer.u8, sizeof(uint8_t), CHUNK_OF_SAMPLES * encoder_session.info.bytes_per_wide_sample, infile); - - if(bytes_read == 0) { - if(ferror(infile)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - } - else if(bytes_read % encoder_session.info.bytes_per_wide_sample != 0) { - flac__utils_printf(stderr, 1, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - else { - uint32_t wide_samples = bytes_read / encoder_session.info.bytes_per_wide_sample; - if(!format_input(input_, wide_samples, encoder_session.info.is_big_endian, encoder_session.info.is_unsigned_samples, encoder_session.info.channels, encoder_session.info.bits_per_sample, encoder_session.info.shift, channel_map)) - return EncoderSession_finish_error(&encoder_session); - - if(!EncoderSession_process(&encoder_session, (const FLAC__int32 * const *)input_, wide_samples)) { - print_error_with_state(&encoder_session, "ERROR during encoding"); - return EncoderSession_finish_error(&encoder_session); - } - } - } - } - else { - size_t bytes_read; - const FLAC__uint64 max_input_bytes = infilesize; - FLAC__uint64 total_input_bytes_read = 0; - while(total_input_bytes_read < max_input_bytes) { - { - size_t wanted = (CHUNK_OF_SAMPLES * encoder_session.info.bytes_per_wide_sample); - wanted = (size_t) min((FLAC__uint64)wanted, max_input_bytes - total_input_bytes_read); - - if(lookahead_length > 0) { - if(lookahead_length <= wanted) { - memcpy(ubuffer.u8, lookahead, lookahead_length); - wanted -= lookahead_length; - bytes_read = lookahead_length; - } - else { - /* This happens when --until is used on a very short file */ - FLAC__ASSERT(lookahead_length < CHUNK_OF_SAMPLES * encoder_session.info.bytes_per_wide_sample); - memcpy(ubuffer.u8, lookahead, wanted); - wanted = 0; - bytes_read = wanted; - } - if(wanted > 0) { - bytes_read += fread(ubuffer.u8+lookahead_length, sizeof(uint8_t), wanted, infile); - if(ferror(infile)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - } - lookahead_length = 0; - } - else - bytes_read = fread(ubuffer.u8, sizeof(uint8_t), wanted, infile); - } - - if(bytes_read == 0) { - if(ferror(infile)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - else if(feof(infile)) { - flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; expected %" PRIu64 " samples, got %" PRIu64 " samples\n", encoder_session.inbasefilename, encoder_session.total_samples_to_encode, encoder_session.samples_written); - if(encoder_session.treat_warnings_as_errors) - return EncoderSession_finish_error(&encoder_session); - total_input_bytes_read = max_input_bytes; - } - } - else { - if(bytes_read % encoder_session.info.bytes_per_wide_sample != 0) { - flac__utils_printf(stderr, 1, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - else { - uint32_t wide_samples = bytes_read / encoder_session.info.bytes_per_wide_sample; - if(!format_input(input_, wide_samples, encoder_session.info.is_big_endian, encoder_session.info.is_unsigned_samples, encoder_session.info.channels, encoder_session.info.bits_per_sample, encoder_session.info.shift, channel_map)) - return EncoderSession_finish_error(&encoder_session); - - if(!EncoderSession_process(&encoder_session, (const FLAC__int32 * const *)input_, wide_samples)) { - print_error_with_state(&encoder_session, "ERROR during encoding"); - return EncoderSession_finish_error(&encoder_session); - } - total_input_bytes_read += bytes_read; - } - } - } - } - break; - case FORMAT_WAVE: - case FORMAT_WAVE64: - case FORMAT_RF64: - case FORMAT_AIFF: - case FORMAT_AIFF_C: - while(encoder_session.fmt.iff.data_bytes > 0) { - const size_t bytes_to_read = - (size_t) min (sizeof (ubuffer.u8), - min (encoder_session.fmt.iff.data_bytes, - CHUNK_OF_SAMPLES * (uint64_t) encoder_session.info.bytes_per_wide_sample)); - size_t bytes_read = fread(ubuffer.u8, sizeof(uint8_t), bytes_to_read, infile); - if(bytes_read == 0) { - if(ferror(infile)) { - flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - else if(feof(infile)) { - if(options.ignore_chunk_sizes) { - flac__utils_printf(stderr, 1, "%s: INFO: hit EOF with --ignore-chunk-sizes, got %" PRIu64 " samples\n", encoder_session.inbasefilename, encoder_session.samples_written); - } - else { - flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; expected %" PRIu64 " samples, got %" PRIu64 " samples\n", encoder_session.inbasefilename, encoder_session.total_samples_to_encode, encoder_session.samples_written); - if(encoder_session.treat_warnings_as_errors) - return EncoderSession_finish_error(&encoder_session); - } - encoder_session.fmt.iff.data_bytes = 0; - } - } - else { - if(bytes_read % encoder_session.info.bytes_per_wide_sample != 0) { - flac__utils_printf(stderr, 1, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename); - return EncoderSession_finish_error(&encoder_session); - } - else { - uint32_t wide_samples = bytes_read / encoder_session.info.bytes_per_wide_sample; - if(!format_input(input_, wide_samples, encoder_session.info.is_big_endian, encoder_session.info.is_unsigned_samples, encoder_session.info.channels, encoder_session.info.bits_per_sample, encoder_session.info.shift, channel_map)) - return EncoderSession_finish_error(&encoder_session); - - if(!EncoderSession_process(&encoder_session, (const FLAC__int32 * const *)input_, wide_samples)) { - print_error_with_state(&encoder_session, "ERROR during encoding"); - return EncoderSession_finish_error(&encoder_session); - } - encoder_session.fmt.iff.data_bytes -= bytes_read; - } - } - } - break; - case FORMAT_FLAC: - case FORMAT_OGGFLAC: - consecutive_eos_count = 0; - while(!encoder_session.fmt.flac.client_data.fatal_error && encoder_session.fmt.flac.client_data.samples_left_to_process > 0) { - FLAC__StreamDecoderState decoder_state; - /* We can also hit the end of stream without samples_left_to_process - * going to 0 if there are errors and continue_through_decode_errors - * is on, so we want to break in that case too: - */ - decoder_state = FLAC__stream_decoder_get_state(encoder_session.fmt.flac.decoder); - if(encoder_session.continue_through_decode_errors && decoder_state == FLAC__STREAM_DECODER_END_OF_STREAM) - break; - - consecutive_eos_count = decoder_state == FLAC__STREAM_DECODER_END_OF_STREAM ? consecutive_eos_count + 1 : 0; - - /* Exit loop if we get two or more consecutive FLAC__STREAM_DECODER_END_OF_STREAM events. */ - if(consecutive_eos_count >= 2) { - flac__utils_printf(stderr, 1, "%s: ERROR: %d consecutive FLAC__STREAM_DECODER_END_OF_STREAM events.\n", encoder_session.inbasefilename, consecutive_eos_count); - break; - } - - if(decoder_state == FLAC__STREAM_DECODER_ABORTED || !FLAC__stream_decoder_process_single(encoder_session.fmt.flac.decoder)) { - flac__utils_printf(stderr, 1, "%s: ERROR: while decoding FLAC input, state = %s\n", encoder_session.inbasefilename, FLAC__stream_decoder_get_resolved_state_string(encoder_session.fmt.flac.decoder)); - return EncoderSession_finish_error(&encoder_session); - } - } - if(encoder_session.fmt.flac.client_data.fatal_error) { - flac__utils_printf(stderr, 1, "%s: ERROR: while decoding FLAC input, state = %s\n", encoder_session.inbasefilename, FLAC__stream_decoder_get_resolved_state_string(encoder_session.fmt.flac.decoder)); - return EncoderSession_finish_error(&encoder_session); - } - break; - default: - FLAC__ASSERT(0); - /* double protection */ - return EncoderSession_finish_error(&encoder_session); - } - - } - - return EncoderSession_finish_ok( - &encoder_session, - EncoderSession_format_is_iff(&encoder_session)? options.format_options.iff.foreign_metadata : 0, - options.error_on_compression_fail - ); -} - -FLAC__bool EncoderSession_construct(EncoderSession *e, encode_options_t options, FLAC__off_t infilesize, FILE *infile, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, uint32_t lookahead_length) -{ - uint32_t i; - FLAC__uint32 test = 1; - - /* - * initialize globals - */ - - is_big_endian_host_ = (*((FLAC__byte*)(&test)))? false : true; - - for(i = 0; i < FLAC__MAX_CHANNELS; i++) - input_[i] = &(in_[i][0]); - - - /* - * initialize instance - */ - -#if FLAC__HAS_OGG - e->use_ogg = options.use_ogg; -#endif - e->verify = options.verify; - e->treat_warnings_as_errors = options.treat_warnings_as_errors; - e->continue_through_decode_errors = options.continue_through_decode_errors; - - e->is_stdout = (0 == strcmp(outfilename, "-")); - e->outputfile_opened = false; - - e->inbasefilename = grabbag__file_get_basename(infilename); - e->infilename = infilename; - e->outfilename = outfilename; - - e->total_samples_to_encode = 0; - e->unencoded_size = 0; - e->bytes_written = 0; - e->samples_written = 0; -#if 0 /* in case time.h with clock() isn't available for some reason */ - e->stats_frames_interval = 0; - e->old_frames_written = 0; -#else - e->old_clock_t = 0; -#endif - e->compression_ratio = 0.0; - - memset(&e->info, 0, sizeof(e->info)); - - e->format = options.format; - - switch(options.format) { - case FORMAT_RAW: - break; - case FORMAT_WAVE: - case FORMAT_WAVE64: - case FORMAT_RF64: - case FORMAT_AIFF: - case FORMAT_AIFF_C: - e->fmt.iff.data_bytes = 0; - break; - case FORMAT_FLAC: - case FORMAT_OGGFLAC: - e->fmt.flac.decoder = 0; - e->fmt.flac.client_data.filesize = infilesize; - e->fmt.flac.client_data.lookahead = lookahead; - e->fmt.flac.client_data.lookahead_length = lookahead_length; - e->fmt.flac.client_data.num_metadata_blocks = 0; - e->fmt.flac.client_data.samples_left_to_process = 0; - e->fmt.flac.client_data.fatal_error = false; - break; - default: -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - FLAC__ASSERT(0); -#endif - /* double protection */ - return false; - } - - e->encoder = 0; - - e->fin = infile; - e->seek_table_template = 0; - - if(0 == (e->seek_table_template = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE))) { - flac__utils_printf(stderr, 1, "%s: ERROR allocating memory for seek table\n", e->inbasefilename); - return false; - } - - e->encoder = FLAC__stream_encoder_new(); - if(0 == e->encoder) { - flac__utils_printf(stderr, 1, "%s: ERROR creating the encoder instance\n", e->inbasefilename); - EncoderSession_destroy(e); - return false; - } - - return true; -} - -void EncoderSession_destroy(EncoderSession *e) -{ - if(e->format == FORMAT_FLAC || e->format == FORMAT_OGGFLAC) { - size_t i; - if(e->fmt.flac.decoder) - FLAC__stream_decoder_delete(e->fmt.flac.decoder); - e->fmt.flac.decoder = 0; - for(i = 0; i < e->fmt.flac.client_data.num_metadata_blocks; i++) - FLAC__metadata_object_delete(e->fmt.flac.client_data.metadata_blocks[i]); - e->fmt.flac.client_data.num_metadata_blocks = 0; - } - - if(e->fin != stdin) - fclose(e->fin); - - if(0 != e->encoder) { - FLAC__stream_encoder_delete(e->encoder); - e->encoder = 0; - } - - if(0 != e->seek_table_template) { - FLAC__metadata_object_delete(e->seek_table_template); - e->seek_table_template = 0; - } -} - -int EncoderSession_finish_ok(EncoderSession *e, foreign_metadata_t *foreign_metadata, FLAC__bool error_on_compression_fail) -{ - FLAC__StreamEncoderState fse_state = FLAC__STREAM_ENCODER_OK; - int ret = 0; - FLAC__bool verify_error = false; - - if(e->encoder) { - fse_state = FLAC__stream_encoder_get_state(e->encoder); - ret = FLAC__stream_encoder_finish(e->encoder)? 0 : 1; - verify_error = - fse_state == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA || - FLAC__stream_encoder_get_state(e->encoder) == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA - ; - } - /* all errors except verify errors should interrupt the stats */ - if(ret && !verify_error) - print_error_with_state(e, "ERROR during encoding"); - else if(e->total_samples_to_encode > 0) { - print_stats(e); - flac__utils_printf(stderr, 2, "\n"); - } - - if(verify_error) { - print_verify_error(e); - ret = 1; - } - - /*@@@@@@ should this go here or somewhere else? */ - if(ret == 0 && foreign_metadata) { - const char *error; - if(!flac__foreign_metadata_write_to_flac(foreign_metadata, e->infilename, e->outfilename, &error)) { - flac__utils_printf(stderr, 1, "%s: ERROR: updating foreign metadata in FLAC file: %s\n", e->inbasefilename, error); - ret = 1; - } - } - - if (e->compression_ratio >= 1.0 && error_on_compression_fail) { - flac__utils_printf(stderr, 1, - "FAILURE: Compression failed (ratio %0.3f, should be < 1.0).\n" - "This happens for some files for one or more of the following reasons:\n" - " * Recompressing an existing FLAC from a higher to a lower compression setting.\n" - " * Insufficient input data (e.g. very short files, < 10000 frames).\n" - " * The audio data is not compressible (e.g. a full range white noise signal).\n" - , e->compression_ratio); - ret = 1; - } - -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* Always delete output file when fuzzing */ - flac_unlink(e->outfilename); -#endif - - EncoderSession_destroy(e); - - return ret; -} - -int EncoderSession_finish_error(EncoderSession *e) -{ - FLAC__ASSERT(e->encoder); - - if(e->total_samples_to_encode > 0) - flac__utils_printf(stderr, 2, "\n"); - - if(FLAC__stream_encoder_get_state(e->encoder) == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) { - print_verify_error(e); - EncoderSession_destroy(e); - } - else if(e->outputfile_opened) { - /* only want to delete the file if we opened it; otherwise it could be an existing file and our overwrite failed */ - /* Windows cannot unlink an open file, so close it first */ - EncoderSession_destroy(e); - flac_unlink(e->outfilename); - } - else - EncoderSession_destroy(e); - - return 1; -} - -typedef struct { - uint32_t num_metadata; - FLAC__bool *needs_delete; - FLAC__StreamMetadata **metadata; - FLAC__StreamMetadata *cuesheet; /* always needs to be deleted */ -} static_metadata_t; - -static void static_metadata_init(static_metadata_t *m) -{ - m->num_metadata = 0; - m->needs_delete = 0; - m->metadata = 0; - m->cuesheet = 0; -} - -static void static_metadata_clear(static_metadata_t *m) -{ - uint32_t i; - for(i = 0; i < m->num_metadata; i++) - if(m->needs_delete[i]) - FLAC__metadata_object_delete(m->metadata[i]); - if(m->metadata) - free(m->metadata); - if(m->needs_delete) - free(m->needs_delete); - if(m->cuesheet) - FLAC__metadata_object_delete(m->cuesheet); - static_metadata_init(m); -} - -static FLAC__bool static_metadata_append(static_metadata_t *m, FLAC__StreamMetadata *d, FLAC__bool needs_delete) -{ - void *x; - if(0 == (x = safe_realloc_nofree_muladd2_(m->metadata, sizeof(*m->metadata), /*times (*/m->num_metadata, /*+*/1/*)*/))) - return false; - m->metadata = (FLAC__StreamMetadata**)x; - if(0 == (x = safe_realloc_nofree_muladd2_(m->needs_delete, sizeof(*m->needs_delete), /*times (*/m->num_metadata, /*+*/1/*)*/))) - return false; - m->needs_delete = (FLAC__bool*)x; - m->metadata[m->num_metadata] = d; - m->needs_delete[m->num_metadata] = needs_delete; - m->num_metadata++; - return true; -} - -FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t options) -{ - const uint32_t channels = e->info.channels; - const uint32_t bps = e->info.bits_per_sample - e->info.shift; - const uint32_t sample_rate = e->info.sample_rate; - FLACDecoderData *flac_decoder_data = (e->format == FORMAT_FLAC || e->format == FORMAT_OGGFLAC)? &e->fmt.flac.client_data : 0; - FLAC__StreamMetadata padding; - FLAC__StreamMetadata **metadata = 0; - static_metadata_t static_metadata; - uint32_t num_metadata = 0, ic; - FLAC__StreamEncoderInitStatus init_status; - const FLAC__bool is_cdda = (channels == 1 || channels == 2) && (bps == 16) && (sample_rate == 44100); - char apodizations[2000]; - - FLAC__ASSERT(sizeof(options.pictures)/sizeof(options.pictures[0]) <= 64); - - static_metadata_init(&static_metadata); - - e->replay_gain = options.replay_gain; - - apodizations[0] = '\0'; - - if(e->replay_gain) { - if(channels != 1 && channels != 2) { - flac__utils_printf(stderr, 1, "%s: ERROR, number of channels (%u) must be 1 or 2 for --replay-gain\n", e->inbasefilename, channels); - return false; - } - if(!grabbag__replaygain_is_valid_sample_frequency(sample_rate)) { - flac__utils_printf(stderr, 1, "%s: ERROR, invalid sample rate (%u) for --replay-gain\n", e->inbasefilename, sample_rate); - return false; - } - if(options.is_first_file) { - if(!grabbag__replaygain_init(sample_rate)) { - flac__utils_printf(stderr, 1, "%s: ERROR initializing ReplayGain stage\n", e->inbasefilename); - return false; - } - } - } - - if(!parse_cuesheet(&static_metadata.cuesheet, options.cuesheet_filename, e->inbasefilename, sample_rate, is_cdda, e->total_samples_to_encode, e->treat_warnings_as_errors)) - return false; - - if(!convert_to_seek_table_template(options.requested_seek_points, options.num_requested_seek_points, options.cued_seekpoints? static_metadata.cuesheet : 0, e)) { - flac__utils_printf(stderr, 1, "%s: ERROR allocating memory for seek table\n", e->inbasefilename); - static_metadata_clear(&static_metadata); - return false; - } - - /* build metadata */ - if(flac_decoder_data) { - /* - * we're encoding from FLAC so we will use the FLAC file's - * metadata as the basis for the encoded file - */ - { - uint32_t i; - /* - * first handle pictures: simple append any --pictures - * specified. - */ - for(i = 0; i < options.num_pictures; i++) { - FLAC__StreamMetadata *pic = FLAC__metadata_object_clone(options.pictures[i]); - if(0 == pic) { - flac__utils_printf(stderr, 1, "%s: ERROR allocating memory for PICTURE block\n", e->inbasefilename); - static_metadata_clear(&static_metadata); - return false; - } - flac_decoder_data->metadata_blocks[flac_decoder_data->num_metadata_blocks++] = pic; - } - } - { - /* - * next handle vorbis comment: if any tags were specified - * or there is no existing vorbis comment, we create a - * new vorbis comment (discarding any existing one); else - * we keep the existing one. also need to make sure to - * propagate any channel mask tag. - */ - /* @@@ change to append -T values from options.vorbis_comment if input has VC already? */ - size_t i, j; - FLAC__bool vc_found = false; - for(i = 0, j = 0; i < flac_decoder_data->num_metadata_blocks; i++) { - if(flac_decoder_data->metadata_blocks[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) - vc_found = true; - if(flac_decoder_data->metadata_blocks[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT && options.vorbis_comment->data.vorbis_comment.num_comments > 0) { - (void) flac__utils_get_channel_mask_tag(flac_decoder_data->metadata_blocks[i], &e->info.channel_mask); - flac__utils_printf(stderr, 1, "%s: WARNING, replacing tags from input FLAC file with those given on the command-line\n", e->inbasefilename); - if(e->treat_warnings_as_errors) { - static_metadata_clear(&static_metadata); - return false; - } - FLAC__metadata_object_delete(flac_decoder_data->metadata_blocks[i]); - flac_decoder_data->metadata_blocks[i] = 0; - } - else - flac_decoder_data->metadata_blocks[j++] = flac_decoder_data->metadata_blocks[i]; - } - flac_decoder_data->num_metadata_blocks = j; - if((!vc_found || options.vorbis_comment->data.vorbis_comment.num_comments > 0) && flac_decoder_data->num_metadata_blocks < sizeof(flac_decoder_data->metadata_blocks)/sizeof(flac_decoder_data->metadata_blocks[0])) { - /* prepend ours */ - FLAC__StreamMetadata *vc = FLAC__metadata_object_clone(options.vorbis_comment); - if(0 == vc || (e->info.channel_mask && !flac__utils_set_channel_mask_tag(vc, e->info.channel_mask))) { - flac__utils_printf(stderr, 1, "%s: ERROR allocating memory for VORBIS_COMMENT block\n", e->inbasefilename); - static_metadata_clear(&static_metadata); - return false; - } - for(i = flac_decoder_data->num_metadata_blocks; i > 1; i--) - flac_decoder_data->metadata_blocks[i] = flac_decoder_data->metadata_blocks[i-1]; - flac_decoder_data->metadata_blocks[1] = vc; - flac_decoder_data->num_metadata_blocks++; - } - } - { - /* - * next handle cuesheet: if --cuesheet was specified, use - * it; else if file has existing CUESHEET and cuesheet's - * lead-out offset is correct, keep it; else no CUESHEET - */ - size_t i, j; - for(i = 0, j = 0; i < flac_decoder_data->num_metadata_blocks; i++) { - FLAC__bool existing_cuesheet_is_bad = false; - /* check if existing cuesheet matches the input audio */ - if(flac_decoder_data->metadata_blocks[i]->type == FLAC__METADATA_TYPE_CUESHEET && 0 == static_metadata.cuesheet) { - const FLAC__StreamMetadata_CueSheet *cs = &flac_decoder_data->metadata_blocks[i]->data.cue_sheet; - if(e->total_samples_to_encode == 0) { - flac__utils_printf(stderr, 1, "%s: WARNING, cuesheet in input FLAC file cannot be kept if input size is not known, dropping it...\n", e->inbasefilename); - if(e->treat_warnings_as_errors) { - static_metadata_clear(&static_metadata); - return false; - } - existing_cuesheet_is_bad = true; - } - else if(cs->num_tracks > 0 && e->total_samples_to_encode != cs->tracks[cs->num_tracks-1].offset) { - flac__utils_printf(stderr, 1, "%s: WARNING, lead-out offset of cuesheet in input FLAC file does not match input length, dropping existing cuesheet...\n", e->inbasefilename); - if(e->treat_warnings_as_errors) { - static_metadata_clear(&static_metadata); - return false; - } - existing_cuesheet_is_bad = true; - } - } - if(flac_decoder_data->metadata_blocks[i]->type == FLAC__METADATA_TYPE_CUESHEET && (existing_cuesheet_is_bad || 0 != static_metadata.cuesheet)) { - if(0 != static_metadata.cuesheet) { - flac__utils_printf(stderr, 1, "%s: WARNING, replacing cuesheet in input FLAC file with the one given on the command-line\n", e->inbasefilename); - if(e->treat_warnings_as_errors) { - static_metadata_clear(&static_metadata); - return false; - } - } - FLAC__metadata_object_delete(flac_decoder_data->metadata_blocks[i]); - flac_decoder_data->metadata_blocks[i] = 0; - } - else - flac_decoder_data->metadata_blocks[j++] = flac_decoder_data->metadata_blocks[i]; - } - flac_decoder_data->num_metadata_blocks = j; - if(0 != static_metadata.cuesheet && flac_decoder_data->num_metadata_blocks < sizeof(flac_decoder_data->metadata_blocks)/sizeof(flac_decoder_data->metadata_blocks[0])) { - /* prepend ours */ - FLAC__StreamMetadata *cs = FLAC__metadata_object_clone(static_metadata.cuesheet); - if(0 == cs) { - flac__utils_printf(stderr, 1, "%s: ERROR allocating memory for CUESHEET block\n", e->inbasefilename); - static_metadata_clear(&static_metadata); - return false; - } - for(i = flac_decoder_data->num_metadata_blocks; i > 1; i--) - flac_decoder_data->metadata_blocks[i] = flac_decoder_data->metadata_blocks[i-1]; - flac_decoder_data->metadata_blocks[1] = cs; - flac_decoder_data->num_metadata_blocks++; - } - } - { - /* - * next handle seektable: if -S- was specified, no - * SEEKTABLE; else if -S was specified, use it/them; - * else if file has existing SEEKTABLE and input size is - * preserved (no --skip/--until/etc specified), keep it; - * else use default seektable options - * - * note: meanings of num_requested_seek_points: - * -1 : no -S option given, default to some value - * 0 : -S- given (no seektable) - * >0 : one or more -S options given - */ - size_t i, j; - FLAC__bool existing_seektable = false; - for(i = 0, j = 0; i < flac_decoder_data->num_metadata_blocks; i++) { - if(flac_decoder_data->metadata_blocks[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) - existing_seektable = true; - if(flac_decoder_data->metadata_blocks[i]->type == FLAC__METADATA_TYPE_SEEKTABLE && (e->total_samples_to_encode != flac_decoder_data->metadata_blocks[0]->data.stream_info.total_samples || options.num_requested_seek_points >= 0)) { - if(options.num_requested_seek_points > 0) { - flac__utils_printf(stderr, 1, "%s: WARNING, replacing seektable in input FLAC file with the one given on the command-line\n", e->inbasefilename); - if(e->treat_warnings_as_errors) { - static_metadata_clear(&static_metadata); - return false; - } - } - else if(options.num_requested_seek_points == 0) - ; /* no warning, silently delete existing SEEKTABLE since user specified --no-seektable (-S-) */ - else { - flac__utils_printf(stderr, 1, "%s: WARNING, can't use existing seektable in input FLAC since the input size is changing or unknown, dropping existing SEEKTABLE block...\n", e->inbasefilename); - if(e->treat_warnings_as_errors) { - static_metadata_clear(&static_metadata); - return false; - } - } - FLAC__metadata_object_delete(flac_decoder_data->metadata_blocks[i]); - flac_decoder_data->metadata_blocks[i] = 0; - existing_seektable = false; - } - else - flac_decoder_data->metadata_blocks[j++] = flac_decoder_data->metadata_blocks[i]; - } - flac_decoder_data->num_metadata_blocks = j; - if((options.num_requested_seek_points > 0 || (options.num_requested_seek_points < 0 && !existing_seektable)) && flac_decoder_data->num_metadata_blocks < sizeof(flac_decoder_data->metadata_blocks)/sizeof(flac_decoder_data->metadata_blocks[0])) { - /* prepend ours */ - FLAC__StreamMetadata *st = FLAC__metadata_object_clone(e->seek_table_template); - if(0 == st) { - flac__utils_printf(stderr, 1, "%s: ERROR allocating memory for SEEKTABLE block\n", e->inbasefilename); - static_metadata_clear(&static_metadata); - return false; - } - for(i = flac_decoder_data->num_metadata_blocks; i > 1; i--) - flac_decoder_data->metadata_blocks[i] = flac_decoder_data->metadata_blocks[i-1]; - flac_decoder_data->metadata_blocks[1] = st; - flac_decoder_data->num_metadata_blocks++; - } - } - { - /* - * finally handle padding: if --no-padding was specified, - * then delete all padding; else if -P was specified, - * use that instead of existing padding (if any); else - * if existing file has padding, move all existing - * padding blocks to one padding block at the end; else - * use default padding. - */ - int p = -1; - size_t i, j; - for(i = 0, j = 0; i < flac_decoder_data->num_metadata_blocks; i++) { - if(flac_decoder_data->metadata_blocks[i]->type == FLAC__METADATA_TYPE_PADDING) { - if(p < 0) - p = 0; - p += flac_decoder_data->metadata_blocks[i]->length; - FLAC__metadata_object_delete(flac_decoder_data->metadata_blocks[i]); - flac_decoder_data->metadata_blocks[i] = 0; - } - else - flac_decoder_data->metadata_blocks[j++] = flac_decoder_data->metadata_blocks[i]; - } - flac_decoder_data->num_metadata_blocks = j; - if(options.padding > 0) - p = options.padding; - if(p < 0) { - if(sample_rate == 0) - p = FLAC_ENCODE__DEFAULT_PADDING; - else - p = e->total_samples_to_encode / sample_rate < 20*60? FLAC_ENCODE__DEFAULT_PADDING : FLAC_ENCODE__DEFAULT_PADDING*8; - } - if(p > 0) - p += (e->replay_gain ? GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED : 0); - p = min(p, (int)((1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1)); - if(options.padding != 0) { - if(p > 0 && flac_decoder_data->num_metadata_blocks < sizeof(flac_decoder_data->metadata_blocks)/sizeof(flac_decoder_data->metadata_blocks[0])) { - flac_decoder_data->metadata_blocks[flac_decoder_data->num_metadata_blocks] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING); - if(0 == flac_decoder_data->metadata_blocks[flac_decoder_data->num_metadata_blocks]) { - flac__utils_printf(stderr, 1, "%s: ERROR allocating memory for PADDING block\n", e->inbasefilename); - static_metadata_clear(&static_metadata); - return false; - } - flac_decoder_data->metadata_blocks[flac_decoder_data->num_metadata_blocks]->is_last = false; /* the encoder will set this for us */ - flac_decoder_data->metadata_blocks[flac_decoder_data->num_metadata_blocks]->length = p; - flac_decoder_data->num_metadata_blocks++; - } - } - } - metadata = &flac_decoder_data->metadata_blocks[1]; /* don't include STREAMINFO */ - num_metadata = flac_decoder_data->num_metadata_blocks - 1; - } - else { - /* - * we're not encoding from FLAC so we will build the metadata - * from scratch - */ - const foreign_metadata_t *foreign_metadata = EncoderSession_format_is_iff(e)? options.format_options.iff.foreign_metadata : 0; - uint32_t i; - - if(e->seek_table_template->data.seek_table.num_points > 0) { - e->seek_table_template->is_last = false; /* the encoder will set this for us */ - static_metadata_append(&static_metadata, e->seek_table_template, /*needs_delete=*/false); - } - if(0 != static_metadata.cuesheet) - static_metadata_append(&static_metadata, static_metadata.cuesheet, /*needs_delete=*/false); - if(e->info.channel_mask) { - options.vorbis_comment_with_channel_mask_tag = FLAC__metadata_object_clone(options.vorbis_comment); - if(!flac__utils_set_channel_mask_tag(options.vorbis_comment_with_channel_mask_tag, e->info.channel_mask)) { - flac__utils_printf(stderr, 1, "%s: ERROR adding channel mask tag\n", e->inbasefilename); - static_metadata_clear(&static_metadata); - return false; - } - static_metadata_append(&static_metadata, options.vorbis_comment_with_channel_mask_tag, /*needs_delete=*/true); - } - else - static_metadata_append(&static_metadata, options.vorbis_comment, /*needs_delete=*/false); - for(i = 0; i < options.num_pictures; i++) - static_metadata_append(&static_metadata, options.pictures[i], /*needs_delete=*/false); - if(foreign_metadata) { - for(i = 0; i < foreign_metadata->num_blocks; i++) { - FLAC__StreamMetadata *p = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING); - if(!p) { - flac__utils_printf(stderr, 1, "%s: ERROR: out of memory\n", e->inbasefilename); - static_metadata_clear(&static_metadata); - return false; - } - static_metadata_append(&static_metadata, p, /*needs_delete=*/true); - static_metadata.metadata[static_metadata.num_metadata-1]->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8 + foreign_metadata->blocks[i].size; - } - } - if(options.padding != 0) { - padding.is_last = false; /* the encoder will set this for us */ - padding.type = FLAC__METADATA_TYPE_PADDING; - if(sample_rate == 0) - padding.length = (uint32_t)(options.padding>0? options.padding : FLAC_ENCODE__DEFAULT_PADDING) + (e->replay_gain ? GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED : 0); - else - padding.length = (uint32_t)(options.padding>0? options.padding : (e->total_samples_to_encode / sample_rate < 20*60? FLAC_ENCODE__DEFAULT_PADDING : FLAC_ENCODE__DEFAULT_PADDING*8)) + (e->replay_gain ? GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED : 0); - padding.length = min(padding.length, (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1); - static_metadata_append(&static_metadata, &padding, /*needs_delete=*/false); - } - metadata = static_metadata.metadata; - num_metadata = static_metadata.num_metadata; - } - - /* check for a few things that have not already been checked. the - * FLAC__stream_encoder_init*() will check it but only return - * FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA so we check some - * up front to give a better error message. - */ - if(!verify_metadata(e, metadata, num_metadata)) { - static_metadata_clear(&static_metadata); - return false; - } - - FLAC__stream_encoder_set_verify(e->encoder, options.verify); - FLAC__stream_encoder_set_streamable_subset(e->encoder, !options.lax); - FLAC__stream_encoder_set_channels(e->encoder, channels); - FLAC__stream_encoder_set_bits_per_sample(e->encoder, bps); - FLAC__stream_encoder_set_sample_rate(e->encoder, sample_rate); - for(ic = 0; ic < options.num_compression_settings; ic++) { - switch(options.compression_settings[ic].type) { - case CST_BLOCKSIZE: - FLAC__stream_encoder_set_blocksize(e->encoder, options.compression_settings[ic].value.t_unsigned); - break; - case CST_COMPRESSION_LEVEL: - FLAC__stream_encoder_set_compression_level(e->encoder, options.compression_settings[ic].value.t_unsigned); - apodizations[0] = '\0'; - break; - case CST_DO_MID_SIDE: - FLAC__stream_encoder_set_do_mid_side_stereo(e->encoder, options.compression_settings[ic].value.t_bool); - break; - case CST_LOOSE_MID_SIDE: - FLAC__stream_encoder_set_loose_mid_side_stereo(e->encoder, options.compression_settings[ic].value.t_bool); - break; - case CST_APODIZATION: - if(strlen(apodizations)+strlen(options.compression_settings[ic].value.t_string)+2 >= sizeof(apodizations)) { - flac__utils_printf(stderr, 1, "%s: ERROR: too many apodization functions requested\n", e->inbasefilename); - static_metadata_clear(&static_metadata); - return false; - } - else { - safe_strncat(apodizations, options.compression_settings[ic].value.t_string, sizeof(apodizations)); - safe_strncat(apodizations, ";", sizeof(apodizations)); - } - break; - case CST_MAX_LPC_ORDER: -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - FLAC__stream_encoder_set_max_lpc_order(e->encoder, options.compression_settings[ic].value.t_unsigned); -#endif - break; - case CST_QLP_COEFF_PRECISION: - FLAC__stream_encoder_set_qlp_coeff_precision(e->encoder, options.compression_settings[ic].value.t_unsigned); - break; - case CST_DO_QLP_COEFF_PREC_SEARCH: -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - FLAC__stream_encoder_set_do_qlp_coeff_prec_search(e->encoder, options.compression_settings[ic].value.t_bool); -#endif - break; - case CST_DO_ESCAPE_CODING: - FLAC__stream_encoder_set_do_escape_coding(e->encoder, options.compression_settings[ic].value.t_bool); - break; - case CST_DO_EXHAUSTIVE_MODEL_SEARCH: -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - FLAC__stream_encoder_set_do_exhaustive_model_search(e->encoder, options.compression_settings[ic].value.t_bool); -#endif - break; - case CST_MIN_RESIDUAL_PARTITION_ORDER: - FLAC__stream_encoder_set_min_residual_partition_order(e->encoder, options.compression_settings[ic].value.t_unsigned); - break; - case CST_MAX_RESIDUAL_PARTITION_ORDER: - FLAC__stream_encoder_set_max_residual_partition_order(e->encoder, options.compression_settings[ic].value.t_unsigned); - break; - case CST_RICE_PARAMETER_SEARCH_DIST: - FLAC__stream_encoder_set_rice_parameter_search_dist(e->encoder, options.compression_settings[ic].value.t_unsigned); - break; - } - } -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - if(*apodizations) - FLAC__stream_encoder_set_apodization(e->encoder, apodizations); -#endif - FLAC__stream_encoder_set_total_samples_estimate(e->encoder, e->total_samples_to_encode); - FLAC__stream_encoder_set_metadata(e->encoder, (num_metadata > 0)? metadata : 0, num_metadata); - FLAC__stream_encoder_set_limit_min_bitrate(e->encoder, options.limit_min_bitrate); - - FLAC__stream_encoder_disable_constant_subframes(e->encoder, options.debug.disable_constant_subframes); - FLAC__stream_encoder_disable_fixed_subframes(e->encoder, options.debug.disable_fixed_subframes); - FLAC__stream_encoder_disable_verbatim_subframes(e->encoder, options.debug.disable_verbatim_subframes); - if(!options.debug.do_md5) { - flac__utils_printf(stderr, 1, "%s: WARNING, MD5 computation disabled, resulting file will not have MD5 sum\n", e->inbasefilename); - if(e->treat_warnings_as_errors) { - static_metadata_clear(&static_metadata); - return false; - } - FLAC__stream_encoder_set_do_md5(e->encoder, false); - } - else if(e->is_stdout) { - flac__utils_printf(stderr, 1, "%s: WARNING, cannot write back MD5 sum when encoding to stdout\n", e->inbasefilename); - if(e->treat_warnings_as_errors) { - static_metadata_clear(&static_metadata); - return false; - } - } - -#if FLAC__HAS_OGG - if(e->use_ogg) { - FLAC__stream_encoder_set_ogg_serial_number(e->encoder, options.serial_number); - - init_status = FLAC__stream_encoder_init_ogg_file(e->encoder, e->is_stdout? 0 : e->outfilename, encoder_progress_callback, /*client_data=*/e); - } - else -#endif - { - init_status = FLAC__stream_encoder_init_file(e->encoder, e->is_stdout? 0 : e->outfilename, encoder_progress_callback, /*client_data=*/e); - } - - if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { - print_error_with_init_status(e, "ERROR initializing encoder", init_status); - if(FLAC__stream_encoder_get_state(e->encoder) != FLAC__STREAM_ENCODER_IO_ERROR) - e->outputfile_opened = true; - static_metadata_clear(&static_metadata); - return false; - } - else - e->outputfile_opened = true; - -#if 0 /* in case time.h with clock() isn't available for some reason */ - e->stats_frames_interval = - (FLAC__stream_encoder_get_do_exhaustive_model_search(e->encoder) && FLAC__stream_encoder_get_do_qlp_coeff_prec_search(e->encoder))? 0x1f : - (FLAC__stream_encoder_get_do_exhaustive_model_search(e->encoder) || FLAC__stream_encoder_get_do_qlp_coeff_prec_search(e->encoder))? 0x3f : - 0xff; -#endif - - static_metadata_clear(&static_metadata); - - return true; -} - -FLAC__bool EncoderSession_process(EncoderSession *e, const FLAC__int32 * const buffer[], uint32_t samples) -{ - if(e->replay_gain) { - if(!grabbag__replaygain_analyze(buffer, e->info.channels==2, e->info.bits_per_sample, samples)) { - flac__utils_printf(stderr, 1, "%s: WARNING, error while calculating ReplayGain\n", e->inbasefilename); - if(e->treat_warnings_as_errors) - return false; - } - } - - return FLAC__stream_encoder_process(e->encoder, buffer, samples); -} - -FLAC__bool EncoderSession_format_is_iff(const EncoderSession *e) -{ - return - e->format == FORMAT_WAVE || - e->format == FORMAT_WAVE64 || - e->format == FORMAT_RF64 || - e->format == FORMAT_AIFF || - e->format == FORMAT_AIFF_C; -} - -FLAC__bool convert_to_seek_table_template(const char *requested_seek_points, int num_requested_seek_points, FLAC__StreamMetadata *cuesheet, EncoderSession *e) -{ - const FLAC__bool only_placeholders = e->is_stdout; - FLAC__bool has_real_points; - - if(num_requested_seek_points == 0 && 0 == cuesheet) - return true; - -#if FLAC__HAS_OGG - if(e->use_ogg) - return true; -#endif - - if(num_requested_seek_points < 0) { - requested_seek_points = "10s;"; - num_requested_seek_points = 1; - } - - if(num_requested_seek_points > 0) { - if(!grabbag__seektable_convert_specification_to_template(requested_seek_points, only_placeholders, e->total_samples_to_encode, e->info.sample_rate, e->seek_table_template, &has_real_points)) - return false; - } - - if(0 != cuesheet) { - uint32_t i, j; - const FLAC__StreamMetadata_CueSheet *cs = &cuesheet->data.cue_sheet; - for(i = 0; i < cs->num_tracks; i++) { - const FLAC__StreamMetadata_CueSheet_Track *tr = cs->tracks+i; - for(j = 0; j < tr->num_indices; j++) { - if(!FLAC__metadata_object_seektable_template_append_point(e->seek_table_template, tr->offset + tr->indices[j].offset)) - return false; - has_real_points = true; - } - } - if(has_real_points) - if(!FLAC__metadata_object_seektable_template_sort(e->seek_table_template, /*compact=*/true)) - return false; - } - - if(has_real_points) { - if(e->is_stdout) { - flac__utils_printf(stderr, 1, "%s: WARNING, cannot write back seekpoints when encoding to stdout\n", e->inbasefilename); - if(e->treat_warnings_as_errors) - return false; - } - } - - return true; -} - -FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, uint32_t sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input) -{ - /* convert from mm:ss.sss to sample number if necessary */ - if(!flac__utils_canonicalize_skip_until_specification(spec, sample_rate)) { - flac__utils_printf(stderr, 1, "%s: ERROR, value of --until is too large\n", inbasefilename); - return false; - } - - /* special case: if "--until=-0", use the special value '0' to mean "end-of-stream" */ - if(spec->is_relative && spec->value.samples == 0) { - spec->is_relative = false; - return true; - } - - /* in any other case the total samples in the input must be known */ - if(total_samples_in_input == 0) { - flac__utils_printf(stderr, 1, "%s: ERROR, cannot use --until when input length is unknown\n", inbasefilename); - return false; - } - - FLAC__ASSERT(spec->value_is_samples); - - /* convert relative specifications to absolute */ - if(spec->is_relative) { - if(spec->value.samples <= 0) - spec->value.samples += (FLAC__int64)total_samples_in_input; - else - spec->value.samples += skip; - spec->is_relative = false; - } - - /* error check */ - if(spec->value.samples < 0) { - flac__utils_printf(stderr, 1, "%s: ERROR, --until value is before beginning of input\n", inbasefilename); - return false; - } - if((FLAC__uint64)spec->value.samples <= skip) { - flac__utils_printf(stderr, 1, "%s: ERROR, --until value is before --skip point\n", inbasefilename); - return false; - } - if((FLAC__uint64)spec->value.samples > total_samples_in_input) { - flac__utils_printf(stderr, 1, "%s: ERROR, --until value is after end of input\n", inbasefilename); - return false; - } - - return true; -} - -FLAC__bool verify_metadata(const EncoderSession *e, FLAC__StreamMetadata **metadata, uint32_t num_metadata) -{ - FLAC__bool metadata_picture_has_type1 = false; - FLAC__bool metadata_picture_has_type2 = false; - uint32_t i; - - FLAC__ASSERT(0 != metadata); - for(i = 0; i < num_metadata; i++) { - const FLAC__StreamMetadata *m = metadata[i]; - if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) { - if(!FLAC__format_seektable_is_legal(&m->data.seek_table)) { - flac__utils_printf(stderr, 1, "%s: ERROR: SEEKTABLE metadata block is invalid\n", e->inbasefilename); - return false; - } - } - else if(m->type == FLAC__METADATA_TYPE_CUESHEET) { - if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0)) { - flac__utils_printf(stderr, 1, "%s: ERROR: CUESHEET metadata block is invalid\n", e->inbasefilename); - return false; - } - } - else if(m->type == FLAC__METADATA_TYPE_PICTURE) { - const char *error = 0; - if(!FLAC__format_picture_is_legal(&m->data.picture, &error)) { - flac__utils_printf(stderr, 1, "%s: ERROR: PICTURE metadata block is invalid: %s\n", e->inbasefilename, error); - return false; - } - if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) { - if(metadata_picture_has_type1) { - flac__utils_printf(stderr, 1, "%s: ERROR: there may only be one picture of type 1 (32x32 icon) in the file\n", e->inbasefilename); - return false; - } - metadata_picture_has_type1 = true; - } - else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) { - if(metadata_picture_has_type2) { - flac__utils_printf(stderr, 1, "%s: ERROR: there may only be one picture of type 2 (icon) in the file\n", e->inbasefilename); - return false; - } - metadata_picture_has_type2 = true; - } - } - } - - return true; -} - -FLAC__bool format_input(FLAC__int32 *dest[], uint32_t wide_samples, FLAC__bool is_big_endian, FLAC__bool is_unsigned_samples, uint32_t channels, uint32_t bps, uint32_t shift, size_t *channel_map) -{ - uint32_t wide_sample, sample, channel; - FLAC__int32 *out[FLAC__MAX_CHANNELS]; - - if(0 == channel_map) { - for(channel = 0; channel < channels; channel++) - out[channel] = dest[channel]; - } - else { - for(channel = 0; channel < channels; channel++) - out[channel] = dest[channel_map[channel]]; - } - - if(bps == 8) { - if(is_unsigned_samples) { - for(channel = 0; channel < channels; channel++) - for(sample = channel, wide_sample = 0; wide_sample < wide_samples; wide_sample++, sample+=channels) - out[channel][wide_sample] = (FLAC__int32)ubuffer.u8[sample] - 0x80; - } - else { - for(channel = 0; channel < channels; channel++) - for(sample = channel, wide_sample = 0; wide_sample < wide_samples; wide_sample++, sample+=channels) - out[channel][wide_sample] = (FLAC__int32)ubuffer.s8[sample]; - } - } - else if(bps == 16) { - if(is_unsigned_samples) { - if(is_big_endian != is_big_endian_host_) { - for(channel = 0; channel < channels; channel++) - for(sample = channel, wide_sample = 0; wide_sample < wide_samples; wide_sample++, sample+=channels) - out[channel][wide_sample] = (FLAC__int32)(ENDSWAP_16(ubuffer.u16[sample])) - 0x8000; - } - else { - for(channel = 0; channel < channels; channel++) - for(sample = channel, wide_sample = 0; wide_sample < wide_samples; wide_sample++, sample+=channels) - out[channel][wide_sample] = (FLAC__int32)ubuffer.u16[sample] - 0x8000; - } - } - else { - if(is_big_endian != is_big_endian_host_) { - for(channel = 0; channel < channels; channel++) - for(sample = channel, wide_sample = 0; wide_sample < wide_samples; wide_sample++, sample+=channels) - out[channel][wide_sample] = (int16_t)(ENDSWAP_16(ubuffer.s16[sample])); - - } - else { - for(channel = 0; channel < channels; channel++) - for(sample = channel, wide_sample = 0; wide_sample < wide_samples; wide_sample++, sample+=channels) - out[channel][wide_sample] = ubuffer.s16[sample]; - } - } - } - else if(bps == 24) { - if(!is_big_endian) { - if(is_unsigned_samples) { - for(channel = 0; channel < channels; channel++) { - uint32_t b = 3*channel; - for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) { - uint32_t t; - t = ubuffer.u8[b]; - t |= (uint32_t)(ubuffer.u8[b+1]) << 8; - t |= (uint32_t)(ubuffer.u8[b+2]) << 16; - out[channel][wide_sample] = (FLAC__int32)t - 0x800000; - b += 3*channels; - } - } - } - else { - for(channel = 0; channel < channels; channel++) { - uint32_t b = 3*channel; - for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) { - uint32_t t; - t = ubuffer.u8[b]; - t |= (uint32_t)(ubuffer.u8[b+1]) << 8; - t |= (uint32_t)((int32_t)(ubuffer.s8[b+2])) << 16; - out[channel][wide_sample] = t; - b += 3*channels; - } - } - } - } - else { - if(is_unsigned_samples) { - for(channel = 0; channel < channels; channel++) { - uint32_t b = 3*channel; - for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) { - uint32_t t; - t = ubuffer.u8[b]; t <<= 8; - t |= ubuffer.u8[b+1]; t <<= 8; - t |= ubuffer.u8[b+2]; - out[channel][wide_sample] = (FLAC__int32)t - 0x800000; - b += 3*channels; - } - } - } - else { - for(channel = 0; channel < channels; channel++) { - uint32_t b = 3*channel; - for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) { - uint32_t t; - t = ubuffer.s8[b]; t <<= 8; - t |= ubuffer.u8[b+1]; t <<= 8; - t |= ubuffer.u8[b+2]; - out[channel][wide_sample] = t; - b += 3*channels; - } - } - } - } - } - else if(bps == 32) { - if(is_unsigned_samples) { - if(is_big_endian != is_big_endian_host_) { - for(channel = 0; channel < channels; channel++) - for(sample = channel, wide_sample = 0; wide_sample < wide_samples; wide_sample++, sample+=channels) - out[channel][wide_sample] = ENDSWAP_32(ubuffer.u32[sample]) - 0x80000000; - } - else { - for(channel = 0; channel < channels; channel++) - for(sample = channel, wide_sample = 0; wide_sample < wide_samples; wide_sample++, sample+=channels) - out[channel][wide_sample] = ubuffer.u32[sample] - 0x80000000; - } - } - else { - if(is_big_endian != is_big_endian_host_) { - for(channel = 0; channel < channels; channel++) - for(sample = channel, wide_sample = 0; wide_sample < wide_samples; wide_sample++, sample+=channels) - out[channel][wide_sample] = ENDSWAP_32(ubuffer.s32[sample]); - } - else { - for(channel = 0; channel < channels; channel++) - for(sample = channel, wide_sample = 0; wide_sample < wide_samples; wide_sample++, sample+=channels) - out[channel][wide_sample] = ubuffer.s32[sample]; - } - } - } - else { - flac__utils_printf(stderr, 1, "ERROR: unsupported input format\n"); - return false; - } - if(shift > 0) { - FLAC__int32 mask = (1<>= shift; - } - } - return true; -} - -void encoder_progress_callback(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate, void *client_data) -{ - EncoderSession *e = (EncoderSession*)client_data; - - const FLAC__uint64 uesize = e->unencoded_size; - - (void)encoder, (void)total_frames_estimate, (void) frames_written; - - e->bytes_written = bytes_written; - e->samples_written = samples_written; - - e->progress = e->total_samples_to_encode ? (double)samples_written / (double)e->total_samples_to_encode : 0; - e->compression_ratio = (e->progress && uesize) ? (double)e->bytes_written / ((double)uesize * min(1.0, e->progress)) : 0; - -#if 0 /* in case time.h with clock() isn't available for some reason */ - if(e->total_samples_to_encode > 0 && frames_written - e->old_frames_written > e->stats_frames_interval) { - print_stats(e); - e->old_frames_written = frames_written; - } -#else - if(e->total_samples_to_encode > 0 && (clock() - e->old_clock_t) > (CLOCKS_PER_SEC/4)) { - print_stats(e); - e->old_clock_t = clock(); - } - -#endif -} - -FLAC__StreamDecoderReadStatus flac_decoder_read_callback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) -{ - size_t n = 0; - EncoderSession *e = (EncoderSession*)client_data; - FLACDecoderData *data = &e->fmt.flac.client_data; - - (void)decoder; - - if (data->fatal_error) - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - - /* use up lookahead first */ - if (data->lookahead_length) { - n = min(data->lookahead_length, *bytes); - memcpy(buffer, data->lookahead, n); - buffer += n; - data->lookahead += n; - data->lookahead_length -= n; - } - - /* get the rest from file */ - if (*bytes > n) { - *bytes = n + fread(buffer, 1, *bytes-n, e->fin); - if(ferror(e->fin)) - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - else if(0 == *bytes) - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - else - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - else - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; -} - -FLAC__StreamDecoderSeekStatus flac_decoder_seek_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) -{ - EncoderSession *e = (EncoderSession*)client_data; - (void)decoder; - - if(fseeko(e->fin, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0) - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - else - return FLAC__STREAM_DECODER_SEEK_STATUS_OK; -} - -FLAC__StreamDecoderTellStatus flac_decoder_tell_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) -{ - EncoderSession *e = (EncoderSession*)client_data; - FLAC__off_t pos; - (void)decoder; - - if((pos = ftello(e->fin)) < 0) - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - else { - *absolute_byte_offset = (FLAC__uint64)pos; - return FLAC__STREAM_DECODER_TELL_STATUS_OK; - } -} - -FLAC__StreamDecoderLengthStatus flac_decoder_length_callback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) -{ - const EncoderSession *e = (EncoderSession*)client_data; - const FLACDecoderData *data = &e->fmt.flac.client_data; - (void)decoder; - - if(data->filesize < 0) - return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - else { - *stream_length = (FLAC__uint64)data->filesize; - return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; - } -} - -FLAC__bool flac_decoder_eof_callback(const FLAC__StreamDecoder *decoder, void *client_data) -{ - EncoderSession *e = (EncoderSession*)client_data; - (void)decoder; - - return feof(e->fin)? true : false; -} - -FLAC__StreamDecoderWriteStatus flac_decoder_write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - EncoderSession *e = (EncoderSession*)client_data; - FLACDecoderData *data = &e->fmt.flac.client_data; - FLAC__uint64 n = min(data->samples_left_to_process, frame->header.blocksize); - (void)decoder; - - /* Do some checks */ - if(frame->header.channels != e->info.channels) { - print_error_with_state(e, "ERROR: number of channels of input changed mid-stream"); - data->fatal_error = true; - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - if(frame->header.bits_per_sample > e->info.bits_per_sample) { - print_error_with_state(e, "ERROR: bits-per-sample of input changed mid-stream"); - data->fatal_error = true; - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - - if(!EncoderSession_process(e, buffer, (uint32_t)n)) { - print_error_with_state(e, "ERROR during encoding"); - data->fatal_error = true; - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - - data->samples_left_to_process -= n; - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -void flac_decoder_metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - EncoderSession *e = (EncoderSession*)client_data; - FLACDecoderData *data = &e->fmt.flac.client_data; - (void)decoder; - - if (data->fatal_error) - return; - - if ( - data->num_metadata_blocks == sizeof(data->metadata_blocks)/sizeof(data->metadata_blocks[0]) || - 0 == (data->metadata_blocks[data->num_metadata_blocks] = FLAC__metadata_object_clone(metadata)) - ) - data->fatal_error = true; - else - data->num_metadata_blocks++; -} - -void flac_decoder_error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - EncoderSession *e = (EncoderSession*)client_data; - FLACDecoderData *data = &e->fmt.flac.client_data; - (void)decoder; - - stats_print_name(1, e->inbasefilename); - flac__utils_printf(stderr, 1, "ERROR got %s while decoding FLAC input\n", FLAC__StreamDecoderErrorStatusString[status]); - if(!e->continue_through_decode_errors) - data->fatal_error = true; -} - -FLAC__bool parse_cuesheet(FLAC__StreamMetadata **cuesheet, const char *cuesheet_filename, const char *inbasefilename, uint32_t sample_rate, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset, FLAC__bool treat_warnings_as_errors) -{ - FILE *f; - uint32_t last_line_read; - const char *error_message; - - if(0 == cuesheet_filename) - return true; - - if(lead_out_offset == 0) { - flac__utils_printf(stderr, 1, "%s: ERROR cannot import cuesheet when the number of input samples to encode is unknown\n", inbasefilename); - return false; - } - - if(0 == (f = flac_fopen(cuesheet_filename, "r"))) { - flac__utils_printf(stderr, 1, "%s: ERROR opening cuesheet \"%s\" for reading: %s\n", inbasefilename, cuesheet_filename, strerror(errno)); - return false; - } - - *cuesheet = grabbag__cuesheet_parse(f, &error_message, &last_line_read, sample_rate, is_cdda, lead_out_offset); - - fclose(f); - - if(0 == *cuesheet) { - flac__utils_printf(stderr, 1, "%s: ERROR parsing cuesheet \"%s\" on line %u: %s\n", inbasefilename, cuesheet_filename, last_line_read, error_message); - return false; - } - - if(!FLAC__format_cuesheet_is_legal(&(*cuesheet)->data.cue_sheet, /*check_cd_da_subset=*/false, &error_message)) { - flac__utils_printf(stderr, 1, "%s: ERROR parsing cuesheet \"%s\": %s\n", inbasefilename, cuesheet_filename, error_message); - return false; - } - - /* if we're expecting CDDA, warn about non-compliance */ - if(is_cdda && !FLAC__format_cuesheet_is_legal(&(*cuesheet)->data.cue_sheet, /*check_cd_da_subset=*/true, &error_message)) { - flac__utils_printf(stderr, 1, "%s: WARNING cuesheet \"%s\" is not audio CD compliant: %s\n", inbasefilename, cuesheet_filename, error_message); - if(treat_warnings_as_errors) - return false; - (*cuesheet)->data.cue_sheet.is_cd = false; - } - - return true; -} - -static void print_stats(const EncoderSession *encoder_session) -{ - if(flac__utils_verbosity_ >= 2) { - char ratiostr[16]; - - FLAC__ASSERT(encoder_session->total_samples_to_encode > 0); - - if (encoder_session->compression_ratio > 0.0) - flac_snprintf(ratiostr, sizeof(ratiostr), "%0.3f", encoder_session->compression_ratio); - else - flac_snprintf(ratiostr, sizeof(ratiostr), "N/A"); - - if(encoder_session->samples_written == encoder_session->total_samples_to_encode) { - stats_print_name(2, encoder_session->inbasefilename); - stats_print_info(2, "%swrote %" PRIu64 " bytes, ratio=%s", - encoder_session->verify? "Verify OK, " : "", - encoder_session->bytes_written, - ratiostr - ); - } - else { - stats_print_name(2, encoder_session->inbasefilename); - stats_print_info(2, "%u%% complete, ratio=%s", (uint32_t)floor(encoder_session->progress * 100.0 + 0.5), ratiostr); - } - } -} - -void print_error_with_init_status(const EncoderSession *e, const char *message, FLAC__StreamEncoderInitStatus init_status) -{ - const int ilen = strlen(e->inbasefilename) + 1; - const char *state_string = ""; - - flac__utils_printf(stderr, 1, "\n%s: %s\n", e->inbasefilename, message); - - flac__utils_printf(stderr, 1, "%*s init_status = %s\n", ilen, "", FLAC__StreamEncoderInitStatusString[init_status]); - - if(init_status == FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR) { - state_string = FLAC__stream_encoder_get_resolved_state_string(e->encoder); - - flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", state_string); - - /* print out some more info for some errors: */ - if(0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_CLIENT_ERROR])) { - flac__utils_printf(stderr, 1, - "\n" - "An error occurred while writing; the most common cause is that the disk is full.\n" - ); - } - else if(0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_IO_ERROR])) { - flac__utils_printf(stderr, 1, - "\n" - "An error occurred opening the output file; it is likely that the output\n" - "directory does not exist or is not writable, the output file already exists and\n" -#ifdef _WIN32 - "is not writeable, the disk is full or the file has a filename that exceeds the\n" - "path length limit.\n" -#else - "is not writable, or the disk is full.\n" -#endif - ); - } - } - else if(init_status == FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE) { - flac__utils_printf(stderr, 1, - "\n" - "The encoding parameters specified do not conform to the FLAC Subset and may not\n" - "be streamable or playable in hardware devices. If you really understand the\n" - "consequences, you can add --lax to the command-line options to encode with\n" - "these parameters anyway. See http://xiph.org/flac/format.html#subset\n" - ); - } -} - -void print_error_with_state(const EncoderSession *e, const char *message) -{ - const int ilen = strlen(e->inbasefilename) + 1; - const char *state_string; - - flac__utils_printf(stderr, 1, "\n%s: %s\n", e->inbasefilename, message); - - state_string = FLAC__stream_encoder_get_resolved_state_string(e->encoder); - - flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", state_string); - - /* print out some more info for some errors: */ - if(0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_CLIENT_ERROR])) { - flac__utils_printf(stderr, 1, - "\n" - "An error occurred while writing; the most common cause is that the disk is full.\n" - ); - } -} - -void print_verify_error(EncoderSession *e) -{ - FLAC__uint64 absolute_sample; - uint32_t frame_number; - uint32_t channel; - uint32_t sample; - FLAC__int32 expected; - FLAC__int32 got; - - FLAC__stream_encoder_get_verify_decoder_error_stats(e->encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got); - - flac__utils_printf(stderr, 1, "%s: ERROR: mismatch in decoded data, verify FAILED!\n", e->inbasefilename); - flac__utils_printf(stderr, 1, " Absolute sample=%" PRIu64 ", frame=%u, channel=%u, sample=%u, expected %d, got %d\n", absolute_sample, frame_number, channel, sample, expected, got); - flac__utils_printf(stderr, 1, " In all known cases, verify errors are caused by hardware problems,\n"); - flac__utils_printf(stderr, 1, " usually overclocking or bad RAM. Delete %s\n", e->outfilename); - flac__utils_printf(stderr, 1, " and repeat the flac command exactly as before. If it does not give a\n"); - flac__utils_printf(stderr, 1, " verify error in the exact same place each time you try it, then there is\n"); - flac__utils_printf(stderr, 1, " a problem with your hardware; please see the FAQ:\n"); - flac__utils_printf(stderr, 1, " http://xiph.org/flac/faq.html#tools__hardware_prob\n"); - flac__utils_printf(stderr, 1, " If it does fail in the exact same place every time, keep\n"); - flac__utils_printf(stderr, 1, " %s and submit a bug report to:\n", e->outfilename); - flac__utils_printf(stderr, 1, " https://github.com/xiph/flac/issues\n"); - flac__utils_printf(stderr, 1, " Make sure to upload the FLAC file and use the \"Monitor\" feature to\n"); - flac__utils_printf(stderr, 1, " monitor the bug status.\n"); - flac__utils_printf(stderr, 1, "Verify FAILED! Do not trust %s\n", e->outfilename); -} - -FLAC__bool read_bytes(FILE *f, FLAC__byte *buf, size_t n, FLAC__bool eof_ok, const char *fn) -{ - size_t bytes_read = fread(buf, 1, n, f); - - if(bytes_read == 0) { - if(!eof_ok) { - flac__utils_printf(stderr, 1, "%s: ERROR: unexpected EOF\n", fn); - return false; - } - else - return true; - } - if(bytes_read < n) { - flac__utils_printf(stderr, 1, "%s: ERROR: unexpected EOF\n", fn); - return false; - } - return true; -} - -FLAC__bool read_uint16(FILE *f, FLAC__bool big_endian, FLAC__uint16 *val, const char *fn) -{ - if(!read_bytes(f, (FLAC__byte*)val, 2, /*eof_ok=*/false, fn)) - return false; - if(is_big_endian_host_ != big_endian) { - FLAC__byte tmp, *b = (FLAC__byte*)val; - tmp = b[1]; b[1] = b[0]; b[0] = tmp; - } - return true; -} - -FLAC__bool read_uint32(FILE *f, FLAC__bool big_endian, FLAC__uint32 *val, const char *fn) -{ - if(!read_bytes(f, (FLAC__byte*)val, 4, /*eof_ok=*/false, fn)) - return false; - if(is_big_endian_host_ != big_endian) { - FLAC__byte tmp, *b = (FLAC__byte*)val; - tmp = b[3]; b[3] = b[0]; b[0] = tmp; - tmp = b[2]; b[2] = b[1]; b[1] = tmp; - } - return true; -} - -FLAC__bool read_uint64(FILE *f, FLAC__bool big_endian, FLAC__uint64 *val, const char *fn) -{ - if(!read_bytes(f, (FLAC__byte*)val, 8, /*eof_ok=*/false, fn)) - return false; - if(is_big_endian_host_ != big_endian) { - FLAC__byte tmp, *b = (FLAC__byte*)val; - tmp = b[7]; b[7] = b[0]; b[0] = tmp; - tmp = b[6]; b[6] = b[1]; b[1] = tmp; - tmp = b[5]; b[5] = b[2]; b[2] = tmp; - tmp = b[4]; b[4] = b[3]; b[3] = tmp; - } - return true; -} - -FLAC__bool read_sane_extended(FILE *f, FLAC__uint32 *val, const char *fn) - /* Read an IEEE 754 80-bit (aka SANE) extended floating point value from 'f', - * convert it into an integral value and store in 'val'. Return false if only - * between 1 and 9 bytes remain in 'f', if 0 bytes remain in 'f', or if the - * value is negative, between zero and one, or too large to be represented by - * 'val'; return true otherwise. - */ -{ - uint32_t i; - FLAC__byte buf[10]; - FLAC__uint64 p = 0; - FLAC__int16 e; - FLAC__int16 shift; - - if(!read_bytes(f, buf, sizeof(buf), /*eof_ok=*/false, fn)) - return false; - e = ((FLAC__uint16)(buf[0])<<8 | (FLAC__uint16)(buf[1]))-0x3FFF; - shift = 63-e; - if((buf[0]>>7)==1U || e<0 || e>=63) { - flac__utils_printf(stderr, 1, "%s: ERROR: invalid floating-point value\n", fn); - return false; - } - - for(i = 0; i < 8; ++i) - p |= (FLAC__uint64)(buf[i+2])<<(56U-i*8); - *val = (FLAC__uint32)((p>>shift)+(p>>(shift-1) & 0x1)); - - return true; -} - -FLAC__bool fskip_ahead(FILE *f, FLAC__uint64 offset) -{ - static uint8_t dump[8192]; - struct flac_stat_s stb; - - if(flac_fstat(fileno(f), &stb) == 0 && (stb.st_mode & S_IFMT) == S_IFREG) - { - if(fseeko(f, offset, SEEK_CUR) == 0) - return true; - } - while(offset > 0) { - const long need = (long)min(offset, sizeof(dump)); - if((long)fread(dump, 1, need, f) < need) - return false; - offset -= need; - } - return true; -} - -uint32_t count_channel_mask_bits(FLAC__uint32 mask) -{ - uint32_t count = 0; - while(mask) { - if(mask & 1) - count++; - mask >>= 1; - } - return count; -} - diff --git a/flac/src/flac/encode.h b/flac/src/flac/encode.h deleted file mode 100644 index 2d65c50..0000000 --- a/flac/src/flac/encode.h +++ /dev/null @@ -1,116 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 flac__encode_h -#define flac__encode_h - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "FLAC/metadata.h" -#include "foreign_metadata.h" -#include "utils.h" -#include "share/compat.h" - -extern const int FLAC_ENCODE__DEFAULT_PADDING; - -typedef enum { - CST_BLOCKSIZE, - CST_COMPRESSION_LEVEL, - CST_DO_MID_SIDE, - CST_LOOSE_MID_SIDE, - CST_APODIZATION, - CST_MAX_LPC_ORDER, - CST_QLP_COEFF_PRECISION, - CST_DO_QLP_COEFF_PREC_SEARCH, - CST_DO_ESCAPE_CODING, - CST_DO_EXHAUSTIVE_MODEL_SEARCH, - CST_MIN_RESIDUAL_PARTITION_ORDER, - CST_MAX_RESIDUAL_PARTITION_ORDER, - CST_RICE_PARAMETER_SEARCH_DIST -} compression_setting_type_t; - -typedef struct { - compression_setting_type_t type; - union { - FLAC__bool t_bool; - unsigned t_unsigned; - const char *t_string; - } value; -} compression_setting_t; - -typedef struct { - utils__SkipUntilSpecification skip_specification; - utils__SkipUntilSpecification until_specification; - FLAC__bool verify; -#if FLAC__HAS_OGG - FLAC__bool use_ogg; - long serial_number; -#endif - FLAC__bool lax; - int padding; - size_t num_compression_settings; - compression_setting_t compression_settings[64]; - char *requested_seek_points; - int num_requested_seek_points; - const char *cuesheet_filename; - FLAC__bool treat_warnings_as_errors; - FLAC__bool continue_through_decode_errors; /* currently only obeyed when encoding from FLAC or Ogg FLAC */ - FLAC__bool cued_seekpoints; - FLAC__bool channel_map_none; /* --channel-map=none specified, eventually will expand to take actual channel map */ - - FLAC__bool is_first_file; - FLAC__bool is_last_file; - FLAC__bool replay_gain; - FLAC__bool ignore_chunk_sizes; - FLAC__bool error_on_compression_fail; - FLAC__bool limit_min_bitrate; - FLAC__bool relaxed_foreign_metadata_handling; - - FLAC__StreamMetadata *vorbis_comment; - FLAC__StreamMetadata *vorbis_comment_with_channel_mask_tag; - FLAC__StreamMetadata *pictures[64]; - unsigned num_pictures; - - FileFormat format; - union { - struct { - FLAC__bool is_big_endian; - FLAC__bool is_unsigned_samples; - unsigned channels; - unsigned bps; - unsigned sample_rate; - } raw; - struct { - foreign_metadata_t *foreign_metadata; /* NULL unless --keep-foreign-metadata requested */ - } iff; - } format_options; - - struct { - FLAC__bool disable_constant_subframes; - FLAC__bool disable_fixed_subframes; - FLAC__bool disable_verbatim_subframes; - FLAC__bool do_md5; - } debug; -} encode_options_t; - -int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, uint32_t lookahead_length, encode_options_t options); - -#endif diff --git a/flac/src/flac/foreign_metadata.c b/flac/src/flac/foreign_metadata.c deleted file mode 100644 index f63fc3e..0000000 --- a/flac/src/flac/foreign_metadata.c +++ /dev/null @@ -1,952 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include /* for FILE etc. */ -#include /* for calloc() etc. */ -#include /* for memcmp() etc. */ -#include "FLAC/assert.h" -#include "FLAC/metadata.h" -#include "share/alloc.h" -#include "share/compat.h" -#include "foreign_metadata.h" - -#ifdef min -#undef min -#endif -#define min(x,y) ((x)<(y)?(x):(y)) - -const char *FLAC__FOREIGN_METADATA_APPLICATION_ID[FLAC__FOREIGN_METADATA_NUMBER_OF_RECOGNIZED_APPLICATION_IDS] = { "aiff" , "riff", "w64 " }; - -static FLAC__uint32 unpack32be_(const FLAC__byte *b) -{ - return ((FLAC__uint32)b[0]<<24) + ((FLAC__uint32)b[1]<<16) + ((FLAC__uint32)b[2]<<8) + (FLAC__uint32)b[3]; -} - -static FLAC__uint32 unpack32le_(const FLAC__byte *b) -{ - return (FLAC__uint32)b[0] + ((FLAC__uint32)b[1]<<8) + ((FLAC__uint32)b[2]<<16) + ((FLAC__uint32)b[3]<<24); -} - -static FLAC__uint64 unpack64le_(const FLAC__byte *b) -{ - return (FLAC__uint64)b[0] + ((FLAC__uint64)b[1]<<8) + ((FLAC__uint64)b[2]<<16) + ((FLAC__uint64)b[3]<<24) + ((FLAC__uint64)b[4]<<32) + ((FLAC__uint64)b[5]<<40) + ((FLAC__uint64)b[6]<<48) + ((FLAC__uint64)b[7]<<56); -} - -/* copies 'size' bytes from file 'fin' to 'fout', filling in *error with 'read_error' or 'write_error' as necessary */ -static FLAC__bool copy_data_(FILE *fin, FILE *fout, size_t size, const char **error, const char * const read_error, const char * const write_error) -{ - FLAC__byte buffer[4096]; - size_t left; - for(left = size; left > 0; ) { - size_t need = min(sizeof(buffer), left); - if(fread(buffer, 1, need, fin) < need) { - if(error) *error = read_error; - return false; - } - if(fwrite(buffer, 1, need, fout) < need) { - if(error) *error = write_error; - return false; - } - left -= need; - } - return true; -} - -/* compare 'size' bytes from file 'fin' to 'fout', filling in *error with 'read_error' or 'write_error' as necessary */ -static FLAC__bool compare_data_(FILE *fin, FILE *fout, size_t size, const char **error, const char * const read_error, const char * const write_error, const char * const compare_error) -{ - FLAC__byte buffer_in[4096]; - FLAC__byte buffer_out[4096]; /* sizes need to be the same */ - size_t left; - for(left = size; left > 0; ) { - size_t need = min(sizeof(buffer_in), left); - if(fread(buffer_in, 1, need, fin) < need) { - if(error) *error = read_error; - return false; - } - if(fread(buffer_out, 1, need, fout) < need) { - if(error) *error = write_error; - return false; - } - if(memcmp(buffer_in, buffer_out, need)) { - if(error) *error = compare_error; - return false; - } - left -= need; - } - return true; -} - -static FLAC__bool append_block_(foreign_metadata_t *fm, FLAC__off_t offset, FLAC__uint32 size, const char **error) -{ - foreign_block_t *fb; - if(size >= ((1u << FLAC__STREAM_METADATA_LENGTH_LEN) - FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)) { - if(error) *error = "found foreign metadata chunk is too large (max is 16MiB per chunk)"; - return false; - } - fb = safe_realloc_nofree_muladd2_(fm->blocks, sizeof(foreign_block_t), /*times (*/fm->num_blocks, /*+*/1/*)*/); - if(fb) { - fb[fm->num_blocks].offset = offset; - fb[fm->num_blocks].size = size; - fm->num_blocks++; - fm->blocks = fb; - return true; - } - if(error) *error = "out of memory"; - return false; -} - -static FLAC__bool read_from_aiff_(foreign_metadata_t *fm, FILE *f, const char **error) -{ - FLAC__byte buffer[12]; - FLAC__off_t offset, eof_offset; - if((offset = ftello(f)) < 0) { - if(error) *error = "ftello() error (001)"; - return false; - } - if(fread(buffer, 1, 12, f) < 12 || memcmp(buffer, "FORM", 4) || (memcmp(buffer+8, "AIFF", 4) && memcmp(buffer+8, "AIFC", 4))) { - if(error) *error = "unsupported FORM layout (002)"; - return false; - } - if(!append_block_(fm, offset, 12, error)) - return false; - eof_offset = (FLAC__off_t)8 + (FLAC__off_t)unpack32be_(buffer+4); - while(!feof(f)) { - FLAC__uint32 size; - if((offset = ftello(f)) < 0) { - if(error) *error = "ftello() error (003)"; - return false; - } - if((size = fread(buffer, 1, 8, f)) < 8) { - if(size == 0 && feof(f)) - break; - if(error) *error = "invalid AIFF file (004)"; - return false; - } - size = unpack32be_(buffer+4); - /* check if pad byte needed */ - if(size & 1) - size++; - if(!memcmp(buffer, "COMM", 4)) { - if(fm->format_block) { - if(error) *error = "invalid AIFF file: multiple \"COMM\" chunks (005)"; - return false; - } - if(fm->audio_block) { - if(error) *error = "invalid AIFF file: \"SSND\" chunk before \"COMM\" chunk (006)"; - return false; - } - fm->format_block = fm->num_blocks; - } - else if(!memcmp(buffer, "SSND", 4)) { - if(fm->audio_block) { - if(error) *error = "invalid AIFF file: multiple \"SSND\" chunks (007)"; - return false; - } - if(!fm->format_block) { - if(error) *error = "invalid AIFF file: \"SSND\" chunk before \"COMM\" chunk (008)"; - return false; - } - fm->audio_block = fm->num_blocks; - /* read #offset bytes */ - if(fread(buffer+8, 1, 4, f) < 4) { - if(error) *error = "invalid AIFF file (009)"; - return false; - } - fm->ssnd_offset_size = unpack32be_(buffer+8); - if(fseeko(f, -4, SEEK_CUR) < 0) { - if(error) *error = "invalid AIFF file: seek error (010)"; - return false; - } - /* WATCHOUT: For SSND we ignore the blockSize and are not saving any - * unaligned part at the end of the chunk. In retrospect it is pretty - * pointless to save the unaligned data before the PCM but now it is - * done and cast in stone. - */ - } - if(!append_block_(fm, offset, 8 + (memcmp(buffer, "SSND", 4)? size : 8 + fm->ssnd_offset_size), error)) - return false; - /* skip to next chunk */ - if(fseeko(f, size, SEEK_CUR) < 0) { - if(error) *error = "invalid AIFF file: seek error (011)"; - return false; - } - } - if(eof_offset != ftello(f)) { - if(error) *error = "invalid AIFF file: unexpected EOF (012)"; - return false; - } - if(!fm->format_block) { - if(error) *error = "invalid AIFF file: missing \"COMM\" chunk (013)"; - return false; - } - if(!fm->audio_block) { - if(error) *error = "invalid AIFF file: missing \"SSND\" chunk (014)"; - return false; - } - return true; -} - -static FLAC__bool read_from_wave_(foreign_metadata_t *fm, FILE *f, const char **error) -{ - FLAC__byte buffer[12]; - FLAC__off_t offset, eof_offset = -1, ds64_data_size = -1; - if((offset = ftello(f)) < 0) { - if(error) *error = "ftello() error (001)"; - return false; - } - if(fread(buffer, 1, 12, f) < 12 || (memcmp(buffer, "RIFF", 4) && memcmp(buffer, "RF64", 4)) || memcmp(buffer+8, "WAVE", 4)) { - if(error) *error = "unsupported RIFF layout (002)"; - return false; - } - if(!memcmp(buffer, "RF64", 4)) - fm->is_rf64 = true; - if(fm->is_rf64 && sizeof(FLAC__off_t) < 8) { - if(error) *error = "RF64 is not supported on this compile (r00)"; - return false; - } - if(!append_block_(fm, offset, 12, error)) - return false; - if(!fm->is_rf64 || unpack32le_(buffer+4) != 0xffffffff) { - eof_offset = (FLAC__off_t)8 + (FLAC__off_t)unpack32le_(buffer+4); - if(eof_offset & 1) /* fix odd RIFF size */ - eof_offset++; - } - while(!feof(f)) { - FLAC__off_t size; - if((offset = ftello(f)) < 0) { - if(error) *error = "ftello() error (003)"; - return false; - } - if((size = fread(buffer, 1, 8, f)) < 8) { - if(size == 0 && feof(f)) - break; - if(error) *error = "invalid WAVE file (004)"; - return false; - } - size = unpack32le_(buffer+4); - /* check if pad byte needed */ - if(size & 1) - size++; - if(!memcmp(buffer, "fmt ", 4)) { - if(fm->format_block) { - if(error) *error = "invalid WAVE file: multiple \"fmt \" chunks (005)"; - return false; - } - if(fm->audio_block) { - if(error) *error = "invalid WAVE file: \"data\" chunk before \"fmt \" chunk (006)"; - return false; - } - fm->format_block = fm->num_blocks; - } - else if(!memcmp(buffer, "data", 4)) { - if(fm->audio_block) { - if(error) *error = "invalid WAVE file: multiple \"data\" chunks (007)"; - return false; - } - if(!fm->format_block) { - if(error) *error = "invalid WAVE file: \"data\" chunk before \"fmt \" chunk (008)"; - return false; - } - fm->audio_block = fm->num_blocks; - if(fm->is_rf64 && fm->num_blocks < 2) { - if(error) *error = "invalid RF64 file: \"data\" chunk before \"ds64\" chunk (r01)"; - return false; - } - } - if(!append_block_(fm, offset, 8 + (memcmp(buffer, "data", 4)? size : 0), error)) - return false; - /* parse ds64 chunk if necessary */ - if(fm->is_rf64 && fm->num_blocks == 2) { - FLAC__byte buffer2[7*4]; - if(memcmp(buffer, "ds64", 4)) { - if(error) *error = "invalid RF64 file: \"ds64\" chunk does not immediately follow \"WAVE\" marker (r02)"; - return false; - } - /* unpack the size again since we don't want the padding byte effect */ - size = unpack32le_(buffer+4); - if(size < (FLAC__off_t)sizeof(buffer2)) { - if(error) *error = "invalid RF64 file: \"ds64\" chunk size is < 28 (r03)"; - return false; - } - if(size > (FLAC__off_t)sizeof(buffer2)) { - if(error) *error = "RF64 file has \"ds64\" chunk with extra size table, which is not currently supported (r04)"; - return false; - } - if(fread(buffer2, 1, sizeof(buffer2), f) < sizeof(buffer2)) { - if(error) *error = "unexpected EOF reading \"ds64\" chunk data in RF64 file (r05)"; - return false; - } - ds64_data_size = (FLAC__off_t)unpack64le_(buffer2+8); - if(ds64_data_size == (FLAC__off_t)(-1)) { - if(error) *error = "RF64 file has \"ds64\" chunk with data size == -1 (r08)"; - return false; - } - /* check if pad byte needed */ - if(ds64_data_size & 1) - ds64_data_size++; - /* @@@ [2^63 limit] */ - if(ds64_data_size < 0) { - if(error) *error = "RF64 file too large (r09)"; - return false; - } - if(unpack32le_(buffer2+24)) { - if(error) *error = "RF64 file has \"ds64\" chunk with extra size table, which is not currently supported (r06)"; - return false; - } - eof_offset = (FLAC__off_t)8 + (FLAC__off_t)unpack64le_(buffer2); - /* @@@ [2^63 limit] */ - if((FLAC__off_t)unpack64le_(buffer2) < 0 || eof_offset < 0) { - if(error) *error = "RF64 file too large (r07)"; - return false; - } - } - else { /* skip to next chunk */ - if(fm->is_rf64 && !memcmp(buffer, "data", 4) && unpack32le_(buffer+4) == 0xffffffff) { - if(fseeko(f, ds64_data_size, SEEK_CUR) < 0) { - if(error) *error = "invalid RF64 file: seek error (r10)"; - return false; - } - } - else { - if(fseeko(f, size, SEEK_CUR) < 0) { - if(error) *error = "invalid WAVE file: seek error (009)"; - return false; - } - } - } - } - if(fm->is_rf64 && eof_offset == (FLAC__off_t)(-1)) { - if(error) *error = "invalid RF64 file: all RIFF sizes are -1 (r11)"; - return false; - } - if(eof_offset != ftello(f)) { - if(error) *error = "invalid WAVE file: unexpected EOF (010)"; - return false; - } - if(!fm->format_block) { - if(error) *error = "invalid WAVE file: missing \"fmt \" chunk (011)"; - return false; - } - if(!fm->audio_block) { - if(error) *error = "invalid WAVE file: missing \"data\" chunk (012)"; - return false; - } - return true; -} - -static FLAC__bool read_from_wave64_(foreign_metadata_t *fm, FILE *f, const char **error) -{ - FLAC__byte buffer[40]; - FLAC__off_t offset, eof_offset = -1; - if((offset = ftello(f)) < 0) { - if(error) *error = "ftello() error (001)"; - return false; - } - if( - fread(buffer, 1, 40, f) < 40 || - /* RIFF GUID 66666972-912E-11CF-A5D6-28DB04C10000 */ - memcmp(buffer, "\x72\x69\x66\x66\x2E\x91\xCF\x11\xA5\xD6\x28\xDB\x04\xC1\x00\x00", 16) || - /* WAVE GUID 65766177-ACF3-11D3-8CD1-00C04F8EDB8A */ - memcmp(buffer+24, "\x77\x61\x76\x65\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 16) - ) { - if(error) *error = "unsupported Wave64 layout (002)"; - return false; - } - if(sizeof(FLAC__off_t) < 8) { - if(error) *error = "Wave64 is not supported on this compile (r00)"; - return false; - } - if(!append_block_(fm, offset, 40, error)) - return false; - eof_offset = (FLAC__off_t)unpack64le_(buffer+16); /*@@@ [2^63 limit] */ - while(!feof(f)) { - FLAC__uint64 size; - if((offset = ftello(f)) < 0) { - if(error) *error = "ftello() error (003)"; - return false; - } - if((size = fread(buffer, 1, 24, f)) < 24) { - if(size == 0 && feof(f)) - break; - if(error) *error = "invalid Wave64 file (004)"; - return false; - } - size = unpack64le_(buffer+16); - /* check if pad bytes needed */ - if(size & 7) - size = (size+7) & (~((FLAC__uint64)7)); - /* fmt GUID 20746D66-ACF3-11D3-8CD1-00C04F8EDB8A */ - if(!memcmp(buffer, "\x66\x6D\x74\x20\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 16)) { - if(fm->format_block) { - if(error) *error = "invalid Wave64 file: multiple \"fmt \" chunks (005)"; - return false; - } - if(fm->audio_block) { - if(error) *error = "invalid Wave64 file: \"data\" chunk before \"fmt \" chunk (006)"; - return false; - } - fm->format_block = fm->num_blocks; - } - /* data GUID 61746164-ACF3-11D3-8CD1-00C04F8EDB8A */ - else if(!memcmp(buffer, "\x64\x61\x74\x61\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 16)) { - if(fm->audio_block) { - if(error) *error = "invalid Wave64 file: multiple \"data\" chunks (007)"; - return false; - } - if(!fm->format_block) { - if(error) *error = "invalid Wave64 file: \"data\" chunk before \"fmt \" chunk (008)"; - return false; - } - fm->audio_block = fm->num_blocks; - } - if(!append_block_(fm, offset, memcmp(buffer, "\x64\x61\x74\x61\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 16)? (FLAC__uint32)size : 16+8, error)) - return false; - /* skip to next chunk */ - if(fseeko(f, size-24, SEEK_CUR) < 0) { - if(error) *error = "invalid Wave64 file: seek error (009)"; - return false; - } - } - if(eof_offset != ftello(f)) { - if(error) *error = "invalid Wave64 file: unexpected EOF (010)"; - return false; - } - if(!fm->format_block) { - if(error) *error = "invalid Wave64 file: missing \"fmt \" chunk (011)"; - return false; - } - if(!fm->audio_block) { - if(error) *error = "invalid Wave64 file: missing \"data\" chunk (012)"; - return false; - } - return true; -} - -static FLAC__bool write_to_flac_(foreign_metadata_t *fm, FILE *fin, FILE *fout, FLAC__Metadata_SimpleIterator *it, const char **error) -{ - FLAC__byte buffer[4]; - const uint32_t ID_LEN = FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8; - size_t block_num = 0; - FLAC__ASSERT(sizeof(buffer) >= ID_LEN); - while(block_num < fm->num_blocks) { - /* find next matching padding block */ - do { - /* even on the first chunk's loop there will be a skippable STREAMINFO block, on subsequent loops we are first moving past the PADDING we just used */ - if(!FLAC__metadata_simple_iterator_next(it)) { - if(error) *error = "no matching PADDING block found (004)"; - return false; - } - } while(FLAC__metadata_simple_iterator_get_block_type(it) != FLAC__METADATA_TYPE_PADDING); - if(FLAC__metadata_simple_iterator_get_block_length(it) != ID_LEN+fm->blocks[block_num].size) { - if(error) *error = "PADDING block with wrong size found (005)"; - return false; - } - /* transfer chunk into APPLICATION block */ - /* first set up the file pointers */ - if(fseeko(fin, fm->blocks[block_num].offset, SEEK_SET) < 0) { - if(error) *error = "seek failed in WAVE/AIFF file (006)"; - return false; - } - if(fseeko(fout, FLAC__metadata_simple_iterator_get_block_offset(it), SEEK_SET) < 0) { - if(error) *error = "seek failed in FLAC file (007)"; - return false; - } - /* update the type */ - buffer[0] = FLAC__METADATA_TYPE_APPLICATION; - if(FLAC__metadata_simple_iterator_is_last(it)) - buffer[0] |= 0x80; /*MAGIC number*/ - if(fwrite(buffer, 1, 1, fout) < 1) { - if(error) *error = "write failed in FLAC file (008)"; - return false; - } - /* length stays the same so skip over it */ - if(fseeko(fout, FLAC__STREAM_METADATA_LENGTH_LEN/8, SEEK_CUR) < 0) { - if(error) *error = "seek failed in FLAC file (009)"; - return false; - } - /* write the APPLICATION ID */ - memcpy(buffer, FLAC__FOREIGN_METADATA_APPLICATION_ID[fm->type], ID_LEN); - if(fwrite(buffer, 1, ID_LEN, fout) < ID_LEN) { - if(error) *error = "write failed in FLAC file (010)"; - return false; - } - /* transfer the foreign metadata */ - if(!copy_data_(fin, fout, fm->blocks[block_num].size, error, "read failed in WAVE/AIFF file (011)", "write failed in FLAC file (012)")) - return false; - block_num++; - } - return true; -} - -static FLAC__bool read_from_flac_(foreign_metadata_t *fm, FILE *f, FLAC__Metadata_SimpleIterator *it, const char **error) -{ - FLAC__byte id[4], buffer[32]; - FLAC__off_t offset; - FLAC__uint32 length; - FLAC__bool first_block = true, type_found = false, ds64_found = false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_APPLICATION_ID_LEN == sizeof(id)*8); - - while(FLAC__metadata_simple_iterator_next(it)) { - if(FLAC__metadata_simple_iterator_get_block_type(it) != FLAC__METADATA_TYPE_APPLICATION) - continue; - if(!FLAC__metadata_simple_iterator_get_application_id(it, id)) { - if(error) *error = "FLAC__metadata_simple_iterator_get_application_id() error (002)"; - return false; - } - if(first_block) { - uint32_t i; - for(i = 0; i < FLAC__FOREIGN_METADATA_NUMBER_OF_RECOGNIZED_APPLICATION_IDS; i++) - if(memcmp(id, FLAC__FOREIGN_METADATA_APPLICATION_ID[i], sizeof(id)) == 0) { - fm->type = i; - first_block = false; - } - if(first_block) /* means no first foreign metadata block was found yet */ - continue; - } - else if(memcmp(id, FLAC__FOREIGN_METADATA_APPLICATION_ID[fm->type], sizeof(id))) - continue; - offset = FLAC__metadata_simple_iterator_get_block_offset(it); - length = FLAC__metadata_simple_iterator_get_block_length(it); - /* skip over header and app ID */ - offset += (FLAC__STREAM_METADATA_IS_LAST_LEN + FLAC__STREAM_METADATA_TYPE_LEN + FLAC__STREAM_METADATA_LENGTH_LEN) / 8; - offset += sizeof(id); - /* look for format or audio blocks */ - if(fseeko(f, offset, SEEK_SET) < 0) { - if(error) *error = "seek error (003)"; - return false; - } - if(fread(buffer, 1, 4, f) != 4) { - if(error) *error = "read error (004)"; - return false; - } - if(fm->num_blocks == 0) { /* first block? */ - /* Initialize bools */ - fm->is_wavefmtex = 0; - fm->is_aifc = 0; - fm->is_sowt = 0; - fm->is_rf64 = 0 == memcmp(buffer, "RF64", 4); - - if(fm->type == FOREIGN_BLOCK_TYPE__RIFF && (0 == memcmp(buffer, "RIFF", 4) || fm->is_rf64)) - type_found = true; - else if(fm->type == FOREIGN_BLOCK_TYPE__WAVE64 && 0 == memcmp(buffer, "riff", 4)) /* use first 4 bytes instead of whole GUID */ - type_found = true; - else if(fm->type == FOREIGN_BLOCK_TYPE__AIFF && 0 == memcmp(buffer, "FORM", 4)) { - type_found = true; - if(fread(buffer+4, 1, 8, f) != 8) { - if(error) *error = "read error (020)"; - return false; - } - fm->is_aifc = 0 == memcmp(buffer+8, "AIFC", 4); - } - else { - if(error) *error = "unsupported foreign metadata found, may need newer FLAC decoder (005)"; - return false; - } - } - else if(!type_found) { - FLAC__ASSERT(0); - /* double protection: */ - if(error) *error = "unsupported foreign metadata found, may need newer FLAC decoder (006)"; - return false; - } - else if(fm->type == FOREIGN_BLOCK_TYPE__RIFF) { - if(!memcmp(buffer, "fmt ", 4)) { - if(fm->format_block) { - if(error) *error = "invalid WAVE metadata: multiple \"fmt \" chunks (007)"; - return false; - } - if(fm->audio_block) { - if(error) *error = "invalid WAVE metadata: \"data\" chunk before \"fmt \" chunk (008)"; - return false; - } - fm->format_block = fm->num_blocks; - if(fread(buffer+4, 1, 8, f) != 8) { - if(error) *error = "read error (020)"; - return false; - } - fm->is_wavefmtex = 0 == memcmp(buffer+8, "\xfe\xff", 2); - } - else if(!memcmp(buffer, "data", 4)) { - if(fm->audio_block) { - if(error) *error = "invalid WAVE metadata: multiple \"data\" chunks (009)"; - return false; - } - if(!fm->format_block) { - if(error) *error = "invalid WAVE metadata: \"data\" chunk before \"fmt \" chunk (010)"; - return false; - } - fm->audio_block = fm->num_blocks; - } - else if(fm->is_rf64 && fm->num_blocks == 1) { - if(memcmp(buffer, "ds64", 4)) { - if(error) *error = "invalid RF64 metadata: second chunk is not \"ds64\" (011)"; - return false; - } - ds64_found = true; - } - } - else if(fm->type == FOREIGN_BLOCK_TYPE__WAVE64) { - if(!memcmp(buffer, "fmt ", 4)) { /* use first 4 bytes instead of whole GUID */ - if(fm->format_block) { - if(error) *error = "invalid Wave64 metadata: multiple \"fmt \" chunks (012)"; - return false; - } - if(fm->audio_block) { - if(error) *error = "invalid Wave64 metadata: \"data\" chunk before \"fmt \" chunk (013)"; - return false; - } - fm->format_block = fm->num_blocks; - } - else if(!memcmp(buffer, "data", 4)) { /* use first 4 bytes instead of whole GUID */ - if(fm->audio_block) { - if(error) *error = "invalid Wave64 metadata: multiple \"data\" chunks (014)"; - return false; - } - if(!fm->format_block) { - if(error) *error = "invalid Wave64 metadata: \"data\" chunk before \"fmt \" chunk (015)"; - return false; - } - fm->audio_block = fm->num_blocks; - } - } - else if(fm->type == FOREIGN_BLOCK_TYPE__AIFF) { - if(!memcmp(buffer, "COMM", 4)) { - if(fm->format_block) { - if(error) *error = "invalid AIFF metadata: multiple \"COMM\" chunks (016)"; - return false; - } - if(fm->audio_block) { - if(error) *error = "invalid AIFF metadata: \"SSND\" chunk before \"COMM\" chunk (017)"; - return false; - } - fm->format_block = fm->num_blocks; - if(fm->is_aifc) { - if(fread(buffer+4, 1, 26, f) != 26) { - if(error) *error = "read error (020)"; - return false; - } - fm->is_sowt = 0 == memcmp(buffer+26, "sowt", 2); - fm->aifc_comm_length = length; - } - } - else if(!memcmp(buffer, "SSND", 4)) { - if(fm->audio_block) { - if(error) *error = "invalid AIFF metadata: multiple \"SSND\" chunks (018)"; - return false; - } - if(!fm->format_block) { - if(error) *error = "invalid AIFF metadata: \"SSND\" chunk before \"COMM\" chunk (019)"; - return false; - } - fm->audio_block = fm->num_blocks; - /* read SSND offset size */ - if(fread(buffer+4, 1, 8, f) != 8) { - if(error) *error = "read error (020)"; - return false; - } - fm->ssnd_offset_size = unpack32be_(buffer+8); - } - } - else { - FLAC__ASSERT(0); - /* double protection: */ - if(error) *error = "unsupported foreign metadata found, may need newer FLAC decoder (021)"; - return false; - } - if(!append_block_(fm, offset, FLAC__metadata_simple_iterator_get_block_length(it)-sizeof(id), error)) - return false; - } - if(fm->is_rf64 && !ds64_found) { - if(error) *error = "invalid RF64 file: second chunk is not \"ds64\" (023)"; - return false; - } - if(!fm->format_block) { - if(error) - *error = - fm->type==FOREIGN_BLOCK_TYPE__RIFF? "invalid WAVE file: missing \"fmt \" chunk (024)" : - fm->type==FOREIGN_BLOCK_TYPE__WAVE64? "invalid Wave64 file: missing \"fmt \" chunk (025)" : - "invalid AIFF file: missing \"COMM\" chunk (026)"; - return false; - } - if(!fm->audio_block) { - if(error) - *error = - fm->type==FOREIGN_BLOCK_TYPE__RIFF? "invalid WAVE file: missing \"data\" chunk (027)" : - fm->type==FOREIGN_BLOCK_TYPE__WAVE64? "invalid Wave64 file: missing \"data\" chunk (028)" : - "invalid AIFF file: missing \"SSND\" chunk (029)"; - return false; - } - return true; -} - -static FLAC__bool write_to_iff_(foreign_metadata_t *fm, FILE *fin, FILE *fout, FLAC__off_t offset1, FLAC__off_t offset2, FLAC__off_t offset3, const char **error) -{ - size_t i; - if(fseeko(fout, offset1, SEEK_SET) < 0) { - if(error) *error = "seek failed in WAVE/AIFF file"; - return false; - } - - /* don't write first (RIFF/RF64/FORM) chunk, or ds64 chunk in the case of RF64 */ - for(i = fm->is_rf64?2:1; i < fm->format_block; i++) { - if(fseeko(fin, fm->blocks[i].offset, SEEK_SET) < 0) { - if(error) *error = "seek failed in FLAC file"; - return false; - } - if(!copy_data_(fin, fout, fm->blocks[i].size, error, "read failed in FLAC file", "write failed in WAVE/AIFF file")) - return false; - } - - if(fm->is_aifc) { - /* Need to restore compression type name */ - if(fseeko(fout, 30, SEEK_CUR) < 0) { - if(error) *error = "seek failed in AIFF-C file"; - return false; - } - if(fseeko(fin, fm->blocks[i].offset+30, SEEK_SET) < 0) { - if(error) *error = "seek failed in FLAC file"; - return false; - } - if(!copy_data_(fin, fout, fm->aifc_comm_length-34, error, "read failed in FLAC file", "write failed in WAVE/AIFF file")) - return false; - /* Now seek back */ - if(fseeko(fout, ((FLAC__int32)(fm->aifc_comm_length) * -1) + 4, SEEK_CUR) < 0) { - if(error) *error = "seek failed in AIFF-C file"; - return false; - } - } - if(fseeko(fout, offset2, SEEK_SET) < 0) { - if(error) *error = "seek failed in WAVE/AIFF file (006)"; - return false; - } - for(i = fm->format_block+1; i < fm->audio_block; i++) { - if(fseeko(fin, fm->blocks[i].offset, SEEK_SET) < 0) { - if(error) *error = "seek failed in FLAC file"; - return false; - } - if(!copy_data_(fin, fout, fm->blocks[i].size, error, "read failed in FLAC file", "write failed in WAVE/AIFF file")) - return false; - } - if(fseeko(fout, offset3, SEEK_SET) < 0) { - if(error) *error = "seek failed in WAVE/AIFF file"; - return false; - } - for(i = fm->audio_block+1; i < fm->num_blocks; i++) { - if(fseeko(fin, fm->blocks[i].offset, SEEK_SET) < 0) { - if(error) *error = "seek failed in FLAC file"; - return false; - } - if(!copy_data_(fin, fout, fm->blocks[i].size, error, "read failed in FLAC file", "write failed in WAVE/AIFF file")) - return false; - } - return true; -} - -static FLAC__bool compare_with_iff_(foreign_metadata_t *fm, FILE *fin, FILE *fout, FLAC__off_t offset3, const char **error) -{ - size_t i; - - /* Compare blocks before audio data */ - for(i = 0; i <= (fm->audio_block); i++) { - if(fseeko(fin, fm->blocks[i].offset, SEEK_SET) < 0) { - if(error) *error = "seek failed in FLAC file"; - return false; - } - if(!compare_data_(fin, fout, fm->blocks[i].size, error, "read failed in FLAC file", "read failed in WAVE/AIFF file", - i==0?"stored main chunk length differs from written length":( - i==fm->format_block?"stored foreign format block differs from written block. Perhaps the file is being restored to a different format than that of the original file":( - i==fm->audio_block?"stored audio length differs from written length. Perhaps the file changed in length after being originally encoded":"restore of foreign metadata failed")))) - return false; - } - - /* Seek beyond audio */ - if(fseeko(fout, offset3, SEEK_SET) < 0) { - if(error) *error = "seek failed in WAVE/AIFF file"; - return false; - } - for(; i < fm->num_blocks; i++) { - if(fseeko(fin, fm->blocks[i].offset, SEEK_SET) < 0) { - if(error) *error = "seek failed in FLAC file"; - return false; - } - if(!compare_data_(fin, fout, fm->blocks[i].size, error, "read failed in FLAC file", "read failed in WAVE/AIFF file", "restore of foreign metadata failed")) - return false; - } - return true; -} - -foreign_metadata_t *flac__foreign_metadata_new(foreign_block_type_t type) -{ - /* calloc() to zero all the member variables */ - foreign_metadata_t *x = calloc(sizeof(foreign_metadata_t), 1); - if(x) { - x->type = type; - x->is_rf64 = false; - } - return x; -} - -void flac__foreign_metadata_delete(foreign_metadata_t *fm) -{ - if(fm) { - if(fm->blocks) - free(fm->blocks); - free(fm); - } -} - -FLAC__bool flac__foreign_metadata_read_from_aiff(foreign_metadata_t *fm, const char *filename, const char **error) -{ - FLAC__bool ok; - FILE *f = flac_fopen(filename, "rb"); - if(!f) { - if(error) *error = "can't open AIFF file for reading (000)"; - return false; - } - ok = read_from_aiff_(fm, f, error); - fclose(f); - return ok; -} - -FLAC__bool flac__foreign_metadata_read_from_wave(foreign_metadata_t *fm, const char *filename, const char **error) -{ - FLAC__bool ok; - FILE *f = flac_fopen(filename, "rb"); - if(!f) { - if(error) *error = "can't open WAVE file for reading (000)"; - return false; - } - ok = read_from_wave_(fm, f, error); - fclose(f); - return ok; -} - -FLAC__bool flac__foreign_metadata_read_from_wave64(foreign_metadata_t *fm, const char *filename, const char **error) -{ - FLAC__bool ok; - FILE *f = flac_fopen(filename, "rb"); - if(!f) { - if(error) *error = "can't open Wave64 file for reading (000)"; - return false; - } - ok = read_from_wave64_(fm, f, error); - fclose(f); - return ok; -} - -FLAC__bool flac__foreign_metadata_write_to_flac(foreign_metadata_t *fm, const char *infilename, const char *outfilename, const char **error) -{ - FLAC__bool ok; - FILE *fin, *fout; - FLAC__Metadata_SimpleIterator *it = FLAC__metadata_simple_iterator_new(); - if(!it) { - if(error) *error = "out of memory (000)"; - return false; - } - if(!FLAC__metadata_simple_iterator_init(it, outfilename, /*read_only=*/true, /*preserve_file_stats=*/false)) { - if(error) *error = "can't initialize iterator (001)"; - FLAC__metadata_simple_iterator_delete(it); - return false; - } - if(0 == (fin = flac_fopen(infilename, "rb"))) { - if(error) *error = "can't open WAVE/AIFF file for reading (002)"; - FLAC__metadata_simple_iterator_delete(it); - return false; - } - if(0 == (fout = flac_fopen(outfilename, "r+b"))) { - if(error) *error = "can't open FLAC file for updating (003)"; - FLAC__metadata_simple_iterator_delete(it); - fclose(fin); - return false; - } - ok = write_to_flac_(fm, fin, fout, it, error); - FLAC__metadata_simple_iterator_delete(it); - fclose(fin); - fclose(fout); - return ok; -} - -FLAC__bool flac__foreign_metadata_read_from_flac(foreign_metadata_t *fm, const char *filename, const char **error) -{ - FLAC__bool ok; - FILE *f; - FLAC__Metadata_SimpleIterator *it = FLAC__metadata_simple_iterator_new(); - if(!it) { - if(error) *error = "out of memory (000)"; - return false; - } - if(!FLAC__metadata_simple_iterator_init(it, filename, /*read_only=*/true, /*preserve_file_stats=*/false)) { - if(error) *error = "can't initialize iterator (001)"; - FLAC__metadata_simple_iterator_delete(it); - return false; - } - if(0 == (f = flac_fopen(filename, "rb"))) { - if(error) *error = "can't open FLAC file for reading (002)"; - FLAC__metadata_simple_iterator_delete(it); - return false; - } - ok = read_from_flac_(fm, f, it, error); - FLAC__metadata_simple_iterator_delete(it); - fclose(f); - return ok; -} - -FLAC__bool flac__foreign_metadata_write_to_iff(foreign_metadata_t *fm, const char *infilename, const char *outfilename, FLAC__off_t offset1, FLAC__off_t offset2, FLAC__off_t offset3, const char **error) -{ - FLAC__bool ok; - FILE *fin, *fout; - if(0 == (fin = flac_fopen(infilename, "rb"))) { - if(error) *error = "can't open FLAC file for reading (000)"; - return false; - } - if(0 == (fout = flac_fopen(outfilename, "r+b"))) { - if(error) *error = "can't open WAVE/AIFF file for updating (001)"; - fclose(fin); - return false; - } - ok = write_to_iff_(fm, fin, fout, offset1, offset2, offset3, error); - fclose(fin); - fclose(fout); - return ok; -} - -FLAC__bool flac__foreign_metadata_compare_with_iff(foreign_metadata_t *fm, const char *infilename, const char *outfilename, FLAC__off_t offset3, const char **error) -{ - FLAC__bool ok; - FILE *fin, *fout; - if(0 == (fin = flac_fopen(infilename, "rb"))) { - if(error) *error = "can't open FLAC file for reading"; - return false; - } - if(0 == (fout = flac_fopen(outfilename, "rb"))) { - if(error) *error = "can't open WAVE/AIFF file for comparing"; - fclose(fin); - return false; - } - ok = compare_with_iff_(fm, fin, fout, offset3, error); - fclose(fin); - fclose(fout); - return ok; -} diff --git a/flac/src/flac/foreign_metadata.h b/flac/src/flac/foreign_metadata.h deleted file mode 100644 index fa68d46..0000000 --- a/flac/src/flac/foreign_metadata.h +++ /dev/null @@ -1,83 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 flac__foreign_metadata_h -#define flac__foreign_metadata_h - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "FLAC/metadata.h" -#include "utils.h" -#include "share/compat.h" - -#define FLAC__FOREIGN_METADATA_NUMBER_OF_RECOGNIZED_APPLICATION_IDS 3 - -extern const char *FLAC__FOREIGN_METADATA_APPLICATION_ID[FLAC__FOREIGN_METADATA_NUMBER_OF_RECOGNIZED_APPLICATION_IDS]; - -/* WATCHOUT: these enums are used to index internal arrays */ -typedef enum { - FOREIGN_BLOCK_TYPE__AIFF = 0, /* for AIFF and AIFF-C */ - FOREIGN_BLOCK_TYPE__RIFF = 1, /* for WAVE and RF64 */ - FOREIGN_BLOCK_TYPE__WAVE64 = 2 /* only for Sony's flavor */ -} foreign_block_type_t; - -typedef struct { - /* for encoding, this will be the offset in the WAVE/AIFF file of the chunk */ - /* for decoding, this will be the offset in the FLAC file of the chunk data inside the APPLICATION block */ - FLAC__off_t offset; - /* size is the actual size in bytes of the chunk to be stored/recreated. */ - /* It includes the 8 bytes of chunk type and size, and any padding byte for alignment. */ - /* For 'data'/'SSND' chunks, the size does not include the actual sound or padding bytes */ - /* because these are not stored, they are recreated from the compressed FLAC stream. */ - /* So for RIFF 'data', size is 8, and for AIFF 'SSND', size is 8 + 8 + ssnd_offset_size */ - /* 32 bit size is OK because we only care about the non-sound data and FLAC metadata */ - /* only supports a few megs anyway. */ - FLAC__uint32 size; -} foreign_block_t; - -typedef struct { - foreign_block_type_t type; /* currently we don't support multiple foreign types in a stream (and maybe never will) */ - foreign_block_t *blocks; - size_t num_blocks; - size_t format_block; /* block number of 'fmt ' or 'COMM' chunk */ - size_t audio_block; /* block number of 'data' or 'SSND' chunk */ - FLAC__bool is_rf64; /* always false if type!=RIFF */ - FLAC__bool is_wavefmtex; /* always false if type!=RIFF */ - FLAC__bool is_aifc; /* always false if type!=AIFF */ - FLAC__bool is_sowt; /* always false if type!=AIFF */ - FLAC__uint32 aifc_comm_length; - FLAC__uint32 ssnd_offset_size; /* 0 if type!=AIFF */ -} foreign_metadata_t; - -foreign_metadata_t *flac__foreign_metadata_new(foreign_block_type_t type); - -void flac__foreign_metadata_delete(foreign_metadata_t *fm); - -FLAC__bool flac__foreign_metadata_read_from_aiff(foreign_metadata_t *fm, const char *filename, const char **error); -FLAC__bool flac__foreign_metadata_read_from_wave(foreign_metadata_t *fm, const char *filename, const char **error); -FLAC__bool flac__foreign_metadata_read_from_wave64(foreign_metadata_t *fm, const char *filename, const char **error); -FLAC__bool flac__foreign_metadata_write_to_flac(foreign_metadata_t *fm, const char *infilename, const char *outfilename, const char **error); - -FLAC__bool flac__foreign_metadata_read_from_flac(foreign_metadata_t *fm, const char *filename, const char **error); -FLAC__bool flac__foreign_metadata_write_to_iff(foreign_metadata_t *fm, const char *infilename, const char *outfilename, FLAC__off_t offset1, FLAC__off_t offset2, FLAC__off_t offset3, const char **error); -FLAC__bool flac__foreign_metadata_compare_with_iff(foreign_metadata_t *fm, const char *infilename, const char *outfilename, FLAC__off_t offset3, const char **error); - -#endif diff --git a/flac/src/flac/iffscan.c b/flac/src/flac/iffscan.c deleted file mode 100644 index a5472e0..0000000 --- a/flac/src/flac/iffscan.c +++ /dev/null @@ -1,129 +0,0 @@ -/* iffscan - Simple AIFF/RIFF chunk scanner - * Copyright (C) 2007-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include "share/compat.h" -#include "foreign_metadata.h" - -static FLAC__uint32 unpack32be_(const FLAC__byte *b) -{ - return ((FLAC__uint32)b[0]<<24) + ((FLAC__uint32)b[1]<<16) + ((FLAC__uint32)b[2]<<8) + (FLAC__uint32)b[3]; -} - -static FLAC__uint32 unpack32le_(const FLAC__byte *b) -{ - return (FLAC__uint32)b[0] + ((FLAC__uint32)b[1]<<8) + ((FLAC__uint32)b[2]<<16) + ((FLAC__uint32)b[3]<<24); -} - -static FLAC__uint64 unpack64le_(const FLAC__byte *b) -{ - return (FLAC__uint64)b[0] + ((FLAC__uint64)b[1]<<8) + ((FLAC__uint64)b[2]<<16) + ((FLAC__uint64)b[3]<<24) + ((FLAC__uint64)b[4]<<32) + ((FLAC__uint64)b[5]<<40) + ((FLAC__uint64)b[6]<<48) + ((FLAC__uint64)b[7]<<56); -} - -static FLAC__uint32 unpack32_(const FLAC__byte *b, foreign_block_type_t type) -{ - if(type == FOREIGN_BLOCK_TYPE__AIFF) - return unpack32be_(b); - else - return unpack32le_(b); -} - -int main(int argc, char *argv[]) -{ - FILE *f; - char buf[36]; - foreign_metadata_t *fm; - const char *fn, *error; - size_t i; - FLAC__uint32 size; - -#ifdef _WIN32 - if (get_utf8_argv(&argc, &argv) != 0) { - fprintf(stderr, "ERROR: failed to convert command line parameters to UTF-8\n"); - return 1; - } -#endif - - if(argc != 2) { - flac_fprintf(stderr, "usage: %s { file.wav | file.aif }\n", argv[0]); - return 1; - } - fn = argv[1]; - if(0 == (f = flac_fopen(fn, "rb")) || fread(buf, 1, 4, f) != 4) { - flac_fprintf(stderr, "ERROR opening %s for reading\n", fn); - return 1; - } - fclose(f); - if(0 == (fm = flac__foreign_metadata_new(memcmp(buf, "RIFF", 4) && memcmp(buf, "RF64", 4)? FOREIGN_BLOCK_TYPE__AIFF : FOREIGN_BLOCK_TYPE__RIFF))) { - flac_fprintf(stderr, "ERROR: out of memory\n"); - return 1; - } - if(fm->type == FOREIGN_BLOCK_TYPE__AIFF) { - if(!flac__foreign_metadata_read_from_aiff(fm, fn, &error)) { - flac_fprintf(stderr, "ERROR reading chunks from %s: %s\n", fn, error); - return 1; - } - } - else { - if(!flac__foreign_metadata_read_from_wave(fm, fn, &error)) { - flac_fprintf(stderr, "ERROR reading chunks from %s: %s\n", fn, error); - return 1; - } - } - if(0 == (f = flac_fopen(fn, "rb"))) { - flac_fprintf(stderr, "ERROR opening %s for reading\n", fn); - return 1; - } - for(i = 0; i < fm->num_blocks; i++) { - if(fseeko(f, fm->blocks[i].offset, SEEK_SET) < 0) { - flac_fprintf(stderr, "ERROR seeking in %s\n", fn); - return 1; - } - if(fread(buf, 1, i==0?12:8, f) != (i==0?12:8)) { - flac_fprintf(stderr, "ERROR reading %s\n", fn); - return 1; - } - size = unpack32_((FLAC__byte*)buf+4, fm->type); - printf("block:[%c%c%c%c] size=%08x=(%10u)", buf[0], buf[1], buf[2], buf[3], size, size); - if(i == 0) - printf(" type:[%c%c%c%c]", buf[8], buf[9], buf[10], buf[11]); - else if(fm->type == FOREIGN_BLOCK_TYPE__AIFF && i == fm->audio_block) - printf(" offset size=%08x=(%10u)", fm->ssnd_offset_size, fm->ssnd_offset_size); - else if(fm->type == FOREIGN_BLOCK_TYPE__RIFF && i == 1 && !memcmp(buf, "ds64", 4)) { - if(fread(buf+8, 1, 36-8, f) != 36-8) { - flac_fprintf(stderr, "ERROR reading %s\n", fn); - return 1; - } - printf("\n RIFF size=%016" PRIx64 "=(%20" PRIu64 ")", unpack64le_((FLAC__byte*)buf+8), unpack64le_((FLAC__byte*)buf+8)); - printf("\n data size=%016" PRIx64 "=(%20" PRIu64 ")", unpack64le_((FLAC__byte*)buf+16), unpack64le_((FLAC__byte*)buf+16)); - printf("\n sample count=%016" PRIx64 "=(%20" PRIu64 ")", unpack64le_((FLAC__byte*)buf+24), unpack64le_((FLAC__byte*)buf+24)); - printf("\n table size=%08x=(%10u)", unpack32le_((FLAC__byte*)buf+32), unpack32le_((FLAC__byte*)buf+32)); - } - printf("\n"); - } - fclose(f); - flac__foreign_metadata_delete(fm); - return 0; -} diff --git a/flac/src/flac/local_string_utils.c b/flac/src/flac/local_string_utils.c deleted file mode 100644 index 7e25233..0000000 --- a/flac/src/flac/local_string_utils.c +++ /dev/null @@ -1,109 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "utils.h" -#include "local_string_utils.h" - -/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ - * - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -size_t -flac__strlcpy(char *dst, const char *src, size_t siz) -{ - register char *d = dst; - register const char *s = src; - register size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) - break; - } while (--n != 0); - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} - -/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ - * - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. - */ -size_t -flac__strlcat(char *dst, const char *src, size_t siz) -{ - register char *d = dst; - register const char *s = src; - register size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} diff --git a/flac/src/flac/local_string_utils.h b/flac/src/flac/local_string_utils.h deleted file mode 100644 index 01f891f..0000000 --- a/flac/src/flac/local_string_utils.h +++ /dev/null @@ -1,28 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 flac__local_string_utils_h -#define flac__local_string_utils_h - -#include /* for size_t */ - -size_t flac__strlcpy(char *dst, const char *src, size_t siz); -size_t flac__strlcat(char *dst, const char *src, size_t siz); - -#endif diff --git a/flac/src/flac/main.c b/flac/src/flac/main.c deleted file mode 100644 index c22e602..0000000 --- a/flac/src/flac/main.c +++ /dev/null @@ -1,2442 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#if !defined _MSC_VER && !defined __MINGW32__ -/* unlink is in stdio.h in VC++ */ -#include /* for unlink() */ -#endif -#include "FLAC/all.h" -#include "share/alloc.h" -#include "share/grabbag.h" -#include "share/compat.h" -#include "share/endswap.h" -#include "share/safe_str.h" -#include "analyze.h" -#include "decode.h" -#include "encode.h" -#include "local_string_utils.h" /* for flac__strlcat() and flac__strlcpy() */ -#include "utils.h" -#include "vorbiscomment.h" - -#if 0 -/*[JEC] was:#if HAVE_GETOPT_LONG*/ -/*[JEC] see flac/include/share/getopt.h as to why the change */ -# include -#else -# include "share/getopt.h" -#endif - -static int do_it(void); - -static FLAC__bool init_options(void); -static int parse_options(int argc, char *argv[]); -static int parse_option(int short_option, const char *long_option, const char *option_argument); -static void free_options(void); -static void add_compression_setting_bool(compression_setting_type_t type, FLAC__bool value); -static void add_compression_setting_string(compression_setting_type_t type, const char *value); -static void add_compression_setting_uint32_t(compression_setting_type_t type, uint32_t value); - -static int usage_error(const char *message, ...); -static void short_usage(void); -static void show_version(void); -static void show_help(void); -static void show_explain(void); -static void format_mistake(const char *infilename, FileFormat wrong, FileFormat right); - -static int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_last_file); -static int decode_file(const char *infilename); - -static const char *get_encoded_outfilename(const char *infilename); -static const char *get_decoded_outfilename(const char *infilename, const FileFormat format); -static const char *get_outfilename(const char *infilename, const char *suffix); - -static void die(const char *message); -static int conditional_fclose(FILE *f); -static char *local_strdup(const char *source); - -/* - * share__getopt format struct; note that for long options with no - * short option equivalent we just set the 'val' field to 0. - */ -static struct share__option long_options_[] = { - /* - * general options - */ - { "help" , share__no_argument, 0, 'h' }, - { "explain" , share__no_argument, 0, 'H' }, - { "version" , share__no_argument, 0, 'v' }, - { "decode" , share__no_argument, 0, 'd' }, - { "analyze" , share__no_argument, 0, 'a' }, - { "test" , share__no_argument, 0, 't' }, - { "stdout" , share__no_argument, 0, 'c' }, - { "silent" , share__no_argument, 0, 's' }, - { "totally-silent" , share__no_argument, 0, 0 }, - { "warnings-as-errors" , share__no_argument, 0, 'w' }, - { "force" , share__no_argument, 0, 'f' }, - { "delete-input-file" , share__no_argument, 0, 0 }, - { "preserve-modtime" , share__no_argument, 0, 0 }, - { "keep-foreign-metadata" , share__no_argument, 0, 0 }, - { "keep-foreign-metadata-if-present" , share__no_argument, 0, 0 }, - { "output-prefix" , share__required_argument, 0, 0 }, - { "output-name" , share__required_argument, 0, 'o' }, - { "skip" , share__required_argument, 0, 0 }, - { "until" , share__required_argument, 0, 0 }, - { "channel-map" , share__required_argument, 0, 0 }, /* undocumented */ - - /* - * decoding options - */ - { "decode-through-errors", share__no_argument, 0, 'F' }, - { "cue" , share__required_argument, 0, 0 }, - { "apply-replaygain-which-is-not-lossless", share__optional_argument, 0, 0 }, /* undocumented */ - - /* - * encoding options - */ - { "cuesheet" , share__required_argument, 0, 0 }, - { "no-cued-seekpoints" , share__no_argument, 0, 0 }, - { "picture" , share__required_argument, 0, 0 }, - { "tag" , share__required_argument, 0, 'T' }, - { "tag-from-file" , share__required_argument, 0, 0 }, - { "compression-level-0" , share__no_argument, 0, '0' }, - { "compression-level-1" , share__no_argument, 0, '1' }, - { "compression-level-2" , share__no_argument, 0, '2' }, - { "compression-level-3" , share__no_argument, 0, '3' }, - { "compression-level-4" , share__no_argument, 0, '4' }, - { "compression-level-5" , share__no_argument, 0, '5' }, - { "compression-level-6" , share__no_argument, 0, '6' }, - { "compression-level-7" , share__no_argument, 0, '7' }, - { "compression-level-8" , share__no_argument, 0, '8' }, - { "compression-level-9" , share__no_argument, 0, '9' }, - { "best" , share__no_argument, 0, '8' }, - { "fast" , share__no_argument, 0, '0' }, - { "verify" , share__no_argument, 0, 'V' }, - { "force-raw-format" , share__no_argument, 0, 0 }, - { "force-aiff-format" , share__no_argument, 0, 0 }, - { "force-rf64-format" , share__no_argument, 0, 0 }, - { "force-wave64-format" , share__no_argument, 0, 0 }, - { "force-legacy-wave-format" , share__no_argument, 0, 0 }, - { "force-extensible-wave-format",share__no_argument,0, 0 }, - { "force-aiff-c-none-format" , share__no_argument, 0, 0 }, - { "force-aiff-c-sowt-format" , share__no_argument, 0, 0 }, - { "lax" , share__no_argument, 0, 0 }, - { "replay-gain" , share__no_argument, 0, 0 }, - { "ignore-chunk-sizes" , share__no_argument, 0, 0 }, - { "seekpoint" , share__required_argument, 0, 'S' }, - { "padding" , share__required_argument, 0, 'P' }, -#if FLAC__HAS_OGG - { "ogg" , share__no_argument, 0, 0 }, - { "serial-number" , share__required_argument, 0, 0 }, -#endif - { "blocksize" , share__required_argument, 0, 'b' }, - { "exhaustive-model-search" , share__no_argument, 0, 'e' }, - { "max-lpc-order" , share__required_argument, 0, 'l' }, - { "apodization" , share__required_argument, 0, 'A' }, - { "mid-side" , share__no_argument, 0, 'm' }, - { "adaptive-mid-side" , share__no_argument, 0, 'M' }, - { "qlp-coeff-precision-search", share__no_argument, 0, 'p' }, - { "qlp-coeff-precision" , share__required_argument, 0, 'q' }, - { "rice-partition-order" , share__required_argument, 0, 'r' }, - { "endian" , share__required_argument, 0, 0 }, - { "channels" , share__required_argument, 0, 0 }, - { "bps" , share__required_argument, 0, 0 }, - { "sample-rate" , share__required_argument, 0, 0 }, - { "sign" , share__required_argument, 0, 0 }, - { "input-size" , share__required_argument, 0, 0 }, - { "error-on-compression-fail" , share__no_argument, 0, 0 }, - { "limit-min-bitrate" , share__no_argument, 0, 0 }, - - /* - * analysis options - */ - { "residual-gnuplot", share__no_argument, 0, 0 }, - { "residual-text", share__no_argument, 0, 0 }, - - /* - * negatives - */ - { "no-preserve-modtime" , share__no_argument, 0, 0 }, - { "no-decode-through-errors" , share__no_argument, 0, 0 }, - { "no-silent" , share__no_argument, 0, 0 }, - { "no-force" , share__no_argument, 0, 0 }, - { "no-seektable" , share__no_argument, 0, 0 }, - { "no-delete-input-file" , share__no_argument, 0, 0 }, - { "no-keep-foreign-metadata" , share__no_argument, 0, 0 }, - { "no-replay-gain" , share__no_argument, 0, 0 }, - { "no-ignore-chunk-sizes" , share__no_argument, 0, 0 }, - { "no-utf8-convert" , share__no_argument, 0, 0 }, - { "no-lax" , share__no_argument, 0, 0 }, -#if FLAC__HAS_OGG - { "no-ogg" , share__no_argument, 0, 0 }, -#endif - { "no-exhaustive-model-search", share__no_argument, 0, 0 }, - { "no-mid-side" , share__no_argument, 0, 0 }, - { "no-adaptive-mid-side" , share__no_argument, 0, 0 }, - { "no-qlp-coeff-prec-search" , share__no_argument, 0, 0 }, - { "no-padding" , share__no_argument, 0, 0 }, - { "no-verify" , share__no_argument, 0, 0 }, - { "no-warnings-as-errors" , share__no_argument, 0, 0 }, - { "no-residual-gnuplot" , share__no_argument, 0, 0 }, - { "no-residual-text" , share__no_argument, 0, 0 }, - { "no-error-on-compression-fail", share__no_argument, 0, 0 }, - /* - * undocumented debugging options for the test suite - */ - { "disable-constant-subframes", share__no_argument, 0, 0 }, - { "disable-fixed-subframes" , share__no_argument, 0, 0 }, - { "disable-verbatim-subframes", share__no_argument, 0, 0 }, - { "no-md5-sum" , share__no_argument, 0, 0 }, - - {0, 0, 0, 0} -}; - - -/* - * global to hold command-line option values - */ - -static struct { - FLAC__bool show_help; - FLAC__bool show_explain; - FLAC__bool show_version; - FLAC__bool mode_decode; - FLAC__bool verify; - FLAC__bool treat_warnings_as_errors; - FLAC__bool force_file_overwrite; - FLAC__bool continue_through_decode_errors; - replaygain_synthesis_spec_t replaygain_synthesis_spec; - FLAC__bool lax; - FLAC__bool test_only; - FLAC__bool analyze; - FLAC__bool use_ogg; - FLAC__bool has_serial_number; /* true iff --serial-number was used */ - long serial_number; /* this is the Ogg serial number and is unused for native FLAC */ - FLAC__bool force_to_stdout; - FLAC__bool force_raw_format; - FLAC__bool force_aiff_format; - FLAC__bool force_rf64_format; - FLAC__bool force_wave64_format; - FLAC__bool force_legacy_wave_format; - FLAC__bool force_extensible_wave_format; - FLAC__bool force_aiff_c_none_format; - FLAC__bool force_aiff_c_sowt_format; - FLAC__bool delete_input; - FLAC__bool preserve_modtime; - FLAC__bool keep_foreign_metadata; - FLAC__bool keep_foreign_metadata_if_present; - FLAC__bool replay_gain; - FLAC__bool ignore_chunk_sizes; - FLAC__bool utf8_convert; /* true by default, to convert tag strings from locale to utf-8, false if --no-utf8-convert used */ - const char *cmdline_forced_outfilename; - const char *output_prefix; - analysis_options aopts; - int padding; /* -1 => no -P options were given, 0 => -P- was given, else -P value */ - size_t num_compression_settings; - compression_setting_t compression_settings[64]; /* bad MAGIC NUMBER but buffer overflow is checked */ - const char *skip_specification; - const char *until_specification; - const char *cue_specification; - int format_is_big_endian; - int format_is_unsigned_samples; - int format_channels; - int format_bps; - int format_sample_rate; - FLAC__off_t format_input_size; - char requested_seek_points[5000]; /* bad MAGIC NUMBER but buffer overflow is checked */ - int num_requested_seek_points; /* -1 => no -S options were given, 0 => -S- was given */ - const char *cuesheet_filename; - FLAC__bool cued_seekpoints; - FLAC__bool channel_map_none; /* --channel-map=none specified, eventually will expand to take actual channel map */ - FLAC__bool error_on_compression_fail; - FLAC__bool limit_min_bitrate; - - uint32_t num_files; - char **filenames; - - FLAC__StreamMetadata *vorbis_comment; - FLAC__StreamMetadata *pictures[64]; - uint32_t num_pictures; - - struct { - FLAC__bool disable_constant_subframes; - FLAC__bool disable_fixed_subframes; - FLAC__bool disable_verbatim_subframes; - FLAC__bool do_md5; - } debug; -} option_values; - - -/* - * miscellaneous globals - */ - - -#ifndef FUZZ_TOOL_FLAC -int main(int argc, char *argv[]) -#else -static int main_to_fuzz(int argc, char *argv[]) -#endif -{ - int retval = 0; - -#ifdef __EMX__ - _response(&argc, &argv); - _wildcard(&argc, &argv); -#endif -#ifdef _WIN32 - if (get_utf8_argv(&argc, &argv) != 0) { - fprintf(stderr, "ERROR: failed to convert command line parameters to UTF-8\n"); - return 1; - } -#endif - - srand((uint32_t)time(0)); -#ifdef _WIN32 - { - const char *var; - var = getenv("LC_ALL"); - if (!var) - var = getenv("LC_NUMERIC"); - if (!var) - var = getenv("LANG"); - if (!var || strcmp(var, "C") != 0) - setlocale(LC_ALL, ""); - } -#else - setlocale(LC_ALL, ""); -#endif - if(!init_options()) { - flac__utils_printf(stderr, 1, "ERROR: allocating memory\n"); - retval = 1; - } - else { - if((retval = parse_options(argc, argv)) == 0) - retval = do_it(); - } - - free_options(); - - return retval; -} - -int do_it(void) -{ - int retval = 0; - - if(option_values.show_version) { - show_version(); - return 0; - } - else if(option_values.show_explain) { - show_explain(); - return 0; - } - else if(option_values.show_help) { - show_help(); - return 0; - } - else { - if(option_values.num_files == 0) { - if(flac__utils_verbosity_ >= 1) - short_usage(); - return 0; - } - - /* - * tweak options; validate the values - */ - if(!option_values.mode_decode) { - if(0 != option_values.cue_specification) - return usage_error("ERROR: --cue is not allowed in test mode\n"); - } - else { - if(option_values.test_only) { - if(0 != option_values.skip_specification) - return usage_error("ERROR: --skip is not allowed in test mode\n"); - if(0 != option_values.until_specification) - return usage_error("ERROR: --until is not allowed in test mode\n"); - if(0 != option_values.cue_specification) - return usage_error("ERROR: --cue is not allowed in test mode\n"); - if(0 != option_values.analyze) - return usage_error("ERROR: analysis mode (-a/--analyze) and test mode (-t/--test) cannot be used together\n"); - } - } - - if(0 != option_values.cue_specification && (0 != option_values.skip_specification || 0 != option_values.until_specification)) - return usage_error("ERROR: --cue may not be combined with --skip or --until\n"); - - if(option_values.format_channels >= 0) { - if(option_values.format_channels == 0 || (uint32_t)option_values.format_channels > FLAC__MAX_CHANNELS) - return usage_error("ERROR: invalid number of channels '%u', must be > 0 and <= %u\n", option_values.format_channels, FLAC__MAX_CHANNELS); - } - if(option_values.format_bps >= 0) { - if(option_values.format_bps != 8 && option_values.format_bps != 16 && option_values.format_bps != 24 && option_values.format_bps != 32) - return usage_error("ERROR: invalid bits per sample '%u' (must be 8/16/24/32)\n", option_values.format_bps); - } - if(option_values.format_sample_rate >= 0) { - if(!FLAC__format_sample_rate_is_valid(option_values.format_sample_rate)) - return usage_error("ERROR: invalid sample rate '%u', must be > 0 and <= %u\n", option_values.format_sample_rate, FLAC__MAX_SAMPLE_RATE); - } - if((option_values.force_raw_format?1:0) + - (option_values.force_aiff_format?1:0) + - (option_values.force_rf64_format?1:0) + - (option_values.force_wave64_format?1:0) + - (option_values.force_legacy_wave_format?1:0) + - (option_values.force_extensible_wave_format?1:0) + - (option_values.force_aiff_c_none_format?1:0) + - (option_values.force_aiff_c_sowt_format?1:0) - > 1) - return usage_error("ERROR: only one of force format options allowed\n"); - if(option_values.mode_decode) { - if(!option_values.force_raw_format) { - if(option_values.format_is_big_endian >= 0) - return usage_error("ERROR: --endian only allowed with --force-raw-format\n"); - if(option_values.format_is_unsigned_samples >= 0) - return usage_error("ERROR: --sign only allowed with --force-raw-format\n"); - } - if(option_values.format_channels >= 0) - return usage_error("ERROR: --channels not allowed with --decode\n"); - if(option_values.format_bps >= 0) - return usage_error("ERROR: --bps not allowed with --decode\n"); - if(option_values.format_sample_rate >= 0) - return usage_error("ERROR: --sample-rate not allowed with --decode\n"); - } - - if(option_values.ignore_chunk_sizes) { - if(option_values.mode_decode) - return usage_error("ERROR: --ignore-chunk-sizes only allowed for encoding\n"); - if(0 != option_values.until_specification) - return usage_error("ERROR: --ignore-chunk-sizes not allowed with --until\n"); - if(0 != option_values.cue_specification) - return usage_error("ERROR: --ignore-chunk-sizes not allowed with --cue\n"); - if(0 != option_values.cuesheet_filename) - return usage_error("ERROR: --ignore-chunk-sizes not allowed with --cuesheet\n"); - } - if(option_values.replay_gain) { - if(option_values.force_to_stdout) - return usage_error("ERROR: --replay-gain not allowed with -c/--stdout\n"); - if(option_values.mode_decode) - return usage_error("ERROR: --replay-gain only allowed for encoding\n"); - if(option_values.format_channels > 2) - return usage_error("ERROR: --replay-gain can only be done with mono/stereo input\n"); - if(option_values.format_sample_rate >= 0 && !grabbag__replaygain_is_valid_sample_frequency(option_values.format_sample_rate)) - return usage_error("ERROR: invalid sample rate used with --replay-gain\n"); - if( - (option_values.padding >= 0 && option_values.padding < (int)GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED) || - (option_values.padding < 0 && FLAC_ENCODE__DEFAULT_PADDING < (int)GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED) - ) { - flac__utils_printf(stderr, 1, "NOTE: --replay-gain may leave a small PADDING block even with --no-padding\n"); - } - } - if(option_values.num_files > 1 && option_values.cmdline_forced_outfilename) { - return usage_error("ERROR: -o/--output-name cannot be used with multiple files\n"); - } - if(option_values.cmdline_forced_outfilename && option_values.output_prefix) { - return usage_error("ERROR: --output-prefix conflicts with -o/--output-name\n"); - } - if(!option_values.mode_decode && 0 != option_values.cuesheet_filename && option_values.num_files > 1) { - return usage_error("ERROR: --cuesheet cannot be used when encoding multiple files\n"); - } - if(option_values.keep_foreign_metadata || option_values.keep_foreign_metadata_if_present) { - /* we're not going to try and support the re-creation of broken WAVE files */ - if(option_values.ignore_chunk_sizes) - return usage_error("ERROR: using --keep-foreign-metadata cannot be used with --ignore-chunk-sizes\n"); - if(option_values.test_only) - return usage_error("ERROR: --keep-foreign-metadata is not allowed in test mode\n"); - if(option_values.analyze) - return usage_error("ERROR: --keep-foreign-metadata is not allowed in analyis mode\n"); - flac__utils_printf(stderr, 1, "NOTE: --keep-foreign-metadata is a new feature; make sure to test the output file before deleting the original.\n"); - } - } - - flac__utils_printf(stderr, 2, "\n"); - flac__utils_printf(stderr, 2, "flac %s\n", FLAC__VERSION_STRING); - flac__utils_printf(stderr, 2, "Copyright (C) 2000-2009 Josh Coalson, 2011-2023 Xiph.Org Foundation\n"); - flac__utils_printf(stderr, 2, "flac comes with ABSOLUTELY NO WARRANTY. This is free software, and you are\n"); - flac__utils_printf(stderr, 2, "welcome to redistribute it under certain conditions. Type `flac' for details.\n\n"); - - if(option_values.mode_decode) { - FLAC__bool first = true; - - if(option_values.num_files == 0) { - retval = decode_file("-"); - } - else { - uint32_t i; - if(option_values.num_files > 1) - option_values.cmdline_forced_outfilename = 0; - for(i = 0, retval = 0; i < option_values.num_files; i++) { - if(0 == strcmp(option_values.filenames[i], "-") && !first) - continue; - retval |= decode_file(option_values.filenames[i]); - first = false; - } - } - } - else { /* encode */ - FLAC__bool first = true; - - if(option_values.ignore_chunk_sizes) - flac__utils_printf(stderr, 1, "INFO: Make sure you know what you're doing when using --ignore-chunk-sizes.\n Improper use can cause flac to encode non-audio data as audio.\n"); - - if(option_values.num_files == 0) { - retval = encode_file("-", first, true); - } - else { - uint32_t i; - if(option_values.num_files > 1) - option_values.cmdline_forced_outfilename = 0; - for(i = 0, retval = 0; i < option_values.num_files; i++) { - if(0 == strcmp(option_values.filenames[i], "-") && !first) - continue; - if(encode_file(option_values.filenames[i], first, i == (option_values.num_files-1))) - retval = 1; - else - first = false; - } - if(option_values.replay_gain && retval == 0) { - float album_gain, album_peak; - grabbag__replaygain_get_album(&album_gain, &album_peak); - for(i = 0; i < option_values.num_files; i++) { - const char *error, *outfilename = get_encoded_outfilename(option_values.filenames[i]); - if(0 == outfilename) { - flac__utils_printf(stderr, 1, "ERROR: filename too long: %s", option_values.filenames[i]); - return 1; - } - if(0 != (error = grabbag__replaygain_store_to_file_album(outfilename, album_gain, album_peak, option_values.preserve_modtime))) { - flac__utils_printf(stderr, 1, "%s: ERROR writing ReplayGain album tags (%s)\n", outfilename, error); - retval = 1; - } - } - } - } - } - - return retval; -} - -FLAC__bool init_options(void) -{ - option_values.show_help = false; - option_values.show_explain = false; - option_values.show_version = false; - option_values.mode_decode = false; - option_values.verify = false; - option_values.treat_warnings_as_errors = false; - option_values.force_file_overwrite = false; - option_values.continue_through_decode_errors = false; - option_values.replaygain_synthesis_spec.apply = false; - option_values.replaygain_synthesis_spec.use_album_gain = true; - option_values.replaygain_synthesis_spec.limiter = RGSS_LIMIT__HARD; - option_values.replaygain_synthesis_spec.noise_shaping = NOISE_SHAPING_LOW; - option_values.replaygain_synthesis_spec.preamp = 0.0; - option_values.lax = false; - option_values.test_only = false; - option_values.analyze = false; - option_values.use_ogg = false; - option_values.has_serial_number = false; - option_values.serial_number = 0; - option_values.force_to_stdout = false; - option_values.force_raw_format = false; - option_values.force_aiff_format = false; - option_values.force_rf64_format = false; - option_values.force_wave64_format = false; - option_values.force_legacy_wave_format = false; - option_values.force_extensible_wave_format = false; - option_values.force_aiff_c_none_format = false; - option_values.force_aiff_c_sowt_format = false; - option_values.delete_input = false; - option_values.preserve_modtime = true; - option_values.keep_foreign_metadata = false; - option_values.keep_foreign_metadata_if_present = false; - option_values.replay_gain = false; - option_values.ignore_chunk_sizes = false; - option_values.utf8_convert = true; - option_values.cmdline_forced_outfilename = 0; - option_values.output_prefix = 0; - option_values.aopts.do_residual_text = false; - option_values.aopts.do_residual_gnuplot = false; - option_values.padding = -1; - option_values.num_compression_settings = 1; - option_values.compression_settings[0].type = CST_COMPRESSION_LEVEL; - option_values.compression_settings[0].value.t_unsigned = 5; - option_values.skip_specification = 0; - option_values.until_specification = 0; - option_values.cue_specification = 0; - option_values.format_is_big_endian = -1; - option_values.format_is_unsigned_samples = -1; - option_values.format_channels = -1; - option_values.format_bps = -1; - option_values.format_sample_rate = -1; - option_values.format_input_size = (FLAC__off_t)(-1); - option_values.requested_seek_points[0] = '\0'; - option_values.num_requested_seek_points = -1; - option_values.cuesheet_filename = 0; - option_values.cued_seekpoints = true; - option_values.channel_map_none = false; - option_values.error_on_compression_fail = false; - option_values.limit_min_bitrate = false; - - option_values.num_files = 0; - option_values.filenames = 0; - - if(0 == (option_values.vorbis_comment = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT))) - return false; - option_values.num_pictures = 0; - - option_values.debug.disable_constant_subframes = false; - option_values.debug.disable_fixed_subframes = false; - option_values.debug.disable_verbatim_subframes = false; - option_values.debug.do_md5 = true; - - return true; -} - -int parse_options(int argc, char *argv[]) -{ - int short_option; - int option_index = 1; - FLAC__bool had_error = false; - const char *short_opts = "0123456789aA:b:cdefFhHl:mMo:pP:q:r:sS:tT:vVw"; - - while ((short_option = share__getopt_long(argc, argv, short_opts, long_options_, &option_index)) != -1) { - switch (short_option) { - case 0: /* long option with no equivalent short option */ - had_error |= (parse_option(short_option, long_options_[option_index].name, share__optarg) != 0); - break; - case '?': - case ':': - had_error = true; - break; - default: /* short option */ - had_error |= (parse_option(short_option, 0, share__optarg) != 0); - break; - } - } - - if(had_error) { - return 1; - } - - FLAC__ASSERT(share__optind <= argc); - - option_values.num_files = argc - share__optind; - - if(option_values.num_files > 0) { - uint32_t i = 0; - if(0 == (option_values.filenames = malloc(sizeof(char*) * option_values.num_files))) - die("out of memory allocating space for file names list"); - while(share__optind < argc) - option_values.filenames[i++] = local_strdup(argv[share__optind++]); - } - - return 0; -} - -int parse_option(int short_option, const char *long_option, const char *option_argument) -{ - const char *violation; - - if(short_option == 0) { - FLAC__ASSERT(0 != long_option); - if(0 == strcmp(long_option, "totally-silent")) { - flac__utils_verbosity_ = 0; - } - else if(0 == strcmp(long_option, "delete-input-file")) { - option_values.delete_input = true; - } - else if(0 == strcmp(long_option, "preserve-modtime")) { - option_values.preserve_modtime = true; - } - else if(0 == strcmp(long_option, "keep-foreign-metadata")) { - option_values.keep_foreign_metadata = true; - } - else if(0 == strcmp(long_option, "keep-foreign-metadata-if-present")) { - option_values.keep_foreign_metadata_if_present = true; - } - else if(0 == strcmp(long_option, "output-prefix")) { - FLAC__ASSERT(0 != option_argument); - option_values.output_prefix = option_argument; - } - else if(0 == strcmp(long_option, "skip")) { - FLAC__ASSERT(0 != option_argument); - option_values.skip_specification = option_argument; - } - else if(0 == strcmp(long_option, "until")) { - FLAC__ASSERT(0 != option_argument); - option_values.until_specification = option_argument; - } - else if(0 == strcmp(long_option, "input-size")) { - FLAC__ASSERT(0 != option_argument); - { - char *end; - FLAC__int64 ix; - ix = strtoll(option_argument, &end, 10); - if(0 == strlen(option_argument) || *end) - return usage_error("ERROR: --%s must be a number\n", long_option); - option_values.format_input_size = (FLAC__off_t)ix; - if(option_values.format_input_size != ix) /* check if FLAC__off_t is smaller than long long */ - return usage_error("ERROR: --%s too large; this build of flac does not support filesizes over 2GB\n", long_option); - if(option_values.format_input_size <= 0) - return usage_error("ERROR: --%s must be > 0\n", long_option); - } - } - else if(0 == strcmp(long_option, "cue")) { - FLAC__ASSERT(0 != option_argument); - option_values.cue_specification = option_argument; - } - else if(0 == strcmp(long_option, "apply-replaygain-which-is-not-lossless")) { - option_values.replaygain_synthesis_spec.apply = true; - if (0 != option_argument) { - char *p; - option_values.replaygain_synthesis_spec.limiter = RGSS_LIMIT__NONE; - option_values.replaygain_synthesis_spec.noise_shaping = NOISE_SHAPING_NONE; - option_values.replaygain_synthesis_spec.preamp = strtod(option_argument, &p); - for ( ; *p; p++) { - if (*p == 'a') - option_values.replaygain_synthesis_spec.use_album_gain = true; - else if (*p == 't') - option_values.replaygain_synthesis_spec.use_album_gain = false; - else if (*p == 'l') - option_values.replaygain_synthesis_spec.limiter = RGSS_LIMIT__PEAK; - else if (*p == 'L') - option_values.replaygain_synthesis_spec.limiter = RGSS_LIMIT__HARD; - else if (*p == 'n' && p[1] >= '0' && p[1] <= '3') { - option_values.replaygain_synthesis_spec.noise_shaping = p[1] - '0'; - p++; - } - else - return usage_error("ERROR: bad specification string \"%s\" for --%s\n", option_argument, long_option); - } - } - } - else if(0 == strcmp(long_option, "channel-map")) { - if (0 == option_argument || strcmp(option_argument, "none")) - return usage_error("ERROR: only --channel-map=none currently supported\n"); - option_values.channel_map_none = true; - } - else if(0 == strcmp(long_option, "cuesheet")) { - FLAC__ASSERT(0 != option_argument); - option_values.cuesheet_filename = option_argument; - } - else if(0 == strcmp(long_option, "picture")) { - const uint32_t max_pictures = sizeof(option_values.pictures)/sizeof(option_values.pictures[0]); - FLAC__ASSERT(0 != option_argument); - if(option_values.num_pictures >= max_pictures) - return usage_error("ERROR: too many --picture arguments, only %u allowed\n", max_pictures); - if(0 == (option_values.pictures[option_values.num_pictures] = grabbag__picture_parse_specification(option_argument, &violation))) - return usage_error("ERROR: (--picture) %s\n", violation); - option_values.num_pictures++; - } - else if(0 == strcmp(long_option, "tag-from-file")) { - FLAC__ASSERT(0 != option_argument); - if(!flac__vorbiscomment_add(option_values.vorbis_comment, option_argument, /*value_from_file=*/true, /*raw=*/!option_values.utf8_convert, &violation)) - return usage_error("ERROR: (--tag-from-file) %s\n", violation); - } - else if(0 == strcmp(long_option, "no-cued-seekpoints")) { - option_values.cued_seekpoints = false; - } - else if(0 == strcmp(long_option, "force-raw-format")) { - option_values.force_raw_format = true; - } - else if(0 == strcmp(long_option, "force-aiff-format")) { - option_values.force_aiff_format = true; - } - else if(0 == strcmp(long_option, "force-rf64-format")) { - option_values.force_rf64_format = true; - } - else if(0 == strcmp(long_option, "force-wave64-format")) { - option_values.force_wave64_format = true; - } - else if(0 == strcmp(long_option, "force-legacy-wave-format")) { - option_values.force_legacy_wave_format = true; - } - else if(0 == strcmp(long_option, "force-extensible-wave-format")) { - option_values.force_extensible_wave_format = true; - } - else if(0 == strcmp(long_option, "force-aiff-c-none-format")) { - option_values.force_aiff_c_none_format = true; - } - else if(0 == strcmp(long_option, "force-aiff-c-sowt-format")) { - option_values.force_aiff_c_sowt_format = true; - } - else if(0 == strcmp(long_option, "lax")) { - option_values.lax = true; - } - else if(0 == strcmp(long_option, "replay-gain")) { - option_values.replay_gain = true; - } - else if(0 == strcmp(long_option, "ignore-chunk-sizes")) { - option_values.ignore_chunk_sizes = true; - } -#if FLAC__HAS_OGG - else if(0 == strcmp(long_option, "ogg")) { - option_values.use_ogg = true; - } - else if(0 == strcmp(long_option, "serial-number")) { - option_values.has_serial_number = true; - option_values.serial_number = atol(option_argument); - } -#endif - else if(0 == strcmp(long_option, "endian")) { - FLAC__ASSERT(0 != option_argument); - if(0 == strncmp(option_argument, "big", strlen(option_argument))) - option_values.format_is_big_endian = true; - else if(0 == strncmp(option_argument, "little", strlen(option_argument))) - option_values.format_is_big_endian = false; - else - return usage_error("ERROR: argument to --endian must be \"big\" or \"little\"\n"); - } - else if(0 == strcmp(long_option, "channels")) { - FLAC__ASSERT(0 != option_argument); - option_values.format_channels = atoi(option_argument); - } - else if(0 == strcmp(long_option, "bps")) { - FLAC__ASSERT(0 != option_argument); - option_values.format_bps = atoi(option_argument); - } - else if(0 == strcmp(long_option, "sample-rate")) { - FLAC__ASSERT(0 != option_argument); - option_values.format_sample_rate = atoi(option_argument); - } - else if(0 == strcmp(long_option, "sign")) { - FLAC__ASSERT(0 != option_argument); - if(0 == strncmp(option_argument, "signed", strlen(option_argument))) - option_values.format_is_unsigned_samples = false; - else if(0 == strncmp(option_argument, "unsigned", strlen(option_argument))) - option_values.format_is_unsigned_samples = true; - else - return usage_error("ERROR: argument to --sign must be \"signed\" or \"unsigned\"\n"); - } - else if(0 == strcmp(long_option, "residual-gnuplot")) { - option_values.aopts.do_residual_gnuplot = true; - } - else if(0 == strcmp(long_option, "residual-text")) { - option_values.aopts.do_residual_text = true; - } - else if(0 == strcmp(long_option, "limit-min-bitrate")) { - option_values.limit_min_bitrate = true; - } - /* - * negatives - */ - else if(0 == strcmp(long_option, "no-preserve-modtime")) { - option_values.preserve_modtime = false; - } - else if(0 == strcmp(long_option, "no-decode-through-errors")) { - option_values.continue_through_decode_errors = false; - } - else if(0 == strcmp(long_option, "no-silent")) { -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - flac__utils_verbosity_ = 2; -#endif - } - else if(0 == strcmp(long_option, "no-force")) { - option_values.force_file_overwrite = false; - } - else if(0 == strcmp(long_option, "no-seektable")) { - option_values.num_requested_seek_points = 0; - option_values.requested_seek_points[0] = '\0'; - } - else if(0 == strcmp(long_option, "no-delete-input-file")) { - option_values.delete_input = false; - } - else if(0 == strcmp(long_option, "no-keep-foreign-metadata")) { - option_values.keep_foreign_metadata = false; - option_values.keep_foreign_metadata_if_present = false; - } - else if(0 == strcmp(long_option, "no-replay-gain")) { - option_values.replay_gain = false; - } - else if(0 == strcmp(long_option, "no-ignore-chunk-sizes")) { - option_values.ignore_chunk_sizes = false; - } - else if(0 == strcmp(long_option, "no-utf8-convert")) { - option_values.utf8_convert = false; - } - else if(0 == strcmp(long_option, "no-lax")) { - option_values.lax = false; - } -#if FLAC__HAS_OGG - else if(0 == strcmp(long_option, "no-ogg")) { - option_values.use_ogg = false; - } -#endif - else if(0 == strcmp(long_option, "no-exhaustive-model-search")) { - add_compression_setting_bool(CST_DO_EXHAUSTIVE_MODEL_SEARCH, false); - } - else if(0 == strcmp(long_option, "no-mid-side")) { - add_compression_setting_bool(CST_DO_MID_SIDE, false); - add_compression_setting_bool(CST_LOOSE_MID_SIDE, false); - } - else if(0 == strcmp(long_option, "no-adaptive-mid-side")) { - add_compression_setting_bool(CST_DO_MID_SIDE, false); - add_compression_setting_bool(CST_LOOSE_MID_SIDE, false); - } - else if(0 == strcmp(long_option, "no-qlp-coeff-prec-search")) { - add_compression_setting_bool(CST_DO_QLP_COEFF_PREC_SEARCH, false); - } - else if(0 == strcmp(long_option, "no-padding")) { - option_values.padding = 0; - } - else if(0 == strcmp(long_option, "no-verify")) { - option_values.verify = false; - } - else if(0 == strcmp(long_option, "no-warnings-as-errors")) { - option_values.treat_warnings_as_errors = false; - } - else if(0 == strcmp(long_option, "no-residual-gnuplot")) { - option_values.aopts.do_residual_gnuplot = false; - } - else if(0 == strcmp(long_option, "no-residual-text")) { - option_values.aopts.do_residual_text = false; - } - else if(0 == strcmp(long_option, "disable-constant-subframes")) { - option_values.debug.disable_constant_subframes = true; - } - else if(0 == strcmp(long_option, "disable-fixed-subframes")) { - option_values.debug.disable_fixed_subframes = true; - } - else if(0 == strcmp(long_option, "disable-verbatim-subframes")) { - option_values.debug.disable_verbatim_subframes = true; - } - else if(0 == strcmp(long_option, "no-md5-sum")) { - option_values.debug.do_md5 = false; - } - else if(0 == strcmp(long_option, "no-error-on-compression-fail")) { - option_values.error_on_compression_fail = false; - } - else if(0 == strcmp(long_option, "error-on-compression-fail")) { - option_values.error_on_compression_fail = true; - } - } - else { - switch(short_option) { - case 'h': - option_values.show_help = true; - break; - case 'H': - option_values.show_explain = true; - break; - case 'v': - option_values.show_version = true; - break; - case 'd': - option_values.mode_decode = true; - break; - case 'a': - option_values.mode_decode = true; - option_values.analyze = true; - break; - case 't': - option_values.mode_decode = true; - option_values.test_only = true; - break; - case 'c': - option_values.force_to_stdout = true; - break; - case 's': -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - flac__utils_verbosity_ = 1; -#endif - break; - case 'f': - option_values.force_file_overwrite = true; - break; - case 'o': - FLAC__ASSERT(0 != option_argument); - option_values.cmdline_forced_outfilename = option_argument; - break; - case 'F': - option_values.continue_through_decode_errors = true; - break; - case 'T': - FLAC__ASSERT(0 != option_argument); - if(!flac__vorbiscomment_add(option_values.vorbis_comment, option_argument, /*value_from_file=*/false, /*raw=*/!option_values.utf8_convert, &violation)) - return usage_error("ERROR: (-T/--tag) %s\n", violation); - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - add_compression_setting_uint32_t(CST_COMPRESSION_LEVEL, short_option-'0'); - break; - case '9': - return usage_error("ERROR: compression level '9' is reserved\n"); - case 'V': - option_values.verify = true; - break; - case 'w': - option_values.treat_warnings_as_errors = true; - break; - case 'S': - FLAC__ASSERT(0 != option_argument); - if(0 == strcmp(option_argument, "-")) { - option_values.num_requested_seek_points = 0; - option_values.requested_seek_points[0] = '\0'; - } - else { - if(option_values.num_requested_seek_points < 0) - option_values.num_requested_seek_points = 0; - option_values.num_requested_seek_points++; - if(strlen(option_values.requested_seek_points)+strlen(option_argument)+2 >= sizeof(option_values.requested_seek_points)) { - return usage_error("ERROR: too many seekpoints requested\n"); - } - else { - size_t len = strlen(option_values.requested_seek_points); - flac_snprintf(option_values.requested_seek_points+len, sizeof(option_values.requested_seek_points) - len, "%s;", option_argument); - } - } - break; - case 'P': - FLAC__ASSERT(0 != option_argument); - option_values.padding = atoi(option_argument); - if(option_values.padding < 0) - return usage_error("ERROR: argument to -%c must be >= 0; for no padding use -%c-\n", short_option, short_option); - break; - case 'b': - { - uint32_t i ; - FLAC__ASSERT(0 != option_argument); - i = atoi(option_argument); - if((i < (int)FLAC__MIN_BLOCK_SIZE || i > (int)FLAC__MAX_BLOCK_SIZE)) - return usage_error("ERROR: invalid blocksize (-%c) '%d', must be >= %u and <= %u\n", short_option, i, FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE); - add_compression_setting_uint32_t(CST_BLOCKSIZE, (uint32_t)i); - } - break; - case 'e': - add_compression_setting_bool(CST_DO_EXHAUSTIVE_MODEL_SEARCH, true); - break; - case 'E': - add_compression_setting_bool(CST_DO_ESCAPE_CODING, true); - break; - case 'l': - { - uint32_t i ; - FLAC__ASSERT(0 != option_argument); - i = atoi(option_argument); - if(i > FLAC__MAX_LPC_ORDER) - return usage_error("ERROR: invalid LPC order (-%c) '%d', must be >= %u and <= %u\n", short_option, i, 0, FLAC__MAX_LPC_ORDER); - add_compression_setting_uint32_t(CST_MAX_LPC_ORDER, i); - } - break; - case 'A': - FLAC__ASSERT(0 != option_argument); - add_compression_setting_string(CST_APODIZATION, option_argument); - break; - case 'm': - add_compression_setting_bool(CST_DO_MID_SIDE, true); - add_compression_setting_bool(CST_LOOSE_MID_SIDE, false); - break; - case 'M': - add_compression_setting_bool(CST_DO_MID_SIDE, true); - add_compression_setting_bool(CST_LOOSE_MID_SIDE, true); - break; - case 'p': - add_compression_setting_bool(CST_DO_QLP_COEFF_PREC_SEARCH, true); - break; - case 'q': - { - uint32_t i ; - FLAC__ASSERT(0 != option_argument); - i = atoi(option_argument); - if((i > 0 && (i < FLAC__MIN_QLP_COEFF_PRECISION || i > FLAC__MAX_QLP_COEFF_PRECISION))) - return usage_error("ERROR: invalid value '%d' for qlp coeff precision (-%c), must be 0 or between %u and %u, inclusive\n", i, short_option, FLAC__MIN_QLP_COEFF_PRECISION, FLAC__MAX_QLP_COEFF_PRECISION); - add_compression_setting_uint32_t(CST_QLP_COEFF_PRECISION, i); - } - break; - case 'r': - { - uint32_t i; - char * p; - FLAC__ASSERT(0 != option_argument); - p = strchr(option_argument, ','); - if(0 == p) { - add_compression_setting_uint32_t(CST_MIN_RESIDUAL_PARTITION_ORDER, 0); - i = atoi(option_argument); - if(i > FLAC__MAX_RICE_PARTITION_ORDER) - return usage_error("ERROR: invalid value '%d' for residual partition order (-%c), must be between 0 and %u, inclusive\n", i, short_option, FLAC__MAX_RICE_PARTITION_ORDER); - add_compression_setting_uint32_t(CST_MAX_RESIDUAL_PARTITION_ORDER, i); - } - else { - i = atoi(option_argument); - if(i > FLAC__MAX_RICE_PARTITION_ORDER) - return usage_error("ERROR: invalid value '%d' for min residual partition order (-%c), must be between 0 and %u, inclusive\n", i, short_option, FLAC__MAX_RICE_PARTITION_ORDER); - add_compression_setting_uint32_t(CST_MIN_RESIDUAL_PARTITION_ORDER, i); - i = atoi(++p); - if(i > FLAC__MAX_RICE_PARTITION_ORDER) - return usage_error("ERROR: invalid value '%d' for max residual partition order (-%c), must be between 0 and %u, inclusive\n", i, short_option, FLAC__MAX_RICE_PARTITION_ORDER); - add_compression_setting_uint32_t(CST_MAX_RESIDUAL_PARTITION_ORDER, i); - } - } - break; - case 'R': - { - uint32_t i; - i = atoi(option_argument); - add_compression_setting_uint32_t(CST_RICE_PARAMETER_SEARCH_DIST, i); - } - break; - default: - FLAC__ASSERT(0); - } - } - - return 0; -} - -void free_options(void) -{ - uint32_t i; - if(0 != option_values.filenames) { - for(i = 0; i < option_values.num_files; i++) { - if(0 != option_values.filenames[i]) - free(option_values.filenames[i]); - } - free(option_values.filenames); - } - if(0 != option_values.vorbis_comment) - FLAC__metadata_object_delete(option_values.vorbis_comment); - for(i = 0; i < option_values.num_pictures; i++) - FLAC__metadata_object_delete(option_values.pictures[i]); -} - -void add_compression_setting_bool(compression_setting_type_t type, FLAC__bool value) -{ - if(option_values.num_compression_settings >= sizeof(option_values.compression_settings)/sizeof(option_values.compression_settings[0])) -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - die("too many compression settings"); -#else - return; -#endif - option_values.compression_settings[option_values.num_compression_settings].type = type; - option_values.compression_settings[option_values.num_compression_settings].value.t_bool = value; - option_values.num_compression_settings++; -} - -void add_compression_setting_string(compression_setting_type_t type, const char *value) -{ - if(option_values.num_compression_settings >= sizeof(option_values.compression_settings)/sizeof(option_values.compression_settings[0])) -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - die("too many compression settings"); -#else - return; -#endif - option_values.compression_settings[option_values.num_compression_settings].type = type; - option_values.compression_settings[option_values.num_compression_settings].value.t_string = value; - option_values.num_compression_settings++; -} - -void add_compression_setting_uint32_t(compression_setting_type_t type, uint32_t value) -{ - if(option_values.num_compression_settings >= sizeof(option_values.compression_settings)/sizeof(option_values.compression_settings[0])) -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - die("too many compression settings"); -#else - return; -#endif - if(type == CST_COMPRESSION_LEVEL) { - /* Compression level always goes first */ - option_values.compression_settings[0].type = type; - option_values.compression_settings[0].value.t_unsigned = value; - } - else { - option_values.compression_settings[option_values.num_compression_settings].type = type; - option_values.compression_settings[option_values.num_compression_settings].value.t_unsigned = value; - option_values.num_compression_settings++; - } -} - -int usage_error(const char *message, ...) -{ - if(flac__utils_verbosity_ >= 1) { - va_list args; - - FLAC__ASSERT(0 != message); - - va_start(args, message); - -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - (void) vfprintf(stderr, message, args); -#endif - - va_end(args); - - printf("Type \"flac\" for a usage summary or \"flac --help\" for all options\n"); - } - - return 1; -} - -void show_version(void) -{ - printf("flac %s\n", FLAC__VERSION_STRING); -} - -static void usage_header(void) -{ - printf("===============================================================================\n"); - printf("flac - Command-line FLAC encoder/decoder version %s\n", FLAC__VERSION_STRING); - printf("Copyright (C) 2000-2009 Josh Coalson\n"); - printf("Copyright (C) 2011-2023 Xiph.Org Foundation\n"); - printf("\n"); - printf("This program is free software; you can redistribute it and/or\n"); - printf("modify it under the terms of the GNU General Public License\n"); - printf("as published by the Free Software Foundation; either version 2\n"); - printf("of the License, or (at your option) any later version.\n"); - printf("\n"); - printf("This program is distributed in the hope that it will be useful,\n"); - printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); - printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); - printf("GNU General Public License for more details.\n"); - printf("\n"); - printf("You should have received a copy of the GNU General Public License along\n"); - printf("with this program; if not, write to the Free Software Foundation, Inc.,\n"); - printf("51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n"); - printf("===============================================================================\n"); -} - -static void usage_summary(void) -{ - printf("Usage:\n"); - printf("\n"); - printf(" Encoding: flac [] [INPUTFILE [...]]\n"); - printf(" Decoding: flac -d [] [FLACFILE [...]]\n"); - printf(" Testing: flac -t [] [FLACFILE [...]]\n"); - printf("Analyzing: flac -a [] [FLACFILE [...]]\n"); - printf("\n"); - printf("Be sure to read the list of known bugs at:\n"); - printf("http://xiph.org/flac/documentation_bugs.html\n"); - printf("\n"); -} - -void short_usage(void) -{ - usage_header(); - printf("\n"); - printf("This is the short help; for all options use 'flac --help'; for even more\n"); - printf("instructions use 'flac --explain'\n"); - printf("\n"); - printf("Be sure to read the list of known bugs at:\n"); - printf("http://xiph.org/flac/documentation_bugs.html\n"); - printf("\n"); - printf("To encode:\n"); - printf(" flac [-#] [INPUTFILE [...]]\n"); - printf("\n"); - printf(" -# is -0 (fastest compression) to -8 (highest compression); -5 is the default\n"); - printf("\n"); - printf("To decode:\n"); - printf(" flac -d [INPUTFILE [...]]\n"); - printf("\n"); - printf("To test:\n"); - printf(" flac -t [INPUTFILE [...]]\n"); -} - -void show_help(void) -{ - usage_header(); - usage_summary(); - printf("general options:\n"); - printf(" -v, --version Show the flac version number\n"); - printf(" -h, --help Show this screen\n"); - printf(" -H, --explain Show detailed explanation of usage and options\n"); - printf(" -d, --decode Decode (the default behavior is to encode)\n"); - printf(" -t, --test Same as -d except no decoded file is written\n"); - printf(" -a, --analyze Same as -d except an analysis file is written\n"); - printf(" -c, --stdout Write output to stdout\n"); - printf(" -s, --silent Do not write runtime encode/decode statistics\n"); - printf(" --totally-silent Do not print anything, including errors\n"); - printf(" --no-utf8-convert Do not convert tags from local charset to UTF-8\n"); - printf(" -w, --warnings-as-errors Treat all warnings as errors\n"); - printf(" -f, --force Force overwriting of output files\n"); - printf(" -o, --output-name=FILENAME Force the output file name\n"); - printf(" --output-prefix=STRING Prepend STRING to output names\n"); - printf(" --delete-input-file Deletes after a successful encode/decode\n"); - printf(" --preserve-modtime Output files keep timestamp of input (default)\n"); - printf(" --keep-foreign-metadata Save/restore WAVE or AIFF non-audio chunks\n"); - printf(" --keep-foreign-metadata-if-present Save/restore WAVE or AIFF non-audio\n"); - printf(" but not return an error when no such chunks are found\n"); - printf(" --skip={#|mm:ss.ss} Skip the given initial samples for each input\n"); - printf(" --until={#|[+|-]mm:ss.ss} Stop at the given sample for each input file\n"); -#if FLAC__HAS_OGG - printf(" --ogg Use Ogg as transport layer\n"); - printf(" --serial-number Serial number to use for the FLAC stream\n"); -#endif - printf("analysis options:\n"); - printf(" --residual-text Include residual signal in text output\n"); - printf(" --residual-gnuplot Generate gnuplot files of residual distribution\n"); - printf("decoding options:\n"); - printf(" -F, --decode-through-errors Continue decoding through stream errors\n"); - printf(" --cue=[#.#][-[#.#]] Set the beginning and ending cuepoints to decode\n"); - printf("encoding options:\n"); - printf(" -V, --verify Verify a correct encoding\n"); - printf(" --lax Allow encoder to generate non-Subset files\n"); - printf(" --ignore-chunk-sizes Ignore data chunk sizes in WAVE/AIFF files\n"); - printf(" --replay-gain Calculate ReplayGain & store in FLAC tags\n"); - printf(" --cuesheet=FILENAME Import cuesheet and store in CUESHEET block\n"); - printf(" --picture=SPECIFICATION Import picture and store in PICTURE block\n"); - printf(" -T, --tag=FIELD=VALUE Add a FLAC tag; may appear multiple times\n"); - printf(" --tag-from-file=FIELD=FILENAME Like --tag but gets value from file\n"); - printf(" -S, --seekpoint={#|X|#x|#s} Add seek point(s)\n"); - printf(" -P, --padding=# Write a PADDING block of length #\n"); - printf(" -0, --compression-level-0, --fast Synonymous with -l 0 -b 1152 -r 3\n"); - printf(" -1, --compression-level-1 Synonymous with -l 0 -b 1152 -M -r 3\n"); - printf(" -2, --compression-level-2 Synonymous with -l 0 -b 1152 -m -r 3\n"); - printf(" -3, --compression-level-3 Synonymous with -l 6 -b 4096 -r 4\n"); - printf(" -4, --compression-level-4 Synonymous with -l 8 -b 4096 -M -r 4\n"); - printf(" -5, --compression-level-5 Synonymous with -l 8 -b 4096 -m -r 5\n"); - printf(" -6, --compression-level-6 Synonymous with -l 8 -b 4096 -m -r 6\n"); - printf(" -A subdivide_tukey(2)\n"); - printf(" -7, --compression-level-7 Synonymous with -l 12 -b 4096 -m -r 6\n"); - printf(" -A subdivide_tukey(2)\n"); - printf(" -8, --compression-level-8, --best Synonymous with -l 12 -b 4096 -m -r 6\n"); - printf(" -A subdivide_tukey(3)\n"); - printf(" -b, --blocksize=# Specify blocksize in samples\n"); - printf(" -m, --mid-side Try mid-side coding for each frame\n"); - printf(" -M, --adaptive-mid-side Adaptive mid-side coding for all frames\n"); - printf(" -e, --exhaustive-model-search Do exhaustive model search (expensive!)\n"); - printf(" -A, --apodization=\"function\" Window audio data with given the function\n"); - printf(" -l, --max-lpc-order=# Max LPC order; 0 => only fixed predictors\n"); - printf(" -p, --qlp-coeff-precision-search Exhaustively search LP coeff quantization\n"); - printf(" -q, --qlp-coeff-precision=# Specify precision in bits\n"); - printf(" -r, --rice-partition-order=[#,]# Set [min,]max residual partition order\n"); - printf(" --limit-min-bitrate Limit minimum bitrate (for streaming)\n"); - printf("format options:\n"); - printf(" --force-raw-format Treat input or output as raw samples\n"); - printf(" --force-aiff-format Decode to AIFF format\n"); - printf(" --force-rf64-format Decode to RF64 format\n"); - printf(" --force-wave64-format Decode to Wave64 format\n"); - printf(" --force-legacy-wave-format Decode to legacy wave format\n"); - printf(" --force-extensible-wave-format Decode to extensible wave format\n"); - printf(" --force-aiff-c-none-format Decode to AIFF-C NONE format\n"); - printf(" --force-aiff-c-sowt-format Decode to AIFF-C sowt format\n"); - printf("raw format options:\n"); - printf(" --endian={big|little} Set byte order for samples\n"); - printf(" --channels=# Number of channels\n"); - printf(" --bps=# Number of bits per sample\n"); - printf(" --sample-rate=# Sample rate in Hz\n"); - printf(" --sign={signed|unsigned} Sign of samples\n"); - printf(" --input-size=# Size of the raw input in bytes\n"); - printf("negative options:\n"); - printf(" --no-adaptive-mid-side\n"); - printf(" --no-cued-seekpoints\n"); - printf(" --no-decode-through-errors\n"); - printf(" --no-delete-input-file\n"); - printf(" --no-error-on-compression-fail\n"); - printf(" --no-preserve-modtime\n"); - printf(" --no-keep-foreign-metadata\n"); - printf(" --no-exhaustive-model-search\n"); - printf(" --no-lax\n"); - printf(" --no-mid-side\n"); -#if FLAC__HAS_OGG - printf(" --no-ogg\n"); -#endif - printf(" --no-padding\n"); - printf(" --no-qlp-coeff-prec-search\n"); - printf(" --no-replay-gain\n"); - printf(" --no-residual-gnuplot\n"); - printf(" --no-residual-text\n"); - printf(" --no-ignore-chunk-sizes\n"); - printf(" --no-seektable\n"); - printf(" --no-silent\n"); - printf(" --no-force\n"); - printf(" --no-verify\n"); - printf(" --no-warnings-as-errors\n"); -} - -void show_explain(void) -{ - usage_header(); - usage_summary(); - printf("For encoding:\n"); - printf(" The input file(s) may be a PCM WAVE, Wave64, RF64 file, AIFF (or uncompressed\n"); - printf(" AIFF-C) file, or raw samples. The output file(s) will be in native FLAC\n"); - printf(" or Ogg FLAC format\n"); - printf("For decoding, the reverse is true.\n"); - printf("\n"); - printf("A single INPUTFILE may be - for stdin. No INPUTFILE implies stdin. Use of\n"); - printf("stdin implies -c (write to stdout). Normally you should use:\n"); - printf(" flac [options] -o outfilename or flac -d [options] -o outfilename\n"); - printf("instead of:\n"); - printf(" flac [options] > outfilename or flac -d [options] > outfilename\n"); - printf("since the former allows flac to seek backwards to write the STREAMINFO or\n"); - printf("WAVE/AIFF header contents when necessary.\n"); - printf("\n"); - printf("general options:\n"); - printf(" -v, --version Show the flac version number\n"); - printf(" -h, --help Show basic usage a list of all options\n"); - printf(" -H, --explain Show this screen\n"); - printf(" -d, --decode Decode (the default behavior is to encode)\n"); - printf(" -t, --test Same as -d except no decoded file is written\n"); - printf(" -a, --analyze Same as -d except an analysis file is written\n"); - printf(" -c, --stdout Write output to stdout\n"); - printf(" -s, --silent Do not write runtime encode/decode statistics\n"); - printf(" --totally-silent Do not print anything of any kind, including\n"); - printf(" warnings or errors. The exit code will be the\n"); - printf(" only way to determine successful completion.\n"); - printf(" --no-utf8-convert Do not convert tags from local charset to UTF-8.\n"); - printf(" This is useful for scripts, and setting tags in\n"); - printf(" situations where the locale is wrong. This\n"); - printf(" option must appear before any tag options!\n"); - printf(" -w, --warnings-as-errors Treat all warnings as errors\n"); - printf(" -f, --force Force overwriting of output files\n"); - printf(" -o, --output-name=FILENAME Force the output file name; usually flac just\n"); - printf(" changes the extension. May only be used when\n"); - printf(" encoding a single file. May not be used in\n"); - printf(" conjunction with --output-prefix.\n"); - printf(" --output-prefix=STRING Prefix each output file name with the given\n"); - printf(" STRING. This can be useful for encoding or\n"); - printf(" decoding files to a different directory. Make\n"); - printf(" sure if your STRING is a path name that it ends\n"); - printf(" with a '/' slash.\n"); - printf(" --delete-input-file Automatically delete the input file after a\n"); - printf(" successful encode or decode. If there was an\n"); - printf(" error (including a verify error) the input file\n"); - printf(" is left intact.\n"); - printf(" --preserve-modtime Output files have their timestamps/permissions\n"); - printf(" set to match those of their inputs (this is\n"); - printf(" default). Use --no-preserve-modtime to make\n"); - printf(" output files have the current time and default\n"); - printf(" permissions.\n"); - printf(" --keep-foreign-metadata If encoding, save WAVE or AIFF non-audio chunks\n"); - printf(" in FLAC metadata. If decoding, restore any saved\n"); - printf(" non-audio chunks from FLAC metadata when writing\n"); - printf(" the decoded file. Foreign metadata cannot be\n"); - printf(" transcoded, e.g. WAVE chunks saved in a FLAC file\n"); - printf(" cannot be restored when decoding to AIFF. Input\n"); - printf(" and output must be regular files, not stdin/out.\n"); - printf(" With this option, FLAC will pick the right\n"); - printf(" output format on decoding.\n"); - printf(" --keep-foreign-metadata-if-present As previous option, but do not throw\n"); - printf(" an error in case no foreign metadata is found,\n"); - printf(" the wrong kind of foreign metadata is found (on\n"); - printf(" decoding) or if the foreign could not be parsed,\n"); - printf(" i.e. all foreign metadata related errors are\n"); - printf(" treated as warnings.\n"); - printf(" --skip={#|mm:ss.ss} Skip the first # samples of each input file; can\n"); - printf(" be used both for encoding and decoding. The\n"); - printf(" alternative form mm:ss.ss can be used to specify\n"); - printf(" minutes, seconds, and fractions of a second.\n"); - printf(" --until={#|[+|-]mm:ss.ss} Stop at the given sample number for each input\n"); - printf(" file. The given sample number is not included\n"); - printf(" in the decoded output. The alternative form\n"); - printf(" mm:ss.ss can be used to specify minutes,\n"); - printf(" seconds, and fractions of a second. If a `+'\n"); - printf(" sign is at the beginning, the --until point is\n"); - printf(" relative to the --skip point. If a `-' sign is\n"); - printf(" at the beginning, the --until point is relative\n"); - printf(" to end of the audio.\n"); -#if FLAC__HAS_OGG - printf(" --ogg When encoding, generate Ogg FLAC output instead\n"); - printf(" of native FLAC. Ogg FLAC streams are FLAC\n"); - printf(" streams wrapped in an Ogg transport layer. The\n"); - printf(" resulting file should have an '.oga' extension\n"); - printf(" and will still be decodable by flac. When\n"); - printf(" decoding, force the input to be treated as\n"); - printf(" Ogg FLAC. This is useful when piping input\n"); - printf(" from stdin or when the filename does not end in\n"); - printf(" '.oga' or '.ogg'.\n"); - printf(" --serial-number Serial number to use for the FLAC stream. When\n"); - printf(" encoding and no serial number is given, flac\n"); - printf(" uses a random one. If encoding to multiple files\n"); - printf(" the serial number is incremented for each file.\n"); - printf(" When decoding and no number is given, flac uses\n"); - printf(" the serial number of the first page.\n"); -#endif - printf("analysis options:\n"); - printf(" --residual-text Include residual signal in text output. This\n"); - printf(" will make the file very big, much larger than\n"); - printf(" even the decoded file.\n"); - printf(" --residual-gnuplot Generate gnuplot files of residual distribution\n"); - printf(" of each subframe\n"); - printf("decoding options:\n"); - printf(" -F, --decode-through-errors By default flac stops decoding with an error\n"); - printf(" and removes the partially decoded file if it\n"); - printf(" encounters a bitstream error. With -F, errors\n"); - printf(" are still printed but flac will continue\n"); - printf(" decoding to completion. Note that errors may\n"); - printf(" cause the decoded audio to be missing some\n"); - printf(" samples or have silent sections.\n"); - printf(" --cue=[#.#][-[#.#]] Set the beginning and ending cuepoints to\n"); - printf(" decode. The optional first #.# is the track and\n"); - printf(" index point at which decoding will start; the\n"); - printf(" default is the beginning of the stream. The\n"); - printf(" optional second #.# is the track and index point\n"); - printf(" at which decoding will end; the default is the\n"); - printf(" end of the stream. If the cuepoint does not\n"); - printf(" exist, the closest one before it (for the start\n"); - printf(" point) or after it (for the end point) will be\n"); - printf(" used. The cuepoints are merely translated into\n"); - printf(" sample numbers then used as --skip and --until.\n"); - printf(" A CD track can always be cued by, for example,\n"); - printf(" --cue=9.1-10.1 for track 9, even if the CD has\n"); - printf(" no 10th track.\n"); - printf("encoding options:\n"); - printf(" -V, --verify Verify a correct encoding by decoding the\n"); - printf(" output in parallel and comparing to the\n"); - printf(" original\n"); - printf(" --lax Allow encoder to generate non-Subset files\n"); - printf(" --ignore-chunk-sizes Ignore data chunk sizes in WAVE/AIFF files;\n"); - printf(" useful when piping data from programs which\n"); - printf(" generate bogus data chunk sizes.\n"); - printf(" --replay-gain Calculate ReplayGain values and store them as\n"); - printf(" FLAC tags. Title gains/peaks will be computed\n"); - printf(" for each file, and an album gain/peak will be\n"); - printf(" computed for all files. All input files must\n"); - printf(" have the same resolution, sample rate, and\n"); - printf(" number of channels. Only mono and stereo files\n"); - printf(" are allowed, and the sample rate must be 8,\n"); - printf(" 11.025, 12, 16, 18.9, 22.05, 24, 28, 32, 36,\n"); - printf(" 37.8, 44.1, 48, 56, 64, 72, 75.6, 88.2, 96, 112,\n"); - printf(" 128, 144, 151.2, 176.4, 192, 224, 256, 288,\n"); - printf(" 302.4, 352.8, 384, 448, 512, 576, or 604.8 kHz.\n"); - printf(" NOTE: this option may also leave a few extra\n"); - printf(" bytes in the PADDING block.\n"); - printf(" --cuesheet=FILENAME Import the given cuesheet file and store it in\n"); - printf(" a CUESHEET metadata block. This option may only\n"); - printf(" be used when encoding a single file. A\n"); - printf(" seekpoint will be added for each index point in\n"); - printf(" the cuesheet to the SEEKTABLE unless\n"); - printf(" --no-cued-seekpoints is specified.\n"); - printf(" --picture=SPECIFICATION Import a picture and store it in a PICTURE block.\n"); - printf(" More than one --picture command can be specified.\n"); - printf(" The SPECIFICATION can either be a simple filename\n"); - printf(" for the picture file, or a complete specification\n"); - printf(" whose parts are separated by | characters. Some\n"); - printf(" parts may be left empty to invoke default values.\n"); - printf(" Using a filename is shorthand for \"||||FILE\".\n"); - printf(" The SPECIFICATION format is:\n"); - printf(" [TYPE]|[MIME-TYPE]|[DESCRIPTION]|[WIDTHxHEIGHTxDEPTH[/COLORS]]|FILE\n"); - printf(" TYPE is optional; it is a number from one of:\n"); - printf(" 0: Other\n"); - printf(" 1: 32x32 pixels 'file icon' (PNG only)\n"); - printf(" 2: Other file icon\n"); - printf(" 3: Cover (front)\n"); - printf(" 4: Cover (back)\n"); - printf(" 5: Leaflet page\n"); - printf(" 6: Media (e.g. label side of CD)\n"); - printf(" 7: Lead artist/lead performer/soloist\n"); - printf(" 8: Artist/performer\n"); - printf(" 9: Conductor\n"); - printf(" 10: Band/Orchestra\n"); - printf(" 11: Composer\n"); - printf(" 12: Lyricist/text writer\n"); - printf(" 13: Recording Location\n"); - printf(" 14: During recording\n"); - printf(" 15: During performance\n"); - printf(" 16: Movie/video screen capture\n"); - printf(" 17: A bright coloured fish\n"); - printf(" 18: Illustration\n"); - printf(" 19: Band/artist logotype\n"); - printf(" 20: Publisher/Studio logotype\n"); - printf(" The default is 3 (front cover). There may only be one picture each\n"); - printf(" of type 1 and 2 in a file.\n"); - printf(" MIME-TYPE is optional; if left blank, it will be detected from the\n"); - printf(" file. For best compatibility with players, use pictures with MIME\n"); - printf(" type image/jpeg or image/png. The MIME type can also be --> to\n"); - printf(" mean that FILE is actually a URL to an image, though this use is\n"); - printf(" discouraged.\n"); - printf(" DESCRIPTION is optional; the default is an empty string\n"); - printf(" The next part specifies the resolution and color information. If\n"); - printf(" the MIME-TYPE is image/jpeg, image/png, or image/gif, you can\n"); - printf(" usually leave this empty and they can be detected from the file.\n"); - printf(" Otherwise, you must specify the width in pixels, height in pixels,\n"); - printf(" and color depth in bits-per-pixel. If the image has indexed colors\n"); - printf(" you should also specify the number of colors used.\n"); - printf(" FILE is the path to the picture file to be imported, or the URL if\n"); - printf(" MIME type is -->\n"); - printf(" -T, --tag=FIELD=VALUE Add a FLAC tag. Make sure to quote the\n"); - printf(" comment if necessary. This option may appear\n"); - printf(" more than once to add several comments. NOTE:\n"); - printf(" all tags will be added to all encoded files.\n"); - printf(" --tag-from-file=FIELD=FILENAME Like --tag, except FILENAME is a file\n"); - printf(" whose contents will be read verbatim to set the\n"); - printf(" tag value. The contents will be converted to\n"); - printf(" UTF-8 from the local charset. This can be used\n"); - printf(" to store a cuesheet in a tag (e.g.\n"); - printf(" --tag-from-file=\"CUESHEET=image.cue\"). Do not\n"); - printf(" try to store binary data in tag fields! Use\n"); - printf(" APPLICATION blocks for that.\n"); - printf(" -S, --seekpoint={#|X|#x|#s} Include a point or points in a SEEKTABLE\n"); - printf(" # : a specific sample number for a seek point\n"); - printf(" X : a placeholder point (always goes at the end of the SEEKTABLE)\n"); - printf(" #x : # evenly spaced seekpoints, the first being at sample 0\n"); - printf(" #s : a seekpoint every # seconds; # does not have to be a whole number\n"); - printf(" You may use many -S options; the resulting SEEKTABLE will be the unique-\n"); - printf(" ified union of all such values.\n"); - printf(" With no -S options, flac defaults to '-S 10s'. Use -S- for no SEEKTABLE.\n"); - printf(" Note: -S #x and -S #s will not work if the encoder can't determine the\n"); - printf(" input size before starting.\n"); - printf(" Note: if you use -S # and # is >= samples in the input, there will be\n"); - printf(" either no seek point entered (if the input size is determinable\n"); - printf(" before encoding starts) or a placeholder point (if input size is not\n"); - printf(" determinable)\n"); - printf(" -P, --padding=# Tell the encoder to write a PADDING metadata\n"); - printf(" block of the given length (in bytes) after the\n"); - printf(" STREAMINFO block. This is useful if you plan\n"); - printf(" to tag the file later with an APPLICATION\n"); - printf(" block; instead of having to rewrite the entire\n"); - printf(" file later just to insert your block, you can\n"); - printf(" write directly over the PADDING block. Note\n"); - printf(" that the total length of the PADDING block will\n"); - printf(" be 4 bytes longer than the length given because\n"); - printf(" of the 4 metadata block header bytes. You can\n"); - printf(" force no PADDING block at all to be written with\n"); - printf(" --no-padding. The encoder writes a PADDING\n"); - printf(" block of 8192 bytes by default, or 65536 bytes\n"); - printf(" if the input audio is more than 20 minutes long.\n"); - printf(" -b, --blocksize=# Specify the blocksize in samples; the default is\n"); - printf(" 1152 for -l 0, else 4096; for subset streams this\n"); - printf(" must be <= 4608 if the samplerate <= 48kHz,\n"); - printf(" for subset streams with a higher samplerates it\n"); - printf(" must be <= 16384.\n"); - printf(" -0, --compression-level-0, --fast Synonymous with -l 0 -b 1152 -r 3\n"); - printf(" --no-mid-side\n"); - printf(" -1, --compression-level-1 Synonymous with -l 0 -b 1152 -M -r 3\n"); - printf(" -2, --compression-level-2 Synonymous with -l 0 -b 1152 -m -r 3\n"); - printf(" -3, --compression-level-3 Synonymous with -l 6 -b 4096 -r 4\n"); - printf(" --no-mid-side\n"); - printf(" -4, --compression-level-4 Synonymous with -l 8 -b 4096 -M -r 4\n"); - printf(" -5, --compression-level-5 Synonymous with -l 8 -b 4096 -m -r 5\n"); - printf(" -5 is the default setting\n"); - printf(" -6, --compression-level-6 Synonymous with -l 8 -b 4096 -m -r 6\n"); - printf(" -A subdivide_tukey(2)\n"); - printf(" -7, --compression-level-7 Synonymous with -l 12 -b 4096 -m -r 6\n"); - printf(" -A subdivide_tukey(2)\n"); - printf(" -8, --compression-level-8, --best Synonymous with -l 12 -b 4096 -m -r 6\n"); - printf(" -A subdivide_tukey(3)\n"); - printf(" -m, --mid-side Try mid-side coding for each frame\n"); - printf(" (stereo only)\n"); - printf(" -M, --adaptive-mid-side Adaptive mid-side coding for all frames\n"); - printf(" (stereo only)\n"); - printf(" -e, --exhaustive-model-search Do exhaustive model search (expensive!)\n"); - printf(" -A, --apodization=\"function\" Window audio data with given the function.\n"); - printf(" The functions are: bartlett, bartlett_hann,\n"); - printf(" blackman, blackman_harris_4term_92db,\n"); - printf(" connes, flattop, gauss(STDDEV), hamming,\n"); - printf(" hann, kaiser_bessel, nuttall, rectangle,\n"); - printf(" triangle, tukey(P), welch, partial_tukey(n)\n"); - printf(" punchout_tukey(n) and subdivide_tukey(n).\n"); - printf(" More than one may be specified but encoding\n"); - printf(" time is a multiple of the number of\n"); - printf(" functions since they are each tried in \n"); - printf(" turn. The encoder chooses suitable\n"); - printf(" defaults in the absence of any -A options.\n"); - printf(" -l, --max-lpc-order=# Max LPC order; 0 => only fixed predictors.\n"); - printf(" Must be <= 12 for Subset streams if sample\n"); - printf(" rate is <=48kHz.\n"); - printf(" -p, --qlp-coeff-precision-search Do exhaustive search of LP coefficient\n"); - printf(" quantization (expensive!); overrides -q;\n"); - printf(" does nothing if using -l 0\n"); - printf(" -q, --qlp-coeff-precision=# Specify precision in bits of quantized\n"); - printf(" linear-predictor coefficients; 0 => let\n"); - printf(" encoder decide (the minimum is %u, the\n", FLAC__MIN_QLP_COEFF_PRECISION); - printf(" default is -q 0)\n"); - printf(" -r, --rice-partition-order=[#,]# Set [min,]max residual partition order\n"); - printf(" (# is 0 to 15 inclusive; min defaults to 0;\n"); - printf(" the default is -r 0; above 4 does not\n"); - printf(" usually help much)\n"); - printf(" --limit-min-bitrate Limit minimum bitrate by not allowing\n"); - printf(" frames consisting of only constant\n"); - printf(" subframes. This ensures a bitrate of at\n"); - printf(" least 1 bit/sample, for example 48kbit/s\n"); - printf(" for 48kHz input. This is mostly beneficial\n"); - printf(" for internet streaming.\n"); - printf("format options:\n"); - printf(" --force-raw-format Force input (when encoding) or output (when\n"); - printf(" decoding) to be treated as raw samples\n"); - printf(" --force-aiff-format\n"); - printf(" --force-rf64-format\n"); - printf(" --force-wave64-format\n"); - printf(" Force the decoder to output AIFF/RF64/WAVE64 format respectively.\n"); - printf(" This option is not needed if the output filename (as set by -o)\n"); - printf(" ends with *.aif* or *.aiff*, *.rf64* and *.w64* respectively. Also,\n"); - printf(" this option has no effect when encoding since input is\n"); - printf(" auto-detected. When none of these options nor\n"); - printf(" --keep-foreign-metadata are given and no output filename is set,\n"); - printf(" the output format is WAV by default.\n"); - printf(" --force-legacy-wave-format\n"); - printf(" --force-extensible-wave-format\n"); - printf(" Instruct the decoder to output a WAVE file with WAVE_FORMAT_PCM and\n"); - printf(" WAVE_FORMAT_EXTENSIBLE respectively. If none of these options nor\n"); - printf(" --keep-foreign-metadata are given, FLAC outputs WAVE_FORMAT_PCM\n"); - printf(" for mono or stereo with a bit depth of 8 or 16 bits, and\n"); - printf(" WAVE_FORMAT_EXTENSIBLE for all other audio formats.\n"); - printf(" --force-aiff-c-none-format\n"); - printf(" --force-aiff-c-sowt-format\n"); - printf(" Instruct the decoder to output an AIFF-C file with format NONE and\n"); - printf(" sowt respectively.\n"); - printf("raw format options:\n"); - printf(" --endian={big|little} Set byte order for samples\n"); - printf(" --channels=# Number of channels\n"); - printf(" --bps=# Number of bits per sample\n"); - printf(" --sample-rate=# Sample rate in Hz\n"); - printf(" --sign={signed|unsigned} Sign of samples\n"); - printf(" --input-size=# Size of the raw input in bytes. If you are\n"); - printf(" encoding raw samples from stdin, you must set\n"); - printf(" this option in order to be able to use --skip,\n"); - printf(" --until, --cuesheet, or other options that need\n"); - printf(" to know the size of the input beforehand. If\n"); - printf(" the size given is greater than what is found in\n"); - printf(" the input stream, the encoder will complain\n"); - printf(" about an unexpected end-of-file. If the size\n"); - printf(" given is less, samples will be truncated.\n"); - printf("negative options:\n"); - printf(" --no-adaptive-mid-side\n"); - printf(" --no-cued-seekpoints\n"); - printf(" --no-decode-through-errors\n"); - printf(" --no-delete-input-file\n"); - printf(" --no-preserve-modtime\n"); - printf(" --no-keep-foreign-metadata\n"); - printf(" --no-exhaustive-model-search\n"); - printf(" --no-lax\n"); - printf(" --no-mid-side\n"); -#if FLAC__HAS_OGG - printf(" --no-ogg\n"); -#endif - printf(" --no-padding\n"); - printf(" --no-qlp-coeff-prec-search\n"); - printf(" --no-residual-gnuplot\n"); - printf(" --no-residual-text\n"); - printf(" --no-ignore-chunk-sizes\n"); - printf(" --no-seektable\n"); - printf(" --no-silent\n"); - printf(" --no-force\n"); - printf(" --no-verify\n"); - printf(" --no-warnings-as-errors\n"); -} - -void format_mistake(const char *infilename, FileFormat wrong, FileFormat right) -{ - /* WATCHOUT: indexed by FileFormat */ - flac__utils_printf(stderr, 1, "WARNING: %s is not a%s file; treating as a%s file\n", infilename, FileFormatString[wrong], FileFormatString[right]); -} - -int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_last_file) -{ - FILE *encode_infile; - FLAC__byte lookahead[12]; - uint32_t lookahead_length = 0, master_chunk_size = 0; - FileFormat input_format = FORMAT_RAW; - int retval; - FLAC__off_t infilesize; - encode_options_t encode_options; - const char *outfilename = get_encoded_outfilename(infilename); /* the final name of the encoded file */ - /* internal_outfilename is the file we will actually write to; it will be a temporary name if infilename==outfilename */ - char *internal_outfilename = 0; /* NULL implies 'use outfilename' */ - size_t infilename_length; - - if(0 == outfilename) { - flac__utils_printf(stderr, 1, "ERROR: filename too long: %s", infilename); - return 1; - } - - if(0 == strcmp(infilename, "-")) { - infilesize = (FLAC__off_t)(-1); - encode_infile = grabbag__file_get_binary_stdin(); - } - else - { - infilesize = grabbag__file_get_filesize(infilename); - if(0 == (encode_infile = flac_fopen(infilename, "rb"))) { - flac__utils_printf(stderr, 1, "ERROR: can't open input file %s: %s\n", infilename, strerror(errno)); - return 1; - } - } - - if(!option_values.force_raw_format) { - /* first set format based on name */ - infilename_length = strlen(infilename); - if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".wav")) - input_format = FORMAT_WAVE; - else if(infilename_length >= 5 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-5), ".rf64")) - input_format = FORMAT_RF64; - else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".w64")) - input_format = FORMAT_WAVE64; - else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".aif")) - input_format = FORMAT_AIFF; - else if(infilename_length >= 5 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-5), ".aiff")) - input_format = FORMAT_AIFF; - else if(infilename_length >= 5 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-5), ".flac")) - input_format = FORMAT_FLAC; - else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".oga")) - input_format = FORMAT_OGGFLAC; - else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".ogg")) - input_format = FORMAT_OGGFLAC; - - /* attempt to guess the file type based on the first 12 bytes */ - if((lookahead_length = fread(lookahead, 1, 12, encode_infile)) < 12) { - /* all supported non-raw formats have at least 12 bytes of header to read */ - if(input_format != FORMAT_RAW) { - format_mistake(infilename, input_format, FORMAT_RAW); - if(option_values.treat_warnings_as_errors) { - conditional_fclose(encode_infile); - return 1; - } - } - /* force to raw */ - input_format = FORMAT_RAW; - } - else { - if(!memcmp(lookahead, "ID3", 3)) { - flac__utils_printf(stderr, 1, "ERROR: input file %s has an ID3v2 tag\n", infilename); - conditional_fclose(encode_infile); - return 1; - } - else if(!memcmp(lookahead, "RIFF", 4) && !memcmp(lookahead+8, "WAVE", 4)) - input_format = FORMAT_WAVE; - else if(!memcmp(lookahead, "RF64", 4) && !memcmp(lookahead+8, "WAVE", 4)) - input_format = FORMAT_RF64; - else if(!memcmp(lookahead, "riff\x2E\x91\xCF\x11\xA5\xD6\x28\xDB", 12)) /* just check 1st 12 bytes of GUID */ - input_format = FORMAT_WAVE64; - else if(!memcmp(lookahead, "FORM", 4) && !memcmp(lookahead+8, "AIFF", 4)) - input_format = FORMAT_AIFF; - else if(!memcmp(lookahead, "FORM", 4) && !memcmp(lookahead+8, "AIFC", 4)) - input_format = FORMAT_AIFF_C; - else if(!memcmp(lookahead, FLAC__STREAM_SYNC_STRING, sizeof(FLAC__STREAM_SYNC_STRING))) - input_format = FORMAT_FLAC; - /*@@@ this could be made more accurate by looking at the first packet to make sure it's Ogg FLAC and not, say, Ogg Vorbis. we do catch such problems later though. */ - else if(!memcmp(lookahead, "OggS", 4)) - input_format = FORMAT_OGGFLAC; - else { - /* didn't find header of any supported format */ - if(input_format != FORMAT_RAW) { - format_mistake(infilename, input_format, FORMAT_RAW); - if(option_values.treat_warnings_as_errors) { - conditional_fclose(encode_infile); - return 1; - } - } - /* force to raw */ - input_format = FORMAT_RAW; - } - } - } - - if(!option_values.ignore_chunk_sizes - && (input_format == FORMAT_WAVE || input_format == FORMAT_AIFF || input_format == FORMAT_AIFF_C) - && infilesize >= UINT32_MAX) { - conditional_fclose(encode_infile); - return usage_error("ERROR: file %s is too large to be valid.\n" - "Please consult the manual on the --ignore-chunk-sizes option\n\n", infilename); - } - - if(input_format == FORMAT_WAVE || input_format == FORMAT_AIFF || input_format == FORMAT_AIFF_C) { - memcpy(&master_chunk_size,lookahead+4,sizeof(master_chunk_size)); - if((input_format != FORMAT_WAVE) != CPU_IS_BIG_ENDIAN /* logical xor */) - /* true for WAVE on big endian CPUs or AIFF/AIFF-C on little endian CPUs */ - master_chunk_size = ENDSWAP_32(master_chunk_size); - - if(infilesize != (FLAC__off_t)(-1) && infilesize > 8 && (infilesize - 8) != master_chunk_size) { - flac__utils_printf(stderr, 1, "WARNING: %s chunk size of file %s does not agree with filesize\n", (input_format == FORMAT_WAVE)?"RIFF":"FORM", infilename); - if(option_values.treat_warnings_as_errors) - return 1; - } - } - - if(option_values.keep_foreign_metadata || option_values.keep_foreign_metadata_if_present) { - if(encode_infile == stdin || option_values.force_to_stdout) { - conditional_fclose(encode_infile); - return usage_error("ERROR: --keep-foreign-metadata cannot be used when encoding from stdin or to stdout\n"); - } - if(input_format != FORMAT_WAVE && input_format != FORMAT_WAVE64 && input_format != FORMAT_RF64 && input_format != FORMAT_AIFF && input_format != FORMAT_AIFF_C) { - conditional_fclose(encode_infile); - return usage_error("ERROR: --keep-foreign-metadata can only be used with WAVE, Wave64, RF64, or AIFF input\n"); - } - } - - /* - * Error if output file already exists (and -f not used). - * Use grabbag__file_get_filesize() as a cheap way to check. - */ - if(!option_values.test_only && !option_values.force_file_overwrite && strcmp(outfilename, "-") && grabbag__file_get_filesize(outfilename) != (FLAC__off_t)(-1)) { - if(input_format == FORMAT_FLAC) { - /* need more detailed error message when re-flac'ing to avoid confusing the user */ - flac__utils_printf(stderr, 1, - "ERROR: output file %s already exists.\n\n" - "By default flac encodes files to FLAC format; if you meant to decode this file\n" - "from FLAC to something else, use -d. If you meant to re-encode this file from\n" - "FLAC to FLAC again, use -f to force writing to the same file, or -o to specify\n" - "a different output filename.\n", - outfilename - ); - } - else if(input_format == FORMAT_OGGFLAC) { - /* need more detailed error message when re-flac'ing to avoid confusing the user */ - flac__utils_printf(stderr, 1, - "ERROR: output file %s already exists.\n\n" - "By default 'flac -ogg' encodes files to Ogg FLAC format; if you meant to decode\n" - "this file from Ogg FLAC to something else, use -d. If you meant to re-encode\n" - "this file from Ogg FLAC to Ogg FLAC again, use -f to force writing to the same\n" - "file, or -o to specify a different output filename.\n", - outfilename - ); - } - else - flac__utils_printf(stderr, 1, "ERROR: output file %s already exists, use -f to override\n", outfilename); - conditional_fclose(encode_infile); - return 1; - } - - if(option_values.format_input_size >= 0) { - if (input_format != FORMAT_RAW || infilesize >= 0) { - flac__utils_printf(stderr, 1, "ERROR: can only use --input-size when encoding raw samples from stdin\n"); - conditional_fclose(encode_infile); - return 1; - } - else { - infilesize = option_values.format_input_size; - } - } - - if(input_format == FORMAT_RAW) { - if(option_values.format_is_big_endian < 0 || option_values.format_is_unsigned_samples < 0 || option_values.format_channels < 0 || option_values.format_bps < 0 || option_values.format_sample_rate < 0) { - conditional_fclose(encode_infile); - return usage_error("ERROR: for encoding a raw file you must specify a value for --endian, --sign, --channels, --bps, and --sample-rate\n"); - } - } - else { - if(option_values.format_is_big_endian >= 0 || option_values.format_is_unsigned_samples >= 0 || option_values.format_channels >= 0 || option_values.format_bps >= 0 || option_values.format_sample_rate >= 0) { - conditional_fclose(encode_infile); - return usage_error("ERROR: raw format options (--endian, --sign, --channels, --bps, and --sample-rate) are not allowed for non-raw input\n"); - } - } - - if(option_values.force_to_stdout) { - if(option_values.replay_gain) { - conditional_fclose(encode_infile); - return usage_error("ERROR: --replay-gain cannot be used when encoding to stdout\n"); - } - } - if(option_values.replay_gain && option_values.use_ogg) { - conditional_fclose(encode_infile); - return usage_error("ERROR: --replay-gain cannot be used when encoding to Ogg FLAC yet\n"); - } - - if(!flac__utils_parse_skip_until_specification(option_values.skip_specification, &encode_options.skip_specification) || encode_options.skip_specification.is_relative) { - conditional_fclose(encode_infile); - return usage_error("ERROR: invalid value for --skip\n"); - } - - if(!flac__utils_parse_skip_until_specification(option_values.until_specification, &encode_options.until_specification)) { /*@@@@ more checks: no + without --skip, no - unless known total_samples_to_{en,de}code */ - conditional_fclose(encode_infile); - return usage_error("ERROR: invalid value for --until\n"); - } - /* if there is no "--until" we want to default to "--until=-0" */ - if(0 == option_values.until_specification) - encode_options.until_specification.is_relative = true; - - encode_options.verify = option_values.verify; - encode_options.treat_warnings_as_errors = option_values.treat_warnings_as_errors; -#if FLAC__HAS_OGG - encode_options.use_ogg = option_values.use_ogg; - /* set a random serial number if one has not yet been specified */ - if(!option_values.has_serial_number) { - option_values.serial_number = rand(); - option_values.has_serial_number = true; - } - encode_options.serial_number = option_values.serial_number++; -#endif - encode_options.lax = option_values.lax; - encode_options.padding = option_values.padding; - encode_options.num_compression_settings = option_values.num_compression_settings; - FLAC__ASSERT(sizeof(encode_options.compression_settings) >= sizeof(option_values.compression_settings)); - memcpy(encode_options.compression_settings, option_values.compression_settings, sizeof(option_values.compression_settings)); - encode_options.requested_seek_points = option_values.requested_seek_points; - encode_options.num_requested_seek_points = option_values.num_requested_seek_points; - encode_options.cuesheet_filename = option_values.cuesheet_filename; - encode_options.continue_through_decode_errors = option_values.continue_through_decode_errors; - encode_options.cued_seekpoints = option_values.cued_seekpoints; - encode_options.channel_map_none = option_values.channel_map_none; - encode_options.is_first_file = is_first_file; - encode_options.is_last_file = is_last_file; - encode_options.replay_gain = option_values.replay_gain; - encode_options.ignore_chunk_sizes = option_values.ignore_chunk_sizes; - encode_options.vorbis_comment = option_values.vorbis_comment; - FLAC__ASSERT(sizeof(encode_options.pictures) >= sizeof(option_values.pictures)); - memcpy(encode_options.pictures, option_values.pictures, sizeof(option_values.pictures)); - encode_options.num_pictures = option_values.num_pictures; - encode_options.format = input_format; - encode_options.debug.disable_constant_subframes = option_values.debug.disable_constant_subframes; - encode_options.debug.disable_fixed_subframes = option_values.debug.disable_fixed_subframes; - encode_options.debug.disable_verbatim_subframes = option_values.debug.disable_verbatim_subframes; - encode_options.debug.do_md5 = option_values.debug.do_md5; - encode_options.error_on_compression_fail = option_values.error_on_compression_fail; - encode_options.limit_min_bitrate = option_values.limit_min_bitrate; - encode_options.relaxed_foreign_metadata_handling = option_values.keep_foreign_metadata_if_present; - - /* if infilename and outfilename point to the same file, we need to write to a temporary file */ - if(encode_infile != stdin && grabbag__file_are_same(infilename, outfilename)) { - static const char *tmp_suffix = ".tmp,fl-ac+en'c"; - size_t dest_len = strlen(outfilename) + strlen(tmp_suffix) + 1; - /*@@@@ still a remote possibility that a file with this filename exists */ - if((internal_outfilename = safe_malloc_(dest_len)) == NULL) { - flac__utils_printf(stderr, 1, "ERROR allocating memory for tempfile name\n"); - conditional_fclose(encode_infile); - return 1; - } - flac_snprintf(internal_outfilename, dest_len, "%s%s", outfilename, tmp_suffix); - } - - if(input_format == FORMAT_RAW) { - encode_options.format_options.raw.is_big_endian = option_values.format_is_big_endian; - encode_options.format_options.raw.is_unsigned_samples = option_values.format_is_unsigned_samples; - encode_options.format_options.raw.channels = option_values.format_channels; - encode_options.format_options.raw.bps = option_values.format_bps; - encode_options.format_options.raw.sample_rate = option_values.format_sample_rate; - - retval = flac__encode_file(encode_infile, infilesize, infilename, internal_outfilename? internal_outfilename : outfilename, lookahead, lookahead_length, encode_options); - } - else if(input_format == FORMAT_FLAC || input_format == FORMAT_OGGFLAC) { - retval = flac__encode_file(encode_infile, infilesize, infilename, internal_outfilename? internal_outfilename : outfilename, lookahead, lookahead_length, encode_options); - } - else if(input_format == FORMAT_WAVE || input_format == FORMAT_WAVE64 || input_format == FORMAT_RF64 || input_format == FORMAT_AIFF || input_format == FORMAT_AIFF_C) { - encode_options.format_options.iff.foreign_metadata = 0; - - /* initialize foreign metadata if requested */ - if(option_values.keep_foreign_metadata || option_values.keep_foreign_metadata_if_present) { - encode_options.format_options.iff.foreign_metadata = - flac__foreign_metadata_new( - input_format==FORMAT_WAVE || input_format==FORMAT_RF64? - FOREIGN_BLOCK_TYPE__RIFF : - input_format==FORMAT_WAVE64? - FOREIGN_BLOCK_TYPE__WAVE64 : - FOREIGN_BLOCK_TYPE__AIFF - ); - if(0 == encode_options.format_options.iff.foreign_metadata) { - flac__utils_printf(stderr, 1, "ERROR: creating foreign metadata object\n"); - conditional_fclose(encode_infile); - if(internal_outfilename != 0) - free(internal_outfilename); - return 1; - } - } - - retval = flac__encode_file(encode_infile, infilesize, infilename, internal_outfilename? internal_outfilename : outfilename, lookahead, lookahead_length, encode_options); - - if(encode_options.format_options.iff.foreign_metadata) - flac__foreign_metadata_delete(encode_options.format_options.iff.foreign_metadata); - } - else { - FLAC__ASSERT(0); - retval = 1; /* double protection */ - } - - if(retval == 0) { - if(strcmp(outfilename, "-")) { - if(option_values.replay_gain) { - float title_gain, title_peak; - const char *error; - grabbag__replaygain_get_title(&title_gain, &title_peak); - if( - 0 != (error = grabbag__replaygain_store_to_file_reference(internal_outfilename? internal_outfilename : outfilename, option_values.preserve_modtime)) || - 0 != (error = grabbag__replaygain_store_to_file_title(internal_outfilename? internal_outfilename : outfilename, title_gain, title_peak, option_values.preserve_modtime)) - ) { - flac__utils_printf(stderr, 1, "%s: ERROR writing ReplayGain reference/title tags (%s)\n", outfilename, error); - retval = 1; - } - } - if(option_values.preserve_modtime && strcmp(infilename, "-")) - grabbag__file_copy_metadata(infilename, internal_outfilename? internal_outfilename : outfilename); - } - } - - /* rename temporary file if necessary */ - if(retval == 0 && internal_outfilename != 0) { - if(flac_rename(internal_outfilename, outfilename) < 0) { -#if defined _MSC_VER || defined __MINGW32__ || defined __EMX__ - /* on some flavors of windows, flac_rename() will fail if the destination already exists, so we unlink and try again */ - if(flac_unlink(outfilename) < 0) { - flac__utils_printf(stderr, 1, "ERROR: moving new FLAC file %s back on top of original FLAC file %s, keeping both\n", internal_outfilename, outfilename); - retval = 1; - } - else if(flac_rename(internal_outfilename, outfilename) < 0) { - flac__utils_printf(stderr, 1, "ERROR: moving new FLAC file %s back on top of original FLAC file %s, you must do it\n", internal_outfilename, outfilename); - retval = 1; - } -#else - flac__utils_printf(stderr, 1, "ERROR: moving new FLAC file %s back on top of original FLAC file %s, keeping both\n", internal_outfilename, outfilename); - retval = 1; -#endif - } - } - - /* handle --delete-input-file, but don't want to delete if piping from stdin, or if input filename and output filename are the same */ - if(retval == 0 && option_values.delete_input && strcmp(infilename, "-") && internal_outfilename == 0) - flac_unlink(infilename); - - if(internal_outfilename != 0) - free(internal_outfilename); - - return retval; -} - -int decode_file(const char *infilename) -{ - int retval; - FLAC__bool treat_as_ogg = false; - FileFormat output_format = FORMAT_WAVE; - FileSubFormat output_subformat = SUBFORMAT_UNSPECIFIED; - decode_options_t decode_options; - foreign_metadata_t *foreign_metadata = 0; - const char *outfilename = get_outfilename(infilename, ". "); /* Placeholder until we know what the actual suffix is */ - size_t infilename_length; - - if(0 == outfilename) { - flac__utils_printf(stderr, 1, "ERROR: filename too long: %s", infilename); - return 1; - } - - if(!option_values.analyze && !option_values.test_only &&(option_values.keep_foreign_metadata || option_values.keep_foreign_metadata_if_present)) { - const char *error; - if(0 == strcmp(infilename, "-") || 0 == strcmp(outfilename, "-")) - return usage_error("ERROR: --keep-foreign-metadata cannot be used when decoding from stdin or to stdout\n"); - if(output_format == FORMAT_RAW) - return usage_error("ERROR: --keep-foreign-metadata cannot be used with raw output\n"); - decode_options.format_options.iff.foreign_metadata = 0; - /* initialize foreign metadata structure */ - foreign_metadata = flac__foreign_metadata_new(FOREIGN_BLOCK_TYPE__RIFF); /* RIFF is just a placeholder */ - if(0 == foreign_metadata) { - flac__utils_printf(stderr, 1, "ERROR: creating foreign metadata object\n"); - return 1; - } - if(!flac__foreign_metadata_read_from_flac(foreign_metadata, infilename, &error)) { - if(option_values.keep_foreign_metadata_if_present) { - flac__utils_printf(stderr, 1, "%s: WARNING reading foreign metadata: %s\n", infilename, error); - if(option_values.treat_warnings_as_errors) { - flac__foreign_metadata_delete(foreign_metadata); - return 1; - } - else { - /* Couldn't find foreign metadata, stop processing */ - flac__foreign_metadata_delete(foreign_metadata); - foreign_metadata = 0; - } - } - else { - flac__utils_printf(stderr, 1, "%s: ERROR reading foreign metadata: %s\n", infilename, error); - flac__foreign_metadata_delete(foreign_metadata); - return 1; - } - } - } - - if(option_values.force_raw_format) - output_format = FORMAT_RAW; - else if( - option_values.force_aiff_format || - (strlen(outfilename) >= 4 && 0 == FLAC__STRCASECMP(outfilename+(strlen(outfilename)-4), ".aif")) || - (strlen(outfilename) >= 5 && 0 == FLAC__STRCASECMP(outfilename+(strlen(outfilename)-5), ".aiff")) - ) - output_format = FORMAT_AIFF; - else if( - option_values.force_rf64_format || - (strlen(outfilename) >= 5 && 0 == FLAC__STRCASECMP(outfilename+(strlen(outfilename)-5), ".rf64")) - ) - output_format = FORMAT_RF64; - else if( - option_values.force_wave64_format || - (strlen(outfilename) >= 4 && 0 == FLAC__STRCASECMP(outfilename+(strlen(outfilename)-4), ".w64")) - ) - output_format = FORMAT_WAVE64; - else if(foreign_metadata != NULL) { - /* Pick a format based on what the foreign metadata contains */ - if(foreign_metadata->type == FOREIGN_BLOCK_TYPE__WAVE64) - output_format = FORMAT_WAVE64; - else if(foreign_metadata->is_rf64) - output_format = FORMAT_RF64; - else if(foreign_metadata->type == FOREIGN_BLOCK_TYPE__AIFF) { - output_format = FORMAT_AIFF; - if(foreign_metadata->is_aifc) { - output_format = FORMAT_AIFF_C; - } - } - else - output_format = FORMAT_WAVE; - } - else - output_format = FORMAT_WAVE; - - /* Now do subformats */ - if(option_values.force_legacy_wave_format) - output_subformat = SUBFORMAT_WAVE_PCM; - else if(option_values.force_extensible_wave_format) - output_subformat = SUBFORMAT_WAVE_EXTENSIBLE; - else if(option_values.force_aiff_c_none_format) { - output_format = FORMAT_AIFF_C; - output_subformat = SUBFORMAT_AIFF_C_NONE; - } - else if(option_values.force_aiff_c_sowt_format) { - output_format = FORMAT_AIFF_C; - output_subformat = SUBFORMAT_AIFF_C_SOWT; - } - else if(foreign_metadata != NULL) { - if(foreign_metadata->is_wavefmtex) - output_subformat = SUBFORMAT_WAVE_EXTENSIBLE; - else if(output_format == FORMAT_WAVE) - output_subformat = SUBFORMAT_WAVE_PCM; - else if(foreign_metadata->is_aifc) { - if(foreign_metadata->is_sowt) - output_subformat = SUBFORMAT_AIFF_C_SOWT; - else - output_subformat = SUBFORMAT_AIFF_C_NONE; - } - } - - - /* Check whether output format agrees with foreign metadata */ - if(foreign_metadata != NULL) { - if((output_format != FORMAT_WAVE && output_format != FORMAT_RF64) && foreign_metadata->type == FOREIGN_BLOCK_TYPE__RIFF) { - flac__foreign_metadata_delete(foreign_metadata); - return usage_error("ERROR: foreign metadata type RIFF cannot be restored to a%s file, only to WAVE and RF64\n",FileFormatString[output_format]); - } - if((output_format != FORMAT_AIFF && output_format != FORMAT_AIFF_C) && foreign_metadata->type == FOREIGN_BLOCK_TYPE__AIFF) { - flac__foreign_metadata_delete(foreign_metadata); - return usage_error("ERROR: foreign metadata type AIFF cannot be restored to a%s file, only to AIFF and AIFF-C\n",FileFormatString[output_format]); - } - if(output_format != FORMAT_WAVE64 && foreign_metadata->type == FOREIGN_BLOCK_TYPE__WAVE64) { - flac__foreign_metadata_delete(foreign_metadata); - return usage_error("ERROR: foreign metadata type Wave64 cannot be restored to a%s file, only to Wave64\n",FileFormatString[output_format]); - } - } - - /* Now reassemble outfilename */ - get_decoded_outfilename(infilename, output_format); - - /* - * Error if output file already exists (and -f not used). - * Use grabbag__file_get_filesize() as a cheap way to check. - */ - if(!option_values.test_only && !option_values.force_file_overwrite && strcmp(outfilename, "-") && grabbag__file_get_filesize(outfilename) != (FLAC__off_t)(-1)) { - flac__utils_printf(stderr, 1, "ERROR: output file %s already exists, use -f to override\n", outfilename); - flac__foreign_metadata_delete(foreign_metadata); - return 1; - } - - if(!option_values.test_only && !option_values.analyze) { - if(output_format == FORMAT_RAW && (option_values.format_is_big_endian < 0 || option_values.format_is_unsigned_samples < 0)) { - flac__foreign_metadata_delete(foreign_metadata); - return usage_error("ERROR: for decoding to a raw file you must specify a value for --endian and --sign\n"); - } - } - - infilename_length = strlen(infilename); - if(option_values.use_ogg) - treat_as_ogg = true; - else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".oga")) - treat_as_ogg = true; - else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".ogg")) - treat_as_ogg = true; - else - treat_as_ogg = false; - -#if !FLAC__HAS_OGG - if(treat_as_ogg) { - flac__utils_printf(stderr, 1, "%s: Ogg support has not been built into this copy of flac\n", infilename); - flac__foreign_metadata_delete(foreign_metadata); - return 1; - } -#endif - - if(!flac__utils_parse_skip_until_specification(option_values.skip_specification, &decode_options.skip_specification) || decode_options.skip_specification.is_relative) { - flac__foreign_metadata_delete(foreign_metadata); - return usage_error("ERROR: invalid value for --skip\n"); - } - - if(!flac__utils_parse_skip_until_specification(option_values.until_specification, &decode_options.until_specification)) { /*@@@ more checks: no + without --skip, no - unless known total_samples_to_{en,de}code */ - flac__foreign_metadata_delete(foreign_metadata); - return usage_error("ERROR: invalid value for --until\n"); - } - /* if there is no "--until" we want to default to "--until=-0" */ - if(0 == option_values.until_specification) - decode_options.until_specification.is_relative = true; - - if(option_values.cue_specification) { - if(!flac__utils_parse_cue_specification(option_values.cue_specification, &decode_options.cue_specification)) { - flac__foreign_metadata_delete(foreign_metadata); - return usage_error("ERROR: invalid value for --cue\n"); - } - decode_options.has_cue_specification = true; - } - else - decode_options.has_cue_specification = false; - - decode_options.treat_warnings_as_errors = option_values.treat_warnings_as_errors; - decode_options.continue_through_decode_errors = option_values.continue_through_decode_errors; - decode_options.relaxed_foreign_metadata_handling = option_values.keep_foreign_metadata_if_present; - decode_options.replaygain_synthesis_spec = option_values.replaygain_synthesis_spec; - decode_options.force_subformat = output_subformat; -#if FLAC__HAS_OGG - decode_options.is_ogg = treat_as_ogg; - decode_options.use_first_serial_number = !option_values.has_serial_number; - decode_options.serial_number = option_values.serial_number; -#endif - decode_options.channel_map_none = option_values.channel_map_none; - decode_options.format = output_format; - - if(output_format == FORMAT_RAW) { - decode_options.format_options.raw.is_big_endian = option_values.format_is_big_endian; - decode_options.format_options.raw.is_unsigned_samples = option_values.format_is_unsigned_samples; - - retval = flac__decode_file(infilename, option_values.test_only? 0 : outfilename, option_values.analyze, option_values.aopts, decode_options); - } - else { - decode_options.format_options.iff.foreign_metadata = foreign_metadata; - - retval = flac__decode_file(infilename, option_values.test_only? 0 : outfilename, option_values.analyze, option_values.aopts, decode_options); - - } - - if(foreign_metadata) - flac__foreign_metadata_delete(foreign_metadata); - - if(retval == 0 && strcmp(infilename, "-")) { - if(option_values.preserve_modtime && strcmp(outfilename, "-")) - grabbag__file_copy_metadata(infilename, outfilename); - if(option_values.delete_input && !option_values.test_only && !option_values.analyze) - flac_unlink(infilename); - } - - return retval; -} - -const char *get_encoded_outfilename(const char *infilename) -{ - const char *suffix = (option_values.use_ogg? ".oga" : ".flac"); - const char *p; - - if(option_values.output_prefix) { - p = grabbag__file_get_basename(infilename); - } - else { - p = infilename; - } - - return get_outfilename(p, suffix); -} - -const char *get_decoded_outfilename(const char *infilename, const FileFormat format) -{ - const char *suffix; - const char *p; - - if(option_values.output_prefix) { - p = grabbag__file_get_basename(infilename); - } - else { - p = infilename; - } - - if(option_values.analyze) { - suffix = ".ana"; - } - else if(format == FORMAT_RAW) { - suffix = ".raw"; - } - else if(format == FORMAT_AIFF) { - suffix = ".aiff"; - } - else if(format == FORMAT_AIFF_C) { - suffix = ".aifc"; - } - else if(format == FORMAT_RF64) { - suffix = ".rf64"; - } - else if(format == FORMAT_WAVE64) { - suffix = ".w64"; - } - else { - suffix = ".wav"; - } - return get_outfilename(p, suffix); -} - -const char *get_outfilename(const char *infilename, const char *suffix) -{ - if(0 == option_values.cmdline_forced_outfilename) { - static char buffer[4096]; - - if(0 == strcmp(infilename, "-") || option_values.force_to_stdout) { - buffer [0] = '-'; - buffer [1] = 0; - } - else { - char *p; - if (flac__strlcpy(buffer, option_values.output_prefix? option_values.output_prefix : "", sizeof buffer) >= sizeof buffer) - return 0; - if (flac__strlcat(buffer, infilename, sizeof buffer) >= sizeof buffer) - return 0; - /* the . must come after any / to avoid problems with, e.g. "some.directory/extensionless-filename" */ - if(0 == (p = strrchr(buffer, '.')) || strchr(p, '/')) { - if (flac__strlcat(buffer, suffix, sizeof buffer) >= sizeof buffer) - return 0; - } - else { - *p = '\0'; - if (flac__strlcat(buffer, suffix, sizeof buffer) >= sizeof buffer) - return 0; - } - } - return buffer; - } - else - return option_values.cmdline_forced_outfilename; -} - -void die(const char *message) -{ - FLAC__ASSERT(0 != message); - flac__utils_printf(stderr, 1, "ERROR: %s\n", message); - exit(1); -} - -int conditional_fclose(FILE *f) -{ - if(f == 0 || f == stdin || f == stdout) - return 0; - else - return fclose(f); -} - -char *local_strdup(const char *source) -{ - char *ret; - FLAC__ASSERT(0 != source); - if(0 == (ret = strdup(source))) - die("out of memory during strdup()"); - return ret; -} diff --git a/flac/src/flac/utils.c b/flac/src/flac/utils.c deleted file mode 100644 index 446150d..0000000 --- a/flac/src/flac/utils.c +++ /dev/null @@ -1,439 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include "utils.h" -#include "FLAC/assert.h" -#include "FLAC/metadata.h" -#include "share/compat.h" -#ifndef _WIN32 -#ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE -#endif -#include -#ifdef HAVE_TERMIOS_H -# include -#endif -#ifdef HAVE_SYS_IOCTL_H -# include -#endif -#endif - -const char *CHANNEL_MASK_TAG = "WAVEFORMATEXTENSIBLE_CHANNEL_MASK"; - -int flac__utils_verbosity_ = 2; - -static FLAC__bool local__parse_uint64_(const char *s, FLAC__uint64 *value) -{ - FLAC__uint64 ret = 0; - char c; - - if(*s == '\0') - return false; - - while('\0' != (c = *s++)) - if(c >= '0' && c <= '9') { - if(ret > UINT64_MAX / 10) /* check for overflow */ - return false; - else if(ret == UINT64_MAX / 10) { - FLAC__uint64 tmp = ret; - ret = ret * 10 + (c - '0'); - if(ret < tmp) - return false; - } - else - ret = ret * 10 + (c - '0'); - } - else - return false; - - *value = ret; - return true; -} - -static FLAC__bool local__parse_timecode_(const char *s, double *value) -{ - double ret; - uint32_t i; - char c, *endptr; - - /* parse [0-9][0-9]*: */ - c = *s++; - if(c >= '0' && c <= '9') - i = (c - '0'); - else - return false; - while(':' != (c = *s++)) { - if(c >= '0' && c <= '9') - i = i * 10 + (c - '0'); - else - return false; - } - ret = (double)i * 60.; - - /* parse [0-9]*[.,]?[0-9]* i.e. a sign-less rational number (. or , OK for fractional seconds, to support different locales) */ - if(strspn(s, "1234567890.,") != strlen(s)) - return false; - ret += strtod(s, &endptr); - if (endptr == s || *endptr) - return false; - - *value = ret; - return true; -} - -static FLAC__bool local__parse_cue_(const char *s, const char *end, uint32_t *track, uint32_t *indx) -{ - FLAC__bool got_track = false, got_index = false; - uint32_t t = 0, i = 0; - char c; - - while(end? s < end : *s != '\0') { - c = *s++; - if(c >= '0' && c <= '9') { - t = t * 10 + (c - '0'); - got_track = true; - } - else if(c == '.') - break; - else - return false; - } - while(end? s < end : *s != '\0') { - c = *s++; - if(c >= '0' && c <= '9') { - i = i * 10 + (c - '0'); - got_index = true; - } - else - return false; - } - *track = t; - *indx = i; - return got_track && got_index; -} - -/* - * this only works with sorted cuesheets (the spec strongly recommends but - * does not require sorted cuesheets). but if it's not sorted, picking a - * nearest cue point has no significance. - */ -static FLAC__uint64 local__find_closest_cue_(const FLAC__StreamMetadata_CueSheet *cuesheet, uint32_t track, uint32_t indx, FLAC__uint64 total_samples, FLAC__bool look_forward) -{ - int t, i; - if(look_forward) { - for(t = 0; t < (int)cuesheet->num_tracks; t++) - for(i = 0; i < (int)cuesheet->tracks[t].num_indices; i++) - if(cuesheet->tracks[t].number > track || (cuesheet->tracks[t].number == track && cuesheet->tracks[t].indices[i].number >= indx)) - return cuesheet->tracks[t].offset + cuesheet->tracks[t].indices[i].offset; - return total_samples; - } - else { - for(t = (int)cuesheet->num_tracks - 1; t >= 0; t--) - for(i = (int)cuesheet->tracks[t].num_indices - 1; i >= 0; i--) - if(cuesheet->tracks[t].number < track || (cuesheet->tracks[t].number == track && cuesheet->tracks[t].indices[i].number <= indx)) - return cuesheet->tracks[t].offset + cuesheet->tracks[t].indices[i].offset; - return 0; - } -} - -void flac__utils_printf(FILE *stream, int level, const char *format, ...) -{ - if(flac__utils_verbosity_ >= level) { - va_list args; - - FLAC__ASSERT(0 != format); - - va_start(args, format); - - (void) flac_vfprintf(stream, format, args); - - va_end(args); - -#ifdef _MSC_VER - if(stream == stderr) - fflush(stream); /* for some reason stderr is buffered in at least some if not all MSC libs */ -#endif - } -} - -/* variables and functions for console status output */ -static FLAC__bool is_name_printed; -static int stats_char_count = 0; -static int console_width; -static int console_chars_left; - -int get_console_width(void) -{ - int width = 0; -#if defined _WIN32 - width = win_get_console_width(); -#elif defined __EMX__ - int s[2]; - _scrsize (s); - width = s[0]; -#elif defined TIOCGWINSZ - struct winsize w; - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1) - width = w.ws_col; -#endif - if (width <= 0) - width = 80; - return width; -} - -size_t strlen_console(const char *text) -{ -#ifdef _WIN32 - return strlen_utf8(text); -#elif defined(__DJGPP__) /* workaround for DJGPP missing wcswidth() */ - return strlen(text); -#else - size_t len; - wchar_t *wtmp; - - len = strlen(text)+1; - wtmp = (wchar_t *)malloc(len*sizeof(wchar_t)); - if (wtmp == NULL) return len-1; - mbstowcs(wtmp, text, len); - len = wcswidth(wtmp, len); - free(wtmp); - - return len; -#endif -} - -void stats_new_file(void) -{ - is_name_printed = false; -} - -void stats_clear(void) -{ - while (stats_char_count > 0 && stats_char_count--) - fprintf(stderr, "\b"); -} - -void stats_print_name(int level, const char *name) -{ - int len; - - if (flac__utils_verbosity_ >= level) { - stats_clear(); - if(is_name_printed) return; - - console_width = get_console_width(); - len = strlen_console(name)+2; - console_chars_left = console_width - (len % console_width); - flac_fprintf(stderr, "%s: ", name); - is_name_printed = true; - } -} - -void stats_print_info(int level, const char *format, ...) -{ - char tmp[80]; - int len, clear_len; - - if (flac__utils_verbosity_ >= level) { - va_list args; - va_start(args, format); - len = flac_vsnprintf(tmp, sizeof(tmp), format, args); - va_end(args); - stats_clear(); - if (len >= console_chars_left) { - clear_len = console_chars_left; - while (clear_len > 0 && clear_len--) fprintf(stderr, " "); - fprintf(stderr, "\n"); - console_chars_left = console_width; - } - stats_char_count = fprintf(stderr, "%s", tmp); - fflush(stderr); - } -} - -#ifdef FLAC__VALGRIND_TESTING -size_t flac__utils_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) -{ - size_t ret = fwrite(ptr, size, nmemb, stream); - if(!ferror(stream)) - fflush(stream); - return ret; -} -#endif - -FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__SkipUntilSpecification *spec) -{ - FLAC__uint64 val; - FLAC__bool is_negative = false; - - FLAC__ASSERT(0 != spec); - - spec->is_relative = false; - spec->value_is_samples = true; - spec->value.samples = 0; - - if(0 != s) { - if(s[0] == '-') { - is_negative = true; - spec->is_relative = true; - s++; - } - else if(s[0] == '+') { - spec->is_relative = true; - s++; - } - - if(local__parse_uint64_(s, &val)) { - spec->value_is_samples = true; - if(val > INT64_MAX) - return false; - spec->value.samples = (FLAC__int64)val; - if(is_negative) - spec->value.samples = -(spec->value.samples); - } - else { - double d; - if(!local__parse_timecode_(s, &d)) - return false; - spec->value_is_samples = false; - spec->value.seconds = d; - if(is_negative) - spec->value.seconds = -(spec->value.seconds); - } - } - - return true; -} - -FLAC__bool flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, uint32_t sample_rate) -{ - FLAC__ASSERT(0 != spec); - if(!spec->value_is_samples) { - double samples = spec->value.seconds * (double)sample_rate; - if(samples >= (double)INT64_MAX || samples <= (double)INT64_MIN) - return false; - spec->value.samples = (FLAC__int64)(samples); - spec->value_is_samples = true; - } - return true; -} - -FLAC__bool flac__utils_parse_cue_specification(const char *s, utils__CueSpecification *spec) -{ - const char *start = s, *end = 0; - - FLAC__ASSERT(0 != spec); - - spec->has_start_point = spec->has_end_point = false; - - s = strchr(s, '-'); - - if(0 != s) { - if(s == start) - start = 0; - end = s+1; - if(*end == '\0') - end = 0; - } - - if(start) { - if(!local__parse_cue_(start, s, &spec->start_track, &spec->start_index)) - return false; - spec->has_start_point = true; - } - - if(end) { - if(!local__parse_cue_(end, 0, &spec->end_track, &spec->end_index)) - return false; - spec->has_end_point = true; - } - - return true; -} - -void flac__utils_canonicalize_cue_specification(const utils__CueSpecification *cue_spec, const FLAC__StreamMetadata_CueSheet *cuesheet, FLAC__uint64 total_samples, utils__SkipUntilSpecification *skip_spec, utils__SkipUntilSpecification *until_spec) -{ - FLAC__ASSERT(0 != cue_spec); - FLAC__ASSERT(0 != cuesheet); - FLAC__ASSERT(0 != total_samples); - FLAC__ASSERT(0 != skip_spec); - FLAC__ASSERT(0 != until_spec); - - skip_spec->is_relative = false; - skip_spec->value_is_samples = true; - - until_spec->is_relative = false; - until_spec->value_is_samples = true; - - if(cue_spec->has_start_point) - skip_spec->value.samples = local__find_closest_cue_(cuesheet, cue_spec->start_track, cue_spec->start_index, total_samples, /*look_forward=*/false); - else - skip_spec->value.samples = 0; - - if(cue_spec->has_end_point) - until_spec->value.samples = local__find_closest_cue_(cuesheet, cue_spec->end_track, cue_spec->end_index, total_samples, /*look_forward=*/true); - else - until_spec->value.samples = total_samples; -} - -FLAC__bool flac__utils_set_channel_mask_tag(FLAC__StreamMetadata *object, FLAC__uint32 channel_mask) -{ - FLAC__StreamMetadata_VorbisComment_Entry entry = { 0, 0 }; - char tag[128]; - - FLAC__ASSERT(object); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(strlen(CHANNEL_MASK_TAG)+1+2+16+1 <= sizeof(tag)); /* +1 for =, +2 for 0x, +16 for digits, +1 for NUL */ - entry.entry = (FLAC__byte*)tag; - if((entry.length = flac_snprintf(tag, sizeof(tag), "%s=0x%04X", CHANNEL_MASK_TAG, (uint32_t)channel_mask)) >= sizeof(tag)) - return false; - if(!FLAC__metadata_object_vorbiscomment_replace_comment(object, entry, /*all=*/true, /*copy=*/true)) - return false; - return true; -} - -FLAC__bool flac__utils_get_channel_mask_tag(const FLAC__StreamMetadata *object, FLAC__uint32 *channel_mask) -{ - int offset; - uint32_t val; - char *p; - FLAC__ASSERT(object); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - if(0 > (offset = FLAC__metadata_object_vorbiscomment_find_entry_from(object, /*offset=*/0, CHANNEL_MASK_TAG))) - return false; - if(object->data.vorbis_comment.comments[offset].length < strlen(CHANNEL_MASK_TAG)+4) - return false; - if(0 == (p = strchr((const char *)object->data.vorbis_comment.comments[offset].entry, '='))) /* should never happen, but just in case */ - return false; - if(FLAC__STRNCASECMP(p, "=0x", 3)) - return false; - if(sscanf(p+3, "%x", &val) != 1) - return false; - *channel_mask = val; - return true; -} diff --git a/flac/src/flac/utils.h b/flac/src/flac/utils.h deleted file mode 100644 index 931b4a6..0000000 --- a/flac/src/flac/utils.h +++ /dev/null @@ -1,77 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 flac__utils_h -#define flac__utils_h - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "FLAC/ordinals.h" -#include "FLAC/format.h" /* for FLAC__StreamMetadata_CueSheet */ -#include /* for FILE */ - -typedef enum { FORMAT_RAW, FORMAT_WAVE, FORMAT_WAVE64, FORMAT_RF64, FORMAT_AIFF, FORMAT_AIFF_C, FORMAT_FLAC, FORMAT_OGGFLAC } FileFormat; -static const char * const FileFormatString[] = { " raw", " WAVE", " Wave64", "n RF64", "n AIFF", "n AIFF-C", " FLAC", "n Ogg FLAC" }; - -typedef enum { SUBFORMAT_UNSPECIFIED = 0, SUBFORMAT_WAVE_PCM, SUBFORMAT_WAVE_EXTENSIBLE, SUBFORMAT_AIFF_C_NONE, SUBFORMAT_AIFF_C_SOWT } FileSubFormat; - - -typedef struct { - FLAC__bool is_relative; /* i.e. specification string started with + or - */ - FLAC__bool value_is_samples; - union { - double seconds; - FLAC__int64 samples; - } value; -} utils__SkipUntilSpecification; - -typedef struct { - FLAC__bool has_start_point, has_end_point; - unsigned start_track, start_index; - unsigned end_track, end_index; -} utils__CueSpecification; - -#ifdef FLAC__VALGRIND_TESTING -size_t flac__utils_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); -#else -#define flac__utils_fwrite fwrite -#endif - -extern int flac__utils_verbosity_; -void flac__utils_printf(FILE *stream, int level, const char *format, ...); - -int get_console_width(void); -size_t strlen_console(const char *text); -void stats_new_file(void); -void stats_clear(void); -void stats_print_name(int level, const char *name); -void stats_print_info(int level, const char *format, ...); - -FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__SkipUntilSpecification *spec); -FLAC__bool flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, uint32_t sample_rate); - -FLAC__bool flac__utils_parse_cue_specification(const char *s, utils__CueSpecification *spec); -void flac__utils_canonicalize_cue_specification(const utils__CueSpecification *cue_spec, const FLAC__StreamMetadata_CueSheet *cuesheet, FLAC__uint64 total_samples, utils__SkipUntilSpecification *skip_spec, utils__SkipUntilSpecification *until_spec); - -FLAC__bool flac__utils_set_channel_mask_tag(FLAC__StreamMetadata *object, FLAC__uint32 channel_mask); -FLAC__bool flac__utils_get_channel_mask_tag(const FLAC__StreamMetadata *object, FLAC__uint32 *channel_mask); - -#endif diff --git a/flac/src/flac/version.rc b/flac/src/flac/version.rc deleted file mode 100644 index 00842b9..0000000 --- a/flac/src/flac/version.rc +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include "config.h" - -#if (defined GIT_COMMIT_HASH && defined GIT_COMMIT_DATE) -# ifdef GIT_COMMIT_TAG -# define VERSIONSTRING GIT_COMMIT_TAG -# else -# define VERSIONSTRING "git-" GIT_COMMIT_HASH -# endif -#else -# define VERSIONSTRING PACKAGE_VERSION -#endif - -#define xstr(s) str(s) -#define str(s) #s - -VS_VERSION_INFO VERSIONINFO -FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -FILEFLAGS 0 -FILEOS VOS__WINDOWS32 -FILETYPE VFT_DLL -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "FileDescription", "flac command line tool for Windows" - VALUE "ProductName", "Free Lossless Audio Codec" - VALUE "ProductVersion", VERSIONSTRING - VALUE "CompanyName", "Xiph.Org" - VALUE "LegalCopyright", "2000-2009 Josh Coalson, 2011-2023 Xiph.Org Foundation" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END diff --git a/flac/src/flac/vorbiscomment.c b/flac/src/flac/vorbiscomment.c deleted file mode 100644 index 3941ec2..0000000 --- a/flac/src/flac/vorbiscomment.c +++ /dev/null @@ -1,254 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "vorbiscomment.h" -#include "FLAC/assert.h" -#include "FLAC/metadata.h" -#include "share/grabbag.h" /* for grabbag__file_get_filesize() */ -#include "share/utf8.h" -#include -#include -#include -#include -#include "share/compat.h" - - -/* - * This struct and the following 4 static functions are copied from - * ../metaflac/. Maybe someday there will be a convenience - * library for Vorbis comment parsing. - */ -typedef struct { - char *field; /* the whole field as passed on the command line, i.e. "NAME=VALUE" */ - char *field_name; - /* according to the vorbis spec, field values can contain \0 so simple C strings are not enough here */ - uint32_t field_value_length; - char *field_value; - FLAC__bool field_value_from_file; /* true if field_value holds a filename for the value, false for plain value */ -} Argument_VcField; - -static void die(const char *message) -{ - FLAC__ASSERT(0 != message); - fprintf(stderr, "ERROR: %s\n", message); - exit(1); -} - -static char *local_strdup(const char *source) -{ - char *ret; - FLAC__ASSERT(0 != source); - if(0 == (ret = strdup(source))) - die("out of memory during strdup()"); - return ret; -} - -static FLAC__bool parse_vorbis_comment_field(const char *field_ref, char **field, char **name, char **value, uint32_t *length, const char **violation) -{ - static const char * const violations[] = { - "field name contains invalid character", - "field contains no '=' character" - }; - - char *p, *q, *s; - - if(0 != field) - *field = local_strdup(field_ref); - - s = local_strdup(field_ref); - - if(0 == (p = strchr(s, '='))) { - free(s); - *violation = violations[1]; - return false; - } - *p++ = '\0'; - - for(q = s; *q; q++) { - if(*q < 0x20 || *q > 0x7d || *q == 0x3d) { - free(s); - *violation = violations[0]; - return false; - } - } - - *name = local_strdup(s); - *value = local_strdup(p); - *length = strlen(p); - - free(s); - return true; -} - -/* slight modification: no 'filename' arg, and errors are passed back in 'violation' instead of printed to stderr */ -static FLAC__bool set_vc_field(FLAC__StreamMetadata *block, const Argument_VcField *field, FLAC__bool *needs_write, FLAC__bool raw, const char **violation) -{ - FLAC__StreamMetadata_VorbisComment_Entry entry; - char *converted = NULL; - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(0 != field); - FLAC__ASSERT(0 != needs_write); - - if(field->field_value_from_file) { - /* read the file into 'data' */ - FILE *f = 0; - char *data = 0; - const FLAC__off_t size = grabbag__file_get_filesize(field->field_value); - if(size < 0) { - *violation = "can't open file for tag value"; - return false; - } - if(size >= 0x100000) { /* magic arbitrary limit, actual format limit is near 16MB */ - *violation = "file for tag value is too large"; - return false; - } - if(0 == (data = malloc(size+1))) - die("out of memory allocating tag value"); - data[size] = '\0'; - if(0 == (f = flac_fopen(field->field_value, "rb")) || fread(data, 1, size, f) != (size_t)size) { - free(data); - if(f) - fclose(f); - *violation = "error while reading file for tag value"; - return false; - } - fclose(f); - if(strlen(data) != (size_t)size) { - free(data); - *violation = "file for tag value has embedded NULs"; - return false; - } - - /* move 'data' into 'converted', converting to UTF-8 if necessary */ - if(raw) { - converted = data; - } - else if(utf8_encode(data, &converted) >= 0) { - free(data); - } - else { - free(data); - *violation = "error converting file contents to UTF-8 for tag value"; - return false; - } - - /* create and entry and append it */ - if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry, field->field_name, converted)) { - free(converted); - *violation = "file for tag value is not valid UTF-8"; - return false; - } - free(converted); - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) { - *violation = "memory allocation failure"; - return false; - } - - *needs_write = true; - return true; - } - else { - FLAC__bool needs_free = false; -#ifdef _WIN32 /* everything in UTF-8 already. Must not alter */ - entry.entry = (FLAC__byte *)field->field; -#else - if(raw) { - entry.entry = (FLAC__byte *)field->field; - } - else if(utf8_encode(field->field, &converted) >= 0) { - entry.entry = (FLAC__byte *)converted; - needs_free = true; - } - else { - *violation = "error converting comment to UTF-8"; - return false; - } -#endif - entry.length = strlen((const char *)entry.entry); - if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) { - if(needs_free) - free(converted); - /* - * our previous parsing has already established that the field - * name is OK, so it must be the field value - */ - *violation = "tag value is not valid UTF-8"; - return false; - } - - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) { - if(needs_free) - free(converted); - *violation = "memory allocation failure"; - return false; - } - - *needs_write = true; - if(needs_free) - free(converted); - return true; - } -} - -/* - * The rest of the code is novel - */ - -static void free_field(Argument_VcField *obj) -{ - if(0 != obj->field) - free(obj->field); - if(0 != obj->field_name) - free(obj->field_name); - if(0 != obj->field_value) - free(obj->field_value); -} - -FLAC__bool flac__vorbiscomment_add(FLAC__StreamMetadata *block, const char *comment, FLAC__bool value_from_file, FLAC__bool raw, const char **violation) -{ - Argument_VcField parsed; - FLAC__bool dummy; - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(0 != comment); - - memset(&parsed, 0, sizeof(parsed)); - - parsed.field_value_from_file = value_from_file; - if(!parse_vorbis_comment_field(comment, &(parsed.field), &(parsed.field_name), &(parsed.field_value), &(parsed.field_value_length), violation)) { - free_field(&parsed); - return false; - } - - if(parsed.field_value_length > 0 && !set_vc_field(block, &parsed, &dummy, raw, violation)) { - free_field(&parsed); - return false; - } - else { - free_field(&parsed); - return true; - } -} diff --git a/flac/src/flac/vorbiscomment.h b/flac/src/flac/vorbiscomment.h deleted file mode 100644 index a6dcb16..0000000 --- a/flac/src/flac/vorbiscomment.h +++ /dev/null @@ -1,27 +0,0 @@ -/* flac - Command-line FLAC encoder/decoder - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 flac__vorbiscomment_h -#define flac__vorbiscomment_h - -#include "FLAC/metadata.h" - -FLAC__bool flac__vorbiscomment_add(FLAC__StreamMetadata *block, const char *comment, FLAC__bool value_from_file, FLAC__bool raw, const char **violation); - -#endif diff --git a/flac/src/libFLAC++/CMakeLists.txt b/flac/src/libFLAC++/CMakeLists.txt deleted file mode 100644 index 3be43ba..0000000 --- a/flac/src/libFLAC++/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -add_library(FLAC++ - metadata.cpp - stream_decoder.cpp - stream_encoder.cpp - version.rc) -set_property(TARGET FLAC++ PROPERTY PROJECT_LABEL "libFLAC++") -target_compile_definitions(FLAC++ - PRIVATE $<$:FLACPP_API_EXPORTS> - PUBLIC $<$>:FLAC__NO_DLL>) -if(NOT WIN32) - target_compile_definitions(FLAC++ PRIVATE $<$:FLAC__USE_VISIBILITY_ATTR>) -endif() -target_include_directories(FLAC++ INTERFACE - "$" - "$") -target_link_libraries(FLAC++ PUBLIC FLAC) -if(BUILD_SHARED_LIBS) - set_target_properties(FLAC++ PROPERTIES - VERSION 10.0.1 - SOVERSION 10) - if(NOT WIN32) - set_target_properties(FLAC++ PROPERTIES CXX_VISIBILITY_PRESET hidden) - endif() -endif() - -add_library(FLAC::FLAC++ ALIAS FLAC++) - -install(TARGETS FLAC++ EXPORT targets - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/") - -if(INSTALL_PKGCONFIG_MODULES) - set(prefix "${CMAKE_INSTALL_PREFIX}") - set(exec_prefix "${CMAKE_INSTALL_PREFIX}") - set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") - set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") - configure_file(flac++.pc.in flac++.pc @ONLY) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/flac++.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") -endif() diff --git a/flac/src/libFLAC++/Makefile.am b/flac/src/libFLAC++/Makefile.am deleted file mode 100644 index 0b2853b..0000000 --- a/flac/src/libFLAC++/Makefile.am +++ /dev/null @@ -1,68 +0,0 @@ -# libFLAC++ - Free Lossless Audio Codec library -# Copyright (C) 2002-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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 Xiph.org Foundation 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 FOUNDATION 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. - -lib_LTLIBRARIES = libFLAC++.la -noinst_LTLIBRARIES = libFLAC++-static.la - -m4datadir = $(datadir)/aclocal -m4data_DATA = libFLAC++.m4 - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = flac++.pc -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include -EXTRA_DIST = \ - CMakeLists.txt \ - flac++.pc.in \ - libFLAC++.m4 \ - version.rc - -libFLAC___sources = \ - metadata.cpp \ - stream_decoder.cpp \ - stream_encoder.cpp - -if OS_IS_WINDOWS -if HAVE_WINDRES -libFLAC___la_DEPENDENCIES = version.o -windows_resource_link = -Wl,version.o -endif -endif - -# see 'http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning' for numbering convention -libFLAC___la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 10:1:0 $(windows_resource_link) -libFLAC___la_LIBADD = ../libFLAC/libFLAC.la -libFLAC___la_SOURCES = $(libFLAC___sources) - -libFLAC___static_la_SOURCES = $(libFLAC___sources) -libFLAC___static_la_LIBADD = ../libFLAC/libFLAC-static.la - -.rc.o: - $(RC) $(AM_CPPFLAGS) $< $@ diff --git a/flac/src/libFLAC++/flac++.pc.in b/flac/src/libFLAC++/flac++.pc.in deleted file mode 100644 index f09c251..0000000 --- a/flac/src/libFLAC++/flac++.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: FLAC++ -Description: Free Lossless Audio Codec Library (C++ API) -Version: @VERSION@ -Requires: flac -Libs: -L${libdir} -lFLAC++ -Cflags: -I${includedir} diff --git a/flac/src/libFLAC++/libFLAC++.m4 b/flac/src/libFLAC++/libFLAC++.m4 deleted file mode 100644 index e5e1345..0000000 --- a/flac/src/libFLAC++/libFLAC++.m4 +++ /dev/null @@ -1,114 +0,0 @@ -# Configure paths for libFLAC++ -# "Inspired" by ogg.m4 -# Caller must first run AM_PATH_LIBFLAC - -dnl AM_PATH_LIBFLACPP([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libFLAC++, and define LIBFLACPP_CFLAGS, LIBFLACPP_LIBS, LIBFLACPP_LIBDIR -dnl -AC_DEFUN([AM_PATH_LIBFLACPP], -[dnl -dnl Get the cflags and libraries -dnl -AC_ARG_WITH(libFLACPP,[ --with-libFLACPP=PFX Prefix where libFLAC++ is installed (optional)], libFLACPP_prefix="$withval", libFLACPP_prefix="") -AC_ARG_WITH(libFLACPP-libraries,[ --with-libFLACPP-libraries=DIR Directory where libFLAC++ library is installed (optional)], libFLACPP_libraries="$withval", libFLACPP_libraries="") -AC_ARG_WITH(libFLACPP-includes,[ --with-libFLACPP-includes=DIR Directory where libFLAC++ header files are installed (optional)], libFLACPP_includes="$withval", libFLACPP_includes="") -AC_ARG_ENABLE(libFLACPPtest, [ --disable-libFLACPPtest Do not try to compile and run a test libFLAC++ program],, enable_libFLACPPtest=yes) - - if test "x$libFLACPP_libraries" != "x" ; then - LIBFLACPP_LIBDIR="$libFLACPP_libraries" - elif test "x$libFLACPP_prefix" != "x" ; then - LIBFLACPP_LIBDIR="$libFLACPP_prefix/lib" - elif test "x$prefix" != "xNONE" ; then - LIBFLACPP_LIBDIR="$libdir" - fi - - LIBFLACPP_LIBS="-L$LIBFLACPP_LIBDIR -lFLAC++ $LIBFLAC_LIBS" - - if test "x$libFLACPP_includes" != "x" ; then - LIBFLACPP_CFLAGS="-I$libFLACPP_includes" - elif test "x$libFLACPP_prefix" != "x" ; then - LIBFLACPP_CFLAGS="-I$libFLACPP_prefix/include" - elif test "$prefix" != "xNONE"; then - LIBFLACPP_CFLAGS="" - fi - - LIBFLACPP_CFLAGS="$LIBFLACPP_CFLAGS $LIBFLAC_CFLAGS" - - AC_MSG_CHECKING(for libFLAC++) - no_libFLACPP="" - - - if test "x$enable_libFLACPPtest" = "xyes" ; then - ac_save_CFLAGS="$CFLAGS" - ac_save_CXXFLAGS="$CXXFLAGS" - ac_save_LIBS="$LIBS" - ac_save_LD_LIBRARY_PATH="$LD_LIBRARY_PATH" - CFLAGS="$CFLAGS $LIBFLACPP_CFLAGS" - CXXFLAGS="$CXXFLAGS $LIBFLACPP_CFLAGS" - LIBS="$LIBS $LIBFLACPP_LIBS" - LD_LIBRARY_PATH="$LIBFLACPP_LIBDIR:$LIBFLAC_LIBDIR:$LD_LIBRARY_PATH" -dnl -dnl Now check if the installed libFLAC++ is sufficiently new. -dnl - rm -f conf.libFLAC++test - AC_RUN_IFELSE([AC_LANG_PROGRAM([[ -#include -#include -#include -#include -]],[[ - system("touch conf.libFLAC++test"); - return 0; -]])],[],[no_libFLACPP=yes],[echo $ac_n "cross compiling; assumed OK... $ac_c"]) - - CFLAGS="$ac_save_CFLAGS" - CXXFLAGS="$ac_save_CXXFLAGS" - LIBS="$ac_save_LIBS" - LD_LIBRARY_PATH="$ac_save_LD_LIBRARY_PATH" - fi - - if test "x$no_libFLACPP" = "x" ; then - AC_MSG_RESULT(yes) - ifelse([$1], , :, [$1]) - else - AC_MSG_RESULT(no) - if test -f conf.libFLAC++test ; then - : - else - echo "*** Could not run libFLAC++ test program, checking why..." - CFLAGS="$CFLAGS $LIBFLACPP_CFLAGS" - CXXFLAGS="$CXXFLAGS $LIBFLACPP_CFLAGS" - LIBS="$LIBS $LIBFLACPP_LIBS" - LD_LIBRARY_PATH="$LIBFLACPP_LIBDIR:$LIBFLAC_LIBDIR:$LD_LIBRARY_PATH" - AC_TRY_LINK([ -#include -#include -], [ return 0; ], - [ echo "*** The test program compiled, but did not run. This usually means" - echo "*** that the run-time linker is not finding libFLAC++ or finding the wrong" - echo "*** version of libFLAC++. If it is not finding libFLAC++, 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 occurred. This usually means libFLAC++ was incorrectly installed" - echo "*** or that you have moved libFLAC++ since it was installed. In the latter case, you" - echo "*** may want to edit the libFLAC++-config script: $LIBFLACPP_CONFIG" ]) - CFLAGS="$ac_save_CFLAGS" - CXXFLAGS="$ac_save_CXXFLAGS" - LIBS="$ac_save_LIBS" - LD_LIBRARY_PATH="$ac_save_LD_LIBRARY_PATH" - fi - LIBFLACPP_CFLAGS="" - LIBFLACPP_LIBDIR="" - LIBFLACPP_LIBS="" - ifelse([$2], , :, [$2]) - fi - AC_SUBST(LIBFLACPP_CFLAGS) - AC_SUBST(LIBFLACPP_LIBDIR) - AC_SUBST(LIBFLACPP_LIBS) - rm -f conf.libFLAC++test -]) diff --git a/flac/src/libFLAC++/metadata.cpp b/flac/src/libFLAC++/metadata.cpp deleted file mode 100644 index beab110..0000000 --- a/flac/src/libFLAC++/metadata.cpp +++ /dev/null @@ -1,1745 +0,0 @@ -/* libFLAC++ - Free Lossless Audio Codec library - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#define __STDC_LIMIT_MACROS 1 /* otherwise SIZE_MAX is not defined for c++ */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "share/alloc.h" -#include "FLAC++/metadata.h" -#include "FLAC/assert.h" -#include // for malloc(), free() -#include // for memcpy() etc. - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -namespace FLAC { - namespace Metadata { - - // local utility routines - - namespace local { - - Prototype *construct_block(::FLAC__StreamMetadata *object) - { - if (0 == object) - return 0; - - Prototype *ret = 0; - switch(object->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - ret = new StreamInfo(object, /*copy=*/false); - break; - case FLAC__METADATA_TYPE_PADDING: - ret = new Padding(object, /*copy=*/false); - break; - case FLAC__METADATA_TYPE_APPLICATION: - ret = new Application(object, /*copy=*/false); - break; - case FLAC__METADATA_TYPE_SEEKTABLE: - ret = new SeekTable(object, /*copy=*/false); - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - ret = new VorbisComment(object, /*copy=*/false); - break; - case FLAC__METADATA_TYPE_CUESHEET: - ret = new CueSheet(object, /*copy=*/false); - break; - case FLAC__METADATA_TYPE_PICTURE: - ret = new Picture(object, /*copy=*/false); - break; - default: - ret = new Unknown(object, /*copy=*/false); - break; - } - return ret; - } - - } // namespace local - - FLACPP_API Prototype *clone(const Prototype *object) - { - FLAC__ASSERT(0 != object); - - const StreamInfo *streaminfo = dynamic_cast(object); - const Padding *padding = dynamic_cast(object); - const Application *application = dynamic_cast(object); - const SeekTable *seektable = dynamic_cast(object); - const VorbisComment *vorbiscomment = dynamic_cast(object); - const CueSheet *cuesheet = dynamic_cast(object); - const Picture *picture = dynamic_cast(object); - const Unknown *unknown = dynamic_cast(object); - - if(0 != streaminfo) - return new StreamInfo(*streaminfo); - if(0 != padding) - return new Padding(*padding); - if(0 != application) - return new Application(*application); - if(0 != seektable) - return new SeekTable(*seektable); - if(0 != vorbiscomment) - return new VorbisComment(*vorbiscomment); - if(0 != cuesheet) - return new CueSheet(*cuesheet); - if(0 != picture) - return new Picture(*picture); - if(0 != unknown) - return new Unknown(*unknown); - - FLAC__ASSERT(0); - return 0; - } - - // - // Prototype - // - - Prototype::Prototype(const Prototype &object): - object_(::FLAC__metadata_object_clone(object.object_)), - is_reference_(false) - { - FLAC__ASSERT(object.is_valid()); - } - - Prototype::Prototype(const ::FLAC__StreamMetadata &object): - object_(::FLAC__metadata_object_clone(&object)), - is_reference_(false) - { - } - - Prototype::Prototype(const ::FLAC__StreamMetadata *object): - object_(::FLAC__metadata_object_clone(object)), - is_reference_(false) - { - FLAC__ASSERT(0 != object); - } - - Prototype::Prototype(::FLAC__StreamMetadata *object, bool copy): - object_(copy? ::FLAC__metadata_object_clone(object) : object), - is_reference_(false) - { - FLAC__ASSERT(0 != object); - } - - Prototype::~Prototype() - { - clear(); - } - - void Prototype::clear() - { - if(0 != object_ && !is_reference_) - FLAC__metadata_object_delete(object_); - object_ = 0; - } - - Prototype &Prototype::operator=(const Prototype &object) - { - FLAC__ASSERT(object.is_valid()); - clear(); - is_reference_ = false; - object_ = ::FLAC__metadata_object_clone(object.object_); - return *this; - } - - Prototype &Prototype::operator=(const ::FLAC__StreamMetadata &object) - { - clear(); - is_reference_ = false; - object_ = ::FLAC__metadata_object_clone(&object); - return *this; - } - - Prototype &Prototype::operator=(const ::FLAC__StreamMetadata *object) - { - FLAC__ASSERT(0 != object); - clear(); - is_reference_ = false; - object_ = ::FLAC__metadata_object_clone(object); - return *this; - } - - Prototype &Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy) - { - FLAC__ASSERT(0 != object); - clear(); - object_ = (copy? ::FLAC__metadata_object_clone(object) : object); - is_reference_ = false; - return *this; - } - - bool Prototype::get_is_last() const - { - FLAC__ASSERT(is_valid()); - return static_cast(object_->is_last); - } - - FLAC__MetadataType Prototype::get_type() const - { - FLAC__ASSERT(is_valid()); - return object_->type; - } - - uint32_t Prototype::get_length() const - { - FLAC__ASSERT(is_valid()); - return object_->length; - } - - void Prototype::set_is_last(bool value) - { - FLAC__ASSERT(is_valid()); - object_->is_last = value; - } - - - // - // StreamInfo - // - - StreamInfo::StreamInfo(): - Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO), /*copy=*/false) - { } - - StreamInfo::~StreamInfo() - { } - - uint32_t StreamInfo::get_min_blocksize() const - { - FLAC__ASSERT(is_valid()); - return object_->data.stream_info.min_blocksize; - } - - uint32_t StreamInfo::get_max_blocksize() const - { - FLAC__ASSERT(is_valid()); - return object_->data.stream_info.max_blocksize; - } - - uint32_t StreamInfo::get_min_framesize() const - { - FLAC__ASSERT(is_valid()); - return object_->data.stream_info.min_framesize; - } - - uint32_t StreamInfo::get_max_framesize() const - { - FLAC__ASSERT(is_valid()); - return object_->data.stream_info.max_framesize; - } - - uint32_t StreamInfo::get_sample_rate() const - { - FLAC__ASSERT(is_valid()); - return object_->data.stream_info.sample_rate; - } - - uint32_t StreamInfo::get_channels() const - { - FLAC__ASSERT(is_valid()); - return object_->data.stream_info.channels; - } - - uint32_t StreamInfo::get_bits_per_sample() const - { - FLAC__ASSERT(is_valid()); - return object_->data.stream_info.bits_per_sample; - } - - FLAC__uint64 StreamInfo::get_total_samples() const - { - FLAC__ASSERT(is_valid()); - return object_->data.stream_info.total_samples; - } - - const FLAC__byte *StreamInfo::get_md5sum() const - { - FLAC__ASSERT(is_valid()); - return object_->data.stream_info.md5sum; - } - - void StreamInfo::set_min_blocksize(uint32_t value) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(value >= FLAC__MIN_BLOCK_SIZE); - FLAC__ASSERT(value <= FLAC__MAX_BLOCK_SIZE); - object_->data.stream_info.min_blocksize = value; - } - - void StreamInfo::set_max_blocksize(uint32_t value) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(value >= FLAC__MIN_BLOCK_SIZE); - FLAC__ASSERT(value <= FLAC__MAX_BLOCK_SIZE); - object_->data.stream_info.max_blocksize = value; - } - - void StreamInfo::set_min_framesize(uint32_t value) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(value < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN)); - object_->data.stream_info.min_framesize = value; - } - - void StreamInfo::set_max_framesize(uint32_t value) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(value < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN)); - object_->data.stream_info.max_framesize = value; - } - - void StreamInfo::set_sample_rate(uint32_t value) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(FLAC__format_sample_rate_is_valid(value)); - object_->data.stream_info.sample_rate = value; - } - - void StreamInfo::set_channels(uint32_t value) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(value > 0); - FLAC__ASSERT(value <= FLAC__MAX_CHANNELS); - object_->data.stream_info.channels = value; - } - - void StreamInfo::set_bits_per_sample(uint32_t value) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(value >= FLAC__MIN_BITS_PER_SAMPLE); - FLAC__ASSERT(value <= FLAC__MAX_BITS_PER_SAMPLE); - object_->data.stream_info.bits_per_sample = value; - } - - void StreamInfo::set_total_samples(FLAC__uint64 value) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(value < (((FLAC__uint64)1) << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN)); - object_->data.stream_info.total_samples = value; - } - - void StreamInfo::set_md5sum(const FLAC__byte value[16]) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(0 != value); - std::memcpy(object_->data.stream_info.md5sum, value, 16); - } - - - // - // Padding - // - - Padding::Padding(): - Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING), /*copy=*/false) - { } - - Padding::Padding(uint32_t length): - Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING), /*copy=*/false) - { - set_length(length); - } - - Padding::~Padding() - { } - - void Padding::set_length(uint32_t length) - { - FLAC__ASSERT(is_valid()); - object_->length = length; - } - - - // - // Application - // - - Application::Application(): - Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION), /*copy=*/false) - { } - - Application::~Application() - { } - - const FLAC__byte *Application::get_id() const - { - FLAC__ASSERT(is_valid()); - return object_->data.application.id; - } - - const FLAC__byte *Application::get_data() const - { - FLAC__ASSERT(is_valid()); - return object_->data.application.data; - } - - void Application::set_id(const FLAC__byte value[4]) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(0 != value); - std::memcpy(object_->data.application.id, value, 4); - } - - bool Application::set_data(const FLAC__byte *data, uint32_t length) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_application_set_data(object_, const_cast(data), length, true)); - } - - bool Application::set_data(FLAC__byte *data, uint32_t length, bool copy) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_application_set_data(object_, data, length, copy)); - } - - - // - // SeekTable - // - - SeekTable::SeekTable(): - Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE), /*copy=*/false) - { } - - SeekTable::~SeekTable() - { } - - uint32_t SeekTable::get_num_points() const - { - FLAC__ASSERT(is_valid()); - return object_->data.seek_table.num_points; - } - - ::FLAC__StreamMetadata_SeekPoint SeekTable::get_point(uint32_t indx) const - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(indx < object_->data.seek_table.num_points); - return object_->data.seek_table.points[indx]; - } - - bool SeekTable::resize_points(uint32_t new_num_points) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_seektable_resize_points(object_, new_num_points)); - } - - void SeekTable::set_point(uint32_t indx, const ::FLAC__StreamMetadata_SeekPoint &point) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(indx < object_->data.seek_table.num_points); - ::FLAC__metadata_object_seektable_set_point(object_, indx, point); - } - - bool SeekTable::insert_point(uint32_t indx, const ::FLAC__StreamMetadata_SeekPoint &point) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(indx <= object_->data.seek_table.num_points); - return static_cast(::FLAC__metadata_object_seektable_insert_point(object_, indx, point)); - } - - bool SeekTable::delete_point(uint32_t indx) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(indx < object_->data.seek_table.num_points); - return static_cast(::FLAC__metadata_object_seektable_delete_point(object_, indx)); - } - - bool SeekTable::is_legal() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_seektable_is_legal(object_)); - } - - bool SeekTable::template_append_placeholders(uint32_t num) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_seektable_template_append_placeholders(object_, num)); - } - - bool SeekTable::template_append_point(FLAC__uint64 sample_number) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_seektable_template_append_point(object_, sample_number)); - } - - bool SeekTable::template_append_points(FLAC__uint64 sample_numbers[], uint32_t num) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_seektable_template_append_points(object_, sample_numbers, num)); - } - - bool SeekTable::template_append_spaced_points(uint32_t num, FLAC__uint64 total_samples) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_seektable_template_append_spaced_points(object_, num, total_samples)); - } - - bool SeekTable::template_append_spaced_points_by_samples(uint32_t samples, FLAC__uint64 total_samples) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(object_, samples, total_samples)); - } - - bool SeekTable::template_sort(bool compact) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_seektable_template_sort(object_, compact)); - } - - - // - // VorbisComment::Entry - // - - VorbisComment::Entry::Entry() : - is_valid_(true), - entry_(), - field_name_(0), - field_name_length_(0), - field_value_(0), - field_value_length_(0) - { - zero(); - } - - VorbisComment::Entry::Entry(const char *field, uint32_t field_length) : - is_valid_(true), - entry_(), - field_name_(0), - field_name_length_(0), - field_value_(0), - field_value_length_(0) - { - zero(); - construct(field, field_length); - } - - VorbisComment::Entry::Entry(const char *field) : - is_valid_(true), - entry_(), - field_name_(0), - field_name_length_(0), - field_value_(0), - field_value_length_(0) - { - zero(); - construct(field); - } - - VorbisComment::Entry::Entry(const char *field_name, const char *field_value, uint32_t field_value_length) : - is_valid_(true), - entry_(), - field_name_(0), - field_name_length_(0), - field_value_(0), - field_value_length_(0) - { - zero(); - construct(field_name, field_value, field_value_length); - } - - VorbisComment::Entry::Entry(const char *field_name, const char *field_value) : - is_valid_(true), - entry_(), - field_name_(0), - field_name_length_(0), - field_value_(0), - field_value_length_(0) - { - zero(); - construct(field_name, field_value); - } - - VorbisComment::Entry::Entry(const Entry &entry) : - is_valid_(true), - entry_(), - field_name_(0), - field_name_length_(0), - field_value_(0), - field_value_length_(0) - { - FLAC__ASSERT(entry.is_valid()); - zero(); - construct(reinterpret_cast(entry.entry_.entry), entry.entry_.length); - } - - VorbisComment::Entry &VorbisComment::Entry::operator=(const Entry &entry) - { - FLAC__ASSERT(entry.is_valid()); - clear(); - construct(reinterpret_cast(entry.entry_.entry), entry.entry_.length); - return *this; - } - - VorbisComment::Entry::~Entry() - { - clear(); - } - - bool VorbisComment::Entry::is_valid() const - { - return is_valid_; - } - - uint32_t VorbisComment::Entry::get_field_length() const - { - FLAC__ASSERT(is_valid()); - return entry_.length; - } - - uint32_t VorbisComment::Entry::get_field_name_length() const - { - FLAC__ASSERT(is_valid()); - return field_name_length_; - } - - uint32_t VorbisComment::Entry::get_field_value_length() const - { - FLAC__ASSERT(is_valid()); - return field_value_length_; - } - - ::FLAC__StreamMetadata_VorbisComment_Entry VorbisComment::Entry::get_entry() const - { - FLAC__ASSERT(is_valid()); - return entry_; - } - - const char *VorbisComment::Entry::get_field() const - { - FLAC__ASSERT(is_valid()); - return reinterpret_cast(entry_.entry); - } - - const char *VorbisComment::Entry::get_field_name() const - { - FLAC__ASSERT(is_valid()); - return field_name_; - } - - const char *VorbisComment::Entry::get_field_value() const - { - FLAC__ASSERT(is_valid()); - return field_value_; - } - - bool VorbisComment::Entry::set_field(const char *field, uint32_t field_length) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(0 != field); - - if(!::FLAC__format_vorbiscomment_entry_is_legal(reinterpret_cast(field), field_length)) - return is_valid_ = false; - - clear_entry(); - - if(0 == (entry_.entry = static_cast(safe_malloc_add_2op_(field_length, /*+*/1)))) { - is_valid_ = false; - } - else { - entry_.length = field_length; - std::memcpy(entry_.entry, field, field_length); - entry_.entry[field_length] = '\0'; - (void) parse_field(); - } - - return is_valid_; - } - - bool VorbisComment::Entry::set_field(const char *field) - { - return set_field(field, std::strlen(field)); - } - - bool VorbisComment::Entry::set_field_name(const char *field_name) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(0 != field_name); - - if(!::FLAC__format_vorbiscomment_entry_name_is_legal(field_name)) - return is_valid_ = false; - - clear_field_name(); - - if(0 == (field_name_ = strdup(field_name))) { - is_valid_ = false; - } - else { - field_name_length_ = std::strlen(field_name_); - compose_field(); - } - - return is_valid_; - } - - bool VorbisComment::Entry::set_field_value(const char *field_value, uint32_t field_value_length) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(0 != field_value); - - if(!::FLAC__format_vorbiscomment_entry_value_is_legal(reinterpret_cast(field_value), field_value_length)) - return is_valid_ = false; - - clear_field_value(); - - if(0 == (field_value_ = static_cast(safe_malloc_add_2op_(field_value_length, /*+*/1)))) { - is_valid_ = false; - } - else { - field_value_length_ = field_value_length; - std::memcpy(field_value_, field_value, field_value_length); - field_value_[field_value_length] = '\0'; - compose_field(); - } - - return is_valid_; - } - - bool VorbisComment::Entry::set_field_value(const char *field_value) - { - return set_field_value(field_value, std::strlen(field_value)); - } - - void VorbisComment::Entry::zero() - { - is_valid_ = true; - entry_.length = 0; - entry_.entry = 0; - field_name_ = 0; - field_name_length_ = 0; - field_value_ = 0; - field_value_length_ = 0; - } - - void VorbisComment::Entry::clear() - { - clear_entry(); - clear_field_name(); - clear_field_value(); - is_valid_ = true; - } - - void VorbisComment::Entry::clear_entry() - { - if(0 != entry_.entry) { - std::free(entry_.entry); - entry_.entry = 0; - entry_.length = 0; - } - } - - void VorbisComment::Entry::clear_field_name() - { - if(0 != field_name_) { - std::free(field_name_); - field_name_ = 0; - field_name_length_ = 0; - } - } - - void VorbisComment::Entry::clear_field_value() - { - if(0 != field_value_) { - std::free(field_value_); - field_value_ = 0; - field_value_length_ = 0; - } - } - - void VorbisComment::Entry::construct(const char *field, uint32_t field_length) - { - if(set_field(field, field_length)) - parse_field(); - } - - void VorbisComment::Entry::construct(const char *field) - { - construct(field, std::strlen(field)); - } - - void VorbisComment::Entry::construct(const char *field_name, const char *field_value, uint32_t field_value_length) - { - if(set_field_name(field_name) && set_field_value(field_value, field_value_length)) - compose_field(); - } - - void VorbisComment::Entry::construct(const char *field_name, const char *field_value) - { - construct(field_name, field_value, std::strlen(field_value)); - } - - void VorbisComment::Entry::compose_field() - { - clear_entry(); - - if(0 == (entry_.entry = static_cast(safe_malloc_add_4op_(field_name_length_, /*+*/1, /*+*/field_value_length_, /*+*/1)))) { - is_valid_ = false; - } - else { - std::memcpy(entry_.entry, field_name_, field_name_length_); - entry_.length += field_name_length_; - std::memcpy(entry_.entry + entry_.length, "=", 1); - entry_.length += 1; - if (field_value_length_ > 0) - std::memcpy(entry_.entry + entry_.length, field_value_, field_value_length_); - entry_.length += field_value_length_; - entry_.entry[entry_.length] = '\0'; - is_valid_ = true; - } - } - - void VorbisComment::Entry::parse_field() - { - clear_field_name(); - clear_field_value(); - - const char *p = static_cast(std::memchr(entry_.entry, '=', entry_.length)); - - if(0 == p) - p = reinterpret_cast(entry_.entry) + entry_.length; - - field_name_length_ = static_cast(p - reinterpret_cast(entry_.entry)); - if(0 == (field_name_ = static_cast(safe_malloc_add_2op_(field_name_length_, /*+*/1)))) { // +1 for the trailing \0 - is_valid_ = false; - return; - } - std::memcpy(field_name_, entry_.entry, field_name_length_); - field_name_[field_name_length_] = '\0'; - - if(entry_.length - field_name_length_ == 0) { - field_value_length_ = 0; - if(0 == (field_value_ = static_cast(safe_malloc_(0)))) { - is_valid_ = false; - return; - } - } - else { - field_value_length_ = entry_.length - field_name_length_ - 1; - if(0 == (field_value_ = static_cast(safe_malloc_add_2op_(field_value_length_, /*+*/1)))) { // +1 for the trailing \0 - is_valid_ = false; - return; - } - std::memcpy(field_value_, ++p, field_value_length_); - field_value_[field_value_length_] = '\0'; - } - - is_valid_ = true; - } - - - // - // VorbisComment - // - - VorbisComment::VorbisComment(): - Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT), /*copy=*/false) - { } - - VorbisComment::~VorbisComment() - { } - - uint32_t VorbisComment::get_num_comments() const - { - FLAC__ASSERT(is_valid()); - return object_->data.vorbis_comment.num_comments; - } - - const FLAC__byte *VorbisComment::get_vendor_string() const - { - FLAC__ASSERT(is_valid()); - return object_->data.vorbis_comment.vendor_string.entry; - } - - VorbisComment::Entry VorbisComment::get_comment(uint32_t indx) const - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(indx < object_->data.vorbis_comment.num_comments); - return Entry(reinterpret_cast(object_->data.vorbis_comment.comments[indx].entry), object_->data.vorbis_comment.comments[indx].length); - } - - bool VorbisComment::set_vendor_string(const FLAC__byte *string) - { - FLAC__ASSERT(is_valid()); - // vendor_string is a special kind of entry - const ::FLAC__StreamMetadata_VorbisComment_Entry vendor_string = { static_cast(std::strlen(reinterpret_cast(string))), const_cast(string) }; // we can cheat on const-ness because we make a copy below: - return static_cast(::FLAC__metadata_object_vorbiscomment_set_vendor_string(object_, vendor_string, /*copy=*/true)); - } - - bool VorbisComment::resize_comments(uint32_t new_num_comments) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_vorbiscomment_resize_comments(object_, new_num_comments)); - } - - bool VorbisComment::set_comment(uint32_t indx, const VorbisComment::Entry &entry) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(indx < object_->data.vorbis_comment.num_comments); - return static_cast(::FLAC__metadata_object_vorbiscomment_set_comment(object_, indx, entry.get_entry(), /*copy=*/true)); - } - - bool VorbisComment::insert_comment(uint32_t indx, const VorbisComment::Entry &entry) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(indx <= object_->data.vorbis_comment.num_comments); - return static_cast(::FLAC__metadata_object_vorbiscomment_insert_comment(object_, indx, entry.get_entry(), /*copy=*/true)); - } - - bool VorbisComment::append_comment(const VorbisComment::Entry &entry) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_vorbiscomment_append_comment(object_, entry.get_entry(), /*copy=*/true)); - } - - bool VorbisComment::replace_comment(const VorbisComment::Entry &entry, bool all) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_vorbiscomment_replace_comment(object_, entry.get_entry(), static_cast(all), /*copy=*/true)); - } - - bool VorbisComment::delete_comment(uint32_t indx) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(indx < object_->data.vorbis_comment.num_comments); - return static_cast(::FLAC__metadata_object_vorbiscomment_delete_comment(object_, indx)); - } - - int VorbisComment::find_entry_from(uint32_t offset, const char *field_name) - { - FLAC__ASSERT(is_valid()); - return ::FLAC__metadata_object_vorbiscomment_find_entry_from(object_, offset, field_name); - } - - int VorbisComment::remove_entry_matching(const char *field_name) - { - FLAC__ASSERT(is_valid()); - return ::FLAC__metadata_object_vorbiscomment_remove_entry_matching(object_, field_name); - } - - int VorbisComment::remove_entries_matching(const char *field_name) - { - FLAC__ASSERT(is_valid()); - return ::FLAC__metadata_object_vorbiscomment_remove_entries_matching(object_, field_name); - } - - - // - // CueSheet::Track - // - - CueSheet::Track::Track(): - object_(::FLAC__metadata_object_cuesheet_track_new()) - { } - - CueSheet::Track::Track(const ::FLAC__StreamMetadata_CueSheet_Track *track): - object_(::FLAC__metadata_object_cuesheet_track_clone(track)) - { } - - CueSheet::Track::Track(const Track &track): - object_(::FLAC__metadata_object_cuesheet_track_clone(track.object_)) - { } - - CueSheet::Track &CueSheet::Track::operator=(const Track &track) - { - if(0 != object_) - ::FLAC__metadata_object_cuesheet_track_delete(object_); - object_ = ::FLAC__metadata_object_cuesheet_track_clone(track.object_); - return *this; - } - - CueSheet::Track::~Track() - { - if(0 != object_) - ::FLAC__metadata_object_cuesheet_track_delete(object_); - } - - bool CueSheet::Track::is_valid() const - { - return(0 != object_); - } - - ::FLAC__StreamMetadata_CueSheet_Index CueSheet::Track::get_index(uint32_t i) const - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(i < object_->num_indices); - return object_->indices[i]; - } - - void CueSheet::Track::set_isrc(const char value[12]) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(0 != value); - std::memcpy(object_->isrc, value, 12); - object_->isrc[12] = '\0'; - } - - void CueSheet::Track::set_type(uint32_t value) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(value <= 1); - object_->type = value; - } - - void CueSheet::Track::set_index(uint32_t i, const ::FLAC__StreamMetadata_CueSheet_Index &indx) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(i < object_->num_indices); - object_->indices[i] = indx; - } - - - // - // CueSheet - // - - CueSheet::CueSheet(): - Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET), /*copy=*/false) - { } - - CueSheet::~CueSheet() - { } - - const char *CueSheet::get_media_catalog_number() const - { - FLAC__ASSERT(is_valid()); - return object_->data.cue_sheet.media_catalog_number; - } - - FLAC__uint64 CueSheet::get_lead_in() const - { - FLAC__ASSERT(is_valid()); - return object_->data.cue_sheet.lead_in; - } - - bool CueSheet::get_is_cd() const - { - FLAC__ASSERT(is_valid()); - return object_->data.cue_sheet.is_cd? true : false; - } - - uint32_t CueSheet::get_num_tracks() const - { - FLAC__ASSERT(is_valid()); - return object_->data.cue_sheet.num_tracks; - } - - CueSheet::Track CueSheet::get_track(uint32_t i) const - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(i < object_->data.cue_sheet.num_tracks); - return Track(object_->data.cue_sheet.tracks + i); - } - - void CueSheet::set_media_catalog_number(const char value[128]) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(0 != value); - std::memcpy(object_->data.cue_sheet.media_catalog_number, value, 128); - object_->data.cue_sheet.media_catalog_number[128] = '\0'; - } - - void CueSheet::set_lead_in(FLAC__uint64 value) - { - FLAC__ASSERT(is_valid()); - object_->data.cue_sheet.lead_in = value; - } - - void CueSheet::set_is_cd(bool value) - { - FLAC__ASSERT(is_valid()); - object_->data.cue_sheet.is_cd = value; - } - - void CueSheet::set_index(uint32_t track_num, uint32_t index_num, const ::FLAC__StreamMetadata_CueSheet_Index &indx) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(track_num < object_->data.cue_sheet.num_tracks); - FLAC__ASSERT(index_num < object_->data.cue_sheet.tracks[track_num].num_indices); - object_->data.cue_sheet.tracks[track_num].indices[index_num] = indx; - } - - bool CueSheet::resize_indices(uint32_t track_num, uint32_t new_num_indices) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(track_num < object_->data.cue_sheet.num_tracks); - return static_cast(::FLAC__metadata_object_cuesheet_track_resize_indices(object_, track_num, new_num_indices)); - } - - bool CueSheet::insert_index(uint32_t track_num, uint32_t index_num, const ::FLAC__StreamMetadata_CueSheet_Index &indx) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(track_num < object_->data.cue_sheet.num_tracks); - FLAC__ASSERT(index_num <= object_->data.cue_sheet.tracks[track_num].num_indices); - return static_cast(::FLAC__metadata_object_cuesheet_track_insert_index(object_, track_num, index_num, indx)); - } - - bool CueSheet::insert_blank_index(uint32_t track_num, uint32_t index_num) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(track_num < object_->data.cue_sheet.num_tracks); - FLAC__ASSERT(index_num <= object_->data.cue_sheet.tracks[track_num].num_indices); - return static_cast(::FLAC__metadata_object_cuesheet_track_insert_blank_index(object_, track_num, index_num)); - } - - bool CueSheet::delete_index(uint32_t track_num, uint32_t index_num) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(track_num < object_->data.cue_sheet.num_tracks); - FLAC__ASSERT(index_num < object_->data.cue_sheet.tracks[track_num].num_indices); - return static_cast(::FLAC__metadata_object_cuesheet_track_delete_index(object_, track_num, index_num)); - } - - bool CueSheet::resize_tracks(uint32_t new_num_tracks) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_cuesheet_resize_tracks(object_, new_num_tracks)); - } - - bool CueSheet::set_track(uint32_t i, const CueSheet::Track &track) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(i < object_->data.cue_sheet.num_tracks); - // We can safely const_cast since copy=true - return static_cast(::FLAC__metadata_object_cuesheet_set_track(object_, i, const_cast< ::FLAC__StreamMetadata_CueSheet_Track*>(track.get_track()), /*copy=*/true)); - } - - bool CueSheet::insert_track(uint32_t i, const CueSheet::Track &track) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(i <= object_->data.cue_sheet.num_tracks); - // We can safely const_cast since copy=true - return static_cast(::FLAC__metadata_object_cuesheet_insert_track(object_, i, const_cast< ::FLAC__StreamMetadata_CueSheet_Track*>(track.get_track()), /*copy=*/true)); - } - - bool CueSheet::insert_blank_track(uint32_t i) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(i <= object_->data.cue_sheet.num_tracks); - return static_cast(::FLAC__metadata_object_cuesheet_insert_blank_track(object_, i)); - } - - bool CueSheet::delete_track(uint32_t i) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(i < object_->data.cue_sheet.num_tracks); - return static_cast(::FLAC__metadata_object_cuesheet_delete_track(object_, i)); - } - - bool CueSheet::is_legal(bool check_cd_da_subset, const char **violation) const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_cuesheet_is_legal(object_, check_cd_da_subset, violation)); - } - - FLAC__uint32 CueSheet::calculate_cddb_id() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__metadata_object_cuesheet_calculate_cddb_id(object_); - } - - - // - // Picture - // - - Picture::Picture(): - Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE), /*copy=*/false) - { } - - Picture::~Picture() - { } - - ::FLAC__StreamMetadata_Picture_Type Picture::get_type() const - { - FLAC__ASSERT(is_valid()); - return object_->data.picture.type; - } - - const char *Picture::get_mime_type() const - { - FLAC__ASSERT(is_valid()); - return object_->data.picture.mime_type; - } - - const FLAC__byte *Picture::get_description() const - { - FLAC__ASSERT(is_valid()); - return object_->data.picture.description; - } - - FLAC__uint32 Picture::get_width() const - { - FLAC__ASSERT(is_valid()); - return object_->data.picture.width; - } - - FLAC__uint32 Picture::get_height() const - { - FLAC__ASSERT(is_valid()); - return object_->data.picture.height; - } - - FLAC__uint32 Picture::get_depth() const - { - FLAC__ASSERT(is_valid()); - return object_->data.picture.depth; - } - - FLAC__uint32 Picture::get_colors() const - { - FLAC__ASSERT(is_valid()); - return object_->data.picture.colors; - } - - FLAC__uint32 Picture::get_data_length() const - { - FLAC__ASSERT(is_valid()); - return object_->data.picture.data_length; - } - - const FLAC__byte *Picture::get_data() const - { - FLAC__ASSERT(is_valid()); - return object_->data.picture.data; - } - - void Picture::set_type(::FLAC__StreamMetadata_Picture_Type type) - { - FLAC__ASSERT(is_valid()); - object_->data.picture.type = type; - } - - bool Picture::set_mime_type(const char *string) - { - FLAC__ASSERT(is_valid()); - // We can safely const_cast since copy=true - return static_cast(::FLAC__metadata_object_picture_set_mime_type(object_, const_cast(string), /*copy=*/true)); - } - - bool Picture::set_description(const FLAC__byte *string) - { - FLAC__ASSERT(is_valid()); - // We can safely const_cast since copy=true - return static_cast(::FLAC__metadata_object_picture_set_description(object_, const_cast(string), /*copy=*/true)); - } - - void Picture::set_width(FLAC__uint32 value) const - { - FLAC__ASSERT(is_valid()); - object_->data.picture.width = value; - } - - void Picture::set_height(FLAC__uint32 value) const - { - FLAC__ASSERT(is_valid()); - object_->data.picture.height = value; - } - - void Picture::set_depth(FLAC__uint32 value) const - { - FLAC__ASSERT(is_valid()); - object_->data.picture.depth = value; - } - - void Picture::set_colors(FLAC__uint32 value) const - { - FLAC__ASSERT(is_valid()); - object_->data.picture.colors = value; - } - - bool Picture::set_data(const FLAC__byte *data, FLAC__uint32 data_length) - { - FLAC__ASSERT(is_valid()); - // We can safely const_cast since copy=true - return static_cast(::FLAC__metadata_object_picture_set_data(object_, const_cast(data), data_length, /*copy=*/true)); - } - - bool Picture::is_legal(const char **violation) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_picture_is_legal(object_, violation)); - } - - - // - // Unknown - // - - Unknown::Unknown(): - Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION), /*copy=*/false) - { } - - Unknown::~Unknown() - { } - - const FLAC__byte *Unknown::get_data() const - { - FLAC__ASSERT(is_valid()); - return object_->data.application.data; - } - - bool Unknown::set_data(const FLAC__byte *data, uint32_t length) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_application_set_data(object_, const_cast(data), length, true)); - } - - bool Unknown::set_data(FLAC__byte *data, uint32_t length, bool copy) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_object_application_set_data(object_, data, length, copy)); - } - - - // ============================================================ - // - // Level 0 - // - // ============================================================ - - FLACPP_API bool get_streaminfo(const char *filename, StreamInfo &streaminfo) - { - FLAC__ASSERT(0 != filename); - - ::FLAC__StreamMetadata object; - - if(::FLAC__metadata_get_streaminfo(filename, &object)) { - streaminfo = object; - return true; - } - else - return false; - } - - FLACPP_API bool get_tags(const char *filename, VorbisComment *&tags) - { - FLAC__ASSERT(0 != filename); - - ::FLAC__StreamMetadata *object; - - tags = 0; - - if(::FLAC__metadata_get_tags(filename, &object)) { - tags = new VorbisComment(object, /*copy=*/false); - return true; - } - else - return false; - } - - FLACPP_API bool get_tags(const char *filename, VorbisComment &tags) - { - FLAC__ASSERT(0 != filename); - - ::FLAC__StreamMetadata *object; - - if(::FLAC__metadata_get_tags(filename, &object)) { - tags.assign(object, /*copy=*/false); - return true; - } - else - return false; - } - - FLACPP_API bool get_cuesheet(const char *filename, CueSheet *&cuesheet) - { - FLAC__ASSERT(0 != filename); - - ::FLAC__StreamMetadata *object; - - cuesheet = 0; - - if(::FLAC__metadata_get_cuesheet(filename, &object)) { - cuesheet = new CueSheet(object, /*copy=*/false); - return true; - } - else - return false; - } - - FLACPP_API bool get_cuesheet(const char *filename, CueSheet &cuesheet) - { - FLAC__ASSERT(0 != filename); - - ::FLAC__StreamMetadata *object; - - if(::FLAC__metadata_get_cuesheet(filename, &object)) { - cuesheet.assign(object, /*copy=*/false); - return true; - } - else - return false; - } - - FLACPP_API bool get_picture(const char *filename, Picture *&picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors) - { - FLAC__ASSERT(0 != filename); - - ::FLAC__StreamMetadata *object; - - picture = 0; - - if(::FLAC__metadata_get_picture(filename, &object, type, mime_type, description, max_width, max_height, max_depth, max_colors)) { - picture = new Picture(object, /*copy=*/false); - return true; - } - else - return false; - } - - FLACPP_API bool get_picture(const char *filename, Picture &picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors) - { - FLAC__ASSERT(0 != filename); - - ::FLAC__StreamMetadata *object; - - if(::FLAC__metadata_get_picture(filename, &object, type, mime_type, description, max_width, max_height, max_depth, max_colors)) { - picture.assign(object, /*copy=*/false); - return true; - } - else - return false; - } - - - // ============================================================ - // - // Level 1 - // - // ============================================================ - - SimpleIterator::SimpleIterator(): - iterator_(::FLAC__metadata_simple_iterator_new()) - { } - - SimpleIterator::~SimpleIterator() - { - clear(); - } - - void SimpleIterator::clear() - { - if(0 != iterator_) - FLAC__metadata_simple_iterator_delete(iterator_); - iterator_ = 0; - } - - bool SimpleIterator::init(const char *filename, bool read_only, bool preserve_file_stats) - { - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_simple_iterator_init(iterator_, filename, read_only, preserve_file_stats)); - } - - bool SimpleIterator::is_valid() const - { - return 0 != iterator_; - } - - SimpleIterator::Status SimpleIterator::status() - { - FLAC__ASSERT(is_valid()); - return Status(::FLAC__metadata_simple_iterator_status(iterator_)); - } - - bool SimpleIterator::is_writable() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_simple_iterator_is_writable(iterator_)); - } - - bool SimpleIterator::next() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_simple_iterator_next(iterator_)); - } - - bool SimpleIterator::prev() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_simple_iterator_prev(iterator_)); - } - - //@@@@ add to tests - bool SimpleIterator::is_last() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_simple_iterator_is_last(iterator_)); - } - - //@@@@ add to tests - off_t SimpleIterator::get_block_offset() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__metadata_simple_iterator_get_block_offset(iterator_); - } - - ::FLAC__MetadataType SimpleIterator::get_block_type() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__metadata_simple_iterator_get_block_type(iterator_); - } - - //@@@@ add to tests - uint32_t SimpleIterator::get_block_length() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__metadata_simple_iterator_get_block_length(iterator_); - } - - //@@@@ add to tests - bool SimpleIterator::get_application_id(FLAC__byte *id) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_simple_iterator_get_application_id(iterator_, id)); - } - - Prototype *SimpleIterator::get_block() - { - FLAC__ASSERT(is_valid()); - return local::construct_block(::FLAC__metadata_simple_iterator_get_block(iterator_)); - } - - bool SimpleIterator::set_block(Prototype *block, bool use_padding) - { - FLAC__ASSERT(0 != block); - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_simple_iterator_set_block(iterator_, block->object_, use_padding)); - } - - bool SimpleIterator::insert_block_after(Prototype *block, bool use_padding) - { - FLAC__ASSERT(0 != block); - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_simple_iterator_insert_block_after(iterator_, block->object_, use_padding)); - } - - bool SimpleIterator::delete_block(bool use_padding) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_simple_iterator_delete_block(iterator_, use_padding)); - } - - - // ============================================================ - // - // Level 2 - // - // ============================================================ - - Chain::Chain(): - chain_(::FLAC__metadata_chain_new()) - { } - - Chain::~Chain() - { - clear(); - } - - void Chain::clear() - { - if(0 != chain_) - FLAC__metadata_chain_delete(chain_); - chain_ = 0; - } - - bool Chain::is_valid() const - { - return 0 != chain_; - } - - Chain::Status Chain::status() - { - FLAC__ASSERT(is_valid()); - return Status(::FLAC__metadata_chain_status(chain_)); - } - - bool Chain::read(const char *filename, bool is_ogg) - { - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(is_valid()); - return is_ogg? - static_cast(::FLAC__metadata_chain_read_ogg(chain_, filename)) : - static_cast(::FLAC__metadata_chain_read(chain_, filename)) - ; - } - - bool Chain::read(FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks, bool is_ogg) - { - FLAC__ASSERT(is_valid()); - return is_ogg? - static_cast(::FLAC__metadata_chain_read_ogg_with_callbacks(chain_, handle, callbacks)) : - static_cast(::FLAC__metadata_chain_read_with_callbacks(chain_, handle, callbacks)) - ; - } - - bool Chain::check_if_tempfile_needed(bool use_padding) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_chain_check_if_tempfile_needed(chain_, use_padding)); - } - - bool Chain::write(bool use_padding, bool preserve_file_stats) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_chain_write(chain_, use_padding, preserve_file_stats)); - } - - bool Chain::write(bool use_padding, ::FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_chain_write_with_callbacks(chain_, use_padding, handle, callbacks)); - } - - bool Chain::write(bool use_padding, ::FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks, ::FLAC__IOHandle temp_handle, ::FLAC__IOCallbacks temp_callbacks) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_chain_write_with_callbacks_and_tempfile(chain_, use_padding, handle, callbacks, temp_handle, temp_callbacks)); - } - - void Chain::merge_padding() - { - FLAC__ASSERT(is_valid()); - ::FLAC__metadata_chain_merge_padding(chain_); - } - - void Chain::sort_padding() - { - FLAC__ASSERT(is_valid()); - ::FLAC__metadata_chain_sort_padding(chain_); - } - - - Iterator::Iterator(): - iterator_(::FLAC__metadata_iterator_new()) - { } - - Iterator::~Iterator() - { - clear(); - } - - void Iterator::clear() - { - if(0 != iterator_) - FLAC__metadata_iterator_delete(iterator_); - iterator_ = 0; - } - - bool Iterator::is_valid() const - { - return 0 != iterator_; - } - - void Iterator::init(Chain &chain) - { - FLAC__ASSERT(is_valid()); - FLAC__ASSERT(chain.is_valid()); - ::FLAC__metadata_iterator_init(iterator_, chain.chain_); - } - - bool Iterator::next() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_iterator_next(iterator_)); - } - - bool Iterator::prev() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_iterator_prev(iterator_)); - } - - ::FLAC__MetadataType Iterator::get_block_type() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__metadata_iterator_get_block_type(iterator_); - } - - Prototype *Iterator::get_block() - { - FLAC__ASSERT(is_valid()); - Prototype *block = local::construct_block(::FLAC__metadata_iterator_get_block(iterator_)); - if(0 != block) - block->set_reference(true); - return block; - } - - bool Iterator::set_block(Prototype *block) - { - FLAC__ASSERT(0 != block); - FLAC__ASSERT(is_valid()); - bool ret = static_cast(::FLAC__metadata_iterator_set_block(iterator_, block->object_)); - if(ret) { - block->set_reference(true); - delete block; - } - return ret; - } - - bool Iterator::delete_block(bool replace_with_padding) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__metadata_iterator_delete_block(iterator_, replace_with_padding)); - } - - bool Iterator::insert_block_before(Prototype *block) - { - FLAC__ASSERT(0 != block); - FLAC__ASSERT(is_valid()); - bool ret = static_cast(::FLAC__metadata_iterator_insert_block_before(iterator_, block->object_)); - if(ret) { - block->set_reference(true); - delete block; - } - return ret; - } - - bool Iterator::insert_block_after(Prototype *block) - { - FLAC__ASSERT(0 != block); - FLAC__ASSERT(is_valid()); - bool ret = static_cast(::FLAC__metadata_iterator_insert_block_after(iterator_, block->object_)); - if(ret) { - block->set_reference(true); - delete block; - } - return ret; - } - - } // namespace Metadata -} // namespace FLAC diff --git a/flac/src/libFLAC++/stream_decoder.cpp b/flac/src/libFLAC++/stream_decoder.cpp deleted file mode 100644 index 6e351d9..0000000 --- a/flac/src/libFLAC++/stream_decoder.cpp +++ /dev/null @@ -1,394 +0,0 @@ -/* libFLAC++ - Free Lossless Audio Codec library - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "FLAC++/decoder.h" -#include "FLAC/assert.h" - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -namespace FLAC { - namespace Decoder { - - // ------------------------------------------------------------ - // - // Stream - // - // ------------------------------------------------------------ - - Stream::Stream(): - decoder_(::FLAC__stream_decoder_new()) - { } - - Stream::~Stream() - { - if(0 != decoder_) { - (void)::FLAC__stream_decoder_finish(decoder_); - ::FLAC__stream_decoder_delete(decoder_); - } - } - - bool Stream::is_valid() const - { - return 0 != decoder_; - } - - bool Stream::set_ogg_serial_number(long value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_set_ogg_serial_number(decoder_, value)); - } - - bool Stream::set_md5_checking(bool value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_set_md5_checking(decoder_, value)); - } - - bool Stream::set_metadata_respond(::FLAC__MetadataType type) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_set_metadata_respond(decoder_, type)); - } - - bool Stream::set_metadata_respond_application(const FLAC__byte id[4]) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_set_metadata_respond_application(decoder_, id)); - } - - bool Stream::set_metadata_respond_all() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_set_metadata_respond_all(decoder_)); - } - - bool Stream::set_metadata_ignore(::FLAC__MetadataType type) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_set_metadata_ignore(decoder_, type)); - } - - bool Stream::set_metadata_ignore_application(const FLAC__byte id[4]) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_set_metadata_ignore_application(decoder_, id)); - } - - bool Stream::set_metadata_ignore_all() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_set_metadata_ignore_all(decoder_)); - } - - Stream::State Stream::get_state() const - { - FLAC__ASSERT(is_valid()); - return State(::FLAC__stream_decoder_get_state(decoder_)); - } - - bool Stream::get_md5_checking() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_get_md5_checking(decoder_)); - } - - FLAC__uint64 Stream::get_total_samples() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_decoder_get_total_samples(decoder_); - } - - uint32_t Stream::get_channels() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_decoder_get_channels(decoder_); - } - - ::FLAC__ChannelAssignment Stream::get_channel_assignment() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_decoder_get_channel_assignment(decoder_); - } - - uint32_t Stream::get_bits_per_sample() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_decoder_get_bits_per_sample(decoder_); - } - - uint32_t Stream::get_sample_rate() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_decoder_get_sample_rate(decoder_); - } - - uint32_t Stream::get_blocksize() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_decoder_get_blocksize(decoder_); - } - - bool Stream::get_decode_position(FLAC__uint64 *position) const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_decoder_get_decode_position(decoder_, position); - } - - ::FLAC__StreamDecoderInitStatus Stream::init() - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_decoder_init_stream(decoder_, read_callback_, seek_callback_, tell_callback_, length_callback_, eof_callback_, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamDecoderInitStatus Stream::init_ogg() - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_decoder_init_ogg_stream(decoder_, read_callback_, seek_callback_, tell_callback_, length_callback_, eof_callback_, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - bool Stream::finish() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_finish(decoder_)); - } - - bool Stream::flush() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_flush(decoder_)); - } - - bool Stream::reset() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_reset(decoder_)); - } - - bool Stream::process_single() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_process_single(decoder_)); - } - - bool Stream::process_until_end_of_metadata() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_process_until_end_of_metadata(decoder_)); - } - - bool Stream::process_until_end_of_stream() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_process_until_end_of_stream(decoder_)); - } - - bool Stream::skip_single_frame() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_skip_single_frame(decoder_)); - } - - bool Stream::seek_absolute(FLAC__uint64 sample) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_decoder_seek_absolute(decoder_, sample)); - } - - ::FLAC__StreamDecoderSeekStatus Stream::seek_callback(FLAC__uint64 absolute_byte_offset) - { - (void)absolute_byte_offset; - return ::FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; - } - - ::FLAC__StreamDecoderTellStatus Stream::tell_callback(FLAC__uint64 *absolute_byte_offset) - { - (void)absolute_byte_offset; - return ::FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED; - } - - ::FLAC__StreamDecoderLengthStatus Stream::length_callback(FLAC__uint64 *stream_length) - { - (void)stream_length; - return ::FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; - } - - bool Stream::eof_callback() - { - return false; - } - - void Stream::metadata_callback(const ::FLAC__StreamMetadata *metadata) - { - (void)metadata; - } - - ::FLAC__StreamDecoderReadStatus Stream::read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) - { - (void)decoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - return instance->read_callback(buffer, bytes); - } - - ::FLAC__StreamDecoderSeekStatus Stream::seek_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) - { - (void) decoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - return instance->seek_callback(absolute_byte_offset); - } - - ::FLAC__StreamDecoderTellStatus Stream::tell_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) - { - (void) decoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - return instance->tell_callback(absolute_byte_offset); - } - - ::FLAC__StreamDecoderLengthStatus Stream::length_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) - { - (void) decoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - return instance->length_callback(stream_length); - } - - FLAC__bool Stream::eof_callback_(const ::FLAC__StreamDecoder *decoder, void *client_data) - { - (void) decoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - return instance->eof_callback(); - } - - ::FLAC__StreamDecoderWriteStatus Stream::write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) - { - (void)decoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - return instance->write_callback(frame, buffer); - } - - void Stream::metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data) - { - (void)decoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - instance->metadata_callback(metadata); - } - - void Stream::error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data) - { - (void)decoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - instance->error_callback(status); - } - - // ------------------------------------------------------------ - // - // File - // - // ------------------------------------------------------------ - - File::File(): - Stream() - { } - - File::~File() - { - } - - ::FLAC__StreamDecoderInitStatus File::init(FILE *file) - { - FLAC__ASSERT(0 != decoder_); - return ::FLAC__stream_decoder_init_FILE(decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamDecoderInitStatus File::init(const char *filename) - { - FLAC__ASSERT(0 != decoder_); - return ::FLAC__stream_decoder_init_file(decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamDecoderInitStatus File::init(const std::string &filename) - { - return init(filename.c_str()); - } - - ::FLAC__StreamDecoderInitStatus File::init_ogg(FILE *file) - { - FLAC__ASSERT(0 != decoder_); - return ::FLAC__stream_decoder_init_ogg_FILE(decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamDecoderInitStatus File::init_ogg(const char *filename) - { - FLAC__ASSERT(0 != decoder_); - return ::FLAC__stream_decoder_init_ogg_file(decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamDecoderInitStatus File::init_ogg(const std::string &filename) - { - return init_ogg(filename.c_str()); - } - - // This is a dummy to satisfy the pure virtual from Stream; the - // read callback will never be called since we are initializing - // with FLAC__stream_decoder_init_FILE() or - // FLAC__stream_decoder_init_file() and those supply the read - // callback internally. - ::FLAC__StreamDecoderReadStatus File::read_callback(FLAC__byte buffer[], size_t *bytes) - { - (void)buffer, (void)bytes; - FLAC__ASSERT(false); - return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; // double protection - } - - } // namespace Decoder -} // namespace FLAC diff --git a/flac/src/libFLAC++/stream_encoder.cpp b/flac/src/libFLAC++/stream_encoder.cpp deleted file mode 100644 index 8377129..0000000 --- a/flac/src/libFLAC++/stream_encoder.cpp +++ /dev/null @@ -1,519 +0,0 @@ -/* libFLAC++ - Free Lossless Audio Codec library - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "FLAC++/encoder.h" -#include "FLAC++/metadata.h" -#include "FLAC/assert.h" - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -namespace FLAC { - namespace Encoder { - - // ------------------------------------------------------------ - // - // Stream - // - // ------------------------------------------------------------ - - Stream::Stream(): - encoder_(::FLAC__stream_encoder_new()) - { } - - Stream::~Stream() - { - if(0 != encoder_) { - (void)::FLAC__stream_encoder_finish(encoder_); - ::FLAC__stream_encoder_delete(encoder_); - } - } - - bool Stream::is_valid() const - { - return 0 != encoder_; - } - - bool Stream::set_ogg_serial_number(long value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_ogg_serial_number(encoder_, value)); - } - - bool Stream::set_verify(bool value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_verify(encoder_, value)); - } - - bool Stream::set_streamable_subset(bool value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_streamable_subset(encoder_, value)); - } - - bool Stream::set_channels(uint32_t value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_channels(encoder_, value)); - } - - bool Stream::set_bits_per_sample(uint32_t value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_bits_per_sample(encoder_, value)); - } - - bool Stream::set_sample_rate(uint32_t value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_sample_rate(encoder_, value)); - } - - bool Stream::set_compression_level(uint32_t value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_compression_level(encoder_, value)); - } - - bool Stream::set_blocksize(uint32_t value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_blocksize(encoder_, value)); - } - - bool Stream::set_do_mid_side_stereo(bool value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_do_mid_side_stereo(encoder_, value)); - } - - bool Stream::set_loose_mid_side_stereo(bool value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_loose_mid_side_stereo(encoder_, value)); - } - - bool Stream::set_apodization(const char *specification) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_apodization(encoder_, specification)); - } - - bool Stream::set_max_lpc_order(uint32_t value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_max_lpc_order(encoder_, value)); - } - - bool Stream::set_qlp_coeff_precision(uint32_t value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_qlp_coeff_precision(encoder_, value)); - } - - bool Stream::set_do_qlp_coeff_prec_search(bool value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder_, value)); - } - - bool Stream::set_do_escape_coding(bool value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_do_escape_coding(encoder_, value)); - } - - bool Stream::set_do_exhaustive_model_search(bool value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_do_exhaustive_model_search(encoder_, value)); - } - - bool Stream::set_min_residual_partition_order(uint32_t value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_min_residual_partition_order(encoder_, value)); - } - - bool Stream::set_max_residual_partition_order(uint32_t value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_max_residual_partition_order(encoder_, value)); - } - - bool Stream::set_rice_parameter_search_dist(uint32_t value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_rice_parameter_search_dist(encoder_, value)); - } - - bool Stream::set_total_samples_estimate(FLAC__uint64 value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_total_samples_estimate(encoder_, value)); - } - - bool Stream::set_metadata(::FLAC__StreamMetadata **metadata, uint32_t num_blocks) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_metadata(encoder_, metadata, num_blocks)); - } - - bool Stream::set_metadata(FLAC::Metadata::Prototype **metadata, uint32_t num_blocks) - { - FLAC__ASSERT(is_valid()); - // because C++ doesn't have VLA's (variable length arrays) - // this ugly workaround is needed - ::FLAC__StreamMetadata **m = new ::FLAC__StreamMetadata*[num_blocks]; - for(uint32_t i = 0; i < num_blocks; i++) { - // we can get away with the const_cast since we know the encoder will only correct the is_last flags - m[i] = const_cast< ::FLAC__StreamMetadata*>(static_cast(*metadata[i])); - } - // complete the hack - const bool ok = static_cast(::FLAC__stream_encoder_set_metadata(encoder_, m, num_blocks)); - delete [] m; - return ok; - } - - bool Stream::set_limit_min_bitrate(bool value) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_set_limit_min_bitrate(encoder_, value)); - } - - Stream::State Stream::get_state() const - { - FLAC__ASSERT(is_valid()); - return State(::FLAC__stream_encoder_get_state(encoder_)); - } - - Decoder::Stream::State Stream::get_verify_decoder_state() const - { - FLAC__ASSERT(is_valid()); - return Decoder::Stream::State(::FLAC__stream_encoder_get_verify_decoder_state(encoder_)); - } - - void Stream::get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, uint32_t *frame_number, uint32_t *channel, uint32_t *sample, FLAC__int32 *expected, FLAC__int32 *got) - { - FLAC__ASSERT(is_valid()); - ::FLAC__stream_encoder_get_verify_decoder_error_stats(encoder_, absolute_sample, frame_number, channel, sample, expected, got); - } - - bool Stream::get_verify() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_get_verify(encoder_)); - } - - bool Stream::get_streamable_subset() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_get_streamable_subset(encoder_)); - } - - bool Stream::get_do_mid_side_stereo() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_get_do_mid_side_stereo(encoder_)); - } - - bool Stream::get_loose_mid_side_stereo() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_get_loose_mid_side_stereo(encoder_)); - } - - uint32_t Stream::get_channels() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_get_channels(encoder_); - } - - uint32_t Stream::get_bits_per_sample() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_get_bits_per_sample(encoder_); - } - - uint32_t Stream::get_sample_rate() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_get_sample_rate(encoder_); - } - - uint32_t Stream::get_blocksize() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_get_blocksize(encoder_); - } - - uint32_t Stream::get_max_lpc_order() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_get_max_lpc_order(encoder_); - } - - uint32_t Stream::get_qlp_coeff_precision() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_get_qlp_coeff_precision(encoder_); - } - - bool Stream::get_do_qlp_coeff_prec_search() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder_)); - } - - bool Stream::get_do_escape_coding() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_get_do_escape_coding(encoder_)); - } - - bool Stream::get_do_exhaustive_model_search() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_get_do_exhaustive_model_search(encoder_)); - } - - uint32_t Stream::get_min_residual_partition_order() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_get_min_residual_partition_order(encoder_); - } - - uint32_t Stream::get_max_residual_partition_order() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_get_max_residual_partition_order(encoder_); - } - - uint32_t Stream::get_rice_parameter_search_dist() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_get_rice_parameter_search_dist(encoder_); - } - - FLAC__uint64 Stream::get_total_samples_estimate() const - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_get_total_samples_estimate(encoder_); - } - - bool Stream::get_limit_min_bitrate() const - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_get_limit_min_bitrate(encoder_)); - } - - ::FLAC__StreamEncoderInitStatus Stream::init() - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_init_stream(encoder_, write_callback_, seek_callback_, tell_callback_, metadata_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamEncoderInitStatus Stream::init_ogg() - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_init_ogg_stream(encoder_, read_callback_, write_callback_, seek_callback_, tell_callback_, metadata_callback_, /*client_data=*/(void*)this); - } - - bool Stream::finish() - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_finish(encoder_)); - } - - bool Stream::process(const FLAC__int32 * const buffer[], uint32_t samples) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_process(encoder_, buffer, samples)); - } - - bool Stream::process_interleaved(const FLAC__int32 buffer[], uint32_t samples) - { - FLAC__ASSERT(is_valid()); - return static_cast(::FLAC__stream_encoder_process_interleaved(encoder_, buffer, samples)); - } - - ::FLAC__StreamEncoderReadStatus Stream::read_callback(FLAC__byte buffer[], size_t *bytes) - { - (void)buffer, (void)bytes; - return ::FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED; - } - - ::FLAC__StreamEncoderSeekStatus Stream::seek_callback(FLAC__uint64 absolute_byte_offset) - { - (void)absolute_byte_offset; - return ::FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED; - } - - ::FLAC__StreamEncoderTellStatus Stream::tell_callback(FLAC__uint64 *absolute_byte_offset) - { - (void)absolute_byte_offset; - return ::FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED; - } - - void Stream::metadata_callback(const ::FLAC__StreamMetadata *metadata) - { - (void)metadata; - } - - ::FLAC__StreamEncoderReadStatus Stream::read_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data) - { - (void)encoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - return instance->read_callback(buffer, bytes); - } - - ::FLAC__StreamEncoderWriteStatus Stream::write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data) - { - (void)encoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - return instance->write_callback(buffer, bytes, samples, current_frame); - } - - ::FLAC__StreamEncoderSeekStatus Stream::seek_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) - { - (void)encoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - return instance->seek_callback(absolute_byte_offset); - } - - ::FLAC__StreamEncoderTellStatus Stream::tell_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) - { - (void)encoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - return instance->tell_callback(absolute_byte_offset); - } - - void Stream::metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data) - { - (void)encoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - instance->metadata_callback(metadata); - } - - // ------------------------------------------------------------ - // - // File - // - // ------------------------------------------------------------ - - File::File(): - Stream() - { } - - File::~File() - { - } - - ::FLAC__StreamEncoderInitStatus File::init(FILE *file) - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_init_FILE(encoder_, file, progress_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamEncoderInitStatus File::init(const char *filename) - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_init_file(encoder_, filename, progress_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamEncoderInitStatus File::init(const std::string &filename) - { - return init(filename.c_str()); - } - - ::FLAC__StreamEncoderInitStatus File::init_ogg(FILE *file) - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_init_ogg_FILE(encoder_, file, progress_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamEncoderInitStatus File::init_ogg(const char *filename) - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_init_ogg_file(encoder_, filename, progress_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamEncoderInitStatus File::init_ogg(const std::string &filename) - { - return init_ogg(filename.c_str()); - } - - // This is a dummy to satisfy the pure virtual from Stream; the - // read callback will never be called since we are initializing - // with FLAC__stream_decoder_init_FILE() or - // FLAC__stream_decoder_init_file() and those supply the read - // callback internally. - ::FLAC__StreamEncoderWriteStatus File::write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame) - { - (void)buffer, (void)bytes, (void)samples, (void)current_frame; - FLAC__ASSERT(false); - return ::FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; // double protection - } - - void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate) - { - (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate; - } - - void File::progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate, void *client_data) - { - (void)encoder; - FLAC__ASSERT(0 != client_data); - File *instance = reinterpret_cast(client_data); - FLAC__ASSERT(0 != instance); - instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate); - } - - } // namespace Encoder -} // namespace FLAC diff --git a/flac/src/libFLAC++/version.rc b/flac/src/libFLAC++/version.rc deleted file mode 100644 index 14efba0..0000000 --- a/flac/src/libFLAC++/version.rc +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include "config.h" -#include "FLAC++/export.h" - -#if (defined GIT_COMMIT_HASH && defined GIT_COMMIT_DATE) -# ifdef GIT_COMMIT_TAG -# define VERSIONSTRING GIT_COMMIT_TAG -# else -# define VERSIONSTRING "git-" GIT_COMMIT_HASH -# endif -#else -# define VERSIONSTRING PACKAGE_VERSION -#endif - -#define xstr(s) str(s) -#define str(s) #s - -VS_VERSION_INFO VERSIONINFO -FILEVERSION FLACPP_API_VERSION_CURRENT,FLACPP_API_VERSION_REVISION,0,0 -FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -FILEFLAGS 0 -FILEOS VOS__WINDOWS32 -FILETYPE VFT_DLL -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "FileDescription", "libFLAC++ for Windows" - VALUE "ProductName", "Free Lossless Audio Codec" - VALUE "ProductVersion", VERSIONSTRING - VALUE "CompanyName", "Xiph.Org" - VALUE "LegalCopyright", "2000-2009 Josh Coalson, 2011-2023 Xiph.Org Foundation" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END diff --git a/flac/src/libFLAC/CMakeLists.txt b/flac/src/libFLAC/CMakeLists.txt deleted file mode 100644 index cf7368f..0000000 --- a/flac/src/libFLAC/CMakeLists.txt +++ /dev/null @@ -1,126 +0,0 @@ -option(WITH_ASM "Use any assembly optimization routines" ON) - -check_include_file("cpuid.h" HAVE_CPUID_H) -check_include_file("sys/param.h" HAVE_SYS_PARAM_H) - -set(CMAKE_REQUIRED_LIBRARIES m) -check_function_exists(lround HAVE_LROUND) - -include(CheckCSourceCompiles) -include(CheckCPUArch) -include(CheckA64NEON) - -check_cpu_arch_x64(FLAC__CPU_X86_64) -if(NOT FLAC__CPU_X86_64) - check_cpu_arch_x86(FLAC__CPU_IA32) -endif() - -if(FLAC__CPU_X86_64 OR FLAC__CPU_IA32) - set(FLAC__ALIGN_MALLOC_DATA 1) - option(WITH_AVX "Enable AVX, AVX2 optimizations (with runtime detection, resulting binary does not require AVX2, so only necessary when a compiler doesn't know about AVX)" ON) - if(WITH_AVX AND MSVC) - set_source_files_properties(fixed_intrin_avx2.c lpc_intrin_avx2.c stream_encoder_intrin_avx2.c lpc_intrin_fma.c PROPERTIES COMPILE_FLAGS /arch:AVX2) - endif() -else() - check_cpu_arch_arm64(FLAC__CPU_ARM64) - if(FLAC__CPU_ARM64) - check_a64neon(FLAC__HAS_A64NEONINTRIN) - endif() -endif() - -if(NOT WITH_ASM) - add_definitions(-DFLAC__NO_ASM) -endif() - -include_directories("include") - -add_library(FLAC - bitmath.c - bitreader.c - bitwriter.c - cpu.c - crc.c - fixed.c - fixed_intrin_sse2.c - fixed_intrin_ssse3.c - fixed_intrin_sse42.c - fixed_intrin_avx2.c - float.c - format.c - lpc.c - lpc_intrin_neon.c - lpc_intrin_sse2.c - lpc_intrin_sse41.c - lpc_intrin_avx2.c - lpc_intrin_fma.c - md5.c - memory.c - metadata_iterators.c - metadata_object.c - stream_decoder.c - stream_encoder.c - stream_encoder_intrin_sse2.c - stream_encoder_intrin_ssse3.c - stream_encoder_intrin_avx2.c - stream_encoder_framing.c - version.rc - window.c - $<$:../../include/share/win_utf8_io.h> - $<$:../share/win_utf8_io/win_utf8_io.c> - $<$:ogg_decoder_aspect.c> - $<$:ogg_encoder_aspect.c> - $<$:ogg_helper.c> - $<$:ogg_mapping.c>) -set_property(TARGET FLAC PROPERTY PROJECT_LABEL "libFLAC") -if(TARGET FLAC-asm) - target_sources(FLAC PRIVATE $) -endif() - -target_compile_definitions(FLAC - PRIVATE $<$:FLAC_API_EXPORTS> - PUBLIC $<$>:FLAC__NO_DLL>) -if(NOT WIN32) - target_compile_definitions(FLAC PRIVATE $<$:FLAC__USE_VISIBILITY_ATTR>) -endif() -target_include_directories(FLAC INTERFACE - "$" - "$") -target_link_libraries(FLAC PUBLIC $<$:m>) -if(TARGET Ogg::ogg) - target_link_libraries(FLAC PUBLIC Ogg::ogg) -endif() -if(BUILD_SHARED_LIBS) - set_target_properties(FLAC PROPERTIES - VERSION 12.1.0 - SOVERSION 12) - if(NOT WIN32) - set_target_properties(FLAC PROPERTIES C_VISIBILITY_PRESET hidden) - endif() -endif() - -check_c_compiler_flag("-fassociative-math -fno-signed-zeros -fno-trapping-math -freciprocal-math" HAVE_ASSOC_MATH) - -if(MSVC) - target_compile_options(FLAC BEFORE PRIVATE "/fp:fast") -else() - if(HAVE_ASSOC_MATH) - target_compile_options(FLAC BEFORE PRIVATE -fassociative-math -fno-signed-zeros -fno-trapping-math -freciprocal-math) - endif() -endif() - -add_library(FLAC::FLAC ALIAS FLAC) - -install(TARGETS FLAC EXPORT targets - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/") - -if(INSTALL_PKGCONFIG_MODULES) - set(prefix "${CMAKE_INSTALL_PREFIX}") - set(exec_prefix "${CMAKE_INSTALL_PREFIX}") - set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") - set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") - configure_file(flac.pc.in flac.pc @ONLY) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/flac.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") -endif() diff --git a/flac/src/libFLAC/Makefile.am b/flac/src/libFLAC/Makefile.am deleted file mode 100644 index 618939d..0000000 --- a/flac/src/libFLAC/Makefile.am +++ /dev/null @@ -1,123 +0,0 @@ -# libFLAC - Free Lossless Audio Codec library -# Copyright (C) 2001-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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 Xiph.org Foundation 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 FOUNDATION 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. - -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include -lib_LTLIBRARIES = libFLAC.la -noinst_LTLIBRARIES = libFLAC-static.la -if DEBUG -DEBUGCFLAGS = -DFLAC__OVERFLOW_DETECT -else -if ASSOC_MATH_AVAILABLE -ASSOCMATHCFLAGS = -fassociative-math -fno-signed-zeros -fno-trapping-math -freciprocal-math -endif -endif - -AM_CFLAGS = $(DEBUGCFLAGS) ${ASSOCMATHCFLAGS} @OGG_CFLAGS@ - -libFLAC_la_LIBADD = @OGG_LIBS@ -lm - -SUBDIRS = include . - -m4datadir = $(datadir)/aclocal -m4data_DATA = libFLAC.m4 - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = flac.pc - -EXTRA_DIST = \ - CMakeLists.txt \ - flac.pc.in \ - libFLAC.m4 \ - version.rc \ - deduplication/bitreader_read_rice_signed_block.c \ - deduplication/lpc_compute_autocorrelation_intrin.c \ - deduplication/lpc_compute_autocorrelation_intrin_sse2.c \ - deduplication/lpc_compute_autocorrelation_intrin_neon.c - -if OS_IS_WINDOWS -windows_unicode_compat = ../share/win_utf8_io/win_utf8_io.c -if HAVE_WINDRES -libFLAC_la_DEPENDENCIES = version.o -windows_resource_link = -Wl,version.o -endif -endif - -if FLaC__HAS_OGG -extra_ogg_sources = \ - ogg_decoder_aspect.c \ - ogg_encoder_aspect.c \ - ogg_helper.c \ - ogg_mapping.c -endif - -# see 'http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning' for numbering convention -libFLAC_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 13:0:1 $(windows_resource_link) - -libFLAC_sources = \ - bitmath.c \ - bitreader.c \ - bitwriter.c \ - cpu.c \ - crc.c \ - fixed.c \ - fixed_intrin_sse2.c \ - fixed_intrin_ssse3.c \ - fixed_intrin_sse42.c \ - fixed_intrin_avx2.c \ - float.c \ - format.c \ - lpc.c \ - lpc_intrin_sse2.c \ - lpc_intrin_sse41.c \ - lpc_intrin_avx2.c \ - lpc_intrin_fma.c \ - lpc_intrin_neon.c \ - md5.c \ - memory.c \ - metadata_iterators.c \ - metadata_object.c \ - stream_decoder.c \ - stream_encoder.c \ - stream_encoder_intrin_sse2.c \ - stream_encoder_intrin_ssse3.c \ - stream_encoder_intrin_avx2.c \ - stream_encoder_framing.c \ - window.c \ - $(windows_unicode_compat) \ - $(extra_ogg_sources) - -libFLAC_la_SOURCES = $(libFLAC_sources) - -# needed for test_libFLAC -libFLAC_static_la_SOURCES = $(libFLAC_sources) - -.rc.o: - $(RC) $(AM_CPPFLAGS) $< $@ diff --git a/flac/src/libFLAC/bitmath.c b/flac/src/libFLAC/bitmath.c deleted file mode 100644 index 077486b..0000000 --- a/flac/src/libFLAC/bitmath.c +++ /dev/null @@ -1,73 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/bitmath.h" - -/* An example of what FLAC__bitmath_silog2() computes: - * - * silog2(-10) = 5 - * silog2(- 9) = 5 - * silog2(- 8) = 4 - * silog2(- 7) = 4 - * silog2(- 6) = 4 - * silog2(- 5) = 4 - * silog2(- 4) = 3 - * silog2(- 3) = 3 - * silog2(- 2) = 2 - * silog2(- 1) = 2 - * silog2( 0) = 0 - * silog2( 1) = 2 - * silog2( 2) = 3 - * silog2( 3) = 3 - * silog2( 4) = 4 - * silog2( 5) = 4 - * silog2( 6) = 4 - * silog2( 7) = 4 - * silog2( 8) = 5 - * silog2( 9) = 5 - * silog2( 10) = 5 - */ -uint32_t FLAC__bitmath_silog2(FLAC__int64 v) -{ - if(v == 0) - return 0; - - if(v == -1) - return 2; - - v = (v < 0) ? (-(v+1)) : v; - return FLAC__bitmath_ilog2_wide(v)+2; -} diff --git a/flac/src/libFLAC/bitreader.c b/flac/src/libFLAC/bitreader.c deleted file mode 100644 index 829b308..0000000 --- a/flac/src/libFLAC/bitreader.c +++ /dev/null @@ -1,1052 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "private/bitmath.h" -#include "private/bitreader.h" -#include "private/crc.h" -#include "private/cpu.h" -#include "private/macros.h" -#include "FLAC/assert.h" -#include "share/compat.h" -#include "share/endswap.h" - -/* Things should be fastest when this matches the machine word size */ -/* WATCHOUT: if you change this you must also change the following #defines down to COUNT_ZERO_MSBS2 below to match */ -/* WATCHOUT: there are a few places where the code will not work unless brword is >= 32 bits wide */ -/* also, some sections currently only have fast versions for 4 or 8 bytes per word */ - -#if (ENABLE_64_BIT_WORDS == 0) - -typedef FLAC__uint32 brword; -#define FLAC__BYTES_PER_WORD 4 /* sizeof brword */ -#define FLAC__BITS_PER_WORD 32 -#define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff) -/* SWAP_BE_WORD_TO_HOST swaps bytes in a brword (which is always big-endian) if necessary to match host byte order */ -#if WORDS_BIGENDIAN -#define SWAP_BE_WORD_TO_HOST(x) (x) -#else -#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x) -#endif -/* counts the # of zero MSBs in a word */ -#define COUNT_ZERO_MSBS(word) FLAC__clz_uint32(word) -#define COUNT_ZERO_MSBS2(word) FLAC__clz2_uint32(word) - -#else - -typedef FLAC__uint64 brword; -#define FLAC__BYTES_PER_WORD 8 /* sizeof brword */ -#define FLAC__BITS_PER_WORD 64 -#define FLAC__WORD_ALL_ONES ((FLAC__uint64)FLAC__U64L(0xffffffffffffffff)) -/* SWAP_BE_WORD_TO_HOST swaps bytes in a brword (which is always big-endian) if necessary to match host byte order */ -#if WORDS_BIGENDIAN -#define SWAP_BE_WORD_TO_HOST(x) (x) -#else -#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_64(x) -#endif -/* counts the # of zero MSBs in a word */ -#define COUNT_ZERO_MSBS(word) FLAC__clz_uint64(word) -#define COUNT_ZERO_MSBS2(word) FLAC__clz2_uint64(word) - -#endif - -/* - * This should be at least twice as large as the largest number of words - * required to represent any 'number' (in any encoding) you are going to - * read. With FLAC this is on the order of maybe a few hundred bits. - * If the buffer is smaller than that, the decoder won't be able to read - * in a whole number that is in a variable length encoding (e.g. Rice). - * But to be practical it should be at least 1K bytes. - * - * Increase this number to decrease the number of read callbacks, at the - * expense of using more memory. Or decrease for the reverse effect, - * keeping in mind the limit from the first paragraph. The optimal size - * also depends on the CPU cache size and other factors; some twiddling - * may be necessary to squeeze out the best performance. - */ -static const uint32_t FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */ - -struct FLAC__BitReader { - /* any partially-consumed word at the head will stay right-justified as bits are consumed from the left */ - /* any incomplete word at the tail will be left-justified, and bytes from the read callback are added on the right */ - brword *buffer; - uint32_t capacity; /* in words */ - uint32_t words; /* # of completed words in buffer */ - uint32_t bytes; /* # of bytes in incomplete word at buffer[words] */ - uint32_t consumed_words; /* #words ... */ - uint32_t consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */ - uint32_t read_crc16; /* the running frame CRC */ - uint32_t crc16_offset; /* the number of words in the current buffer that should not be CRC'd */ - uint32_t crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */ - FLAC__bool read_limit_set; /* whether reads are limited */ - uint32_t read_limit; /* the remaining size of what can be read */ - uint32_t last_seen_framesync; /* the location of the last seen framesync, if it is in the buffer, in bits from front of buffer */ - FLAC__BitReaderReadCallback read_callback; - void *client_data; -}; - -static inline void crc16_update_word_(FLAC__BitReader *br, brword word) -{ - register uint32_t crc = br->read_crc16; - - for ( ; br->crc16_align < FLAC__BITS_PER_WORD ; br->crc16_align += 8) { - uint32_t shift = FLAC__BITS_PER_WORD - 8 - br->crc16_align ; - crc = FLAC__CRC16_UPDATE ((uint32_t) (shift < FLAC__BITS_PER_WORD ? (word >> shift) & 0xff : 0), crc); - } - - br->read_crc16 = crc; - br->crc16_align = 0; -} - -static inline void crc16_update_block_(FLAC__BitReader *br) -{ - if(br->consumed_words > br->crc16_offset && br->crc16_align) - crc16_update_word_(br, br->buffer[br->crc16_offset++]); - - /* Prevent OOB read due to wrap-around. */ - if (br->consumed_words > br->crc16_offset) { -#if FLAC__BYTES_PER_WORD == 4 - br->read_crc16 = FLAC__crc16_update_words32(br->buffer + br->crc16_offset, br->consumed_words - br->crc16_offset, br->read_crc16); -#elif FLAC__BYTES_PER_WORD == 8 - br->read_crc16 = FLAC__crc16_update_words64(br->buffer + br->crc16_offset, br->consumed_words - br->crc16_offset, br->read_crc16); -#else - unsigned i; - - for (i = br->crc16_offset; i < br->consumed_words; i++) - crc16_update_word_(br, br->buffer[i]); -#endif - } - - br->crc16_offset = 0; -} - -static FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br) -{ - uint32_t start, end; - size_t bytes; - FLAC__byte *target; -#if WORDS_BIGENDIAN -#else - brword preswap_backup; -#endif - - /* first shift the unconsumed buffer data toward the front as much as possible */ - if(br->consumed_words > 0) { - /* invalidate last seen framesync */ - br->last_seen_framesync = -1; - - crc16_update_block_(br); /* CRC consumed words */ - - start = br->consumed_words; - end = br->words + (br->bytes? 1:0); - memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start)); - - br->words -= start; - br->consumed_words = 0; - } - - /* - * set the target for reading, taking into account word alignment and endianness - */ - bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes; - if(bytes == 0) - return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */ - target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes; - - /* before reading, if the existing reader looks like this (say brword is 32 bits wide) - * bitstream : 11 22 33 44 55 br->words=1 br->bytes=1 (partial tail word is left-justified) - * buffer[BE]: 11 22 33 44 55 ?? ?? ?? (shown laid out as bytes sequentially in memory) - * buffer[LE]: 44 33 22 11 ?? ?? ?? 55 (?? being don't-care) - * ^^-------target, bytes=3 - * on LE machines, have to byteswap the odd tail word so nothing is - * overwritten: - */ -#if WORDS_BIGENDIAN -#else - preswap_backup = br->buffer[br->words]; - if(br->bytes) - br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]); -#endif - - /* now it looks like: - * bitstream : 11 22 33 44 55 br->words=1 br->bytes=1 - * buffer[BE]: 11 22 33 44 55 ?? ?? ?? - * buffer[LE]: 44 33 22 11 55 ?? ?? ?? - * ^^-------target, bytes=3 - */ - - /* read in the data; note that the callback may return a smaller number of bytes */ - if(!br->read_callback(target, &bytes, br->client_data)){ - /* Despite the read callback failing, the data in the target - * might be used later, when the buffer is rewound. Therefore - * we revert the swap that was just done */ -#if WORDS_BIGENDIAN -#else - br->buffer[br->words] = preswap_backup; -#endif - return false; - } - - /* after reading bytes 66 77 88 99 AA BB CC DD EE FF from the client: - * bitstream : 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF - * buffer[BE]: 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF ?? - * buffer[LE]: 44 33 22 11 55 66 77 88 99 AA BB CC DD EE FF ?? - * now have to byteswap on LE machines: - */ -#if WORDS_BIGENDIAN -#else - end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + (uint32_t)bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD; - for(start = br->words; start < end; start++) - br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]); -#endif - - /* now it looks like: - * bitstream : 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF - * buffer[BE]: 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF ?? - * buffer[LE]: 44 33 22 11 88 77 66 55 CC BB AA 99 ?? FF EE DD - * finally we'll update the reader values: - */ - end = br->words*FLAC__BYTES_PER_WORD + br->bytes + (uint32_t)bytes; - br->words = end / FLAC__BYTES_PER_WORD; - br->bytes = end % FLAC__BYTES_PER_WORD; - - return true; -} - -/*********************************************************************** - * - * Class constructor/destructor - * - ***********************************************************************/ - -FLAC__BitReader *FLAC__bitreader_new(void) -{ - FLAC__BitReader *br = calloc(1, sizeof(FLAC__BitReader)); - - /* calloc() implies: - memset(br, 0, sizeof(FLAC__BitReader)); - br->buffer = 0; - br->capacity = 0; - br->words = br->bytes = 0; - br->consumed_words = br->consumed_bits = 0; - br->read_callback = 0; - br->client_data = 0; - */ - return br; -} - -void FLAC__bitreader_delete(FLAC__BitReader *br) -{ - FLAC__ASSERT(0 != br); - - FLAC__bitreader_free(br); - free(br); -} - -/*********************************************************************** - * - * Public class methods - * - ***********************************************************************/ - -FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__BitReaderReadCallback rcb, void *cd) -{ - FLAC__ASSERT(0 != br); - - br->words = br->bytes = 0; - br->consumed_words = br->consumed_bits = 0; - br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY; - br->buffer = malloc(sizeof(brword) * br->capacity); - if(br->buffer == 0) - return false; - br->read_callback = rcb; - br->client_data = cd; - br->read_limit_set = false; - br->read_limit = -1; - br->last_seen_framesync = -1; - - return true; -} - -void FLAC__bitreader_free(FLAC__BitReader *br) -{ - FLAC__ASSERT(0 != br); - - if(0 != br->buffer) - free(br->buffer); - br->buffer = 0; - br->capacity = 0; - br->words = br->bytes = 0; - br->consumed_words = br->consumed_bits = 0; - br->read_callback = 0; - br->client_data = 0; - br->read_limit_set = false; - br->read_limit = -1; - br->last_seen_framesync = -1; -} - -FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br) -{ - br->words = br->bytes = 0; - br->consumed_words = br->consumed_bits = 0; - br->read_limit_set = false; - br->read_limit = -1; - br->last_seen_framesync = -1; - return true; -} - -void FLAC__bitreader_set_framesync_location(FLAC__BitReader *br) -{ - br->last_seen_framesync = br->consumed_words * FLAC__BYTES_PER_WORD + br->consumed_bits / 8; -} - -FLAC__bool FLAC__bitreader_rewind_to_after_last_seen_framesync(FLAC__BitReader *br) -{ - if(br->last_seen_framesync == (uint32_t)-1) { - br->consumed_words = br->consumed_bits = 0; - return false; - } - else { - br->consumed_words = (br->last_seen_framesync + 1) / FLAC__BYTES_PER_WORD; - br->consumed_bits = ((br->last_seen_framesync + 1) % FLAC__BYTES_PER_WORD) * 8; - return true; - } -} - -void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed) -{ - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - FLAC__ASSERT((br->consumed_bits & 7) == 0); - - br->read_crc16 = (uint32_t)seed; - br->crc16_offset = br->consumed_words; - br->crc16_align = br->consumed_bits; -} - -FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br) -{ - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - - /* CRC consumed words up to here */ - crc16_update_block_(br); - - FLAC__ASSERT((br->consumed_bits & 7) == 0); - FLAC__ASSERT(br->crc16_align <= br->consumed_bits); - - /* CRC any tail bytes in a partially-consumed word */ - if(br->consumed_bits) { - const brword tail = br->buffer[br->consumed_words]; - for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8) - br->read_crc16 = FLAC__CRC16_UPDATE((uint32_t)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16); - } - return br->read_crc16; -} - -inline FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br) -{ - return ((br->consumed_bits & 7) == 0); -} - -inline uint32_t FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br) -{ - return 8 - (br->consumed_bits & 7); -} - -inline uint32_t FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br) -{ - return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits; -} - -void FLAC__bitreader_set_limit(FLAC__BitReader *br, uint32_t limit) -{ - br->read_limit = limit; - br->read_limit_set = true; -} - -void FLAC__bitreader_remove_limit(FLAC__BitReader *br) -{ - br->read_limit_set = false; - br->read_limit = -1; -} - -uint32_t FLAC__bitreader_limit_remaining(FLAC__BitReader *br) -{ - FLAC__ASSERT(br->read_limit_set); - return br->read_limit; -} -void FLAC__bitreader_limit_invalidate(FLAC__BitReader *br) -{ - br->read_limit = -1; -} - -FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, uint32_t bits) -{ - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - - FLAC__ASSERT(bits <= 32); - FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits); - FLAC__ASSERT(br->consumed_words <= br->words); - - /* WATCHOUT: code does not work with <32bit words; we can make things much faster with this assertion */ - FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32); - - if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */ - *val = 0; - return true; - } - - if(br->read_limit_set && br->read_limit < (uint32_t)-1){ - if(br->read_limit < bits) { - br->read_limit = -1; - return false; - } - else - br->read_limit -= bits; - } - - while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) { - if(!bitreader_read_from_client_(br)) - return false; - } - if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */ - /* OPT: taking out the consumed_bits==0 "else" case below might make things faster if less code allows the compiler to inline this function */ - if(br->consumed_bits) { - /* this also works when consumed_bits==0, it's just a little slower than necessary for that case */ - const uint32_t n = FLAC__BITS_PER_WORD - br->consumed_bits; - const brword word = br->buffer[br->consumed_words]; - const brword mask = br->consumed_bits < FLAC__BITS_PER_WORD ? FLAC__WORD_ALL_ONES >> br->consumed_bits : 0; - if(bits < n) { - uint32_t shift = n - bits; - *val = shift < FLAC__BITS_PER_WORD ? (FLAC__uint32)((word & mask) >> shift) : 0; /* The result has <= 32 non-zero bits */ - br->consumed_bits += bits; - return true; - } - /* (FLAC__BITS_PER_WORD - br->consumed_bits <= bits) ==> (FLAC__WORD_ALL_ONES >> br->consumed_bits) has no more than 'bits' non-zero bits */ - *val = (FLAC__uint32)(word & mask); - bits -= n; - br->consumed_words++; - br->consumed_bits = 0; - if(bits) { /* if there are still bits left to read, there have to be less than 32 so they will all be in the next word */ - uint32_t shift = FLAC__BITS_PER_WORD - bits; - *val = bits < 32 ? *val << bits : 0; - *val |= shift < FLAC__BITS_PER_WORD ? (FLAC__uint32)(br->buffer[br->consumed_words] >> shift) : 0; - br->consumed_bits = bits; - } - return true; - } - else { /* br->consumed_bits == 0 */ - const brword word = br->buffer[br->consumed_words]; - if(bits < FLAC__BITS_PER_WORD) { - *val = (FLAC__uint32)(word >> (FLAC__BITS_PER_WORD-bits)); - br->consumed_bits = bits; - return true; - } - /* at this point bits == FLAC__BITS_PER_WORD == 32; because of previous assertions, it can't be larger */ - *val = (FLAC__uint32)word; - br->consumed_words++; - return true; - } - } - else { - /* in this case we're starting our read at a partial tail word; - * the reader has guaranteed that we have at least 'bits' bits - * available to read, which makes this case simpler. - */ - /* OPT: taking out the consumed_bits==0 "else" case below might make things faster if less code allows the compiler to inline this function */ - if(br->consumed_bits) { - /* this also works when consumed_bits==0, it's just a little slower than necessary for that case */ - FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8); - *val = (FLAC__uint32)((br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits)); - br->consumed_bits += bits; - return true; - } - else { - *val = (FLAC__uint32)(br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits)); - br->consumed_bits += bits; - return true; - } - } -} - -FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, uint32_t bits) -{ - FLAC__uint32 uval, mask; - /* OPT: inline raw uint32 code here, or make into a macro if possible in the .h file */ - if (bits < 1 || ! FLAC__bitreader_read_raw_uint32(br, &uval, bits)) - return false; - /* sign-extend *val assuming it is currently bits wide. */ - /* From: https://graphics.stanford.edu/~seander/bithacks.html#FixedSignExtend */ - mask = bits >= 33 ? 0 : 1lu << (bits - 1); - *val = (uval ^ mask) - mask; - return true; -} - -FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, uint32_t bits) -{ - FLAC__uint32 hi, lo; - - if(bits > 32) { - if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32)) - return false; - if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32)) - return false; - *val = hi; - *val <<= 32; - *val |= lo; - } - else { - if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits)) - return false; - *val = lo; - } - return true; -} - -FLAC__bool FLAC__bitreader_read_raw_int64(FLAC__BitReader *br, FLAC__int64 *val, uint32_t bits) -{ - FLAC__uint64 uval, mask; - /* OPT: inline raw uint64 code here, or make into a macro if possible in the .h file */ - if (bits < 1 || ! FLAC__bitreader_read_raw_uint64(br, &uval, bits)) - return false; - /* sign-extend *val assuming it is currently bits wide. */ - /* From: https://graphics.stanford.edu/~seander/bithacks.html#FixedSignExtend */ - mask = bits >= 65 ? 0 : 1llu << (bits - 1); - *val = (uval ^ mask) - mask; - return true; -} - -inline FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val) -{ - FLAC__uint32 x8, x32 = 0; - - /* this doesn't need to be that fast as currently it is only used for vorbis comments */ - - if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8)) - return false; - - if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8)) - return false; - x32 |= (x8 << 8); - - if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8)) - return false; - x32 |= (x8 << 16); - - if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8)) - return false; - x32 |= (x8 << 24); - - *val = x32; - return true; -} - -FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, uint32_t bits) -{ - /* - * OPT: a faster implementation is possible but probably not that useful - * since this is only called a couple of times in the metadata readers. - */ - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - - if(bits > 0) { - const uint32_t n = br->consumed_bits & 7; - uint32_t m; - FLAC__uint32 x; - - if(n != 0) { - m = flac_min(8-n, bits); - if(!FLAC__bitreader_read_raw_uint32(br, &x, m)) - return false; - bits -= m; - } - m = bits / 8; - if(m > 0) { - if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m)) - return false; - bits %= 8; - } - if(bits > 0) { - if(!FLAC__bitreader_read_raw_uint32(br, &x, bits)) - return false; - } - } - - return true; -} - -FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, uint32_t nvals) -{ - FLAC__uint32 x; - - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br)); - - if(br->read_limit_set && br->read_limit < (uint32_t)-1){ - if(br->read_limit < nvals*8){ - br->read_limit = -1; - return false; - } - } - - /* step 1: skip over partial head word to get word aligned */ - while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */ - if(!FLAC__bitreader_read_raw_uint32(br, &x, 8)) - return false; - nvals--; - } - if(0 == nvals) - return true; - - /* step 2: skip whole words in chunks */ - while(nvals >= FLAC__BYTES_PER_WORD) { - if(br->consumed_words < br->words) { - br->consumed_words++; - nvals -= FLAC__BYTES_PER_WORD; - if(br->read_limit_set) - br->read_limit -= FLAC__BITS_PER_WORD; - } - else if(!bitreader_read_from_client_(br)) - return false; - } - /* step 3: skip any remainder from partial tail bytes */ - while(nvals) { - if(!FLAC__bitreader_read_raw_uint32(br, &x, 8)) - return false; - nvals--; - } - - return true; -} - -FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, uint32_t nvals) -{ - FLAC__uint32 x; - - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br)); - - if(br->read_limit_set && br->read_limit < (uint32_t)-1){ - if(br->read_limit < nvals*8){ - br->read_limit = -1; - return false; - } - } - - /* step 1: read from partial head word to get word aligned */ - while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */ - if(!FLAC__bitreader_read_raw_uint32(br, &x, 8)) - return false; - *val++ = (FLAC__byte)x; - nvals--; - } - if(0 == nvals) - return true; - /* step 2: read whole words in chunks */ - while(nvals >= FLAC__BYTES_PER_WORD) { - if(br->consumed_words < br->words) { - const brword word = br->buffer[br->consumed_words++]; -#if FLAC__BYTES_PER_WORD == 4 - val[0] = (FLAC__byte)(word >> 24); - val[1] = (FLAC__byte)(word >> 16); - val[2] = (FLAC__byte)(word >> 8); - val[3] = (FLAC__byte)word; -#elif FLAC__BYTES_PER_WORD == 8 - val[0] = (FLAC__byte)(word >> 56); - val[1] = (FLAC__byte)(word >> 48); - val[2] = (FLAC__byte)(word >> 40); - val[3] = (FLAC__byte)(word >> 32); - val[4] = (FLAC__byte)(word >> 24); - val[5] = (FLAC__byte)(word >> 16); - val[6] = (FLAC__byte)(word >> 8); - val[7] = (FLAC__byte)word; -#else - for(x = 0; x < FLAC__BYTES_PER_WORD; x++) - val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1))); -#endif - val += FLAC__BYTES_PER_WORD; - nvals -= FLAC__BYTES_PER_WORD; - if(br->read_limit_set) - br->read_limit -= FLAC__BITS_PER_WORD; - } - else if(!bitreader_read_from_client_(br)) - return false; - } - /* step 3: read any remainder from partial tail bytes */ - while(nvals) { - if(!FLAC__bitreader_read_raw_uint32(br, &x, 8)) - return false; - *val++ = (FLAC__byte)x; - nvals--; - } - - return true; -} - -FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, uint32_t *val) -#if 0 /* slow but readable version */ -{ - uint32_t bit; - - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - - *val = 0; - while(1) { - if(!FLAC__bitreader_read_bit(br, &bit)) - return false; - if(bit) - break; - else - *val++; - } - return true; -} -#else -{ - uint32_t i; - - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - - *val = 0; - while(1) { - while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */ - brword b = br->consumed_bits < FLAC__BITS_PER_WORD ? br->buffer[br->consumed_words] << br->consumed_bits : 0; - if(b) { - i = COUNT_ZERO_MSBS(b); - *val += i; - i++; - br->consumed_bits += i; - if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */ - br->consumed_words++; - br->consumed_bits = 0; - } - return true; - } - else { - *val += FLAC__BITS_PER_WORD - br->consumed_bits; - br->consumed_words++; - br->consumed_bits = 0; - /* didn't find stop bit yet, have to keep going... */ - } - } - /* at this point we've eaten up all the whole words; have to try - * reading through any tail bytes before calling the read callback. - * this is a repeat of the above logic adjusted for the fact we - * don't have a whole word. note though if the client is feeding - * us data a byte at a time (unlikely), br->consumed_bits may not - * be zero. - */ - if(br->bytes*8 > br->consumed_bits) { - const uint32_t end = br->bytes * 8; - brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits; - if(b) { - i = COUNT_ZERO_MSBS(b); - *val += i; - i++; - br->consumed_bits += i; - FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD); - return true; - } - else { - *val += end - br->consumed_bits; - br->consumed_bits = end; - FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD); - /* didn't find stop bit yet, have to keep going... */ - } - } - if(!bitreader_read_from_client_(br)) - return false; - } -} -#endif - -#if 0 /* unused */ -FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, uint32_t parameter) -{ - FLAC__uint32 lsbs = 0, msbs = 0; - uint32_t uval; - - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - FLAC__ASSERT(parameter <= 31); - - /* read the unary MSBs and end bit */ - if(!FLAC__bitreader_read_unary_unsigned(br, &msbs)) - return false; - - /* read the binary LSBs */ - if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter)) - return false; - - /* compose the value */ - uval = (msbs << parameter) | lsbs; - if(uval & 1) - *val = -((int)(uval >> 1)) - 1; - else - *val = (int)(uval >> 1); - - return true; -} -#endif - -/* this is by far the most heavily used reader call. it ain't pretty but it's fast */ -FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter) -#include "deduplication/bitreader_read_rice_signed_block.c" - -#ifdef FLAC__BMI2_SUPPORTED -FLAC__SSE_TARGET("bmi2") -FLAC__bool FLAC__bitreader_read_rice_signed_block_bmi2(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter) -#include "deduplication/bitreader_read_rice_signed_block.c" -#endif - -#if 0 /* UNUSED */ -FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, uint32_t parameter) -{ - FLAC__uint32 lsbs = 0, msbs = 0; - uint32_t bit, uval, k; - - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - - k = FLAC__bitmath_ilog2(parameter); - - /* read the unary MSBs and end bit */ - if(!FLAC__bitreader_read_unary_unsigned(br, &msbs)) - return false; - - /* read the binary LSBs */ - if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k)) - return false; - - if(parameter == 1u<= d) { - if(!FLAC__bitreader_read_bit(br, &bit)) - return false; - lsbs <<= 1; - lsbs |= bit; - lsbs -= d; - } - /* compose the value */ - uval = msbs * parameter + lsbs; - } - - /* unfold uint32_t to signed */ - if(uval & 1) - *val = -((int)(uval >> 1)) - 1; - else - *val = (int)(uval >> 1); - - return true; -} - -FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, uint32_t *val, uint32_t parameter) -{ - FLAC__uint32 lsbs, msbs = 0; - uint32_t bit, k; - - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - - k = FLAC__bitmath_ilog2(parameter); - - /* read the unary MSBs and end bit */ - if(!FLAC__bitreader_read_unary_unsigned(br, &msbs)) - return false; - - /* read the binary LSBs */ - if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k)) - return false; - - if(parameter == 1u<= d) { - if(!FLAC__bitreader_read_bit(br, &bit)) - return false; - lsbs <<= 1; - lsbs |= bit; - lsbs -= d; - } - /* compose the value */ - *val = msbs * parameter + lsbs; - } - - return true; -} -#endif /* UNUSED */ - -/* on return, if *val == 0xffffffff then the utf-8 sequence was invalid, but the return value will be true */ -FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, uint32_t *rawlen) -{ - FLAC__uint32 v = 0; - FLAC__uint32 x; - uint32_t i; - - if(!FLAC__bitreader_read_raw_uint32(br, &x, 8)) - return false; - if(raw) - raw[(*rawlen)++] = (FLAC__byte)x; - if(!(x & 0x80)) { /* 0xxxxxxx */ - v = x; - i = 0; - } - else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */ - v = x & 0x1F; - i = 1; - } - else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */ - v = x & 0x0F; - i = 2; - } - else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */ - v = x & 0x07; - i = 3; - } - else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */ - v = x & 0x03; - i = 4; - } - else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */ - v = x & 0x01; - i = 5; - } - else { - *val = 0xffffffff; - return true; - } - for( ; i; i--) { - if(!FLAC__bitreader_read_raw_uint32(br, &x, 8)) - return false; - if(raw) - raw[(*rawlen)++] = (FLAC__byte)x; - if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */ - *val = 0xffffffff; - return true; - } - v <<= 6; - v |= (x & 0x3F); - } - *val = v; - return true; -} - -/* on return, if *val == 0xffffffffffffffff then the utf-8 sequence was invalid, but the return value will be true */ -FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, uint32_t *rawlen) -{ - FLAC__uint64 v = 0; - FLAC__uint32 x; - uint32_t i; - - if(!FLAC__bitreader_read_raw_uint32(br, &x, 8)) - return false; - if(raw) - raw[(*rawlen)++] = (FLAC__byte)x; - if(!(x & 0x80)) { /* 0xxxxxxx */ - v = x; - i = 0; - } - else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */ - v = x & 0x1F; - i = 1; - } - else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */ - v = x & 0x0F; - i = 2; - } - else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */ - v = x & 0x07; - i = 3; - } - else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */ - v = x & 0x03; - i = 4; - } - else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */ - v = x & 0x01; - i = 5; - } - else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */ - v = 0; - i = 6; - } - else { - *val = FLAC__U64L(0xffffffffffffffff); - return true; - } - for( ; i; i--) { - if(!FLAC__bitreader_read_raw_uint32(br, &x, 8)) - return false; - if(raw) - raw[(*rawlen)++] = (FLAC__byte)x; - if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */ - *val = FLAC__U64L(0xffffffffffffffff); - return true; - } - v <<= 6; - v |= (x & 0x3F); - } - *val = v; - return true; -} - -/* These functions are declared inline in this file but are also callable as - * externs from elsewhere. - * According to the C99 spec, section 6.7.4, simply providing a function - * prototype in a header file without 'inline' and making the function inline - * in this file should be sufficient. - * Unfortunately, the Microsoft VS compiler doesn't pick them up externally. To - * fix that we add extern declarations here. - */ -extern FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br); -extern uint32_t FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br); -extern uint32_t FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br); -extern FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); diff --git a/flac/src/libFLAC/bitwriter.c b/flac/src/libFLAC/bitwriter.c deleted file mode 100644 index 1d7be80..0000000 --- a/flac/src/libFLAC/bitwriter.c +++ /dev/null @@ -1,955 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "private/bitwriter.h" -#include "private/crc.h" -#include "private/format.h" -#include "private/macros.h" -#include "private/stream_encoder.h" -#include "FLAC/assert.h" -#include "share/alloc.h" -#include "share/compat.h" -#include "share/endswap.h" - -/* Things should be fastest when this matches the machine word size */ -/* WATCHOUT: if you change this you must also change the following #defines down to SWAP_BE_WORD_TO_HOST below to match */ -/* WATCHOUT: there are a few places where the code will not work unless bwword is >= 32 bits wide */ - -#if (ENABLE_64_BIT_WORDS == 0) - -typedef FLAC__uint32 bwword; -typedef FLAC__uint64 FLAC__bwtemp; -#define FLAC__BYTES_PER_WORD 4 /* sizeof bwword */ -#define FLAC__BITS_PER_WORD 32 -#define FLAC__TEMP_BITS 64 -#define FLAC__HALF_TEMP_BITS 32 -/* SWAP_BE_WORD_TO_HOST swaps bytes in a bwword (which is always big-endian) if necessary to match host byte order */ -#if WORDS_BIGENDIAN -#define SWAP_BE_WORD_TO_HOST(x) (x) -#else -#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x) -#endif - -#else - -typedef FLAC__uint64 bwword; -typedef FLAC__uint64 FLAC__bwtemp; -#define FLAC__BYTES_PER_WORD 8 /* sizeof bwword */ -#define FLAC__BITS_PER_WORD 64 -#define FLAC__TEMP_BITS 64 -#define FLAC__HALF_TEMP_BITS 32 -/* SWAP_BE_WORD_TO_HOST swaps bytes in a bwword (which is always big-endian) if necessary to match host byte order */ -#if WORDS_BIGENDIAN -#define SWAP_BE_WORD_TO_HOST(x) (x) -#else -#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_64(x) -#endif - -#endif - -/* - * The default capacity here doesn't matter too much. The buffer always grows - * to hold whatever is written to it. Usually the encoder will stop adding at - * a frame or metadata block, then write that out and clear the buffer for the - * next one. - */ -static const uint32_t FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */ -/* When growing, increment 4K at a time */ -static const uint32_t FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */ - -#define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD) -#define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits) - -struct FLAC__BitWriter { - bwword *buffer; - bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */ - uint32_t capacity; /* capacity of buffer in words */ - uint32_t words; /* # of complete words in buffer */ - uint32_t bits; /* # of used bits in accum */ -}; - -/* * WATCHOUT: The current implementation only grows the buffer. */ -#ifndef __SUNPRO_C -static -#endif -FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, uint32_t bits_to_add) -{ - uint32_t new_capacity; - bwword *new_buffer; - - FLAC__ASSERT(0 != bw); - FLAC__ASSERT(0 != bw->buffer); - - /* calculate total words needed to store 'bits_to_add' additional bits */ - new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD); - - /* it's possible (due to pessimism in the growth estimation that - * leads to this call) that we don't actually need to grow - */ - if(bw->capacity >= new_capacity) - return true; - - if(new_capacity * sizeof(bwword) > (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) - /* Requested new capacity is larger than the largest possible metadata block, - * which is also larger than the largest sane framesize. That means something - * went very wrong somewhere and previous checks failed. - * To prevent chrashing, give up */ - return false; - - /* round up capacity increase to the nearest FLAC__BITWRITER_DEFAULT_INCREMENT */ - if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT) - new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT); - /* make sure we got everything right */ - FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT); - FLAC__ASSERT(new_capacity > bw->capacity); - FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD)); - - new_buffer = safe_realloc_nofree_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity); - if(new_buffer == 0) - return false; - bw->buffer = new_buffer; - bw->capacity = new_capacity; - return true; -} - - -/*********************************************************************** - * - * Class constructor/destructor - * - ***********************************************************************/ - -FLAC__BitWriter *FLAC__bitwriter_new(void) -{ - FLAC__BitWriter *bw = calloc(1, sizeof(FLAC__BitWriter)); - /* note that calloc() sets all members to 0 for us */ - return bw; -} - -void FLAC__bitwriter_delete(FLAC__BitWriter *bw) -{ - FLAC__ASSERT(0 != bw); - - FLAC__bitwriter_free(bw); - free(bw); -} - -/*********************************************************************** - * - * Public class methods - * - ***********************************************************************/ - -FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw) -{ - FLAC__ASSERT(0 != bw); - - bw->words = bw->bits = 0; - bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY; - bw->buffer = malloc(sizeof(bwword) * bw->capacity); - if(bw->buffer == 0) - return false; - - return true; -} - -void FLAC__bitwriter_free(FLAC__BitWriter *bw) -{ - FLAC__ASSERT(0 != bw); - - if(0 != bw->buffer) - free(bw->buffer); - bw->buffer = 0; - bw->capacity = 0; - bw->words = bw->bits = 0; -} - -void FLAC__bitwriter_clear(FLAC__BitWriter *bw) -{ - bw->words = bw->bits = 0; -} - -FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc) -{ - const FLAC__byte *buffer; - size_t bytes; - - FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */ - - if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes)) - return false; - - *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes); - FLAC__bitwriter_release_buffer(bw); - return true; -} - -FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc) -{ - const FLAC__byte *buffer; - size_t bytes; - - FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */ - - if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes)) - return false; - - *crc = FLAC__crc8(buffer, bytes); - FLAC__bitwriter_release_buffer(bw); - return true; -} - -FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw) -{ - return ((bw->bits & 7) == 0); -} - -uint32_t FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw) -{ - return FLAC__TOTAL_BITS(bw); -} - -FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes) -{ - FLAC__ASSERT((bw->bits & 7) == 0); - /* double protection */ - if(bw->bits & 7) - return false; - /* if we have bits in the accumulator we have to flush those to the buffer first */ - if(bw->bits) { - FLAC__ASSERT(bw->words <= bw->capacity); - if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD)) - return false; - /* append bits as complete word to buffer, but don't change bw->accum or bw->bits */ - bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits)); - } - /* now we can just return what we have */ - *buffer = (FLAC__byte*)bw->buffer; - *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3); - return true; -} - -void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw) -{ - /* nothing to do. in the future, strict checking of a 'writer-is-in- - * get-mode' flag could be added everywhere and then cleared here - */ - (void)bw; -} - -inline FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, uint32_t bits) -{ - uint32_t n; - - FLAC__ASSERT(0 != bw); - FLAC__ASSERT(0 != bw->buffer); - - if(bits == 0) - return true; - /* slightly pessimistic size check but faster than "<= bw->words + (bw->bits+bits+FLAC__BITS_PER_WORD-1)/FLAC__BITS_PER_WORD" */ - if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits)) - return false; - /* first part gets to word alignment */ - if(bw->bits) { - n = flac_min(FLAC__BITS_PER_WORD - bw->bits, bits); - bw->accum <<= n; - bits -= n; - bw->bits += n; - if(bw->bits == FLAC__BITS_PER_WORD) { - bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum); - bw->bits = 0; - } - else - return true; - } - /* do whole words */ - while(bits >= FLAC__BITS_PER_WORD) { - bw->buffer[bw->words++] = 0; - bits -= FLAC__BITS_PER_WORD; - } - /* do any leftovers */ - if(bits > 0) { - bw->accum = 0; - bw->bits = bits; - } - return true; -} - -static inline FLAC__bool FLAC__bitwriter_write_raw_uint32_nocheck(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits) -{ - register uint32_t left; - - /* WATCHOUT: code does not work with <32bit words; we can make things much faster with this assertion */ - FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32); - - if(bw == 0 || bw->buffer == 0) - return false; - - if (bits > 32) - return false; - - if(bits == 0) - return true; - - FLAC__ASSERT((bits == 32) || (val>>bits == 0)); - - /* slightly pessimistic size check but faster than "<= bw->words + (bw->bits+bits+FLAC__BITS_PER_WORD-1)/FLAC__BITS_PER_WORD" */ - if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits)) - return false; - - left = FLAC__BITS_PER_WORD - bw->bits; - if(bits < left) { - bw->accum <<= bits; - bw->accum |= val; - bw->bits += bits; - } - else if(bw->bits) { /* WATCHOUT: if bw->bits == 0, left==FLAC__BITS_PER_WORD and bw->accum<<=left is a NOP instead of setting to 0 */ - bw->accum <<= left; - bw->accum |= val >> (bw->bits = bits - left); - bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum); - bw->accum = val; /* unused top bits can contain garbage */ - } - else { /* at this point bits == FLAC__BITS_PER_WORD == 32 and bw->bits == 0 */ - bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST((bwword)val); - } - - return true; -} - -inline FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits) -{ - /* check that unused bits are unset */ - if((bits < 32) && (val>>bits != 0)) - return false; - - return FLAC__bitwriter_write_raw_uint32_nocheck(bw, val, bits); -} - -inline FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t bits) -{ - /* zero-out unused bits */ - if(bits < 32) - val &= (~(0xffffffff << bits)); - - return FLAC__bitwriter_write_raw_uint32_nocheck(bw, (FLAC__uint32)val, bits); -} - -inline FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, uint32_t bits) -{ - /* this could be a little faster but it's not used for much */ - if(bits > 32) { - return - FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) && - FLAC__bitwriter_write_raw_uint32_nocheck(bw, (FLAC__uint32)val, 32); - } - else - return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits); -} - -inline FLAC__bool FLAC__bitwriter_write_raw_int64(FLAC__BitWriter *bw, FLAC__int64 val, uint32_t bits) -{ - FLAC__uint64 uval = val; - /* zero-out unused bits */ - if(bits < 64) - uval &= (~(UINT64_MAX << bits)); - return FLAC__bitwriter_write_raw_uint64(bw, uval, bits); -} - -inline FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val) -{ - /* this doesn't need to be that fast as currently it is only used for vorbis comments */ - - if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, val & 0xff, 8)) - return false; - if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, (val>>8) & 0xff, 8)) - return false; - if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, (val>>16) & 0xff, 8)) - return false; - if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, val>>24, 8)) - return false; - - return true; -} - -inline FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], uint32_t nvals) -{ - uint32_t i; - - /* grow capacity upfront to prevent constant reallocation during writes */ - if(bw->capacity <= bw->words + nvals / (FLAC__BITS_PER_WORD / 8) + 1 && !bitwriter_grow_(bw, nvals * 8)) - return false; - - /* this could be faster but currently we don't need it to be since it's only used for writing metadata */ - for(i = 0; i < nvals; i++) { - if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, (FLAC__uint32)(vals[i]), 8)) - return false; - } - - return true; -} - -FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, uint32_t val) -{ - if(val < 32) - return FLAC__bitwriter_write_raw_uint32_nocheck(bw, 1, ++val); - else - return - FLAC__bitwriter_write_zeroes(bw, val) && - FLAC__bitwriter_write_raw_uint32_nocheck(bw, 1, 1); -} - -#if 0 /* UNUSED */ -uint32_t FLAC__bitwriter_rice_bits(FLAC__int32 val, uint32_t parameter) -{ - FLAC__uint32 uval; - - FLAC__ASSERT(parameter < 32); - - /* fold signed to uint32_t; actual formula is: negative(v)? -2v-1 : 2v */ - uval = val; - uval <<= 1; - uval ^= (val>>31); - - return 1 + parameter + (uval >> parameter); -} - -uint32_t FLAC__bitwriter_golomb_bits_signed(int val, uint32_t parameter) -{ - uint32_t bits, msbs, uval; - uint32_t k; - - FLAC__ASSERT(parameter > 0); - - /* fold signed to uint32_t */ - if(val < 0) - uval = (uint32_t)(((-(++val)) << 1) + 1); - else - uval = (uint32_t)(val << 1); - - k = FLAC__bitmath_ilog2(parameter); - if(parameter == 1u<> k; - bits = 1 + k + msbs; - } - else { - uint32_t q, r, d; - - d = (1 << (k+1)) - parameter; - q = uval / parameter; - r = uval - (q * parameter); - - bits = 1 + q + k; - if(r >= d) - bits++; - } - return bits; -} - -uint32_t FLAC__bitwriter_golomb_bits_unsigned(uint32_t uval, uint32_t parameter) -{ - uint32_t bits, msbs; - uint32_t k; - - FLAC__ASSERT(parameter > 0); - - k = FLAC__bitmath_ilog2(parameter); - if(parameter == 1u<> k; - bits = 1 + k + msbs; - } - else { - uint32_t q, r, d; - - d = (1 << (k+1)) - parameter; - q = uval / parameter; - r = uval - (q * parameter); - - bits = 1 + q + k; - if(r >= d) - bits++; - } - return bits; -} - -FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t parameter) -{ - uint32_t total_bits, interesting_bits, msbs; - FLAC__uint32 uval, pattern; - - FLAC__ASSERT(0 != bw); - FLAC__ASSERT(0 != bw->buffer); - FLAC__ASSERT(parameter < 32); - - /* fold signed to uint32_t; actual formula is: negative(v)? -2v-1 : 2v */ - uval = val; - uval <<= 1; - uval ^= (val>>31); - - msbs = uval >> parameter; - interesting_bits = 1 + parameter; - total_bits = interesting_bits + msbs; - pattern = 1 << parameter; /* the unary end bit */ - pattern |= (uval & ((1<accum = wide_accum >> FLAC__HALF_TEMP_BITS; \ - bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum); \ - wide_accum <<= FLAC__HALF_TEMP_BITS; \ - bitpointer += FLAC__HALF_TEMP_BITS; \ -} - -#else - -#define WIDE_ACCUM_TO_BW { \ - FLAC__ASSERT(bw->bits % FLAC__HALF_TEMP_BITS == 0); \ - if(bw->bits == 0) { \ - bw->accum = wide_accum >> FLAC__HALF_TEMP_BITS; \ - wide_accum <<= FLAC__HALF_TEMP_BITS; \ - bw->bits = FLAC__HALF_TEMP_BITS; \ - } \ - else { \ - bw->accum <<= FLAC__HALF_TEMP_BITS; \ - bw->accum += wide_accum >> FLAC__HALF_TEMP_BITS; \ - bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum); \ - wide_accum <<= FLAC__HALF_TEMP_BITS; \ - bw->bits = 0; \ - } \ - bitpointer += FLAC__HALF_TEMP_BITS; \ -} - -#endif - -FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, uint32_t nvals, uint32_t parameter) -{ - const FLAC__uint32 mask1 = (FLAC__uint32)0xffffffff << parameter; /* we val|=mask1 to set the stop bit above it... */ - const FLAC__uint32 mask2 = (FLAC__uint32)0xffffffff >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2 */ - FLAC__uint32 uval; - const uint32_t lsbits = 1 + parameter; - uint32_t msbits, total_bits; - FLAC__bwtemp wide_accum = 0; - FLAC__uint32 bitpointer = FLAC__TEMP_BITS; - - FLAC__ASSERT(0 != bw); - FLAC__ASSERT(0 != bw->buffer); - FLAC__ASSERT(parameter < 31); - /* WATCHOUT: code does not work with <32bit words; we can make things much faster with this assertion */ - FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32); -#if (ENABLE_64_BIT_WORDS == 0) - if(bw->bits > 0) { - bitpointer -= bw->bits; - wide_accum = (FLAC__bwtemp)(bw->accum) << bitpointer; - bw->bits = 0; - } -#else - if(bw->bits > 0 && bw->bits < FLAC__HALF_TEMP_BITS) { - bitpointer -= bw->bits; - wide_accum = bw->accum << bitpointer; - bw->bits = 0; - } - else if(bw->bits > FLAC__HALF_TEMP_BITS) { - bitpointer -= (bw->bits - FLAC__HALF_TEMP_BITS); - wide_accum = bw->accum << bitpointer; - bw->accum >>= (bw->bits - FLAC__HALF_TEMP_BITS); - bw->bits = FLAC__HALF_TEMP_BITS; - } -#endif - - /* Reserve one FLAC__TEMP_BITS per symbol, so checks for space are only necessary when very large symbols are encountered - * this might be considered wasteful, but is only at most 8kB more than necessary for a blocksize of 4096 */ - if(bw->capacity * FLAC__BITS_PER_WORD <= bw->words * FLAC__BITS_PER_WORD + nvals * FLAC__TEMP_BITS + bw->bits && !bitwriter_grow_(bw, nvals * FLAC__TEMP_BITS)) - return false; - - while(nvals) { - /* fold signed to uint32_t; actual formula is: negative(v)? -2v-1 : 2v */ - uval = *vals; - uval <<= 1; - uval ^= (*vals>>31); - - msbits = uval >> parameter; - total_bits = lsbits + msbits; - - uval |= mask1; /* set stop bit */ - uval &= mask2; /* mask off unused top bits */ - - - if(total_bits <= bitpointer) { - /* There is room enough to store the symbol whole at once */ - wide_accum |= (FLAC__bwtemp)(uval) << (bitpointer - total_bits); - bitpointer -= total_bits; - if(bitpointer <= FLAC__HALF_TEMP_BITS) { - /* A word is finished, copy the upper 32 bits of the wide_accum */ - WIDE_ACCUM_TO_BW - } - } - else { - /* The symbol needs to be split. This code isn't used often */ - /* First check for space in the bitwriter */ - if(total_bits > FLAC__TEMP_BITS) { - FLAC__uint32 oversize_in_bits = total_bits - FLAC__TEMP_BITS; - FLAC__uint32 capacity_needed = bw->words * FLAC__BITS_PER_WORD + bw->bits + nvals * FLAC__TEMP_BITS + oversize_in_bits; - if(bw->capacity * FLAC__BITS_PER_WORD <= capacity_needed && !bitwriter_grow_(bw, nvals * FLAC__TEMP_BITS + oversize_in_bits)) - return false; - } - if(msbits > bitpointer) { - /* We have a lot of 0 bits to write, first align with bitwriter word */ - msbits -= bitpointer - FLAC__HALF_TEMP_BITS; - bitpointer = FLAC__HALF_TEMP_BITS; - WIDE_ACCUM_TO_BW - while(msbits > bitpointer) { - /* As the accumulator is already zero, we only need to - * assign zeroes to the bitbuffer */ - WIDE_ACCUM_TO_BW - bitpointer -= FLAC__HALF_TEMP_BITS; - msbits -= FLAC__HALF_TEMP_BITS; - } - /* The remaining bits are zero, and the accumulator already is zero, - * so just subtract the number of bits from bitpointer. When storing, - * we can also just store 0 */ - bitpointer -= msbits; - if(bitpointer <= FLAC__HALF_TEMP_BITS) - WIDE_ACCUM_TO_BW - } - else { - bitpointer -= msbits; - if(bitpointer <= FLAC__HALF_TEMP_BITS) - WIDE_ACCUM_TO_BW - } - /* The lsbs + stop bit always fit 32 bit, so this code mirrors the code above */ - wide_accum |= (FLAC__bwtemp)(uval) << (bitpointer - lsbits); - bitpointer -= lsbits; - if(bitpointer <= FLAC__HALF_TEMP_BITS) { - /* A word is finished, copy the upper 32 bits of the wide_accum */ - WIDE_ACCUM_TO_BW - } - } - vals++; - nvals--; - } - /* Now fixup remainder of wide_accum */ -#if (ENABLE_64_BIT_WORDS == 0) - if(bitpointer < FLAC__TEMP_BITS) { - bw->accum = wide_accum >> bitpointer; - bw->bits = FLAC__TEMP_BITS - bitpointer; - } -#else - if(bitpointer < FLAC__TEMP_BITS) { - if(bw->bits == 0) { - bw->accum = wide_accum >> bitpointer; - bw->bits = FLAC__TEMP_BITS - bitpointer; - } - else if (bw->bits == FLAC__HALF_TEMP_BITS) { - bw->accum <<= FLAC__TEMP_BITS - bitpointer; - bw->accum |= (wide_accum >> bitpointer); - bw->bits = FLAC__HALF_TEMP_BITS + FLAC__TEMP_BITS - bitpointer; - } - else { - FLAC__ASSERT(0); - } - } -#endif - - - return true; -} - -#if 0 /* UNUSED */ -FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, uint32_t parameter) -{ - uint32_t total_bits, msbs, uval; - uint32_t k; - - FLAC__ASSERT(0 != bw); - FLAC__ASSERT(0 != bw->buffer); - FLAC__ASSERT(parameter > 0); - - /* fold signed to uint32_t */ - if(val < 0) - uval = (uint32_t)(((-(++val)) << 1) + 1); - else - uval = (uint32_t)(val << 1); - - k = FLAC__bitmath_ilog2(parameter); - if(parameter == 1u<> k; - total_bits = 1 + k + msbs; - pattern = 1 << k; /* the unary end bit */ - pattern |= (uval & ((1u<= d) { - if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1)) - return false; - } - else { - if(!FLAC__bitwriter_write_raw_uint32(bw, r, k)) - return false; - } - } - return true; -} - -FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, uint32_t uval, uint32_t parameter) -{ - uint32_t total_bits, msbs; - uint32_t k; - - FLAC__ASSERT(0 != bw); - FLAC__ASSERT(0 != bw->buffer); - FLAC__ASSERT(parameter > 0); - - k = FLAC__bitmath_ilog2(parameter); - if(parameter == 1u<> k; - total_bits = 1 + k + msbs; - pattern = 1 << k; /* the unary end bit */ - pattern |= (uval & ((1u<= d) { - if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1)) - return false; - } - else { - if(!FLAC__bitwriter_write_raw_uint32(bw, r, k)) - return false; - } - } - return true; -} -#endif /* UNUSED */ - -FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val) -{ - FLAC__bool ok = 1; - - FLAC__ASSERT(0 != bw); - FLAC__ASSERT(0 != bw->buffer); - - if((val & 0x80000000) != 0) /* this version only handles 31 bits */ - return false; - - if(val < 0x80) { - return FLAC__bitwriter_write_raw_uint32_nocheck(bw, val, 8); - } - else if(val < 0x800) { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xC0 | (val>>6), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (val&0x3F), 8); - } - else if(val < 0x10000) { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xE0 | (val>>12), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>6)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (val&0x3F), 8); - } - else if(val < 0x200000) { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xF0 | (val>>18), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>12)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>6)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (val&0x3F), 8); - } - else if(val < 0x4000000) { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xF8 | (val>>24), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>18)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>12)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>6)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (val&0x3F), 8); - } - else { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xFC | (val>>30), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>24)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>18)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>12)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | ((val>>6)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (val&0x3F), 8); - } - - return ok; -} - -FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val) -{ - FLAC__bool ok = 1; - - FLAC__ASSERT(0 != bw); - FLAC__ASSERT(0 != bw->buffer); - - if((val & FLAC__U64L(0xFFFFFFF000000000)) != 0) /* this version only handles 36 bits */ - return false; - - if(val < 0x80) { - return FLAC__bitwriter_write_raw_uint32_nocheck(bw, (FLAC__uint32)val, 8); - } - else if(val < 0x800) { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xC0 | (FLAC__uint32)(val>>6), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8); - } - else if(val < 0x10000) { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xE0 | (FLAC__uint32)(val>>12), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8); - } - else if(val < 0x200000) { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xF0 | (FLAC__uint32)(val>>18), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8); - } - else if(val < 0x4000000) { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xF8 | (FLAC__uint32)(val>>24), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8); - } - else if(val < 0x80000000) { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xFC | (FLAC__uint32)(val>>30), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8); - } - else { - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0xFE, 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8); - ok &= FLAC__bitwriter_write_raw_uint32_nocheck(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8); - } - - return ok; -} - -FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw) -{ - /* 0-pad to byte boundary */ - if(bw->bits & 7u) - return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u)); - else - return true; -} - -/* These functions are declared inline in this file but are also callable as - * externs from elsewhere. - * According to the C99 spec, section 6.7.4, simply providing a function - * prototype in a header file without 'inline' and making the function inline - * in this file should be sufficient. - * Unfortunately, the Microsoft VS compiler doesn't pick them up externally. To - * fix that we add extern declarations here. - */ -extern FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, uint32_t bits); -extern FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits); -extern FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t bits); -extern FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, uint32_t bits); -extern FLAC__bool FLAC__bitwriter_write_raw_int64(FLAC__BitWriter *bw, FLAC__int64 val, uint32_t bits); -extern FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); -extern FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], uint32_t nvals); diff --git a/flac/src/libFLAC/cpu.c b/flac/src/libFLAC/cpu.c deleted file mode 100644 index d088e3c..0000000 --- a/flac/src/libFLAC/cpu.c +++ /dev/null @@ -1,255 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" -#include "share/compat.h" -#include -#include - -#if defined _MSC_VER -#include /* for __cpuid() and _xgetbv() */ -#elif defined __GNUC__ && defined HAVE_CPUID_H -#include /* for __get_cpuid() and __get_cpuid_max() */ -#endif - -#ifndef NDEBUG -#include -#define dfprintf fprintf -#else -/* This is bad practice, it should be a static void empty function */ -#define dfprintf(file, format, ...) -#endif - -#if defined(HAVE_SYS_AUXV_H) -#include -#endif - -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN && !defined FLAC__NO_ASM - -/* these are flags in EDX of CPUID AX=00000001 */ -static const uint32_t FLAC__CPUINFO_X86_CPUID_CMOV = 0x00008000; -static const uint32_t FLAC__CPUINFO_X86_CPUID_MMX = 0x00800000; -static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE = 0x02000000; -static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE2 = 0x04000000; - -/* these are flags in ECX of CPUID AX=00000001 */ -static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE3 = 0x00000001; -static const uint32_t FLAC__CPUINFO_X86_CPUID_SSSE3 = 0x00000200; -static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE41 = 0x00080000; -static const uint32_t FLAC__CPUINFO_X86_CPUID_SSE42 = 0x00100000; -static const uint32_t FLAC__CPUINFO_X86_CPUID_OSXSAVE = 0x08000000; -static const uint32_t FLAC__CPUINFO_X86_CPUID_AVX = 0x10000000; -static const uint32_t FLAC__CPUINFO_X86_CPUID_FMA = 0x00001000; - -/* these are flags in EBX of CPUID AX=00000007 */ -static const uint32_t FLAC__CPUINFO_X86_CPUID_AVX2 = 0x00000020; -static const uint32_t FLAC__CPUINFO_X86_CPUID_BMI2 = 0x00000100; - -static uint32_t -cpu_xgetbv_x86(void) -{ -#if (defined _MSC_VER || defined __INTEL_COMPILER) && FLAC__AVX_SUPPORTED - return (uint32_t)_xgetbv(0); -#elif defined __GNUC__ - uint32_t lo, hi; - __asm__ volatile (".byte 0x0f, 0x01, 0xd0" : "=a"(lo), "=d"(hi) : "c" (0)); - return lo; -#else - return 0; -#endif -} - -static uint32_t -cpu_have_cpuid(void) -{ -#if defined FLAC__CPU_X86_64 || defined __i686__ || defined __SSE__ || (defined _M_IX86_FP && _M_IX86_FP > 0) - /* target CPU does have CPUID instruction */ - return 1; -#elif defined __GNUC__ && defined HAVE_CPUID_H - if (__get_cpuid_max(0, 0) != 0) - return 1; - else - return 0; -#elif defined _MSC_VER - FLAC__uint32 flags1, flags2; - __asm { - pushfd - pushfd - pop eax - mov flags1, eax - xor eax, 0x200000 - push eax - popfd - pushfd - pop eax - mov flags2, eax - popfd - } - if (((flags1^flags2) & 0x200000) != 0) - return 1; - else - return 0; -#else - return 0; -#endif -} - -static void -cpuinfo_x86(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint32 *ecx, FLAC__uint32 *edx) -{ -#if defined _MSC_VER - int cpuinfo[4]; - int ext = level & 0x80000000; - __cpuid(cpuinfo, ext); - if ((uint32_t)cpuinfo[0] >= level) { -#if FLAC__AVX_SUPPORTED - __cpuidex(cpuinfo, level, 0); /* for AVX2 detection */ -#else - __cpuid(cpuinfo, level); /* some old compilers don't support __cpuidex */ -#endif - *eax = cpuinfo[0]; *ebx = cpuinfo[1]; *ecx = cpuinfo[2]; *edx = cpuinfo[3]; - return; - } -#elif defined __GNUC__ && defined HAVE_CPUID_H - FLAC__uint32 ext = level & 0x80000000; - __cpuid(ext, *eax, *ebx, *ecx, *edx); - if (*eax >= level) { - __cpuid_count(level, 0, *eax, *ebx, *ecx, *edx); - return; - } -#endif - *eax = *ebx = *ecx = *edx = 0; -} - -#endif - -static void -x86_cpu_info (FLAC__CPUInfo *info) -{ -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN && !defined FLAC__NO_ASM - FLAC__bool x86_osxsave = false; - FLAC__bool os_avx = false; - FLAC__uint32 flags_eax, flags_ebx, flags_ecx, flags_edx; - - info->use_asm = true; /* we assume a minimum of 80386 */ - if (!cpu_have_cpuid()) - return; - - cpuinfo_x86(0, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx); - info->x86.intel = (flags_ebx == 0x756E6547 && flags_edx == 0x49656E69 && flags_ecx == 0x6C65746E) ? true : false; /* GenuineIntel */ - cpuinfo_x86(1, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx); - - info->x86.cmov = (flags_edx & FLAC__CPUINFO_X86_CPUID_CMOV ) ? true : false; - info->x86.mmx = (flags_edx & FLAC__CPUINFO_X86_CPUID_MMX ) ? true : false; - info->x86.sse = (flags_edx & FLAC__CPUINFO_X86_CPUID_SSE ) ? true : false; - info->x86.sse2 = (flags_edx & FLAC__CPUINFO_X86_CPUID_SSE2 ) ? true : false; - info->x86.sse3 = (flags_ecx & FLAC__CPUINFO_X86_CPUID_SSE3 ) ? true : false; - info->x86.ssse3 = (flags_ecx & FLAC__CPUINFO_X86_CPUID_SSSE3) ? true : false; - info->x86.sse41 = (flags_ecx & FLAC__CPUINFO_X86_CPUID_SSE41) ? true : false; - info->x86.sse42 = (flags_ecx & FLAC__CPUINFO_X86_CPUID_SSE42) ? true : false; - - if (FLAC__AVX_SUPPORTED) { - x86_osxsave = (flags_ecx & FLAC__CPUINFO_X86_CPUID_OSXSAVE) ? true : false; - info->x86.avx = (flags_ecx & FLAC__CPUINFO_X86_CPUID_AVX ) ? true : false; - info->x86.fma = (flags_ecx & FLAC__CPUINFO_X86_CPUID_FMA ) ? true : false; - cpuinfo_x86(7, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx); - info->x86.avx2 = (flags_ebx & FLAC__CPUINFO_X86_CPUID_AVX2 ) ? true : false; - info->x86.bmi2 = (flags_ebx & FLAC__CPUINFO_X86_CPUID_BMI2 ) ? true : false; - } - -#if defined FLAC__CPU_IA32 - dfprintf(stderr, "CPU info (IA-32):\n"); -#else - dfprintf(stderr, "CPU info (x86-64):\n"); -#endif - dfprintf(stderr, " CMOV ....... %c\n", info->x86.cmov ? 'Y' : 'n'); - dfprintf(stderr, " MMX ........ %c\n", info->x86.mmx ? 'Y' : 'n'); - dfprintf(stderr, " SSE ........ %c\n", info->x86.sse ? 'Y' : 'n'); - dfprintf(stderr, " SSE2 ....... %c\n", info->x86.sse2 ? 'Y' : 'n'); - dfprintf(stderr, " SSE3 ....... %c\n", info->x86.sse3 ? 'Y' : 'n'); - dfprintf(stderr, " SSSE3 ...... %c\n", info->x86.ssse3 ? 'Y' : 'n'); - dfprintf(stderr, " SSE41 ...... %c\n", info->x86.sse41 ? 'Y' : 'n'); - dfprintf(stderr, " SSE42 ...... %c\n", info->x86.sse42 ? 'Y' : 'n'); - - if (FLAC__AVX_SUPPORTED) { - dfprintf(stderr, " AVX ........ %c\n", info->x86.avx ? 'Y' : 'n'); - dfprintf(stderr, " FMA ........ %c\n", info->x86.fma ? 'Y' : 'n'); - dfprintf(stderr, " AVX2 ....... %c\n", info->x86.avx2 ? 'Y' : 'n'); - dfprintf(stderr, " BMI2 ....... %c\n", info->x86.bmi2 ? 'Y' : 'n'); - } - - /* - * now have to check for OS support of AVX instructions - */ - if (FLAC__AVX_SUPPORTED && info->x86.avx && x86_osxsave && (cpu_xgetbv_x86() & 0x6) == 0x6) { - os_avx = true; - } - if (os_avx) { - dfprintf(stderr, " AVX OS sup . %c\n", info->x86.avx ? 'Y' : 'n'); - } - if (!os_avx) { - /* no OS AVX support */ - info->x86.avx = false; - info->x86.avx2 = false; - info->x86.fma = false; - } -#else - info->use_asm = false; -#endif -} - -void FLAC__cpu_info (FLAC__CPUInfo *info) -{ - memset(info, 0, sizeof(*info)); - -#ifdef FLAC__CPU_IA32 - info->type = FLAC__CPUINFO_TYPE_IA32; -#elif defined FLAC__CPU_X86_64 - info->type = FLAC__CPUINFO_TYPE_X86_64; -#else - info->type = FLAC__CPUINFO_TYPE_UNKNOWN; -#endif - - switch (info->type) { - case FLAC__CPUINFO_TYPE_IA32: /* fallthrough */ - case FLAC__CPUINFO_TYPE_X86_64: - x86_cpu_info (info); - break; - default: - info->use_asm = false; - break; - } -} diff --git a/flac/src/libFLAC/crc.c b/flac/src/libFLAC/crc.c deleted file mode 100644 index 9e488e9..0000000 --- a/flac/src/libFLAC/crc.c +++ /dev/null @@ -1,436 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/crc.h" - -/* CRC-8, poly = x^8 + x^2 + x^1 + x^0, init = 0 */ - -FLAC__uint8 const FLAC__crc8_table[256] = { - 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, - 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D, - 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, - 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, - 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, - 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD, - 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, - 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD, - 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, - 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, - 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2, - 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A, - 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, - 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A, - 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, - 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, - 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C, - 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4, - 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, - 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4, - 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, - 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44, - 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C, - 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34, - 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, - 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63, - 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, - 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, - 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB, - 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83, - 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, - 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3 -}; - -/* CRC-16, poly = x^16 + x^15 + x^2 + x^0, init = 0 */ - -FLAC__uint16 const FLAC__crc16_table[8][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 }, - - { 0x0000, 0x8603, 0x8c03, 0x0a00, 0x9803, 0x1e00, 0x1400, 0x9203, - 0xb003, 0x3600, 0x3c00, 0xba03, 0x2800, 0xae03, 0xa403, 0x2200, - 0xe003, 0x6600, 0x6c00, 0xea03, 0x7800, 0xfe03, 0xf403, 0x7200, - 0x5000, 0xd603, 0xdc03, 0x5a00, 0xc803, 0x4e00, 0x4400, 0xc203, - 0x4003, 0xc600, 0xcc00, 0x4a03, 0xd800, 0x5e03, 0x5403, 0xd200, - 0xf000, 0x7603, 0x7c03, 0xfa00, 0x6803, 0xee00, 0xe400, 0x6203, - 0xa000, 0x2603, 0x2c03, 0xaa00, 0x3803, 0xbe00, 0xb400, 0x3203, - 0x1003, 0x9600, 0x9c00, 0x1a03, 0x8800, 0x0e03, 0x0403, 0x8200, - 0x8006, 0x0605, 0x0c05, 0x8a06, 0x1805, 0x9e06, 0x9406, 0x1205, - 0x3005, 0xb606, 0xbc06, 0x3a05, 0xa806, 0x2e05, 0x2405, 0xa206, - 0x6005, 0xe606, 0xec06, 0x6a05, 0xf806, 0x7e05, 0x7405, 0xf206, - 0xd006, 0x5605, 0x5c05, 0xda06, 0x4805, 0xce06, 0xc406, 0x4205, - 0xc005, 0x4606, 0x4c06, 0xca05, 0x5806, 0xde05, 0xd405, 0x5206, - 0x7006, 0xf605, 0xfc05, 0x7a06, 0xe805, 0x6e06, 0x6406, 0xe205, - 0x2006, 0xa605, 0xac05, 0x2a06, 0xb805, 0x3e06, 0x3406, 0xb205, - 0x9005, 0x1606, 0x1c06, 0x9a05, 0x0806, 0x8e05, 0x8405, 0x0206, - 0x8009, 0x060a, 0x0c0a, 0x8a09, 0x180a, 0x9e09, 0x9409, 0x120a, - 0x300a, 0xb609, 0xbc09, 0x3a0a, 0xa809, 0x2e0a, 0x240a, 0xa209, - 0x600a, 0xe609, 0xec09, 0x6a0a, 0xf809, 0x7e0a, 0x740a, 0xf209, - 0xd009, 0x560a, 0x5c0a, 0xda09, 0x480a, 0xce09, 0xc409, 0x420a, - 0xc00a, 0x4609, 0x4c09, 0xca0a, 0x5809, 0xde0a, 0xd40a, 0x5209, - 0x7009, 0xf60a, 0xfc0a, 0x7a09, 0xe80a, 0x6e09, 0x6409, 0xe20a, - 0x2009, 0xa60a, 0xac0a, 0x2a09, 0xb80a, 0x3e09, 0x3409, 0xb20a, - 0x900a, 0x1609, 0x1c09, 0x9a0a, 0x0809, 0x8e0a, 0x840a, 0x0209, - 0x000f, 0x860c, 0x8c0c, 0x0a0f, 0x980c, 0x1e0f, 0x140f, 0x920c, - 0xb00c, 0x360f, 0x3c0f, 0xba0c, 0x280f, 0xae0c, 0xa40c, 0x220f, - 0xe00c, 0x660f, 0x6c0f, 0xea0c, 0x780f, 0xfe0c, 0xf40c, 0x720f, - 0x500f, 0xd60c, 0xdc0c, 0x5a0f, 0xc80c, 0x4e0f, 0x440f, 0xc20c, - 0x400c, 0xc60f, 0xcc0f, 0x4a0c, 0xd80f, 0x5e0c, 0x540c, 0xd20f, - 0xf00f, 0x760c, 0x7c0c, 0xfa0f, 0x680c, 0xee0f, 0xe40f, 0x620c, - 0xa00f, 0x260c, 0x2c0c, 0xaa0f, 0x380c, 0xbe0f, 0xb40f, 0x320c, - 0x100c, 0x960f, 0x9c0f, 0x1a0c, 0x880f, 0x0e0c, 0x040c, 0x820f }, - - { 0x0000, 0x8017, 0x802b, 0x003c, 0x8053, 0x0044, 0x0078, 0x806f, - 0x80a3, 0x00b4, 0x0088, 0x809f, 0x00f0, 0x80e7, 0x80db, 0x00cc, - 0x8143, 0x0154, 0x0168, 0x817f, 0x0110, 0x8107, 0x813b, 0x012c, - 0x01e0, 0x81f7, 0x81cb, 0x01dc, 0x81b3, 0x01a4, 0x0198, 0x818f, - 0x8283, 0x0294, 0x02a8, 0x82bf, 0x02d0, 0x82c7, 0x82fb, 0x02ec, - 0x0220, 0x8237, 0x820b, 0x021c, 0x8273, 0x0264, 0x0258, 0x824f, - 0x03c0, 0x83d7, 0x83eb, 0x03fc, 0x8393, 0x0384, 0x03b8, 0x83af, - 0x8363, 0x0374, 0x0348, 0x835f, 0x0330, 0x8327, 0x831b, 0x030c, - 0x8503, 0x0514, 0x0528, 0x853f, 0x0550, 0x8547, 0x857b, 0x056c, - 0x05a0, 0x85b7, 0x858b, 0x059c, 0x85f3, 0x05e4, 0x05d8, 0x85cf, - 0x0440, 0x8457, 0x846b, 0x047c, 0x8413, 0x0404, 0x0438, 0x842f, - 0x84e3, 0x04f4, 0x04c8, 0x84df, 0x04b0, 0x84a7, 0x849b, 0x048c, - 0x0780, 0x8797, 0x87ab, 0x07bc, 0x87d3, 0x07c4, 0x07f8, 0x87ef, - 0x8723, 0x0734, 0x0708, 0x871f, 0x0770, 0x8767, 0x875b, 0x074c, - 0x86c3, 0x06d4, 0x06e8, 0x86ff, 0x0690, 0x8687, 0x86bb, 0x06ac, - 0x0660, 0x8677, 0x864b, 0x065c, 0x8633, 0x0624, 0x0618, 0x860f, - 0x8a03, 0x0a14, 0x0a28, 0x8a3f, 0x0a50, 0x8a47, 0x8a7b, 0x0a6c, - 0x0aa0, 0x8ab7, 0x8a8b, 0x0a9c, 0x8af3, 0x0ae4, 0x0ad8, 0x8acf, - 0x0b40, 0x8b57, 0x8b6b, 0x0b7c, 0x8b13, 0x0b04, 0x0b38, 0x8b2f, - 0x8be3, 0x0bf4, 0x0bc8, 0x8bdf, 0x0bb0, 0x8ba7, 0x8b9b, 0x0b8c, - 0x0880, 0x8897, 0x88ab, 0x08bc, 0x88d3, 0x08c4, 0x08f8, 0x88ef, - 0x8823, 0x0834, 0x0808, 0x881f, 0x0870, 0x8867, 0x885b, 0x084c, - 0x89c3, 0x09d4, 0x09e8, 0x89ff, 0x0990, 0x8987, 0x89bb, 0x09ac, - 0x0960, 0x8977, 0x894b, 0x095c, 0x8933, 0x0924, 0x0918, 0x890f, - 0x0f00, 0x8f17, 0x8f2b, 0x0f3c, 0x8f53, 0x0f44, 0x0f78, 0x8f6f, - 0x8fa3, 0x0fb4, 0x0f88, 0x8f9f, 0x0ff0, 0x8fe7, 0x8fdb, 0x0fcc, - 0x8e43, 0x0e54, 0x0e68, 0x8e7f, 0x0e10, 0x8e07, 0x8e3b, 0x0e2c, - 0x0ee0, 0x8ef7, 0x8ecb, 0x0edc, 0x8eb3, 0x0ea4, 0x0e98, 0x8e8f, - 0x8d83, 0x0d94, 0x0da8, 0x8dbf, 0x0dd0, 0x8dc7, 0x8dfb, 0x0dec, - 0x0d20, 0x8d37, 0x8d0b, 0x0d1c, 0x8d73, 0x0d64, 0x0d58, 0x8d4f, - 0x0cc0, 0x8cd7, 0x8ceb, 0x0cfc, 0x8c93, 0x0c84, 0x0cb8, 0x8caf, - 0x8c63, 0x0c74, 0x0c48, 0x8c5f, 0x0c30, 0x8c27, 0x8c1b, 0x0c0c }, - - { 0x0000, 0x9403, 0xa803, 0x3c00, 0xd003, 0x4400, 0x7800, 0xec03, - 0x2003, 0xb400, 0x8800, 0x1c03, 0xf000, 0x6403, 0x5803, 0xcc00, - 0x4006, 0xd405, 0xe805, 0x7c06, 0x9005, 0x0406, 0x3806, 0xac05, - 0x6005, 0xf406, 0xc806, 0x5c05, 0xb006, 0x2405, 0x1805, 0x8c06, - 0x800c, 0x140f, 0x280f, 0xbc0c, 0x500f, 0xc40c, 0xf80c, 0x6c0f, - 0xa00f, 0x340c, 0x080c, 0x9c0f, 0x700c, 0xe40f, 0xd80f, 0x4c0c, - 0xc00a, 0x5409, 0x6809, 0xfc0a, 0x1009, 0x840a, 0xb80a, 0x2c09, - 0xe009, 0x740a, 0x480a, 0xdc09, 0x300a, 0xa409, 0x9809, 0x0c0a, - 0x801d, 0x141e, 0x281e, 0xbc1d, 0x501e, 0xc41d, 0xf81d, 0x6c1e, - 0xa01e, 0x341d, 0x081d, 0x9c1e, 0x701d, 0xe41e, 0xd81e, 0x4c1d, - 0xc01b, 0x5418, 0x6818, 0xfc1b, 0x1018, 0x841b, 0xb81b, 0x2c18, - 0xe018, 0x741b, 0x481b, 0xdc18, 0x301b, 0xa418, 0x9818, 0x0c1b, - 0x0011, 0x9412, 0xa812, 0x3c11, 0xd012, 0x4411, 0x7811, 0xec12, - 0x2012, 0xb411, 0x8811, 0x1c12, 0xf011, 0x6412, 0x5812, 0xcc11, - 0x4017, 0xd414, 0xe814, 0x7c17, 0x9014, 0x0417, 0x3817, 0xac14, - 0x6014, 0xf417, 0xc817, 0x5c14, 0xb017, 0x2414, 0x1814, 0x8c17, - 0x803f, 0x143c, 0x283c, 0xbc3f, 0x503c, 0xc43f, 0xf83f, 0x6c3c, - 0xa03c, 0x343f, 0x083f, 0x9c3c, 0x703f, 0xe43c, 0xd83c, 0x4c3f, - 0xc039, 0x543a, 0x683a, 0xfc39, 0x103a, 0x8439, 0xb839, 0x2c3a, - 0xe03a, 0x7439, 0x4839, 0xdc3a, 0x3039, 0xa43a, 0x983a, 0x0c39, - 0x0033, 0x9430, 0xa830, 0x3c33, 0xd030, 0x4433, 0x7833, 0xec30, - 0x2030, 0xb433, 0x8833, 0x1c30, 0xf033, 0x6430, 0x5830, 0xcc33, - 0x4035, 0xd436, 0xe836, 0x7c35, 0x9036, 0x0435, 0x3835, 0xac36, - 0x6036, 0xf435, 0xc835, 0x5c36, 0xb035, 0x2436, 0x1836, 0x8c35, - 0x0022, 0x9421, 0xa821, 0x3c22, 0xd021, 0x4422, 0x7822, 0xec21, - 0x2021, 0xb422, 0x8822, 0x1c21, 0xf022, 0x6421, 0x5821, 0xcc22, - 0x4024, 0xd427, 0xe827, 0x7c24, 0x9027, 0x0424, 0x3824, 0xac27, - 0x6027, 0xf424, 0xc824, 0x5c27, 0xb024, 0x2427, 0x1827, 0x8c24, - 0x802e, 0x142d, 0x282d, 0xbc2e, 0x502d, 0xc42e, 0xf82e, 0x6c2d, - 0xa02d, 0x342e, 0x082e, 0x9c2d, 0x702e, 0xe42d, 0xd82d, 0x4c2e, - 0xc028, 0x542b, 0x682b, 0xfc28, 0x102b, 0x8428, 0xb828, 0x2c2b, - 0xe02b, 0x7428, 0x4828, 0xdc2b, 0x3028, 0xa42b, 0x982b, 0x0c28 }, - - { 0x0000, 0x807b, 0x80f3, 0x0088, 0x81e3, 0x0198, 0x0110, 0x816b, - 0x83c3, 0x03b8, 0x0330, 0x834b, 0x0220, 0x825b, 0x82d3, 0x02a8, - 0x8783, 0x07f8, 0x0770, 0x870b, 0x0660, 0x861b, 0x8693, 0x06e8, - 0x0440, 0x843b, 0x84b3, 0x04c8, 0x85a3, 0x05d8, 0x0550, 0x852b, - 0x8f03, 0x0f78, 0x0ff0, 0x8f8b, 0x0ee0, 0x8e9b, 0x8e13, 0x0e68, - 0x0cc0, 0x8cbb, 0x8c33, 0x0c48, 0x8d23, 0x0d58, 0x0dd0, 0x8dab, - 0x0880, 0x88fb, 0x8873, 0x0808, 0x8963, 0x0918, 0x0990, 0x89eb, - 0x8b43, 0x0b38, 0x0bb0, 0x8bcb, 0x0aa0, 0x8adb, 0x8a53, 0x0a28, - 0x9e03, 0x1e78, 0x1ef0, 0x9e8b, 0x1fe0, 0x9f9b, 0x9f13, 0x1f68, - 0x1dc0, 0x9dbb, 0x9d33, 0x1d48, 0x9c23, 0x1c58, 0x1cd0, 0x9cab, - 0x1980, 0x99fb, 0x9973, 0x1908, 0x9863, 0x1818, 0x1890, 0x98eb, - 0x9a43, 0x1a38, 0x1ab0, 0x9acb, 0x1ba0, 0x9bdb, 0x9b53, 0x1b28, - 0x1100, 0x917b, 0x91f3, 0x1188, 0x90e3, 0x1098, 0x1010, 0x906b, - 0x92c3, 0x12b8, 0x1230, 0x924b, 0x1320, 0x935b, 0x93d3, 0x13a8, - 0x9683, 0x16f8, 0x1670, 0x960b, 0x1760, 0x971b, 0x9793, 0x17e8, - 0x1540, 0x953b, 0x95b3, 0x15c8, 0x94a3, 0x14d8, 0x1450, 0x942b, - 0xbc03, 0x3c78, 0x3cf0, 0xbc8b, 0x3de0, 0xbd9b, 0xbd13, 0x3d68, - 0x3fc0, 0xbfbb, 0xbf33, 0x3f48, 0xbe23, 0x3e58, 0x3ed0, 0xbeab, - 0x3b80, 0xbbfb, 0xbb73, 0x3b08, 0xba63, 0x3a18, 0x3a90, 0xbaeb, - 0xb843, 0x3838, 0x38b0, 0xb8cb, 0x39a0, 0xb9db, 0xb953, 0x3928, - 0x3300, 0xb37b, 0xb3f3, 0x3388, 0xb2e3, 0x3298, 0x3210, 0xb26b, - 0xb0c3, 0x30b8, 0x3030, 0xb04b, 0x3120, 0xb15b, 0xb1d3, 0x31a8, - 0xb483, 0x34f8, 0x3470, 0xb40b, 0x3560, 0xb51b, 0xb593, 0x35e8, - 0x3740, 0xb73b, 0xb7b3, 0x37c8, 0xb6a3, 0x36d8, 0x3650, 0xb62b, - 0x2200, 0xa27b, 0xa2f3, 0x2288, 0xa3e3, 0x2398, 0x2310, 0xa36b, - 0xa1c3, 0x21b8, 0x2130, 0xa14b, 0x2020, 0xa05b, 0xa0d3, 0x20a8, - 0xa583, 0x25f8, 0x2570, 0xa50b, 0x2460, 0xa41b, 0xa493, 0x24e8, - 0x2640, 0xa63b, 0xa6b3, 0x26c8, 0xa7a3, 0x27d8, 0x2750, 0xa72b, - 0xad03, 0x2d78, 0x2df0, 0xad8b, 0x2ce0, 0xac9b, 0xac13, 0x2c68, - 0x2ec0, 0xaebb, 0xae33, 0x2e48, 0xaf23, 0x2f58, 0x2fd0, 0xafab, - 0x2a80, 0xaafb, 0xaa73, 0x2a08, 0xab63, 0x2b18, 0x2b90, 0xabeb, - 0xa943, 0x2938, 0x29b0, 0xa9cb, 0x28a0, 0xa8db, 0xa853, 0x2828 }, - - { 0x0000, 0xf803, 0x7003, 0x8800, 0xe006, 0x1805, 0x9005, 0x6806, - 0x4009, 0xb80a, 0x300a, 0xc809, 0xa00f, 0x580c, 0xd00c, 0x280f, - 0x8012, 0x7811, 0xf011, 0x0812, 0x6014, 0x9817, 0x1017, 0xe814, - 0xc01b, 0x3818, 0xb018, 0x481b, 0x201d, 0xd81e, 0x501e, 0xa81d, - 0x8021, 0x7822, 0xf022, 0x0821, 0x6027, 0x9824, 0x1024, 0xe827, - 0xc028, 0x382b, 0xb02b, 0x4828, 0x202e, 0xd82d, 0x502d, 0xa82e, - 0x0033, 0xf830, 0x7030, 0x8833, 0xe035, 0x1836, 0x9036, 0x6835, - 0x403a, 0xb839, 0x3039, 0xc83a, 0xa03c, 0x583f, 0xd03f, 0x283c, - 0x8047, 0x7844, 0xf044, 0x0847, 0x6041, 0x9842, 0x1042, 0xe841, - 0xc04e, 0x384d, 0xb04d, 0x484e, 0x2048, 0xd84b, 0x504b, 0xa848, - 0x0055, 0xf856, 0x7056, 0x8855, 0xe053, 0x1850, 0x9050, 0x6853, - 0x405c, 0xb85f, 0x305f, 0xc85c, 0xa05a, 0x5859, 0xd059, 0x285a, - 0x0066, 0xf865, 0x7065, 0x8866, 0xe060, 0x1863, 0x9063, 0x6860, - 0x406f, 0xb86c, 0x306c, 0xc86f, 0xa069, 0x586a, 0xd06a, 0x2869, - 0x8074, 0x7877, 0xf077, 0x0874, 0x6072, 0x9871, 0x1071, 0xe872, - 0xc07d, 0x387e, 0xb07e, 0x487d, 0x207b, 0xd878, 0x5078, 0xa87b, - 0x808b, 0x7888, 0xf088, 0x088b, 0x608d, 0x988e, 0x108e, 0xe88d, - 0xc082, 0x3881, 0xb081, 0x4882, 0x2084, 0xd887, 0x5087, 0xa884, - 0x0099, 0xf89a, 0x709a, 0x8899, 0xe09f, 0x189c, 0x909c, 0x689f, - 0x4090, 0xb893, 0x3093, 0xc890, 0xa096, 0x5895, 0xd095, 0x2896, - 0x00aa, 0xf8a9, 0x70a9, 0x88aa, 0xe0ac, 0x18af, 0x90af, 0x68ac, - 0x40a3, 0xb8a0, 0x30a0, 0xc8a3, 0xa0a5, 0x58a6, 0xd0a6, 0x28a5, - 0x80b8, 0x78bb, 0xf0bb, 0x08b8, 0x60be, 0x98bd, 0x10bd, 0xe8be, - 0xc0b1, 0x38b2, 0xb0b2, 0x48b1, 0x20b7, 0xd8b4, 0x50b4, 0xa8b7, - 0x00cc, 0xf8cf, 0x70cf, 0x88cc, 0xe0ca, 0x18c9, 0x90c9, 0x68ca, - 0x40c5, 0xb8c6, 0x30c6, 0xc8c5, 0xa0c3, 0x58c0, 0xd0c0, 0x28c3, - 0x80de, 0x78dd, 0xf0dd, 0x08de, 0x60d8, 0x98db, 0x10db, 0xe8d8, - 0xc0d7, 0x38d4, 0xb0d4, 0x48d7, 0x20d1, 0xd8d2, 0x50d2, 0xa8d1, - 0x80ed, 0x78ee, 0xf0ee, 0x08ed, 0x60eb, 0x98e8, 0x10e8, 0xe8eb, - 0xc0e4, 0x38e7, 0xb0e7, 0x48e4, 0x20e2, 0xd8e1, 0x50e1, 0xa8e2, - 0x00ff, 0xf8fc, 0x70fc, 0x88ff, 0xe0f9, 0x18fa, 0x90fa, 0x68f9, - 0x40f6, 0xb8f5, 0x30f5, 0xc8f6, 0xa0f0, 0x58f3, 0xd0f3, 0x28f0 }, - - { 0x0000, 0x8113, 0x8223, 0x0330, 0x8443, 0x0550, 0x0660, 0x8773, - 0x8883, 0x0990, 0x0aa0, 0x8bb3, 0x0cc0, 0x8dd3, 0x8ee3, 0x0ff0, - 0x9103, 0x1010, 0x1320, 0x9233, 0x1540, 0x9453, 0x9763, 0x1670, - 0x1980, 0x9893, 0x9ba3, 0x1ab0, 0x9dc3, 0x1cd0, 0x1fe0, 0x9ef3, - 0xa203, 0x2310, 0x2020, 0xa133, 0x2640, 0xa753, 0xa463, 0x2570, - 0x2a80, 0xab93, 0xa8a3, 0x29b0, 0xaec3, 0x2fd0, 0x2ce0, 0xadf3, - 0x3300, 0xb213, 0xb123, 0x3030, 0xb743, 0x3650, 0x3560, 0xb473, - 0xbb83, 0x3a90, 0x39a0, 0xb8b3, 0x3fc0, 0xbed3, 0xbde3, 0x3cf0, - 0xc403, 0x4510, 0x4620, 0xc733, 0x4040, 0xc153, 0xc263, 0x4370, - 0x4c80, 0xcd93, 0xcea3, 0x4fb0, 0xc8c3, 0x49d0, 0x4ae0, 0xcbf3, - 0x5500, 0xd413, 0xd723, 0x5630, 0xd143, 0x5050, 0x5360, 0xd273, - 0xdd83, 0x5c90, 0x5fa0, 0xdeb3, 0x59c0, 0xd8d3, 0xdbe3, 0x5af0, - 0x6600, 0xe713, 0xe423, 0x6530, 0xe243, 0x6350, 0x6060, 0xe173, - 0xee83, 0x6f90, 0x6ca0, 0xedb3, 0x6ac0, 0xebd3, 0xe8e3, 0x69f0, - 0xf703, 0x7610, 0x7520, 0xf433, 0x7340, 0xf253, 0xf163, 0x7070, - 0x7f80, 0xfe93, 0xfda3, 0x7cb0, 0xfbc3, 0x7ad0, 0x79e0, 0xf8f3, - 0x0803, 0x8910, 0x8a20, 0x0b33, 0x8c40, 0x0d53, 0x0e63, 0x8f70, - 0x8080, 0x0193, 0x02a3, 0x83b0, 0x04c3, 0x85d0, 0x86e0, 0x07f3, - 0x9900, 0x1813, 0x1b23, 0x9a30, 0x1d43, 0x9c50, 0x9f60, 0x1e73, - 0x1183, 0x9090, 0x93a0, 0x12b3, 0x95c0, 0x14d3, 0x17e3, 0x96f0, - 0xaa00, 0x2b13, 0x2823, 0xa930, 0x2e43, 0xaf50, 0xac60, 0x2d73, - 0x2283, 0xa390, 0xa0a0, 0x21b3, 0xa6c0, 0x27d3, 0x24e3, 0xa5f0, - 0x3b03, 0xba10, 0xb920, 0x3833, 0xbf40, 0x3e53, 0x3d63, 0xbc70, - 0xb380, 0x3293, 0x31a3, 0xb0b0, 0x37c3, 0xb6d0, 0xb5e0, 0x34f3, - 0xcc00, 0x4d13, 0x4e23, 0xcf30, 0x4843, 0xc950, 0xca60, 0x4b73, - 0x4483, 0xc590, 0xc6a0, 0x47b3, 0xc0c0, 0x41d3, 0x42e3, 0xc3f0, - 0x5d03, 0xdc10, 0xdf20, 0x5e33, 0xd940, 0x5853, 0x5b63, 0xda70, - 0xd580, 0x5493, 0x57a3, 0xd6b0, 0x51c3, 0xd0d0, 0xd3e0, 0x52f3, - 0x6e03, 0xef10, 0xec20, 0x6d33, 0xea40, 0x6b53, 0x6863, 0xe970, - 0xe680, 0x6793, 0x64a3, 0xe5b0, 0x62c3, 0xe3d0, 0xe0e0, 0x61f3, - 0xff00, 0x7e13, 0x7d23, 0xfc30, 0x7b43, 0xfa50, 0xf960, 0x7873, - 0x7783, 0xf690, 0xf5a0, 0x74b3, 0xf3c0, 0x72d3, 0x71e3, 0xf0f0 }, - - { 0x0000, 0x1006, 0x200c, 0x300a, 0x4018, 0x501e, 0x6014, 0x7012, - 0x8030, 0x9036, 0xa03c, 0xb03a, 0xc028, 0xd02e, 0xe024, 0xf022, - 0x8065, 0x9063, 0xa069, 0xb06f, 0xc07d, 0xd07b, 0xe071, 0xf077, - 0x0055, 0x1053, 0x2059, 0x305f, 0x404d, 0x504b, 0x6041, 0x7047, - 0x80cf, 0x90c9, 0xa0c3, 0xb0c5, 0xc0d7, 0xd0d1, 0xe0db, 0xf0dd, - 0x00ff, 0x10f9, 0x20f3, 0x30f5, 0x40e7, 0x50e1, 0x60eb, 0x70ed, - 0x00aa, 0x10ac, 0x20a6, 0x30a0, 0x40b2, 0x50b4, 0x60be, 0x70b8, - 0x809a, 0x909c, 0xa096, 0xb090, 0xc082, 0xd084, 0xe08e, 0xf088, - 0x819b, 0x919d, 0xa197, 0xb191, 0xc183, 0xd185, 0xe18f, 0xf189, - 0x01ab, 0x11ad, 0x21a7, 0x31a1, 0x41b3, 0x51b5, 0x61bf, 0x71b9, - 0x01fe, 0x11f8, 0x21f2, 0x31f4, 0x41e6, 0x51e0, 0x61ea, 0x71ec, - 0x81ce, 0x91c8, 0xa1c2, 0xb1c4, 0xc1d6, 0xd1d0, 0xe1da, 0xf1dc, - 0x0154, 0x1152, 0x2158, 0x315e, 0x414c, 0x514a, 0x6140, 0x7146, - 0x8164, 0x9162, 0xa168, 0xb16e, 0xc17c, 0xd17a, 0xe170, 0xf176, - 0x8131, 0x9137, 0xa13d, 0xb13b, 0xc129, 0xd12f, 0xe125, 0xf123, - 0x0101, 0x1107, 0x210d, 0x310b, 0x4119, 0x511f, 0x6115, 0x7113, - 0x8333, 0x9335, 0xa33f, 0xb339, 0xc32b, 0xd32d, 0xe327, 0xf321, - 0x0303, 0x1305, 0x230f, 0x3309, 0x431b, 0x531d, 0x6317, 0x7311, - 0x0356, 0x1350, 0x235a, 0x335c, 0x434e, 0x5348, 0x6342, 0x7344, - 0x8366, 0x9360, 0xa36a, 0xb36c, 0xc37e, 0xd378, 0xe372, 0xf374, - 0x03fc, 0x13fa, 0x23f0, 0x33f6, 0x43e4, 0x53e2, 0x63e8, 0x73ee, - 0x83cc, 0x93ca, 0xa3c0, 0xb3c6, 0xc3d4, 0xd3d2, 0xe3d8, 0xf3de, - 0x8399, 0x939f, 0xa395, 0xb393, 0xc381, 0xd387, 0xe38d, 0xf38b, - 0x03a9, 0x13af, 0x23a5, 0x33a3, 0x43b1, 0x53b7, 0x63bd, 0x73bb, - 0x02a8, 0x12ae, 0x22a4, 0x32a2, 0x42b0, 0x52b6, 0x62bc, 0x72ba, - 0x8298, 0x929e, 0xa294, 0xb292, 0xc280, 0xd286, 0xe28c, 0xf28a, - 0x82cd, 0x92cb, 0xa2c1, 0xb2c7, 0xc2d5, 0xd2d3, 0xe2d9, 0xf2df, - 0x02fd, 0x12fb, 0x22f1, 0x32f7, 0x42e5, 0x52e3, 0x62e9, 0x72ef, - 0x8267, 0x9261, 0xa26b, 0xb26d, 0xc27f, 0xd279, 0xe273, 0xf275, - 0x0257, 0x1251, 0x225b, 0x325d, 0x424f, 0x5249, 0x6243, 0x7245, - 0x0202, 0x1204, 0x220e, 0x3208, 0x421a, 0x521c, 0x6216, 0x7210, - 0x8232, 0x9234, 0xa23e, 0xb238, 0xc22a, 0xd22c, 0xe226, 0xf220 } -}; - -#if 0 -void FLAC__crc16_init_table(void) -{ - int i, j; - FLAC__uint16 polynomial, crc; - polynomial = 0x8005; - - for(i = 0; i <= 0xFF; i++){ - crc = i << 8; - - for(j = 0; j < 8; j++) - crc = (crc << 1) ^ (crc & (1 << 15) ? polynomial : 0); - - FLAC__crc16_table[0][i] = crc; - } - - for(i = 0; i <= 0xFF; i++) - for(j = 1; j < 8; j++) - FLAC__crc16_table[j][i] = FLAC__crc16_table[0][FLAC__crc16_table[j - 1][i] >> 8] ^ (FLAC__crc16_table[j - 1][i] << 8); -} -#endif - -FLAC__uint8 FLAC__crc8(const FLAC__byte *data, uint32_t len) -{ - FLAC__uint8 crc = 0; - - while(len--) - crc = FLAC__crc8_table[crc ^ *data++]; - - return crc; -} - -FLAC__uint16 FLAC__crc16(const FLAC__byte *data, uint32_t len) -{ - FLAC__uint16 crc = 0; - - while(len >= 8){ - crc ^= data[0] << 8 | data[1]; - - crc = FLAC__crc16_table[7][crc >> 8] ^ FLAC__crc16_table[6][crc & 0xFF] ^ - FLAC__crc16_table[5][data[2] ] ^ FLAC__crc16_table[4][data[3] ] ^ - FLAC__crc16_table[3][data[4] ] ^ FLAC__crc16_table[2][data[5] ] ^ - FLAC__crc16_table[1][data[6] ] ^ FLAC__crc16_table[0][data[7] ]; - - data += 8; - len -= 8; - } - - while(len--) - crc = (crc<<8) ^ FLAC__crc16_table[0][(crc>>8) ^ *data++]; - - return crc; -} - -FLAC__uint16 FLAC__crc16_update_words32(const FLAC__uint32 *words, uint32_t len, FLAC__uint16 crc) -{ - while (len >= 2) { - crc ^= words[0] >> 16; - - crc = FLAC__crc16_table[7][crc >> 8 ] ^ FLAC__crc16_table[6][crc & 0xFF ] ^ - FLAC__crc16_table[5][(words[0] >> 8) & 0xFF] ^ FLAC__crc16_table[4][ words[0] & 0xFF] ^ - FLAC__crc16_table[3][ words[1] >> 24 ] ^ FLAC__crc16_table[2][(words[1] >> 16) & 0xFF] ^ - FLAC__crc16_table[1][(words[1] >> 8) & 0xFF] ^ FLAC__crc16_table[0][ words[1] & 0xFF]; - - words += 2; - len -= 2; - } - - if (len) { - crc ^= words[0] >> 16; - - crc = FLAC__crc16_table[3][crc >> 8 ] ^ FLAC__crc16_table[2][crc & 0xFF ] ^ - FLAC__crc16_table[1][(words[0] >> 8) & 0xFF] ^ FLAC__crc16_table[0][words[0] & 0xFF]; - } - - return crc; -} - -FLAC__uint16 FLAC__crc16_update_words64(const FLAC__uint64 *words, uint32_t len, FLAC__uint16 crc) -{ - while (len--) { - crc ^= words[0] >> 48; - - crc = FLAC__crc16_table[7][crc >> 8 ] ^ FLAC__crc16_table[6][crc & 0xFF ] ^ - FLAC__crc16_table[5][(words[0] >> 40) & 0xFF] ^ FLAC__crc16_table[4][(words[0] >> 32) & 0xFF] ^ - FLAC__crc16_table[3][(words[0] >> 24) & 0xFF] ^ FLAC__crc16_table[2][(words[0] >> 16) & 0xFF] ^ - FLAC__crc16_table[1][(words[0] >> 8) & 0xFF] ^ FLAC__crc16_table[0][ words[0] & 0xFF]; - - words++; - } - - return crc; -} diff --git a/flac/src/libFLAC/deduplication/bitreader_read_rice_signed_block.c b/flac/src/libFLAC/deduplication/bitreader_read_rice_signed_block.c deleted file mode 100644 index 75ed47f..0000000 --- a/flac/src/libFLAC/deduplication/bitreader_read_rice_signed_block.c +++ /dev/null @@ -1,143 +0,0 @@ -{ - /* try and get br->consumed_words and br->consumed_bits into register; - * must remember to flush them back to *br before calling other - * bitreader functions that use them, and before returning */ - uint32_t cwords, words, lsbs, msbs, x, y, limit; - uint32_t ucbits; /* keep track of the number of unconsumed bits in word */ - brword b; - int *val, *end; - - FLAC__ASSERT(0 != br); - FLAC__ASSERT(0 != br->buffer); - /* WATCHOUT: code does not work with <32bit words; we can make things much faster with this assertion */ - FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32); - FLAC__ASSERT(parameter < 32); - /* the above two asserts also guarantee that the binary part never straddles more than 2 words, so we don't have to loop to read it */ - - limit = UINT32_MAX >> parameter; /* Maximal msbs that can occur with residual bounded to int32_t */ - - val = vals; - end = vals + nvals; - - if(parameter == 0) { - while(val < end) { - /* read the unary MSBs and end bit */ - if(!FLAC__bitreader_read_unary_unsigned(br, &msbs)) - return false; - /* Checking limit here would be overzealous: coding UINT32_MAX - * with parameter == 0 would take 4GiB */ - *val++ = (int)(msbs >> 1) ^ -(int)(msbs & 1); - } - - return true; - } - - FLAC__ASSERT(parameter > 0); - - cwords = br->consumed_words; - words = br->words; - - /* if we've not consumed up to a partial tail word... */ - if(cwords >= words) { - x = 0; - goto process_tail; - } - - ucbits = FLAC__BITS_PER_WORD - br->consumed_bits; - b = br->buffer[cwords] << br->consumed_bits; /* keep unconsumed bits aligned to left */ - - while(val < end) { - /* read the unary MSBs and end bit */ - x = y = COUNT_ZERO_MSBS2(b); - if(x == FLAC__BITS_PER_WORD) { - x = ucbits; - do { - /* didn't find stop bit yet, have to keep going... */ - cwords++; - if (cwords >= words) - goto incomplete_msbs; - b = br->buffer[cwords]; - y = COUNT_ZERO_MSBS2(b); - x += y; - } while(y == FLAC__BITS_PER_WORD); - } - b <<= y; - b <<= 1; /* account for stop bit */ - ucbits = (ucbits - x - 1) % FLAC__BITS_PER_WORD; - msbs = x; - - if(x > limit) - return false; - - /* read the binary LSBs */ - x = (FLAC__uint32)(b >> (FLAC__BITS_PER_WORD - parameter)); /* parameter < 32, so we can cast to 32-bit uint32_t */ - if(parameter <= ucbits) { - ucbits -= parameter; - b <<= parameter; - } else { - /* there are still bits left to read, they will all be in the next word */ - cwords++; - if (cwords >= words) - goto incomplete_lsbs; - b = br->buffer[cwords]; - ucbits += FLAC__BITS_PER_WORD - parameter; - x |= (FLAC__uint32)(b >> ucbits); - b <<= FLAC__BITS_PER_WORD - ucbits; - } - lsbs = x; - - /* compose the value */ - x = (msbs << parameter) | lsbs; - *val++ = (int)(x >> 1) ^ -(int)(x & 1); - - continue; - - /* at this point we've eaten up all the whole words */ -process_tail: - do { - if(0) { -incomplete_msbs: - br->consumed_bits = 0; - br->consumed_words = cwords; - } - - /* read the unary MSBs and end bit */ - if(!FLAC__bitreader_read_unary_unsigned(br, &msbs)) - return false; - msbs += x; - x = ucbits = 0; - - if(0) { -incomplete_lsbs: - br->consumed_bits = 0; - br->consumed_words = cwords; - } - - /* read the binary LSBs */ - if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter - ucbits)) - return false; - lsbs = x | lsbs; - - /* compose the value */ - x = (msbs << parameter) | lsbs; - *val++ = (int)(x >> 1) ^ -(int)(x & 1); - x = 0; - - cwords = br->consumed_words; - words = br->words; - ucbits = FLAC__BITS_PER_WORD - br->consumed_bits; - b = cwords < br->capacity ? br->buffer[cwords] << br->consumed_bits : 0; - } while(cwords >= words && val < end); - } - - if(ucbits == 0 && cwords < words) { - /* don't leave the head word with no unconsumed bits */ - cwords++; - ucbits = FLAC__BITS_PER_WORD; - } - - br->consumed_bits = FLAC__BITS_PER_WORD - ucbits; - br->consumed_words = cwords; - - return true; -} diff --git a/flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin.c b/flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin.c deleted file mode 100644 index 76419db..0000000 --- a/flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin.c +++ /dev/null @@ -1,14 +0,0 @@ - int i, j; - (void) lag; - FLAC__ASSERT(lag <= MAX_LAG); - - for(i = 0; i < MAX_LAG; i++) - autoc[i] = 0.0; - - for(i = 0; i < MAX_LAG; i++) - for(j = 0; j <= i; j++) - autoc[j] += (double)data[i] * (double)data[i-j]; - - for(i = MAX_LAG; i < (int)data_len; i++) - for(j = 0; j < MAX_LAG; j++) - autoc[j] += (double)data[i] * (double)data[i-j]; diff --git a/flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_neon.c b/flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_neon.c deleted file mode 100644 index 4df3aee..0000000 --- a/flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_neon.c +++ /dev/null @@ -1,70 +0,0 @@ - int i; - float64x2_t sum0 = vdupq_n_f64(0.0f); - float64x2_t sum1 = vdupq_n_f64(0.0f); - float64x2_t sum2 = vdupq_n_f64(0.0f); - float64x2_t sum3 = vdupq_n_f64(0.0f); - float64x2_t d0 = vdupq_n_f64(0.0f); - float64x2_t d1 = vdupq_n_f64(0.0f); - float64x2_t d2 = vdupq_n_f64(0.0f); - float64x2_t d3 = vdupq_n_f64(0.0f); -#if MAX_LAG > 8 - float64x2_t sum4 = vdupq_n_f64(0.0f); - float64x2_t d4 = vdupq_n_f64(0.0f); -#endif -#if MAX_LAG > 10 - float64x2_t sum5 = vdupq_n_f64(0.0f); - float64x2_t sum6 = vdupq_n_f64(0.0f); - float64x2_t d5 = vdupq_n_f64(0.0f); - float64x2_t d6 = vdupq_n_f64(0.0f); -#endif - float64x2_t d; - - (void)lag; - FLAC__ASSERT(lag <= MAX_LAG); - - // Loop backwards through samples from data_len to 0 - for (i = data_len - 1; i >= 0; i--) - { - d = vdupq_n_f64(data[i]); // Create vector with 2 entries data[i] - - // The next 6 lines of code right-shift the elements through the 7 vectors d0..d6. - // The 7th line adds the newly loaded element to d0. This works like a stack, where - // data[i] is pushed onto the stack every time and the 9th element falls off -#if MAX_LAG > 10 - d6 = vextq_f64(d5,d6,1); - d5 = vextq_f64(d4,d5,1); -#endif -#if MAX_LAG > 8 - d4 = vextq_f64(d3,d4,1); -#endif - d3 = vextq_f64(d2,d3,1); - d2 = vextq_f64(d1,d2,1); - d1 = vextq_f64(d0,d1,1); - d0 = vextq_f64(d,d0,1); - - // Fused multiply-add sum += d * d0..d6 - sum0 = vfmaq_f64(sum0, d, d0); - sum1 = vfmaq_f64(sum1, d, d1); - sum2 = vfmaq_f64(sum2, d, d2); - sum3 = vfmaq_f64(sum3, d, d3); -#if MAX_LAG > 8 - sum4 = vfmaq_f64(sum4, d, d4); -#endif -#if MAX_LAG > 10 - sum5 = vfmaq_f64(sum5, d, d5); - sum6 = vfmaq_f64(sum6, d, d6); -#endif - } - - // Store sum0..sum6 in autoc[0..14] - vst1q_f64(autoc, sum0); - vst1q_f64(autoc + 2, sum1); - vst1q_f64(autoc + 4, sum2); - vst1q_f64(autoc + 6, sum3); -#if MAX_LAG > 8 - vst1q_f64(autoc + 8, sum4); -#endif -#if MAX_LAG > 10 - vst1q_f64(autoc + 10, sum5); - vst1q_f64(autoc + 12, sum6); -#endif diff --git a/flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_sse2.c b/flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_sse2.c deleted file mode 100644 index 607b42f..0000000 --- a/flac/src/libFLAC/deduplication/lpc_compute_autocorrelation_intrin_sse2.c +++ /dev/null @@ -1,81 +0,0 @@ -/* This code is imported several times in lpc_intrin_sse2.c with different - * values for MAX_LAG. Comments are for MAX_LAG == 14 */ - int i; - __m128d sum0, sum1, sum2, sum3; - __m128d d0, d1, d2, d3; -#if MAX_LAG > 8 - __m128d d4; - __m128d sum4; -#endif -#if MAX_LAG > 10 - __m128d d5, d6; - __m128d sum5, sum6; -#endif - - (void) lag; - FLAC__ASSERT(lag <= MAX_LAG); - - /* Initialize all sum vectors with zero */ - sum0 = _mm_setzero_pd(); - sum1 = _mm_setzero_pd(); - sum2 = _mm_setzero_pd(); - sum3 = _mm_setzero_pd(); - d0 = _mm_setzero_pd(); - d1 = _mm_setzero_pd(); - d2 = _mm_setzero_pd(); - d3 = _mm_setzero_pd(); -#if MAX_LAG > 8 - sum4 = _mm_setzero_pd(); - d4 = _mm_setzero_pd(); -#endif -#if MAX_LAG > 10 - sum5 = _mm_setzero_pd(); - sum6 = _mm_setzero_pd(); - d5 = _mm_setzero_pd(); - d6 = _mm_setzero_pd(); -#endif - - /* Loop backwards through samples from data_len to limit */ - for(i = data_len-1; i >= 0; i--) { - __m128d d = _mm_set1_pd(data[i]); - - /* The next lines of code work like a queue. For more - * information see the lag8 version of this function */ -#if MAX_LAG > 10 - d6 = _mm_shuffle_pd(d5, d6, _MM_SHUFFLE(0,0,0,1)); - d5 = _mm_shuffle_pd(d4, d5, _MM_SHUFFLE(0,0,0,1)); -#endif -#if MAX_LAG > 8 - d4 = _mm_shuffle_pd(d3, d4, _MM_SHUFFLE(0,0,0,1)); -#endif - d3 = _mm_shuffle_pd(d2, d3, _MM_SHUFFLE(0,0,0,1)); - d2 = _mm_shuffle_pd(d1, d2, _MM_SHUFFLE(0,0,0,1)); - d1 = _mm_shuffle_pd(d0, d1, _MM_SHUFFLE(0,0,0,1)); - d0 = _mm_shuffle_pd(d, d0, _MM_SHUFFLE(0,0,0,1)); - - /* sumn += d*dn */ - sum0 = _mm_add_pd(sum0, _mm_mul_pd(d, d0)); - sum1 = _mm_add_pd(sum1, _mm_mul_pd(d, d1)); - sum2 = _mm_add_pd(sum2, _mm_mul_pd(d, d2)); - sum3 = _mm_add_pd(sum3, _mm_mul_pd(d, d3)); -#if MAX_LAG > 8 - sum4 = _mm_add_pd(sum4, _mm_mul_pd(d, d4)); -#endif -#if MAX_LAG > 10 - sum5 = _mm_add_pd(sum5, _mm_mul_pd(d, d5)); - sum6 = _mm_add_pd(sum6, _mm_mul_pd(d, d6)); -#endif - } - - /* Store sum0..sum6 in autoc[0..14] */ - _mm_storeu_pd(autoc, sum0); - _mm_storeu_pd(autoc+2, sum1); - _mm_storeu_pd(autoc+4, sum2); - _mm_storeu_pd(autoc+6 ,sum3); -#if MAX_LAG > 8 - _mm_storeu_pd(autoc+8, sum4); -#endif -#if MAX_LAG > 10 - _mm_storeu_pd(autoc+10,sum5); - _mm_storeu_pd(autoc+12,sum6); -#endif diff --git a/flac/src/libFLAC/fixed.c b/flac/src/libFLAC/fixed.c deleted file mode 100644 index 5c42570..0000000 --- a/flac/src/libFLAC/fixed.c +++ /dev/null @@ -1,667 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "share/compat.h" -#include "private/bitmath.h" -#include "private/fixed.h" -#include "private/macros.h" -#include "FLAC/assert.h" - -#ifdef local_abs -#undef local_abs -#endif -#define local_abs(x) ((uint32_t)((x)<0? -(x) : (x))) - -#ifdef local_abs64 -#undef local_abs64 -#endif -#define local_abs64(x) ((uint64_t)((x)<0? -(x) : (x))) - -#ifdef FLAC__INTEGER_ONLY_LIBRARY -/* rbps stands for residual bits per sample - * - * (ln(2) * err) - * rbps = log (-----------) - * 2 ( n ) - */ -static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n) -{ - FLAC__uint32 rbps; - uint32_t bits; /* the number of bits required to represent a number */ - int fracbits; /* the number of bits of rbps that comprise the fractional part */ - - FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint)); - FLAC__ASSERT(err > 0); - FLAC__ASSERT(n > 0); - - FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE); - if(err <= n) - return 0; - /* - * The above two things tell us 1) n fits in 16 bits; 2) err/n > 1. - * These allow us later to know we won't lose too much precision in the - * fixed-point division (err< 0); - bits = FLAC__bitmath_ilog2(err)+1; - if(bits > 16) { - err >>= (bits-16); - fracbits -= (bits-16); - } - rbps = (FLAC__uint32)err; - - /* Multiply by fixed-point version of ln(2), with 16 fractional bits */ - rbps *= FLAC__FP_LN2; - fracbits += 16; - FLAC__ASSERT(fracbits >= 0); - - /* FLAC__fixedpoint_log2 requires fracbits%4 to be 0 */ - { - const int f = fracbits & 3; - if(f) { - rbps >>= f; - fracbits -= f; - } - } - - rbps = FLAC__fixedpoint_log2(rbps, fracbits, (uint32_t)(-1)); - - if(rbps == 0) - return 0; - - /* - * The return value must have 16 fractional bits. Since the whole part - * of the base-2 log of a 32 bit number must fit in 5 bits, and fracbits - * must be >= -3, these assertion allows us to be able to shift rbps - * left if necessary to get 16 fracbits without losing any bits of the - * whole part of rbps. - * - * There is a slight chance due to accumulated error that the whole part - * will require 6 bits, so we use 6 in the assertion. Really though as - * long as it fits in 13 bits (32 - (16 - (-3))) we are fine. - */ - FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6); - FLAC__ASSERT(fracbits >= -3); - - /* now shift the decimal point into place */ - if(fracbits < 16) - return rbps << (16-fracbits); - else if(fracbits > 16) - return rbps >> (fracbits-16); - else - return rbps; -} - -static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n) -{ - FLAC__uint32 rbps; - uint32_t bits; /* the number of bits required to represent a number */ - int fracbits; /* the number of bits of rbps that comprise the fractional part */ - - FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint)); - FLAC__ASSERT(err > 0); - FLAC__ASSERT(n > 0); - - FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE); - if(err <= n) - return 0; - /* - * The above two things tell us 1) n fits in 16 bits; 2) err/n > 1. - * These allow us later to know we won't lose too much precision in the - * fixed-point division (err< 0); - bits = FLAC__bitmath_ilog2_wide(err)+1; - if(bits > 16) { - err >>= (bits-16); - fracbits -= (bits-16); - } - rbps = (FLAC__uint32)err; - - /* Multiply by fixed-point version of ln(2), with 16 fractional bits */ - rbps *= FLAC__FP_LN2; - fracbits += 16; - FLAC__ASSERT(fracbits >= 0); - - /* FLAC__fixedpoint_log2 requires fracbits%4 to be 0 */ - { - const int f = fracbits & 3; - if(f) { - rbps >>= f; - fracbits -= f; - } - } - - rbps = FLAC__fixedpoint_log2(rbps, fracbits, (uint32_t)(-1)); - - if(rbps == 0) - return 0; - - /* - * The return value must have 16 fractional bits. Since the whole part - * of the base-2 log of a 32 bit number must fit in 5 bits, and fracbits - * must be >= -3, these assertion allows us to be able to shift rbps - * left if necessary to get 16 fracbits without losing any bits of the - * whole part of rbps. - * - * There is a slight chance due to accumulated error that the whole part - * will require 6 bits, so we use 6 in the assertion. Really though as - * long as it fits in 13 bits (32 - (16 - (-3))) we are fine. - */ - FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6); - FLAC__ASSERT(fracbits >= -3); - - /* now shift the decimal point into place */ - if(fracbits < 16) - return rbps << (16-fracbits); - else if(fracbits > 16) - return rbps >> (fracbits-16); - else - return rbps; -} -#endif - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]) -#else -uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]) -#endif -{ - FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0; - uint32_t order; -#if 0 - /* This code has been around a long time, and was written when compilers weren't able - * to vectorize code. These days, compilers are better in optimizing the next block - * which is also much more readable - */ - FLAC__int32 last_error_0 = data[-1]; - FLAC__int32 last_error_1 = data[-1] - data[-2]; - FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]); - FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]); - FLAC__int32 error, save; - uint32_t i; - /* total_error_* are 64-bits to avoid overflow when encoding - * erratic signals when the bits-per-sample and blocksize are - * large. - */ - for(i = 0; i < data_len; i++) { - error = data[i] ; total_error_0 += local_abs(error); save = error; - error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error; - error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error; - error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error; - error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save; - } -#else - int i; - for(i = 0; i < (int)data_len; i++) { - total_error_0 += local_abs(data[i]); - total_error_1 += local_abs(data[i] - data[i-1]); - total_error_2 += local_abs(data[i] - 2 * data[i-1] + data[i-2]); - total_error_3 += local_abs(data[i] - 3 * data[i-1] + 3 * data[i-2] - data[i-3]); - total_error_4 += local_abs(data[i] - 4 * data[i-1] + 6 * data[i-2] - 4 * data[i-3] + data[i-4]); - } -#endif - - - /* prefer lower order */ - if(total_error_0 <= flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4)) - order = 0; - else if(total_error_1 <= flac_min(flac_min(total_error_2, total_error_3), total_error_4)) - order = 1; - else if(total_error_2 <= flac_min(total_error_3, total_error_4)) - order = 2; - else if(total_error_3 <= total_error_4) - order = 3; - else - order = 4; - - /* Estimate the expected number of bits per residual signal sample. */ - /* 'total_error*' is linearly related to the variance of the residual */ - /* signal, so we use it directly to compute E(|x|) */ - FLAC__ASSERT(data_len > 0 || total_error_0 == 0); - FLAC__ASSERT(data_len > 0 || total_error_1 == 0); - FLAC__ASSERT(data_len > 0 || total_error_2 == 0); - FLAC__ASSERT(data_len > 0 || total_error_3 == 0); - FLAC__ASSERT(data_len > 0 || total_error_4 == 0); -#ifndef FLAC__INTEGER_ONLY_LIBRARY - residual_bits_per_sample[0] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (float)((total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (float)((total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (float)((total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (float)((total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double)data_len) / M_LN2 : 0.0); -#else - residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0; - residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0; - residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0; - residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0; - residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0; -#endif - - return order; -} - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]) -#else -uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]) -#endif -{ - FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0; - uint32_t order; - int i; - - for(i = 0; i < (int)data_len; i++) { - total_error_0 += local_abs(data[i]); - total_error_1 += local_abs(data[i] - data[i-1]); - total_error_2 += local_abs(data[i] - 2 * data[i-1] + data[i-2]); - total_error_3 += local_abs(data[i] - 3 * data[i-1] + 3 * data[i-2] - data[i-3]); - total_error_4 += local_abs(data[i] - 4 * data[i-1] + 6 * data[i-2] - 4 * data[i-3] + data[i-4]); - } - - /* prefer lower order */ - if(total_error_0 <= flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4)) - order = 0; - else if(total_error_1 <= flac_min(flac_min(total_error_2, total_error_3), total_error_4)) - order = 1; - else if(total_error_2 <= flac_min(total_error_3, total_error_4)) - order = 2; - else if(total_error_3 <= total_error_4) - order = 3; - else - order = 4; - - /* Estimate the expected number of bits per residual signal sample. */ - /* 'total_error*' is linearly related to the variance of the residual */ - /* signal, so we use it directly to compute E(|x|) */ - FLAC__ASSERT(data_len > 0 || total_error_0 == 0); - FLAC__ASSERT(data_len > 0 || total_error_1 == 0); - FLAC__ASSERT(data_len > 0 || total_error_2 == 0); - FLAC__ASSERT(data_len > 0 || total_error_3 == 0); - FLAC__ASSERT(data_len > 0 || total_error_4 == 0); -#ifndef FLAC__INTEGER_ONLY_LIBRARY - residual_bits_per_sample[0] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (float)((total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (float)((total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (float)((total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (float)((total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double)data_len) / M_LN2 : 0.0); -#else - residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0; - residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0; - residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0; - residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0; - residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0; -#endif - - return order; -} - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#define CHECK_ORDER_IS_VALID(macro_order) \ -if(order_##macro_order##_is_valid && total_error_##macro_order < smallest_error) { \ - order = macro_order; \ - smallest_error = total_error_##macro_order ; \ - residual_bits_per_sample[ macro_order ] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); \ -} \ -else \ - residual_bits_per_sample[ macro_order ] = 34.0f; -#else -#define CHECK_ORDER_IS_VALID(macro_order) \ -if(order_##macro_order##_is_valid && total_error_##macro_order < smallest_error) { \ - order = macro_order; \ - smallest_error = total_error_##macro_order ; \ - residual_bits_per_sample[ macro_order ] = (total_error_##macro_order > 0) ? local__compute_rbps_wide_integerized(total_error_##macro_order, data_len) : 0; \ -} \ -else \ - residual_bits_per_sample[ macro_order ] = 34 * FLAC__FP_ONE; -#endif - - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -uint32_t FLAC__fixed_compute_best_predictor_limit_residual(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]) -#else -uint32_t FLAC__fixed_compute_best_predictor_limit_residual(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]) -#endif -{ - FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0, smallest_error = UINT64_MAX; - FLAC__uint64 error_0, error_1, error_2, error_3, error_4; - FLAC__bool order_0_is_valid = true, order_1_is_valid = true, order_2_is_valid = true, order_3_is_valid = true, order_4_is_valid = true; - uint32_t order = 0; - int i; - - for(i = -4; i < (int)data_len; i++) { - error_0 = local_abs64((FLAC__int64)data[i]); - error_1 = (i > -4) ? local_abs64((FLAC__int64)data[i] - data[i-1]) : 0 ; - error_2 = (i > -3) ? local_abs64((FLAC__int64)data[i] - 2 * (FLAC__int64)data[i-1] + data[i-2]) : 0; - error_3 = (i > -2) ? local_abs64((FLAC__int64)data[i] - 3 * (FLAC__int64)data[i-1] + 3 * (FLAC__int64)data[i-2] - data[i-3]) : 0; - error_4 = (i > -1) ? local_abs64((FLAC__int64)data[i] - 4 * (FLAC__int64)data[i-1] + 6 * (FLAC__int64)data[i-2] - 4 * (FLAC__int64)data[i-3] + data[i-4]) : 0; - - total_error_0 += error_0; - total_error_1 += error_1; - total_error_2 += error_2; - total_error_3 += error_3; - total_error_4 += error_4; - - /* residual must not be INT32_MIN because abs(INT32_MIN) is undefined */ - if(error_0 > INT32_MAX) - order_0_is_valid = false; - if(error_1 > INT32_MAX) - order_1_is_valid = false; - if(error_2 > INT32_MAX) - order_2_is_valid = false; - if(error_3 > INT32_MAX) - order_3_is_valid = false; - if(error_4 > INT32_MAX) - order_4_is_valid = false; - } - - CHECK_ORDER_IS_VALID(0); - CHECK_ORDER_IS_VALID(1); - CHECK_ORDER_IS_VALID(2); - CHECK_ORDER_IS_VALID(3); - CHECK_ORDER_IS_VALID(4); - - return order; -} - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -uint32_t FLAC__fixed_compute_best_predictor_limit_residual_33bit(const FLAC__int64 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]) -#else -uint32_t FLAC__fixed_compute_best_predictor_limit_residual_33bit(const FLAC__int64 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]) -#endif -{ - FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0, smallest_error = UINT64_MAX; - FLAC__uint64 error_0, error_1, error_2, error_3, error_4; - FLAC__bool order_0_is_valid = true, order_1_is_valid = true, order_2_is_valid = true, order_3_is_valid = true, order_4_is_valid = true; - uint32_t order = 0; - int i; - - for(i = -4; i < (int)data_len; i++) { - error_0 = local_abs64(data[i]); - error_1 = (i > -4) ? local_abs64(data[i] - data[i-1]) : 0 ; - error_2 = (i > -3) ? local_abs64(data[i] - 2 * data[i-1] + data[i-2]) : 0; - error_3 = (i > -2) ? local_abs64(data[i] - 3 * data[i-1] + 3 * data[i-2] - data[i-3]) : 0; - error_4 = (i > -1) ? local_abs64(data[i] - 4 * data[i-1] + 6 * data[i-2] - 4 * data[i-3] + data[i-4]) : 0; - - total_error_0 += error_0; - total_error_1 += error_1; - total_error_2 += error_2; - total_error_3 += error_3; - total_error_4 += error_4; - - /* residual must not be INT32_MIN because abs(INT32_MIN) is undefined */ - if(error_0 > INT32_MAX) - order_0_is_valid = false; - if(error_1 > INT32_MAX) - order_1_is_valid = false; - if(error_2 > INT32_MAX) - order_2_is_valid = false; - if(error_3 > INT32_MAX) - order_3_is_valid = false; - if(error_4 > INT32_MAX) - order_4_is_valid = false; - } - - CHECK_ORDER_IS_VALID(0); - CHECK_ORDER_IS_VALID(1); - CHECK_ORDER_IS_VALID(2); - CHECK_ORDER_IS_VALID(3); - CHECK_ORDER_IS_VALID(4); - - return order; -} - -void FLAC__fixed_compute_residual(const FLAC__int32 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[]) -{ - const int idata_len = (int)data_len; - int i; - - switch(order) { - case 0: - FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0])); - memcpy(residual, data, sizeof(residual[0])*data_len); - break; - case 1: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - data[i-1]; - break; - case 2: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - 2*data[i-1] + data[i-2]; - break; - case 3: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3]; - break; - case 4: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4]; - break; - default: - FLAC__ASSERT(0); - } -} - -void FLAC__fixed_compute_residual_wide(const FLAC__int32 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[]) -{ - const int idata_len = (int)data_len; - int i; - - switch(order) { - case 0: - FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0])); - memcpy(residual, data, sizeof(residual[0])*data_len); - break; - case 1: - for(i = 0; i < idata_len; i++) - residual[i] = (FLAC__int64)data[i] - data[i-1]; - break; - case 2: - for(i = 0; i < idata_len; i++) - residual[i] = (FLAC__int64)data[i] - 2*(FLAC__int64)data[i-1] + data[i-2]; - break; - case 3: - for(i = 0; i < idata_len; i++) - residual[i] = (FLAC__int64)data[i] - 3*(FLAC__int64)data[i-1] + 3*(FLAC__int64)data[i-2] - data[i-3]; - break; - case 4: - for(i = 0; i < idata_len; i++) - residual[i] = (FLAC__int64)data[i] - 4*(FLAC__int64)data[i-1] + 6*(FLAC__int64)data[i-2] - 4*(FLAC__int64)data[i-3] + data[i-4]; - break; - default: - FLAC__ASSERT(0); - } -} - -void FLAC__fixed_compute_residual_wide_33bit(const FLAC__int64 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[]) -{ - const int idata_len = (int)data_len; - int i; - - switch(order) { - case 0: - for(i = 0; i < idata_len; i++) - residual[i] = data[i]; - break; - case 1: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - data[i-1]; - break; - case 2: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - 2*data[i-1] + data[i-2]; - break; - case 3: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3]; - break; - case 4: - for(i = 0; i < idata_len; i++) - residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4]; - break; - default: - FLAC__ASSERT(0); - } -} - -#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && !defined(FUZZING_BUILD_MODE_FLAC_SANITIZE_SIGNED_INTEGER_OVERFLOW) -/* The attribute below is to silence the undefined sanitizer of oss-fuzz. - * Because fuzzing feeds bogus predictors and residual samples to the - * decoder, having overflows in this section is unavoidable. Also, - * because the calculated values are audio path only, there is no - * potential for security problems */ -__attribute__((no_sanitize("signed-integer-overflow"))) -#endif -void FLAC__fixed_restore_signal(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int32 data[]) -{ - int i, idata_len = (int)data_len; - - switch(order) { - case 0: - FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0])); - memcpy(data, residual, sizeof(residual[0])*data_len); - break; - case 1: - for(i = 0; i < idata_len; i++) - data[i] = residual[i] + data[i-1]; - break; - case 2: - for(i = 0; i < idata_len; i++) - data[i] = residual[i] + 2*data[i-1] - data[i-2]; - break; - case 3: - for(i = 0; i < idata_len; i++) - data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3]; - break; - case 4: - for(i = 0; i < idata_len; i++) - data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4]; - break; - default: - FLAC__ASSERT(0); - } -} - -void FLAC__fixed_restore_signal_wide(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int32 data[]) -{ - int i, idata_len = (int)data_len; - - switch(order) { - case 0: - FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0])); - memcpy(data, residual, sizeof(residual[0])*data_len); - break; - case 1: - for(i = 0; i < idata_len; i++) - data[i] = (FLAC__int64)residual[i] + (FLAC__int64)data[i-1]; - break; - case 2: - for(i = 0; i < idata_len; i++) - data[i] = (FLAC__int64)residual[i] + 2*(FLAC__int64)data[i-1] - (FLAC__int64)data[i-2]; - break; - case 3: - for(i = 0; i < idata_len; i++) - data[i] = (FLAC__int64)residual[i] + 3*(FLAC__int64)data[i-1] - 3*(FLAC__int64)data[i-2] + (FLAC__int64)data[i-3]; - break; - case 4: - for(i = 0; i < idata_len; i++) - data[i] = (FLAC__int64)residual[i] + 4*(FLAC__int64)data[i-1] - 6*(FLAC__int64)data[i-2] + 4*(FLAC__int64)data[i-3] - (FLAC__int64)data[i-4]; - break; - default: - FLAC__ASSERT(0); - } -} - -#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && !defined(FUZZING_BUILD_MODE_FLAC_SANITIZE_SIGNED_INTEGER_OVERFLOW) -/* The attribute below is to silence the undefined sanitizer of oss-fuzz. - * Because fuzzing feeds bogus predictors and residual samples to the - * decoder, having overflows in this section is unavoidable. Also, - * because the calculated values are audio path only, there is no - * potential for security problems */ -__attribute__((no_sanitize("signed-integer-overflow"))) -#endif -void FLAC__fixed_restore_signal_wide_33bit(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int64 data[]) -{ - int i, idata_len = (int)data_len; - - switch(order) { - case 0: - for(i = 0; i < idata_len; i++) - data[i] = residual[i]; - break; - case 1: - for(i = 0; i < idata_len; i++) - data[i] = (FLAC__int64)residual[i] + data[i-1]; - break; - case 2: - for(i = 0; i < idata_len; i++) - data[i] = (FLAC__int64)residual[i] + 2*data[i-1] - data[i-2]; - break; - case 3: - for(i = 0; i < idata_len; i++) - data[i] = (FLAC__int64)residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3]; - break; - case 4: - for(i = 0; i < idata_len; i++) - data[i] = (FLAC__int64)residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4]; - break; - default: - FLAC__ASSERT(0); - } -} diff --git a/flac/src/libFLAC/fixed_intrin_avx2.c b/flac/src/libFLAC/fixed_intrin_avx2.c deleted file mode 100644 index 85fc4a6..0000000 --- a/flac/src/libFLAC/fixed_intrin_avx2.c +++ /dev/null @@ -1,343 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "private/fixed.h" -#ifdef FLAC__AVX2_SUPPORTED - -#include -#include -#include "private/macros.h" -#include "share/compat.h" -#include "FLAC/assert.h" - -#ifdef local_abs -#undef local_abs -#endif -#define local_abs(x) ((uint32_t)((x)<0? -(x) : (x))) - -FLAC__SSE_TARGET("avx2") -uint32_t FLAC__fixed_compute_best_predictor_wide_intrin_avx2(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]) -{ - FLAC__uint64 total_error_0, total_error_1, total_error_2, total_error_3, total_error_4; - FLAC__int32 i, data_len_int; - uint32_t order; - __m256i total_err0, total_err1, total_err2, total_err3, total_err4; - __m256i prev_err0, prev_err1, prev_err2, prev_err3; - __m256i tempA, tempB, bitmask; - FLAC__int64 data_scalar[4]; - FLAC__int64 prev_err0_scalar[4]; - FLAC__int64 prev_err1_scalar[4]; - FLAC__int64 prev_err2_scalar[4]; - FLAC__int64 prev_err3_scalar[4]; - total_err0 = _mm256_setzero_si256(); - total_err1 = _mm256_setzero_si256(); - total_err2 = _mm256_setzero_si256(); - total_err3 = _mm256_setzero_si256(); - total_err4 = _mm256_setzero_si256(); - data_len_int = data_len; - - for(i = 0; i < 4; i++){ - prev_err0_scalar[i] = data[-1+i*(data_len_int/4)]; - prev_err1_scalar[i] = data[-1+i*(data_len_int/4)] - data[-2+i*(data_len_int/4)]; - prev_err2_scalar[i] = prev_err1_scalar[i] - (data[-2+i*(data_len_int/4)] - data[-3+i*(data_len_int/4)]); - prev_err3_scalar[i] = prev_err2_scalar[i] - (data[-2+i*(data_len_int/4)] - 2*data[-3+i*(data_len_int/4)] + data[-4+i*(data_len_int/4)]); - } - prev_err0 = _mm256_loadu_si256((const __m256i*)(void*)prev_err0_scalar); - prev_err1 = _mm256_loadu_si256((const __m256i*)(void*)prev_err1_scalar); - prev_err2 = _mm256_loadu_si256((const __m256i*)(void*)prev_err2_scalar); - prev_err3 = _mm256_loadu_si256((const __m256i*)(void*)prev_err3_scalar); - for(i = 0; i < data_len_int / 4; i++){ - data_scalar[0] = data[i]; - data_scalar[1] = data[i+data_len/4]; - data_scalar[2] = data[i+2*data_len/4]; - data_scalar[3] = data[i+3*data_len/4]; - tempA = _mm256_loadu_si256((const __m256i*)(void*)data_scalar); - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempA); - tempB = _mm256_xor_si256(tempA, bitmask); - tempB = _mm256_sub_epi64(tempB, bitmask); - total_err0 = _mm256_add_epi64(total_err0,tempB); - tempB = _mm256_sub_epi64(tempA,prev_err0); - prev_err0 = tempA; - /* Next three intrinsics calculate tempA as abs of tempB */ - bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempB); - tempA = _mm256_xor_si256(tempB, bitmask); - tempA = _mm256_sub_epi64(tempA, bitmask); - total_err1 = _mm256_add_epi64(total_err1,tempA); - tempA = _mm256_sub_epi64(tempB,prev_err1); - prev_err1 = tempB; - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempA); - tempB = _mm256_xor_si256(tempA, bitmask); - tempB = _mm256_sub_epi64(tempB, bitmask); - total_err2 = _mm256_add_epi64(total_err2,tempB); - tempB = _mm256_sub_epi64(tempA,prev_err2); - prev_err2 = tempA; - /* Next three intrinsics calculate tempA as abs of tempB */ - bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempB); - tempA = _mm256_xor_si256(tempB, bitmask); - tempA = _mm256_sub_epi64(tempA, bitmask); - total_err3 = _mm256_add_epi64(total_err3,tempA); - tempA = _mm256_sub_epi64(tempB,prev_err3); - prev_err3 = tempB; - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempA); - tempB = _mm256_xor_si256(tempA, bitmask); - tempB = _mm256_sub_epi64(tempB, bitmask); - total_err4 = _mm256_add_epi64(total_err4,tempB); - } - _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err0); - total_error_0 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err1); - total_error_1 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err2); - total_error_2 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err3); - total_error_3 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err4); - total_error_4 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - - /* Ignore the remainder, we're ignore the first few samples too */ - - /* prefer lower order */ - if(total_error_0 <= flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4)) - order = 0; - else if(total_error_1 <= flac_min(flac_min(total_error_2, total_error_3), total_error_4)) - order = 1; - else if(total_error_2 <= flac_min(total_error_3, total_error_4)) - order = 2; - else if(total_error_3 <= total_error_4) - order = 3; - else - order = 4; - - /* Estimate the expected number of bits per residual signal sample. */ - /* 'total_error*' is linearly related to the variance of the residual */ - /* signal, so we use it directly to compute E(|x|) */ - FLAC__ASSERT(data_len > 0 || total_error_0 == 0); - FLAC__ASSERT(data_len > 0 || total_error_1 == 0); - FLAC__ASSERT(data_len > 0 || total_error_2 == 0); - FLAC__ASSERT(data_len > 0 || total_error_3 == 0); - FLAC__ASSERT(data_len > 0 || total_error_4 == 0); - - residual_bits_per_sample[0] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (float)((total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (float)((total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (float)((total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (float)((total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double)data_len) / M_LN2 : 0.0); - - return order; -} - -#ifdef local_abs64 -#undef local_abs64 -#endif -#define local_abs64(x) ((uint64_t)((x)<0? -(x) : (x))) - -#define CHECK_ORDER_IS_VALID(macro_order) \ -if(shadow_error_##macro_order <= INT32_MAX) { \ - if(total_error_##macro_order < smallest_error) { \ - order = macro_order; \ - smallest_error = total_error_##macro_order ; \ - } \ - residual_bits_per_sample[ macro_order ] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); \ -} \ -else \ - residual_bits_per_sample[ macro_order ] = 34.0f; - -FLAC__SSE_TARGET("avx2") -uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_avx2(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]) -{ - FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0, smallest_error = UINT64_MAX; - FLAC__uint64 shadow_error_0 = 0, shadow_error_1 = 0, shadow_error_2 = 0, shadow_error_3 = 0, shadow_error_4 = 0; - FLAC__uint64 error_0, error_1, error_2, error_3, error_4; - FLAC__int32 i, data_len_int; - uint32_t order = 0; - __m256i total_err0, total_err1, total_err2, total_err3, total_err4; - __m256i shadow_err0, shadow_err1, shadow_err2, shadow_err3, shadow_err4; - __m256i prev_err0, prev_err1, prev_err2, prev_err3; - __m256i tempA, tempB, bitmask; - FLAC__int64 data_scalar[4]; - FLAC__int64 prev_err0_scalar[4]; - FLAC__int64 prev_err1_scalar[4]; - FLAC__int64 prev_err2_scalar[4]; - FLAC__int64 prev_err3_scalar[4]; - total_err0 = _mm256_setzero_si256(); - total_err1 = _mm256_setzero_si256(); - total_err2 = _mm256_setzero_si256(); - total_err3 = _mm256_setzero_si256(); - total_err4 = _mm256_setzero_si256(); - shadow_err0 = _mm256_setzero_si256(); - shadow_err1 = _mm256_setzero_si256(); - shadow_err2 = _mm256_setzero_si256(); - shadow_err3 = _mm256_setzero_si256(); - shadow_err4 = _mm256_setzero_si256(); - data_len_int = data_len; - - /* First take care of preceding samples */ - for(i = -4; i < 0; i++) { - error_0 = local_abs64((FLAC__int64)data[i]); - error_1 = (i > -4) ? local_abs64((FLAC__int64)data[i] - data[i-1]) : 0 ; - error_2 = (i > -3) ? local_abs64((FLAC__int64)data[i] - 2 * (FLAC__int64)data[i-1] + data[i-2]) : 0; - error_3 = (i > -2) ? local_abs64((FLAC__int64)data[i] - 3 * (FLAC__int64)data[i-1] + 3 * (FLAC__int64)data[i-2] - data[i-3]) : 0; - - total_error_0 += error_0; - total_error_1 += error_1; - total_error_2 += error_2; - total_error_3 += error_3; - - shadow_error_0 |= error_0; - shadow_error_1 |= error_1; - shadow_error_2 |= error_2; - shadow_error_3 |= error_3; - } - - for(i = 0; i < 4; i++){ - prev_err0_scalar[i] = data[-1+i*(data_len_int/4)]; - prev_err1_scalar[i] = (FLAC__int64)(data[-1+i*(data_len_int/4)]) - data[-2+i*(data_len_int/4)]; - prev_err2_scalar[i] = prev_err1_scalar[i] - ((FLAC__int64)(data[-2+i*(data_len_int/4)]) - data[-3+i*(data_len_int/4)]); - prev_err3_scalar[i] = prev_err2_scalar[i] - ((FLAC__int64)(data[-2+i*(data_len_int/4)]) - 2*(FLAC__int64)(data[-3+i*(data_len_int/4)]) + data[-4+i*(data_len_int/4)]); - } - prev_err0 = _mm256_loadu_si256((const __m256i*)(void*)prev_err0_scalar); - prev_err1 = _mm256_loadu_si256((const __m256i*)(void*)prev_err1_scalar); - prev_err2 = _mm256_loadu_si256((const __m256i*)(void*)prev_err2_scalar); - prev_err3 = _mm256_loadu_si256((const __m256i*)(void*)prev_err3_scalar); - for(i = 0; i < data_len_int / 4; i++){ - data_scalar[0] = data[i]; - data_scalar[1] = data[i+data_len/4]; - data_scalar[2] = data[i+2*data_len/4]; - data_scalar[3] = data[i+3*data_len/4]; - tempA = _mm256_loadu_si256((const __m256i*)(void*)data_scalar); - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempA); - tempB = _mm256_xor_si256(tempA, bitmask); - tempB = _mm256_sub_epi64(tempB, bitmask); - total_err0 = _mm256_add_epi64(total_err0,tempB); - shadow_err0 = _mm256_or_si256(shadow_err0,tempB); - tempB = _mm256_sub_epi64(tempA,prev_err0); - prev_err0 = tempA; - /* Next three intrinsics calculate tempA as abs of tempB */ - bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempB); - tempA = _mm256_xor_si256(tempB, bitmask); - tempA = _mm256_sub_epi64(tempA, bitmask); - total_err1 = _mm256_add_epi64(total_err1,tempA); - shadow_err1 = _mm256_or_si256(shadow_err1,tempA); - tempA = _mm256_sub_epi64(tempB,prev_err1); - prev_err1 = tempB; - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempA); - tempB = _mm256_xor_si256(tempA, bitmask); - tempB = _mm256_sub_epi64(tempB, bitmask); - total_err2 = _mm256_add_epi64(total_err2,tempB); - shadow_err2 = _mm256_or_si256(shadow_err2,tempB); - tempB = _mm256_sub_epi64(tempA,prev_err2); - prev_err2 = tempA; - /* Next three intrinsics calculate tempA as abs of tempB */ - bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempB); - tempA = _mm256_xor_si256(tempB, bitmask); - tempA = _mm256_sub_epi64(tempA, bitmask); - total_err3 = _mm256_add_epi64(total_err3,tempA); - shadow_err3 = _mm256_or_si256(shadow_err3,tempA); - tempA = _mm256_sub_epi64(tempB,prev_err3); - prev_err3 = tempB; - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempA); - tempB = _mm256_xor_si256(tempA, bitmask); - tempB = _mm256_sub_epi64(tempB, bitmask); - total_err4 = _mm256_add_epi64(total_err4,tempB); - shadow_err4 = _mm256_or_si256(shadow_err4,tempB); - } - _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err0); - total_error_0 += data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err1); - total_error_1 += data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err2); - total_error_2 += data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err3); - total_error_3 += data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err4); - total_error_4 += data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,shadow_err0); - shadow_error_0 |= data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,shadow_err1); - shadow_error_1 |= data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,shadow_err2); - shadow_error_2 |= data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,shadow_err3); - shadow_error_3 |= data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3]; - _mm256_storeu_si256((__m256i*)(void*)data_scalar,shadow_err4); - shadow_error_4 |= data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3]; - - /* Take care of remaining sample */ - for(i = (data_len/4)*4; i < data_len_int; i++) { - error_0 = local_abs64((FLAC__int64)data[i]); - error_1 = local_abs64((FLAC__int64)data[i] - data[i-1]); - error_2 = local_abs64((FLAC__int64)data[i] - 2 * (FLAC__int64)data[i-1] + data[i-2]); - error_3 = local_abs64((FLAC__int64)data[i] - 3 * (FLAC__int64)data[i-1] + 3 * (FLAC__int64)data[i-2] - data[i-3]); - error_4 = local_abs64((FLAC__int64)data[i] - 4 * (FLAC__int64)data[i-1] + 6 * (FLAC__int64)data[i-2] - 4 * (FLAC__int64)data[i-3] + data[i-4]); - - total_error_0 += error_0; - total_error_1 += error_1; - total_error_2 += error_2; - total_error_3 += error_3; - total_error_4 += error_4; - - shadow_error_0 |= error_0; - shadow_error_1 |= error_1; - shadow_error_2 |= error_2; - shadow_error_3 |= error_3; - shadow_error_4 |= error_4; - } - - - CHECK_ORDER_IS_VALID(0); - CHECK_ORDER_IS_VALID(1); - CHECK_ORDER_IS_VALID(2); - CHECK_ORDER_IS_VALID(3); - CHECK_ORDER_IS_VALID(4); - - return order; -} - -#endif /* FLAC__AVX2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/fixed_intrin_sse2.c b/flac/src/libFLAC/fixed_intrin_sse2.c deleted file mode 100644 index b92c13c..0000000 --- a/flac/src/libFLAC/fixed_intrin_sse2.c +++ /dev/null @@ -1,194 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN -#include "private/fixed.h" -#ifdef FLAC__SSE2_SUPPORTED - -#include /* SSE2 */ -#include -#include "private/macros.h" -#include "share/compat.h" -#include "FLAC/assert.h" - -#ifdef FLAC__CPU_IA32 -#define m128i_to_i64(dest, src) _mm_storel_epi64((__m128i*)&dest, src) -#else -#define m128i_to_i64(dest, src) dest = _mm_cvtsi128_si64(src) -#endif - -#ifdef local_abs -#undef local_abs -#endif -#define local_abs(x) ((uint32_t)((x)<0? -(x) : (x))) - -FLAC__SSE_TARGET("sse2") -uint32_t FLAC__fixed_compute_best_predictor_intrin_sse2(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]) -{ - FLAC__uint32 total_error_0, total_error_1, total_error_2, total_error_3, total_error_4; - FLAC__int32 i, data_len_int; - uint32_t order; - __m128i total_err0, total_err1, total_err2, total_err3, total_err4; - __m128i prev_err0, prev_err1, prev_err2, prev_err3; - __m128i tempA, tempB, bitmask; - FLAC__int32 data_scalar[4]; - FLAC__int32 prev_err0_scalar[4]; - FLAC__int32 prev_err1_scalar[4]; - FLAC__int32 prev_err2_scalar[4]; - FLAC__int32 prev_err3_scalar[4]; - total_err0 = _mm_setzero_si128(); - total_err1 = _mm_setzero_si128(); - total_err2 = _mm_setzero_si128(); - total_err3 = _mm_setzero_si128(); - total_err4 = _mm_setzero_si128(); - data_len_int = data_len; - - for(i = 0; i < 4; i++){ - prev_err0_scalar[i] = data[-1+i*(data_len_int/4)]; - prev_err1_scalar[i] = data[-1+i*(data_len_int/4)] - data[-2+i*(data_len_int/4)]; - prev_err2_scalar[i] = prev_err1_scalar[i] - (data[-2+i*(data_len_int/4)] - data[-3+i*(data_len_int/4)]); - prev_err3_scalar[i] = prev_err2_scalar[i] - (data[-2+i*(data_len_int/4)] - 2*data[-3+i*(data_len_int/4)] + data[-4+i*(data_len_int/4)]); - } - prev_err0 = _mm_loadu_si128((const __m128i*)prev_err0_scalar); - prev_err1 = _mm_loadu_si128((const __m128i*)prev_err1_scalar); - prev_err2 = _mm_loadu_si128((const __m128i*)prev_err2_scalar); - prev_err3 = _mm_loadu_si128((const __m128i*)prev_err3_scalar); - for(i = 0; i < data_len_int / 4; i++){ - data_scalar[0] = data[i]; - data_scalar[1] = data[i+data_len/4]; - data_scalar[2] = data[i+2*(data_len/4)]; - data_scalar[3] = data[i+3*(data_len/4)]; - tempA = _mm_loadu_si128((const __m128i*)data_scalar); - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm_srai_epi32(tempA, 31); - tempB = _mm_xor_si128(tempA, bitmask); - tempB = _mm_sub_epi32(tempB, bitmask); - total_err0 = _mm_add_epi32(total_err0,tempB); - tempB = _mm_sub_epi32(tempA,prev_err0); - prev_err0 = tempA; - /* Next three intrinsics calculate tempA as abs of tempB */ - bitmask = _mm_srai_epi32(tempB, 31); - tempA = _mm_xor_si128(tempB, bitmask); - tempA = _mm_sub_epi32(tempA, bitmask); - total_err1 = _mm_add_epi32(total_err1,tempA); - tempA = _mm_sub_epi32(tempB,prev_err1); - prev_err1 = tempB; - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm_srai_epi32(tempA, 31); - tempB = _mm_xor_si128(tempA, bitmask); - tempB = _mm_sub_epi32(tempB, bitmask); - total_err2 = _mm_add_epi32(total_err2,tempB); - tempB = _mm_sub_epi32(tempA,prev_err2); - prev_err2 = tempA; - /* Next three intrinsics calculate tempA as abs of tempB */ - bitmask = _mm_srai_epi32(tempB, 31); - tempA = _mm_xor_si128(tempB, bitmask); - tempA = _mm_sub_epi32(tempA, bitmask); - total_err3 = _mm_add_epi32(total_err3,tempA); - tempA = _mm_sub_epi32(tempB,prev_err3); - prev_err3 = tempB; - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm_srai_epi32(tempA, 31); - tempB = _mm_xor_si128(tempA, bitmask); - tempB = _mm_sub_epi32(tempB, bitmask); - total_err4 = _mm_add_epi32(total_err4,tempB); - } - _mm_storeu_si128((__m128i*)data_scalar,total_err0); - total_error_0 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm_storeu_si128((__m128i*)data_scalar,total_err1); - total_error_1 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm_storeu_si128((__m128i*)data_scalar,total_err2); - total_error_2 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm_storeu_si128((__m128i*)data_scalar,total_err3); - total_error_3 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm_storeu_si128((__m128i*)data_scalar,total_err4); - total_error_4 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - - /* Now the remainder of samples needs to be processed */ - i *= 4; - if(data_len % 4 > 0){ - FLAC__int32 last_error_0 = data[i-1]; - FLAC__int32 last_error_1 = data[i-1] - data[i-2]; - FLAC__int32 last_error_2 = last_error_1 - (data[i-2] - data[i-3]); - FLAC__int32 last_error_3 = last_error_2 - (data[i-2] - 2*data[i-3] + data[i-4]); - FLAC__int32 error, save; - for(; i < data_len_int; i++) { - error = data[i] ; total_error_0 += local_abs(error); save = error; - error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error; - error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error; - error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error; - error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save; - } - } - - /* prefer lower order */ - if(total_error_0 <= flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4)) - order = 0; - else if(total_error_1 <= flac_min(flac_min(total_error_2, total_error_3), total_error_4)) - order = 1; - else if(total_error_2 <= flac_min(total_error_3, total_error_4)) - order = 2; - else if(total_error_3 <= total_error_4) - order = 3; - else - order = 4; - - /* Estimate the expected number of bits per residual signal sample. */ - /* 'total_error*' is linearly related to the variance of the residual */ - /* signal, so we use it directly to compute E(|x|) */ - FLAC__ASSERT(data_len > 0 || total_error_0 == 0); - FLAC__ASSERT(data_len > 0 || total_error_1 == 0); - FLAC__ASSERT(data_len > 0 || total_error_2 == 0); - FLAC__ASSERT(data_len > 0 || total_error_3 == 0); - FLAC__ASSERT(data_len > 0 || total_error_4 == 0); - - residual_bits_per_sample[0] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (float)((total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (float)((total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (float)((total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (float)((total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double)data_len) / M_LN2 : 0.0); - - return order; -} - -#endif /* FLAC__SSE2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/fixed_intrin_sse42.c b/flac/src/libFLAC/fixed_intrin_sse42.c deleted file mode 100644 index 0556eaa..0000000 --- a/flac/src/libFLAC/fixed_intrin_sse42.c +++ /dev/null @@ -1,223 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "private/fixed.h" -#ifdef FLAC__SSE4_2_SUPPORTED - -#include /* SSE4.2 */ -#include -#include "private/macros.h" -#include "share/compat.h" -#include "FLAC/assert.h" - -#ifdef local_abs64 -#undef local_abs64 -#endif -#define local_abs64(x) ((uint64_t)((x)<0? -(x) : (x))) - -#define CHECK_ORDER_IS_VALID(macro_order) \ -if(shadow_error_##macro_order <= INT32_MAX) { \ - if(total_error_##macro_order < smallest_error) { \ - order = macro_order; \ - smallest_error = total_error_##macro_order ; \ - } \ - residual_bits_per_sample[ macro_order ] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); \ -} \ -else \ - residual_bits_per_sample[ macro_order ] = 34.0f; - -FLAC__SSE_TARGET("sse4.2") -uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]) -{ - FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0, smallest_error = UINT64_MAX; - FLAC__uint64 shadow_error_0 = 0, shadow_error_1 = 0, shadow_error_2 = 0, shadow_error_3 = 0, shadow_error_4 = 0; - FLAC__uint64 error_0, error_1, error_2, error_3, error_4; - FLAC__int32 i, data_len_int; - uint32_t order = 0; - __m128i total_err0, total_err1, total_err2, total_err3, total_err4; - __m128i shadow_err0, shadow_err1, shadow_err2, shadow_err3, shadow_err4; - __m128i prev_err0, prev_err1, prev_err2, prev_err3; - __m128i tempA, tempB, bitmask; - FLAC__int64 data_scalar[2]; - FLAC__int64 prev_err0_scalar[2]; - FLAC__int64 prev_err1_scalar[2]; - FLAC__int64 prev_err2_scalar[2]; - FLAC__int64 prev_err3_scalar[2]; - total_err0 = _mm_setzero_si128(); - total_err1 = _mm_setzero_si128(); - total_err2 = _mm_setzero_si128(); - total_err3 = _mm_setzero_si128(); - total_err4 = _mm_setzero_si128(); - shadow_err0 = _mm_setzero_si128(); - shadow_err1 = _mm_setzero_si128(); - shadow_err2 = _mm_setzero_si128(); - shadow_err3 = _mm_setzero_si128(); - shadow_err4 = _mm_setzero_si128(); - data_len_int = data_len; - - /* First take care of preceding samples */ - for(i = -4; i < 0; i++) { - error_0 = local_abs64((FLAC__int64)data[i]); - error_1 = (i > -4) ? local_abs64((FLAC__int64)data[i] - data[i-1]) : 0 ; - error_2 = (i > -3) ? local_abs64((FLAC__int64)data[i] - 2 * (FLAC__int64)data[i-1] + data[i-2]) : 0; - error_3 = (i > -2) ? local_abs64((FLAC__int64)data[i] - 3 * (FLAC__int64)data[i-1] + 3 * (FLAC__int64)data[i-2] - data[i-3]) : 0; - - total_error_0 += error_0; - total_error_1 += error_1; - total_error_2 += error_2; - total_error_3 += error_3; - - shadow_error_0 |= error_0; - shadow_error_1 |= error_1; - shadow_error_2 |= error_2; - shadow_error_3 |= error_3; - } - - for(i = 0; i < 2; i++){ - prev_err0_scalar[i] = data[-1+i*(data_len_int/2)]; - prev_err1_scalar[i] = (FLAC__int64)(data[-1+i*(data_len_int/2)]) - data[-2+i*(data_len_int/2)]; - prev_err2_scalar[i] = prev_err1_scalar[i] - ((FLAC__int64)(data[-2+i*(data_len_int/2)]) - data[-3+i*(data_len_int/2)]); - prev_err3_scalar[i] = prev_err2_scalar[i] - ((FLAC__int64)(data[-2+i*(data_len_int/2)]) - 2*(FLAC__int64)(data[-3+i*(data_len_int/2)]) + data[-4+i*(data_len_int/2)]); - } - prev_err0 = _mm_loadu_si128((const __m128i*)prev_err0_scalar); - prev_err1 = _mm_loadu_si128((const __m128i*)prev_err1_scalar); - prev_err2 = _mm_loadu_si128((const __m128i*)prev_err2_scalar); - prev_err3 = _mm_loadu_si128((const __m128i*)prev_err3_scalar); - for(i = 0; i < data_len_int / 2; i++){ - data_scalar[0] = data[i]; - data_scalar[1] = data[i+data_len/2]; - tempA = _mm_loadu_si128((const __m128i*)data_scalar); - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm_cmpgt_epi64(_mm_set1_epi64x(0), tempA); - tempB = _mm_xor_si128(tempA, bitmask); - tempB = _mm_sub_epi64(tempB, bitmask); - total_err0 = _mm_add_epi64(total_err0,tempB); - shadow_err0 = _mm_or_si128(shadow_err0,tempB); - tempB = _mm_sub_epi64(tempA,prev_err0); - prev_err0 = tempA; - /* Next three intrinsics calculate tempA as abs of tempB */ - bitmask = _mm_cmpgt_epi64(_mm_set1_epi64x(0), tempB); - tempA = _mm_xor_si128(tempB, bitmask); - tempA = _mm_sub_epi64(tempA, bitmask); - total_err1 = _mm_add_epi64(total_err1,tempA); - shadow_err1 = _mm_or_si128(shadow_err1,tempA); - tempA = _mm_sub_epi64(tempB,prev_err1); - prev_err1 = tempB; - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm_cmpgt_epi64(_mm_set1_epi64x(0), tempA); - tempB = _mm_xor_si128(tempA, bitmask); - tempB = _mm_sub_epi64(tempB, bitmask); - total_err2 = _mm_add_epi64(total_err2,tempB); - shadow_err2 = _mm_or_si128(shadow_err2,tempB); - tempB = _mm_sub_epi64(tempA,prev_err2); - prev_err2 = tempA; - /* Next three intrinsics calculate tempA as abs of tempB */ - bitmask = _mm_cmpgt_epi64(_mm_set1_epi64x(0), tempB); - tempA = _mm_xor_si128(tempB, bitmask); - tempA = _mm_sub_epi64(tempA, bitmask); - total_err3 = _mm_add_epi64(total_err3,tempA); - shadow_err3 = _mm_or_si128(shadow_err3,tempA); - tempA = _mm_sub_epi64(tempB,prev_err3); - prev_err3 = tempB; - /* Next three intrinsics calculate tempB as abs of tempA */ - bitmask = _mm_cmpgt_epi64(_mm_set1_epi64x(0), tempA); - tempB = _mm_xor_si128(tempA, bitmask); - tempB = _mm_sub_epi64(tempB, bitmask); - total_err4 = _mm_add_epi64(total_err4,tempB); - shadow_err4 = _mm_or_si128(shadow_err4,tempB); - } - _mm_storeu_si128((__m128i*)data_scalar,total_err0); - total_error_0 += data_scalar[0] + data_scalar[1]; - _mm_storeu_si128((__m128i*)data_scalar,total_err1); - total_error_1 += data_scalar[0] + data_scalar[1]; - _mm_storeu_si128((__m128i*)data_scalar,total_err2); - total_error_2 += data_scalar[0] + data_scalar[1]; - _mm_storeu_si128((__m128i*)data_scalar,total_err3); - total_error_3 += data_scalar[0] + data_scalar[1]; - _mm_storeu_si128((__m128i*)data_scalar,total_err4); - total_error_4 += data_scalar[0] + data_scalar[1]; - _mm_storeu_si128((__m128i*)data_scalar,shadow_err0); - shadow_error_0 |= data_scalar[0] | data_scalar[1]; - _mm_storeu_si128((__m128i*)data_scalar,shadow_err1); - shadow_error_1 |= data_scalar[0] | data_scalar[1]; - _mm_storeu_si128((__m128i*)data_scalar,shadow_err2); - shadow_error_2 |= data_scalar[0] | data_scalar[1]; - _mm_storeu_si128((__m128i*)data_scalar,shadow_err3); - shadow_error_3 |= data_scalar[0] | data_scalar[1]; - _mm_storeu_si128((__m128i*)data_scalar,shadow_err4); - shadow_error_4 |= data_scalar[0] | data_scalar[1]; - - /* Take care of remaining sample */ - if(data_len_int % 2 > 0) { - i += data_len/2; - error_0 = local_abs64((FLAC__int64)data[i]); - error_1 = local_abs64((FLAC__int64)data[i] - data[i-1]); - error_2 = local_abs64((FLAC__int64)data[i] - 2 * (FLAC__int64)data[i-1] + data[i-2]); - error_3 = local_abs64((FLAC__int64)data[i] - 3 * (FLAC__int64)data[i-1] + 3 * (FLAC__int64)data[i-2] - data[i-3]); - error_4 = local_abs64((FLAC__int64)data[i] - 4 * (FLAC__int64)data[i-1] + 6 * (FLAC__int64)data[i-2] - 4 * (FLAC__int64)data[i-3] + data[i-4]); - - total_error_0 += error_0; - total_error_1 += error_1; - total_error_2 += error_2; - total_error_3 += error_3; - total_error_4 += error_4; - - shadow_error_0 |= error_0; - shadow_error_1 |= error_1; - shadow_error_2 |= error_2; - shadow_error_3 |= error_3; - shadow_error_4 |= error_4; - } - - - CHECK_ORDER_IS_VALID(0); - CHECK_ORDER_IS_VALID(1); - CHECK_ORDER_IS_VALID(2); - CHECK_ORDER_IS_VALID(3); - CHECK_ORDER_IS_VALID(4); - - return order; -} - -#endif /* FLAC__SSE4_2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/fixed_intrin_ssse3.c b/flac/src/libFLAC/fixed_intrin_ssse3.c deleted file mode 100644 index 551693b..0000000 --- a/flac/src/libFLAC/fixed_intrin_ssse3.c +++ /dev/null @@ -1,179 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "private/fixed.h" -#ifdef FLAC__SSSE3_SUPPORTED - -#include /* SSSE3 */ -#include -#include "private/macros.h" -#include "share/compat.h" -#include "FLAC/assert.h" - -#ifdef FLAC__CPU_IA32 -#define m128i_to_i64(dest, src) _mm_storel_epi64((__m128i*)&dest, src) -#else -#define m128i_to_i64(dest, src) dest = _mm_cvtsi128_si64(src) -#endif - -#ifdef local_abs -#undef local_abs -#endif -#define local_abs(x) ((uint32_t)((x)<0? -(x) : (x))) - -FLAC__SSE_TARGET("ssse3") -uint32_t FLAC__fixed_compute_best_predictor_intrin_ssse3(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]) -{ - FLAC__uint32 total_error_0, total_error_1, total_error_2, total_error_3, total_error_4; - FLAC__int32 i, data_len_int; - uint32_t order; - __m128i total_err0, total_err1, total_err2, total_err3, total_err4; - __m128i prev_err0, prev_err1, prev_err2, prev_err3; - __m128i tempA, tempB; - FLAC__int32 data_scalar[4]; - FLAC__int32 prev_err0_scalar[4]; - FLAC__int32 prev_err1_scalar[4]; - FLAC__int32 prev_err2_scalar[4]; - FLAC__int32 prev_err3_scalar[4]; - total_err0 = _mm_setzero_si128(); - total_err1 = _mm_setzero_si128(); - total_err2 = _mm_setzero_si128(); - total_err3 = _mm_setzero_si128(); - total_err4 = _mm_setzero_si128(); - data_len_int = data_len; - - for(i = 0; i < 4; i++){ - prev_err0_scalar[i] = data[-1+i*(data_len_int/4)]; - prev_err1_scalar[i] = data[-1+i*(data_len_int/4)] - data[-2+i*(data_len_int/4)]; - prev_err2_scalar[i] = prev_err1_scalar[i] - (data[-2+i*(data_len_int/4)] - data[-3+i*(data_len_int/4)]); - prev_err3_scalar[i] = prev_err2_scalar[i] - (data[-2+i*(data_len_int/4)] - 2*data[-3+i*(data_len_int/4)] + data[-4+i*(data_len_int/4)]); - } - prev_err0 = _mm_loadu_si128((const __m128i*)prev_err0_scalar); - prev_err1 = _mm_loadu_si128((const __m128i*)prev_err1_scalar); - prev_err2 = _mm_loadu_si128((const __m128i*)prev_err2_scalar); - prev_err3 = _mm_loadu_si128((const __m128i*)prev_err3_scalar); - for(i = 0; i < data_len_int / 4; i++){ - data_scalar[0] = data[i]; - data_scalar[1] = data[i+data_len/4]; - data_scalar[2] = data[i+2*(data_len/4)]; - data_scalar[3] = data[i+3*(data_len/4)]; - tempA = _mm_loadu_si128((const __m128i*)data_scalar); - tempB = _mm_abs_epi32(tempA); - total_err0 = _mm_add_epi32(total_err0,tempB); - tempB = _mm_sub_epi32(tempA,prev_err0); - prev_err0 = tempA; - tempA = _mm_abs_epi32(tempB); - total_err1 = _mm_add_epi32(total_err1,tempA); - tempA = _mm_sub_epi32(tempB,prev_err1); - prev_err1 = tempB; - tempB = _mm_abs_epi32(tempA); - total_err2 = _mm_add_epi32(total_err2,tempB); - tempB = _mm_sub_epi32(tempA,prev_err2); - prev_err2 = tempA; - tempA = _mm_abs_epi32(tempB); - total_err3 = _mm_add_epi32(total_err3,tempA); - tempA = _mm_sub_epi32(tempB,prev_err3); - prev_err3 = tempB; - tempB = _mm_abs_epi32(tempA); - total_err4 = _mm_add_epi32(total_err4,tempB); - } - _mm_storeu_si128((__m128i*)data_scalar,total_err0); - total_error_0 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm_storeu_si128((__m128i*)data_scalar,total_err1); - total_error_1 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm_storeu_si128((__m128i*)data_scalar,total_err2); - total_error_2 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm_storeu_si128((__m128i*)data_scalar,total_err3); - total_error_3 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - _mm_storeu_si128((__m128i*)data_scalar,total_err4); - total_error_4 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3]; - - /* Now the remainder of samples needs to be processed */ - i *= 4; - if(data_len % 4 > 0){ - FLAC__int32 last_error_0 = data[i-1]; - FLAC__int32 last_error_1 = data[i-1] - data[i-2]; - FLAC__int32 last_error_2 = last_error_1 - (data[i-2] - data[i-3]); - FLAC__int32 last_error_3 = last_error_2 - (data[i-2] - 2*data[i-3] + data[i-4]); - FLAC__int32 error, save; - for(; i < data_len_int; i++) { - error = data[i] ; total_error_0 += local_abs(error); save = error; - error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error; - error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error; - error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error; - error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save; - } - } - - /* prefer lower order */ - if(total_error_0 <= flac_min(flac_min(flac_min(total_error_1, total_error_2), total_error_3), total_error_4)) - order = 0; - else if(total_error_1 <= flac_min(flac_min(total_error_2, total_error_3), total_error_4)) - order = 1; - else if(total_error_2 <= flac_min(total_error_3, total_error_4)) - order = 2; - else if(total_error_3 <= total_error_4) - order = 3; - else - order = 4; - - /* Estimate the expected number of bits per residual signal sample. */ - /* 'total_error*' is linearly related to the variance of the residual */ - /* signal, so we use it directly to compute E(|x|) */ - FLAC__ASSERT(data_len > 0 || total_error_0 == 0); - FLAC__ASSERT(data_len > 0 || total_error_1 == 0); - FLAC__ASSERT(data_len > 0 || total_error_2 == 0); - FLAC__ASSERT(data_len > 0 || total_error_3 == 0); - FLAC__ASSERT(data_len > 0 || total_error_4 == 0); - - residual_bits_per_sample[0] = (float)((total_error_0 > 0) ? log(M_LN2 * (double)total_error_0 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[1] = (float)((total_error_1 > 0) ? log(M_LN2 * (double)total_error_1 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[2] = (float)((total_error_2 > 0) ? log(M_LN2 * (double)total_error_2 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[3] = (float)((total_error_3 > 0) ? log(M_LN2 * (double)total_error_3 / (double)data_len) / M_LN2 : 0.0); - residual_bits_per_sample[4] = (float)((total_error_4 > 0) ? log(M_LN2 * (double)total_error_4 / (double)data_len) / M_LN2 : 0.0); - - return order; -} - -#endif /* FLAC__SSSE3_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/flac.pc.in b/flac/src/libFLAC/flac.pc.in deleted file mode 100644 index 56e8594..0000000 --- a/flac/src/libFLAC/flac.pc.in +++ /dev/null @@ -1,12 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: FLAC -Description: Free Lossless Audio Codec Library -Version: @VERSION@ -Requires.private: @OGG_PACKAGE@ -Libs: -L${libdir} -lFLAC -Libs.private: -lm -Cflags: -I${includedir} diff --git a/flac/src/libFLAC/float.c b/flac/src/libFLAC/float.c deleted file mode 100644 index a06ad28..0000000 --- a/flac/src/libFLAC/float.c +++ /dev/null @@ -1,302 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "FLAC/assert.h" -#include "share/compat.h" -#include "private/float.h" - -#ifdef FLAC__INTEGER_ONLY_LIBRARY - -const FLAC__fixedpoint FLAC__FP_ZERO = 0; -const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000; -const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000; -const FLAC__fixedpoint FLAC__FP_LN2 = 45426; -const FLAC__fixedpoint FLAC__FP_E = 178145; - -/* Lookup tables for Knuth's logarithm algorithm */ -#define LOG2_LOOKUP_PRECISION 16 -static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = { - { - /* - * 0 fraction bits - */ - /* undefined */ 0x00000000, - /* lg(2/1) = */ 0x00000001, - /* lg(4/3) = */ 0x00000000, - /* lg(8/7) = */ 0x00000000, - /* lg(16/15) = */ 0x00000000, - /* lg(32/31) = */ 0x00000000, - /* lg(64/63) = */ 0x00000000, - /* lg(128/127) = */ 0x00000000, - /* lg(256/255) = */ 0x00000000, - /* lg(512/511) = */ 0x00000000, - /* lg(1024/1023) = */ 0x00000000, - /* lg(2048/2047) = */ 0x00000000, - /* lg(4096/4095) = */ 0x00000000, - /* lg(8192/8191) = */ 0x00000000, - /* lg(16384/16383) = */ 0x00000000, - /* lg(32768/32767) = */ 0x00000000 - }, - { - /* - * 4 fraction bits - */ - /* undefined */ 0x00000000, - /* lg(2/1) = */ 0x00000010, - /* lg(4/3) = */ 0x00000007, - /* lg(8/7) = */ 0x00000003, - /* lg(16/15) = */ 0x00000001, - /* lg(32/31) = */ 0x00000001, - /* lg(64/63) = */ 0x00000000, - /* lg(128/127) = */ 0x00000000, - /* lg(256/255) = */ 0x00000000, - /* lg(512/511) = */ 0x00000000, - /* lg(1024/1023) = */ 0x00000000, - /* lg(2048/2047) = */ 0x00000000, - /* lg(4096/4095) = */ 0x00000000, - /* lg(8192/8191) = */ 0x00000000, - /* lg(16384/16383) = */ 0x00000000, - /* lg(32768/32767) = */ 0x00000000 - }, - { - /* - * 8 fraction bits - */ - /* undefined */ 0x00000000, - /* lg(2/1) = */ 0x00000100, - /* lg(4/3) = */ 0x0000006a, - /* lg(8/7) = */ 0x00000031, - /* lg(16/15) = */ 0x00000018, - /* lg(32/31) = */ 0x0000000c, - /* lg(64/63) = */ 0x00000006, - /* lg(128/127) = */ 0x00000003, - /* lg(256/255) = */ 0x00000001, - /* lg(512/511) = */ 0x00000001, - /* lg(1024/1023) = */ 0x00000000, - /* lg(2048/2047) = */ 0x00000000, - /* lg(4096/4095) = */ 0x00000000, - /* lg(8192/8191) = */ 0x00000000, - /* lg(16384/16383) = */ 0x00000000, - /* lg(32768/32767) = */ 0x00000000 - }, - { - /* - * 12 fraction bits - */ - /* undefined */ 0x00000000, - /* lg(2/1) = */ 0x00001000, - /* lg(4/3) = */ 0x000006a4, - /* lg(8/7) = */ 0x00000315, - /* lg(16/15) = */ 0x0000017d, - /* lg(32/31) = */ 0x000000bc, - /* lg(64/63) = */ 0x0000005d, - /* lg(128/127) = */ 0x0000002e, - /* lg(256/255) = */ 0x00000017, - /* lg(512/511) = */ 0x0000000c, - /* lg(1024/1023) = */ 0x00000006, - /* lg(2048/2047) = */ 0x00000003, - /* lg(4096/4095) = */ 0x00000001, - /* lg(8192/8191) = */ 0x00000001, - /* lg(16384/16383) = */ 0x00000000, - /* lg(32768/32767) = */ 0x00000000 - }, - { - /* - * 16 fraction bits - */ - /* undefined */ 0x00000000, - /* lg(2/1) = */ 0x00010000, - /* lg(4/3) = */ 0x00006a40, - /* lg(8/7) = */ 0x00003151, - /* lg(16/15) = */ 0x000017d6, - /* lg(32/31) = */ 0x00000bba, - /* lg(64/63) = */ 0x000005d1, - /* lg(128/127) = */ 0x000002e6, - /* lg(256/255) = */ 0x00000172, - /* lg(512/511) = */ 0x000000b9, - /* lg(1024/1023) = */ 0x0000005c, - /* lg(2048/2047) = */ 0x0000002e, - /* lg(4096/4095) = */ 0x00000017, - /* lg(8192/8191) = */ 0x0000000c, - /* lg(16384/16383) = */ 0x00000006, - /* lg(32768/32767) = */ 0x00000003 - }, - { - /* - * 20 fraction bits - */ - /* undefined */ 0x00000000, - /* lg(2/1) = */ 0x00100000, - /* lg(4/3) = */ 0x0006a3fe, - /* lg(8/7) = */ 0x00031513, - /* lg(16/15) = */ 0x00017d60, - /* lg(32/31) = */ 0x0000bb9d, - /* lg(64/63) = */ 0x00005d10, - /* lg(128/127) = */ 0x00002e59, - /* lg(256/255) = */ 0x00001721, - /* lg(512/511) = */ 0x00000b8e, - /* lg(1024/1023) = */ 0x000005c6, - /* lg(2048/2047) = */ 0x000002e3, - /* lg(4096/4095) = */ 0x00000171, - /* lg(8192/8191) = */ 0x000000b9, - /* lg(16384/16383) = */ 0x0000005c, - /* lg(32768/32767) = */ 0x0000002e - }, - { - /* - * 24 fraction bits - */ - /* undefined */ 0x00000000, - /* lg(2/1) = */ 0x01000000, - /* lg(4/3) = */ 0x006a3fe6, - /* lg(8/7) = */ 0x00315130, - /* lg(16/15) = */ 0x0017d605, - /* lg(32/31) = */ 0x000bb9ca, - /* lg(64/63) = */ 0x0005d0fc, - /* lg(128/127) = */ 0x0002e58f, - /* lg(256/255) = */ 0x0001720e, - /* lg(512/511) = */ 0x0000b8d8, - /* lg(1024/1023) = */ 0x00005c61, - /* lg(2048/2047) = */ 0x00002e2d, - /* lg(4096/4095) = */ 0x00001716, - /* lg(8192/8191) = */ 0x00000b8b, - /* lg(16384/16383) = */ 0x000005c5, - /* lg(32768/32767) = */ 0x000002e3 - }, - { - /* - * 28 fraction bits - */ - /* undefined */ 0x00000000, - /* lg(2/1) = */ 0x10000000, - /* lg(4/3) = */ 0x06a3fe5c, - /* lg(8/7) = */ 0x03151301, - /* lg(16/15) = */ 0x017d6049, - /* lg(32/31) = */ 0x00bb9ca6, - /* lg(64/63) = */ 0x005d0fba, - /* lg(128/127) = */ 0x002e58f7, - /* lg(256/255) = */ 0x001720da, - /* lg(512/511) = */ 0x000b8d87, - /* lg(1024/1023) = */ 0x0005c60b, - /* lg(2048/2047) = */ 0x0002e2d7, - /* lg(4096/4095) = */ 0x00017160, - /* lg(8192/8191) = */ 0x0000b8ad, - /* lg(16384/16383) = */ 0x00005c56, - /* lg(32768/32767) = */ 0x00002e2b - } -}; - -#if 0 -static const FLAC__uint64 log2_lookup_wide[] = { - { - /* - * 32 fraction bits - */ - /* undefined */ 0x00000000, - /* lg(2/1) = */ FLAC__U64L(0x100000000), - /* lg(4/3) = */ FLAC__U64L(0x6a3fe5c6), - /* lg(8/7) = */ FLAC__U64L(0x31513015), - /* lg(16/15) = */ FLAC__U64L(0x17d60497), - /* lg(32/31) = */ FLAC__U64L(0x0bb9ca65), - /* lg(64/63) = */ FLAC__U64L(0x05d0fba2), - /* lg(128/127) = */ FLAC__U64L(0x02e58f74), - /* lg(256/255) = */ FLAC__U64L(0x01720d9c), - /* lg(512/511) = */ FLAC__U64L(0x00b8d875), - /* lg(1024/1023) = */ FLAC__U64L(0x005c60aa), - /* lg(2048/2047) = */ FLAC__U64L(0x002e2d72), - /* lg(4096/4095) = */ FLAC__U64L(0x00171600), - /* lg(8192/8191) = */ FLAC__U64L(0x000b8ad2), - /* lg(16384/16383) = */ FLAC__U64L(0x0005c55d), - /* lg(32768/32767) = */ FLAC__U64L(0x0002e2ac) - }, - { - /* - * 48 fraction bits - */ - /* undefined */ 0x00000000, - /* lg(2/1) = */ FLAC__U64L(0x1000000000000), - /* lg(4/3) = */ FLAC__U64L(0x6a3fe5c60429), - /* lg(8/7) = */ FLAC__U64L(0x315130157f7a), - /* lg(16/15) = */ FLAC__U64L(0x17d60496cfbb), - /* lg(32/31) = */ FLAC__U64L(0xbb9ca64ecac), - /* lg(64/63) = */ FLAC__U64L(0x5d0fba187cd), - /* lg(128/127) = */ FLAC__U64L(0x2e58f7441ee), - /* lg(256/255) = */ FLAC__U64L(0x1720d9c06a8), - /* lg(512/511) = */ FLAC__U64L(0xb8d8752173), - /* lg(1024/1023) = */ FLAC__U64L(0x5c60aa252e), - /* lg(2048/2047) = */ FLAC__U64L(0x2e2d71b0d8), - /* lg(4096/4095) = */ FLAC__U64L(0x1716001719), - /* lg(8192/8191) = */ FLAC__U64L(0xb8ad1de1b), - /* lg(16384/16383) = */ FLAC__U64L(0x5c55d640d), - /* lg(32768/32767) = */ FLAC__U64L(0x2e2abcf52) - } -}; -#endif - -FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, uint32_t fracbits, uint32_t precision) -{ - const FLAC__uint32 ONE = (1u << fracbits); - const FLAC__uint32 *table = log2_lookup[fracbits >> 2]; - - FLAC__ASSERT(fracbits < 32); - FLAC__ASSERT((fracbits & 0x3) == 0); - - if(x < ONE) - return 0; - - if(precision > LOG2_LOOKUP_PRECISION) - precision = LOG2_LOOKUP_PRECISION; - - /* Knuth's algorithm for computing logarithms, optimized for base-2 with lookup tables */ - { - FLAC__uint32 y = 0; - FLAC__uint32 z = x >> 1, k = 1; - while (x > ONE && k < precision) { - if (x - z >= ONE) { - x -= z; - z = x >> k; - y += table[k]; - } - else { - z >>= 1; - k++; - } - } - return y; - } -} - -#endif /* defined FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/format.c b/flac/src/libFLAC/format.c deleted file mode 100644 index 8bbffbe..0000000 --- a/flac/src/libFLAC/format.c +++ /dev/null @@ -1,608 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include /* for qsort() */ -#include /* for memset() */ -#include "FLAC/assert.h" -#include "FLAC/format.h" -#include "share/alloc.h" -#include "share/compat.h" -#include "private/format.h" -#include "private/macros.h" - -#if (defined GIT_COMMIT_HASH && defined GIT_COMMIT_DATE) -# ifdef GIT_COMMIT_TAG -FLAC_API const char *FLAC__VERSION_STRING = GIT_COMMIT_TAG; -FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " GIT_COMMIT_TAG " " GIT_COMMIT_DATE; -# else -FLAC_API const char *FLAC__VERSION_STRING = "git-" GIT_COMMIT_HASH " " GIT_COMMIT_DATE; -FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC git-" GIT_COMMIT_HASH " " GIT_COMMIT_DATE; -# endif -#else -/* PACKAGE_VERSION should come from configure */ -FLAC_API const char *FLAC__VERSION_STRING = PACKAGE_VERSION; -FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " PACKAGE_VERSION " 20230623"; -#endif - -FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' }; -FLAC_API const uint32_t FLAC__STREAM_SYNC = 0x664C6143; -FLAC_API const uint32_t FLAC__STREAM_SYNC_LEN = 32; /* bits */ - -FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */ - -FLAC_API const uint32_t FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */ - -FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */ - -FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff); - -FLAC_API const uint32_t FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */ - -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */ - -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */ - -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */ - -FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */ - -FLAC_API const uint32_t FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */ -FLAC_API const uint32_t FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */ - -FLAC_API const uint32_t FLAC__FRAME_HEADER_SYNC = 0x3ffe; -FLAC_API const uint32_t FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */ -FLAC_API const uint32_t FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */ -FLAC_API const uint32_t FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */ -FLAC_API const uint32_t FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */ -FLAC_API const uint32_t FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */ -FLAC_API const uint32_t FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */ -FLAC_API const uint32_t FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */ -FLAC_API const uint32_t FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */ -FLAC_API const uint32_t FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */ - -FLAC_API const uint32_t FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */ - -FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */ -FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */ -FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */ -FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */ -FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */ - -FLAC_API const uint32_t FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1< FLAC__MAX_SAMPLE_RATE) { - return false; - } - else - return true; -} - -FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(uint32_t blocksize, uint32_t sample_rate) -{ - if(blocksize > 16384) - return false; - else if(sample_rate <= 48000 && blocksize > 4608) - return false; - else - return true; -} - -FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(uint32_t sample_rate) -{ - if( // sample rate is not subset if - !FLAC__format_sample_rate_is_valid(sample_rate) || // sample rate is invalid or - sample_rate >= ((1u << 16) * 10) || // sample rate is larger then or equal to 655360 or - (sample_rate >= (1u << 16) && sample_rate % 10 != 0) //sample rate is >= 65536 and not divisible by 10 - ) { - return false; - } - else - return true; -} - -/* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */ -FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table) -{ - uint32_t i; - FLAC__uint64 prev_sample_number = 0; - FLAC__bool got_prev = false; - - FLAC__ASSERT(0 != seek_table); - - if((FLAC__uint64)(seek_table->num_points) * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) - return false; - - for(i = 0; i < seek_table->num_points; i++) { - if(got_prev) { - if( - seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER && - seek_table->points[i].sample_number <= prev_sample_number - ) - return false; - } - prev_sample_number = seek_table->points[i].sample_number; - got_prev = true; - } - - return true; -} - -/* used as the sort predicate for qsort() */ -static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r) -{ - /* we don't just 'return l->sample_number - r->sample_number' since the result (FLAC__int64) might overflow an 'int' */ - if(l->sample_number == r->sample_number) - return 0; - else if(l->sample_number < r->sample_number) - return -1; - else - return 1; -} - -/* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */ -FLAC_API uint32_t FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table) -{ - uint32_t i, j; - FLAC__bool first; - - FLAC__ASSERT(0 != seek_table); - - if (seek_table->num_points == 0) - return 0; - - /* sort the seekpoints */ - qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_); - - /* uniquify the seekpoints */ - first = true; - for(i = j = 0; i < seek_table->num_points; i++) { - if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) { - if(!first) { - if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number) - continue; - } - } - first = false; - seek_table->points[j++] = seek_table->points[i]; - } - - for(i = j; i < seek_table->num_points; i++) { - seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - seek_table->points[i].stream_offset = 0; - seek_table->points[i].frame_samples = 0; - } - - return j; -} - -/* - * also disallows non-shortest-form encodings, c.f. - * http://www.unicode.org/versions/corrigendum1.html - * and a more clear explanation at the end of this section: - * http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - */ -static uint32_t utf8len_(const FLAC__byte *utf8) -{ - FLAC__ASSERT(0 != utf8); - if ((utf8[0] & 0x80) == 0) { - return 1; - } - else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) { - if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */ - return 0; - return 2; - } - else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) { - if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */ - return 0; - /* illegal surrogates check (U+D800...U+DFFF and U+FFFE...U+FFFF) */ - if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */ - return 0; - if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */ - return 0; - return 3; - } - else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) { - if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */ - return 0; - return 4; - } - else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) { - if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */ - return 0; - return 5; - } - else if ((utf8[0] & 0xFE) == 0xFC && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80 && (utf8[5] & 0xC0) == 0x80) { - if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */ - return 0; - return 6; - } - else { - return 0; - } -} - -FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name) -{ - char c; - for(c = *name; c; c = *(++name)) - if(c < 0x20 || c == 0x3d || c > 0x7d) - return false; - return true; -} - -FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, uint32_t length) -{ - if(length == (uint32_t)(-1)) { - while(*value) { - uint32_t n = utf8len_(value); - if(n == 0) - return false; - value += n; - } - } - else { - const FLAC__byte *end = value + length; - while(value < end) { - uint32_t n = utf8len_(value); - if(n == 0) - return false; - value += n; - } - if(value != end) - return false; - } - return true; -} - -FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, uint32_t length) -{ - const FLAC__byte *s, *end; - - for(s = entry, end = s + length; s < end && *s != '='; s++) { - if(*s < 0x20 || *s > 0x7D) - return false; - } - if(s == end) - return false; - - s++; /* skip '=' */ - - while(s < end) { - uint32_t n = utf8len_(s); - if(n == 0) - return false; - s += n; - } - if(s != end) - return false; - - return true; -} - -/* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */ -FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation) -{ - uint32_t i, j; - - if(check_cd_da_subset) { - if(cue_sheet->lead_in < 2 * 44100) { - if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds"; - return false; - } - if(cue_sheet->lead_in % 588 != 0) { - if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples"; - return false; - } - } - - if(cue_sheet->num_tracks == 0) { - if(violation) *violation = "cue sheet must have at least one track (the lead-out)"; - return false; - } - - if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) { - if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)"; - return false; - } - - for(i = 0; i < cue_sheet->num_tracks; i++) { - if(cue_sheet->tracks[i].number == 0) { - if(violation) *violation = "cue sheet may not have a track number 0"; - return false; - } - - if(check_cd_da_subset) { - if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) { - if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170"; - return false; - } - } - - if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) { - if(violation) { - if(i == cue_sheet->num_tracks-1) /* the lead-out track... */ - *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples"; - else - *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples"; - } - return false; - } - - if(i < cue_sheet->num_tracks - 1) { - if(cue_sheet->tracks[i].num_indices == 0) { - if(violation) *violation = "cue sheet track must have at least one index point"; - return false; - } - - if(cue_sheet->tracks[i].indices[0].number > 1) { - if(violation) *violation = "cue sheet track's first index number must be 0 or 1"; - return false; - } - } - - for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) { - if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) { - if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples"; - return false; - } - - if(j > 0) { - if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) { - if(violation) *violation = "cue sheet track index numbers must increase by 1"; - return false; - } - } - } - } - - return true; -} - -/* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */ -FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation) -{ - char *p; - FLAC__byte *b; - - for(p = picture->mime_type; *p; p++) { - if(*p < 0x20 || *p > 0x7e) { - if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)"; - return false; - } - } - - for(b = picture->description; *b; ) { - uint32_t n = utf8len_(b); - if(n == 0) { - if(violation) *violation = "description string must be valid UTF-8"; - return false; - } - b += n; - } - - return true; -} - -/* - * These routines are private to libFLAC - */ -#if 0 /* UNUSED */ -uint32_t FLAC__format_get_max_rice_partition_order(uint32_t blocksize, uint32_t predictor_order) -{ - return - FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order( - FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize), - blocksize, - predictor_order - ); -} -#endif - -uint32_t FLAC__format_get_max_rice_partition_order_from_blocksize(uint32_t blocksize) -{ - uint32_t max_rice_partition_order = 0; - while(!(blocksize & 1)) { - max_rice_partition_order++; - blocksize >>= 1; - } - return flac_min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order); -} - -uint32_t FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(uint32_t limit, uint32_t blocksize, uint32_t predictor_order) -{ - uint32_t max_rice_partition_order = limit; - - while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order) - max_rice_partition_order--; - - FLAC__ASSERT( - (max_rice_partition_order == 0 && blocksize >= predictor_order) || - (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order) - ); - - return max_rice_partition_order; -} - -void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object) -{ - FLAC__ASSERT(0 != object); - - object->parameters = 0; - object->raw_bits = 0; - object->capacity_by_order = 0; -} - -void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object) -{ - FLAC__ASSERT(0 != object); - - if(0 != object->parameters) - free(object->parameters); - if(0 != object->raw_bits) - free(object->raw_bits); - FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object); -} - -#if defined(_MSC_VER) -// silence three MSVC warnings 'result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)' -#pragma warning ( disable : 4334 ) -#endif - -FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, uint32_t max_partition_order) -{ - FLAC__ASSERT(0 != object); - - if(object->capacity_by_order < max_partition_order || object->parameters == NULL || object->raw_bits == NULL) { - if(0 == (object->parameters = safe_realloc_(object->parameters, sizeof(uint32_t)*(1 << max_partition_order)))) - return false; - if(0 == (object->raw_bits = safe_realloc_(object->raw_bits, sizeof(uint32_t)*(1 << max_partition_order)))) - return false; - memset(object->raw_bits, 0, sizeof(uint32_t)*(1 << max_partition_order)); - object->capacity_by_order = max_partition_order; - } - - return true; -} - -#if defined(_MSC_VER) -#pragma warning ( default : 4334 ) -#endif diff --git a/flac/src/libFLAC/include/Makefile.am b/flac/src/libFLAC/include/Makefile.am deleted file mode 100644 index 8484d12..0000000 --- a/flac/src/libFLAC/include/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -# libFLAC - Free Lossless Audio Codec library -# Copyright (C) 2001-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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 Xiph.org Foundation 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 FOUNDATION 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. - -SUBDIRS = private protected diff --git a/flac/src/libFLAC/include/private/Makefile.am b/flac/src/libFLAC/include/private/Makefile.am deleted file mode 100644 index 3e63d31..0000000 --- a/flac/src/libFLAC/include/private/Makefile.am +++ /dev/null @@ -1,53 +0,0 @@ -# libFLAC - Free Lossless Audio Codec library -# Copyright (C) 2001-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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 Xiph.org Foundation 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 FOUNDATION 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. - -noinst_HEADERS = \ - all.h \ - bitmath.h \ - bitreader.h \ - bitwriter.h \ - cpu.h \ - crc.h \ - fixed.h \ - float.h \ - format.h \ - lpc.h \ - macros.h \ - md5.h \ - memory.h \ - metadata.h \ - ogg_decoder_aspect.h \ - ogg_encoder_aspect.h \ - ogg_helper.h \ - ogg_mapping.h \ - stream_encoder.h \ - stream_encoder_framing.h \ - window.h diff --git a/flac/src/libFLAC/include/private/all.h b/flac/src/libFLAC/include/private/all.h deleted file mode 100644 index 10b6949..0000000 --- a/flac/src/libFLAC/include/private/all.h +++ /dev/null @@ -1,50 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__ALL_H -#define FLAC__PRIVATE__ALL_H - -#include "bitmath.h" -#include "bitreader.h" -#include "bitwriter.h" -#include "cpu.h" -#include "crc.h" -#include "fixed.h" -#include "float.h" -#include "format.h" -#include "lpc.h" -#include "md5.h" -#include "memory.h" -#include "metadata.h" -#include "stream_encoder_framing.h" - -#endif diff --git a/flac/src/libFLAC/include/private/bitmath.h b/flac/src/libFLAC/include/private/bitmath.h deleted file mode 100644 index 12e062f..0000000 --- a/flac/src/libFLAC/include/private/bitmath.h +++ /dev/null @@ -1,210 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__BITMATH_H -#define FLAC__PRIVATE__BITMATH_H - -#include "FLAC/ordinals.h" -#include "FLAC/assert.h" - -#include "share/compat.h" - -#if defined(_MSC_VER) -#include /* for _BitScanReverse* */ -#endif - -/* Will never be emitted for MSVC, GCC, Intel compilers */ -static inline uint32_t FLAC__clz_soft_uint32(FLAC__uint32 word) -{ - static const uint8_t byte_to_unary_table[] = { - 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, - 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, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - }; - - return word > 0xffffff ? byte_to_unary_table[word >> 24] : - word > 0xffff ? byte_to_unary_table[word >> 16] + 8 : - word > 0xff ? byte_to_unary_table[word >> 8] + 16 : - byte_to_unary_table[word] + 24; -} - -static inline uint32_t FLAC__clz_uint32(FLAC__uint32 v) -{ -/* Never used with input 0 */ - FLAC__ASSERT(v > 0); -#if defined(__INTEL_COMPILER) - return _bit_scan_reverse(v) ^ 31U; -#elif defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -/* This will translate either to (bsr ^ 31U), clz , ctlz, cntlz, lzcnt depending on - * -march= setting or to a software routine in exotic machines. */ - return __builtin_clz(v); -#elif defined(_MSC_VER) - { - uint32_t idx; - _BitScanReverse(&idx, v); - return idx ^ 31U; - } -#else - return FLAC__clz_soft_uint32(v); -#endif -} - -/* Used when 64-bit bsr/clz is unavailable; can use 32-bit bsr/clz when possible */ -static inline uint32_t FLAC__clz_soft_uint64(FLAC__uint64 word) -{ - return (FLAC__uint32)(word>>32) ? FLAC__clz_uint32((FLAC__uint32)(word>>32)) : - FLAC__clz_uint32((FLAC__uint32)word) + 32; -} - -static inline uint32_t FLAC__clz_uint64(FLAC__uint64 v) -{ - /* Never used with input 0 */ - FLAC__ASSERT(v > 0); -#if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) - return __builtin_clzll(v); -#elif (defined(__INTEL_COMPILER) || defined(_MSC_VER)) && (defined(_M_IA64) || defined(_M_X64)) - { - uint32_t idx; - _BitScanReverse64(&idx, v); - return idx ^ 63U; - } -#else - return FLAC__clz_soft_uint64(v); -#endif -} - -/* These two functions work with input 0 */ -static inline uint32_t FLAC__clz2_uint32(FLAC__uint32 v) -{ - if (!v) - return 32; - return FLAC__clz_uint32(v); -} - -static inline uint32_t FLAC__clz2_uint64(FLAC__uint64 v) -{ - if (!v) - return 64; - return FLAC__clz_uint64(v); -} - -/* An example of what FLAC__bitmath_ilog2() computes: - * - * ilog2( 0) = assertion failure - * ilog2( 1) = 0 - * ilog2( 2) = 1 - * ilog2( 3) = 1 - * ilog2( 4) = 2 - * ilog2( 5) = 2 - * ilog2( 6) = 2 - * ilog2( 7) = 2 - * ilog2( 8) = 3 - * ilog2( 9) = 3 - * ilog2(10) = 3 - * ilog2(11) = 3 - * ilog2(12) = 3 - * ilog2(13) = 3 - * ilog2(14) = 3 - * ilog2(15) = 3 - * ilog2(16) = 4 - * ilog2(17) = 4 - * ilog2(18) = 4 - */ - -static inline uint32_t FLAC__bitmath_ilog2(FLAC__uint32 v) -{ - FLAC__ASSERT(v > 0); -#if defined(__INTEL_COMPILER) - return _bit_scan_reverse(v); -#elif defined(_MSC_VER) - { - uint32_t idx; - _BitScanReverse(&idx, v); - return idx; - } -#else - return FLAC__clz_uint32(v) ^ 31U; -#endif -} - -static inline uint32_t FLAC__bitmath_ilog2_wide(FLAC__uint64 v) -{ - FLAC__ASSERT(v > 0); -#if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) - return __builtin_clzll(v) ^ 63U; -/* Sorry, only supported in x64/Itanium.. and both have fast FPU which makes integer-only encoder pointless */ -#elif (defined(__INTEL_COMPILER) || defined(_MSC_VER)) && (defined(_M_IA64) || defined(_M_X64)) - { - uint32_t idx; - _BitScanReverse64(&idx, v); - return idx; - } -#else -/* Brain-damaged compilers will use the fastest possible way that is, - de Bruijn sequences (http://supertech.csail.mit.edu/papers/debruijn.pdf) - (C) Timothy B. Terriberry (tterribe@xiph.org) 2001-2009 CC0 (Public domain). -*/ - { - static const uint8_t DEBRUIJN_IDX64[64]={ - 0, 1, 2, 7, 3,13, 8,19, 4,25,14,28, 9,34,20,40, - 5,17,26,38,15,46,29,48,10,31,35,54,21,50,41,57, - 63, 6,12,18,24,27,33,39,16,37,45,47,30,53,49,56, - 62,11,23,32,36,44,52,55,61,22,43,51,60,42,59,58 - }; - v|= v>>1; - v|= v>>2; - v|= v>>4; - v|= v>>8; - v|= v>>16; - v|= v>>32; - v= (v>>1)+1; - return DEBRUIJN_IDX64[v*FLAC__U64L(0x218A392CD3D5DBF)>>58&0x3F]; - } -#endif -} - -uint32_t FLAC__bitmath_silog2(FLAC__int64 v); - -#endif diff --git a/flac/src/libFLAC/include/private/bitreader.h b/flac/src/libFLAC/include/private/bitreader.h deleted file mode 100644 index c36c926..0000000 --- a/flac/src/libFLAC/include/private/bitreader.h +++ /dev/null @@ -1,101 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__BITREADER_H -#define FLAC__PRIVATE__BITREADER_H - -#include /* for FILE */ -#include "FLAC/ordinals.h" -#include "cpu.h" - -/* - * opaque structure definition - */ -struct FLAC__BitReader; -typedef struct FLAC__BitReader FLAC__BitReader; - -typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data); - -/* - * construction, deletion, initialization, etc functions - */ -FLAC__BitReader *FLAC__bitreader_new(void); -void FLAC__bitreader_delete(FLAC__BitReader *br); -FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__BitReaderReadCallback rcb, void *cd); -void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */ -FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br); -void FLAC__bitreader_set_framesync_location(FLAC__BitReader *br); -FLAC__bool FLAC__bitreader_rewind_to_after_last_seen_framesync(FLAC__BitReader *br); - -/* - * CRC functions - */ -void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed); -FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br); - -/* - * info functions - */ -FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br); -uint32_t FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br); -uint32_t FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br); -void FLAC__bitreader_set_limit(FLAC__BitReader *br, uint32_t limit); -void FLAC__bitreader_remove_limit(FLAC__BitReader *br); -uint32_t FLAC__bitreader_limit_remaining(FLAC__BitReader *br); -void FLAC__bitreader_limit_invalidate(FLAC__BitReader *br); - -/* - * read functions - */ - -FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, uint32_t bits); -FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, uint32_t bits); -FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, uint32_t bits); -FLAC__bool FLAC__bitreader_read_raw_int64(FLAC__BitReader *br, FLAC__int64 *val, uint32_t bits); -FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/ -FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, uint32_t bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */ -FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, uint32_t nvals); /* WATCHOUT: does not CRC the read data! */ -FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, uint32_t nvals); /* WATCHOUT: does not CRC the read data! */ -FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, uint32_t *val); -FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, uint32_t parameter); -FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter); -#ifdef FLAC__BMI2_SUPPORTED -FLAC__bool FLAC__bitreader_read_rice_signed_block_bmi2(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter); -#endif - -#if 0 /* UNUSED */ -FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, uint32_t parameter); -FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, uint32_t *val, uint32_t parameter); -#endif -FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, uint32_t *rawlen); -FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, uint32_t *rawlen); -#endif diff --git a/flac/src/libFLAC/include/private/bitwriter.h b/flac/src/libFLAC/include/private/bitwriter.h deleted file mode 100644 index 39bcf25..0000000 --- a/flac/src/libFLAC/include/private/bitwriter.h +++ /dev/null @@ -1,104 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__BITWRITER_H -#define FLAC__PRIVATE__BITWRITER_H - -#include /* for FILE */ -#include "FLAC/ordinals.h" - -/* - * opaque structure definition - */ -struct FLAC__BitWriter; -typedef struct FLAC__BitWriter FLAC__BitWriter; - -/* - * construction, deletion, initialization, etc functions - */ -FLAC__BitWriter *FLAC__bitwriter_new(void); -void FLAC__bitwriter_delete(FLAC__BitWriter *bw); -FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw); -void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */ -void FLAC__bitwriter_clear(FLAC__BitWriter *bw); - -/* - * CRC functions - * - * non-const *bw because they have to cal FLAC__bitwriter_get_buffer() - */ -FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc); -FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc); - -/* - * info functions - */ -FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw); -uint32_t FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */ - -/* - * direct buffer access - * - * there may be no calls on the bitwriter between get and release. - * the bitwriter continues to own the returned buffer. - * before get, bitwriter MUST be byte aligned: check with FLAC__bitwriter_is_byte_aligned() - */ -FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes); -void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw); - -/* - * write functions - */ -FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, uint32_t bits); -FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, uint32_t bits); -FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t bits); -FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, uint32_t bits); -FLAC__bool FLAC__bitwriter_write_raw_int64(FLAC__BitWriter *bw, FLAC__int64 val, uint32_t bits); -FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/ -FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], uint32_t nvals); -FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, uint32_t val); -#if 0 /* UNUSED */ -uint32_t FLAC__bitwriter_rice_bits(FLAC__int32 val, uint32_t parameter); -uint32_t FLAC__bitwriter_golomb_bits_signed(int val, uint32_t parameter); -uint32_t FLAC__bitwriter_golomb_bits_unsigned(uint32_t val, uint32_t parameter); -FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, uint32_t parameter); -#endif -FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, uint32_t nvals, uint32_t parameter); -#if 0 /* UNUSED */ -FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, uint32_t parameter); -FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, uint32_t val, uint32_t parameter); -#endif -FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val); -FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val); -FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw); - -#endif diff --git a/flac/src/libFLAC/include/private/cpu.h b/flac/src/libFLAC/include/private/cpu.h deleted file mode 100644 index 8843c74..0000000 --- a/flac/src/libFLAC/include/private/cpu.h +++ /dev/null @@ -1,198 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__CPU_H -#define FLAC__PRIVATE__CPU_H - -#include "FLAC/ordinals.h" - -#ifdef HAVE_CONFIG_H -#include -#endif - -#ifndef FLAC__CPU_X86_64 - -#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) -#define FLAC__CPU_X86_64 -#endif - -#endif - -#ifndef FLAC__CPU_IA32 - -#if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) ||defined( __i386) || defined(_M_IX86) -#define FLAC__CPU_IA32 -#endif - -#endif - -#ifndef __has_attribute -#define __has_attribute(x) 0 -#endif - -#if FLAC__HAS_X86INTRIN -/* SSE intrinsics support by ICC/MSVC/GCC */ -#if defined __INTEL_COMPILER - #define FLAC__SSE_TARGET(x) - #define FLAC__SSE_SUPPORTED 1 - #define FLAC__SSE2_SUPPORTED 1 - #if (__INTEL_COMPILER >= 1000) /* Intel C++ Compiler 10.0 */ - #define FLAC__SSSE3_SUPPORTED 1 - #define FLAC__SSE4_1_SUPPORTED 1 - #define FLAC__SSE4_2_SUPPORTED 1 - #endif - #ifdef FLAC__USE_AVX - #if (__INTEL_COMPILER >= 1110) /* Intel C++ Compiler 11.1 */ - #define FLAC__AVX_SUPPORTED 1 - #endif - #if (__INTEL_COMPILER >= 1300) /* Intel C++ Compiler 13.0 */ - #define FLAC__AVX2_SUPPORTED 1 - #define FLAC__FMA_SUPPORTED 1 - #endif - #endif -#elif defined __clang__ && __has_attribute(__target__) /* clang */ - #define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x))) - #define FLAC__SSE_SUPPORTED 1 - #define FLAC__SSE2_SUPPORTED 1 - #define FLAC__SSSE3_SUPPORTED 1 - #define FLAC__SSE4_1_SUPPORTED 1 - #define FLAC__SSE4_2_SUPPORTED 1 - #ifdef FLAC__USE_AVX - #define FLAC__AVX_SUPPORTED 1 - #define FLAC__AVX2_SUPPORTED 1 - #define FLAC__FMA_SUPPORTED 1 - #define FLAC__BMI2_SUPPORTED 1 - #endif -#elif defined __GNUC__ && !defined __clang__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) /* GCC 4.9+ */ - #define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x))) - #define FLAC__SSE_SUPPORTED 1 - #define FLAC__SSE2_SUPPORTED 1 - #define FLAC__SSSE3_SUPPORTED 1 - #define FLAC__SSE4_1_SUPPORTED 1 - #define FLAC__SSE4_2_SUPPORTED 1 - #ifdef FLAC__USE_AVX - #define FLAC__AVX_SUPPORTED 1 - #define FLAC__AVX2_SUPPORTED 1 - #define FLAC__FMA_SUPPORTED 1 - #define FLAC__BMI2_SUPPORTED 1 - #endif -#elif defined _MSC_VER - #define FLAC__SSE_TARGET(x) - #define FLAC__SSE_SUPPORTED 1 - #define FLAC__SSE2_SUPPORTED 1 - #if (_MSC_VER >= 1500) /* MS Visual Studio 2008 */ - #define FLAC__SSSE3_SUPPORTED 1 - #define FLAC__SSE4_1_SUPPORTED 1 - #define FLAC__SSE4_2_SUPPORTED 1 - #endif - #ifdef FLAC__USE_AVX - #if (_MSC_FULL_VER >= 160040219) /* MS Visual Studio 2010 SP1 */ - #define FLAC__AVX_SUPPORTED 1 - #endif - #if (_MSC_VER >= 1700) /* MS Visual Studio 2012 */ - #define FLAC__AVX2_SUPPORTED 1 - #define FLAC__FMA_SUPPORTED 1 - #endif - #endif -#else - #define FLAC__SSE_TARGET(x) - #ifdef __SSE__ - #define FLAC__SSE_SUPPORTED 1 - #endif - #ifdef __SSE2__ - #define FLAC__SSE2_SUPPORTED 1 - #endif - #ifdef __SSSE3__ - #define FLAC__SSSE3_SUPPORTED 1 - #endif - #ifdef __SSE4_1__ - #define FLAC__SSE4_1_SUPPORTED 1 - #endif - #ifdef __SSE4_2__ - #define FLAC__SSE4_2_SUPPORTED 1 - #endif - #ifdef FLAC__USE_AVX - #ifdef __AVX__ - #define FLAC__AVX_SUPPORTED 1 - #endif - #ifdef __AVX2__ - #define FLAC__AVX2_SUPPORTED 1 - #endif - #ifdef __FMA__ - #define FLAC__FMA_SUPPORTED 1 - #endif - #endif -#endif /* compiler version */ -#endif /* intrinsics support */ - - -#ifndef FLAC__AVX_SUPPORTED -#define FLAC__AVX_SUPPORTED 0 -#endif - -typedef enum { - FLAC__CPUINFO_TYPE_IA32, - FLAC__CPUINFO_TYPE_X86_64, - FLAC__CPUINFO_TYPE_UNKNOWN -} FLAC__CPUInfo_Type; - -typedef struct { - FLAC__bool intel; - - FLAC__bool cmov; - FLAC__bool mmx; - FLAC__bool sse; - FLAC__bool sse2; - - FLAC__bool sse3; - FLAC__bool ssse3; - FLAC__bool sse41; - FLAC__bool sse42; - FLAC__bool avx; - FLAC__bool avx2; - FLAC__bool fma; - FLAC__bool bmi2; -} FLAC__CPUInfo_x86; - -typedef struct { - FLAC__bool use_asm; - FLAC__CPUInfo_Type type; - FLAC__CPUInfo_x86 x86; -} FLAC__CPUInfo; - -void FLAC__cpu_info(FLAC__CPUInfo *info); - -FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void); - -void FLAC__cpu_info_asm_ia32(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint32 *ecx, FLAC__uint32 *edx); - -#endif diff --git a/flac/src/libFLAC/include/private/crc.h b/flac/src/libFLAC/include/private/crc.h deleted file mode 100644 index fe44502..0000000 --- a/flac/src/libFLAC/include/private/crc.h +++ /dev/null @@ -1,60 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__CRC_H -#define FLAC__PRIVATE__CRC_H - -#include "FLAC/ordinals.h" - -/* 8 bit CRC generator, MSB shifted first -** polynomial = x^8 + x^2 + x^1 + x^0 -** init = 0 -*/ -FLAC__uint8 FLAC__crc8(const FLAC__byte *data, uint32_t len); - -/* 16 bit CRC generator, MSB shifted first -** polynomial = x^16 + x^15 + x^2 + x^0 -** init = 0 -*/ -extern FLAC__uint16 const FLAC__crc16_table[8][256]; - -#define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[0][((crc)>>8) ^ (data)]) -/* this alternate may be faster on some systems/compilers */ -#if 0 -#define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[0][((crc)>>8) ^ (data)]) & 0xffff) -#endif - -FLAC__uint16 FLAC__crc16(const FLAC__byte *data, uint32_t len); -FLAC__uint16 FLAC__crc16_update_words32(const FLAC__uint32 *words, uint32_t len, FLAC__uint16 crc); -FLAC__uint16 FLAC__crc16_update_words64(const FLAC__uint64 *words, uint32_t len, FLAC__uint16 crc); - -#endif diff --git a/flac/src/libFLAC/include/private/fixed.h b/flac/src/libFLAC/include/private/fixed.h deleted file mode 100644 index c4efecd..0000000 --- a/flac/src/libFLAC/include/private/fixed.h +++ /dev/null @@ -1,117 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__FIXED_H -#define FLAC__PRIVATE__FIXED_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "private/cpu.h" -#include "private/float.h" -#include "FLAC/format.h" - -/* - * FLAC__fixed_compute_best_predictor() - * -------------------------------------------------------------------- - * Compute the best fixed predictor and the expected bits-per-sample - * of the residual signal for each order. The _wide() version uses - * 64-bit integers which is statistically necessary when bits-per- - * sample + log2(blocksize) > 30 - * - * IN data[0,data_len-1] - * IN data_len - * OUT residual_bits_per_sample[0,FLAC__MAX_FIXED_ORDER] - */ -#ifndef FLAC__INTEGER_ONLY_LIBRARY -uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -uint32_t FLAC__fixed_compute_best_predictor_limit_residual(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -uint32_t FLAC__fixed_compute_best_predictor_limit_residual_33bit(const FLAC__int64 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -# ifndef FLAC__NO_ASM -# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -# ifdef FLAC__SSE2_SUPPORTED -uint32_t FLAC__fixed_compute_best_predictor_intrin_sse2(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER + 1]); -# endif -# ifdef FLAC__SSSE3_SUPPORTED -uint32_t FLAC__fixed_compute_best_predictor_intrin_ssse3(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -# endif -# ifdef FLAC__SSE4_2_SUPPORTED -uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -# endif -# ifdef FLAC__AVX2_SUPPORTED -uint32_t FLAC__fixed_compute_best_predictor_wide_intrin_avx2(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_avx2(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -# endif -# endif -# endif -#else -uint32_t FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -uint32_t FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -uint32_t FLAC__fixed_compute_best_predictor_limit_residual(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -uint32_t FLAC__fixed_compute_best_predictor_limit_residual_33bit(const FLAC__int64 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -#endif - -/* - * FLAC__fixed_compute_residual() - * -------------------------------------------------------------------- - * Compute the residual signal obtained from sutracting the predicted - * signal from the original. - * - * IN data[-order,data_len-1] original signal (NOTE THE INDICES!) - * IN data_len length of original signal - * IN order <= FLAC__MAX_FIXED_ORDER fixed-predictor order - * OUT residual[0,data_len-1] residual signal - */ -void FLAC__fixed_compute_residual(const FLAC__int32 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[]); -void FLAC__fixed_compute_residual_wide(const FLAC__int32 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[]); -void FLAC__fixed_compute_residual_wide_33bit(const FLAC__int64 data[], uint32_t data_len, uint32_t order, FLAC__int32 residual[]); - -/* - * FLAC__fixed_restore_signal() - * -------------------------------------------------------------------- - * Restore the original signal by summing the residual and the - * predictor. - * - * IN residual[0,data_len-1] residual signal - * IN data_len length of original signal - * IN order <= FLAC__MAX_FIXED_ORDER fixed-predictor order - * *** IMPORTANT: the caller must pass in the historical samples: - * IN data[-order,-1] previously-reconstructed historical samples - * OUT data[0,data_len-1] original signal - */ -void FLAC__fixed_restore_signal(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int32 data[]); -void FLAC__fixed_restore_signal_wide(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int32 data[]); -void FLAC__fixed_restore_signal_wide_33bit(const FLAC__int32 residual[], uint32_t data_len, uint32_t order, FLAC__int64 data[]); - -#endif diff --git a/flac/src/libFLAC/include/private/float.h b/flac/src/libFLAC/include/private/float.h deleted file mode 100644 index bec2634..0000000 --- a/flac/src/libFLAC/include/private/float.h +++ /dev/null @@ -1,95 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__FLOAT_H -#define FLAC__PRIVATE__FLOAT_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "FLAC/ordinals.h" - -/* - * All the code in libFLAC that uses float and double - * should be protected by checks of the macro - * FLAC__INTEGER_ONLY_LIBRARY. - * - */ -#ifndef FLAC__INTEGER_ONLY_LIBRARY -/* - * FLAC__real is the basic floating point type used in LPC analysis. - * - * WATCHOUT: changing FLAC__real will change the signatures of many - * functions that have assembly language equivalents and break them. - */ -typedef float FLAC__real; -#else -/* - * The convention for FLAC__fixedpoint is to use the upper 16 bits - * for the integer part and lower 16 bits for the fractional part. - */ -typedef FLAC__int32 FLAC__fixedpoint; -extern const FLAC__fixedpoint FLAC__FP_ZERO; -extern const FLAC__fixedpoint FLAC__FP_ONE_HALF; -extern const FLAC__fixedpoint FLAC__FP_ONE; -extern const FLAC__fixedpoint FLAC__FP_LN2; -extern const FLAC__fixedpoint FLAC__FP_E; - -#define FLAC__fixedpoint_trunc(x) ((x)>>16) - -#define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) ) - -#define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) ) - -/* - * FLAC__fixedpoint_log2() - * -------------------------------------------------------------------- - * Returns the base-2 logarithm of the fixed-point number 'x' using an - * algorithm by Knuth for x >= 1.0 - * - * 'fracbits' is the number of fractional bits of 'x'. 'fracbits' must - * be < 32 and evenly divisible by 4 (0 is OK but not very precise). - * - * 'precision' roughly limits the number of iterations that are done; - * use (uint32_t)(-1) for maximum precision. - * - * If 'x' is less than one -- that is, x < (1< -#endif - -#include "private/cpu.h" -#include "private/float.h" -#include "FLAC/format.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY - -/* - * FLAC__lpc_window_data() - * -------------------------------------------------------------------- - * Applies the given window to the data. - * OPT: asm implementation - * - * IN in[0,data_len-1] - * IN window[0,data_len-1] - * OUT out[0,lag-1] - * IN data_len - */ -void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len); -void FLAC__lpc_window_data_wide(const FLAC__int64 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len); -void FLAC__lpc_window_data_partial(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len, uint32_t part_size, uint32_t data_shift); -void FLAC__lpc_window_data_partial_wide(const FLAC__int64 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len, uint32_t part_size, uint32_t data_shift); - -/* - * FLAC__lpc_compute_autocorrelation() - * -------------------------------------------------------------------- - * Compute the autocorrelation for lags between 0 and lag-1. - * Assumes data[] outside of [0,data_len-1] == 0. - * Asserts that lag > 0. - * - * IN data[0,data_len-1] - * IN data_len - * IN 0 < lag <= data_len - * OUT autoc[0,lag-1] - */ -void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); -#ifndef FLAC__NO_ASM -# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -# ifdef FLAC__SSE2_SUPPORTED -void FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); -void FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_10(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); -void FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_14(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); -# endif -# endif -# if defined FLAC__CPU_X86_64 && FLAC__HAS_X86INTRIN -# ifdef FLAC__FMA_SUPPORTED -void FLAC__lpc_compute_autocorrelation_intrin_fma_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); -void FLAC__lpc_compute_autocorrelation_intrin_fma_lag_12(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); -void FLAC__lpc_compute_autocorrelation_intrin_fma_lag_16(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); -# endif -# endif -#if defined FLAC__CPU_ARM64 && FLAC__HAS_NEONINTRIN && FLAC__HAS_A64NEONINTRIN -void FLAC__lpc_compute_autocorrelation_intrin_neon_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); -void FLAC__lpc_compute_autocorrelation_intrin_neon_lag_10(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); -void FLAC__lpc_compute_autocorrelation_intrin_neon_lag_14(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); -#endif -#endif /* FLAC__NO_ASM */ - -/* - * FLAC__lpc_compute_lp_coefficients() - * -------------------------------------------------------------------- - * Computes LP coefficients for orders 1..max_order. - * Do not call if autoc[0] == 0.0. This means the signal is zero - * and there is no point in calculating a predictor. - * - * IN autoc[0,max_order] autocorrelation values - * IN 0 < max_order <= FLAC__MAX_LPC_ORDER max LP order to compute - * OUT lp_coeff[0,max_order-1][0,max_order-1] LP coefficients for each order - * *** IMPORTANT: - * *** lp_coeff[0,max_order-1][max_order,FLAC__MAX_LPC_ORDER-1] are untouched - * OUT error[0,max_order-1] error for each order (more - * specifically, the variance of - * the error signal times # of - * samples in the signal) - * - * Example: if max_order is 9, the LP coefficients for order 9 will be - * in lp_coeff[8][0,8], the LP coefficients for order 8 will be - * in lp_coeff[7][0,7], etc. - */ -void FLAC__lpc_compute_lp_coefficients(const double autoc[], uint32_t *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], double error[]); - -/* - * FLAC__lpc_quantize_coefficients() - * -------------------------------------------------------------------- - * Quantizes the LP coefficients. NOTE: precision + bits_per_sample - * must be less than 32 (sizeof(FLAC__int32)*8). - * - * IN lp_coeff[0,order-1] LP coefficients - * IN order LP order - * IN FLAC__MIN_QLP_COEFF_PRECISION < precision - * desired precision (in bits, including sign - * bit) of largest coefficient - * OUT qlp_coeff[0,order-1] quantized coefficients - * OUT shift # of bits to shift right to get approximated - * LP coefficients. NOTE: could be negative. - * RETURN 0 => quantization OK - * 1 => coefficients require too much shifting for *shift to - * fit in the LPC subframe header. 'shift' is unset. - * 2 => coefficients are all zero, which is bad. 'shift' is - * unset. - */ -int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], uint32_t order, uint32_t precision, FLAC__int32 qlp_coeff[], int *shift); - -/* - * FLAC__lpc_compute_residual_from_qlp_coefficients() - * -------------------------------------------------------------------- - * Compute the residual signal obtained from sutracting the predicted - * signal from the original. - * - * IN data[-order,data_len-1] original signal (NOTE THE INDICES!) - * IN data_len length of original signal - * IN qlp_coeff[0,order-1] quantized LP coefficients - * IN order > 0 LP order - * IN lp_quantization quantization of LP coefficients in bits - * OUT residual[0,data_len-1] residual signal - */ -void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -FLAC__bool FLAC__lpc_compute_residual_from_qlp_coefficients_limit_residual(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -FLAC__bool FLAC__lpc_compute_residual_from_qlp_coefficients_limit_residual_33bit(const FLAC__int64 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -#ifndef FLAC__NO_ASM -# ifdef FLAC__CPU_ARM64 -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_neon(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_neon(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -# endif - -# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -# ifdef FLAC__SSE2_SUPPORTED -void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_sse2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -# endif -# ifdef FLAC__SSE4_1_SUPPORTED -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_sse41(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -# endif -# ifdef FLAC__AVX2_SUPPORTED -void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -# endif -# endif -#endif - -#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */ - -uint32_t FLAC__lpc_max_prediction_before_shift_bps(uint32_t subframe_bps, const FLAC__int32 qlp_coeff[], uint32_t order); -uint32_t FLAC__lpc_max_residual_bps(uint32_t subframe_bps, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization); - -/* - * FLAC__lpc_restore_signal() - * -------------------------------------------------------------------- - * Restore the original signal by summing the residual and the - * predictor. - * - * IN residual[0,data_len-1] residual signal - * IN data_len length of original signal - * IN qlp_coeff[0,order-1] quantized LP coefficients - * IN order > 0 LP order - * IN lp_quantization quantization of LP coefficients in bits - * *** IMPORTANT: the caller must pass in the historical samples: - * IN data[-order,-1] previously-reconstructed historical samples - * OUT data[0,data_len-1] original signal - */ -void FLAC__lpc_restore_signal(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]); -void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 data[]); -void FLAC__lpc_restore_signal_wide_33bit(const FLAC__int32 residual[], uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int64 data[]); - -#ifndef FLAC__INTEGER_ONLY_LIBRARY - -/* - * FLAC__lpc_compute_expected_bits_per_residual_sample() - * -------------------------------------------------------------------- - * Compute the expected number of bits per residual signal sample - * based on the LP error (which is related to the residual variance). - * - * IN lpc_error >= 0.0 error returned from calculating LP coefficients - * IN total_samples > 0 # of samples in residual signal - * RETURN expected bits per sample - */ -double FLAC__lpc_compute_expected_bits_per_residual_sample(double lpc_error, uint32_t total_samples); -double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(double lpc_error, double error_scale); - -/* - * FLAC__lpc_compute_best_order() - * -------------------------------------------------------------------- - * Compute the best order from the array of signal errors returned - * during coefficient computation. - * - * IN lpc_error[0,max_order-1] >= 0.0 error returned from calculating LP coefficients - * IN max_order > 0 max LP order - * IN total_samples > 0 # of samples in residual signal - * IN overhead_bits_per_order # of bits overhead for each increased LP order - * (includes warmup sample size and quantized LP coefficient) - * RETURN [1,max_order] best order - */ -uint32_t FLAC__lpc_compute_best_order(const double lpc_error[], uint32_t max_order, uint32_t total_samples, uint32_t overhead_bits_per_order); - -#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */ - -#endif diff --git a/flac/src/libFLAC/include/private/macros.h b/flac/src/libFLAC/include/private/macros.h deleted file mode 100644 index 8204ed5..0000000 --- a/flac/src/libFLAC/include/private/macros.h +++ /dev/null @@ -1,74 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2012-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__MACROS_H -#define FLAC__PRIVATE__MACROS_H - -#if defined(__GNUC__) && (__GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 3)) - -#define flac_max(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a > _b ? _a : _b; }) - -#define MIN_PASTE(A,B) A##B -#define MIN_IMPL(A,B,L) ({ \ - __typeof__(A) MIN_PASTE(__a,L) = (A); \ - __typeof__(B) MIN_PASTE(__b,L) = (B); \ - MIN_PASTE(__a,L) < MIN_PASTE(__b,L) ? MIN_PASTE(__a,L) : MIN_PASTE(__b,L); \ - }) - -#define flac_min(A,B) MIN_IMPL(A,B,__COUNTER__) - -/* Whatever other unix that has sys/param.h */ -#elif defined(HAVE_SYS_PARAM_H) -#include -#if defined(MIN) && defined(MAX) -#define flac_max(a,b) MAX(a,b) -#define flac_min(a,b) MIN(a,b) -#endif - -/* Windows VS has them in stdlib.h.. XXX:Untested */ -#elif defined(_MSC_VER) -#include -#define flac_max(a,b) __max(a,b) -#define flac_min(a,b) __min(a,b) -#endif - -#ifndef flac_min -#define flac_min(x,y) ((x) <= (y) ? (x) : (y)) -#endif - -#ifndef flac_max -#define flac_max(x,y) ((x) >= (y) ? (x) : (y)) -#endif - -#endif diff --git a/flac/src/libFLAC/include/private/md5.h b/flac/src/libFLAC/include/private/md5.h deleted file mode 100644 index f9d79c3..0000000 --- a/flac/src/libFLAC/include/private/md5.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef FLAC__PRIVATE__MD5_H -#define FLAC__PRIVATE__MD5_H - -/* - * This is the header file for the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - * - * Changed so as no longer to depend on Colin Plumb's `usual.h' - * header definitions; now uses stuff from dpkg's config.h - * - Ian Jackson . - * Still in the public domain. - * - * Josh Coalson: made some changes to integrate with libFLAC. - * Still in the public domain, with no warranty. - */ - -#include "FLAC/ordinals.h" - -typedef union { - FLAC__byte *p8; - FLAC__int16 *p16; - FLAC__int32 *p32; -} FLAC__multibyte; - -typedef struct { - FLAC__uint32 in[16]; - FLAC__uint32 buf[4]; - FLAC__uint32 bytes[2]; - FLAC__multibyte internal_buf; - size_t capacity; -} FLAC__MD5Context; - -void FLAC__MD5Init(FLAC__MD5Context *context); -void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context); - -FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], uint32_t channels, uint32_t samples, uint32_t bytes_per_sample); - -#endif diff --git a/flac/src/libFLAC/include/private/memory.h b/flac/src/libFLAC/include/private/memory.h deleted file mode 100644 index 4221bcf..0000000 --- a/flac/src/libFLAC/include/private/memory.h +++ /dev/null @@ -1,58 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__MEMORY_H -#define FLAC__PRIVATE__MEMORY_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include /* for size_t */ - -#include "private/float.h" -#include "FLAC/ordinals.h" /* for FLAC__bool */ - -/* Returns the unaligned address returned by malloc. - * Use free() on this address to deallocate. - */ -void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address); -FLAC__bool FLAC__memory_alloc_aligned_int32_array(size_t elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer); -FLAC__bool FLAC__memory_alloc_aligned_uint32_array(size_t elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer); -FLAC__bool FLAC__memory_alloc_aligned_int64_array(size_t elements, FLAC__int64 **unaligned_pointer, FLAC__int64 **aligned_pointer); -FLAC__bool FLAC__memory_alloc_aligned_uint64_array(size_t elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer); -#ifndef FLAC__INTEGER_ONLY_LIBRARY -FLAC__bool FLAC__memory_alloc_aligned_real_array(size_t elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer); -#endif -void *safe_malloc_mul_2op_p(size_t size1, size_t size2); - -#endif diff --git a/flac/src/libFLAC/include/private/metadata.h b/flac/src/libFLAC/include/private/metadata.h deleted file mode 100644 index d3ceb53..0000000 --- a/flac/src/libFLAC/include/private/metadata.h +++ /dev/null @@ -1,46 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__METADATA_H -#define FLAC__PRIVATE__METADATA_H - -#include "FLAC/metadata.h" - -/* WATCHOUT: all malloc()ed data in the block is free()ed; this may not - * be a consistent state (e.g. PICTURE) or equivalent to the initial - * state after FLAC__metadata_object_new() - */ -void FLAC__metadata_object_delete_data(FLAC__StreamMetadata *object); - -void FLAC__metadata_object_cuesheet_track_delete_data(FLAC__StreamMetadata_CueSheet_Track *object); - -#endif diff --git a/flac/src/libFLAC/include/private/ogg_decoder_aspect.h b/flac/src/libFLAC/include/private/ogg_decoder_aspect.h deleted file mode 100644 index c923641..0000000 --- a/flac/src/libFLAC/include/private/ogg_decoder_aspect.h +++ /dev/null @@ -1,80 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__OGG_DECODER_ASPECT_H -#define FLAC__PRIVATE__OGG_DECODER_ASPECT_H - -#include - -#include "FLAC/ordinals.h" -#include "FLAC/stream_decoder.h" /* for FLAC__StreamDecoderReadStatus */ - -typedef struct FLAC__OggDecoderAspect { - /* these are storage for values that can be set through the API */ - FLAC__bool use_first_serial_number; - long serial_number; - - /* these are for internal state related to Ogg decoding */ - ogg_stream_state stream_state; - ogg_sync_state sync_state; - uint32_t version_major, version_minor; - FLAC__bool need_serial_number; - FLAC__bool end_of_stream; - FLAC__bool have_working_page; /* only if true will the following vars be valid */ - ogg_page working_page; - FLAC__bool have_working_packet; /* only if true will the following vars be valid */ - ogg_packet working_packet; /* as we work through the packet we will move working_packet.packet forward and working_packet.bytes down */ -} FLAC__OggDecoderAspect; - -void FLAC__ogg_decoder_aspect_set_serial_number(FLAC__OggDecoderAspect *aspect, long value); -void FLAC__ogg_decoder_aspect_set_defaults(FLAC__OggDecoderAspect *aspect); -FLAC__bool FLAC__ogg_decoder_aspect_init(FLAC__OggDecoderAspect *aspect); -void FLAC__ogg_decoder_aspect_finish(FLAC__OggDecoderAspect *aspect); -void FLAC__ogg_decoder_aspect_flush(FLAC__OggDecoderAspect *aspect); -void FLAC__ogg_decoder_aspect_reset(FLAC__OggDecoderAspect *aspect); - -typedef enum { - FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK = 0, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR, - FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR -} FLAC__OggDecoderAspectReadStatus; - -typedef FLAC__OggDecoderAspectReadStatus (*FLAC__OggDecoderAspectReadCallbackProxy)(const void *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); - -FLAC__OggDecoderAspectReadStatus FLAC__ogg_decoder_aspect_read_callback_wrapper(FLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], size_t *bytes, FLAC__OggDecoderAspectReadCallbackProxy read_callback, const FLAC__StreamDecoder *decoder, void *client_data); - -#endif diff --git a/flac/src/libFLAC/include/private/ogg_encoder_aspect.h b/flac/src/libFLAC/include/private/ogg_encoder_aspect.h deleted file mode 100644 index 0e9bb4b..0000000 --- a/flac/src/libFLAC/include/private/ogg_encoder_aspect.h +++ /dev/null @@ -1,63 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__OGG_ENCODER_ASPECT_H -#define FLAC__PRIVATE__OGG_ENCODER_ASPECT_H - -#include - -#include "FLAC/ordinals.h" -#include "FLAC/stream_encoder.h" /* for FLAC__StreamEncoderWriteStatus */ - -typedef struct FLAC__OggEncoderAspect { - /* these are storage for values that can be set through the API */ - long serial_number; - uint32_t num_metadata; - - /* these are for internal state related to Ogg encoding */ - ogg_stream_state stream_state; - ogg_page page; - FLAC__bool seen_magic; /* true if we've seen the fLaC magic in the write callback yet */ - FLAC__bool is_first_packet; - FLAC__uint64 samples_written; -} FLAC__OggEncoderAspect; - -void FLAC__ogg_encoder_aspect_set_serial_number(FLAC__OggEncoderAspect *aspect, long value); -FLAC__bool FLAC__ogg_encoder_aspect_set_num_metadata(FLAC__OggEncoderAspect *aspect, uint32_t value); -void FLAC__ogg_encoder_aspect_set_defaults(FLAC__OggEncoderAspect *aspect); -FLAC__bool FLAC__ogg_encoder_aspect_init(FLAC__OggEncoderAspect *aspect); -void FLAC__ogg_encoder_aspect_finish(FLAC__OggEncoderAspect *aspect); - -typedef FLAC__StreamEncoderWriteStatus (*FLAC__OggEncoderAspectWriteCallbackProxy)(const void *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data); - -FLAC__StreamEncoderWriteStatus FLAC__ogg_encoder_aspect_write_callback_wrapper(FLAC__OggEncoderAspect *aspect, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, FLAC__bool is_last_block, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data); -#endif diff --git a/flac/src/libFLAC/include/private/ogg_helper.h b/flac/src/libFLAC/include/private/ogg_helper.h deleted file mode 100644 index 6768578..0000000 --- a/flac/src/libFLAC/include/private/ogg_helper.h +++ /dev/null @@ -1,44 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__OGG_HELPER_H -#define FLAC__PRIVATE__OGG_HELPER_H - -#include -#include "FLAC/stream_encoder.h" /* for FLAC__StreamEncoder */ - -void simple_ogg_page__init(ogg_page *page); -void simple_ogg_page__clear(ogg_page *page); -FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderReadCallback read_callback, void *client_data); -FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data); - -#endif diff --git a/flac/src/libFLAC/include/private/ogg_mapping.h b/flac/src/libFLAC/include/private/ogg_mapping.h deleted file mode 100644 index 1a213a4..0000000 --- a/flac/src/libFLAC/include/private/ogg_mapping.h +++ /dev/null @@ -1,64 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__OGG_MAPPING_H -#define FLAC__PRIVATE__OGG_MAPPING_H - -#include "FLAC/ordinals.h" - -/** The length of the packet type field in bytes. */ -#define FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH (1u) - -extern const uint32_t FLAC__OGG_MAPPING_PACKET_TYPE_LEN; /* = 8 bits */ - -extern const FLAC__byte FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE; /* = 0x7f */ - -/** The length of the 'FLAC' magic in bytes. */ -#define FLAC__OGG_MAPPING_MAGIC_LENGTH (4u) - -extern const FLAC__byte * const FLAC__OGG_MAPPING_MAGIC; /* = "FLAC" */ - -extern const uint32_t FLAC__OGG_MAPPING_VERSION_MAJOR_LEN; /* = 8 bits */ -extern const uint32_t FLAC__OGG_MAPPING_VERSION_MINOR_LEN; /* = 8 bits */ - -/** The length of the Ogg FLAC mapping major version number in bytes. */ -#define FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH (1u) - -/** The length of the Ogg FLAC mapping minor version number in bytes. */ -#define FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH (1u) - -extern const uint32_t FLAC__OGG_MAPPING_NUM_HEADERS_LEN; /* = 16 bits */ - -/** The length of the #-of-header-packets number bytes. */ -#define FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH (2u) - -#endif diff --git a/flac/src/libFLAC/include/private/stream_encoder.h b/flac/src/libFLAC/include/private/stream_encoder.h deleted file mode 100644 index 0a1b672..0000000 --- a/flac/src/libFLAC/include/private/stream_encoder.h +++ /dev/null @@ -1,67 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__STREAM_ENCODER_H -#define FLAC__PRIVATE__STREAM_ENCODER_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -/* - * This is used to avoid overflow with unusual signals in 32-bit - * accumulator in the *precompute_partition_info_sums_* functions. - */ -#define FLAC__MAX_EXTRA_RESIDUAL_BPS 4 - -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN -#include "private/cpu.h" -#include "FLAC/format.h" - -#ifdef FLAC__SSE2_SUPPORTED -extern void FLAC__precompute_partition_info_sums_intrin_sse2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps); -#endif - -#ifdef FLAC__SSSE3_SUPPORTED -extern void FLAC__precompute_partition_info_sums_intrin_ssse3(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps); -#endif - -#ifdef FLAC__AVX2_SUPPORTED -extern void FLAC__precompute_partition_info_sums_intrin_avx2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps); -#endif - -#endif - -#endif diff --git a/flac/src/libFLAC/include/private/stream_encoder_framing.h b/flac/src/libFLAC/include/private/stream_encoder_framing.h deleted file mode 100644 index 705965a..0000000 --- a/flac/src/libFLAC/include/private/stream_encoder_framing.h +++ /dev/null @@ -1,46 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H -#define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H - -#include "FLAC/format.h" -#include "bitwriter.h" - -FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw, FLAC__bool update_vendor_string); -FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw); -FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw); -FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, uint32_t residual_samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw); -FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, uint32_t residual_samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw); -FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, uint32_t samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw); - -#endif diff --git a/flac/src/libFLAC/include/private/window.h b/flac/src/libFLAC/include/private/window.h deleted file mode 100644 index 87a3fdf..0000000 --- a/flac/src/libFLAC/include/private/window.h +++ /dev/null @@ -1,74 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2006-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PRIVATE__WINDOW_H -#define FLAC__PRIVATE__WINDOW_H - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "private/float.h" -#include "FLAC/format.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY - -/* - * FLAC__window_*() - * -------------------------------------------------------------------- - * Calculates window coefficients according to different apodization - * functions. - * - * OUT window[0,L-1] - * IN L (number of points in window) - */ -void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */ -void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L); -void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p); -void FLAC__window_partial_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p, const FLAC__real start, const FLAC__real end); -void FLAC__window_punchout_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p, const FLAC__real start, const FLAC__real end); -void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L); - -#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */ - -#endif diff --git a/flac/src/libFLAC/include/protected/Makefile.am b/flac/src/libFLAC/include/protected/Makefile.am deleted file mode 100644 index 97e85a8..0000000 --- a/flac/src/libFLAC/include/protected/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -# libFLAC - Free Lossless Audio Codec library -# Copyright (C) 2001-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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 Xiph.org Foundation 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 FOUNDATION 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. - -noinst_HEADERS = \ - all.h \ - stream_decoder.h \ - stream_encoder.h diff --git a/flac/src/libFLAC/include/protected/all.h b/flac/src/libFLAC/include/protected/all.h deleted file mode 100644 index 9f6de97..0000000 --- a/flac/src/libFLAC/include/protected/all.h +++ /dev/null @@ -1,39 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PROTECTED__ALL_H -#define FLAC__PROTECTED__ALL_H - -#include "stream_decoder.h" -#include "stream_encoder.h" - -#endif diff --git a/flac/src/libFLAC/include/protected/stream_decoder.h b/flac/src/libFLAC/include/protected/stream_decoder.h deleted file mode 100644 index 4a9c768..0000000 --- a/flac/src/libFLAC/include/protected/stream_decoder.h +++ /dev/null @@ -1,60 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PROTECTED__STREAM_DECODER_H -#define FLAC__PROTECTED__STREAM_DECODER_H - -#include "FLAC/stream_decoder.h" -#if FLAC__HAS_OGG -#include "private/ogg_decoder_aspect.h" -#endif - -typedef struct FLAC__StreamDecoderProtected { - FLAC__StreamDecoderState state; - FLAC__StreamDecoderInitStatus initstate; - uint32_t channels; - FLAC__ChannelAssignment channel_assignment; - uint32_t bits_per_sample; - uint32_t sample_rate; /* in Hz */ - uint32_t blocksize; /* in samples (per channel) */ - FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */ -#if FLAC__HAS_OGG - FLAC__OggDecoderAspect ogg_decoder_aspect; -#endif -} FLAC__StreamDecoderProtected; - -/* - * Return the number of input bytes consumed - */ -uint32_t FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder); - -#endif diff --git a/flac/src/libFLAC/include/protected/stream_encoder.h b/flac/src/libFLAC/include/protected/stream_encoder.h deleted file mode 100644 index 863e43b..0000000 --- a/flac/src/libFLAC/include/protected/stream_encoder.h +++ /dev/null @@ -1,124 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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 FLAC__PROTECTED__STREAM_ENCODER_H -#define FLAC__PROTECTED__STREAM_ENCODER_H - -#include "FLAC/stream_encoder.h" -#if FLAC__HAS_OGG -#include "private/ogg_encoder_aspect.h" -#endif - -#ifndef FLAC__INTEGER_ONLY_LIBRARY - -#include "private/float.h" - -#define FLAC__MAX_APODIZATION_FUNCTIONS 32 - -typedef enum { - FLAC__APODIZATION_BARTLETT, - FLAC__APODIZATION_BARTLETT_HANN, - FLAC__APODIZATION_BLACKMAN, - FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE, - FLAC__APODIZATION_CONNES, - FLAC__APODIZATION_FLATTOP, - FLAC__APODIZATION_GAUSS, - FLAC__APODIZATION_HAMMING, - FLAC__APODIZATION_HANN, - FLAC__APODIZATION_KAISER_BESSEL, - FLAC__APODIZATION_NUTTALL, - FLAC__APODIZATION_RECTANGLE, - FLAC__APODIZATION_TRIANGLE, - FLAC__APODIZATION_TUKEY, - FLAC__APODIZATION_PARTIAL_TUKEY, - FLAC__APODIZATION_PUNCHOUT_TUKEY, - FLAC__APODIZATION_SUBDIVIDE_TUKEY, - FLAC__APODIZATION_WELCH -} FLAC__ApodizationFunction; - -typedef struct { - FLAC__ApodizationFunction type; - union { - struct { - FLAC__real stddev; - } gauss; - struct { - FLAC__real p; - } tukey; - struct { - FLAC__real p; - FLAC__real start; - FLAC__real end; - } multiple_tukey; - struct { - FLAC__real p; - FLAC__int32 parts; - } subdivide_tukey; - } parameters; -} FLAC__ApodizationSpecification; - -#endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY - -typedef struct FLAC__StreamEncoderProtected { - FLAC__StreamEncoderState state; - FLAC__bool verify; - FLAC__bool streamable_subset; - FLAC__bool do_md5; - FLAC__bool do_mid_side_stereo; - FLAC__bool loose_mid_side_stereo; - uint32_t channels; - uint32_t bits_per_sample; - uint32_t sample_rate; - uint32_t blocksize; -#ifndef FLAC__INTEGER_ONLY_LIBRARY - uint32_t num_apodizations; - FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS]; -#endif - uint32_t max_lpc_order; - uint32_t qlp_coeff_precision; - FLAC__bool do_qlp_coeff_prec_search; - FLAC__bool do_exhaustive_model_search; - FLAC__bool do_escape_coding; - uint32_t min_residual_partition_order; - uint32_t max_residual_partition_order; - uint32_t rice_parameter_search_dist; - FLAC__uint64 total_samples_estimate; - FLAC__bool limit_min_bitrate; - FLAC__StreamMetadata **metadata; - uint32_t num_metadata_blocks; - FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset; -#if FLAC__HAS_OGG - FLAC__OggEncoderAspect ogg_encoder_aspect; -#endif -} FLAC__StreamEncoderProtected; - -#endif diff --git a/flac/src/libFLAC/libFLAC.m4 b/flac/src/libFLAC/libFLAC.m4 deleted file mode 100644 index 5dfc5ea..0000000 --- a/flac/src/libFLAC/libFLAC.m4 +++ /dev/null @@ -1,114 +0,0 @@ -# Configure paths for libFLAC -# "Inspired" by ogg.m4 - -dnl AM_PATH_LIBFLAC([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libFLAC, and define LIBFLAC_CFLAGS, LIBFLAC_LIBS, LIBFLAC_LIBDIR -dnl -AC_DEFUN([AM_PATH_LIBFLAC], -[dnl -dnl Get the cflags and libraries -dnl -AC_ARG_WITH(libFLAC,[ --with-libFLAC=PFX Prefix where libFLAC is installed (optional)], libFLAC_prefix="$withval", libFLAC_prefix="") -AC_ARG_WITH(libFLAC-libraries,[ --with-libFLAC-libraries=DIR Directory where libFLAC library is installed (optional)], libFLAC_libraries="$withval", libFLAC_libraries="") -AC_ARG_WITH(libFLAC-includes,[ --with-libFLAC-includes=DIR Directory where libFLAC header files are installed (optional)], libFLAC_includes="$withval", libFLAC_includes="") -AC_ARG_ENABLE(libFLACtest, [ --disable-libFLACtest Do not try to compile and run a test libFLAC program],, enable_libFLACtest=yes) - - if test "x$libFLAC_libraries" != "x" ; then - LIBFLAC_LIBS="-L$libFLAC_libraries" - elif test "x$libFLAC_prefix" = "xno" || test "x$libFLAC_prefix" = "xyes" ; then - LIBFLAC_LIBS="" - elif test "x$libFLAC_prefix" != "x" ; then - LIBFLAC_LIBS="-L$libFLAC_prefix/lib" - elif test "x$prefix" != "xNONE"; then - LIBFLAC_LIBS="-L$prefix/lib" - fi - - if test "x$libFLAC_prefix" != "xno" ; then - LIBFLAC_LIBS="$LIBFLAC_LIBS -lFLAC $OGG_LIBS -lm" - fi - - if test "x$libFLAC_includes" != "x" ; then - LIBFLAC_CFLAGS="-I$libFLAC_includes" - elif test "x$libFLAC_prefix" != "x" ; then - LIBFLAC_CFLAGS="-I$libFLAC_prefix/include" - elif test "$prefix" != "xNONE"; then - LIBFLAC_CFLAGS="" - fi - - AC_MSG_CHECKING(for libFLAC) - no_libFLAC="" - - - if test "x$enable_libFLACtest" = "xyes" ; then - ac_save_CFLAGS="$CFLAGS" - ac_save_CXXFLAGS="$CXXFLAGS" - ac_save_LIBS="$LIBS" - ac_save_LD_LIBRARY_PATH="$LD_LIBRARY_PATH" - CFLAGS="$CFLAGS $LIBFLAC_CFLAGS" - CXXFLAGS="$CXXFLAGS $LIBFLAC_CFLAGS" - LIBS="$LIBS $LIBFLAC_LIBS" - LD_LIBRARY_PATH="$LIBFLAC_LIBDIR:$LD_LIBRARY_PATH" -dnl -dnl Now check if the installed libFLAC is sufficiently new. -dnl - rm -f conf.libFLACtest - AC_RUN_IFELSE([AC_LANG_PROGRAM([[ -#include -#include -#include -#include -]],[[ - system("touch conf.libFLACtest"); - return 0; -]])],[],[no_libFLAC=yes],[echo $ac_n "cross compiling; assumed OK... $ac_c"]) - CFLAGS="$ac_save_CFLAGS" - CXXFLAGS="$ac_save_CXXFLAGS" - LIBS="$ac_save_LIBS" - LD_LIBRARY_PATH="$ac_save_LD_LIBRARY_PATH" - fi - - if test "x$no_libFLAC" = "x" ; then - AC_MSG_RESULT(yes) - ifelse([$1], , :, [$1]) - else - AC_MSG_RESULT(no) - if test -f conf.libFLACtest ; then - : - else - echo "*** Could not run libFLAC test program, checking why..." - CFLAGS="$CFLAGS $LIBFLAC_CFLAGS" - CXXFLAGS="$CXXFLAGS $LIBFLAC_CFLAGS" - LIBS="$LIBS $LIBFLAC_LIBS" - LD_LIBRARY_PATH="$LIBFLAC_LIBDIR:$LD_LIBRARY_PATH" - AC_TRY_LINK([ -#include -#include -], [ return 0; ], - [ echo "*** The test program compiled, but did not run. This usually means" - echo "*** that the run-time linker is not finding libFLAC or finding the wrong" - echo "*** version of libFLAC. If it is not finding libFLAC, 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 occurred. This usually means libFLAC was incorrectly installed" - echo "*** or that you have moved libFLAC since it was installed. In the latter case, you" - echo "*** may want to edit the libFLAC-config script: $LIBFLAC_CONFIG" ]) - CFLAGS="$ac_save_CFLAGS" - CXXFLAGS="$ac_save_CXXFLAGS" - LIBS="$ac_save_LIBS" - LD_LIBRARY_PATH="$ac_save_LD_LIBRARY_PATH" - fi - LIBFLAC_CFLAGS="" - LIBFLAC_LIBDIR="" - LIBFLAC_LIBS="" - ifelse([$2], , :, [$2]) - fi - AC_SUBST(LIBFLAC_CFLAGS) - AC_SUBST(LIBFLAC_LIBDIR) - AC_SUBST(LIBFLAC_LIBS) - rm -f conf.libFLACtest -]) diff --git a/flac/src/libFLAC/lpc.c b/flac/src/libFLAC/lpc.c deleted file mode 100644 index bcb8673..0000000 --- a/flac/src/libFLAC/lpc.c +++ /dev/null @@ -1,1629 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include "FLAC/assert.h" -#include "FLAC/format.h" -#include "share/compat.h" -#include "private/bitmath.h" -#include "private/lpc.h" -#include "private/macros.h" - -#if !defined(NDEBUG) || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE -#include -#endif - -/* OPT: #undef'ing this may improve the speed on some architectures */ -#define FLAC__LPC_UNROLLED_FILTER_LOOPS - -#ifndef FLAC__INTEGER_ONLY_LIBRARY - -#if defined(_MSC_VER) && (_MSC_VER < 1800) -#include -static inline long int lround(double x) { - return (long)(x + _copysign(0.5, x)); -} -#elif !defined(HAVE_LROUND) && defined(__GNUC__) -static inline long int lround(double x) { - return (long)(x + __builtin_copysign(0.5, x)); -} -/* If this fails, we are in the presence of a mid 90's compiler, move along... */ -#endif - -void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len) -{ - uint32_t i; - for(i = 0; i < data_len; i++) - out[i] = in[i] * window[i]; -} - -void FLAC__lpc_window_data_wide(const FLAC__int64 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len) -{ - uint32_t i; - for(i = 0; i < data_len; i++) - out[i] = in[i] * window[i]; -} - -void FLAC__lpc_window_data_partial(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len, uint32_t part_size, uint32_t data_shift) -{ - uint32_t i, j; - if((part_size + data_shift) < data_len){ - for(i = 0; i < part_size; i++) - out[i] = in[data_shift+i] * window[i]; - i = flac_min(i,data_len - part_size - data_shift); - for(j = data_len - part_size; j < data_len; i++, j++) - out[i] = in[data_shift+i] * window[j]; - if(i < data_len) - out[i] = 0.0f; - } -} - -void FLAC__lpc_window_data_partial_wide(const FLAC__int64 in[], const FLAC__real window[], FLAC__real out[], uint32_t data_len, uint32_t part_size, uint32_t data_shift) -{ - uint32_t i, j; - if((part_size + data_shift) < data_len){ - for(i = 0; i < part_size; i++) - out[i] = in[data_shift+i] * window[i]; - i = flac_min(i,data_len - part_size - data_shift); - for(j = data_len - part_size; j < data_len; i++, j++) - out[i] = in[data_shift+i] * window[j]; - if(i < data_len) - out[i] = 0.0f; - } -} - -void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]) -{ - /* a readable, but slower, version */ -#if 0 - double d; - uint32_t i; - - FLAC__ASSERT(lag > 0); - FLAC__ASSERT(lag <= data_len); - - /* - * Technically we should subtract the mean first like so: - * for(i = 0; i < data_len; i++) - * data[i] -= mean; - * but it appears not to make enough of a difference to matter, and - * most signals are already closely centered around zero - */ - while(lag--) { - for(i = lag, d = 0.0; i < data_len; i++) - d += data[i] * (double)data[i - lag]; - autoc[lag] = d; - } -#endif - if (data_len < FLAC__MAX_LPC_ORDER || lag > 16) { - /* - * this version tends to run faster because of better data locality - * ('data_len' is usually much larger than 'lag') - */ - double d; - uint32_t sample, coeff; - const uint32_t limit = data_len - lag; - - FLAC__ASSERT(lag > 0); - FLAC__ASSERT(lag <= data_len); - - for(coeff = 0; coeff < lag; coeff++) - autoc[coeff] = 0.0; - for(sample = 0; sample <= limit; sample++) { - d = data[sample]; - for(coeff = 0; coeff < lag; coeff++) - autoc[coeff] += d * data[sample+coeff]; - } - for(; sample < data_len; sample++) { - d = data[sample]; - for(coeff = 0; coeff < data_len - sample; coeff++) - autoc[coeff] += d * data[sample+coeff]; - } - } - else if(lag <= 8) { - #undef MAX_LAG - #define MAX_LAG 8 - #include "deduplication/lpc_compute_autocorrelation_intrin.c" - } - else if(lag <= 12) { - #undef MAX_LAG - #define MAX_LAG 12 - #include "deduplication/lpc_compute_autocorrelation_intrin.c" - } - else if(lag <= 16) { - #undef MAX_LAG - #define MAX_LAG 16 - #include "deduplication/lpc_compute_autocorrelation_intrin.c" - } - -} - -void FLAC__lpc_compute_lp_coefficients(const double autoc[], uint32_t *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], double error[]) -{ - uint32_t i, j; - double r, err, lpc[FLAC__MAX_LPC_ORDER]; - - FLAC__ASSERT(0 != max_order); - FLAC__ASSERT(0 < *max_order); - FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER); - FLAC__ASSERT(autoc[0] != 0.0); - - err = autoc[0]; - - for(i = 0; i < *max_order; i++) { - /* Sum up this iteration's reflection coefficient. */ - r = -autoc[i+1]; - for(j = 0; j < i; j++) - r -= lpc[j] * autoc[i-j]; - r /= err; - - /* Update LPC coefficients and total error. */ - lpc[i]=r; - for(j = 0; j < (i>>1); j++) { - double tmp = lpc[j]; - lpc[j] += r * lpc[i-1-j]; - lpc[i-1-j] += r * tmp; - } - if(i & 1) - lpc[j] += lpc[j] * r; - - err *= (1.0 - r * r); - - /* save this order */ - for(j = 0; j <= i; j++) - lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */ - error[i] = err; - - /* see SF bug https://sourceforge.net/p/flac/bugs/234/ */ - if(err == 0.0) { - *max_order = i+1; - return; - } - } -} - -int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], uint32_t order, uint32_t precision, FLAC__int32 qlp_coeff[], int *shift) -{ - uint32_t i; - double cmax; - FLAC__int32 qmax, qmin; - - FLAC__ASSERT(precision > 0); - FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION); - - /* drop one bit for the sign; from here on out we consider only |lp_coeff[i]| */ - precision--; - qmax = 1 << precision; - qmin = -qmax; - qmax--; - - /* calc cmax = max( |lp_coeff[i]| ) */ - cmax = 0.0; - for(i = 0; i < order; i++) { - const double d = fabs(lp_coeff[i]); - if(d > cmax) - cmax = d; - } - - if(cmax <= 0.0) { - /* => coefficients are all 0, which means our constant-detect didn't work */ - return 2; - } - else { - const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1; - const int min_shiftlimit = -max_shiftlimit - 1; - int log2cmax; - - (void)frexp(cmax, &log2cmax); - log2cmax--; - *shift = (int)precision - log2cmax - 1; - - if(*shift > max_shiftlimit) - *shift = max_shiftlimit; - else if(*shift < min_shiftlimit) - return 1; - } - - if(*shift >= 0) { - double error = 0.0; - FLAC__int32 q; - for(i = 0; i < order; i++) { - error += lp_coeff[i] * (1 << *shift); - q = lround(error); - -#ifdef FLAC__OVERFLOW_DETECT - if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */ - fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]); - else if(q < qmin) - fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q qmax) - q = qmax; - else if(q < qmin) - q = qmin; - error -= q; - qlp_coeff[i] = q; - } - } - /* negative shift is very rare but due to design flaw, negative shift is - * not allowed in the decoder, so it must be handled specially by scaling - * down coeffs - */ - else { - const int nshift = -(*shift); - double error = 0.0; - FLAC__int32 q; -#ifndef NDEBUG - fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax); -#endif - for(i = 0; i < order; i++) { - error += lp_coeff[i] / (1 << nshift); - q = lround(error); -#ifdef FLAC__OVERFLOW_DETECT - if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */ - fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]); - else if(q < qmin) - fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q qmax) - q = qmax; - else if(q < qmin) - q = qmin; - error -= q; - qlp_coeff[i] = q; - } - *shift = 0; - } - - return 0; -} - -#if defined(_MSC_VER) -// silence MSVC warnings about __restrict modifier -#pragma warning ( disable : 4028 ) -#endif - -void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 * flac_restrict data, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict residual) -#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS) -{ - FLAC__int64 sumo; - uint32_t i, j; - FLAC__int32 sum; - const FLAC__int32 *history; - -#ifdef FLAC__OVERFLOW_DETECT_VERBOSE - fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization); - for(i=0;i 0); - - for(i = 0; i < data_len; i++) { - sumo = 0; - sum = 0; - history = data; - for(j = 0; j < order; j++) { - sum += qlp_coeff[j] * (*(--history)); - sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history); - if(sumo > 2147483647ll || sumo < -2147483648ll) - fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%" PRId64 "\n",i,j,qlp_coeff[j],*history,sumo); - } - *(residual++) = *(data++) - (sum >> lp_quantization); - } - - /* Here's a slower but clearer version: - for(i = 0; i < data_len; i++) { - sum = 0; - for(j = 0; j < order; j++) - sum += qlp_coeff[j] * data[i-j-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - */ -} -#else /* fully unrolled version for normal use */ -{ - int i; - FLAC__int32 sum; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - /* - * We do unique versions up to 12th order since that's the subset limit. - * Also they are roughly ordered to match frequency of occurrence to - * minimize branching. - */ - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[9] * data[i-10]; - sum += qlp_coeff[8] * data[i-9]; - sum += qlp_coeff[7] * data[i-8]; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 11 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[9] * data[i-10]; - sum += qlp_coeff[8] * data[i-9]; - sum += qlp_coeff[7] * data[i-8]; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - } - else { - if(order == 10) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[9] * data[i-10]; - sum += qlp_coeff[8] * data[i-9]; - sum += qlp_coeff[7] * data[i-8]; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 9 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[8] * data[i-9]; - sum += qlp_coeff[7] * data[i-8]; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[7] * data[i-8]; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 7 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - } - else { - if(order == 6) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 5 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 3 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - } - else { - if(order == 2) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 1 */ - for(i = 0; i < (int)data_len; i++) - residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization); - } - } - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } -} -#endif - -void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 * flac_restrict data, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict residual) -#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS) -{ - uint32_t i, j; - FLAC__int64 sum; - const FLAC__int32 *history; - -#ifdef FLAC__OVERFLOW_DETECT_VERBOSE - fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization); - for(i=0;i 0); - - for(i = 0; i < data_len; i++) { - sum = 0; - history = data; - for(j = 0; j < order; j++) - sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history)); - if(FLAC__bitmath_silog2((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) { - fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%" PRId64 ", residual=%" PRId64 "\n", i, *data, (int64_t)(sum >> lp_quantization), ((FLAC__int64)(*data) - (sum >> lp_quantization))); - break; - } - *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization); - } -} -#else /* fully unrolled version for normal use */ -{ - int i; - FLAC__int64 sum; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - /* - * We do unique versions up to 12th order since that's the subset limit. - * Also they are roughly ordered to match frequency of occurrence to - * minimize branching. - */ - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; - sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 11 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - } - else { - if(order == 10) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 9 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 7 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - } - else { - if(order == 6) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 5 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 3 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - } - else { - if(order == 2) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order == 1 */ - for(i = 0; i < (int)data_len; i++) - residual[i] = data[i] - ((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization); - } - } - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13]; - sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; - sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9]; - sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8]; - sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7]; - sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6]; - sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5]; - sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4]; - sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3]; - sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2]; - sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } -} -#endif - -FLAC__bool FLAC__lpc_compute_residual_from_qlp_coefficients_limit_residual(const FLAC__int32 * flac_restrict data, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict residual) -{ - int i; - FLAC__int64 sum, residual_to_check; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13]; /* Falls through. */ - case 12: sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1]; - } - residual_to_check = data[i] - (sum >> lp_quantization); - /* residual must not be INT32_MIN because abs(INT32_MIN) is undefined */ - if(residual_to_check <= INT32_MIN || residual_to_check > INT32_MAX) - return false; - else - residual[i] = residual_to_check; - } - return true; -} - -FLAC__bool FLAC__lpc_compute_residual_from_qlp_coefficients_limit_residual_33bit(const FLAC__int64 * flac_restrict data, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict residual) -{ - int i; - FLAC__int64 sum, residual_to_check; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; /* Falls through. */ - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - residual_to_check = data[i] - (sum >> lp_quantization); - /* residual must not be INT32_MIN because abs(INT32_MIN) is undefined */ - if(residual_to_check <= INT32_MIN || residual_to_check > INT32_MAX) - return false; - else - residual[i] = residual_to_check; - } - return true; -} - -#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */ - -uint32_t FLAC__lpc_max_prediction_before_shift_bps(uint32_t subframe_bps, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order) -{ - /* This used to be subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) - * but that treats both the samples as well as the predictor as unknown. The - * predictor is known however, so taking the log2 of the sum of the absolute values - * of all coefficients is a more accurate representation of the predictor */ - FLAC__int32 abs_sum_of_qlp_coeff = 0; - uint32_t i; - for(i = 0; i < order; i++) - abs_sum_of_qlp_coeff += abs(qlp_coeff[i]); - if(abs_sum_of_qlp_coeff == 0) - abs_sum_of_qlp_coeff = 1; - return subframe_bps + FLAC__bitmath_silog2(abs_sum_of_qlp_coeff); -} - - -uint32_t FLAC__lpc_max_residual_bps(uint32_t subframe_bps, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization) -{ - FLAC__int32 predictor_sum_bps = FLAC__lpc_max_prediction_before_shift_bps(subframe_bps, qlp_coeff, order) - lp_quantization; - if((int)subframe_bps > predictor_sum_bps) - return subframe_bps + 1; - else - return predictor_sum_bps + 1; -} - -#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && !defined(FUZZING_BUILD_MODE_FLAC_SANITIZE_SIGNED_INTEGER_OVERFLOW) -/* The attribute below is to silence the undefined sanitizer of oss-fuzz. - * Because fuzzing feeds bogus predictors and residual samples to the - * decoder, having overflows in this section is unavoidable. Also, - * because the calculated values are audio path only, there is no - * potential for security problems */ -__attribute__((no_sanitize("signed-integer-overflow"))) -#endif -void FLAC__lpc_restore_signal(const FLAC__int32 * flac_restrict residual, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict data) -#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS) -{ - FLAC__int64 sumo; - uint32_t i, j; - FLAC__int32 sum; - const FLAC__int32 *r = residual, *history; - -#ifdef FLAC__OVERFLOW_DETECT_VERBOSE - fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization); - for(i=0;i 0); - - for(i = 0; i < data_len; i++) { - sumo = 0; - sum = 0; - history = data; - for(j = 0; j < order; j++) { - sum += qlp_coeff[j] * (*(--history)); - sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history); -#ifdef FLAC__OVERFLOW_DETECT - if(sumo > 2147483647ll || sumo < -2147483648ll) - fprintf(stderr,"FLAC__lpc_restore_signal: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%" PRId64 "\n",i,j,qlp_coeff[j],*history,sumo); -#endif - } - *(data++) = *(r++) + (sum >> lp_quantization); - } - - /* Here's a slower but clearer version: - for(i = 0; i < data_len; i++) { - sum = 0; - for(j = 0; j < order; j++) - sum += qlp_coeff[j] * data[i-j-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - */ -} -#else /* fully unrolled version for normal use */ -{ - int i; - FLAC__int32 sum; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - /* - * We do unique versions up to 12th order since that's the subset limit. - * Also they are roughly ordered to match frequency of occurrence to - * minimize branching. - */ - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[9] * data[i-10]; - sum += qlp_coeff[8] * data[i-9]; - sum += qlp_coeff[7] * data[i-8]; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - else { /* order == 11 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[9] * data[i-10]; - sum += qlp_coeff[8] * data[i-9]; - sum += qlp_coeff[7] * data[i-8]; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - } - else { - if(order == 10) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[9] * data[i-10]; - sum += qlp_coeff[8] * data[i-9]; - sum += qlp_coeff[7] * data[i-8]; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - else { /* order == 9 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[8] * data[i-9]; - sum += qlp_coeff[7] * data[i-8]; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[7] * data[i-8]; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - else { /* order == 7 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[6] * data[i-7]; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - } - else { - if(order == 6) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[5] * data[i-6]; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - else { /* order == 5 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[4] * data[i-5]; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[3] * data[i-4]; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - else { /* order == 3 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[2] * data[i-3]; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - } - else { - if(order == 2) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[1] * data[i-2]; - sum += qlp_coeff[0] * data[i-1]; - data[i] = residual[i] + (sum >> lp_quantization); - } - } - else { /* order == 1 */ - for(i = 0; i < (int)data_len; i++) - data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization); - } - } - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - data[i] = residual[i] + (sum >> lp_quantization); - } - } -} -#endif - -void FLAC__lpc_restore_signal_wide(const FLAC__int32 * flac_restrict residual, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int32 * flac_restrict data) -#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS) -{ - uint32_t i, j; - FLAC__int64 sum; - const FLAC__int32 *r = residual, *history; - -#ifdef FLAC__OVERFLOW_DETECT_VERBOSE - fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization); - for(i=0;i 0); - - for(i = 0; i < data_len; i++) { - sum = 0; - history = data; - for(j = 0; j < order; j++) - sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history)); -#ifdef FLAC__OVERFLOW_DETECT - if(FLAC__bitmath_silog2((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) { - fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%" PRId64 ", data=%" PRId64 "\n", i, *r, (sum >> lp_quantization), ((FLAC__int64)(*r) + (sum >> lp_quantization))); - break; - } -#endif - *(data++) = (FLAC__int32)(*(r++) + (sum >> lp_quantization)); - } -} -#else /* fully unrolled version for normal use */ -{ - int i; - FLAC__int64 sum; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - /* - * We do unique versions up to 12th order since that's the subset limit. - * Also they are roughly ordered to match frequency of occurrence to - * minimize branching. - */ - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; - sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - else { /* order == 11 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - } - else { - if(order == 10) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - else { /* order == 9 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - else { /* order == 7 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - } - else { - if(order == 6) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - else { /* order == 5 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - else { /* order == 3 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - } - else { - if(order == 2) { - for(i = 0; i < (int)data_len; i++) { - sum = 0; - sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } - else { /* order == 1 */ - for(i = 0; i < (int)data_len; i++) - data[i] = (FLAC__int32)(residual[i] + ((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization)); - } - } - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13]; - sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; - sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9]; - sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8]; - sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7]; - sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6]; - sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5]; - sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4]; - sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3]; - sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2]; - sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1]; - } - data[i] = (FLAC__int32) (residual[i] + (sum >> lp_quantization)); - } - } -} -#endif - -#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && !defined(FUZZING_BUILD_MODE_FLAC_SANITIZE_SIGNED_INTEGER_OVERFLOW) -/* The attribute below is to silence the undefined sanitizer of oss-fuzz. - * Because fuzzing feeds bogus predictors and residual samples to the - * decoder, having overflows in this section is unavoidable. Also, - * because the calculated values are audio path only, there is no - * potential for security problems */ -__attribute__((no_sanitize("signed-integer-overflow"))) -#endif -void FLAC__lpc_restore_signal_wide_33bit(const FLAC__int32 * flac_restrict residual, uint32_t data_len, const FLAC__int32 * flac_restrict qlp_coeff, uint32_t order, int lp_quantization, FLAC__int64 * flac_restrict data) -#if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS) -{ - uint32_t i, j; - FLAC__int64 sum; - const FLAC__int32 *r = residual; - const FLAC__int64 *history; - - FLAC__ASSERT(order > 0); - - for(i = 0; i < data_len; i++) { - sum = 0; - history = data; - for(j = 0; j < order; j++) - sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history)); -#ifdef FLAC__OVERFLOW_DETECT - if(FLAC__bitmath_silog2((FLAC__int64)(*r) + (sum >> lp_quantization)) > 33) { - fprintf(stderr,"FLAC__lpc_restore_signal_33bit: OVERFLOW, i=%u, residual=%d, sum=%" PRId64 ", data=%" PRId64 "\n", i, *r, (sum >> lp_quantization), ((FLAC__int64)(*r) + (sum >> lp_quantization))); - break; - } -#endif - *(data++) = (FLAC__int64)(*(r++)) + (sum >> lp_quantization); - } -} -#else /* unrolled version for normal use */ -{ - int i; - FLAC__int64 sum; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; /* Falls through. */ - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - data[i] = residual[i] + (sum >> lp_quantization); - } -} -#endif - -#if defined(_MSC_VER) -#pragma warning ( default : 4028 ) -#endif - -#ifndef FLAC__INTEGER_ONLY_LIBRARY - -double FLAC__lpc_compute_expected_bits_per_residual_sample(double lpc_error, uint32_t total_samples) -{ - double error_scale; - - FLAC__ASSERT(total_samples > 0); - - error_scale = 0.5 / (double)total_samples; - - return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale); -} - -double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(double lpc_error, double error_scale) -{ - if(lpc_error > 0.0) { - double bps = (double)0.5 * log(error_scale * lpc_error) / M_LN2; - if(bps >= 0.0) - return bps; - else - return 0.0; - } - else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */ - return 1e32; - } - else { - return 0.0; - } -} - -uint32_t FLAC__lpc_compute_best_order(const double lpc_error[], uint32_t max_order, uint32_t total_samples, uint32_t overhead_bits_per_order) -{ - uint32_t order, indx, best_index; /* 'index' the index into lpc_error; index==order-1 since lpc_error[0] is for order==1, lpc_error[1] is for order==2, etc */ - double bits, best_bits, error_scale; - - FLAC__ASSERT(max_order > 0); - FLAC__ASSERT(total_samples > 0); - - error_scale = 0.5 / (double)total_samples; - - best_index = 0; - best_bits = (uint32_t)(-1); - - for(indx = 0, order = 1; indx < max_order; indx++, order++) { - bits = FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error[indx], error_scale) * (double)(total_samples - order) + (double)(order * overhead_bits_per_order); - if(bits < best_bits) { - best_index = indx; - best_bits = bits; - } - } - - return best_index+1; /* +1 since indx of lpc_error[] is order-1 */ -} - -#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/lpc_intrin_avx2.c b/flac/src/libFLAC/lpc_intrin_avx2.c deleted file mode 100644 index 7f1c03e..0000000 --- a/flac/src/libFLAC/lpc_intrin_avx2.c +++ /dev/null @@ -1,1122 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "private/lpc.h" -#ifdef FLAC__AVX2_SUPPORTED - -#include "FLAC/assert.h" -#include "FLAC/format.h" - -#include /* AVX2 */ - -FLAC__SSE_TARGET("avx2") -void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int32 sum; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(0xffff & qlp_coeff[9 ]); - q10 = _mm256_set1_epi32(0xffff & qlp_coeff[10]); - q11 = _mm256_set1_epi32(0xffff & qlp_coeff[11]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q11, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-12))); - mull = _mm256_madd_epi16(q10, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-11))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q9, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-10))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-9 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 11 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(0xffff & qlp_coeff[9 ]); - q10 = _mm256_set1_epi32(0xffff & qlp_coeff[10]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q10, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-11))); - mull = _mm256_madd_epi16(q9, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-10))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-9 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 10) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(0xffff & qlp_coeff[9 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q9, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-10))); - mull = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-9 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 9 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(0xffff & qlp_coeff[8 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q8, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-9 ))); - mull = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-8 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(0xffff & qlp_coeff[7 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q7, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-8 ))); - mull = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 7 */ - __m256i q0, q1, q2, q3, q4, q5, q6; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(0xffff & qlp_coeff[6 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7 ))); - mull = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 6) { - __m256i q0, q1, q2, q3, q4, q5; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(0xffff & qlp_coeff[5 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6 ))); - mull = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 5 */ - __m256i q0, q1, q2, q3, q4; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(0xffff & qlp_coeff[4 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5 ))); - mull = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - __m256i q0, q1, q2, q3; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(0xffff & qlp_coeff[3 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4 ))); - mull = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 3 */ - __m256i q0, q1, q2; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(0xffff & qlp_coeff[2 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3 ))); - mull = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 2) { - __m256i q0, q1; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(0xffff & qlp_coeff[1 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_madd_epi16(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2 ))); - mull = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 1 */ - __m256i q0; - q0 = _mm256_set1_epi32(0xffff & qlp_coeff[0 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ; - summ = _mm256_madd_epi16(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1 ))); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - _mm256_zeroupper(); -} - -FLAC__SSE_TARGET("avx2") -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int32 sum; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(qlp_coeff[9 ]); - q10 = _mm256_set1_epi32(qlp_coeff[10]); - q11 = _mm256_set1_epi32(qlp_coeff[11]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q11, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-12))); - mull = _mm256_mullo_epi32(q10, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-11))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q9, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-10))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-9))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-8))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 11 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(qlp_coeff[9 ]); - q10 = _mm256_set1_epi32(qlp_coeff[10]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q10, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-11))); - mull = _mm256_mullo_epi32(q9, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-10))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-9))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-8))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 10) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(qlp_coeff[8 ]); - q9 = _mm256_set1_epi32(qlp_coeff[9 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q9, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-10))); - mull = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-9))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-8))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 9 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(qlp_coeff[7 ]); - q8 = _mm256_set1_epi32(qlp_coeff[8 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q8, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-9))); - mull = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-8))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - q7 = _mm256_set1_epi32(qlp_coeff[7 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q7, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-8))); - mull = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 7 */ - __m256i q0, q1, q2, q3, q4, q5, q6; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - q6 = _mm256_set1_epi32(qlp_coeff[6 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q6, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-7))); - mull = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 6) { - __m256i q0, q1, q2, q3, q4, q5; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - q5 = _mm256_set1_epi32(qlp_coeff[5 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q5, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-6))); - mull = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 5 */ - __m256i q0, q1, q2, q3, q4; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - q4 = _mm256_set1_epi32(qlp_coeff[4 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q4, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-5))); - mull = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - __m256i q0, q1, q2, q3; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - q3 = _mm256_set1_epi32(qlp_coeff[3 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q3, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-4))); - mull = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 3 */ - __m256i q0, q1, q2; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - q2 = _mm256_set1_epi32(qlp_coeff[2 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q2, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-3))); - mull = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); summ = _mm256_add_epi32(summ, mull); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 2) { - __m256i q0, q1; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - q1 = _mm256_set1_epi32(qlp_coeff[1 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ, mull; - summ = _mm256_mullo_epi32(q1, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-2))); - mull = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); summ = _mm256_add_epi32(summ, mull); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 1 */ - __m256i q0; - q0 = _mm256_set1_epi32(qlp_coeff[0 ]); - - for(i = 0; i < (int)data_len-7; i+=8) { - __m256i summ; - summ = _mm256_mullo_epi32(q0, _mm256_loadu_si256((const __m256i*)(const void*)(data+i-1))); - summ = _mm256_sra_epi32(summ, cnt); - _mm256_storeu_si256((__m256i*)(void*)(residual+i), _mm256_sub_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(data+i)), summ)); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - _mm256_zeroupper(); -} - -static FLAC__int32 pack_arr[8] = { 0, 2, 4, 6, 1, 3, 5, 7 }; - -FLAC__SSE_TARGET("avx2") -void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int64 sum; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - const __m256i pack = _mm256_loadu_si256((const __m256i *)(const void*)pack_arr); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - FLAC__ASSERT(lp_quantization <= 32); /* there's no _mm256_sra_epi64() so we have to use _mm256_srl_epi64() */ - - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ])); - q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ])); - q9 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[9 ])); - q10 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[10])); - q11 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[11])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q11, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-12)))); - mull = _mm256_mul_epi32(q10, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-11)))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q9, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-10)))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-9 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 11 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ])); - q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ])); - q9 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[9 ])); - q10 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[10])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q10, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-11)))); - mull = _mm256_mul_epi32(q9, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-10)))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-9 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - else { - if(order == 10) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ])); - q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ])); - q9 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[9 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q9, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-10)))); - mull = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-9 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 9 */ - __m256i q0, q1, q2, q3, q4, q5, q6, q7, q8; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ])); - q8 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[8 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q8, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-9 )))); - mull = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-8 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - __m256i q0, q1, q2, q3, q4, q5, q6, q7; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - q7 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[7 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q7, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-8 )))); - mull = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-7 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 7 */ - __m256i q0, q1, q2, q3, q4, q5, q6; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - q6 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[6 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q6, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-7 )))); - mull = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-6 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - else { - if(order == 6) { - __m256i q0, q1, q2, q3, q4, q5; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - q5 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[5 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q5, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-6 )))); - mull = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-5 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 5 */ - __m256i q0, q1, q2, q3, q4; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - q4 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[4 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q4, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-5 )))); - mull = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-4 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - __m256i q0, q1, q2, q3; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - q3 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[3 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q3, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-4 )))); - mull = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-3 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 3 */ - __m256i q0, q1, q2; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - q2 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[2 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q2, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-3 )))); - mull = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); summ = _mm256_add_epi64(summ, mull); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - else { - if(order == 2) { - __m256i q0, q1; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - q1 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[1 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ, mull; - summ = _mm256_mul_epi32(q1, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-2 )))); - mull = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); summ = _mm256_add_epi64(summ, mull); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - else { /* order == 1 */ - __m256i q0; - q0 = _mm256_cvtepu32_epi64(_mm_set1_epi32(qlp_coeff[0 ])); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m256i summ; - summ = _mm256_mul_epi32(q0, _mm256_cvtepu32_epi64(_mm_loadu_si128((const __m128i*)(const void*)(data+i-1 )))); - summ = _mm256_permutevar8x32_epi32(_mm256_srl_epi64(summ, cnt), pack); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), _mm256_castsi256_si128(summ))); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1]; - } - residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13]; - sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; - sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9]; - sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8]; - sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7]; - sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6]; - sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5]; - sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4]; - sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3]; - sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2]; - sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1]; - } - residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization); - } - } - _mm256_zeroupper(); -} - -#endif /* FLAC__AVX2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/lpc_intrin_fma.c b/flac/src/libFLAC/lpc_intrin_fma.c deleted file mode 100644 index c0740a8..0000000 --- a/flac/src/libFLAC/lpc_intrin_fma.c +++ /dev/null @@ -1,73 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2022-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if defined FLAC__CPU_X86_64 && FLAC__HAS_X86INTRIN -#include "private/lpc.h" -#ifdef FLAC__FMA_SUPPORTED - -#include "FLAC/assert.h" - -FLAC__SSE_TARGET("fma") -void FLAC__lpc_compute_autocorrelation_intrin_fma_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]) -{ -#undef MAX_LAG -#define MAX_LAG 8 -#include "deduplication/lpc_compute_autocorrelation_intrin.c" -} - -FLAC__SSE_TARGET("fma") -void FLAC__lpc_compute_autocorrelation_intrin_fma_lag_12(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]) -{ -#undef MAX_LAG -#define MAX_LAG 12 -#include "deduplication/lpc_compute_autocorrelation_intrin.c" -} -FLAC__SSE_TARGET("fma") -void FLAC__lpc_compute_autocorrelation_intrin_fma_lag_16(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]) -{ -#undef MAX_LAG -#define MAX_LAG 16 -#include "deduplication/lpc_compute_autocorrelation_intrin.c" - -} - -#endif /* FLAC__FMA_SUPPORTED */ -#endif /* FLAC__CPU_X86_64 && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/lpc_intrin_neon.c b/flac/src/libFLAC/lpc_intrin_neon.c deleted file mode 100644 index b9945d5..0000000 --- a/flac/src/libFLAC/lpc_intrin_neon.c +++ /dev/null @@ -1,1273 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#include "private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if defined FLAC__CPU_ARM64 && FLAC__HAS_NEONINTRIN -#include "private/lpc.h" -#include "FLAC/assert.h" -#include "FLAC/format.h" -#include "private/macros.h" -#include - -#if FLAC__HAS_A64NEONINTRIN -void FLAC__lpc_compute_autocorrelation_intrin_neon_lag_14(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]) -{ -#undef MAX_LAG -#define MAX_LAG 14 -#include "deduplication/lpc_compute_autocorrelation_intrin_neon.c" -} - -void FLAC__lpc_compute_autocorrelation_intrin_neon_lag_10(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]) -{ -#undef MAX_LAG -#define MAX_LAG 10 -#include "deduplication/lpc_compute_autocorrelation_intrin_neon.c" -} - -void FLAC__lpc_compute_autocorrelation_intrin_neon_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]) -{ -#undef MAX_LAG -#define MAX_LAG 8 -#include "deduplication/lpc_compute_autocorrelation_intrin_neon.c" -} - -#endif /* ifdef FLAC__HAS_A64NEONINTRIN */ - - -#define MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_vec, lane) \ - summ_0 = vmulq_laneq_s32(tmp_vec[0], qlp_coeff_vec, lane); \ - summ_1 = vmulq_laneq_s32(tmp_vec[4], qlp_coeff_vec, lane); \ - summ_2 = vmulq_laneq_s32(tmp_vec[8], qlp_coeff_vec, lane); - - -#define MACC_32BIT_LOOP_UNROOL_3(tmp_vec_ind, qlp_coeff_vec, lane) \ - summ_0 = vmlaq_laneq_s32(summ_0,tmp_vec[tmp_vec_ind] ,qlp_coeff_vec, lane); \ - summ_1 = vmlaq_laneq_s32(summ_1,tmp_vec[tmp_vec_ind+4] ,qlp_coeff_vec, lane); \ - summ_2 = vmlaq_laneq_s32(summ_2,tmp_vec[tmp_vec_ind+8] ,qlp_coeff_vec, lane); - -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_neon(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int32 sum; - int32x4_t tmp_vec[20]; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - // Using prologue reads is valid as encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order,....) - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if (order == 12) { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], qlp_coeff[6], qlp_coeff[7]}; - int32x4_t qlp_coeff_2 = {qlp_coeff[8], qlp_coeff[9], qlp_coeff[10], qlp_coeff[11]}; - - tmp_vec[0] = vld1q_s32(data - 12); - tmp_vec[1] = vld1q_s32(data - 11); - tmp_vec[2] = vld1q_s32(data - 10); - tmp_vec[3] = vld1q_s32(data - 9); - tmp_vec[4] = vld1q_s32(data - 8); - tmp_vec[5] = vld1q_s32(data - 7); - tmp_vec[6] = vld1q_s32(data - 6); - tmp_vec[7] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - - tmp_vec[8] = vld1q_s32(data + i - 4); - tmp_vec[9] = vld1q_s32(data+i-3); - tmp_vec[10] = vld1q_s32(data+i-2); - tmp_vec[11] = vld1q_s32(data+i-1); - tmp_vec[12] = vld1q_s32(data+i); - tmp_vec[13] = vld1q_s32(data+i+1); - tmp_vec[14] = vld1q_s32(data+i+2); - tmp_vec[15] = vld1q_s32(data+i+3); - tmp_vec[16] = vld1q_s32(data + i + 4); - tmp_vec[17] = vld1q_s32(data + i + 5); - tmp_vec[18] = vld1q_s32(data + i + 6); - tmp_vec[19] = vld1q_s32(data + i + 7); - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_2, 3) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_2, 2) - MACC_32BIT_LOOP_UNROOL_3(2, qlp_coeff_2, 1) - MACC_32BIT_LOOP_UNROOL_3(3, qlp_coeff_2, 0) - MACC_32BIT_LOOP_UNROOL_3(4, qlp_coeff_1, 3) - MACC_32BIT_LOOP_UNROOL_3(5, qlp_coeff_1, 2) - MACC_32BIT_LOOP_UNROOL_3(6, qlp_coeff_1, 1) - MACC_32BIT_LOOP_UNROOL_3(7, qlp_coeff_1, 0) - MACC_32BIT_LOOP_UNROOL_3(8, qlp_coeff_0, 3) - MACC_32BIT_LOOP_UNROOL_3(9, qlp_coeff_0, 2) - MACC_32BIT_LOOP_UNROOL_3(10, qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(11, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - tmp_vec[3] = tmp_vec[15]; - tmp_vec[4] = tmp_vec[16]; - tmp_vec[5] = tmp_vec[17]; - tmp_vec[6] = tmp_vec[18]; - tmp_vec[7] = tmp_vec[19]; - } - } - - else { /* order == 11 */ - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], qlp_coeff[6], qlp_coeff[7]}; - int32x4_t qlp_coeff_2 = {qlp_coeff[8], qlp_coeff[9], qlp_coeff[10], 0}; - - tmp_vec[0] = vld1q_s32(data - 11); - tmp_vec[1] = vld1q_s32(data - 10); - tmp_vec[2] = vld1q_s32(data - 9); - tmp_vec[3] = vld1q_s32(data - 8); - tmp_vec[4] = vld1q_s32(data - 7); - tmp_vec[5] = vld1q_s32(data - 6); - tmp_vec[6] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - tmp_vec[7] = vld1q_s32(data + i - 4); - tmp_vec[8] = vld1q_s32(data + i - 3); - tmp_vec[9] = vld1q_s32(data + i - 2); - tmp_vec[10] = vld1q_s32(data + i - 1); - tmp_vec[11] = vld1q_s32(data + i - 0); - tmp_vec[12] = vld1q_s32(data + i + 1); - tmp_vec[13] = vld1q_s32(data + i + 2); - tmp_vec[14] = vld1q_s32(data + i + 3); - tmp_vec[15] = vld1q_s32(data + i + 4); - tmp_vec[16] = vld1q_s32(data + i + 5); - tmp_vec[17] = vld1q_s32(data + i + 6); - tmp_vec[18] = vld1q_s32(data + i + 7); - - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_2, 2) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_2, 1) - MACC_32BIT_LOOP_UNROOL_3(2, qlp_coeff_2, 0) - MACC_32BIT_LOOP_UNROOL_3(3, qlp_coeff_1, 3) - MACC_32BIT_LOOP_UNROOL_3(4, qlp_coeff_1, 2) - MACC_32BIT_LOOP_UNROOL_3(5, qlp_coeff_1, 1) - MACC_32BIT_LOOP_UNROOL_3(6, qlp_coeff_1, 0) - MACC_32BIT_LOOP_UNROOL_3(7, qlp_coeff_0, 3) - MACC_32BIT_LOOP_UNROOL_3(8, qlp_coeff_0, 2) - MACC_32BIT_LOOP_UNROOL_3(9, qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(10, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - tmp_vec[3] = tmp_vec[15]; - tmp_vec[4] = tmp_vec[16]; - tmp_vec[5] = tmp_vec[17]; - tmp_vec[6] = tmp_vec[18]; - } - } - } - else { - if(order == 10) { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], qlp_coeff[6], qlp_coeff[7]}; - int32x4_t qlp_coeff_2 = {qlp_coeff[8], qlp_coeff[9], 0, 0}; - - tmp_vec[0] = vld1q_s32(data - 10); - tmp_vec[1] = vld1q_s32(data - 9); - tmp_vec[2] = vld1q_s32(data - 8); - tmp_vec[3] = vld1q_s32(data - 7); - tmp_vec[4] = vld1q_s32(data - 6); - tmp_vec[5] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - tmp_vec[6] = vld1q_s32(data + i - 4); - tmp_vec[7] = vld1q_s32(data + i - 3); - tmp_vec[8] = vld1q_s32(data + i - 2); - tmp_vec[9] = vld1q_s32(data + i - 1); - tmp_vec[10] = vld1q_s32(data + i - 0); - tmp_vec[11] = vld1q_s32(data + i + 1); - tmp_vec[12] = vld1q_s32(data + i + 2); - tmp_vec[13] = vld1q_s32(data + i + 3); - tmp_vec[14] = vld1q_s32(data + i + 4); - tmp_vec[15] = vld1q_s32(data + i + 5); - tmp_vec[16] = vld1q_s32(data + i + 6); - tmp_vec[17] = vld1q_s32(data + i + 7); - - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_2, 1) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_2, 0) - MACC_32BIT_LOOP_UNROOL_3(2, qlp_coeff_1, 3) - MACC_32BIT_LOOP_UNROOL_3(3, qlp_coeff_1, 2) - MACC_32BIT_LOOP_UNROOL_3(4, qlp_coeff_1, 1) - MACC_32BIT_LOOP_UNROOL_3(5, qlp_coeff_1, 0) - MACC_32BIT_LOOP_UNROOL_3(6, qlp_coeff_0, 3) - MACC_32BIT_LOOP_UNROOL_3(7, qlp_coeff_0, 2) - MACC_32BIT_LOOP_UNROOL_3(8, qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(9, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - tmp_vec[3] = tmp_vec[15]; - tmp_vec[4] = tmp_vec[16]; - tmp_vec[5] = tmp_vec[17]; - } - } - else { /* order == 9 */ - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], qlp_coeff[6], qlp_coeff[7]}; - int32x4_t qlp_coeff_2 = {qlp_coeff[8], 0, 0, 0}; - - tmp_vec[0] = vld1q_s32(data - 9); - tmp_vec[1] = vld1q_s32(data - 8); - tmp_vec[2] = vld1q_s32(data - 7); - tmp_vec[3] = vld1q_s32(data - 6); - tmp_vec[4] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - tmp_vec[5] = vld1q_s32(data + i - 4); - tmp_vec[6] = vld1q_s32(data + i - 3); - tmp_vec[7] = vld1q_s32(data + i - 2); - tmp_vec[8] = vld1q_s32(data + i - 1); - tmp_vec[9] = vld1q_s32(data + i - 0); - tmp_vec[10] = vld1q_s32(data + i + 1); - tmp_vec[11] = vld1q_s32(data + i + 2); - tmp_vec[12] = vld1q_s32(data + i + 3); - tmp_vec[13] = vld1q_s32(data + i + 4); - tmp_vec[14] = vld1q_s32(data + i + 5); - tmp_vec[15] = vld1q_s32(data + i + 6); - tmp_vec[16] = vld1q_s32(data + i + 7); - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_2, 0) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_1, 3) - MACC_32BIT_LOOP_UNROOL_3(2, qlp_coeff_1, 2) - MACC_32BIT_LOOP_UNROOL_3(3, qlp_coeff_1, 1) - MACC_32BIT_LOOP_UNROOL_3(4, qlp_coeff_1, 0) - MACC_32BIT_LOOP_UNROOL_3(5, qlp_coeff_0, 3) - MACC_32BIT_LOOP_UNROOL_3(6, qlp_coeff_0, 2) - MACC_32BIT_LOOP_UNROOL_3(7, qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(8, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - tmp_vec[3] = tmp_vec[15]; - tmp_vec[4] = tmp_vec[16]; - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], qlp_coeff[6], qlp_coeff[7]}; - - tmp_vec[0] = vld1q_s32(data - 8); - tmp_vec[1] = vld1q_s32(data - 7); - tmp_vec[2] = vld1q_s32(data - 6); - tmp_vec[3] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - tmp_vec[4] = vld1q_s32(data + i - 4); - tmp_vec[5] = vld1q_s32(data + i - 3); - tmp_vec[6] = vld1q_s32(data + i - 2); - tmp_vec[7] = vld1q_s32(data + i - 1); - tmp_vec[8] = vld1q_s32(data + i - 0); - tmp_vec[9] = vld1q_s32(data + i + 1); - tmp_vec[10] = vld1q_s32(data + i + 2); - tmp_vec[11] = vld1q_s32(data + i + 3); - tmp_vec[12] = vld1q_s32(data + i + 4); - tmp_vec[13] = vld1q_s32(data + i + 5); - tmp_vec[14] = vld1q_s32(data + i + 6); - tmp_vec[15] = vld1q_s32(data + i + 7); - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_1, 3) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_1, 2) - MACC_32BIT_LOOP_UNROOL_3(2, qlp_coeff_1, 1) - MACC_32BIT_LOOP_UNROOL_3(3, qlp_coeff_1, 0) - MACC_32BIT_LOOP_UNROOL_3(4, qlp_coeff_0, 3) - MACC_32BIT_LOOP_UNROOL_3(5, qlp_coeff_0, 2) - MACC_32BIT_LOOP_UNROOL_3(6, qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(7, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - tmp_vec[3] = tmp_vec[15]; - } - } - else { /* order == 7 */ - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], qlp_coeff[6], 0}; - - tmp_vec[0] = vld1q_s32(data - 7); - tmp_vec[1] = vld1q_s32(data - 6); - tmp_vec[2] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - tmp_vec[3] = vld1q_s32(data + i - 4); - tmp_vec[4] = vld1q_s32(data + i - 3); - tmp_vec[5] = vld1q_s32(data + i - 2); - tmp_vec[6] = vld1q_s32(data + i - 1); - tmp_vec[7] = vld1q_s32(data + i - 0); - tmp_vec[8] = vld1q_s32(data + i + 1); - tmp_vec[9] = vld1q_s32(data + i + 2); - tmp_vec[10] = vld1q_s32(data + i + 3); - tmp_vec[11] = vld1q_s32(data + i + 4); - tmp_vec[12] = vld1q_s32(data + i + 5); - tmp_vec[13] = vld1q_s32(data + i + 6); - tmp_vec[14] = vld1q_s32(data + i + 7); - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_1, 2) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_1, 1) - MACC_32BIT_LOOP_UNROOL_3(2, qlp_coeff_1, 0) - MACC_32BIT_LOOP_UNROOL_3(3, qlp_coeff_0, 3) - MACC_32BIT_LOOP_UNROOL_3(4, qlp_coeff_0, 2) - MACC_32BIT_LOOP_UNROOL_3(5, qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(6, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - } - } - } - else { - if(order == 6) { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], 0, 0}; - - tmp_vec[0] = vld1q_s32(data - 6); - tmp_vec[1] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - tmp_vec[2] = vld1q_s32(data + i - 4); - tmp_vec[3] = vld1q_s32(data + i - 3); - tmp_vec[4] = vld1q_s32(data + i - 2); - tmp_vec[5] = vld1q_s32(data + i - 1); - tmp_vec[6] = vld1q_s32(data + i - 0); - tmp_vec[7] = vld1q_s32(data + i + 1); - tmp_vec[8] = vld1q_s32(data + i + 2); - tmp_vec[9] = vld1q_s32(data + i + 3); - tmp_vec[10] = vld1q_s32(data + i + 4); - tmp_vec[11] = vld1q_s32(data + i + 5); - tmp_vec[12] = vld1q_s32(data + i + 6); - tmp_vec[13] = vld1q_s32(data + i + 7); - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_1, 1) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_1, 0) - MACC_32BIT_LOOP_UNROOL_3(2, qlp_coeff_0, 3) - MACC_32BIT_LOOP_UNROOL_3(3, qlp_coeff_0, 2) - MACC_32BIT_LOOP_UNROOL_3(4, qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(5, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - } - } - else { /* order == 5 */ - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], 0, 0, 0}; - - tmp_vec[0] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - - tmp_vec[1] = vld1q_s32(data + i - 4); - tmp_vec[2] = vld1q_s32(data + i - 3); - tmp_vec[3] = vld1q_s32(data + i - 2); - tmp_vec[4] = vld1q_s32(data + i - 1); - tmp_vec[5] = vld1q_s32(data + i - 0); - tmp_vec[6] = vld1q_s32(data + i + 1); - tmp_vec[7] = vld1q_s32(data + i + 2); - tmp_vec[8] = vld1q_s32(data + i + 3); - tmp_vec[9] = vld1q_s32(data + i + 4); - tmp_vec[10] = vld1q_s32(data + i + 5); - tmp_vec[11] = vld1q_s32(data + i + 6); - tmp_vec[12] = vld1q_s32(data + i + 7); - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_1, 0) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_0, 3) - MACC_32BIT_LOOP_UNROOL_3(2, qlp_coeff_0, 2) - MACC_32BIT_LOOP_UNROOL_3(3, qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(4, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - - tmp_vec[0] = tmp_vec[12]; - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - tmp_vec[0] = vld1q_s32(data + i - 4); - tmp_vec[1] = vld1q_s32(data + i - 3); - tmp_vec[2] = vld1q_s32(data + i - 2); - tmp_vec[3] = vld1q_s32(data + i - 1); - tmp_vec[4] = vld1q_s32(data + i - 0); - tmp_vec[5] = vld1q_s32(data + i + 1); - tmp_vec[6] = vld1q_s32(data + i + 2); - tmp_vec[7] = vld1q_s32(data + i + 3); - tmp_vec[8] = vld1q_s32(data + i + 4); - tmp_vec[9] = vld1q_s32(data + i + 5); - tmp_vec[10] = vld1q_s32(data + i + 6); - tmp_vec[11] = vld1q_s32(data + i + 7); - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_0, 3) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_0, 2) - MACC_32BIT_LOOP_UNROOL_3(2, qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(3, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - } - } - else { /* order == 3 */ - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], 0}; - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - tmp_vec[0] = vld1q_s32(data + i - 3); - tmp_vec[1] = vld1q_s32(data + i - 2); - tmp_vec[2] = vld1q_s32(data + i - 1); - tmp_vec[4] = vld1q_s32(data + i + 1); - tmp_vec[5] = vld1q_s32(data + i + 2); - tmp_vec[6] = vld1q_s32(data + i + 3); - tmp_vec[8] = vld1q_s32(data + i + 5); - tmp_vec[9] = vld1q_s32(data + i + 6); - tmp_vec[10] = vld1q_s32(data + i + 7); - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_0, 2) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(2, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - } - } - } - else { - if(order == 2) { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], 0, 0}; - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - tmp_vec[0] = vld1q_s32(data + i - 2); - tmp_vec[1] = vld1q_s32(data + i - 1); - tmp_vec[4] = vld1q_s32(data + i + 2); - tmp_vec[5] = vld1q_s32(data + i + 3); - tmp_vec[8] = vld1q_s32(data + i + 6); - tmp_vec[9] = vld1q_s32(data + i + 7); - - MUL_32_BIT_LOOP_UNROOL_3(qlp_coeff_0, 1) - MACC_32BIT_LOOP_UNROOL_3(1, qlp_coeff_0, 0) - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - } - } - else { /* order == 1 */ - int32x4_t qlp_coeff_0 = vdupq_n_s32(qlp_coeff[0]); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int32x4_t summ_0, summ_1, summ_2; - tmp_vec[0] = vld1q_s32(data + i - 1); - tmp_vec[4] = vld1q_s32(data + i + 3); - tmp_vec[8] = vld1q_s32(data + i + 7); - - summ_0 = vmulq_s32(tmp_vec[0], qlp_coeff_0); - summ_1 = vmulq_s32(tmp_vec[4], qlp_coeff_0); - summ_2 = vmulq_s32(tmp_vec[8], qlp_coeff_0); - - vst1q_s32(residual+i + 0, vsubq_s32(vld1q_s32(data+i + 0) , vshlq_s32(summ_0,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 4, vsubq_s32(vld1q_s32(data+i + 4) , vshlq_s32(summ_1,vdupq_n_s32(-lp_quantization)))); - vst1q_s32(residual+i + 8, vsubq_s32(vld1q_s32(data+i + 8) , vshlq_s32(summ_2,vdupq_n_s32(-lp_quantization)))); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } -} - - - -#define MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_vec, lane) \ - summ_l_0 = vmull_laneq_s32(vget_low_s32(tmp_vec[0]),qlp_coeff_vec, lane); \ - summ_h_0 = vmull_high_laneq_s32(tmp_vec[0], qlp_coeff_vec, lane);\ - summ_l_1 = vmull_laneq_s32(vget_low_s32(tmp_vec[4]),qlp_coeff_vec, lane); \ - summ_h_1 = vmull_high_laneq_s32(tmp_vec[4], qlp_coeff_vec, lane);\ - summ_l_2 = vmull_laneq_s32(vget_low_s32(tmp_vec[8]),qlp_coeff_vec, lane);\ - summ_h_2 = vmull_high_laneq_s32(tmp_vec[8], qlp_coeff_vec, lane); - - -#define MACC_64_BIT_LOOP_UNROOL_3(tmp_vec_ind, qlp_coeff_vec, lane) \ - summ_l_0 = vmlal_laneq_s32(summ_l_0,vget_low_s32(tmp_vec[tmp_vec_ind]),qlp_coeff_vec, lane); \ - summ_h_0 = vmlal_high_laneq_s32(summ_h_0, tmp_vec[tmp_vec_ind], qlp_coeff_vec, lane); \ - summ_l_1 = vmlal_laneq_s32(summ_l_1, vget_low_s32(tmp_vec[tmp_vec_ind+4]),qlp_coeff_vec, lane); \ - summ_h_1 = vmlal_high_laneq_s32(summ_h_1, tmp_vec[tmp_vec_ind+4], qlp_coeff_vec, lane); \ - summ_l_2 = vmlal_laneq_s32(summ_l_2, vget_low_s32(tmp_vec[tmp_vec_ind+8]),qlp_coeff_vec, lane);\ - summ_h_2 = vmlal_high_laneq_s32(summ_h_2,tmp_vec[tmp_vec_ind+8], qlp_coeff_vec, lane); - -#define SHIFT_SUMS_64BITS_AND_STORE_SUB() \ - res0 = vuzp1q_s32(vreinterpretq_s32_s64(vshlq_s64(summ_l_0,lp_quantization_vec)), vreinterpretq_s32_s64(vshlq_s64(summ_h_0,lp_quantization_vec))); \ - res1 = vuzp1q_s32(vreinterpretq_s32_s64(vshlq_s64(summ_l_1,lp_quantization_vec)), vreinterpretq_s32_s64(vshlq_s64(summ_h_1,lp_quantization_vec))); \ - res2 = vuzp1q_s32(vreinterpretq_s32_s64(vshlq_s64(summ_l_2,lp_quantization_vec)), vreinterpretq_s32_s64(vshlq_s64(summ_h_2,lp_quantization_vec))); \ - vst1q_s32(residual+i+0, vsubq_s32(vld1q_s32(data+i+0), res0));\ - vst1q_s32(residual+i+4, vsubq_s32(vld1q_s32(data+i+4), res1));\ - vst1q_s32(residual+i+8, vsubq_s32(vld1q_s32(data+i+8), res2)); - -void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_neon(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) { - int i; - FLAC__int64 sum; - - int32x4_t tmp_vec[20]; - int32x4_t res0, res1, res2; - int64x2_t lp_quantization_vec = vdupq_n_s64(-lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - // Using prologue reads is valid as encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order,....) - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4],qlp_coeff[5],qlp_coeff[6],qlp_coeff[7]}; - int32x4_t qlp_coeff_2 = {qlp_coeff[8],qlp_coeff[9],qlp_coeff[10],qlp_coeff[11]}; - - tmp_vec[0] = vld1q_s32(data - 12); - tmp_vec[1] = vld1q_s32(data - 11); - tmp_vec[2] = vld1q_s32(data - 10); - tmp_vec[3] = vld1q_s32(data - 9); - tmp_vec[4] = vld1q_s32(data - 8); - tmp_vec[5] = vld1q_s32(data - 7); - tmp_vec[6] = vld1q_s32(data - 6); - tmp_vec[7] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - - tmp_vec[8] = vld1q_s32(data+i-4); - tmp_vec[9] = vld1q_s32(data+i-3); - tmp_vec[10] = vld1q_s32(data+i-2); - tmp_vec[11] = vld1q_s32(data+i-1); - tmp_vec[12] = vld1q_s32(data+i); - tmp_vec[13] = vld1q_s32(data+i+1); - tmp_vec[14] = vld1q_s32(data+i+2); - tmp_vec[15] = vld1q_s32(data+i+3); - tmp_vec[16] = vld1q_s32(data + i + 4); - tmp_vec[17] = vld1q_s32(data + i + 5); - tmp_vec[18] = vld1q_s32(data + i + 6); - tmp_vec[19] = vld1q_s32(data + i + 7); - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_2, 3) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_2, 2) - MACC_64_BIT_LOOP_UNROOL_3(2, qlp_coeff_2, 1) - MACC_64_BIT_LOOP_UNROOL_3(3, qlp_coeff_2, 0) - MACC_64_BIT_LOOP_UNROOL_3(4, qlp_coeff_1, 3) - MACC_64_BIT_LOOP_UNROOL_3(5, qlp_coeff_1, 2) - MACC_64_BIT_LOOP_UNROOL_3(6, qlp_coeff_1, 1) - MACC_64_BIT_LOOP_UNROOL_3(7, qlp_coeff_1, 0) - MACC_64_BIT_LOOP_UNROOL_3(8, qlp_coeff_0, 3) - MACC_64_BIT_LOOP_UNROOL_3(9, qlp_coeff_0, 2) - MACC_64_BIT_LOOP_UNROOL_3(10,qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(11,qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - tmp_vec[3] = tmp_vec[15]; - tmp_vec[4] = tmp_vec[16]; - tmp_vec[5] = tmp_vec[17]; - tmp_vec[6] = tmp_vec[18]; - tmp_vec[7] = tmp_vec[19]; - } - } - else { /* order == 11 */ - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4],qlp_coeff[5],qlp_coeff[6],qlp_coeff[7]}; - int32x4_t qlp_coeff_2 = {qlp_coeff[8],qlp_coeff[9],qlp_coeff[10],0}; - - tmp_vec[0] = vld1q_s32(data - 11); - tmp_vec[1] = vld1q_s32(data - 10); - tmp_vec[2] = vld1q_s32(data - 9); - tmp_vec[3] = vld1q_s32(data - 8); - tmp_vec[4] = vld1q_s32(data - 7); - tmp_vec[5] = vld1q_s32(data - 6); - tmp_vec[6] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - - tmp_vec[7] = vld1q_s32(data+i-4); - tmp_vec[8] = vld1q_s32(data+i-3); - tmp_vec[9] = vld1q_s32(data+i-2); - tmp_vec[10] = vld1q_s32(data+i-1); - tmp_vec[11] = vld1q_s32(data+i); - tmp_vec[12] = vld1q_s32(data+i+1); - tmp_vec[13] = vld1q_s32(data+i+2); - tmp_vec[14] = vld1q_s32(data+i+3); - tmp_vec[15] = vld1q_s32(data + i + 4); - tmp_vec[16] = vld1q_s32(data + i + 5); - tmp_vec[17] = vld1q_s32(data + i + 6); - tmp_vec[18] = vld1q_s32(data + i + 7); - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_2, 2) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_2, 1) - MACC_64_BIT_LOOP_UNROOL_3(2, qlp_coeff_2, 0) - MACC_64_BIT_LOOP_UNROOL_3(3, qlp_coeff_1, 3) - MACC_64_BIT_LOOP_UNROOL_3(4, qlp_coeff_1, 2) - MACC_64_BIT_LOOP_UNROOL_3(5, qlp_coeff_1, 1) - MACC_64_BIT_LOOP_UNROOL_3(6, qlp_coeff_1, 0) - MACC_64_BIT_LOOP_UNROOL_3(7, qlp_coeff_0, 3) - MACC_64_BIT_LOOP_UNROOL_3(8, qlp_coeff_0, 2) - MACC_64_BIT_LOOP_UNROOL_3(9, qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(10,qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - tmp_vec[3] = tmp_vec[15]; - tmp_vec[4] = tmp_vec[16]; - tmp_vec[5] = tmp_vec[17]; - tmp_vec[6] = tmp_vec[18]; - } - } - } - else - { - if (order == 10) { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], qlp_coeff[6], qlp_coeff[7]}; - int32x4_t qlp_coeff_2 = {qlp_coeff[8], qlp_coeff[9], 0, 0}; - - tmp_vec[0] = vld1q_s32(data - 10); - tmp_vec[1] = vld1q_s32(data - 9); - tmp_vec[2] = vld1q_s32(data - 8); - tmp_vec[3] = vld1q_s32(data - 7); - tmp_vec[4] = vld1q_s32(data - 6); - tmp_vec[5] = vld1q_s32(data - 5); - - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - - tmp_vec[6] = vld1q_s32(data + i - 4); - tmp_vec[7] = vld1q_s32(data + i - 3); - tmp_vec[8] = vld1q_s32(data + i - 2); - tmp_vec[9] = vld1q_s32(data + i - 1); - tmp_vec[10] = vld1q_s32(data + i - 0); - tmp_vec[11] = vld1q_s32(data + i + 1); - tmp_vec[12] = vld1q_s32(data + i + 2); - tmp_vec[13] = vld1q_s32(data + i + 3); - tmp_vec[14] = vld1q_s32(data + i + 4); - tmp_vec[15] = vld1q_s32(data + i + 5); - tmp_vec[16] = vld1q_s32(data + i + 6); - tmp_vec[17] = vld1q_s32(data + i + 7); - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_2, 1) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_2, 0) - MACC_64_BIT_LOOP_UNROOL_3(2, qlp_coeff_1, 3) - MACC_64_BIT_LOOP_UNROOL_3(3, qlp_coeff_1, 2) - MACC_64_BIT_LOOP_UNROOL_3(4, qlp_coeff_1, 1) - MACC_64_BIT_LOOP_UNROOL_3(5, qlp_coeff_1, 0) - MACC_64_BIT_LOOP_UNROOL_3(6, qlp_coeff_0, 3) - MACC_64_BIT_LOOP_UNROOL_3(7, qlp_coeff_0, 2) - MACC_64_BIT_LOOP_UNROOL_3(8, qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(9, qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - tmp_vec[3] = tmp_vec[15]; - tmp_vec[4] = tmp_vec[16]; - tmp_vec[5] = tmp_vec[17]; - } - } - - else /* order == 9 */ { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], qlp_coeff[6], qlp_coeff[7]}; - int32x4_t qlp_coeff_2 = {qlp_coeff[8], 0, 0, 0}; - - tmp_vec[0] = vld1q_s32(data - 9); - tmp_vec[1] = vld1q_s32(data - 8); - tmp_vec[2] = vld1q_s32(data - 7); - tmp_vec[3] = vld1q_s32(data - 6); - tmp_vec[4] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - - tmp_vec[5] = vld1q_s32(data + i - 4); - tmp_vec[6] = vld1q_s32(data + i - 3); - tmp_vec[7] = vld1q_s32(data + i - 2); - tmp_vec[8] = vld1q_s32(data + i - 1); - tmp_vec[9] = vld1q_s32(data + i - 0); - tmp_vec[10] = vld1q_s32(data + i + 1); - tmp_vec[11] = vld1q_s32(data + i + 2); - tmp_vec[12] = vld1q_s32(data + i + 3); - tmp_vec[13] = vld1q_s32(data + i + 4); - tmp_vec[14] = vld1q_s32(data + i + 5); - tmp_vec[15] = vld1q_s32(data + i + 6); - tmp_vec[16] = vld1q_s32(data + i + 7); - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_2, 0) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_1, 3) - MACC_64_BIT_LOOP_UNROOL_3(2, qlp_coeff_1, 2) - MACC_64_BIT_LOOP_UNROOL_3(3, qlp_coeff_1, 1) - MACC_64_BIT_LOOP_UNROOL_3(4, qlp_coeff_1, 0) - MACC_64_BIT_LOOP_UNROOL_3(5, qlp_coeff_0, 3) - MACC_64_BIT_LOOP_UNROOL_3(6, qlp_coeff_0, 2) - MACC_64_BIT_LOOP_UNROOL_3(7, qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(8, qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - tmp_vec[3] = tmp_vec[15]; - tmp_vec[4] = tmp_vec[16]; - } - } - } - } - else if (order > 4) - { - if (order > 6) - { - if (order == 8) - { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], qlp_coeff[6], qlp_coeff[7]}; - - tmp_vec[0] = vld1q_s32(data - 8); - tmp_vec[1] = vld1q_s32(data - 7); - tmp_vec[2] = vld1q_s32(data - 6); - tmp_vec[3] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - - tmp_vec[4] = vld1q_s32(data + i - 4); - tmp_vec[5] = vld1q_s32(data + i - 3); - tmp_vec[6] = vld1q_s32(data + i - 2); - tmp_vec[7] = vld1q_s32(data + i - 1); - tmp_vec[8] = vld1q_s32(data + i - 0); - tmp_vec[9] = vld1q_s32(data + i + 1); - tmp_vec[10] = vld1q_s32(data + i + 2); - tmp_vec[11] = vld1q_s32(data + i + 3); - tmp_vec[12] = vld1q_s32(data + i + 4); - tmp_vec[13] = vld1q_s32(data + i + 5); - tmp_vec[14] = vld1q_s32(data + i + 6); - tmp_vec[15] = vld1q_s32(data + i + 7); - - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_1, 3) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_1, 2) - MACC_64_BIT_LOOP_UNROOL_3(2, qlp_coeff_1, 1) - MACC_64_BIT_LOOP_UNROOL_3(3, qlp_coeff_1, 0) - MACC_64_BIT_LOOP_UNROOL_3(4, qlp_coeff_0, 3) - MACC_64_BIT_LOOP_UNROOL_3(5, qlp_coeff_0, 2) - MACC_64_BIT_LOOP_UNROOL_3(6, qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(7, qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - tmp_vec[3] = tmp_vec[15]; - } - } - else /* order == 7 */ - { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], qlp_coeff[6], 0}; - - tmp_vec[0] = vld1q_s32(data - 7); - tmp_vec[1] = vld1q_s32(data - 6); - tmp_vec[2] = vld1q_s32(data - 5); - - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - tmp_vec[3] = vld1q_s32(data +i - 4); - tmp_vec[4] = vld1q_s32(data + i - 3); - tmp_vec[5] = vld1q_s32(data + i - 2); - tmp_vec[6] = vld1q_s32(data + i - 1); - tmp_vec[7] = vld1q_s32(data + i - 0); - tmp_vec[8] = vld1q_s32(data + i + 1); - tmp_vec[9] = vld1q_s32(data + i + 2); - tmp_vec[10] = vld1q_s32(data + i + 3); - tmp_vec[11] = vld1q_s32(data + i + 4); - tmp_vec[12] = vld1q_s32(data + i + 5); - tmp_vec[13] = vld1q_s32(data + i + 6); - tmp_vec[14] = vld1q_s32(data + i + 7); - - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_1, 2) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_1, 1) - MACC_64_BIT_LOOP_UNROOL_3(2, qlp_coeff_1, 0) - MACC_64_BIT_LOOP_UNROOL_3(3, qlp_coeff_0, 3) - MACC_64_BIT_LOOP_UNROOL_3(4, qlp_coeff_0, 2) - MACC_64_BIT_LOOP_UNROOL_3(5, qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(6, qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - tmp_vec[2] = tmp_vec[14]; - } - } - } - else - { - if (order == 6) { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], qlp_coeff[5], 0, 0}; - - tmp_vec[0] = vld1q_s32(data - 6); - tmp_vec[1] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - - tmp_vec[2] = vld1q_s32(data + i - 4); - tmp_vec[3] = vld1q_s32(data + i - 3); - tmp_vec[4] = vld1q_s32(data + i - 2); - tmp_vec[5] = vld1q_s32(data + i - 1); - tmp_vec[6] = vld1q_s32(data + i - 0); - tmp_vec[7] = vld1q_s32(data + i + 1); - tmp_vec[8] = vld1q_s32(data + i + 2); - tmp_vec[9] = vld1q_s32(data + i + 3); - tmp_vec[10] = vld1q_s32(data + i + 4); - tmp_vec[11] = vld1q_s32(data + i + 5); - tmp_vec[12] = vld1q_s32(data + i + 6); - tmp_vec[13] = vld1q_s32(data + i + 7); - - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_1, 1) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_1, 0) - MACC_64_BIT_LOOP_UNROOL_3(2, qlp_coeff_0, 3) - MACC_64_BIT_LOOP_UNROOL_3(3, qlp_coeff_0, 2) - MACC_64_BIT_LOOP_UNROOL_3(4, qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(5, qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - - tmp_vec[0] = tmp_vec[12]; - tmp_vec[1] = tmp_vec[13]; - } - } - - else - { /* order == 5 */ - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - int32x4_t qlp_coeff_1 = {qlp_coeff[4], 0, 0, 0}; - - tmp_vec[0] = vld1q_s32(data - 5); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - tmp_vec[1] = vld1q_s32(data + i - 4); - tmp_vec[2] = vld1q_s32(data + i - 3); - tmp_vec[3] = vld1q_s32(data + i - 2); - tmp_vec[4] = vld1q_s32(data + i - 1); - tmp_vec[5] = vld1q_s32(data + i - 0); - tmp_vec[6] = vld1q_s32(data + i + 1); - tmp_vec[7] = vld1q_s32(data + i + 2); - tmp_vec[8] = vld1q_s32(data + i + 3); - tmp_vec[9] = vld1q_s32(data + i + 4); - tmp_vec[10] = vld1q_s32(data + i + 5); - tmp_vec[11] = vld1q_s32(data + i + 6); - tmp_vec[12] = vld1q_s32(data + i + 7); - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_1, 0) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_0, 3) - MACC_64_BIT_LOOP_UNROOL_3(2, qlp_coeff_0, 2) - MACC_64_BIT_LOOP_UNROOL_3(3, qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(4, qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - - tmp_vec[0] = tmp_vec[12]; - } - } - } - } - else - { - if (order > 2) - { - if (order == 4) - { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], qlp_coeff[3]}; - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - tmp_vec[0] = vld1q_s32(data + i - 4); - tmp_vec[1] = vld1q_s32(data + i - 3); - tmp_vec[2] = vld1q_s32(data + i - 2); - tmp_vec[3] = vld1q_s32(data + i - 1); - tmp_vec[4] = vld1q_s32(data + i - 0); - tmp_vec[5] = vld1q_s32(data + i + 1); - tmp_vec[6] = vld1q_s32(data + i + 2); - tmp_vec[7] = vld1q_s32(data + i + 3); - tmp_vec[8] = vld1q_s32(data + i + 4); - tmp_vec[9] = vld1q_s32(data + i + 5); - tmp_vec[10] = vld1q_s32(data + i + 6); - tmp_vec[11] = vld1q_s32(data + i + 7); - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_0, 3) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_0, 2) - MACC_64_BIT_LOOP_UNROOL_3(2, qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(3, qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - } - } - else - { /* order == 3 */ - - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], qlp_coeff[2], 0}; - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - tmp_vec[0] = vld1q_s32(data + i - 3); - tmp_vec[1] = vld1q_s32(data + i - 2); - tmp_vec[2] = vld1q_s32(data + i - 1); - tmp_vec[4] = vld1q_s32(data + i + 1); - tmp_vec[5] = vld1q_s32(data + i + 2); - tmp_vec[6] = vld1q_s32(data + i + 3); - tmp_vec[8] = vld1q_s32(data + i + 5); - tmp_vec[9] = vld1q_s32(data + i + 6); - tmp_vec[10] = vld1q_s32(data + i + 7); - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_0, 2) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(2, qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - } - } - } - else - { - if (order == 2) - { - int32x4_t qlp_coeff_0 = {qlp_coeff[0], qlp_coeff[1], 0, 0}; - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - tmp_vec[0] = vld1q_s32(data + i - 2); - tmp_vec[1] = vld1q_s32(data + i - 1); - tmp_vec[4] = vld1q_s32(data + i + 2); - tmp_vec[5] = vld1q_s32(data + i + 3); - tmp_vec[8] = vld1q_s32(data + i + 6); - tmp_vec[9] = vld1q_s32(data + i + 7); - - MUL_64_BIT_LOOP_UNROOL_3(qlp_coeff_0, 1) - MACC_64_BIT_LOOP_UNROOL_3(1, qlp_coeff_0, 0) - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - } - } - - else - { /* order == 1 */ - - int32x2_t qlp_coeff_0_2 = vdup_n_s32(qlp_coeff[0]); - int32x4_t qlp_coeff_0_4 = vdupq_n_s32(qlp_coeff[0]); - - for (i = 0; i < (int)data_len - 11; i += 12) - { - int64x2_t summ_l_0, summ_h_0, summ_l_1, summ_h_1, summ_l_2, summ_h_2; - tmp_vec[0] = vld1q_s32(data + i - 1); - tmp_vec[4] = vld1q_s32(data + i + 3); - tmp_vec[8] = vld1q_s32(data + i + 7); - - summ_l_0 = vmull_s32(vget_low_s32(tmp_vec[0]), qlp_coeff_0_2); - summ_h_0 = vmull_high_s32(tmp_vec[0], qlp_coeff_0_4); - - summ_l_1 = vmull_s32(vget_low_s32(tmp_vec[4]), qlp_coeff_0_2); - summ_h_1 = vmull_high_s32(tmp_vec[4], qlp_coeff_0_4); - - summ_l_2 = vmull_s32(vget_low_s32(tmp_vec[8]), qlp_coeff_0_2); - summ_h_2 = vmull_high_s32(tmp_vec[8], qlp_coeff_0_4); - - SHIFT_SUMS_64BITS_AND_STORE_SUB() - } - } - } - } - for (; i < (int)data_len; i++) - { - sum = 0; - switch (order) - { - case 12: - sum += qlp_coeff[11] * (FLAC__int64)data[i - 12]; /* Falls through. */ - case 11: - sum += qlp_coeff[10] * (FLAC__int64)data[i - 11]; /* Falls through. */ - case 10: - sum += qlp_coeff[9] * (FLAC__int64)data[i - 10]; /* Falls through. */ - case 9: - sum += qlp_coeff[8] * (FLAC__int64)data[i - 9]; /* Falls through. */ - case 8: - sum += qlp_coeff[7] * (FLAC__int64)data[i - 8]; /* Falls through. */ - case 7: - sum += qlp_coeff[6] * (FLAC__int64)data[i - 7]; /* Falls through. */ - case 6: - sum += qlp_coeff[5] * (FLAC__int64)data[i - 6]; /* Falls through. */ - case 5: - sum += qlp_coeff[4] * (FLAC__int64)data[i - 5]; /* Falls through. */ - case 4: - sum += qlp_coeff[3] * (FLAC__int64)data[i - 4]; /* Falls through. */ - case 3: - sum += qlp_coeff[2] * (FLAC__int64)data[i - 3]; /* Falls through. */ - case 2: - sum += qlp_coeff[1] * (FLAC__int64)data[i - 2]; /* Falls through. */ - case 1: - sum += qlp_coeff[0] * (FLAC__int64)data[i - 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else - { /* order > 12 */ - for (i = 0; i < (int)data_len; i++) - { - sum = 0; - switch (order) - { - case 32: - sum += qlp_coeff[31] * (FLAC__int64)data[i - 32]; /* Falls through. */ - case 31: - sum += qlp_coeff[30] * (FLAC__int64)data[i - 31]; /* Falls through. */ - case 30: - sum += qlp_coeff[29] * (FLAC__int64)data[i - 30]; /* Falls through. */ - case 29: - sum += qlp_coeff[28] * (FLAC__int64)data[i - 29]; /* Falls through. */ - case 28: - sum += qlp_coeff[27] * (FLAC__int64)data[i - 28]; /* Falls through. */ - case 27: - sum += qlp_coeff[26] * (FLAC__int64)data[i - 27]; /* Falls through. */ - case 26: - sum += qlp_coeff[25] * (FLAC__int64)data[i - 26]; /* Falls through. */ - case 25: - sum += qlp_coeff[24] * (FLAC__int64)data[i - 25]; /* Falls through. */ - case 24: - sum += qlp_coeff[23] * (FLAC__int64)data[i - 24]; /* Falls through. */ - case 23: - sum += qlp_coeff[22] * (FLAC__int64)data[i - 23]; /* Falls through. */ - case 22: - sum += qlp_coeff[21] * (FLAC__int64)data[i - 22]; /* Falls through. */ - case 21: - sum += qlp_coeff[20] * (FLAC__int64)data[i - 21]; /* Falls through. */ - case 20: - sum += qlp_coeff[19] * (FLAC__int64)data[i - 20]; /* Falls through. */ - case 19: - sum += qlp_coeff[18] * (FLAC__int64)data[i - 19]; /* Falls through. */ - case 18: - sum += qlp_coeff[17] * (FLAC__int64)data[i - 18]; /* Falls through. */ - case 17: - sum += qlp_coeff[16] * (FLAC__int64)data[i - 17]; /* Falls through. */ - case 16: - sum += qlp_coeff[15] * (FLAC__int64)data[i - 16]; /* Falls through. */ - case 15: - sum += qlp_coeff[14] * (FLAC__int64)data[i - 15]; /* Falls through. */ - case 14: - sum += qlp_coeff[13] * (FLAC__int64)data[i - 14]; /* Falls through. */ - case 13: - sum += qlp_coeff[12] * (FLAC__int64)data[i - 13]; - sum += qlp_coeff[11] * (FLAC__int64)data[i - 12]; - sum += qlp_coeff[10] * (FLAC__int64)data[i - 11]; - sum += qlp_coeff[9] * (FLAC__int64)data[i - 10]; - sum += qlp_coeff[8] * (FLAC__int64)data[i - 9]; - sum += qlp_coeff[7] * (FLAC__int64)data[i - 8]; - sum += qlp_coeff[6] * (FLAC__int64)data[i - 7]; - sum += qlp_coeff[5] * (FLAC__int64)data[i - 6]; - sum += qlp_coeff[4] * (FLAC__int64)data[i - 5]; - sum += qlp_coeff[3] * (FLAC__int64)data[i - 4]; - sum += qlp_coeff[2] * (FLAC__int64)data[i - 3]; - sum += qlp_coeff[1] * (FLAC__int64)data[i - 2]; - sum += qlp_coeff[0] * (FLAC__int64)data[i - 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - - return; -} - -#endif /* FLAC__CPU_ARM64 && FLAC__HAS_ARCH64INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/lpc_intrin_sse2.c b/flac/src/libFLAC/lpc_intrin_sse2.c deleted file mode 100644 index d16a085..0000000 --- a/flac/src/libFLAC/lpc_intrin_sse2.c +++ /dev/null @@ -1,966 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "private/lpc.h" -#ifdef FLAC__SSE2_SUPPORTED - -#include "FLAC/assert.h" -#include "FLAC/format.h" - -#include /* SSE2 */ - -#define RESIDUAL32_RESULT(xmmN) residual[i] = data[i] - (_mm_cvtsi128_si32(xmmN) >> lp_quantization); -#define DATA32_RESULT(xmmN) data[i] = residual[i] + (_mm_cvtsi128_si32(xmmN) >> lp_quantization); - - -FLAC__SSE_TARGET("sse2") -void FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_8(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]) -{ -#undef MAX_LAG -#define MAX_LAG 8 -#include "deduplication/lpc_compute_autocorrelation_intrin_sse2.c" -} - -FLAC__SSE_TARGET("sse2") -void FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_10(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]) -{ -#undef MAX_LAG -#define MAX_LAG 10 -#include "deduplication/lpc_compute_autocorrelation_intrin_sse2.c" -} - - -FLAC__SSE_TARGET("sse2") -void FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_14(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]) -{ -#undef MAX_LAG -#define MAX_LAG 14 -#include "deduplication/lpc_compute_autocorrelation_intrin_sse2.c" -} - -FLAC__SSE_TARGET("sse2") -void FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_sse2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int32 sum; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(0xffff & qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(0xffff & qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(0xffff & qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - q10 = _mm_cvtsi32_si128(0xffff & qlp_coeff[10]); q10 = _mm_shuffle_epi32(q10, _MM_SHUFFLE(0,0,0,0)); - q11 = _mm_cvtsi32_si128(0xffff & qlp_coeff[11]); q11 = _mm_shuffle_epi32(q11, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q11, _mm_loadu_si128((const __m128i*)(const void*)(data+i-12))); - mull = _mm_madd_epi16(q10, _mm_loadu_si128((const __m128i*)(const void*)(data+i-11))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q9, _mm_loadu_si128((const __m128i*)(const void*)(data+i-10))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q8, _mm_loadu_si128((const __m128i*)(const void*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q7, _mm_loadu_si128((const __m128i*)(const void*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 11 */ - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(0xffff & qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(0xffff & qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(0xffff & qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - q10 = _mm_cvtsi32_si128(0xffff & qlp_coeff[10]); q10 = _mm_shuffle_epi32(q10, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q10, _mm_loadu_si128((const __m128i*)(const void*)(data+i-11))); - mull = _mm_madd_epi16(q9, _mm_loadu_si128((const __m128i*)(const void*)(data+i-10))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q8, _mm_loadu_si128((const __m128i*)(const void*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q7, _mm_loadu_si128((const __m128i*)(const void*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 10) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(0xffff & qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(0xffff & qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(0xffff & qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q9, _mm_loadu_si128((const __m128i*)(const void*)(data+i-10))); - mull = _mm_madd_epi16(q8, _mm_loadu_si128((const __m128i*)(const void*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q7, _mm_loadu_si128((const __m128i*)(const void*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 9 */ - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(0xffff & qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(0xffff & qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q8, _mm_loadu_si128((const __m128i*)(const void*)(data+i-9))); - mull = _mm_madd_epi16(q7, _mm_loadu_si128((const __m128i*)(const void*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(0xffff & qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q7, _mm_loadu_si128((const __m128i*)(const void*)(data+i-8))); - mull = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 7 */ - __m128i q0, q1, q2, q3, q4, q5, q6; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(0xffff & qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); - mull = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 6) { - __m128i q0, q1, q2, q3, q4, q5; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(0xffff & qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); - mull = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 5 */ - __m128i q0, q1, q2, q3, q4; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(0xffff & qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); - mull = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - __m128i q0, q1, q2, q3; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(0xffff & qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); - mull = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 3 */ - __m128i q0, q1, q2; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(0xffff & qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); - mull = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 2) { - __m128i q0, q1; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(0xffff & qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_madd_epi16(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); - mull = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 1 */ - __m128i q0; - q0 = _mm_cvtsi32_si128(0xffff & qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ; - summ = _mm_madd_epi16(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } -} - -#if defined FLAC__CPU_IA32 /* unused for x86_64 */ - -FLAC__SSE_TARGET("sse2") -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse2(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - if(order > 8) { /* order == 9, 10, 11, 12 */ - if(order > 10) { /* order == 11, 12 */ - if(order == 12) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); // 0 0 q[1] q[0] - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); // 0 0 q[3] q[2] - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); // 0 0 q[5] q[4] - xmm3 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+6)); // 0 0 q[7] q[6] - xmm4 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+8)); // 0 0 q[9] q[8] - xmm5 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+10)); // 0 0 q[11] q[10] - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); // 0 q[1] 0 q[0] - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); // 0 q[3] 0 q[2] - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); // 0 q[5] 0 q[4] - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); // 0 q[7] 0 q[6] - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); // 0 q[9] 0 q[8] - xmm5 = _mm_shuffle_epi32(xmm5, _MM_SHUFFLE(3,1,2,0)); // 0 q[11] 0 q[10] - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[11] * data[i-12]; - //sum += qlp_coeff[10] * data[i-11]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-12)); // 0 0 d[i-11] d[i-12] - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); // 0 d[i-12] 0 d[i-11] - xmm7 = _mm_mul_epu32(xmm7, xmm5); /* we use _unsigned_ multiplication and discard high dword of the result values */ - - //sum += qlp_coeff[9] * data[i-10]; - //sum += qlp_coeff[8] * data[i-9]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-10)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm4); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[7] * data[i-8]; - //sum += qlp_coeff[6] * data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm3); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 11 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+6)); - xmm4 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+8)); - xmm5 = _mm_cvtsi32_si128(qlp_coeff[10]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[10] * data[i-11]; - xmm7 = _mm_cvtsi32_si128(data[i-11]); - xmm7 = _mm_mul_epu32(xmm7, xmm5); - - //sum += qlp_coeff[9] * data[i-10]; - //sum += qlp_coeff[8] * data[i-9]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-10)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm4); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[7] * data[i-8]; - //sum += qlp_coeff[6] * data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm3); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - } - else { /* order == 9, 10 */ - if(order == 10) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+6)); - xmm4 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+8)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[9] * data[i-10]; - //sum += qlp_coeff[8] * data[i-9]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-10)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epu32(xmm7, xmm4); - - //sum += qlp_coeff[7] * data[i-8]; - //sum += qlp_coeff[6] * data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm3); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 9 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+6)); - xmm4 = _mm_cvtsi32_si128(qlp_coeff[8]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[8] * data[i-9]; - xmm7 = _mm_cvtsi32_si128(data[i-9]); - xmm7 = _mm_mul_epu32(xmm7, xmm4); - - //sum += qlp_coeff[7] * data[i-8]; - //sum += qlp_coeff[6] * data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm3); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - } - } - else if(order > 4) { /* order == 5, 6, 7, 8 */ - if(order > 6) { /* order == 7, 8 */ - if(order == 8) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+6)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[7] * data[i-8]; - //sum += qlp_coeff[6] * data[i-7]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-8)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epu32(xmm7, xmm3); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 7 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - xmm3 = _mm_cvtsi32_si128(qlp_coeff[6]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[6] * data[i-7]; - xmm7 = _mm_cvtsi32_si128(data[i-7]); - xmm7 = _mm_mul_epu32(xmm7, xmm3); - - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm2); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - } - else { /* order == 5, 6 */ - if(order == 6) { - __m128i xmm0, xmm1, xmm2, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[5] * data[i-6]; - //sum += qlp_coeff[4] * data[i-5]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epu32(xmm7, xmm2); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 5 */ - __m128i xmm0, xmm1, xmm2, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_cvtsi32_si128(qlp_coeff[4]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[4] * data[i-5]; - xmm7 = _mm_cvtsi32_si128(data[i-5]); - xmm7 = _mm_mul_epu32(xmm7, xmm2); - - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm1); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - } - } - else { /* order == 1, 2, 3, 4 */ - if(order > 2) { /* order == 3, 4 */ - if(order == 4) { - __m128i xmm0, xmm1, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[3] * data[i-4]; - //sum += qlp_coeff[2] * data[i-3]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epu32(xmm7, xmm1); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 3 */ - __m128i xmm0, xmm1, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_cvtsi32_si128(qlp_coeff[2]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[2] * data[i-3]; - xmm7 = _mm_cvtsi32_si128(data[i-3]); - xmm7 = _mm_mul_epu32(xmm7, xmm1); - - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epu32(xmm6, xmm0); - xmm7 = _mm_add_epi32(xmm7, xmm6); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - } - else { /* order == 1, 2 */ - if(order == 2) { - __m128i xmm0, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[1] * data[i-2]; - //sum += qlp_coeff[0] * data[i-1]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epu32(xmm7, xmm0); - - xmm7 = _mm_add_epi32(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL32_RESULT(xmm7); - } - } - else { /* order == 1 */ - for(i = 0; i < (int)data_len; i++) - residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization); - } - } - } - } - else { /* order > 12 */ - FLAC__int32 sum; - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } -} - -#endif /* FLAC__CPU_IA32 */ -#endif /* FLAC__SSE2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/lpc_intrin_sse41.c b/flac/src/libFLAC/lpc_intrin_sse41.c deleted file mode 100644 index 756c5dd..0000000 --- a/flac/src/libFLAC/lpc_intrin_sse41.c +++ /dev/null @@ -1,950 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "private/lpc.h" -#ifdef FLAC__SSE4_1_SUPPORTED - -#include "FLAC/assert.h" -#include "FLAC/format.h" - -#include /* SSE4.1 */ - -#if defined FLAC__CPU_IA32 /* unused for x64 */ - -#define RESIDUAL64_RESULT(xmmN) residual[i] = data[i] - _mm_cvtsi128_si32(_mm_srl_epi64(xmmN, cnt)) -#define RESIDUAL64_RESULT1(xmmN) residual[i] = data[i] - _mm_cvtsi128_si32(_mm_srli_epi64(xmmN, lp_quantization)) - -FLAC__SSE_TARGET("sse4.1") -void FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_sse41(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - FLAC__ASSERT(lp_quantization <= 32); /* there's no _mm_sra_epi64() so we have to use _mm_srl_epi64() */ - - if(order <= 12) { - if(order > 8) { /* order == 9, 10, 11, 12 */ - if(order > 10) { /* order == 11, 12 */ - if(order == 12) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); // 0 0 q[1] q[0] - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); // 0 0 q[3] q[2] - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); // 0 0 q[5] q[4] - xmm3 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+6)); // 0 0 q[7] q[6] - xmm4 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+8)); // 0 0 q[9] q[8] - xmm5 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+10)); // 0 0 q[11] q[10] - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); // 0 q[1] 0 q[0] - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); // 0 q[3] 0 q[2] - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); // 0 q[5] 0 q[4] - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); // 0 q[7] 0 q[6] - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); // 0 q[9] 0 q[8] - xmm5 = _mm_shuffle_epi32(xmm5, _MM_SHUFFLE(3,1,2,0)); // 0 q[11] 0 q[10] - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; - //sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-12)); // 0 0 d[i-11] d[i-12] - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); // 0 d[i-12] 0 d[i-11] - xmm7 = _mm_mul_epi32(xmm7, xmm5); - - //sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - //sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-10)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm4); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - //sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm3); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT1(xmm7); - } - } - else { /* order == 11 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+6)); - xmm4 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+8)); - xmm5 = _mm_cvtsi32_si128(qlp_coeff[10]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[10] * (FLAC__int64)data[i-11]; - xmm7 = _mm_cvtsi32_si128(data[i-11]); - xmm7 = _mm_mul_epi32(xmm7, xmm5); - - //sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - //sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-10)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm4); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - //sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm3); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT1(xmm7); - } - } - } - else { /* order == 9, 10 */ - if(order == 10) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+6)); - xmm4 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+8)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - xmm4 = _mm_shuffle_epi32(xmm4, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[9] * (FLAC__int64)data[i-10]; - //sum += qlp_coeff[8] * (FLAC__int64)data[i-9]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-10)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epi32(xmm7, xmm4); - - //sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - //sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm3); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - else { /* order == 9 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+6)); - xmm4 = _mm_cvtsi32_si128(qlp_coeff[8]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[8] * (FLAC__int64)data[i-9]; - xmm7 = _mm_cvtsi32_si128(data[i-9]); - xmm7 = _mm_mul_epi32(xmm7, xmm4); - - //sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - //sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-8)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm3); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - } - } - else if(order > 4) { /* order == 5, 6, 7, 8 */ - if(order > 6) { /* order == 7, 8 */ - if(order == 8) { - __m128i xmm0, xmm1, xmm2, xmm3, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - xmm3 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+6)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - xmm3 = _mm_shuffle_epi32(xmm3, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[7] * (FLAC__int64)data[i-8]; - //sum += qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-8)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epi32(xmm7, xmm3); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - else { /* order == 7 */ - __m128i xmm0, xmm1, xmm2, xmm3, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - xmm3 = _mm_cvtsi32_si128(qlp_coeff[6]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[6] * (FLAC__int64)data[i-7]; - xmm7 = _mm_cvtsi32_si128(data[i-7]); - xmm7 = _mm_mul_epi32(xmm7, xmm3); - - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm2); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - } - else { /* order == 5, 6 */ - if(order == 6) { - __m128i xmm0, xmm1, xmm2, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+4)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - xmm2 = _mm_shuffle_epi32(xmm2, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[5] * (FLAC__int64)data[i-6]; - //sum += qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-6)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epi32(xmm7, xmm2); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - else { /* order == 5 */ - __m128i xmm0, xmm1, xmm2, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - xmm2 = _mm_cvtsi32_si128(qlp_coeff[4]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[4] * (FLAC__int64)data[i-5]; - xmm7 = _mm_cvtsi32_si128(data[i-5]); - xmm7 = _mm_mul_epi32(xmm7, xmm2); - - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm1); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - } - } - else { /* order == 1, 2, 3, 4 */ - if(order > 2) { /* order == 3, 4 */ - if(order == 4) { - __m128i xmm0, xmm1, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+2)); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - xmm1 = _mm_shuffle_epi32(xmm1, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[3] * (FLAC__int64)data[i-4]; - //sum += qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-4)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epi32(xmm7, xmm1); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - else { /* order == 3 */ - __m128i xmm0, xmm1, xmm6, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm1 = _mm_cvtsi32_si128(qlp_coeff[2]); - - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum = qlp_coeff[2] * (FLAC__int64)data[i-3]; - xmm7 = _mm_cvtsi32_si128(data[i-3]); - xmm7 = _mm_mul_epi32(xmm7, xmm1); - - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm6 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm6 = _mm_shuffle_epi32(xmm6, _MM_SHUFFLE(2,0,3,1)); - xmm6 = _mm_mul_epi32(xmm6, xmm0); - xmm7 = _mm_add_epi64(xmm7, xmm6); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - } - else { /* order == 1, 2 */ - if(order == 2) { - __m128i xmm0, xmm7; - xmm0 = _mm_loadl_epi64((const __m128i*)(const void*)(qlp_coeff+0)); - xmm0 = _mm_shuffle_epi32(xmm0, _MM_SHUFFLE(3,1,2,0)); - - for(i = 0; i < (int)data_len; i++) { - //sum = 0; - //sum += qlp_coeff[1] * (FLAC__int64)data[i-2]; - //sum += qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm7 = _mm_loadl_epi64((const __m128i*)(const void*)(data+i-2)); - xmm7 = _mm_shuffle_epi32(xmm7, _MM_SHUFFLE(2,0,3,1)); - xmm7 = _mm_mul_epi32(xmm7, xmm0); - - xmm7 = _mm_add_epi64(xmm7, _mm_srli_si128(xmm7, 8)); - RESIDUAL64_RESULT(xmm7); - } - } - else { /* order == 1 */ - __m128i xmm0, xmm7; - xmm0 = _mm_cvtsi32_si128(qlp_coeff[0]); - - for(i = 0; i < (int)data_len; i++) { - //sum = qlp_coeff[0] * (FLAC__int64)data[i-1]; - xmm7 = _mm_cvtsi32_si128(data[i-1]); - xmm7 = _mm_mul_epi32(xmm7, xmm0); - RESIDUAL64_RESULT(xmm7); - } - } - } - } - } - else { /* order > 12 */ - FLAC__int64 sum; - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13]; - sum += qlp_coeff[11] * (FLAC__int64)data[i-12]; - sum += qlp_coeff[10] * (FLAC__int64)data[i-11]; - sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10]; - sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9]; - sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8]; - sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7]; - sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6]; - sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5]; - sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4]; - sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3]; - sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2]; - sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1]; - } - residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization); - } - } -} - -#endif /* defined FLAC__CPU_IA32 */ - -FLAC__SSE_TARGET("sse4.1") -void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]) -{ - int i; - FLAC__int32 sum; - const __m128i cnt = _mm_cvtsi32_si128(lp_quantization); - - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= 32); - - if(order <= 12) { - if(order > 8) { - if(order > 10) { - if(order == 12) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - q10 = _mm_cvtsi32_si128(qlp_coeff[10]); q10 = _mm_shuffle_epi32(q10, _MM_SHUFFLE(0,0,0,0)); - q11 = _mm_cvtsi32_si128(qlp_coeff[11]); q11 = _mm_shuffle_epi32(q11, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q11, _mm_loadu_si128((const __m128i*)(const void*)(data+i-12))); - mull = _mm_mullo_epi32(q10, _mm_loadu_si128((const __m128i*)(const void*)(data+i-11))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q9, _mm_loadu_si128((const __m128i*)(const void*)(data+i-10))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q8, _mm_loadu_si128((const __m128i*)(const void*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q7, _mm_loadu_si128((const __m128i*)(const void*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 11 */ - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - q10 = _mm_cvtsi32_si128(qlp_coeff[10]); q10 = _mm_shuffle_epi32(q10, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q10, _mm_loadu_si128((const __m128i*)(const void*)(data+i-11))); - mull = _mm_mullo_epi32(q9, _mm_loadu_si128((const __m128i*)(const void*)(data+i-10))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q8, _mm_loadu_si128((const __m128i*)(const void*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q7, _mm_loadu_si128((const __m128i*)(const void*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 10) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8, q9; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - q9 = _mm_cvtsi32_si128(qlp_coeff[9]); q9 = _mm_shuffle_epi32(q9, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q9, _mm_loadu_si128((const __m128i*)(const void*)(data+i-10))); - mull = _mm_mullo_epi32(q8, _mm_loadu_si128((const __m128i*)(const void*)(data+i-9))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q7, _mm_loadu_si128((const __m128i*)(const void*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 9 */ - __m128i q0, q1, q2, q3, q4, q5, q6, q7, q8; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - q8 = _mm_cvtsi32_si128(qlp_coeff[8]); q8 = _mm_shuffle_epi32(q8, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q8, _mm_loadu_si128((const __m128i*)(const void*)(data+i-9))); - mull = _mm_mullo_epi32(q7, _mm_loadu_si128((const __m128i*)(const void*)(data+i-8))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - } - else if(order > 4) { - if(order > 6) { - if(order == 8) { - __m128i q0, q1, q2, q3, q4, q5, q6, q7; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - q7 = _mm_cvtsi32_si128(qlp_coeff[7]); q7 = _mm_shuffle_epi32(q7, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q7, _mm_loadu_si128((const __m128i*)(const void*)(data+i-8))); - mull = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 7 */ - __m128i q0, q1, q2, q3, q4, q5, q6; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - q6 = _mm_cvtsi32_si128(qlp_coeff[6]); q6 = _mm_shuffle_epi32(q6, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q6, _mm_loadu_si128((const __m128i*)(const void*)(data+i-7))); - mull = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 6) { - __m128i q0, q1, q2, q3, q4, q5; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - q5 = _mm_cvtsi32_si128(qlp_coeff[5]); q5 = _mm_shuffle_epi32(q5, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q5, _mm_loadu_si128((const __m128i*)(const void*)(data+i-6))); - mull = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 5 */ - __m128i q0, q1, q2, q3, q4; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - q4 = _mm_cvtsi32_si128(qlp_coeff[4]); q4 = _mm_shuffle_epi32(q4, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q4, _mm_loadu_si128((const __m128i*)(const void*)(data+i-5))); - mull = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - } - else { - if(order > 2) { - if(order == 4) { - __m128i q0, q1, q2, q3; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - q3 = _mm_cvtsi32_si128(qlp_coeff[3]); q3 = _mm_shuffle_epi32(q3, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q3, _mm_loadu_si128((const __m128i*)(const void*)(data+i-4))); - mull = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 3 */ - __m128i q0, q1, q2; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - q2 = _mm_cvtsi32_si128(qlp_coeff[2]); q2 = _mm_shuffle_epi32(q2, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q2, _mm_loadu_si128((const __m128i*)(const void*)(data+i-3))); - mull = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); summ = _mm_add_epi32(summ, mull); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - else { - if(order == 2) { - __m128i q0, q1; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - q1 = _mm_cvtsi32_si128(qlp_coeff[1]); q1 = _mm_shuffle_epi32(q1, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ, mull; - summ = _mm_mullo_epi32(q1, _mm_loadu_si128((const __m128i*)(const void*)(data+i-2))); - mull = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); summ = _mm_add_epi32(summ, mull); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - else { /* order == 1 */ - __m128i q0; - q0 = _mm_cvtsi32_si128(qlp_coeff[0]); q0 = _mm_shuffle_epi32(q0, _MM_SHUFFLE(0,0,0,0)); - - for(i = 0; i < (int)data_len-3; i+=4) { - __m128i summ; - summ = _mm_mullo_epi32(q0, _mm_loadu_si128((const __m128i*)(const void*)(data+i-1))); - summ = _mm_sra_epi32(summ, cnt); - _mm_storeu_si128((__m128i*)(void*)(residual+i), _mm_sub_epi32(_mm_loadu_si128((const __m128i*)(const void*)(data+i)), summ)); - } - } - } - } - for(; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 12: sum += qlp_coeff[11] * data[i-12]; /* Falls through. */ - case 11: sum += qlp_coeff[10] * data[i-11]; /* Falls through. */ - case 10: sum += qlp_coeff[ 9] * data[i-10]; /* Falls through. */ - case 9: sum += qlp_coeff[ 8] * data[i- 9]; /* Falls through. */ - case 8: sum += qlp_coeff[ 7] * data[i- 8]; /* Falls through. */ - case 7: sum += qlp_coeff[ 6] * data[i- 7]; /* Falls through. */ - case 6: sum += qlp_coeff[ 5] * data[i- 6]; /* Falls through. */ - case 5: sum += qlp_coeff[ 4] * data[i- 5]; /* Falls through. */ - case 4: sum += qlp_coeff[ 3] * data[i- 4]; /* Falls through. */ - case 3: sum += qlp_coeff[ 2] * data[i- 3]; /* Falls through. */ - case 2: sum += qlp_coeff[ 1] * data[i- 2]; /* Falls through. */ - case 1: sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } - else { /* order > 12 */ - for(i = 0; i < (int)data_len; i++) { - sum = 0; - switch(order) { - case 32: sum += qlp_coeff[31] * data[i-32]; /* Falls through. */ - case 31: sum += qlp_coeff[30] * data[i-31]; /* Falls through. */ - case 30: sum += qlp_coeff[29] * data[i-30]; /* Falls through. */ - case 29: sum += qlp_coeff[28] * data[i-29]; /* Falls through. */ - case 28: sum += qlp_coeff[27] * data[i-28]; /* Falls through. */ - case 27: sum += qlp_coeff[26] * data[i-27]; /* Falls through. */ - case 26: sum += qlp_coeff[25] * data[i-26]; /* Falls through. */ - case 25: sum += qlp_coeff[24] * data[i-25]; /* Falls through. */ - case 24: sum += qlp_coeff[23] * data[i-24]; /* Falls through. */ - case 23: sum += qlp_coeff[22] * data[i-23]; /* Falls through. */ - case 22: sum += qlp_coeff[21] * data[i-22]; /* Falls through. */ - case 21: sum += qlp_coeff[20] * data[i-21]; /* Falls through. */ - case 20: sum += qlp_coeff[19] * data[i-20]; /* Falls through. */ - case 19: sum += qlp_coeff[18] * data[i-19]; /* Falls through. */ - case 18: sum += qlp_coeff[17] * data[i-18]; /* Falls through. */ - case 17: sum += qlp_coeff[16] * data[i-17]; /* Falls through. */ - case 16: sum += qlp_coeff[15] * data[i-16]; /* Falls through. */ - case 15: sum += qlp_coeff[14] * data[i-15]; /* Falls through. */ - case 14: sum += qlp_coeff[13] * data[i-14]; /* Falls through. */ - case 13: sum += qlp_coeff[12] * data[i-13]; - sum += qlp_coeff[11] * data[i-12]; - sum += qlp_coeff[10] * data[i-11]; - sum += qlp_coeff[ 9] * data[i-10]; - sum += qlp_coeff[ 8] * data[i- 9]; - sum += qlp_coeff[ 7] * data[i- 8]; - sum += qlp_coeff[ 6] * data[i- 7]; - sum += qlp_coeff[ 5] * data[i- 6]; - sum += qlp_coeff[ 4] * data[i- 5]; - sum += qlp_coeff[ 3] * data[i- 4]; - sum += qlp_coeff[ 2] * data[i- 3]; - sum += qlp_coeff[ 1] * data[i- 2]; - sum += qlp_coeff[ 0] * data[i- 1]; - } - residual[i] = data[i] - (sum >> lp_quantization); - } - } -} - -#endif /* FLAC__SSE4_1_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ -#endif /* FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/libFLAC/md5.c b/flac/src/libFLAC/md5.c deleted file mode 100644 index 09933d7..0000000 --- a/flac/src/libFLAC/md5.c +++ /dev/null @@ -1,517 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include -#endif - -#include /* for malloc() */ -#include /* for memcpy() */ - -#include "private/md5.h" -#include "share/alloc.h" -#include "share/compat.h" -#include "share/endswap.h" - -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - * - * Changed so as no longer to depend on Colin Plumb's `usual.h' header - * definitions; now uses stuff from dpkg's config.h. - * - Ian Jackson . - * Still in the public domain. - * - * Josh Coalson: made some changes to integrate with libFLAC. - * Still in the public domain. - */ - -/* The four core functions - F1 is optimized somewhat */ - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f,w,x,y,z,in,s) \ - (w += f(x,y,z) + in, w = (w<>(32-s)) + x) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. MD5Update blocks - * the data and converts bytes into longwords for this routine. - */ -static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16]) -{ - register FLAC__uint32 a, b, c, d; - - a = buf[0]; - b = buf[1]; - c = buf[2]; - d = buf[3]; - - MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); - - buf[0] += a; - buf[1] += b; - buf[2] += c; - buf[3] += d; -} - -#if WORDS_BIGENDIAN -//@@@@@@ OPT: use bswap/intrinsics -static void byteSwap(FLAC__uint32 *buf, uint32_t words) -{ - register FLAC__uint32 x; - do { - x = *buf; - x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); - *buf++ = (x >> 16) | (x << 16); - } while (--words); -} -static void byteSwapX16(FLAC__uint32 *buf) -{ - register FLAC__uint32 x; - - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16); - x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16); -} -#else -#define byteSwap(buf, words) -#define byteSwapX16(buf) -#endif - -/* - * Update context to reflect the concatenation of another buffer full - * of bytes. - */ -static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, uint32_t len) -{ - FLAC__uint32 t; - - /* Update byte count */ - - t = ctx->bytes[0]; - if ((ctx->bytes[0] = t + len) < t) - ctx->bytes[1]++; /* Carry from low to high */ - - t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */ - if (t > len) { - memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len); - return; - } - /* First chunk is an odd size */ - memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t); - byteSwapX16(ctx->in); - FLAC__MD5Transform(ctx->buf, ctx->in); - buf += t; - len -= t; - - /* Process data in 64-byte chunks */ - while (len >= 64) { - memcpy(ctx->in, buf, 64); - byteSwapX16(ctx->in); - FLAC__MD5Transform(ctx->buf, ctx->in); - buf += 64; - len -= 64; - } - - /* Handle any remaining bytes of data. */ - memcpy(ctx->in, buf, len); -} - -/* - * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious - * initialization constants. - */ -void FLAC__MD5Init(FLAC__MD5Context *ctx) -{ - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; - - ctx->bytes[0] = 0; - ctx->bytes[1] = 0; - - ctx->internal_buf.p8 = 0; - ctx->capacity = 0; -} - -/* - * Final wrapup - pad to 64-byte boundary with the bit pattern - * 1 0* (64-bit count of bits processed, MSB-first) - */ -void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx) -{ - int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */ - FLAC__byte *p = (FLAC__byte *)ctx->in + count; - - /* Set the first char of padding to 0x80. There is always room. */ - *p++ = 0x80; - - /* Bytes of padding needed to make 56 bytes (-8..55) */ - count = 56 - 1 - count; - - if (count < 0) { /* Padding forces an extra block */ - memset(p, 0, count + 8); - byteSwapX16(ctx->in); - FLAC__MD5Transform(ctx->buf, ctx->in); - p = (FLAC__byte *)ctx->in; - count = 56; - } - memset(p, 0, count); - byteSwap(ctx->in, 14); - - /* Append length in bits and transform */ - ctx->in[14] = ctx->bytes[0] << 3; - ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29; - FLAC__MD5Transform(ctx->buf, ctx->in); - - byteSwap(ctx->buf, 4); - memcpy(digest, ctx->buf, 16); - if (0 != ctx->internal_buf.p8) { - free(ctx->internal_buf.p8); - ctx->internal_buf.p8 = 0; - ctx->capacity = 0; - } - memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ -} - -/* - * Convert the incoming audio signal to a byte stream - */ -static void format_input_(FLAC__multibyte *mbuf, const FLAC__int32 * const signal[], uint32_t channels, uint32_t samples, uint32_t bytes_per_sample) -{ - FLAC__byte *buf_ = mbuf->p8; - FLAC__int16 *buf16 = mbuf->p16; - FLAC__int32 *buf32 = mbuf->p32; - FLAC__int32 a_word; - uint32_t channel, sample; - - /* Storage in the output buffer, buf, is little endian. */ - -#define BYTES_CHANNEL_SELECTOR(bytes, channels) (bytes * 100 + channels) - - /* First do the most commonly used combinations. */ - switch (BYTES_CHANNEL_SELECTOR (bytes_per_sample, channels)) { - /* One byte per sample. */ - case (BYTES_CHANNEL_SELECTOR (1, 1)): - for (sample = 0; sample < samples; sample++) - *buf_++ = signal[0][sample]; - return; - - case (BYTES_CHANNEL_SELECTOR (1, 2)): - for (sample = 0; sample < samples; sample++) { - *buf_++ = signal[0][sample]; - *buf_++ = signal[1][sample]; - } - return; - - case (BYTES_CHANNEL_SELECTOR (1, 4)): - for (sample = 0; sample < samples; sample++) { - *buf_++ = signal[0][sample]; - *buf_++ = signal[1][sample]; - *buf_++ = signal[2][sample]; - *buf_++ = signal[3][sample]; - } - return; - - case (BYTES_CHANNEL_SELECTOR (1, 6)): - for (sample = 0; sample < samples; sample++) { - *buf_++ = signal[0][sample]; - *buf_++ = signal[1][sample]; - *buf_++ = signal[2][sample]; - *buf_++ = signal[3][sample]; - *buf_++ = signal[4][sample]; - *buf_++ = signal[5][sample]; - } - return; - - case (BYTES_CHANNEL_SELECTOR (1, 8)): - for (sample = 0; sample < samples; sample++) { - *buf_++ = signal[0][sample]; - *buf_++ = signal[1][sample]; - *buf_++ = signal[2][sample]; - *buf_++ = signal[3][sample]; - *buf_++ = signal[4][sample]; - *buf_++ = signal[5][sample]; - *buf_++ = signal[6][sample]; - *buf_++ = signal[7][sample]; - } - return; - - /* Two bytes per sample. */ - case (BYTES_CHANNEL_SELECTOR (2, 1)): - for (sample = 0; sample < samples; sample++) - *buf16++ = H2LE_16(signal[0][sample]); - return; - - case (BYTES_CHANNEL_SELECTOR (2, 2)): - for (sample = 0; sample < samples; sample++) { - *buf16++ = H2LE_16(signal[0][sample]); - *buf16++ = H2LE_16(signal[1][sample]); - } - return; - - case (BYTES_CHANNEL_SELECTOR (2, 4)): - for (sample = 0; sample < samples; sample++) { - *buf16++ = H2LE_16(signal[0][sample]); - *buf16++ = H2LE_16(signal[1][sample]); - *buf16++ = H2LE_16(signal[2][sample]); - *buf16++ = H2LE_16(signal[3][sample]); - } - return; - - case (BYTES_CHANNEL_SELECTOR (2, 6)): - for (sample = 0; sample < samples; sample++) { - *buf16++ = H2LE_16(signal[0][sample]); - *buf16++ = H2LE_16(signal[1][sample]); - *buf16++ = H2LE_16(signal[2][sample]); - *buf16++ = H2LE_16(signal[3][sample]); - *buf16++ = H2LE_16(signal[4][sample]); - *buf16++ = H2LE_16(signal[5][sample]); - } - return; - - case (BYTES_CHANNEL_SELECTOR (2, 8)): - for (sample = 0; sample < samples; sample++) { - *buf16++ = H2LE_16(signal[0][sample]); - *buf16++ = H2LE_16(signal[1][sample]); - *buf16++ = H2LE_16(signal[2][sample]); - *buf16++ = H2LE_16(signal[3][sample]); - *buf16++ = H2LE_16(signal[4][sample]); - *buf16++ = H2LE_16(signal[5][sample]); - *buf16++ = H2LE_16(signal[6][sample]); - *buf16++ = H2LE_16(signal[7][sample]); - } - return; - - /* Three bytes per sample. */ - case (BYTES_CHANNEL_SELECTOR (3, 1)): - for (sample = 0; sample < samples; sample++) { - a_word = signal[0][sample]; - *buf_++ = (FLAC__byte)a_word; a_word >>= 8; - *buf_++ = (FLAC__byte)a_word; a_word >>= 8; - *buf_++ = (FLAC__byte)a_word; - } - return; - - case (BYTES_CHANNEL_SELECTOR (3, 2)): - for (sample = 0; sample < samples; sample++) { - a_word = signal[0][sample]; - *buf_++ = (FLAC__byte)a_word; a_word >>= 8; - *buf_++ = (FLAC__byte)a_word; a_word >>= 8; - *buf_++ = (FLAC__byte)a_word; - a_word = signal[1][sample]; - *buf_++ = (FLAC__byte)a_word; a_word >>= 8; - *buf_++ = (FLAC__byte)a_word; a_word >>= 8; - *buf_++ = (FLAC__byte)a_word; - } - return; - - /* Four bytes per sample. */ - case (BYTES_CHANNEL_SELECTOR (4, 1)): - for (sample = 0; sample < samples; sample++) - *buf32++ = H2LE_32(signal[0][sample]); - return; - - case (BYTES_CHANNEL_SELECTOR (4, 2)): - for (sample = 0; sample < samples; sample++) { - *buf32++ = H2LE_32(signal[0][sample]); - *buf32++ = H2LE_32(signal[1][sample]); - } - return; - - case (BYTES_CHANNEL_SELECTOR (4, 4)): - for (sample = 0; sample < samples; sample++) { - *buf32++ = H2LE_32(signal[0][sample]); - *buf32++ = H2LE_32(signal[1][sample]); - *buf32++ = H2LE_32(signal[2][sample]); - *buf32++ = H2LE_32(signal[3][sample]); - } - return; - - case (BYTES_CHANNEL_SELECTOR (4, 6)): - for (sample = 0; sample < samples; sample++) { - *buf32++ = H2LE_32(signal[0][sample]); - *buf32++ = H2LE_32(signal[1][sample]); - *buf32++ = H2LE_32(signal[2][sample]); - *buf32++ = H2LE_32(signal[3][sample]); - *buf32++ = H2LE_32(signal[4][sample]); - *buf32++ = H2LE_32(signal[5][sample]); - } - return; - - case (BYTES_CHANNEL_SELECTOR (4, 8)): - for (sample = 0; sample < samples; sample++) { - *buf32++ = H2LE_32(signal[0][sample]); - *buf32++ = H2LE_32(signal[1][sample]); - *buf32++ = H2LE_32(signal[2][sample]); - *buf32++ = H2LE_32(signal[3][sample]); - *buf32++ = H2LE_32(signal[4][sample]); - *buf32++ = H2LE_32(signal[5][sample]); - *buf32++ = H2LE_32(signal[6][sample]); - *buf32++ = H2LE_32(signal[7][sample]); - } - return; - - default: - break; - } - - /* General version. */ - switch (bytes_per_sample) { - case 1: - for (sample = 0; sample < samples; sample++) - for (channel = 0; channel < channels; channel++) - *buf_++ = signal[channel][sample]; - return; - - case 2: - for (sample = 0; sample < samples; sample++) - for (channel = 0; channel < channels; channel++) - *buf16++ = H2LE_16(signal[channel][sample]); - return; - - case 3: - for (sample = 0; sample < samples; sample++) - for (channel = 0; channel < channels; channel++) { - a_word = signal[channel][sample]; - *buf_++ = (FLAC__byte)a_word; a_word >>= 8; - *buf_++ = (FLAC__byte)a_word; a_word >>= 8; - *buf_++ = (FLAC__byte)a_word; - } - return; - - case 4: - for (sample = 0; sample < samples; sample++) - for (channel = 0; channel < channels; channel++) - *buf32++ = H2LE_32(signal[channel][sample]); - return; - - default: - break; - } -} - -/* - * Convert the incoming audio signal to a byte stream and FLAC__MD5Update it. - */ -FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], uint32_t channels, uint32_t samples, uint32_t bytes_per_sample) -{ - const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample; - - /* overflow check */ - if ((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample) - return false; - if ((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples) - return false; - - if (ctx->capacity < bytes_needed) { - if (0 == (ctx->internal_buf.p8 = safe_realloc_(ctx->internal_buf.p8, bytes_needed))) { - if (0 == (ctx->internal_buf.p8 = safe_malloc_(bytes_needed))) { - ctx->capacity = 0; - return false; - } - } - ctx->capacity = bytes_needed; - } - - format_input_(&ctx->internal_buf, signal, channels, samples, bytes_per_sample); - - FLAC__MD5Update(ctx, ctx->internal_buf.p8, bytes_needed); - - return true; -} diff --git a/flac/src/libFLAC/memory.c b/flac/src/libFLAC/memory.c deleted file mode 100644 index ad5371e..0000000 --- a/flac/src/libFLAC/memory.c +++ /dev/null @@ -1,219 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#ifdef HAVE_STDINT_H -#include -#endif - -#include "private/memory.h" -#include "FLAC/assert.h" -#include "share/compat.h" -#include "share/alloc.h" - -void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address) -{ - void *x; - - FLAC__ASSERT(0 != aligned_address); - -#ifdef FLAC__ALIGN_MALLOC_DATA - /* align on 32-byte (256-bit) boundary */ - x = safe_malloc_add_2op_(bytes, /*+*/31L); - *aligned_address = (void*)(((uintptr_t)x + 31L) & -32L); -#else - x = safe_malloc_(bytes); - *aligned_address = x; -#endif - return x; -} - -FLAC__bool FLAC__memory_alloc_aligned_int32_array(size_t elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer) -{ - FLAC__int32 *pu; /* unaligned pointer */ - union { /* union needed to comply with C99 pointer aliasing rules */ - FLAC__int32 *pa; /* aligned pointer */ - void *pv; /* aligned pointer alias */ - } u; - - FLAC__ASSERT(elements > 0); - FLAC__ASSERT(0 != unaligned_pointer); - FLAC__ASSERT(0 != aligned_pointer); - FLAC__ASSERT(unaligned_pointer != aligned_pointer); - - if(elements > SIZE_MAX / sizeof(*pu)) /* overflow check */ - return false; - - pu = FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); - if(0 == pu) { - return false; - } - else { - if(*unaligned_pointer != 0) - free(*unaligned_pointer); - *unaligned_pointer = pu; - *aligned_pointer = u.pa; - return true; - } -} - -FLAC__bool FLAC__memory_alloc_aligned_uint32_array(size_t elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer) -{ - FLAC__uint32 *pu; /* unaligned pointer */ - union { /* union needed to comply with C99 pointer aliasing rules */ - FLAC__uint32 *pa; /* aligned pointer */ - void *pv; /* aligned pointer alias */ - } u; - - FLAC__ASSERT(elements > 0); - FLAC__ASSERT(0 != unaligned_pointer); - FLAC__ASSERT(0 != aligned_pointer); - FLAC__ASSERT(unaligned_pointer != aligned_pointer); - - if(elements > SIZE_MAX / sizeof(*pu)) /* overflow check */ - return false; - - pu = FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); - if(0 == pu) { - return false; - } - else { - if(*unaligned_pointer != 0) - free(*unaligned_pointer); - *unaligned_pointer = pu; - *aligned_pointer = u.pa; - return true; - } -} - -FLAC__bool FLAC__memory_alloc_aligned_int64_array(size_t elements, FLAC__int64 **unaligned_pointer, FLAC__int64 **aligned_pointer) -{ - FLAC__int64 *pu; /* unaligned pointer */ - union { /* union needed to comply with C99 pointer aliasing rules */ - FLAC__int64 *pa; /* aligned pointer */ - void *pv; /* aligned pointer alias */ - } u; - - FLAC__ASSERT(elements > 0); - FLAC__ASSERT(0 != unaligned_pointer); - FLAC__ASSERT(0 != aligned_pointer); - FLAC__ASSERT(unaligned_pointer != aligned_pointer); - - if(elements > SIZE_MAX / sizeof(*pu)) /* overflow check */ - return false; - - pu = FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); - if(0 == pu) { - return false; - } - else { - if(*unaligned_pointer != 0) - free(*unaligned_pointer); - *unaligned_pointer = pu; - *aligned_pointer = u.pa; - return true; - } -} - -FLAC__bool FLAC__memory_alloc_aligned_uint64_array(size_t elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer) -{ - FLAC__uint64 *pu; /* unaligned pointer */ - union { /* union needed to comply with C99 pointer aliasing rules */ - FLAC__uint64 *pa; /* aligned pointer */ - void *pv; /* aligned pointer alias */ - } u; - - FLAC__ASSERT(elements > 0); - FLAC__ASSERT(0 != unaligned_pointer); - FLAC__ASSERT(0 != aligned_pointer); - FLAC__ASSERT(unaligned_pointer != aligned_pointer); - - if(elements > SIZE_MAX / sizeof(*pu)) /* overflow check */ - return false; - - pu = FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); - if(0 == pu) { - return false; - } - else { - if(*unaligned_pointer != 0) - free(*unaligned_pointer); - *unaligned_pointer = pu; - *aligned_pointer = u.pa; - return true; - } -} - -#ifndef FLAC__INTEGER_ONLY_LIBRARY - -FLAC__bool FLAC__memory_alloc_aligned_real_array(size_t elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer) -{ - FLAC__real *pu; /* unaligned pointer */ - union { /* union needed to comply with C99 pointer aliasing rules */ - FLAC__real *pa; /* aligned pointer */ - void *pv; /* aligned pointer alias */ - } u; - - FLAC__ASSERT(elements > 0); - FLAC__ASSERT(0 != unaligned_pointer); - FLAC__ASSERT(0 != aligned_pointer); - FLAC__ASSERT(unaligned_pointer != aligned_pointer); - - if(elements > SIZE_MAX / sizeof(*pu)) /* overflow check */ - return false; - - pu = FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv); - if(0 == pu) { - return false; - } - else { - if(*unaligned_pointer != 0) - free(*unaligned_pointer); - *unaligned_pointer = pu; - *aligned_pointer = u.pa; - return true; - } -} - -#endif - -void *safe_malloc_mul_2op_p(size_t size1, size_t size2) -{ - if(!size1 || !size2) - return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */ - if(size1 > SIZE_MAX / size2) - return 0; - return malloc(size1*size2); -} diff --git a/flac/src/libFLAC/metadata_iterators.c b/flac/src/libFLAC/metadata_iterators.c deleted file mode 100644 index 20e926b..0000000 --- a/flac/src/libFLAC/metadata_iterators.c +++ /dev/null @@ -1,3554 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include - -#include /* for stat(), maybe chmod() */ - -#include "private/metadata.h" - -#include "FLAC/assert.h" -#include "FLAC/stream_decoder.h" -#include "share/alloc.h" -#include "share/compat.h" -#include "share/macros.h" -#include "private/macros.h" -#include "private/memory.h" - -/* Alias the first (in share/alloc.h) to the second (in src/libFLAC/memory.c). */ -#define safe_malloc_mul_2op_ safe_malloc_mul_2op_p - -/**************************************************************************** - * - * Local function declarations - * - ***************************************************************************/ - -static void pack_uint32_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes); -static void pack_uint32_little_endian_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes); -static void pack_uint64_(FLAC__uint64 val, FLAC__byte *b, uint32_t bytes); -static FLAC__uint32 unpack_uint32_(FLAC__byte *b, uint32_t bytes); -static FLAC__uint32 unpack_uint32_little_endian_(FLAC__byte *b, uint32_t bytes); -static FLAC__uint64 unpack_uint64_(FLAC__byte *b, uint32_t bytes); - -static FLAC__bool read_metadata_block_header_(FLAC__Metadata_SimpleIterator *iterator); -static FLAC__bool read_metadata_block_data_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block); -static FLAC__bool read_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__bool *is_last, FLAC__MetadataType *type, uint32_t *length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata *block); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_StreamInfo *block); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_Padding *block, uint32_t block_length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Application *block, uint32_t block_length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_SeekTable *block, uint32_t block_length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_VorbisComment_Entry *entry, uint32_t max_length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_VorbisComment *block, uint32_t block_length); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet_Track *track); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet *block); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Picture *block); -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Unknown *block, uint32_t block_length); - -static FLAC__bool write_metadata_block_header_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block); -static FLAC__bool write_metadata_block_data_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block); -static FLAC__bool write_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block); -static FLAC__bool write_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block); -static FLAC__bool write_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_StreamInfo *block); -static FLAC__bool write_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Padding *block, uint32_t block_length); -static FLAC__bool write_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Application *block, uint32_t block_length); -static FLAC__bool write_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_SeekTable *block); -static FLAC__bool write_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_VorbisComment *block); -static FLAC__bool write_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_CueSheet *block); -static FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Picture *block); -static FLAC__bool write_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Unknown *block, uint32_t block_length); - -static FLAC__bool write_metadata_block_stationary_(FLAC__Metadata_SimpleIterator *iterator, const FLAC__StreamMetadata *block); -static FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, uint32_t padding_length, FLAC__bool padding_is_last); -static FLAC__bool rewrite_whole_file_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool append); - -static void simple_iterator_push_(FLAC__Metadata_SimpleIterator *iterator); -static FLAC__bool simple_iterator_pop_(FLAC__Metadata_SimpleIterator *iterator); - -static uint32_t seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb); -static uint32_t seek_to_first_metadata_block_(FILE *f); - -static FLAC__bool simple_iterator_copy_file_prefix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, FLAC__bool append); -static FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, FLAC__off_t fixup_is_last_flag_offset, FLAC__bool backup); - -static FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status); -static FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status); -static FLAC__bool copy_remaining_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__Metadata_SimpleIteratorStatus *status); -static FLAC__bool copy_remaining_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__Metadata_SimpleIteratorStatus *status); - -static FLAC__bool open_tempfile_(const char *filename, const char *tempfile_path_prefix, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status); -static FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status); -static void cleanup_tempfile_(FILE **tempfile, char **tempfilename); - -static FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stats); -static void set_file_stats_(const char *filename, struct flac_stat_s *stats); - -static int fseek_wrapper_(FLAC__IOHandle handle, FLAC__int64 offset, int whence); -static FLAC__int64 ftell_wrapper_(FLAC__IOHandle handle); - -static FLAC__Metadata_ChainStatus get_equivalent_status_(FLAC__Metadata_SimpleIteratorStatus status); - - -#ifdef FLAC__VALGRIND_TESTING -static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) -{ - size_t ret = fwrite(ptr, size, nmemb, stream); - if(!ferror(stream)) - fflush(stream); - return ret; -} -#else -#define local__fwrite fwrite -#endif - -/**************************************************************************** - * - * Level 0 implementation - * - ***************************************************************************/ - -static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); -static void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); -static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); - -typedef struct { - FLAC__bool got_error; - FLAC__StreamMetadata *object; -} level0_client_data; - -static FLAC__StreamMetadata *get_one_metadata_block_(const char *filename, FLAC__MetadataType type) -{ - level0_client_data cd; - FLAC__StreamDecoder *decoder; - - FLAC__ASSERT(0 != filename); - - cd.got_error = false; - cd.object = 0; - - decoder = FLAC__stream_decoder_new(); - - if(0 == decoder) - return 0; - - FLAC__stream_decoder_set_md5_checking(decoder, false); - FLAC__stream_decoder_set_metadata_ignore_all(decoder); - FLAC__stream_decoder_set_metadata_respond(decoder, type); - - if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) { - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - return 0; - } - - if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder) || cd.got_error) { - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - if(0 != cd.object) - FLAC__metadata_object_delete(cd.object); - return 0; - } - - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - - return cd.object; -} - -FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo) -{ - FLAC__StreamMetadata *object; - - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != streaminfo); - - object = get_one_metadata_block_(filename, FLAC__METADATA_TYPE_STREAMINFO); - - if (object) { - /* can just copy the contents since STREAMINFO has no internal structure */ - *streaminfo = *object; - FLAC__metadata_object_delete(object); - return true; - } - else { - return false; - } -} - -FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != tags); - - *tags = get_one_metadata_block_(filename, FLAC__METADATA_TYPE_VORBIS_COMMENT); - - return 0 != *tags; -} - -FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != cuesheet); - - *cuesheet = get_one_metadata_block_(filename, FLAC__METADATA_TYPE_CUESHEET); - - return 0 != *cuesheet; -} - -FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - (void)decoder, (void)frame, (void)buffer, (void)client_data; - - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - level0_client_data *cd = (level0_client_data *)client_data; - (void)decoder; - - /* - * we assume we only get here when the one metadata block we were - * looking for was passed to us - */ - if(!cd->got_error && 0 == cd->object) { - if(0 == (cd->object = FLAC__metadata_object_clone(metadata))) - cd->got_error = true; - } -} - -void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - level0_client_data *cd = (level0_client_data *)client_data; - (void)decoder; - - if(status != FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC) - cd->got_error = true; -} - -FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors) -{ - FLAC__Metadata_SimpleIterator *it; - FLAC__uint64 max_area_seen = 0; - FLAC__uint64 max_depth_seen = 0; - - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != picture); - - *picture = 0; - - it = FLAC__metadata_simple_iterator_new(); - if(0 == it) - return false; - if(!FLAC__metadata_simple_iterator_init(it, filename, /*read_only=*/true, /*preserve_file_stats=*/true)) { - FLAC__metadata_simple_iterator_delete(it); - return false; - } - do { - if(FLAC__metadata_simple_iterator_get_block_type(it) == FLAC__METADATA_TYPE_PICTURE) { - FLAC__StreamMetadata *obj = FLAC__metadata_simple_iterator_get_block(it); - if(0 != obj) { - FLAC__uint64 area = (FLAC__uint64)obj->data.picture.width * (FLAC__uint64)obj->data.picture.height; - - /* check constraints */ - if( - (type == (FLAC__StreamMetadata_Picture_Type)(-1) || type == obj->data.picture.type) && - (mime_type == 0 || !strcmp(mime_type, obj->data.picture.mime_type)) && - (description == 0 || !strcmp((const char *)description, (const char *)obj->data.picture.description)) && - obj->data.picture.width <= max_width && - obj->data.picture.height <= max_height && - obj->data.picture.depth <= max_depth && - obj->data.picture.colors <= max_colors && - (area > max_area_seen || (area == max_area_seen && obj->data.picture.depth > max_depth_seen)) - ) { - if(*picture) - FLAC__metadata_object_delete(*picture); - *picture = obj; - max_area_seen = area; - max_depth_seen = obj->data.picture.depth; - } - else { - FLAC__metadata_object_delete(obj); - } - } - else - break; - } - } while(FLAC__metadata_simple_iterator_next(it)); - - FLAC__metadata_simple_iterator_delete(it); - - return (0 != *picture); -} - - -/**************************************************************************** - * - * Level 1 implementation - * - ***************************************************************************/ - -#define SIMPLE_ITERATOR_MAX_PUSH_DEPTH (1+4) -/* 1 for initial offset, +4 for our own personal use */ - -struct FLAC__Metadata_SimpleIterator { - FILE *file; - char *filename, *tempfile_path_prefix; - struct flac_stat_s stats; - FLAC__bool has_stats; - FLAC__bool is_writable; - FLAC__Metadata_SimpleIteratorStatus status; - FLAC__off_t offset[SIMPLE_ITERATOR_MAX_PUSH_DEPTH]; - FLAC__off_t first_offset; /* this is the offset to the STREAMINFO block */ - uint32_t depth; - /* this is the metadata block header of the current block we are pointing to: */ - FLAC__bool is_last; - FLAC__MetadataType type; - uint32_t length; -}; - -FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[] = { - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR", - "FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR" -}; - - -FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void) -{ - FLAC__Metadata_SimpleIterator *iterator = calloc(1, sizeof(FLAC__Metadata_SimpleIterator)); - - if(0 != iterator) { - iterator->file = 0; - iterator->filename = 0; - iterator->tempfile_path_prefix = 0; - iterator->has_stats = false; - iterator->is_writable = false; - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; - iterator->first_offset = iterator->offset[0] = -1; - iterator->depth = 0; - } - - return iterator; -} - -static void simple_iterator_free_guts_(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - - if(0 != iterator->file) { - fclose(iterator->file); - iterator->file = 0; - if(iterator->has_stats) - set_file_stats_(iterator->filename, &iterator->stats); - } - if(0 != iterator->filename) { - free(iterator->filename); - iterator->filename = 0; - } - if(0 != iterator->tempfile_path_prefix) { - free(iterator->tempfile_path_prefix); - iterator->tempfile_path_prefix = 0; - } -} - -FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - - simple_iterator_free_guts_(iterator); - free(iterator); -} - -FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__Metadata_SimpleIteratorStatus status; - - FLAC__ASSERT(0 != iterator); - - status = iterator->status; - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; - return status; -} - -static FLAC__bool simple_iterator_prime_input_(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool read_only) -{ - uint32_t ret; - - FLAC__ASSERT(0 != iterator); - - if(read_only || 0 == (iterator->file = flac_fopen(iterator->filename, "r+b"))) { - iterator->is_writable = false; - if(read_only || errno == EACCES) { - if(0 == (iterator->file = flac_fopen(iterator->filename, "rb"))) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE; - return false; - } - } - else { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE; - return false; - } - } - else { - iterator->is_writable = true; - } - - ret = seek_to_first_metadata_block_(iterator->file); - switch(ret) { - case 0: - iterator->depth = 0; - iterator->first_offset = iterator->offset[iterator->depth] = ftello(iterator->file); - ret = read_metadata_block_header_(iterator); - /* The first metadata block must be a streaminfo. If this is not the - * case, the file is invalid and assumptions made elsewhere in the - * code are invalid */ - if(iterator->type != FLAC__METADATA_TYPE_STREAMINFO) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA; - return false; - } - return ret; - case 1: - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - case 2: - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - case 3: - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE; - return false; - default: - FLAC__ASSERT(0); - return false; - } -} - -#if 0 -@@@ If we decide to finish implementing this, put this comment back in metadata.h -/* - * The 'tempfile_path_prefix' allows you to specify a directory where - * tempfiles should go. Remember that if your metadata edits cause the - * FLAC file to grow, the entire file will have to be rewritten. If - * 'tempfile_path_prefix' is NULL, the temp file will be written in the - * same directory as the original FLAC file. This makes replacing the - * original with the tempfile fast but requires extra space in the same - * partition for the tempfile. If space is a problem, you can pass a - * directory name belonging to a different partition in - * 'tempfile_path_prefix'. Note that you should use the forward slash - * '/' as the directory separator. A trailing slash is not needed; it - * will be added automatically. - */ -FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool preserve_file_stats, const char *tempfile_path_prefix); -#endif - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool read_only, FLAC__bool preserve_file_stats) -{ - const char *tempfile_path_prefix = 0; /*@@@ search for comments near 'flac_rename(...)' for what it will take to finish implementing this */ - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != filename); - - simple_iterator_free_guts_(iterator); - - if(!read_only && preserve_file_stats) - iterator->has_stats = get_file_stats_(filename, &iterator->stats); - - if(0 == (iterator->filename = strdup(filename))) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - if(0 != tempfile_path_prefix && 0 == (iterator->tempfile_path_prefix = strdup(tempfile_path_prefix))) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - - return simple_iterator_prime_input_(iterator, read_only); -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - return iterator->is_writable; -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - if(iterator->is_last) - return false; - - if(0 != fseeko(iterator->file, iterator->length, SEEK_CUR)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - iterator->offset[iterator->depth] = ftello(iterator->file); - - return read_metadata_block_header_(iterator); -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__off_t this_offset; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - if(iterator->offset[iterator->depth] == iterator->first_offset) - return false; - - if(0 != fseeko(iterator->file, iterator->first_offset, SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - this_offset = iterator->first_offset; - if(!read_metadata_block_header_(iterator)) - return false; - - /* we ignore any error from ftello() and catch it in fseeko() */ - while(ftello(iterator->file) + (FLAC__off_t)iterator->length < iterator->offset[iterator->depth]) { - if(0 != fseeko(iterator->file, iterator->length, SEEK_CUR)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - this_offset = ftello(iterator->file); - if(!read_metadata_block_header_(iterator)) - return false; - } - - iterator->offset[iterator->depth] = this_offset; - - return true; -} - -/*@@@@add to tests*/ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - return iterator->is_last; -} - -/*@@@@add to tests*/ -FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - return (off_t)iterator->offset[iterator->depth]; -} - -FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - return iterator->type; -} - -/*@@@@add to tests*/ -FLAC_API uint32_t FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - return iterator->length; -} - -/*@@@@add to tests*/ -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id) -{ - const uint32_t id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(0 != id); - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - if(iterator->type != FLAC__METADATA_TYPE_APPLICATION) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT; - return false; - } - - if(fread(id, 1, id_bytes, iterator->file) != id_bytes) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - - /* back up */ - if(0 != fseeko(iterator->file, -((int)id_bytes), SEEK_CUR)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - return true; -} - -FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__StreamMetadata *block = FLAC__metadata_object_new(iterator->type); - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - if(0 != block) { - block->is_last = iterator->is_last; - block->length = iterator->length; - - if(!read_metadata_block_data_(iterator, block)) { - FLAC__metadata_object_delete(block); - return 0; - } - - /* back up to the beginning of the block data to stay consistent */ - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth] + FLAC__STREAM_METADATA_HEADER_LENGTH, SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - FLAC__metadata_object_delete(block); - return 0; - } - } - else - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - return block; -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding) -{ - FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth];) - FLAC__bool ret; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(0 != block); - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - if(!iterator->is_writable) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE; - return false; - } - - if(iterator->type == FLAC__METADATA_TYPE_STREAMINFO || block->type == FLAC__METADATA_TYPE_STREAMINFO) { - if(iterator->type != block->type) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT; - return false; - } - } - - block->is_last = iterator->is_last; - - if(iterator->length == block->length) - return write_metadata_block_stationary_(iterator, block); - else if(iterator->length > block->length) { - if(use_padding && iterator->length >= FLAC__STREAM_METADATA_HEADER_LENGTH + block->length) { - ret = write_metadata_block_stationary_with_padding_(iterator, block, iterator->length - FLAC__STREAM_METADATA_HEADER_LENGTH - block->length, block->is_last); - FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - else { - if((ret = rewrite_whole_file_(iterator, block, /*append=*/false))) { - FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - } - return ret; - } - } - else /* iterator->length < block->length */ { - uint32_t padding_leftover = 0; - FLAC__bool padding_is_last = false; - if(use_padding) { - /* first see if we can even use padding */ - if(iterator->is_last) { - use_padding = false; - } - else { - const uint32_t extra_padding_bytes_required = block->length - iterator->length; - simple_iterator_push_(iterator); - if(!FLAC__metadata_simple_iterator_next(iterator)) { - (void)simple_iterator_pop_(iterator); - return false; - } - if(iterator->type != FLAC__METADATA_TYPE_PADDING) { - use_padding = false; - } - else { - if(FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length == extra_padding_bytes_required) { - padding_leftover = 0; - block->is_last = iterator->is_last; - } - else if(iterator->length < extra_padding_bytes_required) - use_padding = false; - else { - padding_leftover = FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length - extra_padding_bytes_required; - padding_is_last = iterator->is_last; - block->is_last = false; - } - } - if(!simple_iterator_pop_(iterator)) - return false; - } - } - if(use_padding) { - if(padding_leftover == 0) { - ret = write_metadata_block_stationary_(iterator, block); - FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - else { - FLAC__ASSERT(padding_leftover >= FLAC__STREAM_METADATA_HEADER_LENGTH); - ret = write_metadata_block_stationary_with_padding_(iterator, block, padding_leftover - FLAC__STREAM_METADATA_HEADER_LENGTH, padding_is_last); - FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - } - else { - if((ret = rewrite_whole_file_(iterator, block, /*append=*/false))) { - FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - } - return ret; - } - } -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding) -{ - uint32_t padding_leftover = 0; - FLAC__bool padding_is_last = false; - - FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth] + FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length;) - FLAC__bool ret; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - FLAC__ASSERT(0 != block); - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - if(!iterator->is_writable) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE; - return false; - } - - if(block->type == FLAC__METADATA_TYPE_STREAMINFO) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT; - return false; - } - - block->is_last = iterator->is_last; - - if(use_padding) { - /* first see if we can even use padding */ - if(iterator->is_last) { - use_padding = false; - } - else { - simple_iterator_push_(iterator); - if(!FLAC__metadata_simple_iterator_next(iterator)) { - (void)simple_iterator_pop_(iterator); - return false; - } - if(iterator->type != FLAC__METADATA_TYPE_PADDING) { - use_padding = false; - } - else { - if(iterator->length == block->length) { - padding_leftover = 0; - block->is_last = iterator->is_last; - } - else if(iterator->length < FLAC__STREAM_METADATA_HEADER_LENGTH + block->length) - use_padding = false; - else { - padding_leftover = iterator->length - block->length; - padding_is_last = iterator->is_last; - block->is_last = false; - } - } - if(!simple_iterator_pop_(iterator)) - return false; - } - } - if(use_padding) { - /* move to the next block, which is suitable padding */ - if(!FLAC__metadata_simple_iterator_next(iterator)) - return false; - if(padding_leftover == 0) { - ret = write_metadata_block_stationary_(iterator, block); - FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - else { - FLAC__ASSERT(padding_leftover >= FLAC__STREAM_METADATA_HEADER_LENGTH); - ret = write_metadata_block_stationary_with_padding_(iterator, block, padding_leftover - FLAC__STREAM_METADATA_HEADER_LENGTH, padding_is_last); - FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - return ret; - } - } - else { - if((ret = rewrite_whole_file_(iterator, block, /*append=*/true))) { - FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset); - FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - } - return ret; - } -} - -FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding) -{ - FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth];) - FLAC__bool ret; - - FLAC__ASSERT(iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); - - if(!iterator->is_writable) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE; - return false; - } - - if(iterator->type == FLAC__METADATA_TYPE_STREAMINFO) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT; - return false; - } - - if(use_padding) { - FLAC__StreamMetadata *padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING); - if(0 == padding) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - padding->length = iterator->length; - if(!FLAC__metadata_simple_iterator_set_block(iterator, padding, false)) { - FLAC__metadata_object_delete(padding); - return false; - } - FLAC__metadata_object_delete(padding); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return false; - FLAC__ASSERT(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length == debug_target_offset); - FLAC__ASSERT(ftello(iterator->file) + (FLAC__off_t)iterator->length == debug_target_offset); - return true; - } - else { - if((ret = rewrite_whole_file_(iterator, 0, /*append=*/false))) { - FLAC__ASSERT(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length == debug_target_offset); - FLAC__ASSERT(ftello(iterator->file) + (FLAC__off_t)iterator->length == debug_target_offset); - } - return ret; - } -} - - - -/**************************************************************************** - * - * Level 2 implementation - * - ***************************************************************************/ - - -typedef struct FLAC__Metadata_Node { - FLAC__StreamMetadata *data; - struct FLAC__Metadata_Node *prev, *next; -} FLAC__Metadata_Node; - -struct FLAC__Metadata_Chain { - char *filename; /* will be NULL if using callbacks */ - FLAC__bool is_ogg; - FLAC__Metadata_Node *head; - FLAC__Metadata_Node *tail; - uint32_t nodes; - FLAC__Metadata_ChainStatus status; - FLAC__off_t first_offset, last_offset; - /* - * This is the length of the chain initially read from the FLAC file. - * it is used to compare against the current length to decide whether - * or not the whole file has to be rewritten. - */ - FLAC__off_t initial_length; - /* @@@ hacky, these are currently only needed by ogg reader */ - FLAC__IOHandle handle; - FLAC__IOCallback_Read read_cb; -}; - -struct FLAC__Metadata_Iterator { - FLAC__Metadata_Chain *chain; - FLAC__Metadata_Node *current; -}; - -FLAC_API const char * const FLAC__Metadata_ChainStatusString[] = { - "FLAC__METADATA_CHAIN_STATUS_OK", - "FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT", - "FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE", - "FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE", - "FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE", - "FLAC__METADATA_CHAIN_STATUS_BAD_METADATA", - "FLAC__METADATA_CHAIN_STATUS_READ_ERROR", - "FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR", - "FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR", - "FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR", - "FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR", - "FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR", - "FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR", - "FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS", - "FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", - "FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL" -}; - - -static FLAC__Metadata_Node *node_new_(void) -{ - return calloc(1, sizeof(FLAC__Metadata_Node)); -} - -static void node_delete_(FLAC__Metadata_Node *node) -{ - FLAC__ASSERT(0 != node); - if(0 != node->data) - FLAC__metadata_object_delete(node->data); - free(node); -} - -static void chain_init_(FLAC__Metadata_Chain *chain) -{ - FLAC__ASSERT(0 != chain); - - chain->filename = 0; - chain->is_ogg = false; - chain->head = chain->tail = 0; - chain->nodes = 0; - chain->status = FLAC__METADATA_CHAIN_STATUS_OK; - chain->initial_length = 0; - chain->read_cb = 0; -} - -static void chain_clear_(FLAC__Metadata_Chain *chain) -{ - FLAC__Metadata_Node *node, *next; - - FLAC__ASSERT(0 != chain); - - for(node = chain->head; node; ) { - next = node->next; - node_delete_(node); - node = next; - } - - if(0 != chain->filename) - free(chain->filename); - - chain_init_(chain); -} - -static void chain_append_node_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node) -{ - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != node); - FLAC__ASSERT(0 != node->data); - - node->next = node->prev = 0; - node->data->is_last = true; - if(0 != chain->tail) - chain->tail->data->is_last = false; - - if(0 == chain->head) - chain->head = node; - else { - FLAC__ASSERT(0 != chain->tail); - chain->tail->next = node; - node->prev = chain->tail; - } - chain->tail = node; - chain->nodes++; -} - -static void chain_remove_node_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node) -{ - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != node); - - if(node == chain->head) - chain->head = node->next; - else - node->prev->next = node->next; - - if(node == chain->tail) - chain->tail = node->prev; - else - node->next->prev = node->prev; - - if(0 != chain->tail) - chain->tail->data->is_last = true; - - chain->nodes--; -} - -static void chain_delete_node_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node) -{ - chain_remove_node_(chain, node); - node_delete_(node); -} - -static FLAC__off_t chain_calculate_length_(FLAC__Metadata_Chain *chain) -{ - const FLAC__Metadata_Node *node; - FLAC__off_t length = 0; - for(node = chain->head; node; node = node->next) - length += (FLAC__STREAM_METADATA_HEADER_LENGTH + node->data->length); - return length; -} - -static void iterator_insert_node_(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Node *node) -{ - FLAC__ASSERT(0 != node); - FLAC__ASSERT(0 != node->data); - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - FLAC__ASSERT(0 != iterator->chain); - FLAC__ASSERT(0 != iterator->chain->head); - FLAC__ASSERT(0 != iterator->chain->tail); - - node->data->is_last = false; - - node->prev = iterator->current->prev; - node->next = iterator->current; - - if(0 == node->prev) - iterator->chain->head = node; - else - node->prev->next = node; - - iterator->current->prev = node; - - iterator->chain->nodes++; -} - -static void iterator_insert_node_after_(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Node *node) -{ - FLAC__ASSERT(0 != node); - FLAC__ASSERT(0 != node->data); - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - FLAC__ASSERT(0 != iterator->chain); - FLAC__ASSERT(0 != iterator->chain->head); - FLAC__ASSERT(0 != iterator->chain->tail); - - iterator->current->data->is_last = false; - - node->prev = iterator->current; - node->next = iterator->current->next; - - if(0 == node->next) - iterator->chain->tail = node; - else - node->next->prev = node; - - node->prev->next = node; - - iterator->chain->tail->data->is_last = true; - - iterator->chain->nodes++; -} - -/* return true iff node and node->next are both padding */ -static FLAC__bool chain_merge_adjacent_padding_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node) -{ - if(node->data->type == FLAC__METADATA_TYPE_PADDING && 0 != node->next && node->next->data->type == FLAC__METADATA_TYPE_PADDING) { - const uint32_t growth = FLAC__STREAM_METADATA_HEADER_LENGTH + node->next->data->length; - node->data->length += growth; /* new block size can be greater than max metadata block size, but it'll be fixed later in chain_prepare_for_write_() */ - - chain_delete_node_(chain, node->next); - return true; - } - else - return false; -} - -#if defined(_MSC_VER) -// silence three MSVC warnings 'conversion from 'conversion from 'const __int64' to 'uint32_t', possible loss of data' -#pragma warning ( disable : 4244 ) -#endif - -/* Returns the new length of the chain, or 0 if there was an error. */ -/* WATCHOUT: This can get called multiple times before a write, so - * it should still work when this happens. - */ -/* WATCHOUT: Make sure to also update the logic in - * FLAC__metadata_chain_check_if_tempfile_needed() if the logic here changes. - */ -static FLAC__off_t chain_prepare_for_write_(FLAC__Metadata_Chain *chain, FLAC__bool use_padding) -{ - FLAC__off_t current_length = chain_calculate_length_(chain); - FLAC__Metadata_Node * i; - - /* Check all is_last settings on the blocks */ - for(i = chain->head; i->next != NULL; i = i->next) - i->data->is_last = 0; - chain->tail->data->is_last = 1; - - if(use_padding) { - /* if the metadata shrank and the last block is padding, we just extend the last padding block */ - if(current_length < chain->initial_length && chain->tail->data->type == FLAC__METADATA_TYPE_PADDING) { - const FLAC__off_t delta = chain->initial_length - current_length; - chain->tail->data->length += delta; - current_length += delta; - FLAC__ASSERT(current_length == chain->initial_length); - } - /* if the metadata shrank more than 4 bytes then there's room to add another padding block */ - else if(current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length) { - FLAC__StreamMetadata *padding; - FLAC__Metadata_Node *node; - if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) { - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return 0; - } - padding->length = chain->initial_length - (FLAC__STREAM_METADATA_HEADER_LENGTH + current_length); - if(0 == (node = node_new_())) { - FLAC__metadata_object_delete(padding); - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return 0; - } - node->data = padding; - chain_append_node_(chain, node); - current_length = chain_calculate_length_(chain); - FLAC__ASSERT(current_length == chain->initial_length); - } - /* if the metadata grew but the last block is padding, try cutting the padding to restore the original length so we don't have to rewrite the whole file */ - else if(current_length > chain->initial_length) { - const FLAC__off_t delta = current_length - chain->initial_length; - if(chain->tail->data->type == FLAC__METADATA_TYPE_PADDING) { - /* if the delta is exactly the size of the last padding block, remove the padding block */ - if((FLAC__off_t)chain->tail->data->length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta) { - chain_delete_node_(chain, chain->tail); - current_length = chain_calculate_length_(chain); - FLAC__ASSERT(current_length == chain->initial_length); - } - /* if there is at least 'delta' bytes of padding, trim the padding down */ - else if((FLAC__off_t)chain->tail->data->length >= delta) { - chain->tail->data->length -= delta; - current_length -= delta; - FLAC__ASSERT(current_length == chain->initial_length); - } - } - } - } - - /* check sizes of all metadata blocks; reduce padding size if necessary */ - { - FLAC__Metadata_Node *node; - for (node = chain->head; node; node = node->next) { - if(node->data->length >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) { - if(node->data->type == FLAC__METADATA_TYPE_PADDING) { - node->data->length = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1; - current_length = chain_calculate_length_(chain); - } else { - chain->status = FLAC__METADATA_CHAIN_STATUS_BAD_METADATA; - return 0; - } - } - } - } - - return current_length; -} - -#if defined(_MSC_VER) -#pragma warning ( default : 4244 ) -#endif - -static FLAC__bool chain_read_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__IOCallback_Tell tell_cb) -{ - FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != chain); - - /* we assume we're already at the beginning of the file */ - - switch(seek_to_first_metadata_block_cb_(handle, read_cb, seek_cb)) { - case 0: - break; - case 1: - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR; - return false; - case 2: - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; - case 3: - chain->status = FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE; - return false; - default: - FLAC__ASSERT(0); - return false; - } - - { - FLAC__int64 pos = tell_cb(handle); - if(pos < 0) { - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR; - return false; - } - chain->first_offset = (FLAC__off_t)pos; - } - - { - FLAC__bool is_last; - FLAC__MetadataType type; - uint32_t length; - - do { - node = node_new_(); - if(0 == node) { - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - - if(!read_metadata_block_header_cb_(handle, read_cb, &is_last, &type, &length)) { - node_delete_(node); - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR; - return false; - } - - node->data = FLAC__metadata_object_new(type); - if(0 == node->data) { - node_delete_(node); - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - - node->data->is_last = is_last; - node->data->length = length; - - chain->status = get_equivalent_status_(read_metadata_block_data_cb_(handle, read_cb, seek_cb, node->data)); - if(chain->status != FLAC__METADATA_CHAIN_STATUS_OK) { - node_delete_(node); - return false; - } - chain_append_node_(chain, node); - } while(!is_last); - } - - { - FLAC__int64 pos = tell_cb(handle); - if(pos < 0) { - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR; - return false; - } - chain->last_offset = (FLAC__off_t)pos; - } - - if(chain->head->data->type != FLAC__METADATA_TYPE_STREAMINFO) { - chain->status = FLAC__METADATA_CHAIN_STATUS_BAD_METADATA; - return false; - } - - chain->initial_length = chain_calculate_length_(chain); - - return true; -} - -static FLAC__StreamDecoderReadStatus chain_read_ogg_read_cb_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) -{ - FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data; - (void)decoder; - if(*bytes > 0 && chain->status == FLAC__METADATA_CHAIN_STATUS_OK) { - *bytes = chain->read_cb(buffer, sizeof(FLAC__byte), *bytes, chain->handle); - if(*bytes == 0) - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - else - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - else - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; -} - -static FLAC__StreamDecoderWriteStatus chain_read_ogg_write_cb_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - (void)decoder, (void)frame, (void)buffer, (void)client_data; - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; -} - -static void chain_read_ogg_metadata_cb_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data; - FLAC__Metadata_Node *node; - - (void)decoder; - - node = node_new_(); - if(0 == node) { - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return; - } - - node->data = FLAC__metadata_object_clone(metadata); - if(0 == node->data) { - node_delete_(node); - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return; - } - - chain_append_node_(chain, node); -} - -static void chain_read_ogg_error_cb_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data; - (void)decoder, (void)status; - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */ -} - -static FLAC__bool chain_read_ogg_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb) -{ - FLAC__StreamDecoder *decoder; - - FLAC__ASSERT(0 != chain); - - /* we assume we're already at the beginning of the file */ - - chain->handle = handle; - chain->read_cb = read_cb; - if(0 == (decoder = FLAC__stream_decoder_new())) { - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - FLAC__stream_decoder_set_metadata_respond_all(decoder); - if(FLAC__stream_decoder_init_ogg_stream(decoder, chain_read_ogg_read_cb_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, chain_read_ogg_write_cb_, chain_read_ogg_metadata_cb_, chain_read_ogg_error_cb_, chain) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - FLAC__stream_decoder_delete(decoder); - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */ - return false; - } - - chain->first_offset = 0; /*@@@ wrong; will need to be set correctly to implement metadata writing for Ogg FLAC */ - - if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */ - if(chain->status != FLAC__METADATA_CHAIN_STATUS_OK) { - FLAC__stream_decoder_delete(decoder); - return false; - } - - FLAC__stream_decoder_delete(decoder); - - chain->last_offset = 0; /*@@@ wrong; will need to be set correctly to implement metadata writing for Ogg FLAC */ - - chain->initial_length = chain_calculate_length_(chain); - - if(chain->initial_length == 0 || chain->head->data->type != FLAC__METADATA_TYPE_STREAMINFO) { - /* Ogg FLAC file must have at least streaminfo and vorbis comment */ - chain->status = FLAC__METADATA_CHAIN_STATUS_BAD_METADATA; - return false; - } - - return true; -} - -static FLAC__bool chain_rewrite_metadata_in_place_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, FLAC__IOCallback_Seek seek_cb) -{ - FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != chain->head); - - if(0 != seek_cb(handle, chain->first_offset, SEEK_SET)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; - } - - for(node = chain->head; node; node = node->next) { - if(!write_metadata_block_header_cb_(handle, write_cb, node->data)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR; - return false; - } - if(!write_metadata_block_data_cb_(handle, write_cb, node->data)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR; - return false; - } - } - - /*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/ - - chain->status = FLAC__METADATA_CHAIN_STATUS_OK; - return true; -} - -static FLAC__bool chain_rewrite_metadata_in_place_(FLAC__Metadata_Chain *chain) -{ - FILE *file; - FLAC__bool ret; - - FLAC__ASSERT(0 != chain->filename); - - if(0 == (file = flac_fopen(chain->filename, "r+b"))) { - chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE; - return false; - } - - /* chain_rewrite_metadata_in_place_cb_() sets chain->status for us */ - ret = chain_rewrite_metadata_in_place_cb_(chain, (FLAC__IOHandle)file, (FLAC__IOCallback_Write)fwrite, fseek_wrapper_); - - fclose(file); - - return ret; -} - -static FLAC__bool chain_rewrite_file_(FLAC__Metadata_Chain *chain, const char *tempfile_path_prefix) -{ - FILE *f, *tempfile = NULL; - char *tempfilename; - FLAC__Metadata_SimpleIteratorStatus status; - const FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != chain->filename); - FLAC__ASSERT(0 != chain->head); - - /* copy the file prefix (data up to first metadata block */ - if(0 == (f = flac_fopen(chain->filename, "rb"))) { - chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE; - return false; - } - if(!open_tempfile_(chain->filename, tempfile_path_prefix, &tempfile, &tempfilename, &status)) { - chain->status = get_equivalent_status_(status); - goto err; - } - if(!copy_n_bytes_from_file_(f, tempfile, chain->first_offset, &status)) { - chain->status = get_equivalent_status_(status); - goto err; - } - - /* write the metadata */ - for(node = chain->head; node; node = node->next) { - if(!write_metadata_block_header_(tempfile, &status, node->data)) { - chain->status = get_equivalent_status_(status); - goto err; - } - if(!write_metadata_block_data_(tempfile, &status, node->data)) { - chain->status = get_equivalent_status_(status); - goto err; - } - } - /*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/ - - /* copy the file postfix (everything after the metadata) */ - if(0 != fseeko(f, chain->last_offset, SEEK_SET)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - goto err; - } - if(!copy_remaining_bytes_from_file_(f, tempfile, &status)) { - chain->status = get_equivalent_status_(status); - goto err; - } - - /* move the tempfile on top of the original */ - (void)fclose(f); - if(!transport_tempfile_(chain->filename, &tempfile, &tempfilename, &status)) - return false; - - return true; - -err: - (void)fclose(f); - cleanup_tempfile_(&tempfile, &tempfilename); - return false; -} - -/* assumes 'handle' is already at beginning of file */ -static FLAC__bool chain_rewrite_file_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb) -{ - FLAC__Metadata_SimpleIteratorStatus status; - const FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 == chain->filename); - FLAC__ASSERT(0 != chain->head); - - /* copy the file prefix (data up to first metadata block */ - if(!copy_n_bytes_from_file_cb_(handle, read_cb, temp_handle, temp_write_cb, chain->first_offset, &status)) { - chain->status = get_equivalent_status_(status); - return false; - } - - /* write the metadata */ - for(node = chain->head; node; node = node->next) { - if(!write_metadata_block_header_cb_(temp_handle, temp_write_cb, node->data)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR; - return false; - } - if(!write_metadata_block_data_cb_(temp_handle, temp_write_cb, node->data)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR; - return false; - } - } - /*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/ - - /* copy the file postfix (everything after the metadata) */ - if(0 != seek_cb(handle, chain->last_offset, SEEK_SET)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; - } - if(!copy_remaining_bytes_from_file_cb_(handle, read_cb, eof_cb, temp_handle, temp_write_cb, &status)) { - chain->status = get_equivalent_status_(status); - return false; - } - - return true; -} - -FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void) -{ - FLAC__Metadata_Chain *chain = calloc(1, sizeof(FLAC__Metadata_Chain)); - - if(0 != chain) - chain_init_(chain); - - return chain; -} - -FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain) -{ - FLAC__ASSERT(0 != chain); - - chain_clear_(chain); - - free(chain); -} - -FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain) -{ - FLAC__Metadata_ChainStatus status; - - FLAC__ASSERT(0 != chain); - - status = chain->status; - chain->status = FLAC__METADATA_CHAIN_STATUS_OK; - return status; -} - -static FLAC__bool chain_read_(FLAC__Metadata_Chain *chain, const char *filename, FLAC__bool is_ogg) -{ - FILE *file; - FLAC__bool ret; - - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != filename); - - chain_clear_(chain); - - if(0 == (chain->filename = strdup(filename))) { - chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - - chain->is_ogg = is_ogg; - - if(0 == (file = flac_fopen(filename, "rb"))) { - chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE; - return false; - } - - /* the function also sets chain->status for us */ - ret = is_ogg? - chain_read_ogg_cb_(chain, file, (FLAC__IOCallback_Read)fread) : - chain_read_cb_(chain, file, (FLAC__IOCallback_Read)fread, fseek_wrapper_, ftell_wrapper_) - ; - - fclose(file); - - return ret; -} - -FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename) -{ - return chain_read_(chain, filename, /*is_ogg=*/false); -} - -/*@@@@add to tests*/ -FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename) -{ - return chain_read_(chain, filename, /*is_ogg=*/true); -} - -static FLAC__bool chain_read_with_callbacks_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__bool is_ogg) -{ - FLAC__bool ret; - - FLAC__ASSERT(0 != chain); - - chain_clear_(chain); - - if (0 == callbacks.read || 0 == callbacks.seek || 0 == callbacks.tell) { - chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS; - return false; - } - - chain->is_ogg = is_ogg; - - /* rewind */ - if(0 != callbacks.seek(handle, 0, SEEK_SET)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; - } - - /* the function also sets chain->status for us */ - ret = is_ogg? - chain_read_ogg_cb_(chain, handle, callbacks.read) : - chain_read_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.tell) - ; - - return ret; -} - -FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks) -{ - return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/false); -} - -/*@@@@add to tests*/ -FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks) -{ - return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/true); -} - -typedef enum { - LBS_NONE = 0, - LBS_SIZE_CHANGED, - LBS_BLOCK_ADDED, - LBS_BLOCK_REMOVED -} LastBlockState; - -#if defined(_MSC_VER) -// silence three MSVC warnings 'conversion from 'conversion from 'const __int64' to 'uint32_t', possible loss of data' -#pragma warning ( disable : 4244 ) -#endif - -FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding) -{ - /* This does all the same checks that are in chain_prepare_for_write_() - * but doesn't actually alter the chain. Make sure to update the logic - * here if chain_prepare_for_write_() changes. - */ - FLAC__off_t current_length; - LastBlockState lbs_state = LBS_NONE; - uint32_t lbs_size = 0; - - FLAC__ASSERT(0 != chain); - - current_length = chain_calculate_length_(chain); - - if(use_padding) { - const FLAC__Metadata_Node * const node = chain->tail; - /* if the metadata shrank and the last block is padding, we just extend the last padding block */ - if(current_length < chain->initial_length && node->data->type == FLAC__METADATA_TYPE_PADDING) { - lbs_state = LBS_SIZE_CHANGED; - lbs_size = node->data->length + (chain->initial_length - current_length); - } - /* if the metadata shrank more than 4 bytes then there's room to add another padding block */ - else if(current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length) { - lbs_state = LBS_BLOCK_ADDED; - lbs_size = chain->initial_length - (current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH); - } - /* if the metadata grew but the last block is padding, try cutting the padding to restore the original length so we don't have to rewrite the whole file */ - else if(current_length > chain->initial_length) { - const FLAC__off_t delta = current_length - chain->initial_length; - if(node->data->type == FLAC__METADATA_TYPE_PADDING) { - /* if the delta is exactly the size of the last padding block, remove the padding block */ - if((FLAC__off_t)node->data->length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta) { - lbs_state = LBS_BLOCK_REMOVED; - lbs_size = 0; - } - /* if there is at least 'delta' bytes of padding, trim the padding down */ - else if((FLAC__off_t)node->data->length >= delta) { - lbs_state = LBS_SIZE_CHANGED; - lbs_size = node->data->length - delta; - } - } - } - } - - current_length = 0; - /* check sizes of all metadata blocks; reduce padding size if necessary */ - { - const FLAC__Metadata_Node *node; - for(node = chain->head; node; node = node->next) { - uint32_t block_len = node->data->length; - if(node == chain->tail) { - if(lbs_state == LBS_BLOCK_REMOVED) - continue; - else if(lbs_state == LBS_SIZE_CHANGED) - block_len = lbs_size; - } - if(block_len >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) { - if(node->data->type == FLAC__METADATA_TYPE_PADDING) - block_len = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1; - else - return false /* the return value doesn't matter */; - } - current_length += (FLAC__STREAM_METADATA_HEADER_LENGTH + block_len); - } - - if(lbs_state == LBS_BLOCK_ADDED) { - /* test added padding block */ - uint32_t block_len = lbs_size; - if(block_len >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) - block_len = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1; - current_length += (FLAC__STREAM_METADATA_HEADER_LENGTH + block_len); - } - } - - return (current_length != chain->initial_length); -} - -#if defined(_MSC_VER) -#pragma warning ( default : 4244 ) -#endif - -FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats) -{ - struct flac_stat_s stats; - const char *tempfile_path_prefix = 0; - FLAC__off_t current_length; - - FLAC__ASSERT(0 != chain); - - if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */ - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; - return false; - } - - if (0 == chain->filename) { - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH; - return false; - } - - current_length = chain_prepare_for_write_(chain, use_padding); - - /* a return value of 0 means there was an error; chain->status is already set */ - if (0 == current_length) - return false; - - if(preserve_file_stats) - get_file_stats_(chain->filename, &stats); - - if(current_length == chain->initial_length) { - if(!chain_rewrite_metadata_in_place_(chain)) - return false; - } - else { - if(!chain_rewrite_file_(chain, tempfile_path_prefix)) - return false; - - /* recompute lengths and offsets */ - { - const FLAC__Metadata_Node *node; - chain->initial_length = current_length; - chain->last_offset = chain->first_offset; - for(node = chain->head; node; node = node->next) - chain->last_offset += (FLAC__STREAM_METADATA_HEADER_LENGTH + node->data->length); - } - } - - if(preserve_file_stats) - set_file_stats_(chain->filename, &stats); - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks) -{ - FLAC__off_t current_length; - - FLAC__ASSERT(0 != chain); - - if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */ - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; - return false; - } - - if (0 != chain->filename) { - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH; - return false; - } - - if (0 == callbacks.write || 0 == callbacks.seek) { - chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS; - return false; - } - - if (FLAC__metadata_chain_check_if_tempfile_needed(chain, use_padding)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL; - return false; - } - - current_length = chain_prepare_for_write_(chain, use_padding); - - /* a return value of 0 means there was an error; chain->status is already set */ - if (0 == current_length) - return false; - - FLAC__ASSERT(current_length == chain->initial_length); - - return chain_rewrite_metadata_in_place_cb_(chain, handle, callbacks.write, callbacks.seek); -} - -FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__IOHandle temp_handle, FLAC__IOCallbacks temp_callbacks) -{ - FLAC__off_t current_length; - - FLAC__ASSERT(0 != chain); - - if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */ - chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; - return false; - } - - if (0 != chain->filename) { - chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH; - return false; - } - - if (0 == callbacks.read || 0 == callbacks.seek || 0 == callbacks.eof) { - chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS; - return false; - } - if (0 == temp_callbacks.write) { - chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS; - return false; - } - - if (!FLAC__metadata_chain_check_if_tempfile_needed(chain, use_padding)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL; - return false; - } - - current_length = chain_prepare_for_write_(chain, use_padding); - - /* a return value of 0 means there was an error; chain->status is already set */ - if (0 == current_length) - return false; - - FLAC__ASSERT(current_length != chain->initial_length); - - /* rewind */ - if(0 != callbacks.seek(handle, 0, SEEK_SET)) { - chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - return false; - } - - if(!chain_rewrite_file_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.eof, temp_handle, temp_callbacks.write)) - return false; - - /* recompute lengths and offsets */ - { - const FLAC__Metadata_Node *node; - chain->initial_length = current_length; - chain->last_offset = chain->first_offset; - for(node = chain->head; node; node = node->next) - chain->last_offset += (FLAC__STREAM_METADATA_HEADER_LENGTH + node->data->length); - } - - return true; -} - -FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain) -{ - FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != chain); - - for(node = chain->head; node; ) { - if(!chain_merge_adjacent_padding_(chain, node)) - node = node->next; - } -} - -FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain) -{ - FLAC__Metadata_Node *node, *save; - uint32_t i; - - FLAC__ASSERT(0 != chain); - - /* - * Don't try and be too smart... this simple algo is good enough for - * the small number of nodes that we deal with. - */ - for(i = 0, node = chain->head; i < chain->nodes; i++) { - if(node->data->type == FLAC__METADATA_TYPE_PADDING) { - save = node->next; - chain_remove_node_(chain, node); - chain_append_node_(chain, node); - node = save; - } - else { - node = node->next; - } - } - - FLAC__metadata_chain_merge_padding(chain); -} - - -FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void) -{ - FLAC__Metadata_Iterator *iterator = calloc(1, sizeof(FLAC__Metadata_Iterator)); - - /* calloc() implies: - iterator->current = 0; - iterator->chain = 0; - */ - - return iterator; -} - -FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - - free(iterator); -} - -FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != chain); - FLAC__ASSERT(0 != chain->head); - - iterator->chain = chain; - iterator->current = chain->head; -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - - if(0 == iterator->current || 0 == iterator->current->next) - return false; - - iterator->current = iterator->current->next; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - - if(0 == iterator->current || 0 == iterator->current->prev) - return false; - - iterator->current = iterator->current->prev; - return true; -} - -FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - FLAC__ASSERT(0 != iterator->current->data); - - return iterator->current->data->type; -} - -FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - - return iterator->current->data; -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != block); - return FLAC__metadata_iterator_delete_block(iterator, false) && FLAC__metadata_iterator_insert_block_after(iterator, block); -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding) -{ - FLAC__Metadata_Node *save; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - - if(0 == iterator->current->prev) { - FLAC__ASSERT(iterator->current->data->type == FLAC__METADATA_TYPE_STREAMINFO); - return false; - } - - save = iterator->current->prev; - - if(replace_with_padding) { - FLAC__metadata_object_delete_data(iterator->current->data); - iterator->current->data->type = FLAC__METADATA_TYPE_PADDING; - } - else { - chain_delete_node_(iterator->chain, iterator->current); - } - - iterator->current = save; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block) -{ - FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - FLAC__ASSERT(0 != block); - - if(block->type == FLAC__METADATA_TYPE_STREAMINFO) - return false; - - if(0 == iterator->current->prev) { - FLAC__ASSERT(iterator->current->data->type == FLAC__METADATA_TYPE_STREAMINFO); - return false; - } - - if(0 == (node = node_new_())) - return false; - - node->data = block; - iterator_insert_node_(iterator, node); - iterator->current = node; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block) -{ - FLAC__Metadata_Node *node; - - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->current); - FLAC__ASSERT(0 != block); - - if(block->type == FLAC__METADATA_TYPE_STREAMINFO) - return false; - - if(0 == (node = node_new_())) - return false; - - node->data = block; - iterator_insert_node_after_(iterator, node); - iterator->current = node; - return true; -} - - -/**************************************************************************** - * - * Local function definitions - * - ***************************************************************************/ - -void pack_uint32_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes) -{ - uint32_t i; - - b += bytes; - - for(i = 0; i < bytes; i++) { - *(--b) = (FLAC__byte)(val & 0xff); - val >>= 8; - } -} - -void pack_uint32_little_endian_(FLAC__uint32 val, FLAC__byte *b, uint32_t bytes) -{ - uint32_t i; - - for(i = 0; i < bytes; i++) { - *(b++) = (FLAC__byte)(val & 0xff); - val >>= 8; - } -} - -void pack_uint64_(FLAC__uint64 val, FLAC__byte *b, uint32_t bytes) -{ - uint32_t i; - - b += bytes; - - for(i = 0; i < bytes; i++) { - *(--b) = (FLAC__byte)(val & 0xff); - val >>= 8; - } -} - -FLAC__uint32 unpack_uint32_(FLAC__byte *b, uint32_t bytes) -{ - FLAC__uint32 ret = 0; - uint32_t i; - - for(i = 0; i < bytes; i++) - ret = (ret << 8) | (FLAC__uint32)(*b++); - - return ret; -} - -FLAC__uint32 unpack_uint32_little_endian_(FLAC__byte *b, uint32_t bytes) -{ - FLAC__uint32 ret = 0; - uint32_t i; - - b += bytes; - - for(i = 0; i < bytes; i++) - ret = (ret << 8) | (FLAC__uint32)(*--b); - - return ret; -} - -FLAC__uint64 unpack_uint64_(FLAC__byte *b, uint32_t bytes) -{ - FLAC__uint64 ret = 0; - uint32_t i; - - for(i = 0; i < bytes; i++) - ret = (ret << 8) | (FLAC__uint64)(*b++); - - return ret; -} - -FLAC__bool read_metadata_block_header_(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - if(!read_metadata_block_header_cb_((FLAC__IOHandle)iterator->file, (FLAC__IOCallback_Read)fread, &iterator->is_last, &iterator->type, &iterator->length)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - - return true; -} - -FLAC__bool read_metadata_block_data_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != iterator); - FLAC__ASSERT(0 != iterator->file); - - iterator->status = read_metadata_block_data_cb_((FLAC__IOHandle)iterator->file, (FLAC__IOCallback_Read)fread, fseek_wrapper_, block); - - return (iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK); -} - -FLAC__bool read_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__bool *is_last, FLAC__MetadataType *type, uint32_t *length) -{ - FLAC__byte raw_header[FLAC__STREAM_METADATA_HEADER_LENGTH]; - - if(read_cb(raw_header, 1, FLAC__STREAM_METADATA_HEADER_LENGTH, handle) != FLAC__STREAM_METADATA_HEADER_LENGTH) - return false; - - *is_last = raw_header[0] & 0x80? true : false; - *type = (FLAC__MetadataType)(raw_header[0] & 0x7f); - *length = unpack_uint32_(raw_header + 1, 3); - - /* Note that we don't check: - * if(iterator->type >= FLAC__METADATA_TYPE_UNDEFINED) - * we just will read in an opaque block - */ - - return true; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata *block) -{ - switch(block->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - return read_metadata_block_data_streaminfo_cb_(handle, read_cb, &block->data.stream_info); - case FLAC__METADATA_TYPE_PADDING: - return read_metadata_block_data_padding_cb_(handle, seek_cb, &block->data.padding, block->length); - case FLAC__METADATA_TYPE_APPLICATION: - return read_metadata_block_data_application_cb_(handle, read_cb, &block->data.application, block->length); - case FLAC__METADATA_TYPE_SEEKTABLE: - return read_metadata_block_data_seektable_cb_(handle, read_cb, &block->data.seek_table, block->length); - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - return read_metadata_block_data_vorbis_comment_cb_(handle, read_cb, seek_cb, &block->data.vorbis_comment, block->length); - case FLAC__METADATA_TYPE_CUESHEET: - return read_metadata_block_data_cuesheet_cb_(handle, read_cb, &block->data.cue_sheet); - case FLAC__METADATA_TYPE_PICTURE: - return read_metadata_block_data_picture_cb_(handle, read_cb, &block->data.picture); - default: - return read_metadata_block_data_unknown_cb_(handle, read_cb, &block->data.unknown, block->length); - } -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_StreamInfo *block) -{ - FLAC__byte buffer[FLAC__STREAM_METADATA_STREAMINFO_LENGTH], *b; - - if(read_cb(buffer, 1, FLAC__STREAM_METADATA_STREAMINFO_LENGTH, handle) != FLAC__STREAM_METADATA_STREAMINFO_LENGTH) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - b = buffer; - - /* we are using hardcoded numbers for simplicity but we should - * probably eventually write a bit-level unpacker and use the - * _STREAMINFO_ constants. - */ - block->min_blocksize = unpack_uint32_(b, 2); b += 2; - block->max_blocksize = unpack_uint32_(b, 2); b += 2; - block->min_framesize = unpack_uint32_(b, 3); b += 3; - block->max_framesize = unpack_uint32_(b, 3); b += 3; - block->sample_rate = (unpack_uint32_(b, 2) << 4) | ((uint32_t)(b[2] & 0xf0) >> 4); - block->channels = (uint32_t)((b[2] & 0x0e) >> 1) + 1; - block->bits_per_sample = ((((uint32_t)(b[2] & 0x01)) << 4) | (((uint32_t)(b[3] & 0xf0)) >> 4)) + 1; - block->total_samples = (((FLAC__uint64)(b[3] & 0x0f)) << 32) | unpack_uint64_(b+4, 4); - memcpy(block->md5sum, b+8, 16); - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_Padding *block, uint32_t block_length) -{ - (void)block; /* nothing to do; we don't care about reading the padding bytes */ - - if(0 != seek_cb(handle, block_length, SEEK_CUR)) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Application *block, uint32_t block_length) -{ - const uint32_t id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8; - - if(read_cb(block->id, 1, id_bytes, handle) != id_bytes) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - if(block_length < id_bytes) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - block_length -= id_bytes; - - if(block_length == 0) { - block->data = 0; - } - else { - if(0 == (block->data = malloc(block_length))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - if(read_cb(block->data, 1, block_length, handle) != block_length) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_SeekTable *block, uint32_t block_length) -{ - uint32_t i; - FLAC__byte buffer[FLAC__STREAM_METADATA_SEEKPOINT_LENGTH]; - - if(block_length % FLAC__STREAM_METADATA_SEEKPOINT_LENGTH != 0) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA; - - block->num_points = block_length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH; - - if(block->num_points == 0) - block->points = 0; - else if(0 == (block->points = safe_malloc_mul_2op_p(block->num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint)))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - for(i = 0; i < block->num_points; i++) { - if(read_cb(buffer, 1, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH, handle) != FLAC__STREAM_METADATA_SEEKPOINT_LENGTH) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - /* some MAGIC NUMBERs here */ - block->points[i].sample_number = unpack_uint64_(buffer, 8); - block->points[i].stream_offset = unpack_uint64_(buffer+8, 8); - block->points[i].frame_samples = unpack_uint32_(buffer+16, 2); - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_VorbisComment_Entry *entry, uint32_t max_length) -{ - const uint32_t entry_length_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8; - FLAC__byte buffer[4]; /* magic number is asserted below */ - - FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8 == sizeof(buffer)); - - if(max_length < entry_length_len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA; - - max_length -= entry_length_len; - if(read_cb(buffer, 1, entry_length_len, handle) != entry_length_len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - entry->length = unpack_uint32_little_endian_(buffer, entry_length_len); - if(max_length < entry->length) { - entry->length = 0; - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA; - } - - if(0 != entry->entry) - free(entry->entry); - - if(0 == (entry->entry = safe_malloc_add_2op_(entry->length, /*+*/1))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - if(entry->length > 0 && read_cb(entry->entry, 1, entry->length, handle) != entry->length) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - entry->entry[entry->length] = '\0'; - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_VorbisComment *block, uint32_t block_length) -{ - uint32_t i; - FLAC__Metadata_SimpleIteratorStatus status; - const uint32_t num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8; - FLAC__byte buffer[4]; /* magic number is asserted below */ - - FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8 == sizeof(buffer)); - - status = read_metadata_block_data_vorbis_comment_entry_cb_(handle, read_cb, &(block->vendor_string), block_length); - if(block_length >= 4) - block_length -= 4; - if(status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA) - goto skip; - else if(status != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) - return status; - block_length -= block->vendor_string.length; - - if(block_length < num_comments_len) goto skip; else block_length -= num_comments_len; - if(read_cb(buffer, 1, num_comments_len, handle) != num_comments_len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->num_comments = unpack_uint32_little_endian_(buffer, num_comments_len); - - if(block->num_comments == 0) { - block->comments = 0; - } - else if(block->num_comments > (block_length >> 2)) { /* each comment needs at least 4 byte */ - block->num_comments = 0; - status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA; - goto skip; - } - else if(0 == (block->comments = calloc(block->num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) { - block->num_comments = 0; - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - } - - for(i = 0; i < block->num_comments; i++) { - status = read_metadata_block_data_vorbis_comment_entry_cb_(handle, read_cb, block->comments + i, block_length); - if(block_length >= 4) block_length -= 4; - if(status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA) { - block->num_comments = i; - goto skip; - } - else if(status != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) return status; - block_length -= block->comments[i].length; - } - - skip: - if(block_length > 0) { - /* bad metadata */ - if(0 != seek_cb(handle, block_length, SEEK_CUR)) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - } - - return status; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet_Track *track) -{ - uint32_t i, len; - FLAC__byte buffer[32]; /* asserted below that this is big enough */ - - FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64)); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - track->offset = unpack_uint64_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - track->number = (FLAC__byte)unpack_uint32_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN / 8; - if(read_cb(track->isrc, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) % 8 == 0); - len = (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN == 1); - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN == 1); - track->type = buffer[0] >> 7; - track->pre_emphasis = (buffer[0] >> 6) & 1; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - track->num_indices = (FLAC__byte)unpack_uint32_(buffer, len); - - if(track->num_indices == 0) { - track->indices = 0; - } - else if(0 == (track->indices = calloc(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - for(i = 0; i < track->num_indices; i++) { - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - track->indices[i].offset = unpack_uint64_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - track->indices[i].number = (FLAC__byte)unpack_uint32_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet *block) -{ - uint32_t i, len; - FLAC__Metadata_SimpleIteratorStatus status; - FLAC__byte buffer[1024]; /* MSVC needs a constant expression so we put a magic number and assert */ - - FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN)/8 <= sizeof(buffer)); - FLAC__ASSERT(sizeof(FLAC__uint64) <= sizeof(buffer)); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN / 8; - if(read_cb(block->media_catalog_number, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->lead_in = unpack_uint64_(buffer, len); - - FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) % 8 == 0); - len = (FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->is_cd = buffer[0]&0x80? true : false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->num_tracks = unpack_uint32_(buffer, len); - - if(block->num_tracks == 0) { - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA; - } - else if(0 == (block->tracks = calloc(block->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - for(i = 0; i < block->num_tracks; i++) { - if(FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK != (status = read_metadata_block_data_cuesheet_track_cb_(handle, read_cb, block->tracks + i))) - return status; - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cstring_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__byte **data, FLAC__uint32 *length, FLAC__uint32 length_len) -{ - FLAC__byte buffer[sizeof(FLAC__uint32)]; - - FLAC__ASSERT(0 != data); - FLAC__ASSERT(length_len%8 == 0); - - length_len /= 8; /* convert to bytes */ - - FLAC__ASSERT(sizeof(buffer) >= length_len); - - if(read_cb(buffer, 1, length_len, handle) != length_len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - *length = unpack_uint32_(buffer, length_len); - - if(*length > (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) /* data cannot be larger than FLAC metadata block */ - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA; - - if(0 != *data) - free(*data); - - if(0 == (*data = safe_malloc_add_2op_(*length, /*+*/1))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - if(*length > 0) { - if(read_cb(*data, 1, *length, handle) != *length) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - } - - (*data)[*length] = '\0'; - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Picture *block) -{ - FLAC__Metadata_SimpleIteratorStatus status; - FLAC__byte buffer[4]; /* asserted below that this is big enough */ - FLAC__uint32 len; - - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8); - - FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_TYPE_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_PICTURE_TYPE_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->type = (FLAC__StreamMetadata_Picture_Type)unpack_uint32_(buffer, len); - - if((status = read_metadata_block_data_picture_cstring_cb_(handle, read_cb, (FLAC__byte**)(&(block->mime_type)), &len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN)) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) - return status; - - if((status = read_metadata_block_data_picture_cstring_cb_(handle, read_cb, &(block->description), &len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN)) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) - return status; - - FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->width = unpack_uint32_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->height = unpack_uint32_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->depth = unpack_uint32_(buffer, len); - - FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_COLORS_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_PICTURE_COLORS_LEN / 8; - if(read_cb(buffer, 1, len, handle) != len) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - block->colors = unpack_uint32_(buffer, len); - - /* for convenience we use read_metadata_block_data_picture_cstring_cb_() even though it adds an extra terminating NUL we don't use */ - if((status = read_metadata_block_data_picture_cstring_cb_(handle, read_cb, &(block->data), &(block->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN)) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) - return status; - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Unknown *block, uint32_t block_length) -{ - if(block_length == 0) { - block->data = 0; - } - else { - if(0 == (block->data = malloc(block_length))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - if(read_cb(block->data, 1, block_length, handle) != block_length) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - } - - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; -} - -FLAC__bool write_metadata_block_header_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != file); - FLAC__ASSERT(0 != status); - - if(!write_metadata_block_header_cb_((FLAC__IOHandle)file, (FLAC__IOCallback_Write)fwrite, block)) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - - return true; -} - -FLAC__bool write_metadata_block_data_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != file); - FLAC__ASSERT(0 != status); - - if (write_metadata_block_data_cb_((FLAC__IOHandle)file, (FLAC__IOCallback_Write)fwrite, block)) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK; - return true; - } - else { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } -} - -FLAC__bool write_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block) -{ - FLAC__byte buffer[FLAC__STREAM_METADATA_HEADER_LENGTH]; - - FLAC__ASSERT(block->length < (1u << FLAC__STREAM_METADATA_LENGTH_LEN)); - /* double protection */ - if(block->length >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) - return false; - - buffer[0] = (block->is_last? 0x80 : 0) | (FLAC__byte)block->type; - pack_uint32_(block->length, buffer + 1, 3); - - if(write_cb(buffer, 1, FLAC__STREAM_METADATA_HEADER_LENGTH, handle) != FLAC__STREAM_METADATA_HEADER_LENGTH) - return false; - - return true; -} - -FLAC__bool write_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != block); - - switch(block->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - return write_metadata_block_data_streaminfo_cb_(handle, write_cb, &block->data.stream_info); - case FLAC__METADATA_TYPE_PADDING: - return write_metadata_block_data_padding_cb_(handle, write_cb, &block->data.padding, block->length); - case FLAC__METADATA_TYPE_APPLICATION: - return write_metadata_block_data_application_cb_(handle, write_cb, &block->data.application, block->length); - case FLAC__METADATA_TYPE_SEEKTABLE: - return write_metadata_block_data_seektable_cb_(handle, write_cb, &block->data.seek_table); - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - return write_metadata_block_data_vorbis_comment_cb_(handle, write_cb, &block->data.vorbis_comment); - case FLAC__METADATA_TYPE_CUESHEET: - return write_metadata_block_data_cuesheet_cb_(handle, write_cb, &block->data.cue_sheet); - case FLAC__METADATA_TYPE_PICTURE: - return write_metadata_block_data_picture_cb_(handle, write_cb, &block->data.picture); - default: - return write_metadata_block_data_unknown_cb_(handle, write_cb, &block->data.unknown, block->length); - } -} - -FLAC__bool write_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_StreamInfo *block) -{ - FLAC__byte buffer[FLAC__STREAM_METADATA_STREAMINFO_LENGTH]; - const uint32_t channels1 = block->channels - 1; - const uint32_t bps1 = block->bits_per_sample - 1; - - /* we are using hardcoded numbers for simplicity but we should - * probably eventually write a bit-level packer and use the - * _STREAMINFO_ constants. - */ - pack_uint32_(block->min_blocksize, buffer, 2); - pack_uint32_(block->max_blocksize, buffer+2, 2); - pack_uint32_(block->min_framesize, buffer+4, 3); - pack_uint32_(block->max_framesize, buffer+7, 3); - buffer[10] = (block->sample_rate >> 12) & 0xff; - buffer[11] = (block->sample_rate >> 4) & 0xff; - buffer[12] = ((block->sample_rate & 0x0f) << 4) | (channels1 << 1) | (bps1 >> 4); - buffer[13] = (FLAC__byte)(((bps1 & 0x0f) << 4) | ((block->total_samples >> 32) & 0x0f)); - pack_uint32_((FLAC__uint32)block->total_samples, buffer+14, 4); - memcpy(buffer+18, block->md5sum, 16); - - if(write_cb(buffer, 1, FLAC__STREAM_METADATA_STREAMINFO_LENGTH, handle) != FLAC__STREAM_METADATA_STREAMINFO_LENGTH) - return false; - - return true; -} - -FLAC__bool write_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Padding *block, uint32_t block_length) -{ - uint32_t i, n = block_length; - FLAC__byte buffer[1024]; - - (void)block; - - memset(buffer, 0, 1024); - - for(i = 0; i < n/1024; i++) - if(write_cb(buffer, 1, 1024, handle) != 1024) - return false; - - n %= 1024; - - if(write_cb(buffer, 1, n, handle) != n) - return false; - - return true; -} - -FLAC__bool write_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Application *block, uint32_t block_length) -{ - const uint32_t id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8; - - if(write_cb(block->id, 1, id_bytes, handle) != id_bytes) - return false; - - block_length -= id_bytes; - - if(write_cb(block->data, 1, block_length, handle) != block_length) - return false; - - return true; -} - -FLAC__bool write_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_SeekTable *block) -{ - uint32_t i; - FLAC__byte buffer[FLAC__STREAM_METADATA_SEEKPOINT_LENGTH]; - - for(i = 0; i < block->num_points; i++) { - /* some MAGIC NUMBERs here */ - pack_uint64_(block->points[i].sample_number, buffer, 8); - pack_uint64_(block->points[i].stream_offset, buffer+8, 8); - pack_uint32_(block->points[i].frame_samples, buffer+16, 2); - if(write_cb(buffer, 1, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH, handle) != FLAC__STREAM_METADATA_SEEKPOINT_LENGTH) - return false; - } - - return true; -} - -FLAC__bool write_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_VorbisComment *block) -{ - uint32_t i; - const uint32_t entry_length_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8; - const uint32_t num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8; - FLAC__byte buffer[4]; /* magic number is asserted below */ - - FLAC__ASSERT(flac_max(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN, FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8 == sizeof(buffer)); - - pack_uint32_little_endian_(block->vendor_string.length, buffer, entry_length_len); - if(write_cb(buffer, 1, entry_length_len, handle) != entry_length_len) - return false; - if(write_cb(block->vendor_string.entry, 1, block->vendor_string.length, handle) != block->vendor_string.length) - return false; - - pack_uint32_little_endian_(block->num_comments, buffer, num_comments_len); - if(write_cb(buffer, 1, num_comments_len, handle) != num_comments_len) - return false; - - for(i = 0; i < block->num_comments; i++) { - pack_uint32_little_endian_(block->comments[i].length, buffer, entry_length_len); - if(write_cb(buffer, 1, entry_length_len, handle) != entry_length_len) - return false; - if(write_cb(block->comments[i].entry, 1, block->comments[i].length, handle) != block->comments[i].length) - return false; - } - - return true; -} - -FLAC__bool write_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_CueSheet *block) -{ - uint32_t i, j, len; - FLAC__byte buffer[1024]; /* asserted below that this is big enough */ - - FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64)); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN)/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN/8); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN / 8; - if(write_cb(block->media_catalog_number, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN / 8; - pack_uint64_(block->lead_in, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) % 8 == 0); - len = (FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) / 8; - memset(buffer, 0, len); - if(block->is_cd) - buffer[0] |= 0x80; - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN / 8; - pack_uint32_(block->num_tracks, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - for(i = 0; i < block->num_tracks; i++) { - FLAC__StreamMetadata_CueSheet_Track *track = block->tracks + i; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN / 8; - pack_uint64_(track->offset, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN / 8; - pack_uint32_(track->number, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN / 8; - if(write_cb(track->isrc, 1, len, handle) != len) - return false; - - FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) % 8 == 0); - len = (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8; - memset(buffer, 0, len); - buffer[0] = (track->type << 7) | (track->pre_emphasis << 6); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN / 8; - pack_uint32_(track->num_indices, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - for(j = 0; j < track->num_indices; j++) { - FLAC__StreamMetadata_CueSheet_Index *indx = track->indices + j; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN / 8; - pack_uint64_(indx->offset, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN / 8; - pack_uint32_(indx->number, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN % 8 == 0); - len = FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN / 8; - memset(buffer, 0, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - } - } - - return true; -} - -FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Picture *block) -{ - uint32_t len; - size_t slen; - FLAC__byte buffer[4]; /* magic number is asserted below */ - - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_TYPE_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_COLORS_LEN%8); - FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN%8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8); - FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN/8); - - len = FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8; - pack_uint32_(block->type, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN/8; - slen = strlen(block->mime_type); - pack_uint32_(slen, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - if(write_cb(block->mime_type, 1, slen, handle) != slen) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN/8; - slen = strlen((const char *)block->description); - pack_uint32_(slen, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - if(write_cb(block->description, 1, slen, handle) != slen) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8; - pack_uint32_(block->width, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8; - pack_uint32_(block->height, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8; - pack_uint32_(block->depth, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8; - pack_uint32_(block->colors, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - - len = FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN/8; - pack_uint32_(block->data_length, buffer, len); - if(write_cb(buffer, 1, len, handle) != len) - return false; - if(write_cb(block->data, 1, block->data_length, handle) != block->data_length) - return false; - - return true; -} - -FLAC__bool write_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Unknown *block, uint32_t block_length) -{ - if(write_cb(block->data, 1, block_length, handle) != block_length) - return false; - - return true; -} - -FLAC__bool write_metadata_block_stationary_(FLAC__Metadata_SimpleIterator *iterator, const FLAC__StreamMetadata *block) -{ - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - if(!write_metadata_block_header_(iterator->file, &iterator->status, block)) - return false; - - if(!write_metadata_block_data_(iterator->file, &iterator->status, block)) - return false; - - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - return read_metadata_block_header_(iterator); -} - -FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, uint32_t padding_length, FLAC__bool padding_is_last) -{ - FLAC__StreamMetadata *padding; - - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - block->is_last = false; - - if(!write_metadata_block_header_(iterator->file, &iterator->status, block)) - return false; - - if(!write_metadata_block_data_(iterator->file, &iterator->status, block)) - return false; - - if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) - return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - - padding->is_last = padding_is_last; - padding->length = padding_length; - - if(!write_metadata_block_header_(iterator->file, &iterator->status, padding)) { - FLAC__metadata_object_delete(padding); - return false; - } - - if(!write_metadata_block_data_(iterator->file, &iterator->status, padding)) { - FLAC__metadata_object_delete(padding); - return false; - } - - FLAC__metadata_object_delete(padding); - - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - return read_metadata_block_header_(iterator); -} - -FLAC__bool rewrite_whole_file_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool append) -{ - FILE *tempfile = NULL; - char *tempfilename = NULL; - int fixup_is_last_code = 0; /* 0 => no need to change any is_last flags */ - FLAC__off_t fixup_is_last_flag_offset = -1; - - FLAC__ASSERT(0 != block || append == false); - - if(iterator->is_last) { - if(append) { - fixup_is_last_code = 1; /* 1 => clear the is_last flag at the following offset */ - fixup_is_last_flag_offset = iterator->offset[iterator->depth]; - } - else if(0 == block) { - simple_iterator_push_(iterator); - if(!FLAC__metadata_simple_iterator_prev(iterator)) { - (void)simple_iterator_pop_(iterator); - return false; - } - fixup_is_last_code = -1; /* -1 => set the is_last the flag at the following offset */ - fixup_is_last_flag_offset = iterator->offset[iterator->depth]; - if(!simple_iterator_pop_(iterator)) - return false; - } - } - - if(!simple_iterator_copy_file_prefix_(iterator, &tempfile, &tempfilename, append)) - return false; - - if(0 != block) { - if(!write_metadata_block_header_(tempfile, &iterator->status, block)) { - cleanup_tempfile_(&tempfile, &tempfilename); - return false; - } - - if(!write_metadata_block_data_(tempfile, &iterator->status, block)) { - cleanup_tempfile_(&tempfile, &tempfilename); - return false; - } - } - - if(!simple_iterator_copy_file_postfix_(iterator, &tempfile, &tempfilename, fixup_is_last_code, fixup_is_last_flag_offset, block==0)) - return false; - - if(append) - return FLAC__metadata_simple_iterator_next(iterator); - - return true; -} - -void simple_iterator_push_(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(iterator->depth+1 < SIMPLE_ITERATOR_MAX_PUSH_DEPTH); - iterator->offset[iterator->depth+1] = iterator->offset[iterator->depth]; - iterator->depth++; -} - -FLAC__bool simple_iterator_pop_(FLAC__Metadata_SimpleIterator *iterator) -{ - FLAC__ASSERT(iterator->depth > 0); - iterator->depth--; - if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - - return read_metadata_block_header_(iterator); -} - -/* return meanings: - * 0: ok - * 1: read error - * 2: seek error - * 3: not a FLAC file - */ -uint32_t seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb) -{ - FLAC__byte buffer[4]; - size_t n; - uint32_t i; - - FLAC__ASSERT(FLAC__STREAM_SYNC_LENGTH == sizeof(buffer)); - - /* skip any id3v2 tag */ - errno = 0; - n = read_cb(buffer, 1, 4, handle); - if(errno) - return 1; - else if(n != 4) - return 3; - else if(0 == memcmp(buffer, "ID3", 3)) { - uint32_t tag_length = 0; - - /* skip to the tag length */ - if(seek_cb(handle, 2, SEEK_CUR) < 0) - return 2; - - /* read the length */ - for(i = 0; i < 4; i++) { - if(read_cb(buffer, 1, 1, handle) < 1 || buffer[0] & 0x80) - return 1; - tag_length <<= 7; - tag_length |= (buffer[0] & 0x7f); - } - - /* skip the rest of the tag */ - if(seek_cb(handle, tag_length, SEEK_CUR) < 0) - return 2; - - /* read the stream sync code */ - errno = 0; - n = read_cb(buffer, 1, 4, handle); - if(errno) - return 1; - else if(n != 4) - return 3; - } - - /* check for the fLaC signature */ - if(0 == memcmp(FLAC__STREAM_SYNC_STRING, buffer, FLAC__STREAM_SYNC_LENGTH)) - return 0; - else - return 3; -} - -uint32_t seek_to_first_metadata_block_(FILE *f) -{ - return seek_to_first_metadata_block_cb_((FLAC__IOHandle)f, (FLAC__IOCallback_Read)fread, fseek_wrapper_); -} - -FLAC__bool simple_iterator_copy_file_prefix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, FLAC__bool append) -{ - const FLAC__off_t offset_end = append? iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length : iterator->offset[iterator->depth]; - - if(0 != fseeko(iterator->file, 0, SEEK_SET)) { - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - if(!open_tempfile_(iterator->filename, iterator->tempfile_path_prefix, tempfile, tempfilename, &iterator->status)) { - cleanup_tempfile_(tempfile, tempfilename); - return false; - } - if(!copy_n_bytes_from_file_(iterator->file, *tempfile, offset_end, &iterator->status)) { - cleanup_tempfile_(tempfile, tempfilename); - return false; - } - - return true; -} - -FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, FLAC__off_t fixup_is_last_flag_offset, FLAC__bool backup) -{ - FLAC__off_t save_offset = iterator->offset[iterator->depth]; - FLAC__ASSERT(0 != *tempfile); - - if(0 != fseeko(iterator->file, save_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length, SEEK_SET)) { - cleanup_tempfile_(tempfile, tempfilename); - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - if(!copy_remaining_bytes_from_file_(iterator->file, *tempfile, &iterator->status)) { - cleanup_tempfile_(tempfile, tempfilename); - return false; - } - - if(fixup_is_last_code != 0) { - /* - * if code == 1, it means a block was appended to the end so - * we have to clear the is_last flag of the previous block - * if code == -1, it means the last block was deleted so - * we have to set the is_last flag of the previous block - */ - /* MAGIC NUMBERs here; we know the is_last flag is the high bit of the byte at this location */ - FLAC__byte x; - if(0 != fseeko(*tempfile, fixup_is_last_flag_offset, SEEK_SET)) { - cleanup_tempfile_(tempfile, tempfilename); - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - if(fread(&x, 1, 1, *tempfile) != 1) { - cleanup_tempfile_(tempfile, tempfilename); - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - if(fixup_is_last_code > 0) { - FLAC__ASSERT(x & 0x80); - x &= 0x7f; - } - else { - FLAC__ASSERT(!(x & 0x80)); - x |= 0x80; - } - if(0 != fseeko(*tempfile, fixup_is_last_flag_offset, SEEK_SET)) { - cleanup_tempfile_(tempfile, tempfilename); - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR; - return false; - } - if(local__fwrite(&x, 1, 1, *tempfile) != 1) { - cleanup_tempfile_(tempfile, tempfilename); - iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - } - - (void)fclose(iterator->file); - - if(!transport_tempfile_(iterator->filename, tempfile, tempfilename, &iterator->status)) - return false; - - if(iterator->has_stats) - set_file_stats_(iterator->filename, &iterator->stats); - - if(!simple_iterator_prime_input_(iterator, !iterator->is_writable)) - return false; - if(backup) { - while(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length < save_offset) - if(!FLAC__metadata_simple_iterator_next(iterator)) - return false; - return true; - } - else { - /* move the iterator to it's original block faster by faking a push, then doing a pop_ */ - FLAC__ASSERT(iterator->depth == 0); - iterator->offset[0] = save_offset; - iterator->depth++; - return simple_iterator_pop_(iterator); - } -} - -FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status) -{ - FLAC__byte buffer[8192]; - size_t n; - - FLAC__ASSERT(bytes >= 0); - while(bytes > 0) { - n = flac_min(sizeof(buffer), (size_t)bytes); - if(fread(buffer, 1, n, file) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - if(local__fwrite(buffer, 1, n, tempfile) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - bytes -= n; - } - - return true; -} - -FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status) -{ - FLAC__byte buffer[8192]; - size_t n; - - FLAC__ASSERT(bytes >= 0); - while(bytes > 0) { - n = flac_min(sizeof(buffer), (size_t)bytes); - if(read_cb(buffer, 1, n, handle) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - if(temp_write_cb(buffer, 1, n, temp_handle) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - bytes -= n; - } - - return true; -} - -FLAC__bool copy_remaining_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__Metadata_SimpleIteratorStatus *status) -{ - FLAC__byte buffer[8192]; - size_t n; - - while(!feof(file)) { - n = fread(buffer, 1, sizeof(buffer), file); - if(n == 0 && !feof(file)) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - if(n > 0 && local__fwrite(buffer, 1, n, tempfile) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - } - - return true; -} - -FLAC__bool copy_remaining_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__Metadata_SimpleIteratorStatus *status) -{ - FLAC__byte buffer[8192]; - size_t n; - - while(!eof_cb(handle)) { - n = read_cb(buffer, 1, sizeof(buffer), handle); - if(n == 0 && !eof_cb(handle)) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; - return false; - } - if(n > 0 && temp_write_cb(buffer, 1, n, temp_handle) != n) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; - return false; - } - } - - return true; -} - -static int -local_snprintf(char *str, size_t size, const char *fmt, ...) -{ - va_list va; - int rc; - -#if defined _MSC_VER - if (size == 0) - return 1024; -#endif - - va_start (va, fmt); - -#if defined _MSC_VER - rc = vsnprintf_s (str, size, _TRUNCATE, fmt, va); - if (rc < 0) - rc = size - 1; -#elif defined __MINGW32__ - rc = __mingw_vsnprintf (str, size, fmt, va); -#else - rc = vsnprintf (str, size, fmt, va); -#endif - va_end (va); - - return rc; -} - -FLAC__bool open_tempfile_(const char *filename, const char *tempfile_path_prefix, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status) -{ - static const char *tempfile_suffix = ".metadata_edit"; - if(0 == tempfile_path_prefix) { - size_t dest_len = strlen(filename) + strlen(tempfile_suffix) + 1; - if(0 == (*tempfilename = safe_malloc_(dest_len))) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - local_snprintf(*tempfilename, dest_len, "%s%s", filename, tempfile_suffix); - } - else { - const char *p = strrchr(filename, '/'); - size_t dest_len; - if(0 == p) - p = filename; - else - p++; - - dest_len = strlen(tempfile_path_prefix) + strlen(p) + strlen(tempfile_suffix) + 2; - - if(0 == (*tempfilename = safe_malloc_(dest_len))) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; - return false; - } - local_snprintf(*tempfilename, dest_len, "%s/%s%s", tempfile_path_prefix, p, tempfile_suffix); - } - - if(0 == (*tempfile = flac_fopen(*tempfilename, "w+b"))) { - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE; - return false; - } - - return true; -} - -FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != tempfile); - FLAC__ASSERT(0 != *tempfile); - FLAC__ASSERT(0 != tempfilename); - FLAC__ASSERT(0 != *tempfilename); - FLAC__ASSERT(0 != status); - - (void)fclose(*tempfile); - *tempfile = 0; - -#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ || defined __EMX__ - /* on some flavors of windows, flac_rename() will fail if the destination already exists */ - if(flac_unlink(filename) < 0) { - cleanup_tempfile_(tempfile, tempfilename); - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR; - return false; - } -#endif - - /*@@@ to fully support the tempfile_path_prefix we need to update this piece to actually copy across filesystems instead of just flac_rename(): */ - if(0 != flac_rename(*tempfilename, filename)) { - cleanup_tempfile_(tempfile, tempfilename); - *status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR; - return false; - } - - cleanup_tempfile_(tempfile, tempfilename); - - return true; -} - -void cleanup_tempfile_(FILE **tempfile, char **tempfilename) -{ - if(0 != *tempfile) { - (void)fclose(*tempfile); - *tempfile = 0; - } - - if(0 != *tempfilename) { - (void)flac_unlink(*tempfilename); - free(*tempfilename); - *tempfilename = 0; - } -} - -FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stats) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - return (0 == flac_stat(filename, stats)); -} - -void set_file_stats_(const char *filename, struct flac_stat_s *stats) -{ -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) && !defined(_WIN32) - struct timespec srctime[2] = {}; - srctime[0].tv_sec = stats->st_atime; - srctime[1].tv_sec = stats->st_mtime; -#else - struct utimbuf srctime; - srctime.actime = stats->st_atime; - srctime.modtime = stats->st_mtime; -#endif - - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - - (void)flac_chmod(filename, stats->st_mode); - (void)flac_utime(filename, &srctime); -#if !defined _MSC_VER && !defined __BORLANDC__ && !defined __MINGW32__ - FLAC_CHECK_RETURN(chown(filename, stats->st_uid, -1)); - FLAC_CHECK_RETURN(chown(filename, -1, stats->st_gid)); -#endif -} - -int fseek_wrapper_(FLAC__IOHandle handle, FLAC__int64 offset, int whence) -{ - return fseeko((FILE*)handle, (FLAC__off_t)offset, whence); -} - -FLAC__int64 ftell_wrapper_(FLAC__IOHandle handle) -{ - return ftello((FILE*)handle); -} - -FLAC__Metadata_ChainStatus get_equivalent_status_(FLAC__Metadata_SimpleIteratorStatus status) -{ - switch(status) { - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK: - return FLAC__METADATA_CHAIN_STATUS_OK; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT: - return FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE: - return FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE: - return FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE: - return FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA: - return FLAC__METADATA_CHAIN_STATUS_BAD_METADATA; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR: - return FLAC__METADATA_CHAIN_STATUS_READ_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR: - return FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR: - return FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR: - return FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR: - return FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR: - return FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR; - case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR: - default: - return FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; - } -} diff --git a/flac/src/libFLAC/metadata_object.c b/flac/src/libFLAC/metadata_object.c deleted file mode 100644 index 73e7607..0000000 --- a/flac/src/libFLAC/metadata_object.c +++ /dev/null @@ -1,2018 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include "private/metadata.h" -#include "private/memory.h" -#include "private/stream_encoder_framing.h" - -#include "FLAC/assert.h" -#include "FLAC/stream_decoder.h" -#include "share/alloc.h" -#include "share/compat.h" - -/* Alias the first (in share/alloc.h) to the second (in src/libFLAC/memory.c). */ -#define safe_malloc_mul_2op_ safe_malloc_mul_2op_p - - -/**************************************************************************** - * - * Local routines - * - ***************************************************************************/ - -/* copy bytes: - * from = NULL && bytes = 0 - * to <- NULL - * from != NULL && bytes > 0 - * to <- copy of from - * else ASSERT - * malloc error leaves 'to' unchanged - */ -static FLAC__bool copy_bytes_(FLAC__byte **to, const FLAC__byte *from, uint32_t bytes) -{ - FLAC__ASSERT(to != NULL); - if (bytes > 0 && from != NULL) { - FLAC__byte *x; - if ((x = safe_malloc_(bytes)) == NULL) - return false; - memcpy(x, from, bytes); - *to = x; - } - else { - *to = 0; - } - return true; -} - -#if 0 /* UNUSED */ -/* like copy_bytes_(), but free()s the original '*to' if the copy succeeds and the original '*to' is non-NULL */ -static FLAC__bool free_copy_bytes_(FLAC__byte **to, const FLAC__byte *from, uint32_t bytes) -{ - FLAC__byte *copy; - FLAC__ASSERT(to != NULL); - if (copy_bytes_(©, from, bytes)) { - free(*to); - *to = copy; - return true; - } - else - return false; -} -#endif - -/* reallocate entry to 1 byte larger and add a terminating NUL */ -/* realloc() failure leaves entry unchanged */ -static FLAC__bool ensure_null_terminated_(FLAC__byte **entry, uint32_t length) -{ - FLAC__byte *x = safe_realloc_nofree_add_2op_(*entry, length, /*+*/1); - if (x != NULL) { - x[length] = '\0'; - *entry = x; - return true; - } - else - return false; -} - -/* copies the NUL-terminated C-string 'from' to '*to', leaving '*to' - * unchanged if malloc fails, free()ing the original '*to' if it - * succeeds and the original '*to' was not NULL - */ -static FLAC__bool copy_cstring_(char **to, const char *from) -{ - char *copy = strdup(from); - FLAC__ASSERT(to != NULL); - if (copy) { - free(*to); - *to = copy; - return true; - } - else - return false; -} - -static FLAC__bool copy_vcentry_(FLAC__StreamMetadata_VorbisComment_Entry *to, const FLAC__StreamMetadata_VorbisComment_Entry *from) -{ - to->length = from->length; - if (from->entry == 0) { - FLAC__ASSERT(from->length == 0); - if ((to->entry = safe_malloc_(1)) == NULL) - return false; - to->entry[0] = '\0'; - } - else { - FLAC__byte *x; - if ((x = safe_malloc_add_2op_(from->length, /*+*/1)) == NULL) - return false; - memcpy(x, from->entry, from->length); - x[from->length] = '\0'; - to->entry = x; - } - return true; -} - -static FLAC__bool copy_track_(FLAC__StreamMetadata_CueSheet_Track *to, const FLAC__StreamMetadata_CueSheet_Track *from) -{ - memcpy(to, from, sizeof(FLAC__StreamMetadata_CueSheet_Track)); - if (from->indices == 0) { - FLAC__ASSERT(from->num_indices == 0); - } - else { - FLAC__StreamMetadata_CueSheet_Index *x; - FLAC__ASSERT(from->num_indices > 0); - if ((x = safe_malloc_mul_2op_p(from->num_indices, /*times*/sizeof(FLAC__StreamMetadata_CueSheet_Index))) == NULL) - return false; - memcpy(x, from->indices, from->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index)); - to->indices = x; - } - return true; -} - -static void seektable_calculate_length_(FLAC__StreamMetadata *object) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - object->length = object->data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH; -} - -static FLAC__StreamMetadata_SeekPoint *seekpoint_array_new_(uint32_t num_points) -{ - FLAC__StreamMetadata_SeekPoint *object_array; - - FLAC__ASSERT(num_points > 0); - - object_array = safe_malloc_mul_2op_p(num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint)); - - if (object_array != NULL) { - uint32_t i; - for (i = 0; i < num_points; i++) { - object_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - object_array[i].stream_offset = 0; - object_array[i].frame_samples = 0; - } - } - - return object_array; -} - -static void vorbiscomment_calculate_length_(FLAC__StreamMetadata *object) -{ - uint32_t i; - - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - object->length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN) / 8; - object->length += object->data.vorbis_comment.vendor_string.length; - object->length += (FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8; - for (i = 0; i < object->data.vorbis_comment.num_comments; i++) { - object->length += (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8); - object->length += object->data.vorbis_comment.comments[i].length; - } -} - -static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_new_(uint32_t num_comments) -{ - FLAC__ASSERT(num_comments > 0); - - return safe_calloc_(num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)); -} - -static void vorbiscomment_entry_array_delete_(FLAC__StreamMetadata_VorbisComment_Entry *object_array, uint32_t num_comments) -{ - uint32_t i; - - FLAC__ASSERT(object_array != NULL); - - for (i = 0; i < num_comments; i++) - free(object_array[i].entry); - - free(object_array); -} - -static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_copy_(const FLAC__StreamMetadata_VorbisComment_Entry *object_array, uint32_t num_comments) -{ - FLAC__StreamMetadata_VorbisComment_Entry *return_array; - - FLAC__ASSERT(object_array != NULL); - FLAC__ASSERT(num_comments > 0); - - return_array = vorbiscomment_entry_array_new_(num_comments); - - if (return_array != NULL) { - uint32_t i; - - for (i = 0; i < num_comments; i++) { - if (!copy_vcentry_(return_array+i, object_array+i)) { - vorbiscomment_entry_array_delete_(return_array, num_comments); - return 0; - } - } - } - - return return_array; -} - -static FLAC__bool vorbiscomment_set_entry_(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry *dest, const FLAC__StreamMetadata_VorbisComment_Entry *src, FLAC__bool copy) -{ - FLAC__byte *save; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(dest != NULL); - FLAC__ASSERT(src != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT((src->entry != NULL && src->length > 0) || (src->entry == NULL && src->length == 0)); - - save = dest->entry; - - if (src->entry != NULL) { - if (copy) { - /* do the copy first so that if we fail we leave the dest object untouched */ - if (!copy_vcentry_(dest, src)) - return false; - } - else { - /* we have to make sure that the string we're taking over is null-terminated */ - - /* - * Stripping the const from src->entry is OK since we're taking - * ownership of the pointer. This is a hack around a deficiency - * in the API where the same function is used for 'copy' and - * 'own', but the source entry is a const pointer. If we were - * precise, the 'own' flavor would be a separate function with a - * non-const source pointer. But it's not, so we hack away. - */ - if (!ensure_null_terminated_((FLAC__byte**)(&src->entry), src->length)) - return false; - *dest = *src; - } - } - else { - /* the src is null */ - *dest = *src; - } - - free(save); - - vorbiscomment_calculate_length_(object); - return true; -} - -static int vorbiscomment_find_entry_from_(const FLAC__StreamMetadata *object, uint32_t offset, const char *field_name, uint32_t field_name_length) -{ - uint32_t i; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(field_name != NULL); - - for (i = offset; i < object->data.vorbis_comment.num_comments; i++) { - if (FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) - return (int)i; - } - - return -1; -} - -static void cuesheet_calculate_length_(FLAC__StreamMetadata *object) -{ - uint32_t i; - - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - - object->length = ( - FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN + - FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + - FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN - ) / 8; - - object->length += object->data.cue_sheet.num_tracks * ( - FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN - ) / 8; - - for (i = 0; i < object->data.cue_sheet.num_tracks; i++) { - object->length += object->data.cue_sheet.tracks[i].num_indices * ( - FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN + - FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN - ) / 8; - } -} - -static FLAC__StreamMetadata_CueSheet_Index *cuesheet_track_index_array_new_(uint32_t num_indices) -{ - FLAC__ASSERT(num_indices > 0); - - return safe_calloc_(num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)); -} - -static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_new_(uint32_t num_tracks) -{ - FLAC__ASSERT(num_tracks > 0); - - return safe_calloc_(num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)); -} - -static void cuesheet_track_array_delete_(FLAC__StreamMetadata_CueSheet_Track *object_array, uint32_t num_tracks) -{ - uint32_t i; - - FLAC__ASSERT(object_array != NULL && num_tracks > 0); - - for (i = 0; i < num_tracks; i++) { - if (object_array[i].indices != 0) { - FLAC__ASSERT(object_array[i].num_indices > 0); - free(object_array[i].indices); - } - } - - free(object_array); -} - -static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_copy_(const FLAC__StreamMetadata_CueSheet_Track *object_array, uint32_t num_tracks) -{ - FLAC__StreamMetadata_CueSheet_Track *return_array; - - FLAC__ASSERT(object_array != NULL); - FLAC__ASSERT(num_tracks > 0); - - return_array = cuesheet_track_array_new_(num_tracks); - - if (return_array != NULL) { - uint32_t i; - - for (i = 0; i < num_tracks; i++) { - if (!copy_track_(return_array+i, object_array+i)) { - cuesheet_track_array_delete_(return_array, num_tracks); - return 0; - } - } - } - - return return_array; -} - -static FLAC__bool cuesheet_set_track_(FLAC__StreamMetadata *object, FLAC__StreamMetadata_CueSheet_Track *dest, const FLAC__StreamMetadata_CueSheet_Track *src, FLAC__bool copy) -{ - FLAC__StreamMetadata_CueSheet_Index *save; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(dest != NULL); - FLAC__ASSERT(src != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT((src->indices != NULL && src->num_indices > 0) || (src->indices == NULL && src->num_indices == 0)); - - save = dest->indices; - - /* do the copy first so that if we fail we leave the object untouched */ - if (copy) { - if (!copy_track_(dest, src)) - return false; - } - else { - *dest = *src; - } - - free(save); - - cuesheet_calculate_length_(object); - return true; -} - - -/**************************************************************************** - * - * Metadata object routines - * - ***************************************************************************/ - -FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type) -{ - FLAC__StreamMetadata *object; - - if (type > FLAC__MAX_METADATA_TYPE) - return 0; - - object = calloc(1, sizeof(FLAC__StreamMetadata)); - if (object != NULL) { - object->is_last = false; - object->type = type; - switch(type) { - case FLAC__METADATA_TYPE_STREAMINFO: - object->length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH; - break; - case FLAC__METADATA_TYPE_PADDING: - /* calloc() took care of this for us: - object->length = 0; - */ - break; - case FLAC__METADATA_TYPE_APPLICATION: - object->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8; - /* calloc() took care of this for us: - object->data.application.data = 0; - */ - break; - case FLAC__METADATA_TYPE_SEEKTABLE: - /* calloc() took care of this for us: - object->length = 0; - object->data.seek_table.num_points = 0; - object->data.seek_table.points = 0; - */ - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - object->data.vorbis_comment.vendor_string.length = (uint32_t)strlen(FLAC__VENDOR_STRING); - if (!copy_bytes_(&object->data.vorbis_comment.vendor_string.entry, (const FLAC__byte*)FLAC__VENDOR_STRING, object->data.vorbis_comment.vendor_string.length+1)) { - free(object); - return 0; - } - vorbiscomment_calculate_length_(object); - break; - case FLAC__METADATA_TYPE_CUESHEET: - cuesheet_calculate_length_(object); - break; - case FLAC__METADATA_TYPE_PICTURE: - object->length = ( - FLAC__STREAM_METADATA_PICTURE_TYPE_LEN + - FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* empty mime_type string */ - FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* empty description string */ - FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN + - FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN + - FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN + - FLAC__STREAM_METADATA_PICTURE_COLORS_LEN + - FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN + - 0 /* no data */ - ) / 8; - object->data.picture.type = FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER; - object->data.picture.mime_type = 0; - object->data.picture.description = 0; - /* calloc() took care of this for us: - object->data.picture.width = 0; - object->data.picture.height = 0; - object->data.picture.depth = 0; - object->data.picture.colors = 0; - object->data.picture.data_length = 0; - object->data.picture.data = 0; - */ - /* now initialize mime_type and description with empty strings to make things easier on the client */ - if (!copy_cstring_(&object->data.picture.mime_type, "")) { - free(object); - return 0; - } - if (!copy_cstring_((char**)(&object->data.picture.description), "")) { - free(object->data.picture.mime_type); - free(object); - return 0; - } - break; - default: - /* calloc() took care of this for us: - object->length = 0; - object->data.unknown.data = 0; - */ - break; - } - } - - return object; -} - -FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object) -{ - FLAC__StreamMetadata *to; - - FLAC__ASSERT(object != NULL); - - if ((to = FLAC__metadata_object_new(object->type)) != NULL) { - to->is_last = object->is_last; - to->type = object->type; - to->length = object->length; - switch(to->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - memcpy(&to->data.stream_info, &object->data.stream_info, sizeof(FLAC__StreamMetadata_StreamInfo)); - break; - case FLAC__METADATA_TYPE_PADDING: - break; - case FLAC__METADATA_TYPE_APPLICATION: - if (to->length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) { /* underflow check */ - FLAC__metadata_object_delete(to); - return 0; - } - memcpy(&to->data.application.id, &object->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8); - if (!copy_bytes_(&to->data.application.data, object->data.application.data, object->length - FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)) { - FLAC__metadata_object_delete(to); - return 0; - } - break; - case FLAC__METADATA_TYPE_SEEKTABLE: - to->data.seek_table.num_points = object->data.seek_table.num_points; - if (to->data.seek_table.num_points > UINT32_MAX / sizeof(FLAC__StreamMetadata_SeekPoint)) { /* overflow check */ - FLAC__metadata_object_delete(to); - return 0; - } - if (!copy_bytes_((FLAC__byte**)&to->data.seek_table.points, (FLAC__byte*)object->data.seek_table.points, object->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint))) { - FLAC__metadata_object_delete(to); - return 0; - } - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - if (to->data.vorbis_comment.vendor_string.entry != NULL) { - free(to->data.vorbis_comment.vendor_string.entry); - to->data.vorbis_comment.vendor_string.entry = 0; - } - if (!copy_vcentry_(&to->data.vorbis_comment.vendor_string, &object->data.vorbis_comment.vendor_string)) { - FLAC__metadata_object_delete(to); - return 0; - } - if (object->data.vorbis_comment.num_comments == 0) { - to->data.vorbis_comment.comments = 0; - } - else { - to->data.vorbis_comment.comments = vorbiscomment_entry_array_copy_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments); - if (to->data.vorbis_comment.comments == NULL) { - to->data.vorbis_comment.num_comments = 0; - FLAC__metadata_object_delete(to); - return 0; - } - } - to->data.vorbis_comment.num_comments = object->data.vorbis_comment.num_comments; - break; - case FLAC__METADATA_TYPE_CUESHEET: - memcpy(&to->data.cue_sheet, &object->data.cue_sheet, sizeof(FLAC__StreamMetadata_CueSheet)); - if (object->data.cue_sheet.num_tracks == 0) { - FLAC__ASSERT(object->data.cue_sheet.tracks == NULL); - } - else { - FLAC__ASSERT(object->data.cue_sheet.tracks != 0); - to->data.cue_sheet.tracks = cuesheet_track_array_copy_(object->data.cue_sheet.tracks, object->data.cue_sheet.num_tracks); - if (to->data.cue_sheet.tracks == NULL) { - FLAC__metadata_object_delete(to); - return 0; - } - } - break; - case FLAC__METADATA_TYPE_PICTURE: - to->data.picture.type = object->data.picture.type; - if (!copy_cstring_(&to->data.picture.mime_type, object->data.picture.mime_type)) { - FLAC__metadata_object_delete(to); - return 0; - } - if (!copy_cstring_((char**)(&to->data.picture.description), (const char*)object->data.picture.description)) { - FLAC__metadata_object_delete(to); - return 0; - } - to->data.picture.width = object->data.picture.width; - to->data.picture.height = object->data.picture.height; - to->data.picture.depth = object->data.picture.depth; - to->data.picture.colors = object->data.picture.colors; - to->data.picture.data_length = object->data.picture.data_length; - if (!copy_bytes_((&to->data.picture.data), object->data.picture.data, object->data.picture.data_length)) { - FLAC__metadata_object_delete(to); - return 0; - } - break; - default: - if (!copy_bytes_(&to->data.unknown.data, object->data.unknown.data, object->length)) { - FLAC__metadata_object_delete(to); - return 0; - } - break; - } - } - - return to; -} - -void FLAC__metadata_object_delete_data(FLAC__StreamMetadata *object) -{ - FLAC__ASSERT(object != NULL); - - switch(object->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - case FLAC__METADATA_TYPE_PADDING: - break; - case FLAC__METADATA_TYPE_APPLICATION: - if (object->data.application.data != NULL) { - free(object->data.application.data); - object->data.application.data = NULL; - } - break; - case FLAC__METADATA_TYPE_SEEKTABLE: - if (object->data.seek_table.points != NULL) { - free(object->data.seek_table.points); - object->data.seek_table.points = NULL; - } - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - if (object->data.vorbis_comment.vendor_string.entry != NULL) { - free(object->data.vorbis_comment.vendor_string.entry); - object->data.vorbis_comment.vendor_string.entry = 0; - } - if (object->data.vorbis_comment.comments != NULL) { - vorbiscomment_entry_array_delete_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments); - object->data.vorbis_comment.comments = NULL; - object->data.vorbis_comment.num_comments = 0; - } - break; - case FLAC__METADATA_TYPE_CUESHEET: - if (object->data.cue_sheet.tracks != NULL) { - FLAC__ASSERT(object->data.cue_sheet.num_tracks > 0); - cuesheet_track_array_delete_(object->data.cue_sheet.tracks, object->data.cue_sheet.num_tracks); - object->data.cue_sheet.tracks = NULL; - object->data.cue_sheet.num_tracks = 0; - } - break; - case FLAC__METADATA_TYPE_PICTURE: - if (object->data.picture.mime_type != NULL) { - free(object->data.picture.mime_type); - object->data.picture.mime_type = NULL; - } - if (object->data.picture.description != NULL) { - free(object->data.picture.description); - object->data.picture.description = NULL; - } - if (object->data.picture.data != NULL) { - free(object->data.picture.data); - object->data.picture.data = NULL; - } - break; - default: - if (object->data.unknown.data != NULL) { - free(object->data.unknown.data); - object->data.unknown.data = NULL; - } - break; - } -} - -FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object) -{ - FLAC__metadata_object_delete_data(object); - free(object); -} - -static FLAC__bool compare_block_data_streaminfo_(const FLAC__StreamMetadata_StreamInfo *block1, const FLAC__StreamMetadata_StreamInfo *block2) -{ - if (block1->min_blocksize != block2->min_blocksize) - return false; - if (block1->max_blocksize != block2->max_blocksize) - return false; - if (block1->min_framesize != block2->min_framesize) - return false; - if (block1->max_framesize != block2->max_framesize) - return false; - if (block1->sample_rate != block2->sample_rate) - return false; - if (block1->channels != block2->channels) - return false; - if (block1->bits_per_sample != block2->bits_per_sample) - return false; - if (block1->total_samples != block2->total_samples) - return false; - if (memcmp(block1->md5sum, block2->md5sum, 16) != 0) - return false; - return true; -} - -static FLAC__bool compare_block_data_application_(const FLAC__StreamMetadata_Application *block1, const FLAC__StreamMetadata_Application *block2, uint32_t block_length) -{ - FLAC__ASSERT(block1 != NULL); - FLAC__ASSERT(block2 != NULL); - FLAC__ASSERT(block_length >= sizeof(block1->id)); - - if (memcmp(block1->id, block2->id, sizeof(block1->id)) != 0) - return false; - if (block1->data != NULL && block2->data != NULL) - return memcmp(block1->data, block2->data, block_length - sizeof(block1->id)) == 0; - else - return block1->data == block2->data; -} - -static FLAC__bool compare_block_data_seektable_(const FLAC__StreamMetadata_SeekTable *block1, const FLAC__StreamMetadata_SeekTable *block2) -{ - uint32_t i; - - FLAC__ASSERT(block1 != NULL); - FLAC__ASSERT(block2 != NULL); - - if (block1->num_points != block2->num_points) - return false; - - if (block1->points != NULL && block2->points != NULL) { - for (i = 0; i < block1->num_points; i++) { - if (block1->points[i].sample_number != block2->points[i].sample_number) - return false; - if (block1->points[i].stream_offset != block2->points[i].stream_offset) - return false; - if (block1->points[i].frame_samples != block2->points[i].frame_samples) - return false; - } - return true; - } - else - return block1->points == block2->points; -} - -static FLAC__bool compare_block_data_vorbiscomment_(const FLAC__StreamMetadata_VorbisComment *block1, const FLAC__StreamMetadata_VorbisComment *block2) -{ - uint32_t i; - - if (block1->vendor_string.length != block2->vendor_string.length) - return false; - - if (block1->vendor_string.entry != NULL && block2->vendor_string.entry != NULL) { - if (memcmp(block1->vendor_string.entry, block2->vendor_string.entry, block1->vendor_string.length) != 0) - return false; - } - else if (block1->vendor_string.entry != block2->vendor_string.entry) - return false; - - if (block1->num_comments != block2->num_comments) - return false; - - for (i = 0; i < block1->num_comments; i++) { - if (block1->comments[i].entry != NULL && block2->comments[i].entry != NULL) { - if (memcmp(block1->comments[i].entry, block2->comments[i].entry, block1->comments[i].length) != 0) - return false; - } - else if (block1->comments[i].entry != block2->comments[i].entry) - return false; - } - return true; -} - -static FLAC__bool compare_block_data_cuesheet_(const FLAC__StreamMetadata_CueSheet *block1, const FLAC__StreamMetadata_CueSheet *block2) -{ - uint32_t i, j; - - if (strcmp(block1->media_catalog_number, block2->media_catalog_number) != 0) - return false; - - if (block1->lead_in != block2->lead_in) - return false; - - if (block1->is_cd != block2->is_cd) - return false; - - if (block1->num_tracks != block2->num_tracks) - return false; - - if (block1->tracks != NULL && block2->tracks != NULL) { - FLAC__ASSERT(block1->num_tracks > 0); - for (i = 0; i < block1->num_tracks; i++) { - if (block1->tracks[i].offset != block2->tracks[i].offset) - return false; - if (block1->tracks[i].number != block2->tracks[i].number) - return false; - if (memcmp(block1->tracks[i].isrc, block2->tracks[i].isrc, sizeof(block1->tracks[i].isrc)) != 0) - return false; - if (block1->tracks[i].type != block2->tracks[i].type) - return false; - if (block1->tracks[i].pre_emphasis != block2->tracks[i].pre_emphasis) - return false; - if (block1->tracks[i].num_indices != block2->tracks[i].num_indices) - return false; - if (block1->tracks[i].indices != NULL && block2->tracks[i].indices != NULL) { - FLAC__ASSERT(block1->tracks[i].num_indices > 0); - for (j = 0; j < block1->tracks[i].num_indices; j++) { - if (block1->tracks[i].indices[j].offset != block2->tracks[i].indices[j].offset) - return false; - if (block1->tracks[i].indices[j].number != block2->tracks[i].indices[j].number) - return false; - } - } - else if (block1->tracks[i].indices != block2->tracks[i].indices) - return false; - } - } - else if (block1->tracks != block2->tracks) - return false; - return true; -} - -static FLAC__bool compare_block_data_picture_(const FLAC__StreamMetadata_Picture *block1, const FLAC__StreamMetadata_Picture *block2) -{ - if (block1->type != block2->type) - return false; - if (block1->mime_type != block2->mime_type && (block1->mime_type == 0 || block2->mime_type == 0 || strcmp(block1->mime_type, block2->mime_type))) - return false; - if (block1->description != block2->description && (block1->description == 0 || block2->description == 0 || strcmp((const char *)block1->description, (const char *)block2->description))) - return false; - if (block1->width != block2->width) - return false; - if (block1->height != block2->height) - return false; - if (block1->depth != block2->depth) - return false; - if (block1->colors != block2->colors) - return false; - if (block1->data_length != block2->data_length) - return false; - if (block1->data != block2->data && (block1->data == NULL || block2->data == NULL || memcmp(block1->data, block2->data, block1->data_length))) - return false; - return true; -} - -static FLAC__bool compare_block_data_unknown_(const FLAC__StreamMetadata_Unknown *block1, const FLAC__StreamMetadata_Unknown *block2, uint32_t block_length) -{ - FLAC__ASSERT(block1 != NULL); - FLAC__ASSERT(block2 != NULL); - - if (block1->data != NULL && block2->data != NULL) - return memcmp(block1->data, block2->data, block_length) == 0; - else - return block1->data == block2->data; -} - -FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2) -{ - FLAC__ASSERT(block1 != NULL); - FLAC__ASSERT(block2 != NULL); - - if (block1->type != block2->type) { - return false; - } - if (block1->is_last != block2->is_last) { - return false; - } - if (block1->length != block2->length) { - return false; - } - switch(block1->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - return compare_block_data_streaminfo_(&block1->data.stream_info, &block2->data.stream_info); - case FLAC__METADATA_TYPE_PADDING: - return true; /* we don't compare the padding guts */ - case FLAC__METADATA_TYPE_APPLICATION: - return compare_block_data_application_(&block1->data.application, &block2->data.application, block1->length); - case FLAC__METADATA_TYPE_SEEKTABLE: - return compare_block_data_seektable_(&block1->data.seek_table, &block2->data.seek_table); - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - return compare_block_data_vorbiscomment_(&block1->data.vorbis_comment, &block2->data.vorbis_comment); - case FLAC__METADATA_TYPE_CUESHEET: - return compare_block_data_cuesheet_(&block1->data.cue_sheet, &block2->data.cue_sheet); - case FLAC__METADATA_TYPE_PICTURE: - return compare_block_data_picture_(&block1->data.picture, &block2->data.picture); - default: - return compare_block_data_unknown_(&block1->data.unknown, &block2->data.unknown, block1->length); - } -} - -FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, uint32_t length, FLAC__bool copy) -{ - FLAC__byte *save; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_APPLICATION); - FLAC__ASSERT((data != NULL && length > 0) || (data == NULL && length == 0 && copy == false)); - - save = object->data.application.data; - - /* do the copy first so that if we fail we leave the object untouched */ - if (copy) { - if (!copy_bytes_(&object->data.application.data, data, length)) - return false; - } - else { - object->data.application.data = data; - } - - free(save); - - object->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8 + length; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, uint32_t new_num_points) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - if((FLAC__uint64)(new_num_points) * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) - return false; - - if (object->data.seek_table.points == 0) { - FLAC__ASSERT(object->data.seek_table.num_points == 0); - if (new_num_points == 0) - return true; - else if ((object->data.seek_table.points = seekpoint_array_new_(new_num_points)) == 0) - return false; - } - else { - const size_t old_size = object->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint); - const size_t new_size = new_num_points * sizeof(FLAC__StreamMetadata_SeekPoint); - - /* overflow check */ - if (new_num_points > UINT32_MAX / sizeof(FLAC__StreamMetadata_SeekPoint)) - return false; - - FLAC__ASSERT(object->data.seek_table.num_points > 0); - - if (new_size == 0) { - free(object->data.seek_table.points); - object->data.seek_table.points = 0; - } - else { - /* Leave object->data.seek_table.points untouched if realloc fails */ - FLAC__StreamMetadata_SeekPoint *tmpptr; - if ((tmpptr = realloc(object->data.seek_table.points, new_size)) == NULL) - return false; - object->data.seek_table.points = tmpptr; - } - - /* if growing, set new elements to placeholders */ - if (new_size > old_size) { - uint32_t i; - for (i = object->data.seek_table.num_points; i < new_num_points; i++) { - object->data.seek_table.points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - object->data.seek_table.points[i].stream_offset = 0; - object->data.seek_table.points[i].frame_samples = 0; - } - } - } - - object->data.seek_table.num_points = new_num_points; - - seektable_calculate_length_(object); - return true; -} - -FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, uint32_t point_num, FLAC__StreamMetadata_SeekPoint point) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - FLAC__ASSERT(point_num < object->data.seek_table.num_points); - - object->data.seek_table.points[point_num] = point; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, uint32_t point_num, FLAC__StreamMetadata_SeekPoint point) -{ - int i; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - FLAC__ASSERT(point_num <= object->data.seek_table.num_points); - - if (!FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points+1)) - return false; - - /* move all points >= point_num forward one space */ - for (i = (int)object->data.seek_table.num_points-1; i > (int)point_num; i--) - object->data.seek_table.points[i] = object->data.seek_table.points[i-1]; - - FLAC__metadata_object_seektable_set_point(object, point_num, point); - seektable_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, uint32_t point_num) -{ - uint32_t i; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - FLAC__ASSERT(point_num < object->data.seek_table.num_points); - - /* move all points > point_num backward one space */ - for (i = point_num; i < object->data.seek_table.num_points-1; i++) - object->data.seek_table.points[i] = object->data.seek_table.points[i+1]; - - return FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points-1); -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - return FLAC__format_seektable_is_legal(&object->data.seek_table); -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, uint32_t num) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - if (num > 0) - /* WATCHOUT: we rely on the fact that growing the array adds PLACEHOLDERS at the end */ - return FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points + num); - else - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number) -{ - FLAC__StreamMetadata_SeekTable *seek_table; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - seek_table = &object->data.seek_table; - - if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + 1)) - return false; - - seek_table->points[seek_table->num_points - 1].sample_number = sample_number; - seek_table->points[seek_table->num_points - 1].stream_offset = 0; - seek_table->points[seek_table->num_points - 1].frame_samples = 0; - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], uint32_t num) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - FLAC__ASSERT(sample_numbers != 0 || num == 0); - - if (num > 0) { - FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table; - uint32_t i, j; - - i = seek_table->num_points; - - if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num)) - return false; - - for (j = 0; j < num; i++, j++) { - seek_table->points[i].sample_number = sample_numbers[j]; - seek_table->points[i].stream_offset = 0; - seek_table->points[i].frame_samples = 0; - } - } - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, uint32_t num, FLAC__uint64 total_samples) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - if (num > 0 && total_samples > 0) { - FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table; - uint32_t i, j; - - i = seek_table->num_points; - - if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num)) - return false; - - for (j = 0; j < num; i++, j++) { - seek_table->points[i].sample_number = total_samples * (FLAC__uint64)j / (FLAC__uint64)num; - seek_table->points[i].stream_offset = 0; - seek_table->points[i].frame_samples = 0; - } - } - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, uint32_t samples, FLAC__uint64 total_samples) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - if (samples > 0 && total_samples > 0) { - FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table; - uint32_t i, j; - FLAC__uint64 num, sample; - - num = 1 + total_samples / samples; /* 1+ for the first sample at 0 */ - /* now account for the fact that we don't place a seekpoint at "total_samples" since samples are number from 0: */ - if (total_samples % samples == 0) - num--; - - /* Put a strict upper bound on the number of allowed seek points. */ - if (num > 32768) { - /* Set the bound and recalculate samples accordingly. */ - num = 32768; - samples = (uint32_t)(total_samples / num); - } - - i = seek_table->num_points; - - if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + (uint32_t)num)) - return false; - - sample = 0; - for (j = 0; j < num; i++, j++, sample += samples) { - seek_table->points[i].sample_number = sample; - seek_table->points[i].stream_offset = 0; - seek_table->points[i].frame_samples = 0; - } - } - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact) -{ - uint32_t unique; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE); - - unique = FLAC__format_seektable_sort(&object->data.seek_table); - - return !compact || FLAC__metadata_object_seektable_resize_points(object, unique); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy) -{ - if (!FLAC__format_vorbiscomment_entry_value_is_legal(entry.entry, entry.length)) - return false; - return vorbiscomment_set_entry_(object, &object->data.vorbis_comment.vendor_string, &entry, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, uint32_t new_num_comments) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - if (object->data.vorbis_comment.comments == NULL) { - FLAC__ASSERT(object->data.vorbis_comment.num_comments == 0); - if (new_num_comments == 0) - return true; - else { - uint32_t i; - if ((object->data.vorbis_comment.comments = vorbiscomment_entry_array_new_(new_num_comments)) == NULL) - return false; - for (i = 0; i < new_num_comments; i++) { - object->data.vorbis_comment.comments[i].length = 0; - if ((object->data.vorbis_comment.comments[i].entry = safe_malloc_(1)) == NULL) { - object->data.vorbis_comment.num_comments = i+1; - return false; - } - object->data.vorbis_comment.comments[i].entry[0] = '\0'; - } - } - } - else { - const size_t old_size = object->data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry); - const size_t new_size = new_num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry); - - /* overflow check */ - if (new_num_comments > UINT32_MAX / sizeof(FLAC__StreamMetadata_VorbisComment_Entry)) - return false; - - FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0); - - /* if shrinking, free the truncated entries */ - if (new_num_comments < object->data.vorbis_comment.num_comments) { - uint32_t i; - for (i = new_num_comments; i < object->data.vorbis_comment.num_comments; i++) - if (object->data.vorbis_comment.comments[i].entry != NULL) - free(object->data.vorbis_comment.comments[i].entry); - } - - if (new_size == 0) { - free(object->data.vorbis_comment.comments); - object->data.vorbis_comment.comments = 0; - } - else { - /* Leave object->data.vorbis_comment.comments untouched if realloc fails */ - FLAC__StreamMetadata_VorbisComment_Entry *tmpptr; - if ((tmpptr = realloc(object->data.vorbis_comment.comments, new_size)) == NULL) - return false; - object->data.vorbis_comment.comments = tmpptr; - } - - /* if growing, zero all the length/pointers of new elements */ - if (new_size > old_size) { - uint32_t i; - for (i = object->data.vorbis_comment.num_comments; i < new_num_comments; i++) { - object->data.vorbis_comment.comments[i].length = 0; - if ((object->data.vorbis_comment.comments[i].entry = safe_malloc_(1)) == NULL) { - object->data.vorbis_comment.num_comments = i+1; - return false; - } - object->data.vorbis_comment.comments[i].entry[0] = '\0'; - } - } - } - - object->data.vorbis_comment.num_comments = new_num_comments; - - vorbiscomment_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, uint32_t comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(comment_num < object->data.vorbis_comment.num_comments); - - if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) - return false; - return vorbiscomment_set_entry_(object, &object->data.vorbis_comment.comments[comment_num], &entry, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, uint32_t comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy) -{ - FLAC__StreamMetadata_VorbisComment *vc; - FLAC__StreamMetadata_VorbisComment_Entry temp; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(comment_num <= object->data.vorbis_comment.num_comments); - - if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) - return false; - - vc = &object->data.vorbis_comment; - - if (!FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments+1)) - return false; - - /* move all comments >= comment_num forward one space */ - /* reuse newly added empty comment */ - temp = vc->comments[vc->num_comments-1]; - memmove(&vc->comments[comment_num+1], &vc->comments[comment_num], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(vc->num_comments-1-comment_num)); - vc->comments[comment_num] = temp; - - return FLAC__metadata_object_vorbiscomment_set_comment(object, comment_num, entry, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - return FLAC__metadata_object_vorbiscomment_insert_comment(object, object->data.vorbis_comment.num_comments, entry, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy) -{ - FLAC__ASSERT(entry.entry != NULL); - - if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) - return false; - - { - int i; - size_t field_name_length; - const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length); - - if (eq == NULL) - return false; /* double protection */ - - field_name_length = eq-entry.entry; - - i = vorbiscomment_find_entry_from_(object, 0, (const char *)entry.entry, field_name_length); - if (i >= 0) { - uint32_t indx = (uint32_t)i; - if (!FLAC__metadata_object_vorbiscomment_set_comment(object, indx, entry, copy)) - return false; - entry = object->data.vorbis_comment.comments[indx]; - indx++; /* skip over replaced comment */ - if (all && indx < object->data.vorbis_comment.num_comments) { - i = vorbiscomment_find_entry_from_(object, indx, (const char *)entry.entry, field_name_length); - while (i >= 0) { - indx = (uint32_t)i; - if (!FLAC__metadata_object_vorbiscomment_delete_comment(object, indx)) - return false; - if (indx < object->data.vorbis_comment.num_comments) - i = vorbiscomment_find_entry_from_(object, indx, (const char *)entry.entry, field_name_length); - else - i = -1; - } - } - return true; - } - else - return FLAC__metadata_object_vorbiscomment_append_comment(object, entry, copy); - } -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, uint32_t comment_num) -{ - FLAC__StreamMetadata_VorbisComment *vc; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(comment_num < object->data.vorbis_comment.num_comments); - - vc = &object->data.vorbis_comment; - - /* free the comment at comment_num */ - free(vc->comments[comment_num].entry); - - /* move all comments > comment_num backward one space */ - memmove(&vc->comments[comment_num], &vc->comments[comment_num+1], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(vc->num_comments-comment_num-1)); - vc->comments[vc->num_comments-1].length = 0; - vc->comments[vc->num_comments-1].entry = 0; - - return FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments-1); -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field_name, const char *field_value) -{ - FLAC__ASSERT(entry != NULL); - FLAC__ASSERT(field_name != NULL); - FLAC__ASSERT(field_value != NULL); - - if (!FLAC__format_vorbiscomment_entry_name_is_legal(field_name)) - return false; - if (!FLAC__format_vorbiscomment_entry_value_is_legal((const FLAC__byte *)field_value, (uint32_t)(-1))) - return false; - - { - const size_t nn = strlen(field_name); - const size_t nv = strlen(field_value); - entry->length = nn + 1 /*=*/ + nv; - if ((entry->entry = safe_malloc_add_4op_(nn, /*+*/1, /*+*/nv, /*+*/1)) == NULL) - return false; - memcpy(entry->entry, field_name, nn); - entry->entry[nn] = '='; - memcpy(entry->entry+nn+1, field_value, nv); - entry->entry[entry->length] = '\0'; - } - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(const FLAC__StreamMetadata_VorbisComment_Entry entry, char **field_name, char **field_value) -{ - FLAC__ASSERT(entry.entry != NULL); - FLAC__ASSERT(field_name != NULL); - FLAC__ASSERT(field_value != NULL); - - if (!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) - return false; - - { - const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length); - const size_t nn = eq-entry.entry; - const size_t nv = entry.length-nn-1; /* -1 for the '=' */ - - if (eq == NULL) - return false; /* double protection */ - if ((*field_name = safe_malloc_add_2op_(nn, /*+*/1)) == NULL) - return false; - if ((*field_value = safe_malloc_add_2op_(nv, /*+*/1)) == NULL) { - free(*field_name); - return false; - } - memcpy(*field_name, entry.entry, nn); - memcpy(*field_value, entry.entry+nn+1, nv); - (*field_name)[nn] = '\0'; - (*field_value)[nv] = '\0'; - } - - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, uint32_t field_name_length) -{ - FLAC__ASSERT(entry.entry != NULL); - { - const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length); - return (eq != NULL && (uint32_t)(eq-entry.entry) == field_name_length && FLAC__STRNCASECMP(field_name, (const char *)entry.entry, field_name_length) == 0); - } -} - -FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, uint32_t offset, const char *field_name) -{ - FLAC__ASSERT(field_name != NULL); - - return vorbiscomment_find_entry_from_(object, offset, field_name, strlen(field_name)); -} - -FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name) -{ - const uint32_t field_name_length = strlen(field_name); - uint32_t i; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - for (i = 0; i < object->data.vorbis_comment.num_comments; i++) { - if (FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) { - if (!FLAC__metadata_object_vorbiscomment_delete_comment(object, i)) - return -1; - else - return 1; - } - } - - return 0; -} - -FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name) -{ - FLAC__bool ok = true; - uint32_t matching = 0; - const uint32_t field_name_length = strlen(field_name); - int i; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - /* must delete from end to start otherwise it will interfere with our iteration */ - for (i = (int)object->data.vorbis_comment.num_comments - 1; ok && i >= 0; i--) { - if (FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) { - matching++; - ok &= FLAC__metadata_object_vorbiscomment_delete_comment(object, (uint32_t)i); - } - } - - return ok? (int)matching : -1; -} - -FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void) -{ - return calloc(1, sizeof(FLAC__StreamMetadata_CueSheet_Track)); -} - -FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object) -{ - FLAC__StreamMetadata_CueSheet_Track *to; - - FLAC__ASSERT(object != NULL); - - if ((to = FLAC__metadata_object_cuesheet_track_new()) != NULL) { - if (!copy_track_(to, object)) { - FLAC__metadata_object_cuesheet_track_delete(to); - return 0; - } - } - - return to; -} - -void FLAC__metadata_object_cuesheet_track_delete_data(FLAC__StreamMetadata_CueSheet_Track *object) -{ - FLAC__ASSERT(object != NULL); - - if (object->indices != NULL) { - FLAC__ASSERT(object->num_indices > 0); - free(object->indices); - } -} - -FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object) -{ - FLAC__metadata_object_cuesheet_track_delete_data(object); - free(object); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t new_num_indices) -{ - FLAC__StreamMetadata_CueSheet_Track *track; - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks); - - track = &object->data.cue_sheet.tracks[track_num]; - - if (track->indices == NULL) { - FLAC__ASSERT(track->num_indices == 0); - if (new_num_indices == 0) - return true; - else if ((track->indices = cuesheet_track_index_array_new_(new_num_indices)) == NULL) - return false; - } - else { - const size_t old_size = track->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index); - const size_t new_size = new_num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index); - - /* overflow check */ - if (new_num_indices > UINT32_MAX / sizeof(FLAC__StreamMetadata_CueSheet_Index)) - return false; - - FLAC__ASSERT(track->num_indices > 0); - - if (new_size == 0) { - free(track->indices); - track->indices = 0; - } - else { - /* Leave track->indices untouched if realloc fails */ - FLAC__StreamMetadata_CueSheet_Index *tmpptr; - if ((tmpptr = realloc(track->indices, new_size)) == NULL) - return false; - track->indices = tmpptr; - } - - /* if growing, zero all the lengths/pointers of new elements */ - if (new_size > old_size) - memset(track->indices + track->num_indices, 0, new_size - old_size); - } - - track->num_indices = new_num_indices; - - cuesheet_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num, FLAC__StreamMetadata_CueSheet_Index indx) -{ - FLAC__StreamMetadata_CueSheet_Track *track; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks); - FLAC__ASSERT(index_num <= object->data.cue_sheet.tracks[track_num].num_indices); - - track = &object->data.cue_sheet.tracks[track_num]; - - if (!FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices+1)) - return false; - - /* move all indices >= index_num forward one space */ - memmove(&track->indices[index_num+1], &track->indices[index_num], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(track->num_indices-1-index_num)); - - track->indices[index_num] = indx; - cuesheet_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num) -{ - FLAC__StreamMetadata_CueSheet_Index indx; - memset(&indx, 0, sizeof(indx)); - return FLAC__metadata_object_cuesheet_track_insert_index(object, track_num, index_num, indx); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, uint32_t track_num, uint32_t index_num) -{ - FLAC__StreamMetadata_CueSheet_Track *track; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks); - FLAC__ASSERT(index_num < object->data.cue_sheet.tracks[track_num].num_indices); - - track = &object->data.cue_sheet.tracks[track_num]; - - /* move all indices > index_num backward one space */ - memmove(&track->indices[index_num], &track->indices[index_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(track->num_indices-index_num-1)); - - FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices-1); - cuesheet_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, uint32_t new_num_tracks) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - - if (object->data.cue_sheet.tracks == NULL) { - FLAC__ASSERT(object->data.cue_sheet.num_tracks == 0); - if (new_num_tracks == 0) - return true; - else if ((object->data.cue_sheet.tracks = cuesheet_track_array_new_(new_num_tracks)) == NULL) - return false; - } - else { - const size_t old_size = object->data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track); - const size_t new_size = new_num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track); - - /* overflow check */ - if (new_num_tracks > UINT32_MAX / sizeof(FLAC__StreamMetadata_CueSheet_Track)) - return false; - - FLAC__ASSERT(object->data.cue_sheet.num_tracks > 0); - - /* if shrinking, free the truncated entries */ - if (new_num_tracks < object->data.cue_sheet.num_tracks) { - uint32_t i; - for (i = new_num_tracks; i < object->data.cue_sheet.num_tracks; i++) - free(object->data.cue_sheet.tracks[i].indices); - } - - if (new_size == 0) { - free(object->data.cue_sheet.tracks); - object->data.cue_sheet.tracks = 0; - } - else { - /* Leave object->data.cue_sheet.tracks untouched if realloc fails */ - FLAC__StreamMetadata_CueSheet_Track *tmpptr; - if ((tmpptr = realloc(object->data.cue_sheet.tracks, new_size)) == NULL) - return false; - object->data.cue_sheet.tracks = tmpptr; - } - - /* if growing, zero all the lengths/pointers of new elements */ - if (new_size > old_size) - memset(object->data.cue_sheet.tracks + object->data.cue_sheet.num_tracks, 0, new_size - old_size); - } - - object->data.cue_sheet.num_tracks = new_num_tracks; - - cuesheet_calculate_length_(object); - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, uint32_t track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks); - - return cuesheet_set_track_(object, object->data.cue_sheet.tracks + track_num, track, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, uint32_t track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy) -{ - FLAC__StreamMetadata_CueSheet *cs; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT(track_num <= object->data.cue_sheet.num_tracks); - - cs = &object->data.cue_sheet; - - if (!FLAC__metadata_object_cuesheet_resize_tracks(object, cs->num_tracks+1)) - return false; - - /* move all tracks >= track_num forward one space */ - memmove(&cs->tracks[track_num+1], &cs->tracks[track_num], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(cs->num_tracks-1-track_num)); - cs->tracks[track_num].num_indices = 0; - cs->tracks[track_num].indices = 0; - - return FLAC__metadata_object_cuesheet_set_track(object, track_num, track, copy); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, uint32_t track_num) -{ - FLAC__StreamMetadata_CueSheet_Track track; - memset(&track, 0, sizeof(track)); - return FLAC__metadata_object_cuesheet_insert_track(object, track_num, &track, /*copy=*/false); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, uint32_t track_num) -{ - FLAC__StreamMetadata_CueSheet *cs; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks); - - cs = &object->data.cue_sheet; - - /* free the track at track_num */ - free(cs->tracks[track_num].indices); - - /* move all tracks > track_num backward one space */ - memmove(&cs->tracks[track_num], &cs->tracks[track_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(cs->num_tracks-track_num-1)); - cs->tracks[cs->num_tracks-1].num_indices = 0; - cs->tracks[cs->num_tracks-1].indices = 0; - - return FLAC__metadata_object_cuesheet_resize_tracks(object, cs->num_tracks-1); -} - -FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - - return FLAC__format_cuesheet_is_legal(&object->data.cue_sheet, check_cd_da_subset, violation); -} - -static FLAC__uint64 get_index_01_offset_(const FLAC__StreamMetadata_CueSheet *cs, uint32_t track) -{ - if (track >= (cs->num_tracks-1) || cs->tracks[track].num_indices < 1) - return 0; - else if (cs->tracks[track].indices[0].number == 1) - return cs->tracks[track].indices[0].offset + cs->tracks[track].offset + cs->lead_in; - else if (cs->tracks[track].num_indices < 2) - return 0; - else if (cs->tracks[track].indices[1].number == 1) - return cs->tracks[track].indices[1].offset + cs->tracks[track].offset + cs->lead_in; - else - return 0; -} - -static FLAC__uint32 cddb_add_digits_(FLAC__uint32 x) -{ - FLAC__uint32 n = 0; - while (x) { - n += (x%10); - x /= 10; - } - return n; -} - -/*@@@@add to tests*/ -FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object) -{ - const FLAC__StreamMetadata_CueSheet *cs; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET); - - cs = &object->data.cue_sheet; - - if (cs->num_tracks < 2) /* need at least one real track and the lead-out track */ - return 0; - - { - FLAC__uint32 i, length, sum = 0; - for (i = 0; i < (cs->num_tracks-1); i++) /* -1 to avoid counting the lead-out */ - sum += cddb_add_digits_((FLAC__uint32)(get_index_01_offset_(cs, i) / 44100)); - length = (FLAC__uint32)((cs->tracks[cs->num_tracks-1].offset+cs->lead_in) / 44100) - (FLAC__uint32)(get_index_01_offset_(cs, 0) / 44100); - - return (sum % 0xFF) << 24 | length << 8 | (FLAC__uint32)(cs->num_tracks-1); - } -} - -FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy) -{ - char *old; - size_t old_length, new_length; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE); - FLAC__ASSERT(mime_type != NULL); - - old = object->data.picture.mime_type; - old_length = old? strlen(old) : 0; - new_length = strlen(mime_type); - - /* do the copy first so that if we fail we leave the object untouched */ - if (copy) { - if (new_length >= SIZE_MAX) /* overflow check */ - return false; - if (!copy_bytes_((FLAC__byte**)(&object->data.picture.mime_type), (FLAC__byte*)mime_type, new_length+1)) - return false; - } - else { - object->data.picture.mime_type = mime_type; - } - - free(old); - - object->length -= old_length; - object->length += new_length; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy) -{ - FLAC__byte *old; - size_t old_length, new_length; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE); - FLAC__ASSERT(description != NULL); - - old = object->data.picture.description; - old_length = old? strlen((const char *)old) : 0; - new_length = strlen((const char *)description); - - /* do the copy first so that if we fail we leave the object untouched */ - if (copy) { - if (new_length >= SIZE_MAX) /* overflow check */ - return false; - if (!copy_bytes_(&object->data.picture.description, description, new_length+1)) - return false; - } - else { - object->data.picture.description = description; - } - - free(old); - - object->length -= old_length; - object->length += new_length; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy) -{ - FLAC__byte *old; - - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE); - FLAC__ASSERT((data != NULL && length > 0) || (data == NULL && length == 0 && copy == false)); - - old = object->data.picture.data; - - /* do the copy first so that if we fail we leave the object untouched */ - if (copy) { - if (!copy_bytes_(&object->data.picture.data, data, length)) - return false; - } - else { - object->data.picture.data = data; - } - - free(old); - - object->length -= object->data.picture.data_length; - object->data.picture.data_length = length; - object->length += length; - return true; -} - -FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation) -{ - FLAC__ASSERT(object != NULL); - FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE); - - return FLAC__format_picture_is_legal(&object->data.picture, violation); -} - -FLAC_API FLAC__byte * FLAC__metadata_object_get_raw(const FLAC__StreamMetadata *object) -{ - FLAC__BitWriter *bw; - const FLAC__byte * buffer; - FLAC__byte * output; - size_t bytes; - - FLAC__ASSERT(object != NULL); - - if((bw = FLAC__bitwriter_new()) == NULL) - return 0; - if(!FLAC__bitwriter_init(bw)) { - FLAC__bitwriter_delete(bw); - return 0; - } - if(!FLAC__add_metadata_block(object, bw, false)) { - FLAC__bitwriter_delete(bw); - return 0; - } - - if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes)) { - FLAC__bitwriter_delete(bw); - return 0; - } - - /* Extra check whether length of bitwriter agrees with length of metadata block */ - if(bytes != (object->length+FLAC__STREAM_METADATA_HEADER_LENGTH)) { - FLAC__bitwriter_delete(bw); - return 0; - } - - output = safe_malloc_(bytes); - if(output == 0) { - FLAC__bitwriter_delete(bw); - return 0; - } - - memcpy(output,buffer,bytes); - FLAC__bitwriter_delete(bw); - return output; -} - -/* The following callbacks are for FLAC__metadata_object_set_raw */ - -static FLAC__StreamDecoderReadStatus read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte *buffer, size_t *bytes, void *client_data); -static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); -static void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); -static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); - -typedef struct { - FLAC__StreamMetadata *object; - FLAC__bool got_error; - FLAC__byte *buffer; - FLAC__int32 length; - FLAC__int32 tell; -} set_raw_client_data; - -FLAC_API FLAC__StreamMetadata * FLAC__metadata_object_set_raw(FLAC__byte *buffer, FLAC__uint32 length) -{ - set_raw_client_data cd; - FLAC__StreamDecoder * decoder; - - cd.buffer = buffer; - cd.length = length; - cd.got_error = false; - cd.object = 0; - cd.tell = -4; - - decoder = FLAC__stream_decoder_new(); - - if(0 == decoder) - return 0; - - FLAC__stream_decoder_set_md5_checking(decoder, false); - FLAC__stream_decoder_set_metadata_respond_all(decoder); - - if(FLAC__stream_decoder_init_stream(decoder, read_callback_, NULL, NULL, NULL, NULL, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) { - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - return 0; - } - - if((!FLAC__stream_decoder_process_until_end_of_metadata(decoder) && FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_END_OF_STREAM) || cd.got_error) { - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - if(0 != cd.object) - FLAC__metadata_object_delete(cd.object); - return 0; - } - - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - - return cd.object; - -} - -FLAC__StreamDecoderReadStatus read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte *buffer, size_t *bytes, void *client_data) -{ - set_raw_client_data *cd = (set_raw_client_data *)client_data; - (void)decoder; - - if(cd->tell == -4) { - if(*bytes < 4) - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - buffer[0] = 'f'; - buffer[1] = 'L'; - buffer[2] = 'a'; - buffer[3] = 'C'; - *bytes = 4; - cd->tell = 0; - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - else if(cd->tell < 0) - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - else if(cd->tell == cd->length) { - *bytes = 0; - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - } - else { - if((FLAC__int32)(*bytes) > (cd->length - cd->tell)) - *bytes = cd->length - cd->tell; - memcpy(buffer, cd->buffer+cd->tell, *bytes); - cd->tell += *bytes; - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } -} - -FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - (void)decoder, (void)frame, (void)buffer, (void)client_data; - - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - set_raw_client_data *cd = (set_raw_client_data *)client_data; - (void)decoder; - - /* - * we assume we only get here when the one metadata block we were - * looking for was passed to us - */ - if(!cd->got_error && 0 == cd->object) { - if(0 == (cd->object = FLAC__metadata_object_clone(metadata))) - cd->got_error = true; - } -} - -void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - set_raw_client_data *cd = (set_raw_client_data *)client_data; - (void)decoder; - - if(status != FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC) - cd->got_error = true; -} diff --git a/flac/src/libFLAC/ogg_decoder_aspect.c b/flac/src/libFLAC/ogg_decoder_aspect.c deleted file mode 100644 index 58a2934..0000000 --- a/flac/src/libFLAC/ogg_decoder_aspect.c +++ /dev/null @@ -1,251 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include /* for memcpy() */ -#include "FLAC/assert.h" -#include "private/ogg_decoder_aspect.h" -#include "private/ogg_mapping.h" -#include "private/macros.h" - - -/*********************************************************************** - * - * Public class methods - * - ***********************************************************************/ - -FLAC__bool FLAC__ogg_decoder_aspect_init(FLAC__OggDecoderAspect *aspect) -{ - /* we will determine the serial number later if necessary */ - if(ogg_stream_init(&aspect->stream_state, aspect->serial_number) != 0) - return false; - - if(ogg_sync_init(&aspect->sync_state) != 0) - return false; - - aspect->version_major = ~(0u); - aspect->version_minor = ~(0u); - - aspect->need_serial_number = aspect->use_first_serial_number; - - aspect->end_of_stream = false; - aspect->have_working_page = false; - - return true; -} - -void FLAC__ogg_decoder_aspect_finish(FLAC__OggDecoderAspect *aspect) -{ - (void)ogg_sync_clear(&aspect->sync_state); - (void)ogg_stream_clear(&aspect->stream_state); -} - -void FLAC__ogg_decoder_aspect_set_serial_number(FLAC__OggDecoderAspect *aspect, long value) -{ - aspect->use_first_serial_number = false; - aspect->serial_number = value; -} - -void FLAC__ogg_decoder_aspect_set_defaults(FLAC__OggDecoderAspect *aspect) -{ - aspect->use_first_serial_number = true; -} - -void FLAC__ogg_decoder_aspect_flush(FLAC__OggDecoderAspect *aspect) -{ - (void)ogg_stream_reset(&aspect->stream_state); - (void)ogg_sync_reset(&aspect->sync_state); - aspect->end_of_stream = false; - aspect->have_working_page = false; -} - -void FLAC__ogg_decoder_aspect_reset(FLAC__OggDecoderAspect *aspect) -{ - FLAC__ogg_decoder_aspect_flush(aspect); - - if(aspect->use_first_serial_number) - aspect->need_serial_number = true; -} - -FLAC__OggDecoderAspectReadStatus FLAC__ogg_decoder_aspect_read_callback_wrapper(FLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], size_t *bytes, FLAC__OggDecoderAspectReadCallbackProxy read_callback, const FLAC__StreamDecoder *decoder, void *client_data) -{ - static const size_t OGG_BYTES_CHUNK = 8192; - const size_t bytes_requested = *bytes; - - /* - * The FLAC decoding API uses pull-based reads, whereas Ogg decoding - * is push-based. In libFLAC, when you ask to decode a frame, the - * decoder will eventually call the read callback to supply some data, - * but how much it asks for depends on how much free space it has in - * its internal buffer. It does not try to grow its internal buffer - * to accommodate a whole frame because then the internal buffer size - * could not be limited, which is necessary in embedded applications. - * - * Ogg however grows its internal buffer until a whole page is present; - * only then can you get decoded data out. So we can't just ask for - * the same number of bytes from Ogg, then pass what's decoded down to - * libFLAC. If what libFLAC is asking for will not contain a whole - * page, then we will get no data from ogg_sync_pageout(), and at the - * same time cannot just read more data from the client for the purpose - * of getting a whole decoded page because the decoded size might be - * larger than libFLAC's internal buffer. - * - * Instead, whenever this read callback wrapper is called, we will - * continually request data from the client until we have at least one - * page, and manage pages internally so that we can send pieces of - * pages down to libFLAC in such a way that we obey its size - * requirement. To limit the amount of callbacks, we will always try - * to read in enough pages to return the full number of bytes - * requested. - */ - *bytes = 0; - while (*bytes < bytes_requested && !aspect->end_of_stream) { - if (aspect->have_working_page) { - if (aspect->have_working_packet) { - size_t n = bytes_requested - *bytes; - if ((size_t)aspect->working_packet.bytes <= n) { - /* the rest of the packet will fit in the buffer */ - n = aspect->working_packet.bytes; - memcpy(buffer, aspect->working_packet.packet, n); - *bytes += n; - buffer += n; - aspect->have_working_packet = false; - } - else { - /* only n bytes of the packet will fit in the buffer */ - memcpy(buffer, aspect->working_packet.packet, n); - *bytes += n; - buffer += n; - aspect->working_packet.packet += n; - aspect->working_packet.bytes -= n; - } - } - else { - /* try and get another packet */ - const int ret = ogg_stream_packetout(&aspect->stream_state, &aspect->working_packet); - if (ret > 0) { - aspect->have_working_packet = true; - /* if it is the first header packet, check for magic and a supported Ogg FLAC mapping version */ - if (aspect->working_packet.bytes > 0 && aspect->working_packet.packet[0] == FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE) { - const FLAC__byte *b = aspect->working_packet.packet; - const uint32_t header_length = - FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH + - FLAC__OGG_MAPPING_MAGIC_LENGTH + - FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH + - FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH + - FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH; - if (aspect->working_packet.bytes < (long)header_length) - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC; - b += FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH; - if (memcmp(b, FLAC__OGG_MAPPING_MAGIC, FLAC__OGG_MAPPING_MAGIC_LENGTH)) - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC; - b += FLAC__OGG_MAPPING_MAGIC_LENGTH; - aspect->version_major = (uint32_t)(*b); - b += FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH; - aspect->version_minor = (uint32_t)(*b); - if (aspect->version_major != 1) - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION; - aspect->working_packet.packet += header_length; - aspect->working_packet.bytes -= header_length; - } - } - else if (ret == 0) { - aspect->have_working_page = false; - } - else { /* ret < 0 */ - /* lost sync, we'll leave the working page for the next call */ - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC; - } - } - } - else { - /* try and get another page */ - const int ret = ogg_sync_pageout(&aspect->sync_state, &aspect->working_page); - if (ret > 0) { - /* got a page, grab the serial number if necessary */ - if(aspect->need_serial_number) { - aspect->stream_state.serialno = aspect->serial_number = ogg_page_serialno(&aspect->working_page); - aspect->need_serial_number = false; - } - if(ogg_stream_pagein(&aspect->stream_state, &aspect->working_page) == 0) { - aspect->have_working_page = true; - aspect->have_working_packet = false; - } - /* else do nothing, could be a page from another stream */ - } - else if (ret == 0) { - /* need more data */ - const size_t ogg_bytes_to_read = flac_max(bytes_requested - *bytes, OGG_BYTES_CHUNK); - char *oggbuf = ogg_sync_buffer(&aspect->sync_state, ogg_bytes_to_read); - - if(0 == oggbuf) { - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR; - } - else { - size_t ogg_bytes_read = ogg_bytes_to_read; - - switch(read_callback(decoder, (FLAC__byte*)oggbuf, &ogg_bytes_read, client_data)) { - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK: - break; - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM: - aspect->end_of_stream = true; - break; - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT: - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT; - default: - FLAC__ASSERT(0); - } - - if(ogg_sync_wrote(&aspect->sync_state, ogg_bytes_read) < 0) { - /* double protection; this will happen if the read callback returns more bytes than the max requested, which would overflow Ogg's internal buffer */ - FLAC__ASSERT(0); - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR; - } - } - } - else { /* ret < 0 */ - /* lost sync, bail out */ - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC; - } - } - } - - if (aspect->end_of_stream && *bytes == 0) { - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM; - } - - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK; -} diff --git a/flac/src/libFLAC/ogg_encoder_aspect.c b/flac/src/libFLAC/ogg_encoder_aspect.c deleted file mode 100644 index a88713b..0000000 --- a/flac/src/libFLAC/ogg_encoder_aspect.c +++ /dev/null @@ -1,228 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include /* for memset() */ -#include "FLAC/assert.h" -#include "private/ogg_encoder_aspect.h" -#include "private/ogg_mapping.h" - -static const FLAC__byte FLAC__OGG_MAPPING_VERSION_MAJOR = 1; -static const FLAC__byte FLAC__OGG_MAPPING_VERSION_MINOR = 0; - -/*********************************************************************** - * - * Public class methods - * - ***********************************************************************/ - -FLAC__bool FLAC__ogg_encoder_aspect_init(FLAC__OggEncoderAspect *aspect) -{ - /* we will determine the serial number later if necessary */ - if(ogg_stream_init(&aspect->stream_state, aspect->serial_number) != 0) - return false; - - aspect->seen_magic = false; - aspect->is_first_packet = true; - aspect->samples_written = 0; - - return true; -} - -void FLAC__ogg_encoder_aspect_finish(FLAC__OggEncoderAspect *aspect) -{ - (void)ogg_stream_clear(&aspect->stream_state); - /*@@@ what about the page? */ -} - -void FLAC__ogg_encoder_aspect_set_serial_number(FLAC__OggEncoderAspect *aspect, long value) -{ - aspect->serial_number = value; -} - -FLAC__bool FLAC__ogg_encoder_aspect_set_num_metadata(FLAC__OggEncoderAspect *aspect, uint32_t value) -{ - if(value < (1u << FLAC__OGG_MAPPING_NUM_HEADERS_LEN)) { - aspect->num_metadata = value; - return true; - } - else - return false; -} - -void FLAC__ogg_encoder_aspect_set_defaults(FLAC__OggEncoderAspect *aspect) -{ - aspect->serial_number = 0; - aspect->num_metadata = 0; -} - -/* - * The basic FLAC -> Ogg mapping goes like this: - * - * - 'fLaC' magic and STREAMINFO block get combined into the first - * packet. The packet is prefixed with - * + the one-byte packet type 0x7F - * + 'FLAC' magic - * + the 2 byte Ogg FLAC mapping version number - * + tne 2 byte big-endian # of header packets - * - The first packet is flushed to the first page. - * - Each subsequent metadata block goes into its own packet. - * - Each metadata packet is flushed to page (this is not required, - * the mapping only requires that a flush must occur after all - * metadata is written). - * - Each subsequent FLAC audio frame goes into its own packet. - * - * WATCHOUT: - * This depends on the behavior of FLAC__StreamEncoder that we get a - * separate write callback for the fLaC magic, and then separate write - * callbacks for each metadata block and audio frame. - */ -FLAC__StreamEncoderWriteStatus FLAC__ogg_encoder_aspect_write_callback_wrapper(FLAC__OggEncoderAspect *aspect, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, FLAC__bool is_last_block, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data) -{ - /* WATCHOUT: - * This depends on the behavior of FLAC__StreamEncoder that 'samples' - * will be 0 for metadata writes. - */ - const FLAC__bool is_metadata = (samples == 0); - - /* - * Treat fLaC magic packet specially. We will note when we see it, then - * wait until we get the STREAMINFO and prepend it in that packet - */ - if(aspect->seen_magic) { - ogg_packet packet; - FLAC__byte synthetic_first_packet_body[ - FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH + - FLAC__OGG_MAPPING_MAGIC_LENGTH + - FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH + - FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH + - FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH + - FLAC__STREAM_SYNC_LENGTH + - FLAC__STREAM_METADATA_HEADER_LENGTH + - FLAC__STREAM_METADATA_STREAMINFO_LENGTH - ]; - - memset(&packet, 0, sizeof(packet)); - packet.granulepos = aspect->samples_written + samples; - - if(aspect->is_first_packet) { - FLAC__byte *b = synthetic_first_packet_body; - if(bytes != FLAC__STREAM_METADATA_HEADER_LENGTH + FLAC__STREAM_METADATA_STREAMINFO_LENGTH) { - /* - * If we get here, our assumption about the way write callbacks happen - * (explained above) is wrong - */ - FLAC__ASSERT(0); - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - /* add first header packet type */ - *b = FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE; - b += FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH; - /* add 'FLAC' mapping magic */ - memcpy(b, FLAC__OGG_MAPPING_MAGIC, FLAC__OGG_MAPPING_MAGIC_LENGTH); - b += FLAC__OGG_MAPPING_MAGIC_LENGTH; - /* add Ogg FLAC mapping major version number */ - memcpy(b, &FLAC__OGG_MAPPING_VERSION_MAJOR, FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH); - b += FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH; - /* add Ogg FLAC mapping minor version number */ - memcpy(b, &FLAC__OGG_MAPPING_VERSION_MINOR, FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH); - b += FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH; - /* add number of header packets */ - *b = (FLAC__byte)(aspect->num_metadata >> 8); - b++; - *b = (FLAC__byte)(aspect->num_metadata); - b++; - /* add native FLAC 'fLaC' magic */ - memcpy(b, FLAC__STREAM_SYNC_STRING, FLAC__STREAM_SYNC_LENGTH); - b += FLAC__STREAM_SYNC_LENGTH; - /* add STREAMINFO */ - memcpy(b, buffer, bytes); - FLAC__ASSERT(b + bytes - synthetic_first_packet_body == sizeof(synthetic_first_packet_body)); - packet.packet = (uint8_t *)synthetic_first_packet_body; - packet.bytes = sizeof(synthetic_first_packet_body); - - packet.b_o_s = 1; - aspect->is_first_packet = false; - } - else { - packet.packet = (uint8_t *)buffer; - packet.bytes = bytes; - } - - if(is_last_block) { - /* we used to check: - * FLAC__ASSERT(total_samples_estimate == 0 || total_samples_estimate == aspect->samples_written + samples); - * but it's really not useful since total_samples_estimate is an estimate and can be inexact - */ - packet.e_o_s = 1; - } - - if(ogg_stream_packetin(&aspect->stream_state, &packet) != 0) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - - /*@@@ can't figure out a way to pass a useful number for 'samples' to the write_callback, so we'll just pass 0 */ - if(is_metadata) { - while(ogg_stream_flush(&aspect->stream_state, &aspect->page) != 0) { - if(write_callback(encoder, aspect->page.header, aspect->page.header_len, 0, current_frame, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - if(write_callback(encoder, aspect->page.body, aspect->page.body_len, 0, current_frame, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - } - else { - while(ogg_stream_pageout(&aspect->stream_state, &aspect->page) != 0) { - if(write_callback(encoder, aspect->page.header, aspect->page.header_len, 0, current_frame, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - if(write_callback(encoder, aspect->page.body, aspect->page.body_len, 0, current_frame, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - } - } - else if(is_metadata && current_frame == 0 && samples == 0 && bytes == 4 && 0 == memcmp(buffer, FLAC__STREAM_SYNC_STRING, sizeof(FLAC__STREAM_SYNC_STRING))) { - aspect->seen_magic = true; - } - else { - /* - * If we get here, our assumption about the way write callbacks happen - * explained above is wrong - */ - FLAC__ASSERT(0); - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - - aspect->samples_written += samples; - - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; -} diff --git a/flac/src/libFLAC/ogg_helper.c b/flac/src/libFLAC/ogg_helper.c deleted file mode 100644 index a4be34d..0000000 --- a/flac/src/libFLAC/ogg_helper.c +++ /dev/null @@ -1,210 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include /* for malloc() */ -#include /* for memcmp(), memcpy() */ -#include "FLAC/assert.h" -#include "share/alloc.h" -#include "private/ogg_helper.h" -#include "protected/stream_encoder.h" - - -static FLAC__bool full_read_(FLAC__StreamEncoder *encoder, FLAC__byte *buffer, size_t bytes, FLAC__StreamEncoderReadCallback read_callback, void *client_data) -{ - while(bytes > 0) { - size_t bytes_read = bytes; - switch(read_callback(encoder, buffer, &bytes_read, client_data)) { - case FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE: - bytes -= bytes_read; - buffer += bytes_read; - break; - case FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM: - if(bytes_read == 0) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - return false; - } - bytes -= bytes_read; - buffer += bytes_read; - break; - case FLAC__STREAM_ENCODER_READ_STATUS_ABORT: - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - case FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED: - return false; - default: - /* double protection: */ - FLAC__ASSERT(0); - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - } - - return true; -} - -void simple_ogg_page__init(ogg_page *page) -{ - page->header = 0; - page->header_len = 0; - page->body = 0; - page->body_len = 0; -} - -void simple_ogg_page__clear(ogg_page *page) -{ - if(page->header) - free(page->header); - if(page->body) - free(page->body); - simple_ogg_page__init(page); -} - -FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderReadCallback read_callback, void *client_data) -{ - static const uint32_t OGG_HEADER_FIXED_PORTION_LEN = 27; - static const uint32_t OGG_MAX_HEADER_LEN = 27/*OGG_HEADER_FIXED_PORTION_LEN*/ + 255; - FLAC__byte crc[4]; - FLAC__StreamEncoderSeekStatus seek_status; - - FLAC__ASSERT(page->header == 0); - FLAC__ASSERT(page->header_len == 0); - FLAC__ASSERT(page->body == 0); - FLAC__ASSERT(page->body_len == 0); - - /* move the stream pointer to the supposed beginning of the page */ - if(0 == seek_callback) - return false; - if((seek_status = seek_callback((FLAC__StreamEncoder*)encoder, position, client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { - if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - - /* allocate space for the page header */ - if(0 == (page->header = safe_malloc_(OGG_MAX_HEADER_LEN))) { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return false; - } - - /* read in the fixed part of the page header (up to but not including - * the segment table */ - if(!full_read_(encoder, page->header, OGG_HEADER_FIXED_PORTION_LEN, read_callback, client_data)) - return false; - - page->header_len = OGG_HEADER_FIXED_PORTION_LEN + page->header[26]; - - /* check to see if it's a correct, "simple" page (one packet only) */ - if( - memcmp(page->header, "OggS", 4) || /* doesn't start with OggS */ - (page->header[5] & 0x01) || /* continued packet */ - memcmp(page->header+6, "\0\0\0\0\0\0\0\0", 8) || /* granulepos is non-zero */ - page->header[26] == 0 /* packet is 0-size */ - ) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - return false; - } - - /* read in the segment table */ - if(!full_read_(encoder, page->header + OGG_HEADER_FIXED_PORTION_LEN, page->header[26], read_callback, client_data)) - return false; - - { - uint32_t i; - - /* check to see that it specifies a single packet */ - for(i = 0; i < (uint32_t)page->header[26] - 1; i++) { - if(page->header[i + OGG_HEADER_FIXED_PORTION_LEN] != 255) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - return false; - } - } - - page->body_len = 255 * i + page->header[i + OGG_HEADER_FIXED_PORTION_LEN]; - } - - /* allocate space for the page body */ - if(0 == (page->body = safe_malloc_(page->body_len))) { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return false; - } - - /* read in the page body */ - if(!full_read_(encoder, page->body, page->body_len, read_callback, client_data)) - return false; - - /* check the CRC */ - memcpy(crc, page->header+22, 4); - ogg_page_checksum_set(page); - if(memcmp(crc, page->header+22, 4)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - return false; - } - - return true; -} - -FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data) -{ - FLAC__StreamEncoderSeekStatus seek_status; - - FLAC__ASSERT(page->header != 0); - FLAC__ASSERT(page->header_len != 0); - FLAC__ASSERT(page->body != 0); - FLAC__ASSERT(page->body_len != 0); - - /* move the stream pointer to the supposed beginning of the page */ - if(0 == seek_callback) - return false; - if((seek_status = seek_callback((FLAC__StreamEncoder*)encoder, position, client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { - if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - - ogg_page_checksum_set(page); - - /* re-write the page */ - if(write_callback((FLAC__StreamEncoder*)encoder, page->header, page->header_len, 0, 0, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - if(write_callback((FLAC__StreamEncoder*)encoder, page->body, page->body_len, 0, 0, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - - return true; -} diff --git a/flac/src/libFLAC/ogg_mapping.c b/flac/src/libFLAC/ogg_mapping.c deleted file mode 100644 index 756c716..0000000 --- a/flac/src/libFLAC/ogg_mapping.c +++ /dev/null @@ -1,48 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/ogg_mapping.h" - -const uint32_t FLAC__OGG_MAPPING_PACKET_TYPE_LEN = 8; /* bits */ - -const FLAC__byte FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE = 0x7f; - -const FLAC__byte * const FLAC__OGG_MAPPING_MAGIC = (const FLAC__byte * const)"FLAC"; - -const uint32_t FLAC__OGG_MAPPING_VERSION_MAJOR_LEN = 8; /* bits */ -const uint32_t FLAC__OGG_MAPPING_VERSION_MINOR_LEN = 8; /* bits */ - -const uint32_t FLAC__OGG_MAPPING_NUM_HEADERS_LEN = 16; /* bits */ diff --git a/flac/src/libFLAC/stream_decoder.c b/flac/src/libFLAC/stream_decoder.c deleted file mode 100644 index 18d8dd3..0000000 --- a/flac/src/libFLAC/stream_decoder.c +++ /dev/null @@ -1,3731 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include /* for malloc() */ -#include /* for memset/memcpy() */ -#include /* for off_t */ -#include /* for stat() */ -#include "share/compat.h" -#include "FLAC/assert.h" -#include "share/alloc.h" -#include "protected/stream_decoder.h" -#include "private/bitreader.h" -#include "private/bitmath.h" -#include "private/cpu.h" -#include "private/crc.h" -#include "private/fixed.h" -#include "private/format.h" -#include "private/lpc.h" -#include "private/md5.h" -#include "private/memory.h" -#include "private/macros.h" - - -/* technically this should be in an "export.c" but this is convenient enough */ -FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC = FLAC__HAS_OGG; - - -/*********************************************************************** - * - * Private static data - * - ***********************************************************************/ - -static const FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' }; - -/*********************************************************************** - * - * Private class method prototypes - * - ***********************************************************************/ - -static void set_defaults_(FLAC__StreamDecoder *decoder); -static FILE *get_binary_stdin_(void); -static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, uint32_t size, uint32_t channels, uint32_t bps); -static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id); -static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder); -static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder); -static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, uint32_t length); -static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, uint32_t length); -static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj, uint32_t length); -static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj); -static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj); -static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder); -static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder); -static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode); -static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder); -static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode); -static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode); -static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, const uint32_t order, FLAC__bool do_full_decode); -static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, const uint32_t order, FLAC__bool do_full_decode); -static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode); -static FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, uint32_t predictor_order, uint32_t partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended); -static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder); -static void undo_channel_coding(FLAC__StreamDecoder *decoder); -static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data); -#if FLAC__HAS_OGG -static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes); -static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); -#endif -static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]); -static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status); -static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample); -#if FLAC__HAS_OGG -static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample); -#endif -static FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); -static FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); -static FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); -static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); -static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data); - -/*********************************************************************** - * - * Private class data - * - ***********************************************************************/ - -typedef struct FLAC__StreamDecoderPrivate { - FLAC__bool is_ogg; - FLAC__StreamDecoderReadCallback read_callback; - FLAC__StreamDecoderSeekCallback seek_callback; - FLAC__StreamDecoderTellCallback tell_callback; - FLAC__StreamDecoderLengthCallback length_callback; - FLAC__StreamDecoderEofCallback eof_callback; - FLAC__StreamDecoderWriteCallback write_callback; - FLAC__StreamDecoderMetadataCallback metadata_callback; - FLAC__StreamDecoderErrorCallback error_callback; - void *client_data; - FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */ - FLAC__BitReader *input; - FLAC__int32 *output[FLAC__MAX_CHANNELS]; - FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */ - FLAC__int64 *side_subframe; - FLAC__bool side_subframe_in_use; - FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS]; - uint32_t output_capacity, output_channels; - FLAC__uint32 fixed_block_size, next_fixed_block_size; - FLAC__uint64 samples_decoded; - FLAC__bool has_stream_info, has_seek_table; - FLAC__StreamMetadata stream_info; - FLAC__StreamMetadata seek_table; - FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */ - FLAC__byte *metadata_filter_ids; - size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */ - FLAC__Frame frame; - FLAC__bool cached; /* true if there is a byte in lookahead */ - FLAC__CPUInfo cpuinfo; - FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */ - FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */ - /* unaligned (original) pointers to allocated data */ - FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS]; - FLAC__bool do_md5_checking; /* initially gets protected_->md5_checking but is turned off after a seek or if the metadata has a zero MD5 */ - FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */ - FLAC__bool is_seeking; - FLAC__MD5Context md5context; - FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */ - /* (the rest of these are only used for seeking) */ - FLAC__Frame last_frame; /* holds the info of the last frame we decoded or seeked to */ - FLAC__bool last_frame_is_set; - FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */ - FLAC__uint64 last_seen_framesync; /* if tell callback works, the location of the last seen frame sync code, to rewind to if needed */ - FLAC__uint64 target_sample; - uint32_t unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */ - FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */ - FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter); -} FLAC__StreamDecoderPrivate; - -/*********************************************************************** - * - * Public static class data - * - ***********************************************************************/ - -FLAC_API const char * const FLAC__StreamDecoderStateString[] = { - "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA", - "FLAC__STREAM_DECODER_READ_METADATA", - "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC", - "FLAC__STREAM_DECODER_READ_FRAME", - "FLAC__STREAM_DECODER_END_OF_STREAM", - "FLAC__STREAM_DECODER_OGG_ERROR", - "FLAC__STREAM_DECODER_SEEK_ERROR", - "FLAC__STREAM_DECODER_ABORTED", - "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR", - "FLAC__STREAM_DECODER_UNINITIALIZED" -}; - -FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = { - "FLAC__STREAM_DECODER_INIT_STATUS_OK", - "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER", - "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS", - "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR", - "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE", - "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED" -}; - -FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = { - "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE", - "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM", - "FLAC__STREAM_DECODER_READ_STATUS_ABORT" -}; - -FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = { - "FLAC__STREAM_DECODER_SEEK_STATUS_OK", - "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR", - "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED" -}; - -FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = { - "FLAC__STREAM_DECODER_TELL_STATUS_OK", - "FLAC__STREAM_DECODER_TELL_STATUS_ERROR", - "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED" -}; - -FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = { - "FLAC__STREAM_DECODER_LENGTH_STATUS_OK", - "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR", - "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED" -}; - -FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = { - "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE", - "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT" -}; - -FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = { - "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC", - "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER", - "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH", - "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM", - "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA" -}; - -/*********************************************************************** - * - * Class constructor/destructor - * - ***********************************************************************/ -FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void) -{ - FLAC__StreamDecoder *decoder; - uint32_t i; - - FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */ - - decoder = calloc(1, sizeof(FLAC__StreamDecoder)); - if(decoder == 0) { - return 0; - } - - decoder->protected_ = calloc(1, sizeof(FLAC__StreamDecoderProtected)); - if(decoder->protected_ == 0) { - free(decoder); - return 0; - } - - decoder->private_ = calloc(1, sizeof(FLAC__StreamDecoderPrivate)); - if(decoder->private_ == 0) { - free(decoder->protected_); - free(decoder); - return 0; - } - - decoder->private_->input = FLAC__bitreader_new(); - if(decoder->private_->input == 0) { - free(decoder->private_); - free(decoder->protected_); - free(decoder); - return 0; - } - - decoder->private_->metadata_filter_ids_capacity = 16; - if(0 == (decoder->private_->metadata_filter_ids = malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) { - FLAC__bitreader_delete(decoder->private_->input); - free(decoder->private_); - free(decoder->protected_); - free(decoder); - return 0; - } - - for(i = 0; i < FLAC__MAX_CHANNELS; i++) { - decoder->private_->output[i] = 0; - decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0; - } - - decoder->private_->side_subframe = 0; - - decoder->private_->output_capacity = 0; - decoder->private_->output_channels = 0; - decoder->private_->has_seek_table = false; - - for(i = 0; i < FLAC__MAX_CHANNELS; i++) - FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]); - - decoder->private_->file = 0; - - set_defaults_(decoder); - - decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED; - - return decoder; -} - -FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder) -{ - uint32_t i; - - if (decoder == NULL) - return ; - - FLAC__ASSERT(0 != decoder->protected_); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->private_->input); - - (void)FLAC__stream_decoder_finish(decoder); - - if(0 != decoder->private_->metadata_filter_ids) - free(decoder->private_->metadata_filter_ids); - - FLAC__bitreader_delete(decoder->private_->input); - - for(i = 0; i < FLAC__MAX_CHANNELS; i++) - FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]); - - free(decoder->private_); - free(decoder->protected_); - free(decoder); -} - -/*********************************************************************** - * - * Public class methods - * - ***********************************************************************/ - -static FLAC__StreamDecoderInitStatus init_stream_internal_( - FLAC__StreamDecoder *decoder, - FLAC__StreamDecoderReadCallback read_callback, - FLAC__StreamDecoderSeekCallback seek_callback, - FLAC__StreamDecoderTellCallback tell_callback, - FLAC__StreamDecoderLengthCallback length_callback, - FLAC__StreamDecoderEofCallback eof_callback, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data, - FLAC__bool is_ogg -) -{ - FLAC__ASSERT(0 != decoder); - - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED; - - if(FLAC__HAS_OGG == 0 && is_ogg) - return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER; - - if( - 0 == read_callback || - 0 == write_callback || - 0 == error_callback || - (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback)) - ) - return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS; - -#if FLAC__HAS_OGG - decoder->private_->is_ogg = is_ogg; - if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect)) - return decoder->protected_->initstate = FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE; -#endif - - FLAC__cpu_info(&decoder->private_->cpuinfo); - decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block; - -#ifdef FLAC__BMI2_SUPPORTED - if (decoder->private_->cpuinfo.x86.bmi2) { - decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_bmi2; - } -#endif - - /* from here on, errors are fatal */ - - if(!FLAC__bitreader_init(decoder->private_->input, read_callback_, decoder)) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR; - } - - decoder->private_->read_callback = read_callback; - decoder->private_->seek_callback = seek_callback; - decoder->private_->tell_callback = tell_callback; - decoder->private_->length_callback = length_callback; - decoder->private_->eof_callback = eof_callback; - decoder->private_->write_callback = write_callback; - decoder->private_->metadata_callback = metadata_callback; - decoder->private_->error_callback = error_callback; - decoder->private_->client_data = client_data; - decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0; - decoder->private_->samples_decoded = 0; - decoder->private_->has_stream_info = false; - decoder->private_->cached = false; - - decoder->private_->do_md5_checking = decoder->protected_->md5_checking; - decoder->private_->is_seeking = false; - - decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */ - if(!FLAC__stream_decoder_reset(decoder)) { - /* above call sets the state for us */ - return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR; - } - - return FLAC__STREAM_DECODER_INIT_STATUS_OK; -} - -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream( - FLAC__StreamDecoder *decoder, - FLAC__StreamDecoderReadCallback read_callback, - FLAC__StreamDecoderSeekCallback seek_callback, - FLAC__StreamDecoderTellCallback tell_callback, - FLAC__StreamDecoderLengthCallback length_callback, - FLAC__StreamDecoderEofCallback eof_callback, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -) -{ - return init_stream_internal_( - decoder, - read_callback, - seek_callback, - tell_callback, - length_callback, - eof_callback, - write_callback, - metadata_callback, - error_callback, - client_data, - /*is_ogg=*/false - ); -} - -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream( - FLAC__StreamDecoder *decoder, - FLAC__StreamDecoderReadCallback read_callback, - FLAC__StreamDecoderSeekCallback seek_callback, - FLAC__StreamDecoderTellCallback tell_callback, - FLAC__StreamDecoderLengthCallback length_callback, - FLAC__StreamDecoderEofCallback eof_callback, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -) -{ - return init_stream_internal_( - decoder, - read_callback, - seek_callback, - tell_callback, - length_callback, - eof_callback, - write_callback, - metadata_callback, - error_callback, - client_data, - /*is_ogg=*/true - ); -} - -static FLAC__StreamDecoderInitStatus init_FILE_internal_( - FLAC__StreamDecoder *decoder, - FILE *file, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data, - FLAC__bool is_ogg -) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != file); - - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return decoder->protected_->initstate = FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED; - - if(0 == write_callback || 0 == error_callback) - return decoder->protected_->initstate = FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS; - - /* - * To make sure that our file does not go unclosed after an error, we - * must assign the FILE pointer before any further error can occur in - * this routine. - */ - if(file == stdin) - file = get_binary_stdin_(); /* just to be safe */ - - decoder->private_->file = file; - - return init_stream_internal_( - decoder, - file_read_callback_, - decoder->private_->file == stdin? 0: file_seek_callback_, - decoder->private_->file == stdin? 0: file_tell_callback_, - decoder->private_->file == stdin? 0: file_length_callback_, - file_eof_callback_, - write_callback, - metadata_callback, - error_callback, - client_data, - is_ogg - ); -} - -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE( - FLAC__StreamDecoder *decoder, - FILE *file, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -) -{ - return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false); -} - -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE( - FLAC__StreamDecoder *decoder, - FILE *file, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -) -{ - return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true); -} - -static FLAC__StreamDecoderInitStatus init_file_internal_( - FLAC__StreamDecoder *decoder, - const char *filename, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data, - FLAC__bool is_ogg -) -{ - FILE *file; - - FLAC__ASSERT(0 != decoder); - - /* - * To make sure that our file does not go unclosed after an error, we - * have to do the same entrance checks here that are later performed - * in FLAC__stream_decoder_init_FILE() before the FILE* is assigned. - */ - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return decoder->protected_->initstate = FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED; - - if(0 == write_callback || 0 == error_callback) - return decoder->protected_->initstate = FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS; - - file = filename? flac_fopen(filename, "rb") : stdin; - - if(0 == file) - return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE; - - return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg); -} - -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file( - FLAC__StreamDecoder *decoder, - const char *filename, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -) -{ - return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false); -} - -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file( - FLAC__StreamDecoder *decoder, - const char *filename, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -) -{ - return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true); -} - -FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder) -{ - FLAC__bool md5_failed = false; - uint32_t i; - - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - - if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED) - return true; - - /* see the comment in FLAC__stream_decoder_reset() as to why we - * always call FLAC__MD5Final() - */ - FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context); - - free(decoder->private_->seek_table.data.seek_table.points); - decoder->private_->seek_table.data.seek_table.points = 0; - decoder->private_->has_seek_table = false; - - FLAC__bitreader_free(decoder->private_->input); - for(i = 0; i < FLAC__MAX_CHANNELS; i++) { - /* WATCHOUT: - * FLAC__lpc_restore_signal_asm_ia32_mmx() and ..._intrin_sseN() - * require that the output arrays have a buffer of up to 3 zeroes - * in front (at negative indices) for alignment purposes; - * we use 4 to keep the data well-aligned. - */ - if(0 != decoder->private_->output[i]) { - free(decoder->private_->output[i]-4); - decoder->private_->output[i] = 0; - } - if(0 != decoder->private_->residual_unaligned[i]) { - free(decoder->private_->residual_unaligned[i]); - decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0; - } - } - if(0 != decoder->private_->side_subframe) { - free(decoder->private_->side_subframe); - decoder->private_->side_subframe = 0; - } - decoder->private_->output_capacity = 0; - decoder->private_->output_channels = 0; - -#if FLAC__HAS_OGG - if(decoder->private_->is_ogg) - FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect); -#endif - - if(0 != decoder->private_->file) { - if(decoder->private_->file != stdin) - fclose(decoder->private_->file); - decoder->private_->file = 0; - } - - if(decoder->private_->do_md5_checking) { - if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16)) - md5_failed = true; - } - decoder->private_->is_seeking = false; - - set_defaults_(decoder); - - decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED; - - return !md5_failed; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return false; -#if FLAC__HAS_OGG - /* can't check decoder->private_->is_ogg since that's not set until init time */ - FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value); - return true; -#else - (void)value; - return false; -#endif -} - -FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return false; - decoder->protected_->md5_checking = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - FLAC__ASSERT((uint32_t)type <= FLAC__MAX_METADATA_TYPE_CODE); - /* double protection */ - if((uint32_t)type > FLAC__MAX_METADATA_TYPE_CODE) - return false; - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return false; - decoder->private_->metadata_filter[type] = true; - if(type == FLAC__METADATA_TYPE_APPLICATION) - decoder->private_->metadata_filter_ids_count = 0; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - FLAC__ASSERT(0 != id); - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return false; - - if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION]) - return true; - - FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids); - - if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) { - if(0 == (decoder->private_->metadata_filter_ids = safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - decoder->private_->metadata_filter_ids_capacity *= 2; - } - - memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metadata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)); - decoder->private_->metadata_filter_ids_count++; - - return true; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder) -{ - uint32_t i; - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return false; - for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++) - decoder->private_->metadata_filter[i] = true; - decoder->private_->metadata_filter_ids_count = 0; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - FLAC__ASSERT((uint32_t)type <= FLAC__MAX_METADATA_TYPE_CODE); - /* double protection */ - if((uint32_t)type > FLAC__MAX_METADATA_TYPE_CODE) - return false; - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return false; - decoder->private_->metadata_filter[type] = false; - if(type == FLAC__METADATA_TYPE_APPLICATION) - decoder->private_->metadata_filter_ids_count = 0; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - FLAC__ASSERT(0 != id); - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return false; - - if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION]) - return true; - - FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids); - - if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) { - if(0 == (decoder->private_->metadata_filter_ids = safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - decoder->private_->metadata_filter_ids_capacity *= 2; - } - - memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metadata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)); - decoder->private_->metadata_filter_ids_count++; - - return true; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) - return false; - memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter)); - decoder->private_->metadata_filter_ids_count = 0; - return true; -} - -FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - return decoder->protected_->state; -} - -FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder) -{ - return FLAC__StreamDecoderStateString[decoder->protected_->state]; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - return decoder->protected_->md5_checking; -} - -FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0; -} - -FLAC_API uint32_t FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - return decoder->protected_->channels; -} - -FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - return decoder->protected_->channel_assignment; -} - -FLAC_API uint32_t FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - return decoder->protected_->bits_per_sample; -} - -FLAC_API uint32_t FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - return decoder->protected_->sample_rate; -} - -FLAC_API uint32_t FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - return decoder->protected_->blocksize; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != position); - - if(FLAC__HAS_OGG && decoder->private_->is_ogg) - return false; - - if(0 == decoder->private_->tell_callback) - return false; - if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK) - return false; - /* should never happen since all FLAC frames and metadata blocks are byte aligned, but check just in case */ - if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) - return false; - FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder)); - *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder); - return true; -} - -FLAC_API const void *FLAC__stream_decoder_get_client_data(FLAC__StreamDecoder *decoder) -{ - return decoder->private_->client_data; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - - if(!decoder->private_->internal_reset_hack && decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED) - return false; - - decoder->private_->samples_decoded = 0; - decoder->private_->do_md5_checking = false; - decoder->private_->last_seen_framesync = 0; - decoder->private_->last_frame_is_set = false; - -#if FLAC__HAS_OGG - if(decoder->private_->is_ogg) - FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect); -#endif - - if(!FLAC__bitreader_clear(decoder->private_->input)) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - - return true; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - - if(!FLAC__stream_decoder_flush(decoder)) { - /* above call sets the state for us */ - return false; - } - -#if FLAC__HAS_OGG - /*@@@ could go in !internal_reset_hack block below */ - if(decoder->private_->is_ogg) - FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect); -#endif - - /* Rewind if necessary. If FLAC__stream_decoder_init() is calling us, - * (internal_reset_hack) don't try to rewind since we are already at - * the beginning of the stream and don't want to fail if the input is - * not seekable. - */ - if(!decoder->private_->internal_reset_hack) { - if(decoder->private_->file == stdin) - return false; /* can't rewind stdin, reset fails */ - if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR) - return false; /* seekable and seek fails, reset fails */ - } - - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA; - - decoder->private_->has_stream_info = false; - - free(decoder->private_->seek_table.data.seek_table.points); - decoder->private_->seek_table.data.seek_table.points = 0; - decoder->private_->has_seek_table = false; - - decoder->private_->do_md5_checking = decoder->protected_->md5_checking; - /* - * This goes in reset() and not flush() because according to the spec, a - * fixed-blocksize stream must stay that way through the whole stream. - */ - decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0; - - /* We initialize the FLAC__MD5Context even though we may never use it. This - * is because md5 checking may be turned on to start and then turned off if - * a seek occurs. So we init the context here and finalize it in - * FLAC__stream_decoder_finish() to make sure things are always cleaned up - * properly. - */ - if(!decoder->private_->internal_reset_hack) { - /* Only finish MD5 context when it has been initialized - * (i.e. when internal_reset_hack is not set) */ - FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context); - } - else - decoder->private_->internal_reset_hack = false; - FLAC__MD5Init(&decoder->private_->md5context); - - decoder->private_->first_frame_offset = 0; - decoder->private_->unparseable_frame_count = 0; - decoder->private_->last_seen_framesync = 0; - decoder->private_->last_frame_is_set = false; - - return true; -} - -FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder) -{ - FLAC__bool got_a_frame; - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - - while(1) { - switch(decoder->protected_->state) { - case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA: - if(!find_metadata_(decoder)) - return false; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_READ_METADATA: - if(!read_metadata_(decoder)) - return false; /* above function sets the status for us */ - else - return true; - case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC: - if(!frame_sync_(decoder)) - return true; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_READ_FRAME: - if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true)) - return false; /* above function sets the status for us */ - if(got_a_frame) - return true; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_END_OF_STREAM: - case FLAC__STREAM_DECODER_ABORTED: - return true; - default: - return false; - } - } -} - -FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - - while(1) { - switch(decoder->protected_->state) { - case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA: - if(!find_metadata_(decoder)) - return false; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_READ_METADATA: - if(!read_metadata_(decoder)) - return false; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC: - case FLAC__STREAM_DECODER_READ_FRAME: - case FLAC__STREAM_DECODER_END_OF_STREAM: - case FLAC__STREAM_DECODER_ABORTED: - return true; - default: - return false; - } - } -} - -FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder) -{ - FLAC__bool dummy; - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - - while(1) { - switch(decoder->protected_->state) { - case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA: - if(!find_metadata_(decoder)) - return false; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_READ_METADATA: - if(!read_metadata_(decoder)) - return false; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC: - if(!frame_sync_(decoder)) - return true; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_READ_FRAME: - if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true)) - return false; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_END_OF_STREAM: - case FLAC__STREAM_DECODER_ABORTED: - return true; - default: - return false; - } - } -} - -FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder) -{ - FLAC__bool got_a_frame; - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - - while(1) { - switch(decoder->protected_->state) { - case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA: - case FLAC__STREAM_DECODER_READ_METADATA: - return false; /* above function sets the status for us */ - case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC: - if(!frame_sync_(decoder)) - return true; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_READ_FRAME: - if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false)) - return false; /* above function sets the status for us */ - if(got_a_frame) - return true; /* above function sets the status for us */ - break; - case FLAC__STREAM_DECODER_END_OF_STREAM: - case FLAC__STREAM_DECODER_ABORTED: - return true; - default: - return false; - } - } -} - -FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample) -{ - FLAC__uint64 length; - - FLAC__ASSERT(0 != decoder); - - if( - decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA && - decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA && - decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC && - decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME && - decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM - ) - return false; - - if(0 == decoder->private_->seek_callback) - return false; - - FLAC__ASSERT(decoder->private_->seek_callback); - FLAC__ASSERT(decoder->private_->tell_callback); - FLAC__ASSERT(decoder->private_->length_callback); - FLAC__ASSERT(decoder->private_->eof_callback); - - if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) - return false; - - decoder->private_->is_seeking = true; - - /* turn off md5 checking if a seek is attempted */ - decoder->private_->do_md5_checking = false; - - /* get the file length (currently our algorithm needs to know the length so it's also an error to get FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED) */ - if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) { - decoder->private_->is_seeking = false; - return false; - } - - /* if we haven't finished processing the metadata yet, do that so we have the STREAMINFO, SEEK_TABLE, and first_frame_offset */ - if( - decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA || - decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA - ) { - if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) { - /* above call sets the state for us */ - decoder->private_->is_seeking = false; - return false; - } - /* check this again in case we didn't know total_samples the first time */ - if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) { - decoder->private_->is_seeking = false; - return false; - } - } - - { - const FLAC__bool ok = -#if FLAC__HAS_OGG - decoder->private_->is_ogg? - seek_to_absolute_sample_ogg_(decoder, length, sample) : -#endif - seek_to_absolute_sample_(decoder, length, sample) - ; - decoder->private_->is_seeking = false; - return ok; - } -} - -/*********************************************************************** - * - * Protected class methods - * - ***********************************************************************/ - -uint32_t FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)); - FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7)); - return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8; -} - -/*********************************************************************** - * - * Private class methods - * - ***********************************************************************/ - -void set_defaults_(FLAC__StreamDecoder *decoder) -{ - decoder->private_->is_ogg = false; - decoder->private_->read_callback = 0; - decoder->private_->seek_callback = 0; - decoder->private_->tell_callback = 0; - decoder->private_->length_callback = 0; - decoder->private_->eof_callback = 0; - decoder->private_->write_callback = 0; - decoder->private_->metadata_callback = 0; - decoder->private_->error_callback = 0; - decoder->private_->client_data = 0; - - memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter)); - decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true; - decoder->private_->metadata_filter_ids_count = 0; - - decoder->protected_->md5_checking = false; - -#if FLAC__HAS_OGG - FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect); -#endif -} - -/* - * This will forcibly set stdin to binary mode (for OSes that require it) - */ -FILE *get_binary_stdin_(void) -{ - /* if something breaks here it is probably due to the presence or - * absence of an underscore before the identifiers 'setmode', - * 'fileno', and/or 'O_BINARY'; check your system header files. - */ -#if defined _MSC_VER || defined __MINGW32__ - _setmode(_fileno(stdin), _O_BINARY); -#elif defined __EMX__ - setmode(fileno(stdin), O_BINARY); -#endif - - return stdin; -} - -FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, uint32_t size, uint32_t channels, uint32_t bps) -{ - uint32_t i; - FLAC__int32 *tmp; - - if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels && - (bps < 32 || decoder->private_->side_subframe != 0)) - return true; - - /* simply using realloc() is not practical because the number of channels may change mid-stream */ - - for(i = 0; i < FLAC__MAX_CHANNELS; i++) { - if(0 != decoder->private_->output[i]) { - free(decoder->private_->output[i]-4); - decoder->private_->output[i] = 0; - } - if(0 != decoder->private_->residual_unaligned[i]) { - free(decoder->private_->residual_unaligned[i]); - decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0; - } - } - - if(0 != decoder->private_->side_subframe) { - free(decoder->private_->side_subframe); - decoder->private_->side_subframe = 0; - } - - for(i = 0; i < channels; i++) { - /* WATCHOUT: - * FLAC__lpc_restore_signal_asm_ia32_mmx() and ..._intrin_sseN() - * require that the output arrays have a buffer of up to 3 zeroes - * in front (at negative indices) for alignment purposes; - * we use 4 to keep the data well-aligned. - */ - tmp = safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/); - if(tmp == 0) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - memset(tmp, 0, sizeof(FLAC__int32)*4); - decoder->private_->output[i] = tmp + 4; - - if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - } - - if(bps == 32) { - decoder->private_->side_subframe = safe_malloc_mul_2op_p(sizeof(FLAC__int64), /*times (*/size); - if(decoder->private_->side_subframe == NULL) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - } - - decoder->private_->output_capacity = size; - decoder->private_->output_channels = channels; - - return true; -} - -FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id) -{ - size_t i; - - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - - for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++) - if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))) - return true; - - return false; -} - -FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder) -{ - FLAC__uint32 x; - uint32_t i, id; - FLAC__bool first = true; - - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)); - - for(i = id = 0; i < 4; ) { - if(decoder->private_->cached) { - x = (FLAC__uint32)decoder->private_->lookahead; - decoder->private_->cached = false; - } - else { - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) - return false; /* read_callback_ sets the state for us */ - } - if(x == FLAC__STREAM_SYNC_STRING[i]) { - first = true; - i++; - id = 0; - continue; - } - - if(id >= 3) - return false; - - if(x == ID3V2_TAG_[id]) { - id++; - i = 0; - if(id == 3) { - if(!skip_id3v2_tag_(decoder)) - return false; /* skip_id3v2_tag_ sets the state for us */ - } - continue; - } - id = 0; - if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */ - decoder->private_->header_warmup[0] = (FLAC__byte)x; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) - return false; /* read_callback_ sets the state for us */ - - /* we have to check if we just read two 0xff's in a row; the second may actually be the beginning of the sync code */ - /* else we have to check if the second byte is the end of a sync code */ - if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */ - decoder->private_->lookahead = (FLAC__byte)x; - decoder->private_->cached = true; - } - else if(x >> 1 == 0x7c) { /* MAGIC NUMBER for the last 6 sync bits and reserved 7th bit */ - decoder->private_->header_warmup[1] = (FLAC__byte)x; - decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME; - return true; - } - } - i = 0; - if(first) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - first = false; - } - } - - decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA; - return true; -} - -FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder) -{ - FLAC__bool is_last; - FLAC__uint32 i, x, type, length; - - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)); - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN)) - return false; /* read_callback_ sets the state for us */ - is_last = x? true : false; - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN)) - return false; /* read_callback_ sets the state for us */ - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN)) - return false; /* read_callback_ sets the state for us */ - - if(type == FLAC__METADATA_TYPE_STREAMINFO) { - if(!read_metadata_streaminfo_(decoder, is_last, length)) - return false; - - decoder->private_->has_stream_info = true; - if(0 == memcmp(decoder->private_->stream_info.data.stream_info.md5sum, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16)) - decoder->private_->do_md5_checking = false; - if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback) - decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data); - } - else if(type == FLAC__METADATA_TYPE_SEEKTABLE) { - /* just in case we already have a seek table, and reading the next one fails: */ - decoder->private_->has_seek_table = false; - - if(length > 0) { - if(!read_metadata_seektable_(decoder, is_last, length)) - return false; - - decoder->private_->has_seek_table = true; - if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback) - decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data); - } - } - else { - FLAC__bool skip_it = !decoder->private_->metadata_filter[type]; - uint32_t real_length = length; - FLAC__StreamMetadata block; - - memset(&block, 0, sizeof(block)); - block.is_last = is_last; - block.type = (FLAC__MetadataType)type; - block.length = length; - - if(type == FLAC__METADATA_TYPE_APPLICATION) { - if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)) - return false; /* read_callback_ sets the state for us */ - - if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */ - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/ - return false; - } - - real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8; - - if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id)) - skip_it = !skip_it; - } - - if(skip_it) { - if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length)) - return false; /* read_callback_ sets the state for us */ - } - else { - FLAC__bool ok = true; - FLAC__bitreader_set_limit(decoder->private_->input, real_length*8); - switch(type) { - case FLAC__METADATA_TYPE_PADDING: - /* skip the padding bytes */ - if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length)) - ok = false; /* read_callback_ sets the state for us */ - break; - case FLAC__METADATA_TYPE_APPLICATION: - /* remember, we read the ID already */ - if(real_length > 0) { - if(0 == (block.data.application.data = malloc(real_length))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - ok = false; - } - else if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length)) - ok = false; /* read_callback_ sets the state for us */ - } - else - block.data.application.data = 0; - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment, real_length)) - ok = false; - break; - case FLAC__METADATA_TYPE_CUESHEET: - if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet)) - ok = false; - break; - case FLAC__METADATA_TYPE_PICTURE: - if(!read_metadata_picture_(decoder, &block.data.picture)) - ok = false; - break; - case FLAC__METADATA_TYPE_STREAMINFO: - case FLAC__METADATA_TYPE_SEEKTABLE: - FLAC__ASSERT(0); - break; - default: - if(real_length > 0) { - if(0 == (block.data.unknown.data = malloc(real_length))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - ok = false; - } - else if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length)) - ok = false; /* read_callback_ sets the state for us */ - } - else - block.data.unknown.data = 0; - break; - } - if(FLAC__bitreader_limit_remaining(decoder->private_->input) > 0) { - /* Content in metadata block didn't fit in block length - * We cannot know whether the length or the content was - * corrupt, so stop parsing metadata */ - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA); - if(decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA) - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - ok = false; - } - FLAC__bitreader_remove_limit(decoder->private_->input); - if(ok && !decoder->private_->is_seeking && decoder->private_->metadata_callback) - decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data); - - /* now we have to free any malloc()ed data in the block */ - switch(type) { - case FLAC__METADATA_TYPE_PADDING: - break; - case FLAC__METADATA_TYPE_APPLICATION: - if(0 != block.data.application.data) - free(block.data.application.data); - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - if(0 != block.data.vorbis_comment.vendor_string.entry) - free(block.data.vorbis_comment.vendor_string.entry); - if(block.data.vorbis_comment.num_comments > 0) - for(i = 0; i < block.data.vorbis_comment.num_comments; i++) - if(0 != block.data.vorbis_comment.comments[i].entry) - free(block.data.vorbis_comment.comments[i].entry); - if(0 != block.data.vorbis_comment.comments) - free(block.data.vorbis_comment.comments); - break; - case FLAC__METADATA_TYPE_CUESHEET: - if(block.data.cue_sheet.num_tracks > 0 && 0 != block.data.cue_sheet.tracks) - for(i = 0; i < block.data.cue_sheet.num_tracks; i++) - if(0 != block.data.cue_sheet.tracks[i].indices) - free(block.data.cue_sheet.tracks[i].indices); - if(0 != block.data.cue_sheet.tracks) - free(block.data.cue_sheet.tracks); - break; - case FLAC__METADATA_TYPE_PICTURE: - if(0 != block.data.picture.mime_type) - free(block.data.picture.mime_type); - if(0 != block.data.picture.description) - free(block.data.picture.description); - if(0 != block.data.picture.data) - free(block.data.picture.data); - break; - case FLAC__METADATA_TYPE_STREAMINFO: - case FLAC__METADATA_TYPE_SEEKTABLE: - FLAC__ASSERT(0); - default: - if(0 != block.data.unknown.data) - free(block.data.unknown.data); - break; - } - - if(!ok) /* anything that unsets "ok" should also make sure decoder->protected_->state is updated */ - return false; - } - } - - if(is_last) { - /* if this fails, it's OK, it's just a hint for the seek routine */ - if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset)) - decoder->private_->first_frame_offset = 0; - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - } - - return true; -} - -FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, uint32_t length) -{ - FLAC__uint32 x; - uint32_t bits, used_bits = 0; - - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)); - - decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO; - decoder->private_->stream_info.is_last = is_last; - decoder->private_->stream_info.length = length; - - bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->stream_info.data.stream_info.min_blocksize = x; - used_bits += bits; - - bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->stream_info.data.stream_info.max_blocksize = x; - used_bits += bits; - - bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->stream_info.data.stream_info.min_framesize = x; - used_bits += bits; - - bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->stream_info.data.stream_info.max_framesize = x; - used_bits += bits; - - bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->stream_info.data.stream_info.sample_rate = x; - used_bits += bits; - - bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->stream_info.data.stream_info.channels = x+1; - used_bits += bits; - - bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1; - used_bits += bits; - - bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; - if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &decoder->private_->stream_info.data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN)) - return false; /* read_callback_ sets the state for us */ - used_bits += bits; - - if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16)) - return false; /* read_callback_ sets the state for us */ - used_bits += 16*8; - - /* skip the rest of the block */ - FLAC__ASSERT(used_bits % 8 == 0); - if (length < (used_bits / 8)) - return false; /* read_callback_ sets the state for us */ - length -= (used_bits / 8); - if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length)) - return false; /* read_callback_ sets the state for us */ - - return true; -} - -FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, uint32_t length) -{ - FLAC__uint32 i, x; - FLAC__uint64 xx; - - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)); - - decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE; - decoder->private_->seek_table.is_last = is_last; - decoder->private_->seek_table.length = length; - - if(length % FLAC__STREAM_METADATA_SEEKPOINT_LENGTH) { - FLAC__bitreader_limit_invalidate(decoder->private_->input); - return false; - } - - decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH; - - /* use realloc since we may pass through here several times (e.g. after seeking) */ - if(0 == (decoder->private_->seek_table.data.seek_table.points = safe_realloc_mul_2op_(decoder->private_->seek_table.data.seek_table.points, decoder->private_->seek_table.data.seek_table.num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint)))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) { - if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx; - - if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx; - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x; - } - length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH); - - FLAC__ASSERT(length == 0); - - return true; -} - -FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj, uint32_t length) -{ - FLAC__uint32 i; - - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)); - - /* read vendor string */ - if (length >= 8) { - length -= 8; /* vendor string length + num comments entries alone take 8 bytes */ - FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32); - if (!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length)) - return false; /* read_callback_ sets the state for us */ - if (length < obj->vendor_string.length) { - obj->vendor_string.length = 0; - obj->vendor_string.entry = 0; - goto skip; - } - else - length -= obj->vendor_string.length; - if (0 == (obj->vendor_string.entry = safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - if (!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length)) - return false; /* read_callback_ sets the state for us */ - obj->vendor_string.entry[obj->vendor_string.length] = '\0'; - - /* read num comments */ - FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32); - if (!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments)) - return false; /* read_callback_ sets the state for us */ - - /* read comments */ - if (obj->num_comments > 100000) { - /* Possibly malicious file. */ - obj->num_comments = 0; - return false; - } - if (obj->num_comments > 0) { - if (0 == (obj->comments = safe_malloc_mul_2op_p(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) { - obj->num_comments = 0; - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - for (i = 0; i < obj->num_comments; i++) { - /* Initialize here just to make sure. */ - obj->comments[i].length = 0; - obj->comments[i].entry = 0; - - FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32); - if (length < 4) { - obj->num_comments = i; - goto skip; - } - else - length -= 4; - if (!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length)) { - obj->num_comments = i; - return false; /* read_callback_ sets the state for us */ - } - if (length < obj->comments[i].length) { - obj->num_comments = i; - FLAC__bitreader_limit_invalidate(decoder->private_->input); - return false; - } - else - length -= obj->comments[i].length; - if (0 == (obj->comments[i].entry = safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - obj->num_comments = i; - return false; - } - memset (obj->comments[i].entry, 0, obj->comments[i].length) ; - if (!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length)) { - /* Current i-th entry is bad, so we delete it. */ - free (obj->comments[i].entry) ; - obj->comments[i].entry = NULL ; - obj->num_comments = i; - goto skip; - } - obj->comments[i].entry[obj->comments[i].length] = '\0'; - } - } - } - else { - FLAC__bitreader_limit_invalidate(decoder->private_->input); - return false; - } - - skip: - if (length > 0) { - /* length > 0 can only happen on files with invalid data in comments */ - if(obj->num_comments < 1) { - free(obj->comments); - obj->comments = NULL; - } - FLAC__bitreader_limit_invalidate(decoder->private_->input); - return false; - } - - return true; -} - -FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj) -{ - FLAC__uint32 i, j, x; - - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)); - - memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet)); - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0); - if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->media_catalog_number, FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN/8)) - return false; /* read_callback_ sets the state for us */ - - if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN)) - return false; /* read_callback_ sets the state for us */ - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN)) - return false; /* read_callback_ sets the state for us */ - obj->is_cd = x? true : false; - - if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN)) - return false; /* read_callback_ sets the state for us */ - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN)) - return false; /* read_callback_ sets the state for us */ - obj->num_tracks = x; - - if(obj->num_tracks > 0) { - if(0 == (obj->tracks = safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - for(i = 0; i < obj->num_tracks; i++) { - FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i]; - if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN)) - return false; /* read_callback_ sets the state for us */ - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN)) - return false; /* read_callback_ sets the state for us */ - track->number = (FLAC__byte)x; - - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0); - if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8)) - return false; /* read_callback_ sets the state for us */ - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN)) - return false; /* read_callback_ sets the state for us */ - track->type = x; - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN)) - return false; /* read_callback_ sets the state for us */ - track->pre_emphasis = x; - - if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN)) - return false; /* read_callback_ sets the state for us */ - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN)) - return false; /* read_callback_ sets the state for us */ - track->num_indices = (FLAC__byte)x; - - if(track->num_indices > 0) { - if(0 == (track->indices = safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - for(j = 0; j < track->num_indices; j++) { - FLAC__StreamMetadata_CueSheet_Index *indx = &track->indices[j]; - if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &indx->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN)) - return false; /* read_callback_ sets the state for us */ - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN)) - return false; /* read_callback_ sets the state for us */ - indx->number = (FLAC__byte)x; - - if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN)) - return false; /* read_callback_ sets the state for us */ - } - } - } - } - else { /* obj->num_tracks == 0 */ - FLAC__bitreader_limit_invalidate(decoder->private_->input); - return false; - } - - return true; -} - -FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj) -{ - FLAC__uint32 x; - - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)); - - /* read type */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN)) - return false; /* read_callback_ sets the state for us */ - if(x < FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED) - obj->type = x; - else - obj->type = FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER; - - /* read MIME type */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN)) - return false; /* read_callback_ sets the state for us */ - if(FLAC__bitreader_limit_remaining(decoder->private_->input) < x){ - FLAC__bitreader_limit_invalidate(decoder->private_->input); - return false; - } - if(0 == (obj->mime_type = safe_malloc_add_2op_(x, /*+*/1))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - if(x > 0) { - if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x)) - return false; /* read_callback_ sets the state for us */ - } - obj->mime_type[x] = '\0'; - - /* read description */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN)) - return false; /* read_callback_ sets the state for us */ - if(FLAC__bitreader_limit_remaining(decoder->private_->input) < x){ - FLAC__bitreader_limit_invalidate(decoder->private_->input); - return false; - } - if(0 == (obj->description = safe_malloc_add_2op_(x, /*+*/1))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - if(x > 0) { - if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x)) - return false; /* read_callback_ sets the state for us */ - } - obj->description[x] = '\0'; - - /* read width */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN)) - return false; /* read_callback_ sets the state for us */ - - /* read height */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN)) - return false; /* read_callback_ sets the state for us */ - - /* read depth */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN)) - return false; /* read_callback_ sets the state for us */ - - /* read colors */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN)) - return false; /* read_callback_ sets the state for us */ - - /* read data */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN)) - return false; /* read_callback_ sets the state for us */ - if(FLAC__bitreader_limit_remaining(decoder->private_->input) < obj->data_length){ - FLAC__bitreader_limit_invalidate(decoder->private_->input); - return false; - } - if(0 == (obj->data = safe_malloc_(obj->data_length))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - if(obj->data_length > 0) { - if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length)) - return false; /* read_callback_ sets the state for us */ - } - - return true; -} - -FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder) -{ - FLAC__uint32 x; - uint32_t i, skip; - - /* skip the version and flags bytes */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24)) - return false; /* read_callback_ sets the state for us */ - /* get the size (in bytes) to skip */ - skip = 0; - for(i = 0; i < 4; i++) { - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) - return false; /* read_callback_ sets the state for us */ - skip <<= 7; - skip |= (x & 0x7f); - } - /* skip the rest of the tag */ - if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip)) - return false; /* read_callback_ sets the state for us */ - return true; -} - -FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder) -{ - FLAC__uint32 x; - FLAC__bool first = true; - - /* make sure we're byte aligned */ - if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) { - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input))) - return false; /* read_callback_ sets the state for us */ - } - - while(1) { - if(decoder->private_->cached) { - x = (FLAC__uint32)decoder->private_->lookahead; - decoder->private_->cached = false; - } - else { - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) - return false; /* read_callback_ sets the state for us */ - } - if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */ - decoder->private_->header_warmup[0] = (FLAC__byte)x; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) - return false; /* read_callback_ sets the state for us */ - - /* we have to check if we just read two 0xff's in a row; the second may actually be the beginning of the sync code */ - /* else we have to check if the second byte is the end of a sync code */ - if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */ - decoder->private_->lookahead = (FLAC__byte)x; - decoder->private_->cached = true; - } - else if(x >> 1 == 0x7c) { /* MAGIC NUMBER for the last 6 sync bits and reserved 7th bit */ - decoder->private_->header_warmup[1] = (FLAC__byte)x; - decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME; - - /* Save location so we can rewind in case the frame turns - * out to be invalid after the header */ - FLAC__bitreader_set_framesync_location(decoder->private_->input); - if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->last_seen_framesync)) - decoder->private_->last_seen_framesync = 0; - return true; - } - } - if(first) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - first = false; - } - } - - return true; -} - -FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode) -{ - uint32_t channel; - uint32_t i; - uint32_t frame_crc; /* the one we calculate from the input stream */ - FLAC__uint32 x; - - *got_a_frame = false; - decoder->private_->side_subframe_in_use = false; - - /* init the CRC */ - frame_crc = 0; - frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc); - frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc); - FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc); - - if(!read_frame_header_(decoder)) - return false; - if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */ - return true; - if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels, decoder->private_->frame.header.bits_per_sample)) - return false; - for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) { - /* - * first figure the correct bits-per-sample of the subframe - */ - uint32_t bps = decoder->private_->frame.header.bits_per_sample; - switch(decoder->private_->frame.header.channel_assignment) { - case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT: - /* no adjustment needed */ - break; - case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE: - FLAC__ASSERT(decoder->private_->frame.header.channels == 2); - if(channel == 1) - bps++; - break; - case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE: - FLAC__ASSERT(decoder->private_->frame.header.channels == 2); - if(channel == 0) - bps++; - break; - case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE: - FLAC__ASSERT(decoder->private_->frame.header.channels == 2); - if(channel == 1) - bps++; - break; - default: - FLAC__ASSERT(0); - } - /* - * now read it - */ - if(!read_subframe_(decoder, channel, bps, do_full_decode)){ - /* read_callback_ sets the state for us */ - if(decoder->protected_->state == FLAC__STREAM_DECODER_END_OF_STREAM) - break; - else - return false; - } - if(decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME) - break; - } - - if(decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM) - if(!read_zero_padding_(decoder)) - return false; - - /* - * Read the frame CRC-16 from the footer and check - */ - if(decoder->protected_->state == FLAC__STREAM_DECODER_READ_FRAME) { - frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input); - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN)) { - /* read_callback_ sets the state for us */ - if(decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM) - return false; - } -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - } - if(decoder->protected_->state == FLAC__STREAM_DECODER_READ_FRAME && frame_crc == x) { -#endif - if(do_full_decode) { - /* Undo any special channel coding */ - undo_channel_coding(decoder); - /* Check whether decoded data actually fits bps */ - for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) { - for(i = 0; i < decoder->private_->frame.header.blocksize; i++) { - int shift_bits = 32 - decoder->private_->frame.header.bits_per_sample; - /* Check whether shift_bits MSBs are 'empty' by shifting up and down */ - if((decoder->private_->output[channel][i] < (INT32_MIN >> shift_bits)) || - (decoder->private_->output[channel][i] > (INT32_MAX >> shift_bits))) { - /* Bad frame, emit error */ - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - break; - } - } - } - } - } -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - else if (decoder->protected_->state == FLAC__STREAM_DECODER_READ_FRAME) { - /* Bad frame, emit error */ - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - } -#endif - - /* Check whether frames are missing, if so, add silence to compensate */ - if(decoder->private_->last_frame_is_set && decoder->protected_->state == FLAC__STREAM_DECODER_READ_FRAME && !decoder->private_->is_seeking && do_full_decode) { - FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); - FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); - if(decoder->private_->last_frame.header.number.sample_number + decoder->private_->last_frame.header.blocksize < decoder->private_->frame.header.number.sample_number) { - uint32_t padding_samples_needed = decoder->private_->frame.header.number.sample_number - (decoder->private_->last_frame.header.number.sample_number + decoder->private_->last_frame.header.blocksize); - - /* Do some extra validation to assure last frame an current frame - * header are both valid before adding silence inbetween - * Technically both frames could be valid with differing sample_rates, - * channels and bits_per_sample, but it is quite rare */ - if(decoder->private_->last_frame.header.sample_rate == decoder->private_->frame.header.sample_rate && - decoder->private_->last_frame.header.channels == decoder->private_->frame.header.channels && - decoder->private_->last_frame.header.bits_per_sample == decoder->private_->frame.header.bits_per_sample && - decoder->private_->last_frame.header.blocksize >= 16) { - FLAC__Frame empty_frame; - FLAC__int32 * empty_buffer[FLAC__MAX_CHANNELS] = {NULL}; - empty_frame.header = decoder->private_->last_frame.header; - empty_frame.footer.crc = 0; - for(i = 0; i < empty_frame.header.channels; i++) { - empty_buffer[i] = safe_calloc_(empty_frame.header.blocksize, sizeof(FLAC__int32)); - if(empty_buffer[i] == NULL) { - for(i = 0; i < empty_frame.header.channels; i++) - if(empty_buffer[i] != NULL) - free(empty_buffer[i]); - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - } - /* No repairs larger than 5 seconds or 50 frames are made, to not - * unexpectedly create enormous files when one of the headers was - * corrupt after all */ - if(padding_samples_needed > (5*empty_frame.header.sample_rate)) - padding_samples_needed = 5*empty_frame.header.sample_rate; - if(padding_samples_needed > (50*empty_frame.header.blocksize)) - padding_samples_needed = 50*empty_frame.header.blocksize; - while(padding_samples_needed){ - empty_frame.header.number.sample_number += empty_frame.header.blocksize; - if(padding_samples_needed < empty_frame.header.blocksize) - empty_frame.header.blocksize = padding_samples_needed; - padding_samples_needed -= empty_frame.header.blocksize; - decoder->protected_->blocksize = empty_frame.header.blocksize; - - FLAC__ASSERT(empty_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); - decoder->private_->samples_decoded = empty_frame.header.number.sample_number + empty_frame.header.blocksize; - - for(channel = 0; channel < empty_frame.header.channels; channel++) { - empty_frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT; - empty_frame.subframes[channel].data.constant.value = 0; - empty_frame.subframes[channel].wasted_bits = 0; - } - - if(write_audio_frame_to_client_(decoder, &empty_frame, (const FLAC__int32 * const *)empty_buffer) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE) { - decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED; - for(i = 0; i < empty_frame.header.channels; i++) - if(empty_buffer[i] != NULL) - free(empty_buffer[i]); - return false; - } - } - for(i = 0; i < empty_frame.header.channels; i++) - if(empty_buffer[i] != NULL) - free(empty_buffer[i]); - - } - } - } - - if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC || decoder->protected_->state == FLAC__STREAM_DECODER_END_OF_STREAM) { - /* Got corruption, rewind if possible. Return value of seek - * isn't checked, if the seek fails the decoder will continue anyway */ - if(!FLAC__bitreader_rewind_to_after_last_seen_framesync(decoder->private_->input)){ -#ifndef NDEBUG - fprintf(stderr, "Rewinding, seeking necessary\n"); -#endif - if(decoder->private_->seek_callback && decoder->private_->last_seen_framesync){ - /* Last framesync isn't in bitreader anymore, rewind with seek if possible */ -#ifndef NDEBUG - FLAC__uint64 current_decode_position; - if(FLAC__stream_decoder_get_decode_position(decoder, ¤t_decode_position)) - fprintf(stderr, "Bitreader was %" PRIu64 " bytes short\n", current_decode_position-decoder->private_->last_seen_framesync); -#endif - if(decoder->private_->seek_callback(decoder, decoder->private_->last_seen_framesync, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - if(!FLAC__bitreader_clear(decoder->private_->input)) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - } - } -#ifndef NDEBUG - else{ - fprintf(stderr, "Rewinding, seeking not necessary\n"); - } -#endif - } - else { - *got_a_frame = true; - - /* we wait to update fixed_block_size until here, when we're sure we've got a proper frame and hence a correct blocksize */ - if(decoder->private_->next_fixed_block_size) - decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size; - - /* put the latest values into the public section of the decoder instance */ - decoder->protected_->channels = decoder->private_->frame.header.channels; - decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment; - decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample; - decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate; - decoder->protected_->blocksize = decoder->private_->frame.header.blocksize; - - FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); - decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize; - - /* write it */ - if(do_full_decode) { - if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE) { - decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED; - return false; - } - } - } - - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; -} - -FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder) -{ - FLAC__uint32 x; - FLAC__uint64 xx; - uint32_t i, blocksize_hint = 0, sample_rate_hint = 0; - FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */ - uint32_t raw_header_len; - FLAC__bool is_unparseable = false; - - FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)); - - /* init the raw header with the saved bits from synchronization */ - raw_header[0] = decoder->private_->header_warmup[0]; - raw_header[1] = decoder->private_->header_warmup[1]; - raw_header_len = 2; - - /* check to make sure that reserved bit is 0 */ - if(raw_header[1] & 0x02) /* MAGIC NUMBER */ - is_unparseable = true; - - /* - * Note that along the way as we read the header, we look for a sync - * code inside. If we find one it would indicate that our original - * sync was bad since there cannot be a sync code in a valid header. - * - * Three kinds of things can go wrong when reading the frame header: - * 1) We may have sync'ed incorrectly and not landed on a frame header. - * If we don't find a sync code, it can end up looking like we read - * a valid but unparseable header, until getting to the frame header - * CRC. Even then we could get a false positive on the CRC. - * 2) We may have sync'ed correctly but on an unparseable frame (from a - * future encoder). - * 3) We may be on a damaged frame which appears valid but unparseable. - * - * For all these reasons, we try and read a complete frame header as - * long as it seems valid, even if unparseable, up until the frame - * header CRC. - */ - - /* - * read in the raw header as bytes so we can CRC it, and parse it on the way - */ - for(i = 0; i < 2; i++) { - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) - return false; /* read_callback_ sets the state for us */ - if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */ - /* if we get here it means our original sync was erroneous since the sync code cannot appear in the header */ - decoder->private_->lookahead = (FLAC__byte)x; - decoder->private_->cached = true; - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - raw_header[raw_header_len++] = (FLAC__byte)x; - } - - switch(x = raw_header[2] >> 4) { - case 0: - is_unparseable = true; - break; - case 1: - decoder->private_->frame.header.blocksize = 192; - break; - case 2: - case 3: - case 4: - case 5: - decoder->private_->frame.header.blocksize = 576 << (x-2); - break; - case 6: - case 7: - blocksize_hint = x; - break; - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - decoder->private_->frame.header.blocksize = 256 << (x-8); - break; - default: - FLAC__ASSERT(0); - break; - } - - switch(x = raw_header[2] & 0x0f) { - case 0: - if(decoder->private_->has_stream_info) - decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate; - else - is_unparseable = true; - break; - case 1: - decoder->private_->frame.header.sample_rate = 88200; - break; - case 2: - decoder->private_->frame.header.sample_rate = 176400; - break; - case 3: - decoder->private_->frame.header.sample_rate = 192000; - break; - case 4: - decoder->private_->frame.header.sample_rate = 8000; - break; - case 5: - decoder->private_->frame.header.sample_rate = 16000; - break; - case 6: - decoder->private_->frame.header.sample_rate = 22050; - break; - case 7: - decoder->private_->frame.header.sample_rate = 24000; - break; - case 8: - decoder->private_->frame.header.sample_rate = 32000; - break; - case 9: - decoder->private_->frame.header.sample_rate = 44100; - break; - case 10: - decoder->private_->frame.header.sample_rate = 48000; - break; - case 11: - decoder->private_->frame.header.sample_rate = 96000; - break; - case 12: - case 13: - case 14: - sample_rate_hint = x; - break; - case 15: - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - default: - FLAC__ASSERT(0); - } - - x = (uint32_t)(raw_header[3] >> 4); - if(x & 8) { - decoder->private_->frame.header.channels = 2; - switch(x & 7) { - case 0: - decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE; - break; - case 1: - decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE; - break; - case 2: - decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE; - break; - default: - is_unparseable = true; - break; - } - } - else { - decoder->private_->frame.header.channels = (uint32_t)x + 1; - decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; - } - - switch(x = (uint32_t)(raw_header[3] & 0x0e) >> 1) { - case 0: - if(decoder->private_->has_stream_info) - decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample; - else - is_unparseable = true; - break; - case 1: - decoder->private_->frame.header.bits_per_sample = 8; - break; - case 2: - decoder->private_->frame.header.bits_per_sample = 12; - break; - case 3: - is_unparseable = true; - break; - case 4: - decoder->private_->frame.header.bits_per_sample = 16; - break; - case 5: - decoder->private_->frame.header.bits_per_sample = 20; - break; - case 6: - decoder->private_->frame.header.bits_per_sample = 24; - break; - case 7: - decoder->private_->frame.header.bits_per_sample = 32; - break; - default: - FLAC__ASSERT(0); - break; - } - -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* check to make sure that reserved bit is 0 */ - if(raw_header[3] & 0x01) /* MAGIC NUMBER */ - is_unparseable = true; -#endif - - /* read the frame's starting sample number (or frame number as the case may be) */ - if( - raw_header[1] & 0x01 || - /*@@@ this clause is a concession to the old way of doing variable blocksize; the only known implementation is flake and can probably be removed without inconveniencing anyone */ - (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize) - ) { /* variable blocksize */ - if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len)) - return false; /* read_callback_ sets the state for us */ - if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */ - decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */ - decoder->private_->cached = true; - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER; - decoder->private_->frame.header.number.sample_number = xx; - } - else { /* fixed blocksize */ - if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len)) - return false; /* read_callback_ sets the state for us */ - if(x == 0xffffffff) { /* i.e. non-UTF8 code... */ - decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */ - decoder->private_->cached = true; - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER; - decoder->private_->frame.header.number.frame_number = x; - } - - if(blocksize_hint) { - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) - return false; /* read_callback_ sets the state for us */ - raw_header[raw_header_len++] = (FLAC__byte)x; - if(blocksize_hint == 7) { - FLAC__uint32 _x; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8)) - return false; /* read_callback_ sets the state for us */ - raw_header[raw_header_len++] = (FLAC__byte)_x; - x = (x << 8) | _x; - } - decoder->private_->frame.header.blocksize = x+1; - if(decoder->private_->frame.header.blocksize > 65535) { /* invalid blocksize (65536) specified */ - decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */ - decoder->private_->cached = true; - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - - } - - if(sample_rate_hint) { - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) - return false; /* read_callback_ sets the state for us */ - raw_header[raw_header_len++] = (FLAC__byte)x; - if(sample_rate_hint != 12) { - FLAC__uint32 _x; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8)) - return false; /* read_callback_ sets the state for us */ - raw_header[raw_header_len++] = (FLAC__byte)_x; - x = (x << 8) | _x; - } - if(sample_rate_hint == 12) - decoder->private_->frame.header.sample_rate = x*1000; - else if(sample_rate_hint == 13) - decoder->private_->frame.header.sample_rate = x; - else - decoder->private_->frame.header.sample_rate = x*10; - } - - /* read the CRC-8 byte */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) - return false; /* read_callback_ sets the state for us */ - crc8 = (FLAC__byte)x; - -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - if(FLAC__crc8(raw_header, raw_header_len) != crc8) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } -#endif - - /* calculate the sample number from the frame number if needed */ - decoder->private_->next_fixed_block_size = 0; - if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) { - x = decoder->private_->frame.header.number.frame_number; - decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER; - if(decoder->private_->fixed_block_size) - decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x; - else if(decoder->private_->has_stream_info) { - if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) { - decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x; - decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize; - } - else - is_unparseable = true; - } - else if(x == 0) { - decoder->private_->frame.header.number.sample_number = 0; - decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize; - } - else { - /* can only get here if the stream has invalid frame numbering and no STREAMINFO, so assume it's not the last (possibly short) frame */ - decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x; - } - } - - if(is_unparseable) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - - return true; -} - -FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode) -{ - FLAC__uint32 x; - FLAC__bool wasted_bits; - uint32_t i; - - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */ - return false; /* read_callback_ sets the state for us */ - - wasted_bits = (x & 1); - x &= 0xfe; - - if(wasted_bits) { - uint32_t u; - if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u)) - return false; /* read_callback_ sets the state for us */ - decoder->private_->frame.subframes[channel].wasted_bits = u+1; - if (decoder->private_->frame.subframes[channel].wasted_bits >= bps) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - bps -= decoder->private_->frame.subframes[channel].wasted_bits; - } - else - decoder->private_->frame.subframes[channel].wasted_bits = 0; - - /* - * Lots of magic numbers here - */ - if(x & 0x80) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - else if(x == 0) { - if(!read_subframe_constant_(decoder, channel, bps, do_full_decode)) - return false; - } - else if(x == 2) { - if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode)) - return false; - } - else if(x < 16) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - else if(x <= 24) { - uint32_t predictor_order = (x>>1)&7; - if(decoder->private_->frame.header.blocksize <= predictor_order){ - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - if(!read_subframe_fixed_(decoder, channel, bps, predictor_order, do_full_decode)) - return false; - if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */ - return true; - } - else if(x < 64) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - else { - uint32_t predictor_order = ((x>>1)&31)+1; - if(decoder->private_->frame.header.blocksize <= predictor_order){ - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - if(!read_subframe_lpc_(decoder, channel, bps, predictor_order, do_full_decode)) - return false; - if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */ - return true; - } - - if(wasted_bits && do_full_decode) { - x = decoder->private_->frame.subframes[channel].wasted_bits; - if((bps + x) < 33) { - for(i = 0; i < decoder->private_->frame.header.blocksize; i++) { - uint32_t val = decoder->private_->output[channel][i]; - decoder->private_->output[channel][i] = (val << x); - } - } - else { - /* When there are wasted bits, bps is never 33 and so - * side_subframe is never already in use */ - FLAC__ASSERT(!decoder->private_->side_subframe_in_use); - decoder->private_->side_subframe_in_use = true; - for(i = 0; i < decoder->private_->frame.header.blocksize; i++) { - uint64_t val = decoder->private_->output[channel][i]; - decoder->private_->side_subframe[i] = (val << x); - } - } - } - - return true; -} - -FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode) -{ - FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant; - FLAC__int64 x; - uint32_t i; - - decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT; - - if(!FLAC__bitreader_read_raw_int64(decoder->private_->input, &x, bps)) - return false; /* read_callback_ sets the state for us */ - - subframe->value = x; - - /* decode the subframe */ - if(do_full_decode) { - if(bps <= 32) { - FLAC__int32 *output = decoder->private_->output[channel]; - for(i = 0; i < decoder->private_->frame.header.blocksize; i++) - output[i] = x; - } else { - FLAC__int64 *output = decoder->private_->side_subframe; - decoder->private_->side_subframe_in_use = true; - for(i = 0; i < decoder->private_->frame.header.blocksize; i++) - output[i] = x; - } - } - - return true; -} - -FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, const uint32_t order, FLAC__bool do_full_decode) -{ - FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed; - FLAC__int64 i64; - FLAC__uint32 u32; - uint32_t u; - - decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED; - - subframe->residual = decoder->private_->residual[channel]; - subframe->order = order; - - /* read warm-up samples */ - for(u = 0; u < order; u++) { - if(!FLAC__bitreader_read_raw_int64(decoder->private_->input, &i64, bps)) - return false; /* read_callback_ sets the state for us */ - subframe->warmup[u] = i64; - } - - /* read entropy coding method info */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN)) - return false; /* read_callback_ sets the state for us */ - subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32; - switch(subframe->entropy_coding_method.type) { - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE: - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2: - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN)) - return false; /* read_callback_ sets the state for us */ - if((decoder->private_->frame.header.blocksize >> u32 < order) || - (decoder->private_->frame.header.blocksize % (1 << u32) > 0)) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - subframe->entropy_coding_method.data.partitioned_rice.order = u32; - subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel]; - break; - default: - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - - /* read residual */ - switch(subframe->entropy_coding_method.type) { - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE: - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2: - if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel], /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2)) - return false; - break; - default: - FLAC__ASSERT(0); - } - - /* decode the subframe */ - if(do_full_decode) { - if(bps < 33){ - uint32_t i; - for(i = 0; i < order; i++) - decoder->private_->output[channel][i] = subframe->warmup[i]; - if(bps+order <= 32) - FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order); - else - FLAC__fixed_restore_signal_wide(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order); - } - else { - decoder->private_->side_subframe_in_use = true; - memcpy(decoder->private_->side_subframe, subframe->warmup, sizeof(FLAC__int64) * order); - FLAC__fixed_restore_signal_wide_33bit(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->side_subframe+order); - } - } - - return true; -} - -FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, const uint32_t order, FLAC__bool do_full_decode) -{ - FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc; - FLAC__int32 i32; - FLAC__int64 i64; - FLAC__uint32 u32; - uint32_t u; - - decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC; - - subframe->residual = decoder->private_->residual[channel]; - subframe->order = order; - - /* read warm-up samples */ - for(u = 0; u < order; u++) { - if(!FLAC__bitreader_read_raw_int64(decoder->private_->input, &i64, bps)) - return false; /* read_callback_ sets the state for us */ - subframe->warmup[u] = i64; - } - - /* read qlp coeff precision */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN)) - return false; /* read_callback_ sets the state for us */ - if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - subframe->qlp_coeff_precision = u32+1; - - /* read qlp shift */ - if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN)) - return false; /* read_callback_ sets the state for us */ - if(i32 < 0) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - subframe->quantization_level = i32; - - /* read quantized lp coefficiencts */ - for(u = 0; u < order; u++) { - if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision)) - return false; /* read_callback_ sets the state for us */ - subframe->qlp_coeff[u] = i32; - } - - /* read entropy coding method info */ - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN)) - return false; /* read_callback_ sets the state for us */ - subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32; - switch(subframe->entropy_coding_method.type) { - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE: - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2: - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN)) - return false; /* read_callback_ sets the state for us */ - if((decoder->private_->frame.header.blocksize >> u32 < order) || - (decoder->private_->frame.header.blocksize % (1 << u32) > 0)) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - subframe->entropy_coding_method.data.partitioned_rice.order = u32; - subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel]; - break; - default: - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - - /* read residual */ - switch(subframe->entropy_coding_method.type) { - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE: - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2: - if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel], /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2)) - return false; - break; - default: - FLAC__ASSERT(0); - } - - /* decode the subframe */ - if(do_full_decode) { - if(bps <= 32) { - uint32_t i; - for(i = 0; i < order; i++) - decoder->private_->output[channel][i] = subframe->warmup[i]; - if(FLAC__lpc_max_residual_bps(bps, subframe->qlp_coeff, order, subframe->quantization_level) <= 32 && - FLAC__lpc_max_prediction_before_shift_bps(bps, subframe->qlp_coeff, order) <= 32) - FLAC__lpc_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order); - else - FLAC__lpc_restore_signal_wide(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order); - } - else { - decoder->private_->side_subframe_in_use = true; - memcpy(decoder->private_->side_subframe, subframe->warmup, sizeof(FLAC__int64) * order); - FLAC__lpc_restore_signal_wide_33bit(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->side_subframe+order); - } - } - - return true; -} - -FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode) -{ - FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim; - uint32_t i; - - decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM; - - if(bps < 33) { - FLAC__int32 x, *residual = decoder->private_->residual[channel]; - - subframe->data_type = FLAC__VERBATIM_SUBFRAME_DATA_TYPE_INT32; - subframe->data.int32 = residual; - - for(i = 0; i < decoder->private_->frame.header.blocksize; i++) { - if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps)) - return false; /* read_callback_ sets the state for us */ - residual[i] = x; - } - - /* decode the subframe */ - if(do_full_decode) - memcpy(decoder->private_->output[channel], subframe->data.int32, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize); - } - else { - FLAC__int64 x, *side = decoder->private_->side_subframe; - - subframe->data_type = FLAC__VERBATIM_SUBFRAME_DATA_TYPE_INT64; - subframe->data.int64 = side; - decoder->private_->side_subframe_in_use = true; - - for(i = 0; i < decoder->private_->frame.header.blocksize; i++) { - if(!FLAC__bitreader_read_raw_int64(decoder->private_->input, &x, bps)) - return false; /* read_callback_ sets the state for us */ - side[i] = x; - } - } - - return true; -} - -FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, uint32_t predictor_order, uint32_t partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended) -{ - FLAC__uint32 rice_parameter; - int i; - uint32_t partition, sample, u; - const uint32_t partitions = 1u << partition_order; - const uint32_t partition_samples = decoder->private_->frame.header.blocksize >> partition_order; - const uint32_t plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; - const uint32_t pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER; - - /* invalid predictor and partition orders mush be handled in the callers */ - FLAC__ASSERT(partition_order > 0? partition_samples >= predictor_order : decoder->private_->frame.header.blocksize >= predictor_order); - - if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, flac_max(6u, partition_order))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - - sample = 0; - for(partition = 0; partition < partitions; partition++) { - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen)) - return false; /* read_callback_ sets the state for us */ - partitioned_rice_contents->parameters[partition] = rice_parameter; - if(rice_parameter < pesc) { - partitioned_rice_contents->raw_bits[partition] = 0; - u = (partition == 0) ? partition_samples - predictor_order : partition_samples; - if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, residual + sample, u, rice_parameter)){ - if(decoder->protected_->state == FLAC__STREAM_DECODER_READ_FRAME) { - /* no error was set, read_callback_ didn't set it, so - * invalid rice symbol was found */ - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - return true; - } - else - return false; /* read_callback_ sets the state for us */ - } - sample += u; - } - else { - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN)) - return false; /* read_callback_ sets the state for us */ - partitioned_rice_contents->raw_bits[partition] = rice_parameter; - if(rice_parameter == 0) { - for(u = (partition == 0)? predictor_order : 0; u < partition_samples; u++, sample++) - residual[sample] = 0; - } - else{ - for(u = (partition == 0)? predictor_order : 0; u < partition_samples; u++, sample++) { - if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i, rice_parameter)) - return false; /* read_callback_ sets the state for us */ - residual[sample] = i; - } - } - } - } - - return true; -} - -FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder) -{ - if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) { - FLAC__uint32 zero = 0; - if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input))) - return false; /* read_callback_ sets the state for us */ -#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - if(zero != 0) { - send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC); - decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC; - } -#endif - } - return true; -} - -FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data) -{ - FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data; - - if( -#if FLAC__HAS_OGG - /* see [1] HACK NOTE below for why we don't call the eof_callback when decoding Ogg FLAC */ - !decoder->private_->is_ogg && -#endif - decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data) - ) { - *bytes = 0; - decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM; - return false; - } - else if(*bytes > 0) { - /* While seeking, it is possible for our seek to land in the - * middle of audio data that looks exactly like a frame header - * from a future version of an encoder. When that happens, our - * error callback will get an - * FLAC__STREAM_DECODER_UNPARSEABLE_STREAM and increment its - * unparseable_frame_count. But there is a remote possibility - * that it is properly synced at such a "future-codec frame", - * so to make sure, we wait to see many "unparseable" errors in - * a row before bailing out. - */ - if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) { - decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED; - return false; - } - else { - const FLAC__StreamDecoderReadStatus status = -#if FLAC__HAS_OGG - decoder->private_->is_ogg? - read_callback_ogg_aspect_(decoder, buffer, bytes) : -#endif - decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data) - ; - if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) { - decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED; - return false; - } - else if(*bytes == 0) { - if( - status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM || - ( -#if FLAC__HAS_OGG - /* see [1] HACK NOTE below for why we don't call the eof_callback when decoding Ogg FLAC */ - !decoder->private_->is_ogg && -#endif - decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data) - ) - ) { - decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM; - return false; - } - else - return true; - } - else - return true; - } - } - else { - /* abort to avoid a deadlock */ - decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED; - return false; - } - /* [1] @@@ HACK NOTE: The end-of-stream checking has to be hacked around - * for Ogg FLAC. This is because the ogg decoder aspect can lose sync - * and at the same time hit the end of the stream (for example, seeking - * to a point that is after the beginning of the last Ogg page). There - * is no way to report an Ogg sync loss through the callbacks (see note - * in read_callback_ogg_aspect_()) so it returns CONTINUE with *bytes==0. - * So to keep the decoder from stopping at this point we gate the call - * to the eof_callback and let the Ogg decoder aspect set the - * end-of-stream state when it is needed. - */ -} - -#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && !defined(FUZZING_BUILD_MODE_FLAC_SANITIZE_SIGNED_INTEGER_OVERFLOW) -/* The attribute below is to silence the undefined sanitizer of oss-fuzz. - * Because fuzzing feeds bogus predictors and residual samples to the - * decoder, having overflows in this section is unavoidable. Also, - * because the calculated values are audio path only, there is no - * potential for security problems */ -__attribute__((no_sanitize("signed-integer-overflow"))) -#endif -void undo_channel_coding(FLAC__StreamDecoder *decoder) { - uint32_t i; - switch(decoder->private_->frame.header.channel_assignment) { - case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT: - /* do nothing */ - break; - case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE: - FLAC__ASSERT(decoder->private_->frame.header.channels == 2); - FLAC__ASSERT(decoder->private_->side_subframe_in_use != /* logical XOR */ (decoder->private_->frame.header.bits_per_sample < 32)); - for(i = 0; i < decoder->private_->frame.header.blocksize; i++) - if(decoder->private_->side_subframe_in_use) - decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->side_subframe[i]; - else - decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i]; - break; - case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE: - FLAC__ASSERT(decoder->private_->frame.header.channels == 2); - FLAC__ASSERT(decoder->private_->side_subframe_in_use != /* logical XOR */ (decoder->private_->frame.header.bits_per_sample < 32)); - for(i = 0; i < decoder->private_->frame.header.blocksize; i++) - if(decoder->private_->side_subframe_in_use) - decoder->private_->output[0][i] = decoder->private_->output[1][i] + decoder->private_->side_subframe[i]; - else - decoder->private_->output[0][i] += decoder->private_->output[1][i]; - break; - case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE: - FLAC__ASSERT(decoder->private_->frame.header.channels == 2); - FLAC__ASSERT(decoder->private_->side_subframe_in_use != /* logical XOR */ (decoder->private_->frame.header.bits_per_sample < 32)); - for(i = 0; i < decoder->private_->frame.header.blocksize; i++) { - if(!decoder->private_->side_subframe_in_use){ - FLAC__int32 mid, side; - mid = decoder->private_->output[0][i]; - side = decoder->private_->output[1][i]; - mid = ((uint32_t) mid) << 1; - mid |= (side & 1); /* i.e. if 'side' is odd... */ - decoder->private_->output[0][i] = (mid + side) >> 1; - decoder->private_->output[1][i] = (mid - side) >> 1; - } - else { /* bps == 32 */ - FLAC__int64 mid; - mid = ((uint64_t)decoder->private_->output[0][i]) << 1; - mid |= (decoder->private_->side_subframe[i] & 1); /* i.e. if 'side' is odd... */ - decoder->private_->output[0][i] = (mid + decoder->private_->side_subframe[i]) >> 1; - decoder->private_->output[1][i] = (mid - decoder->private_->side_subframe[i]) >> 1; - } - } - break; - default: - FLAC__ASSERT(0); - break; - } -} - -#if FLAC__HAS_OGG -FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes) -{ - switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) { - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK: - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - /* we don't really have a way to handle lost sync via read - * callback so we'll let it pass and let the underlying - * FLAC decoder catch the error - */ - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC: - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM: - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC: - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION: - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT: - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR: - case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR: - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - default: - FLAC__ASSERT(0); - /* double protection */ - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - } -} - -FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) -{ - FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder; - - switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) { - case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE: - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK; - case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM: - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM; - case FLAC__STREAM_DECODER_READ_STATUS_ABORT: - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT; - default: - /* double protection: */ - FLAC__ASSERT(0); - return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT; - } -} -#endif - -FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]) -{ - decoder->private_->last_frame = *frame; /* save the frame */ - decoder->private_->last_frame_is_set = true; - if(decoder->private_->is_seeking) { - FLAC__uint64 this_frame_sample = frame->header.number.sample_number; - FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize; - FLAC__uint64 target_sample = decoder->private_->target_sample; - - FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); - -#if FLAC__HAS_OGG - decoder->private_->got_a_frame = true; -#endif - if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */ - uint32_t delta = (uint32_t)(target_sample - this_frame_sample); - /* kick out of seek mode */ - decoder->private_->is_seeking = false; - /* shift out the samples before target_sample */ - if(delta > 0) { - uint32_t channel; - const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS]; - for(channel = 0; channel < frame->header.channels; channel++) { - newbuffer[channel] = buffer[channel] + delta; - decoder->private_->last_frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM; - decoder->private_->last_frame.subframes[channel].data.verbatim.data_type = FLAC__VERBATIM_SUBFRAME_DATA_TYPE_INT32; - decoder->private_->last_frame.subframes[channel].data.verbatim.data.int32 = newbuffer[channel]; - } - decoder->private_->last_frame.header.blocksize -= delta; - decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta; - /* write the relevant samples */ - return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data); - } - else { - /* write the relevant samples */ - return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data); - } - } - else { - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; - } - } - else { - /* - * If we never got STREAMINFO, turn off MD5 checking to save - * cycles since we don't have a sum to compare to anyway - */ - if(!decoder->private_->has_stream_info) - decoder->private_->do_md5_checking = false; - if(decoder->private_->do_md5_checking) { - if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8)) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data); - } -} - -void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status) -{ - if(!decoder->private_->is_seeking) - decoder->private_->error_callback(decoder, status, decoder->private_->client_data); - else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM) - decoder->private_->unparseable_frame_count++; -} - -FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample) -{ - FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample; - FLAC__int64 pos = -1; - int i; - uint32_t approx_bytes_per_frame; - FLAC__bool first_seek = true, seek_from_lower_bound = false; - const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder); - const uint32_t min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize; - const uint32_t max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize; - const uint32_t max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize; - const uint32_t min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize; - /* take these from the current frame in case they've changed mid-stream */ - uint32_t channels = FLAC__stream_decoder_get_channels(decoder); - uint32_t bps = FLAC__stream_decoder_get_bits_per_sample(decoder); - const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0; - - /* use values from stream info if we didn't decode a frame */ - if(channels == 0) - channels = decoder->private_->stream_info.data.stream_info.channels; - if(bps == 0) - bps = decoder->private_->stream_info.data.stream_info.bits_per_sample; - - /* we are just guessing here */ - if(max_framesize > 0) - approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1; - /* - * Check if it's a known fixed-blocksize stream. Note that though - * the spec doesn't allow zeroes in the STREAMINFO block, we may - * never get a STREAMINFO block when decoding so the value of - * min_blocksize might be zero. - */ - else if(min_blocksize == max_blocksize && min_blocksize > 0) { - /* note there are no () around 'bps/8' to keep precision up since it's an integer calculation */ - approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64; - } - else - approx_bytes_per_frame = 4096 * channels * bps/8 + 64; - - /* - * First, we set an upper and lower bound on where in the - * stream we will search. For now we take the current position - * as one bound and, depending on where the target position lies, - * the beginning of the first frame or the end of the stream as - * the other bound. - */ - lower_bound = first_frame_offset; - lower_bound_sample = 0; - upper_bound = stream_length; - upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/; - - if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC && - decoder->private_->samples_decoded != 0) { - if(target_sample < decoder->private_->samples_decoded) { - if(FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) - upper_bound_sample = decoder->private_->samples_decoded; - } else { - if(FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) - lower_bound_sample = decoder->private_->samples_decoded; - } - } - - /* - * Now we refine the bounds if we have a seektable with - * suitable points. Note that according to the spec they - * must be ordered by ascending sample number. - * - * Note: to protect against invalid seek tables we will ignore points - * that have frame_samples==0 or sample_number>=total_samples. Also, - * because math is limited to 64-bit ints, seekpoints with an offset - * larger than 2^63 (8 exbibyte) are rejected. - */ - if(seek_table) { - FLAC__uint64 new_lower_bound = lower_bound; - FLAC__uint64 new_upper_bound = upper_bound; - FLAC__uint64 new_lower_bound_sample = lower_bound_sample; - FLAC__uint64 new_upper_bound_sample = upper_bound_sample; - - /* find the closest seek point <= target_sample, if it exists */ - for(i = (int)seek_table->num_points - 1; i >= 0; i--) { - if( - seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER && - seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */ - (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */ - seek_table->points[i].sample_number <= target_sample - ) - break; - } - if(i >= 0) { /* i.e. we found a suitable seek point... */ - new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset; - new_lower_bound_sample = seek_table->points[i].sample_number; - } - - /* find the closest seek point > target_sample, if it exists */ - for(i = 0; i < (int)seek_table->num_points; i++) { - if( - seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER && - seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */ - (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */ - seek_table->points[i].sample_number > target_sample - ) - break; - } - if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */ - new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset; - new_upper_bound_sample = seek_table->points[i].sample_number; - } - /* final protection against unsorted seek tables; keep original values if bogus */ - if(new_upper_bound >= new_lower_bound) { - lower_bound = new_lower_bound; - upper_bound = new_upper_bound; - lower_bound_sample = new_lower_bound_sample; - upper_bound_sample = new_upper_bound_sample; - } - } - - FLAC__ASSERT(upper_bound_sample >= lower_bound_sample); - /* there are 2 insidious ways that the following equality occurs, which - * we need to fix: - * 1) total_samples is 0 (unknown) and target_sample is 0 - * 2) total_samples is 0 (unknown) and target_sample happens to be - * exactly equal to the last seek point in the seek table; this - * means there is no seek point above it, and upper_bound_samples - * remains equal to the estimate (of target_samples) we made above - * in either case it does not hurt to move upper_bound_sample up by 1 - */ - if(upper_bound_sample == lower_bound_sample) - upper_bound_sample++; - - decoder->private_->target_sample = target_sample; - while(1) { - /* check whether decoder is still valid so bad state isn't overwritten - * with seek error */ - if(decoder->protected_->state == FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR || - decoder->protected_->state == FLAC__STREAM_DECODER_ABORTED) - return false; - /* check if the bounds are still ok */ - if (lower_bound_sample >= upper_bound_sample || - lower_bound > upper_bound || - upper_bound >= INT64_MAX) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - if(seek_from_lower_bound) { - pos = lower_bound; - } - else { -#ifndef FLAC__INTEGER_ONLY_LIBRARY - pos = (FLAC__int64)lower_bound + (FLAC__int64)((double)(target_sample - lower_bound_sample) / (double)(upper_bound_sample - lower_bound_sample) * (double)(upper_bound - lower_bound)) - approx_bytes_per_frame; -#else - /* a little less accurate: */ - if(upper_bound - lower_bound < 0xffffffff) - pos = (FLAC__int64)lower_bound + (FLAC__int64)(((target_sample - lower_bound_sample) * (upper_bound - lower_bound)) / (upper_bound_sample - lower_bound_sample)) - approx_bytes_per_frame; - else { /* @@@ WATCHOUT, ~2TB limit */ - FLAC__uint64 ratio = (1<<16) / (upper_bound_sample - lower_bound_sample); - pos = (FLAC__int64)lower_bound + (FLAC__int64)((((target_sample - lower_bound_sample)>>8) * ((upper_bound - lower_bound)>>8) * ratio)) - approx_bytes_per_frame; - } -#endif - } - if(pos >= (FLAC__int64)upper_bound) - pos = (FLAC__int64)upper_bound - 1; - if(pos < (FLAC__int64)lower_bound) - pos = (FLAC__int64)lower_bound; - if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - if(!FLAC__stream_decoder_flush(decoder)) { - /* above call sets the state for us */ - return false; - } - /* Now we need to get a frame. First we need to reset our - * unparseable_frame_count; if we get too many unparseable - * frames in a row, the read callback will return - * FLAC__STREAM_DECODER_READ_STATUS_ABORT, causing - * FLAC__stream_decoder_process_single() to return false. - */ - decoder->private_->unparseable_frame_count = 0; - if(!FLAC__stream_decoder_process_single(decoder) || decoder->protected_->state == FLAC__STREAM_DECODER_ABORTED || 0 == decoder->private_->samples_decoded) { - /* No frame could be decoded */ - if(decoder->protected_->state != FLAC__STREAM_DECODER_ABORTED && decoder->private_->eof_callback(decoder, decoder->private_->client_data) && !seek_from_lower_bound){ - /* decoder has hit end of stream while processing corrupt - * frame. To remedy this, try decoding a frame at the lower - * bound so the seek after that hopefully ends up somewhere - * else */ - seek_from_lower_bound = true; - continue; - } - else { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - } - seek_from_lower_bound = false; - - /* our write callback will change the state when it gets to the target frame */ - /* actually, we could have got_a_frame if our decoder is at FLAC__STREAM_DECODER_END_OF_STREAM so we need to check for that also */ - if(!decoder->private_->is_seeking) - break; - - FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); - this_frame_sample = decoder->private_->last_frame.header.number.sample_number; - - if(this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek) { - if (pos == (FLAC__int64)lower_bound) { - /* can't move back any more than the first frame, something is fatally wrong */ - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - /* our last move backwards wasn't big enough, try again */ - approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16; - continue; - } - /* allow one seek over upper bound, so we can get a correct upper_bound_sample for streams with unknown total_samples */ - first_seek = false; - - /* make sure we are not seeking in corrupted stream */ - if (this_frame_sample < lower_bound_sample) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - - /* we need to narrow the search */ - if(target_sample < this_frame_sample) { - upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize; -/*@@@@@@ what will decode position be if at end of stream? */ - if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - approx_bytes_per_frame = (uint32_t)(2 * (upper_bound - pos) / 3 + 16); - } - else { /* target_sample >= this_frame_sample + this frame's blocksize */ - lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize; - if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - approx_bytes_per_frame = (uint32_t)(2 * (lower_bound - pos) / 3 + 16); - } - } - - return true; -} - -#if FLAC__HAS_OGG -FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample) -{ - FLAC__uint64 left_pos = 0, right_pos = stream_length; - FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder); - FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1; - FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */ - FLAC__bool did_a_seek; - uint32_t iteration = 0; - - /* In the first iterations, we will calculate the target byte position - * by the distance from the target sample to left_sample and - * right_sample (let's call it "proportional search"). After that, we - * will switch to binary search. - */ - uint32_t BINARY_SEARCH_AFTER_ITERATION = 2; - - /* We will switch to a linear search once our current sample is less - * than this number of samples ahead of the target sample - */ - static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2; - - /* If the total number of samples is unknown, use a large value, and - * force binary search immediately. - */ - if(right_sample == 0) { - right_sample = (FLAC__uint64)(-1); - BINARY_SEARCH_AFTER_ITERATION = 0; - } - - decoder->private_->target_sample = target_sample; - for( ; ; iteration++) { - /* Do sanity checks on bounds */ - if(right_pos <= left_pos || right_pos - left_pos < 9) { - /* FLAC frame is at least 9 byte in size */ - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) { - if (iteration >= BINARY_SEARCH_AFTER_ITERATION) { - pos = (right_pos + left_pos) / 2; - } - else { -#ifndef FLAC__INTEGER_ONLY_LIBRARY - pos = (FLAC__uint64)((double)(target_sample - left_sample) / (double)(right_sample - left_sample) * (double)(right_pos - left_pos)); -#else - /* a little less accurate: */ - if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff)) - pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample)); - else /* @@@ WATCHOUT, ~2TB limit */ - pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16)); -#endif - /* @@@ TODO: might want to limit pos to some distance - * before EOF, to make sure we land before the last frame, - * thereby getting a this_frame_sample and so having a better - * estimate. - */ - } - - /* physical seek */ - if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - if(!FLAC__stream_decoder_flush(decoder)) { - /* above call sets the state for us */ - return false; - } - did_a_seek = true; - } - else - did_a_seek = false; - - decoder->private_->got_a_frame = false; - if(!FLAC__stream_decoder_process_single(decoder) || - decoder->protected_->state == FLAC__STREAM_DECODER_ABORTED) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - if(!decoder->private_->got_a_frame) { - if(did_a_seek) { - /* this can happen if we seek to a point after the last frame; we drop - * to binary search right away in this case to avoid any wasted - * iterations of proportional search. - */ - right_pos = pos; - BINARY_SEARCH_AFTER_ITERATION = 0; - } - else { - /* this can probably only happen if total_samples is unknown and the - * target_sample is past the end of the stream - */ - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - } - /* our write callback will change the state when it gets to the target frame */ - else if(!decoder->private_->is_seeking) { - break; - } - else { - this_frame_sample = decoder->private_->last_frame.header.number.sample_number; - FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); - - if (did_a_seek) { - if (this_frame_sample <= target_sample) { - /* The 'equal' case should not happen, since - * FLAC__stream_decoder_process_single() - * should recognize that it has hit the - * target sample and we would exit through - * the 'break' above. - */ - FLAC__ASSERT(this_frame_sample != target_sample); - - left_sample = this_frame_sample; - /* sanity check to avoid infinite loop */ - if (left_pos == pos) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - left_pos = pos; - } - else { - right_sample = this_frame_sample; - /* sanity check to avoid infinite loop */ - if (right_pos == pos) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - right_pos = pos; - } - } - } - } - - return true; -} -#endif - -FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) -{ - (void)client_data; - - if(*bytes > 0) { - *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file); - if(ferror(decoder->private_->file)) - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - else if(*bytes == 0) - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - else - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - else - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */ -} - -FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) -{ - (void)client_data; - - if(decoder->private_->file == stdin) - return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; - else if(fseeko(decoder->private_->file, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0) - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - else - return FLAC__STREAM_DECODER_SEEK_STATUS_OK; -} - -FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) -{ - FLAC__off_t pos; - (void)client_data; - - if(decoder->private_->file == stdin) - return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED; - else if((pos = ftello(decoder->private_->file)) < 0) - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - else { - *absolute_byte_offset = (FLAC__uint64)pos; - return FLAC__STREAM_DECODER_TELL_STATUS_OK; - } -} - -FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) -{ - struct flac_stat_s filestats; - (void)client_data; - - if(decoder->private_->file == stdin) - return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; - -#ifndef FLAC__USE_FILELENGTHI64 - if(flac_fstat(fileno(decoder->private_->file), &filestats) != 0) -#else - filestats.st_size = _filelengthi64(fileno(decoder->private_->file)); - if(filestats.st_size < 0) -#endif - return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - else { - *stream_length = (FLAC__uint64)filestats.st_size; - return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; - } -} - -FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data) -{ - (void)client_data; - - return feof(decoder->private_->file)? true : false; -} diff --git a/flac/src/libFLAC/stream_encoder.c b/flac/src/libFLAC/stream_encoder.c deleted file mode 100644 index c1c03e4..0000000 --- a/flac/src/libFLAC/stream_encoder.c +++ /dev/null @@ -1,4738 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include /* for malloc() */ -#include /* for memcpy() */ -#include /* for off_t */ -#ifdef _WIN32 -#include /* for GetFileType() */ -#include /* for _get_osfhandle() */ -#endif -#include "share/compat.h" -#include "FLAC/assert.h" -#include "FLAC/stream_decoder.h" -#include "protected/stream_encoder.h" -#include "private/bitwriter.h" -#include "private/bitmath.h" -#include "private/crc.h" -#include "private/cpu.h" -#include "private/fixed.h" -#include "private/format.h" -#include "private/lpc.h" -#include "private/md5.h" -#include "private/memory.h" -#include "private/macros.h" -#if FLAC__HAS_OGG -#include "private/ogg_helper.h" -#include "private/ogg_mapping.h" -#endif -#include "private/stream_encoder.h" -#include "private/stream_encoder_framing.h" -#include "private/window.h" -#include "share/alloc.h" -#include "share/private.h" - - -/* Exact Rice codeword length calculation is off by default. The simple - * (and fast) estimation (of how many bits a residual value will be - * encoded with) in this encoder is very good, almost always yielding - * compression within 0.1% of exact calculation. - */ -#undef EXACT_RICE_BITS_CALCULATION -/* Rice parameter searching is off by default. The simple (and fast) - * parameter estimation in this encoder is very good, almost always - * yielding compression within 0.1% of the optimal parameters. - */ -#undef ENABLE_RICE_PARAMETER_SEARCH - - -typedef struct { - FLAC__int32 *data[FLAC__MAX_CHANNELS]; - uint32_t size; /* of each data[] in samples */ - uint32_t tail; -} verify_input_fifo; - -typedef struct { - const FLAC__byte *data; - uint32_t capacity; - uint32_t bytes; -} verify_output; - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -typedef struct { - uint32_t a, b, c; - FLAC__ApodizationSpecification * current_apodization; - double autoc_root[FLAC__MAX_LPC_ORDER+1]; - double autoc[FLAC__MAX_LPC_ORDER+1]; -} apply_apodization_state_struct; -#endif - -typedef enum { - ENCODER_IN_MAGIC = 0, - ENCODER_IN_METADATA = 1, - ENCODER_IN_AUDIO = 2 -} EncoderStateHint; - -static const struct CompressionLevels { - FLAC__bool do_mid_side_stereo; - FLAC__bool loose_mid_side_stereo; - uint32_t max_lpc_order; - uint32_t qlp_coeff_precision; - FLAC__bool do_qlp_coeff_prec_search; - FLAC__bool do_escape_coding; - FLAC__bool do_exhaustive_model_search; - uint32_t min_residual_partition_order; - uint32_t max_residual_partition_order; - uint32_t rice_parameter_search_dist; - const char *apodization; -} compression_levels_[] = { - { false, false, 0, 0, false, false, false, 0, 3, 0, "tukey(5e-1)" }, - { true , true , 0, 0, false, false, false, 0, 3, 0, "tukey(5e-1)" }, - { true , false, 0, 0, false, false, false, 0, 3, 0, "tukey(5e-1)" }, - { false, false, 6, 0, false, false, false, 0, 4, 0, "tukey(5e-1)" }, - { true , true , 8, 0, false, false, false, 0, 4, 0, "tukey(5e-1)" }, - { true , false, 8, 0, false, false, false, 0, 5, 0, "tukey(5e-1)" }, - { true , false, 8, 0, false, false, false, 0, 6, 0, "subdivide_tukey(2)" }, - { true , false, 12, 0, false, false, false, 0, 6, 0, "subdivide_tukey(2)" }, - { true , false, 12, 0, false, false, false, 0, 6, 0, "subdivide_tukey(3)" } - /* here we use locale-independent 5e-1 instead of 0.5 or 0,5 */ -}; - - -/*********************************************************************** - * - * Private class method prototypes - * - ***********************************************************************/ - -static void set_defaults_(FLAC__StreamEncoder *encoder); -static void free_(FLAC__StreamEncoder *encoder); -static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, uint32_t new_blocksize); -static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, uint32_t samples, FLAC__bool is_last_block); -static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, FLAC__bool is_last_block); -static void update_metadata_(const FLAC__StreamEncoder *encoder); -#if FLAC__HAS_OGG -static void update_ogg_metadata_(FLAC__StreamEncoder *encoder); -#endif -static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_block); -static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder); - -static FLAC__bool process_subframe_( - FLAC__StreamEncoder *encoder, - uint32_t min_partition_order, - uint32_t max_partition_order, - const FLAC__FrameHeader *frame_header, - uint32_t subframe_bps, - const void *integer_signal, - FLAC__Subframe *subframe[2], - FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2], - FLAC__int32 *residual[2], - uint32_t *best_subframe, - uint32_t *best_bits -); - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -static FLAC__bool apply_apodization_( - FLAC__StreamEncoder *encoder, - apply_apodization_state_struct *apply_apodization_state, - uint32_t blocksize, - double *lpc_error, - uint32_t *max_lpc_order_this_apodization, - uint32_t subframe_bps, - const void *integer_signal, - uint32_t *guess_lpc_order -); -#endif - -static FLAC__bool add_subframe_( - FLAC__StreamEncoder *encoder, - uint32_t blocksize, - uint32_t subframe_bps, - const FLAC__Subframe *subframe, - FLAC__BitWriter *frame -); - -static uint32_t evaluate_constant_subframe_( - FLAC__StreamEncoder *encoder, - const FLAC__int64 signal, - uint32_t blocksize, - uint32_t subframe_bps, - FLAC__Subframe *subframe -); - -static uint32_t evaluate_fixed_subframe_( - FLAC__StreamEncoder *encoder, - const void *signal, - FLAC__int32 residual[], - FLAC__uint64 abs_residual_partition_sums[], - uint32_t raw_bits_per_partition[], - uint32_t blocksize, - uint32_t subframe_bps, - uint32_t order, - uint32_t rice_parameter_limit, - uint32_t min_partition_order, - uint32_t max_partition_order, - FLAC__bool do_escape_coding, - uint32_t rice_parameter_search_dist, - FLAC__Subframe *subframe, - FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents -); - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -static uint32_t evaluate_lpc_subframe_( - FLAC__StreamEncoder *encoder, - const void *signal, - FLAC__int32 residual[], - FLAC__uint64 abs_residual_partition_sums[], - uint32_t raw_bits_per_partition[], - const FLAC__real lp_coeff[], - uint32_t blocksize, - uint32_t subframe_bps, - uint32_t order, - uint32_t qlp_coeff_precision, - uint32_t rice_parameter_limit, - uint32_t min_partition_order, - uint32_t max_partition_order, - FLAC__bool do_escape_coding, - uint32_t rice_parameter_search_dist, - FLAC__Subframe *subframe, - FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents -); -#endif - -static uint32_t evaluate_verbatim_subframe_( - FLAC__StreamEncoder *encoder, - const void *signal, - uint32_t blocksize, - uint32_t subframe_bps, - FLAC__Subframe *subframe -); - -static uint32_t find_best_partition_order_( - struct FLAC__StreamEncoderPrivate *private_, - const FLAC__int32 residual[], - FLAC__uint64 abs_residual_partition_sums[], - uint32_t raw_bits_per_partition[], - uint32_t residual_samples, - uint32_t predictor_order, - uint32_t rice_parameter_limit, - uint32_t min_partition_order, - uint32_t max_partition_order, - uint32_t bps, - FLAC__bool do_escape_coding, - uint32_t rice_parameter_search_dist, - FLAC__EntropyCodingMethod *best_ecm -); - -static void precompute_partition_info_sums_( - const FLAC__int32 residual[], - FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, - uint32_t predictor_order, - uint32_t min_partition_order, - uint32_t max_partition_order, - uint32_t bps -); - -static void precompute_partition_info_escapes_( - const FLAC__int32 residual[], - uint32_t raw_bits_per_partition[], - uint32_t residual_samples, - uint32_t predictor_order, - uint32_t min_partition_order, - uint32_t max_partition_order -); - -static FLAC__bool set_partitioned_rice_( -#ifdef EXACT_RICE_BITS_CALCULATION - const FLAC__int32 residual[], -#endif - const FLAC__uint64 abs_residual_partition_sums[], - const uint32_t raw_bits_per_partition[], - const uint32_t residual_samples, - const uint32_t predictor_order, - const uint32_t rice_parameter_limit, - const uint32_t rice_parameter_search_dist, - const uint32_t partition_order, - const FLAC__bool search_for_escapes, - FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, - uint32_t *bits -); - -static uint32_t get_wasted_bits_(FLAC__int32 signal[], uint32_t samples); -static uint32_t get_wasted_bits_wide_(FLAC__int64 signal_wide[], FLAC__int32 signal[], uint32_t samples); - -/* verify-related routines: */ -static void append_to_verify_fifo_( - verify_input_fifo *fifo, - const FLAC__int32 * const input[], - uint32_t input_offset, - uint32_t channels, - uint32_t wide_samples -); - -static void append_to_verify_fifo_interleaved_( - verify_input_fifo *fifo, - const FLAC__int32 input[], - uint32_t input_offset, - uint32_t channels, - uint32_t wide_samples -); - -static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); -static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); -static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); -static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); - -static FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data); -static FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); -static FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data); -static FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data); -static FILE *get_binary_stdout_(void); - - -/*********************************************************************** - * - * Private class data - * - ***********************************************************************/ - -typedef struct FLAC__StreamEncoderPrivate { - uint32_t input_capacity; /* current size (in samples) of the signal and residual buffers */ - FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */ - FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */ - FLAC__int64 *integer_signal_33bit_side; /* 33-bit side for 32-bit stereo decorrelation */ -#ifndef FLAC__INTEGER_ONLY_LIBRARY - FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */ - FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */ - FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */ - FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */ -#endif - uint32_t subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */ - uint32_t subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */ - FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */ - FLAC__int32 *residual_workspace_mid_side[2][2]; - FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2]; - FLAC__Subframe subframe_workspace_mid_side[2][2]; - FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2]; - FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2]; - FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2]; - FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2]; - FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2]; - FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2]; - uint32_t best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */ - uint32_t best_subframe_mid_side[2]; - uint32_t best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */ - uint32_t best_subframe_bits_mid_side[2]; - FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */ - uint32_t *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */ - FLAC__BitWriter *frame; /* the current frame being worked on */ - uint32_t loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */ - uint32_t loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */ - FLAC__ChannelAssignment last_channel_assignment; - FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */ - FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */ - uint32_t current_sample_number; - uint32_t current_frame_number; - FLAC__MD5Context md5context; - FLAC__CPUInfo cpuinfo; - void (*local_precompute_partition_info_sums)(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps); -#ifndef FLAC__INTEGER_ONLY_LIBRARY - uint32_t (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); - uint32_t (*local_fixed_compute_best_predictor_wide)(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); - uint32_t (*local_fixed_compute_best_predictor_limit_residual)(const FLAC__int32 data[], uint32_t data_len, float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -#else - uint32_t (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); - uint32_t (*local_fixed_compute_best_predictor_wide)(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); - uint32_t (*local_fixed_compute_best_predictor_limit_residual)(const FLAC__int32 data[], uint32_t data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]); -#endif -#ifndef FLAC__INTEGER_ONLY_LIBRARY - void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], uint32_t data_len, uint32_t lag, double autoc[]); - void (*local_lpc_compute_residual_from_qlp_coefficients)(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); - void (*local_lpc_compute_residual_from_qlp_coefficients_64bit)(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); - void (*local_lpc_compute_residual_from_qlp_coefficients_16bit)(const FLAC__int32 *data, uint32_t data_len, const FLAC__int32 qlp_coeff[], uint32_t order, int lp_quantization, FLAC__int32 residual[]); -#endif - FLAC__bool disable_mmx; - FLAC__bool disable_sse2; - FLAC__bool disable_ssse3; - FLAC__bool disable_sse41; - FLAC__bool disable_sse42; - FLAC__bool disable_avx2; - FLAC__bool disable_fma; - FLAC__bool disable_constant_subframes; - FLAC__bool disable_fixed_subframes; - FLAC__bool disable_verbatim_subframes; - FLAC__bool is_ogg; - FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */ - FLAC__StreamEncoderSeekCallback seek_callback; - FLAC__StreamEncoderTellCallback tell_callback; - FLAC__StreamEncoderWriteCallback write_callback; - FLAC__StreamEncoderMetadataCallback metadata_callback; - FLAC__StreamEncoderProgressCallback progress_callback; - void *client_data; - uint32_t first_seekpoint_to_check; - FILE *file; /* only used when encoding to a file */ - FLAC__uint64 bytes_written; - FLAC__uint64 samples_written; - uint32_t frames_written; - uint32_t total_frames_estimate; - /* unaligned (original) pointers to allocated data */ - FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS]; - FLAC__int32 *integer_signal_mid_side_unaligned[2]; - FLAC__int64 *integer_signal_33bit_side_unaligned; -#ifndef FLAC__INTEGER_ONLY_LIBRARY - FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */ - FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */ - FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS]; - FLAC__real *windowed_signal_unaligned; -#endif - FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2]; - FLAC__int32 *residual_workspace_mid_side_unaligned[2][2]; - FLAC__uint64 *abs_residual_partition_sums_unaligned; - uint32_t *raw_bits_per_partition_unaligned; - /* - * These fields have been moved here from private function local - * declarations merely to save stack space during encoding. - */ -#ifndef FLAC__INTEGER_ONLY_LIBRARY - FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */ -#endif - FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */ - /* - * The data for the verify section - */ - struct { - FLAC__StreamDecoder *decoder; - EncoderStateHint state_hint; - FLAC__bool needs_magic_hack; - verify_input_fifo input_fifo; - verify_output output; - struct { - FLAC__uint64 absolute_sample; - uint32_t frame_number; - uint32_t channel; - uint32_t sample; - FLAC__int32 expected; - FLAC__int32 got; - } error_stats; - } verify; - FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */ -} FLAC__StreamEncoderPrivate; - -/*********************************************************************** - * - * Public static class data - * - ***********************************************************************/ - -FLAC_API const char * const FLAC__StreamEncoderStateString[] = { - "FLAC__STREAM_ENCODER_OK", - "FLAC__STREAM_ENCODER_UNINITIALIZED", - "FLAC__STREAM_ENCODER_OGG_ERROR", - "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR", - "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA", - "FLAC__STREAM_ENCODER_CLIENT_ERROR", - "FLAC__STREAM_ENCODER_IO_ERROR", - "FLAC__STREAM_ENCODER_FRAMING_ERROR", - "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR" -}; - -FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = { - "FLAC__STREAM_ENCODER_INIT_STATUS_OK", - "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR", - "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER", - "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS", - "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS", - "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE", - "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE", - "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE", - "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER", - "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION", - "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER", - "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE", - "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA", - "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED" -}; - -FLAC_API const char * const FLAC__StreamEncoderReadStatusString[] = { - "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE", - "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM", - "FLAC__STREAM_ENCODER_READ_STATUS_ABORT", - "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED" -}; - -FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = { - "FLAC__STREAM_ENCODER_WRITE_STATUS_OK", - "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR" -}; - -FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = { - "FLAC__STREAM_ENCODER_SEEK_STATUS_OK", - "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR", - "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED" -}; - -FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = { - "FLAC__STREAM_ENCODER_TELL_STATUS_OK", - "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR", - "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED" -}; - -/* Number of samples that will be overread to watch for end of stream. By - * 'overread', we mean that the FLAC__stream_encoder_process*() calls will - * always try to read blocksize+1 samples before encoding a block, so that - * even if the stream has a total sample count that is an integral multiple - * of the blocksize, we will still notice when we are encoding the last - * block. This is needed, for example, to correctly set the end-of-stream - * marker in Ogg FLAC. - * - * WATCHOUT: some parts of the code assert that OVERREAD_ == 1 and there's - * not really any reason to change it. - */ -static const uint32_t OVERREAD_ = 1; - -/*********************************************************************** - * - * Class constructor/destructor - * - */ -FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void) -{ - FLAC__StreamEncoder *encoder; - uint32_t i; - - FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */ - - encoder = calloc(1, sizeof(FLAC__StreamEncoder)); - if(encoder == 0) { - return 0; - } - - encoder->protected_ = calloc(1, sizeof(FLAC__StreamEncoderProtected)); - if(encoder->protected_ == 0) { - free(encoder); - return 0; - } - - encoder->private_ = calloc(1, sizeof(FLAC__StreamEncoderPrivate)); - if(encoder->private_ == 0) { - free(encoder->protected_); - free(encoder); - return 0; - } - - encoder->private_->frame = FLAC__bitwriter_new(); - if(encoder->private_->frame == 0) { - free(encoder->private_); - free(encoder->protected_); - free(encoder); - return 0; - } - - encoder->private_->file = 0; - - encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED; - - set_defaults_(encoder); - - encoder->private_->is_being_deleted = false; - - for(i = 0; i < FLAC__MAX_CHANNELS; i++) { - encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0]; - encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1]; - } - for(i = 0; i < 2; i++) { - encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0]; - encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1]; - } - for(i = 0; i < FLAC__MAX_CHANNELS; i++) { - encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0]; - encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1]; - } - for(i = 0; i < 2; i++) { - encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]; - encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]; - } - - for(i = 0; i < FLAC__MAX_CHANNELS; i++) { - FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]); - FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]); - } - for(i = 0; i < 2; i++) { - FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]); - FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]); - } - for(i = 0; i < 2; i++) - FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]); - - return encoder; -} - -FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder) -{ - uint32_t i; - - if (encoder == NULL) - return ; - - FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->private_->frame); - - encoder->private_->is_being_deleted = true; - - (void)FLAC__stream_encoder_finish(encoder); - - if(0 != encoder->private_->verify.decoder) - FLAC__stream_decoder_delete(encoder->private_->verify.decoder); - - for(i = 0; i < FLAC__MAX_CHANNELS; i++) { - FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]); - FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]); - } - for(i = 0; i < 2; i++) { - FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]); - FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]); - } - for(i = 0; i < 2; i++) - FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]); - - FLAC__bitwriter_delete(encoder->private_->frame); - free(encoder->private_); - free(encoder->protected_); - free(encoder); -} - -/*********************************************************************** - * - * Public class methods - * - ***********************************************************************/ - -static FLAC__StreamEncoderInitStatus init_stream_internal_( - FLAC__StreamEncoder *encoder, - FLAC__StreamEncoderReadCallback read_callback, - FLAC__StreamEncoderWriteCallback write_callback, - FLAC__StreamEncoderSeekCallback seek_callback, - FLAC__StreamEncoderTellCallback tell_callback, - FLAC__StreamEncoderMetadataCallback metadata_callback, - void *client_data, - FLAC__bool is_ogg -) -{ - uint32_t i; - FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2; - - FLAC__ASSERT(0 != encoder); - - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED; - - if(FLAC__HAS_OGG == 0 && is_ogg) - return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER; - - if(0 == write_callback || (seek_callback && 0 == tell_callback)) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS; - - if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS; - - if(encoder->protected_->channels != 2) { - encoder->protected_->do_mid_side_stereo = false; - encoder->protected_->loose_mid_side_stereo = false; - } - else if(!encoder->protected_->do_mid_side_stereo) - encoder->protected_->loose_mid_side_stereo = false; - - if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__MAX_BITS_PER_SAMPLE) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE; - - if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate)) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE; - - if(encoder->protected_->blocksize == 0) { - if(encoder->protected_->max_lpc_order == 0) - encoder->protected_->blocksize = 1152; - else - encoder->protected_->blocksize = 4096; - } - - if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE; - - if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER; - - if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order) - return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER; - - if(encoder->protected_->qlp_coeff_precision == 0) { - if(encoder->protected_->bits_per_sample < 16) { - /* @@@ need some data about how to set this here w.r.t. blocksize and sample rate */ - /* @@@ until then we'll make a guess */ - encoder->protected_->qlp_coeff_precision = flac_max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2); - } - else if(encoder->protected_->bits_per_sample == 16) { - if(encoder->protected_->blocksize <= 192) - encoder->protected_->qlp_coeff_precision = 7; - else if(encoder->protected_->blocksize <= 384) - encoder->protected_->qlp_coeff_precision = 8; - else if(encoder->protected_->blocksize <= 576) - encoder->protected_->qlp_coeff_precision = 9; - else if(encoder->protected_->blocksize <= 1152) - encoder->protected_->qlp_coeff_precision = 10; - else if(encoder->protected_->blocksize <= 2304) - encoder->protected_->qlp_coeff_precision = 11; - else if(encoder->protected_->blocksize <= 4608) - encoder->protected_->qlp_coeff_precision = 12; - else - encoder->protected_->qlp_coeff_precision = 13; - } - else { - if(encoder->protected_->blocksize <= 384) - encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2; - else if(encoder->protected_->blocksize <= 1152) - encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1; - else - encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION; - } - FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION); - } - else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION; - - if(encoder->protected_->streamable_subset) { - if(!FLAC__format_blocksize_is_subset(encoder->protected_->blocksize, encoder->protected_->sample_rate)) - return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE; - if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate)) - return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE; - if( - encoder->protected_->bits_per_sample != 8 && - encoder->protected_->bits_per_sample != 12 && - encoder->protected_->bits_per_sample != 16 && - encoder->protected_->bits_per_sample != 20 && - encoder->protected_->bits_per_sample != 24 && - encoder->protected_->bits_per_sample != 32 - ) - return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE; - if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER) - return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE; - if( - encoder->protected_->sample_rate <= 48000 && - ( - encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ || - encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ - ) - ) { - return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE; - } - } - - if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN)) - encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1; - if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order) - encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order; - -#if FLAC__HAS_OGG - /* drop any seektable for ogg */ - if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) { - uint32_t i1; - for(i1 = 0; i1 < encoder->protected_->num_metadata_blocks; i1++) { - if(0 != encoder->protected_->metadata[i1] && encoder->protected_->metadata[i1]->type == FLAC__METADATA_TYPE_SEEKTABLE) { - encoder->protected_->num_metadata_blocks--; - for( ; i1 < encoder->protected_->num_metadata_blocks; i1++) - encoder->protected_->metadata[i1] = encoder->protected_->metadata[i1+1]; - break; - } - } - } - /* reorder metadata if necessary to ensure that any VORBIS_COMMENT is the first, according to the mapping spec */ - if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) { - uint32_t i1; - for(i1 = 1; i1 < encoder->protected_->num_metadata_blocks; i1++) { - if(0 != encoder->protected_->metadata[i1] && encoder->protected_->metadata[i1]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { - FLAC__StreamMetadata *vc = encoder->protected_->metadata[i1]; - for( ; i1 > 0; i1--) - encoder->protected_->metadata[i1] = encoder->protected_->metadata[i1-1]; - encoder->protected_->metadata[0] = vc; - break; - } - } - } -#endif - /* keep track of any SEEKTABLE block */ - if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) { - uint32_t i2; - for(i2 = 0; i2 < encoder->protected_->num_metadata_blocks; i2++) { - if(0 != encoder->protected_->metadata[i2] && encoder->protected_->metadata[i2]->type == FLAC__METADATA_TYPE_SEEKTABLE) { - encoder->private_->seek_table = &encoder->protected_->metadata[i2]->data.seek_table; - break; /* take only the first one */ - } - } - } - - /* validate metadata */ - if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - metadata_has_seektable = false; - metadata_has_vorbis_comment = false; - metadata_picture_has_type1 = false; - metadata_picture_has_type2 = false; - for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) { - const FLAC__StreamMetadata *m = encoder->protected_->metadata[i]; - if(m->type == FLAC__METADATA_TYPE_STREAMINFO) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) { - if(metadata_has_seektable) /* only one is allowed */ - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - metadata_has_seektable = true; - if(!FLAC__format_seektable_is_legal(&m->data.seek_table)) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - } - else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { - if(metadata_has_vorbis_comment) /* only one is allowed */ - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - metadata_has_vorbis_comment = true; - } - else if(m->type == FLAC__METADATA_TYPE_CUESHEET) { - if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0)) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - } - else if(m->type == FLAC__METADATA_TYPE_PICTURE) { - if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0)) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) { - if(metadata_picture_has_type1) /* there should only be 1 per stream */ - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - metadata_picture_has_type1 = true; - /* standard icon must be 32x32 pixel PNG */ - if( - m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD && - ( - (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) || - m->data.picture.width != 32 || - m->data.picture.height != 32 - ) - ) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - } - else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) { - if(metadata_picture_has_type2) /* there should only be 1 per stream */ - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - metadata_picture_has_type2 = true; - } - } - } - - encoder->private_->input_capacity = 0; - for(i = 0; i < encoder->protected_->channels; i++) { - encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0; -#ifndef FLAC__INTEGER_ONLY_LIBRARY - encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0; -#endif - } - for(i = 0; i < 2; i++) { - encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0; -#ifndef FLAC__INTEGER_ONLY_LIBRARY - encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0; -#endif - } - encoder->private_->integer_signal_33bit_side_unaligned = encoder->private_->integer_signal_33bit_side = 0; -#ifndef FLAC__INTEGER_ONLY_LIBRARY - for(i = 0; i < encoder->protected_->num_apodizations; i++) - encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0; - encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0; -#endif - for(i = 0; i < encoder->protected_->channels; i++) { - encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0; - encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0; - encoder->private_->best_subframe[i] = 0; - } - for(i = 0; i < 2; i++) { - encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0; - encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0; - encoder->private_->best_subframe_mid_side[i] = 0; - } - encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0; - encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0; -#ifndef FLAC__INTEGER_ONLY_LIBRARY - encoder->private_->loose_mid_side_stereo_frames = (uint32_t)((double)encoder->protected_->sample_rate * 0.4 / (double)encoder->protected_->blocksize + 0.5); -#else - /* 26214 is the approximate fixed-point equivalent to 0.4 (0.4 * 2^16) */ - /* sample rate can be up to 1048575 Hz, and thus use 20 bits, so we do the multiply÷ by hand */ - FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 1048575); - FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535); - FLAC__ASSERT(encoder->protected_->sample_rate <= 1048575); - FLAC__ASSERT(encoder->protected_->blocksize <= 65535); - encoder->private_->loose_mid_side_stereo_frames = (uint32_t)FLAC__fixedpoint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(26214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF); -#endif - if(encoder->private_->loose_mid_side_stereo_frames == 0) - encoder->private_->loose_mid_side_stereo_frames = 1; - encoder->private_->loose_mid_side_stereo_frame_count = 0; - encoder->private_->current_sample_number = 0; - encoder->private_->current_frame_number = 0; - - /* - * get the CPU info and set the function pointers - */ - FLAC__cpu_info(&encoder->private_->cpuinfo); - /* remove cpu info as requested by - * FLAC__stream_encoder_disable_instruction_set */ - if(encoder->private_->disable_mmx) - encoder->private_->cpuinfo.x86.mmx = false; - if(encoder->private_->disable_sse2) - encoder->private_->cpuinfo.x86.sse2 = false; - if(encoder->private_->disable_ssse3) - encoder->private_->cpuinfo.x86.ssse3 = false; - if(encoder->private_->disable_sse41) - encoder->private_->cpuinfo.x86.sse41 = false; - if(encoder->private_->disable_sse42) - encoder->private_->cpuinfo.x86.sse42 = false; - if(encoder->private_->disable_avx2) - encoder->private_->cpuinfo.x86.avx2 = false; - if(encoder->private_->disable_fma) - encoder->private_->cpuinfo.x86.fma = false; - /* first default to the non-asm routines */ -#ifndef FLAC__INTEGER_ONLY_LIBRARY - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation; -#endif - encoder->private_->local_precompute_partition_info_sums = precompute_partition_info_sums_; - encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor; - encoder->private_->local_fixed_compute_best_predictor_wide = FLAC__fixed_compute_best_predictor_wide; - encoder->private_->local_fixed_compute_best_predictor_limit_residual = FLAC__fixed_compute_best_predictor_limit_residual; -#ifndef FLAC__INTEGER_ONLY_LIBRARY - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients; - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide; - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients; -#endif - /* now override with asm where appropriate */ -#ifndef FLAC__INTEGER_ONLY_LIBRARY -# ifndef FLAC__NO_ASM -#if defined FLAC__CPU_ARM64 && FLAC__HAS_NEONINTRIN -#if FLAC__HAS_A64NEONINTRIN - if(encoder->protected_->max_lpc_order < 8) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_neon_lag_8; - else if(encoder->protected_->max_lpc_order < 10) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_neon_lag_10; - else if(encoder->protected_->max_lpc_order < 14) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_neon_lag_14; - else - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation; -#endif - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_neon; - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_neon; - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_neon; -#endif /* defined FLAC__CPU_ARM64 && FLAC__HAS_NEONINTRIN */ - - if(encoder->private_->cpuinfo.use_asm) { -# ifdef FLAC__CPU_IA32 - FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32); -# if FLAC__HAS_X86INTRIN -# ifdef FLAC__SSE2_SUPPORTED - if (encoder->private_->cpuinfo.x86.sse2) { - if(encoder->protected_->max_lpc_order < 8) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_8; - else if(encoder->protected_->max_lpc_order < 10) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_10; - else if(encoder->protected_->max_lpc_order < 14) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_14; - - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse2; - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_sse2; - } -# endif -# ifdef FLAC__SSE4_1_SUPPORTED - if (encoder->private_->cpuinfo.x86.sse41) { - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41; - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_sse41; - } -# endif -# ifdef FLAC__AVX2_SUPPORTED - if (encoder->private_->cpuinfo.x86.avx2) { - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2; - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2; - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2; - } -# endif - -# ifdef FLAC__SSE2_SUPPORTED - if (encoder->private_->cpuinfo.x86.sse2) { - encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_intrin_sse2; - } -# endif -# ifdef FLAC__SSSE3_SUPPORTED - if (encoder->private_->cpuinfo.x86.ssse3) { - encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_intrin_ssse3; - } -# endif -# ifdef FLAC__SSE4_2_SUPPORTED - if (encoder->private_->cpuinfo.x86.sse42) { - encoder->private_->local_fixed_compute_best_predictor_limit_residual = FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42; - } -# endif -# ifdef FLAC__AVX2_SUPPORTED - if (encoder->private_->cpuinfo.x86.avx2) { - encoder->private_->local_fixed_compute_best_predictor_wide = FLAC__fixed_compute_best_predictor_wide_intrin_avx2; - encoder->private_->local_fixed_compute_best_predictor_limit_residual = FLAC__fixed_compute_best_predictor_limit_residual_intrin_avx2; - } -# endif -# endif /* FLAC__HAS_X86INTRIN */ -# elif defined FLAC__CPU_X86_64 - FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_X86_64); -# if FLAC__HAS_X86INTRIN -# ifdef FLAC__SSE2_SUPPORTED - if(encoder->private_->cpuinfo.x86.sse2) { /* For fuzzing */ - if(encoder->protected_->max_lpc_order < 8) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_8; - else if(encoder->protected_->max_lpc_order < 10) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_10; - else if(encoder->protected_->max_lpc_order < 14) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_sse2_lag_14; - - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_sse2; - } -# endif -# ifdef FLAC__SSE4_1_SUPPORTED - if(encoder->private_->cpuinfo.x86.sse41) { - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_sse41; - } -# endif -# ifdef FLAC__AVX2_SUPPORTED - if(encoder->private_->cpuinfo.x86.avx2) { - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_16_intrin_avx2; - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_avx2; - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_avx2; - } -# endif -# ifdef FLAC__FMA_SUPPORTED - if(encoder->private_->cpuinfo.x86.fma) { - if(encoder->protected_->max_lpc_order < 8) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_fma_lag_8; - else if(encoder->protected_->max_lpc_order < 12) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_fma_lag_12; - else if(encoder->protected_->max_lpc_order < 16) - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_intrin_fma_lag_16; - } -# endif - - -# ifdef FLAC__SSE2_SUPPORTED - if(encoder->private_->cpuinfo.x86.sse2) { /* For fuzzing */ - encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_intrin_sse2; - } -# endif -# ifdef FLAC__SSSE3_SUPPORTED - if (encoder->private_->cpuinfo.x86.ssse3) { - encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_intrin_ssse3; - } -# endif -# ifdef FLAC__SSE4_2_SUPPORTED - if (encoder->private_->cpuinfo.x86.sse42) { - encoder->private_->local_fixed_compute_best_predictor_limit_residual = FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42; - } -# endif -# ifdef FLAC__AVX2_SUPPORTED - if (encoder->private_->cpuinfo.x86.avx2) { - encoder->private_->local_fixed_compute_best_predictor_wide = FLAC__fixed_compute_best_predictor_wide_intrin_avx2; - encoder->private_->local_fixed_compute_best_predictor_limit_residual = FLAC__fixed_compute_best_predictor_limit_residual_intrin_avx2; - } -# endif -# endif /* FLAC__HAS_X86INTRIN */ -# endif /* FLAC__CPU_... */ - } -# endif /* !FLAC__NO_ASM */ - -#endif /* !FLAC__INTEGER_ONLY_LIBRARY */ -#if !defined FLAC__NO_ASM && FLAC__HAS_X86INTRIN - if(encoder->private_->cpuinfo.use_asm) { -# if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) -# ifdef FLAC__SSE2_SUPPORTED - if (encoder->private_->cpuinfo.x86.sse2) - encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_sse2; -# endif -# ifdef FLAC__SSSE3_SUPPORTED - if (encoder->private_->cpuinfo.x86.ssse3) - encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_ssse3; -# endif -# ifdef FLAC__AVX2_SUPPORTED - if (encoder->private_->cpuinfo.x86.avx2) - encoder->private_->local_precompute_partition_info_sums = FLAC__precompute_partition_info_sums_intrin_avx2; -# endif -# endif /* FLAC__CPU_... */ - } -#endif /* !FLAC__NO_ASM && FLAC__HAS_X86INTRIN */ - - /* set state to OK; from here on, errors are fatal and we'll override the state then */ - encoder->protected_->state = FLAC__STREAM_ENCODER_OK; - -#if FLAC__HAS_OGG - encoder->private_->is_ogg = is_ogg; - if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } -#endif - - encoder->private_->read_callback = read_callback; - encoder->private_->write_callback = write_callback; - encoder->private_->seek_callback = seek_callback; - encoder->private_->tell_callback = tell_callback; - encoder->private_->metadata_callback = metadata_callback; - encoder->private_->client_data = client_data; - - if(!resize_buffers_(encoder, encoder->protected_->blocksize)) { - /* the above function sets the state for us in case of an error */ - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - if(!FLAC__bitwriter_init(encoder->private_->frame)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - /* - * Set up the verify stuff if necessary - */ - if(encoder->protected_->verify) { - /* - * First, set up the fifo which will hold the - * original signal to compare against - */ - encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_; - for(i = 0; i < encoder->protected_->channels; i++) { - if(0 == (encoder->private_->verify.input_fifo.data[i] = safe_malloc_mul_2op_p(sizeof(FLAC__int32), /*times*/encoder->private_->verify.input_fifo.size))) { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - } - encoder->private_->verify.input_fifo.tail = 0; - - /* - * Now set up a stream decoder for verification - */ - if(0 == encoder->private_->verify.decoder) { - encoder->private_->verify.decoder = FLAC__stream_decoder_new(); - if(0 == encoder->private_->verify.decoder) { - encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - } - - if(FLAC__stream_decoder_init_stream(encoder->private_->verify.decoder, verify_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, verify_write_callback_, verify_metadata_callback_, verify_error_callback_, /*client_data=*/encoder) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - } - encoder->private_->verify.error_stats.absolute_sample = 0; - encoder->private_->verify.error_stats.frame_number = 0; - encoder->private_->verify.error_stats.channel = 0; - encoder->private_->verify.error_stats.sample = 0; - encoder->private_->verify.error_stats.expected = 0; - encoder->private_->verify.error_stats.got = 0; - - /* - * These must be done before we write any metadata, because that - * calls the write_callback, which uses these values. - */ - encoder->private_->first_seekpoint_to_check = 0; - encoder->private_->samples_written = 0; - encoder->protected_->streaminfo_offset = 0; - encoder->protected_->seektable_offset = 0; - encoder->protected_->audio_offset = 0; - - /* - * write the stream header - */ - if(encoder->protected_->verify) - encoder->private_->verify.state_hint = ENCODER_IN_MAGIC; - if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) { - /* the above function sets the state for us in case of an error */ - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - /* - * write the STREAMINFO metadata block - */ - if(encoder->protected_->verify) - encoder->private_->verify.state_hint = ENCODER_IN_METADATA; - encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO; - encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */ - encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH; - encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */ - encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize; - encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */ - encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */ - encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate; - encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels; - encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample; - encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */ - memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */ - if(encoder->protected_->do_md5) - FLAC__MD5Init(&encoder->private_->md5context); - if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame, true)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) { - /* the above function sets the state for us in case of an error */ - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - /* - * Now that the STREAMINFO block is written, we can init this to an - * absurdly-high value... - */ - encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1; - /* ... and clear this to 0 */ - encoder->private_->streaminfo.data.stream_info.total_samples = 0; - - /* - * Check to see if the supplied metadata contains a VORBIS_COMMENT; - * if not, we will write an empty one (FLAC__add_metadata_block() - * automatically supplies the vendor string). - * - * WATCHOUT: the Ogg FLAC mapping requires us to write this block after - * the STREAMINFO. (In the case that metadata_has_vorbis_comment is - * true it will have already insured that the metadata list is properly - * ordered.) - */ - if(!metadata_has_vorbis_comment) { - FLAC__StreamMetadata vorbis_comment; - vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT; - vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0); - vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */ - vorbis_comment.data.vorbis_comment.vendor_string.length = 0; - vorbis_comment.data.vorbis_comment.vendor_string.entry = 0; - vorbis_comment.data.vorbis_comment.num_comments = 0; - vorbis_comment.data.vorbis_comment.comments = 0; - if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame, true)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) { - /* the above function sets the state for us in case of an error */ - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - } - - /* - * write the user's metadata blocks - */ - for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) { - encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1); - if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame, true)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) { - /* the above function sets the state for us in case of an error */ - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - } - - /* now that all the metadata is written, we save the stream offset */ - if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &encoder->protected_->audio_offset, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) { /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get the offset; no error */ - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - if(encoder->protected_->verify) - encoder->private_->verify.state_hint = ENCODER_IN_AUDIO; - - return FLAC__STREAM_ENCODER_INIT_STATUS_OK; -} - -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream( - FLAC__StreamEncoder *encoder, - FLAC__StreamEncoderWriteCallback write_callback, - FLAC__StreamEncoderSeekCallback seek_callback, - FLAC__StreamEncoderTellCallback tell_callback, - FLAC__StreamEncoderMetadataCallback metadata_callback, - void *client_data -) -{ - return init_stream_internal_( - encoder, - /*read_callback=*/0, - write_callback, - seek_callback, - tell_callback, - metadata_callback, - client_data, - /*is_ogg=*/false - ); -} - -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream( - FLAC__StreamEncoder *encoder, - FLAC__StreamEncoderReadCallback read_callback, - FLAC__StreamEncoderWriteCallback write_callback, - FLAC__StreamEncoderSeekCallback seek_callback, - FLAC__StreamEncoderTellCallback tell_callback, - FLAC__StreamEncoderMetadataCallback metadata_callback, - void *client_data -) -{ - return init_stream_internal_( - encoder, - read_callback, - write_callback, - seek_callback, - tell_callback, - metadata_callback, - client_data, - /*is_ogg=*/true - ); -} - -static FLAC__StreamEncoderInitStatus init_FILE_internal_( - FLAC__StreamEncoder *encoder, - FILE *file, - FLAC__StreamEncoderProgressCallback progress_callback, - void *client_data, - FLAC__bool is_ogg -) -{ - FLAC__StreamEncoderInitStatus init_status; - - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != file); - - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED; - - /* double protection */ - if(file == 0) { - encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - /* - * To make sure that our file does not go unclosed after an error, we - * must assign the FILE pointer before any further error can occur in - * this routine. - */ - if(file == stdout) - file = get_binary_stdout_(); /* just to be safe */ - -#ifdef _WIN32 - /* - * Windows can suffer quite badly from disk fragmentation. This can be - * reduced significantly by setting the output buffer size to be 10MB. - */ - if(GetFileType((HANDLE)_get_osfhandle(_fileno(file))) == FILE_TYPE_DISK) - setvbuf(file, NULL, _IOFBF, 10*1024*1024); -#endif - encoder->private_->file = file; - - encoder->private_->progress_callback = progress_callback; - encoder->private_->bytes_written = 0; - encoder->private_->samples_written = 0; - encoder->private_->frames_written = 0; - - init_status = init_stream_internal_( - encoder, - encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_ : 0, - file_write_callback_, - encoder->private_->file == stdout? 0 : file_seek_callback_, - encoder->private_->file == stdout? 0 : file_tell_callback_, - /*metadata_callback=*/0, - client_data, - is_ogg - ); - if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { - /* the above function sets the state for us in case of an error */ - return init_status; - } - - { - uint32_t blocksize = FLAC__stream_encoder_get_blocksize(encoder); - - FLAC__ASSERT(blocksize != 0); - encoder->private_->total_frames_estimate = (uint32_t)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize); - } - - return init_status; -} - -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE( - FLAC__StreamEncoder *encoder, - FILE *file, - FLAC__StreamEncoderProgressCallback progress_callback, - void *client_data -) -{ - return init_FILE_internal_(encoder, file, progress_callback, client_data, /*is_ogg=*/false); -} - -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE( - FLAC__StreamEncoder *encoder, - FILE *file, - FLAC__StreamEncoderProgressCallback progress_callback, - void *client_data -) -{ - return init_FILE_internal_(encoder, file, progress_callback, client_data, /*is_ogg=*/true); -} - -static FLAC__StreamEncoderInitStatus init_file_internal_( - FLAC__StreamEncoder *encoder, - const char *filename, - FLAC__StreamEncoderProgressCallback progress_callback, - void *client_data, - FLAC__bool is_ogg -) -{ - FILE *file; - - FLAC__ASSERT(0 != encoder); - - /* - * To make sure that our file does not go unclosed after an error, we - * have to do the same entrance checks here that are later performed - * in FLAC__stream_encoder_init_FILE() before the FILE* is assigned. - */ - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED; - - file = filename? flac_fopen(filename, "w+b") : stdout; - - if(file == 0) { - encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - return init_FILE_internal_(encoder, file, progress_callback, client_data, is_ogg); -} - -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file( - FLAC__StreamEncoder *encoder, - const char *filename, - FLAC__StreamEncoderProgressCallback progress_callback, - void *client_data -) -{ - return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/false); -} - -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file( - FLAC__StreamEncoder *encoder, - const char *filename, - FLAC__StreamEncoderProgressCallback progress_callback, - void *client_data -) -{ - return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/true); -} - -FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder) -{ - FLAC__bool error = false; - - if (encoder == NULL) - return false; - - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - - if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED){ - if(encoder->protected_->metadata){ // True in case FLAC__stream_encoder_set_metadata was used but init failed - free(encoder->protected_->metadata); - encoder->protected_->metadata = 0; - encoder->protected_->num_metadata_blocks = 0; - } - if(0 != encoder->private_->file) { - if(encoder->private_->file != stdout) - fclose(encoder->private_->file); - encoder->private_->file = 0; - } - return true; - } - - if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) { - if(encoder->private_->current_sample_number != 0) { - encoder->protected_->blocksize = encoder->private_->current_sample_number; - if(!resize_buffers_(encoder, encoder->protected_->blocksize)) { - /* the above function sets the state for us in case of an error */ - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - if(!process_frame_(encoder, /*is_last_block=*/true)) - error = true; - } - } - - if(encoder->protected_->do_md5) - FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context); - - if(!encoder->private_->is_being_deleted) { - if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) { - if(encoder->private_->seek_callback) { -#if FLAC__HAS_OGG - if(encoder->private_->is_ogg) - update_ogg_metadata_(encoder); - else -#endif - update_metadata_(encoder); - - /* check if an error occurred while updating metadata */ - if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK) - error = true; - } - if(encoder->private_->metadata_callback) - encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data); - } - - if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) { - if(!error) - encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA; - error = true; - } - } - - if(0 != encoder->private_->file) { - if(encoder->private_->file != stdout) - fclose(encoder->private_->file); - encoder->private_->file = 0; - } - -#if FLAC__HAS_OGG - if(encoder->private_->is_ogg) - FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect); -#endif - - free_(encoder); - set_defaults_(encoder); - - if(!error) - encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED; - - return !error; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; -#if FLAC__HAS_OGG - /* can't check encoder->private_->is_ogg since that's not set until init time */ - FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value); - return true; -#else - (void)value; - return false; -#endif -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; -#ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING - encoder->protected_->verify = value; -#endif - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->streamable_subset = value; - return true; -} - -/* - * The following routine was intended as debug routine and is not in the - * public headers, but SHOULD NOT CHANGE! It is known is is used in - * some non-audio projects needing every last bit of performance. - * See https://github.com/xiph/flac/issues/547 for details. These projects - * provide their own prototype, so changing the signature of this function - * would break building. - */ -FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->do_md5 = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, uint32_t value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->channels = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, uint32_t value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->bits_per_sample = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, uint32_t value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->sample_rate = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, uint32_t value) -{ - FLAC__bool ok = true; - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0])) - value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1; - ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo); - ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo); -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#if 1 - ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization); -#else - /* equivalent to -A tukey(0.5) */ - encoder->protected_->num_apodizations = 1; - encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY; - encoder->protected_->apodizations[0].parameters.tukey.p = 0.5; -#endif -#endif - ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order); - ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision); - ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search); - ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding); - ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search); - ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order); - ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order); - ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist); - return ok; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, uint32_t value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->blocksize = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->do_mid_side_stereo = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->loose_mid_side_stereo = value; - return true; -} - -/*@@@@add to tests*/ -FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != specification); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; -#ifdef FLAC__INTEGER_ONLY_LIBRARY - (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */ -#else - encoder->protected_->num_apodizations = 0; - while(1) { - const char *s = strchr(specification, ';'); - const size_t n = s? (size_t)(s - specification) : strlen(specification); - if (n==8 && 0 == strncmp("bartlett" , specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT; - else if(n==13 && 0 == strncmp("bartlett_hann", specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN; - else if(n==8 && 0 == strncmp("blackman" , specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN; - else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE; - else if(n==6 && 0 == strncmp("connes" , specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES; - else if(n==7 && 0 == strncmp("flattop" , specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP; - else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) { - FLAC__real stddev = (FLAC__real)strtod(specification+6, 0); - if (stddev > 0.0 && stddev <= 0.5) { - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev; - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS; - } - } - else if(n==7 && 0 == strncmp("hamming" , specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING; - else if(n==4 && 0 == strncmp("hann" , specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN; - else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL; - else if(n==7 && 0 == strncmp("nuttall" , specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL; - else if(n==9 && 0 == strncmp("rectangle" , specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE; - else if(n==8 && 0 == strncmp("triangle" , specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE; - else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) { - FLAC__real p = (FLAC__real)strtod(specification+6, 0); - if (p >= 0.0 && p <= 1.0) { - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p; - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY; - } - } - else if(n>15 && 0 == strncmp("partial_tukey(", specification, 14)) { - FLAC__int32 tukey_parts = (FLAC__int32)strtod(specification+14, 0); - const char *si_1 = strchr(specification, '/'); - FLAC__real overlap = si_1?flac_min((FLAC__real)strtod(si_1+1, 0),0.99f):0.1f; - FLAC__real overlap_units = 1.0f/(1.0f - overlap) - 1.0f; - const char *si_2 = strchr((si_1?(si_1+1):specification), '/'); - FLAC__real tukey_p = si_2?(FLAC__real)strtod(si_2+1, 0):0.2f; - - if (tukey_parts <= 1) { - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = tukey_p; - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY; - }else if (encoder->protected_->num_apodizations + tukey_parts < 32){ - FLAC__int32 m; - for(m = 0; m < tukey_parts; m++){ - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.multiple_tukey.p = tukey_p; - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.multiple_tukey.start = m/(tukey_parts+overlap_units); - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.multiple_tukey.end = (m+1+overlap_units)/(tukey_parts+overlap_units); - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_PARTIAL_TUKEY; - } - } - } - else if(n>16 && 0 == strncmp("punchout_tukey(", specification, 15)) { - FLAC__int32 tukey_parts = (FLAC__int32)strtod(specification+15, 0); - const char *si_1 = strchr(specification, '/'); - FLAC__real overlap = si_1?flac_min((FLAC__real)strtod(si_1+1, 0),0.99f):0.2f; - FLAC__real overlap_units = 1.0f/(1.0f - overlap) - 1.0f; - const char *si_2 = strchr((si_1?(si_1+1):specification), '/'); - FLAC__real tukey_p = si_2?(FLAC__real)strtod(si_2+1, 0):0.2f; - - if (tukey_parts <= 1) { - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = tukey_p; - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY; - }else if (encoder->protected_->num_apodizations + tukey_parts < 32){ - FLAC__int32 m; - for(m = 0; m < tukey_parts; m++){ - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.multiple_tukey.p = tukey_p; - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.multiple_tukey.start = m/(tukey_parts+overlap_units); - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.multiple_tukey.end = (m+1+overlap_units)/(tukey_parts+overlap_units); - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_PUNCHOUT_TUKEY; - } - } - } - else if(n>17 && 0 == strncmp("subdivide_tukey(", specification, 16)){ - FLAC__int32 parts = (FLAC__int32)strtod(specification+16, 0); - if(parts > 1){ - const char *si_1 = strchr(specification, '/'); - FLAC__real p = si_1?(FLAC__real)strtod(si_1+1, 0):5e-1; - if(p > 1) - p = 1; - else if(p < 0) - p = 0; - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.subdivide_tukey.parts = parts; - encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.subdivide_tukey.p = p/parts; - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_SUBDIVIDE_TUKEY; - } - } - else if(n==5 && 0 == strncmp("welch" , specification, n)) - encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH; - if (encoder->protected_->num_apodizations == 32) - break; - if (s) - specification = s+1; - else - break; - } - if(encoder->protected_->num_apodizations == 0) { - encoder->protected_->num_apodizations = 1; - encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY; - encoder->protected_->apodizations[0].parameters.tukey.p = 0.5; - } -#endif - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, uint32_t value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->max_lpc_order = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, uint32_t value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->qlp_coeff_precision = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->do_qlp_coeff_prec_search = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* was deprecated since FLAC 1.0.4 (24-Sep-2002), but is needed for - * full spec coverage, so this should be reenabled at some point. - * For now only enable while fuzzing */ - encoder->protected_->do_escape_coding = value; -#else - (void)value; -#endif - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->do_exhaustive_model_search = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, uint32_t value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->min_residual_partition_order = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, uint32_t value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->max_residual_partition_order = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, uint32_t value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; -#if 0 - /*@@@ deprecated: */ - encoder->protected_->rice_parameter_search_dist = value; -#else - (void)value; -#endif - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - value = flac_min(value, (FLAC__U64L(1) << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN) - 1); - encoder->protected_->total_samples_estimate = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, uint32_t num_blocks) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - if(0 == metadata) - num_blocks = 0; - if(0 == num_blocks) - metadata = 0; - /* realloc() does not do exactly what we want so... */ - if(encoder->protected_->metadata) { - free(encoder->protected_->metadata); - encoder->protected_->metadata = 0; - encoder->protected_->num_metadata_blocks = 0; - } - if(num_blocks) { - FLAC__StreamMetadata **m; - if(0 == (m = safe_malloc_mul_2op_p(sizeof(m[0]), /*times*/num_blocks))) - return false; - memcpy(m, metadata, sizeof(m[0]) * num_blocks); - encoder->protected_->metadata = m; - encoder->protected_->num_metadata_blocks = num_blocks; - } -#if FLAC__HAS_OGG - if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks)) - return false; -#endif - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_set_limit_min_bitrate(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->protected_->limit_min_bitrate = value; - return true; -} - -/* - * These four functions are not static, but not publicly exposed in - * include/FLAC/ either. They are used by the test suite and in fuzzing - */ -FLAC_API FLAC__bool FLAC__stream_encoder_disable_instruction_set(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->private_->disable_mmx = value & 1; - encoder->private_->disable_sse2 = value & 2; - encoder->private_->disable_ssse3 = value & 4; - encoder->private_->disable_sse41 = value & 8; - encoder->private_->disable_avx2 = value & 16; - encoder->private_->disable_fma = value & 32; - encoder->private_->disable_sse42 = value & 64; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->private_->disable_constant_subframes = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->private_->disable_fixed_subframes = value; - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - encoder->private_->disable_verbatim_subframes = value; - return true; -} - -FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->state; -} - -FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->verify) - return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder); - else - return FLAC__STREAM_DECODER_UNINITIALIZED; -} - -FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) - return FLAC__StreamEncoderStateString[encoder->protected_->state]; - else - return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder); -} - -FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, uint32_t *frame_number, uint32_t *channel, uint32_t *sample, FLAC__int32 *expected, FLAC__int32 *got) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(0 != absolute_sample) - *absolute_sample = encoder->private_->verify.error_stats.absolute_sample; - if(0 != frame_number) - *frame_number = encoder->private_->verify.error_stats.frame_number; - if(0 != channel) - *channel = encoder->private_->verify.error_stats.channel; - if(0 != sample) - *sample = encoder->private_->verify.error_stats.sample; - if(0 != expected) - *expected = encoder->private_->verify.error_stats.expected; - if(0 != got) - *got = encoder->private_->verify.error_stats.got; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->verify; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->streamable_subset; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->do_md5; -} - -FLAC_API uint32_t FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->channels; -} - -FLAC_API uint32_t FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->bits_per_sample; -} - -FLAC_API uint32_t FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->sample_rate; -} - -FLAC_API uint32_t FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->blocksize; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->do_mid_side_stereo; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->loose_mid_side_stereo; -} - -FLAC_API uint32_t FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->max_lpc_order; -} - -FLAC_API uint32_t FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->qlp_coeff_precision; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->do_qlp_coeff_prec_search; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->do_escape_coding; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->do_exhaustive_model_search; -} - -FLAC_API uint32_t FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->min_residual_partition_order; -} - -FLAC_API uint32_t FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->max_residual_partition_order; -} - -FLAC_API uint32_t FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->rice_parameter_search_dist; -} - -FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->total_samples_estimate; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_get_limit_min_bitrate(const FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->limit_min_bitrate; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], uint32_t samples) -{ - uint32_t i, j = 0, k = 0, channel; - const uint32_t channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize; - const FLAC__int32 sample_max = INT32_MAX >> (32 - encoder->protected_->bits_per_sample); - const FLAC__int32 sample_min = INT32_MIN >> (32 - encoder->protected_->bits_per_sample); - - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - - if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK) - return false; - - do { - const uint32_t n = flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j); - - if(encoder->protected_->verify) - append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n); - - for(channel = 0; channel < channels; channel++) { - if (buffer[channel] == NULL) { - return false; - } - for(i = encoder->private_->current_sample_number, k = j; i <= blocksize && k < samples; i++, k++) { - if(buffer[channel][k] < sample_min || buffer[channel][k] > sample_max){ - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - } - memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n); - } - j += n; - encoder->private_->current_sample_number += n; - - /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */ - if(encoder->private_->current_sample_number > blocksize) { - FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_); - FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */ - if(!process_frame_(encoder, /*is_last_block=*/false)) - return false; - /* move unprocessed overread samples to beginnings of arrays */ - for(channel = 0; channel < channels; channel++) - encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize]; - encoder->private_->current_sample_number = 1; - } - } while(j < samples); - - return true; -} - -FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], uint32_t samples) -{ - uint32_t i, j, k, channel; - const uint32_t channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize; - const FLAC__int32 sample_max = INT32_MAX >> (32 - encoder->protected_->bits_per_sample); - const FLAC__int32 sample_min = INT32_MIN >> (32 - encoder->protected_->bits_per_sample); - - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - - if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK) - return false; - - j = k = 0; - do { - if(encoder->protected_->verify) - append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j)); - - /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */ - for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) { - for(channel = 0; channel < channels; channel++){ - if(buffer[k] < sample_min || buffer[k] > sample_max){ - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - encoder->private_->integer_signal[channel][i] = buffer[k++]; - } - } - encoder->private_->current_sample_number = i; - /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */ - if(i > blocksize) { - if(!process_frame_(encoder, /*is_last_block=*/false)) - return false; - /* move unprocessed overread samples to beginnings of arrays */ - FLAC__ASSERT(i == blocksize+OVERREAD_); - FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */ - for(channel = 0; channel < channels; channel++) - encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize]; - encoder->private_->current_sample_number = 1; - } - } while(j < samples); - - return true; -} - -/*********************************************************************** - * - * Private class methods - * - ***********************************************************************/ - -void set_defaults_(FLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - -#ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING - encoder->protected_->verify = true; -#else - encoder->protected_->verify = false; -#endif - encoder->protected_->streamable_subset = true; - encoder->protected_->do_md5 = true; - encoder->protected_->do_mid_side_stereo = false; - encoder->protected_->loose_mid_side_stereo = false; - encoder->protected_->channels = 2; - encoder->protected_->bits_per_sample = 16; - encoder->protected_->sample_rate = 44100; - encoder->protected_->blocksize = 0; -#ifndef FLAC__INTEGER_ONLY_LIBRARY - encoder->protected_->num_apodizations = 1; - encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY; - encoder->protected_->apodizations[0].parameters.tukey.p = 0.5; -#endif - encoder->protected_->max_lpc_order = 0; - encoder->protected_->qlp_coeff_precision = 0; - encoder->protected_->do_qlp_coeff_prec_search = false; - encoder->protected_->do_exhaustive_model_search = false; - encoder->protected_->do_escape_coding = false; - encoder->protected_->min_residual_partition_order = 0; - encoder->protected_->max_residual_partition_order = 0; - encoder->protected_->rice_parameter_search_dist = 0; - encoder->protected_->total_samples_estimate = 0; - encoder->protected_->limit_min_bitrate = false; - encoder->protected_->metadata = 0; - encoder->protected_->num_metadata_blocks = 0; - - encoder->private_->seek_table = 0; - encoder->private_->disable_mmx = false; - encoder->private_->disable_sse2 = false; - encoder->private_->disable_ssse3 = false; - encoder->private_->disable_sse41 = false; - encoder->private_->disable_sse42 = false; - encoder->private_->disable_avx2 = false; - encoder->private_->disable_constant_subframes = false; - encoder->private_->disable_fixed_subframes = false; - encoder->private_->disable_verbatim_subframes = false; - encoder->private_->is_ogg = false; - encoder->private_->read_callback = 0; - encoder->private_->write_callback = 0; - encoder->private_->seek_callback = 0; - encoder->private_->tell_callback = 0; - encoder->private_->metadata_callback = 0; - encoder->private_->progress_callback = 0; - encoder->private_->client_data = 0; - -#if FLAC__HAS_OGG - FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect); -#endif - - FLAC__stream_encoder_set_compression_level(encoder, 5); -} - -void free_(FLAC__StreamEncoder *encoder) -{ - uint32_t i, channel; - - FLAC__ASSERT(0 != encoder); - if(encoder->protected_->metadata) { - free(encoder->protected_->metadata); - encoder->protected_->metadata = 0; - encoder->protected_->num_metadata_blocks = 0; - } - for(i = 0; i < encoder->protected_->channels; i++) { - if(0 != encoder->private_->integer_signal_unaligned[i]) { - free(encoder->private_->integer_signal_unaligned[i]); - encoder->private_->integer_signal_unaligned[i] = 0; - } -#ifndef FLAC__INTEGER_ONLY_LIBRARY - if(0 != encoder->private_->real_signal_unaligned[i]) { - free(encoder->private_->real_signal_unaligned[i]); - encoder->private_->real_signal_unaligned[i] = 0; - } -#endif - } - for(i = 0; i < 2; i++) { - if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) { - free(encoder->private_->integer_signal_mid_side_unaligned[i]); - encoder->private_->integer_signal_mid_side_unaligned[i] = 0; - } -#ifndef FLAC__INTEGER_ONLY_LIBRARY - if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) { - free(encoder->private_->real_signal_mid_side_unaligned[i]); - encoder->private_->real_signal_mid_side_unaligned[i] = 0; - } -#endif - } - if(0 != encoder->private_->integer_signal_33bit_side_unaligned){ - free(encoder->private_->integer_signal_33bit_side_unaligned); - encoder->private_->integer_signal_33bit_side_unaligned = 0; - } -#ifndef FLAC__INTEGER_ONLY_LIBRARY - for(i = 0; i < encoder->protected_->num_apodizations; i++) { - if(0 != encoder->private_->window_unaligned[i]) { - free(encoder->private_->window_unaligned[i]); - encoder->private_->window_unaligned[i] = 0; - } - } - if(0 != encoder->private_->windowed_signal_unaligned) { - free(encoder->private_->windowed_signal_unaligned); - encoder->private_->windowed_signal_unaligned = 0; - } -#endif - for(channel = 0; channel < encoder->protected_->channels; channel++) { - for(i = 0; i < 2; i++) { - if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) { - free(encoder->private_->residual_workspace_unaligned[channel][i]); - encoder->private_->residual_workspace_unaligned[channel][i] = 0; - } - } - } - for(channel = 0; channel < 2; channel++) { - for(i = 0; i < 2; i++) { - if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) { - free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]); - encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0; - } - } - } - if(0 != encoder->private_->abs_residual_partition_sums_unaligned) { - free(encoder->private_->abs_residual_partition_sums_unaligned); - encoder->private_->abs_residual_partition_sums_unaligned = 0; - } - if(0 != encoder->private_->raw_bits_per_partition_unaligned) { - free(encoder->private_->raw_bits_per_partition_unaligned); - encoder->private_->raw_bits_per_partition_unaligned = 0; - } - if(encoder->protected_->verify) { - for(i = 0; i < encoder->protected_->channels; i++) { - if(0 != encoder->private_->verify.input_fifo.data[i]) { - free(encoder->private_->verify.input_fifo.data[i]); - encoder->private_->verify.input_fifo.data[i] = 0; - } - } - } - FLAC__bitwriter_free(encoder->private_->frame); -} - -FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, uint32_t new_blocksize) -{ - FLAC__bool ok; - uint32_t i, channel; - - FLAC__ASSERT(new_blocksize > 0); - FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK); - - ok = true; - - /* To avoid excessive malloc'ing, we only grow the buffer; no shrinking. */ - if(new_blocksize > encoder->private_->input_capacity) { - - /* WATCHOUT: FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx() and ..._intrin_sse2() - * require that the input arrays (in our case the integer signals) - * have a buffer of up to 3 zeroes in front (at negative indices) for - * alignment purposes; we use 4 in front to keep the data well-aligned. - */ - - for(i = 0; ok && i < encoder->protected_->channels; i++) { - ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]); - if(ok) { - memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4); - encoder->private_->integer_signal[i] += 4; - } - } - for(i = 0; ok && i < 2; i++) { - ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_mid_side_unaligned[i], &encoder->private_->integer_signal_mid_side[i]); - if(ok) { - memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4); - encoder->private_->integer_signal_mid_side[i] += 4; - } - } - ok = ok && FLAC__memory_alloc_aligned_int64_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_33bit_side_unaligned, &encoder->private_->integer_signal_33bit_side); -#ifndef FLAC__INTEGER_ONLY_LIBRARY - if(ok && encoder->protected_->max_lpc_order > 0) { - for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) - ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]); - ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal); - } -#endif - for(channel = 0; ok && channel < encoder->protected_->channels; channel++) { - for(i = 0; ok && i < 2; i++) { - ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]); - } - } - - - for(channel = 0; ok && channel < encoder->protected_->channels; channel++) { - for(i = 0; ok && i < 2; i++) { - ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_workspace[channel][i], encoder->protected_->max_residual_partition_order); - ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_workspace[channel][i], encoder->protected_->max_residual_partition_order); - } - } - - for(channel = 0; ok && channel < 2; channel++) { - for(i = 0; ok && i < 2; i++) { - ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_mid_side_unaligned[channel][i], &encoder->private_->residual_workspace_mid_side[channel][i]); - } - } - - for(channel = 0; ok && channel < 2; channel++) { - for(i = 0; ok && i < 2; i++) { - ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_workspace_mid_side[channel][i], encoder->protected_->max_residual_partition_order); - } - } - - for(i = 0; ok && i < 2; i++) { - ok = ok && FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(&encoder->private_->partitioned_rice_contents_extra[i], encoder->protected_->max_residual_partition_order); - } - - - /* the *2 is an approximation to the series 1 + 1/2 + 1/4 + ... that sums tree occupies in a flat array */ - /*@@@ new_blocksize*2 is too pessimistic, but to fix, we need smarter logic because a smaller new_blocksize can actually increase the # of partitions; would require moving this out into a separate function, then checking its capacity against the need of the current blocksize&min/max_partition_order (and maybe predictor order) */ - ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums); - if(encoder->protected_->do_escape_coding) - ok = ok && FLAC__memory_alloc_aligned_uint32_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition); -} - if(ok) - encoder->private_->input_capacity = new_blocksize; - else { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return ok; - } - - - /* now adjust the windows if the blocksize has changed */ -#ifndef FLAC__INTEGER_ONLY_LIBRARY - if(encoder->protected_->max_lpc_order > 0 && new_blocksize > 1) { - for(i = 0; i < encoder->protected_->num_apodizations; i++) { - switch(encoder->protected_->apodizations[i].type) { - case FLAC__APODIZATION_BARTLETT: - FLAC__window_bartlett(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_BARTLETT_HANN: - FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_BLACKMAN: - FLAC__window_blackman(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE: - FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_CONNES: - FLAC__window_connes(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_FLATTOP: - FLAC__window_flattop(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_GAUSS: - FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev); - break; - case FLAC__APODIZATION_HAMMING: - FLAC__window_hamming(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_HANN: - FLAC__window_hann(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_KAISER_BESSEL: - FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_NUTTALL: - FLAC__window_nuttall(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_RECTANGLE: - FLAC__window_rectangle(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_TRIANGLE: - FLAC__window_triangle(encoder->private_->window[i], new_blocksize); - break; - case FLAC__APODIZATION_TUKEY: - FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p); - break; - case FLAC__APODIZATION_PARTIAL_TUKEY: - FLAC__window_partial_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.multiple_tukey.p, encoder->protected_->apodizations[i].parameters.multiple_tukey.start, encoder->protected_->apodizations[i].parameters.multiple_tukey.end); - break; - case FLAC__APODIZATION_PUNCHOUT_TUKEY: - FLAC__window_punchout_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.multiple_tukey.p, encoder->protected_->apodizations[i].parameters.multiple_tukey.start, encoder->protected_->apodizations[i].parameters.multiple_tukey.end); - break; - case FLAC__APODIZATION_SUBDIVIDE_TUKEY: - FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p); - break; - case FLAC__APODIZATION_WELCH: - FLAC__window_welch(encoder->private_->window[i], new_blocksize); - break; - default: - FLAC__ASSERT(0); - /* double protection */ - FLAC__window_hann(encoder->private_->window[i], new_blocksize); - break; - } - } - } - if (new_blocksize <= FLAC__MAX_LPC_ORDER) { - /* intrinsics autocorrelation routines do not all handle cases in which lag might be - * larger than data_len. Lag is one larger than the LPC order */ - encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation; - } -#endif - - return true; -} - -FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, uint32_t samples, FLAC__bool is_last_block) -{ - const FLAC__byte *buffer; - size_t bytes; - - FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame)); - - if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return false; - } - - if(encoder->protected_->verify) { - encoder->private_->verify.output.data = buffer; - encoder->private_->verify.output.bytes = bytes; - if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) { - encoder->private_->verify.needs_magic_hack = true; - } - else { - if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder) - || (!is_last_block - && (FLAC__stream_encoder_get_verify_decoder_state(encoder) == FLAC__STREAM_DECODER_END_OF_STREAM)) - || encoder->protected_->state == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR /* Happens when error callback was used */) { - FLAC__bitwriter_release_buffer(encoder->private_->frame); - FLAC__bitwriter_clear(encoder->private_->frame); - if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) - encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR; - return false; - } - } - } - - if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - FLAC__bitwriter_release_buffer(encoder->private_->frame); - FLAC__bitwriter_clear(encoder->private_->frame); - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return false; - } - - FLAC__bitwriter_release_buffer(encoder->private_->frame); - FLAC__bitwriter_clear(encoder->private_->frame); - - if(samples > 0) { - encoder->private_->streaminfo.data.stream_info.min_framesize = flac_min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize); - encoder->private_->streaminfo.data.stream_info.max_framesize = flac_max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize); - } - - return true; -} - -FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, FLAC__bool is_last_block) -{ - FLAC__StreamEncoderWriteStatus status; - FLAC__uint64 output_position = 0; - -#if FLAC__HAS_OGG == 0 - (void)is_last_block; -#endif - - /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get the offset; no error */ - if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) { - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - - /* - * Watch for the STREAMINFO block and first SEEKTABLE block to go by and store their offsets. - */ - if(samples == 0) { - FLAC__MetadataType type = (buffer[0] & 0x7f); - if(type == FLAC__METADATA_TYPE_STREAMINFO) - encoder->protected_->streaminfo_offset = output_position; - else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0) - encoder->protected_->seektable_offset = output_position; - } - - /* - * Mark the current seek point if hit (if audio_offset == 0 that - * means we're still writing metadata and haven't hit the first - * frame yet) - */ - if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) { - const uint32_t blocksize = FLAC__stream_encoder_get_blocksize(encoder); - const FLAC__uint64 frame_first_sample = encoder->private_->samples_written; - const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1; - FLAC__uint64 test_sample; - uint32_t i; - for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) { - test_sample = encoder->private_->seek_table->points[i].sample_number; - if(test_sample > frame_last_sample) { - break; - } - else if(test_sample >= frame_first_sample) { - encoder->private_->seek_table->points[i].sample_number = frame_first_sample; - encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset; - encoder->private_->seek_table->points[i].frame_samples = blocksize; - encoder->private_->first_seekpoint_to_check++; - /* DO NOT: "break;" and here's why: - * The seektable template may contain more than one target - * sample for any given frame; we will keep looping, generating - * duplicate seekpoints for them, and we'll clean it up later, - * just before writing the seektable back to the metadata. - */ - } - else { - encoder->private_->first_seekpoint_to_check++; - } - } - } - -#if FLAC__HAS_OGG - if(encoder->private_->is_ogg) { - status = FLAC__ogg_encoder_aspect_write_callback_wrapper( - &encoder->protected_->ogg_encoder_aspect, - buffer, - bytes, - samples, - encoder->private_->current_frame_number, - is_last_block, - (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback, - encoder, - encoder->private_->client_data - ); - } - else -#endif - status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data); - - if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->private_->bytes_written += bytes; - encoder->private_->samples_written += samples; - /* we keep a high watermark on the number of frames written because - * when the encoder goes back to write metadata, 'current_frame' - * will drop back to 0. - */ - encoder->private_->frames_written = flac_max(encoder->private_->frames_written, encoder->private_->current_frame_number+1); - } - else - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - - return status; -} - -/* Gets called when the encoding process has finished so that we can update the STREAMINFO and SEEKTABLE blocks. */ -void update_metadata_(const FLAC__StreamEncoder *encoder) -{ - FLAC__byte b[flac_max(6u, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)]; - const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo; - FLAC__uint64 samples = metadata->data.stream_info.total_samples; - const uint32_t min_framesize = metadata->data.stream_info.min_framesize; - const uint32_t max_framesize = metadata->data.stream_info.max_framesize; - const uint32_t bps = metadata->data.stream_info.bits_per_sample; - FLAC__StreamEncoderSeekStatus seek_status; - - FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO); - - /* All this is based on intimate knowledge of the stream header - * layout, but a change to the header format that would break this - * would also break all streams encoded in the previous format. - */ - - /* - * Write MD5 signature - */ - { - const uint32_t md5_offset = - FLAC__STREAM_METADATA_HEADER_LENGTH + - ( - FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN + - FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN - ) / 8; - - if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { - if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return; - } - if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return; - } - } - - /* - * Write total samples - */ - { - const uint32_t total_samples_byte_offset = - FLAC__STREAM_METADATA_HEADER_LENGTH + - ( - FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN + - FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN - - 4 - ) / 8; - if(samples > (FLAC__U64L(1) << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN)) - samples = 0; - - b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F); - b[1] = (FLAC__byte)((samples >> 24) & 0xFF); - b[2] = (FLAC__byte)((samples >> 16) & 0xFF); - b[3] = (FLAC__byte)((samples >> 8) & 0xFF); - b[4] = (FLAC__byte)(samples & 0xFF); - if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + total_samples_byte_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { - if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return; - } - if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return; - } - } - - /* - * Write min/max framesize - */ - { - const uint32_t min_framesize_offset = - FLAC__STREAM_METADATA_HEADER_LENGTH + - ( - FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN - ) / 8; - - b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF); - b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF); - b[2] = (FLAC__byte)(min_framesize & 0xFF); - b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF); - b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF); - b[5] = (FLAC__byte)(max_framesize & 0xFF); - if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + min_framesize_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { - if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return; - } - if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return; - } - } - - /* - * Write seektable - */ - if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) { - uint32_t i; - - FLAC__format_seektable_sort(encoder->private_->seek_table); - - FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table)); - - if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->seektable_offset + FLAC__STREAM_METADATA_HEADER_LENGTH, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { - if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return; - } - - for(i = 0; i < encoder->private_->seek_table->num_points; i++) { - FLAC__uint64 xx; - uint32_t x; - xx = encoder->private_->seek_table->points[i].sample_number; - b[7] = (FLAC__byte)xx; xx >>= 8; - b[6] = (FLAC__byte)xx; xx >>= 8; - b[5] = (FLAC__byte)xx; xx >>= 8; - b[4] = (FLAC__byte)xx; xx >>= 8; - b[3] = (FLAC__byte)xx; xx >>= 8; - b[2] = (FLAC__byte)xx; xx >>= 8; - b[1] = (FLAC__byte)xx; xx >>= 8; - b[0] = (FLAC__byte)xx; xx >>= 8; - xx = encoder->private_->seek_table->points[i].stream_offset; - b[15] = (FLAC__byte)xx; xx >>= 8; - b[14] = (FLAC__byte)xx; xx >>= 8; - b[13] = (FLAC__byte)xx; xx >>= 8; - b[12] = (FLAC__byte)xx; xx >>= 8; - b[11] = (FLAC__byte)xx; xx >>= 8; - b[10] = (FLAC__byte)xx; xx >>= 8; - b[9] = (FLAC__byte)xx; xx >>= 8; - b[8] = (FLAC__byte)xx; xx >>= 8; - x = encoder->private_->seek_table->points[i].frame_samples; - b[17] = (FLAC__byte)x; x >>= 8; - b[16] = (FLAC__byte)x; x >>= 8; - if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; - return; - } - } - } -} - -#if FLAC__HAS_OGG -/* Gets called when the encoding process has finished so that we can update the STREAMINFO and SEEKTABLE blocks. */ -void update_ogg_metadata_(FLAC__StreamEncoder *encoder) -{ - /* the # of bytes in the 1st packet that precede the STREAMINFO */ - static const uint32_t FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH = - FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH + - FLAC__OGG_MAPPING_MAGIC_LENGTH + - FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH + - FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH + - FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH + - FLAC__STREAM_SYNC_LENGTH - ; - FLAC__byte b[flac_max(6u, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)]; - const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo; - const FLAC__uint64 samples = metadata->data.stream_info.total_samples; - const uint32_t min_framesize = metadata->data.stream_info.min_framesize; - const uint32_t max_framesize = metadata->data.stream_info.max_framesize; - ogg_page page; - - FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO); - FLAC__ASSERT(0 != encoder->private_->seek_callback); - - /* Pre-check that client supports seeking, since we don't want the - * ogg_helper code to ever have to deal with this condition. - */ - if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED) - return; - - /* All this is based on intimate knowledge of the stream header - * layout, but a change to the header format that would break this - * would also break all streams encoded in the previous format. - */ - - /** - ** Write STREAMINFO stats - **/ - simple_ogg_page__init(&page); - if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) { - simple_ogg_page__clear(&page); - return; /* state already set */ - } - - /* - * Write MD5 signature - */ - { - const uint32_t md5_offset = - FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH + - FLAC__STREAM_METADATA_HEADER_LENGTH + - ( - FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN + - FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN - ) / 8; - - if(md5_offset + 16 > (uint32_t)page.body_len) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - simple_ogg_page__clear(&page); - return; - } - memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16); - } - - /* - * Write total samples - */ - { - const uint32_t total_samples_byte_offset = - FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH + - FLAC__STREAM_METADATA_HEADER_LENGTH + - ( - FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN + - FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN - - 4 - ) / 8; - - if(total_samples_byte_offset + 5 > (uint32_t)page.body_len) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - simple_ogg_page__clear(&page); - return; - } - b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0; - b[0] |= (FLAC__byte)((samples >> 32) & 0x0F); - b[1] = (FLAC__byte)((samples >> 24) & 0xFF); - b[2] = (FLAC__byte)((samples >> 16) & 0xFF); - b[3] = (FLAC__byte)((samples >> 8) & 0xFF); - b[4] = (FLAC__byte)(samples & 0xFF); - memcpy(page.body + total_samples_byte_offset, b, 5); - } - - /* - * Write min/max framesize - */ - { - const uint32_t min_framesize_offset = - FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH + - FLAC__STREAM_METADATA_HEADER_LENGTH + - ( - FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN - ) / 8; - - if(min_framesize_offset + 6 > (uint32_t)page.body_len) { - encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; - simple_ogg_page__clear(&page); - return; - } - b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF); - b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF); - b[2] = (FLAC__byte)(min_framesize & 0xFF); - b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF); - b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF); - b[5] = (FLAC__byte)(max_framesize & 0xFF); - memcpy(page.body + min_framesize_offset, b, 6); - } - if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) { - simple_ogg_page__clear(&page); - return; /* state already set */ - } - simple_ogg_page__clear(&page); -} -#endif - -FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_block) -{ - FLAC__uint16 crc; - FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK); - - /* - * Accumulate raw signal to the MD5 signature - */ - if(encoder->protected_->do_md5 && !FLAC__MD5Accumulate(&encoder->private_->md5context, (const FLAC__int32 * const *)encoder->private_->integer_signal, encoder->protected_->channels, encoder->protected_->blocksize, (encoder->protected_->bits_per_sample+7) / 8)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return false; - } - - /* - * Process the frame header and subframes into the frame bitbuffer - */ - if(!process_subframes_(encoder)) { - /* the above function sets the state for us in case of an error */ - return false; - } - - /* - * Zero-pad the frame to a byte_boundary - */ - if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return false; - } - - /* - * CRC-16 the whole thing - */ - FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame)); - if( - !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) || - !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN) - ) { - encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; - return false; - } - - /* - * Write it - */ - if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) { - /* the above function sets the state for us in case of an error */ - return false; - } - - /* - * Get ready for the next frame - */ - encoder->private_->current_sample_number = 0; - encoder->private_->current_frame_number++; - encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize; - - return true; -} - -FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder) -{ - FLAC__FrameHeader frame_header; - uint32_t channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order; - FLAC__bool do_independent, do_mid_side, backup_disable_constant_subframes = encoder->private_->disable_constant_subframes, all_subframes_constant = true; - - /* - * Calculate the min,max Rice partition orders - */ - - max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize); - max_partition_order = flac_min(max_partition_order, encoder->protected_->max_residual_partition_order); - min_partition_order = flac_min(min_partition_order, max_partition_order); - - /* - * Setup the frame - */ - frame_header.blocksize = encoder->protected_->blocksize; - frame_header.sample_rate = encoder->protected_->sample_rate; - frame_header.channels = encoder->protected_->channels; - frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */ - frame_header.bits_per_sample = encoder->protected_->bits_per_sample; - frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER; - frame_header.number.frame_number = encoder->private_->current_frame_number; - - /* - * Figure out what channel assignments to try - */ - if(encoder->protected_->do_mid_side_stereo) { - if(encoder->protected_->loose_mid_side_stereo) { - if(encoder->private_->loose_mid_side_stereo_frame_count == 0) { - do_independent = true; - do_mid_side = true; - } - else { - do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT); - do_mid_side = !do_independent; - } - } - else { - do_independent = true; - do_mid_side = true; - } - } - else { - do_independent = true; - do_mid_side = false; - } - - FLAC__ASSERT(do_independent || do_mid_side); - - /* - * Prepare mid-side signals if applicable - */ - if(do_mid_side) { - uint32_t i; - FLAC__ASSERT(encoder->protected_->channels == 2); - if(encoder->protected_->bits_per_sample < 32) - for(i = 0; i < encoder->protected_->blocksize; i++) { - encoder->private_->integer_signal_mid_side[1][i] = encoder->private_->integer_signal[0][i] - encoder->private_->integer_signal[1][i]; - encoder->private_->integer_signal_mid_side[0][i] = (encoder->private_->integer_signal[0][i] + encoder->private_->integer_signal[1][i]) >> 1; /* NOTE: not the same as 'mid = (signal[0][j] + signal[1][j]) / 2' ! */ - } - else - for(i = 0; i <= encoder->protected_->blocksize; i++) { - encoder->private_->integer_signal_33bit_side[i] = (FLAC__int64)encoder->private_->integer_signal[0][i] - (FLAC__int64)encoder->private_->integer_signal[1][i]; - encoder->private_->integer_signal_mid_side[0][i] = ((FLAC__int64)encoder->private_->integer_signal[0][i] + (FLAC__int64)encoder->private_->integer_signal[1][i]) >> 1; /* NOTE: not the same as 'mid = (signal[0][j] + signal[1][j]) / 2' ! */ - } - } - - - /* - * Check for wasted bits; set effective bps for each subframe - */ - if(do_independent) { - for(channel = 0; channel < encoder->protected_->channels; channel++) { - uint32_t w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize); - if (w > encoder->protected_->bits_per_sample) { - w = encoder->protected_->bits_per_sample; - } - encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w; - encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w; - } - } - if(do_mid_side) { - FLAC__ASSERT(encoder->protected_->channels == 2); - for(channel = 0; channel < 2; channel++) { - uint32_t w; - if(encoder->protected_->bits_per_sample < 32 || channel == 0) - w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize); - else - w = get_wasted_bits_wide_(encoder->private_->integer_signal_33bit_side, encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize); - - if (w > encoder->protected_->bits_per_sample) { - w = encoder->protected_->bits_per_sample; - } - encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w; - encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1); - } - } - - /* - * First do a normal encoding pass of each independent channel - */ - if(do_independent) { - for(channel = 0; channel < encoder->protected_->channels; channel++) { - if(encoder->protected_->limit_min_bitrate && all_subframes_constant && (channel + 1) == encoder->protected_->channels){ - /* This frame contains only constant subframes at this point. - * To prevent the frame from becoming too small, make sure - * the last subframe isn't constant */ - encoder->private_->disable_constant_subframes = true; - } - if(! - process_subframe_( - encoder, - min_partition_order, - max_partition_order, - &frame_header, - encoder->private_->subframe_bps[channel], - encoder->private_->integer_signal[channel], - encoder->private_->subframe_workspace_ptr[channel], - encoder->private_->partitioned_rice_contents_workspace_ptr[channel], - encoder->private_->residual_workspace[channel], - encoder->private_->best_subframe+channel, - encoder->private_->best_subframe_bits+channel - ) - ) - return false; - if(encoder->private_->subframe_workspace[channel][encoder->private_->best_subframe[channel]].type != FLAC__SUBFRAME_TYPE_CONSTANT) - all_subframes_constant = false; - } - } - - /* - * Now do mid and side channels if requested - */ - if(do_mid_side) { - FLAC__ASSERT(encoder->protected_->channels == 2); - - for(channel = 0; channel < 2; channel++) { - void *integer_signal_; - if(encoder->private_->subframe_bps_mid_side[channel] <= 32) - integer_signal_ = encoder->private_->integer_signal_mid_side[channel]; - else - integer_signal_ = encoder->private_->integer_signal_33bit_side; - if(! - process_subframe_( - encoder, - min_partition_order, - max_partition_order, - &frame_header, - encoder->private_->subframe_bps_mid_side[channel], - integer_signal_, - encoder->private_->subframe_workspace_ptr_mid_side[channel], - encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel], - encoder->private_->residual_workspace_mid_side[channel], - encoder->private_->best_subframe_mid_side+channel, - encoder->private_->best_subframe_bits_mid_side+channel - ) - ) - return false; - } - } - - /* - * Compose the frame bitbuffer - */ - if(do_mid_side) { - uint32_t left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */ - FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */ - FLAC__ChannelAssignment channel_assignment; - - FLAC__ASSERT(encoder->protected_->channels == 2); - - if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) { - channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE); - } - else { - uint32_t bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */ - uint32_t min_bits; - int ca; - - FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0); - FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1); - FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2); - FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3); - FLAC__ASSERT(do_independent && do_mid_side); - - /* We have to figure out which channel assignent results in the smallest frame */ - bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1]; - bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1]; - bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1]; - bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1]; - - channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; - min_bits = bits[channel_assignment]; - - /* When doing loose mid-side stereo, ignore left-side - * and right-side options */ - ca = encoder->protected_->loose_mid_side_stereo ? 3 : 1; - for( ; ca <= 3; ca++) { - if(bits[ca] < min_bits) { - min_bits = bits[ca]; - channel_assignment = (FLAC__ChannelAssignment)ca; - } - } - } - - frame_header.channel_assignment = channel_assignment; - - if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; - return false; - } - - switch(channel_assignment) { - case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT: - left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]]; - right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]]; - break; - case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE: - left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]]; - right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]]; - break; - case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE: - left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]]; - right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]]; - break; - case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE: - left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]]; - right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]]; - break; - default: - FLAC__ASSERT(0); - } - - switch(channel_assignment) { - case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT: - left_bps = encoder->private_->subframe_bps [0]; - right_bps = encoder->private_->subframe_bps [1]; - break; - case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE: - left_bps = encoder->private_->subframe_bps [0]; - right_bps = encoder->private_->subframe_bps_mid_side[1]; - break; - case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE: - left_bps = encoder->private_->subframe_bps_mid_side[1]; - right_bps = encoder->private_->subframe_bps [1]; - break; - case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE: - left_bps = encoder->private_->subframe_bps_mid_side[0]; - right_bps = encoder->private_->subframe_bps_mid_side[1]; - break; - default: - FLAC__ASSERT(0); - } - - /* note that encoder_add_subframe_ sets the state for us in case of an error */ - if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame)) - return false; - if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame)) - return false; - } - else { - if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; - return false; - } - - for(channel = 0; channel < encoder->protected_->channels; channel++) { - if(!add_subframe_(encoder, frame_header.blocksize, encoder->private_->subframe_bps[channel], &encoder->private_->subframe_workspace[channel][encoder->private_->best_subframe[channel]], encoder->private_->frame)) { - /* the above function sets the state for us in case of an error */ - return false; - } - } - } - - if(encoder->protected_->loose_mid_side_stereo) { - encoder->private_->loose_mid_side_stereo_frame_count++; - if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames) - encoder->private_->loose_mid_side_stereo_frame_count = 0; - } - - encoder->private_->last_channel_assignment = frame_header.channel_assignment; - encoder->private_->disable_constant_subframes = backup_disable_constant_subframes; - - return true; -} - -FLAC__bool process_subframe_( - FLAC__StreamEncoder *encoder, - uint32_t min_partition_order, - uint32_t max_partition_order, - const FLAC__FrameHeader *frame_header, - uint32_t subframe_bps, - const void *integer_signal, - FLAC__Subframe *subframe[2], - FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2], - FLAC__int32 *residual[2], - uint32_t *best_subframe, - uint32_t *best_bits -) -{ -#ifndef FLAC__INTEGER_ONLY_LIBRARY - float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]; -#else - FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]; -#endif -#ifndef FLAC__INTEGER_ONLY_LIBRARY - double lpc_residual_bits_per_sample; - apply_apodization_state_struct apply_apodization_state; - double lpc_error[FLAC__MAX_LPC_ORDER]; - uint32_t min_lpc_order, max_lpc_order, lpc_order, guess_lpc_order; - uint32_t min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision; -#endif - uint32_t min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order; - uint32_t _candidate_bits, _best_bits; - uint32_t _best_subframe; - /* only use RICE2 partitions if stream bps > 16 */ - const uint32_t rice_parameter_limit = FLAC__stream_encoder_get_bits_per_sample(encoder) > 16? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER; - - FLAC__ASSERT(frame_header->blocksize > 0); - - /* verbatim subframe is the baseline against which we measure other compressed subframes */ - _best_subframe = 0; - if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) - _best_bits = UINT32_MAX; - else - _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]); - *best_bits = _best_bits; - - if(frame_header->blocksize > FLAC__MAX_FIXED_ORDER) { - uint32_t signal_is_constant = false; - /* The next formula determines when to use a 64-bit accumulator - * for the error of a fixed predictor, and when a 32-bit one. As - * the error of a 4th order predictor for a given sample is the - * sum of 17 sample values (1+4+6+4+1) and there are blocksize - - * order error values to be summed, the maximum total error is - * maximum_sample_value * (blocksize - order) * 17. As ilog2(x) - * calculates floor(2log(x)), the result must be 31 or lower - */ - if(subframe_bps < 28){ - if(subframe_bps + FLAC__bitmath_ilog2((frame_header->blocksize-FLAC__MAX_FIXED_ORDER)*17) < 32) - guess_fixed_order = encoder->private_->local_fixed_compute_best_predictor(((FLAC__int32 *)integer_signal)+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample); - else - guess_fixed_order = encoder->private_->local_fixed_compute_best_predictor_wide(((FLAC__int32 *)integer_signal)+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample); - } - else - if(subframe_bps <= 32) - guess_fixed_order = encoder->private_->local_fixed_compute_best_predictor_limit_residual(((FLAC__int32 *)integer_signal+FLAC__MAX_FIXED_ORDER),frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample); - else - guess_fixed_order = FLAC__fixed_compute_best_predictor_limit_residual_33bit(((FLAC__int64 *)integer_signal+FLAC__MAX_FIXED_ORDER),frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample); - - /* check for constant subframe */ - if( - !encoder->private_->disable_constant_subframes && -#ifndef FLAC__INTEGER_ONLY_LIBRARY - fixed_residual_bits_per_sample[1] == 0.0 -#else - fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO -#endif - ) { - /* the above means it's possible all samples are the same value; now double-check it: */ - uint32_t i; - signal_is_constant = true; - if(subframe_bps <= 32){ - const FLAC__int32 *integer_signal_ = integer_signal; - for(i = 1; i < frame_header->blocksize; i++) { - if(integer_signal_[0] != integer_signal_[i]) { - signal_is_constant = false; - break; - } - } - } - else { - const FLAC__int64 *integer_signal_ = integer_signal; - for(i = 1; i < frame_header->blocksize; i++) { - if(integer_signal_[0] != integer_signal_[i]) { - signal_is_constant = false; - break; - } - } - } - } - if(signal_is_constant) { - if(subframe_bps <= 32) - _candidate_bits = evaluate_constant_subframe_(encoder, ((FLAC__int32 *)integer_signal)[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]); - else - _candidate_bits = evaluate_constant_subframe_(encoder, ((FLAC__int64 *)integer_signal)[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]); - - if(_candidate_bits < _best_bits) { - _best_subframe = !_best_subframe; - _best_bits = _candidate_bits; - } - } - else { - if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) { - /* encode fixed */ - if(encoder->protected_->do_exhaustive_model_search) { - min_fixed_order = 0; - max_fixed_order = FLAC__MAX_FIXED_ORDER; - } - else { - min_fixed_order = max_fixed_order = guess_fixed_order; - } - if(max_fixed_order >= frame_header->blocksize) - max_fixed_order = frame_header->blocksize - 1; - for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) { -#ifndef FLAC__INTEGER_ONLY_LIBRARY - if(fixed_residual_bits_per_sample[fixed_order] >= (float)subframe_bps) - continue; /* don't even try */ -#else - if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps) - continue; /* don't even try */ -#endif - _candidate_bits = - evaluate_fixed_subframe_( - encoder, - integer_signal, - residual[!_best_subframe], - encoder->private_->abs_residual_partition_sums, - encoder->private_->raw_bits_per_partition, - frame_header->blocksize, - subframe_bps, - fixed_order, - rice_parameter_limit, - min_partition_order, - max_partition_order, - encoder->protected_->do_escape_coding, - encoder->protected_->rice_parameter_search_dist, - subframe[!_best_subframe], - partitioned_rice_contents[!_best_subframe] - ); - if(_candidate_bits < _best_bits) { - _best_subframe = !_best_subframe; - _best_bits = _candidate_bits; - } - } - } - -#ifndef FLAC__INTEGER_ONLY_LIBRARY - /* encode lpc */ - if(encoder->protected_->max_lpc_order > 0) { - if(encoder->protected_->max_lpc_order >= frame_header->blocksize) - max_lpc_order = frame_header->blocksize-1; - else - max_lpc_order = encoder->protected_->max_lpc_order; - if(max_lpc_order > 0) { - apply_apodization_state.a = 0; - apply_apodization_state.b = 1; - apply_apodization_state.c = 0; - while (apply_apodization_state.a < encoder->protected_->num_apodizations) { - uint32_t max_lpc_order_this_apodization = max_lpc_order; - - if(!apply_apodization_(encoder, &apply_apodization_state, - frame_header->blocksize, lpc_error, - &max_lpc_order_this_apodization, - subframe_bps, integer_signal, - &guess_lpc_order)) - /* If apply_apodization_ fails, try next apodization */ - continue; - - if(encoder->protected_->do_exhaustive_model_search) { - min_lpc_order = 1; - } - else { - min_lpc_order = max_lpc_order_this_apodization = guess_lpc_order; - } - for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order_this_apodization; lpc_order++) { - lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order); - if(lpc_residual_bits_per_sample >= (double)subframe_bps) - continue; /* don't even try */ - if(encoder->protected_->do_qlp_coeff_prec_search) { - min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION; - /* try to keep qlp coeff precision such that only 32-bit math is required for decode of <=16bps(+1bps for side channel) streams */ - if(subframe_bps <= 17) { - max_qlp_coeff_precision = flac_min(32 - subframe_bps - FLAC__bitmath_ilog2(lpc_order), FLAC__MAX_QLP_COEFF_PRECISION); - max_qlp_coeff_precision = flac_max(max_qlp_coeff_precision, min_qlp_coeff_precision); - } - else - max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION; - } - else { - min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision; - } - for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) { - _candidate_bits = - evaluate_lpc_subframe_( - encoder, - integer_signal, - residual[!_best_subframe], - encoder->private_->abs_residual_partition_sums, - encoder->private_->raw_bits_per_partition, - encoder->private_->lp_coeff[lpc_order-1], - frame_header->blocksize, - subframe_bps, - lpc_order, - qlp_coeff_precision, - rice_parameter_limit, - min_partition_order, - max_partition_order, - encoder->protected_->do_escape_coding, - encoder->protected_->rice_parameter_search_dist, - subframe[!_best_subframe], - partitioned_rice_contents[!_best_subframe] - ); - if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */ - if(_candidate_bits < _best_bits) { - _best_subframe = !_best_subframe; - _best_bits = _candidate_bits; - } - } - } - } - } - } - } -#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */ - } - } - - /* under rare circumstances this can happen when all but lpc subframe types are disabled: */ - if(_best_bits == UINT32_MAX) { - FLAC__ASSERT(_best_subframe == 0); - _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]); - } - - *best_subframe = _best_subframe; - *best_bits = _best_bits; - - return true; -} - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -static inline void set_next_subdivide_tukey(FLAC__int32 parts, uint32_t * apodizations, uint32_t * current_depth, uint32_t * current_part){ - // current_part is interleaved: even are partial, odd are punchout - if(*current_depth == 2){ - // For depth 2, we only do partial, no punchout as that is almost redundant - if(*current_part == 0){ - *current_part = 2; - }else{ /* *current_path == 2 */ - *current_part = 0; - (*current_depth)++; - } - }else if((*current_part) < (2*(*current_depth)-1)){ - (*current_part)++; - }else{ /* (*current_part) >= (2*(*current_depth)-1) */ - *current_part = 0; - (*current_depth)++; - } - - /* Now check if we are done with this SUBDIVIDE_TUKEY apodization */ - if(*current_depth > (uint32_t) parts){ - (*apodizations)++; - *current_depth = 1; - *current_part = 0; - } -} - -FLAC__bool apply_apodization_(FLAC__StreamEncoder *encoder, - apply_apodization_state_struct *apply_apodization_state, - uint32_t blocksize, - double *lpc_error, - uint32_t *max_lpc_order_this_apodization, - uint32_t subframe_bps, - const void *integer_signal, - uint32_t *guess_lpc_order) -{ - apply_apodization_state->current_apodization = &encoder->protected_->apodizations[apply_apodization_state->a]; - - if(apply_apodization_state->b == 1) { - /* window full subblock */ - if(subframe_bps <= 32) - FLAC__lpc_window_data(integer_signal, encoder->private_->window[apply_apodization_state->a], encoder->private_->windowed_signal, blocksize); - else - FLAC__lpc_window_data_wide(integer_signal, encoder->private_->window[apply_apodization_state->a], encoder->private_->windowed_signal, blocksize); - encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, blocksize, (*max_lpc_order_this_apodization)+1, apply_apodization_state->autoc); - if(apply_apodization_state->current_apodization->type == FLAC__APODIZATION_SUBDIVIDE_TUKEY){ - uint32_t i; - for(i = 0; i < *max_lpc_order_this_apodization; i++) - memcpy(apply_apodization_state->autoc_root, apply_apodization_state->autoc, *max_lpc_order_this_apodization*sizeof(apply_apodization_state->autoc[0])); - - (apply_apodization_state->b)++; - }else{ - (apply_apodization_state->a)++; - } - } - else { - /* window part of subblock */ - if(blocksize/apply_apodization_state->b <= FLAC__MAX_LPC_ORDER) { - /* intrinsics autocorrelation routines do not all handle cases in which lag might be - * larger than data_len, and some routines round lag up to the nearest multiple of 4 - * As little gain is expected from using LPC on part of a signal as small as 32 samples - * and to enable widening this rounding up to larger values in the future, windowing - * parts smaller than or equal to FLAC__MAX_LPC_ORDER (which is 32) samples is not supported */ - set_next_subdivide_tukey(apply_apodization_state->current_apodization->parameters.subdivide_tukey.parts, &apply_apodization_state->a, &apply_apodization_state->b, &apply_apodization_state->c); - return false; - } - if(!(apply_apodization_state->c % 2)) { - /* on even c, evaluate the (c/2)th partial window of size blocksize/b */ - if(subframe_bps <= 32) - FLAC__lpc_window_data_partial(integer_signal, encoder->private_->window[apply_apodization_state->a], encoder->private_->windowed_signal, blocksize, blocksize/apply_apodization_state->b/2, (apply_apodization_state->c/2*blocksize)/apply_apodization_state->b); - else - FLAC__lpc_window_data_partial_wide(integer_signal, encoder->private_->window[apply_apodization_state->a], encoder->private_->windowed_signal, blocksize, blocksize/apply_apodization_state->b/2, (apply_apodization_state->c/2*blocksize)/apply_apodization_state->b); - encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, blocksize/apply_apodization_state->b, (*max_lpc_order_this_apodization)+1, apply_apodization_state->autoc); - } - else { - /* on uneven c, evaluate the root window (over the whole block) minus the previous partial window - * similar to tukey_punchout apodization but more efficient */ - uint32_t i; - for(i = 0; i < *max_lpc_order_this_apodization; i++) - apply_apodization_state->autoc[i] = apply_apodization_state->autoc_root[i] - apply_apodization_state->autoc[i]; - } - /* Next function sets a, b and c appropriate for next iteration */ - set_next_subdivide_tukey(apply_apodization_state->current_apodization->parameters.subdivide_tukey.parts, &apply_apodization_state->a, &apply_apodization_state->b, &apply_apodization_state->c); - } - - if(apply_apodization_state->autoc[0] == 0.0) /* Signal seems to be constant, so we can't do lp. Constant detection is probably disabled */ - return false; - FLAC__lpc_compute_lp_coefficients(apply_apodization_state->autoc, max_lpc_order_this_apodization, encoder->private_->lp_coeff, lpc_error); - *guess_lpc_order = - FLAC__lpc_compute_best_order( - lpc_error, - *max_lpc_order_this_apodization, - blocksize, - subframe_bps + ( - encoder->protected_->do_qlp_coeff_prec_search? - FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */ - encoder->protected_->qlp_coeff_precision - ) - ); - return true; -} -#endif - -FLAC__bool add_subframe_( - FLAC__StreamEncoder *encoder, - uint32_t blocksize, - uint32_t subframe_bps, - const FLAC__Subframe *subframe, - FLAC__BitWriter *frame -) -{ - switch(subframe->type) { - case FLAC__SUBFRAME_TYPE_CONSTANT: - if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; - return false; - } - break; - case FLAC__SUBFRAME_TYPE_FIXED: - if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; - return false; - } - break; - case FLAC__SUBFRAME_TYPE_LPC: - if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; - return false; - } - break; - case FLAC__SUBFRAME_TYPE_VERBATIM: - if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) { - encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; - return false; - } - break; - default: - FLAC__ASSERT(0); - } - - return true; -} - -#define SPOTCHECK_ESTIMATE 0 -#if SPOTCHECK_ESTIMATE -static void spotcheck_subframe_estimate_( - FLAC__StreamEncoder *encoder, - uint32_t blocksize, - uint32_t subframe_bps, - const FLAC__Subframe *subframe, - uint32_t estimate -) -{ - FLAC__bool ret; - FLAC__BitWriter *frame = FLAC__bitwriter_new(); - if(frame == 0) { - fprintf(stderr, "EST: can't allocate frame\n"); - return; - } - if(!FLAC__bitwriter_init(frame)) { - fprintf(stderr, "EST: can't init frame\n"); - return; - } - ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame); - FLAC__ASSERT(ret); - { - const uint32_t actual = FLAC__bitwriter_get_input_bits_unconsumed(frame); - if(estimate != actual) - fprintf(stderr, "EST: bad, frame#%u sub#%%d type=%8s est=%u, actual=%u, delta=%d\n", encoder->private_->current_frame_number, FLAC__SubframeTypeString[subframe->type], estimate, actual, (int)actual-(int)estimate); - } - FLAC__bitwriter_delete(frame); -} -#endif - -uint32_t evaluate_constant_subframe_( - FLAC__StreamEncoder *encoder, - const FLAC__int64 signal, - uint32_t blocksize, - uint32_t subframe_bps, - FLAC__Subframe *subframe -) -{ - uint32_t estimate; - subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT; - subframe->data.constant.value = signal; - - estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps; - -#if SPOTCHECK_ESTIMATE - spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate); -#else - (void)encoder, (void)blocksize; -#endif - - return estimate; -} - -uint32_t evaluate_fixed_subframe_( - FLAC__StreamEncoder *encoder, - const void *signal, - FLAC__int32 residual[], - FLAC__uint64 abs_residual_partition_sums[], - uint32_t raw_bits_per_partition[], - uint32_t blocksize, - uint32_t subframe_bps, - uint32_t order, - uint32_t rice_parameter_limit, - uint32_t min_partition_order, - uint32_t max_partition_order, - FLAC__bool do_escape_coding, - uint32_t rice_parameter_search_dist, - FLAC__Subframe *subframe, - FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents -) -{ - uint32_t i, residual_bits, estimate; - const uint32_t residual_samples = blocksize - order; - - if((subframe_bps + order) <= 32) - FLAC__fixed_compute_residual(((FLAC__int32 *)signal)+order, residual_samples, order, residual); - else if(subframe_bps <= 32) - FLAC__fixed_compute_residual_wide(((FLAC__int32 *)signal)+order, residual_samples, order, residual); - else - FLAC__fixed_compute_residual_wide_33bit(((FLAC__int64 *)signal)+order, residual_samples, order, residual); - - subframe->type = FLAC__SUBFRAME_TYPE_FIXED; - - subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE; - subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents; - subframe->data.fixed.residual = residual; - - residual_bits = - find_best_partition_order_( - encoder->private_, - residual, - abs_residual_partition_sums, - raw_bits_per_partition, - residual_samples, - order, - rice_parameter_limit, - min_partition_order, - max_partition_order, - subframe_bps, - do_escape_coding, - rice_parameter_search_dist, - &subframe->data.fixed.entropy_coding_method - ); - - subframe->data.fixed.order = order; - if(subframe_bps <= 32) - for(i = 0; i < order; i++) - subframe->data.fixed.warmup[i] = ((FLAC__int32 *)signal)[i]; - else - for(i = 0; i < order; i++) - subframe->data.fixed.warmup[i] = ((FLAC__int64 *)signal)[i]; - - estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps); - if(residual_bits < UINT32_MAX - estimate) // To make sure estimate doesn't overflow - estimate += residual_bits; - else - estimate = UINT32_MAX; - -#if SPOTCHECK_ESTIMATE - spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate); -#endif - - return estimate; -} - -#ifndef FLAC__INTEGER_ONLY_LIBRARY -uint32_t evaluate_lpc_subframe_( - FLAC__StreamEncoder *encoder, - const void *signal, - FLAC__int32 residual[], - FLAC__uint64 abs_residual_partition_sums[], - uint32_t raw_bits_per_partition[], - const FLAC__real lp_coeff[], - uint32_t blocksize, - uint32_t subframe_bps, - uint32_t order, - uint32_t qlp_coeff_precision, - uint32_t rice_parameter_limit, - uint32_t min_partition_order, - uint32_t max_partition_order, - FLAC__bool do_escape_coding, - uint32_t rice_parameter_search_dist, - FLAC__Subframe *subframe, - FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents -) -{ - FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER]; /* WATCHOUT: the size is important; some x86 intrinsic routines need more than lpc order elements */ - uint32_t i, residual_bits, estimate; - int quantization, ret; - const uint32_t residual_samples = blocksize - order; - - /* try to keep qlp coeff precision such that only 32-bit math is required for decode of <=16bps(+1bps for side channel) streams */ - if(subframe_bps <= 17) { - FLAC__ASSERT(order > 0); - FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER); - qlp_coeff_precision = flac_min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order)); - } - - ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization); - if(ret != 0) - return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */ - - if(FLAC__lpc_max_residual_bps(subframe_bps, qlp_coeff, order, quantization) > 32) { - if(subframe_bps <= 32){ - if(!FLAC__lpc_compute_residual_from_qlp_coefficients_limit_residual(((FLAC__int32 *)signal)+order, residual_samples, qlp_coeff, order, quantization, residual)) - return 0; - } - else - if(!FLAC__lpc_compute_residual_from_qlp_coefficients_limit_residual_33bit(((FLAC__int64 *)signal)+order, residual_samples, qlp_coeff, order, quantization, residual)) - return 0; - } - else - if(FLAC__lpc_max_prediction_before_shift_bps(subframe_bps, qlp_coeff, order) <= 32) - if(subframe_bps <= 16 && qlp_coeff_precision <= 16) - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(((FLAC__int32 *)signal)+order, residual_samples, qlp_coeff, order, quantization, residual); - else - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(((FLAC__int32 *)signal)+order, residual_samples, qlp_coeff, order, quantization, residual); - else - encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(((FLAC__int32 *)signal)+order, residual_samples, qlp_coeff, order, quantization, residual); - - subframe->type = FLAC__SUBFRAME_TYPE_LPC; - - subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE; - subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents; - subframe->data.lpc.residual = residual; - - residual_bits = - find_best_partition_order_( - encoder->private_, - residual, - abs_residual_partition_sums, - raw_bits_per_partition, - residual_samples, - order, - rice_parameter_limit, - min_partition_order, - max_partition_order, - subframe_bps, - do_escape_coding, - rice_parameter_search_dist, - &subframe->data.lpc.entropy_coding_method - ); - - subframe->data.lpc.order = order; - subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision; - subframe->data.lpc.quantization_level = quantization; - memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER); - if(subframe_bps <= 32) - for(i = 0; i < order; i++) - subframe->data.lpc.warmup[i] = ((FLAC__int32 *)signal)[i]; - else - for(i = 0; i < order; i++) - subframe->data.lpc.warmup[i] = ((FLAC__int64 *)signal)[i]; - - - estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN + FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN + (order * (qlp_coeff_precision + subframe_bps)); - if(residual_bits < UINT32_MAX - estimate) // To make sure estimate doesn't overflow - estimate += residual_bits; - else - estimate = UINT32_MAX; - -#if SPOTCHECK_ESTIMATE - spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate); -#endif - - return estimate; -} -#endif - -uint32_t evaluate_verbatim_subframe_( - FLAC__StreamEncoder *encoder, - const void *signal, - uint32_t blocksize, - uint32_t subframe_bps, - FLAC__Subframe *subframe -) -{ - uint32_t estimate; - - subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM; - - if(subframe_bps <= 32){ - subframe->data.verbatim.data_type = FLAC__VERBATIM_SUBFRAME_DATA_TYPE_INT32; - subframe->data.verbatim.data.int32 = signal; - } - else { - subframe->data.verbatim.data_type = FLAC__VERBATIM_SUBFRAME_DATA_TYPE_INT64; - subframe->data.verbatim.data.int64 = signal; - } - - estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps); - -#if SPOTCHECK_ESTIMATE - spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate); -#else - (void)encoder; -#endif - - return estimate; -} - -uint32_t find_best_partition_order_( - FLAC__StreamEncoderPrivate *private_, - const FLAC__int32 residual[], - FLAC__uint64 abs_residual_partition_sums[], - uint32_t raw_bits_per_partition[], - uint32_t residual_samples, - uint32_t predictor_order, - uint32_t rice_parameter_limit, - uint32_t min_partition_order, - uint32_t max_partition_order, - uint32_t bps, - FLAC__bool do_escape_coding, - uint32_t rice_parameter_search_dist, - FLAC__EntropyCodingMethod *best_ecm -) -{ - uint32_t residual_bits, best_residual_bits = 0; - uint32_t best_parameters_index = 0; - uint32_t best_partition_order = 0; - const uint32_t blocksize = residual_samples + predictor_order; - - max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order); - min_partition_order = flac_min(min_partition_order, max_partition_order); - - private_->local_precompute_partition_info_sums(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps); - - if(do_escape_coding) - precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order); - - { - int partition_order; - uint32_t sum; - - for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) { - if(! - set_partitioned_rice_( -#ifdef EXACT_RICE_BITS_CALCULATION - residual, -#endif - abs_residual_partition_sums+sum, - raw_bits_per_partition+sum, - residual_samples, - predictor_order, - rice_parameter_limit, - rice_parameter_search_dist, - (uint32_t)partition_order, - do_escape_coding, - &private_->partitioned_rice_contents_extra[!best_parameters_index], - &residual_bits - ) - ) - { - FLAC__ASSERT(best_residual_bits != 0); - break; - } - sum += 1u << partition_order; - if(best_residual_bits == 0 || residual_bits < best_residual_bits) { - best_residual_bits = residual_bits; - best_parameters_index = !best_parameters_index; - best_partition_order = partition_order; - } - } - } - - best_ecm->data.partitioned_rice.order = best_partition_order; - - { - /* - * We are allowed to de-const the pointer based on our special - * knowledge; it is const to the outside world. - */ - FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents; - uint32_t partition; - - /* save best parameters and raw_bits */ - memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, (uint32_t)sizeof(uint32_t)*(1<<(best_partition_order))); - if(do_escape_coding) - memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, (uint32_t)sizeof(uint32_t)*(1<<(best_partition_order))); - /* - * Now need to check if the type should be changed to - * FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 based on the - * size of the rice parameters. - */ - for(partition = 0; partition < (1u<parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) { - best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2; - break; - } - } - } - - return best_residual_bits; -} - -void precompute_partition_info_sums_( - const FLAC__int32 residual[], - FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, - uint32_t predictor_order, - uint32_t min_partition_order, - uint32_t max_partition_order, - uint32_t bps -) -{ - const uint32_t default_partition_samples = (residual_samples + predictor_order) >> max_partition_order; - uint32_t partitions = 1u << max_partition_order; - - FLAC__ASSERT(default_partition_samples > predictor_order); - - /* first do max_partition_order */ - { - const uint32_t threshold = 32 - FLAC__bitmath_ilog2(default_partition_samples); - uint32_t partition, residual_sample, end = (uint32_t)(-(int)predictor_order); - /* WATCHOUT: "bps + FLAC__MAX_EXTRA_RESIDUAL_BPS" is the maximum assumed size of the average residual magnitude */ - if(bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < threshold) { - for(partition = residual_sample = 0; partition < partitions; partition++) { - FLAC__uint32 abs_residual_partition_sum = 0; - end += default_partition_samples; - for( ; residual_sample < end; residual_sample++) - abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */ - abs_residual_partition_sums[partition] = abs_residual_partition_sum; - } - } - else { /* have to pessimistically use 64 bits for accumulator */ - for(partition = residual_sample = 0; partition < partitions; partition++) { - FLAC__uint64 abs_residual_partition_sum64 = 0; - end += default_partition_samples; - for( ; residual_sample < end; residual_sample++) - abs_residual_partition_sum64 += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */ - abs_residual_partition_sums[partition] = abs_residual_partition_sum64; - } - } - } - - /* now merge partitions for lower orders */ - { - uint32_t from_partition = 0, to_partition = partitions; - int partition_order; - for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) { - uint32_t i; - partitions >>= 1; - for(i = 0; i < partitions; i++) { - abs_residual_partition_sums[to_partition++] = - abs_residual_partition_sums[from_partition ] + - abs_residual_partition_sums[from_partition+1]; - from_partition += 2; - } - } - } -} - -void precompute_partition_info_escapes_( - const FLAC__int32 residual[], - uint32_t raw_bits_per_partition[], - uint32_t residual_samples, - uint32_t predictor_order, - uint32_t min_partition_order, - uint32_t max_partition_order -) -{ - int partition_order; - uint32_t from_partition, to_partition = 0; - const uint32_t blocksize = residual_samples + predictor_order; - - /* first do max_partition_order */ - for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) { - FLAC__int32 r; - FLAC__uint32 rmax; - uint32_t partition, partition_sample, partition_samples, residual_sample; - const uint32_t partitions = 1u << partition_order; - const uint32_t default_partition_samples = blocksize >> partition_order; - - FLAC__ASSERT(default_partition_samples > predictor_order); - - for(partition = residual_sample = 0; partition < partitions; partition++) { - partition_samples = default_partition_samples; - if(partition == 0) - partition_samples -= predictor_order; - rmax = 0; - for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) { - r = residual[residual_sample++]; - /* OPT: maybe faster: rmax |= r ^ (r>>31) */ - if(r < 0) - rmax |= ~r; - else - rmax |= r; - } - /* now we know all residual values are in the range [-rmax-1,rmax] */ - raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1; - } - to_partition = partitions; - break; /*@@@ yuck, should remove the 'for' loop instead */ - } - - /* now merge partitions for lower orders */ - for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) { - uint32_t m; - uint32_t i; - const uint32_t partitions = 1u << partition_order; - for(i = 0; i < partitions; i++) { - m = raw_bits_per_partition[from_partition]; - from_partition++; - raw_bits_per_partition[to_partition] = flac_max(m, raw_bits_per_partition[from_partition]); - from_partition++; - to_partition++; - } - } -} - -#ifdef EXACT_RICE_BITS_CALCULATION -static inline uint32_t count_rice_bits_in_partition_( - const uint32_t rice_parameter, - const uint32_t partition_samples, - const FLAC__int32 *residual -) -{ - uint32_t i; - uint64_t partition_bits = - FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /* actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN but err on side of 16bps */ - (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */ - ; - for(i = 0; i < partition_samples; i++) - partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter ); - return (uint32_t)(flac_min(partition_bits,UINT32_MAX)); // To make sure the return value doesn't overflow -} -#else -static inline uint32_t count_rice_bits_in_partition_( - const uint32_t rice_parameter, - const uint32_t partition_samples, - const FLAC__uint64 abs_residual_partition_sum -) -{ - return (uint32_t)(flac_min( // To make sure the return value doesn't overflow - FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /* actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN but err on side of 16bps */ - (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */ - ( - rice_parameter? - (abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */ - : (abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */ - ) - - (partition_samples >> 1),UINT32_MAX)); - /* -(partition_samples>>1) to subtract out extra contributions to the abs_residual_partition_sum. - * The actual number of bits used is closer to the sum(for all i in the partition) of abs(residual[i])>>(rice_parameter-1) - * By using the abs_residual_partition sum, we also add in bits in the LSBs that would normally be shifted out. - * So the subtraction term tries to guess how many extra bits were contributed. - * If the LSBs are randomly distributed, this should average to 0.5 extra bits per sample. - */ - ; -} -#endif - -FLAC__bool set_partitioned_rice_( -#ifdef EXACT_RICE_BITS_CALCULATION - const FLAC__int32 residual[], -#endif - const FLAC__uint64 abs_residual_partition_sums[], - const uint32_t raw_bits_per_partition[], - const uint32_t residual_samples, - const uint32_t predictor_order, - const uint32_t rice_parameter_limit, - const uint32_t rice_parameter_search_dist, - const uint32_t partition_order, - const FLAC__bool search_for_escapes, - FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, - uint32_t *bits -) -{ - uint32_t rice_parameter, partition_bits; - uint32_t best_partition_bits, best_rice_parameter = 0; - uint32_t bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; - uint32_t *parameters, *raw_bits; - uint32_t partition, residual_sample; - uint32_t partition_samples, partition_samples_base; - uint32_t partition_samples_fixed_point_divisor, partition_samples_fixed_point_divisor_base; - const uint32_t partitions = 1u << partition_order; - FLAC__uint64 mean; -#ifdef ENABLE_RICE_PARAMETER_SEARCH - uint32_t min_rice_parameter, max_rice_parameter; -#else - (void)rice_parameter_search_dist; -#endif - - FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER); - - parameters = partitioned_rice_contents->parameters; - raw_bits = partitioned_rice_contents->raw_bits; - - partition_samples_base = (residual_samples+predictor_order) >> partition_order; - - /* Integer division is slow. To speed up things, precalculate a fixed point - * divisor, as all partitions except the first are the same size. 18 bits - * are taken because maximum block size is 65535, max partition size for - * partitions other than 0 is 32767 (15 bit), max abs residual is 2^31, - * which leaves 18 bit */ - partition_samples_fixed_point_divisor_base = 0x40000 / partition_samples_base; - - for(partition = residual_sample = 0; partition < partitions; partition++) { - partition_samples = partition_samples_base; - if(partition > 0) { - partition_samples_fixed_point_divisor = partition_samples_fixed_point_divisor_base; - } - else { - if(partition_samples <= predictor_order) - return false; - else - partition_samples -= predictor_order; - partition_samples_fixed_point_divisor = 0x40000 / partition_samples; - } - mean = abs_residual_partition_sums[partition]; - /* 'mean' is not a good name for the variable, it is - * actually the sum of magnitudes of all residual values - * in the partition, so the actual mean is - * mean/partition_samples - */ - if(mean < 2 || (((mean - 1)*partition_samples_fixed_point_divisor)>>18) == 0) - rice_parameter = 0; - else - rice_parameter = FLAC__bitmath_ilog2_wide(((mean - 1)*partition_samples_fixed_point_divisor)>>18) + 1; - - if(rice_parameter >= rice_parameter_limit) { -#ifndef NDEBUG - fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1); -#endif - rice_parameter = rice_parameter_limit - 1; - } - - best_partition_bits = UINT32_MAX; -#ifdef ENABLE_RICE_PARAMETER_SEARCH - if(rice_parameter_search_dist) { - if(rice_parameter < rice_parameter_search_dist) - min_rice_parameter = 0; - else - min_rice_parameter = rice_parameter - rice_parameter_search_dist; - max_rice_parameter = rice_parameter + rice_parameter_search_dist; - if(max_rice_parameter >= rice_parameter_limit) { -#ifndef NDEBUG - fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1); -#endif - max_rice_parameter = rice_parameter_limit - 1; - } - } - else - min_rice_parameter = max_rice_parameter = rice_parameter; - - for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) { -#endif -#ifdef EXACT_RICE_BITS_CALCULATION - partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample); -#else - partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]); -#endif - if(partition_bits < best_partition_bits) { - best_rice_parameter = rice_parameter; - best_partition_bits = partition_bits; - } -#ifdef ENABLE_RICE_PARAMETER_SEARCH - } -#endif - if(search_for_escapes) { - partition_bits = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN + raw_bits_per_partition[partition] * partition_samples; - if(partition_bits <= best_partition_bits && raw_bits_per_partition[partition] < 32) { - raw_bits[partition] = raw_bits_per_partition[partition]; - best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */ - best_partition_bits = partition_bits; - } - else - raw_bits[partition] = 0; - } - parameters[partition] = best_rice_parameter; - if(best_partition_bits < UINT32_MAX - bits_) // To make sure _bits doesn't overflow - bits_ += best_partition_bits; - else - bits_ = UINT32_MAX; - residual_sample += partition_samples; - } - - *bits = bits_; - return true; -} - -uint32_t get_wasted_bits_(FLAC__int32 signal[], uint32_t samples) -{ - uint32_t i, shift; - FLAC__int32 x = 0; - - for(i = 0; i < samples && !(x&1); i++) - x |= signal[i]; - - if(x == 0) { - shift = 0; - } - else { - for(shift = 0; !(x&1); shift++) - x >>= 1; - } - - if(shift > 0) { - for(i = 0; i < samples; i++) - signal[i] >>= shift; - } - - return shift; -} - -uint32_t get_wasted_bits_wide_(FLAC__int64 signal_wide[], FLAC__int32 signal[], uint32_t samples) -{ - uint32_t i, shift; - FLAC__int64 x = 0; - - for(i = 0; i < samples && !(x&1); i++) - x |= signal_wide[i]; - - if(x == 0) { - shift = 1; - } - else { - for(shift = 0; !(x&1); shift++) - x >>= 1; - } - - if(shift > 0) { - for(i = 0; i < samples; i++) - signal[i] = (FLAC__int32)(signal_wide[i] >> shift); - } - - return shift; -} - - -void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], uint32_t input_offset, uint32_t channels, uint32_t wide_samples) -{ - uint32_t channel; - - for(channel = 0; channel < channels; channel++) - memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples); - - fifo->tail += wide_samples; - - FLAC__ASSERT(fifo->tail <= fifo->size); -} - -void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], uint32_t input_offset, uint32_t channels, uint32_t wide_samples) -{ - uint32_t channel; - uint32_t sample, wide_sample; - uint32_t tail = fifo->tail; - - sample = input_offset * channels; - for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) { - for(channel = 0; channel < channels; channel++) - fifo->data[channel][tail] = input[sample++]; - tail++; - } - fifo->tail = tail; - - FLAC__ASSERT(fifo->tail <= fifo->size); -} - -FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) -{ - FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data; - const size_t encoded_bytes = encoder->private_->verify.output.bytes; - (void)decoder; - - if(encoder->private_->verify.needs_magic_hack) { - FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH); - *bytes = FLAC__STREAM_SYNC_LENGTH; - memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes); - encoder->private_->verify.needs_magic_hack = false; - } - else { - if(encoded_bytes == 0) { - /* - * If we get here, a FIFO underflow has occurred, - * which means there is a bug somewhere. - */ - FLAC__ASSERT(0); - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - } - else if(encoded_bytes < *bytes) - *bytes = encoded_bytes; - memcpy(buffer, encoder->private_->verify.output.data, *bytes); - encoder->private_->verify.output.data += *bytes; - encoder->private_->verify.output.bytes -= *bytes; - } - - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; -} - -FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data; - uint32_t channel; - const uint32_t channels = frame->header.channels; - const uint32_t blocksize = frame->header.blocksize; - const uint32_t bytes_per_block = sizeof(FLAC__int32) * blocksize; - - (void)decoder; - - if(encoder->protected_->state == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) { - /* This is set when verify_error_callback_ was called */ - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - - for(channel = 0; channel < channels; channel++) { - if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) { - uint32_t i, sample = 0; - FLAC__int32 expect = 0, got = 0; - - for(i = 0; i < blocksize; i++) { - if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) { - sample = i; - expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i]; - got = (FLAC__int32)buffer[channel][i]; - break; - } - } - FLAC__ASSERT(i < blocksize); - FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); - encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample; - encoder->private_->verify.error_stats.frame_number = (uint32_t)(frame->header.number.sample_number / blocksize); - encoder->private_->verify.error_stats.channel = channel; - encoder->private_->verify.error_stats.sample = sample; - encoder->private_->verify.error_stats.expected = expect; - encoder->private_->verify.error_stats.got = got; - encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA; - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } - /* dequeue the frame from the fifo */ - encoder->private_->verify.input_fifo.tail -= blocksize; - FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_); - for(channel = 0; channel < channels; channel++) - memmove(&encoder->private_->verify.input_fifo.data[channel][0], &encoder->private_->verify.input_fifo.data[channel][blocksize], encoder->private_->verify.input_fifo.tail * sizeof(encoder->private_->verify.input_fifo.data[0][0])); - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - (void)decoder, (void)metadata, (void)client_data; -} - -void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data; - (void)decoder, (void)status; - encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR; -} - -FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data) -{ - (void)client_data; - - *bytes = fread(buffer, 1, *bytes, encoder->private_->file); - if (*bytes == 0) { - if (feof(encoder->private_->file)) - return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM; - else if (ferror(encoder->private_->file)) - return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; - } - return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; -} - -FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) -{ - (void)client_data; - - if(fseeko(encoder->private_->file, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0) - return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR; - else - return FLAC__STREAM_ENCODER_SEEK_STATUS_OK; -} - -FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) -{ - FLAC__off_t offset; - - (void)client_data; - - offset = ftello(encoder->private_->file); - - if(offset < 0) { - return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR; - } - else { - *absolute_byte_offset = (FLAC__uint64)offset; - return FLAC__STREAM_ENCODER_TELL_STATUS_OK; - } -} - -#ifdef FLAC__VALGRIND_TESTING -static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) -{ - size_t ret = fwrite(ptr, size, nmemb, stream); - if(!ferror(stream)) - fflush(stream); - return ret; -} -#else -#define local__fwrite fwrite -#endif - -FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data) -{ - (void)client_data, (void)current_frame; - - if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) { - FLAC__bool call_it = 0 != encoder->private_->progress_callback && ( -#if FLAC__HAS_OGG - /* We would like to be able to use 'samples > 0' in the - * clause here but currently because of the nature of our - * Ogg writing implementation, 'samples' is always 0 (see - * ogg_encoder_aspect.c). The downside is extra progress - * callbacks. - */ - encoder->private_->is_ogg? true : -#endif - samples > 0 - ); - if(call_it) { - /* NOTE: We have to add +bytes, +samples, and +1 to the stats - * because at this point in the callback chain, the stats - * have not been updated. Only after we return and control - * gets back to write_frame_() are the stats updated - */ - encoder->private_->progress_callback(encoder, encoder->private_->bytes_written+bytes, encoder->private_->samples_written+samples, encoder->private_->frames_written+(samples?1:0), encoder->private_->total_frames_estimate, encoder->private_->client_data); - } - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; - } - else - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; -} - -/* - * This will forcibly set stdout to binary mode (for OSes that require it) - */ -FILE *get_binary_stdout_(void) -{ - /* if something breaks here it is probably due to the presence or - * absence of an underscore before the identifiers 'setmode', - * 'fileno', and/or 'O_BINARY'; check your system header files. - */ -#if defined _MSC_VER || defined __MINGW32__ - _setmode(_fileno(stdout), _O_BINARY); -#elif defined __EMX__ - setmode(fileno(stdout), O_BINARY); -#endif - - return stdout; -} diff --git a/flac/src/libFLAC/stream_encoder_framing.c b/flac/src/libFLAC/stream_encoder_framing.c deleted file mode 100644 index 0e07a31..0000000 --- a/flac/src/libFLAC/stream_encoder_framing.c +++ /dev/null @@ -1,594 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include /* for strlen() */ -#include "private/stream_encoder_framing.h" -#include "private/crc.h" -#include "FLAC/assert.h" -#include "share/compat.h" - -static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method); -static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const uint32_t residual_samples, const uint32_t predictor_order, const uint32_t rice_parameters[], const uint32_t raw_bits[], const uint32_t partition_order, const FLAC__bool is_extended); - -FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw, FLAC__bool update_vendor_string) -{ - uint32_t i, j, metadata_length; - const uint32_t vendor_string_length = (uint32_t)strlen(FLAC__VENDOR_STRING); - const uint32_t start_bits = FLAC__bitwriter_get_input_bits_unconsumed(bw); - - FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw)); - - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN)) - return false; - - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN)) - return false; - - /* - * First, for VORBIS_COMMENTs, adjust the length to reflect our vendor string - */ - metadata_length = metadata->length; - if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT && update_vendor_string) { - FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry); - metadata_length -= metadata->data.vorbis_comment.vendor_string.length; - metadata_length += vendor_string_length; - } - FLAC__ASSERT(metadata_length < (1u << FLAC__STREAM_METADATA_LENGTH_LEN)); - /* double protection */ - if(metadata_length >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata_length, FLAC__STREAM_METADATA_LENGTH_LEN)) - return false; - - switch(metadata->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN)); - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN)) - return false; - FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN)); - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN)) - return false; - FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN)); - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN)) - return false; - FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN)); - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN)) - return false; - FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate)); - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN)) - return false; - FLAC__ASSERT(metadata->data.stream_info.channels > 0); - FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN)); - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN)) - return false; - FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0); - FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN)); - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN)) - return false; - if(metadata->data.stream_info.total_samples >= (FLAC__U64L(1) << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN)){ - if(!FLAC__bitwriter_write_raw_uint64(bw, 0, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN)) - return false; - }else{ - if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN)) - return false; - } - if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16)) - return false; - break; - case FLAC__METADATA_TYPE_PADDING: - if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8)) - return false; - break; - case FLAC__METADATA_TYPE_APPLICATION: - if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)) - return false; - if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))) - return false; - break; - case FLAC__METADATA_TYPE_SEEKTABLE: - for(i = 0; i < metadata->data.seek_table.num_points; i++) { - if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN)) - return false; - } - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - if(update_vendor_string) { - if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length)) - return false; - if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length)) - return false; - } - else { - if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.vendor_string.length)) - return false; - if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.vendor_string.entry, metadata->data.vorbis_comment.vendor_string.length)) - return false; - } - if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments)) - return false; - for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) { - if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length)) - return false; - if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length)) - return false; - } - break; - case FLAC__METADATA_TYPE_CUESHEET: - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0); - if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.cue_sheet.media_catalog_number, FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN/8)) - return false; - if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN)) - return false; - if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN)) - return false; - for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) { - const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i; - - if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN)) - return false; - FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0); - if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN)) - return false; - if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN)) - return false; - for(j = 0; j < track->num_indices; j++) { - const FLAC__StreamMetadata_CueSheet_Index *indx = track->indices + j; - - if(!FLAC__bitwriter_write_raw_uint64(bw, indx->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, indx->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN)) - return false; - if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN)) - return false; - } - } - break; - case FLAC__METADATA_TYPE_PICTURE: - { - size_t len; - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN)) - return false; - len = strlen(metadata->data.picture.mime_type); - if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN)) - return false; - if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len)) - return false; - len = strlen((const char *)metadata->data.picture.description); - if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN)) - return false; - if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN)) - return false; - if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length)) - return false; - } - break; - default: - if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length)) - return false; - break; - } - - /* Now check whether metadata block length was correct */ - { - uint32_t length_in_bits = FLAC__bitwriter_get_input_bits_unconsumed(bw); - if(length_in_bits < start_bits) - return false; - length_in_bits -= start_bits; - if(length_in_bits % 8 != 0 || length_in_bits != (metadata_length*8+32)) - return false; - } - - FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw)); - return true; -} - -FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw) -{ - uint32_t u, blocksize_hint, sample_rate_hint; - FLAC__byte crc; - - FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw)); - - if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN)) - return false; - - if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN)) - return false; - - if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN)) - return false; - - FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE); - /* when this assertion holds true, any legal blocksize can be expressed in the frame header */ - FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u); - blocksize_hint = 0; - switch(header->blocksize) { - case 192: u = 1; break; - case 576: u = 2; break; - case 1152: u = 3; break; - case 2304: u = 4; break; - case 4608: u = 5; break; - case 256: u = 8; break; - case 512: u = 9; break; - case 1024: u = 10; break; - case 2048: u = 11; break; - case 4096: u = 12; break; - case 8192: u = 13; break; - case 16384: u = 14; break; - case 32768: u = 15; break; - default: - if(header->blocksize <= 0x100) - blocksize_hint = u = 6; - else - blocksize_hint = u = 7; - break; - } - if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN)) - return false; - - FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate)); - sample_rate_hint = 0; - switch(header->sample_rate) { - case 88200: u = 1; break; - case 176400: u = 2; break; - case 192000: u = 3; break; - case 8000: u = 4; break; - case 16000: u = 5; break; - case 22050: u = 6; break; - case 24000: u = 7; break; - case 32000: u = 8; break; - case 44100: u = 9; break; - case 48000: u = 10; break; - case 96000: u = 11; break; - default: - if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0) - sample_rate_hint = u = 12; - else if(header->sample_rate <= 655350 && header->sample_rate % 10 == 0) - sample_rate_hint = u = 14; - else if(header->sample_rate <= 0xffff) - sample_rate_hint = u = 13; - else - u = 0; - break; - } - if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN)) - return false; - - FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS); - switch(header->channel_assignment) { - case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT: - u = header->channels - 1; - break; - case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE: - FLAC__ASSERT(header->channels == 2); - u = 8; - break; - case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE: - FLAC__ASSERT(header->channels == 2); - u = 9; - break; - case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE: - FLAC__ASSERT(header->channels == 2); - u = 10; - break; - default: - FLAC__ASSERT(0); - } - if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN)) - return false; - - FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN)); - switch(header->bits_per_sample) { - case 8 : u = 1; break; - case 12: u = 2; break; - case 16: u = 4; break; - case 20: u = 5; break; - case 24: u = 6; break; - case 32: u = 7; break; - default: u = 0; break; - } - if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN)) - return false; - - if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN)) - return false; - - if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) { - if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number)) - return false; - } - else { - if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number)) - return false; - } - - if(blocksize_hint) - if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16)) - return false; - - switch(sample_rate_hint) { - case 12: - if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8)) - return false; - break; - case 13: - if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16)) - return false; - break; - case 14: - if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16)) - return false; - break; - } - - /* write the CRC */ - if(!FLAC__bitwriter_get_write_crc8(bw, &crc)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN)) - return false; - - return true; -} - -FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw) -{ - FLAC__bool ok; - - ok = - FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN) && - (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) && - FLAC__bitwriter_write_raw_int64(bw, subframe->value, subframe_bps) - ; - - return ok; -} - -FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, uint32_t residual_samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw) -{ - uint32_t i; - - if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK | (subframe->order<<1) | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN)) - return false; - if(wasted_bits) - if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1)) - return false; - - for(i = 0; i < subframe->order; i++) - if(!FLAC__bitwriter_write_raw_int64(bw, subframe->warmup[i], subframe_bps)) - return false; - - if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method)) - return false; - switch(subframe->entropy_coding_method.type) { - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE: - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2: - if(!add_residual_partitioned_rice_( - bw, - subframe->residual, - residual_samples, - subframe->order, - subframe->entropy_coding_method.data.partitioned_rice.contents->parameters, - subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits, - subframe->entropy_coding_method.data.partitioned_rice.order, - /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 - )) - return false; - break; - default: - FLAC__ASSERT(0); - } - - return true; -} - -FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, uint32_t residual_samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw) -{ - uint32_t i; - - if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK | ((subframe->order-1)<<1) | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN)) - return false; - if(wasted_bits) - if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1)) - return false; - - for(i = 0; i < subframe->order; i++) - if(!FLAC__bitwriter_write_raw_int64(bw, subframe->warmup[i], subframe_bps)) - return false; - - if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN)) - return false; - if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN)) - return false; - for(i = 0; i < subframe->order; i++) - if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision)) - return false; - - if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method)) - return false; - switch(subframe->entropy_coding_method.type) { - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE: - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2: - if(!add_residual_partitioned_rice_( - bw, - subframe->residual, - residual_samples, - subframe->order, - subframe->entropy_coding_method.data.partitioned_rice.contents->parameters, - subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits, - subframe->entropy_coding_method.data.partitioned_rice.order, - /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 - )) - return false; - break; - default: - FLAC__ASSERT(0); - } - - return true; -} - -FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, uint32_t samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw) -{ - uint32_t i; - - if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN)) - return false; - if(wasted_bits) - if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1)) - return false; - - if(subframe->data_type == FLAC__VERBATIM_SUBFRAME_DATA_TYPE_INT32) { - const FLAC__int32 *signal = subframe->data.int32; - - FLAC__ASSERT(subframe_bps < 33); - - for(i = 0; i < samples; i++) - if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps)) - return false; - } - else { - const FLAC__int64 *signal = subframe->data.int64; - - FLAC__ASSERT(subframe_bps == 33); - - for(i = 0; i < samples; i++) - if(!FLAC__bitwriter_write_raw_int64(bw, (FLAC__int64)signal[i], subframe_bps)) - return false; - } - - return true; -} - -FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method) -{ - if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN)) - return false; - switch(method->type) { - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE: - case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2: - if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN)) - return false; - break; - default: - FLAC__ASSERT(0); - } - return true; -} - -FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const uint32_t residual_samples, const uint32_t predictor_order, const uint32_t rice_parameters[], const uint32_t raw_bits[], const uint32_t partition_order, const FLAC__bool is_extended) -{ - const uint32_t plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; - const uint32_t pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER; - - if(partition_order == 0) { - uint32_t i; - - if(raw_bits[0] == 0) { - if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen)) - return false; - if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0])) - return false; - } - else { - FLAC__ASSERT(rice_parameters[0] == 0); - if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen)) - return false; - if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN)) - return false; - for(i = 0; i < residual_samples; i++) { - if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0])) - return false; - } - } - return true; - } - else { - uint32_t i, j, k = 0, k_last = 0; - uint32_t partition_samples; - const uint32_t default_partition_samples = (residual_samples+predictor_order) >> partition_order; - for(i = 0; i < (1u< -#endif - -#include "private/cpu.h" - -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "private/stream_encoder.h" -#include "private/bitmath.h" -#ifdef FLAC__AVX2_SUPPORTED - -#include /* for abs() */ -#include /* AVX2 */ -#include "FLAC/assert.h" - -FLAC__SSE_TARGET("avx2") -void FLAC__precompute_partition_info_sums_intrin_avx2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps) -{ - const uint32_t default_partition_samples = (residual_samples + predictor_order) >> max_partition_order; - uint32_t partitions = 1u << max_partition_order; - - FLAC__ASSERT(default_partition_samples > predictor_order); - - /* first do max_partition_order */ - { - const uint32_t threshold = 32 - FLAC__bitmath_ilog2(default_partition_samples); - uint32_t partition, residual_sample, end = (uint32_t)(-(int32_t)predictor_order); - - if(bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < threshold) { - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m256i sum256 = _mm256_setzero_si256(); - __m128i sum128; - end += default_partition_samples; - - for( ; (int)residual_sample < (int)end-7; residual_sample+=8) { - __m256i res256 = _mm256_abs_epi32(_mm256_loadu_si256((const __m256i*)(const void*)(residual+residual_sample))); - sum256 = _mm256_add_epi32(sum256, res256); - } - - sum128 = _mm_add_epi32(_mm256_extracti128_si256(sum256, 1), _mm256_castsi256_si128(sum256)); - - for( ; (int)residual_sample < (int)end-3; residual_sample+=4) { - __m128i res128 = _mm_abs_epi32(_mm_loadu_si128((const __m128i*)(const void*)(residual+residual_sample))); - sum128 = _mm_add_epi32(sum128, res128); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i res128 = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - sum128 = _mm_add_epi32(sum128, res128); - } - - sum128 = _mm_add_epi32(sum128, _mm_shuffle_epi32(sum128, _MM_SHUFFLE(1,0,3,2))); - sum128 = _mm_add_epi32(sum128, _mm_shufflelo_epi16(sum128, _MM_SHUFFLE(1,0,3,2))); - abs_residual_partition_sums[partition] = (FLAC__uint32)_mm_cvtsi128_si32(sum128); -/* workaround for MSVC bugs (at least versions 2015 and 2017 are affected) */ -#if (defined _MSC_VER) && (defined FLAC__CPU_X86_64) - abs_residual_partition_sums[partition] &= 0xFFFFFFFF; /**/ -#endif - } - } - else { /* have to pessimistically use 64 bits for accumulator */ - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m256i sum256 = _mm256_setzero_si256(); - __m128i sum128; - end += default_partition_samples; - - for( ; (int)residual_sample < (int)end-3; residual_sample+=4) { - __m128i res128 = _mm_abs_epi32(_mm_loadu_si128((const __m128i*)(const void*)(residual+residual_sample))); - __m256i res256 = _mm256_cvtepu32_epi64(res128); - sum256 = _mm256_add_epi64(sum256, res256); - } - - sum128 = _mm_add_epi64(_mm256_extracti128_si256(sum256, 1), _mm256_castsi256_si128(sum256)); - - for( ; (int)residual_sample < (int)end-1; residual_sample+=2) { - __m128i res128 = _mm_abs_epi32(_mm_loadl_epi64((const __m128i*)(const void*)(residual+residual_sample))); - res128 = _mm_cvtepu32_epi64(res128); - sum128 = _mm_add_epi64(sum128, res128); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i res128 = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - sum128 = _mm_add_epi64(sum128, res128); - } - - sum128 = _mm_add_epi64(sum128, _mm_srli_si128(sum128, 8)); - _mm_storel_epi64((__m128i*)(void*)(abs_residual_partition_sums+partition), sum128); - } - } - } - - /* now merge partitions for lower orders */ - { - uint32_t from_partition = 0, to_partition = partitions; - int partition_order; - for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) { - uint32_t i; - partitions >>= 1; - for(i = 0; i < partitions; i++) { - abs_residual_partition_sums[to_partition++] = - abs_residual_partition_sums[from_partition ] + - abs_residual_partition_sums[from_partition+1]; - from_partition += 2; - } - } - } - _mm256_zeroupper(); -} - -#endif /* FLAC__AVX2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ diff --git a/flac/src/libFLAC/stream_encoder_intrin_sse2.c b/flac/src/libFLAC/stream_encoder_intrin_sse2.c deleted file mode 100644 index dd25fa6..0000000 --- a/flac/src/libFLAC/stream_encoder_intrin_sse2.c +++ /dev/null @@ -1,159 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" - -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "private/stream_encoder.h" -#include "private/bitmath.h" -#ifdef FLAC__SSE2_SUPPORTED - -#include /* for abs() */ -#include /* SSE2 */ -#include "FLAC/assert.h" -#include "share/compat.h" - -FLAC__SSE_TARGET("sse2") -static inline __m128i local_abs_epi32(__m128i val) -{ - __m128i mask = _mm_srai_epi32(val, 31); - val = _mm_xor_si128(val, mask); - val = _mm_sub_epi32(val, mask); - return val; -} - - -FLAC__SSE_TARGET("sse2") -void FLAC__precompute_partition_info_sums_intrin_sse2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps) -{ - const uint32_t default_partition_samples = (residual_samples + predictor_order) >> max_partition_order; - uint32_t partitions = 1u << max_partition_order; - - FLAC__ASSERT(default_partition_samples > predictor_order); - - /* first do max_partition_order */ - { - const uint32_t threshold = 32 - FLAC__bitmath_ilog2(default_partition_samples); - uint32_t partition, residual_sample, end = (uint32_t)(-(int32_t)predictor_order); - - if(bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < threshold) { - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m128i mm_sum = _mm_setzero_si128(); - uint32_t e1, e3; - end += default_partition_samples; - - e1 = (residual_sample + 3) & ~3; e3 = end & ~3; - if(e1 > end) - e1 = end; /* try flac -l 1 -b 16 and you'll be here */ - - /* assumption: residual[] is properly aligned so (residual + e1) is properly aligned too and _mm_loadu_si128() is fast */ - for( ; residual_sample < e1; residual_sample++) { - __m128i mm_res = local_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - for( ; residual_sample < e3; residual_sample+=4) { - __m128i mm_res = local_abs_epi32(_mm_loadu_si128((const __m128i*)(const void*)(residual+residual_sample))); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i mm_res = local_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - mm_sum = _mm_add_epi32(mm_sum, _mm_shuffle_epi32(mm_sum, _MM_SHUFFLE(1,0,3,2))); - mm_sum = _mm_add_epi32(mm_sum, _mm_shufflelo_epi16(mm_sum, _MM_SHUFFLE(1,0,3,2))); - abs_residual_partition_sums[partition] = (FLAC__uint32)_mm_cvtsi128_si32(mm_sum); -/* workaround for MSVC bugs (at least versions 2015 and 2017 are affected) */ -#if (defined _MSC_VER) && (defined FLAC__CPU_X86_64) - abs_residual_partition_sums[partition] &= 0xFFFFFFFF; -#endif - } - } - else { /* have to pessimistically use 64 bits for accumulator */ - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m128i mm_sum = _mm_setzero_si128(); - uint32_t e1, e3; - end += default_partition_samples; - - e1 = (residual_sample + 1) & ~1; e3 = end & ~1; - FLAC__ASSERT(e1 <= end); - - for( ; residual_sample < e1; residual_sample++) { - __m128i mm_res = local_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); /* 0 0 0 |r0| == 00 |r0_64| */ - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - for( ; residual_sample < e3; residual_sample+=2) { - __m128i mm_res = local_abs_epi32(_mm_loadl_epi64((const __m128i*)(const void*)(residual+residual_sample))); /* 0 0 |r1| |r0| */ - mm_res = _mm_shuffle_epi32(mm_res, _MM_SHUFFLE(3,1,2,0)); /* 0 |r1| 0 |r0| == |r1_64| |r0_64| */ - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i mm_res = local_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - mm_sum = _mm_add_epi64(mm_sum, _mm_srli_si128(mm_sum, 8)); - _mm_storel_epi64((__m128i*)(void*)(abs_residual_partition_sums+partition), mm_sum); - } - } - } - - /* now merge partitions for lower orders */ - { - uint32_t from_partition = 0, to_partition = partitions; - int partition_order; - for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) { - uint32_t i; - partitions >>= 1; - for(i = 0; i < partitions; i++) { - abs_residual_partition_sums[to_partition++] = - abs_residual_partition_sums[from_partition ] + - abs_residual_partition_sums[from_partition+1]; - from_partition += 2; - } - } - } -} - -#endif /* FLAC__SSE2_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ diff --git a/flac/src/libFLAC/stream_encoder_intrin_ssse3.c b/flac/src/libFLAC/stream_encoder_intrin_ssse3.c deleted file mode 100644 index 241f723..0000000 --- a/flac/src/libFLAC/stream_encoder_intrin_ssse3.c +++ /dev/null @@ -1,148 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "private/cpu.h" - -#ifndef FLAC__NO_ASM -#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN -#include "private/stream_encoder.h" -#include "private/bitmath.h" -#ifdef FLAC__SSSE3_SUPPORTED - -#include /* for abs() */ -#include /* SSSE3 */ -#include "FLAC/assert.h" - -FLAC__SSE_TARGET("ssse3") -void FLAC__precompute_partition_info_sums_intrin_ssse3(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[], - uint32_t residual_samples, uint32_t predictor_order, uint32_t min_partition_order, uint32_t max_partition_order, uint32_t bps) -{ - const uint32_t default_partition_samples = (residual_samples + predictor_order) >> max_partition_order; - uint32_t partitions = 1u << max_partition_order; - - FLAC__ASSERT(default_partition_samples > predictor_order); - - /* first do max_partition_order */ - { - const uint32_t threshold = 32 - FLAC__bitmath_ilog2(default_partition_samples); - uint32_t partition, residual_sample, end = (uint32_t)(-(int32_t)predictor_order); - - if(bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < threshold) { - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m128i mm_sum = _mm_setzero_si128(); - uint32_t e1, e3; - end += default_partition_samples; - - e1 = (residual_sample + 3) & ~3; e3 = end & ~3; - if(e1 > end) - e1 = end; /* try flac -l 1 -b 16 and you'll be here */ - - /* assumption: residual[] is properly aligned so (residual + e1) is properly aligned too and _mm_loadu_si128() is fast */ - for( ; residual_sample < e1; residual_sample++) { - __m128i mm_res = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - for( ; residual_sample < e3; residual_sample+=4) { - __m128i mm_res = _mm_abs_epi32(_mm_loadu_si128((const __m128i*)(const void*)(residual+residual_sample))); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i mm_res = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi32(mm_sum, mm_res); - } - - mm_sum = _mm_add_epi32(mm_sum, _mm_shuffle_epi32(mm_sum, _MM_SHUFFLE(1,0,3,2))); - mm_sum = _mm_add_epi32(mm_sum, _mm_shufflelo_epi16(mm_sum, _MM_SHUFFLE(1,0,3,2))); - abs_residual_partition_sums[partition] = (FLAC__uint32)_mm_cvtsi128_si32(mm_sum); -/* workaround for MSVC bugs (at least versions 2015 and 2017 are affected) */ -#if (defined _MSC_VER) && (defined FLAC__CPU_X86_64) - abs_residual_partition_sums[partition] &= 0xFFFFFFFF; -#endif - } - } - else { /* have to pessimistically use 64 bits for accumulator */ - for(partition = residual_sample = 0; partition < partitions; partition++) { - __m128i mm_sum = _mm_setzero_si128(); - uint32_t e1, e3; - end += default_partition_samples; - - e1 = (residual_sample + 1) & ~1; e3 = end & ~1; - FLAC__ASSERT(e1 <= end); - - for( ; residual_sample < e1; residual_sample++) { - __m128i mm_res = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); /* 0 0 0 |r0| == 00 |r0_64| */ - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - for( ; residual_sample < e3; residual_sample+=2) { - __m128i mm_res = _mm_abs_epi32(_mm_loadl_epi64((const __m128i*)(const void*)(residual+residual_sample))); /* 0 0 |r1| |r0| */ - mm_res = _mm_shuffle_epi32(mm_res, _MM_SHUFFLE(3,1,2,0)); /* 0 |r1| 0 |r0| == |r1_64| |r0_64| */ - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - for( ; residual_sample < end; residual_sample++) { - __m128i mm_res = _mm_abs_epi32(_mm_cvtsi32_si128(residual[residual_sample])); - mm_sum = _mm_add_epi64(mm_sum, mm_res); - } - - mm_sum = _mm_add_epi64(mm_sum, _mm_srli_si128(mm_sum, 8)); - _mm_storel_epi64((__m128i*)(void*)(abs_residual_partition_sums+partition), mm_sum); - } - } - } - - /* now merge partitions for lower orders */ - { - uint32_t from_partition = 0, to_partition = partitions; - int partition_order; - for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) { - uint32_t i; - partitions >>= 1; - for(i = 0; i < partitions; i++) { - abs_residual_partition_sums[to_partition++] = - abs_residual_partition_sums[from_partition ] + - abs_residual_partition_sums[from_partition+1]; - from_partition += 2; - } - } - } -} - -#endif /* FLAC__SSSE3_SUPPORTED */ -#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */ -#endif /* FLAC__NO_ASM */ diff --git a/flac/src/libFLAC/version.rc b/flac/src/libFLAC/version.rc deleted file mode 100644 index 019da1d..0000000 --- a/flac/src/libFLAC/version.rc +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include "config.h" -#include "FLAC/export.h" - -#if (defined GIT_COMMIT_HASH && defined GIT_COMMIT_DATE) -# ifdef GIT_COMMIT_TAG -# define VERSIONSTRING GIT_COMMIT_TAG -# else -# define VERSIONSTRING "git-" GIT_COMMIT_HASH -# endif -#else -# define VERSIONSTRING PACKAGE_VERSION -#endif - -#define xstr(s) str(s) -#define str(s) #s - -VS_VERSION_INFO VERSIONINFO -FILEVERSION FLAC_API_VERSION_CURRENT,FLAC_API_VERSION_REVISION,0,0 -FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -FILEFLAGS 0 -FILEOS VOS__WINDOWS32 -FILETYPE VFT_DLL -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "FileDescription", "libFLAC for Windows" - VALUE "ProductName", "Free Lossless Audio Codec" - VALUE "ProductVersion", VERSIONSTRING - VALUE "CompanyName", "Xiph.Org" - VALUE "LegalCopyright", "2000-2009 Josh Coalson, 2011-2023 Xiph.Org Foundation" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END diff --git a/flac/src/libFLAC/window.c b/flac/src/libFLAC/window.c deleted file mode 100644 index 69d5464..0000000 --- a/flac/src/libFLAC/window.c +++ /dev/null @@ -1,308 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2006-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include "share/compat.h" -#include "FLAC/assert.h" -#include "FLAC/format.h" -#include "private/window.h" - -#ifndef FLAC__INTEGER_ONLY_LIBRARY - -#if defined(_MSC_VER) -// silence 25 MSVC warnings 'conversion from 'double' to 'float', possible loss of data' -#pragma warning ( disable : 4244 ) -#endif - -void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - FLAC__int32 n; - - if (L & 1) { - for (n = 0; n <= N/2; n++) - window[n] = 2.0f * n / (float)N; - for (; n <= N; n++) - window[n] = 2.0f - 2.0f * n / (float)N; - } - else { - for (n = 0; n <= L/2-1; n++) - window[n] = 2.0f * n / (float)N; - for (; n <= N; n++) - window[n] = 2.0f - 2.0f * n / (float)N; - } -} - -void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - FLAC__int32 n; - - for (n = 0; n < L; n++) - window[n] = (FLAC__real)(0.62f - 0.48f * fabsf((float)n/(float)N-0.5f) - 0.38f * cosf(2.0f * M_PI * ((float)n/(float)N))); -} - -void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - FLAC__int32 n; - - for (n = 0; n < L; n++) - window[n] = (FLAC__real)(0.42f - 0.5f * cosf(2.0f * M_PI * n / N) + 0.08f * cosf(4.0f * M_PI * n / N)); -} - -/* 4-term -92dB side-lobe */ -void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - FLAC__int32 n; - - for (n = 0; n <= N; n++) - window[n] = (FLAC__real)(0.35875f - 0.48829f * cosf(2.0f * M_PI * n / N) + 0.14128f * cosf(4.0f * M_PI * n / N) - 0.01168f * cosf(6.0f * M_PI * n / N)); -} - -void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - const double N2 = (double)N / 2.; - FLAC__int32 n; - - for (n = 0; n <= N; n++) { - double k = ((double)n - N2) / N2; - k = 1.0f - k * k; - window[n] = (FLAC__real)(k * k); - } -} - -void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - FLAC__int32 n; - - for (n = 0; n < L; n++) - window[n] = (FLAC__real)(0.21557895f - 0.41663158f * cosf(2.0f * M_PI * n / N) + 0.277263158f * cosf(4.0f * M_PI * n / N) - 0.083578947f * cosf(6.0f * M_PI * n / N) + 0.006947368f * cosf(8.0f * M_PI * n / N)); -} - -void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev) -{ - const FLAC__int32 N = L - 1; - const double N2 = (double)N / 2.; - FLAC__int32 n; - - if(!(stddev > 0.0f && stddev <= 0.5f)) - /* stddev is not between 0 and 0.5, might be NaN. - * Default to 0.5 */ - FLAC__window_gauss(window, L, 0.25f); - else { - for (n = 0; n <= N; n++) { - const double k = ((double)n - N2) / (stddev * N2); - window[n] = (FLAC__real)exp(-0.5f * k * k); - } - } -} - -void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - FLAC__int32 n; - - for (n = 0; n < L; n++) - window[n] = (FLAC__real)(0.54f - 0.46f * cosf(2.0f * M_PI * n / N)); -} - -void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - FLAC__int32 n; - - for (n = 0; n < L; n++) - window[n] = (FLAC__real)(0.5f - 0.5f * cosf(2.0f * M_PI * n / N)); -} - -void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - FLAC__int32 n; - - for (n = 0; n < L; n++) - window[n] = (FLAC__real)(0.402f - 0.498f * cosf(2.0f * M_PI * n / N) + 0.098f * cosf(4.0f * M_PI * n / N) - 0.001f * cosf(6.0f * M_PI * n / N)); -} - -void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - FLAC__int32 n; - - for (n = 0; n < L; n++) - window[n] = (FLAC__real)(0.3635819f - 0.4891775f*cosf(2.0f*M_PI*n/N) + 0.1365995f*cosf(4.0f*M_PI*n/N) - 0.0106411f*cosf(6.0f*M_PI*n/N)); -} - -void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L) -{ - FLAC__int32 n; - - for (n = 0; n < L; n++) - window[n] = 1.0f; -} - -void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L) -{ - FLAC__int32 n; - - if (L & 1) { - for (n = 1; n <= (L+1)/2; n++) - window[n-1] = 2.0f * n / ((float)L + 1.0f); - for (; n <= L; n++) - window[n-1] = (float)(2 * (L - n + 1)) / ((float)L + 1.0f); - } - else { - for (n = 1; n <= L/2; n++) - window[n-1] = 2.0f * n / ((float)L + 1.0f); - for (; n <= L; n++) - window[n-1] = (float)(2 * (L - n + 1)) / ((float)L + 1.0f); - } -} - -void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p) -{ - if (p <= 0.0) - FLAC__window_rectangle(window, L); - else if (p >= 1.0) - FLAC__window_hann(window, L); - else if (!(p > 0.0f && p < 1.0f)) - /* p is not between 0 and 1, probably NaN. - * Default to 0.5 */ - FLAC__window_tukey(window, L, 0.5f); - else { - const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1; - FLAC__int32 n; - /* start with rectangle... */ - FLAC__window_rectangle(window, L); - /* ...replace ends with hann */ - if (Np > 0) { - for (n = 0; n <= Np; n++) { - window[n] = (FLAC__real)(0.5f - 0.5f * cosf(M_PI * n / Np)); - window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cosf(M_PI * (n+Np) / Np)); - } - } - } -} - -void FLAC__window_partial_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p, const FLAC__real start, const FLAC__real end) -{ - const FLAC__int32 start_n = (FLAC__int32)(start * L); - const FLAC__int32 end_n = (FLAC__int32)(end * L); - const FLAC__int32 N = end_n - start_n; - FLAC__int32 Np, n, i; - - if (p <= 0.0f) - FLAC__window_partial_tukey(window, L, 0.05f, start, end); - else if (p >= 1.0f) - FLAC__window_partial_tukey(window, L, 0.95f, start, end); - else if (!(p > 0.0f && p < 1.0f)) - /* p is not between 0 and 1, probably NaN. - * Default to 0.5 */ - FLAC__window_partial_tukey(window, L, 0.5f, start, end); - else { - - Np = (FLAC__int32)(p / 2.0f * N); - - for (n = 0; n < start_n && n < L; n++) - window[n] = 0.0f; - for (i = 1; n < (start_n+Np) && n < L; n++, i++) - window[n] = (FLAC__real)(0.5f - 0.5f * cosf(M_PI * i / Np)); - for (; n < (end_n-Np) && n < L; n++) - window[n] = 1.0f; - for (i = Np; n < end_n && n < L; n++, i--) - window[n] = (FLAC__real)(0.5f - 0.5f * cosf(M_PI * i / Np)); - for (; n < L; n++) - window[n] = 0.0f; - } -} - -void FLAC__window_punchout_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p, const FLAC__real start, const FLAC__real end) -{ - const FLAC__int32 start_n = (FLAC__int32)(start * L); - const FLAC__int32 end_n = (FLAC__int32)(end * L); - FLAC__int32 Ns, Ne, n, i; - - if (p <= 0.0f) - FLAC__window_punchout_tukey(window, L, 0.05f, start, end); - else if (p >= 1.0f) - FLAC__window_punchout_tukey(window, L, 0.95f, start, end); - else if (!(p > 0.0f && p < 1.0f)) - /* p is not between 0 and 1, probably NaN. - * Default to 0.5 */ - FLAC__window_punchout_tukey(window, L, 0.5f, start, end); - else { - - Ns = (FLAC__int32)(p / 2.0f * start_n); - Ne = (FLAC__int32)(p / 2.0f * (L - end_n)); - - for (n = 0, i = 1; n < Ns && n < L; n++, i++) - window[n] = (FLAC__real)(0.5f - 0.5f * cosf(M_PI * i / Ns)); - for (; n < start_n-Ns && n < L; n++) - window[n] = 1.0f; - for (i = Ns; n < start_n && n < L; n++, i--) - window[n] = (FLAC__real)(0.5f - 0.5f * cosf(M_PI * i / Ns)); - for (; n < end_n && n < L; n++) - window[n] = 0.0f; - for (i = 1; n < end_n+Ne && n < L; n++, i++) - window[n] = (FLAC__real)(0.5f - 0.5f * cosf(M_PI * i / Ne)); - for (; n < L - (Ne) && n < L; n++) - window[n] = 1.0f; - for (i = Ne; n < L; n++, i--) - window[n] = (FLAC__real)(0.5f - 0.5f * cosf(M_PI * i / Ne)); - } -} - -void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L) -{ - const FLAC__int32 N = L - 1; - const double N2 = (double)N / 2.; - FLAC__int32 n; - - for (n = 0; n <= N; n++) { - const double k = ((double)n - N2) / N2; - window[n] = (FLAC__real)(1.0f - k * k); - } -} - -#if defined(_MSC_VER) -#pragma warning ( default : 4244 ) -#endif - -#endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */ diff --git a/flac/src/metaflac/CMakeLists.txt b/flac/src/metaflac/CMakeLists.txt deleted file mode 100644 index b8af705..0000000 --- a/flac/src/metaflac/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -add_executable(metaflac - main.c - operations.c - operations_shorthand_cuesheet.c - operations_shorthand_picture.c - operations_shorthand_seektable.c - operations_shorthand_streaminfo.c - operations_shorthand_vorbiscomment.c - options.c - usage.c - utils.c - version.rc - $<$:../../include/share/win_utf8_io.h> - $<$:../share/win_utf8_io/win_utf8_io.c>) -target_link_libraries(metaflac FLAC getopt utf8) - -install(TARGETS metaflac EXPORT targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") diff --git a/flac/src/metaflac/Makefile.am b/flac/src/metaflac/Makefile.am deleted file mode 100644 index 8c212ff..0000000 --- a/flac/src/metaflac/Makefile.am +++ /dev/null @@ -1,65 +0,0 @@ -# metaflac - Command-line FLAC metadata editor -# Copyright (C) 2000-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -if OS_IS_WINDOWS -win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la -if HAVE_WINDRES -metaflac_DEPENDENCIES = version.o -windows_resource_link = -Wl,version.o -endif -endif - -bin_PROGRAMS = metaflac - -AM_CFLAGS = @OGG_CFLAGS@ -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include -EXTRA_DIST = \ - CMakeLists.txt \ - version.rc - -metaflac_SOURCES = \ - main.c \ - operations.c \ - operations_shorthand_cuesheet.c \ - operations_shorthand_picture.c \ - operations_shorthand_seektable.c \ - operations_shorthand_streaminfo.c \ - operations_shorthand_vorbiscomment.c \ - options.c \ - usage.c \ - utils.c \ - operations.h \ - operations_shorthand.h \ - options.h \ - usage.h \ - utils.h -metaflac_LDFLAGS = $(AM_LDFLAGS) $(windows_resource_link) - -metaflac_LDADD = \ - $(top_builddir)/src/share/grabbag/libgrabbag.la \ - $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/share/getopt/libgetopt.la \ - $(top_builddir)/src/share/utf8/libutf8.la \ - $(top_builddir)/src/libFLAC/libFLAC.la \ - $(win_utf8_lib) \ - @LTLIBICONV@ - -CLEANFILES = metaflac.exe - -.rc.o: - $(RC) $(AM_CPPFLAGS) $< $@ diff --git a/flac/src/metaflac/main.c b/flac/src/metaflac/main.c deleted file mode 100644 index bb66293..0000000 --- a/flac/src/metaflac/main.c +++ /dev/null @@ -1,75 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "operations.h" -#include "options.h" -#include -#include -#include -#include "share/compat.h" - -#ifndef FUZZ_TOOL_METAFLAC -int main(int argc, char *argv[]) -#else -static int main_to_fuzz(int argc, char *argv[]) -#endif -{ - CommandLineOptions options; - int ret = 0; - -#ifdef __EMX__ - _response(&argc, &argv); - _wildcard(&argc, &argv); -#endif -#ifdef _WIN32 - if (get_utf8_argv(&argc, &argv) != 0) { - fputs("ERROR: failed to convert command line parameters to UTF-8\n", stderr); - return 1; - } -#endif - -#ifdef _WIN32 - { - const char *var; - var = getenv("LC_ALL"); - if (!var) - var = getenv("LC_NUMERIC"); - if (!var) - var = getenv("LANG"); - if (!var || strcmp(var, "C") != 0) - setlocale(LC_ALL, ""); - } -#else - setlocale(LC_ALL, ""); -#endif - init_options(&options); - - if ((ret = parse_options(argc, argv, &options)) == 0) - ret = !do_operations(&options); - else - ret = 1; - - free_options(&options); - - return ret; -} diff --git a/flac/src/metaflac/operations.c b/flac/src/metaflac/operations.c deleted file mode 100644 index d81d87a..0000000 --- a/flac/src/metaflac/operations.c +++ /dev/null @@ -1,823 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "operations.h" -#include "usage.h" -#include "utils.h" -#include "FLAC/assert.h" -#include "FLAC/metadata.h" -#include "share/alloc.h" -#include "share/grabbag.h" -#include "share/compat.h" -#include -#include -#include -#include "operations_shorthand.h" - -static void show_version(void); -static FLAC__bool do_major_operation(const CommandLineOptions *options); -static FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOptions *options); -static FLAC__bool do_major_operation__list(const char *filename, FLAC__Metadata_Chain *chain, const CommandLineOptions *options); -static FLAC__bool do_major_operation__append(FLAC__Metadata_Chain *chain, const CommandLineOptions *options); -static FLAC__bool do_major_operation__remove(FLAC__Metadata_Chain *chain, const CommandLineOptions *options); -static FLAC__bool do_major_operation__remove_all(FLAC__Metadata_Chain *chain, const CommandLineOptions *options); -static FLAC__bool do_shorthand_operations(const CommandLineOptions *options); -static FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLineOptions *options); -static FLAC__bool do_shorthand_operation(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write, FLAC__bool utf8_convert); -static FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned num_files, FLAC__bool preserve_modtime, FLAC__bool scan); -static FLAC__bool do_shorthand_operation__add_padding(const char *filename, FLAC__Metadata_Chain *chain, unsigned length, FLAC__bool *needs_write); - -static FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetadata *block, unsigned block_number); -static void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned block_number, FLAC__bool raw, FLAC__bool hexdump_application); -static void write_metadata_binary(FLAC__StreamMetadata *block, FLAC__byte *block_raw, FLAC__bool headerless); - -/* from operations_shorthand_seektable.c */ -extern FLAC__bool do_shorthand_operation__add_seekpoints(const char *filename, FLAC__Metadata_Chain *chain, const char *specification, FLAC__bool *needs_write); - -/* from operations_shorthand_streaminfo.c */ -extern FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write); - -/* from operations_shorthand_vorbiscomment.c */ -extern FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write, FLAC__bool raw); - -/* from operations_shorthand_cuesheet.c */ -extern FLAC__bool do_shorthand_operation__cuesheet(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write); - -/* from operations_shorthand_picture.c */ -extern FLAC__bool do_shorthand_operation__picture(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write); - - -FLAC__bool do_operations(const CommandLineOptions *options) -{ - FLAC__bool ok = true; - - if(options->show_long_help) { - long_usage(0); - } - if(options->show_version) { - show_version(); - } - else if(options->args.checks.num_major_ops > 0) { - FLAC__ASSERT(options->args.checks.num_shorthand_ops == 0); - FLAC__ASSERT(options->args.checks.num_major_ops == 1); - FLAC__ASSERT(options->args.checks.num_major_ops == options->ops.num_operations); - ok = do_major_operation(options); - } - else if(options->args.checks.num_shorthand_ops > 0) { - FLAC__ASSERT(options->args.checks.num_shorthand_ops == options->ops.num_operations); - ok = do_shorthand_operations(options); - } - - return ok; -} - -/* - * local routines - */ - -void show_version(void) -{ - printf("metaflac %s\n", FLAC__VERSION_STRING); -} - -FLAC__bool do_major_operation(const CommandLineOptions *options) -{ - unsigned i; - FLAC__bool ok = true; - - /* to die after first error, v--- add '&& ok' here */ - for(i = 0; i < options->num_files; i++) - ok &= do_major_operation_on_file(options->filenames[i], options); - - return ok; -} - -FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOptions *options) -{ - FLAC__bool ok = true, needs_write = false, is_ogg = false; - FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new(); - - if(0 == chain) - die("out of memory allocating chain"); - - /*@@@@ lame way of guessing the file type */ - if(strlen(filename) >= 4 && (0 == strcmp(filename+strlen(filename)-4, ".oga") || 0 == strcmp(filename+strlen(filename)-4, ".ogg"))) - is_ogg = true; - - if(! (is_ogg? FLAC__metadata_chain_read_ogg(chain, filename) : FLAC__metadata_chain_read(chain, filename)) ) { - print_error_with_chain_status(chain, "%s: ERROR: reading metadata", filename); - FLAC__metadata_chain_delete(chain); - return false; - } - - switch(options->ops.operations[0].type) { - case OP__LIST: - ok = do_major_operation__list(options->prefix_with_filename? filename : 0, chain, options); - break; - case OP__APPEND: - ok = do_major_operation__append(chain, options); - needs_write = true; - break; - case OP__REMOVE: - ok = do_major_operation__remove(chain, options); - needs_write = true; - break; - case OP__REMOVE_ALL: - ok = do_major_operation__remove_all(chain, options); - needs_write = true; - break; - case OP__MERGE_PADDING: - FLAC__metadata_chain_merge_padding(chain); - needs_write = true; - break; - case OP__SORT_PADDING: - FLAC__metadata_chain_sort_padding(chain); - needs_write = true; - break; - default: - FLAC__ASSERT(0); - return false; - } - - if(ok && needs_write) { - if(options->use_padding) - FLAC__metadata_chain_sort_padding(chain); - ok = FLAC__metadata_chain_write(chain, options->use_padding, options->preserve_modtime); - if(!ok) - print_error_with_chain_status(chain, "%s: ERROR: writing FLAC file", filename); - } - - FLAC__metadata_chain_delete(chain); - - return ok; -} - -FLAC__bool do_major_operation__list(const char *filename, FLAC__Metadata_Chain *chain, const CommandLineOptions *options) -{ - FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); - FLAC__StreamMetadata *block; - FLAC__bool ok = true; - unsigned block_number; - - if(0 == iterator) - die("out of memory allocating iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - block_number = 0; - do { - block = FLAC__metadata_iterator_get_block(iterator); - ok &= (0 != block); - if(!ok) - flac_fprintf(stderr, "%s: ERROR: couldn't get block from chain\n", filename); - else if(passes_filter(options, FLAC__metadata_iterator_get_block(iterator), block_number)) { - if(!options->data_format_is_binary && !options->data_format_is_binary_headerless) - write_metadata(filename, block, block_number, !options->utf8_convert, options->application_data_format_is_hexdump); - else { - FLAC__byte * block_raw = FLAC__metadata_object_get_raw(block); - if(block_raw == 0) { - flac_fprintf(stderr, "%s: ERROR: couldn't get block in raw form\n", filename); - FLAC__metadata_iterator_delete(iterator); - return false; - } - write_metadata_binary(block, block_raw, options->data_format_is_binary_headerless); - free(block_raw); - } - } - block_number++; - } while(ok && FLAC__metadata_iterator_next(iterator)); - - FLAC__metadata_iterator_delete(iterator); - - return ok; -} - -FLAC__bool do_major_operation__append(FLAC__Metadata_Chain *chain, const CommandLineOptions *options) -{ - FLAC__byte header[FLAC__STREAM_METADATA_HEADER_LENGTH]; - FLAC__byte *buffer; - FLAC__uint32 buffer_size, num_objects = 0, i, append_after = UINT32_MAX; - FLAC__StreamMetadata *object; - FLAC__Metadata_Iterator *iterator = 0; - FLAC__bool has_vorbiscomment = false; - - /* First, find out after which block appending should take place */ - for(i = 0; i < options->args.num_arguments; i++) { - if(options->args.arguments[i].type == ARG__BLOCK_NUMBER) { - if(append_after != UINT32_MAX || options->args.arguments[i].value.block_number.num_entries > 1) { - flac_fprintf(stderr, "ERROR: more than one block number specified with --append\n"); - return false; - } - append_after = options->args.arguments[i].value.block_number.entries[0]; - } - } - - iterator = FLAC__metadata_iterator_new(); - - if(0 == iterator) - die("out of memory allocating iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - /* Find out whether there is already a vorbis comment block present */ - do { - FLAC__MetadataType type = FLAC__metadata_iterator_get_block_type(iterator); - if(type == FLAC__METADATA_TYPE_VORBIS_COMMENT) - has_vorbiscomment = true; - } - while(FLAC__metadata_iterator_next(iterator)); - - /* Reset iterator */ - FLAC__metadata_iterator_init(iterator, chain); - - /* Go to requested block */ - for(i = 0; i < append_after; i++) { - if(!FLAC__metadata_iterator_next(iterator)) - break; - } - -#ifdef _WIN32 - _setmode(fileno(stdin),_O_BINARY); -#endif - - /* Read header from stdin */ - while(fread(header, 1, FLAC__STREAM_METADATA_HEADER_LENGTH, stdin) == FLAC__STREAM_METADATA_HEADER_LENGTH) { - - buffer_size = ((FLAC__uint32)(header[1]) << 16) + ((FLAC__uint32)(header[2]) << 8) + header[3]; - buffer = safe_malloc_(buffer_size + FLAC__STREAM_METADATA_HEADER_LENGTH); - if(0 == buffer) - die("out of memory allocating read buffer"); - memcpy(buffer, header, FLAC__STREAM_METADATA_HEADER_LENGTH); - - num_objects++; - - if(fread(buffer+FLAC__STREAM_METADATA_HEADER_LENGTH, 1, buffer_size, stdin) < buffer_size) { - flac_fprintf(stderr, "ERROR: couldn't read metadata block #%u from stdin\n",(num_objects)); - free(buffer); - FLAC__metadata_iterator_delete(iterator); - return false; - } - - if((object = FLAC__metadata_object_set_raw(buffer, buffer_size + FLAC__STREAM_METADATA_HEADER_LENGTH)) == NULL) { - flac_fprintf(stderr, "ERROR: couldn't parse supplied metadata block #%u\n",(num_objects)); - free(buffer); - FLAC__metadata_iterator_delete(iterator); - return false; - } - free(buffer); - - if(has_vorbiscomment && object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { - flac_fprintf(stderr, "ERROR: can't add another vorbis comment block to file, it already has one\n"); - FLAC__metadata_object_delete(object); - FLAC__metadata_iterator_delete(iterator); - return false; - } - - - if(object->type == FLAC__METADATA_TYPE_STREAMINFO) { - flac_fprintf(stderr, "ERROR: can't add streaminfo to file\n"); - FLAC__metadata_object_delete(object); - FLAC__metadata_iterator_delete(iterator); - return false; - } - - if(object->type == FLAC__METADATA_TYPE_SEEKTABLE) { - flac_fprintf(stderr, "ERROR: can't add seektable to file, please use --add-seekpoint instead\n"); - FLAC__metadata_object_delete(object); - FLAC__metadata_iterator_delete(iterator); - return false; - } - - if(!FLAC__metadata_iterator_insert_block_after(iterator, object)) { - flac_fprintf(stderr, "ERROR: couldn't add supplied metadata block #%u to file\n",(num_objects)); - FLAC__metadata_object_delete(object); - FLAC__metadata_iterator_delete(iterator); - return false; - } - /* Now check whether what type of block was added */ - { - FLAC__MetadataType type = FLAC__metadata_iterator_get_block_type(iterator); - if(type == FLAC__METADATA_TYPE_VORBIS_COMMENT) - has_vorbiscomment = true; - } - } - -#ifdef _WIN32 - _setmode(fileno(stdin),_O_TEXT); -#endif - - if(num_objects == 0) - flac_fprintf(stderr, "ERROR: unable to find a metadata block in the supplied input\n"); - - FLAC__metadata_iterator_delete(iterator); - - return true; -} - -FLAC__bool do_major_operation__remove(FLAC__Metadata_Chain *chain, const CommandLineOptions *options) -{ - FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); - FLAC__bool ok = true; - unsigned block_number; - - if(0 == iterator) - die("out of memory allocating iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - block_number = 0; - while(ok && FLAC__metadata_iterator_next(iterator)) { - block_number++; - if(passes_filter(options, FLAC__metadata_iterator_get_block(iterator), block_number)) { - ok &= FLAC__metadata_iterator_delete_block(iterator, options->use_padding); - if(options->use_padding) - ok &= FLAC__metadata_iterator_next(iterator); - } - } - - FLAC__metadata_iterator_delete(iterator); - - return ok; -} - -FLAC__bool do_major_operation__remove_all(FLAC__Metadata_Chain *chain, const CommandLineOptions *options) -{ - FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); - FLAC__bool ok = true; - - if(0 == iterator) - die("out of memory allocating iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - while(ok && FLAC__metadata_iterator_next(iterator)) { - ok &= FLAC__metadata_iterator_delete_block(iterator, options->use_padding); - if(options->use_padding) - ok &= FLAC__metadata_iterator_next(iterator); - } - - FLAC__metadata_iterator_delete(iterator); - - return ok; -} - -FLAC__bool do_shorthand_operations(const CommandLineOptions *options) -{ - unsigned i; - FLAC__bool ok = true; - - /* to die after first error, v--- add '&& ok' here */ - for(i = 0; i < options->num_files; i++) - ok &= do_shorthand_operations_on_file(options->filenames[i], options); - - /* check if OP__ADD_REPLAY_GAIN requested */ - if(ok && options->num_files > 0) { - for(i = 0; i < options->ops.num_operations; i++) { - if(options->ops.operations[i].type == OP__ADD_REPLAY_GAIN) - ok = do_shorthand_operation__add_replay_gain(options->filenames, options->num_files, options->preserve_modtime, false); - else if(options->ops.operations[i].type == OP__SCAN_REPLAY_GAIN) - ok = do_shorthand_operation__add_replay_gain(options->filenames, options->num_files, options->preserve_modtime, true); - } - } - - return ok; -} - -FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLineOptions *options) -{ - unsigned i; - FLAC__bool ok = true, needs_write = false, use_padding = options->use_padding; - FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new(); - - if(0 == chain) - die("out of memory allocating chain"); - - if(!FLAC__metadata_chain_read(chain, filename)) { - print_error_with_chain_status(chain, "%s: ERROR: reading metadata", filename); - ok = false; - goto cleanup; - } - - for(i = 0; i < options->ops.num_operations && ok; i++) { - /* - * Do OP__ADD_SEEKPOINT last to avoid decoding twice if both - * --add-seekpoint and --import-cuesheet-from are used. - */ - if(options->ops.operations[i].type != OP__ADD_SEEKPOINT) - ok &= do_shorthand_operation(filename, options->prefix_with_filename, chain, &options->ops.operations[i], &needs_write, options->utf8_convert); - - /* The following seems counterintuitive but the meaning - * of 'use_padding' is 'try to keep the overall metadata - * to its original size, adding or truncating extra - * padding if necessary' which is why we need to turn it - * off in this case. If we don't, the extra padding block - * will just be truncated. - */ - if(options->ops.operations[i].type == OP__ADD_PADDING) - use_padding = false; - } - - /* - * Do OP__ADD_SEEKPOINT last to avoid decoding twice if both - * --add-seekpoint and --import-cuesheet-from are used. - */ - for(i = 0; i < options->ops.num_operations && ok; i++) { - if(options->ops.operations[i].type == OP__ADD_SEEKPOINT) - ok &= do_shorthand_operation(filename, options->prefix_with_filename, chain, &options->ops.operations[i], &needs_write, options->utf8_convert); - } - - if(ok && needs_write) { - if(use_padding) - FLAC__metadata_chain_sort_padding(chain); - ok = FLAC__metadata_chain_write(chain, use_padding, options->preserve_modtime); - if(!ok) - print_error_with_chain_status(chain, "%s: ERROR: writing FLAC file", filename); - } - - cleanup : - FLAC__metadata_chain_delete(chain); - - return ok; -} - -FLAC__bool do_shorthand_operation(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write, FLAC__bool utf8_convert) -{ - FLAC__bool ok = true; - - switch(operation->type) { - case OP__SHOW_MD5SUM: - case OP__SHOW_MIN_BLOCKSIZE: - case OP__SHOW_MAX_BLOCKSIZE: - case OP__SHOW_MIN_FRAMESIZE: - case OP__SHOW_MAX_FRAMESIZE: - case OP__SHOW_SAMPLE_RATE: - case OP__SHOW_CHANNELS: - case OP__SHOW_BPS: - case OP__SHOW_TOTAL_SAMPLES: - case OP__SET_MD5SUM: - case OP__SET_MIN_BLOCKSIZE: - case OP__SET_MAX_BLOCKSIZE: - case OP__SET_MIN_FRAMESIZE: - case OP__SET_MAX_FRAMESIZE: - case OP__SET_SAMPLE_RATE: - case OP__SET_CHANNELS: - case OP__SET_BPS: - case OP__SET_TOTAL_SAMPLES: - ok = do_shorthand_operation__streaminfo(filename, prefix_with_filename, chain, operation, needs_write); - break; - case OP__SHOW_VC_VENDOR: - case OP__SHOW_VC_FIELD: - case OP__REMOVE_VC_ALL: - case OP__REMOVE_VC_ALL_EXCEPT: - case OP__REMOVE_VC_FIELD: - case OP__REMOVE_VC_FIRSTFIELD: - case OP__SET_VC_FIELD: - case OP__IMPORT_VC_FROM: - case OP__EXPORT_VC_TO: - ok = do_shorthand_operation__vorbis_comment(filename, prefix_with_filename, chain, operation, needs_write, !utf8_convert); - break; - case OP__IMPORT_CUESHEET_FROM: - case OP__EXPORT_CUESHEET_TO: - ok = do_shorthand_operation__cuesheet(filename, chain, operation, needs_write); - break; - case OP__IMPORT_PICTURE_FROM: - case OP__EXPORT_PICTURE_TO: - ok = do_shorthand_operation__picture(filename, chain, operation, needs_write); - break; - case OP__ADD_SEEKPOINT: - ok = do_shorthand_operation__add_seekpoints(filename, chain, operation->argument.add_seekpoint.specification, needs_write); - break; - case OP__ADD_REPLAY_GAIN: - case OP__SCAN_REPLAY_GAIN: - /* these commands are always executed last */ - ok = true; - break; - case OP__ADD_PADDING: - ok = do_shorthand_operation__add_padding(filename, chain, operation->argument.add_padding.length, needs_write); - break; - default: - ok = false; - FLAC__ASSERT(0); - break; - }; - - return ok; -} - -FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned num_files, FLAC__bool preserve_modtime, FLAC__bool scan) -{ - FLAC__StreamMetadata streaminfo; - float *title_gains = 0, *title_peaks = 0; - float album_gain, album_peak; - unsigned sample_rate = 0; - unsigned bits_per_sample = 0; - unsigned channels = 0; - unsigned i; - const char *error; - FLAC__bool first = true; - - FLAC__ASSERT(num_files > 0); - - for(i = 0; i < num_files; i++) { - FLAC__ASSERT(0 != filenames[i]); - if(!FLAC__metadata_get_streaminfo(filenames[i], &streaminfo)) { - flac_fprintf(stderr, "%s: ERROR: can't open file or get STREAMINFO block\n", filenames[i]); - return false; - } - if(first) { - first = false; - sample_rate = streaminfo.data.stream_info.sample_rate; - bits_per_sample = streaminfo.data.stream_info.bits_per_sample; - channels = streaminfo.data.stream_info.channels; - } - else { - if(sample_rate != streaminfo.data.stream_info.sample_rate) { - flac_fprintf(stderr, "%s: ERROR: sample rate of %u Hz does not match previous files' %u Hz\n", filenames[i], streaminfo.data.stream_info.sample_rate, sample_rate); - return false; - } - if(bits_per_sample != streaminfo.data.stream_info.bits_per_sample) { - flac_fprintf(stderr, "%s: ERROR: resolution of %u bps does not match previous files' %u bps\n", filenames[i], streaminfo.data.stream_info.bits_per_sample, bits_per_sample); - return false; - } - if(channels != streaminfo.data.stream_info.channels) { - flac_fprintf(stderr, "%s: ERROR: # channels (%u) does not match previous files' (%u)\n", filenames[i], streaminfo.data.stream_info.channels, channels); - return false; - } - } - if(!grabbag__replaygain_is_valid_sample_frequency(sample_rate)) { - flac_fprintf(stderr, "%s: ERROR: sample rate of %u Hz is not supported\n", filenames[i], sample_rate); - return false; - } - if(channels != 1 && channels != 2) { - flac_fprintf(stderr, "%s: ERROR: # of channels (%u) is not supported, must be 1 or 2\n", filenames[i], channels); - return false; - } - if(bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || bits_per_sample > FLAC__MAX_BITS_PER_SAMPLE) { - flac_fprintf(stderr, "%s: ERROR: resolution (%u) is not supported, must be between %u and %u\n", filenames[i], bits_per_sample, FLAC__MIN_BITS_PER_SAMPLE, FLAC__MAX_BITS_PER_SAMPLE); - return false; - } - } - - if(!grabbag__replaygain_init(sample_rate)) { - FLAC__ASSERT(0); - /* double protection */ - flac_fprintf(stderr, "internal error\n"); - return false; - } - - if( - 0 == (title_gains = safe_malloc_mul_2op_(sizeof(float), /*times*/num_files)) || - 0 == (title_peaks = safe_malloc_mul_2op_(sizeof(float), /*times*/num_files)) - ) - die("out of memory allocating space for title gains/peaks"); - - for(i = 0; i < num_files; i++) { - if(0 != (error = grabbag__replaygain_analyze_file(filenames[i], title_gains+i, title_peaks+i))) { - flac_fprintf(stderr, "%s: ERROR: during analysis (%s)\n", filenames[i], error); - free(title_gains); - free(title_peaks); - return false; - } - } - grabbag__replaygain_get_album(&album_gain, &album_peak); - - for(i = 0; i < num_files; i++) { - if(!scan) { - if(0 != (error = grabbag__replaygain_store_to_file(filenames[i], album_gain, album_peak, title_gains[i], title_peaks[i], preserve_modtime))) { - flac_fprintf(stderr, "%s: ERROR: writing tags (%s)\n", filenames[i], error); - free(title_gains); - free(title_peaks); - return false; - } - } else { - flac_fprintf(stdout, "%s: %f %f %f %f\n", filenames[i], album_gain, album_peak, title_gains[i], title_peaks[i]); - } - } - - free(title_gains); - free(title_peaks); - return true; -} - -FLAC__bool do_shorthand_operation__add_padding(const char *filename, FLAC__Metadata_Chain *chain, unsigned length, FLAC__bool *needs_write) -{ - FLAC__StreamMetadata *padding = 0; - FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); - - if(0 == iterator) - die("out of memory allocating iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - while(FLAC__metadata_iterator_next(iterator)) - ; - - padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING); - if(0 == padding) - die("out of memory allocating PADDING block"); - - padding->length = length; - - if(!FLAC__metadata_iterator_insert_block_after(iterator, padding)) { - print_error_with_chain_status(chain, "%s: ERROR: adding new PADDING block to metadata", filename); - FLAC__metadata_object_delete(padding); - FLAC__metadata_iterator_delete(iterator); - return false; - } - - FLAC__metadata_iterator_delete(iterator); - *needs_write = true; - return true; -} - -FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetadata *block, unsigned block_number) -{ - unsigned i, j; - FLAC__bool matches_number = false, matches_type = false; - FLAC__bool has_block_number_arg = false; - - for(i = 0; i < options->args.num_arguments; i++) { - if(options->args.arguments[i].type == ARG__BLOCK_TYPE || options->args.arguments[i].type == ARG__EXCEPT_BLOCK_TYPE) { - for(j = 0; j < options->args.arguments[i].value.block_type.num_entries; j++) { - if(options->args.arguments[i].value.block_type.entries[j].type == block->type) { - if(block->type != FLAC__METADATA_TYPE_APPLICATION || !options->args.arguments[i].value.block_type.entries[j].filter_application_by_id || 0 == memcmp(options->args.arguments[i].value.block_type.entries[j].application_id, block->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)) - matches_type = true; - } - } - } - else if(options->args.arguments[i].type == ARG__BLOCK_NUMBER) { - has_block_number_arg = true; - for(j = 0; j < options->args.arguments[i].value.block_number.num_entries; j++) { - if(options->args.arguments[i].value.block_number.entries[j] == block_number) - matches_number = true; - } - } - } - - if(!has_block_number_arg) - matches_number = true; - - if(options->args.checks.has_block_type) { - FLAC__ASSERT(!options->args.checks.has_except_block_type); - } - else if(options->args.checks.has_except_block_type) - matches_type = !matches_type; - else - matches_type = true; - - return matches_number && matches_type; -} - -void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned block_number, FLAC__bool raw, FLAC__bool hexdump_application) -{ - unsigned i, j; - -/*@@@ yuck, should do this with a varargs function or something: */ -#define PPR if(filename) { if(raw) printf("%s:",filename); else flac_printf("%s:",filename); } - PPR; printf("METADATA block #%u\n", block_number); - PPR; printf(" type: %u (%s)\n", (unsigned)block->type, block->type < FLAC__METADATA_TYPE_UNDEFINED? FLAC__MetadataTypeString[block->type] : "UNKNOWN"); - PPR; printf(" is last: %s\n", block->is_last? "true":"false"); - PPR; printf(" length: %u\n", block->length); - - switch(block->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - PPR; printf(" minimum blocksize: %u samples\n", block->data.stream_info.min_blocksize); - PPR; printf(" maximum blocksize: %u samples\n", block->data.stream_info.max_blocksize); - PPR; printf(" minimum framesize: %u bytes\n", block->data.stream_info.min_framesize); - PPR; printf(" maximum framesize: %u bytes\n", block->data.stream_info.max_framesize); - PPR; printf(" sample_rate: %u Hz\n", block->data.stream_info.sample_rate); - PPR; printf(" channels: %u\n", block->data.stream_info.channels); - PPR; printf(" bits-per-sample: %u\n", block->data.stream_info.bits_per_sample); - PPR; printf(" total samples: %" PRIu64 "\n", block->data.stream_info.total_samples); - PPR; printf(" MD5 signature: "); - for(i = 0; i < 16; i++) { - printf("%02x", (unsigned)block->data.stream_info.md5sum[i]); - } - printf("\n"); - break; - case FLAC__METADATA_TYPE_PADDING: - /* nothing to print */ - break; - case FLAC__METADATA_TYPE_APPLICATION: - PPR; printf(" application ID: "); - for(i = 0; i < 4; i++) - printf("%02x", block->data.application.id[i]); - printf("\n"); - PPR; printf(" data contents:\n"); - if(0 != block->data.application.data) { - if(hexdump_application) - hexdump(filename, block->data.application.data, block->length - FLAC__STREAM_METADATA_HEADER_LENGTH, " "); - else - (void) local_fwrite(block->data.application.data, 1, block->length - FLAC__STREAM_METADATA_HEADER_LENGTH, stdout); - } - break; - case FLAC__METADATA_TYPE_SEEKTABLE: - PPR; printf(" seek points: %u\n", block->data.seek_table.num_points); - for(i = 0; i < block->data.seek_table.num_points; i++) { - if(block->data.seek_table.points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) { - PPR; printf(" point %u: sample_number=%" PRIu64 ", stream_offset=%" PRIu64 ", frame_samples=%u\n", i, block->data.seek_table.points[i].sample_number, block->data.seek_table.points[i].stream_offset, block->data.seek_table.points[i].frame_samples); - } - else { - PPR; printf(" point %u: PLACEHOLDER\n", i); - } - } - break; - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - PPR; printf(" vendor string: "); - write_vc_field(0, &block->data.vorbis_comment.vendor_string, raw, stdout); - PPR; printf(" comments: %u\n", block->data.vorbis_comment.num_comments); - for(i = 0; i < block->data.vorbis_comment.num_comments; i++) { - PPR; printf(" comment[%u]: ", i); - write_vc_field(0, &block->data.vorbis_comment.comments[i], raw, stdout); - } - break; - case FLAC__METADATA_TYPE_CUESHEET: - PPR; printf(" media catalog number: %s\n", block->data.cue_sheet.media_catalog_number); - PPR; printf(" lead-in: %" PRIu64 "\n", block->data.cue_sheet.lead_in); - PPR; printf(" is CD: %s\n", block->data.cue_sheet.is_cd? "true":"false"); - PPR; printf(" number of tracks: %u\n", block->data.cue_sheet.num_tracks); - for(i = 0; i < block->data.cue_sheet.num_tracks; i++) { - const FLAC__StreamMetadata_CueSheet_Track *track = block->data.cue_sheet.tracks+i; - const FLAC__bool is_last = (i == block->data.cue_sheet.num_tracks-1); - const FLAC__bool is_leadout = is_last && track->num_indices == 0; - PPR; printf(" track[%u]\n", i); - PPR; printf(" offset: %" PRIu64 "\n", track->offset); - if(is_last) { - PPR; printf(" number: %u (%s)\n", (unsigned)track->number, is_leadout? "LEAD-OUT" : "INVALID"); - } - else { - PPR; printf(" number: %u\n", (unsigned)track->number); - } - if(!is_leadout) { - PPR; printf(" ISRC: %s\n", track->isrc); - PPR; printf(" type: %s\n", track->type == 1? "DATA" : "AUDIO"); - PPR; printf(" pre-emphasis: %s\n", track->pre_emphasis? "true":"false"); - PPR; printf(" number of index points: %u\n", track->num_indices); - for(j = 0; j < track->num_indices; j++) { - const FLAC__StreamMetadata_CueSheet_Index *indx = track->indices+j; - PPR; printf(" index[%u]\n", j); - PPR; printf(" offset: %" PRIu64 "\n", indx->offset); - PPR; printf(" number: %u\n", (unsigned)indx->number); - } - } - } - break; - case FLAC__METADATA_TYPE_PICTURE: - PPR; printf(" type: %u (%s)\n", block->data.picture.type, block->data.picture.type < FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED? FLAC__StreamMetadata_Picture_TypeString[block->data.picture.type] : "UNDEFINED"); - PPR; printf(" MIME type: %s\n", block->data.picture.mime_type); - PPR; printf(" description: %s\n", block->data.picture.description); - PPR; printf(" width: %u\n", (unsigned)block->data.picture.width); - PPR; printf(" height: %u\n", (unsigned)block->data.picture.height); - PPR; printf(" depth: %u\n", (unsigned)block->data.picture.depth); - PPR; printf(" colors: %u%s\n", (unsigned)block->data.picture.colors, block->data.picture.colors? "" : " (unindexed)"); - PPR; printf(" data length: %u\n", (unsigned)block->data.picture.data_length); - PPR; printf(" data:\n"); - if(0 != block->data.picture.data) - hexdump(filename, block->data.picture.data, block->data.picture.data_length, " "); - break; - default: - PPR; printf(" data contents:\n"); - if(0 != block->data.unknown.data) - hexdump(filename, block->data.unknown.data, block->length, " "); - break; - } -#undef PPR -} - -void write_metadata_binary(FLAC__StreamMetadata *block, FLAC__byte *block_raw, FLAC__bool headerless) -{ -#ifdef _WIN32 - fflush(stdout); - _setmode(fileno(stdout),_O_BINARY); -#endif - if(!headerless) - local_fwrite(block_raw, 1, block->length+FLAC__STREAM_METADATA_HEADER_LENGTH, stdout); - else if(block->type == FLAC__METADATA_TYPE_APPLICATION && block->length > 3) - local_fwrite(block_raw+FLAC__STREAM_METADATA_HEADER_LENGTH+4, 1, block->length-4, stdout); - else - local_fwrite(block_raw+FLAC__STREAM_METADATA_HEADER_LENGTH, 1, block->length, stdout); -#ifdef _WIN32 - fflush(stdout); - _setmode(fileno(stdout),_O_TEXT); -#endif -} diff --git a/flac/src/metaflac/operations.h b/flac/src/metaflac/operations.h deleted file mode 100644 index 79e1c3b..0000000 --- a/flac/src/metaflac/operations.h +++ /dev/null @@ -1,27 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 metaflac__operations_h -#define metaflac__operations_h - -#include "options.h" - -FLAC__bool do_operations(const CommandLineOptions *options); - -#endif diff --git a/flac/src/metaflac/operations_shorthand.h b/flac/src/metaflac/operations_shorthand.h deleted file mode 100644 index 1877c26..0000000 --- a/flac/src/metaflac/operations_shorthand.h +++ /dev/null @@ -1,26 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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. - */ - -#include "options.h" - -FLAC__bool do_shorthand_operation__picture(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write); -FLAC__bool do_shorthand_operation__cuesheet(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write); -FLAC__bool do_shorthand_operation__add_seekpoints(const char *filename, FLAC__Metadata_Chain *chain, const char *specification, FLAC__bool *needs_write); -FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write); -FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write, FLAC__bool raw); diff --git a/flac/src/metaflac/operations_shorthand_cuesheet.c b/flac/src/metaflac/operations_shorthand_cuesheet.c deleted file mode 100644 index 13c4ded..0000000 --- a/flac/src/metaflac/operations_shorthand_cuesheet.c +++ /dev/null @@ -1,226 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "options.h" -#include "utils.h" -#include "FLAC/assert.h" -#include "share/grabbag.h" -#include "share/compat.h" -#include "operations_shorthand.h" - -static FLAC__bool import_cs_from(const char *filename, FLAC__StreamMetadata **cuesheet, const char *cs_filename, FLAC__bool *needs_write, FLAC__uint64 lead_out_offset, unsigned sample_rate, FLAC__bool is_cdda, Argument_AddSeekpoint *add_seekpoint_link); -static FLAC__bool export_cs_to(const char *filename, const FLAC__StreamMetadata *cuesheet, const char *cs_filename); - -FLAC__bool do_shorthand_operation__cuesheet(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write) -{ - FLAC__bool ok = true; - FLAC__StreamMetadata *cuesheet = 0; - FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); - FLAC__uint64 lead_out_offset = 0; - FLAC__bool is_cdda = false; - unsigned sample_rate = 0; - - if(0 == iterator) - die("out of memory allocating iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - do { - FLAC__StreamMetadata *block = FLAC__metadata_iterator_get_block(iterator); - if(block->type == FLAC__METADATA_TYPE_STREAMINFO) { - lead_out_offset = block->data.stream_info.total_samples; - if(lead_out_offset == 0) { - flac_fprintf(stderr, "%s: ERROR: FLAC file must have total_samples set in STREAMINFO in order to import/export cuesheet\n", filename); - FLAC__metadata_iterator_delete(iterator); - return false; - } - sample_rate = block->data.stream_info.sample_rate; - is_cdda = (block->data.stream_info.channels == 1 || block->data.stream_info.channels == 2) && (block->data.stream_info.bits_per_sample == 16) && (sample_rate == 44100); - } - else if(block->type == FLAC__METADATA_TYPE_CUESHEET) - cuesheet = block; - } while(FLAC__metadata_iterator_next(iterator)); - - if(lead_out_offset == 0) { - flac_fprintf(stderr, "%s: ERROR: FLAC stream has no STREAMINFO block\n", filename); - FLAC__metadata_iterator_delete(iterator); - return false; - } - - if(sample_rate == 0) { - flac_fprintf(stderr, "%s: ERROR: cannot parse cuesheet when sample rate is unknown\n", filename); - FLAC__metadata_iterator_delete(iterator); - return false; - } - - switch(operation->type) { - case OP__IMPORT_CUESHEET_FROM: - if(0 != cuesheet) { - flac_fprintf(stderr, "%s: ERROR: FLAC file already has CUESHEET block\n", filename); - ok = false; - } - else { - ok = import_cs_from(filename, &cuesheet, operation->argument.import_cuesheet_from.filename, needs_write, lead_out_offset, sample_rate, is_cdda, operation->argument.import_cuesheet_from.add_seekpoint_link); - if(ok) { - /* append CUESHEET block */ - while(FLAC__metadata_iterator_next(iterator)) - ; - if(!FLAC__metadata_iterator_insert_block_after(iterator, cuesheet)) { - print_error_with_chain_status(chain, "%s: ERROR: adding new CUESHEET block to metadata", filename); - FLAC__metadata_object_delete(cuesheet); - ok = false; - } - } - } - break; - case OP__EXPORT_CUESHEET_TO: - if(0 == cuesheet) { - flac_fprintf(stderr, "%s: ERROR: FLAC file has no CUESHEET block\n", filename); - ok = false; - } - else - ok = export_cs_to(filename, cuesheet, operation->argument.filename.value); - break; - default: - ok = false; - FLAC__ASSERT(0); - break; - }; - - FLAC__metadata_iterator_delete(iterator); - return ok; -} - -/* - * local routines - */ - -FLAC__bool import_cs_from(const char *filename, FLAC__StreamMetadata **cuesheet, const char *cs_filename, FLAC__bool *needs_write, FLAC__uint64 lead_out_offset, unsigned sample_rate, FLAC__bool is_cdda, Argument_AddSeekpoint *add_seekpoint_link) -{ - FILE *f; - const char *error_message; - char **seekpoint_specification = add_seekpoint_link? &(add_seekpoint_link->specification) : 0; - unsigned last_line_read; - - if(0 == cs_filename || strlen(cs_filename) == 0) { - flac_fprintf(stderr, "%s: ERROR: empty import file name\n", filename); - return false; - } - if(0 == strcmp(cs_filename, "-")) - f = stdin; - else - f = flac_fopen(cs_filename, "r"); - - if(0 == f) { - flac_fprintf(stderr, "%s: ERROR: can't open import file %s: %s\n", filename, cs_filename, strerror(errno)); - return false; - } - - *cuesheet = grabbag__cuesheet_parse(f, &error_message, &last_line_read, sample_rate, is_cdda, lead_out_offset); - - if(f != stdin) - fclose(f); - - if(0 == *cuesheet) { - flac_fprintf(stderr, "%s: ERROR: while parsing cuesheet \"%s\" on line %u: %s\n", filename, cs_filename, last_line_read, error_message); - return false; - } - - if(!FLAC__format_cuesheet_is_legal(&(*cuesheet)->data.cue_sheet, /*check_cd_da_subset=*/false, &error_message)) { - flac_fprintf(stderr, "%s: ERROR parsing cuesheet \"%s\": %s\n", filename, cs_filename, error_message); - FLAC__metadata_object_delete(*cuesheet); - return false; - } - - /* if we're expecting CDDA, warn about non-compliance */ - if(is_cdda && !FLAC__format_cuesheet_is_legal(&(*cuesheet)->data.cue_sheet, /*check_cd_da_subset=*/true, &error_message)) { - flac_fprintf(stderr, "%s: WARNING cuesheet \"%s\" is not audio CD compliant: %s\n", filename, cs_filename, error_message); - (*cuesheet)->data.cue_sheet.is_cd = false; - } - - /* add seekpoints for each index point if required */ - if(0 != seekpoint_specification) { - char spec[128]; - unsigned track, indx; - const FLAC__StreamMetadata_CueSheet *cs = &(*cuesheet)->data.cue_sheet; - if(0 == *seekpoint_specification) - *seekpoint_specification = local_strdup(""); - for(track = 0; track < cs->num_tracks; track++) { - const FLAC__StreamMetadata_CueSheet_Track *tr = cs->tracks+track; - for(indx = 0; indx < tr->num_indices; indx++) { - flac_snprintf(spec, sizeof (spec), "%" PRIu64 ";", (tr->offset + tr->indices[indx].offset)); - local_strcat(seekpoint_specification, spec); - } - } - } - - *needs_write = true; - return true; -} - -FLAC__bool export_cs_to(const char *filename, const FLAC__StreamMetadata *cuesheet, const char *cs_filename) -{ - FILE *f; - char *ref = 0; - size_t reflen; - - if(0 == cs_filename || strlen(cs_filename) == 0) { - flac_fprintf(stderr, "%s: ERROR: empty export file name\n", filename); - return false; - } - if(0 == strcmp(cs_filename, "-")) - f = stdout; - else - f = flac_fopen(cs_filename, "w"); - - if(0 == f) { - flac_fprintf(stderr, "%s: ERROR: can't open export file %s: %s\n", filename, cs_filename, strerror(errno)); - return false; - } - - reflen = strlen(filename) + 7 + 1; - if(0 == (ref = malloc(reflen))) { - flac_fprintf(stderr, "%s: ERROR: allocating memory\n", filename); - if(f != stdout) - fclose(f); - return false; - } - - flac_snprintf(ref, reflen, "\"%s\" FLAC", filename); - - grabbag__cuesheet_emit(f, cuesheet, ref); - - free(ref); - - if(f != stdout) - fclose(f); -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* Delete output file when fuzzing */ - if(f != stdout) - flac_unlink(cs_filename); -#endif - - return true; -} diff --git a/flac/src/metaflac/operations_shorthand_picture.c b/flac/src/metaflac/operations_shorthand_picture.c deleted file mode 100644 index 6bb459b..0000000 --- a/flac/src/metaflac/operations_shorthand_picture.c +++ /dev/null @@ -1,184 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "options.h" -#include "utils.h" -#include "FLAC/assert.h" -#include "share/grabbag.h" /* for grabbag__picture_parse_specification() etc */ - -#include "operations_shorthand.h" - -static FLAC__bool import_pic_from(const char *filename, FLAC__StreamMetadata **picture, const char *specification, FLAC__bool *needs_write); -static FLAC__bool export_pic_to(const char *filename, const FLAC__StreamMetadata *picture, const char *pic_filename); - -FLAC__bool do_shorthand_operation__picture(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write) -{ - FLAC__bool ok = true, has_type1 = false, has_type2 = false; - FLAC__StreamMetadata *picture = 0; - FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); - - if(0 == iterator) - die("out of memory allocating iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - switch(operation->type) { - case OP__IMPORT_PICTURE_FROM: - ok = import_pic_from(filename, &picture, operation->argument.specification.value, needs_write); - if(ok) { - /* append PICTURE block */ - while(FLAC__metadata_iterator_next(iterator)) - ; - if(!FLAC__metadata_iterator_insert_block_after(iterator, picture)) { - print_error_with_chain_status(chain, "%s: ERROR: adding new PICTURE block to metadata", filename); - FLAC__metadata_object_delete(picture); - ok = false; - } - } - if(ok) { - /* check global PICTURE constraints (max 1 block each of type=1 and type=2) */ - while(FLAC__metadata_iterator_prev(iterator)) - ; - do { - FLAC__StreamMetadata *block = FLAC__metadata_iterator_get_block(iterator); - if(block->type == FLAC__METADATA_TYPE_PICTURE) { - if(block->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) { - if(has_type1) { - print_error_with_chain_status(chain, "%s: ERROR: FLAC stream can only have one 32x32 standard icon (type=1) PICTURE block", filename); - ok = false; - } - has_type1 = true; - } - else if(block->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) { - if(has_type2) { - print_error_with_chain_status(chain, "%s: ERROR: FLAC stream can only have one icon (type=2) PICTURE block", filename); - ok = false; - } - has_type2 = true; - } - } - } while(FLAC__metadata_iterator_next(iterator)); - } - break; - case OP__EXPORT_PICTURE_TO: - { - const Argument_BlockNumber *a = operation->argument.export_picture_to.block_number_link; - int block_number = (a && a->num_entries > 0)? (int)a->entries[0] : -1; - unsigned i = 0; - do { - FLAC__StreamMetadata *block = FLAC__metadata_iterator_get_block(iterator); - if(block->type == FLAC__METADATA_TYPE_PICTURE && (block_number < 0 || i == (unsigned)block_number)) - picture = block; - i++; - } while(FLAC__metadata_iterator_next(iterator) && 0 == picture); - if(0 == picture) { - if(block_number < 0) - flac_fprintf(stderr, "%s: ERROR: FLAC file has no PICTURE block\n", filename); - else - flac_fprintf(stderr, "%s: ERROR: FLAC file has no PICTURE block at block #%d\n", filename, block_number); - ok = false; - } - else - ok = export_pic_to(filename, picture, operation->argument.filename.value); - } - break; - default: - ok = false; - FLAC__ASSERT(0); - break; - }; - - FLAC__metadata_iterator_delete(iterator); - return ok; -} - -/* - * local routines - */ - -FLAC__bool import_pic_from(const char *filename, FLAC__StreamMetadata **picture, const char *specification, FLAC__bool *needs_write) -{ - const char *error_message; - - if(0 == specification || strlen(specification) == 0) { - flac_fprintf(stderr, "%s: ERROR: empty picture specification\n", filename); - return false; - } - - *picture = grabbag__picture_parse_specification(specification, &error_message); - - if(0 == *picture) { - flac_fprintf(stderr, "%s: ERROR: while parsing picture specification \"%s\": %s\n", filename, specification, error_message); - return false; - } - - if(!FLAC__format_picture_is_legal(&(*picture)->data.picture, &error_message)) { - flac_fprintf(stderr, "%s: ERROR: new PICTURE block for \"%s\" is illegal: %s\n", filename, specification, error_message); - FLAC__metadata_object_delete(*picture); - *picture = 0; - return false; - } - - *needs_write = true; - return true; -} - -FLAC__bool export_pic_to(const char *filename, const FLAC__StreamMetadata *picture, const char *pic_filename) -{ - FILE *f; - const FLAC__uint32 len = picture->data.picture.data_length; - - if(0 == pic_filename || strlen(pic_filename) == 0) { - flac_fprintf(stderr, "%s: ERROR: empty export file name\n", filename); - return false; - } - if(0 == strcmp(pic_filename, "-")) - f = grabbag__file_get_binary_stdout(); - else - f = flac_fopen(pic_filename, "wb"); - - if(0 == f) { - flac_fprintf(stderr, "%s: ERROR: can't open export file %s: %s\n", filename, pic_filename, strerror(errno)); - return false; - } - - if(fwrite(picture->data.picture.data, 1, len, f) != len) { - flac_fprintf(stderr, "%s: ERROR: writing PICTURE data to file\n", filename); - if(f != stdout) - fclose(f); - return false; - } - - if(f != stdout) - fclose(f); - -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* Delete output file when fuzzing */ - if(f != stdout) - flac_unlink(pic_filename); -#endif - - return true; -} diff --git a/flac/src/metaflac/operations_shorthand_seektable.c b/flac/src/metaflac/operations_shorthand_seektable.c deleted file mode 100644 index c9175b3..0000000 --- a/flac/src/metaflac/operations_shorthand_seektable.c +++ /dev/null @@ -1,220 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "utils.h" -#include "FLAC/assert.h" -#include "FLAC/stream_decoder.h" -#include "FLAC/metadata.h" -#include "share/grabbag.h" -#include "operations_shorthand.h" - -static FLAC__bool populate_seekpoint_values(const char *filename, FLAC__StreamMetadata *block, FLAC__bool *needs_write); - -FLAC__bool do_shorthand_operation__add_seekpoints(const char *filename, FLAC__Metadata_Chain *chain, const char *specification, FLAC__bool *needs_write) -{ - FLAC__bool ok = true, found_seektable_block = false; - FLAC__StreamMetadata *block = 0; - FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); - FLAC__uint64 total_samples = 0; - unsigned sample_rate = 0; - - if(0 == iterator) - die("out of memory allocating iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - do { - block = FLAC__metadata_iterator_get_block(iterator); - if(block->type == FLAC__METADATA_TYPE_STREAMINFO) { - sample_rate = block->data.stream_info.sample_rate; - total_samples = block->data.stream_info.total_samples; - } - else if(block->type == FLAC__METADATA_TYPE_SEEKTABLE) - found_seektable_block = true; - } while(!found_seektable_block && FLAC__metadata_iterator_next(iterator)); - - if(total_samples == 0) { - flac_fprintf(stderr, "%s: ERROR: cannot add seekpoints because STREAMINFO block does not specify total_samples\n", filename); - FLAC__metadata_iterator_delete(iterator); - return false; - } - - if(!found_seektable_block) { - /* create a new block */ - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE); - if(0 == block) - die("out of memory allocating SEEKTABLE block"); - while(FLAC__metadata_iterator_prev(iterator)) - ; - if(!FLAC__metadata_iterator_insert_block_after(iterator, block)) { - print_error_with_chain_status(chain, "%s: ERROR: adding new SEEKTABLE block to metadata", filename); - FLAC__metadata_object_delete(block); - FLAC__metadata_iterator_delete(iterator); - return false; - } - /* iterator is left pointing to new block */ - FLAC__ASSERT(FLAC__metadata_iterator_get_block(iterator) == block); - } - - FLAC__metadata_iterator_delete(iterator); - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_SEEKTABLE); - - if(!grabbag__seektable_convert_specification_to_template(specification, /*only_explicit_placeholders=*/false, total_samples, sample_rate, block, /*spec_has_real_points=*/0)) { - flac_fprintf(stderr, "%s: ERROR (internal) preparing seektable with seekpoints\n", filename); - return false; - } - - ok = populate_seekpoint_values(filename, block, needs_write); - - if(ok) - (void) FLAC__format_seektable_sort(&block->data.seek_table); - - return ok; -} - -/* - * local routines - */ - -typedef struct { - FLAC__StreamMetadata_SeekTable *seektable_template; - FLAC__uint64 samples_written; - FLAC__uint64 audio_offset, last_offset; - unsigned first_seekpoint_to_check; - FLAC__bool error_occurred; - FLAC__StreamDecoderErrorStatus error_status; -} ClientData; - -static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - ClientData *cd = (ClientData*)client_data; - - (void)buffer; - FLAC__ASSERT(0 != cd); - - if(!cd->error_occurred) { - const unsigned blocksize = frame->header.blocksize; - const FLAC__uint64 frame_first_sample = cd->samples_written; - const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1; - FLAC__uint64 test_sample; - unsigned i; - for(i = cd->first_seekpoint_to_check; i < cd->seektable_template->num_points; i++) { - test_sample = cd->seektable_template->points[i].sample_number; - if(test_sample > frame_last_sample) { - break; - } - else if(test_sample >= frame_first_sample) { - cd->seektable_template->points[i].sample_number = frame_first_sample; - cd->seektable_template->points[i].stream_offset = cd->last_offset - cd->audio_offset; - cd->seektable_template->points[i].frame_samples = blocksize; - cd->first_seekpoint_to_check++; - /* DO NOT: "break;" and here's why: - * The seektable template may contain more than one target - * sample for any given frame; we will keep looping, generating - * duplicate seekpoints for them, and we'll clean it up later, - * just before writing the seektable back to the metadata. - */ - } - else { - cd->first_seekpoint_to_check++; - } - } - cd->samples_written += blocksize; - if(!FLAC__stream_decoder_get_decode_position(decoder, &cd->last_offset)) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; - } - else - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; -} - -static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - ClientData *cd = (ClientData*)client_data; - - (void)decoder; - FLAC__ASSERT(0 != cd); - - if(!cd->error_occurred) { /* don't let multiple errors overwrite the first one */ - cd->error_occurred = true; - cd->error_status = status; - } -} - -FLAC__bool populate_seekpoint_values(const char *filename, FLAC__StreamMetadata *block, FLAC__bool *needs_write) -{ - FLAC__StreamDecoder *decoder; - ClientData client_data; - FLAC__bool ok = true; - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_SEEKTABLE); - - client_data.seektable_template = &block->data.seek_table; - client_data.samples_written = 0; - /* client_data.audio_offset must be determined later */ - client_data.first_seekpoint_to_check = 0; - client_data.error_occurred = false; - - decoder = FLAC__stream_decoder_new(); - - if(0 == decoder) { - flac_fprintf(stderr, "%s: ERROR (--add-seekpoint) creating the decoder instance\n", filename); - return false; - } - - FLAC__stream_decoder_set_md5_checking(decoder, false); - FLAC__stream_decoder_set_metadata_ignore_all(decoder); - - if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, /*metadata_callback=*/0, error_callback_, &client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - flac_fprintf(stderr, "%s: ERROR (--add-seekpoint) initializing the decoder instance (%s)\n", filename, FLAC__stream_decoder_get_resolved_state_string(decoder)); - ok = false; - } - - if(ok && !FLAC__stream_decoder_process_until_end_of_metadata(decoder)) { - flac_fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file (%s)\n", filename, FLAC__stream_decoder_get_resolved_state_string(decoder)); - ok = false; - } - - if(ok && !FLAC__stream_decoder_get_decode_position(decoder, &client_data.audio_offset)) { - flac_fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file\n", filename); - ok = false; - } - client_data.last_offset = client_data.audio_offset; - - if(ok && !FLAC__stream_decoder_process_until_end_of_stream(decoder)) { - flac_fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file (%s)\n", filename, FLAC__stream_decoder_get_resolved_state_string(decoder)); - ok = false; - } - - if(ok && client_data.error_occurred) { - flac_fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file (%u:%s)\n", filename, (unsigned)client_data.error_status, FLAC__StreamDecoderErrorStatusString[client_data.error_status]); - ok = false; - } - - *needs_write = true; - FLAC__stream_decoder_delete(decoder); - return ok; -} diff --git a/flac/src/metaflac/operations_shorthand_streaminfo.c b/flac/src/metaflac/operations_shorthand_streaminfo.c deleted file mode 100644 index 3219841..0000000 --- a/flac/src/metaflac/operations_shorthand_streaminfo.c +++ /dev/null @@ -1,127 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "options.h" -#include "utils.h" -#include "FLAC/assert.h" -#include "FLAC/metadata.h" -#include "share/compat.h" -#include -#include "operations_shorthand.h" - -FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write) -{ - unsigned i; - FLAC__bool ok = true; - FLAC__StreamMetadata *block; - FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); - - if(0 == iterator) - die("out of memory allocating iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - block = FLAC__metadata_iterator_get_block(iterator); - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_STREAMINFO); - - if(prefix_with_filename) - flac_printf("%s:", filename); - - switch(operation->type) { - case OP__SHOW_MD5SUM: - for(i = 0; i < 16; i++) - printf("%02x", block->data.stream_info.md5sum[i]); - printf("\n"); - break; - case OP__SHOW_MIN_BLOCKSIZE: - printf("%u\n", block->data.stream_info.min_blocksize); - break; - case OP__SHOW_MAX_BLOCKSIZE: - printf("%u\n", block->data.stream_info.max_blocksize); - break; - case OP__SHOW_MIN_FRAMESIZE: - printf("%u\n", block->data.stream_info.min_framesize); - break; - case OP__SHOW_MAX_FRAMESIZE: - printf("%u\n", block->data.stream_info.max_framesize); - break; - case OP__SHOW_SAMPLE_RATE: - printf("%u\n", block->data.stream_info.sample_rate); - break; - case OP__SHOW_CHANNELS: - printf("%u\n", block->data.stream_info.channels); - break; - case OP__SHOW_BPS: - printf("%u\n", block->data.stream_info.bits_per_sample); - break; - case OP__SHOW_TOTAL_SAMPLES: - printf("%" PRIu64 "\n", block->data.stream_info.total_samples); - break; - case OP__SET_MD5SUM: - memcpy(block->data.stream_info.md5sum, operation->argument.streaminfo_md5.value, 16); - *needs_write = true; - break; - case OP__SET_MIN_BLOCKSIZE: - block->data.stream_info.min_blocksize = operation->argument.streaminfo_uint32.value; - *needs_write = true; - break; - case OP__SET_MAX_BLOCKSIZE: - block->data.stream_info.max_blocksize = operation->argument.streaminfo_uint32.value; - *needs_write = true; - break; - case OP__SET_MIN_FRAMESIZE: - block->data.stream_info.min_framesize = operation->argument.streaminfo_uint32.value; - *needs_write = true; - break; - case OP__SET_MAX_FRAMESIZE: - block->data.stream_info.max_framesize = operation->argument.streaminfo_uint32.value; - *needs_write = true; - break; - case OP__SET_SAMPLE_RATE: - block->data.stream_info.sample_rate = operation->argument.streaminfo_uint32.value; - *needs_write = true; - break; - case OP__SET_CHANNELS: - block->data.stream_info.channels = operation->argument.streaminfo_uint32.value; - *needs_write = true; - break; - case OP__SET_BPS: - block->data.stream_info.bits_per_sample = operation->argument.streaminfo_uint32.value; - *needs_write = true; - break; - case OP__SET_TOTAL_SAMPLES: - block->data.stream_info.total_samples = operation->argument.streaminfo_uint64.value; - *needs_write = true; - break; - default: - ok = false; - FLAC__ASSERT(0); - break; - }; - - FLAC__metadata_iterator_delete(iterator); - - return ok; -} diff --git a/flac/src/metaflac/operations_shorthand_vorbiscomment.c b/flac/src/metaflac/operations_shorthand_vorbiscomment.c deleted file mode 100644 index 27c9e4c..0000000 --- a/flac/src/metaflac/operations_shorthand_vorbiscomment.c +++ /dev/null @@ -1,430 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "options.h" -#include "utils.h" -#include "FLAC/assert.h" -#include "share/grabbag.h" /* for grabbag__file_get_filesize() */ -#include "share/utf8.h" -#include -#include -#include -#include "operations_shorthand.h" -#include "share/compat.h" - -static FLAC__bool remove_vc_all(const char *filename, FLAC__StreamMetadata *block, FLAC__bool *needs_write); -static FLAC__bool remove_vc_all_except(const char *filename, FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write); -static FLAC__bool remove_vc_field(const char *filename, FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write); -static FLAC__bool remove_vc_firstfield(const char *filename, FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write); -static FLAC__bool set_vc_field(const char *filename, FLAC__StreamMetadata *block, const Argument_VcField *field, FLAC__bool *needs_write, FLAC__bool raw); -static FLAC__bool import_vc_from(const char *filename, FLAC__StreamMetadata *block, const Argument_String *vc_filename, FLAC__bool *needs_write, FLAC__bool raw); -static FLAC__bool export_vc_to(const char *filename, FLAC__StreamMetadata *block, const Argument_String *vc_filename, FLAC__bool raw); - -FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write, FLAC__bool raw) -{ - FLAC__bool ok = true, found_vc_block = false; - FLAC__StreamMetadata *block = 0; - FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); - - if(0 == iterator) - die("out of memory allocating iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - do { - block = FLAC__metadata_iterator_get_block(iterator); - if(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) - found_vc_block = true; - } while(!found_vc_block && FLAC__metadata_iterator_next(iterator)); - - if(!found_vc_block) { - /* create a new block if necessary */ - if(operation->type == OP__SET_VC_FIELD || operation->type == OP__IMPORT_VC_FROM) { - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); - if(0 == block) - die("out of memory allocating VORBIS_COMMENT block"); - while(FLAC__metadata_iterator_next(iterator)) - ; - if(!FLAC__metadata_iterator_insert_block_after(iterator, block)) { - print_error_with_chain_status(chain, "%s: ERROR: adding new VORBIS_COMMENT block to metadata", filename); - return false; - } - /* iterator is left pointing to new block */ - FLAC__ASSERT(FLAC__metadata_iterator_get_block(iterator) == block); - } - else { - FLAC__metadata_iterator_delete(iterator); - return ok; - } - } - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - switch(operation->type) { - case OP__SHOW_VC_VENDOR: - write_vc_field(prefix_with_filename? filename : 0, &block->data.vorbis_comment.vendor_string, raw, stdout); - break; - case OP__SHOW_VC_FIELD: - write_vc_fields(prefix_with_filename? filename : 0, operation->argument.vc_field_name.value, block->data.vorbis_comment.comments, block->data.vorbis_comment.num_comments, raw, stdout); - break; - case OP__REMOVE_VC_ALL: - ok = remove_vc_all(filename, block, needs_write); - break; - case OP__REMOVE_VC_ALL_EXCEPT: - ok = remove_vc_all_except(filename, block, operation->argument.vc_field_name.value, needs_write); - break; - case OP__REMOVE_VC_FIELD: - ok = remove_vc_field(filename, block, operation->argument.vc_field_name.value, needs_write); - break; - case OP__REMOVE_VC_FIRSTFIELD: - ok = remove_vc_firstfield(filename, block, operation->argument.vc_field_name.value, needs_write); - break; - case OP__SET_VC_FIELD: -#ifdef _WIN32 /* do not convert anything or things will break */ - ok = set_vc_field(filename, block, &operation->argument.vc_field, needs_write, true); -#else - ok = set_vc_field(filename, block, &operation->argument.vc_field, needs_write, raw); -#endif - break; - case OP__IMPORT_VC_FROM: - ok = import_vc_from(filename, block, &operation->argument.filename, needs_write, raw); - break; - case OP__EXPORT_VC_TO: - ok = export_vc_to(filename, block, &operation->argument.filename, raw); - break; - default: - ok = false; - FLAC__ASSERT(0); - break; - }; - - FLAC__metadata_iterator_delete(iterator); - return ok; -} - -/* - * local routines - */ - -FLAC__bool remove_vc_all(const char *filename, FLAC__StreamMetadata *block, FLAC__bool *needs_write) -{ - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(0 != needs_write); - - if(0 != block->data.vorbis_comment.comments) { - FLAC__ASSERT(block->data.vorbis_comment.num_comments > 0); - if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, 0)) { - flac_fprintf(stderr, "%s: ERROR: memory allocation failure\n", filename); - return false; - } - *needs_write = true; - } - else { - FLAC__ASSERT(block->data.vorbis_comment.num_comments == 0); - } - - return true; -} - -FLAC__bool remove_vc_all_except(const char *filename, FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write) -{ - char * field_names[200]; - uint32_t field_name_length, i; - int j, num_field_names; - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(0 != needs_write); - - field_name_length = strlen(field_name); - field_names[0] = (void *)field_name; - - for(num_field_names = 1; num_field_names < 200; num_field_names++) { - char * separator = strchr(field_names[num_field_names-1], '='); - if(separator == 0 || separator >= field_name + field_name_length) - break; - field_names[num_field_names] = separator+1; - } - - if(num_field_names > 200) { - flac_fprintf(stderr, "%s: ERROR: too many field names\n", filename); - return false; - } - - for(i = 0; i < block->data.vorbis_comment.num_comments; ) { - int field_name_found = false; - for(j = 0; j < num_field_names; j++) { - const uint32_t length = (j == (num_field_names - 1))?(uint32_t)strlen(field_names[j]):(uint32_t)(strchr(field_names[j],'=')-field_names[j]); - if(FLAC__metadata_object_vorbiscomment_entry_matches(block->data.vorbis_comment.comments[i], field_names[j], length)) { - field_name_found = true; - break; - } - } - if(!field_name_found) { - FLAC__metadata_object_vorbiscomment_delete_comment(block, i); - *needs_write = true; - } - else - i++; - } - - return true; -} - -FLAC__bool remove_vc_field(const char *filename, FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write) -{ - int n; - - FLAC__ASSERT(0 != needs_write); - - n = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, field_name); - - if(n < 0) { - flac_fprintf(stderr, "%s: ERROR: memory allocation failure\n", filename); - return false; - } - else if(n > 0) - *needs_write = true; - - return true; -} - -FLAC__bool remove_vc_firstfield(const char *filename, FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write) -{ - int n; - - FLAC__ASSERT(0 != needs_write); - - n = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, field_name); - - if(n < 0) { - flac_fprintf(stderr, "%s: ERROR: memory allocation failure\n", filename); - return false; - } - else if(n > 0) - *needs_write = true; - - return true; -} - -FLAC__bool set_vc_field(const char *filename, FLAC__StreamMetadata *block, const Argument_VcField *field, FLAC__bool *needs_write, FLAC__bool raw) -{ - FLAC__StreamMetadata_VorbisComment_Entry entry; - char *converted; - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(0 != field); - FLAC__ASSERT(0 != needs_write); - - if(field->field_value_from_file) { - /* read the file into 'data' */ - FILE *f = 0; - char *data = 0; - const FLAC__off_t size = grabbag__file_get_filesize(field->field_value); - if(size < 0) { - flac_fprintf(stderr, "%s: ERROR: can't open file '%s' for '%s' tag value\n", filename, field->field_value, field->field_name); - return false; - } - if(size >= 0x100000) { /* magic arbitrary limit, actual format limit is near 16MB */ - flac_fprintf(stderr, "%s: ERROR: file '%s' for '%s' tag value is too large\n", filename, field->field_value, field->field_name); - return false; - } - if(0 == (data = malloc(size+1))) - die("out of memory allocating tag value"); - data[size] = '\0'; - if(0 == (f = flac_fopen(field->field_value, "rb")) || fread(data, 1, size, f) != (size_t)size) { - flac_fprintf(stderr, "%s: ERROR: while reading file '%s' for '%s' tag value: %s\n", filename, field->field_value, field->field_name, strerror(errno)); - free(data); - if(f) - fclose(f); - return false; - } - fclose(f); - if(strlen(data) != (size_t)size) { - free(data); - flac_fprintf(stderr, "%s: ERROR: file '%s' for '%s' tag value has embedded NULs\n", filename, field->field_value, field->field_name); - return false; - } - - /* move 'data' into 'converted', converting to UTF-8 if necessary */ - if(raw) { - converted = data; - } - else if(utf8_encode(data, &converted) >= 0) { - free(data); - } - else { - free(data); - flac_fprintf(stderr, "%s: ERROR: converting file '%s' contents to UTF-8 for tag value\n", filename, field->field_value); - return false; - } - - /* create and entry and append it */ - if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry, field->field_name, converted)) { - free(converted); - flac_fprintf(stderr, "%s: ERROR: file '%s' for '%s' tag value is not valid UTF-8\n", filename, field->field_value, field->field_name); - return false; - } - free(converted); - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) { - flac_fprintf(stderr, "%s: ERROR: memory allocation failure\n", filename); - return false; - } - - *needs_write = true; - return true; - } - else { - FLAC__bool needs_free = false; - entry.entry = (FLAC__byte *)field->field; - if(raw) { - entry.entry = (FLAC__byte *)field->field; - } - else if(utf8_encode(field->field, &converted) >= 0) { - entry.entry = (FLAC__byte *)converted; - needs_free = true; - } - else { - flac_fprintf(stderr, "%s: ERROR: converting comment '%s' to UTF-8\n", filename, field->field); - return false; - } - entry.length = strlen((const char *)entry.entry); - if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) { - if(needs_free) - free(converted); - /* - * our previous parsing has already established that the field - * name is OK, so it must be the field value - */ - flac_fprintf(stderr, "%s: ERROR: tag value for '%s' is not valid UTF-8\n", filename, field->field_name); - return false; - } - - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) { - if(needs_free) - free(converted); - flac_fprintf(stderr, "%s: ERROR: memory allocation failure\n", filename); - return false; - } - - *needs_write = true; - if(needs_free) - free(converted); - return true; - } -} - -FLAC__bool import_vc_from(const char *filename, FLAC__StreamMetadata *block, const Argument_String *vc_filename, FLAC__bool *needs_write, FLAC__bool raw) -{ - FILE *f; - char line[65536]; - FLAC__bool ret; - - if(0 == vc_filename->value || strlen(vc_filename->value) == 0) { - flac_fprintf(stderr, "%s: ERROR: empty import file name\n", filename); - return false; - } - if(0 == strcmp(vc_filename->value, "-")) - f = stdin; - else - f = flac_fopen(vc_filename->value, "r"); - - if(0 == f) { - flac_fprintf(stderr, "%s: ERROR: can't open import file %s: %s\n", filename, vc_filename->value, strerror(errno)); - return false; - } - - ret = true; - while(ret && !feof(f) && fgets(line, sizeof(line), f) != NULL) { - if(!feof(f)) { - char *p = strchr(line, '\n'); - if(0 == p) { - flac_fprintf(stderr, "%s: ERROR: line too long, aborting\n", vc_filename->value); - ret = false; - } - else { - const char *violation; - Argument_VcField field; - *p = '\0'; - memset(&field, 0, sizeof(Argument_VcField)); - field.field_value_from_file = false; - if(!parse_vorbis_comment_field(line, &field.field, &field.field_name, &field.field_value, &field.field_value_length, &violation)) { - FLAC__ASSERT(0 != violation); - flac_fprintf(stderr, "%s: ERROR: malformed vorbis comment field \"%s\",\n %s\n", vc_filename->value, line, violation); - ret = false; - } - else { - ret = set_vc_field(filename, block, &field, needs_write, raw); - } - if(0 != field.field) - free(field.field); - if(0 != field.field_name) - free(field.field_name); - if(0 != field.field_value) - free(field.field_value); - } - } - }; - - if(f != stdin) - fclose(f); - return ret; -} - -FLAC__bool export_vc_to(const char *filename, FLAC__StreamMetadata *block, const Argument_String *vc_filename, FLAC__bool raw) -{ - FILE *f; - FLAC__bool ret; - - if(0 == vc_filename->value || strlen(vc_filename->value) == 0) { - flac_fprintf(stderr, "%s: ERROR: empty export file name\n", filename); - return false; - } - if(0 == strcmp(vc_filename->value, "-")) - f = stdout; - else - f = flac_fopen(vc_filename->value, "w"); - - if(0 == f) { - flac_fprintf(stderr, "%s: ERROR: can't open export file %s: %s\n", filename, vc_filename->value, strerror(errno)); - return false; - } - - ret = true; - - write_vc_fields(0, 0, block->data.vorbis_comment.comments, block->data.vorbis_comment.num_comments, raw, f); - - if(f != stdout) - fclose(f); - -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - /* Delete output file when fuzzing */ - if(f != stdout) - flac_unlink(vc_filename->value); -#endif - - return ret; -} diff --git a/flac/src/metaflac/options.c b/flac/src/metaflac/options.c deleted file mode 100644 index 1b4b6f6..0000000 --- a/flac/src/metaflac/options.c +++ /dev/null @@ -1,1146 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "options.h" -#include "usage.h" -#include "utils.h" -#include "FLAC/assert.h" -#include "share/alloc.h" -#include "share/compat.h" -#include "share/grabbag/replaygain.h" -#include -#include -#include -#include - -/* - share__getopt format struct; note we don't use short options so we just - set the 'val' field to 0 everywhere to indicate a valid option. -*/ -struct share__option long_options_[] = { - /* global options */ - { "preserve-modtime", 0, 0, 0 }, - { "with-filename", 0, 0, 0 }, - { "no-filename", 0, 0, 0 }, - { "no-utf8-convert", 0, 0, 0 }, - { "dont-use-padding", 0, 0, 0 }, - { "no-cued-seekpoints", 0, 0, 0 }, - /* shorthand operations */ - { "show-md5sum", 0, 0, 0 }, - { "show-min-blocksize", 0, 0, 0 }, - { "show-max-blocksize", 0, 0, 0 }, - { "show-min-framesize", 0, 0, 0 }, - { "show-max-framesize", 0, 0, 0 }, - { "show-sample-rate", 0, 0, 0 }, - { "show-channels", 0, 0, 0 }, - { "show-bps", 0, 0, 0 }, - { "show-total-samples", 0, 0, 0 }, - { "set-md5sum", 1, 0, 0 }, /* undocumented */ - { "set-min-blocksize", 1, 0, 0 }, /* undocumented */ - { "set-max-blocksize", 1, 0, 0 }, /* undocumented */ - { "set-min-framesize", 1, 0, 0 }, /* undocumented */ - { "set-max-framesize", 1, 0, 0 }, /* undocumented */ - { "set-sample-rate", 1, 0, 0 }, /* undocumented */ - { "set-channels", 1, 0, 0 }, /* undocumented */ - { "set-bps", 1, 0, 0 }, /* undocumented */ - { "set-total-samples", 1, 0, 0 }, /* undocumented */ /* WATCHOUT: used by test/test_flac.sh on windows */ - { "show-vendor-tag", 0, 0, 0 }, - { "show-all-tags", 0, 0, 0 }, - { "show-tag", 1, 0, 0 }, - { "remove-all-tags", 0, 0, 0 }, - { "remove-all-tags-except", 1, 0, 0 }, - { "remove-tag", 1, 0, 0 }, - { "remove-first-tag", 1, 0, 0 }, - { "set-tag", 1, 0, 0 }, - { "set-tag-from-file", 1, 0, 0 }, - { "import-tags-from", 1, 0, 0 }, - { "export-tags-to", 1, 0, 0 }, - { "import-cuesheet-from", 1, 0, 0 }, - { "export-cuesheet-to", 1, 0, 0 }, - { "import-picture-from", 1, 0, 0 }, - { "export-picture-to", 1, 0, 0 }, - { "add-seekpoint", 1, 0, 0 }, - { "add-replay-gain", 0, 0, 0 }, - { "scan-replay-gain", 0, 0, 0 }, - { "remove-replay-gain", 0, 0, 0 }, - { "add-padding", 1, 0, 0 }, - /* major operations */ - { "help", 0, 0, 0 }, - { "version", 0, 0, 0 }, - { "list", 0, 0, 0 }, - { "append", 0, 0, 0 }, - { "remove", 0, 0, 0 }, - { "remove-all", 0, 0, 0 }, - { "merge-padding", 0, 0, 0 }, - { "sort-padding", 0, 0, 0 }, - /* major operation arguments */ - { "block-number", 1, 0, 0 }, - { "block-type", 1, 0, 0 }, - { "except-block-type", 1, 0, 0 }, - { "data-format", 1, 0, 0 }, - { "application-data-format", 1, 0, 0 }, - { "from-file", 1, 0, 0 }, - {0, 0, 0, 0} -}; - -static FLAC__bool parse_option(int option_index, const char *option_argument, CommandLineOptions *options); -static void append_new_operation(CommandLineOptions *options, Operation operation); -static void append_new_argument(CommandLineOptions *options, Argument argument); -static Operation *append_major_operation(CommandLineOptions *options, OperationType type); -static Operation *append_shorthand_operation(CommandLineOptions *options, OperationType type); -static Argument *find_argument(CommandLineOptions *options, ArgumentType type); -static Operation *find_shorthand_operation(CommandLineOptions *options, OperationType type); -static Argument *append_argument(CommandLineOptions *options, ArgumentType type); -static FLAC__bool parse_md5(const char *src, FLAC__byte dest[16]); -static FLAC__bool parse_uint32(const char *src, FLAC__uint32 *dest); -static FLAC__bool parse_uint64(const char *src, FLAC__uint64 *dest); -static FLAC__bool parse_string(const char *src, char **dest); -static FLAC__bool parse_vorbis_comment_field_name(const char *field_ref, char **name, const char **violation); -static FLAC__bool parse_vorbis_comment_field_names(const char *field_ref, char **names, const char **violation); -static FLAC__bool parse_add_seekpoint(const char *in, char **out, const char **violation); -static FLAC__bool parse_add_padding(const char *in, unsigned *out); -static FLAC__bool parse_block_number(const char *in, Argument_BlockNumber *out); -static FLAC__bool parse_block_type(const char *in, Argument_BlockType *out); -static FLAC__bool parse_data_format(const char *in, Argument_DataFormat *out); -static FLAC__bool parse_application_data_format(const char *in, FLAC__bool *out); -static void undocumented_warning(const char *opt); - - -void init_options(CommandLineOptions *options) -{ - options->preserve_modtime = false; - - /* '2' is a hack to mean "use default if not forced on command line" */ - FLAC__ASSERT(true != 2); - options->prefix_with_filename = 2; - - options->utf8_convert = true; - options->use_padding = true; - options->cued_seekpoints = true; - options->show_long_help = false; - options->show_version = false; - options->data_format_is_binary = false; - options->data_format_is_binary_headerless = false; - options->application_data_format_is_hexdump = false; - - options->ops.operations = 0; - options->ops.num_operations = 0; - options->ops.capacity = 0; - - options->args.arguments = 0; - options->args.num_arguments = 0; - options->args.capacity = 0; - - options->args.checks.num_shorthand_ops = 0; - options->args.checks.num_major_ops = 0; - options->args.checks.has_block_type = false; - options->args.checks.has_except_block_type = false; - - options->num_files = 0; - options->filenames = 0; -} - -FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options) -{ - int ret; - int option_index = 1; - FLAC__bool had_error = false; - - while ((ret = share__getopt_long(argc, argv, "", long_options_, &option_index)) != -1) { - switch (ret) { - case 0: - had_error |= !parse_option(option_index, share__optarg, options); - break; - case '?': - case ':': - had_error = true; - break; - default: - FLAC__ASSERT(0); - break; - } - } - - if(options->prefix_with_filename == 2) - options->prefix_with_filename = (argc - share__optind > 1); - - if(share__optind >= argc && !options->show_long_help && !options->show_version) { - flac_fprintf(stderr,"ERROR: you must specify at least one FLAC file;\n"); - flac_fprintf(stderr," metaflac cannot be used as a pipe\n"); - had_error = true; - } - - options->num_files = argc - share__optind; - - if(options->num_files > 0) { - unsigned i = 0; - if(0 == (options->filenames = safe_malloc_mul_2op_(sizeof(char*), /*times*/options->num_files))) - die("out of memory allocating space for file names list"); - while(share__optind < argc) - options->filenames[i++] = local_strdup(argv[share__optind++]); - } - - if(options->args.checks.num_major_ops > 0) { - if(options->args.checks.num_major_ops > 1) { - flac_fprintf(stderr, "ERROR: you may only specify one major operation at a time\n"); - had_error = true; - } - else if(options->args.checks.num_shorthand_ops > 0) { - flac_fprintf(stderr, "ERROR: you may not mix shorthand and major operations\n"); - had_error = true; - } - } - - /* check for only one FLAC file used with certain options */ - if(!had_error && options->num_files > 1) { - if(0 != find_shorthand_operation(options, OP__IMPORT_CUESHEET_FROM)) { - flac_fprintf(stderr, "ERROR: you may only specify one FLAC file when using '--import-cuesheet-from'\n"); - had_error = true; - } - if(0 != find_shorthand_operation(options, OP__EXPORT_CUESHEET_TO)) { - flac_fprintf(stderr, "ERROR: you may only specify one FLAC file when using '--export-cuesheet-to'\n"); - had_error = true; - } - if(0 != find_shorthand_operation(options, OP__EXPORT_PICTURE_TO)) { - flac_fprintf(stderr, "ERROR: you may only specify one FLAC file when using '--export-picture-to'\n"); - had_error = true; - } - if( - 0 != find_shorthand_operation(options, OP__IMPORT_VC_FROM) && - 0 == strcmp(find_shorthand_operation(options, OP__IMPORT_VC_FROM)->argument.filename.value, "-") - ) { - flac_fprintf(stderr, "ERROR: you may only specify one FLAC file when using '--import-tags-from=-'\n"); - had_error = true; - } - } - - if(options->args.checks.has_block_type && options->args.checks.has_except_block_type) { - flac_fprintf(stderr, "ERROR: you may not specify both '--block-type' and '--except-block-type'\n"); - had_error = true; - } - - if(had_error) - short_usage(0); - - /* - * We need to create an OP__ADD_SEEKPOINT operation if there is - * not one already, and --import-cuesheet-from was specified but - * --no-cued-seekpoints was not: - */ - if(options->cued_seekpoints) { - Operation *op = find_shorthand_operation(options, OP__IMPORT_CUESHEET_FROM); - if(0 != op) { - Operation *op2 = find_shorthand_operation(options, OP__ADD_SEEKPOINT); - if(0 == op2) - op2 = append_shorthand_operation(options, OP__ADD_SEEKPOINT); - op->argument.import_cuesheet_from.add_seekpoint_link = &(op2->argument.add_seekpoint); - } - } - - return had_error; -} - -void free_options(CommandLineOptions *options) -{ - unsigned i; - Operation *op; - Argument *arg; - - FLAC__ASSERT(0 == options->ops.operations || options->ops.num_operations > 0); - FLAC__ASSERT(0 == options->args.arguments || options->args.num_arguments > 0); - - for(i = 0, op = options->ops.operations; i < options->ops.num_operations; i++, op++) { - switch(op->type) { - case OP__SHOW_VC_FIELD: - case OP__REMOVE_VC_FIELD: - case OP__REMOVE_VC_FIRSTFIELD: - case OP__REMOVE_VC_ALL_EXCEPT: - if(0 != op->argument.vc_field_name.value) - free(op->argument.vc_field_name.value); - break; - case OP__SET_VC_FIELD: - if(0 != op->argument.vc_field.field) - free(op->argument.vc_field.field); - if(0 != op->argument.vc_field.field_name) - free(op->argument.vc_field.field_name); - if(0 != op->argument.vc_field.field_value) - free(op->argument.vc_field.field_value); - break; - case OP__IMPORT_VC_FROM: - case OP__EXPORT_VC_TO: - case OP__EXPORT_CUESHEET_TO: - if(0 != op->argument.filename.value) - free(op->argument.filename.value); - break; - case OP__IMPORT_CUESHEET_FROM: - if(0 != op->argument.import_cuesheet_from.filename) - free(op->argument.import_cuesheet_from.filename); - break; - case OP__IMPORT_PICTURE_FROM: - if(0 != op->argument.specification.value) - free(op->argument.specification.value); - break; - case OP__EXPORT_PICTURE_TO: - if(0 != op->argument.export_picture_to.filename) - free(op->argument.export_picture_to.filename); - break; - case OP__ADD_SEEKPOINT: - if(0 != op->argument.add_seekpoint.specification) - free(op->argument.add_seekpoint.specification); - break; - default: - break; - } - } - - for(i = 0, arg = options->args.arguments; i < options->args.num_arguments; i++, arg++) { - switch(arg->type) { - case ARG__BLOCK_NUMBER: - if(0 != arg->value.block_number.entries) - free(arg->value.block_number.entries); - break; - case ARG__BLOCK_TYPE: - case ARG__EXCEPT_BLOCK_TYPE: - if(0 != arg->value.block_type.entries) - free(arg->value.block_type.entries); - break; - case ARG__FROM_FILE: - if(0 != arg->value.from_file.file_name) - free(arg->value.from_file.file_name); - break; - default: - break; - } - } - - if(0 != options->ops.operations) - free(options->ops.operations); - - if(0 != options->args.arguments) - free(options->args.arguments); - - if(0 != options->filenames) { - for(i = 0; i < options->num_files; i++) { - if(0 != options->filenames[i]) - free(options->filenames[i]); - } - free(options->filenames); - } -} - -/* - * local routines - */ - -FLAC__bool parse_option(int option_index, const char *option_argument, CommandLineOptions *options) -{ - const char *opt = long_options_[option_index].name; - Operation *op; - Argument *arg; - FLAC__bool ok = true; - - if(0 == strcmp(opt, "preserve-modtime")) { - options->preserve_modtime = true; - } - else if(0 == strcmp(opt, "with-filename")) { - options->prefix_with_filename = true; - } - else if(0 == strcmp(opt, "no-filename")) { - options->prefix_with_filename = false; - } - else if(0 == strcmp(opt, "no-utf8-convert")) { - options->utf8_convert = false; - } - else if(0 == strcmp(opt, "dont-use-padding")) { - options->use_padding = false; - } - else if(0 == strcmp(opt, "no-cued-seekpoints")) { - options->cued_seekpoints = false; - } - else if(0 == strcmp(opt, "show-md5sum")) { - (void) append_shorthand_operation(options, OP__SHOW_MD5SUM); - } - else if(0 == strcmp(opt, "show-min-blocksize")) { - (void) append_shorthand_operation(options, OP__SHOW_MIN_BLOCKSIZE); - } - else if(0 == strcmp(opt, "show-max-blocksize")) { - (void) append_shorthand_operation(options, OP__SHOW_MAX_BLOCKSIZE); - } - else if(0 == strcmp(opt, "show-min-framesize")) { - (void) append_shorthand_operation(options, OP__SHOW_MIN_FRAMESIZE); - } - else if(0 == strcmp(opt, "show-max-framesize")) { - (void) append_shorthand_operation(options, OP__SHOW_MAX_FRAMESIZE); - } - else if(0 == strcmp(opt, "show-sample-rate")) { - (void) append_shorthand_operation(options, OP__SHOW_SAMPLE_RATE); - } - else if(0 == strcmp(opt, "show-channels")) { - (void) append_shorthand_operation(options, OP__SHOW_CHANNELS); - } - else if(0 == strcmp(opt, "show-bps")) { - (void) append_shorthand_operation(options, OP__SHOW_BPS); - } - else if(0 == strcmp(opt, "show-total-samples")) { - (void) append_shorthand_operation(options, OP__SHOW_TOTAL_SAMPLES); - } - else if(0 == strcmp(opt, "set-md5sum")) { - op = append_shorthand_operation(options, OP__SET_MD5SUM); - FLAC__ASSERT(0 != option_argument); - if(!parse_md5(option_argument, op->argument.streaminfo_md5.value)) { - flac_fprintf(stderr, "ERROR (--%s): bad MD5 sum\n", opt); - ok = false; - } - else - undocumented_warning(opt); - } - else if(0 == strcmp(opt, "set-min-blocksize")) { - op = append_shorthand_operation(options, OP__SET_MIN_BLOCKSIZE); - if(!parse_uint32(option_argument, &(op->argument.streaminfo_uint32.value)) || op->argument.streaminfo_uint32.value < FLAC__MIN_BLOCK_SIZE || op->argument.streaminfo_uint32.value > FLAC__MAX_BLOCK_SIZE) { - flac_fprintf(stderr, "ERROR (--%s): value must be >= %u and <= %u\n", opt, FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE); - ok = false; - } - else - undocumented_warning(opt); - } - else if(0 == strcmp(opt, "set-max-blocksize")) { - op = append_shorthand_operation(options, OP__SET_MAX_BLOCKSIZE); - if(!parse_uint32(option_argument, &(op->argument.streaminfo_uint32.value)) || op->argument.streaminfo_uint32.value < FLAC__MIN_BLOCK_SIZE || op->argument.streaminfo_uint32.value > FLAC__MAX_BLOCK_SIZE) { - flac_fprintf(stderr, "ERROR (--%s): value must be >= %u and <= %u\n", opt, FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE); - ok = false; - } - else - undocumented_warning(opt); - } - else if(0 == strcmp(opt, "set-min-framesize")) { - op = append_shorthand_operation(options, OP__SET_MIN_FRAMESIZE); - if(!parse_uint32(option_argument, &(op->argument.streaminfo_uint32.value)) || op->argument.streaminfo_uint32.value >= (1u<argument.streaminfo_uint32.value)) || op->argument.streaminfo_uint32.value >= (1u<argument.streaminfo_uint32.value)) || !FLAC__format_sample_rate_is_valid(op->argument.streaminfo_uint32.value)) { - flac_fprintf(stderr, "ERROR (--%s): invalid sample rate\n", opt); - ok = false; - } - else - undocumented_warning(opt); - } - else if(0 == strcmp(opt, "set-channels")) { - op = append_shorthand_operation(options, OP__SET_CHANNELS); - if(!parse_uint32(option_argument, &(op->argument.streaminfo_uint32.value)) || op->argument.streaminfo_uint32.value > FLAC__MAX_CHANNELS) { - flac_fprintf(stderr, "ERROR (--%s): value must be > 0 and <= %u\n", opt, FLAC__MAX_CHANNELS); - ok = false; - } - else - undocumented_warning(opt); - } - else if(0 == strcmp(opt, "set-bps")) { - op = append_shorthand_operation(options, OP__SET_BPS); - if(!parse_uint32(option_argument, &(op->argument.streaminfo_uint32.value)) || op->argument.streaminfo_uint32.value < FLAC__MIN_BITS_PER_SAMPLE || op->argument.streaminfo_uint32.value > FLAC__MAX_BITS_PER_SAMPLE) { - flac_fprintf(stderr, "ERROR (--%s): value must be >= %u and <= %u\n", opt, FLAC__MIN_BITS_PER_SAMPLE, FLAC__MAX_BITS_PER_SAMPLE); - ok = false; - } - else - undocumented_warning(opt); - } - else if(0 == strcmp(opt, "set-total-samples")) { - op = append_shorthand_operation(options, OP__SET_TOTAL_SAMPLES); - if(!parse_uint64(option_argument, &(op->argument.streaminfo_uint64.value)) || op->argument.streaminfo_uint64.value >= (((FLAC__uint64)1)<argument.vc_field_name.value), &violation)) { - FLAC__ASSERT(0 != violation); - flac_fprintf(stderr, "ERROR (--%s): malformed vorbis comment field name \"%s\",\n %s\n", opt, option_argument, violation); - ok = false; - } - } - else if(0 == strcmp(opt, "show-all-tags")) { - op = append_shorthand_operation(options, OP__EXPORT_VC_TO); - parse_string("-",&op->argument.filename.value); - } - else if(0 == strcmp(opt, "remove-all-tags")) { - (void) append_shorthand_operation(options, OP__REMOVE_VC_ALL); - } - else if(0 == strcmp(opt, "remove-all-tags-except")) { - const char *violation; - op = append_shorthand_operation(options, OP__REMOVE_VC_ALL_EXCEPT); - FLAC__ASSERT(0 != option_argument); - if(!parse_vorbis_comment_field_names(option_argument, &(op->argument.vc_field_name.value), &violation)) { - FLAC__ASSERT(0 != violation); - flac_fprintf(stderr, "ERROR (--%s): malformed vorbis comment field name \"%s\",\n %s\n", opt, option_argument, violation); - ok = false; - } - } - else if(0 == strcmp(opt, "remove-tag")) { - const char *violation; - op = append_shorthand_operation(options, OP__REMOVE_VC_FIELD); - FLAC__ASSERT(0 != option_argument); - if(!parse_vorbis_comment_field_name(option_argument, &(op->argument.vc_field_name.value), &violation)) { - FLAC__ASSERT(0 != violation); - flac_fprintf(stderr, "ERROR (--%s): malformed vorbis comment field name \"%s\",\n %s\n", opt, option_argument, violation); - ok = false; - } - } - else if(0 == strcmp(opt, "remove-first-tag")) { - const char *violation; - op = append_shorthand_operation(options, OP__REMOVE_VC_FIRSTFIELD); - FLAC__ASSERT(0 != option_argument); - if(!parse_vorbis_comment_field_name(option_argument, &(op->argument.vc_field_name.value), &violation)) { - FLAC__ASSERT(0 != violation); - flac_fprintf(stderr, "ERROR (--%s): malformed vorbis comment field name \"%s\",\n %s\n", opt, option_argument, violation); - ok = false; - } - } - else if(0 == strcmp(opt, "set-tag")) { - const char *violation; - op = append_shorthand_operation(options, OP__SET_VC_FIELD); - FLAC__ASSERT(0 != option_argument); - op->argument.vc_field.field_value_from_file = false; - if(!parse_vorbis_comment_field(option_argument, &(op->argument.vc_field.field), &(op->argument.vc_field.field_name), &(op->argument.vc_field.field_value), &(op->argument.vc_field.field_value_length), &violation)) { - FLAC__ASSERT(0 != violation); - flac_fprintf(stderr, "ERROR (--%s): malformed vorbis comment field \"%s\",\n %s\n", opt, option_argument, violation); - ok = false; - } - } - else if(0 == strcmp(opt, "set-tag-from-file")) { - const char *violation; - op = append_shorthand_operation(options, OP__SET_VC_FIELD); - FLAC__ASSERT(0 != option_argument); - op->argument.vc_field.field_value_from_file = true; - if(!parse_vorbis_comment_field(option_argument, &(op->argument.vc_field.field), &(op->argument.vc_field.field_name), &(op->argument.vc_field.field_value), &(op->argument.vc_field.field_value_length), &violation)) { - FLAC__ASSERT(0 != violation); - flac_fprintf(stderr, "ERROR (--%s): malformed vorbis comment field \"%s\",\n %s\n", opt, option_argument, violation); - ok = false; - } - } - else if(0 == strcmp(opt, "import-tags-from")) { - op = append_shorthand_operation(options, OP__IMPORT_VC_FROM); - FLAC__ASSERT(0 != option_argument); - if(!parse_string(option_argument, &(op->argument.filename.value))) { - flac_fprintf(stderr, "ERROR (--%s): missing filename\n", opt); - ok = false; - } - } - else if(0 == strcmp(opt, "export-tags-to")) { - op = append_shorthand_operation(options, OP__EXPORT_VC_TO); - FLAC__ASSERT(0 != option_argument); - if(!parse_string(option_argument, &(op->argument.filename.value))) { - flac_fprintf(stderr, "ERROR (--%s): missing filename\n", opt); - ok = false; - } - } - else if(0 == strcmp(opt, "import-cuesheet-from")) { - if(0 != find_shorthand_operation(options, OP__IMPORT_CUESHEET_FROM)) { - flac_fprintf(stderr, "ERROR (--%s): may be specified only once\n", opt); - ok = false; - } - op = append_shorthand_operation(options, OP__IMPORT_CUESHEET_FROM); - FLAC__ASSERT(0 != option_argument); - if(!parse_string(option_argument, &(op->argument.import_cuesheet_from.filename))) { - flac_fprintf(stderr, "ERROR (--%s): missing filename\n", opt); - ok = false; - } - } - else if(0 == strcmp(opt, "export-cuesheet-to")) { - op = append_shorthand_operation(options, OP__EXPORT_CUESHEET_TO); - FLAC__ASSERT(0 != option_argument); - if(!parse_string(option_argument, &(op->argument.filename.value))) { - flac_fprintf(stderr, "ERROR (--%s): missing filename\n", opt); - ok = false; - } - } - else if(0 == strcmp(opt, "import-picture-from")) { - op = append_shorthand_operation(options, OP__IMPORT_PICTURE_FROM); - FLAC__ASSERT(0 != option_argument); - if(!parse_string(option_argument, &(op->argument.specification.value))) { - flac_fprintf(stderr, "ERROR (--%s): missing specification\n", opt); - ok = false; - } - } - else if(0 == strcmp(opt, "export-picture-to")) { - arg = find_argument(options, ARG__BLOCK_NUMBER); - op = append_shorthand_operation(options, OP__EXPORT_PICTURE_TO); - FLAC__ASSERT(0 != option_argument); - if(!parse_string(option_argument, &(op->argument.export_picture_to.filename))) { - flac_fprintf(stderr, "ERROR (--%s): missing filename\n", opt); - ok = false; - } - op->argument.export_picture_to.block_number_link = arg? &(arg->value.block_number) : 0; - } - else if(0 == strcmp(opt, "add-seekpoint")) { - const char *violation; - char *spec; - FLAC__ASSERT(0 != option_argument); - if(!parse_add_seekpoint(option_argument, &spec, &violation)) { - FLAC__ASSERT(0 != violation); - flac_fprintf(stderr, "ERROR (--%s): malformed seekpoint specification \"%s\",\n %s\n", opt, option_argument, violation); - ok = false; - } - else { - op = find_shorthand_operation(options, OP__ADD_SEEKPOINT); - if(0 == op) - op = append_shorthand_operation(options, OP__ADD_SEEKPOINT); - local_strcat(&(op->argument.add_seekpoint.specification), spec); - local_strcat(&(op->argument.add_seekpoint.specification), ";"); - free(spec); - } - } - else if(0 == strcmp(opt, "add-replay-gain")) { - (void) append_shorthand_operation(options, OP__ADD_REPLAY_GAIN); - } - else if(0 == strcmp(opt, "scan-replay-gain")) { - (void) append_shorthand_operation(options, OP__SCAN_REPLAY_GAIN); - } - else if(0 == strcmp(opt, "remove-replay-gain")) { - const FLAC__byte * const tags[5] = { - GRABBAG__REPLAYGAIN_TAG_REFERENCE_LOUDNESS, - GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN, - GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK, - GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN, - GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK - }; - size_t i; - for(i = 0; i < sizeof(tags)/sizeof(tags[0]); i++) { - op = append_shorthand_operation(options, OP__REMOVE_VC_FIELD); - op->argument.vc_field_name.value = local_strdup((const char *)tags[i]); - } - } - else if(0 == strcmp(opt, "add-padding")) { - op = append_shorthand_operation(options, OP__ADD_PADDING); - FLAC__ASSERT(0 != option_argument); - if(!parse_add_padding(option_argument, &(op->argument.add_padding.length))) { - flac_fprintf(stderr, "ERROR (--%s): illegal length \"%s\", length must be >= 0 and < 2^%u\n", opt, option_argument, FLAC__STREAM_METADATA_LENGTH_LEN); - ok = false; - } - } - else if(0 == strcmp(opt, "help")) { - options->show_long_help = true; - } - else if(0 == strcmp(opt, "version")) { - options->show_version = true; - } - else if(0 == strcmp(opt, "list")) { - (void) append_major_operation(options, OP__LIST); - } - else if(0 == strcmp(opt, "append")) { - (void) append_major_operation(options, OP__APPEND); - } - else if(0 == strcmp(opt, "remove")) { - (void) append_major_operation(options, OP__REMOVE); - } - else if(0 == strcmp(opt, "remove-all")) { - (void) append_major_operation(options, OP__REMOVE_ALL); - } - else if(0 == strcmp(opt, "merge-padding")) { - (void) append_major_operation(options, OP__MERGE_PADDING); - } - else if(0 == strcmp(opt, "sort-padding")) { - (void) append_major_operation(options, OP__SORT_PADDING); - } - else if(0 == strcmp(opt, "block-number")) { - arg = append_argument(options, ARG__BLOCK_NUMBER); - FLAC__ASSERT(0 != option_argument); - if(!parse_block_number(option_argument, &(arg->value.block_number))) { - flac_fprintf(stderr, "ERROR: malformed block number specification \"%s\"\n", option_argument); - ok = false; - } - } - else if(0 == strcmp(opt, "block-type")) { - arg = append_argument(options, ARG__BLOCK_TYPE); - FLAC__ASSERT(0 != option_argument); - if(!parse_block_type(option_argument, &(arg->value.block_type))) { - flac_fprintf(stderr, "ERROR (--%s): malformed block type specification \"%s\"\n", opt, option_argument); - ok = false; - } - options->args.checks.has_block_type = true; - } - else if(0 == strcmp(opt, "except-block-type")) { - arg = append_argument(options, ARG__EXCEPT_BLOCK_TYPE); - FLAC__ASSERT(0 != option_argument); - if(!parse_block_type(option_argument, &(arg->value.block_type))) { - flac_fprintf(stderr, "ERROR (--%s): malformed block type specification \"%s\"\n", opt, option_argument); - ok = false; - } - options->args.checks.has_except_block_type = true; - } - else if(0 == strcmp(opt, "data-format")) { - arg = append_argument(options, ARG__DATA_FORMAT); - FLAC__ASSERT(0 != option_argument); - if(!parse_data_format(option_argument, &(arg->value.data_format))) { - flac_fprintf(stderr, "ERROR (--%s): illegal data format \"%s\"\n", opt, option_argument); - ok = false; - } - options->data_format_is_binary = arg->value.data_format.is_binary; - options->data_format_is_binary_headerless = arg->value.data_format.is_headerless; - } - else if(0 == strcmp(opt, "application-data-format")) { - FLAC__ASSERT(0 != option_argument); - if(!parse_application_data_format(option_argument, &(options->application_data_format_is_hexdump))) { - flac_fprintf(stderr, "ERROR (--%s): illegal application data format \"%s\"\n", opt, option_argument); - ok = false; - } - } - else if(0 == strcmp(opt, "from-file")) { - arg = append_argument(options, ARG__FROM_FILE); - FLAC__ASSERT(0 != option_argument); - arg->value.from_file.file_name = local_strdup(option_argument); - } - else { - FLAC__ASSERT(0); - } - - return ok; -} - -void append_new_operation(CommandLineOptions *options, Operation operation) -{ - if(options->ops.capacity == 0) { - options->ops.capacity = 50; - if(0 == (options->ops.operations = malloc(sizeof(Operation) * options->ops.capacity))) - die("out of memory allocating space for option list"); - memset(options->ops.operations, 0, sizeof(Operation) * options->ops.capacity); - } - if(options->ops.capacity <= options->ops.num_operations) { - unsigned original_capacity = options->ops.capacity; - if(options->ops.capacity > UINT32_MAX / 2) /* overflow check */ - die("out of memory allocating space for option list"); - options->ops.capacity *= 2; - if(0 == (options->ops.operations = safe_realloc_mul_2op_(options->ops.operations, sizeof(Operation), /*times*/options->ops.capacity))) - die("out of memory allocating space for option list"); - memset(options->ops.operations + original_capacity, 0, sizeof(Operation) * (options->ops.capacity - original_capacity)); - } - - options->ops.operations[options->ops.num_operations++] = operation; -} - -void append_new_argument(CommandLineOptions *options, Argument argument) -{ - if(options->args.capacity == 0) { - options->args.capacity = 50; - if(0 == (options->args.arguments = malloc(sizeof(Argument) * options->args.capacity))) - die("out of memory allocating space for option list"); - memset(options->args.arguments, 0, sizeof(Argument) * options->args.capacity); - } - if(options->args.capacity <= options->args.num_arguments) { - unsigned original_capacity = options->args.capacity; - if(options->args.capacity > UINT32_MAX / 2) /* overflow check */ - die("out of memory allocating space for option list"); - options->args.capacity *= 2; - if(0 == (options->args.arguments = safe_realloc_mul_2op_(options->args.arguments, sizeof(Argument), /*times*/options->args.capacity))) - die("out of memory allocating space for option list"); - memset(options->args.arguments + original_capacity, 0, sizeof(Argument) * (options->args.capacity - original_capacity)); - } - - options->args.arguments[options->args.num_arguments++] = argument; -} - -Operation *append_major_operation(CommandLineOptions *options, OperationType type) -{ - Operation op; - memset(&op, 0, sizeof(op)); - op.type = type; - append_new_operation(options, op); - options->args.checks.num_major_ops++; - return options->ops.operations + (options->ops.num_operations - 1); -} - -Operation *append_shorthand_operation(CommandLineOptions *options, OperationType type) -{ - Operation op; - memset(&op, 0, sizeof(op)); - op.type = type; - append_new_operation(options, op); - options->args.checks.num_shorthand_ops++; - return options->ops.operations + (options->ops.num_operations - 1); -} - -Argument *find_argument(CommandLineOptions *options, ArgumentType type) -{ - unsigned i; - for(i = 0; i < options->args.num_arguments; i++) - if(options->args.arguments[i].type == type) - return &options->args.arguments[i]; - return 0; -} - -Operation *find_shorthand_operation(CommandLineOptions *options, OperationType type) -{ - unsigned i; - for(i = 0; i < options->ops.num_operations; i++) - if(options->ops.operations[i].type == type) - return &options->ops.operations[i]; - return 0; -} - -Argument *append_argument(CommandLineOptions *options, ArgumentType type) -{ - Argument arg; - memset(&arg, 0, sizeof(arg)); - arg.type = type; - append_new_argument(options, arg); - return options->args.arguments + (options->args.num_arguments - 1); -} - -FLAC__bool parse_md5(const char *src, FLAC__byte dest[16]) -{ - unsigned i, d; - int c; - FLAC__ASSERT(0 != src); - if(strlen(src) != 32) - return false; - /* strtoul() accepts negative numbers which we do not want, so we do it the hard way */ - for(i = 0; i < 16; i++) { - c = (int)(*src++); - if(isdigit(c)) - d = (unsigned)(c - '0'); - else if(c >= 'a' && c <= 'f') - d = (unsigned)(c - 'a') + 10u; - else if(c >= 'A' && c <= 'F') - d = (unsigned)(c - 'A') + 10u; - else - return false; - d <<= 4; - c = (int)(*src++); - if(isdigit(c)) - d |= (unsigned)(c - '0'); - else if(c >= 'a' && c <= 'f') - d |= (unsigned)(c - 'a') + 10u; - else if(c >= 'A' && c <= 'F') - d |= (unsigned)(c - 'A') + 10u; - else - return false; - dest[i] = (FLAC__byte)d; - } - return true; -} - -FLAC__bool parse_uint32(const char *src, FLAC__uint32 *dest) -{ - FLAC__ASSERT(0 != src); - if(strlen(src) == 0 || strspn(src, "0123456789") != strlen(src)) - return false; - *dest = strtoul(src, 0, 10); - return true; -} - -FLAC__bool parse_uint64(const char *src, FLAC__uint64 *dest) -{ - FLAC__ASSERT(0 != src); - if(strlen(src) == 0 || strspn(src, "0123456789") != strlen(src)) - return false; - *dest = strtoull(src, 0, 10); - return true; -} - -FLAC__bool parse_string(const char *src, char **dest) -{ - if(0 == src || strlen(src) == 0) - return false; - *dest = strdup(src); - return true; -} - -FLAC__bool parse_vorbis_comment_field_name(const char *field_ref, char **name, const char **violation) -{ - static const char * const violations[] = { - "field name contains invalid character" - }; - - char *q, *s; - - s = local_strdup(field_ref); - - for(q = s; *q; q++) { - if(*q < 0x20 || *q > 0x7d || *q == 0x3d) { - free(s); - *violation = violations[0]; - return false; - } - } - - *name = s; - - return true; -} - -FLAC__bool parse_vorbis_comment_field_names(const char *field_ref, char **names, const char **violation) -{ - static const char * const violations[] = { - "field name contains invalid character" - }; - - char *q, *s; - - s = local_strdup(field_ref); - - for(q = s; *q; q++) { - if(*q < 0x20 || *q > 0x7d) { - free(s); - *violation = violations[0]; - return false; - } - } - - *names = s; - - return true; -} - -FLAC__bool parse_add_seekpoint(const char *in, char **out, const char **violation) -{ - static const char *garbled_ = "garbled specification"; - const unsigned n = strlen(in); - - FLAC__ASSERT(0 != in); - FLAC__ASSERT(0 != out); - - if(n == 0) { - *violation = "specification is empty"; - return false; - } - - if(n > strspn(in, "0123456789.Xsx")) { - *violation = "specification contains invalid character"; - return false; - } - - if(in[n-1] == 'X') { - if(n > 1) { - *violation = garbled_; - return false; - } - } - else if(in[n-1] == 's') { - if(n-1 > strspn(in, "0123456789.")) { - *violation = garbled_; - return false; - } - } - else if(in[n-1] == 'x') { - if(n-1 > strspn(in, "0123456789")) { - *violation = garbled_; - return false; - } - } - else { - if(n > strspn(in, "0123456789")) { - *violation = garbled_; - return false; - } - } - - *out = local_strdup(in); - return true; -} - -FLAC__bool parse_add_padding(const char *in, unsigned *out) -{ - FLAC__ASSERT(0 != in); - FLAC__ASSERT(0 != out); - *out = (unsigned)strtoul(in, 0, 10); - return *out < (1u << FLAC__STREAM_METADATA_LENGTH_LEN); -} - -FLAC__bool parse_block_number(const char *in, Argument_BlockNumber *out) -{ - char *p, *q, *s, *end; - long i; - unsigned entry; - - if(*in == '\0') - return false; - - s = local_strdup(in); - - /* first count the entries */ - for(out->num_entries = 1, p = strchr(s, ','); p; out->num_entries++, p = strchr(++p, ',')) - ; - - /* make space */ - FLAC__ASSERT(out->num_entries > 0); - if(0 == (out->entries = safe_malloc_mul_2op_(sizeof(unsigned), /*times*/out->num_entries))) - die("out of memory allocating space for option list"); - - /* load 'em up */ - entry = 0; - q = s; - while(q) { - FLAC__ASSERT(entry < out->num_entries); - if(0 != (p = strchr(q, ','))) - *p++ = '\0'; - if(!isdigit((int)(*q)) || (i = strtol(q, &end, 10)) < 0 || *end) { - free(s); - return false; - } - out->entries[entry++] = (unsigned)i; - q = p; - } - FLAC__ASSERT(entry == out->num_entries); - - free(s); - return true; -} - -FLAC__bool parse_block_type(const char *in, Argument_BlockType *out) -{ - char *p, *q, *r, *s; - unsigned entry; - - if(*in == '\0') - return false; - - s = local_strdup(in); - - /* first count the entries */ - for(out->num_entries = 1, p = strchr(s, ','); p; out->num_entries++, p = strchr(++p, ',')) - ; - - /* make space */ - FLAC__ASSERT(out->num_entries > 0); - if(0 == (out->entries = safe_malloc_mul_2op_(sizeof(Argument_BlockTypeEntry), /*times*/out->num_entries))) - die("out of memory allocating space for option list"); - - /* load 'em up */ - entry = 0; - q = s; - while(q) { - FLAC__ASSERT(entry < out->num_entries); - if(0 != (p = strchr(q, ','))) - *p++ = 0; - r = strchr(q, ':'); - if(r) - *r++ = '\0'; - if(0 != r && 0 != strcmp(q, "APPLICATION")) { - free(s); - return false; - } - if(0 == strcmp(q, "STREAMINFO")) { - out->entries[entry++].type = FLAC__METADATA_TYPE_STREAMINFO; - } - else if(0 == strcmp(q, "PADDING")) { - out->entries[entry++].type = FLAC__METADATA_TYPE_PADDING; - } - else if(0 == strcmp(q, "APPLICATION")) { - out->entries[entry].type = FLAC__METADATA_TYPE_APPLICATION; - out->entries[entry].filter_application_by_id = (0 != r); - if(0 != r) { - if(strlen(r) == sizeof (out->entries[entry].application_id)) { - memcpy(out->entries[entry].application_id, r, sizeof (out->entries[entry].application_id)); - } - else if(strlen(r) == 10 && FLAC__STRNCASECMP(r, "0x", 2) == 0 && strspn(r+2, "0123456789ABCDEFabcdef") == 8) { - FLAC__uint32 x = strtoul(r+2, 0, 16); - out->entries[entry].application_id[3] = (FLAC__byte)(x & 0xff); - out->entries[entry].application_id[2] = (FLAC__byte)((x>>=8) & 0xff); - out->entries[entry].application_id[1] = (FLAC__byte)((x>>=8) & 0xff); - out->entries[entry].application_id[0] = (FLAC__byte)((x>>=8) & 0xff); - } - else { - free(s); - return false; - } - } - entry++; - } - else if(0 == strcmp(q, "SEEKTABLE")) { - out->entries[entry++].type = FLAC__METADATA_TYPE_SEEKTABLE; - } - else if(0 == strcmp(q, "VORBIS_COMMENT")) { - out->entries[entry++].type = FLAC__METADATA_TYPE_VORBIS_COMMENT; - } - else if(0 == strcmp(q, "CUESHEET")) { - out->entries[entry++].type = FLAC__METADATA_TYPE_CUESHEET; - } - else if(0 == strcmp(q, "PICTURE")) { - out->entries[entry++].type = FLAC__METADATA_TYPE_PICTURE; - } - else { - free(s); - return false; - } - q = p; - } - FLAC__ASSERT(entry == out->num_entries); - - free(s); - return true; -} - -FLAC__bool parse_data_format(const char *in, Argument_DataFormat *out) -{ - if(0 == strcmp(in, "binary-headerless")) { - out->is_binary = false; - out->is_headerless = true; - } - else if(0 == strcmp(in, "binary")) { - out->is_binary = true; - out->is_headerless = false; - } - else if(0 == strcmp(in, "text")) { - out->is_binary = false; - out->is_headerless = false; - } - else - return false; - return true; -} - -FLAC__bool parse_application_data_format(const char *in, FLAC__bool *out) -{ - if(0 == strcmp(in, "hexdump")) - *out = true; - else if(0 == strcmp(in, "text")) - *out = false; - else - return false; - return true; -} - -void undocumented_warning(const char *opt) -{ - flac_fprintf(stderr, "WARNING: undocumented option --%s should be used with caution,\n only for repairing a damaged STREAMINFO block\n", opt); -} diff --git a/flac/src/metaflac/options.h b/flac/src/metaflac/options.h deleted file mode 100644 index 984f2e1..0000000 --- a/flac/src/metaflac/options.h +++ /dev/null @@ -1,221 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 metaflac__options_h -#define metaflac__options_h - -#include "FLAC/format.h" - -#if 0 -/*[JEC] was:#if HAVE_GETOPT_LONG*/ -/*[JEC] see flac/include/share/getopt.h as to why the change */ -# include -#else -# include "share/getopt.h" -#endif - -extern struct share__option long_options_[]; - -typedef enum { - OP__SHOW_MD5SUM, - OP__SHOW_MIN_BLOCKSIZE, - OP__SHOW_MAX_BLOCKSIZE, - OP__SHOW_MIN_FRAMESIZE, - OP__SHOW_MAX_FRAMESIZE, - OP__SHOW_SAMPLE_RATE, - OP__SHOW_CHANNELS, - OP__SHOW_BPS, - OP__SHOW_TOTAL_SAMPLES, - OP__SET_MD5SUM, - OP__SET_MIN_BLOCKSIZE, - OP__SET_MAX_BLOCKSIZE, - OP__SET_MIN_FRAMESIZE, - OP__SET_MAX_FRAMESIZE, - OP__SET_SAMPLE_RATE, - OP__SET_CHANNELS, - OP__SET_BPS, - OP__SET_TOTAL_SAMPLES, - OP__SHOW_VC_VENDOR, - OP__SHOW_VC_FIELD, - OP__REMOVE_VC_ALL, - OP__REMOVE_VC_ALL_EXCEPT, - OP__REMOVE_VC_FIELD, - OP__REMOVE_VC_FIRSTFIELD, - OP__SET_VC_FIELD, - OP__IMPORT_VC_FROM, - OP__EXPORT_VC_TO, - OP__IMPORT_CUESHEET_FROM, - OP__EXPORT_CUESHEET_TO, - OP__IMPORT_PICTURE_FROM, - OP__EXPORT_PICTURE_TO, - OP__ADD_SEEKPOINT, - OP__ADD_REPLAY_GAIN, - OP__SCAN_REPLAY_GAIN, - OP__ADD_PADDING, - OP__LIST, - OP__APPEND, - OP__REMOVE, - OP__REMOVE_ALL, - OP__MERGE_PADDING, - OP__SORT_PADDING -} OperationType; - -typedef enum { - ARG__BLOCK_NUMBER, - ARG__BLOCK_TYPE, - ARG__EXCEPT_BLOCK_TYPE, - ARG__DATA_FORMAT, - ARG__FROM_FILE -} ArgumentType; - -typedef struct { - FLAC__byte value[16]; -} Argument_StreaminfoMD5; - -typedef struct { - FLAC__uint32 value; -} Argument_StreaminfoUInt32; - -typedef struct { - FLAC__uint64 value; -} Argument_StreaminfoUInt64; - -typedef struct { - char *value; -} Argument_VcFieldName; - -typedef struct { - char *field; /* the whole field as passed on the command line, i.e. "NAME=VALUE" */ - char *field_name; - /* according to the vorbis spec, field values can contain \0 so simple C strings are not enough here */ - unsigned field_value_length; - char *field_value; - FLAC__bool field_value_from_file; /* true if field_value holds a filename for the value, false for plain value */ -} Argument_VcField; - -typedef struct { - char *value; -} Argument_String; - -typedef struct { - unsigned num_entries; - unsigned *entries; -} Argument_BlockNumber; - -typedef struct { - FLAC__MetadataType type; - char application_id[4]; /* only relevant if type == FLAC__STREAM_METADATA_TYPE_APPLICATION */ - FLAC__bool filter_application_by_id; -} Argument_BlockTypeEntry; - -typedef struct { - unsigned num_entries; - Argument_BlockTypeEntry *entries; -} Argument_BlockType; - -typedef struct { - FLAC__bool is_binary; - FLAC__bool is_headerless; -} Argument_DataFormat; - -typedef struct { - char *file_name; -} Argument_FromFile; - -typedef struct { - char *specification; -} Argument_AddSeekpoint; - -typedef struct { - char *filename; - Argument_AddSeekpoint *add_seekpoint_link; -} Argument_ImportCuesheetFrom; - -typedef struct { - char *filename; - const Argument_BlockNumber *block_number_link; /* may be NULL to mean 'first PICTURE block' */ -} Argument_ExportPictureTo; - -typedef struct { - unsigned length; -} Argument_AddPadding; - -typedef struct { - OperationType type; - union { - Argument_StreaminfoMD5 streaminfo_md5; - Argument_StreaminfoUInt32 streaminfo_uint32; - Argument_StreaminfoUInt64 streaminfo_uint64; - Argument_VcFieldName vc_field_name; - Argument_VcField vc_field; - Argument_String filename; - Argument_String specification; - Argument_ImportCuesheetFrom import_cuesheet_from; - Argument_ExportPictureTo export_picture_to; - Argument_AddSeekpoint add_seekpoint; - Argument_AddPadding add_padding; - } argument; -} Operation; - -typedef struct { - ArgumentType type; - union { - Argument_BlockNumber block_number; - Argument_BlockType block_type; - Argument_DataFormat data_format; - Argument_FromFile from_file; - } value; -} Argument; - -typedef struct { - FLAC__bool preserve_modtime; - FLAC__bool prefix_with_filename; - FLAC__bool utf8_convert; - FLAC__bool use_padding; - FLAC__bool cued_seekpoints; - FLAC__bool show_long_help; - FLAC__bool show_version; - FLAC__bool data_format_is_binary; - FLAC__bool data_format_is_binary_headerless; - FLAC__bool application_data_format_is_hexdump; - struct { - Operation *operations; - unsigned num_operations; - unsigned capacity; - } ops; - struct { - struct { - unsigned num_shorthand_ops; - unsigned num_major_ops; - FLAC__bool has_block_type; - FLAC__bool has_except_block_type; - } checks; - Argument *arguments; - unsigned num_arguments; - unsigned capacity; - } args; - unsigned num_files; - char **filenames; -} CommandLineOptions; - -void init_options(CommandLineOptions *options); -FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options); -void free_options(CommandLineOptions *options); - -#endif diff --git a/flac/src/metaflac/usage.c b/flac/src/metaflac/usage.c deleted file mode 100644 index 58afc0e..0000000 --- a/flac/src/metaflac/usage.c +++ /dev/null @@ -1,349 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "utils.h" -#include "usage.h" -#include "FLAC/format.h" -#include -#include -#include "share/compat.h" - -static void usage_header(FILE *out) -{ - fprintf(out, "==============================================================================\n"); - fprintf(out, "metaflac - Command-line FLAC metadata editor version %s\n", FLAC__VERSION_STRING); - fprintf(out, "Copyright (C) 2001-2009 Josh Coalson\n"); - fprintf(out, "Copyright (C) 2011-2023 Xiph.Org Foundation\n"); - fprintf(out, "\n"); - fprintf(out, "This program is free software; you can redistribute it and/or\n"); - fprintf(out, "modify it under the terms of the GNU General Public License\n"); - fprintf(out, "as published by the Free Software Foundation; either version 2\n"); - fprintf(out, "of the License, or (at your option) any later version.\n"); - fprintf(out, "\n"); - fprintf(out, "This program is distributed in the hope that it will be useful,\n"); - fprintf(out, "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); - fprintf(out, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); - fprintf(out, "GNU General Public License for more details.\n"); - fprintf(out, "\n"); - fprintf(out, "You should have received a copy of the GNU General Public License along\n"); - fprintf(out, "with this program; if not, write to the Free Software Foundation, Inc.,\n"); - fprintf(out, "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n"); - fprintf(out, "==============================================================================\n"); -} - -static void usage_summary(FILE *out) -{ - fprintf(out, "Usage:\n"); - fprintf(out, " metaflac [options] [operations] FLACfile [FLACfile ...]\n"); - fprintf(out, "\n"); - fprintf(out, "Use metaflac to list, add, remove, or edit metadata in one or more FLAC files.\n"); - fprintf(out, "You may perform one major operation, or many shorthand operations at a time.\n"); - fprintf(out, "\n"); - fprintf(out, "Options:\n"); - fprintf(out, "--preserve-modtime Preserve the original modification time in spite of edits\n"); - fprintf(out, "--with-filename Prefix each output line with the FLAC file name\n"); - fprintf(out, " (the default if more than one FLAC file is specified).\n"); - fprintf(out, " This option has no effect for options exporting to a\n"); - fprintf(out, " file, like --export-tags-to.\n"); - fprintf(out, "--no-filename Do not prefix each output line with the FLAC file name\n"); - fprintf(out, " (the default if only one FLAC file is specified)\n"); - fprintf(out, "--no-utf8-convert Do not convert tags from UTF-8 to local charset,\n"); - fprintf(out, " or vice versa. This is useful for scripts, and setting\n"); - fprintf(out, " tags in situations where the locale is wrong.\n"); - fprintf(out, "--dont-use-padding By default metaflac tries to use padding where possible\n"); - fprintf(out, " to avoid rewriting the entire file if the metadata size\n"); - fprintf(out, " changes. Use this option to tell metaflac to not take\n"); - fprintf(out, " advantage of padding this way.\n"); -} - -int short_usage(const char *message, ...) -{ - va_list args; - - if(message) { - va_start(args, message); - - (void) vfprintf(stderr, message, args); - - va_end(args); - - } - usage_header(stderr); - flac_fprintf(stderr, "\n"); - flac_fprintf(stderr, "This is the short help; for full help use 'metaflac --help'\n"); - flac_fprintf(stderr, "\n"); - usage_summary(stderr); - - return message? 1 : 0; -} - -int long_usage(const char *message, ...) -{ - FILE *out = (message? stderr : stdout); - va_list args; - - if(message) { - va_start(args, message); - - (void) vfprintf(stderr, message, args); - - va_end(args); - - } - usage_header(out); - fprintf(out, "\n"); - usage_summary(out); - fprintf(out, "\n"); - fprintf(out, "Shorthand operations:\n"); - fprintf(out, "--show-md5sum Show the MD5 signature from the STREAMINFO block.\n"); - fprintf(out, "--show-min-blocksize Show the minimum block size from the STREAMINFO block.\n"); - fprintf(out, "--show-max-blocksize Show the maximum block size from the STREAMINFO block.\n"); - fprintf(out, "--show-min-framesize Show the minimum frame size from the STREAMINFO block.\n"); - fprintf(out, "--show-max-framesize Show the maximum frame size from the STREAMINFO block.\n"); - fprintf(out, "--show-sample-rate Show the sample rate from the STREAMINFO block.\n"); - fprintf(out, "--show-channels Show the number of channels from the STREAMINFO block.\n"); - fprintf(out, "--show-bps Show the # of bits per sample from the STREAMINFO block.\n"); - fprintf(out, "--show-total-samples Show the total # of samples from the STREAMINFO block.\n"); - fprintf(out, "\n"); - fprintf(out, "--show-vendor-tag Show the vendor string from the VORBIS_COMMENT block.\n"); - fprintf(out, "--show-tag=NAME Show all tags where the field name matches 'NAME'.\n"); - fprintf(out, "--show-all-tags Show all tags. This is an alias for --export-tags-to=-.\n"); - fprintf(out, "--remove-tag=NAME Remove all tags whose field name is 'NAME'.\n"); - fprintf(out, "--remove-first-tag=NAME Remove first tag whose field name is 'NAME'.\n"); - fprintf(out, "--remove-all-tags Remove all tags, leaving only the vendor string.\n"); - fprintf(out, "--remove-all-tags-except=NAME1[=NAME2[=...]] Remove all tags, except the vendor\n"); - fprintf(out, " string and the tag names specified. Tag names must be\n"); - fprintf(out, " separated by an = character.\n"); - fprintf(out, "--set-tag=FIELD Add a tag. The FIELD must comply with the Vorbis comment\n"); - fprintf(out, " spec, of the form \"NAME=VALUE\". If there is currently\n"); - fprintf(out, " no tag block, one will be created.\n"); - fprintf(out, "--set-tag-from-file=FIELD Like --set-tag, except the VALUE is a filename\n"); - fprintf(out, " whose contents will be read verbatim to set the tag value.\n"); - fprintf(out, " Unless --no-utf8-convert is specified, the contents will\n"); - fprintf(out, " be converted to UTF-8 from the local charset. This can\n"); - fprintf(out, " be used to store a cuesheet in a tag (e.g.\n"); - fprintf(out, " --set-tag-from-file=\"CUESHEET=image.cue\"). Do not try\n"); - fprintf(out, " to store binary data in tag fields! Use APPLICATION\n"); - fprintf(out, " blocks for that.\n"); - fprintf(out, "--import-tags-from=FILE Import tags from a file. Use '-' for stdin. Each line\n"); - fprintf(out, " should be of the form NAME=VALUE. Multi-line comments\n"); - fprintf(out, " are currently not supported. Specify --remove-all-tags\n"); - fprintf(out, " and/or --no-utf8-convert before --import-tags-from if\n"); - fprintf(out, " necessary. If FILE is '-' (stdin), only one FLAC file\n"); - fprintf(out, " may be specified.\n"); - fprintf(out, "--export-tags-to=FILE Export tags to a file. Use '-' for stdout. Each line\n"); - fprintf(out, " will be of the form NAME=VALUE. Specify\n"); - fprintf(out, " --no-utf8-convert if necessary.\n"); - fprintf(out, "--import-cuesheet-from=FILE Import a cuesheet from a file. Use '-' for stdin.\n"); - fprintf(out, " Only one FLAC file may be specified. A seekpoint will be\n"); - fprintf(out, " added for each index point in the cuesheet to the\n"); - fprintf(out, " SEEKTABLE unless --no-cued-seekpoints is specified.\n"); - fprintf(out, "--export-cuesheet-to=FILE Export CUESHEET block to a cuesheet file, suitable\n"); - fprintf(out, " for use by CD authoring software. Use '-' for stdout.\n"); - fprintf(out, " Only one FLAC file may be specified on the command line.\n"); - fprintf(out, "--import-picture-from=FILENAME|SPECIFICATION Import a picture and store it in a\n"); - fprintf(out, " PICTURE block. Either a filename for the picture file or\n"); - fprintf(out, " a more complete specification form can be used. The\n"); - fprintf(out, " SPECIFICATION is a string whose parts are separated by |\n"); - fprintf(out, " characters. Some parts may be left empty to invoke\n"); - fprintf(out, " default values. FILENAME is just shorthand for\n"); - fprintf(out, " \"||||FILENAME\". The format of SPECIFICATION is:\n"); - fprintf(out, " [TYPE]|[MIME-TYPE]|[DESCRIPTION]|[WIDTHxHEIGHTxDEPTH[/COLORS]]|FILE\n"); - fprintf(out, " TYPE is optional; it is a number from one of:\n"); - fprintf(out, " 0: Other\n"); - fprintf(out, " 1: 32x32 pixels 'file icon' (PNG only)\n"); - fprintf(out, " 2: Other file icon\n"); - fprintf(out, " 3: Cover (front)\n"); - fprintf(out, " 4: Cover (back)\n"); - fprintf(out, " 5: Leaflet page\n"); - fprintf(out, " 6: Media (e.g. label side of CD)\n"); - fprintf(out, " 7: Lead artist/lead performer/soloist\n"); - fprintf(out, " 8: Artist/performer\n"); - fprintf(out, " 9: Conductor\n"); - fprintf(out, " 10: Band/Orchestra\n"); - fprintf(out, " 11: Composer\n"); - fprintf(out, " 12: Lyricist/text writer\n"); - fprintf(out, " 13: Recording Location\n"); - fprintf(out, " 14: During recording\n"); - fprintf(out, " 15: During performance\n"); - fprintf(out, " 16: Movie/video screen capture\n"); - fprintf(out, " 17: A bright coloured fish\n"); - fprintf(out, " 18: Illustration\n"); - fprintf(out, " 19: Band/artist logotype\n"); - fprintf(out, " 20: Publisher/Studio logotype\n"); - fprintf(out, " The default is 3 (front cover). There may only be one picture each\n"); - fprintf(out, " of type 1 and 2 in a file.\n"); - fprintf(out, " MIME-TYPE is optional; if left blank, it will be detected from the\n"); - fprintf(out, " file. For best compatibility with players, use pictures with MIME\n"); - fprintf(out, " type image/jpeg or image/png. The MIME type can also be --> to\n"); - fprintf(out, " mean that FILE is actually a URL to an image, though this use is\n"); - fprintf(out, " discouraged.\n"); - fprintf(out, " DESCRIPTION is optional; the default is an empty string\n"); - fprintf(out, " The next part specifies the resolution and color information. If\n"); - fprintf(out, " the MIME-TYPE is image/jpeg, image/png, or image/gif, you can\n"); - fprintf(out, " usually leave this empty and they can be detected from the file.\n"); - fprintf(out, " Otherwise, you must specify the width in pixels, height in pixels,\n"); - fprintf(out, " and color depth in bits-per-pixel. If the image has indexed colors\n"); - fprintf(out, " you should also specify the number of colors used.\n"); - fprintf(out, " FILE is the path to the picture file to be imported, or the URL if\n"); - fprintf(out, " MIME type is -->\n"); - fprintf(out, "--export-picture-to=FILE Export PICTURE block to a file. Use '-' for stdout.\n"); - fprintf(out, " Only one FLAC file may be specified. The first PICTURE\n"); - fprintf(out, " block will be exported unless --export-picture-to is\n"); - fprintf(out, " preceded by a --block-number=# option to specify the exact\n"); - fprintf(out, " metadata block to extract. Note that the block number is\n"); - fprintf(out, " the one shown by --list.\n"); - fprintf(out, "--add-replay-gain Calculates the title and album gains/peaks of the given\n"); - fprintf(out, " FLAC files as if all the files were part of one album,\n"); - fprintf(out, " then stores them in the VORBIS_COMMENT block. The tags\n"); - fprintf(out, " are the same as those used by vorbisgain. Existing\n"); - fprintf(out, " ReplayGain tags will be replaced. If only one FLAC file\n"); - fprintf(out, " is given, the album and title gains will be the same.\n"); - fprintf(out, " Since this operation requires two passes, it is always\n"); - fprintf(out, " executed last, after all other operations have been\n"); - fprintf(out, " completed and written to disk. All FLAC files specified\n"); - fprintf(out, " must have the same resolution, sample rate, and number\n"); - fprintf(out, " of channels. Only mono and stereo files are allowed,\n"); - fprintf(out, " and the sample rate must be 8, 11.025, 12, 16, 18.9,\n"); - fprintf(out, " 22.05, 24, 28, 32, 36, 37.8, 44.1, 48, 56, 64, 72, 75.6,\n"); - fprintf(out, " 88.2, 96, 112, 128, 144, 151.2, 176.4, 192, 224, 256,\n"); - fprintf(out, " 288, 302.4, 352.8, 384, 448, 512, 576, or 604.8 kHz.\n"); - fprintf(out, "--scan-replay-gain Like --add-replay-gain, but only analyzes the files\n"); - fprintf(out, " rather than writing them to tags.\n"); - fprintf(out, "--remove-replay-gain Removes the ReplayGain tags.\n"); - fprintf(out, "--add-seekpoint={#|X|#x|#s} Add seek points to a SEEKTABLE block\n"); - fprintf(out, " # : a specific sample number for a seek point\n"); - fprintf(out, " X : a placeholder point (always goes at the end of the SEEKTABLE)\n"); - fprintf(out, " #x : # evenly spaced seekpoints, the first being at sample 0\n"); - fprintf(out, " #s : a seekpoint every # seconds; # does not have to be a whole number\n"); - fprintf(out, " If no SEEKTABLE block exists, one will be created. If\n"); - fprintf(out, " one already exists, points will be added to the existing\n"); - fprintf(out, " table, and any duplicates will be turned into placeholder\n"); - fprintf(out, " points. You may use many --add-seekpoint options; the\n"); - fprintf(out, " resulting SEEKTABLE will be the unique-ified union of\n"); - fprintf(out, " all such values. Example: --add-seekpoint=100x\n"); - fprintf(out, " --add-seekpoint=3.5s will add 100 evenly spaced\n"); - fprintf(out, " seekpoints and a seekpoint every 3.5 seconds.\n"); - fprintf(out, "--add-padding=length Add a padding block of the given length (in bytes).\n"); - fprintf(out, " The overall length of the new block will be 4 + length;\n"); - fprintf(out, " the extra 4 bytes is for the metadata block header.\n"); - fprintf(out, "\n"); - fprintf(out, "Major operations:\n"); - fprintf(out, "--version\n"); - fprintf(out, " Show the metaflac version number.\n"); - fprintf(out, "--list\n"); - fprintf(out, " List the contents of one or more metadata blocks to stdout. By default,\n"); - fprintf(out, " all metadata blocks are listed in text format. Use the following options\n"); - fprintf(out, " to change this behavior:\n"); - fprintf(out, "\n"); - fprintf(out, " --block-number=#[,#[...]]\n"); - fprintf(out, " An optional comma-separated list of block numbers to display. The first\n"); - fprintf(out, " block, the STREAMINFO block, is block 0.\n"); - fprintf(out, "\n"); - fprintf(out, " --block-type=type[,type[...]]\n"); - fprintf(out, " --except-block-type=type[,type[...]]\n"); - fprintf(out, " An optional comma-separated list of block types to be included or ignored\n"); - fprintf(out, " with this option. Use only one of --block-type or --except-block-type.\n"); - fprintf(out, " The valid block types are: STREAMINFO, PADDING, APPLICATION, SEEKTABLE,\n"); - fprintf(out, " VORBIS_COMMENT. You may narrow down the types of APPLICATION blocks\n"); - fprintf(out, " displayed as follows:\n"); - fprintf(out, " APPLICATION:abcd The APPLICATION block(s) whose textual repre-\n"); - fprintf(out, " sentation of the 4-byte ID is \"abcd\"\n"); - fprintf(out, " APPLICATION:0xXXXXXXXX The APPLICATION block(s) whose hexadecimal big-\n"); - fprintf(out, " endian representation of the 4-byte ID is\n"); - fprintf(out, " \"0xXXXXXXXX\". For the example \"abcd\" above the\n"); - fprintf(out, " hexadecimal equivalalent is 0x61626364\n"); - fprintf(out, "\n"); - fprintf(out, " NOTE: if both --block-number and --[except-]block-type are specified,\n"); - fprintf(out, " the result is the logical AND of both arguments.\n"); - fprintf(out, "\n"); - fprintf(out, " --data-format=binary|binary-headerless|text\n"); - fprintf(out, " By default a human-readable text representation of the data is displayed.\n"); - fprintf(out, " You may specify --data-format=binary to dump the raw binary form of each\n"); - fprintf(out, " metadata block. Specify --data-format=binary-headerless to omit output of\n"); - fprintf(out, " metadata block headers, including the id of APPLICATION metadata blocks.\n"); - fprintf(out, " The output can be read in using a subsequent call to\n"); - fprintf(out, " \"metaflac --append\"\n"); - fprintf(out, "\n"); - fprintf(out, " --application-data-format=hexdump|text\n"); - fprintf(out, " If the application block you are displaying contains binary data but your\n"); - fprintf(out, " --data-format=text, you can display a hex dump of the application data\n"); - fprintf(out, " contents instead using --application-data-format=hexdump\n"); - fprintf(out, "\n"); - fprintf(out, "--append\n"); - fprintf(out, " Insert a metadata block from a file. This must be a binary block as\n"); - fprintf(out, " exported with --list --data-format=binary. The insertion point is\n"); - fprintf(out, " defined with --block-number=#. The new block will be added after the\n"); - fprintf(out, " given block number. This prevents the illegal insertion of a block\n"); - fprintf(out, " before the first STREAMINFO block. You may not --append another\n"); - fprintf(out, " STREAMINFO block. It is possible to copy a metadata block from one\n"); - fprintf(out, " file to another with this option. For example use\n"); - fprintf(out, " metaflac --list --data-format=binary --block-number=6 file.flac > block\n"); - fprintf(out, " to export the block, and then import it with\n"); - fprintf(out, " metaflac --append anotherfile.flac < block\n"); - fprintf(out, " Insert a metadata block from a file. The input file must be in the same\n"); - fprintf(out, " format as generated with --list.\n"); - fprintf(out, "\n"); - fprintf(out, " --block-number=#\n"); - fprintf(out, " Specify the insertion point (defaults to last block). The new block will\n"); - fprintf(out, " be added after the given block number. This prevents the illegal insertion\n"); - fprintf(out, " of a block before the first STREAMINFO block. You may not --append another\n"); - fprintf(out, " STREAMINFO block.\n"); - fprintf(out, "\n"); -#if 0 - /*@@@ not implemented yet */ - fprintf(out, " --from-file=filename\n"); - fprintf(out, " Mandatory 'option' to specify the input file containing the block contents.\n"); - fprintf(out, "\n"); - fprintf(out, " --data-format=binary|text\n"); - fprintf(out, " By default the block contents are assumed to be in binary format. You can\n"); - fprintf(out, " override this by specifying --data-format=text\n"); - fprintf(out, "\n"); -#endif - fprintf(out, "--remove\n"); - fprintf(out, " Remove one or more metadata blocks from the metadata. Unless\n"); - fprintf(out, " --dont-use-padding is specified, the blocks will be replaced with padding.\n"); - fprintf(out, " You may not remove the STREAMINFO block.\n"); - fprintf(out, "\n"); - fprintf(out, " --block-number=#[,#[...]]\n"); - fprintf(out, " --block-type=type[,type[...]]\n"); - fprintf(out, " --except-block-type=type[,type[...]]\n"); - fprintf(out, " See --list above for usage.\n"); - fprintf(out, "\n"); - fprintf(out, " NOTE: if both --block-number and --[except-]block-type are specified,\n"); - fprintf(out, " the result is the logical AND of both arguments.\n"); - fprintf(out, "\n"); - fprintf(out, "--remove-all\n"); - fprintf(out, " Remove all metadata blocks (except the STREAMINFO block) from the\n"); - fprintf(out, " metadata. Unless --dont-use-padding is specified, the blocks will be\n"); - fprintf(out, " replaced with padding.\n"); - fprintf(out, "\n"); - fprintf(out, "--merge-padding\n"); - fprintf(out, " Merge adjacent PADDING blocks into single blocks.\n"); - fprintf(out, "\n"); - fprintf(out, "--sort-padding\n"); - fprintf(out, " Move all PADDING blocks to the end of the metadata and merge them into a\n"); - fprintf(out, " single block.\n"); - - return message? 1 : 0; -} diff --git a/flac/src/metaflac/usage.h b/flac/src/metaflac/usage.h deleted file mode 100644 index 1366417..0000000 --- a/flac/src/metaflac/usage.h +++ /dev/null @@ -1,26 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 metaflac__usage_h -#define metaflac__usage_h - -int short_usage(const char *message, ...); -int long_usage(const char *message, ...); - -#endif diff --git a/flac/src/metaflac/utils.c b/flac/src/metaflac/utils.c deleted file mode 100644 index 045719a..0000000 --- a/flac/src/metaflac/utils.c +++ /dev/null @@ -1,282 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include "utils.h" -#include "FLAC/assert.h" -#include "share/alloc.h" -#include "share/safe_str.h" -#include "share/utf8.h" -#include "share/compat.h" - -void die(const char *message) -{ - FLAC__ASSERT(0 != message); - flac_fprintf(stderr, "ERROR: %s\n", message); - exit(1); -} - -#ifdef FLAC__VALGRIND_TESTING -size_t local_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) -{ - size_t ret = fwrite(ptr, size, nmemb, stream); - if(!ferror(stream)) - fflush(stream); - return ret; -} -#endif - -char *local_strdup(const char *source) -{ - char *ret; - FLAC__ASSERT(0 != source); - if(0 == (ret = strdup(source))) - die("out of memory during strdup()"); - return ret; -} - -void local_strcat(char **dest, const char *source) -{ - size_t ndest, nsource, outlen; - - FLAC__ASSERT(0 != dest); - FLAC__ASSERT(0 != source); - - ndest = *dest ? strlen(*dest) : 0; - nsource = strlen(source); - outlen = ndest + nsource + 1; - - if(nsource == 0) - return; - - *dest = safe_realloc_add_3op_(*dest, ndest, /*+*/nsource, /*+*/1); - if(*dest == NULL) - die("out of memory growing string"); - /* If ndest == 0, strlen in safe_strncat reads - * uninitialized data. To prevent that, set first character - * to zero */ - if(ndest == 0) - *dest[0] = 0; - safe_strncat(*dest, source, outlen); -} - -static inline int local_isprint(int c) -{ - if (c < 32) return 0; - if (c > 127) return 0; - return isprint(c); -} - -void hexdump(const char *filename, const FLAC__byte *buf, unsigned bytes, const char *indent) -{ - unsigned i, left = bytes; - const FLAC__byte *b = buf; - - for(i = 0; i < bytes; i += 16) { - flac_printf("%s%s", filename? filename:"", filename? ":":""); - printf("%s%08X: " - "%02X %02X %02X %02X %02X %02X %02X %02X " - "%02X %02X %02X %02X %02X %02X %02X %02X " - "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", - indent, i, - left > 0? (unsigned char)b[ 0] : 0, - left > 1? (unsigned char)b[ 1] : 0, - left > 2? (unsigned char)b[ 2] : 0, - left > 3? (unsigned char)b[ 3] : 0, - left > 4? (unsigned char)b[ 4] : 0, - left > 5? (unsigned char)b[ 5] : 0, - left > 6? (unsigned char)b[ 6] : 0, - left > 7? (unsigned char)b[ 7] : 0, - left > 8? (unsigned char)b[ 8] : 0, - left > 9? (unsigned char)b[ 9] : 0, - left > 10? (unsigned char)b[10] : 0, - left > 11? (unsigned char)b[11] : 0, - left > 12? (unsigned char)b[12] : 0, - left > 13? (unsigned char)b[13] : 0, - left > 14? (unsigned char)b[14] : 0, - left > 15? (unsigned char)b[15] : 0, - (left > 0) ? (local_isprint(b[ 0]) ? b[ 0] : '.') : ' ', - (left > 1) ? (local_isprint(b[ 1]) ? b[ 1] : '.') : ' ', - (left > 2) ? (local_isprint(b[ 2]) ? b[ 2] : '.') : ' ', - (left > 3) ? (local_isprint(b[ 3]) ? b[ 3] : '.') : ' ', - (left > 4) ? (local_isprint(b[ 4]) ? b[ 4] : '.') : ' ', - (left > 5) ? (local_isprint(b[ 5]) ? b[ 5] : '.') : ' ', - (left > 6) ? (local_isprint(b[ 6]) ? b[ 6] : '.') : ' ', - (left > 7) ? (local_isprint(b[ 7]) ? b[ 7] : '.') : ' ', - (left > 8) ? (local_isprint(b[ 8]) ? b[ 8] : '.') : ' ', - (left > 9) ? (local_isprint(b[ 9]) ? b[ 9] : '.') : ' ', - (left > 10) ? (local_isprint(b[10]) ? b[10] : '.') : ' ', - (left > 11) ? (local_isprint(b[11]) ? b[11] : '.') : ' ', - (left > 12) ? (local_isprint(b[12]) ? b[12] : '.') : ' ', - (left > 13) ? (local_isprint(b[13]) ? b[13] : '.') : ' ', - (left > 14) ? (local_isprint(b[14]) ? b[14] : '.') : ' ', - (left > 15) ? (local_isprint(b[15]) ? b[15] : '.') : ' ' - ); - left -= 16; - b += 16; - } -} - -void print_error_with_chain_status(FLAC__Metadata_Chain *chain, const char *format, ...) -{ - const FLAC__Metadata_ChainStatus status = FLAC__metadata_chain_status(chain); - va_list args; - - FLAC__ASSERT(0 != format); - - va_start(args, format); - - (void) flac_vfprintf(stderr, format, args); - - va_end(args); - - flac_fprintf(stderr, ", status = \"%s\"\n", FLAC__Metadata_ChainStatusString[status]); - - if(status == FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE) { - flac_fprintf(stderr, "\n" - "The FLAC file could not be opened. Most likely the file does not exist\n" - "or is not readable.\n" - ); - } - else if(status == FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE) { - flac_fprintf(stderr, "\n" - "The file does not appear to be a FLAC file.\n" - ); - } - else if(status == FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE) { - flac_fprintf(stderr, "\n" - "The FLAC file does not have write permissions.\n" - ); - } - else if(status == FLAC__METADATA_CHAIN_STATUS_BAD_METADATA) { - flac_fprintf(stderr, "\n" - "The metadata to be written does not conform to the FLAC metadata\n" - "specifications.\n" - ); - } - else if(status == FLAC__METADATA_CHAIN_STATUS_READ_ERROR) { - flac_fprintf(stderr, "\n" - "There was an error while reading the FLAC file.\n" - ); - } - else if(status == FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR) { - flac_fprintf(stderr, "\n" - "There was an error while writing FLAC file; most probably the disk is\n" - "full.\n" - ); - } - else if(status == FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR) { - flac_fprintf(stderr, "\n" - "There was an error removing the temporary FLAC file.\n" - ); - } -} - -FLAC__bool parse_vorbis_comment_field(const char *field_ref, char **field, char **name, char **value, unsigned *length, const char **violation) -{ - static const char * const violations[] = { - "field name contains invalid character", - "field contains no '=' character" - }; - - char *p, *q, *s; - - if(0 != field) - *field = local_strdup(field_ref); - - s = local_strdup(field_ref); - - if(0 == (p = strchr(s, '='))) { - free(s); - *violation = violations[1]; - return false; - } - *p++ = '\0'; - - for(q = s; *q; q++) { - if(*q < 0x20 || *q > 0x7d || *q == 0x3d) { - free(s); - *violation = violations[0]; - return false; - } - } - - *name = local_strdup(s); - *value = local_strdup(p); - *length = strlen(p); - - free(s); - return true; -} - -void write_vc_field(const char *filename, const FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__bool raw, FILE *f) -{ - if(0 != entry->entry) { - if(filename) - flac_fprintf(f, "%s:", filename); - - if(!raw) { - /* - * WATCHOUT: comments that contain an embedded null will - * be truncated by utf_decode(). - */ -#ifdef _WIN32 /* if we are outputting to console, we need to use proper print functions to show unicode characters */ - if (f == stdout || f == stderr) { - flac_fprintf(f, "%s", entry->entry); - } else { -#endif - char *converted; - - if(utf8_decode((const char *)entry->entry, &converted) >= 0) { - (void) local_fwrite(converted, 1, strlen(converted), f); - free(converted); - } - else { - (void) local_fwrite(entry->entry, 1, entry->length, f); - } -#ifdef _WIN32 - } -#endif - } - else { - (void) local_fwrite(entry->entry, 1, entry->length, f); - } - } - - putc('\n', f); -} - -void write_vc_fields(const char *filename, const char *field_name, const FLAC__StreamMetadata_VorbisComment_Entry entry[], unsigned num_entries, FLAC__bool raw, FILE *f) -{ - unsigned i; - const unsigned field_name_length = (0 != field_name)? strlen(field_name) : 0; - - for(i = 0; i < num_entries; i++) { - if(0 == field_name || FLAC__metadata_object_vorbiscomment_entry_matches(entry[i], field_name, field_name_length)) - write_vc_field(filename, entry + i, raw, f); - } -} diff --git a/flac/src/metaflac/utils.h b/flac/src/metaflac/utils.h deleted file mode 100644 index 972a450..0000000 --- a/flac/src/metaflac/utils.h +++ /dev/null @@ -1,47 +0,0 @@ -/* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 metaflac__utils_h -#define metaflac__utils_h - -#include "FLAC/metadata.h" -#include /* for FILE */ - -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -#undef stderr -#define stderr stdout -#endif - -void die(const char *message); -#ifdef FLAC__VALGRIND_TESTING -size_t local_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); -#else -#define local_fwrite fwrite -#endif -char *local_strdup(const char *source); -void local_strcat(char **dest, const char *source); -void hexdump(const char *filename, const FLAC__byte *buf, unsigned bytes, const char *indent); -void print_error_with_chain_status(FLAC__Metadata_Chain *chain, const char *format, ...); - -FLAC__bool parse_vorbis_comment_field(const char *field_ref, char **field, char **name, char **value, unsigned *length, const char **violation); - -void write_vc_field(const char *filename, const FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__bool raw, FILE *f); -void write_vc_fields(const char *filename, const char *field_name, const FLAC__StreamMetadata_VorbisComment_Entry entry[], unsigned num_entries, FLAC__bool raw, FILE *f); - -#endif diff --git a/flac/src/metaflac/version.rc b/flac/src/metaflac/version.rc deleted file mode 100644 index 5117202..0000000 --- a/flac/src/metaflac/version.rc +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include "config.h" - -#if (defined GIT_COMMIT_HASH && defined GIT_COMMIT_DATE) -# ifdef GIT_COMMIT_TAG -# define VERSIONSTRING GIT_COMMIT_TAG -# else -# define VERSIONSTRING "git-" GIT_COMMIT_HASH -# endif -#else -# define VERSIONSTRING PACKAGE_VERSION -#endif - -#define xstr(s) str(s) -#define str(s) #s - -VS_VERSION_INFO VERSIONINFO -FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -FILEFLAGS 0 -FILEOS VOS__WINDOWS32 -FILETYPE VFT_DLL -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "FileDescription", "metaflac command line tool for Windows" - VALUE "ProductName", "Free Lossless Audio Codec" - VALUE "ProductVersion", VERSIONSTRING - VALUE "CompanyName", "Xiph.Org" - VALUE "LegalCopyright", "2000-2009 Josh Coalson, 2011-2023 Xiph.Org Foundation" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END diff --git a/flac/src/share/Makefile.am b/flac/src/share/Makefile.am deleted file mode 100644 index caf6122..0000000 --- a/flac/src/share/Makefile.am +++ /dev/null @@ -1,73 +0,0 @@ -# FLAC - Free Lossless Audio Codec -# Copyright (C) 2002-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# This file is part the FLAC project. FLAC is comprised of several -# components distributed under different licenses. The codec libraries -# are distributed under Xiph.Org's BSD-like license (see the file -# COPYING.Xiph in this distribution). All other programs, libraries, and -# plugins are distributed under the GPL (see COPYING.GPL). The documentation -# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the -# FLAC distribution contains at the top the terms under which it may be -# distributed. -# -# Since this particular file is relevant to all components of FLAC, -# it may be distributed under the Xiph.Org license, which is the least -# restrictive of those mentioned above. See the file COPYING.Xiph in this -# distribution. - -AUTOMAKE_OPTIONS = subdir-objects - -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include - -EXTRA_DIST = \ - README \ - getopt/CMakeLists.txt \ - grabbag/CMakeLists.txt \ - replaygain_analysis/CMakeLists.txt \ - replaygain_synthesis/CMakeLists.txt \ - utf8/CMakeLists.txt \ - utf8/charmaps.h \ - utf8/makemap.c \ - utf8/charset_test.c - - -noinst_LTLIBRARIES = \ - getopt/libgetopt.la \ - grabbag/libgrabbag.la \ - utf8/libutf8.la \ - $(libwin_utf8_io) \ - replaygain_analysis/libreplaygain_analysis.la \ - replaygain_synthesis/libreplaygain_synthesis.la - - -if OS_IS_WINDOWS -win_utf8_io_libwin_utf8_io_la_SOURCES = win_utf8_io/win_utf8_io.c -libwin_utf8_io = win_utf8_io/libwin_utf8_io.la -else -win_utf8_io_libwin_utf8_io_la_SOURCES = -libwin_utf8_io = -endif - -getopt_libgetopt_la_SOURCES = getopt/getopt.c getopt/getopt1.c - -grabbag_libgrabbag_la_SOURCES = \ - grabbag/alloc.c \ - grabbag/cuesheet.c \ - grabbag/file.c \ - grabbag/picture.c \ - grabbag/replaygain.c \ - grabbag/seektable.c \ - grabbag/snprintf.c - -utf8_libutf8_la_SOURCES = \ - utf8/charset.c \ - utf8/charset.h \ - utf8/iconvert.c \ - utf8/iconvert.h \ - utf8/utf8.c - -replaygain_analysis_libreplaygain_analysis_la_SOURCES = replaygain_analysis/replaygain_analysis.c - -replaygain_synthesis_libreplaygain_synthesis_la_CFLAGS = -I $(top_srcdir)/src/share/replaygain_synthesis/include -replaygain_synthesis_libreplaygain_synthesis_la_SOURCES = replaygain_synthesis/replaygain_synthesis.c diff --git a/flac/src/share/README b/flac/src/share/README deleted file mode 100644 index 1d4fede..0000000 --- a/flac/src/share/README +++ /dev/null @@ -1,5 +0,0 @@ -This directory contains several convenience libraries used by the rest of the -tools and plugins. Two of them (getopt and utf8) are shamelessly copied from -vorbistools, one for manipulating UTF-8 strings (GPL) and one for implementing -getopt (LGPL). libFLAC does not link to either; the only FLAC tools that do -are GPL'ed. diff --git a/flac/src/share/getopt/CMakeLists.txt b/flac/src/share/getopt/CMakeLists.txt deleted file mode 100644 index d905615..0000000 --- a/flac/src/share/getopt/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -check_include_file("string.h" HAVE_STRING_H) - -if(NOT WIN32) - find_package(Intl) -endif() - -add_library(getopt STATIC getopt.c getopt1.c) - -if(Intl_FOUND) - target_include_directories(getopt PRIVATE ${Intl_INCLUDE_DIRS}) - target_link_libraries(getopt PUBLIC ${Intl_LIBRARIES}) - target_compile_definitions(getopt PRIVATE HAVE_LIBINTL_H) -endif() diff --git a/flac/src/share/getopt/getopt.c b/flac/src/share/getopt/getopt.c deleted file mode 100644 index 39fab80..0000000 --- a/flac/src/share/getopt/getopt.c +++ /dev/null @@ -1,1053 +0,0 @@ -/* - NOTE: - I cannot get the vanilla getopt code to work (i.e. compile only what - is needed and not duplicate symbols found in the standard library) - on all the platforms that FLAC supports. In particular the gating - of code with the ELIDE_CODE #define is not accurate enough on systems - that are POSIX but not glibc. If someone has a patch that works on - GNU/Linux, Darwin, AND Solaris please submit it on the project page: - https://sourceforge.net/p/flac/patches/ - - In the meantime I have munged the global symbols and removed gates - around code, while at the same time trying to touch the original as - little as possible. -*/ -/* Getopt for GNU. - NOTE: getopt is now part of the C library, so if you don't know what - "Keep this file name-space clean" means, talk to drepper@gnu.org - before changing it! - - Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 - Free Software Foundation, Inc. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ - -/* This tells Alpha OSF/1 not to define a getopt prototype in . - Ditto for AIX 3.2 and . */ -#ifndef _NO_PROTO -# define _NO_PROTO -#endif - -#ifdef HAVE_CONFIG_H -# include -#endif - -#if !defined __STDC__ || !__STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -# ifndef const -# define const -# endif -#endif - -#include - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#define GETOPT_INTERFACE_VERSION 2 -#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 -# include -# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION -# define ELIDE_CODE -# endif -#endif - -#if 1 -/*[JEC] was:#ifndef ELIDE_CODE*/ - - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -/* Don't include stdlib.h for non-GNU C libraries because some of them - contain conflicting prototypes for getopt. */ -# include -# include -#endif /* GNU C library. */ - -#ifdef VMS -# include -# ifdef HAVE_STRING_H -# include -# endif -#endif - -#ifndef _ -/* This is for other GNU distributions with internationalized messages. - When compiling libc, the _ macro is predefined. */ -# ifdef HAVE_LIBINTL_H -# include -# define _(msgid) gettext (msgid) -# else -# define _(msgid) (msgid) -# endif -#endif - -/* This version of `share__getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `share__getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. - - Setting the environment variable POSIXLY_CORRECT disables permutation. - Then the behavior is completely standard. - - GNU application programs can use a third alternative mode in which - they can distinguish the relative order of options and other arguments. */ - -#include "share/getopt.h" -/*[JEC] was:#include "getopt.h"*/ - -/* For communication from `share__getopt' to the caller. - When `share__getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -char *share__optarg = 0; /*[JEC] initialize to avoid being a 'Common' symbol */ - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `share__getopt'. - - On entry to `share__getopt', zero means this is the first call; initialize. - - When `share__getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `share__optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -/* 1003.2 says this must be 1 before any call. */ -int share__optind = 1; - -/* Formerly, initialization of getopt depended on share__optind==0, which - causes problems with re-calling getopt as programs generally don't - know that. */ - -static int share____getopt_initialized = 0; - -/* The next char to be scanned in the option-element - in which the last option character we returned was found. - This allows us to pick up the scan where we left off. - - If this is zero, or a null string, it means resume the scan - by advancing to the next ARGV-element. */ - -static char *nextchar; - -/* Callers store zero here to inhibit the error message - for unrecognized options. */ - -int share__opterr = 1; - -/* Set to an option character which was unrecognized. - This must be initialized on some systems to avoid linking in the - system's own getopt implementation. */ - -int share__optopt = '?'; - -/* Describe how to deal with options that follow non-option ARGV-elements. - - If the caller did not specify anything, - the default is REQUIRE_ORDER if the environment variable - POSIXLY_CORRECT is defined, PERMUTE otherwise. - - REQUIRE_ORDER means don't recognize them as options; - stop option processing when the first non-option is seen. - This is what Unix does. - This mode of operation is selected by either setting the environment - variable POSIXLY_CORRECT, or using `+' as the first character - of the list of option characters. - - PERMUTE is the default. We permute the contents of ARGV as we scan, - so that eventually all the non-options are at the end. This allows options - to be given in any order, even with programs that were not written to - expect this. - - RETURN_IN_ORDER is an option available to programs that were written - to expect options and other ARGV-elements in any order and that care about - the ordering of the two. We describe each non-option ARGV-element - as if it were the argument of an option with character code 1. - Using `-' as the first character of the list of option characters - selects this mode of operation. - - The special argument `--' forces an end of option-scanning regardless - of the value of `ordering'. In the case of RETURN_IN_ORDER, only - `--' can cause `share__getopt' to return -1 with `share__optind' != ARGC. */ - -static enum -{ - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER -} ordering; - -/* Value of POSIXLY_CORRECT environment variable. */ -static char *posixly_correct; - -#ifdef __GNU_LIBRARY__ -/* We want to avoid inclusion of string.h with non-GNU libraries - because there are many ways it can cause trouble. - On some systems, it contains special magic macros that don't work - in GCC. */ -# include -# define my_index strchr -#else - -#include - -/* Avoid depending on library functions or files - whose names are inconsistent. */ - -#ifndef getenv -extern char *getenv (const char * name); -#endif - -static char * -my_index (const char *str, int chr) -{ - while (*str) - { - if (*str == chr) - return (char *) str; - str++; - } - return 0; -} - -/* If using GCC, we can safely declare strlen this way. - If not using GCC, it is ok not to declare it. */ -#ifdef __GNUC__ -/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. - That was relevant to code that was here before. */ -# if (!defined __STDC__ || !__STDC__) && !defined strlen -/* gcc with -traditional declares the built-in strlen to return int, - and has done so at least since version 2.4.5. -- rms. */ -extern int strlen (const char *); -# endif /* not __STDC__ */ -#endif /* __GNUC__ */ - -#endif /* not __GNU_LIBRARY__ */ - -/* Handle permutation of arguments. */ - -/* Describe the part of ARGV that contains non-options that have - been skipped. `first_nonopt' is the index in ARGV of the first of them; - `last_nonopt' is the index after the last of them. */ - -static int first_nonopt; -static int last_nonopt; - -#ifdef _LIBC -/* Bash 2.0 gives us an environment variable containing flags - indicating ARGV elements that should not be considered arguments. */ - -/* Defined in getopt_init.c */ -extern char *__getopt_nonoption_flags; - -static int nonoption_flags_max_len; -static int nonoption_flags_len; - -static int original_argc; -static char *const *original_argv; - -/* Make sure the environment variable bash 2.0 puts in the environment - is valid for the getopt call we must make sure that the ARGV passed - to getopt is that one passed to the process. */ -static void -__attribute__ ((unused)) -store_args_and_env (int argc, char *const *argv) -{ - /* XXX This is no good solution. We should rather copy the args so - that we can compare them later. But we must not use malloc(3). */ - original_argc = argc; - original_argv = argv; -} -# ifdef text_set_element -text_set_element (__libc_subinit, store_args_and_env); -# endif /* text_set_element */ - -# define SWAP_FLAGS(ch1, ch2) \ - if (nonoption_flags_len > 0) \ - { \ - char __tmp = __getopt_nonoption_flags[ch1]; \ - __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ - __getopt_nonoption_flags[ch2] = __tmp; \ - } -#else /* !_LIBC */ -# define SWAP_FLAGS(ch1, ch2) -#endif /* _LIBC */ - -/* Exchange two adjacent subsequences of ARGV. - One subsequence is elements [first_nonopt,last_nonopt) - which contains all the non-options that have been skipped so far. - The other is elements [last_nonopt,share__optind), which contains all - the options processed since those non-options were skipped. - - `first_nonopt' and `last_nonopt' are relocated so that they describe - the new indices of the non-options in ARGV after they are moved. */ - -#if defined __STDC__ && __STDC__ -static void exchange (char **); -#endif - -static void -exchange (char **argv) -{ - int bottom = first_nonopt; - int middle = last_nonopt; - int top = share__optind; - char *tem; - - /* Exchange the shorter segment with the far end of the longer segment. - That puts the shorter segment into the right place. - It leaves the longer segment in the right place overall, - but it consists of two parts that need to be swapped next. */ - -#ifdef _LIBC - /* First make sure the handling of the `__getopt_nonoption_flags' - string can work normally. Our top argument must be in the range - of the string. */ - if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) - { - /* We must extend the array. The user plays games with us and - presents new arguments. */ - char *new_str = malloc (top + 1); - if (new_str == NULL) - nonoption_flags_len = nonoption_flags_max_len = 0; - else - { - memset (__mempcpy (new_str, __getopt_nonoption_flags, - nonoption_flags_max_len), - '\0', top + 1 - nonoption_flags_max_len); - nonoption_flags_max_len = top + 1; - __getopt_nonoption_flags = new_str; - } - } -#endif - - while (top > middle && middle > bottom) - { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - SWAP_FLAGS (bottom + i, middle + i); - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - - /* Update records for the slots the non-options now occupy. */ - - first_nonopt += (share__optind - last_nonopt); - last_nonopt = share__optind; -} - -/* Initialize the internal data when the first call is made. */ - -#if defined __STDC__ && __STDC__ -static const char *share___getopt_initialize (int, char *const *, const char *); -#endif -static const char * -share___getopt_initialize (int argc, char *const *argv, const char *optstring ) -{ - /* Start processing options with ARGV-element 1 (since ARGV-element 0 - is the program name); the sequence of previously skipped - non-option ARGV-elements is empty. */ - - first_nonopt = last_nonopt = share__optind; - - nextchar = NULL; - - posixly_correct = getenv ("POSIXLY_CORRECT"); - - /* Determine how to handle the ordering of options and nonoptions. */ - - if (optstring[0] == '-') - { - ordering = RETURN_IN_ORDER; - ++optstring; - } - else if (optstring[0] == '+') - { - ordering = REQUIRE_ORDER; - ++optstring; - } - else if (posixly_correct != NULL) - ordering = REQUIRE_ORDER; - else - ordering = PERMUTE; - -#ifdef _LIBC - if (posixly_correct == NULL - && argc == original_argc && argv == original_argv) - { - if (nonoption_flags_max_len == 0) - { - if (__getopt_nonoption_flags == NULL - || __getopt_nonoption_flags[0] == '\0') - nonoption_flags_max_len = -1; - else - { - const char *orig_str = __getopt_nonoption_flags; - int len = nonoption_flags_max_len = strlen (orig_str); - if (nonoption_flags_max_len < argc) - nonoption_flags_max_len = argc; - __getopt_nonoption_flags = - malloc (nonoption_flags_max_len); - if (__getopt_nonoption_flags == NULL) - nonoption_flags_max_len = -1; - else - memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), - '\0', nonoption_flags_max_len - len); - } - } - nonoption_flags_len = nonoption_flags_max_len; - } - else - nonoption_flags_len = 0; -#else - (void)argc, (void)argv; -#endif - - return optstring; -} - -/* Scan elements of ARGV (whose length is ARGC) for option characters - given in OPTSTRING. - - If an element of ARGV starts with '-', and is not exactly "-" or "--", - then it is an option element. The characters of this element - (aside from the initial '-') are option characters. If `share__getopt' - is called repeatedly, it returns successively each of the option characters - from each of the option elements. - - If `share__getopt' finds another option character, it returns that character, - updating `share__optind' and `nextchar' so that the next call to `share__getopt' can - resume the scan with the following option character or ARGV-element. - - If there are no more option characters, `share__getopt' returns -1. - Then `share__optind' is the index in ARGV of the first ARGV-element - that is not an option. (The ARGV-elements have been permuted - so that those that are not options now come last.) - - OPTSTRING is a string containing the legitimate option characters. - If an option character is seen that is not listed in OPTSTRING, - return '?' after printing an error message. If you set `share__opterr' to - zero, the error message is suppressed but we still return '?'. - - If a char in OPTSTRING is followed by a colon, that means it wants an arg, - so the following text in the same ARGV-element, or the text of the following - ARGV-element, is returned in `share__optarg'. Two colons mean an option that - wants an optional arg; if there is text in the current ARGV-element, - it is returned in `share__optarg', otherwise `share__optarg' is set to zero. - - If OPTSTRING starts with `-' or `+', it requests different methods of - handling the non-option ARGV-elements. - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - - Long-named options begin with `--' instead of `-'. - Their names may be abbreviated as long as the abbreviation is unique - or is an exact match for some defined option. If they have an - argument, it follows the option name in the same ARGV-element, separated - from the option name by a `=', or else the in next ARGV-element. - When `share__getopt' finds a long-named option, it returns 0 if that option's - `flag' field is nonzero, the value of the option's `val' field - if the `flag' field is zero. - - The elements of ARGV aren't really const, because we permute them. - But we pretend they're const in the prototype to be compatible - with other systems. - - LONGOPTS is a vector of `struct share__option' terminated by an - element containing a name which is zero. - - LONGIND returns the index in LONGOPT of the long-named option found. - It is only valid when a long-named option has been found by the most - recent call. - - If LONG_ONLY is nonzero, '-' as well as '--' can introduce - long-named options. */ - -int -share___getopt_internal ( - int argc, - char *const *argv, - const char *optstring, - const struct share__option *longopts, - int *longind, - int long_only ) -{ - share__optarg = NULL; - - if (share__optind == 0 || !share____getopt_initialized) - { - if (share__optind == 0) - share__optind = 1; /* Don't scan ARGV[0], the program name. */ - optstring = share___getopt_initialize (argc, argv, optstring); - share____getopt_initialized = 1; - } - - /* Test whether ARGV[share__optind] points to a non-option argument. - Either it does not have option syntax, or there is an environment flag - from the shell indicating it is not an option. The later information - is only used when the used in the GNU libc. */ -#ifdef _LIBC -# define NONOPTION_P (argv[share__optind][0] != '-' || argv[share__optind][1] == '\0' \ - || (share__optind < nonoption_flags_len \ - && __getopt_nonoption_flags[share__optind] == '1')) -#else -# define NONOPTION_P (argv[share__optind][0] != '-' || argv[share__optind][1] == '\0') -#endif - - if (nextchar == NULL || *nextchar == '\0') - { - /* Advance to the next ARGV-element. */ - - /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been - moved back by the user (who may also have changed the arguments). */ - if (last_nonopt > share__optind) - last_nonopt = share__optind; - if (first_nonopt > share__optind) - first_nonopt = share__optind; - - if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - exchange them so that the options come first. */ - - if (first_nonopt != last_nonopt && last_nonopt != share__optind) - exchange ((char **) argv); - else if (last_nonopt != share__optind) - first_nonopt = share__optind; - - /* Skip any additional non-options - and extend the range of non-options previously skipped. */ - - while (share__optind < argc && NONOPTION_P) - share__optind++; - last_nonopt = share__optind; - } - - /* The special ARGV-element `--' means premature end of options. - Skip it like a null option, - then exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ - - if (share__optind != argc && !strcmp (argv[share__optind], "--")) - { - share__optind++; - - if (first_nonopt != last_nonopt && last_nonopt != share__optind) - exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = share__optind; - last_nonopt = argc; - - share__optind = argc; - } - - /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ - - if (share__optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - share__optind = first_nonopt; - return -1; - } - - /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ - - if (NONOPTION_P) - { - if (ordering == REQUIRE_ORDER) - return -1; - share__optarg = argv[share__optind++]; - return 1; - } - - /* We have found another option-ARGV-element. - Skip the initial punctuation. */ - - nextchar = (argv[share__optind] + 1 - + (longopts != NULL && argv[share__optind][1] == '-')); - } - - /* Decode the current option-ARGV-element. */ - - /* Check whether the ARGV-element is a long option. - - If long_only and the ARGV-element has the form "-f", where f is - a valid short option, don't consider it an abbreviated form of - a long option that starts with f. Otherwise there would be no - way to give the -f short option. - - On the other hand, if there's a long option "fubar" and - the ARGV-element is "-fu", do consider that an abbreviation of - the long option, just like "--fu", and not "-f" with arg "u". - - This distinction seems to be the most useful approach. */ - - if (longopts != NULL - && (argv[share__optind][1] == '-' - || (long_only && (argv[share__optind][2] || !my_index (optstring, argv[share__optind][1]))))) - { - char *nameend; - const struct share__option *p; - const struct share__option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((size_t) (nameend - nextchar) == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - - if (ambig && !exact) - { - if (share__opterr) - fprintf (stderr, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[share__optind]); - nextchar += strlen (nextchar); - share__optind++; - share__optopt = 0; - return '?'; - } - - if (pfound != NULL) - { - option_index = indfound; - share__optind++; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - share__optarg = nameend + 1; - else - { - if (share__opterr) - { - if (argv[share__optind - 1][1] == '-') - /* --option */ - fprintf (stderr, - _("%s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - _("%s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[share__optind - 1][0], pfound->name); - } - - nextchar += strlen (nextchar); - - share__optopt = pfound->val; - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (share__optind < argc) - share__optarg = argv[share__optind++]; - else - { - if (share__opterr) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[share__optind - 1]); - nextchar += strlen (nextchar); - share__optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - - /* Can't find it as a long option. If this is not share__getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ - if (!long_only || argv[share__optind][1] == '-' - || my_index (optstring, *nextchar) == NULL) - { - if (share__opterr) - { - if (argv[share__optind][1] == '-') - /* --option */ - fprintf (stderr, _("%s: unrecognized option `--%s'\n"), - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), - argv[0], argv[share__optind][0], nextchar); - } - nextchar = (char *) ""; - share__optind++; - share__optopt = 0; - return '?'; - } - } - - /* Look at and handle the next short option-character. */ - - { - char c = *nextchar++; - char *temp = my_index (optstring, c); - - /* Increment `share__optind' when we start to process its last character. */ - if (*nextchar == '\0') - ++share__optind; - - if (temp == NULL || c == ':') - { - if (share__opterr) - { - if (posixly_correct) - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: illegal option -- %c\n"), - argv[0], c); - else - fprintf (stderr, _("%s: invalid option -- %c\n"), - argv[0], c); - } - share__optopt = c; - return '?'; - } - /* Convenience. Treat POSIX -W foo same as long option --foo */ - if (temp[0] == 'W' && temp[1] == ';') - { - char *nameend; - const struct share__option *p; - const struct share__option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = 0; - int option_index; - - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - share__optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - share__optind++; - } - else if (share__optind == argc) - { - if (share__opterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - share__optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - return c; - } - else - /* We already incremented `share__optind' once; - increment it again when taking next ARGV-elt as argument. */ - share__optarg = argv[share__optind++]; - - /* share__optarg is now the argument, see if it's in the - table of longopts. */ - - for (nextchar = nameend = share__optarg; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((size_t) (nameend - nextchar) == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) - { - if (share__opterr) - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[share__optind]); - nextchar += strlen (nextchar); - share__optind++; - return '?'; - } - if (pfound != NULL) - { - option_index = indfound; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - share__optarg = nameend + 1; - else - { - if (share__opterr) - fprintf (stderr, _("\ -%s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name); - - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (share__optind < argc) - share__optarg = argv[share__optind++]; - else - { - if (share__opterr) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[share__optind - 1]); - nextchar += strlen (nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - nextchar = NULL; - return 'W'; /* Let the application handle it. */ - } - if (temp[1] == ':') - { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - share__optarg = nextchar; - share__optind++; - } - else - share__optarg = NULL; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - share__optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - share__optind++; - } - else if (share__optind == argc) - { - if (share__opterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, - _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - share__optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `share__optind' once; - increment it again when taking next ARGV-elt as argument. */ - share__optarg = argv[share__optind++]; - nextchar = NULL; - } - } - return c; - } -} - -int -share__getopt (int argc, char *const *argv, const char *optstring) -{ - return share___getopt_internal (argc, argv, optstring, - (const struct share__option *) 0, - (int *) 0, - 0); -} - -#endif /* Not ELIDE_CODE. */ - -#ifdef TEST - -/* Compile with -DTEST to make an executable for use in testing - the above definition of `share__getopt'. */ - -int -main (int argc, char **argv) -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = share__optind ? share__optind : 1; - - c = share__getopt (argc, argv, "abc:d:0123456789"); - if (c == -1) - break; - - switch (c) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", share__optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (share__optind < argc) - { - printf ("non-option ARGV-elements: "); - while (share__optind < argc) - printf ("%s ", argv[share__optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/flac/src/share/getopt/getopt1.c b/flac/src/share/getopt/getopt1.c deleted file mode 100644 index fc52678..0000000 --- a/flac/src/share/getopt/getopt1.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - NOTE: - I cannot get the vanilla getopt code to work (i.e. compile only what - is needed and not duplicate symbols found in the standard library) - on all the platforms that FLAC supports. In particular the gating - of code with the ELIDE_CODE #define is not accurate enough on systems - that are POSIX but not glibc. If someone has a patch that works on - GNU/Linux, Darwin, AND Solaris please submit it on the project page: - https://sourceforge.net/p/flac/patches/ - - In the meantime I have munged the global symbols and removed gates - around code, while at the same time trying to touch the original as - little as possible. -*/ -/* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 - Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#if !defined __STDC__ || !__STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - -#include - -#include "share/getopt.h" -/*[JEC] was:#include "getopt.h"*/ - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#define GETOPT_INTERFACE_VERSION 2 -#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 -#include -#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION -#define ELIDE_CODE -#endif -#endif - -#if 1 -/*[JEC] was:#ifndef ELIDE_CODE*/ - - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -#include -#endif - -#ifndef NULL -#define NULL 0 -#endif - -int share__getopt_long(int argc, char *const *argv, const char *options, const struct share__option *long_options, int *opt_index) -{ - return share___getopt_internal (argc, argv, options, long_options, opt_index, 0); -} - -/* Like share__getopt_long, but '-' as well as '--' can indicate a long option. - If an option that starts with '-' (not '--') doesn't match a long option, - but does match a short option, it is parsed as a short option - instead. */ - -int share__getopt_long_only(int argc, char *const *argv, const char *options, const struct share__option *long_options, int *opt_index) -{ - return share___getopt_internal (argc, argv, options, long_options, opt_index, 1); -} - - -#endif /* Not ELIDE_CODE. */ - -#ifdef TEST - -#include - -int main(int argc, char **argv) -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = share__optind ? share__optind : 1; - int option_index = 0; - static struct share__option long_options[] = - { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} - }; - - c = share__getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (share__optarg) - printf (" with arg %s", share__optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", share__optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", share__optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (share__optind < argc) - { - printf ("non-option ARGV-elements: "); - while (share__optind < argc) - printf ("%s ", argv[share__optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/flac/src/share/grabbag/CMakeLists.txt b/flac/src/share/grabbag/CMakeLists.txt deleted file mode 100644 index 203ae3f..0000000 --- a/flac/src/share/grabbag/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_library(grabbag STATIC - alloc.c - cuesheet.c - file.c - picture.c - replaygain.c - seektable.c - snprintf.c) -target_link_libraries(grabbag PUBLIC - FLAC - replaygain_analysis) -if(TARGET win_utf8_io) - target_link_libraries(grabbag PUBLIC win_utf8_io) -endif() diff --git a/flac/src/share/grabbag/alloc.c b/flac/src/share/grabbag/alloc.c deleted file mode 100644 index 4e5fb60..0000000 --- a/flac/src/share/grabbag/alloc.c +++ /dev/null @@ -1,48 +0,0 @@ -/* alloc - Convenience routines for safely allocating memory - * Copyright (C) 2007-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "share/alloc.h" - -void *safe_malloc_mul_2op_(size_t size1, size_t size2) -{ - if(!size1 || !size2) - return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */ - if(size1 > SIZE_MAX / size2) - return 0; - return malloc(size1*size2); -} diff --git a/flac/src/share/grabbag/cuesheet.c b/flac/src/share/grabbag/cuesheet.c deleted file mode 100644 index 0d19ee7..0000000 --- a/flac/src/share/grabbag/cuesheet.c +++ /dev/null @@ -1,681 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include "FLAC/assert.h" -#include "share/compat.h" -#include "share/grabbag.h" -#include "share/safe_str.h" - -uint32_t grabbag__cuesheet_msf_to_frame(uint32_t minutes, uint32_t seconds, uint32_t frames) -{ - return ((minutes * 60) + seconds) * 75 + frames; -} - -void grabbag__cuesheet_frame_to_msf(uint32_t frame, uint32_t *minutes, uint32_t *seconds, uint32_t *frames) -{ - *frames = frame % 75; - frame /= 75; - *seconds = frame % 60; - frame /= 60; - *minutes = frame; -} - -/* since we only care about values >= 0 or error, returns < 0 for any illegal string, else value */ -static FLAC__int64 local__parse_int64_(const char *s) -{ - FLAC__int64 ret = 0; - char c; - - if(*s == '\0') - return -1; - - while('\0' != (c = *s++)) - if(c >= '0' && c <= '9') { - if(ret >= (INT64_MAX / 10)) - return -1; - else - ret = ret * 10 + (c - '0'); - } - else - return -1; - - return ret; -} - -/* since we only care about values >= 0 or error, returns < 0 for any illegal string, else value */ -static int local__parse_int_(const char *s) -{ - FLAC__int64 ret64 = local__parse_int64_(s); - if(ret64 < 0 || ret64 > INT_MAX) - return -1; - return ret64; -} - -/* accept minute:second:frame syntax of '[0-9]+:[0-9][0-9]?:[0-9][0-9]?', but max second of 59 and max frame of 74, e.g. 0:0:0, 123:45:67 - * return sample number or <0 for error - * WATCHOUT: if sample rate is not evenly divisible by 75, the resulting sample number will be approximate - */ -static FLAC__int64 local__parse_msf_(const char *s, uint32_t sample_rate) -{ - FLAC__int64 ret, field; - char c; - - if(sample_rate == 0) - return -1; - - c = *s++; - if(c >= '0' && c <= '9') - field = (c - '0'); - else - return -1; - while(':' != (c = *s++)) { - if(c >= '0' && c <= '9') { - if(field >= (INT64_MAX / 10)) - return -1; - else - field = field * 10 + (c - '0'); - } - else - return -1; - } - - if(field >= INT64_MAX / (60 * sample_rate)) - return -1; - ret = field * 60 * sample_rate; - - c = *s++; - if(c >= '0' && c <= '9') - field = (c - '0'); - else - return -1; - if(':' != (c = *s++)) { - if(c >= '0' && c <= '9') { - field = field * 10 + (c - '0'); - c = *s++; - if(c != ':') - return -1; - } - else - return -1; - } - - if(field >= 60) - return -1; - - { - FLAC__int64 tmp = ret; - ret += field * sample_rate; - if(ret < tmp) - return -1; - } - - c = *s++; - if(c >= '0' && c <= '9') - field = (c - '0'); - else - return -1; - if('\0' != (c = *s++)) { - if(c >= '0' && c <= '9') { - field = field * 10 + (c - '0'); - c = *s++; - } - else - return -1; - } - - if(c != '\0') - return -1; - - if(field >= 75) - return -1; - - { - FLAC__int64 tmp = ret; - ret += field * (sample_rate / 75); - if(ret < tmp) - return -1; - } - - return ret; -} - -/* accept minute:second syntax of '[0-9]+:[0-9][0-9]?{,.[0-9]+}', but second < 60, e.g. 0:0.0, 3:5, 15:31.731 - * return sample number or <0 for error - * WATCHOUT: depending on the sample rate, the resulting sample number may be approximate with fractional seconds - */ -static FLAC__int64 local__parse_ms_(const char *s, uint32_t sample_rate) -{ - FLAC__int64 ret, field; - double x; - char c, *end; - - if(sample_rate == 0) - return -1; - - c = *s++; - if(c >= '0' && c <= '9') - field = (c - '0'); - else - return -1; - while(':' != (c = *s++)) { - if(c >= '0' && c <= '9') { - if(field >= (INT64_MAX / 10)) - return -1; - else - field = field * 10 + (c - '0'); - } - else - return -1; - } - - if(field >= INT64_MAX / (60 * sample_rate)) - return -1; - ret = field * 60 * sample_rate; - - if(strspn(s, "0123456789.") != strlen(s)) - return -1; - x = strtod(s, &end); - if(*end || end == s) - return -1; - if(x < 0.0 || x >= 60.0) - return -1; - - ret += (FLAC__int64)(x * sample_rate); - - return ret; -} - -static char *local__get_field_(char **s, FLAC__bool allow_quotes) -{ - FLAC__bool has_quote = false; - char *p; - - FLAC__ASSERT(0 != s); - - if(0 == *s) - return 0; - - /* skip leading whitespace */ - while(**s && 0 != strchr(" \t\r\n", **s)) - (*s)++; - - if(**s == 0) { - *s = 0; - return 0; - } - - if(allow_quotes && (**s == '"')) { - has_quote = true; - (*s)++; - if(**s == 0) { - *s = 0; - return 0; - } - } - - p = *s; - - if(has_quote) { - *s = strchr(*s, '\"'); - /* if there is no matching end quote, it's an error */ - if(0 == *s) - p = *s = 0; - else { - **s = '\0'; - (*s)++; - } - } - else { - while(**s && 0 == strchr(" \t\r\n", **s)) - (*s)++; - if(**s) { - **s = '\0'; - (*s)++; - } - else - *s = 0; - } - - return p; -} - -static FLAC__bool local__cuesheet_parse_(FILE *file, const char **error_message, uint32_t *last_line_read, FLAC__StreamMetadata *cuesheet, uint32_t sample_rate, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset) -{ - char buffer[4096], *line, *field; - uint32_t forced_leadout_track_num = 0; - FLAC__uint64 forced_leadout_track_offset = 0; - int in_track_num = -1, in_index_num = -1; - FLAC__bool disc_has_catalog = false, track_has_flags = false, track_has_isrc = false, has_forced_leadout = false; - FLAC__StreamMetadata_CueSheet *cs = &cuesheet->data.cue_sheet; - - FLAC__ASSERT(!is_cdda || sample_rate == 44100); - /* double protection */ - if(is_cdda && sample_rate != 44100) { - *error_message = "CD-DA cuesheet only allowed with 44.1kHz sample rate"; - return false; - } - - cs->lead_in = is_cdda? 2 * 44100 /* The default lead-in size for CD-DA */ : 0; - cs->is_cd = is_cdda; - - while(0 != fgets(buffer, sizeof(buffer), file)) { - (*last_line_read)++; - line = buffer; - - { - size_t linelen = strlen(line); - if((linelen == sizeof(buffer)-1) && line[linelen-1] != '\n') { - *error_message = "line too long"; - return false; - } - } - - if(0 != (field = local__get_field_(&line, /*allow_quotes=*/false))) { - if(0 == FLAC__STRCASECMP(field, "CATALOG")) { - if(disc_has_catalog) { - *error_message = "found multiple CATALOG commands"; - return false; - } - if(0 == (field = local__get_field_(&line, /*allow_quotes=*/true))) { - *error_message = "CATALOG is missing catalog number"; - return false; - } - if(strlen(field) >= sizeof(cs->media_catalog_number)) { - *error_message = "CATALOG number is too long"; - return false; - } - if(is_cdda && (strlen(field) != 13 || strspn(field, "0123456789") != 13)) { - *error_message = "CD-DA CATALOG number must be 13 decimal digits"; - return false; - } - safe_strncpy(cs->media_catalog_number, field, sizeof(cs->media_catalog_number)); - disc_has_catalog = true; - } - else if(0 == FLAC__STRCASECMP(field, "FLAGS")) { - if(track_has_flags) { - *error_message = "found multiple FLAGS commands"; - return false; - } - if(in_track_num < 0 || in_index_num >= 0) { - *error_message = "FLAGS command must come after TRACK but before INDEX"; - return false; - } - while(0 != (field = local__get_field_(&line, /*allow_quotes=*/false))) { - if(0 == FLAC__STRCASECMP(field, "PRE")) - cs->tracks[cs->num_tracks-1].pre_emphasis = 1; - } - track_has_flags = true; - } - else if(0 == FLAC__STRCASECMP(field, "INDEX")) { - FLAC__int64 xx; - FLAC__StreamMetadata_CueSheet_Track *track = &cs->tracks[cs->num_tracks-1]; - if(in_track_num < 0) { - *error_message = "found INDEX before any TRACK"; - return false; - } - if(0 == (field = local__get_field_(&line, /*allow_quotes=*/false))) { - *error_message = "INDEX is missing index number"; - return false; - } - in_index_num = local__parse_int_(field); - if(in_index_num < 0) { - *error_message = "INDEX has invalid index number"; - return false; - } - FLAC__ASSERT(cs->num_tracks > 0); - if(track->num_indices == 0) { - /* it's the first index point of the track */ - if(in_index_num > 1) { - *error_message = "first INDEX number of a TRACK must be 0 or 1"; - return false; - } - } - else { - if(in_index_num != track->indices[track->num_indices-1].number + 1) { - *error_message = "INDEX numbers must be sequential"; - return false; - } - } - if(is_cdda && in_index_num > 99) { - *error_message = "CD-DA INDEX number must be between 0 and 99, inclusive"; - return false; - } - /*@@@ search for duplicate track number? */ - if(0 == (field = local__get_field_(&line, /*allow_quotes=*/false))) { - *error_message = "INDEX is missing an offset after the index number"; - return false; - } - /* first parse as minute:second:frame format */ - xx = local__parse_msf_(field, sample_rate); - if(xx < 0) { - /* CD-DA must use only MM:SS:FF format */ - if(is_cdda) { - *error_message = "illegal INDEX offset (not of the form MM:SS:FF)"; - return false; - } - /* as an extension for non-CD-DA we allow MM:SS.SS or raw sample number */ - xx = local__parse_ms_(field, sample_rate); - if(xx < 0) { - xx = local__parse_int64_(field); - if(xx < 0) { - *error_message = "illegal INDEX offset"; - return false; - } - } - } - else if(sample_rate % 75 && xx) { - /* only sample zero is exact */ - *error_message = "illegal INDEX offset (MM:SS:FF form not allowed if sample rate is not a multiple of 75)"; - return false; - } - if(is_cdda && cs->num_tracks == 1 && cs->tracks[0].num_indices == 0 && xx != 0) { - *error_message = "first INDEX of first TRACK must have an offset of 00:00:00"; - return false; - } - if(is_cdda && track->num_indices > 0 && (FLAC__uint64)xx <= track->indices[track->num_indices-1].offset) { - *error_message = "CD-DA INDEX offsets must increase in time"; - return false; - } - /* fill in track offset if it's the first index of the track */ - if(track->num_indices == 0) - track->offset = (FLAC__uint64)xx; - if(is_cdda && cs->num_tracks > 1) { - const FLAC__StreamMetadata_CueSheet_Track *prev = &cs->tracks[cs->num_tracks-2]; - if((FLAC__uint64)xx <= prev->offset + prev->indices[prev->num_indices-1].offset) { - *error_message = "CD-DA INDEX offsets must increase in time"; - return false; - } - } - if(!FLAC__metadata_object_cuesheet_track_insert_blank_index(cuesheet, cs->num_tracks-1, track->num_indices)) { - *error_message = "memory allocation error"; - return false; - } - track->indices[track->num_indices-1].offset = (FLAC__uint64)xx - track->offset; - track->indices[track->num_indices-1].number = in_index_num; - } - else if(0 == FLAC__STRCASECMP(field, "ISRC")) { - char *l, *r; - if(track_has_isrc) { - *error_message = "found multiple ISRC commands"; - return false; - } - if(in_track_num < 0 || in_index_num >= 0) { - *error_message = "ISRC command must come after TRACK but before INDEX"; - return false; - } - if(0 == (field = local__get_field_(&line, /*allow_quotes=*/true))) { - *error_message = "ISRC is missing ISRC number"; - return false; - } - /* strip out dashes */ - for(l = r = field; *r; r++) { - if(*r != '-') - *l++ = *r; - } - *l = '\0'; - if(strlen(field) != 12 || strspn(field, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") < 5 || strspn(field+5, "1234567890") != 7) { - *error_message = "invalid ISRC number"; - return false; - } - safe_strncpy(cs->tracks[cs->num_tracks-1].isrc, field, sizeof(cs->tracks[cs->num_tracks-1].isrc)); - track_has_isrc = true; - } - else if(0 == FLAC__STRCASECMP(field, "TRACK")) { - if(cs->num_tracks > 0) { - const FLAC__StreamMetadata_CueSheet_Track *prev = &cs->tracks[cs->num_tracks-1]; - if( - prev->num_indices == 0 || - ( - is_cdda && - ( - (prev->num_indices == 1 && prev->indices[0].number != 1) || - (prev->num_indices == 2 && prev->indices[0].number != 1 && prev->indices[1].number != 1) - ) - ) - ) { - *error_message = is_cdda? - "previous TRACK must specify at least one INDEX 01" : - "previous TRACK must specify at least one INDEX"; - return false; - } - } - if(0 == (field = local__get_field_(&line, /*allow_quotes=*/false))) { - *error_message = "TRACK is missing track number"; - return false; - } - in_track_num = local__parse_int_(field); - if(in_track_num < 0) { - *error_message = "TRACK has invalid track number"; - return false; - } - if(in_track_num == 0) { - *error_message = "TRACK number must be greater than 0"; - return false; - } - if(is_cdda) { - if(in_track_num > 99) { - *error_message = "CD-DA TRACK number must be between 1 and 99, inclusive"; - return false; - } - } - else { - if(in_track_num == 255) { - *error_message = "TRACK number 255 is reserved for the lead-out"; - return false; - } - else if(in_track_num > 255) { - *error_message = "TRACK number must be between 1 and 254, inclusive"; - return false; - } - } - if(is_cdda && cs->num_tracks > 0 && in_track_num != cs->tracks[cs->num_tracks-1].number + 1) { - *error_message = "CD-DA TRACK numbers must be sequential"; - return false; - } - /*@@@ search for duplicate track number? */ - if(0 == (field = local__get_field_(&line, /*allow_quotes=*/false))) { - *error_message = "TRACK is missing a track type after the track number"; - return false; - } - if(!FLAC__metadata_object_cuesheet_insert_blank_track(cuesheet, cs->num_tracks)) { - *error_message = "memory allocation error"; - return false; - } - cs->tracks[cs->num_tracks-1].number = in_track_num; - cs->tracks[cs->num_tracks-1].type = (0 == FLAC__STRCASECMP(field, "AUDIO"))? 0 : 1; /*@@@ should we be more strict with the value here? */ - in_index_num = -1; - track_has_flags = false; - track_has_isrc = false; - } - else if(0 == FLAC__STRCASECMP(field, "REM")) { - if(0 != (field = local__get_field_(&line, /*allow_quotes=*/false))) { - if(0 == strcmp(field, "FLAC__lead-in")) { - FLAC__int64 xx; - if(0 == (field = local__get_field_(&line, /*allow_quotes=*/false))) { - *error_message = "FLAC__lead-in is missing offset"; - return false; - } - xx = local__parse_int64_(field); - if(xx < 0) { - *error_message = "illegal FLAC__lead-in offset"; - return false; - } - if(is_cdda && xx % 588 != 0) { - *error_message = "illegal CD-DA FLAC__lead-in offset, must be even multiple of 588 samples"; - return false; - } - cs->lead_in = (FLAC__uint64)xx; - } - else if(0 == strcmp(field, "FLAC__lead-out")) { - int track_num; - FLAC__int64 offset; - if(has_forced_leadout) { - *error_message = "multiple FLAC__lead-out commands"; - return false; - } - if(0 == (field = local__get_field_(&line, /*allow_quotes=*/false))) { - *error_message = "FLAC__lead-out is missing track number"; - return false; - } - track_num = local__parse_int_(field); - if(track_num < 0) { - *error_message = "illegal FLAC__lead-out track number"; - return false; - } - forced_leadout_track_num = (uint32_t)track_num; - /*@@@ search for duplicate track number? */ - if(0 == (field = local__get_field_(&line, /*allow_quotes=*/false))) { - *error_message = "FLAC__lead-out is missing offset"; - return false; - } - offset = local__parse_int64_(field); - if(offset < 0) { - *error_message = "illegal FLAC__lead-out offset"; - return false; - } - forced_leadout_track_offset = (FLAC__uint64)offset; - if(forced_leadout_track_offset != lead_out_offset) { - *error_message = "FLAC__lead-out offset does not match end-of-stream offset"; - return false; - } - has_forced_leadout = true; - } - } - } - } - } - - if(cs->num_tracks == 0) { - *error_message = "there must be at least one TRACK command"; - return false; - } - else { - const FLAC__StreamMetadata_CueSheet_Track *prev = &cs->tracks[cs->num_tracks-1]; - if( - prev->num_indices == 0 || - ( - is_cdda && - ( - (prev->num_indices == 1 && prev->indices[0].number != 1) || - (prev->num_indices == 2 && prev->indices[0].number != 1 && prev->indices[1].number != 1) - ) - ) - ) { - *error_message = is_cdda? - "previous TRACK must specify at least one INDEX 01" : - "previous TRACK must specify at least one INDEX"; - return false; - } - } - - if(!has_forced_leadout) { - forced_leadout_track_num = is_cdda? 170 : 255; - forced_leadout_track_offset = lead_out_offset; - } - if(!FLAC__metadata_object_cuesheet_insert_blank_track(cuesheet, cs->num_tracks)) { - *error_message = "memory allocation error"; - return false; - } - cs->tracks[cs->num_tracks-1].number = forced_leadout_track_num; - cs->tracks[cs->num_tracks-1].offset = forced_leadout_track_offset; - - if(!feof(file)) { - *error_message = "read error"; - return false; - } - return true; -} - -FLAC__StreamMetadata *grabbag__cuesheet_parse(FILE *file, const char **error_message, uint32_t *last_line_read, uint32_t sample_rate, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset) -{ - FLAC__StreamMetadata *cuesheet; - - FLAC__ASSERT(0 != file); - FLAC__ASSERT(0 != error_message); - FLAC__ASSERT(0 != last_line_read); - - *last_line_read = 0; - cuesheet = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET); - - if(0 == cuesheet) { - *error_message = "memory allocation error"; - return 0; - } - - if(!local__cuesheet_parse_(file, error_message, last_line_read, cuesheet, sample_rate, is_cdda, lead_out_offset)) { - FLAC__metadata_object_delete(cuesheet); - return 0; - } - - return cuesheet; -} - -void grabbag__cuesheet_emit(FILE *file, const FLAC__StreamMetadata *cuesheet, const char *file_reference) -{ - const FLAC__StreamMetadata_CueSheet *cs; - uint32_t track_num, index_num; - - FLAC__ASSERT(0 != file); - FLAC__ASSERT(0 != cuesheet); - FLAC__ASSERT(cuesheet->type == FLAC__METADATA_TYPE_CUESHEET); - - cs = &cuesheet->data.cue_sheet; - - if(*(cs->media_catalog_number)) - fprintf(file, "CATALOG %s\n", cs->media_catalog_number); - fprintf(file, "FILE %s\n", file_reference); - - FLAC__ASSERT(cs->num_tracks > 0); - - for(track_num = 0; track_num < cs->num_tracks-1; track_num++) { - const FLAC__StreamMetadata_CueSheet_Track *track = cs->tracks + track_num; - - fprintf(file, " TRACK %02u %s\n", (uint32_t)track->number, track->type == 0? "AUDIO" : "DATA"); - - if(track->pre_emphasis) - fprintf(file, " FLAGS PRE\n"); - if(*(track->isrc)) - fprintf(file, " ISRC %s\n", track->isrc); - - for(index_num = 0; index_num < track->num_indices; index_num++) { - const FLAC__StreamMetadata_CueSheet_Index *indx = track->indices + index_num; - - fprintf(file, " INDEX %02u ", (uint32_t)indx->number); - if(cs->is_cd) { - const uint32_t logical_frame = (uint32_t)((track->offset + indx->offset) / (44100 / 75)); - uint32_t m, s, f; - grabbag__cuesheet_frame_to_msf(logical_frame, &m, &s, &f); - fprintf(file, "%02u:%02u:%02u\n", m, s, f); - } - else - fprintf(file, "%" PRIu64 "\n", (track->offset + indx->offset)); - } - } - - fprintf(file, "REM FLAC__lead-in %" PRIu64 "\n", cs->lead_in); - fprintf(file, "REM FLAC__lead-out %u %" PRIu64 "\n", (uint32_t)cs->tracks[track_num].number, cs->tracks[track_num].offset); -} diff --git a/flac/src/share/grabbag/file.c b/flac/src/share/grabbag/file.c deleted file mode 100644 index 307645f..0000000 --- a/flac/src/share/grabbag/file.c +++ /dev/null @@ -1,207 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#if defined _MSC_VER || defined __MINGW32__ -#include /* for utime() */ -#include /* for chmod(), _setmode(), unlink() */ -#include /* for _O_BINARY */ -#else -#include /* some flavors of BSD (like OS X) require this to get time_t */ -#endif -#if defined __EMX__ -#include /* for setmode(), O_BINARY */ -#include /* for _O_BINARY */ -#endif -#include /* for stat(), maybe chmod() */ -#if defined _WIN32 && !defined __CYGWIN__ -#else -#include /* for unlink() */ -#endif -#include -#include -#include /* for strrchr() */ -#if defined _WIN32 && !defined __CYGWIN__ -// for GetFileInformationByHandle() etc -#include -#include -#endif -#include "share/grabbag.h" -#include "share/compat.h" - - -void grabbag__file_copy_metadata(const char *srcpath, const char *destpath) -{ - struct flac_stat_s srcstat; - - if(0 == flac_stat(srcpath, &srcstat)) { -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) && !defined(_WIN32) - struct timespec srctime[2] = {}; - srctime[0].tv_sec = srcstat.st_atime; - srctime[1].tv_sec = srcstat.st_mtime; -#else - struct utimbuf srctime; - srctime.actime = srcstat.st_atime; - srctime.modtime = srcstat.st_mtime; -#endif - (void)flac_chmod(destpath, srcstat.st_mode); - (void)flac_utime(destpath, &srctime); - } -} - -FLAC__off_t grabbag__file_get_filesize(const char *srcpath) -{ - struct flac_stat_s srcstat; - - if(0 == flac_stat(srcpath, &srcstat)) - return srcstat.st_size; - else - return -1; -} - -const char *grabbag__file_get_basename(const char *srcpath) -{ - const char *p; - - p = strrchr(srcpath, '/'); - if(0 == p) { -#if defined _WIN32 && !defined __CYGWIN__ - p = strrchr(srcpath, '\\'); - if(0 == p) -#endif - return srcpath; - } - return ++p; -} - -FLAC__bool grabbag__file_change_stats(const char *filename, FLAC__bool read_only) -{ - struct flac_stat_s stats; - - if(0 == flac_stat(filename, &stats)) { -#if !defined _MSC_VER && !defined __MINGW32__ - if(read_only) { - stats.st_mode &= ~S_IWUSR; - stats.st_mode &= ~S_IWGRP; - stats.st_mode &= ~S_IWOTH; - } - else { - stats.st_mode |= S_IWUSR; - } -#else - if(read_only) - stats.st_mode &= ~S_IWRITE; - else - stats.st_mode |= S_IWRITE; -#endif - if(0 != flac_chmod(filename, stats.st_mode)) - return false; - } - else - return false; - - return true; -} - -FLAC__bool grabbag__file_are_same(const char *f1, const char *f2) -{ -#if defined _WIN32 && !defined __CYGWIN__ -#if !defined(WINAPI_FAMILY_PARTITION) -#define WINAPI_FAMILY_PARTITION(x) x -#define WINAPI_PARTITION_DESKTOP 1 -#endif - /* see - * http://www.hydrogenaudio.org/forums/index.php?showtopic=49439&pid=444300&st=0 - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileinformationbyhandle.asp - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/by_handle_file_information_str.asp - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp - * apparently both the files have to be open at the same time for the comparison to work - */ - FLAC__bool same = false; - BY_HANDLE_FILE_INFORMATION info1, info2; - HANDLE h1, h2; - BOOL ok = 1; - h1 = CreateFile_utf8(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - h2 = CreateFile_utf8(f2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if(h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE) - ok = 0; -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - ok &= GetFileInformationByHandle(h1, &info1); - ok &= GetFileInformationByHandle(h2, &info2); - if(ok) - same = - info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber && - info1.nFileIndexHigh == info2.nFileIndexHigh && - info1.nFileIndexLow == info2.nFileIndexLow - ; -#else // !WINAPI_PARTITION_DESKTOP - FILE_ID_INFO id_info1, id_info2; - same = GetFileInformationByHandleEx(h1, FileIdInfo, &id_info1, sizeof (id_info1)) && - GetFileInformationByHandleEx(h2, FileIdInfo, &id_info2, sizeof (id_info2)) && - id_info1.VolumeSerialNumber == id_info2.VolumeSerialNumber && - memcmp(&id_info1.FileId, &id_info2.FileId, sizeof(id_info1.FileId)) == 0; -#endif // !WINAPI_PARTITION_DESKTOP - if(h1 != INVALID_HANDLE_VALUE) - CloseHandle(h1); - if(h2 != INVALID_HANDLE_VALUE) - CloseHandle(h2); - return same; -#else - struct flac_stat_s s1, s2; - return f1 && f2 && flac_stat(f1, &s1) == 0 && flac_stat(f2, &s2) == 0 && s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev; -#endif -} - -FLAC__bool grabbag__file_remove_file(const char *filename) -{ - return grabbag__file_change_stats(filename, /*read_only=*/false) && 0 == flac_unlink(filename); -} - -FILE *grabbag__file_get_binary_stdin(void) -{ - /* if something breaks here it is probably due to the presence or - * absence of an underscore before the identifiers 'setmode', - * 'fileno', and/or 'O_BINARY'; check your system header files. - */ -#if defined _MSC_VER || defined __MINGW32__ - _setmode(_fileno(stdin), _O_BINARY); -#elif defined __EMX__ - setmode(fileno(stdin), O_BINARY); -#endif - - return stdin; -} - -FILE *grabbag__file_get_binary_stdout(void) -{ - /* if something breaks here it is probably due to the presence or - * absence of an underscore before the identifiers 'setmode', - * 'fileno', and/or 'O_BINARY'; check your system header files. - */ -#if defined _MSC_VER || defined __MINGW32__ - _setmode(_fileno(stdout), _O_BINARY); -#elif defined __EMX__ - setmode(fileno(stdout), O_BINARY); -#endif - - return stdout; -} diff --git a/flac/src/share/grabbag/picture.c b/flac/src/share/grabbag/picture.c deleted file mode 100644 index 9a4aafe..0000000 --- a/flac/src/share/grabbag/picture.c +++ /dev/null @@ -1,515 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2006-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "share/alloc.h" -#include "share/grabbag.h" -#include "FLAC/assert.h" -#include -#include -#include -#include "share/compat.h" -#include "share/safe_str.h" - -/* slightly different that strndup(): this always copies 'size' bytes starting from s into a NUL-terminated string. */ -static char *local__strndup_(const char *s, size_t size) -{ - char *x = safe_malloc_add_2op_(size, /*+*/1); - if(x) { - memcpy(x, s, size); - x[size] = '\0'; - } - return x; -} - -static FLAC__bool local__parse_type_(const char *s, size_t len, FLAC__StreamMetadata_Picture *picture) -{ - size_t i; - FLAC__uint32 val = 0; - - picture->type = FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER; - - if(len == 0) - return true; /* empty string implies default to 'front cover' */ - - for(i = 0; i < len; i++) { - if(s[i] >= '0' && s[i] <= '9') - val = 10*val + (FLAC__uint32)(s[i] - '0'); - else - return false; - } - - if(i == len) - picture->type = val; - else - return false; - - return true; -} - -static FLAC__bool local__parse_resolution_(const char *s, size_t len, FLAC__StreamMetadata_Picture *picture) -{ - int state = 0; - size_t i; - FLAC__uint32 val = 0; - - picture->width = picture->height = picture->depth = picture->colors = 0; - - if(len == 0) - return true; /* empty string implies client wants to get info from the file itself */ - - for(i = 0; i < len; i++) { - if(s[i] == 'x') { - if(state == 0) - picture->width = val; - else if(state == 1) - picture->height = val; - else - return false; - state++; - val = 0; - } - else if(s[i] == '/') { - if(state == 2) - picture->depth = val; - else - return false; - state++; - val = 0; - } - else if(s[i] >= '0' && s[i] <= '9') - val = 10*val + (FLAC__uint32)(s[i] - '0'); - else - return false; - } - - if(state < 2) - return false; - else if(state == 2) - picture->depth = val; - else if(state == 3) - picture->colors = val; - else - return false; - if(picture->depth < 32 && 1u<depth < picture->colors) - return false; - - return true; -} - -static FLAC__bool local__extract_mime_type_(FLAC__StreamMetadata *obj) -{ - if(obj->data.picture.data_length >= 8 && 0 == memcmp(obj->data.picture.data, "\x89PNG\x0d\x0a\x1a\x0a", 8)) - return FLAC__metadata_object_picture_set_mime_type(obj, "image/png", /*copy=*/true); - else if(obj->data.picture.data_length >= 6 && (0 == memcmp(obj->data.picture.data, "GIF87a", 6) || 0 == memcmp(obj->data.picture.data, "GIF89a", 6))) - return FLAC__metadata_object_picture_set_mime_type(obj, "image/gif", /*copy=*/true); - else if(obj->data.picture.data_length >= 2 && 0 == memcmp(obj->data.picture.data, "\xff\xd8", 2)) - return FLAC__metadata_object_picture_set_mime_type(obj, "image/jpeg", /*copy=*/true); - return false; -} - -static FLAC__bool local__extract_resolution_color_info_(FLAC__StreamMetadata_Picture *picture) -{ - const FLAC__byte *data = picture->data; - FLAC__uint32 len = picture->data_length; - - if(0 == strcmp(picture->mime_type, "image/png")) { - /* c.f. http://www.w3.org/TR/PNG/ */ - FLAC__bool need_palette = false; /* if IHDR has color_type=3, we need to also read the PLTE chunk to get the #colors */ - if(len < 8 || memcmp(data, "\x89PNG\x0d\x0a\x1a\x0a", 8)) - return false; - /* try to find IHDR chunk */ - data += 8; - len -= 8; - while(len > 12) { /* every PNG chunk must be at least 12 bytes long */ - const FLAC__uint32 clen = (FLAC__uint32)data[0] << 24 | (FLAC__uint32)data[1] << 16 | (FLAC__uint32)data[2] << 8 | (FLAC__uint32)data[3]; - /* First check whether clen makes sense or causes overflow in this bit of code */ - if(clen + 12 <= clen || clen + 12 > len) - return false; - else if(0 == memcmp(data+4, "IHDR", 4) && clen == 13) { - uint32_t color_type = data[17]; - picture->width = (FLAC__uint32)data[8] << 24 | (FLAC__uint32)data[9] << 16 | (FLAC__uint32)data[10] << 8 | (FLAC__uint32)data[11]; - picture->height = (FLAC__uint32)data[12] << 24 | (FLAC__uint32)data[13] << 16 | (FLAC__uint32)data[14] << 8 | (FLAC__uint32)data[15]; - if(color_type == 3) { - /* even though the bit depth for color_type==3 can be 1,2,4,or 8, - * the spec in 11.2.2 of http://www.w3.org/TR/PNG/ says that the - * sample depth is always 8 - */ - picture->depth = 8 * 3u; - need_palette = true; - data += 12 + clen; - len -= 12 + clen; - } - else { - if(color_type == 0) /* greyscale, 1 sample per pixel */ - picture->depth = (FLAC__uint32)data[16]; - if(color_type == 2) /* truecolor, 3 samples per pixel */ - picture->depth = (FLAC__uint32)data[16] * 3u; - if(color_type == 4) /* greyscale+alpha, 2 samples per pixel */ - picture->depth = (FLAC__uint32)data[16] * 2u; - if(color_type == 6) /* truecolor+alpha, 4 samples per pixel */ - picture->depth = (FLAC__uint32)data[16] * 4u; - picture->colors = 0; - return true; - } - } - else if(need_palette && 0 == memcmp(data+4, "PLTE", 4)) { - picture->colors = clen / 3u; - return true; - } - else { - data += 12 + clen; - len -= 12 + clen; - } - } - } - else if(0 == strcmp(picture->mime_type, "image/jpeg")) { - /* c.f. http://www.w3.org/Graphics/JPEG/itu-t81.pdf and Q22 of http://www.faqs.org/faqs/jpeg-faq/part1/ */ - if(len < 2 || memcmp(data, "\xff\xd8", 2)) - return false; - data += 2; - len -= 2; - while(1) { - /* look for sync FF byte */ - for( ; len > 0; data++, len--) { - if(*data == 0xff) - break; - } - if(len == 0) - return false; - /* eat any extra pad FF bytes before marker */ - for( ; len > 0; data++, len--) { - if(*data != 0xff) - break; - } - if(len == 0) - return false; - /* if we hit SOS or EOI, bail */ - if(*data == 0xda || *data == 0xd9) - return false; - /* looking for some SOFn */ - else if(memchr("\xc0\xc1\xc2\xc3\xc5\xc6\xc7\xc9\xca\xcb\xcd\xce\xcf", *data, 13)) { - data++; len--; /* skip marker byte */ - if(len < 2) - return false; - else { - const FLAC__uint32 clen = (FLAC__uint32)data[0] << 8 | (FLAC__uint32)data[1]; - if(clen < 8 || len < clen) - return false; - picture->width = (FLAC__uint32)data[5] << 8 | (FLAC__uint32)data[6]; - picture->height = (FLAC__uint32)data[3] << 8 | (FLAC__uint32)data[4]; - picture->depth = (FLAC__uint32)data[2] * (FLAC__uint32)data[7]; - picture->colors = 0; - return true; - } - } - /* else skip it */ - else { - data++; len--; /* skip marker byte */ - if(len < 2) - return false; - else { - const FLAC__uint32 clen = (FLAC__uint32)data[0] << 8 | (FLAC__uint32)data[1]; - if(clen < 2 || len < clen) - return false; - data += clen; - len -= clen; - } - } - } - } - else if(0 == strcmp(picture->mime_type, "image/gif")) { - /* c.f. http://www.w3.org/Graphics/GIF/spec-gif89a.txt */ - if(len < 14) - return false; - if(memcmp(data, "GIF87a", 6) && memcmp(data, "GIF89a", 6)) - return false; -#if 0 - /* according to the GIF spec, even if the GCTF is 0, the low 3 bits should still tell the total # colors used */ - if(data[10] & 0x80 == 0) - return false; -#endif - picture->width = (FLAC__uint32)data[6] | ((FLAC__uint32)data[7] << 8); - picture->height = (FLAC__uint32)data[8] | ((FLAC__uint32)data[9] << 8); -#if 0 - /* this value doesn't seem to be reliable... */ - picture->depth = (((FLAC__uint32)(data[10] & 0x70) >> 4) + 1) * 3u; -#else - /* ...just pessimistically assume it's 24-bit color without scanning all the color tables */ - picture->depth = 8u * 3u; -#endif - picture->colors = 1u << ((FLAC__uint32)(data[10] & 0x07) + 1u); - return true; - } - return false; -} - -static const char *error_messages[] = { - "memory allocation error", - "invalid picture specification", - "invalid picture specification: can't parse resolution/color part", - "unable to extract resolution and color info from URL, user must set explicitly", - "unable to extract resolution and color info from file, user must set explicitly", - "error opening picture file", - "error reading picture file", - "invalid picture type", - "unable to guess MIME type from file, user must set explicitly", - "type 1 icon must be a 32x32 pixel PNG", - "file not found", /* currently unused */ - "file is too large", - "empty file" -}; - -static const char * read_file (const char * filepath, FLAC__StreamMetadata * obj) -{ - const FLAC__off_t size = grabbag__file_get_filesize(filepath); - FLAC__byte *buffer; - FILE *file; - const char *error_message=NULL; - - if (size < 0) - return error_messages[5]; - - if (size == 0) - return error_messages[12]; - - if (size >= (FLAC__off_t)(1u << FLAC__STREAM_METADATA_LENGTH_LEN)) /* actual limit is less because of other fields in the PICTURE metadata block */ - return error_messages[11]; - - if ((buffer = safe_malloc_(size)) == NULL) - return error_messages[0]; - - if ((file = flac_fopen(filepath, "rb")) == NULL) { - free(buffer); - return error_messages[5]; - } - - if (fread(buffer, 1, size, file) != (size_t) size) { - fclose(file); - free(buffer); - return error_messages[6]; - } - fclose(file); - - if (!FLAC__metadata_object_picture_set_data(obj, buffer, (FLAC__uint32)size, /*copy=*/false)) - error_message = error_messages[6]; - /* try to extract MIME type if user left it blank */ - else if (*obj->data.picture.mime_type == '\0' && !local__extract_mime_type_(obj)) - error_message = error_messages[8]; - /* try to extract resolution/color info if user left it blank */ - else if ((obj->data.picture.width == 0 || obj->data.picture.height == 0 || obj->data.picture.depth == 0) && !local__extract_resolution_color_info_(&obj->data.picture)) - error_message = error_messages[4]; - /* check metadata block size */ - else if (obj->length >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) - error_message = error_messages[11]; - - return error_message; -} - -FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, const char **error_message) -{ - FLAC__StreamMetadata *obj; - int state = 0; - - FLAC__ASSERT(0 != spec); - FLAC__ASSERT(0 != error_message); - - /* double protection */ - if(0 == spec) - return 0; - if(0 == error_message) - return 0; - - *error_message = 0; - - if(0 == (obj = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE))) { - *error_message = error_messages[0]; - return obj; - } - - if(strchr(spec, '|')) { /* full format */ - const char *p; - char *q; - for(p = spec; *error_message==0 && *p; ) { - if(*p == '|') { - switch(state) { - case 0: /* type */ - if(!local__parse_type_(spec, p-spec, &obj->data.picture)) - *error_message = error_messages[7]; - break; - case 1: /* mime type */ - if(p-spec) { /* if blank, we'll try to guess later from the picture data */ - if(0 == (q = local__strndup_(spec, p-spec))) - *error_message = error_messages[0]; - else if(!FLAC__metadata_object_picture_set_mime_type(obj, q, /*copy=*/false)) - *error_message = error_messages[0]; - } - break; - case 2: /* description */ - if(0 == (q = local__strndup_(spec, p-spec))) - *error_message = error_messages[0]; - else if(!FLAC__metadata_object_picture_set_description(obj, (FLAC__byte*)q, /*copy=*/false)) - *error_message = error_messages[0]; - break; - case 3: /* resolution/color (e.g. [300x300x16[/1234]] */ - if(!local__parse_resolution_(spec, p-spec, &obj->data.picture)) - *error_message = error_messages[2]; - break; - default: - *error_message = error_messages[1]; - break; - } - p++; - spec = p; - state++; - } - else - p++; - } - } - else { /* simple format, filename only, everything else guessed */ - if(!local__parse_type_("", 0, &obj->data.picture)) /* use default picture type */ - *error_message = error_messages[7]; - /* leave MIME type to be filled in later */ - /* leave description empty */ - /* leave the rest to be filled in later: */ - else if(!local__parse_resolution_("", 0, &obj->data.picture)) - *error_message = error_messages[2]; - else - state = 4; - } - - /* parse filename, read file, try to extract resolution/color info if needed */ - if(*error_message == 0) { - if(state != 4) - *error_message = error_messages[1]; - else { /* 'spec' points to filename/URL */ - if(0 == strcmp(obj->data.picture.mime_type, "-->")) { /* magic MIME type means URL */ - if(strlen(spec) == 0) - *error_message = error_messages[1]; - else if(!FLAC__metadata_object_picture_set_data(obj, (FLAC__byte*)spec, strlen(spec), /*copy=*/true)) - *error_message = error_messages[0]; - else if(obj->data.picture.width == 0 || obj->data.picture.height == 0 || obj->data.picture.depth == 0) - *error_message = error_messages[3]; - } - else { /* regular picture file */ - *error_message = read_file (spec, obj); - } - } - } - - if(*error_message == 0) { - if( - obj->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD && - ( - (strcmp(obj->data.picture.mime_type, "image/png") && strcmp(obj->data.picture.mime_type, "-->")) || - obj->data.picture.width != 32 || - obj->data.picture.height != 32 - ) - ) - *error_message = error_messages[9]; - } - - if(*error_message && obj) { - FLAC__metadata_object_delete(obj); - obj = 0; - } - - return obj; -} - -FLAC__StreamMetadata *grabbag__picture_from_specification(int type, const char *mime_type_in, const char * description, - const PictureResolution * res, const char * filepath, const char **error_message) -{ - - FLAC__StreamMetadata *obj; - char mime_type [64] ; - - if (error_message == 0) - return 0; - - safe_strncpy(mime_type, mime_type_in, sizeof (mime_type)); - - *error_message = 0; - - if ((obj = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE)) == 0) { - *error_message = error_messages[0]; - return obj; - } - - /* Picture type if known. */ - obj->data.picture.type = type >= 0 ? type : FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER; - - /* Mime type if known. */ - if (mime_type_in && ! FLAC__metadata_object_picture_set_mime_type(obj, mime_type, /*copy=*/true)) { - *error_message = error_messages[0]; - return obj; - } - - /* Description if present. */ - if (description && ! FLAC__metadata_object_picture_set_description(obj, (FLAC__byte*) description, /*copy=*/true)) { - *error_message = error_messages[0]; - return obj; - } - - if (res == NULL) { - obj->data.picture.width = 0; - obj->data.picture.height = 0; - obj->data.picture.depth = 0; - obj->data.picture.colors = 0; - } - else { - obj->data.picture.width = res->width; - obj->data.picture.height = res->height; - obj->data.picture.depth = res->depth; - obj->data.picture.colors = res->colors; - } - - if (strcmp(obj->data.picture.mime_type, "-->") == 0) { /* magic MIME type means URL */ - if (!FLAC__metadata_object_picture_set_data(obj, (FLAC__byte*)filepath, strlen(filepath), /*copy=*/true)) - *error_message = error_messages[0]; - else if (obj->data.picture.width == 0 || obj->data.picture.height == 0 || obj->data.picture.depth == 0) - *error_message = error_messages[3]; - } - else { - *error_message = read_file (filepath, obj); - } - - if (*error_message == NULL) { - if ( - obj->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD && - ( - (strcmp(obj->data.picture.mime_type, "image/png") && strcmp(obj->data.picture.mime_type, "-->")) || - obj->data.picture.width != 32 || - obj->data.picture.height != 32 - ) - ) - *error_message = error_messages[9]; - } - - if (*error_message && obj) { - FLAC__metadata_object_delete(obj); - obj = 0; - } - - return obj; -} diff --git a/flac/src/share/grabbag/replaygain.c b/flac/src/share/grabbag/replaygain.c deleted file mode 100644 index 32c9603..0000000 --- a/flac/src/share/grabbag/replaygain.c +++ /dev/null @@ -1,669 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#if defined _MSC_VER || defined __MINGW32__ -#include /* for chmod() */ -#endif -#include /* for stat(), maybe chmod() */ - -#include "FLAC/assert.h" -#include "FLAC/metadata.h" -#include "FLAC/stream_decoder.h" -#include "share/grabbag.h" -#include "share/replaygain_analysis.h" -#include "share/safe_str.h" - -#ifdef local_min -#undef local_min -#endif -#define local_min(a,b) ((a)<(b)?(a):(b)) - -#ifdef local_max -#undef local_max -#endif -#define local_max(a,b) ((a)>(b)?(a):(b)) - -#ifdef abs32 -#undef abs32 -#endif -#define abs32(a) (((a)==INT32_MIN)?INT32_MAX:abs(a)) - -static const char *reference_format_ = "%s=%2.1f dB"; -static const char *gain_format_ = "%s=%+2.2f dB"; -static const char *peak_format_ = "%s=%1.8f"; - -static double album_peak_, title_peak_; - -const uint32_t GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED = 190; -/* - FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + 29 + 1 + 8 + - FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + 21 + 1 + 10 + - FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + 21 + 1 + 12 + - FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + 21 + 1 + 10 + - FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + 21 + 1 + 12 -*/ - -const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_REFERENCE_LOUDNESS = (const FLAC__byte * const)"REPLAYGAIN_REFERENCE_LOUDNESS"; -const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN = (const FLAC__byte * const)"REPLAYGAIN_TRACK_GAIN"; -const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK = (const FLAC__byte * const)"REPLAYGAIN_TRACK_PEAK"; -const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN = (const FLAC__byte * const)"REPLAYGAIN_ALBUM_GAIN"; -const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK = (const FLAC__byte * const)"REPLAYGAIN_ALBUM_PEAK"; - - -static FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stats) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - return (0 == flac_stat(filename, stats)); -} - -static void set_file_stats_(const char *filename, struct flac_stat_s *stats) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - - (void)flac_chmod(filename, stats->st_mode); -} - -static FLAC__bool append_tag_(FLAC__StreamMetadata *block, const char *format, const FLAC__byte *name, float value) -{ - char buffer[256]; - char *saved_locale; - FLAC__StreamMetadata_VorbisComment_Entry entry; - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__ASSERT(0 != format); - FLAC__ASSERT(0 != name); - - buffer[sizeof(buffer)-1] = '\0'; - /* - * We need to save the old locale and switch to "C" because the locale - * influences the formatting of %f and we want it a certain way. - */ - saved_locale = strdup(setlocale(LC_ALL, 0)); - if (0 == saved_locale) - return false; - setlocale(LC_ALL, "C"); - flac_snprintf(buffer, sizeof(buffer), format, name, value); - setlocale(LC_ALL, saved_locale); - free(saved_locale); - - entry.entry = (FLAC__byte *)buffer; - entry.length = strlen(buffer); - - return FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true); -} - -FLAC__bool grabbag__replaygain_is_valid_sample_frequency(uint32_t sample_frequency) -{ - return ValidGainFrequency( sample_frequency ); -} - -FLAC__bool grabbag__replaygain_init(uint32_t sample_frequency) -{ - title_peak_ = album_peak_ = 0.0; - return InitGainAnalysis((long)sample_frequency) == INIT_GAIN_ANALYSIS_OK; -} - -FLAC__bool grabbag__replaygain_analyze(const FLAC__int32 * const input[], FLAC__bool is_stereo, uint32_t bps, uint32_t samples) -{ - /* using a small buffer improves data locality; we'd like it to fit easily in the dcache */ - static flac_float_t lbuffer[2048], rbuffer[2048]; - static const uint32_t nbuffer = sizeof(lbuffer) / sizeof(lbuffer[0]); - FLAC__int32 block_peak = 0, s; - uint32_t i, j; - - FLAC__ASSERT(bps >= FLAC__MIN_BITS_PER_SAMPLE && bps <= FLAC__MAX_BITS_PER_SAMPLE); - FLAC__ASSERT(FLAC__MIN_BITS_PER_SAMPLE == 4 && FLAC__MAX_BITS_PER_SAMPLE == 32); - - if(bps == 16) { - if(is_stereo) { - j = 0; - while(samples > 0) { - const uint32_t n = local_min(samples, nbuffer); - for(i = 0; i < n; i++, j++) { - s = input[0][j]; - lbuffer[i] = (flac_float_t)s; - s = abs(s); - block_peak = local_max(block_peak, s); - - s = input[1][j]; - rbuffer[i] = (flac_float_t)s; - s = abs(s); - block_peak = local_max(block_peak, s); - } - samples -= n; - if(AnalyzeSamples(lbuffer, rbuffer, n, 2) != GAIN_ANALYSIS_OK) - return false; - } - } - else { - j = 0; - while(samples > 0) { - const uint32_t n = local_min(samples, nbuffer); - for(i = 0; i < n; i++, j++) { - s = input[0][j]; - lbuffer[i] = (flac_float_t)s; - s = abs(s); - block_peak = local_max(block_peak, s); - } - samples -= n; - if(AnalyzeSamples(lbuffer, 0, n, 1) != GAIN_ANALYSIS_OK) - return false; - } - } - } - else { - const double scale = ( - (bps > 16)? - (double)1. / (double)(1u << (bps - 16)) : - (double)(1u << (16 - bps)) - ); - - if(is_stereo) { - j = 0; - while(samples > 0) { - const uint32_t n = local_min(samples, nbuffer); - for(i = 0; i < n; i++, j++) { - s = input[0][j]; - lbuffer[i] = (flac_float_t)(scale * (double)s); - s = abs32(s); - block_peak = local_max(block_peak, s); - - s = input[1][j]; - rbuffer[i] = (flac_float_t)(scale * (double)s); - s = abs32(s); - block_peak = local_max(block_peak, s); - } - samples -= n; - if(AnalyzeSamples(lbuffer, rbuffer, n, 2) != GAIN_ANALYSIS_OK) - return false; - } - } - else { - j = 0; - while(samples > 0) { - const uint32_t n = local_min(samples, nbuffer); - for(i = 0; i < n; i++, j++) { - s = input[0][j]; - lbuffer[i] = (flac_float_t)(scale * (double)s); - s = abs32(s); - block_peak = local_max(block_peak, s); - } - samples -= n; - if(AnalyzeSamples(lbuffer, 0, n, 1) != GAIN_ANALYSIS_OK) - return false; - } - } - } - - { - const double peak_scale = (double)(1u << (bps - 1)); - double peak = (double)block_peak / peak_scale; - if(peak > title_peak_) - title_peak_ = peak; - if(peak > album_peak_) - album_peak_ = peak; - } - - return true; -} - -void grabbag__replaygain_get_album(float *gain, float *peak) -{ - *gain = (float)GetAlbumGain(); - *peak = (float)album_peak_; - album_peak_ = 0.0; -} - -void grabbag__replaygain_get_title(float *gain, float *peak) -{ - *gain = (float)GetTitleGain(); - *peak = (float)title_peak_; - title_peak_ = 0.0; -} - - -typedef struct { - uint32_t channels; - uint32_t bits_per_sample; - uint32_t sample_rate; - FLAC__bool error; -} DecoderInstance; - -static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - DecoderInstance *instance = (DecoderInstance*)client_data; - const uint32_t bits_per_sample = frame->header.bits_per_sample; - const uint32_t channels = frame->header.channels; - const uint32_t sample_rate = frame->header.sample_rate; - const uint32_t samples = frame->header.blocksize; - - (void)decoder; - - if( - !instance->error && - (channels == 2 || channels == 1) && - bits_per_sample == instance->bits_per_sample && - channels == instance->channels && - sample_rate == instance->sample_rate - ) { - instance->error = !grabbag__replaygain_analyze(buffer, channels==2, bits_per_sample, samples); - } - else { - instance->error = true; - } - - if(!instance->error) - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; - else - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; -} - -static void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - DecoderInstance *instance = (DecoderInstance*)client_data; - - (void)decoder; - - if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { - instance->bits_per_sample = metadata->data.stream_info.bits_per_sample; - instance->channels = metadata->data.stream_info.channels; - instance->sample_rate = metadata->data.stream_info.sample_rate; - - if(instance->channels != 1 && instance->channels != 2) { - instance->error = true; - return; - } - - if(!grabbag__replaygain_is_valid_sample_frequency(instance->sample_rate)) { - instance->error = true; - return; - } - } -} - -static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - DecoderInstance *instance = (DecoderInstance*)client_data; - - (void)decoder, (void)status; - - instance->error = true; -} - -const char *grabbag__replaygain_analyze_file(const char *filename, float *title_gain, float *title_peak) -{ - DecoderInstance instance; - FLAC__StreamDecoder *decoder = FLAC__stream_decoder_new(); - - if(0 == decoder) - return "memory allocation error"; - - instance.error = false; - - /* It does these three by default but lets be explicit: */ - FLAC__stream_decoder_set_md5_checking(decoder, false); - FLAC__stream_decoder_set_metadata_ignore_all(decoder); - FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_STREAMINFO); - - if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &instance) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - FLAC__stream_decoder_delete(decoder); - return "initializing decoder"; - } - - if(!FLAC__stream_decoder_process_until_end_of_stream(decoder) || instance.error) { - FLAC__stream_decoder_delete(decoder); - return "decoding file"; - } - - FLAC__stream_decoder_delete(decoder); - - grabbag__replaygain_get_title(title_gain, title_peak); - - return 0; -} - -const char *grabbag__replaygain_store_to_vorbiscomment(FLAC__StreamMetadata *block, float album_gain, float album_peak, float title_gain, float title_peak) -{ - const char *error; - - if(0 != (error = grabbag__replaygain_store_to_vorbiscomment_reference(block))) - return error; - - if(0 != (error = grabbag__replaygain_store_to_vorbiscomment_title(block, title_gain, title_peak))) - return error; - - if(0 != (error = grabbag__replaygain_store_to_vorbiscomment_album(block, album_gain, album_peak))) - return error; - - return 0; -} - -const char *grabbag__replaygain_store_to_vorbiscomment_reference(FLAC__StreamMetadata *block) -{ - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - if(FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)GRABBAG__REPLAYGAIN_TAG_REFERENCE_LOUDNESS) < 0) - return "memory allocation error"; - - if(!append_tag_(block, reference_format_, GRABBAG__REPLAYGAIN_TAG_REFERENCE_LOUDNESS, ReplayGainReferenceLoudness)) - return "memory allocation error"; - - return 0; -} - -const char *grabbag__replaygain_store_to_vorbiscomment_album(FLAC__StreamMetadata *block, float album_gain, float album_peak) -{ - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - if( - FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN) < 0 || - FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK) < 0 - ) - return "memory allocation error"; - - if( - !append_tag_(block, gain_format_, GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN, album_gain) || - !append_tag_(block, peak_format_, GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK, album_peak) - ) - return "memory allocation error"; - - return 0; -} - -const char *grabbag__replaygain_store_to_vorbiscomment_title(FLAC__StreamMetadata *block, float title_gain, float title_peak) -{ - FLAC__ASSERT(0 != block); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - if( - FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN) < 0 || - FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK) < 0 - ) - return "memory allocation error"; - - if( - !append_tag_(block, gain_format_, GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN, title_gain) || - !append_tag_(block, peak_format_, GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK, title_peak) - ) - return "memory allocation error"; - - return 0; -} - -static const char *store_to_file_pre_(const char *filename, FLAC__Metadata_Chain **chain, FLAC__StreamMetadata **block) -{ - FLAC__Metadata_Iterator *iterator; - const char *error; - FLAC__bool found_vc_block = false; - - if(0 == (*chain = FLAC__metadata_chain_new())) - return "memory allocation error"; - - if(!FLAC__metadata_chain_read(*chain, filename)) { - error = FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(*chain)]; - FLAC__metadata_chain_delete(*chain); - return error; - } - - if(0 == (iterator = FLAC__metadata_iterator_new())) { - FLAC__metadata_chain_delete(*chain); - return "memory allocation error"; - } - - FLAC__metadata_iterator_init(iterator, *chain); - - do { - *block = FLAC__metadata_iterator_get_block(iterator); - if((*block)->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) - found_vc_block = true; - } while(!found_vc_block && FLAC__metadata_iterator_next(iterator)); - - if(!found_vc_block) { - /* create a new block */ - *block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); - if(0 == *block) { - FLAC__metadata_chain_delete(*chain); - FLAC__metadata_iterator_delete(iterator); - return "memory allocation error"; - } - while(FLAC__metadata_iterator_next(iterator)) - ; - if(!FLAC__metadata_iterator_insert_block_after(iterator, *block)) { - error = FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(*chain)]; - FLAC__metadata_chain_delete(*chain); - FLAC__metadata_iterator_delete(iterator); - return error; - } - /* iterator is left pointing to new block */ - FLAC__ASSERT(FLAC__metadata_iterator_get_block(iterator) == *block); - } - - FLAC__metadata_iterator_delete(iterator); - - FLAC__ASSERT(0 != *block); - FLAC__ASSERT((*block)->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - return 0; -} - -static const char *store_to_file_post_(const char *filename, FLAC__Metadata_Chain *chain, FLAC__bool preserve_modtime) -{ - struct flac_stat_s stats; - const FLAC__bool have_stats = get_file_stats_(filename, &stats); - - (void)grabbag__file_change_stats(filename, /*read_only=*/false); - - FLAC__metadata_chain_sort_padding(chain); - if(!FLAC__metadata_chain_write(chain, /*use_padding=*/true, preserve_modtime)) { - const char *error; - error = FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]; - FLAC__metadata_chain_delete(chain); - return error; - } - - FLAC__metadata_chain_delete(chain); - - if(have_stats) - set_file_stats_(filename, &stats); - - return 0; -} - -const char *grabbag__replaygain_store_to_file(const char *filename, float album_gain, float album_peak, float title_gain, float title_peak, FLAC__bool preserve_modtime) -{ - FLAC__Metadata_Chain *chain; - FLAC__StreamMetadata *block = NULL; - const char *error; - - if(0 != (error = store_to_file_pre_(filename, &chain, &block))) - return error; - - if(0 != (error = grabbag__replaygain_store_to_vorbiscomment(block, album_gain, album_peak, title_gain, title_peak))) { - FLAC__metadata_chain_delete(chain); - return error; - } - - if(0 != (error = store_to_file_post_(filename, chain, preserve_modtime))) - return error; - - return 0; -} - -const char *grabbag__replaygain_store_to_file_reference(const char *filename, FLAC__bool preserve_modtime) -{ - FLAC__Metadata_Chain *chain; - FLAC__StreamMetadata *block = NULL; - const char *error; - - if(0 != (error = store_to_file_pre_(filename, &chain, &block))) - return error; - - if(0 != (error = grabbag__replaygain_store_to_vorbiscomment_reference(block))) { - FLAC__metadata_chain_delete(chain); - return error; - } - - if(0 != (error = store_to_file_post_(filename, chain, preserve_modtime))) - return error; - - return 0; -} - -const char *grabbag__replaygain_store_to_file_album(const char *filename, float album_gain, float album_peak, FLAC__bool preserve_modtime) -{ - FLAC__Metadata_Chain *chain; - FLAC__StreamMetadata *block = NULL; - const char *error; - - if(0 != (error = store_to_file_pre_(filename, &chain, &block))) - return error; - - if(0 != (error = grabbag__replaygain_store_to_vorbiscomment_album(block, album_gain, album_peak))) { - FLAC__metadata_chain_delete(chain); - return error; - } - - if(0 != (error = store_to_file_post_(filename, chain, preserve_modtime))) - return error; - - return 0; -} - -const char *grabbag__replaygain_store_to_file_title(const char *filename, float title_gain, float title_peak, FLAC__bool preserve_modtime) -{ - FLAC__Metadata_Chain *chain; - FLAC__StreamMetadata *block = NULL; - const char *error; - - if(0 != (error = store_to_file_pre_(filename, &chain, &block))) - return error; - - if(0 != (error = grabbag__replaygain_store_to_vorbiscomment_title(block, title_gain, title_peak))) { - FLAC__metadata_chain_delete(chain); - return error; - } - - if(0 != (error = store_to_file_post_(filename, chain, preserve_modtime))) - return error; - - return 0; -} - -static FLAC__bool parse_double_(const FLAC__StreamMetadata_VorbisComment_Entry *entry, double *val) -{ - char s[32], *end; - const char *p, *q; - double v; - - FLAC__ASSERT(0 != entry); - FLAC__ASSERT(0 != val); - - p = (const char *)entry->entry; - q = strchr(p, '='); - if(0 == q) - return false; - q++; - safe_strncpy(s, q, local_min(sizeof(s), (size_t) (entry->length - (q-p)))); - - v = strtod(s, &end); - if(end == s) - return false; - - *val = v; - return true; -} - -FLAC__bool grabbag__replaygain_load_from_vorbiscomment(const FLAC__StreamMetadata *block, FLAC__bool album_mode, FLAC__bool strict, double *reference, double *gain, double *peak) -{ - int reference_offset, gain_offset, peak_offset; - char *saved_locale; - FLAC__bool res = true; - - FLAC__ASSERT(0 != block); - FLAC__ASSERT(0 != reference); - FLAC__ASSERT(0 != gain); - FLAC__ASSERT(0 != peak); - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); - - /* Default to current level until overridden by a detected tag; this - * will always be true until we change replaygain_analysis.c - */ - *reference = ReplayGainReferenceLoudness; - - /* - * We need to save the old locale and switch to "C" because the locale - * influences the behaviour of strtod and we want it a certain way. - */ - saved_locale = strdup(setlocale(LC_ALL, 0)); - if (0 == saved_locale) - return false; - setlocale(LC_ALL, "C"); - - if(0 <= (reference_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, (const char *)GRABBAG__REPLAYGAIN_TAG_REFERENCE_LOUDNESS))) - (void)parse_double_(block->data.vorbis_comment.comments + reference_offset, reference); - - if(0 > (gain_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, (const char *)(album_mode? GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN : GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN)))) - res = false; - if(0 > (peak_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, (const char *)(album_mode? GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK : GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK)))) - res = false; - - if(res && !parse_double_(block->data.vorbis_comment.comments + gain_offset, gain)) - res = false; - if(res && !parse_double_(block->data.vorbis_comment.comments + peak_offset, peak)) - res = false; - if(res && *peak < 0.0) - res = false; - - setlocale(LC_ALL, saved_locale); - free(saved_locale); - - /* something failed; retry with strict */ - if (!res && !strict) - res = grabbag__replaygain_load_from_vorbiscomment(block, !album_mode, /*strict=*/true, reference, gain, peak); - - return res; -} - -double grabbag__replaygain_compute_scale_factor(double peak, double gain, double preamp, FLAC__bool prevent_clipping) -{ - double scale; - FLAC__ASSERT(peak >= 0.0); - gain += preamp; - scale = (float) pow(10.0, gain * 0.05); - if(prevent_clipping && peak > 0.0) { - const double max_scale = (float)(1.0 / peak); - if(scale > max_scale) - scale = max_scale; - } - return scale; -} diff --git a/flac/src/share/grabbag/seektable.c b/flac/src/share/grabbag/seektable.c deleted file mode 100644 index 01caa99..0000000 --- a/flac/src/share/grabbag/seektable.c +++ /dev/null @@ -1,105 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "share/grabbag.h" -#include "share/compat.h" -#include "FLAC/assert.h" -#include /* for atoi() */ -#include - -FLAC__bool grabbag__seektable_convert_specification_to_template(const char *spec, FLAC__bool only_explicit_placeholders, FLAC__uint64 total_samples_to_encode, uint32_t sample_rate, FLAC__StreamMetadata *seektable_template, FLAC__bool *spec_has_real_points) -{ - uint32_t i; - const char *pt; - - FLAC__ASSERT(0 != spec); - FLAC__ASSERT(0 != seektable_template); - FLAC__ASSERT(seektable_template->type == FLAC__METADATA_TYPE_SEEKTABLE); - - if(0 != spec_has_real_points) - *spec_has_real_points = false; - - for(pt = spec, i = 0; pt && *pt; i++) { - const char *q = strchr(pt, ';'); - FLAC__ASSERT(0 != q); - - if(q > pt) { - if(0 == strncmp(pt, "X;", 2)) { /* -S X */ - if(!FLAC__metadata_object_seektable_template_append_placeholders(seektable_template, 1)) - return false; - } - else if(q[-1] == 'x') { /* -S #x */ - if(total_samples_to_encode > 0) { /* we can only do these if we know the number of samples to encode up front */ - if(0 != spec_has_real_points) - *spec_has_real_points = true; - if(!only_explicit_placeholders) { - const int n = (uint32_t)atoi(pt); - if(n > 0) - if(!FLAC__metadata_object_seektable_template_append_spaced_points(seektable_template, (uint32_t)n, total_samples_to_encode)) - return false; - } - } - } - else if(q[-1] == 's') { /* -S #s */ - if(total_samples_to_encode > 0 && sample_rate > 0) { /* we can only do these if we know the number of samples and sample rate to encode up front */ - if(0 != spec_has_real_points) - *spec_has_real_points = true; - if(!only_explicit_placeholders) { - const double sec = atof(pt); - if(sec > 0.0) { - uint32_t samples = (uint32_t)(sec * (double)sample_rate); - /* Restrict seekpoints to two per second of audio. */ - samples = samples < sample_rate / 2 ? sample_rate / 2 : samples; - if(samples > 0) { - /* +1 for the initial point at sample 0 */ - if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(seektable_template, samples, total_samples_to_encode)) - return false; - } - } - } - } - } - else { /* -S # */ - if(0 != spec_has_real_points) - *spec_has_real_points = true; - if(!only_explicit_placeholders) { - char *endptr; - const FLAC__int64 n = (FLAC__int64)strtoll(pt, &endptr, 10); - if( - (n > 0 || (endptr > pt && *endptr == ';')) && /* is a valid number (extra check needed for "0") */ - (total_samples_to_encode == 0 || (FLAC__uint64)n < total_samples_to_encode) /* number is not >= the known total_samples_to_encode */ - ) - if(!FLAC__metadata_object_seektable_template_append_point(seektable_template, (FLAC__uint64)n)) - return false; - } - } - } - - pt = ++q; - } - - if(!FLAC__metadata_object_seektable_template_sort(seektable_template, /*compact=*/true)) - return false; - - return true; -} diff --git a/flac/src/share/grabbag/snprintf.c b/flac/src/share/grabbag/snprintf.c deleted file mode 100644 index bd7ffba..0000000 --- a/flac/src/share/grabbag/snprintf.c +++ /dev/null @@ -1,101 +0,0 @@ -/* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2013-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include "share/compat.h" - -/* - * FLAC needs to compile and work correctly on systems with a normal ISO C99 - * snprintf as well as Microsoft Visual Studio which has an non-standards - * conformant snprint_s function. - * - * The important difference occurs when the resultant string (plus string - * terminator) would have been longer than the supplied size parameter. When - * this happens, ISO C's snprintf returns the length of resultant string, but - * does not over-write the end of the buffer. MS's snprintf_s in this case - * returns -1. - * - * The _MSC_VER code below attempts to modify the return code for vsnprintf_s - * to something that is more compatible with the behaviour of the ISO C version. - */ - -int -flac_snprintf(char *str, size_t size, const char *fmt, ...) -{ - va_list va; - int rc; - -#if defined _MSC_VER - if (size == 0) - return 1024; -#endif - - va_start (va, fmt); - -#if defined _MSC_VER - rc = vsnprintf_s (str, size, _TRUNCATE, fmt, va); - if (rc < 0) - rc = size - 1; -#elif defined __MINGW32__ - rc = __mingw_vsnprintf (str, size, fmt, va); -#else - rc = vsnprintf (str, size, fmt, va); -#endif - va_end (va); - - return rc; -} - -int -flac_vsnprintf(char *str, size_t size, const char *fmt, va_list va) -{ - int rc; - -#if defined _MSC_VER - if (size == 0) - return 1024; - rc = vsnprintf_s (str, size, _TRUNCATE, fmt, va); - if (rc < 0) - rc = size - 1; -#elif defined __MINGW32__ - rc = __mingw_vsnprintf (str, size, fmt, va); -#else - rc = vsnprintf (str, size, fmt, va); -#endif - - return rc; -} diff --git a/flac/src/share/replaygain_analysis/CMakeLists.txt b/flac/src/share/replaygain_analysis/CMakeLists.txt deleted file mode 100644 index 4362b90..0000000 --- a/flac/src/share/replaygain_analysis/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_library(replaygain_analysis STATIC - replaygain_analysis.c) diff --git a/flac/src/share/replaygain_analysis/replaygain_analysis.c b/flac/src/share/replaygain_analysis/replaygain_analysis.c deleted file mode 100644 index 37b77ab..0000000 --- a/flac/src/share/replaygain_analysis/replaygain_analysis.c +++ /dev/null @@ -1,575 +0,0 @@ -/* - * ReplayGainAnalysis - analyzes input samples and give the recommended dB change - * Copyright (C) 2001 David Robinson and Glen Sawyer - * - * 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.1 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 - * - * concept and filter values by David Robinson (David@Robinson.org) - * -- blame him if you think the idea is flawed - * original coding by Glen Sawyer (glensawyer@hotmail.com) - * -- blame him if you think this runs too slowly, or the coding is otherwise flawed - * - * lots of code improvements by Frank Klemm ( http://www.uni-jena.de/~pfk/mpp/ ) - * -- credit him for all the _good_ programming ;) - * - * minor cosmetic tweaks to integrate with FLAC by Josh Coalson - * - * - * For an explanation of the concepts and the basic algorithms involved, go to: - * http://www.replaygain.org/ - */ - -/* - * Here's the deal. Call - * - * InitGainAnalysis ( long samplefreq ); - * - * to initialize everything. Call - * - * AnalyzeSamples ( const flac_float_t* left_samples, - * const flac_float_t* right_samples, - * size_t num_samples, - * int num_channels ); - * - * as many times as you want, with as many or as few samples as you want. - * If mono, pass the sample buffer in through left_samples, leave - * right_samples NULL, and make sure num_channels = 1. - * - * GetTitleGain() - * - * will return the recommended dB level change for all samples analyzed - * SINCE THE LAST TIME you called GetTitleGain() OR InitGainAnalysis(). - * - * GetAlbumGain() - * - * will return the recommended dB level change for all samples analyzed - * since InitGainAnalysis() was called and finalized with GetTitleGain(). - * - * Pseudo-code to process an album: - * - * flac_float_t l_samples [4096]; - * flac_float_t r_samples [4096]; - * size_t num_samples; - * uint32_t num_songs; - * uint32_t i; - * - * InitGainAnalysis ( 44100 ); - * for ( i = 1; i <= num_songs; i++ ) { - * while ( ( num_samples = getSongSamples ( song[i], left_samples, right_samples ) ) > 0 ) - * AnalyzeSamples ( left_samples, right_samples, num_samples, 2 ); - * fprintf ("Recommended dB change for song %2d: %+6.2f dB\n", i, GetTitleGain() ); - * } - * fprintf ("Recommended dB change for whole album: %+6.2f dB\n", GetAlbumGain() ); - */ - -/* - * So here's the main source of potential code confusion: - * - * The filters applied to the incoming samples are IIR filters, - * meaning they rely on up to number of previous samples - * AND up to number of previous filtered samples. - * - * I set up the AnalyzeSamples routine to minimize memory usage and interface - * complexity. The speed isn't compromised too much (I don't think), but the - * internal complexity is higher than it should be for such a relatively - * simple routine. - * - * Optimization/clarity suggestions are welcome. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include "share/alloc.h" -#include "share/compat.h" -#include "share/replaygain_analysis.h" - -flac_float_t ReplayGainReferenceLoudness = 89.0; /* in dB SPL */ - -#define YULE_ORDER 10 -#define BUTTER_ORDER 2 -#define RMS_PERCENTILE 0.95 /* percentile which is louder than the proposed level */ -#define RMS_WINDOW_TIME 50 /* Time slice size [ms] */ -#define STEPS_per_dB 100. /* Table entries per dB */ -#define MAX_dB 120. /* Table entries for 0...MAX_dB (normal max. values are 70...80 dB) */ - -#define MAX_ORDER (BUTTER_ORDER > YULE_ORDER ? BUTTER_ORDER : YULE_ORDER) -#define PINK_REF 64.82 /* 298640883795 */ /* calibration value */ - -static flac_float_t linprebuf [MAX_ORDER * 2]; -static flac_float_t* linpre; /* left input samples, with pre-buffer */ -static flac_float_t* lstepbuf; -static flac_float_t* lstep; /* left "first step" (i.e. post first filter) samples */ -static flac_float_t* loutbuf; -static flac_float_t* lout; /* left "out" (i.e. post second filter) samples */ -static flac_float_t rinprebuf [MAX_ORDER * 2]; -static flac_float_t* rinpre; /* right input samples ... */ -static flac_float_t* rstepbuf; -static flac_float_t* rstep; -static flac_float_t* routbuf; -static flac_float_t* rout; -static uint32_t sampleWindow; /* number of samples required to reach number of milliseconds required for RMS window */ -static uint64_t totsamp; -static double lsum; -static double rsum; -#if 0 -static uint32_t A [(size_t)(STEPS_per_dB * MAX_dB)]; -static uint32_t B [(size_t)(STEPS_per_dB * MAX_dB)]; -#else -/* [JEC] Solaris Forte compiler doesn't like float calc in array indices */ -static uint32_t A [120 * 100]; -static uint32_t B [120 * 100]; -#endif - -#ifdef _MSC_VER -#pragma warning ( disable : 4305 ) -#endif - -struct ReplayGainFilter { - long rate; - uint32_t downsample; - flac_float_t BYule[YULE_ORDER+1]; - flac_float_t AYule[YULE_ORDER+1]; - flac_float_t BButter[BUTTER_ORDER+1]; - flac_float_t AButter[BUTTER_ORDER+1]; -}; - -static struct ReplayGainFilter *replaygainfilter; - -static const struct ReplayGainFilter ReplayGainFilters[] = { - - { - 48000, 0, /* ORIGINAL */ - { 0.03857599435200, -0.02160367184185, -0.00123395316851, -0.00009291677959, -0.01655260341619, 0.02161526843274, -0.02074045215285, 0.00594298065125, 0.00306428023191, 0.00012025322027, 0.00288463683916 }, - { 1.00000000000000, -3.84664617118067, 7.81501653005538, -11.34170355132042, 13.05504219327545, -12.28759895145294, 9.48293806319790, -5.87257861775999, 2.75465861874613, -0.86984376593551, 0.13919314567432 }, - { 0.98621192462708, -1.97242384925416, 0.98621192462708 }, - { 1.00000000000000, -1.97223372919527, 0.97261396931306 }, - }, - - { - 44100, 0, /* ORIGINAL */ - { 0.05418656406430, -0.02911007808948, -0.00848709379851, -0.00851165645469, -0.00834990904936, 0.02245293253339, -0.02596338512915, 0.01624864962975, -0.00240879051584, 0.00674613682247, -0.00187763777362 }, - { 1.00000000000000, -3.47845948550071, 6.36317777566148, -8.54751527471874, 9.47693607801280, -8.81498681370155, 6.85401540936998, -4.39470996079559, 2.19611684890774, -0.75104302451432, 0.13149317958808 }, - { 0.98500175787242, -1.97000351574484, 0.98500175787242 }, - { 1.00000000000000, -1.96977855582618, 0.97022847566350 }, - }, - - { - 37800, 0, - { 0.10296717174470, -0.04877975583256, -0.02878009075237, -0.03519509188311, 0.02888717172493, -0.00609872684844, 0.00209851217112, 0.00911704668543, 0.01154404718589, -0.00630293688700, 0.00107527155228 }, - { 1.00000000000000, -2.64848054923531, 3.58406058405771, -3.83794914179161, 3.90142345804575, -3.50179818637243, 2.67085284083076, -1.82581142372418, 1.09530368139801, -0.47689017820395, 0.11171431535905 }, - { 0.98252400815195, -1.96504801630391, 0.98252400815195 }, - { 1.00000000000000, -1.96474258269041, 0.96535344991740 }, - }, - - { - 36000, 0, - { 0.11572297028613, -0.04120916051252, -0.04977731768022, -0.01047308680426, 0.00750863219157, 0.00055507694408, 0.00140344192886, 0.01286095246036, 0.00998223033885, -0.00725013810661, 0.00326503346879 }, - { 1.00000000000000, -2.43606802820871, 3.01907406973844, -2.90372016038192, 2.67947188094303, -2.17606479220391, 1.44912956803015, -0.87785765549050, 0.53592202672557, -0.26469344817509, 0.07495878059717 }, - { 0.98165826840326, -1.96331653680652, 0.98165826840326 }, - { 1.00000000000000, -1.96298008938934, 0.96365298422371 }, - }, - - { - 32000, 0, /* ORIGINAL */ - { 0.15457299681924, -0.09331049056315, -0.06247880153653, 0.02163541888798, -0.05588393329856, 0.04781476674921, 0.00222312597743, 0.03174092540049, -0.01390589421898, 0.00651420667831, -0.00881362733839 }, - { 1.00000000000000, -2.37898834973084, 2.84868151156327, -2.64577170229825, 2.23697657451713, -1.67148153367602, 1.00595954808547, -0.45953458054983, 0.16378164858596, -0.05032077717131, 0.02347897407020 }, - { 0.97938932735214, -1.95877865470428, 0.97938932735214 }, - { 1.00000000000000, -1.95835380975398, 0.95920349965459 }, - }, - - { - 28000, 0, - { 0.23882392323383, -0.22007791534089, -0.06014581950332, 0.05004458058021, -0.03293111254977, 0.02348678189717, 0.04290549799671, -0.00938141862174, 0.00015095146303, -0.00712601540885, -0.00626520210162 }, - { 1.00000000000000, -2.06894080899139, 1.76944699577212, -0.81404732584187, 0.25418286850232, -0.30340791669762, 0.35616884070937, -0.14967310591258, -0.07024154183279, 0.11078404345174, -0.03551838002425 }, - { 0.97647981663949, -1.95295963327897, 0.97647981663949 }, - { 1.00000000000000, -1.95240635772520, 0.95351290883275 }, - - }, - - { - 24000, 0, /* ORIGINAL */ - { 0.30296907319327, -0.22613988682123, -0.08587323730772, 0.03282930172664, -0.00915702933434, -0.02364141202522, -0.00584456039913, 0.06276101321749, -0.00000828086748, 0.00205861885564, -0.02950134983287 }, - { 1.00000000000000, -1.61273165137247, 1.07977492259970, -0.25656257754070, -0.16276719120440, -0.22638893773906, 0.39120800788284, -0.22138138954925, 0.04500235387352, 0.02005851806501, 0.00302439095741 }, - { 0.97531843204928, -1.95063686409857, 0.97531843204928 }, - { 1.00000000000000, -1.95002759149878, 0.95124613669835 }, - }, - - { - 22050, 0, /* ORIGINAL */ - { 0.33642304856132, -0.25572241425570, -0.11828570177555, 0.11921148675203, -0.07834489609479, -0.00469977914380, -0.00589500224440, 0.05724228140351, 0.00832043980773, -0.01635381384540, -0.01760176568150 }, - { 1.00000000000000, -1.49858979367799, 0.87350271418188, 0.12205022308084, -0.80774944671438, 0.47854794562326, -0.12453458140019, -0.04067510197014, 0.08333755284107, -0.04237348025746, 0.02977207319925 }, - { 0.97316523498161, -1.94633046996323, 0.97316523498161 }, - { 1.00000000000000, -1.94561023566527, 0.94705070426118 }, - }, - - { - 18900, 0, - { 0.38412657295385, -0.44533729608120, 0.20426638066221, -0.28031676047946, 0.31484202614802, -0.26078311203207, 0.12925201224848, -0.01141164696062, 0.03036522115769, -0.03776339305406, 0.00692036603586 }, - { 1.00000000000000, -1.74403915585708, 1.96686095832499, -2.10081452941881, 1.90753918182846, -1.83814263754422, 1.36971352214969, -0.77883609116398, 0.39266422457649, -0.12529383592986, 0.05424760697665 }, - { 0.96535326815829, -1.93070653631658, 0.96535326815829 }, - { 1.00000000000000, -1.92950577983524, 0.93190729279793 }, - }, - - { - 16000, 0, /* ORIGINAL */ - { 0.44915256608450, -0.14351757464547, -0.22784394429749, -0.01419140100551, 0.04078262797139, -0.12398163381748, 0.04097565135648, 0.10478503600251, -0.01863887810927, -0.03193428438915, 0.00541907748707 }, - { 1.00000000000000, -0.62820619233671, 0.29661783706366, -0.37256372942400, 0.00213767857124, -0.42029820170918, 0.22199650564824, 0.00613424350682, 0.06747620744683, 0.05784820375801, 0.03222754072173 }, - { 0.96454515552826, -1.92909031105652, 0.96454515552826 }, - { 1.00000000000000, -1.92783286977036, 0.93034775234268 }, - }, - - { - 12000, 0, /* ORIGINAL */ - { 0.56619470757641, -0.75464456939302, 0.16242137742230, 0.16744243493672, -0.18901604199609, 0.30931782841830, -0.27562961986224, 0.00647310677246, 0.08647503780351, -0.03788984554840, -0.00588215443421 }, - { 1.00000000000000, -1.04800335126349, 0.29156311971249, -0.26806001042947, 0.00819999645858, 0.45054734505008, -0.33032403314006, 0.06739368333110, -0.04784254229033, 0.01639907836189, 0.01807364323573 }, - { 0.96009142950541, -1.92018285901082, 0.96009142950541 }, - { 1.00000000000000, -1.91858953033784, 0.92177618768381 }, - }, - - { - 11025, 0, /* ORIGINAL */ - { 0.58100494960553, -0.53174909058578, -0.14289799034253, 0.17520704835522, 0.02377945217615, 0.15558449135573, -0.25344790059353, 0.01628462406333, 0.06920467763959, -0.03721611395801, -0.00749618797172 }, - { 1.00000000000000, -0.51035327095184, -0.31863563325245, -0.20256413484477, 0.14728154134330, 0.38952639978999, -0.23313271880868, -0.05246019024463, -0.02505961724053, 0.02442357316099, 0.01818801111503 }, - { 0.95856916599601, -1.91713833199203, 0.95856916599601 }, - { 1.00000000000000, -1.91542108074780, 0.91885558323625 }, - }, - - { - 8000, 0, /* ORIGINAL */ - { 0.53648789255105, -0.42163034350696, -0.00275953611929, 0.04267842219415, -0.10214864179676, 0.14590772289388, -0.02459864859345, -0.11202315195388, -0.04060034127000, 0.04788665548180, -0.02217936801134 }, - { 1.00000000000000, -0.25049871956020, -0.43193942311114, -0.03424681017675, -0.04678328784242, 0.26408300200955, 0.15113130533216, -0.17556493366449, -0.18823009262115, 0.05477720428674, 0.04704409688120 }, - { 0.94597685600279, -1.89195371200558, 0.94597685600279 }, - { 1.00000000000000, -1.88903307939452, 0.89487434461664 }, - }, - -}; - -#ifdef _MSC_VER -#pragma warning ( default : 4305 ) -#endif - -/* When calling this procedure, make sure that ip[-order] and op[-order] point to real data! */ - -static void -filter ( const flac_float_t* input, flac_float_t* output, size_t nSamples, const flac_float_t* a, const flac_float_t* b, size_t order, uint32_t downsample ) -{ - double y; - size_t i; - size_t k; - - const flac_float_t* input_head = input; - const flac_float_t* input_tail; - - flac_float_t* output_head = output; - flac_float_t* output_tail; - - for ( i = 0; i < nSamples; i++, input_head += downsample, ++output_head ) { - - input_tail = input_head; - output_tail = output_head; - - y = *input_head * b[0]; - - for ( k = 1; k <= order; k++ ) { - input_tail -= downsample; - --output_tail; - y += *input_tail * b[k] - *output_tail * a[k]; - } - - output[i] = (flac_float_t)y; - } -} - -/* returns a INIT_GAIN_ANALYSIS_OK if successful, INIT_GAIN_ANALYSIS_ERROR if not */ - -static struct ReplayGainFilter* -CreateGainFilter ( long samplefreq ) -{ - uint32_t i; - long maxrate = 0; - uint32_t downsample = 1; - struct ReplayGainFilter* gainfilter = malloc(sizeof(*gainfilter)); - - if ( !gainfilter ) - return 0; - - while (1) { - for ( i = 0; i < sizeof(ReplayGainFilters)/sizeof(ReplayGainFilters[0]); ++i ) { - if (maxrate < ReplayGainFilters[i].rate) - maxrate = ReplayGainFilters[i].rate; - - if ( ReplayGainFilters[i].rate == samplefreq ) { - *gainfilter = ReplayGainFilters[i]; - gainfilter->downsample = downsample; - return gainfilter; - } - } - - if (samplefreq < maxrate) - break; - - while (samplefreq > maxrate) { - downsample *= 2; - samplefreq /= 2; - } - } - - free(gainfilter); - - return 0; -} - -static void* -ReallocateWindowBuffer(uint32_t window_size, flac_float_t **window_buffer) -{ - *window_buffer = safe_realloc_(*window_buffer, sizeof(**window_buffer) * (window_size + MAX_ORDER)); - return *window_buffer; -} - -static int -ResetSampleFrequency ( long samplefreq ) { - int i; - - free(replaygainfilter); - - replaygainfilter = CreateGainFilter( samplefreq ); - - if ( ! replaygainfilter) - return INIT_GAIN_ANALYSIS_ERROR; - - sampleWindow = - (replaygainfilter->rate * RMS_WINDOW_TIME + 1000-1) / 1000; - - if ( ! ReallocateWindowBuffer(sampleWindow, &lstepbuf) || - ! ReallocateWindowBuffer(sampleWindow, &rstepbuf) || - ! ReallocateWindowBuffer(sampleWindow, &loutbuf) || - ! ReallocateWindowBuffer(sampleWindow, &routbuf) ) { - - return INIT_GAIN_ANALYSIS_ERROR; - } - - /* zero out initial values */ - for ( i = 0; i < MAX_ORDER; i++ ) - linprebuf[i] = lstepbuf[i] = loutbuf[i] = rinprebuf[i] = rstepbuf[i] = routbuf[i] = 0.; - - lsum = 0.; - rsum = 0.; - totsamp = 0; - - memset ( A, 0, sizeof(A) ); - - return INIT_GAIN_ANALYSIS_OK; -} - -int -ValidGainFrequency ( long samplefreq ) -{ - struct ReplayGainFilter* gainfilter = CreateGainFilter( samplefreq ); - - if (gainfilter == 0) { - return 0; - } else { - free(gainfilter); - return 1; - } -} - -int -InitGainAnalysis ( long samplefreq ) -{ - if (ResetSampleFrequency(samplefreq) != INIT_GAIN_ANALYSIS_OK) { - return INIT_GAIN_ANALYSIS_ERROR; - } - - linpre = linprebuf + MAX_ORDER; - rinpre = rinprebuf + MAX_ORDER; - lstep = lstepbuf + MAX_ORDER; - rstep = rstepbuf + MAX_ORDER; - lout = loutbuf + MAX_ORDER; - rout = routbuf + MAX_ORDER; - - memset ( B, 0, sizeof(B) ); - - return INIT_GAIN_ANALYSIS_OK; -} - -/* returns GAIN_ANALYSIS_OK if successful, GAIN_ANALYSIS_ERROR if not */ - -int -AnalyzeSamples ( const flac_float_t* left_samples, const flac_float_t* right_samples, size_t num_samples, int num_channels ) -{ - uint32_t downsample = replaygainfilter->downsample; - const flac_float_t* curleft; - const flac_float_t* curright; - long prebufsamples; - long batchsamples; - long cursamples; - long cursamplepos; - int i; - - num_samples /= downsample; - - if ( num_samples == 0 ) - return GAIN_ANALYSIS_OK; - - cursamplepos = 0; - batchsamples = num_samples; - - switch ( num_channels) { - case 1: right_samples = left_samples; - case 2: break; - default: return GAIN_ANALYSIS_ERROR; - } - - prebufsamples = MAX_ORDER; - if ((size_t) prebufsamples > num_samples) - prebufsamples = num_samples; - - for ( i = 0; i < prebufsamples; ++i ) { - linprebuf[i+MAX_ORDER] = left_samples [i * downsample]; - rinprebuf[i+MAX_ORDER] = right_samples[i * downsample]; - } - - while ( batchsamples > 0 ) { - cursamples = batchsamples > (long)(sampleWindow-totsamp) ? (long)(sampleWindow - totsamp) : batchsamples; - if ( cursamplepos < MAX_ORDER ) { - downsample = 1; - curleft = linpre+cursamplepos; - curright = rinpre+cursamplepos; - if (cursamples > MAX_ORDER - cursamplepos ) - cursamples = MAX_ORDER - cursamplepos; - } - else { - downsample = replaygainfilter->downsample; - curleft = left_samples + cursamplepos * downsample; - curright = right_samples + cursamplepos * downsample; - } - - filter ( curleft , lstep + totsamp, cursamples, replaygainfilter->AYule, replaygainfilter->BYule, YULE_ORDER, downsample ); - filter ( curright, rstep + totsamp, cursamples, replaygainfilter->AYule, replaygainfilter->BYule, YULE_ORDER, downsample ); - - filter ( lstep + totsamp, lout + totsamp, cursamples, replaygainfilter->AButter, replaygainfilter->BButter, BUTTER_ORDER, 1 ); - filter ( rstep + totsamp, rout + totsamp, cursamples, replaygainfilter->AButter, replaygainfilter->BButter, BUTTER_ORDER, 1 ); - - for ( i = 0; i < cursamples; i++ ) { /* Get the squared values */ - lsum += lout [totsamp+i] * lout [totsamp+i]; - rsum += rout [totsamp+i] * rout [totsamp+i]; - } - - batchsamples -= cursamples; - cursamplepos += cursamples; - totsamp += cursamples; - if ( totsamp == sampleWindow ) { /* Get the Root Mean Square (RMS) for this set of samples */ - double val = STEPS_per_dB * 10. * log10 ( (lsum+rsum) / totsamp * 0.5 + 1.e-37 ); - int ival = (int) val; - if ( ival < 0 ) ival = 0; - if ( ival >= (int)(sizeof(A)/sizeof(*A)) ) ival = (int)(sizeof(A)/sizeof(*A)) - 1; - A [ival]++; - lsum = rsum = 0.; - memmove ( loutbuf , loutbuf + totsamp, MAX_ORDER * sizeof(flac_float_t) ); - memmove ( routbuf , routbuf + totsamp, MAX_ORDER * sizeof(flac_float_t) ); - memmove ( lstepbuf, lstepbuf + totsamp, MAX_ORDER * sizeof(flac_float_t) ); - memmove ( rstepbuf, rstepbuf + totsamp, MAX_ORDER * sizeof(flac_float_t) ); - totsamp = 0; - } - if ( totsamp > sampleWindow ) /* somehow I really screwed up: Error in programming! Contact author about totsamp > sampleWindow */ - return GAIN_ANALYSIS_ERROR; - } - - if ( num_samples < MAX_ORDER ) { - memmove ( linprebuf, linprebuf + num_samples, (MAX_ORDER-num_samples) * sizeof(flac_float_t) ); - memmove ( rinprebuf, rinprebuf + num_samples, (MAX_ORDER-num_samples) * sizeof(flac_float_t) ); - memcpy ( linprebuf + MAX_ORDER - num_samples, left_samples, num_samples * sizeof(flac_float_t) ); - memcpy ( rinprebuf + MAX_ORDER - num_samples, right_samples, num_samples * sizeof(flac_float_t) ); - } - else { - downsample = replaygainfilter->downsample; - - left_samples += (num_samples - MAX_ORDER) * downsample; - right_samples += (num_samples - MAX_ORDER) * downsample; - - for ( i = 0; i < MAX_ORDER; ++i ) { - linprebuf[i] = left_samples [i * downsample]; - rinprebuf[i] = right_samples[i * downsample]; - } - } - - return GAIN_ANALYSIS_OK; -} - - -static flac_float_t -analyzeResult ( uint32_t* Array, size_t len ) -{ - uint32_t elems; - int32_t upper; - size_t i; - - elems = 0; - for ( i = 0; i < len; i++ ) - elems += Array[i]; - if ( elems == 0 ) - return GAIN_NOT_ENOUGH_SAMPLES; - -/* workaround for GCC bug #61423: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61423 */ -#if 0 - upper = (int32_t) ceil (elems * (1. - RMS_PERCENTILE)); -#else - upper = (int32_t) (elems / 20 + ((elems % 20) ? 1 : 0)); -#endif - for ( i = len; i-- > 0; ) { - if ( (upper -= Array[i]) <= 0 ) - break; - } - - return (flac_float_t) ((flac_float_t)PINK_REF - (flac_float_t)i / (flac_float_t)STEPS_per_dB); -} - - -flac_float_t -GetTitleGain ( void ) -{ - flac_float_t retval; - uint32_t i; - - retval = analyzeResult ( A, sizeof(A)/sizeof(*A) ); - - for ( i = 0; i < sizeof(A)/sizeof(*A); i++ ) { - B[i] += A[i]; - A[i] = 0; - } - - for ( i = 0; i < MAX_ORDER; i++ ) - linprebuf[i] = lstepbuf[i] = loutbuf[i] = rinprebuf[i] = rstepbuf[i] = routbuf[i] = 0.f; - - totsamp = 0; - lsum = rsum = 0.; - return retval; -} - - -flac_float_t -GetAlbumGain ( void ) -{ - return analyzeResult ( B, sizeof(B)/sizeof(*B) ); -} - -/* end of replaygain_analysis.c */ diff --git a/flac/src/share/replaygain_synthesis/CMakeLists.txt b/flac/src/share/replaygain_synthesis/CMakeLists.txt deleted file mode 100644 index 0736f4f..0000000 --- a/flac/src/share/replaygain_synthesis/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_library(replaygain_synthesis STATIC - replaygain_synthesis.c) diff --git a/flac/src/share/replaygain_synthesis/replaygain_synthesis.c b/flac/src/share/replaygain_synthesis/replaygain_synthesis.c deleted file mode 100644 index 8d4fda6..0000000 --- a/flac/src/share/replaygain_synthesis/replaygain_synthesis.c +++ /dev/null @@ -1,429 +0,0 @@ -/* replaygain_synthesis - Routines for applying ReplayGain to a signal - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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.1 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 is an aggregation of pieces of code from John Edwards' WaveGain - * program. Mostly cosmetic changes were made; otherwise, the dithering - * code is almost untouched and the gain processing was converted from - * processing a whole file to processing chunks of samples. - * - * The original copyright notices for WaveGain's dither.c and wavegain.c - * appear below: - */ -/* - * (c) 2002 John Edwards - * mostly lifted from work by Frank Klemm - * random functions for dithering. - */ -/* - * Copyright (C) 2002 John Edwards - * Additional code by Magnus Holmgren and Gian-Carlo Pascutto - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include /* for memset() */ -#include -#include "share/compat.h" -#include "share/replaygain_synthesis.h" -#include "FLAC/assert.h" - -#define FLAC__I64L(x) x##LL - - -/* - * the following is based on parts of dither.c - */ - - -/* - * 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. - */ - -static uint32_t random_int_(void) -{ - static const uint8_t parity_[256] = { - 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 - }; - static uint32_t r1_ = 1; - static uint32_t r2_ = 1; - - uint32_t t1, t2, t3, t4; - - /* Parity calculation is done via table lookup, this is also available - * on CPUs without parity, can be implemented in C and avoid unpredictable - * jumps and slow rotate through the carry flag operations. - */ - t3 = t1 = r1_; t4 = t2 = r2_; - t1 &= 0xF5; t2 >>= 25; - t1 = parity_[t1]; t2 &= 0x63; - t1 <<= 31; t2 = parity_[t2]; - - return (r1_ = (t3 >> 1) | t1 ) ^ (r2_ = (t4 + t4) | t2 ); -} - -/* gives a equal distributed random number */ -/* between -2^31*mult and +2^31*mult */ -static double random_equi_(double mult) -{ - return mult * (int) random_int_(); -} - -/* gives a triangular distributed random number */ -/* between -2^32*mult and +2^32*mult */ -static double random_triangular_(double mult) -{ - return mult * ( (double) (int) random_int_() + (double) (int) random_int_() ); -} - - -static const float F44_0 [16 + 32] = { - (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, - (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, - - (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, - (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, - - (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, - (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0, (float)0 -}; - - -static const float F44_1 [16 + 32] = { /* SNR(w) = 4.843163 dB, SNR = -3.192134 dB */ - (float) 0.85018292704024355931, (float) 0.29089597350995344721, (float)-0.05021866022121039450, (float)-0.23545456294599161833, - (float)-0.58362726442227032096, (float)-0.67038978965193036429, (float)-0.38566861572833459221, (float)-0.15218663390367969967, - (float)-0.02577543084864530676, (float) 0.14119295297688728127, (float) 0.22398848581628781612, (float) 0.15401727203382084116, - (float) 0.05216161232906000929, (float)-0.00282237820999675451, (float)-0.03042794608323867363, (float)-0.03109780942998826024, - - (float) 0.85018292704024355931, (float) 0.29089597350995344721, (float)-0.05021866022121039450, (float)-0.23545456294599161833, - (float)-0.58362726442227032096, (float)-0.67038978965193036429, (float)-0.38566861572833459221, (float)-0.15218663390367969967, - (float)-0.02577543084864530676, (float) 0.14119295297688728127, (float) 0.22398848581628781612, (float) 0.15401727203382084116, - (float) 0.05216161232906000929, (float)-0.00282237820999675451, (float)-0.03042794608323867363, (float)-0.03109780942998826024, - - (float) 0.85018292704024355931, (float) 0.29089597350995344721, (float)-0.05021866022121039450, (float)-0.23545456294599161833, - (float)-0.58362726442227032096, (float)-0.67038978965193036429, (float)-0.38566861572833459221, (float)-0.15218663390367969967, - (float)-0.02577543084864530676, (float) 0.14119295297688728127, (float) 0.22398848581628781612, (float) 0.15401727203382084116, - (float) 0.05216161232906000929, (float)-0.00282237820999675451, (float)-0.03042794608323867363, (float)-0.03109780942998826024, -}; - - -static const float F44_2 [16 + 32] = { /* SNR(w) = 10.060213 dB, SNR = -12.766730 dB */ - (float) 1.78827593892108555290, (float) 0.95508210637394326553, (float)-0.18447626783899924429, (float)-0.44198126506275016437, - (float)-0.88404052492547413497, (float)-1.42218907262407452967, (float)-1.02037566838362314995, (float)-0.34861755756425577264, - (float)-0.11490230170431934434, (float) 0.12498899339968611803, (float) 0.38065885268563131927, (float) 0.31883491321310506562, - (float) 0.10486838686563442765, (float)-0.03105361685110374845, (float)-0.06450524884075370758, (float)-0.02939198261121969816, - - (float) 1.78827593892108555290, (float) 0.95508210637394326553, (float)-0.18447626783899924429, (float)-0.44198126506275016437, - (float)-0.88404052492547413497, (float)-1.42218907262407452967, (float)-1.02037566838362314995, (float)-0.34861755756425577264, - (float)-0.11490230170431934434, (float) 0.12498899339968611803, (float) 0.38065885268563131927, (float) 0.31883491321310506562, - (float) 0.10486838686563442765, (float)-0.03105361685110374845, (float)-0.06450524884075370758, (float)-0.02939198261121969816, - - (float) 1.78827593892108555290, (float) 0.95508210637394326553, (float)-0.18447626783899924429, (float)-0.44198126506275016437, - (float)-0.88404052492547413497, (float)-1.42218907262407452967, (float)-1.02037566838362314995, (float)-0.34861755756425577264, - (float)-0.11490230170431934434, (float) 0.12498899339968611803, (float) 0.38065885268563131927, (float) 0.31883491321310506562, - (float) 0.10486838686563442765, (float)-0.03105361685110374845, (float)-0.06450524884075370758, (float)-0.02939198261121969816, -}; - - -static const float F44_3 [16 + 32] = { /* SNR(w) = 15.382598 dB, SNR = -29.402334 dB */ - (float) 2.89072132015058161445, (float) 2.68932810943698754106, (float) 0.21083359339410251227, (float)-0.98385073324997617515, - (float)-1.11047823227097316719, (float)-2.18954076314139673147, (float)-2.36498032881953056225, (float)-0.95484132880101140785, - (float)-0.23924057925542965158, (float)-0.13865235703915925642, (float) 0.43587843191057992846, (float) 0.65903257226026665927, - (float) 0.24361815372443152787, (float)-0.00235974960154720097, (float) 0.01844166574603346289, (float) 0.01722945988740875099, - - (float) 2.89072132015058161445, (float) 2.68932810943698754106, (float) 0.21083359339410251227, (float)-0.98385073324997617515, - (float)-1.11047823227097316719, (float)-2.18954076314139673147, (float)-2.36498032881953056225, (float)-0.95484132880101140785, - (float)-0.23924057925542965158, (float)-0.13865235703915925642, (float) 0.43587843191057992846, (float) 0.65903257226026665927, - (float) 0.24361815372443152787, (float)-0.00235974960154720097, (float) 0.01844166574603346289, (float) 0.01722945988740875099, - - (float) 2.89072132015058161445, (float) 2.68932810943698754106, (float) 0.21083359339410251227, (float)-0.98385073324997617515, - (float)-1.11047823227097316719, (float)-2.18954076314139673147, (float)-2.36498032881953056225, (float)-0.95484132880101140785, - (float)-0.23924057925542965158, (float)-0.13865235703915925642, (float) 0.43587843191057992846, (float) 0.65903257226026665927, - (float) 0.24361815372443152787, (float)-0.00235974960154720097, (float) 0.01844166574603346289, (float) 0.01722945988740875099 -}; - - -static double scalar16_(const float* x, const float* y) -{ - return - x[ 0]*y[ 0] + x[ 1]*y[ 1] + x[ 2]*y[ 2] + x[ 3]*y[ 3] + - x[ 4]*y[ 4] + x[ 5]*y[ 5] + x[ 6]*y[ 6] + x[ 7]*y[ 7] + - x[ 8]*y[ 8] + x[ 9]*y[ 9] + x[10]*y[10] + x[11]*y[11] + - x[12]*y[12] + x[13]*y[13] + x[14]*y[14] + x[15]*y[15]; -} - - -void FLAC__replaygain_synthesis__init_dither_context(DitherContext *d, int bits, int shapingtype) -{ - static uint8_t default_dither [] = { 92, 92, 88, 84, 81, 78, 74, 67, 0, 0 }; - static const float* F [] = { F44_0, F44_1, F44_2, F44_3 }; - - int indx; - - if (shapingtype < 0) shapingtype = 0; - if (shapingtype > 3) shapingtype = 3; - d->ShapingType = (NoiseShaping)shapingtype; - indx = bits - 11 - shapingtype; - if (indx < 0) indx = 0; - if (indx > 9) indx = 9; - - memset ( d->ErrorHistory , 0, sizeof (d->ErrorHistory ) ); - memset ( d->DitherHistory, 0, sizeof (d->DitherHistory) ); - - d->FilterCoeff = F [shapingtype]; - d->Mask = ((FLAC__uint64)-1) << (32 - bits); - d->Add = 0.5 * ((1L << (32 - bits)) - 1); - d->Dither = 0.01f*default_dither[indx] / (((FLAC__int64)1) << bits); - d->LastHistoryIndex = 0; -} - -static inline int64_t -ROUND64 (DitherContext *d, double x) -{ - union { - double d; - int64_t i; - } doubletmp; - - doubletmp.d = x + d->Add + (int64_t)FLAC__I64L(0x001FFFFD80000000); - - return doubletmp.i - (int64_t)FLAC__I64L(0x433FFFFD80000000); -} - -/* - * the following is based on parts of wavegain.c - */ - -static int64_t dither_output_(DitherContext *d, FLAC__bool do_dithering, int shapingtype, int i, double Sum, int k) -{ - double Sum2; - int64_t val; - - if(do_dithering) { - if(shapingtype == 0) { - double tmp = random_equi_(d->Dither); - Sum2 = tmp - d->LastRandomNumber [k]; - d->LastRandomNumber [k] = (int)tmp; - Sum2 = Sum += Sum2; - val = ROUND64(d, Sum2) & d->Mask; - } - else { - Sum2 = random_triangular_(d->Dither) - scalar16_(d->DitherHistory[k], d->FilterCoeff + i); - Sum += d->DitherHistory [k] [(-1-i)&15] = (float)Sum2; - Sum2 = Sum + scalar16_(d->ErrorHistory [k], d->FilterCoeff + i); - val = ROUND64(d, Sum2) & d->Mask; - d->ErrorHistory [k] [(-1-i)&15] = (float)(Sum - val); - } - return val; - } - - return ROUND64(d, Sum); -} - -#if 0 - float peak = 0.f, - new_peak, - factor_clip - double scale, - dB; - - ... - - peak is in the range -32768.0 .. 32767.0 - - /* calculate factors for ReplayGain and ClippingPrevention */ - *track_gain = GetTitleGain() + settings->man_gain; - scale = (float) pow(10., *track_gain * 0.05); - if(settings->clip_prev) { - factor_clip = (float) (32767./( peak + 1)); - if(scale < factor_clip) - factor_clip = 1.f; - else - factor_clip /= scale; - scale *= factor_clip; - } - new_peak = (float) peak * scale; - - dB = 20. * log10(scale); - *track_gain = (float) dB; - - const double scale = pow(10., (double)gain * 0.05); -#endif - - -size_t FLAC__replaygain_synthesis__apply_gain(FLAC__byte *data_out, FLAC__bool little_endian_data_out, FLAC__bool uint32_t_data_out, const FLAC__int32 * const input[], uint32_t wide_samples, uint32_t channels, const uint32_t source_bps, const uint32_t target_bps, const double scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context) -{ - static const FLAC__int64 hard_clip_factors_[33] = { - 0, /* 0 bits-per-sample (not supported) */ - 0, /* 1 bits-per-sample (not supported) */ - 0, /* 2 bits-per-sample (not supported) */ - 0, /* 3 bits-per-sample (not supported) */ - -8, /* 4 bits-per-sample */ - -16, /* 5 bits-per-sample */ - -32, /* 6 bits-per-sample */ - -64, /* 7 bits-per-sample */ - -128, /* 8 bits-per-sample */ - -256, /* 9 bits-per-sample */ - -512, /* 10 bits-per-sample */ - -1024, /* 11 bits-per-sample */ - -2048, /* 12 bits-per-sample */ - -4096, /* 13 bits-per-sample */ - -8192, /* 14 bits-per-sample */ - -16384, /* 15 bits-per-sample */ - -32768, /* 16 bits-per-sample */ - -65536, /* 17 bits-per-sample */ - -131072, /* 18 bits-per-sample */ - -262144, /* 19 bits-per-sample */ - -524288, /* 20 bits-per-sample */ - -1048576, /* 21 bits-per-sample */ - -2097152, /* 22 bits-per-sample */ - -4194304, /* 23 bits-per-sample */ - -8388608, /* 24 bits-per-sample */ - -16777216, /* 25 bits-per-sample */ - -33554432, /* 26 bits-per-sample */ - -67108864, /* 27 bits-per-sample */ - -134217728, /* 28 bits-per-sample */ - -268435456, /* 29 bits-per-sample */ - -536870912, /* 30 bits-per-sample */ - -1073741824, /* 31 bits-per-sample */ - (FLAC__int64)(-1073741824) * 2 /* 32 bits-per-sample */ - }; - const FLAC__int32 conv_shift = 32 - target_bps; - const FLAC__int64 hard_clip_factor = hard_clip_factors_[target_bps]; - /* - * The integer input coming in has a varying range based on the - * source_bps. We want to normalize it to [-1.0, 1.0) so instead - * of doing two multiplies on each sample, we just multiple - * 'scale' by 1/(2^(source_bps-1)) - */ - const double multi_scale = scale / (double)(1u << (source_bps-1)); - - FLAC__byte * const start = data_out; - uint32_t i, channel; - const FLAC__int32 *input_; - double sample; - const uint32_t bytes_per_sample = target_bps / 8; - const uint32_t last_history_index = dither_context->LastHistoryIndex; - NoiseShaping noise_shaping = dither_context->ShapingType; - FLAC__int64 val64; - FLAC__int32 val32; - FLAC__int32 uval32; - const FLAC__uint32 twiggle = 1u << (target_bps - 1); - - FLAC__ASSERT(channels > 0 && channels <= FLAC_SHARE__MAX_SUPPORTED_CHANNELS); - FLAC__ASSERT(source_bps >= 4); - FLAC__ASSERT(target_bps >= 4); - FLAC__ASSERT(source_bps <= 32); - FLAC__ASSERT(target_bps < 32); - FLAC__ASSERT((target_bps & 7) == 0); - - for(channel = 0; channel < channels; channel++) { - const uint32_t incr = bytes_per_sample * channels; - data_out = start + bytes_per_sample * channel; - input_ = input[channel]; - for(i = 0; i < wide_samples; i++, data_out += incr) { - sample = (double)input_[i] * multi_scale; - - if(hard_limit) { - /* hard 6dB limiting */ - if(sample < -0.5) - sample = tanh((sample + 0.5) / (1-0.5)) * (1-0.5) - 0.5; - else if(sample > 0.5) - sample = tanh((sample - 0.5) / (1-0.5)) * (1-0.5) + 0.5; - } - sample *= 2147483647.; - - val64 = dither_output_(dither_context, do_dithering, noise_shaping, (i + last_history_index) % 32, sample, channel) >> conv_shift; - - val32 = (FLAC__int32)val64; - if(val64 >= -hard_clip_factor) - val32 = (FLAC__int32)(-(hard_clip_factor+1)); - else if(val64 < hard_clip_factor) - val32 = (FLAC__int32)hard_clip_factor; - - uval32 = (FLAC__uint32)val32; - if (uint32_t_data_out) - uval32 ^= twiggle; - - if (little_endian_data_out) { - switch(target_bps) { - case 24: - data_out[2] = (FLAC__byte)(uval32 >> 16); - /* fall through */ - case 16: - data_out[1] = (FLAC__byte)(uval32 >> 8); - /* fall through */ - case 8: - data_out[0] = (FLAC__byte)uval32; - break; - } - } - else { - switch(target_bps) { - case 24: - data_out[0] = (FLAC__byte)(uval32 >> 16); - data_out[1] = (FLAC__byte)(uval32 >> 8); - data_out[2] = (FLAC__byte)uval32; - break; - case 16: - data_out[0] = (FLAC__byte)(uval32 >> 8); - data_out[1] = (FLAC__byte)uval32; - break; - case 8: - data_out[0] = (FLAC__byte)uval32; - break; - } - } - } - } - dither_context->LastHistoryIndex = (last_history_index + wide_samples) % 32; - - return wide_samples * channels * (target_bps/8); -} diff --git a/flac/src/share/utf8/CMakeLists.txt b/flac/src/share/utf8/CMakeLists.txt deleted file mode 100644 index 389b09e..0000000 --- a/flac/src/share/utf8/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 3.12) - -add_library(utf8 STATIC - charset.c - iconvert.c - utf8.c) - -target_link_libraries(utf8 PUBLIC grabbag $) diff --git a/flac/src/share/utf8/charmaps.h b/flac/src/share/utf8/charmaps.h deleted file mode 100644 index 16d049a..0000000 --- a/flac/src/share/utf8/charmaps.h +++ /dev/null @@ -1,57 +0,0 @@ - -/* - * If you need to generate more maps, use makemap.c on a system - * with a decent iconv. - */ - -static const uint16_t mapping_iso_8859_2[256] = { - 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, - 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, - 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, - 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, - 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, - 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, - 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, - 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, - 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, - 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, - 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, - 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, - 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, - 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, - 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, - 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, - 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, - 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, - 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, - 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, - 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, - 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, - 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, - 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, - 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, - 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, - 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, - 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, - 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, - 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, - 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, - 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9 -}; - -static struct { - const char *name; - const uint16_t *map; - struct charset *charset; -} maps[] = { - { "ISO-8859-2", mapping_iso_8859_2, 0 }, - { 0, 0, 0 } -}; - -static const struct { - const char *bad; - const char *good; -} names[] = { - { "ANSI_X3.4-1968", "us-ascii" }, - { 0, 0 } -}; diff --git a/flac/src/share/utf8/charset.c b/flac/src/share/utf8/charset.c deleted file mode 100644 index 5c5693d..0000000 --- a/flac/src/share/utf8/charset.c +++ /dev/null @@ -1,534 +0,0 @@ -/* - * Copyright (C) 2001 Edmund Grimley Evans - * - * 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. - */ - -/* - * See the corresponding header file for a description of the functions - * that this file provides. - * - * This was first written for Ogg Vorbis but could be of general use. - * - * The only deliberate assumption about data sizes is that a short has - * at least 16 bits, but this code has only been tested on systems with - * 8-bit char, 16-bit short and 32-bit int. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#if !defined _WIN32 && !defined HAVE_ICONV /* should be && defined USE_CHARSET_CONVERT */ - -#include - -#include "share/alloc.h" -#include "charset.h" - -#include "charmaps.h" - -/* - * This is like the standard strcasecmp, but it does not depend - * on the locale. Locale-dependent functions can be dangerous: - * we once had a bug involving strcasecmp("iso", "ISO") in a - * Turkish locale! - * - * (I'm not really sure what the official standard says - * about the sign of strcasecmp("Z", "["), but usually - * we're only interested in whether it's zero.) - */ - -static int ascii_strcasecmp(const char *s1, const char *s2) -{ - char c1, c2; - - for (;; s1++, s2++) { - if (!*s1 || !*s2) - break; - if (*s1 == *s2) - continue; - c1 = *s1; - if ('a' <= c1 && c1 <= 'z') - c1 += 'A' - 'a'; - c2 = *s2; - if ('a' <= c2 && c2 <= 'z') - c2 += 'A' - 'a'; - if (c1 != c2) - break; - } - return (uint8_t)*s1 - (uint8_t)*s2; -} - -/* - * UTF-8 equivalents of the C library's wctomb() and mbtowc(). - */ - -int utf8_mbtowc(int *pwc, const char *s, size_t n) -{ - uint8_t c; - int wc, i, k; - - if (!n || !s) - return 0; - - c = *s; - if (c < 0x80) { - if (pwc) - *pwc = c; - return c ? 1 : 0; - } - else if (c < 0xc2) - return -1; - else if (c < 0xe0) { - if (n >= 2 && (s[1] & 0xc0) == 0x80) { - if (pwc) - *pwc = ((c & 0x1f) << 6) | (s[1] & 0x3f); - return 2; - } - else - return -1; - } - else if (c < 0xf0) - k = 3; - else if (c < 0xf8) - k = 4; - else if (c < 0xfc) - k = 5; - else if (c < 0xfe) - k = 6; - else - return -1; - - if (n < (size_t)k) - return -1; - wc = *s++ & ((1 << (7 - k)) - 1); - for (i = 1; i < k; i++) { - if ((*s & 0xc0) != 0x80) - return -1; - wc = (wc << 6) | (*s++ & 0x3f); - } - if (wc < (1 << (5 * k - 4))) - return -1; - if (pwc) - *pwc = wc; - return k; -} - -int utf8_wctomb(char *s, int wc1) -{ - uint32_t wc = wc1; - - if (!s) - return 0; - if (wc < (1u << 7)) { - *s++ = wc; - return 1; - } - else if (wc < (1u << 11)) { - *s++ = 0xc0 | (wc >> 6); - *s++ = 0x80 | (wc & 0x3f); - return 2; - } - else if (wc < (1u << 16)) { - *s++ = 0xe0 | (wc >> 12); - *s++ = 0x80 | ((wc >> 6) & 0x3f); - *s++ = 0x80 | (wc & 0x3f); - return 3; - } - else if (wc < (1u << 21)) { - *s++ = 0xf0 | (wc >> 18); - *s++ = 0x80 | ((wc >> 12) & 0x3f); - *s++ = 0x80 | ((wc >> 6) & 0x3f); - *s++ = 0x80 | (wc & 0x3f); - return 4; - } - else if (wc < (1u << 26)) { - *s++ = 0xf8 | (wc >> 24); - *s++ = 0x80 | ((wc >> 18) & 0x3f); - *s++ = 0x80 | ((wc >> 12) & 0x3f); - *s++ = 0x80 | ((wc >> 6) & 0x3f); - *s++ = 0x80 | (wc & 0x3f); - return 5; - } - else if (wc < (1u << 31)) { - *s++ = 0xfc | (wc >> 30); - *s++ = 0x80 | ((wc >> 24) & 0x3f); - *s++ = 0x80 | ((wc >> 18) & 0x3f); - *s++ = 0x80 | ((wc >> 12) & 0x3f); - *s++ = 0x80 | ((wc >> 6) & 0x3f); - *s++ = 0x80 | (wc & 0x3f); - return 6; - } - else - return -1; -} - -/* - * The charset "object" and methods. - */ - -struct charset { - int max; - int (*mbtowc)(void *table, int *pwc, const char *s, size_t n); - int (*wctomb)(void *table, char *s, int wc); - void *map; -}; - -int charset_mbtowc(struct charset *charset, int *pwc, const char *s, size_t n) -{ - return (*charset->mbtowc)(charset->map, pwc, s, n); -} - -int charset_wctomb(struct charset *charset, char *s, int wc) -{ - return (*charset->wctomb)(charset->map, s, wc); -} - -int charset_max(struct charset *charset) -{ - return charset->max; -} - -/* - * Implementation of UTF-8. - */ - -static int mbtowc_utf8(void *map, int *pwc, const char *s, size_t n) -{ - (void)map; - return utf8_mbtowc(pwc, s, n); -} - -static int wctomb_utf8(void *map, char *s, int wc) -{ - (void)map; - return utf8_wctomb(s, wc); -} - -/* - * Implementation of US-ASCII. - * Probably on most architectures this compiles to less than 256 bytes - * of code, so we can save space by not having a table for this one. - */ - -static int mbtowc_ascii(void *map, int *pwc, const char *s, size_t n) -{ - int wc; - - (void)map; - if (!n || !s) - return 0; - wc = (uint8_t)*s; - if (wc & ~0x7f) - return -1; - if (pwc) - *pwc = wc; - return wc ? 1 : 0; -} - -static int wctomb_ascii(void *map, char *s, int wc) -{ - (void)map; - if (!s) - return 0; - if (wc & ~0x7f) - return -1; - *s = wc; - return 1; -} - -/* - * Implementation of ISO-8859-1. - * Probably on most architectures this compiles to less than 256 bytes - * of code, so we can save space by not having a table for this one. - */ - -static int mbtowc_iso1(void *map, int *pwc, const char *s, size_t n) -{ - int wc; - - (void)map; - if (!n || !s) - return 0; - wc = (uint8_t)*s; - if (wc & ~0xff) - return -1; - if (pwc) - *pwc = wc; - return wc ? 1 : 0; -} - -static int wctomb_iso1(void *map, char *s, int wc) -{ - (void)map; - if (!s) - return 0; - if (wc & ~0xff) - return -1; - *s = wc; - return 1; -} - -/* - * Implementation of any 8-bit charset. - */ - -struct map { - const uint16_t *from; - struct inverse_map *to; -}; - -static int mbtowc_8bit(void *map1, int *pwc, const char *s, size_t n) -{ - struct map *map = map1; - uint16_t wc; - - if (!n || !s) - return 0; - wc = map->from[(uint8_t)*s]; - if (wc == 0xffff) - return -1; - if (pwc) - *pwc = (int)wc; - return wc ? 1 : 0; -} - -/* - * For the inverse map we use a hash table, which has the advantages - * of small constant memory requirement and simple memory allocation, - * but the disadvantage of slow conversion in the worst case. - * If you need real-time performance while letting a potentially - * malicious user define their own map, then the method used in - * linux/drivers/char/consolemap.c would be more appropriate. - */ - -struct inverse_map { - uint8_t first[256]; - uint8_t next[256]; -}; - -/* - * The simple hash is good enough for this application. - * Use the alternative trivial hashes for testing. - */ -#define HASH(i) ((i) & 0xff) -/* #define HASH(i) 0 */ -/* #define HASH(i) 99 */ - -static struct inverse_map *make_inverse_map(const uint16_t *from) -{ - struct inverse_map *to; - char used[256]; - int i, j, k; - - to = malloc(sizeof(struct inverse_map)); - if (!to) - return 0; - for (i = 0; i < 256; i++) - to->first[i] = to->next[i] = used[i] = 0; - for (i = 255; i >= 0; i--) - if (from[i] != 0xffff) { - k = HASH(from[i]); - to->next[i] = to->first[k]; - to->first[k] = i; - used[k] = 1; - } - - /* Point the empty buckets at an empty list. */ - for (i = 0; i < 256; i++) - if (!to->next[i]) - break; - if (i < 256) - for (j = 0; j < 256; j++) - if (!used[j]) - to->first[j] = i; - - return to; -} - -static int wctomb_8bit(void *map1, char *s, int wc1) -{ - struct map *map = map1; - uint16_t wc = wc1; - int i; - - if (!s) - return 0; - - if (wc1 & ~0xffff) - return -1; - - if (1) /* Change 1 to 0 to test the case where malloc fails. */ - if (!map->to) - map->to = make_inverse_map(map->from); - - if (map->to) { - /* Use the inverse map. */ - i = map->to->first[HASH(wc)]; - for (;;) { - if (map->from[i] == wc) { - *s = i; - return 1; - } - if (!(i = map->to->next[i])) - break; - } - } - else { - /* We don't have an inverse map, so do a linear search. */ - for (i = 0; i < 256; i++) - if (map->from[i] == wc) { - *s = i; - return 1; - } - } - - return -1; -} - -/* - * The "constructor" charset_find(). - */ - -struct charset charset_utf8 = { - 6, - &mbtowc_utf8, - &wctomb_utf8, - 0 -}; - -struct charset charset_iso1 = { - 1, - &mbtowc_iso1, - &wctomb_iso1, - 0 -}; - -struct charset charset_ascii = { - 1, - &mbtowc_ascii, - &wctomb_ascii, - 0 -}; - -struct charset *charset_find(const char *code) -{ - int i; - - /* Find good (MIME) name. */ - for (i = 0; names[i].bad; i++) - if (!ascii_strcasecmp(code, names[i].bad)) { - code = names[i].good; - break; - } - - /* Recognise some charsets for which we avoid using a table. */ - if (!ascii_strcasecmp(code, "UTF-8")) - return &charset_utf8; - if (!ascii_strcasecmp(code, "US-ASCII")) - return &charset_ascii; - if (!ascii_strcasecmp(code, "ISO-8859-1")) - return &charset_iso1; - - /* Look for a mapping for a simple 8-bit encoding. */ - for (i = 0; maps[i].name; i++) - if (!ascii_strcasecmp(code, maps[i].name)) { - if (!maps[i].charset) { - maps[i].charset = malloc(sizeof(struct charset)); - if (maps[i].charset) { - struct map *map = malloc(sizeof(struct map)); - if (!map) { - free(maps[i].charset); - maps[i].charset = 0; - } - else { - maps[i].charset->max = 1; - maps[i].charset->mbtowc = &mbtowc_8bit; - maps[i].charset->wctomb = &wctomb_8bit; - maps[i].charset->map = map; - map->from = maps[i].map; - map->to = 0; /* inverse mapping is created when required */ - } - } - } - return maps[i].charset; - } - - return 0; -} - -/* - * Function to convert a buffer from one encoding to another. - * Invalid bytes are replaced by '#', and characters that are - * not available in the target encoding are replaced by '?'. - * Each of TO and TOLEN may be zero, if the result is not needed. - * The output buffer is null-terminated, so it is all right to - * use charset_convert(fromcode, tocode, s, strlen(s), &t, 0). - */ - -int charset_convert(const char *fromcode, const char *tocode, - const char *from, size_t fromlen, - char **to, size_t *tolen) -{ - int ret = 0; - struct charset *charset1, *charset2; - char *tobuf, *p; - int i, j, wc; - - charset1 = charset_find(fromcode); - charset2 = charset_find(tocode); - if (!charset1 || !charset2 ) - return -1; - - tobuf = safe_malloc_mul2add_(fromlen, /*times*/charset2->max, /*+*/1); - if (!tobuf) - return -2; - - for (p = tobuf; fromlen; from += i, fromlen -= i, p += j) { - i = charset_mbtowc(charset1, &wc, from, fromlen); - if (!i) - i = 1; - else if (i == -1) { - i = 1; - wc = '#'; - ret = 2; - } - j = charset_wctomb(charset2, p, wc); - if (j == -1) { - if (!ret) - ret = 1; - j = charset_wctomb(charset2, p, '?'); - if (j == -1) - j = 0; - } - } - - if (tolen) - *tolen = p - tobuf; - *p++ = '\0'; - if (to) { - char *tobuf_saved = tobuf; - *to = realloc(tobuf, p - tobuf); - if (*to == NULL) - *to = tobuf_saved; - } - else - free(tobuf); - - return ret; -} - -#endif /* USE_CHARSET_ICONV */ diff --git a/flac/src/share/utf8/charset.h b/flac/src/share/utf8/charset.h deleted file mode 100644 index ea8e31e..0000000 --- a/flac/src/share/utf8/charset.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2001 Edmund Grimley Evans - * - * 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. - */ - -#include - -/* - * These functions are like the C library's mbtowc() and wctomb(), - * but instead of depending on the locale they always work in UTF-8, - * and they use int instead of wchar_t. - */ - -int utf8_mbtowc(int *pwc, const char *s, size_t n); -int utf8_wctomb(char *s, int wc); - -/* - * This is an object-oriented version of mbtowc() and wctomb(). - * The caller first uses charset_find() to get a pointer to struct - * charset, then uses the mbtowc() and wctomb() methods on it. - * The function charset_max() gives the maximum length of a - * multibyte character in that encoding. - * This API is only appropriate for stateless encodings like UTF-8 - * or ISO-8859-3, but I have no intention of implementing anything - * other than UTF-8 and 8-bit encodings. - * - * MINOR BUG: If there is no memory charset_find() may return 0 and - * there is no way to distinguish this case from an unknown encoding. - */ - -struct charset; - -struct charset *charset_find(const char *code); - -int charset_mbtowc(struct charset *charset, int *pwc, const char *s, size_t n); -int charset_wctomb(struct charset *charset, char *s, int wc); -int charset_max(struct charset *charset); - -/* - * Function to convert a buffer from one encoding to another. - * Invalid bytes are replaced by '#', and characters that are - * not available in the target encoding are replaced by '?'. - * Each of TO and TOLEN may be zero if the result is not wanted. - * The input or output may contain null bytes, but the output - * buffer is also null-terminated, so it is all right to - * use charset_convert(fromcode, tocode, s, strlen(s), &t, 0). - * - * Return value: - * - * -2 : memory allocation failed - * -1 : unknown encoding - * 0 : data was converted exactly - * 1 : valid data was converted approximately (using '?') - * 2 : input was invalid (but still converted, using '#') - */ - -int charset_convert(const char *fromcode, const char *tocode, - const char *from, size_t fromlen, - char **to, size_t *tolen); diff --git a/flac/src/share/utf8/charset_test.c b/flac/src/share/utf8/charset_test.c deleted file mode 100644 index 6761100..0000000 --- a/flac/src/share/utf8/charset_test.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (C) 2001 Edmund Grimley Evans - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include "charset.h" - -void test_any(struct charset *charset) -{ - int wc; - char s[2]; - - assert(charset); - - /* Decoder */ - - assert(charset_mbtowc(charset, 0, 0, 0) == 0); - assert(charset_mbtowc(charset, 0, 0, 1) == 0); - assert(charset_mbtowc(charset, 0, (char *)(-1), 0) == 0); - - assert(charset_mbtowc(charset, 0, "a", 0) == 0); - assert(charset_mbtowc(charset, 0, "", 1) == 0); - assert(charset_mbtowc(charset, 0, "b", 1) == 1); - assert(charset_mbtowc(charset, 0, "", 2) == 0); - assert(charset_mbtowc(charset, 0, "c", 2) == 1); - - wc = 'x'; - assert(charset_mbtowc(charset, &wc, "a", 0) == 0 && wc == 'x'); - assert(charset_mbtowc(charset, &wc, "", 1) == 0 && wc == 0); - assert(charset_mbtowc(charset, &wc, "b", 1) == 1 && wc == 'b'); - assert(charset_mbtowc(charset, &wc, "", 2) == 0 && wc == 0); - assert(charset_mbtowc(charset, &wc, "c", 2) == 1 && wc == 'c'); - - /* Encoder */ - - assert(charset_wctomb(charset, 0, 0) == 0); - - s[0] = s[1] = '.'; - assert(charset_wctomb(charset, s, 0) == 1 && - s[0] == '\0' && s[1] == '.'); - assert(charset_wctomb(charset, s, 'x') == 1 && - s[0] == 'x' && s[1] == '.'); -} - -void test_utf8() -{ - struct charset *charset; - int wc; - char s[8]; - - charset = charset_find("UTF-8"); - test_any(charset); - - /* Decoder */ - wc = 0; - assert(charset_mbtowc(charset, &wc, "\177", 1) == 1 && wc == 127); - assert(charset_mbtowc(charset, &wc, "\200", 2) == -1); - assert(charset_mbtowc(charset, &wc, "\301\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\302\200", 1) == -1); - assert(charset_mbtowc(charset, &wc, "\302\200", 2) == 2 && wc == 128); - assert(charset_mbtowc(charset, &wc, "\302\200", 3) == 2 && wc == 128); - assert(charset_mbtowc(charset, &wc, "\340\237\200", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\340\240\200", 9) == 3 && - wc == 1 << 11); - assert(charset_mbtowc(charset, &wc, "\360\217\277\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\360\220\200\200", 9) == 4 && - wc == 1 << 16); - assert(charset_mbtowc(charset, &wc, "\370\207\277\277\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\370\210\200\200\200", 9) == 5 && - wc == 1 << 21); - assert(charset_mbtowc(charset, &wc, "\374\203\277\277\277\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\374\204\200\200\200\200", 9) == 6 && - wc == 1 << 26); - assert(charset_mbtowc(charset, &wc, "\375\277\277\277\277\277", 9) == 6 && - wc == 0x7fffffff); - - assert(charset_mbtowc(charset, &wc, "\302\000", 2) == -1); - assert(charset_mbtowc(charset, &wc, "\302\300", 2) == -1); - assert(charset_mbtowc(charset, &wc, "\340\040\200", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\340\340\200", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\340\240\000", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\340\240\300", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\360\020\200\200", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\360\320\200\200", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\360\220\000\200", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\360\220\300\200", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\360\220\200\000", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\360\220\200\300", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\375\077\277\277\277\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\375\377\277\277\277\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\375\277\077\277\277\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\375\277\377\277\277\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\375\277\277\277\077\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\375\277\277\277\377\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\375\277\277\277\277\077", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\375\277\277\277\277\377", 9) == -1); - - assert(charset_mbtowc(charset, &wc, "\376\277\277\277\277\277", 9) == -1); - assert(charset_mbtowc(charset, &wc, "\377\277\277\277\277\277", 9) == -1); - - /* Encoder */ - safe_strncpy(s, ".......", sizeof(s)); - assert(charset_wctomb(charset, s, 1u << 31) == -1 && - !strcmp(s, ".......")); - assert(charset_wctomb(charset, s, 127) == 1 && - !strcmp(s, "\177......")); - assert(charset_wctomb(charset, s, 128) == 2 && - !strcmp(s, "\302\200.....")); - assert(charset_wctomb(charset, s, 0x7ff) == 2 && - !strcmp(s, "\337\277.....")); - assert(charset_wctomb(charset, s, 0x800) == 3 && - !strcmp(s, "\340\240\200....")); - assert(charset_wctomb(charset, s, 0xffff) == 3 && - !strcmp(s, "\357\277\277....")); - assert(charset_wctomb(charset, s, 0x10000) == 4 && - !strcmp(s, "\360\220\200\200...")); - assert(charset_wctomb(charset, s, 0x1fffff) == 4 && - !strcmp(s, "\367\277\277\277...")); - assert(charset_wctomb(charset, s, 0x200000) == 5 && - !strcmp(s, "\370\210\200\200\200..")); - assert(charset_wctomb(charset, s, 0x3ffffff) == 5 && - !strcmp(s, "\373\277\277\277\277..")); - assert(charset_wctomb(charset, s, 0x4000000) == 6 && - !strcmp(s, "\374\204\200\200\200\200.")); - assert(charset_wctomb(charset, s, 0x7fffffff) == 6 && - !strcmp(s, "\375\277\277\277\277\277.")); -} - -void test_ascii() -{ - struct charset *charset; - int wc; - char s[3]; - - charset = charset_find("us-ascii"); - test_any(charset); - - /* Decoder */ - wc = 0; - assert(charset_mbtowc(charset, &wc, "\177", 2) == 1 && wc == 127); - assert(charset_mbtowc(charset, &wc, "\200", 2) == -1); - - /* Encoder */ - safe_strncpy(s, "..", sizeof(s)); - assert(charset_wctomb(charset, s, 256) == -1 && !strcmp(s, "..")); - assert(charset_wctomb(charset, s, 255) == -1); - assert(charset_wctomb(charset, s, 128) == -1); - assert(charset_wctomb(charset, s, 127) == 1 && !strcmp(s, "\177.")); -} - -void test_iso1() -{ - struct charset *charset; - int wc; - char s[3]; - - charset = charset_find("iso-8859-1"); - test_any(charset); - - /* Decoder */ - wc = 0; - assert(charset_mbtowc(charset, &wc, "\302\200", 9) == 1 && wc == 0xc2); - - /* Encoder */ - safe_strncpy(s, "..", sizeof(s)); - assert(charset_wctomb(charset, s, 256) == -1 && !strcmp(s, "..")); - assert(charset_wctomb(charset, s, 255) == 1 && !strcmp(s, "\377.")); - assert(charset_wctomb(charset, s, 128) == 1 && !strcmp(s, "\200.")); -} - -void test_iso2() -{ - struct charset *charset; - int wc; - char s[3]; - - charset = charset_find("iso-8859-2"); - test_any(charset); - - /* Decoder */ - wc = 0; - assert(charset_mbtowc(charset, &wc, "\302\200", 9) == 1 && wc == 0xc2); - assert(charset_mbtowc(charset, &wc, "\377", 2) == 1 && wc == 0x2d9); - - /* Encoder */ - safe_strncpy(s, "..", sizeof(s)); - assert(charset_wctomb(charset, s, 256) == -1 && !strcmp(s, "..")); - assert(charset_wctomb(charset, s, 255) == -1 && !strcmp(s, "..")); - assert(charset_wctomb(charset, s, 258) == 1 && !strcmp(s, "\303.")); - assert(charset_wctomb(charset, s, 128) == 1 && !strcmp(s, "\200.")); -} - -void test_convert() -{ - const char *p; - char *q, *r; - char s[256]; - size_t n, n2; - int i; - - p = "\000x\302\200\375\277\277\277\277\277"; - assert(charset_convert("UTF-8", "UTF-8", p, 10, &q, &n) == 0 && - n == 10 && !strcmp(p, q)); - assert(charset_convert("UTF-8", "UTF-8", "x\301\277y", 4, &q, &n) == 2 && - n == 4 && !strcmp(q, "x##y")); - assert(charset_convert("UTF-8", "UTF-8", "x\301\277y", 4, 0, &n) == 2 && - n == 4); - assert(charset_convert("UTF-8", "UTF-8", "x\301\277y", 4, &q, 0) == 2 && - !strcmp(q, "x##y")); - assert(charset_convert("UTF-8", "iso-8859-1", - "\302\200\304\200x", 5, &q, &n) == 1 && - n == 3 && !strcmp(q, "\200?x")); - assert(charset_convert("iso-8859-1", "UTF-8", - "\000\200\377", 3, &q, &n) == 0 && - n == 5 && !memcmp(q, "\000\302\200\303\277", 5)); - assert(charset_convert("iso-8859-1", "iso-8859-1", - "\000\200\377", 3, &q, &n) == 0 && - n == 3 && !memcmp(q, "\000\200\377", 3)); - - assert(charset_convert("iso-8859-2", "utf-8", "\300", 1, &q, &n) == 0 && - n == 2 && !strcmp(q, "\305\224")); - assert(charset_convert("utf-8", "iso-8859-2", "\305\224", 2, &q, &n) == 0 && - n == 1 && !strcmp(q, "\300")); - - for (i = 0; i < 256; i++) - s[i] = i; - - assert(charset_convert("iso-8859-2", "utf-8", s, 256, &q, &n) == 0); - assert(charset_convert("utf-8", "iso-8859-2", q, n, &r, &n2) == 0); - assert(n2 == 256 && !memcmp(r, s, n2)); -} - -int main() -{ - test_utf8(); - test_ascii(); - test_iso1(); - test_iso2(); - - test_convert(); - - return 0; -} diff --git a/flac/src/share/utf8/iconvert.c b/flac/src/share/utf8/iconvert.c deleted file mode 100644 index 9a1e3f6..0000000 --- a/flac/src/share/utf8/iconvert.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (C) 2001 Edmund Grimley Evans - * - * 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 HAVE_CONFIG_H -# include -#endif - -#if !defined _WIN32 && defined HAVE_ICONV - -#include -#include -#include -#include -#include -#include - -#include "iconvert.h" -#include "share/alloc.h" -#include "share/safe_str.h" - -/* - * Convert data from one encoding to another. Return: - * - * -2 : memory allocation failed - * -1 : unknown encoding - * 0 : data was converted exactly - * 1 : data was converted inexactly - * 2 : data was invalid (but still converted) - * - * We convert in two steps, via UTF-8, as this is the only - * reliable way of distinguishing between invalid input - * and valid input which iconv refuses to transliterate. - * We convert from UTF-8 twice, because we have no way of - * knowing whether the conversion was exact if iconv returns - * E2BIG (due to a bug in the specification of iconv). - * An alternative approach is to assume that the output of - * iconv is never more than 4 times as long as the input, - * but I prefer to avoid that assumption if possible. - */ - -int iconvert(const char *fromcode, const char *tocode, - const char *from, size_t fromlen, - char **to, size_t *tolen) -{ - int ret = 0; - iconv_t cd1, cd2; - char *ib; - char *ob; - char *utfbuf = 0, *outbuf, *newbuf; - size_t utflen, outlen, ibl, obl, obp, k; - char tbuf[2048]; - - cd1 = iconv_open("UTF-8", fromcode); - if (cd1 == (iconv_t)(-1)) - return -1; - - cd2 = (iconv_t)(-1); - /* Don't use strcasecmp() as it's locale-dependent. */ - if (!strchr("Uu", tocode[0]) || - !strchr("Tt", tocode[1]) || - !strchr("Ff", tocode[2]) || - tocode[3] != '-' || - tocode[4] != '8' || - tocode[5] != '\0') { - char *tocode1; - int rc; - /* - * Try using this non-standard feature of glibc and libiconv. - * This is deliberately not a config option as people often - * change their iconv library without rebuilding applications. - */ - - rc = asprintf(&tocode1, "%s//TRANSLIT", tocode); - if (rc < 0 || ! tocode1) - goto fail; - - cd2 = iconv_open(tocode1, "UTF-8"); - free(tocode1); - - if (cd2 == (iconv_t)(-1)) - cd2 = iconv_open(tocode, fromcode); - - if (cd2 == (iconv_t)(-1)) { - iconv_close(cd1); - return -1; - } - } - - utflen = 1; /*fromlen * 2 + 1; XXX */ - utfbuf = malloc(utflen); - if (!utfbuf) - goto fail; - - /* Convert to UTF-8 */ - ib = (char *)from; - ibl = fromlen; - ob = utfbuf; - obl = utflen; - for (;;) { - k = iconv(cd1, &ib, &ibl, &ob, &obl); - assert((!k && !ibl) || - (k == (size_t)(-1) && errno == E2BIG && ibl && obl < 6) || - (k == (size_t)(-1) && - (errno == EILSEQ || errno == EINVAL) && ibl)); - if (!ibl) - break; - if (obl < 6) { - /* Enlarge the buffer */ - if(utflen*2 < utflen) /* overflow check */ - goto fail; - utflen *= 2; - obp = ob - utfbuf; /* save position */ - newbuf = realloc(utfbuf, utflen); - if (!newbuf) - goto fail; - ob = newbuf + obp; - obl = utflen - obp; - utfbuf = newbuf; - } - else { - /* Invalid input */ - ib++, ibl--; - *ob++ = '#', obl--; - ret = 2; - iconv(cd1, 0, 0, 0, 0); - } - } - - if (cd2 == (iconv_t)(-1)) { - /* The target encoding was UTF-8 */ - if (tolen) - *tolen = ob - utfbuf; - if (!to) { - free(utfbuf); - iconv_close(cd1); - return ret; - } - newbuf = safe_realloc_nofree_add_2op_(utfbuf, (ob - utfbuf), /*+*/1); - if (!newbuf) - goto fail; - ob = (ob - utfbuf) + newbuf; - *ob = '\0'; - *to = newbuf; - iconv_close(cd1); - return ret; - } - - /* Truncate the buffer to be tidy */ - utflen = ob - utfbuf; - if (utflen == 0) - goto fail; - newbuf = realloc(utfbuf, utflen); - if (!newbuf) - goto fail; - utfbuf = newbuf; - - /* Convert from UTF-8 to discover how long the output is */ - outlen = 0; - ib = utfbuf; - ibl = utflen; - while (ibl) { - ob = tbuf; - obl = sizeof(tbuf); - k = iconv(cd2, &ib, &ibl, &ob, &obl); - assert((k != (size_t)(-1) && !ibl) || - (k == (size_t)(-1) && errno == E2BIG && ibl) || - (k == (size_t)(-1) && errno == EILSEQ && ibl)); - if (ibl && !(k == (size_t)(-1) && errno == E2BIG)) { - /* Replace one character */ - char *tb = "?"; - size_t tbl = 1; - - outlen += ob - tbuf; - ob = tbuf; - obl = sizeof(tbuf); - k = iconv(cd2, &tb, &tbl, &ob, &obl); - assert((!k && !tbl) || - (k == (size_t)(-1) && errno == EILSEQ && tbl)); - for (++ib, --ibl; ibl && (*ib & 0x80); ib++, ibl--) - ; - } - outlen += ob - tbuf; - } - ob = tbuf; - obl = sizeof(tbuf); - k = iconv(cd2, 0, 0, &ob, &obl); - assert(!k); - outlen += ob - tbuf; - - /* Convert from UTF-8 for real */ - outbuf = safe_malloc_add_2op_(outlen, /*+*/1); - if (!outbuf) - goto fail; - ib = utfbuf; - ibl = utflen; - ob = outbuf; - obl = outlen; - while (ibl) { - k = iconv(cd2, &ib, &ibl, &ob, &obl); - assert((k != (size_t)(-1) && !ibl) || - (k == (size_t)(-1) && errno == EILSEQ && ibl)); - if (k && !ret) - ret = 1; - if (ibl && !(k == (size_t)(-1) && errno == E2BIG)) { - /* Replace one character */ - char *tb = "?"; - size_t tbl = 1; - - k = iconv(cd2, &tb, &tbl, &ob, &obl); - assert((!k && !tbl) || - (k == (size_t)(-1) && errno == EILSEQ && tbl)); - for (++ib, --ibl; ibl && (*ib & 0x80); ib++, ibl--) - ; - } - } - k = iconv(cd2, 0, 0, &ob, &obl); - assert(!k); - assert(!obl); - *ob = '\0'; - - free(utfbuf); - iconv_close(cd1); - iconv_close(cd2); - if (tolen) - *tolen = outlen; - if (!to) { - free(outbuf); - return ret; - } - *to = outbuf; - return ret; - - fail: - if(0 != utfbuf) - free(utfbuf); - iconv_close(cd1); - if (cd2 != (iconv_t)(-1)) - iconv_close(cd2); - return -2; -} - -#endif /* HAVE_ICONV */ diff --git a/flac/src/share/utf8/iconvert.h b/flac/src/share/utf8/iconvert.h deleted file mode 100644 index a2d75a2..0000000 --- a/flac/src/share/utf8/iconvert.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2001 Edmund Grimley Evans - * - * 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 HAVE_CONFIG_H -# include -#endif - -#ifdef HAVE_ICONV - -/* - * Convert data from one encoding to another. Return: - * - * -2 : memory allocation failed - * -1 : unknown encoding - * 0 : data was converted exactly - * 1 : data was converted inexactly - * 2 : data was invalid (but still converted) - * - * We convert in two steps, via UTF-8, as this is the only - * reliable way of distinguishing between invalid input - * and valid input which iconv refuses to transliterate. - * We convert from UTF-8 twice, because we have no way of - * knowing whether the conversion was exact if iconv returns - * E2BIG (due to a bug in the specification of iconv). - * An alternative approach is to assume that the output of - * iconv is never more than 4 times as long as the input, - * but I prefer to avoid that assumption if possible. - */ - -int iconvert(const char *fromcode, const char *tocode, - const char *from, size_t fromlen, - char **to, size_t *tolen) ; - -#endif /* HAVE_ICONV */ diff --git a/flac/src/share/utf8/makemap.c b/flac/src/share/utf8/makemap.c deleted file mode 100644 index 790021c..0000000 --- a/flac/src/share/utf8/makemap.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2001 Edmund Grimley Evans - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -int main(int argc, char *argv[]) -{ - iconv_t cd; - const char *ib; - char *ob; - size_t ibl, obl, k; - uint8_t c, buf[4]; - int i, wc; - - if (argc != 2) { - printf("Usage: %s ENCODING\n", argv[0]); - printf("Output a charset map for the 8-bit ENCODING.\n"); - return 1; - } - - cd = iconv_open("UCS-4", argv[1]); - if (cd == (iconv_t)(-1)) { - perror("iconv_open"); - return 1; - } - - for (i = 0; i < 256; i++) { - c = i; - ib = &c; - ibl = 1; - ob = buf; - obl = 4; - k = iconv(cd, &ib, &ibl, &ob, &obl); - if (!k && !ibl && !obl) { - wc = (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]; - if (wc >= 0xffff) { - printf("Dodgy value.\n"); - return 1; - } - } - else if (k == (size_t)(-1) && errno == EILSEQ) - wc = 0xffff; - else { - printf("Non-standard iconv.\n"); - return 1; - } - - if (i % 8 == 0) - printf(" "); - printf("0x%04x", wc); - if (i == 255) - printf("\n"); - else if (i % 8 == 7) - printf(",\n"); - else - printf(", "); - } - - return 0; -} diff --git a/flac/src/share/utf8/utf8.c b/flac/src/share/utf8/utf8.c deleted file mode 100644 index 34af187..0000000 --- a/flac/src/share/utf8/utf8.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (C) 2001 Peter Harris - * Copyright (C) 2001 Edmund Grimley Evans - * - * Buffer overflow checking added: Josh Coalson, 9/9/2007 - * - * Win32 part rewritten: lvqcl, 2/2/2016 - * - * 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. - */ - -/* - * Convert a string between UTF-8 and the locale's charset. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include "share/alloc.h" -#include "share/utf8.h" - -#ifdef _WIN32 - -#include - -int utf8_encode(const char *from, char **to) -{ - wchar_t *unicode = NULL; - char *utf8 = NULL; - int ret = -1; - - do { - int len; - - len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, from, -1, NULL, 0); - if(len == 0) break; - unicode = (wchar_t*) safe_malloc_mul_2op_((size_t)len, sizeof(wchar_t)); - if(unicode == NULL) break; - len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, from, -1, unicode, len); - if(len == 0) break; - - len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL); - if(len == 0) break; - utf8 = (char*) safe_malloc_mul_2op_((size_t)len, sizeof(char)); - if(utf8 == NULL) break; - len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len, NULL, NULL); - if(len == 0) break; - - ret = 0; - - } while(0); - - free(unicode); - - if(ret == 0) { - *to = utf8; - } else { - free(utf8); - *to = NULL; - } - - return ret; -} - -int utf8_decode(const char *from, char **to) -{ - wchar_t *unicode = NULL; - char *acp = NULL; - int ret = -1; - - do { - int len; - - len = MultiByteToWideChar(CP_UTF8, 0, from, -1, NULL, 0); - if(len == 0) break; - unicode = (wchar_t*) safe_malloc_mul_2op_((size_t)len, sizeof(wchar_t)); - if(unicode == NULL) break; - len = MultiByteToWideChar(CP_UTF8, 0, from, -1, unicode, len); - if(len == 0) break; - - len = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, unicode, -1, NULL, 0, NULL, NULL); - if(len == 0) break; - acp = (char*) safe_malloc_mul_2op_((size_t)len, sizeof(char)); - if(acp == NULL) break; - len = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, unicode, -1, acp, len, NULL, NULL); - if(len == 0) break; - - ret = 0; - - } while(0); - - free(unicode); - - if(ret == 0) { - *to = acp; - } else { - free(acp); - *to = NULL; - } - - return ret; -} - -#else /* End win32. Rest is for real operating systems */ - - -#ifdef HAVE_LANGINFO_CODESET -#include -#endif - -#include - -#include "share/safe_str.h" -#include "iconvert.h" -#include "charset.h" - -static const char *current_charset(void) -{ - const char *c = 0; -#ifdef HAVE_LANGINFO_CODESET - c = nl_langinfo(CODESET); -#endif - - if (!c) - c = getenv("CHARSET"); - - return c? c : "US-ASCII"; -} - -static int convert_buffer(const char *fromcode, const char *tocode, - const char *from, size_t fromlen, - char **to, size_t *tolen) -{ - int ret = -1; - -#ifdef HAVE_ICONV - ret = iconvert(fromcode, tocode, from, fromlen, to, tolen); - if (ret != -1) - return ret; -#endif - -#ifndef HAVE_ICONV /* should be ifdef USE_CHARSET_CONVERT */ - ret = charset_convert(fromcode, tocode, from, fromlen, to, tolen); - if (ret != -1) - return ret; -#endif - - return ret; -} - -static int convert_string(const char *fromcode, const char *tocode, - const char *from, char **to, char replace) -{ - int ret; - size_t fromlen; - char *s; - - fromlen = strlen(from); - ret = convert_buffer(fromcode, tocode, from, fromlen, to, 0); - if (ret == -2) - return -1; - if (ret != -1) - return ret; - - s = safe_malloc_add_2op_(fromlen, /*+*/1); - if (!s) - return -1; - snprintf(s, fromlen + 1, "%s", from); - *to = s; - for (; *s; s++) - if (*s & ~0x7f) - *s = replace; - return 3; -} - -int utf8_encode(const char *from, char **to) -{ - return convert_string(current_charset(), "UTF-8", from, to, '#'); -} - -int utf8_decode(const char *from, char **to) -{ - return convert_string("UTF-8", current_charset(), from, to, '?'); -} - -#endif diff --git a/flac/src/share/win_utf8_io/win_utf8_io.c b/flac/src/share/win_utf8_io/win_utf8_io.c deleted file mode 100644 index 3ae35b3..0000000 --- a/flac/src/share/win_utf8_io/win_utf8_io.c +++ /dev/null @@ -1,398 +0,0 @@ -/* libFLAC - Free Lossless Audio Codec library - * Copyright (C) 2013-2023 Xiph.Org Foundation - * - * 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 Xiph.org Foundation 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 FOUNDATION 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. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "share/win_utf8_io.h" - -#define UTF8_BUFFER_SIZE 32768 - -/* detect whether it is Windows APP (UWP) or standard Win32 envionment */ -#ifdef WINAPI_FAMILY_PARTITION - #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - #define FLAC_WINDOWS_APP 1 - #else - #define FLAC_WINDOWS_APP 0 - #endif -#else - #define FLAC_WINDOWS_APP 0 -#endif - -static int local_vsnprintf(char *str, size_t size, const char *fmt, va_list va) -{ - int rc; - -#if defined _MSC_VER - if (size == 0) - return 1024; - rc = vsnprintf_s(str, size, _TRUNCATE, fmt, va); - if (rc < 0) - rc = size - 1; -#elif defined __MINGW32__ - rc = __mingw_vsnprintf(str, size, fmt, va); -#else - rc = vsnprintf(str, size, fmt, va); -#endif - - return rc; -} - -/* convert WCHAR stored Unicode string to UTF-8. Caller is responsible for freeing memory */ -static char *utf8_from_wchar(const wchar_t *wstr) -{ - char *utf8str; - int len; - - if (!wstr) - return NULL; - if ((len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL)) == 0) - return NULL; - if ((utf8str = (char *)malloc(len)) == NULL) - return NULL; - if (WideCharToMultiByte(CP_UTF8, 0, wstr, -1, utf8str, len, NULL, NULL) == 0) { - free(utf8str); - utf8str = NULL; - } - - return utf8str; -} - -/* convert UTF-8 back to WCHAR. Caller is responsible for freeing memory */ -static wchar_t *wchar_from_utf8(const char *str) -{ - wchar_t *widestr; - int len; - - if (!str) - return NULL; - if ((len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0)) == 0) - return NULL; - if ((widestr = (wchar_t *)malloc(len*sizeof(wchar_t))) == NULL) - return NULL; - if (MultiByteToWideChar(CP_UTF8, 0, str, -1, widestr, len) == 0) { - free(widestr); - widestr = NULL; - } - - return widestr; -} - -/* retrieve WCHAR commandline, expand wildcards and convert everything to UTF-8 */ -int get_utf8_argv(int *argc, char ***argv) -{ -#if !FLAC_WINDOWS_APP - typedef int (__cdecl *wgetmainargs_t)(int*, wchar_t***, wchar_t***, int, int*); - wgetmainargs_t wgetmainargs; - HMODULE handle; -#endif // !FLAC_WINDOWS_APP - int wargc; - wchar_t **wargv; - wchar_t **wenv; - char **utf8argv; - int ret, i; - -#if FLAC_WINDOWS_APP - wargc = __argc; - wargv = __wargv; - wenv = _wenviron; -#else // !FLAC_WINDOWS_APP - if ((handle = LoadLibraryW(L"msvcrt.dll")) == NULL) return 1; - if ((wgetmainargs = (wgetmainargs_t)GetProcAddress(handle, "__wgetmainargs")) == NULL) { - FreeLibrary(handle); - return 1; - } - i = 0; - /* when the 4th argument is 1, __wgetmainargs expands wildcards but also erroneously converts \\?\c:\path\to\file.flac to \\file.flac */ - if (wgetmainargs(&wargc, &wargv, &wenv, 1, &i) != 0) { - FreeLibrary(handle); - return 1; - } -#endif // !FLAC_WINDOWS_APP - if ((utf8argv = (char **)calloc(wargc, sizeof(char*))) == NULL) { - #if !FLAC_WINDOWS_APP - FreeLibrary(handle); - #endif // !FLAC_WINDOWS_APP - return 1; - } - - ret = 0; - for (i=0; iactime; - ut.modtime = times->modtime; - ret = _wutime64(wname, &ut); - free(wname); - - return ret; -} - -int unlink_utf8(const char *filename) -{ - wchar_t *wname; - int ret; - - if (!(wname = wchar_from_utf8(filename))) return -1; - ret = _wunlink(wname); - free(wname); - - return ret; -} - -int rename_utf8(const char *oldname, const char *newname) -{ - wchar_t *wold = NULL; - wchar_t *wnew = NULL; - int ret = -1; - - do { - if (!(wold = wchar_from_utf8(oldname))) break; - if (!(wnew = wchar_from_utf8(newname))) break; - ret = _wrename(wold, wnew); - } while(0); - - free(wold); - free(wnew); - - return ret; -} diff --git a/flac/src/test_grabbag/CMakeLists.txt b/flac/src/test_grabbag/CMakeLists.txt deleted file mode 100644 index 56abe81..0000000 --- a/flac/src/test_grabbag/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(cuesheet) -add_subdirectory(picture) diff --git a/flac/src/test_grabbag/Makefile.am b/flac/src/test_grabbag/Makefile.am deleted file mode 100644 index ea71009..0000000 --- a/flac/src/test_grabbag/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -# FLAC - Free Lossless Audio Codec -# Copyright (C) 2002-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# This file is part the FLAC project. FLAC is comprised of several -# components distributed under different licenses. The codec libraries -# are distributed under Xiph.Org's BSD-like license (see the file -# COPYING.Xiph in this distribution). All other programs, libraries, and -# plugins are distributed under the GPL (see COPYING.GPL). The documentation -# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the -# FLAC distribution contains at the top the terms under which it may be -# distributed. -# -# Since this particular file is relevant to all components of FLAC, -# it may be distributed under the Xiph.Org license, which is the least -# restrictive of those mentioned above. See the file COPYING.Xiph in this -# distribution. - -SUBDIRS = cuesheet picture - -EXTRA_DIST = \ - CMakeLists.txt diff --git a/flac/src/test_grabbag/cuesheet/CMakeLists.txt b/flac/src/test_grabbag/cuesheet/CMakeLists.txt deleted file mode 100644 index 5f9a646..0000000 --- a/flac/src/test_grabbag/cuesheet/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_executable(test_cuesheet - main.c - $<$:../../../include/share/win_utf8_io.h> - $<$:../../share/win_utf8_io/win_utf8_io.c>) -target_link_libraries(test_cuesheet FLAC grabbag) diff --git a/flac/src/test_grabbag/cuesheet/Makefile.am b/flac/src/test_grabbag/cuesheet/Makefile.am deleted file mode 100644 index 1cee370..0000000 --- a/flac/src/test_grabbag/cuesheet/Makefile.am +++ /dev/null @@ -1,37 +0,0 @@ -# test_cuesheet - Simple tester for cuesheet routines in grabbag -# Copyright (C) 2002-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -EXTRA_DIST = \ - CMakeLists.txt - -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include -check_PROGRAMS = test_cuesheet -test_cuesheet_SOURCES = \ - main.c - -if OS_IS_WINDOWS -win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la -endif - -test_cuesheet_LDADD = \ - $(top_builddir)/src/share/grabbag/libgrabbag.la \ - $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/libFLAC/libFLAC.la \ - $(win_utf8_lib) - -CLEANFILES = test_cuesheet.exe diff --git a/flac/src/test_grabbag/cuesheet/main.c b/flac/src/test_grabbag/cuesheet/main.c deleted file mode 100644 index b3d0e9a..0000000 --- a/flac/src/test_grabbag/cuesheet/main.c +++ /dev/null @@ -1,147 +0,0 @@ -/* test_cuesheet - Simple tester for cuesheet routines in grabbag - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include "FLAC/assert.h" -#include "FLAC/metadata.h" -#include "share/grabbag.h" - -static int do_cuesheet(const char *infilename, uint32_t sample_rate, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset) -{ - FILE *fin, *fout; - const char *error_message, *tmpfilenamebase; - char tmpfilename[4096]; - uint32_t last_line_read; - FLAC__StreamMetadata *cuesheet; - - FLAC__ASSERT(strlen(infilename) + 2 < sizeof(tmpfilename)); - - /* - * pass 1 - */ - if(0 == strcmp(infilename, "-")) { - fin = stdin; - } - else if(0 == (fin = flac_fopen(infilename, "r"))) { - fprintf(stderr, "can't open file %s for reading: %s\n", infilename, strerror(errno)); - return 255; - } - if(0 != (cuesheet = grabbag__cuesheet_parse(fin, &error_message, &last_line_read, sample_rate, is_cdda, lead_out_offset))) { - if(fin != stdin) - fclose(fin); - } - else { - printf("pass1: parse error, line %u: \"%s\"\n", last_line_read, error_message); - if(fin != stdin) - fclose(fin); - return 1; - } - if(!FLAC__metadata_object_cuesheet_is_legal(cuesheet, is_cdda, &error_message)) { - printf("pass1: illegal cuesheet: \"%s\"\n", error_message); - FLAC__metadata_object_delete(cuesheet); - return 1; - } - - tmpfilenamebase = strstr(infilename, "cuesheets/"); - tmpfilenamebase = tmpfilenamebase == NULL ? infilename : tmpfilenamebase; - - flac_snprintf(tmpfilename, sizeof (tmpfilename), "%s.1", tmpfilenamebase); - if(0 == (fout = flac_fopen(tmpfilename, "w"))) { - fprintf(stderr, "can't open file %s for writing: %s\n", tmpfilename, strerror(errno)); - FLAC__metadata_object_delete(cuesheet); - return 255; - } - grabbag__cuesheet_emit(fout, cuesheet, "\"dummy.wav\" WAVE"); - FLAC__metadata_object_delete(cuesheet); - fclose(fout); - - /* - * pass 2 - */ - if(0 == (fin = flac_fopen(tmpfilename, "r"))) { - fprintf(stderr, "can't open file %s for reading: %s\n", tmpfilename, strerror(errno)); - return 255; - } - if(0 != (cuesheet = grabbag__cuesheet_parse(fin, &error_message, &last_line_read, sample_rate, is_cdda, lead_out_offset))) { - if(fin != stdin) - fclose(fin); - } - else { - printf("pass2: parse error, line %u: \"%s\"\n", last_line_read, error_message); - if(fin != stdin) - fclose(fin); - return 1; - } - if(!FLAC__metadata_object_cuesheet_is_legal(cuesheet, is_cdda, &error_message)) { - printf("pass2: illegal cuesheet: \"%s\"\n", error_message); - FLAC__metadata_object_delete(cuesheet); - return 1; - } - flac_snprintf(tmpfilename, sizeof (tmpfilename), "%s.2", tmpfilenamebase); - if(0 == (fout = flac_fopen(tmpfilename, "w"))) { - fprintf(stderr, "can't open file %s for writing: %s\n", tmpfilename, strerror(errno)); - FLAC__metadata_object_delete(cuesheet); - return 255; - } - grabbag__cuesheet_emit(fout, cuesheet, "\"dummy.wav\" WAVE"); - FLAC__metadata_object_delete(cuesheet); - fclose(fout); - - return 0; -} - -int main(int argc, char *argv[]) -{ - FLAC__uint64 lead_out_offset; - uint32_t sample_rate = 48000; - FLAC__bool is_cdda = false; - const char *usage = "usage: test_cuesheet cuesheet_file lead_out_offset [ [ sample_rate ] cdda ]\n"; - - if(argc > 1 && 0 == strcmp(argv[1], "-h")) { - puts(usage); - return 0; - } - - if(argc < 3 || argc > 5) { - fputs(usage, stderr); - return 255; - } - - lead_out_offset = (FLAC__uint64)strtoul(argv[2], 0, 10); - if(argc >= 4) { - sample_rate = (uint32_t)atoi(argv[3]); - if(argc >= 5) { - if(0 == strcmp(argv[4], "cdda")) - is_cdda = true; - else { - fputs(usage, stderr); - return 255; - } - } - } - - return do_cuesheet(argv[1], sample_rate, is_cdda, lead_out_offset); -} diff --git a/flac/src/test_grabbag/picture/CMakeLists.txt b/flac/src/test_grabbag/picture/CMakeLists.txt deleted file mode 100644 index 77f1a38..0000000 --- a/flac/src/test_grabbag/picture/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_executable(test_picture - main.c - $<$:../../../include/share/win_utf8_io.h> - $<$:../../share/win_utf8_io/win_utf8_io.c>) -target_link_libraries(test_picture FLAC grabbag) diff --git a/flac/src/test_grabbag/picture/Makefile.am b/flac/src/test_grabbag/picture/Makefile.am deleted file mode 100644 index 45e1457..0000000 --- a/flac/src/test_grabbag/picture/Makefile.am +++ /dev/null @@ -1,37 +0,0 @@ -# test_picture - Simple tester for picture routines in grabbag -# Copyright (C) 2006-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -EXTRA_DIST = \ - CMakeLists.txt - -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include -check_PROGRAMS = test_picture -test_picture_SOURCES = \ - main.c - -if OS_IS_WINDOWS -win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la -endif - -test_picture_LDADD = \ - $(top_builddir)/src/share/grabbag/libgrabbag.la \ - $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/libFLAC/libFLAC.la \ - $(win_utf8_lib) - -CLEANFILES = test_picture.exe diff --git a/flac/src/test_grabbag/picture/main.c b/flac/src/test_grabbag/picture/main.c deleted file mode 100644 index fe43be9..0000000 --- a/flac/src/test_grabbag/picture/main.c +++ /dev/null @@ -1,222 +0,0 @@ -/* test_picture - Simple tester for picture routines in grabbag - * Copyright (C) 2006-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include "FLAC/assert.h" -#include "share/grabbag.h" - -typedef struct { - const char *path; - const char *mime_type; - const char *description; - FLAC__uint32 width; - FLAC__uint32 height; - FLAC__uint32 depth; - FLAC__uint32 colors; - FLAC__StreamMetadata_Picture_Type type; -} PictureFile; - -PictureFile picturefiles[] = { - { "0.gif", "image/gif" , "", 24, 24, 24, 2, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "1.gif", "image/gif" , "", 12, 8, 24, 256, FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER }, - { "2.gif", "image/gif" , "", 16, 14, 24, 128, FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER }, - { "0.jpg", "image/jpeg", "", 30, 20, 8, 0, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "4.jpg", "image/jpeg", "", 31, 47, 24, 0, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "0.png", "image/png" , "", 30, 20, 8, 0, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "1.png", "image/png" , "", 30, 20, 8, 0, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "2.png", "image/png" , "", 30, 20, 24, 7, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "3.png", "image/png" , "", 30, 20, 24, 7, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "4.png", "image/png" , "", 31, 47, 24, 0, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "5.png", "image/png" , "", 31, 47, 24, 0, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "6.png", "image/png" , "", 31, 47, 24, 23, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "7.png", "image/png" , "", 31, 47, 24, 23, FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER }, - { "8.png", "image/png" , "", 32, 32, 32, 0, 999 } -}; - -static FLAC__bool debug_ = false; - -static FLAC__bool failed_(const char *msg) -{ - if(msg) - printf("FAILED, %s\n", msg); - else - printf("FAILED\n"); - - return false; -} - -static FLAC__bool test_one_picture(const char *prefix, const PictureFile *pf, const PictureResolution * res, FLAC__bool fn_only) -{ - FLAC__StreamMetadata *obj; - const char *error; - char s[4096]; - if(fn_only) - flac_snprintf(s, sizeof(s), "pictures/%s", pf->path); - else if (res == NULL) - flac_snprintf(s, sizeof(s), "%u|%s|%s||pictures/%s", (uint32_t)pf->type, pf->mime_type, pf->description, pf->path); - else - flac_snprintf(s, sizeof(s), "%u|%s|%s|%dx%dx%d/%d|pictures/%s", (uint32_t)pf->type, pf->mime_type, pf->description, res->width, res->height, res->depth, res->colors, pf->path); - - printf("testing grabbag__picture_parse_specification(\"%s\")... ", s); - - flac_snprintf(s, sizeof(s), "%s/%s", prefix, pf->path); - if((obj = grabbag__picture_from_specification(fn_only? FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER : pf->type, pf->mime_type, pf->description, res, s, &error)) == 0) - return failed_(error); - if(debug_) { - printf("\ntype=%u (%s)\nmime_type=%s\ndescription=%s\nwidth=%u\nheight=%u\ndepth=%u\ncolors=%u\ndata_length=%u\n", - obj->data.picture.type, - obj->data.picture.type < FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED? - FLAC__StreamMetadata_Picture_TypeString[obj->data.picture.type] : "UNDEFINED", - obj->data.picture.mime_type, - obj->data.picture.description, - obj->data.picture.width, - obj->data.picture.height, - obj->data.picture.depth, - obj->data.picture.colors, - obj->data.picture.data_length - ); - } - if(obj->data.picture.type != (fn_only? FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER : pf->type)) - return failed_("picture type mismatch"); - if(strcmp(obj->data.picture.mime_type, pf->mime_type)) - return failed_("picture MIME type mismatch"); - if(strcmp((const char *)obj->data.picture.description, (const char *)pf->description)) - return failed_("picture description mismatch"); - if(obj->data.picture.width != pf->width) - return failed_("picture width mismatch"); - if(obj->data.picture.height != pf->height) - return failed_("picture height mismatch"); - if(obj->data.picture.depth != pf->depth) - return failed_("picture depth mismatch"); - if(obj->data.picture.colors != pf->colors) - return failed_("picture colors mismatch"); - printf("OK\n"); - FLAC__metadata_object_delete(obj); - return true; -} - -static FLAC__bool do_picture(const char *prefix) -{ - FLAC__StreamMetadata *obj; - PictureResolution res; - const char *error; - size_t i; - - printf("\n+++ grabbag unit test: picture\n\n"); - - /* invalid spec: no filename */ - printf("testing grabbag__picture_parse_specification(\"\")... "); - if(0 != (obj = grabbag__picture_parse_specification("", &error))) - return failed_("expected error, got object"); - printf("OK (failed as expected, error: %s)\n", error); - - /* invalid spec: no filename */ - printf("testing grabbag__picture_parse_specification(\"||||\")... "); - if(0 != (obj = grabbag__picture_parse_specification("||||", &error))) - return failed_("expected error, got object"); - printf("OK (failed as expected: %s)\n", error); - - /* invalid spec: no filename */ - printf("testing grabbag__picture_parse_specification(\"|image/gif|||\")... "); - if(0 != (obj = grabbag__picture_parse_specification("|image/gif|||", &error))) - return failed_("expected error, got object"); - printf("OK (failed as expected: %s)\n", error); - - /* invalid spec: bad resolution */ - printf("testing grabbag__picture_parse_specification(\"|image/gif|desc|320|0.gif\")... "); - if(0 != (obj = grabbag__picture_parse_specification("|image/gif|desc|320|0.gif", &error))) - return failed_("expected error, got object"); - printf("OK (failed as expected: %s)\n", error); - - /* invalid spec: bad resolution */ - printf("testing grabbag__picture_parse_specification(\"|image/gif|desc|320x240|0.gif\")... "); - if(0 != (obj = grabbag__picture_parse_specification("|image/gif|desc|320x240|0.gif", &error))) - return failed_("expected error, got object"); - printf("OK (failed as expected: %s)\n", error); - - /* invalid spec: no filename */ - printf("testing grabbag__picture_parse_specification(\"|image/gif|desc|320x240x9|\")... "); - if(0 != (obj = grabbag__picture_parse_specification("|image/gif|desc|320x240x9|", &error))) - return failed_("expected error, got object"); - printf("OK (failed as expected: %s)\n", error); - - /* invalid spec: #colors exceeds color depth */ - printf("testing grabbag__picture_parse_specification(\"|image/gif|desc|320x240x9/2345|0.gif\")... "); - if(0 != (obj = grabbag__picture_parse_specification("|image/gif|desc|320x240x9/2345|0.gif", &error))) - return failed_("expected error, got object"); - printf("OK (failed as expected: %s)\n", error); - - /* invalid spec: standard icon has to be 32x32 PNG */ - printf("testing grabbag__picture_parse_specification(\"1|-->|desc|32x24x9|0.gif\")... "); - if(0 != (obj = grabbag__picture_parse_specification("1|-->|desc|32x24x9|0.gif", &error))) - return failed_("expected error, got object"); - printf("OK (failed as expected: %s)\n", error); - - /* invalid spec: need resolution for linked URL */ - printf("testing grabbag__picture_parse_specification(\"|-->|desc||http://blah.blah.blah/z.gif\")... "); - if(0 != (obj = grabbag__picture_parse_specification("|-->|desc||http://blah.blah.blah/z.gif", &error))) - return failed_("expected error, got object"); - printf("OK (failed as expected: %s)\n", error); - - printf("testing grabbag__picture_parse_specification(\"|-->|desc|320x240x9|http://blah.blah.blah/z.gif\")... "); - if(0 == (obj = grabbag__picture_parse_specification("|-->|desc|320x240x9|http://blah.blah.blah/z.gif", &error))) - return failed_(error); - printf("OK\n"); - FLAC__metadata_object_delete(obj); - - /* test automatic parsing of picture files from only the file name */ - for(i = 0; i < sizeof(picturefiles)/sizeof(picturefiles[0]); i++) - if(!test_one_picture(prefix, picturefiles+i, NULL, /*fn_only=*/true)) - return false; - - /* test automatic parsing of picture files to get resolution/color info */ - for(i = 0; i < sizeof(picturefiles)/sizeof(picturefiles[0]); i++) - if(!test_one_picture(prefix, picturefiles+i, NULL, /*fn_only=*/false)) - return false; - - res.width = picturefiles[0].width = 320; - res.height = picturefiles[0].height = 240; - res.depth = picturefiles[0].depth = 3; - res.colors = picturefiles[0].colors = 2; - if(!test_one_picture(prefix, picturefiles+0, &res, /*fn_only=*/false)) - return false; - - return true; -} - -int main(int argc, char *argv[]) -{ - const char *usage = "usage: test_pictures path_prefix\n"; - - if(argc > 1 && 0 == strcmp(argv[1], "-h")) { - puts(usage); - return 0; - } - - if(argc != 2) { - fputs(usage, stderr); - return 255; - } - - return do_picture(argv[1])? 0 : 1; -} diff --git a/flac/src/test_libFLAC++/CMakeLists.txt b/flac/src/test_libFLAC++/CMakeLists.txt deleted file mode 100644 index 2fa7b1e..0000000 --- a/flac/src/test_libFLAC++/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -add_executable(test_libFLAC++ - decoders.cpp - encoders.cpp - main.cpp - metadata.cpp - metadata_manip.cpp - metadata_object.cpp - $<$:../../include/share/win_utf8_io.h> - $<$:../share/win_utf8_io/win_utf8_io.c>) -target_link_libraries(test_libFLAC++ FLAC++ test_libs_common grabbag) diff --git a/flac/src/test_libFLAC++/Makefile.am b/flac/src/test_libFLAC++/Makefile.am deleted file mode 100644 index 8bf746f..0000000 --- a/flac/src/test_libFLAC++/Makefile.am +++ /dev/null @@ -1,50 +0,0 @@ -# test_libFLAC++ - Unit tester for libFLAC++ -# Copyright (C) 2002-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -EXTRA_DIST = \ - CMakeLists.txt - -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include -check_PROGRAMS = test_libFLAC++ - -if OS_IS_WINDOWS -win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la -endif - -test_libFLAC___LDADD = \ - $(top_builddir)/src/share/grabbag/libgrabbag.la \ - $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/test_libs_common/libtest_libs_common.la \ - $(top_builddir)/src/libFLAC++/libFLAC++.la \ - $(top_builddir)/src/libFLAC/libFLAC.la \ - $(win_utf8_lib) \ - @OGG_LIBS@ \ - -lm - -test_libFLAC___SOURCES = \ - decoders.cpp \ - encoders.cpp \ - main.cpp \ - metadata.cpp \ - metadata_manip.cpp \ - metadata_object.cpp \ - decoders.h \ - encoders.h \ - metadata.h - -CLEANFILES = test_libFLAC++.exe diff --git a/flac/src/test_libFLAC++/decoders.cpp b/flac/src/test_libFLAC++/decoders.cpp deleted file mode 100644 index 9f375f3..0000000 --- a/flac/src/test_libFLAC++/decoders.cpp +++ /dev/null @@ -1,1179 +0,0 @@ -/* test_libFLAC++ - Unit tester for libFLAC++ - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include "decoders.h" -#include "FLAC/assert.h" -#include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal() -#include "FLAC++/decoder.h" -#include "share/grabbag.h" -#include "share/compat.h" -extern "C" { -#include "test_libs_common/file_utils_flac.h" -#include "test_libs_common/metadata_utils.h" -} - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -typedef enum { - LAYER_STREAM = 0, /* FLAC__stream_decoder_init_stream() without seeking */ - LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_stream() with seeking */ - LAYER_FILE, /* FLAC__stream_decoder_init_FILE() */ - LAYER_FILENAME /* FLAC__stream_decoder_init_file() */ -} Layer; - -static const char * const LayerString[] = { - "Stream", - "Seekable Stream", - "FILE*", - "Filename" -}; - -static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; -static ::FLAC__StreamMetadata *expected_metadata_sequence_[9]; -static uint32_t num_expected_; -static FLAC__off_t flacfilesize_; - -static const char *flacfilename(bool is_ogg) -{ - return is_ogg? "metadata.oga" : "metadata.flac"; -} - -static bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static FLAC__bool die_s_(const char *msg, const FLAC::Decoder::Stream *decoder) -{ - FLAC::Decoder::Stream::State state = decoder->get_state(); - - if(msg) - printf("FAILED, %s", msg); - else - printf("FAILED"); - - printf(", state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring()); - - return false; -} - -static void init_metadata_blocks_() -{ - mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static void free_metadata_blocks_() -{ - mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static bool generate_file_(FLAC__bool is_ogg) -{ - printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg? "Ogg ":""); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - /* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */ - - if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_)) - return die_("creating the encoded file"); - - return true; -} - - -class DecoderCommon { -public: - Layer layer_; - uint32_t current_metadata_number_; - bool ignore_errors_; - bool error_occurred_; - - DecoderCommon(Layer layer): layer_(layer), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { } - virtual ~DecoderCommon(void) { } - ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame); - void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata); - void common_error_callback_(::FLAC__StreamDecoderErrorStatus status); -}; - -::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame) -{ - if(error_occurred_) - return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - - if( - (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) || - (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0) - ) { - printf("content... "); - fflush(stdout); - } - - return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata) -{ - if(error_occurred_) - return; - - printf("%u... ", current_metadata_number_); - fflush(stdout); - - if(current_metadata_number_ >= num_expected_) { - (void)die_("got more metadata blocks than expected"); - error_occurred_ = true; - } - else { - if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) { - (void)die_("metadata block mismatch"); - error_occurred_ = true; - } - } - current_metadata_number_++; -} - -void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status) -{ - if(!ignore_errors_) { - printf("ERROR: got error callback: err = %u (%s)\n", (uint32_t)status, ::FLAC__StreamDecoderErrorStatusString[status]); - error_occurred_ = true; - } -} - -class StreamDecoder : public FLAC::Decoder::Stream, public DecoderCommon { -public: - FILE *file_; - - StreamDecoder(Layer layer): FLAC::Decoder::Stream(), DecoderCommon(layer), file_(0) { } - ~StreamDecoder() { } - - // from FLAC::Decoder::Stream - ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes); - ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset); - ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset); - ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length); - bool eof_callback(); - ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]); - void metadata_callback(const ::FLAC__StreamMetadata *metadata); - void error_callback(::FLAC__StreamDecoderErrorStatus status); - - bool test_respond(bool is_ogg); -private: - StreamDecoder(const StreamDecoder&); - StreamDecoder&operator=(const StreamDecoder&); -}; - -::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], size_t *bytes) -{ - const size_t requested_bytes = *bytes; - - if(error_occurred_) - return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; - - if(feof(file_)) { - *bytes = 0; - return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - } - else if(requested_bytes > 0) { - *bytes = ::fread(buffer, 1, requested_bytes, file_); - if(*bytes == 0) { - if(feof(file_)) - return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - else - return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - else { - return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - } - else - return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */ -} - -::FLAC__StreamDecoderSeekStatus StreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset) -{ - if(layer_ == LAYER_STREAM) - return ::FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; - - if(error_occurred_) - return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - - if(fseeko(file_, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0) { - error_occurred_ = true; - return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - } - - return ::FLAC__STREAM_DECODER_SEEK_STATUS_OK; -} - -::FLAC__StreamDecoderTellStatus StreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset) -{ - if(layer_ == LAYER_STREAM) - return ::FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED; - - if(error_occurred_) - return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - - FLAC__off_t offset = ftello(file_); - *absolute_byte_offset = (FLAC__uint64)offset; - - if(offset < 0) { - error_occurred_ = true; - return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - } - - return ::FLAC__STREAM_DECODER_TELL_STATUS_OK; -} - -::FLAC__StreamDecoderLengthStatus StreamDecoder::length_callback(FLAC__uint64 *stream_length) -{ - if(layer_ == LAYER_STREAM) - return ::FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; - - if(error_occurred_) - return ::FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - - *stream_length = (FLAC__uint64)flacfilesize_; - return ::FLAC__STREAM_DECODER_LENGTH_STATUS_OK; -} - -bool StreamDecoder::eof_callback() -{ - if(layer_ == LAYER_STREAM) - return false; - - if(error_occurred_) - return true; - - return (bool)feof(file_); -} - -::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) -{ - (void)buffer; - - return common_write_callback_(frame); -} - -void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata) -{ - common_metadata_callback_(metadata); -} - -void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status) -{ - common_error_callback_(status); -} - -bool StreamDecoder::test_respond(bool is_ogg) -{ - ::FLAC__StreamDecoderInitStatus init_status; - - if(!set_md5_checking(true)) { - printf("FAILED at set_md5_checking(), returned false\n"); - return false; - } - - printf("testing init%s()... ", is_ogg? "_ogg":""); - init_status = is_ogg? init_ogg() : init(); - if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, this); - printf("OK\n"); - - current_metadata_number_ = 0; - - if(fseeko(file_, 0, SEEK_SET) < 0) { - printf("FAILED rewinding input, errno = %d\n", errno); - return false; - } - - printf("testing process_until_end_of_stream()... "); - if(!process_until_end_of_stream()) { - State state = get_state(); - printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring()); - return false; - } - printf("OK\n"); - - printf("testing finish()... "); - if(!finish()) { - State state = get_state(); - printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring()); - return false; - } - printf("OK\n"); - - return true; -} - -class FileDecoder : public FLAC::Decoder::File, public DecoderCommon { -public: - FileDecoder(Layer layer): FLAC::Decoder::File(), DecoderCommon(layer) { } - ~FileDecoder() { } - - // from FLAC::Decoder::Stream - ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]); - void metadata_callback(const ::FLAC__StreamMetadata *metadata); - void error_callback(::FLAC__StreamDecoderErrorStatus status); - - bool test_respond(bool is_ogg); -}; - -::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) -{ - (void)buffer; - return common_write_callback_(frame); -} - -void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata) -{ - common_metadata_callback_(metadata); -} - -void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status) -{ - common_error_callback_(status); -} - -bool FileDecoder::test_respond(bool is_ogg) -{ - ::FLAC__StreamDecoderInitStatus init_status; - - if(!set_md5_checking(true)) { - printf("FAILED at set_md5_checking(), returned false\n"); - return false; - } - - switch(layer_) { - case LAYER_FILE: - { - printf("opening %sFLAC file... ", is_ogg? "Ogg ":""); - FILE *file = ::flac_fopen(flacfilename(is_ogg), "rb"); - if(0 == file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - - printf("testing init%s()... ", is_ogg? "_ogg":""); - init_status = is_ogg? init_ogg(file) : init(file); - } - break; - case LAYER_FILENAME: - printf("testing init%s()... ", is_ogg? "_ogg":""); - init_status = is_ogg? init_ogg(flacfilename(is_ogg)) : init(flacfilename(is_ogg)); - break; - default: - die_("internal error 001"); - return false; - } - if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, this); - printf("OK\n"); - - current_metadata_number_ = 0; - - printf("testing process_until_end_of_stream()... "); - if(!process_until_end_of_stream()) { - State state = get_state(); - printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring()); - return false; - } - printf("OK\n"); - - printf("testing finish()... "); - if(!finish()) { - State state = get_state(); - printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring()); - return false; - } - printf("OK\n"); - - return true; -} - - -static FLAC::Decoder::Stream *new_by_layer(Layer layer) -{ - if(layer < LAYER_FILE) - return new StreamDecoder(layer); - else - return new FileDecoder(layer); -} - -static bool test_stream_decoder(Layer layer, bool is_ogg) -{ - FLAC::Decoder::Stream *decoder; - ::FLAC__StreamDecoderInitStatus init_status; - bool expect; - - printf("\n+++ libFLAC++ unit test: FLAC::Decoder::%s (layer: %s, format: %s)\n\n", layer delete - // - printf("allocating decoder instance... "); - decoder = new_by_layer(layer); - if(0 == decoder) { - printf("FAILED, new returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing is_valid()... "); - if(!decoder->is_valid()) { - printf("FAILED, returned false\n"); - delete decoder; - return false; - } - printf("OK\n"); - - printf("freeing decoder instance... "); - delete decoder; - printf("OK\n"); - - // - // test new -> init -> delete - // - printf("allocating decoder instance... "); - decoder = new_by_layer(layer); - if(0 == decoder) { - printf("FAILED, new returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing is_valid()... "); - if(!decoder->is_valid()) { - printf("FAILED, returned false\n"); - delete decoder; - return false; - } - printf("OK\n"); - - printf("testing init%s()... ", is_ogg? "_ogg":""); - switch(layer) { - case LAYER_STREAM: - case LAYER_SEEKABLE_STREAM: - dynamic_cast(decoder)->file_ = stdin; - init_status = is_ogg? decoder->init_ogg() : decoder->init(); - break; - case LAYER_FILE: - init_status = is_ogg? - dynamic_cast(decoder)->init_ogg(stdin) : - dynamic_cast(decoder)->init(stdin); - break; - case LAYER_FILENAME: - init_status = is_ogg? - dynamic_cast(decoder)->init_ogg(flacfilename(is_ogg)) : - dynamic_cast(decoder)->init(flacfilename(is_ogg)); - break; - default: - die_("internal error 006"); - delete decoder; - return false; - } - if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - printf("OK\n"); - - printf("freeing decoder instance... "); - delete decoder; - printf("OK\n"); - - // - // test normal usage - // - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - - printf("allocating decoder instance... "); - decoder = new_by_layer(layer); - if(0 == decoder) { - printf("FAILED, new returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing is_valid()... "); - if(!decoder->is_valid()) { - printf("FAILED, returned false\n"); - delete decoder; - return false; - } - printf("OK\n"); - - if(is_ogg) { - printf("testing set_ogg_serial_number()... "); - if(!decoder->set_ogg_serial_number(file_utils__ogg_serial_number)) - return die_s_("returned false", decoder); - printf("OK\n"); - } - - if(!decoder->set_md5_checking(true)) { - printf("FAILED at set_md5_checking(), returned false\n"); - return false; - } - - switch(layer) { - case LAYER_STREAM: - case LAYER_SEEKABLE_STREAM: - printf("opening %sFLAC file... ", is_ogg? "Ogg ":""); - dynamic_cast(decoder)->file_ = ::flac_fopen(flacfilename(is_ogg), "rb"); - if(0 == dynamic_cast(decoder)->file_) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - - printf("testing init%s()... ", is_ogg? "_ogg":""); - init_status = is_ogg? decoder->init_ogg() : decoder->init(); - break; - case LAYER_FILE: - { - printf("opening FLAC file... "); - FILE *file = ::flac_fopen(flacfilename(is_ogg), "rb"); - if(0 == file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - - printf("testing init%s()... ", is_ogg? "_ogg":""); - init_status = is_ogg? - dynamic_cast(decoder)->init_ogg(file) : - dynamic_cast(decoder)->init(file); - } - break; - case LAYER_FILENAME: - printf("testing init%s()... ", is_ogg? "_ogg":""); - init_status = is_ogg? - dynamic_cast(decoder)->init_ogg(flacfilename(is_ogg)) : - dynamic_cast(decoder)->init(flacfilename(is_ogg)); - break; - default: - die_("internal error 009"); - return false; - } - if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - printf("OK\n"); - - printf("testing get_state()... "); - FLAC::Decoder::Stream::State state = decoder->get_state(); - printf("returned state = %u (%s)... OK\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring()); - - dynamic_cast(decoder)->current_metadata_number_ = 0; - dynamic_cast(decoder)->ignore_errors_ = false; - dynamic_cast(decoder)->error_occurred_ = false; - - printf("testing get_md5_checking()... "); - if(!decoder->get_md5_checking()) { - printf("FAILED, returned false, expected true\n"); - return false; - } - printf("OK\n"); - - printf("testing process_until_end_of_metadata()... "); - if(!decoder->process_until_end_of_metadata()) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing process_single()... "); - if(!decoder->process_single()) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing skip_single_frame()... "); - if(!decoder->skip_single_frame()) - return die_s_("returned false", decoder); - printf("OK\n"); - - if(layer < LAYER_FILE) { - printf("testing flush()... "); - if(!decoder->flush()) - return die_s_("returned false", decoder); - printf("OK\n"); - - dynamic_cast(decoder)->ignore_errors_ = true; - printf("testing process_single()... "); - if(!decoder->process_single()) - return die_s_("returned false", decoder); - printf("OK\n"); - dynamic_cast(decoder)->ignore_errors_ = false; - } - - expect = (layer != LAYER_STREAM); - printf("testing seek_absolute()... "); - if(decoder->seek_absolute(0) != expect) - return die_s_(expect? "returned false" : "returned true", decoder); - printf("OK\n"); - - printf("testing process_until_end_of_stream()... "); - if(!decoder->process_until_end_of_stream()) - return die_s_("returned false", decoder); - printf("OK\n"); - - expect = (layer != LAYER_STREAM); - printf("testing seek_absolute()... "); - if(decoder->seek_absolute(0) != expect) - return die_s_(expect? "returned false" : "returned true", decoder); - printf("OK\n"); - - printf("testing get_channels()... "); - { - uint32_t channels = decoder->get_channels(); - if(channels != streaminfo_.data.stream_info.channels) { - printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels); - return false; - } - } - printf("OK\n"); - - printf("testing get_bits_per_sample()... "); - { - uint32_t bits_per_sample = decoder->get_bits_per_sample(); - if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) { - printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample); - return false; - } - } - printf("OK\n"); - - printf("testing get_sample_rate()... "); - { - uint32_t sample_rate = decoder->get_sample_rate(); - if(sample_rate != streaminfo_.data.stream_info.sample_rate) { - printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate); - return false; - } - } - printf("OK\n"); - - printf("testing get_blocksize()... "); - { - uint32_t blocksize = decoder->get_blocksize(); - /* value could be anything since we're at the last block, so accept any reasonable answer */ - printf("returned %u... %s\n", blocksize, blocksize>0? "OK" : "FAILED"); - if(blocksize == 0) - return false; - } - - printf("testing get_channel_assignment()... "); - { - ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment(); - printf("returned %u (%s)... OK\n", (uint32_t)ca, ::FLAC__ChannelAssignmentString[ca]); - } - - if(layer < LAYER_FILE) { - printf("testing reset()... "); - if(!decoder->reset()) - return die_s_("returned false", decoder); - printf("OK\n"); - - if(layer == LAYER_STREAM) { - /* after a reset() we have to rewind the input ourselves */ - printf("rewinding input... "); - if(fseeko(dynamic_cast(decoder)->file_, 0, SEEK_SET) < 0) { - printf("FAILED, errno = %d\n", errno); - return false; - } - printf("OK\n"); - } - - dynamic_cast(decoder)->current_metadata_number_ = 0; - - printf("testing process_until_end_of_stream()... "); - if(!decoder->process_until_end_of_stream()) - return die_s_("returned false", decoder); - printf("OK\n"); - } - - printf("testing finish()... "); - if(!decoder->finish()) { - state = decoder->get_state(); - printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring()); - return false; - } - printf("OK\n"); - - /* - * respond all - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */ - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - else { - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * ignore all - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * respond all, ignore VORBIS_COMMENT - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore(VORBIS_COMMENT)... "); - if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - if(!is_ogg) /* encoder removes seektable for ogg */ - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * respond all, ignore APPLICATION - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore(APPLICATION)... "); - if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */ - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - else { - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * respond all, ignore APPLICATION id of app#1 - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore_application(of app block #1)... "); - if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */ - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - else { - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * respond all, ignore APPLICATION id of app#1 & app#2 - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore_application(of app block #1)... "); - if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore_application(of app block #2)... "); - if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes seektable */ - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - else { - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * ignore all, respond VORBIS_COMMENT - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond(VORBIS_COMMENT)... "); - if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * ignore all, respond APPLICATION - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond(APPLICATION)... "); - if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * ignore all, respond APPLICATION id of app#1 - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond_application(of app block #1)... "); - if(!decoder->set_metadata_respond_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * ignore all, respond APPLICATION id of app#1 & app#2 - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond_application(of app block #1)... "); - if(!decoder->set_metadata_respond_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond_application(of app block #2)... "); - if(!decoder->set_metadata_respond_application(application2_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * respond all, ignore APPLICATION, respond APPLICATION id of app#1 - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore(APPLICATION)... "); - if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond_application(of app block #1)... "); - if(!decoder->set_metadata_respond_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */ - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - else { - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - /* - * ignore all, respond APPLICATION, ignore APPLICATION id of app#1 - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond(APPLICATION)... "); - if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore_application(of app block #1)... "); - if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!(layer < LAYER_FILE? dynamic_cast(decoder)->test_respond(is_ogg) : dynamic_cast(decoder)->test_respond(is_ogg))) - return false; - - if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */ - ::fclose(dynamic_cast(decoder)->file_); - - printf("freeing decoder instance... "); - delete decoder; - printf("OK\n"); - - printf("\nPASSED!\n"); - - return true; -} - -bool test_decoders() -{ - FLAC__bool is_ogg = false; - - while(1) { - init_metadata_blocks_(); - - if(!generate_file_(is_ogg)) - return false; - - if(!test_stream_decoder(LAYER_STREAM, is_ogg)) - return false; - - if(!test_stream_decoder(LAYER_SEEKABLE_STREAM, is_ogg)) - return false; - - if(!test_stream_decoder(LAYER_FILE, is_ogg)) - return false; - - if(!test_stream_decoder(LAYER_FILENAME, is_ogg)) - return false; - - (void) grabbag__file_remove_file(flacfilename(is_ogg)); - - free_metadata_blocks_(); - - if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg) - break; - is_ogg = true; - } - - return true; -} diff --git a/flac/src/test_libFLAC++/decoders.h b/flac/src/test_libFLAC++/decoders.h deleted file mode 100644 index 4bbce13..0000000 --- a/flac/src/test_libFLAC++/decoders.h +++ /dev/null @@ -1,25 +0,0 @@ -/* test_libFLAC++ - Unit tester for libFLAC++ - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLACPP_DECODERS_H -#define FLAC__TEST_LIBFLACPP_DECODERS_H - -bool test_decoders(); - -#endif diff --git a/flac/src/test_libFLAC++/encoders.cpp b/flac/src/test_libFLAC++/encoders.cpp deleted file mode 100644 index 0e356af..0000000 --- a/flac/src/test_libFLAC++/encoders.cpp +++ /dev/null @@ -1,576 +0,0 @@ -/* test_libFLAC++ - Unit tester for libFLAC++ - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -#include "config.h" -#endif - -#include "encoders.h" -#include "FLAC/assert.h" -#include "FLAC++/encoder.h" -#include "share/grabbag.h" -extern "C" { -#include "test_libs_common/file_utils_flac.h" -#include "test_libs_common/metadata_utils.h" -} -#include -#include -#include -#include -#include "share/compat.h" - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -typedef enum { - LAYER_STREAM = 0, /* FLAC__stream_encoder_init_stream() without seeking */ - LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_stream() with seeking */ - LAYER_FILE, /* FLAC__stream_encoder_init_FILE() */ - LAYER_FILENAME /* FLAC__stream_encoder_init_file() */ -} Layer; - -static const char * const LayerString[] = { - "Stream", - "Seekable Stream", - "FILE*", - "Filename" -}; - -static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; -static ::FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ }; -static const uint32_t num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]); - -static const char *flacfilename(bool is_ogg) -{ - return is_ogg? "metadata.oga" : "metadata.flac"; -} - -static bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static bool die_s_(const char *msg, const FLAC::Encoder::Stream *encoder) -{ - FLAC::Encoder::Stream::State state = encoder->get_state(); - - if(msg) - printf("FAILED, %s", msg); - else - printf("FAILED"); - - printf(", state = %u (%s)\n", (uint32_t)((::FLAC__StreamEncoderState)state), state.as_cstring()); - if(state == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) { - FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state(); - printf(" verify decoder state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring()); - } - - return false; -} - -static void init_metadata_blocks_() -{ - mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static void free_metadata_blocks_() -{ - mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -class StreamEncoder : public FLAC::Encoder::Stream { -public: - Layer layer_; - FILE *file_; - - StreamEncoder(Layer layer): FLAC::Encoder::Stream(), layer_(layer), file_(0) { } - ~StreamEncoder() { } - - // from FLAC::Encoder::Stream - ::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes); - ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame); - ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset); - ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset); - void metadata_callback(const ::FLAC__StreamMetadata *metadata); -private: - StreamEncoder(const StreamEncoder&); - StreamEncoder&operator=(const StreamEncoder&); -}; - -::FLAC__StreamEncoderReadStatus StreamEncoder::read_callback(FLAC__byte buffer[], size_t *bytes) -{ - if(*bytes > 0) { - *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file_); - if(ferror(file_)) - return ::FLAC__STREAM_ENCODER_READ_STATUS_ABORT; - else if(*bytes == 0) - return ::FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM; - else - return ::FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; - } - else - return ::FLAC__STREAM_ENCODER_READ_STATUS_ABORT; -} - -::FLAC__StreamEncoderWriteStatus StreamEncoder::write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame) -{ - (void)samples, (void)current_frame; - - if(fwrite(buffer, 1, bytes, file_) != bytes) - return ::FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - else - return ::FLAC__STREAM_ENCODER_WRITE_STATUS_OK; -} - -::FLAC__StreamEncoderSeekStatus StreamEncoder::seek_callback(FLAC__uint64 absolute_byte_offset) -{ - if(layer_==LAYER_STREAM) - return ::FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED; - else if(fseeko(file_, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0) - return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR; - else - return FLAC__STREAM_ENCODER_SEEK_STATUS_OK; -} - -::FLAC__StreamEncoderTellStatus StreamEncoder::tell_callback(FLAC__uint64 *absolute_byte_offset) -{ - FLAC__off_t pos; - if(layer_==LAYER_STREAM) - return ::FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED; - else if((pos = ftello(file_)) < 0) - return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR; - else { - *absolute_byte_offset = (FLAC__uint64)pos; - return FLAC__STREAM_ENCODER_TELL_STATUS_OK; - } -} - -void StreamEncoder::metadata_callback(const ::FLAC__StreamMetadata *metadata) -{ - (void)metadata; -} - -class FileEncoder : public FLAC::Encoder::File { -public: - Layer layer_; - - FileEncoder(Layer layer): FLAC::Encoder::File(), layer_(layer) { } - ~FileEncoder() { } - - // from FLAC::Encoder::File - void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate); -}; - -void FileEncoder::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate) -{ - (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate; -} - -static FLAC::Encoder::Stream *new_by_layer(Layer layer) -{ - if(layer < LAYER_FILE) - return new StreamEncoder(layer); - else - return new FileEncoder(layer); -} - -static bool test_stream_encoder(Layer layer, bool is_ogg) -{ - FLAC::Encoder::Stream *encoder; - ::FLAC__StreamEncoderInitStatus init_status; - FILE *file = 0; - FLAC__int32 samples[1024]; - FLAC__int32 *samples_array[1] = { samples }; - uint32_t i; - - printf("\n+++ libFLAC++ unit test: FLAC::Encoder::%s (layer: %s, format: %s)\n\n", layeris_valid()) { - printf("FAILED, returned false\n"); - delete encoder; - return false; - } - printf("OK\n"); - - if(is_ogg) { - printf("testing set_ogg_serial_number()... "); - if(!encoder->set_ogg_serial_number(file_utils__ogg_serial_number)) - return die_s_("returned false", encoder); - printf("OK\n"); - } - - printf("testing set_verify()... "); - if(!encoder->set_verify(true)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_streamable_subset()... "); - if(!encoder->set_streamable_subset(true)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_channels()... "); - if(!encoder->set_channels(streaminfo_.data.stream_info.channels)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_bits_per_sample()... "); - if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_sample_rate()... "); - if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_compression_level()... "); - if(!encoder->set_compression_level((uint32_t)(-1))) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_blocksize()... "); - if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_do_mid_side_stereo()... "); - if(!encoder->set_do_mid_side_stereo(false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_loose_mid_side_stereo()... "); - if(!encoder->set_loose_mid_side_stereo(false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_max_lpc_order()... "); - if(!encoder->set_max_lpc_order(0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_qlp_coeff_precision()... "); - if(!encoder->set_qlp_coeff_precision(0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_do_qlp_coeff_prec_search()... "); - if(!encoder->set_do_qlp_coeff_prec_search(false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_do_escape_coding()... "); - if(!encoder->set_do_escape_coding(false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_do_exhaustive_model_search()... "); - if(!encoder->set_do_exhaustive_model_search(false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_min_residual_partition_order()... "); - if(!encoder->set_min_residual_partition_order(0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_max_residual_partition_order()... "); - if(!encoder->set_max_residual_partition_order(0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_rice_parameter_search_dist()... "); - if(!encoder->set_rice_parameter_search_dist(0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_total_samples_estimate()... "); - if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_metadata()... "); - if(!encoder->set_metadata(metadata_sequence_, num_metadata_)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_limit_min_bitrate()... "); - if(!encoder->set_limit_min_bitrate(true)) - return die_s_("returned false", encoder); - printf("OK\n"); - - if(layer < LAYER_FILENAME) { - printf("opening file for FLAC output... "); - file = ::flac_fopen(flacfilename(is_ogg), "w+b"); - if(0 == file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - if(layer < LAYER_FILE) - dynamic_cast(encoder)->file_ = file; - } - - switch(layer) { - case LAYER_STREAM: - case LAYER_SEEKABLE_STREAM: - printf("testing init%s()... ", is_ogg? "_ogg":""); - init_status = is_ogg? encoder->init_ogg() : encoder->init(); - break; - case LAYER_FILE: - printf("testing init%s()... ", is_ogg? "_ogg":""); - init_status = is_ogg? - dynamic_cast(encoder)->init_ogg(file) : - dynamic_cast(encoder)->init(file); - break; - case LAYER_FILENAME: - printf("testing init%s()... ", is_ogg? "_ogg":""); - init_status = is_ogg? - dynamic_cast(encoder)->init_ogg(flacfilename(is_ogg)) : - dynamic_cast(encoder)->init(flacfilename(is_ogg)); - break; - default: - die_("internal error 001"); - return false; - } - if(init_status != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); - printf("OK\n"); - - printf("testing get_state()... "); - FLAC::Encoder::Stream::State state = encoder->get_state(); - printf("returned state = %u (%s)... OK\n", (uint32_t)((::FLAC__StreamEncoderState)state), state.as_cstring()); - - printf("testing get_verify_decoder_state()... "); - FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state(); - printf("returned state = %u (%s)... OK\n", (uint32_t)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring()); - - { - FLAC__uint64 absolute_sample; - uint32_t frame_number; - uint32_t channel; - uint32_t sample; - FLAC__int32 expected; - FLAC__int32 got; - - printf("testing get_verify_decoder_error_stats()... "); - encoder->get_verify_decoder_error_stats(&absolute_sample, &frame_number, &channel, &sample, &expected, &got); - printf("OK\n"); - } - - printf("testing get_verify()... "); - if(encoder->get_verify() != true) { - printf("FAILED, expected true, got false\n"); - return false; - } - printf("OK\n"); - - printf("testing get_streamable_subset()... "); - if(encoder->get_streamable_subset() != true) { - printf("FAILED, expected true, got false\n"); - return false; - } - printf("OK\n"); - - printf("testing get_do_mid_side_stereo()... "); - if(encoder->get_do_mid_side_stereo() != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing get_loose_mid_side_stereo()... "); - if(encoder->get_loose_mid_side_stereo() != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing get_channels()... "); - if(encoder->get_channels() != streaminfo_.data.stream_info.channels) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels()); - return false; - } - printf("OK\n"); - - printf("testing get_bits_per_sample()... "); - if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample()); - return false; - } - printf("OK\n"); - - printf("testing get_sample_rate()... "); - if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate()); - return false; - } - printf("OK\n"); - - printf("testing get_blocksize()... "); - if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize()); - return false; - } - printf("OK\n"); - - printf("testing get_max_lpc_order()... "); - if(encoder->get_max_lpc_order() != 0) { - printf("FAILED, expected %d, got %u\n", 0, encoder->get_max_lpc_order()); - return false; - } - printf("OK\n"); - - printf("testing get_qlp_coeff_precision()... "); - (void)encoder->get_qlp_coeff_precision(); - /* we asked the encoder to auto select this so we accept anything */ - printf("OK\n"); - - printf("testing get_do_qlp_coeff_prec_search()... "); - if(encoder->get_do_qlp_coeff_prec_search() != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing get_do_escape_coding()... "); - if(encoder->get_do_escape_coding() != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing get_do_exhaustive_model_search()... "); - if(encoder->get_do_exhaustive_model_search() != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing get_min_residual_partition_order()... "); - if(encoder->get_min_residual_partition_order() != 0) { - printf("FAILED, expected %d, got %u\n", 0, encoder->get_min_residual_partition_order()); - return false; - } - printf("OK\n"); - - printf("testing get_max_residual_partition_order()... "); - if(encoder->get_max_residual_partition_order() != 0) { - printf("FAILED, expected %d, got %u\n", 0, encoder->get_max_residual_partition_order()); - return false; - } - printf("OK\n"); - - printf("testing get_rice_parameter_search_dist()... "); - if(encoder->get_rice_parameter_search_dist() != 0) { - printf("FAILED, expected %d, got %u\n", 0, encoder->get_rice_parameter_search_dist()); - return false; - } - printf("OK\n"); - - printf("testing get_total_samples_estimate()... "); - if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) { - printf("FAILED, expected %" PRIu64 ", got %" PRIu64 "\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate()); - return false; - } - printf("OK\n"); - - printf("testing get_limit_min_bitrate()... "); - if(encoder->get_limit_min_bitrate() != true) { - printf("FAILED, expected true, got false\n"); - return false; - } - printf("OK\n"); - - /* init the dummy sample buffer */ - for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++) - samples[i] = i & 7; - - printf("testing process()... "); - if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32))) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing process_interleaved()... "); - if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32))) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing finish()... "); - if(!encoder->finish()) { - state = encoder->get_state(); - printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamEncoderState)state), state.as_cstring()); - return false; - } - printf("OK\n"); - - if(layer < LAYER_FILE) - ::fclose(dynamic_cast(encoder)->file_); - - printf("freeing encoder instance... "); - delete encoder; - printf("OK\n"); - - printf("\nPASSED!\n"); - - return true; -} - -bool test_encoders() -{ - FLAC__bool is_ogg = false; - - while(1) { - init_metadata_blocks_(); - - if(!test_stream_encoder(LAYER_STREAM, is_ogg)) - return false; - - if(!test_stream_encoder(LAYER_SEEKABLE_STREAM, is_ogg)) - return false; - - if(!test_stream_encoder(LAYER_FILE, is_ogg)) - return false; - - if(!test_stream_encoder(LAYER_FILENAME, is_ogg)) - return false; - - (void) grabbag__file_remove_file(flacfilename(is_ogg)); - - free_metadata_blocks_(); - - if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg) - break; - is_ogg = true; - } - - return true; -} diff --git a/flac/src/test_libFLAC++/encoders.h b/flac/src/test_libFLAC++/encoders.h deleted file mode 100644 index 9da415c..0000000 --- a/flac/src/test_libFLAC++/encoders.h +++ /dev/null @@ -1,25 +0,0 @@ -/* test_libFLAC++ - Unit tester for libFLAC++ - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLACPP_ENCODERS_H -#define FLAC__TEST_LIBFLACPP_ENCODERS_H - -bool test_encoders(); - -#endif diff --git a/flac/src/test_libFLAC++/main.cpp b/flac/src/test_libFLAC++/main.cpp deleted file mode 100644 index 7183def..0000000 --- a/flac/src/test_libFLAC++/main.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* test_libFLAC++ - Unit tester for libFLAC++ - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -#include "config.h" -#endif - -#include "decoders.h" -#include "encoders.h" -#include "metadata.h" - -int main(int argc, char *argv[]) -{ - (void)argc, (void)argv; - - if(!test_encoders()) - return 1; - - if(!test_decoders()) - return 1; - - if(!test_metadata()) - return 1; - - return 0; -} diff --git a/flac/src/test_libFLAC++/metadata.cpp b/flac/src/test_libFLAC++/metadata.cpp deleted file mode 100644 index a31031b..0000000 --- a/flac/src/test_libFLAC++/metadata.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* test_libFLAC++ - Unit tester for libFLAC++ - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -#include "config.h" -#endif - -#include "metadata.h" -#include - -extern bool test_metadata_object(); -extern bool test_metadata_file_manipulation(); - -bool test_metadata() -{ - if(!test_metadata_object()) - return false; - - if(!test_metadata_file_manipulation()) - return false; - - printf("\nPASSED!\n"); - - return true; -} diff --git a/flac/src/test_libFLAC++/metadata.h b/flac/src/test_libFLAC++/metadata.h deleted file mode 100644 index 8c45bc0..0000000 --- a/flac/src/test_libFLAC++/metadata.h +++ /dev/null @@ -1,25 +0,0 @@ -/* test_libFLAC++ - Unit tester for libFLAC++ - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLACPP_METADATA_H -#define FLAC__TEST_LIBFLACPP_METADATA_H - -bool test_metadata(); - -#endif diff --git a/flac/src/test_libFLAC++/metadata_manip.cpp b/flac/src/test_libFLAC++/metadata_manip.cpp deleted file mode 100644 index 5d395db..0000000 --- a/flac/src/test_libFLAC++/metadata_manip.cpp +++ /dev/null @@ -1,2241 +0,0 @@ -/* test_libFLAC++ - Unit tester for libFLAC++ - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include /* for malloc() */ -#include /* for memcpy()/memset() */ -#include /* some flavors of BSD (like OS X) require this to get time_t */ -#ifdef _MSC_VER -#include -#endif -#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__ -#include /* for chown(), unlink() */ -#endif -#include /* for stat(), maybe chmod() */ -#include "FLAC/assert.h" -#include "FLAC++/decoder.h" -#include "FLAC++/metadata.h" -#include "share/grabbag.h" -#include "share/compat.h" -#include "share/macros.h" -#include "share/safe_str.h" -extern "C" { -#include "test_libs_common/file_utils_flac.h" -} - -/****************************************************************************** - The general strategy of these tests (for interface levels 1 and 2) is - to create a dummy FLAC file with a known set of initial metadata - blocks, then keep a mirror locally of what we expect the metadata to be - after each operation. Then testing becomes a simple matter of running - a FLAC::Decoder::File over the dummy file after each operation, comparing - the decoded metadata to what's in our local copy. If there are any - differences in the metadata, or the actual audio data is corrupted, we - will catch it while decoding. -******************************************************************************/ - -class OurFileDecoder: public FLAC::Decoder::File { -public: - inline OurFileDecoder(bool ignore_metadata): ignore_metadata_(ignore_metadata), error_occurred_(false) { } - - bool ignore_metadata_; - bool error_occurred_; -protected: - ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]); - void metadata_callback(const ::FLAC__StreamMetadata *metadata); - void error_callback(::FLAC__StreamDecoderErrorStatus status); -}; - -struct OurMetadata { - FLAC::Metadata::Prototype *blocks[64]; - uint32_t num_blocks; -}; - -/* our copy of the metadata in flacfilename() */ -static OurMetadata our_metadata_; - -/* the current block number that corresponds to the position of the iterator we are testing */ -static uint32_t mc_our_block_number_ = 0; - -static const char *flacfilename(bool is_ogg) -{ - return is_ogg? "metadata.oga" : "metadata.flac"; -} - -static bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static bool die_c_(const char *msg, FLAC::Metadata::Chain::Status status) -{ - printf("ERROR: %s\n", msg); - printf(" status=%u (%s)\n", (uint32_t)((::FLAC__Metadata_ChainStatus)status), status.as_cstring()); - return false; -} - -static bool die_ss_(const char *msg, FLAC::Metadata::SimpleIterator &iterator) -{ - const FLAC::Metadata::SimpleIterator::Status status = iterator.status(); - printf("ERROR: %s\n", msg); - printf(" status=%u (%s)\n", (uint32_t)((::FLAC__Metadata_SimpleIteratorStatus)status), status.as_cstring()); - return false; -} - -static void *malloc_or_die_(size_t size) -{ - void *x = malloc(size); - if(0 == x) { - fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (uint32_t)size); - exit(1); - } - return x; -} - -static char *strdup_or_die_(const char *s) -{ - char *x = strdup(s); - if(0 == x) { - fprintf(stderr, "ERROR: out of memory copying string \"%s\"\n", s); - exit(1); - } - return x; -} - -/* functions for working with our metadata copy */ - -static bool replace_in_our_metadata_(FLAC::Metadata::Prototype *block, uint32_t position, bool copy) -{ - uint32_t i; - FLAC::Metadata::Prototype *obj = block; - FLAC__ASSERT(position < our_metadata_.num_blocks); - if(copy) { - if(0 == (obj = FLAC::Metadata::clone(block))) - return die_("during FLAC::Metadata::clone()"); - } - delete our_metadata_.blocks[position]; - our_metadata_.blocks[position] = obj; - - /* set the is_last flags */ - for(i = 0; i < our_metadata_.num_blocks - 1; i++) - our_metadata_.blocks[i]->set_is_last(false); - our_metadata_.blocks[i]->set_is_last(true); - - return true; -} - -static bool insert_to_our_metadata_(FLAC::Metadata::Prototype *block, uint32_t position, bool copy) -{ - uint32_t i; - FLAC::Metadata::Prototype *obj = block; - if(copy) { - if(0 == (obj = FLAC::Metadata::clone(block))) - return die_("during FLAC::Metadata::clone()"); - } - if(position > our_metadata_.num_blocks) { - position = our_metadata_.num_blocks; - } - else { - for(i = our_metadata_.num_blocks; i > position; i--) - our_metadata_.blocks[i] = our_metadata_.blocks[i-1]; - } - our_metadata_.blocks[position] = obj; - our_metadata_.num_blocks++; - - /* set the is_last flags */ - for(i = 0; i < our_metadata_.num_blocks - 1; i++) - our_metadata_.blocks[i]->set_is_last(false); - our_metadata_.blocks[i]->set_is_last(true); - - return true; -} - -static void delete_from_our_metadata_(uint32_t position) -{ - uint32_t i; - FLAC__ASSERT(position < our_metadata_.num_blocks); - delete our_metadata_.blocks[position]; - for(i = position; i < our_metadata_.num_blocks - 1; i++) - our_metadata_.blocks[i] = our_metadata_.blocks[i+1]; - our_metadata_.num_blocks--; - - /* set the is_last flags */ - if(our_metadata_.num_blocks > 0) { - for(i = 0; i < our_metadata_.num_blocks - 1; i++) - our_metadata_.blocks[i]->set_is_last(false); - our_metadata_.blocks[i]->set_is_last(true); - } -} - -void add_to_padding_length_(uint32_t indx, int delta) -{ - FLAC::Metadata::Padding *padding = dynamic_cast(our_metadata_.blocks[indx]); - FLAC__ASSERT(0 != padding); - padding->set_length((uint32_t)((int)padding->get_length() + delta)); -} - -/* - * This wad of functions supports filename- and callback-based chain reading/writing. - * Everything up to set_file_stats_() is copied from libFLAC/metadata_iterators.c - */ -bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfilename) -{ - static const char *tempfile_suffix = ".metadata_edit"; - size_t destlen = strlen(filename) + strlen(tempfile_suffix) + 1; - - *tempfilename = (char*)malloc(destlen); - if (*tempfilename == 0) - return false; - flac_snprintf(*tempfilename, destlen, "%s%s", filename, tempfile_suffix); - - *tempfile = flac_fopen(*tempfilename, "wb"); - if (*tempfile == 0) - return false; - - return true; -} - -void cleanup_tempfile_(FILE **tempfile, char **tempfilename) -{ - if (*tempfile != 0) { - (void)fclose(*tempfile); - *tempfile = 0; - } - - if (*tempfilename != 0) { - (void)flac_unlink(*tempfilename); - free(*tempfilename); - *tempfilename = 0; - } -} - -bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != tempfile); - FLAC__ASSERT(0 != tempfilename); - FLAC__ASSERT(0 != *tempfilename); - - if(0 != *tempfile) { - (void)fclose(*tempfile); - *tempfile = 0; - } - -#if defined _MSC_VER || defined __MINGW32__ || defined __EMX__ - /* on some flavors of windows, flac_rename() will fail if the destination already exists */ - if(flac_unlink(filename) < 0) { - cleanup_tempfile_(tempfile, tempfilename); - return false; - } -#endif - - if(0 != flac_rename(*tempfilename, filename)) { - cleanup_tempfile_(tempfile, tempfilename); - return false; - } - - cleanup_tempfile_(tempfile, tempfilename); - - return true; -} - -bool get_file_stats_(const char *filename, struct flac_stat_s *stats) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - return (0 == flac_stat(filename, stats)); -} - -void set_file_stats_(const char *filename, struct flac_stat_s *stats) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) && !defined(_WIN32) - struct timespec srctime[2] = {}; - srctime[0].tv_sec = stats->st_atime; - srctime[1].tv_sec = stats->st_mtime; -#else - struct utimbuf srctime; - srctime.actime = stats->st_atime; - srctime.modtime = stats->st_mtime; -#endif - (void)flac_chmod(filename, stats->st_mode); - (void)flac_utime(filename, &srctime); -#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__ - FLAC_CHECK_RETURN(chown(filename, stats->st_uid, (gid_t)(-1))); - FLAC_CHECK_RETURN(chown(filename, (uid_t)(-1), stats->st_gid)); -#endif -} - -#ifdef FLAC__VALGRIND_TESTING -static size_t chain_write_cb_(const void *ptr, size_t size, size_t nmemb, ::FLAC__IOHandle handle) -{ - FILE *stream = (FILE*)handle; - size_t ret = fwrite(ptr, size, nmemb, stream); - if(!ferror(stream)) - fflush(stream); - return ret; -} -#endif - -static int chain_seek_cb_(::FLAC__IOHandle handle, FLAC__int64 offset, int whence) -{ - FLAC__off_t o = (FLAC__off_t)offset; - FLAC__ASSERT(offset == o); - return fseeko((FILE*)handle, o, whence); -} - -static FLAC__int64 chain_tell_cb_(::FLAC__IOHandle handle) -{ - return ftello((FILE*)handle); -} - -static int chain_eof_cb_(::FLAC__IOHandle handle) -{ - return feof((FILE*)handle); -} - -static bool write_chain_(FLAC::Metadata::Chain &chain, bool use_padding, bool preserve_file_stats, bool filename_based, const char *filename) -{ - if(filename_based) - return chain.write(use_padding, preserve_file_stats); - else { - ::FLAC__IOCallbacks callbacks; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.read = (::FLAC__IOCallback_Read)fread; -#ifdef FLAC__VALGRIND_TESTING - callbacks.write = chain_write_cb_; -#else - callbacks.write = (::FLAC__IOCallback_Write)fwrite; -#endif - callbacks.seek = chain_seek_cb_; - callbacks.eof = chain_eof_cb_; - - if(chain.check_if_tempfile_needed(use_padding)) { - struct flac_stat_s stats; - FILE *file, *tempfile; - char *tempfilename; - if(preserve_file_stats) { - if(!get_file_stats_(filename, &stats)) - return false; - } - if(0 == (file = flac_fopen(filename, "rb"))) - return false; /*@@@@ chain status still says OK though */ - if(!open_tempfile_(filename, &tempfile, &tempfilename)) { - fclose(file); - cleanup_tempfile_(&tempfile, &tempfilename); - return false; /*@@@@ chain status still says OK though */ - } - if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks, (::FLAC__IOHandle)tempfile, callbacks)) { - fclose(file); - fclose(tempfile); - return false; - } - fclose(file); - fclose(tempfile); - file = tempfile = 0; - if(!transport_tempfile_(filename, &tempfile, &tempfilename)) - return false; - if(preserve_file_stats) - set_file_stats_(filename, &stats); - } - else { - FILE *file = flac_fopen(filename, "r+b"); - if(0 == file) - return false; /*@@@@ chain status still says OK though */ - if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks)) { - fclose(file); - return false; - } - fclose(file); - } - } - - return true; -} - -static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool filename_based, bool is_ogg) -{ - if(filename_based) - return chain.read(filename, is_ogg); - else { - ::FLAC__IOCallbacks callbacks; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.read = (::FLAC__IOCallback_Read)fread; - callbacks.seek = chain_seek_cb_; - callbacks.tell = chain_tell_cb_; - - { - bool ret; - FILE *file = flac_fopen(filename, "rb"); - if(0 == file) - return false; /*@@@@ chain status still says OK though */ - ret = chain.read((::FLAC__IOHandle)file, callbacks, is_ogg); - fclose(file); - return ret; - } - } -} - -/* function for comparing our metadata to a FLAC::Metadata::Chain */ - -static bool compare_chain_(FLAC::Metadata::Chain &chain, uint32_t current_position, FLAC::Metadata::Prototype *current_block) -{ - uint32_t i; - FLAC::Metadata::Iterator iterator; - bool next_ok = true; - - printf("\tcomparing chain... "); - fflush(stdout); - - if(!iterator.is_valid()) - return die_("allocating memory for iterator"); - - iterator.init(chain); - - i = 0; - do { - FLAC::Metadata::Prototype *block; - - printf("%u... ", i); - fflush(stdout); - - if(0 == (block = iterator.get_block())) - return die_("getting block from iterator"); - - if(*block != *our_metadata_.blocks[i]) - return die_("metadata block mismatch"); - - delete block; - i++; - next_ok = iterator.next(); - } while(i < our_metadata_.num_blocks && next_ok); - - if(next_ok) - return die_("chain has more blocks than expected"); - - if(i < our_metadata_.num_blocks) - return die_("short block count in chain"); - - if(0 != current_block) { - printf("CURRENT_POSITION... "); - fflush(stdout); - - if(*current_block != *our_metadata_.blocks[current_position]) - return die_("metadata block mismatch"); - } - - printf("PASSED\n"); - - return true; -} - -::FLAC__StreamDecoderWriteStatus OurFileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) -{ - (void)buffer; - - if( - (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) || - (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0) - ) { - printf("content... "); - fflush(stdout); - } - - return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -void OurFileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata) -{ - /* don't bother checking if we've already hit an error */ - if(error_occurred_) - return; - - printf("%u... ", mc_our_block_number_); - fflush(stdout); - - if(!ignore_metadata_) { - if(mc_our_block_number_ >= our_metadata_.num_blocks) { - (void)die_("got more metadata blocks than expected"); - error_occurred_ = true; - } - else { - if(*our_metadata_.blocks[mc_our_block_number_] != metadata) { - (void)die_("metadata block mismatch"); - error_occurred_ = true; - } - } - } - - mc_our_block_number_++; -} - -void OurFileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status) -{ - error_occurred_ = true; - printf("ERROR: got error callback, status = %s (%u)\n", FLAC__StreamDecoderErrorStatusString[status], (uint32_t)status); -} - -static bool generate_file_(bool include_extras, bool is_ogg) -{ - ::FLAC__StreamMetadata streaminfo, vorbiscomment, *cuesheet, picture, padding; - ::FLAC__StreamMetadata *metadata[4]; - uint32_t i = 0, n = 0; - - printf("generating %sFLAC file for test\n", is_ogg? "Ogg " : ""); - - while(our_metadata_.num_blocks > 0) - delete_from_our_metadata_(0); - - streaminfo.is_last = false; - streaminfo.type = ::FLAC__METADATA_TYPE_STREAMINFO; - streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH; - streaminfo.data.stream_info.min_blocksize = 576; - streaminfo.data.stream_info.max_blocksize = 576; - streaminfo.data.stream_info.min_framesize = 0; - streaminfo.data.stream_info.max_framesize = 0; - streaminfo.data.stream_info.sample_rate = 44100; - streaminfo.data.stream_info.channels = 1; - streaminfo.data.stream_info.bits_per_sample = 8; - streaminfo.data.stream_info.total_samples = 0; - memset(streaminfo.data.stream_info.md5sum, 0, 16); - - { - const uint32_t vendor_string_length = (uint32_t)strlen(FLAC__VENDOR_STRING); - vorbiscomment.is_last = false; - vorbiscomment.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT; - vorbiscomment.length = (4 + vendor_string_length) + 4; - vorbiscomment.data.vorbis_comment.vendor_string.length = vendor_string_length; - vorbiscomment.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(vendor_string_length+1); - memcpy(vorbiscomment.data.vorbis_comment.vendor_string.entry, FLAC__VENDOR_STRING, vendor_string_length+1); - vorbiscomment.data.vorbis_comment.num_comments = 0; - vorbiscomment.data.vorbis_comment.comments = 0; - } - - { - if (0 == (cuesheet = ::FLAC__metadata_object_new(::FLAC__METADATA_TYPE_CUESHEET))) - return die_("priming our metadata"); - cuesheet->is_last = false; - safe_strncpy(cuesheet->data.cue_sheet.media_catalog_number, "bogo-MCN", sizeof(cuesheet->data.cue_sheet.media_catalog_number)); - cuesheet->data.cue_sheet.lead_in = 123; - cuesheet->data.cue_sheet.is_cd = false; - if (!FLAC__metadata_object_cuesheet_insert_blank_track(cuesheet, 0)) - return die_("priming our metadata"); - cuesheet->data.cue_sheet.tracks[0].number = 1; - if (!FLAC__metadata_object_cuesheet_track_insert_blank_index(cuesheet, 0, 0)) - return die_("priming our metadata"); - } - - { - picture.is_last = false; - picture.type = ::FLAC__METADATA_TYPE_PICTURE; - picture.length = - ( - FLAC__STREAM_METADATA_PICTURE_TYPE_LEN + - FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* will add the length for the string later */ - FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* will add the length for the string later */ - FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN + - FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN + - FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN + - FLAC__STREAM_METADATA_PICTURE_COLORS_LEN + - FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */ - ) / 8 - ; - picture.data.picture.type = ::FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER; - picture.data.picture.mime_type = strdup_or_die_("image/jpeg"); - picture.length += strlen(picture.data.picture.mime_type); - picture.data.picture.description = (FLAC__byte*)strdup_or_die_("desc"); - picture.length += strlen((const char *)picture.data.picture.description); - picture.data.picture.width = 300; - picture.data.picture.height = 300; - picture.data.picture.depth = 24; - picture.data.picture.colors = 0; - picture.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA"); - picture.data.picture.data_length = strlen((const char *)picture.data.picture.data); - picture.length += picture.data.picture.data_length; - } - - padding.is_last = true; - padding.type = ::FLAC__METADATA_TYPE_PADDING; - padding.length = 1234; - - metadata[n++] = &vorbiscomment; - if(include_extras) { - metadata[n++] = cuesheet; - metadata[n++] = &picture; - } - metadata[n++] = &padding; - - FLAC::Metadata::StreamInfo s(&streaminfo); - FLAC::Metadata::VorbisComment v(&vorbiscomment); - FLAC::Metadata::CueSheet c(cuesheet, /*copy=*/false); - FLAC::Metadata::Picture pi(&picture); - FLAC::Metadata::Padding p(&padding); - if( - !insert_to_our_metadata_(&s, i++, /*copy=*/true) || - !insert_to_our_metadata_(&v, i++, /*copy=*/true) || - (include_extras && !insert_to_our_metadata_(&c, i++, /*copy=*/true)) || - (include_extras && !insert_to_our_metadata_(&pi, i++, /*copy=*/true)) || - !insert_to_our_metadata_(&p, i++, /*copy=*/true) - ) - return die_("priming our metadata"); - - if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), 0, 512 * 1024, &streaminfo, metadata, n)) - return die_("creating the encoded file"); - - free(vorbiscomment.data.vorbis_comment.vendor_string.entry); - free(picture.data.picture.mime_type); - free(picture.data.picture.description); - free(picture.data.picture.data); - - return true; -} - -static bool test_file_(bool is_ogg, bool ignore_metadata) -{ - const char *filename = flacfilename(is_ogg); - OurFileDecoder decoder(ignore_metadata); - - mc_our_block_number_ = 0; - decoder.error_occurred_ = false; - - printf("\ttesting '%s'... ", filename); - fflush(stdout); - - if(!decoder.is_valid()) - return die_("couldn't allocate decoder instance"); - - decoder.set_md5_checking(true); - decoder.set_metadata_respond_all(); - if((is_ogg? decoder.init_ogg(filename) : decoder.init(filename)) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) { - (void)decoder.finish(); - return die_("initializing decoder\n"); - } - if(!decoder.process_until_end_of_stream()) { - (void)decoder.finish(); - return die_("decoding file\n"); - } - - (void)decoder.finish(); - - if(decoder.error_occurred_) - return false; - - if(mc_our_block_number_ != our_metadata_.num_blocks) - return die_("short metadata block count"); - - printf("PASSED\n"); - return true; -} - -static bool change_stats_(const char *filename, bool read_only) -{ - if(!grabbag__file_change_stats(filename, read_only)) - return die_("during grabbag__file_change_stats()"); - - return true; -} - -static bool remove_file_(const char *filename) -{ - while(our_metadata_.num_blocks > 0) - delete_from_our_metadata_(0); - - if(!grabbag__file_remove_file(filename)) - return die_("removing file"); - - return true; -} - -static bool test_level_0_() -{ - FLAC::Metadata::StreamInfo streaminfo; - - printf("\n\n++++++ testing level 0 interface\n"); - - if(!generate_file_(/*include_extras=*/true, /*is_ogg=*/false)) - return false; - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true)) - return false; - - printf("testing FLAC::Metadata::get_streaminfo()... "); - - if(!FLAC::Metadata::get_streaminfo(flacfilename(/*is_ogg=*/false), streaminfo)) - return die_("during FLAC::Metadata::get_streaminfo()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(streaminfo.get_channels() != 1) - return die_("mismatch in streaminfo.get_channels()"); - if(streaminfo.get_bits_per_sample() != 8) - return die_("mismatch in streaminfo.get_bits_per_sample()"); - if(streaminfo.get_sample_rate() != 44100) - return die_("mismatch in streaminfo.get_sample_rate()"); - if(streaminfo.get_min_blocksize() != 576) - return die_("mismatch in streaminfo.get_min_blocksize()"); - if(streaminfo.get_max_blocksize() != 576) - return die_("mismatch in streaminfo.get_max_blocksize()"); - - printf("OK\n"); - - { - printf("testing FLAC::Metadata::get_tags(VorbisComment *&)... "); - - FLAC::Metadata::VorbisComment *tags = 0; - - if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags)) - return die_("during FLAC::Metadata::get_tags()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(tags->get_num_comments() != 0) - return die_("mismatch in tags->get_num_comments()"); - - printf("OK\n"); - - delete tags; - } - - { - printf("testing FLAC::Metadata::get_tags(VorbisComment &)... "); - - FLAC::Metadata::VorbisComment tags; - - if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags)) - return die_("during FLAC::Metadata::get_tags()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(tags.get_num_comments() != 0) - return die_("mismatch in tags.get_num_comments()"); - - printf("OK\n"); - } - - { - printf("testing FLAC::Metadata::get_cuesheet(CueSheet *&)... "); - - FLAC::Metadata::CueSheet *cuesheet = 0; - - if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet)) - return die_("during FLAC::Metadata::get_cuesheet()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(cuesheet->get_lead_in() != 123) - return die_("mismatch in cuesheet->get_lead_in()"); - - printf("OK\n"); - - delete cuesheet; - } - - { - printf("testing FLAC::Metadata::get_cuesheet(CueSheet &)... "); - - FLAC::Metadata::CueSheet cuesheet; - - if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet)) - return die_("during FLAC::Metadata::get_cuesheet()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(cuesheet.get_lead_in() != 123) - return die_("mismatch in cuesheet.get_lead_in()"); - - printf("OK\n"); - } - - { - printf("testing FLAC::Metadata::get_picture(Picture *&)... "); - - FLAC::Metadata::Picture *picture = 0; - - if(!FLAC::Metadata::get_picture(flacfilename(/*is_ogg=*/false), picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(uint32_t)(-1), /*max_height=*/(uint32_t)(-1), /*max_depth=*/(uint32_t)(-1), /*max_colors=*/(uint32_t)(-1))) - return die_("during FLAC::Metadata::get_picture()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(picture->get_type () != ::FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER) - return die_("mismatch in picture->get_type ()"); - - printf("OK\n"); - - delete picture; - } - - { - printf("testing FLAC::Metadata::get_picture(Picture &)... "); - - FLAC::Metadata::Picture picture; - - if(!FLAC::Metadata::get_picture(flacfilename(/*is_ogg=*/false), picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(uint32_t)(-1), /*max_height=*/(uint32_t)(-1), /*max_depth=*/(uint32_t)(-1), /*max_colors=*/(uint32_t)(-1))) - return die_("during FLAC::Metadata::get_picture()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(picture.get_type () != ::FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER) - return die_("mismatch in picture->get_type ()"); - - printf("OK\n"); - } - - if(!remove_file_(flacfilename(/*is_ogg=*/false))) - return false; - - return true; -} - -static bool test_level_1_() -{ - FLAC::Metadata::Prototype *block; - FLAC::Metadata::StreamInfo *streaminfo; - FLAC::Metadata::Padding *padding; - FLAC::Metadata::Application *app; - FLAC__byte data[1000]; - uint32_t our_current_position = 0; - - // initialize 'data' to avoid Valgrind errors - memset(data, 0, sizeof(data)); - - printf("\n\n++++++ testing level 1 interface\n"); - - /************************************************************/ - { - printf("simple iterator on read-only file\n"); - - if(!generate_file_(/*include_extras=*/false, /*is_ogg=*/false)) - return false; - - if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read_only=*/true)) - return false; - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true)) - return false; - - FLAC::Metadata::SimpleIterator iterator; - - if(!iterator.is_valid()) - return die_("iterator.is_valid() returned false"); - - if(!iterator.init(flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false)) - return die_("iterator.init() returned false"); - - printf("is writable = %u\n", (uint32_t)iterator.is_writable()); - if(iterator.is_writable()) - return die_("iterator claims file is writable when tester thinks it should not be; are you running as root?\n"); - - printf("iterate forwards\n"); - - if(iterator.get_block_type() != ::FLAC__METADATA_TYPE_STREAMINFO) - return die_("expected STREAMINFO type from iterator.get_block_type()"); - if(0 == (block = iterator.get_block())) - return die_("getting block 0"); - if(block->get_type() != ::FLAC__METADATA_TYPE_STREAMINFO) - return die_("expected STREAMINFO type"); - if(block->get_is_last()) - return die_("expected is_last to be false"); - if(block->get_length() != FLAC__STREAM_METADATA_STREAMINFO_LENGTH) - return die_("bad STREAMINFO length"); - /* check to see if some basic data matches (c.f. generate_file_()) */ - streaminfo = dynamic_cast(block); - FLAC__ASSERT(0 != streaminfo); - if(streaminfo->get_channels() != 1) - return die_("mismatch in channels"); - if(streaminfo->get_bits_per_sample() != 8) - return die_("mismatch in bits_per_sample"); - if(streaminfo->get_sample_rate() != 44100) - return die_("mismatch in sample_rate"); - if(streaminfo->get_min_blocksize() != 576) - return die_("mismatch in min_blocksize"); - if(streaminfo->get_max_blocksize() != 576) - return die_("mismatch in max_blocksize"); - // we will delete streaminfo a little later when we're really done with it... - - if(!iterator.next()) - return die_("forward iterator ended early"); - our_current_position++; - - if(!iterator.next()) - return die_("forward iterator ended early"); - our_current_position++; - - if(iterator.get_block_type() != ::FLAC__METADATA_TYPE_PADDING) - return die_("expected PADDING type from iterator.get_block_type()"); - if(0 == (block = iterator.get_block())) - return die_("getting block 1"); - if(block->get_type() != ::FLAC__METADATA_TYPE_PADDING) - return die_("expected PADDING type"); - if(!block->get_is_last()) - return die_("expected is_last to be true"); - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(block->get_length() != 1234) - return die_("bad PADDING length"); - delete block; - - if(iterator.next()) - return die_("forward iterator returned true but should have returned false"); - - printf("iterate backwards\n"); - if(!iterator.prev()) - return die_("reverse iterator ended early"); - if(!iterator.prev()) - return die_("reverse iterator ended early"); - if(iterator.prev()) - return die_("reverse iterator returned true but should have returned false"); - - printf("testing iterator.set_block() on read-only file...\n"); - - if(!iterator.set_block(streaminfo, false)) - printf("PASSED. iterator.set_block() returned false like it should\n"); - else - return die_("iterator.set_block() returned true but shouldn't have"); - delete streaminfo; - } - - /************************************************************/ - { - printf("simple iterator on writable file\n"); - - if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read-only=*/false)) - return false; - - printf("creating APPLICATION block\n"); - - if(0 == (app = new FLAC::Metadata::Application())) - return die_("new FLAC::Metadata::Application()"); - app->set_id((const uint8_t *)"duh"); - - printf("creating PADDING block\n"); - - if(0 == (padding = new FLAC::Metadata::Padding())) { - delete app; - return die_("new FLAC::Metadata::Padding()"); - } - padding->set_length(20); - - FLAC::Metadata::SimpleIterator iterator; - - if(!iterator.is_valid()) { - delete app; - delete padding; - return die_("iterator.is_valid() returned false"); - } - - if(!iterator.init(flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false)) { - delete app; - delete padding; - return die_("iterator.init() returned false"); - } - our_current_position = 0; - - printf("is writable = %u\n", (uint32_t)iterator.is_writable()); - - printf("[S]VP\ttry to write over STREAMINFO block...\n"); - if(!iterator.set_block(app, false)) - printf("\titerator.set_block() returned false like it should\n"); - else { - delete app; - delete padding; - return die_("iterator.set_block() returned true but shouldn't have"); - } - - if(iterator.status() != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT) - return die_("iterator.status() should have been FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT"); - - printf("[S]VP\tnext\n"); - if(!iterator.next()) { - delete app; - delete padding; - return die_("iterator ended early\n"); - } - our_current_position++; - - printf("S[V]P\tnext\n"); - if(!iterator.next()) { - delete app; - delete padding; - return die_("iterator ended early\n"); - } - our_current_position++; - - printf("SV[P]\tinsert PADDING after, don't expand into padding\n"); - padding->set_length(25); - if(!iterator.insert_block_after(padding, false)) - return die_ss_("iterator.insert_block_after(padding, false)", iterator); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return false; - - printf("SVP[P]\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SV[P]P\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("S[V]PP\tinsert PADDING after, don't expand into padding\n"); - padding->set_length(30); - if(!iterator.insert_block_after(padding, false)) - return die_ss_("iterator.insert_block_after(padding, false)", iterator); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return false; - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[P]PP\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("S[V]PPP\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("[S]VPPP\tdelete (STREAMINFO block), must fail\n"); - if(iterator.delete_block(false)) - return die_ss_("iterator.delete_block(false) should have returned false", iterator); - - if(iterator.status() != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT) - return die_("iterator.status() should have been FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT"); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("[S]VPPP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]PPP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]PP\tdelete (middle block), replace with padding\n"); - if(!iterator.delete_block(true)) - return die_ss_("iterator.delete_block(true)", iterator); - our_current_position--; - - printf("S[V]PPP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]PP\tdelete (middle block), don't replace with padding\n"); - if(!iterator.delete_block(false)) - return die_ss_("iterator.delete_block(false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("S[V]PP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]P\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVP[P]\tdelete (last block), replace with padding\n"); - if(!iterator.delete_block(true)) - return die_ss_("iterator.delete_block(false)", iterator); - our_current_position--; - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[P]P\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVP[P]\tdelete (last block), don't replace with padding\n"); - if(!iterator.delete_block(false)) - return die_ss_("iterator.delete_block(false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[P]\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("S[V]P\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("[S]VP\tset STREAMINFO (change sample rate)\n"); - FLAC__ASSERT(our_current_position == 0); - block = iterator.get_block(); - streaminfo = dynamic_cast(block); - FLAC__ASSERT(0 != streaminfo); - streaminfo->set_sample_rate(32000); - if(!replace_in_our_metadata_(block, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(block, false)) - return die_ss_("iterator.set_block(block, false)", iterator); - delete block; - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("[S]VP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]P\tinsert APPLICATION after, expand into padding of exceeding size\n"); - app->set_id((const uint8_t *)"euh"); /* twiddle the id so that our comparison doesn't miss transposition */ - if(!iterator.insert_block_after(app, true)) - return die_ss_("iterator.insert_block_after(app, true)", iterator); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return false; - add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length())); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]P\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVA[P]\tset APPLICATION, expand into padding of exceeding size\n"); - app->set_id((const uint8_t *)"fuh"); /* twiddle the id */ - if(!iterator.set_block(app, true)) - return die_ss_("iterator.set_block(app, true)", iterator); - if(!insert_to_our_metadata_(app, our_current_position, /*copy=*/true)) - return false; - add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length())); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVA[A]P\tset APPLICATION (grow), don't expand into padding\n"); - app->set_id((const uint8_t *)"guh"); /* twiddle the id */ - if(!app->set_data(data, sizeof(data), true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app, false)) - return die_ss_("iterator.set_block(app, false)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVA[A]P\tset APPLICATION (shrink), don't fill in with padding\n"); - app->set_id((const uint8_t *)"huh"); /* twiddle the id */ - if(!app->set_data(data, 12, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app, false)) - return die_ss_("iterator.set_block(app, false)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVA[A]P\tset APPLICATION (grow), expand into padding of exceeding size\n"); - app->set_id((const uint8_t *)"iuh"); /* twiddle the id */ - if(!app->set_data(data, sizeof(data), true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - add_to_padding_length_(our_current_position+1, -((int)sizeof(data) - 12)); - if(!iterator.set_block(app, true)) - return die_ss_("iterator.set_block(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVA[A]P\tset APPLICATION (shrink), fill in with padding\n"); - app->set_id((const uint8_t *)"juh"); /* twiddle the id */ - if(!app->set_data(data, 23, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!insert_to_our_metadata_(padding, our_current_position+1, /*copy=*/true)) - return die_("copying object"); - dynamic_cast(our_metadata_.blocks[our_current_position+1])->set_length(sizeof(data) - 23 - FLAC__STREAM_METADATA_HEADER_LENGTH); - if(!iterator.set_block(app, true)) - return die_ss_("iterator.set_block(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVA[A]PP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVAA[P]P\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVAAP[P]\tset PADDING (shrink), don't fill in with padding\n"); - padding->set_length(5); - if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(padding, false)) - return die_ss_("iterator.set_block(padding, false)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVAAP[P]\tset APPLICATION (grow)\n"); - app->set_id((const uint8_t *)"kuh"); /* twiddle the id */ - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app, false)) - return die_ss_("iterator.set_block(app, false)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVAAP[A]\tset PADDING (equal)\n"); - padding->set_length(27); - if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(padding, false)) - return die_ss_("iterator.set_block(padding, false)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVAAP[P]\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SVAA[P]P\tdelete (middle block), don't replace with padding\n"); - if(!iterator.delete_block(false)) - return die_ss_("iterator.delete_block(false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVA[A]P\tdelete (middle block), don't replace with padding\n"); - if(!iterator.delete_block(false)) - return die_ss_("iterator.delete_block(false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]P\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVA[P]\tinsert PADDING after\n"); - padding->set_length(5); - if(!iterator.insert_block_after(padding, false)) - return die_ss_("iterator.insert_block_after(padding, false)", iterator); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return false; - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVAP[P]\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SVA[P]P\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is too small\n"); - if(!app->set_data(data, 32, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app, true)) - return die_ss_("iterator.set_block(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is 'close' but still too small\n"); - if(!app->set_data(data, 60, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app, true)) - return die_ss_("iterator.set_block(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]PP\tset APPLICATION (grow), expand into padding which will leave 0-length pad\n"); - if(!app->set_data(data, 87, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - dynamic_cast(our_metadata_.blocks[our_current_position+1])->set_length(0); - if(!iterator.set_block(app, true)) - return die_ss_("iterator.set_block(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]PP\tset APPLICATION (grow), expand into padding which is exactly consumed\n"); - if(!app->set_data(data, 91, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - delete_from_our_metadata_(our_current_position+1); - if(!iterator.set_block(app, true)) - return die_ss_("iterator.set_block(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]P\tset APPLICATION (grow), expand into padding which is exactly consumed\n"); - if(!app->set_data(data, 100, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - delete_from_our_metadata_(our_current_position+1); - our_metadata_.blocks[our_current_position]->set_is_last(true); - if(!iterator.set_block(app, true)) - return die_ss_("iterator.set_block(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]\tset PADDING (equal size)\n"); - padding->set_length(app->get_length()); - if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(padding, true)) - return die_ss_("iterator.set_block(padding, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[P]\tinsert PADDING after\n"); - if(!iterator.insert_block_after(padding, false)) - return die_ss_("iterator.insert_block_after(padding, false)", iterator); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return false; - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVP[P]\tinsert PADDING after\n"); - padding->set_length(5); - if(!iterator.insert_block_after(padding, false)) - return die_ss_("iterator.insert_block_after(padding, false)", iterator); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return false; - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SVPP[P]\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SVP[P]P\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SV[P]PP\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is too small\n"); - if(!app->set_data(data, 101, true)) - return die_("setting APPLICATION data"); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.insert_block_after(app, true)) - return die_ss_("iterator.insert_block_after(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n"); - if(!iterator.delete_block(false)) - return die_ss_("iterator.delete_block(false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is 'close' but still too small\n"); - if(!app->set_data(data, 97, true)) - return die_("setting APPLICATION data"); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.insert_block_after(app, true)) - return die_ss_("iterator.insert_block_after(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n"); - if(!iterator.delete_block(false)) - return die_ss_("iterator.delete_block(false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("S[V]PPP\tinsert APPLICATION after, expand into padding which is exactly consumed\n"); - if(!app->set_data(data, 100, true)) - return die_("setting APPLICATION data"); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return die_("copying object"); - delete_from_our_metadata_(our_current_position+1); - if(!iterator.insert_block_after(app, true)) - return die_ss_("iterator.insert_block_after(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]PP\tdelete (middle block), don't replace with padding\n"); - if(!iterator.delete_block(false)) - return die_ss_("iterator.delete_block(false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("S[V]PP\tinsert APPLICATION after, expand into padding which will leave 0-length pad\n"); - if(!app->set_data(data, 96, true)) - return die_("setting APPLICATION data"); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return die_("copying object"); - dynamic_cast(our_metadata_.blocks[our_current_position+1])->set_length(0); - if(!iterator.insert_block_after(app, true)) - return die_ss_("iterator.insert_block_after(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]PP\tdelete (middle block), don't replace with padding\n"); - if(!iterator.delete_block(false)) - return die_ss_("iterator.delete_block(false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("S[V]PP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]P\tdelete (middle block), don't replace with padding\n"); - if(!iterator.delete_block(false)) - return die_ss_("iterator.delete_block(false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - - printf("S[V]P\tinsert APPLICATION after, expand into padding which is exactly consumed\n"); - if(!app->set_data(data, 1, true)) - return die_("setting APPLICATION data"); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return die_("copying object"); - delete_from_our_metadata_(our_current_position+1); - if(!iterator.insert_block_after(app, true)) - return die_ss_("iterator.insert_block_after(app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false)) - return false; - } - - delete app; - delete padding; - - if(!remove_file_(flacfilename(/*is_ogg=*/false))) - return false; - - return true; -} - -static bool test_level_2_(bool filename_based, bool is_ogg) -{ - FLAC::Metadata::Prototype *block; - FLAC::Metadata::StreamInfo *streaminfo; - FLAC::Metadata::Application *app; - FLAC::Metadata::Padding *padding; - FLAC__byte data[2000]; - uint32_t our_current_position; - - // initialize 'data' to avoid Valgrind errors - memset(data, 0, sizeof(data)); - - printf("\n\n++++++ testing level 2 interface (%s-based, %s FLAC)\n", filename_based? "filename":"callback", is_ogg? "Ogg":"native"); - - printf("generate read-only file\n"); - - if(!generate_file_(/*include_extras=*/false, is_ogg)) - return false; - - if(!change_stats_(flacfilename(is_ogg), /*read_only=*/true)) - return false; - - printf("create chain\n"); - FLAC::Metadata::Chain chain; - if(!chain.is_valid()) - return die_("allocating memory for chain"); - - printf("read chain\n"); - - if(!read_chain_(chain, flacfilename(is_ogg), filename_based, is_ogg)) - return die_c_("reading chain", chain.status()); - - printf("[S]VP\ttest initial metadata\n"); - - if(!compare_chain_(chain, 0, 0)) - return false; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - if(is_ogg) - goto end; - - printf("switch file to read-write\n"); - - if(!change_stats_(flacfilename(is_ogg), /*read-only=*/false)) - return false; - - printf("create iterator\n"); - { - FLAC::Metadata::Iterator iterator; - if(!iterator.is_valid()) - return die_("allocating memory for iterator"); - - our_current_position = 0; - - iterator.init(chain); - - if(0 == (block = iterator.get_block())) - return die_("getting block from iterator"); - - FLAC__ASSERT(block->get_type() == FLAC__METADATA_TYPE_STREAMINFO); - - printf("[S]VP\tmodify STREAMINFO, write\n"); - - streaminfo = dynamic_cast(block); - FLAC__ASSERT(0 != streaminfo); - streaminfo->set_sample_rate(32000); - if(!replace_in_our_metadata_(block, our_current_position, /*copy=*/true)) - return die_("copying object"); - delete block; - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/true, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(false, true)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("[S]VP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]P\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]\treplace PADDING with identical-size APPLICATION\n"); - if(0 == (block = iterator.get_block())) - return die_("getting block from iterator"); - if(0 == (app = new FLAC::Metadata::Application())) - return die_("new FLAC::Metadata::Application()"); - app->set_id((const uint8_t *)"duh"); - if(!app->set_data(data, block->get_length()-(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), true)) - return die_("setting APPLICATION data"); - delete block; - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app)) - return die_c_("iterator.set_block(app)", chain.status()); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(false, false)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]\tshrink APPLICATION, don't use padding\n"); - if(0 == (app = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("copying object"); - if(!app->set_data(data, 26, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app)) - return die_c_("iterator.set_block(app)", chain.status()); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(false, false)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]\tgrow APPLICATION, don't use padding\n"); - if(0 == (app = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("copying object"); - if(!app->set_data(data, 28, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app)) - return die_c_("iterator.set_block(app)", chain.status()); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(false, false)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]\tgrow APPLICATION, use padding, but last block is not padding\n"); - if(0 == (app = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("copying object"); - if(!app->set_data(data, 36, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app)) - return die_c_("iterator.set_block(app)", chain.status()); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(false, false)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, but delta is too small for new PADDING block\n"); - if(0 == (app = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("copying object"); - if(!app->set_data(data, 33, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app)) - return die_c_("iterator.set_block(app)", chain.status()); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(true, false)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, delta is enough for new PADDING block\n"); - if(0 == (padding = new FLAC::Metadata::Padding())) - return die_("creating PADDING block"); - if(0 == (app = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("copying object"); - if(!app->set_data(data, 29, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - padding->set_length(0); - if(!insert_to_our_metadata_(padding, our_current_position+1, /*copy=*/false)) - return die_("internal error"); - if(!iterator.set_block(app)) - return die_c_("iterator.set_block(app)", chain.status()); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(true, false)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]P\tshrink APPLICATION, use padding, last block is padding\n"); - if(0 == (app = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("copying object"); - if(!app->set_data(data, 16, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - dynamic_cast(our_metadata_.blocks[our_current_position+1])->set_length(13); - if(!iterator.set_block(app)) - return die_c_("iterator.set_block(app)", chain.status()); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(true, false)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding, but delta is too small\n"); - if(0 == (app = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("copying object"); - if(!app->set_data(data, 50, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!iterator.set_block(app)) - return die_c_("iterator.set_block(app)", chain.status()); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(true, false)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exceeding size\n"); - if(0 == (app = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("copying object"); - if(!app->set_data(data, 56, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - add_to_padding_length_(our_current_position+1, -(56 - 50)); - if(!iterator.set_block(app)) - return die_c_("iterator.set_block(app)", chain.status()); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(true, false)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exact size\n"); - if(0 == (app = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("copying object"); - if(!app->set_data(data, 67, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - delete_from_our_metadata_(our_current_position+1); - if(!iterator.set_block(app)) - return die_c_("iterator.set_block(app)", chain.status()); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(true, false)", chain.status()); - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV[A]\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("S[V]A\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("[S]VA\tinsert PADDING before STREAMINFO (should fail)\n"); - if(0 == (padding = new FLAC::Metadata::Padding())) - return die_("creating PADDING block"); - padding->set_length(30); - if(!iterator.insert_block_before(padding)) - printf("\titerator.insert_block_before() returned false like it should\n"); - else - return die_("iterator.insert_block_before() should have returned false"); - - printf("[S]VA\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]A\tinsert PADDING after\n"); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return die_("copying metadata"); - if(!iterator.insert_block_after(padding)) - return die_("iterator.insert_block_after(padding)"); - - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - - printf("SV[P]A\tinsert PADDING before\n"); - if(0 == (padding = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("creating PADDING block"); - padding->set_length(17); - if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying metadata"); - if(!iterator.insert_block_before(padding)) - return die_("iterator.insert_block_before(padding)"); - - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - - printf("SV[P]PA\tinsert PADDING before\n"); - if(0 == (padding = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position])))) - return die_("creating PADDING block"); - padding->set_length(0); - if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying metadata"); - if(!iterator.insert_block_before(padding)) - return die_("iterator.insert_block_before(padding)"); - - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - - printf("SV[P]PPA\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVP[P]PA\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVPP[P]A\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVPPP[A]\tinsert PADDING after\n"); - if(0 == (padding = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[2])))) - return die_("creating PADDING block"); - padding->set_length(57); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return die_("copying metadata"); - if(!iterator.insert_block_after(padding)) - return die_("iterator.insert_block_after(padding)"); - - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - - printf("SVPPPA[P]\tinsert PADDING before\n"); - if(0 == (padding = dynamic_cast(FLAC::Metadata::clone(our_metadata_.blocks[2])))) - return die_("creating PADDING block"); - padding->set_length(99); - if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying metadata"); - if(!iterator.insert_block_before(padding)) - return die_("iterator.insert_block_before(padding)"); - - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - - } - our_current_position = 0; - - printf("SVPPPAPP\tmerge padding\n"); - chain.merge_padding(); - add_to_padding_length_(2, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[3]->get_length()); - add_to_padding_length_(2, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[4]->get_length()); - add_to_padding_length_(6, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[7]->get_length()); - delete_from_our_metadata_(7); - delete_from_our_metadata_(4); - delete_from_our_metadata_(3); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(true, false)", chain.status()); - if(!compare_chain_(chain, 0, 0)) - return false; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SVPAP\tsort padding\n"); - chain.sort_padding(); - add_to_padding_length_(4, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[2]->get_length()); - delete_from_our_metadata_(2); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(true, false)", chain.status()); - if(!compare_chain_(chain, 0, 0)) - return false; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("create iterator\n"); - { - FLAC::Metadata::Iterator iterator; - if(!iterator.is_valid()) - return die_("allocating memory for iterator"); - - our_current_position = 0; - - iterator.init(chain); - - printf("[S]VAP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]AP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[A]P\tdelete middle block, replace with padding\n"); - if(0 == (padding = new FLAC::Metadata::Padding())) - return die_("creating PADDING block"); - padding->set_length(71); - if(!replace_in_our_metadata_(padding, our_current_position--, /*copy=*/false)) - return die_("copying object"); - if(!iterator.delete_block(/*replace_with_padding=*/true)) - return die_c_("iterator.delete_block(true)", chain.status()); - - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - - printf("S[V]PP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]P\tdelete middle block, don't replace with padding\n"); - delete_from_our_metadata_(our_current_position--); - if(!iterator.delete_block(/*replace_with_padding=*/false)) - return die_c_("iterator.delete_block(false)", chain.status()); - - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - - printf("S[V]P\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]\tdelete last block, replace with padding\n"); - if(0 == (padding = new FLAC::Metadata::Padding())) - return die_("creating PADDING block"); - padding->set_length(219); - if(!replace_in_our_metadata_(padding, our_current_position--, /*copy=*/false)) - return die_("copying object"); - if(!iterator.delete_block(/*replace_with_padding=*/true)) - return die_c_("iterator.delete_block(true)", chain.status()); - - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - - printf("S[V]P\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]\tdelete last block, don't replace with padding\n"); - delete_from_our_metadata_(our_current_position--); - if(!iterator.delete_block(/*replace_with_padding=*/false)) - return die_c_("iterator.delete_block(false)", chain.status()); - - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - - printf("S[V]\tprev\n"); - if(!iterator.prev()) - return die_("iterator ended early\n"); - our_current_position--; - - printf("[S]V\tdelete STREAMINFO block, should fail\n"); - if(iterator.delete_block(/*replace_with_padding=*/false)) - return die_("iterator.delete_block() on STREAMINFO should have failed but didn't"); - - block = iterator.get_block(); - if(!compare_chain_(chain, our_current_position, block)) - return false; - delete block; - - } // delete iterator - our_current_position = 0; - - printf("SV\tmerge padding\n"); - chain.merge_padding(); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(false, false)", chain.status()); - if(!compare_chain_(chain, 0, 0)) - return false; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - - printf("SV\tsort padding\n"); - chain.sort_padding(); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during chain.write(false, false)", chain.status()); - if(!compare_chain_(chain, 0, 0)) - return false; - if(!test_file_(is_ogg, /*ignore_metadata=*/false)) - return false; - -end: - if(!remove_file_(flacfilename(is_ogg))) - return false; - - return true; -} - -static bool test_level_2_misc_(bool is_ogg) -{ - ::FLAC__IOCallbacks callbacks; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.read = (::FLAC__IOCallback_Read)fread; -#ifdef FLAC__VALGRIND_TESTING - callbacks.write = chain_write_cb_; -#else - callbacks.write = (::FLAC__IOCallback_Write)fwrite; -#endif - callbacks.seek = chain_seek_cb_; - callbacks.tell = chain_tell_cb_; - callbacks.eof = chain_eof_cb_; - - printf("\n\n++++++ testing level 2 interface (mismatched read/write protections)\n"); - - printf("generate file\n"); - - if(!generate_file_(/*include_extras=*/false, is_ogg)) - return false; - - printf("create chain\n"); - FLAC::Metadata::Chain chain; - if(!chain.is_valid()) - return die_("allocating chain"); - - printf("read chain (filename-based)\n"); - - if(!chain.read(flacfilename(is_ogg))) - return die_c_("reading chain", chain.status()); - - printf("write chain with wrong method Chain::write(with callbacks)\n"); - { - if(chain.write(/*use_padding=*/false, 0, callbacks)) - return die_c_("mismatched write should have failed", chain.status()); - if(chain.status() != ::FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH) - return die_c_("expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", chain.status()); - printf(" OK: Chain::write(with callbacks) returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should\n"); - } - - printf("read chain (filename-based)\n"); - - if(!chain.read(flacfilename(is_ogg))) - return die_c_("reading chain", chain.status()); - - printf("write chain with wrong method Chain::write(with callbacks and tempfile)\n"); - { - if(chain.write(/*use_padding=*/false, 0, callbacks, 0, callbacks)) - return die_c_("mismatched write should have failed", chain.status()); - if(chain.status() != ::FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH) - return die_c_("expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", chain.status()); - printf(" OK: Chain::write(with callbacks and tempfile) returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should\n"); - } - - printf("read chain (callback-based)\n"); - { - FILE *file = flac_fopen(flacfilename(is_ogg), "rb"); - if(0 == file) - return die_("opening file"); - if(!chain.read((::FLAC__IOHandle)file, callbacks)) { - fclose(file); - return die_c_("reading chain", chain.status()); - } - fclose(file); - } - - printf("write chain with wrong method write()\n"); - { - if(chain.write(/*use_padding=*/false, /*preserve_file_stats=*/false)) - return die_c_("mismatched write should have failed", chain.status()); - if(chain.status() != ::FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH) - return die_c_("expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", chain.status()); - printf(" OK: write() returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should\n"); - } - - printf("read chain (callback-based)\n"); - { - FILE *file = flac_fopen(flacfilename(is_ogg), "rb"); - if(0 == file) - return die_("opening file"); - if(!chain.read((::FLAC__IOHandle)file, callbacks)) { - fclose(file); - return die_c_("reading chain", chain.status()); - } - fclose(file); - } - - printf("testing Chain::check_if_tempfile_needed()... "); - - if(!chain.check_if_tempfile_needed(/*use_padding=*/false)) - printf("OK: Chain::check_if_tempfile_needed() returned false like it should\n"); - else - return die_("Chain::check_if_tempfile_needed() returned true but shouldn't have"); - - printf("write chain with wrong method Chain::write(with callbacks and tempfile)\n"); - { - if(chain.write(/*use_padding=*/false, 0, callbacks, 0, callbacks)) - return die_c_("mismatched write should have failed", chain.status()); - if(chain.status() != ::FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL) - return die_c_("expected FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL", chain.status()); - printf(" OK: Chain::write(with callbacks and tempfile) returned false,FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL like it should\n"); - } - - printf("read chain (callback-based)\n"); - { - FILE *file = flac_fopen(flacfilename(is_ogg), "rb"); - if(0 == file) - return die_("opening file"); - if(!chain.read((::FLAC__IOHandle)file, callbacks)) { - fclose(file); - return die_c_("reading chain", chain.status()); - } - fclose(file); - } - - printf("create iterator\n"); - { - FLAC::Metadata::Iterator iterator; - if(!iterator.is_valid()) - return die_("allocating memory for iterator"); - - iterator.init(chain); - - printf("[S]VP\tnext\n"); - if(!iterator.next()) - return die_("iterator ended early\n"); - - printf("S[V]P\tdelete VORBIS_COMMENT, write\n"); - if(!iterator.delete_block(/*replace_with_padding=*/false)) - return die_c_("block delete failed\n", chain.status()); - - printf("testing Chain::check_if_tempfile_needed()... "); - - if(chain.check_if_tempfile_needed(/*use_padding=*/false)) - printf("OK: Chain::check_if_tempfile_needed() returned true like it should\n"); - else - return die_("Chain::check_if_tempfile_needed() returned false but shouldn't have"); - - printf("write chain with wrong method Chain::write(with callbacks)\n"); - { - if(chain.write(/*use_padding=*/false, 0, callbacks)) - return die_c_("mismatched write should have failed", chain.status()); - if(chain.status() != ::FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL) - return die_c_("expected FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL", chain.status()); - printf(" OK: Chain::write(with callbacks) returned false,FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL like it should\n"); - } - - } // delete iterator - - if(!remove_file_(flacfilename(is_ogg))) - return false; - - return true; -} - -bool test_metadata_file_manipulation() -{ - printf("\n+++ libFLAC++ unit test: metadata manipulation\n\n"); - - our_metadata_.num_blocks = 0; - - if(!test_level_0_()) - return false; - - if(!test_level_1_()) - return false; - - if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/false)) /* filename-based */ - return false; - if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/false)) /* callback-based */ - return false; - if(!test_level_2_misc_(/*is_ogg=*/false)) - return false; - - if(FLAC_API_SUPPORTS_OGG_FLAC) { - if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/true)) /* filename-based */ - return false; - if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/true)) /* callback-based */ - return false; -#if 0 - /* when ogg flac write is supported, will have to add this: */ - if(!test_level_2_misc_(/*is_ogg=*/true)) - return false; -#endif - } - - return true; -} diff --git a/flac/src/test_libFLAC++/metadata_object.cpp b/flac/src/test_libFLAC++/metadata_object.cpp deleted file mode 100644 index ab4cfbf..0000000 --- a/flac/src/test_libFLAC++/metadata_object.cpp +++ /dev/null @@ -1,2099 +0,0 @@ -/* test_libFLAC++ - Unit tester for libFLAC++ - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include /* for malloc() */ -#include /* for memcmp() */ -#include "FLAC/assert.h" -#include "FLAC++/metadata.h" -#include "share/safe_str.h" - -static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application_, vorbiscomment_, cuesheet_, picture_; - -static bool die_(const char *msg) -{ - printf("FAILED, %s\n", msg); - return false; -} - -static void *malloc_or_die_(size_t size) -{ - void *x = malloc(size); - if(0 == x) { - fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (uint32_t)size); - exit(1); - } - return x; -} - -static char *strdup_or_die_(const char *s) -{ - char *x = strdup(s); - if(0 == x) { - fprintf(stderr, "ERROR: out of memory copying string \"%s\"\n", s); - exit(1); - } - return x; -} - -static bool index_is_equal_(const ::FLAC__StreamMetadata_CueSheet_Index &indx, const ::FLAC__StreamMetadata_CueSheet_Index &indxcopy) -{ - if(indxcopy.offset != indx.offset) - return false; - if(indxcopy.number != indx.number) - return false; - return true; -} - -static bool track_is_equal_(const ::FLAC__StreamMetadata_CueSheet_Track *track, const ::FLAC__StreamMetadata_CueSheet_Track *trackcopy) -{ - uint32_t i; - - if(trackcopy->offset != track->offset) - return false; - if(trackcopy->number != track->number) - return false; - if(0 != strcmp(trackcopy->isrc, track->isrc)) - return false; - if(trackcopy->type != track->type) - return false; - if(trackcopy->pre_emphasis != track->pre_emphasis) - return false; - if(trackcopy->num_indices != track->num_indices) - return false; - if(0 == track->indices || 0 == trackcopy->indices) { - if(track->indices != trackcopy->indices) - return false; - } - else { - for(i = 0; i < track->num_indices; i++) { - if(!index_is_equal_(trackcopy->indices[i], track->indices[i])) - return false; - } - } - return true; -} - -static void init_metadata_blocks_() -{ - streaminfo_.is_last = false; - streaminfo_.type = ::FLAC__METADATA_TYPE_STREAMINFO; - streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH; - streaminfo_.data.stream_info.min_blocksize = 576; - streaminfo_.data.stream_info.max_blocksize = 576; - streaminfo_.data.stream_info.min_framesize = 0; - streaminfo_.data.stream_info.max_framesize = 0; - streaminfo_.data.stream_info.sample_rate = 44100; - streaminfo_.data.stream_info.channels = 1; - streaminfo_.data.stream_info.bits_per_sample = 8; - streaminfo_.data.stream_info.total_samples = 0; - memset(streaminfo_.data.stream_info.md5sum, 0, 16); - - padding_.is_last = false; - padding_.type = ::FLAC__METADATA_TYPE_PADDING; - padding_.length = 1234; - - seektable_.is_last = false; - seektable_.type = ::FLAC__METADATA_TYPE_SEEKTABLE; - seektable_.data.seek_table.num_points = 2; - seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH; - seektable_.data.seek_table.points = (::FLAC__StreamMetadata_SeekPoint*)malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(::FLAC__StreamMetadata_SeekPoint)); - seektable_.data.seek_table.points[0].sample_number = 0; - seektable_.data.seek_table.points[0].stream_offset = 0; - seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize; - seektable_.data.seek_table.points[1].sample_number = ::FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - seektable_.data.seek_table.points[1].stream_offset = 1000; - seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize; - - application_.is_last = false; - application_.type = ::FLAC__METADATA_TYPE_APPLICATION; - application_.length = 8; - memcpy(application_.data.application.id, "\xfe\xdc\xba\x98", 4); - application_.data.application.data = (FLAC__byte*)malloc_or_die_(4); - memcpy(application_.data.application.data, "\xf0\xe1\xd2\xc3", 4); - - vorbiscomment_.is_last = false; - vorbiscomment_.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT; - vorbiscomment_.length = (4 + 5) + 4 + (4 + 12) + (4 + 12); - vorbiscomment_.data.vorbis_comment.vendor_string.length = 5; - vorbiscomment_.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(5+1); - memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "name0", 5+1); - vorbiscomment_.data.vorbis_comment.num_comments = 2; - vorbiscomment_.data.vorbis_comment.comments = (::FLAC__StreamMetadata_VorbisComment_Entry*)malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(::FLAC__StreamMetadata_VorbisComment_Entry)); - vorbiscomment_.data.vorbis_comment.comments[0].length = 12; - vorbiscomment_.data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(12+1); - memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "name2=value2", 12+1); - vorbiscomment_.data.vorbis_comment.comments[1].length = 12; - vorbiscomment_.data.vorbis_comment.comments[1].entry = (FLAC__byte*)malloc_or_die_(12+1); - memcpy(vorbiscomment_.data.vorbis_comment.comments[1].entry, "name3=value3", 12+1); - - cuesheet_.is_last = false; - cuesheet_.type = ::FLAC__METADATA_TYPE_CUESHEET; - cuesheet_.length = - /* cuesheet guts */ - ( - FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN + - FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + - FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN - ) / 8 + - /* 2 tracks */ - 2 * ( - FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN - ) / 8 + - /* 3 index points */ - 3 * ( - FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN + - FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN - ) / 8 - ; - memset(cuesheet_.data.cue_sheet.media_catalog_number, 0, sizeof(cuesheet_.data.cue_sheet.media_catalog_number)); - cuesheet_.data.cue_sheet.media_catalog_number[0] = 'j'; - cuesheet_.data.cue_sheet.media_catalog_number[1] = 'C'; - cuesheet_.data.cue_sheet.lead_in = 159; - cuesheet_.data.cue_sheet.is_cd = true; - cuesheet_.data.cue_sheet.num_tracks = 2; - cuesheet_.data.cue_sheet.tracks = (FLAC__StreamMetadata_CueSheet_Track*)malloc_or_die_(cuesheet_.data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track)); - cuesheet_.data.cue_sheet.tracks[0].offset = 1; - cuesheet_.data.cue_sheet.tracks[0].number = 1; - memcpy(cuesheet_.data.cue_sheet.tracks[0].isrc, "ACBDE1234567", sizeof(cuesheet_.data.cue_sheet.tracks[0].isrc)); - cuesheet_.data.cue_sheet.tracks[0].type = 0; - cuesheet_.data.cue_sheet.tracks[0].pre_emphasis = 1; - cuesheet_.data.cue_sheet.tracks[0].num_indices = 2; - cuesheet_.data.cue_sheet.tracks[0].indices = (FLAC__StreamMetadata_CueSheet_Index*)malloc_or_die_(cuesheet_.data.cue_sheet.tracks[0].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index)); - cuesheet_.data.cue_sheet.tracks[0].indices[0].offset = 0; - cuesheet_.data.cue_sheet.tracks[0].indices[0].number = 0; - cuesheet_.data.cue_sheet.tracks[0].indices[1].offset = 1234567890; - cuesheet_.data.cue_sheet.tracks[0].indices[1].number = 1; - cuesheet_.data.cue_sheet.tracks[1].offset = 2345678901u; - cuesheet_.data.cue_sheet.tracks[1].number = 2; - memcpy(cuesheet_.data.cue_sheet.tracks[1].isrc, "ACBDE7654321", sizeof(cuesheet_.data.cue_sheet.tracks[1].isrc)); - cuesheet_.data.cue_sheet.tracks[1].type = 1; - cuesheet_.data.cue_sheet.tracks[1].pre_emphasis = 0; - cuesheet_.data.cue_sheet.tracks[1].num_indices = 1; - cuesheet_.data.cue_sheet.tracks[1].indices = (FLAC__StreamMetadata_CueSheet_Index*)malloc_or_die_(cuesheet_.data.cue_sheet.tracks[1].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index)); - cuesheet_.data.cue_sheet.tracks[1].indices[0].offset = 0; - cuesheet_.data.cue_sheet.tracks[1].indices[0].number = 1; - - picture_.is_last = true; - picture_.type = FLAC__METADATA_TYPE_PICTURE; - picture_.length = - ( - FLAC__STREAM_METADATA_PICTURE_TYPE_LEN + - FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* will add the length for the string later */ - FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* will add the length for the string later */ - FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN + - FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN + - FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN + - FLAC__STREAM_METADATA_PICTURE_COLORS_LEN + - FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */ - ) / 8 - ; - picture_.data.picture.type = FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER; - picture_.data.picture.mime_type = strdup_or_die_("image/jpeg"); - picture_.length += strlen(picture_.data.picture.mime_type); - picture_.data.picture.description = (FLAC__byte*)strdup_or_die_("desc"); - picture_.length += strlen((const char *)picture_.data.picture.description); - picture_.data.picture.width = 300; - picture_.data.picture.height = 300; - picture_.data.picture.depth = 24; - picture_.data.picture.colors = 0; - picture_.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA"); - picture_.data.picture.data_length = strlen((const char *)picture_.data.picture.data); - picture_.length += picture_.data.picture.data_length; -} - -static void free_metadata_blocks_() -{ - free(seektable_.data.seek_table.points); - free(application_.data.application.data); - free(vorbiscomment_.data.vorbis_comment.vendor_string.entry); - free(vorbiscomment_.data.vorbis_comment.comments[0].entry); - free(vorbiscomment_.data.vorbis_comment.comments[1].entry); - free(vorbiscomment_.data.vorbis_comment.comments); - free(cuesheet_.data.cue_sheet.tracks[0].indices); - free(cuesheet_.data.cue_sheet.tracks[1].indices); - free(cuesheet_.data.cue_sheet.tracks); - free(picture_.data.picture.mime_type); - free(picture_.data.picture.description); - free(picture_.data.picture.data); -} - -bool test_metadata_object_streaminfo() -{ - uint32_t expected_length; - - printf("testing class FLAC::Metadata::StreamInfo\n"); - - printf("testing StreamInfo::StreamInfo()... "); - FLAC::Metadata::StreamInfo block; - if(!block.is_valid()) - return die_("!block.is_valid()"); - expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH; - if(block.get_length() != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length()); - return false; - } - printf("OK\n"); - - printf("testing StreamInfo::StreamInfo(const StreamInfo &)... +\n"); - printf(" StreamInfo::operator!=(const StreamInfo &)... "); - { - FLAC::Metadata::StreamInfo blockcopy(block); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != block) - return die_("copy is not identical to original"); - printf("OK\n"); - - printf("testing StreamInfo::~StreamInfo()... "); - } - printf("OK\n"); - - printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata &)... +\n"); - printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::StreamInfo blockcopy(streaminfo_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != streaminfo_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata *)... +\n"); - printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::StreamInfo blockcopy(&streaminfo_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != streaminfo_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::StreamInfo blockcopy(&streaminfo_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != streaminfo_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&streaminfo_); - FLAC::Metadata::StreamInfo blockcopy(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != streaminfo_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing StreamInfo::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::StreamInfo blockcopy; - blockcopy.assign(&streaminfo_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != streaminfo_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing StreamInfo::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&streaminfo_); - FLAC::Metadata::StreamInfo blockcopy; - blockcopy.assign(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != streaminfo_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing StreamInfo::operator=(const StreamInfo &)... +\n"); - printf(" StreamInfo::operator==(const StreamInfo &)... "); - { - FLAC::Metadata::StreamInfo blockcopy = block; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == block)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing StreamInfo::operator=(const ::FLAC__StreamMetadata &)... +\n"); - printf(" StreamInfo::operator==(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::StreamInfo blockcopy = streaminfo_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == streaminfo_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing StreamInfo::operator=(const ::FLAC__StreamMetadata *)... +\n"); - printf(" StreamInfo::operator==(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::StreamInfo blockcopy = &streaminfo_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == streaminfo_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing StreamInfo::set_min_blocksize()... "); - block.set_min_blocksize(streaminfo_.data.stream_info.min_blocksize); - printf("OK\n"); - - printf("testing StreamInfo::set_max_blocksize()... "); - block.set_max_blocksize(streaminfo_.data.stream_info.max_blocksize); - printf("OK\n"); - - printf("testing StreamInfo::set_min_framesize()... "); - block.set_min_framesize(streaminfo_.data.stream_info.min_framesize); - printf("OK\n"); - - printf("testing StreamInfo::set_max_framesize()... "); - block.set_max_framesize(streaminfo_.data.stream_info.max_framesize); - printf("OK\n"); - - printf("testing StreamInfo::set_sample_rate()... "); - block.set_sample_rate(streaminfo_.data.stream_info.sample_rate); - printf("OK\n"); - - printf("testing StreamInfo::set_channels()... "); - block.set_channels(streaminfo_.data.stream_info.channels); - printf("OK\n"); - - printf("testing StreamInfo::set_bits_per_sample()... "); - block.set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample); - printf("OK\n"); - - printf("testing StreamInfo::set_total_samples()... "); - block.set_total_samples(streaminfo_.data.stream_info.total_samples); - printf("OK\n"); - - printf("testing StreamInfo::set_md5sum()... "); - block.set_md5sum(streaminfo_.data.stream_info.md5sum); - printf("OK\n"); - - printf("testing StreamInfo::get_min_blocksize()... "); - if(block.get_min_blocksize() != streaminfo_.data.stream_info.min_blocksize) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing StreamInfo::get_max_blocksize()... "); - if(block.get_max_blocksize() != streaminfo_.data.stream_info.max_blocksize) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing StreamInfo::get_min_framesize()... "); - if(block.get_min_framesize() != streaminfo_.data.stream_info.min_framesize) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing StreamInfo::get_max_framesize()... "); - if(block.get_max_framesize() != streaminfo_.data.stream_info.max_framesize) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing StreamInfo::get_sample_rate()... "); - if(block.get_sample_rate() != streaminfo_.data.stream_info.sample_rate) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing StreamInfo::get_channels()... "); - if(block.get_channels() != streaminfo_.data.stream_info.channels) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing StreamInfo::get_bits_per_sample()... "); - if(block.get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing StreamInfo::get_total_samples()... "); - if(block.get_total_samples() != streaminfo_.data.stream_info.total_samples) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing StreamInfo::get_md5sum()... "); - if(0 != memcmp(block.get_md5sum(), streaminfo_.data.stream_info.md5sum, 16)) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... "); - FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block); - if(0 == clone_) - return die_("returned NULL"); - if(0 == dynamic_cast(clone_)) - return die_("downcast is NULL"); - if(*dynamic_cast(clone_) != block) - return die_("clone is not identical"); - printf("OK\n"); - printf("testing StreamInfo::~StreamInfo()... "); - delete clone_; - printf("OK\n"); - - - printf("PASSED\n\n"); - return true; -} - -bool test_metadata_object_padding() -{ - uint32_t expected_length; - - printf("testing class FLAC::Metadata::Padding\n"); - - printf("testing Padding::Padding()... "); - FLAC::Metadata::Padding block; - if(!block.is_valid()) - return die_("!block.is_valid()"); - expected_length = 0; - if(block.get_length() != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length()); - return false; - } - printf("OK\n"); - - printf("testing Padding::Padding(const Padding &)... +\n"); - printf(" Padding::operator!=(const Padding &)... "); - { - FLAC::Metadata::Padding blockcopy(block); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != block) - return die_("copy is not identical to original"); - printf("OK\n"); - - printf("testing Padding::~Padding()... "); - } - printf("OK\n"); - - printf("testing Padding::Padding(const ::FLAC__StreamMetadata &)... +\n"); - printf(" Padding::operator!=(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::Padding blockcopy(padding_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != padding_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Padding::Padding(const ::FLAC__StreamMetadata *)... +\n"); - printf(" Padding::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Padding blockcopy(&padding_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != padding_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Padding::Padding(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" Padding::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Padding blockcopy(&padding_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != padding_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Padding::Padding(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" Padding::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&padding_); - FLAC::Metadata::Padding blockcopy(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != padding_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Padding::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" Padding::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Padding blockcopy; - blockcopy.assign(&padding_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != padding_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Padding::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" Padding::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&padding_); - FLAC::Metadata::Padding blockcopy; - blockcopy.assign(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != padding_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Padding::operator=(const Padding &)... +\n"); - printf(" Padding::operator==(const Padding &)... "); - { - FLAC::Metadata::Padding blockcopy = block; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == block)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Padding::operator=(const ::FLAC__StreamMetadata &)... +\n"); - printf(" Padding::operator==(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::Padding blockcopy = padding_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == padding_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Padding::operator=(const ::FLAC__StreamMetadata *)... +\n"); - printf(" Padding::operator==(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Padding blockcopy = &padding_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == padding_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Padding::set_length()... "); - block.set_length(padding_.length); - printf("OK\n"); - - printf("testing Prototype::get_length()... "); - if(block.get_length() != padding_.length) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... "); - FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block); - if(0 == clone_) - return die_("returned NULL"); - if(0 == dynamic_cast(clone_)) - return die_("downcast is NULL"); - if(*dynamic_cast(clone_) != block) - return die_("clone is not identical"); - printf("OK\n"); - printf("testing Padding::~Padding()... "); - delete clone_; - printf("OK\n"); - - - printf("PASSED\n\n"); - return true; -} - -bool test_metadata_object_application() -{ - uint32_t expected_length; - - printf("testing class FLAC::Metadata::Application\n"); - - printf("testing Application::Application()... "); - FLAC::Metadata::Application block; - if(!block.is_valid()) - return die_("!block.is_valid()"); - expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8; - if(block.get_length() != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length()); - return false; - } - printf("OK\n"); - - printf("testing Application::Application(const Application &)... +\n"); - printf(" Application::operator!=(const Application &)... "); - { - FLAC::Metadata::Application blockcopy(block); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != block) - return die_("copy is not identical to original"); - printf("OK\n"); - - printf("testing Application::~Application()... "); - } - printf("OK\n"); - - printf("testing Application::Application(const ::FLAC__StreamMetadata &)... +\n"); - printf(" Application::operator!=(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::Application blockcopy(application_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != application_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Application::Application(const ::FLAC__StreamMetadata *)... +\n"); - printf(" Application::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Application blockcopy(&application_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != application_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Application::Application(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" Application::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Application blockcopy(&application_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != application_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Application::Application(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" Application::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&application_); - FLAC::Metadata::Application blockcopy(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != application_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Application::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" Application::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Application blockcopy; - blockcopy.assign(&application_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != application_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Application::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" Application::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&application_); - FLAC::Metadata::Application blockcopy; - blockcopy.assign(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != application_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Application::operator=(const Application &)... +\n"); - printf(" Application::operator==(const Application &)... "); - { - FLAC::Metadata::Application blockcopy = block; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == block)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Application::operator=(const ::FLAC__StreamMetadata &)... +\n"); - printf(" Application::operator==(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::Application blockcopy = application_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == application_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Application::operator=(const ::FLAC__StreamMetadata *)... +\n"); - printf(" Application::operator==(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Application blockcopy = &application_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == application_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Application::set_id()... "); - block.set_id(application_.data.application.id); - printf("OK\n"); - - printf("testing Application::set_data()... "); - block.set_data(application_.data.application.data, application_.length - sizeof(application_.data.application.id), /*copy=*/true); - printf("OK\n"); - - printf("testing Application::get_id()... "); - if(0 != memcmp(block.get_id(), application_.data.application.id, sizeof(application_.data.application.id))) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing Application::get_data()... "); - if(0 != memcmp(block.get_data(), application_.data.application.data, application_.length - sizeof(application_.data.application.id))) - return die_("value mismatch, doesn't match previously set value"); - printf("OK\n"); - - printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... "); - FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block); - if(0 == clone_) - return die_("returned NULL"); - if(0 == dynamic_cast(clone_)) - return die_("downcast is NULL"); - if(*dynamic_cast(clone_) != block) - return die_("clone is not identical"); - printf("OK\n"); - printf("testing Application::~Application()... "); - delete clone_; - printf("OK\n"); - - - printf("PASSED\n\n"); - return true; -} - -bool test_metadata_object_seektable() -{ - uint32_t expected_length; - - printf("testing class FLAC::Metadata::SeekTable\n"); - - printf("testing SeekTable::SeekTable()... "); - FLAC::Metadata::SeekTable block; - if(!block.is_valid()) - return die_("!block.is_valid()"); - expected_length = 0; - if(block.get_length() != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length()); - return false; - } - printf("OK\n"); - - printf("testing SeekTable::SeekTable(const SeekTable &)... +\n"); - printf(" SeekTable::operator!=(const SeekTable &)... "); - { - FLAC::Metadata::SeekTable blockcopy(block); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != block) - return die_("copy is not identical to original"); - printf("OK\n"); - - printf("testing SeekTable::~SeekTable()... "); - } - printf("OK\n"); - - printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata &)... +\n"); - printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::SeekTable blockcopy(seektable_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != seektable_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata *)... +\n"); - printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::SeekTable blockcopy(&seektable_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != seektable_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::SeekTable blockcopy(&seektable_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != seektable_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&seektable_); - FLAC::Metadata::SeekTable blockcopy(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != seektable_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing SeekTable::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::SeekTable blockcopy; - blockcopy.assign(&seektable_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != seektable_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing SeekTable::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&seektable_); - FLAC::Metadata::SeekTable blockcopy; - blockcopy.assign(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != seektable_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing SeekTable::operator=(const SeekTable &)... +\n"); - printf(" SeekTable::operator==(const SeekTable &)... "); - { - FLAC::Metadata::SeekTable blockcopy = block; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == block)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing SeekTable::operator=(const ::FLAC__StreamMetadata &)... +\n"); - printf(" SeekTable::operator==(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::SeekTable blockcopy = seektable_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == seektable_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing SeekTable::operator=(const ::FLAC__StreamMetadata *)... +\n"); - printf(" SeekTable::operator==(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::SeekTable blockcopy = &seektable_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == seektable_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing SeekTable::insert_point() x 3... "); - if(!block.insert_point(0, seektable_.data.seek_table.points[1])) - return die_("returned false"); - if(!block.insert_point(0, seektable_.data.seek_table.points[1])) - return die_("returned false"); - if(!block.insert_point(1, seektable_.data.seek_table.points[0])) - return die_("returned false"); - printf("OK\n"); - - printf("testing SeekTable::is_legal()... "); - if(block.is_legal()) - return die_("returned true"); - printf("OK\n"); - - printf("testing SeekTable::set_point()... "); - block.set_point(0, seektable_.data.seek_table.points[0]); - printf("OK\n"); - - printf("testing SeekTable::delete_point()... "); - if(!block.delete_point(0)) - return die_("returned false"); - printf("OK\n"); - - printf("testing SeekTable::is_legal()... "); - if(!block.is_legal()) - return die_("returned false"); - printf("OK\n"); - - printf("testing SeekTable::get_num_points()... "); - if(block.get_num_points() != seektable_.data.seek_table.num_points) - return die_("number mismatch"); - printf("OK\n"); - - printf("testing SeekTable::operator!=(const ::FLAC__StreamMetadata &)... "); - if(block != seektable_) - return die_("data mismatch"); - printf("OK\n"); - - printf("testing SeekTable::get_point()... "); - if( - block.get_point(1).sample_number != seektable_.data.seek_table.points[1].sample_number || - block.get_point(1).stream_offset != seektable_.data.seek_table.points[1].stream_offset || - block.get_point(1).frame_samples != seektable_.data.seek_table.points[1].frame_samples - ) - return die_("point mismatch"); - printf("OK\n"); - - printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... "); - FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block); - if(0 == clone_) - return die_("returned NULL"); - if(0 == dynamic_cast(clone_)) - return die_("downcast is NULL"); - if(*dynamic_cast(clone_) != block) - return die_("clone is not identical"); - printf("OK\n"); - printf("testing SeekTable::~SeekTable()... "); - delete clone_; - printf("OK\n"); - - - printf("PASSED\n\n"); - return true; -} - -bool test_metadata_object_vorbiscomment() -{ - uint32_t expected_length; - - printf("testing class FLAC::Metadata::VorbisComment::Entry\n"); - - printf("testing Entry::Entry()... "); - { - FLAC::Metadata::VorbisComment::Entry entry1; - if(!entry1.is_valid()) - return die_("!is_valid()"); - printf("OK\n"); - - printf("testing Entry::~Entry()... "); - } - printf("OK\n"); - - printf("testing Entry::Entry(const char *field, uint32_t field_length)... "); - FLAC::Metadata::VorbisComment::Entry entry2("name2=value2", strlen("name2=value2")); - if(!entry2.is_valid()) - return die_("!is_valid()"); - printf("OK\n"); - - { - printf("testing Entry::Entry(const char *field)... "); - FLAC::Metadata::VorbisComment::Entry entry2z("name2=value2"); - if(!entry2z.is_valid()) - return die_("!is_valid()"); - if(strcmp(entry2.get_field(), entry2z.get_field())) - return die_("bad value"); - printf("OK\n"); - } - - printf("testing Entry::Entry(const char *field_name, const char *field_value, uint32_t field_value_length)... "); - FLAC::Metadata::VorbisComment::Entry entry3("name3", "value3", strlen("value3")); - if(!entry3.is_valid()) - return die_("!is_valid()"); - printf("OK\n"); - - { - printf("testing Entry::Entry(const char *field_name, const char *field_value)... "); - FLAC::Metadata::VorbisComment::Entry entry3z("name3", "value3"); - if(!entry3z.is_valid()) - return die_("!is_valid()"); - if(strcmp(entry3.get_field(), entry3z.get_field())) - return die_("bad value"); - printf("OK\n"); - } - - printf("testing Entry::Entry(const Entry &entry)... "); - { - FLAC::Metadata::VorbisComment::Entry entry2copy(entry2); - if(!entry2copy.is_valid()) - return die_("!is_valid()"); - printf("OK\n"); - - printf("testing Entry::~Entry()... "); - } - printf("OK\n"); - - printf("testing Entry::operator=(const Entry &entry)... "); - FLAC::Metadata::VorbisComment::Entry entry1 = entry2; - if(!entry2.is_valid()) - return die_("!is_valid()"); - printf("OK\n"); - - printf("testing Entry::get_field_length()... "); - if(entry1.get_field_length() != strlen("name2=value2")) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Entry::get_field_name_length()... "); - if(entry1.get_field_name_length() != strlen("name2")) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Entry::get_field_value_length()... "); - if(entry1.get_field_value_length() != strlen("value2")) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Entry::get_entry()... "); - { - ::FLAC__StreamMetadata_VorbisComment_Entry entry = entry1.get_entry(); - if(entry.length != strlen("name2=value2")) - return die_("entry length mismatch"); - if(0 != memcmp(entry.entry, "name2=value2", entry.length)) - return die_("entry value mismatch"); - } - printf("OK\n"); - - printf("testing Entry::get_field()... "); - if(0 != memcmp(entry1.get_field(), "name2=value2", strlen("name2=value2"))) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Entry::get_field_name()... "); - if(0 != memcmp(entry1.get_field_name(), "name2", strlen("name2"))) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Entry::get_field_value()... "); - if(0 != memcmp(entry1.get_field_value(), "value2", strlen("value2"))) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Entry::set_field_name()... "); - if(!entry1.set_field_name("name1")) - return die_("returned false"); - if(0 != memcmp(entry1.get_field_name(), "name1", strlen("name1"))) - return die_("value mismatch"); - if(0 != memcmp(entry1.get_field(), "name1=value2", strlen("name1=value2"))) - return die_("entry mismatch"); - printf("OK\n"); - - printf("testing Entry::set_field_value(const char *field_value, uint32_t field_value_length)... "); - if(!entry1.set_field_value("value1", strlen("value1"))) - return die_("returned false"); - if(0 != memcmp(entry1.get_field_value(), "value1", strlen("value1"))) - return die_("value mismatch"); - if(0 != memcmp(entry1.get_field(), "name1=value1", strlen("name1=value1"))) - return die_("entry mismatch"); - printf("OK\n"); - - printf("testing Entry::set_field_value(const char *field_value)... "); - if(!entry1.set_field_value("value1")) - return die_("returned false"); - if(0 != memcmp(entry1.get_field_value(), "value1", strlen("value1"))) - return die_("value mismatch"); - if(0 != memcmp(entry1.get_field(), "name1=value1", strlen("name1=value1"))) - return die_("entry mismatch"); - printf("OK\n"); - - printf("testing Entry::set_field(const char *field, uint32_t field_length)... "); - if(!entry1.set_field("name0=value0", strlen("name0=value0"))) - return die_("returned false"); - if(0 != memcmp(entry1.get_field_name(), "name0", strlen("name0"))) - return die_("value mismatch"); - if(0 != memcmp(entry1.get_field_value(), "value0", strlen("value0"))) - return die_("value mismatch"); - if(0 != memcmp(entry1.get_field(), "name0=value0", strlen("name0=value0"))) - return die_("entry mismatch"); - printf("OK\n"); - - printf("testing Entry::set_field(const char *field)... "); - if(!entry1.set_field("name0=value0")) - return die_("returned false"); - if(0 != memcmp(entry1.get_field_name(), "name0", strlen("name0"))) - return die_("value mismatch"); - if(0 != memcmp(entry1.get_field_value(), "value0", strlen("value0"))) - return die_("value mismatch"); - if(0 != memcmp(entry1.get_field(), "name0=value0", strlen("name0=value0"))) - return die_("entry mismatch"); - printf("OK\n"); - - printf("PASSED\n\n"); - - - printf("testing class FLAC::Metadata::VorbisComment\n"); - - printf("testing VorbisComment::VorbisComment()... "); - FLAC::Metadata::VorbisComment block; - if(!block.is_valid()) - return die_("!block.is_valid()"); - expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(::FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8); - if(block.get_length() != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length()); - return false; - } - printf("OK\n"); - - printf("testing VorbisComment::VorbisComment(const VorbisComment &)... +\n"); - printf(" VorbisComment::operator!=(const VorbisComment &)... "); - { - FLAC::Metadata::VorbisComment blockcopy(block); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != block) - return die_("copy is not identical to original"); - printf("OK\n"); - - printf("testing VorbisComment::~VorbisComment()... "); - } - printf("OK\n"); - - printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata &)... +\n"); - printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::VorbisComment blockcopy(vorbiscomment_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != vorbiscomment_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata *)... +\n"); - printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::VorbisComment blockcopy(&vorbiscomment_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != vorbiscomment_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::VorbisComment blockcopy(&vorbiscomment_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != vorbiscomment_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&vorbiscomment_); - FLAC::Metadata::VorbisComment blockcopy(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != vorbiscomment_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing VorbisComment::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::VorbisComment blockcopy; - blockcopy.assign(&vorbiscomment_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != vorbiscomment_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing VorbisComment::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&vorbiscomment_); - FLAC::Metadata::VorbisComment blockcopy; - blockcopy.assign(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != vorbiscomment_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing VorbisComment::operator=(const VorbisComment &)... +\n"); - printf(" VorbisComment::operator==(const VorbisComment &)... "); - { - FLAC::Metadata::VorbisComment blockcopy = block; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == block)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing VorbisComment::operator=(const ::FLAC__StreamMetadata &)... +\n"); - printf(" VorbisComment::operator==(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::VorbisComment blockcopy = vorbiscomment_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == vorbiscomment_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing VorbisComment::operator=(const ::FLAC__StreamMetadata *)... +\n"); - printf(" VorbisComment::operator==(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::VorbisComment blockcopy = &vorbiscomment_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == vorbiscomment_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing VorbisComment::get_num_comments()... "); - if(block.get_num_comments() != 0) - return die_("value mismatch, expected 0"); - printf("OK\n"); - - printf("testing VorbisComment::set_vendor_string()... "); - if(!block.set_vendor_string((const FLAC__byte *)"mame0")) - return die_("returned false"); - printf("OK\n"); - vorbiscomment_.data.vorbis_comment.vendor_string.entry[0] = 'm'; - - printf("testing VorbisComment::get_vendor_string()... "); - if(strlen((const char *)block.get_vendor_string()) != vorbiscomment_.data.vorbis_comment.vendor_string.length) - return die_("length mismatch"); - if(0 != memcmp(block.get_vendor_string(), vorbiscomment_.data.vorbis_comment.vendor_string.entry, vorbiscomment_.data.vorbis_comment.vendor_string.length)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing VorbisComment::append_comment()... +\n"); - printf(" VorbisComment::get_comment()... "); - if(!block.append_comment(entry3)) - return die_("returned false"); - if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length) - return die_("length mismatch"); - if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing VorbisComment::append_comment()... +\n"); - printf(" VorbisComment::get_comment()... "); - if(!block.append_comment(entry2)) - return die_("returned false"); - if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length) - return die_("length mismatch"); - if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing VorbisComment::delete_comment()... +\n"); - printf(" VorbisComment::get_comment()... "); - if(!block.delete_comment(0)) - return die_("returned false"); - if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length) - return die_("length[0] mismatch"); - if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length)) - return die_("value[0] mismatch"); - printf("OK\n"); - - printf("testing VorbisComment::delete_comment()... +\n"); - printf(" VorbisComment::get_comment()... "); - if(!block.delete_comment(0)) - return die_("returned false"); - if(block.get_num_comments() != 0) - return die_("block mismatch, expected num_comments = 0"); - printf("OK\n"); - - printf("testing VorbisComment::insert_comment()... +\n"); - printf(" VorbisComment::get_comment()... "); - if(!block.insert_comment(0, entry3)) - return die_("returned false"); - if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length) - return die_("length mismatch"); - if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing VorbisComment::insert_comment()... +\n"); - printf(" VorbisComment::get_comment()... "); - if(!block.insert_comment(0, entry3)) - return die_("returned false"); - if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length) - return die_("length mismatch"); - if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing VorbisComment::insert_comment()... +\n"); - printf(" VorbisComment::get_comment()... "); - if(!block.insert_comment(1, entry2)) - return die_("returned false"); - if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length) - return die_("length mismatch"); - if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing VorbisComment::set_comment()... +\n"); - printf(" VorbisComment::get_comment()... "); - if(!block.set_comment(0, entry2)) - return die_("returned false"); - if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length) - return die_("length mismatch"); - if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing VorbisComment::delete_comment()... +\n"); - printf(" VorbisComment::get_comment()... "); - if(!block.delete_comment(0)) - return die_("returned false"); - if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length) - return die_("length[0] mismatch"); - if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length)) - return die_("value[0] mismatch"); - if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length) - return die_("length[1] mismatch"); - if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length)) - return die_("value[0] mismatch"); - printf("OK\n"); - - printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... "); - FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block); - if(0 == clone_) - return die_("returned NULL"); - if(0 == dynamic_cast(clone_)) - return die_("downcast is NULL"); - if(*dynamic_cast(clone_) != block) - return die_("clone is not identical"); - printf("OK\n"); - printf("testing VorbisComment::~VorbisComment()... "); - delete clone_; - printf("OK\n"); - - - printf("PASSED\n\n"); - return true; -} - -bool test_metadata_object_cuesheet() -{ - uint32_t expected_length; - - printf("testing class FLAC::Metadata::CueSheet::Track\n"); - - printf("testing Track::Track()... "); - FLAC::Metadata::CueSheet::Track track0; - if(!track0.is_valid()) - return die_("!is_valid()"); - printf("OK\n"); - - { - printf("testing Track::get_track()... "); - const ::FLAC__StreamMetadata_CueSheet_Track *trackp = track0.get_track(); - if(0 == trackp) - return die_("returned pointer is NULL"); - printf("OK\n"); - - printf("testing Track::Track(const ::FLAC__StreamMetadata_CueSheet_Track*)... "); - FLAC::Metadata::CueSheet::Track track2(trackp); - if(!track2.is_valid()) - return die_("!is_valid()"); - if(!track_is_equal_(track2.get_track(), trackp)) - return die_("copy is not equal"); - printf("OK\n"); - - printf("testing Track::~Track()... "); - } - printf("OK\n"); - - printf("testing Track::Track(const Track &track)... "); - { - FLAC::Metadata::CueSheet::Track track0copy(track0); - if(!track0copy.is_valid()) - return die_("!is_valid()"); - if(!track_is_equal_(track0copy.get_track(), track0.get_track())) - return die_("copy is not equal"); - printf("OK\n"); - - printf("testing Track::~Track()... "); - } - printf("OK\n"); - - printf("testing Track::operator=(const Track &track)... "); - FLAC::Metadata::CueSheet::Track track1 = track0; - if(!track0.is_valid()) - return die_("!is_valid()"); - if(!track_is_equal_(track1.get_track(), track0.get_track())) - return die_("copy is not equal"); - printf("OK\n"); - - printf("testing Track::get_offset()... "); - if(track1.get_offset() != 0) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Track::get_number()... "); - if(track1.get_number() != 0) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Track::get_isrc()... "); - if(0 != memcmp(track1.get_isrc(), "\0\0\0\0\0\0\0\0\0\0\0\0\0", 13)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Track::get_type()... "); - if(track1.get_type() != 0) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Track::get_pre_emphasis()... "); - if(track1.get_pre_emphasis() != 0) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Track::get_num_indices()... "); - if(track1.get_num_indices() != 0) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Track::set_offset()... "); - track1.set_offset(588); - if(track1.get_offset() != 588) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Track::set_number()... "); - track1.set_number(1); - if(track1.get_number() != 1) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Track::set_isrc()... "); - track1.set_isrc("ABCDE1234567"); - if(0 != memcmp(track1.get_isrc(), "ABCDE1234567", 13)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Track::set_type()... "); - track1.set_type(1); - if(track1.get_type() != 1) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Track::set_pre_emphasis()... "); - track1.set_pre_emphasis(1); - if(track1.get_pre_emphasis() != 1) - return die_("value mismatch"); - printf("OK\n"); - - printf("PASSED\n\n"); - - printf("testing class FLAC::Metadata::CueSheet\n"); - - printf("testing CueSheet::CueSheet()... "); - FLAC::Metadata::CueSheet block; - if(!block.is_valid()) - return die_("!block.is_valid()"); - expected_length = ( - FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN + - FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + - FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN - ) / 8; - if(block.get_length() != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length()); - return false; - } - printf("OK\n"); - - printf("testing CueSheet::CueSheet(const CueSheet &)... +\n"); - printf(" CueSheet::operator!=(const CueSheet &)... "); - { - FLAC::Metadata::CueSheet blockcopy(block); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != block) - return die_("copy is not identical to original"); - printf("OK\n"); - - printf("testing CueSheet::~CueSheet()... "); - } - printf("OK\n"); - - printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata &)... +\n"); - printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::CueSheet blockcopy(cuesheet_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != cuesheet_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata *)... +\n"); - printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::CueSheet blockcopy(&cuesheet_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != cuesheet_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::CueSheet blockcopy(&cuesheet_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != cuesheet_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&cuesheet_); - FLAC::Metadata::CueSheet blockcopy(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != cuesheet_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing CueSheet::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::CueSheet blockcopy; - blockcopy.assign(&cuesheet_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != cuesheet_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing CueSheet::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&cuesheet_); - FLAC::Metadata::CueSheet blockcopy; - blockcopy.assign(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != cuesheet_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing CueSheet::operator=(const CueSheet &)... +\n"); - printf(" CueSheet::operator==(const CueSheet &)... "); - { - FLAC::Metadata::CueSheet blockcopy = block; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == block)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing CueSheet::operator=(const ::FLAC__StreamMetadata &)... +\n"); - printf(" CueSheet::operator==(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::CueSheet blockcopy = cuesheet_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == cuesheet_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing CueSheet::operator=(const ::FLAC__StreamMetadata *)... +\n"); - printf(" CueSheet::operator==(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::CueSheet blockcopy = &cuesheet_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == cuesheet_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing CueSheet::get_media_catalog_number()... "); - if(0 != strcmp(block.get_media_catalog_number(), "")) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing CueSheet::get_lead_in()... "); - if(block.get_lead_in() != 0) - return die_("value mismatch, expected 0"); - printf("OK\n"); - - printf("testing CueSheet::get_is_cd()... "); - if(block.get_is_cd()) - return die_("value mismatch, expected false"); - printf("OK\n"); - - printf("testing CueSheet::get_num_tracks()... "); - if(block.get_num_tracks() != 0) - return die_("value mismatch, expected 0"); - printf("OK\n"); - - printf("testing CueSheet::set_media_catalog_number()... "); - { - char mcn[129]; - memset(mcn, 0, sizeof(mcn)); - safe_strncpy(mcn, "1234567890123", sizeof(mcn)); - block.set_media_catalog_number(mcn); - if(0 != memcmp(block.get_media_catalog_number(), mcn, sizeof(mcn))) - return die_("value mismatch"); - } - printf("OK\n"); - - printf("testing CueSheet::set_lead_in()... "); - block.set_lead_in(588); - if(block.get_lead_in() != 588) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing CueSheet::set_is_cd()... "); - block.set_is_cd(true); - if(!block.get_is_cd()) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing CueSheet::insert_track()... +\n"); - printf(" CueSheet::get_track()... "); - if(!block.insert_track(0, track0)) - return die_("returned false"); - if(!track_is_equal_(block.get_track(0).get_track(), track0.get_track())) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing CueSheet::insert_track()... +\n"); - printf(" CueSheet::get_track()... "); - if(!block.insert_track(1, track1)) - return die_("returned false"); - if(!track_is_equal_(block.get_track(1).get_track(), track1.get_track())) - return die_("value mismatch"); - printf("OK\n"); - - ::FLAC__StreamMetadata_CueSheet_Index index0; - index0.offset = 588*4; - index0.number = 1; - - printf("testing CueSheet::insert_index(0)... +\n"); - printf(" CueSheet::get_track()... +\n"); - printf(" CueSheet::Track::get_index()... "); - if(!block.insert_index(0, 0, index0)) - return die_("returned false"); - if(!index_is_equal_(block.get_track(0).get_index(0), index0)) - return die_("value mismatch"); - printf("OK\n"); - - index0.offset = 588*5; - printf("testing CueSheet::Track::set_index()... "); - { - FLAC::Metadata::CueSheet::Track track_ = block.get_track(0); - track_.set_index(0, index0); - if(!index_is_equal_(track_.get_index(0), index0)) - return die_("value mismatch"); - } - printf("OK\n"); - - index0.offset = 588*6; - printf("testing CueSheet::set_index()... "); - block.set_index(0, 0, index0); - if(!index_is_equal_(block.get_track(0).get_index(0), index0)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing CueSheet::delete_index()... "); - if(!block.delete_index(0, 0)) - return die_("returned false"); - if(block.get_track(0).get_num_indices() != 0) - return die_("num_indices mismatch"); - printf("OK\n"); - - - printf("testing CueSheet::set_track()... +\n"); - printf(" CueSheet::get_track()... "); - if(!block.set_track(0, track1)) - return die_("returned false"); - if(!track_is_equal_(block.get_track(0).get_track(), track1.get_track())) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing CueSheet::delete_track()... "); - if(!block.delete_track(0)) - return die_("returned false"); - if(block.get_num_tracks() != 1) - return die_("num_tracks mismatch"); - printf("OK\n"); - - printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... "); - FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block); - if(0 == clone_) - return die_("returned NULL"); - if(0 == dynamic_cast(clone_)) - return die_("downcast is NULL"); - if(*dynamic_cast(clone_) != block) - return die_("clone is not identical"); - printf("OK\n"); - printf("testing CueSheet::~CueSheet()... "); - delete clone_; - printf("OK\n"); - - printf("PASSED\n\n"); - return true; -} - -bool test_metadata_object_picture() -{ - uint32_t expected_length; - - printf("testing class FLAC::Metadata::Picture\n"); - - printf("testing Picture::Picture()... "); - FLAC::Metadata::Picture block; - if(!block.is_valid()) - return die_("!block.is_valid()"); - expected_length = ( - FLAC__STREAM_METADATA_PICTURE_TYPE_LEN + - FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + - FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + - FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN + - FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN + - FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN + - FLAC__STREAM_METADATA_PICTURE_COLORS_LEN + - FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN - ) / 8; - if(block.get_length() != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length()); - return false; - } - printf("OK\n"); - - printf("testing Picture::Picture(const Picture &)... +\n"); - printf(" Picture::operator!=(const Picture &)... "); - { - FLAC::Metadata::Picture blockcopy(block); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != block) - return die_("copy is not identical to original"); - printf("OK\n"); - - printf("testing Picture::~Picture()... "); - } - printf("OK\n"); - - printf("testing Picture::Picture(const ::FLAC__StreamMetadata &)... +\n"); - printf(" Picture::operator!=(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::Picture blockcopy(picture_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != picture_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Picture::Picture(const ::FLAC__StreamMetadata *)... +\n"); - printf(" Picture::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Picture blockcopy(&picture_); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != picture_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Picture::Picture(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" Picture::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Picture blockcopy(&picture_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != picture_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Picture::Picture(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" Picture::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&picture_); - FLAC::Metadata::Picture blockcopy(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != picture_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Picture::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n"); - printf(" Picture::operator!=(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Picture blockcopy; - blockcopy.assign(&picture_, /*copy=*/true); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != picture_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Picture::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n"); - printf(" Picture::operator!=(const ::FLAC__StreamMetadata *)... "); - { - ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&picture_); - FLAC::Metadata::Picture blockcopy; - blockcopy.assign(copy, /*copy=*/false); - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(blockcopy != picture_) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Picture::operator=(const Picture &)... +\n"); - printf(" Picture::operator==(const Picture &)... "); - { - FLAC::Metadata::Picture blockcopy = block; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == block)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Picture::operator=(const ::FLAC__StreamMetadata &)... +\n"); - printf(" Picture::operator==(const ::FLAC__StreamMetadata &)... "); - { - FLAC::Metadata::Picture blockcopy = picture_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == picture_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Picture::operator=(const ::FLAC__StreamMetadata *)... +\n"); - printf(" Picture::operator==(const ::FLAC__StreamMetadata *)... "); - { - FLAC::Metadata::Picture blockcopy = &picture_; - if(!blockcopy.is_valid()) - return die_("!blockcopy.is_valid()"); - if(!(blockcopy == picture_)) - return die_("copy is not identical to original"); - printf("OK\n"); - } - - printf("testing Picture::get_type()... "); - if(block.get_type() != ::FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER) - return die_("value mismatch, expected ::FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER"); - printf("OK\n"); - - printf("testing Picture::set_type()... +\n"); - printf(" Picture::get_type()... "); - block.set_type(::FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA); - if(block.get_type() != ::FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA) - return die_("value mismatch, expected ::FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA"); - printf("OK\n"); - - printf("testing Picture::set_mime_type()... "); - if(!block.set_mime_type("qmage/jpeg")) - return die_("returned false"); - printf("OK\n"); - picture_.data.picture.mime_type[0] = 'q'; - - printf("testing Picture::get_mime_type()... "); - if(0 != strcmp(block.get_mime_type(), picture_.data.picture.mime_type)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Picture::set_description()... "); - if(!block.set_description((const FLAC__byte*)"qesc")) - return die_("returned false"); - printf("OK\n"); - picture_.data.picture.description[0] = 'q'; - - printf("testing Picture::get_description()... "); - if(0 != strcmp((const char *)block.get_description(), (const char *)picture_.data.picture.description)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing Picture::get_width()... "); - if(block.get_width() != 0) - return die_("value mismatch, expected 0"); - printf("OK\n"); - - printf("testing Picture::set_width()... +\n"); - printf(" Picture::get_width()... "); - block.set_width(400); - if(block.get_width() != 400) - return die_("value mismatch, expected 400"); - printf("OK\n"); - - printf("testing Picture::get_height()... "); - if(block.get_height() != 0) - return die_("value mismatch, expected 0"); - printf("OK\n"); - - printf("testing Picture::set_height()... +\n"); - printf(" Picture::get_height()... "); - block.set_height(200); - if(block.get_height() != 200) - return die_("value mismatch, expected 200"); - printf("OK\n"); - - printf("testing Picture::get_depth()... "); - if(block.get_depth() != 0) - return die_("value mismatch, expected 0"); - printf("OK\n"); - - printf("testing Picture::set_depth()... +\n"); - printf(" Picture::get_depth()... "); - block.set_depth(16); - if(block.get_depth() != 16) - return die_("value mismatch, expected 16"); - printf("OK\n"); - - printf("testing Picture::get_colors()... "); - if(block.get_colors() != 0) - return die_("value mismatch, expected 0"); - printf("OK\n"); - - printf("testing Picture::set_colors()... +\n"); - printf(" Picture::get_colors()... "); - block.set_colors(1u>16); - if(block.get_colors() != (1u>16)) - return die_("value mismatch, expected 2^16"); - printf("OK\n"); - - printf("testing Picture::get_data_length()... "); - if(block.get_data_length() != 0) - return die_("value mismatch, expected 0"); - printf("OK\n"); - - printf("testing Picture::set_data()... "); - if(!block.set_data((const FLAC__byte*)"qOMEJPEGDATA", strlen("qOMEJPEGDATA"))) - return die_("returned false"); - printf("OK\n"); - picture_.data.picture.data[0] = 'q'; - - printf("testing Picture::get_data()... "); - if(block.get_data_length() != picture_.data.picture.data_length) - return die_("length mismatch"); - if(0 != memcmp(block.get_data(), picture_.data.picture.data, picture_.data.picture.data_length)) - return die_("value mismatch"); - printf("OK\n"); - - printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... "); - FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block); - if(0 == clone_) - return die_("returned NULL"); - if(0 == dynamic_cast(clone_)) - return die_("downcast is NULL"); - if(*dynamic_cast(clone_) != block) - return die_("clone is not identical"); - printf("OK\n"); - printf("testing Picture::~Picture()... "); - delete clone_; - printf("OK\n"); - - - printf("PASSED\n\n"); - return true; -} - -bool test_metadata_object() -{ - printf("\n+++ libFLAC++ unit test: metadata objects\n\n"); - - init_metadata_blocks_(); - - if(!test_metadata_object_streaminfo()) - return false; - - if(!test_metadata_object_padding()) - return false; - - if(!test_metadata_object_application()) - return false; - - if(!test_metadata_object_seektable()) - return false; - - if(!test_metadata_object_vorbiscomment()) - return false; - - if(!test_metadata_object_cuesheet()) - return false; - - if(!test_metadata_object_picture()) - return false; - - free_metadata_blocks_(); - - return true; -} diff --git a/flac/src/test_libFLAC/CMakeLists.txt b/flac/src/test_libFLAC/CMakeLists.txt deleted file mode 100644 index 36a5820..0000000 --- a/flac/src/test_libFLAC/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -add_executable(test_libFLAC - bitreader.c - bitwriter.c - crc.c - decoders.c - encoders.c - endswap.c - format.c - main.c - metadata.c - metadata_manip.c - metadata_object.c - md5.c - "$/bitreader.c" - "$/bitwriter.c" - "$/crc.c" - "$/md5.c" - $<$:../../include/share/win_utf8_io.h> - $<$:../share/win_utf8_io/win_utf8_io.c>) - -target_compile_definitions(test_libFLAC PRIVATE - $<$:ENABLE_64_BIT_WORDS>) -target_include_directories(test_libFLAC PRIVATE - "$/include") -target_link_libraries(test_libFLAC FLAC grabbag test_libs_common) diff --git a/flac/src/test_libFLAC/Makefile.am b/flac/src/test_libFLAC/Makefile.am deleted file mode 100644 index c77f87e..0000000 --- a/flac/src/test_libFLAC/Makefile.am +++ /dev/null @@ -1,63 +0,0 @@ -# test_libFLAC - Unit tester for libFLAC -# Copyright (C) 2000-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -EXTRA_DIST = \ - CMakeLists.txt - -check_PROGRAMS = test_libFLAC - -if OS_IS_WINDOWS -win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la -flac__no_dll = -DFLAC__NO_DLL -endif - -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include -I$(top_srcdir)/src/libFLAC/include $(flac__no_dll) - -test_libFLAC_LDADD = \ - $(top_builddir)/src/share/grabbag/libgrabbag.la \ - $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/test_libs_common/libtest_libs_common.la \ - $(top_builddir)/src/libFLAC/libFLAC-static.la \ - $(win_utf8_lib) \ - @OGG_LIBS@ \ - -lm - -test_libFLAC_SOURCES = \ - bitreader.c \ - bitwriter.c \ - crc.c \ - decoders.c \ - encoders.c \ - endswap.c \ - format.c \ - main.c \ - metadata.c \ - metadata_manip.c \ - metadata_object.c \ - md5.c \ - bitreader.h \ - bitwriter.h \ - crc.h \ - decoders.h \ - encoders.h \ - endswap.h \ - format.h \ - metadata.h \ - md5.h - -CLEANFILES = test_libFLAC.exe diff --git a/flac/src/test_libFLAC/bitreader.c b/flac/src/test_libFLAC/bitreader.c deleted file mode 100644 index d40bd1f..0000000 --- a/flac/src/test_libFLAC/bitreader.c +++ /dev/null @@ -1,355 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "FLAC/assert.h" -#include "share/compat.h" -#include "private/bitreader.h" /* from the libFLAC private include area */ -#include "bitreader.h" -#include -#include /* for memcpy() */ - -/* - * WATCHOUT! Since FLAC__BitReader is a private structure, we use a copy of - * the definition here to get at the internals. Make sure this is kept up - * to date with what is in ../libFLAC/bitreader.c - */ -#if (ENABLE_64_BIT_WORDS == 0) - -typedef FLAC__uint32 brword; -#define FLAC__BYTES_PER_WORD 4 -#define FLAC__BITS_PER_WORD 32 - -#else - -typedef FLAC__uint64 brword; -#define FLAC__BYTES_PER_WORD 8 -#define FLAC__BITS_PER_WORD 64 - -#endif - -struct FLAC__BitReader { - /* any partially-consumed word at the head will stay right-justified as bits are consumed from the left */ - /* any incomplete word at the tail will be left-justified, and bytes from the read callback are added on the right */ - brword *buffer; - uint32_t capacity; /* in words */ - uint32_t words; /* # of completed words in buffer */ - uint32_t bytes; /* # of bytes in incomplete word at buffer[words] */ - uint32_t consumed_words; /* #words ... */ - uint32_t consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */ - uint32_t read_crc16; /* the running frame CRC */ - uint32_t crc16_offset; /* the number of words in the current buffer that should not be CRC'd */ - uint32_t crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */ - FLAC__bool read_limit_set; /* whether reads are limited */ - uint32_t read_limit; /* the remaining size of what can be read */ - uint32_t last_seen_framesync; /* the location of the last seen framesync, if it is in the buffer, in bits from front of buffer */ - FLAC__BitReaderReadCallback read_callback; - void *client_data; -}; - -static FLAC__bool read_callback(FLAC__byte buffer[], size_t *bytes, void *data); - -static void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out) -{ - uint32_t i, j; - if(br == 0) { - fprintf(out, "bitreader is NULL\n"); - } - else { - fprintf(out, "bitreader: capacity=%u words=%u bytes=%u consumed: words=%u, bits=%u\n", br->capacity, br->words, br->bytes, br->consumed_words, br->consumed_bits); - - for(i = 0; i < br->words; i++) { - fprintf(out, "%08X: ", i); - for(j = 0; j < FLAC__BITS_PER_WORD; j++) - if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits)) - fprintf(out, "."); - else - fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0); - fprintf(out, "\n"); - } - if(br->bytes > 0) { - fprintf(out, "%08X: ", i); - for(j = 0; j < br->bytes*8; j++) - if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits)) - fprintf(out, "."); - else - fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (br->bytes*8-j-1)) ? 1:0); - fprintf(out, "\n"); - } - } -} - -FLAC__bool test_bitreader(void) -{ - FLAC__BitReader *br; - FLAC__bool ok; - uint32_t i; - uint32_t words, bits; /* what we think br->consumed_words and br->consumed_bits should be */ - - FLAC__uint16 crc,expected_crcs[4] = { 0x5e4c, 0x7f6b, 0x2272, 0x42bf }; - FLAC__byte data[32]; - - FLAC__uint32 val_uint32; - FLAC__uint64 val_uint64; - - for (i = 0; i < 32; i++) - data[i] = i * 8 + 7; - - printf("\n+++ libFLAC unit test: bitreader\n\n"); - - /* - * test new -> delete - */ - printf("testing new... "); - br = FLAC__bitreader_new(); - if(0 == br) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing delete... "); - FLAC__bitreader_delete(br); - printf("OK\n"); - - /* - * test new -> init -> delete - */ - printf("testing new... "); - br = FLAC__bitreader_new(); - if(0 == br) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing init... "); - if(!FLAC__bitreader_init(br, read_callback, data)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing delete... "); - FLAC__bitreader_delete(br); - printf("OK\n"); - - /* - * test new -> init -> clear -> delete - */ - printf("testing new... "); - br = FLAC__bitreader_new(); - if(0 == br) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing init... "); - if(!FLAC__bitreader_init(br, read_callback, data)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing clear... "); - if(!FLAC__bitreader_clear(br)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing delete... "); - FLAC__bitreader_delete(br); - printf("OK\n"); - - /* - * test normal usage - */ - printf("testing new... "); - br = FLAC__bitreader_new(); - if(0 == br) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing init... "); - if(!FLAC__bitreader_init(br, read_callback, data)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing clear... "); - if(!FLAC__bitreader_clear(br)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - words = bits = 0; - - printf("capacity = %u\n", br->capacity); - - printf("testing raw reads... "); - ok = - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 1) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 2) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 5) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 8) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 10) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 4) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 32) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 4) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 2) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 8) && - FLAC__bitreader_read_raw_uint64(br, &val_uint64, 64) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 12) - ; - if(!ok) { - printf("FAILED\n"); - FLAC__bitreader_dump(br, stdout); - return false; - } - /* we read 152 bits (=19 bytes) from the bitreader */ - words = 152 / FLAC__BITS_PER_WORD; - bits = 152 - words*FLAC__BITS_PER_WORD; - - if(br->consumed_words != words) { - printf("FAILED word count %u != %u\n", br->consumed_words, words); - FLAC__bitreader_dump(br, stdout); - return false; - } - if(br->consumed_bits != bits) { - printf("FAILED bit count %u != %u\n", br->consumed_bits, bits); - FLAC__bitreader_dump(br, stdout); - return false; - } - crc = FLAC__bitreader_get_read_crc16(br); - if(crc != expected_crcs[0]) { - printf("FAILED reported CRC 0x%04x does not match expected 0x%04x\n", crc, expected_crcs[0]); - FLAC__bitreader_dump(br, stdout); - return false; - } - printf("OK\n"); - FLAC__bitreader_dump(br, stdout); - - printf("testing CRC reset... "); - FLAC__bitreader_clear(br); - FLAC__bitreader_reset_read_crc16(br, 0xFFFF); - crc = FLAC__bitreader_get_read_crc16(br); - if(crc != 0xFFFF) { - printf("FAILED reported CRC 0x%04x does not match expected 0xFFFF\n", crc); - FLAC__bitreader_dump(br, stdout); - return false; - } - FLAC__bitreader_reset_read_crc16(br, 0); - crc = FLAC__bitreader_get_read_crc16(br); - if(crc != 0) { - printf("FAILED reported CRC 0x%04x does not match expected 0x0000\n", crc); - FLAC__bitreader_dump(br, stdout); - return false; - } - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 16); - FLAC__bitreader_reset_read_crc16(br, 0); - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 32); - crc = FLAC__bitreader_get_read_crc16(br); - if(crc != expected_crcs[1]) { - printf("FAILED reported CRC 0x%04x does not match expected 0x%04x\n", crc, expected_crcs[1]); - FLAC__bitreader_dump(br, stdout); - return false; - } - printf("OK\n"); - - printf("testing unaligned < 32 bit reads... "); - FLAC__bitreader_clear(br); - FLAC__bitreader_skip_bits_no_crc(br, 8); - FLAC__bitreader_reset_read_crc16(br, 0); - ok = - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 1) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 2) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 5) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 8) - ; - if(!ok) { - printf("FAILED\n"); - FLAC__bitreader_dump(br, stdout); - return false; - } - crc = FLAC__bitreader_get_read_crc16(br); - if(crc != expected_crcs[2]) { - printf("FAILED reported CRC 0x%04x does not match expected 0x%04x\n", crc, expected_crcs[2]); - FLAC__bitreader_dump(br, stdout); - return false; - } - printf("OK\n"); - FLAC__bitreader_dump(br, stdout); - - printf("testing unaligned < 64 bit reads... "); - FLAC__bitreader_clear(br); - FLAC__bitreader_skip_bits_no_crc(br, 8); - FLAC__bitreader_reset_read_crc16(br, 0); - ok = - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 1) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 2) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 5) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 8) && - FLAC__bitreader_read_raw_uint32(br, &val_uint32, 32) - ; - if(!ok) { - printf("FAILED\n"); - FLAC__bitreader_dump(br, stdout); - return false; - } - crc = FLAC__bitreader_get_read_crc16(br); - if(crc != expected_crcs[3]) { - printf("FAILED reported CRC 0x%04x does not match expected 0x%04x\n", crc, expected_crcs[3]); - FLAC__bitreader_dump(br, stdout); - return false; - } - printf("OK\n"); - FLAC__bitreader_dump(br, stdout); - - printf("testing free... "); - FLAC__bitreader_free(br); - printf("OK\n"); - - printf("testing delete... "); - FLAC__bitreader_delete(br); - printf("OK\n"); - - printf("\nPASSED!\n"); - return true; -} - -/*----------------------------------------------------------------------------*/ - -static FLAC__bool read_callback(FLAC__byte buffer[], size_t *bytes, void *data) -{ - if (*bytes > 32) - *bytes = 32; - - memcpy(buffer, data, *bytes); - - return true; -} diff --git a/flac/src/test_libFLAC/bitreader.h b/flac/src/test_libFLAC/bitreader.h deleted file mode 100644 index f497acf..0000000 --- a/flac/src/test_libFLAC/bitreader.h +++ /dev/null @@ -1,27 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLAC_BITREADER_H -#define FLAC__TEST_LIBFLAC_BITREADER_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_bitreader(void); - -#endif diff --git a/flac/src/test_libFLAC/bitwriter.c b/flac/src/test_libFLAC/bitwriter.c deleted file mode 100644 index 0aafff2..0000000 --- a/flac/src/test_libFLAC/bitwriter.c +++ /dev/null @@ -1,688 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "FLAC/assert.h" -#include "share/compat.h" -#include "private/bitwriter.h" /* from the libFLAC private include area */ -#include "bitwriter.h" -#include -#include /* for memcmp() */ - -/* - * WATCHOUT! Since FLAC__BitWriter is a private structure, we use a copy of - * the definition here to get at the internals. Make sure this is kept up - * to date with what is in ../libFLAC/bitwriter.c - */ -#if (ENABLE_64_BIT_WORDS == 0) - -typedef FLAC__uint32 bwword; -#define FLAC__BYTES_PER_WORD 4 -#define FLAC__BITS_PER_WORD 32 -#define PRI_BWWORD "08x" - -#else - -typedef FLAC__uint64 bwword; -#define FLAC__BYTES_PER_WORD 8 -#define FLAC__BITS_PER_WORD 64 -#define PRI_BWWORD "016" PRIx64 - -#endif - -struct FLAC__BitWriter { - bwword *buffer; - bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */ - uint32_t capacity; /* capacity of buffer in words */ - uint32_t words; /* # of complete words in buffer */ - uint32_t bits; /* # of used bits in accum */ -}; - -#define WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD) -#define TOTAL_BITS(bw) (WORDS_TO_BITS((bw)->words) + (bw)->bits) - -static void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out) -{ - uint32_t i, j; - if(bw == 0) { - fprintf(out, "bitwriter is NULL\n"); - } - else { - fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, TOTAL_BITS(bw)); - - for(i = 0; i < bw->words; i++) { - fprintf(out, "%08X: ", i); - for(j = 0; j < FLAC__BITS_PER_WORD; j++) - fprintf(out, "%01d", bw->buffer[i] & ((bwword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0); - fprintf(out, "\n"); - } - if(bw->bits > 0) { - fprintf(out, "%08X: ", i); - for(j = 0; j < bw->bits; j++) - fprintf(out, "%01d", bw->accum & ((bwword)1 << (bw->bits-j-1)) ? 1:0); - fprintf(out, "\n"); - } - } -} - -FLAC__bool test_bitwriter(void) -{ - FLAC__BitWriter *bw; - FLAC__bool ok; - uint32_t i, j; -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - static bwword test_pattern1[5] = { 0xaaf0aabe, 0xaaaaaaa8, 0x300aaaaa, 0xaaadeadb, 0x00eeface }; -#else - static bwword test_pattern1[5] = { 0xbeaaf0aa, 0xa8aaaaaa, 0xaaaa0a30, 0xdbeaadaa, 0x00eeface }; -#endif -#elif FLAC__BYTES_PER_WORD == 8 -#if WORDS_BIGENDIAN - static bwword test_pattern1[3] = { FLAC__U64L(0xaaf0aabeaaaaaaa8), FLAC__U64L(0x300aaaaaaaadeadb), FLAC__U64L(0x0000000000eeface) }; -#else - static bwword test_pattern1[3] = { FLAC__U64L(0xa8aaaaaabeaaf0aa), FLAC__U64L(0xdbeaadaaaaaa0a30), FLAC__U64L(0x0000000000eeface) }; -#endif -#else -#error FLAC__BYTES_PER_WORD is neither 4 nor 8 -- not implemented -#endif - uint32_t words, bits; /* what we think bw->words and bw->bits should be */ - - printf("\n+++ libFLAC unit test: bitwriter\n\n"); - - /* - * test new -> delete - */ - printf("testing new... "); - bw = FLAC__bitwriter_new(); - if(0 == bw) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing delete... "); - FLAC__bitwriter_delete(bw); - printf("OK\n"); - - /* - * test new -> init -> delete - */ - printf("testing new... "); - bw = FLAC__bitwriter_new(); - if(0 == bw) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing init... "); - if(!FLAC__bitwriter_init(bw)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing delete... "); - FLAC__bitwriter_delete(bw); - printf("OK\n"); - - /* - * test new -> init -> clear -> delete - */ - printf("testing new... "); - bw = FLAC__bitwriter_new(); - if(0 == bw) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing init... "); - if(!FLAC__bitwriter_init(bw)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing clear... "); - FLAC__bitwriter_clear(bw); - printf("OK\n"); - - printf("testing delete... "); - FLAC__bitwriter_delete(bw); - printf("OK\n"); - - /* - * test normal usage - */ - printf("testing new... "); - bw = FLAC__bitwriter_new(); - if(0 == bw) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing init... "); - if(!FLAC__bitwriter_init(bw)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing clear... "); - FLAC__bitwriter_clear(bw); - printf("OK\n"); - - words = bits = 0; - - printf("capacity = %u\n", bw->capacity); - - printf("testing zeroes, raw_uint32*... "); - ok = - FLAC__bitwriter_write_raw_uint32(bw, 0x1, 1) && - FLAC__bitwriter_write_raw_uint32(bw, 0x1, 2) && - FLAC__bitwriter_write_raw_uint32(bw, 0xa, 5) && - FLAC__bitwriter_write_raw_uint32(bw, 0xf0, 8) && - FLAC__bitwriter_write_raw_uint32(bw, 0x2aa, 10) && - FLAC__bitwriter_write_raw_uint32(bw, 0xf, 4) && - FLAC__bitwriter_write_raw_uint32(bw, 0xaaaaaaaa, 32) && - FLAC__bitwriter_write_zeroes(bw, 4) && - FLAC__bitwriter_write_raw_uint32(bw, 0x3, 2) && - FLAC__bitwriter_write_zeroes(bw, 8) && - FLAC__bitwriter_write_raw_uint64(bw, FLAC__U64L(0xaaaaaaaadeadbeef), 64) && - FLAC__bitwriter_write_raw_uint32(bw, 0xace, 12) - ; - if(!ok) { - printf("FAILED\n"); - FLAC__bitwriter_dump(bw, stdout); - return false; - } - /* we wrote 152 bits (=19 bytes) to the bitwriter */ - words = 152 / FLAC__BITS_PER_WORD; - bits = 152 - words*FLAC__BITS_PER_WORD; - - if(bw->words != words) { - printf("FAILED word count %u != %u\n", bw->words, words); - FLAC__bitwriter_dump(bw, stdout); - return false; - } - if(bw->bits != bits) { - printf("FAILED bit count %u != %u\n", bw->bits, bits); - FLAC__bitwriter_dump(bw, stdout); - return false; - } - if(memcmp(bw->buffer, test_pattern1, sizeof(bwword)*words) != 0) { - printf("FAILED pattern match (buffer)\n"); - FLAC__bitwriter_dump(bw, stdout); - return false; - } - if((bw->accum & 0x00ffffff) != test_pattern1[words]) { - printf("FAILED pattern match (bw->accum=%" PRI_BWWORD " != %" PRI_BWWORD ")\n", bw->accum&0x00ffffff, test_pattern1[words]); - FLAC__bitwriter_dump(bw, stdout); - return false; - } - printf("OK\n"); - FLAC__bitwriter_dump(bw, stdout); - - printf("testing raw_uint32 some more... "); - ok = FLAC__bitwriter_write_raw_uint32(bw, 0x3d, 6); - if(!ok) { - printf("FAILED\n"); - FLAC__bitwriter_dump(bw, stdout); - return false; - } - bits += 6; - test_pattern1[words] <<= 6; - test_pattern1[words] |= 0x3d; - if(bw->words != words) { - printf("FAILED word count %u != %u\n", bw->words, words); - FLAC__bitwriter_dump(bw, stdout); - return false; - } - if(bw->bits != bits) { - printf("FAILED bit count %u != %u\n", bw->bits, bits); - FLAC__bitwriter_dump(bw, stdout); - return false; - } - if(memcmp(bw->buffer, test_pattern1, sizeof(bwword)*words) != 0) { - printf("FAILED pattern match (buffer)\n"); - FLAC__bitwriter_dump(bw, stdout); - return false; - } - if((bw->accum & 0x3fffffff) != test_pattern1[words]) { - printf("FAILED pattern match (bw->accum=%" PRI_BWWORD " != %" PRI_BWWORD ")\n", bw->accum&0x3fffffff, test_pattern1[words]); - FLAC__bitwriter_dump(bw, stdout); - return false; - } - printf("OK\n"); - FLAC__bitwriter_dump(bw, stdout); - - printf("testing utf8_uint32(0x00000000)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x00000000); - ok = TOTAL_BITS(bw) == 8 && (bw->accum & 0xff) == 0; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x0000007F)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x0000007F); - ok = TOTAL_BITS(bw) == 8 && (bw->accum & 0xff) == 0x7F; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x00000080)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x00000080); - ok = TOTAL_BITS(bw) == 16 && (bw->accum & 0xffff) == 0xC280; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x000007FF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x000007FF); - ok = TOTAL_BITS(bw) == 16 && (bw->accum & 0xffff) == 0xDFBF; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x00000800)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x00000800); - ok = TOTAL_BITS(bw) == 24 && (bw->accum & 0xffffff) == 0xE0A080; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x0000FFFF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x0000FFFF); - ok = TOTAL_BITS(bw) == 24 && (bw->accum & 0xffffff) == 0xEFBFBF; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x00010000)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x00010000); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xF0908080; -#else - ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0x808090F0; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 32 && (bw->accum & 0xffffffff) == 0xF0908080; -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x001FFFFF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x001FFFFF); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xF7BFBFBF; -#else - ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xBFBFBFF7; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 32 && (bw->accum & 0xffffffff) == 0xF7BFBFBF; -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x00200000)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x00200000); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xF8888080 && (bw->accum & 0xff) == 0x80; -#else - ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0x808088F8 && (bw->accum & 0xff) == 0x80; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 40 && (bw->accum & FLAC__U64L(0xffffffffff)) == FLAC__U64L(0xF888808080); -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x03FFFFFF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x03FFFFFF); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xFBBFBFBF && (bw->accum & 0xff) == 0xBF; -#else - ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xBFBFBFFB && (bw->accum & 0xff) == 0xBF; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 40 && (bw->accum & FLAC__U64L(0xffffffffff)) == FLAC__U64L(0xFBBFBFBFBF); -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x04000000)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x04000000); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xFC848080 && (bw->accum & 0xffff) == 0x8080; -#else - ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0x808084FC && (bw->accum & 0xffff) == 0x8080; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 48 && (bw->accum & FLAC__U64L(0xffffffffffff)) == FLAC__U64L(0xFC8480808080); -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint32(0x7FFFFFFF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint32(bw, 0x7FFFFFFF); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xFDBFBFBF && (bw->accum & 0xffff) == 0xBFBF; -#else - ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xBFBFBFFD && (bw->accum & 0xffff) == 0xBFBF; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 48 && (bw->accum & FLAC__U64L(0xffffffffffff)) == FLAC__U64L(0xFDBFBFBFBFBF); -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x0000000000000000)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x0000000000000000)); - ok = TOTAL_BITS(bw) == 8 && (bw->accum & 0xff) == 0; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x000000000000007F)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x000000000000007F)); - ok = TOTAL_BITS(bw) == 8 && (bw->accum & 0xff) == 0x7F; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x0000000000000080)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x0000000000000080)); - ok = TOTAL_BITS(bw) == 16 && (bw->accum & 0xffff) == 0xC280; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x00000000000007FF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x00000000000007FF)); - ok = TOTAL_BITS(bw) == 16 && (bw->accum & 0xffff) == 0xDFBF; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x0000000000000800)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x0000000000000800)); - ok = TOTAL_BITS(bw) == 24 && (bw->accum & 0xffffff) == 0xE0A080; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x000000000000FFFF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x000000000000FFFF)); - ok = TOTAL_BITS(bw) == 24 && (bw->accum & 0xffffff) == 0xEFBFBF; - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x0000000000010000)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x0000000000010000)); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xF0908080; -#else - ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0x808090F0; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 32 && (bw->accum & 0xffffffff) == 0xF0908080; -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x00000000001FFFFF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x00000000001FFFFF)); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xF7BFBFBF; -#else - ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xBFBFBFF7; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 32 && (bw->accum & 0xffffffff) == 0xF7BFBFBF; -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x0000000000200000)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x0000000000200000)); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xF8888080 && (bw->accum & 0xff) == 0x80; -#else - ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0x808088F8 && (bw->accum & 0xff) == 0x80; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 40 && (bw->accum & FLAC__U64L(0xffffffffff)) == FLAC__U64L(0xF888808080); -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x0000000003FFFFFF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x0000000003FFFFFF)); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xFBBFBFBF && (bw->accum & 0xff) == 0xBF; -#else - ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xBFBFBFFB && (bw->accum & 0xff) == 0xBF; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 40 && (bw->accum & FLAC__U64L(0xffffffffff)) == FLAC__U64L(0xFBBFBFBFBF); -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x0000000004000000)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x0000000004000000)); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xFC848080 && (bw->accum & 0xffff) == 0x8080; -#else - ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0x808084FC && (bw->accum & 0xffff) == 0x8080; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 48 && (bw->accum & FLAC__U64L(0xffffffffffff)) == FLAC__U64L(0xFC8480808080); -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x000000007FFFFFFF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x000000007FFFFFFF)); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xFDBFBFBF && (bw->accum & 0xffff) == 0xBFBF; -#else - ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xBFBFBFFD && (bw->accum & 0xffff) == 0xBFBF; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 48 && (bw->accum & FLAC__U64L(0xffffffffffff)) == FLAC__U64L(0xFDBFBFBFBFBF); -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x0000000080000000)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x0000000080000000)); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 56 && bw->buffer[0] == 0xFE828080 && (bw->accum & 0xffffff) == 0x808080; -#else - ok = TOTAL_BITS(bw) == 56 && bw->buffer[0] == 0x808082FE && (bw->accum & 0xffffff) == 0x808080; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 56 && (bw->accum & FLAC__U64L(0xffffffffffffff)) == FLAC__U64L(0xFE828080808080); -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing utf8_uint64(0x0000000FFFFFFFFF)... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x0000000FFFFFFFFF)); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == 56 && bw->buffer[0] == 0xFEBFBFBF && (bw->accum & 0xffffff) == 0xBFBFBF; -#else - ok = TOTAL_BITS(bw) == 56 && bw->buffer[0] == 0xBFBFBFFE && (bw->accum & 0xffffff) == 0xBFBFBF; -#endif -#elif FLAC__BYTES_PER_WORD == 8 - ok = TOTAL_BITS(bw) == 56 && (bw->accum & FLAC__U64L(0xffffffffffffff)) == FLAC__U64L(0xFEBFBFBFBFBFBF); -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - - printf("testing grow... "); - FLAC__bitwriter_clear(bw); - FLAC__bitwriter_write_raw_uint32(bw, 0x5, 4); - j = bw->capacity; - for(i = 0; i < j; i++) - FLAC__bitwriter_write_raw_uint32(bw, 0xaaaaaaaa, 32); -#if FLAC__BYTES_PER_WORD == 4 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == i*32+4 && bw->buffer[0] == 0x5aaaaaaa && (bw->accum & 0xf) == 0xa; -#else - ok = TOTAL_BITS(bw) == i*32+4 && bw->buffer[0] == 0xaaaaaa5a && (bw->accum & 0xf) == 0xa; -#endif -#elif FLAC__BYTES_PER_WORD == 8 -#if WORDS_BIGENDIAN - ok = TOTAL_BITS(bw) == i*32+4 && bw->buffer[0] == FLAC__U64L(0x5aaaaaaaaaaaaaaa) && (bw->accum & 0xf) == 0xa; -#else - ok = TOTAL_BITS(bw) == i*32+4 && bw->buffer[0] == FLAC__U64L(0xaaaaaaaaaaaaaa5a) && (bw->accum & 0xf) == 0xa; -#endif -#endif - printf("%s\n", ok?"OK":"FAILED"); - if(!ok) { - FLAC__bitwriter_dump(bw, stdout); - return false; - } - printf("capacity = %u\n", bw->capacity); - - printf("testing free... "); - FLAC__bitwriter_free(bw); - printf("OK\n"); - - printf("testing delete... "); - FLAC__bitwriter_delete(bw); - printf("OK\n"); - - printf("\nPASSED!\n"); - return true; -} diff --git a/flac/src/test_libFLAC/bitwriter.h b/flac/src/test_libFLAC/bitwriter.h deleted file mode 100644 index 9b6a824..0000000 --- a/flac/src/test_libFLAC/bitwriter.h +++ /dev/null @@ -1,27 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLAC_BITBUFFER_H -#define FLAC__TEST_LIBFLAC_BITBUFFER_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_bitwriter(void); - -#endif diff --git a/flac/src/test_libFLAC/crc.c b/flac/src/test_libFLAC/crc.c deleted file mode 100644 index 8b87671..0000000 --- a/flac/src/test_libFLAC/crc.c +++ /dev/null @@ -1,274 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2014-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include - -#include "FLAC/assert.h" -#include "share/compat.h" -#include "private/crc.h" -#include "crc.h" - -static FLAC__uint8 crc8_update_ref(FLAC__byte byte, FLAC__uint8 crc); -static FLAC__uint16 crc16_update_ref(FLAC__byte byte, FLAC__uint16 crc); - -static FLAC__bool test_crc8(const FLAC__byte *data, size_t size); -static FLAC__bool test_crc16(const FLAC__byte *data, size_t size); -static FLAC__bool test_crc16_update(const FLAC__byte *data, size_t size); -static FLAC__bool test_crc16_32bit_words(const FLAC__uint32 *words, size_t size); -static FLAC__bool test_crc16_64bit_words(const FLAC__uint64 *words, size_t size); - -#define DATA_SIZE 32768 - -FLAC__bool test_crc(void) -{ - uint32_t i; - FLAC__byte data[DATA_SIZE] = { 0 }; - - /* Initialize data reproducibly with pseudo-random values. */ - for (i = 1; i < DATA_SIZE; i++) - data[i] = crc8_update_ref(i % 256, data[i - 1]); - - printf("\n+++ libFLAC unit test: crc\n\n"); - - if (! test_crc8(data, DATA_SIZE)) - return false; - - if (! test_crc16(data, DATA_SIZE)) - return false; - - if (! test_crc16_update(data, DATA_SIZE)) - return false; - - if (! test_crc16_32bit_words((FLAC__uint32 *)data, DATA_SIZE / 4)) - return false; - - if (! test_crc16_64bit_words((FLAC__uint64 *)data, DATA_SIZE / 8)) - return false; - - printf("\nPASSED!\n"); - return true; -} - -/*----------------------------------------------------------------------------*/ - -/* Reference implementations of CRC-8 and CRC-16 to check against. */ - -#define CRC8_POLYNOMIAL 0x07 - -static FLAC__uint8 crc8_update_ref(FLAC__byte byte, FLAC__uint8 crc) -{ - uint32_t i; - - crc ^= byte; - - for (i = 0; i < 8; i++) { - crc = (crc << 1) ^ ((crc >> 7) ? CRC8_POLYNOMIAL : 0); - } - - return crc; -} - -#define CRC16_POLYNOMIAL 0x8005 - -static FLAC__uint16 crc16_update_ref(FLAC__byte byte, FLAC__uint16 crc) -{ - uint32_t i; - - crc ^= byte << 8; - - for (i = 0; i < 8; i++) { - crc = (crc << 1) ^ ((crc >> 15) ? CRC16_POLYNOMIAL : 0); - } - - return crc; -} - -/*----------------------------------------------------------------------------*/ - -static FLAC__bool test_crc8(const FLAC__byte *data, size_t size) -{ - uint32_t i; - FLAC__uint8 crc0,crc1; - - printf("testing FLAC__crc8 ... "); - - crc0 = 0; - crc1 = FLAC__crc8(data, 0); - - if (crc1 != crc0) { - printf("FAILED, FLAC__crc8 returned non-zero CRC for zero bytes of data\n"); - return false; - } - - for (i = 0; i < size; i++) { - crc0 = crc8_update_ref(data[i], crc0); - crc1 = FLAC__crc8(data, i + 1); - - if (crc1 != crc0) { - printf("FAILED, FLAC__crc8 result did not match reference CRC for %u bytes of test data\n", i + 1); - return false; - } - } - - printf("OK\n"); - - return true; -} - -static FLAC__bool test_crc16(const FLAC__byte *data, size_t size) -{ - uint32_t i; - FLAC__uint16 crc0,crc1; - - printf("testing FLAC__crc16 ... "); - - crc0 = 0; - crc1 = FLAC__crc16(data, 0); - - if (crc1 != crc0) { - printf("FAILED, FLAC__crc16 returned non-zero CRC for zero bytes of data\n"); - return false; - } - - for (i = 0; i < size; i++) { - crc0 = crc16_update_ref(data[i], crc0); - crc1 = FLAC__crc16(data, i + 1); - - if (crc1 != crc0) { - printf("FAILED, FLAC__crc16 result did not match reference CRC for %u bytes of test data\n", i + 1); - return false; - } - } - - printf("OK\n"); - - return true; -} - -static FLAC__bool test_crc16_update(const FLAC__byte *data, size_t size) -{ - uint32_t i; - FLAC__uint16 crc0,crc1; - - printf("testing FLAC__CRC16_UPDATE macro ... "); - - crc0 = 0; - crc1 = 0; - - for (i = 0; i < size; i++) { - crc0 = crc16_update_ref(data[i], crc0); - crc1 = FLAC__CRC16_UPDATE(data[i], crc1); - - if (crc1 != crc0) { - printf("FAILED, FLAC__CRC16_UPDATE result did not match reference CRC after %u bytes of test data\n", i + 1); - return false; - } - } - - printf("OK\n"); - - return true; -} - -static FLAC__bool test_crc16_32bit_words(const FLAC__uint32 *words, size_t size) -{ - uint32_t n,i,k; - FLAC__uint16 crc0,crc1; - - for (n = 1; n <= 16; n++) { - printf("testing FLAC__crc16_update_words32 (length=%i) ... ", n); - - crc0 = 0; - crc1 = 0; - - for (i = 0; i <= size - n; i += n) { - for (k = 0; k < n; k++) { - crc0 = crc16_update_ref( words[i + k] >> 24, crc0); - crc0 = crc16_update_ref((words[i + k] >> 16) & 0xFF, crc0); - crc0 = crc16_update_ref((words[i + k] >> 8) & 0xFF, crc0); - crc0 = crc16_update_ref( words[i + k] & 0xFF, crc0); - } - - crc1 = FLAC__crc16_update_words32(words + i, n, crc1); - - if (crc1 != crc0) { - printf("FAILED, FLAC__crc16_update_words32 result did not match reference CRC after %u words of test data\n", i + n); - return false; - } - } - - crc1 = FLAC__crc16_update_words32(words, 0, crc1); - - if (crc1 != crc0) { - printf("FAILED, FLAC__crc16_update_words32 called with zero bytes changed CRC value\n"); - return false; - } - - printf("OK\n"); - } - - return true; -} - -static FLAC__bool test_crc16_64bit_words(const FLAC__uint64 *words, size_t size) -{ - uint32_t n,i,k; - FLAC__uint16 crc0,crc1; - - for (n = 1; n <= 16; n++) { - printf("testing FLAC__crc16_update_words64 (length=%i) ... ", n); - - crc0 = 0; - crc1 = 0; - - for (i = 0; i <= size - n; i += n) { - for (k = 0; k < n; k++) { - crc0 = crc16_update_ref( words[i + k] >> 56, crc0); - crc0 = crc16_update_ref((words[i + k] >> 48) & 0xFF, crc0); - crc0 = crc16_update_ref((words[i + k] >> 40) & 0xFF, crc0); - crc0 = crc16_update_ref((words[i + k] >> 32) & 0xFF, crc0); - crc0 = crc16_update_ref((words[i + k] >> 24) & 0xFF, crc0); - crc0 = crc16_update_ref((words[i + k] >> 16) & 0xFF, crc0); - crc0 = crc16_update_ref((words[i + k] >> 8) & 0xFF, crc0); - crc0 = crc16_update_ref( words[i + k] & 0xFF, crc0); - } - - crc1 = FLAC__crc16_update_words64(words + i, n, crc1); - - if (crc1 != crc0) { - printf("FAILED, FLAC__crc16_update_words64 result did not match reference CRC after %u words of test data\n", i + n); - return false; - } - } - - crc1 = FLAC__crc16_update_words64(words, 0, crc1); - - if (crc1 != crc0) { - printf("FAILED, FLAC__crc16_update_words64 called with zero bytes changed CRC value\n"); - return false; - } - - printf("OK\n"); - } - - return true; -} diff --git a/flac/src/test_libFLAC/crc.h b/flac/src/test_libFLAC/crc.h deleted file mode 100644 index 11523cd..0000000 --- a/flac/src/test_libFLAC/crc.h +++ /dev/null @@ -1,26 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2014-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLAC_CRC_H -#define FLAC__TEST_LIBFLAC_CRC_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_crc(void); - -#endif diff --git a/flac/src/test_libFLAC/decoders.c b/flac/src/test_libFLAC/decoders.c deleted file mode 100644 index ae114ce..0000000 --- a/flac/src/test_libFLAC/decoders.c +++ /dev/null @@ -1,1054 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include "decoders.h" -#include "FLAC/assert.h" -#include "FLAC/stream_decoder.h" -#include "share/grabbag.h" -#include "share/compat.h" -#include "share/safe_str.h" -#include "test_libs_common/file_utils_flac.h" -#include "test_libs_common/metadata_utils.h" - -typedef enum { - LAYER_STREAM = 0, /* FLAC__stream_decoder_init_[ogg_]stream() without seeking */ - LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_[ogg_]stream() with seeking */ - LAYER_FILE, /* FLAC__stream_decoder_init_[ogg_]FILE() */ - LAYER_FILENAME /* FLAC__stream_decoder_init_[ogg_]file() */ -} Layer; - -static const char * const LayerString[] = { - "Stream", - "Seekable Stream", - "FILE*", - "Filename" -}; - -typedef struct { - Layer layer; - FILE *file; - char filename[512]; - uint32_t current_metadata_number; - FLAC__bool ignore_errors; - FLAC__bool error_occurred; -} StreamDecoderClientData; - -static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; -static FLAC__StreamMetadata *expected_metadata_sequence_[9]; -static uint32_t num_expected_; -static FLAC__off_t flacfilesize_; - -static const char *flacfilename(FLAC__bool is_ogg) -{ - return is_ogg? "metadata.oga" : "metadata.flac"; -} - -static FLAC__bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static FLAC__bool die_s_(const char *msg, const FLAC__StreamDecoder *decoder) -{ - FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(decoder); - - if(msg) - printf("FAILED, %s", msg); - else - printf("FAILED"); - - printf(", state = %u (%s)\n", (uint32_t)state, FLAC__StreamDecoderStateString[state]); - - return false; -} - -static void open_test_file(StreamDecoderClientData * pdcd, int is_ogg, const char * mode) -{ - pdcd->file = flac_fopen(flacfilename(is_ogg), mode); - safe_strncpy(pdcd->filename, flacfilename(is_ogg), sizeof (pdcd->filename)); -} - -static void init_metadata_blocks_(void) -{ - mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static void free_metadata_blocks_(void) -{ - mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static FLAC__bool generate_file_(FLAC__bool is_ogg) -{ - printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg? "Ogg ":""); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - /* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */ - - if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_)) - return die_("creating the encoded file"); - - return true; -} - -static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - const size_t requested_bytes = *bytes; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in read callback is NULL\n"); - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - - if(feof(dcd->file)) { - *bytes = 0; - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - } - else if(requested_bytes > 0) { - *bytes = fread(buffer, 1, requested_bytes, dcd->file); - if(*bytes == 0) { - if(feof(dcd->file)) - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - else - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - } - else { - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - } - else - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */ -} - -static FLAC__StreamDecoderSeekStatus stream_decoder_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in seek callback is NULL\n"); - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - - if(fseeko(dcd->file, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0) { - dcd->error_occurred = true; - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - } - - return FLAC__STREAM_DECODER_SEEK_STATUS_OK; -} - -static FLAC__StreamDecoderTellStatus stream_decoder_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - FLAC__off_t offset; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in tell callback is NULL\n"); - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - - offset = ftello(dcd->file); - *absolute_byte_offset = (FLAC__uint64)offset; - - if(offset < 0) { - dcd->error_occurred = true; - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - } - - return FLAC__STREAM_DECODER_TELL_STATUS_OK; -} - -static FLAC__StreamDecoderLengthStatus stream_decoder_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in length callback is NULL\n"); - return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - - *stream_length = (FLAC__uint64)flacfilesize_; - return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; -} - -static FLAC__bool stream_decoder_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in eof callback is NULL\n"); - return true; - } - - if(dcd->error_occurred) - return true; - - return feof(dcd->file); -} - -static FLAC__StreamDecoderWriteStatus stream_decoder_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder, (void)buffer; - - if(0 == dcd) { - printf("ERROR: client_data in write callback is NULL\n"); - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - - if( - (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) || - (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0) - ) { - printf("content... "); - fflush(stdout); - } - - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -static void stream_decoder_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in metadata callback is NULL\n"); - return; - } - - if(dcd->error_occurred) - return; - - if (metadata->type == FLAC__METADATA_TYPE_APPLICATION) { - printf ("%u ('%c%c%c%c')... ", dcd->current_metadata_number, metadata->data.application.id [0], metadata->data.application.id [1], metadata->data.application.id [2], metadata->data.application.id [3]); - } - else { - printf("%u... ", dcd->current_metadata_number); - } - fflush(stdout); - - - if(dcd->current_metadata_number >= num_expected_) { - (void)die_("got more metadata blocks than expected"); - dcd->error_occurred = true; - } - else { - if(!mutils__compare_block(expected_metadata_sequence_[dcd->current_metadata_number], metadata)) { - (void)die_("metadata block mismatch"); - dcd->error_occurred = true; - } - } - dcd->current_metadata_number++; -} - -static void stream_decoder_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in error callback is NULL\n"); - return; - } - - if(!dcd->ignore_errors) { - printf("ERROR: got error callback: err = %u (%s)\n", (uint32_t)status, FLAC__StreamDecoderErrorStatusString[status]); - dcd->error_occurred = true; - } -} - -static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, StreamDecoderClientData *dcd, FLAC__bool is_ogg) -{ - FLAC__StreamDecoderInitStatus init_status; - - if(!FLAC__stream_decoder_set_md5_checking(decoder, true)) - return die_s_("at FLAC__stream_decoder_set_md5_checking(), returned false", decoder); - - /* for FLAC__stream_encoder_init_FILE(), the FLAC__stream_encoder_finish() closes the file so we have to keep re-opening: */ - if(dcd->layer == LAYER_FILE) { - printf("opening %sFLAC file... ", is_ogg? "Ogg ":""); - open_test_file(dcd, is_ogg, "rb"); - if(0 == dcd->file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - } - - switch(dcd->layer) { - case LAYER_STREAM: - printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) : - FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) - ; - break; - case LAYER_SEEKABLE_STREAM: - printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) : - FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); - break; - case LAYER_FILE: - printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) : - FLAC__stream_decoder_init_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); - break; - case LAYER_FILENAME: - printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) : - FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); - break; - default: - die_("internal error 000"); - return false; - } - if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - printf("OK\n"); - - dcd->current_metadata_number = 0; - - if(dcd->layer < LAYER_FILE && fseeko(dcd->file, 0, SEEK_SET) < 0) { - printf("FAILED rewinding input, errno = %d\n", errno); - return false; - } - - printf("testing FLAC__stream_decoder_process_until_end_of_stream()... "); - if(!FLAC__stream_decoder_process_until_end_of_stream(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_finish()... "); - if(!FLAC__stream_decoder_finish(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - return true; -} - -static FLAC__bool test_stream_decoder(Layer layer, FLAC__bool is_ogg) -{ - FLAC__StreamDecoder *decoder; - FLAC__StreamDecoderInitStatus init_status; - FLAC__StreamDecoderState state; - StreamDecoderClientData decoder_client_data; - FLAC__bool expect; - - decoder_client_data.layer = layer; - - printf("\n+++ libFLAC unit test: FLAC__StreamDecoder (layer: %s, format: %s)\n\n", LayerString[layer], is_ogg? "Ogg FLAC" : "FLAC"); - - printf("testing FLAC__stream_decoder_new()... "); - decoder = FLAC__stream_decoder_new(); - if(0 == decoder) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_decoder_delete()... "); - FLAC__stream_decoder_delete(decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_new()... "); - decoder = FLAC__stream_decoder_new(); - if(0 == decoder) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - switch(layer) { - case LAYER_STREAM: - case LAYER_SEEKABLE_STREAM: - printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0) : - FLAC__stream_decoder_init_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0); - break; - case LAYER_FILE: - printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_FILE(decoder, stdin, 0, 0, 0, 0) : - FLAC__stream_decoder_init_FILE(decoder, stdin, 0, 0, 0, 0); - break; - case LAYER_FILENAME: - printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), 0, 0, 0, 0) : - FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), 0, 0, 0, 0); - break; - default: - die_("internal error 003"); - return false; - } - if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS) - return die_s_(0, decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_delete()... "); - FLAC__stream_decoder_delete(decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - - printf("testing FLAC__stream_decoder_new()... "); - decoder = FLAC__stream_decoder_new(); - if(0 == decoder) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - if(is_ogg) { - printf("testing FLAC__stream_decoder_set_ogg_serial_number()... "); - if(!FLAC__stream_decoder_set_ogg_serial_number(decoder, file_utils__ogg_serial_number)) - return die_s_("returned false", decoder); - printf("OK\n"); - } - - printf("testing FLAC__stream_decoder_set_md5_checking()... "); - if(!FLAC__stream_decoder_set_md5_checking(decoder, true)) - return die_s_("returned false", decoder); - printf("OK\n"); - - if(layer < LAYER_FILENAME) { - printf("opening %sFLAC file... ", is_ogg? "Ogg ":""); - open_test_file(&decoder_client_data, is_ogg, "rb"); - if(0 == decoder_client_data.file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - } - - switch(layer) { - case LAYER_STREAM: - printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) : - FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data); - break; - case LAYER_SEEKABLE_STREAM: - printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) : - FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data); - break; - case LAYER_FILE: - printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) : - FLAC__stream_decoder_init_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data); - break; - case LAYER_FILENAME: - printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) : - FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data); - break; - default: - die_("internal error 009"); - return false; - } - if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_get_state()... "); - state = FLAC__stream_decoder_get_state(decoder); - printf("returned state = %u (%s)... OK\n", state, FLAC__StreamDecoderStateString[state]); - - decoder_client_data.current_metadata_number = 0; - decoder_client_data.ignore_errors = false; - decoder_client_data.error_occurred = false; - - printf("testing FLAC__stream_decoder_get_md5_checking()... "); - if(!FLAC__stream_decoder_get_md5_checking(decoder)) { - printf("FAILED, returned false, expected true\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_decoder_process_until_end_of_metadata()... "); - if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_process_single()... "); - if(!FLAC__stream_decoder_process_single(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_skip_single_frame()... "); - if(!FLAC__stream_decoder_skip_single_frame(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - if(layer < LAYER_FILE) { - printf("testing FLAC__stream_decoder_flush()... "); - if(!FLAC__stream_decoder_flush(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - decoder_client_data.ignore_errors = true; - printf("testing FLAC__stream_decoder_process_single()... "); - if(!FLAC__stream_decoder_process_single(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - decoder_client_data.ignore_errors = false; - } - - expect = (layer != LAYER_STREAM); - printf("testing FLAC__stream_decoder_seek_absolute()... "); - if(FLAC__stream_decoder_seek_absolute(decoder, 0) != expect) - return die_s_(expect? "returned false" : "returned true", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_process_until_end_of_stream()... "); - if(!FLAC__stream_decoder_process_until_end_of_stream(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - expect = (layer != LAYER_STREAM); - printf("testing FLAC__stream_decoder_seek_absolute()... "); - if(FLAC__stream_decoder_seek_absolute(decoder, 0) != expect) - return die_s_(expect? "returned false" : "returned true", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_get_channels()... "); - { - uint32_t channels = FLAC__stream_decoder_get_channels(decoder); - if(channels != streaminfo_.data.stream_info.channels) { - printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels); - return false; - } - } - printf("OK\n"); - - printf("testing FLAC__stream_decoder_get_bits_per_sample()... "); - { - uint32_t bits_per_sample = FLAC__stream_decoder_get_bits_per_sample(decoder); - if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) { - printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample); - return false; - } - } - printf("OK\n"); - - printf("testing FLAC__stream_decoder_get_sample_rate()... "); - { - uint32_t sample_rate = FLAC__stream_decoder_get_sample_rate(decoder); - if(sample_rate != streaminfo_.data.stream_info.sample_rate) { - printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate); - return false; - } - } - printf("OK\n"); - - printf("testing FLAC__stream_decoder_get_blocksize()... "); - { - uint32_t blocksize = FLAC__stream_decoder_get_blocksize(decoder); - /* value could be anything since we're at the last block, so accept any reasonable answer */ - printf("returned %u... %s\n", blocksize, blocksize>0? "OK" : "FAILED"); - if(blocksize == 0) - return false; - } - - printf("testing FLAC__stream_decoder_get_channel_assignment()... "); - { - FLAC__ChannelAssignment ca = FLAC__stream_decoder_get_channel_assignment(decoder); - printf("returned %u (%s)... OK\n", (uint32_t)ca, FLAC__ChannelAssignmentString[ca]); - } - - if(layer < LAYER_FILE) { - printf("testing FLAC__stream_decoder_reset()... "); - if(!FLAC__stream_decoder_reset(decoder)) { - state = FLAC__stream_decoder_get_state(decoder); - printf("FAILED, returned false, state = %u (%s)\n", state, FLAC__StreamDecoderStateString[state]); - return false; - } - printf("OK\n"); - - if(layer == LAYER_STREAM) { - /* after a reset() we have to rewind the input ourselves */ - printf("rewinding input... "); - if(fseeko(decoder_client_data.file, 0, SEEK_SET) < 0) { - printf("FAILED, errno = %d\n", errno); - return false; - } - printf("OK\n"); - } - - decoder_client_data.current_metadata_number = 0; - - printf("testing FLAC__stream_decoder_process_until_end_of_stream()... "); - if(!FLAC__stream_decoder_process_until_end_of_stream(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - } - - printf("testing FLAC__stream_decoder_finish()... "); - if(!FLAC__stream_decoder_finish(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - /* - * respond all - */ - - printf("testing FLAC__stream_decoder_set_metadata_respond_all()... "); - if(!FLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */ - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - else { - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * ignore all - */ - - printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * respond all, ignore VORBIS_COMMENT - */ - - printf("testing FLAC__stream_decoder_set_metadata_respond_all()... "); - if(!FLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_ignore(VORBIS_COMMENT)... "); - if(!FLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - if(!is_ogg) /* encoder removes seektable for ogg */ - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * respond all, ignore APPLICATION - */ - - printf("testing FLAC__stream_decoder_set_metadata_respond_all()... "); - if(!FLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_ignore(APPLICATION)... "); - if(!FLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */ - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - else { - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * respond all, ignore APPLICATION id of app#1 - */ - - printf("testing FLAC__stream_decoder_set_metadata_respond_all()... "); - if(!FLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... "); - if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */ - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - else { - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * respond all, ignore APPLICATION id of app#1 & app#2 - */ - - printf("testing FLAC__stream_decoder_set_metadata_respond_all()... "); - if(!FLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... "); - if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #2)... "); - if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application2_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */ - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - else { - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * ignore all, respond VORBIS_COMMENT - */ - - printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_respond(VORBIS_COMMENT)... "); - if(!FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * ignore all, respond APPLICATION - */ - - printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_respond(APPLICATION)... "); - if(!FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * ignore all, respond APPLICATION id of app#1 - */ - - printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #1)... "); - if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * ignore all, respond APPLICATION id of app#1 & app#2 - */ - - printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #1)... "); - if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #2)... "); - if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application2_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * respond all, ignore APPLICATION, respond APPLICATION id of app#1 - */ - - printf("testing FLAC__stream_decoder_set_metadata_respond_all()... "); - if(!FLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_ignore(APPLICATION)... "); - if(!FLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #1)... "); - if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */ - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - else { - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - } - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - /* - * ignore all, respond APPLICATION, ignore APPLICATION id of app#1 - */ - - printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_respond(APPLICATION)... "); - if(!FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... "); - if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) - return false; - - if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */ - fclose(decoder_client_data.file); - - printf("testing FLAC__stream_decoder_delete()... "); - FLAC__stream_decoder_delete(decoder); - printf("OK\n"); - - printf("\nPASSED!\n"); - - return true; -} - -FLAC__bool test_decoders(void) -{ - FLAC__bool is_ogg = false; - - while(1) { - init_metadata_blocks_(); - - if(!generate_file_(is_ogg)) - return false; - - if(!test_stream_decoder(LAYER_STREAM, is_ogg)) - return false; - - if(!test_stream_decoder(LAYER_SEEKABLE_STREAM, is_ogg)) - return false; - - if(!test_stream_decoder(LAYER_FILE, is_ogg)) - return false; - - if(!test_stream_decoder(LAYER_FILENAME, is_ogg)) - return false; - - (void) grabbag__file_remove_file(flacfilename(is_ogg)); - - free_metadata_blocks_(); - - if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg) - break; - is_ogg = true; - } - - return true; -} diff --git a/flac/src/test_libFLAC/decoders.h b/flac/src/test_libFLAC/decoders.h deleted file mode 100644 index 431eb17..0000000 --- a/flac/src/test_libFLAC/decoders.h +++ /dev/null @@ -1,27 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLAC_DECODERS_H -#define FLAC__TEST_LIBFLAC_DECODERS_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_decoders(void); - -#endif diff --git a/flac/src/test_libFLAC/encoders.c b/flac/src/test_libFLAC/encoders.c deleted file mode 100644 index d3fd39d..0000000 --- a/flac/src/test_libFLAC/encoders.c +++ /dev/null @@ -1,530 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include "encoders.h" -#include "FLAC/assert.h" -#include "FLAC/stream_encoder.h" -#include "share/grabbag.h" -#include "share/compat.h" -#include "test_libs_common/file_utils_flac.h" -#include "test_libs_common/metadata_utils.h" - -typedef enum { - LAYER_STREAM = 0, /* FLAC__stream_encoder_init_[ogg_]stream() without seeking */ - LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_[ogg_]stream() with seeking */ - LAYER_FILE, /* FLAC__stream_encoder_init_[ogg_]FILE() */ - LAYER_FILENAME /* FLAC__stream_encoder_init_[ogg_]file() */ -} Layer; - -static const char * const LayerString[] = { - "Stream", - "Seekable Stream", - "FILE*", - "Filename" -}; - -static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; -static FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ }; -static const uint32_t num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]); - -static const char *flacfilename(FLAC__bool is_ogg) -{ - return is_ogg? "metadata.oga" : "metadata.flac"; -} - -static FLAC__bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder) -{ - FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder); - - if(msg) - printf("FAILED, %s", msg); - else - printf("FAILED"); - - printf(", state = %u (%s)\n", (uint32_t)state, FLAC__StreamEncoderStateString[state]); - if(state == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) { - FLAC__StreamDecoderState dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder); - printf(" verify decoder state = %u (%s)\n", (uint32_t)dstate, FLAC__StreamDecoderStateString[dstate]); - } - - return false; -} - -static void init_metadata_blocks_(void) -{ - mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static void free_metadata_blocks_(void) -{ - mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static FLAC__StreamEncoderReadStatus stream_encoder_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data) -{ - FILE *f = (FILE*)client_data; - (void)encoder; - if(*bytes > 0) { - *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, f); - if(ferror(f)) - return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; - else if(*bytes == 0) - return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM; - else - return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; - } - else - return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; -} - -static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data) -{ - FILE *f = (FILE*)client_data; - (void)encoder, (void)samples, (void)current_frame; - if(fwrite(buffer, 1, bytes, f) != bytes) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - else - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; -} - -static FLAC__StreamEncoderSeekStatus stream_encoder_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) -{ - FILE *f = (FILE*)client_data; - (void)encoder; - if(fseeko(f, (long)absolute_byte_offset, SEEK_SET) < 0) - return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR; - else - return FLAC__STREAM_ENCODER_SEEK_STATUS_OK; -} - -static FLAC__StreamEncoderTellStatus stream_encoder_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) -{ - FILE *f = (FILE*)client_data; - FLAC__off_t pos; - (void)encoder; - if((pos = ftello(f)) < 0) - return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR; - else { - *absolute_byte_offset = (FLAC__uint64)pos; - return FLAC__STREAM_ENCODER_TELL_STATUS_OK; - } -} - -static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - (void)encoder, (void)metadata, (void)client_data; -} - -static void stream_encoder_progress_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate, void *client_data) -{ - (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data; -} - -static FLAC__bool test_stream_encoder(Layer layer, FLAC__bool is_ogg) -{ - FLAC__StreamEncoder *encoder; - FLAC__StreamEncoderInitStatus init_status; - FLAC__StreamEncoderState state; - FLAC__StreamDecoderState dstate; - FILE *file = 0; - FLAC__int32 samples[1024]; - FLAC__int32 *samples_array[1]; - uint32_t i; - - samples_array[0] = samples; - - printf("\n+++ libFLAC unit test: FLAC__StreamEncoder (layer: %s, format: %s)\n\n", LayerString[layer], is_ogg? "Ogg FLAC":"FLAC"); - - printf("testing FLAC__stream_encoder_new()... "); - encoder = FLAC__stream_encoder_new(); - if(0 == encoder) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - if(is_ogg) { - printf("testing FLAC__stream_encoder_set_ogg_serial_number()... "); - if(!FLAC__stream_encoder_set_ogg_serial_number(encoder, file_utils__ogg_serial_number)) - return die_s_("returned false", encoder); - printf("OK\n"); - } - - printf("testing FLAC__stream_encoder_set_verify()... "); - if(!FLAC__stream_encoder_set_verify(encoder, true)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_streamable_subset()... "); - if(!FLAC__stream_encoder_set_streamable_subset(encoder, true)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_channels()... "); - if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_bits_per_sample()... "); - if(!FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_sample_rate()... "); - if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_compression_level()... "); - if(!FLAC__stream_encoder_set_compression_level(encoder, (uint32_t)(-1))) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_blocksize()... "); - if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... "); - if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... "); - if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_max_lpc_order()... "); - if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... "); - if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... "); - if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_do_escape_coding()... "); - if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... "); - if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... "); - if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... "); - if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... "); - if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_total_samples_estimate()... "); - if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_metadata()... "); - if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_set_limit_min_bitrate()... "); - if(!FLAC__stream_encoder_set_limit_min_bitrate(encoder, true)) - return die_s_("returned false", encoder); - printf("OK\n"); - - if(layer < LAYER_FILENAME) { - printf("opening file for FLAC output... "); - file = flac_fopen(flacfilename(is_ogg), "w+b"); - if(0 == file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - } - - switch(layer) { - case LAYER_STREAM: - printf("testing FLAC__stream_encoder_init_%sstream()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_encoder_init_ogg_stream(encoder, /*read_callback=*/0, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/file) : - FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/file); - break; - case LAYER_SEEKABLE_STREAM: - printf("testing FLAC__stream_encoder_init_%sstream()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_encoder_init_ogg_stream(encoder, stream_encoder_read_callback_, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/file) : - FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/file); - break; - case LAYER_FILE: - printf("testing FLAC__stream_encoder_init_%sFILE()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_encoder_init_ogg_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0) : - FLAC__stream_encoder_init_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0); - break; - case LAYER_FILENAME: - printf("testing FLAC__stream_encoder_init_%sfile()... ", is_ogg? "ogg_":""); - init_status = is_ogg? - FLAC__stream_encoder_init_ogg_file(encoder, flacfilename(is_ogg), stream_encoder_progress_callback_, /*client_data=*/0) : - FLAC__stream_encoder_init_file(encoder, flacfilename(is_ogg), stream_encoder_progress_callback_, /*client_data=*/0); - break; - default: - die_("internal error 001"); - return false; - } - if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_state()... "); - state = FLAC__stream_encoder_get_state(encoder); - printf("returned state = %u (%s)... OK\n", (uint32_t)state, FLAC__StreamEncoderStateString[state]); - - printf("testing FLAC__stream_encoder_get_verify_decoder_state()... "); - dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder); - printf("returned state = %u (%s)... OK\n", (uint32_t)dstate, FLAC__StreamDecoderStateString[dstate]); - - { - FLAC__uint64 absolute_sample; - uint32_t frame_number; - uint32_t channel; - uint32_t sample; - FLAC__int32 expected; - FLAC__int32 got; - - printf("testing FLAC__stream_encoder_get_verify_decoder_error_stats()... "); - FLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got); - printf("OK\n"); - } - - printf("testing FLAC__stream_encoder_get_verify()... "); - if(FLAC__stream_encoder_get_verify(encoder) != true) { - printf("FAILED, expected true, got false\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_streamable_subset()... "); - if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) { - printf("FAILED, expected true, got false\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... "); - if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... "); - if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_channels()... "); - if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder)); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_bits_per_sample()... "); - if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder)); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_sample_rate()... "); - if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder)); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_blocksize()... "); - if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder)); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_max_lpc_order()... "); - if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) { - printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder)); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... "); - (void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder); - /* we asked the encoder to auto select this so we accept anything */ - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... "); - if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_do_escape_coding()... "); - if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... "); - if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... "); - if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) { - printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder)); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... "); - if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) { - printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder)); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... "); - if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) { - printf("FAILED, expected %d, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder)); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_total_samples_estimate()... "); - if(FLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) { - printf("FAILED, expected %" PRIu64 ", got %" PRIu64 "\n", streaminfo_.data.stream_info.total_samples, FLAC__stream_encoder_get_total_samples_estimate(encoder)); - return false; - } - printf("OK\n"); - - printf("testing FLAC__stream_encoder_get_limit_min_bitrate()... "); - if(FLAC__stream_encoder_get_limit_min_bitrate(encoder) != true) { - printf("FAILED, expected true, got false\n"); - return false; - } - - /* init the dummy sample buffer */ - for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++) - samples[i] = i & 7; - - printf("testing FLAC__stream_encoder_process()... "); - if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32))) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_process_interleaved()... "); - if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32))) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing FLAC__stream_encoder_finish()... "); - if(!FLAC__stream_encoder_finish(encoder)) - return die_s_("returned false", encoder); - printf("OK\n"); - - if(layer < LAYER_FILE) - fclose(file); - - printf("testing FLAC__stream_encoder_delete()... "); - FLAC__stream_encoder_delete(encoder); - printf("OK\n"); - - printf("\nPASSED!\n"); - - return true; -} - -FLAC__bool test_encoders(void) -{ - FLAC__bool is_ogg = false; - - while(1) { - init_metadata_blocks_(); - - if(!test_stream_encoder(LAYER_STREAM, is_ogg)) - return false; - - if(!test_stream_encoder(LAYER_SEEKABLE_STREAM, is_ogg)) - return false; - - if(!test_stream_encoder(LAYER_FILE, is_ogg)) - return false; - - if(!test_stream_encoder(LAYER_FILENAME, is_ogg)) - return false; - - (void) grabbag__file_remove_file(flacfilename(is_ogg)); - - free_metadata_blocks_(); - - if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg) - break; - is_ogg = true; - } - - return true; -} diff --git a/flac/src/test_libFLAC/encoders.h b/flac/src/test_libFLAC/encoders.h deleted file mode 100644 index 7bdcaf5..0000000 --- a/flac/src/test_libFLAC/encoders.h +++ /dev/null @@ -1,27 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLAC_ENCODERS_H -#define FLAC__TEST_LIBFLAC_ENCODERS_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_encoders(void); - -#endif diff --git a/flac/src/test_libFLAC/endswap.c b/flac/src/test_libFLAC/endswap.c deleted file mode 100644 index 808f81f..0000000 --- a/flac/src/test_libFLAC/endswap.c +++ /dev/null @@ -1,111 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2014-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include "share/compat.h" -#include "FLAC/assert.h" -#include "share/endswap.h" -#include "private/md5.h" -#include "endswap.h" - - -FLAC__bool test_endswap(void) -{ - int16_t i16 = 0x1234; - uint16_t u16 = 0xabcd; - int32_t i32 = 0x12345678; - uint32_t u32 = 0xabcdef01; - - union { - uint8_t bytes[4]; - uint16_t u16; - uint32_t u32; - } data; - - printf("\n+++ libFLAC unit test: endswap (%s endian host)\n\n", CPU_IS_BIG_ENDIAN ? "big" : "little"); - - printf("testing ENDSWAP_16 on int16_t ... "); - if (((int16_t) ENDSWAP_16(i16)) == i16) { - printf("\nFAILED, ENDSWAP_16(0x%04x) -> 0x%04x == 0x%04x\n", i16, ENDSWAP_16(i16), i16); - return false; - } - if (((int16_t) ENDSWAP_16(ENDSWAP_16(i16))) != i16) { - printf("\nFAILED, ENDSWAP_16(ENDSWAP_16(0x%04x)) -> 0x%04x != 0x%04x\n", i16, ENDSWAP_16(ENDSWAP_16(i16)), i16); - return false; - } - puts("OK"); - - printf("testing ENDSWAP_16 on uint16_t ... "); - if (((uint16_t) ENDSWAP_16(u16)) == u16) { - printf("\nFAILED, ENDSWAP_16(0x%04x) -> 0x%04x == 0x%04x\n", u16, ENDSWAP_16(u16), u16); - return false; - } - if (((uint16_t) ENDSWAP_16(ENDSWAP_16(u16))) != u16) { - printf("\nFAILED, ENDSWAP_16(ENDSWAP_16(0x%04x)) -> 0x%04x != 0x%04x\n", u16, ENDSWAP_16(ENDSWAP_16(u16)), u16); - return false; - } - puts("OK"); - - printf("testing ENDSWAP_32 on int32_t ... "); - if (((int32_t) ENDSWAP_32 (i32)) == i32) { - printf("\nFAILED, ENDSWAP_32(0x%08x) -> 0x%08x == 0x%08x\n", i32, (uint32_t) ENDSWAP_32 (i32), i32); - return false; - } - if (((int32_t) ENDSWAP_32 (ENDSWAP_32 (i32))) != i32) { - printf("\nFAILED, ENDSWAP_32(ENDSWAP_32(0x%08x)) -> 0x%08x != 0x%08x\n", i32, (uint32_t) ENDSWAP_32(ENDSWAP_32 (i32)), i32); - return false; - } - puts("OK"); - - printf("testing ENDSWAP_32 on uint32_t ... "); - if (((uint32_t) ENDSWAP_32(u32)) == u32) { - printf("\nFAILED, ENDSWAP_32(0x%08x) -> 0x%08x == 0x%08x\n", u32, (uint32_t) ENDSWAP_32(u32), u32); - return false; - } - if (((uint32_t) ENDSWAP_32 (ENDSWAP_32(u32))) != u32) { - printf("\nFAILED, ENDSWAP_32(ENDSWAP_32(0x%08x)) -> 0x%08x != 0%08x\n", u32, (uint32_t) ENDSWAP_32(ENDSWAP_32(u32)), u32); - return false; - } - puts("OK"); - - printf("testing H2LE_16 on uint16_t ... "); - data.u16 = H2LE_16(0x1234); - if (data.bytes [0] != 0x34 || data.bytes [1] != 0x12) { - printf("\nFAILED, H2LE_16(0x%04x) -> { 0x%02x, 0x%02x }\n", data.u16, data.bytes [0] & 0xff, data.bytes [1] & 0xff); - return false; - } - puts("OK"); - - printf("testing H2LE_32 on uint32_t ... "); - data.u32 = H2LE_32(0x12345678); - if (data.bytes [0] != 0x78 || data.bytes [1] != 0x56 || data.bytes [2] != 0x34 || data.bytes [3] != 0x12) { - printf("\nFAILED, H2LE_32(0x%08x) -> { 0x%02x, 0x%02x, 0x%02x, 0x%02x }\n", - data.u32, data.bytes [0] & 0xff, data.bytes [1] & 0xff, data.bytes [2] & 0xff, data.bytes [3] & 0xff); - return false; - } - puts("OK"); - - printf("\nPASSED!\n"); - return true; -} diff --git a/flac/src/test_libFLAC/endswap.h b/flac/src/test_libFLAC/endswap.h deleted file mode 100644 index 952b17f..0000000 --- a/flac/src/test_libFLAC/endswap.h +++ /dev/null @@ -1,26 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2014-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLAC_ENDSWAP_H -#define FLAC__TEST_LIBFLAC_ENDSWAP_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_endswap(void); - -#endif diff --git a/flac/src/test_libFLAC/format.c b/flac/src/test_libFLAC/format.c deleted file mode 100644 index c5e8bf2..0000000 --- a/flac/src/test_libFLAC/format.c +++ /dev/null @@ -1,260 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "FLAC/assert.h" -#include "FLAC/format.h" -#include "format.h" -#include - -static const char *true_false_string_[2] = { "false", "true" }; - -static struct { - uint32_t rate; - FLAC__bool valid; - FLAC__bool subset; -} SAMPLE_RATES[] = { - { 0 , true , true }, - { 1 , true , true }, - { 9 , true , true }, - { 10 , true , true }, - { 4000 , true , true }, - { 8000 , true , true }, - { 11025 , true , true }, - { 12000 , true , true }, - { 16000 , true , true }, - { 22050 , true , true }, - { 24000 , true , true }, - { 32000 , true , true }, - { 32768 , true , true }, - { 44100 , true , true }, - { 48000 , true , true }, - { 65000 , true , true }, - { 65535 , true , true }, - { 65536 , true , false }, - { 65540 , true , true }, - { 65550 , true , true }, - { 65555 , true , false }, - { 66000 , true , true }, - { 66001 , true , false }, - { 96000 , true , true }, - { 100000 , true , true }, - { 100001 , true , false }, - { 192000 , true , true }, - { 500000 , true , true }, - { 500001 , true , false }, - { 500010 , true , true }, - { 655349 , true , false }, - { 655350 , true , true }, - { 655351 , true , false }, - { 655360 , true , false }, - { 700000 , true , false }, - { 700010 , true , false }, - { 705600 , true , false }, - { 768000 , true , false }, - { 1000000, true , false }, - { 1048575, true , false }, - { 1100000, false, false } -}; - -static struct { - const char *string; - FLAC__bool valid; -} VCENTRY_NAMES[] = { - { "" , true }, - { "a" , true }, - { "=" , false }, - { "a=" , false }, - { "\x01", false }, - { "\x1f", false }, - { "\x7d", true }, - { "\x7e", false }, - { "\xff", false } -}; - -static struct { - uint32_t length; - const FLAC__byte *string; - FLAC__bool valid; -} VCENTRY_VALUES[] = { - { 0, (const FLAC__byte*)"" , true }, - { 1, (const FLAC__byte*)"" , true }, - { 1, (const FLAC__byte*)"\x01" , true }, - { 1, (const FLAC__byte*)"\x7f" , true }, - { 1, (const FLAC__byte*)"\x80" , false }, - { 1, (const FLAC__byte*)"\x81" , false }, - { 1, (const FLAC__byte*)"\xc0" , false }, - { 1, (const FLAC__byte*)"\xe0" , false }, - { 1, (const FLAC__byte*)"\xf0" , false }, - { 2, (const FLAC__byte*)"\xc0\x41" , false }, - { 2, (const FLAC__byte*)"\xc1\x41" , false }, - { 2, (const FLAC__byte*)"\xc0\x85" , false }, /* non-shortest form */ - { 2, (const FLAC__byte*)"\xc1\x85" , false }, /* non-shortest form */ - { 2, (const FLAC__byte*)"\xc2\x85" , true }, - { 2, (const FLAC__byte*)"\xe0\x41" , false }, - { 2, (const FLAC__byte*)"\xe1\x41" , false }, - { 2, (const FLAC__byte*)"\xe0\x85" , false }, - { 2, (const FLAC__byte*)"\xe1\x85" , false }, - { 3, (const FLAC__byte*)"\xe0\x85\x41", false }, - { 3, (const FLAC__byte*)"\xe1\x85\x41", false }, - { 3, (const FLAC__byte*)"\xe0\x85\x80", false }, /* non-shortest form */ - { 3, (const FLAC__byte*)"\xe0\x95\x80", false }, /* non-shortest form */ - { 3, (const FLAC__byte*)"\xe0\xa5\x80", true }, - { 3, (const FLAC__byte*)"\xe1\x85\x80", true }, - { 3, (const FLAC__byte*)"\xe1\x95\x80", true }, - { 3, (const FLAC__byte*)"\xe1\xa5\x80", true } -}; - -static struct { - const FLAC__byte *string; - FLAC__bool valid; -} VCENTRY_VALUES_NT[] = { - { (const FLAC__byte*)"" , true }, - { (const FLAC__byte*)"\x01" , true }, - { (const FLAC__byte*)"\x7f" , true }, - { (const FLAC__byte*)"\x80" , false }, - { (const FLAC__byte*)"\x81" , false }, - { (const FLAC__byte*)"\xc0" , false }, - { (const FLAC__byte*)"\xe0" , false }, - { (const FLAC__byte*)"\xf0" , false }, - { (const FLAC__byte*)"\xc0\x41" , false }, - { (const FLAC__byte*)"\xc1\x41" , false }, - { (const FLAC__byte*)"\xc0\x85" , false }, /* non-shortest form */ - { (const FLAC__byte*)"\xc1\x85" , false }, /* non-shortest form */ - { (const FLAC__byte*)"\xc2\x85" , true }, - { (const FLAC__byte*)"\xe0\x41" , false }, - { (const FLAC__byte*)"\xe1\x41" , false }, - { (const FLAC__byte*)"\xe0\x85" , false }, - { (const FLAC__byte*)"\xe1\x85" , false }, - { (const FLAC__byte*)"\xe0\x85\x41", false }, - { (const FLAC__byte*)"\xe1\x85\x41", false }, - { (const FLAC__byte*)"\xe0\x85\x80", false }, /* non-shortest form */ - { (const FLAC__byte*)"\xe0\x95\x80", false }, /* non-shortest form */ - { (const FLAC__byte*)"\xe0\xa5\x80", true }, - { (const FLAC__byte*)"\xe1\x85\x80", true }, - { (const FLAC__byte*)"\xe1\x95\x80", true }, - { (const FLAC__byte*)"\xe1\xa5\x80", true } -}; - -static struct { - uint32_t length; - const FLAC__byte *string; - FLAC__bool valid; -} VCENTRIES[] = { - { 0, (const FLAC__byte*)"" , false }, - { 1, (const FLAC__byte*)"a" , false }, - { 1, (const FLAC__byte*)"=" , true }, - { 2, (const FLAC__byte*)"a=" , true }, - { 2, (const FLAC__byte*)"\x01=" , false }, - { 2, (const FLAC__byte*)"\x1f=" , false }, - { 2, (const FLAC__byte*)"\x7d=" , true }, - { 2, (const FLAC__byte*)"\x7e=" , false }, - { 2, (const FLAC__byte*)"\xff=" , false }, - { 3, (const FLAC__byte*)"a=\x01" , true }, - { 3, (const FLAC__byte*)"a=\x7f" , true }, - { 3, (const FLAC__byte*)"a=\x80" , false }, - { 3, (const FLAC__byte*)"a=\x81" , false }, - { 3, (const FLAC__byte*)"a=\xc0" , false }, - { 3, (const FLAC__byte*)"a=\xe0" , false }, - { 3, (const FLAC__byte*)"a=\xf0" , false }, - { 4, (const FLAC__byte*)"a=\xc0\x41" , false }, - { 4, (const FLAC__byte*)"a=\xc1\x41" , false }, - { 4, (const FLAC__byte*)"a=\xc0\x85" , false }, /* non-shortest form */ - { 4, (const FLAC__byte*)"a=\xc1\x85" , false }, /* non-shortest form */ - { 4, (const FLAC__byte*)"a=\xc2\x85" , true }, - { 4, (const FLAC__byte*)"a=\xe0\x41" , false }, - { 4, (const FLAC__byte*)"a=\xe1\x41" , false }, - { 4, (const FLAC__byte*)"a=\xe0\x85" , false }, - { 4, (const FLAC__byte*)"a=\xe1\x85" , false }, - { 5, (const FLAC__byte*)"a=\xe0\x85\x41", false }, - { 5, (const FLAC__byte*)"a=\xe1\x85\x41", false }, - { 5, (const FLAC__byte*)"a=\xe0\x85\x80", false }, /* non-shortest form */ - { 5, (const FLAC__byte*)"a=\xe0\x95\x80", false }, /* non-shortest form */ - { 5, (const FLAC__byte*)"a=\xe0\xa5\x80", true }, - { 5, (const FLAC__byte*)"a=\xe1\x85\x80", true }, - { 5, (const FLAC__byte*)"a=\xe1\x95\x80", true }, - { 5, (const FLAC__byte*)"a=\xe1\xa5\x80", true } -}; - -FLAC__bool test_format(void) -{ - uint32_t i; - - printf("\n+++ libFLAC unit test: format\n\n"); - - for(i = 0; i < sizeof(SAMPLE_RATES)/sizeof(SAMPLE_RATES[0]); i++) { - printf("testing FLAC__format_sample_rate_is_valid(%u)... ", SAMPLE_RATES[i].rate); - if(FLAC__format_sample_rate_is_valid(SAMPLE_RATES[i].rate) != SAMPLE_RATES[i].valid) { - printf("FAILED, expected %s, got %s\n", true_false_string_[SAMPLE_RATES[i].valid], true_false_string_[!SAMPLE_RATES[i].valid]); - return false; - } - printf("OK\n"); - } - - for(i = 0; i < sizeof(SAMPLE_RATES)/sizeof(SAMPLE_RATES[0]); i++) { - printf("testing FLAC__format_sample_rate_is_subset(%u)... ", SAMPLE_RATES[i].rate); - if(FLAC__format_sample_rate_is_subset(SAMPLE_RATES[i].rate) != SAMPLE_RATES[i].subset) { - printf("FAILED, expected %s, got %s\n", true_false_string_[SAMPLE_RATES[i].subset], true_false_string_[!SAMPLE_RATES[i].subset]); - return false; - } - printf("OK\n"); - } - - for(i = 0; i < sizeof(VCENTRY_NAMES)/sizeof(VCENTRY_NAMES[0]); i++) { - printf("testing FLAC__format_vorbiscomment_entry_name_is_legal(\"%s\")... ", VCENTRY_NAMES[i].string); - if(FLAC__format_vorbiscomment_entry_name_is_legal(VCENTRY_NAMES[i].string) != VCENTRY_NAMES[i].valid) { - printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_NAMES[i].valid], true_false_string_[!VCENTRY_NAMES[i].valid]); - return false; - } - printf("OK\n"); - } - - for(i = 0; i < sizeof(VCENTRY_VALUES)/sizeof(VCENTRY_VALUES[0]); i++) { - printf("testing FLAC__format_vorbiscomment_entry_value_is_legal(\"%s\", %u)... ", VCENTRY_VALUES[i].string, VCENTRY_VALUES[i].length); - if(FLAC__format_vorbiscomment_entry_value_is_legal(VCENTRY_VALUES[i].string, VCENTRY_VALUES[i].length) != VCENTRY_VALUES[i].valid) { - printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_VALUES[i].valid], true_false_string_[!VCENTRY_VALUES[i].valid]); - return false; - } - printf("OK\n"); - } - - for(i = 0; i < sizeof(VCENTRY_VALUES_NT)/sizeof(VCENTRY_VALUES_NT[0]); i++) { - printf("testing FLAC__format_vorbiscomment_entry_value_is_legal(\"%s\", -1)... ", VCENTRY_VALUES_NT[i].string); - if(FLAC__format_vorbiscomment_entry_value_is_legal(VCENTRY_VALUES_NT[i].string, (uint32_t)(-1)) != VCENTRY_VALUES_NT[i].valid) { - printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRY_VALUES_NT[i].valid], true_false_string_[!VCENTRY_VALUES_NT[i].valid]); - return false; - } - printf("OK\n"); - } - - for(i = 0; i < sizeof(VCENTRIES)/sizeof(VCENTRIES[0]); i++) { - printf("testing FLAC__format_vorbiscomment_entry_is_legal(\"%s\", %u)... ", VCENTRIES[i].string, VCENTRIES[i].length); - if(FLAC__format_vorbiscomment_entry_is_legal(VCENTRIES[i].string, VCENTRIES[i].length) != VCENTRIES[i].valid) { - printf("FAILED, expected %s, got %s\n", true_false_string_[VCENTRIES[i].valid], true_false_string_[!VCENTRIES[i].valid]); - return false; - } - printf("OK\n"); - } - - printf("\nPASSED!\n"); - return true; -} diff --git a/flac/src/test_libFLAC/format.h b/flac/src/test_libFLAC/format.h deleted file mode 100644 index f78d55d..0000000 --- a/flac/src/test_libFLAC/format.h +++ /dev/null @@ -1,27 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLAC_FORMAT_H -#define FLAC__TEST_LIBFLAC_FORMAT_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_format(void); - -#endif diff --git a/flac/src/test_libFLAC/main.c b/flac/src/test_libFLAC/main.c deleted file mode 100644 index a4be0fe..0000000 --- a/flac/src/test_libFLAC/main.c +++ /dev/null @@ -1,64 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "bitreader.h" -#include "bitwriter.h" -#include "crc.h" -#include "decoders.h" -#include "encoders.h" -#include "endswap.h" -#include "format.h" -#include "metadata.h" -#include "md5.h" - -int main(void) -{ - if(!test_endswap()) - return 1; - - if(!test_crc()) - return 1; - - if(!test_md5()) - return 1; - - if(!test_bitreader()) - return 1; - - if(!test_bitwriter()) - return 1; - - if(!test_format()) - return 1; - - if(!test_encoders()) - return 1; - - if(!test_decoders()) - return 1; - - if(!test_metadata()) - return 1; - - return 0; -} diff --git a/flac/src/test_libFLAC/matrix b/flac/src/test_libFLAC/matrix deleted file mode 100644 index a78ecf3..0000000 --- a/flac/src/test_libFLAC/matrix +++ /dev/null @@ -1,69 +0,0 @@ -#if 0 -level 1 - -4 delete middle block nopad -1 delete middle block pad -1 delete last block nopad -1 delete last block pad -1 insert middle block nopad -1 insert middle block equalpad -1 insert middle block smallpad -1 insert middle block smallpad+1 -1 insert middle block biggerpad -1 insert last block X -1 set middle block smaller nopad -1 set middle block smaller pad -1 set last block smaller nopad -1 set last block smaller pad -1 set middle block bigger nopad -1 set middle block bigger equalpad -1 set middle block bigger smallpad -1 set middle block bigger smallpad+1 -1 set middle block bigger biggerpad -1 set last block bigger nopad -1 set middle block equal X -2 set last block equal X - -level 2 - -FLAC__bool FLAC__metadata_chain_write() - -1 newsize==oldsize - newsize>oldsize -b no use_padding -c use_padding, last block is not padding -g use_padding, last block is padding of insufficient length -h use_padding, last block is padding, but padding header straddles border (can't do it) -j use_padding, last block is padding of exact sufficient length (padding totally consumed) -i use_padding, last block is padding of abundant length (padding is reduced) - newsize= 4 -f use_padding, last block is padding - -void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain); -void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain); - -S:34 A:1234 -a:shrink A->30 write nopad -S:34 A:30 -b:grow A->32 write nopad -S:34 A:32 -c:grow A->40 write pad -S:34 A:40 -d:shrink A->37 write pad -S:34 A:37 -e:shrink A->33 write pad -S:34 A:33 P:0 -f:shrink A->20 write pad -S:34 A:20 P:13 -g:grow A->40 write pad -S:34 A:40 P:13 -h:grow A->54 write pad -S:34 A:54 P:13 -i:grow A->60 write pad -S:34 A:60 P:7 -j:grow A->71 write pad -S:34 A:71 -#endif diff --git a/flac/src/test_libFLAC/md5.c b/flac/src/test_libFLAC/md5.c deleted file mode 100644 index bac4a74..0000000 --- a/flac/src/test_libFLAC/md5.c +++ /dev/null @@ -1,221 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2014-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include "FLAC/assert.h" -#include "share/compat.h" -#include "private/md5.h" -#include "md5.h" - - -static FLAC__bool test_md5_clear_context(void); -static FLAC__bool test_md5_codec(void); -static FLAC__bool test_md5_accumulate(const FLAC__int32 * const * signal,uint32_t channels, uint32_t samples, uint32_t bytes_per_sample, const FLAC__byte target_digest [16]); - -FLAC__bool test_md5(void) -{ - printf("\n+++ libFLAC unit test: md5\n\n"); - - if (! test_md5_clear_context()) - return false; - - if (! test_md5_codec()) - return false; - - printf("\nPASSED!\n"); - return true; -} - -/*----------------------------------------------------------------------------*/ - -static FLAC__bool test_md5_clear_context(void) -{ - FLAC__MD5Context ctx; - FLAC__byte digest[16]; - FLAC__byte target[16] = { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e }; - uint32_t k ; - char * cptr; - - printf("testing FLAC__MD5Init ... "); - FLAC__MD5Init (&ctx); - if (ctx.buf[0] != 0x67452301) { - printf("FAILED!\n"); - return false; - } - printf("OK\n"); - - printf("testing that FLAC__MD5Final clears the MD5Context ... "); - FLAC__MD5Final(digest, &ctx); - cptr = (char*) &ctx ; - for (k = 0 ; k < sizeof (ctx) ; k++) { - if (cptr [k]) { - printf("FAILED, MD5 ctx has not been cleared after FLAC__MD5Final\n"); - return false; - } - } - printf("OK\n"); - - printf("testing digest correct for zero data ... "); - if (memcmp(digest, target, sizeof (digest))) { - printf("\nFAILED, expected MD5 sum "); - for (k = 0 ; k < 16 ; k++) - printf("%02x", (target [k] & 0xff)); - printf (" but got "); - for (k = 0 ; k < 16 ; k++) - printf("%02x", (digest [k] & 0xff)); - puts("\n"); - return false; - } - puts("OK"); - - return true; -} - -static FLAC__byte target_digests [8][4][16] = -{ /* 1 channel */ - { /* 1 byte per sample */ - { 0xc1, 0x9a, 0x5b, 0xeb, 0x57, 0x8f, 0x26, 0xeb, 0xfb, 0x34, 0x7c, 0xef, 0x04, 0x31, 0x6d, 0x7d }, - /* 2 bytes per sample */ - { 0xd4, 0x78, 0x90, 0xd3, 0xa9, 0x17, 0x4e, 0x76, 0xca, 0x4d, 0x27, 0x20, 0x98, 0x36, 0x8b, 0x2e }, - /* 3 bytes per sample */ - { 0x5a, 0x4b, 0xd6, 0xac, 0xa1, 0x70, 0x84, 0x19, 0x7c, 0x0d, 0xfb, 0x5b, 0xa9, 0x7b, 0xcb, 0x54 }, - /* 4 bytes per sample */ - { 0x79, 0xd5, 0x7a, 0x32, 0x06, 0x0b, 0xfe, 0x46, 0xa3, 0xe7, 0xba, 0xc5, 0xf7, 0x48, 0x6f, 0x50 } - }, - - /* 2 channels */ - { - { 0x89, 0xac, 0xcf, 0x91, 0xf1, 0x8c, 0xea, 0xab, 0x46, 0x12, 0x74, 0xbc, 0x4e, 0x82, 0xbe, 0x7d }, - { 0xb9, 0x17, 0x16, 0x5b, 0xd8, 0x1c, 0xc8, 0x4e, 0x5a, 0x28, 0xfb, 0xba, 0x87, 0x74, 0x76, 0x44 }, - { 0xec, 0x63, 0x92, 0xca, 0x4f, 0x6b, 0x9e, 0xb1, 0x9f, 0xec, 0x3b, 0x2c, 0x15, 0x30, 0xfd, 0x2a }, - { 0x05, 0x4d, 0xfd, 0xb8, 0x9d, 0x8a, 0xa2, 0xdd, 0x26, 0x47, 0xc6, 0xfb, 0x4f, 0x23, 0x67, 0x6d } - }, - - /* 3 channels */ - { - { 0xad, 0x05, 0xda, 0xf3, 0x7a, 0xa1, 0x94, 0xdb, 0x0c, 0x61, 0x06, 0xb2, 0x94, 0x39, 0x6c, 0xa9 }, - { 0x8b, 0xcc, 0x41, 0x4d, 0xe9, 0xe3, 0xc2, 0x61, 0x61, 0x8a, 0x8b, 0x22, 0xc6, 0x4e, 0xac, 0xa7 }, - { 0x8a, 0xce, 0x97, 0xc1, 0x86, 0xae, 0xbc, 0x73, 0x88, 0x8b, 0x35, 0x5a, 0x37, 0x33, 0xf9, 0xcf }, - { 0x69, 0x59, 0xe8, 0x38, 0x29, 0x80, 0x80, 0x21, 0xb1, 0xd2, 0xba, 0xf6, 0x28, 0xd6, 0x6a, 0x83 } - }, - - /* 4 channels */ - { - { 0x61, 0x40, 0x75, 0xef, 0x22, 0xf1, 0x0f, 0xa6, 0x08, 0x6c, 0x88, 0xff, 0x2c, 0x4e, 0x98, 0x0b }, - { 0xa0, 0x77, 0x3a, 0x59, 0x4a, 0xbf, 0xd0, 0x5c, 0xcc, 0xe3, 0xb9, 0x83, 0x2b, 0xf3, 0xdf, 0x1a }, - { 0xdb, 0xd7, 0xf1, 0x82, 0x13, 0x60, 0x42, 0x7c, 0x84, 0xe6, 0xcf, 0x30, 0xab, 0xa2, 0x64, 0xf1 }, - { 0x4a, 0x9a, 0xad, 0x53, 0x05, 0x74, 0xb1, 0x1c, 0xb8, 0xd4, 0xae, 0x78, 0x13, 0xf6, 0x2a, 0x11 } - }, - - /* 5 channels */ - { - { 0xcc, 0xca, 0x44, 0xc0, 0x54, 0xe2, 0xc9, 0xba, 0x99, 0x32, 0xc9, 0x65, 0xf3, 0x3e, 0x44, 0x34}, - { 0x40, 0x38, 0x6a, 0xdd, 0xde, 0x89, 0x10, 0x3c, 0x8e, 0xec, 0xdf, 0x15, 0x53, 0x4c, 0x2c, 0x92 }, - { 0xc8, 0x95, 0x0a, 0x7c, 0x17, 0x30, 0xc0, 0xac, 0x8e, 0x34, 0xdb, 0x79, 0x76, 0x64, 0x7c, 0x6e }, - { 0x3f, 0x06, 0x11, 0x8a, 0x8d, 0x80, 0xb5, 0x4f, 0x8b, 0xb5, 0x8e, 0xb3, 0x27, 0x3e, 0x41, 0xe8 } - }, - - /* 6 channels */ - { - { 0x61, 0xe4, 0xbd, 0xb1, 0xc0, 0x2f, 0xf4, 0x4c, 0x6e, 0x09, 0x5a, 0xbd, 0x90, 0x18, 0x8b, 0x62 }, - { 0x47, 0xe7, 0x6e, 0x3b, 0x18, 0x86, 0x60, 0x1b, 0x09, 0x62, 0xc6, 0xc9, 0x7c, 0x4c, 0x03, 0xb5 }, - { 0x70, 0x57, 0xbf, 0x67, 0x66, 0x0f, 0xe3, 0x0a, 0x6c, 0xd2, 0x97, 0x66, 0xa2, 0xd2, 0xe4, 0x79 }, - { 0xaa, 0x3f, 0xc7, 0xf5, 0x7a, 0xa5, 0x46, 0xf7, 0xea, 0xe3, 0xd5, 0x1a, 0xa4, 0x62, 0xbe, 0xfa } - }, - - /* 7 channels */ - { - { 0x7c, 0x8d, 0xd2, 0x8c, 0xfd, 0x91, 0xbb, 0x77, 0x6f, 0x0e, 0xf0, 0x39, 0x1f, 0x39, 0xc4, 0xac }, - { 0xfb, 0xab, 0x18, 0x3f, 0x1e, 0x1d, 0xa5, 0x77, 0xe0, 0x5c, 0xea, 0x45, 0x6f, 0x64, 0xa4, 0x64 }, - { 0xe3, 0xac, 0x33, 0x50, 0xc1, 0xb1, 0x93, 0xfb, 0xca, 0x4b, 0x15, 0xcb, 0x2d, 0xcd, 0xd5, 0xef }, - { 0x10, 0xfb, 0x02, 0x83, 0x76, 0x0d, 0xe5, 0xd2, 0x3b, 0xb1, 0x4c, 0x78, 0x3b, 0x73, 0xf7, 0x1a } - }, - - /* 8 channels */ - { - { 0x65, 0x7b, 0xe5, 0x92, 0xe2, 0x1c, 0x95, 0x3e, 0xd7, 0x2f, 0x64, 0xa0, 0x86, 0xec, 0x1a, 0xed }, - { 0x9d, 0x04, 0x8f, 0xa4, 0xea, 0x10, 0xec, 0xb8, 0xa3, 0x88, 0xe2, 0x5d, 0x3c, 0xe2, 0xfb, 0x94 }, - { 0x5a, 0xd3, 0xd2, 0x75, 0x6a, 0xfa, 0xa7, 0x42, 0xf3, 0xbf, 0x0e, 0xbc, 0x90, 0x2a, 0xf8, 0x5f }, - { 0x76, 0xe1, 0xe5, 0xf6, 0xe3, 0x44, 0x08, 0x29, 0xae, 0x79, 0x19, 0xeb, 0xa8, 0x57, 0x16, 0x2a } - } -}; - -#define MAX_CHANNEL_COUNT 8 -#define MD5_SAMPLE_COUNT 64 - -static FLAC__bool test_md5_codec(void) -{ - FLAC__int32 arrays[MAX_CHANNEL_COUNT][MD5_SAMPLE_COUNT], *pointer[MAX_CHANNEL_COUNT], **signal; - uint32_t chan, byte_size, seed = 0x12345679; - - /* Set up signal data using a trivial Linear Congruent PRNG. */ - signal = &pointer[0]; - for (chan = 0 ; chan < MAX_CHANNEL_COUNT ; chan ++) { - uint32_t k; - pointer[chan] = arrays [chan]; - for (k = 0 ; k < MD5_SAMPLE_COUNT ; k++) { - seed = seed * 1103515245 + 12345; - arrays[chan][k] = seed; - } - } - - for (chan = 1 ; chan <= MAX_CHANNEL_COUNT ; chan ++) { - for (byte_size = 1 ; byte_size <= 4 ; byte_size ++) { - if (! test_md5_accumulate((const FLAC__int32 * const *) signal, chan, MD5_SAMPLE_COUNT, byte_size, target_digests[chan-1][byte_size-1])) - return false; - } - } - - return true; -} - -static FLAC__bool test_md5_accumulate(const FLAC__int32 * const * signal, uint32_t channels, uint32_t samples, uint32_t bytes_per_sample, const FLAC__byte target_digest [16]) -{ - FLAC__MD5Context ctx; - FLAC__byte digest[16]; - - memset(&ctx, 0, sizeof (ctx)); - - printf("testing FLAC__MD5Accumulate (samples=%u, channels=%u, bytes_per_sample=%u) ... ", samples, channels, bytes_per_sample); - - FLAC__MD5Init(&ctx); - FLAC__MD5Accumulate(&ctx, signal, channels, samples, bytes_per_sample); - FLAC__MD5Final(digest, &ctx); - - if (memcmp(digest, target_digest, sizeof (digest))) { - int k ; - - printf("\nFAILED, expected MD5 sum "); - for (k = 0 ; k < 16 ; k++) - printf("%02x", (target_digest [k] & 0xff)); - printf (" but got "); - for (k = 0 ; k < 16 ; k++) - printf("%02x", (digest [k] & 0xff)); - puts("\n"); - return false; - } - - printf("OK\n"); - return true; -} diff --git a/flac/src/test_libFLAC/md5.h b/flac/src/test_libFLAC/md5.h deleted file mode 100644 index 6863268..0000000 --- a/flac/src/test_libFLAC/md5.h +++ /dev/null @@ -1,26 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2014-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLAC_MD5_H -#define FLAC__TEST_LIBFLAC_MD5_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_md5(void); - -#endif diff --git a/flac/src/test_libFLAC/metadata.c b/flac/src/test_libFLAC/metadata.c deleted file mode 100644 index 0347f6d..0000000 --- a/flac/src/test_libFLAC/metadata.c +++ /dev/null @@ -1,41 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "metadata.h" -#include - -extern FLAC__bool test_metadata_object(void); -extern FLAC__bool test_metadata_file_manipulation(void); - -FLAC__bool test_metadata(void) -{ - if(!test_metadata_object()) - return false; - - if(!test_metadata_file_manipulation()) - return false; - - printf("\nPASSED!\n"); - - return true; -} diff --git a/flac/src/test_libFLAC/metadata.h b/flac/src/test_libFLAC/metadata.h deleted file mode 100644 index 51bdf7a..0000000 --- a/flac/src/test_libFLAC/metadata.h +++ /dev/null @@ -1,29 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 FLAC__TEST_LIBFLAC_METADATA_H -#define FLAC__TEST_LIBFLAC_METADATA_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_metadata(void); -FLAC__bool test_metadata_file_manipulation(void); -FLAC__bool test_metadata_object(void); - -#endif diff --git a/flac/src/test_libFLAC/metadata_manip.c b/flac/src/test_libFLAC/metadata_manip.c deleted file mode 100644 index 334dc3a..0000000 --- a/flac/src/test_libFLAC/metadata_manip.c +++ /dev/null @@ -1,2146 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include /* for malloc() */ -#include /* for memcpy()/memset() */ -#if defined _MSC_VER || defined __MINGW32__ -#include /* for utime() */ -#include /* for chmod() */ -#else -#include /* some flavors of BSD (like OS X) require this to get time_t */ -#include /* for chown(), unlink() */ -#endif -#include /* for stat(), maybe chmod() */ -#include "FLAC/assert.h" -#include "FLAC/stream_decoder.h" -#include "FLAC/metadata.h" -#include "share/grabbag.h" -#include "share/compat.h" -#include "share/macros.h" -#include "share/safe_str.h" -#include "test_libs_common/file_utils_flac.h" -#include "test_libs_common/metadata_utils.h" -#include "metadata.h" - - -/****************************************************************************** - The general strategy of these tests (for interface levels 1 and 2) is - to create a dummy FLAC file with a known set of initial metadata - blocks, then keep a mirror locally of what we expect the metadata to be - after each operation. Then testing becomes a simple matter of running - a FLAC__StreamDecoder over the dummy file after each operation, comparing - the decoded metadata to what's in our local copy. If there are any - differences in the metadata, or the actual audio data is corrupted, we - will catch it while decoding. -******************************************************************************/ - -typedef struct { - FLAC__bool error_occurred; -} decoder_client_struct; - -typedef struct { - FLAC__StreamMetadata *blocks[64]; - uint32_t num_blocks; -} our_metadata_struct; - -/* our copy of the metadata in flacfilename() */ -static our_metadata_struct our_metadata_; - -/* the current block number that corresponds to the position of the iterator we are testing */ -static uint32_t mc_our_block_number_ = 0; - -static const char *flacfilename(FLAC__bool is_ogg) -{ - return is_ogg? "metadata.oga" : "metadata.flac"; -} - -static FLAC__bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static FLAC__bool die_c_(const char *msg, FLAC__Metadata_ChainStatus status) -{ - printf("ERROR: %s\n", msg); - printf(" status=%s\n", FLAC__Metadata_ChainStatusString[status]); - return false; -} - -static FLAC__bool die_ss_(const char *msg, FLAC__Metadata_SimpleIterator *iterator) -{ - printf("ERROR: %s\n", msg); - printf(" status=%s\n", FLAC__Metadata_SimpleIteratorStatusString[FLAC__metadata_simple_iterator_status(iterator)]); - return false; -} - -static void *malloc_or_die_(size_t size) -{ - void *x = malloc(size); - if(0 == x) { - fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (uint32_t)size); - exit(1); - } - return x; -} - -static char *strdup_or_die_(const char *s) -{ - char *x = strdup(s); - if(0 == x) { - fprintf(stderr, "ERROR: out of memory copying string \"%s\"\n", s); - exit(1); - } - return x; -} - -/* functions for working with our metadata copy */ - -static FLAC__bool replace_in_our_metadata_(FLAC__StreamMetadata *block, uint32_t position, FLAC__bool copy) -{ - uint32_t i; - FLAC__StreamMetadata *obj = block; - FLAC__ASSERT(position < our_metadata_.num_blocks); - if(copy) { - if(0 == (obj = FLAC__metadata_object_clone(block))) - return die_("during FLAC__metadata_object_clone()"); - } - FLAC__metadata_object_delete(our_metadata_.blocks[position]); - our_metadata_.blocks[position] = obj; - - /* set the is_last flags */ - for(i = 0; i < our_metadata_.num_blocks - 1; i++) - our_metadata_.blocks[i]->is_last = false; - our_metadata_.blocks[i]->is_last = true; - - return true; -} - -static FLAC__bool insert_to_our_metadata_(FLAC__StreamMetadata *block, uint32_t position, FLAC__bool copy) -{ - uint32_t i; - FLAC__StreamMetadata *obj = block; - if(copy) { - if(0 == (obj = FLAC__metadata_object_clone(block))) - return die_("during FLAC__metadata_object_clone()"); - } - if(position > our_metadata_.num_blocks) { - position = our_metadata_.num_blocks; - } - else { - for(i = our_metadata_.num_blocks; i > position; i--) - our_metadata_.blocks[i] = our_metadata_.blocks[i-1]; - } - our_metadata_.blocks[position] = obj; - our_metadata_.num_blocks++; - - /* set the is_last flags */ - for(i = 0; i < our_metadata_.num_blocks - 1; i++) - our_metadata_.blocks[i]->is_last = false; - our_metadata_.blocks[i]->is_last = true; - - return true; -} - -static void delete_from_our_metadata_(uint32_t position) -{ - uint32_t i; - FLAC__ASSERT(position < our_metadata_.num_blocks); - FLAC__metadata_object_delete(our_metadata_.blocks[position]); - for(i = position; i < our_metadata_.num_blocks - 1; i++) - our_metadata_.blocks[i] = our_metadata_.blocks[i+1]; - our_metadata_.num_blocks--; - - /* set the is_last flags */ - if(our_metadata_.num_blocks > 0) { - for(i = 0; i < our_metadata_.num_blocks - 1; i++) - our_metadata_.blocks[i]->is_last = false; - our_metadata_.blocks[i]->is_last = true; - } -} - -/* - * This wad of functions supports filename- and callback-based chain reading/writing. - * Everything up to set_file_stats_() is copied from libFLAC/metadata_iterators.c - */ -static FLAC__bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfilename) -{ - static const char *tempfile_suffix = ".metadata_edit"; - size_t dest_len = strlen(filename) + strlen(tempfile_suffix) + 1; - - *tempfilename = malloc(dest_len); - if (*tempfilename == NULL) - return false; - safe_strncpy(*tempfilename, filename, dest_len); - safe_strncat(*tempfilename, tempfile_suffix, dest_len); - - *tempfile = flac_fopen(*tempfilename, "wb"); - if (*tempfile == NULL) - return false; - - return true; -} - -static void cleanup_tempfile_(FILE **tempfile, char **tempfilename) -{ - if (*tempfile != NULL) { - (void)fclose(*tempfile); - *tempfile = 0; - } - - if (*tempfilename != NULL) { - (void)flac_unlink(*tempfilename); - free(*tempfilename); - *tempfilename = 0; - } -} - -static FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != tempfile); - FLAC__ASSERT(0 != tempfilename); - FLAC__ASSERT(0 != *tempfilename); - - if(0 != *tempfile) { - (void)fclose(*tempfile); - *tempfile = 0; - } - -#if defined _MSC_VER || defined __MINGW32__ || defined __EMX__ - /* on some flavors of windows, flac_rename() will fail if the destination already exists */ - if(flac_unlink(filename) < 0) { - cleanup_tempfile_(tempfile, tempfilename); - return false; - } -#endif - - if(0 != flac_rename(*tempfilename, filename)) { - cleanup_tempfile_(tempfile, tempfilename); - return false; - } - - cleanup_tempfile_(tempfile, tempfilename); - - return true; -} - -static FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stats) -{ - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - return (0 == flac_stat(filename, stats)); -} - -static void set_file_stats_(const char *filename, struct flac_stat_s *stats) -{ -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) && !defined(_WIN32) - struct timespec srctime[2] = {}; - srctime[0].tv_sec = stats->st_atime; - srctime[1].tv_sec = stats->st_mtime; -#else - struct utimbuf srctime; - srctime.actime = stats->st_atime; - srctime.modtime = stats->st_mtime; -#endif - FLAC__ASSERT(0 != filename); - FLAC__ASSERT(0 != stats); - - (void)flac_chmod(filename, stats->st_mode); - (void)flac_utime(filename, &srctime); -#if !defined _MSC_VER && !defined __MINGW32__ - FLAC_CHECK_RETURN(chown(filename, stats->st_uid, -1)); - FLAC_CHECK_RETURN(chown(filename, -1, stats->st_gid)); -#endif -} - -#ifdef FLAC__VALGRIND_TESTING -static size_t chain_write_cb_(const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle) -{ - FILE *stream = (FILE*)handle; - size_t ret = fwrite(ptr, size, nmemb, stream); - if(!ferror(stream)) - fflush(stream); - return ret; -} -#endif - -static int chain_seek_cb_(FLAC__IOHandle handle, FLAC__int64 offset, int whence) -{ - FLAC__off_t o = (FLAC__off_t)offset; - FLAC__ASSERT(offset == o); - return fseeko((FILE*)handle, o, whence); -} - -static FLAC__int64 chain_tell_cb_(FLAC__IOHandle handle) -{ - return ftello((FILE*)handle); -} - -static int chain_eof_cb_(FLAC__IOHandle handle) -{ - return feof((FILE*)handle); -} - -static FLAC__bool write_chain_(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats, FLAC__bool filename_based, const char *filename) -{ - if(filename_based) - return FLAC__metadata_chain_write(chain, use_padding, preserve_file_stats); - else { - FLAC__IOCallbacks callbacks; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.read = (FLAC__IOCallback_Read)fread; -#ifdef FLAC__VALGRIND_TESTING - callbacks.write = chain_write_cb_; -#else - callbacks.write = (FLAC__IOCallback_Write)fwrite; -#endif - callbacks.seek = chain_seek_cb_; - callbacks.eof = chain_eof_cb_; - - if(FLAC__metadata_chain_check_if_tempfile_needed(chain, use_padding)) { - struct flac_stat_s stats; - FILE *file, *tempfile = 0; - char *tempfilename; - if(preserve_file_stats) { - if(!get_file_stats_(filename, &stats)) - return false; - } - if(0 == (file = flac_fopen(filename, "rb"))) - return false; /*@@@@ chain status still says OK though */ - if(!open_tempfile_(filename, &tempfile, &tempfilename)) { - fclose(file); - cleanup_tempfile_(&tempfile, &tempfilename); - return false; /*@@@@ chain status still says OK though */ - } - if(!FLAC__metadata_chain_write_with_callbacks_and_tempfile(chain, use_padding, (FLAC__IOHandle)file, callbacks, (FLAC__IOHandle)tempfile, callbacks)) { - fclose(file); - fclose(tempfile); - return false; - } - fclose(file); - fclose(tempfile); - file = tempfile = 0; - if(!transport_tempfile_(filename, &tempfile, &tempfilename)) - return false; - if(preserve_file_stats) - set_file_stats_(filename, &stats); - } - else { - FILE *file = flac_fopen(filename, "r+b"); - if(0 == file) - return false; /*@@@@ chain status still says OK though */ - if(!FLAC__metadata_chain_write_with_callbacks(chain, use_padding, (FLAC__IOHandle)file, callbacks)) - return false; - fclose(file); - } - } - - return true; -} - -static FLAC__bool read_chain_(FLAC__Metadata_Chain *chain, const char *filename, FLAC__bool filename_based, FLAC__bool is_ogg) -{ - if(filename_based) - return is_ogg? - FLAC__metadata_chain_read_ogg(chain, flacfilename(is_ogg)) : - FLAC__metadata_chain_read(chain, flacfilename(is_ogg)) - ; - else { - FLAC__IOCallbacks callbacks; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.read = (FLAC__IOCallback_Read)fread; - callbacks.seek = chain_seek_cb_; - callbacks.tell = chain_tell_cb_; - - { - FLAC__bool ret; - FILE *file = flac_fopen(filename, "rb"); - if(0 == file) - return false; /*@@@@ chain status still says OK though */ - ret = is_ogg? - FLAC__metadata_chain_read_ogg_with_callbacks(chain, (FLAC__IOHandle)file, callbacks) : - FLAC__metadata_chain_read_with_callbacks(chain, (FLAC__IOHandle)file, callbacks) - ; - fclose(file); - return ret; - } - } -} - -/* function for comparing our metadata to a FLAC__Metadata_Chain */ - -static FLAC__bool compare_chain_(FLAC__Metadata_Chain *chain, uint32_t current_position, FLAC__StreamMetadata *current_block) -{ - uint32_t i; - FLAC__Metadata_Iterator *iterator; - FLAC__StreamMetadata *block; - FLAC__bool next_ok = true; - - FLAC__ASSERT(0 != chain); - - printf("\tcomparing chain... "); - fflush(stdout); - - if(0 == (iterator = FLAC__metadata_iterator_new())) - return die_("allocating memory for iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - i = 0; - do { - printf("%u... ", i); - fflush(stdout); - - if(0 == (block = FLAC__metadata_iterator_get_block(iterator))) { - FLAC__metadata_iterator_delete(iterator); - return die_("getting block from iterator"); - } - - if(!mutils__compare_block(our_metadata_.blocks[i], block)) { - FLAC__metadata_iterator_delete(iterator); - return die_("metadata block mismatch"); - } - - i++; - next_ok = FLAC__metadata_iterator_next(iterator); - } while(i < our_metadata_.num_blocks && next_ok); - - FLAC__metadata_iterator_delete(iterator); - - if(next_ok) - return die_("chain has more blocks than expected"); - - if(i < our_metadata_.num_blocks) - return die_("short block count in chain"); - - if(0 != current_block) { - printf("CURRENT_POSITION... "); - fflush(stdout); - - if(!mutils__compare_block(our_metadata_.blocks[current_position], current_block)) - return die_("metadata block mismatch"); - } - - printf("PASSED\n"); - - return true; -} - -/* decoder callbacks for checking the file */ - -static FLAC__StreamDecoderWriteStatus decoder_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - (void)decoder, (void)buffer, (void)client_data; - - if( - (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) || - (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0) - ) { - printf("content... "); - fflush(stdout); - } - - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -/* this version pays no attention to the metadata */ -static void decoder_metadata_callback_null_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - (void)decoder, (void)metadata, (void)client_data; - - printf("%u... ", mc_our_block_number_); - fflush(stdout); - - mc_our_block_number_++; -} - -/* this version is used when we want to compare to our metadata copy */ -static void decoder_metadata_callback_compare_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - decoder_client_struct *dcd = (decoder_client_struct*)client_data; - - (void)decoder; - - /* don't bother checking if we've already hit an error */ - if(dcd->error_occurred) - return; - - printf("%u... ", mc_our_block_number_); - fflush(stdout); - - if(mc_our_block_number_ >= our_metadata_.num_blocks) { - (void)die_("got more metadata blocks than expected"); - dcd->error_occurred = true; - } - else { - if(!mutils__compare_block(our_metadata_.blocks[mc_our_block_number_], metadata)) { - (void)die_("metadata block mismatch"); - dcd->error_occurred = true; - } - } - mc_our_block_number_++; -} - -static void decoder_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - decoder_client_struct *dcd = (decoder_client_struct*)client_data; - (void)decoder; - - dcd->error_occurred = true; - printf("ERROR: got error callback, status = %s (%u)\n", FLAC__StreamDecoderErrorStatusString[status], (uint32_t)status); -} - -static FLAC__bool generate_file_(FLAC__bool include_extras, FLAC__bool is_ogg) -{ - FLAC__StreamMetadata streaminfo, vorbiscomment, *cuesheet, picture, padding; - FLAC__StreamMetadata *metadata[4]; - uint32_t i = 0, n = 0; - - printf("generating %sFLAC file for test\n", is_ogg? "Ogg " : ""); - - while(our_metadata_.num_blocks > 0) - delete_from_our_metadata_(0); - - streaminfo.is_last = false; - streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO; - streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH; - streaminfo.data.stream_info.min_blocksize = 576; - streaminfo.data.stream_info.max_blocksize = 576; - streaminfo.data.stream_info.min_framesize = 0; - streaminfo.data.stream_info.max_framesize = 0; - streaminfo.data.stream_info.sample_rate = 44100; - streaminfo.data.stream_info.channels = 1; - streaminfo.data.stream_info.bits_per_sample = 8; - streaminfo.data.stream_info.total_samples = 0; - memset(streaminfo.data.stream_info.md5sum, 0, 16); - - { - const uint32_t vendor_string_length = (uint32_t)strlen(FLAC__VENDOR_STRING); - vorbiscomment.is_last = false; - vorbiscomment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT; - vorbiscomment.length = (4 + vendor_string_length) + 4; - vorbiscomment.data.vorbis_comment.vendor_string.length = vendor_string_length; - vorbiscomment.data.vorbis_comment.vendor_string.entry = malloc_or_die_(vendor_string_length+1); - memcpy(vorbiscomment.data.vorbis_comment.vendor_string.entry, FLAC__VENDOR_STRING, vendor_string_length+1); - vorbiscomment.data.vorbis_comment.num_comments = 0; - vorbiscomment.data.vorbis_comment.comments = 0; - } - - { - if (0 == (cuesheet = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET))) - return die_("priming our metadata"); - cuesheet->is_last = false; - safe_strncpy(cuesheet->data.cue_sheet.media_catalog_number, "bogo-MCN", sizeof(cuesheet->data.cue_sheet.media_catalog_number)); - cuesheet->data.cue_sheet.lead_in = 123; - cuesheet->data.cue_sheet.is_cd = false; - if (!FLAC__metadata_object_cuesheet_insert_blank_track(cuesheet, 0)) - return die_("priming our metadata"); - cuesheet->data.cue_sheet.tracks[0].number = 1; - if (!FLAC__metadata_object_cuesheet_track_insert_blank_index(cuesheet, 0, 0)) - return die_("priming our metadata"); - } - - { - picture.is_last = false; - picture.type = FLAC__METADATA_TYPE_PICTURE; - picture.length = - ( - FLAC__STREAM_METADATA_PICTURE_TYPE_LEN + - FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* will add the length for the string later */ - FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* will add the length for the string later */ - FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN + - FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN + - FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN + - FLAC__STREAM_METADATA_PICTURE_COLORS_LEN + - FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */ - ) / 8 - ; - picture.data.picture.type = FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER; - picture.data.picture.mime_type = strdup_or_die_("image/jpeg"); - picture.length += strlen(picture.data.picture.mime_type); - picture.data.picture.description = (FLAC__byte*)strdup_or_die_("desc"); - picture.length += strlen((const char *)picture.data.picture.description); - picture.data.picture.width = 300; - picture.data.picture.height = 300; - picture.data.picture.depth = 24; - picture.data.picture.colors = 0; - picture.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA"); - picture.data.picture.data_length = strlen((const char *)picture.data.picture.data); - picture.length += picture.data.picture.data_length; - } - - padding.is_last = true; - padding.type = FLAC__METADATA_TYPE_PADDING; - padding.length = 1234; - - metadata[n++] = &vorbiscomment; - if(include_extras) { - metadata[n++] = cuesheet; - metadata[n++] = &picture; - } - metadata[n++] = &padding; - - if( - !insert_to_our_metadata_(&streaminfo, i++, /*copy=*/true) || - !insert_to_our_metadata_(&vorbiscomment, i++, /*copy=*/true) || - (include_extras && !insert_to_our_metadata_(cuesheet, i++, /*copy=*/false)) || - (include_extras && !insert_to_our_metadata_(&picture, i++, /*copy=*/true)) || - !insert_to_our_metadata_(&padding, i++, /*copy=*/true) - ) - return die_("priming our metadata"); - - if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), 0, 512 * 1024, &streaminfo, metadata, n)) - return die_("creating the encoded file"); - - free(vorbiscomment.data.vorbis_comment.vendor_string.entry); - free(picture.data.picture.mime_type); - free(picture.data.picture.description); - free(picture.data.picture.data); - if(!include_extras) - FLAC__metadata_object_delete(cuesheet); - - return true; -} - -static FLAC__bool test_file_(FLAC__bool is_ogg, FLAC__StreamDecoderMetadataCallback metadata_callback) -{ - const char *filename = flacfilename(is_ogg); - FLAC__StreamDecoder *decoder; - decoder_client_struct decoder_client_data; - - FLAC__ASSERT(0 != metadata_callback); - - mc_our_block_number_ = 0; - decoder_client_data.error_occurred = false; - - printf("\ttesting '%s'... ", filename); - fflush(stdout); - - if(0 == (decoder = FLAC__stream_decoder_new())) - return die_("couldn't allocate decoder instance"); - - FLAC__stream_decoder_set_md5_checking(decoder, true); - FLAC__stream_decoder_set_metadata_respond_all(decoder); - if( - (is_ogg? - FLAC__stream_decoder_init_ogg_file(decoder, filename, decoder_write_callback_, metadata_callback, decoder_error_callback_, &decoder_client_data) : - FLAC__stream_decoder_init_file(decoder, filename, decoder_write_callback_, metadata_callback, decoder_error_callback_, &decoder_client_data) - ) != FLAC__STREAM_DECODER_INIT_STATUS_OK - ) { - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - return die_("initializing decoder\n"); - } - if(!FLAC__stream_decoder_process_until_end_of_stream(decoder)) { - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - return die_("decoding file\n"); - } - - (void)FLAC__stream_decoder_finish(decoder); - FLAC__stream_decoder_delete(decoder); - - if(decoder_client_data.error_occurred) - return false; - - if(mc_our_block_number_ != our_metadata_.num_blocks) - return die_("short metadata block count"); - - printf("PASSED\n"); - return true; -} - -static FLAC__bool change_stats_(const char *filename, FLAC__bool read_only) -{ - if(!grabbag__file_change_stats(filename, read_only)) - return die_("during grabbag__file_change_stats()"); - - return true; -} - -static FLAC__bool remove_file_(const char *filename) -{ - while(our_metadata_.num_blocks > 0) - delete_from_our_metadata_(0); - - if(!grabbag__file_remove_file(filename)) - return die_("removing file"); - - return true; -} - -static FLAC__bool test_level_0_(void) -{ - FLAC__StreamMetadata streaminfo; - FLAC__StreamMetadata *tags = 0; - FLAC__StreamMetadata *cuesheet = 0; - FLAC__StreamMetadata *picture = 0; - - printf("\n\n++++++ testing level 0 interface\n"); - - if(!generate_file_(/*include_extras=*/true, /*is_ogg=*/false)) - return false; - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_null_)) - return false; - - printf("testing FLAC__metadata_get_streaminfo()... "); - - if(!FLAC__metadata_get_streaminfo(flacfilename(/*is_ogg=*/false), &streaminfo)) - return die_("during FLAC__metadata_get_streaminfo()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(streaminfo.data.stream_info.channels != 1) - return die_("mismatch in streaminfo.data.stream_info.channels"); - if(streaminfo.data.stream_info.bits_per_sample != 8) - return die_("mismatch in streaminfo.data.stream_info.bits_per_sample"); - if(streaminfo.data.stream_info.sample_rate != 44100) - return die_("mismatch in streaminfo.data.stream_info.sample_rate"); - if(streaminfo.data.stream_info.min_blocksize != 576) - return die_("mismatch in streaminfo.data.stream_info.min_blocksize"); - if(streaminfo.data.stream_info.max_blocksize != 576) - return die_("mismatch in streaminfo.data.stream_info.max_blocksize"); - - printf("OK\n"); - - printf("testing FLAC__metadata_get_tags()... "); - - if(!FLAC__metadata_get_tags(flacfilename(/*is_ogg=*/false), &tags)) - return die_("during FLAC__metadata_get_tags()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(tags->data.vorbis_comment.num_comments != 0) - return die_("mismatch in tags->data.vorbis_comment.num_comments"); - - printf("OK\n"); - - FLAC__metadata_object_delete(tags); - - printf("testing FLAC__metadata_get_cuesheet()... "); - - if(!FLAC__metadata_get_cuesheet(flacfilename(/*is_ogg=*/false), &cuesheet)) - return die_("during FLAC__metadata_get_cuesheet()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(cuesheet->data.cue_sheet.lead_in != 123) - return die_("mismatch in cuesheet->data.cue_sheet.lead_in"); - - printf("OK\n"); - - FLAC__metadata_object_delete(cuesheet); - - printf("testing FLAC__metadata_get_picture()... "); - - if(!FLAC__metadata_get_picture(flacfilename(/*is_ogg=*/false), &picture, /*type=*/(FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(uint32_t)(-1), /*max_height=*/(uint32_t)(-1), /*max_depth=*/(uint32_t)(-1), /*max_colors=*/(uint32_t)(-1))) - return die_("during FLAC__metadata_get_picture()"); - - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(picture->data.picture.type != FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER) - return die_("mismatch in picture->data.picture.type"); - - printf("OK\n"); - - FLAC__metadata_object_delete(picture); - - if(!remove_file_(flacfilename(/*is_ogg=*/false))) - return false; - - return true; -} - -static FLAC__bool test_level_1_(void) -{ - FLAC__Metadata_SimpleIterator *iterator; - FLAC__StreamMetadata *block, *app, *padding; - FLAC__byte data[1000]; - uint32_t our_current_position = 0; - - /* initialize 'data' to avoid Valgrind errors */ - memset(data, 0, sizeof(data)); - - printf("\n\n++++++ testing level 1 interface\n"); - - /************************************************************/ - - printf("simple iterator on read-only file\n"); - - if(!generate_file_(/*include_extras=*/false, /*is_ogg=*/false)) - return false; - - if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read_only=*/true)) - return false; - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_null_)) - return false; - - if(0 == (iterator = FLAC__metadata_simple_iterator_new())) - return die_("FLAC__metadata_simple_iterator_new()"); - - if(!FLAC__metadata_simple_iterator_init(iterator, flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false)) - return die_("FLAC__metadata_simple_iterator_init() returned false"); - - printf("is writable = %u\n", (uint32_t)FLAC__metadata_simple_iterator_is_writable(iterator)); - if(FLAC__metadata_simple_iterator_is_writable(iterator)) - return die_("iterator claims file is writable when tester thinks it should not be; are you running as root?\n"); - - printf("iterate forwards\n"); - - if(FLAC__metadata_simple_iterator_get_block_type(iterator) != FLAC__METADATA_TYPE_STREAMINFO) - return die_("expected STREAMINFO type from FLAC__metadata_simple_iterator_get_block_type()"); - if(0 == (block = FLAC__metadata_simple_iterator_get_block(iterator))) - return die_("getting block 0"); - if(block->type != FLAC__METADATA_TYPE_STREAMINFO) - return die_("expected STREAMINFO type"); - if(block->is_last) - return die_("expected is_last to be false"); - if(block->length != FLAC__STREAM_METADATA_STREAMINFO_LENGTH) - return die_("bad STREAMINFO length"); - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(block->data.stream_info.channels != 1) - return die_("mismatch in channels"); - if(block->data.stream_info.bits_per_sample != 8) - return die_("mismatch in bits_per_sample"); - if(block->data.stream_info.sample_rate != 44100) - return die_("mismatch in sample_rate"); - if(block->data.stream_info.min_blocksize != 576) - return die_("mismatch in min_blocksize"); - if(block->data.stream_info.max_blocksize != 576) - return die_("mismatch in max_blocksize"); - FLAC__metadata_object_delete(block); - - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("forward iterator ended early"); - our_current_position++; - - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("forward iterator ended early"); - our_current_position++; - - if(FLAC__metadata_simple_iterator_get_block_type(iterator) != FLAC__METADATA_TYPE_PADDING) - return die_("expected PADDING type from FLAC__metadata_simple_iterator_get_block_type()"); - if(0 == (block = FLAC__metadata_simple_iterator_get_block(iterator))) - return die_("getting block 2"); - if(block->type != FLAC__METADATA_TYPE_PADDING) - return die_("expected PADDING type"); - if(!block->is_last) - return die_("expected is_last to be true"); - /* check to see if some basic data matches (c.f. generate_file_()) */ - if(block->length != 1234) - return die_("bad PADDING length"); - FLAC__metadata_object_delete(block); - - if(FLAC__metadata_simple_iterator_next(iterator)) - return die_("forward iterator returned true but should have returned false"); - - printf("iterate backwards\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("reverse iterator ended early"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("reverse iterator ended early"); - if(FLAC__metadata_simple_iterator_prev(iterator)) - return die_("reverse iterator returned true but should have returned false"); - - printf("testing FLAC__metadata_simple_iterator_set_block() on read-only file...\n"); - - if(!FLAC__metadata_simple_iterator_set_block(iterator, (FLAC__StreamMetadata*)99, false)) - printf("OK: FLAC__metadata_simple_iterator_set_block() returned false like it should\n"); - else - return die_("FLAC__metadata_simple_iterator_set_block() returned true but shouldn't have"); - - FLAC__metadata_simple_iterator_delete(iterator); - - /************************************************************/ - - printf("simple iterator on writable file\n"); - - if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read-only=*/false)) - return false; - - printf("creating APPLICATION block\n"); - - if(0 == (app = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION))) - return die_("FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION)"); - memcpy(app->data.application.id, "duh", (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)); - - printf("creating PADDING block\n"); - - if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) - return die_("FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING)"); - padding->length = 20; - - if(0 == (iterator = FLAC__metadata_simple_iterator_new())) - return die_("FLAC__metadata_simple_iterator_new()"); - - if(!FLAC__metadata_simple_iterator_init(iterator, flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false)) - return die_("FLAC__metadata_simple_iterator_init() returned false"); - our_current_position = 0; - - printf("is writable = %u\n", (uint32_t)FLAC__metadata_simple_iterator_is_writable(iterator)); - - printf("[S]VP\ttry to write over STREAMINFO block...\n"); - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, false)) - printf("\tFLAC__metadata_simple_iterator_set_block() returned false like it should\n"); - else - return die_("FLAC__metadata_simple_iterator_set_block() returned true but shouldn't have"); - - if(FLAC__metadata_simple_iterator_status(iterator) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT) - return die_("FLAC__metadata_simple_iterator_status() should have been FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT"); - - printf("[S]VP\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]P\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]\tinsert PADDING after, don't expand into padding\n"); - padding->length = 25; - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false)", iterator); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return false; - - printf("SVP[P]\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SV[P]P\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("S[V]PP\tinsert PADDING after, don't expand into padding\n"); - padding->length = 30; - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false)", iterator); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return false; - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[P]PP\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("S[V]PPP\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("[S]VPPP\tdelete (STREAMINFO block), must fail\n"); - if(FLAC__metadata_simple_iterator_delete_block(iterator, false)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false) should have returned false", iterator); - - if(FLAC__metadata_simple_iterator_status(iterator) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT) - return die_("FLAC__metadata_simple_iterator_status() should have been FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT"); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("[S]VPPP\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]PPP\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]PP\tdelete (middle block), replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, true)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, true)", iterator); - our_current_position--; - - printf("S[V]PPP\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]PP\tdelete (middle block), don't replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, false)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("S[V]PP\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]P\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVP[P]\tdelete (last block), replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, true)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator); - our_current_position--; - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[P]P\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVP[P]\tdelete (last block), don't replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, false)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[P]\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("S[V]P\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("[S]VP\tset STREAMINFO (change sample rate)\n"); - FLAC__ASSERT(our_current_position == 0); - block = FLAC__metadata_simple_iterator_get_block(iterator); - block->data.stream_info.sample_rate = 32000; - if(!replace_in_our_metadata_(block, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_set_block(iterator, block, false)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, block, false)", iterator); - FLAC__metadata_object_delete(block); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("[S]VP\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]P\tinsert APPLICATION after, expand into padding of exceeding size\n"); - app->data.application.id[0] = 'e'; /* twiddle the id so that our comparison doesn't miss transposition */ - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return false; - our_metadata_.blocks[our_current_position+1]->length -= (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + app->length; - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]P\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVA[P]\tset APPLICATION, expand into padding of exceeding size\n"); - app->data.application.id[0] = 'f'; /* twiddle the id */ - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator); - if(!insert_to_our_metadata_(app, our_current_position, /*copy=*/true)) - return false; - our_metadata_.blocks[our_current_position+1]->length -= (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + app->length; - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVA[A]P\tset APPLICATION (grow), don't expand into padding\n"); - app->data.application.id[0] = 'g'; /* twiddle the id */ - if(!FLAC__metadata_object_application_set_data(app, data, sizeof(data), true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, false)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, false)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVA[A]P\tset APPLICATION (shrink), don't fill in with padding\n"); - app->data.application.id[0] = 'h'; /* twiddle the id */ - if(!FLAC__metadata_object_application_set_data(app, data, 12, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, false)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, false)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVA[A]P\tset APPLICATION (grow), expand into padding of exceeding size\n"); - app->data.application.id[0] = 'i'; /* twiddle the id */ - if(!FLAC__metadata_object_application_set_data(app, data, sizeof(data), true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - our_metadata_.blocks[our_current_position+1]->length -= (sizeof(data) - 12); - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVA[A]P\tset APPLICATION (shrink), fill in with padding\n"); - app->data.application.id[0] = 'j'; /* twiddle the id */ - if(!FLAC__metadata_object_application_set_data(app, data, 23, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!insert_to_our_metadata_(padding, our_current_position+1, /*copy=*/true)) - return die_("copying object"); - our_metadata_.blocks[our_current_position+1]->length = sizeof(data) - 23 - FLAC__STREAM_METADATA_HEADER_LENGTH; - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVA[A]PP\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVAA[P]P\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVAAP[P]\tset PADDING (shrink), don't fill in with padding\n"); - padding->length = 5; - if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_set_block(iterator, padding, false)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, padding, false)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVAAP[P]\tset APPLICATION (grow)\n"); - app->data.application.id[0] = 'k'; /* twiddle the id */ - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, false)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, false)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVAAP[A]\tset PADDING (equal)\n"); - padding->length = 27; - if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_set_block(iterator, padding, false)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, padding, false)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVAAP[P]\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SVAA[P]P\tdelete (middle block), don't replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, false)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVA[A]P\tdelete (middle block), don't replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, false)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]P\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVA[P]\tinsert PADDING after\n"); - padding->length = 5; - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false)", iterator); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return false; - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVAP[P]\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SVA[P]P\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is too small\n"); - if(!FLAC__metadata_object_application_set_data(app, data, 32, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is 'close' but still too small\n"); - if(!FLAC__metadata_object_application_set_data(app, data, 60, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]PP\tset APPLICATION (grow), expand into padding which will leave 0-length pad\n"); - if(!FLAC__metadata_object_application_set_data(app, data, 87, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - our_metadata_.blocks[our_current_position+1]->length = 0; - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]PP\tset APPLICATION (grow), expand into padding which is exactly consumed\n"); - if(!FLAC__metadata_object_application_set_data(app, data, 91, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - delete_from_our_metadata_(our_current_position+1); - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]P\tset APPLICATION (grow), expand into padding which is exactly consumed\n"); - if(!FLAC__metadata_object_application_set_data(app, data, 100, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - delete_from_our_metadata_(our_current_position+1); - our_metadata_.blocks[our_current_position]->is_last = true; - if(!FLAC__metadata_simple_iterator_set_block(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]\tset PADDING (equal size)\n"); - padding->length = app->length; - if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_set_block(iterator, padding, true)) - return die_ss_("FLAC__metadata_simple_iterator_set_block(iterator, padding, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[P]\tinsert PADDING after\n"); - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false)", iterator); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return false; - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVP[P]\tinsert PADDING after\n"); - padding->length = 5; - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, padding, false)", iterator); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return false; - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SVPP[P]\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SVP[P]P\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("SV[P]PP\tprev\n"); - if(!FLAC__metadata_simple_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is too small\n"); - if(!FLAC__metadata_object_application_set_data(app, data, 101, true)) - return die_("setting APPLICATION data"); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, false)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is 'close' but still too small\n"); - if(!FLAC__metadata_object_application_set_data(app, data, 97, true)) - return die_("setting APPLICATION data"); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, false)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("S[V]PPP\tinsert APPLICATION after, expand into padding which is exactly consumed\n"); - if(!FLAC__metadata_object_application_set_data(app, data, 100, true)) - return die_("setting APPLICATION data"); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return die_("copying object"); - delete_from_our_metadata_(our_current_position+1); - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]PP\tdelete (middle block), don't replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, false)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("S[V]PP\tinsert APPLICATION after, expand into padding which will leave 0-length pad\n"); - if(!FLAC__metadata_object_application_set_data(app, data, 96, true)) - return die_("setting APPLICATION data"); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return die_("copying object"); - our_metadata_.blocks[our_current_position+1]->length = 0; - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]PP\tdelete (middle block), don't replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, false)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("S[V]PP\tnext\n"); - if(!FLAC__metadata_simple_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]P\tdelete (middle block), don't replace with padding\n"); - if(!FLAC__metadata_simple_iterator_delete_block(iterator, false)) - return die_ss_("FLAC__metadata_simple_iterator_delete_block(iterator, false)", iterator); - delete_from_our_metadata_(our_current_position--); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("S[V]P\tinsert APPLICATION after, expand into padding which is exactly consumed\n"); - if(!FLAC__metadata_object_application_set_data(app, data, 1, true)) - return die_("setting APPLICATION data"); - if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true)) - return die_("copying object"); - delete_from_our_metadata_(our_current_position+1); - if(!FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)) - return die_ss_("FLAC__metadata_simple_iterator_insert_block_after(iterator, app, true)", iterator); - - if(!test_file_(/*is_ogg=*/false, decoder_metadata_callback_compare_)) - return false; - - printf("delete simple iterator\n"); - - FLAC__metadata_simple_iterator_delete(iterator); - - FLAC__metadata_object_delete(app); - FLAC__metadata_object_delete(padding); - - if(!remove_file_(flacfilename(/*is_ogg=*/false))) - return false; - - return true; -} - -static FLAC__bool test_level_2_(FLAC__bool filename_based, FLAC__bool is_ogg) -{ - FLAC__Metadata_Iterator *iterator; - FLAC__Metadata_Chain *chain; - FLAC__StreamMetadata *block, *app, *padding; - FLAC__byte data[2000]; - uint32_t our_current_position; - - /* initialize 'data' to avoid Valgrind errors */ - memset(data, 0, sizeof(data)); - - printf("\n\n++++++ testing level 2 interface (%s-based, %s FLAC)\n", filename_based? "filename":"callback", is_ogg? "Ogg":"native"); - - printf("generate read-only file\n"); - - if(!generate_file_(/*include_extras=*/false, is_ogg)) - return false; - - if(!change_stats_(flacfilename(is_ogg), /*read_only=*/true)) - return false; - - printf("create chain\n"); - - if(0 == (chain = FLAC__metadata_chain_new())) - return die_("allocating chain"); - - printf("read chain\n"); - - if(!read_chain_(chain, flacfilename(is_ogg), filename_based, is_ogg)) - return die_c_("reading chain", FLAC__metadata_chain_status(chain)); - - printf("[S]VP\ttest initial metadata\n"); - - if(!compare_chain_(chain, 0, 0)) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - if(is_ogg) - goto end; - - printf("switch file to read-write\n"); - - if(!change_stats_(flacfilename(is_ogg), /*read-only=*/false)) - return false; - - printf("create iterator\n"); - if(0 == (iterator = FLAC__metadata_iterator_new())) - return die_("allocating memory for iterator"); - - our_current_position = 0; - - FLAC__metadata_iterator_init(iterator, chain); - - if(0 == (block = FLAC__metadata_iterator_get_block(iterator))) - return die_("getting block from iterator"); - - FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_STREAMINFO); - - printf("[S]VP\tmodify STREAMINFO, write\n"); - - block->data.stream_info.sample_rate = 32000; - if(!replace_in_our_metadata_(block, our_current_position, /*copy=*/true)) - return die_("copying object"); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/true, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, false, true)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("[S]VP\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]P\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]\treplace PADDING with identical-size APPLICATION\n"); - if(0 == (block = FLAC__metadata_iterator_get_block(iterator))) - return die_("getting block from iterator"); - if(0 == (app = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION))) - return die_("FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION)"); - memcpy(app->data.application.id, "duh", (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)); - if(!FLAC__metadata_object_application_set_data(app, data, block->length-(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_iterator_set_block(iterator, app)) - return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain)); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]\tshrink APPLICATION, don't use padding\n"); - if(0 == (app = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("copying object"); - if(!FLAC__metadata_object_application_set_data(app, data, 26, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_iterator_set_block(iterator, app)) - return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain)); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]\tgrow APPLICATION, don't use padding\n"); - if(0 == (app = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("copying object"); - if(!FLAC__metadata_object_application_set_data(app, data, 28, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_iterator_set_block(iterator, app)) - return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain)); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]\tgrow APPLICATION, use padding, but last block is not padding\n"); - if(0 == (app = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("copying object"); - if(!FLAC__metadata_object_application_set_data(app, data, 36, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_iterator_set_block(iterator, app)) - return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain)); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, but delta is too small for new PADDING block\n"); - if(0 == (app = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("copying object"); - if(!FLAC__metadata_object_application_set_data(app, data, 33, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_iterator_set_block(iterator, app)) - return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain)); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, delta is enough for new PADDING block\n"); - if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) - return die_("creating PADDING block"); - if(0 == (app = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("copying object"); - if(!FLAC__metadata_object_application_set_data(app, data, 29, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - padding->length = 0; - if(!insert_to_our_metadata_(padding, our_current_position+1, /*copy=*/false)) - return die_("internal error"); - if(!FLAC__metadata_iterator_set_block(iterator, app)) - return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain)); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]P\tshrink APPLICATION, use padding, last block is padding\n"); - if(0 == (app = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("copying object"); - if(!FLAC__metadata_object_application_set_data(app, data, 16, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - our_metadata_.blocks[our_current_position+1]->length = 13; - if(!FLAC__metadata_iterator_set_block(iterator, app)) - return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain)); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding, but delta is too small\n"); - if(0 == (app = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("copying object"); - if(!FLAC__metadata_object_application_set_data(app, data, 50, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - if(!FLAC__metadata_iterator_set_block(iterator, app)) - return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain)); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exceeding size\n"); - if(0 == (app = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("copying object"); - if(!FLAC__metadata_object_application_set_data(app, data, 56, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - our_metadata_.blocks[our_current_position+1]->length -= (56 - 50); - if(!FLAC__metadata_iterator_set_block(iterator, app)) - return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain)); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exact size\n"); - if(0 == (app = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("copying object"); - if(!FLAC__metadata_object_application_set_data(app, data, 67, true)) - return die_("setting APPLICATION data"); - if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true)) - return die_("copying object"); - delete_from_our_metadata_(our_current_position+1); - if(!FLAC__metadata_iterator_set_block(iterator, app)) - return die_c_("FLAC__metadata_iterator_set_block(iterator, app)", FLAC__metadata_chain_status(chain)); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV[A]\tprev\n"); - if(!FLAC__metadata_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("S[V]A\tprev\n"); - if(!FLAC__metadata_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("[S]VA\tinsert PADDING before STREAMINFO (should fail)\n"); - if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) - return die_("creating PADDING block"); - padding->length = 30; - if(!FLAC__metadata_iterator_insert_block_before(iterator, padding)) - printf("\tFLAC__metadata_iterator_insert_block_before() returned false like it should\n"); - else - return die_("FLAC__metadata_iterator_insert_block_before() should have returned false"); - - printf("[S]VP\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]A\tinsert PADDING after\n"); - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return die_("copying metadata"); - if(!FLAC__metadata_iterator_insert_block_after(iterator, padding)) - return die_("FLAC__metadata_iterator_insert_block_after(iterator, padding)"); - - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - - printf("SV[P]A\tinsert PADDING before\n"); - if(0 == (padding = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("creating PADDING block"); - padding->length = 17; - if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying metadata"); - if(!FLAC__metadata_iterator_insert_block_before(iterator, padding)) - return die_("FLAC__metadata_iterator_insert_block_before(iterator, padding)"); - - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - - printf("SV[P]PA\tinsert PADDING before\n"); - if(0 == (padding = FLAC__metadata_object_clone(our_metadata_.blocks[our_current_position]))) - return die_("creating PADDING block"); - padding->length = 0; - if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying metadata"); - if(!FLAC__metadata_iterator_insert_block_before(iterator, padding)) - return die_("FLAC__metadata_iterator_insert_block_before(iterator, padding)"); - - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - - printf("SV[P]PPA\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVP[P]PA\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVPP[P]A\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SVPPP[A]\tinsert PADDING after\n"); - if(0 == (padding = FLAC__metadata_object_clone(our_metadata_.blocks[2]))) - return die_("creating PADDING block"); - padding->length = 57; - if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true)) - return die_("copying metadata"); - if(!FLAC__metadata_iterator_insert_block_after(iterator, padding)) - return die_("FLAC__metadata_iterator_insert_block_after(iterator, padding)"); - - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - - printf("SVPPPA[P]\tinsert PADDING before\n"); - if(0 == (padding = FLAC__metadata_object_clone(our_metadata_.blocks[2]))) - return die_("creating PADDING block"); - padding->length = 99; - if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true)) - return die_("copying metadata"); - if(!FLAC__metadata_iterator_insert_block_before(iterator, padding)) - return die_("FLAC__metadata_iterator_insert_block_before(iterator, padding)"); - - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - - printf("delete iterator\n"); - FLAC__metadata_iterator_delete(iterator); - our_current_position = 0; - - printf("SVPPPAPP\tmerge padding\n"); - FLAC__metadata_chain_merge_padding(chain); - our_metadata_.blocks[2]->length += (FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[3]->length); - our_metadata_.blocks[2]->length += (FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[4]->length); - our_metadata_.blocks[6]->length += (FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[7]->length); - delete_from_our_metadata_(7); - delete_from_our_metadata_(4); - delete_from_our_metadata_(3); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, 0, 0)) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SVPAP\tsort padding\n"); - FLAC__metadata_chain_sort_padding(chain); - our_metadata_.blocks[4]->length += (FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[2]->length); - delete_from_our_metadata_(2); - - if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, true, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, 0, 0)) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("create iterator\n"); - if(0 == (iterator = FLAC__metadata_iterator_new())) - return die_("allocating memory for iterator"); - - our_current_position = 0; - - FLAC__metadata_iterator_init(iterator, chain); - - printf("[S]VAP\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("S[V]AP\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[A]P\tdelete middle block, replace with padding\n"); - if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) - return die_("creating PADDING block"); - padding->length = 71; - if(!replace_in_our_metadata_(padding, our_current_position--, /*copy=*/false)) - return die_("copying object"); - if(!FLAC__metadata_iterator_delete_block(iterator, /*replace_with_padding=*/true)) - return die_c_("FLAC__metadata_iterator_delete_block(iterator, true)", FLAC__metadata_chain_status(chain)); - - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - - printf("S[V]PP\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]P\tdelete middle block, don't replace with padding\n"); - delete_from_our_metadata_(our_current_position--); - if(!FLAC__metadata_iterator_delete_block(iterator, /*replace_with_padding=*/false)) - return die_c_("FLAC__metadata_iterator_delete_block(iterator, false)", FLAC__metadata_chain_status(chain)); - - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - - printf("S[V]P\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]\tdelete last block, replace with padding\n"); - if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) - return die_("creating PADDING block"); - padding->length = 219; - if(!replace_in_our_metadata_(padding, our_current_position--, /*copy=*/false)) - return die_("copying object"); - if(!FLAC__metadata_iterator_delete_block(iterator, /*replace_with_padding=*/true)) - return die_c_("FLAC__metadata_iterator_delete_block(iterator, true)", FLAC__metadata_chain_status(chain)); - - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - - printf("S[V]P\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - our_current_position++; - - printf("SV[P]\tdelete last block, don't replace with padding\n"); - delete_from_our_metadata_(our_current_position--); - if(!FLAC__metadata_iterator_delete_block(iterator, /*replace_with_padding=*/false)) - return die_c_("FLAC__metadata_iterator_delete_block(iterator, false)", FLAC__metadata_chain_status(chain)); - - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - - printf("S[V]\tprev\n"); - if(!FLAC__metadata_iterator_prev(iterator)) - return die_("iterator ended early\n"); - our_current_position--; - - printf("[S]V\tdelete STREAMINFO block, should fail\n"); - if(FLAC__metadata_iterator_delete_block(iterator, /*replace_with_padding=*/false)) - return die_("FLAC__metadata_iterator_delete_block() on STREAMINFO should have failed but didn't"); - - if(!compare_chain_(chain, our_current_position, FLAC__metadata_iterator_get_block(iterator))) - return false; - - printf("delete iterator\n"); - FLAC__metadata_iterator_delete(iterator); - our_current_position = 0; - - printf("SV\tmerge padding\n"); - FLAC__metadata_chain_merge_padding(chain); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, 0, 0)) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - - printf("SV\tsort padding\n"); - FLAC__metadata_chain_sort_padding(chain); - - if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg))) - return die_c_("during FLAC__metadata_chain_write(chain, false, false)", FLAC__metadata_chain_status(chain)); - if(!compare_chain_(chain, 0, 0)) - return false; - if(!test_file_(is_ogg, decoder_metadata_callback_compare_)) - return false; - -end: - printf("delete chain\n"); - - FLAC__metadata_chain_delete(chain); - - if(!remove_file_(flacfilename(is_ogg))) - return false; - - return true; -} - -static FLAC__bool test_level_2_misc_(FLAC__bool is_ogg) -{ - FLAC__Metadata_Iterator *iterator; - FLAC__Metadata_Chain *chain; - FLAC__IOCallbacks callbacks; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.read = (FLAC__IOCallback_Read)fread; -#ifdef FLAC__VALGRIND_TESTING - callbacks.write = chain_write_cb_; -#else - callbacks.write = (FLAC__IOCallback_Write)fwrite; -#endif - callbacks.seek = chain_seek_cb_; - callbacks.tell = chain_tell_cb_; - callbacks.eof = chain_eof_cb_; - - printf("\n\n++++++ testing level 2 interface (mismatched read/write protections)\n"); - - printf("generate file\n"); - - if(!generate_file_(/*include_extras=*/false, is_ogg)) - return false; - - printf("create chain\n"); - - if(0 == (chain = FLAC__metadata_chain_new())) - return die_("allocating chain"); - - printf("read chain (filename-based)\n"); - - if(!FLAC__metadata_chain_read(chain, flacfilename(is_ogg))) - return die_c_("reading chain", FLAC__metadata_chain_status(chain)); - - printf("write chain with wrong method FLAC__metadata_chain_write_with_callbacks()\n"); - { - if(FLAC__metadata_chain_write_with_callbacks(chain, /*use_padding=*/false, 0, callbacks)) - return die_c_("mismatched write should have failed", FLAC__metadata_chain_status(chain)); - if(FLAC__metadata_chain_status(chain) != FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH) - return die_c_("expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", FLAC__metadata_chain_status(chain)); - printf(" OK: FLAC__metadata_chain_write_with_callbacks() returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should\n"); - } - - printf("read chain (filename-based)\n"); - - if(!FLAC__metadata_chain_read(chain, flacfilename(is_ogg))) - return die_c_("reading chain", FLAC__metadata_chain_status(chain)); - - printf("write chain with wrong method FLAC__metadata_chain_write_with_callbacks_and_tempfile()\n"); - { - if(FLAC__metadata_chain_write_with_callbacks_and_tempfile(chain, /*use_padding=*/false, 0, callbacks, 0, callbacks)) - return die_c_("mismatched write should have failed", FLAC__metadata_chain_status(chain)); - if(FLAC__metadata_chain_status(chain) != FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH) - return die_c_("expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", FLAC__metadata_chain_status(chain)); - printf(" OK: FLAC__metadata_chain_write_with_callbacks_and_tempfile() returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should\n"); - } - - printf("read chain (callback-based)\n"); - { - FILE *file = flac_fopen(flacfilename(is_ogg), "rb"); - if(0 == file) - return die_("opening file"); - if(!FLAC__metadata_chain_read_with_callbacks(chain, (FLAC__IOHandle)file, callbacks)) { - fclose(file); - return die_c_("reading chain", FLAC__metadata_chain_status(chain)); - } - fclose(file); - } - - printf("write chain with wrong method FLAC__metadata_chain_write()\n"); - { - if(FLAC__metadata_chain_write(chain, /*use_padding=*/false, /*preserve_file_stats=*/false)) - return die_c_("mismatched write should have failed", FLAC__metadata_chain_status(chain)); - if(FLAC__metadata_chain_status(chain) != FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH) - return die_c_("expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", FLAC__metadata_chain_status(chain)); - printf(" OK: FLAC__metadata_chain_write() returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should\n"); - } - - printf("read chain (callback-based)\n"); - { - FILE *file = flac_fopen(flacfilename(is_ogg), "rb"); - if(0 == file) - return die_("opening file"); - if(!FLAC__metadata_chain_read_with_callbacks(chain, (FLAC__IOHandle)file, callbacks)) { - fclose(file); - return die_c_("reading chain", FLAC__metadata_chain_status(chain)); - } - fclose(file); - } - - printf("testing FLAC__metadata_chain_check_if_tempfile_needed()... "); - - if(!FLAC__metadata_chain_check_if_tempfile_needed(chain, /*use_padding=*/false)) - printf("OK: FLAC__metadata_chain_check_if_tempfile_needed() returned false like it should\n"); - else - return die_("FLAC__metadata_chain_check_if_tempfile_needed() returned true but shouldn't have"); - - printf("write chain with wrong method FLAC__metadata_chain_write_with_callbacks_and_tempfile()\n"); - { - if(FLAC__metadata_chain_write_with_callbacks_and_tempfile(chain, /*use_padding=*/false, 0, callbacks, 0, callbacks)) - return die_c_("mismatched write should have failed", FLAC__metadata_chain_status(chain)); - if(FLAC__metadata_chain_status(chain) != FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL) - return die_c_("expected FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL", FLAC__metadata_chain_status(chain)); - printf(" OK: FLAC__metadata_chain_write_with_callbacks_and_tempfile() returned false,FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL like it should\n"); - } - - printf("read chain (callback-based)\n"); - { - FILE *file = flac_fopen(flacfilename(is_ogg), "rb"); - if(0 == file) - return die_("opening file"); - if(!FLAC__metadata_chain_read_with_callbacks(chain, (FLAC__IOHandle)file, callbacks)) { - fclose(file); - return die_c_("reading chain", FLAC__metadata_chain_status(chain)); - } - fclose(file); - } - - printf("create iterator\n"); - if(0 == (iterator = FLAC__metadata_iterator_new())) - return die_("allocating memory for iterator"); - - FLAC__metadata_iterator_init(iterator, chain); - - printf("[S]VP\tnext\n"); - if(!FLAC__metadata_iterator_next(iterator)) - return die_("iterator ended early\n"); - - printf("S[V]P\tdelete VORBIS_COMMENT, write\n"); - if(!FLAC__metadata_iterator_delete_block(iterator, /*replace_with_padding=*/false)) - return die_c_("block delete failed\n", FLAC__metadata_chain_status(chain)); - - printf("testing FLAC__metadata_chain_check_if_tempfile_needed()... "); - - if(FLAC__metadata_chain_check_if_tempfile_needed(chain, /*use_padding=*/false)) - printf("OK: FLAC__metadata_chain_check_if_tempfile_needed() returned true like it should\n"); - else - return die_("FLAC__metadata_chain_check_if_tempfile_needed() returned false but shouldn't have"); - - printf("write chain with wrong method FLAC__metadata_chain_write_with_callbacks()\n"); - { - if(FLAC__metadata_chain_write_with_callbacks(chain, /*use_padding=*/false, 0, callbacks)) - return die_c_("mismatched write should have failed", FLAC__metadata_chain_status(chain)); - if(FLAC__metadata_chain_status(chain) != FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL) - return die_c_("expected FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL", FLAC__metadata_chain_status(chain)); - printf(" OK: FLAC__metadata_chain_write_with_callbacks() returned false,FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL like it should\n"); - } - - printf("delete iterator\n"); - - FLAC__metadata_iterator_delete(iterator); - - printf("delete chain\n"); - - FLAC__metadata_chain_delete(chain); - - if(!remove_file_(flacfilename(is_ogg))) - return false; - - return true; -} - -FLAC__bool test_metadata_file_manipulation(void) -{ - printf("\n+++ libFLAC unit test: metadata manipulation\n\n"); - - our_metadata_.num_blocks = 0; - - if(!test_level_0_()) - return false; - - if(!test_level_1_()) - return false; - - if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/false)) /* filename-based */ - return false; - if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/false)) /* callback-based */ - return false; - if(!test_level_2_misc_(/*is_ogg=*/false)) - return false; - - if(FLAC_API_SUPPORTS_OGG_FLAC) { - if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/true)) /* filename-based */ - return false; - if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/true)) /* callback-based */ - return false; -#if 0 - /* when ogg flac write is supported, will have to add this: */ - if(!test_level_2_misc_(/*is_ogg=*/true)) - return false; -#endif - } - - return true; -} diff --git a/flac/src/test_libFLAC/metadata_object.c b/flac/src/test_libFLAC/metadata_object.c deleted file mode 100644 index ea6b69f..0000000 --- a/flac/src/test_libFLAC/metadata_object.c +++ /dev/null @@ -1,2291 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "FLAC/assert.h" -#include "FLAC/metadata.h" -#include "test_libs_common/metadata_utils.h" -#include "share/compat.h" -#include "metadata.h" -#include -#include /* for malloc() */ -#include /* for memcmp() */ - -static FLAC__byte *make_dummydata_(FLAC__byte *dummydata, uint32_t len) -{ - FLAC__byte *ret; - - if(0 == (ret = malloc(len))) { - printf("FAILED, malloc error\n"); - exit(1); - } - else - memcpy(ret, dummydata, len); - - return ret; -} - -static FLAC__bool compare_track_(const FLAC__StreamMetadata_CueSheet_Track *from, const FLAC__StreamMetadata_CueSheet_Track *to) -{ - uint32_t i; - - if(from->offset != to->offset) { - printf("FAILED, track offset mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", to->offset, from->offset); - return false; - } - if(from->number != to->number) { - printf("FAILED, track number mismatch, expected %u, got %u\n", (uint32_t)to->number, (uint32_t)from->number); - return false; - } - if(0 != strcmp(from->isrc, to->isrc)) { - printf("FAILED, track number mismatch, expected %s, got %s\n", to->isrc, from->isrc); - return false; - } - if(from->type != to->type) { - printf("FAILED, track type mismatch, expected %u, got %u\n", (uint32_t)to->type, (uint32_t)from->type); - return false; - } - if(from->pre_emphasis != to->pre_emphasis) { - printf("FAILED, track pre_emphasis mismatch, expected %u, got %u\n", (uint32_t)to->pre_emphasis, (uint32_t)from->pre_emphasis); - return false; - } - if(from->num_indices != to->num_indices) { - printf("FAILED, track num_indices mismatch, expected %u, got %u\n", (uint32_t)to->num_indices, (uint32_t)from->num_indices); - return false; - } - if(0 == to->indices || 0 == from->indices) { - if(to->indices != from->indices) { - printf("FAILED, track indices mismatch\n"); - return false; - } - } - else { - for(i = 0; i < to->num_indices; i++) { - if(from->indices[i].offset != to->indices[i].offset) { - printf("FAILED, track indices[%u].offset mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", i, to->indices[i].offset, from->indices[i].offset); - return false; - } - if(from->indices[i].number != to->indices[i].number) { - printf("FAILED, track indices[%u].number mismatch, expected %u, got %u\n", i, (uint32_t)to->indices[i].number, (uint32_t)from->indices[i].number); - return false; - } - } - } - - return true; -} - -static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetadata_SeekPoint *from, const FLAC__StreamMetadata_SeekPoint *to, uint32_t n) -{ - uint32_t i; - - FLAC__ASSERT(0 != from); - FLAC__ASSERT(0 != to); - - for(i = 0; i < n; i++) { - if(from[i].sample_number != to[i].sample_number) { - printf("FAILED, point[%u].sample_number mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", i, to[i].sample_number, from[i].sample_number); - return false; - } - if(from[i].stream_offset != to[i].stream_offset) { - printf("FAILED, point[%u].stream_offset mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", i, to[i].stream_offset, from[i].stream_offset); - return false; - } - if(from[i].frame_samples != to[i].frame_samples) { - printf("FAILED, point[%u].frame_samples mismatch, expected %u, got %u\n", i, to[i].frame_samples, from[i].frame_samples); - return false; - } - } - - return true; -} - -static FLAC__bool check_seektable_(const FLAC__StreamMetadata *block, uint32_t num_points, const FLAC__StreamMetadata_SeekPoint *array) -{ - const uint32_t expected_length = num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH; - - if(block->length != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length); - return false; - } - if(block->data.seek_table.num_points != num_points) { - printf("FAILED, expected %u point, got %u\n", num_points, block->data.seek_table.num_points); - return false; - } - if(0 == array) { - if(0 != block->data.seek_table.points) { - printf("FAILED, 'points' pointer is not null\n"); - return false; - } - } - else { - if(!compare_seekpoint_array_(block->data.seek_table.points, array, num_points)) - return false; - } - printf("OK\n"); - - return true; -} - -static void entry_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field) -{ - entry->length = strlen(field); - entry->entry = malloc(entry->length+1); - FLAC__ASSERT(0 != entry->entry); - memcpy(entry->entry, field, entry->length); - entry->entry[entry->length] = '\0'; -} - -static void entry_clone_(FLAC__StreamMetadata_VorbisComment_Entry *entry) -{ - FLAC__byte *x = malloc(entry->length+1); - FLAC__ASSERT(0 != x); - memcpy(x, entry->entry, entry->length); - x[entry->length] = '\0'; - entry->entry = x; -} - -static void vc_calc_len_(FLAC__StreamMetadata *block) -{ - const FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment; - uint32_t i; - - block->length = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8; - block->length += vc->vendor_string.length; - block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8; - for(i = 0; i < vc->num_comments; i++) { - block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8; - block->length += vc->comments[i].length; - } -} - -static void vc_resize_(FLAC__StreamMetadata *block, uint32_t num) -{ - FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment; - - if(vc->num_comments != 0) { - FLAC__ASSERT(0 != vc->comments); - if(num < vc->num_comments) { - uint32_t i; - for(i = num; i < vc->num_comments; i++) { - if(0 != vc->comments[i].entry) - free(vc->comments[i].entry); - } - } - } - if(num == 0) { - if(0 != vc->comments) { - free(vc->comments); - vc->comments = 0; - } - } - else { - uint32_t i; - vc->comments = realloc(vc->comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*num); - FLAC__ASSERT(0 != vc->comments); - for(i = vc->num_comments; i < num; i++) { - vc->comments[i].length = 0; - vc->comments[i].entry = malloc(1); - vc->comments[i].entry[0] = '\0'; - } - } - - vc->num_comments = num; - vc_calc_len_(block); -} - -static int vc_find_from_(FLAC__StreamMetadata *block, const char *name, uint32_t start) -{ - const uint32_t n = strlen(name); - uint32_t i; - for(i = start; i < block->data.vorbis_comment.num_comments; i++) { - const FLAC__StreamMetadata_VorbisComment_Entry *entry = &block->data.vorbis_comment.comments[i]; - if(entry->length > n && 0 == strncmp((const char *)entry->entry, name, n) && entry->entry[n] == '=') - return (int)i; - } - return -1; -} - -static void vc_set_vs_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field) -{ - if(0 != block->data.vorbis_comment.vendor_string.entry) - free(block->data.vorbis_comment.vendor_string.entry); - entry_new_(entry, field); - block->data.vorbis_comment.vendor_string = *entry; - vc_calc_len_(block); -} - -static void vc_set_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, uint32_t pos, const char *field) -{ - if(0 != block->data.vorbis_comment.comments[pos].entry) - free(block->data.vorbis_comment.comments[pos].entry); - entry_new_(entry, field); - block->data.vorbis_comment.comments[pos] = *entry; - vc_calc_len_(block); -} - -static void vc_insert_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, uint32_t pos, const char *field) -{ - FLAC__StreamMetadata_VorbisComment_Entry temp; - vc_resize_(block, block->data.vorbis_comment.num_comments+1); - temp = block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1]; - memmove(&block->data.vorbis_comment.comments[pos+1], &block->data.vorbis_comment.comments[pos], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(block->data.vorbis_comment.num_comments-1-pos)); - block->data.vorbis_comment.comments[pos] = temp; - vc_set_new_(entry, block, pos, field); - vc_calc_len_(block); -} - -static void vc_delete_(FLAC__StreamMetadata *block, uint32_t pos) -{ - if(0 != block->data.vorbis_comment.comments[pos].entry) - free(block->data.vorbis_comment.comments[pos].entry); - memmove(&block->data.vorbis_comment.comments[pos], &block->data.vorbis_comment.comments[pos+1], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(block->data.vorbis_comment.num_comments-pos-1)); - block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].entry = 0; - block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].length = 0; - vc_resize_(block, block->data.vorbis_comment.num_comments-1); - vc_calc_len_(block); -} - -static void vc_replace_new_(FLAC__StreamMetadata_VorbisComment_Entry *entry, FLAC__StreamMetadata *block, const char *field, FLAC__bool all) -{ - int indx; - char field_name[256]; - const char *eq = strchr(field, '='); - FLAC__ASSERT(eq>field && (uint32_t)(eq-field) < sizeof(field_name)); - memcpy(field_name, field, eq-field); - field_name[eq-field]='\0'; - - indx = vc_find_from_(block, field_name, 0); - if(indx < 0) - vc_insert_new_(entry, block, block->data.vorbis_comment.num_comments, field); - else { - vc_set_new_(entry, block, (uint32_t)indx, field); - if(all) { - for(indx = indx+1; indx >= 0 && (uint32_t)indx < block->data.vorbis_comment.num_comments; ) - if((indx = vc_find_from_(block, field_name, (uint32_t)indx)) >= 0) - vc_delete_(block, (uint32_t)indx); - } - } - - vc_calc_len_(block); -} - -static void track_new_(FLAC__StreamMetadata_CueSheet_Track *track, FLAC__uint64 offset, FLAC__byte number, const char *isrc, FLAC__bool data, FLAC__bool pre_em) -{ - track->offset = offset; - track->number = number; - memcpy(track->isrc, isrc, sizeof(track->isrc)); - track->type = data; - track->pre_emphasis = pre_em; - track->num_indices = 0; - track->indices = 0; -} - -static void track_clone_(FLAC__StreamMetadata_CueSheet_Track *track) -{ - if(track->num_indices > 0) { - size_t bytes = sizeof(FLAC__StreamMetadata_CueSheet_Index) * track->num_indices; - FLAC__StreamMetadata_CueSheet_Index *x = malloc(bytes); - FLAC__ASSERT(0 != x); - memcpy(x, track->indices, bytes); - track->indices = x; - } -} - -static void cs_calc_len_(FLAC__StreamMetadata *block) -{ - const FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet; - uint32_t i; - - block->length = ( - FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN + - FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + - FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN - ) / 8; - block->length += cs->num_tracks * ( - FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN - ) / 8; - for(i = 0; i < cs->num_tracks; i++) { - block->length += cs->tracks[i].num_indices * ( - FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN + - FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN - ) / 8; - } -} - -static void tr_resize_(FLAC__StreamMetadata *block, uint32_t track_num, uint32_t num) -{ - FLAC__StreamMetadata_CueSheet_Track *tr; - - FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks); - - tr = &block->data.cue_sheet.tracks[track_num]; - - if(tr->num_indices != 0) { - FLAC__ASSERT(0 != tr->indices); - } - if(num == 0) { - if(0 != tr->indices) { - free(tr->indices); - tr->indices = 0; - } - } - else { - tr->indices = realloc(tr->indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)*num); - FLAC__ASSERT(0 != tr->indices); - if(num > tr->num_indices) - memset(tr->indices+tr->num_indices, 0, sizeof(FLAC__StreamMetadata_CueSheet_Index)*(num-tr->num_indices)); - } - - tr->num_indices = num; - cs_calc_len_(block); -} - -static void tr_set_new_(FLAC__StreamMetadata *block, uint32_t track_num, uint32_t pos, FLAC__StreamMetadata_CueSheet_Index indx) -{ - FLAC__StreamMetadata_CueSheet_Track *tr; - - FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks); - - tr = &block->data.cue_sheet.tracks[track_num]; - - FLAC__ASSERT(pos < tr->num_indices); - - tr->indices[pos] = indx; - - cs_calc_len_(block); -} - -static void tr_insert_new_(FLAC__StreamMetadata *block, uint32_t track_num, uint32_t pos, FLAC__StreamMetadata_CueSheet_Index indx) -{ - FLAC__StreamMetadata_CueSheet_Track *tr; - - FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks); - - tr = &block->data.cue_sheet.tracks[track_num]; - - FLAC__ASSERT(pos <= tr->num_indices); - - tr_resize_(block, track_num, tr->num_indices+1); - memmove(&tr->indices[pos+1], &tr->indices[pos], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-1-pos)); - tr_set_new_(block, track_num, pos, indx); - cs_calc_len_(block); -} - -static void tr_delete_(FLAC__StreamMetadata *block, uint32_t track_num, uint32_t pos) -{ - FLAC__StreamMetadata_CueSheet_Track *tr; - - FLAC__ASSERT(track_num < block->data.cue_sheet.num_tracks); - - tr = &block->data.cue_sheet.tracks[track_num]; - - FLAC__ASSERT(pos <= tr->num_indices); - - memmove(&tr->indices[pos], &tr->indices[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(tr->num_indices-pos-1)); - tr_resize_(block, track_num, tr->num_indices-1); - cs_calc_len_(block); -} - -static void cs_resize_(FLAC__StreamMetadata *block, uint32_t num) -{ - FLAC__StreamMetadata_CueSheet *cs = &block->data.cue_sheet; - - if(cs->num_tracks != 0) { - FLAC__ASSERT(0 != cs->tracks); - if(num < cs->num_tracks) { - uint32_t i; - for(i = num; i < cs->num_tracks; i++) { - if(0 != cs->tracks[i].indices) - free(cs->tracks[i].indices); - } - } - } - if(num == 0) { - if(0 != cs->tracks) { - free(cs->tracks); - cs->tracks = 0; - } - } - else { - cs->tracks = realloc(cs->tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)*num); - FLAC__ASSERT(0 != cs->tracks); - if(num > cs->num_tracks) - memset(cs->tracks+cs->num_tracks, 0, sizeof(FLAC__StreamMetadata_CueSheet_Track)*(num-cs->num_tracks)); - } - - cs->num_tracks = num; - cs_calc_len_(block); -} - -static void cs_set_new_(FLAC__StreamMetadata_CueSheet_Track *track, FLAC__StreamMetadata *block, uint32_t pos, FLAC__uint64 offset, FLAC__byte number, const char *isrc, FLAC__bool data, FLAC__bool pre_em) -{ - track_new_(track, offset, number, isrc, data, pre_em); - block->data.cue_sheet.tracks[pos] = *track; - cs_calc_len_(block); -} - -static void cs_insert_new_(FLAC__StreamMetadata_CueSheet_Track *track, FLAC__StreamMetadata *block, uint32_t pos, FLAC__uint64 offset, FLAC__byte number, const char *isrc, FLAC__bool data, FLAC__bool pre_em) -{ - cs_resize_(block, block->data.cue_sheet.num_tracks+1); - memmove(&block->data.cue_sheet.tracks[pos+1], &block->data.cue_sheet.tracks[pos], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(block->data.cue_sheet.num_tracks-1-pos)); - cs_set_new_(track, block, pos, offset, number, isrc, data, pre_em); - cs_calc_len_(block); -} - -static void cs_delete_(FLAC__StreamMetadata *block, uint32_t pos) -{ - if(0 != block->data.cue_sheet.tracks[pos].indices) - free(block->data.cue_sheet.tracks[pos].indices); - memmove(&block->data.cue_sheet.tracks[pos], &block->data.cue_sheet.tracks[pos+1], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(block->data.cue_sheet.num_tracks-pos-1)); - block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].indices = 0; - block->data.cue_sheet.tracks[block->data.cue_sheet.num_tracks-1].num_indices = 0; - cs_resize_(block, block->data.cue_sheet.num_tracks-1); - cs_calc_len_(block); -} - -static void pi_set_mime_type(FLAC__StreamMetadata *block, const char *s) -{ - if(block->data.picture.mime_type) { - block->length -= strlen(block->data.picture.mime_type); - free(block->data.picture.mime_type); - } - block->data.picture.mime_type = strdup(s); - FLAC__ASSERT(block->data.picture.mime_type); - block->length += strlen(block->data.picture.mime_type); -} - -static void pi_set_description(FLAC__StreamMetadata *block, const FLAC__byte *s) -{ - if(block->data.picture.description) { - block->length -= strlen((const char *)block->data.picture.description); - free(block->data.picture.description); - } - block->data.picture.description = (FLAC__byte*)strdup((const char *)s); - FLAC__ASSERT(block->data.picture.description); - block->length += strlen((const char *)block->data.picture.description); -} - -static void pi_set_data(FLAC__StreamMetadata *block, const FLAC__byte *data, FLAC__uint32 len) -{ - if(block->data.picture.data) { - block->length -= block->data.picture.data_length; - free(block->data.picture.data); - } - block->data.picture.data = (FLAC__byte*)strdup((const char *)data); - FLAC__ASSERT(block->data.picture.data); - block->data.picture.data_length = len; - block->length += len; -} - -FLAC__bool test_metadata_object(void) -{ - FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet, *picture; - FLAC__StreamMetadata_SeekPoint seekpoint_array[14]; - FLAC__StreamMetadata_VorbisComment_Entry entry; - FLAC__StreamMetadata_CueSheet_Index indx; - FLAC__StreamMetadata_CueSheet_Track track; - uint32_t i, expected_length, seekpoints; - int j; - static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' }; - - printf("\n+++ libFLAC unit test: metadata objects\n\n"); - - - printf("testing STREAMINFO\n"); - - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH; - if(block->length != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - - printf("testing PADDING\n"); - - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - expected_length = 0; - if(block->length != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - - printf("testing APPLICATION\n"); - - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8; - if(block->length != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - printf("OK\n"); - - printf("testing FLAC__metadata_object_application_set_data(copy)... "); - if(!FLAC__metadata_object_application_set_data(block, dummydata, sizeof(dummydata), true/*copy*/)) { - printf("FAILED, returned false\n"); - return false; - } - expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata); - if(block->length != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length); - return false; - } - if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) { - printf("FAILED, data mismatch\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - printf("OK\n"); - - printf("testing FLAC__metadata_object_application_set_data(own)... "); - if(!FLAC__metadata_object_application_set_data(block, make_dummydata_(dummydata, sizeof(dummydata)), sizeof(dummydata), false/*own*/)) { - printf("FAILED, returned false\n"); - return false; - } - expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata); - if(block->length != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length); - return false; - } - if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) { - printf("FAILED, data mismatch\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - - printf("testing SEEKTABLE\n"); - - for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) { - seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - seekpoint_array[i].stream_offset = 0; - seekpoint_array[i].frame_samples = 0; - } - - seekpoints = 0; - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!check_seektable_(block, seekpoints, 0)) - return false; - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - printf("OK\n"); - - seekpoints = 2; - printf("testing FLAC__metadata_object_seektable_resize_points(grow to %u)...", seekpoints); - if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - seekpoints = 1; - printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints); - if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - printf("testing FLAC__metadata_object_seektable_is_legal()..."); - if(!FLAC__metadata_object_seektable_is_legal(block)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - seekpoints = 0; - printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints); - if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, 0)) - return false; - - seekpoints++; - printf("testing FLAC__metadata_object_seektable_insert_point() on empty array..."); - if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - seekpoint_array[0].sample_number = 1; - seekpoints++; - printf("testing FLAC__metadata_object_seektable_insert_point() on beginning of non-empty array..."); - if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - seekpoint_array[1].sample_number = 2; - seekpoints++; - printf("testing FLAC__metadata_object_seektable_insert_point() on middle of non-empty array..."); - if(!FLAC__metadata_object_seektable_insert_point(block, 1, seekpoint_array[1])) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - seekpoint_array[3].sample_number = 3; - seekpoints++; - printf("testing FLAC__metadata_object_seektable_insert_point() on end of non-empty array..."); - if(!FLAC__metadata_object_seektable_insert_point(block, 3, seekpoint_array[3])) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - printf("OK\n"); - - seekpoint_array[2].sample_number = seekpoint_array[3].sample_number; - seekpoints--; - printf("testing FLAC__metadata_object_seektable_delete_point() on middle of array..."); - if(!FLAC__metadata_object_seektable_delete_point(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - seekpoints--; - printf("testing FLAC__metadata_object_seektable_delete_point() on end of array..."); - if(!FLAC__metadata_object_seektable_delete_point(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - seekpoints--; - printf("testing FLAC__metadata_object_seektable_delete_point() on beginning of array..."); - if(!FLAC__metadata_object_seektable_delete_point(block, 0)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array+1)) - return false; - - printf("testing FLAC__metadata_object_seektable_set_point()..."); - FLAC__metadata_object_seektable_set_point(block, 0, seekpoint_array[0]); - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - /* seektable template functions */ - - for(i = 0; i < sizeof(seekpoint_array) / sizeof(FLAC__StreamMetadata_SeekPoint); i++) { - seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - seekpoint_array[i].stream_offset = 0; - seekpoint_array[i].frame_samples = 0; - } - - seekpoints = 0; - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!check_seektable_(block, seekpoints, 0)) - return false; - - seekpoints += 2; - printf("testing FLAC__metadata_object_seekpoint_template_append_placeholders()... "); - if(!FLAC__metadata_object_seektable_template_append_placeholders(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - seekpoint_array[seekpoints++].sample_number = 7; - printf("testing FLAC__metadata_object_seekpoint_template_append_point()... "); - if(!FLAC__metadata_object_seektable_template_append_point(block, 7)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - { - FLAC__uint64 nums[2] = { 3, 7 }; - seekpoint_array[seekpoints++].sample_number = nums[0]; - seekpoint_array[seekpoints++].sample_number = nums[1]; - printf("testing FLAC__metadata_object_seekpoint_template_append_points()... "); - if(!FLAC__metadata_object_seektable_template_append_points(block, nums, sizeof(nums)/sizeof(FLAC__uint64))) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - } - - seekpoint_array[seekpoints++].sample_number = 0; - seekpoint_array[seekpoints++].sample_number = 10; - seekpoint_array[seekpoints++].sample_number = 20; - printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points()... "); - if(!FLAC__metadata_object_seektable_template_append_spaced_points(block, 3, 30)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - seekpoints--; - seekpoint_array[0].sample_number = 0; - seekpoint_array[1].sample_number = 3; - seekpoint_array[2].sample_number = 7; - seekpoint_array[3].sample_number = 10; - seekpoint_array[4].sample_number = 20; - seekpoint_array[5].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - seekpoint_array[6].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=true)... "); - if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!FLAC__metadata_object_seektable_is_legal(block)) { - printf("FAILED, seek table is illegal\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - printf("testing FLAC__metadata_object_seekpoint_template_sort(compact=false)... "); - if(!FLAC__metadata_object_seektable_template_sort(block, /*compact=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!FLAC__metadata_object_seektable_is_legal(block)) { - printf("FAILED, seek table is illegal\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - seekpoint_array[seekpoints++].sample_number = 0; - seekpoint_array[seekpoints++].sample_number = 10; - seekpoint_array[seekpoints++].sample_number = 20; - printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... "); - if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 10, 30)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - seekpoint_array[seekpoints++].sample_number = 0; - seekpoint_array[seekpoints++].sample_number = 11; - seekpoint_array[seekpoints++].sample_number = 22; - printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... "); - if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 11, 30)) { - printf("FAILED, returned false\n"); - return false; - } - if(!check_seektable_(block, seekpoints, seekpoint_array)) - return false; - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - - printf("testing VORBIS_COMMENT\n"); - - { - FLAC__StreamMetadata_VorbisComment_Entry entry_; - char *field_name, *field_value; - - printf("testing FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair()... "); - if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry_, "name", "value")) { - printf("FAILED, returned false\n"); - return false; - } - if(strcmp((const char *)entry_.entry, "name=value")) { - printf("FAILED, field mismatch\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair()... "); - if(!FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(entry_, &field_name, &field_value)) { - printf("FAILED, returned false\n"); - return false; - } - if(strcmp(field_name, "name")) { - printf("FAILED, field name mismatch\n"); - return false; - } - if(strcmp(field_value, "value")) { - printf("FAILED, field value mismatch\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... "); - if(!FLAC__metadata_object_vorbiscomment_entry_matches(entry_, field_name, strlen(field_name))) { - printf("FAILED, expected true, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_entry_matches()... "); - if(FLAC__metadata_object_vorbiscomment_entry_matches(entry_, "blah", strlen("blah"))) { - printf("FAILED, expected false, returned true\n"); - return false; - } - printf("OK\n"); - - free(entry_.entry); - free(field_name); - free(field_value); - } - - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8); - if(block->length != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - vorbiscomment = FLAC__metadata_object_clone(block); - if(0 == vorbiscomment) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - vc_resize_(vorbiscomment, 2); - printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(grow to %u)...", vorbiscomment->data.vorbis_comment.num_comments); - if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - vc_resize_(vorbiscomment, 1); - printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments); - if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - vc_resize_(vorbiscomment, 0); - printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments); - if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on empty array..."); - vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1"); - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2"); - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - vc_resize_(vorbiscomment, 0); - printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments); - if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on empty array..."); - vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1"); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on beginning of non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2"); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on middle of non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3"); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4"); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1"); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1"); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); - if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name3")) != 1) { - printf("FAILED, expected 1, got %d\n", j); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); - if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name3")) != 4) { - printf("FAILED, expected 4, got %d\n", j); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); - if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name3")) != 5) { - printf("FAILED, expected 5, got %d\n", j); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); - if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "name2")) != 0) { - printf("FAILED, expected 0, got %d\n", j); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); - if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, j+1, "name2")) != -1) { - printf("FAILED, expected -1, got %d\n", j); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_find_entry_from()..."); - if((j = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, "blah")) != -1) { - printf("FAILED, expected -1, got %d\n", j); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, copy)..."); - vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false); - if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - if(block->data.vorbis_comment.num_comments != 6) { - printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, copy)..."); - vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true); - if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - if(block->data.vorbis_comment.num_comments != 4) { - printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array..."); - vc_delete_(vorbiscomment, 2); - if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array..."); - vc_delete_(vorbiscomment, 2); - if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array..."); - vc_delete_(vorbiscomment, 0); - if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 1, "rem0=val0"); - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 2, "rem0=val1"); - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_append_comment(copy) on non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 3, "rem0=val2"); - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_remove_entry_matching(\"blah\")..."); - if((j = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, "blah")) != 0) { - printf("FAILED, expected 0, got %d\n", j); - return false; - } - if(block->data.vorbis_comment.num_comments != 4) { - printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_remove_entry_matching(\"rem0\")..."); - vc_delete_(vorbiscomment, 1); - if((j = FLAC__metadata_object_vorbiscomment_remove_entry_matching(block, "rem0")) != 1) { - printf("FAILED, expected 1, got %d\n", j); - return false; - } - if(block->data.vorbis_comment.num_comments != 3) { - printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_remove_entries_matching(\"blah\")..."); - if((j = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, "blah")) != 0) { - printf("FAILED, expected 0, got %d\n", j); - return false; - } - if(block->data.vorbis_comment.num_comments != 3) { - printf("FAILED, expected 3 comments, got %u\n", block->data.vorbis_comment.num_comments); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_remove_entries_matching(\"rem0\")..."); - vc_delete_(vorbiscomment, 1); - vc_delete_(vorbiscomment, 1); - if((j = FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, "rem0")) != 2) { - printf("FAILED, expected 2, got %d\n", j); - return false; - } - if(block->data.vorbis_comment.num_comments != 1) { - printf("FAILED, expected 1 comments, got %u\n", block->data.vorbis_comment.num_comments); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_set_comment(copy)..."); - vc_set_new_(&entry, vorbiscomment, 0, "name5=field5"); - FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/true); - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(copy)..."); - vc_set_vs_new_(&entry, vorbiscomment, "name6=field6"); - FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/true); - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(vorbiscomment); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - vorbiscomment = FLAC__metadata_object_clone(block); - if(0 == vorbiscomment) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_append_comment(own) on empty array..."); - vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1"); - entry_clone_(&entry); - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_append_comment(own) on non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 1, "name2=field2"); - entry_clone_(&entry); - if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(vorbiscomment); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - vorbiscomment = FLAC__metadata_object_clone(block); - if(0 == vorbiscomment) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on empty array..."); - vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1"); - entry_clone_(&entry); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on beginning of non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2"); - entry_clone_(&entry); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on middle of non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3"); - entry_clone_(&entry); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4"); - entry_clone_(&entry); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 4, "name3=field3dup1"); - entry_clone_(&entry); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 4, entry, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array..."); - vc_insert_new_(&entry, vorbiscomment, 5, "name3=field3dup1"); - entry_clone_(&entry); - if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 5, entry, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(first, own)..."); - vc_replace_new_(&entry, vorbiscomment, "name3=field3new1", /*all=*/false); - entry_clone_(&entry); - if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/false, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - if(block->data.vorbis_comment.num_comments != 6) { - printf("FAILED, expected 6 comments, got %u\n", block->data.vorbis_comment.num_comments); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_replace_comment(all, own)..."); - vc_replace_new_(&entry, vorbiscomment, "name3=field3new2", /*all=*/true); - entry_clone_(&entry); - if(!FLAC__metadata_object_vorbiscomment_replace_comment(block, entry, /*all=*/true, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - if(block->data.vorbis_comment.num_comments != 4) { - printf("FAILED, expected 4 comments, got %u\n", block->data.vorbis_comment.num_comments); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array..."); - vc_delete_(vorbiscomment, 2); - if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array..."); - vc_delete_(vorbiscomment, 2); - if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array..."); - vc_delete_(vorbiscomment, 0); - if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_set_comment(own)..."); - vc_set_new_(&entry, vorbiscomment, 0, "name5=field5"); - entry_clone_(&entry); - FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/false); - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(own)..."); - vc_set_vs_new_(&entry, vorbiscomment, "name6=field6"); - entry_clone_(&entry); - FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/false); - if(!mutils__compare_block(vorbiscomment, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(vorbiscomment); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - - printf("testing CUESHEET\n"); - - { - FLAC__StreamMetadata_CueSheet_Track *track_, *trackcopy_; - - printf("testing FLAC__metadata_object_cuesheet_track_new()... "); - track_ = FLAC__metadata_object_cuesheet_track_new(); - if(0 == track_) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_track_clone()... "); - trackcopy_ = FLAC__metadata_object_cuesheet_track_clone(track_); - if(0 == trackcopy_) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!compare_track_(trackcopy_, track_)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_track_delete()... "); - FLAC__metadata_object_cuesheet_track_delete(trackcopy_); - FLAC__metadata_object_cuesheet_track_delete(track_); - printf("OK\n"); - } - - - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - expected_length = ( - FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN + - FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + - FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN - ) / 8; - if(block->length != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - cuesheet = FLAC__metadata_object_clone(block); - if(0 == cuesheet) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - cs_resize_(cuesheet, 2); - printf("testing FLAC__metadata_object_cuesheet_resize_tracks(grow to %u)...", cuesheet->data.cue_sheet.num_tracks); - if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - cs_resize_(cuesheet, 1); - printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks); - if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - cs_resize_(cuesheet, 0); - printf("testing FLAC__metadata_object_cuesheet_resize_tracks(shrink to %u)...", cuesheet->data.cue_sheet.num_tracks); - if(!FLAC__metadata_object_cuesheet_resize_tracks(block, cuesheet->data.cue_sheet.num_tracks)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on empty array..."); - cs_insert_new_(&track, cuesheet, 0, 0, 1, "ABCDE1234567", false, false); - if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on beginning of non-empty array..."); - cs_insert_new_(&track, cuesheet, 0, 10, 2, "BBCDE1234567", false, false); - if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on middle of non-empty array..."); - cs_insert_new_(&track, cuesheet, 1, 20, 3, "CBCDE1234567", false, false); - if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_insert_track(copy) on end of non-empty array..."); - cs_insert_new_(&track, cuesheet, 3, 30, 4, "DBCDE1234567", false, false); - if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_insert_blank_track() on end of non-empty array..."); - cs_insert_new_(&track, cuesheet, 4, 0, 0, "\0\0\0\0\0\0\0\0\0\0\0\0", false, false); - if(!FLAC__metadata_object_cuesheet_insert_blank_track(block, 4)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array..."); - cs_delete_(cuesheet, 4); - if(!FLAC__metadata_object_cuesheet_delete_track(block, 4)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array..."); - cs_delete_(cuesheet, 2); - if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array..."); - cs_delete_(cuesheet, 2); - if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array..."); - cs_delete_(cuesheet, 0); - if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_set_track(copy)..."); - cs_set_new_(&track, cuesheet, 0, 40, 5, "EBCDE1234567", false, false); - FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/true); - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - tr_resize_(cuesheet, 0, 2); - printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(grow to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices); - if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - tr_resize_(cuesheet, 0, 1); - printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices); - if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - tr_resize_(cuesheet, 0, 0); - printf("testing FLAC__metadata_object_cuesheet_track_resize_indices(shrink to %u)...", cuesheet->data.cue_sheet.tracks[0].num_indices); - if(!FLAC__metadata_object_cuesheet_track_resize_indices(block, 0, cuesheet->data.cue_sheet.tracks[0].num_indices)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - indx.offset = 0; - indx.number = 1; - printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on empty array..."); - tr_insert_new_(cuesheet, 0, 0, indx); - if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, indx)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - indx.offset = 10; - indx.number = 2; - printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on beginning of non-empty array..."); - tr_insert_new_(cuesheet, 0, 0, indx); - if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 0, indx)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - indx.offset = 20; - indx.number = 3; - printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on middle of non-empty array..."); - tr_insert_new_(cuesheet, 0, 1, indx); - if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 1, indx)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - indx.offset = 30; - indx.number = 4; - printf("testing FLAC__metadata_object_cuesheet_track_insert_index() on end of non-empty array..."); - tr_insert_new_(cuesheet, 0, 3, indx); - if(!FLAC__metadata_object_cuesheet_track_insert_index(block, 0, 3, indx)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - indx.offset = 0; - indx.number = 0; - printf("testing FLAC__metadata_object_cuesheet_track_insert_blank_index() on end of non-empty array..."); - tr_insert_new_(cuesheet, 0, 4, indx); - if(!FLAC__metadata_object_cuesheet_track_insert_blank_index(block, 0, 4)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array..."); - tr_delete_(cuesheet, 0, 4); - if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 4)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on middle of array..."); - tr_delete_(cuesheet, 0, 2); - if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on end of array..."); - tr_delete_(cuesheet, 0, 2); - if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_track_delete_index() on beginning of array..."); - tr_delete_(cuesheet, 0, 0); - if(!FLAC__metadata_object_cuesheet_track_delete_index(block, 0, 0)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(cuesheet); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_CUESHEET); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - cuesheet = FLAC__metadata_object_clone(block); - if(0 == cuesheet) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on empty array..."); - cs_insert_new_(&track, cuesheet, 0, 60, 7, "GBCDE1234567", false, false); - track_clone_(&track); - if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on beginning of non-empty array..."); - cs_insert_new_(&track, cuesheet, 0, 70, 8, "HBCDE1234567", false, false); - track_clone_(&track); - if(!FLAC__metadata_object_cuesheet_insert_track(block, 0, &track, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on middle of non-empty array..."); - cs_insert_new_(&track, cuesheet, 1, 80, 9, "IBCDE1234567", false, false); - track_clone_(&track); - if(!FLAC__metadata_object_cuesheet_insert_track(block, 1, &track, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_insert_track(own) on end of non-empty array..."); - cs_insert_new_(&track, cuesheet, 3, 90, 10, "JBCDE1234567", false, false); - track_clone_(&track); - if(!FLAC__metadata_object_cuesheet_insert_track(block, 3, &track, /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_delete_track() on middle of array..."); - cs_delete_(cuesheet, 2); - if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_delete_track() on end of array..."); - cs_delete_(cuesheet, 2); - if(!FLAC__metadata_object_cuesheet_delete_track(block, 2)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_delete_track() on beginning of array..."); - cs_delete_(cuesheet, 0); - if(!FLAC__metadata_object_cuesheet_delete_track(block, 0)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_set_track(own)..."); - cs_set_new_(&track, cuesheet, 0, 100, 11, "KBCDE1234567", false, false); - track_clone_(&track); - FLAC__metadata_object_cuesheet_set_track(block, 0, &track, /*copy=*/false); - if(!mutils__compare_block(cuesheet, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_cuesheet_is_legal()..."); - { - const char *violation; - if(FLAC__metadata_object_cuesheet_is_legal(block, /*check_cd_da_subset=*/true, &violation)) { - printf("FAILED, returned true when expecting false\n"); - return false; - } - printf("returned false as expected, violation=\"%s\" OK\n", violation); - } - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(cuesheet); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - - printf("testing PICTURE\n"); - - printf("testing FLAC__metadata_object_new()... "); - block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE); - if(0 == block) { - printf("FAILED, returned NULL\n"); - return false; - } - expected_length = ( - FLAC__STREAM_METADATA_PICTURE_TYPE_LEN + - FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + - FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + - FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN + - FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN + - FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN + - FLAC__STREAM_METADATA_PICTURE_COLORS_LEN + - FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN - ) / 8; - if(block->length != expected_length) { - printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length); - return false; - } - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - picture = FLAC__metadata_object_clone(block); - if(0 == picture) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - pi_set_mime_type(picture, "image/png\t"); - printf("testing FLAC__metadata_object_picture_set_mime_type(copy)..."); - if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png\t", /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_picture_is_legal()..."); - { - const char *violation; - if(FLAC__metadata_object_picture_is_legal(block, &violation)) { - printf("FAILED, returned true when expecting false\n"); - return false; - } - printf("returned false as expected, violation=\"%s\" OK\n", violation); - } - - pi_set_mime_type(picture, "image/png"); - printf("testing FLAC__metadata_object_picture_set_mime_type(copy)..."); - if(!FLAC__metadata_object_picture_set_mime_type(block, "image/png", /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_picture_is_legal()..."); - { - const char *violation; - if(!FLAC__metadata_object_picture_is_legal(block, &violation)) { - printf("FAILED, returned false, violation=\"%s\"\n", violation); - return false; - } - printf("OK\n"); - } - - pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff"); - printf("testing FLAC__metadata_object_picture_set_description(copy)..."); - if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION\xff", /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_picture_is_legal()..."); - { - const char *violation; - if(FLAC__metadata_object_picture_is_legal(block, &violation)) { - printf("FAILED, returned true when expecting false\n"); - return false; - } - printf("returned false as expected, violation=\"%s\" OK\n", violation); - } - - pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION"); - printf("testing FLAC__metadata_object_picture_set_description(copy)..."); - if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)"DESCRIPTION", /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_picture_is_legal()..."); - { - const char *violation; - if(!FLAC__metadata_object_picture_is_legal(block, &violation)) { - printf("FAILED, returned false, violation=\"%s\"\n", violation); - return false; - } - printf("OK\n"); - } - - - pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA")); - printf("testing FLAC__metadata_object_picture_set_data(copy)..."); - if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)"PNGDATA", strlen("PNGDATA"), /*copy=*/true)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - printf("OK\n"); - - pi_set_mime_type(picture, "image/png\t"); - printf("testing FLAC__metadata_object_picture_set_mime_type(own)..."); - if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png\t"), /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_picture_is_legal()..."); - { - const char *violation; - if(FLAC__metadata_object_picture_is_legal(block, &violation)) { - printf("FAILED, returned true when expecting false\n"); - return false; - } - printf("returned false as expected, violation=\"%s\" OK\n", violation); - } - - pi_set_mime_type(picture, "image/png"); - printf("testing FLAC__metadata_object_picture_set_mime_type(own)..."); - if(!FLAC__metadata_object_picture_set_mime_type(block, strdup("image/png"), /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_picture_is_legal()..."); - { - const char *violation; - if(!FLAC__metadata_object_picture_is_legal(block, &violation)) { - printf("FAILED, returned false, violation=\"%s\"\n", violation); - return false; - } - printf("OK\n"); - } - - pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION\xff"); - printf("testing FLAC__metadata_object_picture_set_description(own)..."); - if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION\xff"), /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_picture_is_legal()..."); - { - const char *violation; - if(FLAC__metadata_object_picture_is_legal(block, &violation)) { - printf("FAILED, returned true when expecting false\n"); - return false; - } - printf("returned false as expected, violation=\"%s\" OK\n", violation); - } - - pi_set_description(picture, (const FLAC__byte *)"DESCRIPTION"); - printf("testing FLAC__metadata_object_picture_set_description(own)..."); - if(!FLAC__metadata_object_picture_set_description(block, (FLAC__byte *)strdup("DESCRIPTION"), /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_picture_is_legal()..."); - { - const char *violation; - if(!FLAC__metadata_object_picture_is_legal(block, &violation)) { - printf("FAILED, returned false, violation=\"%s\"\n", violation); - return false; - } - printf("OK\n"); - } - - pi_set_data(picture, (const FLAC__byte*)"PNGDATA", strlen("PNGDATA")); - printf("testing FLAC__metadata_object_picture_set_data(own)..."); - if(!FLAC__metadata_object_picture_set_data(block, (FLAC__byte*)strdup("PNGDATA"), strlen("PNGDATA"), /*copy=*/false)) { - printf("FAILED, returned false\n"); - return false; - } - if(!mutils__compare_block(picture, block)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_clone()... "); - blockcopy = FLAC__metadata_object_clone(block); - if(0 == blockcopy) { - printf("FAILED, returned NULL\n"); - return false; - } - if(!mutils__compare_block(block, blockcopy)) - return false; - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(blockcopy); - printf("OK\n"); - - printf("testing FLAC__metadata_object_delete()... "); - FLAC__metadata_object_delete(picture); - FLAC__metadata_object_delete(block); - printf("OK\n"); - - - return true; -} diff --git a/flac/src/test_libs_common/CMakeLists.txt b/flac/src/test_libs_common/CMakeLists.txt deleted file mode 100644 index 8a0c871..0000000 --- a/flac/src/test_libs_common/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -add_library(test_libs_common STATIC - file_utils_flac.c - metadata_utils.c) -target_link_libraries(test_libs_common PUBLIC FLAC) diff --git a/flac/src/test_libs_common/Makefile.am b/flac/src/test_libs_common/Makefile.am deleted file mode 100644 index 30e1f15..0000000 --- a/flac/src/test_libs_common/Makefile.am +++ /dev/null @@ -1,29 +0,0 @@ -# test_libs_common - Common code to library unit tests -# Copyright (C) 2000-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include - -noinst_LTLIBRARIES = libtest_libs_common.la - -libtest_libs_common_la_SOURCES = \ - file_utils_flac.c \ - metadata_utils.c - -EXTRA_DIST = \ - CMakeLists.txt \ - README diff --git a/flac/src/test_libs_common/README b/flac/src/test_libs_common/README deleted file mode 100644 index 6a704c2..0000000 --- a/flac/src/test_libs_common/README +++ /dev/null @@ -1,2 +0,0 @@ -This directory contains a convenience library of routines that are -common to the library unit testers. diff --git a/flac/src/test_libs_common/file_utils_flac.c b/flac/src/test_libs_common/file_utils_flac.c deleted file mode 100644 index 3cc8c30..0000000 --- a/flac/src/test_libs_common/file_utils_flac.c +++ /dev/null @@ -1,155 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include "FLAC/assert.h" -#include "FLAC/stream_encoder.h" -#include "test_libs_common/file_utils_flac.h" -#include -#include -#include /* for stat() */ -#include "share/compat.h" - -#ifdef min -#undef min -#endif -#define min(a,b) ((a)<(b)?(a):(b)) - -const long file_utils__ogg_serial_number = 12345; - -#ifdef FLAC__VALGRIND_TESTING -static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) -{ - size_t ret = fwrite(ptr, size, nmemb, stream); - if(!ferror(stream)) - fflush(stream); - return ret; -} -#else -#define local__fwrite fwrite -#endif - -typedef struct { - FILE *file; -} encoder_client_struct; - -static FLAC__StreamEncoderWriteStatus encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data) -{ - encoder_client_struct *ecd = (encoder_client_struct*)client_data; - - (void)encoder, (void)samples, (void)current_frame; - - if(local__fwrite(buffer, 1, bytes, ecd->file) != bytes) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - else - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; -} - -static void encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - (void)encoder, (void)metadata, (void)client_data; -} - -FLAC__bool file_utils__generate_flacfile(FLAC__bool is_ogg, const char *output_filename, FLAC__off_t *output_filesize, uint32_t length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, uint32_t num_metadata) -{ - FLAC__int32 samples[1024]; - FLAC__StreamEncoder *encoder; - FLAC__StreamEncoderInitStatus init_status; - encoder_client_struct encoder_client_data; - uint32_t i, n; - - FLAC__ASSERT(0 != output_filename); - FLAC__ASSERT(0 != streaminfo); - FLAC__ASSERT(streaminfo->type == FLAC__METADATA_TYPE_STREAMINFO); - FLAC__ASSERT((streaminfo->is_last && num_metadata == 0) || (!streaminfo->is_last && num_metadata > 0)); - - if(0 == (encoder_client_data.file = flac_fopen(output_filename, "wb"))) - return false; - - encoder = FLAC__stream_encoder_new(); - if(0 == encoder) { - fclose(encoder_client_data.file); - return false; - } - - FLAC__stream_encoder_set_ogg_serial_number(encoder, file_utils__ogg_serial_number); - FLAC__stream_encoder_set_verify(encoder, true); - FLAC__stream_encoder_set_streamable_subset(encoder, true); - FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false); - FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false); - FLAC__stream_encoder_set_channels(encoder, streaminfo->data.stream_info.channels); - FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo->data.stream_info.bits_per_sample); - FLAC__stream_encoder_set_sample_rate(encoder, streaminfo->data.stream_info.sample_rate); - FLAC__stream_encoder_set_blocksize(encoder, streaminfo->data.stream_info.min_blocksize); - FLAC__stream_encoder_set_max_lpc_order(encoder, 0); - FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0); - FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false); - FLAC__stream_encoder_set_do_escape_coding(encoder, false); - FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false); - FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0); - FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0); - FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0); - FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo->data.stream_info.total_samples); - FLAC__stream_encoder_set_metadata(encoder, metadata, num_metadata); - - if(is_ogg) - init_status = FLAC__stream_encoder_init_ogg_stream(encoder, /*read_callback=*/0, encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, encoder_metadata_callback_, &encoder_client_data); - else - init_status = FLAC__stream_encoder_init_stream(encoder, encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, encoder_metadata_callback_, &encoder_client_data); - - if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { - fclose(encoder_client_data.file); - return false; - } - - /* init the dummy sample buffer */ - for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++) - samples[i] = i & 7; - - while(length > 0) { - n = min(length, sizeof(samples) / sizeof(FLAC__int32)); - - if(!FLAC__stream_encoder_process_interleaved(encoder, samples, n)) { - fclose(encoder_client_data.file); - return false; - } - - length -= n; - } - - (void)FLAC__stream_encoder_finish(encoder); - - fclose(encoder_client_data.file); - - FLAC__stream_encoder_delete(encoder); - - if(0 != output_filesize) { - struct flac_stat_s filestats; - - if(flac_stat(output_filename, &filestats) != 0) - return false; - else - *output_filesize = filestats.st_size; - } - - return true; -} diff --git a/flac/src/test_libs_common/metadata_utils.c b/flac/src/test_libs_common/metadata_utils.c deleted file mode 100644 index 929ca63..0000000 --- a/flac/src/test_libs_common/metadata_utils.c +++ /dev/null @@ -1,636 +0,0 @@ -/* test_libFLAC - Unit tester for libFLAC - * Copyright (C) 2002-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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. - */ - -/* - * These are not tests, just utility functions used by the metadata tests - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "FLAC/metadata.h" -#include "test_libs_common/metadata_utils.h" -#include "share/compat.h" -#include -#include /* for malloc() */ -#include /* for memcmp() */ - -FLAC__bool mutils__compare_block_data_streaminfo(const FLAC__StreamMetadata_StreamInfo *block, const FLAC__StreamMetadata_StreamInfo *blockcopy) -{ - if(blockcopy->min_blocksize != block->min_blocksize) { - printf("FAILED, min_blocksize mismatch, expected %u, got %u\n", block->min_blocksize, blockcopy->min_blocksize); - return false; - } - if(blockcopy->max_blocksize != block->max_blocksize) { - printf("FAILED, max_blocksize mismatch, expected %u, got %u\n", block->max_blocksize, blockcopy->max_blocksize); - return false; - } - if(blockcopy->min_framesize != block->min_framesize) { - printf("FAILED, min_framesize mismatch, expected %u, got %u\n", block->min_framesize, blockcopy->min_framesize); - return false; - } - if(blockcopy->max_framesize != block->max_framesize) { - printf("FAILED, max_framesize mismatch, expected %u, got %u\n", block->max_framesize, blockcopy->max_framesize); - return false; - } - if(blockcopy->sample_rate != block->sample_rate) { - printf("FAILED, sample_rate mismatch, expected %u, got %u\n", block->sample_rate, blockcopy->sample_rate); - return false; - } - if(blockcopy->channels != block->channels) { - printf("FAILED, channels mismatch, expected %u, got %u\n", block->channels, blockcopy->channels); - return false; - } - if(blockcopy->bits_per_sample != block->bits_per_sample) { - printf("FAILED, bits_per_sample mismatch, expected %u, got %u\n", block->bits_per_sample, blockcopy->bits_per_sample); - return false; - } - if(blockcopy->total_samples != block->total_samples) { - printf("FAILED, total_samples mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", block->total_samples, blockcopy->total_samples); - return false; - } - if(0 != memcmp(blockcopy->md5sum, block->md5sum, sizeof(block->md5sum))) { - printf("FAILED, md5sum mismatch, expected %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X, got %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n", - (uint32_t)block->md5sum[0], - (uint32_t)block->md5sum[1], - (uint32_t)block->md5sum[2], - (uint32_t)block->md5sum[3], - (uint32_t)block->md5sum[4], - (uint32_t)block->md5sum[5], - (uint32_t)block->md5sum[6], - (uint32_t)block->md5sum[7], - (uint32_t)block->md5sum[8], - (uint32_t)block->md5sum[9], - (uint32_t)block->md5sum[10], - (uint32_t)block->md5sum[11], - (uint32_t)block->md5sum[12], - (uint32_t)block->md5sum[13], - (uint32_t)block->md5sum[14], - (uint32_t)block->md5sum[15], - (uint32_t)blockcopy->md5sum[0], - (uint32_t)blockcopy->md5sum[1], - (uint32_t)blockcopy->md5sum[2], - (uint32_t)blockcopy->md5sum[3], - (uint32_t)blockcopy->md5sum[4], - (uint32_t)blockcopy->md5sum[5], - (uint32_t)blockcopy->md5sum[6], - (uint32_t)blockcopy->md5sum[7], - (uint32_t)blockcopy->md5sum[8], - (uint32_t)blockcopy->md5sum[9], - (uint32_t)blockcopy->md5sum[10], - (uint32_t)blockcopy->md5sum[11], - (uint32_t)blockcopy->md5sum[12], - (uint32_t)blockcopy->md5sum[13], - (uint32_t)blockcopy->md5sum[14], - (uint32_t)blockcopy->md5sum[15] - ); - return false; - } - return true; -} - -FLAC__bool mutils__compare_block_data_padding(const FLAC__StreamMetadata_Padding *block, const FLAC__StreamMetadata_Padding *blockcopy, uint32_t block_length) -{ - /* we don't compare the padding guts */ - (void)block, (void)blockcopy, (void)block_length; - return true; -} - -FLAC__bool mutils__compare_block_data_application(const FLAC__StreamMetadata_Application *block, const FLAC__StreamMetadata_Application *blockcopy, uint32_t block_length) -{ - if(block_length < sizeof(block->id)) { - printf("FAILED, bad block length = %u\n", block_length); - return false; - } - if(0 != memcmp(blockcopy->id, block->id, sizeof(block->id))) { - printf("FAILED, id mismatch, expected %02X%02X%02X%02X, got %02X%02X%02X%02X\n", - (uint32_t)block->id[0], - (uint32_t)block->id[1], - (uint32_t)block->id[2], - (uint32_t)block->id[3], - (uint32_t)blockcopy->id[0], - (uint32_t)blockcopy->id[1], - (uint32_t)blockcopy->id[2], - (uint32_t)blockcopy->id[3] - ); - return false; - } - if(0 == block->data || 0 == blockcopy->data) { - if(block->data != blockcopy->data) { - printf("FAILED, data mismatch (%s's data pointer is null)\n", 0==block->data?"original":"copy"); - return false; - } - else if(block_length - sizeof(block->id) > 0) { - printf("FAILED, data pointer is null but block length is not 0\n"); - return false; - } - } - else { - if(block_length - sizeof(block->id) == 0) { - printf("FAILED, data pointer is not null but block length is 0\n"); - return false; - } - else if(0 != memcmp(blockcopy->data, block->data, block_length - sizeof(block->id))) { - printf("FAILED, data mismatch\n"); - return false; - } - } - return true; -} - -FLAC__bool mutils__compare_block_data_seektable(const FLAC__StreamMetadata_SeekTable *block, const FLAC__StreamMetadata_SeekTable *blockcopy) -{ - uint32_t i; - if(blockcopy->num_points != block->num_points) { - printf("FAILED, num_points mismatch, expected %u, got %u\n", block->num_points, blockcopy->num_points); - return false; - } - for(i = 0; i < block->num_points; i++) { - if(blockcopy->points[i].sample_number != block->points[i].sample_number) { - printf("FAILED, points[%u].sample_number mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", i, block->points[i].sample_number, blockcopy->points[i].sample_number); - return false; - } - if(blockcopy->points[i].stream_offset != block->points[i].stream_offset) { - printf("FAILED, points[%u].stream_offset mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", i, block->points[i].stream_offset, blockcopy->points[i].stream_offset); - return false; - } - if(blockcopy->points[i].frame_samples != block->points[i].frame_samples) { - printf("FAILED, points[%u].frame_samples mismatch, expected %u, got %u\n", i, block->points[i].frame_samples, blockcopy->points[i].frame_samples); - return false; - } - } - return true; -} - -FLAC__bool mutils__compare_block_data_vorbiscomment(const FLAC__StreamMetadata_VorbisComment *block, const FLAC__StreamMetadata_VorbisComment *blockcopy) -{ - uint32_t i; - if(blockcopy->vendor_string.length != block->vendor_string.length) { - printf("FAILED, vendor_string.length mismatch, expected %u, got %u\n", block->vendor_string.length, blockcopy->vendor_string.length); - return false; - } - if(0 == block->vendor_string.entry || 0 == blockcopy->vendor_string.entry) { - if(block->vendor_string.entry != blockcopy->vendor_string.entry) { - printf("FAILED, vendor_string.entry mismatch\n"); - return false; - } - } - else if(0 != memcmp(blockcopy->vendor_string.entry, block->vendor_string.entry, block->vendor_string.length)) { - printf("FAILED, vendor_string.entry mismatch\n"); - return false; - } - if(blockcopy->num_comments != block->num_comments) { - printf("FAILED, num_comments mismatch, expected %u, got %u\n", block->num_comments, blockcopy->num_comments); - return false; - } - for(i = 0; i < block->num_comments; i++) { - if(blockcopy->comments[i].length != block->comments[i].length) { - printf("FAILED, comments[%u].length mismatch, expected %u, got %u\n", i, block->comments[i].length, blockcopy->comments[i].length); - return false; - } - if(0 == block->comments[i].entry || 0 == blockcopy->comments[i].entry) { - if(block->comments[i].entry != blockcopy->comments[i].entry) { - printf("FAILED, comments[%u].entry mismatch\n", i); - return false; - } - } - else { - if(0 != memcmp(blockcopy->comments[i].entry, block->comments[i].entry, block->comments[i].length)) { - printf("FAILED, comments[%u].entry mismatch\n", i); - return false; - } - } - } - return true; -} - -FLAC__bool mutils__compare_block_data_cuesheet(const FLAC__StreamMetadata_CueSheet *block, const FLAC__StreamMetadata_CueSheet *blockcopy) -{ - uint32_t i, j; - - if(0 != strcmp(blockcopy->media_catalog_number, block->media_catalog_number)) { - printf("FAILED, media_catalog_number mismatch, expected %s, got %s\n", block->media_catalog_number, blockcopy->media_catalog_number); - return false; - } - if(blockcopy->lead_in != block->lead_in) { - printf("FAILED, lead_in mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", block->lead_in, blockcopy->lead_in); - return false; - } - if(blockcopy->is_cd != block->is_cd) { - printf("FAILED, is_cd mismatch, expected %u, got %u\n", (uint32_t)block->is_cd, (uint32_t)blockcopy->is_cd); - return false; - } - if(blockcopy->num_tracks != block->num_tracks) { - printf("FAILED, num_tracks mismatch, expected %u, got %u\n", block->num_tracks, blockcopy->num_tracks); - return false; - } - for(i = 0; i < block->num_tracks; i++) { - if(blockcopy->tracks[i].offset != block->tracks[i].offset) { - printf("FAILED, tracks[%u].offset mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", i, block->tracks[i].offset, blockcopy->tracks[i].offset); - return false; - } - if(blockcopy->tracks[i].number != block->tracks[i].number) { - printf("FAILED, tracks[%u].number mismatch, expected %u, got %u\n", i, (uint32_t)block->tracks[i].number, (uint32_t)blockcopy->tracks[i].number); - return false; - } - if(blockcopy->tracks[i].num_indices != block->tracks[i].num_indices) { - printf("FAILED, tracks[%u].num_indices mismatch, expected %u, got %u\n", i, (uint32_t)block->tracks[i].num_indices, (uint32_t)blockcopy->tracks[i].num_indices); - return false; - } - /* num_indices == 0 means lead-out track so only the track offset and number are valid */ - if(block->tracks[i].num_indices > 0) { - if(0 != strcmp(blockcopy->tracks[i].isrc, block->tracks[i].isrc)) { - printf("FAILED, tracks[%u].isrc mismatch, expected %s, got %s\n", i, block->tracks[i].isrc, blockcopy->tracks[i].isrc); - return false; - } - if(blockcopy->tracks[i].type != block->tracks[i].type) { - printf("FAILED, tracks[%u].type mismatch, expected %u, got %u\n", i, (uint32_t)block->tracks[i].type, (uint32_t)blockcopy->tracks[i].type); - return false; - } - if(blockcopy->tracks[i].pre_emphasis != block->tracks[i].pre_emphasis) { - printf("FAILED, tracks[%u].pre_emphasis mismatch, expected %u, got %u\n", i, (uint32_t)block->tracks[i].pre_emphasis, (uint32_t)blockcopy->tracks[i].pre_emphasis); - return false; - } - if(0 == block->tracks[i].indices || 0 == blockcopy->tracks[i].indices) { - if(block->tracks[i].indices != blockcopy->tracks[i].indices) { - printf("FAILED, tracks[%u].indices mismatch\n", i); - return false; - } - } - else { - for(j = 0; j < block->tracks[i].num_indices; j++) { - if(blockcopy->tracks[i].indices[j].offset != block->tracks[i].indices[j].offset) { - printf("FAILED, tracks[%u].indices[%u].offset mismatch, expected %" PRIu64 ", got %" PRIu64 "\n", i, j, block->tracks[i].indices[j].offset, blockcopy->tracks[i].indices[j].offset); - return false; - } - if(blockcopy->tracks[i].indices[j].number != block->tracks[i].indices[j].number) { - printf("FAILED, tracks[%u].indices[%u].number mismatch, expected %u, got %u\n", i, j, (uint32_t)block->tracks[i].indices[j].number, (uint32_t)blockcopy->tracks[i].indices[j].number); - return false; - } - } - } - } - } - return true; -} - -FLAC__bool mutils__compare_block_data_picture(const FLAC__StreamMetadata_Picture *block, const FLAC__StreamMetadata_Picture *blockcopy) -{ - size_t len, lencopy; - if(blockcopy->type != block->type) { - printf("FAILED, type mismatch, expected %u, got %u\n", (uint32_t)block->type, (uint32_t)blockcopy->type); - return false; - } - len = strlen(block->mime_type); - lencopy = strlen(blockcopy->mime_type); - if(lencopy != len) { - printf("FAILED, mime_type length mismatch, expected %u, got %u\n", (uint32_t)len, (uint32_t)lencopy); - return false; - } - if(strcmp(blockcopy->mime_type, block->mime_type)) { - printf("FAILED, mime_type mismatch, expected %s, got %s\n", block->mime_type, blockcopy->mime_type); - return false; - } - len = strlen((const char *)block->description); - lencopy = strlen((const char *)blockcopy->description); - if(lencopy != len) { - printf("FAILED, description length mismatch, expected %u, got %u\n", (uint32_t)len, (uint32_t)lencopy); - return false; - } - if(strcmp((const char *)blockcopy->description, (const char *)block->description)) { - printf("FAILED, description mismatch, expected %s, got %s\n", block->description, blockcopy->description); - return false; - } - if(blockcopy->width != block->width) { - printf("FAILED, width mismatch, expected %u, got %u\n", block->width, blockcopy->width); - return false; - } - if(blockcopy->height != block->height) { - printf("FAILED, height mismatch, expected %u, got %u\n", block->height, blockcopy->height); - return false; - } - if(blockcopy->depth != block->depth) { - printf("FAILED, depth mismatch, expected %u, got %u\n", block->depth, blockcopy->depth); - return false; - } - if(blockcopy->colors != block->colors) { - printf("FAILED, colors mismatch, expected %u, got %u\n", block->colors, blockcopy->colors); - return false; - } - if(blockcopy->data_length != block->data_length) { - printf("FAILED, data_length mismatch, expected %u, got %u\n", block->data_length, blockcopy->data_length); - return false; - } - if(block->data_length > 0 && memcmp(blockcopy->data, block->data, block->data_length)) { - printf("FAILED, data mismatch\n"); - return false; - } - return true; -} - -FLAC__bool mutils__compare_block_data_unknown(const FLAC__StreamMetadata_Unknown *block, const FLAC__StreamMetadata_Unknown *blockcopy, uint32_t block_length) -{ - if(0 == block->data || 0 == blockcopy->data) { - if(block->data != blockcopy->data) { - printf("FAILED, data mismatch (%s's data pointer is null)\n", 0==block->data?"original":"copy"); - return false; - } - else if(block_length > 0) { - printf("FAILED, data pointer is null but block length is not 0\n"); - return false; - } - } - else { - if(block_length == 0) { - printf("FAILED, data pointer is not null but block length is 0\n"); - return false; - } - else if(0 != memcmp(blockcopy->data, block->data, block_length)) { - printf("FAILED, data mismatch\n"); - return false; - } - } - return true; -} - -FLAC__bool mutils__compare_block(const FLAC__StreamMetadata *block, const FLAC__StreamMetadata *blockcopy) -{ - if(blockcopy->type != block->type) { - printf("FAILED, type mismatch, expected %s, got %s\n", FLAC__MetadataTypeString[block->type], FLAC__MetadataTypeString[blockcopy->type]); - return false; - } - if(blockcopy->is_last != block->is_last) { - printf("FAILED, is_last mismatch, expected %u, got %u\n", (uint32_t)block->is_last, (uint32_t)blockcopy->is_last); - return false; - } - if(blockcopy->length != block->length) { - printf("FAILED, length mismatch, expected %u, got %u\n", block->length, blockcopy->length); - return false; - } - switch(block->type) { - case FLAC__METADATA_TYPE_STREAMINFO: - return mutils__compare_block_data_streaminfo(&block->data.stream_info, &blockcopy->data.stream_info); - case FLAC__METADATA_TYPE_PADDING: - return mutils__compare_block_data_padding(&block->data.padding, &blockcopy->data.padding, block->length); - case FLAC__METADATA_TYPE_APPLICATION: - return mutils__compare_block_data_application(&block->data.application, &blockcopy->data.application, block->length); - case FLAC__METADATA_TYPE_SEEKTABLE: - return mutils__compare_block_data_seektable(&block->data.seek_table, &blockcopy->data.seek_table); - case FLAC__METADATA_TYPE_VORBIS_COMMENT: - return mutils__compare_block_data_vorbiscomment(&block->data.vorbis_comment, &blockcopy->data.vorbis_comment); - case FLAC__METADATA_TYPE_CUESHEET: - return mutils__compare_block_data_cuesheet(&block->data.cue_sheet, &blockcopy->data.cue_sheet); - case FLAC__METADATA_TYPE_PICTURE: - return mutils__compare_block_data_picture(&block->data.picture, &blockcopy->data.picture); - default: - return mutils__compare_block_data_unknown(&block->data.unknown, &blockcopy->data.unknown, block->length); - } -} - -static void *malloc_or_die_(size_t size) -{ - void *x = malloc(size); - if(0 == x) { - fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (uint32_t)size); - exit(1); - } - return x; -} - -static void *calloc_or_die_(size_t n, size_t size) -{ - void *x = calloc(n, size); - if(0 == x) { - fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (uint32_t)n * (uint32_t)size); - exit(1); - } - return x; -} - -static char *strdup_or_die_(const char *s) -{ - char *x = strdup(s); - if(0 == x) { - fprintf(stderr, "ERROR: out of memory copying string \"%s\"\n", s); - exit(1); - } - return x; -} - -void mutils__init_metadata_blocks( - FLAC__StreamMetadata *streaminfo, - FLAC__StreamMetadata *padding, - FLAC__StreamMetadata *seektable, - FLAC__StreamMetadata *application1, - FLAC__StreamMetadata *application2, - FLAC__StreamMetadata *vorbiscomment, - FLAC__StreamMetadata *cuesheet, - FLAC__StreamMetadata *picture, - FLAC__StreamMetadata *unknown -) -{ - /* - most of the actual numbers and data in the blocks don't matter, - we just want to make sure the decoder parses them correctly - - remember, the metadata interface gets tested after the decoders, - so we do all the metadata manipulation here without it. - */ - - /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */ - streaminfo->is_last = false; - streaminfo->type = FLAC__METADATA_TYPE_STREAMINFO; - streaminfo->length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH; - streaminfo->data.stream_info.min_blocksize = 576; - streaminfo->data.stream_info.max_blocksize = 576; - streaminfo->data.stream_info.min_framesize = 0; - streaminfo->data.stream_info.max_framesize = 0; - streaminfo->data.stream_info.sample_rate = 44100; - streaminfo->data.stream_info.channels = 1; - streaminfo->data.stream_info.bits_per_sample = 8; - streaminfo->data.stream_info.total_samples = 0; - memset(streaminfo->data.stream_info.md5sum, 0, 16); - - padding->is_last = false; - padding->type = FLAC__METADATA_TYPE_PADDING; - padding->length = 1234; - - seektable->is_last = false; - seektable->type = FLAC__METADATA_TYPE_SEEKTABLE; - seektable->data.seek_table.num_points = 2; - seektable->length = seektable->data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH; - seektable->data.seek_table.points = malloc_or_die_(seektable->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint)); - seektable->data.seek_table.points[0].sample_number = 0; - seektable->data.seek_table.points[0].stream_offset = 0; - seektable->data.seek_table.points[0].frame_samples = streaminfo->data.stream_info.min_blocksize; - seektable->data.seek_table.points[1].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; - seektable->data.seek_table.points[1].stream_offset = 1000; - seektable->data.seek_table.points[1].frame_samples = streaminfo->data.stream_info.min_blocksize; - - application1->is_last = false; - application1->type = FLAC__METADATA_TYPE_APPLICATION; - application1->length = 8; - memcpy(application1->data.application.id, "This", 4); - application1->data.application.data = malloc_or_die_(4); - memcpy(application1->data.application.data, "\xf0\xe1\xd2\xc3", 4); - - application2->is_last = false; - application2->type = FLAC__METADATA_TYPE_APPLICATION; - application2->length = 4; - memcpy(application2->data.application.id, "Here", 4); - application2->data.application.data = 0; - - { - const uint32_t vendor_string_length = (uint32_t)strlen(FLAC__VENDOR_STRING); - vorbiscomment->is_last = false; - vorbiscomment->type = FLAC__METADATA_TYPE_VORBIS_COMMENT; - vorbiscomment->length = (4 + vendor_string_length) + 4 + (4 + 5) + (4 + 0); - vorbiscomment->data.vorbis_comment.vendor_string.length = vendor_string_length; - vorbiscomment->data.vorbis_comment.vendor_string.entry = malloc_or_die_(vendor_string_length+1); - memcpy(vorbiscomment->data.vorbis_comment.vendor_string.entry, FLAC__VENDOR_STRING, vendor_string_length+1); - vorbiscomment->data.vorbis_comment.num_comments = 2; - vorbiscomment->data.vorbis_comment.comments = malloc_or_die_(vorbiscomment->data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry)); - vorbiscomment->data.vorbis_comment.comments[0].length = 5; - vorbiscomment->data.vorbis_comment.comments[0].entry = malloc_or_die_(5+1); - memcpy(vorbiscomment->data.vorbis_comment.comments[0].entry, "ab=cd", 5+1); - vorbiscomment->data.vorbis_comment.comments[1].length = 0; - vorbiscomment->data.vorbis_comment.comments[1].entry = malloc_or_die_(1); - vorbiscomment->data.vorbis_comment.comments[1].entry[0] = '\0'; - } - - cuesheet->is_last = false; - cuesheet->type = FLAC__METADATA_TYPE_CUESHEET; - cuesheet->length = - /* cuesheet guts */ - ( - FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN + - FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + - FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN - ) / 8 + - /* 2 tracks */ - 3 * ( - FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN + - FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN - ) / 8 + - /* 3 index points */ - 3 * ( - FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN + - FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN + - FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN - ) / 8 - ; - memset(cuesheet->data.cue_sheet.media_catalog_number, 0, sizeof(cuesheet->data.cue_sheet.media_catalog_number)); - cuesheet->data.cue_sheet.media_catalog_number[0] = 'j'; - cuesheet->data.cue_sheet.media_catalog_number[1] = 'C'; - cuesheet->data.cue_sheet.lead_in = 2 * 44100; - cuesheet->data.cue_sheet.is_cd = true; - cuesheet->data.cue_sheet.num_tracks = 3; - cuesheet->data.cue_sheet.tracks = calloc_or_die_(cuesheet->data.cue_sheet.num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)); - cuesheet->data.cue_sheet.tracks[0].offset = 0; - cuesheet->data.cue_sheet.tracks[0].number = 1; - memcpy(cuesheet->data.cue_sheet.tracks[0].isrc, "ACBDE1234567", sizeof(cuesheet->data.cue_sheet.tracks[0].isrc)); - cuesheet->data.cue_sheet.tracks[0].type = 0; - cuesheet->data.cue_sheet.tracks[0].pre_emphasis = 1; - cuesheet->data.cue_sheet.tracks[0].num_indices = 2; - cuesheet->data.cue_sheet.tracks[0].indices = malloc_or_die_(cuesheet->data.cue_sheet.tracks[0].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index)); - cuesheet->data.cue_sheet.tracks[0].indices[0].offset = 0; - cuesheet->data.cue_sheet.tracks[0].indices[0].number = 0; - cuesheet->data.cue_sheet.tracks[0].indices[1].offset = 123 * 588; - cuesheet->data.cue_sheet.tracks[0].indices[1].number = 1; - cuesheet->data.cue_sheet.tracks[1].offset = 1234 * 588; - cuesheet->data.cue_sheet.tracks[1].number = 2; - memcpy(cuesheet->data.cue_sheet.tracks[1].isrc, "ACBDE7654321", sizeof(cuesheet->data.cue_sheet.tracks[1].isrc)); - cuesheet->data.cue_sheet.tracks[1].type = 1; - cuesheet->data.cue_sheet.tracks[1].pre_emphasis = 0; - cuesheet->data.cue_sheet.tracks[1].num_indices = 1; - cuesheet->data.cue_sheet.tracks[1].indices = malloc_or_die_(cuesheet->data.cue_sheet.tracks[1].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index)); - cuesheet->data.cue_sheet.tracks[1].indices[0].offset = 0; - cuesheet->data.cue_sheet.tracks[1].indices[0].number = 1; - cuesheet->data.cue_sheet.tracks[2].offset = 12345 * 588; - cuesheet->data.cue_sheet.tracks[2].number = 170; - cuesheet->data.cue_sheet.tracks[2].num_indices = 0; - - picture->is_last = false; - picture->type = FLAC__METADATA_TYPE_PICTURE; - picture->length = - ( - FLAC__STREAM_METADATA_PICTURE_TYPE_LEN + - FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* will add the length for the string later */ - FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* will add the length for the string later */ - FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN + - FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN + - FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN + - FLAC__STREAM_METADATA_PICTURE_COLORS_LEN + - FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */ - ) / 8 - ; - picture->data.picture.type = FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER; - picture->data.picture.mime_type = strdup_or_die_("image/jpeg"); - picture->length += strlen(picture->data.picture.mime_type); - picture->data.picture.description = (FLAC__byte*)strdup_or_die_("desc"); - picture->length += strlen((const char *)picture->data.picture.description); - picture->data.picture.width = 300; - picture->data.picture.height = 300; - picture->data.picture.depth = 24; - picture->data.picture.colors = 0; - picture->data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA"); - picture->data.picture.data_length = strlen((const char *)picture->data.picture.data); - picture->length += picture->data.picture.data_length; - - unknown->is_last = true; - unknown->type = 126; - unknown->length = 8; - unknown->data.unknown.data = malloc_or_die_(unknown->length); - memcpy(unknown->data.unknown.data, "\xfe\xdc\xba\x98\xf0\xe1\xd2\xc3", unknown->length); -} - -void mutils__free_metadata_blocks( - FLAC__StreamMetadata *streaminfo, - FLAC__StreamMetadata *padding, - FLAC__StreamMetadata *seektable, - FLAC__StreamMetadata *application1, - FLAC__StreamMetadata *application2, - FLAC__StreamMetadata *vorbiscomment, - FLAC__StreamMetadata *cuesheet, - FLAC__StreamMetadata *picture, - FLAC__StreamMetadata *unknown -) -{ - (void)streaminfo, (void)padding, (void)application2; - free(seektable->data.seek_table.points); - free(application1->data.application.data); - free(vorbiscomment->data.vorbis_comment.vendor_string.entry); - free(vorbiscomment->data.vorbis_comment.comments[0].entry); - free(vorbiscomment->data.vorbis_comment.comments); - free(cuesheet->data.cue_sheet.tracks[0].indices); - free(cuesheet->data.cue_sheet.tracks[1].indices); - free(cuesheet->data.cue_sheet.tracks); - free(picture->data.picture.mime_type); - free(picture->data.picture.description); - free(picture->data.picture.data); - free(unknown->data.unknown.data); -} diff --git a/flac/src/test_seeking/CMakeLists.txt b/flac/src/test_seeking/CMakeLists.txt deleted file mode 100644 index 5144291..0000000 --- a/flac/src/test_seeking/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_executable(test_seeking - main.c - $<$:../../include/share/win_utf8_io.h> - $<$:../share/win_utf8_io/win_utf8_io.c>) -target_link_libraries(test_seeking FLAC) diff --git a/flac/src/test_seeking/Makefile.am b/flac/src/test_seeking/Makefile.am deleted file mode 100644 index 9c9b8da..0000000 --- a/flac/src/test_seeking/Makefile.am +++ /dev/null @@ -1,39 +0,0 @@ -# test_seeking - Seeking tester for libFLAC -# Copyright (C) 2004-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -EXTRA_DIST = \ - CMakeLists.txt - -AM_CFLAGS = @OGG_CFLAGS@ - -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include - -check_PROGRAMS = test_seeking - -if OS_IS_WINDOWS -win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la -endif - -test_seeking_LDADD = \ - $(top_builddir)/src/libFLAC/libFLAC.la \ - $(win_utf8_lib) - -test_seeking_SOURCES = \ - main.c - -CLEANFILES = test_seeking.exe diff --git a/flac/src/test_seeking/main.c b/flac/src/test_seeking/main.c deleted file mode 100644 index 16ab9f4..0000000 --- a/flac/src/test_seeking/main.c +++ /dev/null @@ -1,473 +0,0 @@ -/* test_seeking - Seeking tester for libFLAC - * Copyright (C) 2004-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#if defined _MSC_VER || defined __MINGW32__ -#include -#else -#include -#endif -#include /* for stat() */ -#include "FLAC/assert.h" -#include "FLAC/metadata.h" -#include "FLAC/stream_decoder.h" -#include "share/compat.h" - -typedef struct { - FLAC__int32 **pcm; - FLAC__bool got_data; - FLAC__uint64 total_samples; - uint32_t channels; - uint32_t bits_per_sample; - FLAC__bool quiet; - FLAC__bool ignore_errors; - FLAC__bool error_occurred; -} DecoderClientData; - -static FLAC__bool stop_signal_ = false; - -static void our_sigint_handler_(int signum) -{ - (void)signum; - printf("(caught SIGINT) "); - fflush(stdout); - stop_signal_ = true; -} - -static FLAC__bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static FLAC__bool die_s_(const char *msg, const FLAC__StreamDecoder *decoder) -{ - FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(decoder); - - if(msg) - printf("FAILED, %s", msg); - else - printf("FAILED"); - - printf(", state = %u (%s)\n", (uint32_t)state, FLAC__StreamDecoderStateString[state]); - - return false; -} - -static uint32_t local_rand_(void) -{ -#if !defined _MSC_VER && !defined __MINGW32__ -#define RNDFUNC random -#else -#define RNDFUNC rand -#endif - /* every RAND_MAX I've ever seen is 2^15-1 or 2^31-1, so a little hackery here: */ - if (RAND_MAX > 32767) - return RNDFUNC(); - else /* usually MSVC, some solaris */ - return (RNDFUNC()<<15) | RNDFUNC(); -#undef RNDFUNC -} - -static FLAC__off_t get_filesize_(const char *srcpath) -{ - struct flac_stat_s srcstat; - - if(0 == flac_stat(srcpath, &srcstat)) - return srcstat.st_size; - else - return -1; -} - -static FLAC__bool read_pcm_(FLAC__int32 *pcm[], const char *rawfilename, const char *flacfilename) -{ - FILE *f; - uint32_t channels = 0, bps = 0, samples, i, j; - - FLAC__off_t rawfilesize = get_filesize_(rawfilename); - if (rawfilesize < 0) { - fprintf(stderr, "ERROR: can't determine filesize for %s\n", rawfilename); - return false; - } - /* get sample format from flac file; would just use FLAC__metadata_get_streaminfo() except it doesn't work for Ogg FLAC yet */ - { -#if 0 - FLAC__StreamMetadata streaminfo; - if(!FLAC__metadata_get_streaminfo(flacfilename, &streaminfo)) { - printf("ERROR: getting STREAMINFO from %s\n", flacfilename); - return false; - } - channels = streaminfo.data.stream_info.channels; - bps = streaminfo.data.stream_info.bits_per_sample; -#else - FLAC__bool ok = true; - FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new(); - FLAC__Metadata_Iterator *it = 0; - ok = ok && chain && (FLAC__metadata_chain_read(chain, flacfilename) || FLAC__metadata_chain_read_ogg(chain, flacfilename)); - ok = ok && (it = FLAC__metadata_iterator_new()); - if(ok) FLAC__metadata_iterator_init(it, chain); - ok = ok && (FLAC__metadata_iterator_get_block(it)->type == FLAC__METADATA_TYPE_STREAMINFO); - ok = ok && (channels = FLAC__metadata_iterator_get_block(it)->data.stream_info.channels); - ok = ok && (bps = FLAC__metadata_iterator_get_block(it)->data.stream_info.bits_per_sample); - if(it) FLAC__metadata_iterator_delete(it); - if(chain) FLAC__metadata_chain_delete(chain); - if(!ok) { - printf("ERROR: getting STREAMINFO from %s\n", flacfilename); - return false; - } -#endif - } - if(channels > 2) { - printf("ERROR: PCM verification requires 1 or 2 channels, got %u\n", channels); - return false; - } - if(bps != 8 && bps != 16) { - printf("ERROR: PCM verification requires 8 or 16 bps, got %u\n", bps); - return false; - } - samples = (uint32_t)(rawfilesize / channels / (bps>>3)); - if (samples > 10000000) { - fprintf(stderr, "ERROR: %s is too big\n", rawfilename); - return false; - } - for(i = 0; i < channels; i++) { - if(0 == (pcm[i] = malloc(sizeof(FLAC__int32)*samples))) { - printf("ERROR: allocating space for PCM samples\n"); - return false; - } - } - if(0 == (f = flac_fopen(rawfilename, "rb"))) { - printf("ERROR: opening %s for reading\n", rawfilename); - return false; - } - /* assumes signed big-endian data */ - if(bps == 8) { - signed char c; - for(i = 0; i < samples; i++) { - for(j = 0; j < channels; j++) { - if (fread(&c, 1, 1, f) == 1) - pcm[j][i] = c; - } - } - } - else { /* bps == 16 */ - uint8_t c[2]; - uint16_t value; - for(i = 0; i < samples; i++) { - for(j = 0; j < channels; j++) { - if (fread(&c, 1, 2, f) == 2) { - value = (c[0] << 8) | c[1]; - pcm[j][i] = value & 0x8000 ? 0xffff0000 | value : value; - } - } - } - } - fclose(f); - return true; -} - -static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - DecoderClientData *dcd = (DecoderClientData*)client_data; - - (void)decoder, (void)buffer; - - if(0 == dcd) { - printf("ERROR: client_data in write callback is NULL\n"); - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - - FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); /* decoder guarantees this */ - if (!dcd->quiet) - printf("frame@%" PRIu64 "(%u)... ", frame->header.number.sample_number, frame->header.blocksize); - fflush(stdout); - - /* check against PCM data if we have it */ - if (dcd->pcm) { - uint32_t c, i, j; - for (c = 0; c < frame->header.channels; c++) - for (i = (uint32_t)frame->header.number.sample_number, j = 0; j < frame->header.blocksize; i++, j++) - if (buffer[c][j] != dcd->pcm[c][i]) { - printf("ERROR: sample mismatch at sample#%u(%u), channel=%u, expected %d, got %d\n", i, j, c, buffer[c][j], dcd->pcm[c][i]); - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - } - - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -static void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - DecoderClientData *dcd = (DecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in metadata callback is NULL\n"); - return; - } - - if(dcd->error_occurred) - return; - - if (!dcd->got_data && metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { - dcd->got_data = true; - dcd->total_samples = metadata->data.stream_info.total_samples; - dcd->channels = metadata->data.stream_info.channels; - dcd->bits_per_sample = metadata->data.stream_info.bits_per_sample; - } -} - -static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - DecoderClientData *dcd = (DecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in error callback is NULL\n"); - return; - } - - if(!dcd->ignore_errors) { - printf("ERROR: got error callback: err = %u (%s)\n", (uint32_t)status, FLAC__StreamDecoderErrorStatusString[status]); - dcd->error_occurred = true; - } -} - -/* read mode: - * 0 - no read after seek - * 1 - read 2 frames - * 2 - read until end - */ -static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, FLAC__off_t filesize, uint32_t count, FLAC__int64 total_samples, uint32_t read_mode, FLAC__int32 **pcm) -{ - FLAC__StreamDecoder *decoder; - DecoderClientData decoder_client_data; - uint32_t i; - long int n; - - decoder_client_data.pcm = pcm; - decoder_client_data.got_data = false; - decoder_client_data.total_samples = 0; - decoder_client_data.quiet = false; - decoder_client_data.ignore_errors = false; - decoder_client_data.error_occurred = false; - - printf("\n+++ seek test: FLAC__StreamDecoder (%s FLAC, read_mode=%u)\n\n", is_ogg? "Ogg":"native", read_mode); - - decoder = FLAC__stream_decoder_new(); - if(0 == decoder) - return die_("FLAC__stream_decoder_new() FAILED, returned NULL\n"); - - if(is_ogg) { - if(FLAC__stream_decoder_init_ogg_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_("FLAC__stream_decoder_init_file() FAILED", decoder); - } - else { - if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_("FLAC__stream_decoder_init_file() FAILED", decoder); - } - - if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) - return die_s_("FLAC__stream_decoder_process_until_end_of_metadata() FAILED", decoder); - - if(!is_ogg) { /* not necessary to do this for Ogg because of its seeking method */ - /* process until end of stream to make sure we can still seek in that state */ - decoder_client_data.quiet = true; - if(!FLAC__stream_decoder_process_until_end_of_stream(decoder)) - return die_s_("FLAC__stream_decoder_process_until_end_of_stream() FAILED", decoder); - decoder_client_data.quiet = false; - - printf("stream decoder state is %s\n", FLAC__stream_decoder_get_resolved_state_string(decoder)); - if(FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_END_OF_STREAM) - return die_s_("expected FLAC__STREAM_DECODER_END_OF_STREAM", decoder); - } - - printf("file's total_samples is %" PRIu64 "\n", decoder_client_data.total_samples); - n = (long int)decoder_client_data.total_samples; - - if(n == 0 && total_samples >= 0) - n = (long int)total_samples; - - /* if we don't have a total samples count, just guess based on the file size */ - /* @@@ for is_ogg we should get it from last page's granulepos */ - if(n == 0) { - /* 8 would imply no compression, 9 guarantees that we will get some samples off the end of the stream to test that case */ - n = (long int)(9 * filesize / (decoder_client_data.channels * decoder_client_data.bits_per_sample)); - } - - printf("Begin seek barrage, count=%u\n", count); - - for (i = 0; !stop_signal_ && (count == 0 || i < count); i++) { - FLAC__uint64 pos; - - /* for the first 10, seek to the first 10 samples */ - if (n >= 10 && i < 10) { - pos = i; - } - /* for the second 10, seek to the last 10 samples */ - else if (n >= 10 && i < 20) { - pos = n - 1 - (i-10); - } - /* for the third 10, seek past the end and make sure we fail properly as expected */ - else if (i < 30) { - pos = n + (i-20); - } - else { - pos = (FLAC__uint64)(local_rand_() % n); - } - - printf("#%u:seek(%" PRIu64 ")... ", i, pos); - fflush(stdout); - if(!FLAC__stream_decoder_seek_absolute(decoder, pos)) { - if(pos >= (FLAC__uint64)n) - printf("seek past end failed as expected... "); - else if(decoder_client_data.total_samples == 0 && total_samples <= 0) - printf("seek failed, assuming it was past EOF... "); - else - return die_s_("FLAC__stream_decoder_seek_absolute() FAILED", decoder); - if(!FLAC__stream_decoder_flush(decoder)) - return die_s_("FLAC__stream_decoder_flush() FAILED", decoder); - } - else if(read_mode == 1) { - printf("decode_frame... "); - fflush(stdout); - if(!FLAC__stream_decoder_process_single(decoder)) - return die_s_("FLAC__stream_decoder_process_single() FAILED", decoder); - - printf("decode_frame... "); - fflush(stdout); - if(!FLAC__stream_decoder_process_single(decoder)) - return die_s_("FLAC__stream_decoder_process_single() FAILED", decoder); - } - else if(read_mode == 2) { - printf("decode_all... "); - fflush(stdout); - decoder_client_data.quiet = true; - if(!FLAC__stream_decoder_process_until_end_of_stream(decoder)) - return die_s_("FLAC__stream_decoder_process_until_end_of_stream() FAILED", decoder); - decoder_client_data.quiet = false; - } - - printf("OK\n"); - fflush(stdout); - } - stop_signal_ = false; - - if(FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_UNINITIALIZED) { - if(!FLAC__stream_decoder_finish(decoder)) - return die_s_("FLAC__stream_decoder_finish() FAILED", decoder); - } - - FLAC__stream_decoder_delete(decoder); - printf("\nPASSED!\n"); - - return true; -} - - -int main(int argc, char *argv[]) -{ - const char *flacfilename, *rawfilename = 0; - uint32_t count = 0, read_mode; - FLAC__int64 samples = -1; - FLAC__off_t flacfilesize; - FLAC__int32 *pcm[2] = { 0, 0 }; - FLAC__bool ok = true; - - static const char * const usage = "usage: test_seeking file.flac [#seeks] [#samples-in-file.flac] [file.raw]\n"; - - if (argc < 2 || argc > 5) { - fputs(usage, stderr); - return 1; - } - - flacfilename = argv[1]; - - if (argc > 2) - count = strtoul(argv[2], 0, 10); - if (argc > 3) - samples = strtoull(argv[3], 0, 10); - if (argc > 4) - rawfilename = argv[4]; - - if (count < 30) - fprintf(stderr, "WARNING: random seeks don't kick in until after 30 preprogrammed ones\n"); - -#if !defined _MSC_VER && !defined __MINGW32__ - { - struct timeval tv; - - if (gettimeofday(&tv, 0) < 0) { - fprintf(stderr, "WARNING: couldn't seed RNG with time\n"); - tv.tv_usec = 4321; - } - srandom(tv.tv_usec); - } -#else - srand((uint32_t)time(0)); -#endif - - flacfilesize = get_filesize_(flacfilename); - if (flacfilesize < 0) { - fprintf(stderr, "ERROR: can't determine filesize for %s\n", flacfilename); - return 1; - } - - if (rawfilename && !read_pcm_(pcm, rawfilename, flacfilename)) { - free(pcm[0]); - free(pcm[1]); - return 1; - } - - (void) signal(SIGINT, our_sigint_handler_); - - for (read_mode = 0; ok && read_mode <= 2; read_mode++) { - /* no need to do "decode all" read_mode if PCM checking is available */ - if (rawfilename && read_mode > 1) - continue; - if (strlen(flacfilename) > 4 && (0 == strcmp(flacfilename+strlen(flacfilename)-4, ".oga") || 0 == strcmp(flacfilename+strlen(flacfilename)-4, ".ogg"))) { -#if FLAC__HAS_OGG - ok = seek_barrage(/*is_ogg=*/true, flacfilename, flacfilesize, count, samples, read_mode, rawfilename? pcm : 0); -#else - fprintf(stderr, "ERROR: Ogg FLAC not supported\n"); - ok = false; -#endif - } - else { - ok = seek_barrage(/*is_ogg=*/false, flacfilename, flacfilesize, count, samples, read_mode, rawfilename? pcm : 0); - } - } - - free(pcm[0]); - free(pcm[1]); - - return ok? 0 : 2; -} diff --git a/flac/src/test_streams/CMakeLists.txt b/flac/src/test_streams/CMakeLists.txt deleted file mode 100644 index f9fafb9..0000000 --- a/flac/src/test_streams/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_executable(test_streams main.c) -target_link_libraries(test_streams FLAC grabbag) diff --git a/flac/src/test_streams/Makefile.am b/flac/src/test_streams/Makefile.am deleted file mode 100644 index 9aa4b02..0000000 --- a/flac/src/test_streams/Makefile.am +++ /dev/null @@ -1,29 +0,0 @@ -# test_streams - Simple test pattern generator -# Copyright (C) 2000-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -EXTRA_DIST = \ - CMakeLists.txt - -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include -check_PROGRAMS = test_streams -test_streams_SOURCES = \ - main.c - -test_streams_LDADD = $(top_builddir)/src/share/grabbag/libgrabbag.la -lm - -CLEANFILES = test_streams.exe diff --git a/flac/src/test_streams/main.c b/flac/src/test_streams/main.c deleted file mode 100644 index 466bf8e..0000000 --- a/flac/src/test_streams/main.c +++ /dev/null @@ -1,1398 +0,0 @@ -/* test_streams - Simple test pattern generator - * Copyright (C) 2000-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include "share/compat.h" -#if defined _MSC_VER || defined __MINGW32__ -#include -#else -#include -#endif -#include "FLAC/assert.h" -#include "FLAC/ordinals.h" -#include "share/compat.h" - -#if !defined _MSC_VER && !defined __MINGW32__ -#define GET_RANDOM_BYTE (((unsigned)random()) & 0xff) -#else -#define GET_RANDOM_BYTE (((unsigned)rand()) & 0xff) -#endif - -static FLAC__bool is_big_endian_host; - - -static FLAC__bool write_little_endian_unsigned(FILE *f, FLAC__uint32 x, size_t bytes) -{ - while(bytes) { - if(fputc(x, f) == EOF) - return false; - x >>= 8; - bytes--; - } - return true; -} - -static FLAC__bool write_little_endian_signed(FILE *f, FLAC__int32 x, size_t bytes) -{ - return write_little_endian_unsigned(f, (FLAC__uint32) x, bytes); -} - -static FLAC__bool write_little_endian_uint16(FILE *f, FLAC__uint16 x) -{ - return - fputc(x, f) != EOF && - fputc(x >> 8, f) != EOF - ; -} - -static FLAC__bool write_little_endian_int16(FILE *f, FLAC__int16 x) -{ - return write_little_endian_uint16(f, (FLAC__uint16)x); -} - -static FLAC__bool write_little_endian_uint24(FILE *f, FLAC__uint32 x) -{ - return - fputc(x, f) != EOF && - fputc(x >> 8, f) != EOF && - fputc(x >> 16, f) != EOF - ; -} - -static FLAC__bool write_little_endian_int24(FILE *f, FLAC__int32 x) -{ - return write_little_endian_uint24(f, (FLAC__uint32)x); -} - -static FLAC__bool write_little_endian_uint32(FILE *f, FLAC__uint32 x) -{ - return - fputc(x, f) != EOF && - fputc(x >> 8, f) != EOF && - fputc(x >> 16, f) != EOF && - fputc(x >> 24, f) != EOF - ; -} - -static FLAC__bool write_little_endian_int32(FILE *f, FLAC__int32 x) -{ - return write_little_endian_uint32(f, (FLAC__uint32)x); -} - -#if defined(_MSC_VER) -// silence 4 MSVC warnings 'conversion from 'FLAC__uint64' to 'int', possible loss of data' -#pragma warning ( disable : 4244 ) -#endif -static FLAC__bool write_little_endian_uint64(FILE *f, FLAC__uint64 x) -{ - return - fputc(x, f) != EOF && - fputc(x >> 8, f) != EOF && - fputc(x >> 16, f) != EOF && - fputc(x >> 24, f) != EOF && - fputc(x >> 32, f) != EOF && - fputc(x >> 40, f) != EOF && - fputc(x >> 48, f) != EOF && - fputc(x >> 56, f) != EOF - ; -} -#if defined(_MSC_VER) -#pragma warning ( default : 4244 ) -#endif - -static FLAC__bool write_big_endian(FILE *f, FLAC__int32 x, size_t bytes) -{ - if(bytes < 4) - x <<= 8*(4-bytes); - while(bytes) { - if(fputc(x>>24, f) == EOF) - return false; - x <<= 8; - bytes--; - } - return true; -} - -static FLAC__bool write_big_endian_uint16(FILE *f, FLAC__uint16 x) -{ - return - fputc(x >> 8, f) != EOF && - fputc(x, f) != EOF - ; -} - -#if 0 -/* @@@ not used (yet) */ -static FLAC__bool write_big_endian_int16(FILE *f, FLAC__int16 x) -{ - return write_big_endian_uint16(f, (FLAC__uint16)x); -} -#endif - -#if 0 -/* @@@ not used (yet) */ -static FLAC__bool write_big_endian_uint24(FILE *f, FLAC__uint32 x) -{ - return - fputc(x >> 16, f) != EOF && - fputc(x >> 8, f) != EOF && - fputc(x, f) != EOF - ; -} -#endif - -#if 0 -/* @@@ not used (yet) */ -static FLAC__bool write_big_endian_int24(FILE *f, FLAC__int32 x) -{ - return write_big_endian_uint24(f, (FLAC__uint32)x); -} -#endif - -static FLAC__bool write_big_endian_uint32(FILE *f, FLAC__uint32 x) -{ - return - fputc(x >> 24, f) != EOF && - fputc(x >> 16, f) != EOF && - fputc(x >> 8, f) != EOF && - fputc(x, f) != EOF - ; -} - -#if 0 -/* @@@ not used (yet) */ -static FLAC__bool write_big_endian_int32(FILE *f, FLAC__int32 x) -{ - return write_big_endian_uint32(f, (FLAC__uint32)x); -} -#endif - -static FLAC__bool write_sane_extended(FILE *f, unsigned val) - /* Write to 'f' a SANE extended representation of 'val'. Return false if - * the write succeeds; return true otherwise. - * - * SANE extended is an 80-bit IEEE-754 representation with sign bit, 15 bits - * of exponent, and 64 bits of significand (mantissa). Unlike most IEEE-754 - * representations, it does not imply a 1 above the MSB of the significand. - * - * Preconditions: - * val!=0U - */ -{ - unsigned int shift, exponent; - - FLAC__ASSERT(val!=0U); /* handling 0 would require a special case */ - - for(shift= 0U; (val>>(31-shift))==0U; ++shift) - ; - val<<= shift; - exponent= 63U-(shift+32U); /* add 32 for unused second word */ - - if(!write_big_endian_uint16(f, (FLAC__uint16)(exponent+0x3FFF))) - return false; - if(!write_big_endian_uint32(f, val)) - return false; - if(!write_big_endian_uint32(f, 0)) /* unused second word */ - return false; - - return true; -} - -/* a mono one-sample 16bps stream */ -static FLAC__bool generate_01(void) -{ - FILE *f; - FLAC__int16 x = -32768; - - if(0 == (f = fopen("test01.raw", "wb"))) - return false; - - if(!write_little_endian_int16(f, x)) - goto foo; - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a stereo one-sample 16bps stream */ -static FLAC__bool generate_02(void) -{ - FILE *f; - FLAC__int16 xl = -32768, xr = 32767; - - if(0 == (f = fopen("test02.raw", "wb"))) - return false; - - if(!write_little_endian_int16(f, xl)) - goto foo; - if(!write_little_endian_int16(f, xr)) - goto foo; - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a mono five-sample 16bps stream */ -static FLAC__bool generate_03(void) -{ - FILE *f; - FLAC__int16 x[] = { -25, 0, 25, 50, 100 }; - unsigned i; - - if(0 == (f = fopen("test03.raw", "wb"))) - return false; - - for(i = 0; i < 5; i++) - if(!write_little_endian_int16(f, x[i])) - goto foo; - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a stereo five-sample 16bps stream */ -static FLAC__bool generate_04(void) -{ - FILE *f; - FLAC__int16 x[] = { -25, 500, 0, 400, 25, 300, 50, 200, 100, 100 }; - unsigned i; - - if(0 == (f = fopen("test04.raw", "wb"))) - return false; - - for(i = 0; i < 10; i++) - if(!write_little_endian_int16(f, x[i])) - goto foo; - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a mono full-scale deflection 8bps stream */ -static FLAC__bool generate_fsd8(const char *fn, const int pattern[], unsigned reps) -{ - FILE *f; - unsigned rep, p; - - FLAC__ASSERT(pattern != 0); - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(rep = 0; rep < reps; rep++) { - for(p = 0; pattern[p]; p++) { - signed char x = pattern[p] > 0? 127 : -128; - if(fwrite(&x, sizeof(x), 1, f) < 1) - goto foo; - } - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a mono full-scale deflection 16bps stream */ -static FLAC__bool generate_fsd16(const char *fn, const int pattern[], unsigned reps) -{ - FILE *f; - unsigned rep, p; - - FLAC__ASSERT(pattern != 0); - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(rep = 0; rep < reps; rep++) { - for(p = 0; pattern[p]; p++) { - FLAC__int16 x = pattern[p] > 0? 32767 : -32768; - if(!write_little_endian_int16(f, x)) - goto foo; - } - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a stereo wasted-bits-per-sample 16bps stream */ -static FLAC__bool generate_wbps16(const char *fn, unsigned samples) -{ - FILE *f; - unsigned sample; - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(sample = 0; sample < samples; sample++) { - FLAC__int16 l = (sample % 2000) << 2; - FLAC__int16 r = (sample % 1000) << 3; - if(!write_little_endian_int16(f, l)) - goto foo; - if(!write_little_endian_int16(f, r)) - goto foo; - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a mono full-scale deflection 24bps stream */ -static FLAC__bool generate_fsd24(const char *fn, const int pattern[], unsigned reps) -{ - FILE *f; - unsigned rep, p; - - FLAC__ASSERT(pattern != 0); - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(rep = 0; rep < reps; rep++) { - for(p = 0; pattern[p]; p++) { - FLAC__int32 x = pattern[p] > 0? 8388607 : -8388608; - if(!write_little_endian_int24(f, x)) - goto foo; - } - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a mono full-scale deflection 32bps stream */ -static FLAC__bool generate_fsd32(const char *fn, const int pattern[], unsigned reps) -{ - FILE *f; - unsigned rep, p; - - FLAC__ASSERT(pattern != 0); - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(rep = 0; rep < reps; rep++) { - for(p = 0; pattern[p]; p++) { - FLAC__int32 x = pattern[p] > 0? 2147483647 : -2147483648; - if(!write_little_endian_int32(f, x)) - goto foo; - } - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a mono sine-wave 8bps stream */ -static FLAC__bool generate_sine8_1(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2) -{ - const FLAC__int8 full_scale = 127; - const double delta1 = 2.0 * M_PI / ( sample_rate / f1); - const double delta2 = 2.0 * M_PI / ( sample_rate / f2); - FILE *f; - double theta1, theta2; - unsigned i; - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int8 v = (FLAC__int8)(val + 0.5); - if(fwrite(&v, sizeof(v), 1, f) < 1) - goto foo; - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a stereo sine-wave 8bps stream */ -static FLAC__bool generate_sine8_2(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2, double fmult) -{ - const FLAC__int8 full_scale = 127; - const double delta1 = 2.0 * M_PI / ( sample_rate / f1); - const double delta2 = 2.0 * M_PI / ( sample_rate / f2); - FILE *f; - double theta1, theta2; - unsigned i; - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int8 v = (FLAC__int8)(val + 0.5); - if(fwrite(&v, sizeof(v), 1, f) < 1) - goto foo; - val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale; - v = (FLAC__int8)(val + 0.5); - if(fwrite(&v, sizeof(v), 1, f) < 1) - goto foo; - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a mono sine-wave 16bps stream */ -static FLAC__bool generate_sine16_1(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2) -{ - const FLAC__int16 full_scale = 32767; - const double delta1 = 2.0 * M_PI / ( sample_rate / f1); - const double delta2 = 2.0 * M_PI / ( sample_rate / f2); - FILE *f; - double theta1, theta2; - unsigned i; - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int16 v = (FLAC__int16)(val + 0.5); - if(!write_little_endian_int16(f, v)) - goto foo; - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a stereo sine-wave 16bps stream */ -static FLAC__bool generate_sine16_2(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2, double fmult) -{ - const FLAC__int16 full_scale = 32767; - const double delta1 = 2.0 * M_PI / ( sample_rate / f1); - const double delta2 = 2.0 * M_PI / ( sample_rate / f2); - FILE *f; - double theta1, theta2; - unsigned i; - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int16 v = (FLAC__int16)(val + 0.5); - if(!write_little_endian_int16(f, v)) - goto foo; - val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale; - v = (FLAC__int16)(val + 0.5); - if(!write_little_endian_int16(f, v)) - goto foo; - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a mono sine-wave 24bps stream */ -static FLAC__bool generate_sine24_1(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2) -{ - const FLAC__int32 full_scale = 0x7fffff; - const double delta1 = 2.0 * M_PI / ( sample_rate / f1); - const double delta2 = 2.0 * M_PI / ( sample_rate / f2); - FILE *f; - double theta1, theta2; - unsigned i; - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int32 v = (FLAC__int32)(val + 0.5); - if(!write_little_endian_int24(f, v)) - goto foo; - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a stereo sine-wave 24bps stream */ -static FLAC__bool generate_sine24_2(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2, double fmult) -{ - const FLAC__int32 full_scale = 0x7fffff; - const double delta1 = 2.0 * M_PI / ( sample_rate / f1); - const double delta2 = 2.0 * M_PI / ( sample_rate / f2); - FILE *f; - double theta1, theta2; - unsigned i; - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int32 v = (FLAC__int32)(val + 0.5); - if(!write_little_endian_int24(f, v)) - goto foo; - val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale; - v = (FLAC__int32)(val + 0.5); - if(!write_little_endian_int24(f, v)) - goto foo; - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a mono sine-wave 32bps stream */ -static FLAC__bool generate_sine32_1(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2) -{ - const FLAC__int32 full_scale = 0x7fffffff; - const double delta1 = 2.0 * M_PI / ( sample_rate / f1); - const double delta2 = 2.0 * M_PI / ( sample_rate / f2); - FILE *f; - double theta1, theta2; - unsigned i; - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int32 v = (FLAC__int32)(val + 0.5); - if(!write_little_endian_int32(f, v)) - goto foo; - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* a stereo sine-wave 32bps stream */ -static FLAC__bool generate_sine32_2(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2, double fmult) -{ - const FLAC__int32 full_scale = 0x7fffffff; - const double delta1 = 2.0 * M_PI / ( sample_rate / f1); - const double delta2 = 2.0 * M_PI / ( sample_rate / f2); - FILE *f; - double theta1, theta2; - unsigned i; - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int32 v = (FLAC__int32)(val + 0.5); - if(!write_little_endian_int32(f, v)) - goto foo; - val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale; - v = (FLAC__int32)(val + 0.5); - if(!write_little_endian_int32(f, v)) - goto foo; - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -static FLAC__bool generate_noise(const char *fn, unsigned bytes) -{ - FILE *f; - unsigned b; - - if(0 == (f = fopen(fn, "wb"))) - return false; - - for(b = 0; b < bytes; b++) { -#if !defined _MSC_VER && !defined __MINGW32__ - FLAC__byte x = (FLAC__byte)(((unsigned)random()) & 0xff); -#else - FLAC__byte x = (FLAC__byte)(((unsigned)rand()) & 0xff); -#endif - if(fwrite(&x, sizeof(x), 1, f) < 1) - goto foo; - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -static FLAC__bool generate_signed_raw(const char *filename, unsigned channels, unsigned bytes_per_sample, unsigned samples) -{ - const FLAC__int32 full_scale = (1 << (bytes_per_sample*8-1)) - 1; - const double f1 = 441.0, a1 = 0.61, f2 = 661.5, a2 = 0.37; - const double delta1 = 2.0 * M_PI / ( 44100.0 / f1); - const double delta2 = 2.0 * M_PI / ( 44100.0 / f2); - double theta1, theta2; - FILE *f; - unsigned i, j; - - if(0 == (f = fopen(filename, "wb"))) - return false; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - for(j = 0; j < channels; j++) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int32 v = (FLAC__int32)(val + 0.5) + ((GET_RANDOM_BYTE>>4)-8); - if(!write_little_endian_signed(f, v, bytes_per_sample)) - goto foo; - } - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -static FLAC__bool generate_unsigned_raw(const char *filename, unsigned channels, unsigned bytes_per_sample, unsigned samples) -{ - const FLAC__int32 full_scale = (1 << (bytes_per_sample*8-1)) - 1; - const double f1 = 441.0, a1 = 0.61, f2 = 661.5, a2 = 0.37; - const double delta1 = 2.0 * M_PI / ( 44100.0 / f1); - const double delta2 = 2.0 * M_PI / ( 44100.0 / f2); - const double half_scale = 0.5 * full_scale; - double theta1, theta2; - FILE *f; - unsigned i, j; - - if(0 == (f = fopen(filename, "wb"))) - return false; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - for(j = 0; j < channels; j++) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int32 v = (FLAC__int32)(half_scale + val + 0.5) + ((GET_RANDOM_BYTE>>4)-8); - if(!write_little_endian_unsigned(f, v, bytes_per_sample)) - goto foo; - } - } - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsigned channels, unsigned bps, unsigned samples) -{ - const unsigned bytes_per_sample = (bps+7)/8; - const unsigned true_size = channels * bytes_per_sample * samples; - const unsigned padded_size = (true_size + 1) & (~1u); - const unsigned shift = (bps%8)? 8 - (bps%8) : 0; - const FLAC__int32 full_scale = (1 << (bps-1)) - 1; - const double f1 = 441.0, a1 = 0.61, f2 = 661.5, a2 = 0.37; - const double delta1 = 2.0 * M_PI / ( sample_rate / f1); - const double delta2 = 2.0 * M_PI / ( sample_rate / f2); - double theta1, theta2; - FILE *f; - unsigned i, j; - - if(0 == (f = fopen(filename, "wb"))) - return false; - if(fwrite("FORM", 1, 4, f) < 4) - goto foo; - if(!write_big_endian_uint32(f, padded_size + 46)) - goto foo; - if(fwrite("AIFFCOMM\000\000\000\022", 1, 12, f) < 12) - goto foo; - if(!write_big_endian_uint16(f, (FLAC__uint16)channels)) - goto foo; - if(!write_big_endian_uint32(f, samples)) - goto foo; - if(!write_big_endian_uint16(f, (FLAC__uint16)bps)) - goto foo; - if(!write_sane_extended(f, sample_rate)) - goto foo; - if(fwrite("SSND", 1, 4, f) < 4) - goto foo; - if(!write_big_endian_uint32(f, true_size + 8)) - goto foo; - if(fwrite("\000\000\000\000\000\000\000\000", 1, 8, f) < 8) - goto foo; - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - for(j = 0; j < channels; j++) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int32 v = ((FLAC__int32)(val + 0.5) + ((GET_RANDOM_BYTE>>4)-8)) << shift; - if(!write_big_endian(f, v, bytes_per_sample)) - goto foo; - } - } - for(i = true_size; i < padded_size; i++) - if(fputc(0, f) == EOF) - goto foo; - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -/* flavor is: 0:WAVE, 1:RF64, 2:WAVE64 */ -static FLAC__bool generate_wav(const char *filename, unsigned sample_rate, unsigned channels, unsigned bps, unsigned samples, FLAC__bool strict, int flavor) -{ - const FLAC__bool waveformatextensible = strict && (channels > 2 || (bps != 8 && bps != 16)); - - const unsigned bytes_per_sample = (bps+7)/8; - const unsigned shift = (bps%8)? 8 - (bps%8) : 0; - /* this rig is not going over 4G so we're ok with 32-bit sizes here */ - const FLAC__uint32 true_size = channels * bytes_per_sample * samples; - const FLAC__uint32 padded_size = flavor<2? (true_size + 1) & (~1u) : (true_size + 7) & (~7u); - const FLAC__int32 full_scale = (1 << (bps-1)) - 1; - const double f1 = 441.0, a1 = 0.61, f2 = 661.5, a2 = 0.37; - const double delta1 = 2.0 * M_PI / ( sample_rate / f1); - const double delta2 = 2.0 * M_PI / ( sample_rate / f2); - double theta1, theta2; - FILE *f; - unsigned i, j; - - if(0 == (f = fopen(filename, "wb"))) - return false; - /* RIFFxxxxWAVE or equivalent: */ - switch(flavor) { - case 0: - if(fwrite("RIFF", 1, 4, f) < 4) - goto foo; - /* +4 for WAVE */ - /* +8+{40,16} for fmt chunk */ - /* +8 for data chunk header */ - if(!write_little_endian_uint32(f, 4 + 8+(waveformatextensible?40:16) + 8 + padded_size)) - goto foo; - if(fwrite("WAVE", 1, 4, f) < 4) - goto foo; - break; - case 1: - if(fwrite("RF64", 1, 4, f) < 4) - goto foo; - if(!write_little_endian_uint32(f, 0xffffffff)) - goto foo; - if(fwrite("WAVE", 1, 4, f) < 4) - goto foo; - break; - case 2: - /* RIFF GUID 66666972-912E-11CF-A5D6-28DB04C10000 */ - if(fwrite("\x72\x69\x66\x66\x2E\x91\xCF\x11\xA5\xD6\x28\xDB\x04\xC1\x00\x00", 1, 16, f) < 16) - goto foo; - /* +(16+8) for RIFF GUID + size */ - /* +16 for WAVE GUID */ - /* +16+8+{40,16} for fmt chunk */ - /* +16+8 for data chunk header */ - if(!write_little_endian_uint64(f, (16+8) + 16 + 16+8+(waveformatextensible?40:16) + (16+8) + padded_size)) - goto foo; - /* WAVE GUID 65766177-ACF3-11D3-8CD1-00C04F8EDB8A */ - if(fwrite("\x77\x61\x76\x65\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) < 16) - goto foo; - break; - default: - goto foo; - } - if(flavor == 1) { /* rf64 */ - if(fwrite("ds64", 1, 4, f) < 4) - goto foo; - if(!write_little_endian_uint32(f, 28)) /* ds64 chunk size */ - goto foo; - if(!write_little_endian_uint64(f, 36 + padded_size + (waveformatextensible?60:36))) - goto foo; - if(!write_little_endian_uint64(f, true_size)) - goto foo; - if(!write_little_endian_uint64(f, samples)) - goto foo; - if(!write_little_endian_uint32(f, 0)) /* table size */ - goto foo; - } - /* fmt chunk */ - if(flavor < 2) { - if(fwrite("fmt ", 1, 4, f) < 4) - goto foo; - /* chunk size */ - if(!write_little_endian_uint32(f, waveformatextensible?40:16)) - goto foo; - } - else { /* wave64 */ - /* fmt GUID 20746D66-ACF3-11D3-8CD1-00C04F8EDB8A */ - if(fwrite("\x66\x6D\x74\x20\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) < 16) - goto foo; - /* chunk size (+16+8 for GUID and size fields) */ - if(!write_little_endian_uint64(f, 16+8+(waveformatextensible?40:16))) - goto foo; - } - if(!write_little_endian_uint16(f, (FLAC__uint16)(waveformatextensible?65534:1))) - goto foo; - if(!write_little_endian_uint16(f, (FLAC__uint16)channels)) - goto foo; - if(!write_little_endian_uint32(f, sample_rate)) - goto foo; - if(!write_little_endian_uint32(f, sample_rate * channels * bytes_per_sample)) - goto foo; - if(!write_little_endian_uint16(f, (FLAC__uint16)(channels * bytes_per_sample))) /* block align */ - goto foo; - if(!write_little_endian_uint16(f, (FLAC__uint16)(bps+shift))) - goto foo; - if(waveformatextensible) { - if(!write_little_endian_uint16(f, (FLAC__uint16)22)) /* cbSize */ - goto foo; - if(!write_little_endian_uint16(f, (FLAC__uint16)bps)) /* validBitsPerSample */ - goto foo; - if(!write_little_endian_uint32(f, 0)) /* channelMask */ - goto foo; - /* GUID = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} */ - if(fwrite("\x01\x00\x00\x00\x00\x00\x10\x00\x80\x00\x00\xaa\x00\x38\x9b\x71", 1, 16, f) != 16) - goto foo; - } - /* data chunk */ - if(flavor < 2) { - if(fwrite("data", 1, 4, f) < 4) - goto foo; - if(!write_little_endian_uint32(f, flavor==1? 0xffffffff : true_size)) - goto foo; - } - else { /* wave64 */ - /* data GUID 61746164-ACF3-11D3-8CD1-00C04F8EDB8A */ - if(fwrite("\x64\x61\x74\x61\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) != 16) - goto foo; - /* +16+8 for GUID and size fields */ - if(!write_little_endian_uint64(f, 16+8 + true_size)) - goto foo; - } - - for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { - for(j = 0; j < channels; j++) { - double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; - FLAC__int32 v = ((FLAC__int32)(val + 0.5) + ((GET_RANDOM_BYTE>>4)-8)) << shift; - if(!write_little_endian_signed(f, v, bytes_per_sample)) - goto foo; - } - } - for(i = true_size; i < padded_size; i++) - if(fputc(0, f) == EOF) - goto foo; - - fclose(f); - return true; -foo: - fclose(f); - return false; -} - -static FLAC__bool generate_wackywavs(void) -{ - FILE *f; - FLAC__byte wav[] = { - 'R', 'I', 'F', 'F', 76, 0, 0, 0, - 'W', 'A', 'V', 'E', 'j', 'u', 'n', 'k', - 4, 0, 0, 0 , 'b', 'l', 'a', 'h', - 'p', 'a', 'd', ' ', 4, 0, 0, 0, - 'B', 'L', 'A', 'H', 'f', 'm', 't', ' ', - 16, 0, 0, 0, 1, 0, 1, 0, - 0x44,0xAC, 0, 0,0x88,0x58,0x01, 0, - 2, 0, 16, 0, 'd', 'a', 't', 'a', - 16, 0, 0, 0, 0, 0, 1, 0, - 4, 0, 9, 0, 16, 0, 25, 0, - 36, 0, 49, 0, 'p', 'a', 'd', ' ', - 4, 0, 0, 0, 'b', 'l', 'a', 'h' - }; - - if(0 == (f = fopen("wacky1.wav", "wb"))) - return false; - if(fwrite(wav, 1, 84, f) < 84) - goto foo; - fclose(f); - - wav[4] += 12; - if(0 == (f = fopen("wacky2.wav", "wb"))) - return false; - if(fwrite(wav, 1, 96, f) < 96) - goto foo; - fclose(f); - - return true; -foo: - fclose(f); - return false; -} - -static FLAC__bool write_simple_wavex_header (FILE * f, unsigned samplerate, unsigned channels, unsigned bytespersample, unsigned frames) -{ - unsigned datalen = channels * bytespersample * frames ; - - if (fwrite("RIFF", 1, 4, f) != 4) - return false; - if (!write_little_endian_uint32(f, 60 + datalen)) - return false; - - if (fwrite("WAVEfmt ", 8, 1, f) != 1) - return false; - if (!write_little_endian_uint32(f, 40)) - return false; - - if(!write_little_endian_uint16(f, 65534)) /* WAVEFORMATEXTENSIBLE tag */ - return false; - if(!write_little_endian_uint16(f, channels)) - return false; - if(!write_little_endian_uint32(f, samplerate)) - return false; - if(!write_little_endian_uint32(f, samplerate * channels * bytespersample)) - return false; - if(!write_little_endian_uint16(f, channels * bytespersample)) /* block align */ - return false; - if(!write_little_endian_uint16(f, bytespersample * 8)) - return false; - - if(!write_little_endian_uint16(f, 22)) /* cbSize */ - return false; - if(!write_little_endian_uint16(f, bytespersample * 8)) /* validBitsPerSample */ - return false; - if(!write_little_endian_uint32(f, 0)) /* channelMask */ - return false; - /* GUID = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} */ - if(fwrite("\x01\x00\x00\x00\x00\x00\x10\x00\x80\x00\x00\xaa\x00\x38\x9b\x71", 1, 16, f) != 16) - return false; - - if (fwrite("data", 1, 4, f) != 4) - return false; - if (!write_little_endian_uint32(f, datalen)) - return false; - - return true; -} - -static FLAC__bool generate_noisy_sine(void) -{ - FILE *f; - int64_t randstate = 0x1243456; - double sample, last_val = 0.0; - int k; - int seconds = 300; - - if(0 == (f = fopen("noisy-sine.wav", "wb"))) - return false; - - if(!write_simple_wavex_header (f, 44100, 1, 2, 44100*seconds)) - goto foo; - - for (k = 0 ; k < seconds * 44100 ; k++) { - /* Obvioulsy not a crypto quality RNG. */ - randstate = 11117 * randstate + 211231; - randstate = 11117 * randstate + 211231; - randstate = 11117 * randstate + 211231; - - sample = ((int32_t) randstate) / (0x7fffffff * 1.000001); - sample = 0.2 * sample - 0.9 * last_val; - - last_val = sample; - - sample += sin (2.0 * k * M_PI * 1.0 / 32.0); - sample *= 0.4; -#if !defined _MSC_VER - write_little_endian_int16(f, lrintf(sample * 32700.0)); -#else - write_little_endian_int16(f, (FLAC__int16)(sample * 32700.0)); -#endif - }; - - fclose(f); - - return true; -foo: - fclose(f); - return false; -} - -static FLAC__bool generate_wackywav64s(void) -{ - FILE *f; - FLAC__byte wav[] = { - 0x72,0x69,0x66,0x66,0x2E,0x91,0xCF,0x11, /* RIFF GUID */ - 0xA5,0xD6,0x28,0xDB,0x04,0xC1,0x00,0x00, - 152, 0, 0, 0, 0, 0, 0, 0, - 0x77,0x61,0x76,0x65,0xF3,0xAC,0xD3,0x11, /* WAVE GUID */ - 0x8C,0xD1,0x00,0xC0,0x4F,0x8E,0xDB,0x8A, - 0x6A,0x75,0x6E,0x6B,0xF3,0xAC,0xD3,0x11, /* junk GUID */ - 0x8C,0xD1,0x00,0xC0,0x4F,0x8E,0xDB,0x8A, - 32, 0, 0, 0 , 0, 0, 0, 0, - 'b', 'l', 'a', 'h', 'b', 'l', 'a', 'h', - 0x66,0x6D,0x74,0x20,0xF3,0xAC,0xD3,0x11, /* fmt GUID */ - 0x8C,0xD1,0x00,0xC0,0x4F,0x8E,0xDB,0x8A, - 40, 0, 0, 0 , 0, 0, 0, 0, - 1, 0, 1, 0,0x44,0xAC, 0, 0, - 0x88,0x58,0x01, 0, 2, 0, 16, 0, - 0x64,0x61,0x74,0x61,0xF3,0xAC,0xD3,0x11, /* data GUID */ - 0x8C,0xD1,0x00,0xC0,0x4F,0x8E,0xDB,0x8A, - 40, 0, 0, 0 , 0, 0, 0, 0, - 0, 0, 1, 0, 4, 0, 9, 0, - 16, 0, 25, 0, 36, 0, 49, 0, - 0x6A,0x75,0x6E,0x6B,0xF3,0xAC,0xD3,0x11, /* junk GUID */ - 0x8C,0xD1,0x00,0xC0,0x4F,0x8E,0xDB,0x8A, - 32, 0, 0, 0 , 0, 0, 0, 0, - 'b', 'l', 'a', 'h', 'b', 'l', 'a', 'h' - }; - - if(0 == (f = fopen("wacky1.w64", "wb"))) - return false; - if(fwrite(wav, 1, wav[16], f) < wav[16]) - goto foo; - fclose(f); - - wav[16] += 32; - if(0 == (f = fopen("wacky2.w64", "wb"))) - return false; - if(fwrite(wav, 1, wav[16], f) < wav[16]) - goto foo; - fclose(f); - - return true; -foo: - fclose(f); - return false; -} - -static FLAC__bool generate_wackyrf64s(void) -{ - FILE *f; - FLAC__byte wav[] = { - 'R', 'F', '6', '4', 255, 255, 255, 255, - 'W', 'A', 'V', 'E', 'd', 's', '6', '4', - 28, 0, 0, 0, 112, 0, 0, 0, - 0, 0, 0, 0, 16, 0, 0, 0, - 0, 0, 0, 0, 8, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 'j', 'u', 'n', 'k', - 4, 0, 0, 0, 'b', 'l', 'a', 'h', - 'p', 'a', 'd', ' ', 4, 0, 0, 0, - 'B', 'L', 'A', 'H', 'f', 'm', 't', ' ', - 16, 0, 0, 0, 1, 0, 1, 0, - 0x44,0xAC, 0, 0,0x88,0x58,0x01, 0, - 2, 0, 16, 0, 'd', 'a', 't', 'a', - 255, 255, 255, 255, 0, 0, 1, 0, - 4, 0, 9, 0, 16, 0, 25, 0, - 36, 0, 49, 0, 'p', 'a', 'd', ' ', - 4, 0, 0, 0, 'b', 'l', 'a', 'h' - }; - - if(0 == (f = fopen("wacky1.rf64", "wb"))) - return false; - if(fwrite(wav, 1, 120, f) < 120) - goto foo; - fclose(f); - - wav[20] += 12; - if(0 == (f = fopen("wacky2.rf64", "wb"))) - return false; - if(fwrite(wav, 1, 132, f) < 132) - goto foo; - fclose(f); - - return true; -foo: - fclose(f); - return false; -} - -static FLAC__bool generate_replaygain_tone (unsigned samplerate) -{ - FILE *f; - char fname [256] ; - double tone, sample, samplerange; - int k; - - flac_snprintf(fname, sizeof(fname), "rpg-tone-%u.wav", samplerate); - - if(0 == (f = fopen(fname, "wb"))) - return false; - - if(!write_simple_wavex_header (f, samplerate, 1, 3, 220500)) - goto foo; - - - samplerange = 0x7fffff; /* Largest sample value allowed for a 24 bit PCM file. */ - tone = 1000.0; /* 1 kHz */ - - for (k = 0 ; k < 5 * 44100 ; k++) { - sample = sin(2 * M_PI * tone * k / samplerate); - sample *= samplerange; - if (!write_little_endian_uint24(f, (FLAC__int32) sample)) - goto foo; - }; - - fclose(f); - - return true; -foo: - fclose(f); - return false; -} - -int main(int argc, char *argv[]) -{ - FLAC__uint32 test = 1; - unsigned channels; - - int pattern01[] = { 1, -1, 0 }; - int pattern02[] = { 1, 1, -1, 0 }; - int pattern03[] = { 1, -1, -1, 0 }; - int pattern04[] = { 1, -1, 1, -1, 0 }; - int pattern05[] = { 1, -1, -1, 1, 0 }; - int pattern06[] = { 1, -1, 1, 1, -1, 0 }; - int pattern07[] = { 1, -1, -1, 1, -1, 0 }; - - (void)argc; - (void)argv; - is_big_endian_host = (*((FLAC__byte*)(&test)))? false : true; - -#if !defined _MSC_VER && !defined __MINGW32__ - { - struct timeval tv; - - if(gettimeofday(&tv, 0) < 0) { - fprintf(stderr, "WARNING: couldn't seed RNG with time\n"); - tv.tv_usec = 4321; - } - srandom(tv.tv_usec); - } -#else - srand((unsigned)time(0)); -#endif - - if(!generate_01()) return 1; - if(!generate_02()) return 1; - if(!generate_03()) return 1; - if(!generate_04()) return 1; - - if(!generate_fsd8("fsd8-01.raw", pattern01, 100)) return 1; - if(!generate_fsd8("fsd8-02.raw", pattern02, 100)) return 1; - if(!generate_fsd8("fsd8-03.raw", pattern03, 100)) return 1; - if(!generate_fsd8("fsd8-04.raw", pattern04, 100)) return 1; - if(!generate_fsd8("fsd8-05.raw", pattern05, 100)) return 1; - if(!generate_fsd8("fsd8-06.raw", pattern06, 100)) return 1; - if(!generate_fsd8("fsd8-07.raw", pattern07, 100)) return 1; - - if(!generate_fsd16("fsd16-01.raw", pattern01, 100)) return 1; - if(!generate_fsd16("fsd16-02.raw", pattern02, 100)) return 1; - if(!generate_fsd16("fsd16-03.raw", pattern03, 100)) return 1; - if(!generate_fsd16("fsd16-04.raw", pattern04, 100)) return 1; - if(!generate_fsd16("fsd16-05.raw", pattern05, 100)) return 1; - if(!generate_fsd16("fsd16-06.raw", pattern06, 100)) return 1; - if(!generate_fsd16("fsd16-07.raw", pattern07, 100)) return 1; - - if(!generate_fsd24("fsd24-01.raw", pattern01, 100)) return 1; - if(!generate_fsd24("fsd24-02.raw", pattern02, 100)) return 1; - if(!generate_fsd24("fsd24-03.raw", pattern03, 100)) return 1; - if(!generate_fsd24("fsd24-04.raw", pattern04, 100)) return 1; - if(!generate_fsd24("fsd24-05.raw", pattern05, 100)) return 1; - if(!generate_fsd24("fsd24-06.raw", pattern06, 100)) return 1; - if(!generate_fsd24("fsd24-07.raw", pattern07, 100)) return 1; - - if(!generate_fsd32("fsd32-01.raw", pattern01, 100)) return 1; - if(!generate_fsd32("fsd32-02.raw", pattern02, 100)) return 1; - if(!generate_fsd32("fsd32-03.raw", pattern03, 100)) return 1; - if(!generate_fsd32("fsd32-04.raw", pattern04, 100)) return 1; - if(!generate_fsd32("fsd32-05.raw", pattern05, 100)) return 1; - if(!generate_fsd32("fsd32-06.raw", pattern06, 100)) return 1; - if(!generate_fsd32("fsd32-07.raw", pattern07, 100)) return 1; - - if(!generate_wbps16("wbps16-01.raw", 1000)) return 1; - - if(!generate_sine8_1("sine8-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1; - if(!generate_sine8_1("sine8-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1; - if(!generate_sine8_1("sine8-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1; - if(!generate_sine8_1("sine8-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1; - if(!generate_sine8_1("sine8-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1; - - if(!generate_sine8_2("sine8-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1; - if(!generate_sine8_2("sine8-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1; - if(!generate_sine8_2("sine8-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1; - if(!generate_sine8_2("sine8-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1; - if(!generate_sine8_2("sine8-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1; - if(!generate_sine8_2("sine8-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1; - if(!generate_sine8_2("sine8-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1; - if(!generate_sine8_2("sine8-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1; - if(!generate_sine8_2("sine8-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1; - if(!generate_sine8_2("sine8-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1; - - if(!generate_sine16_1("sine16-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1; - if(!generate_sine16_1("sine16-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1; - if(!generate_sine16_1("sine16-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1; - if(!generate_sine16_1("sine16-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1; - if(!generate_sine16_1("sine16-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1; - - if(!generate_sine16_2("sine16-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1; - if(!generate_sine16_2("sine16-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1; - if(!generate_sine16_2("sine16-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1; - if(!generate_sine16_2("sine16-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1; - if(!generate_sine16_2("sine16-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1; - if(!generate_sine16_2("sine16-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1; - if(!generate_sine16_2("sine16-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1; - if(!generate_sine16_2("sine16-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1; - if(!generate_sine16_2("sine16-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1; - if(!generate_sine16_2("sine16-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1; - - if(!generate_sine24_1("sine24-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1; - if(!generate_sine24_1("sine24-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1; - if(!generate_sine24_1("sine24-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1; - if(!generate_sine24_1("sine24-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1; - if(!generate_sine24_1("sine24-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1; - - if(!generate_sine24_2("sine24-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1; - if(!generate_sine24_2("sine24-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1; - if(!generate_sine24_2("sine24-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1; - if(!generate_sine24_2("sine24-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1; - if(!generate_sine24_2("sine24-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1; - if(!generate_sine24_2("sine24-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1; - if(!generate_sine24_2("sine24-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1; - if(!generate_sine24_2("sine24-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1; - if(!generate_sine24_2("sine24-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1; - if(!generate_sine24_2("sine24-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1; - - if(!generate_sine32_1("sine32-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1; - if(!generate_sine32_1("sine32-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1; - if(!generate_sine32_1("sine32-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1; - if(!generate_sine32_1("sine32-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1; - if(!generate_sine32_1("sine32-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1; - - if(!generate_sine32_2("sine32-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1; - if(!generate_sine32_2("sine32-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1; - if(!generate_sine32_2("sine32-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1; - if(!generate_sine32_2("sine32-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1; - if(!generate_sine32_2("sine32-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1; - if(!generate_sine32_2("sine32-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1; - if(!generate_sine32_2("sine32-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1; - if(!generate_sine32_2("sine32-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1; - if(!generate_sine32_2("sine32-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1; - if(!generate_sine32_2("sine32-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1; - - if(!generate_replaygain_tone(8000)) return 1; - if(!generate_replaygain_tone(11025)) return 1; - if(!generate_replaygain_tone(12000)) return 1; - if(!generate_replaygain_tone(16000)) return 1; - if(!generate_replaygain_tone(18900)) return 1; - if(!generate_replaygain_tone(22050)) return 1; - if(!generate_replaygain_tone(24000)) return 1; - if(!generate_replaygain_tone(28000)) return 1; - if(!generate_replaygain_tone(32000)) return 1; - if(!generate_replaygain_tone(36000)) return 1; - if(!generate_replaygain_tone(37800)) return 1; - if(!generate_replaygain_tone(44100)) return 1; - if(!generate_replaygain_tone(48000)) return 1; - if(!generate_replaygain_tone(96000)) return 1; - if(!generate_replaygain_tone(192000)) return 1; - - /* WATCHOUT: the size of noise.raw is hardcoded into test/test_flac.sh */ - if(!generate_noise("noise.raw", 65536 * 8 * 3)) return 1; - if(!generate_noise("noise8m32.raw", 32)) return 1; - if(!generate_wackywavs()) return 1; - if(!generate_wackywav64s()) return 1; - if(!generate_wackyrf64s()) return 1; - if(!generate_noisy_sine()) return 1; - for(channels = 1; channels <= 8; channels *= 2) { - unsigned bits_per_sample; - for(bits_per_sample = 8; bits_per_sample <= 24; bits_per_sample += 4) { - static const unsigned nsamples[] = { 1, 111, 4777 } ; - unsigned samples; - for(samples = 0; samples < sizeof(nsamples)/sizeof(nsamples[0]); samples++) { - char fn[64]; - - flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.aiff", channels, bits_per_sample, nsamples[samples]); - if(!generate_aiff(fn, 44100, channels, bits_per_sample, nsamples[samples])) - return 1; - - flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.wav", channels, bits_per_sample, nsamples[samples]); - if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/0)) - return 1; - - flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.rf64", channels, bits_per_sample, nsamples[samples]); - if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/1)) - return 1; - - flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.w64", channels, bits_per_sample, nsamples[samples]); - if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/2)) - return 1; - - if(bits_per_sample % 8 == 0) { - flac_snprintf(fn, sizeof (fn), "rt-%u-%u-signed-%u.raw", channels, bits_per_sample, nsamples[samples]); - if(!generate_signed_raw(fn, channels, bits_per_sample/8, nsamples[samples])) - return 1; - flac_snprintf(fn, sizeof (fn), "rt-%u-%u-unsigned-%u.raw", channels, bits_per_sample, nsamples[samples]); - if(!generate_unsigned_raw(fn, channels, bits_per_sample/8, nsamples[samples])) - return 1; - } - } - } - } - - return 0; -} diff --git a/flac/src/utils/Makefile.am b/flac/src/utils/Makefile.am deleted file mode 100644 index 5207b13..0000000 --- a/flac/src/utils/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ -# FLAC - Free Lossless Audio Codec -# Copyright (C) 2001-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# This file is part the FLAC project. FLAC is comprised of several -# components distributed under different licenses. The codec libraries -# are distributed under Xiph.Org's BSD-like license (see the file -# COPYING.Xiph in this distribution). All other programs, libraries, and -# plugins are distributed under the GPL (see COPYING.GPL). The documentation -# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the -# FLAC distribution contains at the top the terms under which it may be -# distributed. -# -# Since this particular file is relevant to all components of FLAC, -# it may be distributed under the Xiph.Org license, which is the least -# restrictive of those mentioned above. See the file COPYING.Xiph in this -# distribution. - -SUBDIRS = flacdiff flactimer diff --git a/flac/src/utils/flacdiff/CMakeLists.txt b/flac/src/utils/flacdiff/CMakeLists.txt deleted file mode 100644 index ec9f771..0000000 --- a/flac/src/utils/flacdiff/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_executable(flacdiff - main.cpp - $<$:../../../include/share/win_utf8_io.h> - $<$:../../share/win_utf8_io/win_utf8_io.c>) -target_link_libraries(flacdiff FLAC++) diff --git a/flac/src/utils/flacdiff/Makefile.am b/flac/src/utils/flacdiff/Makefile.am deleted file mode 100644 index b181d98..0000000 --- a/flac/src/utils/flacdiff/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -# flacdiff - Displays where two FLAC streams differ -# Copyright (C) 2007-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -EXTRA_DIST = \ - CMakeLists.txt \ - main.cpp diff --git a/flac/src/utils/flacdiff/main.cpp b/flac/src/utils/flacdiff/main.cpp deleted file mode 100644 index 358fe04..0000000 --- a/flac/src/utils/flacdiff/main.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* flacdiff - Displays where two FLAC streams differ - * Copyright (C) 2007-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "FLAC++/decoder.h" -#include "share/compat.h" - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -class AutoFILE { -protected: - ::FILE *f_; -public: - inline AutoFILE(const char *path, const char *mode): f_(::fopen(path, mode)) { } - inline virtual ~AutoFILE() { if (f_) (void)::fclose(f_); } - - inline operator bool() const { return 0 != f_; } - inline operator const ::FILE *() const { return f_; } - inline operator ::FILE *() { return f_; } -private: - AutoFILE(); - AutoFILE(const AutoFILE &); - void operator=(const AutoFILE &); -}; - -class Decoder: public FLAC::Decoder::Stream { -public: - Decoder(AutoFILE &f, FLAC__off_t tgt): tgtpos_((FLAC__uint64)tgt), curpos_(0), go_(true), err_(false), frame_(), f_(f) { memset(&frame_, 0, sizeof(::FLAC__Frame)); } - FLAC__uint64 tgtpos_, curpos_; - bool go_, err_; - ::FLAC__Frame frame_; -protected: - AutoFILE &f_; - // from FLAC::Decoder::Stream - virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) - { - *bytes = fread(buffer, 1, *bytes, f_); - if(ferror((FILE*)f_)) - return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; - else if(*bytes == 0 && feof((FILE*)f_)) - return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - else - return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - - virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) - { - FLAC__off_t off = ftello(f_); - if(off < 0) - return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - *absolute_byte_offset = off; - return ::FLAC__STREAM_DECODER_TELL_STATUS_OK; - } - - virtual bool eof_callback() - { - return (bool)feof((FILE*)f_); - } - - virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const /*buffer*/[]) - { - FLAC__uint64 pos; - if(!get_decode_position(&pos)) { - go_ = false; - err_ = true; - return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - if(pos > tgtpos_) { - go_ = false; - frame_ = *frame; - } - else - curpos_ = pos; - return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; - } - - virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) - { - fprintf(stderr, "got error %d:%s\n", status, ::FLAC__StreamDecoderErrorStatusString[status]); - go_ = false; - err_ = true; - } -}; - -static bool show_diff(AutoFILE &f1, AutoFILE &f2, FLAC__off_t off) -{ - Decoder d1(f1, off), d2(f2, off); - if(!d1) { - fprintf(stderr, "ERROR: setting up decoder1, state=%s\n", d1.get_state().resolved_as_cstring(d1)); - return false; - } - if(!d2) { - fprintf(stderr, "ERROR: setting up decoder2, state=%s\n", d2.get_state().resolved_as_cstring(d2)); - return false; - } - ::FLAC__StreamDecoderInitStatus is; - if((is = d1.init()) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - fprintf(stderr, "ERROR: initializing decoder1, status=%s state=%s\n", FLAC__StreamDecoderInitStatusString[is], d1.get_state().resolved_as_cstring(d1)); - return false; - } - if((is = d2.init()) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - fprintf(stderr, "ERROR: initializing decoder2, status=%s state=%s\n", FLAC__StreamDecoderInitStatusString[is], d2.get_state().resolved_as_cstring(d2)); - return false; - } - if(!d1.process_until_end_of_metadata()) { - fprintf(stderr, "ERROR: skipping metadata in decoder1, state=%s\n", d1.get_state().resolved_as_cstring(d1)); - return false; - } - if(!d2.process_until_end_of_metadata()) { - fprintf(stderr, "ERROR: skipping metadata in decoder2, state=%s\n", d2.get_state().resolved_as_cstring(d2)); - return false; - } - while(d1.go_ && d2.go_) { - if(!d1.process_single()) { - fprintf(stderr, "ERROR: decoding frame in decoder1, state=%s\n", d1.get_state().resolved_as_cstring(d1)); - return false; - } - if(!d2.process_single()) { - fprintf(stderr, "ERROR: decoding frame in decoder2, state=%s\n", d2.get_state().resolved_as_cstring(d2)); - return false; - } - } - if(d1.err_) { - fprintf(stderr, "ERROR: got err_ in decoder1, state=%s\n", d1.get_state().resolved_as_cstring(d1)); - return false; - } - if(d2.err_) { - fprintf(stderr, "ERROR: got err_ in decoder2, state=%s\n", d2.get_state().resolved_as_cstring(d2)); - return false; - } - if(d1.go_ != d2.go_) { - fprintf(stderr, "ERROR: d1.go_(%s) != d2.go_(%s)\n", d1.go_?"true":"false", d2.go_?"true":"false"); - return false; - } - fprintf(stdout, "pos1 = %" PRIu64 " blocksize=%u sample#%" PRIu64 " frame#%" PRIu64 "\n", d1.curpos_, d1.frame_.header.blocksize, d1.frame_.header.number.sample_number, d1.frame_.header.number.sample_number / d1.frame_.header.blocksize); - fprintf(stdout, "pos2 = %" PRIu64 " blocksize=%u sample#%" PRIu64 " frame#%" PRIu64 "\n", d2.curpos_, d2.frame_.header.blocksize, d2.frame_.header.number.sample_number, d2.frame_.header.number.sample_number / d2.frame_.header.blocksize); - - return true; -} - -static FLAC__off_t get_diff_offset(AutoFILE &f1, AutoFILE &f2) -{ - FLAC__off_t off = 0; - while(1) { - if(feof((FILE*)f1) && feof((FILE*)f2)) { - fprintf(stderr, "ERROR: files are identical\n"); - return -1; - } - if(feof((FILE*)f1)) { - fprintf(stderr, "ERROR: file1 EOF\n"); - return -1; - } - if(feof((FILE*)f2)) { - fprintf(stderr, "ERROR: file2 EOF\n"); - return -1; - } - if(fgetc(f1) != fgetc(f2)) - return off; - off++; - } -} - -static bool run(const char *fn1, const char *fn2) -{ - FLAC__off_t off; - AutoFILE f1(fn1, "rb"), f2(fn2, "rb"); - - if(!f1) { - flac_fprintf(stderr, "ERROR: opening %s for reading\n", fn1); - return false; - } - if(!f2) { - flac_fprintf(stderr, "ERROR: opening %s for reading\n", fn2); - return false; - } - - if((off = get_diff_offset(f1, f2)) < 0) - return false; - - fprintf(stdout, "got diff offset = %" PRId64 "\n", off); - - return show_diff(f1, f2, off); -} - -int main(int argc, char *argv[]) -{ - const char *usage = "usage: flacdiff flacfile1 flacfile2\n"; - -#ifdef _WIN32 - if (get_utf8_argv(&argc, &argv) != 0) { - fprintf(stderr, "ERROR: failed to convert command line parameters to UTF-8\n"); - return 1; - } -#endif - - if(argc > 1 && 0 == strcmp(argv[1], "-h")) { - printf("%s", usage); - return 0; - } - else if(argc != 3) { - fprintf(stderr, "%s", usage); - return 255; - } - - return run(argv[1], argv[2])? 0 : 1; -} diff --git a/flac/src/utils/flactimer/CMakeLists.txt b/flac/src/utils/flactimer/CMakeLists.txt deleted file mode 100644 index 47bf1e5..0000000 --- a/flac/src/utils/flactimer/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_executable(flactimer main.cpp) -target_link_libraries(flactimer FLAC++) diff --git a/flac/src/utils/flactimer/Makefile.am b/flac/src/utils/flactimer/Makefile.am deleted file mode 100644 index 0737863..0000000 --- a/flac/src/utils/flactimer/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -# flactimer - Runs a command and prints timing information -# Copyright (C) 2007-2009 Josh Coalson -# Copyright (C) 2011-2023 Xiph.Org Foundation -# -# 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. - -EXTRA_DIST = \ - CMakeLists.txt \ - main.cpp diff --git a/flac/src/utils/flactimer/main.cpp b/flac/src/utils/flactimer/main.cpp deleted file mode 100644 index 120a37f..0000000 --- a/flac/src/utils/flactimer/main.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* flactimer - Runs a command and prints timing information - * Copyright (C) 2007-2009 Josh Coalson - * Copyright (C) 2011-2023 Xiph.Org Foundation - * - * 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 HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include "share/compat.h" -#include "share/safe_str.h" - -static inline uint64_t time2nsec(const FILETIME &t) -{ - uint64_t n = t.dwHighDateTime; - n <<= 32; - n |= (uint64_t)t.dwLowDateTime; - return n * 100; -} - -static void printtime(FILE *fout, uint64_t nsec, uint64_t total) -{ - uint32_t pct = (uint32_t)(100.0 * ((double)nsec / (double)total)); - uint64_t msec = nsec / 1000000; nsec -= msec * 1000000; - uint64_t sec = msec / 1000; msec -= sec * 1000; - uint64_t min = sec / 60; sec -= min * 60; - uint64_t hour = min / 60; min -= hour * 60; - fprintf(fout, " %5u.%03u = %02u:%02u:%02u.%03u = %3u%%\n", - (uint32_t)((hour*60+min)*60+sec), - (uint32_t)msec, - (uint32_t)hour, - (uint32_t)min, - (uint32_t)sec, - (uint32_t)msec, - pct - ); -} - -int main(int argc, char *argv[]) -{ - const char *usage = "usage: flactimer [-1 | -2 | -o outputfile] command\n"; - FILE *fout = stderr; - - if(argc == 1 || (argc > 1 && 0 == strcmp(argv[1], "-h"))) { - fprintf(stderr, usage); - return 0; - } - argv++; - argc--; - if(0 == strcmp(argv[0], "-1") || 0 == strcmp(argv[0], "/1")) { - fout = stdout; - argv++; - argc--; - } - else if(0 == strcmp(argv[0], "-2") || 0 == strcmp(argv[0], "/2")) { - fout = stdout; - argv++; - argc--; - } - else if(0 == strcmp(argv[0], "-o")) { - if(argc < 2) { - fprintf(stderr, usage); - return 1; - } - fout = fopen(argv[1], "w"); - if(!fout) { - fprintf(stderr, "ERROR opening file %s for writing\n", argv[1]); - return 1; - } - argv += 2; - argc -= 2; - } - if(argc <= 0) { - fprintf(fout, "ERROR, no command!\n\n"); - fprintf(fout, usage); - fclose(fout); - return 1; - } - - // improvement: double-quote all args - int i, n = 0; - for(i = 0; i < argc; i++) { - if(i > 0) - n++; - n += strlen(argv[i]); - } - char *args = (char*)malloc(n+1); - if(!args) { - fprintf(fout, "ERROR, no memory\n"); - fclose(fout); - return 1; - } - args[0] = '\0'; - for(i = 0; i < argc; i++) { - if(i > 0) - safe_strncat(args, " ", sizeof(args)); - safe_strncat(args, argv[i], sizeof(args)); - } - - //fprintf(stderr, "@@@ cmd=[%s] args=[%s]\n", argv[0], args); - - STARTUPINFOA si; - GetStartupInfoA(&si); - - DWORD wallclock_msec = GetTickCount(); - - PROCESS_INFORMATION pi; - BOOL ok = CreateProcessA( - argv[0], // lpApplicationName - args, // lpCommandLine - NULL, // lpProcessAttributes - NULL, // lpThreadAttributes - FALSE, // bInheritHandles - 0, // dwCreationFlags - NULL, // lpEnvironment - NULL, // lpCurrentDirectory - &si, // lpStartupInfo (inherit from this proc?) - &pi // lpProcessInformation - ); - - if(!ok) { - fprintf(fout, "ERROR running command\n"); - free(args); //@@@ ok to free here or have to wait to wait till process is reaped? - fclose(fout); - return 1; - } - - //fprintf(stderr, "@@@ waiting...\n"); - WaitForSingleObject(pi.hProcess, INFINITE); - //fprintf(stderr, "@@@ done\n"); - - wallclock_msec = GetTickCount() - wallclock_msec; - - FILETIME creation_time; - FILETIME exit_time; - FILETIME kernel_time; - FILETIME user_time; - if(!GetProcessTimes(pi.hProcess, &creation_time, &exit_time, &kernel_time, &user_time)) { - fprintf(fout, "ERROR getting time info\n"); - free(args); //@@@ ok to free here or have to wait to wait till process is reaped? - fclose(fout); - return 1; - } - uint64_t kernel_nsec = time2nsec(kernel_time); - uint64_t user_nsec = time2nsec(user_time); - - fprintf(fout, "Kernel Time = "); printtime(fout, kernel_nsec, (uint64_t)wallclock_msec * 1000000); - fprintf(fout, "User Time = "); printtime(fout, user_nsec, (uint64_t)wallclock_msec * 1000000); - fprintf(fout, "Process Time = "); printtime(fout, kernel_nsec+user_nsec, (uint64_t)wallclock_msec * 1000000); - fprintf(fout, "Global Time = "); printtime(fout, (uint64_t)wallclock_msec * 1000000, (uint64_t)wallclock_msec * 1000000); - - CloseHandle(pi.hThread); - CloseHandle(pi.hProcess); - - free(args); //@@@ always causes crash, maybe CreateProcess takes ownership? - fclose(fout); - return 0; -} diff --git a/flac/src/utils/loudness/loudness.sci b/flac/src/utils/loudness/loudness.sci deleted file mode 100644 index a476a17..0000000 --- a/flac/src/utils/loudness/loudness.sci +++ /dev/null @@ -1,115 +0,0 @@ -// Equal Loudness Filter -// -// Adapted from original MATLAB code written by David Robinson -// -// http://replaygain.hydrogenaudio.org/proposal/equal_loudness.html -// http://replaygain.hydrogenaudio.org/proposal/mfiles/equalloudfilt.m - -// ***************************************************************************** -// Print Filter Coefficients -// -// This function takes a vector of filter tap settings, and prints -// each tap setting from least significant to most significant. - -function c=printcoeff(p) - - c=coeff(p); - c=c($:-1:1); - - for ix = 1:1:length(c) - if ix > 1 - printf(" ") - end - printf("%.14f", c(ix)); - end - -endfunction - -// ***************************************************************************** -// Equal Loudness Filter -// -// This function is adapted from David Robison's original MATLAB code. -// Apart from changes to port it to scilab, the other change is to -// use a single specification of the frequency points in the 80dB Equal -// Loudness curve. -// -// The original code had different curves for different sampling -// frequencies. This code dynamically computes the current data -// points to use as determined by the Nyquist frequency. - -function [a1,b1,a2,b2]=equalloudfilt(fs); -// Design a filter to match equal loudness curves -// 9/7/2001 - -[%nargout,%nargin]=argn(0); - -// If the user hasn't specified a sampling frequency, use the CD default -if %nargin<1 then - fs=44100; -end - -// Specify the 80 dB Equal Loudness curve -EL80=[0,120;20,113;30,103;40,97;50,93;60,91;70,89;80,87;90,86; .. - .. - 100,85;200,78;300,76;400,76;500,76;600,76;700,77;800,78;900,79.5; .. - .. - 1000,80;1500,79;2000,77;2500,74;3000,71.5;3700,70;4000,70.5; .. - 5000,74;6000,79;7000,84;8000,86;9000,86; .. - .. - 10000,85;12000,95;15000,110;20000,125;24000,140]; - -for ex = 1:1:length(EL80(:,1)) - if EL80(ex,1) > fs/2 - EL80 = [ EL80(1:ex-1,:); fs/2, EL80(ex-1,2) ]; - break - elseif EL80(ex,1) == fs/2 - EL80 = EL80(1:ex,:); - break - end - if ex == length(EL80(:,1)) - EL80 = [ EL80(1:$, :); fs/2, EL80($,2) ]; - end -end - -// convert frequency and amplitude of the equal loudness curve into format suitable for yulewalk -f=EL80(:,1)./(fs/2); -m=10.^((70-EL80(:,2))/20); - -// Use a MATLAB utility to design a best bit IIR filter -[b1,a1]=yulewalk(10,f,m); - -// Add a 2nd order high pass filter at 150Hz to finish the job -hz=iir(2,'hp','butt',[150/fs,0],[1e-3 1e-3]); -b2=numer(hz); // b2=b2($:-1:1); -a2=denom(hz); // a2=a2($:-1:1); - -endfunction - -// ***************************************************************************** -// Generate Filter Taps -// -// Generate the filter taps for each of the desired frequencies. - -format('v', 16); - -freqs = [ 8000 11025 12000 16000 18900 22050 24000 .. - 28000 32000 36000 37800 44100 48000 ]; - -for fx = 1:1:length(freqs) - - printf("\n%d\n", freqs(fx)); - - [a1,b1,a2,b2] = equalloudfilt(freqs(fx)); - - printf("{ "); bb=printcoeff(b1); printf(" }\n"); - printf("{ "); aa=printcoeff(a1); printf(" }\n"); - - printf("{ "); printcoeff(b2); printf(" }\n"); - printf("{ "); printcoeff(a2); printf(" }\n"); - -// freqz_fwd(bb,aa,1024,freqs(fx)); - -end - - -quit diff --git a/freetype/LICENSE.TXT b/freetype/LICENSE.TXT deleted file mode 100644 index 8b9ce9e..0000000 --- a/freetype/LICENSE.TXT +++ /dev/null @@ -1,46 +0,0 @@ -FREETYPE LICENSES ------------------ - -The FreeType 2 font engine is copyrighted work and cannot be used -legally without a software license. In order to make this project -usable to a vast majority of developers, we distribute it under two -mutually exclusive open-source licenses. - -This means that *you* must choose *one* of the two licenses described -below, then obey all its terms and conditions when using FreeType 2 in -any of your projects or products. - - - The FreeType License, found in the file `docs/FTL.TXT`, which is - similar to the original BSD license *with* an advertising clause - that forces you to explicitly cite the FreeType project in your - product's documentation. All details are in the license file. - This license is suited to products which don't use the GNU General - Public License. - - Note that this license is compatible to the GNU General Public - License version 3, but not version 2. - - - The GNU General Public License version 2, found in - `docs/GPLv2.TXT` (any later version can be used also), for - programs which already use the GPL. Note that the FTL is - incompatible with GPLv2 due to its advertisement clause. - -The contributed BDF and PCF drivers come with a license similar to -that of the X Window System. It is compatible to the above two -licenses (see files `src/bdf/README` and `src/pcf/README`). The same -holds for the source code files `src/base/fthash.c` and -`include/freetype/internal/fthash.h`; they were part of the BDF driver -in earlier FreeType versions. - -The gzip module uses the zlib license (see `src/gzip/zlib.h`) which -too is compatible to the above two licenses. - -The files `src/autofit/ft-hb.c` and `src/autofit/ft-hb.h` contain code -taken almost verbatim from the HarfBuzz file `hb-ft.cc`, which uses -the 'Old MIT' license, compatible to the above two licenses. - -The MD5 checksum support (only used for debugging in development -builds) is in the public domain. - - ---- end of LICENSE.TXT --- diff --git a/freetype/README b/freetype/README deleted file mode 100644 index cd4c1d7..0000000 --- a/freetype/README +++ /dev/null @@ -1,107 +0,0 @@ -FreeType 2.13.2 -=============== - -Homepage: https://www.freetype.org - -FreeType is a freely available software library to render fonts. - -It is written in C, designed to be small, efficient, highly -customizable, and portable while capable of producing high-quality -output (glyph images) of most vector and bitmap font formats. - -Please read the `docs/CHANGES` file, it contains IMPORTANT -INFORMATION. - -Read the files `docs/INSTALL*` for installation instructions; see the -file `docs/LICENSE.TXT` for the available licenses. - -For using FreeType's git repository instead of a distribution bundle, -please read file `README.git`. Note that you have to actually clone -the repository; using a snapshot will not work (in other words, don't -use gitlab's 'Download' button). - -The FreeType 2 API reference is located in directory `docs/reference`; -use the file `index.html` as the top entry point. [Please note that -currently the search function for locally installed documentation -doesn't work due to cross-site scripting issues.] - -Additional documentation is available as a separate package from our -sites. Go to - - https://download.savannah.gnu.org/releases/freetype/ - -and download one of the following files. - - freetype-doc-2.13.2.tar.xz - freetype-doc-2.13.2.tar.gz - ftdoc2132.zip - -To view the documentation online, go to - - https://www.freetype.org/freetype2/docs/ - - -Mailing Lists -------------- - -The preferred way of communication with the FreeType team is using -e-mail lists. - - general use and discussion: freetype@nongnu.org - engine internals, porting, etc.: freetype-devel@nongnu.org - announcements: freetype-announce@nongnu.org - git repository tracker: freetype-commit@nongnu.org - -The lists are moderated; see - - https://www.freetype.org/contact.html - -how to subscribe. - - -Bugs ----- - -Please submit bug reports at - - https://gitlab.freedesktop.org/freetype/freetype/-/issues - -Alternatively, you might report bugs by e-mail to -`freetype-devel@nongnu.org`. Don't forget to send a detailed -explanation of the problem -- there is nothing worse than receiving a -terse message that only says 'it doesn't work'. - - -Patches -------- - -For larger changes please provide merge requests at - - https://gitlab.freedesktop.org/freetype/freetype/-/merge_requests - -Alternatively, you can send patches to the `freetype-devel@nongnu.org` -mailing list -- and thank you in advance for your work on improving -FreeType! - -Details on the process can be found here: - - https://www.freetype.org/developer.html#patches - - -Enjoy! - - The FreeType Team - ----------------------------------------------------------------------- - -Copyright (C) 2006-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute -this file you indicate that you have read the license and understand -and accept it fully. - - ---- end of README --- diff --git a/freetype/README.git b/freetype/README.git deleted file mode 100644 index 117d74f..0000000 --- a/freetype/README.git +++ /dev/null @@ -1,102 +0,0 @@ -README.git -========== - - -repository issues ------------------ - -FreeType's official repository site is - - https://gitlab.freedesktop.org/freetype , - -from which the 'freetype.git' and 'freetype-demos.git' repositories -can be cloned in the usual way. - - git clone https://gitlab.freedesktop.org/freetype/freetype.git - git clone https://gitlab.freedesktop.org/freetype/freetype-demos.git - -If you want to use the Savannah mirror instead, you have to do a -slightly different incantation because the repository names contain -digit '2' for historical reasons. - - git clone \ - https://git.savannah.nongnu.org/git/freetype/freetype2.git \ - freetype - git clone \ - https://git.savannah.nongnu.org/git/freetype/freetype2-demos.git \ - freetype-demos - - -standard builds with `configure` --------------------------------- - -The git repository doesn't contain pre-built configuration scripts for -UNIXish platforms. To generate them say - - sh autogen.sh - -which in turn depends on the following packages: - - automake (1.10.1) - libtool (2.2.4) - autoconf (2.62) - -The versions given in parentheses are known to work. Newer versions -should work too, of course. Note that `autogen.sh` also sets up -proper file permissions for the `configure` and auxiliary scripts. - -The `autogen.sh` script checks whether the versions of the above three -tools match the numbers above. Otherwise it will complain and suggest -either upgrading or using environment variables to point to more -recent versions of the required tools. - -Note that `aclocal` is provided by the 'automake' package on Linux, -and that `libtoolize` is called `glibtoolize` on Darwin (OS X). - - -alternative build methods -------------------------- - -For static builds that don't use platform-specific optimizations, no -configure script is necessary at all; saying - - make setup ansi - make - -should work on all platforms that have GNU `make` (or `makepp`). - -A build with `cmake` or `meson` can be done directly from the git -repository. However, if you want to use the `FT_DEBUG_LOGGING` macro -(see file `docs/DEBUG` for more information) it is currently mandatory -to execute `autogen.sh` in advance; this script clones the 'dlg' git -submodule and copies some files into FreeType's source tree. - - -Code of Conduct ---------------- - -Please note that this project is released with a Contributor Code of -Conduct (CoC). By participating in this project you agree to abide by -its terms, which you can find in the following link: - - https://www.freedesktop.org/wiki/CodeOfConduct - -CoC issues may be raised to the project maintainers at the following -address: - - wl@gnu.org - apodtele@gmail.com - ----------------------------------------------------------------------- - -Copyright (C) 2005-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute -this file you indicate that you have read the license and understand -and accept it fully. - - ---- end of README.git --- diff --git a/freetype/build-freetype.lua b/freetype/build-freetype.lua deleted file mode 100644 index e786598..0000000 --- a/freetype/build-freetype.lua +++ /dev/null @@ -1,96 +0,0 @@ -local m = {} - -local scriptdir = path.getabsolute(path.getdirectory(_SCRIPT)) - -function m.generateproject(liboutdir, intdir) - project"freetype" - kind"staticLib" - language"C" -- c++ will mangle names and sfml wont build - targetdir (liboutdir) - objdir(intdir) - warnings"Off" - - includedirs {path.join(scriptdir, "include")} - - defines - { - "FT2_BUILD_LIBRARY", - "NDEBUG", -- have freetype always be in release mode - "FT_DEBUG_LEVEL_ERROR=0", -- fix linking errors - "FT_DEBUG_LEVEL_TRACE=0" -- fix linking errors - } - - files - { - path.join(scriptdir, "src/autofit/autofit.c"), - path.join(scriptdir, "src/base/ftbase.c"), - path.join(scriptdir, "src/base/ftbbox.c"), - path.join(scriptdir, "src/base/ftbdf.c"), - path.join(scriptdir, "src/base/ftbitmap.c"), - path.join(scriptdir, "src/base/ftcid.c"), - path.join(scriptdir, "src/base/ftfstype.c"), - path.join(scriptdir, "src/base/ftgasp.c"), - path.join(scriptdir, "src/base/ftglyph.c"), - path.join(scriptdir, "src/base/ftgxval.c"), - path.join(scriptdir, "src/base/ftinit.c"), - path.join(scriptdir, "src/base/ftmm.c"), - path.join(scriptdir, "src/base/ftotval.c"), - path.join(scriptdir, "src/base/ftpatent.c"), - path.join(scriptdir, "src/base/ftpfr.c"), - path.join(scriptdir, "src/base/ftstroke.c"), - path.join(scriptdir, "src/base/ftsynth.c"), - path.join(scriptdir, "src/base/fttype1.c"), - path.join(scriptdir, "src/base/ftwinfnt.c"), - path.join(scriptdir, "src/bdf/bdf.c"), - path.join(scriptdir, "src/bzip2/ftbzip2.c"), - path.join(scriptdir, "src/cache/ftcache.c"), - path.join(scriptdir, "src/cff/cff.c"), - path.join(scriptdir, "src/cid/type1cid.c"), - path.join(scriptdir, "src/gzip/ftgzip.c"), - path.join(scriptdir, "src/lzw/ftlzw.c"), - path.join(scriptdir, "src/pcf/pcf.c"), - path.join(scriptdir, "src/pfr/pfr.c"), - path.join(scriptdir, "src/psaux/psaux.c"), - path.join(scriptdir, "src/pshinter/pshinter.c"), - path.join(scriptdir, "src/psnames/psnames.c"), - path.join(scriptdir, "src/raster/raster.c"), - path.join(scriptdir, "src/sdf/sdf.c"), - path.join(scriptdir, "src/sfnt/sfnt.c"), - path.join(scriptdir, "src/smooth/smooth.c"), - path.join(scriptdir, "src/svg/svg.c"), - path.join(scriptdir, "src/truetype/truetype.c"), - path.join(scriptdir, "src/type1/type1.c"), - path.join(scriptdir, "src/type42/type42.c"), - path.join(scriptdir, "src/winfonts/winfnt.c"), - path.join(scriptdir, "src/base/ftdebug.c"), --fix linking errors related to FT_THROW, et)c - } - - filter "system:linux" - defines - { - "HAVE_FCNTL_H",--fix error in ftsystem.c - "HAVE_UNISTD_H" --fix error in ftsystem.c - } - - filter"system:windows" - files - { - path.join(scriptdir, "builds/windows/ftsystem.c"), - path.join(scriptdir, "builds/windows/ftdebug.c"), - } - - filter"system:linux" - files{path.join(scriptdir, "builds/unix/ftsystem.c")} - - filter "configurations:Debug" - optimize"Speed" - - filter"" -end - -function m.link() - externalincludedirs{path.join(scriptdir, "include")} - links {"freetype"} -end - -return m \ No newline at end of file diff --git a/freetype/builds/amiga/README b/freetype/builds/amiga/README deleted file mode 100644 index 5b2abef..0000000 --- a/freetype/builds/amiga/README +++ /dev/null @@ -1,110 +0,0 @@ - -README for the builds/amiga subdirectory. - -Copyright (C) 2005-2023 by -Werner Lemberg and Detlef Würkner. - -This file is part of the FreeType project, and may only be used, modified, -and distributed under the terms of the FreeType project license, -LICENSE.TXT. By continuing to use, modify, or distribute this file you -indicate that you have read the license and understand and accept it -fully. - - -The makefile.os4 is for the AmigaOS4 SDK. To use it, type -"make -f makefile.os4", it produces a link library libft2_ppc.a. - -The makefile is for ppc-morphos-gcc-2.95.3-bin.tgz (gcc 2.95.3 hosted on -68k-Amiga producing MorphOS-PPC-binaries from http://www.morphos.de). -To use it, type "make assign", then "make"; it produces a link library -libft2_ppc.a. - -The smakefile is a makefile for Amiga SAS/C 6.58 (no longer available, -latest sold version was 6.50, updates can be found in Aminet). It is -based on the version found in the sourcecode of ttf.library 0.83b for -FreeType 1.3.1 from Richard Griffith (ragriffi@sprynet.com, -http://ragriffi.home.sprynet.com). - -You will also need the latest include files and amiga.lib from the -Amiga web site (https://os.amigaworld.de/download.php?id=3) for -AmigaOS 3.9; the generated code should work under AmigaOS 2.04 and up. - -To use it, call "smake assign" and then "smake" from the builds/amiga -directory. The results are: - -- A link library "ft2_680x0.lib" (where x depends on the setting of - the CPU entry in the smakefile) containing all FreeType2 parts - except of the init code, debugging code, and the system interface - code. - -- ftsystem.o, an object module containing the standard version of the - system interface code which uses fopen() fclose() fread() fseek() - ftell() malloc() realloc() and free() from lib:sc.lib (not pure). - -- ftsystempure.o, an object module containing the pure version of the - system interface code which uses Open() Close() Read() Seek() - ExamineFH() AsmAllocPooled() AsmFreePooled() etc. This version can - be used in both normal programs and in Amiga run-time shared system - librarys (can be linked with lib:libinit.o, no copying of DATA and - BSS hunks for each OpenLibrary() necessary). Source code is in - src/base/ftsystem.c. - -- ftdebug.o, an object module containing the standard version of the - debugging code which uses vprintf() and exit() (not pure). - Debugging can be turned on in FT:include/freetype/config/ftoption.h - and with FT_SetTraceLevel(). - -- ftdebugpure.o, an object module containing the pure version of the - debugging code which uses KVPrintf() from lib:debug.lib and no - exit(). For debugging of Amiga run-time shared system libraries. - Source code is in src/base/ftdebug.c. - -- NO ftinit.o. Because linking with a link library should result in - linking only the needed object modules in it, but standard - ftsystem.o would force ALL FreeType2 modules to be linked to your - program, I decided to use a different scheme: You must #include - FT:src/base/ftinit.c in your sourcecode and specify with #define - statements which modules you need. See - include/freetype/config/ftmodule.h. - - -To use in your own programs: - -- Insert the #define and #include statements from top of - include/freetype/config/ftmodule.h in your source code and - uncomment the #define statements for the FreeType2 modules you need. - -- You can use either PARAMETERS=REGISTER or PARAMETERS=STACK for - calling the FreeType2 functions, because the link library and the - object files are compiled with PARAMETERS=BOTH. - -- "smake assign" (assign "FT:" to the FreeType2 main directory). - -- Compile your program. - -- Link with either ftsystem.o or ftsystempure.o, if debugging enabled - with either ftdebug.o or (ftdebugpure.o and lib:debug.lib), and with - ft2_680x0.lib as link library. - - -To adapt to other compilers: - -- The standard ANSI C maximum length of 31 significant characters in - identifiers is not enough for FreeType2. Check if your compiler has - a minimum length of 40 significant characters or can be switched to - it. "idlen=40" is the option for SAS/C. Setting #define - HAVE_LIMIT_ON_IDENTS in an include file may also work (not tested). - -- Make sure that the include directory in builds/amiga is searched - before the normal FreeType2 include directory, so you are able to - replace problematic include files with your own version (same may be - useful for the src directory). - -- An example of how to replace/workaround a problematic include file - is include/freetype/config/ftconfig.h; it changes a #define that - would prevent SAS/C from generating XDEF's where it should do that and - then includes the standard FreeType2 include file. - -Local Variables: -coding: latin-1 -End: diff --git a/freetype/builds/amiga/include/config/ftconfig.h b/freetype/builds/amiga/include/config/ftconfig.h deleted file mode 100644 index de074bf..0000000 --- a/freetype/builds/amiga/include/config/ftconfig.h +++ /dev/null @@ -1,55 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftconfig.h */ -/* */ -/* Amiga-specific configuration file (specification only). */ -/* */ -/* Copyright (C) 2005-2023 by */ -/* Werner Lemberg and Detlef Würkner. */ -/* */ -/* This file is part of the FreeType project, and may only be used, */ -/* modified, and distributed under the terms of the FreeType project */ -/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ -/* this file you indicate that you have read the license and */ -/* understand and accept it fully. */ -/* */ -/***************************************************************************/ - -/* - * This is an example how to override the default FreeType2 header files - * with Amiga-specific changes. When the compiler searches this directory - * before the default directory, we can do some modifications. - * - * Here we must change FT_EXPORT_DEF so that SAS/C does - * generate the needed XDEFs. - */ - -#if 0 -#define FT_EXPORT_DEF( x ) extern x -#endif - -#undef FT_EXPORT_DEF -#define FT_EXPORT_DEF( x ) x - -/* Now include the original file */ -#ifndef __MORPHOS__ -#ifdef __SASC -#include "FT:include/freetype/config/ftconfig.h" -#else -#include "/FT/include/freetype/config/ftconfig.h" -#endif -#else -/* We must define that, it seems that - * lib/gcc-lib/ppc-morphos/2.95.3/include/syslimits.h is missing in - * ppc-morphos-gcc-2.95.3-bin.tgz (gcc for 68k producing MorphOS PPC elf - * binaries from http://www.morphos.de) - */ -#define _LIBC_LIMITS_H_ -#include "/FT/include/freetype/config/ftconfig.h" -#endif - -/* -Local Variables: -coding: latin-1 -End: -*/ diff --git a/freetype/builds/amiga/include/config/ftmodule.h b/freetype/builds/amiga/include/config/ftmodule.h deleted file mode 100644 index bf33367..0000000 --- a/freetype/builds/amiga/include/config/ftmodule.h +++ /dev/null @@ -1,158 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftmodule.h */ -/* */ -/* Amiga-specific FreeType module selection. */ -/* */ -/* Copyright (C) 2005-2023 by */ -/* Werner Lemberg and Detlef Würkner. */ -/* */ -/* This file is part of the FreeType project, and may only be used, */ -/* modified, and distributed under the terms of the FreeType project */ -/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ -/* this file you indicate that you have read the license and */ -/* understand and accept it fully. */ -/* */ -/***************************************************************************/ - -/* - * To avoid that all your programs include all FreeType modules, - * you copy the following piece of source code into your own - * source file and specify which modules you really need in your - * application by uncommenting the appropriate lines. - */ -/* -//#define FT_USE_AUTOFIT // autofitter -//#define FT_USE_RASTER // monochrome rasterizer -//#define FT_USE_SMOOTH // anti-aliasing rasterizer -//#define FT_USE_TT // truetype font driver -//#define FT_USE_T1 // type1 font driver -//#define FT_USE_T42 // type42 font driver -//#define FT_USE_T1CID // cid-keyed type1 font driver // no cmap support -//#define FT_USE_CFF // opentype font driver -//#define FT_USE_BDF // bdf bitmap font driver -//#define FT_USE_PCF // pcf bitmap font driver -//#define FT_USE_PFR // pfr font driver -//#define FT_USE_WINFNT // windows .fnt|.fon bitmap font driver -//#define FT_USE_OTV // opentype validator -//#define FT_USE_GXV // truetype gx validator -#include "FT:src/base/ftinit.c" -*/ - -/* Make sure that the needed support modules are built in. - * Dependencies can be found by searching for FT_Get_Module. - */ - -#ifdef FT_USE_T42 -#define FT_USE_TT -#endif - -#ifdef FT_USE_TT -#define FT_USE_SFNT -#endif - -#ifdef FT_USE_CFF -#define FT_USE_SFNT -#define FT_USE_PSHINT -#define FT_USE_PSNAMES -#endif - -#ifdef FT_USE_T1 -#define FT_USE_PSAUX -#define FT_USE_PSHINT -#define FT_USE_PSNAMES -#endif - -#ifdef FT_USE_T1CID -#define FT_USE_PSAUX -#define FT_USE_PSHINT -#define FT_USE_PSNAMES -#endif - -#ifdef FT_USE_PSAUX -#define FT_USE_PSNAMES -#endif - -#ifdef FT_USE_SFNT -#define FT_USE_PSNAMES -#endif - -/* Now include the modules */ - -#ifdef FT_USE_AUTOFIT -FT_USE_MODULE( FT_Module_Class, autofit_module_class ) -#endif - -#ifdef FT_USE_TT -FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class ) -#endif - -#ifdef FT_USE_T1 -FT_USE_MODULE( FT_Driver_ClassRec, t1_driver_class ) -#endif - -#ifdef FT_USE_CFF -FT_USE_MODULE( FT_Driver_ClassRec, cff_driver_class ) -#endif - -#ifdef FT_USE_T1CID -FT_USE_MODULE( FT_Driver_ClassRec, t1cid_driver_class ) -#endif - -#ifdef FT_USE_PFR -FT_USE_MODULE( FT_Driver_ClassRec, pfr_driver_class ) -#endif - -#ifdef FT_USE_T42 -FT_USE_MODULE( FT_Driver_ClassRec, t42_driver_class ) -#endif - -#ifdef FT_USE_WINFNT -FT_USE_MODULE( FT_Driver_ClassRec, winfnt_driver_class ) -#endif - -#ifdef FT_USE_PCF -FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class ) -#endif - -#ifdef FT_USE_PSAUX -FT_USE_MODULE( FT_Module_Class, psaux_module_class ) -#endif - -#ifdef FT_USE_PSNAMES -FT_USE_MODULE( FT_Module_Class, psnames_module_class ) -#endif - -#ifdef FT_USE_PSHINT -FT_USE_MODULE( FT_Module_Class, pshinter_module_class ) -#endif - -#ifdef FT_USE_RASTER -FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) -#endif - -#ifdef FT_USE_SFNT -FT_USE_MODULE( FT_Module_Class, sfnt_module_class ) -#endif - -#ifdef FT_USE_SMOOTH -FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class ) -#endif - -#ifdef FT_USE_OTV -FT_USE_MODULE( FT_Module_Class, otv_module_class ) -#endif - -#ifdef FT_USE_BDF -FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class ) -#endif - -#ifdef FT_USE_GXV -FT_USE_MODULE( FT_Module_Class, gxv_module_class ) -#endif - -/* -Local Variables: -coding: latin-1 -End: -*/ diff --git a/freetype/builds/amiga/makefile.os4 b/freetype/builds/amiga/makefile.os4 deleted file mode 100644 index dfc3e9f..0000000 --- a/freetype/builds/amiga/makefile.os4 +++ /dev/null @@ -1,297 +0,0 @@ -# -# Makefile for FreeType2 link library using gcc 4.0.3 from the -# AmigaOS4 SDK -# - - -# Copyright (C) 2005-2023 by -# Werner Lemberg and Detlef Würkner. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# to build from the builds/amiga directory call -# -# make -f makefile.os4 -# -# Your programs source code should start with this -# (uncomment the parts you do not need to keep the program small): -# ---8<--- -#define FT_USE_AUTOFIT // autofitter -#define FT_USE_RASTER // monochrome rasterizer -#define FT_USE_SMOOTH // anti-aliasing rasterizer -#define FT_USE_TT // truetype font driver -#define FT_USE_T1 // type1 font driver -#define FT_USE_T42 // type42 font driver -#define FT_USE_T1CID // cid-keyed type1 font driver -#define FT_USE_CFF // opentype font driver -#define FT_USE_BDF // bdf bitmap font driver -#define FT_USE_PCF // pcf bitmap font driver -#define FT_USE_PFR // pfr font driver -#define FT_USE_WINFNT // windows .fnt|.fon bitmap font driver -#define FT_USE_OTV // opentype validator -#define FT_USE_GXV // truetype gx validator -#include "FT:src/base/ftinit.c" -# ---8<--- -# -# link your programs with libft2_ppc.a and either ftsystem.ppc.o or ftsystempure.ppc.o -# (and either ftdebug.ppc.o or ftdebugpure.ppc.o if you enabled FT_DEBUG_LEVEL_ERROR or -# FT_DEBUG_LEVEL_TRACE in include/freetype/config/ftoption.h). - -all: assign libft2_ppc.a ftsystem.ppc.o ftsystempure.ppc.o - -assign: - assign FT: // - -CC = ppc-amigaos-gcc -AR = ppc-amigaos-ar -RANLIB = ppc-amigaos-ranlib - -DIRFLAGS = -Iinclude -I/FT/src -I/FT/include -I/SDK/include - -WARNINGS = -Wall -W -Wundef -Wpointer-arith -Wbad-function-cast \ - -Waggregate-return -Wwrite-strings -Wshadow - -OPTIONS = -DFT2_BUILD_LIBRARY -DNDEBUG -fno-builtin -OPTIMIZE = -O2 -fomit-frame-pointer -fstrength-reduce -finline-functions - -CFLAGS = -mcrt=clib2 $(DIRFLAGS) $(WARNINGS) $(FT2FLAGS) $(OPTIONS) $(OPTIMIZE) - -# -# FreeType2 library base -# -ftbase.ppc.o: FT:src/base/ftbase.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftbase.c - -ftinit.ppc.o: FT:src/base/ftinit.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftinit.c - -ftsystem.ppc.o: FT:src/base/ftsystem.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftsystem.c - -# pure version for use in run-time library etc -ftsystempure.ppc.o: src/base/ftsystem.c - $(CC) -c $(CFLAGS) -o $@ src/base/ftsystem.c - -# -# FreeType2 library base extensions -# -ftbbox.ppc.o: FT:src/base/ftbbox.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftbbox.c - -ftbdf.ppc.o: FT:src/base/ftbdf.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftbdf.c - -ftbitmap.ppc.o: FT:src/base/ftbitmap.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftbitmap.c - -ftcid.ppc.o: FT:src/base/ftcid.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftcid.c - -ftdebug.ppc.o: FT:src/base/ftdebug.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftdebug.c - -# pure version for use in run-time library etc -ftdebugpure.ppc.o: src/base/ftdebug.c - $(CC) -c $(CFLAGS) -o $@ src/base/ftdebug.c - -ftfstype.ppc.o: FT:src/base/ftfstype.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftfstype.c - -ftgasp.ppc.o: FT:src/base/ftgasp.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftgasp.c - -ftglyph.ppc.o: FT:src/base/ftglyph.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftglyph.c - -ftgxval.ppc.o: FT:src/base/ftgxval.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftgxval.c - -ftmm.ppc.o: FT:src/base/ftmm.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftmm.c - -ftotval.ppc.o: FT:src/base/ftotval.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftotval.c - -ftpatent.ppc.o: FT:src/base/ftpatent.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftpatent.c - -ftpfr.ppc.o: FT:src/base/ftpfr.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftpfr.c - -ftstroke.ppc.o: FT:src/base/ftstroke.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftstroke.c - -ftsynth.ppc.o: FT:src/base/ftsynth.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftsynth.c - -fttype1.ppc.o: FT:src/base/fttype1.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/fttype1.c - -ftwinfnt.ppc.o: FT:src/base/ftwinfnt.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/base/ftwinfnt.c - -# -# FreeType2 library autofitting module -# -autofit.ppc.o: FT:src/autofit/autofit.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/autofit/autofit.c - -# -# FreeType2 library postscript hinting module -# -pshinter.ppc.o: FT:src/pshinter/pshinter.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/pshinter/pshinter.c - -# -# FreeType2 library PS support module -# -psaux.ppc.o: FT:src/psaux/psaux.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/psaux/psaux.c - -# -# FreeType2 library PS glyph names module -# -psnames.ppc.o: FT:src/psnames/psnames.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/psnames/psnames.c - -# -# FreeType2 library monochrome raster module -# -raster.ppc.o: FT:src/raster/raster.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/raster/raster.c - -# -# FreeType2 library anti-aliasing raster module -# -smooth.ppc.o: FT:src/smooth/smooth.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/smooth/smooth.c - -# -# FreeType2 library 'sfnt' module -# -sfnt.ppc.o: FT:src/sfnt/sfnt.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/sfnt/sfnt.c - -# -# FreeType2 library glyph and image caching system -# -ftcache.ppc.o: FT:src/cache/ftcache.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/cache/ftcache.c - -# -# FreeType2 library OpenType font driver -# -cff.ppc.o: FT:src/cff/cff.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/cff/cff.c - -# -# FreeType2 library TrueType font driver -# -truetype.ppc.o: FT:src/truetype/truetype.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/truetype/truetype.c - -# -# FreeType2 library Type1 font driver -# -type1.ppc.o: FT:src/type1/type1.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/type1/type1.c - -# -# FreeType2 library Type42 font driver -# -type42.ppc.o: FT:src/type42/type42.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/type42/type42.c - -# -# FreeType2 library CID-keyed Type1 font driver -# -type1cid.ppc.o: FT:src/cid/type1cid.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/cid/type1cid.c - -# -# FreeType2 library BDF bitmap font driver -# -bdf.ppc.o: FT:src/bdf/bdf.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/bdf/bdf.c - -# -# FreeType2 library PCF bitmap font driver -# -pcf.ppc.o: FT:src/pcf/pcf.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/pcf/pcf.c - -# -# FreeType2 library gzip support for compressed PCF bitmap fonts -# -gzip.ppc.o: FT:src/gzip/ftgzip.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/gzip/ftgzip.c - -# -# FreeType2 library bzip2 support for compressed PCF bitmap fonts -# -bzip2.ppc.o: FT:src/bzip2/ftbzip2.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/bzip2/ftbzip2.c - -# -# FreeType2 library compress support for compressed PCF bitmap fonts -# -lzw.ppc.o: FT:src/lzw/ftlzw.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/lzw/ftlzw.c - -# -# FreeType2 library PFR font driver -# -pfr.ppc.o: FT:src/pfr/pfr.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/pfr/pfr.c - -# -# FreeType2 library Windows FNT/FON bitmap font driver -# -winfnt.ppc.o: FT:src/winfonts/winfnt.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/winfonts/winfnt.c - -# -# FreeType2 library TrueTypeGX Validator -# -gxvalid.ppc.o: FT:src/gxvalid/gxvalid.c - $(CC) -c $(CFLAGS) -Wno-aggregate-return -o $@ /FT/src/gxvalid/gxvalid.c - -# -# FreeType2 library OpenType validator -# -otvalid.ppc.o: FT:src/otvalid/otvalid.c - $(CC) -c $(CFLAGS) -o $@ /FT/src/otvalid/otvalid.c - -BASE = ftbase.ppc.o ftbbox.ppc.o ftbdf.ppc.o ftbitmap.ppc.o ftcid.ppc.o \ - ftfstype.ppc.o ftgasp.ppc.o ftglyph.ppc.o \ - ftgxval.ppc.o ftmm.ppc.o ftotval.ppc.o \ - ftpatent.ppc.o ftpfr.ppc.o ftstroke.ppc.o ftsynth.ppc.o \ - fttype1.ppc.o ftwinfnt.ppc.o - -DEBUG = ftdebug.ppc.o ftdebugpure.ppc.o - -AFIT = autofit.ppc.o - -GXV = gxvalid.ppc.o - -OTV = otvalid.ppc.o - -PS = psaux.ppc.o psnames.ppc.o pshinter.ppc.o - -RASTER = raster.ppc.o smooth.ppc.o - -FONTD = cff.ppc.o type1.ppc.o type42.ppc.o type1cid.ppc.o truetype.ppc.o\ - bdf.ppc.o pcf.ppc.o pfr.ppc.o winfnt.ppc.o - -libft2_ppc.a: $(BASE) $(AFIT) $(GXV) $(OTV) $(PS) $(RASTER) sfnt.ppc.o ftcache.ppc.o $(FONTD) gzip.ppc.o lzw.ppc.o - $(AR) r $@ $(BASE) $(AFIT) $(GXV) $(OTV) $(PS) $(RASTER) sfnt.ppc.o ftcache.ppc.o $(FONTD) gzip.ppc.o lzw.ppc.o - $(RANLIB) $@ - -#Local Variables: -#coding: latin-1 -#End: diff --git a/freetype/builds/amiga/smakefile b/freetype/builds/amiga/smakefile deleted file mode 100644 index ca3da66..0000000 --- a/freetype/builds/amiga/smakefile +++ /dev/null @@ -1,299 +0,0 @@ -# -# Makefile for FreeType2 link library using Amiga SAS/C 6.58 -# - - -# Copyright (C) 2005-2023 by -# Werner Lemberg and Detlef Würkner. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# to build from the builds/amiga directory call -# -# smake assign -# smake -# -# Your programs source code should start with this -# (uncomment the parts you do not need to keep the program small): -# ---8<--- -#define FT_USE_AUTOFIT // autofitter -#define FT_USE_RASTER // monochrome rasterizer -#define FT_USE_SMOOTH // anti-aliasing rasterizer -#define FT_USE_TT // truetype font driver -#define FT_USE_T1 // type1 font driver -#define FT_USE_T42 // type42 font driver -#define FT_USE_T1CID // cid-keyed type1 font driver -#define FT_USE_CFF // opentype font driver -#define FT_USE_BDF // bdf bitmap font driver -#define FT_USE_PCF // pcf bitmap font driver -#define FT_USE_PFR // pfr font driver -#define FT_USE_WINFNT // windows .fnt|.fon bitmap font driver -#define FT_USE_OTV // opentype validator -#define FT_USE_GXV // truetype gx validator -#include "FT:src/base/ftinit.c" -# ---8<--- -# -# link your programs with ft2_680x0.lib and either ftsystem.o or ftsystempure.o -# (and either ftdebug.o or ftdebugpure.o if you enabled FT_DEBUG_LEVEL_ERROR or -# FT_DEBUG_LEVEL_TRACE in include/freetype/config/ftoption.h). - -OBJBASE = ftbase.o ftbbox.o ftbdf.o ftbitmap.o ftcid.o ftfstype.o \ - ftgasp.o ftglyph.o ftgxval.o ftmm.o ftotval.o \ - ftpatent.o ftpfr.o ftstroke.o ftsynth.o fttype1.o ftwinfnt.o - -OBJSYSTEM = ftsystem.o ftsystempure.o - -OBJDEBUG = ftdebug.o ftdebugpure.o - -OBJAFIT = autofit.o - -OBJGXV = gxvalid.o - -OBJOTV = otvalid.o - -OBJPS = psaux.o psnames.o pshinter.o - -OBJRASTER = raster.o smooth.o - -OBJSFNT = sfnt.o - -OBJCACHE = ftcache.o - -OBJFONTD = cff.o type1.o type42.o type1cid.o\ - truetype.o winfnt.o bdf.o pcf.o pfr.o - -CORE = FT:src/ - -CPU = 68000 -#CPU = 68020 -#CPU = 68030 -#CPU = 68040 -#CPU = 68060 - -OPTIMIZER = optinlocal - -SCFLAGS = optimize opttime optsched strmerge data=faronly idlen=50 cpu=$(CPU)\ - idir=include/ idir=$(CORE) idir=FT:include/ nostackcheck nochkabort\ - noicons ignore=79,85,110,306 parameters=both define=FT2_BUILD_LIBRARY - -LIB = ft2_$(CPU).lib - -# sample linker options -OPTS = link lib=$(LIB),lib:sc.lib,lib:amiga.lib,lib:debug.lib\ - smallcode smalldata noicons utillib - -# sample program entry -#myprog: myprog.c ftsystem.o $(LIB) -# sc $< programname=$@ ftsystem.o $(SCFLAGS) $(OPTS) - -all: $(LIB) $(OBJSYSTEM) $(OBJDEBUG) - -assign: - assign FT: // - -# uses separate object modules in lib to make for easier debugging -# also, can make smaller programs if entire engine is not used -ft2_$(CPU).lib: $(OBJBASE) $(OBJAFIT) $(OBJOTV) $(OBJPS) $(OBJRASTER) $(OBJSFNT) $(OBJCACHE) $(OBJFONTD) lzw.o gzip.o bzip2.o - oml $@ r $(OBJBASE) $(OBJAFIT) $(OBJOTV) $(OBJPS) $(OBJRASTER) $(OBJSFNT) $(OBJCACHE) $(OBJFONTD) lzw.o gzip.o bzip2.o - -clean: - -delete \#?.o - -realclean: clean - -delete ft2$(CPU).lib - -# -# freetype library base -# -ftbase.o: $(CORE)base/ftbase.c - sc $(SCFLAGS) objname=$@ $< -ftinit.o: $(CORE)base/ftinit.c - sc $(SCFLAGS) objname=$@ $< -ftsystem.o: $(CORE)base/ftsystem.c - sc $(SCFLAGS) objname=$@ $< -ftsystempure.o: src/base/ftsystem.c ## pure version for use in run-time library etc - sc $(SCFLAGS) objname=$@ $< -ftdebug.o: $(CORE)base/ftdebug.c - sc $(SCFLAGS) objname=$@ $< -ftdebugpure.o: src/base/ftdebug.c ## pure version for use in run-time library etc - sc $(SCFLAGS) objname=$@ $< -# -# freetype library base extensions -# -ftbbox.o: $(CORE)base/ftbbox.c - sc $(SCFLAGS) objname=$@ $< -ftbdf.o: $(CORE)base/ftbdf.c - sc $(SCFLAGS) objname=$@ $< -ftbitmap.o: $(CORE)base/ftbitmap.c - sc $(SCFLAGS) objname=$@ $< -ftcid.o: $(CORE)base/ftcid.c - sc $(SCFLAGS) objname=$@ $< -ftfstype.o: $(CORE)base/ftfstype.c - sc $(SCFLAGS) objname=$@ $< -ftgasp.o: $(CORE)base/ftgasp.c - sc $(SCFLAGS) objname=$@ $< -ftglyph.o: $(CORE)base/ftglyph.c - sc $(SCFLAGS) objname=$@ $< -ftgxval.o: $(CORE)base/ftgxval.c - sc $(SCFLAGS) objname=$@ $< -ftmm.o: $(CORE)base/ftmm.c - sc $(SCFLAGS) objname=$@ $< -ftotval.o: $(CORE)base/ftotval.c - sc $(SCFLAGS) objname=$@ $< -ftpatent.o: $(CORE)base/ftpatent.c - sc $(SCFLAGS) objname=$@ $< -ftpfr.o: $(CORE)base/ftpfr.c - sc $(SCFLAGS) objname=$@ $< -ftstroke.o: $(CORE)base/ftstroke.c - sc $(SCFLAGS) objname=$@ $< -ftsynth.o: $(CORE)base/ftsynth.c - sc $(SCFLAGS) objname=$@ $< -fttype1.o: $(CORE)base/fttype1.c - sc $(SCFLAGS) objname=$@ $< -ftwinfnt.o: $(CORE)base/ftwinfnt.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library autofitter module -# -autofit.o: $(CORE)autofit/autofit.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library PS hinting module -# -pshinter.o: $(CORE)pshinter/pshinter.c - sc $(SCFLAGS) objname=$@ $< -# -# freetype library PS support module -# -psaux.o: $(CORE)psaux/psaux.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library PS glyph names module -# -psnames.o: $(CORE)psnames/psnames.c - sc $(SCFLAGS) code=far objname=$@ $< - -# -# freetype library monochrome raster module -# -raster.o: $(CORE)raster/raster.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library anti-aliasing raster module -# -smooth.o: $(CORE)smooth/smooth.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library 'sfnt' module -# -sfnt.o: $(CORE)sfnt/sfnt.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library glyph and image caching system (still experimental) -# -ftcache.o: $(CORE)cache/ftcache.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library OpenType font driver -# -cff.o: $(CORE)cff/cff.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library TrueType font driver -# -truetype.o: $(CORE)truetype/truetype.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library Type1 font driver -# -type1.o: $(CORE)type1/type1.c - sc $(SCFLAGS) objname=$@ $< - -# -# FreeType2 library Type42 font driver -# -type42.o: $(CORE)type42/type42.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library CID-keyed Type1 font driver -# -type1cid.o: $(CORE)cid/type1cid.c - sc $(SCFLAGS) objname=$@ $< -# -# freetype library CID-keyed Type1 font driver extensions -# -#cidafm.o: $(CORE)cid/cidafm.c -# sc $(SCFLAGS) objname=$@ $< - -# -# freetype library BDF bitmap font driver -# -bdf.o: $(CORE)bdf/bdf.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library PCF bitmap font driver -# -pcf.o: $(CORE)pcf/pcf.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library gzip support for compressed PCF bitmap fonts -# -gzip.o: $(CORE)gzip/ftgzip.c - sc $(SCFLAGS) define FAR objname=$@ $< - -# -# freetype library bzip2 support for compressed PCF bitmap fonts -# -bzip2.o: $(CORE)bzip2/ftbzip2.c - sc $(SCFLAGS) define FAR objname=$@ $< - -# -# freetype library compress support for compressed PCF bitmap fonts -# -lzw.o: $(CORE)lzw/ftlzw.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library PFR font driver -# -pfr.o: $(CORE)pfr/pfr.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library Windows FNT/FON bitmap font driver -# -winfnt.o: $(CORE)winfonts/winfnt.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library TrueTypeGX validator -# -gxvalid.o: $(CORE)gxvalid/gxvalid.c - sc $(SCFLAGS) objname=$@ $< - -# -# freetype library OpenType validator -# -otvalid.o: $(CORE)otvalid/otvalid.c - sc $(SCFLAGS) objname=$@ $< - -#Local Variables: -#coding: latin-1 -#End: diff --git a/freetype/builds/amiga/src/base/ftdebug.c b/freetype/builds/amiga/src/base/ftdebug.c deleted file mode 100644 index a209297..0000000 --- a/freetype/builds/amiga/src/base/ftdebug.c +++ /dev/null @@ -1,348 +0,0 @@ -/**************************************************************************** - * - * ftdebug.c - * - * Debugging and logging component for amiga (body). - * - * Copyright (C) 1996-2023 by - * David Turner, Robert Wilhelm, Werner Lemberg, and Detlef Wuerkner. - * - * This file is part of the FreeType project, and may only be used, - * modified, and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify, or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - */ - - - /************************************************************************** - * - * This component contains various macros and functions used to ease the - * debugging of the FreeType engine. Its main purpose is in assertion - * checking, tracing, and error detection. - * - * There are now three debugging modes: - * - * - trace mode - * - * Error and trace messages are sent to the log file (which can be the - * standard error output). - * - * - error mode - * - * Only error messages are generated. - * - * - release mode: - * - * No error message is sent or generated. The code is free from any - * debugging parts. - * - */ - - - /* - * Based on the default `ftdebug.c' file, - * replaced `vprintf' with `KVPrintF', - * commented out `exit', - * replaced `getenv' with `GetVar'. - */ - -#include -#include -#include -#include - -#define __NOLIBBASE__ -#define __NOLOBALIFACE__ -#define __USE_INLINE__ - -#include -#include - -#ifndef __amigaos4__ - extern struct Library* DOSBase; -#else - extern struct DOSIFace* IDOS; -#endif - - -#include -#include -#include - - -#ifdef FT_DEBUG_LEVEL_ERROR - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Message( const char* fmt, - ... ) - { - va_list ap; - - - va_start( ap, fmt ); - KVPrintF( fmt, ap ); - va_end( ap ); - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Panic( const char* fmt, - ... ) - { - va_list ap; - - - va_start( ap, fmt ); - KVPrintF( fmt, ap ); - va_end( ap ); - - /* exit( EXIT_FAILURE ); */ - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( int ) - FT_Throw( FT_Error error, - int line, - const char* file ) - { -#if 0 - /* activating the code in this block makes FreeType very chatty */ - fprintf( stderr, - "%s:%d: error 0x%02x: %s\n", - file, - line, - error, - FT_Error_String( error ) ); -#else - FT_UNUSED( error ); - FT_UNUSED( line ); - FT_UNUSED( file ); -#endif - - return 0; - } - -#endif /* FT_DEBUG_LEVEL_ERROR */ - - - -#ifdef FT_DEBUG_LEVEL_TRACE - - /* array of trace levels, initialized to 0; */ - /* this gets adjusted at run-time */ - static int ft_trace_levels_enabled[trace_count]; - - /* array of trace levels, always initialized to 0 */ - static int ft_trace_levels_disabled[trace_count]; - - /* a pointer to either `ft_trace_levels_enabled' */ - /* or `ft_trace_levels_disabled' */ - int* ft_trace_levels; - - /* define array of trace toggle names */ -#define FT_TRACE_DEF( x ) #x , - - static const char* ft_trace_toggles[trace_count + 1] = - { -#include - NULL - }; - -#undef FT_TRACE_DEF - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( FT_Int ) - FT_Trace_Get_Count( void ) - { - return trace_count; - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( const char * ) - FT_Trace_Get_Name( FT_Int idx ) - { - int max = FT_Trace_Get_Count(); - - - if ( idx < max ) - return ft_trace_toggles[idx]; - else - return NULL; - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Trace_Disable( void ) - { - ft_trace_levels = ft_trace_levels_disabled; - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Trace_Enable( void ) - { - ft_trace_levels = ft_trace_levels_enabled; - } - - - /************************************************************************** - * - * Initialize the tracing sub-system. This is done by retrieving the - * value of the `FT2_DEBUG' environment variable. It must be a list of - * toggles, separated by spaces, `;', or `,'. Example: - * - * export FT2_DEBUG="any:3 memory:7 stream:5" - * - * This requests that all levels be set to 3, except the trace level for - * the memory and stream components which are set to 7 and 5, - * respectively. - * - * See the file `include/freetype/internal/fttrace.h' for details of - * the available toggle names. - * - * The level must be between 0 and 7; 0 means quiet (except for serious - * runtime errors), and 7 means _very_ verbose. - */ - FT_BASE_DEF( void ) - ft_debug_init( void ) - { - /* const char* ft2_debug = ft_getenv( "FT2_DEBUG" ); */ - char buf[256]; - const char* ft2_debug = &buf[0]; - - - /* if ( ft2_debug ) */ - if ( GetVar( "FT2_DEBUG", (STRPTR)ft2_debug, 256, LV_VAR ) > 0 ) - { - const char* p = ft2_debug; - const char* q; - - - for ( ; *p; p++ ) - { - /* skip leading whitespace and separators */ - if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' ) - continue; - - /* read toggle name, followed by ':' */ - q = p; - while ( *p && *p != ':' ) - p++; - - if ( !*p ) - break; - - if ( *p == ':' && p > q ) - { - FT_Int n, i, len = (FT_Int)( p - q ); - FT_Int level = -1, found = -1; - - - for ( n = 0; n < trace_count; n++ ) - { - const char* toggle = ft_trace_toggles[n]; - - - for ( i = 0; i < len; i++ ) - { - if ( toggle[i] != q[i] ) - break; - } - - if ( i == len && toggle[i] == 0 ) - { - found = n; - break; - } - } - - /* read level */ - p++; - if ( *p ) - { - level = *p - '0'; - if ( level < 0 || level > 7 ) - level = -1; - } - - if ( found >= 0 && level >= 0 ) - { - if ( found == trace_any ) - { - /* special case for `any' */ - for ( n = 0; n < trace_count; n++ ) - ft_trace_levels_enabled[n] = level; - } - else - ft_trace_levels_enabled[found] = level; - } - } - } - } - - ft_trace_levels = ft_trace_levels_enabled; - } - - -#else /* !FT_DEBUG_LEVEL_TRACE */ - - - FT_BASE_DEF( void ) - ft_debug_init( void ) - { - /* nothing */ - } - - - FT_BASE_DEF( FT_Int ) - FT_Trace_Get_Count( void ) - { - return 0; - } - - - FT_BASE_DEF( const char * ) - FT_Trace_Get_Name( FT_Int idx ) - { - FT_UNUSED( idx ); - - return NULL; - } - - - FT_BASE_DEF( void ) - FT_Trace_Disable( void ) - { - /* nothing */ - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Trace_Enable( void ) - { - /* nothing */ - } - - -#endif /* !FT_DEBUG_LEVEL_TRACE */ - - -/* END */ diff --git a/freetype/builds/amiga/src/base/ftsystem.c b/freetype/builds/amiga/src/base/ftsystem.c deleted file mode 100644 index d85845c..0000000 --- a/freetype/builds/amiga/src/base/ftsystem.c +++ /dev/null @@ -1,530 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftsystem.c */ -/* */ -/* Amiga-specific FreeType low-level system interface (body). */ -/* */ -/* Copyright (C) 1996-2023 by */ -/* David Turner, Robert Wilhelm, Werner Lemberg and Detlef Würkner. */ -/* */ -/* This file is part of the FreeType project, and may only be used, */ -/* modified, and distributed under the terms of the FreeType project */ -/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ -/* this file you indicate that you have read the license and */ -/* understand and accept it fully. */ -/* */ -/***************************************************************************/ - - /*************************************************************************/ - /* */ - /* This file contains the Amiga interface used by FreeType to access */ - /* low-level, i.e. memory management, i/o access as well as thread */ - /* synchronisation. */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* Maintained by Detlef Würkner */ - /* */ - /* Based on the original ftsystem.c, */ - /* modified to avoid fopen(), fclose(), fread(), fseek(), ftell(), */ - /* malloc(), realloc(), and free(). */ - /* */ - /* Those C library functions are often not thread-safe or cant be */ - /* used in a shared Amiga library. If that's not a problem for you, */ - /* you can of course use the default ftsystem.c with C library calls */ - /* instead. */ - /* */ - /* This implementation needs exec V39+ because it uses AllocPooled() etc */ - /* */ - /*************************************************************************/ - -#define __NOLIBBASE__ -#define __NOGLOBALIFACE__ -#define __USE_INLINE__ -#include -#include -#include -#ifdef __amigaos4__ -extern struct ExecIFace *IExec; -extern struct DOSIFace *IDOS; -#else -extern struct Library *SysBase; -extern struct Library *DOSBase; -#endif - -#define IOBUF_SIZE 512 - -/* structure that helps us to avoid - * useless calls of Seek() and Read() - */ -struct SysFile -{ - BPTR file; - ULONG iobuf_start; - ULONG iobuf_end; - UBYTE iobuf[IOBUF_SIZE]; -}; - -#ifndef __amigaos4__ -/* C implementation of AllocVecPooled (see autodoc exec/AllocPooled) */ -APTR -Alloc_VecPooled( APTR poolHeader, - ULONG memSize ) -{ - ULONG newSize = memSize + sizeof ( ULONG ); - ULONG *mem = AllocPooled( poolHeader, newSize ); - - if ( !mem ) - return NULL; - *mem = newSize; - return mem + 1; -} - -/* C implementation of FreeVecPooled (see autodoc exec/AllocPooled) */ -void -Free_VecPooled( APTR poolHeader, - APTR memory ) -{ - ULONG *realmem = (ULONG *)memory - 1; - - FreePooled( poolHeader, realmem, *realmem ); -} -#endif - -#include -#include FT_CONFIG_CONFIG_H -#include -#include -#include -#include - -#include -#include -#include - - - /*************************************************************************/ - /* */ - /* MEMORY MANAGEMENT INTERFACE */ - /* */ - /*************************************************************************/ - - /*************************************************************************/ - /* */ - /* It is not necessary to do any error checking for the */ - /* allocation-related functions. This is done by the higher level */ - /* routines like ft_mem_alloc() or ft_mem_realloc(). */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* */ - /* ft_alloc */ - /* */ - /* */ - /* The memory allocation function. */ - /* */ - /* */ - /* memory :: A pointer to the memory object. */ - /* */ - /* size :: The requested size in bytes. */ - /* */ - /* */ - /* The address of newly allocated block. */ - /* */ - FT_CALLBACK_DEF( void* ) - ft_alloc( FT_Memory memory, - long size ) - { -#ifdef __amigaos4__ - return AllocVecPooled( memory->user, size ); -#else - return Alloc_VecPooled( memory->user, size ); -#endif - } - - - /*************************************************************************/ - /* */ - /* */ - /* ft_realloc */ - /* */ - /* */ - /* The memory reallocation function. */ - /* */ - /* */ - /* memory :: A pointer to the memory object. */ - /* */ - /* cur_size :: The current size of the allocated memory block. */ - /* */ - /* new_size :: The newly requested size in bytes. */ - /* */ - /* block :: The current address of the block in memory. */ - /* */ - /* */ - /* The address of the reallocated memory block. */ - /* */ - FT_CALLBACK_DEF( void* ) - ft_realloc( FT_Memory memory, - long cur_size, - long new_size, - void* block ) - { - void* new_block; - -#ifdef __amigaos4__ - new_block = AllocVecPooled ( memory->user, new_size ); -#else - new_block = Alloc_VecPooled ( memory->user, new_size ); -#endif - if ( new_block != NULL ) - { - CopyMem ( block, new_block, - ( new_size > cur_size ) ? cur_size : new_size ); -#ifdef __amigaos4__ - FreeVecPooled ( memory->user, block ); -#else - Free_VecPooled ( memory->user, block ); -#endif - } - return new_block; - } - - - /*************************************************************************/ - /* */ - /* */ - /* ft_free */ - /* */ - /* */ - /* The memory release function. */ - /* */ - /* */ - /* memory :: A pointer to the memory object. */ - /* */ - /* block :: The address of block in memory to be freed. */ - /* */ - FT_CALLBACK_DEF( void ) - ft_free( FT_Memory memory, - void* block ) - { -#ifdef __amigaos4__ - FreeVecPooled( memory->user, block ); -#else - Free_VecPooled( memory->user, block ); -#endif - } - - - /*************************************************************************/ - /* */ - /* RESOURCE MANAGEMENT INTERFACE */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT io - - /* We use the macro STREAM_FILE for convenience to extract the */ - /* system-specific stream handle from a given FreeType stream object */ -#define STREAM_FILE( stream ) ( (struct SysFile *)stream->descriptor.pointer ) - - - /*************************************************************************/ - /* */ - /* */ - /* ft_amiga_stream_close */ - /* */ - /* */ - /* The function to close a stream. */ - /* */ - /* */ - /* stream :: A pointer to the stream object. */ - /* */ - FT_CALLBACK_DEF( void ) - ft_amiga_stream_close( FT_Stream stream ) - { - struct SysFile* sysfile; - - sysfile = STREAM_FILE( stream ); - Close ( sysfile->file ); - FreeMem ( sysfile, sizeof ( struct SysFile )); - - stream->descriptor.pointer = NULL; - stream->size = 0; - stream->base = NULL; - } - - - /*************************************************************************/ - /* */ - /* */ - /* ft_amiga_stream_io */ - /* */ - /* */ - /* The function to open a stream. */ - /* */ - /* */ - /* stream :: A pointer to the stream object. */ - /* */ - /* offset :: The position in the data stream to start reading. */ - /* */ - /* buffer :: The address of buffer to store the read data. */ - /* */ - /* count :: The number of bytes to read from the stream. */ - /* */ - /* */ - /* The number of bytes actually read. */ - /* */ - FT_CALLBACK_DEF( unsigned long ) - ft_amiga_stream_io( FT_Stream stream, - unsigned long offset, - unsigned char* buffer, - unsigned long count ) - { - struct SysFile* sysfile; - unsigned long read_bytes; - - if ( count != 0 ) - { - sysfile = STREAM_FILE( stream ); - - /* handle the seek */ - if ( (offset < sysfile->iobuf_start) || (offset + count > sysfile->iobuf_end) ) - { - /* requested offset implies we need a buffer refill */ - if ( !sysfile->iobuf_end || offset != sysfile->iobuf_end ) - { - /* a physical seek is necessary */ - Seek( sysfile->file, offset, OFFSET_BEGINNING ); - } - sysfile->iobuf_start = offset; - sysfile->iobuf_end = 0; /* trigger a buffer refill */ - } - - /* handle the read */ - if ( offset + count <= sysfile->iobuf_end ) - { - /* we have buffer and requested bytes are all inside our buffer */ - CopyMem( &sysfile->iobuf[offset - sysfile->iobuf_start], buffer, count ); - read_bytes = count; - } - else - { - /* (re)fill buffer */ - if ( count <= IOBUF_SIZE ) - { - /* requested bytes is a subset of the buffer */ - read_bytes = Read( sysfile->file, sysfile->iobuf, IOBUF_SIZE ); - if ( read_bytes == -1UL ) - { - /* error */ - read_bytes = 0; - } - else - { - sysfile->iobuf_end = offset + read_bytes; - CopyMem( sysfile->iobuf, buffer, count ); - if ( read_bytes > count ) - { - read_bytes = count; - } - } - } - else - { - /* we actually need more than our buffer can hold, so we decide - ** to do a single big read, and then copy the last IOBUF_SIZE - ** bytes of that to our internal buffer for later use */ - read_bytes = Read( sysfile->file, buffer, count ); - if ( read_bytes == -1UL ) - { - /* error */ - read_bytes = 0; - } - else - { - ULONG bufsize; - - bufsize = ( read_bytes > IOBUF_SIZE ) ? IOBUF_SIZE : read_bytes; - sysfile->iobuf_end = offset + read_bytes; - sysfile->iobuf_start = sysfile->iobuf_end - bufsize; - CopyMem( &buffer[read_bytes - bufsize] , sysfile->iobuf, bufsize ); - } - } - } - } - else - { - read_bytes = 0; - } - - return read_bytes; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Error ) - FT_Stream_Open( FT_Stream stream, - const char* filepathname ) - { - struct FileInfoBlock* fib; - struct SysFile* sysfile; - - - if ( !stream ) - return FT_THROW( Invalid_Stream_Handle ); - -#ifdef __amigaos4__ - sysfile = AllocMem ( sizeof (struct SysFile ), MEMF_SHARED ); -#else - sysfile = AllocMem ( sizeof (struct SysFile ), MEMF_PUBLIC ); -#endif - if ( !sysfile ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not open `%s'\n", filepathname )); - - return FT_THROW( Cannot_Open_Resource ); - } - sysfile->file = Open( (STRPTR)filepathname, MODE_OLDFILE ); - if ( !sysfile->file ) - { - FreeMem ( sysfile, sizeof ( struct SysFile )); - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not open `%s'\n", filepathname )); - - return FT_THROW( Cannot_Open_Resource ); - } - - fib = AllocDosObject( DOS_FIB, NULL ); - if ( !fib ) - { - Close ( sysfile->file ); - FreeMem ( sysfile, sizeof ( struct SysFile )); - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not open `%s'\n", filepathname )); - - return FT_THROW( Cannot_Open_Resource ); - } - if ( !( ExamineFH( sysfile->file, fib ) ) ) - { - FreeDosObject( DOS_FIB, fib ); - Close ( sysfile->file ); - FreeMem ( sysfile, sizeof ( struct SysFile )); - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not open `%s'\n", filepathname )); - - return FT_THROW( Cannot_Open_Resource ); - } - stream->size = fib->fib_Size; - FreeDosObject( DOS_FIB, fib ); - - stream->descriptor.pointer = (void *)sysfile; - stream->pathname.pointer = (char*)filepathname; - sysfile->iobuf_start = 0; - sysfile->iobuf_end = 0; - stream->pos = 0; - - stream->read = ft_amiga_stream_io; - stream->close = ft_amiga_stream_close; - - if ( !stream->size ) - { - ft_amiga_stream_close( stream ); - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " opened `%s' but zero-sized\n", filepathname )); - return FT_THROW( Cannot_Open_Stream ); - } - - FT_TRACE1(( "FT_Stream_Open:" )); - FT_TRACE1(( " opened `%s' (%ld bytes) successfully\n", - filepathname, stream->size )); - - return FT_Err_Ok; - } - - -#ifdef FT_DEBUG_MEMORY - - extern FT_Int - ft_mem_debug_init( FT_Memory memory ); - - extern void - ft_mem_debug_done( FT_Memory memory ); - -#endif - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Memory ) - FT_New_Memory( void ) - { - FT_Memory memory; - - -#ifdef __amigaos4__ - memory = (FT_Memory)AllocVec( sizeof ( *memory ), MEMF_SHARED ); -#else - memory = (FT_Memory)AllocVec( sizeof ( *memory ), MEMF_PUBLIC ); -#endif - if ( memory ) - { -#ifdef __amigaos4__ - memory->user = CreatePool( MEMF_SHARED, 16384, 16384 ); -#else - memory->user = CreatePool( MEMF_PUBLIC, 16384, 16384 ); -#endif - if ( memory->user == NULL ) - { - FreeVec( memory ); - memory = NULL; - } - else - { - memory->alloc = ft_alloc; - memory->realloc = ft_realloc; - memory->free = ft_free; -#ifdef FT_DEBUG_MEMORY - ft_mem_debug_init( memory ); -#endif - } - } - - return memory; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( void ) - FT_Done_Memory( FT_Memory memory ) - { -#ifdef FT_DEBUG_MEMORY - ft_mem_debug_done( memory ); -#endif - - DeletePool( memory->user ); - FreeVec( memory ); - } - -/* -Local Variables: -coding: latin-1 -End: -*/ -/* END */ diff --git a/freetype/builds/ansi/ansi-def.mk b/freetype/builds/ansi/ansi-def.mk deleted file mode 100644 index 8217893..0000000 --- a/freetype/builds/ansi/ansi-def.mk +++ /dev/null @@ -1,77 +0,0 @@ -# -# FreeType 2 configuration rules for a `normal' ANSI system -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -DELETE := rm -f -CAT := cat -SEP := / -PLATFORM_DIR := $(TOP_DIR)/builds/ansi -PLATFORM := ansi - -# This is used for `make refdoc' and `make refdoc-venv' -# -BIN := bin - -# The directory where all library files are placed. -# -# By default, this is the same as $(OBJ_DIR); however, this can be changed -# to suit particular needs. -# -LIB_DIR := $(OBJ_DIR) - - -# The name of the final library file. Note that the DOS-specific Makefile -# uses a shorter (8.3) name. -# -LIBRARY := lib$(PROJECT) - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := -l - - -# Target flag. -# -T := -o$(space) - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= -c - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSIFLAGS ?= - - -# EOF diff --git a/freetype/builds/ansi/ansi.mk b/freetype/builds/ansi/ansi.mk deleted file mode 100644 index ad40939..0000000 --- a/freetype/builds/ansi/ansi.mk +++ /dev/null @@ -1,21 +0,0 @@ -# -# FreeType 2 configuration rules for a `normal' pseudo ANSI compiler/system -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -include $(TOP_DIR)/builds/ansi/ansi-def.mk -include $(TOP_DIR)/builds/compiler/ansi-cc.mk -include $(TOP_DIR)/builds/link_std.mk - - -# EOF diff --git a/freetype/builds/atari/ATARI.H b/freetype/builds/atari/ATARI.H deleted file mode 100644 index 4ddd2eb..0000000 --- a/freetype/builds/atari/ATARI.H +++ /dev/null @@ -1,20 +0,0 @@ -#if defined( GXVALID_H_ ) -#pragma warn -aus /* too many unevaluated variables in gxvalid */ -#endif - -#ifndef ATARI_H -#define ATARI_H - -#pragma warn -stu - -/* PureC doesn't like 32bit enumerations */ - -#ifndef FT_IMAGE_TAG -#define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value -#endif /* FT_IMAGE_TAG */ - -#ifndef FT_ENC_TAG -#define FT_ENC_TAG( value, a, b, c, d ) value -#endif /* FT_ENC_TAG */ - -#endif /* ATARI_H */ diff --git a/freetype/builds/atari/FNames.SIC b/freetype/builds/atari/FNames.SIC deleted file mode 100644 index f365717..0000000 --- a/freetype/builds/atari/FNames.SIC +++ /dev/null @@ -1,37 +0,0 @@ -/* the following changes file names for PureC projects */ - -if (argc > 0) -{ - ordner = argv[0]; - if (basename(ordner) == "") /* ist Ordner */ - { - ChangeFilenames(ordner); - } -} - -proc ChangeFilenames(folder) -local i,entries,directory,file; -{ - entries = filelist(directory,folder); - for (i = 0; i < entries; ++i) - { - file = directory[i,0]; - if ((directory[i,3]&16) > 0) /* subdirectory */ - { - ChangeFilenames(folder+file+"\\"); - } - else - { - if ((stricmp(suffix(file),".h")==0)|(stricmp(suffix(file),".c")==0)) - ChangeFilename(folder,file); - } - } -} - -proc ChangeFilename(path,datei) -local newfile,err; -{ - newfile=datei; - newfile[0]=(newfile[0] | 32) ^ 32; - err=files.rename("-q",path+datei,newfile); -} diff --git a/freetype/builds/atari/FREETYPE.PRJ b/freetype/builds/atari/FREETYPE.PRJ deleted file mode 100644 index 4776a5b..0000000 --- a/freetype/builds/atari/FREETYPE.PRJ +++ /dev/null @@ -1,32 +0,0 @@ -;FreeType project file - -FREETYPE.LIB - -.C [-K -P -R -A] -.L [-J -V] -.S - -= - -..\..\src\base\ftsystem.c -..\..\src\base\ftdebug.c - -..\..\src\base\ftinit.c -..\..\src\base\ftglyph.c -..\..\src\base\ftmm -..\..\src\base\ftbbox - -..\..\src\base\ftbase.c -..\..\src\autohint\autohint.c -;..\..\src\cache\ftcache.c -..\..\src\cff\cff.c -..\..\src\cid\type1cid.c -..\..\src\psaux\psaux.c -..\..\src\pshinter\pshinter.c -..\..\src\psnames\psnames.c -..\..\src\raster\raster.c -..\..\src\sfnt\sfnt.c -..\..\src\smooth\smooth.c -..\..\src\truetype\truetype.c -..\..\src\type1\type1.c -..\..\src\type42\type42.c diff --git a/freetype/builds/atari/README.TXT b/freetype/builds/atari/README.TXT deleted file mode 100644 index 1300817..0000000 --- a/freetype/builds/atari/README.TXT +++ /dev/null @@ -1,51 +0,0 @@ -Compiling FreeType 2 with PureC compiler -======================================== - -[See below for a German version.] - -To compile FreeType 2 as a library the following changes must be applied: - -- All *.c files must start with an uppercase letter. - (In case GEMSCRIPT is available: - Simply drag the whole FreeType 2 directory to the file `FNames.SIC'.) - -- You have to change the INCLUDE directory in PureC's compiler options - to contain both the `INCLUDE' and `freetype2\include' directory. - Example: - - INCLUDE;E:\freetype2\include - -- The file `freetype/include/Ft2build.h' must be patched as follows to - include ATARI.H: - - #ifndef FT2_BUILD_GENERIC_H_ - #define FT2_BUILD_GENERIC_H_ - - #include "ATARI.H" - - - -Compilieren von FreeType 2 mit PureC -==================================== - -Um FreeType 2 als eine Bibliothek (library) zu compilieren, muss folgendes -ge„ndert werden: - -- Alle *.c-files mssen mit einem GROSSBUCHSTABEN beginnen. - (Falls GEMSCRIPT zur Verfgung steht: - Den kompletten Ordner freetype2 auf die Datei `FNames.SIC' draggen.) - -- In den Compiler-Optionen von PureC muss das INCLUDE directory auf INCLUDE - und freetype2\include verweisen. Z.B.: - - INCLUDE;E:\freetype2\include - -- In der Datei freetype/include/Ft2build.h muss zu Beginn - ein #include "ATARI.H" wie folgt eingefgt werden: - - #ifndef FT2_BUILD_GENERIC_H_ - #define FT2_BUILD_GENERIC_H_ - - #include "ATARI.H" - ---- end of README.TXT --- diff --git a/freetype/builds/atari/deflinejoiner.awk b/freetype/builds/atari/deflinejoiner.awk deleted file mode 100644 index 16d9e6d..0000000 --- a/freetype/builds/atari/deflinejoiner.awk +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/env awk - - -function shift( array, \ - junk, elm0, l ) -{ - elm0 = array[0] - for ( l = 0; l < asorti( array, junk ) - 1; l++ ) - array[l] = array[l+1]; - delete array[l] - return elm0 -} - - -function init_cpp_src_line() -{ - logical_line = "" - delete break_pos -} - - -function shift_valid_bp( array, \ - junk, elm ) -{ - elm = -1 - - if ( 0 < asorti( array, junk ) ) - do { - elm = shift( array ) - } while ( 0 > elm ); - - return elm -} - - -function check_cpp_src_line_break_pos( \ - i, junk ) -{ - printf( "break_pos:" ) - for ( i = 0; i < asorti( break_pos, junk ); i++ ) - printf( " %d", break_pos[i] ); - printf( "\n" ) -} - - -function check_cpp_src_line() -{ - printf( "logical_line[%s]\n", logical_line ) - check_cpp_src_line_break_pos() -} - - -function append_line( phys_line, \ - filt_line, bp_len ) -{ - filt_line = phys_line - sub( /\\$/, " ", filt_line ) - logical_line = logical_line filt_line - bp_len = asorti( break_pos, junk ) - break_pos[bp_len] = length( logical_line ) - 1 -} - - -function print_line( \ - c0, c1, i, junk, part_str ) -{ - c0 = 0 - - while( asorti( break_pos, junk ) > 1 ) - { - if ( ( c1 = shift_valid_bp( break_pos ) ) < 1 ) - { - part_str = substr( logical_line, c0 + 1 ) - printf( "%s\n", part_str ) - return - } - - part_str = substr( logical_line, c0 + 1, c1 - c0 + 1 ) - gsub( / $/, "\\", part_str ) - printf( "%s\n", part_str ) - c0 = c1 + 1 - } - - part_str = substr( logical_line, c0 + 1 ) - printf( "%s\n", part_str ) -} - - -function shrink_spaces( pos, \ - tail, removed_length, k ) -{ - tail = substr( logical_line, pos ) - sub( /^[ \t]+/, " ", tail ) - removed_length = length( logical_line ) - pos - length( tail ) + 1 - logical_line = substr( logical_line, 0, pos - 1 ) tail - - - for ( k = 0; k < asorti( break_pos, junk ); k++ ) - if ( ( pos + removed_length ) <= break_pos[k] ) - break_pos[k] = break_pos[k] - removed_length; - else if ( pos <= break_pos[k] ) - break_pos[k] = -1; - - return removed_length -} - - -function shrink_spaces_to_linebreak( pos, \ - junk, part_str, removed_length, i ) -{ - for ( i = 0; i < asorti( break_pos, junk ) && break_pos[i] < pos ; i++ ) - ; - - if ( break_pos[i] < 1 ) - return; - - part_str = substr( logical_line, pos, break_pos[i] - pos + 1 ) - sub( /^[ \t]+/, " ", part_str ) - removed_length = ( break_pos[i] - pos + 1 ) - length( part_str ) - - tail = substr( logical_line, pos + removed_length ) - logical_line = substr( logical_line, 0, pos - 1 ) tail - - for ( ; i < asorti( break_pos, junk ); i++ ) - break_pos[i] -= removed_length; - - return removed_length -} - - -function delete_linebreaks_in_2nd_token( \ - tail, paren_depth, junk, i, j, k, l ) -{ - if ( logical_line ~ /^[ \t]*#[ \t]*define[ \t]+[0-9A-Za-z_]+\(/ ) - { - tail = logical_line - sub( /^[ \t]*#[ \t]*define[ \t]+[0-9A-Za-z_]+/, "", tail ) - - paren_depth = 0 - l = 0 - i = length( logical_line ) - length( tail ) + 1 # seek to the 1st op paren - j = i - do { - if ( substr( logical_line, j, 2 ) ~ /[ \t][ \t]/ ) - l = shrink_spaces( j ); - else if ( substr( logical_line, j, 1 ) == "(" ) - paren_depth += 1; - else if ( substr( logical_line, j, 1 ) == ")" ) - paren_depth -= 1; - j += 1 - } while ( j < length( logical_line ) && paren_depth != 0 ) - - for ( k = 0; k < asorti( break_pos, junk ); k++ ) - if ( i <= break_pos[k] && break_pos[k] < j ) - break_pos[k] = -1; - - if ( l > 0 ) - shrink_spaces_to_linebreak( j ); - } -} - - -BEGIN{ - init_cpp_src_line() -} -{ - append_line( $0 ) - if ( $0 !~ /\\$/ ) - { - delete_linebreaks_in_2nd_token() - print_line() - init_cpp_src_line() - } -} -END{ - if ( 0 < length( logical_line ) ) - { - delete_linebreaks_in_2nd_token() - print_line() - } -} diff --git a/freetype/builds/atari/gen-purec-patch.sh b/freetype/builds/atari/gen-purec-patch.sh deleted file mode 100644 index 1ec050c..0000000 --- a/freetype/builds/atari/gen-purec-patch.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh - -TOP_DIR=. -OBJ_DIR=. - -for x in "$@" -do - case x"$x" in - x--srcdir=* | x--topdir=* ) - TOP_DIR=`echo $x | sed 's/^--[a-z]*dir=//'` - ;; - x--builddir=* | x--objdir=* ) - OBJ_DIR=`echo $x | sed 's/^--[a-z]*dir=//'` - ;; - esac -done - -mkdir -p ${OBJ_DIR}/builds/atari/tmp/orig - -( cd ${TOP_DIR} && find . -name '*.[CHch]' -type f | fgrep -v builds/atari/tmp | cpio -o ) | \ -( cd ${OBJ_DIR}/builds/atari/tmp/orig && cpio -idum ) -cp ${TOP_DIR}/builds/atari/deflinejoiner.awk ${OBJ_DIR}/builds/atari/tmp - -pushd ${OBJ_DIR}/builds/atari/tmp - - cp -pr orig purec - for f in `cd orig && find . -type f` - do - echo filter $f - env LANG=C awk -f deflinejoiner.awk < orig/$f > purec/$f - done - - echo '#define FT2_BUILD_LIBRARY' > purec/include/ft2build.h - echo '#include "ATARI.H"' >> purec/include/ft2build.h - env LANG=C awk -f deflinejoiner.awk < orig/include/ft2build.h >> purec/include/ft2build.h - - env LANG=C diff -ur orig purec > ../purec.diff - -popd -rm -rf ${OBJ_DIR}/builds/atari/tmp diff --git a/freetype/builds/beos/beos-def.mk b/freetype/builds/beos/beos-def.mk deleted file mode 100644 index 1cca80c..0000000 --- a/freetype/builds/beos/beos-def.mk +++ /dev/null @@ -1,79 +0,0 @@ -# -# FreeType 2 configuration rules for a BeOS system -# -# this is similar to the "ansi-def.mk" file, except for BUILD and PLATFORM -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -DELETE := rm -f -CAT := cat -SEP := / -PLATFORM_DIR := $(TOP_DIR)/builds/beos -PLATFORM := beos - -# This is used for `make refdoc' and `make refdoc-venv' -# -BIN := bin - -# The directory where all library files are placed. -# -# By default, this is the same as $(OBJ_DIR); however, this can be changed -# to suit particular needs. -# -LIB_DIR := $(OBJ_DIR) - - -# The name of the final library file. Note that the DOS-specific Makefile -# uses a shorter (8.3) name. -# -LIBRARY := lib$(PROJECT) - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := -l - - -# Target flag. -# -T := -o$(space) - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= -c - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSIFLAGS ?= - - -# EOF diff --git a/freetype/builds/beos/beos.mk b/freetype/builds/beos/beos.mk deleted file mode 100644 index 69ca1f1..0000000 --- a/freetype/builds/beos/beos.mk +++ /dev/null @@ -1,19 +0,0 @@ -# -# FreeType 2 configuration rules for a BeOS system -# - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -include $(TOP_DIR)/builds/beos/beos-def.mk -include $(TOP_DIR)/builds/compiler/ansi-cc.mk -include $(TOP_DIR)/builds/link_std.mk - - -# EOF diff --git a/freetype/builds/beos/detect.mk b/freetype/builds/beos/detect.mk deleted file mode 100644 index dd1b5a6..0000000 --- a/freetype/builds/beos/detect.mk +++ /dev/null @@ -1,41 +0,0 @@ -# -# FreeType 2 configuration file to detect an BeOS host platform. -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -.PHONY: setup - - -ifeq ($(PLATFORM),ansi) - - ifdef BE_HOST_CPU - - PLATFORM := beos - - endif # test MACHTYPE beos -endif - -ifeq ($(PLATFORM),beos) - - DELETE := rm -f - CAT := cat - SEP := / - PLATFORM_DIR := $(TOP_DIR)/builds/beos - CONFIG_FILE := beos.mk - - setup: std_setup - -endif # test PLATFORM beos - - -# EOF diff --git a/freetype/builds/cmake/FindBrotliDec.cmake b/freetype/builds/cmake/FindBrotliDec.cmake deleted file mode 100644 index 81036cb..0000000 --- a/freetype/builds/cmake/FindBrotliDec.cmake +++ /dev/null @@ -1,52 +0,0 @@ -# FindBrotliDec.cmake -# -# Copyright (C) 2019-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# Written by Werner Lemberg -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. -# -# -# Try to find libbrotlidec include and library directories. -# -# If found, the following variables are set. -# -# BROTLIDEC_INCLUDE_DIRS -# BROTLIDEC_LIBRARIES - -find_package(PkgConfig QUIET) - -pkg_check_modules(PC_BROTLIDEC QUIET libbrotlidec) - -if (PC_BROTLIDEC_VERSION) - set(BROTLIDEC_VERSION "${PC_BROTLIDEC_VERSION}") -endif () - - -find_path(BROTLIDEC_INCLUDE_DIRS - NAMES brotli/decode.h - HINTS ${PC_BROTLIDEC_INCLUDEDIR} - ${PC_BROTLIDEC_INCLUDE_DIRS} - PATH_SUFFIXES brotli) - -find_library(BROTLIDEC_LIBRARIES - NAMES brotlidec - HINTS ${PC_BROTLIDEC_LIBDIR} - ${PC_BROTLIDEC_LIBRARY_DIRS}) - - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - BrotliDec - REQUIRED_VARS BROTLIDEC_INCLUDE_DIRS BROTLIDEC_LIBRARIES - FOUND_VAR BROTLIDEC_FOUND - VERSION_VAR BROTLIDEC_VERSION) - -mark_as_advanced( - BROTLIDEC_INCLUDE_DIRS - BROTLIDEC_LIBRARIES) diff --git a/freetype/builds/cmake/FindHarfBuzz.cmake b/freetype/builds/cmake/FindHarfBuzz.cmake deleted file mode 100644 index b481fa4..0000000 --- a/freetype/builds/cmake/FindHarfBuzz.cmake +++ /dev/null @@ -1,203 +0,0 @@ -# Copyright (c) 2012, Intel Corporation -# Copyright (c) 2019 Sony Interactive Entertainment Inc. -# -# 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 Intel Corporation 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. -# -# Try to find Harfbuzz include and library directories. -# -# After successful discovery, this will set for inclusion where needed: -# HarfBuzz_INCLUDE_DIRS - containg the HarfBuzz headers -# HarfBuzz_LIBRARIES - containg the HarfBuzz library - -#[=======================================================================[.rst: -FindHarfBuzz --------------- - -Find HarfBuzz headers and libraries. - -Imported Targets -^^^^^^^^^^^^^^^^ - -``HarfBuzz::HarfBuzz`` - The HarfBuzz library, if found. - -``HarfBuzz::ICU`` - The HarfBuzz ICU library, if found. - -Result Variables -^^^^^^^^^^^^^^^^ - -This will define the following variables in your project: - -``HarfBuzz_FOUND`` - true if (the requested version of) HarfBuzz is available. -``HarfBuzz_VERSION`` - the version of HarfBuzz. -``HarfBuzz_LIBRARIES`` - the libraries to link against to use HarfBuzz. -``HarfBuzz_INCLUDE_DIRS`` - where to find the HarfBuzz headers. -``HarfBuzz_COMPILE_OPTIONS`` - this should be passed to target_compile_options(), if the - target is not used for linking - -#]=======================================================================] - -find_package(PkgConfig QUIET) -pkg_check_modules(PC_HARFBUZZ QUIET harfbuzz) -set(HarfBuzz_COMPILE_OPTIONS ${PC_HARFBUZZ_CFLAGS_OTHER}) -set(HarfBuzz_VERSION ${PC_HARFBUZZ_CFLAGS_VERSION}) - -find_path(HarfBuzz_INCLUDE_DIR - NAMES hb.h - HINTS ${PC_HARFBUZZ_INCLUDEDIR} ${PC_HARFBUZZ_INCLUDE_DIRS} - PATH_SUFFIXES harfbuzz -) - -find_library(HarfBuzz_LIBRARY - NAMES ${HarfBuzz_NAMES} harfbuzz - HINTS ${PC_HARFBUZZ_LIBDIR} ${PC_HARFBUZZ_LIBRARY_DIRS} -) - -if (HarfBuzz_INCLUDE_DIR AND NOT HarfBuzz_VERSION) - if (EXISTS "${HarfBuzz_INCLUDE_DIR}/hb-version.h") - file(READ "${HarfBuzz_INCLUDE_DIR}/hb-version.h" _harfbuzz_version_content) - - string(REGEX MATCH "#define +HB_VERSION_STRING +\"([0-9]+\\.[0-9]+\\.[0-9]+)\"" _dummy "${_harfbuzz_version_content}") - set(HarfBuzz_VERSION "${CMAKE_MATCH_1}") - endif () -endif () - -if ("${HarfBuzz_FIND_VERSION}" VERSION_GREATER "${HarfBuzz_VERSION}") - if (HarfBuzz_FIND_REQUIRED) - message(FATAL_ERROR - "Required version (" ${HarfBuzz_FIND_VERSION} ")" - " is higher than found version (" ${HarfBuzz_VERSION} ")") - else () - message(WARNING - "Required version (" ${HarfBuzz_FIND_VERSION} ")" - " is higher than found version (" ${HarfBuzz_VERSION} ")") - unset(HarfBuzz_VERSION) - unset(HarfBuzz_INCLUDE_DIRS) - unset(HarfBuzz_LIBRARIES) - return () - endif () -endif () - -# Find components -if (HarfBuzz_INCLUDE_DIR AND HarfBuzz_LIBRARY) - set(_HarfBuzz_REQUIRED_LIBS_FOUND ON) - set(HarfBuzz_LIBS_FOUND "HarfBuzz (required): ${HarfBuzz_LIBRARY}") -else () - set(_HarfBuzz_REQUIRED_LIBS_FOUND OFF) - set(HarfBuzz_LIBS_NOT_FOUND "HarfBuzz (required)") -endif () - -if (NOT CMAKE_VERSION VERSION_LESS 3.3) - if ("ICU" IN_LIST HarfBuzz_FIND_COMPONENTS) - pkg_check_modules(PC_HARFBUZZ_ICU QUIET harfbuzz-icu) - set(HarfBuzz_ICU_COMPILE_OPTIONS ${PC_HARFBUZZ_ICU_CFLAGS_OTHER}) - - find_path(HarfBuzz_ICU_INCLUDE_DIR - NAMES hb-icu.h - HINTS ${PC_HARFBUZZ_ICU_INCLUDEDIR} ${PC_HARFBUZZ_ICU_INCLUDE_DIRS} - PATH_SUFFIXES harfbuzz - ) - - find_library(HarfBuzz_ICU_LIBRARY - NAMES ${HarfBuzz_ICU_NAMES} harfbuzz-icu - HINTS ${PC_HARFBUZZ_ICU_LIBDIR} ${PC_HARFBUZZ_ICU_LIBRARY_DIRS} - ) - - if (HarfBuzz_ICU_LIBRARY) - if (HarfBuzz_FIND_REQUIRED_ICU) - list(APPEND HarfBuzz_LIBS_FOUND "ICU (required): ${HarfBuzz_ICU_LIBRARY}") - else () - list(APPEND HarfBuzz_LIBS_FOUND "ICU (optional): ${HarfBuzz_ICU_LIBRARY}") - endif () - else () - if (HarfBuzz_FIND_REQUIRED_ICU) - set(_HarfBuzz_REQUIRED_LIBS_FOUND OFF) - list(APPEND HarfBuzz_LIBS_NOT_FOUND "ICU (required)") - else () - list(APPEND HarfBuzz_LIBS_NOT_FOUND "ICU (optional)") - endif () - endif () - endif () -endif () - -if (NOT HarfBuzz_FIND_QUIETLY) - if (HarfBuzz_LIBS_FOUND) - message(STATUS "Found the following HarfBuzz libraries:") - foreach (found ${HarfBuzz_LIBS_FOUND}) - message(STATUS " ${found}") - endforeach () - endif () - if (HarfBuzz_LIBS_NOT_FOUND) - message(STATUS "The following HarfBuzz libraries were not found:") - foreach (found ${HarfBuzz_LIBS_NOT_FOUND}) - message(STATUS " ${found}") - endforeach () - endif () -endif () - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(HarfBuzz - FOUND_VAR HarfBuzz_FOUND - REQUIRED_VARS HarfBuzz_INCLUDE_DIR HarfBuzz_LIBRARY _HarfBuzz_REQUIRED_LIBS_FOUND - VERSION_VAR HarfBuzz_VERSION -) - -if (NOT CMAKE_VERSION VERSION_LESS 3.1) - if (HarfBuzz_LIBRARY AND NOT TARGET HarfBuzz::HarfBuzz) - add_library(HarfBuzz::HarfBuzz UNKNOWN IMPORTED GLOBAL) - set_target_properties(HarfBuzz::HarfBuzz PROPERTIES - IMPORTED_LOCATION "${HarfBuzz_LIBRARY}" - INTERFACE_COMPILE_OPTIONS "${HarfBuzz_COMPILE_OPTIONS}" - INTERFACE_INCLUDE_DIRECTORIES "${HarfBuzz_INCLUDE_DIR}" - ) - endif () - - if (HarfBuzz_ICU_LIBRARY AND NOT TARGET HarfBuzz::ICU) - add_library(HarfBuzz::ICU UNKNOWN IMPORTED GLOBAL) - set_target_properties(HarfBuzz::ICU PROPERTIES - IMPORTED_LOCATION "${HarfBuzz_ICU_LIBRARY}" - INTERFACE_COMPILE_OPTIONS "${HarfBuzz_ICU_COMPILE_OPTIONS}" - INTERFACE_INCLUDE_DIRECTORIES "${HarfBuzz_ICU_INCLUDE_DIR}" - ) - endif () -endif () - -mark_as_advanced( - HarfBuzz_INCLUDE_DIR - HarfBuzz_ICU_INCLUDE_DIR - HarfBuzz_LIBRARY - HarfBuzz_ICU_LIBRARY -) - -if (HarfBuzz_FOUND) - set(HarfBuzz_LIBRARIES ${HarfBuzz_LIBRARY} ${HarfBuzz_ICU_LIBRARY}) - set(HarfBuzz_INCLUDE_DIRS ${HarfBuzz_INCLUDE_DIR} ${HarfBuzz_ICU_INCLUDE_DIR}) -endif () diff --git a/freetype/builds/cmake/iOS.cmake b/freetype/builds/cmake/iOS.cmake deleted file mode 100644 index 7aba7c5..0000000 --- a/freetype/builds/cmake/iOS.cmake +++ /dev/null @@ -1,270 +0,0 @@ -# iOS.cmake -# -# Copyright (C) 2014-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# Written by David Wimsey -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. -# -# -# This file is derived from the files `Platform/Darwin.cmake' and -# `Platform/UnixPaths.cmake', which are part of CMake 2.8.4. It has been -# altered for iOS development. - - -# Options -# ------- -# -# IOS_PLATFORM = OS | SIMULATOR -# -# This decides whether SDKS are selected from the `iPhoneOS.platform' or -# `iPhoneSimulator.platform' folders. -# -# OS - the default, used to build for iPhone and iPad physical devices, -# which have an ARM architecture. -# SIMULATOR - used to build for the Simulator platforms, which have an -# x86 architecture. -# -# CMAKE_IOS_DEVELOPER_ROOT = /path/to/platform/Developer folder -# -# By default, this location is automatically chosen based on the -# IOS_PLATFORM value above. If you manually set this variable, it -# overrides the default location and forces the use of a particular -# Developer Platform. -# -# CMAKE_IOS_SDK_ROOT = /path/to/platform/Developer/SDKs/SDK folder -# -# By default, this location is automatically chosen based on the -# CMAKE_IOS_DEVELOPER_ROOT value. In this case it is always the most -# up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path. If you -# manually set this variable, it forces the use of a specific SDK -# version. -# -# -# Macros -# ------ -# -# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE) -# -# A convenience macro for setting Xcode specific properties on targets. -# -# Example: -# -# set_xcode_property(myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1") -# -# find_host_package (PROGRAM ARGS) -# -# A macro to find executable programs on the host system, not within the -# iOS environment. Thanks to the `android-cmake' project for providing -# the command. - - -# standard settings -set(CMAKE_SYSTEM_NAME Darwin) -set(CMAKE_SYSTEM_VERSION 1) -set(UNIX True) -set(APPLE True) -set(IOS True) - -# required as of cmake 2.8.10 -set(CMAKE_OSX_DEPLOYMENT_TARGET "" - CACHE STRING "Force unset of the deployment target for iOS" FORCE -) - -# determine the cmake host system version so we know where to find the iOS -# SDKs -find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin) -if (CMAKE_UNAME) - exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION) - string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" - DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}") -endif (CMAKE_UNAME) - -# skip the platform compiler checks for cross compiling -set(CMAKE_CXX_COMPILER_WORKS TRUE) -set(CMAKE_C_COMPILER_WORKS TRUE) - -# all iOS/Darwin specific settings - some may be redundant -set(CMAKE_SHARED_LIBRARY_PREFIX "lib") -set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") -set(CMAKE_SHARED_MODULE_PREFIX "lib") -set(CMAKE_SHARED_MODULE_SUFFIX ".so") -set(CMAKE_MODULE_EXISTS 1) -set(CMAKE_DL_LIBS "") - -set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG - "-compatibility_version ") -set(CMAKE_C_OSX_CURRENT_VERSION_FLAG - "-current_version ") -set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG - "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") -set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG - "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") - -# hidden visibility is required for cxx on iOS -set(CMAKE_C_FLAGS_INIT "") -set(CMAKE_CXX_FLAGS_INIT - "-headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden") - -set(CMAKE_C_LINK_FLAGS - "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") -set(CMAKE_CXX_LINK_FLAGS - "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") - -set(CMAKE_PLATFORM_HAS_INSTALLNAME 1) -set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS - "-dynamiclib -headerpad_max_install_names") -set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS - "-bundle -headerpad_max_install_names") -set(CMAKE_SHARED_MODULE_LOADER_C_FLAG - "-Wl,-bundle_loader,") -set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG - "-Wl,-bundle_loader,") -set(CMAKE_FIND_LIBRARY_SUFFIXES - ".dylib" ".so" ".a") - -# hack: If a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old -# build tree (where `install_name_tool' was hardcoded), and where -# CMAKE_INSTALL_NAME_TOOL isn't in the cache and still cmake didn't -# fail in `CMakeFindBinUtils.cmake' (because it isn't rerun), hardcode -# CMAKE_INSTALL_NAME_TOOL here to `install_name_tool' so it behaves as -# it did before. -if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) - find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool) -endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) - -# set up iOS platform unless specified manually with IOS_PLATFORM -if (NOT DEFINED IOS_PLATFORM) - set(IOS_PLATFORM "OS") -endif (NOT DEFINED IOS_PLATFORM) - -set(IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") - -# check the platform selection and setup for developer root -if (${IOS_PLATFORM} STREQUAL "OS") - set(IOS_PLATFORM_LOCATION "iPhoneOS.platform") - - # this causes the installers to properly locate the output libraries - set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") - -elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") - set(IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") - - # this causes the installers to properly locate the output libraries - set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") - -else (${IOS_PLATFORM} STREQUAL "OS") - message(FATAL_ERROR - "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR.") - -endif (${IOS_PLATFORM} STREQUAL "OS") - -# set up iOS developer location unless specified manually with -# CMAKE_IOS_DEVELOPER_ROOT -- -# note that Xcode 4.3 changed the installation location; choose the most -# recent one available -set(XCODE_POST_43_ROOT - "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") -set(XCODE_PRE_43_ROOT - "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") - -if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) - if (EXISTS ${XCODE_POST_43_ROOT}) - set(CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) - elseif (EXISTS ${XCODE_PRE_43_ROOT}) - set(CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) - endif (EXISTS ${XCODE_POST_43_ROOT}) -endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) - -set(CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} - CACHE PATH "Location of iOS Platform" -) - -# find and use the most recent iOS SDK unless specified manually with -# CMAKE_IOS_SDK_ROOT -if (NOT DEFINED CMAKE_IOS_SDK_ROOT) - file(GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*") - if (_CMAKE_IOS_SDKS) - list(SORT _CMAKE_IOS_SDKS) - list(REVERSE _CMAKE_IOS_SDKS) - list(GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT) - else (_CMAKE_IOS_SDKS) - message(FATAL_ERROR - "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.") - endif (_CMAKE_IOS_SDKS) - - message(STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}") -endif (NOT DEFINED CMAKE_IOS_SDK_ROOT) - -set(CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} - CACHE PATH "Location of the selected iOS SDK" -) - -# set the sysroot default to the most recent SDK -set(CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} - CACHE PATH "Sysroot used for iOS support" -) - -# set the architecture for iOS -- -# note that currently both ARCHS_STANDARD_32_BIT and -# ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually -if (${IOS_PLATFORM} STREQUAL "OS") - set(IOS_ARCH $(ARCHS_STANDARD_32_64_BIT)) -else (${IOS_PLATFORM} STREQUAL "OS") - set(IOS_ARCH i386) -endif (${IOS_PLATFORM} STREQUAL "OS") - -set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} - CACHE string "Build architecture for iOS" -) - -# set the find root to the iOS developer roots and to user defined paths -set(CMAKE_FIND_ROOT_PATH - ${CMAKE_IOS_DEVELOPER_ROOT} - ${CMAKE_IOS_SDK_ROOT} - ${CMAKE_PREFIX_PATH} - CACHE string "iOS find search path root" -) - -# default to searching for frameworks first -set(CMAKE_FIND_FRAMEWORK FIRST) - -# set up the default search directories for frameworks -set(CMAKE_SYSTEM_FRAMEWORK_PATH - ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks - ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks - ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks -) - -# only search the iOS SDKs, not the remainder of the host filesystem -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - -# this little macro lets you set any Xcode specific property -macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE) - set_property(TARGET ${TARGET} - PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE}) -endmacro(set_xcode_property) - -# this macro lets you find executable programs on the host system -macro(find_host_package) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) - set(IOS FALSE) - - find_package(${ARGN}) - - set(IOS TRUE) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -endmacro(find_host_package) - -# eof diff --git a/freetype/builds/cmake/testbuild.sh b/freetype/builds/cmake/testbuild.sh deleted file mode 100644 index 007170b..0000000 --- a/freetype/builds/cmake/testbuild.sh +++ /dev/null @@ -1,157 +0,0 @@ -#!/bin/sh -e - -# Copyright (C) 2015-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# This script tests the CMake build. Simply run -# -# builds/cmake/testbuild.sh -# -# or -# -# BUILD_SHARED_LIBS=1 builds/cmake/testbuild.sh -# -# The script: -# -# - builds the main CMakeLists.txt -# - builds and runs a small test app in a separate build tree so -# the config-module is tested, too -# -# Options (environment variables): -# -# - The variable BUILD_SHARED_LIBS will be forwarded to the CMake project -# that builds the library. -# - - -# prepare temporary dir - -cd `dirname $0`/../.. -ftdir=`pwd` -tmpdir=/tmp/freetype-cmake-testbuild -rm -rf $tmpdir -mkdir -p $tmpdir - - -# build and install freetype - -if test -n "$BUILD_SHARED_LIBS"; then - bsl=-DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -else - bsl=-UBUILD_SHARED_LIBS -fi - -build_opts="-DWITH_ZLIB=0 \ - -DWITH_BZip2=0 \ - -DWITH_PNG=0 \ - -DWITH_HarfBuzz=0 \ - $bsl \ - -DCMAKE_INSTALL_PREFIX=$tmpdir/out" - -(set -x; cmake -H$ftdir \ - -B$tmpdir/ftb \ - -DCMAKE_BUILD_TYPE=Debug \ - $build_opts) -(set -x; cmake --build $tmpdir/ftb \ - --config Debug \ - --target install) - -(set -x; cmake $tmpdir/ftb \ - -DCMAKE_BUILD_TYPE=Release) -(set -x; cmake --build $tmpdir/ftb \ - --config Release \ - --target install \ - --clean-first) - - -# create test project CMakeLists.txt - -cat >$tmpdir/CMakeLists.txt << END -cmake_minimum_required(VERSION 2.6) -project(freetype-cmake-testbuild) - -find_package(Freetype REQUIRED CONFIG) - -add_executable(freetype-cmake-test main.c) -target_link_libraries(freetype-cmake-test freetype) - -enable_testing() -add_test(freetype-cmake-test freetype-cmake-test) -END - - -# create test project main.c - -cat >$tmpdir/main.c << END -#include -#include - -#include -#include - - -FT_Library library; - - -int main(int argc, - char*argv[]) -{ - FT_Error error; - FT_Int major = 0; - FT_Int minor = 0; - FT_Int patch = 0; - - error = FT_Init_FreeType(&library); - if (error) - return EXIT_FAILURE; - - FT_Library_Version(library, &major, &minor, &patch); - if (major != FREETYPE_MAJOR - || minor != FREETYPE_MINOR - || patch != FREETYPE_PATCH) - return EXIT_FAILURE; - - printf("FT_Library_Version: %d.%d.%d\n", major, minor, patch); - - error = FT_Done_FreeType(library); - if (error) - return EXIT_FAILURE; - - return EXIT_SUCCESS; -} -END - - -# build and test - -mkdir -p $tmpdir/tb -cd $tmpdir/tb - -LD_LIBRARY_PATH=$tmpdir/out/lib:$LD_LIBRARY_PATH -DYLD_LIBRARY_PATH=$tmpdir/out/lib:$DYLD_LIBRARY_PATH -export LD_LIBRARY_PATH -export DYLD_LIBRARY_PATH - -(set -x; cmake $tmpdir \ - -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_PREFIX_PATH=$tmpdir/out) -(set -x; cmake --build . \ - --config Debug) -(set -x; ctest -V -C Debug) - -(set -x; cmake . \ - -DCMAKE_BUILD_TYPE=Release) -(set -x; cmake --build . \ - --config Release \ - --clean-first) -(set -x; ctest -V -C Release) - -rm -rf $tmpdir - -# EOF diff --git a/freetype/builds/compiler/ansi-cc.mk b/freetype/builds/compiler/ansi-cc.mk deleted file mode 100644 index f8386f6..0000000 --- a/freetype/builds/compiler/ansi-cc.mk +++ /dev/null @@ -1,80 +0,0 @@ -# -# FreeType 2 generic pseudo ANSI compiler -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# Compiler command line name -# -CC := cc -COMPILER_SEP := $(SEP) - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := o -SO := o - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := a -SA := a - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := -l - - -# Target flag. -# -T := -o$(space) - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= -c - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -# we assume the compiler is already strictly ANSI -# -ANSIFLAGS ?= - - -# Library linking -# -CLEAN_LIBRARY ?= $(DELETE) $(subst /,$(SEP),$(PROJECT_LIBRARY)) -LINK_LIBRARY = $(AR) -r $@ $(subst /,$(COMPILER_SEP),$(OBJECTS_LIST)) - - -# EOF diff --git a/freetype/builds/compiler/bcc-dev.mk b/freetype/builds/compiler/bcc-dev.mk deleted file mode 100644 index d01ed7c..0000000 --- a/freetype/builds/compiler/bcc-dev.mk +++ /dev/null @@ -1,86 +0,0 @@ -# -# FreeType 2 Borland C++-specific with NO OPTIMIZATIONS + DEBUGGING -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# Compiler command line name -# -CC := bcc32 -COMPILER_SEP := $(SEP) - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := obj -SO := obj - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := lib -SA := lib - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := - - -# Target flag -- no trailing space. -# -T := -o -TE := -e - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= -q -c -y -d -v -Od -w-par -w-ccc -w-rch -w-pro -w-aus - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSIFLAGS ?= -A - - -# Library linking -# -CLEAN_LIBRARY ?= $(DELETE) $(subst /,$(SEP),$(PROJECT_LIBRARY)) -LINK_LIBRARY = tlib /u /P128 $(subst /,$(COMPILER_SEP),$@ $(OBJECTS_LIST:%=+%)) - - -# Borland C++ specific temporary files -# -CLEAN += \ - $(subst /,$(SEP),$(TOP_DIR)/apinames.$(O)) \ - $(subst /,$(SEP),$(OBJ_DIR)/apinames.tds) - - -# EOF diff --git a/freetype/builds/compiler/bcc.mk b/freetype/builds/compiler/bcc.mk deleted file mode 100644 index a484bba..0000000 --- a/freetype/builds/compiler/bcc.mk +++ /dev/null @@ -1,86 +0,0 @@ -# -# FreeType 2 Borland C++-specific rules -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# Compiler command line name -# -CC := bcc32 -COMPILER_SEP := $(SEP) - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := obj -SO := obj - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := lib -SA := lib - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := - - -# Target flag -- no trailing space. -# -T := -o -TE := -e - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= -c -q -y -d -v -Od -w-par -w-ccc -w-rch -w-pro -w-aus - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSIFLAGS ?= -A - - -# Library linking -# -CLEAN_LIBRARY ?= $(DELETE) $(subst /,$(SEP),$(PROJECT_LIBRARY)) -LINK_LIBRARY = tlib /u /P128 $(subst /,$(COMPILER_SEP),$@ $(OBJECTS_LIST:%=+%)) - - -# Borland C++ specific temporary files -# -CLEAN += \ - $(subst /,$(SEP),$(TOP_DIR)/apinames.$(O)) \ - $(subst /,$(SEP),$(OBJ_DIR)/apinames.tds) - - -# EOF diff --git a/freetype/builds/compiler/emx.mk b/freetype/builds/compiler/emx.mk deleted file mode 100644 index 34d06b2..0000000 --- a/freetype/builds/compiler/emx.mk +++ /dev/null @@ -1,77 +0,0 @@ -# -# FreeType 2 emx-specific definitions -# - - -# Copyright (C) 2003-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# Compiler command line name -# -CC := set GCCOPT="-ansi -pedantic"; gcc -COMPILER_SEP := / - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := o -SO := o - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := a -SA := a - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := -l - - -# Target flag. -# -T := -o$(space) - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= -c -g -O6 -Wall - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSIFLAGS ?= - - -# Library linking -# -CLEAN_LIBRARY ?= $(DELETE) $(subst /,$(SEP),$(PROJECT_LIBRARY)) -LINK_LIBRARY = $(foreach m,$(OBJECTS_LIST),$(AR) -r $@ $(m);) echo > nul - - -# EOF diff --git a/freetype/builds/compiler/gcc-dev.mk b/freetype/builds/compiler/gcc-dev.mk deleted file mode 100644 index a6ded52..0000000 --- a/freetype/builds/compiler/gcc-dev.mk +++ /dev/null @@ -1,96 +0,0 @@ -# -# FreeType 2 gcc-specific with NO OPTIMIZATIONS + DEBUGGING -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# Compiler command line name -# -CC := gcc -COMPILER_SEP := / - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := o -SO := o - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := a -SA := a - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := -l - - -# Target flag. -# -T := -o$(space) - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -ifndef CFLAGS - ifeq ($(findstring g++,$(CC)),) - nested_externs := -Wnested-externs - strict_prototypes := -Wstrict-prototypes - endif - - CFLAGS := -c -g -O0 \ - -Wall \ - -W \ - -Wundef \ - -Wshadow \ - -Wpointer-arith \ - -Wwrite-strings \ - -Wredundant-decls \ - -Wno-long-long \ - $(nested_externs) \ - $(strict_prototypes) -endif - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# You can override this on the command line. -# -ANSIFLAGS ?= -std=c99 -pedantic - - -# Library linking -# -CLEAN_LIBRARY ?= $(DELETE) $(subst /,$(SEP),$(PROJECT_LIBRARY)) -LINK_LIBRARY = $(AR) -r $@ $(OBJECTS_LIST) - - -# EOF diff --git a/freetype/builds/compiler/gcc.mk b/freetype/builds/compiler/gcc.mk deleted file mode 100644 index 20ca969..0000000 --- a/freetype/builds/compiler/gcc.mk +++ /dev/null @@ -1,77 +0,0 @@ -# -# FreeType 2 gcc-specific definitions -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# Compiler command line name -# -CC := gcc -COMPILER_SEP := / - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := o -SO := o - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := a -SA := a - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := -l - - -# Target flag. -# -T := -o$(space) - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= -c -g -O3 -Wall - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSIFLAGS ?= -std=c99 -pedantic - - -# Library linking -# -CLEAN_LIBRARY ?= $(DELETE) $(subst /,$(SEP),$(PROJECT_LIBRARY)) -LINK_LIBRARY = $(AR) -r $@ $(OBJECTS_LIST) - - -# EOF diff --git a/freetype/builds/compiler/intelc.mk b/freetype/builds/compiler/intelc.mk deleted file mode 100644 index 1f72493..0000000 --- a/freetype/builds/compiler/intelc.mk +++ /dev/null @@ -1,85 +0,0 @@ -# -# FreeType 2 Intel C/C++ definitions (VC++ compatibility mode) -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# compiler command line name -# -CC := icl -COMPILER_SEP := $(SEP) - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := obj -SO := obj - - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := lib -SA := lib - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := /I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := /D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := /Fl - - -# Target flag. -# -T := /Fo -TE := /Fe - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -# Note that the Intel C/C++ compiler version 4.5 complains about -# the use of FT_FIELD_OFFSET with "value must be arithmetic type"! -# This really looks like a bug in the compiler because the macro -# _does_ compute an arithmetic value, so we disable this warning -# with "/Qwd32". -# -CFLAGS ?= /nologo /c /Ox /G5 /W3 /Qwd32 - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSIFLAGS ?= /Qansi_alias /Za - -# Library linking -# -#CLEAN_LIBRARY = -LINK_LIBRARY = lib /nologo /out:$(subst /,$(COMPILER_SEP),$@ $(OBJECTS_LIST)) - - -# EOF diff --git a/freetype/builds/compiler/unix-lcc.mk b/freetype/builds/compiler/unix-lcc.mk deleted file mode 100644 index af11d17..0000000 --- a/freetype/builds/compiler/unix-lcc.mk +++ /dev/null @@ -1,83 +0,0 @@ -# -# FreeType 2 Unix LCC specific definitions -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# Command line name -# -CC := lcc -COMPILER_SEP := $(SEP) - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := o -SO := o - - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := a -SA := a - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := -l - - -# Target flag. -# -T := -o$(space) - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= -c -g - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -# LCC is pure ANSI anyway! -# -# the "-A" flag simply increments verbosity about non ANSI code -# -ANSIFLAGS ?= -A - - -# library linking -# -CLEAN_LIBRARY ?= $(DELETE) $(PROJECT_LIBRARY) -LINK_LIBRARY = $(AR) -r $@ $(OBJECTS_LIST) - - -# EOF diff --git a/freetype/builds/compiler/visualage.mk b/freetype/builds/compiler/visualage.mk deleted file mode 100644 index 75e9023..0000000 --- a/freetype/builds/compiler/visualage.mk +++ /dev/null @@ -1,76 +0,0 @@ -# -# FreeType 2 Visual Age C++ specific definitions -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# command line compiler name -# -CC := icc -COMPILER_SEP := $(SEP) - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := obj -SO := obj - - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := lib -SA := lib - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := /I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := /D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := /Fl - - -# Target flag. -# -T := /Fo - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -CFLAGS ?= /Q- /Gd+ /O2 /G5 /W3 /C - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSI_FLAGS := /Sa - - -# Library linking -# -#CLEAN_LIBRARY := -LINK_LIBRARY = lib /nologo /out:$(subst /,$(COMPILER_SEP),$@ $(OBJECTS_LIST)) - - -# EOF diff --git a/freetype/builds/compiler/visualc.mk b/freetype/builds/compiler/visualc.mk deleted file mode 100644 index 30b03fc..0000000 --- a/freetype/builds/compiler/visualc.mk +++ /dev/null @@ -1,82 +0,0 @@ -# -# FreeType 2 Visual C++ definitions -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# compiler command line name -# -CC := cl -COMPILER_SEP := $(SEP) - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := obj -SO := obj - - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := lib -SA := lib - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := /I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := /D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := /Fl - - -# Target flag. -# -T := /Fo - -# Target executable flag -# -TE := /Fe - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= /nologo /c /Ox /W3 /WX - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSIFLAGS ?= /Za /D_CRT_SECURE_NO_DEPRECATE - - -# Library linking -# -#CLEAN_LIBRARY = -LINK_LIBRARY = lib /nologo /out:$(subst /,$(COMPILER_SEP),$@ $(OBJECTS_LIST)) - - -# EOF diff --git a/freetype/builds/compiler/watcom.mk b/freetype/builds/compiler/watcom.mk deleted file mode 100644 index 61f8cd7..0000000 --- a/freetype/builds/compiler/watcom.mk +++ /dev/null @@ -1,81 +0,0 @@ -# -# FreeType 2 Watcom-specific definitions -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# Compiler command line name -# -CC := wcc386 -COMPILER_SEP := $(SEP) - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := obj -SO := obj - - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := lib -SA := lib - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I= - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := -l - - -# Target flag. -# -T := -FO= - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= -zq - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSIFLAGS ?= -za - - -# Library linking -# -CLEAN_LIBRARY ?= $(DELETE) $(subst /,$(SEP),$(PROJECT_LIBRARY)) -LINK_LIBRARY = $(subst /,$(COMPILER_SEP), \ - wlib -q -n $@; \ - $(foreach m, $(OBJECTS_LIST), wlib -q $@ +$(m);) \ - echo > nul) - -# EOF diff --git a/freetype/builds/compiler/win-lcc.mk b/freetype/builds/compiler/win-lcc.mk deleted file mode 100644 index 92f653e..0000000 --- a/freetype/builds/compiler/win-lcc.mk +++ /dev/null @@ -1,81 +0,0 @@ -# -# FreeType 2 Win32-LCC specific definitions -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# Command line name -# -CC := lcc -COMPILER_SEP := $(SEP) - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := obj -SO := obj - - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := lib -SA := lib - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := -Fl - - -# Target flag. -# -T := -Fo - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -CFLAGS ?= -c -g2 -O - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -# LCC is pure ANSI anyway! -# -ANSIFLAGS ?= - - -# library linking -# -#CLEAN_LIBRARY := -LINK_LIBRARY = lcclib /out:$(subst /,$(COMPILER_SEP),$@ $(OBJECTS_LIST)) - - -# EOF diff --git a/freetype/builds/detect.mk b/freetype/builds/detect.mk deleted file mode 100644 index d5cddb0..0000000 --- a/freetype/builds/detect.mk +++ /dev/null @@ -1,128 +0,0 @@ -# -# FreeType 2 host platform detection rules -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# This sub-Makefile is in charge of detecting the current platform. It sets -# the following variables: -# -# PLATFORM_DIR The configuration and system-specific directory. Usually -# `builds/$(PLATFORM)' but can be different for custom builds -# of the library. -# -# The following variables must be defined in system specific `detect.mk' -# files: -# -# PLATFORM The detected platform. This will default to `ansi' if -# auto-detection fails. -# CONFIG_FILE The configuration sub-makefile to use. This usually depends -# on the compiler defined in the `CC' environment variable. -# DELETE The shell command used to remove a given file. -# COPY The shell command used to copy one file. -# SEP The platform-specific directory separator. -# COMPILER_SEP The separator used in arguments of the compilation tools. -# CC The compiler to use. -# -# You need to set the following variable(s) before calling it: -# -# TOP_DIR The top-most directory in the FreeType library source -# hierarchy. If not defined, it will default to `.'. - -# Set auto-detection default to `ansi' resp. UNIX-like operating systems. -# -PLATFORM := ansi -DELETE := $(RM) -COPY := cp -CAT := cat -SEP := / - -BUILD_CONFIG := $(TOP_DIR)/builds - -# These two assignments must be delayed. -PLATFORM_DIR = $(BUILD_CONFIG)/$(PLATFORM) -CONFIG_RULES = $(PLATFORM_DIR)/$(CONFIG_FILE) - -# We define the BACKSLASH variable to hold a single back-slash character. -# This is needed because a line like -# -# SEP := \ -# -# does not work with GNU Make (the backslash is interpreted as a line -# continuation). While a line like -# -# SEP := \\ -# -# really defines $(SEP) as `\' on Unix, and `\\' on Dos and Windows! -# -BACKSLASH := $(strip \ ) - -# Find all auto-detectable platforms. -# -PLATFORMS := $(notdir $(subst /detect.mk,,$(wildcard $(BUILD_CONFIG)/*/detect.mk))) -.PHONY: $(PLATFORMS) ansi - -# Filter out platform specified as setup target. -# -PLATFORM := $(firstword $(filter $(MAKECMDGOALS),$(PLATFORMS))) - -# If no setup target platform was specified, enable auto-detection/ -# default platform. -# -ifeq ($(PLATFORM),) - PLATFORM := ansi -endif - -# If the user has explicitly asked for `ansi' on the command line, -# disable auto-detection. -# -ifeq ($(findstring ansi,$(MAKECMDGOALS)),) - # Now, include all detection rule files found in the `builds/' - # directories. Note that the calling order of the various `detect.mk' - # files isn't predictable. - # - include $(wildcard $(BUILD_CONFIG)/*/detect.mk) -endif - -# In case no detection rule file was successful, use the default. -# -ifndef CONFIG_FILE - CONFIG_FILE := ansi.mk - setup: std_setup - .PHONY: setup -endif - -# Flash out and copy rules. -# -.PHONY: std_setup - -std_setup: - $(info ) - $(info $(PROJECT_TITLE) build system -- automatic system detection) - $(info ) - $(info The following settings are used:) - $(info ) - $(info $(empty) platform $(PLATFORM)) - $(info $(empty) compiler $(CC)) - $(info $(empty) configuration directory $(subst /,$(SEP),$(PLATFORM_DIR))) - $(info $(empty) configuration rules $(subst /,$(SEP),$(CONFIG_RULES))) - $(info ) - $(info If this does not correspond to your system or settings please remove the file) - $(info `$(CONFIG_MK)' from this directory then read the INSTALL file for help.) - $(info ) - $(info Otherwise, simply type `$(MAKE)' again to build the library,) - $(info or `$(MAKE) refdoc' to build the API reference (this needs Python >= 3.5).) - $(info ) - @$(COPY) $(subst /,$(SEP),$(CONFIG_RULES) $(CONFIG_MK)) - - -# EOF diff --git a/freetype/builds/dos/detect.mk b/freetype/builds/dos/detect.mk deleted file mode 100644 index 8ed148b..0000000 --- a/freetype/builds/dos/detect.mk +++ /dev/null @@ -1,152 +0,0 @@ -# -# FreeType 2 configuration file to detect a DOS host platform. -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -.PHONY: setup - - -ifeq ($(PLATFORM),ansi) - - # Test for DJGPP by checking the DJGPP environment variable, which must be - # set in order to use the system (ie. it will always be present when the - # `make' utility is run). - # - # We test for the COMSPEC environment variable, then run the `ver' - # command-line program to see if its output contains the word `Dos' or - # `DOS'. - # - # If this is true, we are running a Dos-ish platform (or an emulation). - # - ifdef DJGPP - PLATFORM := dos - else - ifdef COMSPEC - is_dos := $(findstring DOS,$(subst Dos,DOS,$(shell ver))) - - # We try to recognize a Dos session under OS/2. The `ver' command - # returns `Operating System/2 ...' there, so `is_dos' should be empty. - # - # To recognize a Dos session under OS/2, we check COMSPEC for the - # substring `MDOS\COMMAND' - # - ifeq ($(is_dos),) - is_dos := $(findstring MDOS\COMMAND,$(COMSPEC)) - endif - - # We also try to recognize Dos 7.x without Windows 9X launched. - # See builds/windows/detect.mk for explanations about the logic. - # - ifeq ($(is_dos),) - ifdef winbootdir -#ifneq ($(OS),Windows_NT) - # If windows is available, do not trigger this test. - ifndef windir - is_dos := $(findstring Windows,$(strip $(shell ver))) - endif -#endif - endif - endif - - endif # test COMSPEC - - ifneq ($(is_dos),) - - PLATFORM := dos - - endif # test Dos - endif # test DJGPP -endif # test PLATFORM ansi - -ifeq ($(PLATFORM),dos) - - # Use DJGPP (i.e. gcc) by default. - # - CONFIG_FILE := dos-gcc.mk - CC ?= gcc - - # additionally, we provide hooks for various other compilers - # - ifneq ($(findstring emx,$(MAKECMDGOALS)),) # EMX gcc - CONFIG_FILE := dos-emx.mk - CC := gcc - - .PHONY: emx - emx: setup - @cd . - endif - - ifneq ($(findstring turboc,$(MAKECMDGOALS)),) # Turbo C - CONFIG_FILE := dos-tcc.mk - CC := tcc - - .PHONY: turboc - turboc: setup - @cd . - endif - - ifneq ($(findstring watcom,$(MAKECMDGOALS)),) # Watcom C/C++ - CONFIG_FILE := dos-wat.mk - CC := wcc386 - - .PHONY: watcom - watcom: setup - @cd . - endif - - ifneq ($(findstring borlandc,$(MAKECMDGOALS)),) # Borland C/C++ 32-bit - CONFIG_FILE := dos-bcc.mk - CC := bcc32 - - .PHONY: borlandc - borlandc: setup - @cd . - endif - - ifneq ($(findstring borlandc16,$(MAKECMDGOALS)),) # Borland C/C++ 16-bit - CONFIG_FILE := dos-bcc.mk - CC := bcc - - .PHONY: borlandc16 - borlandc16: setup - @cd . - endif - - ifneq ($(findstring bash,$(SHELL)),) # check for bash - SEP := / - DELETE := rm - COPY := cp - CAT := cat - setup: std_setup - else - SEP := $(BACKSLASH) - DELETE := del - CAT := type - - # Setting COPY is a bit trickier. We can be running DJGPP on some - # Windows NT derivatives, like XP. See builds/windows/detect.mk for - # explanations why we need hacking here. - # - ifeq ($(OS),Windows_NT) - COPY := cmd.exe /c copy - else - COPY := copy - endif # test NT - - setup: std_setup - endif - -endif # test PLATFORM dos - - -# EOF diff --git a/freetype/builds/dos/dos-def.mk b/freetype/builds/dos/dos-def.mk deleted file mode 100644 index 37cb2c1..0000000 --- a/freetype/builds/dos/dos-def.mk +++ /dev/null @@ -1,48 +0,0 @@ -# -# FreeType 2 DOS specific definitions -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -DELETE := del -CAT := type -SEP := $(strip \ ) -PLATFORM_DIR := $(TOP_DIR)/builds/dos -PLATFORM := dos - -# This is used for `make refdoc' and `make refdoc-venv' -# -BIN := Scripts - -# The executable file extension (for tools), *with* leading dot. -# -E := .exe - -# The directory where all library files are placed. -# -# By default, this is the same as $(OBJ_DIR); however, this can be changed -# to suit particular needs. -# -LIB_DIR := $(OBJ_DIR) - -# The name of the final library file. Note that the DOS-specific Makefile -# uses a shorter (8.3) name. -# -LIBRARY := $(PROJECT) - - -# The NO_OUTPUT macro is used to ignore the output of commands. -# -NO_OUTPUT = > nul - - -# EOF diff --git a/freetype/builds/dos/dos-emx.mk b/freetype/builds/dos/dos-emx.mk deleted file mode 100644 index 23181d7..0000000 --- a/freetype/builds/dos/dos-emx.mk +++ /dev/null @@ -1,21 +0,0 @@ -# -# FreeType 2 configuration rules for the EMX gcc compiler -# - - -# Copyright (C) 2003-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -include $(TOP_DIR)/builds/dos/dos-def.mk -include $(TOP_DIR)/builds/compiler/emx.mk -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/dos/dos-gcc.mk b/freetype/builds/dos/dos-gcc.mk deleted file mode 100644 index cd695db..0000000 --- a/freetype/builds/dos/dos-gcc.mk +++ /dev/null @@ -1,21 +0,0 @@ -# -# FreeType 2 configuration rules for the DJGPP compiler -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -include $(TOP_DIR)/builds/dos/dos-def.mk -include $(TOP_DIR)/builds/compiler/gcc.mk -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/dos/dos-wat.mk b/freetype/builds/dos/dos-wat.mk deleted file mode 100644 index a6b65cb..0000000 --- a/freetype/builds/dos/dos-wat.mk +++ /dev/null @@ -1,20 +0,0 @@ -# -# FreeType 2 configuration rules for the Watcom C/C++ compiler -# - - -# Copyright (C) 2003-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -include $(TOP_DIR)/builds/dos/dos-def.mk -include $(TOP_DIR)/builds/compiler/watcom.mk -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/exports.mk b/freetype/builds/exports.mk deleted file mode 100644 index b10924a..0000000 --- a/freetype/builds/exports.mk +++ /dev/null @@ -1,80 +0,0 @@ -# -# FreeType 2 exports sub-Makefile -# - - -# Copyright (C) 2005-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# DO NOT INVOKE THIS MAKEFILE DIRECTLY! IT IS MEANT TO BE INCLUDED BY -# OTHER MAKEFILES. - - -# This sub-Makefile is used to compute the list of exported symbols whenever -# the EXPORTS_LIST variable is defined by one of the platform or compiler -# specific build files. -# -# EXPORTS_LIST contains the name of the `list' file, for example a Windows -# .DEF file. -# -ifneq ($(EXPORTS_LIST),) - - # CCexe is the compiler used to compile the `apinames' tool program - # on the host machine. This isn't necessarily the same as the compiler - # which can be a cross-compiler for a different architecture, for example. - # - ifeq ($(CCexe),) - CCexe := $(CC) - endif - - # TE acts like T, but for executables instead of object files. - ifeq ($(TE),) - TE := $T - endif - - # The list of public headers we're going to parse. - PUBLIC_HEADERS := $(filter-out $(PUBLIC_DIR)/ftmac.h, \ - $(wildcard $(PUBLIC_DIR)/*.h)) - ifneq ($(ftmac_c),) - PUBLIC_HEADERS += $(PUBLIC_DIR)/ftmac.h - endif - - # The `apinames' source and executable. We use $E_BUILD as the host - # executable suffix, which *includes* the final dot. - # - # Note that $(APINAMES_OPTIONS) is empty, except for Windows compilers. - # - APINAMES_SRC := $(subst /,$(SEP),$(TOP_DIR)/src/tools/apinames.c) - APINAMES_EXE := $(subst /,$(SEP),$(OBJ_DIR)/apinames$(E_BUILD)) - - $(APINAMES_EXE): $(APINAMES_SRC) - $(CCexe) $(CCexe_CFLAGS) $(TE)$@ $< $(CCexe_LDFLAGS) - - .PHONY: symbols_list - - symbols_list: $(EXPORTS_LIST) - - # We manually add TT_New_Context and TT_RunIns, which are needed by TT - # debuggers, to the EXPORTS_LIST. - # - $(EXPORTS_LIST): $(APINAMES_EXE) $(PUBLIC_HEADERS) - $(subst /,$(SEP),$(APINAMES_EXE)) -o$@ $(APINAMES_OPTIONS) $(PUBLIC_HEADERS) - @echo TT_New_Context >> $(EXPORTS_LIST) - @echo TT_RunIns >> $(EXPORTS_LIST) - - $(PROJECT_LIBRARY): $(EXPORTS_LIST) - - CLEAN += $(EXPORTS_LIST) \ - $(APINAMES_EXE) - -endif - - -# EOF diff --git a/freetype/builds/freetype.mk b/freetype/builds/freetype.mk deleted file mode 100644 index b3fac80..0000000 --- a/freetype/builds/freetype.mk +++ /dev/null @@ -1,385 +0,0 @@ -# -# FreeType 2 library sub-Makefile -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# DO NOT INVOKE THIS MAKEFILE DIRECTLY! IT IS MEANT TO BE INCLUDED BY -# OTHER MAKEFILES. - - -# The following variables (set by other Makefile components, in the -# environment, or on the command line) are used: -# -# PLATFORM_DIR The architecture-dependent directory, -# e.g., `$(TOP_DIR)/builds/unix'. Added to INCLUDES also. -# -# OBJ_DIR The directory in which object files are created. -# -# LIB_DIR The directory in which the library is created. -# -# DOC_DIR The directory in which the API reference is created. -# -# INCLUDES A list of directories to be included additionally. -# -# DEVEL_DIR Development directory which is added to the INCLUDES -# variable before the standard include directories. -# -# CFLAGS Compilation flags. This overrides the default settings -# in the platform-specific configuration files. -# -# FTSYS_SRC If set, its value is used as the name of a replacement -# file for `src/base/ftsystem.c'. -# -# FTDEBUG_SRC If set, its value is used as the name of a replacement -# file for `src/base/ftdebug.c'. [For a normal build, this -# file does nothing.] -# -# FTMODULE_H The file which contains the list of module classes for -# the current build. Usually, this is automatically -# created by `modules.mk'. -# -# BASE_OBJ_S -# BASE_OBJ_M A list of base objects (for single object and multiple -# object builds, respectively). Set up in -# `src/base/rules.mk'. -# -# BASE_EXT_OBJ A list of base extension objects. Set up in -# `src/base/rules.mk'. -# -# DRV_OBJ_S -# DRV_OBJ_M A list of driver objects (for single object and multiple -# object builds, respectively). Set up cumulatively in -# `src//rules.mk'. -# -# CLEAN -# DISTCLEAN The sub-makefiles can append additional stuff to these two -# variables which is to be removed for the `clean' resp. -# `distclean' target. -# -# TOP_DIR, SEP, -# COMPILER_SEP, -# LIBRARY, CC, -# A, I, O, T Check `config.mk' for details. - - -# The targets `objects' and `library' are defined at the end of this -# Makefile after all other rules have been included. -# -.PHONY: single multi objects library refdoc refdoc-venv - -# default target -- build single objects and library -# -single: objects library - -# `multi' target -- build multiple objects and library -# -multi: objects library - - -# The FreeType source directory, usually `./src'. -# -SRC_DIR := $(TOP_DIR)/src - -# The directory where the base layer components are placed, usually -# `./src/base'. -# -BASE_DIR := $(SRC_DIR)/base - -# Other derived directories. -# -PUBLIC_DIR := $(TOP_DIR)/include/freetype -INTERNAL_DIR := $(PUBLIC_DIR)/internal -SERVICES_DIR := $(INTERNAL_DIR)/services -CONFIG_DIR := $(PUBLIC_DIR)/config - -# The documentation directory. -# -DOC_DIR ?= $(TOP_DIR)/docs - -# The final name of the library file. -# -PROJECT_LIBRARY := $(LIB_DIR)/$(LIBRARY).$A - - -# include paths -# -# IMPORTANT NOTE: The architecture-dependent directory must ALWAYS be placed -# before the standard include list. Porters are then able to -# put their own version of some of the FreeType components -# in the `builds/' directory, as these files will -# override the default sources. -# -INCLUDES := $(subst /,$(COMPILER_SEP),$(OBJ_DIR) \ - $(DEVEL_DIR) \ - $(PLATFORM_DIR) \ - $(TOP_DIR)/include) - -INCLUDE_FLAGS := $(INCLUDES:%=$I%) - -# For a development build, we assume that the external library dependencies -# defined in `ftoption.h' are fulfilled, so we directly access the necessary -# include directory information using `pkg-config'. -# -ifdef DEVEL_DIR - INCLUDE_FLAGS += $(shell pkg-config --cflags libpng) - INCLUDE_FLAGS += $(shell pkg-config --cflags harfbuzz) - INCLUDE_FLAGS += $(shell pkg-config --cflags libbrotlidec) -endif - - -# C flags used for the compilation of an object file. This must include at -# least the paths for the `base' and `builds/' directories; -# debug/optimization/warning flags + ansi compliance if needed. -# -# $(INCLUDE_FLAGS) should come before $(CFLAGS) to avoid problems with -# old FreeType versions. -# -# Note what we also define the macro FT2_BUILD_LIBRARY when building -# FreeType. This is required to let our sources include the internal -# headers (something forbidden by clients). -# -# `CPPFLAGS' might be specified by the user in the environment. -# -FT_CFLAGS = $(CPPFLAGS) \ - $(CFLAGS) \ - $DFT2_BUILD_LIBRARY - -FT_COMPILE := $(CC) $(ANSIFLAGS) $(INCLUDE_FLAGS) $(FT_CFLAGS) - - -# Include the `exports' rules file. -# -include $(TOP_DIR)/builds/exports.mk - - -# Initialize the list of objects. -# -OBJECTS_LIST := - - -# Define $(PUBLIC_H) as the list of all public header files located in -# `$(TOP_DIR)/include/freetype'. $(INTERNAL_H), and $(CONFIG_H) are defined -# similarly. $(FTOPTION_H) is the option file used in the compilation. -# -# This is used to simplify the dependency rules -- if one of these files -# changes, the whole library is recompiled. -# -ifneq ($(wildcard $(OBJ_DIR)/ftoption.h),) - FTOPTION_H := $(OBJ_DIR)/ftoption.h -else ifneq ($(wildcard $(PLATFORM_DIR)/ftoption.h),) - FTOPTION_H := $(PLATFORM_DIR)/ftoption.h -endif - -PUBLIC_H := $(wildcard $(PUBLIC_DIR)/*.h) -INTERNAL_H := $(wildcard $(INTERNAL_DIR)/*.h) \ - $(wildcard $(SERVICES_DIR)/*.h) -CONFIG_H := $(wildcard $(CONFIG_DIR)/*.h) \ - $(wildcard $(PLATFORM_DIR)/config/*.h) \ - $(FTMODULE_H) \ - $(FTOPTION_H) -DEVEL_H := $(wildcard $(TOP_DIR)/devel/*.h) - -FREETYPE_H := $(PUBLIC_H) $(INTERNAL_H) $(CONFIG_H) $(DEVEL_H) - - -# ftsystem component -# -FTSYS_SRC ?= $(BASE_DIR)/ftsystem.c - -FTSYS_OBJ := $(OBJ_DIR)/ftsystem.$O - -OBJECTS_LIST += $(FTSYS_OBJ) - -$(FTSYS_OBJ): $(FTSYS_SRC) $(FREETYPE_H) - $(FT_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) - - -# ftdebug component -# -FTDEBUG_SRC ?= $(BASE_DIR)/ftdebug.c - -FTDEBUG_OBJ := $(OBJ_DIR)/ftdebug.$O - -OBJECTS_LIST += $(FTDEBUG_OBJ) - -$(FTDEBUG_OBJ): $(FTDEBUG_SRC) $(FREETYPE_H) - $(FT_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) - - -# Include all rule files from FreeType components. -# -include $(SRC_DIR)/base/rules.mk -include $(patsubst %,$(SRC_DIR)/%/rules.mk,$(MODULES)) -include $(SRC_DIR)/dlg/rules.mk - - -# ftinit component -# -# The C source `ftinit.c' contains the FreeType initialization routines. -# It is able to automatically register one or more drivers when the API -# function FT_Init_FreeType() is called. -# -# The set of initial drivers is determined by the driver Makefiles -# includes above. Each driver Makefile updates the FTINIT_xxx lists -# which contain additional include paths and macros used to compile the -# single `ftinit.c' source. -# -FTINIT_SRC := $(BASE_DIR)/ftinit.c -FTINIT_OBJ := $(OBJ_DIR)/ftinit.$O - -OBJECTS_LIST += $(FTINIT_OBJ) - -$(FTINIT_OBJ): $(FTINIT_SRC) $(FREETYPE_H) - $(FT_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<) - - -# ftver component -# -# The VERSIONINFO resource `ftver.rc' contains version and copyright -# to be compiled by windres and tagged into DLL usually. -# -ifneq ($(RC),) - FTVER_SRC := $(BASE_DIR)/ftver.rc - FTVER_OBJ := $(OBJ_DIR)/ftver.$O - - OBJECTS_LIST += $(FTVER_OBJ) - - $(FTVER_OBJ): $(FTVER_SRC) - $(RC) -o $@ $< -endif - - -# All FreeType library objects. -# -OBJ_M := $(BASE_OBJ_M) $(BASE_EXT_OBJ) $(DRV_OBJS_M) $(DLG_OBJS_M) -OBJ_S := $(BASE_OBJ_S) $(BASE_EXT_OBJ) $(DRV_OBJS_S) $(DLG_OBJS_S) - - -# The target `multi' on the Make command line indicates that we want to -# compile each source file independently. -# -# Otherwise, each module/driver is compiled in a single object file through -# source file inclusion (see `src/base/ftbase.c' or -# `src/truetype/truetype.c' for examples). -# -BASE_OBJECTS := $(OBJECTS_LIST) - -ifneq ($(findstring multi,$(MAKECMDGOALS)),) - OBJECTS_LIST += $(OBJ_M) -else - OBJECTS_LIST += $(OBJ_S) -endif - -objects: $(OBJECTS_LIST) - -library: $(PROJECT_LIBRARY) - -# Run `docwriter' in the current Python environment. -# -PYTHON ?= python - -refdoc: - @echo Running docwriter... - $(PYTHON) -m docwriter \ - --prefix=ft2 \ - --title=FreeType-$(version) \ - --site=reference \ - --output=$(DOC_DIR) \ - $(PUBLIC_DIR)/*.h \ - $(PUBLIC_DIR)/config/*.h \ - $(PUBLIC_DIR)/cache/*.h - @echo Building static site... - cd $(DOC_DIR) && $(PYTHON) -m mkdocs build - @echo Done. - -# Variables for running `refdoc' with Python's `virtualenv'. The -# environment is created in `DOC_DIR/env' and is gitignored. -# -# We still need to cd into `DOC_DIR' to build `mkdocs' because paths in -# `mkdocs.yml' are relative to the current working directory. -# -VENV_NAME := env -VENV_DIR := $(DOC_DIR)$(SEP)$(VENV_NAME) -ENV_PYTHON := $(VENV_DIR)$(SEP)$(BIN)$(SEP)$(PYTHON) - -refdoc-venv: - @echo Setting up virtualenv for Python... - virtualenv --python=$(PYTHON) $(VENV_DIR) - @echo Installing docwriter... - $(ENV_PYTHON) -m pip install docwriter - @echo Running docwriter... - $(ENV_PYTHON) -m docwriter \ - --prefix=ft2 \ - --title=FreeType-$(version) \ - --site=reference \ - --output=$(DOC_DIR) \ - $(PUBLIC_DIR)/*.h \ - $(PUBLIC_DIR)/config/*.h \ - $(PUBLIC_DIR)/cache/*.h - @echo Building static site... - cd $(DOC_DIR) && $(VENV_NAME)$(SEP)$(BIN)$(SEP)python -m mkdocs build - @echo Done. - -.PHONY: clean_project_std distclean_project_std - -# Standard cleaning and distclean rules. These are not accepted -# on all systems though. -# -clean_project_std: - -$(DELETE) $(BASE_OBJECTS) $(OBJ_M) $(OBJ_S) $(CLEAN) - -distclean_project_std: clean_project_std - -$(DELETE) $(PROJECT_LIBRARY) - -$(DELETE) *.orig *~ core *.core $(DISTCLEAN) - - -.PHONY: clean_project_dos distclean_project_dos - -# The Dos command shell does not support very long list of arguments, so -# we are stuck with wildcards. -# -# Don't break the command lines with \; this prevents the "del" command from -# working correctly on Win9x. -# -clean_project_dos: - -$(DELETE) $(subst /,$(SEP),$(OBJ_DIR)/*.$O $(CLEAN) $(NO_OUTPUT)) - -distclean_project_dos: clean_project_dos - -$(DELETE) $(subst /,$(SEP),$(PROJECT_LIBRARY) $(DISTCLEAN) $(NO_OUTPUT)) - - -.PHONY: remove_config_mk remove_ftmodule_h - -# Remove configuration file (used for distclean). -# -remove_config_mk: - -$(DELETE) $(subst /,$(SEP),$(CONFIG_MK) $(NO_OUTPUT)) - -# Remove module list (used for distclean). -# -remove_ftmodule_h: - -$(DELETE) $(subst /,$(SEP),$(FTMODULE_H) $(NO_OUTPUT)) - - -.PHONY: clean distclean - -# The `config.mk' file must define `clean_project' and `distclean_project'. -# Implementations may use to relay these to either the `std' or `dos' -# versions from above, or simply provide their own implementation. -# -clean: clean_project -distclean: distclean_project remove_config_mk remove_ftmodule_h - -$(DELETE) $(subst /,$(SEP),$(DOC_DIR)/*.html $(NO_OUTPUT)) - - -# EOF diff --git a/freetype/builds/link_dos.mk b/freetype/builds/link_dos.mk deleted file mode 100644 index b3dc451..0000000 --- a/freetype/builds/link_dos.mk +++ /dev/null @@ -1,42 +0,0 @@ -# -# Link instructions for Dos-like systems (Dos, Win32, OS/2) -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -ifdef BUILD_PROJECT - - .PHONY: clean_project distclean_project - - # Now include the main sub-makefile. It contains all the rules used to - # build the library with the previous variables defined. - # - include $(TOP_DIR)/builds/$(PROJECT).mk - - # The cleanup targets. - # - clean_project: clean_project_dos - distclean_project: distclean_project_dos - - # This final rule is used to link all object files into a single library. - # this is compiler-specific - # - $(PROJECT_LIBRARY): $(OBJECTS_LIST) - ifdef CLEAN_LIBRARY - -$(CLEAN_LIBRARY) $(NO_OUTPUT) - endif - $(LINK_LIBRARY) - -endif - - -# EOF diff --git a/freetype/builds/link_std.mk b/freetype/builds/link_std.mk deleted file mode 100644 index aca8ec4..0000000 --- a/freetype/builds/link_std.mk +++ /dev/null @@ -1,42 +0,0 @@ -# -# Link instructions for standard systems -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -ifdef BUILD_PROJECT - - .PHONY: clean_project distclean_project - - # Now include the main sub-makefile. It contains all the rules used to - # build the library with the previous variables defined. - # - include $(TOP_DIR)/builds/$(PROJECT).mk - - # The cleanup targets. - # - clean_project: clean_project_std - distclean_project: distclean_project_std - - # This final rule is used to link all object files into a single library. - # this is compiler-specific - # - $(PROJECT_LIBRARY): $(OBJECTS_LIST) - ifdef CLEAN_LIBRARY - -$(CLEAN_LIBRARY) $(NO_OUTPUT) - endif - $(LINK_LIBRARY) - -endif - - -# EOF diff --git a/freetype/builds/mac/FreeType.m68k_cfm.make.txt b/freetype/builds/mac/FreeType.m68k_cfm.make.txt deleted file mode 100644 index b74565f..0000000 --- a/freetype/builds/mac/FreeType.m68k_cfm.make.txt +++ /dev/null @@ -1,209 +0,0 @@ -# File: FreeType.m68k_cfm.make -# Target: FreeType.m68k_cfm -# Created: Thursday, October 27, 2005 09:23:25 PM - - -MAKEFILE = FreeType.m68k_cfm.make -\xA5MondoBuild\xA5 = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified - -ObjDir = :objs: -Includes = \xB6 - -ansi strict \xB6 - -includes unix \xB6 - -i :include: \xB6 - -i :src: \xB6 - -i :include:freetype:config: - -Sym-68K = -sym off - -COptions = \xB6 - -d FT_MACINTOSH=1 \xB6 - -d HAVE_FSSPEC=1 \xB6 - -d HAVE_FSREF=0 \xB6 - -d HAVE_QUICKDRAW_TOOLBOX=1 \xB6 - -d HAVE_QUICKDRAW_CARBON=0 \xB6 - -d HAVE_ATS=0 \xB6 - -d FT2_BUILD_LIBRARY \xB6 - -d FT_CONFIG_CONFIG_H="" \xB6 - -d FT_CONFIG_MODULES_H="" \xB6 - {Includes} {Sym-68K} -model cfmseg - - -### Source Files ### - -SrcFiles = \xB6 - :src:autofit:autofit.c \xB6 - :builds:mac:ftbase.c \xB6 - :src:base:ftbbox.c \xB6 - :src:base:ftbdf.c \xB6 - :src:base:ftbitmap.c \xB6 - :src:base:ftdebug.c \xB6 - :src:base:ftfstype.c \xB6 - :src:base:ftglyph.c \xB6 - :src:base:ftgxval.c \xB6 - :src:base:ftinit.c \xB6 - :src:base:ftmm.c \xB6 - :src:base:ftotval.c \xB6 - :src:base:ftpfr.c \xB6 - :src:base:ftstroke.c \xB6 - :src:base:ftsynth.c \xB6 - :src:base:ftsystem.c \xB6 - :src:base:fttype1.c \xB6 - :src:base:ftwinfnt.c \xB6 - :src:cache:ftcache.c \xB6 - :src:bdf:bdf.c \xB6 - :src:cff:cff.c \xB6 - :src:cid:type1cid.c \xB6 -# :src:gxvalid:gxvalid.c \xB6 - :src:gzip:ftgzip.c \xB6 - :src:bzip2:ftbzip2.c \xB6 - :src:lzw:ftlzw.c \xB6 - :src:otvalid:otvalid.c \xB6 - :src:pcf:pcf.c \xB6 - :src:pfr:pfr.c \xB6 - :src:psaux:psaux.c \xB6 - :src:pshinter:pshinter.c \xB6 - :src:psnames:psmodule.c \xB6 - :src:raster:raster.c \xB6 - :src:sfnt:sfnt.c \xB6 - :src:smooth:smooth.c \xB6 - :src:truetype:truetype.c \xB6 - :src:type1:type1.c \xB6 - :src:type42:type42.c \xB6 - :src:winfonts:winfnt.c - - -### Object Files ### - -ObjFiles-68K = \xB6 - "{ObjDir}autofit.c.o" \xB6 - "{ObjDir}ftbase.c.o" \xB6 - "{ObjDir}ftbbox.c.o" \xB6 - "{ObjDir}ftbdf.c.o" \xB6 - "{ObjDir}ftbitmap.c.o" \xB6 - "{ObjDir}ftdebug.c.o" \xB6 - "{ObjDir}ftfstype.c.o" \xB6 - "{ObjDir}ftglyph.c.o" \xB6 - "{ObjDir}ftgxval.c.o" \xB6 - "{ObjDir}ftinit.c.o" \xB6 - "{ObjDir}ftmm.c.o" \xB6 - "{ObjDir}ftotval.c.o" \xB6 - "{ObjDir}ftpfr.c.o" \xB6 - "{ObjDir}ftstroke.c.o" \xB6 - "{ObjDir}ftsynth.c.o" \xB6 - "{ObjDir}ftsystem.c.o" \xB6 - "{ObjDir}fttype1.c.o" \xB6 - "{ObjDir}ftwinfnt.c.o" \xB6 - "{ObjDir}ftcache.c.o" \xB6 - "{ObjDir}bdf.c.o" \xB6 - "{ObjDir}cff.c.o" \xB6 - "{ObjDir}type1cid.c.o" \xB6 -# "{ObjDir}gxvalid.c.o" \xB6 - "{ObjDir}ftgzip.c.o" \xB6 - "{ObjDir}ftbzip2.c.o" \xB6 - "{ObjDir}ftlzw.c.o" \xB6 - "{ObjDir}otvalid.c.o" \xB6 - "{ObjDir}pcf.c.o" \xB6 - "{ObjDir}pfr.c.o" \xB6 - "{ObjDir}psaux.c.o" \xB6 - "{ObjDir}pshinter.c.o" \xB6 - "{ObjDir}psmodule.c.o" \xB6 - "{ObjDir}raster.c.o" \xB6 - "{ObjDir}sfnt.c.o" \xB6 - "{ObjDir}smooth.c.o" \xB6 - "{ObjDir}truetype.c.o" \xB6 - "{ObjDir}type1.c.o" \xB6 - "{ObjDir}type42.c.o" \xB6 - "{ObjDir}winfnt.c.o" - - -### Libraries ### - -LibFiles-68K = - - -### Default Rules ### - -.c.o \xC4 .c {\xA5MondoBuild\xA5} - {C} {depDir}{default}.c -o {targDir}{default}.c.o {COptions} - - -### Build Rules ### - -:builds:mac:ftbase.c \xC4\xC4 :src:base:ftbase.c - Duplicate :src:base:ftbase.c :builds:mac:ftbase.c - -"{ObjDir}ftbase.c.o" \xC4\xC4 :builds:mac:ftbase.c - {C} :builds:mac:ftbase.c -o "{ObjDir}ftbase.c.o" \xB6 - -i :builds:mac: \xB6 - -i :src:base: \xB6 - {COptions} - -FreeType.m68k_cfm \xC4\xC4 FreeType.m68k_cfm.o - -FreeType.m68k_cfm.o \xC4\xC4 {ObjFiles-68K} {LibFiles-68K} {\xA5MondoBuild\xA5} - Lib \xB6 - -o {Targ} \xB6 - {ObjFiles-68K} \xB6 - {LibFiles-68K} \xB6 - {Sym-68K} \xB6 - -mf -d - - - -### Required Dependencies ### - -"{ObjDir}autofit.c.o" \xC4 :src:autofit:autofit.c -# "{ObjDir}ftbase.c.o" \xC4 :src:base:ftbase.c -"{ObjDir}ftbbox.c.o" \xC4 :src:base:ftbbox.c -"{ObjDir}ftbdf.c.o" \xC4 :src:base:ftbdf.c -"{ObjDir}ftbitmap.c.o" \xC4 :src:base:ftbitmap.c -"{ObjDir}ftdebug.c.o" \xC4 :src:base:ftdebug.c -"{ObjDir}ftfstype.c.o" \xC4 :src:base:ftfstype.c -"{ObjDir}ftglyph.c.o" \xC4 :src:base:ftglyph.c -"{ObjDir}ftgxval.c.o" \xC4 :src:base:ftgxval.c -"{ObjDir}ftinit.c.o" \xC4 :src:base:ftinit.c -"{ObjDir}ftmm.c.o" \xC4 :src:base:ftmm.c -"{ObjDir}ftotval.c.o" \xC4 :src:base:ftotval.c -"{ObjDir}ftpfr.c.o" \xC4 :src:base:ftpfr.c -"{ObjDir}ftstroke.c.o" \xC4 :src:base:ftstroke.c -"{ObjDir}ftsynth.c.o" \xC4 :src:base:ftsynth.c -"{ObjDir}ftsystem.c.o" \xC4 :src:base:ftsystem.c -"{ObjDir}fttype1.c.o" \xC4 :src:base:fttype1.c -"{ObjDir}ftwinfnt.c.o" \xC4 :src:base:ftwinfnt.c -"{ObjDir}ftcache.c.o" \xC4 :src:cache:ftcache.c -"{ObjDir}bdf.c.o" \xC4 :src:bdf:bdf.c -"{ObjDir}cff.c.o" \xC4 :src:cff:cff.c -"{ObjDir}type1cid.c.o" \xC4 :src:cid:type1cid.c -# "{ObjDir}gxvalid.c.o" \xC4 :src:gxvalid:gxvalid.c -"{ObjDir}ftgzip.c.o" \xC4 :src:gzip:ftgzip.c -"{ObjDir}ftbzip2.c.o" \xC4 :src:bzip2:ftbzip2.c -"{ObjDir}ftlzw.c.o" \xC4 :src:lzw:ftlzw.c -"{ObjDir}otvalid.c.o" \xC4 :src:otvalid:otvalid.c -"{ObjDir}pcf.c.o" \xC4 :src:pcf:pcf.c -"{ObjDir}pfr.c.o" \xC4 :src:pfr:pfr.c -"{ObjDir}psaux.c.o" \xC4 :src:psaux:psaux.c -"{ObjDir}pshinter.c.o" \xC4 :src:pshinter:pshinter.c -"{ObjDir}psmodule.c.o" \xC4 :src:psnames:psmodule.c -"{ObjDir}raster.c.o" \xC4 :src:raster:raster.c -"{ObjDir}sfnt.c.o" \xC4 :src:sfnt:sfnt.c -"{ObjDir}smooth.c.o" \xC4 :src:smooth:smooth.c -"{ObjDir}truetype.c.o" \xC4 :src:truetype:truetype.c -"{ObjDir}type1.c.o" \xC4 :src:type1:type1.c -"{ObjDir}type42.c.o" \xC4 :src:type42:type42.c -"{ObjDir}winfnt.c.o" \xC4 :src:winfonts:winfnt.c - - -### Optional Dependencies ### -### Build this target to generate "include file" dependencies. ### - -Dependencies \xC4 $OutOfDate - MakeDepend \xB6 - -append {MAKEFILE} \xB6 - -ignore "{CIncludes}" \xB6 - -objdir "{ObjDir}" \xB6 - -objext .o \xB6 - {Includes} \xB6 - {SrcFiles} - - diff --git a/freetype/builds/mac/FreeType.m68k_far.make.txt b/freetype/builds/mac/FreeType.m68k_far.make.txt deleted file mode 100644 index d880ddb..0000000 --- a/freetype/builds/mac/FreeType.m68k_far.make.txt +++ /dev/null @@ -1,208 +0,0 @@ -# File: FreeType.m68k_far.make -# Target: FreeType.m68k_far -# Created: Tuesday, October 25, 2005 03:34:05 PM - - -MAKEFILE = FreeType.m68k_far.make -\xA5MondoBuild\xA5 = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified - -ObjDir = :objs: -Includes = \xB6 - -includes unix \xB6 - -i :include: \xB6 - -i :src: \xB6 - -i :include:freetype:config: - -Sym-68K = -sym off - -COptions = \xB6 - -d FT_MACINTOSH=1 \xB6 - -d HAVE_FSSPEC=1 \xB6 - -d HAVE_FSREF=0 \xB6 - -d HAVE_QUICKDRAW_TOOLBOX=1 \xB6 - -d HAVE_QUICKDRAW_CARBON=0 \xB6 - -d HAVE_ATS=0 \xB6 - -d FT2_BUILD_LIBRARY \xB6 - -d FT_CONFIG_CONFIG_H="" \xB6 - -d FT_CONFIG_MODULES_H="" \xB6 - {Includes} {Sym-68K} -model far - - -### Source Files ### - -SrcFiles = \xB6 - :src:autofit:autofit.c \xB6 - :builds:mac:ftbase.c \xB6 - :src:base:ftbbox.c \xB6 - :src:base:ftbdf.c \xB6 - :src:base:ftbitmap.c \xB6 - :src:base:ftdebug.c \xB6 - :src:base:ftfstype.c \xB6 - :src:base:ftglyph.c \xB6 - :src:base:ftgxval.c \xB6 - :src:base:ftinit.c \xB6 - :src:base:ftmm.c \xB6 - :src:base:ftotval.c \xB6 - :src:base:ftpfr.c \xB6 - :src:base:ftstroke.c \xB6 - :src:base:ftsynth.c \xB6 - :src:base:ftsystem.c \xB6 - :src:base:fttype1.c \xB6 - :src:base:ftwinfnt.c \xB6 - :src:cache:ftcache.c \xB6 - :src:bdf:bdf.c \xB6 - :src:cff:cff.c \xB6 - :src:cid:type1cid.c \xB6 - :src:gxvalid:gxvalid.c \xB6 - :src:gzip:ftgzip.c \xB6 - :src:bzip2:ftbzip2.c \xB6 - :src:lzw:ftlzw.c \xB6 - :src:otvalid:otvalid.c \xB6 - :src:pcf:pcf.c \xB6 - :src:pfr:pfr.c \xB6 - :src:psaux:psaux.c \xB6 - :src:pshinter:pshinter.c \xB6 - :src:psnames:psmodule.c \xB6 - :src:raster:raster.c \xB6 - :src:sfnt:sfnt.c \xB6 - :src:smooth:smooth.c \xB6 - :src:truetype:truetype.c \xB6 - :src:type1:type1.c \xB6 - :src:type42:type42.c \xB6 - :src:winfonts:winfnt.c - - -### Object Files ### - -ObjFiles-68K = \xB6 - "{ObjDir}autofit.c.o" \xB6 - "{ObjDir}ftbase.c.o" \xB6 - "{ObjDir}ftbbox.c.o" \xB6 - "{ObjDir}ftbdf.c.o" \xB6 - "{ObjDir}ftbitmap.c.o" \xB6 - "{ObjDir}ftdebug.c.o" \xB6 - "{ObjDir}ftfstype.c.o" \xB6 - "{ObjDir}ftglyph.c.o" \xB6 - "{ObjDir}ftgxval.c.o" \xB6 - "{ObjDir}ftinit.c.o" \xB6 - "{ObjDir}ftmm.c.o" \xB6 - "{ObjDir}ftotval.c.o" \xB6 - "{ObjDir}ftpfr.c.o" \xB6 - "{ObjDir}ftstroke.c.o" \xB6 - "{ObjDir}ftsynth.c.o" \xB6 - "{ObjDir}ftsystem.c.o" \xB6 - "{ObjDir}fttype1.c.o" \xB6 - "{ObjDir}ftwinfnt.c.o" \xB6 - "{ObjDir}ftcache.c.o" \xB6 - "{ObjDir}bdf.c.o" \xB6 - "{ObjDir}cff.c.o" \xB6 - "{ObjDir}type1cid.c.o" \xB6 - "{ObjDir}gxvalid.c.o" \xB6 - "{ObjDir}ftgzip.c.o" \xB6 - "{ObjDir}ftbzip2.c.o" \xB6 - "{ObjDir}ftlzw.c.o" \xB6 - "{ObjDir}otvalid.c.o" \xB6 - "{ObjDir}pcf.c.o" \xB6 - "{ObjDir}pfr.c.o" \xB6 - "{ObjDir}psaux.c.o" \xB6 - "{ObjDir}pshinter.c.o" \xB6 - "{ObjDir}psmodule.c.o" \xB6 - "{ObjDir}raster.c.o" \xB6 - "{ObjDir}sfnt.c.o" \xB6 - "{ObjDir}smooth.c.o" \xB6 - "{ObjDir}truetype.c.o" \xB6 - "{ObjDir}type1.c.o" \xB6 - "{ObjDir}type42.c.o" \xB6 - "{ObjDir}winfnt.c.o" - - -### Libraries ### - -LibFiles-68K = - - -### Default Rules ### - -.c.o \xC4 .c {\xA5MondoBuild\xA5} - {C} {depDir}{default}.c -o {targDir}{default}.c.o {COptions} \xB6 - -ansi strict - -### Build Rules ### - -:builds:mac:ftbase.c \xC4\xC4 :src:base:ftbase.c - Duplicate :src:base:ftbase.c :builds:mac:ftbase.c - -"{ObjDir}ftbase.c.o" \xC4\xC4 :builds:mac:ftbase.c - {C} :builds:mac:ftbase.c -o "{ObjDir}ftbase.c.o" \xB6 - -i :builds:mac: \xB6 - -i :src:base: \xB6 - {COptions} - -FreeType.m68k_far \xC4\xC4 FreeType.m68k_far.o - -FreeType.m68k_far.o \xC4\xC4 {ObjFiles-68K} {LibFiles-68K} {\xA5MondoBuild\xA5} - Lib \xB6 - -o {Targ} \xB6 - {ObjFiles-68K} \xB6 - {LibFiles-68K} \xB6 - {Sym-68K} \xB6 - -mf -d - - - -### Required Dependencies ### - -"{ObjDir}autofit.c.o" \xC4 :src:autofit:autofit.c -# "{ObjDir}ftbase.c.o" \xC4 :src:base:ftbase.c -"{ObjDir}ftbbox.c.o" \xC4 :src:base:ftbbox.c -"{ObjDir}ftbdf.c.o" \xC4 :src:base:ftbdf.c -"{ObjDir}ftbitmap.c.o" \xC4 :src:base:ftbitmap.c -"{ObjDir}ftdebug.c.o" \xC4 :src:base:ftdebug.c -"{ObjDir}ftfstype.c.o" \xC4 :src:base:ftfstype.c -"{ObjDir}ftglyph.c.o" \xC4 :src:base:ftglyph.c -"{ObjDir}ftgxval.c.o" \xC4 :src:base:ftgxval.c -"{ObjDir}ftinit.c.o" \xC4 :src:base:ftinit.c -"{ObjDir}ftmm.c.o" \xC4 :src:base:ftmm.c -"{ObjDir}ftotval.c.o" \xC4 :src:base:ftotval.c -"{ObjDir}ftpfr.c.o" \xC4 :src:base:ftpfr.c -"{ObjDir}ftstroke.c.o" \xC4 :src:base:ftstroke.c -"{ObjDir}ftsynth.c.o" \xC4 :src:base:ftsynth.c -"{ObjDir}ftsystem.c.o" \xC4 :src:base:ftsystem.c -"{ObjDir}fttype1.c.o" \xC4 :src:base:fttype1.c -"{ObjDir}ftwinfnt.c.o" \xC4 :src:base:ftwinfnt.c -"{ObjDir}ftcache.c.o" \xC4 :src:cache:ftcache.c -"{ObjDir}bdf.c.o" \xC4 :src:bdf:bdf.c -"{ObjDir}cff.c.o" \xC4 :src:cff:cff.c -"{ObjDir}type1cid.c.o" \xC4 :src:cid:type1cid.c -"{ObjDir}gxvalid.c.o" \xC4 :src:gxvalid:gxvalid.c -"{ObjDir}ftgzip.c.o" \xC4 :src:gzip:ftgzip.c -"{ObjDir}ftbzip2.c.o" \xC4 :src:bzip2:ftbzip2.c -"{ObjDir}ftlzw.c.o" \xC4 :src:lzw:ftlzw.c -"{ObjDir}otvalid.c.o" \xC4 :src:otvalid:otvalid.c -"{ObjDir}pcf.c.o" \xC4 :src:pcf:pcf.c -"{ObjDir}pfr.c.o" \xC4 :src:pfr:pfr.c -"{ObjDir}psaux.c.o" \xC4 :src:psaux:psaux.c -"{ObjDir}pshinter.c.o" \xC4 :src:pshinter:pshinter.c -"{ObjDir}psmodule.c.o" \xC4 :src:psnames:psmodule.c -"{ObjDir}raster.c.o" \xC4 :src:raster:raster.c -"{ObjDir}sfnt.c.o" \xC4 :src:sfnt:sfnt.c -"{ObjDir}smooth.c.o" \xC4 :src:smooth:smooth.c -"{ObjDir}truetype.c.o" \xC4 :src:truetype:truetype.c -"{ObjDir}type1.c.o" \xC4 :src:type1:type1.c -"{ObjDir}type42.c.o" \xC4 :src:type42:type42.c -"{ObjDir}winfnt.c.o" \xC4 :src:winfonts:winfnt.c - - -### Optional Dependencies ### -### Build this target to generate "include file" dependencies. ### - -Dependencies \xC4 $OutOfDate - MakeDepend \xB6 - -append {MAKEFILE} \xB6 - -ignore "{CIncludes}" \xB6 - -objdir "{ObjDir}" \xB6 - -objext .o \xB6 - {Includes} \xB6 - {SrcFiles} - - diff --git a/freetype/builds/mac/FreeType.ppc_carbon.make.txt b/freetype/builds/mac/FreeType.ppc_carbon.make.txt deleted file mode 100644 index 1fa8c30..0000000 --- a/freetype/builds/mac/FreeType.ppc_carbon.make.txt +++ /dev/null @@ -1,212 +0,0 @@ -# File: FreeType.ppc_carbon.make -# Target: FreeType.ppc_carbon -# Created: Friday, October 28, 2005 03:40:06 PM - - -MAKEFILE = FreeType.ppc_carbon.make -\xA5MondoBuild\xA5 = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified - -ObjDir = :objs: -Includes = \xB6 - -ansi strict \xB6 - -includes unix \xB6 - -i :include: \xB6 - -i :src: \xB6 - -i :include:freetype:config: - -Sym-PPC = -sym off - -PPCCOptions = \xB6 - -d FT_MACINTOSH=1 \xB6 - -d HAVE_FSSPEC=1 \xB6 - -d HAVE_FSREF=1 \xB6 - -d HAVE_QUICKDRAW_TOOLBOX=1 \xB6 - -d HAVE_QUICKDRAW_CARBON=1 \xB6 - -d HAVE_ATS=0 \xB6 - -d FT2_BUILD_LIBRARY \xB6 - -d FT_CONFIG_CONFIG_H="" \xB6 - -d FT_CONFIG_MODULES_H="" \xB6 - {Includes} {Sym-PPC} -d TARGET_API_MAC_CARBON=1 - - -### Source Files ### - -SrcFiles = \xB6 - :src:autofit:autofit.c \xB6 - :builds:mac:ftbase.c \xB6 - :src:base:ftbbox.c \xB6 - :src:base:ftbdf.c \xB6 - :src:base:ftbitmap.c \xB6 - :src:base:ftdebug.c \xB6 - :src:base:ftfstype.c \xB6 - :src:base:ftglyph.c \xB6 - :src:base:ftgxval.c \xB6 - :src:base:ftinit.c \xB6 - :src:base:ftmm.c \xB6 - :src:base:ftotval.c \xB6 - :src:base:ftpfr.c \xB6 - :src:base:ftstroke.c \xB6 - :src:base:ftsynth.c \xB6 - :src:base:ftsystem.c \xB6 - :src:base:fttype1.c \xB6 - :src:base:ftwinfnt.c \xB6 - :src:cache:ftcache.c \xB6 - :src:bdf:bdf.c \xB6 - :src:cff:cff.c \xB6 - :src:cid:type1cid.c \xB6 - :src:gxvalid:gxvalid.c \xB6 - :src:gzip:ftgzip.c \xB6 - :src:bzip2:ftbzip2.c \xB6 - :src:lzw:ftlzw.c \xB6 - :src:otvalid:otvalid.c \xB6 - :src:pcf:pcf.c \xB6 - :src:pfr:pfr.c \xB6 - :src:psaux:psaux.c \xB6 - :src:pshinter:pshinter.c \xB6 - :src:psnames:psmodule.c \xB6 - :src:raster:raster.c \xB6 - :src:sfnt:sfnt.c \xB6 - :src:smooth:smooth.c \xB6 - :src:truetype:truetype.c \xB6 - :src:type1:type1.c \xB6 - :src:type42:type42.c \xB6 - :src:winfonts:winfnt.c - - -### Object Files ### - -ObjFiles-PPC = \xB6 - "{ObjDir}autofit.c.x" \xB6 - "{ObjDir}ftbase.c.x" \xB6 - "{ObjDir}ftbbox.c.x" \xB6 - "{ObjDir}ftbdf.c.x" \xB6 - "{ObjDir}ftbitmap.c.x" \xB6 - "{ObjDir}ftdebug.c.x" \xB6 - "{ObjDir}ftfstype.c.x" \xB6 - "{ObjDir}ftglyph.c.x" \xB6 - "{ObjDir}ftgxval.c.x" \xB6 - "{ObjDir}ftinit.c.x" \xB6 - "{ObjDir}ftmm.c.x" \xB6 - "{ObjDir}ftotval.c.x" \xB6 - "{ObjDir}ftpfr.c.x" \xB6 - "{ObjDir}ftstroke.c.x" \xB6 - "{ObjDir}ftsynth.c.x" \xB6 - "{ObjDir}ftsystem.c.x" \xB6 - "{ObjDir}fttype1.c.x" \xB6 - "{ObjDir}ftwinfnt.c.x" \xB6 - "{ObjDir}ftcache.c.x" \xB6 - "{ObjDir}bdf.c.x" \xB6 - "{ObjDir}cff.c.x" \xB6 - "{ObjDir}type1cid.c.x" \xB6 - "{ObjDir}gxvalid.c.x" \xB6 - "{ObjDir}ftgzip.c.x" \xB6 - "{ObjDir}ftbzip2.c.x" \xB6 - "{ObjDir}ftlzw.c.x" \xB6 - "{ObjDir}otvalid.c.x" \xB6 - "{ObjDir}pcf.c.x" \xB6 - "{ObjDir}pfr.c.x" \xB6 - "{ObjDir}psaux.c.x" \xB6 - "{ObjDir}pshinter.c.x" \xB6 - "{ObjDir}psmodule.c.x" \xB6 - "{ObjDir}raster.c.x" \xB6 - "{ObjDir}sfnt.c.x" \xB6 - "{ObjDir}smooth.c.x" \xB6 - "{ObjDir}truetype.c.x" \xB6 - "{ObjDir}type1.c.x" \xB6 - "{ObjDir}type42.c.x" \xB6 - "{ObjDir}winfnt.c.x" - - -### Libraries ### - -LibFiles-PPC = - - -### Default Rules ### - -.c.x \xC4 .c {\xA5MondoBuild\xA5} - {PPCC} {depDir}{default}.c -o {targDir}{default}.c.x {PPCCOptions} - - -### Build Rules ### - -:builds:mac:ftbase.c \xC4\xC4 :src:base:ftbase.c - Duplicate :src:base:ftbase.c :builds:mac:ftbase.c - -"{ObjDir}ftbase.c.x" \xC4\xC4 :builds:mac:ftbase.c - {PPCC} :builds:mac:ftbase.c -o {ObjDir}ftbase.c.x \xB6 - -i :builds:mac: \xB6 - -i :src:base: \xB6 - {PPCCOptions} - -FreeType.ppc_carbon \xC4\xC4 FreeType.ppc_carbon.o - -FreeType.ppc_carbon.o \xC4\xC4 {ObjFiles-PPC} {LibFiles-PPC} {\xA5MondoBuild\xA5} - PPCLink \xB6 - -o {Targ} \xB6 - {ObjFiles-PPC} \xB6 - {LibFiles-PPC} \xB6 - {Sym-PPC} \xB6 - -mf -d \xB6 - -t 'XCOF' \xB6 - -c 'MPS ' \xB6 - -xm l - - - -### Required Dependencies ### - -"{ObjDir}autofit.c.x" \xC4 :src:autofit:autofit.c -# "{ObjDir}ftbase.c.x" \xC4 :builds:mac:ftbase.c -"{ObjDir}ftbbox.c.x" \xC4 :src:base:ftbbox.c -"{ObjDir}ftbdf.c.x" \xC4 :src:base:ftbdf.c -"{ObjDir}ftbitmap.c.x" \xC4 :src:base:ftbitmap.c -"{ObjDir}ftdebug.c.x" \xC4 :src:base:ftdebug.c -"{ObjDir}ftfstype.c.x" \xC4 :src:base:ftfstype.c -"{ObjDir}ftglyph.c.x" \xC4 :src:base:ftglyph.c -"{ObjDir}ftgxval.c.x" \xC4 :src:base:ftgxval.c -"{ObjDir}ftinit.c.x" \xC4 :src:base:ftinit.c -"{ObjDir}ftmm.c.x" \xC4 :src:base:ftmm.c -"{ObjDir}ftotval.c.x" \xC4 :src:base:ftotval.c -"{ObjDir}ftpfr.c.x" \xC4 :src:base:ftpfr.c -"{ObjDir}ftstroke.c.x" \xC4 :src:base:ftstroke.c -"{ObjDir}ftsynth.c.x" \xC4 :src:base:ftsynth.c -"{ObjDir}ftsystem.c.x" \xC4 :src:base:ftsystem.c -"{ObjDir}fttype1.c.x" \xC4 :src:base:fttype1.c -"{ObjDir}ftwinfnt.c.x" \xC4 :src:base:ftwinfnt.c -"{ObjDir}ftcache.c.x" \xC4 :src:cache:ftcache.c -"{ObjDir}bdf.c.x" \xC4 :src:bdf:bdf.c -"{ObjDir}cff.c.x" \xC4 :src:cff:cff.c -"{ObjDir}type1cid.c.x" \xC4 :src:cid:type1cid.c -"{ObjDir}gxvalid.c.x" \xC4 :src:gxvalid:gxvalid.c -"{ObjDir}ftgzip.c.x" \xC4 :src:gzip:ftgzip.c -"{ObjDir}ftbzip2.c.x" \xC4 :src:bzip2:ftbzip2.c -"{ObjDir}ftlzw.c.x" \xC4 :src:lzw:ftlzw.c -"{ObjDir}otvalid.c.x" \xC4 :src:otvalid:otvalid.c -"{ObjDir}pcf.c.x" \xC4 :src:pcf:pcf.c -"{ObjDir}pfr.c.x" \xC4 :src:pfr:pfr.c -"{ObjDir}psaux.c.x" \xC4 :src:psaux:psaux.c -"{ObjDir}pshinter.c.x" \xC4 :src:pshinter:pshinter.c -"{ObjDir}psmodule.c.x" \xC4 :src:psnames:psmodule.c -"{ObjDir}raster.c.x" \xC4 :src:raster:raster.c -"{ObjDir}sfnt.c.x" \xC4 :src:sfnt:sfnt.c -"{ObjDir}smooth.c.x" \xC4 :src:smooth:smooth.c -"{ObjDir}truetype.c.x" \xC4 :src:truetype:truetype.c -"{ObjDir}type1.c.x" \xC4 :src:type1:type1.c -"{ObjDir}type42.c.x" \xC4 :src:type42:type42.c -"{ObjDir}winfnt.c.x" \xC4 :src:winfonts:winfnt.c - - -### Optional Dependencies ### -### Build this target to generate "include file" dependencies. ### - -Dependencies \xC4 $OutOfDate - MakeDepend \xB6 - -append {MAKEFILE} \xB6 - -ignore "{CIncludes}" \xB6 - -objdir "{ObjDir}" \xB6 - -objext .x \xB6 - {Includes} \xB6 - {SrcFiles} - - diff --git a/freetype/builds/mac/FreeType.ppc_classic.make.txt b/freetype/builds/mac/FreeType.ppc_classic.make.txt deleted file mode 100644 index 2550190..0000000 --- a/freetype/builds/mac/FreeType.ppc_classic.make.txt +++ /dev/null @@ -1,213 +0,0 @@ -# File: FreeType.ppc_classic.make -# Target: FreeType.ppc_classic -# Created: Thursday, October 27, 2005 07:42:43 PM - - -MAKEFILE = FreeType.ppc_classic.make -\xA5MondoBuild\xA5 = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified - -ObjDir = :objs: -Includes = \xB6 - -ansi strict \xB6 - -includes unix \xB6 - -i :include: \xB6 - -i :src: \xB6 - -i :include:freetype:config: - -Sym-PPC = -sym off - -PPCCOptions = \xB6 - -d FT_MACINTOSH=1 \xB6 - -d HAVE_FSSPEC=1 \xB6 - -d HAVE_FSREF=0 \xB6 - -d HAVE_QUICKDRAW_TOOLBOX=1 \xB6 - -d HAVE_QUICKDRAW_CARBON=0 \xB6 - -d HAVE_ATS=0 \xB6 - -d FT2_BUILD_LIBRARY \xB6 - -d FT_CONFIG_CONFIG_H="" \xB6 - -d FT_CONFIG_MODULES_H="" \xB6 - {Includes} {Sym-PPC} - - -### Source Files ### - -SrcFiles = \xB6 - :src:autofit:autofit.c \xB6 - :builds:mac:ftbase.c \xB6 - :src:base:ftbbox.c \xB6 - :src:base:ftbdf.c \xB6 - :src:base:ftbitmap.c \xB6 - :src:base:ftdebug.c \xB6 - :src:base:ftfstype.c \xB6 - :src:base:ftglyph.c \xB6 - :src:base:ftgxval.c \xB6 - :src:base:ftinit.c \xB6 - :src:base:ftmm.c \xB6 - :src:base:ftotval.c \xB6 - :src:base:ftpfr.c \xB6 - :src:base:ftstroke.c \xB6 - :src:base:ftsynth.c \xB6 - :src:base:ftsystem.c \xB6 - :src:base:fttype1.c \xB6 - :src:base:ftwinfnt.c \xB6 - :src:cache:ftcache.c \xB6 - :src:bdf:bdf.c \xB6 - :src:cff:cff.c \xB6 - :src:cid:type1cid.c \xB6 - :src:gxvalid:gxvalid.c \xB6 - :src:gzip:ftgzip.c \xB6 - :src:bzip2:ftbzip2.c \xB6 - :src:lzw:ftlzw.c \xB6 - :src:otvalid:otvalid.c \xB6 - :src:pcf:pcf.c \xB6 - :src:pfr:pfr.c \xB6 - :src:psaux:psaux.c \xB6 - :src:pshinter:pshinter.c \xB6 - :src:psnames:psmodule.c \xB6 - :src:raster:raster.c \xB6 - :src:sfnt:sfnt.c \xB6 - :src:smooth:smooth.c \xB6 - :src:truetype:truetype.c \xB6 - :src:type1:type1.c \xB6 - :src:type42:type42.c \xB6 - :src:winfonts:winfnt.c - - -### Object Files ### - -ObjFiles-PPC = \xB6 - "{ObjDir}autofit.c.x" \xB6 - "{ObjDir}ftbase.c.x" \xB6 - "{ObjDir}ftbbox.c.x" \xB6 - "{ObjDir}ftbdf.c.x" \xB6 - "{ObjDir}ftbitmap.c.x" \xB6 - "{ObjDir}ftdebug.c.x" \xB6 - "{ObjDir}ftfstype.c.x" \xB6 - "{ObjDir}ftglyph.c.x" \xB6 - "{ObjDir}ftgxval.c.x" \xB6 - "{ObjDir}ftinit.c.x" \xB6 - "{ObjDir}ftmm.c.x" \xB6 - "{ObjDir}ftotval.c.x" \xB6 - "{ObjDir}ftpfr.c.x" \xB6 - "{ObjDir}ftstroke.c.x" \xB6 - "{ObjDir}ftsynth.c.x" \xB6 - "{ObjDir}ftsystem.c.x" \xB6 - "{ObjDir}fttype1.c.x" \xB6 - "{ObjDir}ftwinfnt.c.x" \xB6 - "{ObjDir}ftcache.c.x" \xB6 - "{ObjDir}bdf.c.x" \xB6 - "{ObjDir}cff.c.x" \xB6 - "{ObjDir}type1cid.c.x" \xB6 - "{ObjDir}gxvalid.c.x" \xB6 - "{ObjDir}ftgzip.c.x" \xB6 - "{ObjDir}ftbzip2.c.x" \xB6 - "{ObjDir}ftlzw.c.x" \xB6 - "{ObjDir}otvalid.c.x" \xB6 - "{ObjDir}pcf.c.x" \xB6 - "{ObjDir}pfr.c.x" \xB6 - "{ObjDir}psaux.c.x" \xB6 - "{ObjDir}pshinter.c.x" \xB6 - "{ObjDir}psmodule.c.x" \xB6 - "{ObjDir}raster.c.x" \xB6 - "{ObjDir}sfnt.c.x" \xB6 - "{ObjDir}smooth.c.x" \xB6 - "{ObjDir}truetype.c.x" \xB6 - "{ObjDir}type1.c.x" \xB6 - "{ObjDir}type42.c.x" \xB6 - "{ObjDir}winfnt.c.x" - - -### Libraries ### - -LibFiles-PPC = - - -### Default Rules ### - -.c.x \xC4 .c {\xA5MondoBuild\xA5} - {PPCC} {depDir}{default}.c -o {targDir}{default}.c.x {PPCCOptions} - - -### Build Rules ### - -:builds:mac:ftbase.c \xC4\xC4 :src:base:ftbase.c - Duplicate :src:base:ftbase.c :builds:mac:ftbase.c - -"{ObjDir}ftbase.c.x" \xC4\xC4 :builds:mac:ftbase.c - {PPCC} :builds:mac:ftbase.c -o "{ObjDir}ftbase.c.x" \xB6 - -i :builds:mac: \xB6 - -i :src:base: \xB6 - {PPCCOptions} - -FreeType.ppc_classic \xC4\xC4 FreeType.ppc_classic.o - -FreeType.ppc_classic.o \xC4\xC4 {ObjFiles-PPC} {LibFiles-PPC} {\xA5MondoBuild\xA5} - PPCLink \xB6 - -o {Targ} \xB6 - {ObjFiles-PPC} \xB6 - {LibFiles-PPC} \xB6 - {Sym-PPC} \xB6 - -mf -d \xB6 - -t 'XCOF' \xB6 - -c 'MPS ' \xB6 - -xm l - - - -### Required Dependencies ### - -"{ObjDir}autofit.c.x" \xC4 :src:autofit:autofit.c -# "{ObjDir}ftbase.c.x" \xC4 :builds:mac:ftbase.c -"{ObjDir}ftbbox.c.x" \xC4 :src:base:ftbbox.c -"{ObjDir}ftbdf.c.x" \xC4 :src:base:ftbdf.c -"{ObjDir}ftbitmap.c.x" \xC4 :src:base:ftbitmap.c -"{ObjDir}ftdebug.c.x" \xC4 :src:base:ftdebug.c -"{ObjDir}ftfstype.c.x" \xC4 :src:base:ftfstype.c -"{ObjDir}ftglyph.c.x" \xC4 :src:base:ftglyph.c -"{ObjDir}ftgxval.c.x" \xC4 :src:base:ftgxval.c -"{ObjDir}ftinit.c.x" \xC4 :src:base:ftinit.c -"{ObjDir}ftmm.c.x" \xC4 :src:base:ftmm.c -"{ObjDir}ftotval.c.x" \xC4 :src:base:ftotval.c -"{ObjDir}ftpfr.c.x" \xC4 :src:base:ftpfr.c -"{ObjDir}ftstroke.c.x" \xC4 :src:base:ftstroke.c -"{ObjDir}ftsynth.c.x" \xC4 :src:base:ftsynth.c -"{ObjDir}ftsystem.c.x" \xC4 :src:base:ftsystem.c -"{ObjDir}fttype1.c.x" \xC4 :src:base:fttype1.c -"{ObjDir}ftwinfnt.c.x" \xC4 :src:base:ftwinfnt.c -"{ObjDir}ftcache.c.x" \xC4 :src:cache:ftcache.c -"{ObjDir}bdf.c.x" \xC4 :src:bdf:bdf.c -"{ObjDir}cff.c.x" \xC4 :src:cff:cff.c -"{ObjDir}type1cid.c.x" \xC4 :src:cid:type1cid.c -"{ObjDir}gxvalid.c.x" \xC4 :src:gxvalid:gxvalid.c -"{ObjDir}ftgzip.c.x" \xC4 :src:gzip:ftgzip.c -"{ObjDir}ftbzip2.c.x" \xC4 :src:bzip2:ftbzip2.c -"{ObjDir}ftlzw.c.x" \xC4 :src:lzw:ftlzw.c -"{ObjDir}otvalid.c.x" \xC4 :src:otvalid:otvalid.c -"{ObjDir}pcf.c.x" \xC4 :src:pcf:pcf.c -"{ObjDir}pfr.c.x" \xC4 :src:pfr:pfr.c -"{ObjDir}psaux.c.x" \xC4 :src:psaux:psaux.c -"{ObjDir}pshinter.c.x" \xC4 :src:pshinter:pshinter.c -"{ObjDir}psmodule.c.x" \xC4 :src:psnames:psmodule.c -"{ObjDir}raster.c.x" \xC4 :src:raster:raster.c -"{ObjDir}sfnt.c.x" \xC4 :src:sfnt:sfnt.c -"{ObjDir}smooth.c.x" \xC4 :src:smooth:smooth.c -"{ObjDir}truetype.c.x" \xC4 :src:truetype:truetype.c -"{ObjDir}type1.c.x" \xC4 :src:type1:type1.c -"{ObjDir}type42.c.x" \xC4 :src:type42:type42.c -"{ObjDir}winfnt.c.x" \xC4 :src:winfonts:winfnt.c - - - -### Optional Dependencies ### -### Build this target to generate "include file" dependencies. ### - -Dependencies \xC4 $OutOfDate - MakeDepend \xB6 - -append {MAKEFILE} \xB6 - -ignore "{CIncludes}" \xB6 - -objdir "{ObjDir}" \xB6 - -objext .x \xB6 - {Includes} \xB6 - {SrcFiles} - - diff --git a/freetype/builds/mac/README b/freetype/builds/mac/README deleted file mode 100644 index 06e3d51..0000000 --- a/freetype/builds/mac/README +++ /dev/null @@ -1,393 +0,0 @@ -This folder contains - - * Makefile skeletons for Apple MPW (Macintosh's Programmer's Workshop) - - * Python script to generate MPW makefile from skeleton - - * Metrowerks CodeWarrior 9.0 project file in XML format - ------------------------------------------------------------- - -1. What is this ---------------- - -Files in this directory are designed to build FreeType -running on classic MacOS. To build FreeType running on -Mac OS X, build as the system is UNIX. - -However, Mac OS X is most useful to manipulate files in -vanilla FreeType to fit classic MacOS. - -The information about MacOS specific API is written in -appendix of this document. - -2. Requirement --------------- - -You can use MPW: a free-charged developer environment -by Apple, or CodeWarrior: a commercial developer -environment by Metrowerks. GCC for MPW and Symantec -"Think C" are not tested at present. - - - 2-1. Apple MPW - -------------- - - Following C compilers are tested: - - m68k target: Apple SC 8.9.0d3e1 - ppc target: Apple MrC 5.0.0d3c1 - - The final MPW-GM (official release on 1999/Dec) is too - old and cannot compile FreeType, because bundled C - compilers cannot search header files in sub directories. - Updating by the final MPW-PR (pre-release on 2001/Feb) - is required. - - Required files are downloadable from: - - http://macintoshgarden.org/apps/macintosh-programmers-workshop - - Also you can find documents how to update by MPW-PR. - - Python is required to restore MPW makefiles from the - skeletons. Python bundled to Mac OS X is enough. For - classic MacOS, MacPython is available: - - https://homepages.cwi.nl/~jack/macpython/ - - MPW requires all files are typed by resource fork. - ResEdit bundled to MPW is enough. In Mac OS X, - /Developer/Tools/SetFile of DevTool is useful to - manipulate from commandline. - - 2-2. Metrowerks CodeWarrior - --------------------------- - - XML project file is generated and tested by - CodeWarrior 9.0. Older versions are not tested - at all. At present, static library for ppc target - is available in the project file. - - -3. How to build ---------------- - - 3-1. Apple MPW - -------------- - Detailed building procedure by Apple MPW is - described in following. - - 3-1-1. Generate MPW makefiles from the skeletons - ------------------------------------------------ - - Here are 4 skeletons for following targets are - included. - - - FreeType.m68k_far.make.txt - Ancient 32bit binary executable format for - m68k MacOS: System 6, with 32bit addressing - mode (far-pointer-model) So-called "Toolbox" - API is used. - - - FreeType.m68k_cfm.make.txt - CFM binary executable format for m68k MacOS: - System 7. So-called "Toolbox" API is used. - - - FreeType.ppc_classic.make.txt - CFM binary executable format for ppc MacOS: - System 7, MacOS 8, MacOS 9. So-called "Toolbox" - API is used. - - - FreeType.ppc_carbon.make.txt - CFM binary executable format for ppc MacOS: - MacOS 9. Carbon API is used. - - At present, static library is only supported, - although targets except of m68k_far are capable - to use shared library. - - MPW makefile syntax uses 8bit characters. To keep - from violating them during version control, here - we store skeletons in pure ASCII format. You must - generate MPW makefile by Python script ascii2mpw.py. - - In Mac OS X terminal, you can convert as: - - python builds/mac/ascii2mpw.py \ - < builds/mac/FreeType.m68k_far.make.txt \ - > FreeType.m68k_far.make - - The skeletons are designed to use in the top - directory where there are builds, include, src etc. - You must name the generated MPW makefile by removing - ".txt" from source skeleton name. - - 3-1-2. Add resource forks to related files - ------------------------------------------ - - MPW's Make and C compilers cannot recognize files - without resource fork. You have to add resource - fork to the files that MPW uses. In Mac OS X - terminal of the system, you can do as: - - find . -name '*.[ch]' -exec \ - /Developer/Tools/SetFile -a l -c "MPS " -t TEXT \{\} \; - - find . -name '*.make' -exec \ - /Developer/Tools/SetFile -a l -c "MPS " -t TEXT \{\} \; - - - 3-1-3. Open MPW shell and build - ------------------------------- - - Open MPW shell and go to the top directory that - FreeType sources are extracted (MPW makefile must - be located in there), from "Set Directory" in - "Directory" menu. - - Choose "Build" from "Build" menu, and type the - name of project by removing ".make" from MPW - makefile, as: FreeType.m68k_far - - If building is successfully finished, you can find - built library in objs/ directory. - - - 3-2. Metrowerks CodeWarrior - --------------------------- - - Detailed building procedure by Metrowerks - CodeWarrior (CW) 9.0 is described in following. - - 3-2-1. Import XML project file - ------------------------------ - - CW XML project file is not ready for double- - click. Start CodeWarrior IDE, and choose - "Import project" in "File" menu. Choose XML - project file: builds/mac/ftlib.prj.xml. - In next, you will be asked where to save CW - native project file: you must choose - "builds/mac/ftlib.prj". The project file is - designed with relative path from there. After - CW native project file is generated, it is - automatically loaded, small project window - titled "ftlib.prj" is displayed. - - 3-2-2. Building - --------------- - Choose "Make" from "Project" menu. If building - is successfully finished, you can find built - library at objs/FreeTypeLib. - -4. TODO -------- - - 4-1. All modules should be included - ----------------------------------- - - At present, MPW makefiles and CW project file are - just updated versions of these by Leonard. Some - modules are added after the last maintenance, they - are not included. - - 4-2. Working test with ftdemos - ------------------------------ - - At present, MPW makefiles and CW project file can - build FreeType for classic MacOS. But their working - behaviours are not tested at all. Building ftdemos - for classic MacOS and working test is required. - - -APPENDIX I ----------- - - A-1. Framework dependencies - --------------------------- - - src/base/ftmac.c adds two Mac-specific features to - FreeType. These features are based on MacOS libraries. - - * accessing resource-fork font - The fonts for classic MacOS store their graphical data - in resource forks which cannot be accessed via ANSI C - functions. FreeType2 provides functions to handle such - resource fork fonts, they are based on File Manager - framework of MacOS. In addition, HFS and HFS+ file - system driver of Linux is supported. Following - functions are for this purpose. - - FT_New_Face_From_Resource() - FT_New_Face_From_FSSpec() - FT_New_Face_From_FSRef() - - * resolving font name to font file - The font menu of MacOS application prefers font name - written in FOND resource than sfnt resource. FreeType2 - provides functions to find font file by name in MacOS - application, they are based on QuickDraw Font Manager - and Apple Type Service framework of MacOS. - - FT_GetFile_From_Mac_Name() - FT_GetFile_From_Mac_ATS_Name() - - Working functions for each MacOS are summarized as - following. - - upto MacOS 6: - not tested (you have to obtain MPW 2.x) - - MacOS 7.x, 8.x, 9.x (without CarbonLib): - FT_GetFile_From_Mac_Name() - FT_New_Face_From_Resource() - FT_New_Face_From_FSSpec() - - MacOS 9.x (with CarbonLib): - FT_GetFile_From_Mac_Name() - FT_New_Face_From_Resource() - FT_New_Face_From_FSSpec() - FT_New_Face_From_FSRef() - - Mac OS X upto 10.4.x: - FT_GetFile_From_Mac_Name() deprecated - FT_New_Face_From_FSSpec() deprecated - FT_GetFile_From_Mac_ATS_Name() deprecated? - FT_New_Face_From_FSRef() - - A-2. Deprecated Functions - ------------------------- - - A-2-1. FileManager - ------------------ - - For convenience to write MacOS application, ftmac.c - provides functions to specify a file by FSSpec and FSRef, - because the file identification pathname had ever been - unrecommended method in MacOS programming. - - Toward to MacOS X 10.4 & 5, Carbon functions using FSSpec - datatype is noticed as deprecated, and recommended to - migrate to FSRef datatype. The big differences of FSRef - against FSSpec are explained in Apple TechNotes 2078. - - https://developer.apple.com/library/archive/technotes/tn2078/ - - - filename length: the max length of file - name of FSRef is 255 chars (it is limit of HFS+), - that of FSSpec is 31 chars (it is limit of HFS). - - - filename encoding: FSSpec is localized by - legacy encoding for each language system, - FSRef is Unicode enabled. - - A-2-2. FontManager - ------------------ - - Following functions receive QuickDraw fontname: - - FT_GetFile_From_Mac_Name() - - QuickDraw is deprecated and replaced by Quartz - since Mac OS X 10.4. They are still kept for - backward compatibility. By undefinition of - HAVE_QUICKDRAW in building, you can change these - functions to return FT_Err_Unimplemented always. - - Replacement functions are added for migration. - - FT_GetFile_From_Mac_ATS_Name() - - They are usable on Mac OS X only. On older systems, - these functions return FT_Err_Unimplemented always. - - The detailed incompatibilities and possibility - of FontManager emulation without QuickDraw is - explained in - - http://gyvern.ipc.hiroshima-u.ac.jp/~mpsuzuki/ats_benchmark.html - - A-3. Framework Availabilities - ----------------------------- - - The framework of MacOS are often revised, especially - when new format of binary executable is introduced. - Following table is the minimum version of frameworks - to use functions used in FreeType2. The table is - extracted from MPW header files for assembly language. - - *** NOTE *** - The conditional definition of available data type - in MPW compiler is insufficient. You can compile - program using FSRef data type for older systems - (MacOS 7, 8) that don't know FSRef data type. - - - +-------------------+-----------------------------+ - CPU | mc680x0 | PowerPC | - +---------+---------+---------+---------+---------+ - Binary Executable Format | Classic | 68K-CFM | CFM | CFM | Mach-O | - +---------+---------+---------+---------+---------+ - Framework API | Toolbox | Toolbox | Toolbox | Carbon | Carbon | - +---------+---------+---------+---------+---------+ - - +---------+---------+---------+---------+---------+ - | ?(*) |Interface|Interface|CarbonLib|Mac OS X | - | |Lib |Lib | | | -* Files.h +---------+---------+---------+---------+---------+ -PBGetFCBInfoSync() | o | 7.1- | 7.1- | 1.0- | o | -FSMakeFSSpec() | o | 7.1- | 7.1- | 1.0- | o | -FSGetForkCBInfo() | o | (**) | 9.0- | 1.0- | o | -FSpMakeFSRef() | o | (**) | 9.0- | 1.0- | o | -FSGetCatalogInfo() | o | (**) | 9.0- | 1.0- | -10.3 | -FSPathMakeRef() | x | x | x | 1.1- | -10.3 | - +---------+---------+---------+---------+---------+ - - +---------+---------+---------+---------+---------+ - | ?(*) |Font |Font |CarbonLib|Mac OS X | - | |Manager |Manager | | | -* Fonts.h +---------+---------+---------+---------+---------+ -FMCreateFontFamilyIterator() | x | x | 9.0- | 1.0- | -10.3 | -FMDisposeFontFamilyIterator() | x | x | 9.0- | 1.0- | -10.3 | -FMGetNextFontFamily() | x | x | 9.0- | 1.0- | -10.3 | -FMGetFontFamilyName() | x | x | 9.0- | 1.0- | -10.3 | -FMCreateFontFamilyInstanceIterator() | x | x | 9.0- | 1.0- | -10.3 | -FMDisposeFontFamilyInstanceIterator() | x | x | 9.0- | 1.0- | -10.3 | -FMGetNextFontFamilyInstance() | x | x | 9.0- | 1.0- | -10.3 | - +---------+---------+---------+---------+---------+ - - +---------+---------+---------+---------+---------+ - | - | - | - |CarbonLib|Mac OS X | -* ATSFont.h (***) +---------+---------+---------+---------+---------+ -ATSFontFindFromName() | x | x | x | x | o | -ATSFontGetFileSpecification() | x | x | x | x | o | - +---------+---------+---------+---------+---------+ - - (*) - In the "Classic": the original binary executable - format, these framework functions are directly - transformed to MacOS system call. Therefore, the - exact availability should be checked by running - system. - - (**) - InterfaceLib is bundled to MacOS and its version - is usually equal to MacOS. There's no separate - update for InterfaceLib. It is supposed that - there's no InterfaceLib 9.x for m68k platforms. - In fact, these functions are FSRef dependent. - - (***) - ATSUI framework is available on ATSUnicode 8.5 on - ppc Toolbox CFM, CarbonLib 1.0 too. But its base: - ATS font manager is not published in these versions. - ------------------------------------------------------------- -Last update: 2013-Nov-03. - -Currently maintained by - suzuki toshiya, -Originally prepared by - Leonard Rosenthol, - Just van Rossum, diff --git a/freetype/builds/mac/ascii2mpw.py b/freetype/builds/mac/ascii2mpw.py deleted file mode 100644 index ad32b21..0000000 --- a/freetype/builds/mac/ascii2mpw.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python -import sys -import string - -if len( sys.argv ) == 1 : - for asc_line in sys.stdin.readlines(): - mpw_line = string.replace(asc_line, "\\xA5", "\245") - mpw_line = string.replace(mpw_line, "\\xB6", "\266") - mpw_line = string.replace(mpw_line, "\\xC4", "\304") - mpw_line = string.replace(mpw_line, "\\xC5", "\305") - mpw_line = string.replace(mpw_line, "\\xFF", "\377") - mpw_line = string.replace(mpw_line, "\n", "\r") - mpw_line = string.replace(mpw_line, "\\n", "\n") - sys.stdout.write(mpw_line) -elif sys.argv[1] == "-r" : - for mpw_line in sys.stdin.readlines(): - asc_line = string.replace(mpw_line, "\n", "\\n") - asc_line = string.replace(asc_line, "\r", "\n") - asc_line = string.replace(asc_line, "\245", "\\xA5") - asc_line = string.replace(asc_line, "\266", "\\xB6") - asc_line = string.replace(asc_line, "\304", "\\xC4") - asc_line = string.replace(asc_line, "\305", "\\xC5") - asc_line = string.replace(asc_line, "\377", "\\xFF") - sys.stdout.write(asc_line) diff --git a/freetype/builds/mac/freetype-Info.plist b/freetype/builds/mac/freetype-Info.plist deleted file mode 100644 index 344e5ac..0000000 --- a/freetype/builds/mac/freetype-Info.plist +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - CFBundleDevelopmentRegion - English - - CFBundleExecutable - freetype - - CFBundleGetInfoString - FreeType ${PROJECT_VERSION} - - CFBundleInfoDictionaryVersion - 6.0 - - CFBundleName - FreeType - - CFBundlePackageType - FMWK - - CFBundleShortVersionString - ${PROJECT_VERSION} - - CFBundleSignature - ???? - - CFBundleVersion - ${PROJECT_VERSION} - - - diff --git a/freetype/builds/mac/ftlib.prj.xml b/freetype/builds/mac/ftlib.prj.xml deleted file mode 100644 index cbbc45e..0000000 --- a/freetype/builds/mac/ftlib.prj.xml +++ /dev/null @@ -1,1194 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -]> - - - - - FreeTypeLib - - - - UserSourceTrees - - - AlwaysSearchUserPathstrue - InterpretDOSAndUnixPathstrue - RequireFrameworkStyleIncludesfalse - SourceRelativeIncludesfalse - UserSearchPaths - - SearchPath - Path: - PathFormatMacOS - PathRootProject - - Recursivetrue - FrameworkPathfalse - HostFlagsAll - - - SearchPath - Path:::include: - PathFormatMacOS - PathRootProject - - Recursivetrue - FrameworkPathfalse - HostFlagsAll - - - SearchPath - Path:::src: - PathFormatMacOS - PathRootProject - - Recursivetrue - FrameworkPathfalse - HostFlagsAll - - - SearchPath - Path:: - PathFormatMacOS - PathRootProject - - Recursivetrue - FrameworkPathfalse - HostFlagsAll - - - SystemSearchPaths - - SearchPath - Path: - PathFormatMacOS - PathRootCodeWarrior - - Recursivetrue - FrameworkPathfalse - HostFlagsAll - - - - - MWRuntimeSettings_WorkingDirectory - MWRuntimeSettings_CommandLine - MWRuntimeSettings_HostApplication - Path - PathFormatGeneric - PathRootAbsolute - - MWRuntimeSettings_EnvVars - - - LinkerMacOS PPC Linker - PreLinker - PostLinker - TargetnameFreeTypeLib - OutputDirectory - Path:::objs: - PathFormatMacOS - PathRootProject - - SaveEntriesUsingRelativePathsfalse - - - FileMappings - - FileTypeAPPL - FileExtension - Compiler - EditLanguage - Precompilefalse - Launchabletrue - ResourceFiletrue - IgnoredByMakefalse - - - FileTypeAppl - FileExtension - Compiler - EditLanguage - Precompilefalse - Launchabletrue - ResourceFiletrue - IgnoredByMakefalse - - - FileTypeMMLB - FileExtension - CompilerLib Import PPC - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeMPLF - FileExtension - CompilerLib Import PPC - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeMWCD - FileExtension - Compiler - EditLanguage - Precompilefalse - Launchabletrue - ResourceFiletrue - IgnoredByMakefalse - - - FileTypeRSRC - FileExtension - Compiler - EditLanguage - Precompilefalse - Launchabletrue - ResourceFiletrue - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.bh - CompilerBalloon Help - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.c - CompilerMW C/C++ PPC - EditLanguageC/C++ - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.c++ - CompilerMW C/C++ PPC - EditLanguageC/C++ - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.cc - CompilerMW C/C++ PPC - EditLanguageC/C++ - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.cp - CompilerMW C/C++ PPC - EditLanguageC/C++ - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.cpp - CompilerMW C/C++ PPC - EditLanguageC/C++ - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.exp - Compiler - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.h - CompilerMW C/C++ PPC - EditLanguageC/C++ - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMaketrue - - - FileTypeTEXT - FileExtension.p - CompilerMW Pascal PPC - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.pas - CompilerMW Pascal PPC - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.pch - CompilerMW C/C++ PPC - EditLanguageC/C++ - Precompiletrue - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.pch++ - CompilerMW C/C++ PPC - EditLanguageC/C++ - Precompiletrue - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.ppu - CompilerMW Pascal PPC - EditLanguage - Precompiletrue - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.r - CompilerRez - EditLanguageRez - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeTEXT - FileExtension.s - CompilerPPCAsm - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypeXCOF - FileExtension - CompilerXCOFF Import PPC - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypedocu - FileExtension - Compiler - EditLanguage - Precompilefalse - Launchabletrue - ResourceFiletrue - IgnoredByMakefalse - - - FileTypersrc - FileExtension - Compiler - EditLanguage - Precompilefalse - Launchabletrue - ResourceFiletrue - IgnoredByMakefalse - - - FileTypeshlb - FileExtension - CompilerPEF Import PPC - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileTypestub - FileExtension - CompilerPEF Import PPC - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileExtension.doc - Compiler - EditLanguage - Precompilefalse - Launchabletrue - ResourceFilefalse - IgnoredByMaketrue - - - FileExtension.o - CompilerXCOFF Import PPC - EditLanguage - Precompilefalse - Launchablefalse - ResourceFilefalse - IgnoredByMakefalse - - - FileExtension.ppob - Compiler - EditLanguage - Precompilefalse - Launchabletrue - ResourceFiletrue - IgnoredByMakefalse - - - FileExtension.rsrc - Compiler - EditLanguage - Precompilefalse - Launchabletrue - ResourceFiletrue - IgnoredByMakefalse - - - - - CacheModDatestrue - DumpBrowserInfofalse - CacheSubprojectstrue - UseThirdPartyDebuggerfalse - BrowserGenerator1 - DebuggerAppPath - Path - PathFormatGeneric - PathRootAbsolute - - DebuggerCmdLineArgs - DebuggerWorkingDir - Path - PathFormatGeneric - PathRootAbsolute - - CodeCompletionPrefixFileNameMacHeaders.c - CodeCompletionMacroFileNameMacOS_Carbon_C++_Macros.h - - - ConsoleEncoding0 - LogSystemMessagestrue - AutoTargetDLLsfalse - StopAtWatchpointstrue - PauseWhileRunningfalse - PauseInterval5 - PauseUIFlags0 - AltExePath - Path - PathFormatGeneric - PathRootAbsolute - - StopAtTempBPOnLaunchtrue - CacheSymbolicstrue - TempBPFunctionNamemain - TempBPType0 - - - Enabledfalse - ConnectionName - DownloadPath - LaunchRemoteAppfalse - RemoteAppPath - CoreID0 - JTAGClockSpeed8000 - IsMultiCorefalse - OSDownloadfalse - UseGlobalOSDownloadfalse - OSDownloadConnectionName - OSDownloadPath - AltDownloadfalse - AltDownloadConnectionName - - - OtherExecutables - - - AnalyzerConnectionName - - - CustomColor1 - Red0 - Green32767 - Blue0 - - CustomColor2 - Red0 - Green32767 - Blue0 - - CustomColor3 - Red0 - Green32767 - Blue0 - - CustomColor4 - Red0 - Green32767 - Blue0 - - - - MWFrontEnd_C_cplusplus0 - MWFrontEnd_C_checkprotos1 - MWFrontEnd_C_arm0 - MWFrontEnd_C_trigraphs0 - MWFrontEnd_C_onlystdkeywords0 - MWFrontEnd_C_enumsalwaysint0 - MWFrontEnd_C_ansistrict1 - MWFrontEnd_C_wchar_type1 - MWFrontEnd_C_enableexceptions1 - MWFrontEnd_C_dontreusestrings0 - MWFrontEnd_C_poolstrings0 - MWFrontEnd_C_dontinline0 - MWFrontEnd_C_useRTTI1 - MWFrontEnd_C_unsignedchars0 - MWFrontEnd_C_autoinline0 - MWFrontEnd_C_booltruefalse1 - MWFrontEnd_C_inlinelevel0 - MWFrontEnd_C_ecplusplus0 - MWFrontEnd_C_defer_codegen0 - MWFrontEnd_C_templateparser0 - MWFrontEnd_C_c990 - MWFrontEnd_C_bottomupinline1 - MWFrontEnd_C_gcc_extensions0 - MWFrontEnd_C_instance_manager0 - - - C_CPP_Preprocessor_EmitFiletrue - C_CPP_Preprocessor_EmitLinefalse - C_CPP_Preprocessor_EmitFullPathfalse - C_CPP_Preprocessor_KeepCommentsfalse - C_CPP_Preprocessor_PCHUsesPrefixTextfalse - C_CPP_Preprocessor_EmitPragmastrue - C_CPP_Preprocessor_KeepWhiteSpacefalse - C_CPP_Preprocessor_MultiByteEncodingencASCII_Unicode - C_CPP_Preprocessor_PrefixText/* settings imported from old "C/C++ Language" panel */ - -#if !__option(precompile) -#include "ftoption.h" /* was "Prefix file" */ -#endif - - - - MWWarning_C_warn_illpragma0 - MWWarning_C_warn_emptydecl0 - MWWarning_C_warn_possunwant0 - MWWarning_C_warn_unusedvar1 - MWWarning_C_warn_unusedarg1 - MWWarning_C_warn_extracomma0 - MWWarning_C_pedantic0 - MWWarning_C_warningerrors0 - MWWarning_C_warn_hidevirtual0 - MWWarning_C_warn_implicitconv0 - MWWarning_C_warn_notinlined0 - MWWarning_C_warn_structclass0 - MWWarning_C_warn_missingreturn0 - MWWarning_C_warn_no_side_effect0 - MWWarning_C_warn_resultnotused0 - MWWarning_C_warn_padding0 - MWWarning_C_warn_impl_i2f_conv0 - MWWarning_C_warn_impl_f2i_conv0 - MWWarning_C_warn_impl_s2u_conv0 - MWWarning_C_warn_illtokenpasting0 - MWWarning_C_warn_filenamecaps0 - MWWarning_C_warn_filenamecapssystem0 - MWWarning_C_warn_undefmacro0 - MWWarning_C_warn_ptrintconv0 - - - MWMerge_MacOS_projectTypeApplication - MWMerge_MacOS_outputNameMerge Out - MWMerge_MacOS_outputCreator???? - MWMerge_MacOS_outputTypeAPPL - MWMerge_MacOS_suppressWarning0 - MWMerge_MacOS_copyFragments1 - MWMerge_MacOS_copyResources1 - MWMerge_MacOS_flattenResource0 - MWMerge_MacOS_flatFileNamea.rsrc - MWMerge_MacOS_flatFileOutputPath - Path: - PathFormatMacOS - PathRootProject - - MWMerge_MacOS_skipResources - DLGX - ckid - Proj - WSPC - - - - FileLockedfalse - ResourcesMapIsReadOnlyfalse - PrinterDriverIsMultiFinderCompatiblefalse - Invisiblefalse - HasBundlefalse - NameLockedfalse - Stationeryfalse - HasCustomIconfalse - Sharedfalse - HasBeenInitedfalse - Label0 - Comments - HasCustomBadgefalse - HasRoutingInfofalse - - - MWCodeGen_PPC_structalignmentPPC_mw - MWCodeGen_PPC_tracebacktablesNone - MWCodeGen_PPC_processorGeneric - MWCodeGen_PPC_function_align4 - MWCodeGen_PPC_tocdata1 - MWCodeGen_PPC_largetoc0 - MWCodeGen_PPC_profiler0 - MWCodeGen_PPC_vectortocdata0 - MWCodeGen_PPC_poolconst0 - MWCodeGen_PPC_peephole0 - MWCodeGen_PPC_readonlystrings0 - MWCodeGen_PPC_linkerpoolsstrings0 - MWCodeGen_PPC_volatileasm0 - MWCodeGen_PPC_schedule0 - MWCodeGen_PPC_altivec0 - MWCodeGen_PPC_altivec_move_block0 - MWCodeGen_PPC_strictIEEEfp0 - MWCodeGen_PPC_fpcontract1 - MWCodeGen_PPC_genfsel0 - MWCodeGen_PPC_orderedfpcmp0 - - - MWCodeGen_MachO_structalignmentPPC_mw - MWCodeGen_MachO_profiler_enumOff - MWCodeGen_MachO_processorGeneric - MWCodeGen_MachO_function_align4 - MWCodeGen_MachO_common0 - MWCodeGen_MachO_boolisint0 - MWCodeGen_MachO_peephole1 - MWCodeGen_MachO_readonlystrings0 - MWCodeGen_MachO_linkerpoolsstrings1 - MWCodeGen_MachO_volatileasm0 - MWCodeGen_MachO_schedule0 - MWCodeGen_MachO_altivec0 - MWCodeGen_MachO_vecmove0 - MWCodeGen_MachO_fp_ieee_strict0 - MWCodeGen_MachO_fpcontract1 - MWCodeGen_MachO_genfsel0 - MWCodeGen_MachO_fp_cmps_ordered0 - - - MWDisassembler_PPC_showcode1 - MWDisassembler_PPC_extended1 - MWDisassembler_PPC_mix0 - MWDisassembler_PPC_nohex0 - MWDisassembler_PPC_showdata1 - MWDisassembler_PPC_showexceptions1 - MWDisassembler_PPC_showsym0 - MWDisassembler_PPC_shownames1 - - - GlobalOptimizer_PPC_optimizationlevelLevel0 - GlobalOptimizer_PPC_optforSpeed - - - MWLinker_PPC_linksym1 - MWLinker_PPC_symfullpath1 - MWLinker_PPC_linkmap0 - MWLinker_PPC_nolinkwarnings0 - MWLinker_PPC_dontdeadstripinitcode0 - MWLinker_PPC_permitmultdefs0 - MWLinker_PPC_linkmodeFast - MWLinker_PPC_code_foldingNone - MWLinker_PPC_initname - MWLinker_PPC_mainname - MWLinker_PPC_termname - - - MWLinker_MacOSX_linksym1 - MWLinker_MacOSX_symfullpath0 - MWLinker_MacOSX_nolinkwarnings0 - MWLinker_MacOSX_linkmap0 - MWLinker_MacOSX_dontdeadstripinitcode0 - MWLinker_MacOSX_permitmultdefs0 - MWLinker_MacOSX_use_objectivec_semantics0 - MWLinker_MacOSX_strip_debug_symbols0 - MWLinker_MacOSX_split_segs0 - MWLinker_MacOSX_report_msl_overloads0 - MWLinker_MacOSX_objects_follow_linkorder0 - MWLinker_MacOSX_linkmodeNormal - MWLinker_MacOSX_exportsReferencedGlobals - MWLinker_MacOSX_sortcodeNone - MWLinker_MacOSX_mainname - MWLinker_MacOSX_initname - MWLinker_MacOSX_code_foldingNone - MWLinker_MacOSX_stabsgenNone - - - MWProject_MacOSX_typeExecutable - MWProject_MacOSX_outfile - MWProject_MacOSX_filecreator???? - MWProject_MacOSX_filetypeMEXE - MWProject_MacOSX_vmaddress4096 - MWProject_MacOSX_usedefaultvmaddr1 - MWProject_MacOSX_flatrsrc0 - MWProject_MacOSX_flatrsrcfilename - MWProject_MacOSX_flatrsrcoutputdir - Path: - PathFormatMacOS - PathRootProject - - MWProject_MacOSX_installpath./ - MWProject_MacOSX_dont_prebind0 - MWProject_MacOSX_flat_namespace0 - MWProject_MacOSX_frameworkversionA - MWProject_MacOSX_currentversion0 - MWProject_MacOSX_flat_oldimpversion0 - MWProject_MacOSX_AddrMode1 - - - MWPEF_exportsNone - MWPEF_libfolder0 - MWPEF_sortcodeNone - MWPEF_expandbss0 - MWPEF_sharedata0 - MWPEF_olddefversion0 - MWPEF_oldimpversion0 - MWPEF_currentversion0 - MWPEF_fragmentname - MWPEF_collapsereloads0 - - - MWProject_PPC_typeLibrary - MWProject_PPC_outfileFreeTypeLib - MWProject_PPC_filecreator???? - MWProject_PPC_filetype???? - MWProject_PPC_size0 - MWProject_PPC_minsize0 - MWProject_PPC_stacksize0 - MWProject_PPC_flags0 - MWProject_PPC_symfilename - MWProject_PPC_rsrcname - MWProject_PPC_rsrcheaderNative - MWProject_PPC_rsrctype???? - MWProject_PPC_rsrcid0 - MWProject_PPC_rsrcflags0 - MWProject_PPC_rsrcstore0 - MWProject_PPC_rsrcmerge0 - MWProject_PPC_flatrsrc0 - MWProject_PPC_flatrsrcoutputdir - Path: - PathFormatMacOS - PathRootProject - - MWProject_PPC_flatrsrcfilename - - - MWAssembler_PPC_auxheader0 - MWAssembler_PPC_symmodeMac - MWAssembler_PPC_dialectPPC - MWAssembler_PPC_prefixfile - MWAssembler_PPC_typecheck0 - MWAssembler_PPC_warnings0 - MWAssembler_PPC_casesensitive0 - - - PList_OutputTypeFile - PList_OutputEncodingUTF-8 - PList_PListVersion1.0 - PList_Prefix - PList_FileFilenameInfo.plist - PList_FileDirectory - Path: - PathFormatMacOS - PathRootProject - - PList_ResourceTypeplst - PList_ResourceID0 - PList_ResourceName - - - MWRez_Language_maxwidth80 - MWRez_Language_scriptRoman - MWRez_Language_alignmentAlign1 - MWRez_Language_filtermodeFilterSkip - MWRez_Language_suppresswarnings0 - MWRez_Language_escapecontrolchars1 - MWRez_Language_prefixname - MWRez_Language_filteredtypes'CODE' 'DATA' 'PICT' - - - - Name - ftsystem.c - MacOS - Text - Debug - - - Name - ftbase.c - MacOS - Text - Debug - - - Name - ftinit.c - MacOS - Text - Debug - - - Name - sfnt.c - MacOS - Text - Debug - - - Name - psnames.c - MacOS - Text - Debug - - - Name - ftdebug.c - MacOS - Text - Debug - - - Name - type1cid.c - MacOS - Text - Debug - - - Name - cff.c - MacOS - Text - Debug - - - Name - smooth.c - MacOS - Text - Debug - - - Name - winfnt.c - MacOS - Text - Debug - - - Name - truetype.c - MacOS - Text - Debug - - - Name - ftmac.c - MacOS - Text - Debug - - - Name - psaux.c - MacOS - Text - - - - Name - ftcache.c - MacOS - Text - - - - Name - ftglyph.c - MacOS - Text - - - - Name - type1.c - MacOS - Text - Debug - - - Name - pshinter.c - MacOS - Text - Debug - - - Name - pcf.c - MacOS - Text - Debug - - - Name - ftraster.c - MacOS - Text - Debug - - - Name - ftrend1.c - MacOS - Text - Debug - - - - - Name - ftsystem.c - MacOS - - - Name - ftbase.c - MacOS - - - Name - ftinit.c - MacOS - - - Name - sfnt.c - MacOS - - - Name - psnames.c - MacOS - - - Name - ftdebug.c - MacOS - - - Name - type1cid.c - MacOS - - - Name - cff.c - MacOS - - - Name - smooth.c - MacOS - - - Name - winfnt.c - MacOS - - - Name - truetype.c - MacOS - - - Name - ftmac.c - MacOS - - - Name - psaux.c - MacOS - - - Name - ftcache.c - MacOS - - - Name - ftglyph.c - MacOS - - - Name - type1.c - MacOS - - - Name - pshinter.c - MacOS - - - Name - pcf.c - MacOS - - - Name - ftraster.c - MacOS - - - Name - ftrend1.c - MacOS - - - - - - - FreeTypeLib - - - - base - - FreeTypeLib - Name - ftbase.c - MacOS - - - FreeTypeLib - Name - ftdebug.c - MacOS - - - FreeTypeLib - Name - ftglyph.c - MacOS - - - FreeTypeLib - Name - ftinit.c - MacOS - - - FreeTypeLib - Name - ftsystem.c - MacOS - - - FreeTypeLib - Name - ftmac.c - MacOS - - - ftmodules - - FreeTypeLib - Name - cff.c - MacOS - - - FreeTypeLib - Name - ftcache.c - MacOS - - - FreeTypeLib - Name - psaux.c - MacOS - - - FreeTypeLib - Name - psnames.c - MacOS - - - FreeTypeLib - Name - sfnt.c - MacOS - - - FreeTypeLib - Name - smooth.c - MacOS - - - FreeTypeLib - Name - truetype.c - MacOS - - - FreeTypeLib - Name - type1cid.c - MacOS - - - FreeTypeLib - Name - winfnt.c - MacOS - - - FreeTypeLib - Name - type1.c - MacOS - - - FreeTypeLib - Name - pshinter.c - MacOS - - - FreeTypeLib - Name - pcf.c - MacOS - - - FreeTypeLib - Name - ftraster.c - MacOS - - - FreeTypeLib - Name - ftrend1.c - MacOS - - - - - diff --git a/freetype/builds/mac/ftmac.c b/freetype/builds/mac/ftmac.c deleted file mode 100644 index 8fe5565..0000000 --- a/freetype/builds/mac/ftmac.c +++ /dev/null @@ -1,1542 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftmac.c */ -/* */ -/* Mac FOND support. Written by just@letterror.com. */ -/* Heavily Fixed by mpsuzuki, George Williams and Sean McBride */ -/* */ -/* Copyright (C) 1996-2023 by */ -/* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. */ -/* */ -/* This file is part of the FreeType project, and may only be used, */ -/* modified, and distributed under the terms of the FreeType project */ -/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ -/* this file you indicate that you have read the license and */ -/* understand and accept it fully. */ -/* */ -/***************************************************************************/ - - - /* - Notes - - Mac suitcase files can (and often do!) contain multiple fonts. To - support this I use the face_index argument of FT_(Open|New)_Face() - functions, and pretend the suitcase file is a collection. - - Warning: fbit and NFNT bitmap resources are not supported yet. In old - sfnt fonts, bitmap glyph data for each size is stored in each `NFNT' - resources instead of the `bdat' table in the sfnt resource. Therefore, - face->num_fixed_sizes is set to 0, because bitmap data in `NFNT' - resource is unavailable at present. - - The Mac FOND support works roughly like this: - - - Check whether the offered stream points to a Mac suitcase file. This - is done by checking the file type: it has to be 'FFIL' or 'tfil'. The - stream that gets passed to our init_face() routine is a stdio stream, - which isn't usable for us, since the FOND resources live in the - resource fork. So we just grab the stream->pathname field. - - - Read the FOND resource into memory, then check whether there is a - TrueType font and/or(!) a Type 1 font available. - - - If there is a Type 1 font available (as a separate `LWFN' file), read - its data into memory, massage it slightly so it becomes PFB data, wrap - it into a memory stream, load the Type 1 driver and delegate the rest - of the work to it by calling FT_Open_Face(). (XXX TODO: after this - has been done, the kerning data from the FOND resource should be - appended to the face: On the Mac there are usually no AFM files - available. However, this is tricky since we need to map Mac char - codes to ps glyph names to glyph ID's...) - - - If there is a TrueType font (an `sfnt' resource), read it into memory, - wrap it into a memory stream, load the TrueType driver and delegate - the rest of the work to it, by calling FT_Open_Face(). - - - Some suitcase fonts (notably Onyx) might point the `LWFN' file to - itself, even though it doesn't contains `POST' resources. To handle - this special case without opening the file an extra time, we just - ignore errors from the `LWFN' and fallback to the `sfnt' if both are - available. - */ - - -#include -#include -#include -#include "ftbase.h" - -#if defined( __GNUC__ ) || defined( __IBMC__ ) - /* This is for Mac OS X. Without redefinition, OS_INLINE */ - /* expands to `static inline' which doesn't survive the */ - /* -ansi compilation flag of GCC. */ -#if !HAVE_ANSI_OS_INLINE -#undef OS_INLINE -#define OS_INLINE static __inline__ -#endif -#include -#include -#include /* PATH_MAX */ -#else -#include -#include -#include -#include -#include -#include -#endif - -#ifndef PATH_MAX -#define PATH_MAX 1024 /* same with Mac OS X's syslimits.h */ -#endif - -#if defined( __MWERKS__ ) && !TARGET_RT_MAC_MACHO -#include -#endif - -#define FT_DEPRECATED_ATTRIBUTE - -#include - - /* undefine blocking-macros in ftmac.h */ -#undef FT_GetFile_From_Mac_Name -#undef FT_GetFile_From_Mac_ATS_Name -#undef FT_New_Face_From_FOND -#undef FT_New_Face_From_FSSpec -#undef FT_New_Face_From_FSRef - - - /* FSSpec functions are deprecated since Mac OS X 10.4 */ -#ifndef HAVE_FSSPEC -#if TARGET_API_MAC_OS8 || TARGET_API_MAC_CARBON -#define HAVE_FSSPEC 1 -#else -#define HAVE_FSSPEC 0 -#endif -#endif - - /* most FSRef functions were introduced since Mac OS 9 */ -#ifndef HAVE_FSREF -#if TARGET_API_MAC_OSX -#define HAVE_FSREF 1 -#else -#define HAVE_FSREF 0 -#endif -#endif - - /* QuickDraw is deprecated since Mac OS X 10.4 */ -#ifndef HAVE_QUICKDRAW_CARBON -#if TARGET_API_MAC_OS8 || TARGET_API_MAC_CARBON -#define HAVE_QUICKDRAW_CARBON 1 -#else -#define HAVE_QUICKDRAW_CARBON 0 -#endif -#endif - - /* AppleTypeService is available since Mac OS X */ -#ifndef HAVE_ATS -#if TARGET_API_MAC_OSX -#define HAVE_ATS 1 -#ifndef kATSOptionFlagsUnRestrictedScope /* since Mac OS X 10.1 */ -#define kATSOptionFlagsUnRestrictedScope kATSOptionFlagsDefault -#endif -#else -#define HAVE_ATS 0 -#endif -#endif - - /* `configure' checks the availability of `ResourceIndex' strictly */ - /* and sets HAVE_TYPE_RESOURCE_INDEX to 1 or 0 always. If it is */ - /* not set (e.g., a build without `configure'), the availability */ - /* is guessed from the SDK version. */ -#ifndef HAVE_TYPE_RESOURCE_INDEX -#if !defined( MAC_OS_X_VERSION_10_5 ) || \ - ( MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 ) -#define HAVE_TYPE_RESOURCE_INDEX 0 -#else -#define HAVE_TYPE_RESOURCE_INDEX 1 -#endif -#endif /* !HAVE_TYPE_RESOURCE_INDEX */ - -#if ( HAVE_TYPE_RESOURCE_INDEX == 0 ) -typedef short ResourceIndex; -#endif - - /* Set PREFER_LWFN to 1 if LWFN (Type 1) is preferred over - TrueType in case *both* are available (this is not common, - but it *is* possible). */ -#ifndef PREFER_LWFN -#define PREFER_LWFN 1 -#endif - -#ifdef FT_MACINTOSH - -#if !HAVE_QUICKDRAW_CARBON /* QuickDraw is deprecated since Mac OS X 10.4 */ - - FT_EXPORT_DEF( FT_Error ) - FT_GetFile_From_Mac_Name( const char* fontName, - FSSpec* pathSpec, - FT_Long* face_index ) - { - FT_UNUSED( fontName ); - FT_UNUSED( pathSpec ); - FT_UNUSED( face_index ); - - return FT_THROW( Unimplemented_Feature ); - } - -#else - - FT_EXPORT_DEF( FT_Error ) - FT_GetFile_From_Mac_Name( const char* fontName, - FSSpec* pathSpec, - FT_Long* face_index ) - { - OptionBits options = kFMUseGlobalScopeOption; - - FMFontFamilyIterator famIter; - OSStatus status = FMCreateFontFamilyIterator( NULL, NULL, - options, - &famIter ); - FMFont the_font = 0; - FMFontFamily family = 0; - - - if ( !fontName || !face_index ) - return FT_THROW( Invalid_Argument ); - - *face_index = 0; - while ( status == 0 && !the_font ) - { - status = FMGetNextFontFamily( &famIter, &family ); - if ( status == 0 ) - { - int stat2; - FMFontFamilyInstanceIterator instIter; - Str255 famNameStr; - char famName[256]; - - - /* get the family name */ - FMGetFontFamilyName( family, famNameStr ); - CopyPascalStringToC( famNameStr, famName ); - - /* iterate through the styles */ - FMCreateFontFamilyInstanceIterator( family, &instIter ); - - *face_index = 0; - stat2 = 0; - - while ( stat2 == 0 && !the_font ) - { - FMFontStyle style; - FMFontSize size; - FMFont font; - - - stat2 = FMGetNextFontFamilyInstance( &instIter, &font, - &style, &size ); - if ( stat2 == 0 && size == 0 ) - { - char fullName[256]; - - - /* build up a complete face name */ - ft_strcpy( fullName, famName ); - if ( style & bold ) - ft_strcat( fullName, " Bold" ); - if ( style & italic ) - ft_strcat( fullName, " Italic" ); - - /* compare with the name we are looking for */ - if ( ft_strcmp( fullName, fontName ) == 0 ) - { - /* found it! */ - the_font = font; - } - else - ++(*face_index); - } - } - - FMDisposeFontFamilyInstanceIterator( &instIter ); - } - } - - FMDisposeFontFamilyIterator( &famIter ); - - if ( the_font ) - { - FMGetFontContainer( the_font, pathSpec ); - return FT_Err_Ok; - } - else - return FT_THROW( Unknown_File_Format ); - } - -#endif /* HAVE_QUICKDRAW_CARBON */ - - -#if HAVE_ATS - - /* Private function. */ - /* The FSSpec type has been discouraged for a long time, */ - /* unfortunately an FSRef replacement API for */ - /* ATSFontGetFileSpecification() is only available in */ - /* Mac OS X 10.5 and later. */ - static OSStatus - FT_ATSFontGetFileReference( ATSFontRef ats_font_id, - FSRef* ats_font_ref ) - { - OSStatus err; - -#if !defined( MAC_OS_X_VERSION_10_5 ) || \ - MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 - FSSpec spec; - - - err = ATSFontGetFileSpecification( ats_font_id, &spec ); - if ( noErr == err ) - err = FSpMakeFSRef( &spec, ats_font_ref ); -#else - err = ATSFontGetFileReference( ats_font_id, ats_font_ref ); -#endif - - return err; - } - - - static FT_Error - FT_GetFileRef_From_Mac_ATS_Name( const char* fontName, - FSRef* ats_font_ref, - FT_Long* face_index ) - { - CFStringRef cf_fontName; - ATSFontRef ats_font_id; - - - *face_index = 0; - - cf_fontName = CFStringCreateWithCString( NULL, fontName, - kCFStringEncodingMacRoman ); - ats_font_id = ATSFontFindFromName( cf_fontName, - kATSOptionFlagsUnRestrictedScope ); - CFRelease( cf_fontName ); - - if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) - return FT_THROW( Unknown_File_Format ); - - if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) ) - return FT_THROW( Unknown_File_Format ); - - /* face_index calculation by searching preceding fontIDs */ - /* with same FSRef */ - { - ATSFontRef id2 = ats_font_id - 1; - FSRef ref2; - - - while ( id2 > 0 ) - { - if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) ) - break; - if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) ) - break; - - id2--; - } - *face_index = ats_font_id - ( id2 + 1 ); - } - - return FT_Err_Ok; - } - -#endif - -#if !HAVE_ATS - - FT_EXPORT_DEF( FT_Error ) - FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, - UInt8* path, - UInt32 maxPathSize, - FT_Long* face_index ) - { - FT_UNUSED( fontName ); - FT_UNUSED( path ); - FT_UNUSED( maxPathSize ); - FT_UNUSED( face_index ); - - return FT_THROW( Unimplemented_Feature ); - } - -#else - - FT_EXPORT_DEF( FT_Error ) - FT_GetFilePath_From_Mac_ATS_Name( const char* fontName, - UInt8* path, - UInt32 maxPathSize, - FT_Long* face_index ) - { - FSRef ref; - FT_Error err; - - - err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); - if ( err ) - return err; - - if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) ) - return FT_THROW( Unknown_File_Format ); - - return FT_Err_Ok; - } - -#endif /* HAVE_ATS */ - - -#if !HAVE_FSSPEC || !HAVE_ATS - - FT_EXPORT_DEF( FT_Error ) - FT_GetFile_From_Mac_ATS_Name( const char* fontName, - FSSpec* pathSpec, - FT_Long* face_index ) - { - FT_UNUSED( fontName ); - FT_UNUSED( pathSpec ); - FT_UNUSED( face_index ); - - return FT_THROW( Unimplemented_Feature ); - } - -#else - - /* This function is deprecated because FSSpec is deprecated in Mac OS X. */ - FT_EXPORT_DEF( FT_Error ) - FT_GetFile_From_Mac_ATS_Name( const char* fontName, - FSSpec* pathSpec, - FT_Long* face_index ) - { - FSRef ref; - FT_Error err; - - - err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index ); - if ( err ) - return err; - - if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL, - pathSpec, NULL ) ) - return FT_THROW( Unknown_File_Format ); - - return FT_Err_Ok; - } - -#endif - - -#if defined( __MWERKS__ ) && !TARGET_RT_MAC_MACHO - -#define STREAM_FILE( stream ) ( (FT_FILE*)stream->descriptor.pointer ) - - - FT_CALLBACK_DEF( void ) - ft_FSp_stream_close( FT_Stream stream ) - { - ft_fclose( STREAM_FILE( stream ) ); - - stream->descriptor.pointer = NULL; - stream->size = 0; - stream->base = NULL; - } - - - FT_CALLBACK_DEF( unsigned long ) - ft_FSp_stream_io( FT_Stream stream, - unsigned long offset, - unsigned char* buffer, - unsigned long count ) - { - FT_FILE* file; - - - file = STREAM_FILE( stream ); - - ft_fseek( file, offset, SEEK_SET ); - - return (unsigned long)ft_fread( buffer, 1, count, file ); - } - -#endif /* __MWERKS__ && !TARGET_RT_MAC_MACHO */ - - -#if HAVE_FSSPEC && !HAVE_FSREF - - /* isDirectory is a dummy to synchronize API with FSPathMakeRef() */ - static OSErr - FT_FSPathMakeSpec( const UInt8* pathname, - FSSpec* spec_p, - Boolean isDirectory ) - { - const char *p, *q; - short vRefNum; - long dirID; - Str255 nodeName; - OSErr err; - FT_UNUSED( isDirectory ); - - - p = q = (const char *)pathname; - dirID = 0; - vRefNum = 0; - - while ( 1 ) - { - int len = ft_strlen( p ); - - - if ( len > 255 ) - len = 255; - - q = p + len; - - if ( q == p ) - return 0; - - if ( 255 < ft_strlen( (char *)pathname ) ) - { - while ( p < q && *q != ':' ) - q--; - } - - if ( p < q ) - *(char *)nodeName = q - p; - else if ( ft_strlen( p ) < 256 ) - *(char *)nodeName = ft_strlen( p ); - else - return errFSNameTooLong; - - ft_strncpy( (char *)nodeName + 1, (char *)p, *(char *)nodeName ); - err = FSMakeFSSpec( vRefNum, dirID, nodeName, spec_p ); - if ( err || '\0' == *q ) - return err; - - vRefNum = spec_p->vRefNum; - dirID = spec_p->parID; - - p = q; - } - } - - - static OSErr - FT_FSpMakePath( const FSSpec* spec_p, - UInt8* path, - UInt32 maxPathSize ) - { - OSErr err; - FSSpec spec = *spec_p; - short vRefNum; - long dirID; - Str255 parDir_name; - - - FT_MEM_SET( path, 0, maxPathSize ); - while ( 1 ) - { - int child_namelen = ft_strlen( (char *)path ); - unsigned char node_namelen = spec.name[0]; - unsigned char* node_name = spec.name + 1; - - - if ( node_namelen + child_namelen > maxPathSize ) - return errFSNameTooLong; - - FT_MEM_MOVE( path + node_namelen + 1, path, child_namelen ); - FT_MEM_COPY( path, node_name, node_namelen ); - if ( child_namelen > 0 ) - path[node_namelen] = ':'; - - vRefNum = spec.vRefNum; - dirID = spec.parID; - parDir_name[0] = '\0'; - err = FSMakeFSSpec( vRefNum, dirID, parDir_name, &spec ); - if ( noErr != err || dirID == spec.parID ) - break; - } - return noErr; - } - -#endif /* HAVE_FSSPEC && !HAVE_FSREF */ - - - static OSErr - FT_FSPathMakeRes( const UInt8* pathname, - ResFileRefNum* res ) - { - -#if HAVE_FSREF - - OSErr err; - FSRef ref; - - - if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) ) - return FT_THROW( Cannot_Open_Resource ); - - /* at present, no support for dfont format */ - err = FSOpenResourceFile( &ref, 0, NULL, fsRdPerm, res ); - if ( noErr == err ) - return err; - - /* fallback to original resource-fork font */ - *res = FSOpenResFile( &ref, fsRdPerm ); - err = ResError(); - -#else - - OSErr err; - FSSpec spec; - - - if ( noErr != FT_FSPathMakeSpec( pathname, &spec, FALSE ) ) - return FT_THROW( Cannot_Open_Resource ); - - /* at present, no support for dfont format without FSRef */ - /* (see above), try original resource-fork font */ - *res = FSpOpenResFile( &spec, fsRdPerm ); - err = ResError(); - -#endif /* HAVE_FSREF */ - - return err; - } - - - /* Return the file type for given pathname */ - static OSType - get_file_type_from_path( const UInt8* pathname ) - { - -#if HAVE_FSREF - - FSRef ref; - FSCatalogInfo info; - - - if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) ) - return ( OSType ) 0; - - if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoFinderInfo, &info, - NULL, NULL, NULL ) ) - return ( OSType ) 0; - - return ((FInfo *)(info.finderInfo))->fdType; - -#else - - FSSpec spec; - FInfo finfo; - - - if ( noErr != FT_FSPathMakeSpec( pathname, &spec, FALSE ) ) - return ( OSType ) 0; - - if ( noErr != FSpGetFInfo( &spec, &finfo ) ) - return ( OSType ) 0; - - return finfo.fdType; - -#endif /* HAVE_FSREF */ - - } - - - /* Given a PostScript font name, create the Macintosh LWFN file name. */ - static void - create_lwfn_name( char* ps_name, - Str255 lwfn_file_name ) - { - int max = 5, count = 0; - FT_Byte* p = lwfn_file_name; - FT_Byte* q = (FT_Byte*)ps_name; - - - lwfn_file_name[0] = 0; - - while ( *q ) - { - if ( ft_isupper( *q ) ) - { - if ( count ) - max = 3; - count = 0; - } - if ( count < max && ( ft_isalnum( *q ) || *q == '_' ) ) - { - *++p = *q; - lwfn_file_name[0]++; - count++; - } - q++; - } - } - - - static short - count_faces_sfnt( char* fond_data ) - { - /* The count is 1 greater than the value in the FOND. */ - /* Isn't that cute? :-) */ - - return EndianS16_BtoN( *( (short*)( fond_data + - sizeof ( FamRec ) ) ) ) + 1; - } - - - static short - count_faces_scalable( char* fond_data ) - { - AsscEntry* assoc; - short i, face, face_all; - - - face_all = EndianS16_BtoN( *( (short *)( fond_data + - sizeof ( FamRec ) ) ) ) + 1; - assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 ); - face = 0; - - for ( i = 0; i < face_all; i++ ) - { - if ( 0 == EndianS16_BtoN( assoc[i].fontSize ) ) - face++; - } - return face; - } - - - /* Look inside the FOND data, answer whether there should be an SFNT - resource, and answer the name of a possible LWFN Type 1 file. - - Thanks to Paul Miller (paulm@profoundeffects.com) for the fix - to load a face OTHER than the first one in the FOND! - */ - - static void - parse_fond( char* fond_data, - short* have_sfnt, - ResID* sfnt_id, - Str255 lwfn_file_name, - short face_index ) - { - AsscEntry* assoc; - AsscEntry* base_assoc; - FamRec* fond; - - - *sfnt_id = 0; - *have_sfnt = 0; - lwfn_file_name[0] = 0; - - fond = (FamRec*)fond_data; - assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 ); - base_assoc = assoc; - - /* the maximum faces in a FOND is 48, size of StyleTable.indexes[] */ - if ( 47 < face_index ) - return; - - /* Let's do a little range checking before we get too excited here */ - if ( face_index < count_faces_sfnt( fond_data ) ) - { - assoc += face_index; /* add on the face_index! */ - - /* if the face at this index is not scalable, - fall back to the first one (old behavior) */ - if ( EndianS16_BtoN( assoc->fontSize ) == 0 ) - { - *have_sfnt = 1; - *sfnt_id = EndianS16_BtoN( assoc->fontID ); - } - else if ( base_assoc->fontSize == 0 ) - { - *have_sfnt = 1; - *sfnt_id = EndianS16_BtoN( base_assoc->fontID ); - } - } - - if ( EndianS32_BtoN( fond->ffStylOff ) ) - { - unsigned char* p = (unsigned char*)fond_data; - StyleTable* style; - unsigned short string_count; - char ps_name[256]; - unsigned char* names[64]; - int i; - - - p += EndianS32_BtoN( fond->ffStylOff ); - style = (StyleTable*)p; - p += sizeof ( StyleTable ); - string_count = EndianS16_BtoN( *(short*)(p) ); - string_count = FT_MIN( 64, string_count ); - p += sizeof ( short ); - - for ( i = 0; i < string_count; i++ ) - { - names[i] = p; - p += names[i][0]; - p++; - } - - { - size_t ps_name_len = (size_t)names[0][0]; - - - if ( ps_name_len != 0 ) - { - ft_memcpy(ps_name, names[0] + 1, ps_name_len); - ps_name[ps_name_len] = 0; - } - if ( style->indexes[face_index] > 1 && - style->indexes[face_index] <= string_count ) - { - unsigned char* suffixes = names[style->indexes[face_index] - 1]; - - - for ( i = 1; i <= suffixes[0]; i++ ) - { - unsigned char* s; - size_t j = suffixes[i] - 1; - - - if ( j < string_count && ( s = names[j] ) != NULL ) - { - size_t s_len = (size_t)s[0]; - - - if ( s_len != 0 && ps_name_len + s_len < sizeof ( ps_name ) ) - { - ft_memcpy( ps_name + ps_name_len, s + 1, s_len ); - ps_name_len += s_len; - ps_name[ps_name_len] = 0; - } - } - } - } - } - - create_lwfn_name( ps_name, lwfn_file_name ); - } - } - - - static FT_Error - lookup_lwfn_by_fond( const UInt8* path_fond, - ConstStr255Param base_lwfn, - UInt8* path_lwfn, - int path_size ) - { - -#if HAVE_FSREF - - FSRef ref, par_ref; - int dirname_len; - - - /* Pathname for FSRef can be in various formats: HFS, HFS+, and POSIX. */ - /* We should not extract parent directory by string manipulation. */ - - if ( noErr != FSPathMakeRef( path_fond, &ref, FALSE ) ) - return FT_THROW( Invalid_Argument ); - - if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, - NULL, NULL, NULL, &par_ref ) ) - return FT_THROW( Invalid_Argument ); - - if ( noErr != FSRefMakePath( &par_ref, path_lwfn, path_size ) ) - return FT_THROW( Invalid_Argument ); - - if ( ft_strlen( (char *)path_lwfn ) + 1 + base_lwfn[0] > path_size ) - return FT_THROW( Invalid_Argument ); - - /* now we have absolute dirname in path_lwfn */ - if ( path_lwfn[0] == '/' ) - ft_strcat( (char *)path_lwfn, "/" ); - else - ft_strcat( (char *)path_lwfn, ":" ); - - dirname_len = ft_strlen( (char *)path_lwfn ); - ft_strcat( (char *)path_lwfn, (char *)base_lwfn + 1 ); - path_lwfn[dirname_len + base_lwfn[0]] = '\0'; - - if ( noErr != FSPathMakeRef( path_lwfn, &ref, FALSE ) ) - return FT_THROW( Cannot_Open_Resource ); - - if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, - NULL, NULL, NULL, NULL ) ) - return FT_THROW( Cannot_Open_Resource ); - - return FT_Err_Ok; - -#else - - int i; - FSSpec spec; - - - /* pathname for FSSpec is always HFS format */ - if ( ft_strlen( (char *)path_fond ) > path_size ) - return FT_THROW( Invalid_Argument ); - - ft_strcpy( (char *)path_lwfn, (char *)path_fond ); - - i = ft_strlen( (char *)path_lwfn ) - 1; - while ( i > 0 && ':' != path_lwfn[i] ) - i--; - - if ( i + 1 + base_lwfn[0] > path_size ) - return FT_THROW( Invalid_Argument ); - - if ( ':' == path_lwfn[i] ) - { - ft_strcpy( (char *)path_lwfn + i + 1, (char *)base_lwfn + 1 ); - path_lwfn[i + 1 + base_lwfn[0]] = '\0'; - } - else - { - ft_strcpy( (char *)path_lwfn, (char *)base_lwfn + 1 ); - path_lwfn[base_lwfn[0]] = '\0'; - } - - if ( noErr != FT_FSPathMakeSpec( path_lwfn, &spec, FALSE ) ) - return FT_THROW( Cannot_Open_Resource ); - - return FT_Err_Ok; - -#endif /* HAVE_FSREF */ - - } - - - static short - count_faces( Handle fond, - const UInt8* pathname ) - { - ResID sfnt_id; - short have_sfnt, have_lwfn; - Str255 lwfn_file_name; - UInt8 buff[PATH_MAX]; - FT_Error err; - short num_faces; - - - have_sfnt = have_lwfn = 0; - - HLock( fond ); - parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, 0 ); - - if ( lwfn_file_name[0] ) - { - err = lookup_lwfn_by_fond( pathname, lwfn_file_name, - buff, sizeof ( buff ) ); - if ( !err ) - have_lwfn = 1; - } - - if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) - num_faces = 1; - else - num_faces = count_faces_scalable( *fond ); - - HUnlock( fond ); - return num_faces; - } - - - /* Read Type 1 data from the POST resources inside the LWFN file, - return a PFB buffer. This is somewhat convoluted because the FT2 - PFB parser wants the ASCII header as one chunk, and the LWFN - chunks are often not organized that way, so we glue chunks - of the same type together. */ - static FT_Error - read_lwfn( FT_Memory memory, - ResFileRefNum res, - FT_Byte** pfb_data, - FT_ULong* size ) - { - FT_Error error = FT_Err_Ok; - ResID res_id; - unsigned char *buffer, *p, *size_p = NULL; - FT_ULong total_size = 0; - FT_ULong old_total_size = 0; - FT_ULong post_size, pfb_chunk_size; - Handle post_data; - char code, last_code; - - - UseResFile( res ); - - /* First pass: load all POST resources, and determine the size of */ - /* the output buffer. */ - res_id = 501; - last_code = -1; - - for (;;) - { - post_data = Get1Resource( TTAG_POST, res_id++ ); - if ( post_data == NULL ) - break; /* we are done */ - - code = (*post_data)[0]; - - if ( code != last_code ) - { - if ( code == 5 ) - total_size += 2; /* just the end code */ - else - total_size += 6; /* code + 4 bytes chunk length */ - } - - total_size += GetHandleSize( post_data ) - 2; - last_code = code; - - /* detect integer overflows */ - if ( total_size < old_total_size ) - { - error = FT_ERR( Array_Too_Large ); - goto Error; - } - - old_total_size = total_size; - } - - if ( FT_QALLOC( buffer, (FT_Long)total_size ) ) - goto Error; - - /* Second pass: append all POST data to the buffer, add PFB fields. */ - /* Glue all consecutive chunks of the same type together. */ - p = buffer; - res_id = 501; - last_code = -1; - pfb_chunk_size = 0; - - for (;;) - { - post_data = Get1Resource( TTAG_POST, res_id++ ); - if ( post_data == NULL ) - break; /* we are done */ - - post_size = (FT_ULong)GetHandleSize( post_data ) - 2; - code = (*post_data)[0]; - - if ( code != last_code ) - { - if ( last_code != -1 ) - { - /* we are done adding a chunk, fill in the size field */ - if ( size_p != NULL ) - { - *size_p++ = (FT_Byte)( pfb_chunk_size & 0xFF ); - *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 8 ) & 0xFF ); - *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF ); - *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF ); - } - pfb_chunk_size = 0; - } - - *p++ = 0x80; - if ( code == 5 ) - *p++ = 0x03; /* the end */ - else if ( code == 2 ) - *p++ = 0x02; /* binary segment */ - else - *p++ = 0x01; /* ASCII segment */ - - if ( code != 5 ) - { - size_p = p; /* save for later */ - p += 4; /* make space for size field */ - } - } - - ft_memcpy( p, *post_data + 2, post_size ); - pfb_chunk_size += post_size; - p += post_size; - last_code = code; - } - - *pfb_data = buffer; - *size = total_size; - - Error: - CloseResFile( res ); - return error; - } - - - /* Create a new FT_Face from a file spec to an LWFN file. */ - static FT_Error - FT_New_Face_From_LWFN( FT_Library library, - const UInt8* pathname, - FT_Long face_index, - FT_Face* aface ) - { - FT_Byte* pfb_data; - FT_ULong pfb_size; - FT_Error error; - ResFileRefNum res; - - - if ( noErr != FT_FSPathMakeRes( pathname, &res ) ) - return FT_THROW( Cannot_Open_Resource ); - - pfb_data = NULL; - pfb_size = 0; - error = read_lwfn( library->memory, res, &pfb_data, &pfb_size ); - CloseResFile( res ); /* PFB is already loaded, useless anymore */ - if ( error ) - return error; - - return open_face_from_buffer( library, - pfb_data, - pfb_size, - face_index, - "type1", - aface ); - } - - - /* Create a new FT_Face from an SFNT resource, specified by res ID. */ - static FT_Error - FT_New_Face_From_SFNT( FT_Library library, - ResID sfnt_id, - FT_Long face_index, - FT_Face* aface ) - { - Handle sfnt = NULL; - FT_Byte* sfnt_data; - size_t sfnt_size; - FT_Error error = FT_Err_Ok; - FT_Memory memory = library->memory; - int is_cff, is_sfnt_ps; - - - sfnt = GetResource( TTAG_sfnt, sfnt_id ); - if ( sfnt == NULL ) - return FT_THROW( Invalid_Handle ); - - sfnt_size = (FT_ULong)GetHandleSize( sfnt ); - if ( FT_QALLOC( sfnt_data, (FT_Long)sfnt_size ) ) - { - ReleaseResource( sfnt ); - return error; - } - - HLock( sfnt ); - ft_memcpy( sfnt_data, *sfnt, sfnt_size ); - HUnlock( sfnt ); - ReleaseResource( sfnt ); - - is_cff = sfnt_size > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 ); - is_sfnt_ps = sfnt_size > 4 && !ft_memcmp( sfnt_data, "typ1", 4 ); - - if ( is_sfnt_ps ) - { - FT_Stream stream; - - - if ( FT_NEW( stream ) ) - goto Try_OpenType; - - FT_Stream_OpenMemory( stream, sfnt_data, sfnt_size ); - if ( !open_face_PS_from_sfnt_stream( library, - stream, - face_index, - 0, NULL, - aface ) ) - { - FT_Stream_Close( stream ); - FT_FREE( stream ); - FT_FREE( sfnt_data ); - goto Exit; - } - - FT_FREE( stream ); - } - Try_OpenType: - error = open_face_from_buffer( library, - sfnt_data, - sfnt_size, - face_index, - is_cff ? "cff" : "truetype", - aface ); - Exit: - return error; - } - - - /* Create a new FT_Face from a file spec to a suitcase file. */ - static FT_Error - FT_New_Face_From_Suitcase( FT_Library library, - const UInt8* pathname, - FT_Long face_index, - FT_Face* aface ) - { - FT_Error error = FT_ERR( Cannot_Open_Resource ); - ResFileRefNum res_ref; - ResourceIndex res_index; - Handle fond; - short num_faces_in_res; - - - if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) ) - return FT_THROW( Cannot_Open_Resource ); - - UseResFile( res_ref ); - if ( ResError() ) - return FT_THROW( Cannot_Open_Resource ); - - num_faces_in_res = 0; - for ( res_index = 1; ; ++res_index ) - { - short num_faces_in_fond; - - - fond = Get1IndResource( TTAG_FOND, res_index ); - if ( ResError() ) - break; - - num_faces_in_fond = count_faces( fond, pathname ); - num_faces_in_res += num_faces_in_fond; - - if ( 0 <= face_index && face_index < num_faces_in_fond && error ) - error = FT_New_Face_From_FOND( library, fond, face_index, aface ); - - face_index -= num_faces_in_fond; - } - - CloseResFile( res_ref ); - if ( !error && aface ) - (*aface)->num_faces = num_faces_in_res; - return error; - } - - - /* documentation is in ftmac.h */ - - FT_EXPORT_DEF( FT_Error ) - FT_New_Face_From_FOND( FT_Library library, - Handle fond, - FT_Long face_index, - FT_Face* aface ) - { - short have_sfnt, have_lwfn = 0; - ResID sfnt_id, fond_id; - OSType fond_type; - Str255 fond_name; - Str255 lwfn_file_name; - UInt8 path_lwfn[PATH_MAX]; - OSErr err; - FT_Error error = FT_Err_Ok; - - - /* test for valid `aface' and `library' delayed to */ - /* `FT_New_Face_From_XXX' */ - - GetResInfo( fond, &fond_id, &fond_type, fond_name ); - if ( ResError() != noErr || fond_type != TTAG_FOND ) - return FT_THROW( Invalid_File_Format ); - - HLock( fond ); - parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); - HUnlock( fond ); - - if ( lwfn_file_name[0] ) - { - ResFileRefNum res; - - - res = HomeResFile( fond ); - if ( noErr != ResError() ) - goto found_no_lwfn_file; - -#if HAVE_FSREF - - { - UInt8 path_fond[PATH_MAX]; - FSRef ref; - - - err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum, - NULL, NULL, NULL, &ref, NULL ); - if ( noErr != err ) - goto found_no_lwfn_file; - - err = FSRefMakePath( &ref, path_fond, sizeof ( path_fond ) ); - if ( noErr != err ) - goto found_no_lwfn_file; - - error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, - path_lwfn, sizeof ( path_lwfn ) ); - if ( !error ) - have_lwfn = 1; - } - -#elif HAVE_FSSPEC - - { - UInt8 path_fond[PATH_MAX]; - FCBPBRec pb; - Str255 fond_file_name; - FSSpec spec; - - - FT_MEM_SET( &spec, 0, sizeof ( FSSpec ) ); - FT_MEM_SET( &pb, 0, sizeof ( FCBPBRec ) ); - - pb.ioNamePtr = fond_file_name; - pb.ioVRefNum = 0; - pb.ioRefNum = res; - pb.ioFCBIndx = 0; - - err = PBGetFCBInfoSync( &pb ); - if ( noErr != err ) - goto found_no_lwfn_file; - - err = FSMakeFSSpec( pb.ioFCBVRefNum, pb.ioFCBParID, - fond_file_name, &spec ); - if ( noErr != err ) - goto found_no_lwfn_file; - - err = FT_FSpMakePath( &spec, path_fond, sizeof ( path_fond ) ); - if ( noErr != err ) - goto found_no_lwfn_file; - - error = lookup_lwfn_by_fond( path_fond, lwfn_file_name, - path_lwfn, sizeof ( path_lwfn ) ); - if ( !error ) - have_lwfn = 1; - } - -#endif /* HAVE_FSREF, HAVE_FSSPEC */ - - } - - if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) - error = FT_New_Face_From_LWFN( library, - path_lwfn, - face_index, - aface ); - else - error = FT_ERR( Unknown_File_Format ); - - found_no_lwfn_file: - if ( have_sfnt && error ) - error = FT_New_Face_From_SFNT( library, - sfnt_id, - face_index, - aface ); - - return error; - } - - - /* Common function to load a new FT_Face from a resource file. */ - static FT_Error - FT_New_Face_From_Resource( FT_Library library, - const UInt8* pathname, - FT_Long face_index, - FT_Face* aface ) - { - OSType file_type; - FT_Error error; - - - /* LWFN is a (very) specific file format, check for it explicitly */ - file_type = get_file_type_from_path( pathname ); - if ( file_type == TTAG_LWFN ) - return FT_New_Face_From_LWFN( library, pathname, face_index, aface ); - - /* Otherwise the file type doesn't matter (there are more than */ - /* `FFIL' and `tfil'). Just try opening it as a font suitcase; */ - /* if it works, fine. */ - - error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface ); - if ( !error ) - return error; - - /* let it fall through to normal loader (.ttf, .otf, etc.); */ - /* we signal this by returning no error and no FT_Face */ - *aface = NULL; - return 0; - } - - - /*************************************************************************/ - /* */ - /* */ - /* FT_New_Face */ - /* */ - /* */ - /* This is the Mac-specific implementation of FT_New_Face. In */ - /* addition to the standard FT_New_Face() functionality, it also */ - /* accepts pathnames to Mac suitcase files. For further */ - /* documentation see the original FT_New_Face() in freetype.h. */ - /* */ - FT_EXPORT_DEF( FT_Error ) - FT_New_Face( FT_Library library, - const char* pathname, - FT_Long face_index, - FT_Face* aface ) - { - FT_Open_Args args; - FT_Error error; - - - /* test for valid `library' and `aface' delayed to FT_Open_Face() */ - if ( !pathname ) - return FT_THROW( Invalid_Argument ); - - *aface = NULL; - - /* try resourcefork based font: LWFN, FFIL */ - error = FT_New_Face_From_Resource( library, (UInt8 *)pathname, - face_index, aface ); - if ( error || *aface ) - return error; - - /* let it fall through to normal loader (.ttf, .otf, etc.) */ - args.flags = FT_OPEN_PATHNAME; - args.pathname = (char*)pathname; - return FT_Open_Face( library, &args, face_index, aface ); - } - - - /*************************************************************************/ - /* */ - /* */ - /* FT_New_Face_From_FSRef */ - /* */ - /* */ - /* FT_New_Face_From_FSRef is identical to FT_New_Face except it */ - /* accepts an FSRef instead of a path. */ - /* */ - /* This function is deprecated because Carbon data types (FSRef) */ - /* are not cross-platform, and thus not suitable for the FreeType API. */ - FT_EXPORT_DEF( FT_Error ) - FT_New_Face_From_FSRef( FT_Library library, - const FSRef* ref, - FT_Long face_index, - FT_Face* aface ) - { - -#if !HAVE_FSREF - - FT_UNUSED( library ); - FT_UNUSED( ref ); - FT_UNUSED( face_index ); - FT_UNUSED( aface ); - - return FT_THROW( Unimplemented_Feature ); - -#else - - FT_Error error; - FT_Open_Args args; - OSErr err; - UInt8 pathname[PATH_MAX]; - - - /* test for valid `library' and `aface' delayed to `FT_Open_Face' */ - - if ( !ref ) - return FT_THROW( Invalid_Argument ); - - err = FSRefMakePath( ref, pathname, sizeof ( pathname ) ); - if ( err ) - error = FT_ERR( Cannot_Open_Resource ); - - error = FT_New_Face_From_Resource( library, pathname, face_index, aface ); - if ( error || *aface ) - return error; - - /* fallback to datafork font */ - args.flags = FT_OPEN_PATHNAME; - args.pathname = (char*)pathname; - return FT_Open_Face( library, &args, face_index, aface ); - -#endif /* HAVE_FSREF */ - - } - - - /*************************************************************************/ - /* */ - /* */ - /* FT_New_Face_From_FSSpec */ - /* */ - /* */ - /* FT_New_Face_From_FSSpec is identical to FT_New_Face except it */ - /* accepts an FSSpec instead of a path. */ - /* */ - /* This function is deprecated because Carbon data types (FSSpec) */ - /* are not cross-platform, and thus not suitable for the FreeType API. */ - FT_EXPORT_DEF( FT_Error ) - FT_New_Face_From_FSSpec( FT_Library library, - const FSSpec* spec, - FT_Long face_index, - FT_Face* aface ) - { - -#if HAVE_FSREF - - FSRef ref; - - - if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr ) - return FT_THROW( Invalid_Argument ); - else - return FT_New_Face_From_FSRef( library, &ref, face_index, aface ); - -#elif HAVE_FSSPEC - - FT_Error error; - FT_Open_Args args; - OSErr err; - UInt8 pathname[PATH_MAX]; - - - if ( !spec ) - return FT_THROW( Invalid_Argument ); - - err = FT_FSpMakePath( spec, pathname, sizeof ( pathname ) ); - if ( err ) - error = FT_ERR( Cannot_Open_Resource ); - - error = FT_New_Face_From_Resource( library, pathname, face_index, aface ); - if ( error || *aface ) - return error; - - /* fallback to datafork font */ - args.flags = FT_OPEN_PATHNAME; - args.pathname = (char*)pathname; - return FT_Open_Face( library, &args, face_index, aface ); - -#else - - FT_UNUSED( library ); - FT_UNUSED( spec ); - FT_UNUSED( face_index ); - FT_UNUSED( aface ); - - return FT_THROW( Unimplemented_Feature ); - -#endif /* HAVE_FSREF, HAVE_FSSPEC */ - - } - -#endif /* FT_MACINTOSH */ - - -/* END */ diff --git a/freetype/builds/meson/extract_freetype_version.py b/freetype/builds/meson/extract_freetype_version.py deleted file mode 100644 index c4c60e7..0000000 --- a/freetype/builds/meson/extract_freetype_version.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2020-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -"""Extract the FreeType version numbers from ``. - -This script parses the header to extract the version number defined there. -By default, the full dotted version number is printed, but `--major`, -`--minor` or `--patch` can be used to only print one of these values -instead. -""" - -from __future__ import print_function - -import argparse -import os -import re -import sys - -# Expected input: -# -# ... -# #define FREETYPE_MAJOR 2 -# #define FREETYPE_MINOR 10 -# #define FREETYPE_PATCH 2 -# ... - -RE_MAJOR = re.compile(r"^ \#define \s+ FREETYPE_MAJOR \s+ (.*) $", re.X) -RE_MINOR = re.compile(r"^ \#define \s+ FREETYPE_MINOR \s+ (.*) $", re.X) -RE_PATCH = re.compile(r"^ \#define \s+ FREETYPE_PATCH \s+ (.*) $", re.X) - - -def parse_freetype_header(header): - major = None - minor = None - patch = None - - for line in header.splitlines(): - line = line.rstrip() - m = RE_MAJOR.match(line) - if m: - assert major == None, "FREETYPE_MAJOR appears more than once!" - major = m.group(1) - continue - - m = RE_MINOR.match(line) - if m: - assert minor == None, "FREETYPE_MINOR appears more than once!" - minor = m.group(1) - continue - - m = RE_PATCH.match(line) - if m: - assert patch == None, "FREETYPE_PATCH appears more than once!" - patch = m.group(1) - continue - - assert ( - major and minor and patch - ), "This header is missing one of FREETYPE_MAJOR, FREETYPE_MINOR or FREETYPE_PATCH!" - - return (major, minor, patch) - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - - group = parser.add_mutually_exclusive_group() - group.add_argument( - "--major", - action="store_true", - help="Only print the major version number.", - ) - group.add_argument( - "--minor", - action="store_true", - help="Only print the minor version number.", - ) - group.add_argument( - "--patch", - action="store_true", - help="Only print the patch version number.", - ) - - parser.add_argument( - "input", - metavar="FREETYPE_H", - help="The input freetype.h header to parse.", - ) - - args = parser.parse_args() - with open(args.input) as f: - header = f.read() - - version = parse_freetype_header(header) - - if args.major: - print(version[0]) - elif args.minor: - print(version[1]) - elif args.patch: - print(version[2]) - else: - print("%s.%s.%s" % version) - - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/freetype/builds/meson/extract_libtool_version.py b/freetype/builds/meson/extract_libtool_version.py deleted file mode 100644 index 6fac74c..0000000 --- a/freetype/builds/meson/extract_libtool_version.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2020-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -"""Extract the libtool version from `configure.raw`. - -This script parses the `configure.raw` file to extract the libtool version -number. By default, the full dotted version number is printed, but -`--major`, `--minor` or `--patch` can be used to only print one of these -values instead. -""" - -from __future__ import print_function - -import argparse -import os -import re -import sys - -# Expected input: -# -# ... -# version_info='23:2:17' -# ... - -RE_VERSION_INFO = re.compile(r"^version_info='(\d+):(\d+):(\d+)'") - - -def parse_configure_raw(header): - major = None - minor = None - patch = None - - for line in header.splitlines(): - line = line.rstrip() - m = RE_VERSION_INFO.match(line) - if m: - assert major == None, "version_info appears more than once!" - major = m.group(1) - minor = m.group(2) - patch = m.group(3) - continue - - assert ( - major and minor and patch - ), "This input file is missing a version_info definition!" - - return (major, minor, patch) - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - - group = parser.add_mutually_exclusive_group() - group.add_argument( - "--major", - action="store_true", - help="Only print the major version number.", - ) - group.add_argument( - "--minor", - action="store_true", - help="Only print the minor version number.", - ) - group.add_argument( - "--patch", - action="store_true", - help="Only print the patch version number.", - ) - group.add_argument( - "--soversion", - action="store_true", - help="Only print the libtool library suffix.", - ) - - parser.add_argument( - "input", - metavar="CONFIGURE_RAW", - help="The input configure.raw file to parse.", - ) - - args = parser.parse_args() - with open(args.input) as f: - raw_file = f.read() - - version = parse_configure_raw(raw_file) - - if args.major: - print(version[0]) - elif args.minor: - print(version[1]) - elif args.patch: - print(version[2]) - elif args.soversion: - # Convert libtool version_info to the library suffix. - # (current,revision, age) -> (current - age, age, revision) - print( - "%d.%s.%s" - % (int(version[0]) - int(version[2]), version[2], version[1]) - ) - else: - print("%s.%s.%s" % version) - - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/freetype/builds/meson/generate_reference_docs.py b/freetype/builds/meson/generate_reference_docs.py deleted file mode 100644 index 4208bb6..0000000 --- a/freetype/builds/meson/generate_reference_docs.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2020-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -"""Generate FreeType reference documentation.""" - -from __future__ import print_function - -import argparse -import glob -import os -import subprocess -import sys - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - - parser.add_argument( - "--input-dir", - required=True, - help="Top-level FreeType source directory.", - ) - - parser.add_argument( - "--version", required=True, help='FreeType version (e.g. "2.x.y").' - ) - - parser.add_argument( - "--output-dir", required=True, help="Output directory." - ) - - args = parser.parse_args() - - # Get the list of input files of interest. - include_dir = os.path.join(args.input_dir, "include") - include_config_dir = os.path.join(include_dir, "config") - include_cache_dir = os.path.join(include_dir, "cache") - - all_headers = ( - glob.glob(os.path.join(args.input_dir, "include", "freetype", "*.h")) - + glob.glob( - os.path.join( - args.input_dir, "include", "freetype", "config", "*.h" - ) - ) - + glob.glob( - os.path.join( - args.input_dir, "include", "freetype", "cache", "*.h" - ) - ) - ) - - if not os.path.exists(args.output_dir): - os.makedirs(args.output_dir) - else: - assert os.path.isdir(args.output_dir), ( - "Not a directory: " + args.output_dir - ) - - cmds = [ - sys.executable, - "-m", - "docwriter", - "--prefix=ft2", - "--title=FreeType-" + args.version, - "--site=reference", - "--output=" + args.output_dir, - ] + all_headers - - print("Running docwriter...") - subprocess.check_call(cmds) - - print("Building static site...") - subprocess.check_call( - [sys.executable, "-m", "mkdocs", "build"], cwd=args.output_dir - ) - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/freetype/builds/meson/parse_modules_cfg.py b/freetype/builds/meson/parse_modules_cfg.py deleted file mode 100644 index d48129f..0000000 --- a/freetype/builds/meson/parse_modules_cfg.py +++ /dev/null @@ -1,177 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2020-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -"""Parse modules.cfg and dump its output either as ftmodule.h or a list of -base extensions. -""" - -from __future__ import print_function - -import argparse -import os -import re -import sys - -# Expected input: -# -# ... -# FONT_MODULES += -# HINTING_MODULES += -# RASTER_MODULES += -# AUX_MODULES += -# BASE_EXTENSIONS += -# ... - - -def parse_modules_cfg(input_file): - - lists = { - "FONT_MODULES": [], - "HINTING_MODULES": [], - "RASTER_MODULES": [], - "AUX_MODULES": [], - "BASE_EXTENSIONS": [], - } - - for line in input_file.splitlines(): - line = line.rstrip() - # Ignore empty lines and those that start with a comment. - if not line or line[0] == "#": - continue - - items = line.split() - assert len(items) == 3 and items[1] == "+=", ( - "Unexpected input line [%s]" % line - ) - assert items[0] in lists, ( - "Unexpected configuration variable name " + items[0] - ) - - lists[items[0]].append(items[2]) - - return lists - - -def generate_ftmodule(lists): - result = "/* This is a generated file. */\n" - for driver in lists["FONT_MODULES"]: - if driver == "sfnt": # Special case for the sfnt 'driver'. - result += "FT_USE_MODULE( FT_Module_Class, sfnt_module_class )\n" - continue - - name = { - "truetype": "tt", - "type1": "t1", - "cid": "t1cid", - "type42": "t42", - "winfonts": "winfnt", - }.get(driver, driver) - result += ( - "FT_USE_MODULE( FT_Driver_ClassRec, %s_driver_class )\n" % name - ) - - for module in lists["HINTING_MODULES"]: - result += ( - "FT_USE_MODULE( FT_Module_Class, %s_module_class )\n" % module - ) - - for module in lists["RASTER_MODULES"]: - names = { - "raster": ("ft_raster1",), - "smooth": ("ft_smooth",), - "svg": ("ft_svg",), - "sdf": ("ft_sdf", "ft_bitmap_sdf"), - }.get(module) - for name in names: - result += ( - "FT_USE_MODULE( FT_Renderer_Class, %s_renderer_class )\n" % name - ) - - for module in lists["AUX_MODULES"]: - if module in ("psaux", "psnames", "otvalid", "gxvalid"): - name = { - "gxvalid": "gxv", - "otvalid": "otv", - }.get(module, module) - result += ( - "FT_USE_MODULE( FT_Module_Class, %s_module_class )\n" % name - ) - - result += "/* EOF */\n" - return result - - -def generate_main_modules(lists): - return "\n".join( - lists["FONT_MODULES"] - + lists["HINTING_MODULES"] - + lists["RASTER_MODULES"] - ) - - -def generate_aux_modules(lists): - return "\n".join(lists["AUX_MODULES"]) - - -def generate_base_extensions(lists): - return "\n".join(lists["BASE_EXTENSIONS"]) - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - - parser.add_argument( - "--format", - required=True, - choices=( - "ftmodule.h", - "main-modules", - "aux-modules", - "base-extensions-list", - ), - help="Select output format.", - ) - - parser.add_argument( - "input", - metavar="CONFIGURE_RAW", - help="The input configure.raw file to parse.", - ) - - parser.add_argument("--output", help="Output file (default is stdout).") - - args = parser.parse_args() - with open(args.input) as f: - input_data = f.read() - - lists = parse_modules_cfg(input_data) - - if args.format == "ftmodule.h": - result = generate_ftmodule(lists) - elif args.format == "main-modules": - result = generate_main_modules(lists) - elif args.format == "aux-modules": - result = generate_aux_modules(lists) - elif args.format == "base-extensions-list": - result = generate_base_extensions(lists) - else: - assert False, "Invalid output format!" - - if args.output: - with open(args.output, "w") as f: - f.write(result) - else: - print(result) - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/freetype/builds/meson/process_ftoption_h.py b/freetype/builds/meson/process_ftoption_h.py deleted file mode 100644 index 98daa8c..0000000 --- a/freetype/builds/meson/process_ftoption_h.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2020-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -"""Toggle settings in `ftoption.h` file based on command-line arguments. - -This script takes an `ftoption.h` file as input and rewrites -`#define`/`#undef` lines in it based on `--enable=CONFIG_VARNAME` or -`--disable=CONFIG_VARNAME` arguments passed to it, where `CONFIG_VARNAME` is -configuration variable name, such as `FT_CONFIG_OPTION_USE_LZW`, that may -appear in the file. - -Note that if one of `CONFIG_VARNAME` is not found in the input file, this -script exits with an error message listing the missing variable names. -""" - -import argparse -import os -import re -import sys - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - - parser.add_argument( - "input", metavar="FTOPTION_H", help="Path to input ftoption.h file." - ) - - parser.add_argument("--output", help="Output to file instead of stdout.") - - parser.add_argument( - "--enable", - action="append", - default=[], - help="Enable a given build option (e.g. FT_CONFIG_OPTION_USE_LZW).", - ) - - parser.add_argument( - "--disable", - action="append", - default=[], - help="Disable a given build option.", - ) - - args = parser.parse_args() - - common_options = set(args.enable) & set(args.disable) - if common_options: - parser.error( - "Options cannot be both enabled and disabled: %s" - % sorted(common_options) - ) - return 1 - - with open(args.input) as f: - input_file = f.read() - - options_seen = set() - - new_lines = [] - for line in input_file.splitlines(): - # Expected formats: - # #define - # /* #define */ - # #undef - line = line.rstrip() - if line.startswith("/* #define ") and line.endswith(" */"): - option_name = line[11:-3].strip() - option_enabled = False - elif line.startswith("#define "): - option_name = line[8:].strip() - option_enabled = True - elif line.startswith("#undef "): - option_name = line[7:].strip() - option_enabled = False - else: - new_lines.append(line) - continue - - options_seen.add(option_name) - if option_enabled and option_name in args.disable: - line = "#undef " + option_name - elif not option_enabled and option_name in args.enable: - line = "#define " + option_name - new_lines.append(line) - - result = "\n".join(new_lines) + "\n" - - # Sanity check that all command-line options were actually processed. - cmdline_options = set(args.enable) | set(args.disable) - assert cmdline_options.issubset( - options_seen - ), "Could not find options in input file: " + ", ".join( - sorted(cmdline_options - options_seen) - ) - - if args.output: - with open(args.output, "w") as f: - f.write(result) - else: - print(result) - - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/freetype/builds/modules.mk b/freetype/builds/modules.mk deleted file mode 100644 index a75baaf..0000000 --- a/freetype/builds/modules.mk +++ /dev/null @@ -1,79 +0,0 @@ -# -# FreeType 2 modules sub-Makefile -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# DO NOT INVOKE THIS MAKEFILE DIRECTLY! IT IS MEANT TO BE INCLUDED BY -# OTHER MAKEFILES. - - -# This file is in charge of handling the generation of the modules list -# file. - - -# Build the modules list. -# -$(FTMODULE_H): $(MODULES_CFG) - $(FTMODULE_H_INIT) - $(FTMODULE_H_CREATE) - $(FTMODULE_H_DONE) - -ifneq ($(findstring $(PLATFORM),dos windows os2),) - OPEN_MODULE := @echo$(space) - CLOSE_MODULE := >> $(subst /,$(SEP),$(FTMODULE_H)) - REMOVE_MODULE := @-$(DELETE) $(subst /,$(SEP),$(FTMODULE_H)) -else - OPEN_MODULE := @echo " - CLOSE_MODULE := " >> $(FTMODULE_H) - REMOVE_MODULE := @-$(DELETE) $(FTMODULE_H) -endif - - -define FTMODULE_H_INIT -$(REMOVE_MODULE) -$(info Generating modules list in $(FTMODULE_H)...) -$(OPEN_MODULE)/* This is a generated file. */$(CLOSE_MODULE) -endef - -# It is no mistake that the final closing parenthesis is on the -# next line -- it produces proper newlines during the expansion -# of `foreach'. -# -define FTMODULE_H_CREATE -$(foreach COMMAND,$(FTMODULE_H_COMMANDS),$($(COMMAND)) -) -endef - -define FTMODULE_H_DONE -$(OPEN_MODULE)/* EOF */$(CLOSE_MODULE) -$(info done.) -endef - - -# $(OPEN_DRIVER) & $(CLOSE_DRIVER) are used to specify a given font driver -# in the `module.mk' rules file. -# -OPEN_DRIVER := $(OPEN_MODULE)FT_USE_MODULE( -CLOSE_DRIVER := )$(CLOSE_MODULE) - -ECHO_DRIVER := @echo "* module:$(space) -ECHO_DRIVER_DESC := ( -ECHO_DRIVER_DONE := )" - -# Each `module.mk' in the `src/*' subdirectories adds a variable with -# commands to $(FTMODULE_H_COMMANDS). Note that we can't use SRC_DIR here. -# --include $(patsubst %,$(TOP_DIR)/src/%/module.mk,$(MODULES)) - - -# EOF diff --git a/freetype/builds/os2/detect.mk b/freetype/builds/os2/detect.mk deleted file mode 100644 index afdba74..0000000 --- a/freetype/builds/os2/detect.mk +++ /dev/null @@ -1,81 +0,0 @@ -# -# FreeType 2 configuration file to detect an OS/2 host platform. -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -.PHONY: setup - - -ifeq ($(PLATFORM),ansi) - - ifdef OS2_SHELL - - PLATFORM := os2 - - endif # test OS2_SHELL -endif - -ifeq ($(PLATFORM),os2) - - COPY := copy - DELETE := del - CAT := type - SEP := $(BACKSLASH) - - # gcc-emx by default - CONFIG_FILE := os2-gcc.mk - - # additionally, we provide hooks for various other compilers - # - ifneq ($(findstring visualage,$(MAKECMDGOALS)),) # Visual Age C++ - CONFIG_FILE := os2-icc.mk - CC := icc - - .PHONY: visualage - visualage: setup - @cd . - endif - - ifneq ($(findstring watcom,$(MAKECMDGOALS)),) # Watcom C/C++ - CONFIG_FILE := os2-wat.mk - CC := wcc386 - - .PHONY: watcom - watcom: setup - @cd . - endif - - ifneq ($(findstring borlandc,$(MAKECMDGOALS)),) # Borland C++ 32-bit - CONFIG_FILE := os2-bcc.mk - CC := bcc32 - - .PHONY: borlandc - borlandc: setup - @cd . - endif - - ifneq ($(findstring devel,$(MAKECMDGOALS)),) # development target - CONFIG_FILE := os2-dev.mk - CC := gcc - - .PHONY: devel - devel: setup - @cd . - endif - - setup: std_setup - -endif # test PLATFORM os2 - - -# EOF diff --git a/freetype/builds/os2/os2-def.mk b/freetype/builds/os2/os2-def.mk deleted file mode 100644 index 917ef2d..0000000 --- a/freetype/builds/os2/os2-def.mk +++ /dev/null @@ -1,48 +0,0 @@ -# -# FreeType 2 OS/2 specific definitions -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -DELETE := del -CAT := type -SEP := $(strip \ ) -PLATFORM_DIR := $(TOP_DIR)/builds/os2 -PLATFORM := os2 - -# This is used for `make refdoc' and `make refdoc-venv' -# -BIN := Scripts - -# The executable file extension (for tools), *with* leading dot. -# -E := .exe - -# The directory where all library files are placed. -# -# By default, this is the same as $(OBJ_DIR); however, this can be changed -# to suit particular needs. -# -LIB_DIR := $(OBJ_DIR) - -# The name of the final library file. Note that the DOS-specific Makefile -# uses a shorter (8.3) name. -# -LIBRARY := $(PROJECT) - - -# The NO_OUTPUT macro is used to ignore the output of commands. -# -NO_OUTPUT = 2> nul - - -# EOF diff --git a/freetype/builds/os2/os2-dev.mk b/freetype/builds/os2/os2-dev.mk deleted file mode 100644 index 3584fb6..0000000 --- a/freetype/builds/os2/os2-dev.mk +++ /dev/null @@ -1,30 +0,0 @@ -# -# FreeType 2 configuration rules for OS/2 + GCC -# -# Development version without optimizations. -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -DEVEL_DIR := $(TOP_DIR)/devel - -# include OS/2-specific definitions -include $(TOP_DIR)/builds/os2/os2-def.mk - -# include gcc-specific definitions -include $(TOP_DIR)/builds/compiler/gcc-dev.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/os2/os2-gcc.mk b/freetype/builds/os2/os2-gcc.mk deleted file mode 100644 index e17c5be..0000000 --- a/freetype/builds/os2/os2-gcc.mk +++ /dev/null @@ -1,26 +0,0 @@ -# -# FreeType 2 configuration rules for the OS/2 + gcc -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# include OS/2-specific definitions -include $(TOP_DIR)/builds/os2/os2-def.mk - -# include gcc-specific definitions -include $(TOP_DIR)/builds/compiler/gcc.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/symbian/bld.inf b/freetype/builds/symbian/bld.inf deleted file mode 100644 index 6168922..0000000 --- a/freetype/builds/symbian/bld.inf +++ /dev/null @@ -1,72 +0,0 @@ -// -// FreeType 2 project for the symbian platform -// - -// Copyright (C) 2008-2023 by -// David Turner, Robert Wilhelm, and Werner Lemberg. -// -// This file is part of the FreeType project, and may only be used, modified, -// and distributed under the terms of the FreeType project license, -// LICENSE.TXT. By continuing to use, modify, or distribute this file you -// indicate that you have read the license and understand and accept it -// fully. - -PRJ_PLATFORMS -DEFAULT - -PRJ_MMPFILES -freetype.mmp - -PRJ_EXPORTS -../../include/freetype/ft2build.h -../../include/freetype/config/ftconfig.h config/ftconfig.h -../../include/freetype/config/ftheader.h config/ftheader.h -../../include/freetype/config/ftmodule.h config/ftmodule.h -../../include/freetype/config/ftoption.h config/ftoption.h -../../include/freetype/config/ftstdlib.h config/ftstdlib.h -../../include/freetype/freetype.h freetype.h -../../include/freetype/ftadvanc.h ftadvanc.h -../../include/freetype/ftautoh.h ftautoh.h -../../include/freetype/ftbbox.h ftbbox.h -../../include/freetype/ftbdf.h ftbdf.h -../../include/freetype/ftbitmap.h ftbitmap.h -../../include/freetype/ftbzip2.h ftbzip2.h -../../include/freetype/ftcache.h ftcache.h -../../include/freetype/ftcffdrv.h ftcffdrv.h -../../include/freetype/ftcid.h ftcid.h -../../include/freetype/fterrdef.h fterrdef.h -../../include/freetype/fterrors.h fterrors.h -../../include/freetype/ftfntfmt.h ftfntfmt.h -../../include/freetype/ftgasp.h ftgasp.h -../../include/freetype/ftglyph.h ftglyph.h -../../include/freetype/ftgxval.h ftgxval.h -../../include/freetype/ftgzip.h ftgzip.h -../../include/freetype/ftimage.h ftimage.h -../../include/freetype/ftincrem.h ftincrem.h -../../include/freetype/ftlcdfil.h ftlcdfil.h -../../include/freetype/ftlist.h ftlist.h -../../include/freetype/ftlzw.h ftlzw.h -../../include/freetype/ftmac.h ftmac.h -../../include/freetype/ftmm.h ftmm.h -../../include/freetype/ftmodapi.h ftmodapi.h -../../include/freetype/ftmoderr.h ftmoderr.h -../../include/freetype/ftotval.h ftotval.h -../../include/freetype/ftoutln.h ftoutln.h -../../include/freetype/ftparams.h ftparams.h -../../include/freetype/ftpcfdrv.h ftpcfdrv.h -../../include/freetype/ftpfr.h ftpfr.h -../../include/freetype/ftrender.h ftrender.h -../../include/freetype/ftsizes.h ftsizes.h -../../include/freetype/ftsnames.h ftsnames.h -../../include/freetype/ftstroke.h ftstroke.h -../../include/freetype/ftsynth.h ftsynth.h -../../include/freetype/ftsystem.h ftsystem.h -../../include/freetype/ftt1drv.h ftt1drv.h -../../include/freetype/fttrigon.h fttrigon.h -../../include/freetype/ftttdrv.h ftttdrv.h -../../include/freetype/fttypes.h fttypes.h -../../include/freetype/ftwinfnt.h ftwinfnt.h -../../include/freetype/t1tables.h t1tables.h -../../include/freetype/ttnameid.h ttnameid.h -../../include/freetype/tttables.h tttables.h -../../include/freetype/tttags.h tttags.h diff --git a/freetype/builds/symbian/freetype.mmp b/freetype/builds/symbian/freetype.mmp deleted file mode 100644 index 297678e..0000000 --- a/freetype/builds/symbian/freetype.mmp +++ /dev/null @@ -1,146 +0,0 @@ -// -// FreeType 2 makefile for the symbian platform -// - -// Copyright (C) 2008-2023 by -// David Turner, Robert Wilhelm, and Werner Lemberg. -// -// This file is part of the FreeType project, and may only be used, modified, -// and distributed under the terms of the FreeType project license, -// LICENSE.TXT. By continuing to use, modify, or distribute this file you -// indicate that you have read the license and understand and accept it -// fully. - -target freetype.lib -targettype lib - -macro NDEBUG -macro FT2_BUILD_LIBRARY - -sourcepath ..\..\src\autofit - -source autofit.c - -sourcepath ..\..\src\base - -source ftbase.c -source ftbbox.c -source ftbdf.c -source ftbitmap.c -source ftcid.c -source ftfstype.c -source ftgasp.c -source ftglyph.c -source ftgxval.c -source ftinit.c -source ftmm.c -source ftotval.c -source ftpatent.c -source ftpfr.c -source ftstroke.c -source ftsynth.c -source ftsystem.c -source fttype1.c -source ftwinfnt.c - -sourcepath ..\..\src\bdf - -source bdf.c - -sourcepath ..\..\src\bzip2 - -source ftbzip2.c - -sourcepath ..\..\src\cache - -source ftcache.c - -sourcepath ..\..\src\cff - -source cff.c - -sourcepath ..\..\src\cid - -source type1cid.c - -sourcepath ..\..\src\gzip - -source ftgzip.c - -sourcepath ..\..\src\lzw - -source ftlzw.c - -sourcepath ..\..\src\pcf - -source pcf.c - -sourcepath ..\..\src\pfr - -source pfr.c - -sourcepath ..\..\src\psaux - -source psaux.c - -sourcepath ..\..\src\pshinter - -source pshinter.c - -sourcepath ..\..\src\psnames - -source psmodule.c - -sourcepath ..\..\src\raster - -source raster.c - -sourcepath ..\..\src\sfnt - -source sfnt.c - -sourcepath ..\..\src\smooth - -source smooth.c - -sourcepath ..\..\src\truetype - -source truetype.c - -sourcepath ..\..\src\type1 - -source type1.c - -sourcepath ..\..\src\type42 - -source type42.c - -sourcepath ..\..\src\winfonts - -source winfnt.c - - -systeminclude ..\..\include -systeminclude \epoc32\include\stdapis -userinclude ..\..\src\autofit -userinclude ..\..\src\bdf -userinclude ..\..\src\bzip2 -userinclude ..\..\src\cache -userinclude ..\..\src\cff -userinclude ..\..\src\cid -userinclude ..\..\src\gxvalid -userinclude ..\..\src\gzip -userinclude ..\..\src\lzw -userinclude ..\..\src\otvalid -userinclude ..\..\src\pcf -userinclude ..\..\src\pfr -userinclude ..\..\src\psaux -userinclude ..\..\src\pshinter -userinclude ..\..\src\psnames -userinclude ..\..\src\raster -userinclude ..\..\src\sfnt -userinclude ..\..\src\smooth -userinclude ..\..\src\truetype -userinclude ..\..\src\type1 -userinclude ..\..\src\type42 -userinclude ..\..\src\winfonts diff --git a/freetype/builds/toplevel.mk b/freetype/builds/toplevel.mk deleted file mode 100644 index 8d5063e..0000000 --- a/freetype/builds/toplevel.mk +++ /dev/null @@ -1,317 +0,0 @@ -# -# FreeType build system -- top-level sub-Makefile -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# This file is designed for GNU Make, do not use it with another Make tool! -# -# It works as follows: -# -# - When invoked for the first time, this Makefile includes the rules found -# in `PROJECT/builds/detect.mk'. They are in charge of detecting the -# current platform. -# -# A summary of the detection is displayed, and the file `config.mk' is -# created in the current directory. -# -# - When invoked later, this Makefile includes the rules found in -# `config.mk'. This sub-Makefile defines some system-specific variables -# (like compiler, compilation flags, object suffix, etc.), then includes -# the rules found in `PROJECT/builds/PROJECT.mk', used to build the -# library. -# -# See the comments in `builds/detect.mk' and `builds/PROJECT.mk' for more -# details on host platform detection and library builds. - - -# First of all, check whether we have `$(value ...)'. We do this by testing -# for `$(eval ...)' which has been introduced in the same GNU make version. - -eval_available := -$(eval eval_available := T) -ifneq ($(eval_available),T) - $(error FreeType's build system needs a Make program which supports $$(value)) -endif - - -.PHONY: all dist distclean modules setup - - -# The `space' variable is used to avoid trailing spaces in defining the -# `T' variable later. -# -empty := -space := $(empty) $(empty) - - -# The main configuration file, defining the `XXX_MODULES' variables. We -# prefer a `modules.cfg' file in OBJ_DIR over TOP_DIR. -# -ifndef MODULES_CFG - MODULES_CFG := $(TOP_DIR)/modules.cfg - ifneq ($(wildcard $(OBJ_DIR)/modules.cfg),) - MODULES_CFG := $(OBJ_DIR)/modules.cfg - endif -endif - - -# FTMODULE_H, as its name suggests, indicates where the FreeType module -# class file resides. -# -FTMODULE_H ?= $(OBJ_DIR)/ftmodule.h - - -include $(MODULES_CFG) - - -# The list of modules we are using. -# -MODULES := $(FONT_MODULES) \ - $(HINTING_MODULES) \ - $(RASTER_MODULES) \ - $(AUX_MODULES) - - -CONFIG_MK ?= config.mk - -# If no configuration sub-makefile is present, or if `setup' is the target -# to be built, run the auto-detection rules to figure out which -# configuration rules file to use. -# -# Note that the configuration file is put in the current directory, which is -# not necessarily $(TOP_DIR). - -# If `config.mk' is not present, set `check_platform'. -# -ifeq ($(wildcard $(CONFIG_MK)),) - check_platform := 1 -endif - -# If `setup' is one of the targets requested, set `check_platform'. -# -ifneq ($(findstring setup,$(MAKECMDGOALS)),) - check_platform := 1 -endif - - -# Include the automatic host platform detection rules when we need to -# check the platform. -# -ifdef check_platform - - all modules: setup - - include $(TOP_DIR)/builds/detect.mk - - # For builds directly from the git repository we need to copy files - # from `subprojects/dlg' to `src/dlg' and `include/dlg'. - # - ifeq ($(wildcard $(TOP_DIR)/src/dlg/dlg.*),) - ifeq ($(wildcard $(TOP_DIR)/subprojects/dlg/*),) - copy_submodule: check_out_submodule - endif - - setup: copy_submodule - endif - - # This rule makes sense for Unix only to remove files created by a run of - # the configure script which hasn't been successful (so that no - # `config.mk' has been created). It uses the built-in $(RM) command of - # GNU make. Similarly, `nul' is created if e.g. `make setup windows' has - # been erroneously used. - # - # Note: This test is duplicated in `builds/unix/detect.mk'. - # - is_unix := $(strip $(wildcard /sbin/init) \ - $(wildcard /usr/sbin/init) \ - $(wildcard /dev/null) \ - $(wildcard /hurd/auth)) - ifneq ($(is_unix),) - - distclean: - $(RM) $(TOP_DIR)/builds/unix/config.cache - $(RM) $(TOP_DIR)/builds/unix/config.log - $(RM) $(TOP_DIR)/builds/unix/config.status - $(RM) $(TOP_DIR)/builds/unix/unix-def.mk - $(RM) $(TOP_DIR)/builds/unix/unix-cc.mk - $(RM) $(TOP_DIR)/builds/unix/freetype2.pc - $(RM) nul - - endif # test is_unix - - # IMPORTANT: - # - # `setup' must be defined by the host platform detection rules to create - # the `config.mk' file in the current directory. - -else - - # A configuration sub-Makefile is present -- simply run it. - # - all: single - - BUILD_PROJECT := yes - include $(CONFIG_MK) - -endif # test check_platform - - -.PHONY: check_out_submodule copy_submodule - -check_out_submodule: - $(info Checking out submodule in `subprojects/dlg') - git --git-dir=$(TOP_DIR) submodule init - git --git-dir=$(TOP_DIR) submodule update - -copy_submodule: - $(info Copying files from `subprojects/dlg' to `src/dlg' and `include/dlg') - ifeq ($(wildcard $(TOP_DIR)/include/dlg),) - mkdir $(subst /,$(SEP),$(TOP_DIR)/include/dlg) - endif - $(COPY) $(subst /,$(SEP),$(TOP_DIR)/subprojects/dlg/include/dlg/output.h $(TOP_DIR)/include/dlg) - $(COPY) $(subst /,$(SEP),$(TOP_DIR)/subprojects/dlg/include/dlg/dlg.h $(TOP_DIR)/include/dlg) - $(COPY) $(subst /,$(SEP),$(TOP_DIR)/subprojects/dlg/src/dlg/dlg.c $(TOP_DIR)/src/dlg) - - -# We always need the list of modules in ftmodule.h. -# -all setup: $(FTMODULE_H) - - -# The `modules' target unconditionally rebuilds the module list. -# -modules: - $(FTMODULE_H_INIT) - $(FTMODULE_H_CREATE) - $(FTMODULE_H_DONE) - -include $(TOP_DIR)/builds/modules.mk - - -# get FreeType version string using built-in string functions -# -hash := \# - -work := $(strip $(shell $(CAT) \ - $(subst /,$(SEP),$(TOP_DIR)/include/freetype/freetype.h))) - -work := $(subst $(hash)define$(space)FREETYPE_MAJOR$(space),MAjOR=,$(work)) -work := $(subst $(hash)define$(space)FREETYPE_MINOR$(space),MInOR=,$(work)) -work := $(subst $(hash)define$(space)FREETYPE_PATCH$(space),PAtCH=,$(work)) - -major := $(subst MAjOR=,,$(filter MAjOR=%,$(work))) -minor := $(subst MInOR=,,$(filter MInOR=%,$(work))) -patch := $(subst PAtCH=,,$(filter PAtCH=%,$(work))) - -work := - -# ifneq ($(findstring x0x,x$(patch)x),) -# version := $(major).$(minor) -# winversion := $(major)$(minor) -# else - version := $(major).$(minor).$(patch) - winversion := $(major)$(minor)$(patch) - version_tag := VER-$(major)-$(minor)-$(patch) -# endif - - -# This target builds the tarballs. -# -# Not to be run by a normal user -- there are no attempts to make it -# generic. - -dist: - -rm -rf tmp - rm -f freetype-$(version).tar.gz - rm -f freetype-$(version).tar.xz - rm -f ft$(winversion).zip - - for d in `find . -wholename '*/.git' -prune \ - -o -type f \ - -o -print` ; do \ - mkdir -p tmp/$$d ; \ - done ; - - currdir=`pwd` ; \ - for f in `find . -wholename '*/.git' -prune \ - -o -name .gitattributes \ - -o -name .gitignore \ - -o -name .gitlab-ci.yml \ - -o -name .gitmodules \ - -o -name .mailmap \ - -o -type d \ - -o -print` ; do \ - ln -s $$currdir/$$f tmp/$$f ; \ - done - - cd tmp ; \ - $(MAKE) devel ; \ - $(MAKE) do-dist - - mv tmp freetype-$(version) - - tar -H ustar -chf - freetype-$(version) \ - | gzip -9 -c > freetype-$(version).tar.gz - tar -H ustar -chf - freetype-$(version) \ - | xz -c > freetype-$(version).tar.xz - - @# Use CR/LF for zip files. - zip -lr9 ft$(winversion).zip freetype-$(version) - - rm -fr freetype-$(version) - - -# The locations of the latest `config.guess' and `config.sub' versions (from -# GNU `config' git repository), relative to the `tmp' directory used during -# `make dist'. -# -CONFIG_GUESS = ~/git/config/config.guess -CONFIG_SUB = ~/git/config/config.sub - -# We also use this repository to access the gnulib script that converts git -# commit messages to a ChangeLog file. -CHANGELOG_SCRIPT = ~/git/config/gitlog-to-changelog - - -# Don't say `make do-dist'. Always use `make dist' instead. -# -.PHONY: do-dist - -do-dist: distclean refdoc - @# Without removing the files, `autoconf' and friends follow links. - rm -f $(TOP_DIR)/builds/unix/aclocal.m4 - rm -f $(TOP_DIR)/builds/unix/configure.ac - rm -f $(TOP_DIR)/builds/unix/configure - - sh autogen.sh - rm -rf $(TOP_DIR)/builds/unix/autom4te.cache - - cp $(CONFIG_GUESS) $(TOP_DIR)/builds/unix - cp $(CONFIG_SUB) $(TOP_DIR)/builds/unix - - @# Generate `ChangeLog' file with commits since release 2.11.0 - @# (when we stopped creating this file manually). - $(CHANGELOG_SCRIPT) \ - --format='%B%n' \ - --no-cluster \ - -- VER-2-11-0..$(version_tag) \ - > ChangeLog - - @# Remove intermediate files created by the `refdoc' target. - rm -rf $(TOP_DIR)/docs/markdown - rm -f $(TOP_DIR)/docs/mkdocs.yml - - @# Remove more stuff related to git. - rm -rf $(TOP_DIR)/subprojects/dlg - -# EOF diff --git a/freetype/builds/unix/.gitignore b/freetype/builds/unix/.gitignore deleted file mode 100644 index f89b226..0000000 --- a/freetype/builds/unix/.gitignore +++ /dev/null @@ -1,18 +0,0 @@ -aclocal.m4 -autom4te.cache -config.cache -config.guess -config.log -config.status -config.sub -configure -configure.ac -freetype2.pc -freetype-config -ftconfig.h -ftoption.h -install-sh -libtool -ltmain.sh -unix-cc.mk -unix-def.mk diff --git a/freetype/builds/unix/ax_compare_version.m4 b/freetype/builds/unix/ax_compare_version.m4 deleted file mode 100644 index ffb4997..0000000 --- a/freetype/builds/unix/ax_compare_version.m4 +++ /dev/null @@ -1,177 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_compare_version.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) -# -# DESCRIPTION -# -# This macro compares two version strings. Due to the various number of -# minor-version numbers that can exist, and the fact that string -# comparisons are not compatible with numeric comparisons, this is not -# necessarily trivial to do in a autoconf script. This macro makes doing -# these comparisons easy. -# -# The six basic comparisons are available, as well as checking equality -# limited to a certain number of minor-version levels. -# -# The operator OP determines what type of comparison to do, and can be one -# of: -# -# eq - equal (test A == B) -# ne - not equal (test A != B) -# le - less than or equal (test A <= B) -# ge - greater than or equal (test A >= B) -# lt - less than (test A < B) -# gt - greater than (test A > B) -# -# Additionally, the eq and ne operator can have a number after it to limit -# the test to that number of minor versions. -# -# eq0 - equal up to the length of the shorter version -# ne0 - not equal up to the length of the shorter version -# eqN - equal up to N sub-version levels -# neN - not equal up to N sub-version levels -# -# When the condition is true, shell commands ACTION-IF-TRUE are run, -# otherwise shell commands ACTION-IF-FALSE are run. The environment -# variable 'ax_compare_version' is always set to either 'true' or 'false' -# as well. -# -# Examples: -# -# AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8]) -# AX_COMPARE_VERSION([3.15],[lt],[3.15.8]) -# -# would both be true. -# -# AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8]) -# AX_COMPARE_VERSION([3.15],[gt],[3.15.8]) -# -# would both be false. -# -# AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8]) -# -# would be true because it is only comparing two minor versions. -# -# AX_COMPARE_VERSION([3.15.7],[eq0],[3.15]) -# -# would be true because it is only comparing the lesser number of minor -# versions of the two values. -# -# Note: The characters that separate the version numbers do not matter. An -# empty string is the same as version 0. OP is evaluated by autoconf, not -# configure, so must be a string, not a variable. -# -# The author would like to acknowledge Guido Draheim whose advice about -# the m4_case and m4_ifvaln functions make this macro only include the -# portions necessary to perform the specific comparison specified by the -# OP argument in the final configure script. -# -# LICENSE -# -# Copyright (c) 2008 Tim Toolan -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 13 - -dnl ######################################################################### -AC_DEFUN([AX_COMPARE_VERSION], [ - AC_REQUIRE([AC_PROG_AWK]) - - # Used to indicate true or false condition - ax_compare_version=false - - # Convert the two version strings to be compared into a format that - # allows a simple string comparison. The end result is that a version - # string of the form 1.12.5-r617 will be converted to the form - # 0001001200050617. In other words, each number is zero padded to four - # digits, and non digits are removed. - AS_VAR_PUSHDEF([A],[ax_compare_version_A]) - A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ - -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ - -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ - -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ - -e 's/[[^0-9]]//g'` - - AS_VAR_PUSHDEF([B],[ax_compare_version_B]) - B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ - -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ - -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ - -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ - -e 's/[[^0-9]]//g'` - - dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary - dnl # then the first line is used to determine if the condition is true. - dnl # The sed right after the echo is to remove any indented white space. - m4_case(m4_tolower($2), - [lt],[ - ax_compare_version=`echo "x$A -x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` - ], - [gt],[ - ax_compare_version=`echo "x$A -x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` - ], - [le],[ - ax_compare_version=`echo "x$A -x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` - ], - [ge],[ - ax_compare_version=`echo "x$A -x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` - ],[ - dnl Split the operator from the subversion count if present. - m4_bmatch(m4_substr($2,2), - [0],[ - # A count of zero means use the length of the shorter version. - # Determine the number of characters in A and B. - ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'` - ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'` - - # Set A to no more than B's length and B to no more than A's length. - A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` - B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` - ], - [[0-9]+],[ - # A count greater than zero means use only that many subversions - A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` - B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` - ], - [.+],[ - AC_WARNING( - [invalid OP numeric parameter: $2]) - ],[]) - - # Pad zeros at end of numbers to make same length. - ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" - B="$B`echo $A | sed 's/./0/g'`" - A="$ax_compare_version_tmp_A" - - # Check for equality or inequality as necessary. - m4_case(m4_tolower(m4_substr($2,0,2)), - [eq],[ - test "x$A" = "x$B" && ax_compare_version=true - ], - [ne],[ - test "x$A" != "x$B" && ax_compare_version=true - ],[ - AC_WARNING([invalid OP parameter: $2]) - ]) - ]) - - AS_VAR_POPDEF([A])dnl - AS_VAR_POPDEF([B])dnl - - dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. - if test "$ax_compare_version" = "true" ; then - m4_ifvaln([$4],[$4],[:])dnl - m4_ifvaln([$5],[else $5])dnl - fi -]) dnl AX_COMPARE_VERSION diff --git a/freetype/builds/unix/ax_prog_python_version.m4 b/freetype/builds/unix/ax_prog_python_version.m4 deleted file mode 100644 index dbc3dbf..0000000 --- a/freetype/builds/unix/ax_prog_python_version.m4 +++ /dev/null @@ -1,66 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_prog_python_version.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_PROG_PYTHON_VERSION([VERSION],[ACTION-IF-TRUE],[ACTION-IF-FALSE]) -# -# DESCRIPTION -# -# Makes sure that python supports the version indicated. If true the shell -# commands in ACTION-IF-TRUE are executed. If not the shell commands in -# ACTION-IF-FALSE are run. Note if $PYTHON is not set (for example by -# running AC_CHECK_PROG or AC_PATH_PROG) the macro will fail. -# -# Example: -# -# AC_PATH_PROG([PYTHON],[python]) -# AX_PROG_PYTHON_VERSION([2.4.4],[ ... ],[ ... ]) -# -# This will check to make sure that the python you have supports at least -# version 2.4.4. -# -# NOTE: This macro uses the $PYTHON variable to perform the check. -# AX_WITH_PYTHON can be used to set that variable prior to running this -# macro. The $PYTHON_VERSION variable will be valorized with the detected -# version. -# -# LICENSE -# -# Copyright (c) 2009 Francesco Salvestrini -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 12 - -AC_DEFUN([AX_PROG_PYTHON_VERSION],[ - AC_REQUIRE([AC_PROG_SED]) - AC_REQUIRE([AC_PROG_GREP]) - - AS_IF([test -n "$PYTHON"],[ - ax_python_version="$1" - - AC_MSG_CHECKING([for python version]) - changequote(<<,>>) - python_version=`$PYTHON -V 2>&1 | $GREP "^Python " | $SED -e 's/^.* \([0-9]*\.[0-9]*\.[0-9]*\)/\1/'` - changequote([,]) - AC_MSG_RESULT($python_version) - - AC_SUBST([PYTHON_VERSION],[$python_version]) - - AX_COMPARE_VERSION([$ax_python_version],[le],[$python_version],[ - : - $2 - ],[ - : - $3 - ]) - ],[ - AC_MSG_WARN([could not find the python interpreter]) - $3 - ]) -]) diff --git a/freetype/builds/unix/ax_pthread.m4 b/freetype/builds/unix/ax_pthread.m4 deleted file mode 100644 index e5858e5..0000000 --- a/freetype/builds/unix/ax_pthread.m4 +++ /dev/null @@ -1,522 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_pthread.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -# -# DESCRIPTION -# -# This macro figures out how to build C programs using POSIX threads. It -# sets the PTHREAD_LIBS output variable to the threads library and linker -# flags, and the PTHREAD_CFLAGS output variable to any special C compiler -# flags that are needed. (The user can also force certain compiler -# flags/libs to be tested by setting these environment variables.) -# -# Also sets PTHREAD_CC and PTHREAD_CXX to any special C compiler that is -# needed for multi-threaded programs (defaults to the value of CC -# respectively CXX otherwise). (This is necessary on e.g. AIX to use the -# special cc_r/CC_r compiler alias.) -# -# NOTE: You are assumed to not only compile your program with these flags, -# but also to link with them as well. For example, you might link with -# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS -# $PTHREAD_CXX $CXXFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS -# -# If you are only building threaded programs, you may wish to use these -# variables in your default LIBS, CFLAGS, and CC: -# -# LIBS="$PTHREAD_LIBS $LIBS" -# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" -# CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS" -# CC="$PTHREAD_CC" -# CXX="$PTHREAD_CXX" -# -# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant -# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to -# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). -# -# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the -# PTHREAD_PRIO_INHERIT symbol is defined when compiling with -# PTHREAD_CFLAGS. -# -# ACTION-IF-FOUND is a list of shell commands to run if a threads library -# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it -# is not found. If ACTION-IF-FOUND is not specified, the default action -# will define HAVE_PTHREAD. -# -# Please let the authors know if this macro fails on any platform, or if -# you have any other suggestions or comments. This macro was based on work -# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help -# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by -# Alejandro Forero Cuervo to the autoconf macro repository. We are also -# grateful for the helpful feedback of numerous users. -# -# Updated for Autoconf 2.68 by Daniel Richard G. -# -# LICENSE -# -# Copyright (c) 2008 Steven G. Johnson -# Copyright (c) 2011 Daniel Richard G. -# Copyright (c) 2019 Marc Stevens -# -# 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 3 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, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. 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 the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. - -#serial 30 - -AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) -AC_DEFUN([AX_PTHREAD], [ -AC_REQUIRE([AC_CANONICAL_TARGET]) -AC_REQUIRE([AC_PROG_CC]) -AC_REQUIRE([AC_PROG_SED]) -AC_LANG_PUSH([C]) -ax_pthread_ok=no - -# We used to check for pthread.h first, but this fails if pthread.h -# requires special compiler flags (e.g. on Tru64 or Sequent). -# It gets checked for in the link test anyway. - -# First of all, check if the user has set any of the PTHREAD_LIBS, -# etcetera environment variables, and if threads linking works using -# them: -if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then - ax_pthread_save_CC="$CC" - ax_pthread_save_CFLAGS="$CFLAGS" - ax_pthread_save_LIBS="$LIBS" - AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"]) - AS_IF([test "x$PTHREAD_CXX" != "x"], [CXX="$PTHREAD_CXX"]) - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS]) - AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes]) - AC_MSG_RESULT([$ax_pthread_ok]) - if test "x$ax_pthread_ok" = "xno"; then - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" - fi - CC="$ax_pthread_save_CC" - CFLAGS="$ax_pthread_save_CFLAGS" - LIBS="$ax_pthread_save_LIBS" -fi - -# We must check for the threads library under a number of different -# names; the ordering is very important because some systems -# (e.g. DEC) have both -lpthread and -lpthreads, where one of the -# libraries is broken (non-POSIX). - -# Create a list of thread flags to try. Items with a "," contain both -# C compiler flags (before ",") and linker flags (after ","). Other items -# starting with a "-" are C compiler flags, and remaining items are -# library names, except for "none" which indicates that we try without -# any flags at all, and "pthread-config" which is a program returning -# the flags for the Pth emulation library. - -ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" - -# The ordering *is* (sometimes) important. Some notes on the -# individual items follow: - -# pthreads: AIX (must check this before -lpthread) -# none: in case threads are in libc; should be tried before -Kthread and -# other compiler flags to prevent continual compiler warnings -# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) -# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64 -# (Note: HP C rejects this with "bad form for `-t' option") -# -pthreads: Solaris/gcc (Note: HP C also rejects) -# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it -# doesn't hurt to check since this sometimes defines pthreads and -# -D_REENTRANT too), HP C (must be checked before -lpthread, which -# is present but should not be used directly; and before -mthreads, -# because the compiler interprets this as "-mt" + "-hreads") -# -mthreads: Mingw32/gcc, Lynx/gcc -# pthread: Linux, etcetera -# --thread-safe: KAI C++ -# pthread-config: use pthread-config program (for GNU Pth library) - -case $target_os in - - freebsd*) - - # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) - # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) - - ax_pthread_flags="-kthread lthread $ax_pthread_flags" - ;; - - hpux*) - - # From the cc(1) man page: "[-mt] Sets various -D flags to enable - # multi-threading and also sets -lpthread." - - ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags" - ;; - - openedition*) - - # IBM z/OS requires a feature-test macro to be defined in order to - # enable POSIX threads at all, so give the user a hint if this is - # not set. (We don't define these ourselves, as they can affect - # other portions of the system API in unpredictable ways.) - - AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING], - [ -# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS) - AX_PTHREAD_ZOS_MISSING -# endif - ], - [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])]) - ;; - - solaris*) - - # On Solaris (at least, for some versions), libc contains stubbed - # (non-functional) versions of the pthreads routines, so link-based - # tests will erroneously succeed. (N.B.: The stubs are missing - # pthread_cleanup_push, or rather a function called by this macro, - # so we could check for that, but who knows whether they'll stub - # that too in a future libc.) So we'll check first for the - # standard Solaris way of linking pthreads (-mt -lpthread). - - ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags" - ;; -esac - -# Are we compiling with Clang? - -AC_CACHE_CHECK([whether $CC is Clang], - [ax_cv_PTHREAD_CLANG], - [ax_cv_PTHREAD_CLANG=no - # Note that Autoconf sets GCC=yes for Clang as well as GCC - if test "x$GCC" = "xyes"; then - AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG], - [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ -# if defined(__clang__) && defined(__llvm__) - AX_PTHREAD_CC_IS_CLANG -# endif - ], - [ax_cv_PTHREAD_CLANG=yes]) - fi - ]) -ax_pthread_clang="$ax_cv_PTHREAD_CLANG" - - -# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) - -# Note that for GCC and Clang -pthread generally implies -lpthread, -# except when -nostdlib is passed. -# This is problematic using libtool to build C++ shared libraries with pthread: -# [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460 -# [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333 -# [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555 -# To solve this, first try -pthread together with -lpthread for GCC - -AS_IF([test "x$GCC" = "xyes"], - [ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"]) - -# Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first - -AS_IF([test "x$ax_pthread_clang" = "xyes"], - [ax_pthread_flags="-pthread,-lpthread -pthread"]) - - -# The presence of a feature test macro requesting re-entrant function -# definitions is, on some systems, a strong hint that pthreads support is -# correctly enabled - -case $target_os in - darwin* | hpux* | linux* | osf* | solaris*) - ax_pthread_check_macro="_REENTRANT" - ;; - - aix*) - ax_pthread_check_macro="_THREAD_SAFE" - ;; - - *) - ax_pthread_check_macro="--" - ;; -esac -AS_IF([test "x$ax_pthread_check_macro" = "x--"], - [ax_pthread_check_cond=0], - [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"]) - - -if test "x$ax_pthread_ok" = "xno"; then -for ax_pthread_try_flag in $ax_pthread_flags; do - - case $ax_pthread_try_flag in - none) - AC_MSG_CHECKING([whether pthreads work without any flags]) - ;; - - *,*) - PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"` - PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"` - AC_MSG_CHECKING([whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"]) - ;; - - -*) - AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag]) - PTHREAD_CFLAGS="$ax_pthread_try_flag" - ;; - - pthread-config) - AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) - AS_IF([test "x$ax_pthread_config" = "xno"], [continue]) - PTHREAD_CFLAGS="`pthread-config --cflags`" - PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" - ;; - - *) - AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag]) - PTHREAD_LIBS="-l$ax_pthread_try_flag" - ;; - esac - - ax_pthread_save_CFLAGS="$CFLAGS" - ax_pthread_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - - # Check for various functions. We must include pthread.h, - # since some functions may be macros. (On the Sequent, we - # need a special flag -Kthread to make this header compile.) - # We check for pthread_join because it is in -lpthread on IRIX - # while pthread_create is in libc. We check for pthread_attr_init - # due to DEC craziness with -lpthreads. We check for - # pthread_cleanup_push because it is one of the few pthread - # functions on Solaris that doesn't have a non-functional libc stub. - # We try pthread_create on general principles. - - AC_LINK_IFELSE([AC_LANG_PROGRAM([#include -# if $ax_pthread_check_cond -# error "$ax_pthread_check_macro must be defined" -# endif - static void *some_global = NULL; - static void routine(void *a) - { - /* To avoid any unused-parameter or - unused-but-set-parameter warning. */ - some_global = a; - } - static void *start_routine(void *a) { return a; }], - [pthread_t th; pthread_attr_t attr; - pthread_create(&th, 0, start_routine, 0); - pthread_join(th, 0); - pthread_attr_init(&attr); - pthread_cleanup_push(routine, 0); - pthread_cleanup_pop(0) /* ; */])], - [ax_pthread_ok=yes], - []) - - CFLAGS="$ax_pthread_save_CFLAGS" - LIBS="$ax_pthread_save_LIBS" - - AC_MSG_RESULT([$ax_pthread_ok]) - AS_IF([test "x$ax_pthread_ok" = "xyes"], [break]) - - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" -done -fi - - -# Clang needs special handling, because older versions handle the -pthread -# option in a rather... idiosyncratic way - -if test "x$ax_pthread_clang" = "xyes"; then - - # Clang takes -pthread; it has never supported any other flag - - # (Note 1: This will need to be revisited if a system that Clang - # supports has POSIX threads in a separate library. This tends not - # to be the way of modern systems, but it's conceivable.) - - # (Note 2: On some systems, notably Darwin, -pthread is not needed - # to get POSIX threads support; the API is always present and - # active. We could reasonably leave PTHREAD_CFLAGS empty. But - # -pthread does define _REENTRANT, and while the Darwin headers - # ignore this macro, third-party headers might not.) - - # However, older versions of Clang make a point of warning the user - # that, in an invocation where only linking and no compilation is - # taking place, the -pthread option has no effect ("argument unused - # during compilation"). They expect -pthread to be passed in only - # when source code is being compiled. - # - # Problem is, this is at odds with the way Automake and most other - # C build frameworks function, which is that the same flags used in - # compilation (CFLAGS) are also used in linking. Many systems - # supported by AX_PTHREAD require exactly this for POSIX threads - # support, and in fact it is often not straightforward to specify a - # flag that is used only in the compilation phase and not in - # linking. Such a scenario is extremely rare in practice. - # - # Even though use of the -pthread flag in linking would only print - # a warning, this can be a nuisance for well-run software projects - # that build with -Werror. So if the active version of Clang has - # this misfeature, we search for an option to squash it. - - AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread], - [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG], - [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown - # Create an alternate version of $ac_link that compiles and - # links in two steps (.c -> .o, .o -> exe) instead of one - # (.c -> exe), because the warning occurs only in the second - # step - ax_pthread_save_ac_link="$ac_link" - ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g' - ax_pthread_link_step=`AS_ECHO(["$ac_link"]) | sed "$ax_pthread_sed"` - ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)" - ax_pthread_save_CFLAGS="$CFLAGS" - for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do - AS_IF([test "x$ax_pthread_try" = "xunknown"], [break]) - CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS" - ac_link="$ax_pthread_save_ac_link" - AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], - [ac_link="$ax_pthread_2step_ac_link" - AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], - [break]) - ]) - done - ac_link="$ax_pthread_save_ac_link" - CFLAGS="$ax_pthread_save_CFLAGS" - AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no]) - ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try" - ]) - - case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in - no | unknown) ;; - *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;; - esac - -fi # $ax_pthread_clang = yes - - - -# Various other checks: -if test "x$ax_pthread_ok" = "xyes"; then - ax_pthread_save_CFLAGS="$CFLAGS" - ax_pthread_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - - # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. - AC_CACHE_CHECK([for joinable pthread attribute], - [ax_cv_PTHREAD_JOINABLE_ATTR], - [ax_cv_PTHREAD_JOINABLE_ATTR=unknown - for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do - AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], - [int attr = $ax_pthread_attr; return attr /* ; */])], - [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break], - []) - done - ]) - AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \ - test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \ - test "x$ax_pthread_joinable_attr_defined" != "xyes"], - [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], - [$ax_cv_PTHREAD_JOINABLE_ATTR], - [Define to necessary symbol if this constant - uses a non-standard name on your system.]) - ax_pthread_joinable_attr_defined=yes - ]) - - AC_CACHE_CHECK([whether more special flags are required for pthreads], - [ax_cv_PTHREAD_SPECIAL_FLAGS], - [ax_cv_PTHREAD_SPECIAL_FLAGS=no - case $target_os in - solaris*) - ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS" - ;; - esac - ]) - AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \ - test "x$ax_pthread_special_flags_added" != "xyes"], - [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS" - ax_pthread_special_flags_added=yes]) - - AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], - [ax_cv_PTHREAD_PRIO_INHERIT], - [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], - [[int i = PTHREAD_PRIO_INHERIT; - return i;]])], - [ax_cv_PTHREAD_PRIO_INHERIT=yes], - [ax_cv_PTHREAD_PRIO_INHERIT=no]) - ]) - AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \ - test "x$ax_pthread_prio_inherit_defined" != "xyes"], - [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.]) - ax_pthread_prio_inherit_defined=yes - ]) - - CFLAGS="$ax_pthread_save_CFLAGS" - LIBS="$ax_pthread_save_LIBS" - - # More AIX lossage: compile with *_r variant - if test "x$GCC" != "xyes"; then - case $target_os in - aix*) - AS_CASE(["x/$CC"], - [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6], - [#handle absolute path differently from PATH based program lookup - AS_CASE(["x$CC"], - [x/*], - [ - AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"]) - AS_IF([test "x${CXX}" != "x"], [AS_IF([AS_EXECUTABLE_P([${CXX}_r])],[PTHREAD_CXX="${CXX}_r"])]) - ], - [ - AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC]) - AS_IF([test "x${CXX}" != "x"], [AC_CHECK_PROGS([PTHREAD_CXX],[${CXX}_r],[$CXX])]) - ] - ) - ]) - ;; - esac - fi -fi - -test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" -test -n "$PTHREAD_CXX" || PTHREAD_CXX="$CXX" - -AC_SUBST([PTHREAD_LIBS]) -AC_SUBST([PTHREAD_CFLAGS]) -AC_SUBST([PTHREAD_CC]) -AC_SUBST([PTHREAD_CXX]) - -# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: -if test "x$ax_pthread_ok" = "xyes"; then - ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1]) - : -else - ax_pthread_ok=no - $2 -fi -AC_LANG_POP -])dnl AX_PTHREAD diff --git a/freetype/builds/unix/configure.raw b/freetype/builds/unix/configure.raw deleted file mode 100644 index dc7426e..0000000 --- a/freetype/builds/unix/configure.raw +++ /dev/null @@ -1,1179 +0,0 @@ -# This file is part of the FreeType project. -# -# Process this file with autoconf to produce a configure script. -# -# Copyright (C) 2001-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -AC_INIT([FreeType], [@VERSION@], [freetype@nongnu.org], [freetype]) -AC_CONFIG_SRCDIR([ftconfig.h.in]) - - -# Don't forget to update `docs/VERSIONS.TXT'! - -version_info='26:1:20' -AC_SUBST([version_info]) -ft_version=`echo $version_info | tr : .` -AC_SUBST([ft_version]) - - -# checks for system type - -AC_CANONICAL_HOST - - -# checks for programs - -AC_PROG_CC -AC_PROG_CPP -AC_SUBST(EXEEXT) - -PKG_PROG_PKG_CONFIG([0.24]) - -LT_INIT(win32-dll) -AC_CHECK_HEADER([windows.h], [LT_PROG_RC]) - - -# checks for native programs to generate building tool - -if test ${cross_compiling} = yes; then - AC_CHECK_PROG(CC_BUILD, ${build}-gcc, ${build}-gcc) - test -z "${CC_BUILD}" && AC_CHECK_PROG(CC_BUILD, gcc, gcc) - test -z "${CC_BUILD}" && AC_CHECK_PROG(CC_BUILD, cc, cc, , , /usr/ucb/cc) - test -z "${CC_BUILD}" && AC_MSG_ERROR([cannot find native C compiler]) - - AC_MSG_CHECKING([for suffix of native executables]) - rm -f a.* b.* a_out.exe conftest.* - echo > conftest.c "int main(void) { return 0;}" - ${CC_BUILD} conftest.c || AC_MSG_ERROR([native C compiler is not working]) - rm -f conftest.c - if test -x a.out -o -x b.out -o -x conftest; then - EXEEXT_BUILD="" - elif test -x a_out.exe -o -x conftest.exe; then - EXEEXT_BUILD=".exe" - elif test -x conftest.*; then - EXEEXT_BUILD=`echo conftest.* | sed -n '1s/^.*\././'` - fi - rm -f a.* b.* a_out.exe conftest.* - AC_MSG_RESULT($EXEEXT_BUILD) -else - CC_BUILD=${CC} - EXEEXT_BUILD=${EXEEXT} -fi - -AC_SUBST(CC_BUILD) -AC_SUBST(EXEEXT_BUILD) - - -# Since these files will be eventually called from another directory (namely -# from the top level) we make the path of the scripts absolute. -# -# This small code snippet has been taken from automake's `ylwrap' script. - -AC_PROG_INSTALL -case "$INSTALL" in -[[\\/]]* | ?:[[\\/]]*) - ;; -*[[\\/]]*) - INSTALL="`pwd`/$INSTALL" - ;; -esac - -AC_PROG_MKDIR_P -case "$MKDIR_P" in -[[\\/]]* | ?:[[\\/]]*) - ;; -*[[\\/]]*) - MKDIR_P="`pwd`/$MKDIR_P" - ;; -esac - - -# checks for header files - -AC_CHECK_HEADERS([fcntl.h unistd.h]) - - -# checks for typedefs, structures, and compiler characteristics - -AC_C_CONST - -AC_ARG_ENABLE([freetype-config], - AS_HELP_STRING([--enable-freetype-config], [install freetype-config]), - [case "${enableval}" in - yes) enable_freetype_config="TRUE" ;; - no) enable_freetype_config="FALSE" ;; - *) AC_MSG_ERROR([unknown value '${enableval}' passed with --enable-freetype-config]) ;; - esac], [enable_freetype_config="FALSE"]) - -AC_SUBST(INSTALL_FT2_CONFIG, [$enable_freetype_config]) - -# checks for library functions - -AC_SYS_LARGEFILE - -# Here we check whether we can use our mmap file component. -# -# Note that `ftsystem.c` for Windows has its own mmap-like implementation -# not covered by `AC_FUNC_MMAP` and/or `FT_UNMAP_PARAM`. - -AC_ARG_ENABLE([mmap], - AS_HELP_STRING([--disable-mmap], - [do not check mmap() and do not use]), - [enable_mmap="no"], [enable_mmap="yes"]) -if test "x${enable_mmap}" != "xno"; then - case "$host" in - *-*-mingw*) - AC_MSG_CHECKING([for working mmap]) - AC_MSG_RESULT([using MapViewOfFile in Windows]) - FTSYS_SRC='$(TOP_DIR)/builds/windows/ftsystem.c' - ;; - *) - AC_FUNC_MMAP - if test "$ac_cv_func_mmap_fixed_mapped" = "yes"; then - FTSYS_SRC='$(PLATFORM_DIR)/ftsystem.c' - - AC_CHECK_DECLS([munmap], - [], - [], - [ - -#ifdef HAVE_UNISTD_H -#include -#endif -#include - - ]) - - FT_MUNMAP_PARAM - fi - ;; - esac -fi - -if test -z "$FTSYS_SRC"; then - FTSYS_SRC='$(BASE_DIR)/ftsystem.c' -fi -AC_SUBST([FTSYS_SRC]) - - -# get compiler flags right -# -# We try to make the compiler work for C99-strict source. Even if the -# C compiler is gcc and C99 flags are available, some system headers -# might be broken in C99 mode. We have to check whether compilation -# finishes successfully. -# -if test "x$GCC" = xyes; then - XX_CFLAGS="-Wall" - case "$host" in - *-*-mingw*) - XX_ANSIFLAGS="-pedantic" - ;; - *-*-aix*) - XX_ANSIFLAGS="-pedantic" - ;; - *) - XX_ANSIFLAGS="" - - for a in "-pedantic" "-std=c99" - do - AC_MSG_CHECKING([$CC compiler flag ${a} to assure ANSI C99 works correctly]) - orig_CFLAGS="${CFLAGS}" - CFLAGS="${CFLAGS} ${XX_ANSIFLAGS} ${a}" - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([ - -#include - - ], - [ - - { - puts( "" ); - return 0; - } - - ])], - [AC_MSG_RESULT([ok, adding to XX_ANSIFLAGS]) - XX_ANSIFLAGS="${XX_ANSIFLAGS} ${a}" - ], - [AC_MSG_RESULT([no])]) - CFLAGS="${orig_CFLAGS}" - done - ;; - esac -else - case "$host" in - *-dec-osf*) - CFLAGS= - XX_CFLAGS="-std1 -g3" - XX_ANSIFLAGS= - ;; - *) - XX_CFLAGS= - XX_ANSIFLAGS= - ;; - esac -fi -AC_SUBST([XX_CFLAGS]) -AC_SUBST([XX_ANSIFLAGS]) - - -# It is recommended that shared libraries hide symbols except those with -# explicit __attribute__((visibility("default"))). -# -found_visibility_flag=no -AC_MSG_CHECKING([for -fvisibility=hidden compiler flag]) -orig_CFLAGS="${CFLAGS}" -CFLAGS="${CFLAGS} -fvisibility=hidden" -AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], - [found_visibility_flag=yes - AC_MSG_RESULT(yes)], - [CFLAGS="${orig_CFLAGS}" - AC_MSG_RESULT(no)]) - -if test "${found_visibility_flag}" = "no"; then - AC_MSG_CHECKING([for -xldscope=hidden compiler flag]) - orig_CFLAGS="${CFLAGS}" - CFLAGS="${CFLAGS} -xldscope=hidden" - AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], - [found_visibility_flag=yes - AC_MSG_RESULT(yes)], - [CFLAGS="${orig_CFLAGS}" - AC_MSG_RESULT(no)]) -fi - -# All library tests below try `pkg-config' first. If that fails, a function -# from the library is tested in the traditional autoconf way (zlib, bzip2), -# or a config script is called (libpng). -# -# The `xxx_reqpriv' variables are for the `Requires.private' field in -# `freetype2.pc'. The `xxx_libspriv' variables are for the `Libs.private' -# field in `freetype2.pc' if pkg-config doesn't find a proper .pc file. -# -# The `xxx_libsstaticconf' variables are for the `freetype-config' script. -# -# Note that a call to PKG_CHECK_MODULES(XXX, ...) sets and creates the -# output variables `XXX_CFLAGS' and `XXX_LIBS'. In case one or both are set -# for a library by the user, no entry for this library is added to -# `Requires.private'. Instead, it gets added to `Libs.private' - - -# check for system zlib - -AC_ARG_WITH([zlib], - [AS_HELP_STRING([--with-zlib=@<:@yes|no|auto@:>@], - [use system zlib instead of internal library @<:@default=auto@:>@])], - [], [with_zlib=auto]) - -have_zlib=no -if test x"$with_zlib" = xyes -o x"$with_zlib" = xauto; then - zlib_pkg="zlib" - have_zlib_pkg=no - - if test x"$ZLIB_CFLAGS" = x -a x"$ZLIB_LIBS" = x; then - PKG_CHECK_EXISTS([$zlib_pkg], [have_zlib_pkg=yes]) - fi - PKG_CHECK_MODULES([ZLIB], [$zlib_pkg], - [have_zlib="yes (pkg-config)"], [:]) - - if test $have_zlib_pkg = yes; then - # we have zlib.pc - zlib_reqpriv="$zlib_pkg" - zlib_libspriv= - zlib_libsstaticconf=`$PKG_CONFIG --static --libs "$zlib_pkg"` - else - zlib_reqpriv= - - if test "$have_zlib" != no; then - # ZLIB_CFLAGS and ZLIB_LIBS are set by the user - zlib_libspriv="$ZLIB_LIBS" - zlib_libsstaticconf="$ZLIB_LIBS" - have_zlib="yes (ZLIB_CFLAGS and ZLIB_LIBS)" - else - # fall back to standard autoconf test - AC_CHECK_LIB([z], - [gzsetparams], - [AC_CHECK_HEADER([zlib.h], - [have_zlib="yes (autoconf test)" - zlib_libspriv="-lz" - zlib_libsstaticconf="$zlib_libspriv" - ZLIB_LIBS="$zlib_libspriv"])]) - fi - fi -fi - -if test x"$with_zlib" = xyes -a "$have_zlib" = no; then - AC_MSG_ERROR([external zlib support requested but library not found]) -fi - -SYSTEM_ZLIB= -if test "$have_zlib" != no; then - SYSTEM_ZLIB=yes -fi -AC_SUBST([SYSTEM_ZLIB]) - - -# check for system libbz2 - -AC_ARG_WITH([bzip2], - [AS_HELP_STRING([--with-bzip2=@<:@yes|no|auto@:>@], - [support bzip2 compressed fonts @<:@default=auto@:>@])], - [], [with_bzip2=auto]) - -have_bzip2=no -if test x"$with_bzip2" = xyes -o x"$with_bzip2" = xauto; then - bzip2_pkg="bzip2" - have_bzip2_pkg=no - - if test x"$BZIP2_CFLAGS" = x -a x"$BZIP2_LIBS" = x; then - PKG_CHECK_EXISTS([$bzip2_pkg], [have_bzip2_pkg=yes]) - fi - PKG_CHECK_MODULES([BZIP2], [$bzip2_pkg], - [have_bzip2="yes (pkg-config)"], [:]) - - if test $have_bzip2_pkg = yes; then - # we have bzip2.pc - bzip2_reqpriv="$bzip2_pkg" - bzip2_libspriv= - bzip2_libsstaticconf=`$PKG_CONFIG --static --libs "$bzip2_pkg"` - else - bzip2_reqpriv= - - if test "$have_bzip2" != no; then - # BZIP2_CFLAGS and BZIP2_LIBS are set by the user - bzip2_libspriv="$BZIP2_LIBS" - bzip2_libsstaticconf="$BZIP2_LIBS" - have_bzip2="yes (BZIP2_CFLAGS and BZIP2_LIBS)" - else - # fall back to standard autoconf test - AC_CHECK_LIB([bz2], - [BZ2_bzDecompress], - [AC_CHECK_HEADER([bzlib.h], - [have_bzip2="yes (autoconf test)" - bzip2_libspriv="-lbz2" - bzip2_libsstaticconf="$bzip2_libspriv" - BZIP2_LIBS="$bzip2_libspriv"])]) - fi - fi -fi - -if test x"$with_bzip2" = xyes -a "$have_bzip2" = no; then - AC_MSG_ERROR([bzip2 support requested but library not found]) -fi - - -# check for system libpng - -AC_ARG_WITH([png], - [AS_HELP_STRING([--with-png=@<:@yes|no|auto@:>@], - [support png compressed OpenType embedded bitmaps @<:@default=auto@:>@])], - [], [with_png=auto]) - -have_libpng=no -if test x"$with_png" = xyes -o x"$with_png" = xauto; then - libpng_pkg="libpng" - have_libpng_pkg=no - - if test x"$LIBPNG_CFLAGS" = x -a x"$LIBPNG_LIBS" = x; then - PKG_CHECK_EXISTS([$libpng_pkg], [have_libpng_pkg=yes]) - fi - PKG_CHECK_MODULES([LIBPNG], [$libpng_pkg], - [have_libpng="yes (pkg-config)"], [:]) - - if test $have_libpng_pkg = yes; then - # we have libpng.pc - libpng_reqpriv="$libpng_pkg" - libpng_libspriv= - libpng_libsstaticconf=`$PKG_CONFIG --static --libs "$libpng_pkg"` - else - libpng_reqpriv= - - if test "$have_libpng" != no; then - # LIBPNG_CFLAGS and LIBPNG_LIBS are set by the user - libpng_libspriv="$LIBPNG_LIBS" - libpng_libsstaticconf="$LIBPNG_LIBS" - have_libpng="yes (LIBPNG_CFLAGS and LIBPNG_LIBS)" - else - # fall back to config script - AC_CHECK_PROG(have_libpng, [libpng-config], [yes (libpng-config)], [no]) - if test "$have_libpng" != no; then - LIBPNG_CFLAGS=`libpng-config --cflags` - LIBPNG_LIBS=`libpng-config --ldflags` - libpng_libspriv=`libpng-config --static --ldflags` - libpng_libsstaticconf="$libpng_libspriv" - fi - fi - fi -fi - -if test x"$with_png" = xyes -a "$have_libpng" = no; then - AC_MSG_ERROR([libpng support requested but library not found]) -fi - - -# check for system libharfbuzz - -AC_ARG_WITH([harfbuzz], - [AS_HELP_STRING([--with-harfbuzz=@<:@yes|no|auto@:>@], - [improve auto-hinting of OpenType fonts @<:@default=auto@:>@])], - [], [with_harfbuzz=auto]) - -have_harfbuzz=no -if test x"$with_harfbuzz" = xyes -o x"$with_harfbuzz" = xauto; then - harfbuzz_pkg="harfbuzz >= 2.0.0" - have_harfbuzz_pkg=no - - if test x"$HARFBUZZ_CFLAGS" = x -a x"$HARFBUZZ_LIBS" = x; then - PKG_CHECK_EXISTS([$harfbuzz_pkg], [have_harfbuzz_pkg=yes]) - fi - PKG_CHECK_MODULES([HARFBUZZ], [$harfbuzz_pkg], - [have_harfbuzz="yes (pkg-config)"], [:]) - - if test $have_harfbuzz_pkg = yes; then - # we have harfbuzz.pc - harfbuzz_reqpriv="$harfbuzz_pkg" - harfbuzz_libspriv= - harfbuzz_libsstaticconf=`$PKG_CONFIG --static --libs "$harfbuzz_pkg"` - else - harfbuzz_reqpriv= - - if test "$have_harfbuzz" != no; then - # HARFBUZZ_CFLAGS and HARFBUZZ_LIBS are set by the user - harfbuzz_libspriv="$HARFBUZZ_LIBS" - harfbuzz_libsstaticconf="$HARFBUZZ_LIBS" - have_harfbuzz="yes (HARFBUZZ_CFLAGS and HARFBUZZ_LIBS)" - else - # since HarfBuzz is quite a new library we don't fall back to a - # different test; additionally, it has too many dependencies - : - fi - fi -fi - -if test x"$with_harfbuzz" = xyes -a "$have_harfbuzz" = no; then - AC_MSG_ERROR([harfbuzz support requested but library not found]) -fi - - -# check for system libbrotlidec - -AC_ARG_WITH([brotli], - [AS_HELP_STRING([--with-brotli=@<:@yes|no|auto@:>@], - [support decompression of WOFF2 streams @<:@default=auto@:>@])], - [], [with_brotli=auto]) - -have_brotli=no -if test x"$with_brotli" = xyes -o x"$with_brotli" = xauto; then - brotli_pkg="libbrotlidec" - have_brotli_pkg=no - - if test x"$BROTLI_CFLAGS" = x -a x"$BROTLI_LIBS" = x; then - PKG_CHECK_EXISTS([$brotli_pkg], [have_brotli_pkg=yes]) - fi - PKG_CHECK_MODULES([BROTLI], [$brotli_pkg], - [have_brotli="yes (pkg-config)"], [:]) - - if test $have_brotli_pkg = yes; then - # we have libbrotlidec.pc - brotli_reqpriv="$brotli_pkg" - brotli_libspriv= - brotli_libsstaticconf=`$PKG_CONFIG --static --libs "$brotli_pkg"` - else - brotli_reqpriv= - - if test "$have_brotli" != no; then - # BROTLI_CFLAGS and BROTLI_LIBS are set by the user - brotli_libspriv="$BROTLI_LIBS" - brotli_libsstaticconf="$BROTLI_LIBS" - have_brotli="yes (BROTLI_CFLAGS and BROTLI_LIBS)" - else - # since Brotli is quite a new library we don't fall back to a - # different test - : - fi - fi -fi - -if test x"$with_brotli" = xyes -a "$have_brotli" = no; then - AC_MSG_ERROR([brotli support requested but library not found]) -fi - - -# Checks for the demo programs. -# -# FreeType doesn't need this. However, since the demo program repository -# doesn't come with a `configure` script of its own, we integrate the tests -# here for simplicity. - -# We need `clock_gettime` from 'librt' for the `ftbench` demo program. -# -# The code is modeled after gnulib's file `clock_time.m4`, ignoring -# very old Solaris systems. -LIB_CLOCK_GETTIME= -AC_SEARCH_LIBS([clock_gettime], - [rt], - [test "$ac_cv_search_clock_gettime" = "none required" \ - || LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime]) - -FT_DEMO_CFLAGS="" -FT_DEMO_LDFLAGS="$LIB_CLOCK_GETTIME" - -# 'librsvg' is needed to demonstrate SVG support. -AC_ARG_WITH([librsvg], - [AS_HELP_STRING([--with-librsvg=@<:@yes|no|auto@:>@], - [support OpenType SVG fonts in FreeType demo programs @<:@default=auto@:>@])], - [], [with_librsvg=auto]) - -have_librsvg=no -if test x"$with_librsvg" = xyes -o x"$with_librsvg" = xauto; then - PKG_CHECK_MODULES([LIBRSVG], [librsvg-2.0 >= 2.46.0], - [have_librsvg="yes (pkg-config)"], [:]) - - if test "$have_librsvg" != no; then - FT_DEMO_CFLAGS="$FT_DEMO_CFLAGS $LIBRSVG_CFLAGS -DHAVE_LIBRSVG" - FT_DEMO_LDFLAGS="$FT_DEMO_LDFLAGS $LIBRSVG_LIBS" - fi -fi - -if test x"$with_librsvg" = xyes -a "$have_librsvg" = no; then - AC_MSG_ERROR([librsvg support requested but library not found]) -fi - -AC_SUBST([FT_DEMO_CFLAGS]) -AC_SUBST([FT_DEMO_LDFLAGS]) - - -# Some options handling SDKs/archs in CFLAGS should be copied -# to LDFLAGS. Apple TechNote 2137 recommends to include these -# options in CFLAGS but not in LDFLAGS. - -save_config_args=$* -set dummy ${CFLAGS} -i=1 -while test $i -le $# -do - c=$1 - - case "${c}" in - -isysroot|-arch) # options taking 1 argument - a=$2 - AC_MSG_CHECKING([whether CFLAGS and LDFLAGS share ${c} ${a}]) - if expr " ${LDFLAGS} " : ".* ${c} *${a}.*" > /dev/null - then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no, copy to LDFLAGS]) - LDFLAGS="${LDFLAGS} ${c} ${a}" - fi - shift 1 - ;; - -m32|-m64|-march=*|-mcpu=*) # options taking no argument - AC_MSG_CHECKING([whether CFLAGS and LDFLAGS share ${c}]) - if expr " ${LDFLAGS} " : ".* ${c} *${a}.*" > /dev/null - then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no, copy to LDFLAGS]) - LDFLAGS="${LDFLAGS} ${c}" - fi - ;; - # *) - # AC_MSG_RESULT([${c} is not copied to LDFLAGS]) - # ;; - esac - - shift 1 -done -set ${save_config_args} - - -# Whether to use Mac OS resource-based fonts. - -ftmac_c="" # src/base/ftmac.c should not be included in makefiles by default - -AC_ARG_WITH([old-mac-fonts], - AS_HELP_STRING([--with-old-mac-fonts], - [allow Mac resource-based fonts to be used])) -if test x$with_old_mac_fonts = xyes; then - orig_LDFLAGS="${LDFLAGS}" - AC_MSG_CHECKING([CoreServices & ApplicationServices of Mac OS X]) - ft2_extra_libs="-Wl,-framework,CoreServices -Wl,-framework,ApplicationServices" - LDFLAGS="$LDFLAGS $ft2_extra_libs" - AC_LINK_IFELSE([ - AC_LANG_PROGRAM([ - -#if defined(__GNUC__) && defined(__APPLE_CC__) -# include -# include -#else -# include -# include -#endif - - ], - [ - - short res = 0; - - - UseResFile( res ); - - ])], - [AC_MSG_RESULT([ok]) - ftmac_c='ftmac.c' - AC_MSG_CHECKING([whether OS_INLINE macro is ANSI compatible]) - orig_CFLAGS="$CFLAGS -DFT_MACINTOSH" - CFLAGS="$CFLAGS $XX_CFLAGS $XX_ANSIFLAGS" - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([ - -#if defined(__GNUC__) && defined(__APPLE_CC__) -# include -# include -#else -# include -# include -#endif - - ], - [ - - /* OSHostByteOrder() is typed as OS_INLINE */ - int32_t os_byte_order = OSHostByteOrder(); - - - if ( OSBigEndian != os_byte_order ) - return 1; - - ])], - [AC_MSG_RESULT([ok]) - CFLAGS="$orig_CFLAGS" - CFLAGS="$CFLAGS -DHAVE_ANSI_OS_INLINE=1" - ], - [AC_MSG_RESULT([no, ANSI incompatible]) - CFLAGS="$orig_CFLAGS" - ]) - AC_MSG_CHECKING([type ResourceIndex]) - orig_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $XX_CFLAGS $XX_ANSIFLAGS" - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([ - -#if defined(__GNUC__) && defined(__APPLE_CC__) -# include -# include -#else -# include -# include -# include -#endif - - ], - [ - - ResourceIndex i = 0; - return i; - - ])], - [AC_MSG_RESULT([ok]) - CFLAGS="$orig_CFLAGS" - CFLAGS="$CFLAGS -DHAVE_TYPE_RESOURCE_INDEX=1" - ], - [AC_MSG_RESULT([no]) - CFLAGS="$orig_CFLAGS" - CFLAGS="$CFLAGS -DHAVE_TYPE_RESOURCE_INDEX=0" - ])], - [AC_MSG_RESULT([not found]) - ft2_extra_libs="" - LDFLAGS="${orig_LDFLAGS}" - CFLAGS="$CFLAGS -DDARWIN_NO_CARBON"]) -else - case x$host_os in - xdarwin*) - dnl AC_MSG_WARN([host system is MacOS but configured to build without Carbon]) - CFLAGS="$CFLAGS -DDARWIN_NO_CARBON" - ;; - *) - ;; - esac -fi - - -# Whether to use FileManager, which is deprecated since Mac OS X 10.4. - -AC_ARG_WITH([fsspec], - AS_HELP_STRING([--with-fsspec], - [use obsolete FSSpec API of MacOS, if available (default=yes)])) -if test x$with_fsspec = xno; then - CFLAGS="$CFLAGS -DHAVE_FSSPEC=0" -elif test x$with_old_mac_fonts = xyes -a x$with_fsspec != x; then - AC_MSG_CHECKING([FSSpec-based FileManager]) - AC_LINK_IFELSE([ - AC_LANG_PROGRAM([ - -#if defined(__GNUC__) && defined(__APPLE_CC__) -# include -# include -#else -# include -# include -#endif - - ], - [ - - FCBPBPtr paramBlock; - short vRefNum; - long dirID; - ConstStr255Param fileName; - FSSpec* spec; - - - /* FSSpec functions: deprecated since Mac OS X 10.4 */ - PBGetFCBInfoSync( paramBlock ); - FSMakeFSSpec( vRefNum, dirID, fileName, spec ); - - ])], - [AC_MSG_RESULT([ok]) - CFLAGS="$CFLAGS -DHAVE_FSSPEC=1"], - [AC_MSG_RESULT([not found]) - CFLAGS="$CFLAGS -DHAVE_FSSPEC=0"]) -fi - - -# Whether to use FileManager in Carbon since MacOS 9.x. - -AC_ARG_WITH([fsref], - AS_HELP_STRING([--with-fsref], - [use Carbon FSRef API of MacOS, if available (default=yes)])) -if test x$with_fsref = xno; then - AC_MSG_WARN([ -*** WARNING - FreeType2 built without FSRef API cannot load - data-fork fonts on MacOS, except of XXX.dfont. - ]) - CFLAGS="$CFLAGS -DHAVE_FSREF=0" -elif test x$with_old_mac_fonts = xyes -a x$with_fsref != x; then - AC_MSG_CHECKING([FSRef-based FileManager]) - AC_LINK_IFELSE([ - AC_LANG_PROGRAM([ - -#if defined(__GNUC__) && defined(__APPLE_CC__) -# include -# include -#else -# include -# include -#endif - - ], - [ - - short vRefNum; - long dirID; - ConstStr255Param fileName; - - Boolean* isDirectory; - UInt8* path; - SInt16 desiredRefNum; - SInt16* iterator; - SInt16* actualRefNum; - HFSUniStr255* outForkName; - FSVolumeRefNum volume; - FSCatalogInfoBitmap whichInfo; - FSCatalogInfo* catalogInfo; - FSForkInfo* forkInfo; - FSRef* ref; - -#if HAVE_FSSPEC - FSSpec* spec; -#endif - - /* FSRef functions: no need to check? */ - FSGetForkCBInfo( desiredRefNum, volume, iterator, - actualRefNum, forkInfo, ref, - outForkName ); - FSPathMakeRef( path, ref, isDirectory ); - -#if HAVE_FSSPEC - FSpMakeFSRef ( spec, ref ); - FSGetCatalogInfo( ref, whichInfo, catalogInfo, - outForkName, spec, ref ); -#endif - ])], - [AC_MSG_RESULT([ok]) - CFLAGS="$CFLAGS -DHAVE_FSREF=1"], - [AC_MSG_RESULT([not found]) - CFLAGS="$CFLAGS -DHAVE_FSREF=0"]) -fi - - -# Whether to use QuickDraw API in ToolBox, which is deprecated since -# Mac OS X 10.4. - -AC_ARG_WITH([quickdraw-toolbox], - AS_HELP_STRING([--with-quickdraw-toolbox], - [use MacOS QuickDraw in ToolBox, if available (default=yes)])) -if test x$with_quickdraw_toolbox = xno; then - CFLAGS="$CFLAGS -DHAVE_QUICKDRAW_TOOLBOX=0" -elif test x$with_old_mac_fonts = xyes -a x$with_quickdraw_toolbox != x; then - AC_MSG_CHECKING([QuickDraw FontManager functions in ToolBox]) - AC_LINK_IFELSE([ - AC_LANG_PROGRAM([ - -#if defined(__GNUC__) && defined(__APPLE_CC__) -# include -# include -#else -# include -# include -#endif - - ], - [ - - Str255 familyName; - SInt16 familyID = 0; - FMInput* fmIn = NULL; - FMOutput* fmOut = NULL; - - - GetFontName( familyID, familyName ); - GetFNum( familyName, &familyID ); - fmOut = FMSwapFont( fmIn ); - - ])], - [AC_MSG_RESULT([ok]) - CFLAGS="$CFLAGS -DHAVE_QUICKDRAW_TOOLBOX=1"], - [AC_MSG_RESULT([not found]) - CFLAGS="$CFLAGS -DHAVE_QUICKDRAW_TOOLBOX=0"]) -fi - - -# Whether to use QuickDraw API in Carbon, which is deprecated since -# Mac OS X 10.4. - -AC_ARG_WITH([quickdraw-carbon], - AS_HELP_STRING([--with-quickdraw-carbon], - [use MacOS QuickDraw in Carbon, if available (default=yes)])) -if test x$with_quickdraw_carbon = xno; then - CFLAGS="$CFLAGS -DHAVE_QUICKDRAW_CARBON=0" -elif test x$with_old_mac_fonts = xyes -a x$with_quickdraw_carbon != x; then - AC_MSG_CHECKING([QuickDraw FontManager functions in Carbon]) - AC_LINK_IFELSE([ - AC_LANG_PROGRAM([ - -#if defined(__GNUC__) && defined(__APPLE_CC__) -# include -# include -#else -# include -# include -#endif - - ], - [ - - FMFontFamilyIterator famIter; - FMFontFamily family; - Str255 famNameStr; - FMFontFamilyInstanceIterator instIter; - FMFontStyle style; - FMFontSize size; - FMFont font; - FSSpec* pathSpec; - - - FMCreateFontFamilyIterator( NULL, NULL, kFMUseGlobalScopeOption, - &famIter ); - FMGetNextFontFamily( &famIter, &family ); - FMGetFontFamilyName( family, famNameStr ); - FMCreateFontFamilyInstanceIterator( family, &instIter ); - FMGetNextFontFamilyInstance( &instIter, &font, &style, &size ); - FMDisposeFontFamilyInstanceIterator( &instIter ); - FMDisposeFontFamilyIterator( &famIter ); - FMGetFontContainer( font, pathSpec ); - - ])], - [AC_MSG_RESULT([ok]) - CFLAGS="$CFLAGS -DHAVE_QUICKDRAW_CARBON=1"], - [AC_MSG_RESULT([not found]) - CFLAGS="$CFLAGS -DHAVE_QUICKDRAW_CARBON=0"]) -fi - - -# Whether to use AppleTypeService since Mac OS X. - -AC_ARG_WITH([ats], - AS_HELP_STRING([--with-ats], - [use AppleTypeService, if available (default=yes)])) -if test x$with_ats = xno; then - CFLAGS="$CFLAGS -DHAVE_ATS=0" -elif test x$with_old_mac_fonts = xyes -a x$with_ats != x; then - AC_MSG_CHECKING([AppleTypeService functions]) - AC_LINK_IFELSE([ - AC_LANG_PROGRAM([ - -#if defined(__GNUC__) && defined(__APPLE_CC__) -# include -# include -#else -# include -# include -#endif - - ], - [ - - FSSpec* pathSpec; - - - ATSFontFindFromName( NULL, kATSOptionFlagsUnRestrictedScope ); -#if HAVE_FSSPEC - ATSFontGetFileSpecification( 0, pathSpec ); -#endif - - ])], - [AC_MSG_RESULT([ok]) - CFLAGS="$CFLAGS -DHAVE_ATS=1"], - [AC_MSG_RESULT([not found]) - CFLAGS="$CFLAGS -DHAVE_ATS=0"]) -fi - -case "$CFLAGS" in - *HAVE_FSSPEC* | *HAVE_FSREF* | *HAVE_QUICKDRAW* | *HAVE_ATS* ) - AC_MSG_WARN([ -*** WARNING - FSSpec/FSRef/QuickDraw/ATS options are explicitly given, - thus it is recommended to replace src/base/ftmac.c by builds/mac/ftmac.c. - ]) - CFLAGS="$CFLAGS "'-I$(TOP_DIR)/builds/mac/' - ;; - *) - ;; -esac - -# Check for pthreads - -AX_PTHREAD([have_pthread=yes], [have_pthread=no]) - -# Check for Python and docwriter -PYTHON_MIN_VERSION=3.5 -have_py3=no -have_docwriter=no -PIP=pip - -AC_CHECK_PROGS([PYTHON], [python3 python], [missing]) -if test "x$PYTHON" != "xmissing"; then - AX_PROG_PYTHON_VERSION([$PYTHON_MIN_VERSION], [have_py3=yes], []) - - if test "x$have_py3" = "xyes"; then - PIP="$PYTHON -m $PIP" - AC_MSG_CHECKING([for `docwriter' Python module]) - $PYTHON -m docwriter -h > /dev/null 2>&1 - if test "x$?" = "x0"; then - have_docwriter=yes - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no]) - fi - fi -fi - - -# entries in Requires.private are separated by commas -PKGCONFIG_REQUIRES_PRIVATE="$zlib_reqpriv, \ - $bzip2_reqpriv, \ - $libpng_reqpriv, \ - $harfbuzz_reqpriv, \ - $brotli_reqpriv" -# beautify -PKGCONFIG_REQUIRES_PRIVATE=`echo "$PKGCONFIG_REQUIRES_PRIVATE" \ - | sed -e 's/^ *//' \ - -e 's/ *$//' \ - -e 's/, */,/g' \ - -e 's/,,*/,/g' \ - -e 's/^,*//' \ - -e 's/,*$//' \ - -e 's/,/, /g'` - -PKGCONFIG_LIBS_PRIVATE="$zlib_libspriv \ - $bzip2_libspriv \ - $libpng_libspriv \ - $harfbuzz_libspriv \ - $brotli_libspriv \ - $ft2_extra_libs" -# beautify -PKGCONFIG_LIBS_PRIVATE=`echo "$PKGCONFIG_LIBS_PRIVATE" \ - | sed -e 's/^ *//' \ - -e 's/ *$//' \ - -e 's/ */ /g'` - -LIBSSTATIC_CONFIG="-lfreetype \ - $zlib_libsstaticconf \ - $bzip2_libsstaticconf \ - $libpng_libsstaticconf \ - $harfbuzz_libsstaticconf \ - $brotli_libsstaticconf \ - $ft2_extra_libs" -# remove -L/usr/lib and -L/usr/lib64 since `freetype-config' adds them later -# on if necessary; also beautify -LIBSSTATIC_CONFIG=`echo "$LIBSSTATIC_CONFIG" \ - | sed -e 's|-L */usr/lib64/* | |g' \ - -e 's|-L */usr/lib/* | |g' \ - -e 's/^ *//' \ - -e 's/ *$//' \ - -e 's/ */ /g'` - -# If FreeType gets installed with `--disable-shared', don't use -# 'private' fields. `pkg-config' only looks into `.pc' files and is -# completely agnostic to whether shared libraries are actually present -# or not. As a consequence, the user had to specify `--static' while -# calling `pkg-config', which configure scripts are normally not -# prepared for. - -PKGCONFIG_REQUIRES= -PKGCONFIG_LIBS='-L${libdir} -lfreetype' - -if test $enable_shared = "no"; then - PKGCONFIG_REQUIRES="$PKGCONFIG_REQUIRES $PKGCONFIG_REQUIRES_PRIVATE" - PKGCONFIG_REQUIRES_PRIVATE= - PKGCONFIG_LIBS="$PKGCONFIG_LIBS $PKGCONFIG_LIBS_PRIVATE" - PKGCONFIG_LIBS_PRIVATE= -fi - -AC_SUBST([ftmac_c]) -AC_SUBST([PKGCONFIG_REQUIRES]) -AC_SUBST([PKGCONFIG_LIBS]) -AC_SUBST([PKGCONFIG_REQUIRES_PRIVATE]) -AC_SUBST([PKGCONFIG_LIBS_PRIVATE]) -AC_SUBST([LIBSSTATIC_CONFIG]) - -AC_SUBST([hardcode_libdir_flag_spec]) -AC_SUBST([wl]) -AC_SUBST([build_libtool_libs]) - - -# changing LDFLAGS value should only be done after -# lt_cv_prog_compiler_static_works test - -ftoption_set() -{ - regexp="-e \\\"s|.*#.*def.*$1.*|#define $1|\\\"" - FTOPTION_H_SED="$FTOPTION_H_SED $regexp" -} - -ftoption_unset() -{ - regexp="-e \\\"s|.*#.*def.*$1.*|/* #undef $1 */|\\\"" - FTOPTION_H_SED="$FTOPTION_H_SED $regexp" -} - -if test "$have_zlib" != no; then - CFLAGS="$CFLAGS $ZLIB_CFLAGS" - LDFLAGS="$LDFLAGS $ZLIB_LIBS" - ftoption_set FT_CONFIG_OPTION_SYSTEM_ZLIB -else - ftoption_unset FT_CONFIG_OPTION_SYSTEM_ZLIB -fi -if test "$have_bzip2" != no; then - CFLAGS="$CFLAGS $BZIP2_CFLAGS" - LDFLAGS="$LDFLAGS $BZIP2_LIBS" - ftoption_set FT_CONFIG_OPTION_USE_BZIP2 -else - ftoption_unset FT_CONFIG_OPTION_USE_BZIP2 -fi -if test "$have_libpng" != no; then - CFLAGS="$CFLAGS $LIBPNG_CFLAGS" - LDFLAGS="$LDFLAGS $LIBPNG_LIBS" - ftoption_set FT_CONFIG_OPTION_USE_PNG -else - ftoption_unset FT_CONFIG_OPTION_USE_PNG -fi -if test "$have_harfbuzz" != no; then - CFLAGS="$CFLAGS $HARFBUZZ_CFLAGS" - LDFLAGS="$LDFLAGS $HARFBUZZ_LIBS" - ftoption_set FT_CONFIG_OPTION_USE_HARFBUZZ -else - ftoption_unset FT_CONFIG_OPTION_USE_HARFBUZZ -fi -if test "$have_brotli" != no; then - CFLAGS="$CFLAGS $BROTLI_CFLAGS" - LDFLAGS="$LDFLAGS $BROTLI_LIBS" - ftoption_set FT_CONFIG_OPTION_USE_BROTLI -else - ftoption_unset FT_CONFIG_OPTION_USE_BROTLI -fi - -if test "$have_pthread" != no; then - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - LDFLAGS="$LDFLAGS $PTHREAD_CFLAGS $PTHREAD_LIBS" -fi - -AC_SUBST([CFLAGS]) -AC_SUBST([LDFLAGS]) - -# We don't want to use a template file for `ftoption.h', since compilation -# should work without calling a configure script also. For this reason, we -# copy the `include/freetype/config/ftoption.h' file to the `unix/builds' -# directory (using a dummy `AC_CONFIG_FILES' call) and apply the just -# constructed $FTOPTION_H_SED regexp (using the post-action of -# `AC_CONFIG_FILES'); this is also the version that gets installed later on. -# -AC_CONFIG_FILES([ftoption.h:${srcdir}/../../include/freetype/config/ftoption.h], - [mv ftoption.h ftoption.tmp - eval "sed $FTOPTION_H_SED < ftoption.tmp > ftoption.h" - rm ftoption.tmp], - [FTOPTION_H_SED="$FTOPTION_H_SED"]) - -AC_CONFIG_HEADERS([ftconfig.h]) - -# create the Unix-specific sub-Makefiles `builds/unix/unix-def.mk' -# and `builds/unix/unix-cc.mk' that will be used by the build system -# -AC_CONFIG_FILES([unix-cc.mk:unix-cc.in - unix-def.mk:unix-def.in]) - -AC_OUTPUT - -AC_MSG_NOTICE([ - -Library configuration: - external zlib: $have_zlib - bzip2: $have_bzip2 - libpng: $have_libpng - harfbuzz: $have_harfbuzz - brotli: $have_brotli - pthread: $have_pthread -]) - -# Warn if docwriter is not installed - -if test $have_docwriter = no; then - AC_MSG_WARN([ - `make refdoc' will fail since pip package `docwriter' is not installed. - To install, run `$PIP install docwriter', or to use a Python - virtual environment, run `make refdoc-venv' (requires pip package - `virtualenv'). These operations require Python >= $PYTHON_MIN_VERSION. - ]) -fi - -# Warn if pthread is not available - -if test $have_pthread = no; then - AC_MSG_WARN([ - `FT_DEBUG_LOGGING' will not work since the `pthread' library is not - available. This warning can be safely ignored if you don't plan to use - this configuration macro. - ]) -fi - -# end of configure.raw diff --git a/freetype/builds/unix/detect.mk b/freetype/builds/unix/detect.mk deleted file mode 100644 index 6b87013..0000000 --- a/freetype/builds/unix/detect.mk +++ /dev/null @@ -1,99 +0,0 @@ -# -# FreeType 2 configuration file to detect a UNIX host platform. -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -.PHONY: setup - -ifeq ($(PLATFORM),ansi) - - # Note: this test is duplicated in "builds/toplevel.mk". - # - is_unix := $(strip $(wildcard /sbin/init) \ - $(wildcard /usr/sbin/init) \ - $(wildcard /dev/null) \ - $(wildcard /hurd/auth)) - ifneq ($(is_unix),) - - PLATFORM := unix - - endif # test is_unix -endif # test PLATFORM ansi - -ifeq ($(PLATFORM),unix) - COPY := cp - DELETE := rm -f - CAT := cat - - # If `devel' is the requested target, we use a special configuration - # file named `unix-dev.mk'. It disables optimization and libtool. - # - ifneq ($(findstring devel,$(MAKECMDGOALS)),) - CONFIG_FILE := unix-dev.mk - CC := gcc - - .PHONY: devel - devel: setup - @: - else - - # If `lcc' is the requested target, we use a special configuration - # file named `unix-lcc.mk'. It disables libtool for LCC. - # - ifneq ($(findstring lcc,$(MAKECMDGOALS)),) - CONFIG_FILE := unix-lcc.mk - CC := lcc - - .PHONY: lcc - lcc: setup - @: - else - - # If a Unix platform is detected, the configure script is called and - # `unix-def.mk' together with `unix-cc.mk' is created. - # - # Arguments to `configure' should be in the CFG variable. Example: - # - # make CFG="--prefix=/usr --disable-static" - # - # If you need to set CFLAGS or LDFLAGS, do it here also. - # - # Feel free to add support for other platform specific compilers in - # this directory (e.g. solaris.mk + changes here to detect the - # platform). - # - CONFIG_FILE := unix.mk - must_configure := 1 - - .PHONY: unix - unix: setup - @: - endif - endif - - have_Makefile := $(wildcard $(OBJ_DIR)/Makefile) - - setup: std_setup - ifdef must_configure - ifneq ($(have_Makefile),) - # we are building FT2 not in the src tree - $(TOP_DIR)/builds/unix/configure $(value CFG) - else - cd builds/unix; \ - ./configure $(value CFG) - endif - endif - -endif # test PLATFORM unix - - -# EOF diff --git a/freetype/builds/unix/freetype-config.in b/freetype/builds/unix/freetype-config.in deleted file mode 100644 index 5856112..0000000 --- a/freetype/builds/unix/freetype-config.in +++ /dev/null @@ -1,211 +0,0 @@ -#! /bin/sh -# -# Copyright (C) 2000-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -LC_ALL=C -export LC_ALL - - -# if `pkg-config' is available, use values from `freetype2.pc' -%PKG_CONFIG% --atleast-pkgconfig-version 0.24 >/dev/null 2>&1 -if test $? -eq 0 ; then - # note that option `--variable' is not affected by the - # PKG_CONFIG_SYSROOT_DIR environment variable - if test "x$SYSROOT" != "x" ; then - PKG_CONFIG_SYSROOT_DIR="$SYSROOT" - export PKG_CONFIG_SYSROOT_DIR - fi - - prefix=`%PKG_CONFIG% --variable prefix freetype2` - exec_prefix=`%PKG_CONFIG% --variable exec_prefix freetype2` - - includedir=`%PKG_CONFIG% --variable includedir freetype2` - libdir=`%PKG_CONFIG% --variable libdir freetype2` - - version=`%PKG_CONFIG% --modversion freetype2` - - cflags=`%PKG_CONFIG% --cflags freetype2` - dynamic_libs=`%PKG_CONFIG% --libs freetype2` - static_libs=`%PKG_CONFIG% --static --libs freetype2` -else - prefix="%prefix%" - exec_prefix="%exec_prefix%" - - includedir="%includedir%" - libdir="%libdir%" - - version=%ft_version% - - cflags="-I${SYSROOT}$includedir/freetype2" - dynamic_libs="-lfreetype" - static_libs="%LIBSSTATIC_CONFIG%" - if test "${SYSROOT}$libdir" != "/usr/lib" && - test "${SYSROOT}$libdir" != "/usr/lib64" ; then - libs_L="-L${SYSROOT}$libdir" - fi -fi - -orig_prefix=$prefix -orig_exec_prefix=$exec_prefix - -orig_includedir=$includedir -orig_libdir=$libdir - -include_suffix=`echo $includedir | sed "s|$prefix||"` -lib_suffix=`echo $libdir | sed "s|$exec_prefix||"` - - -usage() -{ - cat <&2 -fi - - -while test $# -gt 0 ; do - case "$1" in - -*=*) - optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` - ;; - *) - optarg= - ;; - esac - - case $1 in - --prefix=*) - prefix=$optarg - local_prefix=yes - ;; - --prefix) - echo_prefix=yes - ;; - --exec-prefix=*) - exec_prefix=$optarg - exec_prefix_set=yes - local_prefix=yes - ;; - --exec-prefix) - echo_exec_prefix=yes - ;; - --version) - echo_version=yes - break - ;; - --ftversion) - echo_ft_version=yes - ;; - --cflags) - echo_cflags=yes - ;; - --libs) - echo_libs=yes - ;; - --libtool) - echo_libtool=yes - ;; - --static) - show_static=yes - ;; - --help) - usage 0 - ;; - *) - usage 1 1>&2 - ;; - esac - shift -done - - -if test "$local_prefix" = "yes" ; then - if test "$exec_prefix_set" != "yes" ; then - exec_prefix=$prefix - fi -fi - -if test "$local_prefix" = "yes" ; then - includedir=${prefix}${include_suffix} - if test "$exec_prefix_set" = "yes" ; then - libdir=${exec_prefix}${lib_suffix} - else - libdir=${prefix}${lib_suffix} - fi -fi - - -if test "$echo_version" = "yes" ; then - echo $version -fi - -if test "$echo_prefix" = "yes" ; then - echo ${SYSROOT}$prefix -fi - -if test "$echo_exec_prefix" = "yes" ; then - echo ${SYSROOT}$exec_prefix -fi - -if test "$echo_ft_version" = "yes" ; then - major=`grep define ${SYSROOT}$includedir/freetype2/freetype/freetype.h \ - | grep FREETYPE_MAJOR \ - | sed 's/.*[ ]\([0-9][0-9]*\).*/\1/'` - minor=`grep define ${SYSROOT}$includedir/freetype2/freetype/freetype.h \ - | grep FREETYPE_MINOR \ - | sed 's/.*[ ]\([0-9][0-9]*\).*/\1/'` - patch=`grep define ${SYSROOT}$includedir/freetype2/freetype/freetype.h \ - | grep FREETYPE_PATCH \ - | sed 's/.*[ ]\([0-9][0-9]*\).*/\1/'` - echo $major.$minor.$patch -fi - -if test "$echo_cflags" = "yes" ; then - echo $cflags | sed "s|$orig_includedir/freetype2|$includedir/freetype2|" -fi - -if test "$echo_libs" = "yes" ; then - if test "$show_static" = "yes" ; then - libs="$libs_L $static_libs" - else - libs="$libs_L $dynamic_libs" - fi - echo $libs | sed "s|$orig_libdir|$libdir|" -fi - -if test "$echo_libtool" = "yes" ; then - echo ${SYSROOT}$libdir/libfreetype.la -fi - -# EOF diff --git a/freetype/builds/unix/freetype2.in b/freetype/builds/unix/freetype2.in deleted file mode 100644 index fe389f4..0000000 --- a/freetype/builds/unix/freetype2.in +++ /dev/null @@ -1,14 +0,0 @@ -prefix=%prefix% -exec_prefix=%exec_prefix% -libdir=%libdir% -includedir=%includedir% - -Name: FreeType 2 -URL: https://freetype.org -Description: A free, high-quality, and portable font engine. -Version: %ft_version% -Requires: %PKGCONFIG_REQUIRES% -Requires.private: %PKGCONFIG_REQUIRES_PRIVATE% -Libs: %PKGCONFIG_LIBS% -Libs.private: %PKGCONFIG_LIBS_PRIVATE% -Cflags: -I${includedir}/freetype2 diff --git a/freetype/builds/unix/freetype2.m4 b/freetype/builds/unix/freetype2.m4 deleted file mode 100644 index 09ead43..0000000 --- a/freetype/builds/unix/freetype2.m4 +++ /dev/null @@ -1,194 +0,0 @@ -# Configure paths for FreeType2 -# Marcelo Magallon 2001-10-26, based on `gtk.m4` by Owen Taylor -# -# Copyright (C) 2001-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. -# -# As a special exception to the FreeType project license, this file may be -# distributed as part of a program that contains a configuration script -# generated by Autoconf, under the same distribution terms as the rest of -# that program. -# -# serial 7 - -# AC_CHECK_FT2([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) -# Test for FreeType 2, and define FT2_CFLAGS and FT2_LIBS. -# MINIMUM-VERSION is what libtool reports; the default is '7.0.1' (this is -# FreeType 2.0.4). -# -# To make this code work with older autoconf versions, `AS_HELP_STRING` is -# not quoted. -# -AC_DEFUN([AC_CHECK_FT2], - [# Get the cflags and libraries from the freetype-config script - # - AC_ARG_WITH([ft-prefix], - AS_HELP_STRING([--with-ft-prefix=PREFIX], - [Prefix where FreeType is installed (optional)]), - [ft_config_prefix="$withval"], - [ft_config_prefix=""]) - - AC_ARG_WITH([ft-exec-prefix], - AS_HELP_STRING([--with-ft-exec-prefix=PREFIX], - [Exec prefix where FreeType is installed (optional)]), - [ft_config_exec_prefix="$withval"], - [ft_config_exec_prefix=""]) - - AC_ARG_ENABLE([freetypetest], - AS_HELP_STRING([--disable-freetypetest], - [Do not try to compile and run a test FreeType program]), - [], - [enable_fttest=yes]) - - if test x$ft_config_exec_prefix != x ; then - ft_config_args="$ft_config_args --exec-prefix=$ft_config_exec_prefix" - if test x${FT2_CONFIG+set} != xset ; then - FT2_CONFIG=$ft_config_exec_prefix/bin/freetype-config - fi - fi - - if test x$ft_config_prefix != x ; then - ft_config_args="$ft_config_args --prefix=$ft_config_prefix" - if test x${FT2_CONFIG+set} != xset ; then - FT2_CONFIG=$ft_config_prefix/bin/freetype-config - fi - fi - - if test "x$FT2_CONFIG" = x ; then - AC_PATH_TOOL([FT2_CONFIG], [freetype-config], [no]) - fi - - min_ft_version=m4_if([$1], [], [7.0.1], [$1]) - AC_MSG_CHECKING([for FreeType -- version >= $min_ft_version]) - no_ft="" - if test "$FT2_CONFIG" = "no" ; then - no_ft=yes - else - FT2_CFLAGS=`$FT2_CONFIG $ft_config_args --cflags` - FT2_LIBS=`$FT2_CONFIG $ft_config_args --libs` - ft_config_major_version=`$FT2_CONFIG $ft_config_args --version | \ - sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` - ft_config_minor_version=`$FT2_CONFIG $ft_config_args --version | \ - sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` - ft_config_micro_version=`$FT2_CONFIG $ft_config_args --version | \ - sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` - ft_min_major_version=`echo $min_ft_version | \ - sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` - ft_min_minor_version=`echo $min_ft_version | \ - sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` - ft_min_micro_version=`echo $min_ft_version | \ - sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` - if test x$enable_fttest = xyes ; then - ft_config_is_lt="" - if test $ft_config_major_version -lt $ft_min_major_version ; then - ft_config_is_lt=yes - else - if test $ft_config_major_version -eq $ft_min_major_version ; then - if test $ft_config_minor_version -lt $ft_min_minor_version ; then - ft_config_is_lt=yes - else - if test $ft_config_minor_version -eq $ft_min_minor_version ; then - if test $ft_config_micro_version -lt $ft_min_micro_version ; then - ft_config_is_lt=yes - fi - fi - fi - fi - fi - if test x$ft_config_is_lt = xyes ; then - no_ft=yes - else - ac_save_CFLAGS="$CFLAGS" - ac_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $FT2_CFLAGS" - LIBS="$FT2_LIBS $LIBS" - - # - # Sanity checks for the results of freetype-config to some extent. - # - AC_RUN_IFELSE([ - AC_LANG_SOURCE([[ - -#include -#include -#include -#include - -int -main(void) -{ - FT_Library library; - FT_Error error; - - error = FT_Init_FreeType(&library); - - if (error) - return 1; - else - { - FT_Done_FreeType(library); - return 0; - } -} - - ]]) - ], - [], - [no_ft=yes], - [echo $ECHO_N "cross compiling; assuming OK... $ECHO_C"]) - - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi # test $ft_config_version -lt $ft_min_version - fi # test x$enable_fttest = xyes - fi # test "$FT2_CONFIG" = "no" - - if test x$no_ft = x ; then - AC_MSG_RESULT([yes]) - m4_if([$2], [], [:], [$2]) - else - AC_MSG_RESULT([no]) - if test "$FT2_CONFIG" = "no" ; then - AC_MSG_WARN([ - - The freetype-config script installed by FreeType 2 could not be found. - If FreeType 2 was installed in PREFIX, make sure PREFIX/bin is in - your path, or set the FT2_CONFIG environment variable to the - full path to freetype-config. - ]) - else - if test x$ft_config_is_lt = xyes ; then - AC_MSG_WARN([ - - Your installed version of the FreeType 2 library is too old. - If you have different versions of FreeType 2, make sure that - correct values for --with-ft-prefix or --with-ft-exec-prefix - are used, or set the FT2_CONFIG environment variable to the - full path to freetype-config. - ]) - else - AC_MSG_WARN([ - - The FreeType test program failed to run. If your system uses - shared libraries and they are installed outside the normal - system library path, make sure the variable LD_LIBRARY_PATH - (or whatever is appropriate for your system) is correctly set. - ]) - fi - fi - - FT2_CFLAGS="" - FT2_LIBS="" - m4_if([$3], [], [:], [$3]) - fi - - AC_SUBST([FT2_CFLAGS]) - AC_SUBST([FT2_LIBS])]) - -# end of freetype2.m4 diff --git a/freetype/builds/unix/ft-munmap.m4 b/freetype/builds/unix/ft-munmap.m4 deleted file mode 100644 index a0fcf35..0000000 --- a/freetype/builds/unix/ft-munmap.m4 +++ /dev/null @@ -1,32 +0,0 @@ -## FreeType specific autoconf tests -# -# Copyright (C) 2002-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# serial 2 - -AC_DEFUN([FT_MUNMAP_PARAM], - [AC_MSG_CHECKING([for munmap's first parameter type]) - AC_COMPILE_IFELSE([ - AC_LANG_SOURCE([[ - -#include -#include -int munmap(void *, size_t); - - ]]) - ], - [AC_MSG_RESULT([void *]) - AC_DEFINE([MUNMAP_USES_VOIDP], - [], - [Define to 1 if the first argument of munmap is of type void *])], - [AC_MSG_RESULT([char *])]) - ]) - -# end of ft-munmap.m4 diff --git a/freetype/builds/unix/ftconfig.h.in b/freetype/builds/unix/ftconfig.h.in deleted file mode 100644 index 3dac561..0000000 --- a/freetype/builds/unix/ftconfig.h.in +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** - * - * ftconfig.h.in - * - * UNIX-specific configuration file (specification only). - * - * Copyright (C) 1996-2023 by - * David Turner, Robert Wilhelm, and Werner Lemberg. - * - * This file is part of the FreeType project, and may only be used, - * modified, and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify, or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - */ - - - /************************************************************************** - * - * This header file contains a number of macro definitions that are used by - * the rest of the engine. Most of the macros here are automatically - * determined at compile time, and you should not need to change it to port - * FreeType, except to compile the library with a non-ANSI compiler. - * - * Note however that if some specific modifications are needed, we advise - * you to place a modified copy in your build directory. - * - * The build directory is usually `builds/`, and contains - * system-specific files that are always included first when building the - * library. - * - */ - -#ifndef FTCONFIG_H_ -#define FTCONFIG_H_ - -#include -#include FT_CONFIG_OPTIONS_H -#include FT_CONFIG_STANDARD_LIBRARY_H - -#undef HAVE_UNISTD_H -#undef HAVE_FCNTL_H - -#include -#include -#include - -#endif /* FTCONFIG_H_ */ - - -/* END */ diff --git a/freetype/builds/unix/ftsystem.c b/freetype/builds/unix/ftsystem.c deleted file mode 100644 index 5927215..0000000 --- a/freetype/builds/unix/ftsystem.c +++ /dev/null @@ -1,436 +0,0 @@ -/**************************************************************************** - * - * ftsystem.c - * - * Unix-specific FreeType low-level system interface (body). - * - * Copyright (C) 1996-2023 by - * David Turner, Robert Wilhelm, and Werner Lemberg. - * - * This file is part of the FreeType project, and may only be used, - * modified, and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify, or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - */ - - -#include - /* we use our special ftconfig.h file, not the standard one */ -#include FT_CONFIG_CONFIG_H -#include -#include -#include -#include -#include - - /* memory-mapping includes and definitions */ -#ifdef HAVE_UNISTD_H -#include -#endif - -#include -#ifndef MAP_FILE -#define MAP_FILE 0x00 -#endif - -#ifdef MUNMAP_USES_VOIDP -#define MUNMAP_ARG_CAST void * -#else -#define MUNMAP_ARG_CAST char * -#endif - -#ifdef NEED_MUNMAP_DECL - -#ifdef __cplusplus - extern "C" -#else - extern -#endif - int - munmap( char* addr, - int len ); - -#define MUNMAP_ARG_CAST char * - -#endif /* NEED_DECLARATION_MUNMAP */ - - -#include -#include - -#ifdef HAVE_FCNTL_H -#include -#endif - -#include -#include -#include -#include - - - /************************************************************************** - * - * MEMORY MANAGEMENT INTERFACE - * - */ - - - /************************************************************************** - * - * It is not necessary to do any error checking for the - * allocation-related functions. This will be done by the higher level - * routines like ft_mem_alloc() or ft_mem_realloc(). - * - */ - - - /************************************************************************** - * - * @Function: - * ft_alloc - * - * @Description: - * The memory allocation function. - * - * @Input: - * memory :: - * A pointer to the memory object. - * - * size :: - * The requested size in bytes. - * - * @Return: - * The address of newly allocated block. - */ - FT_CALLBACK_DEF( void* ) - ft_alloc( FT_Memory memory, - long size ) - { - FT_UNUSED( memory ); - - return malloc( size ); - } - - - /************************************************************************** - * - * @Function: - * ft_realloc - * - * @Description: - * The memory reallocation function. - * - * @Input: - * memory :: - * A pointer to the memory object. - * - * cur_size :: - * The current size of the allocated memory block. - * - * new_size :: - * The newly requested size in bytes. - * - * block :: - * The current address of the block in memory. - * - * @Return: - * The address of the reallocated memory block. - */ - FT_CALLBACK_DEF( void* ) - ft_realloc( FT_Memory memory, - long cur_size, - long new_size, - void* block ) - { - FT_UNUSED( memory ); - FT_UNUSED( cur_size ); - - return realloc( block, new_size ); - } - - - /************************************************************************** - * - * @Function: - * ft_free - * - * @Description: - * The memory release function. - * - * @Input: - * memory :: - * A pointer to the memory object. - * - * block :: - * The address of block in memory to be freed. - */ - FT_CALLBACK_DEF( void ) - ft_free( FT_Memory memory, - void* block ) - { - FT_UNUSED( memory ); - - free( block ); - } - - - /************************************************************************** - * - * RESOURCE MANAGEMENT INTERFACE - * - */ - - - /************************************************************************** - * - * The macro FT_COMPONENT is used in trace mode. It is an implicit - * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log - * messages during execution. - */ -#undef FT_COMPONENT -#define FT_COMPONENT io - - /* We use the macro STREAM_FILE for convenience to extract the */ - /* system-specific stream handle from a given FreeType stream object */ -#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer ) - - - /************************************************************************** - * - * @Function: - * ft_close_stream_by_munmap - * - * @Description: - * The function to close a stream which is opened by mmap. - * - * @Input: - * stream :: A pointer to the stream object. - */ - FT_CALLBACK_DEF( void ) - ft_close_stream_by_munmap( FT_Stream stream ) - { - munmap( (MUNMAP_ARG_CAST)stream->descriptor.pointer, stream->size ); - - stream->descriptor.pointer = NULL; - stream->size = 0; - stream->base = NULL; - } - - - /************************************************************************** - * - * @Function: - * ft_close_stream_by_free - * - * @Description: - * The function to close a stream which is created by ft_alloc. - * - * @Input: - * stream :: A pointer to the stream object. - */ - FT_CALLBACK_DEF( void ) - ft_close_stream_by_free( FT_Stream stream ) - { - ft_free( stream->memory, stream->descriptor.pointer ); - - stream->descriptor.pointer = NULL; - stream->size = 0; - stream->base = NULL; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Error ) - FT_Stream_Open( FT_Stream stream, - const char* filepathname ) - { - int file; - struct stat stat_buf; - - - if ( !stream ) - return FT_THROW( Invalid_Stream_Handle ); - - /* open the file */ - file = open( filepathname, O_RDONLY ); - if ( file < 0 ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not open `%s'\n", filepathname )); - return FT_THROW( Cannot_Open_Resource ); - } - - /* Here we ensure that a "fork" will _not_ duplicate */ - /* our opened input streams on Unix. This is critical */ - /* since it avoids some (possible) access control */ - /* issues and cleans up the kernel file table a bit. */ - /* */ -#ifdef F_SETFD -#ifdef FD_CLOEXEC - (void)fcntl( file, F_SETFD, FD_CLOEXEC ); -#else - (void)fcntl( file, F_SETFD, 1 ); -#endif /* FD_CLOEXEC */ -#endif /* F_SETFD */ - - if ( fstat( file, &stat_buf ) < 0 ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not `fstat' file `%s'\n", filepathname )); - goto Fail_Map; - } - - /* XXX: TODO -- real 64bit platform support */ - /* */ - /* `stream->size' is typedef'd to unsigned long (in `ftsystem.h'); */ - /* `stat_buf.st_size', however, is usually typedef'd to off_t */ - /* (in sys/stat.h). */ - /* On some platforms, the former is 32bit and the latter is 64bit. */ - /* To avoid overflow caused by fonts in huge files larger than */ - /* 2GB, do a test. Temporary fix proposed by Sean McBride. */ - /* */ - if ( stat_buf.st_size > LONG_MAX ) - { - FT_ERROR(( "FT_Stream_Open: file is too big\n" )); - goto Fail_Map; - } - else if ( stat_buf.st_size == 0 ) - { - FT_ERROR(( "FT_Stream_Open: zero-length file\n" )); - goto Fail_Map; - } - - /* This cast potentially truncates a 64bit to 32bit! */ - stream->size = (unsigned long)stat_buf.st_size; - stream->pos = 0; - stream->base = (unsigned char *)mmap( NULL, - stream->size, - PROT_READ, - MAP_FILE | MAP_PRIVATE, - file, - 0 ); - - if ( stream->base != MAP_FAILED ) - stream->close = ft_close_stream_by_munmap; - else - { - ssize_t total_read_count; - - - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not `mmap' file `%s'\n", filepathname )); - - stream->base = (unsigned char*)ft_alloc( stream->memory, stream->size ); - - if ( !stream->base ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not `alloc' memory\n" )); - goto Fail_Map; - } - - total_read_count = 0; - do - { - ssize_t read_count; - - - read_count = read( file, - stream->base + total_read_count, - stream->size - total_read_count ); - - if ( read_count <= 0 ) - { - if ( read_count == -1 && errno == EINTR ) - continue; - - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " error while `read'ing file `%s'\n", filepathname )); - goto Fail_Read; - } - - total_read_count += read_count; - - } while ( (unsigned long)total_read_count != stream->size ); - - stream->close = ft_close_stream_by_free; - } - - close( file ); - - stream->descriptor.pointer = stream->base; - stream->pathname.pointer = (char*)filepathname; - - stream->read = NULL; - - FT_TRACE1(( "FT_Stream_Open:" )); - FT_TRACE1(( " opened `%s' (%ld bytes) successfully\n", - filepathname, stream->size )); - - return FT_Err_Ok; - - Fail_Read: - ft_free( stream->memory, stream->base ); - - Fail_Map: - close( file ); - - stream->base = NULL; - stream->size = 0; - stream->pos = 0; - - return FT_THROW( Cannot_Open_Stream ); - } - - -#ifdef FT_DEBUG_MEMORY - - extern FT_Int - ft_mem_debug_init( FT_Memory memory ); - - extern void - ft_mem_debug_done( FT_Memory memory ); - -#endif - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Memory ) - FT_New_Memory( void ) - { - FT_Memory memory; - - - memory = (FT_Memory)malloc( sizeof ( *memory ) ); - if ( memory ) - { - memory->user = NULL; - memory->alloc = ft_alloc; - memory->realloc = ft_realloc; - memory->free = ft_free; -#ifdef FT_DEBUG_MEMORY - ft_mem_debug_init( memory ); -#endif - } - - return memory; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( void ) - FT_Done_Memory( FT_Memory memory ) - { -#ifdef FT_DEBUG_MEMORY - ft_mem_debug_done( memory ); -#endif - memory->free( memory, memory ); - } - - -/* END */ diff --git a/freetype/builds/unix/install.mk b/freetype/builds/unix/install.mk deleted file mode 100644 index 2f1729b..0000000 --- a/freetype/builds/unix/install.mk +++ /dev/null @@ -1,102 +0,0 @@ -# -# FreeType 2 installation instructions for Unix systems -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# If you say -# -# make install DESTDIR=/tmp/somewhere/ -# -# don't forget the final backslash (this command is mainly for package -# maintainers). - - -.PHONY: install uninstall check - -# Unix installation and deinstallation targets. -# -# Note that we remove any data found in `$(includedir)/freetype2' before -# installing new files to avoid interferences with files installed by -# previous FreeType versions (which use slightly different locations). -# -# We also remove `$(includedir)/ft2build.h' for the same reason. -# -# Note that some header files get handled twice for simplicity; a special, -# configured version overwrites the generic one. -# -install: $(PROJECT_LIBRARY) - -$(DELDIR) $(DESTDIR)$(includedir)/freetype2 - -$(DELETE) $(DESTDIR)$(includedir)/ft2build.h - $(MKINSTALLDIRS) $(DESTDIR)$(libdir) \ - $(DESTDIR)$(libdir)/pkgconfig \ - $(DESTDIR)$(includedir)/freetype2/freetype/config \ - $(DESTDIR)$(datadir)/aclocal -ifeq ($(INSTALL_FT2_CONFIG),TRUE) - $(MKINSTALLDIRS) $(DESTDIR)$(bindir) \ - $(DESTDIR)$(mandir)/man1 -endif - $(LIBTOOL) --mode=install $(INSTALL) \ - $(PROJECT_LIBRARY) $(DESTDIR)$(libdir) - -for P in $(PUBLIC_H) ; do \ - $(INSTALL_DATA) \ - $$P $(DESTDIR)$(includedir)/freetype2/freetype ; \ - done - -for P in $(CONFIG_H) ; do \ - $(INSTALL_DATA) \ - $$P $(DESTDIR)$(includedir)/freetype2/freetype/config ; \ - done - $(INSTALL_DATA) $(TOP_DIR)/include/ft2build.h \ - $(DESTDIR)$(includedir)/freetype2/ft2build.h - $(INSTALL_DATA) $(OBJ_BUILD)/ftconfig.h \ - $(DESTDIR)$(includedir)/freetype2/freetype/config/ftconfig.h - $(INSTALL_DATA) $(OBJ_DIR)/ftmodule.h \ - $(DESTDIR)$(includedir)/freetype2/freetype/config/ftmodule.h - $(INSTALL_DATA) $(OBJ_BUILD)/ftoption.h \ - $(DESTDIR)$(includedir)/freetype2/freetype/config/ftoption.h - $(INSTALL_SCRIPT) -m 644 $(PLATFORM_DIR)/freetype2.m4 \ - $(DESTDIR)$(datadir)/aclocal/freetype2.m4 - $(INSTALL_SCRIPT) -m 644 $(OBJ_BUILD)/freetype2.pc \ - $(DESTDIR)$(libdir)/pkgconfig/freetype2.pc -ifeq ($(INSTALL_FT2_CONFIG),TRUE) - $(INSTALL_SCRIPT) -m 755 $(OBJ_BUILD)/freetype-config \ - $(DESTDIR)$(bindir)/freetype-config - $(INSTALL_DATA) $(TOP_DIR)/docs/freetype-config.1 \ - $(DESTDIR)$(mandir)/man1/freetype-config.1 -endif - - -uninstall: - -$(LIBTOOL) --mode=uninstall $(RM) $(DESTDIR)$(libdir)/$(LIBRARY).$A - -$(DELDIR) $(DESTDIR)$(includedir)/freetype2 - -$(DELETE) $(DESTDIR)$(bindir)/freetype-config - -$(DELETE) $(DESTDIR)$(datadir)/aclocal/freetype2.m4 - -$(DELETE) $(DESTDIR)$(libdir)/pkgconfig/freetype2.pc - -$(DELETE) $(DESTDIR)$(mandir)/man1/freetype-config.1 - - -check: - $(info There is no validation suite for this package.) - - -.PHONY: clean_project_unix distclean_project_unix - -# Unix cleaning and distclean rules. -# -clean_project_unix: - -$(LIBTOOL) --mode=clean $(RM) $(OBJECTS_LIST) - -$(DELETE) $(CLEAN) - -distclean_project_unix: clean_project_unix - -$(LIBTOOL) --mode=clean $(RM) $(PROJECT_LIBRARY) - -$(DELETE) *.orig *~ core *.core $(DISTCLEAN) - -# EOF diff --git a/freetype/builds/unix/pkg.m4 b/freetype/builds/unix/pkg.m4 deleted file mode 100644 index 260e1fb..0000000 --- a/freetype/builds/unix/pkg.m4 +++ /dev/null @@ -1,199 +0,0 @@ -# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- -# serial 1 (pkg-config-0.24) -# -# Copyright © 2004 Scott James Remnant . -# -# 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. -# -# 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. - -# PKG_PROG_PKG_CONFIG([MIN-VERSION]) -# ---------------------------------- -AC_DEFUN([PKG_PROG_PKG_CONFIG], -[m4_pattern_forbid([^_?PKG_[A-Z_]+$]) -m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$]) -m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$]) -AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility]) -AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path]) -AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path]) - -if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then - AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) -fi -if test -n "$PKG_CONFIG"; then - _pkg_min_version=m4_default([$1], [0.9.0]) - AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) - if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no]) - PKG_CONFIG="" - fi -fi[]dnl -])# PKG_PROG_PKG_CONFIG - -# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) -# -# Check to see whether a particular set of modules exists. Similar -# to PKG_CHECK_MODULES(), but does not set variables or print errors. -# -# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) -# only at the first occurrence in configure.ac, so if the first place -# it's called might be skipped (such as if it is within an "if", you -# have to call PKG_CHECK_EXISTS manually -# -------------------------------------------------------------- -AC_DEFUN([PKG_CHECK_EXISTS], -[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl -if test -n "$PKG_CONFIG" && \ - AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then - m4_default([$2], [:]) -m4_ifvaln([$3], [else - $3])dnl -fi]) - -# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) -# --------------------------------------------- -m4_define([_PKG_CONFIG], -[if test -n "$$1"; then - pkg_cv_[]$1="$$1" - elif test -n "$PKG_CONFIG"; then - PKG_CHECK_EXISTS([$3], - [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null` - test "x$?" != "x0" && pkg_failed=yes ], - [pkg_failed=yes]) - else - pkg_failed=untried -fi[]dnl -])# _PKG_CONFIG - -# _PKG_SHORT_ERRORS_SUPPORTED -# ----------------------------- -AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], -[AC_REQUIRE([PKG_PROG_PKG_CONFIG]) -if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then - _pkg_short_errors_supported=yes -else - _pkg_short_errors_supported=no -fi[]dnl -])# _PKG_SHORT_ERRORS_SUPPORTED - - -# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], -# [ACTION-IF-NOT-FOUND]) -# -# -# Note that if there is a possibility the first call to -# PKG_CHECK_MODULES might not happen, you should be sure to include an -# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac -# -# -# -------------------------------------------------------------- -AC_DEFUN([PKG_CHECK_MODULES], -[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl -AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl -AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl - -pkg_failed=no -AC_MSG_CHECKING([for $1]) - -_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) -_PKG_CONFIG([$1][_LIBS], [libs], [$2]) - -m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS -and $1[]_LIBS to avoid the need to call pkg-config. -See the pkg-config man page for more details.]) - -if test $pkg_failed = yes; then - AC_MSG_RESULT([no]) - _PKG_SHORT_ERRORS_SUPPORTED - if test $_pkg_short_errors_supported = yes; then - $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1` - else - $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1` - fi - # Put the nasty error message in config.log where it belongs - echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD - - m4_default([$4], [AC_MSG_ERROR( -[Package requirements ($2) were not met: - -$$1_PKG_ERRORS - -Consider adjusting the PKG_CONFIG_PATH environment variable if you -installed software in a non-standard prefix. - -_PKG_TEXT])[]dnl - ]) -elif test $pkg_failed = untried; then - AC_MSG_RESULT([no]) - m4_default([$4], [AC_MSG_FAILURE( -[The pkg-config script could not be found or is too old. Make sure it -is in your PATH or set the PKG_CONFIG environment variable to the full -path to pkg-config. - -_PKG_TEXT - -To get pkg-config, see .])[]dnl - ]) -else - $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS - $1[]_LIBS=$pkg_cv_[]$1[]_LIBS - AC_MSG_RESULT([yes]) - $3 -fi[]dnl -])# PKG_CHECK_MODULES - - -# PKG_INSTALLDIR(DIRECTORY) -# ------------------------- -# Substitutes the variable pkgconfigdir as the location where a module -# should install pkg-config .pc files. By default the directory is -# $libdir/pkgconfig, but the default can be changed by passing -# DIRECTORY. The user can override through the --with-pkgconfigdir -# parameter. -AC_DEFUN([PKG_INSTALLDIR], -[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])]) -m4_pushdef([pkg_description], - [pkg-config installation directory @<:@]pkg_default[@:>@]) -AC_ARG_WITH([pkgconfigdir], - [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],, - [with_pkgconfigdir=]pkg_default) -AC_SUBST([pkgconfigdir], [$with_pkgconfigdir]) -m4_popdef([pkg_default]) -m4_popdef([pkg_description]) -]) dnl PKG_INSTALLDIR - - -# PKG_NOARCH_INSTALLDIR(DIRECTORY) -# ------------------------- -# Substitutes the variable noarch_pkgconfigdir as the location where a -# module should install arch-independent pkg-config .pc files. By -# default the directory is $datadir/pkgconfig, but the default can be -# changed by passing DIRECTORY. The user can override through the -# --with-noarch-pkgconfigdir parameter. -AC_DEFUN([PKG_NOARCH_INSTALLDIR], -[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])]) -m4_pushdef([pkg_description], - [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@]) -AC_ARG_WITH([noarch-pkgconfigdir], - [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],, - [with_noarch_pkgconfigdir=]pkg_default) -AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir]) -m4_popdef([pkg_default]) -m4_popdef([pkg_description]) -]) dnl PKG_NOARCH_INSTALLDIR diff --git a/freetype/builds/unix/unix-cc.in b/freetype/builds/unix/unix-cc.in deleted file mode 100644 index 802016d..0000000 --- a/freetype/builds/unix/unix-cc.in +++ /dev/null @@ -1,130 +0,0 @@ -# -# FreeType 2 template for Unix-specific compiler definitions -# - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -CC := @CC@ -COMPILER_SEP := $(SEP) -FT_LIBTOOL_DIR ?= $(PLATFORM_DIR) - -LIBTOOL := $(FT_LIBTOOL_DIR)/libtool - - -# The object file extension (for standard and static libraries). This can be -# .o, .tco, .obj, etc., depending on the platform. -# -O := lo -SO := o - - -# The executable file extension. Although most Unix platforms use no -# extension, we copy the extension detected by autoconf. Useful for cross -# building on Unix systems for non-Unix systems. -# -E := @EXEEXT@ - - -# The library file extension (for standard and static libraries). This can -# be .a, .lib, etc., depending on the platform. -# -A := la -SA := a - - -# The name of the final library file. Note that the DOS-specific Makefile -# uses a shorter (8.3) name. -# -LIBRARY := lib$(PROJECT) - - -# Path inclusion flag. Some compilers use a different flag than `-I' to -# specify an additional include path. Examples are `/i=' or `-J'. -# -I := -I - - -# C flag used to define a macro before the compilation of a given source -# object. Usually it is `-D' like in `-DDEBUG'. -# -D := -D - - -# The link flag used to specify a given library file on link. Note that -# this is only used to compile the demo programs, not the library itself. -# -L := -l - - -# Target flag. -# -T := -o$(space) - - -# C flags -# -# These should concern: debug output, optimization & warnings. -# -# Use the ANSIFLAGS variable to define the compiler flags used to enforce -# ANSI compliance. -# -# We use our own FreeType configuration files overriding defaults. -# -CPPFLAGS := @CPPFLAGS@ -CFLAGS := -c @XX_CFLAGS@ @CFLAGS@ \ - $DFT_CONFIG_CONFIG_H="" \ - $DFT_CONFIG_MODULES_H="" \ - $DFT_CONFIG_OPTIONS_H="" - -# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. -# -ANSIFLAGS := @XX_ANSIFLAGS@ - -# C compiler to use -- we use libtool! -# -# CC might be set on the command line; we store this value in `CCraw'. -# Consequently, we use the `override' directive to ensure that the -# libtool call is always prepended. -# -CCraw := $(CC) -override CC := $(LIBTOOL) --mode=compile $(CCraw) - -# Resource compiler to use on Cygwin/MinGW, usually windres. -# -RCraw := @RC@ -ifneq ($(RCraw),) - RC := $(LIBTOOL) --tag=RC --mode=compile $(RCraw) -endif - -# Linker flags. -# -LDFLAGS := @LDFLAGS@ - -# export symbols -# -CCraw_build := @CC_BUILD@ # native CC of building system -E_BUILD := @EXEEXT_BUILD@ # extension for executable on building system -EXPORTS_LIST := $(OBJ_DIR)/ftexport.sym -CCexe := $(CCraw_build) # used to compile `apinames' only - - -# Library linking. -# -LINK_LIBRARY = $(LIBTOOL) --mode=link $(CCraw) -o $@ $(OBJECTS_LIST) \ - -rpath $(libdir) -version-info $(version_info) \ - $(LDFLAGS) -no-undefined \ - -export-symbols $(EXPORTS_LIST) - -# For the demo programs. -FT_DEMO_CFLAGS := @FT_DEMO_CFLAGS@ -FT_DEMO_LDFLAGS := @FT_DEMO_LDFLAGS@ - -# EOF diff --git a/freetype/builds/unix/unix-def.in b/freetype/builds/unix/unix-def.in deleted file mode 100644 index d50994f..0000000 --- a/freetype/builds/unix/unix-def.in +++ /dev/null @@ -1,163 +0,0 @@ -# -# FreeType 2 configuration rules templates for Unix + configure -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -SHELL := @SHELL@ - -TOP_DIR := $(shell cd $(TOP_DIR); pwd) - -DELETE := rm -f -DELDIR := rm -rf -CAT := cat -SEP := / - -# This is used for `make refdoc' and `make refdoc-venv' -# -PYTHON := @PYTHON@ -BIN := bin - -# this is used for `make distclean' and `make install' -OBJ_BUILD ?= $(PLATFORM_DIR) - -# don't use `:=' here since the path stuff will be included after this file -# -FTSYS_SRC = @FTSYS_SRC@ - -INSTALL := @INSTALL@ -INSTALL_DATA := @INSTALL_DATA@ -INSTALL_PROGRAM := @INSTALL_PROGRAM@ -INSTALL_SCRIPT := @INSTALL_SCRIPT@ -MKINSTALLDIRS := @MKDIR_P@ - -CLEAN += $(OBJ_BUILD)/freetype-config \ - $(OBJ_BUILD)/freetype2.pc - -DISTCLEAN += $(OBJ_BUILD)/config.cache \ - $(OBJ_BUILD)/config.log \ - $(OBJ_BUILD)/config.status \ - $(OBJ_BUILD)/unix-def.mk \ - $(OBJ_BUILD)/unix-cc.mk \ - $(OBJ_BUILD)/ftconfig.h \ - $(OBJ_BUILD)/ftoption.h \ - $(LIBTOOL) \ - $(OBJ_BUILD)/Makefile - - -# Standard installation variables. -# -prefix := @prefix@ -exec_prefix := @exec_prefix@ -libdir := @libdir@ -bindir := @bindir@ -includedir := @includedir@ -datarootdir := @datarootdir@ -datadir := @datadir@ -mandir := @mandir@ - -version_info := @version_info@ - -# Variables needed for `freetype-config' and `freetype.pc'. -# -PKG_CONFIG := @PKG_CONFIG@ -PKGCONFIG_REQUIRES := @PKGCONFIG_REQUIRES@ -PKGCONFIG_REQUIRES_PRIVATE := @PKGCONFIG_REQUIRES_PRIVATE@ -PKGCONFIG_LIBS := @PKGCONFIG_LIBS@ -PKGCONFIG_LIBS_PRIVATE := @PKGCONFIG_LIBS_PRIVATE@ -LIBSSTATIC_CONFIG := @LIBSSTATIC_CONFIG@ -build_libtool_libs := @build_libtool_libs@ -ft_version := @ft_version@ - -# The directory where all library files are placed. -# -# By default, this is the same as $(OBJ_DIR); however, this can be changed -# to suit particular needs. -# -LIB_DIR := $(OBJ_DIR) - -# The BASE_SRC macro lists all source files that should be included in -# src/base/ftbase.c. When configure sets up CFLAGS to build ftmac.c, -# ftmac.c should be added to BASE_SRC. -ftmac_c := @ftmac_c@ - -# The SYSTEM_ZLIB macro is defined if the user wishes to link dynamically -# with its system wide zlib. If SYSTEM_ZLIB is 'yes', the zlib part of the -# ftgzip module is not compiled in. -SYSTEM_ZLIB := @SYSTEM_ZLIB@ - - -# The NO_OUTPUT macro is appended to command lines in order to ignore -# the output of some programs. -# -NO_OUTPUT := 2> /dev/null - - -# To support calls like -# -# configure --includedir='${libdir}'/freetype2/include -# -# we generate `freetype-config' and `freetype.pc' at compile time so that -# those variables are properly expanded. - -$(OBJ_BUILD)/freetype-config: $(TOP_DIR)/builds/unix/freetype-config.in - rm -f $@ $@.tmp - sed -e 's|%LIBSSTATIC_CONFIG%|$(LIBSSTATIC_CONFIG)|' \ - -e 's|%PKG_CONFIG%|$(PKG_CONFIG)|' \ - -e 's|%build_libtool_libs%|$(build_libtool_libs)|' \ - -e 's|%exec_prefix%|$(exec_prefix)|' \ - -e 's|%ft_version%|$(ft_version)|' \ - -e 's|%includedir%|$(includedir)|' \ - -e 's|%libdir%|$(libdir)|' \ - -e 's|%prefix%|$(prefix)|' \ - $< \ - > $@.tmp - chmod +x $@.tmp - chmod go-w $@.tmp - mv $@.tmp $@ - -# To support directory names with spaces (as might easily happen on Windows -# platforms), the right solution would be to surround the pkg-variables in -# `freetype2.pc' with double quotes. However, doing so ironically disables -# the prefix override mechanism especially written for Windows. This is a -# bug in pkg-config version 0.28 and earlier. -# -# For this reason, we escape spaces with backslashes. - -exec_prefix_x := $(subst $(space),\\$(space),$(exec_prefix)) -includedir_x := $(subst $(space),\\$(space),$(includedir)) -libdir_x := $(subst $(space),\\$(space),$(libdir)) -prefix_x := $(subst $(space),\\$(space),$(prefix)) - -$(OBJ_BUILD)/freetype2.pc: $(TOP_DIR)/builds/unix/freetype2.in - rm -f $@ $@.tmp - sed -e 's|%PKGCONFIG_REQUIRES%|$(PKGCONFIG_REQUIRES)|' \ - -e 's|%PKGCONFIG_REQUIRES_PRIVATE%|$(PKGCONFIG_REQUIRES_PRIVATE)|' \ - -e 's|%PKGCONFIG_LIBS%|$(PKGCONFIG_LIBS)|' \ - -e 's|%PKGCONFIG_LIBS_PRIVATE%|$(PKGCONFIG_LIBS_PRIVATE)|' \ - -e 's|%build_libtool_libs%|$(build_libtool_libs)|' \ - -e 's|%exec_prefix%|$(exec_prefix_x)|' \ - -e 's|%ft_version%|$(ft_version)|' \ - -e 's|%includedir%|$(includedir_x)|' \ - -e 's|%libdir%|$(libdir_x)|' \ - -e 's|%prefix%|$(prefix_x)|' \ - $< \ - > $@.tmp - chmod a-w $@.tmp - mv $@.tmp $@ - -# defines whether we should install `freetype-config' or not -INSTALL_FT2_CONFIG = @INSTALL_FT2_CONFIG@ - -all install: $(OBJ_BUILD)/freetype-config \ - $(OBJ_BUILD)/freetype2.pc - -# EOF diff --git a/freetype/builds/unix/unix-dev.mk b/freetype/builds/unix/unix-dev.mk deleted file mode 100644 index 9dd8ad6..0000000 --- a/freetype/builds/unix/unix-dev.mk +++ /dev/null @@ -1,26 +0,0 @@ -# -# FreeType 2 Configuration rules for Unix + GCC -# -# Development version without optimizations & libtool -# and no installation. -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -DEVEL_DIR := $(TOP_DIR)/devel - -include $(TOP_DIR)/builds/unix/unixddef.mk -include $(TOP_DIR)/builds/compiler/gcc-dev.mk -include $(TOP_DIR)/builds/link_std.mk - - -# EOF diff --git a/freetype/builds/unix/unix-lcc.mk b/freetype/builds/unix/unix-lcc.mk deleted file mode 100644 index ded24f4..0000000 --- a/freetype/builds/unix/unix-lcc.mk +++ /dev/null @@ -1,24 +0,0 @@ -# -# FreeType 2 Configuration rules for Unix + LCC -# -# Development version without optimizations & libtool -# and no installation. -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -include $(TOP_DIR)/builds/unix/unixddef.mk -include $(TOP_DIR)/builds/compiler/unix-lcc.mk -include $(TOP_DIR)/builds/link_std.mk - - -# EOF diff --git a/freetype/builds/unix/unix.mk b/freetype/builds/unix/unix.mk deleted file mode 100644 index 3505175..0000000 --- a/freetype/builds/unix/unix.mk +++ /dev/null @@ -1,62 +0,0 @@ -# -# FreeType 2 configuration rules for UNIX platforms -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# We need these declarations here since unix-def.mk is a generated file. -PLATFORM_DIR := $(TOP_DIR)/builds/unix -PLATFORM := unix - -have_mk := $(wildcard $(OBJ_DIR)/unix-def.mk) -ifneq ($(have_mk),) - # We are building FreeType 2 not in the src tree. - include $(OBJ_DIR)/unix-def.mk - include $(OBJ_DIR)/unix-cc.mk -else - include $(PLATFORM_DIR)/unix-def.mk - include $(PLATFORM_DIR)/unix-cc.mk -endif - -ifdef BUILD_PROJECT - - .PHONY: clean_project distclean_project - - # Now include the main sub-makefile. It contains all the rules used to - # build the library with the previous variables defined. - # - include $(TOP_DIR)/builds/$(PROJECT).mk - - - # The cleanup targets. - # - clean_project: clean_project_unix - distclean_project: distclean_project_unix - - - # This final rule is used to link all object files into a single library. - # It is part of the system-specific sub-Makefile because not all - # librarians accept a simple syntax like - # - # librarian library_file {list of object files} - # - $(PROJECT_LIBRARY): $(OBJECTS_LIST) - ifdef CLEAN_LIBRARY - -$(CLEAN_LIBRARY) $(NO_OUTPUT) - endif - $(LINK_LIBRARY) - - include $(TOP_DIR)/builds/unix/install.mk - -endif - - -# EOF diff --git a/freetype/builds/unix/unixddef.mk b/freetype/builds/unix/unixddef.mk deleted file mode 100644 index 7197347..0000000 --- a/freetype/builds/unix/unixddef.mk +++ /dev/null @@ -1,46 +0,0 @@ -# -# FreeType 2 configuration rules templates for -# development under Unix with no configure script (gcc only) -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -TOP_DIR := $(shell cd $(TOP_DIR); pwd) -OBJ_DIR := $(shell cd $(OBJ_DIR); pwd) - -PLATFORM := unix - -DELETE := rm -f -CAT := cat -SEP := / - -# This is used for `make refdoc' and `make refdoc-venv' -# -BIN := bin - - -# library file name -# -LIBRARY := lib$(PROJECT) - - -# The directory where all library files are placed. -# -# By default, this is the same as $(OBJ_DIR); however, this can be changed -# to suit particular needs. -# -LIB_DIR := $(OBJ_DIR) - - -NO_OUTPUT := 2> /dev/null - -# EOF diff --git a/freetype/builds/vms/apinames_vms.bash b/freetype/builds/vms/apinames_vms.bash deleted file mode 100644 index e9b1b72..0000000 --- a/freetype/builds/vms/apinames_vms.bash +++ /dev/null @@ -1,2 +0,0 @@ -src/tools/apinames -wV include/freetype/*.h > freetype_vms0.opt -mv freetype_vms0.opt freetype_vms.opt diff --git a/freetype/builds/vms/ftconfig.h b/freetype/builds/vms/ftconfig.h deleted file mode 100644 index 31dfcec..0000000 --- a/freetype/builds/vms/ftconfig.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** - * - * ftconfig.h - * - * VMS-specific configuration file (specification only). - * - * Copyright (C) 1996-2023 by - * David Turner, Robert Wilhelm, and Werner Lemberg. - * - * This file is part of the FreeType project, and may only be used, - * modified, and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify, or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - */ - - - /************************************************************************** - * - * This header file contains a number of macro definitions that are used by - * the rest of the engine. Most of the macros here are automatically - * determined at compile time, and you should not need to change it to port - * FreeType, except to compile the library with a non-ANSI compiler. - * - * Note however that if some specific modifications are needed, we advise - * you to place a modified copy in your build directory. - * - * The build directory is usually `builds/`, and contains - * system-specific files that are always included first when building the - * library. - * - */ - -#ifndef FTCONFIG_H_ -#define FTCONFIG_H_ - -#include -#include FT_CONFIG_OPTIONS_H -#include FT_CONFIG_STANDARD_LIBRARY_H - -#define HAVE_UNISTD_H 1 -#define HAVE_FCNTL_H 1 - -#define SIZEOF_INT 4 -#define SIZEOF_LONG 4 - -#define FT_SIZEOF_INT 4 -#define FT_SIZEOF_LONG 4 - -#include -#include -#include - -#endif /* FTCONFIG_H_ */ - - -/* END */ diff --git a/freetype/builds/vms/ftsystem.c b/freetype/builds/vms/ftsystem.c deleted file mode 100644 index 0afd07d..0000000 --- a/freetype/builds/vms/ftsystem.c +++ /dev/null @@ -1,328 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftsystem.c */ -/* */ -/* VMS-specific FreeType low-level system interface (body). */ -/* */ -/* Copyright (C) 1996-2023 by */ -/* David Turner, Robert Wilhelm, and Werner Lemberg. */ -/* */ -/* This file is part of the FreeType project, and may only be used, */ -/* modified, and distributed under the terms of the FreeType project */ -/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ -/* this file you indicate that you have read the license and */ -/* understand and accept it fully. */ -/* */ -/***************************************************************************/ - - -#include - /* we use our special ftconfig.h file, not the standard one */ -#include -#include -#include -#include -#include -#include - - /* memory-mapping includes and definitions */ -#ifdef HAVE_UNISTD_H -#include -#endif - -#include -#ifndef MAP_FILE -#define MAP_FILE 0x00 -#endif - -#ifdef MUNMAP_USES_VOIDP -#define MUNMAP_ARG_CAST void * -#else -#define MUNMAP_ARG_CAST char * -#endif - -#ifdef NEED_MUNMAP_DECL - -#ifdef __cplusplus - extern "C" -#else - extern -#endif - int - munmap( char* addr, - int len ); - -#define MUNMAP_ARG_CAST char * - -#endif /* NEED_DECLARATION_MUNMAP */ - - -#include -#include - -#ifdef HAVE_FCNTL_H -#include -#endif - -#include -#include -#include - - - /*************************************************************************/ - /* */ - /* MEMORY MANAGEMENT INTERFACE */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* */ - /* ft_alloc */ - /* */ - /* */ - /* The memory allocation function. */ - /* */ - /* */ - /* memory :: A pointer to the memory object. */ - /* */ - /* size :: The requested size in bytes. */ - /* */ - /* */ - /* The address of newly allocated block. */ - /* */ - FT_CALLBACK_DEF( void* ) - ft_alloc( FT_Memory memory, - long size ) - { - FT_UNUSED( memory ); - - return malloc( size ); - } - - - /*************************************************************************/ - /* */ - /* */ - /* ft_realloc */ - /* */ - /* */ - /* The memory reallocation function. */ - /* */ - /* */ - /* memory :: A pointer to the memory object. */ - /* */ - /* cur_size :: The current size of the allocated memory block. */ - /* */ - /* new_size :: The newly requested size in bytes. */ - /* */ - /* block :: The current address of the block in memory. */ - /* */ - /* */ - /* The address of the reallocated memory block. */ - /* */ - FT_CALLBACK_DEF( void* ) - ft_realloc( FT_Memory memory, - long cur_size, - long new_size, - void* block ) - { - FT_UNUSED( memory ); - FT_UNUSED( cur_size ); - - return realloc( block, new_size ); - } - - - /*************************************************************************/ - /* */ - /* */ - /* ft_free */ - /* */ - /* */ - /* The memory release function. */ - /* */ - /* */ - /* memory :: A pointer to the memory object. */ - /* */ - /* block :: The address of block in memory to be freed. */ - /* */ - FT_CALLBACK_DEF( void ) - ft_free( FT_Memory memory, - void* block ) - { - FT_UNUSED( memory ); - - free( block ); - } - - - /*************************************************************************/ - /* */ - /* RESOURCE MANAGEMENT INTERFACE */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ - /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ - /* messages during execution. */ - /* */ -#undef FT_COMPONENT -#define FT_COMPONENT io - - /* We use the macro STREAM_FILE for convenience to extract the */ - /* system-specific stream handle from a given FreeType stream object */ -#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer ) - - - /*************************************************************************/ - /* */ - /* */ - /* ft_close_stream */ - /* */ - /* */ - /* The function to close a stream. */ - /* */ - /* */ - /* stream :: A pointer to the stream object. */ - /* */ - FT_CALLBACK_DEF( void ) - ft_close_stream( FT_Stream stream ) - { - munmap( (MUNMAP_ARG_CAST)stream->descriptor.pointer, stream->size ); - - stream->descriptor.pointer = NULL; - stream->size = 0; - stream->base = NULL; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Error ) - FT_Stream_Open( FT_Stream stream, - const char* filepathname ) - { - int file; - struct stat stat_buf; - - - if ( !stream ) - return FT_THROW( Invalid_Stream_Handle ); - - /* open the file */ - file = open( filepathname, O_RDONLY ); - if ( file < 0 ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not open `%s'\n", filepathname )); - return FT_THROW( Cannot_Open_Resource ); - } - - if ( fstat( file, &stat_buf ) < 0 ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not `fstat' file `%s'\n", filepathname )); - goto Fail_Map; - } - - stream->size = stat_buf.st_size; - if ( !stream->size ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " opened `%s' but zero-sized\n", filepathname )); - goto Fail_Map; - } - - stream->pos = 0; - stream->base = (unsigned char *)mmap( NULL, - stream->size, - PROT_READ, - MAP_FILE | MAP_PRIVATE, - file, - 0 ); - - if ( stream->base == MAP_FAILED ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not `mmap' file `%s'\n", filepathname )); - goto Fail_Map; - } - - close( file ); - - stream->descriptor.pointer = stream->base; - stream->pathname.pointer = (char*)filepathname; - - stream->close = ft_close_stream; - stream->read = NULL; - - FT_TRACE1(( "FT_Stream_Open:" )); - FT_TRACE1(( " opened `%s' (%d bytes) successfully\n", - filepathname, stream->size )); - - return FT_Err_Ok; - - Fail_Map: - close( file ); - - stream->base = NULL; - stream->size = 0; - stream->pos = 0; - - return FT_THROW( Cannot_Open_Stream ); - } - - -#ifdef FT_DEBUG_MEMORY - - extern FT_Int - ft_mem_debug_init( FT_Memory memory ); - - extern void - ft_mem_debug_done( FT_Memory memory ); - -#endif - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Memory ) - FT_New_Memory( void ) - { - FT_Memory memory; - - - memory = (FT_Memory)malloc( sizeof ( *memory ) ); - if ( memory ) - { - memory->user = NULL; - memory->alloc = ft_alloc; - memory->realloc = ft_realloc; - memory->free = ft_free; -#ifdef FT_DEBUG_MEMORY - ft_mem_debug_init( memory ); -#endif - } - - return memory; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( void ) - FT_Done_Memory( FT_Memory memory ) - { -#ifdef FT_DEBUG_MEMORY - ft_mem_debug_done( memory ); -#endif - memory->free( memory, memory ); - } - - -/* END */ diff --git a/freetype/builds/wince/ftdebug.c b/freetype/builds/wince/ftdebug.c deleted file mode 100644 index 6453f8d..0000000 --- a/freetype/builds/wince/ftdebug.c +++ /dev/null @@ -1,353 +0,0 @@ -/**************************************************************************** - * - * ftdebug.c - * - * Debugging and logging component for WinCE (body). - * - * Copyright (C) 1996-2023 by - * David Turner, Robert Wilhelm, and Werner Lemberg. - * - * This file is part of the FreeType project, and may only be used, - * modified, and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify, or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - */ - - - /************************************************************************** - * - * This component contains various macros and functions used to ease the - * debugging of the FreeType engine. Its main purpose is in assertion - * checking, tracing, and error detection. - * - * There are now three debugging modes: - * - * - trace mode - * - * Error and trace messages are sent to the log file (which can be the - * standard error output). - * - * - error mode - * - * Only error messages are generated. - * - * - release mode: - * - * No error message is sent or generated. The code is free from any - * debugging parts. - * - */ - - -#include -#include - - -#ifdef FT_DEBUG_LEVEL_ERROR - -#include -#include -#include - -#include - - - static void - OutputDebugStringEx( const char* str ) - { - static WCHAR buf[8192]; - - int sz = MultiByteToWideChar( CP_ACP, 0, str, -1, buf, - sizeof ( buf ) / sizeof ( *buf ) ); - - - if ( !sz ) - lstrcpyW( buf, L"OutputDebugStringEx: MultiByteToWideChar failed" ); - - OutputDebugStringW( buf ); - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Message( const char* fmt, - ... ) - { - static char buf[8192]; - va_list ap; - - - va_start( ap, fmt ); - vfprintf( stderr, fmt, ap ); - /* send the string to the debugger as well */ - vsprintf( buf, fmt, ap ); - OutputDebugStringEx( buf ); - va_end( ap ); - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Panic( const char* fmt, - ... ) - { - static char buf[8192]; - va_list ap; - - - va_start( ap, fmt ); - vsprintf( buf, fmt, ap ); - OutputDebugStringEx( buf ); - va_end( ap ); - - exit( EXIT_FAILURE ); - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( int ) - FT_Throw( FT_Error error, - int line, - const char* file ) - { -#if 0 - /* activating the code in this block makes FreeType very chatty */ - fprintf( stderr, - "%s:%d: error 0x%02x: %s\n", - file, - line, - error, - FT_Error_String( error ) ); -#else - FT_UNUSED( error ); - FT_UNUSED( line ); - FT_UNUSED( file ); -#endif - - return 0; - } - -#endif /* FT_DEBUG_LEVEL_ERROR */ - - -#ifdef FT_DEBUG_LEVEL_TRACE - - /* array of trace levels, initialized to 0; */ - /* this gets adjusted at run-time */ - static int ft_trace_levels_enabled[trace_count]; - - /* array of trace levels, always initialized to 0 */ - static int ft_trace_levels_disabled[trace_count]; - - /* a pointer to either `ft_trace_levels_enabled' */ - /* or `ft_trace_levels_disabled' */ - int* ft_trace_levels; - - /* define array of trace toggle names */ -#define FT_TRACE_DEF( x ) #x , - - static const char* ft_trace_toggles[trace_count + 1] = - { -#include - NULL - }; - -#undef FT_TRACE_DEF - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( FT_Int ) - FT_Trace_Get_Count( void ) - { - return trace_count; - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( const char * ) - FT_Trace_Get_Name( FT_Int idx ) - { - int max = FT_Trace_Get_Count(); - - - if ( idx < max ) - return ft_trace_toggles[idx]; - else - return NULL; - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Trace_Disable( void ) - { - ft_trace_levels = ft_trace_levels_disabled; - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Trace_Enable( void ) - { - ft_trace_levels = ft_trace_levels_enabled; - } - - - /************************************************************************** - * - * Initialize the tracing sub-system. This is done by retrieving the - * value of the `FT2_DEBUG' environment variable. It must be a list of - * toggles, separated by spaces, `;', or `,'. Example: - * - * export FT2_DEBUG="any:3 memory:7 stream:5" - * - * This requests that all levels be set to 3, except the trace level for - * the memory and stream components which are set to 7 and 5, - * respectively. - * - * See the file `include/freetype/internal/fttrace.h' for details of - * the available toggle names. - * - * The level must be between 0 and 7; 0 means quiet (except for serious - * runtime errors), and 7 means _very_ verbose. - */ - FT_BASE_DEF( void ) - ft_debug_init( void ) - { - /* Windows Mobile doesn't have environment API: */ - /* GetEnvironmentStrings, GetEnvironmentVariable, getenv. */ - /* */ - /* FIXME!!! How to set debug mode? */ - - /* const char* ft2_debug = getenv( "FT2_DEBUG" ); */ - - const char* ft2_debug = NULL; - - - if ( ft2_debug ) - { - const char* p = ft2_debug; - const char* q; - - - for ( ; *p; p++ ) - { - /* skip leading whitespace and separators */ - if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' ) - continue; - - /* read toggle name, followed by ':' */ - q = p; - while ( *p && *p != ':' ) - p++; - - if ( !*p ) - break; - - if ( *p == ':' && p > q ) - { - FT_Int n, i, len = (FT_Int)( p - q ); - FT_Int level = -1, found = -1; - - - for ( n = 0; n < trace_count; n++ ) - { - const char* toggle = ft_trace_toggles[n]; - - - for ( i = 0; i < len; i++ ) - { - if ( toggle[i] != q[i] ) - break; - } - - if ( i == len && toggle[i] == 0 ) - { - found = n; - break; - } - } - - /* read level */ - p++; - if ( *p ) - { - level = *p - '0'; - if ( level < 0 || level > 7 ) - level = -1; - } - - if ( found >= 0 && level >= 0 ) - { - if ( found == trace_any ) - { - /* special case for `any' */ - for ( n = 0; n < trace_count; n++ ) - ft_trace_levels_enabled[n] = level; - } - else - ft_trace_levels_enabled[found] = level; - } - } - } - } - - ft_trace_levels = ft_trace_levels_enabled; - } - - -#else /* !FT_DEBUG_LEVEL_TRACE */ - - - FT_BASE_DEF( void ) - ft_debug_init( void ) - { - /* nothing */ - } - - - FT_BASE_DEF( FT_Int ) - FT_Trace_Get_Count( void ) - { - return 0; - } - - - FT_BASE_DEF( const char * ) - FT_Trace_Get_Name( FT_Int idx ) - { - FT_UNUSED( idx ); - - return NULL; - } - - - FT_BASE_DEF( void ) - FT_Trace_Disable( void ) - { - /* nothing */ - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Trace_Enable( void ) - { - /* nothing */ - } - - -#endif /* !FT_DEBUG_LEVEL_TRACE */ - - -/* END */ diff --git a/freetype/builds/wince/vc2005-ce/freetype.vcproj b/freetype/builds/wince/vc2005-ce/freetype.vcproj deleted file mode 100644 index 238ffc6..0000000 --- a/freetype/builds/wince/vc2005-ce/freetype.vcproj +++ /dev/null @@ -1,878 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/freetype/builds/wince/vc2005-ce/index.html b/freetype/builds/wince/vc2005-ce/index.html deleted file mode 100644 index 8ea6cfd..0000000 --- a/freetype/builds/wince/vc2005-ce/index.html +++ /dev/null @@ -1,47 +0,0 @@ - -
- - FreeType 2 Project Files for VS.NET 2005 - (Pocket PC) - - - -

- FreeType 2 Project Files for VS.NET 2005 - (Pocket PC) -

- -

This directory contains project files for Visual C++, named -freetype.vcproj, and Visual Studio, called freetype.sln for -the following targets: - -

    -
  • PPC/SP 2003 (Pocket PC 2003)
  • -
  • PPC/SP WM5 (Windows Mobile 5)
  • -
  • PPC/SP WM6 (Windows Mobile 6)
  • -
- -It compiles the following libraries from the FreeType 2.13.2 sources:

- -
    -
    -    freetype.lib     - release build; single threaded
    -    freetype_D.lib   - debug build;   single threaded
    -    freetypeMT.lib   - release build; multi-threaded
    -    freetypeMT_D.lib - debug build;   multi-threaded
    -
- -

Be sure to extract the files with the Windows (CR+LF) line endings. ZIP -archives are already stored this way, so no further action is required. If -you use some .tar.*z archives, be sure to configure your extracting -tool to convert the line endings. For example, with WinZip, you should activate the TAR -file smart CR/LF Conversion option. Alternatively, you may consider -using the unix2dos or u2d utilities that are floating -around, which specifically deal with this particular problem. - -

Build directories are placed in the top-level objs -directory.

- - - diff --git a/freetype/builds/wince/vc2008-ce/freetype.vcproj b/freetype/builds/wince/vc2008-ce/freetype.vcproj deleted file mode 100644 index 8404684..0000000 --- a/freetype/builds/wince/vc2008-ce/freetype.vcproj +++ /dev/null @@ -1,3517 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/freetype/builds/wince/vc2008-ce/index.html b/freetype/builds/wince/vc2008-ce/index.html deleted file mode 100644 index a6e74f8..0000000 --- a/freetype/builds/wince/vc2008-ce/index.html +++ /dev/null @@ -1,47 +0,0 @@ - -
- - FreeType 2 Project Files for VS.NET 2008 - (Pocket PC) - - - -

- FreeType 2 Project Files for VS.NET 2008 - (Pocket PC) -

- -

This directory contains project files for Visual C++, named -freetype.dsp, and Visual Studio, called freetype.sln for -the following targets: - -

    -
  • PPC/SP 2003 (Pocket PC 2003)
  • -
  • PPC/SP WM5 (Windows Mobile 5)
  • -
  • PPC/SP WM6 (Windows Mobile 6)
  • -
- -It compiles the following libraries from the FreeType 2.13.2 sources:

- -
    -
    -    freetype.lib     - release build; single threaded
    -    freetype_D.lib   - debug build;   single threaded
    -    freetypeMT.lib   - release build; multi-threaded
    -    freetypeMT_D.lib - debug build;   multi-threaded
    -
- -

Be sure to extract the files with the Windows (CR+LF) line endings. ZIP -archives are already stored this way, so no further action is required. If -you use some .tar.*z archives, be sure to configure your extracting -tool to convert the line endings. For example, with WinZip, you should activate the TAR -file smart CR/LF Conversion option. Alternatively, you may consider -using the unix2dos or u2d utilities that are floating -around, which specifically deal with this particular problem. - -

Build directories are placed in the top-level objs -directory.

- - - diff --git a/freetype/builds/windows/.gitignore b/freetype/builds/windows/.gitignore deleted file mode 100644 index 41456a4..0000000 --- a/freetype/builds/windows/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# user-specific cache/settings files -*.opensdf -*.sdf -*.suo -*.user diff --git a/freetype/builds/windows/detect.mk b/freetype/builds/windows/detect.mk deleted file mode 100644 index d7908be..0000000 --- a/freetype/builds/windows/detect.mk +++ /dev/null @@ -1,202 +0,0 @@ -# -# FreeType 2 configuration file to detect a Win32 host platform. -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -.PHONY: setup - - -ifeq ($(PLATFORM),ansi) - - # Detecting Windows NT is easy, as the OS variable must be defined and - # contains `Windows_NT'. This also works with Windows 2000 and XP. - # - ifeq ($(OS),Windows_NT) - - PLATFORM := windows - - else - - # Detecting Windows 9X - - # We used to run the `ver' command to see if its output contains the - # word `Windows'. If this is true, we are running Windows 95 or later: - # - # ifdef COMSPEC - # # First, check if we have the COMSPEC environment variable, which - # # indicates we can use COMMAND.COM's internal commands - # is_windows := $(findstring Windows,$(strip $(shell ver))) - # endif - # - # Unfortunately, this also detects the case when one is running - # DOS 7.x (the MS-DOS version that lies below Windows) without actually - # launching the GUI. - # - # A better test is to check whether there are both the environment - # variables `winbootdir' and `windir'. The first indicates an - # underlying DOS 7.x, while the second is set only if windows is - # available. - # - # Note that on Windows NT, such an environment variable will not be seen - # from DOS-based tools like DJGPP's make; this is not actually a problem - # since NT is detected independently above. But do not try to be clever! - # - ifdef winbootdir - ifdef windir - - PLATFORM := windows - - endif - endif - - endif # test NT - -endif # test PLATFORM ansi - -ifeq ($(PLATFORM),windows) - - DELETE := del - CAT := type - SEP := $(BACKSLASH) - - # Setting COPY is a bit trickier. Plain COPY on NT will not work - # correctly, because it will uppercase 8.3 filenames, creating a - # `CONFIG.MK' file which isn't found later on by `make'. - # Since we do not want that, we need to force execution of CMD.EXE. - # Unfortunately, CMD.EXE is not available on Windows 9X. - # So we need to hack. - # - # Kudos to Eli Zaretskii (DJGPP guru) that helped debug it. - # Details are available in threads of the FreeType mailing list - # (2004-11-11), and then in the devel mailing list (2004-11-20 to -23). - # - ifeq ($(OS),Windows_NT) - COPY := >nul cmd.exe /c copy - else - COPY := >nul copy - endif # test NT - - - # gcc Makefile by default - CONFIG_FILE := w32-gcc.mk - ifeq ($(firstword $(CC)),cc) - CC := gcc - endif - - ifneq ($(findstring list,$(MAKECMDGOALS)),) # test for the "list" target - dump_target_list: - $(info ) - $(info $(PROJECT_TITLE) build system -- supported compilers) - $(info ) - $(info Several command-line compilers are supported on Win32:) - $(info ) - $(info $(empty) make setup gcc (with Mingw)) - $(info $(empty) make setup visualc Microsoft Visual C++) - $(info $(empty) make setup bcc32 Borland C/C++) - $(info $(empty) make setup lcc Win32-LCC) - $(info $(empty) make setup intelc Intel C/C++) - $(info ) - - setup: dump_target_list - .PHONY: dump_target_list list - else - setup: std_setup - endif - - # additionally, we provide hooks for various other compilers - # - ifneq ($(findstring visualc,$(MAKECMDGOALS)),) # Visual C/C++ - CONFIG_FILE := w32-vcc.mk - CC := cl - - .PHONY: visualc - visualc: setup - @cd . - endif - - ifneq ($(findstring intelc,$(MAKECMDGOALS)),) # Intel C/C++ - CONFIG_FILE := w32-intl.mk - CC := cl - - .PHONY: intelc - visualc: setup - @cd . - endif - - ifneq ($(findstring watcom,$(MAKECMDGOALS)),) # Watcom C/C++ - CONFIG_FILE := w32-wat.mk - CC := wcc386 - - .PHONY: watcom - watcom: setup - @cd . - endif - - ifneq ($(findstring visualage,$(MAKECMDGOALS)),) # Visual Age C++ - CONFIG_FILE := w32-icc.mk - CC := icc - - .PHONY: visualage - visualage: setup - @cd . - endif - - ifneq ($(findstring lcc,$(MAKECMDGOALS)),) # LCC-Win32 - CONFIG_FILE := w32-lcc.mk - CC := lcc - - .PHONY: lcc - lcc: setup - @cd . - endif - - ifneq ($(findstring mingw32,$(MAKECMDGOALS)),) # mingw32 - CONFIG_FILE := w32-mingw32.mk - CC := gcc - - .PHONY: mingw32 - mingw32: setup - @cd . - endif - - ifneq ($(findstring bcc32,$(MAKECMDGOALS)),) # Borland C++ - CONFIG_FILE := w32-bcc.mk - CC := bcc32 - - .PHONY: bcc32 - bcc32: setup - @cd . - endif - - ifneq ($(findstring devel-bcc,$(MAKECMDGOALS)),) # development target - CONFIG_FILE := w32-bccd.mk - CC := bcc32 - - .PHONY: devel-bcc - devel-bcc: setup - @cd . - endif - - ifneq ($(findstring devel-gcc,$(MAKECMDGOALS)),) # development target - CONFIG_FILE := w32-dev.mk - CC := gcc - - .PHONY: devel-gcc - devel-gcc: setup - @cd . - endif - -endif # test PLATFORM windows - - -# EOF diff --git a/freetype/builds/windows/ftdebug.c b/freetype/builds/windows/ftdebug.c deleted file mode 100644 index 360f8c7..0000000 --- a/freetype/builds/windows/ftdebug.c +++ /dev/null @@ -1,698 +0,0 @@ -/**************************************************************************** - * - * ftdebug.c - * - * Debugging and logging component for Win32 (body). - * - * Copyright (C) 1996-2023 by - * David Turner, Robert Wilhelm, and Werner Lemberg. - * - * This file is part of the FreeType project, and may only be used, - * modified, and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify, or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - */ - - - /************************************************************************** - * - * This component contains various macros and functions used to ease the - * debugging of the FreeType engine. Its main purpose is in assertion - * checking, tracing, and error detection. - * - * There are now three debugging modes: - * - * - trace mode - * - * Error and trace messages are sent to the log file (which can be the - * standard error output). - * - * - error mode - * - * Only error messages are generated. - * - * - release mode: - * - * No error message is sent or generated. The code is free from any - * debugging parts. - * - */ - - -#include -#include -#include -#include - - -#ifdef FT_DEBUG_LOGGING - - /************************************************************************** - * - * Variables used to control logging. - * - * 1. `ft_default_trace_level` stores the value of trace levels, which are - * provided to FreeType using the `FT2_DEBUG` environment variable. - * - * 2. `ft_fileptr` stores the `FILE*` handle. - * - * 3. `ft_component` is a string that holds the name of `FT_COMPONENT`. - * - * 4. The flag `ft_component_flag` prints the name of `FT_COMPONENT` along - * with the actual log message if set to true. - * - * 5. The flag `ft_timestamp_flag` prints time along with the actual log - * message if set to ture. - * - * 6. `ft_have_newline_char` is used to differentiate between a log - * message with and without a trailing newline character. - * - * 7. `ft_custom_trace_level` stores the custom trace level value, which - * is provided by the user at run-time. - * - * We use `static` to avoid 'unused variable' warnings. - * - */ - static const char* ft_default_trace_level = NULL; - static FILE* ft_fileptr = NULL; - static const char* ft_component = NULL; - static FT_Bool ft_component_flag = FALSE; - static FT_Bool ft_timestamp_flag = FALSE; - static FT_Bool ft_have_newline_char = TRUE; - static const char* ft_custom_trace_level = NULL; - - /* declared in ftdebug.h */ - - dlg_handler ft_default_log_handler = NULL; - FT_Custom_Log_Handler custom_output_handler = NULL; - -#endif /* FT_DEBUG_LOGGING */ - - -#ifdef FT_DEBUG_LEVEL_ERROR - -#define WIN32_LEAN_AND_MEAN -#include - - -#ifdef _WIN32_WCE - - FT_LOACAL_DEF( void ) - OutputDebugStringA( LPCSTR lpOutputString ) - { - int len; - LPWSTR lpOutputStringW; - - - /* allocate memory space for converted string */ - len = MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, - lpOutputString, -1, NULL, 0 ); - - lpOutputStringW = (LPWSTR)_alloca( len * sizeof ( WCHAR ) ); - - if ( !len || !lpOutputStringW ) - return; - - /* now it is safe to do the translation */ - MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, - lpOutputString, -1, lpOutputStringW, len ); - - OutputDebugStringW( lpOutputStringW ); - } - -#endif /* _WIN32_WCE */ - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Message( const char* fmt, - ... ) - { - va_list ap; - - - va_start( ap, fmt ); - vfprintf( stderr, fmt, ap ); -#if ( defined( _WIN32_WINNT ) && _WIN32_WINNT >= 0x0400 ) || \ - ( defined( _WIN32_WCE ) && _WIN32_WCE >= 0x0600 ) - if ( IsDebuggerPresent() ) - { - static char buf[1024]; - - - vsnprintf( buf, sizeof buf, fmt, ap ); - OutputDebugStringA( buf ); - } -#endif - va_end( ap ); - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Panic( const char* fmt, - ... ) - { - va_list ap; - - - va_start( ap, fmt ); - vfprintf( stderr, fmt, ap ); -#if ( defined( _WIN32_WINNT ) && _WIN32_WINNT >= 0x0400 ) || \ - ( defined( _WIN32_WCE ) && _WIN32_WCE >= 0x0600 ) - if ( IsDebuggerPresent() ) - { - static char buf[1024]; - - - vsnprintf( buf, sizeof buf, fmt, ap ); - OutputDebugStringA( buf ); - } -#endif - va_end( ap ); - - exit( EXIT_FAILURE ); - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( int ) - FT_Throw( FT_Error error, - int line, - const char* file ) - { -#if 0 - /* activating the code in this block makes FreeType very chatty */ - fprintf( stderr, - "%s:%d: error 0x%02x: %s\n", - file, - line, - error, - FT_Error_String( error ) ); -#else - FT_UNUSED( error ); - FT_UNUSED( line ); - FT_UNUSED( file ); -#endif - - return 0; - } - -#endif /* FT_DEBUG_LEVEL_ERROR */ - - -#ifdef FT_DEBUG_LEVEL_TRACE - - /* array of trace levels, initialized to 0; */ - /* this gets adjusted at run-time */ - static int ft_trace_levels_enabled[trace_count]; - - /* array of trace levels, always initialized to 0 */ - static int ft_trace_levels_disabled[trace_count]; - - /* a pointer to either `ft_trace_levels_enabled' */ - /* or `ft_trace_levels_disabled' */ - int* ft_trace_levels; - - /* define array of trace toggle names */ -#define FT_TRACE_DEF( x ) #x , - - static const char* ft_trace_toggles[trace_count + 1] = - { -#include - NULL - }; - -#undef FT_TRACE_DEF - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( FT_Int ) - FT_Trace_Get_Count( void ) - { - return trace_count; - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( const char * ) - FT_Trace_Get_Name( FT_Int idx ) - { - int max = FT_Trace_Get_Count(); - - - if ( idx < max ) - return ft_trace_toggles[idx]; - else - return NULL; - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Trace_Disable( void ) - { - ft_trace_levels = ft_trace_levels_disabled; - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Trace_Enable( void ) - { - ft_trace_levels = ft_trace_levels_enabled; - } - - - /************************************************************************** - * - * Initialize the tracing sub-system. This is done by retrieving the - * value of the `FT2_DEBUG' environment variable. It must be a list of - * toggles, separated by spaces, `;', or `,'. Example: - * - * export FT2_DEBUG="any:3 memory:7 stream:5" - * - * This requests that all levels be set to 3, except the trace level for - * the memory and stream components which are set to 7 and 5, - * respectively. - * - * See the file `include/freetype/internal/fttrace.h' for details of - * the available toggle names. - * - * The level must be between 0 and 7; 0 means quiet (except for serious - * runtime errors), and 7 means _very_ verbose. - */ - FT_BASE_DEF( void ) - ft_debug_init( void ) - { - const char* ft2_debug = NULL; - - -#ifdef FT_DEBUG_LOGGING - if ( ft_custom_trace_level != NULL ) - ft2_debug = ft_custom_trace_level; - else - ft2_debug = ft_default_trace_level; -#else - ft2_debug = ft_getenv( "FT2_DEBUG" ); -#endif - - if ( ft2_debug ) - { - const char* p = ft2_debug; - const char* q; - - - for ( ; *p; p++ ) - { - /* skip leading whitespace and separators */ - if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' ) - continue; - -#ifdef FT_DEBUG_LOGGING - - /* check extra arguments for logging */ - if ( *p == '-' ) - { - const char* r = ++p; - - - if ( *r == 'v' ) - { - const char* s = ++r; - - - ft_component_flag = TRUE; - - if ( *s == 't' ) - { - ft_timestamp_flag = TRUE; - p++; - } - - p++; - } - - else if ( *r == 't' ) - { - const char* s = ++r; - - - ft_timestamp_flag = TRUE; - - if ( *s == 'v' ) - { - ft_component_flag = TRUE; - p++; - } - - p++; - } - } - -#endif /* FT_DEBUG_LOGGING */ - - /* read toggle name, followed by ':' */ - q = p; - while ( *p && *p != ':' ) - p++; - - if ( !*p ) - break; - - if ( *p == ':' && p > q ) - { - FT_Int n, i, len = (FT_Int)( p - q ); - FT_Int level = -1, found = -1; - - - for ( n = 0; n < trace_count; n++ ) - { - const char* toggle = ft_trace_toggles[n]; - - - for ( i = 0; i < len; i++ ) - { - if ( toggle[i] != q[i] ) - break; - } - - if ( i == len && toggle[i] == 0 ) - { - found = n; - break; - } - } - - /* read level */ - p++; - if ( *p ) - { - level = *p - '0'; - if ( level < 0 || level > 7 ) - level = -1; - } - - if ( found >= 0 && level >= 0 ) - { - if ( found == trace_any ) - { - /* special case for `any' */ - for ( n = 0; n < trace_count; n++ ) - ft_trace_levels_enabled[n] = level; - } - else - ft_trace_levels_enabled[found] = level; - } - } - } - } - - ft_trace_levels = ft_trace_levels_enabled; - } - - -#else /* !FT_DEBUG_LEVEL_TRACE */ - - - FT_BASE_DEF( void ) - ft_debug_init( void ) - { - /* nothing */ - } - - - FT_BASE_DEF( FT_Int ) - FT_Trace_Get_Count( void ) - { - return 0; - } - - - FT_BASE_DEF( const char * ) - FT_Trace_Get_Name( FT_Int idx ) - { - FT_UNUSED( idx ); - - return NULL; - } - - - FT_BASE_DEF( void ) - FT_Trace_Disable( void ) - { - /* nothing */ - } - - - /* documentation is in ftdebug.h */ - - FT_BASE_DEF( void ) - FT_Trace_Enable( void ) - { - /* nothing */ - } - -#endif /* !FT_DEBUG_LEVEL_TRACE */ - - -#ifdef FT_DEBUG_LOGGING - - /************************************************************************** - * - * Initialize and de-initialize 'dlg' library. - * - */ - - FT_BASE_DEF( void ) - ft_logging_init( void ) - { - ft_default_log_handler = ft_log_handler; - ft_default_trace_level = ft_getenv( "FT2_DEBUG" ); - - if ( ft_getenv( "FT_LOGGING_FILE" ) ) - ft_fileptr = ft_fopen( ft_getenv( "FT_LOGGING_FILE" ), "w" ); - else - ft_fileptr = stderr; - - ft_debug_init(); - - /* Set the default output handler for 'dlg'. */ - dlg_set_handler( ft_default_log_handler, NULL ); - } - - - FT_BASE_DEF( void ) - ft_logging_deinit( void ) - { - if ( ft_fileptr != stderr ) - ft_fclose( ft_fileptr ); - } - - - /************************************************************************** - * - * An output log handler for FreeType. - * - */ - FT_BASE_DEF( void ) - ft_log_handler( const struct dlg_origin* origin, - const char* string, - void* data ) - { - char features_buf[128]; - char* bufp = features_buf; - - FT_UNUSED( data ); - - - if ( ft_have_newline_char ) - { - const char* features = NULL; - size_t features_length = 0; - - -#define FEATURES_TIMESTAMP "[%h:%m] " -#define FEATURES_COMPONENT "[%t] " -#define FEATURES_TIMESTAMP_COMPONENT "[%h:%m %t] " - - if ( ft_timestamp_flag && ft_component_flag ) - { - features = FEATURES_TIMESTAMP_COMPONENT; - features_length = sizeof ( FEATURES_TIMESTAMP_COMPONENT ); - } - else if ( ft_timestamp_flag ) - { - features = FEATURES_TIMESTAMP; - features_length = sizeof ( FEATURES_TIMESTAMP ); - } - else if ( ft_component_flag ) - { - features = FEATURES_COMPONENT; - features_length = sizeof ( FEATURES_COMPONENT ); - } - - if ( ft_component_flag || ft_timestamp_flag ) - { - ft_strncpy( features_buf, features, features_length ); - bufp += features_length - 1; - } - - if ( ft_component_flag ) - { - size_t tag_length = ft_strlen( *origin->tags ); - size_t i; - - - /* To vertically align tracing messages we compensate the */ - /* different FT_COMPONENT string lengths by inserting an */ - /* appropriate amount of space characters. */ - for ( i = 0; - i < FT_MAX_TRACE_LEVEL_LENGTH - tag_length; - i++ ) - *bufp++ = ' '; - } - } - - /* Finally add the format string for the tracing message. */ - *bufp++ = '%'; - *bufp++ = 'c'; - *bufp = '\0'; - - dlg_generic_outputf_stream( ft_fileptr, - (const char*)features_buf, - origin, - string, - dlg_default_output_styles, - true ); - - if ( ft_strrchr( string, '\n' ) ) - ft_have_newline_char = TRUE; - else - ft_have_newline_char = FALSE; - } - - - /* documentation is in ftdebug.h */ - FT_BASE_DEF( void ) - ft_add_tag( const char* tag ) - { - ft_component = tag; - - dlg_add_tag( tag, NULL ); - } - - - /* documentation is in ftdebug.h */ - FT_BASE_DEF( void ) - ft_remove_tag( const char* tag ) - { - dlg_remove_tag( tag, NULL ); - } - - - /* documentation is in ftlogging.h */ - - FT_EXPORT_DEF( void ) - FT_Trace_Set_Level( const char* level ) - { - ft_component_flag = FALSE; - ft_timestamp_flag = FALSE; - ft_custom_trace_level = level; - - ft_debug_init(); - } - - - /* documentation is in ftlogging.h */ - - FT_EXPORT_DEF( void ) - FT_Trace_Set_Default_Level( void ) - { - ft_component_flag = FALSE; - ft_timestamp_flag = FALSE; - ft_custom_trace_level = NULL; - - ft_debug_init(); - } - - - /************************************************************************** - * - * Functions to handle a custom log handler. - * - */ - - /* documentation is in ftlogging.h */ - - FT_EXPORT_DEF( void ) - FT_Set_Log_Handler( FT_Custom_Log_Handler handler ) - { - custom_output_handler = handler; - } - - - /* documentation is in ftlogging.h */ - - FT_EXPORT_DEF( void ) - FT_Set_Default_Log_Handler( void ) - { - custom_output_handler = NULL; - } - - - /* documentation is in ftdebug.h */ - FT_BASE_DEF( void ) - FT_Logging_Callback( const char* fmt, - ... ) - { - va_list ap; - - - va_start( ap, fmt ); - custom_output_handler( ft_component, fmt, ap ); - va_end( ap ); - } - -#else /* !FT_DEBUG_LOGGING */ - - FT_EXPORT_DEF( void ) - FT_Trace_Set_Level( const char* level ) - { - FT_UNUSED( level ); - } - - - FT_EXPORT_DEF( void ) - FT_Trace_Set_Default_Level( void ) - { - /* nothing */ - } - - - FT_EXPORT_DEF( void ) - FT_Set_Log_Handler( FT_Custom_Log_Handler handler ) - { - FT_UNUSED( handler ); - } - - - FT_EXPORT_DEF( void ) - FT_Set_Default_Log_Handler( void ) - { - /* nothing */ - } - -#endif /* !FT_DEBUG_LOGGING */ - - -/* END */ diff --git a/freetype/builds/windows/ftsystem.c b/freetype/builds/windows/ftsystem.c deleted file mode 100644 index 418d799..0000000 --- a/freetype/builds/windows/ftsystem.c +++ /dev/null @@ -1,499 +0,0 @@ -/**************************************************************************** - * - * ftsystem.c - * - * Windows-specific FreeType low-level system interface (body). - * - * Copyright (C) 2021-2023 by - * David Turner, Robert Wilhelm, and Werner Lemberg. - * - * This file is part of the FreeType project, and may only be used, - * modified, and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify, or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - */ - - -#include - /* we use our special ftconfig.h file, not the standard one */ -#include FT_CONFIG_CONFIG_H -#include -#include -#include -#include -#include - - /* memory mapping and allocation includes and definitions */ -#define WIN32_LEAN_AND_MEAN -#include - - - /************************************************************************** - * - * MEMORY MANAGEMENT INTERFACE - * - */ - - - /************************************************************************** - * - * It is not necessary to do any error checking for the - * allocation-related functions. This will be done by the higher level - * routines like ft_mem_alloc() or ft_mem_realloc(). - * - */ - - - /************************************************************************** - * - * @Function: - * ft_alloc - * - * @Description: - * The memory allocation function. - * - * @Input: - * memory :: - * A pointer to the memory object. - * - * size :: - * The requested size in bytes. - * - * @Return: - * The address of newly allocated block. - */ - FT_CALLBACK_DEF( void* ) - ft_alloc( FT_Memory memory, - long size ) - { - return HeapAlloc( memory->user, 0, size ); - } - - - /************************************************************************** - * - * @Function: - * ft_realloc - * - * @Description: - * The memory reallocation function. - * - * @Input: - * memory :: - * A pointer to the memory object. - * - * cur_size :: - * The current size of the allocated memory block. - * - * new_size :: - * The newly requested size in bytes. - * - * block :: - * The current address of the block in memory. - * - * @Return: - * The address of the reallocated memory block. - */ - FT_CALLBACK_DEF( void* ) - ft_realloc( FT_Memory memory, - long cur_size, - long new_size, - void* block ) - { - FT_UNUSED( cur_size ); - - return HeapReAlloc( memory->user, 0, block, new_size ); - } - - - /************************************************************************** - * - * @Function: - * ft_free - * - * @Description: - * The memory release function. - * - * @Input: - * memory :: - * A pointer to the memory object. - * - * block :: - * The address of block in memory to be freed. - */ - FT_CALLBACK_DEF( void ) - ft_free( FT_Memory memory, - void* block ) - { - HeapFree( memory->user, 0, block ); - } - - - /************************************************************************** - * - * RESOURCE MANAGEMENT INTERFACE - * - */ - - - /************************************************************************** - * - * The macro FT_COMPONENT is used in trace mode. It is an implicit - * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log - * messages during execution. - */ -#undef FT_COMPONENT -#define FT_COMPONENT io - - /* We use the macro STREAM_FILE for convenience to extract the */ - /* system-specific stream handle from a given FreeType stream object */ -#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer ) - - - /************************************************************************** - * - * @Function: - * ft_close_stream_by_munmap - * - * @Description: - * The function to close a stream which is opened by mmap. - * - * @Input: - * stream :: A pointer to the stream object. - */ - FT_CALLBACK_DEF( void ) - ft_close_stream_by_munmap( FT_Stream stream ) - { - UnmapViewOfFile( (LPCVOID)stream->descriptor.pointer ); - - stream->descriptor.pointer = NULL; - stream->size = 0; - stream->base = NULL; - } - - - /************************************************************************** - * - * @Function: - * ft_close_stream_by_free - * - * @Description: - * The function to close a stream which is created by ft_alloc. - * - * @Input: - * stream :: A pointer to the stream object. - */ - FT_CALLBACK_DEF( void ) - ft_close_stream_by_free( FT_Stream stream ) - { - ft_free( stream->memory, stream->descriptor.pointer ); - - stream->descriptor.pointer = NULL; - stream->size = 0; - stream->base = NULL; - } - - - /* non-desktop Universal Windows Platform */ -#if defined( WINAPI_FAMILY ) && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP - -#define PACK_DWORD64( hi, lo ) ( ( (DWORD64)(hi) << 32 ) | (DWORD)(lo) ) - -#define CreateFileMapping( a, b, c, d, e, f ) \ - CreateFileMappingFromApp( a, b, c, PACK_DWORD64( d, e ), f ) -#define MapViewOfFile( a, b, c, d, e ) \ - MapViewOfFileFromApp( a, b, PACK_DWORD64( c, d ), e ) - - FT_LOCAL_DEF( HANDLE ) - CreateFileA( LPCSTR lpFileName, - DWORD dwDesiredAccess, - DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, - HANDLE hTemplateFile ) - { - int len; - LPWSTR lpFileNameW; - - CREATEFILE2_EXTENDED_PARAMETERS createExParams = { - sizeof ( CREATEFILE2_EXTENDED_PARAMETERS ), - dwFlagsAndAttributes & 0x0000FFFF, - dwFlagsAndAttributes & 0xFFF00000, - dwFlagsAndAttributes & 0x000F0000, - lpSecurityAttributes, - hTemplateFile }; - - - /* allocate memory space for converted path name */ - len = MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, - lpFileName, -1, NULL, 0 ); - - lpFileNameW = (LPWSTR)_alloca( len * sizeof ( WCHAR ) ); - - if ( !len || !lpFileNameW ) - { - FT_ERROR(( "FT_Stream_Open: cannot convert file name to LPWSTR\n" )); - return INVALID_HANDLE_VALUE; - } - - /* now it is safe to do the translation */ - MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, - lpFileName, -1, lpFileNameW, len ); - - /* open the file */ - return CreateFile2( lpFileNameW, dwDesiredAccess, dwShareMode, - dwCreationDisposition, &createExParams ); - } - -#endif - - -#if defined( _WIN32_WCE ) - - /* malloc.h provides implementation of alloca()/_alloca() */ - #include - - FT_LOCAL_DEF( HANDLE ) - CreateFileA( LPCSTR lpFileName, - DWORD dwDesiredAccess, - DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, - HANDLE hTemplateFile ) - { - int len; - LPWSTR lpFileNameW; - - - /* allocate memory space for converted path name */ - len = MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, - lpFileName, -1, NULL, 0 ); - - lpFileNameW = (LPWSTR)_alloca( len * sizeof ( WCHAR ) ); - - if ( !len || !lpFileNameW ) - { - FT_ERROR(( "FT_Stream_Open: cannot convert file name to LPWSTR\n" )); - return INVALID_HANDLE_VALUE; - } - - /* now it is safe to do the translation */ - MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, - lpFileName, -1, lpFileNameW, len ); - - /* open the file */ - return CreateFileW( lpFileNameW, dwDesiredAccess, dwShareMode, - lpSecurityAttributes, dwCreationDisposition, - dwFlagsAndAttributes, hTemplateFile ); - } - -#endif - - -#if defined( _WIN32_WCE ) || defined ( _WIN32_WINDOWS ) || \ - !defined( _WIN32_WINNT ) || _WIN32_WINNT <= 0x0400 - - FT_LOCAL_DEF( BOOL ) - GetFileSizeEx( HANDLE hFile, - PLARGE_INTEGER lpFileSize ) - { - lpFileSize->u.LowPart = GetFileSize( hFile, - (DWORD *)&lpFileSize->u.HighPart ); - - if ( lpFileSize->u.LowPart == INVALID_FILE_SIZE && - GetLastError() != NO_ERROR ) - return FALSE; - else - return TRUE; - } - -#endif - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Error ) - FT_Stream_Open( FT_Stream stream, - const char* filepathname ) - { - HANDLE file; - HANDLE fm; - LARGE_INTEGER size; - - - if ( !stream ) - return FT_THROW( Invalid_Stream_Handle ); - - /* open the file */ - file = CreateFileA( (LPCSTR)filepathname, GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); - if ( file == INVALID_HANDLE_VALUE ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not open `%s'\n", filepathname )); - return FT_THROW( Cannot_Open_Resource ); - } - - if ( GetFileSizeEx( file, &size ) == FALSE ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not retrieve size of file `%s'\n", filepathname )); - goto Fail_Open; - } - - /* `stream->size' is typedef'd to unsigned long (in `ftsystem.h'); */ - /* So avoid overflow caused by fonts in huge files larger than */ - /* 2GB, do a test. */ - if ( size.QuadPart > LONG_MAX ) - { - FT_ERROR(( "FT_Stream_Open: file is too big\n" )); - goto Fail_Open; - } - else if ( size.QuadPart == 0 ) - { - FT_ERROR(( "FT_Stream_Open: zero-length file\n" )); - goto Fail_Open; - } - - fm = CreateFileMapping( file, NULL, PAGE_READONLY, 0, 0, NULL ); - if ( fm == NULL ) - { - FT_ERROR(( "FT_Stream_Open: can not map file\n" )); - goto Fail_Open; - } - - /* Store only the low part of this 64 bits integer because long is */ - /* a 32 bits type. Anyway, a check has been done above to forbid */ - /* a size greater than LONG_MAX */ - stream->size = size.LowPart; - stream->pos = 0; - stream->base = (unsigned char *) - MapViewOfFile( fm, FILE_MAP_READ, 0, 0, 0 ); - - CloseHandle( fm ); - - if ( stream->base != NULL ) - stream->close = ft_close_stream_by_munmap; - else - { - DWORD total_read_count; - - - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not `mmap' file `%s'\n", filepathname )); - - stream->base = (unsigned char*)ft_alloc( stream->memory, stream->size ); - - if ( !stream->base ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " could not `alloc' memory\n" )); - goto Fail_Open; - } - - total_read_count = 0; - do - { - DWORD read_count; - - - if ( ReadFile( file, - stream->base + total_read_count, - stream->size - total_read_count, - &read_count, NULL ) == FALSE ) - { - FT_ERROR(( "FT_Stream_Open:" )); - FT_ERROR(( " error while `read'ing file `%s'\n", filepathname )); - goto Fail_Read; - } - - total_read_count += read_count; - - } while ( total_read_count != stream->size ); - - stream->close = ft_close_stream_by_free; - } - - CloseHandle( file ); - - stream->descriptor.pointer = stream->base; - stream->pathname.pointer = (char*)filepathname; - - stream->read = NULL; - - FT_TRACE1(( "FT_Stream_Open:" )); - FT_TRACE1(( " opened `%s' (%ld bytes) successfully\n", - filepathname, stream->size )); - - return FT_Err_Ok; - - Fail_Read: - ft_free( stream->memory, stream->base ); - - Fail_Open: - CloseHandle( file ); - - stream->base = NULL; - stream->size = 0; - stream->pos = 0; - - return FT_THROW( Cannot_Open_Stream ); - } - - -#ifdef FT_DEBUG_MEMORY - - extern FT_Int - ft_mem_debug_init( FT_Memory memory ); - - extern void - ft_mem_debug_done( FT_Memory memory ); - -#endif - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( FT_Memory ) - FT_New_Memory( void ) - { - HANDLE heap; - FT_Memory memory; - - - heap = GetProcessHeap(); - memory = heap ? (FT_Memory)HeapAlloc( heap, 0, sizeof ( *memory ) ) - : NULL; - - if ( memory ) - { - memory->user = heap; - memory->alloc = ft_alloc; - memory->realloc = ft_realloc; - memory->free = ft_free; -#ifdef FT_DEBUG_MEMORY - ft_mem_debug_init( memory ); -#endif - } - - return memory; - } - - - /* documentation is in ftobjs.h */ - - FT_BASE_DEF( void ) - FT_Done_Memory( FT_Memory memory ) - { -#ifdef FT_DEBUG_MEMORY - ft_mem_debug_done( memory ); -#endif - memory->free( memory, memory ); - } - - -/* END */ diff --git a/freetype/builds/windows/vc2010/freetype.user.props b/freetype/builds/windows/vc2010/freetype.user.props deleted file mode 100644 index 78310d4..0000000 --- a/freetype/builds/windows/vc2010/freetype.user.props +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/freetype/builds/windows/vc2010/index.html b/freetype/builds/windows/vc2010/index.html deleted file mode 100644 index ee9b59a..0000000 --- a/freetype/builds/windows/vc2010/index.html +++ /dev/null @@ -1,40 +0,0 @@ - -
- - FreeType 2 Project Files for Visual C++ 2010 or newer - - - -

- FreeType 2 Project Files for Visual C++ 2010 or newer -

- -

This directory contains solution and project files for -Visual C++ 2010 or newer, named freetype.sln, -and freetype.vcxproj. It compiles the following libraries -from the FreeType 2.13.2 sources:

- -
    -
  • freetype.dll using 'Release' or 'Debug' configurations
  • -
  • freetype.lib using 'Release Static' or 'Debug Static' configurations
  • -
- -

Both Win32 and x64 builds are supported. Build directories and target -files are placed in the top-level objs directory.

- -

Customization of the FreeType library is done by editing the -ftoption.h header file in the top-level devel path. -Alternatively, you may copy the file to another directory and change the -include directory in freetype.users.props.

- -

To configure library dependencies like zlib and libpng, -edit the freetype.users.props file in this directory. It also -simplifies automated (command-line) builds using msbuild.

- -

To link your executable with FreeType DLL, you may want to define -DLL_IMPORT so that the imported functions are appropriately -attributed with dllimport.

- - - diff --git a/freetype/builds/windows/visualc/freetype.dsp b/freetype/builds/windows/visualc/freetype.dsp deleted file mode 100644 index 451fab2..0000000 --- a/freetype/builds/windows/visualc/freetype.dsp +++ /dev/null @@ -1,354 +0,0 @@ -# Microsoft Developer Studio Project File - Name="freetype" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=freetype - Win32 Release -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "freetype.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "freetype.mak" CFG="freetype - Win32 Release" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "freetype - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "freetype - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "freetype - Win32 Release Static" (based on "Win32 (x86) Static Library") -!MESSAGE "freetype - Win32 Debug Static" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" - -!IF "$(CFG)" == "freetype - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\..\objs\Win32\Release" -# PROP Intermediate_Dir "..\..\..\objs\Win32\Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -CPP=cl.exe -# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c -# SUBTRACT BASE CPP /YX /Yc /Yu -# ADD CPP /nologo /Za /MD /W3 /O2 /Oi /D "WIN32" /I "..\..\..\include" /D "_CRT_SECURE_NO_WARNINGS" /D "NDEBUG" /D "FT2_BUILD_LIBRARY" /D "DLL_EXPORT" /FD /c -# SUBTRACT CPP /YX /Yc /Yu -MTL=midl.exe -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -RSC=rc.exe -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" /d "DLL_EXPORT" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 /nologo /dll /machine:I386 /opt:REF,ICF /out:"$(OutDir)\freetype.dll" - -!ELSEIF "$(CFG)" == "freetype - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\..\objs\Win32\Debug" -# PROP Intermediate_Dir "..\..\..\objs\Win32\Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -CPP=cl.exe -# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c -# SUBTRACT BASE CPP /YX /Yc /Yu -# ADD CPP /nologo /Za /MDd /W3 /Gm /ZI /Od /I "..\..\..\include" /D "WIN32" /D "_CRT_SECURE_NO_WARNINGS" /D "_DEBUG" /D "FT_DEBUG_LEVEL_ERROR" /D "FT_DEBUG_LEVEL_TRACE" /D "FT2_BUILD_LIBRARY" /D "DLL_EXPORT" /FR /FD /GZ /c -# SUBTRACT CPP /YX /Yc /Yu -MTL=midl.exe -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -RSC=rc.exe -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" /d "DLL_EXPORT" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 /nologo /dll /debug /machine:I386 /out:"$(OutDir)\freetype.dll" /pdbtype:sept - -!ELSEIF "$(CFG)" == "freetype - Win32 Release Static" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release Static" -# PROP BASE Intermediate_Dir "Release Static" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\..\objs\Win32\Release Static" -# PROP Intermediate_Dir "..\..\..\objs\Win32\Release Static" -# PROP Target_Dir "" -CPP=cl.exe -# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /FD /c -# SUBTRACT BASE CPP /YX /Yc /Yu -# ADD CPP /nologo /Za /MD /W3 /O2 /Oi /D "WIN32" /I "..\..\..\include" /D "_CRT_SECURE_NO_WARNINGS" /D "NDEBUG" /D "FT2_BUILD_LIBRARY" /FD /c -# SUBTRACT CPP /YX /Yc /Yu -RSC=rc.exe -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"$(OutDir)\freetype.lib" - -!ELSEIF "$(CFG)" == "freetype - Win32 Debug Static" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug Static" -# PROP BASE Intermediate_Dir "Debug Static" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\..\objs\Win32\Debug Static" -# PROP Intermediate_Dir "..\..\..\objs\Win32\Debug Static" -# PROP Target_Dir "" -CPP=cl.exe -# ADD BASE CPP /nologo /MDd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /FD /GZ /c -# SUBTRACT BASE CPP /YX /Yc /Yu -# ADD CPP /nologo /Za /MDd /W3 /Gm /ZI /Od /I "..\..\..\include" /D "WIN32" /D "_CRT_SECURE_NO_WARNINGS" /D "_DEBUG" /D "FT_DEBUG_LEVEL_ERROR" /D "FT_DEBUG_LEVEL_TRACE" /D "FT2_BUILD_LIBRARY" /FR /FD /GZ /c -# SUBTRACT CPP /YX /Yc /Yu -RSC=rc.exe -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"$(OutDir)\freetype.lib" - -!ENDIF - -# Begin Target - -# Name "freetype - Win32 Release" -# Name "freetype - Win32 Debug" -# Name "freetype - Win32 Release Static" -# Name "freetype - Win32 Debug Static" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\..\..\src\autofit\autofit.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\bdf\bdf.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\cff\cff.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftbase.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftbbox.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftbdf.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftbitmap.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftcid.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftpatent.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftfstype.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftgasp.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\cache\ftcache.c -# End Source File -# Begin Source File - -SOURCE=..\ftdebug.c -# ADD CPP /Ze -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftglyph.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftgxval.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\gzip\ftgzip.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftinit.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\lzw\ftlzw.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftmm.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftotval.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftpfr.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftstroke.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftsynth.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftsystem.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\fttype1.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftwinfnt.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\pcf\pcf.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\pfr\pfr.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\psaux\psaux.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\pshinter\pshinter.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\psnames\psmodule.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\raster\raster.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\sfnt\sfnt.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\smooth\smooth.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\truetype\truetype.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\type1\type1.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\cid\type1cid.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\type42\type42.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\winfonts\winfnt.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=..\..\..\include\ft2build.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\include\freetype\config\ftconfig.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\include\freetype\config\ftheader.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\include\freetype\config\ftmodule.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\include\freetype\config\ftoption.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\include\freetype\config\ftstdlib.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" -# Begin Source File - -SOURCE=..\..\..\src\base\ftver.rc -# End Source File -# End Group -# End Target -# End Project diff --git a/freetype/builds/windows/visualc/freetype.dsw b/freetype/builds/windows/visualc/freetype.dsw deleted file mode 100644 index b1b375d..0000000 --- a/freetype/builds/windows/visualc/freetype.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "freetype"=.\freetype.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/freetype/builds/windows/visualc/freetype.vcproj b/freetype/builds/windows/visualc/freetype.vcproj deleted file mode 100644 index 85c5f1c..0000000 --- a/freetype/builds/windows/visualc/freetype.vcproj +++ /dev/null @@ -1,587 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/freetype/builds/windows/visualc/index.html b/freetype/builds/windows/visualc/index.html deleted file mode 100644 index 816605e..0000000 --- a/freetype/builds/windows/visualc/index.html +++ /dev/null @@ -1,38 +0,0 @@ - -
- - FreeType 2 Project Files for Visual C++ 6.0 and 2002-2008 - - - -

- FreeType 2 Project Files for Visual C++ 6.0 and 2002-2008 -

- -

This directory contains project files freetype.dsp for -Visual C++ 6.0, and freetype.vcproj for Visual C++ 2002 -through 2008, which you might need to upgrade automatically. -It compiles the following libraries from the FreeType 2.13.2 sources:

- -
    -
  • freetype.dll using 'Release' or 'Debug' configurations
  • -
  • freetype.lib using 'Release Static' or 'Debug Static' configurations
  • -
- -

Build directories and target files are placed in the top-level -objs directory.

- -

Be sure to extract the files with the Windows (CR+LF) line endings. ZIP -archives are already stored this way, so no further action is required. If -you use some .tar.*z archives, be sure to configure your extracting -tool to convert the line endings. For example, with WinZip, you should activate the TAR -file smart CR/LF Conversion option. Alternatively, you may consider -using the unix2dos or u2d utilities that are floating -around, which specifically deal with this particular problem. - -

Build directories are placed in the top-level objs -directory.

- - - diff --git a/freetype/builds/windows/visualce/freetype.dsp b/freetype/builds/windows/visualce/freetype.dsp deleted file mode 100644 index 11d59f9..0000000 --- a/freetype/builds/windows/visualce/freetype.dsp +++ /dev/null @@ -1,391 +0,0 @@ -# Microsoft Developer Studio Project File - Name="freetype" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=freetype - Win32 Debug Singlethreaded -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "freetype.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "freetype.mak" CFG="freetype - Win32 Debug Singlethreaded" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "freetype - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "freetype - Win32 Debug" (based on "Win32 (x86) Static Library") -!MESSAGE "freetype - Win32 Debug Multithreaded" (based on "Win32 (x86) Static Library") -!MESSAGE "freetype - Win32 Release Multithreaded" (based on "Win32 (x86) Static Library") -!MESSAGE "freetype - Win32 Release Singlethreaded" (based on "Win32 (x86) Static Library") -!MESSAGE "freetype - Win32 Debug Singlethreaded" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "freetype - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\..\objs\release" -# PROP Intermediate_Dir "..\..\..\objs\release" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /MD /Za /W4 /GX /O2 /I "..\..\..\include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FT2_BUILD_LIBRARY" /FD /c -# SUBTRACT CPP /nologo /Z /YX -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"..\..\..\objs\freetype.lib" - -!ELSEIF "$(CFG)" == "freetype - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\..\objs\debug" -# PROP Intermediate_Dir "..\..\..\objs\debug" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /MDd /Za /W4 /GX /Z7 /Od /I "..\..\..\include" /D "_DEBUG" /D "FT_DEBUG_LEVEL_ERROR" /D "FT_DEBUG_LEVEL_TRACE" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FT2_BUILD_LIBRARY" /FD /GZ /c -# SUBTRACT CPP /nologo /X /YX -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"..\..\..\objs\freetype_D.lib" - -!ELSEIF "$(CFG)" == "freetype - Win32 Debug Multithreaded" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "freetype___Win32_Debug_Multithreaded" -# PROP BASE Intermediate_Dir "freetype___Win32_Debug_Multithreaded" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\..\objs\debug_mt" -# PROP Intermediate_Dir "..\..\..\objs\debug_mt" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /Za /W3 /Gm /GX /ZI /Od /I "..\include\\" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FT_FLAT_COMPILE" /YX /FD /GZ /c -# SUBTRACT BASE CPP /X -# ADD CPP /MTd /Za /W4 /GX /Z7 /Od /I "..\..\..\include" /D "_DEBUG" /D "FT_DEBUG_LEVEL_ERROR" /D "FT_DEBUG_LEVEL_TRACE" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FT2_BUILD_LIBRARY" /FD /GZ /c -# SUBTRACT CPP /nologo /X /YX -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo /out:"lib\freetype_D.lib" -# ADD LIB32 /nologo /out:"..\..\..\objs\freetypeMT_D.lib" - -!ELSEIF "$(CFG)" == "freetype - Win32 Release Multithreaded" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "freetype___Win32_Release_Multithreaded" -# PROP BASE Intermediate_Dir "freetype___Win32_Release_Multithreaded" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\..\objs\release_mt" -# PROP Intermediate_Dir "..\..\..\objs\release_mt" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /Za /W3 /GX /O2 /I "..\include\\" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FT_FLAT_COMPILE" /YX /FD /c -# ADD CPP /MT /Za /W4 /GX /O2 /I "..\..\..\include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FT2_BUILD_LIBRARY" /FD /c -# SUBTRACT CPP /nologo /Z /YX -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo /out:"lib\freetype.lib" -# ADD LIB32 /nologo /out:"..\..\..\objs\freetypeMT.lib" - -!ELSEIF "$(CFG)" == "freetype - Win32 Release Singlethreaded" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "freetype___Win32_Release_Singlethreaded" -# PROP BASE Intermediate_Dir "freetype___Win32_Release_Singlethreaded" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\..\objs\release_st" -# PROP Intermediate_Dir "..\..\..\objs\release_st" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MD /Za /W4 /GX /Zi /O2 /I "..\..\..\include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /FD /c -# SUBTRACT BASE CPP /YX -# ADD CPP /Za /W4 /GX /O2 /I "..\..\..\include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FT2_BUILD_LIBRARY" /FD /c -# SUBTRACT CPP /nologo /Z /YX -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo /out:"..\..\..\objs\freetype.lib" -# ADD LIB32 /out:"..\..\..\objs\freetypeST.lib" -# SUBTRACT LIB32 /nologo - -!ELSEIF "$(CFG)" == "freetype - Win32 Debug Singlethreaded" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "freetype___Win32_Debug_Singlethreaded" -# PROP BASE Intermediate_Dir "freetype___Win32_Debug_Singlethreaded" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\..\objs\debug_st" -# PROP Intermediate_Dir "..\..\..\objs\debug_st" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MDd /Za /W4 /Gm /GX /Zi /Od /I "..\..\..\include" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FT_DEBUG_LEVEL_ERROR" /D "FT_DEBUG_LEVEL_TRACE" /FD /GZ /c -# SUBTRACT BASE CPP /X /YX -# ADD CPP /Za /W4 /GX /Z7 /Od /I "..\..\..\include" /D "_DEBUG" /D "FT_DEBUG_LEVEL_ERROR" /D "FT_DEBUG_LEVEL_TRACE" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FT2_BUILD_LIBRARY" /FD /GZ /c -# SUBTRACT CPP /nologo /X /YX -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo /out:"..\..\..\objs\freetype_D.lib" -# ADD LIB32 /nologo /out:"..\..\..\objs\freetypeST_D.lib" - -!ENDIF - -# Begin Target - -# Name "freetype - Win32 Release" -# Name "freetype - Win32 Debug" -# Name "freetype - Win32 Debug Multithreaded" -# Name "freetype - Win32 Release Multithreaded" -# Name "freetype - Win32 Release Singlethreaded" -# Name "freetype - Win32 Debug Singlethreaded" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\..\..\src\autofit\autofit.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\bdf\bdf.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\cff\cff.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftbase.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftbbox.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftbdf.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftbitmap.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftcid.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftfstype.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftgasp.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\cache\ftcache.c -# End Source File -# Begin Source File - -SOURCE=..\ftdebug.c -# ADD CPP /Ze -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftglyph.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftgxval.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\gzip\ftgzip.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftinit.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\lzw\ftlzw.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftmm.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftotval.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftpatent.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftpfr.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftstroke.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftsynth.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftsystem.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\fttype1.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\base\ftwinfnt.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\pcf\pcf.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\pfr\pfr.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\psaux\psaux.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\pshinter\pshinter.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\psnames\psmodule.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\raster\raster.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\sfnt\sfnt.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\smooth\smooth.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\truetype\truetype.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\type1\type1.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\cid\type1cid.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\type42\type42.c -# End Source File -# Begin Source File - -SOURCE=..\..\..\src\winfonts\winfnt.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=..\..\..\include\ft2build.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\include\freetype\config\ftconfig.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\include\freetype\config\ftheader.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\include\freetype\config\ftmodule.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\include\freetype\config\ftoption.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\include\freetype\config\ftstdlib.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" -# Begin Source File - -SOURCE=..\..\..\src\base\ftver.rc -# End Source File -# End Group -# End Target -# End Project diff --git a/freetype/builds/windows/visualce/freetype.dsw b/freetype/builds/windows/visualce/freetype.dsw deleted file mode 100644 index b1b375d..0000000 --- a/freetype/builds/windows/visualce/freetype.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "freetype"=.\freetype.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/freetype/builds/windows/visualce/freetype.vcproj b/freetype/builds/windows/visualce/freetype.vcproj deleted file mode 100644 index f0f74c7..0000000 --- a/freetype/builds/windows/visualce/freetype.vcproj +++ /dev/null @@ -1,3706 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/freetype/builds/windows/visualce/index.html b/freetype/builds/windows/visualce/index.html deleted file mode 100644 index d9c8fe4..0000000 --- a/freetype/builds/windows/visualce/index.html +++ /dev/null @@ -1,47 +0,0 @@ - -
- - FreeType 2 Project Files for Visual C++ and VS.NET 2005 - (Pocket PC) - - - -

- FreeType 2 Project Files for Visual C++ and VS.NET 2005 - (Pocket PC) -

- -

This directory contains project files for Visual C++, named -freetype.dsp, and Visual Studio, called freetype.sln for -the following targets: - -

    -
  • PPC/SP 2003 (Pocket PC 2003)
  • -
  • PPC/SP WM5 (Windows Mobile 5)
  • -
  • PPC/SP WM6 (Windows Mobile 6)
  • -
- -It compiles the following libraries from the FreeType 2.13.2 sources:

- -
    -
    -    freetype.lib     - release build; single threaded
    -    freetype_D.lib   - debug build;   single threaded
    -    freetypeMT.lib   - release build; multi-threaded
    -    freetypeMT_D.lib - debug build;   multi-threaded
    -
- -

Be sure to extract the files with the Windows (CR+LF) line endings. ZIP -archives are already stored this way, so no further action is required. If -you use some .tar.*z archives, be sure to configure your extracting -tool to convert the line endings. For example, with WinZip, you should activate the TAR -file smart CR/LF Conversion option. Alternatively, you may consider -using the unix2dos or u2d utilities that are floating -around, which specifically deal with this particular problem. - -

Build directories are placed in the top-level objs -directory.

- - - diff --git a/freetype/builds/windows/w32-bcc.mk b/freetype/builds/windows/w32-bcc.mk deleted file mode 100644 index e7cf668..0000000 --- a/freetype/builds/windows/w32-bcc.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -# FreeType 2 Borland C++ on Win32 -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# default definitions of the export list -# -EXPORTS_LIST = $(OBJ_DIR)/freetype.def -EXPORTS_OPTIONS = /DEF:$(EXPORTS_LIST) -APINAMES_OPTIONS := -dfreetype.dll -wB - -include $(TOP_DIR)/builds/windows/win32-def.mk -include $(TOP_DIR)/builds/compiler/bcc.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/windows/w32-bccd.mk b/freetype/builds/windows/w32-bccd.mk deleted file mode 100644 index 64dafdb..0000000 --- a/freetype/builds/windows/w32-bccd.mk +++ /dev/null @@ -1,26 +0,0 @@ -# -# FreeType 2 Borland C++ on Win32 + debugging -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -DEVEL_DIR := $(TOP_DIR)/devel - -include $(TOP_DIR)/builds/windows/win32-def.mk - -include $(TOP_DIR)/builds/compiler/bcc-dev.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/windows/w32-dev.mk b/freetype/builds/windows/w32-dev.mk deleted file mode 100644 index 7c89ad2..0000000 --- a/freetype/builds/windows/w32-dev.mk +++ /dev/null @@ -1,32 +0,0 @@ -# -# FreeType 2 configuration rules for Win32 + GCC -# -# Development version without optimizations. -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -# NOTE: This version requires that GNU Make is invoked from the Windows -# Shell (_not_ Cygwin BASH)! -# - -DEVEL_DIR := $(TOP_DIR)/devel - -include $(TOP_DIR)/builds/windows/win32-def.mk - -include $(TOP_DIR)/builds/compiler/gcc-dev.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/windows/w32-gcc.mk b/freetype/builds/windows/w32-gcc.mk deleted file mode 100644 index f37c185..0000000 --- a/freetype/builds/windows/w32-gcc.mk +++ /dev/null @@ -1,31 +0,0 @@ -# -# FreeType 2 configuration rules for Win32 + GCC -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# default definitions of the export list -# -EXPORTS_LIST = $(OBJ_DIR)/freetype.def -EXPORTS_OPTIONS = $(EXPORTS_LIST) -APINAMES_OPTIONS := -dfreetype.dll -w - -# include Win32-specific definitions -include $(TOP_DIR)/builds/windows/win32-def.mk - -# include gcc-specific definitions -include $(TOP_DIR)/builds/compiler/gcc.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/windows/w32-icc.mk b/freetype/builds/windows/w32-icc.mk deleted file mode 100644 index cf51cce..0000000 --- a/freetype/builds/windows/w32-icc.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -# FreeType 2 configuration rules for Win32 + IBM Visual Age C++ -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# default definitions of the export list -# -EXPORTS_LIST = $(OBJ_DIR)/freetype.def -EXPORTS_OPTIONS = /DEF:$(EXPORTS_LIST) -APINAMES_OPTIONS := -dfreetype.dll -w - -include $(TOP_DIR)/builds/windows/win32-def.mk -include $(TOP_DIR)/builds/compiler/visualage.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/windows/w32-intl.mk b/freetype/builds/windows/w32-intl.mk deleted file mode 100644 index 0c16b4c..0000000 --- a/freetype/builds/windows/w32-intl.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -# FreeType 2 configuration rules for Intel C/C++ on Win32 -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# default definitions of the export list -# -EXPORTS_LIST = $(OBJ_DIR)/freetype.def -EXPORTS_OPTIONS = /DEF:$(EXPORTS_LIST) -APINAMES_OPTIONS := -dfreetype.dll -w - -include $(TOP_DIR)/builds/windows/win32-def.mk -include $(TOP_DIR)/builds/compiler/intelc.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/windows/w32-lcc.mk b/freetype/builds/windows/w32-lcc.mk deleted file mode 100644 index 0dd740e..0000000 --- a/freetype/builds/windows/w32-lcc.mk +++ /dev/null @@ -1,24 +0,0 @@ -# -# FreeType 2 configuration rules for Win32 + LCC -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -SEP := / -include $(TOP_DIR)/builds/windows/win32-def.mk -include $(TOP_DIR)/builds/compiler/win-lcc.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - -# EOF - diff --git a/freetype/builds/windows/w32-mingw32.mk b/freetype/builds/windows/w32-mingw32.mk deleted file mode 100644 index dc323bd..0000000 --- a/freetype/builds/windows/w32-mingw32.mk +++ /dev/null @@ -1,33 +0,0 @@ -# -# FreeType 2 configuration rules for mingw32 -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# default definitions of the export list -# -EXPORTS_LIST = $(OBJ_DIR)/freetype.def -EXPORTS_OPTIONS = $(EXPORTS_LIST) -APINAMES_OPTIONS := -dfreetype.dll -w - -# include Win32-specific definitions -include $(TOP_DIR)/builds/windows/win32-def.mk - -LIBRARY := lib$(PROJECT) - -# include gcc-specific definitions -include $(TOP_DIR)/builds/compiler/gcc.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/windows/w32-vcc.mk b/freetype/builds/windows/w32-vcc.mk deleted file mode 100644 index eea7db8..0000000 --- a/freetype/builds/windows/w32-vcc.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -# FreeType 2 Visual C++ on Win32 -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# definitions of the export list -# -EXPORTS_LIST = $(OBJ_DIR)/freetype.def -EXPORTS_OPTIONS = /DEF:$(EXPORTS_LIST) -APINAMES_OPTIONS := -dfreetype.dll -w - -include $(TOP_DIR)/builds/windows/win32-def.mk -include $(TOP_DIR)/builds/compiler/visualc.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/windows/w32-wat.mk b/freetype/builds/windows/w32-wat.mk deleted file mode 100644 index 5392d2a..0000000 --- a/freetype/builds/windows/w32-wat.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -# FreeType 2 configuration rules for Watcom C/C++ -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - -# redefine export symbol definitions -# -EXPORTS_LIST = $(OBJ_DIR)/watcom-ftexports.lbc -EXPORTS_OPTIONS = -\"export @$(EXPORTS_LIST)\"- -APINAMES_OPTIONS := -wW - -include $(TOP_DIR)/builds/windows/win32-def.mk -include $(TOP_DIR)/builds/compiler/watcom.mk - -# include linking instructions -include $(TOP_DIR)/builds/link_dos.mk - - -# EOF diff --git a/freetype/builds/windows/win32-def.mk b/freetype/builds/windows/win32-def.mk deleted file mode 100644 index 3242651..0000000 --- a/freetype/builds/windows/win32-def.mk +++ /dev/null @@ -1,51 +0,0 @@ -# -# FreeType 2 Win32 specific definitions -# - - -# Copyright (C) 1996-2023 by -# David Turner, Robert Wilhelm, and Werner Lemberg. -# -# This file is part of the FreeType project, and may only be used, modified, -# and distributed under the terms of the FreeType project license, -# LICENSE.TXT. By continuing to use, modify, or distribute this file you -# indicate that you have read the license and understand and accept it -# fully. - - -DELETE := del -CAT := type -SEP := $(strip \ ) -PLATFORM_DIR := $(TOP_DIR)/builds/windows -PLATFORM := windows - -# This is used for `make refdoc' and `make refdoc-venv' -# -BIN := Scripts - -# The executable file extension (for tools). NOTE: WE INCLUDE THE DOT HERE !! -# -E := .exe -E_BUILD := .exe - - -# The directory where all library files are placed. -# -# By default, this is the same as $(OBJ_DIR); however, this can be changed -# to suit particular needs. -# -LIB_DIR := $(OBJ_DIR) - - -# The name of the final library file. Note that the DOS-specific Makefile -# uses a shorter (8.3) name. -# -LIBRARY := $(PROJECT) - - -# The NO_OUTPUT macro is used to ignore the output of commands. -# -NO_OUTPUT = 2> nul - - -# EOF diff --git a/freetype/devel/ft2build.h b/freetype/devel/ft2build.h deleted file mode 100644 index 82fdb30..0000000 --- a/freetype/devel/ft2build.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * - * ft2build.h - * - * FreeType 2 build and setup macros (development version). - * - * Copyright (C) 1996-2023 by - * David Turner, Robert Wilhelm, and Werner Lemberg. - * - * This file is part of the FreeType project, and may only be used, - * modified, and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify, or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - */ - - - /* - * This is a development version of to build the library in - * debug mode. Its only difference to the default version is that it - * includes a local `ftoption.h' header file with different settings for - * many configuration macros. - * - * To use it, simply ensure that the directory containing this file is - * scanned by the compiler before the default FreeType header directory. - * - */ - -#ifndef FT2BUILD_H_ -#define FT2BUILD_H_ - -#define FT_CONFIG_MODULES_H -#define FT_CONFIG_OPTIONS_H - -#include - -#endif /* FT2BUILD_H_ */ - - -/* END */ diff --git a/freetype/devel/ftoption.h b/freetype/devel/ftoption.h deleted file mode 100644 index da56abc..0000000 --- a/freetype/devel/ftoption.h +++ /dev/null @@ -1,1014 +0,0 @@ -/**************************************************************************** - * - * ftoption.h (for development) - * - * User-selectable configuration macros (specification only). - * - * Copyright (C) 1996-2023 by - * David Turner, Robert Wilhelm, and Werner Lemberg. - * - * This file is part of the FreeType project, and may only be used, - * modified, and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify, or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - */ - - -#ifndef FTOPTION_H_ -#define FTOPTION_H_ - - -#include - - -FT_BEGIN_HEADER - - /************************************************************************** - * - * USER-SELECTABLE CONFIGURATION MACROS - * - * This file contains the default configuration macro definitions for a - * standard build of the FreeType library. There are three ways to use - * this file to build project-specific versions of the library: - * - * - You can modify this file by hand, but this is not recommended in - * cases where you would like to build several versions of the library - * from a single source directory. - * - * - You can put a copy of this file in your build directory, more - * precisely in `$BUILD/freetype/config/ftoption.h`, where `$BUILD` is - * the name of a directory that is included _before_ the FreeType include - * path during compilation. - * - * The default FreeType Makefiles use the build directory - * `builds/` by default, but you can easily change that for your - * own projects. - * - * - Copy the file to `$BUILD/ft2build.h` and modify it - * slightly to pre-define the macro `FT_CONFIG_OPTIONS_H` used to locate - * this file during the build. For example, - * - * ``` - * #define FT_CONFIG_OPTIONS_H - * #include - * ``` - * - * will use `$BUILD/myftoptions.h` instead of this file for macro - * definitions. - * - * Note also that you can similarly pre-define the macro - * `FT_CONFIG_MODULES_H` used to locate the file listing of the modules - * that are statically linked to the library at compile time. By - * default, this file is ``. - * - * We highly recommend using the third method whenever possible. - * - */ - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** G E N E R A L F R E E T Y P E 2 C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /*#************************************************************************ - * - * If you enable this configuration option, FreeType recognizes an - * environment variable called `FREETYPE_PROPERTIES`, which can be used to - * control the various font drivers and modules. The controllable - * properties are listed in the section @properties. - * - * You have to undefine this configuration option on platforms that lack - * the concept of environment variables (and thus don't have the `getenv` - * function), for example Windows CE. - * - * `FREETYPE_PROPERTIES` has the following syntax form (broken here into - * multiple lines for better readability). - * - * ``` - * - * ':' - * '=' - * - * ':' - * '=' - * ... - * ``` - * - * Example: - * - * ``` - * FREETYPE_PROPERTIES=truetype:interpreter-version=35 \ - * cff:no-stem-darkening=1 - * ``` - * - */ -#define FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES - - - /************************************************************************** - * - * Uncomment the line below if you want to activate LCD rendering - * technology similar to ClearType in this build of the library. This - * technology triples the resolution in the direction color subpixels. To - * mitigate color fringes inherent to this technology, you also need to - * explicitly set up LCD filtering. - * - * When this macro is not defined, FreeType offers alternative LCD - * rendering technology that produces excellent output. - */ -/* #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ - - - /************************************************************************** - * - * Many compilers provide a non-ANSI 64-bit data type that can be used by - * FreeType to speed up some computations. However, this will create some - * problems when compiling the library in strict ANSI mode. - * - * For this reason, the use of 64-bit integers is normally disabled when - * the `__STDC__` macro is defined. You can however disable this by - * defining the macro `FT_CONFIG_OPTION_FORCE_INT64` here. - * - * For most compilers, this will only create compilation warnings when - * building the library. - * - * ObNote: The compiler-specific 64-bit integers are detected in the - * file `ftconfig.h` either statically or through the `configure` - * script on supported platforms. - */ -#undef FT_CONFIG_OPTION_FORCE_INT64 - - - /************************************************************************** - * - * If this macro is defined, do not try to use an assembler version of - * performance-critical functions (e.g., @FT_MulFix). You should only do - * that to verify that the assembler function works properly, or to execute - * benchmark tests of the various implementations. - */ -/* #define FT_CONFIG_OPTION_NO_ASSEMBLER */ - - - /************************************************************************** - * - * If this macro is defined, try to use an inlined assembler version of the - * @FT_MulFix function, which is a 'hotspot' when loading and hinting - * glyphs, and which should be executed as fast as possible. - * - * Note that if your compiler or CPU is not supported, this will default to - * the standard and portable implementation found in `ftcalc.c`. - */ -#define FT_CONFIG_OPTION_INLINE_MULFIX - - - /************************************************************************** - * - * LZW-compressed file support. - * - * FreeType now handles font files that have been compressed with the - * `compress` program. This is mostly used to parse many of the PCF - * files that come with various X11 distributions. The implementation - * uses NetBSD's `zopen` to partially uncompress the file on the fly (see - * `src/lzw/ftgzip.c`). - * - * Define this macro if you want to enable this 'feature'. - */ -#define FT_CONFIG_OPTION_USE_LZW - - - /************************************************************************** - * - * Gzip-compressed file support. - * - * FreeType now handles font files that have been compressed with the - * `gzip` program. This is mostly used to parse many of the PCF files - * that come with XFree86. The implementation uses 'zlib' to partially - * uncompress the file on the fly (see `src/gzip/ftgzip.c`). - * - * Define this macro if you want to enable this 'feature'. See also the - * macro `FT_CONFIG_OPTION_SYSTEM_ZLIB` below. - */ -#define FT_CONFIG_OPTION_USE_ZLIB - - - /************************************************************************** - * - * ZLib library selection - * - * This macro is only used when `FT_CONFIG_OPTION_USE_ZLIB` is defined. - * It allows FreeType's 'ftgzip' component to link to the system's - * installation of the ZLib library. This is useful on systems like - * Unix or VMS where it generally is already available. - * - * If you let it undefined, the component will use its own copy of the - * zlib sources instead. These have been modified to be included - * directly within the component and **not** export external function - * names. This allows you to link any program with FreeType _and_ ZLib - * without linking conflicts. - * - * Do not `#undef` this macro here since the build system might define - * it for certain configurations only. - * - * If you use a build system like cmake or the `configure` script, - * options set by those programs have precedence, overwriting the value - * here with the configured one. - * - * If you use the GNU make build system directly (that is, without the - * `configure` script) and you define this macro, you also have to pass - * `SYSTEM_ZLIB=yes` as an argument to make. - */ -/* #define FT_CONFIG_OPTION_SYSTEM_ZLIB */ - - - /************************************************************************** - * - * Bzip2-compressed file support. - * - * FreeType now handles font files that have been compressed with the - * `bzip2` program. This is mostly used to parse many of the PCF files - * that come with XFree86. The implementation uses `libbz2` to partially - * uncompress the file on the fly (see `src/bzip2/ftbzip2.c`). Contrary - * to gzip, bzip2 currently is not included and need to use the system - * available bzip2 implementation. - * - * Define this macro if you want to enable this 'feature'. - * - * If you use a build system like cmake or the `configure` script, - * options set by those programs have precedence, overwriting the value - * here with the configured one. - */ -#define FT_CONFIG_OPTION_USE_BZIP2 - - - /************************************************************************** - * - * Define to disable the use of file stream functions and types, `FILE`, - * `fopen`, etc. Enables the use of smaller system libraries on embedded - * systems that have multiple system libraries, some with or without file - * stream support, in the cases where file stream support is not necessary - * such as memory loading of font files. - */ -/* #define FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT */ - - - /************************************************************************** - * - * PNG bitmap support. - * - * FreeType now handles loading color bitmap glyphs in the PNG format. - * This requires help from the external libpng library. Uncompressed - * color bitmaps do not need any external libraries and will be supported - * regardless of this configuration. - * - * Define this macro if you want to enable this 'feature'. - * - * If you use a build system like cmake or the `configure` script, - * options set by those programs have precedence, overwriting the value - * here with the configured one. - */ -#define FT_CONFIG_OPTION_USE_PNG - - - /************************************************************************** - * - * HarfBuzz support. - * - * FreeType uses the HarfBuzz library to improve auto-hinting of OpenType - * fonts. If available, many glyphs not directly addressable by a font's - * character map will be hinted also. - * - * Define this macro if you want to enable this 'feature'. - * - * If you use a build system like cmake or the `configure` script, - * options set by those programs have precedence, overwriting the value - * here with the configured one. - */ -#define FT_CONFIG_OPTION_USE_HARFBUZZ - - - /************************************************************************** - * - * Brotli support. - * - * FreeType uses the Brotli library to provide support for decompressing - * WOFF2 streams. - * - * Define this macro if you want to enable this 'feature'. - * - * If you use a build system like cmake or the `configure` script, - * options set by those programs have precedence, overwriting the value - * here with the configured one. - */ -#define FT_CONFIG_OPTION_USE_BROTLI - - - /************************************************************************** - * - * Glyph Postscript Names handling - * - * By default, FreeType 2 is compiled with the 'psnames' module. This - * module is in charge of converting a glyph name string into a Unicode - * value, or return a Macintosh standard glyph name for the use with the - * TrueType 'post' table. - * - * Undefine this macro if you do not want 'psnames' compiled in your - * build of FreeType. This has the following effects: - * - * - The TrueType driver will provide its own set of glyph names, if you - * build it to support postscript names in the TrueType 'post' table, - * but will not synthesize a missing Unicode charmap. - * - * - The Type~1 driver will not be able to synthesize a Unicode charmap - * out of the glyphs found in the fonts. - * - * You would normally undefine this configuration macro when building a - * version of FreeType that doesn't contain a Type~1 or CFF driver. - */ -#define FT_CONFIG_OPTION_POSTSCRIPT_NAMES - - - /************************************************************************** - * - * Postscript Names to Unicode Values support - * - * By default, FreeType~2 is built with the 'psnames' module compiled in. - * Among other things, the module is used to convert a glyph name into a - * Unicode value. This is especially useful in order to synthesize on - * the fly a Unicode charmap from the CFF/Type~1 driver through a big - * table named the 'Adobe Glyph List' (AGL). - * - * Undefine this macro if you do not want the Adobe Glyph List compiled - * in your 'psnames' module. The Type~1 driver will not be able to - * synthesize a Unicode charmap out of the glyphs found in the fonts. - */ -#define FT_CONFIG_OPTION_ADOBE_GLYPH_LIST - - - /************************************************************************** - * - * Support for Mac fonts - * - * Define this macro if you want support for outline fonts in Mac format - * (mac dfont, mac resource, macbinary containing a mac resource) on - * non-Mac platforms. - * - * Note that the 'FOND' resource isn't checked. - */ -#define FT_CONFIG_OPTION_MAC_FONTS - - - /************************************************************************** - * - * Guessing methods to access embedded resource forks - * - * Enable extra Mac fonts support on non-Mac platforms (e.g., GNU/Linux). - * - * Resource forks which include fonts data are stored sometimes in - * locations which users or developers don't expected. In some cases, - * resource forks start with some offset from the head of a file. In - * other cases, the actual resource fork is stored in file different from - * what the user specifies. If this option is activated, FreeType tries - * to guess whether such offsets or different file names must be used. - * - * Note that normal, direct access of resource forks is controlled via - * the `FT_CONFIG_OPTION_MAC_FONTS` option. - */ -#ifdef FT_CONFIG_OPTION_MAC_FONTS -#define FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK -#endif - - - /************************************************************************** - * - * Allow the use of `FT_Incremental_Interface` to load typefaces that - * contain no glyph data, but supply it via a callback function. This is - * required by clients supporting document formats which supply font data - * incrementally as the document is parsed, such as the Ghostscript - * interpreter for the PostScript language. - */ -#define FT_CONFIG_OPTION_INCREMENTAL - - - /************************************************************************** - * - * The size in bytes of the render pool used by the scan-line converter to - * do all of its work. - */ -#define FT_RENDER_POOL_SIZE 16384L - - - /************************************************************************** - * - * FT_MAX_MODULES - * - * The maximum number of modules that can be registered in a single - * FreeType library object. 32~is the default. - */ -#define FT_MAX_MODULES 32 - - - /************************************************************************** - * - * Debug level - * - * FreeType can be compiled in debug or trace mode. In debug mode, - * errors are reported through the 'ftdebug' component. In trace mode, - * additional messages are sent to the standard output during execution. - * - * Define `FT_DEBUG_LEVEL_ERROR` to build the library in debug mode. - * Define `FT_DEBUG_LEVEL_TRACE` to build it in trace mode. - * - * Don't define any of these macros to compile in 'release' mode! - * - * Do not `#undef` these macros here since the build system might define - * them for certain configurations only. - */ -#define FT_DEBUG_LEVEL_ERROR -#define FT_DEBUG_LEVEL_TRACE - - - /************************************************************************** - * - * Logging - * - * Compiling FreeType in debug or trace mode makes FreeType write error - * and trace log messages to `stderr`. Enabling this macro - * automatically forces the `FT_DEBUG_LEVEL_ERROR` and - * `FT_DEBUG_LEVEL_TRACE` macros and allows FreeType to write error and - * trace log messages to a file instead of `stderr`. For writing logs - * to a file, FreeType uses an the external `dlg` library (the source - * code is in `src/dlg`). - * - * This option needs a C99 compiler. - */ -#define FT_DEBUG_LOGGING - - - /************************************************************************** - * - * Autofitter debugging - * - * If `FT_DEBUG_AUTOFIT` is defined, FreeType provides some means to - * control the autofitter behaviour for debugging purposes with global - * boolean variables (consequently, you should **never** enable this - * while compiling in 'release' mode): - * - * ``` - * af_debug_disable_horz_hints_ - * af_debug_disable_vert_hints_ - * af_debug_disable_blue_hints_ - * ``` - * - * Additionally, the following functions provide dumps of various - * internal autofit structures to stdout (using `printf`): - * - * ``` - * af_glyph_hints_dump_points - * af_glyph_hints_dump_segments - * af_glyph_hints_dump_edges - * af_glyph_hints_get_num_segments - * af_glyph_hints_get_segment_offset - * ``` - * - * As an argument, they use another global variable: - * - * ``` - * af_debug_hints_ - * ``` - * - * Please have a look at the `ftgrid` demo program to see how those - * variables and macros should be used. - * - * Do not `#undef` these macros here since the build system might define - * them for certain configurations only. - */ -#define FT_DEBUG_AUTOFIT - - - /************************************************************************** - * - * Memory Debugging - * - * FreeType now comes with an integrated memory debugger that is capable - * of detecting simple errors like memory leaks or double deletes. To - * compile it within your build of the library, you should define - * `FT_DEBUG_MEMORY` here. - * - * Note that the memory debugger is only activated at runtime when when - * the _environment_ variable `FT2_DEBUG_MEMORY` is defined also! - * - * Do not `#undef` this macro here since the build system might define it - * for certain configurations only. - */ -#define FT_DEBUG_MEMORY - - - /************************************************************************** - * - * Module errors - * - * If this macro is set (which is _not_ the default), the higher byte of - * an error code gives the module in which the error has occurred, while - * the lower byte is the real error code. - * - * Setting this macro makes sense for debugging purposes only, since it - * would break source compatibility of certain programs that use - * FreeType~2. - * - * More details can be found in the files `ftmoderr.h` and `fterrors.h`. - */ -#undef FT_CONFIG_OPTION_USE_MODULE_ERRORS - - - /************************************************************************** - * - * OpenType SVG Glyph Support - * - * Setting this macro enables support for OpenType SVG glyphs. By - * default, FreeType can only fetch SVG documents. However, it can also - * render them if external rendering hook functions are plugged in at - * runtime. - * - * More details on the hooks can be found in file `otsvg.h`. - */ -#define FT_CONFIG_OPTION_SVG - - - /************************************************************************** - * - * Error Strings - * - * If this macro is set, `FT_Error_String` will return meaningful - * descriptions. This is not enabled by default to reduce the overall - * size of FreeType. - * - * More details can be found in the file `fterrors.h`. - */ -/* #define FT_CONFIG_OPTION_ERROR_STRINGS */ - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** S F N T D R I V E R C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_EMBEDDED_BITMAPS` if you want to support - * embedded bitmaps in all formats using the 'sfnt' module (namely - * TrueType~& OpenType). - */ -#define TT_CONFIG_OPTION_EMBEDDED_BITMAPS - - - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_COLOR_LAYERS` if you want to support colored - * outlines (from the 'COLR'/'CPAL' tables) in all formats using the 'sfnt' - * module (namely TrueType~& OpenType). - */ -#define TT_CONFIG_OPTION_COLOR_LAYERS - - - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_POSTSCRIPT_NAMES` if you want to be able to - * load and enumerate Postscript names of glyphs in a TrueType or OpenType - * file. - * - * Note that if you do not compile the 'psnames' module by undefining the - * above `FT_CONFIG_OPTION_POSTSCRIPT_NAMES` macro, the 'sfnt' module will - * contain additional code to read the PostScript name table from a font. - * - * (By default, the module uses 'psnames' to extract glyph names.) - */ -#define TT_CONFIG_OPTION_POSTSCRIPT_NAMES - - - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_SFNT_NAMES` if your applications need to access - * the internal name table in a SFNT-based format like TrueType or - * OpenType. The name table contains various strings used to describe the - * font, like family name, copyright, version, etc. It does not contain - * any glyph name though. - * - * Accessing SFNT names is done through the functions declared in - * `ftsnames.h`. - */ -#define TT_CONFIG_OPTION_SFNT_NAMES - - - /************************************************************************** - * - * TrueType CMap support - * - * Here you can fine-tune which TrueType CMap table format shall be - * supported. - */ -#define TT_CONFIG_CMAP_FORMAT_0 -#define TT_CONFIG_CMAP_FORMAT_2 -#define TT_CONFIG_CMAP_FORMAT_4 -#define TT_CONFIG_CMAP_FORMAT_6 -#define TT_CONFIG_CMAP_FORMAT_8 -#define TT_CONFIG_CMAP_FORMAT_10 -#define TT_CONFIG_CMAP_FORMAT_12 -#define TT_CONFIG_CMAP_FORMAT_13 -#define TT_CONFIG_CMAP_FORMAT_14 - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** T R U E T Y P E D R I V E R C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_BYTECODE_INTERPRETER` if you want to compile a - * bytecode interpreter in the TrueType driver. - * - * By undefining this, you will only compile the code necessary to load - * TrueType glyphs without hinting. - * - * Do not `#undef` this macro here, since the build system might define it - * for certain configurations only. - */ -#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER - - - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_SUBPIXEL_HINTING` if you want to compile - * subpixel hinting support into the TrueType driver. This modifies the - * TrueType hinting mechanism when anything but `FT_RENDER_MODE_MONO` is - * requested. - * - * In particular, it modifies the bytecode interpreter to interpret (or - * not) instructions in a certain way so that all TrueType fonts look like - * they do in a Windows ClearType (DirectWrite) environment. See [1] for a - * technical overview on what this means. See `ttinterp.h` for more - * details on this option. - * - * The new default mode focuses on applying a minimal set of rules to all - * fonts indiscriminately so that modern and web fonts render well while - * legacy fonts render okay. The corresponding interpreter version is v40. - * The so-called Infinality mode (v38) is no longer available in FreeType. - * - * By undefining these, you get rendering behavior like on Windows without - * ClearType, i.e., Windows XP without ClearType enabled and Win9x - * (interpreter version v35). Or not, depending on how much hinting blood - * and testing tears the font designer put into a given font. If you - * define one or both subpixel hinting options, you can switch between - * between v35 and the ones you define (using `FT_Property_Set`). - * - * This option requires `TT_CONFIG_OPTION_BYTECODE_INTERPRETER` to be - * defined. - * - * [1] - * https://www.microsoft.com/typography/cleartype/truetypecleartype.aspx - */ -#define TT_CONFIG_OPTION_SUBPIXEL_HINTING - - - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED` to compile the - * TrueType glyph loader to use Apple's definition of how to handle - * component offsets in composite glyphs. - * - * Apple and MS disagree on the default behavior of component offsets in - * composites. Apple says that they should be scaled by the scaling - * factors in the transformation matrix (roughly, it's more complex) while - * MS says they should not. OpenType defines two bits in the composite - * flags array which can be used to disambiguate, but old fonts will not - * have them. - * - * https://www.microsoft.com/typography/otspec/glyf.htm - * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html - */ -#undef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED - - - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_GX_VAR_SUPPORT` if you want to include support - * for Apple's distortable font technology ('fvar', 'gvar', 'cvar', and - * 'avar' tables). Tagged 'Font Variations', this is now part of OpenType - * also. This has many similarities to Type~1 Multiple Masters support. - */ -#define TT_CONFIG_OPTION_GX_VAR_SUPPORT - - - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_NO_BORING_EXPANSION` if you want to exclude - * support for 'boring' OpenType specification expansions. - * - * https://github.com/harfbuzz/boring-expansion-spec - * - * Right now, the following features are covered: - * - * - 'avar' version 2.0 - * - * Most likely, this is a temporary configuration option to be removed in - * the near future, since it is assumed that eventually those features are - * added to the OpenType standard. - */ -/* #define TT_CONFIG_OPTION_NO_BORING_EXPANSION */ - - - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_BDF` if you want to include support for an - * embedded 'BDF~' table within SFNT-based bitmap formats. - */ -#define TT_CONFIG_OPTION_BDF - - - /************************************************************************** - * - * Option `TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES` controls the maximum - * number of bytecode instructions executed for a single run of the - * bytecode interpreter, needed to prevent infinite loops. You don't want - * to change this except for very special situations (e.g., making a - * library fuzzer spend less time to handle broken fonts). - * - * It is not expected that this value is ever modified by a configuring - * script; instead, it gets surrounded with `#ifndef ... #endif` so that - * the value can be set as a preprocessor option on the compiler's command - * line. - */ -#ifndef TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES -#define TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES 1000000L -#endif - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** T Y P E 1 D R I V E R C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /************************************************************************** - * - * `T1_MAX_DICT_DEPTH` is the maximum depth of nest dictionaries and arrays - * in the Type~1 stream (see `t1load.c`). A minimum of~4 is required. - */ -#define T1_MAX_DICT_DEPTH 5 - - - /************************************************************************** - * - * `T1_MAX_SUBRS_CALLS` details the maximum number of nested sub-routine - * calls during glyph loading. - */ -#define T1_MAX_SUBRS_CALLS 16 - - - /************************************************************************** - * - * `T1_MAX_CHARSTRING_OPERANDS` is the charstring stack's capacity. A - * minimum of~16 is required. - * - * The Chinese font 'MingTiEG-Medium' (covering the CNS 11643 character - * set) needs 256. - */ -#define T1_MAX_CHARSTRINGS_OPERANDS 256 - - - /************************************************************************** - * - * Define this configuration macro if you want to prevent the compilation - * of the 't1afm' module, which is in charge of reading Type~1 AFM files - * into an existing face. Note that if set, the Type~1 driver will be - * unable to produce kerning distances. - */ -#undef T1_CONFIG_OPTION_NO_AFM - - - /************************************************************************** - * - * Define this configuration macro if you want to prevent the compilation - * of the Multiple Masters font support in the Type~1 driver. - */ -#undef T1_CONFIG_OPTION_NO_MM_SUPPORT - - - /************************************************************************** - * - * `T1_CONFIG_OPTION_OLD_ENGINE` controls whether the pre-Adobe Type~1 - * engine gets compiled into FreeType. If defined, it is possible to - * switch between the two engines using the `hinting-engine` property of - * the 'type1' driver module. - */ -#define T1_CONFIG_OPTION_OLD_ENGINE - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** C F F D R I V E R C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /************************************************************************** - * - * Using `CFF_CONFIG_OPTION_DARKENING_PARAMETER_{X,Y}{1,2,3,4}` it is - * possible to set up the default values of the four control points that - * define the stem darkening behaviour of the (new) CFF engine. For more - * details please read the documentation of the `darkening-parameters` - * property (file `ftdriver.h`), which allows the control at run-time. - * - * Do **not** undefine these macros! - */ -#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 500 -#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 400 - -#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 1000 -#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 275 - -#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 1667 -#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 275 - -#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 2333 -#define CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 0 - - - /************************************************************************** - * - * `CFF_CONFIG_OPTION_OLD_ENGINE` controls whether the pre-Adobe CFF engine - * gets compiled into FreeType. If defined, it is possible to switch - * between the two engines using the `hinting-engine` property of the 'cff' - * driver module. - */ -#define CFF_CONFIG_OPTION_OLD_ENGINE - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** P C F D R I V E R C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /************************************************************************** - * - * There are many PCF fonts just called 'Fixed' which look completely - * different, and which have nothing to do with each other. When selecting - * 'Fixed' in KDE or Gnome one gets results that appear rather random, the - * style changes often if one changes the size and one cannot select some - * fonts at all. This option makes the 'pcf' module prepend the foundry - * name (plus a space) to the family name. - * - * We also check whether we have 'wide' characters; all put together, we - * get family names like 'Sony Fixed' or 'Misc Fixed Wide'. - * - * If this option is activated, it can be controlled with the - * `no-long-family-names` property of the 'pcf' driver module. - */ -#define PCF_CONFIG_OPTION_LONG_FAMILY_NAMES - - - /*************************************************************************/ - /*************************************************************************/ - /**** ****/ - /**** A U T O F I T M O D U L E C O N F I G U R A T I O N ****/ - /**** ****/ - /*************************************************************************/ - /*************************************************************************/ - - - /************************************************************************** - * - * Compile 'autofit' module with CJK (Chinese, Japanese, Korean) script - * support. - */ -#define AF_CONFIG_OPTION_CJK - - - /************************************************************************** - * - * Compile 'autofit' module with fallback Indic script support, covering - * some scripts that the 'latin' submodule of the 'autofit' module doesn't - * (yet) handle. Currently, this needs option `AF_CONFIG_OPTION_CJK`. - */ -#ifdef AF_CONFIG_OPTION_CJK -#define AF_CONFIG_OPTION_INDIC -#endif - - - /************************************************************************** - * - * Use TrueType-like size metrics for 'light' auto-hinting. - * - * It is strongly recommended to avoid this option, which exists only to - * help some legacy applications retain its appearance and behaviour with - * respect to auto-hinted TrueType fonts. - * - * The very reason this option exists at all are GNU/Linux distributions - * like Fedora that did not un-patch the following change (which was - * present in FreeType between versions 2.4.6 and 2.7.1, inclusive). - * - * ``` - * 2011-07-16 Steven Chu - * - * [truetype] Fix metrics on size request for scalable fonts. - * ``` - * - * This problematic commit is now reverted (more or less). - */ -/* #define AF_CONFIG_OPTION_TT_SIZE_METRICS */ - - /* */ - - - /* - * This macro is obsolete. Support has been removed in FreeType version - * 2.5. - */ -/* #define FT_CONFIG_OPTION_OLD_INTERNALS */ - - - /* - * The next two macros are defined if native TrueType hinting is - * requested by the definitions above. Don't change this. - */ -#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER -#define TT_USE_BYTECODE_INTERPRETER -#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING -#define TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL -#endif -#endif - - - /* - * The TT_SUPPORT_COLRV1 macro is defined to indicate to clients that this - * version of FreeType has support for 'COLR' v1 API. This definition is - * useful to FreeType clients that want to build in support for 'COLR' v1 - * depending on a tip-of-tree checkout before it is officially released in - * FreeType, and while the feature cannot yet be tested against using - * version macros. Don't change this macro. This may be removed once the - * feature is in a FreeType release version and version macros can be used - * to test for availability. - */ -#ifdef TT_CONFIG_OPTION_COLOR_LAYERS -#define TT_SUPPORT_COLRV1 -#endif - - - /* - * Check CFF darkening parameters. The checks are the same as in function - * `cff_property_set` in file `cffdrivr.c`. - */ -#if CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 < 0 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 < 0 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 < 0 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 < 0 || \ - \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 < 0 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 < 0 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 < 0 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 < 0 || \ - \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1 > \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2 > \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3 > \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4 || \ - \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1 > 500 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2 > 500 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3 > 500 || \ - CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4 > 500 -#error "Invalid CFF darkening parameters!" -#endif - - -FT_END_HEADER - -#endif /* FTOPTION_H_ */ - - -/* END */ diff --git a/freetype/docs/.gitignore b/freetype/docs/.gitignore deleted file mode 100644 index b8d05d1..0000000 --- a/freetype/docs/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -# Static site folder -reference/ - -# HTML and Markdown files -*.html -*.md - -# MkDocs Config file -mkdocs.yml - -# Python virtualenv -env/ diff --git a/freetype/docs/CHANGES b/freetype/docs/CHANGES deleted file mode 100644 index 96cf607..0000000 --- a/freetype/docs/CHANGES +++ /dev/null @@ -1,5686 +0,0 @@ -CHANGES BETWEEN 2.13.1 and 2.13.2 (2023-Aug-25) - - I. MISCELLANEOUS - - - Better support for CFF2 variation fonts. - - - TrueType interpreter version 38 (also known as 'Infinality') has - been removed. - - - Improved OpenVMS support. - - -====================================================================== - -CHANGES BETWEEN 2.13.0 and 2.13.1 (2023-Jun-24) - - I. MISCELLANEOUS - - - New function `FT_Get_Default_Named_Instance` to get the index of - the default named instance of an OpenType Variation Font. - - - A new load flag `FT_LOAD_NO_SVG` to make FreeType ignore glyphs in - an 'SVG ' table. - - - New function `FT_GlyphSlot_AdjustWeight` to adjust the glyph - weight either horizontally or vertically. This is part of the - `ftsynth.h` header file, which is still considered to be in alpha - stage. - - - TrueType interpreter version 38 (also known as 'Infinality') has - been deactivated; the value of `TT_INTERPRETER_VERSION_38` is now - the same as `TT_INTERPRETER_VERSION_40`. - - - Updated OpenVMS support. - - - The base API documentation has been modularized for easier - handling. - - - Switching named instances on and off in Variation Fonts was buggy - if the design coordinates didn't change. - - - `ftbench` has a new command-line option `-a` to apply design - coordinates. - - - `ftview` can now flip SVG rendering on and off using the 'Z' key. - - - In `ftmulti` it is now possible to toggle the fill rule and - overlap flag used for rendering glyphs using the 'F3' and 'F4' - keys, respectively. Toggling the anti-aliased mode has been - changed to the 'TAB' key. - - -====================================================================== - -CHANGES BETWEEN 2.12.1 and 2.13.0 (2023-Feb-09) - - I. IMPORTANT CHANGES - - - The demo program `ftinspect` has been completely updated and much - enhanced. It now combines the functionality of almost all other - graphical FreeType demo programs into a single application based - on the Qt framework. This was Charlie Jiang's GSoC 2022 project. - - - The 'COLR' v1 API is now considered as stable. - - https://learn.microsoft.com/en-us/typography/opentype/spec/colr - - - II. MISCELLANEOUS - - - For OpenType Variable Fonts, `avar` table format 2.0 is now - supported. The code was contributed by Behdad Esfahbod. - - Note that this is an extension supported on recent Apple platforms - and by HarfBuzz, but not yet in the OpenType standard! See - - https://github.com/harfbuzz/boring-expansion-spec/blob/main/avar2.md - - for the specification. To deactivate it, define the configuration - macro 'TT_CONFIG_OPTION_NO_BORING_EXPANSION'. - - - A new API `FT_GlyphSlot_Slant` to slant a glyph by a given angle - has been added. Note that this function is part of `ftsynth.h`, - which is still considered to be in alpha stage. - - - TrueType interpreter version 38 (also known as 'Infinality') that - was first introduced about 10 years ago in FreeType 2.4.11 is now - deprecated and slated to be removed in the next version. TrueType - interpreter version 40 has been FreeType's default version for six - years now and provides an excellent alternative. This is the last - FreeType version with TT_INTERPRETER_VERSION_38 and - TT_INTERPRETER_VERSION_40 treated differently. - - - The only referenced but never documented configuration macro - `FT_CONFIG_OPTION_NO_GLYPH_NAMES` has been removed. - - - The `ftbench` demo program got a new command line option `-e` to - set a charmap index. - - - Specifying a point size is now optional for the demo programs - `ftgrid`, `ftmulti`, `ftstring`, and `ftview`. If not given, a - default size is used. - - - For `ftgrid`, `ftstring`, and `ftview`, option `-e` now also - accepts a numeric value to set a charmap index. - - - In `ftstring`, it is now possible to set the displayed text - interactively by pressing the 'Enter' key. - - - `ftmulti` can now handle up to 16 design axes. - - - To avoid reserved identifiers that are globally defined, the - auto-hinter debugging macros (which are only available if - `FT_DEBUG_AUTOFIT` is defined) - - ``` - _af_debug_disable_horz_hints - _af_debug_disable_vert_hints - _af_debug_disable_blue_hints - _af_debug_hints - ``` - - have been renamed to - - ``` - af_debug_disable_horz_hints_ - af_debug_disable_vert_hints_ - af_debug_disable_blue_hints_ - af_debug_hints_ - ``` - - - The internal zlib library was updated to version 1.2.13. Note, - however, that FreeType is *not* affected by CVE-2022-37434 since - it doesn't use the `inflateGetHeader` function. - - -====================================================================== - -CHANGES BETWEEN 2.12.0 and 2.12.1 (2022-May-01) - - I. IMPORTANT BUG FIXES - - - Loading CFF fonts sometimes made FreeType crash (bug introduced in - version 2.12.0) - - - Loading a fully hinted TrueType glyph a second time (without - caching) sometimes yielded different rendering results if TrueType - hinting was active (bug introduced in version 2.12.0). - - - The generation of the pkg-config file `freetype2.pc` was broken if - the build was done with cmake (bug introduced in version 2.12.0). - - - II. MISCELLANEOUS - - - New option `--with-librsvg` for the `configure` script for better - FreeType demo support. - - - The meson build no longer enforces both static and dynamic - versions of the library by default. - - - The internal zlib library was updated to version 1.2.12. Note, - however, that FreeType is *not* affected by CVE-2018-25032 since - it only does decompression. - - -====================================================================== - -CHANGES BETWEEN 2.11.1 and 2.12.0 (2022-Mar-30) - - I. IMPORTANT CHANGES - - - FreeType now handles OT-SVG fonts, to be controlled with - `FT_CONFIG_OPTION_SVG` configuration macro. By default, it can - only load the 'SVG ' table of an OpenType font. However, by using - the `svg-hooks` property of the new 'ot-svg' module it is possible - to register an external SVG rendering engine. The FreeType demo - programs have been set up to use 'librsvg' as the rendering - library. - - This work was Moazin Khatti's GSoC 2019 project. - - - II. MISCELLANEOUS - - - The handling of fonts with an 'sbix' table has been improved. - - - Corrected bitmap offsets. - - - A new tag `FT_PARAM_TAG_IGNORE_SBIX` for `FT_Open_Face` makes - FreeType ignore an 'sbix' table in a font, allowing applications - to access the font's outline glyphs. - - - `FT_FACE_FLAG_SBIX` and `FT_FACE_FLAG_SBIX_OVERLAY` together - with their corresponding preprocessor macros `FT_HAS_SBIX` and - `FT_HAS_SBIX_OVERLAY` enable applications to treat 'sbix' tables - as described in the OpenType specification. - - - The internal 'zlib' code has been updated to be in sync with the - current 'zlib' version (1.2.11). - - - The previously internal load flag `FT_LOAD_SBITS_ONLY` is now - public. - - - Some minor improvements of the building systems, in particular - handling of the 'zlib' library (internal vs. external). - - - Support for non-desktop Universal Windows Platform. - - - Various other minor bug and documentation fixes. - - - The `ftdump` demo program shows more information for Type1 fonts - if option `-n` is given. - - - `ftgrid` can now display embedded bitmap strikes. - - -====================================================================== - -CHANGES BETWEEN 2.11.0 and 2.11.1 (2021-Dec-01) - - I. IMPORTANT CHANGES - - - Some fields in the `CID_FaceDictRec`, `CID_FaceInfoRec`, and - `FT_Data` structures have been changed from signed to unsigned - type, which better reflects the actual usage. It is also an - additional means to protect against malformed input. - - - II. MISCELLANEOUS - - - Cmake support has been further improved. To do that various - backward-incompatible changes were necessary; please see file - `CMakeLists.txt` for more details. - - - Since version 2.11.0, a C99 compiler is necessary to compile - FreeType. - - - The experimental 'COLR' v1 API has been updated to the latest - OpenType standard 1.9. - - - The `apinames` tool got a new option `-wV` to output an OpenVMS - Linker Option File. - - - VMS support was updated. - - - MS Visual Studio support was added to build the demo programs. - - -====================================================================== - -CHANGES BETWEEN 2.10.4 and 2.11.0 (2021-Jul-18) - - I. IMPORTANT CHANGES - - - A new rendering module has been added to create 8-bit Signed - Distance Field (SDF) bitmaps for both outline and bitmap glyphs. - The new rendering mode is called `FT_RENDER_MODE_SDF`, the pixel - mode is `FT_PIXEL_MODE_GRAY8`, and the corresponding raster flag - is `FT_RASTER_FLAG_SDF`. - - This work was Anuj Verma's GSoC 2020 project. - - - A new, experimental API is now available for surfacing properties - of 'COLR' v1 color fonts (as the name says, this is an extension - to the 'COLR' table for outline color fonts using the SFNT - container format). 'COLR' v1 fonts are a recently proposed - addition to OFF and OpenType; specification work currently happens - in - - https://github.com/googlefonts/colr-gradients-spec/ - - 'COLR' v1 is expected to be merged to OpenType; the ISO - standardisation process for adding 'COLR' v1 as an amendment to - OFF is underway. - - Functions similar to the already existing 'COLR' API have been - added to access the corresponding data. - - FT_Get_Color_Glyph_Paint - Retrieve the root paint for a given glyph ID. - - FT_Get_Paint_Layers - Access the layers of a `PaintColrLayers` table. - - FT_Get_Colorline_Stops - Retrieve the 'color stops' on a color line. As an input, a - color stop iterator gets used, which in turn is retrieved from - a paint. - - FT_Get_Paint - Dereference an `FT_OpaquePaint` object and retrieve the - corresponding `FT_COLR_Paint` object, which contains details - on how to draw the respective 'COLR' v1 `Paint` table. - - - II. MISCELLANEOUS - - - FreeType has moved its infrastructure to - - https://gitlab.freedesktop.org/freetype - - A side effect is that the git repositories are now called - `freetype.git` and `freetype-demos.git`, which by default expand - to the directories `freetype` and `freetype-demos`, respectively. - The documentation has been updated accordingly. - - FreeType's Savannah repositories will stay; they are now mirrors - of the 'freedesktop.org' repositories. - - - A new function `FT_Get_Transform` returns the values set by - `FT_Set_Transform`. - - - A new configuration macro `FT_DEBUG_LOGGING` is available. It - provides extended debugging capabilities for FreeType, for example - showing a time stamp or displaying the component a tracing message - comes from. See file `docs/DEBUG` for more information. - - This work was Priyesh Kumar's GSoC 2020 project. - - - The legacy Type 1 and CFF engines are further demoted due to lack - of CFF2 charstring support. You now need to use `FT_Property_Set` - to enable them besides the `T1_CONFIG_OPTION_OLD_ENGINE` and - `CFF_CONFIG_OPTION_OLD_ENGINE` options, respectively. - - - The experimental 'warp' mode (AF_CONFIG_OPTION_USE_WARPER) for the - auto-hinter has been removed. - - - The smooth rasterizer performance has been improved by >10%. Note - that due to necessary code changes there might be very subtle - differences in rendering. They are not visible by the eye, - however. - - - PCF bitmap fonts compressed with LZW (these are usually files with - the extension `.pcf.Z`) are now handled correctly. - - - Improved Meson build files, including support to build the - FreeType demo programs. - - - A new demo program `ftsdf` is available to display Signed Distance - Fields of glyphs. - - - The `ftlint` demo program has been extended to do more testing of - its input. In particular, it can display horizontal and vertical - acutances for quality assessment, together with computing MD5 - checksums of rendered glyphs. - - [The acutance measures how sharply the pixel coverage changes at - glyph edges. For monochrome bitmaps, it is always 2.0 in either - X or Y direction. For anti-aliased bitmaps, it depends on the - hinting and the shape of a glyph and might approach or even reach - value 2.0 for glyphs like 'I', 'L', '+', '-', or '=', while it - might be lower for glyphs like 'O', 'S', or 'W'.] - - - The `ttdebug` demo program didn't show changed point coordinates - (bug introduced in version 2.10.3). - - - It is now possible to adjust the axis increment for variable fonts - in the `ftmulti` demo program. - - - It is now possible to change the hinting engine in the `ftstring` - demo program. - - - The graphical demo programs work better now in native color depth - on win32 and x11. - - -====================================================================== - -CHANGES BETWEEN 2.10.3 and 2.10.4 (2020-Oct-20) - - I. IMPORTANT BUG FIXES - - - A heap buffer overflow has been found in the handling of embedded - PNG bitmaps, introduced in FreeType version 2.6. - - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-15999 - - If you use option FT_CONFIG_OPTION_USE_PNG you should upgrade - immediately. - - -====================================================================== - -CHANGES BETWEEN 2.10.2 and 2.10.3 (2020-Oct-10) - - I. IMPORTANT CHANGES - - - New flag `FT_OUTLINE_OVERLAP'. If set, make the smooth rasterizer - do 4x4 oversampling to mitigate artifacts in pixels partially - covered by overlapping contours. Note that this at least - quadruples the rendering time. - - If a glyph in a TrueType font has the `OVERLAP_SIMPLE' or - `OVERLAP_COMPOUND' bit set, FreeType automatically selects this - rendering mode. - - - II. MISCELLANEOUS - - - Using the arcane method of including FreeType header files with - macros like `FT_FREETYPE_H' is no longer mandatory (but retained - as an optional feature for backward compatibility). - - - Support for building the library with Meson. Building the demo - programs with Meson will follow in a forthcoming release. - - - Minor improvements to the B/W rasterizer. - - - Auto-hinter support for Medefaidrin script. - - - Fix various memory leaks (mainly for CFF) and other issues that - might cause crashes in rare circumstances. - - - Jam support has been removed. - - - In `ftview', custom LCD filter values are now normalized and - balanced. Unorthodox filters are still available through the `-L' - command line option. - - - The GUI demo programs can now be resized. - - - Demo programs that accept command line option `-k' can now handle - function keys, too. The corresponding character codes start with - 0xF1. As an example, the POSIX shell syntax (accepted by bash, - ksh, and zsh) - - -k $'\xF3q' - - emulates the pressing of function key `F3' followed by key `q'. - - -====================================================================== - -CHANGES BETWEEN 2.10.1 and 2.10.2 (2020-May-09) - - I. IMPORTANT CHANGES - - - Support of WOFF2 fonts. This code contribution was Nikhil - Ramakrishnan's GSoC 2019 project. - - - II. MISCELLANEOUS - - - Function `FT_Get_Var_Axis_Flags' returned random data for Type 1 - MM fonts. - - - Type 1 fonts with non-integer metrics are now supported by the new - (CFF) engine introduced in FreeType 2.9. - - - Drop support for Python 2 in Freetype's API reference generator - `docwriter' (Python >= 3.5 is required for targets `make refdoc' - and `make refdoc-venv'). - - - Auto-hinter support for Hanifi Rohingya. - - - Document the `FT2_KEEP_ALIVE' debugging environment variable. - - - The Visual C++ (and Visual C) project files for Windows builds no - longer generate libraries that contain the FreeType version in its - filenames. Instead, a resource file gets used to make the - libraries contain the corresponding information. - - - The next release will remove Jam build support. - - - The `ftbench' demo program has a new test for testing the - `FT_Glyph_Stroke' functionality. - - -====================================================================== - -CHANGES BETWEEN 2.10.0 and 2.10.1 (2019-Jul-01) - - I. IMPORTANT BUG FIXES - - - The bytecode hinting of OpenType variation fonts was flawed, since - the data in the `CVAR' table wasn't correctly applied. - - - II. MISCELLANEOUS - - - Auto-hinter support for Mongolian. - - - For distribution, `.tar.bz2' packages are replaced with `.tar.xz' - bundles. - - - The handling of the default character in PCF fonts as introduced - in version 2.10.0 was partially broken, causing premature abortion - of charmap iteration for many fonts. - - - If `FT_Set_Named_Instance' was called with the same arguments - twice in a row, the function returned an incorrect error code the - second time. - - - Direct rendering using FT_RASTER_FLAG_DIRECT crashed (bug - introduced in version 2.10.0). - - - Increased precision while computing OpenType font variation - instances. - - - The flattening algorithm of cubic Bezier curves was slightly - changed to make it faster. This can cause very subtle rendering - changes, which aren't noticeable by the eye, however. - - - The auto-hinter now disables hinting if there are blue zones - defined for a `style' (i.e., a certain combination of a script and - its related typographic features) but the font doesn't contain any - characters needed to set up at least one blue zone. - - - The `ftmulti' demo program now supports multiple hidden axes with - the same name tag. - - - `ftview', `ftstring', and `ftgrid' got a `-k' command line option - to emulate a sequence of keystrokes at start-up. - - - `ftview', `ftstring', and `ftgrid' now support screen dumping to a - PNG file. - - - The bytecode debugger, `ttdebug', now supports variation TrueType - fonts; a variation font instance can be selected with the new `-d' - command line option. - - -====================================================================== - -CHANGES BETWEEN 2.9.1 and 2.10.0 (2019-Mar-15) - - I. IMPORTANT CHANGES - - - A bunch of new functions has been added to access and process - COLR/CPAL data of OpenType fonts with color-layered glyphs. - - FT_Palette_Data_Get - Retrieve color palette data. - FT_Palette_Select - Select and activate a color palette for color-layered - glyphs. - FT_Palette_Set_Foreground_Color - Set text foreground color for palette index 0xFFFF. - - FT_Get_Color_Glyph_Layer - Get color layers for a given glyph (using an interator - object). - - FT_Bitmap_Blend - Blend one bitmap onto another with a given color. - - - An experimental feature is the new behaviour of the - `FT_LOAD_COLOR' load flag for color-layered glyphs: Internally - it sets a flag so that if `FT_Render_Glyph' is called with - `FT_RENDER_MODE_NORMAL' (or `FT_Load_Glyph' with - `FT_LOAD_RENDER'), a default blending of the color glyph layers - will happen automatically for convenience. - - - As a GSoC 2018 project, Nikhil Ramakrishnan completely - overhauled and modernized the API reference. - - - II. MISCELLANEOUS - - - The logic for computing the global ascender, descender, and - height of OpenType fonts has been slightly adjusted for - consistency. - - . If the `useTypoMetrics' flag (i.e., bit 7 in the `fsSelection' - field) in the `OS/2' table is set, use the `sTypo' fields in - `OS/2' unconditionally. - . Otherwise use the metrics data from the `hhea' table (if not - zero). - . Otherwise use the `sTypo' fields from the `OS/2' table (if not - zero). - . Otherwise use the `usWin' data from the `OS/2' table as a last - resort. - - Variable fonts will apply the `MVAR' deltas to whichever metrics - were picked. - - - `TT_Set_MM_Blend' could fail if call repeatedly with the same - arguments. - - - The precision of handling deltas in Variation Fonts has been - increased. The problem did only show up with multidimensional - designspaces. - - - New function `FT_Library_SetLcdGeometry' to set up the geometry - of LCD subpixels. - - - FreeType now uses the `defaultChar' property of PCF fonts to set - the glyph for the undefined character at glyph index 0 (as - FreeType already does for all other supported font formats). As - a consequence, the order of glyphs of a PCF font if accessed - with FreeType can be different now compared to previous - versions. - - This change doesn't affect PCF font access with cmaps. - - - `FT_Select_Charmap' has been changed to allow parameter value - `FT_ENCODING_NONE', which is valid for BDF, PCF, and Windows FNT - formats to access built-in cmaps that don't have a predefined - `FT_Encoding' value. - - - A previously reserved field in the `FT_GlyphSlotRec' structure - now holds the glyph index. - - - On Win32 platforms, the use of `_DLL' to build the library has - been replaced with `DLL_EXPORT' and `DLL_IMPORT'. - - - The usual round of fuzzer bug fixes to better reject malformed - fonts. - - - `FT_Outline_New_Internal' and `FT_Outline_Done_Internal' have - been removed. These two functions were public by oversight only - and were never documented. - - - A new function `FT_Error_String' returns descriptions of error - codes if configuration macro FT_CONFIG_OPTION_ERROR_STRINGS is - defined. - - - `FT_Set_MM_WeightVector' and `FT_Get_MM_WeightVector' are new - functions limited to Adobe MultiMaster fonts to directly set and - get the weight vector. - - - Support for Position Independent Code as needed by systems that - prohibit automatic address fixups, such as BREW, has been - removed. [Compilation with modern compilers that use flags like - `-fPIC' or `-fPIE' is not affected.] - - - The `ftdump' demo program has new options `-c' and `-C' to - display charmaps in compact and detailed format, respectively. - Option `-V' has been removed. - - - The `ftview', `ftstring', and `ftgrid' demo programs use a new - command line option `-d' to specify the program window's width, - height, and color depth. - - - The `ftview' demo program now displays red boxes for zero-width - glyphs. - - - `ftglyph' has limited support to display fonts with - color-layered glyphs. This will be improved later on. - - - `ftgrid' can now display bitmap fonts also. - - - The `ttdebug' demo program has a new option `-f' to select a - member of a TrueType collection (TTC). - - - Other various improvements to the demo programs. - - -====================================================================== - -CHANGES BETWEEN 2.9 and 2.9.1 (2019-May-01) - - I. IMPORTANT BUG FIXES - - - Type 1 fonts containing flex features were not rendered - correctly (bug introduced in version 2.9). - - - CVE-2018-6942: Older FreeType versions can crash with certain - malformed variation fonts. - - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-6942 - - - II. MISCELLANEOUS - - - Bug fix: Multiple calls to `FT_Get_MM_Var' returned garbage. - - - The base extensions `ftlcdfil' and `ftfntfmt' are now part of - the base module (and thus no longer configurable in file - `modules.cfg'). - - - Emboldening of bitmaps didn't work correctly sometimes, showing - various artifacts (bug introduced in version 2.8.1). - - - Use of the `freetype-config' script to get compilation and - linking options is deprecated since it doesn't support - cross-compiling, among other deficiencies. Instead, you should - use the `pkg-config' interface. - - The `configure' script no longer installs `freetype-config' by - default. For backward compatibility, a new configure option - `--enable-freetype-config' is provided that reverts this - decision. - - - The auto-hinter script ranges have been updated for Unicode 11. - No support for new scripts have been added, however, with the - exception of Georgian Mtavruli. - - - Support for cmake has been improved. - - - The next release will remove support for Position Independent - Code as needed by systems that prohibit automatic address - fixups, such as BREW. [Compilation with modern compilers that - use flags like `-fPIC' or `-fPIE' is not affected.] - - -====================================================================== - -CHANGES BETWEEN 2.8.1 and 2.9 (2018-Jan-08) - - I. IMPORTANT BUG FIXES - - - Advance width values of variation fonts were often wrong. - - - More fixes for variation font support; you should update to this - version if you want to support them. - - - II. IMPORTANT CHANGES - - - As a GSoC project, Ewald Hew extended the new (Adobe) CFF engine - to handle Type 1 fonts also, thus greatly improving the - rendering of this format. This is the new default. The old - engine is still available if the configuration macro - `T1_CONFIG_OPTION_OLD_ENGINE' gets defined; using the - `hinting-engine' property of the `type1' driver module you can - then switch between the two engines. - - - A new function, `FT_Set_Named_Instance', can be used to set or - change the current named instance. - - - Starting with this FreeType version, resetting variation - coordinates will return to the currently selected named - instance. Previously, FreeType returned to the base font (i.e., - no instance set). - - - III. MISCELLANEOUS - - - The `face_flags' field of the `FT_Face' structure has a new bit, - `FT_FACE_FLAG_VARIATION', which is set if a variation font has - been altered with `FT_Set_MM_Design_Coordinates', - `FT_Set_Var_Design_Coordinates', or - `FT_Set_Var_Blend_Coordinates'. - - - If the current face is a named instance, the new macro - `FT_IS_NAMED_INSTANCE' returns true. - - - `FT_IS_VARIATION' is a new macro that returns true whenever a - face object has been altered by `FT_Set_MM_Design_Coordinates', - `FT_Set_Var_Design_Coordinates', or - `FT_Set_Var_Blend_Coordinates'. - - - Changing the design coordinates of a variation font with - `FT_Set_Var_Design_Coordinates' or - `FT_Set_Var_Blend_Coordinates' does not influence the named - instance index value (only `FT_Set_Named_Instance' does that). - - - Special PostScript names for named instances are only returned - if the named instance is set with `FT_Set_Named_Instance' (and - the font has corresponding entries in its `fvar' table). If - `FT_IS_VARIATION' returns true, the algorithmically derived - PostScript name is provided, not looking up special entries for - named instances. - - - A new function `FT_Done_MM_Var' is provided to free the memory - returned in a call to `FT_Get_MM_Var'. - - - On platforms using the `configure' script, the installed - `ftoption.h' file now correctly reflects configuration options - like `--with-harfbuzz'. - - - Better support to build FreeType as a DLL on Windows using - Visual C. - - - All data specific to driver modules is now collected in a single - file, `FT_DRIVER_H'. Consequently, the macros - `FT_AUTOHINTER_H', `FT_CFF_DRIVER_H', `FT_TRUETYPE_DRIVER_H', - and `FT_PCF_DRIVER_H' still work but are deprecated. - - - Some fuzzer fixes to better reject malformed fonts. - - - The `ftbench' demo program has a new test for opening a new face - and loading some glyphs. - - - The `ftbench' demo program has a new option `-j' to specify the - last glyph index to be used in the tests. - - - The `ftgrid' demo program has a new option `-n' to suppress - display of named instances of variation fonts. - - - The `ttdebug' demo program can now show a stack trace (key `K') - and switch between hexadecimal and decimal display of integers - (key `I'). - - -====================================================================== - -CHANGES BETWEEN 2.8 and 2.8.1 (2017-Sep-16) - - I. IMPORTANT BUG FIXES - - - B/W hinting of TrueType fonts didn't work properly if - interpreter version 38 or 40 was selected. - - - Some severe problems within the handling of TrueType Variation - Fonts were found and fixed. - - - Function `FT_Set_Var_Design_Coordinates' didn't correctly handle - the case with less input coordinates than axes. - - - II. IMPORTANT CHANGES - - - By default, FreeType now offers high quality LCD-optimized - output without resorting to ClearType techniques of resolution - tripling and filtering. In this method, called Harmony, each - color channel is generated separately after shifting the glyph - outline, capitalizing on the fact that the color grids on LCD - panels are shifted by a third of a pixel. This output is - indistinguishable from ClearType with a light 3-tap filter. - - - III. MISCELLANEOUS - - - Using the new function `FT_Get_Var_Axis_Flags', an application - can access the `flags' field of a variation axis (introduced in - OpenType version 1.8.2) - - - More sanity checks. - - - The internal representation of buffers for LCD rendering has - changed (to be more precise, the amount of padding gets computed - differently). Applications that use the FreeType API are not - affected. - - - To reset all design axis values of a variation font to its - default values you can now say - - error = FT_Set_Var_Design_Coordinates( face, 0, NULL ); - - This also works with functions `FT_Set_MM_Design_Coordinates' - and `FT_Set_MM_Blend_Coordinates'. - - - FreeType now synthesizes a missing Unicode cmap for (older) - TrueType fonts also if glyph names are available. - - - FreeType has improved handling of BDF fonts without the - `POINT_SIZE', `RESOLUTION_X', or `RESOLUTION_Y' properties; the - library now uses the values of the `SIZE' keyword if they are - missing. Previously, `SIZE' was completely ignored, and - FreeType used heuristic values instead. - - - Multiple calls to `FT_Bitmap_Convert' do work now as advertised. - Previously, they failed with an assertion error if there was an - empty bitmap between non-empty ones. - - - The warping option has moved from `light' to `normal' hinting - where it replaces the original hinting algorithm. The `light' - mode is now always void of any hinting in x-direction. - - - 16bit compiler support is now officially ended. We didn't - provide any maintenance since many years, and given that there - were no error or problem reports either it seems that it is no - longer needed. - - - The `ftgrid' demo program can now toggle the display of grid - lines with the `G' key. - - - The `ftgrid' demo program can toggle a different set of colors - (suitable to color-blind people) with the `C' key. - - - The `ftgrid' demo program now supports the `-e' command line - option to select a cmap. - - - The `ftdump' demo program has a new command line option `-t' to - output the SFNT table list. - - -====================================================================== - -CHANGES BETWEEN 2.7.1 and 2.8 (2017-May-13) - - I. IMPORTANT CHANGES - - - Support for OpenType Variation Fonts is now complete. The last - missing part was handling the `VVAR' and `MVAR' tables, which is - available with this release. - - - A new function `FT_Face_Properties' allows the control of some - module and library properties per font. Currently, the - following properties can be handled: stem darkening, LCD filter - weights, and the random seed for the `random' CFF operator. - - - The PCF change to show more `colorful' family names (introduced - in version 2.7.1) was too radical; it can now be configured with - PCF_CONFIG_OPTION_LONG_FAMILY_NAMES at compile time. If - activated, it can be switched off at run time with the new pcf - property `no-long-family-names'. If the `FREETYPE_PROPERTIES' - environment variable is available, you can say - - FREETYPE_PROPERTIES=pcf:no-long-family-names=1 - - - Support for the following scripts has been added to the - auto-hinter. - - Adlam, Avestan, Bamum, Buhid, Carian, Chakma, Coptic, Cypriot, - Deseret, Glagolitic, Gothic, Kayah, Lisu, N'Ko, Ol Chiki, Old - Turkic, Osage, Osmanya, Saurashtra, Shavian, Sundanese, Tai - Viet, Tifinagh, Unified Canadian Syllabics, Vai - - - II. IMPORTANT BUG FIXES - - - `Light' auto-hinting mode no longer uses TrueType metrics for - TrueType fonts. This bug was introduced in version 2.4.6, - causing horizontal scaling also. Almost all GNU/Linux - distributions (with Fedora as a notable exception) disabled the - corresponding patch for good reasons; chances are thus high that - you won't notice a difference. - - If optical backward compatibility for legacy applications is - necessary, you might enable the AF_CONFIG_OPTION_TT_SIZE_METRICS - configuration option. However, it is strongly recommended to - avoid that, adjusting font sizes instead. - - - Global size metrics values in the `FT_Size_Metrics' structure - can be different for TrueType fonts. Reason is that in older - FreeType versions the metrics were rounded differently to - integer pixels compared to all other font formats, yielding an - inconsistent behaviour if you used non-native hinting. Starting - with this version, global size metrics for TrueType fonts are - handled the same as other font formats: `ascender' gets rounded - up, `descender' gets rounded down, `height' gets normally - rounded, and `max_advance' gets normally rounded, too. - - If you need more precise values of (global) ascender, descender, - height, or `max_advance', please take the corresponding values - from the `FT_Face' structure and scale them manually. - - - If a TrueType font gets loaded with FT_LOAD_NO_HINTING, FreeType - now scales the font linearly again (bug introduced in version - 2.4.6). - - - CVE-2017-8105, CVE-2017-8287: Older FreeType versions have - out-of-bounds writes caused by heap-based buffer overflows - related to Type 1 fonts. - - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-8105 - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-8287 - - - III. MISCELLANEOUS - - - A new function `FT_Set_Default_Properties' has been added to - parse the `FREETYPE_PROPERTIES' environment variable - (previously, it was internal only). `FT_Init_FreeType' always - call this function, but `FT_New_Library' does not (similar to - `FT_Add_Default_Modules'). - - - To be in sync with OpenType version 1.7 and newer, macros - - FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY, - FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY, - TT_NAME_ID_PREFERRED_FAMILY - TT_NAME_ID_PREFERRED_SUBFAMILY - - are renamed to - - FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY, - FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY, - TT_NAME_ID_TYPOGRAPHIC_FAMILY - TT_NAME_ID_TYPOGRAPHIC_SUBFAMILY - - The old macro names are deprecated (but still available). - - - Support for SFNT `name' tables has been improved. - - . Format 1 `name' tables are now supported. Use new function - `FT_Get_Sfnt_LangTag' to access associated language tags. - - . Language, encoding, and name IDs have been updated to OpenType - version 1.8.1. - - - The new CFF engine now handles the `random' operator. All CFF - opcodes are now supported. - - - The CFF module has a new property `random-seed' to control the - pseudo-random number generation for the `random' operator. - - - The `freetype-config' script is now a wrapper of `pkg-config' if - this program is available in the path. - - - FT_LOAD_TARGET_LCD is now a variant of FT_LOAD_TARGET_LIGHT; - this should provide better rendering results. - - - A mode to display light auto-hinting with subpixel positioning - has been added to `ftdiff'. - - -====================================================================== - -CHANGES BETWEEN 2.7 and 2.7.1 (2016-Dec-30) - - I. IMPORTANT CHANGES - - - Support for the new CFF2 font format as introduced with OpenType - 1.8 has been contributed by Dave Arnolds from Adobe. - - - Preliminary support for variation fonts as specified in OpenType - 1.8 (in addition to the already existing support for Adobe's MM - and Apple's GX formats). Dave Arnolds contributed handling of - advance width change variation; more will come in the next - version. - - - II. IMPORTANT BUG FIXES - - - Handling of raw CID fonts was partially broken (bug introduced - in 2.6.4). - - - CVE-2016-10328: Older FreeType versions had an out-of-bounds - write caused by a heap-based buffer overflow related to the CFF - fonts. - - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-10328 - - - III. MISCELLANEOUS - - - Some limits for TrueType bytecode execution have been tightened - to speed up FreeType's handling of malformed fonts, in - particular to quickly abort endless loops. - - - The number of twilight points can no longer be set to an - arbitrarily large value. - - - The total number of jump opcode instructions (like JMPR) with - negative arguments is dynamically restricted; the same holds - for the total number of iterations in LOOPCALL opcodes. - - The dynamic limits are based on the number of points in a glyph - and the number of CVT entries. Please report if you encounter a - font where the selected values are not adequate. - - - PCF family names are made more `colorful'; they now include the - foundry and information whether they contain wide characters. - For example, you no longer get `Fixed' but rather `Sony Fixed' - or `Misc Fixed Wide'. - - - A new function `FT_Get_Var_Blend_Coordinates' (with its alias - name `FT_Get_MM_Blend_Coordinates') to retrieve the normalized - blend coordinates of the currently selected variation instance - has been added to the Multiple Masters interface. - - - A new function `FT_Get_Var_Design_Coordinates' to retrieve the - design coordinates of the currently selected variation instance - has been added to the Multiple Masters interface. - - - A new load flag `FT_LOAD_BITMAP_METRICS_ONLY' to retrieve bitmap - information without loading the (embedded) bitmap itself. - - - Retrieving advance widths from bitmap strikes (using - `FT_Get_Advance' and `FT_Get_Advances') have been sped up. - - - The usual round of fuzzer fixes to better reject malformed - fonts. - - - The `ftmulti' demo program can now switch engines with key `H'. - - - The `ftstring' demo program can now show some built-in, - non-latin sample strings (to be selected with the TAB key). - - - The `ftview' demo program can now switch between a font's - charmaps using the TAB key. - - -====================================================================== - -CHANGES BETWEEN 2.6.5 and 2.7 (2016-Sep-08) - - I. IMPORTANT CHANGES - - - As announced earlier, the 2.7.x series now uses the new subpixel - hinting mode as the default, emulating a modern version of - ClearType. - - This change inevitably leads to different rendering results, and - you might change the `TT_CONFIG_OPTION_SUBPIXEL_HINTING' - configuration option to adapt it to your taste (or use the new - `FREETYPE_PROPERTIES' environment variable). See the - corresponding entry below for version 2.6.4, which gives more - information. - - - A new option `FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES' has been - introduced. If set (which is the default), an environment - variable `FREETYPE_PROPERTIES' can be used to control driver - properties. Example: - - FREETYPE_PROPERTIES=truetype:interpreter-version=35 \ - cff:no-stem-darkening=1 \ - autofitter:warping=1 - - This allows to select, say, the subpixel hinting mode at runtime - for a given application. See file `ftoption.h' for more. - - - II. IMPORTANT BUG FIXES - - - After loading a named instance of a GX variation font, the - `face_index' value in the returned `FT_Face' structure now - correctly holds the named instance index in the upper 16bits as - documented. - - - III. MISCELLANEOUS - - - A new macro `FT_IS_NAMED_INSTANCE' to test whether a given face - is a named instance. - - - More fixes to GX font handling. - - - Apple's `GETVARIATION' bytecode operator (needed for GX - variation font support) has been implemented. - - - Another round of fuzzer fixes, mainly to reject invalid fonts - faster. - - - Handling of raw CID fonts was broken (bug introduced in version - 2.6.4). - - - The smooth rasterizer has been streamlined to make it faster by - approx. 20%. - - - The `ftgrid' demo program now understands command line option - `-d' to give start-up design coordinates. - - - The `ftdump' demo program has a new command line option `-p' to - dump TrueType bytecode instructions. - - -====================================================================== - -CHANGES BETWEEN 2.6.4 and 2.6.5 (2016-Jul-12) - - I. IMPORTANT BUG FIXES - - - Compilation works again on Mac OS X (bug introduced in version - 2.6.4). - - - II. IMPORTANT CHANGES - - - The new subpixel hinting mode is now disabled by default; it - will be enabled by default in the forthcoming 2.7.x series. - Main reason for reverting this feature is the principle of least - surprise: a sudden change in appearance of all fonts (even if - the rendering improves for almost all recent fonts) should not - be expected in a new micro version of a series. - - -====================================================================== - -CHANGES BETWEEN 2.6.3 and 2.6.4 (2016-Jul-05) - - I. IMPORTANT CHANGES - - - A new subpixel hinting mode has been contributed by Nikolaus - Waxweiler, which is now the default rendering mode for TrueType - fonts. It implements (almost everything of) version 40 of the - bytecode engine. - - The existing code base in FreeType (the `Infinality code') was - stripped to the bare minimum and all configurability removed in - the name of speed and simplicity. The configurability was - mainly aimed at legacy fonts like Arial, Times New Roman, or - Courier. [Legacy fonts are fonts that modify vertical stems to - achieve clean black-and-white bitmaps.] The new mode focuses on - applying a minimal set of rules to all fonts indiscriminately so - that modern and web fonts render well while legacy fonts render - okay. - - Activation of the subpixel hinting support can be controlled - with the `TT_CONFIG_OPTION_SUBPIXEL_HINTING' configuration - option at compile time: If set to value 1, you get the old - Infinality mode (which was never the default due to its - slowness). Value 2 activates the new subpixel hinting mode, and - value 3 activates both. The default is value 2. - - At run time, you can select the subpixel hinting mode with the - `interpreter-version' property (provided you have compiled in - the corresponding hinting mode); see `ftttdrv.h' for more. - - - Support for the following scripts has been added to the - auto-hinter. - - Armenian, Cherokee, Ethiopic, Georgian, Gujarati, Gurmukhi, - Malayalam, Sinhala, Tamil - - - II. MISCELLANEOUS - - - Type 42 fonts as created by LilyPond are now supported. - - - Minor rendering improvements in the auto-hinter. - - - For experimental reasons, the old CFF engine now supports all - CFF operators except `random', including the deprecated Multiple - Masters instructions. This allows the display of fonts like - `ITCGaramondMM-It.otf' (without font variations, though). - - - Another round of fixes to improve handling of invalid fonts. - - - The `ftgrid' demo program now displays the rendered pixels also; - this can be switched off with the `b' key. Selection of various - LCD filtering modes can be done with the `L' key. - - - The demo programs have been extended to allow selection of all - available TrueType bytecode engines. - - - A very early beta version of a new, Qt based demo program called - `ftinspect' is part of the source code bundle; it will - eventually supersede the other demo programs. Currently, you - have to compile it manually with `qmake; make'; note that many - features are still missing. - - -====================================================================== - -CHANGES BETWEEN 2.6.2 and 2.6.3 (2016-Feb-08) - - I. IMPORTANT CHANGES - - - Khmer, Myanmar, Bengali, and Kannada script support has been - added to the auto-hinter. - - - II. MISCELLANEOUS - - - Better support of Indic scripts like Devanagari by using a - top-to-bottom hinting flow. - - - All FreeType macros starting with two underscores have been - renamed to avoid a violation of both the C and C++ standards. - Example: Header macros of the form `__FOO_H__' are now called - `FOO_H_'. In most cases, this should be completely transparent - to the user. The exception to this is `__FTERRORS_H__', which - must be sometimes undefined by the user to get FreeType error - strings: Both this form and the new `FTERRORS_H_' macro are - accepted for backward compatibility. - - - Minor improvements mainly to the Type 1 driver. - - - The new CFF engine now supports all Type 2 operators except - `random'. - - - The macro `_STANDALONE_', used for compiling the B/W and smooth - rasterizers as stand-alone modules, has been renamed to - `STANDALONE_', since macro names starting with an underscore and - followed by an uppercase letter are reserved in both C and C++. - - - Function `FT_Library_SetLcdFilterWeights' now also activates - custom LCD filter weights (instead of just adjusting them). - - - Support for `unpatented hinting' has been completely removed: - Consequently, the two functions `FT_Face_CheckTrueTypePatents' - and `FT_Face_SetUnpatentedHinting' now return always false, - doing nothing. - - - The `ftgamma' demo program has been modernized; the gamma grid - display has been moved from `ftview' to this program. - - - In `ftview', it is now possible to cycle through the available - LCD filtering modes. - - -====================================================================== - -CHANGES BETWEEN 2.6.1 and 2.6.2 (2015-Nov-28) - - I. IMPORTANT CHANGES - - - The auto-hinter now supports stem darkening, to be controlled by - the new `no-stem-darkening' and `darkening-parameters' - properties. This is an experimental feature contributed by - Nikolaus Waxweiler, and the interface might change in a future - release. - - - By default, stem darkening is now switched off (for both the CFF - engine and the auto-hinter). The main reason is that you need - linear alpha blending and gamma correction to get correct - rendering results, and the latter is not yet available in most - freely available rendering stacks like X11. Applying stem - darkening without proper gamma correction leads to far too dark - rendering results. - - - The meaning of `FT_RENDER_MODE_LIGHT' has been slightly - modified. It now essentially means `no hinting along the - horizontal axis'; in particular, no change of glyph advance - widths. Consequently, the auto-hinter is used for all scalable - font formats except for CFF. It is planned that other - font-specific rendering engines (TrueType, Type 1) will follow. - - - II. MISCELLANEOUS - - - The default LCD filter has been changed to be normalized and - color-balanced. - - - For better compatibility with FontConfig, function - `FT_Library_SetLcdFilter' accepts a new enumeration value - `FT_LCD_FILTER_LEGACY1' (which has the same meaning as - `FT_LCD_FILTER_LEGACY'). - - - A large number of bugs have been detected by using the libFuzzer - framework, which should further improve handling of invalid - fonts. Thanks again to Kostya Serebryany and Bungeman! - - - `TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES', a new configuration - option, controls the maximum number of executed opcodes within a - bytecode program. You don't want to change this except for very - special situations (e.g., making a library fuzzer spend less - time to handle broken fonts). - - - The smooth renderer has been made faster. - - - The `ftstring' demo program now supports subpixel rendering; use - key `l' to cycle through the LCD modes. - - - The `ftstring' demo program now supports color rendering; use - the `space' key to cycle through various color combinations. - - - The graphical demo programs now use a default gamma value of 1.8 - (instead of 1.2). - - -====================================================================== - -CHANGES BETWEEN 2.6 and 2.6.1 (2015-Oct-04) - - I. IMPORTANT BUG FIXES - - - It turned out that for CFFs only the advance widths should be - taken from the `htmx' table, not the side bearings. This bug, - introduced in version 2.6.0, makes it necessary to upgrade if - you are using CFFs; otherwise, you get cropped glyphs with GUI - interfaces like GTK or Qt. - - - Accessing Type 42 fonts returned incorrect results if the glyph - order of the embedded TrueType font differs from the glyph order - of the Type 42 charstrings table. - - - II. IMPORTANT CHANGES - - - The header file layout has been changed (again), moving all - header files except `ft2build.h' into a subdirectory tree. - - Doing so reduces the possibility of header file name clashes - (e.g., FTGL's `FTGlyph.h' with FreeType's `ftglyph.h') on case - insensitive file systems like Mac OS X or Windows. - - Applications that use (a) the `freetype-config' script or - FreeType's `freetype2.pc' file for pkg-config to get the include - directory for the compiler, and (b) the documented way for - header inclusion like - - #include - #include FT_FREETYPE_H - ... - - don't need any change to the source code. - - - Simple access to named instances in GX variation fonts is now - available (in addition to the previous method via FreeType's MM - interface). In the `FT_Face' structure, bits 16-30 of the - `face_index' field hold the current named instance index for the - given face index, and bits 16-30 of `style_flags' contain the - number of instances for the given face index. `FT_Open_Face' - and friends also understand the extended bits of the face index - parameter. - - You need to enable TT_CONFIG_OPTION_GX_VAR_SUPPORT for this new - feature. Otherwise, bits 16-30 of the two fields are zero (or - are ignored). - - - Lao script support has been added to the auto-hinter. - - - III. MISCELLANEOUS - - - The auto-hinter's Arabic script support has been enhanced. - - - Superscript-like and subscript-like glyphs as used by various - phonetic alphabets like the IPA are now better supported by the - auto-hinter. - - - The TrueType bytecode interpreter now runs slightly faster. - - - Improved support for builds with cmake. - - - The function `FT_CeilFix' now always rounds towards plus - infinity. - - - The function `FT_FloorFix' now always rounds towards minus - infinity. - - - A new load flag `FT_LOAD_COMPUTE_METRICS' has been added; it - makes FreeType ignore pre-computed metrics, as needed by font - validating or font editing programs. Right now, only the - TrueType module supports it to ignore data from the `hdmx' - table. - - - Another round of bug fixes to better handle broken fonts, found - by Kostya Serebryany . - - -====================================================================== - -CHANGES BETWEEN 2.5.5 and 2.6 (2015-Jun-07) - - I. IMPORTANT CHANGES - - - Behdad Esfahbod contributed code for improved thread-safety, - which results in the following model. - - * An `FT_Face' object can only be safely used from one thread at - a time. - - * An `FT_Library' object can now be used without modification - from multiple threads at the same time. - - * `FT_Face' creation and destruction with the same `FT_Library' - object can only be done from one thread at a time. - - One can use a single `FT_Library' object across threads as long - as a mutex lock is used around `FT_New_Face' and `FT_Done_Face'. - Any calls to `FT_Load_Glyph' and similar API are safe and do not - need the lock to be held as long as the same `FT_Face' is not - used from multiple threads at the same time. - - - Thai script support has been added to the auto-hinter. - - - Arabic script support has been added to the auto-hinter. - - - Following OpenType version 1.7, advance widths and side bearing - values in CFFs (wrapped in an SFNT structure) are now always - taken from the `hmtx' table. - - - Following OpenType version 1.7, the PostScript font name of a - CFF font (wrapped in an SFNT structure) is now always taken from - the `name' table. This is also true for OpenType Collections - (i.e., TTCs using CFFs subfonts instead of TTFs), where it may - have a significant difference. - - - Fonts natively hinted for ClearType are now supported, properly - handling selector index 3 of the INSTCTRL bytecode instruction. - - - Major improvements to the GX TrueType variation font handling. - - - II. MISCELLANEOUS - - - A new auto-hinter property `warping' can switch on and off the - warping code if this experimental feature is compiled in (by - defining the AF_CONFIG_OPTION_USE_WARPER configuration option; - by default this option is now enabled but warping is switched - off). - - The AF_CONFIG_OPTION_USE_WARPER option itself is an old feature, - available since 2006. Warping only works in `light' - auto-hinting mode. The idea of the code is to slightly scale - and shift a glyph along the non-hinted dimension (which is - usually the horizontal axis) so that as much of its segments are - aligned (more or less) to the grid. To find out a glyph's - optimal scaling and shifting value, various parameter - combinations are tried and scored. - - See file `ftautoh.h' for more; the demo programs `ftdiff', - `ftview', and `ftgrid' can toggle warping with key `w'. - - - Some fields in the `FTC_ImageTypeRec' structure have been - changed from signed to unsigned type, which better reflects the - actual usage. It is also an additional means to protect against - malformed input. - - This change doesn't break the ABI; however, it might cause - compiler warnings. - - - Function `FT_Bitmap_New' has been renamed to `FT_Bitmap_Init', - since this name better reflects its function. For backward - compatibility, the old function name is still available. - - - Function `FT_Get_X11_Font_Format' has been renamed to - `FT_Get_Font_Format', since this name better reflects its - function. For backward compatibility, the old function name is - still available. - - Additionally, the header file macro for this function has been - renamed to `FT_FONT_FORMATS_H' (the old name `FT_XFREE86_H' is - retained for backward compatibility). - - - Various improvements to the `ftgrid' demo program. - - . It can now display GX and MM fonts while interactively - manipulating the axes (with keys F2, F3, and F4). - - . Anti-aliasing rendering modes can now be selected (with keys - F5 and F6). - - . The display of point numbers can be toggled with key `D'. - - - Various improvements to the `ftdump' demo program. - - . It now displays information on MM and GX variation axes. - - . New command line option `-u' makes it output data in utf-8 - encoding. - - - The `ftmulti' demo program can now handle up to six MM or GX - axes. - - -====================================================================== - -CHANGES BETWEEN 2.5.4 and 2.5.5 (2014-Dec-30) - - I. IMPORTANT BUG FIXES - - - Handling of uncompressed PCF files works again (bug introduced - in version 2.5.4). - - -====================================================================== - -CHANGES BETWEEN 2.5.3 and 2.5.4 (2014-Dec-06) - - I. IMPORTANT BUG FIXES - - - A variant of vulnerability CVE-2014-2240 was identified - (cf. https://savannah.nongnu.org/bugs/?43661) and fixed in the - new CFF driver. All users should upgrade. - - - The new auto-hinter code using HarfBuzz crashed for some invalid - fonts. - - - Many fixes to better protect against malformed input. - - - II. IMPORTANT CHANGES - - - Full auto-hinter support of the Devanagari script. - - - Experimental auto-hinter support of the Telugu script. - - - CFF stem darkening behaviour can now be controlled at build time - using the eight macros - - CFF_CONFIG_OPTION_DARKENING_PARAMETER_{X,Y}{1,2,3,4} . - - - Some fields in the `FT_Bitmap' structure have been changed from - signed to unsigned type, which better reflects the actual usage. - It is also an additional means to protect against malformed - input. - - This change doesn't break the ABI; however, it might cause - compiler warnings. - - - III. MISCELLANEOUS - - - Improvements to the auto-hinter's algorithm to recognize stems - and local extrema. - - - Function `FT_Get_SubGlyph_Info' always returned an error even in - case of success. - - - Version 2.5.1 introduced major bugs in the cjk part of the - auto-hinter, which are now fixed. - - - The `FT_Sfnt_Tag' enumeration values have been changed to - uppercase, e.g. `FT_SFNT_HEAD'. The lowercase variants are - deprecated. This is for orthogonality with all other - enumeration (and enumeration-like) values in FreeType. - - - `cmake' now supports builds of FreeType as an OS X framework and - for iOS. - - - Improved project files for vc2010, introducing a property file. - - - The documentation generator for the API reference has been - updated to produce better HTML code (with proper CSS). At the - same time, the documentation got a better structure. - - - The FT_LOAD_BITMAP_CROP flag is obsolete; it is not used by any - driver. - - - The TrueType DELTAP[123] bytecode instructions now work in - subpixel hinting mode as described in the ClearType whitepaper - (i.e., for touched points in the non-subpixel direction). - - - Many small improvements to the internal arithmetic routines. - - -====================================================================== - -CHANGES BETWEEN 2.5.2 and 2.5.3 (2014-Mar-06) - - I. IMPORTANT BUG FIXES - - - A vulnerability (CVE-2014-2240) was identified and fixed in the - new CFF driver (cf. https://savannah.nongnu.org/bugs/?41697). - All users should upgrade. - - - More bug fixes related to correct positioning of composite - glyphs. - - - Many fixes to better protect against malformed input. - - - II. IMPORTANT CHANGES - - - FreeType can now use the HarfBuzz library to greatly improve the - auto-hinting of fonts that use OpenType features: Many glyphs - that are part of such features but don't have cmap entries are - now handled properly, for example small caps or superscripts. - Define the configuration macro FT_CONFIG_OPTION_USE_HARFBUZZ to - activate HarfBuzz support. - - You need HarfBuzz version 0.9.19 or newer. - - Note that HarfBuzz depends on FreeType; this currently causes a - chicken-and-egg problem that can be solved as follows in case - HarfBuzz is not yet installed on your system. - - 1. Compile and install FreeType without the configuration - macro FT_CONFIG_OPTION_USE_HARFBUZZ. - - 2. Compile and install HarfBuzz. - - 3. Define macro FT_CONFIG_OPTION_USE_HARFBUZZ, then compile - and install FreeType again. - - With FreeType's `configure' script the procedure boils down to - configure, build, and install FreeType, then configure, compile, - and install HarfBuzz, then configure, compile, and install - FreeType again (after executing `make distclean'). - - - All libraries FreeType depends on are now checked using the - `pkg-config' configuration files first, followed by alternative - methods. - - - The new value `auto' for the various `--with-XXX' library - options (for example `--with-harfbuzz=auto') makes the - `configure' script automatically link to the libraries it finds. - This is now the default. - - - In case FreeType's `configure' script can't find a library, you - can pass environment variables to circumvent pkg-config, and - those variables have been harmonized as a consequence of the - changes mentioned above: - - LIBZ -> removed; use LIBZ_CFLAGS and LIBZ_LIBS - LIBBZ2 -> removed; use BZIP2_CFLAGS and BZIP2_LIBS - LIBPNG_LDFLAGS -> LIBPNG_LIBS - - `./configure --help' shows all available environment variables. - - - The `freetype-config' script now understands option `--static' - to emit static linking information. - - -====================================================================== - -CHANGES BETWEEN 2.5.1 and 2.5.2 (2013-Dec-08) - - I. IMPORTANT BUG FIXES - - - Improving the display of some broken TrueType fonts introduced a - bug that made FreeType crash on some popular (but not fully - conformant) fonts like `ahronbd.ttf'. - - - Another round of improvements to correct positioning and hinting - of composite glyphs in TrueType fonts. - - - II. MISCELLANEOUS - - - Version 2.5.1 introduced a bug in handling embedded bitmap - strikes of TrueType fonts, causing garbage display under some - circumstances. - - - The `ftgrid' demo program couldn't be compiled in - non-development builds. - - -====================================================================== - -CHANGES BETWEEN 2.5 and 2.5.1 (2013-Nov-25) - - I. IMPORTANT BUG FIXES - - - For some WinFNT files, the last glyph wasn't displayed but - incorrectly marked as invalid. - - - The vertical size of glyphs was incorrectly set after a call to - `FT_GlyphSlot_Embolden', resulting in clipped glyphs. - - - Many fields of the `PCLT' table in SFNT based fonts (if accessed - with `FT_Get_Sfnt_Table') were computed incorrectly. - - - In TrueType fonts, hinting of composite glyphs could sometimes - deliver incorrect positions of components or even distorted - shapes. - - - II. IMPORTANT CHANGES - - - WOFF font format support has been added. - - - The auto-hinter now supports Hebrew. Greek and Cyrillic support - has been improved. - - - Support for the forthcoming `OS/2' SFNT table version 5, as can - be found e.g. in the `Sitka' font family for Windows 8.1. - - - The header file layout has been changed. After installation, - all files are now located in `/include/freetype2'. - - Applications that use (a) `freetype-config' or FreeType's - `pkg-config' file to get the include directory for the compiler, - and (b) the documented way for header inclusion like - - #include - #include FT_FREETYPE_H - ... - - don't need any change to the source code. - - - III. MISCELLANEOUS - - - The stem darkening feature of the new CFF engine can now be - fine-tuned with the new `darkening-parameters' property. - - - `ftgrid' has been updated to toggle various engines with the `H' - key, similar to `ftview' and `ftdiff'. - - - The functionality of `ttdebug' has been greatly enhanced. - - . It now displays twilight, storage, and control value data; key - `T' shows the twilight point table, key `S' the storage data, - and key `C' the control value table. - - . Some keys have been reassigned from lowercase to their - uppercase equivalents; for example `q' to quit the program is - now `Q'. - - . Key `f' finishes the current function. - - . Key `R' restarts the debugger. - - . Keys `b' and `p' set a breakpoint. - - . Key `B' provides a function call backtrace. - - - Better support of ARMv7 and x86_64 processors. - - - Apple's `sbix' color bitmap format is now supported. - - - Improved auto-hinter rendering for many TrueType fonts, - especially in the range 20-40ppem. - - - A new face flag `FT_FACE_FLAG_COLOR' has been added (to be - accessed with the macro `FT_HAS_COLOR'). - - - `FT_Gzip_Uncompress' (modeled after zlib's `uncompress' - function) has been added; this is a by-product of the newly - added WOFF support. - - - Support for a build with `cmake' has been contributed by John - Cary . - - - Support for x64 builds with Visual C++ has been contributed by - Kenneth Miller - - - Manual pages for most demo programs have been added. - - - The GETINFO bytecode instruction for TrueType fonts was buggy if - used to retrieve subpixel hinting information. It was necessary - to set selector bit 6 to get results for selector bits 7-10, - which is wrong. - - - Improved computation of emulated vertical metrics for TrueType - fonts. - - - Fixed horizontal start-up position of vertical phantom points in - TrueType bytecode. - - -====================================================================== - -CHANGES BETWEEN 2.4.12 and 2.5 (2013-Jun-19) - - I. IMPORTANT BUG FIXES - - - The cache manager function `FTC_Manager_Reset' didn't flush the - cache. - - - II. IMPORTANT CHANGES - - - Behdad Esfahbod (on behalf of Google) contributed support for - color embedded bitmaps (eg. color emoji). - - A new load flag, FT_LOAD_COLOR, makes FreeType load color - embedded-bitmaps, following this draft specification - - https://color-emoji.googlecode.com/git/specification/v1.html - - which defines two new SFNT tables, `CBDT' and `CBLC' (named and - modeled after `EBDT' and `EBLC', respectively). The color - bitmaps are stored in the new FT_PIXEL_MODE_BGRA format to - represent BGRA pre-multiplied sRGB images. If PNG support is - available, PNG color images as defined in the same proposed - specification are supported also. - - Note that color bitmaps are converted to grayscale if client - didn't ask for color. - - - As announced in the previous release, the old FreeType CFF - engine is now disabled by default. It can be conditionally - compiled by defining the configuration macro - CFF_CONFIG_OPTION_OLD_ENGINE. - - - As announced in the previous release, all code related to macro - FT_CONFIG_OPTION_OLD_INTERNALS has been removed, thus becoming - obsolete. - - - III. MISCELLANEOUS - - - The property API (`FT_Property_Get' and `FT_Property_Set') is - now declared as stable. - - The exception, however, are the experimental auto-hinter - properties `glyph-to-script-map' and `fallback-script' which are - subject to change in a forthcoming release. - - - `ftview' has been updated to support color embedded bitmaps; it - can be toggled on and off with key `c'. The small cache toggle - is now key `K'. - - - It is now possible to control the version of the TrueType - hinting engine using the new `interpreter-version' property of - the `truetype' module: Versions 35 and 38 (the default) are - supported, which roughly corresponds to disable and enable - subpixel hinting support, respectively. - - In both `ftview' and `ftdiff', switching between the two - versions can be done with key `H'. In the `ftbench' demo - program, command line option `-H' has been extended to activate - the non-default interpreter version. - - - The `ttdebug' program has been further improved. In particular, - it accepts a new command line option `-H' to select the hinting - engine. - - - `ftdump's verbose option has been renamed to `-V'. For all demo - programs, `-v' now shows version information. - - - Another round of TrueType subpixel hinting fixes. - - - The `apinames' tool can now create an import file for NetWare. - - - 64bit compilation of the new CFF engine was buggy. - - - Some fixes to improve robustness in memory-tight situations. - - -====================================================================== - -CHANGES BETWEEN 2.4.11 and 2.4.12 (2013-May-08) - - - We have another CFF parsing and hinting engine! Written by Dave - Arnold , this work has been contributed by - Adobe in collaboration with Google. It is vastly superior to - the old CFF engine, and it will replace it in the next release. - Right now, it is still off by default, and you have to - explicitly select it using the new `hinting-engine' property of - the cff driver: - - ... - #include FT_MODULE_H - #include FT_CFF_DRIVER_H - - FT_Library library; - int engine = FT_CFF_HINTING_ADOBE; - - - ... - FT_Property_Set( library, "cff", "hinting-engine", &engine ); - - The code has a (mature) beta status; we encourage all users to - test it and report any problems. - - In case you want to activate the new CFF engine unconditionally, - apply this patch: - ---- snip --- -diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c -index ebcf189..3f2ce6b 100644 ---- a/src/cff/cffobjs.c -+++ b/src/cff/cffobjs.c -@@ -1056,7 +1056,7 @@ - - - /* set default property values */ -- driver->hinting_engine = FT_CFF_HINTING_FREETYPE; -+ driver->hinting_engine = FT_CFF_HINTING_ADOBE; - driver->no_stem_darkening = FALSE; - - return FT_Err_Ok; ---- snip --- - - - The macro FT_CONFIG_OPTION_OLD_INTERNALS is no longer set by - default. In the next release, we will completely remove the - associated code. Please update your programs in case you are - still using this macro. - - - II. MISCELLANEOUS - - - The (top-level) `configure' script now respects the MAKE - environment variable to specify a `make' binary. For backward - compatibility, GNUMAKE still overrides MAKE, though. - - - The `ftview' and `ftdiff' demo programs have been redesigned, - showing more options permanently on the screen, among other - minor improvements. - - - Using the `H' key, it is now possible to select the CFF engine - in both `ftview' and `ftdiff'. - - - The new command line option `-H' for `ftbench' selects the Adobe - CFF engine. - - - It is now possible to directly select the LCD rendering mode - with the keys `A'-`F' in `ftview'. The key mapping for cycling - through LCD modes has been changed from `K' and `L' to `k' and - `l', and toggling custom LCD filtering is no longer mapped to - key `F' but to key `L'. - - - In `ftdiff', key `x' toggles between layout modes: Either use - the advance width (this is new and now the default) or the - bounding box information to determine line breaks. - - - For all demo tools, the new command line option `-v' shows the - version. - - - For the demo tools with a GUI, the new command line options `-w' - and `-h' select the width and the height of the output window, - respectively. - - - The `ttdebug' program was broken and has been reactivated. Note - that this program is not compiled by default. - - -====================================================================== - -CHANGES BETWEEN 2.4.10 and 2.4.11 (2012-Dec-20) - - I. IMPORTANT BUG FIXES - - - Some vulnerabilities in the BDF implementation have been fixed. - Users of this font format should upgrade. - - - II. IMPORTANT CHANGES - - - Subpixel hinting support has been contributed by Infinality, - based on Greg Hitchcock's whitepaper at - - https://www.microsoft.com/typography/cleartype/truetypecleartype.aspx - - Originally, it was a separate patch available from - - https://web.archive.org/web/20150710073951/http://www.infinality.net:80/blog/ - - and which has been integrated. - - Note that ClearType support is not completely implemented! In - particular, full support for the options `compatible_widths', - `symmetrical_smoothing, and `bgr' (via the GETINFO bytecode - instruction) is missing. - - Activation of subpixel hinting support can be controlled with - the `TT_CONFIG_OPTION_SUBPIXEL_HINTING' configuration option; it - is switched off by default. This feature is still experimental; - we welcome test reports! - - - Support for OpenType collections (OTC) has been added. - - - Pure CFF fonts within an SFNT wrapper are now supported. - - - III. MISCELLANEOUS - - - Minor rendering improvements to the auto-hinter. - - - `FT_GlyphSlot_Oblique' now uses a shear angle of 12°. - - - Experimental support to handle `property modules', for example - to control the behaviour of the auto-hinter. The API consists - of two new functions, `FT_Property_Set' and `FT_Property_Get'. - - The code is still subject to change and should not be used for - production. - - - The `ftdiff' demo program now supports UTF-8 encoded input files - for option `-f'. - - - Using keys `r' and `R', you can now adjust the stroker radius in - the `ftview' demo program. - - - Other, minor fixes and improvements. - - -====================================================================== - -CHANGES BETWEEN 2.4.9 and 2.4.10 (2012-Jun-15) - - I. IMPORTANT BUG FIXES - - - Incremental glyph loading as needed by ghostscript was broken. - - - II. MISCELLANEOUS - - - A new function `FT_Outline_EmboldenXY', contributed by Alexei - Podtelezhnikov. - - - In the `ftview' demo program, key `e' has been replaced with `x' - and `y' to embolden in the horizontal and vertical direction, - respectively. - - - The glyph spacing computation in `FT_GlyphSlot_Embolden' (and - similar code in `ftview') has been improved. - - - Minor improvements to the TrueType bytecode interpreter and - glyph loader, the auto-hinter, and the B/W rasterizer. - - -====================================================================== - -CHANGES BETWEEN 2.4.8 and 2.4.9 (2012-Mar-08) - - I. IMPORTANT BUG FIXES - - - Another round of fixes to better handle invalid fonts. Many of - them are vulnerabilities (see CVE-2012-1126 up to CVE-2012-1144 - and SA48320) so all users should upgrade. - - - II. MISCELLANEOUS - - - The `ENCODING -1 ' format of BDF fonts is now supported. - - - For BDF fonts, support for the whole Unicode encoding range has - been added. - - - Better TTF support for x_ppem != y_ppem. - - - `FT_Get_Advances' sometimes returned bogus values. - - - The demo programs no longer recognize and handle default - suffixes; you now have to always specify the complete font name. - - - Better rendering and LCD mode cycling added to `ftview'. - - -====================================================================== - -CHANGES BETWEEN 2.4.7 and 2.4.8 (2011-Nov-14) - - I. IMPORTANT BUG FIXES - - - Some vulnerabilities in handling CID-keyed PostScript fonts have - been fixed; see CVE-2011-3439. - - - II. MISCELLANEOUS - - - Chris Liddell contributed a new API, `FT_Get_PS_Font_Value', to - retrieve most of the dictionary keys in Type 1 fonts. - - -====================================================================== - -CHANGES BETWEEN 2.4.6 and 2.4.7 (2011-Oct-18) - - I. IMPORTANT BUG FIXES - - - Some vulnerabilities in handling Type 1 fonts have been fixed; - see CVE-2011-3256. - - - II. MISCELLANEOUS - - - FreeType now properly handles ZapfDingbats glyph names while - constructing a Unicode character map (for fonts which don't have - one). - - -====================================================================== - -CHANGES BETWEEN 2.4.5 and 2.4.6 (2011-Jul-29) - - I. IMPORTANT BUG FIXES - - - For TrueType based fonts, the ascender and descender values were - incorrect sometimes (off by a pixel if the ppem value was not a - multiple of 5). Depending on the use you might now experience - a different layout; the change should result in better, more - consistent line spacing. - - - Fix CVE-2011-0226 which causes a vulnerability while handling - Type 1 fonts. - - - BDF fonts containing glyphs with negative values for ENCODING - were incorrectly rejected. This bug has been introduced in - FreeType version 2.2.0. - - - David Bevan contributed a major revision of the FreeType stroker - code: - - . The behaviour of FT_STROKER_LINEJOIN_BEVEL has been corrected. - - . A new line join style, FT_STROKER_LINEJOIN_MITER_FIXED, has - been introduced to support PostScript and PDF miter joins. - - . FT_STROKER_LINEJOIN_MITER_VARIABLE has been introduced as an - alias for FT_STROKER_LINEJOIN_MITER. - - . Various stroking glitches has been fixed. - - - II. MISCELLANEOUS - - - SFNT bitmap fonts which contain an outline glyph for `.notdef' - only no longer set the FT_FACE_FLAG_SCALABLE flag. - - -====================================================================== - -CHANGES BETWEEN 2.4.4 and 2.4.5 (2011-Jun-25) - - I. IMPORTANT BUG FIXES - - - A rendering regression for second-order Bézier curves has been - fixed, introduced in 2.4.3. - - - II. IMPORTANT CHANGES - - - If autohinting is not explicitly disabled, FreeType now uses - the autohinter if a TrueType based font doesn't contain native - hints. - - - The load flag FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH has been made - redundant and is simply ignored; this means that FreeType now - ignores the global advance width value in TrueType fonts. - - - III. MISCELLANEOUS - - - `FT_Sfnt_Table_Info' can now return the number of SFNT tables of - a font. - - - Support for PCF files compressed with bzip2 has been contributed - by Joel Klinghed. To make this work, the OS must provide a - bzip2 library. - - - Bradley Grainger contributed project and solution files in - Visual Studio 2010 format. - - - Again some fixes to better handle broken fonts. - - - Some improvements to the B/W rasterizer. - - - Fixes to the cache module to improve robustness. - - - Just Fill Bugs contributed (experimental) code to compute blue - zones for CJK Ideographs, improving the alignment of horizontal - stems at the top or bottom edges. - - - The `ftgrid' demo program can now display autohinter segments, - to be toggled on and off with key `s'. - - -====================================================================== - -CHANGES BETWEEN 2.4.3 and 2.4.4 (2010-Nov-28) - - I. IMPORTANT BUG FIXES - - - UVS support (TrueType/OpenType cmap format 14) support is fixed. - This regression has been introduced in version 2.4.0. - - - II. MISCELLANEOUS - - - Detect tricky fonts (e.g. MingLiU) by the lengths and checksums - of Type42-persistent subtables (`cvt ', `fpgm', and `prep') when - a TrueType font without family name is given. The previous fix, - introduced in 2.4.3, was too rigorous, causing many subsetted - fonts (mainly from PDF files) displayed badly because FreeType - forced rendering with the TrueType bytecode engine instead of - the autohinter. - - - Better support for 64bit platforms. - - - More fixes to improve handling of broken fonts. - - -====================================================================== - -CHANGES BETWEEN 2.4.2 and 2.4.3 (2010-Oct-03) - - I. IMPORTANT BUG FIXES - - - Fix rendering of certain cubic, S-shaped arcs. This regression - has been introduced in version 2.4.0. - - - II. MISCELLANEOUS - - - To fix the above mentioned rendering issue, a new spline - flattening algorithm has been introduced which speeds up both - conic and cubic arcs. - - - Handling of broken fonts has been further improved. - - -====================================================================== - -CHANGES BETWEEN 2.4.1 and 2.4.2 (2010-Aug-06) - - I. IMPORTANT BUG FIXES - - - A stack overflow in CFF Type2 CharStrings interpreter is fixed. - - - Handling Type 42 font deallocation was broken; additionally, the - library is now more robust against malformed Type 42 fonts. - - - II. MISCELLANEOUS - - - Two new functions, `FT_Reference_Library' (in FT_MODULE_H) and - `FT_Reference_Face' (in FT_FREETYPE_H), have been added to - simplify life-cycle management. A counter gets initialized to 1 - at the time an FT_Library (or FT_Face) structure is created. - The two new functions increment the respective counter. - `FT_Done_Library' and `FT_Done_Face' then only destroy a library - or face if the counter is 1, otherwise they simply decrement the - counter. - - -====================================================================== - -CHANGES BETWEEN 2.4.0 and 2.4.1 (2010-Jul-18) - - I. IMPORTANT CHANGES - - - A serious bug in the CFF font module prevented display of many - glyphs in CFF fonts like `MinionPro-Regular.otf'. - - -====================================================================== - -CHANGES BETWEEN 2.3.12 and 2.4.0 (2010-Jul-12) - - I. IMPORTANT CHANGES - - - Since May 2010, all patents regarding the TrueType bytecode - interpreter have expired worldwide. Consequently, we now define - TT_CONFIG_OPTION_BYTECODE_INTERPRETER by default (and undefine - TT_CONFIG_OPTION_UNPATENTED_HINTING). - - - A new function `FT_Library_SetLcdFilterWeights' is available to - adjust the filter weights set by `FT_Library_SetLcdFilter'. - - - II. MISCELLANEOUS - - - Thanks to many reports from Robert ÅšwiÄ™cki, FreeType's stability - in handling broken or damaged fonts is much improved. - - - Support for LCD filter control has been added to the demo - programs `ftdiff' and `ftview'. - - -====================================================================== - -CHANGES BETWEEN 2.3.11 and 2.3.12 - - I. IMPORTANT CHANGES - - - For `FT_Open_Face', new parameters are available to ignore - preferred family names: FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY and - FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY. - - - II. MISCELLANEOUS - - - Support for incremental font loading (controlled with the - FT_CONFIG_OPTION_INCREMENTAL macro) is now active by default. - - - Better support for vertical metrics. - - - Various minor bug fixes. - - -====================================================================== - -CHANGES BETWEEN 2.3.10 and 2.3.11 - - I. IMPORTANT BUG FIXES - - - Version 2.3.10 broke PCF support. - - -====================================================================== - -CHANGES BETWEEN 2.3.10 and 2.3.9 - - I. IMPORTANT BUG FIXES - - - If all ASCII digits in a font have the same (unscaled) width, - the autohinter respects this and won't change it. - - - TrueType fonts are now rasterized correctly if the horizontal - and vertical resolution differ. - - - Type 1 fonts are now handled with increased precision internally - to avoid serious rounding issues if non-integral coordinates are - encountered. - - - Horizontally condensed CFF fonts (using the font matrix) were - rendered incorrectly. This bug has been introduced after - release 2.3.5. - - - II. IMPORTANT CHANGES - - - Support for the SFNT cmap 13 table format (as defined by the new - OpenType 1.6 specification) has been added. - - - B/W rasterization of well-hinted TrueType fonts at small sizes - has been greatly improved. - - - Calculation of vertical metrics in OpenType fonts has been - improved. - - - III. MISCELLANEOUS - - - It is now possible to change the emboldening factor in the - `ftview' demo program with keys `e' and `E'. - - - It is now possible to change the slant value in the `ftview' - demo program with keys `s' and `S'. - - - The 5-levels grayscale mode of the `ftraster' module (which - FreeType doesn't use by default) was broken since version 2.3.0. - - - Compilation of the `ftgrays' and `ftraster' modules was broken - in stand-alone mode. - - - Various fixes for compilation on 64bit and 16bit architectures. - - -====================================================================== - -CHANGES BETWEEN 2.3.9 and 2.3.8 - - I. IMPORTANT BUG FIXES - - - Very unfortunately, FreeType 2.3.8 contained a change that broke - its official ABI. The end result is that programs compiled - against previous versions of the library, but dynamically linked - to 2.3.8 can experience memory corruption if they call the - `FT_Get_PS_Font_Info' function. - - We recommend all users to upgrade to 2.3.9 as soon as possible, - or to downgrade to a previous release of the library if this is - not an option. - - The origin of the bug is that a new field was added to the - publicly defined `PS_FontInfoRec' structure. Unfortunately, - objects of this type can be stack or heap allocated by callers - of `FT_Get_PS_Font_Info', resulting in a memory buffer - overwrite with its implementation in 2.3.8. - - If you want to know whether your code is vulnerable to this - issue, simply search for the substrings `PS_FontInfo' and - `PS_Font_Info' in your source code. If none is found, your code - is safe and is not affected. - - The FreeType team apologizes for the problem. - - - The POSIX support of MacOS resource-fork fonts (Suitcase fonts - and LaserWriter Type1 PostScript fonts) was broken in 2.3.8. If - FreeType2 is built without Carbon framework, these fonts are not - handled correctly. Version 2.3.7 didn't have this bug. - - - `FT_Get_Advance' (and `FT_Get_Advances') returned bad values for - almost all font formats except TrueType fonts. - - - Fix a bug in the SFNT kerning table loader/parser which could - crash the engine if certain malformed tables were encountered. - - - Composite SFNT bitmaps are now handled correctly. - - - II. IMPORTANT CHANGES - - - The new functions `FT_Get_CID_Is_Internally_CID_keyed' and - `FT_Get_CID_From_Glyph_Index' can be used to access CID-keyed - CFF fonts via CID values. This code has been contributed by - Michael Toftdal. - - - III. MISCELLANEOUS - - - `FT_Outline_Get_InsideBorder' returns FT_STROKER_BORDER_RIGHT - for empty outlines. This was incorrectly documented. - - - The `ftview' demo program now supports UTF-8 encoded strings. - - -====================================================================== - -CHANGES BETWEEN 2.3.8 and 2.3.7 - - I. IMPORTANT BUG FIXES - - - CID-keyed fonts in an SFNT wrapper were not handled correctly. - - - The smooth renderer produced truncated images (on the right) for - outline parts with negative horizontal values. Most fonts don't - contain outlines left to the y coordinate axis, but the effect - was very noticeable for outlines processed with FT_Glyph_Stroke, - using thick strokes. - - - `FT_Get_TrueType_Engine_Type' returned a wrong value if both - configuration macros TT_CONFIG_OPTION_BYTECODE_INTERPRETER and - TT_CONFIG_OPTION_UNPATENTED_HINTING were defined. - - - The `face_index' field in the `FT_Face' structure wasn't - initialized properly after calling FT_Open_Face and friends with - a positive face index for CFFs, WinFNTs, and, most importantly, - for TrueType Collections (TTCs). - - - II. IMPORTANT CHANGES - - - Rudimentary support for Type 1 fonts and CID-keyed Type 1 fonts - in an SFNT wrapper has been added -- such fonts are used on the - Mac. The core SFNT tables `TYP1' and `CID ' are passed to the - PS Type 1 and CID-keyed PS font drivers; other tables (`ALMX', - `BBOX', etc.) are not supported yet. - - - A new interface to extract advance values of glyphs without - loading their outlines has been added. The functions are called - `FT_Get_Advance' and `FT_Get_Advances'; they are defined in file - `ftadvanc.h' (to be accessed as FT_ADVANCES_H). - - - A new function `FT_Get_FSType_Flags' (in FT_FREETYPE_H) has been - contributed by David Bevan to access the embedding and - subsetting restriction information of fonts. - - - III. MISCELLANEOUS - - - FT_MulFix is now an inlined function; by default, assembler code - is provided for x86 and ARM. See FT_CONFIG_OPTION_INLINE_MULFIX - and FT_CONFIG_OPTION_NO_ASSEMBLER (in ftoption.h) for more. - - - The handling of `tricky' fonts (that is, fonts which don't work - with the autohinter, needing the font format's hinting engine) - has been generalized and changed slightly: - - . A new face flag FT_FACE_FLAG_TRICKY indicates that the font - format's hinting engine is necessary for correct rendering. - The macro FT_IS_TRICKY can be used to check this flag. - - . FT_LOAD_NO_HINTING is now ignored for tricky fonts. To really - force raw loading of such fonts (without hinting), both - FT_LOAD_NO_HINTING and FT_LOAD_NO_AUTOHINT must be used -- - this is something which you probably never want to do. - - . Tricky TrueType fonts always use the bytecode interpreter, - either the patented or unpatented version. - - - The function `FT_GlyphSlot_Own_Bitmap' has been moved from - FT_SYNTHESIS_H to FT_BITMAP_H; it is now part of the `official' - API. (The functions in FT_SYNTHESIS_H are still subject to - change, however.) - - - In the `ftdiff' demo program you can now toggle the use of - FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH with key `a'. - - -====================================================================== - -CHANGES BETWEEN 2.3.7 and 2.3.6 - - I. IMPORTANT BUG FIXES - - - If the library was compiled on an i386 platform using gcc, and - compiler option -O3 was given, `FT_MulFix' sometimes returned - incorrect results which could have caused problems with - `FT_Request_Metrics' and `FT_Select_Metrics', returning an - incorrect descender size. - - - Pure CFFs without subfonts were scaled incorrectly if the font - matrix was non-standard. This bug has been introduced in - version 2.3.6. - - - The `style_name' field in the `FT_FaceRec' structure often - contained a wrong value for Type 1 fonts. This misbehaviour - has been introduced in version 2.3.6 while trying to fix - another problem. [Note, however, that this value is - informative only since the used algorithm to extract it is - very simplistic.] - - - II. IMPORTANT CHANGES - - - Two new macros, FT_OUTLINE_SMART_DROPOUTS and - FT_OUTLINE_EXCLUDE_STUBS, have been introduced. Together with - FT_OUTLINE_IGNORE_DROPOUTS (which was ignored previously) it is - now possible to control the dropout mode of the `raster' module - (for B&W rasterization), using the `flags' field in the - `FT_Outline' structure. - - - The TrueType bytecode interpreter now passes the dropout mode to - the B&W rasterizer. This greatly increases the output for small - ppem values of many fonts like `pala.ttf'. - - -====================================================================== - -CHANGES BETWEEN 2.3.6 and 2.3.5 - - I. IMPORTANT BUG FIXES - - - A bunch of potential security problems have been found. All - users should update. - - - Microsoft Unicode cmaps in TrueType fonts are now always - preferred over Apple cmaps. This is not a bug per se, but there - exist some buggy fonts created for MS which have broken Apple - cmaps. This affects only the automatic selection of FreeType; - it's always possible to manually select an Apple Unicode cmap if - desired. - - - Many bug fixes to the TrueType bytecode interpreter. - - - Improved Mac support. - - - Subsetted CID-keyed CFFs are now supported correctly. - - - CID-keyed CFFs with subfonts which are scaled in a non-standard - way are now handled correctly. - - - A call to FT_Open_Face with `face_index' < 0 crashed FreeType if - the font was a Windows (bitmap) FNT/FON. - - - II. IMPORTANT CHANGES - - - The new function `FT_Get_CID_Registry_Ordering_Supplement' gives - access to those fields in a CID-keyed font. The code has been - contributed by Derek Clegg. - - - George Williams contributed code to validate the new `MATH' - OpenType table (within the `otvalid' module). The `ftvalid' - demo program has been extended accordingly. - - - An API for cmap 14 support (for Unicode Variant Selectors, UVS) - has been contributed by George Williams. - - - A new face flag FT_FACE_FLAG_CID_KEYED has been added, together - with a macro FT_IS_CID_KEYED which evaluates to 1 if the font is - CID-keyed. - - - III. MISCELLANEOUS - - - Build support for symbian has been contributed. - - - Better WGL4 glyph name support, contributed by Sergey Tolstov. - - - Debugging output of the various FT_TRACEX macros is now sent to - stderr. - - - The `ftview' demo program now provides artificial slanting too. - - - The `ftvalid' demo program has a new option `-f' to select the - font index. - - -====================================================================== - -CHANGES BETWEEN 2.3.5 and 2.3.4 - - I. IMPORTANT BUG FIXES - - - Some subglyphs in TrueType fonts were handled incorrectly due to - a missing graphics state reinitialization. - - - Large .Z files (as distributed with some X11 packages) weren't - handled correctly, making FreeType increase the heap stack in an - endless loop. - - - A large number of bugs have been fixed to avoid crashes and - endless loops with invalid fonts. - - - II. IMPORTANT CHANGES - - - The two new cache functions `FTC_ImageCache_LookupScaler' and - `FTC_SBit_Cache_LookupScaler' have been added to allow lookup of - glyphs using an `FTC_Scaler' object; this makes it possible to - use fractional pixel sizes in the cache. The demo programs have - been updated accordingly to use this feature. - - - A new API `FT_Get_CMap_Format' has been added to get the cmap - format of a TrueType font. This is useful in handling PDF - files. The code has been contributed by Derek Clegg. - - - The auto-hinter now produces better output by default for - non-Latin scripts like Indic. This was done by using the CJK - hinting module as the default instead of the Latin one. Thanks - to Rahul Bhalerao for this suggestion. - - - A new API `FT_Face_CheckTrueTypePatents' has been added to find - out whether a given TrueType font uses patented bytecode - instructions. The `ft2demos' bundle contains a new program - called `ftpatchk' which demonstrates its usage. - - - A new API `FT_Face_SetUnpatentedHinting' has been added to - enable or disable the unpatented hinter. - - - Support for Windows FON files in PE format has been contributed - by Dmitry Timoshkov. - - - III. MISCELLANEOUS - - - Vincent Richomme contributed Visual C++ project files for Pocket - PCs. - - -====================================================================== - -CHANGES BETWEEN 2.3.4 and 2.3.3 - - I. IMPORTANT BUG FIXES - - - A serious bug in the handling of bitmap fonts (and bitmap - strikes of outline fonts) has been introduced in 2.3.3. - - -====================================================================== - -CHANGES BETWEEN 2.3.3 and 2.3.2 - - I. IMPORTANT BUG FIXES - - - Remove a serious regression in the TrueType bytecode interpreter - that was introduced in version 2.3.2. Note that this does not - disable the improvements introduced to the interpreter in - version 2.3.2, only some ill cases that occurred with certain - fonts (though a few popular ones). - - - The auto-hinter now ignores single-point contours for computing - blue zones. This bug created `wavy' baselines when rendering - text with various fonts that use these contours to model - mark-attach points (these are points that are never rasterized - and are placed outside of the glyph's real outline). - - - The `rsb_delta' and `lsb_delta' glyph slot fields are now set to - zero for mono-spaced fonts. Otherwise code that uses them would - essentially ruin the fixed-advance property. - - - Fix CVE-2007-1351 which can cause an integer overflow while - parsing BDF fonts, leading to a potentially exploitable heap - overflow condition. - - - II. MISCELLANEOUS - - - Fixed compilation issues on some 64-bit platforms (see ChangeLog - for details). - - - A new demo program `ftdiff' has been added to compare TrueType - hinting, FreeType's auto hinting, and rendering without hinting - in three columns. - - -====================================================================== - -CHANGES BETWEEN 2.3.2 and 2.3.1 - - I. IMPORTANT BUG FIXES - - - FreeType returned incorrect kerning information from TrueType - fonts when the bytecode interpreter was enabled. This happened - due to a typo introduced in version 2.3.0. - - - Negative kerning values from PFM files are now reported - correctly (they were read as 16-bit unsigned values from the - file). - - - Fixed a small memory leak when `FT_Init_FreeType' failed for - some reason. - - - The Postscript hinter placed and sized very thin and ghost stems - incorrectly. - - - The TrueType bytecode interpreter has been fixed to get rid of - most of the rare differences seen in comparison to the Windows - font loader. - - - II. IMPORTANT CHANGES - - - The auto-hinter now better deals with serifs and corner cases - (e.g., glyph '9' in Arial at 9pt, 96dpi). It also improves - spacing adjustments and doesn't change widths for non-spacing - glyphs. - - - Many Mac-specific functions are deprecated (but still - available); modern replacements have been provided for them. - See the documentation in file `ftmac.h'. - - -====================================================================== - -CHANGES BETWEEN 2.3.1 and 2.3.0 - - I. IMPORTANT BUG FIXES - - - The TrueType interpreter sometimes returned incorrect horizontal - metrics due to a bug in the handling of the SHZ instruction. - - - A typo in a security check introduced after version 2.2.1 - prevented FreeType to render some glyphs in CFF fonts. - - -====================================================================== - -CHANGES BETWEEN 2.3.0 and 2.2.1 - - I. IMPORTANT BUG FIXES - - - The PCF font loader is now much more robust while loading - malformed font files. - - - Various memory leaks have been found and fixed. - - - The TrueType name loader now deals properly with some fonts that - encode their names in UTF-16 (the specification was vague, and - the code incorrectly assumed UCS-4). - - - Fixed the TrueType bytecode loader to deal properly with subtle - monochrome/gray issues when scaling the CVT. Some fonts - exhibited bad rendering artifacts otherwise. - - - `FT_GlyphSlot_Embolden' now supports vertical layouts correctly - (it mangled the vertical advance height). - - - Fixed byte endian issues of `ftmac.c' to support Mac OS X on - i386. - - - The PFR font loader no longer erroneously tags font files - without any outlines as FT_FACE_FLAG_SCALABLE. - - - II. NEW API FUNCTIONS - - - `FT_Library_SetLcdFilter' allows you to select a special filter - to be applied to the bitmaps generated by `FT_Render_Glyph' if - one of the FT_RENDER_MODE_LCD and FT_RENDER_MODE_LCD_V modes has - been selected. This filter is used to reduce color fringes; - several settings are available through the FT_LCD_FILTER_XXX - enumeration. - - Its declaration and documentation can be found in file - `include/freetype/ftlcdfil.h' (to be accessed with macro - FT_LCD_FILTER_H). - - *IMPORTANT*: This function returns an error - (FT_Err_Unimplemented_Feature) in default builds of the library - for patent reasons. See below. - - - `FT_Get_Gasp' allows you to query the flags of the TrueType - `gasp' table for a given character pixel size. This is useful - to duplicate the text rendering of MS Windows when the native - bytecode interpreter is enabled (which isn't the default for - other patent reasons). - - Its declaration and documentation can be found in file - `include/freetype/ftgasp.h' (to be accessed with macro - FT_GASP_H). - - - III. IMPORTANT CHANGES - - - The auto-hinter has been tuned a lot to improve its results with - serif fonts, resulting in much better font rendering of many web - pages. - - - The unpatented hinter is now part of the default build of the - library; we have added code to automatically support `tricky' - fonts that need it. - - This means that FreeType should `just work' with certain Asian - fonts, like MingLiU, which cannot properly be loaded without a - bytecode interpreter, but which fortunately do not use any of - the patented bytecode opcodes. We detect these fonts by name, - so please report any font file that doesn't seem to work with - FreeType, and we shall do what we can to support it in a next - release. - - Note that the API hasn't changed, so you can still force - unpatented hinting with a special parameter to `FT_Open_Face' as - well. This might be useful in same cases; for example, a PDF - reader might present a user option to activate it to deal with - certain `tricky' embedded fonts which cannot be clearly - identified. - - If you are a developer for embedded systems, you might want to - *disable* the feature to save code space by undefining - TT_CONFIG_OPTION_UNPATENTED_HINTING in file `ftoption.h'. - - - LCD-optimized rendering is now *disabled* in all default builds - of the library, mainly due to patent issues. For more - information see: - - https://lists.gnu.org/archive/html/freetype/2006-09/msg00064.html - - A new configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING - has been introduced in `ftoption.h'; manually define it in this - file if you want to re-enable the feature. - - The change only affects the implementation, not the FreeType - API. This means that clients don't need to be modified, because - the library still generates LCD decimated bitmaps, but with the - added constraint that R=G=B on each triplet. - - The displayed result should be equal to normal anti-aliased - rendering. - - Additionally, if FT_CONFIG_OPTION_SUBPIXEL_RENDERING is not - defined, the new `FT_Library_SetLcdFilter' function returns the - FT_Err_Unimplemented_Feature error code. - - - Some computation bugs in the TrueType bytecode interpreter were - found, which allow us to get rid of very subtle and rare - differences we had experienced with the Windows renderer. - - - It is now possible to cross-compile the library easily. See the - file `docs/INSTALL.CROSS' for details. - - - The file `src/base/ftmac.c' now contains code for Mac OS X only; - its deprecated function `FT_GetFile_From_Mac_Font_Name' always - returns an error even if the QuickDraw framework is available. - The previous version has been moved to `builds/mac/ftmac.c'. - - Selecting configure option `--with-quickdraw-carbon' makes the - build process use the original `ftmac.c' file instead of the Mac - OS X-only version. - - - IV. MISCELLANEOUS - - - Various performance and memory footprint optimizations have been - performed on the TrueType and CFF font loaders, sometimes with - very drastic benefits (e.g., the TrueType loader is now about - 25% faster; FreeType should use less heap memory under nearly - all conditions). - - - The anti-aliased rasterizer has been optimized and is now 15% to - 25% percent faster than in previous versions, depending on - content. - - - The Type 1 loader has been improved; as an example, it now skips - top-level dictionaries properly. - - - Better support for Mac fonts on POSIX systems, plus compilation - fixes for Mac OS X on ppc64 where `ftmac.c' cannot be built. - - - Configuration without `--with-old-mac-fonts' does not include - `ftmac.c' (this was the behaviour in FreeType version 2.1.10). - - - The TrueTypeGX validator (gxvalid) checks the order of glyph IDs - in the kern table. - - -====================================================================== - -CHANGES BETWEEN 2.2.1 and 2.2 - - I. IMPORTANT BUG FIXES - - - Various integer overflows have been fixed. - - - PFB fonts with MacOS resource fork weren't handled correctly on - non-MacOS platforms. - - -====================================================================== - -CHANGES BETWEEN 2.2 and 2.1.10 - -(not released officially) - - I. IMPORTANT BUG FIXES - - - Vertical metrics for SFNT fonts were incorrect sometimes. - - - The FT_HAS_KERNING macro always returned 0. - - - CFF OpenType fonts didn't return correct vertical metrics for - glyphs with outlines. - - - If FreeType was compiled without hinters, all font formats based - on PS outlines weren't scaled correctly. - - - II. IMPORTANT CHANGES - - - Version 2.2 no longer exposes its internals, that is, the header - files located in the `include/freetype/internal' directory of - the source package are not copied anymore by the `make install' - command. Consequently, a number of rogue clients which directly - access FreeType's internal functions and structures won't - compile without modification. - - We provide patches for most of those rogue clients. See the - following page for more information: - - https://www.freetype.org/freetype2/patches/rogue-patches.html - - Note that, as a convenience to our Unix desktop users, version - 2.2 is *binary* compatible with FreeType 2.1.7, which means that - installing this release on an existing distribution shall not - break any working desktop. - - - FreeType's build mechanism has been redesigned. With GNU make - it is now sufficient in most cases to edit two files: - `modules.cfg', to select the library components, and the - configuration file `include/freetype/config/ftoption.h' (which - can be copied to the objects directory). Removing unused module - directories to prevent its compilation and editing - `include/freetype/config/ftmodule.h' is no longer necessary. - - - The LIGHT hinting algorithm produces more pleasant results. - Also, using the FT_LOAD_TARGET_LIGHT flags within FT_Load_Glyph - always forces auto-hinting, as a special exception. This allows - you to experiment with it even if you have enabled the TrueType - bytecode interpreter in your build. - - - The auto hinter now employs a new algorithm for CJK fonts, based - on Akito Hirai's patch. Note that this only works for fonts - with a Unicode charmap at the moment. - - - The following callback function types have changed slightly (by - adding the `const' keyword where appropriate): - - FT_Outline_MoveToFunc - FT_Outline_LineToFunc - FT_Outline_ConicToFunc - FT_Outline_CubicToFunc - FT_SpanFunc - FT_Raster_RenderFunc - - FT_Glyph_TransformFunc - FT_Renderer_RenderFunc - FT_Renderer_TransformFunc - - Note that this doesn't affect binary backward compatibility. - - - On MacOS, new APIs have been added as replacements for legacy - APIs: `FT_New_Face_From_FSRef' for `FT_New_Face_From_FSSpec', - and `FT_GetFile_From_Mac_ATS_Name' for - `FT_GetFile_From_Mac_Name'. Legacy APIs are still available, if - FreeType is built without disabling them. - - - A new API `FT_Select_Size' has been added to select a bitmap - strike by its index. Code using other functions to select - bitmap strikes should be updated to use this function. - - - A new API `FT_Get_SubGlyph_Info' has been added to retrieve - subglyph data. This can be used by rogue clients which used to - access the internal headers to get the corresponding data. - - - In 2.1.10, the behaviour of `FT_Set_Pixel_Sizes' was changed for - BDF/PCF fonts, and only for them. This causes inconsistency. - In this release, we undo the change. The intent of the change - in 2.1.10 is to allow size selection through real dimensions, - which can now be done through `FT_Request_Size'. - - - Some security issues were discovered and fixed in the CFF and - Type 1 loader, causing crashes of FreeType by malformed font - files. - - - III. MISCELLANEOUS - - - The documentation for FT_LOAD_TARGET_XXX and FT_RENDER_MODE_XXX - values now better reflects its usage and differences: One set is - used to specify the hinting algorithm, the other to specify the - pixel rendering mode. - - - `FT_New_Face' and `FT_New_Face_From_FSSpec' in ftmac.c have been - changed to count supported scalable faces (sfnt, LWFN) only, and - to return the number of available faces via face->num_faces. - Unsupported bitmap faces (fbit, NFNT) are ignored. - - - builds/unix/configure has been improved for MacOS X. It now - automatically checks available functions in Carbon library, and - prepare to use newest functions by default. Options to specify - the dependencies of each Carbon APIs (FSSpec, FSRef, old/new - QuickDraw, ATS) are available too. By manual disabling of all - QuickDraw functionality, FreeType can be built without - `deprecated function' warnings on MacOS 10.4.x, but - FT_GetFile_Mac_Name in ftmac.c then is changed to a dummy - function, and returns an `unimplemented' error. For details see - builds/mac/README. - - - SFNT cmap handling has been improved, mainly to run much faster - with CJK fonts. - - - A new function `FT_Get_TrueType_Engine_Type (declared in - `FT_MODULE_H') is provided to determine the status of the - TrueType bytecode interpreter compiled into the library - (patented, unpatented, unimplemented). - - - Vertical metrics of glyphs are synthesized if the font does not - provide such information. You can tell whether the metrics are - synthesized or not by checking the FT_FACE_FLAG_VERTICAL flag of - the face. - - - The demo programs `ftview' and `ftstring' have been rewritten - for better readability. `ftview' has a new switch `-p' to test - FT_New_Memory_Face (instead of FT_New_Face). - - - FreeType now honours bit 1 in the `head' table of TrueType fonts - (meaning `left sidebearing point at x=0'). This helps with some - buggy fonts. - - - Rudimentary support for Adobe's new `SING Glyphlet' format. See - - https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5148.SING_Tutorial.pdf - - for more information. - - - The `ftdump' program from the `ft2demos' bundle now shows some - information about charmaps. It also supports a new switch `-v' - to increase verbosity. - - - Better AFM support. This includes track kerning support. - - -====================================================================== - -CHANGES BETWEEN 2.1.10 and 2.1.9 - - I. IMPORTANT BUG FIXES - - - The size comparison for BDF and PCF files could fail sometimes. - - - Some CFF files were still not loaded correctly. Patch from - Derek Noonburg. - - - The stroker still had some serious bugs. - - - Boris Letocha fixed a bug in the TrueType interpreter: The - NPUSHW instruction wasn't skipped correctly in IF clauses. Some - fonts like `Helvetica 75 Bold' failed. - - - Another serious bug in handling TrueType hints caused many - distortions. It has been introduced in version 2.1.8, and it is - highly recommended to upgrade. - - - FreeType didn't properly parse empty Type 1 glyphs. - - - An unbound dynamic buffer growth was fixed in the PFR loader. - - - Several bugs have been fixed in the cache sub-system. - - - FreeType behaved incorrectly when resizing two distinct but very - close character pixel sizes through `FT_Set_Char_Size' (Savannah - bug #12263). - - - The auto-hinter didn't work properly for fonts without a Unicode - charmap -- it even refused to load the glyphs. - - - II. IMPORTANT CHANGES - - - Many fixes have been applied to drastically reduce the amount of - heap memory used by FreeType, especially when using - memory-mapped font files (which is the default on Unix systems - which support them). - - - The auto-hinter has been replaced with a new module, called the - `auto-fitter'. It consumes less memory than its predecessor, - and it is prepared to support non-latin scripts better in next - releases. - - - George Williams contributed code to read kerning data from PFM - files. - - - FreeType now uses the TT_NAME_ID_PREFERRED_FAMILY and - TT_NAME_ID_PREFERRED_SUBFAMILY strings (if available) for - setting family and style in SFNT fonts (patch from Kornfeld - Eliyahu Peter). - - - A new API `FT_Sfnt_Table_Info' (in FT_TRUETYPE_TABLES_H) has - been added to retrieve name and size information of SFNT tables. - - - A new API `FT_OpenType_Validate' (in FT_OPENTYPE_VALIDATE_H) has - been added to validate OpenType tables (BASE, GDEF, GPOS, GSUB, - JSTF). After validation it is no longer necessary to check - for errors in those tables while accessing them. - - Note that this module might be moved to another library in the - future to avoid a tight dependency between FreeType and the - OpenType specification. - - - A new API in FT_BITMAP_H (`FT_Bitmap_New', `FT_Bitmap_Convert', - `FT_Bitmap_Copy', `FT_Bitmap_Embolden', `FT_Bitmap_Done') has - been added. Its use is to convert an FT_Bitmap structure in - 1bpp, 2bpp, 4bpp, or 8bpp format into another 8bpp FT_Bitmap, - probably using a different pitch, and to further manipulate it. - - - A new API `FT_Outline_Embolden' (in FT_OUTLINE_H) gives finer - control how outlines are emboldened. - - - `FT_GlyphSlot_Embolden' (in FT_SYNTHESIS_H) now handles bitmaps - also (code contributed by Chia I Wu). Note that this function - is still experimental and may be replaced with a better API. - - - The method how BDF and PCF bitmap fonts are accessed has been - refined. Formerly, FT_Set_Pixel_Sizes and FT_Set_Char_Size - were synonyms in FreeType's BDF and PCF interface. This has - changed now. FT_Set_Pixel_Sizes should be used to select the - actual font dimensions (the `strike', which is the sum of the - `FONT_ASCENT' and `FONT_DESCENT' properties), while - FT_Set_Char_Size selects the `nominal' size (the `PIXELSIZE' - property). In both functions, the width parameter is ignored. - - - III. MISCELLANEOUS - - - The BDF driver no longer converts all returned bitmaps with a - depth of 2bpp or 4bpp to a depth of 8bpp. The documentation has - not mentioned this explicitly, but implementors might have - relied on this after looking into the source files. - - - A new option `--ftversion' has been added to freetype-config to - return the FreeType version. - - - The memory debugger has been updated to dump allocation - statistics on all allocation sources in the library. This is - useful to spot greedy allocations when loading and processing - fonts. - - - We removed a huge array of constant pointers to constant strings - in the `psnames' module. The problem was that compilations in - PIC mode (i.e., when generating a Unix shared object/dll) put - the array into the non-shared writable section of the library - since absolute pointers are not relocatable by nature. - - This reduces the memory consumption by approximately 16KByte per - process linked to FreeType. We now also store the array in a - compressed form (as a trie) which saves about 20KByte of code as - well. - - - Kirill Smelkov provided patches to make src/raster/ftraster.c - compile stand-alone again. - - -====================================================================== - -CHANGES BETWEEN 2.1.9 and 2.1.8 - - I. IMPORTANT BUG FIXES - - - The function `FT_Get_CharMap_Index' was only declared, without - any real code. For consistency, it has been renamed to - `FT_Get_Charmap_Index'. (This function is needed to implement - cmap caches.) - - - `FT_Outline_Get_BBox' sometimes returned incorrect values for - conic outlines (e.g., for TrueType fonts). - - - Handling of `bhed' table has been fixed. - - - The TrueType driver with enabled byte code interpreter sometimes - returned artifacts due to incorrect rounding. This bug has been - introduced after version 2.1.4. - - - The BDF driver dropped the last glyph in the font. - - - The BDF driver now uses the DEFAULT_CHAR property (if available) - to select a glyph shape for the undefined glyph. - - - The stroker failed for closed outlines and single points. - - - II. IMPORTANT CHANGES - - - George Williams contributed code to handle Apple's font - distortion technology found in GX fonts (`avar', `cvar', `fvar', - and `gvar' tables; the Multiple Masters API has been slightly - extended to cope with the new functionality). - - - The `FT_GlyphSlotRec' structure has been extended: The elements - `lsb_delta' and `rsb_delta' give the difference between hinted - and unhinted left and right side bearings if autohinting is - active. Using those values can improve the inter-letter spacing - considerably. See the documentation of `FT_GlyphSlotRec' and - the `ftstring' demo program how to use it. - - - Loading TrueType and Type 1 fonts has been made much faster. - - - The stroker is no longer experimental (but the cache subsystem - still is). - - - III. MISCELLANEOUS - - - A new documentation file `formats.txt' describes various font - formats supported (and not supported) by FreeType. - - -====================================================================== - -CHANGES BETWEEN 2.1.8 and 2.1.7 - - I. IMPORTANT BUG FIXES - - - The native TrueType hinter contained some bugs which prevented - some fonts to be rendered correctly, most notably Legendum.otf. - - - The PostScript hinter now produces improved results. - - - The linear advance width and height values were incorrectly - rounded, making them virtually unusable if not loaded with - FT_LOAD_LINEAR_DESIGN. - - - Indexing CID-keyed CFF fonts is now working: The glyph index is - correctly treated as a CID, similar to FreeType's CID driver - module. Note that CID CMap support is still missing. - - - The FT_FACE_FLAG_GLYPH_NAMES flag is now set correctly for all - font formats. - - - Some subsetted Type 1 fonts weren't parsed correctly. This bug - has been introduced in 2.1.7. In summary, the Type 1 parser has - become more robust. - - - Non-decimal numbers weren't parsed correctly in PS fonts. - - - The WinFNT driver now correctly reports FT_ENCODING_NONE for all - but one encoding. Use the new FT_WinFNT_ID_XXX values together - with `FT_Get_WinFNT_Header' to get the WinFNT charset ID. - - - The descender metrics (face->size->metrics.descender) for WinFNT - bitmap fonts had the wrong sign. - - - The (emulated) `seac' support for CFF fonts was broken. - - - The `flex' operator didn't work for CFF fonts. - - - PS glyphs which use the `hintmask' operator haven't been - rendered correctly in some cases. - - - Metrics for BDF and PCF bitmap font formats have been fixed. - - - Autohinting is now disabled for glyphs which are vertically - distorted or mirrored (using a transformation matrix). This - fixes a bug which produced zero-height glyphs. - - - The `freetype-config' script now handles --prefix and - --exec-prefix correctly; it also returns the proper --rpath (or - -R) value if FreeType has been built as a shared library. - - - II. IMPORTANT CHANGES - - - Both PCF and BDF drivers now handle the SETWIDTH_NAME and - ADD_STYLE_NAME properties. Values are appended to - face->style_name; example: `Bold SemiCondensed'. - - - The PCF driver now handles bitmap fonts compressed with the LZW - algorithm (extension .pcf.Z, compressed with `compress'). - - - A new API function `FT_Get_CMap_Language_ID' (declared in - `tttables.h') is available to get the language ID of a - TrueType/SFNT cmap. - - - The hexadecimal format of data after the `StartData' command in - CID-keyed Type 1 fonts is now supported. While this can't occur - in file-based fonts, it can happen in document-embedded - resources of PostScript documents. - - - Embedded bitmaps in SFNT-based CFF fonts are now supported. - - - A simple API is now available to control FreeType's tracing - mechanism if compiled with FT_DEBUG_LEVEL_TRACE. See the file - `ftdebug.h' for more details. - - - YAMATO Masatake contributed improved handling of MacOS resource - forks on non-MacOS platforms (for example, Linux can mount MacOS - file systems). - - - Support for MacOS has been improved; there is now a new function - `FT_New_Face_From_FSSpec' similar to `FT_New_Face' except that - it accepts an FSSpec instead of a path. - - - The cache sub-system has been rewritten. - - - There is now support for deinstallation of faces. - - - A new API function `FTC_Manager_RemoveFaceID' has been added - to delete all `idle' nodes that correspond to a given - FTC_FaceID. All `locked' nodes (i.e., those with a reference - count > 0), will be modified to prevent them from appearing in - further lookups (they will be cleaned normally when their - reference count reaches 0). - - - There is now support for point scaling (i.e., providing - character sizes in points + dpis, instead of pixels). - - - Three abstract cache classes are now available: - - FTC_GCache: Used to store one glyph item per cache node, - with the ability to group common attributes into - `families'. This replaces the old - FTC_GlyphCache class. - - FTC_ICache: Used to store one FT_Glyph per cache node. This - extends FTC_GCache. Family definition, family - comparison, and glyph loading are however left - to sub-classes. - - FTC_SCache: Used to store up to 16 small bitmaps per cache - node. This extends FTC_GCache. Family - definition, family comparison and glyph loading - are however left to sub-classes. - - - The file `src/cache/ftcbasic.c' implements: - - FTC_ImageCache: Extends FTC_ICache; implements family - definitions and glyph loading similar to the - old API. - - FTC_SBitCache: Extends FTC_SCache, implements family - definitions and glyph loading similar to the - old API - - Client applications should be able to extend FTC_GCache, - FTC_ICache, or FTC_SCache much more easily (i.e., less code to - write, and less callbacks). For example, one could envision - caches that are capable of storing transformed (obliqued), - stroked, emboldened, or colored glyph images. Use - `ftcbasic.c' as an example. - - - All public APIs are now in `include/freetype/ftcache.h', (to - be accessed as `FT_CACHE_H'). The contents of - `include/freetype/cache/' is only needed by applications that - wish to implement their own caches. - - - There were some major performance improvements through the use - of various programming tricks. Cache hits are up to 70% - faster than in the old code. - - - The FTC_CMapCache has been simplified. Charmaps can only be - accessed by index right now. There is also a new API named - `FT_Charmap_GetIndex' for this purpose. - - - The demo programs have been updated to the new code. The - previous versions will not work with the current one. - - - Using an invalid face index in FT_Open_Face and friends now - causes an error even if the font contains a single face only. - - - III. MISCELLANEOUS - - - Wolfgang Domröse contributed support files for building FreeType - on the Atari using the PureC compiler. Note that the Atari is a - 16bit platform. - - - Vitaliy Pasternak contributed project files for VS.NET 2003. - - -====================================================================== - -CHANGES BETWEEN 2.1.7 and 2.1.6 - - I. IMPORTANT BUG FIXES - - - Updated to newest libtool version, fixing build problems on - various platforms. - - - On Unix platforms, `make install' didn't copy the correct - `ftconfig.h' file. - - Note that version 2.1.7 contains the same library C source code as - version 2.1.6. - - -====================================================================== - -CHANGES BETWEEN 2.1.6 and 2.1.5 - - I. IMPORTANT BUG FIXES - - - The PFR font driver didn't load kerning tables correctly, and - the functions in FT_PFR_H didn't work at all. - - - Type 1 font files in binary format (PFB) with an end-of-file - indicator weren't accepted by the FreeType engine. - - - Fonts which contain /PaintType and /StrokeWidth no longer cause - a segfault. This bug has been introduced in version 2.1.5. - - - Fonts loaded with FT_LOAD_RENDER no longer cause strange - results. This bug has been introduced in version 2.1.5. - - - Some Windows (bitmap) FNT/FON files couldn't be handled - correctly. - - - II. IMPORTANT CHANGES - - - The internal module API has been heavily changed in favor of - massive simplifications within the font engine. This also means - that authors of third-party modules must adapt their code to the - new scheme. - - NOTE: THE NEW SCHEME IS NOT COMPLETED YET. PLEASE WAIT UNTIL A - FINAL ANNOUNCEMENT! - - - The PostScript parser has been enhanced to handle comments and - strings correctly. Additionally, more syntax forms are - recognized. - - - Added the optional unpatented hinting system for TrueType. It - allows typefaces which need hinting to produce correct glyph - forms (e.g., Chinese typefaces from Dynalab) to work acceptably - without infringing Apple patents. This system is compiled only - if TT_CONFIG_OPTION_COMPILE_UNPATENTED_HINTING is defined in - ftoption.h (activated by default). - - - III. MISCELLANEOUS - - - There is now a guard in the public header files to protect - against inclusion of freetype.h from FreeType 1. - - - Direct inclusion of freetype.h and other public header files no - longer works. You have to use the documented scheme - - #include - #include FT_FREETYPE_H - - to load freetype.h with a symbolic name. This protects against - renaming of public header files (which shouldn't happen but - actually has, avoiding two public header files with the same - name). - - -====================================================================== - -CHANGES BETWEEN 2.1.5 and 2.1.4 - - I. IMPORTANT BUG FIXES - - - Parsing the /CIDFontName field now removes the leading slash to - be in sync with other font drivers. - - - gzip support was buggy. Some fonts could not be read. - - - Fonts which have nested subglyphs more than one level deep no - longer cause a segfault. - - - Creation of synthetic cmaps for fonts in CFF format was broken - partially. - - - Numeric font dictionary entries for synthetic fonts are no - longer overwritten. - - - The font matrix wasn't applied to the advance width for Type1, - CID, and CFF fonts. This caused problems when loading certain - synthetic Type 1 fonts like `Helvetica Narrow'. - - - The test for the charset registry in BDF and PCF fonts is now - case-insensitive. - - - FT_Vector_Rotate sometimes returned strange values due to - rounding errors. - - - The PCF driver now returns the correct number of glyphs - (including an artificial `notdef' glyph at index 0). - - - FreeType now supports buggy CMaps which are contained in many - CJK fonts from Dynalab. - - - Opening an invalid font on a Mac caused a segfault due to - double-freeing memory. - - - BDF fonts with more than 32768 glyphs weren't supported - properly. - - - II. IMPORTANT CHANGES - - - Accessing bitmap font formats has been synchronized. To do that - the FT_Bitmap_Size structure has been extended to contain new - fields `size', `x_ppem', and `y_ppem'. - - - The FNT driver now returns multiple faces, not multiple strikes. - - - The `psnames' module has been updated to the Adobe Glyph List - version 2.0. - - - The `psnames' module now understands `uXXXX[X[X]]' glyph names. - - - The algorithm for guessing the font style has been improved. - - - For fonts in SFNT format, root->height is no longer increased if - the line gap is zero. There exist fonts (containing e.g. form - drawing characters) which intentionally have a zero line gap - value. - - - ft_glyph_bbox_xxx flags are now deprecated in favour of - FT_GLYPH_BBOX_XXX. - - - ft_module_xxx flags are now deprecated in favour of - FT_MODULE_XXX. - - - FT_ENCODING_MS_{SJIS,GB2312,BIG5,WANSUNG,JOHAB} are now - deprecated in favour of - FT_ENCODING_{SJIS,GB2312,BIG5,WANSUNG,JOHAB} -- those encodings - are not specific to Microsoft. - - - III. MISCELLANEOUS - - - The autohinter has been further improved; for example, `m' - glyphs now retain its vertical symmetry. - - - Partial support of Mac fonts on non-Mac platforms. - - - `make refdoc' (after first `make') builds the HTML - documentation. You need Python for this. - - - The make build system should now work more reliably on DOS-like - platforms. - - - Support for EMX gcc and Watson C/C++ compilers on MS-DOS has - been added. - - - Better VMS build support. - - - Support for the pkg-config package by providing a `freetype.pc' - file. - - - New configure option --with-old-mac-fonts for Darwin. - - - Some source files have been renamed (mainly to fit into the 8.3 - naming scheme). - - -====================================================================== - -CHANGES BETWEEN 2.1.4 and 2.1.3 - - I. IMPORTANT BUG FIXES - - - Updated to newest libtool version, fixing build problems on - various platforms. - - - A fix in the Gzip stream reader: It couldn't read certain .gz - files properly due to a small typo. In certain cases, FreeType - could also loop endlessly when trying to load tiny gzipped - files. - - - The configure script now tries to use the system-wide zlib when - it finds one (instead of the copy found in src/gzip). And - `freetype-config' has been updated to return relevant flags in - this case when invoked with `--libs' (e.g. `-lzlib'). - - - Certain fonts couldn't be loaded by 2.1.3 because they lacked a - Unicode charmap (e.g. SYMBOL.TTF). FreeType erroneously - rejected them. - - - The CFF loader was modified to accept fonts which only contain a - subset of their reference charset. This prevented the correct - use of PDF-embedded fonts. - - - The logic to detect Unicode charmaps has been modified. This is - required to support fonts which include both 16-bit and 32-bit - charmaps (like very recent asian ones) using the new 10 and 12 - SFNT formats. - - - The TrueType loader now limits the depth of composite glyphs. - This is necessary to prevent broken fonts to break the engine by - blowing the stack with recursive glyph definitions. - - - The CMap cache is now capable of managing UCS-4 character codes - that are mapped through extended charmaps in recent - TrueType/OpenType fonts. - - - The cache sub-system now properly manages out-of-memory - conditions instead of blindly reporting them to the caller. - This means that it will try to empty the cache before restarting - its allocations to see if that can help. - - - The PFR driver didn't return the list of available embedded - bitmaps properly. - - - There was a nasty memory leak when using embedded bitmaps in - certain font formats. - - - II. IMPORTANT CHANGES - - - David Chester contributed some enhancements to the auto-hinter - that significantly increase the quality of its output. The - Postscript hinter was also improved in several ways. - - - The FT_RENDER_MODE_LIGHT render mode was implemented. - - - A new API function called `FT_Get_BDF_Property' has been added - to FT_BDF_H to retrieve BDF properties from BDF _and_ PCF font - files. THIS IS STILL EXPERIMENTAL, since it hasn't been - properly tested yet. - - - A Windows FNT specific API has been added, mostly to access font - headers. This is used by Wine. - - - TrueType tables without an `hmtx' table are now tolerated when - an incremental interface is used. This happens for certain - Type42 fonts passed from Ghostscript to FreeType. - - - The PFR font driver is now capable of returning the font family - and style names when they are available (instead of the sole - `FontID'). This is performed by parsing an *undocumented* - portion of the font file! - - - III. MISCELLANEOUS - - - The path stroker in FT_STROKER_H has entered beta stage. It now - works very well, but its interface might change a bit in the - future. More on this in later releases. - - - The documentation for FT_Size_Metrics didn't appear properly in - the API reference. - - - The file docs/VERSION.DLL has been updated to explain versioning - with FreeType (i.e., comparing release/libtool/so numbers, and - how to use them in autoconf scripts). - - - The installation documentation has been seriously revamped. - Everything is now in the `docs' directory. - - -====================================================================== - -CHANGES BETWEEN 2.1.3 and 2.1.2 - - I. IMPORTANT BUG FIXES - - - FT_Vector_Transform had been incorrectly modified in 2.1.2, - resulting in incorrect transformations being applied (for - example, rotations were processed in opposite angles). - - - The format 8 and 12 TrueType charmap enumeration routines have - been fixed (FT_Get_Next_Char returned invalid values). - - - The PFR font driver returned incorrect advance widths if the - outline and metrics resolution defined in the font file were - different. - - - FT_Glyph_To_Bitmap now returns successfully when called with an - FT_BitmapGlyph argument (it previously returned an error). - - - A bug in the Type 1 loader that prevented valid font bounding - boxes to be loaded from multiple master fonts. - - - The SFNT validation code has been rewritten. FreeType can now - load `broken' fonts that were usable on Windows, but not with - previous versions of the library. - - - The computation of bearings in the BDF driver has been fixed. - - - The Postscript hinter crashed when trying to hint certain glyphs - (more precisely, when trying to apply hints to an empty glyph - outline). - - - The TrueType glyph loader now supports composites in `Apple - format' (they differ slightly from Microsoft/OpenType ones in - the way transformation offsets are computed). - - - FreeType was very slow at opening certain asian CID/CFF fonts, - due to fixed increment in dynamic array re-allocations. This - has been changed to exponential behaviour to get acceptable - performance. - - - - II. IMPORTANT CHANGES - - - The PCF driver now supports gzip-compressed font files natively. - This means that you will be able to use all these bitmap fonts - that come with XFree86 with FreeType (and libXft/libXft2, by - extension). - - - The automatic and postscript hinters have both been updated. - This results in a relatively important increase of rendering - quality since many nasty defaults have been suppressed. Please - visit the web page: - - https://www.freetype.org/hinting/smooth-hinting.html - - for additional details on this topic. - - - The `load_flags' parameter of `FT_Load_Glyph' is now an FT_Int32 - (instead of just being an FT_Int). This breaks source and - binary compatibility for 16bit systems only, while retaining - both of them for 32 and 64 bit ones. - - Some new flags have been added consequently: - - FT_LOAD_NO_AUTOHINT :: Disable the use of the auto-hinter - (but not native format hinters). - - FT_LOAD_TARGET_NORMAL :: Hint and render for normal - anti-aliased displays. - - FT_LOAD_TARGET_MONO :: Hint and render for 1-bit displays. - - FT_LOAD_TARGET_LCD :: Hint and render for horizontal RGB or - BGR subpixel displays (like LCD - screens). THIS IS STILL - EXPERIMENTAL! - - FT_LOAD_TARGET_LCD_V :: Same as FT_LOAD_TARGET_LCD, for - vertical subpixel displays (like - rotated LCD screens). THIS IS STILL - EXPERIMENTAL! - - FT_LOAD_MONOCHROME is still supported, but only affects - rendering, not the hinting. - - Note that the `ftview' demo program available in the `ft2demos' - package has been updated to support LCD-optimized display on - non-paletted displays (under Win32 and X11). - - - The PFR driver now supports embedded bitmaps (all formats - supported), and returns correct kerning metrics for all glyphs. - - - The TrueType charmap loader now supports certain `broken' fonts - that load under Windows without problems. - - - The cache API has been slightly modified (it's still a beta!): - - - The type FTC_ImageDesc has been removed; it is now replaced - by FTC_ImageTypeRec. Note that one of its fields is a - `load_flag' parameter for FT_Load_Glyph. - - - The field `num_grays' of FT_SBitRec has been changed to - `max_grays' in order to fit within a single byte. Its - maximum value is thus 255 (instead of 256 as previously). - - - III. MISCELLANEOUS - - - Added support for the DESTDIR variable during `make install'. - This simplifies packaging of FreeType. - - - Included modified copies of the ZLib sources in `src/gzip' in - order to support gzip-compressed PCF fonts. We do not use the - system-provided zlib for now, though this is a probable - enhancement for future releases. - - - The DocMaker tool used to generate the on-line API reference has - been completely rewritten. It is now located in - `src/tools/docmaker/docmaker.py'. Features: - - - better cross-referenced output - - more polished output - - uses Python regular expressions (though it didn't speed the - program) - - much more modular structure, which allows for different - `backends' in order to generate HTML, XML, or whatever - format. - - One can regenerate the API reference by calling: - - python src/tools/docmaker/docmaker.py \ - --prefix=ft2 \ - --title=FreeType-2.1.3 \ - --output= - include/freetype/*.h \ - include/freetype/config/*.h \ - include/freetype/cache/*.h - - - A new, experimental, support for incremental font loading (i.e., - loading of fonts where the glyphs are not in the font file - itself, but provided by an external component, like a Postscript - interpreter) has been added by Graham Asher. This is still work - in progress, however. - - - A new, EXPERIMENTAL, path stroker has been added. It doesn't - suffer from severe rounding errors and treat bezier arcs - directly. Still work in progress (i.e. not part of the official - API). See the file for some of the - details. - - - The massive re-formatting of sources and internal re-design is - still under-way. Many internal functions, constants, and types - have been renamed. - - -====================================================================== - -CHANGES BETWEEN 2.1.2 and 2.1.1 - - I. IMPORTANT BUG FIXES - - - Many font drivers didn't select a Unicode charmap by default - when a new face was opened (with the FT_CONFIG_OPTION_USE_CMAPS - options enabled), causing many applications to not be able to - display text correctly with the 2.1.x releases. - - - The PFR driver had a bug in its composite loading code that - produces incorrectly placed accents with many fonts. - - - The Type42 driver crashed sometimes due to a nasty bug. - - - The Type 1 custom encoding charmap didn't handle the case where - the first glyph index wasn't 0. - - - A serious typo in the TrueType composite loader produced - incorrectly placed glyphs in fonts like `Wingdings' and a few - others. - - - II. MISCELLANEOUS - - - The Win32 Visual C++ project file has been updated to include - the PFR driver as well. - - - `freetype.m4' is now installed by default by `make install' on - Unix systems. - - - The function FT_Get_PS_Font_Info now works with CID and Type42 - fonts as well. - - -====================================================================== - -CHANGES BETWEEN 2.1.1 and 2.1.0 - - I. IMPORTANT BUG FIXES - - - The `version_info' returned by `freetype-config' in 2.1.0 - returned an invalid value. It now returns 9:1:3 (2.0.9 returned - 9:0:3). - - - Version 2.1.0 couldn't be linked against applications on Win32 - and Amiga systems due to a new debug function that wasn't - properly propagated to the system-specific directory in - `builds'. - - - Various MacOS and Mac OS X specific fixes. - - - Fixed a bug in the TrueType charmap validation routines that - made version 2.1.0 too restrictive -- many popular fonts have - been rejected. - - - There was still a very small difference between the monochrome - glyph bitmaps produced by FreeType 1.x and FreeType 2.x with the - bytecode interpreter enabled. This was caused by an invalid - flag setting in the TrueType glyph loader, making the rasterizer - change its drop-out control mode. Now the results should - _really_ be completely identical. - - - The TrueType name table loader has been improved to support many - popular though buggy Asian fonts. It now ignores empty name - entries, invalid pointer offsets and a few other incorrect - subtleties. Moreover, name strings are now loaded on demand, - which reduces the memory load of many faces (e.g. the ARIAL.TTF - font file contains a 10kByte name table with 70 names). - - - Fixed a bug in the Postscript hinter that prevented family blues - substitution to happen correctly. - - - II. NEW FEATURES - - - Three new font drivers in this release: - - * A BDF font driver, contributed by Franco Zappa Nardelli, - heavily modified by Werner Lemberg. It also supports - anti-aliased bitmaps (using a slightly extended BDF format). - - * A Type42 font driver, contributed by Roberto Alameda. It is - still experimental but seems to work relatively well. - - * A PFR font driver, contributed by David Turner himself. It - doesn't support PFR hinting -- note that BitStream has at - least two patents on this format! - - - III. MISCELLANEOUS - - - The cache sub-system has been optimized in important ways. - Cache hits are now significantly faster. For example, using the - CMap cache is about twice faster than calling FT_Get_Char_Index - on most platforms. Similarly, using an SBit cache is about five - times faster than loading the bitmaps from a bitmap file, and - 300 to 500 times faster than generating them from a scalable - format. - - Note that you should recompile your sources if you designed a - custom cache class for the FT2 Cache subsystem, since the - changes performed are source, but not binary, compatible. - - -====================================================================== - -CHANGES BETWEEN 2.1.0 and 2.0.9 - - I. IMPORTANT BUG FIXES - - - The TrueType bytecode interpreter has been fixed to produce - _exactly_ the same output as FreeType 1.x. Previous differences - were due to slightly distinct fixed-point computation routines - used to perform dot products and vector length measurements. - - It seems that native TrueType hinting is _extremely_ sensitive - to rounding errors. The required vector computation routines - have been optimized and placed within the `ttinterp.c' file. - - - Fixed the parsing of accelerator tables in the PCF font driver. - - - Fixed the Type1 glyph loader routine used to compute the font's - maximum advance width. - - - II. NEW FEATURES - - - The `configure' script used on Unix systems has been modified to - check that GNU Make is being used to build the library. - Otherwise, it will display a message proposing to use the - GNUMAKE environment variable to name it. - - The Unix-specific file README.UNX has been modified accordingly. - - - III. MISCELLANEOUS - - - The FreeType License in `docs/FTL.TXT' has been updated to - include a proposed preferred disclaimer. If you are using - FreeType in your products, you are encouraged (but not mandated) - to use the following text in your documentation: - - """ - Portions of this software are copyright © 1996-2002 The - FreeType Project (www.freetype.org). All rights reserved. - """ - - - The default size of the render pool has been reduced to 16kByte. - This shouldn't result in any noticeable performance penalty, - unless you are using the engine as-is to render very large and - complex glyphs. - - - The FreeType 2 redesign has begun. More information can be - found at this URL: - - https://www.freetype.org/freetype2/redesign.html - - The following internal changes have been performed within the - sources of this release: - - - Many internal types have been renamed to increase - consistency. The following should be true, except for - public types: - - * All structure types have a name ending in `Rec' (short - for `record'). - - * A pointer-to-structure type has the same name as the - structure, _without_ the `Rec' suffix. - - Example: - - typedef struct FooRec_ - { - ... - - } FooRec, *Foo; - - - Many internal macros have been renamed to increase - consistency. The following should be true: - - * All macros have a name beginning with `FT_'. This - required a few changes like - - ALLOC => FT_ALLOC - FREE => FT_FREE - REALLOC => FT_REALLOC - - * All macros are completely UPPERCASE. This required a - few changes like: - - READ_Short => FT_READ_SHORT - NEXT_Short => FT_NEXT_SHORT - GET_ULongLE => FT_GET_ULONG_LE - MEM_Set => FT_MEM_SET - MEM_Copy => FT_MEM_COPY - etc. - - * Whenever possible, all macro names follow the - FT__ pattern. For example - - ACCESS_Frame => FT_FRAME_ENTER - FORGET_Frame => FT_FRAME_EXIT - EXTRACT_Frame => FT_FRAME_EXTRACT - RELEASE_Frame => FT_FRAME_RELEASE - - FILE_Pos => FT_STREAM_POS - FILE_Seek => FT_STREAM_SEEK - FILE_Read => FT_STREAM_READ - FILE_ReadAt => FT_STREAM_READ_AT - READ_Fields => FT_STREAM_READ_FIELDS - - - Many internal functions have been renamed to follow the - FT__ pattern. For example: - - FT_Seek_Stream => FT_Stream_Seek - FT_Read_Stream_At => FT_Stream_ReadAt - FT_Done_Stream => FT_Stream_Close - FT_New_Stream => FT_Stream_Open - FT_New_Memory_Stream => FT_Stream_OpenMemory - FT_Extract_Frame => FT_Stream_ExtractFrame - - Note that method names do not contain `_'. - - - The FT_ALLOC_ARRAY and FT_REALLOC_ARRAY have been replaced - with FT_NEW_ARRAY and FT_RENEW_ARRAY which do not take a - type as the fourth argument. Instead, the array element - type size is computed automatically from the type of the - target pointer used. - - - A new object class, FT_CMap, has been introduced. These - internal objects are used to model character maps. This - eases the support of additional charmap types within the - engine. - - - A new configuration file named `ftstdlib.h' has been added - to `include/freetype/config'. It is used to define aliases - for _every_ routine of the ISO C library that the font - engine uses. Each aliases has a `ft_' prefix - (e.g. `ft_strlen' is an alias for `strlen'). - - This is used to ease the porting of FreeType 2 to exotic - runtime environments where the ISO C Library isn't available - (e.g. XFree86 extension modules). - - More details are available in the `ChangeLog' file. - - -====================================================================== - -CHANGES BETWEEN 2.0.9 and 2.0.8 - - I. IMPORTANT BUG FIXES - - - Certain fonts like `foxjump.ttf' contain broken name tables with - invalid entries and wild offsets. This caused FreeType to crash - when trying to load them. - - The SFNT `name' table loader has been fixed to be able to - support these strange fonts. - - Moreover, the code in charge of processing this table has been - changed to always favour Windows-formatted entries over other - ones. Hence, a font that works on Windows but not on the Mac - will load cleanly in FreeType and report accurate values for - Family & PostScript names. - - - The CID font driver has been fixed. It unfortunately returned a - Postscript Font name with a leading slash, as in - `/MunhwaGothic-Regular'. - - - FreeType 2 should now compile fine on AIX 4.3.3 as a shared - library. - - - A bug in the Postscript hinter has been found and fixed, - removing un-even stem widths at small pixel sizes (like 14-17). - - This improves the quality of a certain number of Postscript - fonts. - - - II. NEW FEATURES - - - A new function named `FT_Library_Version' has been added to - return the current library's major, minor, and patch version - numbers. This is important since the macros FREETYPE_MAJOR, - FREETYPE_MINOR, and FREETYPE_PATCH cannot be used when the - library is dynamically linked by a program. - - - Two new APIs have been added: `FT_Get_First_Char' and - `FT_Get_Next_Char'. - - Together, these can be used to iterate efficiently over the - currently selected charmap of a given face. Read the API - reference for more details. - - - III. MISCELLANEOUS - - - The FreeType sources are under heavy internal re-factoring. As - a consequence, we have created a branch named `STABLE' on the - CVS to hold all future releases/fixes in the 2.0.x family. - - The HEAD branch now contains the re-factored sources and - shouldn't be used for testing or packaging new releases. In - case you would like to access the 2.0.9 sources from our CVS - repository, use the tag `VER-2-0-9'. - - -====================================================================== - -CHANGES BETWEEN 2.0.8 and 2.0.7 - - I. IMPORTANT BUG FIXES - - - There was a small but nasty bug in `freetype-config.in' which - caused the `freetype-config' script to fail on Unix. - - This didn't prevent the installation of the library or even its - execution, but caused problems when trying to compile many Unix - packages that depend on it. - - - Some TrueType or OpenType fonts embedded in PDF documents do not - have a 'cmap', 'post' and 'name' as is required by the - specification. FreeType no longer refuses to load such fonts. - - - Various fixes to the PCF font driver. - - -====================================================================== - -CHANGES BETWEEN 2.0.7 and 2.0.6 - - I. IMPORTANT BUG FIXES - - - Fixed two bugs in the Type 1 font driver. The first one - resulted in a memory leak in subtle cases. The other one caused - FreeType to crash when trying to load `.gsf' files (Ghostscript - so-called Postscript fonts). - - (This made _many_ KDE applications crash on certain systems. - FreeType _is_ becoming a critical system component on Linux :-) - - - Fixed a memory leak in the CFF font driver. - - - Fixed a memory leak in the PCF font driver. - - - Fixed the Visual C++ project file - `builds/win32/visualc/freetype.dsp' since it didn't include the - Postscript hinter component, causing errors at build time. - - - Fixed a small rendering bug in the anti-aliased renderer that - only occurred when trying to draw thin (less than 1 pixel) - strokes. - - - Fixed `builds/unix/freetype2.a4' which is used to generate a - valid `freetype2.m4' for use with autoconf. - - - Fixed the OpenVMS Makefiles. - - - II. MISCELLANEOUS - - - Added `configure' and `install' scripts to the top-level - directory. A GNU-style installation is thus now easily possible - with - - ./configure - make - make install - - -====================================================================== - -CHANGES BETWEEN 2.0.6 and 2.0.5 - - I. IMPORTANT BUG FIXES - - - It wasn't possible to load embedded bitmaps when the auto-hinter - was used. This is now fixed. - - - The TrueType font driver didn't load some composites properly - (the sub-glyphs were slightly shifted, and this was only - noticeable when using monochrome rendering). - - - Various fixes to the auto-hinter. They merely improve the - output of sans-serif fonts. Note that there are still problems - with serifed fonts and composites (accented characters). - - - All scalable font drivers erroneously returned un-fitted glyph - advances when hinting was requested. This created problems for - a number of layout applications. This is a very old bug that - got undetected mainly because most test/demo program perform - rounding explicitly or implicitly (through the cache). - - - `FT_Glyph_To_Bitmap' did erroneously modify the source glyph in - certain cases. - - - `glnames.py' still contained a bug that made FreeType return - invalid names for certain glyphs. - - - The library crashed when loading certain Type 1 fonts like - `sadn.pfb' (`Stalingrad Normal'), which appear to contain - pathetic font info dictionaries. - - - The TrueType glyph loader is now much more paranoid and checks - everything when loading a given glyph image. This was necessary - to avoid problems (crashes and/or memory overwrites) with broken - fonts that came from a really buggy automatic font converter. - - - II. IMPORTANT UPDATES AND NEW FEATURES - - - Important updates to the Mac-specific parts of the library. - - - The caching sub-system has been completely re-designed, and its - API has evolved (the old one is still supported for backward - compatibility). - - The documentation for it is not yet completed, sorry. For now, - you are encouraged to continue using the old API. However, the - ftview demo program in the ft2demos package has already been - updated to use the new caching functions. - - - A new charmap cache is provided too. See `FTC_CMapCache'. This - is useful to perform character code -> glyph index translations - quickly, without the need for an opened FT_Face. - - - A NEW POSTSCRIPT HINTER module has been added to support native - hints in the following formats: PostScript Type 1, PostScript - CID, and CFF/CEF. - - Please test! Note that the auto-hinter produces better results - for a number of badly-hinted fonts (mostly auto-generated ones) - though. - - - A memory debugger is now part of the standard FreeType sources. - To enable it, define FT_DEBUG_MEMORY in - , and recompile the library. - - Additionally, define the _environment_ variable FT_DEBUG_MEMORY - and run any program using FreeType. When the library is exited, - a summary of memory footprints and possible leaks will be - displayed. - - This works transparently with _any_ program that uses FreeType. - However, you will need a lot of memory to use this (allocated - blocks are never released to the heap to detect double deletes - easily). - - - III. MISCELLANEOUS - - - We are aware of subtle differences between the output of - FreeType versions 1 and 2 when it comes to monochrome - TrueType-hinted glyphs. These are most probably due to small - differences in the monochrome rasterizers and will be worked out - in an upcoming release. - - - We have decided to fork the sources in a `stable' branch, and an - `unstable' one, since FreeType is becoming a critical component - of many Unix systems. - - The next bug-fix releases of the library will be named 2.0.7, - 2.0.8, etc., while the `2.1' branch will contain a version of - the sources where we will start major reworking of the library's - internals, in order to produce FreeType 2.2.0 (or even 3.0) in a - more distant future. - - We also hope that this scheme will allow much more frequent - releases than in the past. - - -====================================================================== - -CHANGES BETWEEN 2.0.5 and 2.0.4 - - NOTE THAT 2.0.5 DOES NOT CONTAIN THE POSTSCRIPT HINTER. THIS MODULE - WILL BE PART OF THE NEXT RELEASE (EITHER 2.0.6 or 2.1) - - - Fixed a bug that made certain glyphs, like `Cacute', `cacute' and - `lslash' unavailable from Unicode charmaps of Postscript fonts. - This prevented the correct display of Polish text, for example. - - - The kerning table of Type 1 fonts was loaded by FreeType, when its - AFM file was attached to its face, but the - FT_FACE_FLAG_HAS_KERNING bit flags was not set correctly, - preventing FT_Get_Kerning to return meaningful values. - - - Improved SFNT (TrueType & OpenType) charmap support. Slightly - better performance, as well as support for the new formats defined - by the OpenType 1.3 specification (8, 10, and 12) - - - Fixed a serious typo in `src/base/ftcalc.c' which caused invalid - computations in certain rare cases, producing ugly artefacts. - - - The size of the EM square is computed with a more accurate - algorithm for Postscript fonts. The old one caused slight errors - with embedded fonts found in PDF documents. - - - Fixed a bug in the cache manager that prevented normal LRU - behaviour within the cache manager, causing unnecessary reloads - (for FT_Face and FT_Size objects only). - - - Added a new function named `FT_Get_Name_Index' to retrieve the - glyph index of a given glyph name, when found in a face. - - - Added a new function named `FT_Get_Postscript_Name' to retrieve - the `unique' Postscript font name of a given face. - - - Added a new public header size named FT_SIZES_H (or - ) providing new FT_Size-management functions: - FT_New_Size, FT_Activate_Size, FT_Done_Size. - - - Fixed a reallocation bug that generated a dangling pointer (and - possibly memory leaks) with Postscript fonts (in - src/psaux/psobjs.c). - - - Many fixes for 16-bit correctness. - - - Removed many pedantic compiler warnings from the sources. - - - Added an Amiga build directory in `builds/amiga'. - - -====================================================================== - -CHANGES BETWEEN 2.0.4 and 2.0.3 - - - Fixed a rather annoying bug that was introduced in 2.0.3. Namely, - the font transformation set through FT_Set_Transform was applied - twice to auto-hinted glyphs, resulting in incorrectly rotated text - output. - - - Fixed _many_ compiler warnings. FT2 should now compile cleanly - with Visual C++'s most pedantic warning level (/W4). It already - compiled fine with GCC and a few other compilers. - - - Fixed a bug that prevented the linear advance width of composite - TrueType glyphs to be correctly returned. - - - Fixed the Visual C++ project files located in - `builds/win32/visualc' (previous versions used older names of the - library). - - - Many 32-bit constants have an `L' appended to their value, in - order to improve the 16-bitness of the code. Someone is actually - trying to use FT2 on an Atari ST machine! - - - Updated the `builds/detect.mk' file in order to automatically - build FT2 on AIX systems. AIX uses `/usr/sbin/init' instead of - `/sbin/init' and wasn't previously detected as a Unix platform by - the FreeType build system. - - - Updated the Unix-specific portions of the build system (new - libtool version, etc.). - - - The SFNT kerning loader now ensures that the table is sorted - (since some problem fonts do not meet this requirement). - - -======================================================================= - -CHANGES BETWEEN 2.0.3 and 2.0.2 - - I. CHANGES TO THE MODULES / FONT DRIVERS - - - THE AUTO-HINTER HAS BEEN SLIGHTLY IMPROVED, in order to fix - several annoying artefacts, mainly: - - - Blue zone alignment of horizontal stems wasn't performed - correctly, resulting in artefacts like the `d' being placed - one pixel below the `b' in some fonts like Time New Roman. - - - Overshoot thresholding wasn't performed correctly, creating - unpleasant artefacts at large character pixel sizes. - - - Composite glyph loading has been simplified. This gets rid - of various artefacts where the components of a composite - glyphs were not correctly spaced. - - These are the last changes to the current auto-hinting module. - A new hinting sub-system is currently in the work in order to - support native hints in Type 1 / CFF / OpenType fonts, as well - as globally improve rendering. - - - The PCF driver has been fixed. It reported invalid glyph - dimensions for the fonts available on Solaris. - - - The Type 1, CID and CFF drivers have been modified to fix the - computation of the EM size. - - - The Type 1 driver has been fixed to avoid a dangerous bug that - crashed the library with non-conforming fonts (i.e. ones that do - not place the .notdef glyph at position 0). - - - The TrueType driver had a rather subtle bug (dangling pointer - when loading composite glyphs) that could crash the library in - rare occasions! - - - II. HIGH-LEVEL API CHANGES - - - The error code enumeration values have been changed. An error - value is decomposed in a generic error code, and a module - number. see for details. - - - A new public header file has been introduced, named - FT_TRIGONOMETRY_H (include/freetype/fttrigon.h), providing - trigonometric functions to compute sines, cosines, arctangents, - etc. with 16.16 fixed precision. The implementation is based on - the CORDIC algorithm and is very fast while being sufficiently - accurate. - - - III. INTERNALS - - - Added BeOS-specific files in the old build sub-system. Note - that no changes were required to compile the library with Jam. - - - The configuration is now capable of automatically detecting - 64-bit integers on a set of predefined compilers (GCC, Visual - C++, Borland C++) and will use them by default. This provides a - small performance boost. - - - A small memory leak that happened when opening 0-sized files - (duh!) have been fixed. - - - Fixed bezier stack depth bug in the routines provided by the - FT_BBOX_H header file. Also fixed similar bugs in the - rasterizers. - - - The outline bounding box code has been rewritten to use direct - computations, instead of bezier sub-division, to compute the - exact bounding box of glyphs. This is slightly slower but more - accurate. - - - The build system has been improved and fixed, mainly to support - `make' on Windows 2000 correctly, avoid problems with `make - distclean' on non Unix systems, etc. - - - Hexadecimal constants have been suffixed with `U' to avoid - problems with certain compilers on 64-bit platforms. - - - A new directory named `src/tools' has been created. It contains - Python scripts and simple unit test programs used to develop the - library. - - - The DocMaker tool has been moved from `docs' to `src/tools' and - has been updated with the following: - - - Now accepts the `--title=XXXX' or `-t XXXX' option from the - command line to set the project's name in the generated API - reference. - - - Now accepts the `--output=DIR' or `-o DIR' option from the - command line to set the output directory for all generated - HTML files. - - - Now accepts the `--prefix=XXXX' or `-p XXX' option from the - command line to set the file prefix to use for all - generated HTML files. - - - Now generates the current time/data on each generated page - in order to distinguish between versions. - - DocMaker can be used with other projects now, not only FT2 - (e.g. MLib, FTLayout, etc.). - - -====================================================================== - -CHANGES BETWEEN 2.0.2 and 2.0.1 - - I. CHANGES TO THE MODULES / FONT DRIVERS - - - THE TRUETYPE BYTECODE INTERPRETER IS NOW TURNED OFF, in order to - avoid legal problems with the Apple patents. It seems that we - mistakenly turned this option on in previous releases of the - build. - - Note that if you want to use the bytecode interpreter in order - to get high-quality TrueType rendering, you will need to toggle - by hand the definition of the - TT_CONFIG_OPTION_BYTECODE_INTERPRETER macro in the file - `include/freetype/config/ftoption.h'. - - - The CFF driver has been improved by Tom Kacvinsky and Sander van - der Wal: - - * Support for `seac' emulation. - * Support for `dotsection'. - * Support for retrieving glyph names through - `FT_Get_Glyph_Name'. - - The first two items are necessary to correctly a large number of - Type 1 fonts converted to the CFF formats by Adobe Acrobat. - - - The Type 1 driver was also improved by Tom & others: - - * Better EM size computation. - * Better support for synthetic (transformed) fonts. - * The Type 1 driver returns the charstrings corresponding to - each glyph in the `glyph->control_data' field after a call to - `FT_Load_Glyph' (thanks Ha Shao). - - - Various other bugfixes, including the following: - - * Fixed a nasty memory leak in the Type 1 driver. - * The autohinter and the pcf driver used static writable data - when they shouldn't. - * Many casts were added to make the code more 64-bits safe. It - also now compiles on Windows XP 64-bits without warnings. - * Some incorrect writable statics were removed in the `autohint' - and `pcf' drivers. FreeType 2 now compiles on Epoc again. - - - II. CHANGES TO THE HIGH-LEVEL API - - - The library header files inclusion scheme has been changed. The - old scheme looked like: - - #include - #include - #include - #include - - Now you should use: - - #include - #include FT_FREETYPE_H - #include FT_GLYPH_H - #include FT_CACHE_H - #include FT_CACHE_IMAGE_H - - NOTE THAT THE OLD INCLUSION SCHEME WILL STILL WORK WITH THIS - RELEASE. HOWEVER, WE DO NOT GUARANTEE THAT THIS WILL STILL BE - TRUE IN THE NEXT ONE (A.K.A. FREETYPE 2.1). - - The file is used to define the header filename - macros. The complete and commented list of macros is available - in the API reference under the section name `Header File Macros' - in Chapter I. - - For more information, see section I of the following document: - - https://www.freetype.org/freetype2/docs/tutorial/step1.html - - - Many, many comments have been added to the public source file in - order to automatically generate the API Reference through the - `docmaker.py' Python script. - - The latter has been updated to support the grouping of sections - in chapters and better index sort. See: - - https://www.freetype.org/freetype2/docs/reference/ft2-toc.html - - - III. CHANGES TO THE BUILD PROCESS - - - If you are not building FreeType 2 with its own build system - (but with your own Makefiles or project files), you will need to - be aware that the build process has changed a little bit. - - You don't need to put the `src' directory in the include path - when compiling any FT2 component. Instead, simply put the - component's directory in the current include path. - - So, if you were doing something like: - - cc -c -Iinclude -Isrc src/base/ftbase.c - - change the line to: - - cc -c -Iinclude -Isrc/base src/base/ftbase.c - - If you were doing something like: - - cd src/base - cc -c -I../../include -I.. ftbase.c - - change it to: - - cd src/base - cc -c -I../../include ftbase.c - - -====================================================================== - -CHANGES BETWEEN 2.0.1 and 2.0 - - 2.0.1 introduces a few changes: - - - Fixed many bugs related to the support of CFF / OpenType fonts. - These formats are now much better supported though there is - still work planned to deal with charset tables and PDF-embedded - CFF files that use the old `seac' command. - - - The library could not be compiled in debug mode with a very - small number of C compilers whose pre-processors didn't - implement the `##' directive correctly (i.e. per se the ANSI C - specification!) An elegant fix was found. - - - Added support for the free Borland command-line C++ Builder - compiler. Use `make setup bcc32'. Also fixed a few source - lines that generated new warnings with BCC32. - - - Fixed a bug in FT_Outline_Get_BBox when computing the extrema of - a conic Bezier arc. - - - Updated the INSTALL file to add IDE compilation. - - - Other minor bug fixes, from invalid Type 1 style flags to - correct support of synthetic (obliqued) fonts in the - auto-hinter, better support for embedded bitmaps in a SFNT font. - - - Fixed some problems with `freetype-config'. - - Finally, the `standard' scheme for including FreeType headers is now - gradually changing, but this will be explained in a later release - (probably 2.0.2). - - And very special thanks to Tom Kacvinsky and YAMANO-UCHI Hidetoshi - for their contributions! - - -====================================================================== - -CHANGES BETWEEN beta8 and 2.0 - - - Changed the default installation path for public headers from - `include/freetype' to `include/freetype2'. - - Also added a new `freetype-config' that is automatically generated - and installed on Unix and Cygwin systems. The script itself is - used to retrieve the current install path, C compilation flags as - well as linker flags. - - - Fixed several small bugs: - - * Incorrect max advance width for fixed-pitch Type 1 fonts. - * Incorrect glyph names for certain TrueType fonts. - * The glyph advance was not copied when FT_Glyph_To_Bitmap was - called. - * The linearHoriAdvance and linearVertAdvance fields were not - correctly returned for glyphs processed by the auto-hinter. - * `type1z' renamed back to `type1'; the old `type1' module has - been removed. - - - Revamped the build system to make it a lot more generic. This - will allow us to re-use nearly un-modified in lots of other - projects (including FreeType Layout). - - - Changed `cid' to use `psaux' too. - - - Added the cache sub-system. See as well as - the sources in `src/cache'. Note that it compiles but is still - untested for now. - - - Updated `docs/docmaker.py', a draft API reference is available at - https://web.archive.org/web/20001215173400/http://www.freetype.org:80/ft2api.html. - - - Changed `type1' to use `psaux'. - - - Created a new module named `psaux' to hold the Type 1 & Type 2 - parsing routines. It should be used by `type1', `cid', and `cff' - in the future. - - - Fixed an important bug in `FT_Glyph_Get_CBox'. - - - Fixed some compiler warnings that happened since the TrueType - bytecode decoder was deactivated by default. - - - Fixed two memory leaks: - - * The memory manager (16 bytes) isn't released in - FT_Done_FreeType! - * Using custom input streams, the copy of the original stream was - never released. - - - Fixed the auto-hinter by performing automatic computation of the - `filling direction' of each glyph. This is done through a simple - and fast approximation, and seems to work (problems spotted by - Werner though). The Arphic fonts are a lot nicer though there are - still a lot of things to do to handle Asian fonts correctly. - - -====================================================================== - -BETA-8 (RELEASE CANDIDATE) CHANGES - - - Deactivated the TrueType bytecode interpreter by default. - - - Deactivated the `src/type1' font driver. Now `src/type1z' is used - by default. - - - Updates to the build system. We now compile the library correctly - under Unix system through `configure' which is automatically - called on the first `make' invocation. - - - Added the auto-hinting module! Fixing some bugs here and there. - - - Found some bugs in the composite loader (seac) of the Type1-based - font drivers. - - - Renamed the directory `freetype2/config' to `freetype2/builds' and - updated all relevant files. - - - Found a memory leak in the `type1' driver. - - - Incorporated Tom's patches to support flex operators correctly in - OpenType/CFF fonts. Now all I need is to support pure CFF and CEF - fonts to be done with this driver :-) - - - Added the Windows FNT/FON driver in `src/winfonts'. For now, it - always `simulates' a Unicode charmap, so it shouldn't be - considered completed right now. - - It is there to be more a proof of concept than anything else - anyway. The driver is a single C source file, that compiles to 3 - Kb of code. - - I'm still working on the PCF/BDF drivers, but I'm too lazy to - finish them now. - - - CHANGES TO THE HIGH-LEVEL API - - * FT_Get_Kerning has a new parameter that allows you to select the - coordinates of the kerning vector (font units, scaled, scaled + - grid-fitted). - * The outline functions are now in and not - part of anymore. - * now contains declarations for - FT_New_Library, FT_Done_Library, FT_Add_Default_Modules. - * The so-called convenience functions have moved from `ftoutln.c' - to `ftglyph.c', and are thus available with this optional - component of the library. They are declared in - now. - * Anti-aliased rendering is now the default for FT_Render_Glyph - (i.e. corresponds to render_mode == 0 == ft_render_mode_normal). - To generate a monochrome bitmap, use ft_render_mode_mono, or the - FT_LOAD_MONOCHROME flag in FT_Load_Glyph/FT_Load_Char. - FT_LOAD_ANTI_ALIAS is still defined, but values to 0. - * now include , - solving a few headaches :-) - * The type FT_GlyphSlotRec has now a `library' field. - - - CHANGES TO THE `ftglyph.h' API - - This API has been severely modified in order to make it simpler, - clearer, and more efficient. It certainly now looks like a real - `glyph factory' object, and allows client applications to manage - (i.e. transform, bbox and render) glyph images without ever - knowing their original format. - - - Added support for CID-keyed fonts to the CFF driver. Maybe - support for pure CFF + CEF fonts should come in? - - - Cleaned up source code in order to avoid two functions with the - same name. Also changed the names of the files in `type1z' from - `t1XXXX' to `z1XXXX' in order to avoid any conflicts. - - `make multi' now works well :-) - - Also removed the use of `cidafm' for now, even if the source files - are still there. This functionality will certainly go into a - specific module. - - - ADDED SUPPORT FOR THE AUTO-HINTER - - It works :-) I have a demo program which simply is a copy of - `ftview' that does a `FT_Add_Module(library, - &autohinter_module_class)' after library initialization, and Type - 1 & OpenType/CFF fonts are now hinted. - - CID fonts are not hinted, as they include no charmap and the - auto-hinter doesn't include `generic' global metrics computations - yet. - - Now, I need to release this thing to the FreeType 2 source. - - - CHANGES TO THE RENDERER MODULES - - The monochrome and smooth renderers are now in two distinct - directories, namely `src/raster1' and `src/smooth'. Note that the - old `src/renderer' is now gone. - - I ditched the 5-gray-levels renderers. Basically, it involved a - simple #define toggle in 'src/raster1/ftraster.c'. - - FT_Render_Glyph, FT_Outline_Render & FT_Outline_Get_Bitmap now - select the best renderer available, depending on render mode. If - the current renderer for a given glyph image format isn't capable - of supporting the render mode, another one will be found in the - library's list. This means that client applications do not need - to switch or set the renderers themselves (as in the latest - change), they'll get what they want automatically. At last. - - Changed the demo programs accordingly. - - - MAJOR INTERNAL REDESIGN: - - A lot of internal modifications have been performed lately on the - source in order to provide the following enhancements: - - * More generic module support: - - The FT_Module type is now defined to represent a handle to a - given module. The file contains the - FT_Module_Class definition, as well as the module-loading public - API. - - The FT_Driver type is still defined, and still represents a - pointer to a font driver. Note that FT_Add_Driver is replaced - by FT_Add_Module, FT_Get_Driver by FT_Get_Module, etc. - - * Support for generic glyph image types: - - The FT_Renderer type is a pointer to a module used to perform - various operations on glyph image. - - Each renderer is capable of handling images in a single format - (e.g. ft_glyph_format_outline). Its functions are used to: - - - transform an glyph image - - render a glyph image into a bitmap - - return the control box (dimensions) of a given glyph image - - The scan converters `ftraster.c' and `ftgrays.c' have been moved - to the new directory `src/renderer', and are used to provide two - default renderer modules. - - One corresponds to the `standard' scan-converter, the other to - the `smooth' one. - - he current renderer can be set through the new function - FT_Set_Renderer. - - The old raster-related function FT_Set_Raster, FT_Get_Raster and - FT_Set_Raster_Mode have now disappeared, in favor of the new: - - FT_Get_Renderer - FT_Set_Renderer - - See the file for more details. - - These changes were necessary to properly support different - scalable formats in the future, like bi-color glyphs, etc. - - * Glyph loader object: - - A new internal object, called a 'glyph loader' has been - introduced in the base layer. It is used by all scalable format - font drivers to load glyphs and composites. - - This object has been created to reduce the code size of each - driver, as each one of them basically re-implemented its - functionality. - - See and the FT_GlyphLoader type for - more information. - - * FT_GlyphSlot has new fields: - - In order to support extended features (see below), the - FT_GlyphSlot structure has a few new fields: - - linearHoriAdvance: - - This field gives the linearly scaled (i.e. scaled but - unhinted) advance width for the glyph, expressed as a 16.16 - fixed pixel value. This is useful to perform WYSIWYG text. - - linearVertAdvance: - This field gives the linearly scaled advance height for the - glyph (relevant in vertical glyph layouts only). This is - useful to perform WYSIWYG text. - - Note that the two above field replace the removed `metrics2' - field in the glyph slot. - - advance: - This field is a vector that gives the transformed advance for - the glyph. By default, it corresponds to the advance width, - unless FT_LOAD_VERTICAL_LAYOUT was specified when calling - FT_Load_Glyph or FT_Load_Char. - - bitmap_left: - This field gives the distance in integer pixels from the - current pen position to the left-most pixel of a glyph image - IF IT IS A BITMAP. It is only valid when the `format' field - is set to `ft_glyph_format_bitmap', for example, after calling - the new function FT_Render_Glyph. - - bitmap_top: - This field gives the distance in integer pixels from the - current pen position (located on the baseline) to the top-most - pixel of the glyph image IF IT IS A BITMAP. Positive values - correspond to upwards Y. - - loader: - This is a new private field for the glyph slot. Client - applications should not touch it. - - - * Support for transforms and direct rendering in FT_Load_Glyph: - - Most of the functionality found in has been - moved to the core library. Hence, the following: - - - A transform can be specified for a face through - FT_Set_Transform. this transform is applied by FT_Load_Glyph - to scalable glyph images (i.e. NOT TO BITMAPS) before the - function returns, unless the bit flag FT_LOAD_IGNORE_TRANSFORM - was set in the load flags. - - - Once a glyph image has been loaded, it can be directly - converted to a bitmap by using the new FT_Render_Glyph - function. Note that this function takes the glyph image from - the glyph slot, and converts it to a bitmap whose properties - are returned in `face.glyph.bitmap', `face.glyph.bitmap_left' - and `face.glyph.bitmap_top'. The original native image might - be lost after the conversion. - - - When using the new bit flag FT_LOAD_RENDER, the FT_Load_Glyph - and FT_Load_Char functions will call FT_Render_Glyph - automatically when needed. - - - Reformatted all modules source code in order to get rid of the - basic data types redefinitions (i.e. `TT_Int' instead of `FT_Int', - `T1_Fixed' instead of `FT_Fixed'). Hence the format-specific - prefixes like `TT_', `T1_', `T2_' and `CID_' are only used for - relevant structures. - - -====================================================================== - -OLD CHANGES FOR BETA 7 - - - bug-fixed the OpenType/CFF parser. It now loads and displays my - two fonts nicely, but I'm pretty certain that more testing is - needed :-) - - - fixed the crummy Type 1 hinter, it now handles accented characters - correctly (well, the accent is not always well placed, but that's - another problem..) - - - added the CID-keyed Type 1 driver in `src/cid'. Works pretty well - for only 13 Kb of code ;-) Doesn't read AFM files though, nor the - really useful CMAP files.. - - - fixed two bugs in the smooth renderer (src/base/ftgrays.c). - Thanks to Boris Letocha for spotting them and providing a fix. - - - fixed potential `divide by zero' bugs in ftcalc.c. - - - added source code for the OpenType/CFF driver (still incomplete - though..) - - - modified the SFNT driver slightly to perform more robust header - checks in TT_Load_SFNT_Header. This prevents certain font files - (e.g. some Type 1 Multiple Masters) from being incorrectly - `recognized' as TrueType font files.. - - - moved a lot of stuff from the TrueType driver to the SFNT module, - this allows greater code re-use between font drivers - (e.g. TrueType, OpenType, Compact-TrueType, etc..) - - - added a tiny segment cache to the SFNT Charmap 4 decoder, in order - to minimally speed it up.. - - - added support for Multiple Master fonts in `type1z'. There is - also a new file named which defines functions to - manage them from client applications. - - The new file `src/base/ftmm.c' is also optional to the engine.. - - - various formatting changes (e.g. EXPORT_DEF -> FT_EXPORT_DEF) + - small bug fixes in FT_Load_Glyph, the `type1' driver, etc.. - - - a minor fix to the Type 1 driver to let them apply the font matrix - correctly (used for many oblique fonts..) - - - some fixes for 64-bit systems (mainly changing some FT_TRACE calls - to use %p instead of %lx). Thanks to Karl Robillard. - - - fixed some bugs in the sbit loader (src/base/sfnt/ttsbit.c) + - added a new flag, FT_LOAD_CROP_BITMAP to query that bitmaps be - cropped when loaded from a file (maybe I should move the bitmap - cropper to the base layer ??). - - - changed the default number of gray levels of the smooth renderer - to 256 (instead of the previous 128). Of course, the human eye - can't see any difference ;-) - - - removed TT_MAX_SUBGLYPHS, there is no static limit on the number - of subglyphs in a TrueType font now.. - - -====================================================================== - -OLD CHANGES 16 May 2000 - - - tagged `BETA-6' in the CVS tree. This one is a serious release - candidate even though it doesn't incorporate the auto-hinter yet.. - - - various obsolete files were removed, and copyright header updated - - - finally updated the standard raster to fix the monochrome - rendering bug + re-enable support for 5-gray levels anti-aliasing - (suck, suck..) - - - created new header files, and modified sources accordingly: - - - - simple FreeType types, without the API - - - definition of memory-management macros - - - added the `DSIG' (OpenType Digital Signature) tag to - - - - light update/cleaning of the build system + changes to the sources - in order to get rid of _all_ compiler warnings with three - compilers, i.e: - - gcc with `-ansi -pedantic -Wall -W', Visual C++ with `/W3 /WX' and - LCC - - IMPORTANT NOTE FOR WIN32-LCC USERS: - | - | It seems the C pre-processor that comes with LCC is broken, it - | doesn't recognize the ANSI standard directives # and ## - | correctly when one of the argument is a macro. Also, - | something like: - | - | #define F(x) print##x - | - | F(("hello")) - | - | will get incorrectly translated to: - | - | print "hello") - | - | by its pre-processor. For this reason, you simply cannot build - | FreeType 2 in debug mode with this compiler.. - - - yet another massive grunt work. I've changed the definition of - the EXPORT_DEF, EXPORT_FUNC, BASE_DEF & BASE_FUNC macros. These - now take an argument, which is the function's return value type. - - This is necessary to compile FreeType as a DLL on Windows and - OS/2. Depending on the compiler used, a compiler-specific keyword - like __export or __system must be placed before (VisualC++) or - after (BorlandC++) the type.. - - Of course, this needed a lot of changes throughout the source code - to make it compile again... All cleaned up now, apparently.. - - Note also that there is a new EXPORT_VAR macro defined to allow - the _declaration_ of an exportable public (constant) - variable. This is the case of the raster interfaces (see - ftraster.h and ftgrays.h), as well as each module's interface (see - sfdriver.h, psdriver.h, etc..) - - - new feature: it is now possible to pass extra parameters to font - drivers when creating a new face object. For now, - this capability is unused. It could however prove to - be useful in a near future.. - - the FT_Open_Args structure was changes, as well as the internal - driver interface (the specific `init_face' module function has - now a different signature). - - - updated the tutorial (not finished though). - - - updated the top-level BUILD document - - - fixed a potential memory leak that could occur when loading - embedded bitmaps. - - - added the declaration of FT_New_Memory_Face in - , as it was missing from the public header - (the implementation was already in `ftobjs.c'). - - - the file has been seriously updated in order - to allow the automatic generation of error message tables. See - the comments within it for more information. - - - major directory hierarchy re-organisation. This was done for two - things: - - * first, to ease the `manual' compilation of the library by - requiring at lot less include paths :-) - - * second, to allow external programs to effectively access - internal data fields. For example, this can be extremely - useful if someone wants to write a font producer or a font - manager on top of FreeType. - - Basically, you should now use the 'freetype/' prefix for header - inclusion, as in: - - #include - #include - - Some new include sub-directories are available: - - a. the `freetype/config' directory, contains two files used to - configure the build of the library. Client applications - should not need to look at these normally, but they can if - they want. - - #include - #include - - b. the `freetype/internal' directory, contains header files that - describes library internals. These are the header files that - were previously found in the `src/base' and `src/shared' - directories. - - - As usual, the build system and the demos have been updated to - reflect the change.. - - Here's a layout of the new directory hierarchy: - - TOP_DIR - include/ - freetype/ - freetype.h - ... - config/ - ftoption.h - ftconfig.h - ftmodule.h - - internal/ - ftobjs.h - ftstream.h - ftcalc.h - ... - - src/ - base/ - ... - - sfnt/ - psnames/ - truetype/ - type1/ - type1z/ - - - Compiling a module is now much easier, for example, the following - should work when in the TOP_DIR directory on an ANSI build: - - gcc -c -I./include -I./src/base src/base/ftbase.c - gcc -c -I./include -I./src/sfnt src/sfnt/sfnt.c - etc.. - - (of course, using -Iconfig/ if you provide system-specific - configuration files). - - - updated the structure of FT_Outline_Funcs in order to allow direct - coordinate scaling within the outline decomposition routine (this - is important for virtual `on' points with TrueType outlines) + - updates to the rasters to support this.. - - - updated the OS/2 table loading code in `src/sfnt/ttload.c' in - order to support version 2 of the table (see OpenType 1.2 spec) - - - created `include/tttables.h' and `include/t1tables.h' to allow - client applications to access some of the SFNT and T1 tables of a - face with a procedural interface (see `FT_Get_Sfnt_Table') + - updates to internal source files to reflect the change.. - - - some cleanups in the source code to get rid of warnings when - compiling with the `-Wall -W -ansi -pedantic' options in gcc. - - - debugged and moved the smooth renderer to `src/base/ftgrays.c' and - its header to `include/ftgrays.h' - - - updated TT_MAX_SUBGLYPHS to 96 as some CJK fonts have composites - with up to 80 sub-glyphs !! Thanks to Werner - - -====================================================================== - -OLD CHANGES - 14-apr-2000 - - - fixed a bug in the TrueType glyph loader that prevented the - correct loading of some CJK glyphs in mingli.ttf - - - improved the standard Type 1 hinter in `src/type1' - - - fixed two bugs in the experimental Type 1 driver in `src/type1z' - to handle the new XFree86 4.0 fonts (and a few other ones..) - - - the smooth renderer is now complete and supports sub-banding to - render large glyphs at high speed. However, it is still located - in `demos/src/ftgrays.c' and should move to the library itself in - the next beta. NOTE: The smooth renderer doesn't compile in - stand-alone mode anymore, but this should be fixed RSN.. - - - introduced convenience functions to more easily deal with glyph - images, see `include/ftglyph.h' for more details, as well as the - new demo program named `demos/src/ftstring.c' that demonstrates - its use - - - implemented FT_LOAD_NO_RECURSE in both the TrueType and Type 1 - drivers (this is required by the auto-hinter to improve its - results). - - - changed the raster interface, in order to allow client - applications to provide their own span-drawing callbacks. - However, only the smooth renderer supports this. See - `FT_Raster_Params' in the file `include/ftimage.h'. - - - fixed a small bug in FT_MulFix that caused incorrect transform - computation! - - - Note: The tutorial is out-of-date. - - -====================================================================== - -OLD CHANGES - 12-mar-2000 - - - changed the layout of configuration files : now, all ANSI - configuration files are located in - `freetype2/config'. System-specific over-rides can be placed in - `freetype2/config/'. - - - moved all configuration macros to `config/ftoption.h' - - - improvements in the Type 1 driver with AFM support - - - changed the fields in the FT_Outline structure : the old `flags' - array is re-named `tags', while all ancient flags are encoded into - a single unsigned int named `flags'. - - - introduced new flags in FT_Outline.flags (see - ft_outline_.... enums in `ftimage.h'). - - - changed outline functions to `FT_Outline_' syntax - - - added a smooth anti-alias renderer to the demonstration programs - - - added Mac graphics driver (thanks Just) - - - FT_Open_Face changed in order to received a pointer to a - FT_Open_Args descriptor.. - - - various cleanups, a few more API functions implemented (see - FT_Attach_File) - - - updated some docs - - -====================================================================== - -OLD CHANGES - 22-feb-2000 - - - introduced the `psnames' module. It is used to: - - o convert a Postscript glyph name into the equivalent Unicode - character code (used by the Type 1 driver(s) to synthesize on - the fly a Unicode charmap). - - o provide an interface to retrieve the Postscript names of the - Macintosh, Adobe Standard & Adobe Expert character codes. - (the Macintosh names are used by the SFNT-module postscript - names support routines, while the other two tables are used by - the Type 1 driver(s)). - - - introduced the `type1z' alternate Type 1 driver. This is a (still - experimental) driver for the Type 1 format that will ultimately - replace the one in `src/type1'. It uses pattern matching to load - data from the font, instead of a finite state analyzer. It works - much better than the `old' driver with `broken' fonts. It is also - much smaller (under 15 Kb). - - - the Type 1 drivers (both in `src/type1' and `src/type1z') are - nearly complete. They both provide automatic Unicode charmap - synthesis through the `psnames' module. No re-encoding vector is - needed. (note that they still leak memory due to some code - missing, and I'm getting lazy). - - Trivial AFM support has been added to read kerning information but - wasn't exactly tested as it should ;-) - - - The TrueType glyph loader has been seriously rewritten (see the - file `src/truetype/ttgload.c'. It is now much, much simpler as - well as easier to read, maintain and understand :-) Preliminary - versions introduced a memory leak that has been reported by Jack - Davis, and is now fixed.. - - - introduced the new `ft_glyph_format_plotter', used to represent - stroked outlines like Windows `Vector' fonts, and certain Type 1 - fonts like `Hershey'. The corresponding raster will be written - soon. - - - FT_New_Memory_Face is gone. Likewise, FT_Open_Face has a new - interface that uses a structure to describe the input stream, the - driver (if required), etc.. - - -TODO - - - Write FT_Get_Glyph_Bitmap and FT_Load_Glyph_Bitmap - - - Add a function like FT_Load_Character(face, char_code, load_flags) - that would really embed a call to FT_Get_Char_Index then - FT_Load_Glyph to ease developer's work. - - - Update the tutorial! - - - consider adding support for Multiple Master fonts in the Type 1 - drivers. - - - Test the AFM routines of the Type 1 drivers to check that kerning - information is returned correctly. - - - write a decent auto-gridding component !! We need this to release - FreeType 2.0 gold ! - - -less urgent needs: - - - add a CFF/Type2 driver - - add a BDF driver - - add a FNT/PCF/HBF driver - - add a Speedo driver from the X11 sources - - -====================================================================== - -OLDER CHANGES - 27-jan-2000 - - - updated the `sfnt' module interface to allow several SFNT-based - drivers to co-exist peacefully - - - updated the `T1_Face' type to better separate Postscript font - content from the rest of the FT_Face structure. Might be used - later by the CFF/Type2 driver.. - - - added an experimental replacement Type 1 driver featuring advanced - (and speedy) pattern matching to retrieve the data from postscript - fonts. - - - very minor changes in the implementation of FT_Set_Char_Size and - FT_Set_Pixel_Sizes (they now implement default to lighten the font - driver's code). - - -====================================================================== - -OLD MESSAGE - -This file summarizes the changes that occurred since the last `beta' -of FreeType 2. Because the list is important, it has been divided into -separate sections: - -Table Of Contents: - - I High-Level Interface (easier !) - II Directory Structure - III Glyph Image Formats - IV Build System - V Portability - VI Font Drivers - - ----------------------------------------------------------------------- - -High-Level Interface: - - The high-level API has been considerably simplified. Here is how: - - - resource objects have disappeared. this means that face objects - can now be created with a single function call (see FT_New_Face - and FT_Open_Face) - - - when calling either FT_New_Face & FT_Open_Face, a size object - and a glyph slot object are automatically created for the face, - and can be accessed through `face->glyph' and `face->size' if - one really needs to. In most cases, there's no need to call - FT_New_Size or FT_New_Glyph. - - - similarly, FT_Load_Glyph now only takes a `face' argument - (instead of a glyph slot and a size). Also, its `result' - parameter is gone, as the glyph image type is returned in the - field `face->glyph.format' - - - the list of available charmaps is directly accessible through - `face->charmaps', counting `face->num_charmaps' elements. Each - charmap has an 'encoding' field which specifies which known - encoding it deals with. Valid values are, for example: - - ft_encoding_unicode (for ASCII, Latin-1 and Unicode) - ft_encoding_apple_roman - ft_encoding_sjis - ft_encoding_adobe_standard - ft_encoding_adobe_expert - - other values may be added in the future. Each charmap still - holds its `platform_id' and `encoding_id' values in case the - encoding is too exotic for the current library - - ----------------------------------------------------------------------- - -Directory Structure: - - Should seem obvious to most of you: - - freetype/ - config/ -- configuration sub-makefiles - ansi/ - unix/ -- platform-specific configuration files - win32/ - os2/ - msdos/ - - include/ -- public header files, those to be included - directly by client apps - - src/ -- sources of the library - base/ -- the base layer - sfnt/ -- the sfnt `driver' (see the drivers section - below) - truetype/ -- the truetype driver - type1/ -- the type1 driver - shared/ -- some header files shared between drivers - - demos/ -- demos/tools - - docs/ -- documentation (a bit empty for now) - - ----------------------------------------------------------------------- - -Glyph Image Formats: - - Drivers are now able to register new glyph image formats within the - library. For now, the base layer supports of course bitmaps and - vector outlines, but one could imagine something different like - colored bitmaps, bi-color vectors or whatever else (Metafonts anyone - ??). - - See the file `include/ftimage.h'. Note also that the type - FT_Raster_Map is gone, and is now replaced by FT_Bitmap, which - should encompass all known bitmap types. - - Each new image format must provide at least one `raster', i.e. a - module capable of transforming the glyph image into a bitmap. It's - also possible to change the default raster used for a given glyph - image format. - - The default outline scan-converter now uses 128 levels of grays by - default, which tends to smooth many things. Note that the demo - programs have been updated significantly in order to display these.. - - ----------------------------------------------------------------------- - -Build system: - - You still need GNU Make to build the library. The build system has - been very seriously re-vamped in order to provide things like : - - - automatic host platform detection (reverting to 'config/ansi' if - it is not detected, with pseudo-standard compilation flags) - - - the ability to compile from the Makefiles with very different and - exotic compilers. Note that linking the library can be difficult - for some platforms. - - For example, the file `config/win32/lcclib.bat' is invoked by the - build system to create the `.lib' file with LCC-Win32 because its - librarian has too many flaws to be invoked directly from the - Makefile. - - Here's how it works: - - - the first time you type `make', the build system runs a series of - sub-makefiles in order to detect your host platform. It then - dumps what it found, and creates a file called `config.mk' in the - current directory. This is a sub-Makefile used to define many - important Make variables used to build the library. - - - the second time, the build system detects the `config.mk' then use - it to build the library. All object files go into 'obj' by - default, as well as the library file, but this can easily be - changed. - - Note that you can run `make setup' to force another host platform - detection even if a `config.mk' is present in the current - directory. Another solution is simply to delete the file, then - re-run make. - - Finally, the default compiler for all platforms is gcc (for now, - this will hopefully changed in the future). You can however specify - a different compiler by specifying it after the 'setup' target as - in: - - gnumake setup lcc on Win32 to use the LCC compiler - gnumake setup visualc on Win32 to use Visual C++ - - See the file `config//detect.mk' for a list of supported - compilers for your platforms. - - It should be relatively easy to write new detection rules files and - config.mk.. - - Finally, to build the demo programs, go to `demos' and launch GNU - Make, it will use the `config.mk' in the top directory to build the - test programs.. - - ----------------------------------------------------------------------- - -Portability: - - In the previous beta, a single FT_System object was used to - encompass all low-level operations like thread synchronisation, - memory management and i/o access. This has been greatly simplified: - - - thread synchronisation has been dropped, for the simple reason - that the library is already re-entrant, and that if you really - need two threads accessing the same FT_Library, you should - really synchronize access to it yourself with a simple mutex. - - - memory management is performed through a very simple object - called `FT_Memory', which really is a table containing a table - of pointers to functions like malloc, realloc and free as well - as some user data (closure). - - - resources have disappeared (they created more problems than they - solved), and i/o management have been simplified greatly as a - result. Streams are defined through FT_Stream objects, which - can be either memory-based or disk-based. - - Note that each face has its own stream, which is closed only - when the face object is destroyed. Hence, a function like - TT_Flush_Face in 1.x cannot be directly supported. However, if - you really need something like this, you can easily tailor your - own streams to achieve the same feature at a lower level (and - use FT_Open_Face instead of FT_New_Face to create the face). - - See the file `include/ftsystem.h' for more details, as well as the - implementations found in `config/unix' and `config/ansi'. - - ----------------------------------------------------------------------- - -Font Drivers: - - The Font Driver interface has been modified in order to support - extensions & versioning. - - - The list of the font drivers that are statically linked to the - library at compile time is managed through a new configuration file - called `config//ftmodule.h'. - - This file is autogenerated when invoking `make modules'. This - target will parse all sub-directories of 'src', looking for a - `module.mk' rules file, used to describe the driver to the build - system. - - Hence, one should call `make modules' each time a font driver is - added or removed from the `src' directory. - - Finally, this version provides a `pseudo-driver' in `src/sfnt'. - This driver doesn't support font files directly, but provides - services used by all TrueType-like font drivers. Hence, its code is - shared between the TrueType & OpenType font formats, and possibly - more formats to come if we're lucky.. - - ----------------------------------------------------------------------- - -Extensions support: - - The extensions support is inspired by the one found in 1.x. - - Now, each font driver has its own `extension registry', which lists - which extensions are available for the font faces managed by the - driver. - - Extension ids are now strings, rather than 4-byte tags, as this is - usually more readable. - - Each extension has: - - some data, associated to each face object - - an interface (table of function pointers) - - An extension that is format-specific should simply register itself - to the correct font driver. Here is some example code: - - // Registering an extensions - // - FT_Error FT_Init_XXXX_Extension( FT_Library library ) - { - FT_DriverInterface* tt_driver; - - driver = FT_Get_Driver( library, "truetype" ); - if (!driver) return FT_Err_Unimplemented_Feature; - - return FT_Register_Extension( driver, &extension_class ); - } - - - // Implementing the extensions - // - FT_Error FT_Proceed_Extension_XXX( FT_Face face ) - { - FT_XXX_Extension ext; - FT_XXX_Extension_Interface ext_interface; - - ext = FT_Get_Extension( face, "extensionid", &ext_interface ); - if (!ext) return error; - - return ext_interface->do_it(ext); - } - ------------------------------------------------------------------------- - -Copyright (C) 2000-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute this -file you indicate that you have read the license and understand and -accept it fully. - - -Local Variables: -version-control: never -coding: utf-8 -End: - ---- end of CHANGES --- diff --git a/freetype/docs/CMAKE b/freetype/docs/CMAKE deleted file mode 100644 index 31237ae..0000000 --- a/freetype/docs/CMAKE +++ /dev/null @@ -1,2 +0,0 @@ -Support for a cmake build has been contributed. See the remarks in the -top-level `CMakeLists.txt' file for more. diff --git a/freetype/docs/CUSTOMIZE b/freetype/docs/CUSTOMIZE deleted file mode 100644 index 80527db..0000000 --- a/freetype/docs/CUSTOMIZE +++ /dev/null @@ -1,152 +0,0 @@ -How to customize the compilation of the library -=============================================== - - FreeType is highly customizable to fit various needs, and this - document describes how it is possible to select options and - components at compilation time. - - -I. Configuration macros - - The file `include/freetype/config/ftoption.h' contains a list of - commented configuration macros that can be toggled by developers to - indicate which features should be active while building the library. - - These options range from debug level to availability of certain - features, like native TrueType hinting through a bytecode - interpreter. - - We invite you to read this file for more information. You can - change the file's content to suit your needs, or override it with - one of the techniques described below. - - -II. Modules list - - If you use GNU make please edit the top-level file `modules.cfg'. - It contains a list of available FreeType modules and extensions to - be compiled. Change it to suit your own preferences. Be aware that - certain modules depend on others, as described in the file. GNU - make uses `modules.cfg' to generate `ftmodule.h' (in the object - directory). - - If you build FreeType in a directory separate from the source files, - put your customized `modules.cfg' in that directory; that way you - can keep the source files `clean'. - - If you don't use GNU make you have to manually edit the file - `include/freetype/config/ftmodule.h' (which is *not* used with if - compiled with GNU make) to add or remove the drivers and components - you want to compile into the library. See `INSTALL.ANY' for more - information. - - -III. System interface - - FreeType's default interface to the system (i.e., the parts that - deal with memory management and i/o streams) is located in - `src/base/ftsystem.c'. - - The current implementation uses standard C library calls to manage - memory and to read font files. It is however possible to write - custom implementations to suit specific systems. - - To tell the GNU Make-based build system to use a custom system - interface, you have to define the environment variable FTSYS_SRC to - point to the relevant implementation: - - on Unix: - - ./configure - export FTSYS_SRC=foo/my_ftsystem.c - make - make install - - on Windows: - - make setup - set FTSYS_SRC=foo/my_ftsystem.c - make - - -IV. Overriding default configuration and module headers - - It is possible to override the default configuration and module - headers without changing the original files. There are three ways - to do that: - - - 1. With GNU make - - [This is actually a combination of method 2 and 3.] - - Just put your custom `ftoption.h' file into the objects directory - (normally `/objs' if you build in the source tree, or the - directory where you invoke configure if you build in a separate - directory), which GNU make prefers over the standard location. No - action is needed for `ftmodule.h' because it is generated - automatically in the objects directory. - - 2. Using the C include path - - Use the C include path to ensure that your own versions of the - files are used at compile time when the lines - - #include FT_CONFIG_OPTIONS_H - #include FT_CONFIG_MODULES_H - - are compiled. Their default values being - and , you - can do something like: - - custom/ - config/ - ftoption.h => custom options header - ftmodule.h => custom modules list - - include/ => normal FreeType 2 include - ... - - then change the C include path to always give the path to `custom' - before the FreeType 2 `include'. - - - 3. Redefining FT_CONFIG_OPTIONS_H and FT_CONFIG_MODULES_H - - Another way to do the same thing is to redefine the macros used to - name the configuration headers. To do so, you need a custom - `ft2build.h' whose content can be as simple as: - - #ifndef FT2_BUILD_MY_PLATFORM_H_ - #define FT2_BUILD_MY_PLATFORM_H_ - - #define FT_CONFIG_OPTIONS_H - #define FT_CONFIG_MODULES_H - - #include - - #endif /* FT2_BUILD_MY_PLATFORM_H_ */ - - Place those files in a separate directory, e.g., - - custom/ - ft2build.h => custom version described above - my-ftoption.h => custom options header - my-ftmodule.h => custom modules list header - - and change the C include path to ensure that `custom' is always - placed before the FT2 `include' during compilation. - ----------------------------------------------------------------------- - -Copyright (C) 2003-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute -this file you indicate that you have read the license and understand -and accept it fully. - - ---- end of CUSTOMIZE --- diff --git a/freetype/docs/DEBUG b/freetype/docs/DEBUG deleted file mode 100644 index 7398df6..0000000 --- a/freetype/docs/DEBUG +++ /dev/null @@ -1,310 +0,0 @@ -Debugging within the FreeType sources -===================================== - -I. Configuration macros ------------------------ - -There are several ways to enable debugging features in a FreeType 2 -builds. This is controlled through the definition of special macros -located in the file `ftoption.h'. The macros are: - - - FT_DEBUG_LEVEL_ERROR - - #define this macro if you want to compile the `FT_ERROR' macro - calls to print error messages during program execution. This does - not stop the program. Very useful to spot invalid fonts during - development and to code workarounds for them. - - FT_DEBUG_LEVEL_TRACE - - #define this macro if you want to compile both macros `FT_ERROR' - and `FT_TRACE'. This also includes the variants `FT_TRACE0', - `FT_TRACE1', `FT_TRACE2', ..., `FT_TRACE7'. - - The trace macros are used to send debugging messages when an - appropriate `debug level' is configured at runtime through the - `FT2_DEBUG' environment variable (more on this later). - - FT_DEBUG_MEMORY - - If this macro is #defined, the FreeType engine is linked with a - small but effective debugging memory manager that tracks all - allocations and frees that are performed within the font engine. - - When the `FT2_DEBUG_MEMORY' environment variable is defined at - runtime, a call to `FT_Done_FreeType' dumps memory statistics, - including the list of leaked memory blocks and optionally with the - source locations where these were allocated. It is always a very - good idea to define this in development builds. This works with - _any_ program linked to FreeType, but requires a big deal of - memory (the debugging memory manager never frees the blocks to the - heap in order to detect double frees). - - When `FT2_DEBUG_MEMORY' isn't defined at runtime, the debugging - memory manager is ignored, and performance is unaffected. - - FT_DEBUG_LOGGING - - #define this macro for enhanced logging support; it automatically - sets `FT_DEBUG_LEVEL_TRACE' and `FT_DEBUG_LEVEL_ERROR'. - - If defined, `FT_TRACE' and `FT_ERROR' can send tracing and - debugging messages to a file. The location of the log file has to - be set with the `FT_LOGGING_FILE' environment variable (more on - this later). - - The main enhancements are the possibility of logging the time and - the name of the `FT_COMPONENT' macro together with the affected - `FT_TRACE' or `FT_ERROR' calls. See below how to activate this in - the `FT2_DEBUG' environment variable. - - -II. Debugging macros --------------------- - -Several macros can be used within the FreeType sources to help -debugging its code: - - - 1. FT_ERROR(( ... )) - - This macro is used to send debug messages that indicate relatively - serious errors (like broken font files) without stopping the - execution of the running program. Its code is compiled only when - either `FT_DEBUG_LEVEL_ERROR' or `FT_DEBUG_LEVEL_TRACE' are - defined in `ftoption.h'. - - Note that you have to use a printf-like signature, but with double - parentheses, like in - - FT_ERROR(( "your %s is not %s\n", "foo", "bar" )); - - - 2. FT_ASSERT( condition ) - - This macro is used to check strong assertions at runtime. If its - condition isn't TRUE, the program aborts with a panic message. - Its code is compiled when either `FT_DEBUG_LEVEL_ERROR' or - `FT_DEBUG_LEVEL_TRACE' are defined. You don't need double - parentheses here. Example: - - FT_ASSERT( ptr != NULL ); - - - 3. FT_TRACE( level, (message...) ) - - The `FT_TRACE' macro is used to send general-purpose debugging - messages during program execution. This macro uses an *implicit* - macro named `FT_COMPONENT', which names the current FreeType - component being run. - - The developer should always define `FT_COMPONENT' as appropriate, - for example as in - - #undef FT_COMPONENT - #define FT_COMPONENT io - - The value of the `FT_COMPONENT' macro is one of the component - names defined in the internal file `internal/fttrace.h'. If you - modify the FreeType source code and insert a new `FT_COMPONENT' - macro, you must register it in `fttrace.h'. If you insert or - remove many trace macros, you can test for undefined or unused - trace macros with the script `src/tools/chktrcmp.py'. - - Each such component is assigned a `debug level', ranging from - value 0 to 7, through the use of the `FT2_DEBUG' environment - variable (described below) when a program linked with FreeType - starts. - - When `FT_TRACE' is called, its level is compared to the one of the - corresponding component. Messages with trace levels *higher* than - the corresponding component level are filtered out and never - printed. This means that trace messages with level 0 are always - printed, those with level 2 are only printed when the component - level is *at least* 2, etc. - - The second parameter to `FT_TRACE' must contain parentheses and - corresponds to a printf-like call, as in - - FT_TRACE( 2, ( "your %s is not %s\n", "foo", "bar" ) ) - - The shortcut macros `FT_TRACE0', `FT_TRACE1', `FT_TRACE2', ..., - `FT_TRACE7' can be used with constant level indices, and are much - cleaner to use, as in - - FT_TRACE2(( "your %s is not %s\n", "foo", "bar" )); - - -III. Environment variables --------------------------- - -The following environment variables control debugging output and -behaviour of FreeType at runtime. - - - FT2_DEBUG - - This variable is only used when FreeType is built with - `FT_DEBUG_LEVEL_TRACE' defined. It contains a list of component - level definitions, following this format: - - component1:level1 component2:level2 component3:level3 ... - - where `componentX' is the name of a tracing component, as defined - in `fttrace.h'. `levelX' is the corresponding level to use at - runtime. - - `any' is a special component name that is interpreted as `any/all - components'. For example, the following definitions - - set FT2_DEBUG=any:2 memory:5 io:4 (on Windows) - export FT2_DEBUG="any:2 memory:5 io:4" (on Linux with bash) - - both stipulate that all components should have level 2, except for - the memory and io components, which are set to the trace levels 5 - and 4, respectively. - - If `FT_DEBUG_LOGGING' is defined, two more options are available. - - * -v: Print also the name of FreeType's component from which the - current log is produced, together with the tracing level. - - * -t: Print also the time. - - Here are some examples how the output might look like. - - FT2_DEBUG="any:7 memory:5 -vt" - - => [20:32:02:44969 ttload:2] table directory loaded - - FT2_DEBUG="any:7 memory:5 -t" - - => [20:32:02:44969] table directory loaded - - FT2_DEBUG="any:7 memory:5 -v" - - => [ttload:2] table directory loaded - - - FT_LOGGING_FILE - - This variable is only used if FreeType is built with the - `FT_DEBUG_LOGGING' macro defined. It contains the path to the - file where the user wants to put his log file. If it is not set, - FreeType uses stderr. - - Examples: - - On UNIX-like systems with bash: - export FT_LOGGING_FILE="/tmp/freetype2.log" - - On Windows: - set FT_LOGGING_FILE=C:\Users\AppData\Local\Temp\freetype2.log - - - FT2_DEBUG_MEMORY - - This environment variable, when defined, tells FreeType to use a - debugging memory manager that tracks leaking memory blocks as well - as other common errors like double frees. It is also capable of - reporting _where_ the leaking blocks were allocated, which - considerably saves time when debugging new additions to the - library. - - This code is only compiled when FreeType is built with the - `FT_DEBUG_MEMORY' macro #defined in `ftoption.h' though, it is - ignored in other builds. - - - FT2_ALLOC_TOTAL_MAX - - This variable is ignored if `FT2_DEBUG_MEMORY' is not defined. It - allows you to specify a maximum heap size for all memory - allocations performed by FreeType. This is very useful to test - the robustness of the font engine and programs that use it in - tight memory conditions. - - If it is undefined, or if its value is not strictly positive, no - allocation bounds are checked at runtime. - - - FT2_ALLOC_COUNT_MAX - - This variable is ignored if `FT2_DEBUG_MEMORY' is not defined. It - allows you to specify a maximum number of memory allocations - performed by FreeType before returning the error - `FT_Err_Out_Of_Memory'. This is useful for debugging and testing - the engine's robustness. - - If it is undefined, or if its value is not strictly positive, no - allocation bounds are checked at runtime. - - - FT2_KEEP_ALIVE - - This variable is ignored if `FT2_DEBUG_MEMORY' is not defined. - `Keep alive' means that freed blocks aren't released to the heap. - This is useful to detect double-frees or weird heap corruption, - reporting the source code location of the original allocation and - deallocation in case of a problem. It uses large amounts of - memory, however. - - If it is undefined, or if its value is not strictly positive, - freed blocks are released at runtime. - - -IV. Additional Capabilities with `FT_DEBUG_LOGGING' ---------------------------------------------------- - -If `FT_DEBUG_LOGGING' is defined, four APIs are available to provide -additional debugging support. Use - - #include - -to access them. - - FT_Trace_Set_Level( const char* level ) - - By default, FreeType uses the tracing levels set in the - `FT2_DEBUG' environment variable. Use this function to override - the value with `level'. Use value `NULL' to disable tracing. - - FT_Trace_Set_Default_Level( void ) - - Reset the tracing levels to the default value, i.e., the value of - the `FT2_DEBUG' environment variable or no tracing if not set. - - FT_Set_Log_Handler( ft_custom_log_handler handler ) - - Use `handler' as a custom handler for formatting tracing and error - messages. The `ft_custom_log_handler' typedef has the following - prototype. - - void - (*ft_custom_log_handler)( const char* ft_component, - const char* fmt, - va_list args ); - - `ft_component' is the current component like `ttload', `fmt' is the - first argument of `FT_TRACE' or `FT_ERROR', and `args' holds the - remaining arguments. - - FT_Set_Default_Log_Handler( void ) - - Reset the log handler to the default version. - - ------------------------------------------------------------------------- - -Copyright (C) 2002-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute this -file you indicate that you have read the license and understand and -accept it fully. - - ---- end of DEBUG --- diff --git a/freetype/docs/DOCGUIDE b/freetype/docs/DOCGUIDE deleted file mode 100644 index b46b7bd..0000000 --- a/freetype/docs/DOCGUIDE +++ /dev/null @@ -1,298 +0,0 @@ -Introduction ------------- - -Documentation is an extremely important part of any project, and it -helps a lot if it uses consistent syntax and layout. - -The documentation for the FreeType library is maintained in header -files in the `include/` directory in the form of code comments. These -comments are extracted and organized by 'docwriter' (previously -'docmaker'). The generated docs can be viewed in the -`docs/reference/site/` directory after running `make refdoc`. - -Documentation comments follow a specific structure and format as -described below. - - -Documentation Structure ------------------------ - -The documentation is divided into multiple chapters, which contain -sections relevant to it. The chapter details and sections contained -in them are listed in `include/freetype/ftchapters.h`. Any unlisted -section is added to the 'Miscellaneous' chapter. - -Sections may contain sub-sections which consist of properties, -enumerations, and other data types. - - -Comment Blocks --------------- - -Documentation blocks follow a specific format: - - /***************************** (should end on column 77) - * - * (1 asterisk, 1 space, then content) - * - */ (end of block) - -To make 'docwriter' recognize a comment block, there must be at least -two asterisks in the first line. As a consequence, you should change -the second asterisk to something else if you want to prevent a comment -block being handled by 'docwriter' (for example, change `/****/` to -`/*#**/`). - - -Markup Tags ------------ - -Markup tags are used to indicate what comes next. The syntax for a -tag is: - - @foo: - -An `@`, followed by the tag, and then `:`. - - -Reserved Tags -------------- - -There are some keywords that have a special meaning to docwriter. -As a convention, all keywords are written in lowercase. - -* `chapter`: Defines a chapter. Usually the title with underscores. -* `sections`: List of sections in the chapter, in order. -* `section`: Defines the start or continuation of a section. -* `title`: Title for a chapter or section. May contain spaces. -* `abstract`: The abstract for a section, visible in the Table of - Contents (TOC). -* `description`: Detailed description of a tag (except chapters), - shown as synopsis. -* `values`: A list of 'values' for the tag. These values are used for - cross-referencing. - - -Other Tags ----------- - -Except the ones given above, any other tags will be added as a part of -a subsection. All tags are lowercase by convention. - - -Public Header Definitions -------------------------- - -The public headers for FreeType have their names defined in -`include/freetype/config/ftheader.h`. Any new public header file must -be defined in this file, in the following format: - - #define FT_NEWNAME_H - -Where `newname` is the name of the header file. - -This macro is combined with the file location of a sub-section and -printed with the object. - - -Note on code blocks captured after comments -------------------------------------------- - -All non-documentation lines after a documentation comment block are -captured to be displayed as the code for the sub-section. To stop -collection, a line with `/* */` should be added. - - -General Formatting Conventions ------------------------------- - -* Use two spaces after a full stop ending a sentence. -* Use appropriate uppercasing in titles. Refer - - https://english.stackexchange.com/a/34 - - for more information. -* Do not add trailing parentheses when citing a C function. - - -Markdown Usage --------------- - -All tags, except the ones that define the name and title for a block -support markdown in them. Docwriter uses a markdown parser that -follows rules given in John Gruber's markdown guide: - - https://daringfireball.net/projects/markdown/syntax - -with a few exceptions and extensions, detailed below. This may also -be referred to as the **FreeType Flavored Markdown**. - - -Headers -------- - -Markdown headers should not be used directly, because these are added -based on section titles, sub-section names, and tags. However, if a -header needs to be added, note the following correspondence to HTML tags: - -* Section title on top of the page is `H1`. -* Sub-section titles are `H2`. -* Parts of sub-sections are `H4`. -* Any header added will be visible in the Table of Contents (TOC) of - the page. - - -Emphasis --------- - -* Use `_underscores_` for italics. -* Use `**double asterisks**` for bold. - -Although the other notations (double underscore for bold, single -asterisk for italics) are supported, it is recommended to use the -above for consistency. - -Note that there may be cases where having two asterisks or underscores -in a line may lead to text being picked up as italics or bold. -Although unintentional, this is correct markdown behavior. - -For inline code, wrap the sequence with backticks (see below). This -renders symbols correctly without modifications. If a symbol is -absolutely required outside of an inline code block or code sequence, -escape it with a backslash (like `\*` or `\_`). - - -Lists ------ - -Unordered lists can be created with asterisks: - - * Unordered list items can use asterisks. - * Another list item. - -Ordered lists start with numbers: - - 1. This is an ordered list item. - 2. Brackets after numbers won't work. - -To continue a list over multiple paragraphs, indent them with at least -four spaces. For example: - - 1. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. - Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, - viverra nec, fringilla in, laoreet vitae, risus. - - Donec sit amet nisl. Aliquam semper ipsum sit amet velit. - Suspendisse id sem consectetuer libero luctus adipiscing. - - 2. This is the second list item. - - This paragraph is not a part of the list. - -More information on lists in markdown is available at - - https://daringfireball.net/projects/markdown/syntax#list - - -Cross-references ----------------- - -Other sub-sections can be linked with the `@` symbol: - - @description: - While FreeType's CFF driver doesn't expose API functions by - itself, it is possible to control its behaviour with - @FT_Property_Set and @FT_Property_Get. - -If a field in the `values` table of another sub-section is linked, the -link leads to its parent sub-section. - - -Links and Images ----------------- - -All URLs are converted to links in the HTML documentation. - -Markdown syntax for links and images are fully supported. - - -Inline Code ------------ - -To indicate a span of code, wrap it with backtick quotes (`` ` ``): - - Use the `printf()` function. - -Cross-references, markdown, and html styling do not work in inline code -sequences. - - -Code and Syntax Highlighting ----------------------------- - -Blocks of code are fenced by lines with three back-ticks `` ``` `` -followed by the language name, if any (used for syntax highlighting), -as demonstrated in the following example. - - ```c - x = y + z; - if ( zookoo == 2 ) - { - foobar(); - } - ``` - -Note that the indentation of the opening line and the closing line -must be exactly the same. The code sequence itself should have a -larger indentation than the surrounding back-ticks. - -Like inline code, markdown and html styling is *not* supported inside -code blocks. - - -Tables ------- - -Tables are used to list values, input, and other fields. The FreeType -Flavored Markdown adopts a simple approach to tables with two columns, -or field definition tables. - -Field definition names may contain alphanumeric, underscore, and the -`.` characters. This is followed by `::`. The following lines are -the second column of the table. A field definition ends with the -start of another field definition, or a markup tag. - - @Input: - pathname :: - A path to the font file. - - face_index :: - See @FT_Open_Face for a detailed description of this - parameter. - - -Non-breaking Space ------------------- - -A tilde can be used to create a non-breaking space. The example - - The encoding value~0 is reserved. - -is converted to - - The encoding value 0 is reserved. - - ----------------------------------------------------------------------- - -Copyright (C) 2018-2023 by -Nikhil Ramakrishnan, David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute -this file you indicate that you have read the license and understand -and accept it fully. - - ---- end of DOCGUIDE --- diff --git a/freetype/docs/FTL.TXT b/freetype/docs/FTL.TXT deleted file mode 100644 index c406d15..0000000 --- a/freetype/docs/FTL.TXT +++ /dev/null @@ -1,169 +0,0 @@ - The FreeType Project LICENSE - ---------------------------- - - 2006-Jan-27 - - Copyright 1996-2002, 2006 by - David Turner, Robert Wilhelm, and Werner Lemberg - - - -Introduction -============ - - The FreeType Project is distributed in several archive packages; - some of them may contain, in addition to the FreeType font engine, - various tools and contributions which rely on, or relate to, the - FreeType Project. - - This license applies to all files found in such packages, and - which do not fall under their own explicit license. The license - affects thus the FreeType font engine, the test programs, - documentation and makefiles, at the very least. - - This license was inspired by the BSD, Artistic, and IJG - (Independent JPEG Group) licenses, which all encourage inclusion - and use of free software in commercial and freeware products - alike. As a consequence, its main points are that: - - o We don't promise that this software works. However, we will be - interested in any kind of bug reports. (`as is' distribution) - - o You can use this software for whatever you want, in parts or - full form, without having to pay us. (`royalty-free' usage) - - o You may not pretend that you wrote this software. If you use - it, or only parts of it, in a program, you must acknowledge - somewhere in your documentation that you have used the - FreeType code. (`credits') - - We specifically permit and encourage the inclusion of this - software, with or without modifications, in commercial products. - We disclaim all warranties covering The FreeType Project and - assume no liability related to The FreeType Project. - - - Finally, many people asked us for a preferred form for a - credit/disclaimer to use in compliance with this license. We thus - encourage you to use the following text: - - """ - Portions of this software are copyright © The FreeType - Project (www.freetype.org). All rights reserved. - """ - - Please replace with the value from the FreeType version you - actually use. - - -Legal Terms -=========== - -0. Definitions --------------- - - Throughout this license, the terms `package', `FreeType Project', - and `FreeType archive' refer to the set of files originally - distributed by the authors (David Turner, Robert Wilhelm, and - Werner Lemberg) as the `FreeType Project', be they named as alpha, - beta or final release. - - `You' refers to the licensee, or person using the project, where - `using' is a generic term including compiling the project's source - code as well as linking it to form a `program' or `executable'. - This program is referred to as `a program using the FreeType - engine'. - - This license applies to all files distributed in the original - FreeType Project, including all source code, binaries and - documentation, unless otherwise stated in the file in its - original, unmodified form as distributed in the original archive. - If you are unsure whether or not a particular file is covered by - this license, you must contact us to verify this. - - The FreeType Project is copyright (C) 1996-2000 by David Turner, - Robert Wilhelm, and Werner Lemberg. All rights reserved except as - specified below. - -1. No Warranty --------------- - - THE FREETYPE PROJECT IS PROVIDED `AS IS' WITHOUT WARRANTY OF ANY - KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE. IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE OR THE INABILITY TO - USE, OF THE FREETYPE PROJECT. - -2. Redistribution ------------------ - - This license grants a worldwide, royalty-free, perpetual and - irrevocable right and license to use, execute, perform, compile, - display, copy, create derivative works of, distribute and - sublicense the FreeType Project (in both source and object code - forms) and derivative works thereof for any purpose; and to - authorize others to exercise some or all of the rights granted - herein, subject to the following conditions: - - o Redistribution of source code must retain this license file - (`FTL.TXT') unaltered; any additions, deletions or changes to - the original files must be clearly indicated in accompanying - documentation. The copyright notices of the unaltered, - original files must be preserved in all copies of source - files. - - o Redistribution in binary form must provide a disclaimer that - states that the software is based in part of the work of the - FreeType Team, in the distribution documentation. We also - encourage you to put an URL to the FreeType web page in your - documentation, though this isn't mandatory. - - These conditions apply to any software derived from or based on - the FreeType Project, not just the unmodified files. If you use - our work, you must acknowledge us. However, no fee need be paid - to us. - -3. Advertising --------------- - - Neither the FreeType authors and contributors nor you shall use - the name of the other for commercial, advertising, or promotional - purposes without specific prior written permission. - - We suggest, but do not require, that you use one or more of the - following phrases to refer to this software in your documentation - or advertising materials: `FreeType Project', `FreeType Engine', - `FreeType library', or `FreeType Distribution'. - - As you have not signed this license, you are not required to - accept it. However, as the FreeType Project is copyrighted - material, only this license, or another one contracted with the - authors, grants you the right to use, distribute, and modify it. - Therefore, by using, distributing, or modifying the FreeType - Project, you indicate that you understand and accept all the terms - of this license. - -4. Contacts ------------ - - There are two mailing lists related to FreeType: - - o freetype@nongnu.org - - Discusses general use and applications of FreeType, as well as - future and wanted additions to the library and distribution. - If you are looking for support, start in this list if you - haven't found anything to help you in the documentation. - - o freetype-devel@nongnu.org - - Discusses bugs, as well as engine internals, design issues, - specific licenses, porting, etc. - - Our home page can be found at - - https://www.freetype.org - - ---- end of FTL.TXT --- diff --git a/freetype/docs/GPLv2.TXT b/freetype/docs/GPLv2.TXT deleted file mode 100644 index b2fe7b6..0000000 --- a/freetype/docs/GPLv2.TXT +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, 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 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. - - - Copyright (C) - - 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 St, 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. - - , 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/freetype/docs/INSTALL b/freetype/docs/INSTALL deleted file mode 100644 index 49ab112..0000000 --- a/freetype/docs/INSTALL +++ /dev/null @@ -1,114 +0,0 @@ - -There are several ways to build the FreeType library, depending on -your system and the level of customization you need. Here is a short -overview of the documentation available: - - -I. Prerequisites and dependencies -================================= - - FreeType is a low level C library that only depends on the standard - C library with very few platform-dependent optimizations utilized at - build time. Any C99-compliant compiler should be able to compile - FreeType. System libraries, such as zlib, Gzip, bzip2, Brotli, - and libpng, might be used to handle compressed fonts or decode - embedded PNG glyphs. - - FreeType auto-configuration scripts should be able to detect the - prerequisites if the necessary headers are available at the default - locations. Otherwise, modify `include/freetype/config/ftoption.h` - to control how the FreeType library gets built. Normally, you don't - need to change anything. - - Applications have very limited control over FreeType's behaviour at - run-time; look at the documentation of function `FT_Property_Set`. - - -II. Normal installation and upgrades -==================================== - - 1. Unix and Unix-like systems - - This also includes MacOS, Cygwin, MinGW + MSYS, Mingw-w64 + MSYS2, - and possibly other, similar environments. - - Please read `INSTALL.UNIX` to install or upgrade FreeType 2 on a - Unix system. Note that you *need* GNU Make for automatic - compilation, since other make tools won't work (this includes BSD - Make). - - GNU Make VERSION 3.81 OR NEWER IS NEEDED! - - - 2. Other systems using GNU Make - - On some non-Unix platforms, it is possible to build the library - using only the GNU Make utility. Note that *NO OTHER MAKE TOOL - WILL WORK*[1]! This methods supports several compilers on - Windows, OS/2, and BeOS, including MinGW* (without MSYS*), Visual - C++, Borland C++, and more. - - Instructions are provided in the file `INSTALL.GNU`. - - - 3. Other build tools and platforms. - - A few other tools can be used to build FreeType. You can find - the corresponding instruction files in the FreeType root folder - or the builds/ sub-folder. - - CMake :: see `CMakeLists.txt` for more information - Meson :: see `meson.build` for more information - MSBuild :: see `builds/windows/vc2010/freetype.vcxproj` - MMS :: see `vms_make.com` and `docs/INSTALL.VMS` - - - 4. With an IDE Project File (e.g., for Visual Studio or CodeWarrior) - - We provide a small number of 'project files' for various IDEs to - automatically build the library as well. Note that these files - are not actively supported by FreeType developers, they can break - or become obsolete. - - To find them, have a look at the content of the `builds/` - directory, where stands for your OS or environment. - - - 5. From you own IDE, or own Makefiles - - If you want to create your own project file, follow the - instructions given in the `INSTALL.ANY` document of this - directory. - - -III. Custom builds of the library -================================= - - Customizing the compilation of FreeType is easy, and allows you to - select only the components of the font engine that you really need. - For more details read the file `CUSTOMIZE`. - - ----------------------------------------------------------------------- - -[1] make++, a make tool written in Perl, has sufficient support of GNU - make extensions to build FreeType. See - - https://makepp.sourceforge.net - - for more information; you need version 2.0 or newer, and you must - pass option `--norc-substitution`. - ----------------------------------------------------------------------- - -Copyright (C) 2000-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute -this file you indicate that you have read the license and understand -and accept it fully. - - ---- end of INSTALL --- diff --git a/freetype/docs/INSTALL.ANY b/freetype/docs/INSTALL.ANY deleted file mode 100644 index bb77b1b..0000000 --- a/freetype/docs/INSTALL.ANY +++ /dev/null @@ -1,157 +0,0 @@ -Instructions on how to build FreeType with your own build tool -============================================================== - -See the file `CUSTOMIZE' to learn how to customize FreeType to -specific environments. - - -I. Standard procedure ---------------------- - - * If you use macro names for FreeType header files (while mandatory - in earlier versions, this is now optional since FreeType version - 2.6.1) it is necessary to disable pre-compiled headers. This is - very important for Visual C++, because lines like - - #include FT_FREETYPE_H - - are not correctly supported by this compiler while being ISO C - compliant! - - * You need to add the directory `include' to your include path when - compiling the library. - - * FreeType 2 is made of several components; each of them is located - in a subdirectory of `freetype/src'. For example, - `freetype/src/truetype/' contains the TrueType font driver. - - * DO NOT COMPILE ALL C FILES! Rather, compile the following ones. - - -- base components (required) - - src/base/ftsystem.c - src/base/ftinit.c - src/base/ftdebug.c - - src/base/ftbase.c - - src/base/ftbbox.c -- recommended, see - src/base/ftglyph.c -- recommended, see - - src/base/ftbdf.c -- optional, see - src/base/ftbitmap.c -- optional, see - src/base/ftcid.c -- optional, see - src/base/ftfstype.c -- optional - src/base/ftgasp.c -- optional, see - src/base/ftgxval.c -- optional, see - src/base/ftmm.c -- optional, see - src/base/ftotval.c -- optional, see - src/base/ftpatent.c -- optional - src/base/ftpfr.c -- optional, see - src/base/ftstroke.c -- optional, see - src/base/ftsynth.c -- optional, see - src/base/fttype1.c -- optional, see - src/base/ftwinfnt.c -- optional, see - - src/base/ftmac.c -- only on the Macintosh - - -- font drivers (optional; at least one is needed) - - src/bdf/bdf.c -- BDF font driver - src/cff/cff.c -- CFF/OpenType font driver - src/cid/type1cid.c -- Type 1 CID-keyed font driver - src/pcf/pcf.c -- PCF font driver - src/pfr/pfr.c -- PFR/TrueDoc font driver - src/sfnt/sfnt.c -- SFNT files support - (TrueType & OpenType) - src/truetype/truetype.c -- TrueType font driver - src/type1/type1.c -- Type 1 font driver - src/type42/type42.c -- Type 42 font driver - src/winfonts/winfnt.c -- Windows FONT / FNT font driver - - -- rasterizers (optional; at least one is needed for vector - formats) - - src/raster/raster.c -- monochrome rasterizer - src/sdf/sdf.c -- Signed Distance Field driver - src/smooth/smooth.c -- anti-aliasing rasterizer - - -- auxiliary modules (optional) - - src/autofit/autofit.c -- auto hinting module - src/cache/ftcache.c -- cache sub-system (in beta) - src/gzip/ftgzip.c -- support for compressed fonts (.gz) - src/lzw/ftlzw.c -- support for compressed fonts (.Z) - src/bzip2/ftbzip2.c -- support for compressed fonts (.bz2) - src/gxvalid/gxvalid.c -- TrueTypeGX/AAT table validation - src/otvalid/otvalid.c -- OpenType table validation - src/psaux/psaux.c -- PostScript Type 1 parsing - src/pshinter/pshinter.c -- PS hinting module - src/psnames/psnames.c -- PostScript glyph names support - - - Notes: - - `ftcache.c' needs `ftglyph.c' - `ftfstype.c' needs `fttype1.c' - `ftglyph.c' needs `ftbitmap.c' - `ftstroke.c' needs `ftglyph.c' - `ftsynth.c' needs `ftbitmap.c' - - `cff.c' needs `sfnt.c', `pshinter.c', and `psnames.c' - `truetype.c' needs `sfnt.c' and `psnames.c' - `type1.c' needs `psaux.c' `pshinter.c', and `psnames.c' - `type1cid.c' needs `psaux.c', `pshinter.c', and `psnames.c' - `type42.c' needs `truetype.c' - - Please consult the central `include/freetype/config/ftoption.h' - configuration file for details on additional libraries necessary - for some optional features. - - - Read the file `CUSTOMIZE' in case you want to compile only a subset - of the drivers, renderers, and optional modules; a detailed - description of the various base extension is given in the top-level - file `modules.cfg'. - - You are done. In case of problems, see the archives of the FreeType - development mailing list. - - -II. Support for flat-directory compilation ------------------------------------------- - - It is possible to put all FreeType 2 source files into a single - directory, with the *exception* of the `include' hierarchy. - - 1. Copy all files in current directory - - cp freetype/src/base/*.[hc] . - cp freetype/src/raster1/*.[hc] . - cp freetype/src/smooth/*.[hc] . - etc. - - 2. Compile sources - - cc -c -Iinclude -DFT2_BUILD_LIBRARY ftsystem.c - cc -c -Iinclude -DFT2_BUILD_LIBRARY ftinit.c - cc -c -Iinclude -DFT2_BUILD_LIBRARY ftdebug.c - cc -c -Iinclude -DFT2_BUILD_LIBRARY ftbase.c - etc. - - You don't need to define the FT_FLAT_COMPILATION macro (as this - was required in previous releases of FreeType 2). - ----------------------------------------------------------------------- - -Copyright (C) 2003-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute -this file you indicate that you have read the license and understand -and accept it fully. - - ---- end of INSTALL.ANY --- diff --git a/freetype/docs/INSTALL.CROSS b/freetype/docs/INSTALL.CROSS deleted file mode 100644 index 21f4c31..0000000 --- a/freetype/docs/INSTALL.CROSS +++ /dev/null @@ -1,177 +0,0 @@ -This document contains instructions on how to cross-build the FreeType -library on Unix systems, for example, building binaries for Linux/MIPS -on FreeBSD/i386. Before reading this document, please consult the -file `INSTALL.UNIX' for required tools and the basic self-building -procedure. - - - 1. Required Tools - ----------------- - - For self-building the FreeType library on a Unix system, GNU Make - 3.81 or newer is required. `INSTALL.UNIX' contains hints how to - check the installed `make'. - - The GNU C compiler to cross-build the target system is required. - Currently, using a non-GNU cross compiler is untested. The cross - compiler is expected to be installed with a system prefix. For - example, if your building system is FreeBSD/i386 and the target - system is Linux/MIPS, the cross compiler should be installed with - the name `mips-ip22-linuxelf-gcc'. - - A C compiler for a self-build is required also, to build a tool - (`apinames') that is executed during the build procedure. Non-GNU - self compilers are acceptable, but such a setup is untested. - - - 2. Configuration - ---------------- - - 2.1. Building and target system - - To configure a cross-build, the options `--host=' and - `--build=' must be passed to the `configure' script. - For example, if your build system is FreeBSD/i386 and the target - system is Linux/MIPS, say - - ./configure \ - --build=i386-unknown-freebsd \ - --host=mips-ip22-linuxelf \ - [other options] - - It should be noted that `--host=' specifies the system - where the built binaries will be executed, not the system where - the build actually happens. Older versions of GNU autoconf use - the option pair `--host=' and `--target='. This is broken and - doesn't work. Similarly, an explicit CC specification like - - env CC=mips-ip22-linux-gcc ./configure # BAD - - or - - env CC=/usr/local/mips-ip22-linux/bin/gcc ./configure # BAD - - doesn't work either; such a configuration confuses the - `configure' script while trying to find the cross and native C - compilers. - - - 2.2. The prefix to install FreeType2 - - Setting `--prefix=' properly is important. The prefix - to install FreeType2 is written into the `freetype-config' - script and `freetype2.pc' configuration file. - - If the built FreeType 2 library is used as a part of the - cross-building system, the prefix is expected to be different - from the self-building system. For example, a configuration - with `--prefix=/usr/local' installs binaries into the - system-wide `/usr/local' directory, which then can't be executed - due to the incorrect architecture. This causes confusion in - configuration of all applications that use FreeType2. Instead, - use a prefix to install the cross-build into a separate system - tree, for example, `--prefix=/usr/local/mips-ip22-linux/'. - - On the other hand, if the built FreeType 2 library is used as a - part of the target system, the prefix to install should reflect - the file system structure of the target system. - - - 2.3. Library dependencies - - FreeType normally depends on external libraries like `libpng' or - `libharfbuzz'. The easiest case is to deactivate all such - dependencies using the `--without-XXX' configuration options. - However, if you want to use those libraries, you should ensure - that they are available both on the target system and as - (cross-compiled) libraries on the build system. - - FreeType uses `pkg-config' to find most of the libraries; the - other libraries it links to are expected in the standard system - directories. Since the default pkg-config's meta-information - files (like `harfbuzz.pc') of the build platform don't work, use - one of the two possible solutions below. - - o Use pkg-config's meta-information files that are adjusted to - cross-compile and cross-link with the target platform's - libraries. Make sure those files are found before the build - system's default files. Example: - - ./configure \ - --build=i386-unknown-freebsd \ - --host=mips-ip22-linuxelf \ - PKG_CONFIG_LIBDIR="/usr/local/mips-ip22-linux/lib/pkgconfig" \ - [other options] - - See the manpage of `pkg-config' for more details. - - o Set variables like LIBPNG_LIBS as additional options to the - `configure' script, overriding the values `pkg-config' would - provide. `configure --help' shows the available environment - variables. Example: - - ./configure \ - --build=i386-unknown-freebsd \ - --host=mips-ip22-linuxelf \ - LIBPNG_CFLAGS="-I/usr/local/mips-ip22-linux/include" \ - LIBPNG_LIBS="-L/usr/local/mips-ip22-linux/lib -lpng12" \ - [other options] - - - 3. Building command - ------------------- - - If the configuration finishes successfully, invoking GNU make - builds FreeType2. Just say - - make - - or - - gmake - - depending on the name the GNU make binary actually has. - - - 4. Installation - --------------- - - Saying - - make install - - as usual to install FreeType2 into the directory tree specified by - the argument of the `--prefix' option. - - As noted in section 2.2, FreeType2 is sometimes configured to be - installed into the system directory of the target system, and - should not be installed in the cross-building system. In such - cases, the make variable `DESTDIR' is useful to change the root - directory in the installation. For example, after - - make DESTDIR=/mnt/target_system_root/ install - - the built FreeType2 library files are installed into the directory - `/mnt/target_system_root//lib'. - - - 5. TODO - ------- - - Cross building between Cygwin (or MSys) and Unix must be tested. - - ----------------------------------------------------------------------- - -Copyright (C) 2006-2023 by -suzuki toshiya, David Turner, Robert Wilhelm, and Werner Lemberg. - - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute -this file you indicate that you have read the license and understand -and accept it fully. - - ---- end of INSTALL.CROSS --- diff --git a/freetype/docs/INSTALL.GNU b/freetype/docs/INSTALL.GNU deleted file mode 100644 index 7517d9c..0000000 --- a/freetype/docs/INSTALL.GNU +++ /dev/null @@ -1,181 +0,0 @@ -This document contains instructions how to build the FreeType library -on non-Unix systems with the help of GNU Make. Note that if you are -running Cygwin or MinGW/MSYS in Windows, you should follow the -instructions in the file `INSTALL.UNIX' instead. - - - FreeType 2 includes a powerful and flexible build system that allows - you to easily compile it on a great variety of platforms from the - command line. To do so, just follow these simple instructions. - - 1. Install GNU Make - ------------------- - - The FreeType 2 build system relies on many features special to GNU - Make. - - NEARLY ALL OTHER MAKE TOOLS FAIL, INCLUDING `BSD MAKE', SO REALLY - INSTALL A RECENT VERSION OF GNU MAKE ON YOUR SYSTEM! - - Note that make++, a make tool written in Perl, supports enough - features of GNU make to compile FreeType. See - - https://makepp.sourceforge.net - - for more information; you need version 2.0 or newer, and you must - pass option `--norc-substitution'. - - Make sure that you are invoking GNU Make from the command line, by - typing something like: - - make -v - - to display its version number. - - VERSION 3.81 OR NEWER IS NEEDED! - - - 2. Invoke `make' - ---------------- - - Go to the root directory of FreeType 2, then simply invoke GNU - Make from the command line. This will launch the FreeType 2 host - platform detection routines. A summary will be displayed, for - example, on Win32. - - - ============================================================== - FreeType build system -- automatic system detection - - The following settings are used: - - platform windows - compiler gcc - configuration directory .\builds\windows - configuration rules .\builds\windows\w32-gcc.mk - - If this does not correspond to your system or settings please - remove the file 'config.mk' from this directory then read the - INSTALL file for help. - - Otherwise, simply type 'make' again to build the library - or 'make refdoc' to build the API reference (the latter needs - Python >= 3.5). - ============================================================= - - - If the detected settings correspond to your platform and compiler, - skip to step 5. Note that if your platform is completely alien to - the build system, the detected platform will be `ansi'. - - - 3. Configure the build system for a different compiler - ------------------------------------------------------ - - If the build system correctly detected your platform, but you want - to use a different compiler than the one specified in the summary - (for most platforms, gcc is the default compiler), invoke GNU Make - with - - make setup - - Examples: - - to use Visual C++ on Win32, type: `make setup visualc' - to use Borland C++ on Win32, type `make setup bcc32' - to use Watcom C++ on Win32, type `make setup watcom' - to use Intel C++ on Win32, type `make setup intelc' - to use LCC-Win32 on Win32, type: `make setup lcc' - to use Watcom C++ on OS/2, type `make setup watcom' - to use VisualAge C++ on OS/2, type `make setup visualage' - - The name to use is platform-dependent. The list of - available compilers for your system is available in the file - `builds//detect.mk'. - - If you are satisfied by the new configuration summary, skip to - step 5. - - - 3a. Use clang instead of gcc - ---------------------------- - - The `clang' compiler can use FreeType's setup for `gcc'; it is - sufficient to set the `CC' variable, for example - - make CC=clang - - - 3b. Compiling with a C++ compiler - --------------------------------- - - FreeType can be built with a C++ compiler, for example - - make CC="g++" - - If `clang++' should be used it is necessary to also override the - `ANSIFLAGS' variable: - - make CC="clang++" ANSIFLAGS="" - - - 4. Configure the build system for an unknown platform/compiler - -------------------------------------------------------------- - - The auto-detection/setup phase of the build system copies a file - to the current directory under the name `config.mk'. - - For example, on OS/2+gcc, it would simply copy - `builds/os2/os2-gcc.mk' to `./config.mk'. - - If for some reason your platform isn't correctly detected, copy - manually the configuration sub-makefile to `./config.mk' and go to - step 5. - - Note that this file is a sub-Makefile used to specify Make - variables for compiler and linker invocation during the build. - You can easily create your own version from one of the existing - configuration files, then copy it to the current directory under - the name `./config.mk'. - - - 5. Build the library - -------------------- - - The auto-detection/setup phase should have copied a file in the - current directory, called `./config.mk'. This file contains - definitions of various Make variables used to invoke the compiler - and linker during the build. [It has also generated a file called - `ftmodule.h' in the objects directory (which is normally - `/objs/'); please read the file `docs/CUSTOMIZE' for - customization of FreeType.] - - To launch the build, simply invoke GNU Make again: The top - Makefile will detect the configuration file and run the build with - it. If you have used variables in step 3, you must use the same - variables here, too. - - - Final note - - The above instructions build a _statically_ linked library of the - font engine in the `objs' directory. On Windows, you can build a - DLL either with MinGW (within an MSYS shell, following the - instructions in `INSTALL.UNIX'), or you use one of the Visual C++ - project files; see the subdirectories of `builds/windows'. For - everything else, you are on your own, and you might follow the - instructions in `INSTALL.ANY' to create your own Makefiles. - ----------------------------------------------------------------------- - -Copyright (C) 2003-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute -this file you indicate that you have read the license and understand -and accept it fully. - - ---- end of INSTALL.GNU --- diff --git a/freetype/docs/INSTALL.MAC b/freetype/docs/INSTALL.MAC deleted file mode 100644 index 2587e24..0000000 --- a/freetype/docs/INSTALL.MAC +++ /dev/null @@ -1,32 +0,0 @@ -Please follow the instructions in INSTALL.UNIX to install FreeType on -Mac OS X. - -Currently FreeType2 functions based on some deprecated Carbon APIs -return `FT_Err_Unimplemented_Feature' always, even if FreeType2 is -configured and built on the system that deprecated Carbon APIs are -available. To enable deprecated FreeType2 functions as far as -possible, replace `src/base/ftmac.c' by `builds/mac/ftmac.c'. - -Starting with Mac OS X 10.5, gcc defaults the deployment target to -10.5. In previous versions of Mac OS X, this defaulted to 10.1. If -you want your built binaries to run only on 10.5, this change does not -concern you. If you want them to also run on older versions of Mac -OS X, then you must either set the MACOSX_DEPLOYMENT_TARGET -environment variable or pass `-mmacosx-version-min' to gcc. You -should specify the oldest version of Mac OS you want the code to run -on. For example, if you use Bourne shell: - - export MACOSX_DEPLOYMENT_TARGET=10.2 - -or, if you use C shell: - - setenv MACOSX_DEPLOYMENT_TARGET 10.2 - -Alternatively, you could pass `-mmacosx-version-min=10.2' to gcc. - -Here the number 10.2 is the lowest version that the built binaries can -run on. In the above cases, the built binaries will run on Mac OS X -10.2 and later, but _not_ earlier. If you want to run on earlier, you -have to set lower version, e.g., 10.0. - -For classic Mac OS (Mac OS 7, 8, 9) please refer to builds/mac/README. diff --git a/freetype/docs/INSTALL.UNIX b/freetype/docs/INSTALL.UNIX deleted file mode 100644 index 659f3a2..0000000 --- a/freetype/docs/INSTALL.UNIX +++ /dev/null @@ -1,139 +0,0 @@ -This document contains instructions on how to build the FreeType -library on Unix systems. This also works for emulations like Cygwin -or MSys on Win32: - - - 1. Ensure that you are using GNU Make - ------------------------------------- - - The FreeType build system _exclusively_ works with GNU Make. You - will not be able to compile the library with the instructions - below using any other alternative (including BSD Make). - - Check that you have GNU make by running the command: - - make -v - - This should dump some text that begins with: - - GNU Make - Copyright (C) Free Software Foundation Inc. - - Note that version 3.81 or higher is *required* or the build will - fail. - - It is also fine to have GNU Make under another name (e.g. 'gmake') - if you use the MAKE variable as described below. - - As a special exception, 'makepp' can also be used to build - FreeType 2. See the file docs/MAKEPP for details. - - For builds with `cmake' please check file `CMakeLists.txt'; this - is a contributed file not directly supported by the FreeType team. - - - 2. Regenerate the configure script if needed - -------------------------------------------- - - This only applies if you are building a git snapshot or checkout, - *not* if you grabbed the sources of an official release. - - You need to invoke the `autogen.sh' script in the top-level - directory in order to create the `configure' script for your - platform. Normally, this simply means typing: - - sh autogen.sh - - In case of problems, you may need to install or upgrade Automake, - Autoconf or Libtool. See `README.git' in the top-level directory - for more information. - - - 3. Build and install the library - -------------------------------- - - Say - - ./configure --help - - to see the list of possible configuration options and important - environment variables. The ./configure script will detect some - prerequisite system libraries (libpng, brotli, etc.) if their - headers are available at the default locations. - - The following should work on all Unix systems where the `make' - command invokes GNU Make: - - ./configure [options] - make - make install (as root) - - The default installation path is `/usr/local'. It can be changed - with the `--prefix=' option. Example: - - ./configure --prefix=/usr - - When using a different command to invoke GNU Make, use the MAKE - variable. For example, if `gmake' is the command to use on your - system, do something like: - - MAKE=gmake ./configure [options] - gmake - gmake install (as root) - - If this still doesn't work, there must be a problem with your - system (e.g., you are using a very old version of GNU Make). - - For library identification, FreeType's `configure' script uses the - `pkg-config' interface: Assuming it needs library `foo', it calls - the `pkg-config' program to find information on library `foo', - which in turn looks for a `foo.pc' file installed at the system. - Some platforms, however, don't come with `pkg-support'; you then - have to use environment variables as described by `configure - --help'. Example: - - LIBPNG_CFLAGS="-I/path/to/libpng/include/directory" \ - LIBPNG_LIBS="-L/path/to/libpng/lib/directory" \ - configure ... - - It is possible to compile FreeType in a different directory. - Assuming the FreeType source files in directory `/src/freetype' a - compilation in directory `foo' works as follows: - - cd foo - /src/freetype/configure [options] - make - make install - - - 3.1 Interdependency with HarfBuzz - ................................. - - Note that there is a chicken-and-egg problem currently since the - HarfBuzz library (used by the auto-hinter to improve support of - OpenType fonts) depends on FreeType, which can be solved as - follows in case HarfBuzz is not yet installed on your system. - - 1. Call FreeType's `configure' script with option - `--without-harfbuzz', then compile and install FreeType. - - 2. Compile and install HarfBuzz. - - 3. Call FreeType's `configure' script without option - `--without-harfbuzz' (after executing `make distclean'), then - compile and install FreeType again. - - ----------------------------------------------------------------------- - -Copyright (C) 2003-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute -this file you indicate that you have read the license and understand -and accept it fully. - - ---- end of INSTALL.UNIX --- diff --git a/freetype/docs/INSTALL.VMS b/freetype/docs/INSTALL.VMS deleted file mode 100644 index 4f8c3ac..0000000 --- a/freetype/docs/INSTALL.VMS +++ /dev/null @@ -1,69 +0,0 @@ -How to build the FreeType library on VMS ----------------------------------------- - -It is actually very straightforward to install the FreeType library. -Just execute `vms_make.com from` the toplevel directory to build the -library. This procedure currently accepts the following options: - -* `DEBUG` - Build the library with debug information and without optimization. - -* `lopts=` - Options to pass to the link command, e.g., `lopts=/traceback`. - -* `ccopt=` - Options to pass to the C compiler, e.g., `ccopt=/float=ieee`. - -In case you did download the demos, place them in a separate directory -sharing the same top level as the directory of FreeType and follow the -same instructions as above for the demos from there. The build -process relies on this to figure out the location of the FreeType -include files. - - -To rebuild the sources it is necessary to have MMS/MMK installed on -the system. - -The library is available in the directory - - [.LIB] - -To compile applications using FreeType you have to define the logical -`FREETYPE` pointing to the directory - - [.INCLUDE.FREETYPE] - -i.e., if the directory in which this `INSTALL.VMS` file is located is -`$disk:[freetype.docs]`, then define the logical with - - define freetype $disk:[freetype.include.freetype] - -See http://nchrem.tnw.tudelft.nl/openvms/software2.html#Freetype for -the packages FreeType depends on. - -The latest versions were tested using - - VSI C V7.4-002 and DECWindows V1.7-F on OpenVMS Alpha V8.4-2L1 - - VSI C V7.4-001 and DECWindows V1.7-E on OpenVMS IA64 V8.4-2L3 - - -Any problems can be reported to - - Jouk Jansen or - -Orginal version of the build procedures was created by - - Martin P.J. Zinser - ------------------------------------------------------------------------- - -Copyright (C) 2000-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute this -file you indicate that you have read the license and understand and -accept it fully. - - ---- end of INSTALL.VMS --- diff --git a/freetype/docs/MAKEPP b/freetype/docs/MAKEPP deleted file mode 100644 index 4450e47..0000000 --- a/freetype/docs/MAKEPP +++ /dev/null @@ -1,5 +0,0 @@ -As a special exception, FreeType can also be built with the 'makepp' -build tool, available from https://makepp.sourceforge.net. - -Note, however, that you will need at least version 2.0 and pass the -option --norc-substitution to have it work correctly. diff --git a/freetype/docs/PROBLEMS b/freetype/docs/PROBLEMS deleted file mode 100644 index 40bdc35..0000000 --- a/freetype/docs/PROBLEMS +++ /dev/null @@ -1,90 +0,0 @@ -This file describes various problems that have been encountered in -compiling, installing and running FreeType 2. Suggestions for -additions or other improvements to this file are welcome. - ----------------------------------------------------------------------- - -Running Problems -================ - - -* Some Type 1, Multiple Masters, and CID-keyed PostScript fonts aren't - handled correctly. - ------ - -Of course, there might be bugs in FreeType, but some fonts based on -the PostScript format can't be handled indeed. The reason is that -FreeType doesn't contain a full PostScript interpreter but applies -pattern matching instead. In case a font doesn't follow the standard -structure of the given font format, FreeType fails. A typical example -is Adobe's `Optima' font family which contains extra code to switch -between low and high resolution versions of the glyphs. - -It might be possible to patch FreeType in some situations, though. -Please report failing fonts so that we investigate the problem and set -up a list of such problematic fonts. - - -* Why do identical FreeType versions render differently on different - platforms? - ------ - -Different distributions compile FreeType with different options. The -developer version of a distribution's FreeType package, which is -needed to compile your program against FreeType, includes the file -ftoption.h. Compare each platform's copy of ftoption.h to find the -differences. - - ----------------------------------------------------------------------- - - -Compilation Problems -==================== - - -* I get an `internal compilation error' (ICE) while compiling FreeType - 2.2.1 with Intel C++. - - This has been reported for the following compiler version: - - Intel(R) C++ Compiler for 32-bit applications, - Version 9.0 Build 20050430Z Package ID: W_CC_P_9.0.019 - ------ - -The best solution is to update the compiler to version - - Intel(R) C++ Compiler for 32-bit applications, - Version 9.1 Build 20060323Z Package ID: W_CC_P_9.1.022 - -or newer. If this isn't feasible, apply the following patch. - - ---- src/cache/ftcbasic.c 20 Mar 2006 12:10:24 -0000 1.20 -+++ src/cache/ftcbasic.c.patched 15 May 2006 02:51:02 -0000 -@@ -252,7 +252,7 @@ - */ - - FT_CALLBACK_TABLE_DEF -- const FTC_IFamilyClassRec ftc_basic_image_family_class = -+ FTC_IFamilyClassRec ftc_basic_image_family_class = - { - { - sizeof ( FTC_BasicFamilyRec ), -@@ -266,7 +266,7 @@ - - - FT_CALLBACK_TABLE_DEF -- const FTC_GCacheClassRec ftc_basic_image_cache_class = -+ FTC_GCacheClassRec ftc_basic_image_cache_class = - { - { - ftc_inode_new, - - ----------------------------------------------------------------------- - ---- end of PROBLEMS --- diff --git a/freetype/docs/README b/freetype/docs/README deleted file mode 100644 index c2b5af8..0000000 --- a/freetype/docs/README +++ /dev/null @@ -1,33 +0,0 @@ -After saying `make refdoc' or `make refdoc-venv' the `reference/' directory -contains the FreeType API reference. You need Python >= 3.5 and pip to make -this target. - -There are two ways to generate the documentation: - -1. Using `make refdoc': - - - Ensure `python' and `pip' are available. - - Install pip package `docwriter' with `pip install --user docwriter'. - - Make target with `make refdoc'. - - This target can be run offline once required packages are installed. - -2. Using `make refdoc-venv' (requires internet access): - - - Ensure `python', `pip' and Python package `virtualenv' are available. - - Make target with `make refdoc-venv'. - - This may or may not require internet access every time depending on - pip and system caching. - -Some troubleshooting tips: - -* Regularly run `pip install --upgrade docwriter' to check for updates which -may include bug fixes. - -* `Docwriter' does not support Python 2. Ensure that Python >= 3.5 is -installed and available as `python3'/`python'. - -* Ensure that `docwriter' is installed in the same Python target that -`make refdoc' uses (python3/python). - -* If none of this works, send a mail to `freetype-devel@nongnu.org' or file -an issue at `https://github.com/freetype/docwriter/issues'. diff --git a/freetype/docs/TODO b/freetype/docs/TODO deleted file mode 100644 index d340880..0000000 --- a/freetype/docs/TODO +++ /dev/null @@ -1,40 +0,0 @@ -Here is a list of items that need to be addressed in FreeType 2 ---------------------------------------------------------------- - -* Implement stem3/counter hints properly in the Postscript hinter. - -* Add CIDCMap support to the CID driver. - -* Add track kerning support to the PFR driver. - -* Add kerning (AFM file) support to the CID driver. - - -Here is a list of bugs which should be handled ----------------------------------------------- - -Other bugs have been registered at the savannah bugzilla of FreeType. - -* CID driver: - Handle the case where a CID font has a top-level font matrix also - (see PLRM, 5.11.3, Type 0 CIDFonts). Since CID_FaceInfoRec lacks - a font_matrix entry we have to directly apply it to all subfont - matrices. - -* CID driver: - Use top-level font matrix entry for setting the upem value, not the - entries in the FDarray. If absent, use 1000. - ------------------------------------------------------------------------- - -Copyright (C) 2001-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute this -file you indicate that you have read the license and understand and -accept it fully. - - ---- end of TODO --- diff --git a/freetype/docs/VERSIONS.TXT b/freetype/docs/VERSIONS.TXT deleted file mode 100644 index 8b43c15..0000000 --- a/freetype/docs/VERSIONS.TXT +++ /dev/null @@ -1,137 +0,0 @@ -Due to our use of `libtool' to generate and install the FreeType 2 -libraries on Unix systems, as well as other historical events, it is -generally very difficult to know precisely which release of the font -engine is installed on a given system. - -This file tries to explain why and to document ways to properly detect -FreeType on Unix. - - -1. Version and Release numbers ------------------------------- - -For each new public release of FreeType 2, there are generally *three* -distinct `version' numbers to consider: - - * The official FreeType 2 release number, like 2.7.0 or 2.10.2. - - * The libtool (and Unix) specific version number, like 23.2.17. - This is what - - pkg-config freetype2 --modversion - - or - - freetype-config --version - - returns. - - * The platform-specific shared object number, used for example when - the library is installed as `/usr/lib/libfreetype.so.6.17.2'. - -The platform-specific number is, unsurprisingly, platform-specific and -varies with the operating system you are using (several variants of -Linux, FreeBSD, Solaris, etc.). You should thus _never_ use it, even -for simple tests. - -The libtool-specific number does not equal the release number but is -tied to it. - -The release number is available at *compile* time through the -following macros defined in `freetype.h': - - - FREETYPE_MAJOR: major release number - - FREETYPE_MINOR: minor release number - - FREETYPE_PATCH: patch release number - -See below for a small autoconf fragment. - -The release number is also available at *runtime* through the -`FT_Library_Version' API. - - -2. History ----------- - -The following table gives, for all releases since 2.5.0, the -corresponding libtool number, as well as the shared object number -found on _most_ systems, but not all of them: - - - release libtool so - ------------------------------- - 2.13.2 26.1.20 6.20.1 - 2.13.1 26.0.20 6.20.0 - 2.13.0 25.0.19 6.19.0 - 2.12.1 24.3.18 6.18.3 - 2.12.0 24.2.18 6.18.2 - 2.11.1 24.1.18 6.18.1 - 2.11.0 24.0.18 6.18.0 - 2.10.4 23.4.17 6.17.4 - 2.10.3 23.3.17 6.17.3 - 2.10.2 23.2.17 6.17.2 - 2.10.1 23.1.17 6.17.1 - 2.10.0 23.0.17 6.17.0 - 2.9.1 22.1.16 6.16.1 - 2.9.0 22.0.16 6.16.0 - 2.8.1 21.0.15 6.15.0 - 2.8.0 20.0.14 6.14.0 - 2.7.1 19.0.13 6.13.0 - 2.7.0 18.6.12 6.12.6 - 2.6.5 18.5.12 6.12.5 - 2.6.4 18.4.12 6.12.4 - 2.6.3 18.3.12 6.12.3 - 2.6.2 18.2.12 6.12.2 - 2.6.1 18.1.12 6.12.1 - 2.6.0 18.0.12 6.12.0 - 2.5.5 17.4.11 6.11.4 - 2.5.4 17.3.11 6.11.3 - 2.5.3 17.2.11 6.11.2 - 2.5.2 17.1.11 6.11.1 - 2.5.1 17.0.11 6.11.0 - 2.5.0 16.2.10 6.10.2 - - -3. Autoconf Code Fragment -------------------------- - -Lars Clausen contributed the following autoconf fragment to check -which version of FreeType is installed on a system (now updated to use -`pkg-config' instead of `freetype-config'). This one tests for a -version that is at least 2.10.2; you should change it to check against -other release numbers. - - - AC_MSG_CHECKING([whether FreeType version is 2.10.2 or higher]) - old_CPPFLAGS="$CPPFLAGS" - CPPFLAGS=`pkg-config freetype2 --cflags` - AC_TRY_CPP([ - -#include -#include - -#if FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH < 21002 -# error FreeType version too low. -#endif - - ], - [AC_MSG_RESULT(yes) - FREETYPE_LIBS=`pkg-config freetype2 --libs` - AC_SUBST(FREETYPE_LIBS) - AC_DEFINE(HAVE_FREETYPE,1,[Define if you have the FreeType2 library]) - CPPFLAGS="$old_CPPFLAGS"], - [AC_MSG_ERROR([Need FreeType library version 2.10.2 or higher])]) - ----------------------------------------------------------------------- - -Copyright (C) 2002-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute -this file you indicate that you have read the license and understand -and accept it fully. - - ---- end of VERSIONS.TXT --- diff --git a/freetype/docs/formats.txt b/freetype/docs/formats.txt deleted file mode 100644 index 882d62d..0000000 --- a/freetype/docs/formats.txt +++ /dev/null @@ -1,223 +0,0 @@ -This file contains a list of various font formats. It gives the -reference document and whether it is supported in FreeType 2. - -Table fields ------------- - - wrapper format - The format used to represent the font data. In the table below it - is used only if the font format differs. Possible values are - - SFNT binary - PFB binary - PS a text header, followed by binary or text data - LZW compressed with either `gzip' or `compress' - BZ2 compressed with `bzip2'. - - font format - How the font is to be accessed, possibly after converting the file - type and wrapper format into a generic form. Bitmap formats are - `BDF', `PCF', and one form of `WINFNT'; all others are vector - formats. `PS' indicates third-order, `TT' second-order Bézier - curves. - - font type - Sub-formats of the font format. `SBIT' and `MACSBIT' are bitmap - formats, `MM' and `VAR' support optical axes. `CFF2' supports - optical axes also. - - glyph access - If not specified, the glyph access is `standard' to the font - format. Values are `CID' for CID-keyed fonts, `SYNTHETIC' for - fonts that are modified versions of other fonts by means of a - transformation matrix, and `TYPE_0' for PS fonts which are to be - accessed in a tree-like structure. - - FreeType driver - The module in the FreeType library which handles the specific font - format. A missing entry means that FreeType doesn't support the - font format (yet). - - -Notes ------ - - The SFNT container format also provides `collections' (usually - having the file extension `.ttc' or `.otc'). A collection contains - multiple font faces that share some tables to avoid redundancy, thus - reducing the file size. In FreeType, elements of a collection can - be accessed with a proper face index. - - Both the GX and the OpenType 1.8 variation fonts provide `named - instances'. FreeType maps them to face indices (they can also be - accessed with the standard MM interface). - - Other font formats (not using the SFNT wrapper) also provide - multiple faces within one file; they are marked with an asterisk - (`*') in the table below. - - FreeType can be configured to support Mac files (on older Mac OS - versions, a `file' is stored as a data and a resource fork, that is, - within two separate data chunks). If a file can't be opened as a - font, FreeType then checks whether it is a resource fork, trying to - extract the contained font data from either a `POST' or `sfnt' - resource. - - -Please send additions and/or corrections to wl@gnu.org or to the -FreeType developer's list at freetype-devel@nongnu.org (for -subscribers only). If you can provide a font example for a format -which isn't supported yet please send a mail too. - - - wrapper font font glyph FreeType reference - format format type access driver documents - ----------------------------------------------------------------------------- - - --- BDF --- --- bdf 5005.BDF_Spec.pdf, X11 - - - SFNT PS TYPE_1 --- type1 Type 1 GX Font Format [7] - (for the Mac; not supported) - SFNT PS TYPE_1 CID cid 5180.sfnt.pdf (for the Mac) [3] - SFNT PS CFF --- cff OT spec, 5176.CFF.pdf - (`OTTO' format) - SFNT PS CFF CID cff OT spec, 5176.CFF.pdf - SFNT PS CFF SYNTHETIC --- OT spec, 5176.CFF.pdf - SFNT PS CFF2 --- cff OT spec 1.8 - - SFNT TT SBIT --- sfnt XFree86 (bitmaps only; - with `head' table) - SFNT TT MACSBIT --- sfnt OT spec (for the Mac; - bitmaps only; `bhed' table) - SFNT TT --- --- truetype OT spec (`normal' TT font) - SFNT TT VAR --- truetype GX spec (`?var' tables) - SFNT TT VAR --- truetype OT spec 1.8 - (`?var' + `?VAR' tables) - - - WOFF --- --- --- cff, Compressed SFNT, ver. 1.0 [6] - truetype - WOFF2 --- --- --- cff, Compressed SFNT, ver. 2.0 [6] - truetype - - - --- PS TYPE_1 --- type1 T1_SPEC.pdf - (PFA, Type 1 font resource) - PFB PS TYPE_1 --- type1 T1_SPEC.pdf, - 5040.Download_Fonts.pdf - (`normal' Type 1 font) - --- PS TYPE_1 CID cid PLRM.pdf (CID Font Type 0; - Type 9 font) - --- PS MM --- type1 5015.Type1_Supp.pdf - (Multiple Masters) - --- PS CFF --- cff 5176.CFF.pdf (`pure' CFF) - --- PS* CFF CID cff 5176.CFF.pdf (`pure' CFF) - --- PS CFF SYNTHETIC --- 5176.CFF.pdf (`pure' CFF) - --- PS CFF/MM --- cff old 5167.CFF.pdf (`pure' CFF) - [3] - --- PS* CFF/MM CID cff old 5167.CFF.pdf (`pure' CFF) - [3] - --- PS CFF/MM SYNTHETIC --- old 5167.CFF.pdf (`pure' CFF) - [3] - PS PS CFF --- --- PLRM.pdf (Type 2) [1] - PS PS* CFF CID --- PLRM.pdf (Type 2) [1] - PS PS CFF SYNTHETIC --- PLRM.pdf (Type 2) [1] - PS PS CFF/MM --- --- PLRM.pdf (Type 2) [1] - PS PS* CFF/MM CID --- PLRM.pdf (Type 2) [1] - PS PS CFF/MM SYNTHETIC --- PLRM.pdf (Type 2) [1] - --- PS --- TYPE_0 --- PLRM.pdf - --- PS TYPE_3 --- --- PLRM.pdf (never supported) - --- PS TYPE_3 CID --- PLRM.pdf (CID Font Type 1; - Type 10 font; never supported) - PS PS TYPE_14 --- --- PLRM.pdf (Chameleon font; - Type 14 font; never supported?) - --- PS TYPE_32 CID --- PLRM.pdf (CID Font Type 4; - Type 32 font; never supported?) - PS TT --- --- type42 5012.Type42_Spec.pdf - (Type 42 font) - PS TT --- CID --- PLRM.pdf (CID Font Type 2; - Type 11 font) - - - ? ? CEF ? cff ? - - - --- PCF --- --- pcf X11 [4] - LZW PCF --- --- pcf X11 [4] - BZ2 PCF --- --- pcf X11 [4] - - - --- PFR* PFR0 --- pfr [2] - --- PFR PFR1 --- --- (undocumented, proprietary; - probably never supported) - - - --- WINFNT* --- --- winfonts Windows developer's notes [5] - --- WINFNT VECTOR --- --- Windows developer's notes [5] - - -[1] Support should be rather simple since this is identical to `CFF' - but in a PS wrapper. - -[2] The official PFR specification is no longer available, but - archive.org has archived it: - - https://web.archive.org/web/20091014062300/http://www.bitstream.com/font_rendering/products/truedoc/pfrspec.html - https://web.archive.org/web/20081115152605/http://www.bitstream.com/font_rendering/pdfs/pfrspec1.3.pdf - - The syntax of the auxiliary data is not defined there, but is - partially defined in MHP 1.0.3 (also called ETSI TS 101812 V1.3.1) - section 7.4. - - https://www.etsi.org/ - https://webapp.etsi.org/workprogram/Report_WorkItem.asp?WKI_ID=18799 - -[3] Support is rudimentary currently; some tables or data are not - loaded yet. - -[4] See - - THE X WINDOW SYSTEM SERVER: X VERSION 11, RELEASE 5 - Elias Israel, Erik Fortune, Digital Press, 1992 - ISBN 1-55558-096-3 - - for a specification given in Appendix D on pgs. 436-450. However, - this information might be out of date; unfortunately, there is no - PCF specification available online, and this book is out of print. - George Williams deduced the font format from the X11 sources and - documented it for his FontForge font editor: - - https://fontforge.github.io/pcf-format.html - -[5] This is from MS Windows 3; see Microsoft's Knowledge Base article - at - - https://support.microsoft.com/kb/65123 - -[6] Supported font formats are TrueType and OpenType fonts as - defined in the OpenType specification 1.6 and newer. - -[7] `The Type 1 GX Font Format' (dated 1995-09-27) was distributed in - Apple Developer CD-ROM in those days. The content of `TYP1' table - is a PostScript Type 1 font without the eexec encryption. Current - versions of FreeType don't not support this format, but FontForge - can load it. - ------------------------------------------------------------------------- - -Copyright (C) 2004-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, -modified, and distributed under the terms of the FreeType project -license, LICENSE.TXT. By continuing to use, modify, or distribute this -file you indicate that you have read the license and understand and -accept it fully. - - ---- end of formats.txt --- - -Local Variables: -coding: utf-8 -End: diff --git a/freetype/docs/freetype-config.1 b/freetype/docs/freetype-config.1 deleted file mode 100644 index 6ef1ac8..0000000 --- a/freetype/docs/freetype-config.1 +++ /dev/null @@ -1,146 +0,0 @@ -.TH FREETYPE-CONFIG 1 "August 2023" "FreeType 2.13.2" -. -. -.SH NAME -. -freetype-config \- Get information about a libfreetype installation -. -. -.SH SYNOPSIS -. -.B freetype-config -.RI [ options ] -. -. -.SH DESCRIPTION -. -.B freetype-config -returns information needed for compiling and linking programs with the -FreeType library, such as linker flags and compilation parameters. -. -Alternatively, it can be used to query information about the -FreeType library version installed on the system, such as the -installation (directory path) prefix or the FreeType version number. -. -.PP -If -.BR pkg-config (1) -is found in the path, -.B freetype-config -acts as a wrapper for -.BR pkg-config . -. -.PP -This program is part of the FreeType package. -. -. -.SH OPTIONS -. -There are two types of options: output/display selection options, and -path override options. -. -. -.SS Output selection options -. -Only one of the output selection options should be given at each program -invocation. -. -.TP -.B \-\-prefix -Return the prefix value of the installed FreeType library (the default -prefix will be `/usr' in most cases for distribution-installed -packages). -. -.TP -.B \-\-exec-prefix -Return the executable prefix value of the installed FreeType library -(will often be the same as the prefix value). -. -.TP -.B \-\-ftversion -Return the FreeType version number, directly derived from file -`freetype.h'. -. -.TP -.B \-\-version -Return the `libtool version' of the FreeType library. -. -.TP -.B \-\-libtool -Return the library name for linking with libtool. -. -.TP -.B \-\-libs -Return compiler flags for linking with the installed FreeType library. -. -.TP -.B \-\-cflags -Return compiler flags for compiling against the installed FreeType library. -. -.TP -.B \-\-static -Make command line options display flags for static linking. -. -.TP -.B \-\-help -Show help and exit. -. -. -.SS Path override options -. -These affect any selected output option, except the libtool version -returned by -.BR \-\-version . -. -.TP -.BI \-\-prefix= PREFIX -Override -.B \-\-prefix -value with -.IR PREFIX . -. -This also sets -.BI \-\-exec-prefix= PREFIX -if option -.B \-\-exec-prefix -is not explicitly given. -. -.TP -.BI \-\-exec-prefix= EPREFIX -Override -.B \-\-exec-prefix -value with -.IR EPREFIX . -. -. -.SH BUGS -In case the libraries FreeType links to are located in non-standard -directories, and -.BR pkg-config (1) -is not available, the output from option -.B \-\-libs -might be incomplete. -. -It is thus recommended to use the -.BR pkg-config (1) -interface instead, which is able to correctly resolve all dependencies. -. -.PP -Setting -.B \-\-exec-prefix -(either explicitly or implicitly) might return incorrect results if -combined with option -.BR \-\-static . -. -The same problem can occur if you set the -.B SYSROOT -environment variable. -. -. -.SH AUTHOR -. -This manual page was contributed by Nis Martensen , -with further refinements from the FreeType team. -. -. -.\" eof diff --git a/freetype/docs/markdown/images/favico.ico b/freetype/docs/markdown/images/favico.ico deleted file mode 100644 index 8464e77ad3587b21e6b2dfa38491cc17bd5d6743..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5430 zcmeI0F;2rk5Jd+BeU4xufj9<2Tmvc!&Va-f;0!=Rhr|t_K>`sjK$A2SRCIJ<*Wm^0 z%j+FmiVad$vi{DW|7SL9d!xi`&DL!+vVeu1Y?$qsSy9a6o4}t3ZZ~jY8WeLrfLY*m zY#naShQ6NO?q`hWFt4tsDOc6uuX4&HB+s^z2Pa)3rbKs>qtEoX(px zb-CNetHtMwwHR7Am3#l3Ed14HlsX=)>(w`>=Rw;zo-;+b_QDmhcode { - font-family: monospace; - background-color: #D6E8FF; - padding: 2ex 0 2ex 1%; - overflow-x:auto; -} -span.keyword { - font-family: monospace; - text-align: left; - white-space: pre; - color: #d73a49; -} -.md-typeset pre>code { - white-space: pre; -} -/* H4 Heading */ -h4 { - background-color: #EEEEFF; - font-size: medium; - font-style: oblique; - font-weight: bold; - padding: 0.3em 0 0.3em 1%; -} - -/* Fields table */ -table.fields { - width: 90%; - margin: 1.5ex 0 1.5ex 10%; -} -table.fields td.val { - font-weight: bold; - text-align: right; - width: 30%; - vertical-align: baseline; - padding: 1em 1em 0 0; -} -table.fields td.desc { - vertical-align: baseline; - padding: 1ex 0 0 1em; -} -table.fields td.desc p:first-child { - margin: 0; -} - -table.fields td.desc p { - margin: 1.5ex 0 0 0; -} - -/* Define 'long' tables */ -table.long { - display: block; - width: 93%; -} -table.long thead, -table.long tbody, -table.long th, -table.long td, -table.long tr { - display: block; -} -/* Hide table headers (but not display: none; -, for accessibility) */ -table.long thead tr { - position: absolute; - top: -9999px; - left: -9999px; -} -table.long tr { - border: 0; -} -table.long { - margin: 1.5ex 3% 1.5ex 3%; -} -table.long td.val { - text-align: left; -} -table.long td { - /* Behave like a "row" */ - border: none; - border-bottom: 0; - position: relative; - padding-left: 50%; -} -table.long td:before { - /* Now like a table header */ - position: absolute; - /* Top/left values mimic padding */ - top: 6px; - left: 6px; - width: 45%; - padding-right: 10px; - white-space: nowrap; -} -/* End 'long' table definition */ - -/* toc table */ -table.toc { - width: 95%; - margin: 1.5ex 0 1.5ex 5%; -} -table.toc td.link { - width: 30%; - text-align: right; - vertical-align: baseline; - padding: 1ex 1em 1ex 0; -} -table.toc td.desc { - vertical-align: baseline; - padding: 1ex 0 1ex 1em; - text-align: left; -} -table.toc td.desc p:first-child { - margin: 0; - text-align: left; -} -table.toc td.desc p { - margin: 1.5ex 0 0 0; - text-align: left; -} -div.timestamp { - font-size: small; -} - -/* Change table layout for smaller screens. This query will take effect for any screen smaller than - 760px and also iPads specifically. */ -@media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) { - /* Force table to not be like tables anymore */ - table, thead, tbody, th, td, tr { - display: block; - } - /* Hide table headers (but not display: none; - , for accessibility) */ - thead tr { - position: absolute; - top: -9999px; - left: -9999px; - } - tr { - border: 0; - } - table.fields { - width: 93%; - margin: 1.5ex 3% 1.5ex 3%; - } - table.fields td.val { - text-align: left; - } - td { - /* Behave like a "row" */ - border: none; - border-bottom: 0; - position: relative; - padding-left: 50%; - } - td:before { - /* Now like a table header */ - position: absolute; - /* Top/left values mimic padding */ - top: 6px; - left: 6px; - width: 45%; - padding-right: 10px; - white-space: nowrap; - } -} diff --git a/freetype/docs/oldlogs/ChangeLog.20 b/freetype/docs/oldlogs/ChangeLog.20 deleted file mode 100644 index 0993728..0000000 --- a/freetype/docs/oldlogs/ChangeLog.20 +++ /dev/null @@ -1,2613 +0,0 @@ -2002-02-09 Werner Lemberg - - * README: Fix typo. - * docs/CHANGES: Minor fixes. - - - * Version 2.0.8 released. - ========================= - - -2002-02-08 David Turner - - * docs/CHANGES: Updating for 2.0.8. - - * include/freetype/freetype.h: Setting `PATCH_LEVEL' to 8 and - removing `FT_Get_Next_Char' from the API (temporarily). - - * include/freetype/freetype.h: Adding comments to FT_Get_Next_Char; - note that this function might temporarily be removed for the 2.0.8 - release. - -2002-02-07 David Turner - - * src/pcf/pcfread.c (pcf_load_font): Removed immature support of - the AVERAGE_WIDTH property. - -2002-02-06 David Turner - - * src/sfnt/sfobjs.c (SFNT_Load_Face): Since many fonts embedded in - PDF documents do not include 'cmap', 'post' and 'name' tables, the - SFNT face loader has been changed to not immediately report an - error if these are not present. - - Note that the specification _requires_ these tables, but Adobe - seems to ignore it completely. - - * src/sfnt/ttcmap.c: Removing compiler warnings. - - * src/pcf/pcfread.c (pcf_read_TOC): Use FT_UInt. - (pcf_parse_metric, pcf_parse_compressed_metric): Removed. Code - is now in ... - (pcf_get_metric): Here. - (pcfSeekToType): Renamed to ... - (pcf_seek_to_table_type): This. - Use FT_Int. - (pcfHasType): Renamed to ... - (pcf_has_table_type): This. - Use FT_Int. - (find_property): Renamed to ... - (pcf_find_property): This. - Use FT_Int. - (pcf_get_bitmaps, pcf_get_encodings): Handle invalid PCF fonts - better (delaying format checks out of FT_Access_Frame .. - FT_Forget_Frame blocks to avoid leaving the stream in an incorrect - state when encountering an invalid PCF font). - - * src/pcf/pcfdriver.c (PCF_Done_Face): Renamed to ... - (PCF_Face_Done): This. - (PCF_Init_Face): Renamed to ... - (PCF_Face_Init): This. - (PCF_Get_Char_Index): Renamed to ... - (PCF_Char_Get_Index): This. - (PCF_Get_Next_Char): Renamed to ... - (PCF_Char_Get_Next): This. - (pcf_driver_class): Updated. - - * src/pcf/pcf.h (PCF_Done_Face): Removed. - -2002-02-06 Detlef Würkner - - * src/pcf/pcfdriver.c (FT_Done_Face): Fixed small memory leak. - - * src/pcf/pcfread.c (pcf_load_font): Now handles the `AVERAGE_WIDTH' - property to return correct character pixel (width/height) pairs for - embedded bitmaps. - -2002-02-04 Keith Packard - - Adding the function `FT_Get_Next_Char', doing the obvious thing - w.r.t. the selected charmap. - - * include/freetype/freetype.h: Add prototype. - * include/freetype/internal/ftdriver.h: Add `FTDriver_getNextChar' - typedef. - (FT_Driver_Class): Use it. - * include/freetype/internal/psnames.h: Add `PS_Next_Unicode_Func' - typedef. - (PSNames_Interface): Use it. - * include/freetype/internal/tttypes.h: Add `TT_CharNext_Func' - typedef. - (TT_CMapTable): Use it. - - * src/base/ftobjs.c (FT_Get_Next_Char): New function, implementing - high-level API. - * src/cff/cffdrivr.c (cff_get_next_char): New function. - (cff_driver_class): Add it. - * src/cid/cidriver.c (Cid_Get_Next_Char): New function. - (t1cid_driver_class): Add it. - * src/pcf/pcfdriver.c (PCF_Get_Next_Char): New function. - (pcf_driver_class): Add it. - * src/psnames/psmodule.c (PS_Next_Unicode): New function. - (psnames_interface): Add it. - * src/sfnt/ttcmap.c (code_to_next0, code_to_next2, code_to_next4, - code_to_next6, code_to_next_8_12, code_to_next_10): New auxiliary - functions. - (TT_CharMap_Load): Use them. - * src/truetype/ttdriver.c (Get_Next_Char): New function. - (tt_driver_class): Add it. - * src/type1/t1driver.c (Get_Next_Char): New function. - (t1_driver_class): Add it. - * src/winfonts/winfnt.c (FNT_Get_Next_Char): New function. - (winfnt_driver_class): Add it. - - * src/pcf/pcfread.c (pcf_load_font): For now, report Unicode for - Unicode and Latin 1 encodings. - -2002-02-02 Keith Packard - - * builds/unix/freetype-config.in: Add missing `fi'. - - - * Version 2.0.7 released. - ========================= - - -2002-02-01 David Turner - - * include/freetype/freetype.h: Increasing FREETYPE_PATCH to 7 - for the new release. - -2002-01-31 David Turner - - * README, README.UNX, docs/CHANGES: Updating documentation for the - 2.0.7 release. - -2002-01-30 David Turner - - * INSTALL: Moved to ... - * docs/INSTALL: Here to avoid conflicts with the `install' script on - Windows, where the filesystem doesn't preserve case. - -2002-01-29 David Turner - - * configure: Fixed the script. It previously didn't accept more - than one argument correctly. For example, when typing: - - ./configure --disable-shared --disable-nls - - the `--disable-nls' was incorrectly sent to the `make' program. - -2002-01-29 Werner Lemberg - - * README.UNX: Fix typo. - * builds/unix/install.mk (uninstall): Fix library name for libtool. - -2002-01-28 Francesco Zappa Nardelli - - * src/pcf/pcfdriver.c (PCF_Done_Face): Fix incorrect destruction of - the face object (face->toc.tables, face->root.family_name, - face->root.available_size, face->charset_encoding, - face->charset_registry are now freed). Thanks to Niels Moseley. - -2002-01-28 Roberto Alameda - - * src/type1/t1load.c (parse_encoding): Set `loader->num_chars'. - -2002-01-28 Werner Lemberg - - * src/type1/t1load.c (parse_subrs, parse_charstrings): Use copy - of `base' string for decrypting to not modify the original data. - Based on a patch by Jakub Bogusz . - -2002-01-27 Giuliano Pochini - - * src/smooth/ftgrays.c (gray_render_scanline): Fix bug which caused - bad rendering of thin lines (less than one pixel thick). - -2002-01-25 Werner Lemberg - - * src/cff/cffdrivr.c (cff_get_name_index): Make last patch work - actually. - -2002-01-25 Martin Zinser - - * src/cache/ftccache.c (ftc_node_done, ftc_node_destroy): Fix - compilation warnings. - * src/base/descrip.mms (OBJS): Add `ftmm.obj'. - * src/cache/descrip.mms (ftcache.obj): Dependencies added. - -2002-01-25 WANG Yi - - * src/cff/cffdrivr.c (cff_get_name_index): Fix deallocation bug. - -2002-01-21 Antoine Leca - - * docs/PATENTS: Typo fixed (thanks to Detlef `Hawkeye' Würkner) in - the URL for the online resource. - -2002-01-18 Ian Brown - - * builds/win32/ftdebug.c: New file. - * builds/win32/visualc/freetype.dsp: Updated. - -2002-01-18 Detlef Würkner - - * builds/amiga/src/base/ftsystem.c: Updated for AmigaOS 3.9. - * builds/amiga/README: Updated. - -2002-01-18 Ian Brown - - * builds/win32/visualc/freetype.dsp: Updated. - -2002-01-13 Werner Lemberg - - * builds/unix/freetype2.a4: The script was still buggy. - * builds/unix/freetype-config.in: Make it really work for any install - prefix. - -2002-01-10 Werner Lemberg - - * builds/unix/freetype2.a4: Fix some serious bugs. - -2002-01-09 David Turner - - * builds/unix/configure.ac: Build top-level Jamfile. - -2002-01-09 Maxim Shemanarev - - * src/smooth/ftgrays.c (gray_render_line): Small optimization to - the smooth anti-aliased renderer that deals with vertical segments. - This results in a 5-7% speedup in rendering speed. - -2002-01-08 David Turner - - Added some wrapper scripts to make the installation more - Unix-friendly. - - * configure, install: New files. - - * INSTALL, README.UNX: Updated installation documentation to use the - new 'configure' and 'install' scripts. - -2002-01-07 David Turner - - - * Version 2.0.6 released. - ========================= - - - * docs/BUGS, docs/CHANGES: Updating documentation for 2.0.6 release. - - * src/tools/docmaker.py: Fixed HTML quoting in sources. - (html_format): Replaced with ... - (html_quote): New function. - (html_quote0): New function. - (DocCode::dump_html): Small improvement. - (DocParagraph::dump, DocBlock::html): Use html_quote0 and html_quote. - - * include/freetype/config/ftoption.h: Setting default options for - a release build (debugging off, bytecode interpreter off). - - * src/base/ftobjs.c, src/base/ftoutln.c, src/cache/ftccmap.c, - src/cff/cffload.c, src/cff/cffobjs.c, src/pshinter/pshalgo2.c, - src/sfnt/ttload.c, src/sfnt/ttsbit.c: Removing small compiler - warnings (in pedantic compilation modes). - -2002-01-05 David Turner - - * src/autohint/ahhint.c (ah_align_linked_edge): Modified computation - of auto-hinted stem widths; this avoids color fringes in - `ClearType-like' rendering. - - * src/truetype/ttgload.c (TT_Load_Glyph_Header, - TT_Load_Simple_Glyph, TT_Load_Composite_Glyph, load_truetype_glyph): - Modified the TrueType loader to make it more paranoid; this avoids - nasty buffer overflows in the case of invalid glyph data (as - encountered in the output of some buggy font converters). - -2002-01-04 David Turner - - * README.UNX: Added special README file for Unix users. - - * builds/unix/ftsystem.c (FT_New_Stream): Fixed typo. - - * src/base/ftobjs.c: Added #include FT_OUTLINE_H to get rid - of compiler warnings. - - * src/base/ftoutln.c (FT_Outline_Check): Remove compiler warning. - -2002-01-03 Werner Lemberg - - * src/type1/t1objs.c (T1_Face_Init): Add cast to avoid compiler - warning. - -2002-01-03 Keith Packard - - * builds/unix/ftsystem.c (FT_New_Stream): Added a fix to ensure that - all FreeType input streams are closed in child processes of a `fork' - on Unix systems. This is important to avoid (potential) access - control issues. - -2002-01-03 David Turner - - * src/type1/t1objs.c (T1_Face_Init): Fixed a bug that crashed the - library when dealing with certain weird fonts like `Stalingrad', in - `sadn.pfb' (this font has no full font name entry). - - * src/base/ftoutln.c, include/freetype/ftoutln.h (FT_Outline_Check): - New function to check the consistency of outline data. - - * src/base/ftobjs.c (FT_Load_Glyph): Use `FT_Outline_Check' to - ensure that loaded glyphs are valid. This allows certain fonts like - `tt1095m_.ttf' to be loaded even though it appears they contain - really funky glyphs. - - There still is a bug there, though. - - * src/truetype/ttgload.c (load_truetype_glyph): Fix error condition. - -2001-12-30 David Turner - - * src/autohint/ahhint.c (ah_hinter_load): Fix advance width - computation of auto-hinted glyphs. This noticeably improves the - spacing of letters in KDE and Gnome. - -2001-12-25 Antoine Leca - - * builds/dos/detect.mk: Correcting the order for Borland compilers: - 16-bit bcc was never selected, always overridden by 32-bit bcc32. - -2001-12-22 Francesco Zappa Nardelli - - * src/pcf/pcfread.c (pcf_load_font): Handle property `POINT_SIZE' - and fix incorrect computation of `available_sizes'. - -2001-12-22 David Turner - - * src/autohint/ahhint.c (ah_hinter_load): Auto-hinted glyphs had an - incorrect glyph advance in the case of mono-width fonts (like - Courier, Andale Mono, and others). - -2001-12-22 Detlef Würkner - - * builds/amiga/*: Adaptations to latest changes. - Support added for MorphOS. - -2001-12-22 Werner Lemberg - - * src/pshinter/pshrec.c (FT_COMPONENT): Redefine to `trace_pshrec'. - (ps_mask_table_merge, ps_hints_open, ps_hints_stem, - ps_hints_t1stem3, ps_hints_t2mask, ps_hints_t2counter): Fix - FT_ERROR messages. - * src/pshinter/pshalgo1.c (FT_COMPONENT): Define as - `trace_pshalgo1'. - * src/pshinter/pshalgo2.c (FT_COMPONENT): Define as - `trace_pshalgo2'. - * include/freetype/internal/ftdebug.h (FT_Trace): Updated. - - * docs/modules.txt: New file. - -2001-12-21 David Turner - - * src/pshinter/pshrec.c (ps_hints_t2mask, ps_hints_t2counter): - Ignore invalid `hintmask' and `cntrmask' operators (instead of - returning an error). Glyph 2028 of the CFF font `MSung-Light-Acro' - couldn't be rendered otherwise (it seems its charstring is buggy, - though this requires more analysis). - (FT_COMPONENT): Define. - - * src/cff/cffgload.c (CFF_Parse_CharStrings), src/psaux/t1decode.c - (T1_Decoder_Parse_Charstrings), src/pshinter/pshalgo2.c (*), Fixed a - bug where the X and Y axis where inverted in the postscript hinter. - This caused problem when displaying on non-square surfaces. - - * src/pshinter/pshalgo2.c: s/vertical/dimension/. - - * src/pshinter/pshglob.c (psh_globals_new): Replaced a floating - point constant with a fixed-float equivalent. For some reasons not - all compilers are capable of directly computing a floating pointer - constant casted to FT_Fixed, and will link a math library instead. - -2001-12-20 Werner Lemberg - - * src/cache/ftccache.c (ftc_node_destroy, ftc_cache_lookup): Fix - tracing strings. - * src/cache/ftccmap.c (ftc_cmap_family_init): Ditto. - * src/cache/ftcmanag.c (ftc_family_table_alloc, - ftc_family_table_free, FTC_Manager_Check): Ditto. - * src/cache/ftcsbits.c (ftc_sbit_node_load): Ditto. - - * src/base/ftobjs.c (FT_Done_Library): Remove compiler warning. - -2001-12-20 David Turner - - Added PostScript hinter support to the CFF and CID drivers. - - * include/freetype/internal/cfftypes.h (CFF_Font): New member - `pshinter'. - * src/cff/cffload.c (CFF_Get_Standard_Encoding): New function. - * src/cff/cffload.h: Updated. - * src/cff/cffgload.c (CFF_Init_Builder): Renamed to ... - (CFF_Builder_Init): This. - Added new argument `hinting'. - (CFF_Done_Builder): Renamed to ... - (CFF_Builder_Done): This. - (CFF_Init_Decoder): Added new argument `hinting'. - (CFF_Parse_CharStrings): Implement vstem support. - (CFF_Load_Glyph): Updated. - Add hinting support. - (cff_lookup_glyph_by_stdcharcode): Use CFF_Get_Standard_Encoding(). - (cff_argument_counts): Updated. - * src/cff/cffgload.h: Updated. - * src/cff/cffobjs.c: Include FT_INTERNAL_POSTSCRIPT_HINTS_H. - (CFF_Size_Get_Globals_Funcs, CFF_Size_Done, CFF_Size_Init, - CFF_Size_Reset, CFF_GlyphSlot_Done, CFF_GlyphSlot_Init): New - functions. - (CFF_Init_Face): Renamed to ... - (CFF_Face_Init): This. - Add hinter support. - (CFF_Done_Face): Renamed to ... - (CFF_Face_Done): This. - (CFF_Init_Driver): Renamed to ... - (CFF_Driver_Init): This. - (CFF_Done_Driver): Renamed to ... - (CFF_Driver_Done): This. - * src/cff/cffobjs.h: Updated. - * src/cff/cffdrivr.c (cff_driver_class): Updated. - - * include/freetype/internal/t1types.h (CID_FaceRec): New member - `pshinter'. - * src/cid/cidgload.c (CID_Load_Glyph): Add hinter support. - * src/cid/cidobjs.c: Include FT_INTERNAL_POSTSCRIPT_HINTS_H. - (CID_GlyphSlot_Done, CID_GlyphSlot_Init, CID_Size_Get_Globals_Funcs, - CID_Size_Done, CID_Size_Init, CID_Size_Reset): New functions. - (CID_Done_Face): Renamed to ... - (CID_Face_Done): This. - (CID_Init_Face): Renamed to ... - (CID_Face_Init): This. - Add hinting support. - (CID_Init_Driver): Renamed to ... - (CID_Driver_Init): This. - (CID_Done_Driver): Renamed to ... - (CID_Driver_Done): This. - * src/cid/cidobjs.h: Updated. - * src/cidriver.c: Updated. - - * src/pshinter/pshrec.c (t2_hint_stems): Fixed. - - * src/base/ftobjs.c (FT_Done_Library): Fixed a stupid bug that - crashed the library on exit. - - * src/type1/t1gload.c (T1_Load_Glyph): Enable font matrix - transformation of hinted glyphs. - - * src/cid/cidload.c (cid_read_subrs): Fix error condition. - - * src/cid/cidobjs.c (CID_Face_Done): Fixed a memory leak; the subrs - routines were never released when CID faces were destroyed. - - * src/cff/cffload.h, src/cff/cffload.c, src/cff/cffgload.c: Updated - to move the definition of encoding tables back within `cffload.c' - instead of making them part of a shared header (causing problems in - `multi' builds). This reverts change 2001-08-08. - - * docs/CHANGES: Updated for 2.0.6 release. - * docs/TODO: Added `stem3 and counter hints support' to the TODO - list for the Postscript hinter. - * docs/BUGS: Closed the AUTOHINT-NO-SBITS bug. - -2001-12-19 David Turner - - * include/freetype/cache/ftcache.h: Added comments to indicate that - some of the exported functions should only be used by applications - that need to implement custom cache types. - - * src/truetype/ttgload.c (cur_to_org, org_to_cur): Fixed a nasty bug - that prevented composites from loading correctly, due to missing - parentheses around macro parameters. - - * src/sfnt/sfobjs.c (SFNT_Load_Face): Make the `post' and `name' - tables optional to load PCL fonts properly. - - * src/truetype/ttgload.c (TT_Load_Glyph), src/base/ftobjs.c - (FT_Load_Glyph), include/freetype/freetype.h (FT_LOAD_SBITS_ONLY): - `Fixed' the bug that prevented embedded bitmaps to be loaded when - the auto-hinter is used. This actually is a hack but will be enough - until the internal re-design scheduled for FreeType 2.1. - - * src/raster/ftrend1.c (ft_raster1_render): Fixed a nasty outline - shifting bug in the monochrome renderer. - - * README: Updated version numbers to 2.0.6. - -2001-12-17 Werner Lemberg - - * src/truetype/ttgload.c (load_truetype_glyph): Fix test for invalid - glyph header. - -2001-12-15 Werner Lemberg - - * src/base/ftglyph.c (FT_Glyph_To_Bitmap): Remove compiler warning. - * include/freetype/ftcache.h (FTC_Node_Unref): Removed. It is - already in ftcmanag.h. - * src/cache/ftcsbits.c (ftc_sbit_node_load): Remove unused variable - `gfam'. - * src/cache/ftcmanag.c (ftc_family_table_alloc, - * ftc_family_table_free): Use FT_EXPORT_DEF. - * include/freetype/cache/ftcmanag.h: Updated. - * src/cache/ftccache.c (ftc_node_destroy): Use FT_EXPORT_DEF. - * src/cache/ftccmap.c (ftc_cmap_node_init): Remove unused variable - `cfam'. - Remove compiler warning. - (FTC_CMapCache_Lookup): Remove compiler warnings. - (ftc_cmap_family_init): Ditto. - (FTC_CMapCache_Lookup): Ditto. - - * builds/unix/configure.ac: Increase `version_info' to 8:0:2. - * builds/unix/configure: Regenerated. - -2001-12-14 Werner Lemberg - - * builds/mac/README: Updated. - -2001-12-14 Scott Long - - * src/truetype/ttgload.c (load_truetype_glyph): Fixing crash when - dealing with invalid fonts (i.e. glyph size < 10 bytes). - -2001-12-14 Sam Latinga - - * builds/mac/freetype.make: A new Makefile to build with MPW on - MacOS classic. - -2001-12-14 David Turner - - * src/truetype/ttgload.c (TT_Load_Glyph), src/type1/t1gload.c - (T1_Load_Glyph), src/cid/cidgload.c (CID_Load_Glyph), - src/cff/cffgload.c (CFF_Load_Glyph): Fixed a serious bug common to - all font drivers (the advance width was never hinted when it - should). - - * include/freetype/freetype.h (FREETYPE_PATCH): New macro. - * src/base/ftdbgmem.c (debug_mem_dummy) [!FT_DEBUG_MEMORY]: Don't - use `extern' keyword. - -2001-12-12 David Turner - - * src/pshinter/pshglob.c (psh_blues_scale_zones, psh_blues_snap_stem - psh_globals_new): Adding correct BlueScale/BlueShift support, plus - family blues processing. - * src/pshinter/pshglob.h (PSH_BluesRec): Updated. - - Started adding support for the Postscript hinter in the CFF module. - - * src/cff/cffgload.c: Include FT_INTERNAL_POSTSCRIPT_HINTS_H. - (CFF_Parse_CharStrings): Implement it. - * src/cff/cffgload.h: Updated. - -2001-12-12 Werner Lemberg - - * builds/unix/freetype2.m4: Some portability fixes. - -2001-12-11 Jouk Jansen - - * src/base/descrip.mms (OBJS): Add ftdebug.obj. - -2001-12-11 Werner Lemberg - - * src/sfnt/ttload.c (TT_Load_Generic_Header): Typos. - -2001-12-11 David Turner - - * builds/unix/freetype-config.in: Modified the script to prevent - passing `-L/usr/lib' to gcc. - - * docs/FTL.TXT: Simple fix (change `LICENSE.TXT' to `FTL.TXT'). - - * builds/unix/freetype2.m4: New file for checking configure paths. - We need to install it in $(prefix)/share/aclocal/freetype2.m4 but I - didn't modify builds/unix/install.mk yet. - - * INSTALL: Updated the instructions to build shared libraries with - Jam. They were simply wrong. - - * src/base/fttrigon.c (FT_Cos): Fixed a small bug that caused - slightly improper results for `FT_Cos' and `FT_Sin' (example: - FT_Sin(0) == -1!). - -2001-12-11 Detlef Würkner - - * include/freetype/internal/ftstream.h (GET_LongLE, GET_ULongLE): - Fixed incorrect argument types. - -2001-12-10 Francesco Zappa Nardelli - - * src/pcf/pcfdriver.c (PCF_Init_Face): Allow Xft to use PCF fonts - by setting the `face->metrics.max_advance' correctly. - -2001-12-07 David Turner - - * include/freetype/cache/ftccmap.h, src/cache/ftccmap.c: Added new - charmap cache. - * src/cache/ftcache.c: Updated. - - * src/autohint/ahhint.c (ah_hinter_hint_edges): s/UNUSED/FT_UNUSED/. - -2001-12-06 Leonard Rosenthol - - Added support for reading .dfont files on Mac OS X. Also added a - new routine which looks up a given font by name in the Mac OS and - returns the disk file where it resides. - - * src/base/ftmac.c: Include and . - (is_dfont): New auxiliary function. - (FT_New_Face_From_dfont): New function. - (FT_GetFile_From_Mac_Name): New exported function. - (FT_New_Face): Updated. - * include/freetype/ftmac.h: Updated. - -2001-12-06 David Turner - - * src/cache/Jamfile, src/cache/rules.mk: Updated. - -2001-12-06 Werner Lemberg - - * INSTALL: Small update. - -2001-12-05 David Turner - - * src/base/ftglyph.c (FT_Glyph_To_Bitmap): Re-ordered code for - debugging purposes. - Comment out use of `origin'. - - * src/smooth/ftsmooth.c (ft_smooth_render): Fixed a nasty hidden bug - where outline shifting wasn't correctly undone after bitmap - rasterization. This created problems with certain glyphs (like '"' - of certain fonts) and the cache system. - - * src/pshinter/pshalgo1.c (psh1_hint_table_init): Fix typo. - * src/pshinter/pshalgo2.c (psh2_hint_table_init): Fix typo. - (ps2_hints_apply): Small fix. - -2001-12-05 David Turner - - * src/pshinter/pshalgo2.c (psh2_hint_table_init), - src/pshinter/pshalgo1.c (psh1_hint_table_init): Removed compiler - warnings. - - * include/freetype/ftcache.h, include/freetype/cache/*, src/cache/*: - Yet another massive rewrite of the caching sub-system in order to - both increase performance and allow simpler cache sub-classing. As - an example, the code for the image and sbit caches is now much - simpler. - - I still need to update the documentation in - www/freetype2/docs/cache.html to reflect the new design though. - - * include/freetype/config/ftheader.h (FT_CACHE_CHARMAP_H): New - macro. - (FT_CACHE_INTERNAL_CACHE_H): Updated. - -2001-12-05 David Krause - - * docs/license.txt: s/X Windows/X Window System/. - -2001-12-04 Werner Lemberg - - * src/raster/ftraster.c: Fix definition condition of MEM_Set(). - * src/smooth/ftgrays.c (M_Y): Change value to 192. - * src/base/ftdbgmem.c (ft_mem_table_destroy): Fix printf() parameter. - Remove unused variable. - * src/cache/ftcimage.c (ftc_image_node_init, - ftc_image_node_compare): Remove unused variables. - * src/cache/ftcsbits.c (ftc_sbit_node_weight): Remove unused - variable. - * src/raster/ftraster.c (MEM_Set): Move definition down to avoid - compiler warning. - * src/autohint/ahhint.c (ah_hinter_hint_edges): Use UNUSED() to - avoid compiler warnings. - * src/pcf/pcfread.c (tableNames): Use `const'. - (pcf_read_TOC): Change counter name to avoid compiler warning. - Use `const'. - * src/pshinter/pshrec.c (ps_hints_close): Remove redundant - declaration. - * src/pshinter/pshalgo1.c (psh1_hint_table_init): Rename variables - to avoid shadowing. - * src/pshinter/pshalgo2.c (psh2_hint_table_activate_mask): Ditto. - * src/type1/t1objs.h: Remove double declarations of `T1_Size_Init()' - and `T1_Size_Done()'. - -2001-11-20 Antoine Leca - - * include/freetype/ttnameid.h: Added some new Microsoft language - codes and LCIDs as found in MSDN (Passport SDK). Also added - comments about the meaning of bit 57 of the `OS/2' table - (TT_UCR_SURROGATES) which (with OpenType v.1.3) now means `there is - a character beyond 0xFFFF in this font'. Thanks to Detlef Würkner - for noticing this. - -2001-11-20 David Turner - - * src/pshinter/{pshalgo2.c, pshalgo1.c}: Fixed stupid bug in sorting - routine that created nasty alignment artefacts. - - * src/pshinter/pshrec.c, tests/gview.c: Debugging updates. - - * src/smooth/ftgrays.c: De-activated experimental gamma support. - Apparently, `optimal' gamma tables depend on the monitor type, - resolution and general karma, so it's better to compute them outside - of the rasterizer itself. - (gray_convert_glyph): Use `volatile' keyword. - -2001-10-29 David Turner - - Adding experimental `gamma' support. This produces smoother glyphs - at small sizes for very little cost. - - * src/smooth/ftgrays.c (grays_init_gamma): New function. - (gray_raster_new): Use it. - - Various fixes to the auto-hinter. They merely improve the output of - sans-serif fonts. Note that there are still problems with serifed - fonts and composites (accented characters). - - * src/autohint/ahglyph.c (ah_outline_load, - ah_outline_link_segments): Implement it. - Fix typos. - (ah_outline_save, ah_outline_compute_segments): Fix typos. - * src/autohint/ahhint.c (ah_align_serif_edge): New argument - `vertical'. Implement improvement. - (ah_hint_edges_3, ah_hinter_hint_edges): Implement it. - Fix typos. - (ah_hinter_align_strong_points, ah_hinter_align_weak_points): Fix - typos. - (ah_hinter_load): Set `ah_debug_hinter' if DEBUG_HINTER is defined. - * src/autohint/ahmodule.c: Implement support for DEBUG_HINTER macro. - * src/autohint/ahtypes.h: Ditto. - (AH_Hinter): Remove `disable_horz_edges' and `disable_vert_edges' - (making them global as `ah_debug_disable_horz' and - `ah_debug_disable_vert'). - Fix typos. - - * tests/gview.c: Updated the debugging glyph viewer to show the - hints generated by the `autohint' module. - -2001-10-27 David Turner - - * src/cache/ftcchunk.c (ftc_chunk_cache_lookup): Fixed a bug that - considerably lowered the performance of the abstract chunk cache. - -2001-10-26 David Turner - - * include/freetype/ftcache.h, include/freetype/cache/*.h, - src/cache/*.c: Major re-design of the cache sub-system to provide - better performance as well as an `Acquire'/`Release' API. Seems to - work well here, but probably needs a bit more testing. - -2001-10-26 Leonard Rosenthol - - * builds/mac/README: Updated to reflect my taking over the project - and that is now being actively maintained. - - * src/base/ftmac.c (parse_fond): Applied patches from Paul Miller - to support loading a face other than the - first from a FOND resource. - (FT_New_Face_From_FOND): Updated. - -2001-10-25 Leonard Rosenthol - - * builds/mac/ftlib.prj: Update of CodeWarrior project file for Mac - OS for latest version (7) of CWPro and for recent changes to the FT - source tree. - -2001-10-25 David Turner - - * include/freetype/config/ftoption.h: Updated comments to explain - precisely how to use project-specific macro definitions without - modifying this file manually. - - (FT_CONFIG_FORCE_INT64): Define. - - (FT_DEBUG_MEMORY): New macro. - -2001-10-24 Tom Kacvinsky - - * builds/unix/ftsystem.c (FT_New_Memory): Added a missing `{'. - -2001-10-23 David Turner - - * include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c: - Improvements to the memory debugger to report more information in - case of errors. Also, some allocations that occurred through REALLOC - couldn't be previously caught correctly. - - * src/autohint/ahglyph.c (ah_outline_compute_segments, - ah_outline_compute_edges), src/raster/ftraster.c (ft_black_new), - src/smooth/ftgrays.c (gray_render_span, gray_raster_new): Replaced - liberal uses of memset() by the MEM_Set() macro. - -2001-10-23 David Turner - - * src/raster/ftraster.c (Update): Removed to be inlined in ... - (Sort): Updated. - -2001-10-22 David Turner - - * builds/unix/ftsystem.c (FT_New_Memory, FT_Done_Memory), - builds/vms/ftsystem.c (FT_New_Memory, FT_Done_Memory), - builds/amiga/ftsystem.c (FT_New_Memory, FT_Done_Memory), - src/base/ftdbgmem.c: Updated the memory debugger and - platform-specific implementations of `ftsystem' in order to be able - to debug memory allocations on Unix, VMS and Amiga too! - - * src/pshinter/pshalgo2.c (psh2_hint_table_record_mask): Removed - some bogus warnings. - - * include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c: - Modified the debugging memory manager to report the location (source - file name + line number) where leaked memory blocks are allocated in - the source file. - - * src/base/ftdbgmem.c: New debugging memory manager. You must - define the FT_DEBUG_MEMORY macro in `ftoption.h' to enable it. It - will record every memory block allocated and report simple errors - like memory leaks and double deletes. - - * src/base/Jamfile: Include ftdbgmem. - * src/base/rules.mk: Ditto. - * src/base/ftbase.c: Include ftdbgmem.c. - - * include/freetype/config/ftoption.h: Added the FT_DEBUG_MEMORY - macro definition. - - * src/base/ftsystem.c (FT_New_Memory, FT_Done_Memory): Modified the - base component to use the debugging memory manager when the macro - FT_DEBUG_MEMORY is defined. - -2001-10-21 Tom Kacvinsky - - * src/cff/cffload.c (CFF_Done_Font): Free subfonts array only if - we are working with a CID keyed CFF font. Otherwise, a variable - that was never allocated memory might freed. This is a correction - to the previous patch for freeing subfonts. - -2001-10-21 Tom Kacvinsky - - * src/cff/cffload.c (CFF_Done_Font): Free the subfonts array to - avoid a memory leak. - -2001-10-21 David Turner - - * src/pshinter/pshalgo2.c, src/pshinter/pshalgo1.c, - src/pshinter/pshglob.c: Removing compiler warnings in pedantic modes - (in multi-object compilation mode, mainly). - -2001-10-20 Tom Kacvinsky - - * src/type1/t1load.c (parse_encoding): Add a test to make sure - that custom encodings (i.e., neither StandardEncoding nor - ExpertEncoding) are not loaded twice when the Type 1 font is - synthetic. - - * src/type1/t1load.c (parse_font_name, parse_subrs): Added a test - for when loading synthetic fonts to make sure that the font name - and subroutines are not loaded twice. This is to remove a memory - leak that occurred because the original memory blocks for these - objects were not deallocated when the objects were parsed the - second time. - -2001-10-19 David Turner - - * src/smooth/ftgrays.c, src/pshinter/pshglob.h, - src/pshinter/pshrec.c, src/pshinter/pshalgo2.c: Getting rid of - compiler warnings. - - * src/pshinter/module.mk, src/pshinter/rules.mk: Adding control - files to build the PostScript hinter with the `old' build system. - -2001-10-19 Jacob Jansen - - * descrip.mms, src/pshinter/descrip.mms: Updates to the VMS build - files. - -2001-10-18 David Turner - - * src/psnames/pstables.h, src/tools/glnames.py: Rewrote the - `glnames.py' script used to generate the `pstables.h' header file. - The old one contained a serious bug that made FreeType return - incorrect glyph names for certain glyphs. - - * src/truetype/ttdriver.c (Set_Char_Sizes): Changing computation of - pixel size from character size to use rounding. This is an - experiment to see whether this gives values similar to Windows for - scaled ascent/descent/etc. - - * src/base/ftcalc.c (FT_Div64by32): Changed the implementation - slightly since the original code was mis-compiled on Mac machines - using the MPW C compiler. - - * src/base/ftobjs.c (FT_Realloc): When a memory block was grown - through FT_Realloc(), the new bytes were not set to 0, which created - some strange bugs in the PostScript hinter. - (destroy_face): Don't deallocate unconditionally. - - * src/cid/cidgload.c (CID_Compute_Max_Advance, CID_Load_Glyph): - Adding support to new PostScript hinter. - - * include/freetype/internal/psglobal.h, - include/freetype/internal/pshints.h, - include/freetype/config/ftmodule.h, src/pshinter/Jamfile, - src/pshinter/pshalgo.h, src/pshinter/pshalgo1.h, - src/pshinter/pshalgo1.c, src/pshinter/pshalgo2.h, - src/pshinter/pshalgo2.c, src/pshinter/pshglob.h, - src/pshinter/pshglob.c, src/pshinter/pshinter.c, - src/pshinter/pshmod.c, src/pshinter/pshmod.h, src/pshinter/pshrec.c, - src/pshinter/pshrec.h: Adding new PostScript hinter module. - - * include/freetype/internal/ftobjs.h, - include/freetype/internal/internal.h, - include/freetype/internal/psaux.h, - include/freetype/internal/t1types.h, src/psaux/psobjs.c, - src/psaux/psobjs.h, src/psaux/t1decode.h, src/psaux/t1decode.c, - src/type1/t1driver.c, src/type1/t1gload.c, src/type1/t1objs.c, - src/type1/t1objs.h: Updates to use the new PostScript hinter. - - * tests/Jamfile, tests/gview.c: Adding a new glyph hinting - viewer/debugger to the source tree. Note that you will _not_ be - able to compile it since it depends on an unavailable graphics - library named `Nirvana' to render vector images. - -2001-10-17 David Turner - - - * Version 2.0.5 released. - ========================= - - - * include/freetype/freetype.h, include/internal/ftobjs.h, - src/base/ftobjs.c, src/type1/t1driver.c: Adding a new function named - 'FT_Get_Postscript_Name' to retrieve the PostScript name of a given - font. Should work with all formats except pure CFF/CEF fonts (this - will be added soon). - - * src/cid/cidriver (cid_get_postscript_name): New function. - (CID_Get_Interface): Handle `postscript_name' interface. - - * src/sfnt/sfdriver.c (get_sfnt_postscript_name): New function. - (SFNT_Get_Interface): Handle `postscript_name' interface. - - * src/type1/t1driver.c (t1_get_ps_name): New function. - (Get_Interface): Handle `postscript_name' interface. - - * README, docs/CHANGES: Updated for 2.0.5 release. - -2001-10-08 David Turner - - Fixed a bug in `glnames.py' that prevented it from generating - correct glyph names tables. This resulted in the unavailability of - certain glyphs like `Cacute', `cacute' and `lslash' in Unicode - charmaps, even if these were present in the font (causing problems - for Polish users). - - * src/tools/glnames.py (mac_standard_names): Fixed. - (t1_standard_strings): Some fixes and renamed to ... - (sid_standard_names): This. - (t1_expert_encoding): Fixed. - (the_adobe_glyph_list): Renamed to ... - (adobe_glyph_names): This. - (the_adobe_glyphs): Renamed to ... - (adobe_glyph_values): This. - (dump_mac_indices, dump_glyph_list, dump_unicode_values, main): - Updated. - * src/psnames/pstables.h: Regenerated. - * src/psnames/psmodule.c (PS_Unicode_Value): Fix offset. - Fix return value. - Use `sid_standard_table' and `ps_names_to_unicode' instead of - `t1_standard_glyphs' and `names_to_unicode'. - (PS_Macintosh_Name): Use `ps_glyph_names' instead of - `standard_glyph_names'. - (PS_Standard_Strings): Use `sid_standard_names' instead of - `t1_standard_glyphs'. - - * doc/BUGS, doc/TODO: New documents. - -2001-10-07 Richard Barber - - * src/cache/ftlru.c (FT_Lru_Lookup_Node): Fixed a bug that prevented - correct LRU behaviour. - -2001-10-07 David Turner - - setjmp() and longjmp() are now used for rollback (i.e. when memory - pool overflow occurs). - - Function names are now all uniformly prefixed with `gray_'. - - * src/smooth/ftgrays.c: Include . - (ErrRaster_MemoryOverflow): New macro. - (TArea): New type to store area values in each cell (using `int' was - too small on 16-bit systems). is included to properly - get the needed data type. - (TCell, TRaster): Use it. - (TRaster): New element `jump_buffer'. - (gray_compute_cbox): Use `RAS_ARG' as the only parameter and get - `outline' from it. - (gray_record_cell): Use longjmp(). - (gray_set_cell): Use gray_record_cell() for error handling. - (gray_render_line, gray_render_conic, gray_render_cubic): Simplify. - (gray_convert_glyph_inner): New function, using setjmp(). - (gray_convert_glyph): Use it. - -2001-10-07 David Turner - - Provide a public API to manage multiple size objects for a given - FT_Face in the new header file `ftsizes.h'. - - * include/freetype/ftsizes.h: New header file, - * include/freetype/internal/ftobjs.h: Use it. - Remove declarations of FT_New_Size and FT_Done_Size (moved to - ftsizes.h). - * include/freetype/config/ftheader.h (FT_SIZES_H): New macro. - * src/base/ftobjs.c (FT_Activate_Size): New function. - * src/cache/ftcmanag.c: Include ftsizes.h. - (ftc_manager_init_size, ftc_manager_flush_size): Use - FT_Activate_Size. - -2001-09-20 Detlef Würkner - - * builds/amiga/*: Added port to Amiga with the SAS/C compiler. - -2001-09-15 Detlef Würkner - - * src/type1/t1afm.c (T1_Done_AFM): Free `afm'. - -2001-09-10 Yao Zhang - - * src/sfnt/ttcmap.c (code_to_index2): Handle code values with - hi-byte == 0 correctly. - -2001-09-10 Werner Lemberg - - * builds/link-std.mk ($(PROJECT_LIBRARY)): Fix typo. - -2001-08-30 Martin Muskens - - * src/type1/t1load.c (parse_font_matrix): A new way to compute the - units per EM with greater accuracy (important for embedded T1 fonts - in PDF documents that were automatically generated from TrueType - ones). - - * src/type1/t1load.c (is_alpha): Now supports `+' in font names; - this is used in embedded fonts. - - * src/psaux/psobjs.c (PS_Table_Add): Fixed a reallocation bug that - generated a dangling pointer reference. - -2001-08-30 Anthony Feik - - * src/type1/t1afm.c (T1_Read_AFM): Now correctly sets the flag - FT_FACE_FLAG_KERNING when appropriate for Type1 + AFM files. - -2001-08-25 Werner Lemberg - - * src/sfnt/ttload.c (TT_Load_CMap): Fix frame length of - `cmap_rec_fields'. - - * include/freetype/fterrors.h [!FT_CONFIG_OPTION_USE_MODULE_ERRORS]: - Undefine FT_ERR_BASE before defining again. - -2001-08-22 Werner Lemberg - - * src/truetype/ttinterp.h: Fix prototype of TT_Move_Func. - -2001-08-21 Werner Lemberg - - * builds/dos/dos-def.mk (NO_OUTPUT): Don't use `&>' but `>'. - -2001-08-21 David Turner - - * include/freetype/config/ftoption.h: Changed the default setting - for FT_CONFIG_OPTION_USE_MODULE_ERRORS to undefined, since it breaks - source compatibility in a few cases. Updated the comment to explain - that too. - -2001-08-17 Martin Muskens - - * src/base/ftcalc.c (FT_MulDiv): Fixed serious typo. - -2001-08-12 Werner Lemberg - - Updating to OpenType 1.3. - - * include/freetype/internal/tttypes.h (TT_CMap0, TT_CMap2, TT_CMap4, - TT_CMap6): Adding field `language'. - (TT_CMapTable): Removing field `language'. - Type of `length' field changed to FT_ULong. - Adding fields for cmaps format 8, 10, and 12. - (TT_CMapGroup): New auxiliary structure. - (TT_CMap8_12, TT_CMap10): New structures. - * include/freetype/tttables.h (TT_HoriHeader, TT_VertHeader): - Removed last element of `Reserved' array. - * include/freetype/ttnameid.h (TT_PLATFORM_CUSTOM, TT_MS_ID_UCS_4, - TT_NAME_ID_CID_FINDFONT_NAME): New macros. - - * src/sfnt/ttcmap.c (TT_CharMap_Load): Updated loading of `language' - field to the new structures. - Fixed freeing of arrays in case of unsuccessful loads. - Added support for loading format 8, 10, and 12 cmaps. - (TT_CharMap_Free): Added support for freeing format 8, 10, and 12 - cmaps. - (code_to_index4): Small improvement. - (code_to_index6): Ditto. - (code_to_index8_12, code_to_index10): New functions. - * src/sfnt/ttload.c (TT_Load_Metrics_Header): Updated to new - structure. - (TT_Load_CMap): Ditto. - - * src/sfnt/sfobjs.c (tt_encodings): Add MS UCS4 table (before MS - Unicode). - -2001-08-11 Werner Lemberg - - * src/type1/t1driver.c (t1_get_name_index): Fix compiler warning. - -2001-08-09 Tom Kacvinsky - - * src/cff/cffdrivr.c (get_cff_glyph_name): Renamed to - cff_get_glyph_name for consistency. - - (cff_get_glyph_index): Minor documentation change. - - * src/type1/t1driver.c (t1_get_name_index): New function used in - Get_Interface as the function returned when the `name_index' - function is requested. - - (get_t1_glyph_name): Renamed to t1_get_glyph_name for consistency. - -2001-08-08 Tom Kacvinsky - - * src/cff/cffload.c: Removed definitions of cff_isoadobe_charset, - cff_expert_charset, cff_expertsubset_charset, cff_standard_encoding, - and cff_expert_encoding arrays to cffload.h. - - * src/cff/cffload.h: Added definitions of cff_isoadobe_charset, - cff_expert_charset, cff_expertsubset_charset, cff_standard_encoding, - and cff_expert_encoding arrays. - - * src/cff/cffdrivr.c (cff_get_name_index): New function, returned - when `cff_get_interface' is called with a request for the - `name_index' function. - - (cff_get_interface): Modified so that it returns the function - `cff_get_name_index' when the `name_index' function is requested. - - * src/base/ftobjs.c (FT_Get_Name_Index): New function, used to - return a glyph index for a given glyph name only if the driver - supports glyph names. - - * include/freetype/internal/ftobjs.h (FT_Name_Index_Requester): - New function pointer type definition used in the function - FT_Get_Name_Index. - - * include/freetype/freetype.h (FT_Get_Name_Index): Added - documentation and prototype. - -2001-07-26 Werner Lemberg - - * builds/cygwin/*: Removed. Use the unix stuff instead. - -2001-07-26 Jouk Jansen - - * builds/vms/ftconfig.h (FT_CALLBACK_DEF): Updated to change dated - 2001-06-27. - -2001-07-17 Werner Lemberg - - * include/freetype/internal/psaux.h (PS_Table): Use FT_Offset for - `cursor' and `capacity'. - * src/psaux/psobjs.c (reallocate_t1_table): Use FT_Long for second - parameter. - (PS_Table_Add): Use FT_Offset for `new_size'. - - Add support for version 0.5 maxp tables. - - * src/sfnt/ttload.c (TT_Load_MaxProfile): Implement it. - (TT_Load_OS2): Initialize some values. - -2001-07-13 Werner Lemberg - - * src/base/ftsynth.c: Include ftcalc.h unconditionally. - -2001-07-07 David Turner - - * src/truetype/ttgload.c, src/truetype/ttinterp.c, src/pcf/pcfread: - Removed pedantic compiler warnings when the bytecode interpreter is - compiled in. - -2001-07-03 Werner Lemberg - - * src/autohint/ahhint.c (ah_hinter_align_weak_points): Remove - unused variable `edges'. - (ah_hinter_load): Remove unused variables `old_width' and - `new_width'. - * src/cid/cidload.c (cid_decrypt): Use `U' for constant (again). - * src/psaux/psobjs.c (T1_Decrypt): Ditto. - * src/type1/t1parse.c (T1_Get_Private_Dict): Ditto. - -2001-06-28 David Turner - - * include/internal/ftstream.h: Modified the definitions - of the FT_GET_XXXX and NEXT_XXXX macros for 16-bit correctness. - -2001-06-26 Werner Lemberg - - * src/cid/cidload.c, src/cid/cidload.h (cid_decrypt): Use FT_Offset - instead of FT_Int as type for `length' parameter. - * include/freetype/internal/psaux.h (PSAux_Interface): Updated. - -2001-06-27 Wolfgang Domröse - - * src/psaux/psobjs.c, src/psaux/psobjs.h (T1_Decrypt): Use FT_Offset - instead of FT_Int as type for `length' parameter. - - - * Version 2.0.4 released. - ========================= - - -2001-06-27 David Turner - - * builds/unix/ftconfig.in: Changed the definition of the - FT_CALLBACK_DEF macro. - - * include/freetype/ftconfig.h, src/*/*.c: Changed the definition and - use of the FT_CALLBACK_DEF macro in order to support 16-bit - compilers. - - * builds/unix/ftconfig.in: Changed the definition of the - FT_CALLBACK_DEF macro. - - * src/sfnt/ttload.c (TT_Load_Kern): The kern table loader now ensures - that the kerning table is correctly sorted (some problem fonts don't - have a correct kern table). - -2001-06-26 Wolfgang Domröse - - * include/freetype/internal/ftstream.h (FT_GET_OFF3_LE): Fix typo. - -2001-06-24 David Turner - - * src/base/ftcalc.c (ft_div64by32): Fixed the source to work - correctly on 16-bit systems. - -2001-06-23 Anthony Fok - - * debian/*: Added Debian package build directory for 2.0.4. - -2001-06-22 David Turner - - * docs/PATENTS: Added patents disclaimer. This one was missing! - - * docs/CHANGES, docs/todo: Updated for the upcoming 2.0.4 release. - -2001-06-20 Werner Lemberg - - * include/freetype/config/ftconfig.h: Add two more `L's to - constants. - Add missing semicolons. - - * builds/toplevel.mk: Do similar change as for - builds/unix/detect.mk. - - * include/freetype/freetype.h (FT_ENC_TAG): New version to make it - easier to redefine. - * include/freetype/ftimage.h (FT_IMAGE_TAG): Ditto. - - * src/pcf/pcfread.c (pcf_get_encodings): Add cast. - -2001-06-19 David Turner - - * builds/win32/visualc/freetype.dsp, builds/win32/visualc/index.html: - Updated the Visual C++ project (for the 2.0.4 release). - - * builds/unix/detect.mk: Added rule for AIX detection (which uses - /usr/sbin/init instead of /sbin/init). - - * include/freetype/fterrors.h, src/*/*err*.h: Updated some of the - error macros to simplify handling of new error scheme. - -2001-06-19 Werner Lemberg - - * include/freetype/fttypes.h (FT_ERROR_MODULE): New macro. - -2001-06-19 David Turner - - Removing _lots_ of compiler warnings when the most pedantic warning - levels of Visual C++ and Borland C++ are used. Too many files to be - listed here, but FT2 now compiles without warnings with VC++ and the - `/W4' warning level (lint-style). - - * include/freetype/freetype.h (FT_New_Memory_Face): Updated - documentation. - * include/freetype/fttypes.h (FT_BOOL): New macro. - * include/freetype/internal/ftdebug.h: Add #pragma for Visual C++ - to suppress warning. - * include/freetype/internal/ftstream.h (FT_GET_SHORT_{BE,LE}, - FT_GET_OFF3_{BE,LE}, FT_GET_LONG_{BE,LE}): New macros. - (NEXT_*): Use them. - * src/autohint/ahglobal.c: Include FT_INTERNAL_DEBUG_H. - (FT_New_Memory_Face): Add `const' to function declaration. - -2001-06-18 Werner Lemberg - - Minor cleanups to remove compiler warnings. - - * include/freetype/cache/ftcmanag.h (FTC_MAX_BYTES_DEFAULT): Use - `L' for constant. - * include/freetype/config/ftoption.h (FT_RENDER_POOL_SIZE): Ditto. - * src/base/ftcalc.c (FT_MulDiv): Use `L' for constant. - * src/base/ftglyph.c (FT_Glyph_Get_CBox): Remove `error' variable. - * src/base/fttrigon.c (ft_trig_arctan_table): Use `L' for constants. - * src/base/ftobjs.c (FT_Done_Size): Fix return value. - (FT_Set_Char_Size, FT_Set_Pixel_Sizes, FT_Get_Kerning): Remove - unused `memory' variable. - * src/autohint/ahglyph.c (ah_get_orientation): Use `L' for constant. - * src/autohint/ahhint.c (ah_hint_edges_3, - ah_hinter_align_edge_points): Remove unused `before' and `after' - variables. - (ah_hinter_align_weak_points): Remove unused `edge_limit' variable. - (ah_hinter_load): Remove unused `new_advance', `start_contour', - and `metrics' variables. - * src/cff/cffload.c (CFF_Load_Encoding): Remove dead code to avoid - compiler warning. - * src/cff/cffobjs.c (CFF_Init_Face): Remove unused `base_offset' - variable. - * src/cff/cffgload.c (CFF_Parse_CharStrings): Remove unused - `outline' variable. - (cff_compute_bias): Use `U' for constant. - * src/cid/cidload.c (cid_decrypt): Ditto. - * src/psaux/psobjs.c (T1_Decrypt): Ditto. - * src/psaux/t1decode.c (T1_Decoder_Parse_Charstrings): Ditto. - * src/sfnt/ttload.c (TT_Load_Kern): Remove unused `version' - variable. - * src/sfnt/ttsbit.c (TT_Load_SBit_Image): Remove unused `top' - variable. - * src/truetype/ttgload.c (load_truetype_glyph): Remove unused - `num_contours' and `ins_offset' variables. - (compute_glyph_metrics): Remove unused `Top' and `x_scale' - variables. - (TT_Load_Glyph): Remove unused `memory' variable. - * src/smooth/ftgrays.c (grays_raster_render): Use `L' for constants. - -2001-06-18 Werner Lemberg - - Make the new error scheme source compatible with older FT versions - by introducing another layer. - - * include/freetype/fterrors.h (FT_ERRORDEF_, FT_NOERRORDEF_): New - macros. - (FT_NOERRORDEF): Removed. - * include/*/*err*.h: Use FT_ERRORDEF_ and FT_NOERRORDEF_. - -2001-06-16 Werner Lemberg - - * include/freetype/freetype.h (FT_ENC_TAG): New macro. - (FT_Encoding_): Use it. - * include/freetype/ftimage.h (FT_IMAGE_TAG): Define it - conditionally. - -2001-06-14 David Turner - - Modified the TrueType interpreter to let it use the new - trigonometric functions provided in `fttrigon.h'. This gets rid of - some old 64-bit computation routines, as well as many warnings when - compiling the library with the `long long' 64-bit integer type. - - * include/freetype/config/ftoption.h: Undefine - FT_CONFIG_OPTION_OLD_CALCS. - * include/freetype/internal/ftcalc.h: Rearrange use of - FT_CONFIG_OPTION_OLD_CALCS. - * src/base/ftcalc.c: Add declaration of FT_Int64 if - FT_CONFIG_OPTION_OLD_CALCS isn't defined. - * src/truetype/ttinterp.c: Use FT_TRIGONOMETRY_H. - (Norm): Add a special version if FT_CONFIG_OPTION_OLD_CALCS isn't - defined. - (Current_Ratio, Normalize): Simplify code. - -2001-06-11 Mike Owens - - * src/base/ftcalc.c (FT_MulDiv, FT_DivFix, FT_Sqrt64): Remove - compiler warnings. - -2001-06-08 Werner Lemberg - - * builds/unix/configure.in: Renamed to ... - * builds/unix/configure.ac: This to make sure that autoconf 2.50 is - needed. - Run `autoupdate' on it. - Increase `version_info' to 7:0:1. - * builds/unix/configure: Regenerated. - -2001-06-08 David Turner - - * src/autohint/ahhint.c (ah_hinter_load_glyph): Fixed a bug that - corrupted transformed glyphs that were auto-hinted (the transform - was applied twice). - - Fixed a bug that returned an invalid linear width for composite - TrueType glyphs. - - * include/internal/tttypes.h (TT_Loader_): Two new elements `linear' - and `linear_def'. - * src/truetype/ttgload.c (load_truetype_glyph, - compute_glyph_metrics): Use it. - - * include/fttypes.h (FT_ERROR_BASE): New macro. - * src/base/ftobjs.c (FT_Open_Face, FT_Render_Glyph_Internal): Use it - to make source code work with the new error scheme implemented by - Werner. - * src/base/ftoutln.c (FT_Outline_Render): Ditto. - -2001-06-07 Werner Lemberg - - Updating to libtool 1.4.0 and autoconf 2.50. - - * builds/unix/ltconfig: Removed. - * builds/unix/ltmain.sh, builds/unix/configure.in, - builds/unix/aclocal.m4: Updated. - * builds/unix/configure: Regenerated. - -2001-06-06 Werner Lemberg - - Complete redesign of error codes. Please check ftmoderr.h for more - details. - - * include/freetype/internal/cfferrs.h, - include/freetype/internal/tterrors.h, - include/freetype/internal/t1errors.h: Removed. Replaced with files - local to the module. All extra error codes have been moved to - `fterrors.h'. - - * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. - - * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, - src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, - src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, - src/smooth/ftsmerrs.h, src/truetype/tterrors.h, - src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the - error names for the module it belongs to. - - * include/freetype/ftmoderr.h: New file, defining the module error - offsets. Its structure is similar to `fterrors.h'. - - * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. - (FT_ERRORDEF): Redefined to use module error offsets. - All internal error codes are now public; unused error codes have - been removed, some are new. - - * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New - macro. - * include/freetype/config/ftoption.h - (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. - - All other source files have been updated to use the new error codes; - some already existing (internal) error codes local to a module have - been renamed to give them the same name as in the base module. - - All make files have been updated to include the local error files. - -2001-06-06 Werner Lemberg - - * src/cid/cidtokens.h: Replaced with... - * src/cid/cidtoken.h: This file for 8+3 consistency. - - * src/raster/ftraster.c: Use macros for header file names. - - * src/include/freetype/tttables.h (TT_HoriHeader_, TT_VertHeader_): - Fix length of `Reserved' array. Note that this isn't the real fix - since recent OpenType specs have introduced a `CaretOffset' field - instead of the first reserved byte. - -2001-05-29 Werner Lemberg - - * INSTALL: Minor fixes. - - - * Version 2.0.3 released. - ========================= - - -2001-05-29 David Turner - - * INSTALL, docs/CHANGES: Updated. - -2001-05-25 David Turner - - Moved several documents from the top-level to the `docs' directory. - - * src/base/ftcalc.c (FT_DivFix): Small fix to return value. - -2001-05-16 David Turner - - * src/truetype/ttgload.c (load_truetype_glyph): Fixed a bug in the - composite loader. Spotted by Keith Packard. - * src/base/ftobjs.c (FT_GlyphLoader_Check_Points, - FT_GlyphLoader_Check_Subglyphs): Ditto. - -2001-05-14 David Turner - - Fixed the incorrect blue zone computations, and improved the - composite support. Note that these changes result in improved - rendering, while sometimes introducing their own artefacts. This is - probably the last big change to the autohinter before the - introduction of a complete replacement. - - * src/autohint/ahglobal.c (sort_values): Fix loop. - * src/autohint/ahglyph.c: Removed some obsolete code. - (ah_outline_compute_edges): Modify code to set the ah_edge_round - flag. - (ah_outline_compute_blue_edges): Add code to compute active blue - zones. - * src/autohint/ahhint.c (ah_hinter_glyph_load): Change load_flags - value. - - * src/base/ftcalc.c (FT_DivFix): Fixed a bug in the 64-bit code that - created incorrect scale factors! - (FT_RoundFix, FT_CeilFix, FT_FloorFix): Minor improvements. - -2001-05-12 Werner Lemberg - - * include/freetype/ftbbox.h: FTBBOX_H -> __FTBBOX_H__. - * include/freetype/fttrigon.h: __FT_TRIGONOMETRY_H__ -> - __FTTRIGON_H__. - Include FT_FREETYPE_H. - Beautified; added copyright. - * src/base/fttrigon.c: Beautified; added copyright. - -2001-05-11 David Turner - - * src/cff/cffparse.c (cff_parse_font_matrix), src/cid/cidload.c - (parse_font_matrix), src/type1/t1load.c (parse_font_matrix): Fixed - the incorrect EM size computation. - - * include/freetype/fttrigon.h, src/base/fttrigon.c: New files, - adding trigonometric functions to the core API (using Cordic - algorithms). - * src/base/ftbase.c, src/base/Jamfile, src/base/rules.mk: Use them. - - * builds/newline: New file. - * builds/top_level.mk, builds/detect.mk: Use it. This fixes - problems with Make on Windows 2000, as well as problems when `make - distclean' is invoked on a non-Unix platform when there is no - `config.mk' in the current directory. - - * builds/freetype.mk: Fixed a problem with object deletions under - Dos/Windows/OS/2 systems. - - Added new directory to hold tools and test programs. - - * docs/docmaker.py, docs/glnames.py: Moved to... - * src/tools/docmaker.py, src/tools/glnames.py: This place. - * src/tools/cordic.py: New file used to compute arctangent table - needed by fttrigon.c. - * src/tools/test_bbox.c, src/tools/test_trig.c: New test files. - - * src/tools/docmaker.py: Improved the script to add the current date - at the footer of each web page (useful to distinguish between - versions). - - * Jamfile: Fixed incorrect HDRMACRO argument. - - * TODO: Removed the cubic arc bbox computation note, since it has been - fixed recently. - * src/base/ftbbox.c (test_cubic_zero): Renamed to... - (test_cubic_extrema): This function. Use `UL' for unsigned long - constants. - - * include/freetype/t1tables.h, include/freetype/config/ftoption.h: - Formatting. - -2001-05-10 David Turner - - * src/base/ftobjs.c (FT_Open_Face): Fixed a small memory leak - which happened when trying to open 0-size font files! - -2001-05-09 Werner Lemberg - - * include/freetype/internal/ftcalc.h: Move declaration of - FT_SqrtFixed() out of `#ifdef FT_LONG64'. - -2001-05-08 Francesco Zappa Nardelli - - * src/pcfdriver.c (PCF_Load_Glyph): Fixed incorrect bitmap width - computation. - -2001-05-08 David Turner - - * docs/docmaker.py: Updated the DocMaker script in order to add - command line options (--output,--prefix,--title), fix the erroneous - line numbers reported during errors and warnings, and other - formatting issues. - - * src/base/ftcalc.c (FT_MulDiv, FT_MulFix, FT_DivFix): Various tiny - fixes related to rounding in 64-bits routines and - pseudo-`optimizations'. - -2001-04-27 David Turner - - * src/base/ftbbox.c (BBox_Cubic_Check): Fixed the coefficient - normalization algorithm (invalid final bit position, and invalid - shift computation). - -2001-04-26 Werner Lemberg - - * builds/unix/config.guess, builds/unix/config.sub: Updated to - latest versions from gnu.org. - - * builds/compiler/gcc-dev.mk: Add `-Wno-long-long' flag. - - * include/freetype/internal/ftcalc.h: Define FT_SqrtFixed() - unconditionally. - * src/base/ftbbox.c: Include FT_INTERNAL_CALC_H. - Fix compiler warnings. - * src/base/ftcalc.c: Fix (potential) compiler warnings. - -2001-04-26 David Turner - - * src/base/ftcalc.c (FT_SqrtFixed): Corrected/optimized the 32-bit - fixed-point square root computation. It is now used even with - 64-bits integers, as it is _much_ faster than calling FT_Sqrt64 :-) - - * src/base/ftbbox.c: Removed invalid `#include FT_BEZIER_H' line. - -2001-04-25 David Turner - - * src/base/ftbbox.c (BBox_Cubic_Check): Rewrote function to use - direct computations with 16.16 values instead of sub-divisions. It - is now slower, but proves a point :-) - - * src/raster/ftraster.c, src/smooth/ftgrays.c, src/base/ftbbox.c: - Fixed the Bézier stack depths. - - * src/base/ftcalc.c (FT_MulFix): Minor rounding fix. - - * builds/beos: Added BeOS-specific files to the old build system - (no changes were necessary to support BeOS in the Jamfile though). - -2001-04-20 David Turner - - * ftconfig.h, ftoption.h: Updated `ftconfig.h' to detect 64-bit int - types on platforms where Autoconf is not available). Also removed - FTCALC_USE_LONG_LONG and replaced it with - FT_CONFIG_OPTION_FORCE_INT64. - - * builds/win32/freetype.dsp: Updated the Visual C++ project file. - Doesn't create a DLL yet. - - * cffgload.c: Removed a compilation warning. - -2001-04-10 Tom Kacvinsky - - * t1load.c (parse_charstrings): Changed code for placing .notdef - glyph into slot 0 so that we no longer have a memory access - violation. - - * t1load.h: In structure T1_Loader, added swap_table (of type - PS_Table) to facilitate placing the .notdef glyph into slot 0. - -2001-04-10 Francesco Zappa Nardelli - - * src/pcf/pcfdriver.c (PCF_Get_Char_Index): Fix return value. - -2001-04-09 Laurence Withers - - * builds/dos/detect.mk: Add support for bash. - -2001-04-05 Werner Lemberg - - * builds/os2/*.mk: These files have been forgotten to update to - the structure of similar makefiles. - * builds/dos/*.mk: Ditto. - * builds/ansi/*.mk: Ditto. - - * builds/win32/win32-def.mk (BUILD): Fix typo. - - * builds/compiler/*.mk (CLEAN_LIBRARY): Don't use NO_OUTPUT. - This is already used in the link_*.mk files. - -2001-04-03 Werner Lemberg - - * src/*/Jamfile: Slight changes to make files more cryptic. - -2001-04-03 Werner Lemberg - - * Jamfile, src/Jamfile, src/*/Jamfile: Formatted. Slight changes - to give files identical structure. - -2001-04-02 Werner Lemberg - - * CHANGES: Reformatted, minor fixes. - * TODO: Updated. - * README: Formatting. - * include/freetype/freetype.h: Formatting. - - * Jamfile: Fix typo. - - * src/cff/cffparse.c: Move error code #defines to... - * include/freetype/internal/cfferrs.h: This file. - * src/cff/cffdrivr.c, src/cff/cffobjs.c, src/cff/cffload.c: Replaced - `FT_Err_*' with `CFF_Err_*'. - * src/cid/cidparse.c: Replaced `FT_Err_*' with `T1_Err_*'. - * src/psaux/psobjs.c, src/psaux/t1decode.c: Ditto. - * src/sfnt/sfobjs.c, src/sfnt/ttload.c: Replaced `FT_Err_*' with - `TT_Err_*'. - * src/truetype/ttgload.c, src/truetype/ttobjs.c: Ditto. - * src/type1/t1gload.c, src/type1/t1load.c, src/type1/t1objs.c, - src/type1/t1parse.c: Replaced `FT_Err_*' with `T1_Err_*'. - - * include/freetype/internal/cfferrs.h: Add - `CFF_Err_Unknown_File_Format'. - * include/freetype/internal/t1errors.h: Add - `T1_Err_Unknown_File_Format'. - * include/freetype/internal/tterrors.h: Add - `TT_Err_Unknown_File_Format'. - - * src/cff/cffload.h: Add `cff_*_encoding' and `cff_*_charset' - references. - * src/psaux/psobjs.c: Include `FT_INTERNAL_TYPE1_ERRORS_H'. - - * src/cff/cffobjs.c (CFF_Init_Face, CFF_Done_Face): Use - FT_LOCAL_DEF. - * src/cid/cidobjs.c (CID_Done_Driver): Ditto. - * src/truetype/ttobjs.c (TT_Init_Face, TT_Done_Face, TT_Init_Size): - Ditto. - * src/type1/t1objs.c (T1_Done_Driver): Ditto. - * src/pcf/pcfdriver.c (PCF_Done_Face): Ditto. - * src/pcf/pcf.h: Use FT_LOCAL for `PCF_Done_Face'. - -2001-04-02 Tom Kacvinsky - - * src/sfnt/ttload.c (TT_Load_Metrics): Fix an improper pointer - dereference. Submitted by Herbert Duerr . - -2001-03-26 Tom Kacvinsky - - * include/freetype/config/ftconfig.h: Changed hexadecimal - constants to use suffix U to avoid problems with HP-UX's c89 - compiler. Submitted by G.W. Lucas . - -2001-03-24 David Turner - - * Jamrules, Jamfile, src/Jamfile, src/*/Jamfile: Adding jamfiles to - the source tree. See www.freetype.org/jam/index.html for details. - - - * Version 2.0.2 released. - ========================= - - -2001-03-20 Werner Lemberg - - * builds/win32/detect.mk: Fix .PHONY target for Intel compiler. - -2001-03-20 David Turner - - * include/freetype/config/ftheader.h, include/freetype/ftsnames.h: - Renamed `ftnames.h' to `ftsnames.h', and FT_NAMES_H to - FT_SFNT_NAMES_H. - - * docs/docmaker.py: Added generation of INDEX link in table of - contents. - - * INSTALL, docs/BUILD: Updated documentation to indicate that the - compilation process has changed slightly (no more `src' required in - the include path). - - * builds/*/*-def.mk: Changed the objects directory from `obj' to - `objs'. - - * include/freetype/config/ftheader.h: Removed obsolete macros like - FT_SOURCE_FILE, etc. and added cache-specific macro definitions that - were previously defined in . Added comments to - be included in a new API Reference section. - - * src/*/*: Removed the use of FT_SOURCE_FILE, etc. Now, each - component needs to add its own directory to the include path at - compile time. Modified all `rules.mk' and `descrip.mms' - accordingly. - -2001-03-20 Werner Lemberg - - * builds/unix/configure.in: Add $ft_version. - * builds/unix/freetype-config.in: Use it. - * builds/unix/configure: Updated. - -2001-03-19 Tom Kacvinsky - - * src/type1/t1load.c (parse_font_matrix): Assign the units per em - value an unsigned short value, first by shifting right 16 bits, - then by casting the results to FT_UShort. - - * src/cff/cffparse.c (cff_parse_font_bbox): Assign the units per em - value an unsigned short value, first by shifting right 16 bits, - then by casting the results to FT_UShort. - -2001-03-17 David Turner - - * src/cid/cidobjs.c, src/cid/cidload.c, src/pcf/pcfread.c, - src/type1/t1load.c, src/type1/t1objs.c: Added a few casts to remove - compiler warnings in pedantic modes. - - * include/config/ft2build.h, include/config/ftheader.h: The file - `ft2build.h' was renamed to `ftheader.h' to avoid conflicts with the - top-level . - - * include/config/ftheader.h: Added new section describing the #include - macros. - -2001-03-17 Tom Kacvinsky - - * src/cff/cffparse.c (cff_parse_font_bbox): Obtain rounded FT_Fixed - values for the bounding box numbers. - - * src/cff/cffobjs.c (CFF_Init_Face): When processing a CFF/CEF font, - set `root->ascender' (`root->descender') to the integer part of - `root->bbox.yMax' (`root->bbox.yMin', respectively). - -2001-03-16 Tom Kacvinsky - - * src/cff/cffdrivr.c (get_cff_glyph_name): New function. Used in - cff_get_interface to facilitate getting a glyph name for glyph index - via FT_Get_Glyph_Name(). - - (cff_get_interface): Added support for getting a glyph name via the - `glyph_name' module interface. Uses the new function - get_cff_glyph_name(). - Submitted by Sander van der Wal . - - * src/cff/cffobjs.c (CFF_Init_Face): Logical or the face flags with - FT_FACE_FLAG_GLYPH_NAMES only if FT_CONFIG_OPTION_NO_GLYPH_NAMES is - not defined. This is to add support for getting a glyph name from a - glyph index via FT_Get_Glyph_Name(). - Submitted by Sander van der Wal . - - * src/cff/cffgload.c (CFF_Parse_CharStrings): Added support for - deprecated operator `dotsection'. - Submitted by Sander van der Wal . - -2001-03-12 Werner Lemberg - - * src/psaux/t1decode.c (T1_Decoder_Parse_Charstrings): Fix error - messages. - - * INSTALL, docs/BUILD: We need GNU make 3.78.1 or newer. - -2001-03-12 Tom Kacvinsky - - * include/freetype/internal/psaux.h: Changed the lenIV member of - the T1_Decoder_ struct to be an FT_Int instead of an FT_UInt. - - * src/psaux/t1decode.c (T1_Decoder_Parse_Charstrings): Adjust - for lenIV seed bytes at the start of a decrypted subroutine. - - * src/cid/cidload.c (cid_read_subrs): Decrypt subroutines only - if lenIV >= 0. - - * src/cid/cidgload.c (cid_load_glyph): Decrypt charstrings only - if lenIV >= 0. - -2001-03-11 Werner Lemberg - - * TODO: Updated. - - * src/pcf/pcfread.c: Put READ_Fields() always in a conditional to - avoid compiler warnings. - -2001-03-10 Tom Kacvinsky - - * TODO: New file. - - * include/freetype/freetype.h: Added prototypes and notes for - three new functions: FT_RoundFix, FT_CeilFix, and FT_FloorFix. - * src/base/ftcalc.c (FT_RoundFix, FT_CeilFix, FT_FloorFix): Added - implementation code. - - * src/cid/cidobjs.c (CID_Init_Face): Use calculated units_per_EM, - and if that is not available, default to 1000 units per EM. Changed - assignment code for ascender and descender values. - * src/cid/cidload.c (parse_font_matrix): Added units_per_EM - processing. - (parse_font_bbox): Changed to use FT_Fixed number handling. - - * src/type1/t1objs.c (T1_Init_Face): Changed the assignment code - for ascender, descender, and max_advance_width. - * src/type1/t1load.c (parse_font_bbox): Changed to use FT_Fixed - number handling. - -2001-03-10 Henrik Grubbström - - * src/*/*.c: Added many casts to make code more 64bit-safe. - -2001-03-07 Werner Lemberg - - * INSTALL, docs/BUILD: We need GNU make 3.78 or newer. - -2001-03-07 Tom Kacvinsky - - * src/type1/t1objs.c (T1_Init_Face): Minor correction: We must wait - until parse_font_bbox is changed before we use logical shift rights - in the assignments of `root->ascender', `root->descender', and - `root->max_advance_width'. - - (T1_Done_Face): Free `char_name' table to avoid a memory leak. - Submitted by Sander van der Wal . - -2001-03-05 Tom Kacvinsky - - * src/cff/cffgload.c (CFF_Load_Glyph): Set glyph control data to the - the Type 2 glyph charstring (used by conversion programs). - Submitted by Ha Shao . - -2001-03-04 Antoine Leca - - * include/freetype/ttnameid.h: Correct a stupid typo which prevented - correct compilation (TT_MS_LANGID_TIGRIGNA_ETHIOPIA appeared twice). - -2001-03-04 Werner Lemberg - - * src/autohint/ahtypes.h (AH_Hinter): Add elements - `disable_horz_edges', `disable_vert_edges'. - * src/autohint/ahhint.c (ah_hint_edges_3, ah_hinter_hint_edges): Use - them (and remove static variables with the same names). - * src/pcf/pcfutil.c (BitOrderInvert): Add `const'. - * docs/glnames.py: Updated to latest pstables.h changes. - - * builds/unix/detect.mk: Add test for Hurd. - * builds/hurd/detect.mk: Removed. - -2001-03-04 Sander van der Wal - - * src/psnames/pstables.h: Add more `const'. - * src/pcf/pcfutil.c: Ditto. - -2001-03-04 Werner Lemberg - - * src/base/ftglyph.c (FT_Glyph_To_Bitmap): Fixing typo - (FT_Glyph_Done -> FT_Done_Glyph). - -2001-03-01 Antoine Leca - - * include/freetype/ttnameid.h: Added some new Microsoft language - codes and LCIDs as found in Office Xp. - -2001-02-28 David Turner - - * builds/hurd/detect.mk: New file. Added support to detect the GNU - Hurd operating system as Unix-like. Fix submitted by Anthony Fok - . - - * src/type1/t1gload.c (T1_Load_Glyph): Set glyph control data to the - the Type 1 glyph charstring (used by conversion programs). - Submitted by Ha Shao . - -2001-02-22 David Turner - - * src/base/ftgrays.c (grays_sweep): The function didn't exit - immediately if `num_cells' was 0 as it should. Thanks to Boris for - finding this out. - - * src/base/ftglyph.c (FT_Glyph_To_Bitmap): Fixed memory leak when - bitmap rendering fails (thanks to Graham Asher). - -2001-02-13 Werner Lemberg - - * docs/docmaker.py (DocSection::add_element): Use - `self.print_error()'. - - * builds/unix/config.{guess,sub}: Updated (from ftp.gnu.org). - -2001-02-13 David Turner - - * docs/docmaker.py, include/freetype/*.h: Updated the DocMaker - script to support chapters and section block ordering. Updated the - public header files accordingly. - - * src/base/ftglyph.c (FT_Glyph_Copy): Advance width and glyph format - were not correctly copied. - -2001-02-08 Tom Kacvinsky - - * src/cff/cffparse.c (cff_parse_font_matrix): Removed an - unnecessary fprintf( stderr, ... ). - -2001-02-07 Tom Kacvinsky - - * src/type1/t1objs.c (T1_Init_Face): Added code to get the - units_per_EM from the value assigned in parse_font_matrix, if - available. Default to 1000 if not available. - - * src/cff/cffparse.c (cff_parse_font_matrix): Added logic to get - the units_per_EM from the FontMatrix. - - (cff_parse_fixed_thousand): New function. Gets a real number from - the CFF font, but multiplies by 1000 (this is to avoid rounding - errors when placing this real number into a 16.16 fixed number). - - (cff_parse_real): Added code so that the integer part is moved - into the high sixteen bits of the 16.16 fixed number. - - * src/cff/cffobjs.c (CFF_Init_Face): Added logic to get the units - per EM from the CFF dictionary, if available. - - * include/freetype/internal/cfftypes.h: In struct CFF_Font_Dict_, - added a units_per_em member to facilitate passing of units_per_em - from function cff_parse_font_matrix. - - * src/type1/t1load.c (is_alpha): Make `-' a legal alphanumeric - character. This is so that font names with `-' are fully parsed, - etc... - -2001-02-02 Werner Lemberg - - * src/psaux/psobjs.c (shift_elements): Remove if clause (which is - obsolete now). - - (reallocate_t1_table, PS_Table_Done): Replace REALLOC() with ALLOC() - + MEM_Copy() to avoid a memory bug. - -2001-02-01 David Turner - - * docs/docmaker.py: Improved the index sorting routine to place - capital letters before small ones. Added the `' marker to - section blocks in order to give the order of blocks. - -2001-01-30 Antoine Leca - - * include/freetype/ttnameid.h: Latest updates to Microsoft language - ID codes. - -2001-01-24 Tom Kacvinsky - - * src/cff/t1load.c (parse_font_matrix): Added heuristic to get - units_per_EM from the font matrix. - - (parse_dict): Deleted test to see whether the FontInfo keyword has - been seen. Deletion of this test allows fonts without FontInfo - dictionaries to be parsed by the Type 1 driver. - - (T1_Open_Face): Deleted empty subroutines array test to make sure - fonts with no subroutines still are parsed. - -2001-01-17 Francesco Zappa Nardelli - - * src/pcfread.c (pcf_get_properties, pcf_get_metrics, - pcf_get_bitmaps): Fix compiler errors. - -2001-01-11 David Turner - - * src/pcf/pcfread.c: Removed some compilation warnings related - to comparison of signed vs. unsigned integers. - - * include/freetype/internal/ftdebug.h: Changed the debug trace - constants from trace_t2xxxx to trace_cffxxxx to be able to compile - the CFF driver in debug mode. - -2001-01-11 Matthew Crosby - - * builds/unix/freetype-config.in: Fix problems with separate - --prefix and --exec-prefix. - -2001-01-11 David Turner - - * docs/docmaker.py: Added cross-references generation as well as - more robust handling of pathname wildcard matching. - -2001-01-10 Werner Lemberg - - * docs/docmaker.py: Minor improvements to reduce unwanted spaces - and empty lines in output. - -2001-01-09 David Turner - - * docs/docmaker.py: Improved script to generate table of contents - and index pages. It also supports wildcards on non Unix systems. - - * include/freetype/*.h, include/freetype/cache/*.h: Updated comments - to include section definitions/delimitations for the API Reference - generator. - - * include/freetype/freetype.h: Moved declaration of - `FT_Generic_Finalizer' and the `FT_Generic' structure to... - * include/freetype/fttypes.h: here. - -2001-01-04 Werner Lemberg - - * include/freetype/ttnameid.h: Updated Unicode code range comments. - -2001-01-03 Tom Kacvinsky - - * src/cff/rules.mk: Use cffgload.{c,h} instead of t2gload.{c,h}. - - * include/freetype/internal/internal.h: Changed to use cfftypes.h - (cfferrs.h) instead of t2types.h (t2errors.h, respectively). - - * include/freetype/internal/cfftypes.h: Merged in changes from - t2types.h and made this the canonical `types' header for the CFF - driver. - - * include/freetype/internal/t2types.h: This file was merged with - cfftypes.h and is no longer necessary. - - * include/freetype/internal/t2errors.h: Renamed to cfferrs.h. - - * src/cff/cffobjs.c, src/cff/cffobjs.h, src/cff/cffparse.c, - src/cff/cffdrivr.c, src/cff/cff.c, src/cff/cffload.c, - src/cff/cffgload.c, src/cff/cffgload.h: Changed to use - cffgload.{c,h} instead of t2gload.{c,h}. All occurrences of t2_ - (T2_) were replaced with cff_ (CFF_, respectively). - - * src/cff/t2gload.h: Renamed cffgload.h. - - * src/cff/t2gload.c: Renamed cffgload.c - -2000-01-02 Jouk Jansen - - * builds/vms: Support files for VMS architecture added. - * descrip.mms, src/*/descrip.mms: VMS makefiles added. - * README.VMS: New file. - -2000-01-01 Werner Lemberg - - * LICENSE.TXT: Added info about PCF driver license. - -2001-01-01 Francesco Zappa Nardelli - - * src/pcf/*: New driver module for PCF font format (used in - X Window System). - * include/freetype/internal/ftdebug.h (FT_Trace): Added values for - PCF driver. - * include/freetype/internal/pcftypes.h: New file. - * include/freetype/config/ftmodule.h: Added PCF driver module. - -2001-01-01 Werner Lemberg - - * src/winfonts/winfnt.c (FNT_Get_Char_Index): Fix parameter type. - -2000-12-31 Werner Lemberg - - * builds/modules.mk (clean_module_list): Fixed deletion of module - file in case `make make_module_list' is called before `make setup'. - -2000-12-30 Werner Lemberg - - * src/cff/cffload.c (CFF_Load_Charset): Improved error messages. - (CFF_Load_Charset, CFF_Load_Encoding): Remove unnecessary variable - definition. - -2000-12-30 Tom Kacvinsky - - * include/freetype/internal/t2types.h, - include/freetype/internal/cfftypes.h: Changed the structures for - CFF_Charset and CFF_Encoding for the new implementations of the - charset and encoding parsers in the CFF driver. - - * src/cff/t2gload.c (t2_lookup_glyph_by_stdcharcode, - t2_operator_seac): Added these functions for use in implementing the - seac emulation provided by the Type 2 endchar operator. - (T2_Parse_CharStrings): Added seac emulation for the endchar - operator. - - * src/cff/cffload.c (CFF_Load_Encoding, CFF_Load_Charset, - CFF_Done_Encoding, CFF_Done_Charset): Extended to load and parse the - charset/encoding tables, and free the memory used by them when the - CFF driver is finished with them. Added tables - - cff_isoadobe_charset - cff_expert_charset - cff_expertsubset_charset - cff_standard_encoding - cff_expert_encoding - - so that the encoding/charset parser can handle predefined encodings and - charsets. - -2000-12-24 Tom Kacvinsky - - * src/cff/t2gload.c (T2_Load_Glyph): Added code so that the font - transform is applied. - - * src/cff/cffparse.c (cff_parse_font_matrix): Added code so that - the font matrix numbers are scaled by 1/(matrix->yy). Also, the - offset vector now contains integer values instead of 16.16 fixed - numbers. - -2000-12-22 Tom Kacvinsky - - * src/autohint/ahhint.c (ah_hinter_load_glyph): - Removed unnecessary comments and commented-out code. - -2000-12-21 David Turner - - * src/cid/cidafm.c, src/cid/cidafm.h: removed un-needed files, - we'll work on supporting CID AFM files later I guess :-) - -2000-12-21 Tom Kacvinsky - - * src/autohint/ahhint.c (ah_hinter_load, ah_hinter_load_glyph): - Changed so that fonts with a non-standard FontMatrix render - correctly. Previously, the first glyph rendered from such a - font did not have the transformation matrix applied. - -2000-12-17 Werner Lemberg - - * *.mk: Added lots of `.PHONY' targets. - -2000-12-17 Karsten Fleischer - - * *.mk: Implemented `platform' target to disable auto-detection. - -2000-12-14 Werner Lemberg - - * docs/design/modules.html: Removed. Covered by design-*.html. - - * INSTALL: Added info about makepp. - -2000-12-14 David Turner - - Added support for clipped direct rendering in the smooth renderer. - This should not break binary compatibility of existing applications. - - * include/freetype/fttypes.h, include/freetype/ftimage.h: Move - definition of the FT_BBox structure from the former to the latter. - * include/freetype/ftimage.h: Add `ft_raster_flag_clip' value to - FT_Raster_Flag enumeration. - Add `clip_box' element to FT_Raster_Params structure. - * src/smooth/ftgrays.c (grays_convert_glyph): Implement it. - - * INSTALL: Updated installation instructions on Win32, listing the - new `make setup list' target used to list supported - compilers/targets. - - * src/raster/ftraster.c (ft_black_render): Test for unsupported - direct rendering before testing arguments. - -2000-12-13 David Turner - - * include/freetype/config/ft2build.h, - include/freetype/internal/internal.h: Fixed header inclusion macros - to use direct definitions. This is the only way to do these things - in a portable way :-( The rest of the code should follow shortly - though everything compiles now. - - * builds/compiler/intelc.mk, builds/compiler/watcom.mk: New files. - - * builds/win32/detect.mk: Added support for the Intel C/C++ - compiler, as well as _preliminary_ (read: doesn't work!) support for - Watcom. Also added a new setup target. Type `make setup list' for - a list of supported command-line compilers on Win32. - - * src/base/ftdebug.c: Added dummy symbol to avoid empty file if - conditionals are off. - -2000-12-13 Werner Lemberg - - * builds/unix/ftsystem.c: Fixed typos. Fixed inclusion of wrong - ftconfig.h file. - -2000-12-12 Werner Lemberg - - * include/freetype/config/ft2build.h (FT2_ROOT, FT2_CONFIG_ROOT): - Removed. ANSI C doesn't (explicitly) allow macro expansion in - arguments using `##'. - (FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE): Use directory - names directly. Make them configurable. Use `##' to strip leading - and trailing spaces from arguments. - - * builds/unix/ft2unix.h: Adapted. - - * src/base/ftsystem.c (ft_alloc, ft_realloc, ft_free, ft_io_stream, - ft_close_stream): Use FT_CALLBACK_DEF. - - * builds/unix/ftsystem.c: Use new header scheme. - (FT_Done_Memory): Use free() from FT_Memory structure. - - * src/base/ftinit.c, src/base/ftmac.c: Header scheme fixes. - -2000-12-11 Werner Lemberg - - * include/freetype/config/ft2build.h (FT2_CONFIG_ROOT, - FT2_PUBLIC_FILE, FT2_CONFIG_FILE, FT2_INTERNAL_FILE, - FT_SOURCE_FILE): Use `##' operator to be really ANSI C compliant. - -2000-12-09 Werner Lemberg - - * builds/unix/detect.mk: Remove unused USE_CFLAGS variable. - -2000-12-08 Werner Lemberg - - * */*.h: Changed body inclusion macro names to start and end with - `__' (those which haven't converted yet). Fixed minor conversion - issues. - - * src/winfonts/winfnt.c: Updated to new header inclusion scheme. - - * src/truetype/ttinterp.c: Remove unused CALC_Length() macro. - -2000-12-07 David Turner - - * */*.[ch]: Changed source files to adhere to the new - header inclusion scheme. Not completely tested but works for now - here. - - * src/cff/t2driver.c: Renamed and updated to... - * src/cff/cffdrivr.c: New file. - * src/cff/t2driver.h: Renamed and updated to... - * src/cff/cffdrivr.h: New file. - * src/cff/t2load.c: Renamed and updated to... - * src/cff/cffload.c: New file. - * src/cff/t2load.h: Renamed and updated to... - * src/cff/cffload.h: New file. - * src/cff/t2objs.c: Renamed and updated to... - * src/cff/cffobjs.c: New file. - * src/cff/t2objs.h: Renamed and updated to... - * src/cff/cffobjs.h: New file. - * src/cff/t2parse.c: Renamed and updated to... - * src/cff/cffparse.c: New file. - * src/cff/t2parse.h: Renamed and updated to... - * src/cff/cffparse.h: New file. - * src/cff/t2tokens.h: Renamed and updated to... - * src/cff/cfftoken.h: New file. - - * src/cff/cff.c, src/cff/rules.mk: Updated. - -2000-12-06 David Turner - - * src/cache/ftlru.c (FT_Lru_Done): Fixed memory leak. - -2000-12-06 Werner Lemberg - - * builds/module.mk: Replaced `xxx #' with `xxx$(space). - * builds/os2/detect.mk, builds/win32/detect.mk: Moved comment to - avoid trailing spaces in variable. - * builds/freetype.mk: Use $(D) instead of $D to make statement more - readable. - - * docs/docmaker.py: Formatting. - -2000-12-05 David Turner - - * src/psaux/psauxmod.c: Fixed a broken inclusion of component - header files (an FT_FLAT_COMPILE test was missing). - - * src/cache/ftcmanag.c (FTC_Manager_Done): Fixed a bug that caused - an occasional crash when the function was called (due to a dangling - pointer). - - * src/base/ftsystem.c (FT_Done_Memory): Fixed an obvious bug: - The ANSI `free()' function was called instead of `memory->free()'. - - * docs/docmaker.py: Added section filtering, multi-page generation - (index page generation is still missing though). - -2000-12-04 David Turner - - * builds/unix/install.mk, builds/unix/ft2unix.h: The file `ft2unix.h' - is now installed as for Unix systems. Note that we - still use the `freetype2/freetype' installation path for now. - - * */*.[ch]: Now using as the default build and setup - configuration file in all public headers. Internal source files - still need some changes though. - - * builds/devel/ft2build.h, builds/devel/ftoption.h: Created a new - directory to hold all development options for both the Unix and - Win32 developer builds. - - * builds/win32/detect.mk, builds/win32/w32-bccd.mk, - builds/win32/w32-dev.mk: Changed the developer build targets to - `devel-gcc' and `devel-bcc' in order to be able to develop with the - Borland C++ compiler. - -2000-12-01 David Turner - - - * Version 2.0.1 released. - ========================= - - - * builds/unix/configure.in, builds/unix/configure, - builds/cygwin/configure.in, builds/cygwin/configure: Setting - `version_info' to 6:1:0 for the 2.0.1 release. - - * CHANGES: Added a summary of changes between 2.0.1 and 2.0. - - * builds/unix/ftconfig.in, builds/cygwin/ftconfig.in: Changes - to allow compilation under Unix with the Unix-specific config - files. - -2000-12-01 Werner Lemberg - - * INSTALL: Revised. - * builds/compiler/bcc-dev.mk, builds/compiler/visualage.mk, - builds/compiler/bcc.mk, builds/win32/w32-bcc.mk, - builds/win32/w32-bccd.mk: Revised. - * include/freetype/config/ftbuild.h, - include/freetype/internal/internal.h: Revised. - * include/freetype/ftimage.h: Updated to new header inclusion scheme. - -2000-11-30 Werner Lemberg - - * builds/toplevel.mk (.PHONY): Adding `distclean'. - * builds/unix/detect.mk (.PHONY): Adding `devel', `unix', `lcc', - `setup'. - -2000-11-30 David Turner - - * INSTALL: Slightly updated the quick starter documentation to - include IDE compilation, prevent against BSD Make, and specify `make - setup' instead of a single `make' for build configuration. - - * include/config/ftbuild.h, include/internal/internal.h: Added new - configuration files used to determine the location of all public, - configuration, and internal header files for FreeType 2. Modified - all headers under `include/freetype' to reflect this change. Note - that we still need to change the library source files themselves - though. - - * builds/compiler/bcc.mk, builds/compiler/bcc-dev.mk, - builds/win32/w32-bcc.mk, builds/win32/w32-bccd.mk, - builds/win32/detect.mk: Added new files to support compilation with - the free Borland C++ command-line compiler. Modified the detection - rules to recognize the new `bcc32' target in `make setup bcc32'. - - * src/sfnt/ttcmap.c, src/sfnt/ttpost.c, src/sfnt/ttsbit.c, - src/truetype/ttobjs.c, src/truetype/ttgload.c, - src/truetype/ttinterp.c: Fixed a few comparisons that Borland C++ - didn't really like. Basically, this compiler complains when FT_UInt - is compared to FT_UShort (apparently, it promotes `UShort' to `Int' - in these cases). - -2000-11-30 Tom Kacvinsky - - * t2objs.c (T2_Init_Face): Added calculation of `face->height' for - pure CFF fonts. - - * t1objs.c (T1_Init_Face): Fixed computation of `face->height'. - -2000-11-29 David Turner - - * src/base/ftbbox.c (BBox_Conic_Check): Fixed a really stupid - bug in the formula used to compute the conic Bézier extrema - of non-monotonous arcs. - -2000-11-29 Werner Lemberg - - * src/base/ftcalc.c (FT_SqrtFixed), src/base/ftobjs.c - (FT_Set_Renderer): Use FT_EXPORT_DEF. - * src/cache/ftcimage.c (FTC_Image_Cache_Lookup), - src/cache/ftcmanag.c (FTC_Manager_Done, FTC_Manager_Reset, - FTC_Manager_Lookup_Face, FTC_Manager_Lookup_Size, - FTC_Manager_Register_Cache), src/cache/ftcsbits.c - (FTC_SBit_Cache_Lookup): Ditto. - - * src/include/freetype/cache/ftcglyph.h (FTC_GlyphNode_Init), - src/include/freetype/ftmac.h (FT_New_Face_From_FOND): Use FT_EXPORT. - -2000-11-29 Werner Lemberg - - * src/sfnt/sfdriver.c: Include ttsbit.h and ttpost.h only - conditionally. - - * src/truetype/ttdriver.c (Set_Char_Sizes, Set_Pixel_Sizes): Set - `size->strike_index' only conditionally. - - * src/type1/t1driver.c, src/type1/t1objs.c: Include t1afm.h only - conditionally. - - * src/winfonts/winfnt.h: Move all type definitions to... - * src/include/freetype/internal/fnttypes.h: New file. - * src/winfonts/winfnt.c: Use it. - -2000-11-29 ??? ??? - - * include/freetype/internal/ftdebug.h: Replaced FT_CAT and FT_XCAT - with a direct solution (which also satisfies picky compilers). - -2000-11-28 YAMANO-UCHI Hidetoshi - - * src/truetype/ttobjs.c (TT_Init_Size): Fix #ifdef's to work with - disabled interpreter also. - - * src/base/ftnames.c (FT_Get_Sfnt_Name_Count): Fix incorrect - parentheses. - -2000-11-26 Tom Kacvinsky - - * src/cff/t2gload.c (T2_Parse_CharStrings): Added logic to glyph - width setting code to take into account even/odd argument counts - and glyph width operand before endchar/hmoveto/vmoveto. - -2000-11-26 Werner Lemberg - - * builds/ansi/ansi.mk: Fix inclusion order of files. - -2000-11-26 Keith Packard - - * src/type1/t1objs.c (T1_Init_Face): Compute style flags. - -2000-11-26 Werner Lemberg - - * builds/compiler/ansi-cc.mk (CLEAN_LIBRARY): Fix rule and - conditional. - -2000-11-23 Werner Lemberg - - * src/type1/t1load.c (parse_subrs, parse_charstrings): Use decrypt - function from PSAux module. - - * src/type1/t1parse.c (T1_Done_Parse): Renamed to... - (T1_Finalize_Parser): New function (to avoid name clash with a - function in the PSAux module). - (T1_Decrypt): Removed since it is duplicated in the PSAux module. - (T1_Get_Private_Dict): Added `psaux' as new parameter; use decrypt - function from PSAux module. - - * src/type1/t1parse.h: Adapted. - -2000-11-22 Tom Kacvinsky - - * src/cff/t2objs.c (T2_Init_Face): For pure CFF fonts, set - `root->num_faces' to `cff->num_faces' and set `units_per_EM' - to 1000. - - * src/cff/t2parse.c (parse_t2_real): Fixed real number parsing - loop. - - * src/cff/t2load.c (T2_Get_String): Called T2_Get_Name with a - sid that was off by one. - -2000-11-16 David Turner - - * src/autohint/ahtypes.h (AH_Hinter): Added new fields to control - auto-hinting of synthetic Type 1 fonts. - - * src/autohint/ahhint.c (ah_hinter_load, ah_hinter_load_glyph): - Added auto-hinting support of synthetic Type 1 fonts. - -2000-11-12 Tom Kacvinsky - - * src/sfnt/ttload.c (TT_LookUp_Table, TT_Load_Generic_Table): Change - tracing output. - - * src/sfnt/sfobjs.c (SFNT_Load_Face): Set boolean variable - `has-outline' to true only if the font has a `glyf' or `CFF ' table. - -2000-11-11 Werner Lemberg - - * builds/win32/visualc/freetype.dsp: Fix raster1->raster and - type1z->type1. - -2000-11-11 Tom Kacvinsky - - * builds/unix/freetype-config.in, builds/cygwin/freetype-config.in: - Added a --libtool option. When freetype-config --libtool is - invoked, the absolute path to the libtool convenience library - is returned. - -2000-11-11 Werner Lemberg - - * builds/cygwin/cygwin-def.in: Same fix as previous. - -2000-11-10 Tom Kacvinsky - - * builds/unix/unix-def.in: Add - - INSTALL_PROGRAM := @INSTALL_PROGRAM@ - INSTALL_SCRIPT := @INSTALL_SCRIPT@ - - so that installation of freetype-config does not fail. - -2000-11-10 Werner Lemberg - - * builds/cygwin/freetype-config.in, builds/unix/freetype-config.in: - Move test down for empty --exec-prefix. - Fix --version. - - * builds/cygwin/install.mk, builds/unix/install.mk: Use - $(INSTALL_SCRIPT) for installation of freetype-config. - - * builds/cygwin/install.mk: Fix clean target names. - -2000-11-09 David Turner - - - * Version 2.0 released. - ======================= - ----------------------------------------------------------------------------- - -Copyright (C) 2000-2023 by -David Turner, Robert Wilhelm, and Werner Lemberg. - -This file is part of the FreeType project, and may only be used, modified, -and distributed under the terms of the FreeType project license, -LICENSE.TXT. By continuing to use, modify, or distribute this file you -indicate that you have read the license and understand and accept it -fully. - - -Local Variables: -version-control: never -coding: utf-8 -End: diff --git a/freetype/docs/oldlogs/ChangeLog.21 b/freetype/docs/oldlogs/ChangeLog.21 deleted file mode 100644 index b331257..0000000 --- a/freetype/docs/oldlogs/ChangeLog.21 +++ /dev/null @@ -1,9438 +0,0 @@ -2005-06-08 Werner Lemberg - - - * Version 2.1.10 released. - ========================== - - - * src/pcf/readme: Renamed to... - * src/pcf/README: This. - -2005-06-07 Detlef Würkner - - * builds/amiga/*: Added copyright notes, reworked some comments. - -2005-06-05 Werner Lemberg - - * Add copyright notices to all files which don't have one. - - * docs/license.txt: Renamed to... - * docs/LICENSE.TXT: This. - * docs/FTL.txt: Renamed to... - * docs/FTL.TXT: This. - * docs/GPL.txt: Renamed to... - * docs/GPL.TXT: This. - - * docs/PATENTS: Slightly reworded. Suggested by Sylvain Beucler - . - -2005-06-04 Werner Lemberg - - * include/freetype/ftimage.h (FT_Outline_MoveToFunc, - FT_Outline_LineToFunc, FT_Outline_ConicToFunc, - FT_Outline_CubicToFunc, FT_Raster_RenderFunc), - include/freetype/ftrender.h (FT_Glyph_TransformFunc, - FT_Renderer_RenderFunc, FT_Renderer_TransformFunc): Don't use - `const' to stay compatible with FreeType 2.1.9. - -2005-06-01 Adam D. Moss - - * src/base/ftstroke.c (ft_stroker_inside): Revert `sigma' patch from - 2004-07-11; this gives much better results under normal - circumstances. - -2005-05-30 Chia I Wu - - * include/freetype/ftbitmap.h (FT_Bitmap_Embolden): Minor - documentation improvements. - - * include/freetype/ftoutln.h (FT_Outline_Embolden): Fix typos. - - * src/base/ftbitmap.c (FT_Bitmap_Embolden): Add support for bitmap - of pixel_mode FT_PIXEL_MODE_GRAY2 or FT_PIXEL_MODE_GRAY4. - If xstr is larger than 8 and bitmap is of pixel_mode - FT_PIXEL_MODE_MONO, set xstr to 8 instead of returning error. - -2005-05-29 Chia I Wu - - * src/base/ftbitmap.c (FT_Bitmap_Embolden): Fix emboldening bitmap - of mode FT_PIXEL_MODE_GRAY. Also add support for mode - FT_PIXEL_MODE_LCD and FT_PIXEL_MODE_LCD_V. - (ft_bitmap_assure_buffer): FT_PIXEL_MODE_LCD and FT_PIXEL_MODE_LCD_V - should have ppb (pixel per byte) 1. - Zero the padding when there's no need to allocate memory. - - * src/base/ftsynth.c (FT_GlyphSlot_Embolden): Handle slot->advance - too. - More suited emboldening strength. - -2005-05-28 Chia I Wu - - * src/base/ftbitmap.c (FT_Bitmap_Embolden): Handle negative pitch. - Handle FT_PIXEL_MODE_GRAY with num_gray != 256. - Improve speed for FT_PIXEL_MODE_GRAY. - (ft_bitmap_assure_buffer): Accept FT_PIXEL_MODE_LCD and - FT_PIXEL_MODE_LCD_V. - -2005-05-27 Chia I Wu - - * src/base/ftsynth.c (FT_GlyphSlot_Embolden): Initialize `error'. - - * src/base/ftobjs.c (ft_cmap_done_internal): New function. - (FT_CMap_Done): Remove cmap from cmap list. - (destroy_charmaps, FT_CMap_New): Don't call FT_CMap_Done but - ft_cmap_done_internal. - -2005-05-26 Werner Lemberg - - * docs/GPL.txt: Update postal address of FSF. - -2005-05-26 Chia I Wu - - * include/freetype/ftbitmap.h (FT_Bitmap_Embolden): Improve - documentation. - - * src/base/ftsynth.c (FT_BOLD_THRESHOLD): Removed. - (FT_GlyphSlot_Embolden): Check whether slot is bitmap owner. - Always modify the metrics. - -2005-05-24 Werner Lemberg - - * docs/CHANGES: Updated. - -2005-05-24 Chia I Wu - - * include/freetype/ftbitmap.h (FT_Bitmap_Embolden): New declaration. - - * include/freetype/ftoutln.h (FT_Outline_Embolden): New declaration. - - * src/base/ftbitmap.c (ft_bitmap_assure_buffer): New auxiliary - function. - (FT_Bitmap_Embolden): New function. - - * src/base/ftoutln.c (FT_Outline_Embolden): New function. - - * src/base/ftsynth.c: Don't include FT_INTERNAL_CALC_H and - FT_TRIGONOMETRY_H but FT_BITMAP_H. - (FT_GlyphSlot_Embolden): Use FT_Outline_Embolden or - FT_Bitmap_Embolden. - -2005-05-24 Werner Lemberg - - * configure: Always remove config.mk, builds/unix/unix-def.mk, and - builds/unix/unix-cc.mk. This fixes repeated calls of the script. - Reported by Nelson Beebe and Behdad Esfahbod. - - * README.CVS: Mention file permissions. - -2005-05-23 Werner Lemberg - - * builds/amiga/makefile.os4 (WARNINGS), builds/compiler/gcc-dev.mk - (CFLAGS), builds/compiler/gcc.mk (CFLAGS): Remove - -fno-strict-aliasing. - - * src/sfnt/rules.mk (SFNT_DRV_SRC): Don't include ttsbit0.c -- - it is currently loaded from ttsbit.c. - -2005-05-23 Behdad Esfahbod - - Say you have `(Foo*)x' and want to assign, pass, or return it as - `(Bar*)'. If you simply say `x' or `(Bar*)x', then the C compiler - would warn you that type casting incompatible pointer types breaks - strict-aliasing. The solution is to cast to `(void*)' instead which - is the generic pointer type, so the compiler knows that it should - make no strict-aliasing assumption on `x'. But the problem with - `(void*)x' is that seems like in C++, unlike C, `void*' is not a - generic pointer type and assigning `void*' to `Bar*' without a cast - causes an error. The solution is to cast to `Bar*' too, with - `(Bar*)(void*)x' as the result -- this is what the patch does. - - * include/freetype/cache/ftccache.h (FTC_CACHE_LOOKUP_CMP), - include/freetype/cache/ftcmru.h (FTC_MRULIST_LOOKUP_CMP): Remove - cast on lvalue, use a temporary pointer instead. - Cast temporarily to (void*) to not break strict aliasing. - - * include/freetype/internal/ftmemory.h (FT_MEM_ALLOC, - FT_MEM_REALLOC, FT_MEM_QALLOC, FT_MEM_QREALLOC, FT_MEM_FREE), - src/base/ftglyph.c (FT_Glyph_To_Bitmap): Cast temporarily to (void*) - to not break strict aliasing. - - * src/base/ftinit.c (FT_USE_MODULE): Fix wrong type information. - - * builds/unix/configure.ac (XX_CFLAGS): Remove -fno-strict-aliasing. - -2005-05-23 David Turner - - Fix Savannah bug #12213 (incorrect behaviour of the cache sub-system - in low-memory conditions). - - * include/freetype/cache/ftccache.h (FTC_CACHE_TRYLOOP, - FTC_CACHE_TRYLOOP_END): New macros. - - * src/cache/ftccache.c (FTC_Cache_NewNode), src/cache/ftcsbits.c - (ftc_snode_compare): Use FT_CACHE_TRYLOOP and FTC_CACHE_TRYLOOP_END. - -2005-05-23 Werner Lemberg - - * src/base/rules.mk (BASE_SRC): Don't add ftsynth.c here but... - (BASE_EXT_SRC): Here. - -2005-05-22 Werner Lemberg - - * src/base/ftrfork.c (raccess_guess_apple_generic): Mark - `version_number' and `entry_length' as unused. - (raccess_guess_linux_double_from_file_name): Remove `memory'. - (raccess_make_file_name): Mark `error' as unused. - - * src/bdf/bdflib.c (_bdf_parse_properties): Remove `memory'. - - * src/cid/cidobjs.c (cid_face_init): Remove `psnames'. - - * src/sfnt/sfobjs.c (sfnt_load_face): Remove `memory'. - - * src/truetype/ttgxvar.c (ft_var_readpackedpoints, - ft_var_readpackeddeltas, ft_var_load_avar): Mark `error' as unused. - - * src/base/rules.mk (BASE_SRC): Add ftsynth.c. - -2005-05-21 David Turner - - * src/base/ftsynth.c (FT_GlyphSlot_Embolden): Fix a bug that - produced unpleasant artefacts when trying to embolden very sharp - corners. - -2005-05-20 Werner Lemberg - - * docs/CHANGES: Updated. - -2005-05-20 Chia I Wu - - * src/base/ftbitmap.c: Don't include FT_FREETYPE_H and FT_IMAGE_H - but FT_BITMAP_H. - (FT_Bitmap_Copy): New function (from ftglyph.c). - - * include/freetype/ftbitmap.h (FT_Bitmap_Copy): New public - definition. - - * src/base/ftglyph.c: Include FT_BITMAP_H. - (ft_bitmap_copy): Move to ftbitmap.c. - (ft_bitmap_glyph_init): Remove `memory' variable. - Create new bitmap object if FT_GLYPH_OWN_BITMAP isn't set. - (ft_bitmap_glyph_copy): Use FT_Bitmap_Copy. - (ft_bitmap_glyph_done): Use FT_Bitmap_Done. - (ft_outline_glyph_init): Use FT_Outline_Copy. - - * src/base/ftoutln.c (FT_Outline_Copy): Handle source == target. - (FT_Outline_Done_Internal): Check for valid `memory' pointer. - (FT_Outline_Translate, FT_Outline_Reverse, FT_Outline_Render, - FT_Outline_Transform): Check for valid `outline' pointer. - - * src/base/ftobjs.c (FT_New_GlyphSlot): Prepend glyph slot to - face->glyph, otherwise a new second glyph slot cannot be created. - (FT_Done_GlyphSlot): Fix memory leak. - (FT_Open_Face): Updated -- face->glyph is already managed by - FT_New_GlyphSlot. - - * src/type42/t42objs.c (T42_GlyphSlot_Done): Updated. - -2005-05-20 Kirill Smelkov - - * include/freetype/ftimage.h (FT_Raster_Params), - include/freetype/ftoutln.h (FT_Outline_Translate, - FT_Outline_Transform), src/base/ftoutln.c (FT_Outline_Translate, - FT_Outline_Transform): Decorate parameters with `const' where - appropriate. - Update all callers. - - * src/raster/ftraster.c (ft_black_reset), src/smooth/ftgrays.c - (gray_raster_reset): Remove `const' from `pool_base' argument. - -2005-05-18 Kirill Smelkov - - * src/raster/ftmisc.h: New file. Only needed if ftraster.c is - compiled as stand-alone. - - * src/raster/ftraster.c: Add comment how to compile as stand-alone. - s/FT_CONFIG_OPTION_STATIC_RASTER/FT_STATIC_RASTER/. - s/TT_STATIC_RASTER/FT_STATIC_RASTER/. - [_STANDALONE_]: Include ftimage.h and ftmisc.h. - (FT_TRACE1, FT_TRACE6, ft_memset, FT_MEM_ZERO): Define - conditionally. - (Render_Glyph, Render_Gray_Glyph): Return Raster_Err_None (or - Raster_Err_Unsupported). - (ft_black_new) [_STANDALONE_]: Fix type of `the_raster'. - (ft_black_init, ft_black_reset, ft_black_set_mode, ft_black_render): - Use `ras', not `raster'. - (ft_black_done): Use FT_UNUSED_RASTER. - (Horizontal_Sweep_Init, Horizontal_Sweep_Step, - Horizontal_Gray_Sweep_Span): Use FT_UNUSED_RASTER. - -2005-05-18 Werner Lemberg - - * docs/announce: Start updating. - - * docs/CHANGES: Updated. - -2005-05-16 Vitaliy Pasternak - - * builds/win32/visualc/freetype.vcproj: Updated. - Exclude debug info for `Release' versions to reduce library size. - -2005-05-16 Werner Lemberg - - * src/base/ftobjs.c (FT_Open_Face): Make it work as documented, this - is, ignore `aface' completely if face_index < 0. Reported by David - Osborn . - -2005-05-16 Kirill Smelkov - - * include/freetype/ftimage.h (FT_Outline_MoveToFunc, - FT_Outline_LineTo_Func, FT_Outline_ConicToFunc, - FT_Outline_CubicToFunc), src/smooth/ftgrays.c (gray_render_conic, - gray_render_cubic, gray_move_to, gray_line_to, gray_conic_to, - gray_cubic_to, gray_render_span, gray_sweep): Decorate parameters - with `const' where appropriate. - -2005-05-11 Kirill Smelkov - - * include/freetype/ftimage.h (FT_Raster_RenderFunc), - include/freetype/ftrender.h (FT_Glyph_TransformFunc, - FT_Renderer_Render_Func, FT_Renderer_TransformFunc), - src/base/ftglyph.c (ft_outline_glyph_transform), - src/raster/ftrend1.c (ft_raster1_transform, ft_raster1_render), - src/smooth/ftgrays.c (FT_Outline_Decompose, gray_raster_render), - src/smooth/ftsmooth.c (ft_smooth_transform, - ft_smooth_render_generic, ft_smooth_render, ft_smooth_render_lcd, - ft_smooth_render_lcd_v): Decorate parameters with `const' where - appropriate. - - * src/raster/ftraster.c (RASTER_RENDER_POOL): Removed. Obsolete. - (ft_black_render): Decorate parameters with `const' where - appropriate. - -2005-05-11 Werner Lemberg - - * src/sfnt/ttcmap.c (tt_cmap4_set_range): Fix typo (FT_PEEK_SHORT -> - FT_PEEK_USHORT) which caused crashes. Reported by Ismail Donmez - . - -2005-05-08 Werner Lemberg - - * include/freetype/internal/ftserv.h (FT_FACE_FIND_GLOBAL_SERVICE) - [__cplusplus]: Fix typo. - -2005-05-07 Werner Lemberg - - Handle unsorted SFNT type 4 cmaps correctly (reported by Dirck - Blaskey ). - - * src/sfnt/ttcmap.h (TT_CMap): Add member `unsorted'. - * src/sfnt/ttcmap.c: Use SFNT_Err_Ok where appropriate. - - (tt_cmap0_validate, tt_cmap2_validate, tt_cmap6_validate, - tt_cmap8_validate, tt_cmap10_validate, tt_cmap12_validate): Use - `FT_Error' as return type. - (tt_cmap4_validate): Use `FT_Error' as return type. - Return error code for unsorted cmap. - (tt_cmap4_char_index, tt_cmap4_char_next): Use old code for unsorted - cmaps. - (tt_face_build_cmaps): Set `unsorted' variable in cmap. - -2005-05-07 Werner Lemberg - - * src/truetype/ttpload.c (tt_face_get_location): Fix typo. - -2005-05-06 Werner Lemberg - - * src/cff/cffobjs.c (cff_face_init): Set ppem value in top - dictionary for SFNT-based CFF. - -2005-05-05 Werner Lemberg - - Handle malformed `loca' table entries. - - * docs/TODO: Add some bugs which should be fixed. - - * include/freetype/internal/tttypes.h (TT_FaceRec): Add `glyf_len' - element. - - * src/truetype/ttpload.c (tt_face_load_loca): Get length of `glyf' - table. - (tt_face_get_location): Fix computation of `asize' for malformed - `loca' entries. - -2005-05-01 David Turner - - * Jamfile: Remove `otvalid' from the list of compiled modules. - - * include/freetype/internal/ftserv.h: Add compiler pragmas to get - rid of annoying warnings with Visual C++ compiler in maximum warning - mode. - - * src/autofit/afhints.c, src/autofit/aflatin.c, src/base/ftstroke.c, - src/bdf/bdfdrivr.c, src/cache/ftcbasic.c, src/cache/ftccmap.c, - src/cache/ftcmanag.c, src/cff/cffload.c, src/cid/cidload.c, - src/lzw/zopen.c, src/otvalid/otvgdef.c, src/pcf/pcfread.c, - src/sfnt/sfobjs.c, src/truetype/ttgxvar.c: Remove compiler warnings. - -2005-04-28 Werner Lemberg - - * docs/TODO: Updated. - -2005-04-24 Werner Lemberg - - * src/otvalid/otvcommn.c - (otv_GSUBGPOS_have_MarkAttachmentType_flag): Handle table == 0. - -2005-04-16 Werner Lemberg - - * src/cff/cffobjs.c (cff_face_init): Set default upem value in top - font dict also. - Handle font matrix settings in subfonts. - - * src/cff/cffgload.c (cff_slot_load): Use the correct font matrix - for CID-keyed fonts with subfonts. - - * docs/formats.txt: Updated. - -2005-04-14 Kirill Smelkov - - * include/freetype/freetype.h (FT_Vector_Transform), - include/freetype/ftimage.h (FT_Raster_Params), - include/freetype/ftoutln.h, src/base/ftoutln.c (FT_Outline_Get_CBox, - FT_Outline_Copy, FT_Outline_Transform, FT_Vector_Transform, - FT_Outline_Get_Bitmap), src/raster/ftraster.c (ft_black_render), - src/smooth/ftgrays.c (gray_raster_render): Decorate parameters with - `const' where appropriate. - -2005-04-14 Werner Lemberg - - * src/type1/t1load.c (parse_charstrings): Catch this non-standard - beginning of the /CharStrings dictionary: - - /CharStrings 118 dict def - Private begin - CharStrings begin - - * src/sfnt/ttsbit0.c (tt_sbit_decoder_load_image): Fix arguments - to call of tt_sbit_decoder_load_bitmap. - -2005-04-13 Werner Lemberg - - * docs/TODO: Updated. - - * autogen.sh: Use `--force' for all commands. - -2005-04-09 Werner Lemberg - - * src/pshinter/pshalgo.c (ps_hints_apply): Change scaling values - only if `fitted' is not zero. - -2005-04-06 Werner Lemberg - - * src/truetype/ttgload.c (tt_face_get_metrics) [FT_OPTIMIZE_MEMORY]: - Fix typo which sometimes causes wrong metrics for the last glyph. - -2005-04-04 David Turner - - * devel/ftoption.h, include/freetype/config/ftoption.h - (FT_OPTIMIZE_MEMORY): Comment out this macro for the upcoming 2.1.10 - release. - (*_CHESTER_*): Removed. No longer used. - - * src/autofit/afhints.c (af_axis_hints_new_segment, - af_axis_hints_new_edge): Small tweak to use less heap memory. - -2005-04-03 Werner Lemberg - - * src/type1/t1parse.c (T1_New_Parser): Relax the check for a valid - first line in the font. - -2005-04-03 Werner Lemberg - - * docs/CHANGES, include/freetype/freetype.h: Improve documentation - of FT_Set_Pixel_Sizes and FT_Set_Char_Size. - -2005-03-26 Detlef Würkner - - * builds/amiga/src/base/ftsystem.c (ft_amiga_stream_io): Fix buffer - offsets after a large read. - -2005-03-26 Werner Lemberg - - * src/autofit/afglobal.c (af_face_globals_get_metrics): - s/index/gidx/. - - * src/sfnt/ttsbit0.c (tt_sbit_decoder_load_image): Fix compiler - warnings. - - * src/sfnt/rules.mk (SFNT_DRV_SRC): Add ttsbit0.c. - - * src/sfnt/ttsbit0.h: Dummy file for build with `make'. - -2005-03-26 Detlef Würkner - - Update of the Amiga port. - - * builds/amiga/makefile, builds/amiga/makefile.os4, - builds/amiga/smakefile: Included the base extension files - (ftbitmap.c, ftotval.c, ftpfr.c, ftstroke.c, ftxf86.c). - -2005-03-25 Detlef Würkner - - Update of the Amiga port. - - * builds/amiga/makefile, builds/amiga/smakefile: Handle new modules. - - * builds/amiga/makefile.os4: Makefile for AmigaOS4 SDK. - - * builds/amiga/README: Updated. - - * builds/amiga/include/freetype/config/ftconfig.h: Handle gcc for - AmigaOS4. - - * builds/amiga/include/freetype/config/ftmodule.h: Handle new - modules. - - * builds/amiga/src/base/ftdebug.c: Updated to current version of - default ftdebug.c. - Add various include files and macros to have proper support for - both AmigaOS4 and older AmigaOS versions. - Don't declare KVPrintF explicitly. - Replace getenv with GetVar. - Actually enable debugging code. - - * builds/amiga/src/base/ftsystem.c: Major rewrite. - -2005-03-23 Werner Lemberg - - * tests/*: Removed. - -2005-03-23 Werner Lemberg - - * docs/CHANGES, docs/INSTALL.ANY: Updated. - - * include/freetype/ftmoderr.h: Replace `Autohint' with `Autofit'. - Add `OTvalid'. - - * src/autofit/aferrors.h: New file. - - * src/autofit/afglobal.c, src/autofit/afhints.c, - src/autofit/aflatin.c, src/autofit/afloader.c: s/FT_Err_/AF_Err_/. - Include aferrors.h. - - * src/autofit/rules.mk (AUTOF_DRV_H): Include aferrors.h. - - * src/otvalid/otverror.h: s/FT_Mod_Err_OTV/FT_Mod_Err_OTvalid/. - -2005-03-22 David Turner - - * src/autohint/*: Removed. - * Jamfile: Updated. - -2005-03-15 David Turner - - * src/bdf/bdflib.c: Remove compiler warnings. - (hash_rehash, hash_init): Don't call FT_MEM_ZERO. - (_bdf_list_t): Add `memory' field. - (_bdf_list_init, _bdf_list_done, _bdf_list_ensure): New functions. - (_bdf_shift, _bdf_join): Rename to... - (_bdf_list_shift, _bdf_list_join): This. - (_bdf_split): Renamed to... - (_bdf_list_split): This. Use new functions. - (bdf_internal_readstream): Removed. - (NO_SKIP): New macro. - (_bdf_readstream): Rewritten. - (bdf_create_property, _bdf_add_comment): Improve allocation. - (_bdf_set_default_spacing, _bdf_parse_glyphs): Updated. Improve - allocation. - (_bdf_parse_properties, _bdf_parse_start): Updated. - (bdf_load_font): Updated to use new functions. - - * src/type1/t1parse.c (check_type1_format): New function. - (T1_New_Parser): Use it to check font header before allocating - anything on the heap. - - * src/type42/t42parse.c (t42_parser_init): Modify functions to check - the font header before allocating anything on the heap. - - * include/freetype/internal/ftmemory.h (FT_ARRAY_MAX, - FT_ARRAY_CHECK): New macros. - - * src/base/ftstream.c (FT_Stream_TryRead): New function. - * include/freetype/internal/ftstream.h: Updated. - - * src/pcf/pcfread.c (pcf_read_TOC), src/pcf/pcfutil.c - (BitOrderInvert, TwoByteSwap, FourByteSwap): Minor fixes and - simplifications. Try to protect the PCF driver from doing stupid - things with broken fonts. - - * src/lzw/ftlzw.c (FT_Stream_OpenLZW): Check the LZW header before - doing anything else. This avoids unnecessary heap allocations - (400KByte of heap memory for the LZW decoder). - - * src/gzip/ftgzip.c (FT_Stream_OpenGzip): Ditto for the gzip - decoder, although the code savings are smaller. - - * docs/CHANGES: Updated. - -2005-03-10 David Turner - - * src/tools/glnames.py: Add comment to explain the compression - being used for the Adobe Glyph List. - -2005-03-10 Werner Lemberg - - * src/truetype/ttpload.c (tt_face_load_cvt, tt_face_load_fpgm): - Fix serious typo which prevented correct TT rendering. - - * include/freetype/internal/ftmemory.h: Undo change from 2005-03-03. - To suppress warnings it is sufficient to use `-fno-strict-aliasing'. - -2005-03-10 Werner Lemberg - - * src/tools/glnames.py: Formatted. - Format output to be in sync with other FreeType code. - Import `re' and `os.path'. - (StringTable) <__init__>: Add parameter to initialize master table - name. - (StringTable) : Don't pass master table name. - (StringTable) : Emit explanatory comment. - Simplify and make output more human readable. - (t1_bias, glyph_list, adobe_glyph_names): Removed. Unused. - (main): Use `basename' for file name in header. - - * src/psnames/pstables.h: Regenerated. - -2005-03-09 David Turner - - * src/tools/glnames.py: Rewrite the generator for the `pstables.h' - header file which contains various constant tables related to glyph - names. It now uses a different, more compact storage scheme that - saves about 20KB. This also closes Savannah bug #12262. - - * src/psnames/pstables.h: Regenerated. - - * src/psnames/psmodule.c (ps_unicode_value): Use - `ft_get_adobe_glyph_index', a new function defined in `pstables.h'. - (ps_get_macintosh_name, ps_get_standard_strings): Updated. - - * src/base/ftobjs.c (FT_Set_Char_Size): Handle fractional sizes - more carefully. This fixes Savannah bug #12263. - -2005-03-06 David Turner - - * src/otvalid/otvgsub.c, src/otvalid/otvgpos.c: Make static tables - constant. - - * src/autofit/aflatin.c (af_latin_metrics_init): Fix Savannah bug - #12212 (auto-hinter refuses to work if no Unicode charmap in font). - -2005-03-05 Werner Lemberg - - * autogen.sh: New script for bootstrapping. - - * README.CVS: New file which documents bootstrapping. - - * builds/unix/aclocal.m4, builds/unix/config.guess, - builds/unix/config.sub, builds/unix/configure, - builds/unix/ltmain.sh: Removed. - -2005-03-04 Werner Lemberg - - * src/base/ftutil.c: Include FT_INTERNAL_OBJECTS_H. - -2005-03-03 Werner Lemberg - - Various fixes for C and C++ compiling. - - * src/autofit/*: Add copyright messages. - - * src/autofit/afhints.c (af_glyph_hints_done): Don't use - `AF_Dimension' but `int' for loop counter. - - * src/autofit/aflatin.c (af_latin_metrics_init_widths): Don't use - `AF_Dimension' but `int' for loop counter. - Use proper enumeration value for `render_mode'. - (af_latin_metrics_scale_dim): Don't shadow variables. - (af_latin_hints_compute_segments): Use proper cast for `major_dir' - and `segment_dir'. - (af_latin_align_linked_edge, af_latin_hint_edges): Fix arguments of call to - `af_latin_compute_stem_width'. - (af_latin_hints_apply): Don't use `AF_Dimension' but `int' for loop - counter. - - * src/base/ftdbgmem.c (ft_mem_table_get_source, FT_DumpMemory): Use - proper cast for memory allocation. - - * src/cff/cffdrivr.c (cff_get_kerning): Use proper cast for - initialization of `sfnt'. - - * src/sfnt/sfdriver.c: Include `ttkern.h'. - - * src/sfnt/ttkern.c (tt_face_get_kerning): Don't shadow variables. - - * src/truetype/ttgload.c: Include `ttpload.h'. - -2005-03-03 David Turner - - * include/freetype/internal/ftmemory.h (FT_ALLOC, FT_REALLOC, - FT_QALLOC, FT_QREALLOC) [gcc >= 3.3]: Provide macro versions which - avoid compiler warnings. - (FT_NEW, FT_NEW_ARRAY, FT_RENEW_ARRAY, FT_QNEW, FT_QNEW_ARRAY, - FT_QRENEW_ARRAY, FT_ALLOC_ARRAY, FT_REALLOC_ARRAY): Updated. - - * include/freetype/internal/ftserv.h (FT_FACE_FIND_SERVICE, - FT_FACE_FIND_GLOBAL_SERVICE, FT_FACE_LOOKUP_SERVICE) [__cplusplus]: - Provide macro versions which avoid compiler warnings. - - * src/base/ftutil.c (ft_highpow2): New utility function. - - * include/freetype/internal/ftobjs.h: Updated. - - * src/pfr/pfrload.c (pfr_get_gindex, pfr_compare_kern_pairs, - pfr_sort_kerning_pairs): Don't define if FT_OPTIMIZE_MEMORY is set. - (pfr_phy_font_done): Don't handle `kern_pairs' if FT_OPTIMIZE_MEMORY - is set. - (pfr_phy_font_load): Don't call `pfr_sort_kerning_pairs' if - FT_OPTIMIZE_MEMORY is set. - - * src/pfr/pfrobjs.c (pfr_slot_load): Comment out some code which - doesn't work with broken fonts. - (pfr_face_get_kerning) [FT_OPTIMIZE_MEMORY]: Implement. - - * src/pfr/pfrtypes.h (PFR_KernItemRec): Optimize member types. - (PFR_NEXT_KPAIR): New macro. - (PFR_PhyFontRec): Don't define `kern_pairs' if FT_OPTIMIZE_MEMORY is - set. - - * src/sfnt/ttsbit0.c (tt_sbit_decoder_load_image): Introduce - temporary variable to avoid gcc warning. - (tt_face_load_sbit_image): Mark unused variables with FT_UNUSED. - - * src/truetype/ttpload.c (tt_face_load_loca) [FT_OPTIMIZE_MEMORY]: - Remove redundant variable. - - * include/freetype/config/ftmodule.h: Moving the order of drivers to - speed up font loading. The PCF and BDF loaders are still slow and - consume far too much memory. - -2005-03-03 Werner Lemberg - - * devel/ftoption.h: Updated to recent changes. - -2005-03-02 Werner Lemberg - - * src/autofit/afdummy.c, src/autofit/afdummy.h - (af_dummy_script_class): Fix type. - - * src/autofit/aflatin.c, src/autofit/aflatin.h - (af_latin_script_class): Fix type. - - * src/autofit/rules.mk (AUTOF_DRV_SRC): Fix typo. - -2005-03-01 David Turner - - * src/sfnt/ttkern.c (tt_face_load_kern, tt_face_get_kerning), - src/sfnt/ttsbit0.c (tt_face_load_sbit_strikes, - tt_sbit_decoder_load_byte_aligned, tt_sbit_decoder_load_compound, - tt_sbit_decoder_load_image), src/sfnt/ttload.c - (tt_face_load_metrics): Remove compiler warnings - -- redundant variables, missing initializations, etc. - - * src/sfnt/ttsbit.h: Handle FT_OPTIMIZE_MEMORY. - - * src/autofit/rules.mk, src/autofit/module.mk, - src/autofit/afangles.h: New files. - - * src/autofit/afhints.c (af_axis_hints_new_segment, - af_axis_hints_new_edge): New functions. - (af_glyph_hints_done): Do proper deallocation. - (af_glyph_hints_reload): Only reallocate points array. This - drastically reduces heap usage. - - * src/autofit/afhints.h (AF_PointRec, AF_SegmentRec): Optimize - member types and positions. - (AF_AxisHintsRec): Add `max_segments' and `max_edges'. - (af_axis_hints_new_segment, af_axis_hints_new_edge): New prototypes. - - * src/autofit/aflatin.c (af_latin_metrics_scale): Don't call - AF_SCALER_EQUAL_SCALES. - (af_latin_hints_compute_segments): Change return type to FT_Error. - Update all callers. - Improve segment allocation. - (af_latin_hints_compute_edges): Change return type to FT_Error. - Update all callers. - Improve edge allocation and link handling. - (af_latin_hints_detect_features): Change return type to FT_Error. - Update all callers. - - * src/autofit/aflatin.h: Updated. - - * src/autofit/afloader.c (af_loader_load_g) - : Assure axis->num_edges > 1. This fixes - a bug with certain fonts. - - * include/freetype/config/ftmodule.h: The auto-fitter is now the - only supported auto-hinting module. - - * include/freetype/config/ftstdlib.h (FT_INT_MAX): New macro. - -2005-02-28 Werner Lemberg - - * src/truetype/ttpload.c (tt_face_load_loca): Fix typo. - - * src/sfnt/ttkern.c: Include `ttkern.h'. - (FT_COMPONENT): Updated. - - * include/freetype/internal/fttrace.h: Add entry for `ttkern'. - - * src/sfnt/ttsbit0.c: s/FT_Err_/SFNT_Err_/. - Decorate constants with `U' and `L' where necessary. - - * src/sfnt/ttcmap.c (tt_cmap4_next): Remove unused variable. - -2005-02-28 David Turner - - * src/base/ftdbgmem.c (FT_DumpMemory): Added sorting of memory - sources according to decreasing maximum cumulative allocations. - (ft_mem_source_compare): New auxiliary function. - - * src/sfnt/ttsbit0.c: New file, implementing a heap-optimized - embedded bitmap loader. - - * src/sfnt/ttsbit.c: Include `ft2build.h', FT_INTERNAL_DEBUG_H, - FT_INTERNAL_STREAM_H, FT_TRUETYPE_TAGS_H. - Load `ttsbit0.c' if FT_OPTIMIZE_MEMORY is set, otherwise use - file contents. - (tt_face_load_sbit_strikes): Set up root fields to indicate the - strikes. This fixes Savannah bug #12107. - Use `static' keyword for `sbit_line_metrics_field', - `strike_start_fields', `strike_end_fields'. - - * include/freetype/internal/tttypes.h (TT_FaceRec): Define - `sbit_table', `sbit_table_size', `sbit_num_strikes' if - FT_OPTIMIZE_MEMORY is set. - Don't define `num_sbit_strikes' and `sbit_strikes' if - FT_OPTIMIZE_MEMORY is set. - - * src/cff/cffobjs.c (sbit_size_reset): Handle FT_OPTIMIZE_MEMORY. - - * src/sfnt/sfobjs.c (sfnt_load_face): Fixed bug that prevented - loading SFNT fonts without a `kern' table. - Properly pass root->face_flags. - Remove code for TT_CONFIG_OPTION_EMBEDDED_BITMAPS. - - * src/sfnt/sfdriver.c (sfnt_interface) - [TT_CONFIG_OPTION_EMBEDDED_BITMAPS]: Don't use `tt_find_sbit_image' - and `tt_load_sbit_metrics'. - - * src/sfnt/ttcmap.c: Optimize linear charmap scanning for Format 4. - (OPT_CMAP4): New macro. - (TT_CMap4Rec) [OPT_CMAP4]: New structure. - (tt_cmap4_init, tt_cmap4_set_range, tt_cmap4_next, tt_cmap4_reset) - [OPT_CMAP4]: New functions. - (tt_cmap4_char_next) [OPT_CMAP4]: Use `tt_cmap4_next' and - `tt_cmap4_reset'. - (tt_cmap4_class_rec) [OPT_CMAP4]: Use `TT_CMap4Rec' and - `tt_cmap4_init'. - - * src/truetype/ttobjs.c (Reset_SBit_Size): Handle - FT_OPTIMIZE_MEMORY. - - * src/autofit/afhints.h (AF_PointRec, AF_SegmentRec, AF_EdgeRec): - Optimize member types. - - * src/autofit/afloader.c (af_loader_done): Call - `af_glyph_hints_done'. - -2005-02-27 David Turner - - * src/sfnt/ttkern.c (tt_face_load_kern): Fix a small bug which - caused invalid (random) return values for the horizontal kerning. - -2005-02-25 David Turner - - Implement several memory optimizations to drastically reduce the - heap usage of FreeType, especially in the case of memory-mapped - files. The idea is to avoid loading and decoding tables in the - heap, and instead access the raw data whenever possible (i.e., when - it doesn't compromise performance). - - This has several benefits: For example, opening vera.ttf now uses - just a small amount of memory (even when the FT_Library footprint is - accounted for), until you start loading glyphs. Even then, you save - at least 20KB compared to the non-optimized case. Performance of - various operations, including open and close, has also been - dramatically improved. - - More optimizations to come, especially for the auto-hinter. - - * include/freetype/internal/sfnt.h (TT_Face_GetKerningFunc): New - function type. - (SFNT_Interface): Add it. - - * include/freetype/internal/tttypes.h (TT_HdmxEntryRec, TT_HdmxRec, - TT_Kern0_PairRec): Don't define if FT_OPTIMIZE_MEMORY is set. - (TT_FaceRec): Define `horz_metrics', `horz_metrics_size', - `vert_metrics', `vert_metrics_size', `hdmx_table', - `hdmx_table_size', `hdmx_record_count', `hdmx_record_size', - `hdmx_record_sizes', `kern_table', `kern_table_size, - `num_kern_tables', `kern_avail_bits', `kern_order_bits' if - FT_OPTIMIZE_MEMORY is set. - Don't define `hdmx', `num_kern_pairs', `kern_table_index', - `kern_pairs' if FT_OPTIMIZE_MEMORY is set. - - * src/base/ftdbgmem.c (ft_mem_table_set): Don't shadow variable. - Fix compiler warning. - - * src/cff/cffdrivr.c (Get_Kerning): Renamed to... - (cff_get_kerning): This. Simplify. - (cff_driver_class): Updated. - - * src/sfnt/Jamfile (_sources): Add `ttkern'. - * src/sfnt/rules.mk (SFNT_DRV_SRC): Add `ttkern.c'. - - * src/sfnt/sfdriver.c (sfnt_interface): Add `tt_face_get_kerning'. - - * src/sfnt/sfnt.c: Include `ttkern.c'. - - * src/sfnt/sfobjs.c: Include `ttkern.h'. - (sfnt_load_face): Consider the `kern' and `gasp' table as optional. - (sfnt_done_face): Call `tt_face_done_kern'. - Handle horizontal metrics for FT_OPTIMIZE_MEMORY. - - * src/sfnt/ttkern.c, src/sfnt/ttkern.h: New files. Code has been - taken from `ttload.c' and `ttload.h'. - Provide special versions of `tt_face_load_kern', - `tt_face_get_kerning', and `tt_face_done_kern' for - FT_OPTIMIZE_MEMORY. - - * src/sfnt/ttload.c (tt_face_load_metrics, tt_face_load_hdmx, - tt_face_free_hdmx): Provide version for FT_OPTIMIZE_MEMORY. - (tt_face_load_kern, tt_kern_pair_compare, TT_KERN_INDEX): Moved to - `ttkern.c'. - - * src/sfnt/ttload.h: Updated. - - * src/sfnt/ttsbit.c (sbit_metrics_field): Add `static' keyword. - - * src/truetype/ttdriver.c (Get_Kerning): Renamed to... - (tt_get_kerning): This. Simplify. - (tt_driver_class): Updated. - - * src/truetype/ttgload.c (TT_Get_Metrics): Renamed to... - (tt_face_get_metrics): This. Provide version for FT_OPTIMIZE_MEMORY. - Update all callers. - (Get_Advance_Widths): Replaced with... - (Get_Advance_WidthPtr): This. Provide version for - FT_OPTIMIZE_MEMORY. - Update all callers. - - * src/truetype/ttgload.h: Updated. - -2005-02-22 David Turner - - * src/base/ftdbgmem.c: Partly rewritten. Added the ability to list - all allocation sites in the memory debugger. Also a new function - FT_DumpMemory() was added. It is only available in builds with - FT_DEBUG_MEMORY defined, and you must declare it in your own code to - use it, i.e., with something like: - - extern void FT_DumpMemory( FT_Memory ); - - ... - - FT_DumpMemory( memory ); - - * include/freetype/config/ftoption.h - (TT_CONFIG_OPTION_BYTECODE_INTERPRETER): Comment out definition -- - again. - (FT_OPTIMIZE_MEMORY): New configuration macro to control various - optimizations for reducing the heap footprint of memory-mapped - TrueType files. - - * include/freetype/internal/ftmemory.h (FT_ARRAY_ZERO): New - convenience macro. - - * include/freetype/internal/tttypes.h (TT_FaceRec) - [FT_OPTIMIZE_MEMORY]: Use optimized types for `num_locations' and - `glyph_locations'. - - * src/truetype/ttgload.c (load_truetype_glyph): Call - `tt_face_get_location'. - - * src/truetype/ttobjs.c (tt_face_init) - [FT_CONFIG_OPTION_INCREMENTAL]: Improve error handling. - (tt_face_done): Call `tt_face_done_loca'. - - * src/truetype/ttpload.c (tt_face_get_location, tt_face_done_loca): - New functions. If FT_OPTIMIZE_MEMORY is set, the locations table is - read directly from memory-mapped streams, instead of being decoded - into the heap. - (tt_face_load_loca) [FT_OPTIMIZE_MEMORY]: New implementation. - (tt_face_load_cvt, tt_face_load_fpgm): Only load table if the - bytecode interpreter is compiled in. - - * src/truetype/ttpload.h: Updated. - - * src/autohint/ahglyph.c (ah_outline_load): Improve allocation - logic. - -2005-02-20 Werner Lemberg - - * builds/unix/ltmain.sh: Regenerated with `libtoolize --force - --copy' from libtool 1.5.14. - * builds/unix/aclocal.m4: Regenerated with `aclocal -I .' from - automake 1.9.4. - - * builds/unix/config.guess, builds/unix/config.sub: Updated from - `config' CVS module at subversions.gnu.org. - - * builds/unix/install-sh, builds/unix/mkinstalldirs: Updated from - `texinfo' CVS module at subversions.gnu.org. - -2005-02-14 Werner Lemberg - - * src/cff/cffcmap.c (cff_cmap_unicode_init): Don't try to build - a cmap for a CID-keyed font which doesn't have SIDs. - -2005-02-13 Werner Lemberg - - * src/type1/t1load.c (read_binary_data): Return more meaningful - value. - (parse_encoding, parse_subrs, parse_charstrings, parse_dict): Check - parser error value after call to T1_Skip_PS_Token (where necessary). - - * src/type1/t1parse.c (T1_Get_Private_Dict): Check parser error - value after call to T1_Skip_PS_Token. - - * src/cid/cidparse.c (cid_parser_new): Check parser error value - after call to cid_parser_skip_PS_token. - - * src/type42/t42parse.c (t42_parse_encoding, t42_parse_sfnts, - t42_parse_charstrings, t42_parse_dict): Check parser error value - after call to T1_Skip_PS_Token (where necessary). - - * src/psaux/psobjs.c (skip_string, ps_parser_skip_PS_token, - ps_tobytes): Add error messages. - -2005-02-12 Werner Lemberg - - * configure: Output more variables to the created Makefile so that - it can be used for ft2demos also (if the FT2DEMOS variable is - defined). - -2005-02-10 David Turner - - * src/pfr/pfrgload.c (pfr_glyph_load): Fix an unbounded growing - dynamic array when loading a glyph from a PFR font (Savannah bug - #11921). - - * src/base/ftbitmap.c (FT_Bitmap_Convert): Small improvements to the - conversion function (mainly stupid optimization). - - * src/base/Jamfile: Adding ftbitmap.c to the list of compiled files. - -2005-02-10 Werner Lemberg - - * builds/unix/freetype-config.in: Add new flag `--ftversion' to - return the FreeType version. Suggested by George Williams - . - - * docs/CHANGES: Updated. - -2005-02-09 Werner Lemberg - - * src/otvalid/otvmod.c (otv_validate): Deallocate arrays in case - of error. Reported by YAMANO-UCHI Hidetoshi . - -2005-02-08 Werner Lemberg - - * src/psaux/t1decode.c (t1_decoder_parse_charstrings) - : Accept `T1_Parse_Have_Moveto' state also which can - happen in empty glyphs. Reported by Ian Brown - (Savannah bug #11856). - -2005-02-04 Werner Lemberg - - * src/otlayout/*: Removed. Obsolete. - -2004-12-28 Werner Lemberg - - * builds/unix/ltmain.sh: Regenerated with `libtoolize --force - --copy' from libtool 1.5.10. - * builds/unix/aclocal.m4: Regenerated with `aclocal -I .' from - automake 1.9.4. - * builds/unix/configure: Regenerated with autoconf 2.59b. - - * builds/unix/config.guess, builds/unix/config.sub: Updated from - `config' CVS module at subversions.gnu.org. - - * builds/unix/install-sh: Updated from - `texinfo' CVS module at subversions.gnu.org. - - * builds/unix/ftsystem.c (FT_Stream_Open): Add proper cast for - ft_alloc. - Fix compiler warning. - -2004-12-27 Dirck Blaskey - - * src/cff/cffobjs.c (cff_face_init): Improve computation of - FT_STYLE_BOLD_FLAG. - -2004-12-27 Werner Lemberg - - * src/cff/cffobjs.c (cff_face_init): A CFF within an SFNT can have - only a single font. This is undocumented but has been verified on - the opentype list. - -2004-12-26 Werner Lemberg - - * Jamfile (FT2_COMPONENTS): Add `otvalid'. - -2004-12-25 Werner Lemberg - - * src/base/ftbitmap.c (FT_Bitmap_Convert): Fix compiler warning. - -2004-12-15 Werner Lemberg - - * vms_make.com: Add ftbitmap.obj. - -2004-12-14 Werner Lemberg - - * src/base/ftbitmap.c, include/freetype/ftbitmap.h: New files for - handling various bitmap formats. - - * include/freetype/config/ftheader.h (FT_BITMAP_H): New macro. - - * src/base/rules.mk (BASE_EXT_SRC): Add ftbitmap.c. - - * src/bdf/bdfdrivr.c (BDF_Glyph_Load): Don't convert bitmaps to 8bpp - but return them as-is. - - * docs/CHANGES: Mention new bitmap API. - * include/freetype/ftchapters.h: Updated. - -2004-12-11 Robert Clark - - * src/base/ftobjs.c (FT_Get_Kerning): Make kerning amount - dependent on ppem by scaling down for ppem < 25, then do normal - rounding. This gives slightly better results than rounding towards - zero. - -2004-12-09 Werner Lemberg - - * src/base/ftobjs.c (FT_Get_Kerning): Always round towards zero - for FT_KERNING_DEFAULT. This greatly enhances the kerning for - small ppem values. - -2004-12-08 Werner Lemberg - - * src/base/ftobjs.c (ft_glyphslot_clear): Reset `lsb_delta' and - `rsb_delta'. - -2004-12-05 Werner Lemberg - - * builds/unix/install.mk (install): Use $(OBJ_BUILD) for ftconfig.h. - -2004-12-03 Antoine Leca - - * include/freetype/ttnameid.h: Updated to latest - specifications from Microsoft. - -2004-11-26 Jouk Jansen - - * vms_make.com: Include ftbbox.c. - Fix `ccopt'. - Handle `otvalid' module. - Update `vmslib.dat' default values. - Fixes to `libs.opt'. - -2004-11-23 Anders Kaseorg - - * src/base/ftoutln.c (FT_OrientationExtremumRec, - ft_orientation_extremum_compute): Removed. - (FT_Outline_Get_Orientation): Rewritten, simplified. - - * src/autohint/ahglyph.c: Include FT_OUTLINE_H. - (ah_test_extremum, ah_get_orientation): Removed. - (ah_outline_load): Use FT_Outline_Get_Orientation. - - * src/base/ftsynth.c (ft_test_extrema, ft_get_orientation): Removed. - (FT_GlyphSlot_Embolden): Use FT_Outline_Get_Orientation. - -2004-11-23 Fernando Papa - - * src/truetype/ttinterp.h: Fix typo. - -2004-11-22 Antoine Leca - - * builds/win32/detect.mk: Corrected logic that detects Windows NT to - use the previous change even if win32 is forced. Corrected - detection of win32 on Win9X. - - * builds/dos/detect.mk: Added same correction as for win32 about - COPY on Windows NT. Detection of plain DOS 7.x. - -2004-11-22 Werner Lemberg - - * builds/detect.mk: Undo change from 2004-11-20. - * builds/win32/detect.mk: If the `OS' environment variable contains - `Windows_NT', use `cmd.exe /c copy' for copying files. - -2004-11-20 Werner Lemberg - - * builds/detect.mk (dos_setup): Use `cmd.exe' for copying - $(CONFIG_MK) to force lowercase file name under Windows. - -2004-11-19 Werner Lemberg - - Fix a serious bug in the TT hinter. - - * src/truetype/ttgload.c (TT_Process_Simple_Glyph): Don't shift - points vertically before hinting. - - * docs/CHANGES: Updated. - - * src/cache/ftcglyph.c (FTC_GNode_UnselectFamily, - FTC_GCache_Lookup): A new try to fix comparison with zero. - -2004-11-16 Werner Lemberg - - * builds/unix/configure.ac: Add `-fno-strict-aliasing' if gcc is - used. - * builds/unix/configure: Regenerated. - * builds/unix/config.guess, builds/unix/config.sub: Updated from - `config' CVS module at subversions.gnu.org. - -2004-11-16 Dr. Martin P.J. Zinser - - * src/cache/ftcglyph.c (FTC_GNode_UnselectFamily, - FTC_GCache_Lookup): Fix comparison with zero. - - * docs/INSTALL.VMS: Updated. - - * vms_make.com: Updated. All `descrip.mms' files are now created - automatically. - - * src/*/descrip.mms: Removed. - -2004-11-16 Owen Taylor - - * builds/unix/freetype-config.in: Suppress -L$libdir for - /usr/lib64 as well as /usr/lib. (Reported by Dan Winship - - https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=139199) - -2004-11-11 Werner Lemberg - - * src/cff/cffdrivr.c (cff_service_ps_info): Updated. - * src/cid/cidriver.c (cid_service_ps_info): Updated. - * src/type42/t42drivr.c (t42_ps_get_font_private): New function. - (t42_service_ps_info): Updated. - - * src/type42/t42parse.c (t42_parse_dict): Remove compiler warning. - -2004-11-11 David Bevan - - Add new function FT_Get_PS_Font_Private(). - - * include/freetype/internal/services/svpsinfo.h - (PS_GetFontPrivateFunc): New service function. - - * include/freetype/t1tables.h, src/base/fttype1.c - (FT_Get_PS_Font_Private): New function. - - * src/type1/t1driver.c (t1_ps_get_font_private): New function. - (t1_service_ps_info): Updated. - -2004-10-13 Werner Lemberg - - * include/freetype/config/ftstdlib.h: Include `stddef.h'. - (ft_ptrdiff_t): Define. - - * include/freetype/fttypes.h (FT_PtrDist): Use `ft_ptrdiff_t'. - - * src/cid/cidload.c (cid_parse_dict), src/type1/t1load.c - (parse_dict): Fix compiler warning. - -2004-10-11 Joshua Neal - - * src/sfnt/ttcmap.c (tt_face_build_cmaps): Check for pointer - overflow. - - * src/sfnt/ttload.c (tt_face_load_hdmx): Protect against bad input. - Don't use FT_QNEW_ARRAY but FT_NEW_ARRAY to make deallocation work - in case of failure. - - * src/sfnt/ttsbit.c (Load_SBit_Range): Check range intervals. - (tt_face_load_sbit_strikes): Allocate `strike_sbit_ranges' after - frame test. - - * src/truetype/ttgload.c (TTLoad_Simple_Glyph): Add assertion for - `flag'. - -2004-10-09 Werner Lemberg - - * docs/CHANGES: Updated. - -2004-10-09 Boris Letocha - - Fix handling of NPUSHW if skipped in data stream. - - * src/truetype/ttinterp.c (opcode_length): Set value for NPUSHW - to -2. - (SkipCode, TT_RunIns): Use opcode_length value for computation of - bytes to be skipped. - -2004-09-10 Jouk Jansen - - * vms_make.com: Updated. - -2004-09-09 Werner Lemberg - - Adding OpenType validation module. The code is based on the - (unfinished) `otlayout' module but has been heavily modified to make - it much more compact. - - * src/otvalid/*: New module. - - * include/freetype/ftotval.h, src/base/ftotval.c, - include/freetype/internal/services/svotval.h: New files. - - * include/freetype/config/ftmodule.h: Add otv_module_class. - * include/freetype/config/ftheader.h (FT_OPENTYPE_VALIDATE_H): New - macro. - * include/freetype/internal/ftserv.h - (FT_SERVICE_OPENTYPE_VALIDATE_H): New macro. - * include/freetype/internal/fttrace.h (otvmodule, otvcommon, - otvbase, otvgdef, otvgpos, otvgsub, otvjstf): New trace components. - - * include/freetype/ftchapters.h: Updated. - - * src/base/Jamfile (Library), src/base/descrip.mms (OBJS), - src/base/rules.mk (BASE_EXT_SRC): Updated. - - * docs/CHANGES: Updated. - -2004-09-08 Werner Lemberg - - * src/tools/docmaker/sources.py (re_source_block_format2) : - Use lookahead assertion to not match `*/'. This removes spurious - insertions of `/' in the HTML output. - -2004-09-07 Werner Lemberg - - * src/truetype/ttgxvar.c (TT_Vary_Get_Glyph_Deltas): Fix call to - FT_NEW_ARRAY. - -2004-09-04 Werner Lemberg - - * include/freetype/internal/ftobjs.h: Don't include - FT_CONFIG_STANDARD_LIBRARY_H. - (FT_Validator, FT_ValidationLevel, FT_ValidatorRec, FT_VALIDATOR, - ft_validator_init, ft_validator_run, ft_validator_error, FT_INVALID, - FT_INVALID_TOO_SHORT, FT_INVALID_OFFSET, FT_INVALID_FORMAT, - FT_INVALID_GLYPH_ID, FT_INVALID_DATA): Move to... - - * include/freetype/internal/ftvalid.h: New file. - Make FT_INVALID return module-specific error codes. - - * include/freetype/internal/internal.h (FT_INTERNAL_VALIDATE_H): New - macro. - - * include/freetype/fterrors.h: Undefine FT_ERR_PREFIX only if - FT_KEEP_ERR_PREFIX isn't defined. - - * src/base/ftobjs.c: Include FT_INTERNAL_VALIDATE_H. - - * src/sfnt/ttcmap.h: Don't include FT_INTERNAL_OBJECTS_H but - FT_INTERNAL_VALIDATE_H. - - * src/sfnt/ttcmap.c: Don't include FT_INTERNAL_OBJECTS_H but - FT_INTERNAL_VALIDATE_H. - Include sferrors.h before FT_INTERNAL_VALIDATE_H. - s/FT_Err_Ok/SFNT_Err_Ok/. - - * src/sfnt/sferrors.h: Define FT_KEEP_ERR_PREFIX. - - * src/type1/t1afm.c: Include t1errors.h. - -2004-09-03 Werner Lemberg - - * src/base/ftdebug.c (ft_debug_init): Highest debug level is 7, - not 6. - * docs/DEBUG: Updated. - -2004-08-30 Werner Lemberg - - * include/freetype/tttags.h (TTAG_BASE, TTAG_GDEF, TTAG_GPOS, - TTAG_JSTF): New tags. - - * include/freetype/fttypes.h (FT_Bytes, FT_Tag): New typedefs. - (FT_Int): Add `signed'. - -2004-08-29 Werner Lemberg - - * src/otlayout/otlgpos.c (otl_gpos_subtable_validate): Add argument - to pass number of lookups. - Update all callers. - Don't call otl_lookup_list_validate but otl_lookup_validate. - (otl_gpos_validate): Call otl_lookup_list_validate instead of - otl_gpos_subtable_validate. - - * src/otlayout/otlgpos.h: Updated. - - * src/otlayout/otljstf.c (otl_jstf_max_validate): Add argument to - pass number of lookups. - Update all callers. - - - * src/cff/cffparse.c (cff_parse_real): s/exp/exponent/ to avoid - compiler warning. - - - * src/sfnt/ttcmap0.c, src/sfnt/ttcmap0.h: Renamed to... - * src/sfnt/ttcmap.c, src/sfnt/ttcmap.h: This. - * src/sfnt/Jamfile, src/sfnt/rules.mk, src/sfnt/sfdriver.c, - src/sfnt/sfnt.c, src/sfnt/sfobjs.c: Updated. - - - * builds/compiler/gcc-dev.mk (CFLAGS): Don't add `-Wnested-externs' - if compiler is g++ (v3.3.3 emits a warning otherwise). - -2004-08-28 Werner Lemberg - - * src/otlayout/otlgpos.c (otl_value_length): Return number of bytes, - not number of 16bit entities. - (otl_gpos_lookup2_validate): Check class definition tables for - format 2. - Fix loop for format 2. - (otl_liga_mark2_validate): Fix offset for otl_anchor_validate. - -2004-08-27 Werner Lemberg - - * src/base/ftmac.c: Don't include truetype/ttobjs.h. - Don't include type1/t1objs.h. - (FT_New_Face_From_FSSpec) [!__MWERKS__]: Remove compiler warnings. - -2004-08-27 Mathieu Malaterre - - * src/base/ftmac.c: Handle OS_INLINE for xlc compiler also. - -2004-08-27 Werner Lemberg - - * src/otlayout/otlayout.h: Add copyright. - (OTL_INVALID_OFFSET): Removed. - - * src/otlayout/otlgdef.h: Include otlayout.h. - Comment out inclusion of otltable.h. - - * src/otlayout/otlgpos.c (otl_gpos_lookup4_validate): Fix call - to otl_base_array_validate. - (otl_liga_mark2_validate): Fix `for' loop. - - * src/otlayout/otlgsub.c (otl_ligature_validate): Check `glyph_id', - not components array. - - * src/otlcommn.c (otl_lookup_get_count, otl_feature_get_count): - Comment out. - (otl_lookup_list_get_count, otl_feature_list_get_count): Activate. - (otl_feature_list_validate, otl_gsubgpos_get_lookup_count): - s/otl_lookup_get_count/otl_lookup_list_get_count/. - (otl_script_list_validate): - s/otl_feature_get_count/otl_feature_list_get_count/. - (otl_script_validate): Call otl_lang_validate for default language. - - * src/otlayout/otlcommn.h: Updated. - -2004-08-16 Werner Lemberg - - * src/otlayout/otlgpos.c (otl_gpos_lookup1_validate, - otl_gpos_lookup2_validate, otl_gpos_lookup3_validate, - otl_gpos_lookup4_validate, otl_gpos_lookup5_validate, - otl_gpos_lookup6_validate, otl_gpos_lookup9_validate, - otl_gpos_validate): Update - function arguments. - (otl_gpos_lookup7_validate, otl_gpos_lookup8_validate): Update - function arguments. - Handle NULL offsets correctly. - Check sequence and lookup indices for format 3. - (otl_pos_rule_validate, otl_chain_pos_rule_validate): Add argument - to pass lookup count. - Check sequence and glyph indices. - (otl_gpos_subtable_validate): Update function arguments. - Update callers. - - * src/otlayout/otlgpos.h: Updated. - - * src/otlayout/otlgsub.c (otl_gsub_lookup1_validate, - otl_gsub_lookup3_validate, otl_gsub_lookup8_validate): Update - function arguments. - Add glyph index checks. - (otl_sequence_validate, otl_alternate_set_validate, - otl_ligature_validate): Add argument to pass glyph count. - Update callers. - Add glyph index check. - (otl_gsub_lookup2_validate, otl_gsub_lookup4_validate): Update - function arguments. - (otl_ligature_set_validate): Add argument to pass glyph count. - Update caller. - (otl_sub_class_rule_validate, - otl_sub_class_rule_set_validate): Removed. - (otl_sub_rule_validate, otl_chain_sub_rule_validate): Add argument - to pass lookup count. - Update callers. - Add lookup index check. - (otl_sub_rule_set_validate, otl_chain_sub_rule_set_validate): Add - argument to pass lookup count. - Update callers. - (otl_gsub_lookup5_validate): Update function arguments. - Handle NULL offsets correctly. - Don't call otl_sub_class_rule_set_validate but - otl_sub_rule_set_validate. - Check sequence and lookup indices for format 3. - (otl_gsub_lookup6_validate): Update function arguments. - Handle NULL offsets correctly. - Check sequence and lookup indices for format 3. - (otl_gsub_lookup7_validate, otl_gsub_validate): Update function - arguments. - - * src/otlayout/otlgsub.h: Updated. - - * src/otlayout/otlbase.c (otl_base_validate): Handle NULL offsets - correctly. - - * src/otlayout/otlcommn.c (otl_class_definition_validate): Fix - compiler warning. - (otl_coverage_get_first, otl_coverage_get_last): New functions. - (otl_lookup_validate): Add arguments to pass lookup and glyph - counts. - Update callers. - (otl_lookup_list_validate): Add argument to pass glyph count. - Update callers. - - * src/otlayout/otlcommn.h: Updated. - - * src/otlayout/otljstf.c (otl_jstf_extender_validate, - otl_jstf_max_validate, otl_jstf_script_validate, - otl_jstf_priority_validate, otl_jstf_lang_validate): Add parameter - to validate glyph indices. - Update callers. - (otl_jstf_validate): Add parameter which specifies number of glyphs - in font. - - * src/otlayout/otljstf.h: Updated. - -2004-08-15 Werner Lemberg - - * src/otlayout/otlgpos.c (otl_liga_mark2_validate): Add parameter - to handle possible NULL values properly. - Update all callers. - -2004-08-15 Werner Lemberg - - * src/otlayout/gpos.c: Rename counting variables to be more - meaningful. - Add copyright. - (otl_liga_attach_validate): Renamed to... - (otl_liga_mark2_validate): This. - Update all callers. - (otl_mark2_array_validate): Removed. - (otl_gpos_lookup6_validate): Call otl_liga_mark2_validate, not - otl_mark2_array_validate. - (otl_pos_class_set_validate, otl_pos_class_rule_validate): Removed. - (otl_gpos_lookup7_validate): Complete code for format 2. - (otl_chain_pos_class_rule_validate, - otl_chain_pos_class_set_validate): Removed. - (otl_gpos_lookup8_validate): Don't call - otl_chain_pos_class_set_validate but - otl_chain_pos_rule_set_validate. - Simplify some code. - - * src/otlayout/otlgpos.h: Add copyright. - -2004-08-14 Werner Lemberg - - * src/otlayout/otljstf.c (otl_jstf_gsub_mods_validate): Removed. - (otl_jstf_gpos_mods_validate): Renamed to... - (otl_jstf_gsubgpos_mods_validate): This. - Test whether lookup_count is zero. - (otl_jstf_priority_validate): Use otl_jstf_gsubgpos_mods_validate. - (otl_jstf_validate): Initialize gsub_lookup_count and - gpos_lookup_count if gsub or gpos is zero. - - * src/otlayout/otlgsub.c: Rename counting variables to be more - meaningful. - Add copyright. - (otl_gsub_lookup1_validate): Simplify code. - (otl_gsub_lookup2_validate, otl_gsub_lookup3_validate, - otl_gsub_lookup4_validate, otl_gsub_lookup7_validate): Remove unused - variables. - (otl_gsub_lookup5_validate): Remove unused variable. - Fix call to otl_sub_rule_set_validate and - otl_sub_class_rule_set_validate. - (otl_chain_sub_class_rule_validate, - otl_chain_sub_class_set_validate): Removed. - (otl_gsub_lookup6_validate): Remove unused variable. - Fix call to otl_chain_sub_rule_set_validate. - (otl_gsub_lookup7_validate): Handle lookup type 8 also. - (otl_gsub_lookup8_validate: New function. - (otl_gsub_lookup1_apply, otl_gsub_lookup2_apply, - otl_gsub_lookup3_apply): Commented out. - (otl_gsub_validate_funcs): Add otl_gsub_lookup7_validate and - otl_gsub_lookup8_validate. - (otl_gsub_validate): Updated. - - * src/otlayout/otlgsub.h: Add copyright. - - * src/otlayout/otlcommn.c, src/otlayout/otlcommn.h - (otl_coverage_get_index): Comment out. - -2004-08-13 Werner Lemberg - - * src/otlayout/otlcommn.c (otl_gsubgpos_get_lookup_count): New - function. - * src/otlayout/otlcommn.h: Updated. - - * src/otlayout/otlbase.c: Rename counting variables to be more - meaningful. - Add copyright message. - * src/otlayout/otlbase.h: Add copyright message. - - * src/otlayout/otlgdef.c: Rename counting variables to be more - meaningful. - Add copyright message. - Use OTL_CHECK everywhere. - (otl_caret_value_validate): Remove unused variable. - (otl_gdef_validate): All tables are optional. - * src/otlayout/otlgdef.h: Add copyright message. - - * src/otlayout/otljstf.c: Rename counting variables to be more - meaningful. - Add copyright message. - (otl_jstf_gsub_mods_validate, otl_jstf_gpos_mods_validate): Add - parameter to pass lookup count. - Update all callers. - Check lookup array. - (otl_jstf_max_validate): - s/otl_gpos_subtable_check/otl_gpos_subtable_validate/. - (otl_jstf_priority_validate, otl_jstf_lang_validate, - otl_jstf_script_validate): Add two parameters to pass lookup counts. - Update all callers. - (otl_jstf_validate): Add two parameters to pass GPOS and GSUB - table offsets; use otl_gsubgpos_get_lookup_count to convert extract - lookup counts. - Fix typo. - * src/otlayout/otljstf.h: Updated. - Add copyright message. - - * src/otlayout/otlgpos.c (otl_gpos_subtable_validate): New function. - (otl_gpos_validate): Use it. - * src/otlayout/otlgpos.h: Updated. - -2004-08-13 Werner Lemberg - - * src/otlayout/otcommn.c: Use OTL_CHECK everywhere. - (otl_coverage_validate): Initialize `p', - s/count/num_glyphs/. - s/start_cover/start_coverage/. - (otl_coverage_get_index): Return OTL_Long, not OTL_Int. - Remove unused variables. - (otl_class_definition_validate): s/count/num_glyphs/. - Remove unused variables. - (otl_class_definition_get_value, otl_device_table_get_start, - otl_device_table_get_end, otl_device_table_get_delta, - otl_lookup_get_table, otl_lookup_list_get_count, - otl_lookup_list_get_lookup, otl_lookup_list_get_table, - otl_feature_get_lookups, otl_feature_list_get_count, - otl_feature_list_get_feature, otl_lang_get_count, - otl_lang_get_req_feature, otl_lang_get_features): Commented out - temporarily until we really need it. - (otl_lookup_validate): Removed. - (otl_lookup_table_validate): Renamed to ... - (otl_lookup_validate): This. Update callers. - (otl_lookup_list_validate): Remove already commented out definition - and move the other definition up. - (otl_feature_validate): Add parameter to pass number of lookups. - Update callers. - Check lookup indices. - (otl_feature_list_validate): Add parameter to pass lookup table. - Update callers. - (otl_lang_validate): Add parameter to pass number of features. - Update callers. - Handle req_feature and check feature indices. - (otl_script_validate): Add parameter to pass number of features. - Update callers. - (otl_script_list_validate): Add parameter to pass feature table. - Update callers. - - * src/otlayout/otcommn.h: s/LOCALDEF/LOCAL/. - Comment out the same functions as in otcommn.c. - (otl_script_list_get_script): Removed. - - * src/otlayout/otlgsub.c (otl_gsub_lookup1_apply): Change `index' to - type OTL_Long. - (otl_gsub_lookup2_apply, otl_gsub_lookup3_apply): Change `index' to - type OTL_Long. - Fix test. - (otl_gsub_validate): Fix order of validation. - - * src/otlayout/otlgpos.c (otl_gpos_validate): Fix order of - validation. - -2004-08-12 Werner Lemberg - - Make otlayout module compile (without actually working). - - * src/otlayout/*: s/OTL_Valid/OTL_Validator/. - s/NULL/0/. - - * src/otlayout/otlayout.h: Fix various typos. - (OTL_Bool): New typedef. - (OTL_Int, OTL_Long, OTL_Int16, OTL_Int32): Use `signed' keyword. - (OTL_Err_InvalidArgument): Removed. - (OTL_Err_InvalidData, OTL_Err_InvalidSize): New enum values. - (OTL_MAKE_TAG): Add missing parenthesis. - (OTL_INVALID_DATA): Use OTL_Err_InvalidData. - (OTL_INVALID_TOO_SHORT): Use OTL_Err_InvalidSize. - (OTL_INVALID_FORMAT, OTL_INVALID_OFFSET): New macros. - - * src/otlayout/otlgpos.c: s/FT_/OTL_/. - s/OTL_Short/OTL_Int16/. - (otl_gpos_pairset_validate): Add return type. - (otl_base_array_validate): Fix call to otl_anchor_validate. - (otl_liga_array_validate): Fix call to otl_liga_attach_validate. - (otl_gpos_lookup5_validate): Fix typos. - (otl_gpos_lookup6_validate): Fix call to otl_mark2_array_validate. - (otl_gpos_lookup7_validate): Comment out unfinished code. - Fix typos. - - * src/otlayout/otlgsub.c: Add forward declaration for - otl_gsub_validate_funcs. - (otl_gsub_lookup1_apply, otl_gsub_lookup2_apply, - otl_gsub_lookup3_apply): Fix call to otl_parser_check_property. - s/otl_coverage_lookup/otl_coverage_get_index/. - (otl_ligature_validate): Add missing variable declaration. - (otl_sub_rule_validate): Fix typo. - (otl_sub_class_rule_validate): Add missing variable declaration. - Fix typo. - (otl_gsub_lookup5_validate): Fix typo. - (otl_gsub_lookup6_validate): Fix call to - otl_chain_sub_class_set_validate. - (otl_gsub_validate_funcs): Don't use `const'. - - * src/otlayout/otlcommn.c (otl_class_definition_get_value, - otl_device_table_validate, otl_device_table_get_delta, - otl_lookup_validate, otl_script_validate): Add missing - variable declarations. - (otl_lookup_list_validate): Comment out first definition. - (otl_lookup_list_foreach, otl_feature_list_foreach): Comment out. - (otl_feature_list_validate): - s/otl_feature_table_validate/otl_feature_validate/. - (otl_script_list_validate): - s/otl_script_table_validate/otl_script_validate/. - - * src/otlayout/otlcommn.h: Comment out first declaration. - (otl_lookup_list_foreach, otl_feature_list_foreach): Comment out. - - * src/otlayout/otlbase.c (otl_base_coord_validate): Fix call to - otl_device_table_validate. - (otl_base_script_validate): Add missing variable declarations. - (otl_base_script_list_validate): Fix call to - otl_base_script_validate. - (otl_axis_table_validate): Fix calls to otl_base_tag_list_validate - and otl_base_script_list_validate. - (otl_base_validate): Fix calls to otl_axis_table_validate. - - * src/otlayout/otlgdef.c (otl_attach_list_validate): Fix call to - otl_attach_point_validate. - (otl_caret_value_validate): Add missing variable declaration. - Fix call to otl_device_table_validate. - (otl_ligature_glyph_validate): Fix call to otl_caret_value_validate. - (otl_ligature_caret_list_validate): Fix call to - otl_ligature_glyph_validate. - (otl_gdef_validate): Fix calls to otl_class_definition_validate, - otl_attach_list_validate, otl_ligature_caret_list_validate, and - otl_class_definition_validate. - - * src/otlayout/otltable.h (otl_table_validate, otl_table_init, - otl_table_set_script): Comment out. - - * src/otlayout/otlparse.h (OTL_ParserRec): - s/OTL_Alternate/OTL_GSUB_Alternate/. - (OTL_ParseError): Add OTL_Err_Parser_Memory and - OTL_Err_Parser_Internal. - (otl_parser_error): Fix typo. - (otl_parser_check_property): Remove third argument. - - * src/otlayout/otlparse.c (otl_string_ensure): - s/OTL_Parse_Err_Memory/OTL_Err_Parser_Memory/. - (OTL_STRING_ENSURE, otl_parser_error, otl_parser_get_index, - otl_parser_replace_1, otl_parser_replace_n): Fix typos. - (OTL_PARSER_UNCOVERED): Removed. - (otl_parser_check_property): Remove third argument. - - * src/otlayout/otljstf.c (otl_jstf_priority_validate): Add missing - variable declaration. - - * src/otlayout/otlutils.h (OTL_MEM_REALLOC): Fix typo. - -2004-08-11 Danny - - * src/base/ftstream.c (FT_Stream_Close): Don't reset stream->close - to NULL. This allows custom close functions to delete the FT_STREAM - object. - -2004-08-11 Werner Lemberg - - Add API to get information about SFNT tables. - - * include/freetype/internal/services/svsfnt.h - (FT_SFNT_Table_Info_Func): New typedef. - (SFNT_Table): Add it. - - * src/base/ftobjs (FT_Sfnt_Table_Info): New function. - - * include/freetype/tttables.h: Updated. - - * src/sfnt/sfdriver.c (sfnt_table_info): New function. - (sfnt_service_sfnt_table): Add it. - - * docs/CHANGES: Updated. - - - * include/freetype/freetype.h (FREETYPE_PATCH): Set to 10. - - * builds/unix/configure.ac (version_info): Set to 9:8:3. - * builds/unix/configure: Updated. - - * builds/win32/visualc/index.html, - builds/win32/visualc/freetype.dsp, - builds/win32/visualc/freetype.vcproj: s/219/2110/, s/2.1.9/2.1.10/. - - * builds/freetype.mk (refdoc), README, Jamfile (RefDoc): - s/2.1.9/2.1.10/. - - * docs/CHANGES, docs/VERSION.DLL: Updated. - -2004-08-11 Detlef Würkner - - * src/base/ftrfork.c (FT_Raccess_Guess) - [!FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK]: Remove compiler - warnings. - -2004-08-06 Adam Piotrowski - - * src/pfr/pfrload.c (pfr_sort_kerning_pairs): Single-byte - adjustments are unsigned, not signed. - -2004-08-05 David Turner - - `Activate' gray-scale specifying hinting within the TrueType - bytecode interpreter. This is an experimental feature which - should probably be made optional. - - * src/truetype/ttgload.c (TT_Process_Simple_Glyph, - load_truetype_glyph): Move the code to set the pedantic_hinting flag - to... - (TT_Load_Glyph): Here. - Set `grayscale' flag except for `FT_LOAD_TARGET_MONO'. - - * src/truetype/ttinterp.c (Ins_GETINFO): Return MS rasterizer - version 1.7. - Return rotation and stretching info only if glyph is rotated or - stretched, respectively. - Handle grayscale info. - - * src/truetype/ttinterp.h (TT_ExecContextRec): Add `grayscale' - member. - -2004-08-02 George Williams - - * src/base/ftobjs.c (FT_Attach_File): Initialize `open.stream'. - -2004-08-01 Werner Lemberg - - * docs/CHANGES: Updated. - -2004-08-01 George Williams - - FreeType now can read kerning values from PFM files. - - * src/type1/t1afm.c (T1_Done_AFM): Renamed to... - (T1_Done_Metrics): This. - Update all callers. - (T1_Read_AFM): Make it static. - Don't enter and leave a frame. - (LITTLE_ENDIAN_USHORT, LITTLE_ENDIAN_UINT): New macros. - (T1_Read_PFM): New function. - (T1_Read_Metrics): New higher-level function to be used instead of - T1_Read_AFM. - Update all callers. - -2004-07-31 Werner Lemberg - - * src/pcf/pcfread (pcf_load_font), src/bdf/bdfdrivr.c - (BDF_Face_Init), src/truetype/ttgxvar (TT_Get_MM_Var, - tt_face_vary_cvt): Fix compiler warnings. - -2004-07-26 Søren Sandmann - - * src/pcf/pcfread.c (pcf_interpret_style): Always allocate memory for - face->style_name. - * src/pcf/pcfdrivr.c (PCF_Face_Done): Free `style_name'. - -2004-07-26 Darren J Longhorn - - * include/freetype/config/ftconfig.h (FT_SIZEOF_LONG): Recognize - five-byte `long' (which is avoided then). - -2004-07-25 Detlef Würkner - - * src/pcf/pcfdrivr.c (PCF_Set_Pixel_Size): Compare heights, not - ppem values. - (PCF_Set_Point_Size): Don't call PCF_Set_Pixel_Size but provide own - code to compare ppem values. - * src/bdf/bdfdrivr.c (BDF_Set_Pixel_Size): Compare heights, not - ppem values. - (BDF_Set_Point_Size): Don't call BDF_Set_Pixel_Size but provide own - code to compare ppem values. - -2004-07-25 Kornfeld Eliyahu Peter - - * src/sfnt/sfobjs.c (sfnt_load_face): Handle - TT_NAME_ID_PREFERRED_FAMILY and TT_NAME_ID_PREFERRED_SUBFAMILY. - -2004-07-24 Derek B. Noonburg - - * src/cff/cffload.c (cff_font_load): Always create inverse mapping. - Even if the charstring count is the same as the CID count, it is - still possible that the font uses a different CID -> GID mapping. - -2004-07-23 Werner Lemberg - - * src/truetype/ttobjs.c (tt_face_init): Accept 0x00020000 format tag - found in some Arphic fonts made for Chinese version of Windows 3.1. - -2004-07-17 David Turner - - Fixed a dangling pointer bug in the cache code that happened in very - rare cases, i.e., when a new family object was destroyed by an - out-of-memory condition during a glyph node initialization. The - function FTC_Cache_Lookup would flush the cache and restart the - lookup with a bad pointer. - - * include/freetype/cache/ftcglyph.h (FTC_FAMILY_TREE): New macro. - (FTC_GCACHE_LOOKUP_CMP): Use it. - Handle reference count in `num_nodes' correctly. - - * src/cache/ftcglyph.c (FTC_GNode_UnselectFamily): Use - FTC_FAMILY_FREE. - (FTC_GCache_Lookup): Handle reference count in `num_nodes' correctly. - - * src/cache/ftcmanag.c (FTC_Manager_FlushN): Fixed a cache flushing - bug. - - * src/truetype/ttinterp.c (Normalize): Fixed a bug that caused - long and unnecessary delays while normalizing huge vectors. - -2004-07-15 Werner Lemberg - - * docs/CHANGES: Updated. - - * src/base/ftstroke.c (FT_Stroker_ParseOutline): Fix compiler - warning. - -2004-07-15 David Turner - - * src/base/ftstroke.c (FT_Stroker_ParseOutline): Single points - are not stroked, preventing a bug with pala.ttf and other - fonts. - - * include/freetype/ftstroke.h: Updating documentation comments. - -2004-07-13 Werner Lemberg - - * src/base/ftstroke.c (ft_stroke_border_reverse): Removed. Unused. - -2004-07-12 David Turner - - * src/base/ftstroke.c (ft_stroke_border_close): Add second parameter - to indicate reversion of points. - Update all callers. - (ft_stroke_border_reverse): Fix initialization of `point1' and - `tag1'. - - * src/cache/ftcsbits.c (ftc_snode_load): Fixing advance computation - for transformed glyphs. - -2004-07-11 David Turner - - Fix bugs that prevented the stroker to correctly generate stroked - paths from closed paths, i.e., nearly all glyphs in vectorial fonts. - - The code is still _very_ buggy though; treat with special care. - - * src/base/ftstroke.c (FT_STROKE_TAG_BEGIN_END): New macro. - (ft_stroke_border_reverse): New function. - (ft_stroker_inside): Remove local variable `sigma'; use different - threshold. - (ft_stroker_add_reverse_left): Switch begin/end tags if necessary. - (FT_Stroker_EndSubPath): Call ft_stroker_inside and - ft_stroke_border_reverse. - -2004-06-26 Peter Kovar - - * src/truetype/ttgload.c (load_truetype_glyph): Fix typo. - -2004-06-25 Werner Lemberg - - * src/type1/t1afm.c (afm_atoindex): Fix boundary test. Reported - by Dirck Blaskey. - -2004-06-24 David Turner - - - * Version 2.1.9 released. - ========================= - - - * src/truetype/ttgload.c, src/truetype/ttxgvar.c: Removing - compiler warnings. - -2004-06-23 Werner Lemberg - - * include/freetype/internal/ftmemory.h [FT_DEBUG_MEMORY]: Declare - FT_QAlloc_Debug and FT_QRealloc_Debug. - - * src/base/ftutil.c (FT_QAlloc): Fix error and debug messages. - (FT_QRealloc): Call FT_QAlloc if original pointer is NULL. - Fix error message. - -2004-06-23 David Turner - - * include/freetype/internal/ftmemory.h, src/base/ftutil.c - (FT_QAlloc, FT_QRealloc), src/base/ftdbgmem.c (FT_QAlloc_Debug, - FT_QRealloc_Debug): New functions that perform allocation without - zero-ing out the corresponding blocks. - - * include/freetype/internal/ftmemory.h (FT_MEM_QALLOC, - FT_MEM_QREALLOC, FT_MEM_QNEW, FT_MEM_QNEW_ARRAY, - FT_MEM_QRENEW_ARRAY, FT_QALLOC, FT_QREALLOC, FT_QNEW, FT_QNEW_ARRAY, - FT_QRENEW_ARRAY): New macros. - - * src/base/ftstream.c (FT_Stream_EnterFrame): Use FT_QALLOC. - * src/gzip/ftgzip.c (FT_Stream_OpenGzip): Use FT_QNEW_ARRAY. - * src/sfnt/sfobjs.c (tt_face_get_name): Use FT_QNEW_ARRAY. - - * src/sfnt/ttload.c (tt_face_load_directory, tt_face_load_metrics, - tt_face_load_gasp): Use FT_QNEW_ARRAY. - (tt_face_load_kern): Use FT_QNEW_ARRAY. - Small optimization in the kerning table verifier; this speeds up - TrueType face opening by about 7%. - (tt_face_load_hdmx): Use FT_QNEW_ARRAY and FT_QALLOC. - - * include/freetype/config/ftmodule.h: Changed the order of modules, - putting TrueType and Type 1 first. This dramatically improves the - performance of face open/close operations. For example, putting the - TrueType driver first in the list results in a 5x speedup when - opening `Vera.ttf'. - - The very problem is that both the PCF and BDF drivers do a lot more - than necessary to detect that they cannot handle a font file. - -2004-06-22 Werner Lemberg - - * src/pcf/pcfread.c (pcf_read_TOC, pcf_get_properties, - pcf_get_metrics, pcf_get_bitmaps, pcf_get_encodings): Improve - debugging messages. - - * src/pcf/pcfdrivr.c (FT_COMPONENT): Move up. - (PCF_Face_Init): Simplify code. - - * src/bdf/bdfdrivr.h (BDF_FaceRec): New element `default_glyph'. - - * src/bdf/bdflib.c (_bdf_add_property, _bdf_parse_start), - src/bdf/bdf.h (bdf_font_t): s/default_glyph/default_char/. - - * src/bdf/bdfdrivr.c (BDF_Face_Init): Fix number of glyphs. - Set `default_glyph'. - (BDF_Glyph_Load): Use `default_glyph' for undefined glyph. - - * docs/CHANGES: Updated. - -2004-06-21 Werner Lemberg - - * docs/CHANGES: Updated. - -2004-06-21 David Turner - - * src/truetype/ttgload.c (TT_Process_Simple_Glyph, - load_truetype_glyph): Don't access (unrounded) - `TT_Size.root.metrics' but (rounded) `TT_Size.metrics'. This fixes - a scaling bug that caused incorrect rendering when the bytecode - interpreter was enabled. - -2004-06-14 Huw D M Davies - - * src/winfonts/winfnt.c (FNT_Face_Init): Set x_ppem and y_ppem - based on pixel_width and pixel_height. - (FNT_Size_Set_Pixels): Updated. - -2004-06-14 Werner Lemberg - - * src/lzw/zopen.c: Comment out inclusion of signal.h and unistd.h. - Reported by Hyvärinen Jyrki Juhani. - -2004-06-11 Werner Lemberg - - * docs/CHANGES: Updated. - -2004-06-10 David Turner - - * src/base/ftobject.c, src/base/fthash.c, src/base/ftexcept.c, - src/base/ftsysio.c, src/base/ftsysmem.c, src/base/ftlist.c: Removed. - Obsolete. - - * src/raster/ftraster.c (Alignment, PAlignment): New union to fix - problems with 64bit systems. - (AlignProfileSize): Use it. - -2004-06-08 David Turner - - * include/freetype/freetype.h (FT_Glyph_Metrics): Move `lsb_delta' - and `rsb_delta' elements to... - (FT_GlyphSlotRec): Here to retain binary compatibility with older - FreeType versions. - Update all users. - - * src/sfnt/sfobjs.c (tt_face_get_name): Remove compiler warning. - - * src/winfonts/winfnt.c (FNT_Load_Glyph): Add missing initialization - of slot->metrics.width and slot->metrics.height when loading a - Windows FNT glyph. Thanks to Huw Davies. - - * include/freetype/cache/ftcmru.h (FTC_MruNode_CompareFunc): Change - return type to FT_Bool. - - * src/cache/ftcbasic.c (ftc_basic_family_compare): Change return - type to FT_Bool. - - * src/cache/ftccache.c (FTC_Cache_Init, ftc_cache_init): Make - the former call the latter, not vice versa. - (FTC_Cache_Done, ftc_cache_done): Ditto. - - * src/cache/ftcglyph.c (FTC_GNode_Compare, ftc_gnode_compare): Make - the former call the latter, not vice versa. - (FTC_GCache_Init, ftc_gcache_init): Ditto. - (FTC_GCache_Done, ftc_gcache_done): Ditto. - - * src/cache/ftcimage.c (FTC_INode_Free, ftc_inode_free): Make the - former call the latter, not vice versa. - (FTC_INode_Weight, ftc_inode_weight): Ditto. - - * src/cache/ftcmanag.c (ftc_size_node_compare, - ftc_size_node_compare_faceid, ftc_face_node_compare): Change return - type to FT_Bool. - - * src/cache/ftcsbits.c (FTC_SNode_Free, ftc_snode_free): Make the - former call the latter, not vice versa. - (FTC_SNode_Weight, ftc_snode_weight): Ditto. - (FTC_SNode_Compare, ftc_snode_compare): Ditto. - - * src/cache/ftcsbits.c: Fix some bugs and inefficiencies in the cache - sub-system. - -2004-06-05 Werner Lemberg - - * src/autofit/afloader.c (af_loader_load_g): Set `lsb_delta' and - `rsb_delta' in slot->metrics and tune side bearings slightly. - -2004-06-04 Werner Lemberg - - * docs/CHANGES: Updated. - -2004-06-04 David Chester - - Improve inter-letter spacing for autohinted glyphs. - - * include/freetype/freetype.h (FT_Glyph_Metrics): Add elements - `lsb_delta' and `rsb_delta'. - - * src/autohint/ahhint.c (ah_hinter_load): Set `lsb_delta' and - `rsb_delta' in slot->metrics and tune side bearings slightly. - -2004-06-04 David Turner - - * src/autofit/*: Important fixes to the auto-fitter. The output - now seems to be 100% equivalent to the auto-hinter, while being - about 2% faster (which proves that script-specific algorithm - selection isn't a performance problem). - - To test it, change `autohint' to `autofit' in - and recompile. - - A few more testing is needed before making this the official - auto-hinting module. - -2004-06-02 Werner Lemberg - - * src/truetype/ttgload.c (compute_glyph_metrics): Fix compiler - warnings. - -2004-06-01 Werner Lemberg - - * src/sfnt/sfobjs.c (tt_face_get_name): Make sure that an English - name record for the Apple platform is preferred to a non-English - entry for the Microsoft platform. Problem reported by HANDA - Ken'ichi. - -2004-05-19 George Williams - - * src/type1/t1load.c (mm_axis_unmap, mm_weights_unmap): New - auxiliary functions. - (T1_Get_MM_Var): Provide axis tags. - Use mm_axis_unmap and mm_weights_unmap to provide default values - for design and normalized axis coordinates. - - * include/freetype/t1tables.h (PS_DesignMapRec): Change type of - `design_points' to FT_Long. - Update all users. - -2004-05-17 Werner Lemberg - - * src/base/ftbbox.c (BBox_Conic_Check): Fix boundary cases. - Reported by Mikey Anbary . - -2004-05-15 Werner Lemberg - - * src/sfnt/sfobjs.c (sfnt_done_face): Free face->postscript_name. - -2004-05-15 George Williams - - * src/sfnt/ttload.c (tt_face_load_max_profile): Always set - face->root.num_glyphs. - -2004-05-14 Masatake YAMATO - George Williams - - * src/sfnt/ttload.c (sfnt_dir_check): Handle `bhed' properly. - -2004-05-14 Werner Lemberg - - * src/cache/ftcbasic.c (ftc_basic_family_compare, - ftc_basic_family_init, ftc_basic_family_get_count, - ftc_basic_family_load_bitmap, ftc_basic_family_load_glyph, - ftc_basic_gnode_compare_faceid): Adjust parameters and return types - to prototypes given in header files from include/freetype/cache. - Use casts to proper types locally. - (ftc_basic_image_family_class, ftc_basic_image_cache_class, - ftc_basic_sbit_family_class, ftc_basic_sbit_cache_class): Remove - casts. - - * src/cache/ftccback.h: Adjust parameters and return types to - prototypes given in header files from include/freetype/cache. - - * src/cache/ftcimage.c (ftc_inode_free, ftc_inode_new, - ftc_inode_weight): Adjust parameters and return types to prototypes - given in header files from include/freetype/cache. Use casts to - proper types locally. - - * src/cache/ftcsbits.c (ftc_snode_free, ftc_snode_new, - ftc_snode_weight, ftc_snode_compare): Adjust parameters and return - types to prototypes given in header files from - include/freetype/cache. Use casts to proper types locally. - - * src/cache/ftccmap.c (ftc_cmap_node_free, ftc_cmap_node_new, - ftc_cmap_node_weight, ftc_cmap_node_compare, - ftc_cmap_node_remove_faceid): Adjust parameters and return types to - prototypes given in header files from include/freetype/cache. Use - casts to proper types locally. - (ftc_cmap_cache_class): Remove casts. - - * src/cache/ftcglyph.c (ftc_gnode_compare, ftc_gcache_init, - ftc_gcache_done): Adjust parameters and return types to prototypes - given in header files from include/freetype/cache. Use casts to - proper types locally. - - * src/cache/ftcmanag.c (ftc_size_node_done, ftc_size_node_compare, - ftc_size_node_init, ftc_size_node_reset, - ftc_size_node_compare_faceid, ftc_face_node_init, - ftc_face_node_done, ftc_face_node_compare: Adjust parameters and - return types to prototypes given in header files from - include/freetype/cache. Use casts to proper types locally. - - (ftc_size_list_class, ftc_face_list_class): Remove casts. - -2004-05-13 Werner Lemberg - - * src/autohint/ahmodule.c (ft_autohinter_init, ft_autohinter_done): - Use FT_Module as parameter and do a cast to FT_AutoHinter locally. - (autohint_module_class): Remove casts. - - * src/base/ftglyph.c (ft_bitmap_glyph_init, ft_bitmap_glyph_copy, - ft_bitmap_glyph_done, ft_bitmap_glyph_bbox, ft_outline_glyph_init, - ft_outline_glyph_done, ft_outline_glyph_copy, - ft_outline_glyph_transform, ft_outline_glyph_bbox, - ft_outline_glyph_prepare): Use FT_Glyph as parameter and do a cast - to FT_XXXGlyph locally. - Use FT_CALLBACK_DEF throughout. - (ft_bitmap_glyph_class, ft_outline_glyph_class): Remove casts. - - * src/bdf/bdfdrivr.c (bdf_cmap_init, bdf_cmap_done, - bdf_cmap_char_index, bdf_cmap_char_next): Use FT_CMap as parameter - and do a cast to BDF_CMap locally. - (bdf_cmap_class): Remove casts. - -2004-05-12 Werner Lemberg - - * src/cff/cffgload.h (CFF_Builder): Remove `error'. - * src/cff/cffgload.c (cff_decoder_parse_charstrings): Replace - `Memory_Error' with `Fail' and update all users. - -2004-05-11 Werner Lemberg - - * include/freetype/internal/psaux.h (T1_ParseState): New - enumeration. - (T1_BuilderRec): Replace `path_begun' with `parse_state'. - Remove `error'. - * src/psaux/t1decode.c (t1_decoder_parse_charstrings): Replace - `Memory_Error' with `Fail' and update all users. - Don't use `builder->error'. - Replace `path_begun' with `parse_state' and check parsing states. - - * src/psaux/psobjs.c (t1_builder_init, t1_builder_start_point): - Replace `path_begun' with `parse_state' and check parsing states. - -2004-05-10 George Williams - - * src/truetype/ttxgvar.c (ft_var_load_avar): Do free arrays in case - of error -- `avar' is optional so we can't rely on tt_done_blend - being called automatically. - -2004-05-09 George Williams - - * src/truetype/ttxgvar.c (ft_var_load_avar, ft_var_load_gvar): Fix - error handling. - -2004-05-07 Werner Lemberg - - * src/pfr/pfrobjs.c, src/pfr/pfrobjs.h (pfr_face_init, - pfr_face_done, pfr_face_get_kerning, pfr_slot_init, pfr_slot_done, - pfr_slot_load): Don't use PFR_XXX but FT_XXX arguments which are - typecast to the proper PFR_XXX types within the function. - Update code accordingly. - - * src/pfr/pfrdrivr.c (pfr_get_kerning, pfr_get_advance, - pfr_get_metrics, pfr_get_service): Don't use PFR_XXX but FT_XXX - arguments which are typecast to the proper PFR_XXX types within the - function. - Update code accordingly. - Use FT_CALLBACK_DEF throughout. - (pfr_metrics_service_rec, pfr_driver_class): Remove casts. - -2004-05-06 Masatake YAMATO - - * src/truetype/ttgxvar.c (ft_var_load_gvar): Use FT_FACE_STREAM. - (*): Rename local variable OffsetToData to offsetToData. - -2004-05-06 Werner Lemberg - - * src/cff/cffobjs.c (cff_size_done, cff_size_init, cff_size_reset, - cff_slot_done, cff_slot_init, cff_face_init, cff_face_done): Access - root fields directly. - * src/cff/cffdrivr.c (Load_Glyph): Access root fields directly. - - * src/truetype/ttgload.c (TT_Process_Simple_Glyph): Save current - frame before calling TT_Vary_Get_Glyph_Deltas. - - * src/pcf/pcfdrivr.c (PCF_CMapRec): Rename `cmap' to `root' for - consistency. - (pcf_cmap_init, pcf_cmap_done, pcf_cmap_char_index, - pcf_cmap_char_next): Don't use PCF_XXX but FT_XXX arguments which - are typecast to the proper PCF_XXX types within the function. - Update code accordingly. - (pcf_cmap_class): Remove casts. - (PCF_Face_Done, PCF_Face_Init, PCF_Set_Pixel_Size): Don't use - PCF_XXX but FT_XXX arguments which are typecast to the proper - PCF_XXX types within the function. - Update code accordingly. - Use FT_CALLBACK_DEF throughout. - (PCF_Set_Point_Size): New wrapper function. - (PCF_Glyph_Load, pcf_driver_requester): Use FT_CALLBACK_DEF. - (pcf_driver_class): Remove casts. - -2004-05-04 Steve Hartwell - - * src/truetype/ttobjs.c (tt_driver_done): Fix typo. - -2004-05-04 Werner Lemberg - - * src/bdf/bdfdrivr.c (BDF_Face_Done, BDF_Face_Init, - BDF_Set_Pixel_Size): Don't use BDF_XXX but FT_XXX arguments which - are typecast to the proper BDF_XXX types within the function. - Update code accordingly. - Use FT_CALLBACK_DEF throughout. - (BDF_Set_Point_Size): New wrapper function. - (bdf_driver_class): Remove casts. - - * src/cff/cffdrivr.c (Get_Kerning, Load_Glyph, cff_get_interface): - Don't use CFF_XXX but FT_XXX arguments which are typecast to the - proper CFF_XXX types within the function. - Update code accordingly. - Use FT_CALLBACK_DEF throughout. - (cff_driver_class): Remove casts. - - * src/cff/cffobjs.h, src/cff/cffobjs.c (cff_size_done, - cff_size_init, cff_size_reset, cff_slot_done, cff_slot_init, - cff_face_init, cff_face_done, cff_driver_init, cff_driver_done): - Don't use CFF_XXX but FT_XXX arguments which are typecast to the - proper CFF_XXX types within the function. - Update code accordingly. - (cff_point_size_reset): New wrapper function. - - * src/cid/cidobjs.h, src/cid/cidobjs.c (cid_slot_done, - cid_slot_init, cid_size_done, cid_size_init, cid_size_reset, - cid_face_done, cid_face_init, cid_driver_init, cid_driver_done): - Don't use CID_XXX but FT_XXX arguments which are typecast to the - proper CID_XXX types within the function. - Update code accordingly. - (cid_point_size_reset): New wrapper function. - - * src/cid/cidgload.c, src/cid/cidgload.h (cid_slot_load_glyph): - Don't use CID_XXX but FT_XXX arguments which are typecast to the - proper CID_XXX types within the function. - Update code accordingly. - - * src/cid/cidriver.c (cid_get_interface): - Don't use CID_XXX but FT_XXX arguments which are typecast to the - proper CID_XXX types within the function. - Update code accordingly. - Use FT_CALLBACK_DEF. - (t1cid_driver_class): Remove casts. - - * src/truetype/ttdriver.c (tt_get_interface): Use FT_CALLBACK_DEF. - * src/truetype/ttgxvar.c (ft_var_load_avar): Don't free non-local - variables (this is done later). - (ft_var_load_avar): Fix call to FT_FRAME_ENTER. - (TT_Get_MM_Var): Fix size for `fvar_fields'. - (TT_Vary_Get_Glyph_Deltas): Handle deallocation of local variables - correctly. - - * src/base/ftdbgmem.c (ft_mem_debug_realloc): Don't abort if - current size is zero. - -2004-05-03 Steve Hartwell - - * src/truetype/ttobjs.h, src/truetype/ttobjs.c (tt_face_init, - tt_face_done, tt_size_init, tt_size_done, tt_driver_init, - tt_driver_done): Don't use TT_XXX but FT_XXX arguments which are - typecast to the proper TT_XXX types within the function. - Update code accordingly. - - * src/truetype/ttdriver.c (Get_Kerning, Set_Char_Sizes, - Set_Pixel_Sizes, Load_Glyph, tt_get_interface): Don't use TT_XXX but - FT_XXX arguments which are typecast to the proper TT_XXX types - within the function. - Update code accordingly. - (tt_driver_class): Remove casts. - -2004-05-02 Werner Lemberg - - * src/sfnt/ttload.c (tt_face_free_names): Check that `table->names' - is not NULL. Reported by Gordon Childs . - -2004-04-29 Werner Lemberg - - * docs/formats.txt: Add more information on PFR format. - -2004-04-28 Werner Lemberg - - * docs/formats.txt: New file. - * docs/CHANGES: Updated. - -2004-04-28 Masatake YAMATO - - * include/freetype/internal/tttypes.h (GX_BlendRec_) - [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Fix a typo. - - * src/truetype/ttgxvar.h (GX_BlendRec_): Fix a typo. - -2004-04-27 Masatake YAMATO - - * src/truetype/ttgxvar.h: Use FT_LOCAL instead of FT_LOCAL_DEF - for function declarations. - -2004-04-25 George Williams - - * src/truetype/ttgxvar.c (ft_var_apply_tuple): Fix typo. - -2004-04-25 Werner Lemberg - - * src/truetype/Jamfile, docs/CHANGES: Updated. - -2004-04-24 Werner Lemberg - - * src/pcf/pcfdrivr.c: Revert change from 2004-04-17. - * src/pcf/pcfutil.c: Use FT_LOCAL_DEF. - * src/pcf/pcfutil.h: Include FT_CONFIG_CONFIG_H. - Use FT_BEGIN_HEADER and FT_END_HEADER. - Use FT_LOCAL. - -2004-04-24 George Williams - - Add support for Apple's distortable font technology (in GX fonts). - - * devel/ftoption.h, include/freetype/config/ftoption.h - (TT_CONFIG_OPTION_GX_VAR_SUPPORT): New macro. - - * include/freetype/ftmm.h (FT_Var_Axis, FT_Var_Named_Style, - FT_MM_Var): New structures. - (FT_Get_MM_Var, FT_Set_Var_Design_Coordinates, - FT_Set_Var_Blend_Coordinates): New function declarations. - - * include/freetype/internal/services/svmm.h (FT_Get_MM_Var_Func, - FT_Set_Var_Design_Func): New typedefs. - Update MultiMasters service. - - * include/freetype/internal/tttypes.h - [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include FT_MULTIPLE_MASTERS_H. - (GX_Blend) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: New typedef. - (TT_Face) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: New members `doblend' - and `blend'. - - * include/freetype/tttags.h (TTAG_avar, TTAG_cvar, TTAG_gvar): New - macros. - - * include/freetype/internal/fttrace.h: Add `ttgxvar'. - - * src/base/ftmm.c (FT_Get_MM_Var, FT_Set_Var_Design_Coordinates, - FT_Set_Var_Blend_Coordinates): New functions. - - * src/sfnt/sfobjs.c (sfnt_load_face) - [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Set FT_FACE_FLAG_MULTIPLE_MASTERS - flag for GX var fonts. - - * src/truetype/ttgxvar.c, src/truetype/ttgxvar.h: New files. - - * src/truetype/truetype.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include - ttgxvar.c. - - * src/truetype/ttdriver.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include - FT_MULTIPLE_MASTERS_H, FT_SERVICE_MULTIPLE_MASTERS_H, and ttgxvar.h. - (tt_service_gx_multi_masters) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: - New service. - (tt_services) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Updated. - - * src/truetype/ttgload.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include - ttgxvar.h. - (TT_Process_Simple_Glyph, load_truetype_glyph) - [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Support GX var fonts. - - * src/truetype/ttobjs.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include - ttgxvar.h. - (tt_done_face) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Call - tt_done_blend. - - * src/truetype/ttpload.c [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Include - ttgxvar.h. - (tt_face_load_cvt) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]: Call - tt_face_vary_cvt. - - * src/truetype/rules.mk (TT_DRV_SRC): Add ttgxvar.c. - - * src/type1/t1driver.c (t1_service_multi_masters): Add T1_Get_MM_Var - and T1_Set_Var_Design. - - * src/type1/t1load.c (FT_INT_TO_FIXED, FT_FIXED_TO_INT): New macros. - (T1_Get_MM_Var, T1_Set_Var_Design): New functions. - - * src/type1/t1load.h (T1_Get_MM_Var, T1_Set_Var_Design): New - function declarations. - -2004-04-23 Werner Lemberg - - * include/freetype/ftcache.h (FT_Get_CharMap_Index): Rename - declaration and move to... - * include/freetype/freetype.h (FT_Get_Charmap_Index): Here. - (FREETYPE_PATCH): Set to 9. - - * src/base/ftobjs.c (FT_Get_Charmap_Index): New function. - - * builds/unix/configure.ac (version_info): Set to 9:7:3. - * builds/unix/configure: Updated. - - * builds/win32/visualc/index.html, - builds/win32/visualc/freetype.dsp, - builds/win32/visualc/freetype.vcproj: s/218/219/. - - * builds/freetype.mk (refdoc), README, Jamfile (RefDoc): - s/2.1.8/2.1.9/. - - * docs/CHANGES, docs/VERSION.DLL: Updated. - -2004-04-21 Werner Lemberg - - * src/cff/cffparse.c (cff_parser_run), src/psaux/psobjs.c - (ps_parser_load_field): Use FT_CHAR_BIT. - -2004-04-21 David Turner - - - * Version 2.1.8 released. - ========================= - - - * src/cff/cffobjs.c (cff_face_init): Fix a small memory leak. - - * src/autofit/afloader.c (af_loader_load_g), src/autofit/afmodule.c - (af_autofitter_load_glyph), src/base/ftdebug.c (FT_Trace_Get_Name): - Remove compiler warnings. - - * src/autofit/aftypes.h: Undefine AF_DEBUG. - - * src/lzw/zopen.c (rmask), src/pcf/pcfdrivr.c (pcf_service_bdf, - pcf_services), src/pcf/pcfread.c (tableNames), src/psaux/psobjs.c - (ft_char_table), src/type42/t42drivr.c (t42_service_glyph_dict, - t42_service_ps_font_name): Decorate data arrays with `const' to - avoid populating the `.data' segment. - - * src/lzw/Jamfile: New file. - -2004-04-20 Werner Lemberg - - * src/psaux/psobjs.c (T1Radix): Renamed to... - (ps_radix): This. - Update current cursor position. - - * docs/CHANGES: Updated. - -2004-04-18 Werner Lemberg - - * src/truetype/ttgload.c, src/truetype/ttgload.h (TT_Load_Glyph), - src/ttdriver.c (Load_Glyph): Change type of `glyph_index' to - FT_UInt. From Lex Warners. - -2004-04-17 Chisato Yamauchi - - * src/sfnt/ttload.c (tt_face_load_sfnt_header): Really fix change - from 2004-03-19. - - * src/bdf/bdfdrivr.c (BDF_Face_Init): Use `ft_strlen'. - - * src/pcf/pcfutil.c, src/pcf/pcfutil.h: Decorate functions with - `static'. - Remove unused function `RepadBitmap'. - * src/pcf/pcfdrivr.c: Don't include pcfutil.h. - -2004-04-16 Werner Lemberg - - * builds/unix/freetype-config.in (usage): Fix and improve usage - information. - -2004-04-15 Werner Lemberg - - * builds/unix/ftconfig.in, builds/vms/ftconfig.h: Define - FT_CHAR_BIT. - - * src/base/ftobjs.c (FT_Load_Glyph): Don't apply autohinting if - glyph is vertically distorted or mirrored. - - * src/cff/cffgload.c (cff_slot_load): Handle zero `size' properly - for embedded bitmaps. - - * docs/CHANGES: Updated. - -2004-04-15 bytesoftware - - * include/freetype/config/ftconfig.h, src/base/ftstream.c - (FT_Stream_ReadFields): More fixes using FT_CHAR_BIT. - -2004-04-14 Werner Lemberg - - * include/freetype/config/ftconfig.h (FT_CHAR_BIT): New macro. - -2004-04-14 Alex Strelnikov - - * src/cache/ftcsbits.c (ftc_snode_load): Initialize `*asize' in case - of error. - -2004-04-14 Werner Lemberg - - * src/base/ftmac.c [__GNUC__]: Define OS_INLINE. - * builds/unix/configure.ac: Don't try to remove `-ansi' compilation - switch on the Mac. - - * builds/unix/ltmain.sh: Regenerated with `libtoolize --force - --copy' from libtool 1.5.6. - * builds/unix/aclocal.m4: Regenerated with `aclocal -I .' from - automake 1.8a. - * builds/unix/configure: Regenerated with autoconf 2.59a. - -2004-04-13 Werner Lemberg - - * include/freetype/config/ftconfig.h: Use CHAR_BIT to define - size of FT_SIZEOF_xxx. - -2004-04-12 Chisato Yamauchi - - * include/freetype/internal/sfnt.h (TT_Find_SBit_Image_Func, - TT_Load_SBit_Metrics_Func): New typedefs. - (SFNT_Interface): Add find_sbit_image and load_sbit_metrics. - - * src/sfnt/sfdriver.c (sfnt_interface): Updated. - * src/sfnt/ttsbit.h (tt_find_sbit_image, tt_load_sbit_metrics): New - declarations. - * src/sfnt/ttsbit.c (find_sbit_image): Renamed to... - (tt_find_sbit_image): This. - Updated all callers. - (load_sbit_metrics): Renamed to... - (tt_load_sbit_metrics): This. - Updated all callers. - -2004-04-12 Werner Lemberg - - * configure: Accept makepp also. - - * builds/unix/detect.mk: Use proper path to unix-def.mk. - * builds/unix/unix-def.in (BUILD_DIR, PLATFORM): Remove. - * builds/unix/unix.mk (BUILD_DIR, PLATFORM): Define. - Use BUILD_DIR. - - * docs/INSTALL, docs/INSTALL.GNU, docs/INSTALL.UNX: Update - documentation on makepp. - -2004-04-11 Werner Lemberg - - * src/lzw/zopen.c: Don't include sys/param.h and sys/stat.h. - -2004-04-10 Werner Lemberg - - * src/lzw/ftlzw.c: Include zopen.h dependent on - FT_CONFIG_OPTION_USE_LZW. - - * src/base/ftdebug.c: s/index/idx/ to avoid compiler warnings. - -2004-04-02 Werner Lemberg - - * builds/unix/ltmain.sh: Regenerated with `libtoolize --force - --copy' from libtool 1.5.2. - * builds/unix/aclocal.m4: Regenerated with `aclocal -I .' from - automake 1.8a. - * builds/unix/configure: Regenerated with autoconf 2.59a. - -2004-04-01 Werner Lemberg - - * builds/unix/ft-munmap.m4 (FT_MUNMAP_PARAM): Fix arguments of - AC_COMPILE_IFELSE. - * builds/unix/aclocal.m4: Regenerated with `aclocal -I .' from - automake 1.8a. - * builds/unix/configure: Regenerated with autoconf 2.59a. - * builds/unix/config.guess, builds/unix/config.sub: Updated from - `config' CVS module at subversions.gnu.org. - * builds/unix/install-sh, builds/unix/mkinstalldirs: Updated from - `texinfo' CVS module at subversions.gnu.org. - * builds/freetype.mk (refdoc): Updated. - -2004-03-31 Werner Lemberg - - Handle broken FNT files which don't have a trailing NULL byte - in the face name string. - - * src/winfonts/winfnt.h (FNT_FontRec): New member `family_name'. - * src/winfonts/winfnt.c (fnt_font_done): Free font->family_name. - (FNT_Face_Init): Append a final zero byte to the font face name. - -2004-03-30 Werner Lemberg - - * src/sfnt/ttload.c (tt_face_load_sfnt_header): Fix change from - 2004-03-19. - -2004-03-27 Werner Lemberg - - * src/base/descrip.mms (OBJS): Add ftbbox.obj. - -2004-03-26 George Williams - - Add vertical phantom points. - - * include/freetype/internal/tttypes.h (TT_LoaderRec): Add - `top_bearing', `vadvance', `pp3', and `pp4'. - - * src/autofit/afloader.c (af_loader_load_g): Handle two more points. - - * src/autohint/ahhint.c (ah_hinter_load): Handle two more points. - * src/truetype/ttgload.c (Get_VMetrics): New function. - (TT_Load_Simple_Glyph, TT_Process_Simple_Glyph): Handle two more - points. - (load_truetype_glyph): Use Get_VMetrics. - Handle two more points. - (compute_glyph_metrics): Thanks to vertical phantom points we now - can always compute `advance_height' and `top_bearing'. - * src/truetype/ttobjs.h (TT_SubglyphRec): Add vertical phantom - points. - - - * src/autohint/ahglyph.c (ah_outline_load): Fix allocation of - `news'. - -2004-03-21 Werner Lemberg - - * src/bdf/bdfdrivr.c (BDF_Glyph_Load): Fix left side bearing. - -2004-03-20 Steve Hartwell - - * src/cache/ftcmru.c (FTC_MruList_RemoveSelection): Handle a NULL - value for `selection' as `select all'. - -2004-03-19 Steve Hartwell - - * src/sfnt/ttload.c (tt_face_load_sfnt_header): Reject face_index - values > 0 if loading non-TTC fonts. - - * src/base/ftmac.c (open_face_from_buffer): Set positive face_index - to zero before calling FT_Open_Face. - - * docs/CHANGES: Updated. - -2004-03-04 Werner Lemberg - - * Jamfile, vms_make.com, builds/win32/visualc/freetype.dsp, - builds/win32/visualc/freetype/vcproj, include/freetype/ftmoderr.h: - Add LZW module. - - * Jamfile.in: Removed. - - * docs/CHANGES: Updated. - - * include/freetype/internal/ftobjs.h: s/MIN/FT_MIN/, s/MAX/FT_MAX/, - s/ABS/FT_ABS/. Updated all callers. - - * src/type1/t1load.c (parse_dict), src/pcf/pcfdrivr.c - (PCF_Face_Init): Use FT_ERROR_BASE. - -2004-03-04 Albert Chin - - Add support for PCF fonts compressed with LZW (extension .pcf.Z, - created with `compress'). - - * include/freetype/config/ftoption.h, devel/ftoption.h - (FT_CONFIG_OPTION_USE_LZW): New macro. - - * include/freetype/ftlzw.h: New file. - * include/freetype/config/ftheader.h (FT_LZW_H): New macro for - ftlzw.h. - - * src/lzw/*: New files. - - * src/pcf/pcfdrivr.c: Include FT_LZW_H. - (PCF_Face_Init): Try LZW also. - - * src/gzip/ftgzip.c: s/0/Gzip_Err_Ok/ where appropriate. - Beautify. - -2004-03-03 Werner Lemberg - - * src/pshinter/pshalgo.c (psh_hint_table_init): Simplify code. - -2004-03-02 Werner Lemberg - - Add embedded bitmap support to CFF driver. - - * src/cff/cffobjs.h (CFF_SizeRec): New structure. - - * src/cff/cffgload.c (cff_builder_init): Updated. - (cff_slot_load): Updated. - [TT_CONFIG_OPTION_EMBEDDED_BITMAPS]: Load sbit. - - * src/cff/cffobjs.c (sbit_size_reset) - [TT_CONFIG_OPTION_EMBEDDED_BITMAPS]: New function. - (cff_size_get_globals_funcs, cff_size_done, cff_size_init): Updated. - (cff_size_reset): Updated. - [TT_CONFIG_OPTION_EMBEDDED_BITMAPS]: Call sbit_size_reset. - - * src/cff/cffdrivr.c (Load_Glyph): Updated. - (cff_driver_class): Use CFF_SizeRec. - - * docs/CHANGES: Updated. - -2004-03-01 Werner Lemberg - - * src/pshinter/pshglob.c (psh_globals_scale_widths): Don't use - FT_RoundFix but FT_PIX_ROUND. - (psh_blues_snap_stem): Don't use blue_shift but blue_threshold. - - * src/pshinter/pshalgo.c (PSH_STRONG_THRESHOLD_MAXIMUM): New macro. - (psh_glyph_find_strong_points): Use PSH_STRONG_THRESHOLD_MAXIMUM. - (psh_glyph_find_blue_points): New function. Needed for fonts like - p052003l.pfb (URW Palladio L Roman) which have flex curves at the - base line within blue zones, but the flex curves aren't covered by - hints. - (ps_hints_apply): Use psh_glyph_find_blue_points. - -2004-02-27 Garrick Meeker - - * builds/unix/configure.ac: Fix compiler flags for - `--with-old-mac-fonts'. - * builds/unix/configure: Regenerated. - - * src/base/ftmac.c: s/TARGET_API_MAC_CARBON/!TARGET_API_MAC_OS8/. - (FT_New_Face_From_Resource): New function. - (FT_New_Face): Use FT_New_Face_From_Resource. - (FT_New_Face_From_FSSpec): Use FT_New_Face_From_Resource. - [__MWERKS__]: Don't include FSp_fopen.h. - -2004-02-26 Werner Lemberg - - * src/pshinter/pshglob.c (psh_globals_new): Fix value of - `dim->stdw.count'. - Don't assign default values to blue scale and blue shift. - -2004-02-25 Werner Lemberg - - * docs/CHANGES: Updated. - -2004-02-25 Garrick Meeker - Steve Hartwell - - Improve MacOS fond support. Provide a new API - `FT_New_Face_From_FSSpec' similar to `FT_New_Face'. - - * src/base/ftmac.c [__MWERKS__]: Include FSp_fopen.h. - STREAM_FILE [__MWERKS__]: New macro. - (ft_FSp_stream_close, ft_FSp_stream_io) [__MWERKS__]: New functions. - (file_spec_from_path) [__MWERKS__]: Updated #if statement. - (get_file_type, make_lwfn_spec): Use `const' for argument. - (is_dfont) [TARGET_API_MAC_CARBON]: Removed. - (count_face_sfnt, count_faces): New functions. - (parse_fond): Do some range checking. - (read_lwfn): Change type of second argument. - No longer call FSpOpenResFile. - (OpenFileAsResource): New function. - (FT_New_Face_From_LWFN): Use `const' for second argument. - Use OpenFileAsResource. - (FT_New_Face_From_Suitcase): Change type of second argument. - No longer call FSpOpenResFile. - Loop over all resource indices. - (FT_New_Face_From_dfont) [TARGET_API_MAC_CARBON]: Removed. - (FT_GetFile_From_Mac_Name): Use `const' for first argument. - (ResourceForkSize): Removed. - (FT_New_Face): Updated to use new functions. - (FT_New_Face_From_FSSpec): New function. - - * include/freetype/ftmac.h: Updated. - -2004-02-24 Malcolm Taylor - - * src/autohint/ahhint.c (ah_hinter_load) : - Handle case where outline->num_vedges is zero while computing hinted - metrics. - -2004-02-24 Gordon Childs - - * src/cff/cffcmap.c (cff_cmap_unicode_init): Provide correct value - for `count'. - -2004-02-24 Werner Lemberg - - * include/freetype/t1tables.h (PS_PrivateRec): Add - `expansion_factor'. - - * src/pshinter/pshglob (psh_blues_scale_zones): Fix computation - of blues->no_overshoots -- `blues_scale' is stored with a - magnification of 1000, and `scale' returns fractional pixels. - - * src/type1/t1load.c (T1_Open_Face): Initialize `blue_shift', - `blue_fuzz', `expansion_factor', and `blue_scale' according to the - Type 1 specification. - - * src/type1/t1tokens.h: Handle `ExpansionFactor'. - - * docs/CHANGES: Updated. - -2004-02-24 Masatake YAMATO - - Provide generic access to MacOS resource forks. - - * src/base/ftrfork.c, include/freetype/internal/ftrfork.h: New - files. - - * src/base/ftobjs.c: Include FT_INTERNAL_RFORK_H. - (Mac_Read_POST_Resource, Mac_Read_sfnt_Resource): Remove arguments - `resource_listoffset' and `resource_data' and adapt code - accordingly. These values are calculated outside of the function - now. - Add new argument `offsets'. - (IsMacResource): Use `FT_Raccess_Get_HeaderInfo' and - `FT_Raccess_Get_DataOffsets'. - (load_face_in_embedded_rfork): New function. - (load_mac_face): Use load_face_in_embedded_rfork. - (ft_input_stream_new): Renamed to... - (FT_Stream_New): This. Use FT_BASE_DEF. Updated all callers. - (ft_input_stream_free): Renamed to... - (FT_Stream_Free): This. Use FT_BASE_DEF. Updated all callers. - - * src/base/ftbase.c: Include ftrfork.c. - - * src/base/rules.mk (BASE_SRC), src/base/Jamfile: Updated. - - * include/freetype/internal/internal.h (FT_INTERNAL_RFORK_H): - New macro. - - * include/freetype/internal/fttrace.h: Added `rfork' as a new - trace definition. - - * include/freetype/internal/ftstream.h: Declare FT_Stream_New and - FT_Stream_Free. - - * include/freetype/config/ftoption.h, devel/ftoption.h - (FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK): New option. - - * include/freetype/config/ftstdlib.h (ft_strrchr): New macro. - -2004-02-23 Werner Lemberg - - * docs/CHANGES: Updated. - - * include/freetype/internal/ftdebug.h: Include FT_FREETYPE_H. - -2004-02-23 Masatake YAMATO - - Provide a simple API to control FreeType's tracing levels. - - * include/freetype/internal/ftdebug.h (FT_Trace_Get_Count, - FT_Trace_Get_Name): New declarations. - - * src/base/ftdebug.c (FT_Trace_Get_Count, FT_Trace_Get_Name): New - functions. - -2004-02-23 David Turner - - * src/autofit/afhints.c, src/autofit/afhints.h, - src/autofit/aflatin.c, src/autofit/afloader.c, src/types.h: Grave - bugs have been fixed. The auto-fitter works, doesn't crash, but - still produces unexpected results... - -2004-02-21 Werner Lemberg - - * src/pshinter/pshalgo.c (PSH_STRONG_THRESHOLD): Changed to hold - the accepted shift for strong points in fractional pixels (which - is a heuristic value). - (psh_glyph_find_strong_points): Compute threshold for - psh_hint_table_find_strong_points. - (psh_hint_table_find_strong_point): Add parameter to pass threshold. - -2004-02-20 Werner Lemberg - - * src/pshinter/pshrec.c (ps_mask_table_set_bits): Don't call - ps_mask_table_alloc but ps_mask_table_last. - (ps_hints_t2mask): Use correct position and number for vertical - and horizontal hinter mask bits. - - * docs/CHANGES: Updated. - -2004-02-19 Werner Lemberg - - * src/base/ftstroke.c (FT_Glyph_StrokeBorder): Fix enum handling. - * src/cff/cffdrivr.c (cff_get_cmap_info): Remove compiler warning. - -2004-02-18 Werner Lemberg - - * include/freetype/freetype.h: Document FT_LOAD_TARGET_XXX properly. - - * src/base/ftglyph.c (ft_bitmap_glyph_class, - ft_outline_glyph_class): Tag with FT_CALLBACK_TABLE_DEF. - - * src/smooth/ftsmooth.c (ft_smooth_render): Handle - FT_RENDER_MODE_LIGHT. - -2004-02-17 Werner Lemberg - - Fix callback functions in cache module. - - * src/cache/ftccback.h: New file for callback declarations. - - * src/cache/ftcbasic.c (ftc_basic_family_compare, - ftc_basic_family_init, ftc_basic_family_get_count, - ftc_basic_family_load_bitmap, ftc_basic_family_load_glyph, - ftc_basic_gnode_compare_faceid): Use FT_CALLBACK_DEF. - (ftc_basic_image_family_class, ftc_basic_image_cache_class, - ftc_basic_sbit_family_class, ftc_basic_sbit_cache_class): - Use FT_CALLBACK_TABLE_DEF and local wrapper functions. - - * src/cache/ftccache.c: Include ftccback.h. - (ftc_cache_init, ftc_cache_done): New wrapper functions which use - FT_LOCAL_DEF. - - * src/cache/ftccmap.c: Include ftccback.h. - (ftc_cmap_cache_class): Use local wrapper functions. - - * src/cache/ftcglyph.c: Include ftccback.h. - (ftc_gnode_compare, ftc_gcache_init, ftc_gcache_done): New wrapper - functions which use FT_LOCAL_DEF. - - * src/cache/ftcimage.c: Include ftccback.h. - (ftc_inode_free, ftc_inode_new, ftc_inode_weight): New wrapper - functions which use FT_LOCAL_DEF. - - * src/cache/ftcmanag.c (ftc_size_list_class, ftc_face_list_class): - Use FT_CALLBACK_TABLE_DEF. - - * src/cache;/ftcsbits.c: Include ftccback.h. - (ftc_snode_free, ftc_snode_new, ftc_snode_weight, - ftc_snode_compare): New wrapper functions which use FT_LOCAL_DEF. - - * src/cache/rules.mk (CACHE_DRV_H): Add ftccback.h. - -2004-02-17 Masatake YAMATO - - * include/freetype/ftmac.h (FT_GetFile_From_Mac_Name): Fix a typo - (FT_EXPORT_DEF -> FT_EXPORT). - - * include/freetype/ftxf86.h (FT_Get_X11_Font_Format): Ditto. - -2004-02-15 Werner Lemberg - - * src/base/ftobjs.c (FT_Set_Char_Size): Fix typo. - -2004-02-14 Masatake YAMATO - - * builds/unix/ftsystem.c: Include errno.h. - (ft_close_stream): Renamed to... - (ft_close_stream_by_munmap): This. - (ft_close_stream_by_free): New function. - (FT_Stream_Open): Use fallback method if mmap fails. - Use proper function for closing the stream. - -2004-02-14 Werner Lemberg - - * src/type1/t1load.c (parse_dict): Initialize `start_binary'. - -2004-02-13 Robert Etheridge - - * src/type42/t42objs.c (T42_Face_Init), src/type1/t1objs.c - (T1_Face_Init), src/cid/cidobjs.c (cid_face_init): Fix computation - of underline_position and underline_thickness. - -2004-02-12 Werner Lemberg - - * src/base/ftobjs.c (FT_Set_Char_Size): Return immediately if - ppem values don't change. Suggested by Graham Asher. - -2004-02-11 Werner Lemberg - - * src/cid/cidload.c (cid_face_open): Always allocate - face->cid_stream so that we can deallocate it safely. - -2004-02-10 Werner Lemberg - - Make the PS parser more tolerant w.r.t. non-standard font data. In - general, an error is only reported in case of a syntax error; a - wrong type is now simply ignored (if possible). To be independent - of the order of various MM-specific keywords, the parse_shared_dict - routine has been removed -- the PS parser is now capable to skip - this data. It no longer fails on parsing e.g. - - dup /WeightVector exch def - - Since the token following /WeightVector isn't `[' (starting an - array) it is simply ignored. - - * include/freetype/fterrdef.h: Define `FT_Err_Ignore' (0xA2) as a - new internal error value. - - * src/type1/t1load.c (parse_blend_axis_types, - parse_blend_design_positions, parse_blend_design_map): Return - T1_Err_Ignore if no proper array is following the keyword. - (parse_weight_vector): Use T1_ToTokenArray, initializing `blend' - structure, if necessary. - Return T1_Err_Ignore if no proper array is following the keyword. - (parse_shared_dict): Removed. - (parse_encoding): Set parser->root.error to return T1_Err_Ignore - if no result can be obtained. - Check for errors before accessing `elements' array. - (t1_keywords): Remove /shareddict. - (parse_dict): Reset error if t1_load_keyword returns T1_Err_Ignore. - Set keyword_flag only in case of success. - Check error code if skipping an unrecognized token. - (T1_Open_Face) [!T1_CONFIG_OPTION_NO_MM_SUPPORT]: Call T1_Done_Blend - if blend commands haven't set up a proper MM font. - - * src/psaux/psobjs.c (ps_parser_load_field_table): Remove special - code for synthetic fonts. - Return PSaux_Err_Ignore if no proper value has been found. - -2004-02-09 Werner Lemberg - - * src/cff/cffgload.c (cff_decoder_parse_charstrings) - : Preserve glyph width before calling - cff_operator_seac. - -2004-02-09 Martin Muskens - - * src/cff/cffgload.c (cff_decoder_parse_charstrings): Handle special - first argument for `hintmask' and `cntrmask' operators also. - -2004-02-08 Werner Lemberg - - * builds/unix/configure.in: Call AC_SUBST for `enable_shared', - `hardcode_libdir_flag_spec', and `wl'. - * builds/unix/configure: Regenerated. - - * builds/unix/freetype-config.in: Make --prefix and --exec-prefix - actually work. - Report a proper --rpath (or -R) value for --libs argument if a - shared library has been built. - - * docs/CHANGES: Updated. - -2004-02-07 Keith Packard - - * src/bdf/bdfdrivr.c (BDF_Face_Init, BDF_Set_Pixel_Size): Fix - computation of various vertical and horizontal metric values. - - * src/pcfdrivr.c (PCF_Set_Pixel_Size), src/pcfread (pcf_load_font): - Ditto. - -2004-02-07 Werner Lemberg - - * builds/win32/visualc/index.html, - builds/win32/visualc/freetype.dsp, - builds/win32/visualc/freetype.dsw, docs/CHANGES: Updated. - -2004-02-07 Vitaliy Pasternak - - * builds/win32/visualc/freetype.sln, - builds/win32/visualc/freetype.vcproj: New files for VS.NET 2003. - -2004-02-03 Werner Lemberg - - * include/freetype/cache/ftccache.h (FTC_CACHE_LOOKUP_CMP): - Initialize `node'. - * src/type1/t1load.c (parse_dict): Initialize `have_integer'. - -2004-02-02 Werner Lemberg - - * src/type1/t1load.c (parse_dict): Handle `RD' and `-|' commands - outside of /Subrs or /CharStrings. This can happen if there is - additional code manipulating those two arrays so that FreeType - doesn't recognize them properly. - (T1_Open_Face): Improve an error message. - -2004-02-01 Werner Lemberg - - * src/type1/t1load.c (parse_charstrings): Exit immediately if - there are no elements in /CharStrings. This is needed for fonts - like Optima-Oblique which not only define /CharStrings but access it - also. - -2004-02-01 David Turner - - * src/sfnt/Jamfile: Removing `ttcmap' from the list of sources. - - * include/freetype/cache/ftccache.h (FTC_CACHE_LOOKUP_CMP) - : Provide macro version which doesn't use inline code. - * include/freetype/cache/ftcglyph.h (FTC_GCACHE_LOOKUP_CMP) - : Ditto. - Use FTC_MRULIST_LOOKUP_CMP. - * include/freetype/cache/ftcmru.h (FTC_MRULIST_LOOKUP_CMP): New - macro. - (FTC_MRULIST_LOOKUP): Use it. - - * src/cache/Jamfile (_sources), src/cache/descrip.mms: Updated. - * src/cache/ftcbasic.c: Fix compiler warnings. - * src/cache/ftcmanag.c (FTC_Manager_LookupSize, - FTC_Manager_LookupFace) : Use FTC_MRULIST_LOOKUP_CMP. - * src/cache/ftcmru.c (FTC_MruList_Find): Fix a bug (found after - heavy testing). - - * Jamfile: Updating `refdoc' target, and adding `autohint' to the - list of modules to build. Both the autohinter and autofitter will - be built by default. But which one will be used is determined by - the content of `ftmodule.h'. - - * src/autofit/*: Many updates, but the code is still buggy... - -2004-01-31 Werner Lemberg - - * src/cff/cffgload.c (cff_operator_seac): Fix magnitude of - accent offset. - Update code similarly to the seac support for Type 1 fonts. - (cff_decoder_parse_charstrings) : Fix magnitude - of accent offset. - Don't hint glyphs twice if seac is emulated. - : Assign correct point tags. - * docs/CHANGES: Updated. - -2004-01-30 Werner Lemberg - - * src/type1/t1parse.c (T1_Get_Private_Dict): Use FT_MEM_MOVE, not - FT_MEM_COPY, for copying the private dict. - - * src/type1/t1load.c (parse_subrs): Assign number of subrs only - in first run. - (parse_charstrings): Parse /CharStrings in second run without - assigning values. - (parse_dict): Skip all /CharStrings arrays but the first. We need - this for non-standard fonts like `Optima' which have different - outlines depending on the resolution. Note that there is no - guarantee that we get fitting /Subrs and /CharStrings arrays; this - can only be done by a real PS interpreter. - -2004-01-29 Antoine Leca - - * builds/win32/visualc/index.html: New file, giving detailed - explanations about forcing CR+LF line endings for the VC++ project - files. - -2004-01-22 Garrick Meeker - - * src/cff/cffload.c (cff_subfont_load): Initialize `dict'. - -2004-01-22 Werner Lemberg - - Add support for the hexadecimal representation of binary data - started with `StartData' in CID-keyed Type 1 fonts. - - * include/freetype/internal/t1types.h (CID_FaceRec): Add new - members `binary_data' and `cid_stream'. - - * src/cid/cidload.c (cid_read_subrs): Use `face->cid_stream'. - (cid_hex_to_binary): New auxiliary function. - (cid_face_open): Add new argument `face_index' to return quickly - if less than zero. Updated all callers. - Call `cid_hex_to_binary', then open and assign memory stream to - `face->cid_stream' if `parser->binary_length' is non-zero. - * src/cid/cidload.h: Updated. - - * src/cid/cidobjs.c (cid_face_done): Free `binary_data' and - `cid_stream'. - - * src/cid/cidparse.c (cid_parser_new): Check arguments to - `StartData' and set parser->binary_length accordingly. - * src/cid/cidparse.h (CID_Parser): New member `binary_length'. - - * src/cid/cidgload.c (cid_load_glyph): Use `face->cid_stream'. - - * docs/CHANGES: Updated. - -2004-01-21 Werner Lemberg - - include/freetype/config/ftstdlib.h (ft_atoi): Replaced with... - (ft_atol): This. - * src/base/ftdbgmem.c: s/atol/ft_atol/. - * src/type42/t42drivr.c: s/ft_atoi/ft_atol/. - -2004-01-20 Masatake YAMATO - - * include/freetype/ftcache.h: Delete duplicated definition of - FTC_FaceID. - - * src/cff/cffdrivr.c (cff_get_cmap_info): Call sfnt module's TT CMap - Info service function if the cmap comes from sfnt. Return 0 if the - cmap is synthesized in cff module. - -2004-01-20 David Turner - - * src/cache/ftcmanag.c (ftc_size_node_compare): Call - FT_Activate_Size. - -2004-01-20 Werner Lemberg - - * src/type1/t1parse.c (T1_Get_Private_Dict): Skip exactly one - CR, LF, or CR/LF after `eexec'. - -2004-01-18 David Turner - - * src/sfnt/ttsbit.c (tt_face_set_sbit_strike): Remove compiler - warning. - - * src/tools/docmaker/*: Updating beautifier tool. - -2004-01-15 David Turner - - * src/base/ftoutln.c (ft_orientation_extremum_compute): Fix - infinite loop bug. - - * include/freetype/ftstroke.h: Include FT_GLYPH_H. - (FT_Stroker_Rewind, FT_Glyph_Stroke, FT_Glyph_StrokeBorder): New - declarations. - - * src/base/ftstroke.c: Include FT_INTERNAL_OBJECTS_H. - (FT_Outline_GetOutsideBorder): Inverse result. - (FT_Stroker_Rewind, FT_Glyph_Stroke, FT_Glyph_StrokeBorder): New - functions. - (FT_Stroker_EndSubPath): Close path if needed. - (FT_Stroker_Set, FT_Stroker_ParseOutline): Use FT_Stroker_Rewind. - - * include/freetype/cache/ftcmanag.h (FTC_ScalerRec, - FTC_Manager_LookupSize): Moved to... - * include/freetype/ftcache.h (FTC_ScalerRec, - FTC_Manager_LookupSize): Here. - - * src/tools/docmaker/docbeauty.py: New file to beautify the - documentation comments (e.g., to convert them to single block border - mode). - * src/tools/docmaker/docmaker.py (file_exists, make_file_list): - Moved to... - * src/tools/docmaker/utils.py (file_exists, make_file_list): Here. - -2004-01-14 David Turner - - * include/freetype/internal/ftmemory.h (FT_ARRAY_COPY, - FT_ARRAY_MOVE): New macros to make copying arrays easier. - Updated all relevant code to use them. - -2004-01-14 Werner Lemberg - - * src/cff/cffload.c (cff_font_load): Load charstrings_index earlier. - Use number of charstrings as argument to CFF_Load_FD_Select (as - documented in the CFF specs). - -2004-01-13 Graham Asher - - * src/pshinter/pshalgo.c (psh_glyph_init): Move assignment of - `glyph->memory' up to free arrays properly in case of failure. - -2004-01-10 Masatake YAMATO - - Make `FT_Get_CMap_Language_ID' work with CFF. Bug reported by - Steve Hartwell . - - * src/cff/cffdrivr.c: Include FT_SERVICE_TT_CMAP_H. - (cff_services): Added an entry for FT_SERVICE_ID_TT_CMAP. - (cff_get_cmap_info): New function. - (cff_service_get_cmap_info) New entry for cff_services. - - * src/sfnt/ttcmap0.c: Exit loop after a format match has been found. - Suggested by Steve Hartwell . - -2004-01-03 Masatake YAMATO - - * src/base/ftobjs.c (destroy_charmaps): New function. - (destroy_face, open_face): Use `destroy_charmaps'. - -2004-01-01 Werner Lemberg - - * docs/CHANGES: Updated. - -2004-01-01 Michael Jansson - - * src/winfonts/winfnt.c (FNT_Size_Set_Pixels): Fix sign of - size->metrics.descender. - -2003-12-31 Wolfgang Domröse - - * src/cff/cffgload.c (cff_decoder_parse_charstrings) - [FT_DEBUG_LEVEL_TRACE]: Use `%ld' in FT_TRACE4. - : Change type of dx and dy to FT_Pos and remove - cast for accessing arguments. - -2003-12-31 Werner Lemberg - - * src/truetype/ttgload.c (TT_Load_Simple_Glyph): Revert previous - change. It's not necessary. - -2003-12-29 Smith Charles - - * src/truetype/ttgload.c (TT_Load_Simple_Glyph): Handle `repeated - flags set' correctly. - -2003-12-29 Werner Lemberg - - * src/cff/cffobjs.c (cff_face_init): Fix memory leak by deallocating - `full' and `weight' properly. - * src/cff/cffgload.c (cff_decoder_parse_charstrings) - [FT_DEBUG_LEVEL_TRACE]: Use `0x' as prefix for - tracing output. - -2003-12-26 Werner Lemberg - - * include/freetype/internal/sfnt.h (TT_Set_SBit_Strike_Func): - Use FT_UInt for ppem values. - * src/sfnt/ttsbit.c (tt_face_set_sbit_strike): Use FT_UInt for - ppem values. - * src/sfnt/ttsbit.h: Updated. - - * src/base/ftobjs.c (FT_Set_Pixel_Sizes): Don't allow ppem values - larger than -0FFFF. - -2003-12-25 Werner Lemberg - - * src/base/fttrigon.c, src/base/ftgloadr.c: Include - FT_INTERNAL_OBJECTS_H. - - * src/base/ftstroke.c (FT_Outline_GetInsideBorder, - FT_Outline_GetOutsideBorder): s/or/o/ to make it compile with - C++ compilers. - - * src/cache/ftcmru.c, include/freetype/cache/ftcmru.h: - s/select/selection/ to avoid compiler warning. - * src/cff/cffload.h: s/select/ftselect/ to avoid potential - compiler warning. - -2003-12-24 Werner Lemberg - - * src/cache/ftcsbits.c (FTC_SNode_Weight): - s/FTC_SBIT_ITEM_PER_NODE/FTC_SBIT_ITEMS_PER_NODE/. - -2003-12-24 David Turner - - * Fixed compilation problems in the cache sub-system. - - * Partial updates to src/autofit. - - * Jamfile (FT2_COMPONENTS): Add autofit module. - -2003-12-23 Werner Lemberg - - * src/cff/cffgload.c (cff_lookup_glyph_by_stdcharcode): Handle - CID-keyed fonts. - -2003-12-23 David Turner - - * include/freetype/internal/ftobjs.h (FT_PAD_FLOOR, FT_PAD_ROUND, - FT_PAD_CEIL, FT_PIX_FLOOR, FT_PIX_ROUND, FT_PIX_CEIL): New macros. - They are used to avoid compiler warnings with very pedantic compilers. - Note that `(x) & -64' causes a warning if (x) is not signed. Use - `(x) & ~63' instead! - Updated all related code. - - Add support for extraction of `inside' and `outside' borders. - - * src/base/ftstroke.c (FT_StrokerBorder): New enumeration. - (FT_Outline_GetInsideBorder, FT_Outline_GetOutsideBorder, - FT_Stroker_GetBorderCounts, FT_Stroker_ExportBorder): New functions. - (FT_StrokeBorderRec): New boolean member `valid'. - (ft_stroke_border_get_counts): Updated. - * include/freetype/ftstroke.h: Updated. - -2003-12-22 Werner Lemberg - - * include/freetype/ftwinfnt.h (FT_WinFNT_ID_*): New definitions - to describe the `charset' field in FT_WinFNT_HeaderRec. - * src/winfonts/winfnt.c (FNT_Face_Init): Set encoding to - FT_ENCODING_NONE except for FT_WinFNT_ID_MAC. - - * include/freetype/freetype.h (FT_Encoding): Improve comment, - based on work by Detlef Würkner . - - * docs/CHANGES: Updated. - -2003-12-22 David Turner - - * include/freetype/ftcache.h, - include/freetype/cache/ftcmanag.h, - include/freetype/cache/ftccache.h, - include/freetype/cache/ftcmanag.h, - include/freetype/cache/ftcmru.h (added), - include/freetype/cache/ftlru.h (removed), - include/freetype/cache/ftcsbits.h, - include/freetype/cache/ftcimage.h, - include/freetype/cache/ftcglyph.h, - src/cache/ftcmru.c, - src/cache/ftcmanag.c, - src/cache/ftccache.c, - src/cache/ftcglyph.c, - src/cache/ftcimage.c, - src/cache/ftcsbits.c, - src/cache/ftccmap.c, - src/cache/ftcbasic.c (added), - src/cache/ftlru.c (removed): - - *Complete* rewrite of the cache sub-system to `solve' the - following points: - - - all public APIs have been moved to FT_CACHE_H, everything - under `include/freetype/cache' is only needed by client - applications that want to implement their own caches - - - a new function named FTC_Manager_RemoveFaceID to deal - with the uninstallation of FaceIDs - - - the image and sbit cache are now abstract classes, that - can be extended much more easily by client applications - - - better performance in certain areas. Further optimizations - to come shortly anyway... - - - the FTC_CMapCache_Lookup function has changed its signature, - charmaps can now only be retrieved by index - - - FTC_Manager_Lookup_Face => FTC_Manager_LookupFace - FTC_Manager_Lookup_Size => FTC_Manager_LookupSize (still in - private header for the moment) - -2003-12-21 Werner Lemberg - - * src/type1/t1load.c (parse_dict): Stop parsing if `eexec' keyword - is encountered. - -2003-12-19 Werner Lemberg - - * src/cff/cfftypes.h (CFF_MAX_CID_FONTS): Increase to 32. For - example, the Japanese Hiragino font already contains 15 subfonts. - - * src/cff/cffload.c (cff_font_load): Deallocate `sids' array for - CID-keyed fonts. - - * devel/ftoption.h: Define FT_DEBUG_MEMORY. - -2003-12-18 Werner Lemberg - - * include/freetype/ttnameid.h (TT_ADOBE_ID_LATIN_1): New macro. - * src/type1/t1objs.c (T1_Face_Init): Use TT_ADOBE_ID* values. - -2003-12-18 Werner Lemberg - - * src/cff/cfftypes.h (CFF_FontRecDictRec): Change type of - `cid_count' to `FT_ULong'. - - * src/cff/cffgload.c (cff_slot_load): Take care of empty `cids' - array. - - * src/cff/cffload.c (cff_charset_done): Free `cids' array. - (cff_font_load): Create cids array only for CID-keyed fonts which - are subsetted. - - * src/cff/cffobjs.c (cff_face_init): Check the availability of - the PSNames modules for non-pure CFFs also. - Set FT_FACE_FLAG_GLYPH_NAMES for a non-pure CFF also if it isn't - CID-keyed. - - * src/cff/rules.mk (CFF_DRV_H): Add cfftypes.h. - -2003-12-17 Werner Lemberg - - * src/sfnt/sfobjs.c (sfnt_init_face): Don't set - FT_FACE_FLAG_GLYPH_NAMES if the font contains a version 3.0 `post' - table. - - * docs/CHANGES: Updated. - -2003-12-17 Masatake YAMATO - - Add new function FT_Get_CMap_Language_ID to extract the language ID - for TrueType/sfnt fonts. - - * include/freetype/internal/services/svttcmap.h: New file. - * include/freetype/internal/ftserv.h (FT_SERVICE_TT_CMAP_H): Add - svttcmap.h. - - * src/sfnt/sfdriver.c: Include ttcmap0.h. - (tt_service_get_cmap_info): New service. - (sfnt_services): Updated. - - * src/sfnt/ttcmap0.c (tt_cmap*_get_info): New functions. - (tt_cmap*_class_rec): Add tt_cmap*_get_info members. - (tt_get_cmap_info): New function. - * src/sfnt/ttcmap0.h: Include FT_SERVICE_TT_CMAP_H. - (TT_CMap_ClassRec): New field `get_cmap_info'. - (tt_get_cmap_info): New declaration. - - * src/base/ftobjs.c: Include FT_SERVICE_TT_CMAP_H. - (FT_Get_CMap_Language_ID): New function implementation. - * include/freetype/tttables.h (FT_Get_CMap_Language_ID): New - function declaration. - -2003-12-16 Werner Lemberg - - * src/sfnt/ttcmap.c, src/sfnt/ttcmap.h: Removed. Obsolete. - - * include/freetype/internal/sfnt.h (SFNT_Interface): Remove - obsolete fields `load_charmap' and `free_charmap'. - (TT_CharMap_Load_Func, TT_CharMap_Free_Func): Removed. - * src/sfnt/sfnt.c: Don't include ttcmap.c. - * src/sfnt/rules.mk (SFNT_DRV_SRC): Don't include ttcmap.c. - * src/sfnt/ttload.c: Don't include ttcmap.h. - * src/sfnt/sfdriver.c: Don't include ttcmap.h. - (sfnt_interface): Updated. - - * include/freetype/internal/tttypes.h (TT_TableDirRec, - TT_CMapDirRec, TT_CMapDirEntryRec, TT_CMap0, TT_CMap2SubHeaderRec, - TT_CMap2Rec, TT_CMap4Segment, TT_CMap4Rec, TT_CMap6, - TT_CMapGroupRec, TT_CMap8_12Rec, TT_CMap10Rec, TT_CharMap_Func, - TT_CharNext_Func, TT_CMapTableRec, TT_CharMapRec): Removed. - Obsolete. - * src/cff/cffobjs.h (CFF_CharMapRec): Removed. Obsolete. - -2003-12-15 Werner Lemberg - - * docs/CHANGES: Updated. - -2003-12-15 Wolfgang Domröse - - * builds/atari/*: New directory for building FreeType 2 on Atari - with the PureC compiler. - -2003-12-12 Wolfgang Domröse - - * src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Add - cast. - * src/cff/cffdrivr.c (cff_ps_has_glyph_names): Assure that return - value is either 0 or 1. - -2003-12-12 Werner Lemberg - - * src/cff/cffdrivr.c (cff_get_glyph_name): Improve error message. - (cff_get_name_index): Return if no PSNames service is available. - (cff_ps_has_glyph_names): Handle CID-keyed fonts correctly. - * src/cff/cfftypes.h (CFF_CharsetRec): New field `cids', used for - CID-keyed fonts. This is the inverse mapping of `sids'. - * src/cff/cffload.c (cff_charset_load): New argument `invert'. - Initialize charset->cids if `invert' is set. - (cff_font_load): In call to cff_charset_load, set `invert' to true - for CID-keyed fonts. - * src/cff/cffgload.c (cff_slot_load): Handle glyph index as CID - and map it to the real glyph index. - - * docs/CHANGES: Updated. - -2003-12-11 Werner Lemberg - - * src/cff/cffobjs.c (cff_face_init): Don't set - FT_FACE_FLAG_GLYPH_NAMES for CID-keyed fonts. - Don't construct a cmap for CID-keyed fonts. - -2003-12-10 Werner Lemberg - - Use implementation specific SID value 0xFFFF to indicate that - a dictionary element is missing. - - * src/cff/cffload.c (cff_subfont_load): Initialize all fields - which hold SIDs to 0xFFFF. - (cff_index_get_sid_string): Handle SID value 0xFFFF. - Handle case where `psnames' is zero. - (cff_font_load): Updated. - Don't load encoding for CID-keyed CFFs. - - * src/cff/cffobjs.c (cff_face_init): Updated. - Don't check for PSNames module if font is CID-keyed. - Compute style name properly (using the same algorithm as in the - CID driver). - Fix computation of style flags. - - * src/cff/cfftoken.h: Comment out handling of base_font_name. - Rename `postscript' field to `embedded_postscript' - * src/cff/cfftypes.h (CFF_FontRecDictRec): Remove `base_font_name' - and `postscript'. - -2003-12-10 Detlef Würkner - - * src/pcf/pcfdrivr.c (pcf_get_charset_id): New function (a clone - of the similar BDF function). - (pcf_service_bdf): Use it. - -2003-12-09 Werner Lemberg - - * src/sfnt/sfobjs.c (sfnt_load_face): Set FT_FACE_FLAG_GLYPH_NAMES - only if a `post' table is present. - -2003-12-09 George Williams - - * src/base/ftobjs.c (load_mac_face): Recent versions of Linux - support Mac's HFS+ file system, thus enable code to read /rsrc on - non-Macintosh platforms also. - -2003-12-08 Werner Lemberg - - * include/freetype/internal/psaux.h (PS_TableRec): Change type - of `lengths' to FT_PtrDist. - (T1_DecoderRec): Change type of `subrs_len' to FT_PtrDist. - * include/freetype/internal/t1types.h (T1_FontRec): Change type - of `subrs_len' and `charstrings_len' to FT_PtrDist. - - * src/base/ftobjs.c (Mac_Read_POST_Resource): Replace `junk' - variable with better solution. - (IsMacResource): Remove unused variable `map_len'. - Replace `junk' variable with better solution. - (FT_Open_Face) [!FT_MACINTOSH]: Add conditional - FT_CONFIG_OPTION_MAC_FONTS. - -2003-12-08 Wolfgang Domröse - - * src/autohint/ahhint.c (ah_hinter_hint_edges, - ah_hinter_align_strong_points): Add some casts. - - * src/base/ftoutln.c (FT_OrientationExtremumRec): Change type - of `pos' to FT_Long. - - * src/base/ftobjs.c (Mac_Read_POST_Resource, - Mac_Read_sfnt_Resource): Change type of `len' to FT_Long. - - * src/type42/t42parse.c (t42_parse_dict): Add cast for `n_keywords'. - -2003-12-07 Werner Lemberg - - * docs/raster.txt: New file, taken from FreeType 1 and completely - revised. - -2003-12-04 Masatake YAMATO - - * src/type1/t1driver.c (Get_Interface): Remove FT_UNUSED for - t1_interface. t1_interface is used. - -2003-11-27 David Turner - - * src/pfr/pfrdrivr.c (pfr_get_metrics): Revert incorrect change of - 2003-11-23: For PFR fonts, metrics->x_scale and metrics->y_scale are - the scaling values for outline units, not for metric units. - -2003-11-25 Werner Lemberg - - * src/base/ftcalc.c, include/freetype/internal/ftcalc.h - (FT_MulDiv_No_Round): Surround code with `#ifdef - TT_CONFIG_OPTION_BYTECODE_INTERPRETER ... #endif'. - -2003-11-23 Werner Lemberg - - * src/base/ftcalc.c (FT_MulDiv_No_Round): New function (32 and - 64 bit version). - * include/freetype/internal/ftcalc.h: Updated. - - * src/truetype/ttinterp.c (TT_MULDIV_NO_ROUND): New macro. - (TT_INT64): Removed. - (DO_DIV): Use TT_MULDIV_NO_ROUND. - - * src/pfr/pfrdrivr.c (pfr_get_metrics): Directly use - metrics->x_scale and metrics->y_scale. - -2003-11-22 Rogier van Dalen - - * src/truetype/ttinterp.c (CUR_Func_move_orig): New macro. - (Direct_Move_Orig, Direct_Move_Orig_X, Direct_Move_Orig_Y): New - functions. Similar to Direct_Move, Direct_Move_X, and - Direct_Move_Y but without touching. - (Compute_Funcs): Use new functions. - - (Round_None, Round_To_Grid, Round_To_Half_Grid, Round_Down_To_Grid, - Round_Up_To_Grid, Round_To_Double_Grid, Round_Super, - Round_Super_45): Fix rounding of value zero. - - (DO_DIV): Don't use TT_MULDIV. - - (Ins_SHC): This instruction actually touches the points. - (Ins_MSIRP): Fix undocumented behaviour. - - * src/truetype/ttinterp.h (TT_ExecContextRec): Updated. - -2003-11-22 Werner Lemberg - - * docs/VERSION.DLL, docs/CHANGES: Updated. - - * src/base/ftobjs.c (FT_Set_Char_Size): Make metrics->x_scale and - metrics->y_scale really precise. - - (FT_Load_Glyph): Update computation of linearHoriAdvance and - linearVertAdvance. - - * src/truetype/ttinterp.c (Update_Max): Use FT_REALLOC. - -2003-11-22 David Turner - - * src/autofit/*: More updates. - - * include/freetype/freetype.h (FREETYPE_PATCH): Set to 8. - * builds/unix/configure.ac (version_info): Set to 9:6:3. - * README: Updated. - -2003-11-13 John A. Boyd Jr. - - * src/bdf/bdfdrivr.c (bdf_interpret_style), src/pcf/pcfread.c - (pcf_interpret_style): Replace spaces with dashes in properties - SETWIDTH_NAME and ADD_STYLE_NAME to simplify parsing. - -2003-11-11 Werner Lemberg - - * docs/CHANGES: Updated. - -2003-11-11 John A. Boyd Jr. - - Handle SETWIDTH_NAME and ADD_STYLE_NAME properties for BDF and PCF - fonts. - - * src/bdf/bdfdrivr.c (bdf_interpret_style): New auxiliary function. - (BDF_Face_Init): Don't handle style properties but call - bdf_interpret_style. - - * src/pcf/pcfread.c (pcf_interpret_style): New auxiliary function. - (pcf_load_font): Don't handle style properties but call - pcf_interpret_style. - -2003-11-07 Werner Lemberg - - - * Version 2.1.7 released. - ========================= - - - * include/freetype/freetype.h (FREETYPE_PATCH): Set to 7. - - * builds/unix/ft2unix.h: Fix comments. - - * builds/unix/ftconfig.in: Synchronized with ANSI version. - Use `#undef' in templates as recommended in the autoconf - documentation. - Since real `#undef' lines don't survive during configuration, use - `/undef' instead; the postprocessing facility of the - AC_CONFIG_HEADERS autoconf macro converts them to `#undef'. - - * builds/unix/install.mk (install): Install Unix version of - `ftconfig.h'. - - * builds/unix/unix-cc.in (CFLAGS): Set FT_CONFIG_CONFIG_H macro - to include the correct `ftconfig.h' file. - - * builds/unix/ft-munmap.m4 (FT_MUNMAP_DECL): Removed. - (FT_MUNMAP_PARAM): Updated syntax to autoconf 2.59. - - * builds/unix/freetype2.m4: Updated syntax to autoconf 2.59. - - * builds/unix/configure.ac: Use AC_CONFIG_HEADERS instead of - AC_CONFIG_HEADER to create ftconfig.h, and use second argument - to replace `/undef' with `#undef'. - Don't use FT_MUNMAP_DECL but AC_CHECK_DECLS to check for munmap. - Use AS_HELP_STRING in AC_ARG_WITH. - Update syntax to autoconf 2.59. - - * builds/unix/ltmain.sh: Regenerated with `libtoolize --force - --copy' from libtool 1.5. - * builds/unix/aclocal.m4: Regenerated with `aclocal -I .' from - automake 1.7.8. - * builds/unix/configure: Regenerated with autoconf 2.59. - * builds/unix/config.guess, builds/unix/config.sub: Updated from - `config' CVS module at subversions.gnu.org - * builds/unix/install-sh, builds/unix/mkinstalldirs: Updated from - `texinfo' CVS module at subversions.gnu.org. - - * builds/vms/ftconfig.h: Synchronized with ANSI version. - - * docs/CUSTOMIZE: Fix documentation error. - * docs/CHANGES, docs/VERSION.DLL, docs/release: Updated. - - * builds/freetype.mk (refdoc): Updated --title. - -2003-11-07 David Turner - - - * Version 2.1.6 released. - ========================= - - - * install: Removed. Obsolete. - -2003-11-04 Werner Lemberg - - * src/sfnt/sfdriver.c: Include FT_SERVICE_SFNT_H. - (sfnt_service_sfnt_table): New service. - (sfnt_services): Updated. - - * docs/license.txt: Reworded. - -2003-11-03 Werner Lemberg - - * include/freetype/*: Add a guard to all public header files which - load FT_FREETYPE_H to reject freetype.h from FreeType 1. - -2003-11-02 Patrick Welche - - * builds/unix/freetype2.m4, builds/unix/ft-munmap.m4: Protect - first argument of AC_DEFUN with brackets to avoid possible - expansion. - -2003-11-02 Werner Lemberg - - * include/freetype/cache/ftcglyph.h: Don't include stddef.h. - - * include/freetype/freetype.h: Fix check for ft2build.h. - -2003-11-01 Werner Lemberg - - * include/freetype/freetype.h: Check that ft2build.h has been - loaded first. - - * src/base/fttype1.c (FT_Get_PS_Font_Info): Fix incorrectly applied - patch. - -2003-10-31 Detlef Würkner - - * src/base/fttype1.c (FT_Get_PS_Font_Info, FT_Has_PS_Glyph_Names): - Fix parameter order in calls to FT_FACE_FIND_SERVICE. - -2003-10-31 Werner Lemberg - - * include/freetype/internal/ftserv.h - (FT_SERVICE_POSTSCRIPT_NAMES_H): Removed. Unused. - - * src/type42/t42drivr.c (t42_services): Updated. - -2003-10-29 David Turner - - * include/freetype/internal/bdftypes.h: Removed. Obsolete. - * src/base/ftbdf.c: Updated. - - * include/freetype/internal/cfftypes.h: Moved to... - * src/cff/cfftypes.h: This place since no other module needs to - know about those types. - - * include/freetype/internal/t42types.h: Moved to... - * src/type42/t42types.h: This place since no other module needs to - know about those types. - - * include/freetype/internal/services/svbdf.h: Include FT_BDF_H. - - * include/freetype/internal/services/svpsname.h: Renamed to... - * include/freetype/internal/services/svpscmap.h: This. - Updated `FT_Service_PsNames' -> `FT_Service_PsCMaps' and - `POSTSCRIPT_NAMES' -> `POSTSCRIPT_CMAPS' everywhere. - - * include/freetype/internal/services/svpsinfo.h: New file, providing - PostScript info service. - - * include/freetype/internal/ftserv.h (FT_SERVICE_POSTSCRIPT_CMAPS_H, - FT_SERVICE_POSTSCRIPT_INFO_H): New macros for svpscmap.h and - svpsinfo.h. - * include/freetype/internal/internal.h (FT_INTERNAL_TYPE42_TYPES_H, - FT_INTERNAL_CFF_TYPES_H, FT_INTERNAL_BDF_TYPES_H): Removed. - - * src/base/fttype1.c: Don't include FT_INTERNAL_TYPE1_TYPES_H and - FT_INTERNAL_TYPE42_TYPES_H but FT_INTERNAL_SERVICE_H and - FT_SERVICE_POSTSCRIPT_INFO_H. - (FT_Get_PS_Font_Info, FT_Has_PS_Glyph_Names): Use new - POSTSCRIPT_INFO service. - - * src/cff/cffdrivr.c: Include FT_SERVICE_POSTSCRIPT_INFO_H. - (cff_ps_has_glyph_names): New function. - (cff_service_ps_info): New service. - (cff_services): Updated. - - * src/cff/cffload.h, src/cff/cffobjs.h, src/cff/cffparse.h: Don't - include FT_INTERNAL_CFF_TYPES_H but cfftypes.h directly. - - * src/cid/cidriver.c: Include FT_SERVICE_POSTSCRIPT_INFO_H. - (cid_ps_get_font_info): New function. - (cid_service_ps_info): New service. - (cid_services): Updated. - - * src/type1/t1driver.c: Include FT_SERVICE_POSTSCRIPT_INFO_H. - (t1_ps_get_font_info, t1_ps_has_glyph_names): New functions. - (t1_service_ps_info): New service. - (t1_services): Updated. - - * src/type42/t42drivr.c: Include FT_SERVICE_POSTSCRIPT_INFO_H. - (t42_ps_get_font_info, t42_ps_has_glyph_names): New functions. - (t42_service_ps_info): New service. - - * src/type42/t42objs.h: Don't include FT_INTERNAL_TYPE42_TYPES_H - but t42types.h directly. - - * src/psnames/psmodule.c (psnames_interface, psnames_services): - Renamed to... - (pscmaps_interface, pscmaps_services): This. - Updated all users. - - - * src/gzip/infblock.c (inflate_blocks): Remove compiler warning. - -2003-10-22 Werner Lemberg - - * src/type1/t1load.c (parse_encoding): Handle `/Encoding [ ... ]'. - - * src/type1/t1parse.c (T1_Get_Private_Dict): Test whether `eexec' - is real. - - * src/type42/t42parse.c (t42_parse_encoding): Improve boundary - checking while parsing. - - * docs/CHANGES: Updated. - -2003-10-21 Josselin Mouette - - * include/freetype/internal/t1types.h (T1_FontRec): `paint_type' - and `stroke_width' aren't pointers. - - * src/type42/t42objs.c (T42_Face_Done), src/type1/t1objs.c - (T1_Face_Done): Don't free `paint_type' and `stroke_width'. - -2003-10-20 Graham Asher - - * src/winfonts/winfnt.c (fnt_cmap_class): Fix position of `const'. - -2003-10-19 Werner Lemberg - - * src/autohint/ahhint.c (ah_hinter_load_glyph): Patch from - 2003-08-18 introduced a severe bug (FT_Render_Glyph was called - twice under some circumstances, causing strange results). This - is fixed now by clearing the FT_LOAD_RENDER bit of `load_flags'. - - * src/base/ftpfr.c (FT_Get_PFR_Metrics): Initialize `error'. - * src/psaux/psobjs.c (ps_tobytes): Initialize `n'. - * src/type42/t42parse.c (t42_parse_sfnts): Initialize `string_size'. - -2003-10-16 Werner Lemberg - - Completely revised Type 42 parser. It now handles both fonts - produced with ttftot42 (tested version 0.3.1) and - TrueTypeToType42.ps (tested version May 2001; it is necessary to - fix the broken header comment to be `%!PS-TrueTypeFont...'). - - * src/type42/t42objs.c (T42_GlyphSlot_Load): Change fourth - parameter to `FT_UInt'. - * src/type42/t42objs.h: Updated. - - * src/type42/t42parse.h (T42_ParserRec): Change type of `in_memory' - to FT_Bool. - (T42_Loader): Change type of `num_chars' and `num_glyphs' to - FT_UInt. - Add `swap_table' element. - * src/type42/t42parse.c (T42_KEYWORD_COUNT, T1_ToFixed, - T1_ToCoordArray, T1_ToTokenArray): Removed. - (T1_ToBytes): New macro. - (t42_is_alpha, t42_hexval): Removed. - (t42_is_space): Handle `\0'. - (t42_parse_encoding): Updated to use new PostScript parser routines - from psaux. - Handle `/Encoding [ ... ]' also. - (T42_Load_Status): New enumeration. - (t42_parse_sfnts): Updated to use new PostScript parser routines - from psaux. - (t42_parse_charstrings): Updated to use new PostScript parser - routines from psaux. - Handle `/CharStrings << ... >>' also. - Don't expect that /.notdef is the first element in dictionary. Copy - code from type1 module to handle this. - (t42_parse_dict): Updated to use new PostScript parser routines - from psaux. - Remove code for synthetic fonts (which can't occur in Type 42 - fonts). - (t42_loader_done): Release `swap_table'. - - * src/psaux/psobjs.c (skip_string): Increase `cur' properly. - - * src/type1/t1load.c (parse_charstrings): Make test for `.notdef' - faster. - -2003-10-15 Graham Asher - - * src/autohint/ahglobal.c (blue_chars), src/winfonts/winfnt.c - (fnt_cmap_class_rec, fnt_cmap_class), src/bdf/bdflib.c (empty, - _num_bdf_properties), src/gzip/infutil.c (inflate_mask), - src/gzip/inffixed.h (fixed_bl, fixed_bd, fixed_tl, fixed_td), - src/gzip/inftrees.h (inflate_trees_fixed), src/gzip/inftrees.c - (inflate_trees_fixed): Decorate with more `const' to avoid - writable global variables which are disallowed on ARM. - -2003-10-08 Werner Lemberg - - * src/type1/t1load.c (parse_font_matrix, parse_charstrings): Remove - code specially for synthetic fonts; this is handled elsewhere. - (parse_encoding): Remove code specially for synthetic fonts; this is - handled elsewhere. - Improve boundary checking while parsing. - (parse_dict): Improve boundary checking while parsing. - Use ft_memcmp to simplify code. - -2003-10-07 Werner Lemberg - - * src/type1/t1load.c (parse_subrs, parse_dict): Handle synthetic - fonts properly. - (parse_charstrings): Copy correct number of characters into - `name_table'. - -2003-10-06 Werner Lemberg - - Heavy modification of the PS parser to handle comments and strings - correctly. This doesn't slow down the loading of PS fonts - significantly since charstrings aren't affected. - - * include/freetype/config/ftstdlib.h (ft_xdigit): Renamed to... - (ft_isxdigit): This. Updated all callers. - (ft_isdigit): New alias to `isdigit'. - - * include/freetype/internal/psaux.h (PS_Parser_FuncsRec): Renamed - `skip_alpha' to `skip_PS_token'. - Add parameter to `to_bytes' and change some argument types. - - * src/psaux/psauxmod.c (ps_parser_funcs): Updated. - * src/psaux/psobjs.c (ft_char_table): New array to map character - codes (ASCII and EBCDIC) of digits to numbers. - (OP): New auxiliary macro holding either `>=' or `<' depending on - the character encoding. - (skip_comment): New function. - (skip_spaces): Use it. - (skip_alpha): Removed. - (skip_literal_string, skip_string): New functions. - (ps_parser_skip_PS_token): New function. This is a better - replacement of... - (ps_parser_skip_alpha): Removed. - (ps_parser_to_token, ps_parser_to_token_array): Updated. - (T1Radix): Rewritten, using `ft_char_table'. - (t1_toint): Renamed to... - (ps_toint): This. Update all callers. - Use `ft_char_table'. - (ps_tobytes): Add parameter to handle delimiters and change some - argument types. - Use `ft_char_table'. - (t1_tofixed): Renamed to... - (ps_tofixed): This. Update all callers. - Use `ft_char_table'. - (t1_tocoordarray): Renamed and updated to... - (ps_tocoordarray): This. Update all callers. - (t1_tofixedarray): Renamed and updated to... - (ps_tofixedarray): This. Update all callers. - (t1_tobool): Renamed to... - (ps_tobool): This. Update all callers. - (ps_parser_load_field): Updated. - (ps_parser_load_field_table): Use `T1_MAX_TABLE_ELEMENTS' - everywhere. - (ps_parser_to_int, ps_parser_to_fixed, ps_parser_to_coord_array, - ps_parser_to_fixed_array): Skip spaces. Updated. - (ps_parser_to_bytes): Add parameter to handle delimiters and change - some argument types. Updated. - * src/psaux/psobjs.h: Updated. - - * src/cid/cidload.c (cid_parse_dict): Updated. - * src/cid/cidparse.c (cid_parser_new): Check whether the `StartData' - token was really found. - * src/cid/cidparse.h (cid_parser_skip_alpha): Updated and renamed - to... - (cid_parser_skip_PS_token): This. - - * src/type1/t1parse.h (T1_ParserRec): Use `FT_Bool' for boolean - fields. - (T1_Skip_Alpha): Replaced with... - (T1_Skip_PS_Token): This new macro. - * src/type1/t1parse.c (hexa_value): Removed. - (T1_Get_Private_Dict): Use `ft_isxdigit' and - `psaux->ps_parser_funcs_to_bytes' for handling ASCII hexadecimal - encoding. - After decrypting, replace the four random bytes at the beginning - with whitespace. - * src/type1/t1load.c (t1_allocate_blend): Use proper error values. - (parser_blend_design_positions, parse_blend_design_map, - parse_weight_vector): Updated. - (is_space): Handle `\f' also. - (is_name_char): Removed. - (read_binary_data): Updated. - (parse_encoding): Use `ft_isdigit'. - Updated. - (parse_subrs): Updated. - (TABLE_EXTEND): New macro. - (parse_charstrings): Updated. - Provide a workaround for buggy fonts which have more entries in the - /CharStrings dictionary then expected; the function now adds some - slots and skips entries which still exceed the new limit. - (parse_dict): Updated. - Terminate on the token `closefile'. - - * src/type42/t42parse.c (T1_Skip_Alpha): Replaced with... - (T1_Skip_PS_Token): This new macro. Updated all callers. - (t42_parse_encoding): Use `ft_isdigit'. - - - * src/base/ftmm.c (ft_face_get_mm_service): Return FT_Err_Ok if - success. - -2003-10-05 Werner Lemberg - - * include/freetype/ftmodule.h: Renamed to... - * include/freetype/ftmodapi.h: This to avoid duplicate file names. - * include/freetype/config/ftheader.h (FT_MODULE_H): Updated. - -2003-10-04 Werner Lemberg - - * src/base/ftoutln.c (FT_OrientationExtremumRec, - FT_Outline_Get_Orientation): Trivial typo fixes to make it compile. - -2003-10-02 Markus F.X.J. Oberhumer - - * src/winfonts/winfnt.c (FT_WinFNT_HeaderRec): `color_table_offset' - has four bytes, not two. - Fix all users. - (fnt_font_load, FNT_Load_Glyph): Add more font validity tests. - -2003-10-01 David Turner - - * src/autofit/*: Adding first source files of the new multi-script - `auto-fitter'. - - * include/freetype/ftoutln.h (FT_Orientation): New enumeration. - (FT_Outline_Get_Orientation): New declaration. - - * src/base/ftoutln.c (FT_OrientationExtremumRec): New structure. - (ft_orientation_extremum_compute): New auxiliary function. - (FT_Outline_Get_Orientation): New function to compute the fill - orientation of a given glyph outline. - - * include/freetype/internal/ftserv.h (FT_FACE_LOOKUP_SERVICE): Fixed - trivial bug which could crash the font engine when a cached service - pointer was retrieved. - -2003-09-30 Werner Lemberg - - * src/cid/cidload.c (cid_parse_dict): Skip token if no keyword is - found. - - * src/type1/t1parse.c (IS_T1_WHITESPACE, IS_T1_LINESPACE, - IS_T1_SPACE): Removed. - (PFB_Tag): Removed. - (read_pfb_tag): Don't use PFB_Tag. - - * src/type42/t42parse.c (t42_is_space): Handle `\f' also. - (t42_parse_encoding): Handle synthetic fonts. - -2003-09-29 Werner Lemberg - - * include/freetype/internal/t1types.h: Don't include - FT_INTERNAL_OBJECTS_H but FT_INTERNAL_SERVICE_H. - * src/truetype/ttobjs.c: Don't include - FT_SERVICE_POSTSCRIPT_NAMES_H. - -2003-09-29 David Turner - - Added new service to handle glyph name dictionaries, replacing the - old internal header named `psnames.h' by `services/svpsname.h'. - Note that this is different from `services/svpostnm.h' which only - handles the retrieval of PostScript font names for a given face. - (Should we merge these two services into a single header?) - - * include/freetype/internal/psnames.h: Removed. Most of its - contents is moved to... - * include/freetype/internal/services/svpsname.h: New file. - - * include/freetype/internal/services/svpostnm.h - (FT_SERVICE_ID_POSTSCRIPT_NAME): Replaced with... - (FT_SERVICE_ID_POSTSCRIPT_FONT_NAME): New macro. - (PsName): Service named changed to... - (PsFontName): This. - Updated `FT_Service_PsName' -> `FT_Service_PsFontName' and - `POSTSCRIPT_NAME' -> `POSTSCRIPT_FONT_NAME' everywhere. - - * include/freetype/internal/internal.h - (FT_INTERNAL_POSTSCRIPT_NAMES_H): Removed. - * include/freetype/internal/psaux.h: Include - FT_SERVICE_POSTSCRIPT_NAMES_H. - (T1_DecoderRec): Updated type of `psnames'. - * include/freetype/internal/t1types.h: Don't include - FT_INTERNAL_POSTSCRIPT_NAMES_H but FT_SERVICE_POSTSCRIPT_NAMES_H. - Include FT_INTERNAL_OBJECTS_H. - * include/freetype/internal/t42types.h: Don't include - FT_INTERNAL_POSTSCRIPT_NAMES_H. - * include/freetype/internal/tttypes.h (TT_FaceRec): Updated. - - * include/freetype/internal/ftserv.h (FT_FACE_FIND_SERVICE): Changed - order of parameters. All callers updated. - (FT_FACE_FIND_GLOBAL_SERVICE): New macro to look up a service - globally, checking all modules. - (FT_ServiceCacheRec): Updated. - (FT_SERVICE_POSTSCRIPT_NAMES_H): New macro for accessing - `svpsname.h'. - - * include/freetype/internal/ftobjs.h, src/base/ftobjs.c - (ft_module_get_service): New function. - - * src/cff/cffdrivr.c: Don't include FT_INTERNAL_POSTSCRIPT_NAMES_H - but FT_SERVICE_POSTSCRIPT_NAMES_H. - (cff_get_glyph_name, cff_get_name_index): Use new POSTSCRIPT_NAMES - service. - * src/cff/cffcmap.c (cff_cmap_unicode_init): Updated. - * src/cff/cffload.c, src/cff/cffload.h: Don't include - FT_INTERNAL_POSTSCRIPT_NAMES_H but FT_SERVICE_POSTSCRIPT_NAMES_H. - (cff_index_get_sid_string): Updated. - * src/cff/cffobjs.c: Don't include FT_INTERNAL_POSTSCRIPT_NAMES_H - but FT_SERVICE_POSTSCRIPT_NAMES_H. - (cff_face_init): Use new POSTSCRIPT_NAMES service. - * src/cff/cffobjs.h: Don't include FT_INTERNAL_POSTSCRIPT_NAMES_H - but FT_SERVICE_POSTSCRIPT_NAMES_H. - - * src/cid/cidobjs.c: Don't include FT_INTERNAL_POSTSCRIPT_NAMES_H - but FT_SERVICE_POSTSCRIPT_NAMES_H. - (cid_face_init): Use new POSTSCRIPT_NAMES service. - * src/cid/cidriver.c: Don't include FT_INTERNAL_POSTSCRIPT_NAMES_H. - - * src/psaux/t1cmap.c (t1_cmap_std_init, t1_cmap_unicode_init): Use - new POSTSCRIPT_NAMES service. - * src/psaux/t1decode.h (t1_lookup_glyph_by_stdcharcode, - t1_decode_init): Use new POSTSCRIPT_NAMES service. - * src/psaux/t1cmap.h, src/psaux/t1decode.h: Don't include - FT_INTERNAL_POSTSCRIPT_NAMES_H. - - * src/psnames/psmodule.c: Don't include - FT_INTERNAL_POSTSCRIPT_NAMES_H but FT_SERVICE_POSTSCRIPT_NAMES_H. - (ps_build_unicode_table): Renamed to... - (ps_unicodes_init): This. - (ps_lookup_unicode): Renamed to... - (ps_unicodes_char_index): This. - (ps_next_unicode): Renamed to... - (ps_unicodes_char_next): This. - (psnames_interface): Updated. - (psnames_services): New services list. - (psnames_get_service): New function. - (psnames_module_class): Updated. - - * src/sfnt/sfobjs.c: Don't include FT_INTERNAL_POSTSCRIPT_NAMES_H - but FT_SERVICE_POSTSCRIPT_NAMES_H. - (sfnt_init_face): Use new POSTSCRIPT_NAMES service. - * src/sfnt/ttpost.c: Don't include FT_INTERNAL_POSTSCRIPT_NAMES_H - but FT_SERVICE_POSTSCRIPT_NAMES_H. - (tt_face_get_ps_name): Updated. - - * src/truetype/ttobjs.c: Don't include - FT_INTERNAL_POSTSCRIPT_NAMES_H but FT_SERVICE_POSTSCRIPT_NAMES_H. - - * src/type1/t1driver.c: Don't include - FT_INTERNAL_POSTSCRIPT_NAMES_H but FT_SERVICE_POSTSCRIPT_NAMES_H. - * src/type1/t1objs.c: Don't include - FT_INTERNAL_POSTSCRIPT_NAMES_H but FT_SERVICE_POSTSCRIPT_NAMES_H. - (T1_Face_Init): Use new POSTSCRIPT_NAMES service. - - * src/type42/t42drivr.c (t42_get_ps_name): Renamed to... - (t42_get_ps_font_name): This. - (t42_service_ps_name): Renamed to... - (t42_service_ps_font_name): This. - (t42_services): Updated. - * src/type42/t42objs.c (T42_Face_Init): Use new POSTSCRIPT_NAMES - service. - * src/type42/t42objs.h: Don't include - FT_INTERNAL_POSTSCRIPT_NAMES_H but FT_SERVICE_POSTSCRIPT_NAMES_H. - - - * src/base/ftglyph.c (FT_Get_Glyph): Don't access `slot' before - testing its validity. Reported by Henry Maddocks - . - -2003-09-21 Werner Lemberg - - * include/freetype/internal/ftserv.h (FT_FACE_FIND_SERVICE): - Fix compilation warning (s/pptr/Pptr/). - - * include/freetype/internal/internal.h (FT_INTERNAL_PFR_H, - FT_INTERNAL_FNT_TYPES_H): Removed. - -2003-09-21 David Turner - - Migrating the PFR and WINFNT drivers to the new service-based - internal API. - - * include/freetype/internal/fnttypes.h: Removed. Most of its data - are moved to winfnt.h and... - * include/freetype/internal/services/svwinfnt.h: New file. - - * include/freetype/internal/pfr.h: Removed. Most of its data are - moved to... - * include/freetype/internal/services/svpfr.h: New file. - - * include/freetype/internal/ftserv.h (FT_FACE_FIND_SERVICE, - FT_FACE_LOOKUP_SERVICE): Simplify fix of 2003-09-16 by removing - pointer type argument. - Updated all callers. - Update macro names of services header files. - - * src/base/ftobjs.c (FT_Get_Name_Index): Simplified code. - - * src/base/ftpfr.c: Include FT_SERVICE_PFR_H instead of - FT_INTERNAL_PFR_H. - (ft_pfr_check, FT_Get_PFR_Metrics, FT_Get_PFR_Kerning, - FT_Get_PFR_Advance): Use services provided in `PFR_METRICS'. - - * src/base/ftwinfnt.c: Include FT_SERVICE_WINFNT_H instead of - FT_INTERNAL_FNT_TYPES_H. - (FT_Get_WinFNT_Header): Use service provided in `WINFNT'. - - * src/pfr/pfrdrivr.c: Include FT_SERVICE_PFR_H and - FT_SERVICE_XFREE86_NAME_H instead of FT_INTERNAL_PFR_H. - (pfr_service_bdf): Updated. - (pfr_services): New services list. - (pfr_get_service): New function. - (pfr_driver_class): Updated. - - * src/winfonts/winfnt.c: Include FT_SERVICE_WINFNT_H and - FT_SERVICE_XFREE86_NAME_H instead of FT_INTERNAL_FNT_TYPES_H. - (winfnt_get_header, winfnt_get_service): New functions. - (winfnt_service_rec): New structure providing WINFNT services. - (winfnt_services): New services list. - (winfnt_driver_class): Updated. - * src/winfonts/winfnt.h: Add most of the removed fnttypes.h data. - - * src/sfnt/sfdriver.c (sfnt_service_ps_name): Fix typo. - - * src/type1/t1driver.c (t1_service_ps_name): Fix typo. - - * src/cff/cffobjs.c, src/cid/cidobjs.c, src/pfr/pfrsbit.c, - src/psaux/psobjs.c, src/sfnt/sfobjs.c, src/truetype/ttobjs.c, - src/type1/t1objs.c, src/type42/t42objs.c: Removing various compiler - warnings. - -2003-09-19 David Bevan - - * src/type1/t1parse.c (pfb_tag_fields): Removed. - (read_pfb_tag): Fix code so that it doesn't fail on end-of-file - indicator (0x8003). - * docs/CHANGES: Updated. - -2003-09-16 Werner Lemberg - - * include/freetype/internal/ftserv.h (FT_FACE_FIND_SERVICE, - FT_FACE_LOOKUP_SERVICE): Add parameter to pass pointer type. - Ugly, I know, but this is needed for compilation with C++ -- - maybe someone knows a better solution? - Updated all callers. - - * src/base/ftobjs.c (FT_Get_Name_Index, FT_Get_Glyph_Name): Remove - C++ compiler warnings. - - * src/base/ftbdf.c (FT_Get_BDF_Charset_ID, FT_Get_BDF_Property): - Fix order of arguments passed to FT_FACE_FIND_SERVICE. - -2003-09-15 Werner Lemberg - - Avoid header files with identical names. - - * include/freetype/internal/services/bdf.h: Renamed to... - * include/freetype/internal/services/svbdf.h: This. - Add copyright notice. - * include/freetype/internal/services/glyfdict.h: Renamed to... - * include/freetype/internal/services/svgldict.h: This. - Add copyright notice. - * include/freetype/internal/services/multmast.h: Renamed to... - * include/freetype/internal/services/svmm.h: This. - Add copyright notice. - Add FT_BEGIN_HEADER and FT_END_HEADER. - * include/freetype/internal/services/sfnt.h: Renamed to... - * include/freetype/internal/services/svsfnt.h: This. - Add copyright notice. - * include/freetype/internal/services/postname.h: Renamed to... - * include/freetype/internal/services/svpostnm.h: This. - Add copyright notice. - * include/freetype/internal/services/xf86name.h: Renamed to... - * include/freetype/internal/services/svxf86nm.h: This. - Add copyright notice. - - * include/freetype/internal/ftserv.h: Add FT_BEGIN_HEADER and - FT_END_HEADER. - Add copyright notice. - Update macro names of services header files. - - * builds/freetype.mk (SERVICES_DIR): New variable. - (BASE_H): Add services header files. - -2003-09-11 Werner Lemberg - - * builds/toplevel.mk (distclean): Remove `builds/unix/freetype2.pc'. - - * src/cff/cffdrivr.c: Don't load headers twice. - - * include/freetype/internal/ftserv.h (FT_SERVICE_SFNT_H): New macro. - * src/base/ftobjs.c: Include FT_SERVICE_SFNT_H. - - * src/cff/cffcmap.c: Include `cfferrs.h'. - * src/pfr/pfrdrivr.c: Include `pfrerror.h'. - * src/sfnt/sfdriver.c: Include `sferrors.h'. - * src/psaux/psobjs.h: Add declaration for `ps_parser_to_bytes'. - -2003-09-11 David Turner - - Introducing the concept of `module services'. This is the first - step towards a massive simplification of the engine's internals, in - order to get rid of various numbers of hacks. - - Note that these changes will break source & binary compatibility for - authors of external font drivers. - - * include/freetype/config/ftconfig.h (FT_BEGIN_STMNT, FT_END_STMNT, - FT_DUMMY_STMNT): New macros. - - * include/freetype/internal/ftserv.h: New file, containing the new - structures and macros to provide `services'. - - * include/freetype/internal/internal.h (FT_INTERNAL_EXTENSION_H, - FT_INTERNAL_EXTEND_H, FT_INTERNAL_HASH_H, FT_INTERNAL_OBJECT_H): - Removed, obsolete. - (FT_INTERNAL_SERVICE_H): New macro for `ftserv.h'. - - * include/freetype/internal/services/bdf.h, - include/freetype/internal/services/glyfdict.h, - include/freetype/internal/services/postname.h, - include/freetype/internal/services/xf86name.h: New files. - - * include/freetype/ftmm.h (FT_Get_MM_Func, FT_Set_MM_Design_Func, - FT_Set_MM_Blend_Func): Function pointers moved (in modified form) - to... - * include/freetype/internal/services/multmast.h: New file. - - * include/freetype/internal/sfnt.h (SFNT_Interface): `get_interface' - is now of type `FT_Module_Requester'. - (SFNT_Get_Interface_Func, SFNT_Load_Table_Func): Function pointers - moved (in modified form) to... - * include/freetype/internal/services/sfnt.h: New file. - - * include/freetype/tttables.h (FT_Get_Sfnt_Table_Func): Function - pointer moved (in modified form) to `services/sfnt.h'. - - * include/freetype/ftmodule.h (FT_Module_Interface): Make it a - a typedef to `FT_Pointer'. - - * include/freetype/internal/tttypes.h (TT_FaceRec): Add - `postscript_name'. - * include/freetype/internal/ftobjs.h (FT_Face_InternalRec): Remove - `postscript_name'. - Add `services' element. - (FT_LibraryRec): Remove `meta_class'. - - * src/base/ftbdf.c: Include FT_SERVICE_BDF_H. - (test_font_type): Removed. - (FT_Get_BDF_Charset_ID, FT_Get_BDF_Property): Use services - provided in `FT_SERVICE_ID_BDF'. - - * src/base/ftmm.c: Include FT_SERVICE_MULTIPLE_MASTERS_H. - (ft_face_get_mm_service): New auxiliary function to get services - from `FT_SERVICE_ID_MULTI_MASTERS'. - (FT_Get_Multi_Master, FT_Set_MM_Design_Coordinates, - FT_Set_MM_Blend_Coordinates): Use `ft_face_get_mm_service'. - - * src/base/ftobjs.c: Include FT_SERVICE_POSTSCRIPT_NAME_H and - FT_SERVICE_GLYPH_DICT_H. - (ft_service_list_lookup): New function to get a specific service. - (destroy_face): Updated. - (Mac_Read_POST_Resource): Simplify some code. - (IsMacResource): Fix warnings. - (FT_Get_Name_Index, FT_Get_Glyph_Name): Use services provided in - `FT_SERVICE_ID_GLYPH_DICT'. - (FT_Get_Postscript_Name): Use service provided in - `FT_SERVICE_ID_POSTSCRIPT_NAME'. - (FT_Get_Sfnt_Table, FT_Load_Sfnt_Table): Use services provided in - `FT_SERVICE_ID_SFNT_TABLE'. - - * src/base/ftxf86.c: Include FT_SERVICE_XFREE86_NAME_H. - (FT_Get_X11_Font_Format): Use service provided in - `FT_SERVICE_ID_XF86_NAME'. - - * src/bdf/bdfdrivr.c: Include FT_SERVICE_BDF_H and - FT_SERVICE_XFREE86_NAME_H. - (bdf_get_charset_id): New function. - (bdf_service_bdf): New structure providing BDF services. - (bdf_services): New services list. - (bdf_driver_requester): Use `ft_service_list_lookup'. - - * src/cff/cffdrivr.c: Include FT_SERVICE_XFREE86_NAME_H and - FT_SERVICE_GLYPH_DICT_H. - (cff_service_glyph_dict): New structure providing CFF services. - (cff_services): New services list. - (cff_get_interface): Use `ft_service_list_lookup'. - - * src/cid/cidriver.c: Include FT_SERVICE_POSTSCRIPT_NAME_H and - FT_SERVICE_XFREE86_NAME_H. - (cid_service_ps_name): New structure providing CID services. - (cid_services): New services list. - (cid_get_interface): Use `ft_service_list_lookup'. - - * src/pcf/pcfdrivr.c: Include FT_SERVICE_BDF_H and - FT_SERVICE_XFREE86_NAME_H. - (pcf_service_bdf): New structure providing PCF services. - (pcf_services): New services list. - (pcf_driver_requester): Use `ft_service_list_lookup'. - - * src/sfnt/sfdriver.c: Include FT_SERVICE_GLYPH_DICT_H and - FT_SERVICE_POSTSCRIPT_NAME_H. - (get_sfnt_glyph_name): Renamed to... - (sfnt_get_glyph_name): This. - (get_sfnt_postscript_name): Renamed to... - (sfnt_get_ps_name): This. - Updated. - (sfnt_service_glyph_dict, sfnt_service_ps_name): New structures - providing services. - (sfnt_services): New services list. - (sfnt_get_interface): Use `ft_service_list_lookup'. - - * src/truetype/ttdriver.c: Include FT_SERVICE_XFREE86_NAME_H. - (tt_services): New services list. - (tt_get_interface): Use `ft_service_list_lookup'. - - * src/type1/t1driver.c: Include FT_SERVICE_MULTIPLE_MASTERS_H, - FT_SERVICE_GLYPH_DICT_H, FT_SERVICE_XFREE86_NAME_H, and - FT_SERVICE_POSTSCRIPT_NAME_H. - (t1_service_glyph_dict, t1_service_ps_name, - t1_service_multi_masters): New structures providing Type 1 services. - (t1_services): New services list. - (Get_Interface): Use `ft_service_list_lookup'. - - * src/type42/t42drivr.c: Include FT_SERVICE_XFREE86_NAME_H, - FT_SERVICE_GLYPH_DICT_H, and FT_SERVICE_POSTSCRIPT_NAME_H. - (t42_service_glyph_dict, t42_service_ps_name): New structures - providing Type 42 services. - (t42_services): New services list. - (T42_Get_Interface): Use `ft_service_list_lookup'. - - - * README, docs/CHANGES: Updating version numbers for 2.1.6, and - removing obsolete warnings in the documentation. - * include/freetype/freetype.h (FREETYPE_PATCH): Set to 6. - * builds/unix/configure.ac (version_info): Set to 9:5:3. - * builds/unix/configure: Regenerated. - - * include/freetype/internal/ftcore.h, - include/freetype/internal/ftexcept.h, - include/freetype/internal/fthash.h, - include/freetype/internal/ftobject.h: Removed. Obsolete. - -2003-09-09 David Turner - - Fixing PFR kerning support. The tables within the font file contain - (charcode,charcode) kerning pairs, we need to convert them to - (gindex,gindex). - - * src/base/ftpfr.c (ft_pfr_check): Fix serious typo. - * src/pfr/pfrload.c: Remove dead code. - (pfr_get_gindex, pfr_compare_kern_pairs, pfr_sort_kerning_pairs): - New functions. - (pfr_phy_font_done): Free `kern_pairs'. - (pfr_phy_font_load): Call `pfr_sort_kerning_pairs'. - * src/pfr/pfrobjs.c (pfr_face_get_kerning): Fix kerning extraction. - * src/pfr/pfrtypes.h (PFR_KERN_PAIR_INDEX): New macro. - (PFR_KernPairRec): Make `kerning' an FT_Int. - (PFR_PhyFontRec): New element `kern_pairs'. - (PFR_KernFlags): Values of PFR_KERN_2BYTE_CHAR and - PFR_KERN_2BYTE_ADJ were erroneously reversed. - - * include/freetype/ftoption.h: Commenting out the macro - TT_CONFIG_OPTION_BYTECODE_INTERPRETER. - -2003-09-02 David Turner - - - * Version 2.1.5 released. - ========================= - - -2003-08-31 Manish Singh - - * src/bdf/bdflib.c (_bdf_readstream): Don't use FT_MEM_COPY but - FT_MEM_MOVE. - -2003-08-30 Werner Lemberg - - * include/freetype/freetype.h (FT_ENCODING_SJIS, FT_ENCODING_GB2312, - FT_ENCODING_BIG5, FT_ENCODING_WANSUNG, FT_ENCODING_JOHAB): New - enumerations of FT_Encoding. The FT_ENCODING_MS_* variants except - FT_ENCODING_MS_SYMBOL are now deprecated. - Updated all users. - * docs/CHANGES: Document it. - -2003-08-27 Werner Lemberg - - * src/bdf/bdfdrivr.c (BDF_Face_Init): Accept lowercase characters - for spacing. - -2003-08-27 Mike FABIAN - - * src/pcf/pcfread.c (pcf_load_font), src/bdf/bdfdrivr.c - (BDF_Face_Init): Accept lowercase characters for slant and weight. - -2003-08-18 David Turner - - * include/freetype/config/ftoption.h: Disabling TrueType bytecode - interpreter until the UNPATENTED_HINTING works as advertised. - - * src/autohint/ahhint.c (ah_hinter_load_glyph): Use `|' for - setting `load_flags'. - - * Jamfile: Adding the `refdoc' target to the Jamfile in order to - build the API Reference in `docs/reference' automatically. - - * include/freetype/t1tables.h (PS_FontInfoRec), src/cid/cidtoken.h, - src/type1/t1tokens.h, src/type42/t42parse.c: Resetting the types of - `italic_angle', `underline_position', and `underline_thickness' to - their previous values (i.e., long, short, and ushort) in order to - avoid breaking binary compatibility. - - * include/freetype/ttunpat.h: Fixing documentation comment. - - * include/freetype/config/ftoption.h, devel/ftoption.h - (TT_CONFIG_OPTION_COMPILE_UNPATENTED_HINTING): Replaced with... - (TT_CONFIG_OPTION_UNPATENTED_HINTING): This. Updated all users. - (TT_CONFIG_OPTION_FORCE_UNPATENTED_HINTING): Removed. - - * include/freetype/internal/ftobjs.h (FT_DEBUG_HOOK_TYPE1): Removed. - (FT_DEBUG_HOOK_UNPATENTED_HINTING): New macro. Use this with - `FT_Set_Debug_Hook' to get the same effect as the removed - TT_CONFIG_OPTION_FORCE_UNPATENTED_HINTING. - - * src/truetype/ttobjs.c (tt_face_init): Use - `FT_DEBUG_HOOK_UNPATENTED_HINTING'. - -2003-08-06 Werner Lemberg - - * src/type1/t1gload.c (T1_Load_Glyph), src/cff/cffgload.c - (cff_slot_load), src/cid/cidgload.c (cid_slot_load_glyph): Fix - previous change. - -2003-08-05 Werner Lemberg - - * src/type1/t1gload.c (T1_Load_Glyph), src/cff/cffgload.c - (cff_slot_load), src/cid/cidgload.c (cid_slot_load_glyph): Apply - font matrix to advance width also. - * docs/CHANGES: Updated. - -2003-07-26 Werner Lemberg - - * builds/unix/configure.ac (version_info): Set to 9:4:3. - * builds/unix/configure: Updated. - * docs/CHANGES, docs/VERSION.DLL: Updated. - - * include/freetype/freetype.h (FT_GlyphSlot): Change 2003-06-16 - also breaks binary compatibility. Reintroduce an unsigned integer - at the old position of `flags' called `reserved'. - -2003-07-25 Werner Lemberg - - Make API reference valid HTML 4.01 transitional. - - * src/tools/docmaker/tohtml.py (html_header_1): Add doctype - and charset. - (html_header_2): Fix style elements and add some more. - Fix syntax. - (block_header, block_footer, description_header, description_footer, - marker_header, marker_footer, source_header, source_footer, - chapter_header): Don't use
...
but `align=center' - table attribute. - (chapter_inter, chapter_footer): Add
  • and use special