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

Side by Side Diff: media/base/audio_fifo_unittest.cc

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: . Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO(henrika): add test which included |start_frame| in Consume() call. 5 // TODO(henrika): add test which included |start_frame| in Consume() call.
6 6
7 #include <memory>
8
7 #include "base/macros.h" 9 #include "base/macros.h"
8 #include "media/base/audio_fifo.h" 10 #include "media/base/audio_fifo.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 12
11 namespace media { 13 namespace media {
12 14
13 class AudioFifoTest : public testing::Test { 15 class AudioFifoTest : public testing::Test {
14 public: 16 public:
15 AudioFifoTest() {} 17 AudioFifoTest() {}
16 ~AudioFifoTest() override {} 18 ~AudioFifoTest() override {}
(...skipping 15 matching lines...) Expand all
32 EXPECT_EQ(fifo.frames(), 0); 34 EXPECT_EQ(fifo.frames(), 0);
33 } 35 }
34 36
35 // Pushes audio bus objects to a FIFO and fill it up to different degrees. 37 // Pushes audio bus objects to a FIFO and fill it up to different degrees.
36 TEST_F(AudioFifoTest, Push) { 38 TEST_F(AudioFifoTest, Push) {
37 static const int kChannels = 2; 39 static const int kChannels = 2;
38 static const int kMaxFrameCount = 128; 40 static const int kMaxFrameCount = 128;
39 AudioFifo fifo(kChannels, kMaxFrameCount); 41 AudioFifo fifo(kChannels, kMaxFrameCount);
40 { 42 {
41 SCOPED_TRACE("Push 50%"); 43 SCOPED_TRACE("Push 50%");
42 scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount / 2); 44 std::unique_ptr<AudioBus> bus =
45 AudioBus::Create(kChannels, kMaxFrameCount / 2);
43 EXPECT_EQ(fifo.frames(), 0); 46 EXPECT_EQ(fifo.frames(), 0);
44 fifo.Push(bus.get()); 47 fifo.Push(bus.get());
45 EXPECT_EQ(fifo.frames(), bus->frames()); 48 EXPECT_EQ(fifo.frames(), bus->frames());
46 fifo.Clear(); 49 fifo.Clear();
47 } 50 }
48 { 51 {
49 SCOPED_TRACE("Push 100%"); 52 SCOPED_TRACE("Push 100%");
50 scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount); 53 std::unique_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount);
51 EXPECT_EQ(fifo.frames(), 0); 54 EXPECT_EQ(fifo.frames(), 0);
52 fifo.Push(bus.get()); 55 fifo.Push(bus.get());
53 EXPECT_EQ(fifo.frames(), bus->frames()); 56 EXPECT_EQ(fifo.frames(), bus->frames());
54 fifo.Clear(); 57 fifo.Clear();
55 } 58 }
56 } 59 }
57 60
58 // Consumes audio bus objects from a FIFO and empty it to different degrees. 61 // Consumes audio bus objects from a FIFO and empty it to different degrees.
59 TEST_F(AudioFifoTest, Consume) { 62 TEST_F(AudioFifoTest, Consume) {
60 static const int kChannels = 2; 63 static const int kChannels = 2;
61 static const int kMaxFrameCount = 128; 64 static const int kMaxFrameCount = 128;
62 AudioFifo fifo(kChannels, kMaxFrameCount); 65 AudioFifo fifo(kChannels, kMaxFrameCount);
63 { 66 {
64 scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount); 67 std::unique_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount);
65 fifo.Push(bus.get()); 68 fifo.Push(bus.get());
66 EXPECT_EQ(fifo.frames(), kMaxFrameCount); 69 EXPECT_EQ(fifo.frames(), kMaxFrameCount);
67 } 70 }
68 { 71 {
69 SCOPED_TRACE("Consume 50%"); 72 SCOPED_TRACE("Consume 50%");
70 scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount / 2); 73 std::unique_ptr<AudioBus> bus =
74 AudioBus::Create(kChannels, kMaxFrameCount / 2);
71 fifo.Consume(bus.get(), 0, bus->frames()); 75 fifo.Consume(bus.get(), 0, bus->frames());
72 EXPECT_TRUE(fifo.frames() == bus->frames()); 76 EXPECT_TRUE(fifo.frames() == bus->frames());
73 fifo.Push(bus.get()); 77 fifo.Push(bus.get());
74 EXPECT_EQ(fifo.frames(), kMaxFrameCount); 78 EXPECT_EQ(fifo.frames(), kMaxFrameCount);
75 } 79 }
76 { 80 {
77 SCOPED_TRACE("Consume 100%"); 81 SCOPED_TRACE("Consume 100%");
78 scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount); 82 std::unique_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount);
79 fifo.Consume(bus.get(), 0, bus->frames()); 83 fifo.Consume(bus.get(), 0, bus->frames());
80 EXPECT_EQ(fifo.frames(), 0); 84 EXPECT_EQ(fifo.frames(), 0);
81 fifo.Push(bus.get()); 85 fifo.Push(bus.get());
82 EXPECT_EQ(fifo.frames(), kMaxFrameCount); 86 EXPECT_EQ(fifo.frames(), kMaxFrameCount);
83 } 87 }
84 } 88 }
85 89
86 // Verify that the frames() method of the FIFO works as intended while 90 // Verify that the frames() method of the FIFO works as intended while
87 // appending and removing audio bus elements to/from the FIFO. 91 // appending and removing audio bus elements to/from the FIFO.
88 TEST_F(AudioFifoTest, FramesInFifo) { 92 TEST_F(AudioFifoTest, FramesInFifo) {
89 static const int kChannels = 2; 93 static const int kChannels = 2;
90 static const int kMaxFrameCount = 64; 94 static const int kMaxFrameCount = 64;
91 AudioFifo fifo(kChannels, kMaxFrameCount); 95 AudioFifo fifo(kChannels, kMaxFrameCount);
92 96
93 // Fill up the FIFO and verify that the size grows as it should while adding 97 // Fill up the FIFO and verify that the size grows as it should while adding
94 // one audio frame each time. 98 // one audio frame each time.
95 scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, 1); 99 std::unique_ptr<AudioBus> bus = AudioBus::Create(kChannels, 1);
96 int n = 0; 100 int n = 0;
97 while (fifo.frames() < kMaxFrameCount) { 101 while (fifo.frames() < kMaxFrameCount) {
98 fifo.Push(bus.get()); 102 fifo.Push(bus.get());
99 EXPECT_EQ(fifo.frames(), ++n); 103 EXPECT_EQ(fifo.frames(), ++n);
100 } 104 }
101 EXPECT_EQ(fifo.frames(), kMaxFrameCount); 105 EXPECT_EQ(fifo.frames(), kMaxFrameCount);
102 106
103 // Empty the FIFO and verify that the size decreases as it should. 107 // Empty the FIFO and verify that the size decreases as it should.
104 // Reduce the size of the FIFO by one frame each time. 108 // Reduce the size of the FIFO by one frame each time.
105 while (fifo.frames() > 0) { 109 while (fifo.frames() > 0) {
106 fifo.Consume(bus.get(), 0, bus->frames()); 110 fifo.Consume(bus.get(), 0, bus->frames());
107 EXPECT_EQ(fifo.frames(), --n); 111 EXPECT_EQ(fifo.frames(), --n);
108 } 112 }
109 EXPECT_EQ(fifo.frames(), 0); 113 EXPECT_EQ(fifo.frames(), 0);
110 114
111 // Verify that a steady-state size of #frames in the FIFO is maintained 115 // Verify that a steady-state size of #frames in the FIFO is maintained
112 // during a sequence of Push/Consume calls which involves wrapping. We ensure 116 // during a sequence of Push/Consume calls which involves wrapping. We ensure
113 // wrapping by selecting a buffer size which does divides the FIFO size 117 // wrapping by selecting a buffer size which does divides the FIFO size
114 // with a remainder of one. 118 // with a remainder of one.
115 scoped_ptr<AudioBus> bus2 = 119 std::unique_ptr<AudioBus> bus2 =
116 AudioBus::Create(kChannels, (kMaxFrameCount / 4) - 1); 120 AudioBus::Create(kChannels, (kMaxFrameCount / 4) - 1);
117 const int frames_in_fifo = bus2->frames(); 121 const int frames_in_fifo = bus2->frames();
118 fifo.Push(bus2.get()); 122 fifo.Push(bus2.get());
119 EXPECT_EQ(fifo.frames(), frames_in_fifo); 123 EXPECT_EQ(fifo.frames(), frames_in_fifo);
120 for (int n = 0; n < kMaxFrameCount; ++n) { 124 for (int n = 0; n < kMaxFrameCount; ++n) {
121 fifo.Push(bus2.get()); 125 fifo.Push(bus2.get());
122 fifo.Consume(bus2.get(), 0, frames_in_fifo); 126 fifo.Consume(bus2.get(), 0, frames_in_fifo);
123 EXPECT_EQ(fifo.frames(), frames_in_fifo); 127 EXPECT_EQ(fifo.frames(), frames_in_fifo);
124 } 128 }
125 } 129 }
126 130
127 // Perform a sequence of Push/Consume calls and verify that the data written 131 // Perform a sequence of Push/Consume calls and verify that the data written
128 // to the FIFO is correctly retrieved, i.e., that the order is correct and the 132 // to the FIFO is correctly retrieved, i.e., that the order is correct and the
129 // values are correct. 133 // values are correct.
130 TEST_F(AudioFifoTest, VerifyDataValues) { 134 TEST_F(AudioFifoTest, VerifyDataValues) {
131 static const int kChannels = 2; 135 static const int kChannels = 2;
132 static const int kFrameCount = 2; 136 static const int kFrameCount = 2;
133 static const int kFifoFrameCount = 5 * kFrameCount; 137 static const int kFifoFrameCount = 5 * kFrameCount;
134 138
135 AudioFifo fifo(kChannels, kFifoFrameCount); 139 AudioFifo fifo(kChannels, kFifoFrameCount);
136 scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kFrameCount); 140 std::unique_ptr<AudioBus> bus = AudioBus::Create(kChannels, kFrameCount);
137 EXPECT_EQ(fifo.frames(), 0); 141 EXPECT_EQ(fifo.frames(), 0);
138 EXPECT_EQ(bus->frames(), kFrameCount); 142 EXPECT_EQ(bus->frames(), kFrameCount);
139 143
140 // Start by filling up the FIFO with audio frames. The first audio frame 144 // Start by filling up the FIFO with audio frames. The first audio frame
141 // will contain all 1's, the second all 2's etc. All channels contain the 145 // will contain all 1's, the second all 2's etc. All channels contain the
142 // same value. 146 // same value.
143 int value = 1; 147 int value = 1;
144 while (fifo.frames() < kFifoFrameCount) { 148 while (fifo.frames() < kFifoFrameCount) {
145 for (int j = 0; j < bus->channels(); ++j) 149 for (int j = 0; j < bus->channels(); ++j)
146 std::fill(bus->channel(j), bus->channel(j) + bus->frames(), value); 150 std::fill(bus->channel(j), bus->channel(j) + bus->frames(), value);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 VerifyValue(bus->channel(j), bus->channels(), value); 190 VerifyValue(bus->channel(j), bus->channels(), value);
187 std::fill(bus->channel(j), bus->channel(j) + bus->frames(), value + 1); 191 std::fill(bus->channel(j), bus->channel(j) + bus->frames(), value + 1);
188 } 192 }
189 fifo.Push(bus.get()); 193 fifo.Push(bus.get());
190 EXPECT_EQ(fifo.frames(), bus->frames()); 194 EXPECT_EQ(fifo.frames(), bus->frames());
191 ++value; 195 ++value;
192 } 196 }
193 } 197 }
194 198
195 } // namespace media 199 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698