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/services/mojo_decryptor_service.h" | 5 #include "media/mojo/services/mojo_decryptor_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 void MojoDecryptorService::Initialize( | 39 void MojoDecryptorService::Initialize( |
40 mojo::ScopedDataPipeConsumerHandle receive_pipe, | 40 mojo::ScopedDataPipeConsumerHandle receive_pipe, |
41 mojo::ScopedDataPipeProducerHandle transmit_pipe) { | 41 mojo::ScopedDataPipeProducerHandle transmit_pipe) { |
42 mojo_decoder_buffer_writer_.reset( | 42 mojo_decoder_buffer_writer_.reset( |
43 new MojoDecoderBufferWriter(std::move(transmit_pipe))); | 43 new MojoDecoderBufferWriter(std::move(transmit_pipe))); |
44 mojo_decoder_buffer_reader_.reset( | 44 mojo_decoder_buffer_reader_.reset( |
45 new MojoDecoderBufferReader(std::move(receive_pipe))); | 45 new MojoDecoderBufferReader(std::move(receive_pipe))); |
46 } | 46 } |
47 | 47 |
48 void MojoDecryptorService::Decrypt(mojom::DemuxerStream::Type stream_type, | 48 void MojoDecryptorService::Decrypt(StreamType stream_type, |
49 mojom::DecoderBufferPtr encrypted, | 49 mojom::DecoderBufferPtr encrypted, |
50 const DecryptCallback& callback) { | 50 const DecryptCallback& callback) { |
51 DVLOG(3) << __FUNCTION__; | 51 DVLOG(3) << __FUNCTION__; |
52 | 52 |
53 scoped_refptr<DecoderBuffer> media_buffer = | 53 scoped_refptr<DecoderBuffer> media_buffer = |
54 mojo_decoder_buffer_reader_->ReadDecoderBuffer(encrypted); | 54 mojo_decoder_buffer_reader_->ReadDecoderBuffer(encrypted); |
55 if (!media_buffer) { | 55 if (!media_buffer) { |
56 callback.Run(Status::DECRYPTION_ERROR, nullptr); | 56 callback.Run(Status::kError, nullptr); |
57 return; | 57 return; |
58 } | 58 } |
59 | 59 |
60 decryptor_->Decrypt( | 60 decryptor_->Decrypt( |
61 static_cast<media::Decryptor::StreamType>(stream_type), | 61 stream_type, std::move(media_buffer), |
62 std::move(media_buffer), | |
63 base::Bind(&MojoDecryptorService::OnDecryptDone, weak_this_, callback)); | 62 base::Bind(&MojoDecryptorService::OnDecryptDone, weak_this_, callback)); |
64 } | 63 } |
65 | 64 |
66 void MojoDecryptorService::CancelDecrypt( | 65 void MojoDecryptorService::CancelDecrypt(StreamType stream_type) { |
67 mojom::DemuxerStream::Type stream_type) { | |
68 DVLOG(1) << __FUNCTION__; | 66 DVLOG(1) << __FUNCTION__; |
69 decryptor_->CancelDecrypt( | 67 decryptor_->CancelDecrypt(stream_type); |
70 static_cast<media::Decryptor::StreamType>(stream_type)); | |
71 } | 68 } |
72 | 69 |
73 void MojoDecryptorService::InitializeAudioDecoder( | 70 void MojoDecryptorService::InitializeAudioDecoder( |
74 mojom::AudioDecoderConfigPtr config, | 71 mojom::AudioDecoderConfigPtr config, |
75 const InitializeAudioDecoderCallback& callback) { | 72 const InitializeAudioDecoderCallback& callback) { |
76 DVLOG(1) << __FUNCTION__; | 73 DVLOG(1) << __FUNCTION__; |
77 decryptor_->InitializeAudioDecoder( | 74 decryptor_->InitializeAudioDecoder( |
78 config.To<AudioDecoderConfig>(), | 75 config.To<AudioDecoderConfig>(), |
79 base::Bind(&MojoDecryptorService::OnAudioDecoderInitialized, weak_this_, | 76 base::Bind(&MojoDecryptorService::OnAudioDecoderInitialized, weak_this_, |
80 callback)); | 77 callback)); |
(...skipping 10 matching lines...) Expand all Loading... |
91 } | 88 } |
92 | 89 |
93 void MojoDecryptorService::DecryptAndDecodeAudio( | 90 void MojoDecryptorService::DecryptAndDecodeAudio( |
94 mojom::DecoderBufferPtr encrypted, | 91 mojom::DecoderBufferPtr encrypted, |
95 const DecryptAndDecodeAudioCallback& callback) { | 92 const DecryptAndDecodeAudioCallback& callback) { |
96 DVLOG(3) << __FUNCTION__; | 93 DVLOG(3) << __FUNCTION__; |
97 | 94 |
98 scoped_refptr<DecoderBuffer> media_buffer = | 95 scoped_refptr<DecoderBuffer> media_buffer = |
99 mojo_decoder_buffer_reader_->ReadDecoderBuffer(encrypted); | 96 mojo_decoder_buffer_reader_->ReadDecoderBuffer(encrypted); |
100 if (!media_buffer) { | 97 if (!media_buffer) { |
101 callback.Run(Status::DECRYPTION_ERROR, | 98 callback.Run(Status::kError, std::vector<mojom::AudioBufferPtr>()); |
102 std::vector<mojom::AudioBufferPtr>()); | |
103 return; | 99 return; |
104 } | 100 } |
105 | 101 |
106 decryptor_->DecryptAndDecodeAudio( | 102 decryptor_->DecryptAndDecodeAudio( |
107 std::move(media_buffer), | 103 std::move(media_buffer), |
108 base::Bind(&MojoDecryptorService::OnAudioDecoded, weak_this_, callback)); | 104 base::Bind(&MojoDecryptorService::OnAudioDecoded, weak_this_, callback)); |
109 } | 105 } |
110 | 106 |
111 void MojoDecryptorService::DecryptAndDecodeVideo( | 107 void MojoDecryptorService::DecryptAndDecodeVideo( |
112 mojom::DecoderBufferPtr encrypted, | 108 mojom::DecoderBufferPtr encrypted, |
113 const DecryptAndDecodeVideoCallback& callback) { | 109 const DecryptAndDecodeVideoCallback& callback) { |
114 DVLOG(3) << __FUNCTION__; | 110 DVLOG(3) << __FUNCTION__; |
115 | 111 |
116 scoped_refptr<DecoderBuffer> media_buffer = | 112 scoped_refptr<DecoderBuffer> media_buffer = |
117 mojo_decoder_buffer_reader_->ReadDecoderBuffer(encrypted); | 113 mojo_decoder_buffer_reader_->ReadDecoderBuffer(encrypted); |
118 if (!media_buffer) { | 114 if (!media_buffer) { |
119 callback.Run(Status::DECRYPTION_ERROR, nullptr); | 115 callback.Run(Status::kError, nullptr); |
120 return; | 116 return; |
121 } | 117 } |
122 | 118 |
123 decryptor_->DecryptAndDecodeVideo( | 119 decryptor_->DecryptAndDecodeVideo( |
124 std::move(media_buffer), | 120 std::move(media_buffer), |
125 base::Bind(&MojoDecryptorService::OnVideoDecoded, weak_this_, callback)); | 121 base::Bind(&MojoDecryptorService::OnVideoDecoded, weak_this_, callback)); |
126 } | 122 } |
127 | 123 |
128 void MojoDecryptorService::ResetDecoder( | 124 void MojoDecryptorService::ResetDecoder(StreamType stream_type) { |
129 mojom::DemuxerStream::Type stream_type) { | |
130 DVLOG(1) << __FUNCTION__; | 125 DVLOG(1) << __FUNCTION__; |
131 decryptor_->ResetDecoder( | 126 decryptor_->ResetDecoder(stream_type); |
132 static_cast<media::Decryptor::StreamType>(stream_type)); | |
133 } | 127 } |
134 | 128 |
135 void MojoDecryptorService::DeinitializeDecoder( | 129 void MojoDecryptorService::DeinitializeDecoder(StreamType stream_type) { |
136 mojom::DemuxerStream::Type stream_type) { | |
137 DVLOG(1) << __FUNCTION__; | 130 DVLOG(1) << __FUNCTION__; |
138 decryptor_->DeinitializeDecoder( | 131 decryptor_->DeinitializeDecoder(stream_type); |
139 static_cast<media::Decryptor::StreamType>(stream_type)); | |
140 } | 132 } |
141 | 133 |
142 void MojoDecryptorService::ReleaseSharedBuffer( | 134 void MojoDecryptorService::ReleaseSharedBuffer( |
143 mojo::ScopedSharedBufferHandle buffer, | 135 mojo::ScopedSharedBufferHandle buffer, |
144 uint64_t buffer_size) { | 136 uint64_t buffer_size) { |
145 in_use_video_frames_.erase(buffer.get().value()); | 137 in_use_video_frames_.erase(buffer.get().value()); |
146 } | 138 } |
147 | 139 |
148 void MojoDecryptorService::OnDecryptDone( | 140 void MojoDecryptorService::OnDecryptDone( |
149 const DecryptCallback& callback, | 141 const DecryptCallback& callback, |
150 media::Decryptor::Status status, | 142 Status status, |
151 const scoped_refptr<DecoderBuffer>& buffer) { | 143 const scoped_refptr<DecoderBuffer>& buffer) { |
152 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "(" | 144 DVLOG_IF(1, status != Status::kSuccess) << __FUNCTION__ << "(" << status |
153 << status << ")"; | 145 << ")"; |
154 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__; | 146 DVLOG_IF(3, status == Status::kSuccess) << __FUNCTION__; |
155 | 147 |
156 if (!buffer) { | 148 if (!buffer) { |
157 DCHECK_NE(status, media::Decryptor::kSuccess); | 149 DCHECK_NE(status, Status::kSuccess); |
158 callback.Run(static_cast<Decryptor::Status>(status), nullptr); | 150 callback.Run(status, nullptr); |
159 return; | 151 return; |
160 } | 152 } |
161 | 153 |
162 mojom::DecoderBufferPtr mojo_buffer = | 154 mojom::DecoderBufferPtr mojo_buffer = |
163 mojo_decoder_buffer_writer_->WriteDecoderBuffer(buffer); | 155 mojo_decoder_buffer_writer_->WriteDecoderBuffer(buffer); |
164 if (!mojo_buffer) { | 156 if (!mojo_buffer) { |
165 callback.Run(Status::DECRYPTION_ERROR, nullptr); | 157 callback.Run(Status::kError, nullptr); |
166 return; | 158 return; |
167 } | 159 } |
168 | 160 |
169 callback.Run(static_cast<Decryptor::Status>(status), std::move(mojo_buffer)); | 161 callback.Run(status, std::move(mojo_buffer)); |
170 } | 162 } |
171 | 163 |
172 void MojoDecryptorService::OnAudioDecoderInitialized( | 164 void MojoDecryptorService::OnAudioDecoderInitialized( |
173 const InitializeAudioDecoderCallback& callback, | 165 const InitializeAudioDecoderCallback& callback, |
174 bool success) { | 166 bool success) { |
175 DVLOG(1) << __FUNCTION__ << "(" << success << ")"; | 167 DVLOG(1) << __FUNCTION__ << "(" << success << ")"; |
176 callback.Run(success); | 168 callback.Run(success); |
177 } | 169 } |
178 | 170 |
179 void MojoDecryptorService::OnVideoDecoderInitialized( | 171 void MojoDecryptorService::OnVideoDecoderInitialized( |
180 const InitializeVideoDecoderCallback& callback, | 172 const InitializeVideoDecoderCallback& callback, |
181 bool success) { | 173 bool success) { |
182 DVLOG(1) << __FUNCTION__ << "(" << success << ")"; | 174 DVLOG(1) << __FUNCTION__ << "(" << success << ")"; |
183 callback.Run(success); | 175 callback.Run(success); |
184 } | 176 } |
185 | 177 |
186 void MojoDecryptorService::OnAudioDecoded( | 178 void MojoDecryptorService::OnAudioDecoded( |
187 const DecryptAndDecodeAudioCallback& callback, | 179 const DecryptAndDecodeAudioCallback& callback, |
188 media::Decryptor::Status status, | 180 Status status, |
189 const media::Decryptor::AudioFrames& frames) { | 181 const media::Decryptor::AudioFrames& frames) { |
190 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "(" | 182 DVLOG_IF(1, status != Status::kSuccess) << __FUNCTION__ << "(" << status |
191 << status << ")"; | 183 << ")"; |
192 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__; | 184 DVLOG_IF(3, status == Status::kSuccess) << __FUNCTION__; |
193 | 185 |
194 std::vector<mojom::AudioBufferPtr> audio_buffers; | 186 std::vector<mojom::AudioBufferPtr> audio_buffers; |
195 for (const auto& frame : frames) | 187 for (const auto& frame : frames) |
196 audio_buffers.push_back(mojom::AudioBuffer::From(frame)); | 188 audio_buffers.push_back(mojom::AudioBuffer::From(frame)); |
197 | 189 |
198 callback.Run(static_cast<Decryptor::Status>(status), | 190 callback.Run(status, std::move(audio_buffers)); |
199 std::move(audio_buffers)); | |
200 } | 191 } |
201 | 192 |
202 void MojoDecryptorService::OnVideoDecoded( | 193 void MojoDecryptorService::OnVideoDecoded( |
203 const DecryptAndDecodeVideoCallback& callback, | 194 const DecryptAndDecodeVideoCallback& callback, |
204 media::Decryptor::Status status, | 195 Status status, |
205 const scoped_refptr<VideoFrame>& frame) { | 196 const scoped_refptr<VideoFrame>& frame) { |
206 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "(" | 197 DVLOG_IF(1, status != Status::kSuccess) << __FUNCTION__ << "(" << status |
207 << status << ")"; | 198 << ")"; |
208 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__; | 199 DVLOG_IF(3, status == Status::kSuccess) << __FUNCTION__; |
209 | 200 |
210 if (!frame) { | 201 if (!frame) { |
211 DCHECK_NE(status, media::Decryptor::kSuccess); | 202 DCHECK_NE(status, Status::kSuccess); |
212 callback.Run(static_cast<Decryptor::Status>(status), nullptr); | 203 callback.Run(status, nullptr); |
213 return; | 204 return; |
214 } | 205 } |
215 | 206 |
216 // If |frame| has shared memory that will be passed back, keep a reference | 207 // If |frame| has shared memory that will be passed back, keep a reference |
217 // to it until the other side is done with the memory. | 208 // to it until the other side is done with the memory. |
218 if (frame->storage_type() == VideoFrame::STORAGE_MOJO_SHARED_BUFFER) { | 209 if (frame->storage_type() == VideoFrame::STORAGE_MOJO_SHARED_BUFFER) { |
219 MojoSharedBufferVideoFrame* mojo_frame = | 210 MojoSharedBufferVideoFrame* mojo_frame = |
220 static_cast<MojoSharedBufferVideoFrame*>(frame.get()); | 211 static_cast<MojoSharedBufferVideoFrame*>(frame.get()); |
221 in_use_video_frames_.insert( | 212 in_use_video_frames_.insert( |
222 std::make_pair(mojo_frame->Handle().value(), frame)); | 213 std::make_pair(mojo_frame->Handle().value(), frame)); |
223 } | 214 } |
224 | 215 |
225 callback.Run(static_cast<Decryptor::Status>(status), | 216 callback.Run(status, mojom::VideoFrame::From(frame)); |
226 mojom::VideoFrame::From(frame)); | |
227 } | 217 } |
228 | 218 |
229 } // namespace media | 219 } // namespace media |
OLD | NEW |