developer.texi 40 KB

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