| 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 "media/base/seekable_buffer.h" | 5 #include "media/base/seekable_buffer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <cstdlib> | 10 #include <cstdlib> |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 EXPECT_EQ(0, buffer_.Read(write_buffer_, 0)); | 289 EXPECT_EQ(0, buffer_.Read(write_buffer_, 0)); |
| 290 EXPECT_EQ(0, buffer_.Read(write_buffer_, 1)); | 290 EXPECT_EQ(0, buffer_.Read(write_buffer_, 1)); |
| 291 EXPECT_TRUE(buffer_.Seek(0)); | 291 EXPECT_TRUE(buffer_.Seek(0)); |
| 292 EXPECT_FALSE(buffer_.Seek(-1)); | 292 EXPECT_FALSE(buffer_.Seek(-1)); |
| 293 EXPECT_FALSE(buffer_.Seek(1)); | 293 EXPECT_FALSE(buffer_.Seek(1)); |
| 294 EXPECT_EQ(0, buffer_.forward_bytes()); | 294 EXPECT_EQ(0, buffer_.forward_bytes()); |
| 295 EXPECT_EQ(0, buffer_.backward_bytes()); | 295 EXPECT_EQ(0, buffer_.backward_bytes()); |
| 296 } | 296 } |
| 297 | 297 |
| 298 TEST_F(SeekableBufferTest, GetTime) { | 298 TEST_F(SeekableBufferTest, GetTime) { |
| 299 const int64_t kNoTS = kNoTimestamp().ToInternalValue(); | 299 const int64_t kNoTS = kNoTimestamp.ToInternalValue(); |
| 300 const struct { | 300 const struct { |
| 301 int64_t first_time_useconds; | 301 int64_t first_time_useconds; |
| 302 int64_t duration_useconds; | 302 int64_t duration_useconds; |
| 303 int consume_bytes; | 303 int consume_bytes; |
| 304 int64_t expected_time; | 304 int64_t expected_time; |
| 305 } tests[] = { | 305 } tests[] = { |
| 306 { kNoTS, 1000000, 0, kNoTS }, | 306 { kNoTS, 1000000, 0, kNoTS }, |
| 307 { kNoTS, 4000000, 0, kNoTS }, | 307 { kNoTS, 4000000, 0, kNoTS }, |
| 308 { kNoTS, 8000000, 0, kNoTS }, | 308 { kNoTS, 8000000, 0, kNoTS }, |
| 309 { kNoTS, 1000000, kWriteSize / 2, kNoTS }, | 309 { kNoTS, 1000000, kWriteSize / 2, kNoTS }, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 325 { 5, 4000000, 0, 5 }, | 325 { 5, 4000000, 0, 5 }, |
| 326 { 5, 8000000, 0, 5 }, | 326 { 5, 8000000, 0, 5 }, |
| 327 { 5, 1000000, kWriteSize / 2, 500005 }, | 327 { 5, 1000000, kWriteSize / 2, 500005 }, |
| 328 { 5, 4000000, kWriteSize / 2, 2000005 }, | 328 { 5, 4000000, kWriteSize / 2, 2000005 }, |
| 329 { 5, 8000000, kWriteSize / 2, 4000005 }, | 329 { 5, 8000000, kWriteSize / 2, 4000005 }, |
| 330 { 5, 1000000, kWriteSize, 1000005 }, | 330 { 5, 1000000, kWriteSize, 1000005 }, |
| 331 { 5, 4000000, kWriteSize, 4000005 }, | 331 { 5, 4000000, kWriteSize, 4000005 }, |
| 332 { 5, 8000000, kWriteSize, 8000005 }, | 332 { 5, 8000000, kWriteSize, 8000005 }, |
| 333 }; | 333 }; |
| 334 | 334 |
| 335 // current_time() must initially return kNoTimestamp(). | 335 // current_time() must initially return kNoTimestamp. |
| 336 EXPECT_EQ(kNoTimestamp().ToInternalValue(), | 336 EXPECT_EQ(kNoTimestamp.ToInternalValue(), |
| 337 buffer_.current_time().ToInternalValue()); | 337 buffer_.current_time().ToInternalValue()); |
| 338 | 338 |
| 339 scoped_refptr<DataBuffer> buffer = DataBuffer::CopyFrom(data_, kWriteSize); | 339 scoped_refptr<DataBuffer> buffer = DataBuffer::CopyFrom(data_, kWriteSize); |
| 340 | 340 |
| 341 for (size_t i = 0; i < arraysize(tests); ++i) { | 341 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 342 buffer->set_timestamp(base::TimeDelta::FromMicroseconds( | 342 buffer->set_timestamp(base::TimeDelta::FromMicroseconds( |
| 343 tests[i].first_time_useconds)); | 343 tests[i].first_time_useconds)); |
| 344 buffer->set_duration(base::TimeDelta::FromMicroseconds( | 344 buffer->set_duration(base::TimeDelta::FromMicroseconds( |
| 345 tests[i].duration_useconds)); | 345 tests[i].duration_useconds)); |
| 346 buffer_.Append(buffer.get()); | 346 buffer_.Append(buffer.get()); |
| 347 EXPECT_TRUE(buffer_.Seek(tests[i].consume_bytes)); | 347 EXPECT_TRUE(buffer_.Seek(tests[i].consume_bytes)); |
| 348 | 348 |
| 349 int64_t actual = buffer_.current_time().ToInternalValue(); | 349 int64_t actual = buffer_.current_time().ToInternalValue(); |
| 350 | 350 |
| 351 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" | 351 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" |
| 352 << tests[i].first_time_useconds << ", duration:" | 352 << tests[i].first_time_useconds << ", duration:" |
| 353 << tests[i].duration_useconds << ", consumed:" | 353 << tests[i].duration_useconds << ", consumed:" |
| 354 << tests[i].consume_bytes << " }\n"; | 354 << tests[i].consume_bytes << " }\n"; |
| 355 | 355 |
| 356 buffer_.Clear(); | 356 buffer_.Clear(); |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 | 359 |
| 360 } // namespace media | 360 } // namespace media |
| OLD | NEW |