developer.texi 43 KB

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