gstvaapiimage.c 19.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 *  gstvaapiimage.c - VA image abstraction
 *
 *  gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include "config.h"
#include <string.h>
gb's avatar
gb committed
23
#include "gstvaapiutils.h"
24 25 26 27
#include "gstvaapiimage.h"
#include <va/va_backend.h>

#define DEBUG 1
gb's avatar
gb committed
28
#include "gstvaapidebug.h"
29 30 31 32 33 34 35 36 37 38

G_DEFINE_TYPE(GstVaapiImage, gst_vaapi_image, G_TYPE_OBJECT);

#define GST_VAAPI_IMAGE_GET_PRIVATE(obj)                \
    (G_TYPE_INSTANCE_GET_PRIVATE((obj),                 \
                                 GST_VAAPI_TYPE_IMAGE,	\
                                 GstVaapiImagePrivate))

struct _GstVaapiImagePrivate {
    GstVaapiDisplay    *display;
39
    gboolean            is_constructed;
40 41
    VAImage             image;
    guchar             *image_data;
42
    GstVaapiImageFormat internal_format;
43
    GstVaapiImageFormat format;
44 45 46 47 48 49 50 51 52
    guint               width;
    guint               height;
};

enum {
    PROP_0,

    PROP_DISPLAY,
    PROP_IMAGE_ID,
53
    PROP_FORMAT,
54
    PROP_WIDTH,
55
    PROP_HEIGHT
56 57
};

58 59 60 61 62 63
#define SWAP_UINT(a, b) do { \
        unsigned int v = a;  \
        a = b;               \
        b = v;               \
    } while (0)

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
static void
gst_vaapi_image_destroy(GstVaapiImage *image)
{
    GstVaapiImagePrivate * const priv = image->priv;
    VADisplay dpy = gst_vaapi_display_get_display(priv->display);
    VAStatus status;

    gst_vaapi_image_unmap(image);

    if (priv->image.image_id != VA_INVALID_ID) {
        status = vaDestroyImage(dpy, priv->image.image_id);
        if (!vaapi_check_status(status, "vaDestroyImage()"))
            g_warning("failed to destroy image 0x%08x\n", priv->image.image_id);
        priv->image.image_id = VA_INVALID_ID;
    }

    if (priv->display) {
        g_object_unref(priv->display);
        priv->display = NULL;
    }
}

static gboolean
87
_gst_vaapi_image_create(GstVaapiImage *image, GstVaapiImageFormat format)
88 89
{
    GstVaapiImagePrivate * const priv = image->priv;
90
    const VAImageFormat *va_format;
91 92
    VAStatus status;

93
    if (!gst_vaapi_display_has_image_format(priv->display, format))
94 95
        return FALSE;

96 97 98
    va_format = gst_vaapi_image_format_get_va_format(format);
    if (!va_format)
        return FALSE;
99 100 101

    status = vaCreateImage(
        gst_vaapi_display_get_display(priv->display),
102
        (VAImageFormat *)va_format,
103 104 105 106
        priv->width,
        priv->height,
        &priv->image
    );
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    return (status == VA_STATUS_SUCCESS &&
            priv->image.format.fourcc == va_format->fourcc);
}

static gboolean
gst_vaapi_image_create(GstVaapiImage *image)
{
    GstVaapiImagePrivate * const priv = image->priv;

    if (_gst_vaapi_image_create(image, priv->format)) {
        priv->internal_format = priv->format;
        return TRUE;
    }

    switch (priv->format) {
    case GST_VAAPI_IMAGE_I420:
        priv->internal_format = GST_VAAPI_IMAGE_YV12;
        break;
    case GST_VAAPI_IMAGE_YV12:
        priv->internal_format = GST_VAAPI_IMAGE_I420;
        break;
    default:
        priv->internal_format = 0;
        break;
    }
    if (!priv->internal_format)
        return FALSE;
    if (!_gst_vaapi_image_create(image, priv->internal_format))
135 136
        return FALSE;

137
    GST_DEBUG("image 0x%08x", priv->image.image_id);
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    return TRUE;
}

