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

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

Issue 1809903002: Reland "Update mojo Decryptor interface to support reusing shared memory" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add includes Created 4 years, 9 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
« no previous file with comments | « media/mojo/services/mojo_decryptor_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h>
8
9 #include <utility> 7 #include <utility>
10 8
11 #include "base/bind.h" 9 #include "base/bind.h"
12 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
13 #include "media/base/audio_decoder_config.h" 11 #include "media/base/audio_decoder_config.h"
14 #include "media/base/cdm_context.h" 12 #include "media/base/cdm_context.h"
15 #include "media/base/decoder_buffer.h" 13 #include "media/base/decoder_buffer.h"
16 #include "media/base/decryptor.h" 14 #include "media/base/decryptor.h"
17 #include "media/base/media_keys.h" 15 #include "media/base/media_keys.h"
18 #include "media/base/video_decoder_config.h" 16 #include "media/base/video_decoder_config.h"
19 #include "media/base/video_frame.h" 17 #include "media/base/video_frame.h"
20 #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"
21 #include "media/mojo/interfaces/demuxer_stream.mojom.h" 20 #include "media/mojo/interfaces/demuxer_stream.mojom.h"
22 21
23 namespace media { 22 namespace media {
24 23
25 MojoDecryptorService::MojoDecryptorService( 24 MojoDecryptorService::MojoDecryptorService(
26 const scoped_refptr<MediaKeys>& cdm, 25 const scoped_refptr<MediaKeys>& cdm,
27 mojo::InterfaceRequest<interfaces::Decryptor> request, 26 mojo::InterfaceRequest<interfaces::Decryptor> request,
28 const mojo::Closure& error_handler) 27 const mojo::Closure& error_handler)
29 : binding_(this, std::move(request)), cdm_(cdm), weak_factory_(this) { 28 : binding_(this, std::move(request)), cdm_(cdm), weak_factory_(this) {
30 DVLOG(1) << __FUNCTION__; 29 DVLOG(1) << __FUNCTION__;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 static_cast<media::Decryptor::StreamType>(stream_type)); 104 static_cast<media::Decryptor::StreamType>(stream_type));
106 } 105 }
107 106
108 void MojoDecryptorService::DeinitializeDecoder( 107 void MojoDecryptorService::DeinitializeDecoder(
109 interfaces::DemuxerStream::Type stream_type) { 108 interfaces::DemuxerStream::Type stream_type) {
110 DVLOG(1) << __FUNCTION__; 109 DVLOG(1) << __FUNCTION__;
111 decryptor_->DeinitializeDecoder( 110 decryptor_->DeinitializeDecoder(
112 static_cast<media::Decryptor::StreamType>(stream_type)); 111 static_cast<media::Decryptor::StreamType>(stream_type));
113 } 112 }
114 113
114 void MojoDecryptorService::ReleaseSharedBuffer(
115 mojo::ScopedSharedBufferHandle buffer,
116 uint64_t buffer_size) {
117 in_use_video_frames_.erase(buffer.get().value());
118 }
119
115 void MojoDecryptorService::OnDecryptDone( 120 void MojoDecryptorService::OnDecryptDone(
116 const DecryptCallback& callback, 121 const DecryptCallback& callback,
117 media::Decryptor::Status status, 122 media::Decryptor::Status status,
118 const scoped_refptr<DecoderBuffer>& buffer) { 123 const scoped_refptr<DecoderBuffer>& buffer) {
119 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "(" 124 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "("
120 << status << ")"; 125 << status << ")";
121 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__; 126 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__;
122 127
123 if (!buffer) { 128 if (!buffer) {
124 DCHECK_NE(status, media::Decryptor::kSuccess); 129 DCHECK_NE(status, media::Decryptor::kSuccess);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "(" 172 DVLOG_IF(1, status != media::Decryptor::kSuccess) << __FUNCTION__ << "("
168 << status << ")"; 173 << status << ")";
169 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__; 174 DVLOG_IF(3, status == media::Decryptor::kSuccess) << __FUNCTION__;
170 175
171 if (!frame) { 176 if (!frame) {
172 DCHECK_NE(status, media::Decryptor::kSuccess); 177 DCHECK_NE(status, media::Decryptor::kSuccess);
173 callback.Run(static_cast<Decryptor::Status>(status), nullptr); 178 callback.Run(static_cast<Decryptor::Status>(status), nullptr);
174 return; 179 return;
175 } 180 }
176 181
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.
184 if (frame->storage_type() == VideoFrame::STORAGE_MOJO_SHARED_BUFFER) {
185 MojoSharedBufferVideoFrame* mojo_frame =
186 static_cast<MojoSharedBufferVideoFrame*>(frame.get());
187 in_use_video_frames_.insert(
188 std::make_pair(mojo_frame->Handle().value(), frame));
189 }
190
177 callback.Run(static_cast<Decryptor::Status>(status), 191 callback.Run(static_cast<Decryptor::Status>(status),
178 interfaces::VideoFrame::From(frame)); 192 interfaces::VideoFrame::From(frame));
179 } 193 }
180 194
181 interfaces::DecoderBufferPtr MojoDecryptorService::TransferDecoderBuffer( 195 interfaces::DecoderBufferPtr MojoDecryptorService::TransferDecoderBuffer(
182 const scoped_refptr<DecoderBuffer>& encrypted) { 196 const scoped_refptr<DecoderBuffer>& encrypted) {
183 interfaces::DecoderBufferPtr buffer = 197 interfaces::DecoderBufferPtr buffer =
184 interfaces::DecoderBuffer::From(encrypted); 198 interfaces::DecoderBuffer::From(encrypted);
185 if (encrypted->end_of_stream()) 199 if (encrypted->end_of_stream())
186 return buffer; 200 return buffer;
(...skipping 30 matching lines...) Expand all
217 DCHECK_GT(bytes_to_read, 0u); 231 DCHECK_GT(bytes_to_read, 0u);
218 uint32_t bytes_read = bytes_to_read; 232 uint32_t bytes_read = bytes_to_read;
219 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), 233 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(),
220 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), 234 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE),
221 MOJO_RESULT_OK); 235 MOJO_RESULT_OK);
222 CHECK_EQ(bytes_to_read, bytes_read); 236 CHECK_EQ(bytes_to_read, bytes_read);
223 return media_buffer; 237 return media_buffer;
224 } 238 }
225 239
226 } // namespace media 240 } // namespace media
OLDNEW
« no previous file with comments | « 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