| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 client_ = std::move(client); | 43 client_ = std::move(client); |
| 44 | 44 |
| 45 // TODO(timav): Get CdmContext from cdm_id. | 45 // TODO(timav): Get CdmContext from cdm_id. |
| 46 decoder_->Initialize( | 46 decoder_->Initialize( |
| 47 config.To<media::AudioDecoderConfig>(), | 47 config.To<media::AudioDecoderConfig>(), |
| 48 nullptr, // no CdmContext | 48 nullptr, // no CdmContext |
| 49 base::Bind(&MojoAudioDecoderService::OnInitialized, weak_this_, callback), | 49 base::Bind(&MojoAudioDecoderService::OnInitialized, weak_this_, callback), |
| 50 base::Bind(&MojoAudioDecoderService::OnAudioBufferReady, weak_this_)); | 50 base::Bind(&MojoAudioDecoderService::OnAudioBufferReady, weak_this_)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void MojoAudioDecoderService::SetDataSource( |
| 54 mojo::ScopedDataPipeConsumerHandle receive_pipe) { |
| 55 DVLOG(1) << __FUNCTION__; |
| 56 consumer_handle_ = std::move(receive_pipe); |
| 57 } |
| 58 |
| 53 void MojoAudioDecoderService::Decode(interfaces::DecoderBufferPtr buffer, | 59 void MojoAudioDecoderService::Decode(interfaces::DecoderBufferPtr buffer, |
| 54 const DecodeCallback& callback) { | 60 const DecodeCallback& callback) { |
| 55 DVLOG(3) << __FUNCTION__; | 61 DVLOG(3) << __FUNCTION__; |
| 56 decoder_->Decode(ReadDecoderBuffer(std::move(buffer)), | 62 decoder_->Decode(ReadDecoderBuffer(std::move(buffer)), |
| 57 base::Bind(&MojoAudioDecoderService::OnDecodeStatus, | 63 base::Bind(&MojoAudioDecoderService::OnDecodeStatus, |
| 58 weak_this_, callback)); | 64 weak_this_, callback)); |
| 59 } | 65 } |
| 60 | 66 |
| 61 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { | 67 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { |
| 62 DVLOG(1) << __FUNCTION__; | 68 DVLOG(1) << __FUNCTION__; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 } | 98 } |
| 93 | 99 |
| 94 void MojoAudioDecoderService::OnResetDone(const ResetCallback& callback) { | 100 void MojoAudioDecoderService::OnResetDone(const ResetCallback& callback) { |
| 95 DVLOG(1) << __FUNCTION__; | 101 DVLOG(1) << __FUNCTION__; |
| 96 callback.Run(); | 102 callback.Run(); |
| 97 } | 103 } |
| 98 | 104 |
| 99 void MojoAudioDecoderService::OnAudioBufferReady( | 105 void MojoAudioDecoderService::OnAudioBufferReady( |
| 100 const scoped_refptr<AudioBuffer>& audio_buffer) { | 106 const scoped_refptr<AudioBuffer>& audio_buffer) { |
| 101 DVLOG(1) << __FUNCTION__; | 107 DVLOG(1) << __FUNCTION__; |
| 102 NOTIMPLEMENTED(); | 108 |
| 109 // TODO(timav): Use DataPipe. |
| 110 client_->OnBufferDecoded(interfaces::AudioBuffer::From(audio_buffer)); |
| 103 } | 111 } |
| 104 | 112 |
| 105 scoped_refptr<DecoderBuffer> MojoAudioDecoderService::ReadDecoderBuffer( | 113 scoped_refptr<DecoderBuffer> MojoAudioDecoderService::ReadDecoderBuffer( |
| 106 interfaces::DecoderBufferPtr buffer) { | 114 interfaces::DecoderBufferPtr buffer) { |
| 107 scoped_refptr<DecoderBuffer> media_buffer( | 115 scoped_refptr<DecoderBuffer> media_buffer( |
| 108 buffer.To<scoped_refptr<DecoderBuffer>>()); | 116 buffer.To<scoped_refptr<DecoderBuffer>>()); |
| 109 | 117 |
| 110 NOTIMPLEMENTED(); | 118 if (media_buffer->end_of_stream()) |
| 119 return media_buffer; |
| 120 |
| 121 // Wait for the data to become available in the DataPipe. |
| 122 MojoHandleSignalsState state; |
| 123 CHECK_EQ(MOJO_RESULT_OK, |
| 124 MojoWait(consumer_handle_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 125 MOJO_DEADLINE_INDEFINITE, &state)); |
| 126 CHECK_EQ(MOJO_HANDLE_SIGNAL_READABLE, state.satisfied_signals); |
| 127 |
| 128 // Read the inner data for the DecoderBuffer from our DataPipe. |
| 129 uint32_t bytes_to_read = |
| 130 base::checked_cast<uint32_t>(media_buffer->data_size()); |
| 131 DCHECK_GT(bytes_to_read, 0u); |
| 132 uint32_t bytes_read = bytes_to_read; |
| 133 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), |
| 134 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
| 135 MOJO_RESULT_OK); |
| 136 CHECK_EQ(bytes_to_read, bytes_read); |
| 137 |
| 111 return media_buffer; | 138 return media_buffer; |
| 112 } | 139 } |
| 113 | 140 |
| 114 } // namespace media | 141 } // namespace media |
| OLD | NEW |