Subject: RFC: new utility functions in auconv.c
To: None <tech-kern@netbsd.org>
From: TAMURA Kent <kent@NetBSD.org>
List: tech-kern
Date: 11/08/2004 21:28:53
any comments?
BACKGROUND
To write audio_hw_if::set_params() and query_encoding() annoys
us. It is dull work and many audio drivers have similar code.
A driver loses an encoding which can be supported by sw_code if
the driver author forgets to add code to set the sw_code for the
encoding in set_params().
PROPOSAL
To reduce dull work and to unify redudant code, I propose to add
the following four functions to auconv.c.
--------------------------------
/**
* Set appropriate parameters in `param,' and return the index in
* the hardware capability array `formats.'
*
* @param formats [IN] An array of formats which a hardware can support.
* @param nformats [IN] The number of elements of the array.
* @param mode [IN] Either AUMODE_PLAY or AUMODE_RECORD.
* @param param [IN/OUT] Requested format. param->sw_code may be modified.
* @param rateconv [IN] TRUE if aurateconv may be used.
* @return The index of selected audio_format entry. -1 if the device
* can not support the specified param.
*/
int
auconv_set_converter(const struct audio_format *formats, int nformats,
int mode, struct audio_params *param, int rateconv)
--------------------------------
/**
* Create an audio_encoding_t array besed on hardware capability represented
* by audio_format.
*
* Usage:
* foo_attach(...) {
* :
* if (auconv_create_encodings(formats, nformats,
* &sc->sc_encodings, &sc->sc_nencodings) != 0) {
* // attach failure
* }
*
* @param formats [IN] An array of formats which a hardware can support.
* @param nformats [IN] The number of elements of the array.
* @param encodings [OUT] receives an address of audio_encoding_t array.
* @param nencodings [OUT] receives the size of the audio_encoding_t array.
* @return errno; 0 for success.
*/
int
auconv_create_encodings(const struct audio_format *formats, int nformats,
audio_encoding_t **encodings, int *nencodings)
--------------------------------
/**
* Delete an audio_encoding_t array created by auconv_create_encodings().
*
* Usage:
* foo_detach(...) {
* :
* auconv_delete_encodings(sc->sc_encodings);
* :
* }
*
* @param encodings [IN] An array of audio_encoding_t which was created by
* auconv_create_encodings().
* @return errno; 0 for success.
*/
int auconv_delete_encodings(audio_encoding_t *encodings)
--------------------------------
/**
* Copy the element specified by aep->index.
*
* Usage:
* int foo_query_encoding(void *v, audio_encoding_t *aep) {
* struct foo_softc *sc = (struct foo_softc *)v;
* return auconv_query_encoding(sc->sc_encodings, sc->sc_nencodings, aep);
* }
*
* @param encodings [IN] An array of audio_encoding_t created by
* auconv_create_encodings().
* @param nencodings [IN] The number of elements in encodings.
* @param aep [IN/OUT] resultant audio_encoding_t.
*/
int
auconv_query_encoding(const audio_encoding_t *encodings, int nencodings,
audio_encoding_t *aep)
--------------------------------
IMPACT
There is no influence on existing audio drivers. They work as
usual.
If a driver uses the proposed functions, the code will be
simplified and shorter. If we added new audio converter and it
was supported by the proposed functions, drivers using them
would get support for the new converter without any code change.
I modified auich, auvia, and uaudio to use the proposed
functions. The followings are contributions to the kernel size
on i386:
auconv +3700 Bytes
auich -600 Bytes
auvia -800 Bytes
uaudio -1400 Bytes
The patch [1] is the current implementation. I have tested
auich, auvia, and uaudio, and they have worked fine.
[1] http://www.hauN.org/kent/netbsd-current/auconv.diff
--
TAMURA Kent <kent2004? at hauN.org> <kent at NetBSD.org>