| 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 10 matching lines...) Expand all Loading... |
| 21 #include "media/formats/webm/webm_crypto_helpers.h" | 21 #include "media/formats/webm/webm_crypto_helpers.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
| 25 using ::testing::Exactly; | 25 using ::testing::Exactly; |
| 26 using ::testing::InSequence; | 26 using ::testing::InSequence; |
| 27 using ::testing::NotNull; | 27 using ::testing::NotNull; |
| 28 using ::testing::Return; | 28 using ::testing::Return; |
| 29 using ::testing::SaveArg; | 29 using ::testing::SaveArg; |
| 30 using ::testing::SetArgumentPointee; | 30 using ::testing::SetArgumentPointee; |
| 31 using ::testing::Values; |
| 31 using ::testing::_; | 32 using ::testing::_; |
| 32 | 33 |
| 33 namespace media { | 34 namespace media { |
| 34 | 35 |
| 35 const uint8 kTracksHeader[] = { | 36 const uint8 kTracksHeader[] = { |
| 36 0x16, 0x54, 0xAE, 0x6B, // Tracks ID | 37 0x16, 0x54, 0xAE, 0x6B, // Tracks ID |
| 37 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // tracks(size = 0) | 38 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // tracks(size = 0) |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 // WebM Block bytes that represent a VP8 keyframe. | 41 // WebM Block bytes that represent a VP8 keyframe. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 *called = true; | 126 *called = true; |
| 126 } | 127 } |
| 127 | 128 |
| 128 static void OnSeekDone_OKExpected(bool* called, PipelineStatus status) { | 129 static void OnSeekDone_OKExpected(bool* called, PipelineStatus status) { |
| 129 EXPECT_EQ(status, PIPELINE_OK); | 130 EXPECT_EQ(status, PIPELINE_OK); |
| 130 *called = true; | 131 *called = true; |
| 131 } | 132 } |
| 132 | 133 |
| 133 static void LogFunc(const std::string& str) { DVLOG(1) << str; } | 134 static void LogFunc(const std::string& str) { DVLOG(1) << str; } |
| 134 | 135 |
| 135 class ChunkDemuxerTest : public testing::Test { | 136 // Test parameter determines which coded frame processor is used to process |
| 137 // appended data. If true, LegacyFrameProcessor is used. Otherwise, (not yet |
| 138 // supported), a more compliant frame processor is used. |
| 139 // TODO(wolenetz): Enable usage of new frame processor based on this flag. |
| 140 // See http://crbug.com/249422. |
| 141 class ChunkDemuxerTest : public ::testing::TestWithParam<bool> { |
| 136 protected: | 142 protected: |
| 137 enum CodecsIndex { | 143 enum CodecsIndex { |
| 138 AUDIO, | 144 AUDIO, |
| 139 VIDEO, | 145 VIDEO, |
| 140 MAX_CODECS_INDEX | 146 MAX_CODECS_INDEX |
| 141 }; | 147 }; |
| 142 | 148 |
| 143 // Default cluster to append first for simple tests. | 149 // Default cluster to append first for simple tests. |
| 144 scoped_ptr<Cluster> kDefaultFirstCluster() { | 150 scoped_ptr<Cluster> kDefaultFirstCluster() { |
| 145 return GenerateCluster(0, 4); | 151 return GenerateCluster(0, 4); |
| 146 } | 152 } |
| 147 | 153 |
| 148 // Default cluster to append after kDefaultFirstCluster() | 154 // Default cluster to append after kDefaultFirstCluster() |
| 149 // has been appended. This cluster starts with blocks that | 155 // has been appended. This cluster starts with blocks that |
| 150 // have timestamps consistent with the end times of the blocks | 156 // have timestamps consistent with the end times of the blocks |
| 151 // in kDefaultFirstCluster() so that these two clusters represent | 157 // in kDefaultFirstCluster() so that these two clusters represent |
| 152 // a continuous region. | 158 // a continuous region. |
| 153 scoped_ptr<Cluster> kDefaultSecondCluster() { | 159 scoped_ptr<Cluster> kDefaultSecondCluster() { |
| 154 return GenerateCluster(46, 66, 5); | 160 return GenerateCluster(46, 66, 5); |
| 155 } | 161 } |
| 156 | 162 |
| 157 ChunkDemuxerTest() | 163 ChunkDemuxerTest() |
| 158 : append_window_end_for_next_append_(kInfiniteDuration()) { | 164 : append_window_end_for_next_append_(kInfiniteDuration()) { |
| 165 use_legacy_frame_processor_ = GetParam(); |
| 159 CreateNewDemuxer(); | 166 CreateNewDemuxer(); |
| 160 } | 167 } |
| 161 | 168 |
| 162 void CreateNewDemuxer() { | 169 void CreateNewDemuxer() { |
| 163 base::Closure open_cb = | 170 base::Closure open_cb = |
| 164 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this)); | 171 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this)); |
| 165 Demuxer::NeedKeyCB need_key_cb = | 172 Demuxer::NeedKeyCB need_key_cb = |
| 166 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this)); | 173 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this)); |
| 167 demuxer_.reset( | 174 demuxer_.reset( |
| 168 new ChunkDemuxer(open_cb, need_key_cb, base::Bind(&LogFunc), false)); | 175 new ChunkDemuxer(open_cb, need_key_cb, base::Bind(&LogFunc), false)); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 313 |
| 307 if (has_video) { | 314 if (has_video) { |
| 308 codecs.push_back("vp8"); | 315 codecs.push_back("vp8"); |
| 309 type = "video/webm"; | 316 type = "video/webm"; |
| 310 } | 317 } |
| 311 | 318 |
| 312 if (!has_audio && !has_video) { | 319 if (!has_audio && !has_video) { |
| 313 return AddId(kSourceId, HAS_AUDIO | HAS_VIDEO); | 320 return AddId(kSourceId, HAS_AUDIO | HAS_VIDEO); |
| 314 } | 321 } |
| 315 | 322 |
| 316 return demuxer_->AddId(source_id, type, codecs); | 323 return demuxer_->AddId(source_id, type, codecs, |
| 324 use_legacy_frame_processor_); |
| 317 } | 325 } |
| 318 | 326 |
| 319 void AppendData(const uint8* data, size_t length) { | 327 void AppendData(const uint8* data, size_t length) { |
| 320 AppendData(kSourceId, data, length); | 328 AppendData(kSourceId, data, length); |
| 321 } | 329 } |
| 322 | 330 |
| 323 void AppendCluster(const std::string& source_id, | 331 void AppendCluster(const std::string& source_id, |
| 324 scoped_ptr<Cluster> cluster) { | 332 scoped_ptr<Cluster> cluster) { |
| 325 AppendData(source_id, cluster->data(), cluster->size()); | 333 AppendData(source_id, cluster->data(), cluster->size()); |
| 326 } | 334 } |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 return false; | 969 return false; |
| 962 | 970 |
| 963 timestamp_offset_map_[id] = timestamp_offset; | 971 timestamp_offset_map_[id] = timestamp_offset; |
| 964 return true; | 972 return true; |
| 965 } | 973 } |
| 966 | 974 |
| 967 base::MessageLoop message_loop_; | 975 base::MessageLoop message_loop_; |
| 968 MockDemuxerHost host_; | 976 MockDemuxerHost host_; |
| 969 | 977 |
| 970 scoped_ptr<ChunkDemuxer> demuxer_; | 978 scoped_ptr<ChunkDemuxer> demuxer_; |
| 979 bool use_legacy_frame_processor_; |
| 971 | 980 |
| 972 base::TimeDelta append_window_start_for_next_append_; | 981 base::TimeDelta append_window_start_for_next_append_; |
| 973 base::TimeDelta append_window_end_for_next_append_; | 982 base::TimeDelta append_window_end_for_next_append_; |
| 974 | 983 |
| 975 // Map of source id to timestamp offset to use for the next AppendData() | 984 // Map of source id to timestamp offset to use for the next AppendData() |
| 976 // operation for that source id. | 985 // operation for that source id. |
| 977 std::map<std::string, base::TimeDelta> timestamp_offset_map_; | 986 std::map<std::string, base::TimeDelta> timestamp_offset_map_; |
| 978 | 987 |
| 979 private: | 988 private: |
| 980 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); | 989 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); |
| 981 }; | 990 }; |
| 982 | 991 |
| 983 TEST_F(ChunkDemuxerTest, Init) { | 992 TEST_P(ChunkDemuxerTest, Init) { |
| 984 // Test no streams, audio-only, video-only, and audio & video scenarios. | 993 // Test no streams, audio-only, video-only, and audio & video scenarios. |
| 985 // Audio and video streams can be encrypted or not encrypted. | 994 // Audio and video streams can be encrypted or not encrypted. |
| 986 for (int i = 0; i < 16; i++) { | 995 for (int i = 0; i < 16; i++) { |
| 987 bool has_audio = (i & 0x1) != 0; | 996 bool has_audio = (i & 0x1) != 0; |
| 988 bool has_video = (i & 0x2) != 0; | 997 bool has_video = (i & 0x2) != 0; |
| 989 bool is_audio_encrypted = (i & 0x4) != 0; | 998 bool is_audio_encrypted = (i & 0x4) != 0; |
| 990 bool is_video_encrypted = (i & 0x8) != 0; | 999 bool is_video_encrypted = (i & 0x8) != 0; |
| 991 | 1000 |
| 992 // No test on invalid combination. | 1001 // No test on invalid combination. |
| 993 if ((!has_audio && is_audio_encrypted) || | 1002 if ((!has_audio && is_audio_encrypted) || |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 EXPECT_FALSE(video_stream); | 1051 EXPECT_FALSE(video_stream); |
| 1043 } | 1052 } |
| 1044 | 1053 |
| 1045 ShutdownDemuxer(); | 1054 ShutdownDemuxer(); |
| 1046 demuxer_.reset(); | 1055 demuxer_.reset(); |
| 1047 } | 1056 } |
| 1048 } | 1057 } |
| 1049 | 1058 |
| 1050 // TODO(acolwell): Fold this test into Init tests since the tests are | 1059 // TODO(acolwell): Fold this test into Init tests since the tests are |
| 1051 // almost identical. | 1060 // almost identical. |
| 1052 TEST_F(ChunkDemuxerTest, InitText) { | 1061 TEST_P(ChunkDemuxerTest, InitText) { |
| 1053 // Test with 1 video stream and 1 text streams, and 0 or 1 audio streams. | 1062 // Test with 1 video stream and 1 text streams, and 0 or 1 audio streams. |
| 1054 // No encryption cases handled here. | 1063 // No encryption cases handled here. |
| 1055 bool has_video = true; | 1064 bool has_video = true; |
| 1056 bool is_audio_encrypted = false; | 1065 bool is_audio_encrypted = false; |
| 1057 bool is_video_encrypted = false; | 1066 bool is_video_encrypted = false; |
| 1058 for (int i = 0; i < 2; i++) { | 1067 for (int i = 0; i < 2; i++) { |
| 1059 bool has_audio = (i & 0x1) != 0; | 1068 bool has_audio = (i & 0x1) != 0; |
| 1060 | 1069 |
| 1061 CreateNewDemuxer(); | 1070 CreateNewDemuxer(); |
| 1062 | 1071 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 EXPECT_FALSE(video_stream); | 1115 EXPECT_FALSE(video_stream); |
| 1107 } | 1116 } |
| 1108 | 1117 |
| 1109 ShutdownDemuxer(); | 1118 ShutdownDemuxer(); |
| 1110 demuxer_.reset(); | 1119 demuxer_.reset(); |
| 1111 } | 1120 } |
| 1112 } | 1121 } |
| 1113 | 1122 |
| 1114 // Make sure that the demuxer reports an error if Shutdown() | 1123 // Make sure that the demuxer reports an error if Shutdown() |
| 1115 // is called before all the initialization segments are appended. | 1124 // is called before all the initialization segments are appended. |
| 1116 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { | 1125 TEST_P(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { |
| 1117 EXPECT_CALL(*this, DemuxerOpened()); | 1126 EXPECT_CALL(*this, DemuxerOpened()); |
| 1118 demuxer_->Initialize( | 1127 demuxer_->Initialize( |
| 1119 &host_, CreateInitDoneCB( | 1128 &host_, CreateInitDoneCB( |
| 1120 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1129 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); |
| 1121 | 1130 |
| 1122 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); | 1131 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); |
| 1123 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); | 1132 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); |
| 1124 | 1133 |
| 1125 AppendInitSegmentWithSourceId("audio", HAS_AUDIO); | 1134 AppendInitSegmentWithSourceId("audio", HAS_AUDIO); |
| 1126 | 1135 |
| 1127 ShutdownDemuxer(); | 1136 ShutdownDemuxer(); |
| 1128 } | 1137 } |
| 1129 | 1138 |
| 1130 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) { | 1139 TEST_P(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) { |
| 1131 EXPECT_CALL(*this, DemuxerOpened()); | 1140 EXPECT_CALL(*this, DemuxerOpened()); |
| 1132 demuxer_->Initialize( | 1141 demuxer_->Initialize( |
| 1133 &host_, CreateInitDoneCB( | 1142 &host_, CreateInitDoneCB( |
| 1134 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1143 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); |
| 1135 | 1144 |
| 1136 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); | 1145 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); |
| 1137 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); | 1146 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); |
| 1138 | 1147 |
| 1139 EXPECT_CALL(host_, AddTextStream(_, _)) | 1148 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 1140 .Times(Exactly(1)); | 1149 .Times(Exactly(1)); |
| 1141 | 1150 |
| 1142 AppendInitSegmentWithSourceId("video_and_text", HAS_VIDEO | HAS_TEXT); | 1151 AppendInitSegmentWithSourceId("video_and_text", HAS_VIDEO | HAS_TEXT); |
| 1143 | 1152 |
| 1144 ShutdownDemuxer(); | 1153 ShutdownDemuxer(); |
| 1145 } | 1154 } |
| 1146 | 1155 |
| 1147 // Verifies that all streams waiting for data receive an end of stream | 1156 // Verifies that all streams waiting for data receive an end of stream |
| 1148 // buffer when Shutdown() is called. | 1157 // buffer when Shutdown() is called. |
| 1149 TEST_F(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) { | 1158 TEST_P(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) { |
| 1150 DemuxerStream* text_stream = NULL; | 1159 DemuxerStream* text_stream = NULL; |
| 1151 EXPECT_CALL(host_, AddTextStream(_, _)) | 1160 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 1152 .WillOnce(SaveArg<0>(&text_stream)); | 1161 .WillOnce(SaveArg<0>(&text_stream)); |
| 1153 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 1162 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
| 1154 | 1163 |
| 1155 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1164 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 1156 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1165 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 1157 | 1166 |
| 1158 bool audio_read_done = false; | 1167 bool audio_read_done = false; |
| 1159 bool video_read_done = false; | 1168 bool video_read_done = false; |
| 1160 bool text_read_done = false; | 1169 bool text_read_done = false; |
| 1161 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); | 1170 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); |
| 1162 video_stream->Read(base::Bind(&OnReadDone_EOSExpected, &video_read_done)); | 1171 video_stream->Read(base::Bind(&OnReadDone_EOSExpected, &video_read_done)); |
| 1163 text_stream->Read(base::Bind(&OnReadDone_EOSExpected, &text_read_done)); | 1172 text_stream->Read(base::Bind(&OnReadDone_EOSExpected, &text_read_done)); |
| 1164 message_loop_.RunUntilIdle(); | 1173 message_loop_.RunUntilIdle(); |
| 1165 | 1174 |
| 1166 EXPECT_FALSE(audio_read_done); | 1175 EXPECT_FALSE(audio_read_done); |
| 1167 EXPECT_FALSE(video_read_done); | 1176 EXPECT_FALSE(video_read_done); |
| 1168 EXPECT_FALSE(text_read_done); | 1177 EXPECT_FALSE(text_read_done); |
| 1169 | 1178 |
| 1170 ShutdownDemuxer(); | 1179 ShutdownDemuxer(); |
| 1171 | 1180 |
| 1172 EXPECT_TRUE(audio_read_done); | 1181 EXPECT_TRUE(audio_read_done); |
| 1173 EXPECT_TRUE(video_read_done); | 1182 EXPECT_TRUE(video_read_done); |
| 1174 EXPECT_TRUE(text_read_done); | 1183 EXPECT_TRUE(text_read_done); |
| 1175 } | 1184 } |
| 1176 | 1185 |
| 1177 // Test that Seek() completes successfully when the first cluster | 1186 // Test that Seek() completes successfully when the first cluster |
| 1178 // arrives. | 1187 // arrives. |
| 1179 TEST_F(ChunkDemuxerTest, AppendDataAfterSeek) { | 1188 TEST_P(ChunkDemuxerTest, AppendDataAfterSeek) { |
| 1180 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1189 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1181 AppendCluster(kDefaultFirstCluster()); | 1190 AppendCluster(kDefaultFirstCluster()); |
| 1182 | 1191 |
| 1183 InSequence s; | 1192 InSequence s; |
| 1184 | 1193 |
| 1185 EXPECT_CALL(*this, Checkpoint(1)); | 1194 EXPECT_CALL(*this, Checkpoint(1)); |
| 1186 | 1195 |
| 1187 Seek(base::TimeDelta::FromMilliseconds(46)); | 1196 Seek(base::TimeDelta::FromMilliseconds(46)); |
| 1188 | 1197 |
| 1189 EXPECT_CALL(*this, Checkpoint(2)); | 1198 EXPECT_CALL(*this, Checkpoint(2)); |
| 1190 | 1199 |
| 1191 Checkpoint(1); | 1200 Checkpoint(1); |
| 1192 | 1201 |
| 1193 AppendCluster(kDefaultSecondCluster()); | 1202 AppendCluster(kDefaultSecondCluster()); |
| 1194 | 1203 |
| 1195 message_loop_.RunUntilIdle(); | 1204 message_loop_.RunUntilIdle(); |
| 1196 | 1205 |
| 1197 Checkpoint(2); | 1206 Checkpoint(2); |
| 1198 } | 1207 } |
| 1199 | 1208 |
| 1200 // Test that parsing errors are handled for clusters appended after init. | 1209 // Test that parsing errors are handled for clusters appended after init. |
| 1201 TEST_F(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) { | 1210 TEST_P(ChunkDemuxerTest, ErrorWhileParsingClusterAfterInit) { |
| 1202 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1211 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1203 AppendCluster(kDefaultFirstCluster()); | 1212 AppendCluster(kDefaultFirstCluster()); |
| 1204 | 1213 |
| 1205 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 1214 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
| 1206 AppendGarbage(); | 1215 AppendGarbage(); |
| 1207 } | 1216 } |
| 1208 | 1217 |
| 1209 // Test the case where a Seek() is requested while the parser | 1218 // Test the case where a Seek() is requested while the parser |
| 1210 // is in the middle of cluster. This is to verify that the parser | 1219 // is in the middle of cluster. This is to verify that the parser |
| 1211 // does not reset itself on a seek. | 1220 // does not reset itself on a seek. |
| 1212 TEST_F(ChunkDemuxerTest, SeekWhileParsingCluster) { | 1221 TEST_P(ChunkDemuxerTest, SeekWhileParsingCluster) { |
| 1213 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1222 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1214 | 1223 |
| 1215 InSequence s; | 1224 InSequence s; |
| 1216 | 1225 |
| 1217 scoped_ptr<Cluster> cluster_a(GenerateCluster(0, 6)); | 1226 scoped_ptr<Cluster> cluster_a(GenerateCluster(0, 6)); |
| 1218 | 1227 |
| 1219 // Split the cluster into two appends at an arbitrary point near the end. | 1228 // Split the cluster into two appends at an arbitrary point near the end. |
| 1220 int first_append_size = cluster_a->size() - 11; | 1229 int first_append_size = cluster_a->size() - 11; |
| 1221 int second_append_size = cluster_a->size() - first_append_size; | 1230 int second_append_size = cluster_a->size() - first_append_size; |
| 1222 | 1231 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1236 // Append the rest of the cluster. | 1245 // Append the rest of the cluster. |
| 1237 AppendData(cluster_a->data() + first_append_size, second_append_size); | 1246 AppendData(cluster_a->data() + first_append_size, second_append_size); |
| 1238 | 1247 |
| 1239 // Append the new cluster and verify that only the blocks | 1248 // Append the new cluster and verify that only the blocks |
| 1240 // in the new cluster are returned. | 1249 // in the new cluster are returned. |
| 1241 AppendCluster(GenerateCluster(5000, 6)); | 1250 AppendCluster(GenerateCluster(5000, 6)); |
| 1242 GenerateExpectedReads(5000, 6); | 1251 GenerateExpectedReads(5000, 6); |
| 1243 } | 1252 } |
| 1244 | 1253 |
| 1245 // Test the case where AppendData() is called before Init(). | 1254 // Test the case where AppendData() is called before Init(). |
| 1246 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) { | 1255 TEST_P(ChunkDemuxerTest, AppendDataBeforeInit) { |
| 1247 scoped_ptr<uint8[]> info_tracks; | 1256 scoped_ptr<uint8[]> info_tracks; |
| 1248 int info_tracks_size = 0; | 1257 int info_tracks_size = 0; |
| 1249 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, | 1258 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, |
| 1250 false, false, &info_tracks, &info_tracks_size); | 1259 false, false, &info_tracks, &info_tracks_size); |
| 1251 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, | 1260 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, |
| 1252 append_window_start_for_next_append_, | 1261 append_window_start_for_next_append_, |
| 1253 append_window_end_for_next_append_, | 1262 append_window_end_for_next_append_, |
| 1254 ×tamp_offset_map_[kSourceId]); | 1263 ×tamp_offset_map_[kSourceId]); |
| 1255 } | 1264 } |
| 1256 | 1265 |
| 1257 // Make sure Read() callbacks are dispatched with the proper data. | 1266 // Make sure Read() callbacks are dispatched with the proper data. |
| 1258 TEST_F(ChunkDemuxerTest, Read) { | 1267 TEST_P(ChunkDemuxerTest, Read) { |
| 1259 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1268 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1260 | 1269 |
| 1261 AppendCluster(kDefaultFirstCluster()); | 1270 AppendCluster(kDefaultFirstCluster()); |
| 1262 | 1271 |
| 1263 bool audio_read_done = false; | 1272 bool audio_read_done = false; |
| 1264 bool video_read_done = false; | 1273 bool video_read_done = false; |
| 1265 ReadAudio(base::Bind(&OnReadDone, | 1274 ReadAudio(base::Bind(&OnReadDone, |
| 1266 base::TimeDelta::FromMilliseconds(0), | 1275 base::TimeDelta::FromMilliseconds(0), |
| 1267 &audio_read_done)); | 1276 &audio_read_done)); |
| 1268 ReadVideo(base::Bind(&OnReadDone, | 1277 ReadVideo(base::Bind(&OnReadDone, |
| 1269 base::TimeDelta::FromMilliseconds(0), | 1278 base::TimeDelta::FromMilliseconds(0), |
| 1270 &video_read_done)); | 1279 &video_read_done)); |
| 1271 | 1280 |
| 1272 EXPECT_TRUE(audio_read_done); | 1281 EXPECT_TRUE(audio_read_done); |
| 1273 EXPECT_TRUE(video_read_done); | 1282 EXPECT_TRUE(video_read_done); |
| 1274 } | 1283 } |
| 1275 | 1284 |
| 1276 TEST_F(ChunkDemuxerTest, OutOfOrderClusters) { | 1285 TEST_P(ChunkDemuxerTest, OutOfOrderClusters) { |
| 1277 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1286 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1278 AppendCluster(kDefaultFirstCluster()); | 1287 AppendCluster(kDefaultFirstCluster()); |
| 1279 AppendCluster(GenerateCluster(10, 4)); | 1288 AppendCluster(GenerateCluster(10, 4)); |
| 1280 | 1289 |
| 1281 // Make sure that AppendCluster() does not fail with a cluster that has | 1290 // Make sure that AppendCluster() does not fail with a cluster that has |
| 1282 // overlaps with the previously appended cluster. | 1291 // overlaps with the previously appended cluster. |
| 1283 AppendCluster(GenerateCluster(5, 4)); | 1292 AppendCluster(GenerateCluster(5, 4)); |
| 1284 | 1293 |
| 1285 // Verify that AppendData() can still accept more data. | 1294 // Verify that AppendData() can still accept more data. |
| 1286 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); | 1295 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); |
| 1287 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(), | 1296 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(), |
| 1288 append_window_start_for_next_append_, | 1297 append_window_start_for_next_append_, |
| 1289 append_window_end_for_next_append_, | 1298 append_window_end_for_next_append_, |
| 1290 ×tamp_offset_map_[kSourceId]); | 1299 ×tamp_offset_map_[kSourceId]); |
| 1291 } | 1300 } |
| 1292 | 1301 |
| 1293 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { | 1302 TEST_P(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { |
| 1294 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1303 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1295 AppendCluster(kDefaultFirstCluster()); | 1304 AppendCluster(kDefaultFirstCluster()); |
| 1296 | 1305 |
| 1297 ClusterBuilder cb; | 1306 ClusterBuilder cb; |
| 1298 | 1307 |
| 1299 // Test the case where block timecodes are not monotonically | 1308 // Test the case where block timecodes are not monotonically |
| 1300 // increasing but stay above the cluster timecode. | 1309 // increasing but stay above the cluster timecode. |
| 1301 cb.SetClusterTimecode(5); | 1310 cb.SetClusterTimecode(5); |
| 1302 AddSimpleBlock(&cb, kAudioTrackNum, 5); | 1311 AddSimpleBlock(&cb, kAudioTrackNum, 5); |
| 1303 AddSimpleBlock(&cb, kVideoTrackNum, 10); | 1312 AddSimpleBlock(&cb, kVideoTrackNum, 10); |
| 1304 AddSimpleBlock(&cb, kAudioTrackNum, 7); | 1313 AddSimpleBlock(&cb, kAudioTrackNum, 7); |
| 1305 AddSimpleBlock(&cb, kVideoTrackNum, 15); | 1314 AddSimpleBlock(&cb, kVideoTrackNum, 15); |
| 1306 | 1315 |
| 1307 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 1316 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
| 1308 AppendCluster(cb.Finish()); | 1317 AppendCluster(cb.Finish()); |
| 1309 | 1318 |
| 1310 // Verify that AppendData() ignores data after the error. | 1319 // Verify that AppendData() ignores data after the error. |
| 1311 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); | 1320 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); |
| 1312 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), | 1321 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), |
| 1313 append_window_start_for_next_append_, | 1322 append_window_start_for_next_append_, |
| 1314 append_window_end_for_next_append_, | 1323 append_window_end_for_next_append_, |
| 1315 ×tamp_offset_map_[kSourceId]); | 1324 ×tamp_offset_map_[kSourceId]); |
| 1316 } | 1325 } |
| 1317 | 1326 |
| 1318 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { | 1327 TEST_P(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { |
| 1319 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1328 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1320 AppendCluster(kDefaultFirstCluster()); | 1329 AppendCluster(kDefaultFirstCluster()); |
| 1321 | 1330 |
| 1322 ClusterBuilder cb; | 1331 ClusterBuilder cb; |
| 1323 | 1332 |
| 1324 // Test timecodes going backwards and including values less than the cluster | 1333 // Test timecodes going backwards and including values less than the cluster |
| 1325 // timecode. | 1334 // timecode. |
| 1326 cb.SetClusterTimecode(5); | 1335 cb.SetClusterTimecode(5); |
| 1327 AddSimpleBlock(&cb, kAudioTrackNum, 5); | 1336 AddSimpleBlock(&cb, kAudioTrackNum, 5); |
| 1328 AddSimpleBlock(&cb, kVideoTrackNum, 5); | 1337 AddSimpleBlock(&cb, kVideoTrackNum, 5); |
| 1329 AddSimpleBlock(&cb, kAudioTrackNum, 3); | 1338 AddSimpleBlock(&cb, kAudioTrackNum, 3); |
| 1330 AddSimpleBlock(&cb, kVideoTrackNum, 3); | 1339 AddSimpleBlock(&cb, kVideoTrackNum, 3); |
| 1331 | 1340 |
| 1332 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 1341 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
| 1333 AppendCluster(cb.Finish()); | 1342 AppendCluster(cb.Finish()); |
| 1334 | 1343 |
| 1335 // Verify that AppendData() ignores data after the error. | 1344 // Verify that AppendData() ignores data after the error. |
| 1336 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); | 1345 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); |
| 1337 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), | 1346 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), |
| 1338 append_window_start_for_next_append_, | 1347 append_window_start_for_next_append_, |
| 1339 append_window_end_for_next_append_, | 1348 append_window_end_for_next_append_, |
| 1340 ×tamp_offset_map_[kSourceId]); | 1349 ×tamp_offset_map_[kSourceId]); |
| 1341 } | 1350 } |
| 1342 | 1351 |
| 1343 | 1352 |
| 1344 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { | 1353 TEST_P(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { |
| 1345 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1354 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1346 AppendCluster(kDefaultFirstCluster()); | 1355 AppendCluster(kDefaultFirstCluster()); |
| 1347 | 1356 |
| 1348 ClusterBuilder cb; | 1357 ClusterBuilder cb; |
| 1349 | 1358 |
| 1350 // Test monotonic increasing timestamps on a per stream | 1359 // Test monotonic increasing timestamps on a per stream |
| 1351 // basis. | 1360 // basis. |
| 1352 cb.SetClusterTimecode(5); | 1361 cb.SetClusterTimecode(5); |
| 1353 AddSimpleBlock(&cb, kAudioTrackNum, 5); | 1362 AddSimpleBlock(&cb, kAudioTrackNum, 5); |
| 1354 AddSimpleBlock(&cb, kVideoTrackNum, 5); | 1363 AddSimpleBlock(&cb, kVideoTrackNum, 5); |
| 1355 AddSimpleBlock(&cb, kAudioTrackNum, 4); | 1364 AddSimpleBlock(&cb, kAudioTrackNum, 4); |
| 1356 AddSimpleBlock(&cb, kVideoTrackNum, 7); | 1365 AddSimpleBlock(&cb, kVideoTrackNum, 7); |
| 1357 | 1366 |
| 1358 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 1367 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
| 1359 AppendCluster(cb.Finish()); | 1368 AppendCluster(cb.Finish()); |
| 1360 } | 1369 } |
| 1361 | 1370 |
| 1362 // Test the case where a cluster is passed to AppendCluster() before | 1371 // Test the case where a cluster is passed to AppendCluster() before |
| 1363 // INFO & TRACKS data. | 1372 // INFO & TRACKS data. |
| 1364 TEST_F(ChunkDemuxerTest, ClusterBeforeInitSegment) { | 1373 TEST_P(ChunkDemuxerTest, ClusterBeforeInitSegment) { |
| 1365 EXPECT_CALL(*this, DemuxerOpened()); | 1374 EXPECT_CALL(*this, DemuxerOpened()); |
| 1366 demuxer_->Initialize( | 1375 demuxer_->Initialize( |
| 1367 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1376 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); |
| 1368 | 1377 |
| 1369 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); | 1378 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); |
| 1370 | 1379 |
| 1371 AppendCluster(GenerateCluster(0, 1)); | 1380 AppendCluster(GenerateCluster(0, 1)); |
| 1372 } | 1381 } |
| 1373 | 1382 |
| 1374 // Test cases where we get an MarkEndOfStream() call during initialization. | 1383 // Test cases where we get an MarkEndOfStream() call during initialization. |
| 1375 TEST_F(ChunkDemuxerTest, EOSDuringInit) { | 1384 TEST_P(ChunkDemuxerTest, EOSDuringInit) { |
| 1376 EXPECT_CALL(*this, DemuxerOpened()); | 1385 EXPECT_CALL(*this, DemuxerOpened()); |
| 1377 demuxer_->Initialize( | 1386 demuxer_->Initialize( |
| 1378 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1387 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); |
| 1379 MarkEndOfStream(PIPELINE_OK); | 1388 MarkEndOfStream(PIPELINE_OK); |
| 1380 } | 1389 } |
| 1381 | 1390 |
| 1382 TEST_F(ChunkDemuxerTest, EndOfStreamWithNoAppend) { | 1391 TEST_P(ChunkDemuxerTest, EndOfStreamWithNoAppend) { |
| 1383 EXPECT_CALL(*this, DemuxerOpened()); | 1392 EXPECT_CALL(*this, DemuxerOpened()); |
| 1384 demuxer_->Initialize( | 1393 demuxer_->Initialize( |
| 1385 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1394 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); |
| 1386 | 1395 |
| 1387 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); | 1396 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); |
| 1388 | 1397 |
| 1389 CheckExpectedRanges("{ }"); | 1398 CheckExpectedRanges("{ }"); |
| 1390 MarkEndOfStream(PIPELINE_OK); | 1399 MarkEndOfStream(PIPELINE_OK); |
| 1391 ShutdownDemuxer(); | 1400 ShutdownDemuxer(); |
| 1392 CheckExpectedRanges("{ }"); | 1401 CheckExpectedRanges("{ }"); |
| 1393 demuxer_->RemoveId(kSourceId); | 1402 demuxer_->RemoveId(kSourceId); |
| 1394 demuxer_.reset(); | 1403 demuxer_.reset(); |
| 1395 } | 1404 } |
| 1396 | 1405 |
| 1397 TEST_F(ChunkDemuxerTest, EndOfStreamWithNoMediaAppend) { | 1406 TEST_P(ChunkDemuxerTest, EndOfStreamWithNoMediaAppend) { |
| 1398 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1407 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1399 | 1408 |
| 1400 CheckExpectedRanges("{ }"); | 1409 CheckExpectedRanges("{ }"); |
| 1401 MarkEndOfStream(PIPELINE_OK); | 1410 MarkEndOfStream(PIPELINE_OK); |
| 1402 CheckExpectedRanges("{ }"); | 1411 CheckExpectedRanges("{ }"); |
| 1403 } | 1412 } |
| 1404 | 1413 |
| 1405 TEST_F(ChunkDemuxerTest, DecodeErrorEndOfStream) { | 1414 TEST_P(ChunkDemuxerTest, DecodeErrorEndOfStream) { |
| 1406 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1415 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1407 | 1416 |
| 1408 AppendCluster(kDefaultFirstCluster()); | 1417 AppendCluster(kDefaultFirstCluster()); |
| 1409 CheckExpectedRanges(kDefaultFirstClusterRange); | 1418 CheckExpectedRanges(kDefaultFirstClusterRange); |
| 1410 | 1419 |
| 1411 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 1420 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
| 1412 MarkEndOfStream(PIPELINE_ERROR_DECODE); | 1421 MarkEndOfStream(PIPELINE_ERROR_DECODE); |
| 1413 CheckExpectedRanges(kDefaultFirstClusterRange); | 1422 CheckExpectedRanges(kDefaultFirstClusterRange); |
| 1414 } | 1423 } |
| 1415 | 1424 |
| 1416 TEST_F(ChunkDemuxerTest, NetworkErrorEndOfStream) { | 1425 TEST_P(ChunkDemuxerTest, NetworkErrorEndOfStream) { |
| 1417 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1426 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1418 | 1427 |
| 1419 AppendCluster(kDefaultFirstCluster()); | 1428 AppendCluster(kDefaultFirstCluster()); |
| 1420 CheckExpectedRanges(kDefaultFirstClusterRange); | 1429 CheckExpectedRanges(kDefaultFirstClusterRange); |
| 1421 | 1430 |
| 1422 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_NETWORK)); | 1431 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_NETWORK)); |
| 1423 MarkEndOfStream(PIPELINE_ERROR_NETWORK); | 1432 MarkEndOfStream(PIPELINE_ERROR_NETWORK); |
| 1424 } | 1433 } |
| 1425 | 1434 |
| 1426 // Helper class to reduce duplicate code when testing end of stream | 1435 // Helper class to reduce duplicate code when testing end of stream |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 | 1475 |
| 1467 Demuxer* demuxer_; | 1476 Demuxer* demuxer_; |
| 1468 bool audio_read_done_; | 1477 bool audio_read_done_; |
| 1469 bool video_read_done_; | 1478 bool video_read_done_; |
| 1470 | 1479 |
| 1471 DISALLOW_COPY_AND_ASSIGN(EndOfStreamHelper); | 1480 DISALLOW_COPY_AND_ASSIGN(EndOfStreamHelper); |
| 1472 }; | 1481 }; |
| 1473 | 1482 |
| 1474 // Make sure that all pending reads that we don't have media data for get an | 1483 // Make sure that all pending reads that we don't have media data for get an |
| 1475 // "end of stream" buffer when MarkEndOfStream() is called. | 1484 // "end of stream" buffer when MarkEndOfStream() is called. |
| 1476 TEST_F(ChunkDemuxerTest, EndOfStreamWithPendingReads) { | 1485 TEST_P(ChunkDemuxerTest, EndOfStreamWithPendingReads) { |
| 1477 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1486 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1478 | 1487 |
| 1479 AppendCluster(GenerateCluster(0, 2)); | 1488 AppendCluster(GenerateCluster(0, 2)); |
| 1480 | 1489 |
| 1481 bool audio_read_done_1 = false; | 1490 bool audio_read_done_1 = false; |
| 1482 bool video_read_done_1 = false; | 1491 bool video_read_done_1 = false; |
| 1483 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get()); | 1492 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get()); |
| 1484 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get()); | 1493 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get()); |
| 1485 | 1494 |
| 1486 ReadAudio(base::Bind(&OnReadDone, | 1495 ReadAudio(base::Bind(&OnReadDone, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1501 MarkEndOfStream(PIPELINE_OK); | 1510 MarkEndOfStream(PIPELINE_OK); |
| 1502 | 1511 |
| 1503 end_of_stream_helper_1.CheckIfReadDonesWereCalled(true); | 1512 end_of_stream_helper_1.CheckIfReadDonesWereCalled(true); |
| 1504 | 1513 |
| 1505 end_of_stream_helper_2.RequestReads(); | 1514 end_of_stream_helper_2.RequestReads(); |
| 1506 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true); | 1515 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true); |
| 1507 } | 1516 } |
| 1508 | 1517 |
| 1509 // Make sure that all Read() calls after we get an MarkEndOfStream() | 1518 // Make sure that all Read() calls after we get an MarkEndOfStream() |
| 1510 // call return an "end of stream" buffer. | 1519 // call return an "end of stream" buffer. |
| 1511 TEST_F(ChunkDemuxerTest, ReadsAfterEndOfStream) { | 1520 TEST_P(ChunkDemuxerTest, ReadsAfterEndOfStream) { |
| 1512 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1521 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1513 | 1522 |
| 1514 AppendCluster(GenerateCluster(0, 2)); | 1523 AppendCluster(GenerateCluster(0, 2)); |
| 1515 | 1524 |
| 1516 bool audio_read_done_1 = false; | 1525 bool audio_read_done_1 = false; |
| 1517 bool video_read_done_1 = false; | 1526 bool video_read_done_1 = false; |
| 1518 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get()); | 1527 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get()); |
| 1519 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get()); | 1528 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get()); |
| 1520 EndOfStreamHelper end_of_stream_helper_3(demuxer_.get()); | 1529 EndOfStreamHelper end_of_stream_helper_3(demuxer_.get()); |
| 1521 | 1530 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1540 | 1549 |
| 1541 // Request a few more reads and make sure we immediately get | 1550 // Request a few more reads and make sure we immediately get |
| 1542 // end of stream buffers. | 1551 // end of stream buffers. |
| 1543 end_of_stream_helper_2.RequestReads(); | 1552 end_of_stream_helper_2.RequestReads(); |
| 1544 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true); | 1553 end_of_stream_helper_2.CheckIfReadDonesWereCalled(true); |
| 1545 | 1554 |
| 1546 end_of_stream_helper_3.RequestReads(); | 1555 end_of_stream_helper_3.RequestReads(); |
| 1547 end_of_stream_helper_3.CheckIfReadDonesWereCalled(true); | 1556 end_of_stream_helper_3.CheckIfReadDonesWereCalled(true); |
| 1548 } | 1557 } |
| 1549 | 1558 |
| 1550 TEST_F(ChunkDemuxerTest, EndOfStreamDuringCanceledSeek) { | 1559 TEST_P(ChunkDemuxerTest, EndOfStreamDuringCanceledSeek) { |
| 1551 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1560 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1552 | 1561 |
| 1553 AppendCluster(0, 10); | 1562 AppendCluster(0, 10); |
| 1554 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(138))); | 1563 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(138))); |
| 1555 MarkEndOfStream(PIPELINE_OK); | 1564 MarkEndOfStream(PIPELINE_OK); |
| 1556 | 1565 |
| 1557 // Start the first seek. | 1566 // Start the first seek. |
| 1558 Seek(base::TimeDelta::FromMilliseconds(20)); | 1567 Seek(base::TimeDelta::FromMilliseconds(20)); |
| 1559 | 1568 |
| 1560 // Simulate another seek being requested before the first | 1569 // Simulate another seek being requested before the first |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1571 // Make sure audio can reach end of stream. | 1580 // Make sure audio can reach end of stream. |
| 1572 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); | 1581 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); |
| 1573 ASSERT_EQ(status, DemuxerStream::kOk); | 1582 ASSERT_EQ(status, DemuxerStream::kOk); |
| 1574 | 1583 |
| 1575 // Make sure video can reach end of stream. | 1584 // Make sure video can reach end of stream. |
| 1576 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); | 1585 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); |
| 1577 ASSERT_EQ(status, DemuxerStream::kOk); | 1586 ASSERT_EQ(status, DemuxerStream::kOk); |
| 1578 } | 1587 } |
| 1579 | 1588 |
| 1580 // Verify buffered range change behavior for audio/video/text tracks. | 1589 // Verify buffered range change behavior for audio/video/text tracks. |
| 1581 TEST_F(ChunkDemuxerTest, EndOfStreamRangeChanges) { | 1590 TEST_P(ChunkDemuxerTest, EndOfStreamRangeChanges) { |
| 1582 DemuxerStream* text_stream = NULL; | 1591 DemuxerStream* text_stream = NULL; |
| 1583 | 1592 |
| 1584 EXPECT_CALL(host_, AddTextStream(_, _)) | 1593 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 1585 .WillOnce(SaveArg<0>(&text_stream)); | 1594 .WillOnce(SaveArg<0>(&text_stream)); |
| 1586 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 1595 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
| 1587 | 1596 |
| 1588 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); | 1597 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); |
| 1589 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K"); | 1598 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K"); |
| 1590 | 1599 |
| 1591 // Check expected ranges and verify that an empty text track does not | 1600 // Check expected ranges and verify that an empty text track does not |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1610 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K"); | 1619 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K"); |
| 1611 CheckExpectedRanges(kSourceId, "{ [0,46) }"); | 1620 CheckExpectedRanges(kSourceId, "{ [0,46) }"); |
| 1612 | 1621 |
| 1613 // Mark end of stream and verify that text track data is reflected in | 1622 // Mark end of stream and verify that text track data is reflected in |
| 1614 // the new range. | 1623 // the new range. |
| 1615 MarkEndOfStream(PIPELINE_OK); | 1624 MarkEndOfStream(PIPELINE_OK); |
| 1616 CheckExpectedRanges(kSourceId, "{ [0,200) }"); | 1625 CheckExpectedRanges(kSourceId, "{ [0,200) }"); |
| 1617 } | 1626 } |
| 1618 | 1627 |
| 1619 // Make sure AppendData() will accept elements that span multiple calls. | 1628 // Make sure AppendData() will accept elements that span multiple calls. |
| 1620 TEST_F(ChunkDemuxerTest, AppendingInPieces) { | 1629 TEST_P(ChunkDemuxerTest, AppendingInPieces) { |
| 1621 EXPECT_CALL(*this, DemuxerOpened()); | 1630 EXPECT_CALL(*this, DemuxerOpened()); |
| 1622 demuxer_->Initialize( | 1631 demuxer_->Initialize( |
| 1623 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); | 1632 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); |
| 1624 | 1633 |
| 1625 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); | 1634 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); |
| 1626 | 1635 |
| 1627 scoped_ptr<uint8[]> info_tracks; | 1636 scoped_ptr<uint8[]> info_tracks; |
| 1628 int info_tracks_size = 0; | 1637 int info_tracks_size = 0; |
| 1629 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, | 1638 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, |
| 1630 false, false, &info_tracks, &info_tracks_size); | 1639 false, false, &info_tracks, &info_tracks_size); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1642 dst += cluster_a->size(); | 1651 dst += cluster_a->size(); |
| 1643 | 1652 |
| 1644 memcpy(dst, cluster_b->data(), cluster_b->size()); | 1653 memcpy(dst, cluster_b->data(), cluster_b->size()); |
| 1645 dst += cluster_b->size(); | 1654 dst += cluster_b->size(); |
| 1646 | 1655 |
| 1647 AppendDataInPieces(buffer.get(), buffer_size); | 1656 AppendDataInPieces(buffer.get(), buffer_size); |
| 1648 | 1657 |
| 1649 GenerateExpectedReads(0, 9); | 1658 GenerateExpectedReads(0, 9); |
| 1650 } | 1659 } |
| 1651 | 1660 |
| 1652 TEST_F(ChunkDemuxerTest, WebMFile_AudioAndVideo) { | 1661 TEST_P(ChunkDemuxerTest, WebMFile_AudioAndVideo) { |
| 1653 struct BufferTimestamps buffer_timestamps[] = { | 1662 struct BufferTimestamps buffer_timestamps[] = { |
| 1654 {0, 0}, | 1663 {0, 0}, |
| 1655 {33, 3}, | 1664 {33, 3}, |
| 1656 {67, 6}, | 1665 {67, 6}, |
| 1657 {100, 9}, | 1666 {100, 9}, |
| 1658 {133, 12}, | 1667 {133, 12}, |
| 1659 {kSkip, kSkip}, | 1668 {kSkip, kSkip}, |
| 1660 }; | 1669 }; |
| 1661 | 1670 |
| 1662 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the | 1671 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the |
| 1663 // ParseWebMFile() call's expected duration, below, once the file is fixed to | 1672 // ParseWebMFile() call's expected duration, below, once the file is fixed to |
| 1664 // have the correct duration in the init segment. See http://crbug.com/354284. | 1673 // have the correct duration in the init segment. See http://crbug.com/354284. |
| 1665 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2768))); | 1674 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2768))); |
| 1666 | 1675 |
| 1667 ASSERT_TRUE(ParseWebMFile("bear-320x240.webm", buffer_timestamps, | 1676 ASSERT_TRUE(ParseWebMFile("bear-320x240.webm", buffer_timestamps, |
| 1668 base::TimeDelta::FromMilliseconds(2744))); | 1677 base::TimeDelta::FromMilliseconds(2744))); |
| 1669 } | 1678 } |
| 1670 | 1679 |
| 1671 TEST_F(ChunkDemuxerTest, WebMFile_LiveAudioAndVideo) { | 1680 TEST_P(ChunkDemuxerTest, WebMFile_LiveAudioAndVideo) { |
| 1672 struct BufferTimestamps buffer_timestamps[] = { | 1681 struct BufferTimestamps buffer_timestamps[] = { |
| 1673 {0, 0}, | 1682 {0, 0}, |
| 1674 {33, 3}, | 1683 {33, 3}, |
| 1675 {67, 6}, | 1684 {67, 6}, |
| 1676 {100, 9}, | 1685 {100, 9}, |
| 1677 {133, 12}, | 1686 {133, 12}, |
| 1678 {kSkip, kSkip}, | 1687 {kSkip, kSkip}, |
| 1679 }; | 1688 }; |
| 1680 | 1689 |
| 1681 ASSERT_TRUE(ParseWebMFile("bear-320x240-live.webm", buffer_timestamps, | 1690 ASSERT_TRUE(ParseWebMFile("bear-320x240-live.webm", buffer_timestamps, |
| 1682 kInfiniteDuration())); | 1691 kInfiniteDuration())); |
| 1683 } | 1692 } |
| 1684 | 1693 |
| 1685 TEST_F(ChunkDemuxerTest, WebMFile_AudioOnly) { | 1694 TEST_P(ChunkDemuxerTest, WebMFile_AudioOnly) { |
| 1686 struct BufferTimestamps buffer_timestamps[] = { | 1695 struct BufferTimestamps buffer_timestamps[] = { |
| 1687 {kSkip, 0}, | 1696 {kSkip, 0}, |
| 1688 {kSkip, 3}, | 1697 {kSkip, 3}, |
| 1689 {kSkip, 6}, | 1698 {kSkip, 6}, |
| 1690 {kSkip, 9}, | 1699 {kSkip, 9}, |
| 1691 {kSkip, 12}, | 1700 {kSkip, 12}, |
| 1692 {kSkip, kSkip}, | 1701 {kSkip, kSkip}, |
| 1693 }; | 1702 }; |
| 1694 | 1703 |
| 1695 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the | 1704 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the |
| 1696 // ParseWebMFile() call's expected duration, below, once the file is fixed to | 1705 // ParseWebMFile() call's expected duration, below, once the file is fixed to |
| 1697 // have the correct duration in the init segment. See http://crbug.com/354284. | 1706 // have the correct duration in the init segment. See http://crbug.com/354284. |
| 1698 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2768))); | 1707 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2768))); |
| 1699 | 1708 |
| 1700 ASSERT_TRUE(ParseWebMFile("bear-320x240-audio-only.webm", buffer_timestamps, | 1709 ASSERT_TRUE(ParseWebMFile("bear-320x240-audio-only.webm", buffer_timestamps, |
| 1701 base::TimeDelta::FromMilliseconds(2744), | 1710 base::TimeDelta::FromMilliseconds(2744), |
| 1702 HAS_AUDIO)); | 1711 HAS_AUDIO)); |
| 1703 } | 1712 } |
| 1704 | 1713 |
| 1705 TEST_F(ChunkDemuxerTest, WebMFile_VideoOnly) { | 1714 TEST_P(ChunkDemuxerTest, WebMFile_VideoOnly) { |
| 1706 struct BufferTimestamps buffer_timestamps[] = { | 1715 struct BufferTimestamps buffer_timestamps[] = { |
| 1707 {0, kSkip}, | 1716 {0, kSkip}, |
| 1708 {33, kSkip}, | 1717 {33, kSkip}, |
| 1709 {67, kSkip}, | 1718 {67, kSkip}, |
| 1710 {100, kSkip}, | 1719 {100, kSkip}, |
| 1711 {133, kSkip}, | 1720 {133, kSkip}, |
| 1712 {kSkip, kSkip}, | 1721 {kSkip, kSkip}, |
| 1713 }; | 1722 }; |
| 1714 | 1723 |
| 1715 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the | 1724 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the |
| 1716 // ParseWebMFile() call's expected duration, below, once the file is fixed to | 1725 // ParseWebMFile() call's expected duration, below, once the file is fixed to |
| 1717 // have the correct duration in the init segment. See http://crbug.com/354284. | 1726 // have the correct duration in the init segment. See http://crbug.com/354284. |
| 1718 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2736))); | 1727 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2736))); |
| 1719 | 1728 |
| 1720 ASSERT_TRUE(ParseWebMFile("bear-320x240-video-only.webm", buffer_timestamps, | 1729 ASSERT_TRUE(ParseWebMFile("bear-320x240-video-only.webm", buffer_timestamps, |
| 1721 base::TimeDelta::FromMilliseconds(2703), | 1730 base::TimeDelta::FromMilliseconds(2703), |
| 1722 HAS_VIDEO)); | 1731 HAS_VIDEO)); |
| 1723 } | 1732 } |
| 1724 | 1733 |
| 1725 TEST_F(ChunkDemuxerTest, WebMFile_AltRefFrames) { | 1734 TEST_P(ChunkDemuxerTest, WebMFile_AltRefFrames) { |
| 1726 struct BufferTimestamps buffer_timestamps[] = { | 1735 struct BufferTimestamps buffer_timestamps[] = { |
| 1727 {0, 0}, | 1736 {0, 0}, |
| 1728 {33, 3}, | 1737 {33, 3}, |
| 1729 {33, 6}, | 1738 {33, 6}, |
| 1730 {67, 9}, | 1739 {67, 9}, |
| 1731 {100, 12}, | 1740 {100, 12}, |
| 1732 {kSkip, kSkip}, | 1741 {kSkip, kSkip}, |
| 1733 }; | 1742 }; |
| 1734 | 1743 |
| 1735 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the | 1744 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the |
| 1736 // ParseWebMFile() call's expected duration, below, once the file is fixed to | 1745 // ParseWebMFile() call's expected duration, below, once the file is fixed to |
| 1737 // have the correct duration in the init segment. See http://crbug.com/354284. | 1746 // have the correct duration in the init segment. See http://crbug.com/354284. |
| 1738 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2768))); | 1747 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2768))); |
| 1739 | 1748 |
| 1740 ASSERT_TRUE(ParseWebMFile("bear-320x240-altref.webm", buffer_timestamps, | 1749 ASSERT_TRUE(ParseWebMFile("bear-320x240-altref.webm", buffer_timestamps, |
| 1741 base::TimeDelta::FromMilliseconds(2767))); | 1750 base::TimeDelta::FromMilliseconds(2767))); |
| 1742 } | 1751 } |
| 1743 | 1752 |
| 1744 // Verify that we output buffers before the entire cluster has been parsed. | 1753 // Verify that we output buffers before the entire cluster has been parsed. |
| 1745 TEST_F(ChunkDemuxerTest, IncrementalClusterParsing) { | 1754 TEST_P(ChunkDemuxerTest, IncrementalClusterParsing) { |
| 1746 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1755 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1747 AppendEmptyCluster(0); | 1756 AppendEmptyCluster(0); |
| 1748 | 1757 |
| 1749 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6)); | 1758 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6)); |
| 1750 | 1759 |
| 1751 bool audio_read_done = false; | 1760 bool audio_read_done = false; |
| 1752 bool video_read_done = false; | 1761 bool video_read_done = false; |
| 1753 ReadAudio(base::Bind(&OnReadDone, | 1762 ReadAudio(base::Bind(&OnReadDone, |
| 1754 base::TimeDelta::FromMilliseconds(0), | 1763 base::TimeDelta::FromMilliseconds(0), |
| 1755 &audio_read_done)); | 1764 &audio_read_done)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1798 // Append the remaining data. | 1807 // Append the remaining data. |
| 1799 ASSERT_LT(i, cluster->size()); | 1808 ASSERT_LT(i, cluster->size()); |
| 1800 AppendData(cluster->data() + i, cluster->size() - i); | 1809 AppendData(cluster->data() + i, cluster->size() - i); |
| 1801 | 1810 |
| 1802 message_loop_.RunUntilIdle(); | 1811 message_loop_.RunUntilIdle(); |
| 1803 | 1812 |
| 1804 EXPECT_TRUE(audio_read_done); | 1813 EXPECT_TRUE(audio_read_done); |
| 1805 EXPECT_TRUE(video_read_done); | 1814 EXPECT_TRUE(video_read_done); |
| 1806 } | 1815 } |
| 1807 | 1816 |
| 1808 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) { | 1817 TEST_P(ChunkDemuxerTest, ParseErrorDuringInit) { |
| 1809 EXPECT_CALL(*this, DemuxerOpened()); | 1818 EXPECT_CALL(*this, DemuxerOpened()); |
| 1810 demuxer_->Initialize( | 1819 demuxer_->Initialize( |
| 1811 &host_, CreateInitDoneCB( | 1820 &host_, CreateInitDoneCB( |
| 1812 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1821 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true); |
| 1813 | 1822 |
| 1814 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); | 1823 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); |
| 1815 | 1824 |
| 1816 uint8 tmp = 0; | 1825 uint8 tmp = 0; |
| 1817 demuxer_->AppendData(kSourceId, &tmp, 1, | 1826 demuxer_->AppendData(kSourceId, &tmp, 1, |
| 1818 append_window_start_for_next_append_, | 1827 append_window_start_for_next_append_, |
| 1819 append_window_end_for_next_append_, | 1828 append_window_end_for_next_append_, |
| 1820 ×tamp_offset_map_[kSourceId]); | 1829 ×tamp_offset_map_[kSourceId]); |
| 1821 } | 1830 } |
| 1822 | 1831 |
| 1823 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { | 1832 TEST_P(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { |
| 1824 EXPECT_CALL(*this, DemuxerOpened()); | 1833 EXPECT_CALL(*this, DemuxerOpened()); |
| 1825 demuxer_->Initialize( | 1834 demuxer_->Initialize( |
| 1826 &host_, CreateInitDoneCB(kNoTimestamp(), | 1835 &host_, CreateInitDoneCB(kNoTimestamp(), |
| 1827 DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1836 DEMUXER_ERROR_COULD_NOT_OPEN), true); |
| 1828 | 1837 |
| 1829 std::vector<std::string> codecs(1); | 1838 std::vector<std::string> codecs(1); |
| 1830 codecs[0] = "vorbis"; | 1839 codecs[0] = "vorbis"; |
| 1831 ASSERT_EQ(demuxer_->AddId(kSourceId, "audio/webm", codecs), | 1840 ASSERT_EQ(demuxer_->AddId(kSourceId, "audio/webm", codecs, |
| 1841 use_legacy_frame_processor_), |
| 1832 ChunkDemuxer::kOk); | 1842 ChunkDemuxer::kOk); |
| 1833 | 1843 |
| 1834 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); | 1844 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); |
| 1835 } | 1845 } |
| 1836 | 1846 |
| 1837 TEST_F(ChunkDemuxerTest, AVHeadersWithVideoOnlyType) { | 1847 TEST_P(ChunkDemuxerTest, AVHeadersWithVideoOnlyType) { |
| 1838 EXPECT_CALL(*this, DemuxerOpened()); | 1848 EXPECT_CALL(*this, DemuxerOpened()); |
| 1839 demuxer_->Initialize( | 1849 demuxer_->Initialize( |
| 1840 &host_, CreateInitDoneCB(kNoTimestamp(), | 1850 &host_, CreateInitDoneCB(kNoTimestamp(), |
| 1841 DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1851 DEMUXER_ERROR_COULD_NOT_OPEN), true); |
| 1842 | 1852 |
| 1843 std::vector<std::string> codecs(1); | 1853 std::vector<std::string> codecs(1); |
| 1844 codecs[0] = "vp8"; | 1854 codecs[0] = "vp8"; |
| 1845 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs), | 1855 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs, |
| 1856 use_legacy_frame_processor_), |
| 1846 ChunkDemuxer::kOk); | 1857 ChunkDemuxer::kOk); |
| 1847 | 1858 |
| 1848 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); | 1859 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); |
| 1849 } | 1860 } |
| 1850 | 1861 |
| 1851 TEST_F(ChunkDemuxerTest, MultipleHeaders) { | 1862 TEST_P(ChunkDemuxerTest, MultipleHeaders) { |
| 1852 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1863 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1853 | 1864 |
| 1854 AppendCluster(kDefaultFirstCluster()); | 1865 AppendCluster(kDefaultFirstCluster()); |
| 1855 | 1866 |
| 1856 // Append another identical initialization segment. | 1867 // Append another identical initialization segment. |
| 1857 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); | 1868 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); |
| 1858 | 1869 |
| 1859 AppendCluster(kDefaultSecondCluster()); | 1870 AppendCluster(kDefaultSecondCluster()); |
| 1860 | 1871 |
| 1861 GenerateExpectedReads(0, 9); | 1872 GenerateExpectedReads(0, 9); |
| 1862 } | 1873 } |
| 1863 | 1874 |
| 1864 TEST_F(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideo) { | 1875 TEST_P(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideo) { |
| 1865 std::string audio_id = "audio1"; | 1876 std::string audio_id = "audio1"; |
| 1866 std::string video_id = "video1"; | 1877 std::string video_id = "video1"; |
| 1867 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); | 1878 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); |
| 1868 | 1879 |
| 1869 // Append audio and video data into separate source ids. | 1880 // Append audio and video data into separate source ids. |
| 1870 AppendCluster(audio_id, | 1881 AppendCluster(audio_id, |
| 1871 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); | 1882 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); |
| 1872 GenerateAudioStreamExpectedReads(0, 4); | 1883 GenerateAudioStreamExpectedReads(0, 4); |
| 1873 AppendCluster(video_id, | 1884 AppendCluster(video_id, |
| 1874 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); | 1885 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); |
| 1875 GenerateVideoStreamExpectedReads(0, 4); | 1886 GenerateVideoStreamExpectedReads(0, 4); |
| 1876 } | 1887 } |
| 1877 | 1888 |
| 1878 TEST_F(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideoText) { | 1889 TEST_P(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideoText) { |
| 1879 // TODO(matthewjheaney): Here and elsewhere, we need more tests | 1890 // TODO(matthewjheaney): Here and elsewhere, we need more tests |
| 1880 // for inband text tracks (http://crbug/321455). | 1891 // for inband text tracks (http://crbug/321455). |
| 1881 | 1892 |
| 1882 std::string audio_id = "audio1"; | 1893 std::string audio_id = "audio1"; |
| 1883 std::string video_id = "video1"; | 1894 std::string video_id = "video1"; |
| 1884 | 1895 |
| 1885 EXPECT_CALL(host_, AddTextStream(_, _)) | 1896 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 1886 .Times(Exactly(2)); | 1897 .Times(Exactly(2)); |
| 1887 ASSERT_TRUE(InitDemuxerAudioAndVideoSourcesText(audio_id, video_id, true)); | 1898 ASSERT_TRUE(InitDemuxerAudioAndVideoSourcesText(audio_id, video_id, true)); |
| 1888 | 1899 |
| 1889 // Append audio and video data into separate source ids. | 1900 // Append audio and video data into separate source ids. |
| 1890 AppendCluster(audio_id, | 1901 AppendCluster(audio_id, |
| 1891 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); | 1902 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); |
| 1892 GenerateAudioStreamExpectedReads(0, 4); | 1903 GenerateAudioStreamExpectedReads(0, 4); |
| 1893 AppendCluster(video_id, | 1904 AppendCluster(video_id, |
| 1894 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); | 1905 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); |
| 1895 GenerateVideoStreamExpectedReads(0, 4); | 1906 GenerateVideoStreamExpectedReads(0, 4); |
| 1896 } | 1907 } |
| 1897 | 1908 |
| 1898 TEST_F(ChunkDemuxerTest, AddIdFailures) { | 1909 TEST_P(ChunkDemuxerTest, AddIdFailures) { |
| 1899 EXPECT_CALL(*this, DemuxerOpened()); | 1910 EXPECT_CALL(*this, DemuxerOpened()); |
| 1900 demuxer_->Initialize( | 1911 demuxer_->Initialize( |
| 1901 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); | 1912 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); |
| 1902 | 1913 |
| 1903 std::string audio_id = "audio1"; | 1914 std::string audio_id = "audio1"; |
| 1904 std::string video_id = "video1"; | 1915 std::string video_id = "video1"; |
| 1905 | 1916 |
| 1906 ASSERT_EQ(AddId(audio_id, HAS_AUDIO), ChunkDemuxer::kOk); | 1917 ASSERT_EQ(AddId(audio_id, HAS_AUDIO), ChunkDemuxer::kOk); |
| 1907 | 1918 |
| 1908 // Adding an id with audio/video should fail because we already added audio. | 1919 // Adding an id with audio/video should fail because we already added audio. |
| 1909 ASSERT_EQ(AddId(), ChunkDemuxer::kReachedIdLimit); | 1920 ASSERT_EQ(AddId(), ChunkDemuxer::kReachedIdLimit); |
| 1910 | 1921 |
| 1911 AppendInitSegmentWithSourceId(audio_id, HAS_AUDIO); | 1922 AppendInitSegmentWithSourceId(audio_id, HAS_AUDIO); |
| 1912 | 1923 |
| 1913 // Adding an id after append should fail. | 1924 // Adding an id after append should fail. |
| 1914 ASSERT_EQ(AddId(video_id, HAS_VIDEO), ChunkDemuxer::kReachedIdLimit); | 1925 ASSERT_EQ(AddId(video_id, HAS_VIDEO), ChunkDemuxer::kReachedIdLimit); |
| 1915 } | 1926 } |
| 1916 | 1927 |
| 1917 // Test that Read() calls after a RemoveId() return "end of stream" buffers. | 1928 // Test that Read() calls after a RemoveId() return "end of stream" buffers. |
| 1918 TEST_F(ChunkDemuxerTest, RemoveId) { | 1929 TEST_P(ChunkDemuxerTest, RemoveId) { |
| 1919 std::string audio_id = "audio1"; | 1930 std::string audio_id = "audio1"; |
| 1920 std::string video_id = "video1"; | 1931 std::string video_id = "video1"; |
| 1921 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); | 1932 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); |
| 1922 | 1933 |
| 1923 // Append audio and video data into separate source ids. | 1934 // Append audio and video data into separate source ids. |
| 1924 AppendCluster(audio_id, | 1935 AppendCluster(audio_id, |
| 1925 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); | 1936 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); |
| 1926 AppendCluster(video_id, | 1937 AppendCluster(video_id, |
| 1927 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); | 1938 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); |
| 1928 | 1939 |
| 1929 // Read() from audio should return normal buffers. | 1940 // Read() from audio should return normal buffers. |
| 1930 GenerateAudioStreamExpectedReads(0, 4); | 1941 GenerateAudioStreamExpectedReads(0, 4); |
| 1931 | 1942 |
| 1932 // Remove the audio id. | 1943 // Remove the audio id. |
| 1933 demuxer_->RemoveId(audio_id); | 1944 demuxer_->RemoveId(audio_id); |
| 1934 | 1945 |
| 1935 // Read() from audio should return "end of stream" buffers. | 1946 // Read() from audio should return "end of stream" buffers. |
| 1936 bool audio_read_done = false; | 1947 bool audio_read_done = false; |
| 1937 ReadAudio(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); | 1948 ReadAudio(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); |
| 1938 message_loop_.RunUntilIdle(); | 1949 message_loop_.RunUntilIdle(); |
| 1939 EXPECT_TRUE(audio_read_done); | 1950 EXPECT_TRUE(audio_read_done); |
| 1940 | 1951 |
| 1941 // Read() from video should still return normal buffers. | 1952 // Read() from video should still return normal buffers. |
| 1942 GenerateVideoStreamExpectedReads(0, 4); | 1953 GenerateVideoStreamExpectedReads(0, 4); |
| 1943 } | 1954 } |
| 1944 | 1955 |
| 1945 // Test that removing an ID immediately after adding it does not interfere with | 1956 // Test that removing an ID immediately after adding it does not interfere with |
| 1946 // quota for new IDs in the future. | 1957 // quota for new IDs in the future. |
| 1947 TEST_F(ChunkDemuxerTest, RemoveAndAddId) { | 1958 TEST_P(ChunkDemuxerTest, RemoveAndAddId) { |
| 1948 std::string audio_id_1 = "audio1"; | 1959 std::string audio_id_1 = "audio1"; |
| 1949 ASSERT_TRUE(AddId(audio_id_1, HAS_AUDIO) == ChunkDemuxer::kOk); | 1960 ASSERT_TRUE(AddId(audio_id_1, HAS_AUDIO) == ChunkDemuxer::kOk); |
| 1950 demuxer_->RemoveId(audio_id_1); | 1961 demuxer_->RemoveId(audio_id_1); |
| 1951 | 1962 |
| 1952 std::string audio_id_2 = "audio2"; | 1963 std::string audio_id_2 = "audio2"; |
| 1953 ASSERT_TRUE(AddId(audio_id_2, HAS_AUDIO) == ChunkDemuxer::kOk); | 1964 ASSERT_TRUE(AddId(audio_id_2, HAS_AUDIO) == ChunkDemuxer::kOk); |
| 1954 } | 1965 } |
| 1955 | 1966 |
| 1956 TEST_F(ChunkDemuxerTest, SeekCanceled) { | 1967 TEST_P(ChunkDemuxerTest, SeekCanceled) { |
| 1957 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1968 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1958 | 1969 |
| 1959 // Append cluster at the beginning of the stream. | 1970 // Append cluster at the beginning of the stream. |
| 1960 AppendCluster(GenerateCluster(0, 4)); | 1971 AppendCluster(GenerateCluster(0, 4)); |
| 1961 | 1972 |
| 1962 // Seek to an unbuffered region. | 1973 // Seek to an unbuffered region. |
| 1963 Seek(base::TimeDelta::FromSeconds(50)); | 1974 Seek(base::TimeDelta::FromSeconds(50)); |
| 1964 | 1975 |
| 1965 // Attempt to read in unbuffered area; should not fulfill the read. | 1976 // Attempt to read in unbuffered area; should not fulfill the read. |
| 1966 bool audio_read_done = false; | 1977 bool audio_read_done = false; |
| 1967 bool video_read_done = false; | 1978 bool video_read_done = false; |
| 1968 ReadAudio(base::Bind(&OnReadDone_AbortExpected, &audio_read_done)); | 1979 ReadAudio(base::Bind(&OnReadDone_AbortExpected, &audio_read_done)); |
| 1969 ReadVideo(base::Bind(&OnReadDone_AbortExpected, &video_read_done)); | 1980 ReadVideo(base::Bind(&OnReadDone_AbortExpected, &video_read_done)); |
| 1970 EXPECT_FALSE(audio_read_done); | 1981 EXPECT_FALSE(audio_read_done); |
| 1971 EXPECT_FALSE(video_read_done); | 1982 EXPECT_FALSE(video_read_done); |
| 1972 | 1983 |
| 1973 // Now cancel the pending seek, which should flush the reads with empty | 1984 // Now cancel the pending seek, which should flush the reads with empty |
| 1974 // buffers. | 1985 // buffers. |
| 1975 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(0); | 1986 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(0); |
| 1976 demuxer_->CancelPendingSeek(seek_time); | 1987 demuxer_->CancelPendingSeek(seek_time); |
| 1977 message_loop_.RunUntilIdle(); | 1988 message_loop_.RunUntilIdle(); |
| 1978 EXPECT_TRUE(audio_read_done); | 1989 EXPECT_TRUE(audio_read_done); |
| 1979 EXPECT_TRUE(video_read_done); | 1990 EXPECT_TRUE(video_read_done); |
| 1980 | 1991 |
| 1981 // A seek back to the buffered region should succeed. | 1992 // A seek back to the buffered region should succeed. |
| 1982 Seek(seek_time); | 1993 Seek(seek_time); |
| 1983 GenerateExpectedReads(0, 4); | 1994 GenerateExpectedReads(0, 4); |
| 1984 } | 1995 } |
| 1985 | 1996 |
| 1986 TEST_F(ChunkDemuxerTest, SeekCanceledWhileWaitingForSeek) { | 1997 TEST_P(ChunkDemuxerTest, SeekCanceledWhileWaitingForSeek) { |
| 1987 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1998 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 1988 | 1999 |
| 1989 // Append cluster at the beginning of the stream. | 2000 // Append cluster at the beginning of the stream. |
| 1990 AppendCluster(GenerateCluster(0, 4)); | 2001 AppendCluster(GenerateCluster(0, 4)); |
| 1991 | 2002 |
| 1992 // Start waiting for a seek. | 2003 // Start waiting for a seek. |
| 1993 base::TimeDelta seek_time1 = base::TimeDelta::FromSeconds(50); | 2004 base::TimeDelta seek_time1 = base::TimeDelta::FromSeconds(50); |
| 1994 base::TimeDelta seek_time2 = base::TimeDelta::FromSeconds(0); | 2005 base::TimeDelta seek_time2 = base::TimeDelta::FromSeconds(0); |
| 1995 demuxer_->StartWaitingForSeek(seek_time1); | 2006 demuxer_->StartWaitingForSeek(seek_time1); |
| 1996 | 2007 |
| 1997 // Now cancel the upcoming seek to an unbuffered region. | 2008 // Now cancel the upcoming seek to an unbuffered region. |
| 1998 demuxer_->CancelPendingSeek(seek_time2); | 2009 demuxer_->CancelPendingSeek(seek_time2); |
| 1999 demuxer_->Seek(seek_time1, NewExpectedStatusCB(PIPELINE_OK)); | 2010 demuxer_->Seek(seek_time1, NewExpectedStatusCB(PIPELINE_OK)); |
| 2000 | 2011 |
| 2001 // Read requests should be fulfilled with empty buffers. | 2012 // Read requests should be fulfilled with empty buffers. |
| 2002 bool audio_read_done = false; | 2013 bool audio_read_done = false; |
| 2003 bool video_read_done = false; | 2014 bool video_read_done = false; |
| 2004 ReadAudio(base::Bind(&OnReadDone_AbortExpected, &audio_read_done)); | 2015 ReadAudio(base::Bind(&OnReadDone_AbortExpected, &audio_read_done)); |
| 2005 ReadVideo(base::Bind(&OnReadDone_AbortExpected, &video_read_done)); | 2016 ReadVideo(base::Bind(&OnReadDone_AbortExpected, &video_read_done)); |
| 2006 EXPECT_TRUE(audio_read_done); | 2017 EXPECT_TRUE(audio_read_done); |
| 2007 EXPECT_TRUE(video_read_done); | 2018 EXPECT_TRUE(video_read_done); |
| 2008 | 2019 |
| 2009 // A seek back to the buffered region should succeed. | 2020 // A seek back to the buffered region should succeed. |
| 2010 Seek(seek_time2); | 2021 Seek(seek_time2); |
| 2011 GenerateExpectedReads(0, 4); | 2022 GenerateExpectedReads(0, 4); |
| 2012 } | 2023 } |
| 2013 | 2024 |
| 2014 // Test that Seek() successfully seeks to all source IDs. | 2025 // Test that Seek() successfully seeks to all source IDs. |
| 2015 TEST_F(ChunkDemuxerTest, SeekAudioAndVideoSources) { | 2026 TEST_P(ChunkDemuxerTest, SeekAudioAndVideoSources) { |
| 2016 std::string audio_id = "audio1"; | 2027 std::string audio_id = "audio1"; |
| 2017 std::string video_id = "video1"; | 2028 std::string video_id = "video1"; |
| 2018 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); | 2029 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); |
| 2019 | 2030 |
| 2020 AppendCluster( | 2031 AppendCluster( |
| 2021 audio_id, | 2032 audio_id, |
| 2022 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); | 2033 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); |
| 2023 AppendCluster( | 2034 AppendCluster( |
| 2024 video_id, | 2035 video_id, |
| 2025 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); | 2036 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2062 | 2073 |
| 2063 // Read() should return buffers at 3. | 2074 // Read() should return buffers at 3. |
| 2064 EXPECT_TRUE(audio_read_done); | 2075 EXPECT_TRUE(audio_read_done); |
| 2065 EXPECT_TRUE(video_read_done); | 2076 EXPECT_TRUE(video_read_done); |
| 2066 } | 2077 } |
| 2067 | 2078 |
| 2068 // Test that Seek() completes successfully when EndOfStream | 2079 // Test that Seek() completes successfully when EndOfStream |
| 2069 // is called before data is available for that seek point. | 2080 // is called before data is available for that seek point. |
| 2070 // This scenario might be useful if seeking past the end of stream | 2081 // This scenario might be useful if seeking past the end of stream |
| 2071 // of either audio or video (or both). | 2082 // of either audio or video (or both). |
| 2072 TEST_F(ChunkDemuxerTest, EndOfStreamAfterPastEosSeek) { | 2083 TEST_P(ChunkDemuxerTest, EndOfStreamAfterPastEosSeek) { |
| 2073 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2084 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2074 | 2085 |
| 2075 AppendCluster(GenerateSingleStreamCluster(0, 120, kAudioTrackNum, 10)); | 2086 AppendCluster(GenerateSingleStreamCluster(0, 120, kAudioTrackNum, 10)); |
| 2076 AppendCluster(GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 5)); | 2087 AppendCluster(GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 5)); |
| 2077 | 2088 |
| 2078 // Seeking past the end of video. | 2089 // Seeking past the end of video. |
| 2079 // Note: audio data is available for that seek point. | 2090 // Note: audio data is available for that seek point. |
| 2080 bool seek_cb_was_called = false; | 2091 bool seek_cb_was_called = false; |
| 2081 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(110); | 2092 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(110); |
| 2082 demuxer_->StartWaitingForSeek(seek_time); | 2093 demuxer_->StartWaitingForSeek(seek_time); |
| 2083 demuxer_->Seek(seek_time, | 2094 demuxer_->Seek(seek_time, |
| 2084 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); | 2095 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); |
| 2085 message_loop_.RunUntilIdle(); | 2096 message_loop_.RunUntilIdle(); |
| 2086 | 2097 |
| 2087 EXPECT_FALSE(seek_cb_was_called); | 2098 EXPECT_FALSE(seek_cb_was_called); |
| 2088 | 2099 |
| 2089 EXPECT_CALL(host_, SetDuration( | 2100 EXPECT_CALL(host_, SetDuration( |
| 2090 base::TimeDelta::FromMilliseconds(120))); | 2101 base::TimeDelta::FromMilliseconds(120))); |
| 2091 MarkEndOfStream(PIPELINE_OK); | 2102 MarkEndOfStream(PIPELINE_OK); |
| 2092 message_loop_.RunUntilIdle(); | 2103 message_loop_.RunUntilIdle(); |
| 2093 | 2104 |
| 2094 EXPECT_TRUE(seek_cb_was_called); | 2105 EXPECT_TRUE(seek_cb_was_called); |
| 2095 | 2106 |
| 2096 ShutdownDemuxer(); | 2107 ShutdownDemuxer(); |
| 2097 } | 2108 } |
| 2098 | 2109 |
| 2099 // Test that EndOfStream is ignored if coming during a pending seek | 2110 // Test that EndOfStream is ignored if coming during a pending seek |
| 2100 // whose seek time is before some existing ranges. | 2111 // whose seek time is before some existing ranges. |
| 2101 TEST_F(ChunkDemuxerTest, EndOfStreamDuringPendingSeek) { | 2112 TEST_P(ChunkDemuxerTest, EndOfStreamDuringPendingSeek) { |
| 2102 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2113 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2103 | 2114 |
| 2104 AppendCluster(GenerateSingleStreamCluster(0, 120, kAudioTrackNum, 10)); | 2115 AppendCluster(GenerateSingleStreamCluster(0, 120, kAudioTrackNum, 10)); |
| 2105 AppendCluster(GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 5)); | 2116 AppendCluster(GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 5)); |
| 2106 AppendCluster(GenerateSingleStreamCluster(200, 300, kAudioTrackNum, 10)); | 2117 AppendCluster(GenerateSingleStreamCluster(200, 300, kAudioTrackNum, 10)); |
| 2107 AppendCluster(GenerateSingleStreamCluster(200, 300, kVideoTrackNum, 5)); | 2118 AppendCluster(GenerateSingleStreamCluster(200, 300, kVideoTrackNum, 5)); |
| 2108 | 2119 |
| 2109 bool seek_cb_was_called = false; | 2120 bool seek_cb_was_called = false; |
| 2110 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(160); | 2121 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(160); |
| 2111 demuxer_->StartWaitingForSeek(seek_time); | 2122 demuxer_->StartWaitingForSeek(seek_time); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2127 AppendCluster(GenerateSingleStreamCluster(140, 180, kVideoTrackNum, 5)); | 2138 AppendCluster(GenerateSingleStreamCluster(140, 180, kVideoTrackNum, 5)); |
| 2128 | 2139 |
| 2129 message_loop_.RunUntilIdle(); | 2140 message_loop_.RunUntilIdle(); |
| 2130 | 2141 |
| 2131 EXPECT_TRUE(seek_cb_was_called); | 2142 EXPECT_TRUE(seek_cb_was_called); |
| 2132 | 2143 |
| 2133 ShutdownDemuxer(); | 2144 ShutdownDemuxer(); |
| 2134 } | 2145 } |
| 2135 | 2146 |
| 2136 // Test ranges in an audio-only stream. | 2147 // Test ranges in an audio-only stream. |
| 2137 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) { | 2148 TEST_P(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) { |
| 2138 EXPECT_CALL(*this, DemuxerOpened()); | 2149 EXPECT_CALL(*this, DemuxerOpened()); |
| 2139 demuxer_->Initialize( | 2150 demuxer_->Initialize( |
| 2140 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); | 2151 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); |
| 2141 | 2152 |
| 2142 ASSERT_EQ(AddId(kSourceId, HAS_AUDIO), ChunkDemuxer::kOk); | 2153 ASSERT_EQ(AddId(kSourceId, HAS_AUDIO), ChunkDemuxer::kOk); |
| 2143 AppendInitSegment(HAS_AUDIO); | 2154 AppendInitSegment(HAS_AUDIO); |
| 2144 | 2155 |
| 2145 // Test a simple cluster. | 2156 // Test a simple cluster. |
| 2146 AppendCluster( | 2157 AppendCluster( |
| 2147 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); | 2158 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); |
| 2148 | 2159 |
| 2149 CheckExpectedRanges("{ [0,92) }"); | 2160 CheckExpectedRanges("{ [0,92) }"); |
| 2150 | 2161 |
| 2151 // Append a disjoint cluster to check for two separate ranges. | 2162 // Append a disjoint cluster to check for two separate ranges. |
| 2152 AppendCluster(GenerateSingleStreamCluster( | 2163 AppendCluster(GenerateSingleStreamCluster( |
| 2153 150, 219, kAudioTrackNum, kAudioBlockDuration)); | 2164 150, 219, kAudioTrackNum, kAudioBlockDuration)); |
| 2154 | 2165 |
| 2155 CheckExpectedRanges("{ [0,92) [150,219) }"); | 2166 CheckExpectedRanges("{ [0,92) [150,219) }"); |
| 2156 } | 2167 } |
| 2157 | 2168 |
| 2158 // Test ranges in a video-only stream. | 2169 // Test ranges in a video-only stream. |
| 2159 TEST_F(ChunkDemuxerTest, GetBufferedRanges_VideoIdOnly) { | 2170 TEST_P(ChunkDemuxerTest, GetBufferedRanges_VideoIdOnly) { |
| 2160 EXPECT_CALL(*this, DemuxerOpened()); | 2171 EXPECT_CALL(*this, DemuxerOpened()); |
| 2161 demuxer_->Initialize( | 2172 demuxer_->Initialize( |
| 2162 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); | 2173 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); |
| 2163 | 2174 |
| 2164 ASSERT_EQ(AddId(kSourceId, HAS_VIDEO), ChunkDemuxer::kOk); | 2175 ASSERT_EQ(AddId(kSourceId, HAS_VIDEO), ChunkDemuxer::kOk); |
| 2165 AppendInitSegment(HAS_VIDEO); | 2176 AppendInitSegment(HAS_VIDEO); |
| 2166 | 2177 |
| 2167 // Test a simple cluster. | 2178 // Test a simple cluster. |
| 2168 AppendCluster( | 2179 AppendCluster( |
| 2169 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); | 2180 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); |
| 2170 | 2181 |
| 2171 CheckExpectedRanges("{ [0,132) }"); | 2182 CheckExpectedRanges("{ [0,132) }"); |
| 2172 | 2183 |
| 2173 // Append a disjoint cluster to check for two separate ranges. | 2184 // Append a disjoint cluster to check for two separate ranges. |
| 2174 AppendCluster(GenerateSingleStreamCluster( | 2185 AppendCluster(GenerateSingleStreamCluster( |
| 2175 200, 299, kVideoTrackNum, kVideoBlockDuration)); | 2186 200, 299, kVideoTrackNum, kVideoBlockDuration)); |
| 2176 | 2187 |
| 2177 CheckExpectedRanges("{ [0,132) [200,299) }"); | 2188 CheckExpectedRanges("{ [0,132) [200,299) }"); |
| 2178 } | 2189 } |
| 2179 | 2190 |
| 2180 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideo) { | 2191 TEST_P(ChunkDemuxerTest, GetBufferedRanges_AudioVideo) { |
| 2181 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2192 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2182 | 2193 |
| 2183 // Audio: 0 -> 23 | 2194 // Audio: 0 -> 23 |
| 2184 // Video: 0 -> 33 | 2195 // Video: 0 -> 33 |
| 2185 // Buffered Range: 0 -> 23 | 2196 // Buffered Range: 0 -> 23 |
| 2186 // Audio block duration is smaller than video block duration, | 2197 // Audio block duration is smaller than video block duration, |
| 2187 // so the buffered ranges should correspond to the audio blocks. | 2198 // so the buffered ranges should correspond to the audio blocks. |
| 2188 AppendCluster(GenerateSingleStreamCluster( | 2199 AppendCluster(GenerateSingleStreamCluster( |
| 2189 0, kAudioBlockDuration, kAudioTrackNum, kAudioBlockDuration)); | 2200 0, kAudioBlockDuration, kAudioTrackNum, kAudioBlockDuration)); |
| 2190 AppendCluster(GenerateSingleStreamCluster( | 2201 AppendCluster(GenerateSingleStreamCluster( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2227 // Appending within buffered range should not affect buffered ranges. | 2238 // Appending within buffered range should not affect buffered ranges. |
| 2228 AppendCluster(GenerateSingleStreamCluster(930, 950, kAudioTrackNum, 20)); | 2239 AppendCluster(GenerateSingleStreamCluster(930, 950, kAudioTrackNum, 20)); |
| 2229 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); | 2240 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); |
| 2230 | 2241 |
| 2231 // Appending to single stream outside buffered ranges should not affect | 2242 // Appending to single stream outside buffered ranges should not affect |
| 2232 // buffered ranges. | 2243 // buffered ranges. |
| 2233 AppendCluster(GenerateSingleStreamCluster(1230, 1240, kVideoTrackNum, 10)); | 2244 AppendCluster(GenerateSingleStreamCluster(1230, 1240, kVideoTrackNum, 10)); |
| 2234 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); | 2245 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); |
| 2235 } | 2246 } |
| 2236 | 2247 |
| 2237 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) { | 2248 TEST_P(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) { |
| 2238 EXPECT_CALL(host_, AddTextStream(_, _)); | 2249 EXPECT_CALL(host_, AddTextStream(_, _)); |
| 2239 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 2250 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
| 2240 | 2251 |
| 2241 // Append audio & video data | 2252 // Append audio & video data |
| 2242 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23"); | 2253 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23"); |
| 2243 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); | 2254 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); |
| 2244 | 2255 |
| 2245 // Verify that a text track with no cues does not result in an empty buffered | 2256 // Verify that a text track with no cues does not result in an empty buffered |
| 2246 // range. | 2257 // range. |
| 2247 CheckExpectedRanges("{ [0,46) }"); | 2258 CheckExpectedRanges("{ [0,46) }"); |
| 2248 | 2259 |
| 2249 // Add some text cues. | 2260 // Add some text cues. |
| 2250 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K"); | 2261 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K"); |
| 2251 | 2262 |
| 2252 // Verify that the new cues did not affect the buffered ranges. | 2263 // Verify that the new cues did not affect the buffered ranges. |
| 2253 CheckExpectedRanges("{ [0,46) }"); | 2264 CheckExpectedRanges("{ [0,46) }"); |
| 2254 | 2265 |
| 2255 // Remove the buffered range. | 2266 // Remove the buffered range. |
| 2256 demuxer_->Remove(kSourceId, base::TimeDelta(), | 2267 demuxer_->Remove(kSourceId, base::TimeDelta(), |
| 2257 base::TimeDelta::FromMilliseconds(46)); | 2268 base::TimeDelta::FromMilliseconds(46)); |
| 2258 CheckExpectedRanges("{ }"); | 2269 CheckExpectedRanges("{ }"); |
| 2259 } | 2270 } |
| 2260 | 2271 |
| 2261 // Once MarkEndOfStream() is called, GetBufferedRanges should not cut off any | 2272 // Once MarkEndOfStream() is called, GetBufferedRanges should not cut off any |
| 2262 // over-hanging tails at the end of the ranges as this is likely due to block | 2273 // over-hanging tails at the end of the ranges as this is likely due to block |
| 2263 // duration differences. | 2274 // duration differences. |
| 2264 TEST_F(ChunkDemuxerTest, GetBufferedRanges_EndOfStream) { | 2275 TEST_P(ChunkDemuxerTest, GetBufferedRanges_EndOfStream) { |
| 2265 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2276 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2266 | 2277 |
| 2267 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K"); | 2278 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K"); |
| 2268 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); | 2279 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); |
| 2269 | 2280 |
| 2270 CheckExpectedRanges("{ [0,46) }"); | 2281 CheckExpectedRanges("{ [0,46) }"); |
| 2271 | 2282 |
| 2272 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66))); | 2283 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66))); |
| 2273 MarkEndOfStream(PIPELINE_OK); | 2284 MarkEndOfStream(PIPELINE_OK); |
| 2274 | 2285 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2312 | 2323 |
| 2313 MarkEndOfStream(PIPELINE_OK); | 2324 MarkEndOfStream(PIPELINE_OK); |
| 2314 | 2325 |
| 2315 // NOTE: The last range on each stream gets extended to the highest | 2326 // NOTE: The last range on each stream gets extended to the highest |
| 2316 // end timestamp according to the spec. The last audio range gets extended | 2327 // end timestamp according to the spec. The last audio range gets extended |
| 2317 // from [200,246) to [200,366) which is why the intersection results in the | 2328 // from [200,246) to [200,366) which is why the intersection results in the |
| 2318 // middle range getting larger AND the new range appearing. | 2329 // middle range getting larger AND the new range appearing. |
| 2319 CheckExpectedRanges("{ [0,46) [200,266) [300,366) }"); | 2330 CheckExpectedRanges("{ [0,46) [200,266) [300,366) }"); |
| 2320 } | 2331 } |
| 2321 | 2332 |
| 2322 TEST_F(ChunkDemuxerTest, DifferentStreamTimecodes) { | 2333 TEST_P(ChunkDemuxerTest, DifferentStreamTimecodes) { |
| 2323 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2334 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2324 | 2335 |
| 2325 // Create a cluster where the video timecode begins 25ms after the audio. | 2336 // Create a cluster where the video timecode begins 25ms after the audio. |
| 2326 AppendCluster(GenerateCluster(0, 25, 8)); | 2337 AppendCluster(GenerateCluster(0, 25, 8)); |
| 2327 | 2338 |
| 2328 Seek(base::TimeDelta::FromSeconds(0)); | 2339 Seek(base::TimeDelta::FromSeconds(0)); |
| 2329 GenerateExpectedReads(0, 25, 8); | 2340 GenerateExpectedReads(0, 25, 8); |
| 2330 | 2341 |
| 2331 // Seek to 5 seconds. | 2342 // Seek to 5 seconds. |
| 2332 Seek(base::TimeDelta::FromSeconds(5)); | 2343 Seek(base::TimeDelta::FromSeconds(5)); |
| 2333 | 2344 |
| 2334 // Generate a cluster to fulfill this seek, where audio timecode begins 25ms | 2345 // Generate a cluster to fulfill this seek, where audio timecode begins 25ms |
| 2335 // after the video. | 2346 // after the video. |
| 2336 AppendCluster(GenerateCluster(5025, 5000, 8)); | 2347 AppendCluster(GenerateCluster(5025, 5000, 8)); |
| 2337 GenerateExpectedReads(5025, 5000, 8); | 2348 GenerateExpectedReads(5025, 5000, 8); |
| 2338 } | 2349 } |
| 2339 | 2350 |
| 2340 TEST_F(ChunkDemuxerTest, DifferentStreamTimecodesSeparateSources) { | 2351 TEST_P(ChunkDemuxerTest, DifferentStreamTimecodesSeparateSources) { |
| 2341 std::string audio_id = "audio1"; | 2352 std::string audio_id = "audio1"; |
| 2342 std::string video_id = "video1"; | 2353 std::string video_id = "video1"; |
| 2343 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); | 2354 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); |
| 2344 | 2355 |
| 2345 // Generate two streams where the video stream starts 5ms after the audio | 2356 // Generate two streams where the video stream starts 5ms after the audio |
| 2346 // stream and append them. | 2357 // stream and append them. |
| 2347 AppendCluster(audio_id, GenerateSingleStreamCluster( | 2358 AppendCluster(audio_id, GenerateSingleStreamCluster( |
| 2348 25, 4 * kAudioBlockDuration + 25, kAudioTrackNum, kAudioBlockDuration)); | 2359 25, 4 * kAudioBlockDuration + 25, kAudioTrackNum, kAudioBlockDuration)); |
| 2349 AppendCluster(video_id, GenerateSingleStreamCluster( | 2360 AppendCluster(video_id, GenerateSingleStreamCluster( |
| 2350 30, 4 * kVideoBlockDuration + 30, kVideoTrackNum, kVideoBlockDuration)); | 2361 30, 4 * kVideoBlockDuration + 30, kVideoTrackNum, kVideoBlockDuration)); |
| 2351 | 2362 |
| 2352 // Both streams should be able to fulfill a seek to 25. | 2363 // Both streams should be able to fulfill a seek to 25. |
| 2353 Seek(base::TimeDelta::FromMilliseconds(25)); | 2364 Seek(base::TimeDelta::FromMilliseconds(25)); |
| 2354 GenerateAudioStreamExpectedReads(25, 4); | 2365 GenerateAudioStreamExpectedReads(25, 4); |
| 2355 GenerateVideoStreamExpectedReads(30, 4); | 2366 GenerateVideoStreamExpectedReads(30, 4); |
| 2356 } | 2367 } |
| 2357 | 2368 |
| 2358 TEST_F(ChunkDemuxerTest, DifferentStreamTimecodesOutOfRange) { | 2369 TEST_P(ChunkDemuxerTest, DifferentStreamTimecodesOutOfRange) { |
| 2359 std::string audio_id = "audio1"; | 2370 std::string audio_id = "audio1"; |
| 2360 std::string video_id = "video1"; | 2371 std::string video_id = "video1"; |
| 2361 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); | 2372 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); |
| 2362 | 2373 |
| 2363 // Generate two streams where the video stream starts 10s after the audio | 2374 // Generate two streams where the video stream starts 10s after the audio |
| 2364 // stream and append them. | 2375 // stream and append them. |
| 2365 AppendCluster(audio_id, GenerateSingleStreamCluster(0, | 2376 AppendCluster(audio_id, GenerateSingleStreamCluster(0, |
| 2366 4 * kAudioBlockDuration + 0, kAudioTrackNum, kAudioBlockDuration)); | 2377 4 * kAudioBlockDuration + 0, kAudioTrackNum, kAudioBlockDuration)); |
| 2367 AppendCluster(video_id, GenerateSingleStreamCluster(10000, | 2378 AppendCluster(video_id, GenerateSingleStreamCluster(10000, |
| 2368 4 * kVideoBlockDuration + 10000, kVideoTrackNum, kVideoBlockDuration)); | 2379 4 * kVideoBlockDuration + 10000, kVideoTrackNum, kVideoBlockDuration)); |
| 2369 | 2380 |
| 2370 // Should not be able to fulfill a seek to 0. | 2381 // Should not be able to fulfill a seek to 0. |
| 2371 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(0); | 2382 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(0); |
| 2372 demuxer_->StartWaitingForSeek(seek_time); | 2383 demuxer_->StartWaitingForSeek(seek_time); |
| 2373 demuxer_->Seek(seek_time, | 2384 demuxer_->Seek(seek_time, |
| 2374 NewExpectedStatusCB(PIPELINE_ERROR_ABORT)); | 2385 NewExpectedStatusCB(PIPELINE_ERROR_ABORT)); |
| 2375 ExpectRead(DemuxerStream::AUDIO, 0); | 2386 ExpectRead(DemuxerStream::AUDIO, 0); |
| 2376 ExpectEndOfStream(DemuxerStream::VIDEO); | 2387 ExpectEndOfStream(DemuxerStream::VIDEO); |
| 2377 } | 2388 } |
| 2378 | 2389 |
| 2379 TEST_F(ChunkDemuxerTest, ClusterWithNoBuffers) { | 2390 TEST_P(ChunkDemuxerTest, ClusterWithNoBuffers) { |
| 2380 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2391 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2381 | 2392 |
| 2382 // Generate and append an empty cluster beginning at 0. | 2393 // Generate and append an empty cluster beginning at 0. |
| 2383 AppendEmptyCluster(0); | 2394 AppendEmptyCluster(0); |
| 2384 | 2395 |
| 2385 // Sanity check that data can be appended after this cluster correctly. | 2396 // Sanity check that data can be appended after this cluster correctly. |
| 2386 AppendCluster(GenerateCluster(0, 2)); | 2397 AppendCluster(GenerateCluster(0, 2)); |
| 2387 ExpectRead(DemuxerStream::AUDIO, 0); | 2398 ExpectRead(DemuxerStream::AUDIO, 0); |
| 2388 ExpectRead(DemuxerStream::VIDEO, 0); | 2399 ExpectRead(DemuxerStream::VIDEO, 0); |
| 2389 } | 2400 } |
| 2390 | 2401 |
| 2391 TEST_F(ChunkDemuxerTest, CodecPrefixMatching) { | 2402 TEST_P(ChunkDemuxerTest, CodecPrefixMatching) { |
| 2392 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported; | 2403 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported; |
| 2393 | 2404 |
| 2394 #if defined(USE_PROPRIETARY_CODECS) | 2405 #if defined(USE_PROPRIETARY_CODECS) |
| 2395 expected = ChunkDemuxer::kOk; | 2406 expected = ChunkDemuxer::kOk; |
| 2396 #endif | 2407 #endif |
| 2397 | 2408 |
| 2398 std::vector<std::string> codecs; | 2409 std::vector<std::string> codecs; |
| 2399 codecs.push_back("avc1.4D4041"); | 2410 codecs.push_back("avc1.4D4041"); |
| 2400 | 2411 |
| 2401 EXPECT_EQ(demuxer_->AddId("source_id", "video/mp4", codecs), expected); | 2412 EXPECT_EQ(demuxer_->AddId("source_id", "video/mp4", codecs, |
| 2413 use_legacy_frame_processor_), |
| 2414 expected); |
| 2402 } | 2415 } |
| 2403 | 2416 |
| 2404 // Test codec ID's that are not compliant with RFC6381, but have been | 2417 // Test codec ID's that are not compliant with RFC6381, but have been |
| 2405 // seen in the wild. | 2418 // seen in the wild. |
| 2406 TEST_F(ChunkDemuxerTest, CodecIDsThatAreNotRFC6381Compliant) { | 2419 TEST_P(ChunkDemuxerTest, CodecIDsThatAreNotRFC6381Compliant) { |
| 2407 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported; | 2420 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported; |
| 2408 | 2421 |
| 2409 #if defined(USE_PROPRIETARY_CODECS) | 2422 #if defined(USE_PROPRIETARY_CODECS) |
| 2410 expected = ChunkDemuxer::kOk; | 2423 expected = ChunkDemuxer::kOk; |
| 2411 #endif | 2424 #endif |
| 2412 const char* codec_ids[] = { | 2425 const char* codec_ids[] = { |
| 2413 // GPAC places leading zeros on the audio object type. | 2426 // GPAC places leading zeros on the audio object type. |
| 2414 "mp4a.40.02", | 2427 "mp4a.40.02", |
| 2415 "mp4a.40.05" | 2428 "mp4a.40.05" |
| 2416 }; | 2429 }; |
| 2417 | 2430 |
| 2418 for (size_t i = 0; i < arraysize(codec_ids); ++i) { | 2431 for (size_t i = 0; i < arraysize(codec_ids); ++i) { |
| 2419 std::vector<std::string> codecs; | 2432 std::vector<std::string> codecs; |
| 2420 codecs.push_back(codec_ids[i]); | 2433 codecs.push_back(codec_ids[i]); |
| 2421 | 2434 |
| 2422 ChunkDemuxer::Status result = | 2435 ChunkDemuxer::Status result = |
| 2423 demuxer_->AddId("source_id", "audio/mp4", codecs); | 2436 demuxer_->AddId("source_id", "audio/mp4", codecs, |
| 2437 use_legacy_frame_processor_); |
| 2424 | 2438 |
| 2425 EXPECT_EQ(result, expected) | 2439 EXPECT_EQ(result, expected) |
| 2426 << "Fail to add codec_id '" << codec_ids[i] << "'"; | 2440 << "Fail to add codec_id '" << codec_ids[i] << "'"; |
| 2427 | 2441 |
| 2428 if (result == ChunkDemuxer::kOk) | 2442 if (result == ChunkDemuxer::kOk) |
| 2429 demuxer_->RemoveId("source_id"); | 2443 demuxer_->RemoveId("source_id"); |
| 2430 } | 2444 } |
| 2431 } | 2445 } |
| 2432 | 2446 |
| 2433 TEST_F(ChunkDemuxerTest, EndOfStreamStillSetAfterSeek) { | 2447 TEST_P(ChunkDemuxerTest, EndOfStreamStillSetAfterSeek) { |
| 2434 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2448 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2435 | 2449 |
| 2436 EXPECT_CALL(host_, SetDuration(_)) | 2450 EXPECT_CALL(host_, SetDuration(_)) |
| 2437 .Times(AnyNumber()); | 2451 .Times(AnyNumber()); |
| 2438 | 2452 |
| 2439 base::TimeDelta kLastAudioTimestamp = base::TimeDelta::FromMilliseconds(92); | 2453 base::TimeDelta kLastAudioTimestamp = base::TimeDelta::FromMilliseconds(92); |
| 2440 base::TimeDelta kLastVideoTimestamp = base::TimeDelta::FromMilliseconds(99); | 2454 base::TimeDelta kLastVideoTimestamp = base::TimeDelta::FromMilliseconds(99); |
| 2441 | 2455 |
| 2442 AppendCluster(kDefaultFirstCluster()); | 2456 AppendCluster(kDefaultFirstCluster()); |
| 2443 AppendCluster(kDefaultSecondCluster()); | 2457 AppendCluster(kDefaultSecondCluster()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2460 | 2474 |
| 2461 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); | 2475 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); |
| 2462 EXPECT_EQ(DemuxerStream::kOk, status); | 2476 EXPECT_EQ(DemuxerStream::kOk, status); |
| 2463 EXPECT_EQ(kLastAudioTimestamp, last_timestamp); | 2477 EXPECT_EQ(kLastAudioTimestamp, last_timestamp); |
| 2464 | 2478 |
| 2465 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); | 2479 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); |
| 2466 EXPECT_EQ(DemuxerStream::kOk, status); | 2480 EXPECT_EQ(DemuxerStream::kOk, status); |
| 2467 EXPECT_EQ(kLastVideoTimestamp, last_timestamp); | 2481 EXPECT_EQ(kLastVideoTimestamp, last_timestamp); |
| 2468 } | 2482 } |
| 2469 | 2483 |
| 2470 TEST_F(ChunkDemuxerTest, GetBufferedRangesBeforeInitSegment) { | 2484 TEST_P(ChunkDemuxerTest, GetBufferedRangesBeforeInitSegment) { |
| 2471 EXPECT_CALL(*this, DemuxerOpened()); | 2485 EXPECT_CALL(*this, DemuxerOpened()); |
| 2472 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK), true); | 2486 demuxer_->Initialize(&host_, CreateInitDoneCB(PIPELINE_OK), true); |
| 2473 ASSERT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); | 2487 ASSERT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); |
| 2474 ASSERT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); | 2488 ASSERT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); |
| 2475 | 2489 |
| 2476 CheckExpectedRanges("audio", "{ }"); | 2490 CheckExpectedRanges("audio", "{ }"); |
| 2477 CheckExpectedRanges("video", "{ }"); | 2491 CheckExpectedRanges("video", "{ }"); |
| 2478 } | 2492 } |
| 2479 | 2493 |
| 2480 // Test that Seek() completes successfully when the first cluster | 2494 // Test that Seek() completes successfully when the first cluster |
| 2481 // arrives. | 2495 // arrives. |
| 2482 TEST_F(ChunkDemuxerTest, EndOfStreamDuringSeek) { | 2496 TEST_P(ChunkDemuxerTest, EndOfStreamDuringSeek) { |
| 2483 InSequence s; | 2497 InSequence s; |
| 2484 | 2498 |
| 2485 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2499 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2486 | 2500 |
| 2487 AppendCluster(kDefaultFirstCluster()); | 2501 AppendCluster(kDefaultFirstCluster()); |
| 2488 | 2502 |
| 2489 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(0); | 2503 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(0); |
| 2490 demuxer_->StartWaitingForSeek(seek_time); | 2504 demuxer_->StartWaitingForSeek(seek_time); |
| 2491 | 2505 |
| 2492 AppendCluster(kDefaultSecondCluster()); | 2506 AppendCluster(kDefaultSecondCluster()); |
| 2493 EXPECT_CALL(host_, SetDuration( | 2507 EXPECT_CALL(host_, SetDuration( |
| 2494 base::TimeDelta::FromMilliseconds(kDefaultSecondClusterEndTimestamp))); | 2508 base::TimeDelta::FromMilliseconds(kDefaultSecondClusterEndTimestamp))); |
| 2495 MarkEndOfStream(PIPELINE_OK); | 2509 MarkEndOfStream(PIPELINE_OK); |
| 2496 | 2510 |
| 2497 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); | 2511 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); |
| 2498 | 2512 |
| 2499 GenerateExpectedReads(0, 4); | 2513 GenerateExpectedReads(0, 4); |
| 2500 GenerateExpectedReads(46, 66, 5); | 2514 GenerateExpectedReads(46, 66, 5); |
| 2501 | 2515 |
| 2502 EndOfStreamHelper end_of_stream_helper(demuxer_.get()); | 2516 EndOfStreamHelper end_of_stream_helper(demuxer_.get()); |
| 2503 end_of_stream_helper.RequestReads(); | 2517 end_of_stream_helper.RequestReads(); |
| 2504 end_of_stream_helper.CheckIfReadDonesWereCalled(true); | 2518 end_of_stream_helper.CheckIfReadDonesWereCalled(true); |
| 2505 } | 2519 } |
| 2506 | 2520 |
| 2507 TEST_F(ChunkDemuxerTest, ConfigChange_Video) { | 2521 TEST_P(ChunkDemuxerTest, ConfigChange_Video) { |
| 2508 InSequence s; | 2522 InSequence s; |
| 2509 | 2523 |
| 2510 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); | 2524 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); |
| 2511 | 2525 |
| 2512 DemuxerStream::Status status; | 2526 DemuxerStream::Status status; |
| 2513 base::TimeDelta last_timestamp; | 2527 base::TimeDelta last_timestamp; |
| 2514 | 2528 |
| 2515 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 2529 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 2516 | 2530 |
| 2517 // Fetch initial video config and verify it matches what we expect. | 2531 // Fetch initial video config and verify it matches what we expect. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2544 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config())); | 2558 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config())); |
| 2545 | 2559 |
| 2546 ExpectRead(DemuxerStream::VIDEO, 801); | 2560 ExpectRead(DemuxerStream::VIDEO, 801); |
| 2547 | 2561 |
| 2548 // Read until the end of the stream just to make sure there aren't any other | 2562 // Read until the end of the stream just to make sure there aren't any other |
| 2549 // config changes. | 2563 // config changes. |
| 2550 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); | 2564 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); |
| 2551 ASSERT_EQ(status, DemuxerStream::kOk); | 2565 ASSERT_EQ(status, DemuxerStream::kOk); |
| 2552 } | 2566 } |
| 2553 | 2567 |
| 2554 TEST_F(ChunkDemuxerTest, ConfigChange_Audio) { | 2568 TEST_P(ChunkDemuxerTest, ConfigChange_Audio) { |
| 2555 InSequence s; | 2569 InSequence s; |
| 2556 | 2570 |
| 2557 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); | 2571 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); |
| 2558 | 2572 |
| 2559 DemuxerStream::Status status; | 2573 DemuxerStream::Status status; |
| 2560 base::TimeDelta last_timestamp; | 2574 base::TimeDelta last_timestamp; |
| 2561 | 2575 |
| 2562 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 2576 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 2563 | 2577 |
| 2564 // Fetch initial audio config and verify it matches what we expect. | 2578 // Fetch initial audio config and verify it matches what we expect. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2591 ASSERT_TRUE(audio_config_1.Matches(audio->audio_decoder_config())); | 2605 ASSERT_TRUE(audio_config_1.Matches(audio->audio_decoder_config())); |
| 2592 | 2606 |
| 2593 ExpectRead(DemuxerStream::AUDIO, 779); | 2607 ExpectRead(DemuxerStream::AUDIO, 779); |
| 2594 | 2608 |
| 2595 // Read until the end of the stream just to make sure there aren't any other | 2609 // Read until the end of the stream just to make sure there aren't any other |
| 2596 // config changes. | 2610 // config changes. |
| 2597 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); | 2611 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); |
| 2598 ASSERT_EQ(status, DemuxerStream::kOk); | 2612 ASSERT_EQ(status, DemuxerStream::kOk); |
| 2599 } | 2613 } |
| 2600 | 2614 |
| 2601 TEST_F(ChunkDemuxerTest, ConfigChange_Seek) { | 2615 TEST_P(ChunkDemuxerTest, ConfigChange_Seek) { |
| 2602 InSequence s; | 2616 InSequence s; |
| 2603 | 2617 |
| 2604 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); | 2618 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); |
| 2605 | 2619 |
| 2606 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 2620 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 2607 | 2621 |
| 2608 // Fetch initial video config and verify it matches what we expect. | 2622 // Fetch initial video config and verify it matches what we expect. |
| 2609 const VideoDecoderConfig& video_config_1 = video->video_decoder_config(); | 2623 const VideoDecoderConfig& video_config_1 = video->video_decoder_config(); |
| 2610 ASSERT_TRUE(video_config_1.IsValidConfig()); | 2624 ASSERT_TRUE(video_config_1.IsValidConfig()); |
| 2611 EXPECT_EQ(video_config_1.natural_size().width(), 320); | 2625 EXPECT_EQ(video_config_1.natural_size().width(), 320); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2638 // seek to a new location that has the same configuration as | 2652 // seek to a new location that has the same configuration as |
| 2639 // the start of the file without a Read() in the middle. | 2653 // the start of the file without a Read() in the middle. |
| 2640 Seek(base::TimeDelta::FromMilliseconds(527)); | 2654 Seek(base::TimeDelta::FromMilliseconds(527)); |
| 2641 Seek(base::TimeDelta::FromMilliseconds(801)); | 2655 Seek(base::TimeDelta::FromMilliseconds(801)); |
| 2642 | 2656 |
| 2643 // Verify that no config change is signalled. | 2657 // Verify that no config change is signalled. |
| 2644 ExpectRead(DemuxerStream::VIDEO, 801); | 2658 ExpectRead(DemuxerStream::VIDEO, 801); |
| 2645 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config())); | 2659 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config())); |
| 2646 } | 2660 } |
| 2647 | 2661 |
| 2648 TEST_F(ChunkDemuxerTest, TimestampPositiveOffset) { | 2662 TEST_P(ChunkDemuxerTest, TimestampPositiveOffset) { |
| 2649 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2663 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2650 | 2664 |
| 2651 ASSERT_TRUE(SetTimestampOffset(kSourceId, base::TimeDelta::FromSeconds(30))); | 2665 ASSERT_TRUE(SetTimestampOffset(kSourceId, base::TimeDelta::FromSeconds(30))); |
| 2652 AppendCluster(GenerateCluster(0, 2)); | 2666 AppendCluster(GenerateCluster(0, 2)); |
| 2653 | 2667 |
| 2654 Seek(base::TimeDelta::FromMilliseconds(30000)); | 2668 Seek(base::TimeDelta::FromMilliseconds(30000)); |
| 2655 | 2669 |
| 2656 GenerateExpectedReads(30000, 2); | 2670 GenerateExpectedReads(30000, 2); |
| 2657 } | 2671 } |
| 2658 | 2672 |
| 2659 TEST_F(ChunkDemuxerTest, TimestampNegativeOffset) { | 2673 TEST_P(ChunkDemuxerTest, TimestampNegativeOffset) { |
| 2660 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2674 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2661 | 2675 |
| 2662 ASSERT_TRUE(SetTimestampOffset(kSourceId, base::TimeDelta::FromSeconds(-1))); | 2676 ASSERT_TRUE(SetTimestampOffset(kSourceId, base::TimeDelta::FromSeconds(-1))); |
| 2663 AppendCluster(GenerateCluster(1000, 2)); | 2677 AppendCluster(GenerateCluster(1000, 2)); |
| 2664 | 2678 |
| 2665 GenerateExpectedReads(0, 2); | 2679 GenerateExpectedReads(0, 2); |
| 2666 } | 2680 } |
| 2667 | 2681 |
| 2668 TEST_F(ChunkDemuxerTest, TimestampOffsetSeparateStreams) { | 2682 TEST_P(ChunkDemuxerTest, TimestampOffsetSeparateStreams) { |
| 2669 std::string audio_id = "audio1"; | 2683 std::string audio_id = "audio1"; |
| 2670 std::string video_id = "video1"; | 2684 std::string video_id = "video1"; |
| 2671 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); | 2685 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); |
| 2672 | 2686 |
| 2673 ASSERT_TRUE(SetTimestampOffset( | 2687 ASSERT_TRUE(SetTimestampOffset( |
| 2674 audio_id, base::TimeDelta::FromMilliseconds(-2500))); | 2688 audio_id, base::TimeDelta::FromMilliseconds(-2500))); |
| 2675 ASSERT_TRUE(SetTimestampOffset( | 2689 ASSERT_TRUE(SetTimestampOffset( |
| 2676 video_id, base::TimeDelta::FromMilliseconds(-2500))); | 2690 video_id, base::TimeDelta::FromMilliseconds(-2500))); |
| 2677 AppendCluster(audio_id, GenerateSingleStreamCluster(2500, | 2691 AppendCluster(audio_id, GenerateSingleStreamCluster(2500, |
| 2678 2500 + kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); | 2692 2500 + kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); |
| 2679 AppendCluster(video_id, GenerateSingleStreamCluster(2500, | 2693 AppendCluster(video_id, GenerateSingleStreamCluster(2500, |
| 2680 2500 + kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); | 2694 2500 + kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); |
| 2681 GenerateAudioStreamExpectedReads(0, 4); | 2695 GenerateAudioStreamExpectedReads(0, 4); |
| 2682 GenerateVideoStreamExpectedReads(0, 4); | 2696 GenerateVideoStreamExpectedReads(0, 4); |
| 2683 | 2697 |
| 2684 Seek(base::TimeDelta::FromMilliseconds(27300)); | 2698 Seek(base::TimeDelta::FromMilliseconds(27300)); |
| 2685 | 2699 |
| 2686 ASSERT_TRUE(SetTimestampOffset( | 2700 ASSERT_TRUE(SetTimestampOffset( |
| 2687 audio_id, base::TimeDelta::FromMilliseconds(27300))); | 2701 audio_id, base::TimeDelta::FromMilliseconds(27300))); |
| 2688 ASSERT_TRUE(SetTimestampOffset( | 2702 ASSERT_TRUE(SetTimestampOffset( |
| 2689 video_id, base::TimeDelta::FromMilliseconds(27300))); | 2703 video_id, base::TimeDelta::FromMilliseconds(27300))); |
| 2690 AppendCluster(audio_id, GenerateSingleStreamCluster( | 2704 AppendCluster(audio_id, GenerateSingleStreamCluster( |
| 2691 0, kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); | 2705 0, kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); |
| 2692 AppendCluster(video_id, GenerateSingleStreamCluster( | 2706 AppendCluster(video_id, GenerateSingleStreamCluster( |
| 2693 0, kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); | 2707 0, kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); |
| 2694 GenerateVideoStreamExpectedReads(27300, 4); | 2708 GenerateVideoStreamExpectedReads(27300, 4); |
| 2695 GenerateAudioStreamExpectedReads(27300, 4); | 2709 GenerateAudioStreamExpectedReads(27300, 4); |
| 2696 } | 2710 } |
| 2697 | 2711 |
| 2698 TEST_F(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) { | 2712 TEST_P(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) { |
| 2699 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2713 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2700 | 2714 |
| 2701 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); | 2715 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); |
| 2702 // Append only part of the cluster data. | 2716 // Append only part of the cluster data. |
| 2703 AppendData(cluster->data(), cluster->size() - 13); | 2717 AppendData(cluster->data(), cluster->size() - 13); |
| 2704 | 2718 |
| 2705 // Confirm we're in the middle of parsing a media segment. | 2719 // Confirm we're in the middle of parsing a media segment. |
| 2706 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); | 2720 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); |
| 2707 | 2721 |
| 2708 demuxer_->Abort(kSourceId); | 2722 demuxer_->Abort(kSourceId); |
| 2709 // After Abort(), parsing should no longer be in the middle of a media | 2723 // After Abort(), parsing should no longer be in the middle of a media |
| 2710 // segment. | 2724 // segment. |
| 2711 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId)); | 2725 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId)); |
| 2712 } | 2726 } |
| 2713 | 2727 |
| 2714 TEST_F(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { | 2728 TEST_P(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { |
| 2715 // TODO(wolenetz): Also test 'unknown' sized clusters. | 2729 // TODO(wolenetz): Also test 'unknown' sized clusters. |
| 2716 // See http://crbug.com/335676. | 2730 // See http://crbug.com/335676. |
| 2717 const uint8 kBuffer[] = { | 2731 const uint8 kBuffer[] = { |
| 2718 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) | 2732 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) |
| 2719 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) | 2733 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) |
| 2720 }; | 2734 }; |
| 2721 | 2735 |
| 2722 // This array indicates expected return value of IsParsingMediaSegment() | 2736 // This array indicates expected return value of IsParsingMediaSegment() |
| 2723 // following each incrementally appended byte in |kBuffer|. | 2737 // following each incrementally appended byte in |kBuffer|. |
| 2724 const bool kExpectedReturnValues[] = { | 2738 const bool kExpectedReturnValues[] = { |
| 2725 false, false, false, false, true, | 2739 false, false, false, false, true, |
| 2726 true, true, false, | 2740 true, true, false, |
| 2727 }; | 2741 }; |
| 2728 | 2742 |
| 2729 COMPILE_ASSERT(arraysize(kBuffer) == arraysize(kExpectedReturnValues), | 2743 COMPILE_ASSERT(arraysize(kBuffer) == arraysize(kExpectedReturnValues), |
| 2730 test_arrays_out_of_sync); | 2744 test_arrays_out_of_sync); |
| 2731 COMPILE_ASSERT(arraysize(kBuffer) == sizeof(kBuffer), not_one_byte_per_index); | 2745 COMPILE_ASSERT(arraysize(kBuffer) == sizeof(kBuffer), not_one_byte_per_index); |
| 2732 | 2746 |
| 2733 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2747 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2734 | 2748 |
| 2735 for (size_t i = 0; i < sizeof(kBuffer); i++) { | 2749 for (size_t i = 0; i < sizeof(kBuffer); i++) { |
| 2736 DVLOG(3) << "Appending and testing index " << i; | 2750 DVLOG(3) << "Appending and testing index " << i; |
| 2737 AppendData(kBuffer + i, 1); | 2751 AppendData(kBuffer + i, 1); |
| 2738 bool expected_return_value = kExpectedReturnValues[i]; | 2752 bool expected_return_value = kExpectedReturnValues[i]; |
| 2739 EXPECT_EQ(expected_return_value, | 2753 EXPECT_EQ(expected_return_value, |
| 2740 demuxer_->IsParsingMediaSegment(kSourceId)); | 2754 demuxer_->IsParsingMediaSegment(kSourceId)); |
| 2741 } | 2755 } |
| 2742 } | 2756 } |
| 2743 | 2757 |
| 2744 TEST_F(ChunkDemuxerTest, DurationChange) { | 2758 TEST_P(ChunkDemuxerTest, DurationChange) { |
| 2745 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2759 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2746 const int kStreamDuration = kDefaultDuration().InMilliseconds(); | 2760 const int kStreamDuration = kDefaultDuration().InMilliseconds(); |
| 2747 | 2761 |
| 2748 // Add data leading up to the currently set duration. | 2762 // Add data leading up to the currently set duration. |
| 2749 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration, | 2763 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration, |
| 2750 kStreamDuration - kVideoBlockDuration, | 2764 kStreamDuration - kVideoBlockDuration, |
| 2751 2)); | 2765 2)); |
| 2752 | 2766 |
| 2753 CheckExpectedRanges(kSourceId, "{ [201191,201224) }"); | 2767 CheckExpectedRanges(kSourceId, "{ [201191,201224) }"); |
| 2754 | 2768 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2775 base::TimeDelta::FromMilliseconds(kFinalStreamDuration))); | 2789 base::TimeDelta::FromMilliseconds(kFinalStreamDuration))); |
| 2776 AppendCluster(GenerateCluster(kStreamDuration + kAudioBlockDuration, | 2790 AppendCluster(GenerateCluster(kStreamDuration + kAudioBlockDuration, |
| 2777 kStreamDuration + kVideoBlockDuration, | 2791 kStreamDuration + kVideoBlockDuration, |
| 2778 3)); | 2792 3)); |
| 2779 | 2793 |
| 2780 // See that the range has increased appropriately (but not to the full | 2794 // See that the range has increased appropriately (but not to the full |
| 2781 // duration of 201293, since there is not enough video appended for that). | 2795 // duration of 201293, since there is not enough video appended for that). |
| 2782 CheckExpectedRanges(kSourceId, "{ [201191,201290) }"); | 2796 CheckExpectedRanges(kSourceId, "{ [201191,201290) }"); |
| 2783 } | 2797 } |
| 2784 | 2798 |
| 2785 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) { | 2799 TEST_P(ChunkDemuxerTest, DurationChangeTimestampOffset) { |
| 2786 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2800 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2787 | 2801 |
| 2788 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration())); | 2802 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration())); |
| 2789 | 2803 |
| 2790 // TODO(wolenetz): Compliant coded frame processor will emit a max of one | 2804 // TODO(wolenetz): Compliant coded frame processor will emit a max of one |
| 2791 // duration change per each ProcessFrames(). Remove the first expectation here | 2805 // duration change per each ProcessFrames(). Remove the first expectation here |
| 2792 // once compliant coded frame processor is used. See http://crbug.com/249422. | 2806 // once compliant coded frame processor is used. See http://crbug.com/249422. |
| 2793 EXPECT_CALL(host_, SetDuration( | 2807 EXPECT_CALL(host_, SetDuration( |
| 2794 kDefaultDuration() + base::TimeDelta::FromMilliseconds( | 2808 kDefaultDuration() + base::TimeDelta::FromMilliseconds( |
| 2795 kAudioBlockDuration * 2))); | 2809 kAudioBlockDuration * 2))); |
| 2796 EXPECT_CALL(host_, SetDuration( | 2810 EXPECT_CALL(host_, SetDuration( |
| 2797 kDefaultDuration() + base::TimeDelta::FromMilliseconds( | 2811 kDefaultDuration() + base::TimeDelta::FromMilliseconds( |
| 2798 kVideoBlockDuration * 2))); | 2812 kVideoBlockDuration * 2))); |
| 2799 AppendCluster(GenerateCluster(0, 4)); | 2813 AppendCluster(GenerateCluster(0, 4)); |
| 2800 } | 2814 } |
| 2801 | 2815 |
| 2802 TEST_F(ChunkDemuxerTest, EndOfStreamTruncateDuration) { | 2816 TEST_P(ChunkDemuxerTest, EndOfStreamTruncateDuration) { |
| 2803 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2817 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2804 | 2818 |
| 2805 AppendCluster(kDefaultFirstCluster()); | 2819 AppendCluster(kDefaultFirstCluster()); |
| 2806 | 2820 |
| 2807 EXPECT_CALL(host_, SetDuration( | 2821 EXPECT_CALL(host_, SetDuration( |
| 2808 base::TimeDelta::FromMilliseconds(kDefaultFirstClusterEndTimestamp))); | 2822 base::TimeDelta::FromMilliseconds(kDefaultFirstClusterEndTimestamp))); |
| 2809 MarkEndOfStream(PIPELINE_OK); | 2823 MarkEndOfStream(PIPELINE_OK); |
| 2810 } | 2824 } |
| 2811 | 2825 |
| 2812 | 2826 |
| 2813 TEST_F(ChunkDemuxerTest, ZeroLengthAppend) { | 2827 TEST_P(ChunkDemuxerTest, ZeroLengthAppend) { |
| 2814 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2828 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2815 AppendData(NULL, 0); | 2829 AppendData(NULL, 0); |
| 2816 } | 2830 } |
| 2817 | 2831 |
| 2818 TEST_F(ChunkDemuxerTest, AppendAfterEndOfStream) { | 2832 TEST_P(ChunkDemuxerTest, AppendAfterEndOfStream) { |
| 2819 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2833 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2820 | 2834 |
| 2821 EXPECT_CALL(host_, SetDuration(_)) | 2835 EXPECT_CALL(host_, SetDuration(_)) |
| 2822 .Times(AnyNumber()); | 2836 .Times(AnyNumber()); |
| 2823 | 2837 |
| 2824 AppendCluster(kDefaultFirstCluster()); | 2838 AppendCluster(kDefaultFirstCluster()); |
| 2825 MarkEndOfStream(PIPELINE_OK); | 2839 MarkEndOfStream(PIPELINE_OK); |
| 2826 | 2840 |
| 2827 demuxer_->UnmarkEndOfStream(); | 2841 demuxer_->UnmarkEndOfStream(); |
| 2828 | 2842 |
| 2829 AppendCluster(kDefaultSecondCluster()); | 2843 AppendCluster(kDefaultSecondCluster()); |
| 2830 MarkEndOfStream(PIPELINE_OK); | 2844 MarkEndOfStream(PIPELINE_OK); |
| 2831 } | 2845 } |
| 2832 | 2846 |
| 2833 // Test receiving a Shutdown() call before we get an Initialize() | 2847 // Test receiving a Shutdown() call before we get an Initialize() |
| 2834 // call. This can happen if video element gets destroyed before | 2848 // call. This can happen if video element gets destroyed before |
| 2835 // the pipeline has a chance to initialize the demuxer. | 2849 // the pipeline has a chance to initialize the demuxer. |
| 2836 TEST_F(ChunkDemuxerTest, Shutdown_BeforeInitialize) { | 2850 TEST_P(ChunkDemuxerTest, Shutdown_BeforeInitialize) { |
| 2837 demuxer_->Shutdown(); | 2851 demuxer_->Shutdown(); |
| 2838 demuxer_->Initialize( | 2852 demuxer_->Initialize( |
| 2839 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); | 2853 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); |
| 2840 message_loop_.RunUntilIdle(); | 2854 message_loop_.RunUntilIdle(); |
| 2841 } | 2855 } |
| 2842 | 2856 |
| 2843 TEST_F(ChunkDemuxerTest, ReadAfterAudioDisabled) { | 2857 TEST_P(ChunkDemuxerTest, ReadAfterAudioDisabled) { |
| 2844 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2858 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2845 AppendCluster(kDefaultFirstCluster()); | 2859 AppendCluster(kDefaultFirstCluster()); |
| 2846 | 2860 |
| 2847 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 2861 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 2848 ASSERT_TRUE(stream); | 2862 ASSERT_TRUE(stream); |
| 2849 | 2863 |
| 2850 // The stream should no longer be present. | 2864 // The stream should no longer be present. |
| 2851 demuxer_->OnAudioRendererDisabled(); | 2865 demuxer_->OnAudioRendererDisabled(); |
| 2852 ASSERT_FALSE(demuxer_->GetStream(DemuxerStream::AUDIO)); | 2866 ASSERT_FALSE(demuxer_->GetStream(DemuxerStream::AUDIO)); |
| 2853 | 2867 |
| 2854 // Normally this would return an audio buffer at timestamp zero, but | 2868 // Normally this would return an audio buffer at timestamp zero, but |
| 2855 // all reads should return EOS buffers when disabled. | 2869 // all reads should return EOS buffers when disabled. |
| 2856 bool audio_read_done = false; | 2870 bool audio_read_done = false; |
| 2857 stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); | 2871 stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); |
| 2858 message_loop_.RunUntilIdle(); | 2872 message_loop_.RunUntilIdle(); |
| 2859 | 2873 |
| 2860 EXPECT_TRUE(audio_read_done); | 2874 EXPECT_TRUE(audio_read_done); |
| 2861 } | 2875 } |
| 2862 | 2876 |
| 2863 // Verifies that signaling end of stream while stalled at a gap | 2877 // Verifies that signaling end of stream while stalled at a gap |
| 2864 // boundary does not trigger end of stream buffers to be returned. | 2878 // boundary does not trigger end of stream buffers to be returned. |
| 2865 TEST_F(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) { | 2879 TEST_P(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) { |
| 2866 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2880 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2867 | 2881 |
| 2868 AppendCluster(0, 10); | 2882 AppendCluster(0, 10); |
| 2869 AppendCluster(300, 10); | 2883 AppendCluster(300, 10); |
| 2870 CheckExpectedRanges(kSourceId, "{ [0,132) [300,432) }"); | 2884 CheckExpectedRanges(kSourceId, "{ [0,132) [300,432) }"); |
| 2871 | 2885 |
| 2872 GenerateExpectedReads(0, 10); | 2886 GenerateExpectedReads(0, 10); |
| 2873 | 2887 |
| 2874 bool audio_read_done = false; | 2888 bool audio_read_done = false; |
| 2875 bool video_read_done = false; | 2889 bool video_read_done = false; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2918 EXPECT_FALSE(audio_read_done); | 2932 EXPECT_FALSE(audio_read_done); |
| 2919 EXPECT_FALSE(video_read_done); | 2933 EXPECT_FALSE(video_read_done); |
| 2920 | 2934 |
| 2921 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(437))); | 2935 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(437))); |
| 2922 MarkEndOfStream(PIPELINE_OK); | 2936 MarkEndOfStream(PIPELINE_OK); |
| 2923 | 2937 |
| 2924 EXPECT_TRUE(audio_read_done); | 2938 EXPECT_TRUE(audio_read_done); |
| 2925 EXPECT_TRUE(video_read_done); | 2939 EXPECT_TRUE(video_read_done); |
| 2926 } | 2940 } |
| 2927 | 2941 |
| 2928 TEST_F(ChunkDemuxerTest, CanceledSeekDuringInitialPreroll) { | 2942 TEST_P(ChunkDemuxerTest, CanceledSeekDuringInitialPreroll) { |
| 2929 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2943 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2930 | 2944 |
| 2931 // Cancel preroll. | 2945 // Cancel preroll. |
| 2932 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(200); | 2946 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(200); |
| 2933 demuxer_->CancelPendingSeek(seek_time); | 2947 demuxer_->CancelPendingSeek(seek_time); |
| 2934 | 2948 |
| 2935 // Initiate the seek to the new location. | 2949 // Initiate the seek to the new location. |
| 2936 Seek(seek_time); | 2950 Seek(seek_time); |
| 2937 | 2951 |
| 2938 // Append data to satisfy the seek. | 2952 // Append data to satisfy the seek. |
| 2939 AppendCluster(seek_time.InMilliseconds(), 10); | 2953 AppendCluster(seek_time.InMilliseconds(), 10); |
| 2940 } | 2954 } |
| 2941 | 2955 |
| 2942 TEST_F(ChunkDemuxerTest, GCDuringSeek) { | 2956 TEST_P(ChunkDemuxerTest, GCDuringSeek) { |
| 2943 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); | 2957 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
| 2944 | 2958 |
| 2945 demuxer_->SetMemoryLimitsForTesting(5 * kBlockSize); | 2959 demuxer_->SetMemoryLimitsForTesting(5 * kBlockSize); |
| 2946 | 2960 |
| 2947 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(1000); | 2961 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(1000); |
| 2948 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(500); | 2962 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(500); |
| 2949 | 2963 |
| 2950 // Initiate a seek to |seek_time1|. | 2964 // Initiate a seek to |seek_time1|. |
| 2951 Seek(seek_time1); | 2965 Seek(seek_time1); |
| 2952 | 2966 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2975 // Append more data and make sure that the blocks for |seek_time2| | 2989 // Append more data and make sure that the blocks for |seek_time2| |
| 2976 // don't get removed. | 2990 // don't get removed. |
| 2977 // | 2991 // |
| 2978 // NOTE: The current GC algorithm tries to preserve the GOP at the | 2992 // NOTE: The current GC algorithm tries to preserve the GOP at the |
| 2979 // current position as well as the last appended GOP. This is | 2993 // current position as well as the last appended GOP. This is |
| 2980 // why there are 2 ranges in the expectations. | 2994 // why there are 2 ranges in the expectations. |
| 2981 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 700, 5); | 2995 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 700, 5); |
| 2982 CheckExpectedRanges(kSourceId, "{ [500,592) [792,815) }"); | 2996 CheckExpectedRanges(kSourceId, "{ [500,592) [792,815) }"); |
| 2983 } | 2997 } |
| 2984 | 2998 |
| 2985 TEST_F(ChunkDemuxerTest, RemoveBeforeInitSegment) { | 2999 TEST_P(ChunkDemuxerTest, RemoveBeforeInitSegment) { |
| 2986 EXPECT_CALL(*this, DemuxerOpened()); | 3000 EXPECT_CALL(*this, DemuxerOpened()); |
| 2987 demuxer_->Initialize( | 3001 demuxer_->Initialize( |
| 2988 &host_, CreateInitDoneCB(kNoTimestamp(), PIPELINE_OK), true); | 3002 &host_, CreateInitDoneCB(kNoTimestamp(), PIPELINE_OK), true); |
| 2989 | 3003 |
| 2990 EXPECT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO | HAS_VIDEO)); | 3004 EXPECT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO | HAS_VIDEO)); |
| 2991 | 3005 |
| 2992 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(0), | 3006 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(0), |
| 2993 base::TimeDelta::FromMilliseconds(1)); | 3007 base::TimeDelta::FromMilliseconds(1)); |
| 2994 } | 3008 } |
| 2995 | 3009 |
| 2996 TEST_F(ChunkDemuxerTest, AppendWindow_Video) { | 3010 TEST_P(ChunkDemuxerTest, AppendWindow_Video) { |
| 2997 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); | 3011 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); |
| 2998 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 3012 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 2999 | 3013 |
| 3000 // Set the append window to [20,280). | 3014 // Set the append window to [20,280). |
| 3001 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); | 3015 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); |
| 3002 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); | 3016 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); |
| 3003 | 3017 |
| 3004 // Append a cluster that starts before and ends after the append window. | 3018 // Append a cluster that starts before and ends after the append window. |
| 3005 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 3019 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, |
| 3006 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); | 3020 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); |
| 3007 | 3021 |
| 3008 // Verify that GOPs that start outside the window are not included | 3022 // Verify that GOPs that start outside the window are not included |
| 3009 // in the buffer. Also verify that buffers that start inside the | 3023 // in the buffer. Also verify that buffers that start inside the |
| 3010 // window and extend beyond the end of the window are not included. | 3024 // window and extend beyond the end of the window are not included. |
| 3011 CheckExpectedRanges(kSourceId, "{ [120,270) }"); | 3025 CheckExpectedRanges(kSourceId, "{ [120,270) }"); |
| 3012 CheckExpectedBuffers(stream, "120 150 180 210 240"); | 3026 CheckExpectedBuffers(stream, "120 150 180 210 240"); |
| 3013 | 3027 |
| 3014 // Extend the append window to [20,650). | 3028 // Extend the append window to [20,650). |
| 3015 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); | 3029 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); |
| 3016 | 3030 |
| 3017 // Append more data and verify that adding buffers start at the next | 3031 // Append more data and verify that adding buffers start at the next |
| 3018 // keyframe. | 3032 // keyframe. |
| 3019 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 3033 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, |
| 3020 "360 390 420K 450 480 510 540K 570 600 630K"); | 3034 "360 390 420K 450 480 510 540K 570 600 630K"); |
| 3021 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); | 3035 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); |
| 3022 } | 3036 } |
| 3023 | 3037 |
| 3024 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) { | 3038 TEST_P(ChunkDemuxerTest, AppendWindow_Audio) { |
| 3025 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); | 3039 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
| 3026 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 3040 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 3027 | 3041 |
| 3028 // Set the append window to [20,280). | 3042 // Set the append window to [20,280). |
| 3029 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); | 3043 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); |
| 3030 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); | 3044 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); |
| 3031 | 3045 |
| 3032 // Append a cluster that starts before and ends after the append window. | 3046 // Append a cluster that starts before and ends after the append window. |
| 3033 AppendSingleStreamCluster( | 3047 AppendSingleStreamCluster( |
| 3034 kSourceId, kAudioTrackNum, | 3048 kSourceId, kAudioTrackNum, |
| 3035 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); | 3049 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); |
| 3036 | 3050 |
| 3037 // Verify that frames that start outside the window are not included | 3051 // Verify that frames that start outside the window are not included |
| 3038 // in the buffer. Also verify that buffers that start inside the | 3052 // in the buffer. Also verify that buffers that start inside the |
| 3039 // window and extend beyond the end of the window are not included. | 3053 // window and extend beyond the end of the window are not included. |
| 3040 CheckExpectedRanges(kSourceId, "{ [30,270) }"); | 3054 CheckExpectedRanges(kSourceId, "{ [30,270) }"); |
| 3041 CheckExpectedBuffers(stream, "30 60 90 120 150 180 210 240"); | 3055 CheckExpectedBuffers(stream, "30 60 90 120 150 180 210 240"); |
| 3042 | 3056 |
| 3043 // Extend the append window to [20,650). | 3057 // Extend the append window to [20,650). |
| 3044 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); | 3058 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); |
| 3045 | 3059 |
| 3046 // Append more data and verify that a new range is created. | 3060 // Append more data and verify that a new range is created. |
| 3047 AppendSingleStreamCluster( | 3061 AppendSingleStreamCluster( |
| 3048 kSourceId, kAudioTrackNum, | 3062 kSourceId, kAudioTrackNum, |
| 3049 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); | 3063 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); |
| 3050 CheckExpectedRanges(kSourceId, "{ [30,270) [360,630) }"); | 3064 CheckExpectedRanges(kSourceId, "{ [30,270) [360,630) }"); |
| 3051 } | 3065 } |
| 3052 | 3066 |
| 3053 TEST_F(ChunkDemuxerTest, AppendWindow_Text) { | 3067 TEST_P(ChunkDemuxerTest, AppendWindow_Text) { |
| 3054 DemuxerStream* text_stream = NULL; | 3068 DemuxerStream* text_stream = NULL; |
| 3055 EXPECT_CALL(host_, AddTextStream(_, _)) | 3069 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 3056 .WillOnce(SaveArg<0>(&text_stream)); | 3070 .WillOnce(SaveArg<0>(&text_stream)); |
| 3057 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); | 3071 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); |
| 3058 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 3072 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 3059 | 3073 |
| 3060 // Set the append window to [20,280). | 3074 // Set the append window to [20,280). |
| 3061 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); | 3075 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); |
| 3062 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); | 3076 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); |
| 3063 | 3077 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3082 "360 390 420K 450 480 510 540K 570 600 630K"); | 3096 "360 390 420K 450 480 510 540K 570 600 630K"); |
| 3083 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K"); | 3097 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K"); |
| 3084 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); | 3098 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); |
| 3085 | 3099 |
| 3086 // Seek to the new range and verify that the expected buffers are returned. | 3100 // Seek to the new range and verify that the expected buffers are returned. |
| 3087 Seek(base::TimeDelta::FromMilliseconds(420)); | 3101 Seek(base::TimeDelta::FromMilliseconds(420)); |
| 3088 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600"); | 3102 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600"); |
| 3089 CheckExpectedBuffers(text_stream, "400 500"); | 3103 CheckExpectedBuffers(text_stream, "400 500"); |
| 3090 } | 3104 } |
| 3091 | 3105 |
| 3092 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) { | 3106 TEST_P(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) { |
| 3093 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 3107 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 3094 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 3108 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
| 3095 AppendGarbage(); | 3109 AppendGarbage(); |
| 3096 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50); | 3110 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50); |
| 3097 demuxer_->StartWaitingForSeek(seek_time); | 3111 demuxer_->StartWaitingForSeek(seek_time); |
| 3098 } | 3112 } |
| 3099 | 3113 |
| 3100 TEST_F(ChunkDemuxerTest, Remove_AudioVideoText) { | 3114 TEST_P(ChunkDemuxerTest, Remove_AudioVideoText) { |
| 3101 DemuxerStream* text_stream = NULL; | 3115 DemuxerStream* text_stream = NULL; |
| 3102 EXPECT_CALL(host_, AddTextStream(_, _)) | 3116 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 3103 .WillOnce(SaveArg<0>(&text_stream)); | 3117 .WillOnce(SaveArg<0>(&text_stream)); |
| 3104 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 3118 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
| 3105 | 3119 |
| 3106 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 3120 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 3107 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 3121 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 3108 | 3122 |
| 3109 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, | 3123 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, |
| 3110 "0K 20K 40K 60K 80K 100K 120K 140K"); | 3124 "0K 20K 40K 60K 80K 100K 120K 140K"); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3133 | 3147 |
| 3134 Seek(base::TimeDelta()); | 3148 Seek(base::TimeDelta()); |
| 3135 CheckExpectedBuffers(audio_stream, "1 21 41 61 81 101 121 141"); | 3149 CheckExpectedBuffers(audio_stream, "1 21 41 61 81 101 121 141"); |
| 3136 CheckExpectedBuffers(video_stream, "1 31 61 91 121 151 181"); | 3150 CheckExpectedBuffers(video_stream, "1 31 61 91 121 151 181"); |
| 3137 CheckExpectedBuffers(text_stream, "1 101 201"); | 3151 CheckExpectedBuffers(text_stream, "1 101 201"); |
| 3138 } | 3152 } |
| 3139 | 3153 |
| 3140 // Verifies that a Seek() will complete without text cues for | 3154 // Verifies that a Seek() will complete without text cues for |
| 3141 // the seek point and will return cues after the seek position | 3155 // the seek point and will return cues after the seek position |
| 3142 // when they are eventually appended. | 3156 // when they are eventually appended. |
| 3143 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) { | 3157 TEST_P(ChunkDemuxerTest, SeekCompletesWithoutTextCues) { |
| 3144 DemuxerStream* text_stream = NULL; | 3158 DemuxerStream* text_stream = NULL; |
| 3145 EXPECT_CALL(host_, AddTextStream(_, _)) | 3159 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 3146 .WillOnce(SaveArg<0>(&text_stream)); | 3160 .WillOnce(SaveArg<0>(&text_stream)); |
| 3147 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 3161 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
| 3148 | 3162 |
| 3149 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 3163 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 3150 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 3164 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 3151 | 3165 |
| 3152 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(120); | 3166 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(120); |
| 3153 bool seek_cb_was_called = false; | 3167 bool seek_cb_was_called = false; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3188 | 3202 |
| 3189 // NOTE: we start at 175 here because the buffer at 125 was returned | 3203 // NOTE: we start at 175 here because the buffer at 125 was returned |
| 3190 // to the pending read initiated above. | 3204 // to the pending read initiated above. |
| 3191 CheckExpectedBuffers(text_stream, "175 225"); | 3205 CheckExpectedBuffers(text_stream, "175 225"); |
| 3192 | 3206 |
| 3193 // Verify that audio & video streams continue to return expected values. | 3207 // Verify that audio & video streams continue to return expected values. |
| 3194 CheckExpectedBuffers(audio_stream, "160 180"); | 3208 CheckExpectedBuffers(audio_stream, "160 180"); |
| 3195 CheckExpectedBuffers(video_stream, "180 210"); | 3209 CheckExpectedBuffers(video_stream, "180 210"); |
| 3196 } | 3210 } |
| 3197 | 3211 |
| 3212 // TODO(wolenetz): Enable testing of new frame processor based on this flag, |
| 3213 // once the new processor has landed. See http://crbug.com/249422. |
| 3214 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, ChunkDemuxerTest, Values(true)); |
| 3215 |
| 3198 } // namespace media | 3216 } // namespace media |
| OLD | NEW |