README_MOZILLA (7105B)
1 # FFVPX 2 3 This directory contains files used in gecko builds from FFmpeg 4 (http://ffmpeg.org). The current files are from FFmpeg as of 5 revision 6 252fc2e047297697dea78e63aa908377b47c2136 7 git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg 8 git checkout 252fc2e047297697dea78e63aa908377b47c2136 9 10 All source files match their path from the library's source archive. 11 12 Currently, we only use the vp8, vp9, av1 (via libdav1d), mp3, flac, vorbis (via 13 libvorbis), opus (via libopus) and PCM portion of the library. If this changes, 14 configuration files will most likely need to be updated. On Windows, we use d3d11va for vp9 and av1. 15 16 Decoding AV1 via libdav1d and libvorbis is supported, although the decoder 17 libraries are vendored separately, `ffvpx` only contains the code to use 18 those libraries through the `ffmpeg` API. 19 20 The ffmpeg project recommends to use ffmpeg's tip, not a particular release. 21 22 ## Source files 23 24 This library only uses a small part of `ffmpeg`. To update the source tree run: 25 26 > rsync -av --existing ffmpeg-upstream/* ffmpeg-mozilla-dir 27 28 If the new version of ffmpeg requires source files we don't already package, 29 they will not be copied over by this rsync command and will have to be added 30 manually. 31 32 Then, make sure the files: 33 34 - `libavcodec/codec_list.c` 35 - `libavcodec/bsf_list.c` 36 - `libavcodec/parser_list.c` 37 38 include conditional compilation directives, by probably reverting them (or 39 reverting and adjusting them if new codecs are added). 40 41 Revert and adjust libavcodec `dovi_rpu.h` and `lcevcdec.h` so that they contain 42 just the necessary stubs to compile. We do this to avoid patent and other 43 restrictions. When ffmpeg is being upgraded, be on the lookout for other files 44 that may need to be stubbed out as well. 45 46 ## Add headers for a new major ffmpeg version 47 48 For historical reasons, we package ffmpeg according to the libavcodec version. 49 Check `libavcodec/version_major.h`. The version number defined by 50 `LIBAVCODEC_VERSION_MAJOR` is the version number we will be using. 51 52 If a new major version of ffmpeg is being imported in the tree, it's necessary 53 to manually copy the new ffmpeg headers into 54 `dom/media/platforms/ffmpeg/ffmpegxx` where xx is the new ffmpeg major version 55 number. Copy only the header files necessary to compile. 56 57 Then, modify the dynamic linker wrapper in 58 `dom/media/platforms/dom/media/platforms/ffmpeg/{FFmpegLibWrapper.cpp,FFmpegRungtimeLinker.cpp}` 59 with the new version and the new API in this new version. 60 61 ## `config.{h,asm}` generation 62 63 Each platform needs its own `config.h` file and some need a `config.asm` file as 64 well. For example, x86_64 Linux uses `config_unix64.h` and `config_unix64.asm`. 65 Ideally, the existing configuration files should be usable without any changes. 66 If changes are needed, it is preferable to update these files by hand. 67 If this is not possible and the files need to be regenerated entirely, 68 the `configure` script in the ffmpeg source directory can be used. 69 The arguments used to create them can be found in the 70 `FFMPEG_CONFIGURATION` define in the existing header files. 71 72 For example, create `config.h` and `config.asm` for x86_64 Linux desktop by 73 running `./configure` with the arguments from `config_unix64.h`. 74 75 Then, copy the generated `config.h` and `config.asm` files over `config_unix64.h` and `config_unix64.asm`. 76 77 For Linux Desktop, there are a number of overrides in `config_common.h` for 78 VAAPI. We can't put them in `config_components.h` because this breaks the build. 79 80 `config_components.h` is common to all platforms, and then a specific config 81 file is included, based on the platform and architecture. 82 macOS and Android are similar to Linux Desktop. Windows needs a bit more setup. 83 84 # Windows 85 86 The general idea is to get an msys prompt with an msvc toolchain 87 configured, so that the configure script for ffmpeg can run successfully 88 with the thread flavor Gecko prefers on Windows (win32, not pthreads). 89 90 - Open Visual Studio (2019 when writing this) 91 - Tools → Command Line → Developer command prompt 92 - Check that compiling a small C program with cl.exe works 93 - Install msys2 from https://www.msys2.org/ 94 - From the Visual Studio Developer Command Prompt, run the following: 95 > C:\msys64\msys2_shell.cmd -msys2 -use-full-path 96 - This pops up a new shell window, with a 32-bits build environment 97 - Check that compiling a small C program with `cl.exe` works. You may need 98 to install additional packages by running `pacman`, such as: 99 `pacman -S nasm`, `pacman -S pkgconf`, `pacman -S diffutils`. 100 - Run ffmpeg's ./configure with the options needed from `config_win32.h`. 101 102 - Copy `config.h` and `config.asm` as `config_win32.h` and `config_win32.asm` 103 in this directory 104 - Close the `msys2` window, go back to the `cmd.exe` window 105 - Run this command, maybe substituting the Visual Studio version: 106 107 > "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64 108 109 - This pops up a new shell window, now with a 64-bits build 110 environment 111 - Check that compiling a small C program with `cl.exe` works 112 - Run ffmpeg's `./configure` with the options needed from `config_win64.h`. 113 - Copy `config.h` and `config.asm` as `config_win64.h` and `config_win64.asm`. 114 115 For `config_aarch64_win64.h`: You will need to install cpp (either using msys or 116 wsl), then run `configure` with the arguments from `config_aarch64_win64.h`. 117 118 Once all of the config files have been generated, run the following command: 119 120 > sed -i -E '/HAVE_(MALLOC_H|ARC4RANDOM|LOCALTIME_R|MEMALIGN|POSIX_MEMALIGN)/d' config.* 121 122 to avoid redefined macros. 123 124 # Build, fix errors 125 126 Missing files need to be added, and the patch to rename `time.h` to `fftime.h` 127 might need to be reapplied or extended to other files including `time.h`. The 128 issue being that it's included instead of the system header, causing all sorts 129 of issues. 130 131 Additionally, `jni.h` and `jni.c` in ffmpeg sources need to be renamed to 132 `fffjni.h` and `fffjni.c`, and `#include` to those files need to be updated. 133 This is because there are header collisions with the JDK. 134 135 `moz.build` files might need to be modified as well, in light of compilation 136 and link errors. 137 138 There are going to be a lot of changes in terms of symbols exported. Adjust 139 `libavutil/avutil.symbols` and `libavcodec/avcodec.symbols` by removing and 140 adding symbols until the build passes. You may also need to modify 141 `/config/external/gkcodecs/gkcodecs.symbols`. 142 143 Finally, apply the patches: 144 - no-unicode-stdio.patch to avoid passing the infity symbol in unicode to an 145 stdio.h function, that causes bug 1879740 issue on Windows. 146 - opusenc-dtx.patch to allow enabling DTX in the opus encoder. 147 - libaomenc-svc.patch to allow configuring SVC in the libaom encoder. 148 - mediacodec_h264.patch to remove the H264 extradata parsing that brings in 149 encumbered code on Android. 150 - mediacodec_eos.patch to add a method to check definitely if a decoder has 151 reached the end of stream on Android. 152 - mediacodec_drm.patch to add support for encrypted packets on Android. 153 - mediacodec_force_key_frames.patch to add support for forcing key frames when 154 encoding via the frame pict_type on Android.