annotate ffmpeg/libavcodec/vdpau_mpeg12.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * MPEG-1/2 HW decode acceleration through VDPAU
yading@10 3 *
yading@10 4 * Copyright (c) 2008 NVIDIA
yading@10 5 * Copyright (c) 2013 Rémi Denis-Courmont
yading@10 6 *
yading@10 7 * This file is part of FFmpeg.
yading@10 8 *
yading@10 9 * FFmpeg is free software; you can redistribute it and/or
yading@10 10 * modify it under the terms of the GNU Lesser General Public
yading@10 11 * License as published by the Free Software Foundation; either
yading@10 12 * version 2.1 of the License, or (at your option) any later version.
yading@10 13 *
yading@10 14 * FFmpeg is distributed in the hope that it will be useful,
yading@10 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 17 * Lesser General Public License for more details.
yading@10 18 *
yading@10 19 * You should have received a copy of the GNU Lesser General Public
yading@10 20 * License along with FFmpeg; if not, write to the Free Software Foundation,
yading@10 21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 22 */
yading@10 23
yading@10 24 #include <vdpau/vdpau.h>
yading@10 25
yading@10 26 #include "avcodec.h"
yading@10 27 #include "vdpau.h"
yading@10 28 #include "vdpau_internal.h"
yading@10 29
yading@10 30 static int vdpau_mpeg_start_frame(AVCodecContext *avctx,
yading@10 31 const uint8_t *buffer, uint32_t size)
yading@10 32 {
yading@10 33 MpegEncContext * const s = avctx->priv_data;
yading@10 34 AVVDPAUContext *hwctx = avctx->hwaccel_context;
yading@10 35 VdpPictureInfoMPEG1Or2 *info = &hwctx->info.mpeg;
yading@10 36 VdpVideoSurface ref;
yading@10 37 int i;
yading@10 38
yading@10 39 /* fill VdpPictureInfoMPEG1Or2 struct */
yading@10 40 info->forward_reference = VDP_INVALID_HANDLE;
yading@10 41 info->backward_reference = VDP_INVALID_HANDLE;
yading@10 42
yading@10 43 switch (s->pict_type) {
yading@10 44 case AV_PICTURE_TYPE_B:
yading@10 45 ref = ff_vdpau_get_surface_id(&s->next_picture);
yading@10 46 assert(ref != VDP_INVALID_HANDLE);
yading@10 47 hwctx->info.mpeg.backward_reference = ref;
yading@10 48 /* fall through to forward prediction */
yading@10 49 case AV_PICTURE_TYPE_P:
yading@10 50 ref = ff_vdpau_get_surface_id(&s->last_picture);
yading@10 51 hwctx->info.mpeg.forward_reference = ref;
yading@10 52 }
yading@10 53
yading@10 54 info->slice_count = 0;
yading@10 55 info->picture_structure = s->picture_structure;
yading@10 56 info->picture_coding_type = s->pict_type;
yading@10 57 info->intra_dc_precision = s->intra_dc_precision;
yading@10 58 info->frame_pred_frame_dct = s->frame_pred_frame_dct;
yading@10 59 info->concealment_motion_vectors = s->concealment_motion_vectors;
yading@10 60 info->intra_vlc_format = s->intra_vlc_format;
yading@10 61 info->alternate_scan = s->alternate_scan;
yading@10 62 info->q_scale_type = s->q_scale_type;
yading@10 63 info->top_field_first = s->top_field_first;
yading@10 64 // Both for MPEG-1 only, zero for MPEG-2:
yading@10 65 info->full_pel_forward_vector = s->full_pel[0];
yading@10 66 info->full_pel_backward_vector = s->full_pel[1];
yading@10 67 // For MPEG-1 fill both horizontal & vertical:
yading@10 68 info->f_code[0][0] = s->mpeg_f_code[0][0];
yading@10 69 info->f_code[0][1] = s->mpeg_f_code[0][1];
yading@10 70 info->f_code[1][0] = s->mpeg_f_code[1][0];
yading@10 71 info->f_code[1][1] = s->mpeg_f_code[1][1];
yading@10 72 for (i = 0; i < 64; ++i) {
yading@10 73 info->intra_quantizer_matrix[i] = s->intra_matrix[i];
yading@10 74 info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
yading@10 75 }
yading@10 76
yading@10 77 return ff_vdpau_common_start_frame(avctx, buffer, size);
yading@10 78 }
yading@10 79
yading@10 80 static int vdpau_mpeg_decode_slice(AVCodecContext *avctx,
yading@10 81 const uint8_t *buffer, uint32_t size)
yading@10 82 {
yading@10 83 AVVDPAUContext *hwctx = avctx->hwaccel_context;
yading@10 84 int val;
yading@10 85
yading@10 86 val = ff_vdpau_add_buffer(avctx, buffer, size);
yading@10 87 if (val < 0)
yading@10 88 return val;
yading@10 89
yading@10 90 hwctx->info.mpeg.slice_count++;
yading@10 91 return 0;
yading@10 92 }
yading@10 93
yading@10 94 #if CONFIG_MPEG1_VDPAU_HWACCEL
yading@10 95 AVHWAccel ff_mpeg1_vdpau_hwaccel = {
yading@10 96 .name = "mpeg1_vdpau",
yading@10 97 .type = AVMEDIA_TYPE_VIDEO,
yading@10 98 .id = AV_CODEC_ID_MPEG1VIDEO,
yading@10 99 .pix_fmt = AV_PIX_FMT_VDPAU,
yading@10 100 .start_frame = vdpau_mpeg_start_frame,
yading@10 101 .end_frame = ff_vdpau_mpeg_end_frame,
yading@10 102 .decode_slice = vdpau_mpeg_decode_slice,
yading@10 103 };
yading@10 104 #endif
yading@10 105
yading@10 106 #if CONFIG_MPEG2_VDPAU_HWACCEL
yading@10 107 AVHWAccel ff_mpeg2_vdpau_hwaccel = {
yading@10 108 .name = "mpeg2_vdpau",
yading@10 109 .type = AVMEDIA_TYPE_VIDEO,
yading@10 110 .id = AV_CODEC_ID_MPEG2VIDEO,
yading@10 111 .pix_fmt = AV_PIX_FMT_VDPAU,
yading@10 112 .start_frame = vdpau_mpeg_start_frame,
yading@10 113 .end_frame = ff_vdpau_mpeg_end_frame,
yading@10 114 .decode_slice = vdpau_mpeg_decode_slice,
yading@10 115 };
yading@10 116 #endif