Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: media/filters/chunk_demuxer_unittest.cc

Issue 110693007: Fix various operations in ChunkDemuxer that were not being applied to text tracks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address CR comment and added tests Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 EXPECT_FALSE(video_stream); 1053 EXPECT_FALSE(video_stream);
1054 } 1054 }
1055 1055
1056 ShutdownDemuxer(); 1056 ShutdownDemuxer();
1057 demuxer_.reset(); 1057 demuxer_.reset();
1058 } 1058 }
1059 } 1059 }
1060 1060
1061 // Make sure that the demuxer reports an error if Shutdown() 1061 // Make sure that the demuxer reports an error if Shutdown()
1062 // is called before all the initialization segments are appended. 1062 // is called before all the initialization segments are appended.
1063 TEST_F(ChunkDemuxerTest, ShutdownBeforeAllInitSegmentsAppended) { 1063 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) {
xhwang 2014/01/08 19:03:26 In this test and the next one, it's not clear how
acolwell GONE FROM CHROMIUM 2014/01/09 00:21:13 I've added explicit ShutdownDemuxer() calls to mak
1064 EXPECT_CALL(*this, DemuxerOpened()); 1064 EXPECT_CALL(*this, DemuxerOpened());
1065 demuxer_->Initialize( 1065 demuxer_->Initialize(
1066 &host_, CreateInitDoneCB( 1066 &host_, CreateInitDoneCB(
1067 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1067 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1068 1068
1069 EXPECT_EQ(AddId("audio", true, false), ChunkDemuxer::kOk); 1069 EXPECT_EQ(AddId("audio", true, false), ChunkDemuxer::kOk);
1070 EXPECT_EQ(AddId("video", false, true), ChunkDemuxer::kOk); 1070 EXPECT_EQ(AddId("video", false, true), ChunkDemuxer::kOk);
1071 1071
1072 AppendInitSegmentWithSourceId("audio", true, false, false); 1072 AppendInitSegmentWithSourceId("audio", true, false, false);
xhwang 2014/01/08 19:03:26 Can we also use the new HAS_VIDEO | HAS_XXX patter
acolwell GONE FROM CHROMIUM 2014/01/09 00:21:13 Done. This resulted in a fair amount of changes, b
1073 } 1073 }
1074 1074
1075 TEST_F(ChunkDemuxerTest, ShutdownBeforeAllInitSegmentsAppendedText) { 1075 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) {
1076 EXPECT_CALL(*this, DemuxerOpened()); 1076 EXPECT_CALL(*this, DemuxerOpened());
1077 demuxer_->Initialize( 1077 demuxer_->Initialize(
1078 &host_, CreateInitDoneCB( 1078 &host_, CreateInitDoneCB(
1079 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1079 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1080 1080
1081 EXPECT_EQ(AddId("audio", true, false), ChunkDemuxer::kOk); 1081 EXPECT_EQ(AddId("audio", true, false), ChunkDemuxer::kOk);
1082 EXPECT_EQ(AddId("video", false, true), ChunkDemuxer::kOk); 1082 EXPECT_EQ(AddId("video", false, true), ChunkDemuxer::kOk);
1083 1083
1084 EXPECT_CALL(host_, AddTextStream(_, _)) 1084 EXPECT_CALL(host_, AddTextStream(_, _))
1085 .Times(Exactly(1)); 1085 .Times(Exactly(1));
1086 1086
1087 AppendInitSegmentWithSourceId("video", false, true, true); 1087 AppendInitSegmentWithSourceId("video", false, true, true);
xhwang 2014/01/08 19:03:26 s/video/video_and_text?
acolwell GONE FROM CHROMIUM 2014/01/09 00:21:13 These are just ID names so they don't really matte
1088 } 1088 }
1089 1089
1090 TEST_F(ChunkDemuxerTest, Shutdown_AllPendingReadsEOS) {
xhwang 2014/01/08 19:03:26 This name is ambiguous. It reads like "shutdown du
acolwell GONE FROM CHROMIUM 2014/01/09 00:21:13 Changed the name and added a comment.
1091 DemuxerStream* text_stream = NULL;
1092 EXPECT_CALL(host_, AddTextStream(_, _))
1093 .WillOnce(SaveArg<0>(&text_stream));
1094 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
1095
1096 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
1097 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
1098
1099 bool audio_read_done = false;
1100 bool video_read_done = false;
1101 bool text_read_done = false;
1102 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done));
1103 video_stream->Read(base::Bind(&OnReadDone_EOSExpected, &video_read_done));
1104 text_stream->Read(base::Bind(&OnReadDone_EOSExpected, &text_read_done));
1105 message_loop_.RunUntilIdle();
1106
1107 EXPECT_FALSE(audio_read_done);
1108 EXPECT_FALSE(video_read_done);
1109 EXPECT_FALSE(text_read_done);
1110
1111 ShutdownDemuxer();
1112 demuxer_.reset();
1113
1114 EXPECT_TRUE(audio_read_done);
1115 EXPECT_TRUE(video_read_done);
1116 EXPECT_TRUE(text_read_done);
1117 }
1118
1090 // Test that Seek() completes successfully when the first cluster 1119 // Test that Seek() completes successfully when the first cluster
1091 // arrives. 1120 // arrives.
1092 TEST_F(ChunkDemuxerTest, AppendDataAfterSeek) { 1121 TEST_F(ChunkDemuxerTest, AppendDataAfterSeek) {
1093 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1122 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1094 AppendCluster(kDefaultFirstCluster()); 1123 AppendCluster(kDefaultFirstCluster());
1095 1124
1096 InSequence s; 1125 InSequence s;
1097 1126
1098 EXPECT_CALL(*this, Checkpoint(1)); 1127 EXPECT_CALL(*this, Checkpoint(1));
1099 1128
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after
2661 2690
2662 demuxer_->UnmarkEndOfStream(); 2691 demuxer_->UnmarkEndOfStream();
2663 2692
2664 AppendCluster(kDefaultSecondCluster()); 2693 AppendCluster(kDefaultSecondCluster());
2665 MarkEndOfStream(PIPELINE_OK); 2694 MarkEndOfStream(PIPELINE_OK);
2666 } 2695 }
2667 2696
2668 // Test receiving a Shutdown() call before we get an Initialize() 2697 // Test receiving a Shutdown() call before we get an Initialize()
2669 // call. This can happen if video element gets destroyed before 2698 // call. This can happen if video element gets destroyed before
2670 // the pipeline has a chance to initialize the demuxer. 2699 // the pipeline has a chance to initialize the demuxer.
2671 TEST_F(ChunkDemuxerTest, ShutdownBeforeInitialize) { 2700 TEST_F(ChunkDemuxerTest, Shutdown_BeforeInitialize) {
2672 demuxer_->Shutdown(); 2701 demuxer_->Shutdown();
2673 demuxer_->Initialize( 2702 demuxer_->Initialize(
2674 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN), true); 2703 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN), true);
2675 message_loop_.RunUntilIdle(); 2704 message_loop_.RunUntilIdle();
2676 } 2705 }
2677 2706
2678 TEST_F(ChunkDemuxerTest, ReadAfterAudioDisabled) { 2707 TEST_F(ChunkDemuxerTest, ReadAfterAudioDisabled) {
2679 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2708 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2680 AppendCluster(kDefaultFirstCluster()); 2709 AppendCluster(kDefaultFirstCluster());
2681 2710
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 } 2963 }
2935 2964
2936 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) { 2965 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) {
2937 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2966 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2938 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 2967 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
2939 AppendGarbage(); 2968 AppendGarbage();
2940 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50); 2969 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50);
2941 demuxer_->StartWaitingForSeek(seek_time); 2970 demuxer_->StartWaitingForSeek(seek_time);
2942 } 2971 }
2943 2972
2973 TEST_F(ChunkDemuxerTest, Remove_AudioVideoText) {
2974 DemuxerStream* text_stream = NULL;
2975 EXPECT_CALL(host_, AddTextStream(_, _))
2976 .WillOnce(SaveArg<0>(&text_stream));
2977 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
2978
2979 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
2980 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
2981
2982 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
2983 "0K 20K 40K 60K 80K 100K 120K 140K");
2984 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
2985 "0K 30 60 90 120K 150 180");
2986 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K 200K");
2987
2988 CheckExpectedBuffers(audio_stream, "0 20 40 60 80 100 120 140");
2989 CheckExpectedBuffers(video_stream, "0 30 60 90 120 150 180");
2990 CheckExpectedBuffers(text_stream, "0 100 200");
2991
2992 // Remove the buffers that were added.
2993 demuxer_->Remove(kSourceId, base::TimeDelta(),
2994 base::TimeDelta::FromMilliseconds(300));
2995
xhwang 2014/01/08 19:03:26 CheckExpectedBuffers here to make sure the buffers
acolwell GONE FROM CHROMIUM 2014/01/09 00:21:13 I can't use CheckExpectedBuffers here because ther
2996 // Append new buffers that are clearly different than the original
2997 // ones and verify that only the new buffers are returned.
2998 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
2999 "1K 21K 41K 61K 81K 101K 121K 141K");
3000 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3001 "1K 31 61 91 121K 151 181");
3002 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "1K 101K 201K");
3003
3004 Seek(base::TimeDelta());
3005 CheckExpectedBuffers(audio_stream, "1 21 41 61 81 101 121 141");
3006 CheckExpectedBuffers(video_stream, "1 31 61 91 121 151 181");
3007 CheckExpectedBuffers(text_stream, "1 101 201");
3008 }
3009
3010 // Verifies that a Seek() will complete without text cues for
3011 // the seek point and will return cues after the seek position
3012 // when they are eventually appended.
3013 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) {
3014 DemuxerStream* text_stream = NULL;
3015 EXPECT_CALL(host_, AddTextStream(_, _))
3016 .WillOnce(SaveArg<0>(&text_stream));
3017 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
3018
3019 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3020 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3021
3022 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(120);
3023 bool seek_cb_was_called = false;
3024 demuxer_->StartWaitingForSeek(seek_time);
3025 demuxer_->Seek(seek_time,
3026 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called));
3027 message_loop_.RunUntilIdle();
3028
3029 EXPECT_FALSE(seek_cb_was_called);
3030
3031 bool text_read_done = false;
3032 text_stream->Read(base::Bind(&OnReadDone,
3033 base::TimeDelta::FromMilliseconds(125),
3034 &text_read_done));
3035
3036 // Append audio & video data so the seek completes.
3037 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
3038 "0K 20K 40K 60K 80K 100K 120K 140K 160K 180K");
3039 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3040 "0K 30 60 90 120K 150 180 210");
3041
3042 message_loop_.RunUntilIdle();
3043 EXPECT_TRUE(seek_cb_was_called);
3044 EXPECT_FALSE(text_read_done);
3045
3046 // Read some audio & video buffers to further verify seek completion.
3047 CheckExpectedBuffers(audio_stream, "120 140");
3048 CheckExpectedBuffers(video_stream, "120 150");
3049
3050 EXPECT_FALSE(text_read_done);
3051
3052 // Append text cues that start after the seek point and verify that
3053 // they are returned by Read() calls.
3054 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "125K 175K 225K");
3055
3056 message_loop_.RunUntilIdle();
3057 EXPECT_TRUE(text_read_done);
3058
3059 // NOTE: we start at 175 here because the buffer at 125 was returned
3060 // to the pending read initiated above.
3061 CheckExpectedBuffers(text_stream, "175 225");
3062
3063 // Verify that audio & video streams contiue to return expected values.
3064 CheckExpectedBuffers(audio_stream, "160 180");
3065 CheckExpectedBuffers(video_stream, "180 210");
3066 }
xhwang 2014/01/08 19:03:26 I like this test!
acolwell GONE FROM CHROMIUM 2014/01/09 00:21:13 thanks. :)
3067
2944 } // namespace media 3068 } // namespace media
OLDNEW
« media/filters/chunk_demuxer.cc ('K') | « media/filters/chunk_demuxer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698