| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "media/base/audio_decoder_config.h" | 16 #include "media/base/audio_decoder_config.h" |
| 17 #include "media/base/decoder_buffer.h" | 17 #include "media/base/decoder_buffer.h" |
| 18 #include "media/base/media_track.h" | 18 #include "media/base/media_track.h" |
| 19 #include "media/base/media_tracks.h" | 19 #include "media/base/media_tracks.h" |
| 20 #include "media/base/mock_media_log.h" | 20 #include "media/base/mock_media_log.h" |
| 21 #include "media/base/stream_parser.h" |
| 21 #include "media/base/stream_parser_buffer.h" | 22 #include "media/base/stream_parser_buffer.h" |
| 22 #include "media/base/test_data_util.h" | 23 #include "media/base/test_data_util.h" |
| 23 #include "media/base/text_track_config.h" | 24 #include "media/base/text_track_config.h" |
| 24 #include "media/base/video_decoder_config.h" | 25 #include "media/base/video_decoder_config.h" |
| 25 #include "media/formats/mp4/es_descriptor.h" | 26 #include "media/formats/mp4/es_descriptor.h" |
| 26 #include "media/formats/mp4/fourccs.h" | 27 #include "media/formats/mp4/fourccs.h" |
| 27 #include "media/formats/mp4/mp4_stream_parser.h" | 28 #include "media/formats/mp4/mp4_stream_parser.h" |
| 28 #include "media/media_features.h" | 29 #include "media/media_features.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 while (start < end) { | 87 while (start < end) { |
| 87 size_t append_size = std::min(piece_size, | 88 size_t append_size = std::min(piece_size, |
| 88 static_cast<size_t>(end - start)); | 89 static_cast<size_t>(end - start)); |
| 89 if (!AppendData(start, append_size)) | 90 if (!AppendData(start, append_size)) |
| 90 return false; | 91 return false; |
| 91 start += append_size; | 92 start += append_size; |
| 92 } | 93 } |
| 93 return true; | 94 return true; |
| 94 } | 95 } |
| 95 | 96 |
| 96 void InitF(DemuxerStream::Liveness expected_liveness, | 97 void InitF(const StreamParser::InitParameters& expected_params, |
| 97 const StreamParser::InitParameters& params) { | 98 const StreamParser::InitParameters& params) { |
| 98 DVLOG(1) << "InitF: dur=" << params.duration.InMilliseconds() | 99 DVLOG(1) << "InitF: dur=" << params.duration.InMicroseconds() |
| 99 << ", autoTimestampOffset=" << params.auto_update_timestamp_offset; | 100 << ", autoTimestampOffset=" << params.auto_update_timestamp_offset; |
| 100 EXPECT_EQ(expected_liveness, params.liveness); | 101 EXPECT_EQ(expected_params.duration, params.duration); |
| 102 EXPECT_EQ(expected_params.timeline_offset, params.timeline_offset); |
| 103 EXPECT_EQ(expected_params.auto_update_timestamp_offset, |
| 104 params.auto_update_timestamp_offset); |
| 105 EXPECT_EQ(expected_params.liveness, params.liveness); |
| 106 EXPECT_EQ(expected_params.detected_audio_track_count, |
| 107 params.detected_audio_track_count); |
| 108 EXPECT_EQ(expected_params.detected_video_track_count, |
| 109 params.detected_video_track_count); |
| 110 EXPECT_EQ(expected_params.detected_text_track_count, |
| 111 params.detected_text_track_count); |
| 101 } | 112 } |
| 102 | 113 |
| 103 bool NewConfigF(scoped_ptr<MediaTracks> tracks, | 114 bool NewConfigF(scoped_ptr<MediaTracks> tracks, |
| 104 const StreamParser::TextTrackConfigMap& tc) { | 115 const StreamParser::TextTrackConfigMap& tc) { |
| 105 configs_received_ = true; | 116 configs_received_ = true; |
| 106 CHECK(tracks.get()); | 117 CHECK(tracks.get()); |
| 107 media_tracks_ = std::move(tracks); | 118 media_tracks_ = std::move(tracks); |
| 108 audio_decoder_config_ = media_tracks_->getFirstAudioConfig(); | 119 audio_decoder_config_ = media_tracks_->getFirstAudioConfig(); |
| 109 video_decoder_config_ = media_tracks_->getFirstVideoConfig(); | 120 video_decoder_config_ = media_tracks_->getFirstVideoConfig(); |
| 110 DVLOG(1) << "NewConfigF: track count=" << media_tracks_->tracks().size() | 121 DVLOG(1) << "NewConfigF: track count=" << media_tracks_->tracks().size() |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 DVLOG(1) << "NewSegmentF"; | 177 DVLOG(1) << "NewSegmentF"; |
| 167 lower_bound_ = kNoDecodeTimestamp(); | 178 lower_bound_ = kNoDecodeTimestamp(); |
| 168 } | 179 } |
| 169 | 180 |
| 170 void EndOfSegmentF() { | 181 void EndOfSegmentF() { |
| 171 DVLOG(1) << "EndOfSegmentF()"; | 182 DVLOG(1) << "EndOfSegmentF()"; |
| 172 lower_bound_ = | 183 lower_bound_ = |
| 173 DecodeTimestamp::FromPresentationTime(base::TimeDelta::Max()); | 184 DecodeTimestamp::FromPresentationTime(base::TimeDelta::Max()); |
| 174 } | 185 } |
| 175 | 186 |
| 176 void InitializeParserAndExpectLiveness( | 187 void InitializeParserWithInitParametersExpectations( |
| 177 DemuxerStream::Liveness expected_liveness) { | 188 StreamParser::InitParameters params) { |
| 178 parser_->Init( | 189 parser_->Init( |
| 179 base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this), | 190 base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this), params), |
| 180 expected_liveness), | |
| 181 base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), | 191 base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), |
| 182 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), | 192 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), |
| 183 true, | 193 true, |
| 184 base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), | 194 base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), |
| 185 base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this)), | 195 base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this)), |
| 186 base::Bind(&MP4StreamParserTest::EndOfSegmentF, base::Unretained(this)), | 196 base::Bind(&MP4StreamParserTest::EndOfSegmentF, base::Unretained(this)), |
| 187 media_log_); | 197 media_log_); |
| 188 } | 198 } |
| 189 | 199 |
| 190 void InitializeParser() { | 200 StreamParser::InitParameters GetDefaultInitParametersExpectations() { |
| 191 // Most unencrypted test mp4 files have zero duration and are treated as | 201 // Most unencrypted test mp4 files have zero duration and are treated as |
| 192 // live streams. | 202 // live streams. |
| 193 InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_LIVE); | 203 StreamParser::InitParameters params(kInfiniteDuration()); |
| 204 params.liveness = DemuxerStream::LIVENESS_LIVE; |
| 205 params.detected_audio_track_count = 1; |
| 206 params.detected_video_track_count = 1; |
| 207 params.detected_text_track_count = 0; |
| 208 return params; |
| 209 } |
| 210 |
| 211 void InitializeParserAndExpectLiveness(DemuxerStream::Liveness liveness) { |
| 212 auto params = GetDefaultInitParametersExpectations(); |
| 213 params.liveness = liveness; |
| 214 InitializeParserWithInitParametersExpectations(params); |
| 215 } |
| 216 |
| 217 void InitializeParser() { |
| 218 InitializeParserWithInitParametersExpectations( |
| 219 GetDefaultInitParametersExpectations()); |
| 194 } | 220 } |
| 195 | 221 |
| 196 bool ParseMP4File(const std::string& filename, int append_bytes) { | 222 bool ParseMP4File(const std::string& filename, int append_bytes) { |
| 197 InitializeParser(); | |
| 198 | |
| 199 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); | 223 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); |
| 200 EXPECT_TRUE(AppendDataInPieces(buffer->data(), | 224 EXPECT_TRUE(AppendDataInPieces(buffer->data(), |
| 201 buffer->data_size(), | 225 buffer->data_size(), |
| 202 append_bytes)); | 226 append_bytes)); |
| 203 return true; | 227 return true; |
| 204 } | 228 } |
| 205 }; | 229 }; |
| 206 | 230 |
| 207 TEST_F(MP4StreamParserTest, UnalignedAppend) { | 231 TEST_F(MP4StreamParserTest, UnalignedAppend) { |
| 208 // Test small, non-segment-aligned appends (small enough to exercise | 232 // Test small, non-segment-aligned appends (small enough to exercise |
| 209 // incremental append system) | 233 // incremental append system) |
| 210 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); | 234 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| 211 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 235 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| 236 InitializeParser(); |
| 212 ParseMP4File("bear-1280x720-av_frag.mp4", 512); | 237 ParseMP4File("bear-1280x720-av_frag.mp4", 512); |
| 213 } | 238 } |
| 214 | 239 |
| 215 TEST_F(MP4StreamParserTest, BytewiseAppend) { | 240 TEST_F(MP4StreamParserTest, BytewiseAppend) { |
| 216 // Ensure no incremental errors occur when parsing | 241 // Ensure no incremental errors occur when parsing |
| 217 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); | 242 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| 218 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 243 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| 244 InitializeParser(); |
| 219 ParseMP4File("bear-1280x720-av_frag.mp4", 1); | 245 ParseMP4File("bear-1280x720-av_frag.mp4", 1); |
| 220 } | 246 } |
| 221 | 247 |
| 222 TEST_F(MP4StreamParserTest, MultiFragmentAppend) { | 248 TEST_F(MP4StreamParserTest, MultiFragmentAppend) { |
| 223 // Large size ensures multiple fragments are appended in one call (size is | 249 // Large size ensures multiple fragments are appended in one call (size is |
| 224 // larger than this particular test file) | 250 // larger than this particular test file) |
| 225 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); | 251 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| 226 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 252 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| 253 InitializeParser(); |
| 227 ParseMP4File("bear-1280x720-av_frag.mp4", 768432); | 254 ParseMP4File("bear-1280x720-av_frag.mp4", 768432); |
| 228 } | 255 } |
| 229 | 256 |
| 230 TEST_F(MP4StreamParserTest, Flush) { | 257 TEST_F(MP4StreamParserTest, Flush) { |
| 231 // Flush while reading sample data, then start a new stream. | 258 // Flush while reading sample data, then start a new stream. |
| 232 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")).Times(2); | 259 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")).Times(2); |
| 233 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")).Times(2); | 260 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")).Times(2); |
| 234 InitializeParser(); | 261 InitializeParser(); |
| 235 | 262 |
| 236 scoped_refptr<DecoderBuffer> buffer = | 263 scoped_refptr<DecoderBuffer> buffer = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 257 512)); | 284 512)); |
| 258 } | 285 } |
| 259 | 286 |
| 260 TEST_F(MP4StreamParserTest, MPEG2_AAC_LC) { | 287 TEST_F(MP4StreamParserTest, MPEG2_AAC_LC) { |
| 261 InSequence s; | 288 InSequence s; |
| 262 std::set<int> audio_object_types; | 289 std::set<int> audio_object_types; |
| 263 audio_object_types.insert(kISO_13818_7_AAC_LC); | 290 audio_object_types.insert(kISO_13818_7_AAC_LC); |
| 264 parser_.reset(new MP4StreamParser(audio_object_types, false)); | 291 parser_.reset(new MP4StreamParser(audio_object_types, false)); |
| 265 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.67")); | 292 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.67")); |
| 266 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 293 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| 294 auto params = GetDefaultInitParametersExpectations(); |
| 295 params.detected_video_track_count = 0; |
| 296 InitializeParserWithInitParametersExpectations(params); |
| 267 ParseMP4File("bear-mpeg2-aac-only_frag.mp4", 512); | 297 ParseMP4File("bear-mpeg2-aac-only_frag.mp4", 512); |
| 268 } | 298 } |
| 269 | 299 |
| 270 // Test that a moov box is not always required after Flush() is called. | 300 // Test that a moov box is not always required after Flush() is called. |
| 271 TEST_F(MP4StreamParserTest, NoMoovAfterFlush) { | 301 TEST_F(MP4StreamParserTest, NoMoovAfterFlush) { |
| 272 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); | 302 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| 273 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 303 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| 274 InitializeParser(); | 304 InitializeParser(); |
| 275 | 305 |
| 276 scoped_refptr<DecoderBuffer> buffer = | 306 scoped_refptr<DecoderBuffer> buffer = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 288 | 318 |
| 289 // Test an invalid file where there are encrypted samples, but | 319 // Test an invalid file where there are encrypted samples, but |
| 290 // SampleEncryptionBox (senc) and SampleAuxiliaryInformation{Sizes|Offsets}Box | 320 // SampleEncryptionBox (senc) and SampleAuxiliaryInformation{Sizes|Offsets}Box |
| 291 // (saiz|saio) are missing. | 321 // (saiz|saio) are missing. |
| 292 // The parser should fail instead of crash. See http://crbug.com/361347 | 322 // The parser should fail instead of crash. See http://crbug.com/361347 |
| 293 TEST_F(MP4StreamParserTest, MissingSampleEncryptionInfo) { | 323 TEST_F(MP4StreamParserTest, MissingSampleEncryptionInfo) { |
| 294 InSequence s; | 324 InSequence s; |
| 295 | 325 |
| 296 // Encrypted test mp4 files have non-zero duration and are treated as | 326 // Encrypted test mp4 files have non-zero duration and are treated as |
| 297 // recorded streams. | 327 // recorded streams. |
| 298 InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); | 328 auto params = GetDefaultInitParametersExpectations(); |
| 329 params.duration = base::TimeDelta::FromMicroseconds(23219); |
| 330 params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| 331 params.detected_video_track_count = 0; |
| 332 InitializeParserWithInitParametersExpectations(params); |
| 299 | 333 |
| 300 scoped_refptr<DecoderBuffer> buffer = | 334 scoped_refptr<DecoderBuffer> buffer = |
| 301 ReadTestDataFile("bear-1280x720-a_frag-cenc_missing-saiz-saio.mp4"); | 335 ReadTestDataFile("bear-1280x720-a_frag-cenc_missing-saiz-saio.mp4"); |
| 302 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")).Times(2); | 336 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")).Times(2); |
| 303 EXPECT_MEDIA_LOG(SampleEncryptionInfoUnavailableLog()); | 337 EXPECT_MEDIA_LOG(SampleEncryptionInfoUnavailableLog()); |
| 304 EXPECT_FALSE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); | 338 EXPECT_FALSE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| 305 } | 339 } |
| 306 | 340 |
| 307 // Test a file where all video samples start with an Access Unit | 341 // Test a file where all video samples start with an Access Unit |
| 308 // Delimiter (AUD) NALU. | 342 // Delimiter (AUD) NALU. |
| 309 TEST_F(MP4StreamParserTest, VideoSamplesStartWithAUDs) { | 343 TEST_F(MP4StreamParserTest, VideoSamplesStartWithAUDs) { |
| 310 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.4D4028")); | 344 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.4D4028")); |
| 345 auto params = GetDefaultInitParametersExpectations(); |
| 346 params.detected_audio_track_count = 0; |
| 347 InitializeParserWithInitParametersExpectations(params); |
| 311 ParseMP4File("bear-1280x720-av_with-aud-nalus_frag.mp4", 512); | 348 ParseMP4File("bear-1280x720-av_with-aud-nalus_frag.mp4", 512); |
| 312 } | 349 } |
| 313 | 350 |
| 314 TEST_F(MP4StreamParserTest, HEVC_in_MP4_container) { | 351 TEST_F(MP4StreamParserTest, HEVC_in_MP4_container) { |
| 315 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 352 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 316 bool expect_success = true; | 353 bool expect_success = true; |
| 317 EXPECT_MEDIA_LOG(VideoCodecLog("hevc")); | 354 EXPECT_MEDIA_LOG(VideoCodecLog("hevc")); |
| 318 #else | 355 #else |
| 319 bool expect_success = false; | 356 bool expect_success = false; |
| 320 EXPECT_MEDIA_LOG(ErrorLog("Parse unsupported video format hev1")); | 357 EXPECT_MEDIA_LOG(ErrorLog("Parse unsupported video format hev1")); |
| 321 #endif | 358 #endif |
| 322 InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); | 359 auto params = GetDefaultInitParametersExpectations(); |
| 360 params.duration = base::TimeDelta::FromMicroseconds(1002000); |
| 361 params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| 362 params.detected_audio_track_count = 0; |
| 363 InitializeParserWithInitParametersExpectations(params); |
| 364 |
| 323 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-hevc-frag.mp4"); | 365 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-hevc-frag.mp4"); |
| 324 EXPECT_EQ(expect_success, | 366 EXPECT_EQ(expect_success, |
| 325 AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); | 367 AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| 326 } | 368 } |
| 327 | 369 |
| 328 // Sample encryption information is stored as CencSampleAuxiliaryDataFormat | 370 // Sample encryption information is stored as CencSampleAuxiliaryDataFormat |
| 329 // (ISO/IEC 23001-7:2015 8) inside 'mdat' box. No SampleEncryption ('senc') box. | 371 // (ISO/IEC 23001-7:2015 8) inside 'mdat' box. No SampleEncryption ('senc') box. |
| 330 TEST_F(MP4StreamParserTest, CencWithEncryptionInfoStoredAsAuxDataInMdat) { | 372 TEST_F(MP4StreamParserTest, CencWithEncryptionInfoStoredAsAuxDataInMdat) { |
| 331 // Encrypted test mp4 files have non-zero duration and are treated as | 373 // Encrypted test mp4 files have non-zero duration and are treated as |
| 332 // recorded streams. | 374 // recorded streams. |
| 333 InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); | 375 auto params = GetDefaultInitParametersExpectations(); |
| 376 params.duration = base::TimeDelta::FromMicroseconds(2736066); |
| 377 params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| 378 params.detected_audio_track_count = 0; |
| 379 InitializeParserWithInitParametersExpectations(params); |
| 334 | 380 |
| 335 scoped_refptr<DecoderBuffer> buffer = | 381 scoped_refptr<DecoderBuffer> buffer = |
| 336 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4"); | 382 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4"); |
| 337 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); | 383 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| 338 EXPECT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); | 384 EXPECT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| 339 } | 385 } |
| 340 | 386 |
| 341 TEST_F(MP4StreamParserTest, CencWithSampleEncryptionBox) { | 387 TEST_F(MP4StreamParserTest, CencWithSampleEncryptionBox) { |
| 342 // Encrypted test mp4 files have non-zero duration and are treated as | 388 // Encrypted test mp4 files have non-zero duration and are treated as |
| 343 // recorded streams. | 389 // recorded streams. |
| 344 InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); | 390 auto params = GetDefaultInitParametersExpectations(); |
| 391 params.duration = base::TimeDelta::FromMicroseconds(2736066); |
| 392 params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| 393 params.detected_audio_track_count = 0; |
| 394 InitializeParserWithInitParametersExpectations(params); |
| 345 | 395 |
| 346 scoped_refptr<DecoderBuffer> buffer = | 396 scoped_refptr<DecoderBuffer> buffer = |
| 347 ReadTestDataFile("bear-640x360-v_frag-cenc-senc.mp4"); | 397 ReadTestDataFile("bear-640x360-v_frag-cenc-senc.mp4"); |
| 348 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001E")); | 398 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001E")); |
| 349 EXPECT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); | 399 EXPECT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| 350 } | 400 } |
| 351 | 401 |
| 352 TEST_F(MP4StreamParserTest, NaturalSizeWithoutPASP) { | 402 TEST_F(MP4StreamParserTest, NaturalSizeWithoutPASP) { |
| 353 InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); | 403 auto params = GetDefaultInitParametersExpectations(); |
| 404 params.duration = base::TimeDelta::FromMicroseconds(1000966); |
| 405 params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| 406 params.detected_audio_track_count = 0; |
| 407 InitializeParserWithInitParametersExpectations(params); |
| 354 | 408 |
| 355 scoped_refptr<DecoderBuffer> buffer = | 409 scoped_refptr<DecoderBuffer> buffer = |
| 356 ReadTestDataFile("bear-640x360-non_square_pixel-without_pasp.mp4"); | 410 ReadTestDataFile("bear-640x360-non_square_pixel-without_pasp.mp4"); |
| 357 | 411 |
| 358 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001E")); | 412 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001E")); |
| 359 EXPECT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); | 413 EXPECT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| 360 EXPECT_EQ(gfx::Size(639, 360), video_decoder_config_.natural_size()); | 414 EXPECT_EQ(gfx::Size(639, 360), video_decoder_config_.natural_size()); |
| 361 } | 415 } |
| 362 | 416 |
| 363 TEST_F(MP4StreamParserTest, NaturalSizeWithPASP) { | 417 TEST_F(MP4StreamParserTest, NaturalSizeWithPASP) { |
| 364 InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); | 418 auto params = GetDefaultInitParametersExpectations(); |
| 419 params.duration = base::TimeDelta::FromMicroseconds(1000966); |
| 420 params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| 421 params.detected_audio_track_count = 0; |
| 422 InitializeParserWithInitParametersExpectations(params); |
| 365 | 423 |
| 366 scoped_refptr<DecoderBuffer> buffer = | 424 scoped_refptr<DecoderBuffer> buffer = |
| 367 ReadTestDataFile("bear-640x360-non_square_pixel-with_pasp.mp4"); | 425 ReadTestDataFile("bear-640x360-non_square_pixel-with_pasp.mp4"); |
| 368 | 426 |
| 369 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001E")); | 427 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001E")); |
| 370 EXPECT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); | 428 EXPECT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| 371 EXPECT_EQ(gfx::Size(639, 360), video_decoder_config_.natural_size()); | 429 EXPECT_EQ(gfx::Size(639, 360), video_decoder_config_.natural_size()); |
| 372 } | 430 } |
| 373 | 431 |
| 374 TEST_F(MP4StreamParserTest, DemuxingAC3) { | 432 TEST_F(MP4StreamParserTest, DemuxingAC3) { |
| 375 std::set<int> audio_object_types; | 433 std::set<int> audio_object_types; |
| 376 audio_object_types.insert(kAC3); | 434 audio_object_types.insert(kAC3); |
| 377 parser_.reset(new MP4StreamParser(audio_object_types, false)); | 435 parser_.reset(new MP4StreamParser(audio_object_types, false)); |
| 378 | 436 |
| 379 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 437 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 380 bool expect_success = true; | 438 bool expect_success = true; |
| 381 #else | 439 #else |
| 382 bool expect_success = false; | 440 bool expect_success = false; |
| 383 EXPECT_MEDIA_LOG(ErrorLog("Unsupported audio format 0x61632d33 in stsd box")); | 441 EXPECT_MEDIA_LOG(ErrorLog("Unsupported audio format 0x61632d33 in stsd box")); |
| 384 #endif | 442 #endif |
| 385 | 443 |
| 386 InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); | 444 auto params = GetDefaultInitParametersExpectations(); |
| 445 params.duration = base::TimeDelta::FromMicroseconds(1045000); |
| 446 params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| 447 params.detected_video_track_count = 0; |
| 448 InitializeParserWithInitParametersExpectations(params); |
| 449 |
| 387 scoped_refptr<DecoderBuffer> buffer = | 450 scoped_refptr<DecoderBuffer> buffer = |
| 388 ReadTestDataFile("bear-ac3-only-frag.mp4"); | 451 ReadTestDataFile("bear-ac3-only-frag.mp4"); |
| 389 EXPECT_EQ(expect_success, | 452 EXPECT_EQ(expect_success, |
| 390 AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); | 453 AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| 391 } | 454 } |
| 392 | 455 |
| 393 TEST_F(MP4StreamParserTest, DemuxingEAC3) { | 456 TEST_F(MP4StreamParserTest, DemuxingEAC3) { |
| 394 std::set<int> audio_object_types; | 457 std::set<int> audio_object_types; |
| 395 audio_object_types.insert(kEAC3); | 458 audio_object_types.insert(kEAC3); |
| 396 parser_.reset(new MP4StreamParser(audio_object_types, false)); | 459 parser_.reset(new MP4StreamParser(audio_object_types, false)); |
| 397 | 460 |
| 398 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 461 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 399 bool expect_success = true; | 462 bool expect_success = true; |
| 400 #else | 463 #else |
| 401 bool expect_success = false; | 464 bool expect_success = false; |
| 402 EXPECT_MEDIA_LOG(ErrorLog("Unsupported audio format 0x65632d33 in stsd box")); | 465 EXPECT_MEDIA_LOG(ErrorLog("Unsupported audio format 0x65632d33 in stsd box")); |
| 403 #endif | 466 #endif |
| 404 | 467 |
| 405 InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); | 468 auto params = GetDefaultInitParametersExpectations(); |
| 469 params.duration = base::TimeDelta::FromMicroseconds(1045000); |
| 470 params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| 471 params.detected_video_track_count = 0; |
| 472 InitializeParserWithInitParametersExpectations(params); |
| 473 |
| 406 scoped_refptr<DecoderBuffer> buffer = | 474 scoped_refptr<DecoderBuffer> buffer = |
| 407 ReadTestDataFile("bear-eac3-only-frag.mp4"); | 475 ReadTestDataFile("bear-eac3-only-frag.mp4"); |
| 408 EXPECT_EQ(expect_success, | 476 EXPECT_EQ(expect_success, |
| 409 AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); | 477 AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| 410 } | 478 } |
| 411 | 479 |
| 412 TEST_F(MP4StreamParserTest, FourCCToString) { | 480 TEST_F(MP4StreamParserTest, FourCCToString) { |
| 413 // A real FOURCC should print. | 481 // A real FOURCC should print. |
| 414 EXPECT_EQ("mvex", FourCCToString(FOURCC_MVEX)); | 482 EXPECT_EQ("mvex", FourCCToString(FOURCC_MVEX)); |
| 415 | 483 |
| 416 // Invalid FOURCC should also print whenever ASCII values are printable. | 484 // Invalid FOURCC should also print whenever ASCII values are printable. |
| 417 EXPECT_EQ("fake", FourCCToString(static_cast<FourCC>(0x66616b65))); | 485 EXPECT_EQ("fake", FourCCToString(static_cast<FourCC>(0x66616b65))); |
| 418 | 486 |
| 419 // Invalid FORCC with non-printable values should not give error message. | 487 // Invalid FORCC with non-printable values should not give error message. |
| 420 EXPECT_EQ("0x66616b00", FourCCToString(static_cast<FourCC>(0x66616b00))); | 488 EXPECT_EQ("0x66616b00", FourCCToString(static_cast<FourCC>(0x66616b00))); |
| 421 } | 489 } |
| 422 | 490 |
| 423 TEST_F(MP4StreamParserTest, MediaTrackInfoSourcing) { | 491 TEST_F(MP4StreamParserTest, MediaTrackInfoSourcing) { |
| 424 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); | 492 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| 425 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 493 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| 494 InitializeParser(); |
| 426 ParseMP4File("bear-1280x720-av_frag.mp4", 4096); | 495 ParseMP4File("bear-1280x720-av_frag.mp4", 4096); |
| 427 | 496 |
| 428 EXPECT_EQ(media_tracks_->tracks().size(), 2u); | 497 EXPECT_EQ(media_tracks_->tracks().size(), 2u); |
| 429 const MediaTrack& video_track = *(media_tracks_->tracks()[0]); | 498 const MediaTrack& video_track = *(media_tracks_->tracks()[0]); |
| 430 EXPECT_EQ(video_track.type(), MediaTrack::Video); | 499 EXPECT_EQ(video_track.type(), MediaTrack::Video); |
| 431 EXPECT_EQ(video_track.id(), "1"); | 500 EXPECT_EQ(video_track.id(), "1"); |
| 432 EXPECT_EQ(video_track.kind(), "main"); | 501 EXPECT_EQ(video_track.kind(), "main"); |
| 433 EXPECT_EQ(video_track.label(), "VideoHandler"); | 502 EXPECT_EQ(video_track.label(), "VideoHandler"); |
| 434 EXPECT_EQ(video_track.language(), "und"); | 503 EXPECT_EQ(video_track.language(), "und"); |
| 435 | 504 |
| 436 const MediaTrack& audio_track = *(media_tracks_->tracks()[1]); | 505 const MediaTrack& audio_track = *(media_tracks_->tracks()[1]); |
| 437 EXPECT_EQ(audio_track.type(), MediaTrack::Audio); | 506 EXPECT_EQ(audio_track.type(), MediaTrack::Audio); |
| 438 EXPECT_EQ(audio_track.id(), "2"); | 507 EXPECT_EQ(audio_track.id(), "2"); |
| 439 EXPECT_EQ(audio_track.kind(), "main"); | 508 EXPECT_EQ(audio_track.kind(), "main"); |
| 440 EXPECT_EQ(audio_track.label(), "SoundHandler"); | 509 EXPECT_EQ(audio_track.label(), "SoundHandler"); |
| 441 EXPECT_EQ(audio_track.language(), "und"); | 510 EXPECT_EQ(audio_track.language(), "und"); |
| 442 } | 511 } |
| 443 | 512 |
| 513 TEST_F(MP4StreamParserTest, TextTrackDetection) { |
| 514 auto params = GetDefaultInitParametersExpectations(); |
| 515 params.detected_text_track_count = 1; |
| 516 InitializeParserWithInitParametersExpectations(params); |
| 517 |
| 518 scoped_refptr<DecoderBuffer> buffer = |
| 519 ReadTestDataFile("bear-1280x720-avt_subt_frag.mp4"); |
| 520 |
| 521 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| 522 EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| 523 EXPECT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| 524 } |
| 525 |
| 444 } // namespace mp4 | 526 } // namespace mp4 |
| 445 } // namespace media | 527 } // namespace media |
| OLD | NEW |