OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 scoped_refptr<DecoderBuffer> buffer; | 873 scoped_refptr<DecoderBuffer> buffer; |
874 stream->Read(base::Bind(&ChunkDemuxerTest::StoreStatusAndBuffer, | 874 stream->Read(base::Bind(&ChunkDemuxerTest::StoreStatusAndBuffer, |
875 base::Unretained(this), &status, &buffer)); | 875 base::Unretained(this), &status, &buffer)); |
876 base::MessageLoop::current()->RunUntilIdle(); | 876 base::MessageLoop::current()->RunUntilIdle(); |
877 if (status != DemuxerStream::kOk || buffer->end_of_stream()) | 877 if (status != DemuxerStream::kOk || buffer->end_of_stream()) |
878 break; | 878 break; |
879 | 879 |
880 if (i > 0) | 880 if (i > 0) |
881 ss << " "; | 881 ss << " "; |
882 ss << buffer->timestamp().InMilliseconds(); | 882 ss << buffer->timestamp().InMilliseconds(); |
883 | |
884 // Handle preroll buffers. | |
885 if (EndsWith(timestamps[i], "P", true)) { | |
886 scoped_refptr<DecoderBuffer> preroll_buffer; | |
887 preroll_buffer.swap(buffer); | |
888 | |
889 // When a preroll buffer is encountered we should be able to request one | |
890 // more buffer. The first buffer should have a timestamp equal to the | |
891 // second buffer and its discard_padding() should be its duration. | |
892 stream->Read(base::Bind(&ChunkDemuxerTest::StoreStatusAndBuffer, | |
893 base::Unretained(this), &status, &buffer)); | |
894 base::MessageLoop::current()->RunUntilIdle(); | |
895 ASSERT_EQ(preroll_buffer->timestamp(), buffer->timestamp()); | |
896 ASSERT_EQ(preroll_buffer->discard_padding().first, | |
897 preroll_buffer->duration()); | |
898 ss << "P"; | |
899 } | |
883 } | 900 } |
884 EXPECT_EQ(expected, ss.str()); | 901 EXPECT_EQ(expected, ss.str()); |
885 } | 902 } |
886 | 903 |
887 MOCK_METHOD1(Checkpoint, void(int id)); | 904 MOCK_METHOD1(Checkpoint, void(int id)); |
888 | 905 |
889 struct BufferTimestamps { | 906 struct BufferTimestamps { |
890 int video_time_ms; | 907 int video_time_ms; |
891 int audio_time_ms; | 908 int audio_time_ms; |
892 }; | 909 }; |
(...skipping 2159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3052 EXPECT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO | HAS_VIDEO)); | 3069 EXPECT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO | HAS_VIDEO)); |
3053 | 3070 |
3054 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(0), | 3071 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(0), |
3055 base::TimeDelta::FromMilliseconds(1)); | 3072 base::TimeDelta::FromMilliseconds(1)); |
3056 } | 3073 } |
3057 | 3074 |
3058 TEST_P(ChunkDemuxerTest, AppendWindow_Video) { | 3075 TEST_P(ChunkDemuxerTest, AppendWindow_Video) { |
3059 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); | 3076 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); |
3060 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 3077 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
3061 | 3078 |
3062 // Set the append window to [20,280). | 3079 // Set the append window to [50,280). |
wolenetz
2014/05/17 00:41:17
Why increase 20 -> 50? Currently, video does not s
DaleCurtis
2014/05/17 00:55:41
I changed them both because I thought it was a bet
| |
3063 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); | 3080 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); |
3064 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); | 3081 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); |
3065 | 3082 |
3066 // Append a cluster that starts before and ends after the append window. | 3083 // Append a cluster that starts before and ends after the append window. |
3067 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 3084 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, |
3068 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); | 3085 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); |
3069 | 3086 |
3070 // Verify that GOPs that start outside the window are not included | 3087 // Verify that GOPs that start outside the window are not included |
3071 // in the buffer. Also verify that buffers that start inside the | 3088 // in the buffer. Also verify that buffers that start inside the |
3072 // window and extend beyond the end of the window are not included. | 3089 // window and extend beyond the end of the window are not included. |
3073 CheckExpectedRanges(kSourceId, "{ [120,270) }"); | 3090 CheckExpectedRanges(kSourceId, "{ [120,270) }"); |
3074 CheckExpectedBuffers(stream, "120 150 180 210 240"); | 3091 CheckExpectedBuffers(stream, "120 150 180 210 240"); |
3075 | 3092 |
3076 // Extend the append window to [20,650). | 3093 // Extend the append window to [20,650). |
wolenetz
2014/05/17 00:41:17
nit: Fix comment if we keep to 50ms window start.
DaleCurtis
2014/05/22 23:58:57
Done.
| |
3077 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); | 3094 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); |
3078 | 3095 |
3079 // Append more data and verify that adding buffers start at the next | 3096 // Append more data and verify that adding buffers start at the next |
3080 // keyframe. | 3097 // keyframe. |
3081 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 3098 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, |
3082 "360 390 420K 450 480 510 540K 570 600 630K"); | 3099 "360 390 420K 450 480 510 540K 570 600 630K"); |
3083 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); | 3100 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); |
3084 } | 3101 } |
3085 | 3102 |
3086 TEST_P(ChunkDemuxerTest, AppendWindow_Audio) { | 3103 TEST_P(ChunkDemuxerTest, AppendWindow_Audio) { |
3087 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); | 3104 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
3088 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 3105 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
3089 | 3106 |
3090 // Set the append window to [20,280). | 3107 // Set the append window to [50,280). |
3091 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); | 3108 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); |
3092 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); | 3109 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); |
3093 | 3110 |
3094 // Append a cluster that starts before and ends after the append window. | 3111 // Append a cluster that starts before and ends after the append window. |
3095 AppendSingleStreamCluster( | 3112 AppendSingleStreamCluster( |
3096 kSourceId, kAudioTrackNum, | 3113 kSourceId, kAudioTrackNum, |
3097 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); | 3114 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); |
3098 | 3115 |
3099 // Verify that frames that end outside the window are not included | 3116 // Verify that frames that end outside the window are not included |
3100 // in the buffer. Also verify that buffers that start inside the | 3117 // in the buffer. Also verify that buffers that start inside the |
3101 // window and extend beyond the end of the window are not included. | 3118 // window and extend beyond the end of the window are not included. |
3102 // | 3119 // |
3103 // The first 20ms of the first buffer should be trimmed off since it | 3120 // The first 20ms of the second buffer should be trimmed off since it |
3104 // overlaps the start of the append window. | 3121 // overlaps the start of the append window. The first buffer should be |
3105 CheckExpectedRanges(kSourceId, "{ [20,270) }"); | 3122 // added as preroll to the second buffer. |
3106 CheckExpectedBuffers(stream, "20 30 60 90 120 150 180 210 240"); | 3123 CheckExpectedRanges(kSourceId, "{ [50,270) }"); |
3124 CheckExpectedBuffers(stream, "50P 60 90 120 150 180 210 240"); | |
3107 | 3125 |
3108 // Extend the append window to [20,650). | 3126 // Extend the append window to [50,650). |
3109 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); | 3127 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); |
3110 | 3128 |
3111 // Append more data and verify that a new range is created. | 3129 // Append more data and verify that a new range is created. |
3112 AppendSingleStreamCluster( | 3130 AppendSingleStreamCluster( |
3113 kSourceId, kAudioTrackNum, | 3131 kSourceId, kAudioTrackNum, |
3114 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); | 3132 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); |
3115 CheckExpectedRanges(kSourceId, "{ [20,270) [360,630) }"); | 3133 CheckExpectedRanges(kSourceId, "{ [50,270) [360,630) }"); |
3116 } | 3134 } |
3117 | 3135 |
3118 TEST_P(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) { | 3136 TEST_P(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) { |
3119 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); | 3137 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
3120 | 3138 |
3121 // Set the append window to [10,20). | 3139 // Set the append window to [10,20). |
3122 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10); | 3140 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10); |
3123 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20); | 3141 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20); |
3124 | 3142 |
3125 // Append a cluster that starts before and ends after the append window. | 3143 // Append a cluster that starts before and ends after the append window. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3273 // Verify that audio & video streams continue to return expected values. | 3291 // Verify that audio & video streams continue to return expected values. |
3274 CheckExpectedBuffers(audio_stream, "160 180"); | 3292 CheckExpectedBuffers(audio_stream, "160 180"); |
3275 CheckExpectedBuffers(video_stream, "180 210"); | 3293 CheckExpectedBuffers(video_stream, "180 210"); |
3276 } | 3294 } |
3277 | 3295 |
3278 // TODO(wolenetz): Enable testing of new frame processor based on this flag, | 3296 // TODO(wolenetz): Enable testing of new frame processor based on this flag, |
3279 // once the new processor has landed. See http://crbug.com/249422. | 3297 // once the new processor has landed. See http://crbug.com/249422. |
3280 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, ChunkDemuxerTest, Values(true)); | 3298 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, ChunkDemuxerTest, Values(true)); |
3281 | 3299 |
3282 } // namespace media | 3300 } // namespace media |
OLD | NEW |