• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "frame_info.h"
17 #include "vpe_log.h"
18 
19 namespace OHOS {
20 namespace Media {
21 namespace VideoProcessingEngine {
FrameInfo(const sptr<SurfaceBuffer> & buffer)22 FrameInfo::FrameInfo(const sptr<SurfaceBuffer> &buffer)
23 {
24     CHECK_AND_RETURN_LOG(nullptr != buffer, "Get an invalid buffer");
25     width = static_cast<uint32_t>(buffer->GetWidth());
26     height = static_cast<uint32_t>(buffer->GetHeight());
27     widthStride = static_cast<uint32_t>(buffer->GetStride());
28     // 10 bit sample might be as 2bytes, so stride is 2 * (width + padding)
29     pixelFormat = static_cast<GraphicPixelFormat>(buffer->GetFormat());
30     bitDepth = BitDepth::BIT_DEPTH_8;
31     int numTwo = 2;
32     int numThree = 3;
33     int numFour = 4;
34     OH_NativeBuffer_Planes *planes = nullptr;
35     if ((pixelFormat == GRAPHIC_PIXEL_FMT_RGBA_8888) || (pixelFormat == GRAPHIC_PIXEL_FMT_BGRA_8888)) {
36         // RGBA8 has 4 channel per pixel which cost 4*8bit. // GetStride = w * sizeof(uint32)
37         widthStride = static_cast<uint32_t>(buffer->GetStride() / numFour);
38         heightStride = buffer->GetSize() / static_cast<uint32_t>(numFour) / widthStride;
39     } else if ((pixelFormat == GRAPHIC_PIXEL_FMT_YCBCR_420_SP) || (pixelFormat == GRAPHIC_PIXEL_FMT_YCRCB_420_SP)
40         || (pixelFormat == GRAPHIC_PIXEL_FMT_YCBCR_420_P) || (pixelFormat == GRAPHIC_PIXEL_FMT_YCRCB_420_P)) {
41         // GetStride = w * sizeof(uint8) // yuv420(totalsize=3/2*h*w) calculate height stride
42         widthStride = static_cast<uint32_t>(buffer->GetStride());
43         heightStride = buffer->GetSize() * static_cast<uint32_t>(numTwo) /
44                        static_cast<uint32_t>(numThree) / widthStride;
45         if ((buffer->GetPlanesInfo(reinterpret_cast<void**>(&planes)) == OHOS::SURFACE_ERROR_OK) &&
46             (planes != nullptr)) {
47             if (planes->planeCount > 1) {
48                 heightStride = planes->planes[1].offset / planes->planes[0].columnStride;
49             }
50         }
51     } else if (pixelFormat == GRAPHIC_PIXEL_FMT_RGBA_1010102) {
52         // RGBA8 has 4 channel // GetStride = w * sizeof(uint8) (Get wByte nums) 4 channel
53         bitDepth = BitDepth::BIT_DEPTH_10;
54         widthStride = static_cast<uint32_t>(buffer->GetStride() / numFour);
55         heightStride = buffer->GetSize() / static_cast<uint32_t>(numFour) / widthStride;
56     } else if ((pixelFormat == GRAPHIC_PIXEL_FMT_YCBCR_P010) || (pixelFormat == GRAPHIC_PIXEL_FMT_YCRCB_P010)) {
57         // 2 bit GetStride = w * sizeof(uint8) (Get wByte nums) // yuv420(totalsize=3*h*w) calculate height stride
58         bitDepth = BitDepth::BIT_DEPTH_10;
59         widthStride = static_cast<uint32_t>(buffer->GetStride() / numTwo);
60         heightStride = buffer->GetSize() / static_cast<uint32_t>(numThree) / widthStride;
61         if ((buffer->GetPlanesInfo(reinterpret_cast<void**>(&planes)) == OHOS::SURFACE_ERROR_OK) &&
62             (planes != nullptr)) {
63             if (planes->planeCount > 1) {
64                 heightStride = planes->planes[1].offset / planes->planes[0].columnStride;
65             }
66         }
67     } else {
68         heightStride = height;
69     }
70     ColorSpaceDescription::Create(buffer, colorSpace);
71 }
72 } // namespace VideoProcessingEngine
73 } // namespace Media
74 } // namespace OHOS
75