Commit | Line | Data |
---|---|---|
2ba45a60 DM |
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 "mpeg4video.h" | |
28 | #include "vdpau.h" | |
29 | #include "vdpau_internal.h" | |
30 | ||
31 | static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, | |
32 | const uint8_t *buffer, uint32_t size) | |
33 | { | |
34 | Mpeg4DecContext *ctx = avctx->priv_data; | |
35 | MpegEncContext * const s = &ctx->m; | |
36 | Picture *pic = s->current_picture_ptr; | |
37 | struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private; | |
38 | VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4; | |
39 | VdpVideoSurface ref; | |
40 | int i; | |
41 | ||
42 | /* fill VdpPictureInfoMPEG4Part2 struct */ | |
43 | info->forward_reference = VDP_INVALID_HANDLE; | |
44 | info->backward_reference = VDP_INVALID_HANDLE; | |
45 | info->vop_coding_type = 0; | |
46 | ||
47 | switch (s->pict_type) { | |
48 | case AV_PICTURE_TYPE_B: | |
49 | ref = ff_vdpau_get_surface_id(s->next_picture.f); | |
50 | assert(ref != VDP_INVALID_HANDLE); | |
51 | info->backward_reference = ref; | |
52 | info->vop_coding_type = 2; | |
53 | /* fall-through */ | |
54 | case AV_PICTURE_TYPE_P: | |
55 | ref = ff_vdpau_get_surface_id(s->last_picture.f); | |
56 | assert(ref != VDP_INVALID_HANDLE); | |
57 | info->forward_reference = ref; | |
58 | } | |
59 | ||
60 | info->trd[0] = s->pp_time; | |
61 | info->trb[0] = s->pb_time; | |
62 | info->trd[1] = s->pp_field_time >> 1; | |
63 | info->trb[1] = s->pb_field_time >> 1; | |
f6fa7814 | 64 | info->vop_time_increment_resolution = s->avctx->framerate.num; |
2ba45a60 DM |
65 | info->vop_fcode_forward = s->f_code; |
66 | info->vop_fcode_backward = s->b_code; | |
67 | info->resync_marker_disable = !ctx->resync_marker; | |
68 | info->interlaced = !s->progressive_sequence; | |
69 | info->quant_type = s->mpeg_quant; | |
70 | info->quarter_sample = s->quarter_sample; | |
71 | info->short_video_header = avctx->codec->id == AV_CODEC_ID_H263; | |
72 | info->rounding_control = s->no_rounding; | |
73 | info->alternate_vertical_scan_flag = s->alternate_scan; | |
74 | info->top_field_first = s->top_field_first; | |
75 | for (i = 0; i < 64; ++i) { | |
76 | info->intra_quantizer_matrix[i] = s->intra_matrix[i]; | |
77 | info->non_intra_quantizer_matrix[i] = s->inter_matrix[i]; | |
78 | } | |
79 | ||
80 | ff_vdpau_common_start_frame(pic_ctx, buffer, size); | |
81 | return ff_vdpau_add_buffer(pic_ctx, buffer, size); | |
82 | } | |
83 | ||
84 | static int vdpau_mpeg4_decode_slice(av_unused AVCodecContext *avctx, | |
85 | av_unused const uint8_t *buffer, | |
86 | av_unused uint32_t size) | |
87 | { | |
88 | return 0; | |
89 | } | |
90 | ||
91 | #if CONFIG_H263_VDPAU_HWACCEL | |
f6fa7814 DM |
92 | static int vdpau_h263_init(AVCodecContext *avctx) |
93 | { | |
94 | return ff_vdpau_common_init(avctx, VDP_DECODER_PROFILE_MPEG4_PART2_ASP, | |
95 | VDP_DECODER_LEVEL_MPEG4_PART2_ASP_L5); | |
96 | } | |
97 | ||
2ba45a60 DM |
98 | AVHWAccel ff_h263_vdpau_hwaccel = { |
99 | .name = "h263_vdpau", | |
100 | .type = AVMEDIA_TYPE_VIDEO, | |
101 | .id = AV_CODEC_ID_H263, | |
102 | .pix_fmt = AV_PIX_FMT_VDPAU, | |
103 | .start_frame = vdpau_mpeg4_start_frame, | |
104 | .end_frame = ff_vdpau_mpeg_end_frame, | |
105 | .decode_slice = vdpau_mpeg4_decode_slice, | |
106 | .frame_priv_data_size = sizeof(struct vdpau_picture_context), | |
f6fa7814 DM |
107 | .init = vdpau_h263_init, |
108 | .uninit = ff_vdpau_common_uninit, | |
109 | .priv_data_size = sizeof(VDPAUContext), | |
2ba45a60 DM |
110 | }; |
111 | #endif | |
112 | ||
113 | #if CONFIG_MPEG4_VDPAU_HWACCEL | |
f6fa7814 DM |
114 | static int vdpau_mpeg4_init(AVCodecContext *avctx) |
115 | { | |
116 | VdpDecoderProfile profile; | |
117 | ||
118 | switch (avctx->profile) { | |
119 | case FF_PROFILE_MPEG4_SIMPLE: | |
120 | profile = VDP_DECODER_PROFILE_MPEG4_PART2_SP; | |
121 | break; | |
122 | // As any ASP decoder must be able to decode SP, this | |
123 | // should be a safe fallback if profile is unknown/unspecified. | |
124 | case FF_PROFILE_UNKNOWN: | |
125 | case FF_PROFILE_MPEG4_ADVANCED_SIMPLE: | |
126 | profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP; | |
127 | break; | |
128 | default: | |
129 | return AVERROR(ENOTSUP); | |
130 | } | |
131 | ||
132 | return ff_vdpau_common_init(avctx, profile, avctx->level); | |
133 | } | |
134 | ||
2ba45a60 DM |
135 | AVHWAccel ff_mpeg4_vdpau_hwaccel = { |
136 | .name = "mpeg4_vdpau", | |
137 | .type = AVMEDIA_TYPE_VIDEO, | |
138 | .id = AV_CODEC_ID_MPEG4, | |
139 | .pix_fmt = AV_PIX_FMT_VDPAU, | |
140 | .start_frame = vdpau_mpeg4_start_frame, | |
141 | .end_frame = ff_vdpau_mpeg_end_frame, | |
142 | .decode_slice = vdpau_mpeg4_decode_slice, | |
143 | .frame_priv_data_size = sizeof(struct vdpau_picture_context), | |
f6fa7814 DM |
144 | .init = vdpau_mpeg4_init, |
145 | .uninit = ff_vdpau_common_uninit, | |
146 | .priv_data_size = sizeof(VDPAUContext), | |
2ba45a60 DM |
147 | }; |
148 | #endif |