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

Side by Side Diff: media/cdm/simple_cdm_allocator_unittest.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.cc ('k') | media/cdm/simple_cdm_buffer.h » ('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 <stdint.h>
6
7 #include "base/macros.h"
8 #include "media/base/video_frame.h"
9 #include "media/cdm/api/content_decryption_module.h"
10 #include "media/cdm/cdm_helpers.h"
11 #include "media/cdm/simple_cdm_allocator.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace media {
16
17 class TestCdmBuffer : public cdm::Buffer {
18 public:
19 static TestCdmBuffer* Create(uint32_t capacity) {
20 return new TestCdmBuffer(capacity);
21 }
22
23 // cdm::Buffer implementation.
24 void Destroy() {
25 DestroyCalled();
26 delete this;
27 }
28 uint32_t Capacity() const { return buffer_.size(); }
29 uint8_t* Data() { return buffer_.data(); }
30 void SetSize(uint32_t size) { size_ = size > Capacity() ? 0 : size; }
31 uint32_t Size() const { return size_; }
32
33 private:
34 TestCdmBuffer(uint32_t capacity) : buffer_(capacity), size_(0) {
35 // Verify that Destroy() is called on this object.
36 EXPECT_CALL(*this, DestroyCalled());
37 }
38 ~TestCdmBuffer() final {}
39
40 MOCK_METHOD0(DestroyCalled, void());
41
42 std::vector<uint8_t> buffer_;
43 uint32_t size_;
44
45 DISALLOW_COPY_AND_ASSIGN(TestCdmBuffer);
46 };
47
48 class SimpleCdmAllocatorTest : public testing::Test {
49 public:
50 SimpleCdmAllocatorTest() {}
51 ~SimpleCdmAllocatorTest() override {}
52
53 protected:
54 SimpleCdmAllocator allocator_;
55
56 private:
57 DISALLOW_COPY_AND_ASSIGN(SimpleCdmAllocatorTest);
58 };
59
60 TEST_F(SimpleCdmAllocatorTest, CreateCdmBuffer) {
61 cdm::Buffer* buffer = allocator_.CreateCdmBuffer(100);
62 EXPECT_GE(buffer->Capacity(), 100u);
63 buffer->Destroy();
64 }
65
66 TEST_F(SimpleCdmAllocatorTest, CreateCdmVideoFrame) {
67 scoped_ptr<VideoFrameImpl> video_frame = allocator_.CreateCdmVideoFrame();
68 EXPECT_EQ(video_frame->FrameBuffer(), nullptr);
69 video_frame->SetFrameBuffer(TestCdmBuffer::Create(100));
70 EXPECT_NE(video_frame->FrameBuffer(), nullptr);
71
72 // Releasing |video_frame| should free the cdm::Buffer created above
73 // (verified by the mock method TestCdmBuffer::DestroyCalled).
74 video_frame.reset();
75 }
76
77 TEST_F(SimpleCdmAllocatorTest, TransformToVideoFrame) {
78 // For this test we need to pretend we have valid video data. So create
79 // a small video frame of size 2x2.
80 gfx::Size size(2, 2);
81 size_t memory_needed = VideoFrame::AllocationSize(PIXEL_FORMAT_YV12, size);
82
83 // Now create a VideoFrameImpl.
84 scoped_ptr<VideoFrameImpl> video_frame = allocator_.CreateCdmVideoFrame();
85 EXPECT_EQ(video_frame->FrameBuffer(), nullptr);
86
87 // Fill VideoFrameImpl as if it was a small video frame.
88 video_frame->SetFormat(cdm::kI420);
89 video_frame->SetSize(cdm::Size(size.width(), size.height()));
90 video_frame->SetFrameBuffer(TestCdmBuffer::Create(memory_needed));
91 video_frame->FrameBuffer()->SetSize(memory_needed);
92
93 // Now transform VideoFrameImpl to a VideoFrame, and make sure that
94 // FrameBuffer() is transferred to the new object.
95 EXPECT_NE(video_frame->FrameBuffer(), nullptr);
96 scoped_refptr<media::VideoFrame> transformed_frame =
97 video_frame->TransformToVideoFrame(size);
98 EXPECT_EQ(video_frame->FrameBuffer(), nullptr);
99
100 // Releasing |transformed_frame| should free the cdm::Buffer created above
101 // (verified by the mock method TestCdmBuffer::DestroyCalled).
102 transformed_frame = nullptr;
103 }
104
105 } // namespace media
OLDNEW
« no previous file with comments | « media/cdm/simple_cdm_allocator.cc ('k') | media/cdm/simple_cdm_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698