Revision 85b01098 libavcodec/crystalhd.c
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 |
|
509 | 520 |
static inline CopyRet copy_frame(AVCodecContext *avctx, |
510 | 521 |
BC_DTS_PROC_OUT *output, |
511 | 522 |
void *data, int *data_size) |
512 | 523 |
{ |
513 | 524 |
BC_STATUS ret; |
514 | 525 |
BC_DTS_STATUS decoder_status; |
515 |
uint8_t confirmed_interlaced; |
|
516 | 526 |
uint8_t ignore_interlaced; |
517 | 527 |
uint8_t interlaced; |
518 | 528 |
|
... | ... | |
561 | 571 |
} |
562 | 572 |
|
563 | 573 |
/* |
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 |
/* |
|
591 | 574 |
* Testing has, so far, shown that we can't trust the interlaced flag for |
592 | 575 |
* H.264 content when VDEC_FLAG_UNKNOWN_SRC is set. |
593 | 576 |
*/ |
594 | 577 |
ignore_interlaced = avctx->codec->id == CODEC_ID_H264 && |
595 | 578 |
(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) && |
596 | 579 |
(pic_type == 0 || pic_type == PICT_FRAME || |
597 |
!confirmed_interlaced);
|
|
580 |
ASSUME_TWO_INPUTS_ONE_OUTPUT);
|
|
598 | 581 |
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, |
|
603 |
"Next picture number unknown. Assuming progressive frame.\n"); |
|
604 |
} |
|
582 |
!ignore_interlaced; |
|
605 | 583 |
|
606 | 584 |
av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | ignore_interlaced %d\n", |
607 | 585 |
interlaced, ignore_interlaced); |
... | ... | |
672 | 650 |
*(AVFrame *)data = priv->pic; |
673 | 651 |
} |
674 | 652 |
|
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)) { |
|
653 |
if (ASSUME_TWO_INPUTS_ONE_OUTPUT && |
|
654 |
output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) { |
|
684 | 655 |
av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n"); |
685 | 656 |
return RET_SKIP_NEXT_COPY; |
686 | 657 |
} |
Also available in: Unified diff