ARM: check for VFP register arguments
[libav.git] / doc / developer.texi
CommitLineData
a752069d
DB
1\input texinfo @c -*- texinfo -*-
2
3@settitle Developer Documentation
4@titlepage
5@sp 7
6@center @titlefont{Developer Documentation}
7@sp 3
8@end titlepage
9
10
11@chapter Developers Guide
12
13@section API
14@itemize @bullet
15@item libavcodec is the library containing the codecs (both encoding and
16decoding). Look at @file{libavcodec/apiexample.c} to see how to use it.
17
18@item libavformat is the library containing the file format handling (mux and
19demux code for several formats). Look at @file{ffplay.c} to use it in a
20player. See @file{libavformat/output-example.c} to use it to generate
21audio or video streams.
22
23@end itemize
24
25@section Integrating libavcodec or libavformat in your program
26
27You can integrate all the source code of the libraries to link them
28statically to avoid any version problem. All you need is to provide a
29'config.mak' and a 'config.h' in the parent directory. See the defines
30generated by ./configure to understand what is needed.
31
32You can use libavcodec or libavformat in your commercial program, but
33@emph{any patch you make must be published}. The best way to proceed is
34to send your patches to the FFmpeg mailing list.
35
36@node Coding Rules
37@section Coding Rules
38
39FFmpeg is programmed in the ISO C90 language with a few additional
40features from ISO C99, namely:
41@itemize @bullet
42@item
43the @samp{inline} keyword;
44@item
45@samp{//} comments;
46@item
47designated struct initializers (@samp{struct s x = @{ .i = 17 @};})
48@item
49compound literals (@samp{x = (struct s) @{ 17, 23 @};})
50@end itemize
51
52These features are supported by all compilers we care about, so we will not
53accept patches to remove their use unless they absolutely do not impair
54clarity and performance.
55
56All code must compile with GCC 2.95 and GCC 3.3. Currently, FFmpeg also
57compiles with several other compilers, such as the Compaq ccc compiler
58or Sun Studio 9, and we would like to keep it that way unless it would
59be exceedingly involved. To ensure compatibility, please do not use any
60additional C99 features or GCC extensions. Especially watch out for:
61@itemize @bullet
62@item
63mixing statements and declarations;
64@item
65@samp{long long} (use @samp{int64_t} instead);
66@item
67@samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar;
68@item
69GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}).
70@end itemize
71
72Indent size is 4.
73The presentation is the one specified by 'indent -i4 -kr -nut'.
74The TAB character is forbidden outside of Makefiles as is any
75form of trailing whitespace. Commits containing either will be
76rejected by the Subversion repository.
77
78The main priority in FFmpeg is simplicity and small code size in order to
79minimize the bug count.
80
81Comments: Use the JavaDoc/Doxygen
82format (see examples below) so that code documentation
83can be generated automatically. All nontrivial functions should have a comment
84above them explaining what the function does, even if it is just one sentence.
85All structures and their member variables should be documented, too.
86@example
87/**
88 * @@file mpeg.c
89 * MPEG codec.
90 * @@author ...
91 */
92
93/**
94 * Summary sentence.
95 * more text ...
96 * ...
97 */
98typedef struct Foobar@{
99 int var1; /**< var1 description */
100 int var2; ///< var2 description
101 /** var3 description */
102 int var3;
103@} Foobar;
104
105/**
106 * Summary sentence.
107 * more text ...
108 * ...
109 * @@param my_parameter description of my_parameter
110 * @@return return value description
111 */
112int myfunc(int my_parameter)
113...
114@end example
115
116fprintf and printf are forbidden in libavformat and libavcodec,
117please use av_log() instead.
118
119Casts should be used only when necessary. Unneeded parentheses
120should also be avoided if they don't make the code easier to understand.
121
122@section Development Policy
123
124@enumerate
125@item
126 Contributions should be licensed under the LGPL 2.1, including an
127 "or any later version" clause, or the MIT license. GPL 2 including
128 an "or any later version" clause is also acceptable, but LGPL is
129 preferred.
130@item
131 You must not commit code which breaks FFmpeg! (Meaning unfinished but
132 enabled code which breaks compilation or compiles but does not work or
133 breaks the regression tests)
134 You can commit unfinished stuff (for testing etc), but it must be disabled
135 (#ifdef etc) by default so it does not interfere with other developers'
136 work.
137@item
138 You do not have to over-test things. If it works for you, and you think it
139 should work for others, then commit. If your code has problems
140 (portability, triggers compiler bugs, unusual environment etc) they will be
141 reported and eventually fixed.
142@item
143 Do not commit unrelated changes together, split them into self-contained
144 pieces. Also do not forget that if part B depends on part A, but A does not
145 depend on B, then A can and should be committed first and separate from B.
146 Keeping changes well split into self-contained parts makes reviewing and
147 understanding them on the commit log mailing list easier. This also helps
148 in case of debugging later on.
149 Also if you have doubts about splitting or not splitting, do not hesitate to
150 ask/discuss it on the developer mailing list.
151@item
152 Do not change behavior of the program (renaming options etc) without
153 first discussing it on the ffmpeg-devel mailing list. Do not remove
154 functionality from the code. Just improve!
155
156 Note: Redundant code can be removed.
157@item
158 Do not commit changes to the build system (Makefiles, configure script)
159 which change behavior, defaults etc, without asking first. The same
160 applies to compiler warning fixes, trivial looking fixes and to code
161 maintained by other developers. We usually have a reason for doing things
162 the way we do. Send your changes as patches to the ffmpeg-devel mailing
163 list, and if the code maintainers say OK, you may commit. This does not
164 apply to files you wrote and/or maintain.
165@item
166 We refuse source indentation and other cosmetic changes if they are mixed
167 with functional changes, such commits will be rejected and removed. Every
168 developer has his own indentation style, you should not change it. Of course
169 if you (re)write something, you can use your own style, even though we would
170 prefer if the indentation throughout FFmpeg was consistent (Many projects
171 force a given indentation style - we do not.). If you really need to make
172 indentation changes (try to avoid this), separate them strictly from real
173 changes.
174
175 NOTE: If you had to put if()@{ .. @} over a large (> 5 lines) chunk of code,
176 then either do NOT change the indentation of the inner part within (do not
177 move it to the right)! or do so in a separate commit
178@item
179 Always fill out the commit log message. Describe in a few lines what you
180 changed and why. You can refer to mailing list postings if you fix a
181 particular bug. Comments such as "fixed!" or "Changed it." are unacceptable.
182@item
183 If you apply a patch by someone else, include the name and email address in
184 the log message. Since the ffmpeg-cvslog mailing list is publicly
185 archived you should add some SPAM protection to the email address. Send an
186 answer to ffmpeg-devel (or wherever you got the patch from) saying that
187 you applied the patch.
188@item
189 When applying patches that have been discussed (at length) on the mailing
190 list, reference the thread in the log message.
191@item
192 Do NOT commit to code actively maintained by others without permission.
193 Send a patch to ffmpeg-devel instead. If no one answers within a reasonable
194 timeframe (12h for build failures and security fixes, 3 days small changes,
195 1 week for big patches) then commit your patch if you think it is OK.
196 Also note, the maintainer can simply ask for more time to review!
197@item
198 Subscribe to the ffmpeg-cvslog mailing list. The diffs of all commits
199 are sent there and reviewed by all the other developers. Bugs and possible
200 improvements or general questions regarding commits are discussed there. We
201 expect you to react if problems with your code are uncovered.
202@item
203 Update the documentation if you change behavior or add features. If you are
204 unsure how best to do this, send a patch to ffmpeg-devel, the documentation
205 maintainer(s) will review and commit your stuff.
206@item
207 Try to keep important discussions and requests (also) on the public
208 developer mailing list, so that all developers can benefit from them.
209@item
210 Never write to unallocated memory, never write over the end of arrays,
211 always check values read from some untrusted source before using them
212 as array index or other risky things.
213@item
214 Remember to check if you need to bump versions for the specific libav
215 parts (libavutil, libavcodec, libavformat) you are changing. You need
216 to change the version integer.
217 Incrementing the first component means no backward compatibility to
218 previous versions (e.g. removal of a function from the public API).
219 Incrementing the second component means backward compatible change
220 (e.g. addition of a function to the public API or extension of an
221 existing data structure).
222 Incrementing the third component means a noteworthy binary compatible
223 change (e.g. encoder bug fix that matters for the decoder).
224@item
225 Compiler warnings indicate potential bugs or code with bad style. If a type of
226 warning always points to correct and clean code, that warning should
227 be disabled, not the code changed.
228 Thus the remaining warnings can either be bugs or correct code.
229 If it is a bug, the bug has to be fixed. If it is not, the code should
230 be changed to not generate a warning unless that causes a slowdown
231 or obfuscates the code.
232@item
233 If you add a new file, give it a proper license header. Do not copy and
234 paste it from a random place, use an existing file as template.
235@end enumerate
236
237We think our rules are not too hard. If you have comments, contact us.
238
239Note, these rules are mostly borrowed from the MPlayer project.
240
241@section Submitting patches
242
243First, (@pxref{Coding Rules}) above if you did not yet.
244
245When you submit your patch, try to send a unified diff (diff '-up'
246option). We cannot read other diffs :-)
247
248Also please do not submit a patch which contains several unrelated changes.
249Split it into separate, self-contained pieces. This does not mean splitting
250file by file. Instead, make the patch as small as possible while still
251keeping it as a logical unit that contains an individual change, even
252if it spans multiple files. This makes reviewing your patches much easier
253for us and greatly increases your chances of getting your patch applied.
254
255Run the regression tests before submitting a patch so that you can
256verify that there are no big problems.
257
258Patches should be posted as base64 encoded attachments (or any other
259encoding which ensures that the patch will not be trashed during
260transmission) to the ffmpeg-devel mailing list, see
261@url{http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel}
262
263It also helps quite a bit if you tell us what the patch does (for example
264'replaces lrint by lrintf'), and why (for example '*BSD isn't C99 compliant
265and has no lrint()')
266
267Also please if you send several patches, send each patch as a separate mail,
268do not attach several unrelated patches to the same mail.
269
270@section New codecs or formats checklist
271
272@enumerate
273@item
274 Did you use av_cold for codec initialization and close functions?
275@item
276 Did you add a long_name under NULL_IF_CONFIG_SMALL to the AVCodec or
277 AVInputFormat/AVOutputFormat struct?
278@item
279 Did you bump the minor version number in @file{avcodec.h} or
280 @file{avformat.h}?
281@item
282 Did you register it in @file{allcodecs.c} or @file{allformats.c}?
283@item
284 Did you add the CodecID to @file{avcodec.h}?
285@item
286 If it has a fourcc, did you add it to @file{libavformat/riff.c},
287 even if it is only a decoder?
288@item
289 Did you add a rule to compile the appropriate files in the Makefile?
290 Remember to do this even if you're just adding a format to a file that is
291 already being compiled by some other rule, like a raw demuxer.
292@item
293 Did you add an entry to the table of supported formats or codecs in the
294 documentation?
295@item
296 Did you add an entry in the Changelog?
297@item
298 If it depends on a parser or a library, did you add that dependency in
299 configure?
300@item
301 Did you "svn add" the appropriate files before commiting?
302@end enumerate
303
304@section patch submission checklist
305
306@enumerate
307@item
308 Do the regression tests pass with the patch applied?
309@item
310 Does @code{make checkheaders} pass with the patch applied?
311@item
312 Is the patch a unified diff?
313@item
314 Is the patch against latest FFmpeg SVN?
315@item
316 Are you subscribed to ffmpeg-dev?
317 (the list is subscribers only due to spam)
318@item
319 Have you checked that the changes are minimal, so that the same cannot be
320 achieved with a smaller patch and/or simpler final code?
321@item
322 If the change is to speed critical code, did you benchmark it?
323@item
324 If you did any benchmarks, did you provide them in the mail?
325@item
326 Have you checked that the patch does not introduce buffer overflows or
327 other security issues?
328@item
329 Did you test your decoder or demuxer against damaged data? If no, see
330 tools/trasher and the noise bitstream filter. Your decoder or demuxer
331 should not crash or end in a (near) infinite loop when fed damaged data.
332@item
333 Is the patch created from the root of the source tree, so it can be
334 applied with @code{patch -p0}?
335@item
336 Does the patch not mix functional and cosmetic changes?
337@item
338 Did you add tabs or trailing whitespace to the code? Both are forbidden.
339@item
340 Is the patch attached to the email you send?
341@item
342 Is the mime type of the patch correct? It should be text/x-diff or
343 text/x-patch or at least text/plain and not application/octet-stream.
344@item
345 If the patch fixes a bug, did you provide a verbose analysis of the bug?
346@item
347 If the patch fixes a bug, did you provide enough information, including
348 a sample, so the bug can be reproduced and the fix can be verified?
349 Note please do not attach samples >100k to mails but rather provide a
350 URL, you can upload to ftp://upload.ffmpeg.org
351@item
352 Did you provide a verbose summary about what the patch does change?
353@item
354 Did you provide a verbose explanation why it changes things like it does?
355@item
356 Did you provide a verbose summary of the user visible advantages and
357 disadvantages if the patch is applied?
358@item
359 Did you provide an example so we can verify the new feature added by the
360 patch easily?
361@item
362 If you added a new file, did you insert a license header? It should be
363 taken from FFmpeg, not randomly copied and pasted from somewhere else.
364@item
365 You should maintain alphabetical order in alphabetically ordered lists as
366 long as doing so does not break API/ABI compatibility.
367@item
368 Lines with similar content should be aligned vertically when doing so
369 improves readability.
370@item
371 Did you provide a suggestion for a clear commit log message?
372@end enumerate
373
374@section Patch review process
375
376All patches posted to ffmpeg-devel will be reviewed, unless they contain a
377clear note that the patch is not for SVN.
378Reviews and comments will be posted as replies to the patch on the
379mailing list. The patch submitter then has to take care of every comment,
380that can be by resubmitting a changed patch or by discussion. Resubmitted
381patches will themselves be reviewed like any other patch. If at some point
382a patch passes review with no comments then it is approved, that can for
383simple and small patches happen immediately while large patches will generally
384have to be changed and reviewed many times before they are approved.
385After a patch is approved it will be committed to the repository.
386
387We will review all submitted patches, but sometimes we are quite busy so
388especially for large patches this can take several weeks.
389
390When resubmitting patches, please do not make any significant changes
391not related to the comments received during review. Such patches will
392be rejected. Instead, submit significant changes or new features as
393separate patches.
394
395@section Regression tests
396
397Before submitting a patch (or committing to the repository), you should at least
398test that you did not break anything.
399
400The regression tests build a synthetic video stream and a synthetic
401audio stream. These are then encoded and decoded with all codecs or
402formats. The CRC (or MD5) of each generated file is recorded in a
403result file. A 'diff' is launched to compare the reference results and
404the result file.
405
406The regression tests then go on to test the FFserver code with a
407limited set of streams. It is important that this step runs correctly
408as well.
409
410Run 'make test' to test all the codecs and formats.
411
412Run 'make fulltest' to test all the codecs, formats and FFserver.
413
414[Of course, some patches may change the results of the regression tests. In
415this case, the reference results of the regression tests shall be modified
416accordingly].
417
418@bye