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

Side by Side Diff: media/mojo/common/mojo_decoder_buffer_converter.cc

Issue 2725133002: Mojo: Armed Watchers (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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/mojo/common/mojo_decoder_buffer_converter.h" 5 #include "media/mojo/common/mojo_decoder_buffer_converter.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 DVLOG(1) << __func__; 57 DVLOG(1) << __func__;
58 std::unique_ptr<mojo::DataPipe> data_pipe = CreateDataPipe(type); 58 std::unique_ptr<mojo::DataPipe> data_pipe = CreateDataPipe(type);
59 *producer_handle = std::move(data_pipe->producer_handle); 59 *producer_handle = std::move(data_pipe->producer_handle);
60 return base::WrapUnique( 60 return base::WrapUnique(
61 new MojoDecoderBufferReader(std::move(data_pipe->consumer_handle))); 61 new MojoDecoderBufferReader(std::move(data_pipe->consumer_handle)));
62 } 62 }
63 63
64 MojoDecoderBufferReader::MojoDecoderBufferReader( 64 MojoDecoderBufferReader::MojoDecoderBufferReader(
65 mojo::ScopedDataPipeConsumerHandle consumer_handle) 65 mojo::ScopedDataPipeConsumerHandle consumer_handle)
66 : consumer_handle_(std::move(consumer_handle)), 66 : consumer_handle_(std::move(consumer_handle)),
67 pipe_watcher_(FROM_HERE), 67 pipe_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL),
68 bytes_read_(0) { 68 bytes_read_(0) {
69 DVLOG(1) << __func__; 69 DVLOG(1) << __func__;
70 70
71 MojoResult result = 71 MojoResult result =
72 pipe_watcher_.Start(consumer_handle_.get(), MOJO_HANDLE_SIGNAL_READABLE, 72 pipe_watcher_.Watch(consumer_handle_.get(), MOJO_HANDLE_SIGNAL_READABLE,
73 base::Bind(&MojoDecoderBufferReader::OnPipeReadable, 73 base::Bind(&MojoDecoderBufferReader::OnPipeReadable,
74 base::Unretained(this))); 74 base::Unretained(this)));
75 if (result != MOJO_RESULT_OK) { 75 if (result != MOJO_RESULT_OK) {
76 DVLOG(1) << __func__ 76 DVLOG(1) << __func__
77 << ": Failed to start watching the pipe. result=" << result; 77 << ": Failed to start watching the pipe. result=" << result;
78 consumer_handle_.reset(); 78 consumer_handle_.reset();
79 } else {
80 pipe_watcher_.ArmOrNotify();
79 } 81 }
80 } 82 }
81 83
82 MojoDecoderBufferReader::~MojoDecoderBufferReader() { 84 MojoDecoderBufferReader::~MojoDecoderBufferReader() {
83 DVLOG(1) << __func__; 85 DVLOG(1) << __func__;
84 } 86 }
85 87
86 void MojoDecoderBufferReader::ReadDecoderBuffer( 88 void MojoDecoderBufferReader::ReadDecoderBuffer(
87 mojom::DecoderBufferPtr mojo_buffer, 89 mojom::DecoderBufferPtr mojo_buffer,
88 ReadCB read_cb) { 90 ReadCB read_cb) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 154
153 uint32_t num_bytes = buffer_size - bytes_read_; 155 uint32_t num_bytes = buffer_size - bytes_read_;
154 DCHECK_GT(num_bytes, 0u); 156 DCHECK_GT(num_bytes, 0u);
155 157
156 MojoResult result = ReadDataRaw(consumer_handle_.get(), 158 MojoResult result = ReadDataRaw(consumer_handle_.get(),
157 media_buffer_->writable_data() + bytes_read_, 159 media_buffer_->writable_data() + bytes_read_,
158 &num_bytes, MOJO_WRITE_DATA_FLAG_NONE); 160 &num_bytes, MOJO_WRITE_DATA_FLAG_NONE);
159 161
160 if (IsPipeReadWriteError(result)) { 162 if (IsPipeReadWriteError(result)) {
161 OnPipeError(result); 163 OnPipeError(result);
162 } else if (result == MOJO_RESULT_OK) { 164 } else {
163 DCHECK_GT(num_bytes, 0u); 165 pipe_watcher_.ArmOrNotify();
164 bytes_read_ += num_bytes; 166 if (result == MOJO_RESULT_OK) {
165 if (bytes_read_ == buffer_size) { 167 DCHECK_GT(num_bytes, 0u);
166 DCHECK(read_cb_); 168 bytes_read_ += num_bytes;
167 bytes_read_ = 0; 169 if (bytes_read_ == buffer_size) {
168 std::move(read_cb_).Run(std::move(media_buffer_)); 170 DCHECK(read_cb_);
171 bytes_read_ = 0;
172 std::move(read_cb_).Run(std::move(media_buffer_));
173 }
169 } 174 }
170 } 175 }
171 } 176 }
172 177
173 // MojoDecoderBufferWriter 178 // MojoDecoderBufferWriter
174 179
175 // static 180 // static
176 std::unique_ptr<MojoDecoderBufferWriter> MojoDecoderBufferWriter::Create( 181 std::unique_ptr<MojoDecoderBufferWriter> MojoDecoderBufferWriter::Create(
177 DemuxerStream::Type type, 182 DemuxerStream::Type type,
178 mojo::ScopedDataPipeConsumerHandle* consumer_handle) { 183 mojo::ScopedDataPipeConsumerHandle* consumer_handle) {
179 DVLOG(1) << __func__; 184 DVLOG(1) << __func__;
180 std::unique_ptr<mojo::DataPipe> data_pipe = CreateDataPipe(type); 185 std::unique_ptr<mojo::DataPipe> data_pipe = CreateDataPipe(type);
181 *consumer_handle = std::move(data_pipe->consumer_handle); 186 *consumer_handle = std::move(data_pipe->consumer_handle);
182 return base::WrapUnique( 187 return base::WrapUnique(
183 new MojoDecoderBufferWriter(std::move(data_pipe->producer_handle))); 188 new MojoDecoderBufferWriter(std::move(data_pipe->producer_handle)));
184 } 189 }
185 190
186 MojoDecoderBufferWriter::MojoDecoderBufferWriter( 191 MojoDecoderBufferWriter::MojoDecoderBufferWriter(
187 mojo::ScopedDataPipeProducerHandle producer_handle) 192 mojo::ScopedDataPipeProducerHandle producer_handle)
188 : producer_handle_(std::move(producer_handle)), 193 : producer_handle_(std::move(producer_handle)),
189 pipe_watcher_(FROM_HERE), 194 pipe_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL),
190 bytes_written_(0) { 195 bytes_written_(0) {
191 DVLOG(1) << __func__; 196 DVLOG(1) << __func__;
192 197
193 MojoResult result = 198 MojoResult result =
194 pipe_watcher_.Start(producer_handle_.get(), MOJO_HANDLE_SIGNAL_WRITABLE, 199 pipe_watcher_.Watch(producer_handle_.get(), MOJO_HANDLE_SIGNAL_WRITABLE,
195 base::Bind(&MojoDecoderBufferWriter::OnPipeWritable, 200 base::Bind(&MojoDecoderBufferWriter::OnPipeWritable,
196 base::Unretained(this))); 201 base::Unretained(this)));
197 if (result != MOJO_RESULT_OK) { 202 if (result != MOJO_RESULT_OK) {
198 DVLOG(1) << __func__ 203 DVLOG(1) << __func__
199 << ": Failed to start watching the pipe. result=" << result; 204 << ": Failed to start watching the pipe. result=" << result;
200 producer_handle_.reset(); 205 producer_handle_.reset();
206 } else {
207 pipe_watcher_.ArmOrNotify();
201 } 208 }
202 } 209 }
203 210
204 MojoDecoderBufferWriter::~MojoDecoderBufferWriter() { 211 MojoDecoderBufferWriter::~MojoDecoderBufferWriter() {
205 DVLOG(1) << __func__; 212 DVLOG(1) << __func__;
206 } 213 }
207 214
208 mojom::DecoderBufferPtr MojoDecoderBufferWriter::WriteDecoderBuffer( 215 mojom::DecoderBufferPtr MojoDecoderBufferWriter::WriteDecoderBuffer(
209 const scoped_refptr<DecoderBuffer>& media_buffer) { 216 const scoped_refptr<DecoderBuffer>& media_buffer) {
210 DVLOG(3) << __func__; 217 DVLOG(3) << __func__;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 273
267 uint32_t num_bytes = buffer_size - bytes_written_; 274 uint32_t num_bytes = buffer_size - bytes_written_;
268 DCHECK_GT(num_bytes, 0u); 275 DCHECK_GT(num_bytes, 0u);
269 276
270 MojoResult result = WriteDataRaw(producer_handle_.get(), 277 MojoResult result = WriteDataRaw(producer_handle_.get(),
271 media_buffer_->data() + bytes_written_, 278 media_buffer_->data() + bytes_written_,
272 &num_bytes, MOJO_WRITE_DATA_FLAG_NONE); 279 &num_bytes, MOJO_WRITE_DATA_FLAG_NONE);
273 280
274 if (IsPipeReadWriteError(result)) { 281 if (IsPipeReadWriteError(result)) {
275 OnPipeError(result); 282 OnPipeError(result);
276 } else if (result == MOJO_RESULT_OK) { 283 } else {
277 DCHECK_GT(num_bytes, 0u); 284 pipe_watcher_.ArmOrNotify();
278 bytes_written_ += num_bytes; 285 if (result == MOJO_RESULT_OK) {
279 if (bytes_written_ == buffer_size) { 286 DCHECK_GT(num_bytes, 0u);
280 media_buffer_ = nullptr; 287 bytes_written_ += num_bytes;
281 bytes_written_ = 0; 288 if (bytes_written_ == buffer_size) {
289 media_buffer_ = nullptr;
290 bytes_written_ = 0;
291 }
282 } 292 }
283 } 293 }
284 294
285 return result; 295 return result;
286 } 296 }
287 297
288 } // namespace media 298 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/common/mojo_decoder_buffer_converter.h ('k') | media/remoting/demuxer_stream_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698