1/* 2 * Copyright 2014 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 SOFT_VIDEO_ENCODER_OMX_COMPONENT_H_ 18 19#define SOFT_VIDEO_ENCODER_OMX_COMPONENT_H_ 20 21#include <media/IOMX.h> 22 23#include "SimpleSoftOMXComponent.h" 24 25struct hw_module_t; 26 27namespace android { 28 29struct SoftVideoEncoderOMXComponent : public SimpleSoftOMXComponent { 30 SoftVideoEncoderOMXComponent( 31 const char *name, 32 const char *componentRole, 33 OMX_VIDEO_CODINGTYPE codingType, 34 const CodecProfileLevel *profileLevels, 35 size_t numProfileLevels, 36 int32_t width, 37 int32_t height, 38 const OMX_CALLBACKTYPE *callbacks, 39 OMX_PTR appData, 40 OMX_COMPONENTTYPE **component); 41 42 virtual OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index, const OMX_PTR param); 43 virtual OMX_ERRORTYPE internalGetParameter(OMX_INDEXTYPE index, OMX_PTR params); 44 45protected: 46 void initPorts( 47 OMX_U32 numInputBuffers, OMX_U32 numOutputBuffers, OMX_U32 outputBufferSize, 48 const char *mime, OMX_U32 minCompressionRatio = 1); 49 50 static void setRawVideoSize(OMX_PARAM_PORTDEFINITIONTYPE *def); 51 52 static void ConvertFlexYUVToPlanar( 53 uint8_t *dst, size_t dstStride, size_t dstVStride, 54 struct android_ycbcr *ycbcr, int32_t width, int32_t height); 55 56 static void ConvertYUV420SemiPlanarToYUV420Planar( 57 const uint8_t *inYVU, uint8_t* outYUV, int32_t width, int32_t height); 58 59 static void ConvertRGB32ToPlanar( 60 uint8_t *dstY, size_t dstStride, size_t dstVStride, 61 const uint8_t *src, size_t width, size_t height, size_t srcStride, 62 bool bgr); 63 64 const uint8_t *extractGraphicBuffer( 65 uint8_t *dst, size_t dstSize, const uint8_t *src, size_t srcSize, 66 size_t width, size_t height) const; 67 68 virtual OMX_ERRORTYPE getExtensionIndex(const char *name, OMX_INDEXTYPE *index); 69 70 OMX_ERRORTYPE validateInputBuffer(const OMX_BUFFERHEADERTYPE *inputBufferHeader); 71 72 enum { 73 kInputPortIndex = 0, 74 kOutputPortIndex = 1, 75 }; 76 77 bool mInputDataIsMeta; 78 int32_t mWidth; // width of the input frames 79 int32_t mHeight; // height of the input frames 80 uint32_t mBitrate; // target bitrate set for the encoder, in bits per second 81 uint32_t mFramerate; // target framerate set for the encoder, in Q16 format 82 OMX_COLOR_FORMATTYPE mColorFormat; // Color format for the input port 83 84private: 85 void updatePortParams(); 86 OMX_ERRORTYPE internalSetPortParams(const OMX_PARAM_PORTDEFINITIONTYPE* port); 87 88 static const uint32_t kInputBufferAlignment = 1; 89 static const uint32_t kOutputBufferAlignment = 2; 90 91 mutable const hw_module_t *mGrallocModule; 92 93 uint32_t mMinOutputBufferSize; 94 uint32_t mMinCompressionRatio; 95 96 const char *mComponentRole; 97 OMX_VIDEO_CODINGTYPE mCodingType; 98 const CodecProfileLevel *mProfileLevels; 99 size_t mNumProfileLevels; 100 101 DISALLOW_EVIL_CONSTRUCTORS(SoftVideoEncoderOMXComponent); 102}; 103 104} // namespace android 105 106#endif // SOFT_VIDEO_ENCODER_OMX_COMPONENT_H_ 107