1 /*
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 
26 namespace 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;
37             virtual ~ProfileLevelMapper() = default;
38         };
39 
40         static std::shared_ptr<ProfileLevelMapper>
41         GetProfileLevelMapper(std::string mediaType);
42 
43         static std::shared_ptr<ProfileLevelMapper>
44         GetHdrProfileLevelMapper(std::string mediaType, bool isHdr10Plus = false);
45 
46         // convert between bitrates
47         static bool map(C2Config::bitrate_mode_t, int32_t*);
48         static bool map(int32_t, C2Config::bitrate_mode_t*);
49 
50         // convert between pcm encodings
51         static bool map(C2Config::pcm_encoding_t, int32_t*);
52         static bool map(int32_t, C2Config::pcm_encoding_t*);
53 
54         // convert between picture types
55         static bool map(C2Config::picture_type_t, int32_t*);
56         static bool map(int32_t, C2Config::picture_type_t*);
57 
58         // convert between color aspects
59         static bool map(C2Color::range_t, int32_t*);
60         static bool map(int32_t, C2Color::range_t*);
61         static bool map(C2Color::primaries_t, C2Color::matrix_t, int32_t*);
62         static bool map(int32_t, C2Color::primaries_t*, C2Color::matrix_t*);
63         static bool map(C2Color::transfer_t, int32_t*);
64         static bool map(int32_t, C2Color::transfer_t*);
65 
66         static bool map(
67                 C2Color::range_t, C2Color::primaries_t, C2Color::matrix_t, C2Color::transfer_t,
68                 uint32_t *dataSpace);
69 
70         static bool map(C2Color::range_t, ColorAspects::Range*);
71         static bool map(ColorAspects::Range, C2Color::range_t*);
72         static bool map(C2Color::primaries_t, ColorAspects::Primaries*);
73         static bool map(ColorAspects::Primaries, C2Color::primaries_t*);
74         static bool map(C2Color::matrix_t, ColorAspects::MatrixCoeffs*);
75         static bool map(ColorAspects::MatrixCoeffs, C2Color::matrix_t*);
76         static bool map(C2Color::transfer_t, ColorAspects::Transfer*);
77         static bool map(ColorAspects::Transfer, C2Color::transfer_t*);
78     };
79 }
80 
81 #endif  // ANDROID_CODEC2_MAPPER_H_
82