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:
parent
b789439b23
commit
a06ce499d6
@ -19,68 +19,62 @@
|
||||
namespace webrtc {
|
||||
class FileCallback;
|
||||
|
||||
class FilePlayer
|
||||
{
|
||||
public:
|
||||
// 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_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES*2};
|
||||
class FilePlayer {
|
||||
public:
|
||||
// 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_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES * 2 };
|
||||
|
||||
// Note: will return NULL for unsupported formats.
|
||||
static FilePlayer* CreateFilePlayer(const uint32_t instanceID,
|
||||
const FileFormats fileFormat);
|
||||
// Note: will return NULL for unsupported formats.
|
||||
static FilePlayer* CreateFilePlayer(const uint32_t instanceID,
|
||||
const FileFormats fileFormat);
|
||||
|
||||
static void DestroyFilePlayer(FilePlayer* player);
|
||||
static void DestroyFilePlayer(FilePlayer* player);
|
||||
|
||||
// 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
|
||||
// channel).
|
||||
virtual int Get10msAudioFromFile(
|
||||
int16_t* outBuffer,
|
||||
size_t& lengthInSamples,
|
||||
int frequencyInHz) = 0;
|
||||
// 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
|
||||
// channel).
|
||||
virtual int Get10msAudioFromFile(int16_t* outBuffer,
|
||||
size_t& lengthInSamples,
|
||||
int frequencyInHz) = 0;
|
||||
|
||||
// Register callback for receiving file playing notifications.
|
||||
virtual int32_t RegisterModuleFileCallback(
|
||||
FileCallback* callback) = 0;
|
||||
// Register callback for receiving file playing notifications.
|
||||
virtual int32_t RegisterModuleFileCallback(FileCallback* callback) = 0;
|
||||
|
||||
// API for playing audio from fileName to channel.
|
||||
// Note: codecInst is used for pre-encoded files.
|
||||
virtual int32_t StartPlayingFile(
|
||||
const char* fileName,
|
||||
bool loop,
|
||||
uint32_t startPosition,
|
||||
float volumeScaling,
|
||||
uint32_t notification,
|
||||
uint32_t stopPosition = 0,
|
||||
const CodecInst* codecInst = NULL) = 0;
|
||||
// API for playing audio from fileName to channel.
|
||||
// Note: codecInst is used for pre-encoded files.
|
||||
virtual int32_t StartPlayingFile(const char* fileName,
|
||||
bool loop,
|
||||
uint32_t startPosition,
|
||||
float volumeScaling,
|
||||
uint32_t notification,
|
||||
uint32_t stopPosition = 0,
|
||||
const CodecInst* codecInst = NULL) = 0;
|
||||
|
||||
// Note: codecInst is used for pre-encoded files.
|
||||
virtual int32_t StartPlayingFile(
|
||||
InStream& sourceStream,
|
||||
uint32_t startPosition,
|
||||
float volumeScaling,
|
||||
uint32_t notification,
|
||||
uint32_t stopPosition = 0,
|
||||
const CodecInst* codecInst = NULL) = 0;
|
||||
// Note: codecInst is used for pre-encoded files.
|
||||
virtual int32_t StartPlayingFile(InStream& sourceStream,
|
||||
uint32_t startPosition,
|
||||
float volumeScaling,
|
||||
uint32_t notification,
|
||||
uint32_t stopPosition = 0,
|
||||
const CodecInst* codecInst = NULL) = 0;
|
||||
|
||||
virtual int32_t StopPlayingFile() = 0;
|
||||
virtual int32_t StopPlayingFile() = 0;
|
||||
|
||||
virtual bool IsPlayingFile() const = 0;
|
||||
virtual bool IsPlayingFile() const = 0;
|
||||
|
||||
virtual int32_t GetPlayoutPosition(uint32_t& durationMs) = 0;
|
||||
virtual int32_t GetPlayoutPosition(uint32_t& durationMs) = 0;
|
||||
|
||||
// Set audioCodec to the currently used audio codec.
|
||||
virtual int32_t AudioCodec(CodecInst& audioCodec) const = 0;
|
||||
// Set audioCodec to the currently used audio codec.
|
||||
virtual int32_t AudioCodec(CodecInst& audioCodec) const = 0;
|
||||
|
||||
virtual int32_t Frequency() const = 0;
|
||||
virtual int32_t Frequency() const = 0;
|
||||
|
||||
// Note: scaleFactor is in the range [0.0 - 2.0]
|
||||
virtual int32_t SetAudioScaling(float scaleFactor) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~FilePlayer() {}
|
||||
// Note: scaleFactor is in the range [0.0 - 2.0]
|
||||
virtual int32_t SetAudioScaling(float scaleFactor) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~FilePlayer() {}
|
||||
};
|
||||
} // namespace webrtc
|
||||
#endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_
|
||||
#endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_PLAYER_H_
|
||||
|
||||
@ -19,46 +19,39 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class FileRecorder
|
||||
{
|
||||
public:
|
||||
class FileRecorder {
|
||||
public:
|
||||
// Note: will return NULL for unsupported formats.
|
||||
static FileRecorder* CreateFileRecorder(const uint32_t instanceID,
|
||||
const FileFormats fileFormat);
|
||||
|
||||
// Note: will return NULL for unsupported formats.
|
||||
static FileRecorder* CreateFileRecorder(const uint32_t instanceID,
|
||||
const FileFormats fileFormat);
|
||||
static void DestroyFileRecorder(FileRecorder* recorder);
|
||||
|
||||
static void DestroyFileRecorder(FileRecorder* recorder);
|
||||
virtual int32_t RegisterModuleFileCallback(FileCallback* callback) = 0;
|
||||
|
||||
virtual int32_t RegisterModuleFileCallback(
|
||||
FileCallback* callback) = 0;
|
||||
virtual FileFormats RecordingFileFormat() const = 0;
|
||||
|
||||
virtual FileFormats RecordingFileFormat() const = 0;
|
||||
virtual int32_t StartRecordingAudioFile(const char* fileName,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notification) = 0;
|
||||
|
||||
virtual int32_t StartRecordingAudioFile(
|
||||
const char* fileName,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notification) = 0;
|
||||
virtual int32_t StartRecordingAudioFile(OutStream& destStream,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notification) = 0;
|
||||
|
||||
virtual int32_t StartRecordingAudioFile(
|
||||
OutStream& destStream,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notification) = 0;
|
||||
// Stop recording.
|
||||
virtual int32_t StopRecording() = 0;
|
||||
|
||||
// Stop recording.
|
||||
virtual int32_t StopRecording() = 0;
|
||||
// Return true if recording.
|
||||
virtual bool IsRecording() const = 0;
|
||||
|
||||
// Return true if recording.
|
||||
virtual bool IsRecording() const = 0;
|
||||
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.
|
||||
virtual int32_t RecordAudioToFile(
|
||||
const AudioFrame& frame) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~FileRecorder() {}
|
||||
// Write frame to file. Frame should contain 10ms of un-ecoded audio data.
|
||||
virtual int32_t RecordAudioToFile(const AudioFrame& frame) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~FileRecorder() {}
|
||||
};
|
||||
} // namespace webrtc
|
||||
#endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_RECORDER_H_
|
||||
#endif // WEBRTC_MODULES_UTILITY_INCLUDE_FILE_RECORDER_H_
|
||||
|
||||
@ -13,27 +13,24 @@
|
||||
|
||||
namespace webrtc {
|
||||
FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID,
|
||||
FileFormats fileFormat)
|
||||
{
|
||||
switch(fileFormat)
|
||||
{
|
||||
FileFormats fileFormat) {
|
||||
switch (fileFormat) {
|
||||
case kFileFormatWavFile:
|
||||
case kFileFormatCompressedFile:
|
||||
case kFileFormatPreencodedFile:
|
||||
case kFileFormatPcm16kHzFile:
|
||||
case kFileFormatPcm8kHzFile:
|
||||
case kFileFormatPcm32kHzFile:
|
||||
// audio formats
|
||||
return new FilePlayerImpl(instanceID, fileFormat);
|
||||
// audio formats
|
||||
return new FilePlayerImpl(instanceID, fileFormat);
|
||||
default:
|
||||
assert(false);
|
||||
return NULL;
|
||||
}
|
||||
assert(false);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void FilePlayer::DestroyFilePlayer(FilePlayer* player)
|
||||
{
|
||||
delete player;
|
||||
void FilePlayer::DestroyFilePlayer(FilePlayer* player) {
|
||||
delete player;
|
||||
}
|
||||
|
||||
FilePlayerImpl::FilePlayerImpl(const uint32_t instanceID,
|
||||
@ -47,158 +44,125 @@ FilePlayerImpl::FilePlayerImpl(const uint32_t instanceID,
|
||||
_numberOf10MsPerFrame(0),
|
||||
_numberOf10MsInDecoder(0),
|
||||
_resampler(),
|
||||
_scaling(1.0)
|
||||
{
|
||||
_codec.plfreq = 0;
|
||||
_scaling(1.0) {
|
||||
_codec.plfreq = 0;
|
||||
}
|
||||
|
||||
FilePlayerImpl::~FilePlayerImpl()
|
||||
{
|
||||
MediaFile::DestroyMediaFile(&_fileModule);
|
||||
FilePlayerImpl::~FilePlayerImpl() {
|
||||
MediaFile::DestroyMediaFile(&_fileModule);
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::Frequency() const
|
||||
{
|
||||
if(_codec.plfreq == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// Make sure that sample rate is 8,16 or 32 kHz. E.g. WAVE files may have
|
||||
// other sampling rates.
|
||||
if(_codec.plfreq == 11000)
|
||||
{
|
||||
return 16000;
|
||||
}
|
||||
else if(_codec.plfreq == 22000)
|
||||
{
|
||||
return 32000;
|
||||
}
|
||||
else if(_codec.plfreq == 44000)
|
||||
{
|
||||
return 32000;
|
||||
}
|
||||
else if(_codec.plfreq == 48000)
|
||||
{
|
||||
return 32000;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _codec.plfreq;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::AudioCodec(CodecInst& audioCodec) const
|
||||
{
|
||||
audioCodec = _codec;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::Get10msAudioFromFile(
|
||||
int16_t* outBuffer,
|
||||
size_t& lengthInSamples,
|
||||
int frequencyInHz)
|
||||
{
|
||||
if(_codec.plfreq == 0)
|
||||
{
|
||||
LOG(LS_WARNING) << "Get10msAudioFromFile() playing not started!"
|
||||
<< " codec freq = " << _codec.plfreq
|
||||
<< ", wanted freq = " << frequencyInHz;
|
||||
return -1;
|
||||
}
|
||||
|
||||
AudioFrame unresampledAudioFrame;
|
||||
if(STR_CASE_CMP(_codec.plname, "L16") == 0)
|
||||
{
|
||||
unresampledAudioFrame.sample_rate_hz_ = _codec.plfreq;
|
||||
|
||||
// L16 is un-encoded data. Just pull 10 ms.
|
||||
size_t lengthInBytes =
|
||||
sizeof(unresampledAudioFrame.data_);
|
||||
if (_fileModule.PlayoutAudioData(
|
||||
(int8_t*)unresampledAudioFrame.data_,
|
||||
lengthInBytes) == -1)
|
||||
{
|
||||
// End of file reached.
|
||||
return -1;
|
||||
}
|
||||
if(lengthInBytes == 0)
|
||||
{
|
||||
lengthInSamples = 0;
|
||||
return 0;
|
||||
}
|
||||
// One sample is two bytes.
|
||||
unresampledAudioFrame.samples_per_channel_ = lengthInBytes >> 1;
|
||||
|
||||
} else {
|
||||
// Decode will generate 10 ms of audio data. PlayoutAudioData(..)
|
||||
// expects a full frame. If the frame size is larger than 10 ms,
|
||||
// PlayoutAudioData(..) data should be called proportionally less often.
|
||||
int16_t encodedBuffer[MAX_AUDIO_BUFFER_IN_SAMPLES];
|
||||
size_t encodedLengthInBytes = 0;
|
||||
if(++_numberOf10MsInDecoder >= _numberOf10MsPerFrame)
|
||||
{
|
||||
_numberOf10MsInDecoder = 0;
|
||||
size_t bytesFromFile = sizeof(encodedBuffer);
|
||||
if (_fileModule.PlayoutAudioData((int8_t*)encodedBuffer,
|
||||
bytesFromFile) == -1)
|
||||
{
|
||||
// End of file reached.
|
||||
return -1;
|
||||
}
|
||||
encodedLengthInBytes = bytesFromFile;
|
||||
}
|
||||
if(_audioDecoder.Decode(unresampledAudioFrame,frequencyInHz,
|
||||
(int8_t*)encodedBuffer,
|
||||
encodedLengthInBytes) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
size_t outLen = 0;
|
||||
if(_resampler.ResetIfNeeded(unresampledAudioFrame.sample_rate_hz_,
|
||||
frequencyInHz, 1))
|
||||
{
|
||||
LOG(LS_WARNING) << "Get10msAudioFromFile() unexpected codec.";
|
||||
|
||||
// New sampling frequency. Update state.
|
||||
outLen = static_cast<size_t>(frequencyInHz / 100);
|
||||
memset(outBuffer, 0, outLen * sizeof(int16_t));
|
||||
return 0;
|
||||
}
|
||||
_resampler.Push(unresampledAudioFrame.data_,
|
||||
unresampledAudioFrame.samples_per_channel_,
|
||||
outBuffer,
|
||||
MAX_AUDIO_BUFFER_IN_SAMPLES,
|
||||
outLen);
|
||||
|
||||
lengthInSamples = outLen;
|
||||
|
||||
if(_scaling != 1.0)
|
||||
{
|
||||
for (size_t i = 0;i < outLen; i++)
|
||||
{
|
||||
outBuffer[i] = (int16_t)(outBuffer[i] * _scaling);
|
||||
}
|
||||
}
|
||||
_decodedLengthInMS += 10;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::RegisterModuleFileCallback(FileCallback* callback)
|
||||
{
|
||||
return _fileModule.SetModuleFileCallback(callback);
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::SetAudioScaling(float scaleFactor)
|
||||
{
|
||||
if((scaleFactor >= 0)&&(scaleFactor <= 2.0))
|
||||
{
|
||||
_scaling = scaleFactor;
|
||||
return 0;
|
||||
}
|
||||
LOG(LS_WARNING) << "SetAudioScaling() non-allowed scale factor.";
|
||||
int32_t FilePlayerImpl::Frequency() const {
|
||||
if (_codec.plfreq == 0) {
|
||||
return -1;
|
||||
}
|
||||
// Make sure that sample rate is 8,16 or 32 kHz. E.g. WAVE files may have
|
||||
// other sampling rates.
|
||||
if (_codec.plfreq == 11000) {
|
||||
return 16000;
|
||||
} else if (_codec.plfreq == 22000) {
|
||||
return 32000;
|
||||
} else if (_codec.plfreq == 44000) {
|
||||
return 32000;
|
||||
} else if (_codec.plfreq == 48000) {
|
||||
return 32000;
|
||||
} else {
|
||||
return _codec.plfreq;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::AudioCodec(CodecInst& audioCodec) const {
|
||||
audioCodec = _codec;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::Get10msAudioFromFile(int16_t* outBuffer,
|
||||
size_t& lengthInSamples,
|
||||
int frequencyInHz) {
|
||||
if (_codec.plfreq == 0) {
|
||||
LOG(LS_WARNING) << "Get10msAudioFromFile() playing not started!"
|
||||
<< " codec freq = " << _codec.plfreq
|
||||
<< ", wanted freq = " << frequencyInHz;
|
||||
return -1;
|
||||
}
|
||||
|
||||
AudioFrame unresampledAudioFrame;
|
||||
if (STR_CASE_CMP(_codec.plname, "L16") == 0) {
|
||||
unresampledAudioFrame.sample_rate_hz_ = _codec.plfreq;
|
||||
|
||||
// L16 is un-encoded data. Just pull 10 ms.
|
||||
size_t lengthInBytes = sizeof(unresampledAudioFrame.data_);
|
||||
if (_fileModule.PlayoutAudioData((int8_t*)unresampledAudioFrame.data_,
|
||||
lengthInBytes) == -1) {
|
||||
// End of file reached.
|
||||
return -1;
|
||||
}
|
||||
if (lengthInBytes == 0) {
|
||||
lengthInSamples = 0;
|
||||
return 0;
|
||||
}
|
||||
// One sample is two bytes.
|
||||
unresampledAudioFrame.samples_per_channel_ = lengthInBytes >> 1;
|
||||
|
||||
} else {
|
||||
// Decode will generate 10 ms of audio data. PlayoutAudioData(..)
|
||||
// expects a full frame. If the frame size is larger than 10 ms,
|
||||
// PlayoutAudioData(..) data should be called proportionally less often.
|
||||
int16_t encodedBuffer[MAX_AUDIO_BUFFER_IN_SAMPLES];
|
||||
size_t encodedLengthInBytes = 0;
|
||||
if (++_numberOf10MsInDecoder >= _numberOf10MsPerFrame) {
|
||||
_numberOf10MsInDecoder = 0;
|
||||
size_t bytesFromFile = sizeof(encodedBuffer);
|
||||
if (_fileModule.PlayoutAudioData((int8_t*)encodedBuffer, bytesFromFile) ==
|
||||
-1) {
|
||||
// End of file reached.
|
||||
return -1;
|
||||
}
|
||||
encodedLengthInBytes = bytesFromFile;
|
||||
}
|
||||
if (_audioDecoder.Decode(unresampledAudioFrame, frequencyInHz,
|
||||
(int8_t*)encodedBuffer,
|
||||
encodedLengthInBytes) == -1) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
size_t outLen = 0;
|
||||
if (_resampler.ResetIfNeeded(unresampledAudioFrame.sample_rate_hz_,
|
||||
frequencyInHz, 1)) {
|
||||
LOG(LS_WARNING) << "Get10msAudioFromFile() unexpected codec.";
|
||||
|
||||
// New sampling frequency. Update state.
|
||||
outLen = static_cast<size_t>(frequencyInHz / 100);
|
||||
memset(outBuffer, 0, outLen * sizeof(int16_t));
|
||||
return 0;
|
||||
}
|
||||
_resampler.Push(unresampledAudioFrame.data_,
|
||||
unresampledAudioFrame.samples_per_channel_, outBuffer,
|
||||
MAX_AUDIO_BUFFER_IN_SAMPLES, outLen);
|
||||
|
||||
lengthInSamples = outLen;
|
||||
|
||||
if (_scaling != 1.0) {
|
||||
for (size_t i = 0; i < outLen; i++) {
|
||||
outBuffer[i] = (int16_t)(outBuffer[i] * _scaling);
|
||||
}
|
||||
}
|
||||
_decodedLengthInMS += 10;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::RegisterModuleFileCallback(FileCallback* callback) {
|
||||
return _fileModule.SetModuleFileCallback(callback);
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::SetAudioScaling(float scaleFactor) {
|
||||
if ((scaleFactor >= 0) && (scaleFactor <= 2.0)) {
|
||||
_scaling = scaleFactor;
|
||||
return 0;
|
||||
}
|
||||
LOG(LS_WARNING) << "SetAudioScaling() non-allowed scale factor.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::StartPlayingFile(const char* fileName,
|
||||
@ -207,80 +171,66 @@ int32_t FilePlayerImpl::StartPlayingFile(const char* fileName,
|
||||
float volumeScaling,
|
||||
uint32_t notification,
|
||||
uint32_t stopPosition,
|
||||
const CodecInst* codecInst)
|
||||
{
|
||||
if (_fileFormat == kFileFormatPcm16kHzFile ||
|
||||
_fileFormat == kFileFormatPcm8kHzFile||
|
||||
_fileFormat == kFileFormatPcm32kHzFile )
|
||||
{
|
||||
CodecInst codecInstL16;
|
||||
strncpy(codecInstL16.plname,"L16",32);
|
||||
codecInstL16.pltype = 93;
|
||||
codecInstL16.channels = 1;
|
||||
const CodecInst* codecInst) {
|
||||
if (_fileFormat == kFileFormatPcm16kHzFile ||
|
||||
_fileFormat == kFileFormatPcm8kHzFile ||
|
||||
_fileFormat == kFileFormatPcm32kHzFile) {
|
||||
CodecInst codecInstL16;
|
||||
strncpy(codecInstL16.plname, "L16", 32);
|
||||
codecInstL16.pltype = 93;
|
||||
codecInstL16.channels = 1;
|
||||
|
||||
if (_fileFormat == kFileFormatPcm8kHzFile)
|
||||
{
|
||||
codecInstL16.rate = 128000;
|
||||
codecInstL16.plfreq = 8000;
|
||||
codecInstL16.pacsize = 80;
|
||||
if (_fileFormat == kFileFormatPcm8kHzFile) {
|
||||
codecInstL16.rate = 128000;
|
||||
codecInstL16.plfreq = 8000;
|
||||
codecInstL16.pacsize = 80;
|
||||
|
||||
} else if(_fileFormat == kFileFormatPcm16kHzFile)
|
||||
{
|
||||
codecInstL16.rate = 256000;
|
||||
codecInstL16.plfreq = 16000;
|
||||
codecInstL16.pacsize = 160;
|
||||
} else if (_fileFormat == kFileFormatPcm16kHzFile) {
|
||||
codecInstL16.rate = 256000;
|
||||
codecInstL16.plfreq = 16000;
|
||||
codecInstL16.pacsize = 160;
|
||||
|
||||
}else if(_fileFormat == kFileFormatPcm32kHzFile)
|
||||
{
|
||||
codecInstL16.rate = 512000;
|
||||
codecInstL16.plfreq = 32000;
|
||||
codecInstL16.pacsize = 160;
|
||||
} else
|
||||
{
|
||||
LOG(LS_ERROR) << "StartPlayingFile() sample frequency not "
|
||||
<< "supported for PCM format.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_fileModule.StartPlayingAudioFile(fileName, notification, loop,
|
||||
_fileFormat, &codecInstL16,
|
||||
startPosition,
|
||||
stopPosition) == -1)
|
||||
{
|
||||
LOG(LS_WARNING) << "StartPlayingFile() failed to initialize "
|
||||
<< "pcm file " << fileName;
|
||||
return -1;
|
||||
}
|
||||
SetAudioScaling(volumeScaling);
|
||||
}else if(_fileFormat == kFileFormatPreencodedFile)
|
||||
{
|
||||
if (_fileModule.StartPlayingAudioFile(fileName, notification, loop,
|
||||
_fileFormat, codecInst) == -1)
|
||||
{
|
||||
LOG(LS_WARNING) << "StartPlayingFile() failed to initialize "
|
||||
<< "pre-encoded file " << fileName;
|
||||
return -1;
|
||||
}
|
||||
} else
|
||||
{
|
||||
CodecInst* no_inst = NULL;
|
||||
if (_fileModule.StartPlayingAudioFile(fileName, notification, loop,
|
||||
_fileFormat, no_inst,
|
||||
startPosition,
|
||||
stopPosition) == -1)
|
||||
{
|
||||
LOG(LS_WARNING) << "StartPlayingFile() failed to initialize file "
|
||||
<< fileName;
|
||||
return -1;
|
||||
}
|
||||
SetAudioScaling(volumeScaling);
|
||||
} else if (_fileFormat == kFileFormatPcm32kHzFile) {
|
||||
codecInstL16.rate = 512000;
|
||||
codecInstL16.plfreq = 32000;
|
||||
codecInstL16.pacsize = 160;
|
||||
} else {
|
||||
LOG(LS_ERROR) << "StartPlayingFile() sample frequency not "
|
||||
<< "supported for PCM format.";
|
||||
return -1;
|
||||
}
|
||||
if (SetUpAudioDecoder() == -1)
|
||||
{
|
||||
StopPlayingFile();
|
||||
return -1;
|
||||
|
||||
if (_fileModule.StartPlayingAudioFile(fileName, notification, loop,
|
||||
_fileFormat, &codecInstL16,
|
||||
startPosition, stopPosition) == -1) {
|
||||
LOG(LS_WARNING) << "StartPlayingFile() failed to initialize "
|
||||
<< "pcm file " << fileName;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
SetAudioScaling(volumeScaling);
|
||||
} else if (_fileFormat == kFileFormatPreencodedFile) {
|
||||
if (_fileModule.StartPlayingAudioFile(fileName, notification, loop,
|
||||
_fileFormat, codecInst) == -1) {
|
||||
LOG(LS_WARNING) << "StartPlayingFile() failed to initialize "
|
||||
<< "pre-encoded file " << fileName;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
CodecInst* no_inst = NULL;
|
||||
if (_fileModule.StartPlayingAudioFile(fileName, notification, loop,
|
||||
_fileFormat, no_inst, startPosition,
|
||||
stopPosition) == -1) {
|
||||
LOG(LS_WARNING) << "StartPlayingFile() failed to initialize file "
|
||||
<< fileName;
|
||||
return -1;
|
||||
}
|
||||
SetAudioScaling(volumeScaling);
|
||||
}
|
||||
if (SetUpAudioDecoder() == -1) {
|
||||
StopPlayingFile();
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::StartPlayingFile(InStream& sourceStream,
|
||||
@ -288,115 +238,96 @@ int32_t FilePlayerImpl::StartPlayingFile(InStream& sourceStream,
|
||||
float volumeScaling,
|
||||
uint32_t notification,
|
||||
uint32_t stopPosition,
|
||||
const CodecInst* codecInst)
|
||||
{
|
||||
if (_fileFormat == kFileFormatPcm16kHzFile ||
|
||||
_fileFormat == kFileFormatPcm32kHzFile ||
|
||||
_fileFormat == kFileFormatPcm8kHzFile)
|
||||
{
|
||||
CodecInst codecInstL16;
|
||||
strncpy(codecInstL16.plname,"L16",32);
|
||||
codecInstL16.pltype = 93;
|
||||
codecInstL16.channels = 1;
|
||||
const CodecInst* codecInst) {
|
||||
if (_fileFormat == kFileFormatPcm16kHzFile ||
|
||||
_fileFormat == kFileFormatPcm32kHzFile ||
|
||||
_fileFormat == kFileFormatPcm8kHzFile) {
|
||||
CodecInst codecInstL16;
|
||||
strncpy(codecInstL16.plname, "L16", 32);
|
||||
codecInstL16.pltype = 93;
|
||||
codecInstL16.channels = 1;
|
||||
|
||||
if (_fileFormat == kFileFormatPcm8kHzFile)
|
||||
{
|
||||
codecInstL16.rate = 128000;
|
||||
codecInstL16.plfreq = 8000;
|
||||
codecInstL16.pacsize = 80;
|
||||
if (_fileFormat == kFileFormatPcm8kHzFile) {
|
||||
codecInstL16.rate = 128000;
|
||||
codecInstL16.plfreq = 8000;
|
||||
codecInstL16.pacsize = 80;
|
||||
|
||||
}else if (_fileFormat == kFileFormatPcm16kHzFile)
|
||||
{
|
||||
codecInstL16.rate = 256000;
|
||||
codecInstL16.plfreq = 16000;
|
||||
codecInstL16.pacsize = 160;
|
||||
} else if (_fileFormat == kFileFormatPcm16kHzFile) {
|
||||
codecInstL16.rate = 256000;
|
||||
codecInstL16.plfreq = 16000;
|
||||
codecInstL16.pacsize = 160;
|
||||
|
||||
}else if (_fileFormat == kFileFormatPcm32kHzFile)
|
||||
{
|
||||
codecInstL16.rate = 512000;
|
||||
codecInstL16.plfreq = 32000;
|
||||
codecInstL16.pacsize = 160;
|
||||
}else
|
||||
{
|
||||
LOG(LS_ERROR) << "StartPlayingFile() sample frequency not "
|
||||
<< "supported for PCM format.";
|
||||
return -1;
|
||||
}
|
||||
if (_fileModule.StartPlayingAudioStream(sourceStream, notification,
|
||||
_fileFormat, &codecInstL16,
|
||||
startPosition,
|
||||
stopPosition) == -1)
|
||||
{
|
||||
LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream "
|
||||
<< "playout.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
}else if(_fileFormat == kFileFormatPreencodedFile)
|
||||
{
|
||||
if (_fileModule.StartPlayingAudioStream(sourceStream, notification,
|
||||
_fileFormat, codecInst) == -1)
|
||||
{
|
||||
LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream "
|
||||
<< "playout.";
|
||||
return -1;
|
||||
}
|
||||
} else if (_fileFormat == kFileFormatPcm32kHzFile) {
|
||||
codecInstL16.rate = 512000;
|
||||
codecInstL16.plfreq = 32000;
|
||||
codecInstL16.pacsize = 160;
|
||||
} else {
|
||||
CodecInst* no_inst = NULL;
|
||||
if (_fileModule.StartPlayingAudioStream(sourceStream, notification,
|
||||
_fileFormat, no_inst,
|
||||
startPosition,
|
||||
stopPosition) == -1)
|
||||
{
|
||||
LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream "
|
||||
<< "playout.";
|
||||
return -1;
|
||||
}
|
||||
LOG(LS_ERROR) << "StartPlayingFile() sample frequency not "
|
||||
<< "supported for PCM format.";
|
||||
return -1;
|
||||
}
|
||||
if (_fileModule.StartPlayingAudioStream(
|
||||
sourceStream, notification, _fileFormat, &codecInstL16,
|
||||
startPosition, stopPosition) == -1) {
|
||||
LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream "
|
||||
<< "playout.";
|
||||
return -1;
|
||||
}
|
||||
SetAudioScaling(volumeScaling);
|
||||
|
||||
if (SetUpAudioDecoder() == -1)
|
||||
{
|
||||
StopPlayingFile();
|
||||
return -1;
|
||||
} else if (_fileFormat == kFileFormatPreencodedFile) {
|
||||
if (_fileModule.StartPlayingAudioStream(sourceStream, notification,
|
||||
_fileFormat, codecInst) == -1) {
|
||||
LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream "
|
||||
<< "playout.";
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
CodecInst* no_inst = NULL;
|
||||
if (_fileModule.StartPlayingAudioStream(sourceStream, notification,
|
||||
_fileFormat, no_inst, startPosition,
|
||||
stopPosition) == -1) {
|
||||
LOG(LS_ERROR) << "StartPlayingFile() failed to initialize stream "
|
||||
<< "playout.";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
SetAudioScaling(volumeScaling);
|
||||
|
||||
if (SetUpAudioDecoder() == -1) {
|
||||
StopPlayingFile();
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::StopPlayingFile()
|
||||
{
|
||||
memset(&_codec, 0, sizeof(CodecInst));
|
||||
_numberOf10MsPerFrame = 0;
|
||||
_numberOf10MsInDecoder = 0;
|
||||
return _fileModule.StopPlaying();
|
||||
int32_t FilePlayerImpl::StopPlayingFile() {
|
||||
memset(&_codec, 0, sizeof(CodecInst));
|
||||
_numberOf10MsPerFrame = 0;
|
||||
_numberOf10MsInDecoder = 0;
|
||||
return _fileModule.StopPlaying();
|
||||
}
|
||||
|
||||
bool FilePlayerImpl::IsPlayingFile() const
|
||||
{
|
||||
return _fileModule.IsPlaying();
|
||||
bool FilePlayerImpl::IsPlayingFile() const {
|
||||
return _fileModule.IsPlaying();
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::GetPlayoutPosition(uint32_t& durationMs)
|
||||
{
|
||||
return _fileModule.PlayoutPositionMs(durationMs);
|
||||
int32_t FilePlayerImpl::GetPlayoutPosition(uint32_t& durationMs) {
|
||||
return _fileModule.PlayoutPositionMs(durationMs);
|
||||
}
|
||||
|
||||
int32_t FilePlayerImpl::SetUpAudioDecoder()
|
||||
{
|
||||
if ((_fileModule.codec_info(_codec) == -1))
|
||||
{
|
||||
LOG(LS_WARNING) << "Failed to retrieve codec info of file data.";
|
||||
return -1;
|
||||
}
|
||||
if( STR_CASE_CMP(_codec.plname, "L16") != 0 &&
|
||||
_audioDecoder.SetDecodeCodec(_codec) == -1)
|
||||
{
|
||||
LOG(LS_WARNING) << "SetUpAudioDecoder() codec " << _codec.plname
|
||||
<< " not supported.";
|
||||
return -1;
|
||||
}
|
||||
_numberOf10MsPerFrame = _codec.pacsize / (_codec.plfreq / 100);
|
||||
_numberOf10MsInDecoder = 0;
|
||||
return 0;
|
||||
int32_t FilePlayerImpl::SetUpAudioDecoder() {
|
||||
if ((_fileModule.codec_info(_codec) == -1)) {
|
||||
LOG(LS_WARNING) << "Failed to retrieve codec info of file data.";
|
||||
return -1;
|
||||
}
|
||||
if (STR_CASE_CMP(_codec.plname, "L16") != 0 &&
|
||||
_audioDecoder.SetDecodeCodec(_codec) == -1) {
|
||||
LOG(LS_WARNING) << "SetUpAudioDecoder() codec " << _codec.plname
|
||||
<< " not supported.";
|
||||
return -1;
|
||||
}
|
||||
_numberOf10MsPerFrame = _codec.pacsize / (_codec.plfreq / 100);
|
||||
_numberOf10MsInDecoder = 0;
|
||||
return 0;
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
||||
@ -22,57 +22,53 @@
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
class FilePlayerImpl : public FilePlayer
|
||||
{
|
||||
public:
|
||||
FilePlayerImpl(uint32_t instanceID, FileFormats fileFormat);
|
||||
~FilePlayerImpl();
|
||||
class FilePlayerImpl : public FilePlayer {
|
||||
public:
|
||||
FilePlayerImpl(uint32_t instanceID, FileFormats fileFormat);
|
||||
~FilePlayerImpl();
|
||||
|
||||
virtual int Get10msAudioFromFile(
|
||||
int16_t* outBuffer,
|
||||
size_t& lengthInSamples,
|
||||
int frequencyInHz);
|
||||
virtual int32_t RegisterModuleFileCallback(FileCallback* callback);
|
||||
virtual int32_t StartPlayingFile(
|
||||
const char* fileName,
|
||||
bool loop,
|
||||
uint32_t startPosition,
|
||||
float volumeScaling,
|
||||
uint32_t notification,
|
||||
uint32_t stopPosition = 0,
|
||||
const CodecInst* codecInst = NULL);
|
||||
virtual int32_t StartPlayingFile(
|
||||
InStream& sourceStream,
|
||||
uint32_t startPosition,
|
||||
float volumeScaling,
|
||||
uint32_t notification,
|
||||
uint32_t stopPosition = 0,
|
||||
const CodecInst* codecInst = NULL);
|
||||
virtual int32_t StopPlayingFile();
|
||||
virtual bool IsPlayingFile() const;
|
||||
virtual int32_t GetPlayoutPosition(uint32_t& durationMs);
|
||||
virtual int32_t AudioCodec(CodecInst& audioCodec) const;
|
||||
virtual int32_t Frequency() const;
|
||||
virtual int32_t SetAudioScaling(float scaleFactor);
|
||||
virtual int Get10msAudioFromFile(int16_t* outBuffer,
|
||||
size_t& lengthInSamples,
|
||||
int frequencyInHz);
|
||||
virtual int32_t RegisterModuleFileCallback(FileCallback* callback);
|
||||
virtual int32_t StartPlayingFile(const char* fileName,
|
||||
bool loop,
|
||||
uint32_t startPosition,
|
||||
float volumeScaling,
|
||||
uint32_t notification,
|
||||
uint32_t stopPosition = 0,
|
||||
const CodecInst* codecInst = NULL);
|
||||
virtual int32_t StartPlayingFile(InStream& sourceStream,
|
||||
uint32_t startPosition,
|
||||
float volumeScaling,
|
||||
uint32_t notification,
|
||||
uint32_t stopPosition = 0,
|
||||
const CodecInst* codecInst = NULL);
|
||||
virtual int32_t StopPlayingFile();
|
||||
virtual bool IsPlayingFile() const;
|
||||
virtual int32_t GetPlayoutPosition(uint32_t& durationMs);
|
||||
virtual int32_t AudioCodec(CodecInst& audioCodec) const;
|
||||
virtual int32_t Frequency() const;
|
||||
virtual int32_t SetAudioScaling(float scaleFactor);
|
||||
|
||||
protected:
|
||||
int32_t SetUpAudioDecoder();
|
||||
protected:
|
||||
int32_t SetUpAudioDecoder();
|
||||
|
||||
uint32_t _instanceID;
|
||||
const FileFormats _fileFormat;
|
||||
MediaFile& _fileModule;
|
||||
uint32_t _instanceID;
|
||||
const FileFormats _fileFormat;
|
||||
MediaFile& _fileModule;
|
||||
|
||||
uint32_t _decodedLengthInMS;
|
||||
uint32_t _decodedLengthInMS;
|
||||
|
||||
private:
|
||||
AudioCoder _audioDecoder;
|
||||
private:
|
||||
AudioCoder _audioDecoder;
|
||||
|
||||
CodecInst _codec;
|
||||
int32_t _numberOf10MsPerFrame;
|
||||
int32_t _numberOf10MsInDecoder;
|
||||
CodecInst _codec;
|
||||
int32_t _numberOf10MsPerFrame;
|
||||
int32_t _numberOf10MsInDecoder;
|
||||
|
||||
Resampler _resampler;
|
||||
float _scaling;
|
||||
Resampler _resampler;
|
||||
float _scaling;
|
||||
};
|
||||
} // namespace webrtc
|
||||
#endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_
|
||||
#endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_
|
||||
|
||||
@ -55,9 +55,8 @@ class FilePlayerTest : public ::testing::Test {
|
||||
const std::string& ref_checksum,
|
||||
int output_length_ms) {
|
||||
const float kScaling = 1;
|
||||
ASSERT_EQ(0,
|
||||
player_->StartPlayingFile(
|
||||
input_file.c_str(), false, 0, kScaling, 0, 0, NULL));
|
||||
ASSERT_EQ(0, player_->StartPlayingFile(input_file.c_str(), false, 0,
|
||||
kScaling, 0, 0, NULL));
|
||||
rtc::Md5Digest checksum;
|
||||
for (int i = 0; i < output_length_ms / 10; ++i) {
|
||||
int16_t out[10 * kSampleRateHz / 1000] = {0};
|
||||
|
||||
@ -15,245 +15,192 @@
|
||||
|
||||
namespace webrtc {
|
||||
FileRecorder* FileRecorder::CreateFileRecorder(uint32_t instanceID,
|
||||
FileFormats fileFormat)
|
||||
{
|
||||
return new FileRecorderImpl(instanceID, fileFormat);
|
||||
FileFormats fileFormat) {
|
||||
return new FileRecorderImpl(instanceID, fileFormat);
|
||||
}
|
||||
|
||||
void FileRecorder::DestroyFileRecorder(FileRecorder* recorder)
|
||||
{
|
||||
delete recorder;
|
||||
void FileRecorder::DestroyFileRecorder(FileRecorder* recorder) {
|
||||
delete recorder;
|
||||
}
|
||||
|
||||
FileRecorderImpl::FileRecorderImpl(uint32_t instanceID,
|
||||
FileFormats fileFormat)
|
||||
FileRecorderImpl::FileRecorderImpl(uint32_t instanceID, FileFormats fileFormat)
|
||||
: _instanceID(instanceID),
|
||||
_fileFormat(fileFormat),
|
||||
_moduleFile(MediaFile::CreateMediaFile(_instanceID)),
|
||||
codec_info_(),
|
||||
_audioBuffer(),
|
||||
_audioEncoder(instanceID),
|
||||
_audioResampler()
|
||||
{
|
||||
_audioResampler() {}
|
||||
|
||||
FileRecorderImpl::~FileRecorderImpl() {
|
||||
MediaFile::DestroyMediaFile(_moduleFile);
|
||||
}
|
||||
|
||||
FileRecorderImpl::~FileRecorderImpl()
|
||||
{
|
||||
MediaFile::DestroyMediaFile(_moduleFile);
|
||||
FileFormats FileRecorderImpl::RecordingFileFormat() const {
|
||||
return _fileFormat;
|
||||
}
|
||||
|
||||
FileFormats FileRecorderImpl::RecordingFileFormat() const
|
||||
{
|
||||
return _fileFormat;
|
||||
int32_t FileRecorderImpl::RegisterModuleFileCallback(FileCallback* callback) {
|
||||
if (_moduleFile == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return _moduleFile->SetModuleFileCallback(callback);
|
||||
}
|
||||
|
||||
int32_t FileRecorderImpl::RegisterModuleFileCallback(
|
||||
FileCallback* callback)
|
||||
{
|
||||
if(_moduleFile == NULL)
|
||||
{
|
||||
return -1;
|
||||
int32_t FileRecorderImpl::StartRecordingAudioFile(const char* fileName,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notificationTimeMs) {
|
||||
if (_moduleFile == NULL) {
|
||||
return -1;
|
||||
}
|
||||
codec_info_ = codecInst;
|
||||
int32_t retVal = 0;
|
||||
retVal = _moduleFile->StartRecordingAudioFile(fileName, _fileFormat,
|
||||
codecInst, notificationTimeMs);
|
||||
|
||||
if (retVal == 0) {
|
||||
retVal = SetUpAudioEncoder();
|
||||
}
|
||||
if (retVal != 0) {
|
||||
LOG(LS_WARNING) << "Failed to initialize file " << fileName
|
||||
<< " for recording.";
|
||||
|
||||
if (IsRecording()) {
|
||||
StopRecording();
|
||||
}
|
||||
return _moduleFile->SetModuleFileCallback(callback);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int32_t FileRecorderImpl::StartRecordingAudioFile(
|
||||
const char* fileName,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notificationTimeMs)
|
||||
{
|
||||
if(_moduleFile == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
codec_info_ = codecInst;
|
||||
int32_t retVal = 0;
|
||||
retVal =_moduleFile->StartRecordingAudioFile(fileName, _fileFormat,
|
||||
codecInst,
|
||||
notificationTimeMs);
|
||||
int32_t FileRecorderImpl::StartRecordingAudioFile(OutStream& destStream,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notificationTimeMs) {
|
||||
codec_info_ = codecInst;
|
||||
int32_t retVal = _moduleFile->StartRecordingAudioStream(
|
||||
destStream, _fileFormat, codecInst, notificationTimeMs);
|
||||
|
||||
if( retVal == 0)
|
||||
{
|
||||
retVal = SetUpAudioEncoder();
|
||||
}
|
||||
if( retVal != 0)
|
||||
{
|
||||
LOG(LS_WARNING) << "Failed to initialize file " << fileName
|
||||
<< " for recording.";
|
||||
if (retVal == 0) {
|
||||
retVal = SetUpAudioEncoder();
|
||||
}
|
||||
if (retVal != 0) {
|
||||
LOG(LS_WARNING) << "Failed to initialize outStream for recording.";
|
||||
|
||||
if(IsRecording())
|
||||
{
|
||||
StopRecording();
|
||||
}
|
||||
if (IsRecording()) {
|
||||
StopRecording();
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int32_t FileRecorderImpl::StartRecordingAudioFile(
|
||||
OutStream& destStream,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notificationTimeMs)
|
||||
{
|
||||
codec_info_ = codecInst;
|
||||
int32_t retVal = _moduleFile->StartRecordingAudioStream(
|
||||
destStream,
|
||||
_fileFormat,
|
||||
codecInst,
|
||||
notificationTimeMs);
|
||||
|
||||
if( retVal == 0)
|
||||
{
|
||||
retVal = SetUpAudioEncoder();
|
||||
}
|
||||
if( retVal != 0)
|
||||
{
|
||||
LOG(LS_WARNING) << "Failed to initialize outStream for recording.";
|
||||
|
||||
if(IsRecording())
|
||||
{
|
||||
StopRecording();
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
int32_t FileRecorderImpl::StopRecording() {
|
||||
memset(&codec_info_, 0, sizeof(CodecInst));
|
||||
return _moduleFile->StopRecording();
|
||||
}
|
||||
|
||||
int32_t FileRecorderImpl::StopRecording()
|
||||
{
|
||||
memset(&codec_info_, 0, sizeof(CodecInst));
|
||||
return _moduleFile->StopRecording();
|
||||
}
|
||||
|
||||
bool FileRecorderImpl::IsRecording() const
|
||||
{
|
||||
return _moduleFile->IsRecording();
|
||||
bool FileRecorderImpl::IsRecording() const {
|
||||
return _moduleFile->IsRecording();
|
||||
}
|
||||
|
||||
int32_t FileRecorderImpl::RecordAudioToFile(
|
||||
const AudioFrame& incomingAudioFrame)
|
||||
{
|
||||
if (codec_info_.plfreq == 0)
|
||||
{
|
||||
LOG(LS_WARNING) << "RecordAudioToFile() recording audio is not "
|
||||
<< "turned on.";
|
||||
return -1;
|
||||
const AudioFrame& incomingAudioFrame) {
|
||||
if (codec_info_.plfreq == 0) {
|
||||
LOG(LS_WARNING) << "RecordAudioToFile() recording audio is not "
|
||||
<< "turned on.";
|
||||
return -1;
|
||||
}
|
||||
AudioFrame tempAudioFrame;
|
||||
tempAudioFrame.samples_per_channel_ = 0;
|
||||
if (incomingAudioFrame.num_channels_ == 2 && !_moduleFile->IsStereo()) {
|
||||
// Recording mono but incoming audio is (interleaved) stereo.
|
||||
tempAudioFrame.num_channels_ = 1;
|
||||
tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_;
|
||||
tempAudioFrame.samples_per_channel_ =
|
||||
incomingAudioFrame.samples_per_channel_;
|
||||
for (size_t i = 0; i < (incomingAudioFrame.samples_per_channel_); i++) {
|
||||
// Sample value is the average of left and right buffer rounded to
|
||||
// closest integer value. Note samples can be either 1 or 2 byte.
|
||||
tempAudioFrame.data_[i] = ((incomingAudioFrame.data_[2 * i] +
|
||||
incomingAudioFrame.data_[(2 * i) + 1] + 1) >>
|
||||
1);
|
||||
}
|
||||
AudioFrame tempAudioFrame;
|
||||
tempAudioFrame.samples_per_channel_ = 0;
|
||||
if( incomingAudioFrame.num_channels_ == 2 &&
|
||||
!_moduleFile->IsStereo())
|
||||
{
|
||||
// Recording mono but incoming audio is (interleaved) stereo.
|
||||
tempAudioFrame.num_channels_ = 1;
|
||||
tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_;
|
||||
tempAudioFrame.samples_per_channel_ =
|
||||
incomingAudioFrame.samples_per_channel_;
|
||||
for (size_t i = 0;
|
||||
i < (incomingAudioFrame.samples_per_channel_); i++)
|
||||
{
|
||||
// Sample value is the average of left and right buffer rounded to
|
||||
// closest integer value. Note samples can be either 1 or 2 byte.
|
||||
tempAudioFrame.data_[i] =
|
||||
((incomingAudioFrame.data_[2 * i] +
|
||||
incomingAudioFrame.data_[(2 * i) + 1] + 1) >> 1);
|
||||
}
|
||||
}
|
||||
else if( incomingAudioFrame.num_channels_ == 1 &&
|
||||
_moduleFile->IsStereo())
|
||||
{
|
||||
// Recording stereo but incoming audio is mono.
|
||||
tempAudioFrame.num_channels_ = 2;
|
||||
tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_;
|
||||
tempAudioFrame.samples_per_channel_ =
|
||||
incomingAudioFrame.samples_per_channel_;
|
||||
for (size_t i = 0;
|
||||
i < (incomingAudioFrame.samples_per_channel_); i++)
|
||||
{
|
||||
// Duplicate sample to both channels
|
||||
tempAudioFrame.data_[2*i] =
|
||||
incomingAudioFrame.data_[i];
|
||||
tempAudioFrame.data_[2*i+1] =
|
||||
incomingAudioFrame.data_[i];
|
||||
}
|
||||
} else if (incomingAudioFrame.num_channels_ == 1 && _moduleFile->IsStereo()) {
|
||||
// Recording stereo but incoming audio is mono.
|
||||
tempAudioFrame.num_channels_ = 2;
|
||||
tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_;
|
||||
tempAudioFrame.samples_per_channel_ =
|
||||
incomingAudioFrame.samples_per_channel_;
|
||||
for (size_t i = 0; i < (incomingAudioFrame.samples_per_channel_); i++) {
|
||||
// Duplicate sample to both channels
|
||||
tempAudioFrame.data_[2 * i] = incomingAudioFrame.data_[i];
|
||||
tempAudioFrame.data_[2 * i + 1] = incomingAudioFrame.data_[i];
|
||||
}
|
||||
}
|
||||
|
||||
const AudioFrame* ptrAudioFrame = &incomingAudioFrame;
|
||||
if(tempAudioFrame.samples_per_channel_ != 0)
|
||||
{
|
||||
// If ptrAudioFrame is not empty it contains the audio to be recorded.
|
||||
ptrAudioFrame = &tempAudioFrame;
|
||||
}
|
||||
const AudioFrame* ptrAudioFrame = &incomingAudioFrame;
|
||||
if (tempAudioFrame.samples_per_channel_ != 0) {
|
||||
// If ptrAudioFrame is not empty it contains the audio to be recorded.
|
||||
ptrAudioFrame = &tempAudioFrame;
|
||||
}
|
||||
|
||||
// Encode the audio data before writing to file. Don't encode if the codec
|
||||
// is PCM.
|
||||
// NOTE: stereo recording is only supported for WAV files.
|
||||
// TODO (hellner): WAV expect PCM in little endian byte order. Not
|
||||
// "encoding" with PCM coder should be a problem for big endian systems.
|
||||
size_t encodedLenInBytes = 0;
|
||||
if (_fileFormat == kFileFormatPreencodedFile ||
|
||||
STR_CASE_CMP(codec_info_.plname, "L16") != 0)
|
||||
{
|
||||
if (_audioEncoder.Encode(*ptrAudioFrame, _audioBuffer,
|
||||
encodedLenInBytes) == -1)
|
||||
{
|
||||
LOG(LS_WARNING) << "RecordAudioToFile() codec "
|
||||
<< codec_info_.plname
|
||||
<< " not supported or failed to encode stream.";
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
size_t outLen = 0;
|
||||
_audioResampler.ResetIfNeeded(ptrAudioFrame->sample_rate_hz_,
|
||||
codec_info_.plfreq,
|
||||
ptrAudioFrame->num_channels_);
|
||||
_audioResampler.Push(ptrAudioFrame->data_,
|
||||
ptrAudioFrame->samples_per_channel_ *
|
||||
ptrAudioFrame->num_channels_,
|
||||
(int16_t*)_audioBuffer,
|
||||
MAX_AUDIO_BUFFER_IN_BYTES, outLen);
|
||||
encodedLenInBytes = outLen * sizeof(int16_t);
|
||||
// Encode the audio data before writing to file. Don't encode if the codec
|
||||
// is PCM.
|
||||
// NOTE: stereo recording is only supported for WAV files.
|
||||
// TODO (hellner): WAV expect PCM in little endian byte order. Not
|
||||
// "encoding" with PCM coder should be a problem for big endian systems.
|
||||
size_t encodedLenInBytes = 0;
|
||||
if (_fileFormat == kFileFormatPreencodedFile ||
|
||||
STR_CASE_CMP(codec_info_.plname, "L16") != 0) {
|
||||
if (_audioEncoder.Encode(*ptrAudioFrame, _audioBuffer, encodedLenInBytes) ==
|
||||
-1) {
|
||||
LOG(LS_WARNING) << "RecordAudioToFile() codec " << codec_info_.plname
|
||||
<< " not supported or failed to encode stream.";
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
size_t outLen = 0;
|
||||
_audioResampler.ResetIfNeeded(ptrAudioFrame->sample_rate_hz_,
|
||||
codec_info_.plfreq,
|
||||
ptrAudioFrame->num_channels_);
|
||||
_audioResampler.Push(
|
||||
ptrAudioFrame->data_,
|
||||
ptrAudioFrame->samples_per_channel_ * ptrAudioFrame->num_channels_,
|
||||
(int16_t*)_audioBuffer, MAX_AUDIO_BUFFER_IN_BYTES, outLen);
|
||||
encodedLenInBytes = outLen * sizeof(int16_t);
|
||||
}
|
||||
|
||||
// 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
|
||||
// will be available. Wait until then.
|
||||
if (encodedLenInBytes)
|
||||
{
|
||||
if (WriteEncodedAudioData(_audioBuffer, encodedLenInBytes) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// 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
|
||||
// will be available. Wait until then.
|
||||
if (encodedLenInBytes) {
|
||||
if (WriteEncodedAudioData(_audioBuffer, encodedLenInBytes) == -1) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t FileRecorderImpl::SetUpAudioEncoder()
|
||||
{
|
||||
if (_fileFormat == kFileFormatPreencodedFile ||
|
||||
STR_CASE_CMP(codec_info_.plname, "L16") != 0)
|
||||
{
|
||||
if(_audioEncoder.SetEncodeCodec(codec_info_) == -1)
|
||||
{
|
||||
LOG(LS_ERROR) << "SetUpAudioEncoder() codec "
|
||||
<< codec_info_.plname << " not supported.";
|
||||
return -1;
|
||||
}
|
||||
int32_t FileRecorderImpl::SetUpAudioEncoder() {
|
||||
if (_fileFormat == kFileFormatPreencodedFile ||
|
||||
STR_CASE_CMP(codec_info_.plname, "L16") != 0) {
|
||||
if (_audioEncoder.SetEncodeCodec(codec_info_) == -1) {
|
||||
LOG(LS_ERROR) << "SetUpAudioEncoder() codec " << codec_info_.plname
|
||||
<< " not supported.";
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t FileRecorderImpl::codec_info(CodecInst& codecInst) const
|
||||
{
|
||||
if(codec_info_.plfreq == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
codecInst = codec_info_;
|
||||
return 0;
|
||||
int32_t FileRecorderImpl::codec_info(CodecInst& codecInst) const {
|
||||
if (codec_info_.plfreq == 0) {
|
||||
return -1;
|
||||
}
|
||||
codecInst = codec_info_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t FileRecorderImpl::WriteEncodedAudioData(const int8_t* audioBuffer,
|
||||
size_t bufferLength)
|
||||
{
|
||||
return _moduleFile->IncomingAudioData(audioBuffer, bufferLength);
|
||||
size_t bufferLength) {
|
||||
return _moduleFile->IncomingAudioData(audioBuffer, bufferLength);
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
||||
@ -31,49 +31,45 @@
|
||||
|
||||
namespace webrtc {
|
||||
// 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_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES*2};
|
||||
enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60 * 32 };
|
||||
enum { MAX_AUDIO_BUFFER_IN_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES * 2 };
|
||||
enum { kMaxAudioBufferQueueLength = 100 };
|
||||
|
||||
class CriticalSectionWrapper;
|
||||
|
||||
class FileRecorderImpl : public FileRecorder
|
||||
{
|
||||
public:
|
||||
FileRecorderImpl(uint32_t instanceID, FileFormats fileFormat);
|
||||
virtual ~FileRecorderImpl();
|
||||
class FileRecorderImpl : public FileRecorder {
|
||||
public:
|
||||
FileRecorderImpl(uint32_t instanceID, FileFormats fileFormat);
|
||||
virtual ~FileRecorderImpl();
|
||||
|
||||
// FileRecorder functions.
|
||||
int32_t RegisterModuleFileCallback(FileCallback* callback) override;
|
||||
FileFormats RecordingFileFormat() const override;
|
||||
int32_t StartRecordingAudioFile(
|
||||
const char* fileName,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notificationTimeMs) override;
|
||||
int32_t StartRecordingAudioFile(
|
||||
OutStream& destStream,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notificationTimeMs) override;
|
||||
int32_t StopRecording() override;
|
||||
bool IsRecording() const override;
|
||||
int32_t codec_info(CodecInst& codecInst) const override;
|
||||
int32_t RecordAudioToFile(const AudioFrame& frame) override;
|
||||
// FileRecorder functions.
|
||||
int32_t RegisterModuleFileCallback(FileCallback* callback) override;
|
||||
FileFormats RecordingFileFormat() const override;
|
||||
int32_t StartRecordingAudioFile(const char* fileName,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notificationTimeMs) override;
|
||||
int32_t StartRecordingAudioFile(OutStream& destStream,
|
||||
const CodecInst& codecInst,
|
||||
uint32_t notificationTimeMs) override;
|
||||
int32_t StopRecording() override;
|
||||
bool IsRecording() const override;
|
||||
int32_t codec_info(CodecInst& codecInst) const override;
|
||||
int32_t RecordAudioToFile(const AudioFrame& frame) override;
|
||||
|
||||
protected:
|
||||
int32_t WriteEncodedAudioData(const int8_t* audioBuffer,
|
||||
size_t bufferLength);
|
||||
protected:
|
||||
int32_t WriteEncodedAudioData(const int8_t* audioBuffer, size_t bufferLength);
|
||||
|
||||
int32_t SetUpAudioEncoder();
|
||||
int32_t SetUpAudioEncoder();
|
||||
|
||||
uint32_t _instanceID;
|
||||
FileFormats _fileFormat;
|
||||
MediaFile* _moduleFile;
|
||||
uint32_t _instanceID;
|
||||
FileFormats _fileFormat;
|
||||
MediaFile* _moduleFile;
|
||||
|
||||
private:
|
||||
CodecInst codec_info_;
|
||||
int8_t _audioBuffer[MAX_AUDIO_BUFFER_IN_BYTES];
|
||||
AudioCoder _audioEncoder;
|
||||
Resampler _audioResampler;
|
||||
private:
|
||||
CodecInst codec_info_;
|
||||
int8_t _audioBuffer[MAX_AUDIO_BUFFER_IN_BYTES];
|
||||
AudioCoder _audioEncoder;
|
||||
Resampler _audioResampler;
|
||||
};
|
||||
} // namespace webrtc
|
||||
#endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_RECORDER_IMPL_H_
|
||||
#endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_RECORDER_IMPL_H_
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user