Home | History | Annotate | Download | only in media
      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 ANDROID_IOMX_H_
     18 
     19 #define ANDROID_IOMX_H_
     20 
     21 #include <binder/IInterface.h>
     22 #include <utils/List.h>
     23 #include <utils/String8.h>
     24 #include <cutils/native_handle.h>
     25 
     26 #include <list>
     27 
     28 #include <hidl/HybridInterface.h>
     29 #include <media/hardware/MetadataBufferType.h>
     30 #include <android/hardware/media/omx/1.0/IOmxNode.h>
     31 
     32 #include <media/openmax/OMX_Core.h>
     33 #include <media/openmax/OMX_Video.h>
     34 #include <media/openmax/OMX_VideoExt.h>
     35 
     36 namespace android {
     37 
     38 class IGraphicBufferProducer;
     39 class IGraphicBufferSource;
     40 class IMemory;
     41 class IOMXBufferSource;
     42 class IOMXNode;
     43 class IOMXObserver;
     44 class NativeHandle;
     45 class OMXBuffer;
     46 struct omx_message;
     47 
     48 using hardware::media::omx::V1_0::IOmxNode;
     49 
     50 class IOMX : public IInterface {
     51 public:
     52     DECLARE_META_INTERFACE(OMX);
     53 
     54     typedef uint32_t buffer_id;
     55 
     56     enum {
     57         kFenceTimeoutMs = 1000
     58     };
     59 
     60     enum PortMode {
     61         kPortModePresetStart = 0,
     62         kPortModePresetByteBuffer,
     63         kPortModePresetANWBuffer,
     64         kPortModePresetSecureBuffer,
     65         kPortModePresetEnd,
     66 
     67         kPortModeDynamicStart = 100,
     68         kPortModeDynamicANWBuffer,      // uses metadata mode kMetadataBufferTypeANWBuffer
     69                                         // or kMetadataBufferTypeGrallocSource
     70         kPortModeDynamicNativeHandle,   // uses metadata mode kMetadataBufferTypeNativeHandleSource
     71         kPortModeDynamicEnd,
     72     };
     73 
     74     struct ComponentInfo {
     75         String8 mName;
     76         List<String8> mRoles;
     77     };
     78     virtual status_t listNodes(List<ComponentInfo> *list) = 0;
     79 
     80     virtual status_t allocateNode(
     81             const char *name, const sp<IOMXObserver> &observer,
     82             sp<IOMXNode> *omxNode) = 0;
     83 
     84     virtual status_t createInputSurface(
     85             sp<IGraphicBufferProducer> *bufferProducer,
     86             sp<IGraphicBufferSource> *bufferSource) = 0;
     87 };
     88 
     89 class IOMXNode : public IInterface {
     90 public:
     91     DECLARE_HYBRID_META_INTERFACE(OMXNode, IOmxNode);
     92 
     93     typedef IOMX::buffer_id buffer_id;
     94 
     95     virtual status_t freeNode() = 0;
     96 
     97     virtual status_t sendCommand(
     98             OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
     99 
    100     virtual status_t getParameter(
    101             OMX_INDEXTYPE index, void *params, size_t size) = 0;
    102 
    103     virtual status_t setParameter(
    104             OMX_INDEXTYPE index, const void *params, size_t size) = 0;
    105 
    106     virtual status_t getConfig(
    107             OMX_INDEXTYPE index, void *params, size_t size) = 0;
    108 
    109     virtual status_t setConfig(
    110             OMX_INDEXTYPE index, const void *params, size_t size) = 0;
    111 
    112     virtual status_t setPortMode(
    113             OMX_U32 port_index, IOMX::PortMode mode) = 0;
    114 
    115     virtual status_t prepareForAdaptivePlayback(
    116             OMX_U32 portIndex, OMX_BOOL enable,
    117             OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
    118 
    119     virtual status_t configureVideoTunnelMode(
    120             OMX_U32 portIndex, OMX_BOOL tunneled,
    121             OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
    122 
    123     virtual status_t getGraphicBufferUsage(
    124             OMX_U32 port_index, OMX_U32* usage) = 0;
    125 
    126     virtual status_t setInputSurface(
    127             const sp<IOMXBufferSource> &bufferSource) = 0;
    128 
    129     // Allocate an opaque buffer as a native handle. If component supports returning native
    130     // handles, those are returned in *native_handle. Otherwise, the allocated buffer is
    131     // returned in *buffer_data. This clearly only makes sense if the caller lives in the
    132     // same process as the callee, i.e. is the media_server, as the returned "buffer_data"
    133     // pointer is just that, a pointer into local address space.
    134     virtual status_t allocateSecureBuffer(
    135             OMX_U32 port_index, size_t size, buffer_id *buffer,
    136             void **buffer_data, sp<NativeHandle> *native_handle) = 0;
    137 
    138     // Instructs the component to use the buffer passed in via |omxBuf| on the
    139     // specified port. Returns in |*buffer| the buffer id that the component
    140     // assigns to this buffer. |omxBuf| must be one of:
    141     // 1) OMXBuffer::sPreset for meta-mode,
    142     // 2) type kBufferTypeANWBuffer for non-meta-graphic buffer mode,
    143     // 3) type kBufferTypeSharedMem for bytebuffer mode.
    144     virtual status_t useBuffer(
    145             OMX_U32 port_index, const OMXBuffer &omxBuf, buffer_id *buffer) = 0;
    146 
    147     // Frees the buffer on the specified port with buffer id |buffer|.
    148     virtual status_t freeBuffer(
    149             OMX_U32 port_index, buffer_id buffer) = 0;
    150 
    151     // Calls OMX_FillBuffer on buffer. Passes |fenceFd| to component if it
    152     // supports fences. Otherwise, it waits on |fenceFd| before calling
    153     // OMX_FillBuffer. Takes ownership of |fenceFd| even if this call fails.
    154     // If the port is in metadata mode, the buffer will be updated to point
    155     // to the new buffer passed in via |omxBuf| before OMX_FillBuffer is called.
    156     // Otherwise info in the |omxBuf| is not used.
    157     virtual status_t fillBuffer(
    158             buffer_id buffer, const OMXBuffer &omxBuf, int fenceFd = -1) = 0;
    159 
    160     // Calls OMX_EmptyBuffer on buffer. Passes |fenceFd| to component if it
    161     // supports fences. Otherwise, it waits on |fenceFd| before calling
    162     // OMX_EmptyBuffer. Takes ownership of |fenceFd| even if this call fails.
    163     // If the port is in metadata mode, the buffer will be updated to point
    164     // to the new buffer passed in via |omxBuf| before OMX_EmptyBuffer is called.
    165     virtual status_t emptyBuffer(
    166             buffer_id buffer, const OMXBuffer &omxBuf,
    167             OMX_U32 flags, OMX_TICKS timestamp, int fenceFd = -1) = 0;
    168 
    169     virtual status_t getExtensionIndex(
    170             const char *parameter_name,
    171             OMX_INDEXTYPE *index) = 0;
    172 
    173     virtual status_t dispatchMessage(const omx_message &msg) = 0;
    174 };
    175 
    176 struct omx_message {
    177     enum {
    178         EVENT,
    179         EMPTY_BUFFER_DONE,
    180         FILL_BUFFER_DONE,
    181         FRAME_RENDERED,
    182     } type;
    183 
    184     int fenceFd; // used for EMPTY_BUFFER_DONE and FILL_BUFFER_DONE; client must close this
    185 
    186     union {
    187         // if type == EVENT
    188         struct {
    189             OMX_EVENTTYPE event;
    190             OMX_U32 data1;
    191             OMX_U32 data2;
    192             OMX_U32 data3;
    193             OMX_U32 data4;
    194         } event_data;
    195 
    196         // if type == EMPTY_BUFFER_DONE
    197         struct {
    198             IOMX::buffer_id buffer;
    199         } buffer_data;
    200 
    201         // if type == FILL_BUFFER_DONE
    202         struct {
    203             IOMX::buffer_id buffer;
    204             OMX_U32 range_offset;
    205             OMX_U32 range_length;
    206             OMX_U32 flags;
    207             OMX_TICKS timestamp;
    208         } extended_buffer_data;
    209 
    210         // if type == FRAME_RENDERED
    211         struct {
    212             OMX_TICKS timestamp;
    213             OMX_S64 nanoTime;
    214         } render_data;
    215     } u;
    216 };
    217 
    218 class IOMXObserver : public IInterface {
    219 public:
    220     DECLARE_META_INTERFACE(OMXObserver);
    221 
    222     // Handle (list of) messages.
    223     virtual void onMessages(const std::list<omx_message> &messages) = 0;
    224 };
    225 
    226 ////////////////////////////////////////////////////////////////////////////////
    227 
    228 class BnOMX : public BnInterface<IOMX> {
    229 public:
    230     virtual status_t onTransact(
    231             uint32_t code, const Parcel &data, Parcel *reply,
    232             uint32_t flags = 0);
    233 };
    234 
    235 class BnOMXNode : public BnInterface<IOMXNode> {
    236 public:
    237     virtual status_t onTransact(
    238             uint32_t code, const Parcel &data, Parcel *reply,
    239             uint32_t flags = 0);
    240 
    241 protected:
    242     // check if the codec is secure.
    243     virtual bool isSecure() const {
    244         return false;
    245     }
    246 };
    247 
    248 class BnOMXObserver : public BnInterface<IOMXObserver> {
    249 public:
    250     virtual status_t onTransact(
    251             uint32_t code, const Parcel &data, Parcel *reply,
    252             uint32_t flags = 0);
    253 };
    254 
    255 }  // namespace android
    256 
    257 #endif  // ANDROID_IOMX_H_
    258