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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 const int kTestFrames = discard_helper.TimeDeltaToFrames(kDuration); | 318 const int kTestFrames = discard_helper.TimeDeltaToFrames(kDuration); |
| 319 | 319 |
| 320 scoped_refptr<DecoderBuffer> encoded_buffer = | 320 scoped_refptr<DecoderBuffer> encoded_buffer = |
| 321 CreateEncodedBuffer(kTimestamp, kDuration); | 321 CreateEncodedBuffer(kTimestamp, kDuration); |
| 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, half from the inital delay and |
| 329 // another half from the front discard padding. | |
| 330 // | |
| 331 // Encoded Discard Delay | |
| 332 // |--------| |---------| |----| | |
| 333 // |AAAAAAAA| --> |....|AAAA| --> |AAAA| -------> NULL | |
| 334 // |--------| |---------| |----| | |
| 335 // Decoded Discard Front Padding | |
| 336 // | |
| 329 ASSERT_FALSE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | 337 ASSERT_FALSE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); |
| 330 ASSERT_TRUE(discard_helper.initialized()); | 338 ASSERT_TRUE(discard_helper.initialized()); |
| 331 | 339 |
| 332 // Processing another buffer (with the same discard padding) should discard | 340 // Processing another buffer should discard the back half of the buffer since |
|
wolenetz
2014/07/30 22:04:31
nit: s/another buffer should/another buffer that h
DaleCurtis
2014/07/30 22:52:00
Done.
| |
| 333 // the back half of the buffer since kDecoderDelay is half a buffer. | 341 // kDecoderDelay is half a buffer. The end padding should not be discarded |
|
wolenetz
2014/07/30 22:04:32
nit: s/since kDecoderDelay is half a buffer/and fr
DaleCurtis
2014/07/30 22:52:00
I don't think this one is helpful and makes the se
wolenetz
2014/07/30 23:12:34
Acknowledged.
| |
| 334 encoded_buffer->set_timestamp(kTimestamp + kDuration); | 342 // until another buffer is processed. kDuration / 4 is chosen for the end |
| 343 // discard since it will force the end discard to start after position zero | |
| 344 // within the next decoded buffer. | |
| 345 // | |
| 346 // Encoded Discard Front Padding (from B) | |
| 347 // |--------| |---------| |----| | |
| 348 // |BBBBBBBB| --> |AAAA|BBBB| ----------> |AAAA| | |
| 349 // |--------| |---------| |----| | |
| 350 // Decoded | |
| 351 // (includes carryover from A) | |
| 352 // | |
| 353 encoded_buffer->set_timestamp(encoded_buffer->timestamp() + kDuration); | |
| 354 encoded_buffer->set_discard_padding( | |
| 355 std::make_pair(kDuration / 2, kDuration / 4)); | |
| 335 decoded_buffer = CreateDecodedBuffer(kTestFrames); | 356 decoded_buffer = CreateDecodedBuffer(kTestFrames); |
| 336 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); | 357 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); |
| 337 ASSERT_NEAR(kDecoderDelay * kDataStep, | 358 ASSERT_NEAR(kDecoderDelay * kDataStep, |
| 338 ExtractDecodedData(decoded_buffer, kDecoderDelay), | 359 ExtractDecodedData(decoded_buffer, kDecoderDelay), |
| 339 kDataStep * 1000); | 360 kDataStep * 1000); |
|
wolenetz
2014/07/30 22:04:31
This nearness distance requirement seems too loose
DaleCurtis
2014/07/30 22:51:59
Whoops, this should be kDataStep / 1000 meaning th
| |
| 340 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | 361 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); |
| 341 EXPECT_EQ(kTimestamp, decoded_buffer->timestamp()); | 362 EXPECT_EQ(kTimestamp, decoded_buffer->timestamp()); |
| 342 EXPECT_EQ(kDuration / 2, decoded_buffer->duration()); | 363 EXPECT_EQ(kDuration / 2, decoded_buffer->duration()); |
| 343 EXPECT_EQ(kTestFrames / 2, decoded_buffer->frame_count()); | 364 EXPECT_EQ(kTestFrames / 2, decoded_buffer->frame_count()); |
| 344 | 365 |
| 345 // Verify it was actually the latter half of the buffer that was removed. | 366 // Verify it was actually the latter half of the buffer that was removed. |
| 346 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); | 367 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); |
| 368 | |
| 369 // Verify the end discard padding is carried over to the next buffer. Use | |
| 370 // kDuration / 2 so that the next buffer has its start entirely discarded. | |
|
wolenetz
2014/07/30 22:04:31
nit: this "Use kDuration / 2" portion of the comme
DaleCurtis
2014/07/30 22:52:00
As the end discard padding. I've clarified the sen
| |
| 371 // | |
| 372 // Encoded Discard End Padding (from B) | |
| 373 // |--------| |---------| |-------| | |
| 374 // |CCCCCCCC| --> |BBBB|CCCC| ----------> |BB|CCCC| | |
| 375 // |--------| |---------| |-------| | |
| 376 // Decoded | |
| 377 // (includes carryover from B) | |
| 378 // | |
| 379 encoded_buffer->set_timestamp(encoded_buffer->timestamp() + kDuration); | |
| 380 encoded_buffer->set_discard_padding( | |
| 381 std::make_pair(base::TimeDelta(), kDuration / 2)); | |
| 382 decoded_buffer = CreateDecodedBuffer(kTestFrames); | |
| 383 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | |
| 384 EXPECT_EQ(kTimestamp + kDuration / 2, decoded_buffer->timestamp()); | |
| 385 EXPECT_EQ(3 * kDuration / 4, decoded_buffer->duration()); | |
| 386 EXPECT_EQ(3 * kTestFrames / 4, decoded_buffer->frame_count()); | |
| 387 | |
| 388 // Verify it was actually the second quarter of the buffer that was removed. | |
| 389 const int kDiscardFrames = kTestFrames / 4; | |
| 390 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); | |
| 391 ASSERT_FLOAT_EQ( | |
| 392 kDiscardFrames * 2 * kDataStep, | |
| 393 ExtractDecodedData(decoded_buffer, kDecoderDelay - kDiscardFrames)); | |
| 394 | |
| 395 // One last test to ensure carryover discard from the start works. | |
| 396 // | |
| 397 // Encoded Discard End Padding (from C) | |
| 398 // |--------| |---------| |----| | |
| 399 // |DDDDDDDD| --> |CCCC|DDDD| ----------> |DDDD| | |
| 400 // |--------| |---------| |----| | |
| 401 // Decoded | |
| 402 // (includes carryover from C) | |
| 403 // | |
| 404 encoded_buffer->set_timestamp(encoded_buffer->timestamp() + kDuration); | |
| 405 encoded_buffer->set_discard_padding(DecoderBuffer::DiscardPadding()); | |
| 406 decoded_buffer = CreateDecodedBuffer(kTestFrames); | |
| 407 ASSERT_FLOAT_EQ(0.0f, ExtractDecodedData(decoded_buffer, 0)); | |
| 408 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | |
| 409 EXPECT_EQ(kTimestamp + kDuration / 2 + 3 * kDuration / 4, | |
| 410 decoded_buffer->timestamp()); | |
| 411 EXPECT_EQ(kDuration / 2, decoded_buffer->duration()); | |
| 412 EXPECT_EQ(kTestFrames / 2, decoded_buffer->frame_count()); | |
| 413 ASSERT_FLOAT_EQ(kTestFrames / 2 * kDataStep, | |
| 414 ExtractDecodedData(decoded_buffer, 0)); | |
| 347 } | 415 } |
| 348 | 416 |
| 349 TEST(AudioDiscardHelperTest, DelayedDiscardInitialDiscardAndDiscardPadding) { | 417 TEST(AudioDiscardHelperTest, DelayedDiscardInitialDiscardAndDiscardPadding) { |
| 350 AudioDiscardHelper discard_helper(kSampleRate, 0); | 418 AudioDiscardHelper discard_helper(kSampleRate, 0); |
| 351 ASSERT_FALSE(discard_helper.initialized()); | 419 ASSERT_FALSE(discard_helper.initialized()); |
| 352 | 420 |
| 353 const base::TimeDelta kTimestamp = base::TimeDelta(); | 421 const base::TimeDelta kTimestamp = base::TimeDelta(); |
| 354 const base::TimeDelta kDuration = base::TimeDelta::FromMilliseconds(10); | 422 const base::TimeDelta kDuration = base::TimeDelta::FromMilliseconds(10); |
| 355 const int kTestFrames = discard_helper.TimeDeltaToFrames(kDuration); | 423 const int kTestFrames = discard_helper.TimeDeltaToFrames(kDuration); |
| 356 | 424 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 decoded_buffer = CreateDecodedBuffer(kTestFrames * 2); | 540 decoded_buffer = CreateDecodedBuffer(kTestFrames * 2); |
| 473 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); | 541 ASSERT_TRUE(discard_helper.ProcessBuffers(encoded_buffer, decoded_buffer)); |
| 474 EXPECT_EQ(kTimestamp, decoded_buffer->timestamp()); | 542 EXPECT_EQ(kTimestamp, decoded_buffer->timestamp()); |
| 475 EXPECT_EQ(kDuration * 2 - kDuration / 2, decoded_buffer->duration()); | 543 EXPECT_EQ(kDuration * 2 - kDuration / 2, decoded_buffer->duration()); |
| 476 EXPECT_EQ(kTestFrames * 2 - kDecoderDelay, decoded_buffer->frame_count()); | 544 EXPECT_EQ(kTestFrames * 2 - kDecoderDelay, decoded_buffer->frame_count()); |
| 477 ASSERT_FLOAT_EQ(kDecoderDelay * kDataStep, | 545 ASSERT_FLOAT_EQ(kDecoderDelay * kDataStep, |
| 478 ExtractDecodedData(decoded_buffer, 0)); | 546 ExtractDecodedData(decoded_buffer, 0)); |
| 479 } | 547 } |
| 480 | 548 |
| 481 } // namespace media | 549 } // namespace media |
| OLD | NEW |