developer.texi 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. \input texinfo @c -*- texinfo -*-
  2. @documentencoding UTF-8
  3. @settitle Developer Documentation
  4. @titlepage
  5. @center @titlefont{Developer Documentation}
  6. @end titlepage
  7. @top
  8. @contents
  9. @chapter Introduction
  10. This text is concerned with the development @emph{of} FFmpeg itself. Information
  11. on using the FFmpeg libraries in other programs can be found elsewhere, e.g. in:
  12. @itemize @bullet
  13. @item
  14. the installed header files
  15. @item
  16. @url{http://ffmpeg.org/doxygen/trunk/index.html, the Doxygen documentation}
  17. generated from the headers
  18. @item
  19. the examples under @file{doc/examples}
  20. @end itemize
  21. For more detailed legal information about the use of FFmpeg in
  22. external programs read the @file{LICENSE} file in the source tree and
  23. consult @url{https://ffmpeg.org/legal.html}.
  24. If you modify FFmpeg code for your own use case, you are highly encouraged to
  25. @emph{submit your changes back to us}, using this document as a guide. There are
  26. both pragmatic and ideological reasons to do so:
  27. @itemize @bullet
  28. @item
  29. Maintaining external changes to keep up with upstream development is
  30. time-consuming and error-prone. With your code in the main tree, it will be
  31. maintained by FFmpeg developers.
  32. @item
  33. FFmpeg developers include leading experts in the field who can find bugs or
  34. design flaws in your code.
  35. @item
  36. By supporting the project you find useful you ensure it continues to be
  37. maintained and developed.
  38. @end itemize
  39. All proposed code changes should be submitted for review to
  40. @url{mailto:ffmpeg-devel@@ffmpeg.org, the development mailing list}, as
  41. described in more detail in the @ref{Submitting patches} chapter. The code
  42. should comply with the @ref{Development Policy} and follow the @ref{Coding Rules}.
  43. The developer making the commit and the author are responsible for their changes
  44. and should try to fix issues their commit causes.
  45. @anchor{Coding Rules}
  46. @chapter Coding Rules
  47. @section Language
  48. FFmpeg is mainly programmed in the ISO C99 language, extended with:
  49. @itemize @bullet
  50. @item
  51. Atomic operations from C11 @file{stdatomic.h}. They are emulated on
  52. architectures/compilers that do not support them, so all FFmpeg-internal code
  53. may use atomics without any extra checks. However, @file{stdatomic.h} must not
  54. be included in public headers, so they stay C99-compatible.
  55. @end itemize
  56. Compiler-specific extensions may be used with good reason, but must not be
  57. depended on, i.e. the code must still compile and work with compilers lacking
  58. the extension.
  59. The following C99 features must not be used anywhere in the codebase:
  60. @itemize @bullet
  61. @item
  62. variable-length arrays;
  63. @item
  64. complex numbers;
  65. @item
  66. mixed statements and declarations.
  67. @end itemize
  68. @subsection SIMD/DSP
  69. @anchor{SIMD/DSP}
  70. As modern compilers are unable to generate efficient SIMD or other
  71. performance-critical DSP code from plain C, handwritten assembly is used.
  72. Usually such code is isolated in a separate function. Then the standard approach
  73. is writing multiple versions of this function – a plain C one that works
  74. everywhere and may also be useful for debugging, and potentially multiple
  75. architecture-specific optimized implementations. Initialization code then
  76. chooses the best available version at runtime and loads it into a function
  77. pointer; the function in question is then always called through this pointer.
  78. The specific syntax used for writing assembly is:
  79. @itemize @bullet
  80. @item
  81. NASM on x86;
  82. @item
  83. GAS on ARM.
  84. @end itemize
  85. A unit testing framework for assembly called @code{checkasm} lives under
  86. @file{tests/checkasm}. All new assembly should come with @code{checkasm} tests;
  87. adding tests for existing assembly that lacks them is also strongly encouraged.
  88. @subsection Other languages
  89. Other languages than C may be used in special cases:
  90. @itemize @bullet
  91. @item
  92. Compiler intrinsics or inline assembly when the code in question cannot be
  93. written in the standard way described in the @ref{SIMD/DSP} section. This
  94. typically applies to code that needs to be inlined.
  95. @item
  96. Objective-C where required for interacting with macOS-specific interfaces.
  97. @end itemize
  98. @section Code formatting conventions
  99. There are the following guidelines regarding the indentation in files:
  100. @itemize @bullet
  101. @item
  102. Indent size is 4.
  103. @item
  104. The TAB character is forbidden outside of Makefiles as is any
  105. form of trailing whitespace. Commits containing either will be
  106. rejected by the git repository.
  107. @item
  108. You should try to limit your code lines to 80 characters; however, do so if
  109. and only if this improves readability.
  110. @item
  111. K&R coding style is used.
  112. @end itemize
  113. The presentation is one inspired by 'indent -i4 -kr -nut'.
  114. @subsection Vim configuration
  115. In order to configure Vim to follow FFmpeg formatting conventions, paste
  116. the following snippet into your @file{.vimrc}:
  117. @example
  118. " indentation rules for FFmpeg: 4 spaces, no tabs
  119. set expandtab
  120. set shiftwidth=4
  121. set softtabstop=4
  122. set cindent
  123. set cinoptions=(0
  124. " Allow tabs in Makefiles.
  125. autocmd FileType make,automake set noexpandtab shiftwidth=8 softtabstop=8
  126. " Trailing whitespace and tabs are forbidden, so highlight them.
  127. highlight ForbiddenWhitespace ctermbg=red guibg=red
  128. match ForbiddenWhitespace /\s\+$\|\t/
  129. " Do not highlight spaces at the end of line while typing on that line.
  130. autocmd InsertEnter * match ForbiddenWhitespace /\t\|\s\+\%#\@@<!$/
  131. @end example
  132. @subsection Emacs configuration
  133. For Emacs, add these roughly equivalent lines to your @file{.emacs.d/init.el}:
  134. @lisp
  135. (c-add-style "ffmpeg"
  136. '("k&r"
  137. (c-basic-offset . 4)
  138. (indent-tabs-mode . nil)
  139. (show-trailing-whitespace . t)
  140. (c-offsets-alist
  141. (statement-cont . (c-lineup-assignments +)))
  142. )
  143. )
  144. (setq c-default-style "ffmpeg")
  145. @end lisp
  146. @section Comments
  147. Use the JavaDoc/Doxygen format (see examples below) so that code documentation
  148. can be generated automatically. All nontrivial functions should have a comment
  149. above them explaining what the function does, even if it is just one sentence.
  150. All structures and their member variables should be documented, too.
  151. Avoid Qt-style and similar Doxygen syntax with @code{!} in it, i.e. replace
  152. @code{//!} with @code{///} and similar. Also @@ syntax should be employed
  153. for markup commands, i.e. use @code{@@param} and not @code{\param}.
  154. @example
  155. /**
  156. * @@file
  157. * MPEG codec.
  158. * @@author ...
  159. */
  160. /**
  161. * Summary sentence.
  162. * more text ...
  163. * ...
  164. */
  165. typedef struct Foobar @{
  166. int var1; /**< var1 description */
  167. int var2; ///< var2 description
  168. /** var3 description */
  169. int var3;
  170. @} Foobar;
  171. /**
  172. * Summary sentence.
  173. * more text ...
  174. * ...
  175. * @@param my_parameter description of my_parameter
  176. * @@return return value description
  177. */
  178. int myfunc(int my_parameter)
  179. ...
  180. @end example
  181. @anchor{Naming conventions}
  182. @section Naming conventions
  183. Names of functions, variables, and struct members must be lowercase, using
  184. underscores (_) to separate words. For example, @samp{avfilter_get_video_buffer}
  185. is an acceptable function name and @samp{AVFilterGetVideo} is not.
  186. Struct, union, enum, and typedeffed type names must use CamelCase. All structs
  187. and unions should be typedeffed to the same name as the struct/union tag, e.g.
  188. @code{typedef struct AVFoo @{ ... @} AVFoo;}. Enums are typically not
  189. typedeffed.
  190. Enumeration constants and macros must be UPPERCASE, except for macros
  191. masquerading as functions, which should use the function naming convention.
  192. All identifiers in the libraries should be namespaced as follows:
  193. @itemize @bullet
  194. @item
  195. No namespacing for identifiers with file and lower scope (e.g. local variables,
  196. static functions), and struct and union members,
  197. @item
  198. The @code{ff_} prefix must be used for variables and functions visible outside
  199. of file scope, but only used internally within a single library, e.g.
  200. @samp{ff_w64_demuxer}. This prevents name collisions when FFmpeg is statically
  201. linked.
  202. @item
  203. For variables and functions visible outside of file scope, used internally
  204. across multiple libraries, use @code{avpriv_} as prefix, for example,
  205. @samp{avpriv_report_missing_feature}.
  206. @item
  207. All other internal identifiers, like private type or macro names, should be
  208. namespaced only to avoid possible internal conflicts. E.g. @code{H264_NAL_SPS}
  209. vs. @code{HEVC_NAL_SPS}.
  210. @item
  211. Each library has its own prefix for public symbols, in addition to the
  212. commonly used @code{av_} (@code{avformat_} for libavformat,
  213. @code{avcodec_} for libavcodec, @code{swr_} for libswresample, etc).
  214. Check the existing code and choose names accordingly.
  215. @item
  216. Other public identifiers (struct, union, enum, macro, type names) must use their
  217. library's public prefix (@code{AV}, @code{Sws}, or @code{Swr}).
  218. @end itemize
  219. Furthermore, name space reserved for the system should not be invaded.
  220. Identifiers ending in @code{_t} are reserved by
  221. @url{http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_02.html#tag_02_02_02, POSIX}.
  222. Also avoid names starting with @code{__} or @code{_} followed by an uppercase
  223. letter as they are reserved by the C standard. Names starting with @code{_}
  224. are reserved at the file level and may not be used for externally visible
  225. symbols. If in doubt, just avoid names starting with @code{_} altogether.
  226. @section Miscellaneous conventions
  227. @itemize @bullet
  228. @item
  229. Casts should be used only when necessary. Unneeded parentheses
  230. should also be avoided if they don't make the code easier to understand.
  231. @end itemize
  232. @anchor{Development Policy}
  233. @chapter Development Policy
  234. @section Code behaviour
  235. @subheading Correctness
  236. The code must be valid. It must not crash, abort, access invalid pointers, leak
  237. memory, cause data races or signed integer overflow, or otherwise cause
  238. undefined behaviour. Error codes should be checked and, when applicable,
  239. forwarded to the caller.
  240. @subheading Thread- and library-safety
  241. Our libraries may be called by multiple independent callers in the same process.
  242. These calls may happen from any number of threads and the different call sites
  243. may not be aware of each other - e.g. a user program may be calling our
  244. libraries directly, and use one or more libraries that also call our libraries.
  245. The code must behave correctly under such conditions.
  246. @subheading Robustness
  247. The code must treat as untrusted any bytestream received from a caller or read
  248. from a file, network, etc. It must not misbehave when arbitrary data is sent to
  249. it - typically it should print an error message and return
  250. @code{AVERROR_INVALIDDATA} on encountering invalid input data.
  251. @subheading Memory allocation
  252. The code must use the @code{av_malloc()} family of functions from
  253. @file{libavutil/mem.h} to perform all memory allocation, except in special cases
  254. (e.g. when interacting with an external library that requires a specific
  255. allocator to be used).
  256. All allocations should be checked and @code{AVERROR(ENOMEM)} returned on
  257. failure. A common mistake is that error paths leak memory - make sure that does
  258. not happen.
  259. @subheading stdio
  260. Our libraries must not access the stdio streams stdin/stdout/stderr directly
  261. (e.g. via @code{printf()} family of functions), as that is not library-safe. For
  262. logging, use @code{av_log()}.
  263. @section Patches/Committing
  264. @subheading Licenses for patches must be compatible with FFmpeg.
  265. Contributions should be licensed under the
  266. @uref{http://www.gnu.org/licenses/lgpl-2.1.html, LGPL 2.1},
  267. including an "or any later version" clause, or, if you prefer
  268. a gift-style license, the
  269. @uref{http://opensource.org/licenses/isc-license.txt, ISC} or
  270. @uref{http://mit-license.org/, MIT} license.
  271. @uref{http://www.gnu.org/licenses/gpl-2.0.html, GPL 2} including
  272. an "or any later version" clause is also acceptable, but LGPL is
  273. preferred.
  274. If you add a new file, give it a proper license header. Do not copy and
  275. paste it from a random place, use an existing file as template.
  276. @subheading You must not commit code which breaks FFmpeg!
  277. This means unfinished code which is enabled and breaks compilation,
  278. or compiles but does not work/breaks the regression tests. Code which
  279. is unfinished but disabled may be permitted under-circumstances, like
  280. missing samples or an implementation with a small subset of features.
  281. Always check the mailing list for any reviewers with issues and test
  282. FATE before you push.
  283. @subheading Commit messages
  284. Commit messages are highly important tools for informing other developers on
  285. what a given change does and why. Every commit must always have a properly
  286. filled out commit message with the following format:
  287. @example
  288. area changed: short 1 line description
  289. details describing what and why and giving references.
  290. @end example
  291. If the commit addresses a known bug on our bug tracker or other external issue
  292. (e.g. CVE), the commit message should include the relevant bug ID(s) or other
  293. external identifiers. Note that this should be done in addition to a proper
  294. explanation and not instead of it. Comments such as "fixed!" or "Changed it."
  295. are not acceptable.
  296. When applying patches that have been discussed at length on the mailing list,
  297. reference the thread in the commit message.
  298. @subheading Testing must be adequate but not excessive.
  299. If it works for you, others, and passes FATE then it should be OK to commit
  300. it, provided it fits the other committing criteria. You should not worry about
  301. over-testing things. If your code has problems (portability, triggers
  302. compiler bugs, unusual environment etc) they will be reported and eventually
  303. fixed.
  304. @subheading Do not commit unrelated changes together.
  305. They should be split them into self-contained pieces. Also do not forget
  306. that if part B depends on part A, but A does not depend on B, then A can
  307. and should be committed first and separate from B. Keeping changes well
  308. split into self-contained parts makes reviewing and understanding them on
  309. the commit log mailing list easier. This also helps in case of debugging
  310. later on.
  311. Also if you have doubts about splitting or not splitting, do not hesitate to
  312. ask/discuss it on the developer mailing list.
  313. @subheading Cosmetic changes should be kept in separate patches.
  314. We refuse source indentation and other cosmetic changes if they are mixed
  315. with functional changes, such commits will be rejected and removed. Every
  316. developer has his own indentation style, you should not change it. Of course
  317. if you (re)write something, you can use your own style, even though we would
  318. prefer if the indentation throughout FFmpeg was consistent (Many projects
  319. force a given indentation style - we do not.). If you really need to make
  320. indentation changes (try to avoid this), separate them strictly from real
  321. changes.
  322. NOTE: If you had to put if()@{ .. @} over a large (> 5 lines) chunk of code,
  323. then either do NOT change the indentation of the inner part within (do not
  324. move it to the right)! or do so in a separate commit
  325. @subheading Credit the author of the patch.
  326. Make sure the author of the commit is set correctly. (see git commit --author)
  327. If you apply a patch, send an
  328. answer to ffmpeg-devel (or wherever you got the patch from) saying that
  329. you applied the patch.
  330. @subheading Credit any researchers
  331. If a commit/patch fixes an issues found by some researcher, always credit the
  332. researcher in the commit message for finding/reporting the issue.
  333. @subheading Always wait long enough before pushing changes
  334. Do NOT commit to code actively maintained by others without permission.
  335. Send a patch to ffmpeg-devel. If no one answers within a reasonable
  336. time-frame (12h for build failures and security fixes, 3 days small changes,
  337. 1 week for big patches) then commit your patch if you think it is OK.
  338. Also note, the maintainer can simply ask for more time to review!
  339. @section Code
  340. @subheading Warnings for correct code may be disabled if there is no other option.
  341. Compiler warnings indicate potential bugs or code with bad style. If a type of
  342. warning always points to correct and clean code, that warning should
  343. be disabled, not the code changed.
  344. Thus the remaining warnings can either be bugs or correct code.
  345. If it is a bug, the bug has to be fixed. If it is not, the code should
  346. be changed to not generate a warning unless that causes a slowdown
  347. or obfuscates the code.
  348. @section Library public interfaces
  349. Every library in FFmpeg provides a set of public APIs in its installed headers,
  350. which are those listed in the variable @code{HEADERS} in that library's
  351. @file{Makefile}. All identifiers defined in those headers (except for those
  352. explicitly documented otherwise), and corresponding symbols exported from
  353. compiled shared or static libraries are considered public interfaces and must
  354. comply with the API and ABI compatibility rules described in this section.
  355. Public APIs must be backward compatible within a given major version. I.e. any
  356. valid user code that compiles and works with a given library version must still
  357. compile and work with any later version, as long as the major version number is
  358. unchanged. "Valid user code" here means code that is calling our APIs in a
  359. documented and/or intended manner and is not relying on any undefined behavior.
  360. Incrementing the major version may break backward compatibility, but only to the
  361. extent described in @ref{Major version bumps}.
  362. We also guarantee backward ABI compatibility for shared and static libraries.
  363. I.e. it should be possible to replace a shared or static build of our library
  364. with a build of any later version (re-linking the user binary in the static
  365. case) without breaking any valid user binaries, as long as the major version
  366. number remains unchanged.
  367. @subsection Adding new interfaces
  368. Any new public identifiers in installed headers are considered new API - this
  369. includes new functions, structs, macros, enum values, typedefs, new fields in
  370. existing structs, new installed headers, etc. Consider the following
  371. guidelines when adding new APIs.
  372. @subsubheading Motivation
  373. While new APIs can be added relatively easily, changing or removing them is much
  374. harder due to abovementioned compatibility requirements. You should then
  375. consider carefully whether the functionality you are adding really needs to be
  376. exposed to our callers as new public API.
  377. Your new API should have at least one well-established use case outside of the
  378. library that cannot be easily achieved with existing APIs. Every library in
  379. FFmpeg also has a defined scope - your new API must fit within it.
  380. @subsubheading Replacing existing APIs
  381. If your new API is replacing an existing one, it should be strictly superior to
  382. it, so that the advantages of using the new API outweight the cost to the
  383. callers of changing their code. After adding the new API you should then
  384. deprecate the old one and schedule it for removal, as described in
  385. @ref{Removing interfaces}.
  386. If you deem an existing API deficient and want to fix it, the preferred approach
  387. in most cases is to add a differently-named replacement and deprecate the
  388. existing API rather than modify it. It is important to make the changes visible
  389. to our callers (e.g. through compile- or run-time deprecation warnings) and make
  390. it clear how to transition to the new API (e.g. in the Doxygen documentation or
  391. on the wiki).
  392. @subsubheading API design
  393. The FFmpeg libraries are used by a variety of callers to perform a wide range of
  394. multimedia-related processing tasks. You should therefore - within reason - try
  395. to design your new API for the broadest feasible set of use cases and avoid
  396. unnecessarily limiting it to a specific type of callers (e.g. just media
  397. playback or just transcoding).
  398. @subsubheading Consistency
  399. Check whether similar APIs already exist in FFmpeg. If they do, try to model
  400. your new addition on them to achieve better overall consistency.
  401. The naming of your new identifiers should follow the @ref{Naming conventions}
  402. and be aligned with other similar APIs, if applicable.
  403. @subsubheading Extensibility
  404. You should also consider how your API might be extended in the future in a
  405. backward-compatible way. If you are adding a new struct @code{AVFoo}, the
  406. standard approach is requiring the caller to always allocate it through a
  407. constructor function, typically named @code{av_foo_alloc()}. This way new fields
  408. may be added to the end of the struct without breaking ABI compatibility.
  409. Typically you will also want a destructor - @code{av_foo_free(AVFoo**)} that
  410. frees the indirectly supplied object (and its contents, if applicable) and
  411. writes @code{NULL} to the supplied pointer, thus eliminating the potential
  412. dangling pointer in the caller's memory.
  413. If you are adding new functions, consider whether it might be desirable to tweak
  414. their behavior in the future - you may want to add a flags argument, even though
  415. it would be unused initially.
  416. @subsubheading Documentation
  417. All new APIs must be documented as Doxygen-formatted comments above the
  418. identifiers you add to the public headers. You should also briefly mention the
  419. change in @file{doc/APIchanges}.
  420. @subsubheading Bump the version
  421. Backward-incompatible API or ABI changes require incrementing (bumping) the
  422. major version number, as described in @ref{Major version bumps}. Major
  423. bumps are significant events that happen on a schedule - so if your change
  424. strictly requires one you should add it under @code{#if} preprocesor guards that
  425. disable it until the next major bump happens.
  426. New APIs that can be added without breaking API or ABI compatibility require
  427. bumping the minor version number.
  428. Incrementing the third (micro) version component means a noteworthy binary
  429. compatible change (e.g. encoder bug fix that matters for the decoder). The third
  430. component always starts at 100 to distinguish FFmpeg from Libav.
  431. @anchor{Removing interfaces}
  432. @subsection Removing interfaces
  433. Due to abovementioned compatibility guarantees, removing APIs is an involved
  434. process that should only be undertaken with good reason. Typically a deficient,
  435. restrictive, or otherwise inadequate API is replaced by a superior one, though
  436. it does at times happen that we remove an API without any replacement (e.g. when
  437. the feature it provides is deemed not worth the maintenance effort, out of scope
  438. of the project, fundamentally flawed, etc.).
  439. The removal has two steps - first the API is deprecated and scheduled for
  440. removal, but remains present and functional. The second step is actually
  441. removing the API - this is described in @ref{Major version bumps}.
  442. To deprecate an API you should signal to our users that they should stop using
  443. it. E.g. if you intend to remove struct members or functions, you should mark
  444. them with @code{attribute_deprecated}. When this cannot be done, it may be
  445. possible to detect the use of the deprecated API at runtime and print a warning
  446. (though take care not to print it too often). You should also document the
  447. deprecation (and the replacement, if applicable) in the relevant Doxygen
  448. documentation block.
  449. Finally, you should define a deprecation guard along the lines of
  450. @code{#define FF_API_<FOO> (LIBAVBAR_VERSION_MAJOR < XX)} (where XX is the major
  451. version in which the API will be removed) in @file{libavbar/version_major.h}
  452. (@file{version.h} in case of @code{libavutil}). Then wrap all uses of the
  453. deprecated API in @code{#if FF_API_<FOO> .... #endif}, so that the code will
  454. automatically get disabled once the major version reaches XX. You can also use
  455. @code{FF_DISABLE_DEPRECATION_WARNINGS} and @code{FF_ENABLE_DEPRECATION_WARNINGS}
  456. to suppress compiler deprecation warnings inside these guards. You should test
  457. that the code compiles and works with the guard macro evaluating to both true
  458. and false.
  459. @anchor{Major version bumps}
  460. @subsection Major version bumps
  461. A major version bump signifies an API and/or ABI compatibility break. To reduce
  462. the negative effects on our callers, who are required to adapt their code,
  463. backward-incompatible changes during a major bump should be limited to:
  464. @itemize @bullet
  465. @item
  466. Removing previously deprecated APIs.
  467. @item
  468. Performing ABI- but not API-breaking changes, like reordering struct contents.
  469. @end itemize
  470. @section Documentation/Other
  471. @subheading Subscribe to the ffmpeg-devel mailing list.
  472. It is important to be subscribed to the
  473. @uref{https://lists.ffmpeg.org/mailman/listinfo/ffmpeg-devel, ffmpeg-devel}
  474. mailing list. Almost any non-trivial patch is to be sent there for review.
  475. Other developers may have comments about your contribution. We expect you see
  476. those comments, and to improve it if requested. (N.B. Experienced committers
  477. have other channels, and may sometimes skip review for trivial fixes.) Also,
  478. discussion here about bug fixes and FFmpeg improvements by other developers may
  479. be helpful information for you. Finally, by being a list subscriber, your
  480. contribution will be posted immediately to the list, without the moderation
  481. hold which messages from non-subscribers experience.
  482. However, it is more important to the project that we receive your patch than
  483. that you be subscribed to the ffmpeg-devel list. If you have a patch, and don't
  484. want to subscribe and discuss the patch, then please do send it to the list
  485. anyway.
  486. @subheading Subscribe to the ffmpeg-cvslog mailing list.
  487. Diffs of all commits are sent to the
  488. @uref{https://lists.ffmpeg.org/mailman/listinfo/ffmpeg-cvslog, ffmpeg-cvslog}
  489. mailing list. Some developers read this list to review all code base changes
  490. from all sources. Subscribing to this list is not mandatory.
  491. @subheading Keep the documentation up to date.
  492. Update the documentation if you change behavior or add features. If you are
  493. unsure how best to do this, send a patch to ffmpeg-devel, the documentation
  494. maintainer(s) will review and commit your stuff.
  495. @subheading Important discussions should be accessible to all.
  496. Try to keep important discussions and requests (also) on the public
  497. developer mailing list, so that all developers can benefit from them.
  498. @subheading Check your entries in MAINTAINERS.
  499. Make sure that no parts of the codebase that you maintain are missing from the
  500. @file{MAINTAINERS} file. If something that you want to maintain is missing add it with
  501. your name after it.
  502. If at some point you no longer want to maintain some code, then please help in
  503. finding a new maintainer and also don't forget to update the @file{MAINTAINERS} file.
  504. We think our rules are not too hard. If you have comments, contact us.
  505. @anchor{Submitting patches}
  506. @chapter Submitting patches
  507. First, read the @ref{Coding Rules} above if you did not yet, in particular
  508. the rules regarding patch submission.
  509. When you submit your patch, please use @code{git format-patch} or
  510. @code{git send-email}. We cannot read other diffs :-).
  511. Also please do not submit a patch which contains several unrelated changes.
  512. Split it into separate, self-contained pieces. This does not mean splitting
  513. file by file. Instead, make the patch as small as possible while still
  514. keeping it as a logical unit that contains an individual change, even
  515. if it spans multiple files. This makes reviewing your patches much easier
  516. for us and greatly increases your chances of getting your patch applied.
  517. Use the patcheck tool of FFmpeg to check your patch.
  518. The tool is located in the tools directory.
  519. Run the @ref{Regression tests} before submitting a patch in order to verify
  520. it does not cause unexpected problems.
  521. It also helps quite a bit if you tell us what the patch does (for example
  522. 'replaces lrint by lrintf'), and why (for example '*BSD isn't C99 compliant
  523. and has no lrint()')
  524. Also please if you send several patches, send each patch as a separate mail,
  525. do not attach several unrelated patches to the same mail.
  526. Patches should be posted to the
  527. @uref{https://lists.ffmpeg.org/mailman/listinfo/ffmpeg-devel, ffmpeg-devel}
  528. mailing list. Use @code{git send-email} when possible since it will properly
  529. send patches without requiring extra care. If you cannot, then send patches
  530. as base64-encoded attachments, so your patch is not trashed during
  531. transmission. Also ensure the correct mime type is used
  532. (text/x-diff or text/x-patch or at least text/plain) and that only one
  533. patch is inline or attached per mail.
  534. You can check @url{https://patchwork.ffmpeg.org}, if your patch does not show up, its mime type
  535. likely was wrong.
  536. @subheading Sending patches from email clients
  537. Using @code{git send-email} might not be desirable for everyone. The
  538. following trick allows to send patches via email clients in a safe
  539. way. It has been tested with Outlook and Thunderbird (with X-Unsent
  540. extension) and might work with other applications.
  541. Create your patch like this:
  542. @verbatim
  543. git format-patch -s -o "outputfolder" --add-header "X-Unsent: 1" --suffix .eml --to ffmpeg-devel@ffmpeg.org -1 1a2b3c4d
  544. @end verbatim
  545. Now you'll just need to open the eml file with the email application
  546. and execute 'Send'.
  547. @subheading Reviews
  548. Your patch will be reviewed on the mailing list. You will likely be asked
  549. to make some changes and are expected to send in an improved version that
  550. incorporates the requests from the review. This process may go through
  551. several iterations. Once your patch is deemed good enough, some developer
  552. will pick it up and commit it to the official FFmpeg tree.
  553. Give us a few days to react. But if some time passes without reaction,
  554. send a reminder by email. Your patch should eventually be dealt with.
  555. @chapter New codecs or formats checklist
  556. @enumerate
  557. @item
  558. Did you use av_cold for codec initialization and close functions?
  559. @item
  560. Did you add a long_name under NULL_IF_CONFIG_SMALL to the AVCodec or
  561. AVInputFormat/AVOutputFormat struct?
  562. @item
  563. Did you bump the minor version number (and reset the micro version
  564. number) in @file{libavcodec/version.h} or @file{libavformat/version.h}?
  565. @item
  566. Did you register it in @file{allcodecs.c} or @file{allformats.c}?
  567. @item
  568. Did you add the AVCodecID to @file{avcodec.h}?
  569. When adding new codec IDs, also add an entry to the codec descriptor
  570. list in @file{libavcodec/codec_desc.c}.
  571. @item
  572. If it has a FourCC, did you add it to @file{libavformat/riff.c},
  573. even if it is only a decoder?
  574. @item
  575. Did you add a rule to compile the appropriate files in the Makefile?
  576. Remember to do this even if you're just adding a format to a file that is
  577. already being compiled by some other rule, like a raw demuxer.
  578. @item
  579. Did you add an entry to the table of supported formats or codecs in
  580. @file{doc/general.texi}?
  581. @item
  582. Did you add an entry in the Changelog?
  583. @item
  584. If it depends on a parser or a library, did you add that dependency in
  585. configure?
  586. @item
  587. Did you @code{git add} the appropriate files before committing?
  588. @item
  589. Did you make sure it compiles standalone, i.e. with
  590. @code{configure --disable-everything --enable-decoder=foo}
  591. (or @code{--enable-demuxer} or whatever your component is)?
  592. @end enumerate
  593. @chapter Patch submission checklist
  594. @enumerate
  595. @item
  596. Does @code{make fate} pass with the patch applied?
  597. @item
  598. Was the patch generated with git format-patch or send-email?
  599. @item
  600. Did you sign-off your patch? (@code{git commit -s})
  601. See @uref{https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/Documentation/process/submitting-patches.rst, Sign your work} for the meaning
  602. of @dfn{sign-off}.
  603. @item
  604. Did you provide a clear git commit log message?
  605. @item
  606. Is the patch against latest FFmpeg git master branch?
  607. @item
  608. Are you subscribed to ffmpeg-devel?
  609. (the list is subscribers only due to spam)
  610. @item
  611. Have you checked that the changes are minimal, so that the same cannot be
  612. achieved with a smaller patch and/or simpler final code?
  613. @item
  614. If the change is to speed critical code, did you benchmark it?
  615. @item
  616. If you did any benchmarks, did you provide them in the mail?
  617. @item
  618. Have you checked that the patch does not introduce buffer overflows or
  619. other security issues?
  620. @item
  621. Did you test your decoder or demuxer against damaged data? If no, see
  622. tools/trasher, the noise bitstream filter, and
  623. @uref{http://caca.zoy.org/wiki/zzuf, zzuf}. Your decoder or demuxer
  624. should not crash, end in a (near) infinite loop, or allocate ridiculous
  625. amounts of memory when fed damaged data.
  626. @item
  627. Did you test your decoder or demuxer against sample files?
  628. Samples may be obtained at @url{https://samples.ffmpeg.org}.
  629. @item
  630. Does the patch not mix functional and cosmetic changes?
  631. @item
  632. Did you add tabs or trailing whitespace to the code? Both are forbidden.
  633. @item
  634. Is the patch attached to the email you send?
  635. @item
  636. Is the mime type of the patch correct? It should be text/x-diff or
  637. text/x-patch or at least text/plain and not application/octet-stream.
  638. @item
  639. If the patch fixes a bug, did you provide a verbose analysis of the bug?
  640. @item
  641. If the patch fixes a bug, did you provide enough information, including
  642. a sample, so the bug can be reproduced and the fix can be verified?
  643. Note please do not attach samples >100k to mails but rather provide a
  644. URL, you can upload to @url{https://streams.videolan.org/upload/}.
  645. @item
  646. Did you provide a verbose summary about what the patch does change?
  647. @item
  648. Did you provide a verbose explanation why it changes things like it does?
  649. @item
  650. Did you provide a verbose summary of the user visible advantages and
  651. disadvantages if the patch is applied?
  652. @item
  653. Did you provide an example so we can verify the new feature added by the
  654. patch easily?
  655. @item
  656. If you added a new file, did you insert a license header? It should be
  657. taken from FFmpeg, not randomly copied and pasted from somewhere else.
  658. @item
  659. You should maintain alphabetical order in alphabetically ordered lists as
  660. long as doing so does not break API/ABI compatibility.
  661. @item
  662. Lines with similar content should be aligned vertically when doing so
  663. improves readability.
  664. @item
  665. Consider adding a regression test for your code. All new modules
  666. should be covered by tests. That includes demuxers, muxers, decoders, encoders
  667. filters, bitstream filters, parsers. If its not possible to do that, add
  668. an explanation why to your patchset, its ok to not test if theres a reason.
  669. @item
  670. If you added YASM code please check that things still work with --disable-yasm.
  671. @item
  672. Test your code with valgrind and or Address Sanitizer to ensure it's free
  673. of leaks, out of array accesses, etc.
  674. @end enumerate
  675. @chapter Patch review process
  676. All patches posted to ffmpeg-devel will be reviewed, unless they contain a
  677. clear note that the patch is not for the git master branch.
  678. Reviews and comments will be posted as replies to the patch on the
  679. mailing list. The patch submitter then has to take care of every comment,
  680. that can be by resubmitting a changed patch or by discussion. Resubmitted
  681. patches will themselves be reviewed like any other patch. If at some point
  682. a patch passes review with no comments then it is approved, that can for
  683. simple and small patches happen immediately while large patches will generally
  684. have to be changed and reviewed many times before they are approved.
  685. After a patch is approved it will be committed to the repository.
  686. We will review all submitted patches, but sometimes we are quite busy so
  687. especially for large patches this can take several weeks.
  688. If you feel that the review process is too slow and you are willing to try to
  689. take over maintainership of the area of code you change then just clone
  690. git master and maintain the area of code there. We will merge each area from
  691. where its best maintained.
  692. When resubmitting patches, please do not make any significant changes
  693. not related to the comments received during review. Such patches will
  694. be rejected. Instead, submit significant changes or new features as
  695. separate patches.
  696. Everyone is welcome to review patches. Also if you are waiting for your patch
  697. to be reviewed, please consider helping to review other patches, that is a great
  698. way to get everyone's patches reviewed sooner.
  699. @anchor{Regression tests}
  700. @chapter Regression tests
  701. Before submitting a patch (or committing to the repository), you should at least
  702. test that you did not break anything.
  703. Running 'make fate' accomplishes this, please see @url{fate.html} for details.
  704. [Of course, some patches may change the results of the regression tests. In
  705. this case, the reference results of the regression tests shall be modified
  706. accordingly].
  707. @section Adding files to the fate-suite dataset
  708. If you need a sample uploaded send a mail to samples-request.
  709. When there is no muxer or encoder available to generate test media for a
  710. specific test then the media has to be included in the fate-suite.
  711. First please make sure that the sample file is as small as possible to test the
  712. respective decoder or demuxer sufficiently. Large files increase network
  713. bandwidth and disk space requirements.
  714. Once you have a working fate test and fate sample, provide in the commit
  715. message or introductory message for the patch series that you post to
  716. the ffmpeg-devel mailing list, a direct link to download the sample media.
  717. @section Visualizing Test Coverage
  718. The FFmpeg build system allows visualizing the test coverage in an easy
  719. manner with the coverage tools @code{gcov}/@code{lcov}. This involves
  720. the following steps:
  721. @enumerate
  722. @item
  723. Configure to compile with instrumentation enabled:
  724. @code{configure --toolchain=gcov}.
  725. @item
  726. Run your test case, either manually or via FATE. This can be either
  727. the full FATE regression suite, or any arbitrary invocation of any
  728. front-end tool provided by FFmpeg, in any combination.
  729. @item
  730. Run @code{make lcov} to generate coverage data in HTML format.
  731. @item
  732. View @code{lcov/index.html} in your preferred HTML viewer.
  733. @end enumerate
  734. You can use the command @code{make lcov-reset} to reset the coverage
  735. measurements. You will need to rerun @code{make lcov} after running a
  736. new test.
  737. @section Using Valgrind
  738. The configure script provides a shortcut for using valgrind to spot bugs
  739. related to memory handling. Just add the option
  740. @code{--toolchain=valgrind-memcheck} or @code{--toolchain=valgrind-massif}
  741. to your configure line, and reasonable defaults will be set for running
  742. FATE under the supervision of either the @strong{memcheck} or the
  743. @strong{massif} tool of the valgrind suite.
  744. In case you need finer control over how valgrind is invoked, use the
  745. @code{--target-exec='valgrind <your_custom_valgrind_options>} option in
  746. your configure line instead.
  747. @anchor{Release process}
  748. @chapter Release process
  749. FFmpeg maintains a set of @strong{release branches}, which are the
  750. recommended deliverable for system integrators and distributors (such as
  751. Linux distributions, etc.). At regular times, a @strong{release
  752. manager} prepares, tests and publishes tarballs on the
  753. @url{https://ffmpeg.org} website.
  754. There are two kinds of releases:
  755. @enumerate
  756. @item
  757. @strong{Major releases} always include the latest and greatest
  758. features and functionality.
  759. @item
  760. @strong{Point releases} are cut from @strong{release} branches,
  761. which are named @code{release/X}, with @code{X} being the release
  762. version number.
  763. @end enumerate
  764. Note that we promise to our users that shared libraries from any FFmpeg
  765. release never break programs that have been @strong{compiled} against
  766. previous versions of @strong{the same release series} in any case!
  767. However, from time to time, we do make API changes that require adaptations
  768. in applications. Such changes are only allowed in (new) major releases and
  769. require further steps such as bumping library version numbers and/or
  770. adjustments to the symbol versioning file. Please discuss such changes
  771. on the @strong{ffmpeg-devel} mailing list in time to allow forward planning.
  772. @anchor{Criteria for Point Releases}
  773. @section Criteria for Point Releases
  774. Changes that match the following criteria are valid candidates for
  775. inclusion into a point release:
  776. @enumerate
  777. @item
  778. Fixes a security issue, preferably identified by a @strong{CVE
  779. number} issued by @url{http://cve.mitre.org/}.
  780. @item
  781. Fixes a documented bug in @url{https://trac.ffmpeg.org}.
  782. @item
  783. Improves the included documentation.
  784. @item
  785. Retains both source code and binary compatibility with previous
  786. point releases of the same release branch.
  787. @end enumerate
  788. The order for checking the rules is (1 OR 2 OR 3) AND 4.
  789. @section Release Checklist
  790. The release process involves the following steps:
  791. @enumerate
  792. @item
  793. Ensure that the @file{RELEASE} file contains the version number for
  794. the upcoming release.
  795. @item
  796. Add the release at @url{https://trac.ffmpeg.org/admin/ticket/versions}.
  797. @item
  798. Announce the intent to do a release to the mailing list.
  799. @item
  800. Make sure all relevant security fixes have been backported. See
  801. @url{https://ffmpeg.org/security.html}.
  802. @item
  803. Ensure that the FATE regression suite still passes in the release
  804. branch on at least @strong{i386} and @strong{amd64}
  805. (cf. @ref{Regression tests}).
  806. @item
  807. Prepare the release tarballs in @code{bz2} and @code{gz} formats, and
  808. supplementing files that contain @code{gpg} signatures
  809. @item
  810. Publish the tarballs at @url{https://ffmpeg.org/releases}. Create and
  811. push an annotated tag in the form @code{nX}, with @code{X}
  812. containing the version number.
  813. @item
  814. Propose and send a patch to the @strong{ffmpeg-devel} mailing list
  815. with a news entry for the website.
  816. @item
  817. Publish the news entry.
  818. @item
  819. Send an announcement to the mailing list.
  820. @end enumerate
  821. @bye