2.4. Audio Codec Controlling : Codec Management Module

2.4.1. Codec Management Overview

A multimedia terminal may support multiple audio codec sets. For every logical channel there can be different codec than in other channels. This (management) module was developed to allow many codecs to be used simultaneously (e.g., while transmitting stereo signal, when the first stream may be coded using G.711 and the other using G.723.1), to make playing and recording threads unconscious of audio codecs used, and finally, to simplify process of selecting and changing audio codecs. Notice that if audio codec is compatible with the Codec Management module, it could not be used without his module. The way how to add a new codec is described in Section 2.4.3.

Playing and recording threads get a pointer to a codec structure as a parameter. This structure contains pointers to coding and decoding functions of particular codec as well as all parameters of a given codec. So Capturing and Playing Module thread just call the snd_encode or snd_decode function with a codec object (a pointer to a codec structure).

To select a particular codec (by the use of snd_get_coder and snd_get_decoder), a symbol of the codec is needed. The symbol type is the codec_symbol_t type (enumerated one). The following symbols are defined: g711Alaw64k , g711Alaw56k , g711Ulaw64k , g711Ulaw56k , g722_64k , g722_56k , g722_48k , g7231 , g728 , g729 , is11172AudioCapability , g729AnnexA , is13818AudioCapability . Most of them are not implemented yet. The mentioned functions will return NULL if called with the symbol of an unimplemented codec . The structure that describes codecs is called codec_struct, and the pointer to this structure is defined p_cd.

2.4.2. Codec Management API

Example 2-1 illustrates the possible scenario of using codec_mngmnt.



#include <stdio.h>
#include "codec_mngmnt.h"

codec_example()
{
	snd_init_codecs(); /* This must be called before any 
  				other snd_ function is called */

	snd_add_coders( g711_capabilities() );
	snd_add_decoders( g711_capabilities() );
		  /* These add features from g711 module. Every particular 
			codec module must be initited in a such way */
			
	printf("Number of coders: %d\n", snd_get_number_of_coders());
	printf("Number of decoders: %d\n", snd_get_number_of_decoders());
	

	printf("Getting decoders..\n");
	tmp_c = snd_get_first_decoder();
	if(!tmp_c)
			printf("Cannot get decoder (no decoders present?).");
	else
			printf("Decoder symbol: %s (%d), name : %s\n",
				tmp_c->string_symbol, 
					tmp_c->symbol, tmp_c->name);

	while(tmp_c = snd_get_next_decoder(tmp_c))
			printf("Decoder symbol: %s (%d), name : %s\n",
				tmp_c->string_symbol, 
					tmp_c->symbol, tmp_c->name);


	snd_unget_codec(tmp_c);

}


Example 2-1. Codec Management Example

2.4.3. How to add a new codec

To add a new codec to the group of supported codecs the following steps must be performed: