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

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

Issue 2710133003: Replace FFmpegDemuxer thread per element with base::TaskScheduler. (Closed)
Patch Set: Comments. Fix flaky test. Created 3 years, 9 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 (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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <deque> 9 #include <deque>
10 #include <string> 10 #include <string>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/test/mock_callback.h" 20 #include "base/test/mock_callback.h"
21 #include "base/test/scoped_task_scheduler.h"
21 #include "base/threading/thread.h" 22 #include "base/threading/thread.h"
22 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
23 #include "media/base/decrypt_config.h" 24 #include "media/base/decrypt_config.h"
24 #include "media/base/media_log.h" 25 #include "media/base/media_log.h"
25 #include "media/base/media_tracks.h" 26 #include "media/base/media_tracks.h"
26 #include "media/base/mock_demuxer_host.h" 27 #include "media/base/mock_demuxer_host.h"
27 #include "media/base/test_helpers.h" 28 #include "media/base/test_helpers.h"
28 #include "media/base/timestamp_constants.h" 29 #include "media/base/timestamp_constants.h"
29 #include "media/ffmpeg/ffmpeg_common.h" 30 #include "media/ffmpeg/ffmpeg_common.h"
30 #include "media/filters/ffmpeg_demuxer.h" 31 #include "media/filters/ffmpeg_demuxer.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 EXPECT_TRUE(buffer->data()); 74 EXPECT_TRUE(buffer->data());
74 EXPECT_GT(buffer->data_size(), 0u); 75 EXPECT_GT(buffer->data_size(), 0u);
75 *got_eos_buffer = false; 76 *got_eos_buffer = false;
76 }; 77 };
77 78
78 79
79 // Fixture class to facilitate writing tests. Takes care of setting up the 80 // Fixture class to facilitate writing tests. Takes care of setting up the
80 // FFmpeg, pipeline and filter host mocks. 81 // FFmpeg, pipeline and filter host mocks.
81 class FFmpegDemuxerTest : public testing::Test { 82 class FFmpegDemuxerTest : public testing::Test {
82 protected: 83 protected:
83 FFmpegDemuxerTest() {} 84 FFmpegDemuxerTest() : task_scheduler_(&message_loop_) {}
84 85
85 virtual ~FFmpegDemuxerTest() { 86 virtual ~FFmpegDemuxerTest() {
86 if (demuxer_) 87 if (demuxer_)
87 demuxer_->Stop(); 88 demuxer_->Stop();
88 } 89 }
89 90
90 void CreateDemuxer(const std::string& name) { 91 void CreateDemuxer(const std::string& name) {
91 CHECK(!demuxer_); 92 CHECK(!demuxer_);
92 93
93 EXPECT_CALL(host_, OnBufferedTimeRangesChanged(_)).Times(AnyNumber()); 94 EXPECT_CALL(host_, OnBufferedTimeRangesChanged(_)).Times(AnyNumber());
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 233 }
233 234
234 // Accessor to demuxer internals. 235 // Accessor to demuxer internals.
235 void SetDurationKnown(bool duration_known) { 236 void SetDurationKnown(bool duration_known) {
236 demuxer_->duration_known_ = duration_known; 237 demuxer_->duration_known_ = duration_known;
237 if (!duration_known) 238 if (!duration_known)
238 demuxer_->duration_ = kInfiniteDuration; 239 demuxer_->duration_ = kInfiniteDuration;
239 } 240 }
240 241
241 // Fixture members. 242 // Fixture members.
243
244 base::MessageLoop message_loop_;
gab 2017/02/24 01:09:05 Drop this member (ScopedTaskScheduler will provide
DaleCurtis 2017/02/24 23:40:29 Done.
245 base::test::ScopedTaskScheduler task_scheduler_;
242 std::unique_ptr<FileDataSource> data_source_; 246 std::unique_ptr<FileDataSource> data_source_;
243 std::unique_ptr<FFmpegDemuxer> demuxer_; 247 std::unique_ptr<FFmpegDemuxer> demuxer_;
244 StrictMock<MockDemuxerHost> host_; 248 StrictMock<MockDemuxerHost> host_;
245 std::unique_ptr<MediaTracks> media_tracks_; 249 std::unique_ptr<MediaTracks> media_tracks_;
246 base::MessageLoop message_loop_;
247 250
248 AVFormatContext* format_context() { 251 AVFormatContext* format_context() {
249 return demuxer_->glue_->format_context(); 252 return demuxer_->glue_->format_context();
250 } 253 }
251 254
252 DemuxerStream* preferred_seeking_stream(base::TimeDelta seek_time) const { 255 DemuxerStream* preferred_seeking_stream(base::TimeDelta seek_time) const {
253 return demuxer_->FindPreferredStreamForSeeking(seek_time); 256 return demuxer_->FindPreferredStreamForSeeking(seek_time);
254 } 257 }
255 258
256 void ReadUntilEndOfStream(DemuxerStream* stream) { 259 void ReadUntilEndOfStream(DemuxerStream* stream) {
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); 1518 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta()));
1516 1519
1517 // Now pretend that audio stream got disabled. 1520 // Now pretend that audio stream got disabled.
1518 astream->set_enabled(false, base::TimeDelta()); 1521 astream->set_enabled(false, base::TimeDelta());
1519 // Since there's no other enabled streams, the preferred seeking stream should 1522 // Since there's no other enabled streams, the preferred seeking stream should
1520 // still be the audio stream. 1523 // still be the audio stream.
1521 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); 1524 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta()));
1522 } 1525 }
1523 1526
1524 } // namespace media 1527 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698