static void
gst_vaapi_image_finalize(GObject *object)
{
    gst_vaapi_image_destroy(GST_VAAPI_IMAGE(object));

    G_OBJECT_CLASS(gst_vaapi_image_parent_class)->finalize(object);
}

static void
gst_vaapi_image_set_property(
    GObject      *object,
    guint         prop_id,
    const GValue *value,
    GParamSpec   *pspec
)
{
    GstVaapiImage        * const image = GST_VAAPI_IMAGE(object);
    GstVaapiImagePrivate * const priv  = image->priv;

    switch (prop_id) {
    case PROP_DISPLAY:
162
        priv->display = g_object_ref(g_value_get_object(value));
163
        break;
164 165 166
    case PROP_FORMAT:
        priv->format = g_value_get_uint(value);
        break;
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
    case PROP_WIDTH:
        priv->width = g_value_get_uint(value);
        break;
    case PROP_HEIGHT:
        priv->height = g_value_get_uint(value);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
        break;
    }
}

static void
gst_vaapi_image_get_property(
    GObject    *object,
    guint       prop_id,
    GValue     *value,
    GParamSpec *pspec
)
{
187
    GstVaapiImage * const image = GST_VAAPI_IMAGE(object);
188 189 190

    switch (prop_id) {
    case PROP_DISPLAY:
191
        g_value_set_pointer(value, gst_vaapi_image_get_display(image));
192 193 194 195
        break;
    case PROP_IMAGE_ID:
        g_value_set_uint(value, gst_vaapi_image_get_id(image));
        break;
196 197 198
    case PROP_FORMAT:
        g_value_set_uint(value, gst_vaapi_image_get_format(image));
        break;
199 200 201 202 203 204 205 206 207 208 209 210
    case PROP_WIDTH:
        g_value_set_uint(value, gst_vaapi_image_get_width(image));
        break;
    case PROP_HEIGHT:
        g_value_set_uint(value, gst_vaapi_image_get_height(image));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
        break;
    }
}

211 212
static void
gst_vaapi_image_constructed(GObject *object)
213
{
214
    GstVaapiImage * const image = GST_VAAPI_IMAGE(object);
215 216
    GObjectClass *parent_class;

217
    image->priv->is_constructed = gst_vaapi_image_create(image);
218 219

    parent_class = G_OBJECT_CLASS(gst_vaapi_image_parent_class);
220 221
    if (parent_class->constructed)
        parent_class->constructed(object);
222 223 224 225 226 227 228 229 230 231 232 233
}

static void
gst_vaapi_image_class_init(GstVaapiImageClass *klass)
{
    GObjectClass * const object_class = G_OBJECT_CLASS(klass);

    g_type_class_add_private(klass, sizeof(GstVaapiImagePrivate));

    object_class->finalize     = gst_vaapi_image_finalize;
    object_class->set_property = gst_vaapi_image_set_property;
    object_class->get_property = gst_vaapi_image_get_property;
234
    object_class->constructed  = gst_vaapi_image_constructed;
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301

    g_object_class_install_property
        (object_class,
         PROP_DISPLAY,
         g_param_spec_object("display",
                             "display",
                             "GStreamer Va display",
                             GST_VAAPI_TYPE_DISPLAY,
                             G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));

    g_object_class_install_property
        (object_class,
         PROP_IMAGE_ID,
         g_param_spec_uint("id",
                           "VA image id",
                           "VA image id",
                           0, G_MAXUINT32, VA_INVALID_ID,
                           G_PARAM_READABLE));

    g_object_class_install_property
        (object_class,
         PROP_WIDTH,
         g_param_spec_uint("width",
                           "width",
                           "Image width",
                           0, G_MAXUINT32, 0,
                           G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));

    g_object_class_install_property
        (object_class,
         PROP_HEIGHT,
         g_param_spec_uint("height",
                           "height",
                           "Image height",
                           0, G_MAXUINT32, 0,
                           G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));

    g_object_class_install_property
        (object_class,
         PROP_FORMAT,
         g_param_spec_uint("format",
                           "format",
                           "Image format",
                           0, G_MAXUINT32, 0,
                           G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
}

static void
gst_vaapi_image_init(GstVaapiImage *image)
{
    GstVaapiImagePrivate *priv = GST_VAAPI_IMAGE_GET_PRIVATE(image);

    image->priv          = priv;
    priv->display        = NULL;
    priv->image_data     = NULL;
    priv->width          = 0;
    priv->height         = 0;
    priv->format         = 0;

    memset(&priv->image, 0, sizeof(priv->image));
    priv->image.image_id = VA_INVALID_ID;
    priv->image.buf      = VA_INVALID_ID;
}

GstVaapiImage *
gst_vaapi_image_new(
    GstVaapiDisplay    *display,
302
    GstVaapiImageFormat format,
303
    guint               width,
304
    guint               height
305 306
)
{
gb's avatar
gb committed
307 308 309 310
    g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
    g_return_val_if_fail(width > 0, NULL);
    g_return_val_if_fail(height > 0, NULL);

gb's avatar
gb committed
311 312
    GST_DEBUG("format %" GST_FOURCC_FORMAT ", size %ux%u",
              GST_FOURCC_ARGS(format), width, height);
313 314 315

    return g_object_new(GST_VAAPI_TYPE_IMAGE,
                        "display", display,
316
                        "format",  format,
317 318 319 320 321 322 323 324 325
                        "width",   width,
                        "height",  height,
                        NULL);
}

VAImageID
gst_vaapi_image_get_id(GstVaapiImage *image)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), VA_INVALID_ID);
326
    g_return_val_if_fail(image->priv->is_constructed, VA_INVALID_ID);
