CM AAC Encode
The cmAacEncode is used to encode the audio/x-raw(PCM) data to audio/mpeg(AAC) data by the library fdkaac.
API Instructions
create/destroy
gpointer cm_aac_encode_create();
void cm_aac_encode_destroy(gpointer hd);
start/stop
void cm_aac_encode_start(gpointer hd);
void cm_aac_encode_stop(gpointer hd);
parameters
/* @format Aac encode format, supports adts, adif, raw */
void cm_aac_encode_set_stream_format(gpointer hd, const char* format);
/* @br The aac bitrate */
void cm_aac_encode_set_bitrate(gpointer hd, int br);
/* @return Encode output format, "audio/mpeg,..." */
const char* cm_aac_encode_get_caps_str(gpointer hd);
data
The encoder needs to know the actual format of the input before encoding, so must ensure the source is ready to be linked(the media info is ready).
/* @src An audio/x-raw source(cmAlsaSrc, ...) */
void cm_aac_encode_link_to_source(gpointer hd, gpointer src);
void cm_aac_encode_unlink(gpointer hd);
/* @ cb data callback to get data */
void cm_aac_encode_set_data_callback(gpointerhd, cm_data_cb_ptrcb, gpointeruser_data);
void cm_aac_encode_remove_data_callback(gpointerhd, cm_data_cb_ptrcb, gpointeruser_data);
others
GstElement* cm_aac_encode_get_bin(gpointer hd);
Demo
Aac Encode Demo
Structure
Get raw data from the microphone then encode it to AAC.
Main codes
// The data will be send to here
static GstFlowReturn _out_data_cb (GstBuffer *buffer, gpointer user_data) {
......
return GST_FLOW_OK;
}
static gboolean _main_loop(gpointer arg) {
if(!pcm_hd) {
// Create source and start
pcm_hd = cm_audio_alsa_source_create("hw:0,0");
cm_audio_alsa_source_start(pcm_hd);
}
//Wait alsa source is ready to be linked
if(!aac_hd && cm_audio_alsa_source_is_ready(pcm_hd)){
aac_hd = cm_aac_encode_create();
//Link aac encode to alsa source
cm_aac_encode_link_to_source(aac_hd, pcm_hd);
//Set callback to get aac data
cm_aac_encode_start(aac_hd);
}
......
}
For more details please refer to the demo file.
Test result
The AAC data can be saved to the file and displayed on the PC.
, multiple selections available,