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__; |
141 | 127 |
142 // TODO(timav): Use DataPipe. | 128 // TODO(timav): Use DataPipe. |
143 client_->OnBufferDecoded(mojom::AudioBuffer::From(audio_buffer)); | 129 client_->OnBufferDecoded(mojom::AudioBuffer::From(audio_buffer)); |
144 } | 130 } |
145 | 131 |
146 scoped_refptr<DecoderBuffer> MojoAudioDecoderService::ReadDecoderBuffer( | 132 scoped_refptr<DecoderBuffer> MojoAudioDecoderService::ReadDecoderBuffer( |
147 mojom::DecoderBufferPtr buffer) { | 133 mojom::DecoderBufferPtr buffer) { |
148 scoped_refptr<DecoderBuffer> media_buffer( | 134 scoped_refptr<DecoderBuffer> media_buffer( |
149 buffer.To<scoped_refptr<DecoderBuffer>>()); | 135 buffer.To<scoped_refptr<DecoderBuffer>>()); |
150 | 136 |
151 if (media_buffer->end_of_stream()) | 137 if (media_buffer->end_of_stream()) |
152 return media_buffer; | 138 return media_buffer; |
153 | 139 |
154 // Wait for the data to become available in the DataPipe. | 140 // Wait for the data to become available in the DataPipe. |
141 MojoResult result; | |
155 MojoHandleSignalsState state; | 142 MojoHandleSignalsState state; |
156 CHECK_EQ(MOJO_RESULT_OK, | 143 result = MojoWait(consumer_handle_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
157 MojoWait(consumer_handle_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 144 MOJO_DEADLINE_INDEFINITE, &state); |
158 MOJO_DEADLINE_INDEFINITE, &state)); | 145 if (result != MOJO_RESULT_OK || |
159 | 146 !(state.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)) { |
147 return nullptr; | |
148 } | |
160 if (state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_CLOSED) { | 149 if (state.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_CLOSED) { |
161 DVLOG(1) << __FUNCTION__ << ": Peer closed the data pipe"; | 150 DVLOG(1) << __FUNCTION__ << ": Peer closed the data pipe"; |
162 return scoped_refptr<DecoderBuffer>(); | 151 return nullptr; |
163 } | 152 } |
164 | 153 |
165 CHECK_EQ(MOJO_HANDLE_SIGNAL_READABLE, | 154 // Read the inner data for the DecoderBuffer from our DataPipe. |
166 state.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE); | 155 uint32_t data_size = buffer->data_size; |
156 if (data_size != media_buffer->data_size()) | |
Tima Vaisburd
2016/05/18 00:32:16
Drive-by: how can they be different?
sandersd (OOO until July 31)
2016/05/18 00:49:29
They can't (assuming size_t is of higher integer r
sandersd (OOO until July 31)
2016/05/18 00:50:42
*same or higher
dcheng
2016/05/20 21:18:22
I'd suggest DCHECK() or static_assert in the TypeC
sandersd (OOO until July 31)
2016/05/20 22:27:14
Converted to a CHECK() (in MojoVideoDecoderService
| |
157 return nullptr; | |
167 | 158 |
168 // Read the inner data for the DecoderBuffer from our DataPipe. | 159 uint32_t bytes_read = data_size; |
169 uint32_t bytes_to_read = | 160 result = ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), |
170 base::checked_cast<uint32_t>(media_buffer->data_size()); | 161 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE); |
171 DCHECK_GT(bytes_to_read, 0u); | 162 if (result != MOJO_RESULT_OK || bytes_read != data_size) |
172 uint32_t bytes_read = bytes_to_read; | 163 return nullptr; |
173 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), | |
174 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | |
175 MOJO_RESULT_OK); | |
176 CHECK_EQ(bytes_to_read, bytes_read); | |
177 | 164 |
178 return media_buffer; | 165 return media_buffer; |
179 } | 166 } |
180 | 167 |
181 } // namespace media | 168 } // namespace media |
OLD | NEW |