| 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.h" | 5 #include "media/mojo/services/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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
| 14 #include "media/base/audio_buffer.h" | 14 #include "media/base/audio_buffer.h" |
| 15 #include "media/base/decoder_buffer.h" | 15 #include "media/base/decoder_buffer.h" |
| 16 #include "media/base/video_frame.h" | 16 #include "media/base/video_frame.h" |
| 17 #include "media/mojo/common/media_type_converters.h" | 17 #include "media/mojo/common/media_type_converters.h" |
| 18 #include "media/mojo/common/mojo_shared_buffer_video_frame.h" |
| 18 #include "media/mojo/interfaces/decryptor.mojom.h" | 19 #include "media/mojo/interfaces/decryptor.mojom.h" |
| 19 #include "mojo/shell/public/cpp/connect.h" | 20 #include "mojo/shell/public/cpp/connect.h" |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| 22 | 23 |
| 23 MojoDecryptor::MojoDecryptor(interfaces::DecryptorPtr remote_decryptor) | 24 MojoDecryptor::MojoDecryptor(interfaces::DecryptorPtr remote_decryptor) |
| 24 : remote_decryptor_(std::move(remote_decryptor)), weak_factory_(this) { | 25 : remote_decryptor_(std::move(remote_decryptor)), weak_factory_(this) { |
| 25 DVLOG(1) << __FUNCTION__; | 26 DVLOG(1) << __FUNCTION__; |
| 26 CreateDataPipes(); | 27 CreateDataPipes(); |
| 27 } | 28 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 << __FUNCTION__ << "(" << status << ")"; | 177 << __FUNCTION__ << "(" << status << ")"; |
| 177 DVLOG_IF(3, status == interfaces::Decryptor::Status::SUCCESS) << __FUNCTION__; | 178 DVLOG_IF(3, status == interfaces::Decryptor::Status::SUCCESS) << __FUNCTION__; |
| 178 DCHECK(thread_checker_.CalledOnValidThread()); | 179 DCHECK(thread_checker_.CalledOnValidThread()); |
| 179 | 180 |
| 180 if (video_frame.is_null()) { | 181 if (video_frame.is_null()) { |
| 181 video_decode_cb.Run(static_cast<Decryptor::Status>(status), nullptr); | 182 video_decode_cb.Run(static_cast<Decryptor::Status>(status), nullptr); |
| 182 return; | 183 return; |
| 183 } | 184 } |
| 184 | 185 |
| 185 scoped_refptr<VideoFrame> frame(video_frame.To<scoped_refptr<VideoFrame>>()); | 186 scoped_refptr<VideoFrame> frame(video_frame.To<scoped_refptr<VideoFrame>>()); |
| 187 |
| 188 // If using shared memory, ensure that ReleaseSharedBuffer() is called when |
| 189 // |frame| is destroyed. |
| 190 if (frame->storage_type() == VideoFrame::STORAGE_MOJO_SHARED_BUFFER) { |
| 191 MojoSharedBufferVideoFrame* mojo_frame = |
| 192 static_cast<MojoSharedBufferVideoFrame*>(frame.get()); |
| 193 mojo_frame->SetMojoSharedBufferDoneCB(base::Bind( |
| 194 &MojoDecryptor::ReleaseSharedBuffer, weak_factory_.GetWeakPtr())); |
| 195 } |
| 196 |
| 186 video_decode_cb.Run(static_cast<Decryptor::Status>(status), frame); | 197 video_decode_cb.Run(static_cast<Decryptor::Status>(status), frame); |
| 187 } | 198 } |
| 188 | 199 |
| 200 void MojoDecryptor::ReleaseSharedBuffer(mojo::ScopedSharedBufferHandle buffer, |
| 201 size_t buffer_size) { |
| 202 DVLOG(1) << __FUNCTION__; |
| 203 DCHECK(thread_checker_.CalledOnValidThread()); |
| 204 |
| 205 remote_decryptor_->ReleaseSharedBuffer(std::move(buffer), buffer_size); |
| 206 } |
| 207 |
| 189 void MojoDecryptor::CreateDataPipes() { | 208 void MojoDecryptor::CreateDataPipes() { |
| 190 // Allocate DataPipe size based on video content. Video can get quite large; | 209 // Allocate DataPipe size based on video content. Video can get quite large; |
| 191 // at 4K, VP9 delivers packets which are ~1MB in size; so allow for 50% | 210 // at 4K, VP9 delivers packets which are ~1MB in size; so allow for 50% |
| 192 // headroom. | 211 // headroom. |
| 193 MojoCreateDataPipeOptions options; | 212 MojoCreateDataPipeOptions options; |
| 194 options.struct_size = sizeof(MojoCreateDataPipeOptions); | 213 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
| 195 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | 214 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
| 196 options.element_num_bytes = 1; | 215 options.element_num_bytes = 1; |
| 197 options.capacity_num_bytes = 1.5 * (1024 * 1024); | 216 options.capacity_num_bytes = 1.5 * (1024 * 1024); |
| 198 | 217 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); | 263 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); |
| 245 DCHECK_GT(num_bytes, 0u); | 264 DCHECK_GT(num_bytes, 0u); |
| 246 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), | 265 CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(), |
| 247 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 266 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
| 248 MOJO_RESULT_OK); | 267 MOJO_RESULT_OK); |
| 249 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); | 268 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); |
| 250 return media_buffer; | 269 return media_buffer; |
| 251 } | 270 } |
| 252 | 271 |
| 253 } // namespace media | 272 } // namespace media |
| OLD | NEW |