| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_cdm_allocator.h" | 5 #include "media/mojo/services/mojo_cdm_allocator.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
| 13 #include "base/numerics/safe_math.h" | 13 #include "base/numerics/safe_math.h" |
| 14 #include "media/cdm/api/content_decryption_module.h" | 14 #include "media/cdm/api/content_decryption_module.h" |
| 15 #include "media/cdm/cdm_helpers.h" | 15 #include "media/cdm/cdm_helpers.h" |
| 16 #include "media/cdm/simple_cdm_buffer.h" | |
| 17 #include "media/mojo/common/mojo_shared_buffer_video_frame.h" | 16 #include "media/mojo/common/mojo_shared_buffer_video_frame.h" |
| 18 #include "mojo/public/cpp/system/buffer.h" | 17 #include "mojo/public/cpp/system/buffer.h" |
| 19 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 20 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 21 | 20 |
| 22 namespace media { | 21 namespace media { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 typedef base::Callback<void(mojo::ScopedSharedBufferHandle buffer, | 25 typedef base::Callback<void(mojo::ScopedSharedBufferHandle buffer, |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 195 |
| 197 // Ownership of the SharedBufferHandle is passed to MojoCdmBuffer. When it is | 196 // Ownership of the SharedBufferHandle is passed to MojoCdmBuffer. When it is |
| 198 // done with the memory, it must call AddBufferToAvailableMap() to make the | 197 // done with the memory, it must call AddBufferToAvailableMap() to make the |
| 199 // memory available for another MojoCdmBuffer. | 198 // memory available for another MojoCdmBuffer. |
| 200 return MojoCdmBuffer::Create( | 199 return MojoCdmBuffer::Create( |
| 201 std::move(buffer), capacity, | 200 std::move(buffer), capacity, |
| 202 base::Bind(&MojoCdmAllocator::AddBufferToAvailableMap, | 201 base::Bind(&MojoCdmAllocator::AddBufferToAvailableMap, |
| 203 weak_ptr_factory_.GetWeakPtr())); | 202 weak_ptr_factory_.GetWeakPtr())); |
| 204 } | 203 } |
| 205 | 204 |
| 206 // Creates a new SimpleCdmVideoFrame on every request. | 205 // Creates a new MojoCdmVideoFrame on every request. |
| 207 std::unique_ptr<VideoFrameImpl> MojoCdmAllocator::CreateCdmVideoFrame() { | 206 std::unique_ptr<VideoFrameImpl> MojoCdmAllocator::CreateCdmVideoFrame() { |
| 208 DCHECK(thread_checker_.CalledOnValidThread()); | 207 DCHECK(thread_checker_.CalledOnValidThread()); |
| 209 return base::WrapUnique(new MojoCdmVideoFrame( | 208 return base::WrapUnique(new MojoCdmVideoFrame( |
| 210 base::Bind(&MojoCdmAllocator::AddBufferToAvailableMap, | 209 base::Bind(&MojoCdmAllocator::AddBufferToAvailableMap, |
| 211 weak_ptr_factory_.GetWeakPtr()))); | 210 weak_ptr_factory_.GetWeakPtr()))); |
| 212 } | 211 } |
| 213 | 212 |
| 214 mojo::ScopedSharedBufferHandle MojoCdmAllocator::AllocateNewBuffer( | 213 mojo::ScopedSharedBufferHandle MojoCdmAllocator::AllocateNewBuffer( |
| 215 size_t* capacity) { | 214 size_t* capacity) { |
| 216 DCHECK(thread_checker_.CalledOnValidThread()); | 215 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 MojoHandle MojoCdmAllocator::GetHandleForTesting(cdm::Buffer* buffer) { | 252 MojoHandle MojoCdmAllocator::GetHandleForTesting(cdm::Buffer* buffer) { |
| 254 MojoCdmBuffer* mojo_buffer = static_cast<MojoCdmBuffer*>(buffer); | 253 MojoCdmBuffer* mojo_buffer = static_cast<MojoCdmBuffer*>(buffer); |
| 255 return mojo_buffer->Handle().value(); | 254 return mojo_buffer->Handle().value(); |
| 256 } | 255 } |
| 257 | 256 |
| 258 size_t MojoCdmAllocator::GetAvailableBufferCountForTesting() { | 257 size_t MojoCdmAllocator::GetAvailableBufferCountForTesting() { |
| 259 return available_buffers_.size(); | 258 return available_buffers_.size(); |
| 260 } | 259 } |
| 261 | 260 |
| 262 } // namespace media | 261 } // namespace media |
| OLD | NEW |