Changing echo_path_size_bytes() to static, and using size_t rather than int. This is recommended by Chromium:

http://www.chromium.org/developers/coding-style

Fixing a few compile warnings.
Review URL: http://webrtc-codereview.appspot.com/81001

git-svn-id: http://webrtc.googlecode.com/svn/trunk@228 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
ajm@google.com
2011-07-18 18:03:01 +00:00
parent 1e34241426
commit 22e65158bd
8 changed files with 56 additions and 47 deletions

View File

@@ -494,7 +494,6 @@ void aec_rdft_forward_128(float *a) {
void aec_rdft_inverse_128(float *a) { void aec_rdft_inverse_128(float *a) {
const int n = 128; const int n = 128;
int nw; int nw;
float xi;
nw = ip[0]; nw = ip[0];
a[1] = 0.5f * (a[0] - a[1]); a[1] = 0.5f * (a[0] - a[1]);

View File

@@ -175,7 +175,7 @@ WebRtc_Word32 WebRtcAecm_get_config(void *aecmInst,
* ------------------------------------------------------------------- * -------------------------------------------------------------------
* void* aecmInst Pointer to the AECM instance * void* aecmInst Pointer to the AECM instance
* void* echo_path Pointer to the echo path to be set * void* echo_path Pointer to the echo path to be set
* int size_bytes Size in bytes of the echo path * size_t size_bytes Size in bytes of the echo path
* *
* Outputs Description * Outputs Description
* ------------------------------------------------------------------- * -------------------------------------------------------------------
@@ -184,7 +184,7 @@ WebRtc_Word32 WebRtcAecm_get_config(void *aecmInst,
*/ */
WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst, WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
const void* echo_path, const void* echo_path,
int size_bytes); size_t size_bytes);
/* /*
* This function enables the user to get the currently used echo path * This function enables the user to get the currently used echo path
@@ -194,7 +194,7 @@ WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
* ------------------------------------------------------------------- * -------------------------------------------------------------------
* void* aecmInst Pointer to the AECM instance * void* aecmInst Pointer to the AECM instance
* void* echo_path Pointer to echo path * void* echo_path Pointer to echo path
* int size_bytes Size in bytes of the echo path * size_t size_bytes Size in bytes of the echo path
* *
* Outputs Description * Outputs Description
* ------------------------------------------------------------------- * -------------------------------------------------------------------
@@ -203,16 +203,16 @@ WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
*/ */
WebRtc_Word32 WebRtcAecm_GetEchoPath(void* aecmInst, WebRtc_Word32 WebRtcAecm_GetEchoPath(void* aecmInst,
void* echo_path, void* echo_path,
int size_bytes); size_t size_bytes);
/* /*
* This function enables the user to get the echo path size in bytes * This function enables the user to get the echo path size in bytes
* *
* Outputs Description * Outputs Description
* ------------------------------------------------------------------- * -------------------------------------------------------------------
* int return : size in bytes * size_t return : size in bytes
*/ */
int WebRtcAecm_echo_path_size_bytes(); size_t WebRtcAecm_echo_path_size_bytes();
/* /*
* Gets the last error code. * Gets the last error code.

View File

@@ -622,7 +622,7 @@ WebRtc_Word32 WebRtcAecm_get_config(void *aecmInst, AecmConfig *config)
WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst, WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
const void* echo_path, const void* echo_path,
int size_bytes) size_t size_bytes)
{ {
aecmob_t *aecm = aecmInst; aecmob_t *aecm = aecmInst;
const WebRtc_Word16* echo_path_ptr = echo_path; const WebRtc_Word16* echo_path_ptr = echo_path;
@@ -651,7 +651,7 @@ WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
WebRtc_Word32 WebRtcAecm_GetEchoPath(void* aecmInst, WebRtc_Word32 WebRtcAecm_GetEchoPath(void* aecmInst,
void* echo_path, void* echo_path,
int size_bytes) size_t size_bytes)
{ {
aecmob_t *aecm = aecmInst; aecmob_t *aecm = aecmInst;
WebRtc_Word16* echo_path_ptr = echo_path; WebRtc_Word16* echo_path_ptr = echo_path;
@@ -677,7 +677,7 @@ WebRtc_Word32 WebRtcAecm_GetEchoPath(void* aecmInst,
return 0; return 0;
} }
int WebRtcAecm_echo_path_size_bytes() size_t WebRtcAecm_echo_path_size_bytes()
{ {
return (PART_LEN1 * sizeof(WebRtc_Word16)); return (PART_LEN1 * sizeof(WebRtc_Word16));
} }

View File

@@ -11,6 +11,8 @@
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_INTERFACE_AUDIO_PROCESSING_H_ #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_INTERFACE_AUDIO_PROCESSING_H_
#define WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_INTERFACE_AUDIO_PROCESSING_H_ #define WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_INTERFACE_AUDIO_PROCESSING_H_
#include <stddef.h> // size_t
#include "typedefs.h" #include "typedefs.h"
#include "module.h" #include "module.h"
@@ -357,18 +359,24 @@ class EchoControlMobile {
virtual bool is_comfort_noise_enabled() const = 0; virtual bool is_comfort_noise_enabled() const = 0;
// A typical use case is to initialize the component with an echo path from a // A typical use case is to initialize the component with an echo path from a
// previous call. The echo path is retrieved using |GetEchoPath()| typically // previous call. The echo path is retrieved using |GetEchoPath()|, typically
// at the end of a call. The data can then be stored for later use as // at the end of a call. The data can then be stored for later use as an
// initializer, using |SetEchoPath()|. // initializer before the next call, using |SetEchoPath()|.
//
// Controlling the echo path this way requires the data |size_bytes| to match // Controlling the echo path this way requires the data |size_bytes| to match
// the internal echo path size. This size can be acquired using // the internal echo path size. This size can be acquired using
// |echo_path_size_bytes()|. |SetEchoPath()| causes an entire reset, worth // |echo_path_size_bytes()|. |SetEchoPath()| causes an entire reset, worth
// noting if it is to be called during an ongoing call. It is possible that // noting if it is to be called during an ongoing call.
// version incompatibilities may result in a stored echo path of the //
// incorrect size. In this case, the stored path should be discarded. // It is possible that version incompatibilities may result in a stored echo
virtual int SetEchoPath(const void* echo_path, int size_bytes) = 0; // path of the incorrect size. In this case, the stored path should be
virtual int GetEchoPath(void* echo_path, int size_bytes) const = 0; // discarded.
virtual const int echo_path_size_bytes() const = 0; virtual int SetEchoPath(const void* echo_path, size_t size_bytes) = 0;
virtual int GetEchoPath(void* echo_path, size_t size_bytes) const = 0;
// The returned path size is guaranteed not to change for the lifetime of
// the application.
static size_t echo_path_size_bytes();
protected: protected:
virtual ~EchoControlMobile() {}; virtual ~EchoControlMobile() {};

View File

@@ -59,12 +59,15 @@ int MapError(int err) {
} }
} // namespace } // namespace
size_t EchoControlMobile::echo_path_size_bytes() {
return WebRtcAecm_echo_path_size_bytes();
}
EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessingImpl* apm) EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessingImpl* apm)
: ProcessingComponent(apm), : ProcessingComponent(apm),
apm_(apm), apm_(apm),
routing_mode_(kSpeakerphone), routing_mode_(kSpeakerphone),
comfort_noise_enabled_(true), comfort_noise_enabled_(true),
echo_path_size_bytes_(WebRtcAecm_echo_path_size_bytes()),
external_echo_path_(NULL) {} external_echo_path_(NULL) {}
EchoControlMobileImpl::~EchoControlMobileImpl() { EchoControlMobileImpl::~EchoControlMobileImpl() {
@@ -191,12 +194,12 @@ bool EchoControlMobileImpl::is_comfort_noise_enabled() const {
} }
int EchoControlMobileImpl::SetEchoPath(const void* echo_path, int EchoControlMobileImpl::SetEchoPath(const void* echo_path,
int size_bytes) { size_t size_bytes) {
CriticalSectionScoped crit_scoped(*apm_->crit()); CriticalSectionScoped crit_scoped(*apm_->crit());
if (echo_path == NULL) { if (echo_path == NULL) {
return apm_->kNullPointerError; return apm_->kNullPointerError;
} }
if (size_bytes != echo_path_size_bytes_) { if (size_bytes != echo_path_size_bytes()) {
// Size mismatch // Size mismatch
return apm_->kBadParameterError; return apm_->kBadParameterError;
} }
@@ -210,12 +213,12 @@ int EchoControlMobileImpl::SetEchoPath(const void* echo_path,
} }
int EchoControlMobileImpl::GetEchoPath(void* echo_path, int EchoControlMobileImpl::GetEchoPath(void* echo_path,
int size_bytes) const { size_t size_bytes) const {
CriticalSectionScoped crit_scoped(*apm_->crit()); CriticalSectionScoped crit_scoped(*apm_->crit());
if (echo_path == NULL) { if (echo_path == NULL) {
return apm_->kNullPointerError; return apm_->kNullPointerError;
} }
if (size_bytes != echo_path_size_bytes_) { if (size_bytes != echo_path_size_bytes()) {
// Size mismatch // Size mismatch
return apm_->kBadParameterError; return apm_->kBadParameterError;
} }
@@ -232,10 +235,6 @@ int EchoControlMobileImpl::GetEchoPath(void* echo_path,
return apm_->kNoError; return apm_->kNoError;
} }
const int EchoControlMobileImpl::echo_path_size_bytes() const {
return echo_path_size_bytes_;
}
int EchoControlMobileImpl::Initialize() { int EchoControlMobileImpl::Initialize() {
if (!is_component_enabled()) { if (!is_component_enabled()) {
return apm_->kNoError; return apm_->kNoError;
@@ -282,7 +281,7 @@ int EchoControlMobileImpl::InitializeHandle(void* handle) const {
if (external_echo_path_ != NULL) { if (external_echo_path_ != NULL) {
if (WebRtcAecm_InitEchoPath(my_handle, if (WebRtcAecm_InitEchoPath(my_handle,
external_echo_path_, external_echo_path_,
echo_path_size_bytes_) != 0) { echo_path_size_bytes()) != 0) {
return GetHandleError(my_handle); return GetHandleError(my_handle);
} }
} }

View File

@@ -41,9 +41,8 @@ class EchoControlMobileImpl : public EchoControlMobile,
virtual RoutingMode routing_mode() const; virtual RoutingMode routing_mode() const;
virtual int enable_comfort_noise(bool enable); virtual int enable_comfort_noise(bool enable);
virtual bool is_comfort_noise_enabled() const; virtual bool is_comfort_noise_enabled() const;
virtual int SetEchoPath(const void* echo_path, int size_bytes); virtual int SetEchoPath(const void* echo_path, size_t size_bytes);
virtual int GetEchoPath(void* echo_path, int size_bytes) const; virtual int GetEchoPath(void* echo_path, size_t size_bytes) const;
virtual const int echo_path_size_bytes() const;
// ProcessingComponent implementation. // ProcessingComponent implementation.
virtual void* CreateHandle() const; virtual void* CreateHandle() const;
@@ -56,7 +55,6 @@ class EchoControlMobileImpl : public EchoControlMobile,
const AudioProcessingImpl* apm_; const AudioProcessingImpl* apm_;
RoutingMode routing_mode_; RoutingMode routing_mode_;
bool comfort_noise_enabled_; bool comfort_noise_enabled_;
const int echo_path_size_bytes_;
unsigned char* external_echo_path_; unsigned char* external_echo_path_;
}; };
} // namespace webrtc } // namespace webrtc

View File

@@ -382,7 +382,8 @@ void void_main(int argc, char* argv[]) {
ASSERT_TRUE(NULL != aecm_echo_path_in_file) << "Unable to open file " ASSERT_TRUE(NULL != aecm_echo_path_in_file) << "Unable to open file "
<< aecm_echo_path_in_filename; << aecm_echo_path_in_filename;
const int path_size = apm->echo_control_mobile()->echo_path_size_bytes(); const size_t path_size =
apm->echo_control_mobile()->echo_path_size_bytes();
unsigned char echo_path[path_size]; unsigned char echo_path[path_size];
ASSERT_EQ(path_size, fread(echo_path, ASSERT_EQ(path_size, fread(echo_path,
sizeof(unsigned char), sizeof(unsigned char),
@@ -620,7 +621,8 @@ void void_main(int argc, char* argv[]) {
} }
if (aecm_echo_path_out_file != NULL) { if (aecm_echo_path_out_file != NULL) {
const int path_size = apm->echo_control_mobile()->echo_path_size_bytes(); const size_t path_size =
apm->echo_control_mobile()->echo_path_size_bytes();
unsigned char echo_path[path_size]; unsigned char echo_path[path_size];
apm->echo_control_mobile()->GetEchoPath(echo_path, path_size); apm->echo_control_mobile()->GetEchoPath(echo_path, path_size);
ASSERT_EQ(path_size, fwrite(echo_path, ASSERT_EQ(path_size, fwrite(echo_path,

View File

@@ -65,10 +65,10 @@ class ApmTest : public ::testing::Test {
ApmTest::ApmTest() ApmTest::ApmTest()
: apm_(NULL), : apm_(NULL),
far_file_(NULL),
near_file_(NULL),
frame_(NULL), frame_(NULL),
revframe_(NULL) {} revframe_(NULL),
far_file_(NULL),
near_file_(NULL) {}
void ApmTest::SetUp() { void ApmTest::SetUp() {
apm_ = AudioProcessing::Create(0); apm_ = AudioProcessing::Create(0);
@@ -178,8 +178,9 @@ void WriteMessageLiteToFile(const char* filename,
unsigned char* array = new unsigned char[size]; unsigned char* array = new unsigned char[size];
ASSERT_TRUE(message.SerializeToArray(array, size)); ASSERT_TRUE(message.SerializeToArray(array, size));
ASSERT_EQ(1, fwrite(&size, sizeof(int), 1, file)); ASSERT_EQ(1u, fwrite(&size, sizeof(int), 1, file));
ASSERT_EQ(size, fwrite(array, sizeof(unsigned char), size, file)); ASSERT_EQ(static_cast<size_t>(size),
fwrite(array, sizeof(unsigned char), size, file));
delete [] array; delete [] array;
fclose(file); fclose(file);
@@ -193,10 +194,11 @@ void ReadMessageLiteFromFile(const char* filename,
FILE* file = fopen(filename, "rb"); FILE* file = fopen(filename, "rb");
ASSERT_TRUE(file != NULL) << "Could not open " << filename; ASSERT_TRUE(file != NULL) << "Could not open " << filename;
int size = 0; int size = 0;
ASSERT_EQ(1, fread(&size, sizeof(int), 1, file)); ASSERT_EQ(1u, fread(&size, sizeof(int), 1, file));
ASSERT_GT(size, 0); ASSERT_GT(size, 0);
unsigned char* array = new unsigned char[size]; unsigned char* array = new unsigned char[size];
ASSERT_EQ(size, fread(array, sizeof(unsigned char), size, file)); ASSERT_EQ(static_cast<size_t>(size),
fread(array, sizeof(unsigned char), size, file));
ASSERT_TRUE(message->ParseFromArray(array, size)); ASSERT_TRUE(message->ParseFromArray(array, size));
@@ -413,9 +415,9 @@ TEST_F(ApmTest, Process) {
// We don't have a file; add the required tests to the protobuf. // We don't have a file; add the required tests to the protobuf.
// TODO(ajm): vary the output channels as well? // TODO(ajm): vary the output channels as well?
const int channels[] = {1, 2}; const int channels[] = {1, 2};
const int channels_size = sizeof(channels) / sizeof(*channels); const size_t channels_size = sizeof(channels) / sizeof(*channels);
const int sample_rates[] = {8000, 16000, 32000}; const int sample_rates[] = {8000, 16000, 32000};
const int sample_rates_size = sizeof(sample_rates) / sizeof(*sample_rates); const size_t sample_rates_size = sizeof(sample_rates) / sizeof(*sample_rates);
for (size_t i = 0; i < channels_size; i++) { for (size_t i = 0; i < channels_size; i++) {
for (size_t j = 0; j < channels_size; j++) { for (size_t j = 0; j < channels_size; j++) {
for (size_t k = 0; k < sample_rates_size; k++) { for (size_t k = 0; k < sample_rates_size; k++) {
@@ -709,7 +711,8 @@ TEST_F(ApmTest, EchoControlMobile) {
apm_->echo_control_mobile()->enable_comfort_noise(true)); apm_->echo_control_mobile()->enable_comfort_noise(true));
EXPECT_TRUE(apm_->echo_control_mobile()->is_comfort_noise_enabled()); EXPECT_TRUE(apm_->echo_control_mobile()->is_comfort_noise_enabled());
// Set and get echo path // Set and get echo path
const int echo_path_size = apm_->echo_control_mobile()->echo_path_size_bytes(); const size_t echo_path_size =
apm_->echo_control_mobile()->echo_path_size_bytes();
unsigned char echo_path_in[echo_path_size]; unsigned char echo_path_in[echo_path_size];
unsigned char echo_path_out[echo_path_size]; unsigned char echo_path_out[echo_path_size];
EXPECT_EQ(apm_->kNullPointerError, EXPECT_EQ(apm_->kNullPointerError,
@@ -721,7 +724,7 @@ TEST_F(ApmTest, EchoControlMobile) {
EXPECT_EQ(apm_->kNoError, EXPECT_EQ(apm_->kNoError,
apm_->echo_control_mobile()->GetEchoPath(echo_path_out, apm_->echo_control_mobile()->GetEchoPath(echo_path_out,
echo_path_size)); echo_path_size));
for (int i = 0; i < echo_path_size; i++) { for (size_t i = 0; i < echo_path_size; i++) {
echo_path_in[i] = echo_path_out[i] + 1; echo_path_in[i] = echo_path_out[i] + 1;
} }
EXPECT_EQ(apm_->kBadParameterError, EXPECT_EQ(apm_->kBadParameterError,
@@ -730,7 +733,7 @@ TEST_F(ApmTest, EchoControlMobile) {
apm_->echo_control_mobile()->SetEchoPath(echo_path_in, echo_path_size)); apm_->echo_control_mobile()->SetEchoPath(echo_path_in, echo_path_size));
EXPECT_EQ(apm_->kNoError, EXPECT_EQ(apm_->kNoError,
apm_->echo_control_mobile()->GetEchoPath(echo_path_out, echo_path_size)); apm_->echo_control_mobile()->GetEchoPath(echo_path_out, echo_path_size));
for (int i = 0; i < echo_path_size; i++) { for (size_t i = 0; i < echo_path_size; i++) {
EXPECT_EQ(echo_path_in[i], echo_path_out[i]); EXPECT_EQ(echo_path_in[i], echo_path_out[i]);
} }
// Turn AECM off // Turn AECM off