Revision ae7a4a15 libavcodec/crystalhd.c
libavcodec/crystalhd.c | ||
---|---|---|
503 | 503 |
} |
504 | 504 |
|
505 | 505 |
|
506 |
/* |
|
507 |
* The CrystalHD doesn't report interlaced H.264 content in a way that allows |
|
508 |
* us to distinguish between specific cases that require different handling. |
|
509 |
* So, for now, we have to hard-code the behaviour we want. |
|
510 |
* |
|
511 |
* The default behaviour is to assume MBAFF with input and output fieldpairs. |
|
512 |
* |
|
513 |
* Define ASSUME_PAFF_OVER_MBAFF to treat input as PAFF with separate input |
|
514 |
* and output fields. |
|
515 |
* |
|
516 |
* Define ASSUME_TWO_INPUTS_ONE_OUTPUT to treat input as separate fields but |
|
517 |
* output as a single fieldpair. |
|
518 |
* |
|
519 |
* Define both to mess up your playback. |
|
520 |
*/ |
|
521 |
#define ASSUME_PAFF_OVER_MBAFF 0 |
|
522 |
#define ASSUME_TWO_INPUTS_ONE_OUTPUT 0 |
|
523 | 506 |
static inline CopyRet copy_frame(AVCodecContext *avctx, |
524 | 507 |
BC_DTS_PROC_OUT *output, |
525 |
void *data, int *data_size, |
|
526 |
uint8_t second_field) |
|
508 |
void *data, int *data_size) |
|
527 | 509 |
{ |
528 | 510 |
BC_STATUS ret; |
529 | 511 |
BC_DTS_STATUS decoder_status; |
530 |
uint8_t is_paff; |
|
531 |
uint8_t next_frame_same; |
|
512 |
uint8_t trust_interlaced; |
|
532 | 513 |
uint8_t interlaced; |
533 | 514 |
|
534 | 515 |
CHDContext *priv = avctx->priv_data; |
... | ... | |
577 | 558 |
return RET_ERROR; |
578 | 559 |
} |
579 | 560 |
|
580 |
is_paff = ASSUME_PAFF_OVER_MBAFF || |
|
581 |
!(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC); |
|
582 |
next_frame_same = output->PicInfo.picture_number == |
|
583 |
(decoder_status.picNumFlags & ~0x40000000); |
|
584 |
interlaced = ((output->PicInfo.flags & |
|
585 |
VDEC_FLAG_INTERLACED_SRC) && is_paff) || |
|
586 |
next_frame_same || bottom_field || second_field; |
|
561 |
/* |
|
562 |
* For most content, we can trust the interlaced flag returned |
|
563 |
* by the hardware, but sometimes we can't. These are the |
|
564 |
* conditions under which we can trust the flag: |
|
565 |
* |
|
566 |
* 1) It's not h.264 content |
|
567 |
* 2) The UNKNOWN_SRC flag is not set |
|
568 |
* 3) We know we're expecting a second field |
|
569 |
* 4) The hardware reports this picture and the next picture |
|
570 |
* have the same picture number. |
|
571 |
* |
|
572 |
* Note that there can still be interlaced content that will |
|
573 |
* fail this check, if the hardware hasn't decoded the next |
|
574 |
* picture or if there is a corruption in the stream. (In either |
|
575 |
* case a 0 will be returned for the next picture number) |
|
576 |
*/ |
|
577 |
trust_interlaced = avctx->codec->id != CODEC_ID_H264 || |
|
578 |
!(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) || |
|
579 |
priv->need_second_field || |
|
580 |
(decoder_status.picNumFlags & ~0x40000000) == |
|
581 |
output->PicInfo.picture_number; |
|
582 |
|
|
583 |
/* |
|
584 |
* If we got a false negative for trust_interlaced on the first field, |
|
585 |
* we will realise our mistake here when we see that the picture number is that |
|
586 |
* of the previous picture. We cannot recover the frame and should discard the |
|
587 |
* second field to keep the correct number of output frames. |
|
588 |
*/ |
|
589 |
if (output->PicInfo.picture_number == priv->last_picture && !priv->need_second_field) { |
|
590 |
av_log(avctx, AV_LOG_WARNING, |
|
591 |
"Incorrectly guessed progressive frame. Discarding second field\n"); |
|
592 |
/* Returning without providing a picture. */ |
|
593 |
return RET_OK; |
|
594 |
} |
|
595 |
|
|
596 |
interlaced = (output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) && |
|
597 |
trust_interlaced; |
|
587 | 598 |
|
588 |
av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: next_frame_same: %u | %u | %u\n", |
|
589 |
next_frame_same, output->PicInfo.picture_number, |
|
590 |
decoder_status.picNumFlags & ~0x40000000); |
|
599 |
if (!trust_interlaced && (decoder_status.picNumFlags & ~0x40000000) == 0) { |
|
600 |
av_log(avctx, AV_LOG_VERBOSE, |
|
601 |
"Next picture number unknown. Assuming progressive frame.\n"); |
|
602 |
} |
|
603 |
|
|
604 |
av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | trust_interlaced %d\n", |
|
605 |
interlaced, trust_interlaced); |
|
591 | 606 |
|
592 | 607 |
if (priv->pic.data[0] && !priv->need_second_field) |
593 | 608 |
avctx->release_buffer(avctx, &priv->pic); |
... | ... | |
655 | 670 |
*(AVFrame *)data = priv->pic; |
656 | 671 |
} |
657 | 672 |
|
658 |
if (ASSUME_TWO_INPUTS_ONE_OUTPUT && |
|
659 |
output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) { |
|
673 |
/* |
|
674 |
* Two types of PAFF content have been observed. One form causes the |
|
675 |
* hardware to return a field pair and the other individual fields, |
|
676 |
* even though the input is always individual fields. We must skip |
|
677 |
* copying on the next decode() call to maintain pipeline length in |
|
678 |
* the first case. |
|
679 |
*/ |
|
680 |
if (!interlaced && (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) && |
|
681 |
(pic_type == PICT_TOP_FIELD || pic_type == PICT_BOTTOM_FIELD)) { |
|
660 | 682 |
av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n"); |
661 | 683 |
return RET_SKIP_NEXT_COPY; |
662 | 684 |
} |
... | ... | |
672 | 694 |
|
673 | 695 |
|
674 | 696 |
static inline CopyRet receive_frame(AVCodecContext *avctx, |
675 |
void *data, int *data_size, |
|
676 |
uint8_t second_field) |
|
697 |
void *data, int *data_size) |
|
677 | 698 |
{ |
678 | 699 |
BC_STATUS ret; |
679 | 700 |
BC_DTS_PROC_OUT output = { |
... | ... | |
730 | 751 |
priv->last_picture = output.PicInfo.picture_number - 1; |
731 | 752 |
} |
732 | 753 |
|
733 |
copy_ret = copy_frame(avctx, &output, data, data_size, second_field);
|
|
754 |
copy_ret = copy_frame(avctx, &output, data, data_size); |
|
734 | 755 |
if (*data_size > 0) { |
735 | 756 |
avctx->has_b_frames--; |
736 | 757 |
priv->last_picture++; |
... | ... | |
865 | 886 |
} |
866 | 887 |
|
867 | 888 |
do { |
868 |
rec_ret = receive_frame(avctx, data, data_size, 0);
|
|
889 |
rec_ret = receive_frame(avctx, data, data_size); |
|
869 | 890 |
if (rec_ret == RET_OK && *data_size == 0) { |
870 | 891 |
/* |
871 | 892 |
* This case is for when the encoded fields are stored |
... | ... | |
891 | 912 |
ret = DtsGetDriverStatus(dev, &decoder_status); |
892 | 913 |
if (ret == BC_STS_SUCCESS && |
893 | 914 |
decoder_status.ReadyListCount > 0) { |
894 |
rec_ret = receive_frame(avctx, data, data_size, 1);
|
|
915 |
rec_ret = receive_frame(avctx, data, data_size); |
|
895 | 916 |
if ((rec_ret == RET_OK && *data_size > 0) || |
896 | 917 |
rec_ret == RET_ERROR) |
897 | 918 |
break; |
Also available in: Unified diff