annotate DOCS/tech/libao2.txt @ 6965:f8ea0af8edb0

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