Browse code

lavr: add general API usage doxy

Signed-off-by: Anton Khirnov <anton@khirnov.net>

Anton Khirnov authored on 2012/10/29 06:52:54
Showing 2 changed files
... ...
@@ -23,9 +23,76 @@
23 23
 
24 24
 /**
25 25
  * @file
26
+ * @ingroup lavr
26 27
  * external API header
27 28
  */
28 29
 
30
+/**
31
+ * @defgroup lavr Libavresample
32
+ * @{
33
+ *
34
+ * Libavresample (lavr) is a library that handles audio resampling, sample
35
+ * format conversion and mixing.
36
+ *
37
+ * Interaction with lavr is done through AVAudioResampleContext, which is
38
+ * allocated with avresample_alloc_context(). It is opaque, so all parameters
39
+ * must be set with the @ref avoptions API.
40
+ *
41
+ * For example the following code will setup conversion from planar float sample
42
+ * format to interleaved signed 16-bit integer, downsampling from 48kHz to
43
+ * 44.1kHz and downmixing from 5.1 channels to stereo (using the default mixing
44
+ * matrix):
45
+ * @code
46
+ * AVAudioResampleContext *avr = avresample_alloc_context();
47
+ * av_opt_set_int(avr, "in_channel_layout",  AV_CH_LAYOUT_5POINT1, 0);
48
+ * av_opt_set_int(avr, "out_channel_layout", AV_CH_LAYOUT_STEREO,  0);
49
+ * av_opt_set_int(avr, "in_sample_rate",     48000,                0);
50
+ * av_opt_set_int(avr, "out_sample_rate",    44100,                0);
51
+ * av_opt_set_int(avr, "in_sample_fmt",      AV_SAMPLE_FMT_FLTP,   0);
52
+ * av_opt_set_int(avr, "out_sample_fmt,      AV_SAMPLE_FMT_S16,    0);
53
+ * @endcode
54
+ *
55
+ * Once the context is initialized, it must be opened with avresample_open(). If
56
+ * you need to change the conversion parameters, you must close the context with
57
+ * avresample_close(), change the parameters as described above, then reopen it
58
+ * again.
59
+ *
60
+ * The conversion itself is done by repeatedly calling avresample_convert().
61
+ * Note that the samples may get buffered in two places in lavr. The first one
62
+ * is the output FIFO, where the samples end up if the output buffer is not
63
+ * large enough. The data stored in there may be retrieved at any time with
64
+ * avresample_read(). The second place is the resampling delay buffer,
65
+ * applicable only when resampling is done. The samples in it require more input
66
+ * before they can be processed. Their current amount is returned by
67
+ * avresample_get_delay(). At the end of conversion the resampling buffer can be
68
+ * flushed by calling avresample_convert() with NULL input.
69
+ *
70
+ * The following code demonstrates the conversion loop assuming the parameters
71
+ * from above and caller-defined functions get_input() and handle_output():
72
+ * @code
73
+ * uint8_t **input;
74
+ * int in_linesize, in_samples;
75
+ *
76
+ * while (get_input(&input, &in_linesize, &in_samples)) {
77
+ *     uint8_t *output
78
+ *     int out_linesize;
79
+ *     int out_samples = avresample_available(avr) +
80
+ *                       av_rescale_rnd(avresample_get_delay(avr) +
81
+ *                                      in_samples, 44100, 48000, AV_ROUND_UP);
82
+ *     av_samples_alloc(&output, &out_linesize, 2, out_samples,
83
+ *                      AV_SAMPLE_FMT_S16, 0);
84
+ *     out_samples = avresample_convert(avr, &output, out_linesize, out_samples,
85
+ *                                      input, in_linesize, in_samples);
86
+ *     handle_output(output, out_linesize, out_samples);
87
+ *     av_freep(&output);
88
+ *  }
89
+ *  @endcode
90
+ *
91
+ *  When the conversion is finished and the FIFOs are flushed if required, the
92
+ *  conversion context and everything associated with it must be freed with
93
+ *  avresample_free().
94
+ */
95
+
29 96
 #include "libavutil/audioconvert.h"
30 97
 #include "libavutil/avutil.h"
31 98
 #include "libavutil/dict.h"
... ...
@@ -289,4 +356,8 @@ int avresample_available(AVAudioResampleContext *avr);
289 289
  */
290 290
 int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples);
291 291
 
292
+/**
293
+ * @}
294
+ */
295
+
292 296
 #endif /* AVRESAMPLE_AVRESAMPLE_H */
... ...
@@ -39,6 +39,7 @@
39 39
  * @li @ref libavf "libavformat" I/O and muxing/demuxing library
40 40
  * @li @ref lavd "libavdevice" special devices muxing/demuxing library
41 41
  * @li @ref lavu "libavutil" common utility library
42
+ * @li @ref lavr "libavresample" audio resampling, format conversion and mixing
42 43
  * @li @subpage libswscale  color conversion and scaling library
43 44
  */
44 45