FileRecorderImpl and FilePlayerImpl don't need their own .h and .cc files
They are implementations of interfaces that are only ever exposed via "create" functions, so the entire class definitions can be put in anonymous namespaces in the .cc files that defines the "create" functions. NOPRESUBMIT=true Review-Url: https://codereview.webrtc.org/2038513002 Cr-Commit-Position: refs/heads/master@{#13794}
This commit is contained in:
parent
c54071d8ab
commit
144dd27056
@ -19,10 +19,8 @@ source_set("utility") {
|
||||
"source/audio_frame_operations.cc",
|
||||
"source/coder.cc",
|
||||
"source/coder.h",
|
||||
"source/file_player_impl.cc",
|
||||
"source/file_player_impl.h",
|
||||
"source/file_recorder_impl.cc",
|
||||
"source/file_recorder_impl.h",
|
||||
"source/file_player.cc",
|
||||
"source/file_recorder.cc",
|
||||
"source/helpers_android.cc",
|
||||
"source/helpers_ios.mm",
|
||||
"source/jvm_android.cc",
|
||||
|
||||
@ -8,30 +8,70 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/modules/utility/source/file_player_impl.h"
|
||||
#include "webrtc/modules/utility/include/file_player.h"
|
||||
|
||||
#include "webrtc/common_audio/resampler/include/resampler.h"
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/engine_configurations.h"
|
||||
#include "webrtc/modules/media_file/media_file.h"
|
||||
#include "webrtc/modules/media_file/media_file_defines.h"
|
||||
#include "webrtc/modules/utility/source/coder.h"
|
||||
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
||||
#include "webrtc/system_wrappers/include/logging.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID,
|
||||
FileFormats fileFormat) {
|
||||
switch (fileFormat) {
|
||||
case kFileFormatWavFile:
|
||||
case kFileFormatCompressedFile:
|
||||
case kFileFormatPreencodedFile:
|
||||
case kFileFormatPcm16kHzFile:
|
||||
case kFileFormatPcm8kHzFile:
|
||||
case kFileFormatPcm32kHzFile:
|
||||
// audio formats
|
||||
return new FilePlayerImpl(instanceID, fileFormat);
|
||||
default:
|
||||
assert(false);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void FilePlayer::DestroyFilePlayer(FilePlayer* player) {
|
||||
delete player;
|
||||
}
|
||||
namespace {
|
||||
|
||||
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);
|
||||
|
||||
protected:
|
||||
int32_t SetUpAudioDecoder();
|
||||
|
||||
uint32_t _instanceID;
|
||||
const FileFormats _fileFormat;
|
||||
MediaFile& _fileModule;
|
||||
|
||||
uint32_t _decodedLengthInMS;
|
||||
|
||||
private:
|
||||
AudioCoder _audioDecoder;
|
||||
|
||||
CodecInst _codec;
|
||||
int32_t _numberOf10MsPerFrame;
|
||||
int32_t _numberOf10MsInDecoder;
|
||||
|
||||
Resampler _resampler;
|
||||
float _scaling;
|
||||
};
|
||||
|
||||
FilePlayerImpl::FilePlayerImpl(const uint32_t instanceID,
|
||||
const FileFormats fileFormat)
|
||||
@ -330,4 +370,28 @@ int32_t FilePlayerImpl::SetUpAudioDecoder() {
|
||||
_numberOf10MsInDecoder = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
FilePlayer* FilePlayer::CreateFilePlayer(uint32_t instanceID,
|
||||
FileFormats fileFormat) {
|
||||
switch (fileFormat) {
|
||||
case kFileFormatWavFile:
|
||||
case kFileFormatCompressedFile:
|
||||
case kFileFormatPreencodedFile:
|
||||
case kFileFormatPcm16kHzFile:
|
||||
case kFileFormatPcm8kHzFile:
|
||||
case kFileFormatPcm32kHzFile:
|
||||
// audio formats
|
||||
return new FilePlayerImpl(instanceID, fileFormat);
|
||||
default:
|
||||
assert(false);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void FilePlayer::DestroyFilePlayer(FilePlayer* player) {
|
||||
delete player;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_
|
||||
#define WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_
|
||||
|
||||
#include "webrtc/common_audio/resampler/include/resampler.h"
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/engine_configurations.h"
|
||||
#include "webrtc/modules/media_file/media_file.h"
|
||||
#include "webrtc/modules/media_file/media_file_defines.h"
|
||||
#include "webrtc/modules/utility/include/file_player.h"
|
||||
#include "webrtc/modules/utility/source/coder.h"
|
||||
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
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);
|
||||
|
||||
protected:
|
||||
int32_t SetUpAudioDecoder();
|
||||
|
||||
uint32_t _instanceID;
|
||||
const FileFormats _fileFormat;
|
||||
MediaFile& _fileModule;
|
||||
|
||||
uint32_t _decodedLengthInMS;
|
||||
|
||||
private:
|
||||
AudioCoder _audioDecoder;
|
||||
|
||||
CodecInst _codec;
|
||||
int32_t _numberOf10MsPerFrame;
|
||||
int32_t _numberOf10MsInDecoder;
|
||||
|
||||
Resampler _resampler;
|
||||
float _scaling;
|
||||
};
|
||||
} // namespace webrtc
|
||||
#endif // WEBRTC_MODULES_UTILITY_SOURCE_FILE_PLAYER_IMPL_H_
|
||||
@ -8,20 +8,69 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/modules/utility/include/file_recorder.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "webrtc/base/platform_thread.h"
|
||||
#include "webrtc/common_audio/resampler/include/resampler.h"
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/engine_configurations.h"
|
||||
#include "webrtc/engine_configurations.h"
|
||||
#include "webrtc/modules/include/module_common_types.h"
|
||||
#include "webrtc/modules/media_file/media_file.h"
|
||||
#include "webrtc/modules/utility/source/file_recorder_impl.h"
|
||||
#include "webrtc/modules/media_file/media_file.h"
|
||||
#include "webrtc/modules/media_file/media_file_defines.h"
|
||||
#include "webrtc/modules/utility/source/coder.h"
|
||||
#include "webrtc/system_wrappers/include/event_wrapper.h"
|
||||
#include "webrtc/system_wrappers/include/logging.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
FileRecorder* FileRecorder::CreateFileRecorder(uint32_t instanceID,
|
||||
FileFormats fileFormat) {
|
||||
return new FileRecorderImpl(instanceID, fileFormat);
|
||||
}
|
||||
|
||||
void FileRecorder::DestroyFileRecorder(FileRecorder* recorder) {
|
||||
delete recorder;
|
||||
}
|
||||
namespace {
|
||||
|
||||
// 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 { kMaxAudioBufferQueueLength = 100 };
|
||||
|
||||
class CriticalSectionWrapper;
|
||||
|
||||
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;
|
||||
|
||||
protected:
|
||||
int32_t WriteEncodedAudioData(const int8_t* audioBuffer, size_t bufferLength);
|
||||
|
||||
int32_t SetUpAudioEncoder();
|
||||
|
||||
uint32_t _instanceID;
|
||||
FileFormats _fileFormat;
|
||||
MediaFile* _moduleFile;
|
||||
|
||||
private:
|
||||
CodecInst codec_info_;
|
||||
int8_t _audioBuffer[MAX_AUDIO_BUFFER_IN_BYTES];
|
||||
AudioCoder _audioEncoder;
|
||||
Resampler _audioResampler;
|
||||
};
|
||||
|
||||
FileRecorderImpl::FileRecorderImpl(uint32_t instanceID, FileFormats fileFormat)
|
||||
: _instanceID(instanceID),
|
||||
@ -203,4 +252,16 @@ int32_t FileRecorderImpl::WriteEncodedAudioData(const int8_t* audioBuffer,
|
||||
size_t bufferLength) {
|
||||
return _moduleFile->IncomingAudioData(audioBuffer, bufferLength);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
FileRecorder* FileRecorder::CreateFileRecorder(uint32_t instanceID,
|
||||
FileFormats fileFormat) {
|
||||
return new FileRecorderImpl(instanceID, fileFormat);
|
||||
}
|
||||
|
||||
void FileRecorder::DestroyFileRecorder(FileRecorder* recorder) {
|
||||
delete recorder;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
// This file contains a class that can write audio to file in
|
||||
// multiple file formats. The unencoded input data is written to file in the
|
||||
// encoded format specified.
|
||||
|
||||
#ifndef WEBRTC_MODULES_UTILITY_SOURCE_FILE_RECORDER_IMPL_H_
|
||||
#define WEBRTC_MODULES_UTILITY_SOURCE_FILE_RECORDER_IMPL_H_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "webrtc/base/platform_thread.h"
|
||||
#include "webrtc/common_audio/resampler/include/resampler.h"
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/engine_configurations.h"
|
||||
#include "webrtc/modules/include/module_common_types.h"
|
||||
#include "webrtc/modules/media_file/media_file.h"
|
||||
#include "webrtc/modules/media_file/media_file_defines.h"
|
||||
#include "webrtc/modules/utility/include/file_recorder.h"
|
||||
#include "webrtc/modules/utility/source/coder.h"
|
||||
#include "webrtc/system_wrappers/include/event_wrapper.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
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 { kMaxAudioBufferQueueLength = 100 };
|
||||
|
||||
class CriticalSectionWrapper;
|
||||
|
||||
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;
|
||||
|
||||
protected:
|
||||
int32_t WriteEncodedAudioData(const int8_t* audioBuffer, size_t bufferLength);
|
||||
|
||||
int32_t SetUpAudioEncoder();
|
||||
|
||||
uint32_t _instanceID;
|
||||
FileFormats _fileFormat;
|
||||
MediaFile* _moduleFile;
|
||||
|
||||
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_
|
||||
@ -29,10 +29,8 @@
|
||||
'source/audio_frame_operations.cc',
|
||||
'source/coder.cc',
|
||||
'source/coder.h',
|
||||
'source/file_player_impl.cc',
|
||||
'source/file_player_impl.h',
|
||||
'source/file_recorder_impl.cc',
|
||||
'source/file_recorder_impl.h',
|
||||
'source/file_player.cc',
|
||||
'source/file_recorder.cc',
|
||||
'source/helpers_android.cc',
|
||||
'source/helpers_ios.mm',
|
||||
'source/jvm_android.cc',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user