1 /*
2 * Copyright (C) 2016 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 OMX_UTILS_H_
18 #define OMX_UTILS_H_
19
20 #include <media/IOMX.h>
21
22 /***** DO NOT USE THIS INCLUDE!!! INTERAL ONLY!!! UNLESS YOU RESIDE IN media/libstagefright *****/
23
24 // OMXUtils contains omx-specific utility functions for stagefright/omx library
25 // TODO: move ACodec and OMXClient into this library
26
27 namespace android {
28
29 template<class T>
InitOMXParams(T * params)30 static void InitOMXParams(T *params) {
31 memset(params, 0, sizeof(T));
32 params->nSize = sizeof(T);
33 params->nVersion.s.nVersionMajor = 1;
34 params->nVersion.s.nVersionMinor = 0;
35 params->nVersion.s.nRevision = 0;
36 params->nVersion.s.nStep = 0;
37 }
38
39 status_t StatusFromOMXError(OMX_ERRORTYPE err);
40
41 const char *GetComponentRole(bool isEncoder, const char *mime);
42 status_t SetComponentRole(const sp<IOMXNode> &omxNode, const char *role);
43
44 struct DescribeColorFormat2Params;
45
46 bool IsFlexibleColorFormat(
47 const sp<IOMXNode> &omxNode, uint32_t colorFormat,
48 bool usingNativeBuffers, OMX_U32 *flexibleEquivalent);
49 bool DescribeDefaultColorFormat(DescribeColorFormat2Params &describeParams);
50 bool DescribeColorFormat(
51 const sp<IOMXNode> &omxNode,
52 DescribeColorFormat2Params &describeParams);
53
54 inline static const char *asString(MetadataBufferType i, const char *def = "??") {
55 using namespace android;
56 switch (i) {
57 case kMetadataBufferTypeCameraSource: return "CameraSource";
58 case kMetadataBufferTypeGrallocSource: return "GrallocSource";
59 case kMetadataBufferTypeANWBuffer: return "ANWBuffer";
60 case kMetadataBufferTypeNativeHandleSource: return "NativeHandleSource";
61 case kMetadataBufferTypeInvalid: return "Invalid";
62 default: return def;
63 }
64 }
65
66 inline static const char *asString(IOMX::PortMode mode, const char *def = "??") {
67 using namespace android;
68 switch (mode) {
69 case IOMX::kPortModePresetByteBuffer: return "PresetByteBuffer";
70 case IOMX::kPortModePresetANWBuffer: return "PresetANWBuffer";
71 case IOMX::kPortModePresetSecureBuffer: return "PresetSecureBuffer";
72 case IOMX::kPortModeDynamicANWBuffer: return "DynamicANWBuffer";
73 case IOMX::kPortModeDynamicNativeHandle:return "DynamicNativeHandle";
74 default: return def;
75 }
76 }
77
78 } // namespace android
79
80 #endif
81