1 /* 2 * Copyright (C) 2011 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 ****************************************************************************** 18 * @file M4PTO3GPP_InternalTypes.h 19 * @brief Picture to 3gpp Service internal definitions 20 * @note This file contains all enum and types not visible to the external world. 21 ****************************************************************************** 22 */ 23 24 25 #ifndef __M4PTO3GPP_INTERNALTYPES_H__ 26 #define __M4PTO3GPP_INTERNALTYPES_H__ 27 28 #define M4PTO3GPP_VERSION_MAJOR 3 29 #define M4PTO3GPP_VERSION_MINOR 0 30 #define M4PTO3GPP_VERSION_REVISION 6 31 32 /** 33 * M4PTO3GPP public API and types */ 34 #include "M4PTO3GPP_API.h" 35 #include "M4_Utils.h" 36 37 /** 38 * Internally used modules */ 39 40 #include "M4WRITER_common.h" /* Write 3GPP file */ 41 #include "M4READER_Common.h" /* Read AMR file */ 42 #include "M4ENCODER_common.h" 43 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /** 50 ****************************************************************************** 51 * enum M4PTO3GPP_States 52 * @brief Main state machine of the M4PTO3GPP. 53 ****************************************************************************** 54 */ 55 typedef enum 56 { 57 M4PTO3GPP_kState_CREATED = 0, /**< M4PTO3GPP_Init has been called */ 58 M4PTO3GPP_kState_OPENED = 1, /**< M4PTO3GPP_Open has been called */ 59 M4PTO3GPP_kState_READY = 2, /**< Step can be called */ 60 M4PTO3GPP_kState_FINISHED = 3, /**< Transcoding is finished */ 61 M4PTO3GPP_kState_CLOSED = 4 /**< Output file has been created */ 62 } 63 M4PTO3GPP_States; 64 65 /** 66 ****************************************************************************** 67 * enum M4PTO3GPP_StreamState 68 * @brief State of a media stream encoding (audio or video). 69 ****************************************************************************** 70 */ 71 typedef enum 72 { 73 M4PTO3GPP_kStreamState_NOSTREAM = 0, /**< No stream present */ 74 M4PTO3GPP_kStreamState_STARTED = 1, /**< The stream encoding is in progress */ 75 M4PTO3GPP_kStreamState_FINISHED = 2 /**< The stream has finished encoding */ 76 } 77 M4PTO3GPP_StreamState; 78 79 /* 80 * Definition of max AU size */ 81 #define M4PTO3GPP_VIDEO_MIN_COMPRESSION_RATIO 0.8F /**< Max AU size will be 0.8 times the 82 YUV4:2:0 frame size */ 83 #define M4PTO3GPP_VIDEO_AU_SIZE_TO_CHUNCK_SIZE_RATIO 1.2F /**< Max chunk size will be 1.2 times 84 the max AU size */ 85 #define M4PTO3GPP_AUDIO_MAX_AU_SIZE 1000 /**< AAC max AU size seems to be 86 about 850 bytes */ 87 #define M4PTO3GPP_AUDIO_MAX_CHUNK_SIZE 5000 88 89 /** 90 ****************************************************************************** 91 * enum anonymous enum 92 * @brief enum to keep track of the encoder state 93 ****************************************************************************** 94 */ 95 enum 96 { 97 M4PTO3GPP_kNoEncoder, 98 M4PTO3GPP_kEncoderClosed, 99 M4PTO3GPP_kEncoderStopped, 100 M4PTO3GPP_kEncoderRunning 101 }; 102 103 /** 104 ****************************************************************************** 105 * structure M4PTO3GPP_InternalContext 106 * @brief This structure defines the M4PTO3GPP context (private) 107 * @note This structure is used for all M4PTO3GPP calls to store the context 108 ****************************************************************************** 109 */ 110 typedef struct 111 { 112 /** 113 * M4PTO3GPP main variables */ 114 M4PTO3GPP_States m_State; /**< M4PTO3GPP internal state */ 115 M4PTO3GPP_Params m_Params; /**< M4PTO3GPP parameters, set by the user */ 116 M4PTO3GPP_StreamState m_VideoState; /**< State of the video encoding */ 117 M4PTO3GPP_StreamState m_AudioState; /**< State of the audio encoding */ 118 119 /** 120 * OSAL file read/write functions */ 121 M4OSA_FileReadPointer* pOsalFileRead; /**< OSAL file read functions, 122 to be provided by user */ 123 M4OSA_FileWriterPointer* pOsalFileWrite; /**< OSAL file write functions, 124 to be provided by user */ 125 126 /** 127 * Reader stuff */ 128 M4_AccessUnit* m_pReaderAudioAU; /**< Read audio access unit */ 129 M4_AudioStreamHandler* m_pReaderAudioStream;/**< Description of the read audio stream */ 130 131 /** 132 * Writer stuff */ 133 M4SYS_AccessUnit m_WriterVideoAU; /**< Written video access unit */ 134 M4SYS_AccessUnit m_WriterAudioAU; /**< Written audio access unit */ 135 M4ENCODER_Header* m_pEncoderHeader; /**< Sequence header returned by the 136 encoder at encoder create (if any) */ 137 M4SYS_StreamDescription* m_pWriterVideoStream; /**< Description of the written 138 video stream */ 139 M4SYS_StreamDescription* m_pWriterAudioStream; /**< Description of the written 140 audio stream */ 141 M4WRITER_StreamVideoInfos* m_pWriterVideoStreamInfo; /**< Video properties of the written 142 video stream */ 143 M4WRITER_StreamAudioInfos* m_pWriterAudioStreamInfo; /**< Audio properties of the written 144 audio stream */ 145 146 /** 147 * Contexts of the used modules */ 148 M4OSA_Void* m_pAudioReaderContext; /**< Context of the audio reader module*/ 149 M4OSA_Void* m_p3gpWriterContext; /**< Context of the 3GP writer module */ 150 M4OSA_Void* m_pMp4EncoderContext; /**< Mp4 encoder context */ 151 M4OSA_UInt32 m_eEncoderState; 152 153 /** 154 * Reader Interfaces */ 155 M4READER_GlobalInterface* m_pReaderGlobInt; /**< Reader common interface, global part */ 156 M4READER_DataInterface* m_pReaderDataInt; /**< Reader common interface, data part */ 157 158 /** 159 * Writer Interfaces */ 160 M4WRITER_GlobalInterface* m_pWriterGlobInt; /**< Writer common interface, global part */ 161 M4WRITER_DataInterface* m_pWriterDataInt; /**< Writer common interface, data part */ 162 163 /** 164 * Encoder Interfaces */ 165 M4ENCODER_GlobalInterface* m_pEncoderInt; /**< Encoder common interface */ 166 M4OSA_Void* m_pEncoderExternalAPI; 167 M4OSA_Void* m_pEncoderUserData; 168 169 /** 170 * */ 171 M4VIFI_ImagePlane* pSavedPlane; 172 M4OSA_UInt32 uiSavedDuration; 173 174 /** 175 * Video rate control stuff */ 176 M4_MediaTime m_dLastVideoRegulCts; /**< Last time (CTS) the video bitrate 177 regulation has been called */ 178 M4_MediaTime m_mtCts; /**< Current video cts */ 179 M4_MediaTime m_mtNextCts; /**< Next video CTS to transcode */ 180 M4_MediaTime m_mtAudioCts; /**< Current audio cts */ 181 M4_MediaTime m_AudioOffSet; /**< Audio Offset to add to the cts in loop mode*/ 182 M4_MediaTime m_PrevAudioCts; /**< Previous audio cts for AAC looping */ 183 M4_MediaTime m_DeltaAudioCts; /**< Delta audio cts for AAC looping */ 184 M4OSA_UInt32 m_CurrentFileSize; /**< Current Output file size */ 185 M4OSA_UInt32 m_MaxFileSize; /**< Max Output file size */ 186 M4OSA_Bool m_IsLastPicture; /**< A boolean that signals to the encoder that 187 this is the last frame to be encoded*/ 188 M4OSA_Bool m_bLastInternalCallBack; 189 M4OSA_UInt32 m_NbCurrentFrame; /**< Index of the current YUV frame encoded */ 190 191 /** 192 * Audio padding mode */ 193 M4OSA_Bool m_bAudioPaddingSilence; /**< A boolean that signals that audio 194 AU will be padded by silence */ 195 } M4PTO3GPP_InternalContext; 196 197 198 199 /** 200 ****************************************************************************** 201 * M4OSA_ERR M4PTO3GPP_applyVPP(M4VPP_Context pContext, M4VIFI_ImagePlane* pPlaneIn, 202 * M4VIFI_ImagePlane* pPlaneOut) 203 * @brief Call an external callback to get the picture to encode 204 * @note It is called by the video encoder 205 * @param pContext (IN) VPP context, which actually is the M4PTO3GPP 206 * internal context in our case 207 * @param pPlaneIn (IN) Contains the image 208 * @param pPlaneOut (IN/OUT) Pointer to an array of 3 planes that will contain the 209 * output YUV420 image read with the m_pPictureCallbackFct 210 * @return M4NO_ERROR: No error 211 * @return Any error returned by an underlaying module 212 ****************************************************************************** 213 */ 214 M4OSA_ERR M4PTO3GPP_applyVPP(M4VPP_Context pContext, M4VIFI_ImagePlane* pPlaneIn, 215 M4VIFI_ImagePlane* pPlaneOut); 216 217 218 #ifdef __cplusplus 219 } 220 #endif 221 222 #endif /* __M4PTO3GPP_INTERNALTYPES_H__ */ 223 224