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 * Picture header decoding functions. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #include "h263dConfig.h" |
|
23 |
|
24 #include "decpich.h" |
|
25 #include "debug.h" |
|
26 #include "vdeims.h" |
|
27 #include "vdeimb.h" |
|
28 #include "viddemux.h" |
|
29 #include "sync.h" |
|
30 |
|
31 |
|
32 /* |
|
33 * Global functions |
|
34 */ |
|
35 |
|
36 /* {{-output"dphGetPictureHeader.txt"}} */ |
|
37 /* |
|
38 * dphGetPictureHeader |
|
39 * |
|
40 * |
|
41 * Parameters: |
|
42 * inParam input parameters |
|
43 * inOutParam input/output parameters, these parameters |
|
44 * may be modified in the function |
|
45 * outParam output parameters |
|
46 * bitErrorIndication bit error indication, see biterr.h for |
|
47 * the possible values |
|
48 * |
|
49 * Function: |
|
50 * This function gets and decodes a picture header which should start |
|
51 * with a PSC at the current position of the bit buffer. At first, |
|
52 * the function reads the picture header fields from the bitstream. |
|
53 * Then, it checks whether the values of the fields are supported. |
|
54 * An unsupported value is interpreted as a bit error. Finally, |
|
55 * the function updates VDC instance data and output parameters |
|
56 * (according to the new picture header). |
|
57 * |
|
58 * Returns: |
|
59 * DPH_OK |
|
60 * DPH_OK_BUT_BIT_ERROR |
|
61 * DPH_ERR |
|
62 * DPH_ERR_NO_INTRA |
|
63 * DPH_ERR_FORMAT_CHANGE |
|
64 * |
|
65 */ |
|
66 |
|
67 int dphGetPictureHeader( |
|
68 const dphInParam_t *inParam, |
|
69 dphInOutParam_t *inOutParam, |
|
70 dphOutParam_t *outParam, |
|
71 int *bitErrorIndication) |
|
72 /* {{-output"dphGetPictureHeader.txt"}} */ |
|
73 { |
|
74 bibBuffer_t *inBuffer = inOutParam->inBuffer; |
|
75 u_char fPrevIntraGot; /* Non-zero if an INTRA frame has been decoded |
|
76 before the current frame */ |
|
77 vdxGetPictureHeaderInputParam_t picHdrIn; |
|
78 vdxPictureHeader_t picHeader; |
|
79 vdcInstance_t *instance = inOutParam->vdcInstance; |
|
80 vdcPictureParam_t *pictureParam = &instance->pictureParam; |
|
81 vdcPictureParam_t prevPictParam; |
|
82 int trd; /* Difference between present and previous tr */ |
|
83 int fInterFrame; /* non-zero = INTER frame, 0 = INTRA frame */ |
|
84 int fPBFrame; /* Flag indicating a PB-frame */ |
|
85 int fRPS; /* 1 = RPS used, 0 = RPS not used */ |
|
86 int ret = 0; /* temporary variable to carry return values */ |
|
87 int retVal = DPH_OK; /* return value if everything as expected, |
|
88 either DPH_OK or DPH_OK_BUT_SKIP */ |
|
89 int16 error = 0; /* snc and mvc module error code */ |
|
90 |
|
91 |
|
92 /* |
|
93 * Get picture header |
|
94 */ |
|
95 |
|
96 picHdrIn.numStuffBits = inParam->numStuffBits; |
|
97 picHdrIn.fCustomPCF = 0; |
|
98 picHdrIn.fScalabilityMode = 0; |
|
99 picHdrIn.fRPS = instance->fRPS; |
|
100 picHdrIn.flushBits = bibFlushBits; |
|
101 picHdrIn.getBits = bibGetBits; |
|
102 picHdrIn.showBits = bibShowBits; |
|
103 |
|
104 /* Used to recover the 1st picture segment */ |
|
105 u_int32 picHeaderStartPos = bibNumberOfFlushedBits(inBuffer); |
|
106 |
|
107 if ( inParam->numStuffBits ) { |
|
108 bibFlushBits(inParam->numStuffBits, inBuffer, &picHdrIn.numStuffBits, bitErrorIndication, &error); |
|
109 picHdrIn.numStuffBits = 0; |
|
110 } |
|
111 |
|
112 // Read header bits normally from the bitstream |
|
113 ret = vdxGetPictureHeader(inBuffer, &picHdrIn, &picHeader, |
|
114 bitErrorIndication); |
|
115 |
|
116 if ( ret < 0 ) |
|
117 return DPH_ERR; |
|
118 else if ( ret == VDX_OK_BUT_BIT_ERROR ) |
|
119 { |
|
120 // Bit error exists. |
|
121 return DPH_OK_BUT_BIT_ERROR; |
|
122 } // end of if ( ret == VDX_OK_BUT_BIT_ERROR ) |
|
123 |
|
124 |
|
125 /* |
|
126 * Check picture header validity |
|
127 */ |
|
128 |
|
129 /* Local parameters needed in validity check (and possibly afterwards) */ |
|
130 fPrevIntraGot = instance->fIntraGot; |
|
131 fInterFrame = (picHeader.pictureType == VDX_PIC_TYPE_P || |
|
132 picHeader.pictureType == VDX_PIC_TYPE_PB || |
|
133 picHeader.pictureType == VDX_PIC_TYPE_IPB); |
|
134 fPBFrame = ((picHeader.pictureType == VDX_PIC_TYPE_PB)|| |
|
135 (picHeader.pictureType == VDX_PIC_TYPE_IPB)); |
|
136 |
|
137 /* TR with the same value as in the previous picture can be interpreted |
|
138 two ways: |
|
139 - if Reference Picture Selection is enabled, it means |
|
140 a synchronization frame |
|
141 - if Reference Picture Selection is not used, it means the maximum |
|
142 difference between two frames. |
|
143 However, at least VDOPhone uses TR equal to zero always, which |
|
144 in practice should be interpreted that TR field is not used in |
|
145 display timing. */ |
|
146 |
|
147 /* At first, check if RPS is used */ |
|
148 if (picHeader.fPLUSPTYPE && picHeader.ufep) |
|
149 fRPS = picHeader.fRPS; |
|
150 else |
|
151 fRPS = instance->fRPS; |
|
152 |
|
153 /* Calculate temporal reference difference (from the previous frame) */ |
|
154 trd = picHeader.tr - instance->pictureParam.tr; |
|
155 if (trd < 0) |
|
156 trd += 256; /* Note: Add ETR support */ |
|
157 |
|
158 /* If TR is the same as in the previous frame and Reference Picture Selection |
|
159 is not used and not the very first frame (in which case previous tr == 0), |
|
160 the temporal reference difference is the maximum one. */ |
|
161 if (trd == 0 && !fRPS && instance->frameNum > 0) |
|
162 trd = 256; /* Note: Add ETR support */ |
|
163 |
|
164 /* If unsupported picture type */ |
|
165 if (picHeader.pictureType != VDX_PIC_TYPE_I |
|
166 && picHeader.pictureType != VDX_PIC_TYPE_P |
|
167 && picHeader.pictureType != VDX_PIC_TYPE_PB |
|
168 && picHeader.pictureType != VDX_PIC_TYPE_IPB |
|
169 ) { |
|
170 return DPH_OK_BUT_BIT_ERROR; |
|
171 } |
|
172 |
|
173 if (picHeader.pictureType == VDX_PIC_TYPE_PB || |
|
174 picHeader.pictureType == VDX_PIC_TYPE_IPB) { |
|
175 return DPH_OK_BUT_BIT_ERROR; |
|
176 } |
|
177 |
|
178 if (picHeader.cpm) { |
|
179 /* No CPM support */ |
|
180 return DPH_OK_BUT_BIT_ERROR; |
|
181 } |
|
182 |
|
183 if (picHeader.fPLUSPTYPE) { |
|
184 /* If unsupported modes (and UFEP is whatever) */ |
|
185 if (picHeader.fRPR || |
|
186 picHeader.fRRU) { |
|
187 return DPH_OK_BUT_BIT_ERROR; |
|
188 } |
|
189 |
|
190 if (picHeader.ufep == 1) { |
|
191 /* If unsupported mode */ |
|
192 if (picHeader.fISD || |
|
193 picHeader.fSAC || |
|
194 picHeader.fAIV || |
|
195 picHeader.fCustomPCF) { |
|
196 return DPH_OK_BUT_BIT_ERROR; |
|
197 } |
|
198 |
|
199 if (picHeader.fUMV) { |
|
200 return DPH_OK_BUT_BIT_ERROR; |
|
201 } |
|
202 |
|
203 if (picHeader.fAP) { |
|
204 return DPH_OK_BUT_BIT_ERROR; |
|
205 } |
|
206 |
|
207 if (picHeader.fAIC) { |
|
208 return DPH_OK_BUT_BIT_ERROR; |
|
209 } |
|
210 |
|
211 |
|
212 |
|
213 if (picHeader.fDF) { |
|
214 return DPH_OK_BUT_BIT_ERROR; |
|
215 } |
|
216 |
|
217 |
|
218 |
|
219 if (picHeader.fSS) { |
|
220 return DPH_OK_BUT_BIT_ERROR; |
|
221 } |
|
222 |
|
223 |
|
224 |
|
225 if (picHeader.fMQ) { |
|
226 return DPH_OK_BUT_BIT_ERROR; |
|
227 } |
|
228 |
|
229 } |
|
230 |
|
231 /* Note: Add check for "The Indenpenent Segment Decoding mode shall not |
|
232 be used with the Reference Picture Resampling mode" |
|
233 from section 5.1.4.6 of the H.263 recommendation whenever both of |
|
234 the modes in question are supported. |
|
235 Note that this check cannot reside in vdxGetPictureHeader since |
|
236 ISD and RPR can be turned on in different pictures. */ |
|
237 } |
|
238 |
|
239 /* Else no PLUSPTYPE */ |
|
240 else { |
|
241 /* If unsupported modes */ |
|
242 if (picHeader.fSAC) { |
|
243 return DPH_OK_BUT_BIT_ERROR; |
|
244 } |
|
245 |
|
246 if (picHeader.fUMV) { |
|
247 return DPH_OK_BUT_BIT_ERROR; |
|
248 } |
|
249 |
|
250 if (picHeader.fAP) { |
|
251 return DPH_OK_BUT_BIT_ERROR; |
|
252 } |
|
253 } |
|
254 |
|
255 /* If no INTRA frame has ever been decoded and the current frame is INTER */ |
|
256 if (!fPrevIntraGot && fInterFrame) |
|
257 return DPH_ERR_NO_INTRA; |
|
258 |
|
259 if (fPrevIntraGot) { |
|
260 |
|
261 /* If width and height are indicated in the header and |
|
262 they are different from the previous */ |
|
263 if ((picHeader.fPLUSPTYPE == 0 || picHeader.ufep == 1) && |
|
264 (instance->pictureParam.lumWidth != picHeader.lumWidth || |
|
265 instance->pictureParam.lumHeight != picHeader.lumHeight)) { |
|
266 |
|
267 if (fInterFrame) { |
|
268 /* INTER frame, check that the source format has not changed */ |
|
269 deb("vdcDecodeFrame: ERROR - Source format has changed " |
|
270 "(INTER frame)\n"); |
|
271 return DPH_OK_BUT_BIT_ERROR; |
|
272 } |
|
273 else if ( *bitErrorIndication ) { |
|
274 deb("vdcDecodeFrame: ERROR - Frame size changing during " |
|
275 "the sequence, cause: bitError\n"); |
|
276 return DPH_OK_BUT_BIT_ERROR; |
|
277 } |
|
278 else { |
|
279 /* At the moment do NOT allow source format changes during |
|
280 the sequence. */ |
|
281 deb("vdcDecodeFrame: ERROR - Frame size changing during " |
|
282 "the sequence\n"); |
|
283 return DPH_ERR_FORMAT_CHANGE; |
|
284 } |
|
285 } |
|
286 } |
|
287 |
|
288 /* If the temporal reference of B points after P */ |
|
289 if (fPBFrame && trd <= picHeader.trb) { |
|
290 deb("vdcDecodeFrame: ERROR - TRB illegal.\n"); |
|
291 return DPH_OK_BUT_BIT_ERROR; |
|
292 } |
|
293 |
|
294 |
|
295 /* Now, the picture header is considered to be error-free, |
|
296 and its contents are used to manipulate instance data */ |
|
297 |
|
298 /* |
|
299 * Update instance data and output parameters |
|
300 */ |
|
301 |
|
302 /* Update frame numbers */ |
|
303 { |
|
304 int32 oldFrameNum = instance->frameNum; |
|
305 |
|
306 instance->frameNum += trd; |
|
307 if (instance->frameNum < 0) |
|
308 /* Wrap from 0x7fffffff to 0 instead of the largest negative number */ |
|
309 instance->frameNum += 0x80000000; |
|
310 |
|
311 if (fPBFrame) { |
|
312 instance->frameNumForBFrame = oldFrameNum + picHeader.trb; |
|
313 if (instance->frameNumForBFrame < 0) |
|
314 /* Wrap from 0x7fffffff to 0 instead of the largest negative number */ |
|
315 instance->frameNumForBFrame += 0x80000000; |
|
316 } |
|
317 else |
|
318 instance->frameNumForBFrame = -1; |
|
319 } |
|
320 |
|
321 /* Note: If no INTRA has been got the function has already returned */ |
|
322 instance->fIntraGot = 1; |
|
323 |
|
324 outParam->pquant = picHeader.pquant; |
|
325 |
|
326 instance->fRPS = fRPS; |
|
327 |
|
328 if (instance->fRPS && picHeader.trpi) |
|
329 outParam->trp = picHeader.trp; |
|
330 else |
|
331 outParam->trp = -1; |
|
332 |
|
333 if (instance->fRPS && picHeader.fPLUSPTYPE && picHeader.ufep) |
|
334 instance->rpsMode = picHeader.rpsMode; |
|
335 |
|
336 /* Store previous picture parameters temporarily */ |
|
337 memcpy(&prevPictParam, pictureParam, sizeof(vdcPictureParam_t)); |
|
338 |
|
339 /* Update picture parameters */ |
|
340 pictureParam->tr = picHeader.tr; |
|
341 pictureParam->trd = trd; |
|
342 pictureParam->fSplitScreenIndicator = picHeader.fSplitScreen; |
|
343 pictureParam->fDocumentCameraIndicator = picHeader.fDocumentCamera; |
|
344 pictureParam->fFullPictureFreezeRelease = picHeader.fFreezePictureRelease; |
|
345 pictureParam->pictureType = picHeader.pictureType; |
|
346 pictureParam->fPLUSPTYPE = picHeader.fPLUSPTYPE; |
|
347 pictureParam->cpm = picHeader.cpm; |
|
348 pictureParam->psbi = picHeader.psbi; |
|
349 |
|
350 if (fPBFrame) { |
|
351 pictureParam->trb = picHeader.trb; |
|
352 pictureParam->dbquant = picHeader.dbquant; |
|
353 } |
|
354 |
|
355 if (!picHeader.fPLUSPTYPE || picHeader.ufep) { |
|
356 pictureParam->lumWidth = picHeader.lumWidth; |
|
357 pictureParam->lumHeight = picHeader.lumHeight; |
|
358 pictureParam->fUMV = picHeader.fUMV; |
|
359 pictureParam->fSAC = picHeader.fSAC; |
|
360 pictureParam->fAP = picHeader.fAP; |
|
361 |
|
362 if (pictureParam->lumWidth % 16) |
|
363 pictureParam->lumMemWidth = |
|
364 (pictureParam->lumWidth / 16 + 1) * 16; |
|
365 else |
|
366 pictureParam->lumMemWidth = pictureParam->lumWidth; |
|
367 |
|
368 if (pictureParam->lumHeight % 16) |
|
369 pictureParam->lumMemHeight = (pictureParam->lumHeight / 16 + 1) * 16; |
|
370 else |
|
371 pictureParam->lumMemHeight = pictureParam->lumHeight; |
|
372 |
|
373 if (picHeader.lumHeight <= 400) |
|
374 pictureParam->numMBLinesInGOB = 1; |
|
375 else if (picHeader.lumHeight <= 800) |
|
376 pictureParam->numMBLinesInGOB = 2; |
|
377 else |
|
378 pictureParam->numMBLinesInGOB = 4; |
|
379 |
|
380 pictureParam->numMBsInMBLine = pictureParam->lumMemWidth / 16; |
|
381 |
|
382 { |
|
383 int |
|
384 numMBLines = pictureParam->lumMemHeight / 16, |
|
385 numMBLinesInLastGOB = |
|
386 numMBLines % pictureParam->numMBLinesInGOB; |
|
387 |
|
388 if (numMBLinesInLastGOB) { |
|
389 pictureParam->numGOBs = |
|
390 numMBLines / pictureParam->numMBLinesInGOB + 1; |
|
391 pictureParam->fLastGOBSizeDifferent = 1; |
|
392 pictureParam->numMBsInLastGOB = |
|
393 numMBLinesInLastGOB * pictureParam->numMBsInMBLine; |
|
394 } |
|
395 else { |
|
396 pictureParam->numGOBs = |
|
397 numMBLines / pictureParam->numMBLinesInGOB ; |
|
398 pictureParam->fLastGOBSizeDifferent = 0; |
|
399 pictureParam->numMBsInLastGOB = |
|
400 pictureParam->numMBLinesInGOB * pictureParam->numMBsInMBLine; |
|
401 } |
|
402 } |
|
403 |
|
404 pictureParam->numMBsInGOB = |
|
405 pictureParam->numMBsInMBLine * pictureParam->numMBLinesInGOB; |
|
406 } |
|
407 |
|
408 else { |
|
409 pictureParam->lumWidth = prevPictParam.lumWidth; |
|
410 pictureParam->lumHeight = prevPictParam.lumHeight; |
|
411 pictureParam->lumMemWidth = prevPictParam.lumMemWidth; |
|
412 pictureParam->lumMemHeight = prevPictParam.lumMemHeight; |
|
413 pictureParam->fUMV = prevPictParam.fUMV; |
|
414 pictureParam->fSAC = prevPictParam.fSAC; |
|
415 pictureParam->fAP = prevPictParam.fAP; |
|
416 } |
|
417 |
|
418 /* Note: Mode inference rules defined in section 5.1.4.5 of |
|
419 the H.263 recommendation are (in most cases) not reflected to members |
|
420 of pictureParam due to the fact that they are implicitly turned |
|
421 off or irrelevant in the current implementation. (This is particularly |
|
422 true when assigning inferred state "off".) */ |
|
423 |
|
424 if (picHeader.fPLUSPTYPE) { |
|
425 pictureParam->fRPR = picHeader.fRPR; |
|
426 pictureParam->fRRU = picHeader.fRRU; |
|
427 pictureParam->rtype = picHeader.rtype; |
|
428 |
|
429 /* Note: irrelevant if Annex O is not in use */ |
|
430 pictureParam->elnum = picHeader.elnum; |
|
431 |
|
432 if (picHeader.ufep) { |
|
433 pictureParam->fCustomSourceFormat = picHeader.fCustomSourceFormat; |
|
434 pictureParam->fAIC = picHeader.fAIC; |
|
435 pictureParam->fDF = picHeader.fDF; |
|
436 pictureParam->fSS = picHeader.fSS; |
|
437 pictureParam->fRPS = picHeader.fRPS; |
|
438 pictureParam->fISD = picHeader.fISD; |
|
439 pictureParam->fAIV = picHeader.fAIV; |
|
440 pictureParam->fMQ = picHeader.fMQ; |
|
441 |
|
442 pictureParam->fUMVLimited = picHeader.fUMVLimited; |
|
443 |
|
444 } |
|
445 |
|
446 /* Else no UFEP */ |
|
447 else { |
|
448 pictureParam->fCustomSourceFormat = |
|
449 prevPictParam.fCustomSourceFormat; |
|
450 pictureParam->fAIC = prevPictParam.fAIC; |
|
451 pictureParam->fDF = prevPictParam.fDF; |
|
452 pictureParam->fSS = prevPictParam.fSS; |
|
453 pictureParam->fRPS = prevPictParam.fRPS; |
|
454 pictureParam->fISD = prevPictParam.fISD; |
|
455 pictureParam->fAIV = prevPictParam.fAIV; |
|
456 pictureParam->fMQ = prevPictParam.fMQ; |
|
457 |
|
458 pictureParam->fUMVLimited = prevPictParam.fUMVLimited; |
|
459 |
|
460 } |
|
461 } |
|
462 |
|
463 /* Else no PLUSPTYPE */ |
|
464 else { |
|
465 /* Section 5.1.4.5 of the H.263 recommendation states: |
|
466 "If a picture is sent which does not contain (PLUSPTYPE), |
|
467 a state "off" shall be assigned to all modes not explicitly set to |
|
468 "on" in the PTYPE filed, and all modes shall continue to have |
|
469 an inferred state of "off" until a new picture containing |
|
470 the optional part of PLUSPTYPE is sent." */ |
|
471 |
|
472 /* Fields occuring in mandatory part of PLUSPTYPE are copied from |
|
473 the previous picture. */ |
|
474 pictureParam->fRPR = prevPictParam.fRPR; |
|
475 pictureParam->fRRU = prevPictParam.fRRU; |
|
476 |
|
477 /* RTYPE is set to zero according to section 6.1.2 of |
|
478 the H.263 recommendation */ |
|
479 pictureParam->rtype = 0; |
|
480 |
|
481 /* Modes occuring in the optional part of PLUSPTYPE are turned off |
|
482 (unless occuring in PTYPE field too, like Advanced Prediction). */ |
|
483 pictureParam->fCustomSourceFormat = 0; |
|
484 pictureParam->fCustomPCF = 0; |
|
485 pictureParam->fAIC = 0; |
|
486 pictureParam->fDF = 0; |
|
487 pictureParam->fSS = 0; |
|
488 pictureParam->fRPS = 0; |
|
489 pictureParam->fISD = 0; |
|
490 pictureParam->fAIV = 0; |
|
491 pictureParam->fMQ = 0; |
|
492 |
|
493 /* Other related settings turned off just to be sure that they are |
|
494 not misused. */ |
|
495 pictureParam->fUMVLimited = 0; |
|
496 } |
|
497 |
|
498 pictureParam->fMVsOverPictureBoundaries = |
|
499 (pictureParam->fUMV || pictureParam->fAP || |
|
500 pictureParam->fDF); |
|
501 |
|
502 /* Initialize motion vector count module */ |
|
503 mvcStart( &instance->mvcData, |
|
504 instance->pictureParam.lumMemWidth / 16 - 1, |
|
505 pictureParam->lumMemWidth, |
|
506 pictureParam->lumMemHeight, &error); |
|
507 /* Note: This assumes that the memory for frame->mvcData is filled with 0 |
|
508 in the first time the function is called. |
|
509 (This is ensured by setting the instance data to zero when it is |
|
510 initialized in vdcOpen.) */ |
|
511 instance->mvcData.fSS = pictureParam->fSS; |
|
512 |
|
513 if (error) { |
|
514 deb("mvcStart failed.\n"); |
|
515 return DPH_ERR; |
|
516 } |
|
517 |
|
518 /* Get image buffers */ |
|
519 { |
|
520 vdeIms_t *store = instance->imageStore; |
|
521 vdeImsItem_t *imsItem; |
|
522 vdeImb_t *imb; |
|
523 int width, height; |
|
524 |
|
525 vdeImsSetYUVNeed(store, inParam->fNeedDecodedFrame); |
|
526 |
|
527 if (vdeImsGetFree(store, instance->pictureParam.lumMemWidth, |
|
528 instance->pictureParam.lumMemHeight, |
|
529 &instance->currFrame) < 0) |
|
530 goto errGetFreeP; |
|
531 imsItem = instance->currFrame; |
|
532 |
|
533 |
|
534 if (vdeImsStoreItemToImageBuffer(imsItem, &imb) < 0) |
|
535 goto errAfterGetFreeP; |
|
536 |
|
537 if (vdeImbYUV(imb, &outParam->currYFrame, |
|
538 &outParam->currUFrame, &outParam->currVFrame, |
|
539 &width, &height) < 0) |
|
540 goto errAfterGetFreeP; |
|
541 |
|
542 } |
|
543 |
|
544 /* Initialize the parameters for the advanced intra coding structure. */ |
|
545 if (pictureParam->fAIC) |
|
546 { |
|
547 // not supported |
|
548 } |
|
549 |
|
550 /* Initialize the parameters for Slice Structured Mode. */ |
|
551 if (pictureParam->fSS) |
|
552 { |
|
553 // not supported |
|
554 } |
|
555 |
|
556 |
|
557 /* If picture header successfully decoded or reliably recovered */ |
|
558 if ( inParam->fReadBits && ret == VDX_OK ) { |
|
559 |
|
560 /* In the beginning, tr is set to -1 */ |
|
561 if ( instance->fPrevPicHeaderReliable |
|
562 && instance->prevPicHeader->tr >= 0 |
|
563 && ( picHeader.pictureType != instance->prevPicHeader->pictureType |
|
564 || picHeader.fUMV != instance->prevPicHeader->fUMV |
|
565 || picHeader.fAP != instance->prevPicHeader->fAP |
|
566 || picHeader.fPLUSPTYPE != instance->prevPicHeader->fPLUSPTYPE |
|
567 || ( ( picHeader.fPLUSPTYPE == 0 || picHeader.ufep == 1 ) |
|
568 && ( picHeader.lumWidth != instance->prevPicHeader->lumWidth |
|
569 || picHeader.lumHeight != instance->prevPicHeader->lumHeight ) |
|
570 ) |
|
571 || ( picHeader.fPLUSPTYPE == 1 && picHeader.ufep == 1 |
|
572 && ( picHeader.fAIC != instance->prevPicHeader->fAIC |
|
573 || picHeader.fDF != instance->prevPicHeader->fDF |
|
574 || picHeader.fMQ != instance->prevPicHeader->fMQ |
|
575 || picHeader.fUMVLimited != instance->prevPicHeader->fUMVLimited |
|
576 ) |
|
577 ) |
|
578 ) |
|
579 || ( picHeader.fPLUSPTYPE == 1 |
|
580 && picHeader.rtype != instance->prevPicHeader->rtype ) |
|
581 ) { |
|
582 |
|
583 /* Some parameter in PTYPE/PLUSPTYPE has changed, GFID should change also */ |
|
584 /* Note that some parameters, such as SAC, are not checked since they have not been implemented */ |
|
585 |
|
586 instance->fGFIDShouldChange = 1; |
|
587 } |
|
588 else if ( !instance->fPrevPicHeaderReliable ) { |
|
589 /* Previous picture header was not reliable, don't check GFID */ |
|
590 instance->fGFIDShouldChange = 1; |
|
591 instance->gfid = -1; |
|
592 } |
|
593 else if ( instance->gfid == -1 ) { |
|
594 /* The very first frame, or a frame after a lost frame, GFID can be whatever */ |
|
595 /* Note: instance->gfid == -1 is used to indicate that previous GFID |
|
596 is not available as in the first picture in first GOB header. |
|
597 If there is a picture without GOB headers and having a different |
|
598 picture header than the surrounding pictures, instance->gfid is |
|
599 reset to -1 in vdcDecodeFrame()! (Otherwise, a wrong GFID may be |
|
600 used in GFID correctness check.) */ |
|
601 instance->fGFIDShouldChange = 1; |
|
602 } |
|
603 else { |
|
604 /* No changes in PTYPE => the same GFID. |
|
605 * It is better not to change the value of this flag here, since |
|
606 * if there are no GOB or slice headers where GFID can change, the next |
|
607 * read GFID in some other frame than the one with the different PTYPE |
|
608 * will be considered illegal |
|
609 */ |
|
610 /* instance->fGFIDShouldChange = 0; */ |
|
611 } |
|
612 |
|
613 /* Header was reliable and can be used when checking the next header */ |
|
614 instance->fPrevPicHeaderReliable = 1; |
|
615 |
|
616 /* Copy the read header to be used if the next header is corrupted or lost */ |
|
617 memcpy( instance->prevPicHeader, &picHeader, sizeof( vdxPictureHeader_t ) ); |
|
618 } |
|
619 |
|
620 /* Else picture header unreliable */ |
|
621 else { |
|
622 /* Since we cannot trust that picture header is reliable, |
|
623 we cannot detect errors based on GFID. |
|
624 Thus, let's disable GFID checking in GOB level. */ |
|
625 instance->fPrevPicHeaderReliable = 0; |
|
626 instance->fGFIDShouldChange = 1; |
|
627 instance->gfid = -1; |
|
628 } |
|
629 |
|
630 return retVal; |
|
631 |
|
632 /* Error condition handling, |
|
633 release everything in reverse order */ |
|
634 // errAfterGetFreeB: |
|
635 |
|
636 // vdeImsPutFree(instance->imageStore, instance->bFrame); |
|
637 // errGetFreeB: |
|
638 |
|
639 errAfterGetFreeP: |
|
640 |
|
641 vdeImsPutFree(instance->imageStore, instance->currFrame); |
|
642 errGetFreeP: |
|
643 |
|
644 instance->currFrame = NULL; |
|
645 instance->bFrame = NULL; |
|
646 |
|
647 return DPH_ERR; |
|
648 } |
|
649 |
|
650 |
|
651 /* {{-output"dphGetSEI.txt"}} */ |
|
652 /* |
|
653 * dphGetSEI |
|
654 * |
|
655 * |
|
656 * Parameters: |
|
657 * vdcInstance Video Decoder Core instance |
|
658 * inBuffer Bit Buffer instance |
|
659 * bitErrorIndication bit error indication, see biterr.h for |
|
660 * the possible values |
|
661 * |
|
662 * Function: |
|
663 * This function gets and decodes Supplemental Enhancement |
|
664 * Information. |
|
665 * |
|
666 * Returns: |
|
667 * >= 0 the function was successful |
|
668 * < 0 an error occured |
|
669 * |
|
670 */ |
|
671 |
|
672 int dphGetSEI( |
|
673 vdcInstance_t *vdcInstance, /* Video Decoder Core instance */ |
|
674 bibBuffer_t *inBuffer, /* Bit Buffer instance */ |
|
675 int *bitErrorIndication) |
|
676 { |
|
677 /* {{-output"dphGetSEI.txt"}} */ |
|
678 int |
|
679 vdxStatus; |
|
680 |
|
681 vdxSEI_t |
|
682 sei; |
|
683 |
|
684 vdxStatus = vdxGetAndParseSEI( |
|
685 inBuffer, |
|
686 vdcInstance->pictureParam.fPLUSPTYPE, |
|
687 vdcInstance->numAnnexNScalabilityLayers, |
|
688 &sei, |
|
689 bitErrorIndication); |
|
690 |
|
691 if (vdxStatus < 0) |
|
692 return DPH_ERR; |
|
693 else if (vdxStatus == VDX_OK_BUT_BIT_ERROR) |
|
694 return DPH_OK_BUT_BIT_ERROR; |
|
695 |
|
696 |
|
697 return DPH_OK; |
|
698 } |
|
699 // End of File |
|