159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ------------------------------------------------------------------ 259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Copyright (C) 1998-2009 PacketVideo 359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Licensed under the Apache License, Version 2.0 (the "License"); 559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * you may not use this file except in compliance with the License. 659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * You may obtain a copy of the License at 759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * http://www.apache.org/licenses/LICENSE-2.0 959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 1059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Unless required by applicable law or agreed to in writing, software 1159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * distributed under the License is distributed on an "AS IS" BASIS, 1259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 1359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * express or implied. 1459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * See the License for the specific language governing permissions 1559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * and limitations under the License. 1659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * ------------------------------------------------------------------- 1759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong */ 1859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*********************************************************************************/ 1959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* File: cvei.h */ 2059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Purpose: */ 2159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Date: */ 2259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Revision History: */ 2359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** @introduction Common Video Encoder Interface (CVEI) is intended to be used by 2459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong application developers who want to create a multimedia application with video 2559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong encoding feature. CVEI is designed such that new video encoder algorithms or 2659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong modules can be plugged in seamlessly without user interaction. In other words, 2759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong any changes to the CVEI library are transparent to the users. Users can still 2859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong use the same set of APIs for new encoding tools. 2959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 3059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong @requirement CVEI will take an input frame in one of several format supported 3159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong by PV and encode it to an MPEG4 bitstream. It will also return a reconstructed 3259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong image in YUV 4:2:0 format. Currently the input format supported are YUV 4:2:0, 3359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong RGB24 and UYVY 4:2:2. 3459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 3559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong CVEI is designed such that it is simple to use. It should hides implementation 3659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong dependency from the users. In this version, we decided that the operation will 3759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong be synchronous, i.e., the encoding will be a blocked call. Asynchronous operation 3859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong will be in the level above CVEI, i.e., in Author Engine Video Module which will 3959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong take care of capturing device as well. 4059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 4159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong @brief The following classes are used to interface with codecs. Their names 4259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong are CPVxxxVideoEncoder where xxx is codec specific such as MPEG4, H263, H26L, 4359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong etc. All of them are subclasses of CPVCommonVideoEncoder. 4459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong*/ 4559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/*********************************************************************************/ 4659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 4759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef __CVEI_H 4859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define __CVEI_H 4959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 5059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "oscl_scheduler_ao.h" 5159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "oscl_base.h" 5259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4enc_api.h" /* for MP4HintTrack */ 5359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 5459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#define MAX_LAYER 2 5559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 5659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** General returned values. */ 5759f566c4ec3dfc097ad8163523e522280b27e5c3James Dongenum TCVEI_RETVAL 5859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 5959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_SUCCESS, 6059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_FAIL, 6159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_FLUSH, 6259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_MORE_OUTPUT 6359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} ; 6459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 6559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** Returned events with the callback function. */ 6659f566c4ec3dfc097ad8163523e522280b27e5c3James Dongenum TCVEI_EVENT 6759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 6859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Called when a packet or a frame of output bitstream is ready. */ 6959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_BUFFER_READY, 7059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Called when the last packet of a frame of output bitstream is ready. */ 7259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_FRAME_DONE, 7359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Called when no buffers is available for output bitstream. A buffer can be added thru AddBuffer API. */ 7559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_NO_BUFFERS, 7659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Called when there is an error with the encoding operation. */ 7859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_ERROR 7959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 8059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 8159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** Contains supported input format */ 8259f566c4ec3dfc097ad8163523e522280b27e5c3James Dongenum TPVVideoFormat 8359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 8459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_RGB24, 8559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_RGB12, 8659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_YUV420, 8759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_UYVY, 8859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_YUV420SEMIPLANAR 8959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 9059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 9159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** Type of contents for optimal encoding mode. */ 9259f566c4ec3dfc097ad8163523e522280b27e5c3James Dongenum TPVContentType 9359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 9459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Content is to be streamed in real-time. */ 9559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_STREAMING, 9659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 9759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Content is to be downloaded and playbacked later.*/ 9859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_DOWNLOAD, 9959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 10059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Content is to be 3gpp baseline compliant. */ 10159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_H263 10259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 10359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 10459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** Rate control type. */ 10559f566c4ec3dfc097ad8163523e522280b27e5c3James Dongenum TMP4RateControlType 10659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 10759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Constant quality, variable bit rate, fixed quantization level. */ 10859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECONSTANT_Q, 10959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Short-term constant bit rate control. */ 11159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECBR_1, 11259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Long-term constant bit rate control. */ 11459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong EVBR_1 11559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 11659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** Targeted profile and level to encode. */ 11859f566c4ec3dfc097ad8163523e522280b27e5c3James Dongenum TPVM4VProfileLevel 11959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 12059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Non-scalable profile */ 12159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_SIMPLE_LEVEL0 = 0, 12259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_SIMPLE_LEVEL1, 12359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_SIMPLE_LEVEL2, 12459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_SIMPLE_LEVEL3, 12559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_CORE_LEVEL1, 12659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_CORE_LEVEL2, 12759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 12859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Scalable profile */ 12959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_SIMPLE_SCALABLE_LEVEL0 = 6, 13059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_SIMPLE_SCALABLE_LEVEL1, 13159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_SIMPLE_SCALABLE_LEVEL2, 13259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 13359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_CORE_SCALABLE_LEVEL1 = 10, 13459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_CORE_SCALABLE_LEVEL2, 13559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_CORE_SCALABLE_LEVEL3 13659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 13759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 13859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** This structure contains encoder settings. */ 13959f566c4ec3dfc097ad8163523e522280b27e5c3James Dongstruct TPVVideoEncodeParam 14059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 14159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies an ID that will be used to specify this encoder while returning 14259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong the bitstream in asynchronous mode. */ 14359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint32 iEncodeID; 14459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 14559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies whether base only (iNumLayer = 1) or base + enhancement layer 14659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (iNumLayer =2 ) is to be used. */ 14759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int32 iNumLayer; 14859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 14959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the width in pixels of the encoded frames. IFrameWidth[0] is for 15059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong base layer and iFrameWidth[1] is for enhanced layer. */ 15159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int iFrameWidth[MAX_LAYER]; 15259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 15359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the height in pixels of the encoded frames. IFrameHeight[0] is for 15459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong base layer and iFrameHeight[1] is for enhanced layer. */ 15559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int iFrameHeight[MAX_LAYER]; 15659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 15759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the cumulative bit rate in bit per second. IBitRate[0] is for base 15859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong layer and iBitRate[1] is for base+enhanced layer.*/ 15959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int iBitRate[MAX_LAYER]; 16059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 16159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the cumulative frame rate in frame per second. IFrameRate[0] is for 16259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong base layer and iFrameRate[1] is for base+enhanced layer. */ 16359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float iFrameRate[MAX_LAYER]; 16459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 16559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the picture quality factor on the scale of 1 to 10. It trades off 16659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong the picture quality with the frame rate. Higher frame quality means lower frame rate. 16759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Lower frame quality for higher frame rate.*/ 16859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int32 iFrameQuality; 16959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 17059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Enable the use of iFrameQuality to determine the frame rate. If it is false, 17159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong the encoder will try to meet the specified frame rate regardless of the frame quality.*/ 17259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong bool iEnableFrameQuality; 17359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 17459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the maximum number of P-frames between 2 INTRA frames. An INTRA mode is 17559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong forced to a frame once this interval is reached. When there is only one I-frame is present 17659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong at the beginning of the clip, iIFrameInterval should be set to -1. */ 17759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int32 iIFrameInterval; 17859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 17959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** According to iIFrameInterval setting, the minimum number of intra MB per frame is 18059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong optimally calculated for error resiliency. However, when iIFrameInterval is set to -1, 18159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong iNumIntraMBRefresh must be specified to guarantee the minimum number of intra 18259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong macroblocks per frame.*/ 18359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint32 iNumIntraMBRefresh; 18459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 18559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the VBV buffer size which determines the end-to-end delay between the 18659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong encoder and the decoder. The size is in unit of seconds. For download application, 18759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong the buffer size can be larger than the streaming application. For 2-way application, 18859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong this buffer shall be kept minimal. For a special case, in VBR mode, iBufferDelay will 18959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong be set to -1 to allow buffer underflow. */ 19059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float iBufferDelay; 19159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 19259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the type of the access whether it is streaming, CVEI_STREAMING 19359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (data partitioning mode) or download, CVEI_DOWNLOAD (combined mode).*/ 19459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong TPVContentType iContentType; 19559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 19659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the rate control algorithm among one of the following constant Q, 19759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong CBR and VBR. The structure TMP4RateControlType is defined below.*/ 19859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong TMP4RateControlType iRateControlType; 19959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 20059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies high quality but also high complexity mode for rate control. */ 20159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong bool iRDOptimal; 20259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 20359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the initial quantization parameter for the first I-frame. If constant Q 20459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rate control is used, this QP will be used for all the I-frames. This number must be 20559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong set between 1 and 31, otherwise, Initialize() will fail. */ 20659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int iIquant[2]; 20759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 20859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the initial quantization parameter for the first P-frame. If constant Q 20959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rate control is used, this QP will be used for all the P-frames. This number must be 21059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong set between 1 and 31, otherwise, Initialize() will fail. */ 21159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int iPquant[2]; 21259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 21359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the initial quantization parameter for the first B-frame. If constant Q 21459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rate control is used, this QP will be used for all the B-frames. This number must be 21559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong set between 1 and 31, otherwise, Initialize() will fail. */ 21659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int iBquant[2]; 21759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 21859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the search range in pixel unit for motion vector. The range of the 21959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong motion vector will be of dimension [-iSearchRange.5, +iSearchRange.0]. */ 22059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int32 iSearchRange; 22159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 22259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the use of 8x8 motion vectors. */ 22359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong bool iMV8x8; 22459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 22559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the use of half-pel motion vectors. */ 22659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong bool iMVHalfPel; 22759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 22859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies automatic scene detection where I-frame will be used the the first frame 22959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong in a new scene. */ 23059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong bool iSceneDetection; 23159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 23259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the packet size in bytes which represents the number of bytes between two resync markers. 23359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong For ECVEI_DOWNLOAD and ECVEI_H263, if iPacketSize is set to 0, there will be no resync markers in the bitstream. 23459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong For ECVEI_STREAMING is parameter must be set to a value greater than 0.*/ 23559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint32 iPacketSize; 23659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 23759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies whether the current frame skipping decision is allowed after encoding 23859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong the current frame. If there is no memory of what has been coded for the current frame, 23959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong iNoCurrentSkip has to be on. */ 24059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong bool iNoCurrentSkip; 24159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 24259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies that no frame skipping is allowed. Frame skipping is a tool used to 24359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong control the average number of bits spent to meet the target bit rate. */ 24459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong bool iNoFrameSkip; 24559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 24659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the duration of the clip in millisecond.*/ 24759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int32 iClipDuration; 24859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 24959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies the profile and level used to encode the bitstream. When present, 25059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong other settings will be checked against the range allowable by this target profile 25159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong and level. Fail may be returned from the Initialize call. */ 25259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong TPVM4VProfileLevel iProfileLevel; 25359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 25459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies FSI Buffer input */ 25559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint8* iFSIBuff; 25659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 25759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Specifies FSI Buffer Length */ 25859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int iFSIBuffLength; 25959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 26259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** Structure for input format information */ 26559f566c4ec3dfc097ad8163523e522280b27e5c3James Dongstruct TPVVideoInputFormat 26659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 26759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Contains the width in pixels of the input frame. */ 26859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int32 iFrameWidth; 26959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Contains the height in pixels of the input frame. */ 27159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int32 iFrameHeight; 27259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Contains the input frame rate in the unit of frame per second. */ 27459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong float iFrameRate; 27559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Contains Frame Orientation. Used for RGB input. 1 means Bottom_UP RGB, 0 means Top_Down RGB, -1 for video formats other than RGB*/ 27759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int iFrameOrientation; 27859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 27959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Contains the format of the input video, e.g., YUV 4:2:0, UYVY, RGB24, etc. */ 28059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong TPVVideoFormat iVideoFormat; 28159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 28259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 28359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 28459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** Contains the input data information */ 28559f566c4ec3dfc097ad8163523e522280b27e5c3James Dongstruct TPVVideoInputData 28659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 28759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Pointer to an input frame buffer in input source format.*/ 28859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint8 *iSource; 28959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 29059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** The corresponding time stamp of the input frame. */ 29159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint32 iTimeStamp; 29259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 29359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 29459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** Contains the output data information */ 29559f566c4ec3dfc097ad8163523e522280b27e5c3James Dongstruct TPVVideoOutputData 29659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 29759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Pointer to the reconstructed frame buffer in YUV 4:2:0 domain. */ 29859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint8 *iFrame; 29959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 30059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** The number of layer encoded, 0 for base, 1 for enhanced. */ 30159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int32 iLayerNumber; 30259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 30359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Pointer to the encoded bitstream buffer. */ 30459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint8 *iBitStream; 30559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 30659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** The size in bytes of iBStream. */ 30759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int32 iBitStreamSize; 30859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 30959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** The time stamp of the encoded frame according to the bitstream. */ 31059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint32 iVideoTimeStamp; 31159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 31259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** The time stamp of the encoded frame as given before the encoding. */ 31359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint32 iExternalTimeStamp; 31459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 31559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** The hint track information. */ 31659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong MP4HintTrack iHintTrack; 31759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 31859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 31959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** An observer class for callbacks to report the status of the CVEI */ 32059f566c4ec3dfc097ad8163523e522280b27e5c3James Dongclass MPVCVEIObserver 32159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 32259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong public: 32359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** The callback funtion with aEvent being one of TCVEIEvent enumeration. */ 32459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual void HandlePVCVEIEvent 32559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (uint32 aId, uint32 aEvent, uint32 aParam1 = 0) = 0; 32659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual ~MPVCVEIObserver() {} 32759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 32859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 32959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/** This class is the base class for codec specific interface class. 33059f566c4ec3dfc097ad8163523e522280b27e5c3James DongThe users must maintain an instance of the codec specific class throughout 33159f566c4ec3dfc097ad8163523e522280b27e5c3James Dongthe encoding session. 33259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong*/ 33359f566c4ec3dfc097ad8163523e522280b27e5c3James Dongclass CommonVideoEncoder : public OsclTimerObject 33459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 33559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong public: 33659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Constructor for CVEI class. */ 33759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong CommonVideoEncoder() : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PVEncoder") {}; 33859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 33959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Initialization function to set the input video format and the 34059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong encoding parameters. This function returns CVEI_ERROR if there is 34159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong any errors. Otherwise, the function returns CVEI_SUCCESS.*/ 34259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL Initialize(TPVVideoInputFormat *aVidInFormat, TPVVideoEncodeParam *aEncParam) = 0; 34359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 34459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Set the observer for asynchronous encoding mode. */ 34559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL SetObserver(MPVCVEIObserver *aObserver) = 0; 34659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 34759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Add a buffer to the queue of output buffers for output bitstream in 34859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong asynchronous encoding mode. */ 34959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL AddBuffer(TPVVideoOutputData *aVidOut) = 0; 35059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 35159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function sends in an input video data structure containing a source 35259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong frame and the associated timestamp. The encoded bitstream will be returned by 35359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong observer callback. 35459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong The above 3 APIs only replace EncodeFrame() API. Other APIs such as initialization 35559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong and update parameters remain the same. */ 35659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL Encode(TPVVideoInputData *aVidIn) = 0; 35759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 35859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function returns the maximum VBV buffer size such that the 35959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong application can allocate a buffer that guarantees to fit one frame.*/ 36059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual int32 GetBufferSize() = 0; 36159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 36259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function returns the VOL header part (starting from the VOS header) 36359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong of the encoded bitstream. This function must be called after Initialize. 36459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong The output is written to the memory (volHeader) allocated by the users.*/ 36559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL GetVolHeader(uint8 *volHeader, int32 *size, int32 layer) = 0; 36659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 36759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function sends in an input video data structure containing a source 36859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong frame and the associated timestamp. It returns an output video data structure 36959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong containing coded bit stream, reconstructed frame in YUV 4:2:0 (can be changed 37059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong to source format) and the timestamp associated with the coded frame. 37159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong The input timestamp may not correspond to the output timestamp. User can send 37259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong an input structure in without getting any encoded data back or getting an encoded 37359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong frame in the past. This function returns ECVEI_ERROR if there is any errors. 37459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Otherwise, the function returns ECVEI_SUCCESS. 37559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong In case of Overrun Buffer usage, it is possible that return value is ECVEI_MORE_OUTPUT 37659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong which indicates that frame cannot fit in the current buffer*/ 37759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL EncodeFrame(TPVVideoInputData *aVidIn, TPVVideoOutputData *aVidOut, int *aRemainingBytes 37859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef PVAUTHOR_PROFILING 37959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong , void *aParam1 = 0 38059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif 38159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ) = 0; 38259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 38359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** Before the termination of the encoding process, the users have to query 38459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong whether there are any encoded frame pending inside the CVEI. The returned value 38559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong will indicate whether there are more frames to be flushed (ECVEI_FLUSH). 38659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong FlushOutput has to be called until there are no more frames, i.e., it returns 38759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong ECVEI_SUCCESS. This function may be called during the encoding operation if 38859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong there is no input frame and the application does not want to waste the time 38959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong waiting for input frame. It can call this function to flush encoded frame 39059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong out of the memory. */ 39159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL FlushOutput(TPVVideoOutputData *aVidOut) = 0; 39259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 39359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function cleanup the CVEI allocated resources. */ 39459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL Terminate() = 0; 39559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 39659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /**This function dynamically changes the target bit rate of the encoder 39759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while encoding. aBitRate[n] is the new accumulate target bit rate of layer n. 39859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Successful update is returned with ECVEI_SUCCESS.*/ 39959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL UpdateBitRate(int32 aNumLayer, int32 *aBitRate) = 0; 40059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 40159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function dynamically changes the target frame rate of the encoder 40259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while encoding. aFrameRate[n] is the new accumulate target frame rate of 40359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong layer n. Successful update is returned with ECVEI_SUCCESS. */ 40459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL UpdateFrameRate(int32 aNumLayer, float *aFrameRate) = 0; 40559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 40659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function dynamically changes the I-Vop update interval while 40759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong encoding to a new value, aIFrameInterval. */ 40859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL UpdateIFrameInterval(int32 aIFrameInterval) = 0; 40959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 41059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function forces an I-Vop mode to the next frame to be encoded. */ 41159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual TCVEI_RETVAL IFrameRequest() = 0; 41259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 41359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function returns the input width of a specific layer 41459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (not necessarily multiple of 16). */ 41559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual int32 GetEncodeWidth(int32 aLayer) = 0; 41659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 41759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function returns the input height of a specific layer 41859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong (not necessarily multiple of 16). */ 41959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual int32 GetEncodeHeight(int32 aLayer) = 0; 42059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 42159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /** This function returns the target encoded frame rate of a specific layer. */ 42259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual float GetEncodeFrameRate(int32 aLayer) = 0; 42359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong protected: 42459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual void Run(void) = 0; 42559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong virtual void DoCancel(void) = 0; 42659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* internal enum */ 42759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong enum TCVEIState 42859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 42959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong EIdle, 43059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong EEncode 43159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong }; 43259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 43359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong TCVEIState iState; 43459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong uint32 iId; 43559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong}; 43659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 43759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif 438