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

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

Issue 17315021: Refactored DataBuffer to use unix_hacker style methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Inlined getters and setters on DataBuffer Created 7 years, 5 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
« no previous file with comments | « media/base/audio_splicer.cc ('k') | media/base/data_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "media/base/audio_splicer.h" 6 #include "media/base/audio_splicer.h"
7 #include "media/base/audio_timestamp_helper.h" 7 #include "media/base/audio_timestamp_helper.h"
8 #include "media/base/buffers.h" 8 #include "media/base/buffers.h"
9 #include "media/base/data_buffer.h" 9 #include "media/base/data_buffer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 11 matching lines...) Expand all
22 input_timestamp_helper_(kBytesPerFrame, kDefaultSampleRate) { 22 input_timestamp_helper_(kBytesPerFrame, kDefaultSampleRate) {
23 input_timestamp_helper_.SetBaseTimestamp(base::TimeDelta()); 23 input_timestamp_helper_.SetBaseTimestamp(base::TimeDelta());
24 } 24 }
25 25
26 scoped_refptr<DataBuffer> GetNextInputBuffer(uint8 value) { 26 scoped_refptr<DataBuffer> GetNextInputBuffer(uint8 value) {
27 return GetNextInputBuffer(value, kDefaultBufferSize); 27 return GetNextInputBuffer(value, kDefaultBufferSize);
28 } 28 }
29 29
30 scoped_refptr<DataBuffer> GetNextInputBuffer(uint8 value, int size) { 30 scoped_refptr<DataBuffer> GetNextInputBuffer(uint8 value, int size) {
31 scoped_refptr<DataBuffer> buffer = new DataBuffer(size); 31 scoped_refptr<DataBuffer> buffer = new DataBuffer(size);
32 buffer->SetDataSize(size); 32 buffer->set_data_size(size);
33 memset(buffer->GetWritableData(), value, buffer->GetDataSize()); 33 memset(buffer->writable_data(), value, buffer->data_size());
34 buffer->SetTimestamp(input_timestamp_helper_.GetTimestamp()); 34 buffer->set_timestamp(input_timestamp_helper_.GetTimestamp());
35 buffer->SetDuration( 35 buffer->set_duration(
36 input_timestamp_helper_.GetDuration(buffer->GetDataSize())); 36 input_timestamp_helper_.GetDuration(buffer->data_size()));
37 input_timestamp_helper_.AddBytes(buffer->GetDataSize()); 37 input_timestamp_helper_.AddBytes(buffer->data_size());
38 return buffer; 38 return buffer;
39 } 39 }
40 40
41 bool VerifyData(const uint8* data, int size, int value) { 41 bool VerifyData(const uint8* data, int size, int value) {
42 for (int i = 0; i < size; ++i) { 42 for (int i = 0; i < size; ++i) {
43 if (data[i] != value) 43 if (data[i] != value)
44 return false; 44 return false;
45 } 45 }
46 return true; 46 return true;
47 } 47 }
48 48
49 protected: 49 protected:
50 AudioSplicer splicer_; 50 AudioSplicer splicer_;
51 AudioTimestampHelper input_timestamp_helper_; 51 AudioTimestampHelper input_timestamp_helper_;
52 52
53 DISALLOW_COPY_AND_ASSIGN(AudioSplicerTest); 53 DISALLOW_COPY_AND_ASSIGN(AudioSplicerTest);
54 }; 54 };
55 55
56 TEST_F(AudioSplicerTest, PassThru) { 56 TEST_F(AudioSplicerTest, PassThru) {
57 EXPECT_FALSE(splicer_.HasNextBuffer()); 57 EXPECT_FALSE(splicer_.HasNextBuffer());
58 58
59 // Test single buffer pass-thru behavior. 59 // Test single buffer pass-thru behavior.
60 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); 60 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1);
61 EXPECT_TRUE(splicer_.AddInput(input_1)); 61 EXPECT_TRUE(splicer_.AddInput(input_1));
62 EXPECT_TRUE(splicer_.HasNextBuffer()); 62 EXPECT_TRUE(splicer_.HasNextBuffer());
63 63
64 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); 64 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer();
65 EXPECT_FALSE(splicer_.HasNextBuffer()); 65 EXPECT_FALSE(splicer_.HasNextBuffer());
66 EXPECT_EQ(input_1->GetTimestamp(), output_1->GetTimestamp()); 66 EXPECT_EQ(input_1->timestamp(), output_1->timestamp());
67 EXPECT_EQ(input_1->GetDuration(), output_1->GetDuration()); 67 EXPECT_EQ(input_1->duration(), output_1->duration());
68 EXPECT_EQ(input_1->GetDataSize(), output_1->GetDataSize()); 68 EXPECT_EQ(input_1->data_size(), output_1->data_size());
69 69
70 // Test that multiple buffers can be queued in the splicer. 70 // Test that multiple buffers can be queued in the splicer.
71 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2); 71 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2);
72 scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(3); 72 scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(3);
73 EXPECT_TRUE(splicer_.AddInput(input_2)); 73 EXPECT_TRUE(splicer_.AddInput(input_2));
74 EXPECT_TRUE(splicer_.AddInput(input_3)); 74 EXPECT_TRUE(splicer_.AddInput(input_3));
75 EXPECT_TRUE(splicer_.HasNextBuffer()); 75 EXPECT_TRUE(splicer_.HasNextBuffer());
76 76
77 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); 77 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer();
78 EXPECT_TRUE(splicer_.HasNextBuffer()); 78 EXPECT_TRUE(splicer_.HasNextBuffer());
79 EXPECT_EQ(input_2->GetTimestamp(), output_2->GetTimestamp()); 79 EXPECT_EQ(input_2->timestamp(), output_2->timestamp());
80 EXPECT_EQ(input_2->GetDuration(), output_2->GetDuration()); 80 EXPECT_EQ(input_2->duration(), output_2->duration());
81 EXPECT_EQ(input_2->GetDataSize(), output_2->GetDataSize()); 81 EXPECT_EQ(input_2->data_size(), output_2->data_size());
82 82
83 scoped_refptr<DataBuffer> output_3 = splicer_.GetNextBuffer(); 83 scoped_refptr<DataBuffer> output_3 = splicer_.GetNextBuffer();
84 EXPECT_FALSE(splicer_.HasNextBuffer()); 84 EXPECT_FALSE(splicer_.HasNextBuffer());
85 EXPECT_EQ(input_3->GetTimestamp(), output_3->GetTimestamp()); 85 EXPECT_EQ(input_3->timestamp(), output_3->timestamp());
86 EXPECT_EQ(input_3->GetDuration(), output_3->GetDuration()); 86 EXPECT_EQ(input_3->duration(), output_3->duration());
87 EXPECT_EQ(input_3->GetDataSize(), output_3->GetDataSize()); 87 EXPECT_EQ(input_3->data_size(), output_3->data_size());
88 } 88 }
89 89
90 TEST_F(AudioSplicerTest, Reset) { 90 TEST_F(AudioSplicerTest, Reset) {
91 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); 91 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1);
92 EXPECT_TRUE(splicer_.AddInput(input_1)); 92 EXPECT_TRUE(splicer_.AddInput(input_1));
93 EXPECT_TRUE(splicer_.HasNextBuffer()); 93 EXPECT_TRUE(splicer_.HasNextBuffer());
94 94
95 splicer_.Reset(); 95 splicer_.Reset();
96 EXPECT_FALSE(splicer_.HasNextBuffer()); 96 EXPECT_FALSE(splicer_.HasNextBuffer());
97 97
98 // Add some bytes to the timestamp helper so that the 98 // Add some bytes to the timestamp helper so that the
99 // next buffer starts many frames beyond the end of 99 // next buffer starts many frames beyond the end of
100 // |input_1|. This is to make sure that Reset() actually 100 // |input_1|. This is to make sure that Reset() actually
101 // clears its state and doesn't try to insert a gap. 101 // clears its state and doesn't try to insert a gap.
102 input_timestamp_helper_.AddBytes(100 * kBytesPerFrame); 102 input_timestamp_helper_.AddBytes(100 * kBytesPerFrame);
103 103
104 // Verify that a new input buffer passes through as expected. 104 // Verify that a new input buffer passes through as expected.
105 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2); 105 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2);
106 EXPECT_TRUE(splicer_.AddInput(input_2)); 106 EXPECT_TRUE(splicer_.AddInput(input_2));
107 EXPECT_TRUE(splicer_.HasNextBuffer()); 107 EXPECT_TRUE(splicer_.HasNextBuffer());
108 108
109 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); 109 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer();
110 EXPECT_FALSE(splicer_.HasNextBuffer()); 110 EXPECT_FALSE(splicer_.HasNextBuffer());
111 EXPECT_EQ(input_2->GetTimestamp(), output_2->GetTimestamp()); 111 EXPECT_EQ(input_2->timestamp(), output_2->timestamp());
112 EXPECT_EQ(input_2->GetDuration(), output_2->GetDuration()); 112 EXPECT_EQ(input_2->duration(), output_2->duration());
113 EXPECT_EQ(input_2->GetDataSize(), output_2->GetDataSize()); 113 EXPECT_EQ(input_2->data_size(), output_2->data_size());
114 } 114 }
115 115
116 TEST_F(AudioSplicerTest, EndOfStream) { 116 TEST_F(AudioSplicerTest, EndOfStream) {
117 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); 117 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1);
118 scoped_refptr<DataBuffer> input_2 = DataBuffer::CreateEOSBuffer(); 118 scoped_refptr<DataBuffer> input_2 = DataBuffer::CreateEOSBuffer();
119 scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(2); 119 scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(2);
120 EXPECT_TRUE(input_2->IsEndOfStream()); 120 EXPECT_TRUE(input_2->end_of_stream());
121 121
122 EXPECT_TRUE(splicer_.AddInput(input_1)); 122 EXPECT_TRUE(splicer_.AddInput(input_1));
123 EXPECT_TRUE(splicer_.AddInput(input_2)); 123 EXPECT_TRUE(splicer_.AddInput(input_2));
124 EXPECT_TRUE(splicer_.HasNextBuffer()); 124 EXPECT_TRUE(splicer_.HasNextBuffer());
125 125
126 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); 126 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer();
127 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); 127 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer();
128 EXPECT_FALSE(splicer_.HasNextBuffer()); 128 EXPECT_FALSE(splicer_.HasNextBuffer());
129 EXPECT_EQ(input_1->GetTimestamp(), output_1->GetTimestamp()); 129 EXPECT_EQ(input_1->timestamp(), output_1->timestamp());
130 EXPECT_EQ(input_1->GetDuration(), output_1->GetDuration()); 130 EXPECT_EQ(input_1->duration(), output_1->duration());
131 EXPECT_EQ(input_1->GetDataSize(), output_1->GetDataSize()); 131 EXPECT_EQ(input_1->data_size(), output_1->data_size());
132 132
133 EXPECT_TRUE(output_2->IsEndOfStream()); 133 EXPECT_TRUE(output_2->end_of_stream());
134 134
135 // Verify that buffers can be added again after Reset(). 135 // Verify that buffers can be added again after Reset().
136 splicer_.Reset(); 136 splicer_.Reset();
137 EXPECT_TRUE(splicer_.AddInput(input_3)); 137 EXPECT_TRUE(splicer_.AddInput(input_3));
138 scoped_refptr<DataBuffer> output_3 = splicer_.GetNextBuffer(); 138 scoped_refptr<DataBuffer> output_3 = splicer_.GetNextBuffer();
139 EXPECT_FALSE(splicer_.HasNextBuffer()); 139 EXPECT_FALSE(splicer_.HasNextBuffer());
140 EXPECT_EQ(input_3->GetTimestamp(), output_3->GetTimestamp()); 140 EXPECT_EQ(input_3->timestamp(), output_3->timestamp());
141 EXPECT_EQ(input_3->GetDuration(), output_3->GetDuration()); 141 EXPECT_EQ(input_3->duration(), output_3->duration());
142 EXPECT_EQ(input_3->GetDataSize(), output_3->GetDataSize()); 142 EXPECT_EQ(input_3->data_size(), output_3->data_size());
143 } 143 }
144 144
145 145
146 // Test the gap insertion code. 146 // Test the gap insertion code.
147 // +--------------+ +--------------+ 147 // +--------------+ +--------------+
148 // |11111111111111| |22222222222222| 148 // |11111111111111| |22222222222222|
149 // +--------------+ +--------------+ 149 // +--------------+ +--------------+
150 // Results in: 150 // Results in:
151 // +--------------+----+--------------+ 151 // +--------------+----+--------------+
152 // |11111111111111|0000|22222222222222| 152 // |11111111111111|0000|22222222222222|
(...skipping 12 matching lines...) Expand all
165 EXPECT_TRUE(splicer_.AddInput(input_2)); 165 EXPECT_TRUE(splicer_.AddInput(input_2));
166 166
167 // Verify that a gap buffer is generated. 167 // Verify that a gap buffer is generated.
168 EXPECT_TRUE(splicer_.HasNextBuffer()); 168 EXPECT_TRUE(splicer_.HasNextBuffer());
169 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); 169 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer();
170 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); 170 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer();
171 scoped_refptr<DataBuffer> output_3 = splicer_.GetNextBuffer(); 171 scoped_refptr<DataBuffer> output_3 = splicer_.GetNextBuffer();
172 EXPECT_FALSE(splicer_.HasNextBuffer()); 172 EXPECT_FALSE(splicer_.HasNextBuffer());
173 173
174 // Verify that the first input buffer passed through unmodified. 174 // Verify that the first input buffer passed through unmodified.
175 EXPECT_EQ(input_1->GetTimestamp(), output_1->GetTimestamp()); 175 EXPECT_EQ(input_1->timestamp(), output_1->timestamp());
176 EXPECT_EQ(input_1->GetDuration(), output_1->GetDuration()); 176 EXPECT_EQ(input_1->duration(), output_1->duration());
177 EXPECT_EQ(input_1->GetDataSize(), output_1->GetDataSize()); 177 EXPECT_EQ(input_1->data_size(), output_1->data_size());
178 EXPECT_TRUE(VerifyData(output_1->GetData(), output_1->GetDataSize(), 1)); 178 EXPECT_TRUE(VerifyData(output_1->data(), output_1->data_size(), 1));
179 179
180 // Verify the contents of the gap buffer. 180 // Verify the contents of the gap buffer.
181 base::TimeDelta gap_timestamp = 181 base::TimeDelta gap_timestamp =
182 input_1->GetTimestamp() + input_1->GetDuration(); 182 input_1->timestamp() + input_1->duration();
183 base::TimeDelta gap_duration = input_2->GetTimestamp() - gap_timestamp; 183 base::TimeDelta gap_duration = input_2->timestamp() - gap_timestamp;
184 EXPECT_GT(gap_duration, base::TimeDelta()); 184 EXPECT_GT(gap_duration, base::TimeDelta());
185 EXPECT_EQ(gap_timestamp, output_2->GetTimestamp()); 185 EXPECT_EQ(gap_timestamp, output_2->timestamp());
186 EXPECT_EQ(gap_duration, output_2->GetDuration()); 186 EXPECT_EQ(gap_duration, output_2->duration());
187 EXPECT_EQ(kGapSize, output_2->GetDataSize()); 187 EXPECT_EQ(kGapSize, output_2->data_size());
188 EXPECT_TRUE(VerifyData(output_2->GetData(), output_2->GetDataSize(), 0)); 188 EXPECT_TRUE(VerifyData(output_2->data(), output_2->data_size(), 0));
189 189
190 // Verify that the second input buffer passed through unmodified. 190 // Verify that the second input buffer passed through unmodified.
191 EXPECT_EQ(input_2->GetTimestamp(), output_3->GetTimestamp()); 191 EXPECT_EQ(input_2->timestamp(), output_3->timestamp());
192 EXPECT_EQ(input_2->GetDuration(), output_3->GetDuration()); 192 EXPECT_EQ(input_2->duration(), output_3->duration());
193 EXPECT_EQ(input_2->GetDataSize(), output_3->GetDataSize()); 193 EXPECT_EQ(input_2->data_size(), output_3->data_size());
194 EXPECT_TRUE(VerifyData(output_3->GetData(), output_3->GetDataSize(), 2)); 194 EXPECT_TRUE(VerifyData(output_3->data(), output_3->data_size(), 2));
195 } 195 }
196 196
197 197
198 // Test that an error is signalled when the gap between input buffers is 198 // Test that an error is signalled when the gap between input buffers is
199 // too large. 199 // too large.
200 TEST_F(AudioSplicerTest, GapTooLarge) { 200 TEST_F(AudioSplicerTest, GapTooLarge) {
201 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); 201 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1);
202 202
203 // Add a seconds worth of bytes so that an unacceptably large 203 // Add a seconds worth of bytes so that an unacceptably large
204 // gap exists between |input_1| and |input_2|. 204 // gap exists between |input_1| and |input_2|.
205 const int kGapSize = kDefaultSampleRate * kBytesPerFrame; 205 const int kGapSize = kDefaultSampleRate * kBytesPerFrame;
206 input_timestamp_helper_.AddBytes(kGapSize); 206 input_timestamp_helper_.AddBytes(kGapSize);
207 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2); 207 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2);
208 208
209 EXPECT_TRUE(splicer_.AddInput(input_1)); 209 EXPECT_TRUE(splicer_.AddInput(input_1));
210 EXPECT_FALSE(splicer_.AddInput(input_2)); 210 EXPECT_FALSE(splicer_.AddInput(input_2));
211 211
212 EXPECT_TRUE(splicer_.HasNextBuffer()); 212 EXPECT_TRUE(splicer_.HasNextBuffer());
213 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); 213 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer();
214 214
215 // Verify that the first input buffer passed through unmodified. 215 // Verify that the first input buffer passed through unmodified.
216 EXPECT_EQ(input_1->GetTimestamp(), output_1->GetTimestamp()); 216 EXPECT_EQ(input_1->timestamp(), output_1->timestamp());
217 EXPECT_EQ(input_1->GetDuration(), output_1->GetDuration()); 217 EXPECT_EQ(input_1->duration(), output_1->duration());
218 EXPECT_EQ(input_1->GetDataSize(), output_1->GetDataSize()); 218 EXPECT_EQ(input_1->data_size(), output_1->data_size());
219 EXPECT_TRUE(VerifyData(output_1->GetData(), output_1->GetDataSize(), 1)); 219 EXPECT_TRUE(VerifyData(output_1->data(), output_1->data_size(), 1));
220 220
221 // Verify that the second buffer is not available. 221 // Verify that the second buffer is not available.
222 EXPECT_FALSE(splicer_.HasNextBuffer()); 222 EXPECT_FALSE(splicer_.HasNextBuffer());
223 223
224 // Reset the timestamp helper so it can generate a buffer that is 224 // Reset the timestamp helper so it can generate a buffer that is
225 // right after |input_1|. 225 // right after |input_1|.
226 input_timestamp_helper_.SetBaseTimestamp( 226 input_timestamp_helper_.SetBaseTimestamp(
227 input_1->GetTimestamp() + input_1->GetDuration()); 227 input_1->timestamp() + input_1->duration());
228 228
229 // Verify that valid buffers are still accepted. 229 // Verify that valid buffers are still accepted.
230 scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(3); 230 scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(3);
231 EXPECT_TRUE(splicer_.AddInput(input_3)); 231 EXPECT_TRUE(splicer_.AddInput(input_3));
232 EXPECT_TRUE(splicer_.HasNextBuffer()); 232 EXPECT_TRUE(splicer_.HasNextBuffer());
233 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); 233 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer();
234 EXPECT_FALSE(splicer_.HasNextBuffer()); 234 EXPECT_FALSE(splicer_.HasNextBuffer());
235 EXPECT_EQ(input_3->GetTimestamp(), output_2->GetTimestamp()); 235 EXPECT_EQ(input_3->timestamp(), output_2->timestamp());
236 EXPECT_EQ(input_3->GetDuration(), output_2->GetDuration()); 236 EXPECT_EQ(input_3->duration(), output_2->duration());
237 EXPECT_EQ(input_3->GetDataSize(), output_2->GetDataSize()); 237 EXPECT_EQ(input_3->data_size(), output_2->data_size());
238 EXPECT_TRUE(VerifyData(output_2->GetData(), output_2->GetDataSize(), 3)); 238 EXPECT_TRUE(VerifyData(output_2->data(), output_2->data_size(), 3));
239 } 239 }
240 240
241 241
242 // Verifies that an error is signalled if AddInput() is called 242 // Verifies that an error is signalled if AddInput() is called
243 // with a timestamp that is earlier than the first buffer added. 243 // with a timestamp that is earlier than the first buffer added.
244 TEST_F(AudioSplicerTest, BufferAddedBeforeBase) { 244 TEST_F(AudioSplicerTest, BufferAddedBeforeBase) {
245 input_timestamp_helper_.SetBaseTimestamp( 245 input_timestamp_helper_.SetBaseTimestamp(
246 base::TimeDelta::FromMicroseconds(10)); 246 base::TimeDelta::FromMicroseconds(10));
247 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); 247 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1);
248 248
249 // Reset the timestamp helper so the next buffer will have a timestamp earlier 249 // Reset the timestamp helper so the next buffer will have a timestamp earlier
250 // than |input_1|. 250 // than |input_1|.
251 input_timestamp_helper_.SetBaseTimestamp(base::TimeDelta::FromSeconds(0)); 251 input_timestamp_helper_.SetBaseTimestamp(base::TimeDelta::FromSeconds(0));
252 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(1); 252 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(1);
253 253
254 EXPECT_GT(input_1->GetTimestamp(), input_2->GetTimestamp()); 254 EXPECT_GT(input_1->timestamp(), input_2->timestamp());
255 EXPECT_TRUE(splicer_.AddInput(input_1)); 255 EXPECT_TRUE(splicer_.AddInput(input_1));
256 EXPECT_FALSE(splicer_.AddInput(input_2)); 256 EXPECT_FALSE(splicer_.AddInput(input_2));
257 } 257 }
258 258
259 259
260 // Test when one buffer partially overlaps another. 260 // Test when one buffer partially overlaps another.
261 // +--------------+ 261 // +--------------+
262 // |11111111111111| 262 // |11111111111111|
263 // +--------------+ 263 // +--------------+
264 // +--------------+ 264 // +--------------+
265 // |22222222222222| 265 // |22222222222222|
266 // +--------------+ 266 // +--------------+
267 // Results in: 267 // Results in:
268 // +--------------+----------+ 268 // +--------------+----------+
269 // |11111111111111|2222222222| 269 // |11111111111111|2222222222|
270 // +--------------+----------+ 270 // +--------------+----------+
271 TEST_F(AudioSplicerTest, PartialOverlap) { 271 TEST_F(AudioSplicerTest, PartialOverlap) {
272 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); 272 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1);
273 273
274 // Reset timestamp helper so that the next buffer will have a 274 // Reset timestamp helper so that the next buffer will have a
275 // timestamp that starts in the middle of |input_1|. 275 // timestamp that starts in the middle of |input_1|.
276 const int kOverlapSize = input_1->GetDataSize() / 4; 276 const int kOverlapSize = input_1->data_size() / 4;
277 input_timestamp_helper_.SetBaseTimestamp(input_1->GetTimestamp()); 277 input_timestamp_helper_.SetBaseTimestamp(input_1->timestamp());
278 input_timestamp_helper_.AddBytes(input_1->GetDataSize() - kOverlapSize); 278 input_timestamp_helper_.AddBytes(input_1->data_size() - kOverlapSize);
279 279
280 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2); 280 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2);
281 281
282 EXPECT_TRUE(splicer_.AddInput(input_1)); 282 EXPECT_TRUE(splicer_.AddInput(input_1));
283 EXPECT_TRUE(splicer_.AddInput(input_2)); 283 EXPECT_TRUE(splicer_.AddInput(input_2));
284 284
285 EXPECT_TRUE(splicer_.HasNextBuffer()); 285 EXPECT_TRUE(splicer_.HasNextBuffer());
286 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); 286 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer();
287 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); 287 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer();
288 EXPECT_FALSE(splicer_.HasNextBuffer()); 288 EXPECT_FALSE(splicer_.HasNextBuffer());
289 289
290 // Verify that the first input buffer passed through unmodified. 290 // Verify that the first input buffer passed through unmodified.
291 EXPECT_EQ(input_1->GetTimestamp(), output_1->GetTimestamp()); 291 EXPECT_EQ(input_1->timestamp(), output_1->timestamp());
292 EXPECT_EQ(input_1->GetDuration(), output_1->GetDuration()); 292 EXPECT_EQ(input_1->duration(), output_1->duration());
293 EXPECT_EQ(input_1->GetDataSize(), output_1->GetDataSize()); 293 EXPECT_EQ(input_1->data_size(), output_1->data_size());
294 EXPECT_TRUE(VerifyData(output_1->GetData(), output_1->GetDataSize(), 1)); 294 EXPECT_TRUE(VerifyData(output_1->data(), output_1->data_size(), 1));
295 295
296 296
297 // Verify that the second input buffer was truncated to only contain 297 // Verify that the second input buffer was truncated to only contain
298 // the samples that are after the end of |input_1|. 298 // the samples that are after the end of |input_1|.
299 base::TimeDelta expected_timestamp = 299 base::TimeDelta expected_timestamp =
300 input_1->GetTimestamp() + input_1->GetDuration(); 300 input_1->timestamp() + input_1->duration();
301 base::TimeDelta expected_duration = 301 base::TimeDelta expected_duration =
302 (input_2->GetTimestamp() + input_2->GetDuration()) - expected_timestamp; 302 (input_2->timestamp() + input_2->duration()) - expected_timestamp;
303 EXPECT_EQ(expected_timestamp, output_2->GetTimestamp()); 303 EXPECT_EQ(expected_timestamp, output_2->timestamp());
304 EXPECT_EQ(expected_duration, output_2->GetDuration()); 304 EXPECT_EQ(expected_duration, output_2->duration());
305 EXPECT_EQ(input_2->GetDataSize() - kOverlapSize, output_2->GetDataSize()); 305 EXPECT_EQ(input_2->data_size() - kOverlapSize, output_2->data_size());
306 EXPECT_TRUE(VerifyData(output_2->GetData(), output_2->GetDataSize(), 2)); 306 EXPECT_TRUE(VerifyData(output_2->data(), output_2->data_size(), 2));
307 } 307 }
308 308
309 309
310 // Test that an input buffer that is completely overlapped by a buffer 310 // Test that an input buffer that is completely overlapped by a buffer
311 // that was already added is dropped. 311 // that was already added is dropped.
312 // +--------------+ 312 // +--------------+
313 // |11111111111111| 313 // |11111111111111|
314 // +--------------+ 314 // +--------------+
315 // +-----+ 315 // +-----+
316 // |22222| 316 // |22222|
317 // +-----+ 317 // +-----+
318 // +-------------+ 318 // +-------------+
319 // |3333333333333| 319 // |3333333333333|
320 // +-------------+ 320 // +-------------+
321 // Results in: 321 // Results in:
322 // +--------------+-------------+ 322 // +--------------+-------------+
323 // |11111111111111|3333333333333| 323 // |11111111111111|3333333333333|
324 // +--------------+-------------+ 324 // +--------------+-------------+
325 TEST_F(AudioSplicerTest, DropBuffer) { 325 TEST_F(AudioSplicerTest, DropBuffer) {
326 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); 326 scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1);
327 327
328 // Reset timestamp helper so that the next buffer will have a 328 // Reset timestamp helper so that the next buffer will have a
329 // timestamp that starts in the middle of |input_1|. 329 // timestamp that starts in the middle of |input_1|.
330 const int kOverlapOffset = input_1->GetDataSize() / 2; 330 const int kOverlapOffset = input_1->data_size() / 2;
331 const int kOverlapSize = input_1->GetDataSize() / 4; 331 const int kOverlapSize = input_1->data_size() / 4;
332 input_timestamp_helper_.SetBaseTimestamp(input_1->GetTimestamp()); 332 input_timestamp_helper_.SetBaseTimestamp(input_1->timestamp());
333 input_timestamp_helper_.AddBytes(kOverlapOffset); 333 input_timestamp_helper_.AddBytes(kOverlapOffset);
334 334
335 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2, kOverlapSize); 335 scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2, kOverlapSize);
336 336
337 // Reset the timestamp helper so the next buffer will be right after 337 // Reset the timestamp helper so the next buffer will be right after
338 // |input_1|. 338 // |input_1|.
339 input_timestamp_helper_.SetBaseTimestamp(input_1->GetTimestamp()); 339 input_timestamp_helper_.SetBaseTimestamp(input_1->timestamp());
340 input_timestamp_helper_.AddBytes(input_1->GetDataSize()); 340 input_timestamp_helper_.AddBytes(input_1->data_size());
341 scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(3); 341 scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(3);
342 342
343 EXPECT_TRUE(splicer_.AddInput(input_1)); 343 EXPECT_TRUE(splicer_.AddInput(input_1));
344 EXPECT_TRUE(splicer_.AddInput(input_2)); 344 EXPECT_TRUE(splicer_.AddInput(input_2));
345 EXPECT_TRUE(splicer_.AddInput(input_3)); 345 EXPECT_TRUE(splicer_.AddInput(input_3));
346 346
347 EXPECT_TRUE(splicer_.HasNextBuffer()); 347 EXPECT_TRUE(splicer_.HasNextBuffer());
348 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); 348 scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer();
349 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); 349 scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer();
350 EXPECT_FALSE(splicer_.HasNextBuffer()); 350 EXPECT_FALSE(splicer_.HasNextBuffer());
351 351
352 // Verify that the first input buffer passed through unmodified. 352 // Verify that the first input buffer passed through unmodified.
353 EXPECT_EQ(input_1->GetTimestamp(), output_1->GetTimestamp()); 353 EXPECT_EQ(input_1->timestamp(), output_1->timestamp());
354 EXPECT_EQ(input_1->GetDuration(), output_1->GetDuration()); 354 EXPECT_EQ(input_1->duration(), output_1->duration());
355 EXPECT_EQ(input_1->GetDataSize(), output_1->GetDataSize()); 355 EXPECT_EQ(input_1->data_size(), output_1->data_size());
356 EXPECT_TRUE(VerifyData(output_1->GetData(), output_1->GetDataSize(), 1)); 356 EXPECT_TRUE(VerifyData(output_1->data(), output_1->data_size(), 1));
357 357
358 // Verify that the second output buffer only contains 358 // Verify that the second output buffer only contains
359 // the samples that are in |input_3|. 359 // the samples that are in |input_3|.
360 EXPECT_EQ(input_3->GetTimestamp(), output_2->GetTimestamp()); 360 EXPECT_EQ(input_3->timestamp(), output_2->timestamp());
361 EXPECT_EQ(input_3->GetDuration(), output_2->GetDuration()); 361 EXPECT_EQ(input_3->duration(), output_2->duration());
362 EXPECT_EQ(input_3->GetDataSize(), output_2->GetDataSize()); 362 EXPECT_EQ(input_3->data_size(), output_2->data_size());
363 EXPECT_TRUE(VerifyData(output_2->GetData(), output_2->GetDataSize(), 3)); 363 EXPECT_TRUE(VerifyData(output_2->data(), output_2->data_size(), 3));
364 } 364 }
365 365
366 } // namespace media 366 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_splicer.cc ('k') | media/base/data_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698