| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 137 } |
| 138 | 138 |
| 139 void Seek(int position) { | 139 void Seek(int position) { |
| 140 stream_->Seek(position * frame_duration_); | 140 stream_->Seek(position * frame_duration_); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void SeekToTimestamp(base::TimeDelta timestamp) { | 143 void SeekToTimestamp(base::TimeDelta timestamp) { |
| 144 stream_->Seek(timestamp); | 144 stream_->Seek(timestamp); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void GarbageCollect_ExpectSuccess() { |
| 148 EXPECT_TRUE(stream_->GarbageCollectIfNeeded(kNoDecodeTimestamp())); |
| 149 } |
| 150 |
| 151 void GarbageCollect_ExpectFull() { |
| 152 EXPECT_FALSE(stream_->GarbageCollectIfNeeded(kNoDecodeTimestamp())); |
| 153 } |
| 154 |
| 147 void RemoveInMs(int start, int end, int duration) { | 155 void RemoveInMs(int start, int end, int duration) { |
| 148 Remove(base::TimeDelta::FromMilliseconds(start), | 156 Remove(base::TimeDelta::FromMilliseconds(start), |
| 149 base::TimeDelta::FromMilliseconds(end), | 157 base::TimeDelta::FromMilliseconds(end), |
| 150 base::TimeDelta::FromMilliseconds(duration)); | 158 base::TimeDelta::FromMilliseconds(duration)); |
| 151 } | 159 } |
| 152 | 160 |
| 153 void Remove(base::TimeDelta start, base::TimeDelta end, | 161 void Remove(base::TimeDelta start, base::TimeDelta end, |
| 154 base::TimeDelta duration) { | 162 base::TimeDelta duration) { |
| 155 stream_->Remove(start, end, duration); | 163 stream_->Remove(start, end, duration); |
| 156 } | 164 } |
| (...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2322 | 2330 |
| 2323 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteFront) { | 2331 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteFront) { |
| 2324 // Set memory limit to 20 buffers. | 2332 // Set memory limit to 20 buffers. |
| 2325 SetMemoryLimit(20); | 2333 SetMemoryLimit(20); |
| 2326 | 2334 |
| 2327 // Append 20 buffers at positions 0 through 19. | 2335 // Append 20 buffers at positions 0 through 19. |
| 2328 NewSegmentAppend(0, 1, &kDataA); | 2336 NewSegmentAppend(0, 1, &kDataA); |
| 2329 for (int i = 1; i < 20; i++) | 2337 for (int i = 1; i < 20; i++) |
| 2330 AppendBuffers(i, 1, &kDataA); | 2338 AppendBuffers(i, 1, &kDataA); |
| 2331 | 2339 |
| 2340 GarbageCollect_ExpectSuccess(); |
| 2341 |
| 2332 // None of the buffers should trigger garbage collection, so all data should | 2342 // None of the buffers should trigger garbage collection, so all data should |
| 2333 // be there as expected. | 2343 // be there as expected. |
| 2334 CheckExpectedRanges("{ [0,19) }"); | 2344 CheckExpectedRanges("{ [0,19) }"); |
| 2335 Seek(0); | 2345 Seek(0); |
| 2336 CheckExpectedBuffers(0, 19, &kDataA); | 2346 CheckExpectedBuffers(0, 19, &kDataA); |
| 2337 | 2347 |
| 2338 // Seek to the middle of the stream. | 2348 // Seek to the middle of the stream. |
| 2339 Seek(10); | 2349 Seek(10); |
| 2340 | 2350 |
| 2341 // Append 5 buffers to the end of the stream. | 2351 // Append 5 buffers to the end of the stream. |
| 2342 AppendBuffers(20, 5, &kDataA); | 2352 AppendBuffers(20, 5, &kDataA); |
| 2343 | 2353 |
| 2354 // Run garbage collection |
| 2355 GarbageCollect_ExpectSuccess(); |
| 2356 |
| 2344 // GC should have deleted the first 5 buffers. | 2357 // GC should have deleted the first 5 buffers. |
| 2345 CheckExpectedRanges("{ [5,24) }"); | 2358 CheckExpectedRanges("{ [5,24) }"); |
| 2346 CheckExpectedBuffers(10, 24, &kDataA); | 2359 CheckExpectedBuffers(10, 24, &kDataA); |
| 2347 Seek(5); | 2360 Seek(5); |
| 2348 CheckExpectedBuffers(5, 9, &kDataA); | 2361 CheckExpectedBuffers(5, 9, &kDataA); |
| 2349 } | 2362 } |
| 2350 | 2363 |
| 2351 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteFrontGOPsAtATime) { | 2364 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteFrontGOPsAtATime) { |
| 2352 // Set memory limit to 20 buffers. | 2365 // Set memory limit to 20 buffers. |
| 2353 SetMemoryLimit(20); | 2366 SetMemoryLimit(20); |
| 2354 | 2367 |
| 2355 // Append 20 buffers at positions 0 through 19. | 2368 // Append 20 buffers at positions 0 through 19. |
| 2356 NewSegmentAppend(0, 20, &kDataA); | 2369 NewSegmentAppend(0, 20, &kDataA); |
| 2357 | 2370 |
| 2358 // Seek to position 10. | 2371 // Seek to position 10. |
| 2359 Seek(10); | 2372 Seek(10); |
| 2360 | 2373 |
| 2361 // Add one buffer to put the memory over the cap. | 2374 // Add one buffer to put the memory over the cap. |
| 2362 AppendBuffers(20, 1, &kDataA); | 2375 AppendBuffers(20, 1, &kDataA); |
| 2363 | 2376 |
| 2377 GarbageCollect_ExpectSuccess(); |
| 2378 |
| 2364 // GC should have deleted the first 5 buffers so that the range still begins | 2379 // GC should have deleted the first 5 buffers so that the range still begins |
| 2365 // with a keyframe. | 2380 // with a keyframe. |
| 2366 CheckExpectedRanges("{ [5,20) }"); | 2381 CheckExpectedRanges("{ [5,20) }"); |
| 2367 CheckExpectedBuffers(10, 20, &kDataA); | 2382 CheckExpectedBuffers(10, 20, &kDataA); |
| 2368 Seek(5); | 2383 Seek(5); |
| 2369 CheckExpectedBuffers(5, 9, &kDataA); | 2384 CheckExpectedBuffers(5, 9, &kDataA); |
| 2370 } | 2385 } |
| 2371 | 2386 |
| 2372 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteBack) { | 2387 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteBack) { |
| 2373 // Set memory limit to 5 buffers. | 2388 // Set memory limit to 10 buffers. |
| 2374 SetMemoryLimit(5); | 2389 SetMemoryLimit(10); |
| 2375 | 2390 |
| 2376 // Seek to position 0. | 2391 // Seek to position 0. |
| 2377 Seek(0); | 2392 Seek(0); |
| 2378 | 2393 |
| 2379 // Append 20 buffers at positions 0 through 19. | 2394 // Append 20 buffers at positions 0 through 19. |
| 2380 NewSegmentAppend(0, 20, &kDataA); | 2395 NewSegmentAppend(0, 5, &kDataA); |
| 2396 NewSegmentAppend(10, 10, &kDataA); |
| 2397 // GC gaurantees we keep all buffers between current seek and last append. |
| 2398 // Therefore, append buffers at positions 5 to 9 last so that we are allowed |
| 2399 // to collect buffers 10 to 19 (since they are now after last append) |
| 2400 NewSegmentAppend(5, 5, &kDataA); |
| 2401 |
| 2402 // Check we have all the buffers |
| 2403 CheckExpectedRanges("{ [0,19) }"); |
| 2404 |
| 2405 // Run garbage collection |
| 2406 GarbageCollect_ExpectSuccess(); |
| 2381 | 2407 |
| 2382 // Should leave the first 5 buffers from 0 to 4 and the last GOP appended. | 2408 // Should leave the first 5 buffers from 0 to 4 and the last GOP appended. |
| 2383 CheckExpectedRanges("{ [0,4) [15,19) }"); | 2409 CheckExpectedRanges("{ [0,9) }"); |
| 2384 CheckExpectedBuffers(0, 4, &kDataA); | 2410 |
| 2411 // Check that GC refuses to collect last append |
| 2412 SetMemoryLimit(5); |
| 2413 GarbageCollect_ExpectFull(); |
| 2414 |
| 2415 // Should leave the prior buffers untouched |
| 2416 CheckExpectedRanges("{ [0,9) }"); |
| 2417 CheckExpectedBuffers(0, 9, &kDataA); |
| 2418 CheckNoNextBuffer(); |
| 2385 } | 2419 } |
| 2386 | 2420 |
| 2387 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteFrontAndBack) { | 2421 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteFrontAndBack) { |
| 2388 // Set memory limit to 3 buffers. | 2422 // Set memory limit to 3 buffers. |
| 2389 SetMemoryLimit(3); | 2423 SetMemoryLimit(3); |
| 2390 | 2424 |
| 2391 // Seek to position 15. | 2425 // Seek to position 15. |
| 2392 Seek(15); | 2426 Seek(15); |
| 2393 | 2427 |
| 2394 // Append 40 buffers at positions 0 through 39. | 2428 // Append 40 buffers at positions 0 through 39 |
| 2395 NewSegmentAppend(0, 40, &kDataA); | 2429 NewSegmentAppend(0, 20, &kDataA); |
| 2430 NewSegmentAppend(25, 15, &kDataA); |
| 2431 // GC gaurantees we keep all buffers between current seek and last append. |
| 2432 // Therefore, append buffers at positions 20 to 24 last so that we are allowed |
| 2433 // to collect buffers after 24 |
| 2434 NewSegmentAppend(20, 5, &kDataA); |
| 2435 |
| 2436 // Check we have all the buffers |
| 2437 CheckExpectedRanges("{ [0,39) }"); |
| 2438 |
| 2439 // Garbage collect will fail, cannot reduce to 3 buffers |
| 2440 GarbageCollect_ExpectFull(); |
| 2396 | 2441 |
| 2397 // Should leave the GOP containing the seek position and the last GOP | 2442 // Should leave the GOP containing the seek position and the last GOP |
| 2398 // appended. | 2443 // appended. |
| 2399 CheckExpectedRanges("{ [15,19) [35,39) }"); | 2444 CheckExpectedRanges("{ [15,24) }"); |
| 2400 CheckExpectedBuffers(15, 19, &kDataA); | 2445 CheckExpectedBuffers(15, 24, &kDataA); |
| 2401 CheckNoNextBuffer(); | 2446 CheckNoNextBuffer(); |
| 2402 } | 2447 } |
| 2403 | 2448 |
| 2404 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteSeveralRanges) { | 2449 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteSeveralRanges) { |
| 2405 // Append 5 buffers at positions 0 through 4. | 2450 // Append 5 buffers at positions 0 through 4. |
| 2406 NewSegmentAppend(0, 5); | 2451 NewSegmentAppend(0, 5); |
| 2407 | 2452 |
| 2408 // Append 5 buffers at positions 10 through 14. | 2453 // Append 5 buffers at positions 10 through 14. |
| 2409 NewSegmentAppend(10, 5); | 2454 NewSegmentAppend(10, 5); |
| 2410 | 2455 |
| 2411 // Append 5 buffers at positions 20 through 24. | 2456 // Append 5 buffers at positions 20 through 24. |
| 2412 NewSegmentAppend(20, 5); | 2457 NewSegmentAppend(20, 5); |
| 2413 | 2458 |
| 2414 // Append 5 buffers at positions 30 through 34. | 2459 // Append 5 buffers at positions 40 through 44. |
| 2415 NewSegmentAppend(30, 5); | 2460 NewSegmentAppend(40, 5); |
| 2416 | 2461 |
| 2417 CheckExpectedRanges("{ [0,4) [10,14) [20,24) [30,34) }"); | 2462 CheckExpectedRanges("{ [0,4) [10,14) [20,24) [40,44) }"); |
| 2418 | 2463 |
| 2419 // Seek to position 21. | 2464 // Seek to position 21. |
| 2420 Seek(20); | 2465 Seek(20); |
| 2421 CheckExpectedBuffers(20, 20); | 2466 CheckExpectedBuffers(20, 20); |
| 2422 | 2467 |
| 2423 // Set memory limit to 1 buffer. | 2468 // Set memory limit to 1 buffer. |
| 2424 SetMemoryLimit(1); | 2469 SetMemoryLimit(1); |
| 2425 | 2470 |
| 2426 // Append 5 buffers at positions 40 through 44. This will trigger GC. | 2471 // Append 5 buffers at positions 40 through 44. |
| 2427 NewSegmentAppend(40, 5); | 2472 NewSegmentAppend(30, 5); |
| 2428 | 2473 |
| 2429 // Should delete everything except the GOP containing the current buffer and | 2474 // We will have more than 1 buffer left, GC will fail |
| 2430 // the last GOP appended. | 2475 GarbageCollect_ExpectFull(); |
| 2431 CheckExpectedRanges("{ [20,24) [40,44) }"); | 2476 |
| 2477 // Should have deleted all buffer ranges before the current buffer and after |
| 2478 // last GOP |
| 2479 CheckExpectedRanges("{ [20,24) [30,34) }"); |
| 2432 CheckExpectedBuffers(21, 24); | 2480 CheckExpectedBuffers(21, 24); |
| 2433 CheckNoNextBuffer(); | 2481 CheckNoNextBuffer(); |
| 2434 | 2482 |
| 2435 // Continue appending into the last range to make sure it didn't break. | 2483 // Continue appending into the last range to make sure it didn't break. |
| 2436 AppendBuffers(45, 10); | 2484 AppendBuffers(35, 10); |
| 2437 // Should only save last GOP appended. | 2485 GarbageCollect_ExpectFull(); |
| 2438 CheckExpectedRanges("{ [20,24) [50,54) }"); | 2486 // Should save everything between read head and last appended |
| 2487 CheckExpectedRanges("{ [20,24) [30,44) }"); |
| 2439 | 2488 |
| 2440 // Make sure appending before and after the ranges didn't somehow break. | 2489 // Make sure appending before and after the ranges didn't somehow break. |
| 2441 SetMemoryLimit(100); | 2490 SetMemoryLimit(100); |
| 2442 NewSegmentAppend(0, 10); | 2491 NewSegmentAppend(0, 10); |
| 2443 CheckExpectedRanges("{ [0,9) [20,24) [50,54) }"); | 2492 GarbageCollect_ExpectSuccess(); |
| 2493 CheckExpectedRanges("{ [0,9) [20,24) [30,44) }"); |
| 2444 Seek(0); | 2494 Seek(0); |
| 2445 CheckExpectedBuffers(0, 9); | 2495 CheckExpectedBuffers(0, 9); |
| 2446 | 2496 |
| 2447 NewSegmentAppend(90, 10); | 2497 NewSegmentAppend(90, 10); |
| 2448 CheckExpectedRanges("{ [0,9) [20,24) [50,54) [90,99) }"); | 2498 GarbageCollect_ExpectSuccess(); |
| 2449 Seek(50); | 2499 CheckExpectedRanges("{ [0,9) [20,24) [30,44) [90,99) }"); |
| 2450 CheckExpectedBuffers(50, 54); | 2500 Seek(30); |
| 2501 CheckExpectedBuffers(30, 44); |
| 2451 CheckNoNextBuffer(); | 2502 CheckNoNextBuffer(); |
| 2452 Seek(90); | 2503 Seek(90); |
| 2453 CheckExpectedBuffers(90, 99); | 2504 CheckExpectedBuffers(90, 99); |
| 2454 CheckNoNextBuffer(); | 2505 CheckNoNextBuffer(); |
| 2455 } | 2506 } |
| 2456 | 2507 |
| 2457 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteAfterLastAppend) { | 2508 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteAfterLastAppend) { |
| 2458 // Set memory limit to 10 buffers. | 2509 // Set memory limit to 10 buffers. |
| 2459 SetMemoryLimit(10); | 2510 SetMemoryLimit(10); |
| 2460 | 2511 |
| 2461 // Append 1 GOP starting at 310ms, 30ms apart. | 2512 // Append 1 GOP starting at 310ms, 30ms apart. |
| 2462 NewSegmentAppend("310K 340 370"); | 2513 NewSegmentAppend("310K 340 370"); |
| 2463 | 2514 |
| 2464 // Append 2 GOPs starting at 490ms, 30ms apart. | 2515 // Append 2 GOPs starting at 490ms, 30ms apart. |
| 2465 NewSegmentAppend("490K 520 550 580K 610 640"); | 2516 NewSegmentAppend("490K 520 550 580K 610 640"); |
| 2466 | 2517 |
| 2518 GarbageCollect_ExpectSuccess(); |
| 2519 |
| 2467 CheckExpectedRangesByTimestamp("{ [310,400) [490,670) }"); | 2520 CheckExpectedRangesByTimestamp("{ [310,400) [490,670) }"); |
| 2468 | 2521 |
| 2469 // Seek to the GOP at 580ms. | 2522 // Seek to the GOP at 580ms. |
| 2470 SeekToTimestamp(base::TimeDelta::FromMilliseconds(580)); | 2523 SeekToTimestamp(base::TimeDelta::FromMilliseconds(580)); |
| 2471 | 2524 |
| 2472 // Append 2 GOPs before the existing ranges. | 2525 // Append 2 GOPs before the existing ranges. |
| 2473 // So the ranges before GC are "{ [100,280) [310,400) [490,670) }". | 2526 // So the ranges before GC are "{ [100,280) [310,400) [490,670) }". |
| 2474 NewSegmentAppend("100K 130 160 190K 220 250K"); | 2527 NewSegmentAppend("100K 130 160 190K 220 250K"); |
| 2475 | 2528 |
| 2529 GarbageCollect_ExpectSuccess(); |
| 2530 |
| 2476 // Should save the newly appended GOPs. | 2531 // Should save the newly appended GOPs. |
| 2477 CheckExpectedRangesByTimestamp("{ [100,280) [580,670) }"); | 2532 CheckExpectedRangesByTimestamp("{ [100,280) [580,670) }"); |
| 2478 } | 2533 } |
| 2479 | 2534 |
| 2480 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteAfterLastAppendMerged) { | 2535 TEST_F(SourceBufferStreamTest, GarbageCollection_DeleteAfterLastAppendMerged) { |
| 2481 // Set memory limit to 10 buffers. | 2536 // Set memory limit to 10 buffers. |
| 2482 SetMemoryLimit(10); | 2537 SetMemoryLimit(10); |
| 2483 | 2538 |
| 2484 // Append 3 GOPs starting at 400ms, 30ms apart. | 2539 // Append 3 GOPs starting at 400ms, 30ms apart. |
| 2485 NewSegmentAppend("400K 430 460 490K 520 550 580K 610 640"); | 2540 NewSegmentAppend("400K 430 460 490K 520 550 580K 610 640"); |
| 2486 | 2541 |
| 2487 // Seek to the GOP at 580ms. | 2542 // Seek to the GOP at 580ms. |
| 2488 SeekToTimestamp(base::TimeDelta::FromMilliseconds(580)); | 2543 SeekToTimestamp(base::TimeDelta::FromMilliseconds(580)); |
| 2489 | 2544 |
| 2490 // Append 2 GOPs starting at 220ms, and they will be merged with the existing | 2545 // Append 2 GOPs starting at 220ms, and they will be merged with the existing |
| 2491 // range. So the range before GC is "{ [220,670) }". | 2546 // range. So the range before GC is "{ [220,670) }". |
| 2492 NewSegmentAppend("220K 250 280 310K 340 370"); | 2547 NewSegmentAppend("220K 250 280 310K 340 370"); |
| 2493 | 2548 |
| 2549 GarbageCollect_ExpectSuccess(); |
| 2550 |
| 2494 // Should save the newly appended GOPs. | 2551 // Should save the newly appended GOPs. |
| 2495 CheckExpectedRangesByTimestamp("{ [220,400) [580,670) }"); | 2552 CheckExpectedRangesByTimestamp("{ [220,400) [580,670) }"); |
| 2496 } | 2553 } |
| 2497 | 2554 |
| 2498 TEST_F(SourceBufferStreamTest, GarbageCollection_NoSeek) { | 2555 TEST_F(SourceBufferStreamTest, GarbageCollection_NoSeek) { |
| 2499 // Set memory limit to 20 buffers. | 2556 // Set memory limit to 20 buffers. |
| 2500 SetMemoryLimit(20); | 2557 SetMemoryLimit(20); |
| 2501 | 2558 |
| 2502 // Append 25 buffers at positions 0 through 24. | 2559 // Append 25 buffers at positions 0 through 24. |
| 2503 NewSegmentAppend(0, 25, &kDataA); | 2560 NewSegmentAppend(0, 25, &kDataA); |
| 2504 | 2561 |
| 2562 GarbageCollect_ExpectSuccess(); |
| 2563 |
| 2505 // GC deletes the first 5 buffers to keep the memory limit within cap. | 2564 // GC deletes the first 5 buffers to keep the memory limit within cap. |
| 2506 CheckExpectedRanges("{ [5,24) }"); | 2565 CheckExpectedRanges("{ [5,24) }"); |
| 2507 CheckNoNextBuffer(); | 2566 CheckNoNextBuffer(); |
| 2508 Seek(5); | 2567 Seek(5); |
| 2509 CheckExpectedBuffers(5, 24, &kDataA); | 2568 CheckExpectedBuffers(5, 24, &kDataA); |
| 2510 } | 2569 } |
| 2511 | 2570 |
| 2512 TEST_F(SourceBufferStreamTest, GarbageCollection_PendingSeek) { | 2571 TEST_F(SourceBufferStreamTest, GarbageCollection_PendingSeek) { |
| 2513 // Append 10 buffers at positions 0 through 9. | 2572 // Append 10 buffers at positions 0 through 9. |
| 2514 NewSegmentAppend(0, 10, &kDataA); | 2573 NewSegmentAppend(0, 10, &kDataA); |
| 2515 | 2574 |
| 2516 // Append 5 buffers at positions 25 through 29. | 2575 // Append 5 buffers at positions 25 through 29. |
| 2517 NewSegmentAppend(25, 5, &kDataA); | 2576 NewSegmentAppend(25, 5, &kDataA); |
| 2518 | 2577 |
| 2519 // Seek to position 15. | 2578 // Seek to position 15. |
| 2520 Seek(15); | 2579 Seek(15); |
| 2521 CheckNoNextBuffer(); | 2580 CheckNoNextBuffer(); |
| 2522 | 2581 |
| 2582 GarbageCollect_ExpectSuccess(); |
| 2583 |
| 2523 CheckExpectedRanges("{ [0,9) [25,29) }"); | 2584 CheckExpectedRanges("{ [0,9) [25,29) }"); |
| 2524 | 2585 |
| 2525 // Set memory limit to 5 buffers. | 2586 // Set memory limit to 5 buffers. |
| 2526 SetMemoryLimit(5); | 2587 SetMemoryLimit(5); |
| 2527 | 2588 |
| 2528 // Append 5 buffers as positions 30 to 34 to trigger GC. | 2589 // Append 5 buffers as positions 30 to 34 to trigger GC. |
| 2529 AppendBuffers(30, 5, &kDataA); | 2590 AppendBuffers(30, 5, &kDataA); |
| 2530 | 2591 |
| 2592 GarbageCollect_ExpectSuccess(); |
| 2593 |
| 2531 // The current algorithm will delete from the beginning until the memory is | 2594 // The current algorithm will delete from the beginning until the memory is |
| 2532 // under cap. | 2595 // under cap. |
| 2533 CheckExpectedRanges("{ [30,34) }"); | 2596 CheckExpectedRanges("{ [30,34) }"); |
| 2534 | 2597 |
| 2535 // Expand memory limit again so that GC won't be triggered. | 2598 // Expand memory limit again so that GC won't be triggered. |
| 2536 SetMemoryLimit(100); | 2599 SetMemoryLimit(100); |
| 2537 | 2600 |
| 2538 // Append data to fulfill seek. | 2601 // Append data to fulfill seek. |
| 2539 NewSegmentAppend(15, 5, &kDataA); | 2602 NewSegmentAppend(15, 5, &kDataA); |
| 2540 | 2603 |
| 2604 GarbageCollect_ExpectSuccess(); |
| 2605 |
| 2541 // Check to make sure all is well. | 2606 // Check to make sure all is well. |
| 2542 CheckExpectedRanges("{ [15,19) [30,34) }"); | 2607 CheckExpectedRanges("{ [15,19) [30,34) }"); |
| 2543 CheckExpectedBuffers(15, 19, &kDataA); | 2608 CheckExpectedBuffers(15, 19, &kDataA); |
| 2544 Seek(30); | 2609 Seek(30); |
| 2545 CheckExpectedBuffers(30, 34, &kDataA); | 2610 CheckExpectedBuffers(30, 34, &kDataA); |
| 2546 } | 2611 } |
| 2547 | 2612 |
| 2548 TEST_F(SourceBufferStreamTest, GarbageCollection_NeedsMoreData) { | 2613 TEST_F(SourceBufferStreamTest, GarbageCollection_NeedsMoreData) { |
| 2549 // Set memory limit to 15 buffers. | 2614 // Set memory limit to 15 buffers. |
| 2550 SetMemoryLimit(15); | 2615 SetMemoryLimit(15); |
| 2551 | 2616 |
| 2552 // Append 10 buffers at positions 0 through 9. | 2617 // Append 10 buffers at positions 0 through 9. |
| 2553 NewSegmentAppend(0, 10, &kDataA); | 2618 NewSegmentAppend(0, 10, &kDataA); |
| 2554 | 2619 |
| 2555 // Advance next buffer position to 10. | 2620 // Advance next buffer position to 10. |
| 2556 Seek(0); | 2621 Seek(0); |
| 2622 GarbageCollect_ExpectSuccess(); |
| 2557 CheckExpectedBuffers(0, 9, &kDataA); | 2623 CheckExpectedBuffers(0, 9, &kDataA); |
| 2558 CheckNoNextBuffer(); | 2624 CheckNoNextBuffer(); |
| 2559 | 2625 |
| 2560 // Append 20 buffers at positions 15 through 34. | 2626 // Append 20 buffers at positions 15 through 34. |
| 2561 NewSegmentAppend(15, 20, &kDataA); | 2627 NewSegmentAppend(15, 20, &kDataA); |
| 2562 | 2628 |
| 2563 // GC should have saved the keyframe before the current seek position and the | 2629 // GC should save the keyframe before the current seek position and the data |
| 2564 // data closest to the current seek position. It will also save the last GOP | 2630 // closest to the current seek position. It will also save all buffers from |
| 2565 // appended. | 2631 // current seek to the last GOP appended, which overflows limit and leads to |
| 2566 CheckExpectedRanges("{ [5,9) [15,19) [30,34) }"); | 2632 // failure. |
| 2633 GarbageCollect_ExpectFull(); |
| 2634 CheckExpectedRanges("{ [5,9) [15,34) }"); |
| 2567 | 2635 |
| 2568 // Now fulfill the seek at position 10. This will make GC delete the data | 2636 // Now fulfill the seek at position 10. This will make GC delete the data |
| 2569 // before position 10 to keep it within cap. | 2637 // before position 10 to keep it within cap. |
| 2570 NewSegmentAppend(10, 5, &kDataA); | 2638 NewSegmentAppend(10, 5, &kDataA); |
| 2571 CheckExpectedRanges("{ [10,19) [30,34) }"); | 2639 GarbageCollect_ExpectSuccess(); |
| 2572 CheckExpectedBuffers(10, 19, &kDataA); | 2640 CheckExpectedRanges("{ [10,24) }"); |
| 2641 CheckExpectedBuffers(10, 24, &kDataA); |
| 2573 } | 2642 } |
| 2574 | 2643 |
| 2575 TEST_F(SourceBufferStreamTest, GarbageCollection_TrackBuffer) { | 2644 TEST_F(SourceBufferStreamTest, GarbageCollection_TrackBuffer) { |
| 2576 // Set memory limit to 3 buffers. | 2645 // Set memory limit to 3 buffers. |
| 2577 SetMemoryLimit(3); | 2646 SetMemoryLimit(3); |
| 2578 | 2647 |
| 2579 // Seek to position 15. | 2648 // Seek to position 15. |
| 2580 Seek(15); | 2649 Seek(15); |
| 2581 | 2650 |
| 2582 // Append 18 buffers at positions 0 through 17. | 2651 // Append 18 buffers at positions 0 through 17. |
| 2583 NewSegmentAppend(0, 18, &kDataA); | 2652 NewSegmentAppend(0, 18, &kDataA); |
| 2584 | 2653 |
| 2654 GarbageCollect_ExpectSuccess(); |
| 2655 |
| 2585 // Should leave GOP containing seek position. | 2656 // Should leave GOP containing seek position. |
| 2586 CheckExpectedRanges("{ [15,17) }"); | 2657 CheckExpectedRanges("{ [15,17) }"); |
| 2587 | 2658 |
| 2588 // Seek ahead to position 16. | 2659 // Seek ahead to position 16. |
| 2589 CheckExpectedBuffers(15, 15, &kDataA); | 2660 CheckExpectedBuffers(15, 15, &kDataA); |
| 2590 | 2661 |
| 2591 // Completely overlap the existing buffers. | 2662 // Completely overlap the existing buffers. |
| 2592 NewSegmentAppend(0, 20, &kDataB); | 2663 NewSegmentAppend(0, 20, &kDataB); |
| 2593 | 2664 |
| 2665 // 4 buffers in final GOP, which is more than 3 buffers left in buffer, so GC |
| 2666 // will fail |
| 2667 GarbageCollect_ExpectFull(); |
| 2668 |
| 2594 // Because buffers 16 and 17 are not keyframes, they are moved to the track | 2669 // Because buffers 16 and 17 are not keyframes, they are moved to the track |
| 2595 // buffer upon overlap. The source buffer (i.e. not the track buffer) is now | 2670 // buffer upon overlap. The source buffer (i.e. not the track buffer) is now |
| 2596 // waiting for the next keyframe. | 2671 // waiting for the next keyframe. |
| 2597 CheckExpectedRanges("{ [15,19) }"); | 2672 CheckExpectedRanges("{ [15,19) }"); |
| 2598 CheckExpectedBuffers(16, 17, &kDataA); | 2673 CheckExpectedBuffers(16, 17, &kDataA); |
| 2599 CheckNoNextBuffer(); | 2674 CheckNoNextBuffer(); |
| 2600 | 2675 |
| 2601 // Now add a keyframe at position 20. | 2676 // Now add a keyframe at position 20. |
| 2602 AppendBuffers(20, 5, &kDataB); | 2677 AppendBuffers(20, 5, &kDataB); |
| 2603 | 2678 |
| 2679 // 5 buffers in final GOP, GC will fail |
| 2680 GarbageCollect_ExpectFull(); |
| 2681 |
| 2604 // Should garbage collect such that there are 5 frames remaining, starting at | 2682 // Should garbage collect such that there are 5 frames remaining, starting at |
| 2605 // the keyframe. | 2683 // the keyframe. |
| 2606 CheckExpectedRanges("{ [20,24) }"); | 2684 CheckExpectedRanges("{ [20,24) }"); |
| 2607 CheckExpectedBuffers(20, 24, &kDataB); | 2685 CheckExpectedBuffers(20, 24, &kDataB); |
| 2608 CheckNoNextBuffer(); | 2686 CheckNoNextBuffer(); |
| 2609 } | 2687 } |
| 2610 | 2688 |
| 2611 // Test saving the last GOP appended when this GOP is the only GOP in its range. | 2689 // Test saving the last GOP appended when this GOP is the only GOP in its range. |
| 2612 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP) { | 2690 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP) { |
| 2613 // Set memory limit to 3 and make sure the 4-byte GOP is not garbage | 2691 // Set memory limit to 3 and make sure the 4-byte GOP is not garbage |
| 2614 // collected. | 2692 // collected. |
| 2615 SetMemoryLimit(3); | 2693 SetMemoryLimit(3); |
| 2616 NewSegmentAppend("0K 30 60 90"); | 2694 NewSegmentAppend("0K 30 60 90"); |
| 2695 GarbageCollect_ExpectFull(); |
| 2617 CheckExpectedRangesByTimestamp("{ [0,120) }"); | 2696 CheckExpectedRangesByTimestamp("{ [0,120) }"); |
| 2618 | 2697 |
| 2619 // Make sure you can continue appending data to this GOP; again, GC should not | 2698 // Make sure you can continue appending data to this GOP; again, GC should not |
| 2620 // wipe out anything. | 2699 // wipe out anything. |
| 2621 AppendBuffers("120D30"); | 2700 AppendBuffers("120D30"); |
| 2701 GarbageCollect_ExpectFull(); |
| 2622 CheckExpectedRangesByTimestamp("{ [0,150) }"); | 2702 CheckExpectedRangesByTimestamp("{ [0,150) }"); |
| 2623 | 2703 |
| 2624 // Set memory limit to 100 and append a 2nd range after this without | 2704 // Append a 2nd range after this without triggering GC. |
| 2625 // triggering GC. | |
| 2626 SetMemoryLimit(100); | |
| 2627 NewSegmentAppend("200K 230 260 290K 320 350"); | 2705 NewSegmentAppend("200K 230 260 290K 320 350"); |
| 2628 CheckExpectedRangesByTimestamp("{ [0,150) [200,380) }"); | 2706 CheckExpectedRangesByTimestamp("{ [0,150) [200,380) }"); |
| 2629 | 2707 |
| 2630 // Seek to 290ms. | 2708 // Seek to 290ms. |
| 2631 SeekToTimestamp(base::TimeDelta::FromMilliseconds(290)); | 2709 SeekToTimestamp(base::TimeDelta::FromMilliseconds(290)); |
| 2632 | 2710 |
| 2633 // Now set memory limit to 3 and append a GOP in a separate range after the | 2711 // Now append a GOP in a separate range after the selected range and trigger |
| 2634 // selected range. Because it is after 290ms, this tests that the GOP is saved | 2712 // GC. Because it is after 290ms, this tests that the GOP is saved when |
| 2635 // when deleting from the back. | 2713 // deleting from the back. |
| 2636 SetMemoryLimit(3); | |
| 2637 NewSegmentAppend("500K 530 560 590"); | 2714 NewSegmentAppend("500K 530 560 590"); |
| 2715 GarbageCollect_ExpectFull(); |
| 2638 | 2716 |
| 2639 // Should save GOP with 290ms and last GOP appended. | 2717 // Should save GOPs between 290ms and the last GOP appended. |
| 2640 CheckExpectedRangesByTimestamp("{ [290,380) [500,620) }"); | 2718 CheckExpectedRangesByTimestamp("{ [290,380) [500,620) }"); |
| 2641 | 2719 |
| 2642 // Continue appending to this GOP after GC. | 2720 // Continue appending to this GOP after GC. |
| 2643 AppendBuffers("620D30"); | 2721 AppendBuffers("620D30"); |
| 2722 GarbageCollect_ExpectFull(); |
| 2644 CheckExpectedRangesByTimestamp("{ [290,380) [500,650) }"); | 2723 CheckExpectedRangesByTimestamp("{ [290,380) [500,650) }"); |
| 2645 } | 2724 } |
| 2646 | 2725 |
| 2647 // Test saving the last GOP appended when this GOP is in the middle of a | 2726 // Test saving the last GOP appended when this GOP is in the middle of a |
| 2648 // non-selected range. | 2727 // non-selected range. |
| 2649 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Middle) { | 2728 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Middle) { |
| 2650 // Append 3 GOPs starting at 0ms, 30ms apart. | 2729 // Append 3 GOPs starting at 0ms, 30ms apart. |
| 2651 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240"); | 2730 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240"); |
| 2652 CheckExpectedRangesByTimestamp("{ [0,270) }"); | 2731 CheckExpectedRangesByTimestamp("{ [0,270) }"); |
| 2653 | 2732 |
| 2654 // Now set the memory limit to 1 and overlap the middle of the range with a | 2733 // Now set the memory limit to 1 and overlap the middle of the range with a |
| 2655 // new GOP. | 2734 // new GOP. |
| 2656 SetMemoryLimit(1); | 2735 SetMemoryLimit(1); |
| 2657 NewSegmentAppend("80K 110 140"); | 2736 NewSegmentAppend("80K 110 140"); |
| 2658 | 2737 |
| 2659 // This whole GOP should be saved, and should be able to continue appending | 2738 // This whole GOP should be saved after GC, which will fail due to GOP being |
| 2660 // data to it. | 2739 // larger than 1 buffer |
| 2740 GarbageCollect_ExpectFull(); |
| 2661 CheckExpectedRangesByTimestamp("{ [80,170) }"); | 2741 CheckExpectedRangesByTimestamp("{ [80,170) }"); |
| 2742 // We should still be able to continue appending data to GOP |
| 2662 AppendBuffers("170D30"); | 2743 AppendBuffers("170D30"); |
| 2744 GarbageCollect_ExpectFull(); |
| 2663 CheckExpectedRangesByTimestamp("{ [80,200) }"); | 2745 CheckExpectedRangesByTimestamp("{ [80,200) }"); |
| 2664 | 2746 |
| 2665 // Set memory limit to 100 and append a 2nd range after this without | 2747 // Append a 2nd range after this range, without triggering GC. |
| 2666 // triggering GC. | |
| 2667 SetMemoryLimit(100); | |
| 2668 NewSegmentAppend("400K 430 460 490K 520 550 580K 610 640"); | 2748 NewSegmentAppend("400K 430 460 490K 520 550 580K 610 640"); |
| 2669 CheckExpectedRangesByTimestamp("{ [80,200) [400,670) }"); | 2749 CheckExpectedRangesByTimestamp("{ [80,200) [400,670) }"); |
| 2670 | 2750 |
| 2671 // Seek to 80ms to make the first range the selected range. | 2751 // Seek to 80ms to make the first range the selected range. |
| 2672 SeekToTimestamp(base::TimeDelta::FromMilliseconds(80)); | 2752 SeekToTimestamp(base::TimeDelta::FromMilliseconds(80)); |
| 2673 | 2753 |
| 2674 // Now set memory limit to 3 and append a GOP in the middle of the second | 2754 // Now append a GOP in the middle of the second range and trigger GC. Because |
| 2675 // range. Because it is after the selected range, this tests that the GOP is | 2755 // it is after the selected range, this tests that the GOP is saved when |
| 2676 // saved when deleting from the back. | 2756 // deleting from the back. |
| 2677 SetMemoryLimit(3); | |
| 2678 NewSegmentAppend("500K 530 560 590"); | 2757 NewSegmentAppend("500K 530 560 590"); |
| 2758 GarbageCollect_ExpectFull(); |
| 2679 | 2759 |
| 2680 // Should save the GOP containing the seek point and GOP that was last | 2760 // Should save the GOPs between the seek point and GOP that was last appended |
| 2681 // appended. | 2761 CheckExpectedRangesByTimestamp("{ [80,200) [400,620) }"); |
| 2682 CheckExpectedRangesByTimestamp("{ [80,200) [500,620) }"); | |
| 2683 | 2762 |
| 2684 // Continue appending to this GOP after GC. | 2763 // Continue appending to this GOP after GC. |
| 2685 AppendBuffers("620D30"); | 2764 AppendBuffers("620D30"); |
| 2686 CheckExpectedRangesByTimestamp("{ [80,200) [500,650) }"); | 2765 GarbageCollect_ExpectFull(); |
| 2766 CheckExpectedRangesByTimestamp("{ [80,200) [400,650) }"); |
| 2687 } | 2767 } |
| 2688 | 2768 |
| 2689 // Test saving the last GOP appended when the GOP containing the next buffer is | 2769 // Test saving the last GOP appended when the GOP containing the next buffer is |
| 2690 // adjacent to the last GOP appended. | 2770 // adjacent to the last GOP appended. |
| 2691 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected1) { | 2771 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected1) { |
| 2692 // Append 3 GOPs at 0ms, 90ms, and 180ms. | 2772 // Append 3 GOPs at 0ms, 90ms, and 180ms. |
| 2693 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240"); | 2773 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240"); |
| 2694 CheckExpectedRangesByTimestamp("{ [0,270) }"); | 2774 CheckExpectedRangesByTimestamp("{ [0,270) }"); |
| 2695 | 2775 |
| 2696 // Seek to the GOP at 90ms. | 2776 // Seek to the GOP at 90ms. |
| 2697 SeekToTimestamp(base::TimeDelta::FromMilliseconds(90)); | 2777 SeekToTimestamp(base::TimeDelta::FromMilliseconds(90)); |
| 2698 | 2778 |
| 2699 // Set the memory limit to 1, then overlap the GOP at 0. | 2779 // Set the memory limit to 1, then overlap the GOP at 0. |
| 2700 SetMemoryLimit(1); | 2780 SetMemoryLimit(1); |
| 2701 NewSegmentAppend("0K 30 60"); | 2781 NewSegmentAppend("0K 30 60"); |
| 2702 | 2782 |
| 2703 // Should save the GOP at 0ms and 90ms. | 2783 // GC should save the GOP at 0ms and 90ms, and will fail since GOP larger |
| 2784 // than 1 buffer |
| 2785 GarbageCollect_ExpectFull(); |
| 2704 CheckExpectedRangesByTimestamp("{ [0,180) }"); | 2786 CheckExpectedRangesByTimestamp("{ [0,180) }"); |
| 2705 | 2787 |
| 2706 // Seek to 0 and check all buffers. | 2788 // Seek to 0 and check all buffers. |
| 2707 SeekToTimestamp(base::TimeDelta::FromMilliseconds(0)); | 2789 SeekToTimestamp(base::TimeDelta::FromMilliseconds(0)); |
| 2708 CheckExpectedBuffers("0K 30 60 90K 120 150"); | 2790 CheckExpectedBuffers("0K 30 60 90K 120 150"); |
| 2709 CheckNoNextBuffer(); | 2791 CheckNoNextBuffer(); |
| 2710 | 2792 |
| 2711 // Now seek back to 90ms and append a GOP at 180ms. | 2793 // Now seek back to 90ms and append a GOP at 180ms. |
| 2712 SeekToTimestamp(base::TimeDelta::FromMilliseconds(90)); | 2794 SeekToTimestamp(base::TimeDelta::FromMilliseconds(90)); |
| 2713 NewSegmentAppend("180K 210 240"); | 2795 NewSegmentAppend("180K 210 240"); |
| 2714 | 2796 |
| 2715 // Should save the GOP at 90ms and the GOP at 180ms. | 2797 // Should save the GOP at 90ms and the GOP at 180ms. |
| 2798 GarbageCollect_ExpectFull(); |
| 2716 CheckExpectedRangesByTimestamp("{ [90,270) }"); | 2799 CheckExpectedRangesByTimestamp("{ [90,270) }"); |
| 2717 CheckExpectedBuffers("90K 120 150 180K 210 240"); | 2800 CheckExpectedBuffers("90K 120 150 180K 210 240"); |
| 2718 CheckNoNextBuffer(); | 2801 CheckNoNextBuffer(); |
| 2719 } | 2802 } |
| 2720 | 2803 |
| 2721 // Test saving the last GOP appended when it is at the beginning or end of the | 2804 // Test saving the last GOP appended when it is at the beginning or end of the |
| 2722 // selected range. This tests when the last GOP appended is before or after the | 2805 // selected range. This tests when the last GOP appended is before or after the |
| 2723 // GOP containing the next buffer, but not directly adjacent to this GOP. | 2806 // GOP containing the next buffer, but not directly adjacent to this GOP. |
| 2724 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected2) { | 2807 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected2) { |
| 2725 // Append 4 GOPs starting at positions 0ms, 90ms, 180ms, 270ms. | 2808 // Append 4 GOPs starting at positions 0ms, 90ms, 180ms, 270ms. |
| 2726 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240 270K 300 330"); | 2809 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240 270K 300 330"); |
| 2727 CheckExpectedRangesByTimestamp("{ [0,360) }"); | 2810 CheckExpectedRangesByTimestamp("{ [0,360) }"); |
| 2728 | 2811 |
| 2729 // Seek to the last GOP at 270ms. | 2812 // Seek to the last GOP at 270ms. |
| 2730 SeekToTimestamp(base::TimeDelta::FromMilliseconds(270)); | 2813 SeekToTimestamp(base::TimeDelta::FromMilliseconds(270)); |
| 2731 | 2814 |
| 2732 // Set the memory limit to 1, then overlap the GOP at 90ms. | 2815 // Set the memory limit to 1, then overlap the GOP at 90ms. |
| 2733 SetMemoryLimit(1); | 2816 SetMemoryLimit(1); |
| 2734 NewSegmentAppend("90K 120 150"); | 2817 NewSegmentAppend("90K 120 150"); |
| 2735 | 2818 |
| 2736 // Should save the GOP at 90ms and the GOP at 270ms. | 2819 // GC should save the GOP at 90ms and 270ms, and will fail since GOP larger |
| 2820 // than 1 buffer |
| 2821 GarbageCollect_ExpectFull(); |
| 2737 CheckExpectedRangesByTimestamp("{ [90,180) [270,360) }"); | 2822 CheckExpectedRangesByTimestamp("{ [90,180) [270,360) }"); |
| 2738 | 2823 |
| 2739 // Set memory limit to 100 and add 3 GOPs to the end of the selected range | 2824 // Add 3 GOPs to the end of the selected range at 360ms, 450ms, and 540ms. |
| 2740 // at 360ms, 450ms, and 540ms. | |
| 2741 SetMemoryLimit(100); | |
| 2742 NewSegmentAppend("360K 390 420 450K 480 510 540K 570 600"); | 2825 NewSegmentAppend("360K 390 420 450K 480 510 540K 570 600"); |
| 2743 CheckExpectedRangesByTimestamp("{ [90,180) [270,630) }"); | 2826 CheckExpectedRangesByTimestamp("{ [90,180) [270,630) }"); |
| 2744 | 2827 |
| 2745 // Constrain the memory limit again and overlap the GOP at 450ms to test | 2828 // Overlap the GOP at 450ms and garbage collect to test deleting from the |
| 2746 // deleting from the back. | 2829 // back. |
| 2747 SetMemoryLimit(1); | |
| 2748 NewSegmentAppend("450K 480 510"); | 2830 NewSegmentAppend("450K 480 510"); |
| 2831 GarbageCollect_ExpectFull(); |
| 2749 | 2832 |
| 2750 // Should save GOP at 270ms and the GOP at 450ms. | 2833 // Should save GOPs from GOP at 270ms to GOP at 450ms. |
| 2751 CheckExpectedRangesByTimestamp("{ [270,360) [450,540) }"); | 2834 CheckExpectedRangesByTimestamp("{ [270,540) }"); |
| 2752 } | 2835 } |
| 2753 | 2836 |
| 2754 // Test saving the last GOP appended when it is the same as the GOP containing | 2837 // Test saving the last GOP appended when it is the same as the GOP containing |
| 2755 // the next buffer. | 2838 // the next buffer. |
| 2756 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected3) { | 2839 TEST_F(SourceBufferStreamTest, GarbageCollection_SaveAppendGOP_Selected3) { |
| 2757 // Seek to start of stream. | 2840 // Seek to start of stream. |
| 2758 SeekToTimestamp(base::TimeDelta::FromMilliseconds(0)); | 2841 SeekToTimestamp(base::TimeDelta::FromMilliseconds(0)); |
| 2759 | 2842 |
| 2760 // Append 3 GOPs starting at 0ms, 90ms, 180ms. | 2843 // Append 3 GOPs starting at 0ms, 90ms, 180ms. |
| 2761 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240"); | 2844 NewSegmentAppend("0K 30 60 90K 120 150 180K 210 240"); |
| 2762 CheckExpectedRangesByTimestamp("{ [0,270) }"); | 2845 CheckExpectedRangesByTimestamp("{ [0,270) }"); |
| 2763 | 2846 |
| 2764 // Set the memory limit to 1 then begin appending the start of a GOP starting | 2847 // Set the memory limit to 1 then begin appending the start of a GOP starting |
| 2765 // at 0ms. | 2848 // at 0ms. |
| 2766 SetMemoryLimit(1); | 2849 SetMemoryLimit(1); |
| 2767 NewSegmentAppend("0K 30"); | 2850 NewSegmentAppend("0K 30"); |
| 2768 | 2851 |
| 2769 // Should save the newly appended GOP, which is also the next GOP that will be | 2852 // GC should save the newly appended GOP, which is also the next GOP that |
| 2770 // returned from the seek request. | 2853 // will be returned from the seek request. |
| 2854 GarbageCollect_ExpectFull(); |
| 2771 CheckExpectedRangesByTimestamp("{ [0,60) }"); | 2855 CheckExpectedRangesByTimestamp("{ [0,60) }"); |
| 2772 | 2856 |
| 2773 // Check the buffers in the range. | 2857 // Check the buffers in the range. |
| 2774 CheckExpectedBuffers("0K 30"); | 2858 CheckExpectedBuffers("0K 30"); |
| 2775 CheckNoNextBuffer(); | 2859 CheckNoNextBuffer(); |
| 2776 | 2860 |
| 2777 // Continue appending to this buffer. | 2861 // Continue appending to this buffer. |
| 2778 AppendBuffers("60 90"); | 2862 AppendBuffers("60 90"); |
| 2779 | 2863 |
| 2780 // Should still save the rest of this GOP and should be able to fulfill the | 2864 // GC should still save the rest of this GOP and should be able to fulfill |
| 2781 // read. | 2865 // the read. |
| 2866 GarbageCollect_ExpectFull(); |
| 2782 CheckExpectedRangesByTimestamp("{ [0,120) }"); | 2867 CheckExpectedRangesByTimestamp("{ [0,120) }"); |
| 2783 CheckExpectedBuffers("60 90"); | 2868 CheckExpectedBuffers("60 90"); |
| 2784 CheckNoNextBuffer(); | 2869 CheckNoNextBuffer(); |
| 2785 } | 2870 } |
| 2786 | 2871 |
| 2787 // Currently disabled because of bug: crbug.com/140875. | 2872 // Currently disabled because of bug: crbug.com/140875. |
| 2788 TEST_F(SourceBufferStreamTest, DISABLED_GarbageCollection_WaitingForKeyframe) { | 2873 TEST_F(SourceBufferStreamTest, DISABLED_GarbageCollection_WaitingForKeyframe) { |
| 2789 // Set memory limit to 10 buffers. | 2874 // Set memory limit to 10 buffers. |
| 2790 SetMemoryLimit(10); | 2875 SetMemoryLimit(10); |
| 2791 | 2876 |
| (...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3941 CheckNoNextBuffer(); | 4026 CheckNoNextBuffer(); |
| 3942 } | 4027 } |
| 3943 | 4028 |
| 3944 // TODO(vrk): Add unit tests where keyframes are unaligned between streams. | 4029 // TODO(vrk): Add unit tests where keyframes are unaligned between streams. |
| 3945 // (crbug.com/133557) | 4030 // (crbug.com/133557) |
| 3946 | 4031 |
| 3947 // TODO(vrk): Add unit tests with end of stream being called at interesting | 4032 // TODO(vrk): Add unit tests with end of stream being called at interesting |
| 3948 // times. | 4033 // times. |
| 3949 | 4034 |
| 3950 } // namespace media | 4035 } // namespace media |
| OLD | NEW |