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