327 328 329 330

    return image->priv->image.image_id;
}

331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
gboolean
gst_vaapi_image_get_image(GstVaapiImage *image, VAImage *va_image)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
    g_return_val_if_fail(image->priv->is_constructed, FALSE);

    if (!va_image)
        return TRUE;

    *va_image = image->priv->image;

    if (image->priv->format != image->priv->internal_format) {
        if (!(image->priv->format == GST_VAAPI_IMAGE_I420 &&
              image->priv->internal_format == GST_VAAPI_IMAGE_YV12) &&
            !(image->priv->format == GST_VAAPI_IMAGE_YV12 &&
              image->priv->internal_format == GST_VAAPI_IMAGE_I420))
            return FALSE;
        SWAP_UINT(va_image->offsets[1], va_image->offsets[2]);
        SWAP_UINT(va_image->pitches[1], va_image->pitches[2]);
    }
    return TRUE;
}

354 355 356 357
GstVaapiDisplay *
gst_vaapi_image_get_display(GstVaapiImage *image)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), NULL);
358
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
359

360
    return image->priv->display;
361 362
}

gb's avatar
gb committed
363 364 365 366 367 368 369 370 371
GstVaapiImageFormat
gst_vaapi_image_get_format(GstVaapiImage *image)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
    g_return_val_if_fail(image->priv->is_constructed, FALSE);

    return image->priv->format;
}

372 373 374 375
guint
gst_vaapi_image_get_width(GstVaapiImage *image)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
376
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
377 378 379 380 381 382 383 384

    return image->priv->width;
}

guint
gst_vaapi_image_get_height(GstVaapiImage *image)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
385
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
386 387 388 389

    return image->priv->height;
}

gb's avatar
gb committed
390 391 392
void
gst_vaapi_image_get_size(GstVaapiImage *image, guint *pwidth, guint *pheight)
{
gb's avatar
gb committed
393 394
    g_return_if_fail(GST_VAAPI_IS_IMAGE(image));
    g_return_if_fail(image->priv->is_constructed);
gb's avatar
gb committed
395 396 397 398 399 400 401 402

    if (pwidth)
        *pwidth = image->priv->width;

    if (pheight)
        *pheight = image->priv->height;
}

