FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vdpau_mpeg4.c
Date: 2025-06-06 12:11:19
Exec Total Coverage
Lines: 0 51 0.0%
Functions: 0 3 0.0%
Branches: 0 8 0.0%

Line Branch Exec Source
1 /*
2 * MPEG-4 Part 2 / H.263 decode acceleration through VDPAU
3 *
4 * Copyright (c) 2008 NVIDIA
5 * Copyright (c) 2013 Rémi Denis-Courmont
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include <vdpau/vdpau.h>
25
26 #include "avcodec.h"
27 #include "hwaccel_internal.h"
28 #include "mpeg4videodec.h"
29 #include "vdpau.h"
30 #include "vdpau_internal.h"
31
32 static int vdpau_mpeg4_start_frame(AVCodecContext *avctx,
33 const AVBufferRef *buffer_ref,
34 const uint8_t *buffer, uint32_t size)
35 {
36 Mpeg4DecContext *ctx = avctx->priv_data;
37 MpegEncContext * const s = &ctx->m;
38 MPVPicture *pic = s->cur_pic.ptr;
39 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
40 VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
41 VdpVideoSurface ref;
42 int i;
43
44 /* fill VdpPictureInfoMPEG4Part2 struct */
45 info->forward_reference = VDP_INVALID_HANDLE;
46 info->backward_reference = VDP_INVALID_HANDLE;
47 info->vop_coding_type = 0;
48
49 switch (s->pict_type) {
50 case AV_PICTURE_TYPE_B:
51 ref = ff_vdpau_get_surface_id(s->next_pic.ptr->f);
52 assert(ref != VDP_INVALID_HANDLE);
53 info->backward_reference = ref;
54 info->vop_coding_type = 2;
55 /* fall-through */
56 case AV_PICTURE_TYPE_P:
57 ref = ff_vdpau_get_surface_id(s->last_pic.ptr->f);
58 assert(ref != VDP_INVALID_HANDLE);
59 info->forward_reference = ref;
60 }
61
62 info->trd[0] = s->pp_time;
63 info->trb[0] = s->pb_time;
64 info->trd[1] = s->pp_field_time >> 1;
65 info->trb[1] = s->pb_field_time >> 1;
66 info->vop_time_increment_resolution = s->avctx->framerate.num;
67 info->vop_fcode_forward = ctx->f_code;
68 info->vop_fcode_backward = ctx->b_code;
69 info->resync_marker_disable = !ctx->resync_marker;
70 info->interlaced = !s->progressive_sequence;
71 info->quant_type = ctx->mpeg_quant;
72 info->quarter_sample = s->quarter_sample;
73 info->short_video_header = avctx->codec->id == AV_CODEC_ID_H263;
74 info->rounding_control = s->no_rounding;
75 info->alternate_vertical_scan_flag = s->alternate_scan;
76 info->top_field_first = s->top_field_first;
77 for (i = 0; i < 64; ++i) {
78 int n = s->idsp.idct_permutation[i];
79 info->intra_quantizer_matrix[i] = s->intra_matrix[n];
80 info->non_intra_quantizer_matrix[i] = s->inter_matrix[n];
81 }
82
83 ff_vdpau_common_start_frame(pic_ctx, buffer, size);
84 return ff_vdpau_add_buffer(pic_ctx, buffer, size);
85 }
86
87 static int vdpau_mpeg4_decode_slice(av_unused AVCodecContext *avctx,
88 av_unused const uint8_t *buffer,
89 av_unused uint32_t size)
90 {
91 return 0;
92 }
93
94 static av_cold int vdpau_mpeg4_init(AVCodecContext *avctx)
95 {
96 VdpDecoderProfile profile;
97
98 switch (avctx->profile) {
99 case AV_PROFILE_MPEG4_SIMPLE:
100 profile = VDP_DECODER_PROFILE_MPEG4_PART2_SP;
101 break;
102 // As any ASP decoder must be able to decode SP, this
103 // should be a safe fallback if profile is unknown/unspecified.
104 case AV_PROFILE_UNKNOWN:
105 case AV_PROFILE_MPEG4_ADVANCED_SIMPLE:
106 profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
107 break;
108 default:
109 return AVERROR(ENOTSUP);
110 }
111
112 return ff_vdpau_common_init(avctx, profile, avctx->level);
113 }
114
115 const FFHWAccel ff_mpeg4_vdpau_hwaccel = {
116 .p.name = "mpeg4_vdpau",
117 .p.type = AVMEDIA_TYPE_VIDEO,
118 .p.id = AV_CODEC_ID_MPEG4,
119 .p.pix_fmt = AV_PIX_FMT_VDPAU,
120 .start_frame = vdpau_mpeg4_start_frame,
121 .end_frame = ff_vdpau_mpeg_end_frame,
122 .decode_slice = vdpau_mpeg4_decode_slice,
123 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
124 .init = vdpau_mpeg4_init,
125 .uninit = ff_vdpau_common_uninit,
126 .frame_params = ff_vdpau_common_frame_params,
127 .priv_data_size = sizeof(VDPAUContext),
128 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
129 };
130