summaryrefslogtreecommitdiff
path: root/media/codec2/sfplugin/utils/Codec2Mapper.h
blob: 797c8a898e072d057fe8c31a3bb08ad265c03f18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_CODEC2_MAPPER_H_
#define ANDROID_CODEC2_MAPPER_H_

#include <C2Config.h>

#include <media/stagefright/foundation/ColorUtils.h>

#include <memory>

namespace android {

    /**
     * Utility class to map Codec 2.0 values to android values.
     */
    struct C2Mapper {
        struct ProfileLevelMapper {
            virtual bool mapProfile(C2Config::profile_t, int32_t*) = 0;
            virtual bool mapProfile(int32_t, C2Config::profile_t*) = 0;
            virtual bool mapLevel(C2Config::level_t, int32_t*) = 0;
            virtual bool mapLevel(int32_t, C2Config::level_t*) = 0;
            virtual ~ProfileLevelMapper() = default;
        };

        static std::shared_ptr<ProfileLevelMapper>
        GetProfileLevelMapper(std::string mediaType);

        static std::shared_ptr<ProfileLevelMapper>
        GetHdrProfileLevelMapper(std::string mediaType, bool isHdr10Plus = false);

        // convert between bitrates
        static bool map(C2Config::bitrate_mode_t, int32_t*);
        static bool map(int32_t, C2Config::bitrate_mode_t*);

        // convert between pcm encodings
        static bool map(C2Config::pcm_encoding_t, int32_t*);
        static bool map(int32_t, C2Config::pcm_encoding_t*);

        // convert between picture types
        static bool map(C2Config::picture_type_t, int32_t*);
        static bool map(int32_t, C2Config::picture_type_t*);

        // convert between color aspects
        static bool map(C2Color::range_t, int32_t*);
        static bool map(int32_t, C2Color::range_t*);
        static bool map(C2Color::primaries_t, C2Color::matrix_t, int32_t*);
        static bool map(int32_t, C2Color::primaries_t*, C2Color::matrix_t*);
        static bool map(C2Color::transfer_t, int32_t*);
        static bool map(int32_t, C2Color::transfer_t*);

        static bool map(
                C2Color::range_t, C2Color::primaries_t, C2Color::matrix_t, C2Color::transfer_t,
                uint32_t *dataSpace);

        static bool map(C2Color::range_t, ColorAspects::Range*);
        static bool map(ColorAspects::Range, C2Color::range_t*);
        static bool map(C2Color::primaries_t, ColorAspects::Primaries*);
        static bool map(ColorAspects::Primaries, C2Color::primaries_t*);
        static bool map(C2Color::matrix_t, ColorAspects::MatrixCoeffs*);
        static bool map(ColorAspects::MatrixCoeffs, C2Color::matrix_t*);
        static bool map(C2Color::transfer_t, ColorAspects::Transfer*);
        static bool map(ColorAspects::Transfer, C2Color::transfer_t*);

        static bool mapPixelFormatFrameworkToCodec(
                int32_t frameworkValue, uint32_t *c2Value);
        static bool mapPixelFormatCodecToFramework(
                uint32_t c2Value, int32_t *frameworkValue);
    };
}

#endif  // ANDROID_CODEC2_MAPPER_H_