Revision 4ab57cff

View differences:

libavcodec/crystalhd.c
506 506
}
507 507

  
508 508

  
509
/*
510
 * The CrystalHD doesn't report interlaced H.264 content in a way that allows
511
 * us to distinguish between specific cases that require different handling.
512
 * So, for now, we have to hard-code the behaviour we want.
513
 *
514
 * Specifically, there are PAFF samples where input is always separate fields
515
 * but the hardware returns separate fields on one occasion and a field-pair
516
 * on another. The code assumes the first case and define
517
 * ASSUME_TWO_INPUTS_ONE_OUTPUT to assume the second case.
518
 */
519
#define ASSUME_TWO_INPUTS_ONE_OUTPUT 0
520 509
static inline CopyRet copy_frame(AVCodecContext *avctx,
521 510
                                 BC_DTS_PROC_OUT *output,
522 511
                                 void *data, int *data_size)
523 512
{
524 513
    BC_STATUS ret;
525 514
    BC_DTS_STATUS decoder_status;
515
    uint8_t confirmed_interlaced;
526 516
    uint8_t ignore_interlaced;
527 517
    uint8_t interlaced;
528 518

  
......
571 561
    }
572 562

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

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

  
590
    /*
574 591
     * Testing has, so far, shown that we can't trust the interlaced flag for
575 592
     * H.264 content when VDEC_FLAG_UNKNOWN_SRC is set.
576 593
     */
577 594
    ignore_interlaced = avctx->codec->id == CODEC_ID_H264 &&
578 595
                        (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) &&
579 596
                        (pic_type == 0 || pic_type == PICT_FRAME ||
580
                         ASSUME_TWO_INPUTS_ONE_OUTPUT);
597
                         !confirmed_interlaced);
581 598
    interlaced        = (output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) &&
582
                        !ignore_interlaced;
599
                        (!ignore_interlaced || confirmed_interlaced);
600

  
601
    if (ignore_interlaced && (decoder_status.picNumFlags & ~0x40000000) == 0) {
602
        av_log(avctx, AV_LOG_WARNING,
603
               "Next picture number unknown. Assuming progressive frame.\n");
604
    }
583 605

  
584 606
    av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | ignore_interlaced %d\n",
585 607
           interlaced, ignore_interlaced);
......
650 672
        *(AVFrame *)data = priv->pic;
651 673
    }
652 674

  
653
    if (ASSUME_TWO_INPUTS_ONE_OUTPUT &&
654
        output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) {
675
    /*
676
     * Two types of PAFF content have been observed. One form causes the
677
     * hardware to return a field pair and the other individual fields,
678
     * even though the input is always individual fields. We must skip
679
     * copying on the next decode() call to maintain pipeline length in
680
     * the first case.
681
     */
682
    if (!interlaced && (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) &&
683
        (pic_type == PICT_TOP_FIELD || pic_type == PICT_BOTTOM_FIELD)) {
655 684
        av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n");
656 685
        return RET_SKIP_NEXT_COPY;
657 686
    }

Also available in: Unified diff