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