Run "git cl format" on some files before I start to modify them

This CL does literally nothing else but run "git cl format --full"
on the touched files.

NOPRESUBMIT=true

Review-Url: https://codereview.webrtc.org/2035663002
Cr-Commit-Position: refs/heads/master@{#13782}
This commit is contained in:
kwiberg 2016-08-16 05:35:24 -07:00 committed by Commit bot
parent b789439b23
commit a06ce499d6
7 changed files with 539 additions and 683 deletions

View File

@ -19,8 +19,7 @@
namespace webrtc { namespace webrtc {
class FileCallback; class FileCallback;
class FilePlayer class FilePlayer {
{
public: public:
// The largest decoded frame size in samples (60ms with 32kHz sample rate). // The largest decoded frame size in samples (60ms with 32kHz sample rate).
enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60 * 32 }; enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60 * 32 };
@ -35,19 +34,16 @@ public:
// Read 10 ms of audio at |frequencyInHz| to |outBuffer|. |lengthInSamples| // Read 10 ms of audio at |frequencyInHz| to |outBuffer|. |lengthInSamples|
// will be set to the number of samples read (not the number of samples per // will be set to the number of samples read (not the number of samples per
// channel). // channel).
virtual int Get10msAudioFromFile( virtual int Get10msAudioFromFile(int16_t* outBuffer,
int16_t* outBuffer,
size_t& lengthInSamples, size_t& lengthInSamples,
int frequencyInHz) = 0; int frequencyInHz) = 0;
// Register callback for receiving file playing notifications. // Register callback for receiving file playing notifications.
virtual int32_t RegisterModuleFileCallback( virtual int32_t RegisterModuleFileCallback(FileCallback* callback) = 0;
FileCallback* callback) = 0;
// API for playing audio from fileName to channel. // API for playing audio from fileName to channel.
// Note: codecInst is used for pre-encoded files. // Note: codecInst is used for pre-encoded files.
virtual int32_t StartPlayingFile( virtual int32_t StartPlayingFile(const char* fileName,
const char* fileName,
bool loop, bool loop,
uint32_t startPosition, uint32_t startPosition,
float volumeScaling, float volumeScaling,
@ -56,8 +52,7 @@ public:
const CodecInst* codecInst = NULL) = 0; const CodecInst* codecInst = NULL) = 0;
// Note: codecInst is used for pre-encoded files. // Note: codecInst is used for pre-encoded files.
virtual int32_t StartPlayingFile( virtual int32_t StartPlayingFile(InStream& sourceStream,
InStream& sourceStream,
uint32_t startPosition, uint32_t startPosition,
float volumeScaling, float volumeScaling,
uint32_t notification, uint32_t notification,
@ -80,7 +75,6 @@ public:
protected: protected:
virtual ~FilePlayer() {} virtual ~FilePlayer() {}
}; };
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_ #endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_

View File

@ -19,28 +19,23 @@
namespace webrtc { namespace webrtc {
class FileRecorder class FileRecorder {
{
public: public:
// Note: will return NULL for unsupported formats. // Note: will return NULL for unsupported formats.
static FileRecorder* CreateFileRecorder(const uint32_t instanceID, static FileRecorder* CreateFileRecorder(const uint32_t instanceID,
const FileFormats fileFormat); const FileFormats fileFormat);
static void DestroyFileRecorder(FileRecorder* recorder); static void DestroyFileRecorder(FileRecorder* recorder);
virtual int32_t RegisterModuleFileCallback( virtual int32_t RegisterModuleFileCallback(FileCallback* callback) = 0;
FileCallback* callback) = 0;
virtual FileFormats RecordingFileFormat() const = 0; virtual FileFormats RecordingFileFormat() const = 0;
virtual int32_t StartRecordingAudioFile( virtual int32_t StartRecordingAudioFile(const char* fileName,
const char* fileName,
const CodecInst& codecInst, const CodecInst& codecInst,
uint32_t notification) = 0; uint32_t notification) = 0;
virtual int32_t StartRecordingAudioFile( virtual int32_t StartRecordingAudioFile(OutStream& destStream,
OutStream& destStream,
const CodecInst& codecInst, const CodecInst& codecInst,
uint32_t notification) = 0; uint32_t notification) = 0;
@ -53,12 +48,10 @@ public:
virtual int32_t codec_info(CodecInst& codecInst) const = 0; virtual int32_t codec_info(CodecInst& codecInst) const = 0;
// Write frame to file. Frame should contain 10ms of un-ecoded audio data. // Write frame to file. Frame should contain 10ms of un-ecoded audio data.
virtual int32_t RecordAudioToFile( virtual int32_t RecordAudioToFile(const AudioFrame& frame) = 0;
const AudioFrame& frame) = 0;
protected: protected:
virtual ~FileRecorder() {} virtual ~FileRecorder() {}
}; };
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_RECORDER_H_ #endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_RECORDER_H_

View File

@ -13,10 +13,8 @@
namespace webrtc { namespace webrtc {
FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID, FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID,
FileFormats fileFormat) FileFormats fileFormat) {
{ switch (fileFormat) {
switch(fileFormat)
{
case kFileFormatWavFile: case kFileFormatWavFile:
case kFileFormatCompressedFile: case kFileFormatCompressedFile:
case kFileFormatPreencodedFile: case kFileFormatPreencodedFile:
@ -31,8 +29,7 @@ FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID,
} }
} }
void FilePlayer::DestroyFilePlayer(FilePlayer* player) void FilePlayer::DestroyFilePlayer(FilePlayer* player) {
{
delete player; delete player;
} }
@ -47,59 +44,42 @@ FilePlayerImpl::FilePlayerImpl(const uint32_t instanceID,
_numberOf10MsPerFrame(0), _numberOf10MsPerFrame(0),
_numberOf10MsInDecoder(0), _numberOf10MsInDecoder(0),
_resampler(), _resampler(),
_scaling(1.0) _scaling(1.0) {
{
_codec.plfreq = 0; _codec.plfreq = 0;
} }
FilePlayerImpl::~FilePlayerImpl() FilePlayerImpl::~FilePlayerImpl() {
{
MediaFile::DestroyMediaFile(&_fileModule); MediaFile::DestroyMediaFile(&_fileModule);
} }
int32_t FilePlayerImpl::Frequency() const int32_t FilePlayerImpl::Frequency() const {
{ if (_codec.plfreq == 0) {
if(_codec.plfreq == 0)
{
return -1; return -1;
} }
// Make sure that sample rate is 8,16 or 32 kHz. E.g. WAVE files may have // Make sure that sample rate is 8,16 or 32 kHz. E.g. WAVE files may have
// other sampling rates. // other sampling rates.
if(_codec.plfreq == 11000) if (_codec.plfreq == 11000) {
{
return 16000; return 16000;
} } else if (_codec.plfreq == 22000) {
else if(_codec.plfreq == 22000)
{
return 32000; return 32000;
} } else if (_codec.plfreq == 44000) {
else if(_codec.plfreq == 44000)
{
return 32000; return 32000;
} } else if (_codec.plfreq == 48000) {
else if(_codec.plfreq == 48000)
{
return 32000; return 32000;
} } else {
else
{
return _codec.plfreq; return _codec.plfreq;
} }
} }
int32_t FilePlayerImpl::AudioCodec(CodecInst& audioCodec) const int32_t FilePlayerImpl::AudioCodec(CodecInst& audioCodec) const {
{
audioCodec = _codec; audioCodec = _codec;
return 0; return 0;
} }
int32_t FilePlayerImpl::Get10msAudioFromFile( int32_t FilePlayerImpl::Get10msAudioFromFile(int16_t* outBuffer,
int16_t* outBuffer,
size_t& lengthInSamples, size_t& lengthInSamples,
int frequencyInHz) int frequencyInHz) {
{ if (_codec.plfreq == 0) {
if(_codec.plfreq == 0)
{
LOG(LS_WARNING) << "Get10msAudioFromFile() playing not started!" LOG(LS_WARNING) << "Get10msAudioFromFile() playing not started!"
<< " codec freq = " << _codec.plfreq << " codec freq = " << _codec.plfreq
<< ", wanted freq = " << frequencyInHz; << ", wanted freq = " << frequencyInHz;
@ -107,22 +87,17 @@ int32_t FilePlayerImpl::Get10msAudioFromFile(
} }
AudioFrame unresampledAudioFrame; AudioFrame unresampledAudioFrame;
if(STR_CASE_CMP(_codec.plname, "L16") == 0) if (STR_CASE_CMP(_codec.plname, "L16") == 0) {
{
unresampledAudioFrame.sample_rate_hz_ = _codec.plfreq; unresampledAudioFrame.sample_rate_hz_ = _codec.plfreq;
// L16 is un-encoded data. Just pull 10 ms. // L16 is un-encoded data. Just pull 10 ms.
size_t lengthInBytes = size_t lengthInBytes = sizeof(unresampledAudioFrame.data_);
sizeof(unresampledAudioFrame.data_); if (_fileModule.PlayoutAudioData((int8_t*)unresampledAudioFrame.data_,
if (_fileModule.PlayoutAudioData( lengthInBytes) == -1) {
(int8_t*)unresampledAudioFrame.data_,
lengthInBytes) == -1)
{
// End of file reached. // End of file reached.
return -1; return -1;
} }
if(lengthInBytes == 0) if (lengthInBytes == 0) {
{
lengthInSamples = 0; lengthInSamples = 0;
return 0; return 0;
} }
@ -135,13 +110,11 @@ int32_t FilePlayerImpl::Get10msAudioFromFile(
// PlayoutAudioData(..) data should be called proportionally less often. // PlayoutAudioData(..) data should be called proportionally less often.
int16_t encodedBuffer[MAX_AUDIO_BUFFER_IN_SAMPLES]; int16_t encodedBuffer[MAX_AUDIO_BUFFER_IN_SAMPLES];
size_t encodedLengthInBytes = 0; size_t encodedLengthInBytes = 0;
if(++_numberOf10MsInDecoder >= _numberOf10MsPerFrame) if (++_numberOf10MsInDecoder >= _numberOf10MsPerFrame) {
{
_numberOf10MsInDecoder = 0; _numberOf10MsInDecoder = 0;
size_t bytesFromFile = sizeof(encodedBuffer); size_t bytesFromFile = sizeof(encodedBuffer);
if (_fileModule.PlayoutAudioData((int8_t*)encodedBuffer, if (_fileModule.PlayoutAudioData((int8_t*)encodedBuffer, bytesFromFile) ==
bytesFromFile) == -1) -1) {
{
// End of file reached. // End of file reached.
return -1; return -1;
} }
@ -149,16 +122,14 @@ int32_t FilePlayerImpl::Get10msAudioFromFile(
} }
if (_audioDecoder.Decode(unresampledAudioFrame, frequencyInHz, if (_audioDecoder.Decode(unresampledAudioFrame, frequencyInHz,
(int8_t*)encodedBuffer, (int8_t*)encodedBuffer,
encodedLengthInBytes) == -1) encodedLengthInBytes) == -1) {
{
return -1; return -1;
} }
} }
size_t outLen = 0; size_t outLen = 0;
if (_resampler.ResetIfNeeded(unresampledAudioFrame.sample_rate_hz_, if (_resampler.ResetIfNeeded(unresampledAudioFrame.sample_rate_hz_,
frequencyInHz, 1)) frequencyInHz, 1)) {
{
LOG(LS_WARNING) << "Get10msAudioFromFile() unexpected codec."; LOG(LS_WARNING) << "Get10msAudioFromFile() unexpected codec.";
// New sampling frequency. Update state. // New sampling frequency. Update state.
@ -167,17 +138,13 @@ int32_t FilePlayerImpl::Get10msAudioFromFile(
return 0; return 0;
} }
_resampler.Push(unresampledAudioFrame.data_, _resampler.Push(unresampledAudioFrame.data_,
unresampledAudioFrame.samples_per_channel_, unresampledAudioFrame.samples_per_channel_, outBuffer,
outBuffer, MAX_AUDIO_BUFFER_IN_SAMPLES, outLen);
MAX_AUDIO_BUFFER_IN_SAMPLES,
outLen);
lengthInSamples = outLen; lengthInSamples = outLen;
if(_scaling != 1.0) if (_scaling != 1.0) {
{ for (size_t i = 0; i < outLen; i++) {
for (size_t i = 0;i < outLen; i++)
{
outBuffer[i] = (int16_t)(outBuffer[i] * _scaling); outBuffer[i] = (int16_t)(outBuffer[i] * _scaling);
} }
} }
@ -185,15 +152,12 @@ int32_t FilePlayerImpl::Get10msAudioFromFile(
return 0; return 0;
} }
int32_t FilePlayerImpl::RegisterModuleFileCallback(FileCallback* callback) int32_t FilePlayerImpl::RegisterModuleFileCallback(FileCallback* callback) {
{
return _fileModule.SetModuleFileCallback(callback); return _fileModule.SetModuleFileCallback(callback);
} }
int32_t FilePlayerImpl::SetAudioScaling(float scaleFactor) int32_t FilePlayerImpl::SetAudioScaling(float scaleFactor) {
{ if ((scaleFactor >= 0) && (scaleFactor <= 2.0)) {
if((scaleFactor >= 0)&&(scaleFactor <= 2.0))
{
_scaling = scaleFactor; _scaling = scaleFactor;
return 0; return 0;
} }
@ -207,36 +171,30 @@ int32_t FilePlayerImpl::StartPlayingFile(const char* fileName,
float volumeScaling, float volumeScaling,
uint32_t notification, uint32_t notification,
uint32_t stopPosition, uint32_t stopPosition,
const CodecInst* codecInst) const CodecInst* codecInst) {
{
if (_fileFormat == kFileFormatPcm16kHzFile || if (_fileFormat == kFileFormatPcm16kHzFile ||
_fileFormat == kFileFormatPcm8kHzFile || _fileFormat == kFileFormatPcm8kHzFile ||
_fileFormat == kFileFormatPcm32kHzFile ) _fileFormat == kFileFormatPcm32kHzFile) {
{
CodecInst codecInstL16; CodecInst codecInstL16;
strncpy(codecInstL16.plname, "L16", 32); strncpy(codecInstL16.plname, "L16", 32);
codecInstL16.pltype = 93; codecInstL16.pltype = 93;
codecInstL16.channels = 1; codecInstL16.channels = 1;
if (_fileFormat == kFileFormatPcm8kHzFile) if (_fileFormat == kFileFormatPcm8kHzFile) {
{
codecInstL16.rate = 128000; codecInstL16.rate = 128000;
codecInstL16.plfreq = 8000; codecInstL16.plfreq = 8000;
codecInstL16.pacsize = 80; codecInstL16.pacsize = 80;
} else if(_fileFormat == kFileFormatPcm16kHzFile) } else if (_fileFormat == kFileFormatPcm16kHzFile) {
{
codecInstL16.rate = 256000; codecInstL16.rate = 256000;
codecInstL16.plfreq = 16000; codecInstL16.plfreq = 16000;
codecInstL16.pacsize = 160; codecInstL16.pacsize = 160;
}else if(_fileFormat == kFileFormatPcm32kHzFile) } else if (_fileFormat == kFileFormatPcm32kHzFile) {
{
codecInstL16.rate = 512000; codecInstL16.rate = 512000;
codecInstL16.plfreq = 32000; codecInstL16.plfreq = 32000;
codecInstL16.pacsize = 160; codecInstL16.pacsize = 160;
} else } else {
{
LOG(LS_ERROR) << "StartPlayingFile() sample frequency not " LOG(LS_ERROR) << "StartPlayingFile() sample frequency not "
<< "supported for PCM format."; << "supported for PCM format.";
return -1; return -1;
@ -244,39 +202,31 @@ int32_t FilePlayerImpl::StartPlayingFile(const char* fileName,
if (_fileModule.StartPlayingAudioFile(fileName, notification, loop, if (_fileModule.StartPlayingAudioFile(fileName, notification, loop,
_fileFormat, &codecInstL16, _fileFormat, &codecInstL16,
startPosition, startPosition, stopPosition) == -1) {
stopPosition) == -1)
{
LOG(LS_WARNING) << "StartPlayingFile() failed to initialize " LOG(LS_WARNING) << "StartPlayingFile() failed to initialize "
<< "pcm file " << fileName; << "pcm file " << fileName;
return -1; return -1;
} }
SetAudioScaling(volumeScaling); SetAudioScaling(volumeScaling);
}else if(_fileFormat == kFileFormatPreencodedFile) } else if (_fileFormat == kFileFormatPreencodedFile) {
{
if (_fileModule.StartPlayingAudioFile(fileName, notification, loop, if (_fileModule.StartPlayingAudioFile(fileName, notification, loop,
_fileFormat, codecInst) == -1) _fileFormat, codecInst) == -1) {
{
LOG(LS_WARNING) << "StartPlayingFile() failed to initialize " LOG(LS_WARNING) << "StartPlayingFile() failed to initialize "
<< "pre-encoded file " << fileName; << "pre-encoded file " << fileName;
return -1; return -1;
} }
} else } else {
{
CodecInst* no_inst = NULL; CodecInst* no_inst = NULL;
if (_fileModule.StartPlayingAudioFile(fileName, notification, loop, if (_fileModule.StartPlayingAudioFile(fileName, notification, loop,
_fileFormat, no_inst, _fileFormat, no_inst, startPosition,
startPosition, stopPosition) == -1) {
stopPosition) == -1)
{
LOG(LS_WARNING) << "StartPlayingFile() failed to initialize file " LOG(LS_WARNING) << "StartPlayingFile() failed to initialize file "
<< fileName; << fileName;
return -1; return -1;
} }
SetAudioScaling(volumeScaling); SetAudioScaling(volumeScaling);
} }
if (SetUpAudioDecoder() == -1) if (SetUpAudioDecoder() == -1) {
{
StopPlayingFile(); StopPlayingFile();
return -1; return -1;
} }
@ -288,55 +238,45 @@ int32_t FilePlayerImpl::StartPlayingFile(InStream& sourceStream,
float volumeScaling, float volumeScaling,
uint32_t notification, uint32_t notification,
uint32_t stopPosition, uint32_t stopPosition,
const CodecInst* codecInst) const CodecInst* codecInst) {
{
if (_fileFormat == kFileFormatPcm16kHzFile || if (_fileFormat == kFileFormatPcm16kHzFile ||
_fileFormat == kFileFormatPcm32kHzFile || _fileFormat == kFileFormatPcm32kHzFile ||
_fileFormat == kFileFormatPcm8kHzFile) _fileFormat == kFileFormatPcm8kHzFile) {
{
CodecInst codecInstL16; CodecInst codecInstL16;
strncpy(codecInstL16.plname, "L16", 32); strncpy(codecInstL16.plname, "L16", 32);
codecInstL16.pltype = 93; codecInstL16.pltype = 93;
codecInstL16.channels = 1; codecInstL16.channels = 1;
if (_fileFormat == kFileFormatPcm8kHzFile) if (_fileFormat == kFileFormatPcm8kHzFile) {
{
codecInstL16.rate = 128000; codecInstL16.rate = 128000;
codecInstL16.plfreq = 8000; codecInstL16.plfreq = 8000;
codecInstL16.pacsize = 80; codecInstL16.pacsize = 80;
}else if (_fileFormat == kFileFormatPcm16kHzFile) } else if (_fileFormat == kFileFormatPcm16kHzFile) {
{
codecInstL16.rate = 256000; codecInstL16.rate = 256000;
codecInstL16.plfreq = 16000; codecInstL16.plfreq = 16000;
codecInstL16.pacsize = 160; codecInstL16.pacsize = 160;
}else if (_fileFormat == kFileFormatPcm32kHzFile) } else if (_fileFormat == kFileFormatPcm32kHzFile) {
{
codecInstL16.rate = 512000; codecInstL16.rate = 512000;
codecInstL16.plfreq = 32000; codecInstL16.plfreq = 32000;
codecInstL16.pacsize = 160; codecInstL16.pacsize = 160;
}else } else {
{
LOG(LS_ERROR) << "StartPlayingFile() sample frequency not " LOG(LS_ERROR) << "StartPlayingFile() sample frequency not "
<< "supported for PCM format."; << "supported for PCM format.";
return -1; return -1;
} }
if (_fileModule.StartPlayingAudioStream(sourceStream, notification, if (_fileModule.StartPlayingAudioStream(
_fileFormat, &codecInstL16, sourceStream, notification, _fileFormat, &codecInstL16,
startPosition, startPosition, stopPosition) == -1) {
stopPosition) == -1)
{
LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream " LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream "
<< "playout."; << "playout.";
return -1; return -1;
} }
}else if(_fileFormat == kFileFormatPreencodedFile) } else if (_fileFormat == kFileFormatPreencodedFile) {
{
if (_fileModule.StartPlayingAudioStream(sourceStream, notification, if (_fileModule.StartPlayingAudioStream(sourceStream, notification,
_fileFormat, codecInst) == -1) _fileFormat, codecInst) == -1) {
{
LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream " LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream "
<< "playout."; << "playout.";
return -1; return -1;
@ -344,10 +284,8 @@ int32_t FilePlayerImpl::StartPlayingFile(InStream& sourceStream,
} else { } else {
CodecInst* no_inst = NULL; CodecInst* no_inst = NULL;
if (_fileModule.StartPlayingAudioStream(sourceStream, notification, if (_fileModule.StartPlayingAudioStream(sourceStream, notification,
_fileFormat, no_inst, _fileFormat, no_inst, startPosition,
startPosition, stopPosition) == -1) {
stopPosition) == -1)
{
LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream " LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream "
<< "playout."; << "playout.";
return -1; return -1;
@ -355,42 +293,35 @@ int32_t FilePlayerImpl::StartPlayingFile(InStream& sourceStream,
} }
SetAudioScaling(volumeScaling); SetAudioScaling(volumeScaling);
if (SetUpAudioDecoder() == -1) if (SetUpAudioDecoder() == -1) {
{
StopPlayingFile(); StopPlayingFile();
return -1; return -1;
} }
return 0; return 0;
} }
int32_t FilePlayerImpl::StopPlayingFile() int32_t FilePlayerImpl::StopPlayingFile() {
{
memset(&_codec, 0, sizeof(CodecInst)); memset(&_codec, 0, sizeof(CodecInst));
_numberOf10MsPerFrame = 0; _numberOf10MsPerFrame = 0;
_numberOf10MsInDecoder = 0; _numberOf10MsInDecoder = 0;
return _fileModule.StopPlaying(); return _fileModule.StopPlaying();
} }
bool FilePlayerImpl::IsPlayingFile() const bool FilePlayerImpl::IsPlayingFile() const {
{
return _fileModule.IsPlaying(); return _fileModule.IsPlaying();
} }
int32_t FilePlayerImpl::GetPlayoutPosition(uint32_t& durationMs) int32_t FilePlayerImpl::GetPlayoutPosition(uint32_t& durationMs) {
{
return _fileModule.PlayoutPositionMs(durationMs); return _fileModule.PlayoutPositionMs(durationMs);
} }
int32_t FilePlayerImpl::SetUpAudioDecoder() int32_t FilePlayerImpl::SetUpAudioDecoder() {
{ if ((_fileModule.codec_info(_codec) == -1)) {
if ((_fileModule.codec_info(_codec) == -1))
{
LOG(LS_WARNING) << "Failed to retrieve codec info of file data."; LOG(LS_WARNING) << "Failed to retrieve codec info of file data.";
return -1; return -1;
} }
if (STR_CASE_CMP(_codec.plname, "L16") != 0 && if (STR_CASE_CMP(_codec.plname, "L16") != 0 &&
_audioDecoder.SetDecodeCodec(_codec) == -1) _audioDecoder.SetDecodeCodec(_codec) == -1) {
{
LOG(LS_WARNING) << "SetUpAudioDecoder() codec " << _codec.plname LOG(LS_WARNING) << "SetUpAudioDecoder() codec " << _codec.plname
<< " not supported."; << " not supported.";
return -1; return -1;

View File

@ -22,27 +22,23 @@
#include "webrtc/typedefs.h" #include "webrtc/typedefs.h"
namespace webrtc { namespace webrtc {
class FilePlayerImpl : public FilePlayer class FilePlayerImpl : public FilePlayer {
{
public: public:
FilePlayerImpl(uint32_t instanceID, FileFormats fileFormat); FilePlayerImpl(uint32_t instanceID, FileFormats fileFormat);
~FilePlayerImpl(); ~FilePlayerImpl();
virtual int Get10msAudioFromFile( virtual int Get10msAudioFromFile(int16_t* outBuffer,
int16_t* outBuffer,
size_t& lengthInSamples, size_t& lengthInSamples,
int frequencyInHz); int frequencyInHz);
virtual int32_t RegisterModuleFileCallback(FileCallback* callback); virtual int32_t RegisterModuleFileCallback(FileCallback* callback);
virtual int32_t StartPlayingFile( virtual int32_t StartPlayingFile(const char* fileName,
const char* fileName,
bool loop, bool loop,
uint32_t startPosition, uint32_t startPosition,
float volumeScaling, float volumeScaling,
uint32_t notification, uint32_t notification,
uint32_t stopPosition = 0, uint32_t stopPosition = 0,
const CodecInst* codecInst = NULL); const CodecInst* codecInst = NULL);
virtual int32_t StartPlayingFile( virtual int32_t StartPlayingFile(InStream& sourceStream,
InStream& sourceStream,
uint32_t startPosition, uint32_t startPosition,
float volumeScaling, float volumeScaling,
uint32_t notification, uint32_t notification,

View File

@ -55,9 +55,8 @@ class FilePlayerTest : public ::testing::Test {
const std::string& ref_checksum, const std::string& ref_checksum,
int output_length_ms) { int output_length_ms) {
const float kScaling = 1; const float kScaling = 1;
ASSERT_EQ(0, ASSERT_EQ(0, player_->StartPlayingFile(input_file.c_str(), false, 0,
player_->StartPlayingFile( kScaling, 0, 0, NULL));
input_file.c_str(), false, 0, kScaling, 0, 0, NULL));
rtc::Md5Digest checksum; rtc::Md5Digest checksum;
for (int i = 0; i < output_length_ms / 10; ++i) { for (int i = 0; i < output_length_ms / 10; ++i) {
int16_t out[10 * kSampleRateHz / 1000] = {0}; int16_t out[10 * kSampleRateHz / 1000] = {0};

View File

@ -15,170 +15,129 @@
namespace webrtc { namespace webrtc {
FileRecorder* FileRecorder::CreateFileRecorder(uint32_t instanceID, FileRecorder* FileRecorder::CreateFileRecorder(uint32_t instanceID,
FileFormats fileFormat) FileFormats fileFormat) {
{
return new FileRecorderImpl(instanceID, fileFormat); return new FileRecorderImpl(instanceID, fileFormat);
} }
void FileRecorder::DestroyFileRecorder(FileRecorder* recorder) void FileRecorder::DestroyFileRecorder(FileRecorder* recorder) {
{
delete recorder; delete recorder;
} }
FileRecorderImpl::FileRecorderImpl(uint32_t instanceID, FileRecorderImpl::FileRecorderImpl(uint32_t instanceID, FileFormats fileFormat)
FileFormats fileFormat)
: _instanceID(instanceID), : _instanceID(instanceID),
_fileFormat(fileFormat), _fileFormat(fileFormat),
_moduleFile(MediaFile::CreateMediaFile(_instanceID)), _moduleFile(MediaFile::CreateMediaFile(_instanceID)),
codec_info_(), codec_info_(),
_audioBuffer(), _audioBuffer(),
_audioEncoder(instanceID), _audioEncoder(instanceID),
_audioResampler() _audioResampler() {}
{
}
FileRecorderImpl::~FileRecorderImpl() FileRecorderImpl::~FileRecorderImpl() {
{
MediaFile::DestroyMediaFile(_moduleFile); MediaFile::DestroyMediaFile(_moduleFile);
} }
FileFormats FileRecorderImpl::RecordingFileFormat() const FileFormats FileRecorderImpl::RecordingFileFormat() const {
{
return _fileFormat; return _fileFormat;
} }
int32_t FileRecorderImpl::RegisterModuleFileCallback( int32_t FileRecorderImpl::RegisterModuleFileCallback(FileCallback* callback) {
FileCallback* callback) if (_moduleFile == NULL) {
{
if(_moduleFile == NULL)
{
return -1; return -1;
} }
return _moduleFile->SetModuleFileCallback(callback); return _moduleFile->SetModuleFileCallback(callback);
} }
int32_t FileRecorderImpl::StartRecordingAudioFile( int32_t FileRecorderImpl::StartRecordingAudioFile(const char* fileName,
const char* fileName,
const CodecInst& codecInst, const CodecInst& codecInst,
uint32_t notificationTimeMs) uint32_t notificationTimeMs) {
{ if (_moduleFile == NULL) {
if(_moduleFile == NULL)
{
return -1; return -1;
} }
codec_info_ = codecInst; codec_info_ = codecInst;
int32_t retVal = 0; int32_t retVal = 0;
retVal = _moduleFile->StartRecordingAudioFile(fileName, _fileFormat, retVal = _moduleFile->StartRecordingAudioFile(fileName, _fileFormat,
codecInst, codecInst, notificationTimeMs);
notificationTimeMs);
if( retVal == 0) if (retVal == 0) {
{
retVal = SetUpAudioEncoder(); retVal = SetUpAudioEncoder();
} }
if( retVal != 0) if (retVal != 0) {
{
LOG(LS_WARNING) << "Failed to initialize file " << fileName LOG(LS_WARNING) << "Failed to initialize file " << fileName
<< " for recording."; << " for recording.";
if(IsRecording()) if (IsRecording()) {
{
StopRecording(); StopRecording();
} }
} }
return retVal; return retVal;
} }
int32_t FileRecorderImpl::StartRecordingAudioFile( int32_t FileRecorderImpl::StartRecordingAudioFile(OutStream& destStream,
OutStream& destStream,
const CodecInst& codecInst, const CodecInst& codecInst,
uint32_t notificationTimeMs) uint32_t notificationTimeMs) {
{
codec_info_ = codecInst; codec_info_ = codecInst;
int32_t retVal = _moduleFile->StartRecordingAudioStream( int32_t retVal = _moduleFile->StartRecordingAudioStream(
destStream, destStream, _fileFormat, codecInst, notificationTimeMs);
_fileFormat,
codecInst,
notificationTimeMs);
if( retVal == 0) if (retVal == 0) {
{
retVal = SetUpAudioEncoder(); retVal = SetUpAudioEncoder();
} }
if( retVal != 0) if (retVal != 0) {
{
LOG(LS_WARNING) << "Failed to initialize outStream for recording."; LOG(LS_WARNING) << "Failed to initialize outStream for recording.";
if(IsRecording()) if (IsRecording()) {
{
StopRecording(); StopRecording();
} }
} }
return retVal; return retVal;
} }
int32_t FileRecorderImpl::StopRecording() int32_t FileRecorderImpl::StopRecording() {
{
memset(&codec_info_, 0, sizeof(CodecInst)); memset(&codec_info_, 0, sizeof(CodecInst));
return _moduleFile->StopRecording(); return _moduleFile->StopRecording();
} }
bool FileRecorderImpl::IsRecording() const bool FileRecorderImpl::IsRecording() const {
{
return _moduleFile->IsRecording(); return _moduleFile->IsRecording();
} }
int32_t FileRecorderImpl::RecordAudioToFile( int32_t FileRecorderImpl::RecordAudioToFile(
const AudioFrame& incomingAudioFrame) const AudioFrame& incomingAudioFrame) {
{ if (codec_info_.plfreq == 0) {
if (codec_info_.plfreq == 0)
{
LOG(LS_WARNING) << "RecordAudioToFile() recording audio is not " LOG(LS_WARNING) << "RecordAudioToFile() recording audio is not "
<< "turned on."; << "turned on.";
return -1; return -1;
} }
AudioFrame tempAudioFrame; AudioFrame tempAudioFrame;
tempAudioFrame.samples_per_channel_ = 0; tempAudioFrame.samples_per_channel_ = 0;
if( incomingAudioFrame.num_channels_ == 2 && if (incomingAudioFrame.num_channels_ == 2 && !_moduleFile->IsStereo()) {
!_moduleFile->IsStereo())
{
// Recording mono but incoming audio is (interleaved) stereo. // Recording mono but incoming audio is (interleaved) stereo.
tempAudioFrame.num_channels_ = 1; tempAudioFrame.num_channels_ = 1;
tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_; tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_;
tempAudioFrame.samples_per_channel_ = tempAudioFrame.samples_per_channel_ =
incomingAudioFrame.samples_per_channel_; incomingAudioFrame.samples_per_channel_;
for (size_t i = 0; for (size_t i = 0; i < (incomingAudioFrame.samples_per_channel_); i++) {
i < (incomingAudioFrame.samples_per_channel_); i++)
{
// Sample value is the average of left and right buffer rounded to // Sample value is the average of left and right buffer rounded to
// closest integer value. Note samples can be either 1 or 2 byte. // closest integer value. Note samples can be either 1 or 2 byte.
tempAudioFrame.data_[i] = tempAudioFrame.data_[i] = ((incomingAudioFrame.data_[2 * i] +
((incomingAudioFrame.data_[2 * i] + incomingAudioFrame.data_[(2 * i) + 1] + 1) >>
incomingAudioFrame.data_[(2 * i) + 1] + 1) >> 1); 1);
} }
} } else if (incomingAudioFrame.num_channels_ == 1 && _moduleFile->IsStereo()) {
else if( incomingAudioFrame.num_channels_ == 1 &&
_moduleFile->IsStereo())
{
// Recording stereo but incoming audio is mono. // Recording stereo but incoming audio is mono.
tempAudioFrame.num_channels_ = 2; tempAudioFrame.num_channels_ = 2;
tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_; tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_;
tempAudioFrame.samples_per_channel_ = tempAudioFrame.samples_per_channel_ =
incomingAudioFrame.samples_per_channel_; incomingAudioFrame.samples_per_channel_;
for (size_t i = 0; for (size_t i = 0; i < (incomingAudioFrame.samples_per_channel_); i++) {
i < (incomingAudioFrame.samples_per_channel_); i++)
{
// Duplicate sample to both channels // Duplicate sample to both channels
tempAudioFrame.data_[2*i] = tempAudioFrame.data_[2 * i] = incomingAudioFrame.data_[i];
incomingAudioFrame.data_[i]; tempAudioFrame.data_[2 * i + 1] = incomingAudioFrame.data_[i];
tempAudioFrame.data_[2*i+1] =
incomingAudioFrame.data_[i];
} }
} }
const AudioFrame* ptrAudioFrame = &incomingAudioFrame; const AudioFrame* ptrAudioFrame = &incomingAudioFrame;
if(tempAudioFrame.samples_per_channel_ != 0) if (tempAudioFrame.samples_per_channel_ != 0) {
{
// If ptrAudioFrame is not empty it contains the audio to be recorded. // If ptrAudioFrame is not empty it contains the audio to be recorded.
ptrAudioFrame = &tempAudioFrame; ptrAudioFrame = &tempAudioFrame;
} }
@ -190,13 +149,10 @@ int32_t FileRecorderImpl::RecordAudioToFile(
// "encoding" with PCM coder should be a problem for big endian systems. // "encoding" with PCM coder should be a problem for big endian systems.
size_t encodedLenInBytes = 0; size_t encodedLenInBytes = 0;
if (_fileFormat == kFileFormatPreencodedFile || if (_fileFormat == kFileFormatPreencodedFile ||
STR_CASE_CMP(codec_info_.plname, "L16") != 0) STR_CASE_CMP(codec_info_.plname, "L16") != 0) {
{ if (_audioEncoder.Encode(*ptrAudioFrame, _audioBuffer, encodedLenInBytes) ==
if (_audioEncoder.Encode(*ptrAudioFrame, _audioBuffer, -1) {
encodedLenInBytes) == -1) LOG(LS_WARNING) << "RecordAudioToFile() codec " << codec_info_.plname
{
LOG(LS_WARNING) << "RecordAudioToFile() codec "
<< codec_info_.plname
<< " not supported or failed to encode stream."; << " not supported or failed to encode stream.";
return -1; return -1;
} }
@ -205,46 +161,38 @@ int32_t FileRecorderImpl::RecordAudioToFile(
_audioResampler.ResetIfNeeded(ptrAudioFrame->sample_rate_hz_, _audioResampler.ResetIfNeeded(ptrAudioFrame->sample_rate_hz_,
codec_info_.plfreq, codec_info_.plfreq,
ptrAudioFrame->num_channels_); ptrAudioFrame->num_channels_);
_audioResampler.Push(ptrAudioFrame->data_, _audioResampler.Push(
ptrAudioFrame->samples_per_channel_ * ptrAudioFrame->data_,
ptrAudioFrame->num_channels_, ptrAudioFrame->samples_per_channel_ * ptrAudioFrame->num_channels_,
(int16_t*)_audioBuffer, (int16_t*)_audioBuffer, MAX_AUDIO_BUFFER_IN_BYTES, outLen);
MAX_AUDIO_BUFFER_IN_BYTES, outLen);
encodedLenInBytes = outLen * sizeof(int16_t); encodedLenInBytes = outLen * sizeof(int16_t);
} }
// Codec may not be operating at a frame rate of 10 ms. Whenever enough // Codec may not be operating at a frame rate of 10 ms. Whenever enough
// 10 ms chunks of data has been pushed to the encoder an encoded frame // 10 ms chunks of data has been pushed to the encoder an encoded frame
// will be available. Wait until then. // will be available. Wait until then.
if (encodedLenInBytes) if (encodedLenInBytes) {
{ if (WriteEncodedAudioData(_audioBuffer, encodedLenInBytes) == -1) {
if (WriteEncodedAudioData(_audioBuffer, encodedLenInBytes) == -1)
{
return -1; return -1;
} }
} }
return 0; return 0;
} }
int32_t FileRecorderImpl::SetUpAudioEncoder() int32_t FileRecorderImpl::SetUpAudioEncoder() {
{
if (_fileFormat == kFileFormatPreencodedFile || if (_fileFormat == kFileFormatPreencodedFile ||
STR_CASE_CMP(codec_info_.plname, "L16") != 0) STR_CASE_CMP(codec_info_.plname, "L16") != 0) {
{ if (_audioEncoder.SetEncodeCodec(codec_info_) == -1) {
if(_audioEncoder.SetEncodeCodec(codec_info_) == -1) LOG(LS_ERROR) << "SetUpAudioEncoder() codec " << codec_info_.plname
{ << " not supported.";
LOG(LS_ERROR) << "SetUpAudioEncoder() codec "
<< codec_info_.plname << " not supported.";
return -1; return -1;
} }
} }
return 0; return 0;
} }
int32_t FileRecorderImpl::codec_info(CodecInst& codecInst) const int32_t FileRecorderImpl::codec_info(CodecInst& codecInst) const {
{ if (codec_info_.plfreq == 0) {
if(codec_info_.plfreq == 0)
{
return -1; return -1;
} }
codecInst = codec_info_; codecInst = codec_info_;
@ -252,8 +200,7 @@ int32_t FileRecorderImpl::codec_info(CodecInst& codecInst) const
} }
int32_t FileRecorderImpl::WriteEncodedAudioData(const int8_t* audioBuffer, int32_t FileRecorderImpl::WriteEncodedAudioData(const int8_t* audioBuffer,
size_t bufferLength) size_t bufferLength) {
{
return _moduleFile->IncomingAudioData(audioBuffer, bufferLength); return _moduleFile->IncomingAudioData(audioBuffer, bufferLength);
} }
} // namespace webrtc } // namespace webrtc

View File

@ -37,8 +37,7 @@ enum { kMaxAudioBufferQueueLength = 100 };
class CriticalSectionWrapper; class CriticalSectionWrapper;
class FileRecorderImpl : public FileRecorder class FileRecorderImpl : public FileRecorder {
{
public: public:
FileRecorderImpl(uint32_t instanceID, FileFormats fileFormat); FileRecorderImpl(uint32_t instanceID, FileFormats fileFormat);
virtual ~FileRecorderImpl(); virtual ~FileRecorderImpl();
@ -46,12 +45,10 @@ public:
// FileRecorder functions. // FileRecorder functions.
int32_t RegisterModuleFileCallback(FileCallback* callback) override; int32_t RegisterModuleFileCallback(FileCallback* callback) override;
FileFormats RecordingFileFormat() const override; FileFormats RecordingFileFormat() const override;
int32_t StartRecordingAudioFile( int32_t StartRecordingAudioFile(const char* fileName,
const char* fileName,
const CodecInst& codecInst, const CodecInst& codecInst,
uint32_t notificationTimeMs) override; uint32_t notificationTimeMs) override;
int32_t StartRecordingAudioFile( int32_t StartRecordingAudioFile(OutStream& destStream,
OutStream& destStream,
const CodecInst& codecInst, const CodecInst& codecInst,
uint32_t notificationTimeMs) override; uint32_t notificationTimeMs) override;
int32_t StopRecording() override; int32_t StopRecording() override;
@ -60,8 +57,7 @@ public:
int32_t RecordAudioToFile(const AudioFrame& frame) override; int32_t RecordAudioToFile(const AudioFrame& frame) override;
protected: protected:
int32_t WriteEncodedAudioData(const int8_t* audioBuffer, int32_t WriteEncodedAudioData(const int8_t* audioBuffer, size_t bufferLength);
size_t bufferLength);
int32_t SetUpAudioEncoder(); int32_t SetUpAudioEncoder();