| 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" |
| 11 #include "media/base/media_keys.h" | 11 #include "media/base/media_keys.h" |
| 12 #include "media/mojo/common/media_type_converters.h" | 12 #include "media/mojo/common/media_type_converters.h" |
| 13 #include "media/mojo/services/mojo_cdm_service_context.h" | 13 #include "media/mojo/services/mojo_cdm_service_context.h" |
| 14 | 14 |
| 15 namespace media { | 15 namespace media { |
| 16 | 16 |
| 17 static mojom::AudioDecoder::DecodeStatus ConvertDecodeStatus( | |
| 18 media::DecodeStatus status) { | |
| 19 switch (status) { | |
| 20 case media::DecodeStatus::OK: | |
| 21 return mojom::AudioDecoder::DecodeStatus::OK; | |
| 22 case media::DecodeStatus::ABORTED: | |
| 23 return mojom::AudioDecoder::DecodeStatus::ABORTED; | |
| 24 case media::DecodeStatus::DECODE_ERROR: | |
| 25 return mojom::AudioDecoder::DecodeStatus::DECODE_ERROR; | |
| 26 } | |
| 27 NOTREACHED(); | |
| 28 return mojom::AudioDecoder::DecodeStatus::DECODE_ERROR; | |
| 29 } | |
| 30 | |
| 31 MojoAudioDecoderService::MojoAudioDecoderService( | 17 MojoAudioDecoderService::MojoAudioDecoderService( |
| 32 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, | 18 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, |
| 33 std::unique_ptr<media::AudioDecoder> decoder, | 19 std::unique_ptr<media::AudioDecoder> decoder, |
| 34 mojo::InterfaceRequest<mojom::AudioDecoder> request) | 20 mojo::InterfaceRequest<mojom::AudioDecoder> request) |
| 35 : binding_(this, std::move(request)), | 21 : binding_(this, std::move(request)), |
| 36 mojo_cdm_service_context_(mojo_cdm_service_context), | 22 mojo_cdm_service_context_(mojo_cdm_service_context), |
| 37 decoder_(std::move(decoder)), | 23 decoder_(std::move(decoder)), |
| 38 weak_factory_(this) { | 24 weak_factory_(this) { |
| 39 weak_this_ = weak_factory_.GetWeakPtr(); | 25 weak_this_ = weak_factory_.GetWeakPtr(); |
| 40 } | 26 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 consumer_handle_ = std::move(receive_pipe); | 74 consumer_handle_ = std::move(receive_pipe); |
| 89 } | 75 } |
| 90 | 76 |
| 91 void MojoAudioDecoderService::Decode(mojom::DecoderBufferPtr buffer, | 77 void MojoAudioDecoderService::Decode(mojom::DecoderBufferPtr buffer, |
| 92 const DecodeCallback& callback) { | 78 const DecodeCallback& callback) { |
| 93 DVLOG(3) << __FUNCTION__; | 79 DVLOG(3) << __FUNCTION__; |
| 94 | 80 |
| 95 scoped_refptr<DecoderBuffer> media_buffer = | 81 scoped_refptr<DecoderBuffer> media_buffer = |
| 96 ReadDecoderBuffer(std::move(buffer)); | 82 ReadDecoderBuffer(std::move(buffer)); |
| 97 if (!media_buffer) { | 83 if (!media_buffer) { |
| 98 callback.Run(ConvertDecodeStatus(media::DecodeStatus::DECODE_ERROR)); | 84 callback.Run(mojom::DecodeStatus::DECODE_ERROR); |
| 99 return; | 85 return; |
| 100 } | 86 } |
| 101 | 87 |
| 102 decoder_->Decode(media_buffer, | 88 decoder_->Decode(media_buffer, |
| 103 base::Bind(&MojoAudioDecoderService::OnDecodeStatus, | 89 base::Bind(&MojoAudioDecoderService::OnDecodeStatus, |
| 104 weak_this_, callback)); | 90 weak_this_, callback)); |
| 105 } | 91 } |
| 106 | 92 |
| 107 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { | 93 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { |
| 108 DVLOG(1) << __FUNCTION__; | 94 DVLOG(1) << __FUNCTION__; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 120 callback.Run(success, decoder_->NeedsBitstreamConversion()); | 106 callback.Run(success, decoder_->NeedsBitstreamConversion()); |
| 121 } else { | 107 } else { |
| 122 // Do not call decoder_->NeedsBitstreamConversion() if init failed. | 108 // Do not call decoder_->NeedsBitstreamConversion() if init failed. |
| 123 callback.Run(false, false); | 109 callback.Run(false, false); |
| 124 } | 110 } |
| 125 } | 111 } |
| 126 | 112 |
| 127 void MojoAudioDecoderService::OnDecodeStatus(const DecodeCallback& callback, | 113 void MojoAudioDecoderService::OnDecodeStatus(const DecodeCallback& callback, |
| 128 media::DecodeStatus status) { | 114 media::DecodeStatus status) { |
| 129 DVLOG(3) << __FUNCTION__ << " status:" << status; | 115 DVLOG(3) << __FUNCTION__ << " status:" << status; |
| 130 callback.Run(ConvertDecodeStatus(status)); | 116 callback.Run(static_cast<mojom::DecodeStatus>(status)); |
| 131 } | 117 } |
| 132 | 118 |
| 133 void MojoAudioDecoderService::OnResetDone(const ResetCallback& callback) { | 119 void MojoAudioDecoderService::OnResetDone(const ResetCallback& callback) { |
| 134 DVLOG(1) << __FUNCTION__; | 120 DVLOG(1) << __FUNCTION__; |
| 135 callback.Run(); | 121 callback.Run(); |
| 136 } | 122 } |
| 137 | 123 |
| 138 void MojoAudioDecoderService::OnAudioBufferReady( | 124 void MojoAudioDecoderService::OnAudioBufferReady( |
| 139 const scoped_refptr<AudioBuffer>& audio_buffer) { | 125 const scoped_refptr<AudioBuffer>& audio_buffer) { |
| 140 DVLOG(1) << __FUNCTION__; | 126 DVLOG(1) << __FUNCTION__; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE); | 158 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE); |
| 173 if (result != MOJO_RESULT_OK || bytes_read != data_size) { | 159 if (result != MOJO_RESULT_OK || bytes_read != data_size) { |
| 174 DVLOG(1) << __FUNCTION__ << ": reading from pipe failed"; | 160 DVLOG(1) << __FUNCTION__ << ": reading from pipe failed"; |
| 175 return nullptr; | 161 return nullptr; |
| 176 } | 162 } |
| 177 | 163 |
| 178 return media_buffer; | 164 return media_buffer; |
| 179 } | 165 } |
| 180 | 166 |
| 181 } // namespace media | 167 } // namespace media |
| OLD | NEW |