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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 3344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3355 seek_time.InMilliseconds(), 5); | 3355 seek_time.InMilliseconds(), 5); |
3356 | 3356 |
3357 // We should delete first append, and be exactly at buffer limit | 3357 // We should delete first append, and be exactly at buffer limit |
3358 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 0)); | 3358 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 0)); |
3359 | 3359 |
3360 // Verify that the old data, and nothing more, has been garbage collected. | 3360 // Verify that the old data, and nothing more, has been garbage collected. |
3361 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [1000,1230) }"); | 3361 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [1000,1230) }"); |
3362 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [1000,1165) }"); | 3362 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [1000,1165) }"); |
3363 } | 3363 } |
3364 | 3364 |
| 3365 TEST_F(ChunkDemuxerTest, GCDuringSeek_SingleRange_SeekForward) { |
| 3366 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
| 3367 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); |
| 3368 // Append some data at position 1000ms |
| 3369 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 10); |
| 3370 CheckExpectedRanges(kSourceId, "{ [1000,1230) }"); |
| 3371 |
| 3372 // GC should be able to evict frames in the currently buffered range, since |
| 3373 // those frames are earlier than the seek target position. |
| 3374 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000); |
| 3375 Seek(seek_time); |
| 3376 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize)); |
| 3377 |
| 3378 // Append data to complete seek operation |
| 3379 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); |
| 3380 CheckExpectedRanges(kSourceId, "{ [1115,1230) [2000,2115) }"); |
| 3381 } |
| 3382 |
| 3383 TEST_F(ChunkDemuxerTest, GCDuringSeek_SingleRange_SeekBack) { |
| 3384 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
| 3385 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); |
| 3386 // Append some data at position 1000ms |
| 3387 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 10); |
| 3388 CheckExpectedRanges(kSourceId, "{ [1000,1230) }"); |
| 3389 |
| 3390 // GC should be able to evict frames in the currently buffered range, since |
| 3391 // seek target position has no data and so we should allow some frames to be |
| 3392 // evicted to make space for the upcoming append at seek target position. |
| 3393 base::TimeDelta seek_time = base::TimeDelta(); |
| 3394 Seek(seek_time); |
| 3395 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize)); |
| 3396 |
| 3397 // Append data to complete seek operation |
| 3398 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 5); |
| 3399 CheckExpectedRanges(kSourceId, "{ [0,115) [1115,1230) }"); |
| 3400 } |
| 3401 |
| 3402 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekForward) { |
| 3403 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
| 3404 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); |
| 3405 // Append some data at position 1000ms then at 2000ms |
| 3406 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); |
| 3407 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); |
| 3408 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); |
| 3409 |
| 3410 // GC should be able to evict frames in the currently buffered ranges, since |
| 3411 // those frames are earlier than the seek target position. |
| 3412 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(3000); |
| 3413 Seek(seek_time); |
| 3414 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize)); |
| 3415 |
| 3416 // Append data to complete seek operation |
| 3417 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3000, 5); |
| 3418 CheckExpectedRanges(kSourceId, "{ [2069,2115) [3000,3115) }"); |
| 3419 } |
| 3420 |
| 3421 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekInbetween1) { |
| 3422 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
| 3423 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); |
| 3424 // Append some data at position 1000ms then at 2000ms |
| 3425 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); |
| 3426 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); |
| 3427 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); |
| 3428 |
| 3429 // GC should be able to evict all frames from the first buffered range, since |
| 3430 // those frames are earlier than the seek target position. But there's only 5 |
| 3431 // blocks worth of data in the first range and seek target position has no |
| 3432 // data, so GC proceeds with trying to delete some frames from the back of |
| 3433 // buffered ranges, that doesn't yield anything, since that's the most |
| 3434 // recently appended data, so then GC starts removing data from the front of |
| 3435 // the remaining buffered range (2000ms) to ensure we free up enough space for |
| 3436 // the upcoming append and allow seek to proceed. |
| 3437 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(1500); |
| 3438 Seek(seek_time); |
| 3439 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize)); |
| 3440 |
| 3441 // Append data to complete seek operation |
| 3442 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1500, 5); |
| 3443 CheckExpectedRanges(kSourceId, "{ [1500,1615) [2069,2115) }"); |
| 3444 } |
| 3445 |
| 3446 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekInbetween2) { |
| 3447 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
| 3448 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); |
| 3449 |
| 3450 // Append some data at position 2000ms first, then at 1000ms, so that the last |
| 3451 // appended data position is in the first buffered range (that matters to the |
| 3452 // GC algorithm since it tries to preserve more recently appended data). |
| 3453 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); |
| 3454 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); |
| 3455 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); |
| 3456 |
| 3457 // Now try performing garbage collection without announcing seek first, i.e. |
| 3458 // without calling Seek(), the GC algorithm should try to preserve data in the |
| 3459 // first range, since that is most recently appended data. |
| 3460 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2030); |
| 3461 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize)); |
| 3462 |
| 3463 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1500, 5); |
| 3464 CheckExpectedRanges(kSourceId, "{ [1000,1115) [1500,1615) }"); |
| 3465 } |
| 3466 |
| 3467 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekBack) { |
| 3468 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
| 3469 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); |
| 3470 // Append some data at position 1000ms then at 2000ms |
| 3471 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); |
| 3472 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); |
| 3473 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); |
| 3474 |
| 3475 // GC should be able to evict frames in the currently buffered ranges, since |
| 3476 // those frames are earlier than the seek target position. |
| 3477 base::TimeDelta seek_time = base::TimeDelta(); |
| 3478 Seek(seek_time); |
| 3479 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize)); |
| 3480 |
| 3481 // Append data to complete seek operation |
| 3482 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 5); |
| 3483 CheckExpectedRanges(kSourceId, "{ [0,115) [2069,2115) }"); |
| 3484 } |
| 3485 |
3365 TEST_F(ChunkDemuxerTest, GCDuringSeek) { | 3486 TEST_F(ChunkDemuxerTest, GCDuringSeek) { |
3366 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); | 3487 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
3367 | 3488 |
3368 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 5 * kBlockSize); | 3489 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 5 * kBlockSize); |
3369 | 3490 |
3370 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(1000); | 3491 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(1000); |
3371 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(500); | 3492 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(500); |
3372 | 3493 |
3373 // Initiate a seek to |seek_time1|. | 3494 // Initiate a seek to |seek_time1|. |
3374 Seek(seek_time1); | 3495 Seek(seek_time1); |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3841 // audio size is 80 bytes, new data is 28 bytes, we need to remove just one 10 | 3962 // audio size is 80 bytes, new data is 28 bytes, we need to remove just one 10 |
3842 // byte block to stay under 100 bytes memory limit after append | 3963 // byte block to stay under 100 bytes memory limit after append |
3843 // 80 - 10 + 28 = 98). | 3964 // 80 - 10 + 28 = 98). |
3844 // For video stream 150 + 52 = 202. Video limit is 150 bytes. We need to | 3965 // For video stream 150 + 52 = 202. Video limit is 150 bytes. We need to |
3845 // remove at least 6 blocks to stay under limit. | 3966 // remove at least 6 blocks to stay under limit. |
3846 CheckExpectedBuffers(audio_stream, "40K 80K 120K 160K 200K 240K 280K"); | 3967 CheckExpectedBuffers(audio_stream, "40K 80K 120K 160K 200K 240K 280K"); |
3847 CheckExpectedBuffers(video_stream, "60K 70 80K 90 100K 110 120K 130 140K"); | 3968 CheckExpectedBuffers(video_stream, "60K 70 80K 90 100K 110 120K 130 140K"); |
3848 } | 3969 } |
3849 | 3970 |
3850 } // namespace media | 3971 } // namespace media |
OLD | NEW |