I. audiorecord recording initialization settings
Audiorecord: Set
->
Audiosystem: getinput
->
In the iaudiopolicyservice. cpp file
The getinput function of bpaudiopolicyservice
Remote ()-> transact (get_input, Data, & reply );
Bnaudiopolicyservice: ontransact (Case get_input: audio_io_handle_t input = getinput (inputsource, samplingrate, format, channels, acoustics); // calls audiopolicyservice: getinput Function
->
Audiopolicyservice: getinput
->
Audiopolicymanagerbase: getinput
Mpclientinterface-> openinput
->
Audiopolicyservice: openinput
->
Bpaudioflinger's openinput Function
->
Audioflinger: openinput
Maudiohardware-> openinputstream
->
AudioHardwareALSA::openInputStream err = mALSADevice->open(&(*it), devices, mode(), 0); in = new AudioStreamInALSA(this, &(*it), acoustics); err = in->set(format, channels, sampleRate);
->
Alsa_default.cpp
Call s_open Function
ALSAStreamOps::set if (rate && *rate > 0) { if (mHandle->sampleRate != *rate) { LOGE("%s L%d mHandle->sampleRate = %d, return BAD_VALUE %d ", __FUNCTION__, __LINE__, mHandle->sampleRate, BAD_VALUE); return BAD_VALUE; } }
E/audiohardwarealsa (1181): Set l123 mhandle-> samplerate = 8000, return bad_value-22 // If the sampling rate is not 8000, bad_value is returned
E/audiohardwarealsa (1181): openinputstream l314 in-> set err =-22
// Bad_value is defined
Bad_value =-einval,
# Define einval 3
According to the above definition, the bad_value value should be-3, but the log output value is-22, which is strange.
----------------------------------------------------------------------------------
Ii. process the recording start Function
1. For video recording, the call sequence of audio recording in the video is:
Mpeg4writer: Start
->
Mpeg4writer: startwriterthread ()
->
Mpeg4writer: starttracks
->
Mpeg4writer: Track: Start
->
During video recording, video track is camerasource, that is, the camerasource: Start function is called.
Audio Track is amrnbencoder, that is, the amrnbencoder: Start function is called.
->
2. If it is a simple recording operation, go directly to the following path:
Audiosource: Start
->
Audiorecord: Start ()
->
Iaudiorecord: Start ()
If the returned value is dead_object
->
Audiorecord: openrecord
->
Audioflinger: openrecord
->
Returns the recordhandle object.
->
Audioflinger: recordhandle: Start ()
->
Audioflinger: recordthread: Start
->
Audiosystem: startinput (MID );
->
Audiopolicyservice: startinput
->
Audiopolicymanagerbase: startinput
If audiorecord: openrecord returns no_error, call iaudiorecord: Start ()
If no_error is returned for iaudiorecord: Start (), the clientrecordthread is started.
----------------------------------------------------------------------------------
3. audiorecord start the recording processing process
1. In the frameworks \ base \ media \ Java \ Android \ media \ audiorecord. Java File
Startrecording () function
// Start recording synchronized (mrecordingstatelock) {// It is always in the synchronous state. Only one recording at a time can exist if (native_start () = success) {// call the native method mrecordingstate = recordstate_recording ;}}
->
2. native_start corresponds to the file in frameworks \ base \ core \ JNI \ android_media_audiorecord.cpp
Android_media_audiorecord_start Function
Obtain the audiorecord object lprecorder, and then call the lprecorder-> Start () function to start recording.
->
3. For the frameworks \ base \ media \ libmedia \ audiorecord. cpp File
Audiorecord: Start () function
3.1 obtain the clientrecordthread object t
3.2 call the iaudiorecord object maudiorecord-> Start ()
(1) If dead_object is returned, execute the audiorecord: openrecord function, call iaudioflinger's openrecord function to open the recording device, and then execute maudiorecord-> Start () to start recording.