~ubuntu-branches/ubuntu/trusty/vdpau-video/trusty-proposed

« back to all changes in this revision

Viewing changes to src/vdpau_image.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2011-09-22 11:35:45 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20110922113545-037dkroelik2be0y
Tags: 0.7.3-0ubuntu1
New upstream version, fix FTBFS with libav 0.7. Closes: #614485, LP: #756021.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  vdpau_image.c - VDPAU backend for VA API (VA images)
 
2
 *  vdpau_image.c - VDPAU backend for VA-API (VA images)
3
3
 *
4
 
 *  vdpau-video (C) 2009-2010 Splitted-Desktop Systems
 
4
 *  vdpau-video (C) 2009-2011 Splitted-Desktop Systems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
50
50
      NPE, EB, { C0, C1, C2, C3 } }
51
51
    DEF_YUV(YCBCR, NV12,        ('N','V','1','2'), LSB, 12),
52
52
    DEF_YUV(YCBCR, YV12,        ('Y','V','1','2'), LSB, 12),
 
53
    DEF_YUV(YCBCR, YV12,        ('I','4','2','0'), LSB, 12), // swap U/V planes
53
54
    DEF_YUV(YCBCR, UYVY,        ('U','Y','V','Y'), LSB, 16),
54
55
    DEF_YUV(YCBCR, YUYV,        ('Y','U','Y','V'), LSB, 16),
55
56
    DEF_YUV(YCBCR, V8U8Y8A8,    ('A','Y','U','V'), LSB, 32),
183
184
    out_image->buf      = VA_INVALID_ID;
184
185
 
185
186
    VAImageID image_id = object_heap_allocate(&driver_data->image_heap);
186
 
    if (image_id == VA_INVALID_ID)
187
 
        return VA_STATUS_ERROR_ALLOCATION_FAILED;
 
187
    if (image_id == VA_INVALID_ID) {
 
188
        va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
 
189
        goto error;
 
190
    }
188
191
 
189
192
    object_image_p obj_image = VDPAU_IMAGE(image_id);
190
 
    if (!obj_image)
191
 
        return VA_STATUS_ERROR_ALLOCATION_FAILED;
 
193
    if (!obj_image) {
 
194
        va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
 
195
        goto error;
 
196
    }
192
197
 
193
198
    const vdpau_image_format_map_t *m = get_format(format);
194
 
    if (!m)
195
 
        return VA_STATUS_ERROR_UNKNOWN; /* VA_STATUS_ERROR_UNSUPPORTED_FORMAT */
 
199
    if (!m) {
 
200
        va_status = VA_STATUS_ERROR_UNKNOWN; /* VA_STATUS_ERROR_UNSUPPORTED_FORMAT */
 
201
        goto error;
 
202
    }
196
203
 
197
204
    VAImage * const image = &obj_image->image;
198
205
    image->image_id       = image_id;
213
220
        image->data_size  = size + 2 * size2;
214
221
        break;
215
222
    case VA_FOURCC('Y','V','1','2'):
 
223
    case VA_FOURCC('I','4','2','0'):
216
224
        image->num_planes = 3;
217
225
        image->pitches[0] = width;
218
226
        image->offsets[0] = 0;
219
227
        image->pitches[1] = width2;
220
 
        image->offsets[1] = size + size2;
 
228
        image->offsets[1] = size;
221
229
        image->pitches[2] = width2;
222
 
        image->offsets[2] = size;
 
230
        image->offsets[2] = size + size2;
223
231
        image->data_size  = size + 2 * size2;
224
232
        break;
225
233
    case VA_FOURCC('A','R','G','B'):
251
259
        goto error;
252
260
    }
253
261
 
 
262
    /* Allocate more bytes to align image data base on 16-byte boundaries */
 
263
    /* XXX: align other planes too? */
 
264
    static const int ALIGN = 16;
 
265
 
254
266
    va_status = vdpau_CreateBuffer(ctx, 0, VAImageBufferType,
255
 
                                   image->data_size, 1, NULL,
 
267
                                   image->data_size + ALIGN, 1, NULL,
256
268
                                   &image->buf);
257
269
    if (va_status != VA_STATUS_SUCCESS)
258
270
        goto error;
259
271
 
 
272
    object_buffer_p obj_buffer = VDPAU_BUFFER(image->buf);
 
273
    if (!obj_buffer)
 
274
        goto error;
 
275
 
 
276
    int align = ((uintptr_t)obj_buffer->buffer_data) % ALIGN;
 
277
    if (align) {
 
278
        align = ALIGN - align;
 
279
        for (i = 0; i < image->num_planes; i++)
 
280
            image->offsets[i] += align;
 
281
    }
 
