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         // convert between bitrates
44         static bool map(C2Config::bitrate_mode_t, int32_t*);
45         static bool map(int32_t, C2Config::bitrate_mode_t*);
46 
47         // convert between pcm encodings
48         static bool map(C2Config::pcm_encoding_t, int32_t*);
49         static bool map(int32_t, C2Config::pcm_encoding_t*);
50 
51         // convert between picture types
52         static bool map(C2Config::picture_type_t, int32_t*);
53         static bool map(int32_t, C2Config::picture_type_t*);
54 
55         // convert between color aspects
56         static bool map(C2Color::range_t, int32_t*);
57         static bool map(int32_t, C2Color::range_t*);
58         static bool map(C2Color::primaries_t, C2Color::matrix_t, int32_t*);
59         static bool map(int32_t, C2Color::primaries_t*, C2Color::matrix_t*);
60         static bool map(C2Color::transfer_t, int32_t*);
61         static bool map(int32_t, C2Color::transfer_t*);
62 
63         static bool map(
64                 C2Color::range_t, C2Color::primaries_t, C2Color::matrix_t, C2Color::transfer_t,
65                 uint32_t *dataSpace);
66 
67         static bool map(C2Color::range_t, ColorAspects::Range*);
68         static bool map(ColorAspects::Range, C2Color::range_t*);
69         static bool map(C2Color::primaries_t, ColorAspects::Primaries*);
70         static bool map(ColorAspects::Primaries, C2Color::primaries_t*);
71         static bool map(C2Color::matrix_t, ColorAspects::MatrixCoeffs*);
72         static bool map(ColorAspects::MatrixCoeffs, C2Color::matrix_t*);
73         static bool map(C2Color::transfer_t, ColorAspects::Transfer*);
74         static bool map(ColorAspects::Transfer, C2Color::transfer_t*);
75     };
76 }
77 
78 #endif  // ANDROID_CODEC2_MAPPER_H_
79