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