OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/ptr_util.h" | |
6 #include "media/base/test_data_util.h" | |
7 #include "media/remoting/end2end_test_renderer.h" | |
8 #include "media/test/pipeline_integration_test_base.h" | |
9 | |
10 namespace media { | |
11 namespace remoting { | |
12 | |
13 namespace { | |
14 | |
15 constexpr char kWebM[] = "video/webm; codecs=\"vp8,vorbis\""; | |
16 constexpr char kAudioOnlyWebM[] = "video/webm; codecs=\"vorbis\""; | |
17 constexpr char kVideoOnlyWebM[] = "video/webm; codecs=\"vp8\""; | |
18 constexpr int kAppendTimeSec = 1; | |
19 | |
20 class TestRendererFactory final : public PipelineTestRendererFactory { | |
21 public: | |
22 explicit TestRendererFactory( | |
23 std::unique_ptr<PipelineTestRendererFactory> renderer_factory) | |
24 : default_renderer_factory_(std::move(renderer_factory)) {} | |
25 ~TestRendererFactory() override {} | |
26 | |
27 // PipelineTestRendererFactory implementation. | |
28 std::unique_ptr<Renderer> CreateRenderer( | |
29 CreateVideoDecodersCB prepend_video_decoders_cb = CreateVideoDecodersCB(), | |
DaleCurtis
2017/04/20 18:24:50
Style for unused arguments is to put the parameter
xjz
2017/04/20 21:26:09
Done.
| |
30 CreateAudioDecodersCB prepend_audio_decoders_cb = | |
31 CreateAudioDecodersCB()) override { | |
32 std::unique_ptr<Renderer> renderer_impl = | |
33 default_renderer_factory_->CreateRenderer(prepend_video_decoders_cb, | |
34 prepend_audio_decoders_cb); | |
35 return base::MakeUnique<End2EndTestRenderer>(std::move(renderer_impl)); | |
36 } | |
37 | |
38 private: | |
39 std::unique_ptr<PipelineTestRendererFactory> default_renderer_factory_; | |
40 | |
41 DISALLOW_COPY_AND_ASSIGN(TestRendererFactory); | |
42 }; | |
43 | |
44 } // namespace | |
45 | |
46 class MediaRemotingIntegrationTest : public testing::Test, | |
47 public PipelineIntegrationTestBase { | |
48 public: | |
49 MediaRemotingIntegrationTest() { | |
50 std::unique_ptr<PipelineTestRendererFactory> factory = | |
51 std::move(renderer_factory_); | |
52 renderer_factory_.reset(new TestRendererFactory(std::move(factory))); | |
53 } | |
54 | |
55 private: | |
56 DISALLOW_COPY_AND_ASSIGN(MediaRemotingIntegrationTest); | |
57 }; | |
58 | |
59 TEST_F(MediaRemotingIntegrationTest, BasicPlayback) { | |
60 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); | |
61 Play(); | |
62 ASSERT_TRUE(WaitUntilOnEnded()); | |
63 } | |
64 | |
65 TEST_F(MediaRemotingIntegrationTest, BasicPlaybackHashed) { | |
DaleCurtis
2017/04/20 18:24:51
I think you can remove this or replace the BasicPl
xjz
2017/04/20 21:26:09
Done.
| |
66 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm", TestTypeFlags::kHashed)); | |
67 Play(); | |
68 ASSERT_TRUE(WaitUntilOnEnded()); | |
69 | |
70 EXPECT_EQ("f0be120a90a811506777c99a2cdf7cc1", GetVideoHash()); | |
71 EXPECT_EQ("-3.59,-2.06,-0.43,2.15,0.77,-0.95,", GetAudioHash()); | |
72 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null()); | |
DaleCurtis
2017/04/20 18:24:50
Delete; not relevant to your testing.
xjz
2017/04/20 21:26:09
Done.
| |
73 } | |
74 | |
75 TEST_F(MediaRemotingIntegrationTest, BasicPlayback_MediaSource) { | |
76 MockMediaSource source("bear-320x240.webm", kWebM, 219229); | |
77 EXPECT_EQ(PIPELINE_OK, StartPipelineWithMediaSource(&source)); | |
78 source.EndOfStream(); | |
79 | |
80 Play(); | |
81 ASSERT_TRUE(WaitUntilOnEnded()); | |
82 EXPECT_TRUE(demuxer_->GetTimelineOffset().is_null()); | |
DaleCurtis
2017/04/20 18:24:51
Delete.
xjz
2017/04/20 21:26:09
Done.
| |
83 source.Shutdown(); | |
84 Stop(); | |
85 } | |
86 | |
87 TEST_F(MediaRemotingIntegrationTest, MediaSource_ConfigChange_WebM) { | |
88 MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM, | |
89 kAppendWholeFile); | |
90 EXPECT_EQ(PIPELINE_OK, StartPipelineWithMediaSource(&source)); | |
91 | |
92 EXPECT_CALL(*this, OnVideoNaturalSizeChange(gfx::Size(640, 360))).Times(1); | |
93 scoped_refptr<DecoderBuffer> second_file = | |
94 ReadTestDataFile("bear-640x360.webm"); | |
95 ASSERT_TRUE(source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec), | |
96 second_file->data(), | |
97 second_file->data_size())); | |
98 source.EndOfStream(); | |
99 | |
100 Play(); | |
101 EXPECT_TRUE(WaitUntilOnEnded()); | |
102 | |
103 source.Shutdown(); | |
104 Stop(); | |
105 } | |
106 | |
107 TEST_F(MediaRemotingIntegrationTest, SeekWhilePaused) { | |
DaleCurtis
2017/04/20 18:24:50
Probably only need one of these seek tests since t
xjz
2017/04/20 21:26:09
Done.
| |
108 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); | |
109 | |
110 base::TimeDelta duration(pipeline_->GetMediaDuration()); | |
111 base::TimeDelta start_seek_time(duration / 4); | |
112 base::TimeDelta seek_time(duration * 3 / 4); | |
113 | |
114 Play(); | |
115 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time)); | |
116 Pause(); | |
117 ASSERT_TRUE(Seek(seek_time)); | |
118 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); | |
119 Play(); | |
120 ASSERT_TRUE(WaitUntilOnEnded()); | |
121 | |
122 // Make sure seeking after reaching the end works as expected. | |
123 Pause(); | |
124 ASSERT_TRUE(Seek(seek_time)); | |
125 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); | |
126 Play(); | |
127 ASSERT_TRUE(WaitUntilOnEnded()); | |
128 } | |
129 | |
130 TEST_F(MediaRemotingIntegrationTest, SeekWhilePlaying) { | |
131 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); | |
132 | |
133 base::TimeDelta duration(pipeline_->GetMediaDuration()); | |
134 base::TimeDelta start_seek_time(duration / 4); | |
135 base::TimeDelta seek_time(duration * 3 / 4); | |
136 | |
137 Play(); | |
138 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time)); | |
139 ASSERT_TRUE(Seek(seek_time)); | |
140 EXPECT_GE(pipeline_->GetMediaTime(), seek_time); | |
141 ASSERT_TRUE(WaitUntilOnEnded()); | |
142 | |
143 // Make sure seeking after reaching the end works as expected. | |
144 ASSERT_TRUE(Seek(seek_time)); | |
145 EXPECT_GE(pipeline_->GetMediaTime(), seek_time); | |
146 ASSERT_TRUE(WaitUntilOnEnded()); | |
147 } | |
148 | |
149 TEST_F(MediaRemotingIntegrationTest, SuspendWhilePaused) { | |
DaleCurtis
2017/04/20 18:24:51
Delete, not necessary here.
xjz
2017/04/20 21:26:09
Done.
| |
150 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); | |
151 | |
152 base::TimeDelta duration(pipeline_->GetMediaDuration()); | |
153 base::TimeDelta start_seek_time(duration / 4); | |
154 base::TimeDelta seek_time(duration * 3 / 4); | |
155 | |
156 Play(); | |
157 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time)); | |
158 Pause(); | |
159 | |
160 // Suspend while paused. | |
161 ASSERT_TRUE(Suspend()); | |
162 | |
163 // Resuming the pipeline will create a new Renderer, | |
164 // which in turn will trigger video size and opacity notifications. | |
165 EXPECT_CALL(*this, OnVideoNaturalSizeChange(gfx::Size(320, 240))).Times(1); | |
166 EXPECT_CALL(*this, OnVideoOpacityChange(true)).Times(1); | |
167 | |
168 ASSERT_TRUE(Resume(seek_time)); | |
169 EXPECT_GE(pipeline_->GetMediaTime(), seek_time); | |
170 Play(); | |
171 ASSERT_TRUE(WaitUntilOnEnded()); | |
172 } | |
173 | |
174 TEST_F(MediaRemotingIntegrationTest, SuspendWhilePlaying) { | |
DaleCurtis
2017/04/20 18:24:50
Delete.
xjz
2017/04/20 21:26:09
Done.
| |
175 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); | |
176 | |
177 base::TimeDelta duration(pipeline_->GetMediaDuration()); | |
178 base::TimeDelta start_seek_time(duration / 4); | |
179 base::TimeDelta seek_time(duration * 3 / 4); | |
180 | |
181 Play(); | |
182 ASSERT_TRUE(WaitUntilCurrentTimeIsAfter(start_seek_time)); | |
183 ASSERT_TRUE(Suspend()); | |
184 | |
185 // Resuming the pipeline will create a new Renderer, | |
186 // which in turn will trigger video size and opacity notifications. | |
187 EXPECT_CALL(*this, OnVideoNaturalSizeChange(gfx::Size(320, 240))).Times(1); | |
188 EXPECT_CALL(*this, OnVideoOpacityChange(true)).Times(1); | |
189 | |
190 ASSERT_TRUE(Resume(seek_time)); | |
191 EXPECT_GE(pipeline_->GetMediaTime(), seek_time); | |
192 ASSERT_TRUE(WaitUntilOnEnded()); | |
193 } | |
194 | |
195 // Verify audio decoder & renderer can handle aborted demuxer reads. | |
DaleCurtis
2017/04/20 18:24:50
Delete.
xjz
2017/04/20 21:26:09
Done.
| |
196 TEST_F(MediaRemotingIntegrationTest, ChunkDemuxerAbortRead_AudioOnly) { | |
197 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-audio-only.webm", kAudioOnlyWebM, | |
198 16384, base::TimeDelta::FromMilliseconds(464), | |
199 base::TimeDelta::FromMilliseconds(617), 0x10CA, | |
200 19730)); | |
201 } | |
202 | |
203 // Verify video decoder & renderer can handle aborted demuxer reads. | |
DaleCurtis
2017/04/20 18:24:50
Delete.
xjz
2017/04/20 21:26:09
Done.
| |
204 TEST_F(MediaRemotingIntegrationTest, ChunkDemuxerAbortRead_VideoOnly) { | |
205 ASSERT_TRUE(TestSeekDuringRead("bear-320x240-video-only.webm", kVideoOnlyWebM, | |
206 32768, base::TimeDelta::FromMilliseconds(167), | |
207 base::TimeDelta::FromMilliseconds(1668), | |
208 0x1C896, 65536)); | |
209 } | |
210 | |
211 // Tests that we signal ended even when audio runs longer than video track. | |
DaleCurtis
2017/04/20 18:24:50
Probably delete.
xjz
2017/04/20 21:26:09
Done.
| |
212 TEST_F(MediaRemotingIntegrationTest, BasicPlaybackAudioLongerThanVideo) { | |
213 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_longer_than_video.ogv")); | |
214 // Audio track is 2000ms. Video track is 1001ms. Duration should be higher | |
215 // of the two. | |
216 EXPECT_EQ(2000, pipeline_->GetMediaDuration().InMilliseconds()); | |
217 Play(); | |
218 ASSERT_TRUE(WaitUntilOnEnded()); | |
219 } | |
220 | |
221 // Tests that we signal ended even when audio runs shorter than video track. | |
222 TEST_F(MediaRemotingIntegrationTest, BasicPlaybackAudioShorterThanVideo) { | |
223 ASSERT_EQ(PIPELINE_OK, Start("bear_audio_shorter_than_video.ogv")); | |
224 // Audio track is 500ms. Video track is 1001ms. Duration should be higher of | |
225 // the two. | |
226 EXPECT_EQ(1001, pipeline_->GetMediaDuration().InMilliseconds()); | |
227 Play(); | |
228 ASSERT_TRUE(WaitUntilOnEnded()); | |
229 } | |
230 | |
231 TEST_F(MediaRemotingIntegrationTest, BasicPlaybackPositiveStartTime) { | |
232 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); | |
233 Play(); | |
234 ASSERT_TRUE(WaitUntilOnEnded()); | |
235 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), | |
236 demuxer_->GetStartTime()); | |
237 } | |
238 | |
239 } // names | |
240 } // namespace media | |
OLD | NEW |