Subversion Repositories Kolibri OS

Rev

Rev 4349 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/*
2
 * Video Acceleration API (video decoding)
3
 * HW decode acceleration for MPEG-2, MPEG-4, H.264 and VC-1
4
 *
5
 * Copyright (C) 2008-2009 Splitted-Desktop Systems
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
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
 */
23
 
24
#include "h264.h"
25
#include "vaapi_internal.h"
26
 
27
/**
28
 * @addtogroup VAAPI_Decoding
29
 *
30
 * @{
31
 */
32
 
5601 serge 33
#define ENTER()   printf("enter %s\n",__FUNCTION__)
34
#define LEAVE()   printf("leave %s\n",__FUNCTION__)
35
#define FAIL()    printf("fail %s\n",__FUNCTION__)
36
 
37
 
4349 Serge 38
static void destroy_buffers(VADisplay display, VABufferID *buffers, unsigned int n_buffers)
39
{
40
    unsigned int i;
41
    for (i = 0; i < n_buffers; i++) {
42
        if (buffers[i]) {
43
            vaDestroyBuffer(display, buffers[i]);
44
            buffers[i] = 0;
45
        }
46
    }
47
}
48
 
49
int ff_vaapi_render_picture(struct vaapi_context *vactx, VASurfaceID surface)
50
{
51
    VABufferID va_buffers[3];
52
    unsigned int n_va_buffers = 0;
53
 
54
    if (!vactx->pic_param_buf_id)
55
        return 0;
56
 
57
    vaUnmapBuffer(vactx->display, vactx->pic_param_buf_id);
58
    va_buffers[n_va_buffers++] = vactx->pic_param_buf_id;
59
 
60
    if (vactx->iq_matrix_buf_id) {
61
        vaUnmapBuffer(vactx->display, vactx->iq_matrix_buf_id);
62
        va_buffers[n_va_buffers++] = vactx->iq_matrix_buf_id;
63
    }
64
 
65
    if (vactx->bitplane_buf_id) {
66
        vaUnmapBuffer(vactx->display, vactx->bitplane_buf_id);
67
        va_buffers[n_va_buffers++] = vactx->bitplane_buf_id;
68
    }
69
 
70
    if (vaBeginPicture(vactx->display, vactx->context_id,
71
                       surface) != VA_STATUS_SUCCESS)
72
        return -1;
73
 
74
    if (vaRenderPicture(vactx->display, vactx->context_id,
75
                        va_buffers, n_va_buffers) != VA_STATUS_SUCCESS)
76
        return -1;
77
 
78
    if (vaRenderPicture(vactx->display, vactx->context_id,
79
                        vactx->slice_buf_ids,
80
                        vactx->n_slice_buf_ids) != VA_STATUS_SUCCESS)
81
        return -1;
82
 
83
    if (vaEndPicture(vactx->display, vactx->context_id) != VA_STATUS_SUCCESS)
84
        return -1;
85
 
86
    return 0;
87
}
88
 
89
int ff_vaapi_commit_slices(struct vaapi_context *vactx)
90
{
91
    VABufferID *slice_buf_ids;
92
    VABufferID slice_param_buf_id, slice_data_buf_id;
93
 
94
    if (vactx->slice_count == 0)
95
        return 0;
96
 
97
    slice_buf_ids =
98
        av_fast_realloc(vactx->slice_buf_ids,
99
                        &vactx->slice_buf_ids_alloc,
100
                        (vactx->n_slice_buf_ids + 2) * sizeof(slice_buf_ids[0]));
101
    if (!slice_buf_ids)
102
        return -1;
103
    vactx->slice_buf_ids = slice_buf_ids;
104
 
105
    slice_param_buf_id = 0;
106
    if (vaCreateBuffer(vactx->display, vactx->context_id,
107
                       VASliceParameterBufferType,
108
                       vactx->slice_param_size,
109
                       vactx->slice_count, vactx->slice_params,
110
                       &slice_param_buf_id) != VA_STATUS_SUCCESS)
111
        return -1;
112
    vactx->slice_count = 0;
113
 
114
    slice_data_buf_id = 0;
115
    if (vaCreateBuffer(vactx->display, vactx->context_id,
116
                       VASliceDataBufferType,
117
                       vactx->slice_data_size,
118
                       1, (void *)vactx->slice_data,
119
                       &slice_data_buf_id) != VA_STATUS_SUCCESS)
120
        return -1;
121
    vactx->slice_data = NULL;
122
    vactx->slice_data_size = 0;
123
 
124
    slice_buf_ids[vactx->n_slice_buf_ids++] = slice_param_buf_id;
125
    slice_buf_ids[vactx->n_slice_buf_ids++] = slice_data_buf_id;
126
    return 0;
127
}
128
 
