OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/cdm/simple_cdm_buffer_allocator.h" |
| 6 |
| 7 #include "media/base/video_frame.h" |
| 8 #include "media/cdm/cdm_video_frame.h" |
| 9 #include "media/cdm/simple_cdm_buffer.h" |
| 10 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/geometry/size.h" |
| 12 |
| 13 namespace media { |
| 14 |
| 15 class SimpleCdmVideoFrame : public CdmVideoFrame { |
| 16 public: |
| 17 SimpleCdmVideoFrame() {} |
| 18 ~SimpleCdmVideoFrame() final {} |
| 19 |
| 20 // CdmVideoFrame implementation. |
| 21 scoped_refptr<media::VideoFrame> CreateVideoFrame( |
| 22 gfx::Size natural_size) override { |
| 23 SimpleCdmBuffer* buffer = static_cast<SimpleCdmBuffer*>(FrameBuffer()); |
| 24 gfx::Size frame_size(Size().width, Size().height); |
| 25 scoped_refptr<media::VideoFrame> frame = |
| 26 media::VideoFrame::WrapExternalYuvData( |
| 27 PIXEL_FORMAT_YV12, frame_size, gfx::Rect(frame_size), natural_size, |
| 28 Stride(CdmVideoFrame::kYPlane), Stride(CdmVideoFrame::kUPlane), |
| 29 Stride(CdmVideoFrame::kVPlane), |
| 30 buffer->Data() + PlaneOffset(CdmVideoFrame::kYPlane), |
| 31 buffer->Data() + PlaneOffset(CdmVideoFrame::kUPlane), |
| 32 buffer->Data() + PlaneOffset(CdmVideoFrame::kVPlane), |
| 33 base::TimeDelta::FromMicroseconds(Timestamp())); |
| 34 |
| 35 // The FrameBuffer needs to remain around until |frame| is destroyed. |
| 36 frame->AddDestructionObserver( |
| 37 base::Bind(&SimpleCdmBuffer::Destroy, base::Unretained(buffer))); |
| 38 return frame; |
| 39 } |
| 40 |
| 41 private: |
| 42 DISALLOW_COPY_AND_ASSIGN(SimpleCdmVideoFrame); |
| 43 }; |
| 44 |
| 45 SimpleCdmBufferAllocator::SimpleCdmBufferAllocator() {} |
| 46 |
| 47 SimpleCdmBufferAllocator::~SimpleCdmBufferAllocator() {} |
| 48 |
| 49 scoped_refptr<CdmBuffer> SimpleCdmBufferAllocator::Allocate(uint32_t capacity) { |
| 50 if (!capacity) |
| 51 return nullptr; |
| 52 |
| 53 return SimpleCdmBuffer::Create(this, capacity); |
| 54 } |
| 55 |
| 56 void SimpleCdmBufferAllocator::Release(scoped_refptr<CdmBuffer> buffer) { |
| 57 // No caching of memory in this simple implementation, so |buffer| is |
| 58 // simply released. |
| 59 } |
| 60 |
| 61 scoped_ptr<CdmVideoFrame> SimpleCdmBufferAllocator::CreateCdmVideoFrame() { |
| 62 scoped_ptr<CdmVideoFrame> frame(new SimpleCdmVideoFrame()); |
| 63 return frame; |
| 64 } |
| 65 |
| 66 } // namespace media |
OLD | NEW |