OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/clients/mojo_decryptor.h" | 5 #include "media/mojo/clients/mojo_decryptor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 DCHECK(thread_checker_.CalledOnValidThread()); | 68 DCHECK(thread_checker_.CalledOnValidThread()); |
69 | 69 |
70 mojom::DecoderBufferPtr mojo_buffer = | 70 mojom::DecoderBufferPtr mojo_buffer = |
71 mojo_decoder_buffer_writer_->WriteDecoderBuffer(encrypted); | 71 mojo_decoder_buffer_writer_->WriteDecoderBuffer(encrypted); |
72 if (!mojo_buffer) { | 72 if (!mojo_buffer) { |
73 decrypt_cb.Run(kError, nullptr); | 73 decrypt_cb.Run(kError, nullptr); |
74 return; | 74 return; |
75 } | 75 } |
76 | 76 |
77 remote_decryptor_->Decrypt( | 77 remote_decryptor_->Decrypt( |
78 static_cast<mojom::DemuxerStream::Type>(stream_type), | 78 stream_type, std::move(mojo_buffer), |
79 std::move(mojo_buffer), | |
80 base::Bind(&MojoDecryptor::OnBufferDecrypted, weak_factory_.GetWeakPtr(), | 79 base::Bind(&MojoDecryptor::OnBufferDecrypted, weak_factory_.GetWeakPtr(), |
81 decrypt_cb)); | 80 decrypt_cb)); |
82 } | 81 } |
83 | 82 |
84 void MojoDecryptor::CancelDecrypt(StreamType stream_type) { | 83 void MojoDecryptor::CancelDecrypt(StreamType stream_type) { |
85 DVLOG(1) << __FUNCTION__; | 84 DVLOG(1) << __FUNCTION__; |
86 DCHECK(thread_checker_.CalledOnValidThread()); | 85 DCHECK(thread_checker_.CalledOnValidThread()); |
87 | 86 |
88 remote_decryptor_->CancelDecrypt( | 87 remote_decryptor_->CancelDecrypt(stream_type); |
89 static_cast<mojom::DemuxerStream::Type>(stream_type)); | |
90 } | 88 } |
91 | 89 |
92 void MojoDecryptor::InitializeAudioDecoder(const AudioDecoderConfig& config, | 90 void MojoDecryptor::InitializeAudioDecoder(const AudioDecoderConfig& config, |
93 const DecoderInitCB& init_cb) { | 91 const DecoderInitCB& init_cb) { |
94 DVLOG(1) << __FUNCTION__; | 92 DVLOG(1) << __FUNCTION__; |
95 DCHECK(thread_checker_.CalledOnValidThread()); | 93 DCHECK(thread_checker_.CalledOnValidThread()); |
96 | 94 |
97 remote_decryptor_->InitializeAudioDecoder( | 95 remote_decryptor_->InitializeAudioDecoder( |
98 mojom::AudioDecoderConfig::From(config), init_cb); | 96 mojom::AudioDecoderConfig::From(config), init_cb); |
99 } | 97 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 remote_decryptor_->DecryptAndDecodeVideo( | 140 remote_decryptor_->DecryptAndDecodeVideo( |
143 std::move(mojo_buffer), | 141 std::move(mojo_buffer), |
144 base::Bind(&MojoDecryptor::OnVideoDecoded, weak_factory_.GetWeakPtr(), | 142 base::Bind(&MojoDecryptor::OnVideoDecoded, weak_factory_.GetWeakPtr(), |
145 video_decode_cb)); | 143 video_decode_cb)); |
146 } | 144 } |
147 | 145 |
148 void MojoDecryptor::ResetDecoder(StreamType stream_type) { | 146 void MojoDecryptor::ResetDecoder(StreamType stream_type) { |
149 DVLOG(1) << __FUNCTION__; | 147 DVLOG(1) << __FUNCTION__; |
150 DCHECK(thread_checker_.CalledOnValidThread()); | 148 DCHECK(thread_checker_.CalledOnValidThread()); |
151 | 149 |
152 remote_decryptor_->ResetDecoder( | 150 remote_decryptor_->ResetDecoder(stream_type); |
153 static_cast<mojom::DemuxerStream::Type>(stream_type)); | |
154 } | 151 } |
155 | 152 |
156 void MojoDecryptor::DeinitializeDecoder(StreamType stream_type) { | 153 void MojoDecryptor::DeinitializeDecoder(StreamType stream_type) { |
157 DVLOG(1) << __FUNCTION__; | 154 DVLOG(1) << __FUNCTION__; |
158 DCHECK(thread_checker_.CalledOnValidThread()); | 155 DCHECK(thread_checker_.CalledOnValidThread()); |
159 | 156 |
160 remote_decryptor_->DeinitializeDecoder( | 157 remote_decryptor_->DeinitializeDecoder(stream_type); |
161 static_cast<mojom::DemuxerStream::Type>(stream_type)); | |
162 } | 158 } |
163 | 159 |
164 void MojoDecryptor::OnKeyAdded() { | 160 void MojoDecryptor::OnKeyAdded() { |
165 DVLOG(1) << __FUNCTION__; | 161 DVLOG(1) << __FUNCTION__; |
166 DCHECK(thread_checker_.CalledOnValidThread()); | 162 DCHECK(thread_checker_.CalledOnValidThread()); |
167 | 163 |
168 if (!new_audio_key_cb_.is_null()) | 164 if (!new_audio_key_cb_.is_null()) |
169 new_audio_key_cb_.Run(); | 165 new_audio_key_cb_.Run(); |
170 | 166 |
171 if (!new_video_key_cb_.is_null()) | 167 if (!new_video_key_cb_.is_null()) |
172 new_video_key_cb_.Run(); | 168 new_video_key_cb_.Run(); |
173 } | 169 } |
174 | 170 |
175 void MojoDecryptor::OnBufferDecrypted(const DecryptCB& decrypt_cb, | 171 void MojoDecryptor::OnBufferDecrypted(const DecryptCB& decrypt_cb, |
176 mojom::Decryptor::Status status, | 172 Status status, |
177 mojom::DecoderBufferPtr buffer) { | 173 mojom::DecoderBufferPtr buffer) { |
178 DVLOG_IF(1, status != mojom::Decryptor::Status::SUCCESS) | 174 DVLOG_IF(1, status != kSuccess) << __FUNCTION__ << "(" << status << ")"; |
179 << __FUNCTION__ << "(" << status << ")"; | 175 DVLOG_IF(3, status == kSuccess) << __FUNCTION__; |
180 DVLOG_IF(3, status == mojom::Decryptor::Status::SUCCESS) << __FUNCTION__; | |
181 DCHECK(thread_checker_.CalledOnValidThread()); | 176 DCHECK(thread_checker_.CalledOnValidThread()); |
182 | 177 |
183 if (buffer.is_null()) { | 178 if (buffer.is_null()) { |
184 decrypt_cb.Run(static_cast<Decryptor::Status>(status), nullptr); | 179 decrypt_cb.Run(static_cast<Decryptor::Status>(status), nullptr); |
185 return; | 180 return; |
186 } | 181 } |
187 | 182 |
188 scoped_refptr<DecoderBuffer> media_buffer = | 183 scoped_refptr<DecoderBuffer> media_buffer = |
189 mojo_decoder_buffer_reader_->ReadDecoderBuffer(buffer); | 184 mojo_decoder_buffer_reader_->ReadDecoderBuffer(buffer); |
190 if (!media_buffer) { | 185 if (!media_buffer) { |
191 decrypt_cb.Run(kError, nullptr); | 186 decrypt_cb.Run(kError, nullptr); |
192 return; | 187 return; |
193 } | 188 } |
194 | 189 |
195 decrypt_cb.Run(static_cast<Decryptor::Status>(status), media_buffer); | 190 decrypt_cb.Run(static_cast<Decryptor::Status>(status), media_buffer); |
196 } | 191 } |
197 | 192 |
198 void MojoDecryptor::OnAudioDecoded( | 193 void MojoDecryptor::OnAudioDecoded( |
199 const AudioDecodeCB& audio_decode_cb, | 194 const AudioDecodeCB& audio_decode_cb, |
200 mojom::Decryptor::Status status, | 195 Status status, |
201 std::vector<mojom::AudioBufferPtr> audio_buffers) { | 196 std::vector<mojom::AudioBufferPtr> audio_buffers) { |
202 DVLOG_IF(1, status != mojom::Decryptor::Status::SUCCESS) | 197 DVLOG_IF(1, status != kSuccess) << __FUNCTION__ << "(" << status << ")"; |
203 << __FUNCTION__ << "(" << status << ")"; | 198 DVLOG_IF(3, status == kSuccess) << __FUNCTION__; |
204 DVLOG_IF(3, status == mojom::Decryptor::Status::SUCCESS) << __FUNCTION__; | |
205 DCHECK(thread_checker_.CalledOnValidThread()); | 199 DCHECK(thread_checker_.CalledOnValidThread()); |
206 | 200 |
207 Decryptor::AudioFrames audio_frames; | 201 Decryptor::AudioFrames audio_frames; |
208 for (size_t i = 0; i < audio_buffers.size(); ++i) | 202 for (size_t i = 0; i < audio_buffers.size(); ++i) |
209 audio_frames.push_back(audio_buffers[i].To<scoped_refptr<AudioBuffer>>()); | 203 audio_frames.push_back(audio_buffers[i].To<scoped_refptr<AudioBuffer>>()); |
210 | 204 |
211 audio_decode_cb.Run(static_cast<Decryptor::Status>(status), audio_frames); | 205 audio_decode_cb.Run(static_cast<Decryptor::Status>(status), audio_frames); |
212 } | 206 } |
213 | 207 |
214 void MojoDecryptor::OnVideoDecoded(const VideoDecodeCB& video_decode_cb, | 208 void MojoDecryptor::OnVideoDecoded(const VideoDecodeCB& video_decode_cb, |
215 mojom::Decryptor::Status status, | 209 Status status, |
216 mojom::VideoFramePtr video_frame) { | 210 mojom::VideoFramePtr video_frame) { |
217 DVLOG_IF(1, status != mojom::Decryptor::Status::SUCCESS) | 211 DVLOG_IF(1, status != kSuccess) << __FUNCTION__ << "(" << status << ")"; |
218 << __FUNCTION__ << "(" << status << ")"; | 212 DVLOG_IF(3, status == kSuccess) << __FUNCTION__; |
219 DVLOG_IF(3, status == mojom::Decryptor::Status::SUCCESS) << __FUNCTION__; | |
220 DCHECK(thread_checker_.CalledOnValidThread()); | 213 DCHECK(thread_checker_.CalledOnValidThread()); |
221 | 214 |
222 if (video_frame.is_null()) { | 215 if (video_frame.is_null()) { |
223 video_decode_cb.Run(static_cast<Decryptor::Status>(status), nullptr); | 216 video_decode_cb.Run(static_cast<Decryptor::Status>(status), nullptr); |
224 return; | 217 return; |
225 } | 218 } |
226 | 219 |
227 scoped_refptr<VideoFrame> frame(video_frame.To<scoped_refptr<VideoFrame>>()); | 220 scoped_refptr<VideoFrame> frame(video_frame.To<scoped_refptr<VideoFrame>>()); |
228 | 221 |
229 // If using shared memory, ensure that ReleaseSharedBuffer() is called when | 222 // If using shared memory, ensure that ReleaseSharedBuffer() is called when |
(...skipping 10 matching lines...) Expand all Loading... |
240 | 233 |
241 void MojoDecryptor::ReleaseSharedBuffer(mojo::ScopedSharedBufferHandle buffer, | 234 void MojoDecryptor::ReleaseSharedBuffer(mojo::ScopedSharedBufferHandle buffer, |
242 size_t buffer_size) { | 235 size_t buffer_size) { |
243 DVLOG(1) << __FUNCTION__; | 236 DVLOG(1) << __FUNCTION__; |
244 DCHECK(thread_checker_.CalledOnValidThread()); | 237 DCHECK(thread_checker_.CalledOnValidThread()); |
245 | 238 |
246 remote_decryptor_->ReleaseSharedBuffer(std::move(buffer), buffer_size); | 239 remote_decryptor_->ReleaseSharedBuffer(std::move(buffer), buffer_size); |
247 } | 240 } |
248 | 241 |
249 } // namespace media | 242 } // namespace media |
OLD | NEW |