Home | History | Annotate | Download | only in videocodec
      1 /*
      2 * Copyright (c) 2009-2011 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_VIDEO_DECODER_BASE_H_
     19 #define OMX_VIDEO_DECODER_BASE_H_
     20 
     21 
     22 #include "OMXComponentCodecBase.h"
     23 #include "VideoDecoderInterface.h"
     24 #include "VideoDecoderHost.h"
     25 
     26 #ifdef USE_GEN_HW
     27 #include "graphics.h"
     28 #endif
     29 
     30 static constexpr const char* VA_VED_RAW_MIME_TYPE = "video/x-raw-vaved";
     31 static const uint32_t VA_VED_COLOR_FORMAT = 0x20;
     32 
     33 
     34 class OMXVideoDecoderBase : public OMXComponentCodecBase {
     35 public:
     36     OMXVideoDecoderBase();
     37     virtual ~OMXVideoDecoderBase();
     38 
     39 protected:
     40     virtual OMX_ERRORTYPE InitInputPort(void);
     41     virtual OMX_ERRORTYPE InitOutputPort(void);
     42     virtual OMX_ERRORTYPE InitInputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE *input) = 0;
     43     virtual OMX_ERRORTYPE InitOutputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE *output);
     44 
     45     virtual OMX_ERRORTYPE ProcessorInit(void);
     46     virtual OMX_ERRORTYPE ProcessorDeinit(void);
     47     virtual OMX_ERRORTYPE ProcessorStart(void);
     48     virtual OMX_ERRORTYPE ProcessorStop(void);
     49     virtual OMX_ERRORTYPE ProcessorPause(void);
     50     virtual OMX_ERRORTYPE ProcessorResume(void);
     51     virtual OMX_ERRORTYPE ProcessorFlush(OMX_U32 portIndex);
     52     virtual OMX_ERRORTYPE ProcessorProcess(
     53             OMX_BUFFERHEADERTYPE ***pBuffers,
     54             buffer_retain_t *retains,
     55             OMX_U32 numberBuffers);
     56     virtual OMX_ERRORTYPE ProcessorReset(void);
     57     virtual bool IsAllBufferAvailable(void);
     58     virtual OMX_ERRORTYPE SetMaxOutputBufferCount(OMX_PARAM_PORTDEFINITIONTYPE *p);
     59     virtual OMX_ERRORTYPE ProcessorPreFillBuffer(OMX_BUFFERHEADERTYPE* buffer);
     60     virtual OMX_ERRORTYPE ProcessorPreFreeBuffer(OMX_U32 nPortIndex,OMX_BUFFERHEADERTYPE * pBuffer);
     61     virtual OMX_ERRORTYPE PrepareConfigBuffer(VideoConfigBuffer *p);
     62     virtual OMX_ERRORTYPE PrepareDecodeBuffer(OMX_BUFFERHEADERTYPE *buffer, buffer_retain_t *retain, VideoDecodeBuffer *p);
     63     virtual OMX_ERRORTYPE PrepareDecodeNativeHandleBuffer(OMX_BUFFERHEADERTYPE *buffer, buffer_retain_t *retain, VideoDecodeBuffer *p);
     64     virtual OMX_ERRORTYPE FillRenderBuffer(OMX_BUFFERHEADERTYPE **pBuffer,  buffer_retain_t *retain,
     65                               OMX_U32 inportBufferFlags,  OMX_BOOL *isResolutionChange);
     66     virtual OMX_ERRORTYPE HandleFormatChange(void);
     67     virtual OMX_ERRORTYPE TranslateDecodeStatus(Decode_Status status);
     68     virtual OMX_COLOR_FORMATTYPE GetOutputColorFormat(int width);
     69     virtual OMX_ERRORTYPE BuildHandlerList(void);
     70     virtual OMX_ERRORTYPE SetDecoderOutputCropSpecific(OMX_PTR pStructure);
     71     virtual OMX_ERRORTYPE GetDecoderOutputCropSpecific(OMX_PTR pStructure);
     72     virtual OMX_ERRORTYPE GetNativeBufferUsageSpecific(OMX_PTR pStructure);
     73     virtual OMX_ERRORTYPE SetNativeBufferUsageSpecific(OMX_PTR pStructure);
     74     virtual OMX_ERRORTYPE SetNativeBufferModeSpecific(OMX_PTR pStructure);
     75     virtual OMX_ERRORTYPE GetNativeBufferModeSpecific(OMX_PTR pStructure);
     76 
     77     DECLARE_HANDLER(OMXVideoDecoderBase, ParamVideoPortFormat);
     78     DECLARE_HANDLER(OMXVideoDecoderBase, CapabilityFlags);
     79     DECLARE_HANDLER(OMXVideoDecoderBase, NativeBufferUsage);
     80     DECLARE_HANDLER(OMXVideoDecoderBase, NativeBuffer);
     81     DECLARE_HANDLER(OMXVideoDecoderBase, NativeBufferMode);
     82     DECLARE_HANDLER(OMXVideoDecoderBase, DecoderRotation);
     83     DECLARE_HANDLER(OMXVideoDecoderBase, DecoderOutputCrop);
     84 #ifdef TARGET_HAS_ISV
     85     DECLARE_HANDLER(OMXVideoDecoderBase, DecoderVppBufferNum);
     86 #endif
     87     DECLARE_HANDLER(OMXVideoDecoderBase, StoreMetaDataMode);
     88     DECLARE_HANDLER(OMXVideoDecoderBase, ErrorReportMode);
     89     DECLARE_HANDLER(OMXVideoDecoderBase, CodecPriority);
     90     DECLARE_HANDLER(OMXVideoDecoderBase, DecoderOperatingRate);
     91 
     92 private:
     93     enum {
     94         // OMX_PARAM_PORTDEFINITIONTYPE
     95         INPORT_MIN_BUFFER_COUNT = 1,
     96         INPORT_ACTUAL_BUFFER_COUNT = 256,
     97         INPORT_BUFFER_SIZE = 1382400,
     98 
     99         // OMX_PARAM_PORTDEFINITIONTYPE
    100         OUTPORT_MIN_BUFFER_COUNT = 1,
    101         OUTPORT_ACTUAL_BUFFER_COUNT = 4,
    102         OUTPORT_BUFFER_SIZE = 1382400,
    103 
    104         OUTPORT_NATIVE_BUFFER_COUNT = 10,
    105     };
    106 
    107     struct GraphicBufferParam {
    108         uint32_t graphicBufferHStride;
    109         uint32_t graphicBufferVStride;
    110         uint32_t graphicBufferWidth;
    111         uint32_t graphicBufferHeight;
    112         uint32_t graphicBufferColorFormat;
    113     };
    114     uint32_t mRotationDegrees;
    115 #ifdef TARGET_HAS_ISV
    116     uint32_t mVppBufferNum;
    117 #endif
    118 
    119     // Codec priority. Higher value means lower priority
    120     // Currently, only two levels are supported:
    121     // 0: realtime priority - This will only be used by
    122     //    media playback, capture, and possibly by realtime
    123     //    communication scenarios if best effort performance is not suitable.
    124     // 1: non-realtime priority (best effort). This is the default value.
    125     uint32_t mCodecPriority;
    126 
    127     uint32_t mOperatingRate;
    128 
    129 protected:
    130     IVideoDecoder *mVideoDecoder;
    131     int  mNativeBufferCount;
    132     enum WorkingMode {
    133         GRAPHICBUFFER_MODE,
    134         RAWDATA_MODE,
    135     };
    136     WorkingMode mWorkingMode;
    137     bool mErrorReportEnabled;
    138     GraphicBufferParam mGraphicBufferParam;
    139     uint32_t mOMXBufferHeaderTypePtrNum;
    140     OMX_BUFFERHEADERTYPE *mOMXBufferHeaderTypePtrArray[MAX_GRAPHIC_BUFFER_NUM];
    141 
    142     enum AdaptivePlaybackMode {
    143         METADATA_MODE,
    144         LEGACY_MODE,
    145     };
    146     AdaptivePlaybackMode mAPMode;
    147     uint32_t mMetaDataBuffersNum;
    148     OMX_TICKS mFlushMode;
    149     bool mFormatChanged;
    150     uint32_t getStride(uint32_t width);
    151 };
    152 
    153 #endif /* OMX_VIDEO_DECODER_BASE_H_ */
    154