HardwareAPI.h revision dde86f7b1802668a9c0986bcf7970c0e3565a92b
198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams/*
298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Copyright (C) 2009 The Android Open Source Project
398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams *
498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Licensed under the Apache License, Version 2.0 (the "License");
598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * you may not use this file except in compliance with the License.
698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * You may obtain a copy of the License at
798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams *
898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams *      http://www.apache.org/licenses/LICENSE-2.0
998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams *
1098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Unless required by applicable law or agreed to in writing, software
1198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * distributed under the License is distributed on an "AS IS" BASIS,
1298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * See the License for the specific language governing permissions and
1498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * limitations under the License.
1598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */
1698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
1798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#ifndef HARDWARE_API_H_
1898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
1998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#define HARDWARE_API_H_
2098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
2198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <media/hardware/OMXPluginBase.h>
2298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <media/hardware/MetadataBufferType.h>
2398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <system/window.h>
2498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <utils/RefBase.h>
2564965801cc56f4fca5c8e55bdd27de57359f7a0eJason Sams
2698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <OMX_Component.h>
2798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
2898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsnamespace android {
2998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
3098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// A pointer to this struct is passed to the OMX_SetParameter when the extension
3198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// index for the 'OMX.google.android.index.enableAndroidNativeBuffers' extension
32c5b37c751f22199fd3cf14f6ef19ed4b9664510fTim Murray// is given.
33c5b37c751f22199fd3cf14f6ef19ed4b9664510fTim Murray//
34c5b37c751f22199fd3cf14f6ef19ed4b9664510fTim Murray// When Android native buffer use is disabled for a port (the default state),
35c5b37c751f22199fd3cf14f6ef19ed4b9664510fTim Murray// the OMX node should operate as normal, and expect UseBuffer calls to set its
36c5b37c751f22199fd3cf14f6ef19ed4b9664510fTim Murray// buffers.  This is the mode that will be used when CPU access to the buffer is
37c5b37c751f22199fd3cf14f6ef19ed4b9664510fTim Murray// required.
3898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams//
3998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// When Android native buffer use has been enabled for a given port, the video
4098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// color format for the port is to be interpreted as an Android pixel format
4198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// rather than an OMX color format.  Enabling Android native buffers may also
4298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// change how the component receives the native buffers.  If store-metadata-mode
4398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// is enabled on the port, the component will receive the buffers as specified
4498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// in the section below. Otherwise, unless the node supports the
4598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// 'OMX.google.android.index.useAndroidNativeBuffer2' extension, it should
4698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// expect to receive UseAndroidNativeBuffer calls (via OMX_SetParameter) rather
4798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// than UseBuffer calls for that port.
4898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstruct EnableAndroidNativeBuffersParams {
4998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nSize;
5098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_VERSIONTYPE nVersion;
5198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nPortIndex;
5298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_BOOL enable;
5398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams};
5498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
5598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// A pointer to this struct is passed to OMX_SetParameter() when the extension
5698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// index "OMX.google.android.index.storeMetaDataInBuffers"
5798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// is given.
5898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams//
5998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// When meta data is stored in the video buffers passed between OMX clients
6098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// and OMX components, interpretation of the buffer data is up to the
6198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// buffer receiver, and the data may or may not be the actual video data, but
6298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// some information helpful for the receiver to locate the actual data.
6398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// The buffer receiver thus needs to know how to interpret what is stored
6498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// in these buffers, with mechanisms pre-determined externally. How to
6598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// interpret the meta data is outside of the scope of this method.
6698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams//
6798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// Currently, this is specifically used to pass meta data from video source
6898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// (camera component, for instance) to video encoder to avoid memcpying of
6998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// input video frame data. To do this, bStoreMetaData is set to OMX_TRUE.
7098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// If bStoreMetaData is set to false, real YUV frame data will be stored
7198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// in the buffers. In addition, if no OMX_SetParameter() call is made
7298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// with the corresponding extension index, real YUV data is stored
7398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// in the buffers.
7498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams//
7598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// For video decoder output port, the metadata buffer layout is defined below.
7698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams//
7798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// Metadata buffers are registered with the component using UseBuffer calls.
7898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstruct StoreMetaDataInBuffersParams {
7998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nSize;
8098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_VERSIONTYPE nVersion;
8198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nPortIndex;
8298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_BOOL bStoreMetaData;
8398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams};
8498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
8598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// Meta data buffer layout used to transport output frames to the decoder for
8698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// dynamic buffer handling.
8798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstruct VideoDecoderOutputMetaData {
8898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams  MetadataBufferType eType;
8998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams  buffer_handle_t pHandle;
9098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams};
9198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
9298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// A pointer to this struct is passed to OMX_SetParameter() when the extension
9398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// index "OMX.google.android.index.prepareForAdaptivePlayback" is given.
9498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams//
9598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// This method is used to signal a video decoder, that the user has requested
9698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// seamless resolution change support (if bEnable is set to OMX_TRUE).
9798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// nMaxFrameWidth and nMaxFrameHeight are the dimensions of the largest
9898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// anticipated frames in the video.  If bEnable is OMX_FALSE, no resolution
9998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// change is expected, and the nMaxFrameWidth/Height fields are unused.
10098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams//
10198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// If the decoder supports dynamic output buffers, it may ignore this
10298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// request.  Otherwise, it shall request resources in such a way so that it
10398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// avoids full port-reconfiguration (due to output port-definition change)
10498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// during resolution changes.
10598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams//
10698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// DO NOT USE THIS STRUCTURE AS IT WILL BE REMOVED.  INSTEAD, IMPLEMENT
10798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// METADATA SUPPORT FOR VIDEO DECODERS.
10898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstruct PrepareForAdaptivePlaybackParams {
10998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nSize;
11098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_VERSIONTYPE nVersion;
11198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nPortIndex;
11298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_BOOL bEnable;
11398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nMaxFrameWidth;
11498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nMaxFrameHeight;
11598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams};
11698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
11798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// A pointer to this struct is passed to OMX_SetParameter when the extension
11898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// index for the 'OMX.google.android.index.useAndroidNativeBuffer' extension is
11998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// given.  This call will only be performed if a prior call was made with the
12098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// 'OMX.google.android.index.enableAndroidNativeBuffers' extension index,
12198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// enabling use of Android native buffers.
12298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstruct UseAndroidNativeBufferParams {
12398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nSize;
12498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_VERSIONTYPE nVersion;
12598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nPortIndex;
12698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_PTR pAppPrivate;
12798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_BUFFERHEADERTYPE **bufferHeader;
12898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    const sp<ANativeWindowBuffer>& nativeBuffer;
12998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams};
13098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
13198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// A pointer to this struct is passed to OMX_GetParameter when the extension
13298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// index for the 'OMX.google.android.index.getAndroidNativeBufferUsage'
13398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// extension is given.  The usage bits returned from this query will be used to
13498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// allocate the Gralloc buffers that get passed to the useAndroidNativeBuffer
13598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// command.
13698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstruct GetAndroidNativeBufferUsageParams {
13798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nSize;              // IN
13898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_VERSIONTYPE nVersion;   // IN
13998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nPortIndex;         // IN
14098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_U32 nUsage;             // OUT
14198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams};
14298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
14398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// An enum OMX_COLOR_FormatAndroidOpaque to indicate an opaque colorformat
14498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// is declared in media/stagefright/openmax/OMX_IVCommon.h
14598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// This will inform the encoder that the actual
14698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// colorformat will be relayed by the GRalloc Buffers.
14798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// OMX_COLOR_FormatAndroidOpaque  = 0x7F000001,
14898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
14998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// A pointer to this struct is passed to OMX_SetParameter when the extension
15098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// index for the 'OMX.google.android.index.prependSPSPPSToIDRFrames' extension
15198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// is given.
152f681be1f0ec328acaa311478887352a456d52be8Jason Sams// A successful result indicates that future IDR frames will be prefixed by
15398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// SPS/PPS.
15498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstruct PrependSPSPPSToIDRFramesParams {
155f681be1f0ec328acaa311478887352a456d52be8Jason Sams    OMX_U32 nSize;
15698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_VERSIONTYPE nVersion;
15798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams    OMX_BOOL bEnable;
15898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams};
15998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
16098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams}  // namespace android
16198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
16298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsextern android::OMXPluginBase *createOMXPlugin();
16398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams
16498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#endif  // HARDWARE_API_H_
16598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams