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