| OLD | NEW |
| 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_service.h" | 5 #include "media/mojo/services/mojo_audio_decoder_service.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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/base/cdm_context.h" | 10 #include "media/base/cdm_context.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 scoped_refptr<DecoderBuffer> MojoAudioDecoderService::ReadDecoderBuffer( | 146 scoped_refptr<DecoderBuffer> MojoAudioDecoderService::ReadDecoderBuffer( |
| 147 mojom::DecoderBufferPtr buffer) { | 147 mojom::DecoderBufferPtr buffer) { |
| 148 scoped_refptr<DecoderBuffer> media_buffer( | 148 scoped_refptr<DecoderBuffer> media_buffer( |
| 149 buffer.To<scoped_refptr<DecoderBuffer>>()); | 149 buffer.To<scoped_refptr<DecoderBuffer>>()); |
| 150 | 150 |
| 151 if (media_buffer->end_of_stream()) | 151 if (media_buffer->end_of_stream()) |
| 152 return media_buffer; | 152 return media_buffer; |
| 153 | 153 |
| 154 // Wait for the data to become available in the DataPipe. | 154 // Wait for the data to become available in the DataPipe. |
| 155 MojoHandleSignalsState state; | 155 MojoHandleSignalsState state; |
| 156 CHECK_EQ(MOJO_RESULT_OK, | 156 MojoResult result = |
| 157 MojoWait(consumer_handle_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 157 MojoWait(consumer_handle_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 158 MOJO_DEADLINE_INDEFINITE, &state)); | 158 MOJO_DEADLINE_INDEFINITE, &state); |
| 159 | 159 |
| 160 if (state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_CLOSED) { | 160 if (result != MOJO_RESULT_OK) { |
| 161 DVLOG(1) << __FUNCTION__ << ": Peer closed the data pipe"; | 161 DVLOG(1) << __FUNCTION__ << ": Peer closed the data pipe"; |
| 162 return scoped_refptr<DecoderBuffer>(); | 162 return nullptr; |
| 163 } | 163 } |
| 164 | 164 |
| 165 CHECK_EQ(MOJO_HANDLE_SIGNAL_READABLE, | 165 // Read the inner data for the DecoderBuffer from our DataPipe. |
| 166 state.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE); | 166 uint32_t data_size = static_cast<uint32_t>(media_buffer->data_size()); |
| 167 DCHECK_EQ(data_size, buffer->data_size); |
| 168 DCHECK_GT(data_size, 0u); |
| 167 | 169 |
| 168 // Read the inner data for the DecoderBuffer from our DataPipe. | 170 uint32_t bytes_read = data_size; |
| 169 uint32_t bytes_to_read = | 171 result = ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), |
| 170 base::checked_cast<uint32_t>(media_buffer->data_size()); | 172 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE); |
| 171 DCHECK_GT(bytes_to_read, 0u); | 173 if (result != MOJO_RESULT_OK || bytes_read != data_size) { |
| 172 uint32_t bytes_read = bytes_to_read; | 174 DVLOG(1) << __FUNCTION__ << ": reading from pipe failed"; |
| 173 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), | 175 return nullptr; |
| 174 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 176 } |
| 175 MOJO_RESULT_OK); | |
| 176 CHECK_EQ(bytes_to_read, bytes_read); | |
| 177 | 177 |
| 178 return media_buffer; | 178 return media_buffer; |
| 179 } | 179 } |
| 180 | 180 |
| 181 } // namespace media | 181 } // namespace media |
| OLD | NEW |