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

Side by Side Diff: media/renderers/video_renderer_impl_unittest.cc

Issue 2086353002: Remove calls to deprecated MessageLoop methods in media. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/debug/stack_trace.h" 13 #include "base/debug/stack_trace.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h"
16 #include "base/stl_util.h" 18 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
19 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
20 #include "base/synchronization/lock.h" 22 #include "base/synchronization/lock.h"
21 #include "base/test/simple_test_tick_clock.h" 23 #include "base/test/simple_test_tick_clock.h"
22 #include "media/base/data_buffer.h" 24 #include "media/base/data_buffer.h"
23 #include "media/base/gmock_callback_support.h" 25 #include "media/base/gmock_callback_support.h"
24 #include "media/base/limits.h" 26 #include "media/base/limits.h"
25 #include "media/base/mock_filters.h" 27 #include "media/base/mock_filters.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 base::Unretained(&time_source_)), 127 base::Unretained(&time_source_)),
126 status_cb); 128 status_cb);
127 } 129 }
128 130
129 void StartPlayingFrom(int milliseconds) { 131 void StartPlayingFrom(int milliseconds) {
130 SCOPED_TRACE(base::StringPrintf("StartPlayingFrom(%d)", milliseconds)); 132 SCOPED_TRACE(base::StringPrintf("StartPlayingFrom(%d)", milliseconds));
131 const base::TimeDelta media_time = 133 const base::TimeDelta media_time =
132 base::TimeDelta::FromMilliseconds(milliseconds); 134 base::TimeDelta::FromMilliseconds(milliseconds);
133 time_source_.SetMediaTime(media_time); 135 time_source_.SetMediaTime(media_time);
134 renderer_->StartPlayingFrom(media_time); 136 renderer_->StartPlayingFrom(media_time);
135 message_loop_.RunUntilIdle(); 137 base::RunLoop().RunUntilIdle();
136 } 138 }
137 139
138 void Flush() { 140 void Flush() {
139 SCOPED_TRACE("Flush()"); 141 SCOPED_TRACE("Flush()");
140 WaitableMessageLoopEvent event; 142 WaitableMessageLoopEvent event;
141 renderer_->Flush(event.GetClosure()); 143 renderer_->Flush(event.GetClosure());
142 event.RunAndWait(); 144 event.RunAndWait();
143 } 145 }
144 146
145 void Destroy() { 147 void Destroy() {
146 SCOPED_TRACE("Destroy()"); 148 SCOPED_TRACE("Destroy()");
147 renderer_.reset(); 149 renderer_.reset();
148 message_loop_.RunUntilIdle(); 150 base::RunLoop().RunUntilIdle();
149 } 151 }
150 152
151 // Parses a string representation of video frames and generates corresponding 153 // Parses a string representation of video frames and generates corresponding
152 // VideoFrame objects in |decode_results_|. 154 // VideoFrame objects in |decode_results_|.
153 // 155 //
154 // Syntax: 156 // Syntax:
155 // nn - Queue a decoder buffer with timestamp nn * 1000us 157 // nn - Queue a decoder buffer with timestamp nn * 1000us
156 // abort - Queue an aborted read 158 // abort - Queue an aborted read
157 // error - Queue a decoder error 159 // error - Queue a decoder error
158 // 160 //
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 DCHECK(wait_for_pending_decode_cb_.is_null()); 233 DCHECK(wait_for_pending_decode_cb_.is_null());
232 } 234 }
233 235
234 void SatisfyPendingDecode() { 236 void SatisfyPendingDecode() {
235 CHECK(!decode_cb_.is_null()); 237 CHECK(!decode_cb_.is_null());
236 CHECK(!decode_results_.empty()); 238 CHECK(!decode_results_.empty());
237 239
238 // Post tasks for OutputCB and DecodeCB. 240 // Post tasks for OutputCB and DecodeCB.
239 scoped_refptr<VideoFrame> frame = decode_results_.front().second; 241 scoped_refptr<VideoFrame> frame = decode_results_.front().second;
240 if (frame.get()) 242 if (frame.get())
241 message_loop_.PostTask(FROM_HERE, base::Bind(output_cb_, frame)); 243 message_loop_.task_runner()->PostTask(FROM_HERE,
242 message_loop_.PostTask( 244 base::Bind(output_cb_, frame));
245 message_loop_.task_runner()->PostTask(
243 FROM_HERE, base::Bind(base::ResetAndReturn(&decode_cb_), 246 FROM_HERE, base::Bind(base::ResetAndReturn(&decode_cb_),
244 decode_results_.front().first)); 247 decode_results_.front().first));
245 decode_results_.pop_front(); 248 decode_results_.pop_front();
246 } 249 }
247 250
248 void SatisfyPendingDecodeWithEndOfStream() { 251 void SatisfyPendingDecodeWithEndOfStream() {
249 DCHECK(!decode_cb_.is_null()); 252 DCHECK(!decode_cb_.is_null());
250 253
251 // Return EOS buffer to trigger EOS frame. 254 // Return EOS buffer to trigger EOS frame.
252 EXPECT_CALL(demuxer_stream_, Read(_)) 255 EXPECT_CALL(demuxer_stream_, Read(_))
253 .WillOnce(RunCallback<0>(DemuxerStream::kOk, 256 .WillOnce(RunCallback<0>(DemuxerStream::kOk,
254 DecoderBuffer::CreateEOSBuffer())); 257 DecoderBuffer::CreateEOSBuffer()));
255 258
256 // Satify pending |decode_cb_| to trigger a new DemuxerStream::Read(). 259 // Satify pending |decode_cb_| to trigger a new DemuxerStream::Read().
257 message_loop_.PostTask( 260 message_loop_.task_runner()->PostTask(
258 FROM_HERE, 261 FROM_HERE,
259 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK)); 262 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK));
260 263
261 WaitForPendingDecode(); 264 WaitForPendingDecode();
262 265
263 message_loop_.PostTask( 266 message_loop_.task_runner()->PostTask(
264 FROM_HERE, 267 FROM_HERE,
265 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK)); 268 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK));
266 } 269 }
267 270
268 void AdvanceWallclockTimeInMs(int time_ms) { 271 void AdvanceWallclockTimeInMs(int time_ms) {
269 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); 272 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
270 base::AutoLock l(lock_); 273 base::AutoLock l(lock_);
271 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(time_ms)); 274 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(time_ms));
272 } 275 }
273 276
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 } 463 }
461 464
462 void FlushRequested(const base::Closure& callback) { 465 void FlushRequested(const base::Closure& callback) {
463 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); 466 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
464 decode_results_.clear(); 467 decode_results_.clear();
465 if (!decode_cb_.is_null()) { 468 if (!decode_cb_.is_null()) {
466 QueueFrames("abort"); 469 QueueFrames("abort");
467 SatisfyPendingDecode(); 470 SatisfyPendingDecode();
468 } 471 }
469 472
470 message_loop_.PostTask(FROM_HERE, callback); 473 message_loop_.task_runner()->PostTask(FROM_HERE, callback);
471 } 474 }
472 475
473 // Used to protect |time_|. 476 // Used to protect |time_|.
474 base::Lock lock_; 477 base::Lock lock_;
475 base::TimeDelta time_; 478 base::TimeDelta time_;
476 479
477 // Used for satisfying reads. 480 // Used for satisfying reads.
478 VideoDecoder::OutputCB output_cb_; 481 VideoDecoder::OutputCB output_cb_;
479 VideoDecoder::DecodeCB decode_cb_; 482 VideoDecoder::DecodeCB decode_cb_;
480 base::TimeDelta next_frame_timestamp_; 483 base::TimeDelta next_frame_timestamp_;
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 1120 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
1118 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 1121 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
1119 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 1122 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
1120 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 1123 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
1121 StartPlayingFrom(0); 1124 StartPlayingFrom(0);
1122 ASSERT_EQ(1u, frame_ready_cbs_.size()); 1125 ASSERT_EQ(1u, frame_ready_cbs_.size());
1123 1126
1124 uint32_t frame_ready_index = 0; 1127 uint32_t frame_ready_index = 0;
1125 while (frame_ready_index < frame_ready_cbs_.size()) { 1128 while (frame_ready_index < frame_ready_cbs_.size()) {
1126 frame_ready_cbs_[frame_ready_index++].Run(); 1129 frame_ready_cbs_[frame_ready_index++].Run();
1127 message_loop_.RunUntilIdle(); 1130 base::RunLoop().RunUntilIdle();
1128 } 1131 }
1129 Destroy(); 1132 Destroy();
1130 } 1133 }
1131 1134
1132 TEST_F(VideoRendererImplAsyncAddFrameReadyTest, WeakFactoryDiscardsOneFrame) { 1135 TEST_F(VideoRendererImplAsyncAddFrameReadyTest, WeakFactoryDiscardsOneFrame) {
1133 Initialize(); 1136 Initialize();
1134 QueueFrames("0 10 20 30"); 1137 QueueFrames("0 10 20 30");
1135 StartPlayingFrom(0); 1138 StartPlayingFrom(0);
1136 Flush(); 1139 Flush();
1137 ASSERT_EQ(1u, frame_ready_cbs_.size()); 1140 ASSERT_EQ(1u, frame_ready_cbs_.size());
1138 // This frame will be discarded. 1141 // This frame will be discarded.
1139 frame_ready_cbs_.front().Run(); 1142 frame_ready_cbs_.front().Run();
1140 Destroy(); 1143 Destroy();
1141 } 1144 }
1142 1145
1143 } // namespace media 1146 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/audio_renderer_impl_unittest.cc ('k') | media/test/pipeline_integration_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698