\input texinfo @c -*- texinfo -*-@documentencoding UTF-8 @settitle Developer Documentation@titlepage@center @titlefont{Developer Documentation}@end titlepage @top @contents @chapter Introduction This text is concerned with the development @emph{of} FFmpeg itself. Informationon using the FFmpeg libraries in other programs can be found elsewhere, e.g. in:@itemize @bullet@itemthe installed header files@item@url{http://ffmpeg.org/doxygen/trunk/index.html, the Doxygen documentation}generated from the headers@itemthe examples under @file{doc/examples}@end itemize For more detailed legal information about the use of FFmpeg inexternal programs read the @file{LICENSE} file in the source tree andconsult @url{https://ffmpeg.org/legal.html}. If you modify FFmpeg code for your own use case, you are highly encouraged to@emph{submit your changes back to us}, using this document as a guide. There areboth pragmatic and ideological reasons to do so:@itemize @bullet@itemMaintaining external changes to keep up with upstream development istime-consuming and error-prone. With your code in the main tree, it will bemaintained by FFmpeg developers.@itemFFmpeg developers include leading experts in the field who can find bugs ordesign flaws in your code.@itemBy supporting the project you find useful you ensure it continues to bemaintained and developed.@end itemize All proposed code changes should be submitted for review to@url{mailto:ffmpeg-devel@@ffmpeg.org, the development mailing list}, asdescribed in more detail in the @ref{Submitting patches} chapter. The codeshould comply with the @ref{Development Policy} and follow the @ref{Coding Rules}.The developer making the commit and the author are responsible for their changesand should try to fix issues their commit causes. @anchor{Coding Rules}@chapter Coding Rules @section Language FFmpeg is mainly programmed in the ISO C11 language, except for the publicheaders which must stay C99 compatible. Compiler-specific extensions may be used with good reason, but must not bedepended on, i.e. the code must still compile and work with compilers lackingthe extension. The following C99 features must not be used anywhere in the codebase:@itemize @bullet@itemvariable-length arrays; @itemcomplex numbers; @itemmixed statements and declarations.@end itemize @subsection SIMD/DSP@anchor{SIMD/DSP} As modern compilers are unable to generate efficient SIMD or otherperformance-critical DSP code from plain C, handwritten assembly is used.Usually such code is isolated in a separate function. Then the standard approachis writing multiple versions of this function – a plain C one that workseverywhere and may also be useful for debugging, and potentially multiplearchitecture-specific optimized implementations. Initialization code thenchooses the best available version at runtime and loads it into a functionpointer; the function in question is then always called through this pointer. The specific syntax used for writing assembly is:@itemize @bullet@itemNASM on x86; @itemGAS on ARM and RISC-V.@end itemize A unit testing framework for assembly called @code{checkasm} lives under@file{tests/checkasm}. All new assembly should come with @code{checkasm} tests;adding tests for existing assembly that lacks them is also strongly encouraged. @subsection Other languages Other languages than C may be used in special cases:@itemize @bullet@itemCompiler intrinsics or inline assembly when the code in question cannot bewritten in the standard way described in the @ref{SIMD/DSP} section. Thistypically applies to code that needs to be inlined. @itemObjective-C where required for interacting with macOS-specific interfaces.@end itemize @section Code formatting conventions There are the following guidelines regarding the code style in files: @itemize @bullet@itemIndent size is 4. @itemThe TAB character is forbidden outside of Makefiles as is anyform of trailing whitespace. Commits containing either will berejected by the git repository. @itemYou should try to limit your code lines to 80 characters; however, do so ifand only if this improves readability. @itemK&R coding style is used.@end itemizeThe presentation is one inspired by 'indent -i4 -kr -nut'. @subsection ExamplesSome notable examples to illustrate common code style in FFmpeg: @itemize @bullet @itemSpace around assignments and after@code{if}/@code{do}/@code{while}/@code{for} keywords: @example c, good// Goodif (condition) av_foo();@end example @example c, good// Goodfor (size_t i = 0; i < len; i++) av_bar(i);@end example @example c, good// Goodsize_t size = 0;@end example However no spaces between the parentheses and condition, unless it helpsreadability of complex conditions, so the following should not be done: @example c, bad// Bad styleif ( condition ) av_foo();@end example @itemNo unnecessary parentheses, unless it helps readability: @example c, good// Goodint fields = ilace ? 2 : 1;@end example @itemNo braces around single-line blocks: @example c, good// Goodif (bits_pixel == 24) avctx->pix_fmt = AV_PIX_FMT_BGR24;else if (bits_pixel == 8) avctx->pix_fmt = AV_PIX_FMT_GRAY8;else @{ av_log(avctx, AV_LOG_ERROR, "Invalid pixel format.\n"); return AVERROR_INVALIDDATA;@}@end example @itemAvoid assignments in conditions where it makes sense: @example c, good// Goodvideo_enc->chroma_intra_matrix = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64)if (!video_enc->chroma_intra_matrix) return AVERROR(ENOMEM);@end example @example c, bad// Bad styleif (!(video_enc->chroma_intra_matrix = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64))) return AVERROR(ENOMEM);@end example @example c, good// Okwhile ((entry = av_dict_iterate(options, entry))) av_log(ctx, AV_LOG_INFO, "Item '%s': '%s'\n", entry->key, entry->value);@end example @itemWhen declaring a pointer variable, the @code{*} goes with the variable not the type: @example c, good// GoodAVStream *stream;@end example @example c, bad// Bad styleAVStream* stream;@end example @end itemize If you work on a file that does not follow these guidelines consistently,change the parts that you are editing to follow these guidelines but donot make unrelated changes in the file to make it conform to these. @subsection Vim configurationIn order to configure Vim to follow FFmpeg formatting conventions, pastethe following snippet into your @file{.vimrc}:@example" indentation rules for FFmpeg: 4 spaces, no tabsset expandtabset shiftwidth=4set softtabstop=4set cindentset cinoptions=(0" Allow tabs in Makefiles.autocmd FileType make,automake set noexpandtab shiftwidth=8 softtabstop=8" Trailing whitespace and tabs are forbidden, so highlight them.highlight ForbiddenWhitespace ctermbg=red guibg=redmatch ForbiddenWhitespace /\s\+$\|\t/" Do not highlight spaces at the end of line while typing on that line.autocmd InsertEnter * match ForbiddenWhitespace /\t\|\s\+\%#\@@<!$/@end example @subsection Emacs configurationFor Emacs, add these roughly equivalent lines to your @file{.emacs.d/init.el}:@lisp(c-add-style "ffmpeg" '("k&r" (c-basic-offset . 4) (indent-tabs-mode . nil) (show-trailing-whitespace . t) (c-offsets-alist (statement-cont . (c-lineup-assignments +))) ) )(setq c-default-style "ffmpeg")@end lisp @section CommentsUse the JavaDoc/Doxygen format (see examples below) so that code documentationcan be generated automatically. All nontrivial functions should have a commentabove them explaining what the function does, even if it is just one sentence.All structures and their member variables should be documented, too. Avoid Qt-style and similar Doxygen syntax with @code{!} in it, i.e. replace@code{//!} with @code{///} and similar. Also @@ syntax should be employedfor markup commands, i.e. use @code{@@param} and not @code{\param}. @example/** * @@file * MPEG codec. * @@author ... */ /** * Summary sentence. * more text ... * ... */typedef struct Foobar @{ int var1; /**< var1 description */ int var2; ///< var2 description /** var3 description */ int var3;@} Foobar; /** * Summary sentence. * more text ... * ... * @@param my_parameter description of my_parameter * @@return return value description */int myfunc(int my_parameter)...@end example @anchor{Naming conventions}@section Naming conventions Names of functions, variables, and struct members must be lowercase, usingunderscores (_) to separate words. For example, @samp{avfilter_get_video_buffer}is an acceptable function name and @samp{AVFilterGetVideo} is not. Struct, union, enum, and typedeffed type names must use CamelCase. All structsand unions should be typedeffed to the same name as the struct/union tag, e.g.@code{typedef struct AVFoo @{ ... @} AVFoo;}. Enums are typically nottypedeffed. Enumeration constants and macros must be UPPERCASE, except for macrosmasquerading as functions, which should use the function naming convention. All identifiers in the libraries should be namespaced as follows:@itemize @bullet@itemNo namespacing for identifiers with file and lower scope (e.g. local variables,static functions), and struct and union members, @itemThe @code{ff_} prefix must be used for variables and functions visible outsideof file scope, but only used internally within a single library, e.g.@samp{ff_w64_demuxer}. This prevents name collisions when FFmpeg is staticallylinked. @itemFor variables and functions visible outside of file scope, used internallyacross multiple libraries, use @code{avpriv_} as prefix, for example,@samp{avpriv_report_missing_feature}. @itemAll other internal identifiers, like private type or macro names, should benamespaced only to avoid possible internal conflicts. E.g. @code{H264_NAL_SPS}vs. @code{HEVC_NAL_SPS}. @itemEach library has its own prefix for public symbols, in addition to thecommonly used @code{av_} (@code{avformat_} for libavformat,@code{avcodec_} for libavcodec, @code{swr_} for libswresample, etc).Check the existing code and choose names accordingly. @itemOther public identifiers (struct, union, enum, macro, type names) must use theirlibrary's public prefix (@code{AV}, @code{Sws}, or @code{Swr}).@end itemize Furthermore, name space reserved for the system should not be invaded.Identifiers ending in @code{_t} are reserved by@url{http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_02.html#tag_02_02_02, POSIX}.Also avoid names starting with @code{__} or @code{_} followed by an uppercaseletter as they are reserved by the C standard. Names starting with @code{_}are reserved at the file level and may not be used for externally visiblesymbols. If in doubt, just avoid names starting with @code{_} altogether. @section Miscellaneous conventions @itemize @bullet@itemCasts should be used only when necessary. Unneeded parenthesesshould also be avoided if they don't make the code easier to understand.@end itemize @anchor{Development Policy}@chapter Development Policy @section Code behaviour @subheading CorrectnessThe code must be valid. It must not crash, abort, access invalid pointers, leakmemory, cause data races or signed integer overflow, or otherwise causeundefined behaviour. Error codes should be checked and, when applicable,forwarded to the caller. @subheading Thread- and library-safetyOur libraries may be called by multiple independent callers in the same process.These calls may happen from any number of threads and the different call sitesmay not be aware of each other - e.g. a user program may be calling ourlibraries directly, and use one or more libraries that also call our libraries.The code must behave correctly under such conditions. @subheading RobustnessThe code must treat as untrusted any bytestream received from a caller or readfrom a file, network, etc. It must not misbehave when arbitrary data is sent toit - typically it should print an error message and return@code{AVERROR_INVALIDDATA} on encountering invalid input data. @subheading Memory allocationThe code must use the @code{av_malloc()} family of functions from@file{libavutil/mem.h} to perform all memory allocation, except in special cases(e.g. when interacting with an external library that requires a specificallocator to be used). All allocations should be checked and @code{AVERROR(ENOMEM)} returned onfailure. A common mistake is that error paths leak memory - make sure that doesnot happen. @subheading stdioOur libraries must not access the stdio streams stdin/stdout/stderr directly(e.g. via @code{printf()} family of functions), as that is not library-safe. Forlogging, use @code{av_log()}. @section Patches/Committing@subheading Licenses for patches must be compatible with FFmpeg.Contributions should be licensed under the@uref{http://www.gnu.org/licenses/lgpl-2.1.html, LGPL 2.1},including an "or any later version" clause, or, if you prefera gift-style license, the@uref{http://opensource.org/licenses/isc-license.txt, ISC} or@uref{http://mit-license.org/, MIT} license.@uref{http://www.gnu.org/licenses/gpl-2.0.html, GPL 2} includingan "or any later version" clause is also acceptable, but LGPL ispreferred.If you add a new file, give it a proper license header. Do not copy andpaste it from a random place, use an existing file as template. @subheading You must not commit code which breaks FFmpeg!This means unfinished code which is enabled and breaks compilation,or compiles but does not work/breaks the regression tests. Code whichis unfinished but disabled may be permitted under-circumstances, likemissing samples or an implementation with a small subset of features.Always check the mailing list for any reviewers with issues and testFATE before you push. @subheading Commit messagesCommit messages are highly important tools for informing other developers onwhat a given change does and why. Every commit must always have a properlyfilled out commit message with the following format:@examplearea changed: short 1 line description details describing what and why and giving references.@end example If the commit addresses a known bug on our bug tracker or other external issue(e.g. CVE), the commit message should include the relevant bug ID(s) or otherexternal identifiers. Note that this should be done in addition to a properexplanation and not instead of it. Comments such as "fixed!" or "Changed it."are not acceptable. When applying patches that have been discussed at length on the mailing list,reference the thread in the commit message. @subheading Testing must be adequate but not excessive.If it works for you, others, and passes FATE then it should be OK to commitit, provided it fits the other committing criteria. You should not worry aboutover-testing things. If your code has problems (portability, triggerscompiler bugs, unusual environment etc) they will be reported and eventuallyfixed. @subheading Do not commit unrelated changes together.They should be split them into self-contained pieces. Also do not forgetthat if part B depends on part A, but A does not depend on B, then A canand should be committed first and separate from B. Keeping changes wellsplit into self-contained parts makes reviewing and understanding them onthe commit log mailing list easier. This also helps in case of debugginglater on.Also if you have doubts about splitting or not splitting, do not hesitate toask/discuss it on the developer mailing list. @subheading Cosmetic changes should be kept in separate patches.We refuse source indentation and other cosmetic changes if they are mixedwith functional changes, such commits will be rejected and removed. Everydeveloper has his own indentation style, you should not change it. Of courseif you (re)write something, you can use your own style, even though we wouldprefer if the indentation throughout FFmpeg was consistent (Many projectsforce a given indentation style - we do not.). If you really need to makeindentation changes (try to avoid this), separate them strictly from realchanges. NOTE: If you had to put if()@{ .. @} over a large (> 5 lines) chunk of code,then either do NOT change the indentation of the inner part within (do notmove it to the right)! or do so in a separate commit @subheading Credit the author of the patch.Make sure the author of the commit is set correctly. (see git commit --author)If you apply a patch, send ananswer to ffmpeg-devel (or wherever you got the patch from) saying thatyou applied the patch. @subheading Credit any researchersIf a commit/patch fixes an issues found by some researcher, always credit theresearcher in the commit message for finding/reporting the issue. @subheading Always wait long enough before pushing changesDo NOT commit to code actively maintained by others without permission.Send a patch to ffmpeg-devel. If no one answers within a reasonabletime-frame (12h for build failures and security fixes, 3 days small changes,1 week for big patches) then commit your patch if you think it is OK.Lines 1–500 of 1149. Load more
\input texinfo @c -*- texinfo -*- @documentencoding UTF-8 @settitle Developer Documentation @titlepage @center @titlefont{Developer Documentation} @end titlepage @top @contents @chapter Introduction This text is concerned with the development @emph{of} FFmpeg itself. Information on using the FFmpeg libraries in other programs can be found elsewhere, e.g. in: @itemize @bullet @item the installed header files @item @url{http://ffmpeg.org/doxygen/trunk/index.html, the Doxygen documentation} generated from the headers @item the examples under @file{doc/examples} @end itemize For more detailed legal information about the use of FFmpeg in external programs read the @file{LICENSE} file in the source tree and consult @url{https://ffmpeg.org/legal.html}. If you modify FFmpeg code for your own use case, you are highly encouraged to @emph{submit your changes back to us}, using this document as a guide. There are both pragmatic and ideological reasons to do so: @itemize @bullet @item Maintaining external changes to keep up with upstream development is time-consuming and error-prone. With your code in the main tree, it will be maintained by FFmpeg developers. @item FFmpeg developers include leading experts in the field who can find bugs or design flaws in your code. @item By supporting the project you find useful you ensure it continues to be maintained and developed. @end itemize All proposed code changes should be submitted for review to @url{mailto:ffmpeg-devel@@ffmpeg.org, the development mailing list}, as described in more detail in the @ref{Submitting patches} chapter. The code should comply with the @ref{Development Policy} and follow the @ref{Coding Rules}. The developer making the commit and the author are responsible for their changes and should try to fix issues their commit causes. @anchor{Coding Rules} @chapter Coding Rules @section Language FFmpeg is mainly programmed in the ISO C11 language, except for the public headers which must stay C99 compatible. Compiler-specific extensions may be used with good reason, but must not be depended on, i.e. the code must still compile and work with compilers lacking the extension. The following C99 features must not be used anywhere in the codebase: @itemize @bullet @item variable-length arrays; @item complex numbers; @item mixed statements and declarations. @end itemize @subsection SIMD/DSP @anchor{SIMD/DSP} As modern compilers are unable to generate efficient SIMD or other performance-critical DSP code from plain C, handwritten assembly is used. Usually such code is isolated in a separate function. Then the standard approach is writing multiple versions of this function – a plain C one that works everywhere and may also be useful for debugging, and potentially multiple architecture-specific optimized implementations. Initialization code then chooses the best available version at runtime and loads it into a function pointer; the function in question is then always called through this pointer. The specific syntax used for writing assembly is: @itemize @bullet @item NASM on x86; @item GAS on ARM and RISC-V. @end itemize A unit testing framework for assembly called @code{checkasm} lives under @file{tests/checkasm}. All new assembly should come with @code{checkasm} tests; adding tests for existing assembly that lacks them is also strongly encouraged. @subsection Other languages Other languages than C may be used in special cases: @itemize @bullet @item Compiler intrinsics or inline assembly when the code in question cannot be written in the standard way described in the @ref{SIMD/DSP} section. This typically applies to code that needs to be inlined. @item Objective-C where required for interacting with macOS-specific interfaces. @end itemize @section Code formatting conventions There are the following guidelines regarding the code style in files: @itemize @bullet @item Indent size is 4. @item The TAB character is forbidden outside of Makefiles as is any form of trailing whitespace. Commits containing either will be rejected by the git repository. @item You should try to limit your code lines to 80 characters; however, do so if and only if this improves readability. @item K&R coding style is used. @end itemize The presentation is one inspired by 'indent -i4 -kr -nut'. @subsection Examples Some notable examples to illustrate common code style in FFmpeg: @itemize @bullet @item Space around assignments and after @code{if}/@code{do}/@code{while}/@code{for} keywords: @example c, good // Good if (condition) av_foo(); @end example @example c, good // Good for (size_t i = 0; i < len; i++) av_bar(i); @end example @example c, good // Good size_t size = 0; @end example However no spaces between the parentheses and condition, unless it helps readability of complex conditions, so the following should not be done: @example c, bad // Bad style if ( condition ) av_foo(); @end example @item No unnecessary parentheses, unless it helps readability: @example c, good // Good int fields = ilace ? 2 : 1; @end example @item No braces around single-line blocks: @example c, good // Good if (bits_pixel == 24) avctx->pix_fmt = AV_PIX_FMT_BGR24; else if (bits_pixel == 8) avctx->pix_fmt = AV_PIX_FMT_GRAY8; else @{ av_log(avctx, AV_LOG_ERROR, "Invalid pixel format.\n"); return AVERROR_INVALIDDATA; @} @end example @item Avoid assignments in conditions where it makes sense: @example c, good // Good video_enc->chroma_intra_matrix = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64) if (!video_enc->chroma_intra_matrix) return AVERROR(ENOMEM); @end example @example c, bad // Bad style if (!(video_enc->chroma_intra_matrix = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64))) return AVERROR(ENOMEM); @end example @example c, good // Ok while ((entry = av_dict_iterate(options, entry))) av_log(ctx, AV_LOG_INFO, "Item '%s': '%s'\n", entry->key, entry->value); @end example @item When declaring a pointer variable, the @code{*} goes with the variable not the type: @example c, good // Good AVStream *stream; @end example @example c, bad // Bad style AVStream* stream; @end example @end itemize If you work on a file that does not follow these guidelines consistently, change the parts that you are editing to follow these guidelines but do not make unrelated changes in the file to make it conform to these. @subsection Vim configuration In order to configure Vim to follow FFmpeg formatting conventions, paste the following snippet into your @file{.vimrc}: @example " indentation rules for FFmpeg: 4 spaces, no tabs set expandtab set shiftwidth=4 set softtabstop=4 set cindent set cinoptions=(0 " Allow tabs in Makefiles. autocmd FileType make,automake set noexpandtab shiftwidth=8 softtabstop=8 " Trailing whitespace and tabs are forbidden, so highlight them. highlight ForbiddenWhitespace ctermbg=red guibg=red match ForbiddenWhitespace /\s\+$\|\t/ " Do not highlight spaces at the end of line while typing on that line. autocmd InsertEnter * match ForbiddenWhitespace /\t\|\s\+\%#\@@<!$/ @end example @subsection Emacs configuration For Emacs, add these roughly equivalent lines to your @file{.emacs.d/init.el}: @lisp (c-add-style "ffmpeg" '("k&r" (c-basic-offset . 4) (indent-tabs-mode . nil) (show-trailing-whitespace . t) (c-offsets-alist (statement-cont . (c-lineup-assignments +))) ) ) (setq c-default-style "ffmpeg") @end lisp @section Comments Use the JavaDoc/Doxygen format (see examples below) so that code documentation can be generated automatically. All nontrivial functions should have a comment above them explaining what the function does, even if it is just one sentence. All structures and their member variables should be documented, too. Avoid Qt-style and similar Doxygen syntax with @code{!} in it, i.e. replace @code{//!} with @code{///} and similar. Also @@ syntax should be employed for markup commands, i.e. use @code{@@param} and not @code{\param}. @example /** * @@file * MPEG codec. * @@author ... */ /** * Summary sentence. * more text ... * ... */ typedef struct Foobar @{ int var1; /**< var1 description */ int var2; ///< var2 description /** var3 description */ int var3; @} Foobar; /** * Summary sentence. * more text ... * ... * @@param my_parameter description of my_parameter * @@return return value description */ int myfunc(int my_parameter) ... @end example @anchor{Naming conventions} @section Naming conventions Names of functions, variables, and struct members must be lowercase, using underscores (_) to separate words. For example, @samp{avfilter_get_video_buffer} is an acceptable function name and @samp{AVFilterGetVideo} is not. Struct, union, enum, and typedeffed type names must use CamelCase. All structs and unions should be typedeffed to the same name as the struct/union tag, e.g. @code{typedef struct AVFoo @{ ... @} AVFoo;}. Enums are typically not typedeffed. Enumeration constants and macros must be UPPERCASE, except for macros masquerading as functions, which should use the function naming convention. All identifiers in the libraries should be namespaced as follows: @itemize @bullet @item No namespacing for identifiers with file and lower scope (e.g. local variables, static functions), and struct and union members, @item The @code{ff_} prefix must be used for variables and functions visible outside of file scope, but only used internally within a single library, e.g. @samp{ff_w64_demuxer}. This prevents name collisions when FFmpeg is statically linked. @item For variables and functions visible outside of file scope, used internally across multiple libraries, use @code{avpriv_} as prefix, for example, @samp{avpriv_report_missing_feature}. @item All other internal identifiers, like private type or macro names, should be namespaced only to avoid possible internal conflicts. E.g. @code{H264_NAL_SPS} vs. @code{HEVC_NAL_SPS}. @item Each library has its own prefix for public symbols, in addition to the commonly used @code{av_} (@code{avformat_} for libavformat, @code{avcodec_} for libavcodec, @code{swr_} for libswresample, etc). Check the existing code and choose names accordingly. @item Other public identifiers (struct, union, enum, macro, type names) must use their library's public prefix (@code{AV}, @code{Sws}, or @code{Swr}). @end itemize Furthermore, name space reserved for the system should not be invaded. Identifiers ending in @code{_t} are reserved by @url{http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_02.html#tag_02_02_02, POSIX}. Also avoid names starting with @code{__} or @code{_} followed by an uppercase letter as they are reserved by the C standard. Names starting with @code{_} are reserved at the file level and may not be used for externally visible symbols. If in doubt, just avoid names starting with @code{_} altogether. @section Miscellaneous conventions @itemize @bullet @item Casts should be used only when necessary. Unneeded parentheses should also be avoided if they don't make the code easier to understand. @end itemize @anchor{Development Policy} @chapter Development Policy @section Code behaviour @subheading Correctness The code must be valid. It must not crash, abort, access invalid pointers, leak memory, cause data races or signed integer overflow, or otherwise cause undefined behaviour. Error codes should be checked and, when applicable, forwarded to the caller. @subheading Thread- and library-safety Our libraries may be called by multiple independent callers in the same process. These calls may happen from any number of threads and the different call sites may not be aware of each other - e.g. a user program may be calling our libraries directly, and use one or more libraries that also call our libraries. The code must behave correctly under such conditions. @subheading Robustness The code must treat as untrusted any bytestream received from a caller or read from a file, network, etc. It must not misbehave when arbitrary data is sent to it - typically it should print an error message and return @code{AVERROR_INVALIDDATA} on encountering invalid input data. @subheading Memory allocation The code must use the @code{av_malloc()} family of functions from @file{libavutil/mem.h} to perform all memory allocation, except in special cases (e.g. when interacting with an external library that requires a specific allocator to be used). All allocations should be checked and @code{AVERROR(ENOMEM)} returned on failure. A common mistake is that error paths leak memory - make sure that does not happen. @subheading stdio Our libraries must not access the stdio streams stdin/stdout/stderr directly (e.g. via @code{printf()} family of functions), as that is not library-safe. For logging, use @code{av_log()}. @section Patches/Committing @subheading Licenses for patches must be compatible with FFmpeg. Contributions should be licensed under the @uref{http://www.gnu.org/licenses/lgpl-2.1.html, LGPL 2.1}, including an "or any later version" clause, or, if you prefer a gift-style license, the @uref{http://opensource.org/licenses/isc-license.txt, ISC} or @uref{http://mit-license.org/, MIT} license. @uref{http://www.gnu.org/licenses/gpl-2.0.html, GPL 2} including an "or any later version" clause is also acceptable, but LGPL is preferred. If you add a new file, give it a proper license header. Do not copy and paste it from a random place, use an existing file as template. @subheading You must not commit code which breaks FFmpeg! This means unfinished code which is enabled and breaks compilation, or compiles but does not work/breaks the regression tests. Code which is unfinished but disabled may be permitted under-circumstances, like missing samples or an implementation with a small subset of features. Always check the mailing list for any reviewers with issues and test FATE before you push. @subheading Commit messages Commit messages are highly important tools for informing other developers on what a given change does and why. Every commit must always have a properly filled out commit message with the following format: @example area changed: short 1 line description details describing what and why and giving references. @end example If the commit addresses a known bug on our bug tracker or other external issue (e.g. CVE), the commit message should include the relevant bug ID(s) or other external identifiers. Note that this should be done in addition to a proper explanation and not instead of it. Comments such as "fixed!" or "Changed it." are not acceptable. When applying patches that have been discussed at length on the mailing list, reference the thread in the commit message. @subheading Testing must be adequate but not excessive. If it works for you, others, and passes FATE then it should be OK to commit it, provided it fits the other committing criteria. You should not worry about over-testing things. If your code has problems (portability, triggers compiler bugs, unusual environment etc) they will be reported and eventually fixed. @subheading Do not commit unrelated changes together. They should be split them into self-contained pieces. Also do not forget that if part B depends on part A, but A does not depend on B, then A can and should be committed first and separate from B. Keeping changes well split into self-contained parts makes reviewing and understanding them on the commit log mailing list easier. This also helps in case of debugging later on. Also if you have doubts about splitting or not splitting, do not hesitate to ask/discuss it on the developer mailing list. @subheading Cosmetic changes should be kept in separate patches. We refuse source indentation and other cosmetic changes if they are mixed with functional changes, such commits will be rejected and removed. Every developer has his own indentation style, you should not change it. Of course if you (re)write something, you can use your own style, even though we would prefer if the indentation throughout FFmpeg was consistent (Many projects force a given indentation style - we do not.). If you really need to make indentation changes (try to avoid this), separate them strictly from real changes. NOTE: If you had to put if()@{ .. @} over a large (> 5 lines) chunk of code, then either do NOT change the indentation of the inner part within (do not move it to the right)! or do so in a separate commit @subheading Credit the author of the patch. Make sure the author of the commit is set correctly. (see git commit --author) If you apply a patch, send an answer to ffmpeg-devel (or wherever you got the patch from) saying that you applied the patch. @subheading Credit any researchers If a commit/patch fixes an issues found by some researcher, always credit the researcher in the commit message for finding/reporting the issue. @subheading Always wait long enough before pushing changes Do NOT commit to code actively maintained by others without permission. Send a patch to ffmpeg-devel. If no one answers within a reasonable time-frame (12h for build failures and security fixes, 3 days small changes, 1 week for big patches) then commit your patch if you think it is OK.