comparison DOCS/tech/libao2.txt @ 20891:5c6111664933

Update libao2 description, delete completely outdated "audio plugins" part
author uau
date Tue, 14 Nov 2006 05:03:47 +0000
parents 8058e403d49c
children eda346733b8c
comparison
equal deleted inserted replaced
20890:9e2d69c27ddb 20891:5c6111664933
21 so after reset() the previously received stuff won't be output. 21 so after reset() the previously received stuff won't be output.
22 (called if pause or seek) 22 (called if pause or seek)
23 23
24 static int get_space(); 24 static int get_space();
25 Returns how many bytes can be written into the audio buffer without 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, 26 blocking (making caller process wait). MPlayer occasionally checks the
27 has to return 0! 27 remaining space and tries to fill the buffer with play() if there's free
28 If it never gives 0, MPlayer won't work! 28 space. The buffer size used should be sane; a buffer that is too small
29 could run empty before MPlayer tries filling it again (normally once per
30 video frame), a buffer that is too big would force MPlayer decode the file
31 far ahead trying to find enough audio data to fill it.
29 32
30 static int play(void* data,int len,int flags); 33 static int play(void* data,int len,int flags);
31 Plays a bit of audio, which is received throught the "data" memory area, with 34 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 35 a size of "len". It has to copy the data, because they can be overwritten
33 they can be overwritten after the call is made. Doesn't really have to use 36 after the call is made. Doesn't have to use all the bytes; it has to
34 all the bytes, it has to give back how many have been used (copied to 37 return the number of bytes used used (copied to buffer). If
35 buffer). 38 flags|AOPLAY_FINAL_CHUNK is true then this is the last audio in the file.
39 The purpose of this flag is to tell aos that round down the audio played
40 from "len" to a multiple of some chunksize that this "len" should not be
41 rounded down to 0 or the data will never be played (as MPlayer will never
42 call play() with a larger len).
36 43
37 static float get_delay(); 44 static float get_delay();
38 Returns how long time it will take to play the data currently in the 45 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 46 output buffer. Be exact, if possible, since the whole timing depends
40 on this! In the worst case, return the maximum delay. 47 on this! In the worst case, return the maximum delay.
41 48
42 !!! Because the video is synchronized to the audio (card), it's very important 49 !!! 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! 50 !!! that the get_delay function is correctly implemented!
44 51
45 6.a audio plugins 52 static void audio_pause(void);
46 Audio plugins are used for processing the audio data before it 53 Pause playing but do not delete buffered data if possible.
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 must 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 54
75 static int init(); 55 static void audio_resume(void);
76 This function is for initializing the plugin, it is called once 56 Continue playing after audio_pause().
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