6848
|
1 6. libao2: this control audio playing
|
|
2
|
|
3 As in libvo (see 5.) also here are some drivers, based on the same API:
|
|
4
|
|
5 static int control(int cmd, int arg);
|
|
6 This is for reading/setting driver-specific and other special parameters.
|
|
7 Not really used for now.
|
|
8
|
|
9 static int init(int rate,int channels,int format,int flags);
|
|
10 The init of driver, opens device, sets sample rate, channels, sample format
|
|
11 parameters.
|
|
12 Sample format: usually AFMT_S16_LE or AFMT_U8, for more definitions see
|
|
13 dec_audio.c and linux/soundcards.h files!
|
|
14
|
|
15 static void uninit();
|
|
16 Guess what.
|
|
17 Ok I help: closes the device, not (yet) called when exit.
|
|
18
|
|
19 static void reset();
|
|
20 Resets device. To be exact, it's for deleting buffers' contents,
|
|
21 so after reset() the previously received stuff won't be output.
|
|
22 (called if pause or seek)
|
|
23
|
|
24 static int get_space();
|
|
25 Returns how many bytes can be written into the audio buffer without
|
|
26 blocking (making caller process wait). If the buffer is (nearly) full,
|
|
27 has to return 0!
|
|
28 If it never gives 0, MPlayer won't work!
|
|
29
|
|
30 static int play(void* data,int len,int flags);
|
|
31 Plays a bit of audio, which is received throught the "data" memory area, with
|
|
32 a size of "len". The "flags" isn't used yet. It has to copy the data, because
|
|
33 they can be overwritten after the call is made. Doesn't really have to use
|
|
34 all the bytes, it has to give back how many have been used (copied to
|
|
35 buffer).
|
|
36
|
|
37 static float get_delay();
|
|
38 Returns how long time it will take to play the data currently in the
|
|
39 output buffer. Be exact, if possible, since the whole timing depends
|
|
40 on this! In the worst case, return the maximum delay.
|
|
41
|
|
42 !!! Because the video is synchronized to the audio (card), it's very important
|
|
43 !!! that the get_space and get_delay functions are correctly implemented!
|
|
44
|
|
45 6.a audio plugins
|
|
46 Audio plugins are used for processing the audio data before it
|
|
47 reaches the soundcard driver. A plugin can change the following
|
|
48 aspects of the audio data stream:
|
|
49 1. Sample format
|
|
50 2. Sample rate
|
|
51 3. Number of channels
|
|
52 4. The data itself (i.e. filtering and other sound effects)
|
|
53 5. The delay (almost all plugins does this)
|
|
54 The plugin interface is implemented as a pseudo device driver with
|
|
55 the catchy name "plugin". The plugins are executed sequentially
|
|
56 ordered by the "-aop list=plugin1,plugin2,..." command line switch.
|
|
57 To add plugins add an entry in audio_plugin.h the makefile and
|
|
58 create a source file named "pl_whatever.c". Input parameters are
|
|
59 added to audio_plugin.h and to cfg-mplayer.h. A good starting point
|
|
60 for writing plugins is pl_delay.c. Below is a description of what
|
|
61 the functions does:
|
|
62
|
|
63 static int control(int cmd, int arg);
|
|
64 This is for reading/setting plugin-specific and other special
|
|
65 parameters and can be used for keyboard input for example. All
|
|
66 plugins bust respond to cmd=AOCONTROL_PLUGIN_SET_LEN which is part
|
|
67 of the initialization of the plugin. When this command is received
|
|
68 the parameter pl_delay.len will contain the maximum size of data the
|
|
69 plugin can produce. This can be used for calculating and allocating
|
|
70 buffer space for the plugin. Before the function exits the parameter
|
|
71 pl_delay.len must be set to the maximum data size the plugin can
|
|
72 receive. Return CONTROL_OK for success and CONTROL_ERROR for fail,
|
|
73 other control codes are found in audio_out.h.
|
|
74
|
|
75 static int init();
|
|
76 This function is for initializing the plugin, it is called once
|
|
77 before the playing is started. In this function the plugin can read
|
|
78 AND write to the ao_plugin_data struct to determine and set input
|
|
79 and output parameters. It is important to write to the
|
|
80 ao_plugin_data.sz_mult and ao_plugin_data.delay_fix parameters if
|
|
81 the plugin changes the data size or adds delay. Return 0 for fail
|
|
82 and 1 for success.
|
|
83
|
|
84 static void uninit()
|
|
85 Called before mplayer exits. Used for deallocating dynamic buffers.
|
|
86
|
|
87 static void reset()
|
|
88 Called during reset can be used to empty buffers. Mplayer calls this
|
|
89 function when pause is pressed.
|
|
90
|
|
91 static int play()
|
|
92 Called for every block of audio data sent through the plugin. This
|
|
93 function should be optimized for speed. The incoming data is found
|
|
94 in ao_plugin_data.data having length ao_plugin_data.len. These two
|
|
95 parameters should be changed by the plugin. Return 1 for success and
|
|
96 0 for fail.
|
|
97
|