Home | History | Annotate | Download | only in omx_adaptor
      1 /*
      2 * Copyright (c) 2015 Intel Corporation.  All rights reserved.
      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 
     18 #ifndef OMX_WRAPPER_H_
     19 #define OMX_WRAPPER_H_
     20 
     21 #include <unistd.h>
     22 #include <OMX_Core.h>
     23 #include <OMX_Component.h>
     24 #include <utils/threads.h>
     25 #include <utils/KeyedVector.h>
     26 #include <utils/String8.h>
     27 #include "MediaResourceArbitrator.h"
     28 
     29 using namespace android;
     30 
     31 typedef KeyedVector <OMX_HANDLETYPE, String8> ComponentNameMap;
     32 typedef KeyedVector <OMX_HANDLETYPE, uint> ComponentFramerateMap;
     33 
     34 typedef struct _AdaptorCodecInfo {
     35     CodecType codecType;
     36     bool isEncoder;
     37     bool isSecured;
     38     ResolutionType resolution;
     39     uint frameRate;
     40 } AdaptorCodecInfo;
     41 
     42 typedef KeyedVector <OMX_HANDLETYPE, AdaptorCodecInfo> ComponentInfoMap;
     43 
     44 class MRM_OMX_Adaptor {
     45 public:
     46     // Returns the singleton instance
     47     static MRM_OMX_Adaptor* getInstance();
     48 
     49     ~MRM_OMX_Adaptor() {
     50         if (sInstance) {
     51             delete sInstance;
     52             sInstance = NULL;
     53         }
     54     };
     55 
     56     // create and configure the MRM arbitrator
     57     OMX_ERRORTYPE MRM_OMX_Init(void);
     58 
     59 
     60     // check with MRM arbitrator if codec resource
     61     // is under full load status.
     62     // this should be called before OMX_GetHandle
     63     // return OMX_ErrorInsufficientResources if true.
     64     OMX_ERRORTYPE MRM_OMX_CheckIfFullLoad(OMX_STRING cComponentName);
     65 
     66 
     67     // Set component name and component handle
     68     // keeps this mapping but not adds resource yet.
     69     // this intends to be called after OMX_GetHandle
     70     void MRM_OMX_SetComponent(
     71                          OMX_HANDLETYPE pComponentHandle,
     72                          OMX_STRING cComponentName);
     73 
     74 
     75     // handle the index 'OMX_IndexParamPortDefinition'
     76     // when codec is configured, with resolution and
     77     // frame rate. this actually adds resource
     78     // to the MRM arbitrator.
     79     // return OMX_ErrorInsufficientResources if failed.
     80     OMX_ERRORTYPE MRM_OMX_SetParameter(
     81                          OMX_HANDLETYPE hComponent,
     82                          OMX_INDEXTYPE nIndex,
     83                          OMX_PTR pComponentParameterStructure);
     84 
     85 
     86     // check grahpic buffer resource
     87     // return OMX_ErrorInsufficientResources if under full load status.
     88     OMX_ERRORTYPE MRM_OMX_UseBuffer(
     89                          OMX_HANDLETYPE hComponent,
     90                          OMX_BUFFERHEADERTYPE **ppBufferHdr,
     91                          OMX_U32 nPortIndex,
     92                          OMX_PTR pAppPrivate,
     93                          OMX_U32 nSizeBytes,
     94                          OMX_U8 *pBuffer);
     95 
     96 
     97     // Remove the component
     98     OMX_ERRORTYPE MRM_OMX_RemoveComponent(OMX_HANDLETYPE pComponentHandle);
     99 
    100 private:
    101     MRM_OMX_Adaptor() { mArbitrator = new MediaResourceArbitrator(); }
    102     MRM_OMX_Adaptor& operator=(const MRM_OMX_Adaptor&);  // Don't call me
    103     MRM_OMX_Adaptor(const MRM_OMX_Adaptor&);             // Don't call me
    104 
    105 
    106     void ParseCodecInfoFromComponentName(const char* componentName,
    107                                          AdaptorCodecInfo* codecInfo);
    108 
    109     MediaResourceArbitrator* mArbitrator;
    110     static Mutex sLock;
    111     static MRM_OMX_Adaptor* sInstance;
    112 
    113     ComponentNameMap mComponentNameMap;
    114     ComponentFramerateMap mComponentFramerateMap;
    115     ComponentInfoMap mComponentInfoMap;
    116 };
    117 #endif /* OMX_WRAPPER_H_ */
    118