Revision 3188d33a
libavcodec/crystalhd.c | ||
---|---|---|
512 | 512 |
{ |
513 | 513 |
BC_STATUS ret; |
514 | 514 |
BC_DTS_STATUS decoder_status; |
515 |
uint8_t trust_interlaced; |
|
515 |
uint8_t confirmed_interlaced; |
|
516 |
uint8_t ignore_interlaced; |
|
516 | 517 |
uint8_t interlaced; |
517 | 518 |
|
518 | 519 |
CHDContext *priv = avctx->priv_data; |
... | ... | |
560 | 561 |
} |
561 | 562 |
|
562 | 563 |
/* |
563 |
* For most content, we can trust the interlaced flag returned
|
|
564 |
* by the hardware, but sometimes we can't. These are the
|
|
565 |
* conditions under which we can trust the flag:
|
|
564 |
* If we're expecting a second field, or we know that the next
|
|
565 |
* picture has the same number as the current picture, then we're
|
|
566 |
* definitely interlaced.
|
|
566 | 567 |
* |
567 |
* 1) It's not h.264 content |
|
568 |
* 2) The UNKNOWN_SRC flag is not set |
|
569 |
* 3) We know we're expecting a second field |
|
570 |
* 4) The hardware reports this picture and the next picture |
|
571 |
* have the same picture number. |
|
572 |
* |
|
573 |
* Note that there can still be interlaced content that will |
|
574 |
* fail this check, if the hardware hasn't decoded the next |
|
575 |
* picture or if there is a corruption in the stream. (In either |
|
576 |
* case a 0 will be returned for the next picture number) |
|
568 |
* Note that this test can return false negatives if the hardware |
|
569 |
* hasn't decoded the next picture or if there is a corruption in |
|
570 |
* the stream. (In either case a 0 will be returned for the next |
|
571 |
* picture number) |
|
577 | 572 |
*/ |
578 |
trust_interlaced = avctx->codec->id != CODEC_ID_H264 || |
|
579 |
!(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) || |
|
580 |
priv->need_second_field || |
|
581 |
(decoder_status.picNumFlags & ~0x40000000) == |
|
582 |
output->PicInfo.picture_number; |
|
573 |
confirmed_interlaced = ((decoder_status.picNumFlags & ~0x40000000) == |
|
574 |
output->PicInfo.picture_number) || |
|
575 |
priv->need_second_field; |
|
583 | 576 |
|
584 | 577 |
/* |
585 |
* If we got a false negative for trust_interlaced on the first field,
|
|
578 |
* If we got a false negative for confirmed_interlaced on the first field,
|
|
586 | 579 |
* we will realise our mistake here when we see that the picture number is that |
587 | 580 |
* of the previous picture. We cannot recover the frame and should discard the |
588 | 581 |
* second field to keep the correct number of output frames. |
589 | 582 |
*/ |
590 | 583 |
if (output->PicInfo.picture_number == priv->last_picture && !priv->need_second_field) { |
591 | 584 |
av_log(avctx, AV_LOG_WARNING, |
592 |
"Incorrectly guessed progressive frame. Discarding second field\n");
|
|
585 |
"Incorrectly guessed progressie frame. Discarding second field\n"); |
|
593 | 586 |
/* Returning without providing a picture. */ |
594 | 587 |
return RET_OK; |
595 | 588 |
} |
596 | 589 |
|
597 |
interlaced = (output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) && |
|
598 |
trust_interlaced; |
|
599 |
|
|
600 |
if (!trust_interlaced && (decoder_status.picNumFlags & ~0x40000000) == 0) { |
|
601 |
av_log(avctx, AV_LOG_VERBOSE, |
|
590 |
/* |
|
591 |
* Testing has, so far, shown that we can't trust the interlaced flag for |
|
592 |
* H.264 content when VDEC_FLAG_UNKNOWN_SRC is set. |
|
593 |
*/ |
|
594 |
ignore_interlaced = avctx->codec->id == CODEC_ID_H264 && |
|
595 |
(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) && |
|
596 |
(pic_type == 0 || pic_type == PICT_FRAME || |
|
597 |
!confirmed_interlaced); |
|
598 |
interlaced = (output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) && |
|
599 |
(!ignore_interlaced || confirmed_interlaced); |
|
600 |
|
|
601 |
if (ignore_interlaced && (decoder_status.picNumFlags & ~0x40000000) == 0) { |
|
602 |
av_log(avctx, AV_LOG_WARNING, |
|
602 | 603 |
"Next picture number unknown. Assuming progressive frame.\n"); |
603 | 604 |
} |
604 | 605 |
|
605 |
av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | trust_interlaced %d\n",
|
|
606 |
interlaced, trust_interlaced);
|
|
606 |
av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | ignore_interlaced %d\n",
|
|
607 |
interlaced, ignore_interlaced);
|
|
607 | 608 |
|
608 | 609 |
if (priv->pic.data[0] && !priv->need_second_field) |
609 | 610 |
avctx->release_buffer(avctx, &priv->pic); |
Also available in: Unified diff