1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Definition for CMPEG4Transcoder, a class for MPEG4 transcoder |
|
17 * working at video packet level or MB level. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 #ifndef __VMPEG4TRANSCODER_H__ |
|
24 #define __VMPEG4TRANSCODER_H__ |
|
25 |
|
26 |
|
27 /* |
|
28 * Includes (header files are copied from core_mpeg.cpp) |
|
29 */ |
|
30 #include <e32base.h> |
|
31 |
|
32 #include <vedcommon.h> |
|
33 #include "h263dConfig.h" |
|
34 #include "vdc263.h" |
|
35 #include "core.h" |
|
36 #include "debug.h" |
|
37 #include "decblock.h" /* for dblFree and dblLoad */ |
|
38 #include "decvp_mpeg.h" |
|
39 #include "h263dapi.h" /* for H263D_BC_MUX_MODE_SEPARATE_CHANNEL and H263D_ERD_ */ |
|
40 #include "vdeimb.h" |
|
41 #include "viddemux.h" |
|
42 #include "vdxint.h" |
|
43 #include "vde.h" |
|
44 #include "vdemain.h" |
|
45 #include "biblin.h" |
|
46 #include "mpegcons.h" |
|
47 #include "h263dmai.h" |
|
48 #include "decpich.h" |
|
49 #include "decmbdct.h" |
|
50 #include "common.h" |
|
51 #include "sync.h" |
|
52 #include "vdcaic.h" |
|
53 #include "zigzag.h" |
|
54 #include "debug.h" |
|
55 |
|
56 #ifndef VDTASSERT |
|
57 // An assertion macro wrapper to clean up the code a bit |
|
58 #define VDTASSERT(x) __ASSERT_DEBUG(x, User::Panic(_L("CMPEG4Transcoder"), EInternalAssertionFailure)) |
|
59 #endif |
|
60 |
|
61 |
|
62 |
|
63 /* Get information about video bitstream */ |
|
64 int vdtGetVideoBitstreamInfo(bibBuffer_t *inBuffer, vdeDecodeParamters_t *aInfoOut, int *aByteIndex, int *aBitIndex); |
|
65 |
|
66 /* Finds the error resilience bit in MPEG-4 VOL and change it, if necessary, to make it Regular Resynchronization mode */ |
|
67 TBool vdtChangeVosHeaderRegResyncL(TPtrC8& aInputBuffer, TUint aBufferSize); |
|
68 |
|
69 |
|
70 #define DefaultTimeIncResolution 3000/1001 |
|
71 |
|
72 // unify error codes |
|
73 #define TX_OK H263D_OK |
|
74 #define TX_ERR H263D_ERROR |
|
75 |
|
76 /* |
|
77 * CopyEditVop |
|
78 * |
|
79 * |
|
80 * Parameters: |
|
81 * hInstance instance handle |
|
82 * |
|
83 * Function: |
|
84 * This function copies the VOP header with edited time stamps of the VOP. |
|
85 * |
|
86 * Params |
|
87 * @param hInstance is handle instance itself |
|
88 * @param aNrBytesToSkip number of bytes to jump over in the beginning of output buffer (e.g. MPEG4 VOS header) |
|
89 * @param inBuffer is the input buffer |
|
90 * @param aDecoderInfo structure with decode params |
|
91 */ |
|
92 |
|
93 int CopyEditVop(vdeHInstance_t hInstance, int aNrOfBytesToSkip, bibBuffer_t * inBuffer, vdeDecodeParamters_t *aDecoderInfo); |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 /* |
|
99 * CopyEditVideoPacket |
|
100 * |
|
101 * |
|
102 * Parameters: |
|
103 * |
|
104 * Function: |
|
105 * This function copies the video packet with edited time stamps, if HEC is enabled |
|
106 * |
|
107 * Returns: |
|
108 * Success or failure |
|
109 */ |
|
110 int CopyEditVideoPacket(bibBuffer_t* inBuffer, |
|
111 bibBuffer_t* outBuffer, |
|
112 bibBufferEdit_t* aBufEdit, |
|
113 vdcInstance_t * vdcTemp, |
|
114 vdeDecodeParamters_t *aDecoderInfo, |
|
115 vdxVopHeader_t* vopheader, |
|
116 int* aSncCode, |
|
117 int* startByteIndex, |
|
118 int* startBitIndex); |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 /* |
|
125 * Classes |
|
126 */ |
|
127 |
|
128 /* General transcoding class |
|
129 * contains all necessary transcoding information |
|
130 * accessible from various points in the decoder module |
|
131 */ |
|
132 class CMPEG4Transcoder : public CBase |
|
133 { |
|
134 public: |
|
135 |
|
136 static CMPEG4Transcoder* NewL (const vdeInstance_t *aVDEInstance, bibBuffer_t *aInBuffer, bibBuffer_t *aOutBuffer); |
|
137 |
|
138 /* Destructor */ |
|
139 ~CMPEG4Transcoder(); |
|
140 |
|
141 /* Indicates whether we need to do MPEG4 bitstream transcoding */ |
|
142 int SetTranscoding(vdeDecodeParamters_t *aDecoderInfo); |
|
143 |
|
144 /* Copy the VOP Header to output buffer */ |
|
145 void VOPHeaderEnded(int aStartByteIndex, int aStartBitIndex, |
|
146 int aQuant, int aPicType, int aFrameNum, int aVOPNotCoded); |
|
147 /* One VOP ended */ |
|
148 void VOPEnded(); |
|
149 /* Record the position before one video packet is processed */ |
|
150 void BeginOneVideoPacket(dvpVPInParam_t *aVPin); |
|
151 /* Record the position before the content of the video packet is processed (called after retreiving the video packet) */ |
|
152 void AfterVideoPacketHeader(dvpVPInOutParam_t *aVPInfo); |
|
153 /* Called after one video packet's contents are retrieved */ |
|
154 void OneVPEnded(); |
|
155 /* Add one IMB instance for I macroblock */ |
|
156 void OneIMBDataStartedDataPartitioned(vdxIMBListItem_t *aMBInstance, dlst_t *aMBList, int aCurrMBNumInVP, int aMBNum); |
|
157 /* Add one PMB instance for P macroblock */ |
|
158 void OnePMBDataStartedDataPartitioned(vdxPMBListItem_t *aMBInstance, dlst_t *aMBList, int aCurrMBNumInVP, int aMBNum); |
|
159 /* Records the position of vop_time_increment_resolution bit */ |
|
160 void MPEG4TimerResolution(int aStartByteIndex, int aStartBitIndex); |
|
161 /* Creates a new H263 macroblock */ |
|
162 int ConstructH263MBData(dmdPParam_t *aParam, int aNewMCBPCLen, int aNewMCBPC); |
|
163 /* Transcode one H263 MB to one MPEG4 MB */ |
|
164 void H263ToMPEG4MBData(int aNewMCBPCLen, int aNewMCBPC); |
|
165 /* fills the reconstructed DCAC values for INTRA block */ |
|
166 void AddOneBlockDCACrecon(int aIndex, int *aDCAC); |
|
167 /* Record MB parameters before the content of the MB is processed (called after retreiving the MB layer) */ |
|
168 void AfterMBLayer(int aUpdatedQp); |
|
169 /* returns first frame QP */ |
|
170 inline int GetRefQP() { return iRefQuant; } |
|
171 |
|
172 |
|
173 /* returns 1 if we need the decoded frame */ |
|
174 int NeedDecodedYUVFrame(); |
|
175 /* Record the position before one MB is processed */ |
|
176 void BeginOneMB(int aMBNum); |
|
177 /* Record the position before one block in MB is processed */ |
|
178 void BeginOneBlock(int aIndex); |
|
179 /* Start one IMB (called after the MB header is read) */ |
|
180 void OneIMBDataStarted(vdxIMBListItem_t *aMBInstance); |
|
181 /* Start one PMB (called after the MB header is read) */ |
|
182 void OnePMBDataStarted(vdxPMBListItem_t *aMBInstance); |
|
183 /* Input one block data to current MB */ |
|
184 void AddOneBlockDataToMB(int aBlockIndex, int *aBlockData); |
|
185 /* Indicates if escape vlc coding is used in one block */ |
|
186 void H263EscapeCoding(int aIndex, int fEscapeCodeUsed); |
|
187 /* Records the position of resnc_marker_disable bit */ |
|
188 void ErrorResilienceInfo(vdxVolHeader_t *header, int aByte, int aBit); |
|
189 /* Constructs the VOS header */ |
|
190 void ConstructVOSHeader(int aMPEG4, vdeDecodeParamters_t *aDecoderInfo); |
|
191 /* Called after one H263 GOB or slice header is parsed */ |
|
192 void H263GOBSliceHeaderEnded(vdxGOBHeader_t *aH263GOBHeader, vdxSliceHeader_t *aH263SliceHeader); |
|
193 /* Called after one H263 picture header is parsed */ |
|
194 int H263PictureHeaderEnded(dphOutParam_t *aH263PicHeader, dphInOutParam_t *aInfo); |
|
195 /* Called before one H.63 GOB or slice header is parsed */ |
|
196 void H263GOBSliceHeaderBegin(); |
|
197 /* Called after one H263 GOB or Slice ends */ |
|
198 void H263OneGOBSliceEnded(int nextExpectedMBNum); |
|
199 /* Called after one GOB (slice) that has GOB header (except the first GOB) ends */ |
|
200 void H263OneGOBSliceWithHeaderEnded(); |
|
201 /* Transcodes one macroblock (may include dequantization, requantization, and re-encoding) */ |
|
202 int TranscodingOneMB(dmdPParam_t *aParam); |
|
203 |
|
204 private: |
|
205 /* Constructors */ |
|
206 CMPEG4Transcoder(const vdeInstance_t *aVDEInstance, bibBuffer_t *aInBuffer, bibBuffer_t *aOutBuffer); |
|
207 |
|
208 /*Constructl to allocate necessary resources*/ |
|
209 void ConstructL(); |
|
210 |
|
211 // main functions to perform transcoding for one macroblock |
|
212 /* Transcode MB - rearranges data partitioned bitstream data to regular */ |
|
213 void ConstructRegularMPEG4MBData(int aNewMCBPCLen, int aNewMCBPC); |
|
214 /* Resets the DCs for U/V blocks in intra MB */ |
|
215 void ResetMPEG4IntraDcUV(); |
|
216 /* Recontruct IMB partitions for color effect when we are not doing format transcoding */ |
|
217 void ReconstructIMBPartitions(); |
|
218 /* Recontruct PMB partitions for color effect when we are not doing format transcoding */ |
|
219 void ReconstructPMBPartitions(); |
|
220 /* Evaluate Chrominance DC Scaler from QP for MPEG4 */ |
|
221 int GetMpeg4DcScalerUV(int aQP); |
|
222 /* Evaluate IntraDC Coefficients for U,V blocks for MPEG4 */ |
|
223 void GetMPEG4IntraDcCoeffUV(TInt aValue, TInt& aSize, TInt& aSizeCode, |
|
224 TInt& aSizeCodeLength, TInt& aValueCode, TInt& aValueCodeLength); |
|
225 |
|
226 |
|
227 |
|
228 private: |
|
229 |
|
230 /* Output data buffer */ |
|
231 bibBuffer_t *iOutBuffer; |
|
232 /* Operation modes */ |
|
233 TVedVideoBitstreamMode iBitStreamMode; |
|
234 |
|
235 /* |
|
236 When we do mode translation for MPEG4, the target mode may be MPEG4Resyn or H263 |
|
237 but for H263, when we do mode translation, the target mode is always MPG4Resyn |
|
238 */ |
|
239 |
|
240 /* Member variables */ |
|
241 |
|
242 /* Indicates the direction for MPEG4 mode translation */ |
|
243 int iTargetFormat; |
|
244 |
|
245 /* Input data buffer */ |
|
246 bibBuffer_t *iInBuffer; |
|
247 |
|
248 /* Indicates if we need to do transcoding for current MB */ |
|
249 int iDoTranscoding; |
|
250 |
|
251 /* Indicates if we need to do MPEG4 bitstream conversion */ |
|
252 int iDoModeTranscoding; |
|
253 |
|
254 /* Special Effect (Black and White) paramter */ |
|
255 int iColorEffect; |
|
256 |
|
257 /* color tone U,V value parameter */ |
|
258 TInt iColorToneU; |
|
259 TInt iColorToneV; |
|
260 |
|
261 /* Information we know about this frame and MB */ |
|
262 |
|
263 /* current VOP coding type */ |
|
264 int iVopCodingType; |
|
265 |
|
266 /* number of MBs in one VOP */ |
|
267 int iNumMBsInOneVOP; |
|
268 |
|
269 /* indicates if stuffing bits have been used */ |
|
270 int8 iStuffingBitsUsed; |
|
271 |
|
272 |
|
273 /* Only valid with resync_marker |
|
274 Information includes: |
|
275 MB number, quant_scale, StartByteIndex, StartBitIndex ... |
|
276 */ |
|
277 /* Contains CurMBNum, quant, frame number, etc */ |
|
278 dvpVPInOutParam_t *iCurVPInOut; |
|
279 /* Contains picture type, etc */ |
|
280 dvpVPInParam_t *iCurVPIn; |
|
281 /* VOL header */ |
|
282 vdxVolHeader_t iVOLHeader; |
|
283 |
|
284 /* position pointers at different levels */ |
|
285 int iVPStartByteIndex, iVPStartBitIndex; |
|
286 int iVPHeaderEndByteIndex, iVPHeaderEndBitIndex; |
|
287 int iTimeResolutionByteIndex, iTimeResolutionBitIndex; |
|
288 /* Array to store the DCT data */ |
|
289 int iDCTBlockData[BLOCK_COEFF_SIZE * 6]; /* YUV components */ |
|
290 int **iH263DCData; /* Intra DC matrix for H263 -> MPEG4 transcoding */ |
|
291 |
|
292 dlst_t *iMBList; |
|
293 tMBInfo* h263mbi; /* one frame MB information for MPEG4 to H263 transcoding */ |
|
294 int iPreQuant; /* last QUANT, used in MPEG4 to H263 transcoding */ |
|
295 |
|
296 /* used for color toning for MPEG4 */ |
|
297 u_char *iMBType; /* array indicating MB type for all MBs in VOP */ |
|
298 int iRefQuant; /* reference QP derived from 1st VOP of MPEG4 */ |
|
299 int iCurQuant; /* current QP */ |
|
300 int iDcScaler; /* DC Scaler for iRefQuant */ |
|
301 |
|
302 |
|
303 int *iH263MBVPNum; /* matrix recording the video packet number for each MB */ |
|
304 |
|
305 int iShortHeaderEndByteIndex , iShortHeaderEndBitIndex; |
|
306 |
|
307 /* iMBStartByteIndex, iMBStartBitIndex also record the postion |
|
308 right after the VP header when video packet is used |
|
309 */ |
|
310 int iMBStartByteIndex, iMBStartBitIndex; |
|
311 |
|
312 /* Positions of each block data including INTRA DC if it exists |
|
313 except for data partioning, in which it only indicates the ACs or DCTs |
|
314 */ |
|
315 int iBlockStartByteIndex[6], iBlockStartBitIndex[6]; |
|
316 int iBlockEndByteIndex[6], iBlockEndBitIndex[6]; |
|
317 int iErrorResilienceStartByteIndex, iErrorResilienceStartBitIndex; |
|
318 |
|
319 /*Added for Time Res 30000 */ |
|
320 int iOutputMpeg4TimeIncResolution; |
|
321 |
|
322 /* Processing data member */ |
|
323 const vdeInstance_t *iVDEInstance; |
|
324 |
|
325 /* Instance for current processing MB */ |
|
326 vdxIMBListItem_t *iCurIMBinstance; |
|
327 vdxPMBListItem_t *iCurPMBinstance; |
|
328 |
|
329 /* Temporary edit buffer */ |
|
330 bibBufferEdit_t bufEdit; |
|
331 |
|
332 /* Current and last processed MB */ |
|
333 int iCurMBNum; |
|
334 |
|
335 /* Last output MB number */ |
|
336 int iLastMBNum; |
|
337 |
|
338 /* current MB number in current video packet */ |
|
339 int iCurMBNumInVP; |
|
340 |
|
341 /* MB coding type: INTRA or INTER */ |
|
342 int iMBCodingType; |
|
343 |
|
344 /* Specific members only for H.263! */ |
|
345 int iGOBSliceStartByteIndex; |
|
346 int iGOBSliceStartBitIndex; |
|
347 int iGOBSliceHeaderEndByteIndex; |
|
348 int iGOBSliceHeaderEndBitIndex; |
|
349 |
|
350 /* Index of video packet in MPEG4 */ |
|
351 int iVideoPacketNumInMPEG4; |
|
352 /* Number of MBs in picture width */ |
|
353 int iMBsinWidth; |
|
354 /* Number of MBs in one GOB */ |
|
355 int iNumMBsInGOB; |
|
356 /* Indicates if its the first frame */ |
|
357 unsigned char fFirstFrameInH263; |
|
358 /* Indicates if escape vlc coding is used */ |
|
359 int iEscapeCodeUsed[6]; |
|
360 |
|
361 }; |
|
362 |
|
363 |
|
364 |
|
365 #endif /* __VMPEG4TRANSCODER_H__ */ |
|
366 |
|