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

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

Issue 2750373002: Revert of 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, mojo::SimpleWatcher::ArmingPolicy::MANUAL), 67 pipe_watcher_(FROM_HERE),
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_.Watch(consumer_handle_.get(), MOJO_HANDLE_SIGNAL_READABLE, 72 pipe_watcher_.Start(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();
81 } 79 }
82 } 80 }
83 81
84 MojoDecoderBufferReader::~MojoDecoderBufferReader() { 82 MojoDecoderBufferReader::~MojoDecoderBufferReader() {
85 DVLOG(1) << __func__; 83 DVLOG(1) << __func__;
86 } 84 }
87 85
88 void MojoDecoderBufferReader::ReadDecoderBuffer( 86 void MojoDecoderBufferReader::ReadDecoderBuffer(
89 mojom::DecoderBufferPtr mojo_buffer, 87 mojom::DecoderBufferPtr mojo_buffer,
90 ReadCB read_cb) { 88 ReadCB read_cb) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 152
155 uint32_t num_bytes = buffer_size - bytes_read_; 153 uint32_t num_bytes = buffer_size - bytes_read_;
156 DCHECK_GT(num_bytes, 0u); 154 DCHECK_GT(num_bytes, 0u);
157 155
158 MojoResult result = ReadDataRaw(consumer_handle_.get(), 156 MojoResult result = ReadDataRaw(consumer_handle_.get(),
159 media_buffer_->writable_data() + bytes_read_, 157 media_buffer_->writable_data() + bytes_read_,
160 &num_bytes, MOJO_WRITE_DATA_FLAG_NONE); 158 &num_bytes, MOJO_WRITE_DATA_FLAG_NONE);
161 159
162 if (IsPipeReadWriteError(result)) { 160 if (IsPipeReadWriteError(result)) {
163 OnPipeError(result); 161 OnPipeError(result);
164 } else { 162 } else if (result == MOJO_RESULT_OK) {
165 pipe_watcher_.ArmOrNotify(); 163 DCHECK_GT(num_bytes, 0u);
166 if (result == MOJO_RESULT_OK) { 164 bytes_read_ += num_bytes;
167 DCHECK_GT(num_bytes, 0u); 165 if (bytes_read_ == buffer_size) {
168 bytes_read_ += num_bytes; 166 DCHECK(read_cb_);
169 if (bytes_read_ == buffer_size) { 167 bytes_read_ = 0;
170 DCHECK(read_cb_); 168 std::move(read_cb_).Run(std::move(media_buffer_));
171 bytes_read_ = 0;
172 std::move(read_cb_).Run(std::move(media_buffer_));
173 }
174 } 169 }
175 } 170 }
176 } 171 }
177 172
178 // MojoDecoderBufferWriter 173 // MojoDecoderBufferWriter
179 174
180 // static 175 // static
181 std::unique_ptr<MojoDecoderBufferWriter> MojoDecoderBufferWriter::Create( 176 std::unique_ptr<MojoDecoderBufferWriter> MojoDecoderBufferWriter::Create(
182 DemuxerStream::Type type, 177 DemuxerStream::Type type,
183 mojo::ScopedDataPipeConsumerHandle* consumer_handle) { 178 mojo::ScopedDataPipeConsumerHandle* consumer_handle) {
184 DVLOG(1) << __func__; 179 DVLOG(1) << __func__;
185 std::unique_ptr<mojo::DataPipe> data_pipe = CreateDataPipe(type); 180 std::unique_ptr<mojo::DataPipe> data_pipe = CreateDataPipe(type);
186 *consumer_handle = std::move(data_pipe->consumer_handle); 181 *consumer_handle = std::move(data_pipe->consumer_handle);
187 return base::WrapUnique( 182 return base::WrapUnique(
188 new MojoDecoderBufferWriter(std::move(data_pipe->producer_handle))); 183 new MojoDecoderBufferWriter(std::move(data_pipe->producer_handle)));
189 } 184 }
190 185
191 MojoDecoderBufferWriter::MojoDecoderBufferWriter( 186 MojoDecoderBufferWriter::MojoDecoderBufferWriter(
192 mojo::ScopedDataPipeProducerHandle producer_handle) 187 mojo::ScopedDataPipeProducerHandle producer_handle)
193 : producer_handle_(std::move(producer_handle)), 188 : producer_handle_(std::move(producer_handle)),
194 pipe_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL), 189 pipe_watcher_(FROM_HERE),
195 bytes_written_(0) { 190 bytes_written_(0) {
196 DVLOG(1) << __func__; 191 DVLOG(1) << __func__;
197 192
198 MojoResult result = 193 MojoResult result =
199 pipe_watcher_.Watch(producer_handle_.get(), MOJO_HANDLE_SIGNAL_WRITABLE, 194 pipe_watcher_.Start(producer_handle_.get(), MOJO_HANDLE_SIGNAL_WRITABLE,
200 base::Bind(&MojoDecoderBufferWriter::OnPipeWritable, 195 base::Bind(&MojoDecoderBufferWriter::OnPipeWritable,
201 base::Unretained(this))); 196 base::Unretained(this)));
202 if (result != MOJO_RESULT_OK) { 197 if (result != MOJO_RESULT_OK) {
203 DVLOG(1) << __func__ 198 DVLOG(1) << __func__
204 << ": Failed to start watching the pipe. result=" << result; 199 << ": Failed to start watching the pipe. result=" << result;
205 producer_handle_.reset(); 200 producer_handle_.reset();
206 } else {
207 pipe_watcher_.ArmOrNotify();
208 } 201 }
209 } 202 }
210 203
211 MojoDecoderBufferWriter::~MojoDecoderBufferWriter() { 204 MojoDecoderBufferWriter::~MojoDecoderBufferWriter() {
212 DVLOG(1) << __func__; 205 DVLOG(1) << __func__;
213 } 206 }
214 207
215 mojom::DecoderBufferPtr MojoDecoderBufferWriter::WriteDecoderBuffer( 208 mojom::DecoderBufferPtr MojoDecoderBufferWriter::WriteDecoderBuffer(
216 const scoped_refptr<DecoderBuffer>& media_buffer) { 209 const scoped_refptr<DecoderBuffer>& media_buffer) {
217 DVLOG(3) << __func__; 210 DVLOG(3) << __func__;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 266
274 uint32_t num_bytes = buffer_size - bytes_written_; 267 uint32_t num_bytes = buffer_size - bytes_written_;
275 DCHECK_GT(num_bytes, 0u); 268 DCHECK_GT(num_bytes, 0u);
276 269
277 MojoResult result = WriteDataRaw(producer_handle_.get(), 270 MojoResult result = WriteDataRaw(producer_handle_.get(),
278 media_buffer_->data() + bytes_written_, 271 media_buffer_->data() + bytes_written_,
279 &num_bytes, MOJO_WRITE_DATA_FLAG_NONE); 272 &num_bytes, MOJO_WRITE_DATA_FLAG_NONE);
280 273
281 if (IsPipeReadWriteError(result)) { 274 if (IsPipeReadWriteError(result)) {
282 OnPipeError(result); 275 OnPipeError(result);
283 } else { 276 } else if (result == MOJO_RESULT_OK) {
284 pipe_watcher_.ArmOrNotify(); 277 DCHECK_GT(num_bytes, 0u);
285 if (result == MOJO_RESULT_OK) { 278 bytes_written_ += num_bytes;
286 DCHECK_GT(num_bytes, 0u); 279 if (bytes_written_ == buffer_size) {
287 bytes_written_ += num_bytes; 280 media_buffer_ = nullptr;
288 if (bytes_written_ == buffer_size) { 281 bytes_written_ = 0;
289 media_buffer_ = nullptr;
290 bytes_written_ = 0;
291 }
292 } 282 }
293 } 283 }
294 284
295 return result; 285 return result;
296 } 286 }
297 287
298 } // namespace media 288 } // 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