HardwareAPI.h revision a8c2454d52d3c23bd53b4a172eff8e5f4af30168
1/* 2 * Copyright (C) 2009 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 HARDWARE_API_H_ 18 19#define HARDWARE_API_H_ 20 21#include <media/hardware/OMXPluginBase.h> 22#include <media/hardware/MetadataBufferType.h> 23#include <system/window.h> 24#include <utils/RefBase.h> 25 26#include <OMX_Component.h> 27 28namespace android { 29 30// A pointer to this struct is passed to the OMX_SetParameter when the extension 31// index for the 'OMX.google.android.index.enableAndroidNativeBuffers' extension 32// is given. 33// 34// When Android native buffer use is disabled for a port (the default state), 35// the OMX node should operate as normal, and expect UseBuffer calls to set its 36// buffers. This is the mode that will be used when CPU access to the buffer is 37// required. 38// 39// When Android native buffer use has been enabled for a given port, the video 40// color format for the port is to be interpreted as an Android pixel format 41// rather than an OMX color format. Enabling Android native buffers may also 42// change how the component receives the native buffers. If store-metadata-mode 43// is enabled on the port, the component will receive the buffers as specified 44// in the section below. Otherwise, unless the node supports the 45// 'OMX.google.android.index.useAndroidNativeBuffer2' extension, it should 46// expect to receive UseAndroidNativeBuffer calls (via OMX_SetParameter) rather 47// than UseBuffer calls for that port. 48struct EnableAndroidNativeBuffersParams { 49 OMX_U32 nSize; 50 OMX_VERSIONTYPE nVersion; 51 OMX_U32 nPortIndex; 52 OMX_BOOL enable; 53}; 54 55// A pointer to this struct is passed to OMX_SetParameter() when the extension index 56// "OMX.google.android.index.storeMetaDataInBuffers" or 57// "OMX.google.android.index.storeANWBufferInMetadata" is given. 58// 59// When meta data is stored in the video buffers passed between OMX clients 60// and OMX components, interpretation of the buffer data is up to the 61// buffer receiver, and the data may or may not be the actual video data, but 62// some information helpful for the receiver to locate the actual data. 63// The buffer receiver thus needs to know how to interpret what is stored 64// in these buffers, with mechanisms pre-determined externally. How to 65// interpret the meta data is outside of the scope of this parameter. 66// 67// Currently, this is used to pass meta data from video source (camera component, for instance) to 68// video encoder to avoid memcpying of input video frame data, as well as to pass dynamic output 69// buffer to video decoder. To do this, bStoreMetaData is set to OMX_TRUE. 70// 71// If bStoreMetaData is set to false, real YUV frame data will be stored in input buffers, and 72// the output buffers contain either real YUV frame data, or are themselves native handles as 73// directed by enable/use-android-native-buffer parameter settings. 74// In addition, if no OMX_SetParameter() call is made on a port with the corresponding extension 75// index, the component should not assume that the client is not using metadata mode for the port. 76// 77// If the component supports this using the "OMX.google.android.index.storeANWBufferInMetadata" 78// extension and bStoreMetaData is set to OMX_TRUE, data is passed using the VideoNativeMetadata 79// layout as defined below. Each buffer will be accompanied by a fence. The fence must signal 80// before the buffer can be used (e.g. read from or written into). When returning such buffer to 81// the client, component must provide a new fence that must signal before the returned buffer can 82// be used (e.g. read from or written into). The component owns the incoming fenceFd, and must close 83// it when fence has signaled. The client will own and close the returned fence file descriptor. 84// 85// If the component supports this using the "OMX.google.android.index.storeMetaDataInBuffers" 86// extension and bStoreMetaData is set to OMX_TRUE, data is passed using VideoGrallocMetadata 87// (the layout of which is the VideoGrallocMetadata defined below). Camera input can be also passed 88// as "CameraSource", the layout of which is vendor dependent. 89// 90// Metadata buffers are registered with the component using UseBuffer calls, or can be allocated 91// by the component for encoder-metadata-output buffers. 92struct StoreMetaDataInBuffersParams { 93 OMX_U32 nSize; 94 OMX_VERSIONTYPE nVersion; 95 OMX_U32 nPortIndex; 96 OMX_BOOL bStoreMetaData; 97}; 98 99// Meta data buffer layout used to transport output frames to the decoder for 100// dynamic buffer handling. 101struct VideoGrallocMetadata { 102 MetadataBufferType eType; // must be kMetadataBufferTypeGrallocSource 103 buffer_handle_t hHandle; 104}; 105 106// Legacy name for VideoGrallocMetadata struct. 107struct VideoDecoderOutputMetaData { 108 MetadataBufferType eType; // must be kMetadataBufferTypeGrallocSource 109 buffer_handle_t pHandle; 110}; 111 112struct VideoNativeMetadata { 113 MetadataBufferType eType; // must be kMetadataBufferTypeANWBuffer 114 struct ANativeWindowBuffer* pBuffer; 115 int nFenceFd; // -1 if unused 116}; 117 118// A pointer to this struct is passed to OMX_SetParameter() when the extension 119// index "OMX.google.android.index.prepareForAdaptivePlayback" is given. 120// 121// This method is used to signal a video decoder, that the user has requested 122// seamless resolution change support (if bEnable is set to OMX_TRUE). 123// nMaxFrameWidth and nMaxFrameHeight are the dimensions of the largest 124// anticipated frames in the video. If bEnable is OMX_FALSE, no resolution 125// change is expected, and the nMaxFrameWidth/Height fields are unused. 126// 127// If the decoder supports dynamic output buffers, it may ignore this 128// request. Otherwise, it shall request resources in such a way so that it 129// avoids full port-reconfiguration (due to output port-definition change) 130// during resolution changes. 131// 132// DO NOT USE THIS STRUCTURE AS IT WILL BE REMOVED. INSTEAD, IMPLEMENT 133// METADATA SUPPORT FOR VIDEO DECODERS. 134struct PrepareForAdaptivePlaybackParams { 135 OMX_U32 nSize; 136 OMX_VERSIONTYPE nVersion; 137 OMX_U32 nPortIndex; 138 OMX_BOOL bEnable; 139 OMX_U32 nMaxFrameWidth; 140 OMX_U32 nMaxFrameHeight; 141}; 142 143// A pointer to this struct is passed to OMX_SetParameter when the extension 144// index for the 'OMX.google.android.index.useAndroidNativeBuffer' extension is 145// given. This call will only be performed if a prior call was made with the 146// 'OMX.google.android.index.enableAndroidNativeBuffers' extension index, 147// enabling use of Android native buffers. 148struct UseAndroidNativeBufferParams { 149 OMX_U32 nSize; 150 OMX_VERSIONTYPE nVersion; 151 OMX_U32 nPortIndex; 152 OMX_PTR pAppPrivate; 153 OMX_BUFFERHEADERTYPE **bufferHeader; 154 const sp<ANativeWindowBuffer>& nativeBuffer; 155}; 156 157// A pointer to this struct is passed to OMX_GetParameter when the extension 158// index for the 'OMX.google.android.index.getAndroidNativeBufferUsage' 159// extension is given. The usage bits returned from this query will be used to 160// allocate the Gralloc buffers that get passed to the useAndroidNativeBuffer 161// command. 162struct GetAndroidNativeBufferUsageParams { 163 OMX_U32 nSize; // IN 164 OMX_VERSIONTYPE nVersion; // IN 165 OMX_U32 nPortIndex; // IN 166 OMX_U32 nUsage; // OUT 167}; 168 169// An enum OMX_COLOR_FormatAndroidOpaque to indicate an opaque colorformat 170// is declared in media/stagefright/openmax/OMX_IVCommon.h 171// This will inform the encoder that the actual 172// colorformat will be relayed by the GRalloc Buffers. 173// OMX_COLOR_FormatAndroidOpaque = 0x7F000001, 174 175// A pointer to this struct is passed to OMX_SetParameter when the extension 176// index for the 'OMX.google.android.index.prependSPSPPSToIDRFrames' extension 177// is given. 178// A successful result indicates that future IDR frames will be prefixed by 179// SPS/PPS. 180struct PrependSPSPPSToIDRFramesParams { 181 OMX_U32 nSize; 182 OMX_VERSIONTYPE nVersion; 183 OMX_BOOL bEnable; 184}; 185 186// Structure describing a media image (frame) 187// Currently only supporting YUV 188struct MediaImage { 189 enum Type { 190 MEDIA_IMAGE_TYPE_UNKNOWN = 0, 191 MEDIA_IMAGE_TYPE_YUV, 192 }; 193 194 enum PlaneIndex { 195 Y = 0, 196 U, 197 V, 198 MAX_NUM_PLANES 199 }; 200 201 Type mType; 202 size_t mNumPlanes; // number of planes 203 size_t mWidth; // width of largest plane (unpadded, as in nFrameWidth) 204 size_t mHeight; // height of largest plane (unpadded, as in nFrameHeight) 205 size_t mBitDepth; // useable bit depth 206 struct PlaneInfo { 207 size_t mOffset; // offset of first pixel of the plane in bytes 208 // from buffer offset 209 size_t mColInc; // column increment in bytes 210 size_t mRowInc; // row increment in bytes 211 size_t mHorizSubsampling; // subsampling compared to the largest plane 212 size_t mVertSubsampling; // subsampling compared to the largest plane 213 }; 214 PlaneInfo mPlane[MAX_NUM_PLANES]; 215}; 216 217// A pointer to this struct is passed to OMX_GetParameter when the extension 218// index for the 'OMX.google.android.index.describeColorFormat' 219// extension is given. This method can be called from any component state 220// other than invalid. The color-format, frame width/height, and stride/ 221// slice-height parameters are ones that are associated with a raw video 222// port (input or output), but the stride/slice height parameters may be 223// incorrect. bUsingNativeBuffers is OMX_TRUE if native android buffers will 224// be used (while specifying this color format). 225// 226// The component shall fill out the MediaImage structure that 227// corresponds to the described raw video format, and the potentially corrected 228// stride and slice-height info. 229// 230// The behavior is slightly different if bUsingNativeBuffers is OMX_TRUE, 231// though most implementations can ignore this difference. When using native buffers, 232// the component may change the configured color format to an optimized format. 233// Additionally, when allocating these buffers for flexible usecase, the framework 234// will set the SW_READ/WRITE_OFTEN usage flags. In this case (if bUsingNativeBuffers 235// is OMX_TRUE), the component shall fill out the MediaImage information for the 236// scenario when these SW-readable/writable buffers are locked using gralloc_lock. 237// Note, that these buffers may also be locked using gralloc_lock_ycbcr, which must 238// be supported for vendor-specific formats. 239// 240// For non-YUV packed planar/semiplanar image formats, or if bUsingNativeBuffers 241// is OMX_TRUE and the component does not support this color format with native 242// buffers, the component shall set mNumPlanes to 0, and mType to MEDIA_IMAGE_TYPE_UNKNOWN. 243struct DescribeColorFormatParams { 244 OMX_U32 nSize; 245 OMX_VERSIONTYPE nVersion; 246 // input: parameters from OMX_VIDEO_PORTDEFINITIONTYPE 247 OMX_COLOR_FORMATTYPE eColorFormat; 248 OMX_U32 nFrameWidth; 249 OMX_U32 nFrameHeight; 250 OMX_U32 nStride; 251 OMX_U32 nSliceHeight; 252 OMX_BOOL bUsingNativeBuffers; 253 254 // output: fill out the MediaImage fields 255 MediaImage sMediaImage; 256}; 257 258// A pointer to this struct is passed to OMX_SetParameter or OMX_GetParameter 259// when the extension index for the 260// 'OMX.google.android.index.configureVideoTunnelMode' extension is given. 261// If the extension is supported then tunneled playback mode should be supported 262// by the codec. If bTunneled is set to OMX_TRUE then the video decoder should 263// operate in "tunneled" mode and output its decoded frames directly to the 264// sink. In this case nAudioHwSync is the HW SYNC ID of the audio HAL Output 265// stream to sync the video with. If bTunneled is set to OMX_FALSE, "tunneled" 266// mode should be disabled and nAudioHwSync should be ignored. 267// OMX_GetParameter is used to query tunneling configuration. bTunneled should 268// return whether decoder is operating in tunneled mode, and if it is, 269// pSidebandWindow should contain the codec allocated sideband window handle. 270struct ConfigureVideoTunnelModeParams { 271 OMX_U32 nSize; // IN 272 OMX_VERSIONTYPE nVersion; // IN 273 OMX_U32 nPortIndex; // IN 274 OMX_BOOL bTunneled; // IN/OUT 275 OMX_U32 nAudioHwSync; // IN 276 OMX_PTR pSidebandWindow; // OUT 277}; 278 279} // namespace android 280 281extern android::OMXPluginBase *createOMXPlugin(); 282 283#endif // HARDWARE_API_H_ 284