129
static void *alloc_buffer(struct vaapi_context *vactx, int type, unsigned int size, uint32_t *buf_id)
130
{
131
    void *data = NULL;
132
 
133
    *buf_id = 0;
134
    if (vaCreateBuffer(vactx->display, vactx->context_id,
135
                       type, size, 1, NULL, buf_id) == VA_STATUS_SUCCESS)
136
        vaMapBuffer(vactx->display, *buf_id, &data);
137
 
138
    return data;
139
}
140
 
141
void *ff_vaapi_alloc_pic_param(struct vaapi_context *vactx, unsigned int size)
142
{
143
    return alloc_buffer(vactx, VAPictureParameterBufferType, size, &vactx->pic_param_buf_id);
144
}
145
 
146
void *ff_vaapi_alloc_iq_matrix(struct vaapi_context *vactx, unsigned int size)
147
{
148
    return alloc_buffer(vactx, VAIQMatrixBufferType, size, &vactx->iq_matrix_buf_id);
149
}
150
 
151
uint8_t *ff_vaapi_alloc_bitplane(struct vaapi_context *vactx, uint32_t size)
152
{
153
    return alloc_buffer(vactx, VABitPlaneBufferType, size, &vactx->bitplane_buf_id);
154
}
155
 
156
VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, const uint8_t *buffer, uint32_t size)
157
{
158
    uint8_t *slice_params;
159
    VASliceParameterBufferBase *slice_param;
5601 serge 160
ENTER();
4349 Serge 161
    if (!vactx->slice_data)
162
        vactx->slice_data = buffer;
163
    if (vactx->slice_data + vactx->slice_data_size != buffer) {
164
        if (ff_vaapi_commit_slices(vactx) < 0)
165
            return NULL;
166
        vactx->slice_data = buffer;
167
    }
168
 
169
    slice_params =
170
        av_fast_realloc(vactx->slice_params,
171
                        &vactx->slice_params_alloc,
172
                        (vactx->slice_count + 1) * vactx->slice_param_size);
173
    if (!slice_params)
174
        return NULL;
175
    vactx->slice_params = slice_params;
176
 
177
    slice_param = (VASliceParameterBufferBase *)(slice_params + vactx->slice_count * vactx->slice_param_size);
178
    slice_param->slice_data_size   = size;
179
    slice_param->slice_data_offset = vactx->slice_data_size;
180
    slice_param->slice_data_flag   = VA_SLICE_DATA_FLAG_ALL;
181
 
182
    vactx->slice_count++;
183
    vactx->slice_data_size += size;
5601 serge 184
LEAVE();
4349 Serge 185
    return slice_param;
186
}
187
 
188
void ff_vaapi_common_end_frame(AVCodecContext *avctx)
189
{
190
    struct vaapi_context * const vactx = avctx->hwaccel_context;
191
 
192
    av_dlog(avctx, "ff_vaapi_common_end_frame()\n");
193
 
194
    destroy_buffers(vactx->display, &vactx->pic_param_buf_id, 1);
195
    destroy_buffers(vactx->display, &vactx->iq_matrix_buf_id, 1);
196
    destroy_buffers(vactx->display, &vactx->bitplane_buf_id, 1);
197
    destroy_buffers(vactx->display, vactx->slice_buf_ids, vactx->n_slice_buf_ids);
198
    av_freep(&vactx->slice_buf_ids);
199
    av_freep(&vactx->slice_params);
200
    vactx->n_slice_buf_ids     = 0;
201
    vactx->slice_buf_ids_alloc = 0;
202
    vactx->slice_count         = 0;
203
    vactx->slice_params_alloc  = 0;
204
}
205
 
206
/* @} */