32
32
You can use Libav in your commercial program, but you must abide to the
33
33
license, LGPL or GPL depending on the specific features used, please refer
34
to @url{http://libav.org/legal.html} for a quick checklist and to
35
@url{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.GPLv2},
36
@url{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.GPLv3},
37
@url{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.LGPLv2.1},
38
@url{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.LGPLv3} for the
39
exact text of the licenses.
34
to @uref{http://libav.org/legal.html, our legal page} for a quick checklist and to
35
the following links for the exact text of each license:
36
@uref{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.GPLv2, GPL version 2},
37
@uref{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.GPLv3, GPL version 3},
38
@uref{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.LGPLv2.1, LGPL version 2.1},
39
@uref{http://git.libav.org/?p=libav.git;a=blob;f=COPYING.LGPLv3, LGPL version 3}.
40
40
Any modification to the source code can be suggested for inclusion.
41
The best way to proceed is to send your patches to the Libav mailing list.
41
The best way to proceed is to send your patches to the
42
@uref{https://lists.libav.org/mailman/listinfo/libav-devel, libav-devel}
43
45
@anchor{Coding Rules}
44
46
@section Coding Rules
46
Libav is programmed in the ISO C90 language with a few additional
47
features from ISO C99, namely:
50
the @samp{inline} keyword;
54
designated struct initializers (@samp{struct s x = @{ .i = 17 @};})
56
compound literals (@samp{x = (struct s) @{ 17, 23 @};})
59
These features are supported by all compilers we care about, so we will not
60
accept patches to remove their use unless they absolutely do not impair
61
clarity and performance.
63
All code must compile with GCC 2.95 and GCC 3.3. Currently, Libav also
64
compiles with several other compilers, such as the Compaq ccc compiler
65
or Sun Studio 9, and we would like to keep it that way unless it would
66
be exceedingly involved. To ensure compatibility, please do not use any
67
additional C99 features or GCC extensions. Especially watch out for:
70
mixing statements and declarations;
72
@samp{long long} (use @samp{int64_t} instead);
74
@samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar;
76
GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}).
48
@subsection Code formatting conventions
49
The code is written in K&R C style. That means the following:
52
The control statements are formatted by putting space between the statement
53
and parenthesis in the following way:
55
for (i = 0; i < filter->input_count; i++) @{
58
The case statement is always located at the same level as the switch itself:
60
switch (link->init_state) @{
63
case AVLINK_STARTINIT:
64
av_log(filter, AV_LOG_INFO, "circular filter chain detected");
68
Braces in function declarations are written on the new line:
70
const char *avfilter_configuration(void)
72
return LIBAV_CONFIGURATION;
76
In case of a single-statement if, no curly braces are required:
82
Do not put spaces immediately inside parentheses. @samp{if (ret)} is
83
a valid style; @samp{if ( ret )} is not.
86
There are the following guidelines regarding the indentation in files:
80
The presentation is one inspired by 'indent -i4 -kr -nut'.
81
91
The TAB character is forbidden outside of Makefiles as is any
82
92
form of trailing whitespace. Commits containing either will be
83
93
rejected by the git repository.
95
You should try to limit your code lines to 80 characters; however, do so if
96
and only if this improves readability.
98
The presentation is one inspired by 'indent -i4 -kr -nut'.
85
100
The main priority in Libav is simplicity and small code size in order to
86
101
minimize the bug count.
88
Comments: Use the JavaDoc/Doxygen
89
format (see examples below) so that code documentation
104
Use the JavaDoc/Doxygen format (see examples below) so that code documentation
90
105
can be generated automatically. All nontrivial functions should have a comment
91
106
above them explaining what the function does, even if it is just one sentence.
92
107
All structures and their member variables should be documented, too.
109
Avoid Qt-style and similar Doxygen syntax with @code{!} in it, i.e. replace
110
@code{//!} with @code{///} and similar. Also @@ syntax should be employed
111
for markup commands, i.e. use @code{@@param} and not @code{\param}.
143
@subsection C language features
145
Libav is programmed in the ISO C90 language with a few additional
146
features from ISO C99, namely:
149
the @samp{inline} keyword;
153
designated struct initializers (@samp{struct s x = @{ .i = 17 @};})
155
compound literals (@samp{x = (struct s) @{ 17, 23 @};})
158
These features are supported by all compilers we care about, so we will not
159
accept patches to remove their use unless they absolutely do not impair
160
clarity and performance.
162
All code must compile with recent versions of GCC and a number of other
163
currently supported compilers. To ensure compatibility, please do not use
164
additional C99 features or GCC extensions. Especially watch out for:
167
mixing statements and declarations;
169
@samp{long long} (use @samp{int64_t} instead);
171
@samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar;
173
GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}).
176
@subsection Naming conventions
177
All names are using underscores (_), not CamelCase. For example,
178
@samp{avfilter_get_video_buffer} is a valid function name and
179
@samp{AVFilterGetVideo} is not. The only exception from this are structure
180
names; they should always be in the CamelCase
182
There are following conventions for naming variables and functions:
185
For local variables no prefix is required.
187
For variables and functions declared as @code{static} no prefixes are required.
189
For variables and functions used internally by the library, @code{ff_} prefix
191
For example, @samp{ff_w64_demuxer}.
193
For variables and functions used internally across multiple libraries, use
194
@code{avpriv_}. For example, @samp{avpriv_aac_parse_header}.
196
For exported names, each library has its own prefixes. Just check the existing
197
code and name accordingly.
200
@subsection Miscellanous conventions
123
203
fprintf and printf are forbidden in libavformat and libavcodec,
124
204
please use av_log() instead.
126
206
Casts should be used only when necessary. Unneeded parentheses
127
207
should also be avoided if they don't make the code easier to understand.
210
@subsection Editor configuration
211
In order to configure Vim to follow Libav formatting conventions, paste
212
the following snippet into your @file{.vimrc}:
214
" indentation rules for libav: 4 spaces, no tabs
218
" allow tabs in Makefiles
219
autocmd FileType make set noexpandtab shiftwidth=8 softtabstop=8
220
" Trailing whitespace and tabs are forbidden, so highlight them.
221
highlight ForbiddenWhitespace ctermbg=red guibg=red
222
match ForbiddenWhitespace /\s\+$\|\t/
223
" Do not highlight spaces at the end of line while typing on that line.
224
autocmd InsertEnter * match ForbiddenWhitespace /\t\|\s\+\%#\@@<!$/
227
For Emacs, add these roughly equivalent lines to your @file{.emacs.d/init.el}:
229
(setq c-default-style "k&r")
230
(setq-default c-basic-offset 4)
231
(setq-default indent-tabs-mode nil)
232
(setq-default show-trailing-whitespace t)
129
235
@section Development Policy
238
347
Use the patcheck tool of Libav to check your patch.
239
348
The tool is located in the tools directory.
241
Run the @pxref{Regression Tests} before submitting a patch in order to verify
350
Run the @ref{Regression Tests} before submitting a patch in order to verify
242
351
it does not cause unexpected problems.
244
353
Patches should be posted as base64 encoded attachments (or any other
245
354
encoding which ensures that the patch will not be trashed during
246
transmission) to the libav-devel mailing list, see
247
@url{https://lists.libav.org/mailman/listinfo/libav-devel}
356
@uref{https://lists.libav.org/mailman/listinfo/libav-devel, libav-devel}
249
359
It also helps quite a bit if you tell us what the patch does (for example
250
360
'replaces lrint by lrintf'), and why (for example '*BSD isn't C99 compliant