403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
gboolean
gst_vaapi_image_is_linear(GstVaapiImage *image)
{
    VAImage va_image;
    guint i, width, height, width2, height2, data_size;

    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
    g_return_val_if_fail(image->priv->is_constructed, FALSE);

    if (!gst_vaapi_image_get_image(image, &va_image))
        return FALSE;

    for (i = 1; i < va_image.num_planes; i++)
        if (va_image.offsets[i] < va_image.offsets[i - 1])
            return FALSE;

    width   = image->priv->width;
    height  = image->priv->height;
    width2  = (width  + 1) / 2;
    height2 = (height + 1) / 2;

    switch (image->priv->internal_format) {
    case GST_VAAPI_IMAGE_NV12:
    case GST_VAAPI_IMAGE_YV12:
    case GST_VAAPI_IMAGE_I420:
        data_size = width * height + 2 * width2 * height2;
        break;
    case GST_VAAPI_IMAGE_ARGB:
    case GST_VAAPI_IMAGE_RGBA:
    case GST_VAAPI_IMAGE_ABGR:
    case GST_VAAPI_IMAGE_BGRA:
        data_size = 4 * width * height;
        break;
    default:
        g_error("FIXME: incomplete formats");
        break;
    }
    return va_image.data_size == data_size;
}

443 444 445 446 447 448 449 450 451 452
static inline gboolean
_gst_vaapi_image_is_mapped(GstVaapiImage *image)
{
    return image->priv->image_data != NULL;
}

gboolean
gst_vaapi_image_is_mapped(GstVaapiImage *image)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
453
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
454 455 456 457 458 459 460 461 462 463 464

    return _gst_vaapi_image_is_mapped(image);
}

gboolean
gst_vaapi_image_map(GstVaapiImage *image)
{
    void *image_data;
    VAStatus status;

    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
465
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487

    if (_gst_vaapi_image_is_mapped(image))
        return TRUE;

    status = vaMapBuffer(
        gst_vaapi_display_get_display(image->priv->display),
        image->priv->image.buf,
        &image_data
    );
    if (!vaapi_check_status(status, "vaMapBuffer()"))
        return FALSE;

    image->priv->image_data = image_data;
    return TRUE;
}

gboolean
gst_vaapi_image_unmap(GstVaapiImage *image)
{
    VAStatus status;

    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
488
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507

    if (!_gst_vaapi_image_is_mapped(image))
        return FALSE;

    status = vaUnmapBuffer(
        gst_vaapi_display_get_display(image->priv->display),
        image->priv->image.buf
    );
    if (!vaapi_check_status(status, "vaUnmapBuffer()"))
        return FALSE;

    image->priv->image_data = NULL;
    return TRUE;
}

guint
gst_vaapi_image_get_plane_count(GstVaapiImage *image)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
508
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
509 510 511 512 513 514 515 516 517
    g_return_val_if_fail(_gst_vaapi_image_is_mapped(image), 0);

    return image->priv->image.num_planes;
}

guchar *
gst_vaapi_image_get_plane(GstVaapiImage *image, guint plane)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), NULL);
518
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
519 520 521 522 523 524 525 526 527 528
    g_return_val_if_fail(_gst_vaapi_image_is_mapped(image), NULL);
    g_return_val_if_fail(plane < image->priv->image.num_planes, NULL);

    return image->priv->image_data + image->priv->image.offsets[plane];
}

guint
gst_vaapi_image_get_pitch(GstVaapiImage *image, guint plane)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
529
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
530 531 532 533 534
    g_return_val_if_fail(_gst_vaapi_image_is_mapped(image), 0);
    g_return_val_if_fail(plane < image->priv->image.num_planes, 0);

    return image->priv->image.pitches[plane];
}
535

536 537 538 539 540 541 542 543 544
guint
gst_vaapi_image_get_data_size(GstVaapiImage *image)
{
    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), 0);
    g_return_val_if_fail(image->priv->is_constructed, FALSE);

    return image->priv->image.data_size;
}

