Chromium Code Reviews| Index: media/formats/mp4/mp4_stream_parser_unittest.cc |
| diff --git a/media/formats/mp4/mp4_stream_parser_unittest.cc b/media/formats/mp4/mp4_stream_parser_unittest.cc |
| index 26144ee3ef8d3d59035f2831eb3f2588820ae2e0..f5681776bd4ce4e17ef77ab9dd572a36c9723849 100644 |
| --- a/media/formats/mp4/mp4_stream_parser_unittest.cc |
| +++ b/media/formats/mp4/mp4_stream_parser_unittest.cc |
| @@ -18,6 +18,7 @@ |
| #include "media/base/media_track.h" |
| #include "media/base/media_tracks.h" |
| #include "media/base/mock_media_log.h" |
| +#include "media/base/stream_parser.h" |
| #include "media/base/stream_parser_buffer.h" |
| #include "media/base/test_data_util.h" |
| #include "media/base/text_track_config.h" |
| @@ -93,11 +94,21 @@ class MP4StreamParserTest : public testing::Test { |
| return true; |
| } |
| - void InitF(DemuxerStream::Liveness expected_liveness, |
| + void InitF(const StreamParser::InitParameters& expected_params, |
| const StreamParser::InitParameters& params) { |
| - DVLOG(1) << "InitF: dur=" << params.duration.InMilliseconds() |
| + DVLOG(1) << "InitF: dur=" << params.duration.InMicroseconds() |
| << ", autoTimestampOffset=" << params.auto_update_timestamp_offset; |
| - EXPECT_EQ(expected_liveness, params.liveness); |
| + EXPECT_EQ(expected_params.duration, params.duration); |
| + EXPECT_EQ(expected_params.timeline_offset, params.timeline_offset); |
| + EXPECT_EQ(expected_params.auto_update_timestamp_offset, |
| + params.auto_update_timestamp_offset); |
| + EXPECT_EQ(expected_params.liveness, params.liveness); |
| + EXPECT_EQ(expected_params.detected_audio_track_count, |
| + params.detected_audio_track_count); |
| + EXPECT_EQ(expected_params.detected_video_track_count, |
| + params.detected_video_track_count); |
| + EXPECT_EQ(expected_params.detected_text_track_count, |
| + params.detected_text_track_count); |
| } |
| bool NewConfigF(scoped_ptr<MediaTracks> tracks, |
| @@ -173,11 +184,10 @@ class MP4StreamParserTest : public testing::Test { |
| DecodeTimestamp::FromPresentationTime(base::TimeDelta::Max()); |
| } |
| - void InitializeParserAndExpectLiveness( |
| - DemuxerStream::Liveness expected_liveness) { |
| + void InitializeParserWithInitParametersExpectations( |
| + StreamParser::InitParameters params) { |
| parser_->Init( |
| - base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this), |
| - expected_liveness), |
| + base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this), params), |
| base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), |
| base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), |
| true, |
| @@ -187,15 +197,29 @@ class MP4StreamParserTest : public testing::Test { |
| media_log_); |
| } |
| - void InitializeParser() { |
| + StreamParser::InitParameters GetDefaultInitParametersExpectations() { |
| // Most unencrypted test mp4 files have zero duration and are treated as |
| // live streams. |
| - InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_LIVE); |
| + StreamParser::InitParameters params(kInfiniteDuration()); |
| + params.liveness = DemuxerStream::LIVENESS_LIVE; |
| + params.detected_audio_track_count = 1; |
| + params.detected_video_track_count = 1; |
| + params.detected_text_track_count = 0; |
| + return params; |
| } |
| - bool ParseMP4File(const std::string& filename, int append_bytes) { |
| - InitializeParser(); |
| + void InitializeParserAndExpectLiveness(DemuxerStream::Liveness liveness) { |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.liveness = liveness; |
| + InitializeParserWithInitParametersExpectations(params); |
| + } |
| + |
| + void InitializeParser() { |
| + InitializeParserWithInitParametersExpectations( |
| + GetDefaultInitParametersExpectations()); |
| + } |
| + bool ParseMP4File(const std::string& filename, int append_bytes) { |
| scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); |
| EXPECT_TRUE(AppendDataInPieces(buffer->data(), |
| buffer->data_size(), |
| @@ -209,6 +233,7 @@ TEST_F(MP4StreamParserTest, UnalignedAppend) { |
| // incremental append system) |
| EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| + InitializeParser(); |
| ParseMP4File("bear-1280x720-av_frag.mp4", 512); |
| } |
| @@ -216,6 +241,7 @@ TEST_F(MP4StreamParserTest, BytewiseAppend) { |
| // Ensure no incremental errors occur when parsing |
| EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| + InitializeParser(); |
| ParseMP4File("bear-1280x720-av_frag.mp4", 1); |
| } |
| @@ -224,6 +250,7 @@ TEST_F(MP4StreamParserTest, MultiFragmentAppend) { |
| // larger than this particular test file) |
| EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| + InitializeParser(); |
| ParseMP4File("bear-1280x720-av_frag.mp4", 768432); |
| } |
| @@ -264,6 +291,9 @@ TEST_F(MP4StreamParserTest, MPEG2_AAC_LC) { |
| parser_.reset(new MP4StreamParser(audio_object_types, false)); |
| EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.67")); |
| EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.detected_video_track_count = 0; |
| + InitializeParserWithInitParametersExpectations(params); |
| ParseMP4File("bear-mpeg2-aac-only_frag.mp4", 512); |
| } |
| @@ -295,7 +325,11 @@ TEST_F(MP4StreamParserTest, MissingSampleEncryptionInfo) { |
| // Encrypted test mp4 files have non-zero duration and are treated as |
| // recorded streams. |
| - InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.duration = base::TimeDelta::FromMicroseconds(23219); |
| + params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| + params.detected_video_track_count = 0; |
| + InitializeParserWithInitParametersExpectations(params); |
| scoped_refptr<DecoderBuffer> buffer = |
| ReadTestDataFile("bear-1280x720-a_frag-cenc_missing-saiz-saio.mp4"); |
| @@ -308,6 +342,9 @@ TEST_F(MP4StreamParserTest, MissingSampleEncryptionInfo) { |
| // Delimiter (AUD) NALU. |
| TEST_F(MP4StreamParserTest, VideoSamplesStartWithAUDs) { |
| EXPECT_MEDIA_LOG(VideoCodecLog("avc1.4D4028")); |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.detected_audio_track_count = 0; |
| + InitializeParserWithInitParametersExpectations(params); |
| ParseMP4File("bear-1280x720-av_with-aud-nalus_frag.mp4", 512); |
| } |
| @@ -319,7 +356,12 @@ TEST_F(MP4StreamParserTest, HEVC_in_MP4_container) { |
| bool expect_success = false; |
| EXPECT_MEDIA_LOG(ErrorLog("Parse unsupported video format hev1")); |
| #endif |
| - InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.duration = base::TimeDelta::FromMicroseconds(1002000); |
| + params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| + params.detected_audio_track_count = 0; |
| + InitializeParserWithInitParametersExpectations(params); |
| + |
| scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-hevc-frag.mp4"); |
| EXPECT_EQ(expect_success, |
| AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| @@ -330,7 +372,11 @@ TEST_F(MP4StreamParserTest, HEVC_in_MP4_container) { |
| TEST_F(MP4StreamParserTest, CencWithEncryptionInfoStoredAsAuxDataInMdat) { |
| // Encrypted test mp4 files have non-zero duration and are treated as |
| // recorded streams. |
| - InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.duration = base::TimeDelta::FromMicroseconds(2736066); |
| + params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| + params.detected_audio_track_count = 0; |
| + InitializeParserWithInitParametersExpectations(params); |
| scoped_refptr<DecoderBuffer> buffer = |
| ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4"); |
| @@ -341,7 +387,11 @@ TEST_F(MP4StreamParserTest, CencWithEncryptionInfoStoredAsAuxDataInMdat) { |
| TEST_F(MP4StreamParserTest, CencWithSampleEncryptionBox) { |
| // Encrypted test mp4 files have non-zero duration and are treated as |
| // recorded streams. |
| - InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.duration = base::TimeDelta::FromMicroseconds(2736066); |
| + params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| + params.detected_audio_track_count = 0; |
| + InitializeParserWithInitParametersExpectations(params); |
| scoped_refptr<DecoderBuffer> buffer = |
| ReadTestDataFile("bear-640x360-v_frag-cenc-senc.mp4"); |
| @@ -350,7 +400,11 @@ TEST_F(MP4StreamParserTest, CencWithSampleEncryptionBox) { |
| } |
| TEST_F(MP4StreamParserTest, NaturalSizeWithoutPASP) { |
| - InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.duration = base::TimeDelta::FromMicroseconds(1000966); |
| + params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| + params.detected_audio_track_count = 0; |
| + InitializeParserWithInitParametersExpectations(params); |
| scoped_refptr<DecoderBuffer> buffer = |
| ReadTestDataFile("bear-640x360-non_square_pixel-without_pasp.mp4"); |
| @@ -361,7 +415,11 @@ TEST_F(MP4StreamParserTest, NaturalSizeWithoutPASP) { |
| } |
| TEST_F(MP4StreamParserTest, NaturalSizeWithPASP) { |
| - InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.duration = base::TimeDelta::FromMicroseconds(1000966); |
| + params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| + params.detected_audio_track_count = 0; |
| + InitializeParserWithInitParametersExpectations(params); |
| scoped_refptr<DecoderBuffer> buffer = |
| ReadTestDataFile("bear-640x360-non_square_pixel-with_pasp.mp4"); |
| @@ -383,7 +441,12 @@ TEST_F(MP4StreamParserTest, DemuxingAC3) { |
| EXPECT_MEDIA_LOG(ErrorLog("Unsupported audio format 0x61632d33 in stsd box")); |
| #endif |
| - InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.duration = base::TimeDelta::FromMicroseconds(1045000); |
| + params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| + params.detected_video_track_count = 0; |
| + InitializeParserWithInitParametersExpectations(params); |
| + |
| scoped_refptr<DecoderBuffer> buffer = |
| ReadTestDataFile("bear-ac3-only-frag.mp4"); |
| EXPECT_EQ(expect_success, |
| @@ -402,7 +465,12 @@ TEST_F(MP4StreamParserTest, DemuxingEAC3) { |
| EXPECT_MEDIA_LOG(ErrorLog("Unsupported audio format 0x65632d33 in stsd box")); |
| #endif |
| - InitializeParserAndExpectLiveness(DemuxerStream::LIVENESS_RECORDED); |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.duration = base::TimeDelta::FromMicroseconds(1045000); |
| + params.liveness = DemuxerStream::LIVENESS_RECORDED; |
| + params.detected_video_track_count = 0; |
| + InitializeParserWithInitParametersExpectations(params); |
| + |
| scoped_refptr<DecoderBuffer> buffer = |
| ReadTestDataFile("bear-eac3-only-frag.mp4"); |
| EXPECT_EQ(expect_success, |
| @@ -423,6 +491,7 @@ TEST_F(MP4StreamParserTest, FourCCToString) { |
| TEST_F(MP4StreamParserTest, MediaTrackInfoSourcing) { |
| EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| + InitializeParser(); |
| ParseMP4File("bear-1280x720-av_frag.mp4", 4096); |
| EXPECT_EQ(media_tracks_->tracks().size(), 2u); |
| @@ -441,5 +510,18 @@ TEST_F(MP4StreamParserTest, MediaTrackInfoSourcing) { |
| EXPECT_EQ(audio_track.language(), "und"); |
| } |
| +TEST_F(MP4StreamParserTest, TextTrackDetection) { |
| + auto params = GetDefaultInitParametersExpectations(); |
| + params.detected_text_track_count = 1; |
| + InitializeParserWithInitParametersExpectations(params); |
| + |
| + scoped_refptr<DecoderBuffer> buffer = |
| + ReadTestDataFile("bear-1280x720-avt_subt_frag.mp4"); |
|
chcunningham
2016/03/29 22:14:50
cool!
|
| + |
| + EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); |
| + EXPECT_MEDIA_LOG(VideoCodecLog("avc1.64001F")); |
| + EXPECT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
| +} |
| + |
| } // namespace mp4 |
| } // namespace media |