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

Side by Side Diff: media/mojo/services/mojo_audio_decoder.cc

Issue 1982883003: Handle unexpected MojoWait() result in MojoAudioDecoderService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase only Created 4 years, 7 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 | « no previous file | media/mojo/services/mojo_audio_decoder_service.cc » ('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 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/services/mojo_audio_decoder.h" 5 #include "media/mojo/services/mojo_audio_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 output_cb_ = output_cb; 72 output_cb_ = output_cb;
73 73
74 // Using base::Unretained(this) is safe because |this| owns |remote_decoder_|, 74 // Using base::Unretained(this) is safe because |this| owns |remote_decoder_|,
75 // and the callback won't be dispatched if |remote_decoder_| is destroyed. 75 // and the callback won't be dispatched if |remote_decoder_| is destroyed.
76 remote_decoder_->Initialize( 76 remote_decoder_->Initialize(
77 binding_.CreateInterfacePtrAndBind(), 77 binding_.CreateInterfacePtrAndBind(),
78 mojom::AudioDecoderConfig::From(config), cdm_id, 78 mojom::AudioDecoderConfig::From(config), cdm_id,
79 base::Bind(&MojoAudioDecoder::OnInitialized, base::Unretained(this))); 79 base::Bind(&MojoAudioDecoder::OnInitialized, base::Unretained(this)));
80 } 80 }
81 81
82 void MojoAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 82 void MojoAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& media_buffer,
83 const DecodeCB& decode_cb) { 83 const DecodeCB& decode_cb) {
84 DVLOG(3) << __FUNCTION__; 84 DVLOG(3) << __FUNCTION__;
85 DCHECK(task_runner_->BelongsToCurrentThread()); 85 DCHECK(task_runner_->BelongsToCurrentThread());
86 86
87 if (has_connection_error_) { 87 if (has_connection_error_) {
88 task_runner_->PostTask(FROM_HERE, 88 task_runner_->PostTask(FROM_HERE,
89 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR)); 89 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR));
90 return; 90 return;
91 } 91 }
92 92
93 mojom::DecoderBufferPtr buffer = TransferDecoderBuffer(media_buffer);
94 if (!buffer) {
95 task_runner_->PostTask(FROM_HERE,
96 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR));
97 return;
98 }
99
93 DCHECK(decode_cb_.is_null()); 100 DCHECK(decode_cb_.is_null());
94 decode_cb_ = decode_cb; 101 decode_cb_ = decode_cb;
95 102
96 remote_decoder_->Decode( 103 remote_decoder_->Decode(
97 TransferDecoderBuffer(buffer), 104 std::move(buffer),
98 base::Bind(&MojoAudioDecoder::OnDecodeStatus, base::Unretained(this))); 105 base::Bind(&MojoAudioDecoder::OnDecodeStatus, base::Unretained(this)));
99 } 106 }
100 107
101 void MojoAudioDecoder::Reset(const base::Closure& closure) { 108 void MojoAudioDecoder::Reset(const base::Closure& closure) {
102 DVLOG(2) << __FUNCTION__; 109 DVLOG(2) << __FUNCTION__;
103 DCHECK(task_runner_->BelongsToCurrentThread()); 110 DCHECK(task_runner_->BelongsToCurrentThread());
104 111
105 if (has_connection_error_) { 112 if (has_connection_error_) {
106 if (!decode_cb_.is_null()) { 113 if (!decode_cb_.is_null()) {
107 task_runner_->PostTask(FROM_HERE, 114 task_runner_->PostTask(FROM_HERE,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 223
217 mojom::DecoderBufferPtr MojoAudioDecoder::TransferDecoderBuffer( 224 mojom::DecoderBufferPtr MojoAudioDecoder::TransferDecoderBuffer(
218 const scoped_refptr<DecoderBuffer>& media_buffer) { 225 const scoped_refptr<DecoderBuffer>& media_buffer) {
219 mojom::DecoderBufferPtr buffer = mojom::DecoderBuffer::From(media_buffer); 226 mojom::DecoderBufferPtr buffer = mojom::DecoderBuffer::From(media_buffer);
220 if (media_buffer->end_of_stream()) 227 if (media_buffer->end_of_stream())
221 return buffer; 228 return buffer;
222 229
223 // Serialize the data section of the DecoderBuffer into our pipe. 230 // Serialize the data section of the DecoderBuffer into our pipe.
224 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); 231 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size());
225 DCHECK_GT(num_bytes, 0u); 232 DCHECK_GT(num_bytes, 0u);
226 CHECK_EQ(WriteDataRaw(producer_handle_.get(), media_buffer->data(), 233 MojoResult result =
227 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), 234 WriteDataRaw(producer_handle_.get(), media_buffer->data(), &num_bytes,
228 MOJO_RESULT_OK); 235 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE);
229 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); 236 if (result != MOJO_RESULT_OK || num_bytes != media_buffer->data_size()) {
237 DVLOG(1) << __FUNCTION__ << ": writing to data pipe failed";
238 return nullptr;
239 }
240
230 return buffer; 241 return buffer;
231 } 242 }
232 243
233 } // namespace media 244 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/mojo/services/mojo_audio_decoder_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698