OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "media/base/data_buffer.h" |
8 #include "media/base/seekable_buffer.h" | 9 #include "media/base/seekable_buffer.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 class SeekableBufferTest : public testing::Test { | 14 class SeekableBufferTest : public testing::Test { |
14 public: | 15 public: |
15 SeekableBufferTest() : buffer_(kBufferSize, kBufferSize) { | 16 SeekableBufferTest() : buffer_(kBufferSize, kBufferSize) { |
16 } | 17 } |
17 | 18 |
(...skipping 22 matching lines...) Expand all Loading... |
40 uint8 write_buffer_[kDataSize]; | 41 uint8 write_buffer_[kDataSize]; |
41 }; | 42 }; |
42 | 43 |
43 TEST_F(SeekableBufferTest, RandomReadWrite) { | 44 TEST_F(SeekableBufferTest, RandomReadWrite) { |
44 size_t write_position = 0; | 45 size_t write_position = 0; |
45 size_t read_position = 0; | 46 size_t read_position = 0; |
46 while (read_position < kDataSize) { | 47 while (read_position < kDataSize) { |
47 // Write a random amount of data. | 48 // Write a random amount of data. |
48 size_t write_size = GetRandomInt(kBufferSize); | 49 size_t write_size = GetRandomInt(kBufferSize); |
49 write_size = std::min(write_size, kDataSize - write_position); | 50 write_size = std::min(write_size, kDataSize - write_position); |
50 bool should_append = buffer_.Append(write_size, data_ + write_position); | 51 bool should_append = buffer_.Append(data_ + write_position, write_size); |
51 write_position += write_size; | 52 write_position += write_size; |
52 EXPECT_GE(write_position, read_position); | 53 EXPECT_GE(write_position, read_position); |
53 EXPECT_EQ(write_position - read_position, buffer_.forward_bytes()); | 54 EXPECT_EQ(write_position - read_position, buffer_.forward_bytes()); |
54 EXPECT_EQ(should_append, buffer_.forward_bytes() < kBufferSize) | 55 EXPECT_EQ(should_append, buffer_.forward_bytes() < kBufferSize) |
55 << "Incorrect buffer full reported"; | 56 << "Incorrect buffer full reported"; |
56 | 57 |
| 58 // Peek a random amount of data. |
| 59 size_t copy_size = GetRandomInt(kBufferSize); |
| 60 size_t bytes_copied = buffer_.Peek(write_buffer_, copy_size); |
| 61 EXPECT_GE(copy_size, bytes_copied); |
| 62 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, bytes_copied)); |
| 63 |
57 // Read a random amount of data. | 64 // Read a random amount of data. |
58 size_t read_size = GetRandomInt(kBufferSize); | 65 size_t read_size = GetRandomInt(kBufferSize); |
59 size_t bytes_read = buffer_.Read(read_size, write_buffer_); | 66 size_t bytes_read = buffer_.Read(write_buffer_, read_size); |
60 EXPECT_GE(read_size, bytes_read); | 67 EXPECT_GE(read_size, bytes_read); |
61 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, bytes_read)); | 68 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, bytes_read)); |
62 read_position += bytes_read; | 69 read_position += bytes_read; |
63 EXPECT_GE(write_position, read_position); | 70 EXPECT_GE(write_position, read_position); |
64 EXPECT_EQ(write_position - read_position, buffer_.forward_bytes()); | 71 EXPECT_EQ(write_position - read_position, buffer_.forward_bytes()); |
65 } | 72 } |
66 } | 73 } |
67 | 74 |
68 TEST_F(SeekableBufferTest, ReadWriteSeek) { | 75 TEST_F(SeekableBufferTest, ReadWriteSeek) { |
69 const size_t kReadSize = kWriteSize / 4; | 76 const size_t kReadSize = kWriteSize / 4; |
70 | 77 |
71 for (int i = 0; i < 10; ++i) { | 78 for (int i = 0; i < 10; ++i) { |
72 // Write until buffer is full. | 79 // Write until buffer is full. |
73 for (size_t j = 0; j < kBufferSize; j += kWriteSize) { | 80 for (size_t j = 0; j < kBufferSize; j += kWriteSize) { |
74 bool should_append = buffer_.Append(kWriteSize, data_ + j); | 81 bool should_append = buffer_.Append(data_ + j, kWriteSize); |
75 EXPECT_EQ(j < kBufferSize - kWriteSize, should_append) | 82 EXPECT_EQ(j < kBufferSize - kWriteSize, should_append) |
76 << "Incorrect buffer full reported"; | 83 << "Incorrect buffer full reported"; |
77 EXPECT_EQ(j + kWriteSize, buffer_.forward_bytes()); | 84 EXPECT_EQ(j + kWriteSize, buffer_.forward_bytes()); |
78 } | 85 } |
79 | 86 |
80 // Simulate a read and seek pattern. Each loop reads 4 times, each time | 87 // Simulate a read and seek pattern. Each loop reads 4 times, each time |
81 // reading a quarter of |kWriteSize|. | 88 // reading a quarter of |kWriteSize|. |
82 size_t read_position = 0; | 89 size_t read_position = 0; |
83 size_t forward_bytes = kBufferSize; | 90 size_t forward_bytes = kBufferSize; |
84 for (size_t j = 0; j < kBufferSize; j += kWriteSize) { | 91 for (size_t j = 0; j < kBufferSize; j += kWriteSize) { |
85 // Read. | 92 // Read. |
86 EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_)); | 93 EXPECT_EQ(kReadSize, buffer_.Read(write_buffer_, kReadSize)); |
87 forward_bytes -= kReadSize; | 94 forward_bytes -= kReadSize; |
88 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); | 95 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); |
89 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); | 96 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); |
90 read_position += kReadSize; | 97 read_position += kReadSize; |
91 | 98 |
92 // Seek forward. | 99 // Seek forward. |
93 EXPECT_TRUE(buffer_.Seek(2 * kReadSize)); | 100 EXPECT_TRUE(buffer_.Seek(2 * kReadSize)); |
94 forward_bytes -= 2 * kReadSize; | 101 forward_bytes -= 2 * kReadSize; |
95 read_position += 2 * kReadSize; | 102 read_position += 2 * kReadSize; |
96 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); | 103 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); |
97 | 104 |
| 105 // Copy. |
| 106 EXPECT_EQ(kReadSize, buffer_.Peek(write_buffer_, kReadSize)); |
| 107 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); |
| 108 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); |
| 109 |
98 // Read. | 110 // Read. |
99 EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_)); | 111 EXPECT_EQ(kReadSize, buffer_.Read(write_buffer_, kReadSize)); |
100 forward_bytes -= kReadSize; | 112 forward_bytes -= kReadSize; |
101 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); | 113 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); |
102 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); | 114 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); |
103 read_position += kReadSize; | 115 read_position += kReadSize; |
104 | 116 |
105 // Seek backward. | 117 // Seek backward. |
106 EXPECT_TRUE(buffer_.Seek(-3 * static_cast<int32>(kReadSize))); | 118 EXPECT_TRUE(buffer_.Seek(-3 * static_cast<int32>(kReadSize))); |
107 forward_bytes += 3 * kReadSize; | 119 forward_bytes += 3 * kReadSize; |
108 read_position -= 3 * kReadSize; | 120 read_position -= 3 * kReadSize; |
109 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); | 121 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); |
110 | 122 |
| 123 // Copy. |
| 124 EXPECT_EQ(kReadSize, buffer_.Peek(write_buffer_, kReadSize)); |
| 125 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); |
| 126 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); |
| 127 |
111 // Read. | 128 // Read. |
112 EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_)); | 129 EXPECT_EQ(kReadSize, buffer_.Read(write_buffer_, kReadSize)); |
113 forward_bytes -= kReadSize; | 130 forward_bytes -= kReadSize; |
114 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); | 131 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); |
115 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); | 132 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); |
116 read_position += kReadSize; | 133 read_position += kReadSize; |
117 | 134 |
| 135 // Copy. |
| 136 EXPECT_EQ(kReadSize, buffer_.Peek(write_buffer_, kReadSize)); |
| 137 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); |
| 138 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); |
| 139 |
118 // Read. | 140 // Read. |
119 EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_)); | 141 EXPECT_EQ(kReadSize, buffer_.Read(write_buffer_, kReadSize)); |
120 forward_bytes -= kReadSize; | 142 forward_bytes -= kReadSize; |
121 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); | 143 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); |
122 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); | 144 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize)); |
123 read_position += kReadSize; | 145 read_position += kReadSize; |
124 | 146 |
125 // Seek forward. | 147 // Seek forward. |
126 EXPECT_TRUE(buffer_.Seek(kReadSize)); | 148 EXPECT_TRUE(buffer_.Seek(kReadSize)); |
127 forward_bytes -= kReadSize; | 149 forward_bytes -= kReadSize; |
128 read_position += kReadSize; | 150 read_position += kReadSize; |
129 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); | 151 EXPECT_EQ(forward_bytes, buffer_.forward_bytes()); |
130 } | 152 } |
131 } | 153 } |
132 } | 154 } |
133 | 155 |
134 TEST_F(SeekableBufferTest, BufferFull) { | 156 TEST_F(SeekableBufferTest, BufferFull) { |
135 const size_t kMaxWriteSize = 2 * kBufferSize; | 157 const size_t kMaxWriteSize = 2 * kBufferSize; |
136 | 158 |
137 // Write and expect the buffer to be not full. | 159 // Write and expect the buffer to be not full. |
138 for (size_t i = 0; i < kBufferSize - kWriteSize; i += kWriteSize) { | 160 for (size_t i = 0; i < kBufferSize - kWriteSize; i += kWriteSize) { |
139 EXPECT_TRUE(buffer_.Append(kWriteSize, data_ + i)); | 161 EXPECT_TRUE(buffer_.Append(data_ + i, kWriteSize)); |
140 EXPECT_EQ(i + kWriteSize, buffer_.forward_bytes()); | 162 EXPECT_EQ(i + kWriteSize, buffer_.forward_bytes()); |
141 } | 163 } |
142 | 164 |
143 // Write until we have kMaxWriteSize bytes in the buffer. Buffer is full in | 165 // Write until we have kMaxWriteSize bytes in the buffer. Buffer is full in |
144 // these writes. | 166 // these writes. |
145 for (size_t i = buffer_.forward_bytes(); i < kMaxWriteSize; i += kWriteSize) { | 167 for (size_t i = buffer_.forward_bytes(); i < kMaxWriteSize; i += kWriteSize) { |
146 EXPECT_FALSE(buffer_.Append(kWriteSize, data_ + i)); | 168 EXPECT_FALSE(buffer_.Append(data_ + i, kWriteSize)); |
147 EXPECT_EQ(i + kWriteSize, buffer_.forward_bytes()); | 169 EXPECT_EQ(i + kWriteSize, buffer_.forward_bytes()); |
148 } | 170 } |
149 | 171 |
150 // Read until the buffer is empty. | 172 // Read until the buffer is empty. |
151 size_t read_position = 0; | 173 size_t read_position = 0; |
152 while (buffer_.forward_bytes()) { | 174 while (buffer_.forward_bytes()) { |
153 // Read a random amount of data. | 175 // Read a random amount of data. |
154 size_t read_size = GetRandomInt(kBufferSize); | 176 size_t read_size = GetRandomInt(kBufferSize); |
155 size_t forward_bytes = buffer_.forward_bytes(); | 177 size_t forward_bytes = buffer_.forward_bytes(); |
156 size_t bytes_read = buffer_.Read(read_size, write_buffer_); | 178 size_t bytes_read = buffer_.Read(write_buffer_, read_size); |
157 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, bytes_read)); | 179 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, bytes_read)); |
158 if (read_size > forward_bytes) | 180 if (read_size > forward_bytes) |
159 EXPECT_EQ(forward_bytes, bytes_read); | 181 EXPECT_EQ(forward_bytes, bytes_read); |
160 else | 182 else |
161 EXPECT_EQ(read_size, bytes_read); | 183 EXPECT_EQ(read_size, bytes_read); |
162 read_position += bytes_read; | 184 read_position += bytes_read; |
163 EXPECT_GE(kMaxWriteSize, read_position); | 185 EXPECT_GE(kMaxWriteSize, read_position); |
164 EXPECT_EQ(kMaxWriteSize - read_position, buffer_.forward_bytes()); | 186 EXPECT_EQ(kMaxWriteSize - read_position, buffer_.forward_bytes()); |
165 } | 187 } |
166 | 188 |
167 // Expects we have no bytes left. | 189 // Expects we have no bytes left. |
168 EXPECT_EQ(0u, buffer_.forward_bytes()); | 190 EXPECT_EQ(0u, buffer_.forward_bytes()); |
169 EXPECT_EQ(0u, buffer_.Read(1, write_buffer_)); | 191 EXPECT_EQ(0u, buffer_.Read(write_buffer_, 1)); |
170 } | 192 } |
171 | 193 |
172 TEST_F(SeekableBufferTest, SeekBackward) { | 194 TEST_F(SeekableBufferTest, SeekBackward) { |
173 EXPECT_EQ(0u, buffer_.forward_bytes()); | 195 EXPECT_EQ(0u, buffer_.forward_bytes()); |
174 EXPECT_EQ(0u, buffer_.backward_bytes()); | 196 EXPECT_EQ(0u, buffer_.backward_bytes()); |
175 EXPECT_FALSE(buffer_.Seek(1)); | 197 EXPECT_FALSE(buffer_.Seek(1)); |
176 EXPECT_FALSE(buffer_.Seek(-1)); | 198 EXPECT_FALSE(buffer_.Seek(-1)); |
177 | 199 |
178 const size_t kReadSize = 256; | 200 const size_t kReadSize = 256; |
179 | 201 |
180 // Write into buffer until it's full. | 202 // Write into buffer until it's full. |
181 for (size_t i = 0; i < kBufferSize; i += kWriteSize) { | 203 for (size_t i = 0; i < kBufferSize; i += kWriteSize) { |
182 // Write a random amount of data. | 204 // Write a random amount of data. |
183 buffer_.Append(kWriteSize, data_ + i); | 205 buffer_.Append(data_ + i, kWriteSize); |
184 } | 206 } |
185 | 207 |
186 // Read until buffer is empty. | 208 // Read until buffer is empty. |
187 for (size_t i = 0; i < kBufferSize; i += kReadSize) { | 209 for (size_t i = 0; i < kBufferSize; i += kReadSize) { |
188 EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_)); | 210 EXPECT_EQ(kReadSize, buffer_.Read(write_buffer_, kReadSize)); |
189 EXPECT_EQ(0, memcmp(write_buffer_, data_ + i, kReadSize)); | 211 EXPECT_EQ(0, memcmp(write_buffer_, data_ + i, kReadSize)); |
190 } | 212 } |
191 | 213 |
192 // Seek backward. | 214 // Seek backward. |
193 EXPECT_TRUE(buffer_.Seek(-static_cast<int32>(kBufferSize))); | 215 EXPECT_TRUE(buffer_.Seek(-static_cast<int32>(kBufferSize))); |
194 EXPECT_FALSE(buffer_.Seek(-1)); | 216 EXPECT_FALSE(buffer_.Seek(-1)); |
195 | 217 |
196 // Read again. | 218 // Read again. |
197 for (size_t i = 0; i < kBufferSize; i += kReadSize) { | 219 for (size_t i = 0; i < kBufferSize; i += kReadSize) { |
198 EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_)); | 220 EXPECT_EQ(kReadSize, buffer_.Read(write_buffer_, kReadSize)); |
199 EXPECT_EQ(0, memcmp(write_buffer_, data_ + i, kReadSize)); | 221 EXPECT_EQ(0, memcmp(write_buffer_, data_ + i, kReadSize)); |
200 } | 222 } |
201 } | 223 } |
202 | 224 |
203 TEST_F(SeekableBufferTest, SeekForward) { | 225 TEST_F(SeekableBufferTest, SeekForward) { |
204 size_t write_position = 0; | 226 size_t write_position = 0; |
205 size_t read_position = 0; | 227 size_t read_position = 0; |
206 while (read_position < kDataSize) { | 228 while (read_position < kDataSize) { |
207 for (int i = 0; i < 10 && write_position < kDataSize; ++i) { | 229 for (int i = 0; i < 10 && write_position < kDataSize; ++i) { |
208 // Write a random amount of data. | 230 // Write a random amount of data. |
209 size_t write_size = GetRandomInt(kBufferSize); | 231 size_t write_size = GetRandomInt(kBufferSize); |
210 write_size = std::min(write_size, kDataSize - write_position); | 232 write_size = std::min(write_size, kDataSize - write_position); |
211 | 233 |
212 bool should_append = buffer_.Append(write_size, data_ + write_position); | 234 bool should_append = buffer_.Append(data_ + write_position, write_size); |
213 write_position += write_size; | 235 write_position += write_size; |
214 EXPECT_GE(write_position, read_position); | 236 EXPECT_GE(write_position, read_position); |
215 EXPECT_EQ(write_position - read_position, buffer_.forward_bytes()); | 237 EXPECT_EQ(write_position - read_position, buffer_.forward_bytes()); |
216 EXPECT_EQ(should_append, buffer_.forward_bytes() < kBufferSize) | 238 EXPECT_EQ(should_append, buffer_.forward_bytes() < kBufferSize) |
217 << "Incorrect buffer full status reported"; | 239 << "Incorrect buffer full status reported"; |
218 } | 240 } |
219 | 241 |
220 // Read a random amount of data. | 242 // Read a random amount of data. |
221 size_t seek_size = GetRandomInt(kBufferSize); | 243 size_t seek_size = GetRandomInt(kBufferSize); |
222 if (buffer_.Seek(seek_size)) | 244 if (buffer_.Seek(seek_size)) |
223 read_position += seek_size; | 245 read_position += seek_size; |
224 EXPECT_GE(write_position, read_position); | 246 EXPECT_GE(write_position, read_position); |
225 EXPECT_EQ(write_position - read_position, buffer_.forward_bytes()); | 247 EXPECT_EQ(write_position - read_position, buffer_.forward_bytes()); |
226 | 248 |
227 // Read a random amount of data. | 249 // Read a random amount of data. |
228 size_t read_size = GetRandomInt(kBufferSize); | 250 size_t read_size = GetRandomInt(kBufferSize); |
229 size_t bytes_read = buffer_.Read(read_size, write_buffer_); | 251 size_t bytes_read = buffer_.Read(write_buffer_, read_size); |
230 EXPECT_GE(read_size, bytes_read); | 252 EXPECT_GE(read_size, bytes_read); |
231 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, bytes_read)); | 253 EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, bytes_read)); |
232 read_position += bytes_read; | 254 read_position += bytes_read; |
233 EXPECT_GE(write_position, read_position); | 255 EXPECT_GE(write_position, read_position); |
234 EXPECT_EQ(write_position - read_position, buffer_.forward_bytes()); | 256 EXPECT_EQ(write_position - read_position, buffer_.forward_bytes()); |
235 } | 257 } |
236 } | 258 } |
237 | 259 |
238 TEST_F(SeekableBufferTest, AllMethods) { | 260 TEST_F(SeekableBufferTest, AllMethods) { |
239 EXPECT_EQ(0u, buffer_.Read(0, write_buffer_)); | 261 EXPECT_EQ(0u, buffer_.Read(write_buffer_, 0)); |
240 EXPECT_EQ(0u, buffer_.Read(1, write_buffer_)); | 262 EXPECT_EQ(0u, buffer_.Read(write_buffer_, 1)); |
241 EXPECT_TRUE(buffer_.Seek(0)); | 263 EXPECT_TRUE(buffer_.Seek(0)); |
242 EXPECT_FALSE(buffer_.Seek(-1)); | 264 EXPECT_FALSE(buffer_.Seek(-1)); |
243 EXPECT_FALSE(buffer_.Seek(1)); | 265 EXPECT_FALSE(buffer_.Seek(1)); |
244 EXPECT_EQ(0u, buffer_.forward_bytes()); | 266 EXPECT_EQ(0u, buffer_.forward_bytes()); |
245 EXPECT_EQ(0u, buffer_.backward_bytes()); | 267 EXPECT_EQ(0u, buffer_.backward_bytes()); |
246 } | 268 } |
247 | 269 |
| 270 |
| 271 TEST_F(SeekableBufferTest, GetTime) { |
| 272 const struct { |
| 273 int64 first_time_useconds; |
| 274 int64 duration_useconds; |
| 275 size_t consume_bytes; |
| 276 int64 expected_time; |
| 277 } tests[] = { |
| 278 // Timestamps of 0 are treated as garbage. |
| 279 { 0, 1000000, 0, 0 }, |
| 280 { 0, 4000000, 0, 0 }, |
| 281 { 0, 8000000, 0, 0 }, |
| 282 { 0, 1000000, 4, 0 }, |
| 283 { 0, 4000000, 4, 0 }, |
| 284 { 0, 8000000, 4, 0 }, |
| 285 { 0, 1000000, kWriteSize, 0 }, |
| 286 { 0, 4000000, kWriteSize, 0 }, |
| 287 { 0, 8000000, kWriteSize, 0 }, |
| 288 { 5, 1000000, 0, 5 }, |
| 289 { 5, 4000000, 0, 5 }, |
| 290 { 5, 8000000, 0, 5 }, |
| 291 { 5, 1000000, kWriteSize / 2, 500005 }, |
| 292 { 5, 4000000, kWriteSize / 2, 2000005 }, |
| 293 { 5, 8000000, kWriteSize / 2, 4000005 }, |
| 294 { 5, 1000000, kWriteSize, 1000005 }, |
| 295 { 5, 4000000, kWriteSize, 4000005 }, |
| 296 { 5, 8000000, kWriteSize, 8000005 }, |
| 297 }; |
| 298 |
| 299 scoped_refptr<media::DataBuffer> buffer = new media::DataBuffer(kWriteSize); |
| 300 memcpy(buffer->GetWritableData(), data_, kWriteSize); |
| 301 buffer->SetDataSize(kWriteSize); |
| 302 |
| 303 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 304 buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( |
| 305 tests[i].first_time_useconds)); |
| 306 buffer->SetDuration(base::TimeDelta::FromMicroseconds( |
| 307 tests[i].duration_useconds)); |
| 308 buffer_.Append(buffer.get()); |
| 309 EXPECT_TRUE(buffer_.Seek(tests[i].consume_bytes)); |
| 310 |
| 311 int64 actual = buffer_.current_time().ToInternalValue(); |
| 312 |
| 313 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" |
| 314 << tests[i].first_time_useconds << ", duration:" |
| 315 << tests[i].duration_useconds << ", consumed:" |
| 316 << tests[i].consume_bytes << "}\n"; |
| 317 |
| 318 buffer_.Clear(); |
| 319 } |
| 320 } |
| 321 |
248 } // namespace | 322 } // namespace |
OLD | NEW |