]> git.sesse.net Git - ffmpeg/blob - libavcodec/vdpau_vc1.c
dsputil: Move LOCAL_ALIGNED macros to libavutil
[ffmpeg] / libavcodec / vdpau_vc1.c
1 /*
2  * VC-1 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 Libav.
8  *
9  * Libav 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  * Libav 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 Libav; 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 "vc1.h"
28 #include "vdpau.h"
29 #include "vdpau_internal.h"
30
31 static int vdpau_vc1_start_frame(AVCodecContext *avctx,
32                                  const uint8_t *buffer, uint32_t size)
33 {
34     VC1Context * const v  = avctx->priv_data;
35     AVVDPAUContext *hwctx = avctx->hwaccel_context;
36     MpegEncContext * const s = &v->s;
37     VdpPictureInfoVC1 *info = &hwctx->info.vc1;
38     VdpVideoSurface ref;
39
40     /*  fill LvPictureInfoVC1 struct */
41     info->forward_reference  = VDP_INVALID_HANDLE;
42     info->backward_reference = VDP_INVALID_HANDLE;
43
44     switch (s->pict_type) {
45     case AV_PICTURE_TYPE_B:
46         ref = ff_vdpau_get_surface_id(&s->next_picture);
47         assert(ref != VDP_INVALID_HANDLE);
48         info->backward_reference = ref;
49         /* fall-through */
50     case AV_PICTURE_TYPE_P:
51         ref = ff_vdpau_get_surface_id(&s->last_picture);
52         assert(ref != VDP_INVALID_HANDLE);
53         info->forward_reference  = ref;
54     }
55
56     info->slice_count       = 0;
57     if (v->bi_type)
58         info->picture_type  = 4;
59     else
60         info->picture_type  = s->pict_type - 1 + s->pict_type / 3;
61
62     info->frame_coding_mode = v->fcm;
63     info->postprocflag      = v->postprocflag;
64     info->pulldown          = v->broadcast;
65     info->interlace         = v->interlace;
66     info->tfcntrflag        = v->tfcntrflag;
67     info->finterpflag       = v->finterpflag;
68     info->psf               = v->psf;
69     info->dquant            = v->dquant;
70     info->panscan_flag      = v->panscanflag;
71     info->refdist_flag      = v->refdist_flag;
72     info->quantizer         = v->quantizer_mode;
73     info->extended_mv       = v->extended_mv;
74     info->extended_dmv      = v->extended_dmv;
75     info->overlap           = v->overlap;
76     info->vstransform       = v->vstransform;
77     info->loopfilter        = v->s.loop_filter;
78     info->fastuvmc          = v->fastuvmc;
79     info->range_mapy_flag   = v->range_mapy_flag;
80     info->range_mapy        = v->range_mapy;
81     info->range_mapuv_flag  = v->range_mapuv_flag;
82     info->range_mapuv       = v->range_mapuv;
83     /* Specific to simple/main profile only */
84     info->multires          = v->multires;
85     info->syncmarker        = v->s.resync_marker;
86     info->rangered          = v->rangered | (v->rangeredfrm << 1);
87     info->maxbframes        = v->s.max_b_frames;
88     info->deblockEnable     = v->postprocflag & 1;
89     info->pquant            = v->pq;
90
91     return ff_vdpau_common_start_frame(avctx, buffer, size);
92 }
93
94 static int vdpau_vc1_decode_slice(AVCodecContext *avctx,
95                                   const uint8_t *buffer, uint32_t size)
96 {
97     AVVDPAUContext *hwctx = avctx->hwaccel_context;
98     int val;
99
100     val = ff_vdpau_add_buffer(avctx, buffer, size);
101     if (val < 0)
102         return val;
103
104     hwctx->info.vc1.slice_count++;
105     return 0;
106 }
107
108 #if CONFIG_WMV3_VDPAU_HWACCEL
109 AVHWAccel ff_wmv3_vdpau_hwaccel = {
110     .name           = "wm3_vdpau",
111     .type           = AVMEDIA_TYPE_VIDEO,
112     .id             = AV_CODEC_ID_WMV3,
113     .pix_fmt        = AV_PIX_FMT_VDPAU,
114     .start_frame    = vdpau_vc1_start_frame,
115     .end_frame      = ff_vdpau_common_end_frame,
116     .decode_slice   = vdpau_vc1_decode_slice,
117 };
118 #endif
119
120 AVHWAccel ff_vc1_vdpau_hwaccel = {
121     .name           = "vc1_vdpau",
122     .type           = AVMEDIA_TYPE_VIDEO,
123     .id             = AV_CODEC_ID_VC1,
124     .pix_fmt        = AV_PIX_FMT_VDPAU,
125     .start_frame    = vdpau_vc1_start_frame,
126     .end_frame      = ff_vdpau_common_end_frame,
127     .decode_slice   = vdpau_vc1_decode_slice,
128 };