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

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

Issue 2719883005: Revert of Replace FFmpegDemuxer thread per element with base::TaskScheduler. (Closed)
Patch Set: 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
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | media/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
22 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
23 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
24 #include "media/base/decrypt_config.h" 23 #include "media/base/decrypt_config.h"
25 #include "media/base/media_log.h" 24 #include "media/base/media_log.h"
26 #include "media/base/media_tracks.h" 25 #include "media/base/media_tracks.h"
27 #include "media/base/mock_demuxer_host.h" 26 #include "media/base/mock_demuxer_host.h"
28 #include "media/base/test_helpers.h" 27 #include "media/base/test_helpers.h"
29 #include "media/base/timestamp_constants.h" 28 #include "media/base/timestamp_constants.h"
30 #include "media/ffmpeg/ffmpeg_common.h" 29 #include "media/ffmpeg/ffmpeg_common.h"
31 #include "media/filters/ffmpeg_demuxer.h" 30 #include "media/filters/ffmpeg_demuxer.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 78
80 // Fixture class to facilitate writing tests. Takes care of setting up the 79 // Fixture class to facilitate writing tests. Takes care of setting up the
81 // FFmpeg, pipeline and filter host mocks. 80 // FFmpeg, pipeline and filter host mocks.
82 class FFmpegDemuxerTest : public testing::Test { 81 class FFmpegDemuxerTest : public testing::Test {
83 protected: 82 protected:
84 FFmpegDemuxerTest() {} 83 FFmpegDemuxerTest() {}
85 84
86 virtual ~FFmpegDemuxerTest() { 85 virtual ~FFmpegDemuxerTest() {
87 if (demuxer_) 86 if (demuxer_)
88 demuxer_->Stop(); 87 demuxer_->Stop();
89 demuxer_.reset();
90 base::RunLoop().RunUntilIdle();
91 } 88 }
92 89
93 void CreateDemuxer(const std::string& name) { 90 void CreateDemuxer(const std::string& name) {
94 CHECK(!demuxer_); 91 CHECK(!demuxer_);
95 92
96 EXPECT_CALL(host_, OnBufferedTimeRangesChanged(_)).Times(AnyNumber()); 93 EXPECT_CALL(host_, OnBufferedTimeRangesChanged(_)).Times(AnyNumber());
97 94
98 CreateDataSource(name); 95 CreateDataSource(name);
99 96
100 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind( 97 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind(
101 &FFmpegDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this)); 98 &FFmpegDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this));
102 99
103 Demuxer::MediaTracksUpdatedCB tracks_updated_cb = base::Bind( 100 Demuxer::MediaTracksUpdatedCB tracks_updated_cb = base::Bind(
104 &FFmpegDemuxerTest::OnMediaTracksUpdated, base::Unretained(this)); 101 &FFmpegDemuxerTest::OnMediaTracksUpdated, base::Unretained(this));
105 102
106 demuxer_.reset(new FFmpegDemuxer( 103 demuxer_.reset(new FFmpegDemuxer(
107 base::ThreadTaskRunnerHandle::Get(), data_source_.get(), 104 message_loop_.task_runner(), data_source_.get(),
108 encrypted_media_init_data_cb, tracks_updated_cb, new MediaLog())); 105 encrypted_media_init_data_cb, tracks_updated_cb, new MediaLog()));
109 } 106 }
110 107
111 DemuxerStream* GetStream(DemuxerStream::Type type) { 108 DemuxerStream* GetStream(DemuxerStream::Type type) {
112 std::vector<DemuxerStream*> streams = demuxer_->GetAllStreams(); 109 std::vector<DemuxerStream*> streams = demuxer_->GetAllStreams();
113 for (auto* stream : streams) { 110 for (auto* stream : streams) {
114 if (stream->type() == type) 111 if (stream->type() == type)
115 return stream; 112 return stream;
116 } 113 }
117 return nullptr; 114 return nullptr;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 EXPECT_EQ(read_expectation.status, status); 181 EXPECT_EQ(read_expectation.status, status);
185 if (status == DemuxerStream::kOk) { 182 if (status == DemuxerStream::kOk) {
186 EXPECT_TRUE(buffer); 183 EXPECT_TRUE(buffer);
187 EXPECT_EQ(read_expectation.size, buffer->data_size()); 184 EXPECT_EQ(read_expectation.size, buffer->data_size());
188 EXPECT_EQ(read_expectation.timestamp_us, 185 EXPECT_EQ(read_expectation.timestamp_us,
189 buffer->timestamp().InMicroseconds()); 186 buffer->timestamp().InMicroseconds());
190 EXPECT_EQ(read_expectation.discard_front_padding, 187 EXPECT_EQ(read_expectation.discard_front_padding,
191 buffer->discard_padding().first); 188 buffer->discard_padding().first);
192 EXPECT_EQ(read_expectation.is_key_frame, buffer->is_key_frame()); 189 EXPECT_EQ(read_expectation.is_key_frame, buffer->is_key_frame());
193 } 190 }
191 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
194 OnReadDoneCalled(read_expectation.size, read_expectation.timestamp_us); 192 OnReadDoneCalled(read_expectation.size, read_expectation.timestamp_us);
195 base::ThreadTaskRunnerHandle::Get()->PostTask( 193 message_loop_.task_runner()->PostTask(
196 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 194 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
197 } 195 }
198 196
199 DemuxerStream::ReadCB NewReadCB( 197 DemuxerStream::ReadCB NewReadCB(
200 const tracked_objects::Location& location, 198 const tracked_objects::Location& location,
201 int size, 199 int size,
202 int64_t timestamp_us, 200 int64_t timestamp_us,
203 bool is_key_frame, 201 bool is_key_frame,
204 DemuxerStream::Status status = DemuxerStream::kOk) { 202 DemuxerStream::Status status = DemuxerStream::kOk) {
205 return NewReadCBWithCheckedDiscard(location, size, timestamp_us, 203 return NewReadCBWithCheckedDiscard(location, size, timestamp_us,
(...skipping 28 matching lines...) Expand all
234 } 232 }
235 233
236 // Accessor to demuxer internals. 234 // Accessor to demuxer internals.
237 void SetDurationKnown(bool duration_known) { 235 void SetDurationKnown(bool duration_known) {
238 demuxer_->duration_known_ = duration_known; 236 demuxer_->duration_known_ = duration_known;
239 if (!duration_known) 237 if (!duration_known)
240 demuxer_->duration_ = kInfiniteDuration; 238 demuxer_->duration_ = kInfiniteDuration;
241 } 239 }
242 240
243 // Fixture members. 241 // Fixture members.
244
245 base::test::ScopedTaskScheduler task_scheduler_;
246 std::unique_ptr<FileDataSource> data_source_; 242 std::unique_ptr<FileDataSource> data_source_;
247 std::unique_ptr<FFmpegDemuxer> demuxer_; 243 std::unique_ptr<FFmpegDemuxer> demuxer_;
248 StrictMock<MockDemuxerHost> host_; 244 StrictMock<MockDemuxerHost> host_;
249 std::unique_ptr<MediaTracks> media_tracks_; 245 std::unique_ptr<MediaTracks> media_tracks_;
246 base::MessageLoop message_loop_;
250 247
251 AVFormatContext* format_context() { 248 AVFormatContext* format_context() {
252 return demuxer_->glue_->format_context(); 249 return demuxer_->glue_->format_context();
253 } 250 }
254 251
255 DemuxerStream* preferred_seeking_stream(base::TimeDelta seek_time) const { 252 DemuxerStream* preferred_seeking_stream(base::TimeDelta seek_time) const {
256 return demuxer_->FindPreferredStreamForSeeking(seek_time); 253 return demuxer_->FindPreferredStreamForSeeking(seek_time);
257 } 254 }
258 255
259 void ReadUntilEndOfStream(DemuxerStream* stream) { 256 void ReadUntilEndOfStream(DemuxerStream* stream) {
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); 1515 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta()));
1519 1516
1520 // Now pretend that audio stream got disabled. 1517 // Now pretend that audio stream got disabled.
1521 astream->set_enabled(false, base::TimeDelta()); 1518 astream->set_enabled(false, base::TimeDelta());
1522 // Since there's no other enabled streams, the preferred seeking stream should 1519 // Since there's no other enabled streams, the preferred seeking stream should
1523 // still be the audio stream. 1520 // still be the audio stream.
1524 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); 1521 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta()));
1525 } 1522 }
1526 1523
1527 } // namespace media 1524 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | media/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698