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
diff --git a/src/modules/audio_processing/aec/main/source/aec_rdft.c b/src/modules/audio_processing/aec/main/source/aec_rdft.c
index 072a1c4..2e5d216 100644
--- a/src/modules/audio_processing/aec/main/source/aec_rdft.c
+++ b/src/modules/audio_processing/aec/main/source/aec_rdft.c
@@ -494,7 +494,6 @@
void aec_rdft_inverse_128(float *a) {
const int n = 128;
int nw;
- float xi;
nw = ip[0];
a[1] = 0.5f * (a[0] - a[1]);
diff --git a/src/modules/audio_processing/aecm/main/interface/echo_control_mobile.h b/src/modules/audio_processing/aecm/main/interface/echo_control_mobile.h
index d50da71..30bea7a 100644
--- a/src/modules/audio_processing/aecm/main/interface/echo_control_mobile.h
+++ b/src/modules/audio_processing/aecm/main/interface/echo_control_mobile.h
@@ -175,7 +175,7 @@
* -------------------------------------------------------------------
* void* aecmInst Pointer to the AECM instance
* 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
* -------------------------------------------------------------------
@@ -184,7 +184,7 @@
*/
WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
const void* echo_path,
- int size_bytes);
+ size_t size_bytes);
/*
* This function enables the user to get the currently used echo path
@@ -194,7 +194,7 @@
* -------------------------------------------------------------------
* void* aecmInst Pointer to the AECM instance
* 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
* -------------------------------------------------------------------
@@ -203,16 +203,16 @@
*/
WebRtc_Word32 WebRtcAecm_GetEchoPath(void* aecmInst,
void* echo_path,
- int size_bytes);
+ size_t size_bytes);
/*
* This function enables the user to get the echo path size in bytes
*
* 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.
diff --git a/src/modules/audio_processing/aecm/main/source/echo_control_mobile.c b/src/modules/audio_processing/aecm/main/source/echo_control_mobile.c
index fc4c389..68eb598 100644
--- a/src/modules/audio_processing/aecm/main/source/echo_control_mobile.c
+++ b/src/modules/audio_processing/aecm/main/source/echo_control_mobile.c
@@ -622,7 +622,7 @@
WebRtc_Word32 WebRtcAecm_InitEchoPath(void* aecmInst,
const void* echo_path,
- int size_bytes)
+ size_t size_bytes)
{
aecmob_t *aecm = aecmInst;
const WebRtc_Word16* echo_path_ptr = echo_path;
@@ -651,7 +651,7 @@
WebRtc_Word32 WebRtcAecm_GetEchoPath(void* aecmInst,
void* echo_path,
- int size_bytes)
+ size_t size_bytes)
{
aecmob_t *aecm = aecmInst;
WebRtc_Word16* echo_path_ptr = echo_path;
@@ -677,7 +677,7 @@
return 0;
}
-int WebRtcAecm_echo_path_size_bytes()
+size_t WebRtcAecm_echo_path_size_bytes()
{
return (PART_LEN1 * sizeof(WebRtc_Word16));
}
diff --git a/src/modules/audio_processing/main/interface/audio_processing.h b/src/modules/audio_processing/main/interface/audio_processing.h
index 4d5df2f..350ef82 100644
--- a/src/modules/audio_processing/main/interface/audio_processing.h
+++ b/src/modules/audio_processing/main/interface/audio_processing.h
@@ -11,6 +11,8 @@
#ifndef 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 "module.h"
@@ -357,18 +359,24 @@
virtual bool is_comfort_noise_enabled() const = 0;
// 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
- // at the end of a call. The data can then be stored for later use as
- // initializer, using |SetEchoPath()|.
+ // 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 an
+ // initializer before the next call, using |SetEchoPath()|.
+ //
// Controlling the echo path this way requires the data |size_bytes| to match
// the internal echo path size. This size can be acquired using
// |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
- // version incompatibilities may result in a stored echo path of the
- // incorrect size. In this case, the stored path should be discarded.
- virtual int SetEchoPath(const void* echo_path, int size_bytes) = 0;
- virtual int GetEchoPath(void* echo_path, int size_bytes) const = 0;
- virtual const int echo_path_size_bytes() const = 0;
+ // noting if it is to be called during an ongoing call.
+ //
+ // It is possible that version incompatibilities may result in a stored echo
+ // path of the incorrect size. In this case, the stored path should be
+ // discarded.
+ 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:
virtual ~EchoControlMobile() {};
diff --git a/src/modules/audio_processing/main/source/echo_control_mobile_impl.cc b/src/modules/audio_processing/main/source/echo_control_mobile_impl.cc
index ce940eb..ff15255 100644
--- a/src/modules/audio_processing/main/source/echo_control_mobile_impl.cc
+++ b/src/modules/audio_processing/main/source/echo_control_mobile_impl.cc
@@ -59,12 +59,15 @@
}
} // namespace
+size_t EchoControlMobile::echo_path_size_bytes() {
+ return WebRtcAecm_echo_path_size_bytes();
+}
+
EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessingImpl* apm)
: ProcessingComponent(apm),
apm_(apm),
routing_mode_(kSpeakerphone),
comfort_noise_enabled_(true),
- echo_path_size_bytes_(WebRtcAecm_echo_path_size_bytes()),
external_echo_path_(NULL) {}
EchoControlMobileImpl::~EchoControlMobileImpl() {
@@ -191,12 +194,12 @@
}
int EchoControlMobileImpl::SetEchoPath(const void* echo_path,
- int size_bytes) {
+ size_t size_bytes) {
CriticalSectionScoped crit_scoped(*apm_->crit());
if (echo_path == NULL) {
return apm_->kNullPointerError;
}
- if (size_bytes != echo_path_size_bytes_) {
+ if (size_bytes != echo_path_size_bytes()) {
// Size mismatch
return apm_->kBadParameterError;
}
@@ -210,12 +213,12 @@
}
int EchoControlMobileImpl::GetEchoPath(void* echo_path,
- int size_bytes) const {
+ size_t size_bytes) const {
CriticalSectionScoped crit_scoped(*apm_->crit());
if (echo_path == NULL) {
return apm_->kNullPointerError;
}
- if (size_bytes != echo_path_size_bytes_) {
+ if (size_bytes != echo_path_size_bytes()) {
// Size mismatch
return apm_->kBadParameterError;
}
@@ -232,10 +235,6 @@
return apm_->kNoError;
}
-const int EchoControlMobileImpl::echo_path_size_bytes() const {
- return echo_path_size_bytes_;
-}
-
int EchoControlMobileImpl::Initialize() {
if (!is_component_enabled()) {
return apm_->kNoError;
@@ -282,7 +281,7 @@
if (external_echo_path_ != NULL) {
if (WebRtcAecm_InitEchoPath(my_handle,
external_echo_path_,
- echo_path_size_bytes_) != 0) {
+ echo_path_size_bytes()) != 0) {
return GetHandleError(my_handle);
}
}
diff --git a/src/modules/audio_processing/main/source/echo_control_mobile_impl.h b/src/modules/audio_processing/main/source/echo_control_mobile_impl.h
index 5e5bd4e..6314e660 100644
--- a/src/modules/audio_processing/main/source/echo_control_mobile_impl.h
+++ b/src/modules/audio_processing/main/source/echo_control_mobile_impl.h
@@ -41,9 +41,8 @@
virtual RoutingMode routing_mode() const;
virtual int enable_comfort_noise(bool enable);
virtual bool is_comfort_noise_enabled() const;
- virtual int SetEchoPath(const void* echo_path, int size_bytes);
- virtual int GetEchoPath(void* echo_path, int size_bytes) const;
- virtual const int echo_path_size_bytes() const;
+ virtual int SetEchoPath(const void* echo_path, size_t size_bytes);
+ virtual int GetEchoPath(void* echo_path, size_t size_bytes) const;
// ProcessingComponent implementation.
virtual void* CreateHandle() const;
@@ -56,7 +55,6 @@
const AudioProcessingImpl* apm_;
RoutingMode routing_mode_;
bool comfort_noise_enabled_;
- const int echo_path_size_bytes_;
unsigned char* external_echo_path_;
};
} // namespace webrtc
diff --git a/src/modules/audio_processing/main/test/process_test/process_test.cc b/src/modules/audio_processing/main/test/process_test/process_test.cc
index 694b851..7e416ec 100644
--- a/src/modules/audio_processing/main/test/process_test/process_test.cc
+++ b/src/modules/audio_processing/main/test/process_test/process_test.cc
@@ -382,7 +382,8 @@
ASSERT_TRUE(NULL != aecm_echo_path_in_file) << "Unable to open file "
<< 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];
ASSERT_EQ(path_size, fread(echo_path,
sizeof(unsigned char),
@@ -620,7 +621,8 @@
}
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];
apm->echo_control_mobile()->GetEchoPath(echo_path, path_size);
ASSERT_EQ(path_size, fwrite(echo_path,
diff --git a/src/modules/audio_processing/main/test/unit_test/unit_test.cc b/src/modules/audio_processing/main/test/unit_test/unit_test.cc
index 6946d82..d129458 100644
--- a/src/modules/audio_processing/main/test/unit_test/unit_test.cc
+++ b/src/modules/audio_processing/main/test/unit_test/unit_test.cc
@@ -65,10 +65,10 @@
ApmTest::ApmTest()
: apm_(NULL),
- far_file_(NULL),
- near_file_(NULL),
frame_(NULL),
- revframe_(NULL) {}
+ revframe_(NULL),
+ far_file_(NULL),
+ near_file_(NULL) {}
void ApmTest::SetUp() {
apm_ = AudioProcessing::Create(0);
@@ -178,8 +178,9 @@
unsigned char* array = new unsigned char[size];
ASSERT_TRUE(message.SerializeToArray(array, size));
- ASSERT_EQ(1, fwrite(&size, sizeof(int), 1, file));
- ASSERT_EQ(size, fwrite(array, sizeof(unsigned char), size, file));
+ ASSERT_EQ(1u, fwrite(&size, sizeof(int), 1, file));
+ ASSERT_EQ(static_cast<size_t>(size),
+ fwrite(array, sizeof(unsigned char), size, file));
delete [] array;
fclose(file);
@@ -193,10 +194,11 @@
FILE* file = fopen(filename, "rb");
ASSERT_TRUE(file != NULL) << "Could not open " << filename;
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);
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));
@@ -413,9 +415,9 @@
// We don't have a file; add the required tests to the protobuf.
// TODO(ajm): vary the output channels as well?
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_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 j = 0; j < channels_size; j++) {
for (size_t k = 0; k < sample_rates_size; k++) {
@@ -709,7 +711,8 @@
apm_->echo_control_mobile()->enable_comfort_noise(true));
EXPECT_TRUE(apm_->echo_control_mobile()->is_comfort_noise_enabled());
// 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_out[echo_path_size];
EXPECT_EQ(apm_->kNullPointerError,
@@ -721,7 +724,7 @@
EXPECT_EQ(apm_->kNoError,
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++) {
echo_path_in[i] = echo_path_out[i] + 1;
}
EXPECT_EQ(apm_->kBadParameterError,
@@ -730,7 +733,7 @@
apm_->echo_control_mobile()->SetEchoPath(echo_path_in, echo_path_size));
EXPECT_EQ(apm_->kNoError,
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]);
}
// Turn AECM off