blob: e58330f9273782feac100916e5af295538d40a46 [file] [log] [blame]
Chong Zhang66469272020-06-04 16:51:55 -07001/*
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//#define LOG_NDEBUG 0
17#define LOG_TAG "NdkCommon"
Chong Zhang5855ee52020-06-22 11:41:25 -070018
Linus Nilsson16d772b2020-09-29 19:21:11 -070019#include <android-base/logging.h>
Chong Zhang66469272020-06-04 16:51:55 -070020#include <media/NdkCommon.h>
21
22#include <cstdio>
23#include <cstring>
24#include <utility>
25
26/* TODO(b/153592281)
27 * Note: constants used by the native media tests but not available in media ndk api
28 */
29const char* AMEDIA_MIMETYPE_VIDEO_VP8 = "video/x-vnd.on2.vp8";
30const char* AMEDIA_MIMETYPE_VIDEO_VP9 = "video/x-vnd.on2.vp9";
31const char* AMEDIA_MIMETYPE_VIDEO_AV1 = "video/av01";
32const char* AMEDIA_MIMETYPE_VIDEO_AVC = "video/avc";
33const char* AMEDIA_MIMETYPE_VIDEO_HEVC = "video/hevc";
34const char* AMEDIA_MIMETYPE_VIDEO_MPEG4 = "video/mp4v-es";
35const char* AMEDIA_MIMETYPE_VIDEO_H263 = "video/3gpp";
36
37/* TODO(b/153592281) */
Linus Nilsson93591892020-08-03 18:56:55 -070038const char* TBD_AMEDIACODEC_PARAMETER_KEY_ALLOW_FRAME_DROP = "allow-frame-drop";
Chong Zhang66469272020-06-04 16:51:55 -070039const char* TBD_AMEDIACODEC_PARAMETER_KEY_REQUEST_SYNC_FRAME = "request-sync";
40const char* TBD_AMEDIACODEC_PARAMETER_KEY_VIDEO_BITRATE = "video-bitrate";
41const char* TBD_AMEDIACODEC_PARAMETER_KEY_MAX_B_FRAMES = "max-bframes";
Linus Nilsson16d772b2020-09-29 19:21:11 -070042
43namespace AMediaFormatUtils {
44
45#define DEFINE_FORMAT_VALUE_COPY_FUNC(_type, _typeName) \
46 bool CopyFormatEntry##_typeName(const char* key, AMediaFormat* from, AMediaFormat* to) { \
47 _type value; \
48 if (AMediaFormat_get##_typeName(from, key, &value)) { \
49 AMediaFormat_set##_typeName(to, key, value); \
50 return true; \
51 } \
52 return false; \
53 }
54
55DEFINE_FORMAT_VALUE_COPY_FUNC(const char*, String);
56DEFINE_FORMAT_VALUE_COPY_FUNC(int64_t, Int64);
57DEFINE_FORMAT_VALUE_COPY_FUNC(int32_t, Int32);
58DEFINE_FORMAT_VALUE_COPY_FUNC(float, Float);
59
60void CopyFormatEntries(AMediaFormat* from, AMediaFormat* to, const EntryCopier* entries,
61 size_t entryCount) {
62 if (from == nullptr || to == nullptr) {
63 LOG(ERROR) << "Cannot copy null formats";
64 return;
65 } else if (entries == nullptr || entryCount < 1) {
66 LOG(WARNING) << "No entries to copy";
67 return;
68 }
69
70 for (size_t i = 0; i < entryCount; ++i) {
71 if (!entries[i].copy(entries[i].key, from, to) && entries[i].copy2 != nullptr) {
72 entries[i].copy2(entries[i].key, from, to);
73 }
74 }
75}
76} // namespace AMediaFormatUtils