Android audioflinger 录音、录像时PCM音频数据的获取

代码位置:src\frameworks\av\services\audioflinger\Threads.cpp
在bool AudioFlinger::RecordThread::threadLoop();方法,
        // If an NBAIO source is present, use it to read the normal capture's data
        if (mPipeSource != 0) {
            size_t framesToRead = mBufferSize / mFrameSize;
            framesRead = mPipeSource->read(& mRsmpInBuffer[rear * mChannelCount],
                    framesToRead, AudioBufferProvider::kInvalidPTS);
            if (framesRead == 0) {
                // since pipe is non-blocking, simulate blocking input
                sleepUs = (framesToRead * 1000000LL) / mSampleRate;
            }
        // otherwise use the HAL / AudioStreamIn directly
        } else {
            ssize_t bytesRead = mInput->stream->read(mInput->stream,
                    & mRsmpInBuffer[rear * mChannelCount], mBufferSize);
            if (bytesRead < 0) {
                framesRead = bytesRead;
            } else {
                framesRead = bytesRead / mFrameSize;
            }
        }
PCM数据读入到 mRsmpInBuffer,将mRsmpInBuffer内容写到/data/test.pcm,通过cooledit就可以播放。
FILE *file = fopen("/data/test.pcm", "ab+");
        if(file == NULL) {
            ALOGE("open file failed!");
        } else {
            fwrite(&mRsmpInBuffer[rear * mChannelCount], mBufferSize, 1, file);
        }
        if(file != NULL)
        fclose(file);

你可能感兴趣的:(Android audioflinger 录音、录像时PCM音频数据的获取)