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

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

Issue 1538063003: Use data pipe to pass DecoderBuffer contents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "media/base/audio_decoder_config.h" 8 #include "media/base/audio_decoder_config.h"
9 #include "media/base/cdm_context.h" 9 #include "media/base/cdm_context.h"
10 #include "media/base/decoder_buffer.h" 10 #include "media/base/decoder_buffer.h"
11 #include "media/base/decryptor.h" 11 #include "media/base/decryptor.h"
12 #include "media/base/media_keys.h" 12 #include "media/base/media_keys.h"
13 #include "media/base/video_decoder_config.h" 13 #include "media/base/video_decoder_config.h"
14 #include "media/base/video_frame.h"
14 #include "media/mojo/interfaces/demuxer_stream.mojom.h" 15 #include "media/mojo/interfaces/demuxer_stream.mojom.h"
15 #include "media/mojo/services/media_type_converters.h" 16 #include "media/mojo/services/media_type_converters.h"
16 17
17 namespace media { 18 namespace media {
18 19
19 MojoDecryptorService::MojoDecryptorService( 20 MojoDecryptorService::MojoDecryptorService(
20 const scoped_refptr<MediaKeys>& cdm, 21 const scoped_refptr<MediaKeys>& cdm,
21 mojo::InterfaceRequest<interfaces::Decryptor> request, 22 mojo::InterfaceRequest<interfaces::Decryptor> request,
22 const mojo::Closure& error_handler) 23 const mojo::Closure& error_handler)
23 : binding_(this, request.Pass()), cdm_(cdm), weak_factory_(this) { 24 : binding_(this, request.Pass()), cdm_(cdm), weak_factory_(this) {
24 decryptor_ = cdm->GetCdmContext()->GetDecryptor(); 25 decryptor_ = cdm->GetCdmContext()->GetDecryptor();
25 DCHECK(decryptor_); 26 DCHECK(decryptor_);
26 weak_this_ = weak_factory_.GetWeakPtr(); 27 weak_this_ = weak_factory_.GetWeakPtr();
27 binding_.set_connection_error_handler(error_handler); 28 binding_.set_connection_error_handler(error_handler);
28 } 29 }
29 30
30 MojoDecryptorService::~MojoDecryptorService() {} 31 MojoDecryptorService::~MojoDecryptorService() {}
31 32
33 void MojoDecryptorService::Initialize(
34 mojo::ScopedDataPipeConsumerHandle receive_pipe,
35 mojo::ScopedDataPipeProducerHandle transmit_pipe) {
36 write_pipe_ = transmit_pipe.Pass();
37 read_pipe_ = receive_pipe.Pass();
38 }
39
32 void MojoDecryptorService::Decrypt(interfaces::DemuxerStream::Type stream_type, 40 void MojoDecryptorService::Decrypt(interfaces::DemuxerStream::Type stream_type,
33 interfaces::DecoderBufferPtr encrypted, 41 interfaces::DecoderBufferPtr encrypted,
34 const DecryptCallback& callback) { 42 const DecryptCallback& callback) {
43 DVLOG(1) << __FUNCTION__;
44
45 scoped_refptr<DecoderBuffer> buffer(
46 encrypted.To<scoped_refptr<DecoderBuffer>>());
47 ReadDataFromDataPipe(buffer);
35 decryptor_->Decrypt( 48 decryptor_->Decrypt(
36 static_cast<media::Decryptor::StreamType>(stream_type), 49 static_cast<media::Decryptor::StreamType>(stream_type), buffer,
37 encrypted.To<scoped_refptr<DecoderBuffer>>(),
38 base::Bind(&MojoDecryptorService::OnDecryptDone, weak_this_, callback)); 50 base::Bind(&MojoDecryptorService::OnDecryptDone, weak_this_, callback));
39 } 51 }
40 52
41 void MojoDecryptorService::CancelDecrypt( 53 void MojoDecryptorService::CancelDecrypt(
42 interfaces::DemuxerStream::Type stream_type) { 54 interfaces::DemuxerStream::Type stream_type) {
55 DVLOG(1) << __FUNCTION__;
43 decryptor_->CancelDecrypt( 56 decryptor_->CancelDecrypt(
44 static_cast<media::Decryptor::StreamType>(stream_type)); 57 static_cast<media::Decryptor::StreamType>(stream_type));
45 } 58 }
46 59
47 void MojoDecryptorService::InitializeAudioDecoder( 60 void MojoDecryptorService::InitializeAudioDecoder(
48 interfaces::AudioDecoderConfigPtr config, 61 interfaces::AudioDecoderConfigPtr config,
49 const InitializeAudioDecoderCallback& callback) { 62 const InitializeAudioDecoderCallback& callback) {
63 DVLOG(1) << __FUNCTION__;
50 decryptor_->InitializeAudioDecoder( 64 decryptor_->InitializeAudioDecoder(
51 config.To<AudioDecoderConfig>(), 65 config.To<AudioDecoderConfig>(),
52 base::Bind(&MojoDecryptorService::OnAudioDecoderInitialized, weak_this_, 66 base::Bind(&MojoDecryptorService::OnAudioDecoderInitialized, weak_this_,
53 callback)); 67 callback));
54 } 68 }
55 69
56 void MojoDecryptorService::InitializeVideoDecoder( 70 void MojoDecryptorService::InitializeVideoDecoder(
57 interfaces::VideoDecoderConfigPtr config, 71 interfaces::VideoDecoderConfigPtr config,
58 const InitializeVideoDecoderCallback& callback) { 72 const InitializeVideoDecoderCallback& callback) {
73 DVLOG(1) << __FUNCTION__;
59 decryptor_->InitializeVideoDecoder( 74 decryptor_->InitializeVideoDecoder(
60 config.To<VideoDecoderConfig>(), 75 config.To<VideoDecoderConfig>(),
61 base::Bind(&MojoDecryptorService::OnVideoDecoderInitialized, weak_this_, 76 base::Bind(&MojoDecryptorService::OnVideoDecoderInitialized, weak_this_,
62 callback)); 77 callback));
63 } 78 }
64 79
65 void MojoDecryptorService::DecryptAndDecodeAudio( 80 void MojoDecryptorService::DecryptAndDecodeAudio(
66 interfaces::DecoderBufferPtr encrypted, 81 interfaces::DecoderBufferPtr encrypted,
67 const DecryptAndDecodeAudioCallback& callback) { 82 const DecryptAndDecodeAudioCallback& callback) {
83 DVLOG(1) << __FUNCTION__;
xhwang 2015/12/19 18:16:31 ditto about log level.
jrummell 2015/12/21 23:20:55 Done.
84 scoped_refptr<DecoderBuffer> buffer(
85 encrypted.To<scoped_refptr<DecoderBuffer>>());
86 ReadDataFromDataPipe(buffer);
68 decryptor_->DecryptAndDecodeAudio( 87 decryptor_->DecryptAndDecodeAudio(
69 encrypted.To<scoped_refptr<DecoderBuffer>>(), 88 buffer,
70 base::Bind(&MojoDecryptorService::OnAudioDecoded, weak_this_, callback)); 89 base::Bind(&MojoDecryptorService::OnAudioDecoded, weak_this_, callback));
71 } 90 }
72 91
73 void MojoDecryptorService::DecryptAndDecodeVideo( 92 void MojoDecryptorService::DecryptAndDecodeVideo(
74 interfaces::DecoderBufferPtr encrypted, 93 interfaces::DecoderBufferPtr encrypted,
75 const DecryptAndDecodeVideoCallback& callback) { 94 const DecryptAndDecodeVideoCallback& callback) {
95 DVLOG(1) << __FUNCTION__;
96 scoped_refptr<DecoderBuffer> buffer(
97 encrypted.To<scoped_refptr<DecoderBuffer>>());
98 ReadDataFromDataPipe(buffer);
76 decryptor_->DecryptAndDecodeVideo( 99 decryptor_->DecryptAndDecodeVideo(
77 encrypted.To<scoped_refptr<DecoderBuffer>>(), 100 buffer,
78 base::Bind(&MojoDecryptorService::OnVideoDecoded, weak_this_, callback)); 101 base::Bind(&MojoDecryptorService::OnVideoDecoded, weak_this_, callback));
79 } 102 }
80 103
81 void MojoDecryptorService::ResetDecoder( 104 void MojoDecryptorService::ResetDecoder(
82 interfaces::DemuxerStream::Type stream_type) { 105 interfaces::DemuxerStream::Type stream_type) {
106 DVLOG(1) << __FUNCTION__;
83 decryptor_->ResetDecoder( 107 decryptor_->ResetDecoder(
84 static_cast<media::Decryptor::StreamType>(stream_type)); 108 static_cast<media::Decryptor::StreamType>(stream_type));
85 } 109 }
86 110
87 void MojoDecryptorService::DeinitializeDecoder( 111 void MojoDecryptorService::DeinitializeDecoder(
88 interfaces::DemuxerStream::Type stream_type) { 112 interfaces::DemuxerStream::Type stream_type) {
113 DVLOG(1) << __FUNCTION__;
89 decryptor_->DeinitializeDecoder( 114 decryptor_->DeinitializeDecoder(
90 static_cast<media::Decryptor::StreamType>(stream_type)); 115 static_cast<media::Decryptor::StreamType>(stream_type));
91 } 116 }
92 117
93 void MojoDecryptorService::OnDecryptDone( 118 void MojoDecryptorService::OnDecryptDone(
94 const DecryptCallback& callback, 119 const DecryptCallback& callback,
95 media::Decryptor::Status status, 120 media::Decryptor::Status status,
96 const scoped_refptr<DecoderBuffer>& buffer) { 121 const scoped_refptr<DecoderBuffer>& buffer) {
97 DVLOG(1) << __FUNCTION__ << "(" << status << ")"; 122 DVLOG(1) << __FUNCTION__ << "(" << status << ")";
123 if (!buffer) {
124 DCHECK_NE(status, media::Decryptor::kSuccess);
125 callback.Run(static_cast<Decryptor::Status>(status), nullptr);
126 return;
127 }
128
129 DVLOG(3) << " buffer: " << buffer->AsHumanReadableString();
130 WriteDataIntoDataPipe(buffer);
98 callback.Run(static_cast<Decryptor::Status>(status), 131 callback.Run(static_cast<Decryptor::Status>(status),
99 interfaces::DecoderBuffer::From(buffer)); 132 interfaces::DecoderBuffer::From(buffer));
100 } 133 }
101 134
102 void MojoDecryptorService::OnAudioDecoderInitialized( 135 void MojoDecryptorService::OnAudioDecoderInitialized(
103 const InitializeAudioDecoderCallback& callback, 136 const InitializeAudioDecoderCallback& callback,
104 bool success) { 137 bool success) {
105 DVLOG(1) << __FUNCTION__ << "(" << success << ")"; 138 DVLOG(1) << __FUNCTION__ << "(" << success << ")";
106 callback.Run(success); 139 callback.Run(success);
107 } 140 }
(...skipping 16 matching lines...) Expand all
124 audio_buffers.push_back(interfaces::AudioBuffer::From(frame).Pass()); 157 audio_buffers.push_back(interfaces::AudioBuffer::From(frame).Pass());
125 158
126 callback.Run(static_cast<Decryptor::Status>(status), audio_buffers.Pass()); 159 callback.Run(static_cast<Decryptor::Status>(status), audio_buffers.Pass());
127 } 160 }
128 161
129 void MojoDecryptorService::OnVideoDecoded( 162 void MojoDecryptorService::OnVideoDecoded(
130 const DecryptAndDecodeVideoCallback& callback, 163 const DecryptAndDecodeVideoCallback& callback,
131 media::Decryptor::Status status, 164 media::Decryptor::Status status,
132 const scoped_refptr<VideoFrame>& frame) { 165 const scoped_refptr<VideoFrame>& frame) {
133 DVLOG(1) << __FUNCTION__ << "(" << status << ")"; 166 DVLOG(1) << __FUNCTION__ << "(" << status << ")";
167 if (!frame) {
168 DCHECK_NE(status, media::Decryptor::kSuccess);
169 callback.Run(static_cast<Decryptor::Status>(status), nullptr);
170 return;
171 }
134 172
173 DVLOG(3) << " video_frame: " << frame->AsHumanReadableString();
135 callback.Run(static_cast<Decryptor::Status>(status), 174 callback.Run(static_cast<Decryptor::Status>(status),
136 interfaces::VideoFrame::From(frame).Pass()); 175 interfaces::VideoFrame::From(frame).Pass());
137 } 176 }
138 177
178 void MojoDecryptorService::WriteDataIntoDataPipe(
179 const scoped_refptr<DecoderBuffer>& buffer) {
180 if (!buffer->end_of_stream()) {
xhwang 2015/12/19 18:16:31 ditto
jrummell 2015/12/21 23:20:55 Done.
181 // Serialize the data section of the DecoderBuffer into our pipe.
182 uint32_t num_bytes = buffer->data_size();
183 DCHECK_GT(num_bytes, 0u);
184 CHECK_EQ(WriteDataRaw(write_pipe_.get(), buffer->data(), &num_bytes,
185 MOJO_READ_DATA_FLAG_ALL_OR_NONE),
186 MOJO_RESULT_OK);
187 CHECK_EQ(num_bytes, static_cast<uint32_t>(buffer->data_size()));
188 }
189 }
190
191 void MojoDecryptorService::ReadDataFromDataPipe(
192 const scoped_refptr<DecoderBuffer>& buffer) {
193 if (!buffer->end_of_stream()) {
194 // Read the inner data for the DecoderBuffer from our DataPipe.
195 uint32_t num_bytes = buffer->data_size();
196 DCHECK_GT(num_bytes, 0u);
197 CHECK_EQ(ReadDataRaw(read_pipe_.get(), buffer->writable_data(), &num_bytes,
198 MOJO_READ_DATA_FLAG_ALL_OR_NONE),
199 MOJO_RESULT_OK);
200 CHECK_EQ(num_bytes, static_cast<uint32_t>(buffer->data_size()));
201 }
202 }
203
139 } // namespace media 204 } // namespace media
OLDNEW
« media/mojo/services/mojo_decryptor.cc ('K') | « media/mojo/services/mojo_decryptor_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698