282
 
260
283
    obj_image->vdp_rgba_output_surface = VDP_INVALID_HANDLE;
261
284
    obj_image->vdp_format_type  = m->vdp_format_type;
262
285
    obj_image->vdp_format       = m->vdp_format;
383
406
    if (!obj_buffer)
384
407
        return VA_STATUS_ERROR_INVALID_BUFFER;
385
408
 
386
 
    for (i = 0; i < image->num_planes; i++) {
387
 
        src[i] = (uint8_t *)obj_buffer->buffer_data + image->offsets[i];
388
 
        src_stride[i] = image->pitches[i];
 
409
    switch (image->format.fourcc) {
 
410
    case VA_FOURCC('I','4','2','0'):
 
411
        src[0] = (uint8_t *)obj_buffer->buffer_data + image->offsets[0];
 
412
        src_stride[0] = image->pitches[0];
 
413
        src[1] = (uint8_t *)obj_buffer->buffer_data + image->offsets[2];
 
414
        src_stride[1] = image->pitches[2];
 
415
        src[2] = (uint8_t *)obj_buffer->buffer_data + image->offsets[1];
 
416
        src_stride[2] = image->pitches[1];
 
417
        break;
 
418
    default:
 
419
        for (i = 0; i < image->num_planes; i++) {
 
420
            src[i] = (uint8_t *)obj_buffer->buffer_data + image->offsets[i];
 
421
            src_stride[i] = image->pitches[i];
 
422
        }
 
423
        break;
389
424
    }
390
425
 
391
426
    switch (obj_image->vdp_format_type) {
416
451
                &obj_image->vdp_rgba_output_surface
417
452
            );
418
453
            if (vdp_status != VDP_STATUS_OK)
419
 
                return vdpau_get_VAStatus(driver_data, vdp_status);
 
454
                return vdpau_get_VAStatus(vdp_status);
420
455
        }
421
456
 
422
457
        VdpRect vdp_rect;
426
461
        vdp_rect.y1 = rect->y + rect->height;
427
462
        vdp_status = video_mixer_render(
428
463
            driver_data,
 
464
            obj_surface->video_mixer,
429
465
            obj_surface,
 
466
            VDP_INVALID_HANDLE,
430
467
            obj_image->vdp_rgba_output_surface,
431
468
            &vdp_rect,
432
469
            &vdp_rect,
433
470
            0
434
471
        );
435
472
        if (vdp_status != VDP_STATUS_OK)
436
 
            return vdpau_get_VAStatus(driver_data, vdp_status);
 
473
            return vdpau_get_VAStatus(vdp_status);
437
474
 
438
475
        vdp_status = vdpau_output_surface_get_bits_native(
439
476
            driver_data,
446
483
    default:
447
484
        return VA_STATUS_ERROR_OPERATION_FAILED;
448
485
    }
449
 
    return vdpau_get_VAStatus(driver_data, vdp_status);
 
486
    return vdpau_get_VAStatus(vdp_status);
450
487
}
451
488
 
452
489
// vaGetImage
525
562
    if (!obj_buffer)
526
563
        return VA_STATUS_ERROR_INVALID_BUFFER;
527
564
 
528
 
    for (i = 0; i < image->num_planes; i++) {
529
 
        src[i] = (uint8_t *)obj_buffer->buffer_data + image->offsets[i];
530
 
        src_stride[i] = image->pitches[i];
 
565
    switch (image->format.fourcc) {
 
566
    case VA_FOURCC('I','4','2','0'):
 
567
        src[0] = (uint8_t *)obj_buffer->buffer_data + image->offsets[0];
 
568
        src_stride[0] = image->pitches[0];
 
569
        src[1] = (uint8_t *)obj_buffer->buffer_data + image->offsets[2];
 
570
        src_stride[1] = image->pitches[2];
 
571
        src[2] = (uint8_t *)obj_buffer->buffer_data + image->offsets[1];
 
572
        src_stride[2] = image->pitches[1];
 
573
        break;
 
574
    default:
 
575
        for (i = 0; i < image->num_planes; i++) {
 
576
            src[i] = (uint8_t *)obj_buffer->buffer_data + image->offsets[i];
 
577
            src_stride[i] = image->pitches[i];
 
578
        }
 
579
        break;
531
580
    }
532
581
 
533
582
    /* XXX: only support YCbCr surfaces for now */
540
589
        obj_image->vdp_format,
541
590
        src, src_stride
542
591
    );
543
 
    return vdpau_get_VAStatus(driver_data, vdp_status);
 
592
    return vdpau_get_VAStatus(vdp_status);
544
593
}
545
594
 
546
595
// vaPutImage