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

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

Issue 2710133003: Replace FFmpegDemuxer thread per element with base::TaskScheduler. (Closed)
Patch Set: Fix chromecast build. 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 CreateDataSource(name); 96 CreateDataSource(name);
96 97
97 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind( 98 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind(
98 &FFmpegDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this)); 99 &FFmpegDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this));
99 100
100 Demuxer::MediaTracksUpdatedCB tracks_updated_cb = base::Bind( 101 Demuxer::MediaTracksUpdatedCB tracks_updated_cb = base::Bind(
101 &FFmpegDemuxerTest::OnMediaTracksUpdated, base::Unretained(this)); 102 &FFmpegDemuxerTest::OnMediaTracksUpdated, base::Unretained(this));
102 103
103 demuxer_.reset(new FFmpegDemuxer( 104 demuxer_.reset(new FFmpegDemuxer(
104 message_loop_.task_runner(), data_source_.get(), 105 base::ThreadTaskRunnerHandle::Get(), data_source_.get(),
105 encrypted_media_init_data_cb, tracks_updated_cb, new MediaLog())); 106 encrypted_media_init_data_cb, tracks_updated_cb, new MediaLog()));
106 } 107 }
107 108
108 DemuxerStream* GetStream(DemuxerStream::Type type) { 109 DemuxerStream* GetStream(DemuxerStream::Type type) {
109 std::vector<DemuxerStream*> streams = demuxer_->GetAllStreams(); 110 std::vector<DemuxerStream*> streams = demuxer_->GetAllStreams();
110 for (const auto& stream : streams) { 111 for (const auto& stream : streams) {
111 if (stream->type() == type) 112 if (stream->type() == type)
112 return stream; 113 return stream;
113 } 114 }
114 return nullptr; 115 return nullptr;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 EXPECT_EQ(read_expectation.status, status); 182 EXPECT_EQ(read_expectation.status, status);
182 if (status == DemuxerStream::kOk) { 183 if (status == DemuxerStream::kOk) {
183 EXPECT_TRUE(buffer); 184 EXPECT_TRUE(buffer);
184 EXPECT_EQ(read_expectation.size, buffer->data_size()); 185 EXPECT_EQ(read_expectation.size, buffer->data_size());
185 EXPECT_EQ(read_expectation.timestamp_us, 186 EXPECT_EQ(read_expectation.timestamp_us,
186 buffer->timestamp().InMicroseconds()); 187 buffer->timestamp().InMicroseconds());
187 EXPECT_EQ(read_expectation.discard_front_padding, 188 EXPECT_EQ(read_expectation.discard_front_padding,
188 buffer->discard_padding().first); 189 buffer->discard_padding().first);
189 EXPECT_EQ(read_expectation.is_key_frame, buffer->is_key_frame()); 190 EXPECT_EQ(read_expectation.is_key_frame, buffer->is_key_frame());
190 } 191 }
191 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
192 OnReadDoneCalled(read_expectation.size, read_expectation.timestamp_us); 192 OnReadDoneCalled(read_expectation.size, read_expectation.timestamp_us);
193 message_loop_.task_runner()->PostTask( 193 base::ThreadTaskRunnerHandle::Get()->PostTask(
194 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 194 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
195 } 195 }
196 196
197 DemuxerStream::ReadCB NewReadCB( 197 DemuxerStream::ReadCB NewReadCB(
198 const tracked_objects::Location& location, 198 const tracked_objects::Location& location,
199 int size, 199 int size,
200 int64_t timestamp_us, 200 int64_t timestamp_us,
201 bool is_key_frame, 201 bool is_key_frame,
202 DemuxerStream::Status status = DemuxerStream::kOk) { 202 DemuxerStream::Status status = DemuxerStream::kOk) {
203 return NewReadCBWithCheckedDiscard(location, size, timestamp_us, 203 return NewReadCBWithCheckedDiscard(location, size, timestamp_us,
(...skipping 28 matching lines...) Expand all
232 } 232 }
233 233
234 // Accessor to demuxer internals. 234 // Accessor to demuxer internals.
235 void SetDurationKnown(bool duration_known) { 235 void SetDurationKnown(bool duration_known) {
236 demuxer_->duration_known_ = duration_known; 236 demuxer_->duration_known_ = duration_known;
237 if (!duration_known) 237 if (!duration_known)
238 demuxer_->duration_ = kInfiniteDuration; 238 demuxer_->duration_ = kInfiniteDuration;
239 } 239 }
240 240
241 // Fixture members. 241 // Fixture members.
242
243 base::test::ScopedTaskScheduler task_scheduler_;
242 std::unique_ptr<FileDataSource> data_source_; 244 std::unique_ptr<FileDataSource> data_source_;
243 std::unique_ptr<FFmpegDemuxer> demuxer_; 245 std::unique_ptr<FFmpegDemuxer> demuxer_;
244 StrictMock<MockDemuxerHost> host_; 246 StrictMock<MockDemuxerHost> host_;
245 std::unique_ptr<MediaTracks> media_tracks_; 247 std::unique_ptr<MediaTracks> media_tracks_;
246 base::MessageLoop message_loop_;
247 248
248 AVFormatContext* format_context() { 249 AVFormatContext* format_context() {
249 return demuxer_->glue_->format_context(); 250 return demuxer_->glue_->format_context();
250 } 251 }
251 252
252 DemuxerStream* preferred_seeking_stream(base::TimeDelta seek_time) const { 253 DemuxerStream* preferred_seeking_stream(base::TimeDelta seek_time) const {
253 return demuxer_->FindPreferredStreamForSeeking(seek_time); 254 return demuxer_->FindPreferredStreamForSeeking(seek_time);
254 } 255 }
255 256
256 void ReadUntilEndOfStream(DemuxerStream* stream) { 257 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())); 1516 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta()));
1516 1517
1517 // Now pretend that audio stream got disabled. 1518 // Now pretend that audio stream got disabled.
1518 astream->set_enabled(false, base::TimeDelta()); 1519 astream->set_enabled(false, base::TimeDelta());
1519 // Since there's no other enabled streams, the preferred seeking stream should 1520 // Since there's no other enabled streams, the preferred seeking stream should
1520 // still be the audio stream. 1521 // still be the audio stream.
1521 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); 1522 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta()));
1522 } 1523 }
1523 1524
1524 } // namespace media 1525 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698