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

Side by Side Diff: media/cdm/simple_cdm_allocator.cc

Issue 1673383002: Add allocator interface for use by cdm_adapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add MEDIA_CDM_EXPORT for Windows Created 4 years, 10 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/cdm/simple_cdm_allocator.h ('k') | media/cdm/simple_cdm_allocator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_allocator.h"
6
7 #include "media/base/video_frame.h"
8 #include "media/cdm/cdm_helpers.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 namespace {
16
17 class SimpleCdmVideoFrame : public VideoFrameImpl {
18 public:
19 SimpleCdmVideoFrame() {}
20 ~SimpleCdmVideoFrame() final {}
21
22 // VideoFrameImpl implementation.
23 scoped_refptr<media::VideoFrame> TransformToVideoFrame(
24 gfx::Size natural_size) final {
25 DCHECK(FrameBuffer());
26
27 cdm::Buffer* buffer = FrameBuffer();
28 gfx::Size frame_size(Size().width, Size().height);
29 scoped_refptr<media::VideoFrame> frame =
30 media::VideoFrame::WrapExternalYuvData(
31 PIXEL_FORMAT_YV12, frame_size, gfx::Rect(frame_size), natural_size,
32 Stride(kYPlane), Stride(kUPlane), Stride(kVPlane),
33 buffer->Data() + PlaneOffset(kYPlane),
34 buffer->Data() + PlaneOffset(kUPlane),
35 buffer->Data() + PlaneOffset(kVPlane),
36 base::TimeDelta::FromMicroseconds(Timestamp()));
37
38 // The FrameBuffer needs to remain around until |frame| is destroyed.
39 frame->AddDestructionObserver(
40 base::Bind(&cdm::Buffer::Destroy, base::Unretained(buffer)));
41
42 // Clear FrameBuffer so that SimpleCdmVideoFrame no longer has a reference
43 // to it.
44 SetFrameBuffer(nullptr);
45 return frame;
46 }
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(SimpleCdmVideoFrame);
50 };
51
52 } // namespace
53
54 SimpleCdmAllocator::SimpleCdmAllocator() {}
55
56 SimpleCdmAllocator::~SimpleCdmAllocator() {}
57
58 // Creates a new SimpleCdmBuffer on every request. It does not keep track of
59 // the memory allocated, so the caller is responsible for calling Destroy()
60 // on the buffer when it is no longer needed.
61 cdm::Buffer* SimpleCdmAllocator::CreateCdmBuffer(uint32_t capacity) {
62 if (!capacity)
63 return nullptr;
64
65 return SimpleCdmBuffer::Create(capacity);
66 }
67
68 // Creates a new SimpleCdmVideoFrame on every request.
69 scoped_ptr<VideoFrameImpl> SimpleCdmAllocator::CreateCdmVideoFrame() {
70 return make_scoped_ptr(new SimpleCdmVideoFrame());
71 }
72
73 } // namespace media
OLDNEW
« no previous file with comments | « media/cdm/simple_cdm_allocator.h ('k') | media/cdm/simple_cdm_allocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698