Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: media/mojo/services/mojo_decryptor_service.cc

Issue 1977173002: Rename media::interfaces to media::mojom. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android + chromeos files Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "media/base/audio_decoder_config.h" 11 #include "media/base/audio_decoder_config.h"
12 #include "media/base/cdm_context.h" 12 #include "media/base/cdm_context.h"
13 #include "media/base/decoder_buffer.h" 13 #include "media/base/decoder_buffer.h"
14 #include "media/base/decryptor.h" 14 #include "media/base/decryptor.h"
15 #include "media/base/media_keys.h" 15 #include "media/base/media_keys.h"
16 #include "media/base/video_decoder_config.h" 16 #include "media/base/video_decoder_config.h"
17 #include "media/base/video_frame.h" 17 #include "media/base/video_frame.h"
18 #include "media/mojo/common/media_type_converters.h" 18 #include "media/mojo/common/media_type_converters.h"
19 #include "media/mojo/common/mojo_shared_buffer_video_frame.h" 19 #include "media/mojo/common/mojo_shared_buffer_video_frame.h"
20 #include "media/mojo/interfaces/demuxer_stream.mojom.h" 20 #include "media/mojo/interfaces/demuxer_stream.mojom.h"
21 21
22 namespace media { 22 namespace media {
23 23
24 MojoDecryptorService::MojoDecryptorService( 24 MojoDecryptorService::MojoDecryptorService(
25 const scoped_refptr<MediaKeys>& cdm, 25 const scoped_refptr<MediaKeys>& cdm,
26 mojo::InterfaceRequest<interfaces::Decryptor> request, 26 mojo::InterfaceRequest<mojom::Decryptor> request,
27 const mojo::Closure& error_handler) 27 const mojo::Closure& error_handler)
28 : binding_(this, std::move(request)), cdm_(cdm), weak_factory_(this) { 28 : binding_(this, std::move(request)), cdm_(cdm), weak_factory_(this) {
29 DVLOG(1) << __FUNCTION__; 29 DVLOG(1) << __FUNCTION__;
30 decryptor_ = cdm->GetCdmContext()->GetDecryptor(); 30 decryptor_ = cdm->GetCdmContext()->GetDecryptor();
31 DCHECK(decryptor_); 31 DCHECK(decryptor_);
32 weak_this_ = weak_factory_.GetWeakPtr(); 32 weak_this_ = weak_factory_.GetWeakPtr();
33 binding_.set_connection_error_handler(error_handler); 33 binding_.set_connection_error_handler(error_handler);
34 } 34 }
35 35
36 MojoDecryptorService::~MojoDecryptorService() {} 36 MojoDecryptorService::~MojoDecryptorService() {}
37 37
38 void MojoDecryptorService::Initialize( 38 void MojoDecryptorService::Initialize(
39 mojo::ScopedDataPipeConsumerHandle receive_pipe, 39 mojo::ScopedDataPipeConsumerHandle receive_pipe,
40 mojo::ScopedDataPipeProducerHandle transmit_pipe) { 40 mojo::ScopedDataPipeProducerHandle transmit_pipe) {
41 producer_handle_ = std::move(transmit_pipe); 41 producer_handle_ = std::move(transmit_pipe);
42 consumer_handle_ = std::move(receive_pipe); 42 consumer_handle_ = std::move(receive_pipe);
43 } 43 }
44 44
45 void MojoDecryptorService::Decrypt(interfaces::DemuxerStream::Type stream_type, 45 void MojoDecryptorService::Decrypt(mojom::DemuxerStream::Type stream_type,
46 interfaces::DecoderBufferPtr encrypted, 46 mojom::DecoderBufferPtr encrypted,
47 const DecryptCallback& callback) { 47 const DecryptCallback& callback) {
48 DVLOG(3) << __FUNCTION__; 48 DVLOG(3) << __FUNCTION__;
49 decryptor_->Decrypt( 49 decryptor_->Decrypt(
50 static_cast<media::Decryptor::StreamType>(stream_type), 50 static_cast<media::Decryptor::StreamType>(stream_type),
51 ReadDecoderBuffer(std::move(encrypted)), 51 ReadDecoderBuffer(std::move(encrypted)),
52 base::Bind(&MojoDecryptorService::OnDecryptDone, weak_this_, callback)); 52 base::Bind(&MojoDecryptorService::OnDecryptDone, weak_this_, callback));
53 } 53 }
54 54
55 void MojoDecryptorService::CancelDecrypt( 55 void MojoDecryptorService::CancelDecrypt(
56 interfaces::DemuxerStream::Type stream_type) { 56 mojom::DemuxerStream::Type stream_type) {
57 DVLOG(1) << __FUNCTION__; 57 DVLOG(1) << __FUNCTION__;
58 decryptor_->CancelDecrypt( 58 decryptor_->CancelDecrypt(
59 static_cast<media::Decryptor::StreamType>(stream_type)); 59 static_cast<media::Decryptor::StreamType>(stream_type));
60 } 60 }
61 61
62 void MojoDecryptorService::InitializeAudioDecoder( 62 void MojoDecryptorService::InitializeAudioDecoder(
63 interfaces::AudioDecoderConfigPtr config, 63 mojom::AudioDecoderConfigPtr config,
64 const InitializeAudioDecoderCallback& callback) { 64 const InitializeAudioDecoderCallback& callback) {
65 DVLOG(1) << __FUNCTION__; 65 DVLOG(1) << __FUNCTION__;
66 decryptor_->InitializeAudioDecoder( 66 decryptor_->InitializeAudioDecoder(
67 config.To<AudioDecoderConfig>(), 67 config.To<AudioDecoderConfig>(),
68 base::Bind(&MojoDecryptorService::OnAudioDecoderInitialized, weak_this_, 68 base::Bind(&MojoDecryptorService::OnAudioDecoderInitialized, weak_this_,
69 callback)); 69 callback));
70 } 70 }
71 71
72 void MojoDecryptorService::InitializeVideoDecoder( 72 void MojoDecryptorService::InitializeVideoDecoder(
73 interfaces::VideoDecoderConfigPtr config, 73 mojom::VideoDecoderConfigPtr config,
74 const InitializeVideoDecoderCallback& callback) { 74 const InitializeVideoDecoderCallback& callback) {
75 DVLOG(1) << __FUNCTION__; 75 DVLOG(1) << __FUNCTION__;
76 decryptor_->InitializeVideoDecoder( 76 decryptor_->InitializeVideoDecoder(
77 config.To<VideoDecoderConfig>(), 77 config.To<VideoDecoderConfig>(),
78 base::Bind(&MojoDecryptorService::OnVideoDecoderInitialized, weak_this_, 78 base::Bind(&MojoDecryptorService::OnVideoDecoderInitialized, weak_this_,
79 callback)); 79 callback));
80 } 80 }
81 81
82 void MojoDecryptorService::DecryptAndDecodeAudio( 82 void MojoDecryptorService::DecryptAndDecodeAudio(
83 interfaces::DecoderBufferPtr encrypted, 83 mojom::DecoderBufferPtr encrypted,
84 const DecryptAndDecodeAudioCallback& callback) { 84 const DecryptAndDecodeAudioCallback& callback) {
85 DVLOG(3) << __FUNCTION__; 85 DVLOG(3) << __FUNCTION__;
86 decryptor_->DecryptAndDecodeAudio( 86 decryptor_->DecryptAndDecodeAudio(
87 ReadDecoderBuffer(std::move(encrypted)), 87 ReadDecoderBuffer(std::move(encrypted)),
88 base::Bind(&MojoDecryptorService::OnAudioDecoded, weak_this_, callback)); 88 base::Bind(&MojoDecryptorService::OnAudioDecoded, weak_this_, callback));
89 } 89 }
90 90
91 void MojoDecryptorService::DecryptAndDecodeVideo( 91 void MojoDecryptorService::DecryptAndDecodeVideo(
92 interfaces::DecoderBufferPtr encrypted, 92 mojom::DecoderBufferPtr encrypted,
93 const DecryptAndDecodeVideoCallback& callback) { 93 const DecryptAndDecodeVideoCallback& callback) {
94 DVLOG(3) << __FUNCTION__; 94 DVLOG(3) << __FUNCTION__;
95 decryptor_->DecryptAndDecodeVideo( 95 decryptor_->DecryptAndDecodeVideo(
96 ReadDecoderBuffer(std::move(encrypted)), 96 ReadDecoderBuffer(std::move(encrypted)),
97 base::Bind(&MojoDecryptorService::OnVideoDecoded, weak_this_, callback)); 97 base::Bind(&MojoDecryptorService::OnVideoDecoded, weak_this_, callback));
98 } 98 }
99 99
100 void MojoDecryptorService::ResetDecoder( 100 void MojoDecryptorService::ResetDecoder(
101 interfaces::DemuxerStream::Type stream_type) { 101 mojom::DemuxerStream::Type stream_type) {
102 DVLOG(1) << __FUNCTION__; 102 DVLOG(1) << __FUNCTION__;
103 decryptor_->ResetDecoder( 103 decryptor_->ResetDecoder(
104 static_cast<media::Decryptor::StreamType>(stream_type)); 104 static_cast<media::Decryptor::StreamType>(stream_type));
105 } 105 }
106 106
107 void MojoDecryptorService::DeinitializeDecoder( 107 void MojoDecryptorService::DeinitializeDecoder(
108 interfaces::DemuxerStream::Type stream_type) { 108 mojom::DemuxerStream::Type stream_type) {
109 DVLOG(1) << __FUNCTION__; 109 DVLOG(1) << __FUNCTION__;
110 decryptor_->DeinitializeDecoder( 110 decryptor_->DeinitializeDecoder(
111 static_cast<media::Decryptor::StreamType>(stream_type)); 111 static_cast<media::Decryptor::StreamType>(stream_type));
112 } 112 }
113 113
114 void MojoDecryptorService::ReleaseSharedBuffer( 114 void MojoDecryptorService::ReleaseSharedBuffer(
115 mojo::ScopedSharedBufferHandle buffer, 115 mojo::ScopedSharedBufferHandle buffer,
116 uint64_t buffer_size) { 116 uint64_t buffer_size) {
117 in_use_video_frames_.erase(buffer.get().value()); 117 in_use_video_frames_.erase(buffer.get().value());
118 } 118 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 150 }
151 151
152 void MojoDecryptorService::OnAudioDecoded( 152 void MojoDecryptorService::OnAudioDecoded(
153 const DecryptAndDecodeAudioCallback& callback, 153 const DecryptAndDecodeAudioCallback& callback,
154 media::Decryptor::Status status, 154 media::Decryptor::Status status,
155 const media::Decryptor::AudioFrames& frames) { 155 const media::Decryptor::AudioFrames& frames) {
156 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "(" 156 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "("
157 << status << ")"; 157 << status << ")";
158 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__; 158 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__;
159 159
160 mojo::Array<interfaces::AudioBufferPtr> audio_buffers; 160 mojo::Array<mojom::AudioBufferPtr> audio_buffers;
161 for (const auto& frame : frames) 161 for (const auto& frame : frames)
162 audio_buffers.push_back(interfaces::AudioBuffer::From(frame)); 162 audio_buffers.push_back(mojom::AudioBuffer::From(frame));
163 163
164 callback.Run(static_cast<Decryptor::Status>(status), 164 callback.Run(static_cast<Decryptor::Status>(status),
165 std::move(audio_buffers)); 165 std::move(audio_buffers));
166 } 166 }
167 167
168 void MojoDecryptorService::OnVideoDecoded( 168 void MojoDecryptorService::OnVideoDecoded(
169 const DecryptAndDecodeVideoCallback& callback, 169 const DecryptAndDecodeVideoCallback& callback,
170 media::Decryptor::Status status, 170 media::Decryptor::Status status,
171 const scoped_refptr<VideoFrame>& frame) { 171 const scoped_refptr<VideoFrame>& frame) {
172 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "(" 172 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "("
173 << status << ")"; 173 << status << ")";
174 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__; 174 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__;
175 175
176 if (!frame) { 176 if (!frame) {
177 DCHECK_NE(status, media::Decryptor::kSuccess); 177 DCHECK_NE(status, media::Decryptor::kSuccess);
178 callback.Run(static_cast<Decryptor::Status>(status), nullptr); 178 callback.Run(static_cast<Decryptor::Status>(status), nullptr);
179 return; 179 return;
180 } 180 }
181 181
182 // If |frame| has shared memory that will be passed back, keep a reference 182 // If |frame| has shared memory that will be passed back, keep a reference
183 // to it until the other side is done with the memory. 183 // to it until the other side is done with the memory.
184 if (frame->storage_type() == VideoFrame::STORAGE_MOJO_SHARED_BUFFER) { 184 if (frame->storage_type() == VideoFrame::STORAGE_MOJO_SHARED_BUFFER) {
185 MojoSharedBufferVideoFrame* mojo_frame = 185 MojoSharedBufferVideoFrame* mojo_frame =
186 static_cast<MojoSharedBufferVideoFrame*>(frame.get()); 186 static_cast<MojoSharedBufferVideoFrame*>(frame.get());
187 in_use_video_frames_.insert( 187 in_use_video_frames_.insert(
188 std::make_pair(mojo_frame->Handle().value(), frame)); 188 std::make_pair(mojo_frame->Handle().value(), frame));
189 } 189 }
190 190
191 callback.Run(static_cast<Decryptor::Status>(status), 191 callback.Run(static_cast<Decryptor::Status>(status),
192 interfaces::VideoFrame::From(frame)); 192 mojom::VideoFrame::From(frame));
193 } 193 }
194 194
195 interfaces::DecoderBufferPtr MojoDecryptorService::TransferDecoderBuffer( 195 mojom::DecoderBufferPtr MojoDecryptorService::TransferDecoderBuffer(
196 const scoped_refptr<DecoderBuffer>& encrypted) { 196 const scoped_refptr<DecoderBuffer>& encrypted) {
197 interfaces::DecoderBufferPtr buffer = 197 mojom::DecoderBufferPtr buffer = mojom::DecoderBuffer::From(encrypted);
198 interfaces::DecoderBuffer::From(encrypted);
199 if (encrypted->end_of_stream()) 198 if (encrypted->end_of_stream())
200 return buffer; 199 return buffer;
201 200
202 // Serialize the data section of the DecoderBuffer into our pipe. 201 // Serialize the data section of the DecoderBuffer into our pipe.
203 uint32_t bytes_to_write = 202 uint32_t bytes_to_write =
204 base::checked_cast<uint32_t>(encrypted->data_size()); 203 base::checked_cast<uint32_t>(encrypted->data_size());
205 DCHECK_GT(bytes_to_write, 0u); 204 DCHECK_GT(bytes_to_write, 0u);
206 uint32_t bytes_written = bytes_to_write; 205 uint32_t bytes_written = bytes_to_write;
207 CHECK_EQ(WriteDataRaw(producer_handle_.get(), encrypted->data(), 206 CHECK_EQ(WriteDataRaw(producer_handle_.get(), encrypted->data(),
208 &bytes_written, MOJO_READ_DATA_FLAG_ALL_OR_NONE), 207 &bytes_written, MOJO_READ_DATA_FLAG_ALL_OR_NONE),
209 MOJO_RESULT_OK); 208 MOJO_RESULT_OK);
210 CHECK_EQ(bytes_to_write, bytes_written); 209 CHECK_EQ(bytes_to_write, bytes_written);
211 return buffer; 210 return buffer;
212 } 211 }
213 212
214 scoped_refptr<DecoderBuffer> MojoDecryptorService::ReadDecoderBuffer( 213 scoped_refptr<DecoderBuffer> MojoDecryptorService::ReadDecoderBuffer(
215 interfaces::DecoderBufferPtr buffer) { 214 mojom::DecoderBufferPtr buffer) {
216 scoped_refptr<DecoderBuffer> media_buffer( 215 scoped_refptr<DecoderBuffer> media_buffer(
217 buffer.To<scoped_refptr<DecoderBuffer>>()); 216 buffer.To<scoped_refptr<DecoderBuffer>>());
218 if (media_buffer->end_of_stream()) 217 if (media_buffer->end_of_stream())
219 return media_buffer; 218 return media_buffer;
220 219
221 // Wait for the data to become available in the DataPipe. 220 // Wait for the data to become available in the DataPipe.
222 MojoHandleSignalsState state; 221 MojoHandleSignalsState state;
223 CHECK_EQ(MOJO_RESULT_OK, 222 CHECK_EQ(MOJO_RESULT_OK,
224 MojoWait(consumer_handle_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, 223 MojoWait(consumer_handle_.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
225 MOJO_DEADLINE_INDEFINITE, &state)); 224 MOJO_DEADLINE_INDEFINITE, &state));
226 CHECK_EQ(MOJO_HANDLE_SIGNAL_READABLE, state.satisfied_signals); 225 CHECK_EQ(MOJO_HANDLE_SIGNAL_READABLE, state.satisfied_signals);
227 226
228 // Read the inner data for the DecoderBuffer from our DataPipe. 227 // Read the inner data for the DecoderBuffer from our DataPipe.
229 uint32_t bytes_to_read = 228 uint32_t bytes_to_read =
230 base::checked_cast<uint32_t>(media_buffer->data_size()); 229 base::checked_cast<uint32_t>(media_buffer->data_size());
231 DCHECK_GT(bytes_to_read, 0u); 230 DCHECK_GT(bytes_to_read, 0u);
232 uint32_t bytes_read = bytes_to_read; 231 uint32_t bytes_read = bytes_to_read;
233 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), 232 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(),
234 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), 233 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE),
235 MOJO_RESULT_OK); 234 MOJO_RESULT_OK);
236 CHECK_EQ(bytes_to_read, bytes_read); 235 CHECK_EQ(bytes_to_read, bytes_read);
237 return media_buffer; 236 return media_buffer;
238 } 237 }
239 238
240 } // namespace media 239 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/services/mojo_decryptor_service.h ('k') | media/mojo/services/mojo_demuxer_stream_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698