developer.texi 43 KB

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