Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2011 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 SIMPLE_SOFT_OMX_COMPONENT_H_
     18 
     19 #define SIMPLE_SOFT_OMX_COMPONENT_H_
     20 
     21 #include "SoftOMXComponent.h"
     22 
     23 #include <media/stagefright/foundation/AHandlerReflector.h>
     24 #include <utils/RefBase.h>
     25 #include <utils/threads.h>
     26 #include <utils/Vector.h>
     27 
     28 namespace android {
     29 
     30 struct ALooper;
     31 
     32 struct SimpleSoftOMXComponent : public SoftOMXComponent {
     33     SimpleSoftOMXComponent(
     34             const char *name,
     35             const OMX_CALLBACKTYPE *callbacks,
     36             OMX_PTR appData,
     37             OMX_COMPONENTTYPE **component);
     38 
     39     virtual void prepareForDestruction();
     40 
     41     void onMessageReceived(const sp<AMessage> &msg);
     42 
     43 protected:
     44     struct BufferInfo {
     45         OMX_BUFFERHEADERTYPE *mHeader;
     46         bool mOwnedByUs;
     47     };
     48 
     49     struct PortInfo {
     50         OMX_PARAM_PORTDEFINITIONTYPE mDef;
     51         Vector<BufferInfo> mBuffers;
     52         List<BufferInfo *> mQueue;
     53 
     54         enum {
     55             NONE,
     56             DISABLING,
     57             ENABLING,
     58         } mTransition;
     59     };
     60 
     61     void addPort(const OMX_PARAM_PORTDEFINITIONTYPE &def);
     62 
     63     virtual OMX_ERRORTYPE internalGetParameter(
     64             OMX_INDEXTYPE index, OMX_PTR params);
     65 
     66     virtual OMX_ERRORTYPE internalSetParameter(
     67             OMX_INDEXTYPE index, const OMX_PTR params);
     68 
     69     virtual void onQueueFilled(OMX_U32 portIndex);
     70     List<BufferInfo *> &getPortQueue(OMX_U32 portIndex);
     71 
     72     virtual void onPortFlushCompleted(OMX_U32 portIndex);
     73     virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
     74     virtual void onReset();
     75 
     76     PortInfo *editPortInfo(OMX_U32 portIndex);
     77 
     78 private:
     79     enum {
     80         kWhatSendCommand,
     81         kWhatEmptyThisBuffer,
     82         kWhatFillThisBuffer,
     83     };
     84 
     85     Mutex mLock;
     86 
     87     sp<ALooper> mLooper;
     88     sp<AHandlerReflector<SimpleSoftOMXComponent> > mHandler;
     89 
     90     OMX_STATETYPE mState;
     91     OMX_STATETYPE mTargetState;
     92 
     93     Vector<PortInfo> mPorts;
     94 
     95     bool isSetParameterAllowed(
     96             OMX_INDEXTYPE index, const OMX_PTR params) const;
     97 
     98     virtual OMX_ERRORTYPE sendCommand(
     99             OMX_COMMANDTYPE cmd, OMX_U32 param, OMX_PTR data);
    100 
    101     virtual OMX_ERRORTYPE getParameter(
    102             OMX_INDEXTYPE index, OMX_PTR params);
    103 
    104     virtual OMX_ERRORTYPE setParameter(
    105             OMX_INDEXTYPE index, const OMX_PTR params);
    106 
    107     virtual OMX_ERRORTYPE useBuffer(
    108             OMX_BUFFERHEADERTYPE **buffer,
    109             OMX_U32 portIndex,
    110             OMX_PTR appPrivate,
    111             OMX_U32 size,
    112             OMX_U8 *ptr);
    113 
    114     virtual OMX_ERRORTYPE allocateBuffer(
    115             OMX_BUFFERHEADERTYPE **buffer,
    116             OMX_U32 portIndex,
    117             OMX_PTR appPrivate,
    118             OMX_U32 size);
    119 
    120     virtual OMX_ERRORTYPE freeBuffer(
    121             OMX_U32 portIndex,
    122             OMX_BUFFERHEADERTYPE *buffer);
    123 
    124     virtual OMX_ERRORTYPE emptyThisBuffer(
    125             OMX_BUFFERHEADERTYPE *buffer);
    126 
    127     virtual OMX_ERRORTYPE fillThisBuffer(
    128             OMX_BUFFERHEADERTYPE *buffer);
    129 
    130     virtual OMX_ERRORTYPE getState(OMX_STATETYPE *state);
    131 
    132     void onSendCommand(OMX_COMMANDTYPE cmd, OMX_U32 param);
    133     void onChangeState(OMX_STATETYPE state);
    134     void onPortEnable(OMX_U32 portIndex, bool enable);
    135     void onPortFlush(OMX_U32 portIndex, bool sendFlushComplete);
    136 
    137     void checkTransitions();
    138 
    139     DISALLOW_EVIL_CONSTRUCTORS(SimpleSoftOMXComponent);
    140 };
    141 
    142 }  // namespace android
    143 
    144 #endif  // SIMPLE_SOFT_OMX_COMPONENT_H_
    145