~thopiekar/arm-mali/libvdpau-sunxi

« back to all changes in this revision

Viewing changes to mpeg4.c

  • Committer: Jens Kuske
  • Date: 2016-02-16 13:12:22 UTC
  • Revision ID: git-v1:685769372a8281bf67046a958883323aaf14d232
Use libcedrus

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <stdlib.h>
21
21
#include <string.h>
22
22
#include <unistd.h>
 
23
#include <cedrus/cedrus.h>
 
24
#include <cedrus/cedrus_regs.h>
23
25
#include "vdpau_private.h"
24
 
#include "ve.h"
25
26
 
26
27
typedef struct
27
28
{
75
76
 
76
77
typedef struct
77
78
{
78
 
        struct ve_mem *mbh_buffer;
79
 
        struct ve_mem *dcac_buffer;
80
 
        struct ve_mem *ncf_buffer;
 
79
        cedrus_mem_t *mbh_buffer;
 
80
        cedrus_mem_t *dcac_buffer;
 
81
        cedrus_mem_t *ncf_buffer;
81
82
} mpeg4_private_t;
82
83
 
83
84
static void mpeg4_private_free(decoder_ctx_t *decoder)
84
85
{
85
86
        mpeg4_private_t *decoder_p = (mpeg4_private_t *)decoder->private;
86
 
        ve_free(decoder_p->mbh_buffer);
87
 
        ve_free(decoder_p->dcac_buffer);
88
 
        ve_free(decoder_p->ncf_buffer);
 
87
        cedrus_mem_free(decoder_p->mbh_buffer);
 
88
        cedrus_mem_free(decoder_p->dcac_buffer);
 
89
        cedrus_mem_free(decoder_p->ncf_buffer);
89
90
        free(decoder_p);
90
91
}
91
92
 
163
164
        if (ret != VDP_STATUS_OK)
164
165
                return ret;
165
166
 
166
 
        bitstream bs = { .data = decoder->data->virt, .length = len, .bitpos = 0 };
 
167
        bitstream bs = { .data = cedrus_mem_get_pointer(decoder->data), .length = len, .bitpos = 0 };
167
168
 
168
169
        while (find_startcode(&bs))
169
170
        {
175
176
                        continue;
176
177
 
177
178
                // activate MPEG engine
178
 
                void *ve_regs = ve_get(VE_ENGINE_MPEG, 0);
 
179
                void *ve_regs = cedrus_ve_get(decoder->device->cedrus, CEDRUS_ENGINE_MPEG, 0);
179
180
 
180
181
                // set buffers
181
 
                writel(decoder_p->mbh_buffer->phys, ve_regs + VE_MPEG_MBH_ADDR);
182
 
                writel(decoder_p->dcac_buffer->phys, ve_regs + VE_MPEG_DCAC_ADDR);
183
 
                writel(decoder_p->ncf_buffer->phys, ve_regs + VE_MPEG_NCF_ADDR);
 
182
                writel(cedrus_mem_get_bus_addr(decoder_p->mbh_buffer), ve_regs + VE_MPEG_MBH_ADDR);
 
183
                writel(cedrus_mem_get_bus_addr(decoder_p->dcac_buffer), ve_regs + VE_MPEG_DCAC_ADDR);
 
184
                writel(cedrus_mem_get_bus_addr(decoder_p->ncf_buffer), ve_regs + VE_MPEG_NCF_ADDR);
184
185
 
185
186
                // set output buffers
186
 
                writel(output->rec->phys, ve_regs + VE_MPEG_REC_LUMA);
187
 
                writel(output->rec->phys + output->luma_size, ve_regs + VE_MPEG_REC_CHROMA);
188
 
                writel(output->yuv->data->phys, ve_regs + VE_MPEG_ROT_LUMA);
189
 
                writel(output->yuv->data->phys + output->luma_size, ve_regs + VE_MPEG_ROT_CHROMA);
 
187
                writel(cedrus_mem_get_bus_addr(output->rec), ve_regs + VE_MPEG_REC_LUMA);
 
188
                writel(cedrus_mem_get_bus_addr(output->rec) + output->luma_size, ve_regs + VE_MPEG_REC_CHROMA);
 
189
                writel(cedrus_mem_get_bus_addr(output->yuv->data), ve_regs + VE_MPEG_ROT_LUMA);
 
190
                writel(cedrus_mem_get_bus_addr(output->yuv->data) + output->luma_size, ve_regs + VE_MPEG_ROT_CHROMA);
190
191
 
191
192
                // ??
192
193
                writel(0x40620000, ve_regs + VE_MPEG_SDROT_CTRL);
193
 
                if (ve_get_version() == 0x1680)
 
194
                if (cedrus_get_ve_version(decoder->device->cedrus) == 0x1680)
194
195
                        writel((0x2 << 30) | (0x1 << 28) | (output->chroma_size / 2), ve_regs + VE_EXTRA_OUT_FMT_OFFSET);
195
196
 
196
197
                // set vop header
217
218
                writel(0x0, ve_regs + VE_MPEG_MBA);
218
219
 
219
220
                // enable interrupt, unknown control flags
220
 
                writel(0x80084118 | ((ve_get_version() != 0x1680) << 7) | ((hdr.vop_coding_type == VOP_P ? 0x1 : 0x0) << 12), ve_regs + VE_MPEG_CTRL);
 
221
                writel(0x80084118 | ((cedrus_get_ve_version(decoder->device->cedrus) != 0x1680) << 7) | ((hdr.vop_coding_type == VOP_P ? 0x1 : 0x0) << 12), ve_regs + VE_MPEG_CTRL);
221
222
 
222
223
                // set quantization parameter
223
224
                writel(hdr.vop_quant, ve_regs + VE_MPEG_QP_INPUT);
226
227
                if (info->forward_reference != VDP_INVALID_HANDLE)
227
228
                {
228
229
                        video_surface_ctx_t *forward = handle_get(info->forward_reference);
229
 
                        writel(forward->rec->phys, ve_regs + VE_MPEG_FWD_LUMA);
230
 
                        writel(forward->rec->phys + forward->luma_size, ve_regs + VE_MPEG_FWD_CHROMA);
 
230
                        writel(cedrus_mem_get_bus_addr(forward->rec), ve_regs + VE_MPEG_FWD_LUMA);
 
231
                        writel(cedrus_mem_get_bus_addr(forward->rec) + forward->luma_size, ve_regs + VE_MPEG_FWD_CHROMA);
231
232
                }
232
233
                if (info->backward_reference != VDP_INVALID_HANDLE)
233
234
                {
234
235
                        video_surface_ctx_t *backward = handle_get(info->backward_reference);
235
 
                        writel(backward->rec->phys, ve_regs + VE_MPEG_BACK_LUMA);
236
 
                        writel(backward->rec->phys + backward->luma_size, ve_regs + VE_MPEG_BACK_CHROMA);
 
236
                        writel(cedrus_mem_get_bus_addr(backward->rec), ve_regs + VE_MPEG_BACK_LUMA);
 
237
                        writel(cedrus_mem_get_bus_addr(backward->rec) + backward->luma_size, ve_regs + VE_MPEG_BACK_CHROMA);
237
238
                }
238
239
 
239
240
                // set trb/trd
254
255
                writel(len * 8 - bs.bitpos, ve_regs + VE_MPEG_VLD_LEN);
255
256
 
256
257
                // input end
257
 
                uint32_t input_addr = decoder->data->phys;
 
258
                uint32_t input_addr = cedrus_mem_get_bus_addr(decoder->data);
258
259
                writel(input_addr + VBV_SIZE - 1, ve_regs + VE_MPEG_VLD_END);
259
260
 
260
261
                // set input buffer
263
264
                // trigger
264
265
                writel(0x8400000d | ((width * height) << 8), ve_regs + VE_MPEG_TRIGGER);
265
266
 
266
 
                ve_wait(1);
 
267
                cedrus_ve_wait(decoder->device->cedrus, 1);
267
268
 
268
269
                // clear status
269
270
                writel(readl(ve_regs + VE_MPEG_STATUS) | 0xf, ve_regs + VE_MPEG_STATUS);
270
271
 
271
272
                // stop MPEG engine
272
 
                ve_put();
 
273
                cedrus_ve_put(decoder->device->cedrus);
273
274
        }
274
275
 
275
276
        return VDP_STATUS_OK;
284
285
        int width = ((decoder->width + 15) / 16);
285
286
        int height = ((decoder->height + 15) / 16);
286
287
 
287
 
        decoder_p->mbh_buffer = ve_malloc(height * 2048);
 
288
        decoder_p->mbh_buffer = cedrus_mem_alloc(decoder->device->cedrus, height * 2048);
288
289
        if (!decoder_p->mbh_buffer)
289
290
                goto err_mbh;
290
291
 
291
 
        decoder_p->dcac_buffer = ve_malloc(width * height * 2);
 
292
        decoder_p->dcac_buffer = cedrus_mem_alloc(decoder->device->cedrus, width * height * 2);
292
293
        if (!decoder_p->dcac_buffer)
293
294
                goto err_dcac;
294
295
 
295
 
        decoder_p->ncf_buffer = ve_malloc(4 * 1024);
 
296
        decoder_p->ncf_buffer = cedrus_mem_alloc(decoder->device->cedrus, 4 * 1024);
296
297
        if (!decoder_p->ncf_buffer)
297
298
                goto err_ncf;
298
299
 
303
304
        return VDP_STATUS_OK;
304
305
 
305
306
err_ncf:
306
 
        ve_free(decoder_p->dcac_buffer);
 
307
        cedrus_mem_free(decoder_p->dcac_buffer);
307
308
err_dcac:
308
 
        ve_free(decoder_p->mbh_buffer);
 
309
        cedrus_mem_free(decoder_p->mbh_buffer);
309
310
err_mbh:
310
311
        free(decoder_p);
311
312
err_priv: