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

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

Issue 65803002: Replace MessageLoopProxy with SingleThreadTaskRunner for media/filters/ + associated code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "media/filters/fake_demuxer_stream.h" 5 #include "media/filters/fake_demuxer_stream.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop_proxy.h"
12 #include "media/base/bind_to_loop.h" 12 #include "media/base/bind_to_loop.h"
13 #include "media/base/decoder_buffer.h" 13 #include "media/base/decoder_buffer.h"
14 #include "media/base/test_helpers.h" 14 #include "media/base/test_helpers.h"
15 #include "media/base/video_frame.h" 15 #include "media/base/video_frame.h"
16 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/size.h" 17 #include "ui/gfx/size.h"
18 18
19 namespace media { 19 namespace media {
20 20
21 static const int kStartTimestampMs = 0; 21 static const int kStartTimestampMs = 0;
22 static const int kDurationMs = 30; 22 static const int kDurationMs = 30;
23 static const int kStartWidth = 320; 23 static const int kStartWidth = 320;
24 static const int kStartHeight = 240; 24 static const int kStartHeight = 240;
25 static const int kWidthDelta = 4; 25 static const int kWidthDelta = 4;
26 static const int kHeightDelta = 3; 26 static const int kHeightDelta = 3;
27 27
28 FakeDemuxerStream::FakeDemuxerStream(int num_configs, 28 FakeDemuxerStream::FakeDemuxerStream(int num_configs,
29 int num_buffers_in_one_config, 29 int num_buffers_in_one_config,
30 bool is_encrypted) 30 bool is_encrypted)
31 : message_loop_(base::MessageLoopProxy::current()), 31 : task_runner_(base::MessageLoopProxy::current()),
32 num_configs_left_(num_configs), 32 num_configs_left_(num_configs),
33 num_buffers_in_one_config_(num_buffers_in_one_config), 33 num_buffers_in_one_config_(num_buffers_in_one_config),
34 is_encrypted_(is_encrypted), 34 is_encrypted_(is_encrypted),
35 num_buffers_left_in_current_config_(num_buffers_in_one_config), 35 num_buffers_left_in_current_config_(num_buffers_in_one_config),
36 num_buffers_returned_(0), 36 num_buffers_returned_(0),
37 current_timestamp_(base::TimeDelta::FromMilliseconds(kStartTimestampMs)), 37 current_timestamp_(base::TimeDelta::FromMilliseconds(kStartTimestampMs)),
38 duration_(base::TimeDelta::FromMilliseconds(kDurationMs)), 38 duration_(base::TimeDelta::FromMilliseconds(kDurationMs)),
39 next_coded_size_(kStartWidth, kStartHeight), 39 next_coded_size_(kStartWidth, kStartHeight),
40 next_read_num_(0), 40 next_read_num_(0),
41 read_to_hold_(-1) { 41 read_to_hold_(-1) {
42 DCHECK_GT(num_configs_left_, 0); 42 DCHECK_GT(num_configs_left_, 0);
43 DCHECK_GT(num_buffers_in_one_config_, 0); 43 DCHECK_GT(num_buffers_in_one_config_, 0);
44 UpdateVideoDecoderConfig(); 44 UpdateVideoDecoderConfig();
45 } 45 }
46 46
47 FakeDemuxerStream::~FakeDemuxerStream() {} 47 FakeDemuxerStream::~FakeDemuxerStream() {}
48 48
49 void FakeDemuxerStream::Read(const ReadCB& read_cb) { 49 void FakeDemuxerStream::Read(const ReadCB& read_cb) {
50 DCHECK(message_loop_->BelongsToCurrentThread()); 50 DCHECK(task_runner_->BelongsToCurrentThread());
51 DCHECK(read_cb_.is_null()); 51 DCHECK(read_cb_.is_null());
52 52
53 read_cb_ = BindToCurrentLoop(read_cb); 53 read_cb_ = BindToCurrentLoop(read_cb);
54 54
55 if (read_to_hold_ == next_read_num_) 55 if (read_to_hold_ == next_read_num_)
56 return; 56 return;
57 57
58 DCHECK(read_to_hold_ == -1 || read_to_hold_ > next_read_num_); 58 DCHECK(read_to_hold_ == -1 || read_to_hold_ > next_read_num_);
59 DoRead(); 59 DoRead();
60 } 60 }
61 61
62 AudioDecoderConfig FakeDemuxerStream::audio_decoder_config() { 62 AudioDecoderConfig FakeDemuxerStream::audio_decoder_config() {
63 DCHECK(message_loop_->BelongsToCurrentThread()); 63 DCHECK(task_runner_->BelongsToCurrentThread());
64 NOTREACHED(); 64 NOTREACHED();
65 return AudioDecoderConfig(); 65 return AudioDecoderConfig();
66 } 66 }
67 67
68 VideoDecoderConfig FakeDemuxerStream::video_decoder_config() { 68 VideoDecoderConfig FakeDemuxerStream::video_decoder_config() {
69 DCHECK(message_loop_->BelongsToCurrentThread()); 69 DCHECK(task_runner_->BelongsToCurrentThread());
70 return video_decoder_config_; 70 return video_decoder_config_;
71 } 71 }
72 72
73 // TODO(xhwang): Support audio if needed. 73 // TODO(xhwang): Support audio if needed.
74 DemuxerStream::Type FakeDemuxerStream::type() { 74 DemuxerStream::Type FakeDemuxerStream::type() {
75 DCHECK(message_loop_->BelongsToCurrentThread()); 75 DCHECK(task_runner_->BelongsToCurrentThread());
76 return VIDEO; 76 return VIDEO;
77 } 77 }
78 78
79 void FakeDemuxerStream::EnableBitstreamConverter() { 79 void FakeDemuxerStream::EnableBitstreamConverter() {
80 DCHECK(message_loop_->BelongsToCurrentThread()); 80 DCHECK(task_runner_->BelongsToCurrentThread());
81 } 81 }
82 82
83 void FakeDemuxerStream::HoldNextRead() { 83 void FakeDemuxerStream::HoldNextRead() {
84 DCHECK(message_loop_->BelongsToCurrentThread()); 84 DCHECK(task_runner_->BelongsToCurrentThread());
85 read_to_hold_ = next_read_num_; 85 read_to_hold_ = next_read_num_;
86 } 86 }
87 87
88 void FakeDemuxerStream::HoldNextConfigChangeRead() { 88 void FakeDemuxerStream::HoldNextConfigChangeRead() {
89 DCHECK(message_loop_->BelongsToCurrentThread()); 89 DCHECK(task_runner_->BelongsToCurrentThread());
90 // Set |read_to_hold_| to be the next config change read. 90 // Set |read_to_hold_| to be the next config change read.
91 read_to_hold_ = next_read_num_ + num_buffers_in_one_config_ - 91 read_to_hold_ = next_read_num_ + num_buffers_in_one_config_ -
92 next_read_num_ % (num_buffers_in_one_config_ + 1); 92 next_read_num_ % (num_buffers_in_one_config_ + 1);
93 } 93 }
94 94
95 void FakeDemuxerStream::SatisfyRead() { 95 void FakeDemuxerStream::SatisfyRead() {
96 DCHECK(message_loop_->BelongsToCurrentThread()); 96 DCHECK(task_runner_->BelongsToCurrentThread());
97 DCHECK_EQ(read_to_hold_, next_read_num_); 97 DCHECK_EQ(read_to_hold_, next_read_num_);
98 DCHECK(!read_cb_.is_null()); 98 DCHECK(!read_cb_.is_null());
99 99
100 read_to_hold_ = -1; 100 read_to_hold_ = -1;
101 DoRead(); 101 DoRead();
102 } 102 }
103 103
104 void FakeDemuxerStream::Reset() { 104 void FakeDemuxerStream::Reset() {
105 read_to_hold_ = -1; 105 read_to_hold_ = -1;
106 106
107 if (!read_cb_.is_null()) 107 if (!read_cb_.is_null())
108 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); 108 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL);
109 } 109 }
110 110
111 void FakeDemuxerStream::UpdateVideoDecoderConfig() { 111 void FakeDemuxerStream::UpdateVideoDecoderConfig() {
112 const gfx::Rect kVisibleRect(kStartWidth, kStartHeight); 112 const gfx::Rect kVisibleRect(kStartWidth, kStartHeight);
113 video_decoder_config_.Initialize( 113 video_decoder_config_.Initialize(
114 kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, VideoFrame::YV12, 114 kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, VideoFrame::YV12,
115 next_coded_size_, kVisibleRect, next_coded_size_, 115 next_coded_size_, kVisibleRect, next_coded_size_,
116 NULL, 0, is_encrypted_, false); 116 NULL, 0, is_encrypted_, false);
117 next_coded_size_.Enlarge(kWidthDelta, kHeightDelta); 117 next_coded_size_.Enlarge(kWidthDelta, kHeightDelta);
118 } 118 }
119 119
120 void FakeDemuxerStream::DoRead() { 120 void FakeDemuxerStream::DoRead() {
121 DCHECK(message_loop_->BelongsToCurrentThread()); 121 DCHECK(task_runner_->BelongsToCurrentThread());
122 DCHECK(!read_cb_.is_null()); 122 DCHECK(!read_cb_.is_null());
123 123
124 next_read_num_++; 124 next_read_num_++;
125 125
126 if (num_buffers_left_in_current_config_ == 0) { 126 if (num_buffers_left_in_current_config_ == 0) {
127 // End of stream. 127 // End of stream.
128 if (num_configs_left_ == 0) { 128 if (num_configs_left_ == 0) {
129 base::ResetAndReturn(&read_cb_).Run(kOk, 129 base::ResetAndReturn(&read_cb_).Run(kOk,
130 DecoderBuffer::CreateEOSBuffer()); 130 DecoderBuffer::CreateEOSBuffer());
131 return; 131 return;
(...skipping 16 matching lines...) Expand all
148 148
149 num_buffers_left_in_current_config_--; 149 num_buffers_left_in_current_config_--;
150 if (num_buffers_left_in_current_config_ == 0) 150 if (num_buffers_left_in_current_config_ == 0)
151 num_configs_left_--; 151 num_configs_left_--;
152 152
153 num_buffers_returned_++; 153 num_buffers_returned_++;
154 base::ResetAndReturn(&read_cb_).Run(kOk, buffer); 154 base::ResetAndReturn(&read_cb_).Run(kOk, buffer);
155 } 155 }
156 156
157 } // namespace media 157 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698