1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "host/frontend/webrtc/cvd_video_frame_buffer.h"
18 
19 #include "common/libs/utils/size_utils.h"
20 
21 namespace cuttlefish {
22 
23 namespace {
24 constexpr int kPlanePadding = 1024;
25 constexpr int kLogAlignment = 6;  // multiple of 2^6
26 
AlignStride(int width)27 inline int AlignStride(int width) {
28   return AlignToPowerOf2(width, kLogAlignment);
29 }
30 
31 }  // namespace
32 
CvdVideoFrameBuffer(int width,int height)33 CvdVideoFrameBuffer::CvdVideoFrameBuffer(int width, int height)
34     : width_(width),
35       height_(height),
36       y_(AlignStride(width) * height + kPlanePadding),
37       u_(AlignStride((width + 1) / 2) * ((height + 1) / 2) + kPlanePadding),
38       v_(AlignStride((width + 1) / 2) * ((height + 1) / 2) + kPlanePadding) {}
39 
width() const40 int CvdVideoFrameBuffer::width() const { return width_; }
height() const41 int CvdVideoFrameBuffer::height() const { return height_; }
42 
StrideY() const43 int CvdVideoFrameBuffer::StrideY() const { return AlignStride(width_); }
StrideU() const44 int CvdVideoFrameBuffer::StrideU() const {
45   return AlignStride((width_ + 1) / 2);
46 }
StrideV() const47 int CvdVideoFrameBuffer::StrideV() const {
48   return AlignStride((width_ + 1) / 2);
49 }
50 
DataY() const51 const uint8_t *CvdVideoFrameBuffer::DataY() const { return y_.data(); }
DataU() const52 const uint8_t *CvdVideoFrameBuffer::DataU() const { return u_.data(); }
DataV() const53 const uint8_t *CvdVideoFrameBuffer::DataV() const { return v_.data(); }
54 
55 }  // namespace cuttlefish
56