blob: c8e9e1382e03e6cf6889f1fcec679270187e9215 [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
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#ifndef ANDROID_CODEC2_MAPPER_H_
18#define ANDROID_CODEC2_MAPPER_H_
19
20#include <C2Config.h>
21
22#include <media/stagefright/foundation/ColorUtils.h>
23
24#include <memory>
25
26namespace android {
27
28 /**
29 * Utility class to map Codec 2.0 values to android values.
30 */
31 struct C2Mapper {
32 struct ProfileLevelMapper {
33 virtual bool mapProfile(C2Config::profile_t, int32_t*) = 0;
34 virtual bool mapProfile(int32_t, C2Config::profile_t*) = 0;
35 virtual bool mapLevel(C2Config::level_t, int32_t*) = 0;
36 virtual bool mapLevel(int32_t, C2Config::level_t*) = 0;
Lajos Molnar427a2f92022-04-28 10:57:21 -070037
38 /**
39 * Mapper method that maps a MediaCodec profile to the supported
40 * HDR format for that profile. Since 10-bit profiles are used for
41 * HLG, this method will return HLG for all 10-bit profiles, but
42 * the caller should also verify that the transfer function is
43 * indeed HLG.
44 */
45 // not an abstract method as we have a default implementation for SDR
46 virtual bool mapHdrFormat(int32_t, C2Config::hdr_format_t *hdr);
Pawin Vongmasa36653902018-11-15 00:10:25 -080047 virtual ~ProfileLevelMapper() = default;
48 };
49
50 static std::shared_ptr<ProfileLevelMapper>
51 GetProfileLevelMapper(std::string mediaType);
52
Chong Zhanga8d5b4f2018-12-04 17:05:29 -080053 static std::shared_ptr<ProfileLevelMapper>
54 GetHdrProfileLevelMapper(std::string mediaType, bool isHdr10Plus = false);
55
Wonsik Kim4b7bb0a2021-11-03 11:43:48 -070056 static std::shared_ptr<ProfileLevelMapper>
57 GetBitDepthProfileLevelMapper(std::string mediaType, int32_t bitDepth = 8);
58
Pawin Vongmasa36653902018-11-15 00:10:25 -080059 // convert between bitrates
60 static bool map(C2Config::bitrate_mode_t, int32_t*);
61 static bool map(int32_t, C2Config::bitrate_mode_t*);
62
63 // convert between pcm encodings
64 static bool map(C2Config::pcm_encoding_t, int32_t*);
65 static bool map(int32_t, C2Config::pcm_encoding_t*);
66
67 // convert between picture types
68 static bool map(C2Config::picture_type_t, int32_t*);
69 static bool map(int32_t, C2Config::picture_type_t*);
70
71 // convert between color aspects
72 static bool map(C2Color::range_t, int32_t*);
73 static bool map(int32_t, C2Color::range_t*);
74 static bool map(C2Color::primaries_t, C2Color::matrix_t, int32_t*);
75 static bool map(int32_t, C2Color::primaries_t*, C2Color::matrix_t*);
76 static bool map(C2Color::transfer_t, int32_t*);
77 static bool map(int32_t, C2Color::transfer_t*);
78
79 static bool map(
80 C2Color::range_t, C2Color::primaries_t, C2Color::matrix_t, C2Color::transfer_t,
81 uint32_t *dataSpace);
82
83 static bool map(C2Color::range_t, ColorAspects::Range*);
84 static bool map(ColorAspects::Range, C2Color::range_t*);
85 static bool map(C2Color::primaries_t, ColorAspects::Primaries*);
86 static bool map(ColorAspects::Primaries, C2Color::primaries_t*);
87 static bool map(C2Color::matrix_t, ColorAspects::MatrixCoeffs*);
88 static bool map(ColorAspects::MatrixCoeffs, C2Color::matrix_t*);
89 static bool map(C2Color::transfer_t, ColorAspects::Transfer*);
90 static bool map(ColorAspects::Transfer, C2Color::transfer_t*);
Wonsik Kimfb7a7672019-12-27 17:13:33 -080091
92 static bool mapPixelFormatFrameworkToCodec(
93 int32_t frameworkValue, uint32_t *c2Value);
94 static bool mapPixelFormatCodecToFramework(
95 uint32_t c2Value, int32_t *frameworkValue);
Pawin Vongmasa36653902018-11-15 00:10:25 -080096 };
97}
98
99#endif // ANDROID_CODEC2_MAPPER_H_