• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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_MEDIA_TRANSCODING_NDK_COMMON_H
18 #define ANDROID_MEDIA_TRANSCODING_NDK_COMMON_H
19 
20 #include <media/NdkMediaFormat.h>
21 
22 #include <vector>
23 
24 extern const char* AMEDIA_MIMETYPE_VIDEO_VP8;
25 extern const char* AMEDIA_MIMETYPE_VIDEO_VP9;
26 extern const char* AMEDIA_MIMETYPE_VIDEO_AV1;
27 extern const char* AMEDIA_MIMETYPE_VIDEO_AVC;
28 extern const char* AMEDIA_MIMETYPE_VIDEO_HEVC;
29 extern const char* AMEDIA_MIMETYPE_VIDEO_MPEG4;
30 extern const char* AMEDIA_MIMETYPE_VIDEO_H263;
31 
32 // TODO(b/146420990)
33 // TODO: make MediaTranscoder use the consts from this header.
34 typedef enum {
35     OUTPUT_FORMAT_START = 0,
36     OUTPUT_FORMAT_MPEG_4 = OUTPUT_FORMAT_START,
37     OUTPUT_FORMAT_WEBM = OUTPUT_FORMAT_START + 1,
38     OUTPUT_FORMAT_THREE_GPP = OUTPUT_FORMAT_START + 2,
39     OUTPUT_FORMAT_HEIF = OUTPUT_FORMAT_START + 3,
40     OUTPUT_FORMAT_OGG = OUTPUT_FORMAT_START + 4,
41     OUTPUT_FORMAT_LIST_END = OUTPUT_FORMAT_START + 4,
42 } MuxerFormat;
43 
44 // Color formats supported by encoder - should mirror supportedColorList
45 // from MediaCodecConstants.h (are these going to be deprecated)
46 static constexpr int COLOR_FormatYUV420SemiPlanar = 21;
47 static constexpr int COLOR_FormatYUV420Flexible = 0x7F420888;
48 static constexpr int COLOR_FormatSurface = 0x7f000789;
49 
50 // Color transfer functions defined by MediaCodecConstants.h but not in NDK
51 static constexpr int32_t COLOR_TRANSFER_HLG = 7;
52 static constexpr int32_t COLOR_TRANSFER_LINEAR = 1;
53 static constexpr int32_t COLOR_TRANSFER_SDR_VIDEO = 3;
54 static constexpr int32_t COLOR_TRANSFER_ST2084 = 6;
55 
56 // constants not defined in NDK
57 extern const char* TBD_AMEDIACODEC_PARAMETER_KEY_ALLOW_FRAME_DROP;
58 extern const char* TBD_AMEDIACODEC_PARAMETER_KEY_REQUEST_SYNC_FRAME;
59 extern const char* TBD_AMEDIACODEC_PARAMETER_KEY_VIDEO_BITRATE;
60 extern const char* TBD_AMEDIACODEC_PARAMETER_KEY_MAX_B_FRAMES;
61 extern const char* TBD_AMEDIACODEC_PARAMETER_KEY_COLOR_TRANSFER_REQUEST;
62 extern const char* TBD_AMEDIACODEC_PARAMETER_KEY_BACKGROUND_MODE;
63 static constexpr int TBD_AMEDIACODEC_BUFFER_FLAG_KEY_FRAME = 0x1;
64 
65 static constexpr int kBitrateModeConstant = 2;
66 
67 namespace AMediaFormatUtils {
68 
69 typedef struct {
70     const char* key;
71     bool (*copy)(const char* key, AMediaFormat* from, AMediaFormat* to);
72     bool (*copy2)(const char* key, AMediaFormat* from, AMediaFormat* to);
73 } EntryCopier;
74 
75 #define ENTRY_COPIER(keyName, typeName) \
76     { keyName, AMediaFormatUtils::CopyFormatEntry##typeName, nullptr }
77 #define ENTRY_COPIER2(keyName, typeName, typeName2)            \
78     {                                                          \
79         keyName, AMediaFormatUtils::CopyFormatEntry##typeName, \
80                 AMediaFormatUtils::CopyFormatEntry##typeName2  \
81     }
82 
83 bool CopyFormatEntryString(const char* key, AMediaFormat* from, AMediaFormat* to);
84 bool CopyFormatEntryInt64(const char* key, AMediaFormat* from, AMediaFormat* to);
85 bool CopyFormatEntryInt32(const char* key, AMediaFormat* from, AMediaFormat* to);
86 bool CopyFormatEntryFloat(const char* key, AMediaFormat* from, AMediaFormat* to);
87 
88 void CopyFormatEntries(AMediaFormat* from, AMediaFormat* to,
89                        const std::vector<EntryCopier>& entries);
90 
91 bool SetDefaultFormatValueFloat(const char* key, AMediaFormat* format, float value);
92 bool SetDefaultFormatValueInt32(const char* key, AMediaFormat* format, int32_t value);
93 
94 bool VideoIsHdr(AMediaFormat* format);
95 
96 }  // namespace AMediaFormatUtils
97 #endif  // ANDROID_MEDIA_TRANSCODING_NDK_COMMON_H
98