1、接口函数:两个函数的主要区别 主要是写流还是写文件。
其他参数:采用的编解码个格式。
int StartRecordingPlayout(int channel,
const char* fileNameUTF8,
CodecInst* compression = NULL,
int maxSizeBytes = -1) override;
int StartRecordingPlayout(int channel,
OutStream* stream,
CodecInst* compression = NULL) override;
2、channel 值如果为-1,就在output_mixer 层录音混音后的音频,如果channel 为其他值在录音对应通道的音频
int VoEFileImpl::StartRecordingPlayout(int channel,
const char* fileNameUTF8,
CodecInst* compression,
int maxSizeBytes) {
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"StartRecordingPlayout(channel=%d, fileNameUTF8=%s, "
"compression, maxSizeBytes=%d)",
channel, fileNameUTF8, maxSizeBytes);
static_assert(1024 == FileWrapper::kMaxFileNameSize, "");
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
if (channel == -1) {
return _shared->output_mixer()->StartRecordingPlayout(fileNameUTF8,
compression);
} else {
// Add file after demultiplexing <=> affects one channel only
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
voe::Channel* channelPtr = ch.channel();
if (channelPtr == NULL) {
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
"StartRecordingPlayout() failed to locate channel");
return -1;
}
return channelPtr->StartRecordingPlayout(fileNameUTF8, compression);
}
}
3、创建fileplayer 类型进行编码以及写文件
int Channel::StartRecordingPlayout(const char* fileName,
const CodecInst* codecInst) {
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::StartRecordingPlayout(fileName=%s)", fileName);
if (_outputFileRecording) {
WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1),
"StartRecordingPlayout() is already recording");
return 0;
}
FileFormats format;
const uint32_t notificationTime(0); // Not supported in VoE
CodecInst dummyCodec = {100, "L16", 16000, 320, 1, 320000};
if ((codecInst != NULL) &&
((codecInst->channels < 1) || (codecInst->channels > 2))) {
_engineStatisticsPtr->SetLastError(
VE_BAD_ARGUMENT, kTraceError,
"StartRecordingPlayout() invalid compression");
return (-1);
}
if (codecInst == NULL) {
format = kFileFormatPcm16kHzFile;
codecInst = &dummyCodec;
} else if ((STR_CASE_CMP(codecInst->plname, "L16") == 0) ||
(STR_CASE_CMP(codecInst->plname, "PCMU") == 0) ||
(STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) {
format = kFileFormatWavFile;
} else {
format = kFileFormatCompressedFile;
}
rtc::CritScope cs(&_fileCritSect);
// Destroy the old instance
if (output_file_recorder_) {
output_file_recorder_->RegisterModuleFileCallback(NULL);
output_file_recorder_.reset();
}
output_file_recorder_ = FileRecorder::CreateFileRecorder(
_outputFileRecorderId, (const FileFormats)format);
if (!output_file_recorder_) {
_engineStatisticsPtr->SetLastError(
VE_INVALID_ARGUMENT, kTraceError,
"StartRecordingPlayout() fileRecorder format isnot correct");
return -1;
}
if (output_file_recorder_->StartRecordingAudioFile(
fileName, (const CodecInst&)*codecInst, notificationTime) != 0) {
_engineStatisticsPtr->SetLastError(
VE_BAD_FILE, kTraceError,
"StartRecordingAudioFile() failed to start file recording");
output_file_recorder_->StopRecording();
output_file_recorder_.reset();
return -1;
}
output_file_recorder_->RegisterModuleFileCallback(this);
_outputFileRecording = true;
return 0;
}