diff --git a/src/modules/audio_coding/codecs/isac/fix/source/pitch_estimator.c b/src/modules/audio_coding/codecs/isac/fix/source/pitch_estimator.c index df46b69235..6af02d8962 100644 --- a/src/modules/audio_coding/codecs/isac/fix/source/pitch_estimator.c +++ b/src/modules/audio_coding/codecs/isac/fix/source/pitch_estimator.c @@ -19,8 +19,9 @@ #include #endif -#include "signal_processing_library.h" #include "pitch_estimator.h" +#include "signal_processing_library.h" +#include "system_wrappers/interface/compile_assert.h" /* log2[0.2, 0.5, 0.98] in Q8 */ static const WebRtc_Word16 kLogLagWinQ8[3] = { @@ -211,7 +212,7 @@ static void PCorr2Q32(const WebRtc_Word16 *in, WebRtc_Word32 *logcorQ8) // Can't shift a Neon register to right with a non-constant shift value. int32x4_t int_32x4_scale = vdupq_n_s32(-scaling); // Assert a codition used in loop unrolling at compile-time. - WEBRTC_STATIC_ASSERT(PITCH_CORR_LEN2, PITCH_CORR_LEN2 %4 == 0); + COMPILE_ASSERT(PITCH_CORR_LEN2 %4 == 0); for (n = 0; n < PITCH_CORR_LEN2; n += 4) { int16x4_t int_16x4_x = vld1_s16(&x[n]); diff --git a/src/modules/audio_coding/codecs/isac/fix/source/pitch_estimator.h b/src/modules/audio_coding/codecs/isac/fix/source/pitch_estimator.h index e261b813b1..6225256cca 100644 --- a/src/modules/audio_coding/codecs/isac/fix/source/pitch_estimator.h +++ b/src/modules/audio_coding/codecs/isac/fix/source/pitch_estimator.h @@ -20,11 +20,6 @@ #include "structs.h" -// TODO(andrew): put this into general WebRTC so other modules can use it. -// Define a compiler-time assertion. -#define WEBRTC_STATIC_ASSERT(name, boolean_cond) \ - static char const static_assert_##name[(boolean_cond) ? 1 : -1] = {'!'} - void WebRtcIsacfix_PitchAnalysis(const WebRtc_Word16 *in, /* PITCH_FRAME_LEN samples */ WebRtc_Word16 *outQ0, /* PITCH_FRAME_LEN+QLOOKAHEAD samples */ PitchAnalysisStruct *State, diff --git a/src/modules/audio_coding/codecs/isac/fix/source/pitch_filter.c b/src/modules/audio_coding/codecs/isac/fix/source/pitch_filter.c index 0214bc492f..1fc6fa75dd 100644 --- a/src/modules/audio_coding/codecs/isac/fix/source/pitch_filter.c +++ b/src/modules/audio_coding/codecs/isac/fix/source/pitch_filter.c @@ -19,6 +19,7 @@ #include "modules/audio_coding/codecs/isac/fix/source/pitch_estimator.h" #include "modules/audio_coding/codecs/isac/fix/source/settings.h" #include "modules/audio_coding/codecs/isac/fix/source/structs.h" +#include "system_wrappers/interface/compile_assert.h" // Number of segments in a pitch subframe. static const int kSegments = 5; @@ -113,10 +114,6 @@ void WebRtcIsacfix_PitchFilterCore(int loopNumber, (*index2)++; } } -#else -// These two conditions are assumptions in ARM assembly file. -WEBRTC_STATIC_ASSERT(PITCH_FRACORDER, PITCH_FRACORDER == 9); -WEBRTC_STATIC_ASSERT(PITCH_DAMPORDER, PITCH_DAMPORDER == 5); #endif void WebRtcIsacfix_PitchFilter(WebRtc_Word16* indatQQ, // Q10 if type is 1 or 4, @@ -137,6 +134,10 @@ void WebRtcIsacfix_PitchFilter(WebRtc_Word16* indatQQ, // Q10 if type is 1 or 4, WebRtc_Word32 tmpW32; const WebRtc_Word16* fracoeffQQ = NULL; + // Assumptions in ARM assembly for WebRtcIsacfix_PitchFilterCoreARM(). + COMPILE_ASSERT(PITCH_FRACORDER == 9); + COMPILE_ASSERT(PITCH_DAMPORDER == 5); + // Set up buffer and states. memcpy(ubufQQ, pfp->ubufQQ, sizeof(pfp->ubufQQ)); memcpy(inystateQQ, pfp->ystateQQ, sizeof(inystateQQ)); diff --git a/src/modules/audio_processing/aecm/aecm_core.c b/src/modules/audio_processing/aecm/aecm_core.c index 059894870c..8101a57c20 100644 --- a/src/modules/audio_processing/aecm/aecm_core.c +++ b/src/modules/audio_processing/aecm/aecm_core.c @@ -18,6 +18,7 @@ #include "delay_estimator_wrapper.h" #include "echo_control_mobile.h" #include "ring_buffer.h" +#include "system_wrappers/interface/compile_assert.h" #include "typedefs.h" #ifdef ARM_WINM_LOG @@ -198,15 +199,6 @@ static const WebRtc_Word16 kSinTable[] = { static const WebRtc_Word16 kNoiseEstQDomain = 15; static const WebRtc_Word16 kNoiseEstIncCount = 5; -// TODO(andrew): put this into general WebRTC so other modules can use it. -// Define a compiler-time assertion. -#define WEBRTC_STATIC_ASSERT(name, boolean_cond) \ - static char const static_assert_##name[(boolean_cond) ? 1 : -1] = {'!'} - -// Assert a preprocessor definition at compile-time. It's an assumption -// used in assembly code, so check the assembly files before any change. -WEBRTC_STATIC_ASSERT(PART_LEN, PART_LEN % 16 == 0); - static void ComfortNoise(AecmCore_t* aecm, const WebRtc_UWord16* dfa, complex16_t* out, @@ -682,7 +674,9 @@ int WebRtcAecm_InitCore(AecmCore_t * const aecm, int samplingFreq) aecm->supGainErrParamDiffAB = SUPGAIN_ERROR_PARAM_A - SUPGAIN_ERROR_PARAM_B; aecm->supGainErrParamDiffBD = SUPGAIN_ERROR_PARAM_B - SUPGAIN_ERROR_PARAM_D; - assert(PART_LEN % 16 == 0); + // Assert a preprocessor definition at compile-time. It's an assumption + // used in assembly code, so check the assembly files before any change. + COMPILE_ASSERT(PART_LEN % 16 == 0); // Initialize function pointers. WebRtcAecm_WindowAndFFT = WindowAndFFTC; diff --git a/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc b/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc index 5c95a72f1d..be935b8789 100644 --- a/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc +++ b/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc @@ -64,11 +64,9 @@ TEST_F(RtpFormatVp8Test, TestStrictMode) { {true, false, true, true, false, false, false}; const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), - kExpectedPart_wrong_size); + sizeof(kExpectedPart) / sizeof(kExpectedPart[0])); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), - kExpectedFragStart_wrong_size); + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0])); helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, kExpectedFragStart, kExpectedNum); @@ -94,11 +92,9 @@ TEST_F(RtpFormatVp8Test, TestAggregateMode) { const bool kExpectedFragStart[] = {true, false, false, true}; const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), - kExpectedPart_wrong_size); + sizeof(kExpectedPart) / sizeof(kExpectedPart[0])); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), - kExpectedFragStart_wrong_size); + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0])); helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, kExpectedFragStart, kExpectedNum); @@ -124,11 +120,9 @@ TEST_F(RtpFormatVp8Test, TestAggregateModeManyPartitions1) { const bool kExpectedFragStart[] = {true, false, true, true}; const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), - kExpectedPart_wrong_size); + sizeof(kExpectedPart) / sizeof(kExpectedPart[0])); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), - kExpectedFragStart_wrong_size); + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0])); helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, kExpectedFragStart, kExpectedNum); @@ -154,11 +148,9 @@ TEST_F(RtpFormatVp8Test, TestAggregateModeManyPartitions2) { const bool kExpectedFragStart[] = {true, false, true, true, false, true}; const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), - kExpectedPart_wrong_size); + sizeof(kExpectedPart) / sizeof(kExpectedPart[0])); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), - kExpectedFragStart_wrong_size); + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0])); helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, kExpectedFragStart, kExpectedNum); @@ -184,11 +176,9 @@ TEST_F(RtpFormatVp8Test, TestAggregateModeTwoLargePartitions) { const bool kExpectedFragStart[] = {true, false, true, false}; const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), - kExpectedPart_wrong_size); + sizeof(kExpectedPart) / sizeof(kExpectedPart[0])); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), - kExpectedFragStart_wrong_size); + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0])); helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, kExpectedFragStart, kExpectedNum); @@ -214,11 +204,9 @@ TEST_F(RtpFormatVp8Test, TestEqualSizeModeFallback) { const bool kExpectedFragStart[] = {true, false, false, false}; const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), - kExpectedPart_wrong_size); + sizeof(kExpectedPart) / sizeof(kExpectedPart[0])); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), - kExpectedFragStart_wrong_size); + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0])); helper_->set_sloppy_partitioning(true); helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, @@ -245,11 +233,9 @@ TEST_F(RtpFormatVp8Test, TestNonReferenceBit) { const bool kExpectedFragStart[] = {true, false}; const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), - kExpectedPart_wrong_size); + sizeof(kExpectedPart) / sizeof(kExpectedPart[0])); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), - kExpectedFragStart_wrong_size); + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0])); helper_->set_sloppy_partitioning(true); helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, @@ -280,11 +266,9 @@ TEST_F(RtpFormatVp8Test, TestTl0PicIdxAndTID) { const bool kExpectedFragStart[1] = {true}; const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), - kExpectedPart_wrong_size); + sizeof(kExpectedPart) / sizeof(kExpectedPart[0])); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), - kExpectedFragStart_wrong_size); + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0])); helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, kExpectedFragStart, kExpectedNum); @@ -312,11 +296,9 @@ TEST_F(RtpFormatVp8Test, TestKeyIdx) { const bool kExpectedFragStart[1] = {true}; const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), - kExpectedPart_wrong_size); + sizeof(kExpectedPart) / sizeof(kExpectedPart[0])); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), - kExpectedFragStart_wrong_size); + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0])); helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, kExpectedFragStart, kExpectedNum); @@ -345,11 +327,9 @@ TEST_F(RtpFormatVp8Test, TestTIDAndKeyIdx) { const bool kExpectedFragStart[1] = {true}; const int kExpectedNum = sizeof(kExpectedSizes) / sizeof(kExpectedSizes[0]); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedPart) / sizeof(kExpectedPart[0]), - kExpectedPart_wrong_size); + sizeof(kExpectedPart) / sizeof(kExpectedPart[0])); COMPILE_ASSERT(kExpectedNum == - sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0]), - kExpectedFragStart_wrong_size); + sizeof(kExpectedFragStart) / sizeof(kExpectedFragStart[0])); helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart, kExpectedFragStart, kExpectedNum); diff --git a/src/system_wrappers/interface/compile_assert.h b/src/system_wrappers/interface/compile_assert.h index 3ea8bbadfb..4feda86c3a 100644 --- a/src/system_wrappers/interface/compile_assert.h +++ b/src/system_wrappers/interface/compile_assert.h @@ -11,17 +11,11 @@ #ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ -template -struct CompileAssert {}; - -// Use this macro to verify at compile time that certain restrictions are met. -// The first argument is the expression to evaluate, the second is a unique -// identifier for the assert. -// Example: -// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); -#undef COMPILE_ASSERT -#define COMPILE_ASSERT(expr, msg) \ - typedef CompileAssert(expr)> \ - msg[static_cast(expr) ? 1 : -1] +/* Use this macro to verify at compile time that certain restrictions are met. + * The argument is the boolean expression to evaluate. + * Example: + * COMPILE_ASSERT(sizeof(foo) < 128); +*/ +#define COMPILE_ASSERT(expression) switch(0){case 0: case expression:;} #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ diff --git a/src/system_wrappers/source/atomic32_win.cc b/src/system_wrappers/source/atomic32_win.cc index 3bc7f77f0e..2fa9d3dd59 100644 --- a/src/system_wrappers/source/atomic32_win.cc +++ b/src/system_wrappers/source/atomic32_win.cc @@ -22,7 +22,7 @@ Atomic32::Atomic32(WebRtc_Word32 initialValue) : _value(initialValue) { // Make sure that the counter variable we're using is of the same size // as what the API expects. - COMPILE_ASSERT(sizeof(_value) == sizeof(LONG), atomic_size_mismatch); + COMPILE_ASSERT(sizeof(_value) == sizeof(LONG)); assert(Is32bitAligned()); }