Chromium Code Reviews| Index: media/cdm/simple_cdm_allocator.cc |
| diff --git a/media/cdm/simple_cdm_allocator.cc b/media/cdm/simple_cdm_allocator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d489e050f1204c85b20c3f51e1f79efadd31d2e3 |
| --- /dev/null |
| +++ b/media/cdm/simple_cdm_allocator.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/cdm/simple_cdm_allocator.h" |
| + |
| +#include "media/base/video_frame.h" |
| +#include "media/cdm/cdm_helpers.h" |
| +#include "media/cdm/simple_cdm_buffer.h" |
| +#include "ui/gfx/geometry/rect.h" |
| +#include "ui/gfx/geometry/size.h" |
| + |
| +namespace media { |
| + |
| +class SimpleCdmVideoFrame : public VideoFrameImpl { |
|
xhwang
2016/02/12 08:45:30
Put this in an anonymous namespace.
jrummell
2016/02/12 23:14:20
Done.
|
| + public: |
| + SimpleCdmVideoFrame() {} |
| + ~SimpleCdmVideoFrame() final {} |
| + |
| + // VideoFrameImpl implementation. |
| + scoped_refptr<media::VideoFrame> CreateVideoFrame( |
| + gfx::Size natural_size) override { |
|
xhwang
2016/02/12 08:45:30
s/override/final to be consistent
jrummell
2016/02/12 23:14:20
Done.
|
| + DCHECK(FrameBuffer()); |
| + |
| + SimpleCdmBuffer* buffer = static_cast<SimpleCdmBuffer*>(FrameBuffer()); |
| + gfx::Size frame_size(Size().width, Size().height); |
| + scoped_refptr<media::VideoFrame> frame = |
| + media::VideoFrame::WrapExternalYuvData( |
| + PIXEL_FORMAT_YV12, frame_size, gfx::Rect(frame_size), natural_size, |
| + Stride(kYPlane), Stride(kUPlane), Stride(kVPlane), |
| + buffer->Data() + PlaneOffset(kYPlane), |
| + buffer->Data() + PlaneOffset(kUPlane), |
| + buffer->Data() + PlaneOffset(kVPlane), |
| + base::TimeDelta::FromMicroseconds(Timestamp())); |
| + |
| + // The FrameBuffer needs to remain around until |frame| is destroyed. |
| + frame->AddDestructionObserver( |
| + base::Bind(&SimpleCdmBuffer::Destroy, base::Unretained(buffer))); |
|
xhwang
2016/02/12 08:45:30
This is a little bit tricky. Can we add a unit tes
jrummell
2016/02/12 23:14:20
Done.
|
| + |
| + // Clear FrameBuffer so that SimpleCdmVideoFrame no longer has a reference |
| + // to it. |
| + SetFrameBuffer(nullptr); |
| + return frame; |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(SimpleCdmVideoFrame); |
| +}; |
| + |
| +SimpleCdmAllocator::SimpleCdmAllocator() {} |
| + |
| +SimpleCdmAllocator::~SimpleCdmAllocator() {} |
| + |
| +cdm::Buffer* SimpleCdmAllocator::Allocate(uint32_t capacity) { |
| + if (!capacity) |
| + return nullptr; |
| + |
| + return SimpleCdmBuffer::Create(capacity); |
| +} |
| + |
| +scoped_ptr<VideoFrameImpl> SimpleCdmAllocator::CreateCdmVideoFrame() { |
| + return make_scoped_ptr(new SimpleCdmVideoFrame()); |
| +} |
| + |
| +} // namespace media |