Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_buffer.h" | 6 #include "media/base/audio_buffer.h" |
| 7 #include "media/base/audio_bus.h" | 7 #include "media/base/audio_bus.h" |
| 8 #include "media/base/audio_discard_helper.h" | 8 #include "media/base/audio_discard_helper.h" |
| 9 #include "media/base/buffers.h" | 9 #include "media/base/buffers.h" |
| 10 #include "media/base/decoder_buffer.h" | 10 #include "media/base/decoder_buffer.h" |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 scoped_refptr<AudioBuffer> decoded_buffer = CreateDecodedBuffer(kTestFrames); | 322 scoped_refptr<AudioBuffer> decoded_buffer = CreateDecodedBuffer(kTestFrames); |
| 323 | 323 |
| 324 // Set a discard padding equivalent to half of the buffer. | 324 // Set a discard padding equivalent to half of the buffer. |
| 325 encoded_buffer->set_discard_padding( | 325 encoded_buffer->set_discard_padding( |
| 326 std::make_pair(kDuration / 2, base::TimeDelta())); | 326 std::make_pair(kDuration / 2, base::TimeDelta())); |
| 327 | 327 |
| 328 // All of the first buffer should be discarded. | 328 // All of the first buffer should be discarded. |
| 329 ASSERT_FALSE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | 329 ASSERT_FALSE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); |
| 330 ASSERT_TRUE(discard_helper.initialized()); | 330 ASSERT_TRUE(discard_helper.initialized()); |
| 331 | 331 |
| 332 // Processing another buffer (with the same discard padding) should discard | 332 // Processing another buffer should discard the back half of the buffer since |
| 333 // the back half of the buffer since kDecoderDelay is half a buffer. | 333 // kDecoderDelay is half a buffer. The end padding should not be discarded |
| 334 // until another buffer is processed. kDuration / 4 is chosen for the end | |
| 335 // discard since it will force the end discard to start after position zero | |
| 336 // within the next decoded buffer. | |
|
acolwell GONE FROM CHROMIUM
2014/07/24 19:22:14
I'm confused by this comment. Wasn't the decoder d
DaleCurtis
2014/07/24 19:58:59
Decoder delay is forever. Remember it's not inclu
DaleCurtis
2014/07/29 01:35:09
Per our offline conversation I've added diagrams e
| |
| 334 encoded_buffer->set_timestamp(kTimestamp + kDuration); | 337 encoded_buffer->set_timestamp(kTimestamp + kDuration); |
| 338 encoded_buffer->set_discard_padding( | |
| 339 std::make_pair(kDuration / 2, kDuration / 4)); | |
| 335 decoded_buffer = CreateDecodedBuffer(kTestFrames); | 340 decoded_buffer = CreateDecodedBuffer(kTestFrames); |
| 336 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); | 341 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); |
| 337 ASSERT_NEAR(kDecoderDelay * kDataStep, | 342 ASSERT_NEAR(kDecoderDelay * kDataStep, |
| 338 ExtractDecodedData(decoded_buffer, kDecoderDelay), | 343 ExtractDecodedData(decoded_buffer, kDecoderDelay), |
| 339 kDataStep * 1000); | 344 kDataStep * 1000); |
| 340 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | 345 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); |
| 341 EXPECT_EQ(kTimestamp, decoded_buffer->timestamp()); | 346 EXPECT_EQ(kTimestamp, decoded_buffer->timestamp()); |
| 342 EXPECT_EQ(kDuration / 2, decoded_buffer->duration()); | 347 EXPECT_EQ(kDuration / 2, decoded_buffer->duration()); |
| 343 EXPECT_EQ(kTestFrames / 2, decoded_buffer->frame_count()); | 348 EXPECT_EQ(kTestFrames / 2, decoded_buffer->frame_count()); |
| 344 | 349 |
| 345 // Verify it was actually the latter half of the buffer that was removed. | 350 // Verify it was actually the latter half of the buffer that was removed. |
| 346 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); | 351 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); |
| 352 | |
| 353 // Verify the end discard padding is carried over to the next buffer. Use | |
| 354 // kDuration / 2 so that the next buffer has its start entirely discarded. | |
| 355 encoded_buffer->set_timestamp(kTimestamp + kDuration); | |
|
acolwell GONE FROM CHROMIUM
2014/07/24 19:22:14
Shouldn't you be using + 2 * kDuration here so it
DaleCurtis
2014/07/29 01:35:09
Done.
| |
| 356 encoded_buffer->set_discard_padding( | |
| 357 std::make_pair(base::TimeDelta(), kDuration / 2)); | |
| 358 decoded_buffer = CreateDecodedBuffer(kTestFrames); | |
| 359 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | |
| 360 EXPECT_EQ(kTimestamp + kDuration / 2, decoded_buffer->timestamp()); | |
| 361 EXPECT_EQ(3 * kDuration / 4, decoded_buffer->duration()); | |
| 362 EXPECT_EQ(3 * kTestFrames / 4, decoded_buffer->frame_count()); | |
| 363 | |
| 364 // Verify it was actually the second quarter of the buffer that was removed. | |
| 365 const int kDiscardFrames = kTestFrames / 4; | |
| 366 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); | |
| 367 ASSERT_FLOAT_EQ( | |
| 368 kDiscardFrames * 2 * kDataStep, | |
| 369 ExtractDecodedData(decoded_buffer, kDecoderDelay - kDiscardFrames)); | |
| 370 | |
| 371 // One last test to ensure carryover discard from the start works. | |
| 372 encoded_buffer->set_timestamp(kTimestamp + kDuration * 2); | |
|
acolwell GONE FROM CHROMIUM
2014/07/24 19:22:14
Shouldn't this be *3?
DaleCurtis
2014/07/29 01:35:09
Done.
| |
| 373 encoded_buffer->set_discard_padding(DecoderBuffer::DiscardPadding()); | |
| 374 decoded_buffer = CreateDecodedBuffer(kTestFrames); | |
| 375 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); | |
| 376 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | |
| 377 EXPECT_EQ(kTimestamp + kDuration / 2 + 3 * kDuration / 4, | |
| 378 decoded_buffer->timestamp()); | |
| 379 EXPECT_EQ(kDuration / 2, decoded_buffer->duration()); | |
| 380 EXPECT_EQ(kTestFrames / 2, decoded_buffer->frame_count()); | |
| 381 ASSERT_FLOAT_EQ(kTestFrames / 2 * kDataStep, | |
| 382 ExtractDecodedData(decoded_buffer, 0)); | |
| 347 } | 383 } |
| 348 | 384 |
| 349 TEST(AudioDiscardHelperTest, DelayedDiscardInitialDiscardAndDiscardPadding) { | 385 TEST(AudioDiscardHelperTest, DelayedDiscardInitialDiscardAndDiscardPadding) { |
| 350 AudioDiscardHelper discard_helper(kSampleRate, 0); | 386 AudioDiscardHelper discard_helper(kSampleRate, 0); |
| 351 ASSERT_FALSE(discard_helper.initialized()); | 387 ASSERT_FALSE(discard_helper.initialized()); |
| 352 | 388 |
| 353 const base::TimeDelta kTimestamp = base::TimeDelta(); | 389 const base::TimeDelta kTimestamp = base::TimeDelta(); |
| 354 const base::TimeDelta kDuration = base::TimeDelta::FromMilliseconds(10); | 390 const base::TimeDelta kDuration = base::TimeDelta::FromMilliseconds(10); |
| 355 const int kTestFrames = discard_helper.TimeDeltaToFrames(kDuration); | 391 const int kTestFrames = discard_helper.TimeDeltaToFrames(kDuration); |
| 356 | 392 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 decoded_buffer = CreateDecodedBuffer(kTestFrames * 2); | 508 decoded_buffer = CreateDecodedBuffer(kTestFrames * 2); |
| 473 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | 509 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); |
| 474 EXPECT_EQ(kTimestamp, decoded_buffer->timestamp()); | 510 EXPECT_EQ(kTimestamp, decoded_buffer->timestamp()); |
| 475 EXPECT_EQ(kDuration * 2 - kDuration / 2, decoded_buffer->duration()); | 511 EXPECT_EQ(kDuration * 2 - kDuration / 2, decoded_buffer->duration()); |
| 476 EXPECT_EQ(kTestFrames * 2 - kDecoderDelay, decoded_buffer->frame_count()); | 512 EXPECT_EQ(kTestFrames * 2 - kDecoderDelay, decoded_buffer->frame_count()); |
| 477 ASSERT_FLOAT_EQ(kDecoderDelay * kDataStep, | 513 ASSERT_FLOAT_EQ(kDecoderDelay * kDataStep, |
| 478 ExtractDecodedData(decoded_buffer, 0)); | 514 ExtractDecodedData(decoded_buffer, 0)); |
| 479 } | 515 } |
| 480 | 516 |
| 481 } // namespace media | 517 } // namespace media |
| OLD | NEW |