FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vdpau_mpeg12.c
Date: 2022-07-04 00:18:54
Exec Total Coverage
Lines: 0 56 0.0%
Branches: 0 10 0.0%

Line Branch Exec Source
1 /*
2 * MPEG-1/2 HW 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 "config_components.h"
25
26 #include <vdpau/vdpau.h>
27
28 #include "avcodec.h"
29 #include "hwconfig.h"
30 #include "mpegvideo.h"
31 #include "vdpau.h"
32 #include "vdpau_internal.h"
33
34 static int vdpau_mpeg_start_frame(AVCodecContext *avctx,
35 const uint8_t *buffer, uint32_t size)
36 {
37 MpegEncContext * const s = avctx->priv_data;
38 Picture *pic = s->current_picture_ptr;
39 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
40 VdpPictureInfoMPEG1Or2 *info = &pic_ctx->info.mpeg;
41 VdpVideoSurface ref;
42 int i;
43
44 /* fill VdpPictureInfoMPEG1Or2 struct */
45 info->forward_reference = VDP_INVALID_HANDLE;
46 info->backward_reference = VDP_INVALID_HANDLE;
47
48 switch (s->pict_type) {
49 case AV_PICTURE_TYPE_B:
50 ref = ff_vdpau_get_surface_id(s->next_picture.f);
51 assert(ref != VDP_INVALID_HANDLE);
52 info->backward_reference = ref;
53 /* fall through to forward prediction */
54 case AV_PICTURE_TYPE_P:
55 ref = ff_vdpau_get_surface_id(s->last_picture.f);
56 info->forward_reference = ref;
57 }
58
59 info->slice_count = 0;
60 info->picture_structure = s->picture_structure;
61 info->picture_coding_type = s->pict_type;
62 info->intra_dc_precision = s->intra_dc_precision;
63 info->frame_pred_frame_dct = s->frame_pred_frame_dct;
64 info->concealment_motion_vectors = s->concealment_motion_vectors;
65 info->intra_vlc_format = s->intra_vlc_format;
66 info->alternate_scan = s->alternate_scan;
67 info->q_scale_type = s->q_scale_type;
68 info->top_field_first = s->top_field_first;
69 // Both for MPEG-1 only, zero for MPEG-2:
70 info->full_pel_forward_vector = s->full_pel[0];
71 info->full_pel_backward_vector = s->full_pel[1];
72 // For MPEG-1 fill both horizontal & vertical:
73 info->f_code[0][0] = s->mpeg_f_code[0][0];
74 info->f_code[0][1] = s->mpeg_f_code[0][1];
75 info->f_code[1][0] = s->mpeg_f_code[1][0];
76 info->f_code[1][1] = s->mpeg_f_code[1][1];
77 for (i = 0; i < 64; ++i) {
78 info->intra_quantizer_matrix[i] = s->intra_matrix[i];
79 info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
80 }
81
82 return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
83 }
84
85 static int vdpau_mpeg_decode_slice(AVCodecContext *avctx,
86 const uint8_t *buffer, uint32_t size)
87 {
88 MpegEncContext * const s = avctx->priv_data;
89 Picture *pic = s->current_picture_ptr;
90 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
91 int val;
92
93 val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
94 if (val < 0)
95 return val;
96
97 pic_ctx->info.mpeg.slice_count++;
98 return 0;
99 }
100
101 #if CONFIG_MPEG1_VDPAU_HWACCEL
102 static int vdpau_mpeg1_init(AVCodecContext *avctx)
103 {
104 return ff_vdpau_common_init(avctx, VDP_DECODER_PROFILE_MPEG1,
105 VDP_DECODER_LEVEL_MPEG1_NA);
106 }
107
108 const AVHWAccel ff_mpeg1_vdpau_hwaccel = {
109 .name = "mpeg1_vdpau",
110 .type = AVMEDIA_TYPE_VIDEO,
111 .id = AV_CODEC_ID_MPEG1VIDEO,
112 .pix_fmt = AV_PIX_FMT_VDPAU,
113 .start_frame = vdpau_mpeg_start_frame,
114 .end_frame = ff_vdpau_mpeg_end_frame,
115 .decode_slice = vdpau_mpeg_decode_slice,
116 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
117 .init = vdpau_mpeg1_init,
118 .uninit = ff_vdpau_common_uninit,
119 .priv_data_size = sizeof(VDPAUContext),
120 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
121 };
122 #endif
123
124 #if CONFIG_MPEG2_VDPAU_HWACCEL
125 static int vdpau_mpeg2_init(AVCodecContext *avctx)
126 {
127 VdpDecoderProfile profile;
128
129 switch (avctx->profile) {
130 case FF_PROFILE_MPEG2_MAIN:
131 profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
132 break;
133 case FF_PROFILE_MPEG2_SIMPLE:
134 profile = VDP_DECODER_PROFILE_MPEG2_SIMPLE;
135 break;
136 default:
137 return AVERROR(EINVAL);
138 }
139
140 return ff_vdpau_common_init(avctx, profile, VDP_DECODER_LEVEL_MPEG2_HL);
141 }
142
143 const AVHWAccel ff_mpeg2_vdpau_hwaccel = {
144 .name = "mpeg2_vdpau",
145 .type = AVMEDIA_TYPE_VIDEO,
146 .id = AV_CODEC_ID_MPEG2VIDEO,
147 .pix_fmt = AV_PIX_FMT_VDPAU,
148 .start_frame = vdpau_mpeg_start_frame,
149 .end_frame = ff_vdpau_mpeg_end_frame,
150 .decode_slice = vdpau_mpeg_decode_slice,
151 .frame_priv_data_size = sizeof(struct vdpau_picture_context),
152 .init = vdpau_mpeg2_init,
153 .uninit = ff_vdpau_common_uninit,
154 .frame_params = ff_vdpau_common_frame_params,
155 .priv_data_size = sizeof(VDPAUContext),
156 .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
157 };
158 #endif
159