Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: media/filters/source_buffer_stream_unittest.cc

Issue 1008463002: Fix MSE GC, make it less aggressive, more spec-compliant (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: A bit more informative logging + fixed unit test Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/filters/source_buffer_stream.h" 5 #include "media/filters/source_buffer_stream.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 139
140 void Seek(int position) { 140 void Seek(int position) {
141 stream_->Seek(position * frame_duration_); 141 stream_->Seek(position * frame_duration_);
142 } 142 }
143 143
144 void SeekToTimestampMs(int64_t timestamp_ms) { 144 void SeekToTimestampMs(int64_t timestamp_ms) {
145 stream_->Seek(base::TimeDelta::FromMilliseconds(timestamp_ms)); 145 stream_->Seek(base::TimeDelta::FromMilliseconds(timestamp_ms));
146 } 146 }
147 147
148 bool GarbageCollectWithPlaybackAtBuffer(int position) {
149 return stream_->GarbageCollectIfNeeded(
150 DecodeTimestamp::FromPresentationTime(position * frame_duration_));
151 }
152
148 void RemoveInMs(int start, int end, int duration) { 153 void RemoveInMs(int start, int end, int duration) {
149 Remove(base::TimeDelta::FromMilliseconds(start), 154 Remove(base::TimeDelta::FromMilliseconds(start),
150 base::TimeDelta::FromMilliseconds(end), 155 base::TimeDelta::FromMilliseconds(end),
151 base::TimeDelta::FromMilliseconds(duration)); 156 base::TimeDelta::FromMilliseconds(duration));
152 } 157 }
153 158
154 void Remove(base::TimeDelta start, base::TimeDelta end, 159 void Remove(base::TimeDelta start, base::TimeDelta end,
155 base::TimeDelta duration) { 160 base::TimeDelta duration) {
156 stream_->Remove(start, end, duration); 161 stream_->Remove(start, end, duration);
157 } 162 }
(...skipping 2196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2354 // Set memory limit to 20 buffers. 2359 // Set memory limit to 20 buffers.
2355 SetMemoryLimit(20); 2360 SetMemoryLimit(20);
2356 2361
2357 // Append 20 buffers at positions 0 through 19. 2362 // Append 20 buffers at positions 0 through 19.
2358 NewSegmentAppend(0, 1, &kDataA); 2363 NewSegmentAppend(0, 1, &kDataA);
2359 for (int i = 1; i < 20; i++) 2364 for (int i = 1; i < 20; i++)
2360 AppendBuffers(i, 1, &kDataA); 2365 AppendBuffers(i, 1, &kDataA);
2361 2366
2362 // None of the buffers should trigger garbage collection, so all data should 2367 // None of the buffers should trigger garbage collection, so all data should
2363 // be there as expected. 2368 // be there as expected.
2369 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(0));
2364 CheckExpectedRanges("{ [0,19) }"); 2370 CheckExpectedRanges("{ [0,19) }");
2365 Seek(0); 2371 Seek(0);
2366 CheckExpectedBuffers(0, 19, &kDataA); 2372 CheckExpectedBuffers(0, 19, &kDataA);
2367 2373
2368 // Seek to the middle of the stream. 2374 // Seek to the middle of the stream.
2369 Seek(10); 2375 Seek(10);
2370 2376
2371 // Append 5 buffers to the end of the stream. 2377 // Append 5 buffers to the end of the stream.
2372 AppendBuffers(20, 5, &kDataA); 2378 AppendBuffers(20, 5, &kDataA);
2373 2379
2380 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(10));
2381
2374 // GC should have deleted the first 5 buffers. 2382 // GC should have deleted the first 5 buffers.
2375 CheckExpectedRanges("{ [5,24) }"); 2383 CheckExpectedRanges("{ [5,24) }");
2376 CheckExpectedBuffers(10, 24, &kDataA); 2384 CheckExpectedBuffers(10, 24, &kDataA);
2377 Seek(5); 2385 Seek(5);
2378 CheckExpectedBuffers(5, 9, &kDataA); 2386 CheckExpectedBuffers(5, 9, &kDataA);
2379 } 2387 }
2380 2388
2381 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteFrontGOPsAtATime) { 2389 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteFrontGOPsAtATime) {
2382 // Set memory limit to 20 buffers. 2390 // Set memory limit to 20 buffers.
2383 SetMemoryLimit(20); 2391 SetMemoryLimit(20);
2384 2392
2385 // Append 20 buffers at positions 0 through 19. 2393 // Append 20 buffers at positions 0 through 19.
2386 NewSegmentAppend(0, 20, &kDataA); 2394 NewSegmentAppend(0, 20, &kDataA);
2387 2395
2388 // Seek to position 10. 2396 // Seek to position 10.
2389 Seek(10); 2397 Seek(10);
2390 2398
2391 // Add one buffer to put the memory over the cap. 2399 // Add one buffer to put the memory over the cap.
2392 AppendBuffers(20, 1, &kDataA); 2400 AppendBuffers(20, 1, &kDataA);
2393 2401
2402 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(10));
2403
2394 // GC should have deleted the first 5 buffers so that the range still begins 2404 // GC should have deleted the first 5 buffers so that the range still begins
2395 // with a keyframe. 2405 // with a keyframe.
2396 CheckExpectedRanges("{ [5,20) }"); 2406 CheckExpectedRanges("{ [5,20) }");
2397 CheckExpectedBuffers(10, 20, &kDataA); 2407 CheckExpectedBuffers(10, 20, &kDataA);
2398 Seek(5); 2408 Seek(5);
2399 CheckExpectedBuffers(5, 9, &kDataA); 2409 CheckExpectedBuffers(5, 9, &kDataA);
2400 } 2410 }
2401 2411
2402 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteBack) { 2412 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteBack) {
2403 // Set memory limit to 5 buffers. 2413 // Set memory limit to 5 buffers.
2404 SetMemoryLimit(5); 2414 SetMemoryLimit(5);
2405 2415
2416 // Append 5 buffers at positions 15 through 19.
2417 NewSegmentAppend(15, 5, &kDataA);
2418
2419 // Append 5 buffers at positions 0 through 4.
2420 NewSegmentAppend(0, 5, &kDataA);
2421 CheckExpectedRanges("{ [0,4) [15,19) }");
2422
2406 // Seek to position 0. 2423 // Seek to position 0.
2407 Seek(0); 2424 Seek(0);
2408 2425 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(0));
2409 // Append 20 buffers at positions 0 through 19. 2426 // Should leave the first 5 buffers from 0 to 4.
2410 NewSegmentAppend(0, 20, &kDataA); 2427 CheckExpectedRanges("{ [0,4) }");
2411
2412 // Should leave the first 5 buffers from 0 to 4 and the last GOP appended.
2413 CheckExpectedRanges("{ [0,4) [15,19) }");
2414 CheckExpectedBuffers(0, 4, &kDataA); 2428 CheckExpectedBuffers(0, 4, &kDataA);
2415 } 2429 }
2416 2430
2417 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteFrontAndBack) { 2431 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteFrontAndBack) {
2418 // Set memory limit to 3 buffers. 2432 // Set memory limit to 3 buffers.
2419 SetMemoryLimit(3); 2433 SetMemoryLimit(3);
2420 2434
2421 // Seek to position 15. 2435 // Seek to position 15.
2422 Seek(15); 2436 Seek(15);
2423 2437
2424 // Append 40 buffers at positions 0 through 39. 2438 // Append 40 buffers at positions 0 through 39.
2425 NewSegmentAppend(0, 40, &kDataA); 2439 NewSegmentAppend(0, 40, &kDataA);
2440 // GC will try to keep data between current playback position and last append
2441 // position. This will ensure that the last append position is 19 and will
2442 // allow GC algorithm to collect data outside of the range [15,19)
2443 NewSegmentAppend(15, 5, &kDataA);
2444 CheckExpectedRanges("{ [0,39) }");
2426 2445
2427 // Should leave the GOP containing the seek position and the last GOP 2446 // Should leave the GOP containing the current playback position 15 and the
2428 // appended. 2447 // last append position 19. GC returns false, since we are still above limit.
2429 CheckExpectedRanges("{ [15,19) [35,39) }"); 2448 EXPECT_FALSE(GarbageCollectWithPlaybackAtBuffer(15));
2449 CheckExpectedRanges("{ [15,19) }");
2430 CheckExpectedBuffers(15, 19, &kDataA); 2450 CheckExpectedBuffers(15, 19, &kDataA);
2431 CheckNoNextBuffer(); 2451 CheckNoNextBuffer();
2432 } 2452 }
2433 2453
2434 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteSeveralRanges) { 2454 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteSeveralRanges) {
2435 // Append 5 buffers at positions 0 through 4. 2455 // Append 5 buffers at positions 0 through 4.
2436 NewSegmentAppend(0, 5); 2456 NewSegmentAppend(0, 5);
2437 2457
2438 // Append 5 buffers at positions 10 through 14. 2458 // Append 5 buffers at positions 10 through 14.
2439 NewSegmentAppend(10, 5); 2459 NewSegmentAppend(10, 5);
2440 2460
2441 // Append 5 buffers at positions 20 through 24. 2461 // Append 5 buffers at positions 20 through 24.
2442 NewSegmentAppend(20, 5); 2462 NewSegmentAppend(20, 5);
2443 2463
2444 // Append 5 buffers at positions 30 through 34. 2464 // Append 5 buffers at positions 40 through 44.
2445 NewSegmentAppend(30, 5); 2465 NewSegmentAppend(40, 5);
2446 2466
2447 CheckExpectedRanges("{ [0,4) [10,14) [20,24) [30,34) }"); 2467 CheckExpectedRanges("{ [0,4) [10,14) [20,24) [40,44) }");
2448 2468
2449 // Seek to position 21. 2469 // Seek to position 20.
2450 Seek(20); 2470 Seek(20);
2451 CheckExpectedBuffers(20, 20); 2471 CheckExpectedBuffers(20, 20);
2452 2472
2453 // Set memory limit to 1 buffer. 2473 // Set memory limit to 1 buffer.
2454 SetMemoryLimit(1); 2474 SetMemoryLimit(1);
2455 2475
2456 // Append 5 buffers at positions 40 through 44. This will trigger GC. 2476 // Append 5 buffers at positions 30 through 34.
2457 NewSegmentAppend(40, 5); 2477 NewSegmentAppend(30, 5);
2458 2478
2459 // Should delete everything except the GOP containing the current buffer and 2479 // We will have more than 1 buffer left, GC will fail
2460 // the last GOP appended. 2480 EXPECT_FALSE(GarbageCollectWithPlaybackAtBuffer(20));
2461 CheckExpectedRanges("{ [20,24) [40,44) }"); 2481
2482 // Should have deleted all buffer ranges before the current buffer and after
2483 // last GOP
2484 CheckExpectedRanges("{ [20,24) [30,34) }");
2462 CheckExpectedBuffers(21, 24); 2485 CheckExpectedBuffers(21, 24);
2463 CheckNoNextBuffer(); 2486 CheckNoNextBuffer();
2464 2487
2465 // Continue appending into the last range to make sure it didn't break. 2488 // Continue appending into the last range to make sure it didn't break.
2466 AppendBuffers(45, 10); 2489 AppendBuffers(35, 10);
2467 // Should only save last GOP appended. 2490 EXPECT_FALSE(GarbageCollectWithPlaybackAtBuffer(20));
2468 CheckExpectedRanges("{ [20,24) [50,54) }"); 2491 // Should save everything between read head and last appended
2492 CheckExpectedRanges("{ [20,24) [30,44) }");
2469 2493
2470 // Make sure appending before and after the ranges didn't somehow break. 2494 // Make sure appending before and after the ranges didn't somehow break.
2471 SetMemoryLimit(100); 2495 SetMemoryLimit(100);
2472 NewSegmentAppend(0, 10); 2496 NewSegmentAppend(0, 10);
2473 CheckExpectedRanges("{ [0,9) [20,24) [50,54) }"); 2497 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(20));
2498 CheckExpectedRanges("{ [0,9) [20,24) [30,44) }");
2474 Seek(0); 2499 Seek(0);
2475 CheckExpectedBuffers(0, 9); 2500 CheckExpectedBuffers(0, 9);
2476 2501
2477 NewSegmentAppend(90, 10); 2502 NewSegmentAppend(90, 10);
2478 CheckExpectedRanges("{ [0,9) [20,24) [50,54) [90,99) }"); 2503 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(0));
2479 Seek(50); 2504 CheckExpectedRanges("{ [0,9) [20,24) [30,44) [90,99) }");
2480 CheckExpectedBuffers(50, 54); 2505 Seek(30);
2506 CheckExpectedBuffers(30, 44);
2481 CheckNoNextBuffer(); 2507 CheckNoNextBuffer();
2482 Seek(90); 2508 Seek(90);
2483 CheckExpectedBuffers(90, 99); 2509 CheckExpectedBuffers(90, 99);
2484 CheckNoNextBuffer(); 2510 CheckNoNextBuffer();
2485 } 2511 }
2486 2512
2487 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteAfterLastAppend) { 2513 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteAfterLastAppend) {
2488 // Set memory limit to 10 buffers. 2514 // Set memory limit to 10 buffers.
2489 SetMemoryLimit(10); 2515 SetMemoryLimit(10);
2490 2516
2491 // Append 1 GOP starting at 310ms, 30ms apart. 2517 // Append 1 GOP starting at 310ms, 30ms apart.
2492 NewSegmentAppend("310K 340 370"); 2518 NewSegmentAppend("310K 340 370");
2493 2519
2494 // Append 2 GOPs starting at 490ms, 30ms apart. 2520 // Append 2 GOPs starting at 490ms, 30ms apart.
2495 NewSegmentAppend("490K 520 550 580K 610 640"); 2521 NewSegmentAppend("490K 520 550 580K 610 640");
2496 2522
2523 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(0));
2524
2497 CheckExpectedRangesByTimestamp("{ [310,400) [490,670) }"); 2525 CheckExpectedRangesByTimestamp("{ [310,400) [490,670) }");
2498 2526
2499 // Seek to the GOP at 580ms. 2527 // Seek to the GOP at 580ms.
2500 SeekToTimestampMs(580); 2528 SeekToTimestampMs(580);
2501 2529
2502 // Append 2 GOPs before the existing ranges. 2530 // Append 2 GOPs before the existing ranges.
2503 // So the ranges before GC are "{ [100,280) [310,400) [490,670) }". 2531 // So the ranges before GC are "{ [100,280) [310,400) [490,670) }".
2504 NewSegmentAppend("100K 130 160 190K 220 250K"); 2532 NewSegmentAppend("100K 130 160 190K 220 250K");
2505 2533
2534 EXPECT_TRUE(stream_->GarbageCollectIfNeeded(
2535 DecodeTimestamp::FromMilliseconds(580)));
2536
2506 // Should save the newly appended GOPs. 2537 // Should save the newly appended GOPs.
2507 CheckExpectedRangesByTimestamp("{ [100,280) [580,670) }"); 2538 CheckExpectedRangesByTimestamp("{ [100,280) [580,670) }");
2508 } 2539 }
2509 2540
2510 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteAfterLastAppendMerged) { 2541 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteAfterLastAppendMerged) {
2511 // Set memory limit to 10 buffers. 2542 // Set memory limit to 10 buffers.
2512 SetMemoryLimit(10); 2543 SetMemoryLimit(10);
2513 2544
2514 // Append 3 GOPs starting at 400ms, 30ms apart. 2545 // Append 3 GOPs starting at 400ms, 30ms apart.
2515 NewSegmentAppend("400K 430 460 490K 520 550 580K 610 640"); 2546 NewSegmentAppend("400K 430 460 490K 520 550 580K 610 640");
2516 2547
2517 // Seek to the GOP at 580ms. 2548 // Seek to the GOP at 580ms.
2518 SeekToTimestampMs(580); 2549 SeekToTimestampMs(580);
2519 2550
2520 // Append 2 GOPs starting at 220ms, and they will be merged with the existing 2551 // Append 2 GOPs starting at 220ms, and they will be merged with the existing
2521 // range. So the range before GC is "{ [220,670) }". 2552 // range. So the range before GC is "{ [220,670) }".
2522 NewSegmentAppend("220K 250 280 310K 340 370"); 2553 NewSegmentAppend("220K 250 280 310K 340 370");
2523 2554
2555 EXPECT_TRUE(stream_->GarbageCollectIfNeeded(
wolenetz 2015/08/12 21:09:57 I suspect it'll be not-obvious to later maintainer
servolk 2015/08/13 00:31:42 Yes, I think I'll add a comment that we are skippi
wolenetz 2015/08/20 23:23:37 Best solution for now, ISTM, would be to add a com
2556 DecodeTimestamp::FromMilliseconds(580)));
2557
2524 // Should save the newly appended GOPs. 2558 // Should save the newly appended GOPs.
2525 CheckExpectedRangesByTimestamp("{ [220,400) [580,670) }"); 2559 CheckExpectedRangesByTimestamp("{ [220,400) [580,670) }");
2526 } 2560 }
2527 2561
2528 TEST_F(SourceBufferStreamTest, GarbageCollection_NoSeek) { 2562 TEST_F(SourceBufferStreamTest, GarbageCollection_NoSeek) {
2529 // Set memory limit to 20 buffers. 2563 // Set memory limit to 20 buffers.
2530 SetMemoryLimit(20); 2564 SetMemoryLimit(20);
2531 2565
2532 // Append 25 buffers at positions 0 through 24. 2566 // Append 25 buffers at positions 0 through 24.
2533 NewSegmentAppend(0, 25, &kDataA); 2567 NewSegmentAppend(0, 25, &kDataA);
2534 2568
2535 // GC deletes the first 5 buffers to keep the memory limit within cap. 2569 // If playback is still in the first GOP (starting at 0), GC should fail.
2570 EXPECT_FALSE(GarbageCollectWithPlaybackAtBuffer(2));
2571 CheckExpectedRanges("{ [0,24) }");
2572
2573 // As soon as playback position moves past the first GOP, it should be removed
2574 // and after removing the first GOP we are under memory limit.
2575 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(5));
2536 CheckExpectedRanges("{ [5,24) }"); 2576 CheckExpectedRanges("{ [5,24) }");
2537 CheckNoNextBuffer(); 2577 CheckNoNextBuffer();
2538 Seek(5); 2578 Seek(5);
2539 CheckExpectedBuffers(5, 24, &kDataA); 2579 CheckExpectedBuffers(5, 24, &kDataA);
2540 } 2580 }
2541 2581
2542 TEST_F(SourceBufferStreamTest, GarbageCollection_PendingSeek) { 2582 TEST_F(SourceBufferStreamTest, GarbageCollection_PendingSeek) {
2543 // Append 10 buffers at positions 0 through 9. 2583 // Append 10 buffers at positions 0 through 9.
2544 NewSegmentAppend(0, 10, &kDataA); 2584 NewSegmentAppend(0, 10, &kDataA);
2545 2585
2546 // Append 5 buffers at positions 25 through 29. 2586 // Append 5 buffers at positions 25 through 29.
2547 NewSegmentAppend(25, 5, &kDataA); 2587 NewSegmentAppend(25, 5, &kDataA);
2548 2588
2549 // Seek to position 15. 2589 // Seek to position 15.
2550 Seek(15); 2590 Seek(15);
2551 CheckNoNextBuffer(); 2591 CheckNoNextBuffer();
2552 2592
2593 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(0));
2594
2553 CheckExpectedRanges("{ [0,9) [25,29) }"); 2595 CheckExpectedRanges("{ [0,9) [25,29) }");
2554 2596
2555 // Set memory limit to 5 buffers. 2597 // Set memory limit to 5 buffers.
2556 SetMemoryLimit(5); 2598 SetMemoryLimit(5);
2557 2599
2558 // Append 5 buffers as positions 30 to 34 to trigger GC. 2600 // Append 5 buffers as positions 30 to 34 to trigger GC.
2559 AppendBuffers(30, 5, &kDataA); 2601 AppendBuffers(30, 5, &kDataA);
2560 2602
2603 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(30));
2604
2561 // The current algorithm will delete from the beginning until the memory is 2605 // The current algorithm will delete from the beginning until the memory is
2562 // under cap. 2606 // under cap.
2563 CheckExpectedRanges("{ [30,34) }"); 2607 CheckExpectedRanges("{ [30,34) }");
2564 2608
2565 // Expand memory limit again so that GC won't be triggered. 2609 // Expand memory limit again so that GC won't be triggered.
2566 SetMemoryLimit(100); 2610 SetMemoryLimit(100);
2567 2611
2568 // Append data to fulfill seek. 2612 // Append data to fulfill seek.
2569 NewSegmentAppend(15, 5, &kDataA); 2613 NewSegmentAppend(15, 5, &kDataA);
2570 2614
2615 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(30));
2616
2571 // Check to make sure all is well. 2617 // Check to make sure all is well.
2572 CheckExpectedRanges("{ [15,19) [30,34) }"); 2618 CheckExpectedRanges("{ [15,19) [30,34) }");
2573 CheckExpectedBuffers(15, 19, &kDataA); 2619 CheckExpectedBuffers(15, 19, &kDataA);
2574 Seek(30); 2620 Seek(30);
2575 CheckExpectedBuffers(30, 34, &kDataA); 2621 CheckExpectedBuffers(30, 34, &kDataA);
2576 } 2622 }
2577 2623
2578 TEST_F(SourceBufferStreamTest, GarbageCollection_NeedsMoreData) { 2624 TEST_F(SourceBufferStreamTest, GarbageCollection_NeedsMoreData) {
2579 // Set memory limit to 15 buffers. 2625 // Set memory limit to 15 buffers.
2580 SetMemoryLimit(15); 2626 SetMemoryLimit(15);
2581 2627
2582 // Append 10 buffers at positions 0 through 9. 2628 // Append 10 buffers at positions 0 through 9.
2583 NewSegmentAppend(0, 10, &kDataA); 2629 NewSegmentAppend(0, 10, &kDataA);
2584 2630
2585 // Advance next buffer position to 10. 2631 // Advance next buffer position to 10.
2586 Seek(0); 2632 Seek(0);
2633 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(0));
2587 CheckExpectedBuffers(0, 9, &kDataA); 2634 CheckExpectedBuffers(0, 9, &kDataA);
2588 CheckNoNextBuffer(); 2635 CheckNoNextBuffer();
2589 2636
2590 // Append 20 buffers at positions 15 through 34. 2637 // Append 20 buffers at positions 15 through 34.
2591 NewSegmentAppend(15, 20, &kDataA); 2638 NewSegmentAppend(15, 20, &kDataA);
2639 CheckExpectedRanges("{ [0,9) [15,34) }");
2592 2640
2593 // GC should have saved the keyframe before the current seek position and the 2641 // GC should save the keyframe before the next buffer position and the data
2594 // data closest to the current seek position. It will also save the last GOP 2642 // closest to the next buffer position. It will also save all buffers from
2595 // appended. 2643 // next buffer to the last GOP appended, which overflows limit and leads to
2596 CheckExpectedRanges("{ [5,9) [15,19) [30,34) }"); 2644 // failure.
2645 EXPECT_FALSE(GarbageCollectWithPlaybackAtBuffer(5));
2646 CheckExpectedRanges("{ [5,9) [15,34) }");
2597 2647
2598 // Now fulfill the seek at position 10. This will make GC delete the data 2648 // Now fulfill the seek at position 10. This will make GC delete the data
2599 // before position 10 to keep it within cap. 2649 // before position 10 to keep it within cap.
2600 NewSegmentAppend(10, 5, &kDataA); 2650 NewSegmentAppend(10, 5, &kDataA);
2601 CheckExpectedRanges("{ [10,19) [30,34) }"); 2651 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(10));
2602 CheckExpectedBuffers(10, 19, &kDataA); 2652 CheckExpectedRanges("{ [10,24) }");
2653 CheckExpectedBuffers(10, 24, &kDataA);
2603 } 2654 }
2604 2655
2605 TEST_F(SourceBufferStreamTest, GarbageCollection_TrackBuffer) { 2656 TEST_F(SourceBufferStreamTest, GarbageCollection_TrackBuffer) {
2606 // Set memory limit to 3 buffers. 2657 // Set memory limit to 3 buffers.
2607 SetMemoryLimit(3); 2658 SetMemoryLimit(3);
2608 2659
2609 // Seek to position 15. 2660 // Seek to position 15.
2610 Seek(15); 2661 Seek(15);
2611 2662
2612 // Append 18 buffers at positions 0 through 17. 2663 // Append 18 buffers at positions 0 through 17.
2613 NewSegmentAppend(0, 18, &kDataA); 2664 NewSegmentAppend(0, 18, &kDataA);
2614 2665
2666 EXPECT_TRUE(GarbageCollectWithPlaybackAtBuffer(15));
2667
2615 // Should leave GOP containing seek position. 2668 // Should leave GOP containing seek position.
2616 CheckExpectedRanges("{ [15,17) }"); 2669 CheckExpectedRanges("{ [15,17) }");
2617 2670
2618 // Seek ahead to position 16. 2671 // Move next buffer position to 16.
2619 CheckExpectedBuffers(15, 15, &kDataA); 2672 CheckExpectedBuffers(15, 15, &kDataA);
2620 2673
2621 // Completely overlap the existing buffers. 2674 // Completely overlap the existing buffers.
2622 NewSegmentAppend(0, 20, &kDataB); 2675 NewSegmentAppend(0, 20, &kDataB);
2623 2676
2677 // Final GOP [15,19) contains 5 buffers, which is more than memory limit of
2678 // 3 buffers set at the beginning of the test, so GC will fail.
2679 EXPECT_FALSE(GarbageCollectWithPlaybackAtBuffer(15));
2680
2624 // Because buffers 16 and 17 are not keyframes, they are moved to the track 2681 // Because buffers 16 and 17 are not keyframes, they are moved to the track
2625 // buffer upon overlap. The source buffer (i.e. not the track buffer) is now 2682 // buffer upon overlap. The source buffer (i.e. not the track buffer) is now
2626 // waiting for the next keyframe. 2683 // waiting for the next keyframe.
2627 CheckExpectedRanges("{ [15,19) }"); 2684 CheckExpectedRanges("{ [15,19) }");
2628 CheckExpectedBuffers(16, 17, &kDataA); 2685 CheckExpectedBuffers(16, 17, &kDataA);
2629 CheckNoNextBuffer(); 2686 CheckNoNextBuffer();
2630 2687
2631 // Now add a keyframe at position 20. 2688 // Now add a keyframe at position 20.
2632 AppendBuffers(20, 5, &kDataB); 2689 AppendBuffers(20, 5, &kDataB);
2633 2690
2691 // 5 buffers in final GOP, GC will fail
2692 EXPECT_FALSE(GarbageCollectWithPlaybackAtBuffer(20));
2693
2634 // Should garbage collect such that there are 5 frames remaining, starting at 2694 // Should garbage collect such that there are 5 frames remaining, starting at
2635 // the keyframe. 2695 // the keyframe.
2636 CheckExpectedRanges("{ [20,24) }"); 2696 CheckExpectedRanges("{ [20,24) }");
2637 CheckExpectedBuffers(20, 24, &kDataB); 2697 CheckExpectedBuffers(20, 24, &kDataB);
2638 CheckNoNextBuffer(); 2698 CheckNoNextBuffer();
2639 } 2699 }
2640 2700
2701 // Test GC preserves data starting at first GOP containing playback position.
2702 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveDataAtPlaybackPosition) {
2703 // Set memory limit to 30 buffers = 1 second of data.
2704 SetMemoryLimit(30);
2705 // And append 300 buffers = 10 seconds of data.
2706 NewSegmentAppend(0, 300, &kDataA);
2707 CheckExpectedRanges("{ [0,299) }");
2708
2709 // Playback position at 0, all data must be preserved.
2710 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2711 DecodeTimestamp::FromMilliseconds(0)));
2712 CheckExpectedRanges("{ [0,299) }");
2713
2714 // Playback position at 1 sec, the first second of data [0,29) should be
2715 // collected, since we are way over memory limit.
2716 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2717 DecodeTimestamp::FromMilliseconds(1000)));
2718 CheckExpectedRanges("{ [30,299) }");
2719
2720 // Playback position at 1.1 sec, no new data can be collected, since the
2721 // playback position is still in the first GOP of buffered data.
2722 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2723 DecodeTimestamp::FromMilliseconds(1100)));
2724 CheckExpectedRanges("{ [30,299) }");
2725
2726 // Playback position at 5.166 sec, just at the very end of GOP corresponding
2727 // to buffer range 150-155, which should be preserved.
2728 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2729 DecodeTimestamp::FromMilliseconds(5166)));
2730 CheckExpectedRanges("{ [150,299) }");
2731
2732 // Playback position at 5.167 sec, just past the end of GOP corresponding to
2733 // buffer range 150-155, it should be garbage collected now.
2734 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2735 DecodeTimestamp::FromMilliseconds(5167)));
2736 CheckExpectedRanges("{ [155,299) }");
2737
2738 // Playback at 9.0 sec, we can now successfully collect all data except the
2739 // last second and we are back under memory limit of 30 buffers, so GCIfNeeded
2740 // should return true.
2741 EXPECT_TRUE(stream_->GarbageCollectIfNeeded(
2742 DecodeTimestamp::FromMilliseconds(9000)));
2743 CheckExpectedRanges("{ [270,299) }");
2744
2745 // Playback at 9.999 sec, GC succeeds, since we are under memory limit even
2746 // without removing any data.
2747 EXPECT_TRUE(stream_->GarbageCollectIfNeeded(
2748 DecodeTimestamp::FromMilliseconds(9999)));
2749 CheckExpectedRanges("{ [270,299) }");
2750
2751 // Playback at 15 sec, this should never happen during regular playback in
2752 // browser, since this position has no data buffered, but it should still
2753 // cause no problems to GC algorithm, so test it just in case.
2754 EXPECT_TRUE(stream_->GarbageCollectIfNeeded(
2755 DecodeTimestamp::FromMilliseconds(15000)));
2756 CheckExpectedRanges("{ [270,299) }");
2757 }
2758
2641 // Test saving the last GOP appended when this GOP is the only GOP in its range. 2759 // Test saving the last GOP appended when this GOP is the only GOP in its range.
2642 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP) { 2760 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP) {
2643 // Set memory limit to 3 and make sure the 4-byte GOP is not garbage 2761 // Set memory limit to 3 and make sure the 4-byte GOP is not garbage
2644 // collected. 2762 // collected.
2645 SetMemoryLimit(3); 2763 SetMemoryLimit(3);
2646 NewSegmentAppend("0K 30 60 90"); 2764 NewSegmentAppend("0K 30 60 90");
2765 EXPECT_FALSE(GarbageCollectWithPlaybackAtBuffer(0));
2647 CheckExpectedRangesByTimestamp("{ [0,120) }"); 2766 CheckExpectedRangesByTimestamp("{ [0,120) }");
2648 2767
2649 // Make sure you can continue appending data to this GOP; again, GC should not 2768 // Make sure you can continue appending data to this GOP; again, GC should not
2650 // wipe out anything. 2769 // wipe out anything.
2651 AppendBuffers("120D30"); 2770 AppendBuffers("120D30");
2771 EXPECT_FALSE(GarbageCollectWithPlaybackAtBuffer(0));
2652 CheckExpectedRangesByTimestamp("{ [0,150) }"); 2772 CheckExpectedRangesByTimestamp("{ [0,150) }");
2653 2773
2654 // Set memory limit to 100 and append a 2nd range after this without 2774 // Append a 2nd range after this without triggering GC.
2655 // triggering GC.
2656 SetMemoryLimit(100);
2657 NewSegmentAppend("200K 230 260 290K 320 350"); 2775 NewSegmentAppend("200K 230 260 290K 320 350");
2658 CheckExpectedRangesByTimestamp("{ [0,150) [200,380) }"); 2776 CheckExpectedRangesByTimestamp("{ [0,150) [200,380) }");
2659 2777
2660 // Seek to 290ms. 2778 // Seek to 290ms.
2661 SeekToTimestampMs(290); 2779 SeekToTimestampMs(290);
2662 2780
2663 // Now set memory limit to 3 and append a GOP in a separate range after the 2781 // Now append a GOP in a separate range after the selected range and trigger
2664 // selected range. Because it is after 290ms, this tests that the GOP is saved 2782 // GC. Because it is after 290ms, this tests that the GOP is saved when
2665 // when deleting from the back. 2783 // deleting from the back.
2666 SetMemoryLimit(3);
2667 NewSegmentAppend("500K 530 560 590"); 2784 NewSegmentAppend("500K 530 560 590");
2785 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2786 DecodeTimestamp::FromMilliseconds(290)));
2668 2787
2669 // Should save GOP with 290ms and last GOP appended. 2788 // Should save GOPs between 290ms and the last GOP appended.
2670 CheckExpectedRangesByTimestamp("{ [290,380) [500,620) }"); 2789 CheckExpectedRangesByTimestamp("{ [290,380) [500,620) }");
2671 2790
2672 // Continue appending to this GOP after GC. 2791 // Continue appending to this GOP after GC.
2673 AppendBuffers("620D30"); 2792 AppendBuffers("620D30");
2793 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2794 DecodeTimestamp::FromMilliseconds(290)));
2674 CheckExpectedRangesByTimestamp("{ [290,380) [500,650) }"); 2795 CheckExpectedRangesByTimestamp("{ [290,380) [500,650) }");
2675 } 2796 }
2676 2797
2677 // Test saving the last GOP appended when this GOP is in the middle of a 2798 // Test saving the last GOP appended when this GOP is in the middle of a
2678 // non-selected range. 2799 // non-selected range.
2679 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Middle) { 2800 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Middle) {
2680 // Append 3 GOPs starting at 0ms, 30ms apart. 2801 // Append 3 GOPs starting at 0ms, 30ms apart.
2681 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240"); 2802 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240");
2682 CheckExpectedRangesByTimestamp("{ [0,270) }"); 2803 CheckExpectedRangesByTimestamp("{ [0,270) }");
2683 2804
2684 // Now set the memory limit to 1 and overlap the middle of the range with a 2805 // Now set the memory limit to 1 and overlap the middle of the range with a
2685 // new GOP. 2806 // new GOP.
2686 SetMemoryLimit(1); 2807 SetMemoryLimit(1);
2687 NewSegmentAppend("80K 110 140"); 2808 NewSegmentAppend("80K 110 140");
2688 2809
2689 // This whole GOP should be saved, and should be able to continue appending 2810 // This whole GOP should be saved after GC, which will fail due to GOP being
2690 // data to it. 2811 // larger than 1 buffer
2812 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2813 DecodeTimestamp::FromMilliseconds(80)));
2691 CheckExpectedRangesByTimestamp("{ [80,170) }"); 2814 CheckExpectedRangesByTimestamp("{ [80,170) }");
2815 // We should still be able to continue appending data to GOP
2692 AppendBuffers("170D30"); 2816 AppendBuffers("170D30");
2817 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2818 DecodeTimestamp::FromMilliseconds(80)));
2693 CheckExpectedRangesByTimestamp("{ [80,200) }"); 2819 CheckExpectedRangesByTimestamp("{ [80,200) }");
2694 2820
2695 // Set memory limit to 100 and append a 2nd range after this without 2821 // Append a 2nd range after this range, without triggering GC.
2696 // triggering GC.
2697 SetMemoryLimit(100);
2698 NewSegmentAppend("400K 430 460 490K 520 550 580K 610 640"); 2822 NewSegmentAppend("400K 430 460 490K 520 550 580K 610 640");
2699 CheckExpectedRangesByTimestamp("{ [80,200) [400,670) }"); 2823 CheckExpectedRangesByTimestamp("{ [80,200) [400,670) }");
2700 2824
2701 // Seek to 80ms to make the first range the selected range. 2825 // Seek to 80ms to make the first range the selected range.
2702 SeekToTimestampMs(80); 2826 SeekToTimestampMs(80);
2703 2827
2704 // Now set memory limit to 3 and append a GOP in the middle of the second 2828 // Now append a GOP in the middle of the second range and trigger GC. Because
2705 // range. Because it is after the selected range, this tests that the GOP is 2829 // it is after the selected range, this tests that the GOP is saved when
2706 // saved when deleting from the back. 2830 // deleting from the back.
2707 SetMemoryLimit(3);
2708 NewSegmentAppend("500K 530 560 590"); 2831 NewSegmentAppend("500K 530 560 590");
2832 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2833 DecodeTimestamp::FromMilliseconds(80)));
2709 2834
2710 // Should save the GOP containing the seek point and GOP that was last 2835 // Should save the GOPs between the seek point and GOP that was last appended
2711 // appended. 2836 CheckExpectedRangesByTimestamp("{ [80,200) [400,620) }");
2712 CheckExpectedRangesByTimestamp("{ [80,200) [500,620) }");
2713 2837
2714 // Continue appending to this GOP after GC. 2838 // Continue appending to this GOP after GC.
2715 AppendBuffers("620D30"); 2839 AppendBuffers("620D30");
2716 CheckExpectedRangesByTimestamp("{ [80,200) [500,650) }"); 2840 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2841 DecodeTimestamp::FromMilliseconds(80)));
2842 CheckExpectedRangesByTimestamp("{ [80,200) [400,650) }");
2717 } 2843 }
2718 2844
2719 // Test saving the last GOP appended when the GOP containing the next buffer is 2845 // Test saving the last GOP appended when the GOP containing the next buffer is
2720 // adjacent to the last GOP appended. 2846 // adjacent to the last GOP appended.
2721 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected1) { 2847 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected1) {
2722 // Append 3 GOPs at 0ms, 90ms, and 180ms. 2848 // Append 3 GOPs at 0ms, 90ms, and 180ms.
2723 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240"); 2849 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240");
2724 CheckExpectedRangesByTimestamp("{ [0,270) }"); 2850 CheckExpectedRangesByTimestamp("{ [0,270) }");
2725 2851
2726 // Seek to the GOP at 90ms. 2852 // Seek to the GOP at 90ms.
2727 SeekToTimestampMs(90); 2853 SeekToTimestampMs(90);
2728 2854
2729 // Set the memory limit to 1, then overlap the GOP at 0. 2855 // Set the memory limit to 1, then overlap the GOP at 0.
2730 SetMemoryLimit(1); 2856 SetMemoryLimit(1);
2731 NewSegmentAppend("0K 30 60"); 2857 NewSegmentAppend("0K 30 60");
2732 2858
2733 // Should save the GOP at 0ms and 90ms. 2859 // GC should save the GOP at 0ms and 90ms, and will fail since GOP larger
2860 // than 1 buffer
2861 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2862 DecodeTimestamp::FromMilliseconds(90)));
2734 CheckExpectedRangesByTimestamp("{ [0,180) }"); 2863 CheckExpectedRangesByTimestamp("{ [0,180) }");
2735 2864
2736 // Seek to 0 and check all buffers. 2865 // Seek to 0 and check all buffers.
2737 SeekToTimestampMs(0); 2866 SeekToTimestampMs(0);
2738 CheckExpectedBuffers("0K 30 60 90K 120 150"); 2867 CheckExpectedBuffers("0K 30 60 90K 120 150");
2739 CheckNoNextBuffer(); 2868 CheckNoNextBuffer();
2740 2869
2741 // Now seek back to 90ms and append a GOP at 180ms. 2870 // Now seek back to 90ms and append a GOP at 180ms.
2742 SeekToTimestampMs(90); 2871 SeekToTimestampMs(90);
2743 NewSegmentAppend("180K 210 240"); 2872 NewSegmentAppend("180K 210 240");
2744 2873
2745 // Should save the GOP at 90ms and the GOP at 180ms. 2874 // Should save the GOP at 90ms and the GOP at 180ms.
2875 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2876 DecodeTimestamp::FromMilliseconds(90)));
2746 CheckExpectedRangesByTimestamp("{ [90,270) }"); 2877 CheckExpectedRangesByTimestamp("{ [90,270) }");
2747 CheckExpectedBuffers("90K 120 150 180K 210 240"); 2878 CheckExpectedBuffers("90K 120 150 180K 210 240");
2748 CheckNoNextBuffer(); 2879 CheckNoNextBuffer();
2749 } 2880 }
2750 2881
2751 // Test saving the last GOP appended when it is at the beginning or end of the 2882 // Test saving the last GOP appended when it is at the beginning or end of the
2752 // selected range. This tests when the last GOP appended is before or after the 2883 // selected range. This tests when the last GOP appended is before or after the
2753 // GOP containing the next buffer, but not directly adjacent to this GOP. 2884 // GOP containing the next buffer, but not directly adjacent to this GOP.
2754 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected2) { 2885 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected2) {
2755 // Append 4 GOPs starting at positions 0ms, 90ms, 180ms, 270ms. 2886 // Append 4 GOPs starting at positions 0ms, 90ms, 180ms, 270ms.
2756 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240 270K 300 330"); 2887 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240 270K 300 330");
2757 CheckExpectedRangesByTimestamp("{ [0,360) }"); 2888 CheckExpectedRangesByTimestamp("{ [0,360) }");
2758 2889
2759 // Seek to the last GOP at 270ms. 2890 // Seek to the last GOP at 270ms.
2760 SeekToTimestampMs(270); 2891 SeekToTimestampMs(270);
2761 2892
2762 // Set the memory limit to 1, then overlap the GOP at 90ms. 2893 // Set the memory limit to 1, then overlap the GOP at 90ms.
2763 SetMemoryLimit(1); 2894 SetMemoryLimit(1);
2764 NewSegmentAppend("90K 120 150"); 2895 NewSegmentAppend("90K 120 150");
2765 2896
2766 // Should save the GOP at 90ms and the GOP at 270ms. 2897 // GC will save data in the range where the most recent append has happened
2767 CheckExpectedRangesByTimestamp("{ [90,180) [270,360) }"); 2898 // [0; 180) and the range where the next read position is [270;360)
2899 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2900 DecodeTimestamp::FromMilliseconds(270)));
2901 CheckExpectedRangesByTimestamp("{ [0,180) [270,360) }");
2768 2902
2769 // Set memory limit to 100 and add 3 GOPs to the end of the selected range 2903 // Add 3 GOPs to the end of the selected range at 360ms, 450ms, and 540ms.
2770 // at 360ms, 450ms, and 540ms.
2771 SetMemoryLimit(100);
2772 NewSegmentAppend("360K 390 420 450K 480 510 540K 570 600"); 2904 NewSegmentAppend("360K 390 420 450K 480 510 540K 570 600");
2773 CheckExpectedRangesByTimestamp("{ [90,180) [270,630) }"); 2905 CheckExpectedRangesByTimestamp("{ [0,180) [270,630) }");
2774 2906
2775 // Constrain the memory limit again and overlap the GOP at 450ms to test 2907 // Overlap the GOP at 450ms and garbage collect to test deleting from the
2776 // deleting from the back. 2908 // back.
2777 SetMemoryLimit(1);
2778 NewSegmentAppend("450K 480 510"); 2909 NewSegmentAppend("450K 480 510");
2910 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2911 DecodeTimestamp::FromMilliseconds(270)));
2779 2912
2780 // Should save GOP at 270ms and the GOP at 450ms. 2913 // Should save GOPs from GOP at 270ms to GOP at 450ms.
2781 CheckExpectedRangesByTimestamp("{ [270,360) [450,540) }"); 2914 CheckExpectedRangesByTimestamp("{ [270,540) }");
2782 } 2915 }
2783 2916
2784 // Test saving the last GOP appended when it is the same as the GOP containing 2917 // Test saving the last GOP appended when it is the same as the GOP containing
2785 // the next buffer. 2918 // the next buffer.
2786 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected3) { 2919 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected3) {
2787 // Seek to start of stream. 2920 // Seek to start of stream.
2788 SeekToTimestampMs(0); 2921 SeekToTimestampMs(0);
2789 2922
2790 // Append 3 GOPs starting at 0ms, 90ms, 180ms. 2923 // Append 3 GOPs starting at 0ms, 90ms, 180ms.
2791 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240"); 2924 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240");
2792 CheckExpectedRangesByTimestamp("{ [0,270) }"); 2925 CheckExpectedRangesByTimestamp("{ [0,270) }");
2793 2926
2794 // Set the memory limit to 1 then begin appending the start of a GOP starting 2927 // Set the memory limit to 1 then begin appending the start of a GOP starting
2795 // at 0ms. 2928 // at 0ms.
2796 SetMemoryLimit(1); 2929 SetMemoryLimit(1);
2797 NewSegmentAppend("0K 30"); 2930 NewSegmentAppend("0K 30");
2798 2931
2799 // Should save the newly appended GOP, which is also the next GOP that will be 2932 // GC should save the newly appended GOP, which is also the next GOP that
2800 // returned from the seek request. 2933 // will be returned from the seek request.
2934 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2935 DecodeTimestamp::FromMilliseconds(0)));
2801 CheckExpectedRangesByTimestamp("{ [0,60) }"); 2936 CheckExpectedRangesByTimestamp("{ [0,60) }");
2802 2937
2803 // Check the buffers in the range. 2938 // Check the buffers in the range.
2804 CheckExpectedBuffers("0K 30"); 2939 CheckExpectedBuffers("0K 30");
2805 CheckNoNextBuffer(); 2940 CheckNoNextBuffer();
2806 2941
2807 // Continue appending to this buffer. 2942 // Continue appending to this buffer.
2808 AppendBuffers("60 90"); 2943 AppendBuffers("60 90");
2809 2944
2810 // Should still save the rest of this GOP and should be able to fulfill the 2945 // GC should still save the rest of this GOP and should be able to fulfill
2811 // read. 2946 // the read.
2947 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(
2948 DecodeTimestamp::FromMilliseconds(0)));
2812 CheckExpectedRangesByTimestamp("{ [0,120) }"); 2949 CheckExpectedRangesByTimestamp("{ [0,120) }");
2813 CheckExpectedBuffers("60 90"); 2950 CheckExpectedBuffers("60 90");
2814 CheckNoNextBuffer(); 2951 CheckNoNextBuffer();
2815 } 2952 }
2816 2953
2817 // Currently disabled because of bug: crbug.com/140875. 2954 // Currently disabled because of bug: crbug.com/140875.
2818 TEST_F(SourceBufferStreamTest, DISABLED_GarbageCollection_WaitingForKeyframe) { 2955 TEST_F(SourceBufferStreamTest, DISABLED_GarbageCollection_WaitingForKeyframe) {
2819 // Set memory limit to 10 buffers. 2956 // Set memory limit to 10 buffers.
2820 SetMemoryLimit(10); 2957 SetMemoryLimit(10);
2821 2958
(...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after
4285 CheckVideoConfig(new_config); 4422 CheckVideoConfig(new_config);
4286 } 4423 }
4287 4424
4288 // TODO(vrk): Add unit tests where keyframes are unaligned between streams. 4425 // TODO(vrk): Add unit tests where keyframes are unaligned between streams.
4289 // (crbug.com/133557) 4426 // (crbug.com/133557)
4290 4427
4291 // TODO(vrk): Add unit tests with end of stream being called at interesting 4428 // TODO(vrk): Add unit tests with end of stream being called at interesting
4292 // times. 4429 // times.
4293 4430
4294 } // namespace media 4431 } // namespace media
OLDNEW
« media/filters/source_buffer_stream.cc ('K') | « media/filters/source_buffer_stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698