545 546 547 548 549 550 551 552 553 554 555 556
gboolean
gst_vaapi_image_update_from_buffer(GstVaapiImage *image, GstBuffer *buffer)
{
    GstVaapiImagePrivate *priv;
    GstStructure *structure;
    GstCaps *caps;
    GstVaapiImageFormat format;
    gint width, height;
    guint offsets[3], pitches[3], widths[3], heights[3];
    guint i, j;
    guchar *data;
    guint32 data_size;
557
    gboolean swap_YUV;
558 559 560 561 562 563 564 565 566 567 568 569 570 571

    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
    g_return_val_if_fail(GST_IS_BUFFER(buffer), FALSE);

    priv      = image->priv;
    data      = GST_BUFFER_DATA(buffer);
    data_size = GST_BUFFER_SIZE(buffer);
    caps      = GST_BUFFER_CAPS(buffer);

    if (!caps)
        return FALSE;

    format = gst_vaapi_image_format_from_caps(caps);
572
    if (format != priv->format)
573 574
        return FALSE;

575 576 577 578 579 580
    swap_YUV = (priv->format != priv->internal_format &&
                ((priv->format == GST_VAAPI_IMAGE_I420 &&
                  priv->internal_format == GST_VAAPI_IMAGE_YV12) ||
                 (priv->format == GST_VAAPI_IMAGE_YV12 &&
                  priv->internal_format == GST_VAAPI_IMAGE_I420)));

581 582 583 584 585 586 587 588 589
    structure = gst_caps_get_structure(caps, 0);
    gst_structure_get_int(structure, "width",  &width);
    gst_structure_get_int(structure, "height", &height);
    if (width != priv->width || height != priv->height)
        return FALSE;

    if (!gst_vaapi_image_map(image))
        return FALSE;

590
    if (format == priv->internal_format && data_size == priv->image.data_size)
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
        memcpy(priv->image_data, data, data_size);
    else {
        /* XXX: copied from gst_video_format_get_row_stride() -- no NV12? */
        const guint width2  = (width  + 1) / 2;
        const guint height2 = (height + 1) / 2;
        guint size2;
        switch (format) {
        case GST_VAAPI_IMAGE_NV12:
            offsets[0] = 0;
            pitches[0] = GST_ROUND_UP_4(width);
            widths [0] = width;
            heights[0] = height;
            offsets[1] = offsets[0] + height * pitches[0];
            pitches[1] = pitches[0];
            widths [1] = width2 * 2;
            heights[1] = height2;
            size2      = offsets[1] + height2 * pitches[1];
            break;
        case GST_VAAPI_IMAGE_YV12:
        case GST_VAAPI_IMAGE_I420:
            offsets[0] = 0;
            pitches[0] = GST_ROUND_UP_4(width);
            widths [0] = width;
            heights[0] = height;
            offsets[1] = offsets[0] + height * pitches[0];
            pitches[1] = GST_ROUND_UP_4(GST_ROUND_UP_2(width) / 2);
            widths [1] = width2;
            heights[1] = height2;
            offsets[2] = offsets[1] + height2 * pitches[1];
            pitches[2] = pitches[1];
            widths [2] = width2;
            heights[2] = height2;
            size2      = offsets[2] + height2 * pitches[2];
            break;
        case GST_VAAPI_IMAGE_ARGB:
        case GST_VAAPI_IMAGE_RGBA:
        case GST_VAAPI_IMAGE_ABGR:
        case GST_VAAPI_IMAGE_BGRA:
            offsets[0] = 0;
            pitches[0] = width * 4;
            widths [0] = width * 4;
            heights[0] = height;
            size2      = offsets[0] + height * pitches[0];
            break;
        default:
            g_error("could not compute row-stride for %" GST_FOURCC_FORMAT,
                    GST_FOURCC_ARGS(format));
            break;
        }
        if (size2 != data_size)
            g_error("data_size mismatch %d / %u", size2, data_size);
642 643 644 645 646 647 648 649 650 651 652 653 654 655
        if (swap_YUV) {
            guint offset = offsets[1];
            guint stride = pitches[1];
            guint width  = widths [1];
            guint height = heights[1];
            offsets[1]   = offsets[2];
            pitches[1]   = pitches[2];
            widths [1]   = widths [2];
            heights[1]   = heights[2];
            offsets[2]   = offset;
            pitches[2]   = stride;
            widths [2]   = width;
            heights[2]   = height;
        }
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
        for (i = 0; i < priv->image.num_planes; i++) {
            guchar *src = data + offsets[i];
            guchar *dst = priv->image_data + priv->image.offsets[i];
            for (j = 0; j < heights[i]; j++) {
                memcpy(dst, src, widths[i]);
                src += pitches[i];
                dst += priv->image.pitches[i];
            }
        }
    }

    if (!gst_vaapi_image_unmap(image))
        return FALSE;

    return TRUE;
}