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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 active_splice_timestamp = buffer->splice_timestamp(); | 342 active_splice_timestamp = buffer->splice_timestamp(); |
343 } | 343 } |
344 EXPECT_EQ(expected, ss.str()); | 344 EXPECT_EQ(expected, ss.str()); |
345 } | 345 } |
346 | 346 |
347 void CheckNoNextBuffer() { | 347 void CheckNoNextBuffer() { |
348 scoped_refptr<StreamParserBuffer> buffer; | 348 scoped_refptr<StreamParserBuffer> buffer; |
349 EXPECT_EQ(SourceBufferStream::kNeedBuffer, stream_->GetNextBuffer(&buffer)); | 349 EXPECT_EQ(SourceBufferStream::kNeedBuffer, stream_->GetNextBuffer(&buffer)); |
350 } | 350 } |
351 | 351 |
| 352 void CheckEOSReached() { |
| 353 scoped_refptr<StreamParserBuffer> buffer; |
| 354 EXPECT_EQ(SourceBufferStream::kEndOfStream, |
| 355 stream_->GetNextBuffer(&buffer)); |
| 356 } |
| 357 |
352 void CheckVideoConfig(const VideoDecoderConfig& config) { | 358 void CheckVideoConfig(const VideoDecoderConfig& config) { |
353 const VideoDecoderConfig& actual = stream_->GetCurrentVideoDecoderConfig(); | 359 const VideoDecoderConfig& actual = stream_->GetCurrentVideoDecoderConfig(); |
354 EXPECT_TRUE(actual.Matches(config)) | 360 EXPECT_TRUE(actual.Matches(config)) |
355 << "Expected: " << config.AsHumanReadableString() | 361 << "Expected: " << config.AsHumanReadableString() |
356 << "\nActual: " << actual.AsHumanReadableString(); | 362 << "\nActual: " << actual.AsHumanReadableString(); |
357 } | 363 } |
358 | 364 |
359 void CheckAudioConfig(const AudioDecoderConfig& config) { | 365 void CheckAudioConfig(const AudioDecoderConfig& config) { |
360 const AudioDecoderConfig& actual = stream_->GetCurrentAudioDecoderConfig(); | 366 const AudioDecoderConfig& actual = stream_->GetCurrentAudioDecoderConfig(); |
361 EXPECT_TRUE(actual.Matches(config)) | 367 EXPECT_TRUE(actual.Matches(config)) |
(...skipping 2870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3232 NewSegmentAppend("400K 430K 460K"); | 3238 NewSegmentAppend("400K 430K 460K"); |
3233 | 3239 |
3234 CheckExpectedRangesByTimestamp("{ [0,90) [200,350) [400,490) }"); | 3240 CheckExpectedRangesByTimestamp("{ [0,90) [200,350) [400,490) }"); |
3235 | 3241 |
3236 stream_->OnSetDuration(base::TimeDelta::FromMilliseconds(120)); | 3242 stream_->OnSetDuration(base::TimeDelta::FromMilliseconds(120)); |
3237 | 3243 |
3238 // Verify that the buffered ranges are updated properly and we don't crash. | 3244 // Verify that the buffered ranges are updated properly and we don't crash. |
3239 CheckExpectedRangesByTimestamp("{ [0,90) }"); | 3245 CheckExpectedRangesByTimestamp("{ [0,90) }"); |
3240 } | 3246 } |
3241 | 3247 |
| 3248 TEST_F(SourceBufferStreamTest, SetExplicitDuration_MarkEOS) { |
| 3249 // Append 1 buffer at positions 0 through 8. |
| 3250 NewSegmentAppend(0, 9); |
| 3251 |
| 3252 // Check expected ranges. |
| 3253 CheckExpectedRanges("{ [0,8) }"); |
| 3254 |
| 3255 // Seek to 5. |
| 3256 Seek(5); |
| 3257 |
| 3258 // Set duration to be before the seeked to position. |
| 3259 // This will result in truncation of the selected range and a reset |
| 3260 // of NextBufferPosition. |
| 3261 stream_->OnSetDuration(frame_duration() * 4); |
| 3262 |
| 3263 // Check the expected ranges. |
| 3264 CheckExpectedRanges("{ [0,3) }"); |
| 3265 |
| 3266 // Mark EOS reached. |
| 3267 stream_->MarkEndOfStream(); |
| 3268 |
| 3269 // Expect EOS to be reached. |
| 3270 CheckEOSReached(); |
| 3271 } |
| 3272 |
| 3273 TEST_F(SourceBufferStreamTest, SetExplicitDuration_MarkEOS_IsSeekPending) { |
| 3274 // Append 1 buffer at positions 0 through 8. |
| 3275 NewSegmentAppend(0, 9); |
| 3276 |
| 3277 // Check expected ranges. |
| 3278 CheckExpectedRanges("{ [0,8) }"); |
| 3279 |
| 3280 // Seek to 9 which will result in a pending seek. |
| 3281 Seek(9); |
| 3282 |
| 3283 // Set duration to be before the seeked to position. |
| 3284 // This will result in truncation of the selected range and a reset |
| 3285 // of NextBufferPosition. |
| 3286 stream_->OnSetDuration(frame_duration() * 4); |
| 3287 |
| 3288 // Check the expected ranges. |
| 3289 CheckExpectedRanges("{ [0,3) }"); |
| 3290 |
| 3291 EXPECT_TRUE(stream_->IsSeekPending()); |
| 3292 // Mark EOS reached. |
| 3293 stream_->MarkEndOfStream(); |
| 3294 EXPECT_FALSE(stream_->IsSeekPending()); |
| 3295 } |
| 3296 |
3242 // Test the case were the current playback position is at the end of the | 3297 // Test the case were the current playback position is at the end of the |
3243 // buffered data and several overlaps occur that causes the selected | 3298 // buffered data and several overlaps occur that causes the selected |
3244 // range to get split and then merged back into a single range. | 3299 // range to get split and then merged back into a single range. |
3245 TEST_F(SourceBufferStreamTest, OverlapSplitAndMergeWhileWaitingForMoreData) { | 3300 TEST_F(SourceBufferStreamTest, OverlapSplitAndMergeWhileWaitingForMoreData) { |
3246 // Seek to start of stream. | 3301 // Seek to start of stream. |
3247 SeekToTimestamp(base::TimeDelta::FromMilliseconds(0)); | 3302 SeekToTimestamp(base::TimeDelta::FromMilliseconds(0)); |
3248 | 3303 |
3249 NewSegmentAppend("0K 30 60 90 120K 150"); | 3304 NewSegmentAppend("0K 30 60 90 120K 150"); |
3250 CheckExpectedRangesByTimestamp("{ [0,180) }"); | 3305 CheckExpectedRangesByTimestamp("{ [0,180) }"); |
3251 | 3306 |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4041 CheckNoNextBuffer(); | 4096 CheckNoNextBuffer(); |
4042 } | 4097 } |
4043 | 4098 |
4044 // TODO(vrk): Add unit tests where keyframes are unaligned between streams. | 4099 // TODO(vrk): Add unit tests where keyframes are unaligned between streams. |
4045 // (crbug.com/133557) | 4100 // (crbug.com/133557) |
4046 | 4101 |
4047 // TODO(vrk): Add unit tests with end of stream being called at interesting | 4102 // TODO(vrk): Add unit tests with end of stream being called at interesting |
4048 // times. | 4103 // times. |
4049 | 4104 |
4050 } // namespace media | 4105 } // namespace media |
OLD | NEW |