Revision f968ef92 libavcodec/crystalhd.c

View differences:

libavcodec/crystalhd.c
512 512
{
513 513
    BC_STATUS ret;
514 514
    BC_DTS_STATUS decoder_status;
515
    uint8_t confirmed_interlaced;
516
    uint8_t ignore_interlaced;
515
    uint8_t trust_interlaced;
517 516
    uint8_t interlaced;
518 517

  
519 518
    CHDContext *priv = avctx->priv_data;
......
561 560
    }
562 561

  
563 562
    /*
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.
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:
567 566
     *
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)
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)
572 577
     */
573
    confirmed_interlaced = ((decoder_status.picNumFlags & ~0x40000000) ==
574
                            output->PicInfo.picture_number) ||
575
                            priv->need_second_field;
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;
576 583

  
577 584
    /*
578
     * If we got a false negative for confirmed_interlaced on the first field,
585
     * If we got a false negative for trust_interlaced on the first field,
579 586
     * we will realise our mistake here when we see that the picture number is that
580 587
     * of the previous picture. We cannot recover the frame and should discard the
581 588
     * second field to keep the correct number of output frames.
582 589
     */
583 590
    if (output->PicInfo.picture_number == priv->last_picture && !priv->need_second_field) {
584 591
        av_log(avctx, AV_LOG_WARNING,
585
               "Incorrectly guessed progressie frame. Discarding second field\n");
592
               "Incorrectly guessed progressive frame. Discarding second field\n");
586 593
        /* Returning without providing a picture. */
587 594
        return RET_OK;
588 595
    }
589 596

  
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,
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,
603 602
               "Next picture number unknown. Assuming progressive frame.\n");
604 603
    }
605 604

  
606
    av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | ignore_interlaced %d\n",
607
           interlaced, ignore_interlaced);
605
    av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | trust_interlaced %d\n",
606
           interlaced, trust_interlaced);
608 607

  
609 608
    if (priv->pic.data[0] && !priv->need_second_field)
610 609
        avctx->release_buffer(avctx, &priv->pic);

Also available in: Unified diff