1 /*
2 * Copyright (C) 2019 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 MEDIACTSNATIVE_NATIVE_MEDIA_COMMON_H
18 #define MEDIACTSNATIVE_NATIVE_MEDIA_COMMON_H
19
20 #include <inttypes.h>
21 #include <string>
22 #include <vector>
23 #include <media/NdkMediaFormat.h>
24 #include <media/NdkMediaMuxer.h>
25
26 // Migrate this method to std::format when C++20 becomes available
27 template <typename... Args>
StringFormat(const std::string & format,Args...args)28 std::string StringFormat(const std::string& format, Args... args) {
29 auto size = std::snprintf(nullptr, 0, format.c_str(), args...);
30 if (size < 0) return std::string();
31 std::vector<char> buffer(size + 1); // Add 1 for terminating null byte
32 std::snprintf(buffer.data(), buffer.size(), format.c_str(), args...);
33 return std::string(buffer.data(), size); // Exclude the terminating null byte
34 }
35
36 extern const char* AMEDIA_MIMETYPE_VIDEO_VP8;
37 extern const char* AMEDIA_MIMETYPE_VIDEO_VP9;
38 extern const char* AMEDIA_MIMETYPE_VIDEO_AV1;
39 extern const char* AMEDIA_MIMETYPE_VIDEO_AVC;
40 extern const char* AMEDIA_MIMETYPE_VIDEO_HEVC;
41 extern const char* AMEDIA_MIMETYPE_VIDEO_MPEG4;
42 extern const char* AMEDIA_MIMETYPE_VIDEO_H263;
43
44 extern const char* AMEDIA_MIMETYPE_AUDIO_AMR_NB;
45 extern const char* AMEDIA_MIMETYPE_AUDIO_AMR_WB;
46 extern const char* AMEDIA_MIMETYPE_AUDIO_AAC;
47 extern const char* AMEDIA_MIMETYPE_AUDIO_FLAC;
48 extern const char* AMEDIA_MIMETYPE_AUDIO_VORBIS;
49 extern const char* AMEDIA_MIMETYPE_AUDIO_OPUS;
50 extern const char* AMEDIA_MIMETYPE_AUDIO_RAW;
51
52 extern const float kRmsErrorTolerance;
53
54 extern const long kQDeQTimeOutUs;
55 extern const int kRetryLimit;
56
57 // TODO: make this extend itself automatically
58 constexpr int LOCAL_AMEDIAMUXER_OUTPUT_FORMAT_FIRST = AMEDIAMUXER_OUTPUT_FORMAT_MPEG_4;
59 constexpr int LOCAL_AMEDIAMUXER_OUTPUT_FORMAT_LAST = AMEDIAMUXER_OUTPUT_FORMAT_OGG;
60
61 // Color formats supported by encoder - should mirror supportedColorList
62 // from MediaCodecConstants.h (are these going to be deprecated)
63 constexpr int COLOR_FormatYUV420SemiPlanar = 21;
64 constexpr int COLOR_FormatYUV420Flexible = 0x7F420888;
65 constexpr int COLOR_FormatSurface = 0x7f000789;
66 constexpr int COLOR_FormatYUVP010 = 54;
67
68 // constants not defined in NDK
69 extern const char* TBD_AMEDIACODEC_PARAMETER_KEY_REQUEST_SYNC_FRAME;
70 extern const char* TBD_AMEDIACODEC_PARAMETER_KEY_VIDEO_BITRATE;
71 extern const char* COMPATIBLE_AMEDIAFORMAT_KEY_MAX_B_FRAMES; // available >= sdk 34
72 extern const char* TBD_AMEDIAFORMAT_KEY_BIT_RATE_MODE;
73
74 // common utility functions
75 bool isCSDIdentical(AMediaFormat* refFormat, AMediaFormat* testFormat);
76 bool isFormatSimilar(AMediaFormat* refFormat, AMediaFormat* testFormat);
77 AMediaFormat* deSerializeMediaFormat(const char* msg, const char* separator);
78 bool isMediaTypeOutputUnAffectedBySeek(const char* mediaType);
79
80 template <class T>
81 void flattenField(uint8_t* buffer, int* pos, T value);
82
83 #endif // MEDIACTSNATIVE_NATIVE_MEDIA_COMMON_H
84