Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "media/base/data_buffer.h" | 8 #include "media/base/data_buffer.h" |
| 9 #include "media/base/seekable_buffer.h" | 9 #include "media/base/seekable_buffer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 EXPECT_EQ(0, buffer_.Read(write_buffer_, 1)); | 284 EXPECT_EQ(0, buffer_.Read(write_buffer_, 1)); |
| 285 EXPECT_TRUE(buffer_.Seek(0)); | 285 EXPECT_TRUE(buffer_.Seek(0)); |
| 286 EXPECT_FALSE(buffer_.Seek(-1)); | 286 EXPECT_FALSE(buffer_.Seek(-1)); |
| 287 EXPECT_FALSE(buffer_.Seek(1)); | 287 EXPECT_FALSE(buffer_.Seek(1)); |
| 288 EXPECT_EQ(0, buffer_.forward_bytes()); | 288 EXPECT_EQ(0, buffer_.forward_bytes()); |
| 289 EXPECT_EQ(0, buffer_.backward_bytes()); | 289 EXPECT_EQ(0, buffer_.backward_bytes()); |
| 290 } | 290 } |
| 291 | 291 |
| 292 | 292 |
| 293 TEST_F(SeekableBufferTest, GetTime) { | 293 TEST_F(SeekableBufferTest, GetTime) { |
| 294 const int64 kNoTS = kNoTimestamp().ToInternalValue(); | |
| 294 const struct { | 295 const struct { |
| 295 int64 first_time_useconds; | 296 int64 first_time_useconds; |
| 296 int64 duration_useconds; | 297 int64 duration_useconds; |
| 297 int consume_bytes; | 298 int consume_bytes; |
| 298 int64 expected_time; | 299 int64 expected_time; |
| 299 } tests[] = { | 300 } tests[] = { |
| 300 // Timestamps of 0 are treated as garbage. | 301 { kNoTS, 1000000, 0, kNoTS }, |
| 301 { 0, 1000000, 0, kNoTimestamp().ToInternalValue() }, | 302 { kNoTS, 4000000, 0, kNoTS }, |
| 302 { 0, 4000000, 0, kNoTimestamp().ToInternalValue() }, | 303 { kNoTS, 8000000, 0, kNoTS }, |
| 303 { 0, 8000000, 0, kNoTimestamp().ToInternalValue() }, | 304 { kNoTS, 1000000, kWriteSize / 2, kNoTS }, |
| 304 { 0, 1000000, 4, kNoTimestamp().ToInternalValue() }, | 305 { kNoTS, 4000000, kWriteSize / 2, kNoTS }, |
| 305 { 0, 4000000, 4, kNoTimestamp().ToInternalValue() }, | 306 { kNoTS, 8000000, kWriteSize / 2, kNoTS }, |
| 306 { 0, 8000000, 4, kNoTimestamp().ToInternalValue() }, | 307 { kNoTS, 1000000, kWriteSize, kNoTS }, |
| 307 { 0, 1000000, kWriteSize, kNoTimestamp().ToInternalValue() }, | 308 { kNoTS, 4000000, kWriteSize, kNoTS }, |
| 308 { 0, 4000000, kWriteSize, kNoTimestamp().ToInternalValue() }, | 309 { kNoTS, 8000000, kWriteSize, kNoTS }, |
| 309 { 0, 8000000, kWriteSize, kNoTimestamp().ToInternalValue() }, | 310 { 0, 1000000, 0, 0 }, |
| 311 { 0, 4000000, 0, 0 }, | |
| 312 { 0, 8000000, 0, 0 }, | |
| 313 { 0, 1000000, kWriteSize / 2, 500000 }, | |
| 314 { 0, 4000000, kWriteSize / 2, 2000000 }, | |
| 315 { 0, 8000000, kWriteSize / 2, 4000000 }, | |
| 316 { 0, 1000000, kWriteSize, 1000000 }, | |
| 317 { 0, 4000000, kWriteSize, 4000000 }, | |
| 318 { 0, 8000000, kWriteSize, 8000000 }, | |
| 310 { 5, 1000000, 0, 5 }, | 319 { 5, 1000000, 0, 5 }, |
| 311 { 5, 4000000, 0, 5 }, | 320 { 5, 4000000, 0, 5 }, |
| 312 { 5, 8000000, 0, 5 }, | 321 { 5, 8000000, 0, 5 }, |
| 313 { 5, 1000000, kWriteSize / 2, 500005 }, | 322 { 5, 1000000, kWriteSize / 2, 500005 }, |
| 314 { 5, 4000000, kWriteSize / 2, 2000005 }, | 323 { 5, 4000000, kWriteSize / 2, 2000005 }, |
| 315 { 5, 8000000, kWriteSize / 2, 4000005 }, | 324 { 5, 8000000, kWriteSize / 2, 4000005 }, |
| 316 { 5, 1000000, kWriteSize, 1000005 }, | 325 { 5, 1000000, kWriteSize, 1000005 }, |
| 317 { 5, 4000000, kWriteSize, 4000005 }, | 326 { 5, 4000000, kWriteSize, 4000005 }, |
| 318 { 5, 8000000, kWriteSize, 8000005 }, | 327 { 5, 8000000, kWriteSize, 8000005 }, |
| 319 }; | 328 }; |
| 320 | 329 |
| 321 // current_time() must initially return kNoTimestamp(). | 330 // current_time() must initially return kNoTimestamp(). |
| 322 EXPECT_EQ(kNoTimestamp().ToInternalValue(), | 331 EXPECT_EQ(kNoTimestamp().ToInternalValue(), |
|
vrk (LEFT CHROMIUM)
2012/05/02 22:18:07
nit: change to kNoTS?
| |
| 323 buffer_.current_time().ToInternalValue()); | 332 buffer_.current_time().ToInternalValue()); |
| 324 | 333 |
| 325 scoped_refptr<media::DataBuffer> buffer(new media::DataBuffer(kWriteSize)); | 334 scoped_refptr<media::DataBuffer> buffer(new media::DataBuffer(kWriteSize)); |
| 326 memcpy(buffer->GetWritableData(), data_, kWriteSize); | 335 memcpy(buffer->GetWritableData(), data_, kWriteSize); |
| 327 buffer->SetDataSize(kWriteSize); | 336 buffer->SetDataSize(kWriteSize); |
| 328 | 337 |
| 329 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 338 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 330 buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( | 339 buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( |
| 331 tests[i].first_time_useconds)); | 340 tests[i].first_time_useconds)); |
| 332 buffer->SetDuration(base::TimeDelta::FromMicroseconds( | 341 buffer->SetDuration(base::TimeDelta::FromMicroseconds( |
| 333 tests[i].duration_useconds)); | 342 tests[i].duration_useconds)); |
| 334 buffer_.Append(buffer.get()); | 343 buffer_.Append(buffer.get()); |
| 335 EXPECT_TRUE(buffer_.Seek(tests[i].consume_bytes)); | 344 EXPECT_TRUE(buffer_.Seek(tests[i].consume_bytes)); |
| 336 | 345 |
| 337 int64 actual = buffer_.current_time().ToInternalValue(); | 346 int64 actual = buffer_.current_time().ToInternalValue(); |
| 338 | 347 |
| 339 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" | 348 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" |
| 340 << tests[i].first_time_useconds << ", duration:" | 349 << tests[i].first_time_useconds << ", duration:" |
| 341 << tests[i].duration_useconds << ", consumed:" | 350 << tests[i].duration_useconds << ", consumed:" |
| 342 << tests[i].consume_bytes << "}\n"; | 351 << tests[i].consume_bytes << " }\n"; |
| 343 | 352 |
| 344 buffer_.Clear(); | 353 buffer_.Clear(); |
| 345 } | 354 } |
| 346 } | 355 } |
| 347 | 356 |
| 348 } // namespace media | 357 } // namespace media |
| OLD | NEW |