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