MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / dvvideo_decode_frame

Function dvvideo_decode_frame

libavcodec/dvdec.c:622–689  ·  view source on GitHub ↗

NOTE: exactly one frame must be given (120000 bytes for NTSC, * 144000 bytes for PAL - or twice those for 50Mbps) */

Source from the content-addressed store, hash-verified

620/* NOTE: exactly one frame must be given (120000 bytes for NTSC,
621 * 144000 bytes for PAL - or twice those for 50Mbps) */
622static int dvvideo_decode_frame(AVCodecContext *avctx, AVFrame *frame,
623 int *got_frame, AVPacket *avpkt)
624{
625 uint8_t *buf = avpkt->data;
626 int buf_size = avpkt->size;
627 DVDecContext *s = avctx->priv_data;
628 const uint8_t *vsc_pack;
629 int apt, is16_9, ret;
630 const AVDVProfile *sys;
631
632 sys = ff_dv_frame_profile(avctx, s->sys, buf, buf_size);
633 if (!sys || buf_size < sys->frame_size) {
634 av_log(avctx, AV_LOG_ERROR, "could not find dv frame profile\n");
635 return -1; /* NOTE: we only accept several full frames */
636 }
637
638 if (sys != s->sys) {
639 ff_dv_init_dynamic_tables(s->work_chunks, sys);
640 dv_init_weight_tables(s, sys);
641 s->sys = sys;
642 }
643
644 s->frame = frame;
645 avctx->pix_fmt = s->sys->pix_fmt;
646 avctx->framerate = av_inv_q(s->sys->time_base);
647 avctx->bit_rate = av_rescale_q(s->sys->frame_size,
648 (AVRational) { 8, 1 },
649 s->sys->time_base);
650
651 ret = ff_set_dimensions(avctx, s->sys->width, s->sys->height);
652 if (ret < 0)
653 return ret;
654
655 /* Determine the codec's sample_aspect ratio from the packet */
656 vsc_pack = buf + 80 * 5 + 48 + 5;
657 if (*vsc_pack == DV_VIDEO_CONTROL) {
658 apt = buf[4] & 0x07;
659 is16_9 = (vsc_pack[2] & 0x07) == 0x02 ||
660 (!apt && (vsc_pack[2] & 0x07) == 0x07);
661 ff_set_sar(avctx, s->sys->sar[is16_9]);
662 }
663
664 if ((ret = ff_thread_get_buffer(avctx, frame, 0)) < 0)
665 return ret;
666
667 /* Determine the codec's field order from the packet */
668 if ( *vsc_pack == DV_VIDEO_CONTROL ) {
669 if (avctx->height == 720) {
670 frame->flags &= ~AV_FRAME_FLAG_INTERLACED;
671 frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
672 } else if (avctx->height == 1080) {
673 frame->flags |= AV_FRAME_FLAG_INTERLACED;
674 frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * ((vsc_pack[3] & 0x40) == 0x40);
675 } else {
676 frame->flags |= AV_FRAME_FLAG_INTERLACED * ((vsc_pack[3] & 0x10) == 0x10);
677 frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * !(vsc_pack[3] & 0x40);
678 }
679 }

Callers

nothing calls this directly

Calls 9

ff_dv_frame_profileFunction · 0.85
av_logFunction · 0.85
dv_init_weight_tablesFunction · 0.85
av_rescale_qFunction · 0.85
ff_set_dimensionsFunction · 0.85
ff_set_sarFunction · 0.85
dv_work_pool_sizeFunction · 0.85
ff_thread_get_bufferFunction · 0.70

Tested by

no test coverage detected