Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Unified Diff: webrtc/modules/module_common_types_unittest.cc

Issue 2750783004: Add mute state field to AudioFrame. (Closed)
Patch Set: Update new usages of AudioFrame::data_ Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/include/module_common_types.h ('k') | webrtc/tools/agc/activity_metric.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/module_common_types_unittest.cc
diff --git a/webrtc/modules/module_common_types_unittest.cc b/webrtc/modules/module_common_types_unittest.cc
index e4d5033b888f56a876e037f98aa369afcc7ee15d..f91668b162bafc3adcb6d0eaba7b7727bd473d96 100644
--- a/webrtc/modules/module_common_types_unittest.cc
+++ b/webrtc/modules/module_common_types_unittest.cc
@@ -10,10 +10,111 @@
#include "webrtc/modules/include/module_common_types.h"
+#include <string.h> // memcmp
+
#include "webrtc/test/gtest.h"
namespace webrtc {
+namespace {
+
+bool AllSamplesAre(int16_t sample, const AudioFrame& frame) {
+ const int16_t* frame_data = frame.data();
+ for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) {
+ if (frame_data[i] != sample) {
+ return false;
+ }
+ }
+ return true;
+}
+
+constexpr int kId = 16;
+constexpr uint32_t kTimestamp = 27;
+constexpr int kSampleRateHz = 16000;
+constexpr size_t kNumChannels = 1;
+constexpr size_t kSamplesPerChannel = kSampleRateHz / 100;
+
+} // namespace
+
+TEST(AudioFrameTest, FrameStartsMuted) {
+ AudioFrame frame;
+ EXPECT_TRUE(frame.muted());
+ EXPECT_TRUE(AllSamplesAre(0, frame));
+}
+
+TEST(AudioFrameTest, UnmutedFrameIsInitiallyZeroed) {
+ AudioFrame frame;
+ frame.mutable_data();
+ EXPECT_FALSE(frame.muted());
+ EXPECT_TRUE(AllSamplesAre(0, frame));
+}
+
+TEST(AudioFrameTest, MutedFrameBufferIsZeroed) {
+ AudioFrame frame;
+ int16_t* frame_data = frame.mutable_data();
+ for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) {
+ frame_data[i] = 17;
+ }
+ ASSERT_TRUE(AllSamplesAre(17, frame));
+ frame.Mute();
+ EXPECT_TRUE(frame.muted());
+ EXPECT_TRUE(AllSamplesAre(0, frame));
+}
+
+TEST(AudioFrameTest, UpdateFrame) {
+ AudioFrame frame;
+ int16_t samples[kNumChannels * kSamplesPerChannel] = {17};
+ frame.UpdateFrame(kId, kTimestamp, samples, kSamplesPerChannel, kSampleRateHz,
+ AudioFrame::kPLC, AudioFrame::kVadActive, kNumChannels);
+
+ EXPECT_EQ(kId, frame.id_);
+ EXPECT_EQ(kTimestamp, frame.timestamp_);
+ EXPECT_EQ(kSamplesPerChannel, frame.samples_per_channel_);
+ EXPECT_EQ(kSampleRateHz, frame.sample_rate_hz_);
+ EXPECT_EQ(AudioFrame::kPLC, frame.speech_type_);
+ EXPECT_EQ(AudioFrame::kVadActive, frame.vad_activity_);
+ EXPECT_EQ(kNumChannels, frame.num_channels_);
+
+ EXPECT_FALSE(frame.muted());
+ EXPECT_EQ(0, memcmp(samples, frame.data(), sizeof(samples)));
+
+ frame.UpdateFrame(kId, kTimestamp, nullptr /* data*/, kSamplesPerChannel,
+ kSampleRateHz, AudioFrame::kPLC, AudioFrame::kVadActive,
+ kNumChannels);
+ EXPECT_TRUE(frame.muted());
+ EXPECT_TRUE(AllSamplesAre(0, frame));
+}
+
+TEST(AudioFrameTest, CopyFrom) {
+ AudioFrame frame1;
+ AudioFrame frame2;
+
+ int16_t samples[kNumChannels * kSamplesPerChannel] = {17};
+ frame2.UpdateFrame(kId, kTimestamp, samples, kSamplesPerChannel,
+ kSampleRateHz, AudioFrame::kPLC, AudioFrame::kVadActive,
+ kNumChannels);
+ frame1.CopyFrom(frame2);
+
+ EXPECT_EQ(frame2.id_, frame1.id_);
+ EXPECT_EQ(frame2.timestamp_, frame1.timestamp_);
+ EXPECT_EQ(frame2.samples_per_channel_, frame1.samples_per_channel_);
+ EXPECT_EQ(frame2.sample_rate_hz_, frame1.sample_rate_hz_);
+ EXPECT_EQ(frame2.speech_type_, frame1.speech_type_);
+ EXPECT_EQ(frame2.vad_activity_, frame1.vad_activity_);
+ EXPECT_EQ(frame2.num_channels_, frame1.num_channels_);
+
+ EXPECT_EQ(frame2.muted(), frame1.muted());
+ EXPECT_EQ(0, memcmp(frame2.data(), frame1.data(), sizeof(samples)));
+
+ frame2.UpdateFrame(kId, kTimestamp, nullptr /* data */, kSamplesPerChannel,
+ kSampleRateHz, AudioFrame::kPLC, AudioFrame::kVadActive,
+ kNumChannels);
+ frame1.CopyFrom(frame2);
+
+ EXPECT_EQ(frame2.muted(), frame1.muted());
+ EXPECT_EQ(0, memcmp(frame2.data(), frame1.data(), sizeof(samples)));
+}
+
TEST(IsNewerSequenceNumber, Equal) {
EXPECT_FALSE(IsNewerSequenceNumber(0x0001, 0x0001));
}
« no previous file with comments | « webrtc/modules/include/module_common_types.h ('k') | webrtc/tools/agc/activity_metric.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698