1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #ifndef MPEG4_ENC_H_INCLUDED 19 #define MPEG4_ENC_H_INCLUDED 20 21 22 #ifndef OSCL_MEM_H_INCLUDED 23 #include "oscl_mem.h" 24 #endif 25 26 #ifndef OMX_Component_h 27 #include "OMX_Component.h" 28 #endif 29 30 #ifndef _MP4ENC_API_H_ 31 #include "mp4enc_api.h" 32 #endif 33 34 #ifndef CCRGB24TOYUV420_H_INCLUDED 35 #include "ccrgb24toyuv420.h" 36 #endif 37 38 #ifndef CCRGB12TOYUV420_H_INCLUDED 39 #include "ccrgb12toyuv420.h" 40 #endif 41 42 #ifndef CCYUV420SEMITOYUV420_H_INCLUDED 43 #include "ccyuv420semitoyuv420.h" 44 #endif 45 46 const uint32 DEFAULT_VOL_HEADER_LENGTH = 28; 47 const uint32 PVMFTIMESTAMP_LESSTHAN_THRESHOLD = 0x80000000; 48 49 enum 50 { 51 MODE_H263 = 0, 52 MODE_MPEG4 53 }; 54 55 56 class Mpeg4Encoder_OMX 57 { 58 public: 59 60 Mpeg4Encoder_OMX(); 61 62 OMX_ERRORTYPE Mp4EncInit(OMX_S32 iEncMode, 63 OMX_VIDEO_PORTDEFINITIONTYPE aInputParam, 64 OMX_CONFIG_ROTATIONTYPE aInputOrientationType, 65 OMX_VIDEO_PORTDEFINITIONTYPE aEncodeParam, 66 OMX_VIDEO_PARAM_MPEG4TYPE aEncodeMpeg4Param, 67 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE aErrorCorrection, 68 OMX_VIDEO_PARAM_BITRATETYPE aRateControlType, 69 OMX_VIDEO_PARAM_QUANTIZATIONTYPE aQuantType, 70 OMX_VIDEO_PARAM_MOTIONVECTORTYPE aSearchRange, 71 OMX_VIDEO_PARAM_INTRAREFRESHTYPE aIntraRefresh, 72 OMX_VIDEO_PARAM_H263TYPE aH263Type, 73 OMX_VIDEO_PARAM_PROFILELEVELTYPE* aProfileLevel); 74 75 76 OMX_BOOL Mp4EncodeVideo(OMX_U8* aOutBuffer, 77 OMX_U32* aOutputLength, 78 OMX_BOOL* aBufferOverRun, 79 OMX_U8** aOverBufferPointer, 80 OMX_U8* aInBuffer, 81 OMX_U32 aInBufSize, 82 OMX_TICKS aInTimeStamp, 83 OMX_TICKS* aOutTimeStamp, 84 OMX_BOOL* aSyncFlag); 85 86 OMX_ERRORTYPE Mp4RequestIFrame(); 87 OMX_BOOL Mp4UpdateBitRate(OMX_U32 aEncodedBitRate); 88 OMX_BOOL Mp4UpdateFrameRate(OMX_U32 aEncodeFramerate); 89 90 OMX_ERRORTYPE Mp4EncDeinit(); 91 92 93 private: 94 95 void CopyToYUVIn(uint8* YUV, int width, int height, int width_16, int height_16); 96 97 /* RGB->YUV conversion */ 98 ColorConvertBase *ccRGBtoYUV; 99 100 //Routine to compare two timestamps a and b 101 OMX_BOOL LessThan(uint32& a, uint32& b, uint32 Threshold); 102 103 VideoEncControls iEncoderControl; 104 OMX_BOOL iInitialized; 105 OMX_COLOR_FORMATTYPE iVideoFormat; 106 107 int iSrcWidth; 108 int iSrcHeight; 109 int iFrameOrientation; 110 uint32 iSrcFrameRate; 111 uint8* iYUVIn; 112 uint8* iVideoIn; 113 uint8* iVideoOut; 114 uint32 iNextModTime; 115 MP4HintTrack iHintTrack; 116 MP4EncodingMode ENC_Mode; 117 118 OMX_U8 iVolHeader[DEFAULT_VOL_HEADER_LENGTH]; /** Vol header */ 119 OMX_U32 iVolHeaderSize; 120 OMX_BOOL iVolHeaderFlag; 121 122 bool iSupport64bitTimestamp; 123 124 }; 125 126 127 #endif ///#ifndef MPEG4_ENC_H_INCLUDED 128