aboutsummaryrefslogtreecommitdiff
path: root/components/VideoFrame.cpp
blob: b7481ad2bf04cd5b0ccc555bb51b40dab4c91e6f (plain)
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
// Copyright 2020 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.

//#define LOG_NDEBUG 0
#define LOG_TAG "VideoFrame"

#include <v4l2_codec2/components/VideoFrame.h>

#include <C2AllocatorGralloc.h>
#include <log/log.h>

namespace android {

// static
std::unique_ptr<VideoFrame> VideoFrame::Create(std::shared_ptr<C2GraphicBlock> block) {
    if (!block) return nullptr;

    std::vector<int> fds;
    const C2Handle* const handle = block->handle();
    for (int i = 0; i < handle->numFds; i++) {
        fds.emplace_back(handle->data[i]);
    }

    return std::unique_ptr<VideoFrame>(new VideoFrame(std::move(block), std::move(fds)));
}

VideoFrame::VideoFrame(std::shared_ptr<C2GraphicBlock> block, std::vector<int> fds)
      : mGraphicBlock(std::move(block)), mFds(fds) {}

VideoFrame::~VideoFrame() = default;

const std::vector<int>& VideoFrame::getFDs() const {
    return mFds;
}

void VideoFrame::setVisibleRect(const Rect& visibleRect) {
    mVisibleRect = visibleRect;
}

const Rect& VideoFrame::getVisibleRect() const {
    return mVisibleRect;
}

void VideoFrame::setBitstreamId(int32_t bitstreamId) {
    mBitstreamId = bitstreamId;
}

int32_t VideoFrame::getBitstreamId() const {
    return mBitstreamId;
}

C2ConstGraphicBlock VideoFrame::getGraphicBlock() {
    return mGraphicBlock->share(C2Rect(mVisibleRect.width(), mVisibleRect.height()), C2Fence());
}

}  // namespace android