1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
media / gpu / mac / video_toolbox_vp9_accelerator_unittest.cc [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "media/base/media_util.h"
#include "media/gpu/codec_picture.h"
#include "media/gpu/mac/video_toolbox_vp9_accelerator.h"
#include "media/gpu/vp9_picture.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::_;
using testing::ElementsAre;
using testing::SaveArg;
namespace media {
class VideoToolboxVP9AcceleratorTest : public testing::Test {
public:
VideoToolboxVP9AcceleratorTest() = default;
~VideoToolboxVP9AcceleratorTest() override = default;
protected:
MOCK_METHOD3(OnDecode,
void(base::apple::ScopedCFTypeRef<CMSampleBufferRef>,
VideoToolboxDecompressionSessionMetadata,
scoped_refptr<CodecPicture>));
MOCK_METHOD1(OnOutput, void(scoped_refptr<CodecPicture>));
std::unique_ptr<VideoToolboxVP9Accelerator> accelerator_{
std::make_unique<VideoToolboxVP9Accelerator>(
std::make_unique<NullMediaLog>(),
std::nullopt,
base::BindRepeating(&VideoToolboxVP9AcceleratorTest::OnDecode,
base::Unretained(this)),
base::BindRepeating(&VideoToolboxVP9AcceleratorTest::OnOutput,
base::Unretained(this)))};
};
TEST_F(VideoToolboxVP9AcceleratorTest, Construct) {}
TEST_F(VideoToolboxVP9AcceleratorTest, DecodeRaw) {
const Vp9SegmentationParams segm_params = {0};
const Vp9LoopFilterParams lf_params = {0};
const Vp9ReferenceFrameVector reference_frames;
constexpr uint8_t frame_data[] = {0x01};
scoped_refptr<VP9Picture> pic = accelerator_->CreateVP9Picture();
pic->frame_hdr = std::make_unique<Vp9FrameHeader>();
pic->frame_hdr->show_frame = true;
pic->frame_hdr->data = base::span(frame_data);
// Save the resulting sample.
base::apple::ScopedCFTypeRef<CMSampleBufferRef> sample;
EXPECT_CALL(*this, OnDecode(_, _, _)).WillOnce(SaveArg<0>(&sample));
EXPECT_CALL(*this, OnOutput(_));
accelerator_->SubmitDecode(pic, segm_params, lf_params, reference_frames);
accelerator_->OutputPicture(pic);
// Verify `sample`.
CMBlockBufferRef buf = CMSampleBufferGetDataBuffer(sample.get());
std::vector<uint8_t> data(CMBlockBufferGetDataLength(buf));
CMBlockBufferCopyDataBytes(buf, 0, CMBlockBufferGetDataLength(buf),
data.data());
EXPECT_THAT(data, ElementsAre(0x01));
}
TEST_F(VideoToolboxVP9AcceleratorTest, DecodeSuperframe) {
const Vp9SegmentationParams segm_params = {0};
const Vp9LoopFilterParams lf_params = {0};
const Vp9ReferenceFrameVector reference_frames;
constexpr uint8_t frame_data1[] = {0x01};
constexpr uint8_t frame_data2[] = {0x02};
scoped_refptr<VP9Picture> pic1 = accelerator_->CreateVP9Picture();
pic1->frame_hdr = std::make_unique<Vp9FrameHeader>();
pic1->frame_hdr->data = base::span(frame_data1);
scoped_refptr<VP9Picture> pic2 = accelerator_->CreateVP9Picture();
pic2->frame_hdr = std::make_unique<Vp9FrameHeader>();
pic2->frame_hdr->show_existing_frame = true;
pic2->frame_hdr->data = base::span(frame_data2);
// Save the resulting sample.
base::apple::ScopedCFTypeRef<CMSampleBufferRef> sample;
EXPECT_CALL(*this, OnDecode(_, _, _)).WillOnce(SaveArg<0>(&sample));
EXPECT_CALL(*this, OnOutput(_));
accelerator_->SubmitDecode(pic1, segm_params, lf_params, reference_frames);
accelerator_->OutputPicture(pic2);
// Verify `sample`.
CMBlockBufferRef buf = CMSampleBufferGetDataBuffer(sample.get());
std::vector<uint8_t> data(CMBlockBufferGetDataLength(buf));
CMBlockBufferCopyDataBytes(buf, 0, CMBlockBufferGetDataLength(buf),
data.data());
EXPECT_THAT(data, ElementsAre(0x01, // frame_data1
0x02, // frame_data2
0b11011001, // header
0x01, 0x00, 0x00, 0x00, // frame_data1 size
0x01, 0x00, 0x00, 0x00, // frame_data2 size
0b11011001 // header
));
}
} // namespace media