blob: e432dd5549ebd9b394ea19cadf011321e1a84e8f [file] [log] [blame]
Harish Mahendrakarf5dec502022-04-13 15:53:55 -07001/*
2 * Copyright 2018, 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//#define LOG_NDEBUG 0
18#define LOG_TAG "Codec2BufferUtils"
19#define ATRACE_TAG ATRACE_TAG_VIDEO
20#include <utils/Log.h>
21
22#include <android/hardware_buffer.h>
23#include <cutils/properties.h>
24#include <media/hardware/HardwareAPI.h>
25#include <system/graphics.h>
26
27#include <C2Debug.h>
28
29#include "Codec2CommonUtils.h"
30
31namespace android {
32
33bool isAtLeastT() {
34 char deviceCodeName[PROP_VALUE_MAX];
35 __system_property_get("ro.build.version.codename", deviceCodeName);
36 return android_get_device_api_level() >= __ANDROID_API_T__ ||
37 !strcmp(deviceCodeName, "Tiramisu");
38}
39
40bool isHalPixelFormatSupported(AHardwareBuffer_Format format) {
41 // HAL_PIXEL_FORMAT_YCBCR_P010 was added in Android T, return false for older versions
42 if (format == (AHardwareBuffer_Format)HAL_PIXEL_FORMAT_YCBCR_P010 && !isAtLeastT()) {
43 return false;
44 }
45
46 const AHardwareBuffer_Desc desc = {
47 .width = 320,
48 .height = 240,
49 .format = format,
50 .layers = 1,
51 .usage = AHARDWAREBUFFER_USAGE_CPU_READ_RARELY | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
52 AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE,
53 .stride = 0,
54 .rfu0 = 0,
55 .rfu1 = 0,
56 };
57
58 return AHardwareBuffer_isSupported(&desc);
59}
60
61} // namespace android