From 9f134c1b6d7e4a488db9933f489ea2a56ec057b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= <@> Date: Thu, 16 Oct 2014 14:16:01 +0200 Subject: [PATCH] Corrected black surface for va-api. --- ChangeLog | 7 +++- video.c | 113 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 72 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ca9bd0..79bf45a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ +User Antti Seppälä +Date: Thu Oct 16 14:15:15 CEST 2014 + + Corrected black surface for va-api. + User johns -Date: +Date: Thu Oct 16 14:05:17 CEST 2014 Newer va-api intel drivers support PutImage. Use more portable fork for vfork. diff --git a/video.c b/video.c index f963c95..7f47f5e 100644 --- a/video.c +++ b/video.c @@ -3555,66 +3555,85 @@ static void VaapiBlackSurface(VaapiDecoder * decoder) } if (decoder->BlackSurface == VA_INVALID_ID) { - if (vaCreateSurfaces(decoder->VaDisplay, VA_RT_FORMAT_YUV420, - VideoWindowWidth, VideoWindowHeight, &decoder->BlackSurface, 1, - NULL, 0) != VA_STATUS_SUCCESS) { - Error(_("video/vaapi: can't create a surface\n")); + uint8_t *va_image_data; + unsigned u; + + status = + vaCreateSurfaces(decoder->VaDisplay, VA_RT_FORMAT_YUV420, + VideoWindowWidth, VideoWindowHeight, &decoder->BlackSurface, 1, + NULL, 0); + if (status != VA_STATUS_SUCCESS) { + Error(_("video/vaapi: can't create a surface: %s\n"), + vaErrorStr(status)); return; } // full sized surface, no difference unscaled/scaled osd - if (vaAssociateSubpicture(decoder->VaDisplay, VaOsdSubpicture, - &decoder->BlackSurface, 1, 0, 0, VaOsdImage.width, - VaOsdImage.height, 0, 0, VideoWindowWidth, VideoWindowHeight, - 0) != VA_STATUS_SUCCESS) { - Error(_("video/vaapi: can't associate subpicture\n")); + status = + vaAssociateSubpicture(decoder->VaDisplay, VaOsdSubpicture, + &decoder->BlackSurface, 1, 0, 0, VaOsdImage.width, + VaOsdImage.height, 0, 0, VideoWindowWidth, VideoWindowHeight, 0); + if (status != VA_STATUS_SUCCESS) { + Error(_("video/vaapi: can't associate subpicture: %s\n"), + vaErrorStr(status)); } Debug(3, "video/vaapi: associate %08x\n", decoder->BlackSurface); - // FIXME: check if intel forgets this also - if (0 && decoder->Image->image_id == VA_INVALID_ID) { + if (decoder->Image->image_id == VA_INVALID_ID) { VAImageFormat format[1]; - void *va_image_data; - int i; - printf("No image\n"); VaapiFindImageFormat(decoder, PIX_FMT_NV12, format); - if ((status = - vaDeriveImage(decoder->VaDisplay, decoder->BlackSurface, - decoder->Image)) != VA_STATUS_SUCCESS) { - Error(_("video/vaapi: vaDeriveImage failed %d\n"), status); - if (vaCreateImage(VaDisplay, format, VideoWindowWidth, - VideoWindowHeight, - decoder->Image) != VA_STATUS_SUCCESS) { - Error(_("video/vaapi: can't create image!\n")); - } - } - if (vaMapBuffer(VaDisplay, decoder->Image->buf, &va_image_data) - != VA_STATUS_SUCCESS) { - Error(_("video/vaapi: can't map the image!\n")); - } - - for (i = 0; (unsigned)i < decoder->Image->data_size; i += 2) { - ((uint8_t *) va_image_data)[i + 0] = 0xFF; - ((uint8_t *) va_image_data)[i + 1] = 0xFF; - } - - if (vaUnmapBuffer(VaDisplay, - decoder->Image->buf) != VA_STATUS_SUCCESS) { - Error(_("video/vaapi: can't unmap the image!\n")); - } - if (vaDestroyImage(VaDisplay, - decoder->Image->image_id) != VA_STATUS_SUCCESS) { - Error(_("video/vaapi: can't destroy image!\n")); + status = + vaCreateImage(VaDisplay, format, VideoWindowWidth, + VideoWindowHeight, decoder->Image); + if (status != VA_STATUS_SUCCESS) { + Error(_("video/vaapi: can't create image: %s\n"), + vaErrorStr(status)); + return; } } - // FIXME: intel didn't support put image. - if (0 - && vaPutImage(VaDisplay, decoder->BlackSurface, + + status = + vaMapBuffer(VaDisplay, decoder->Image->buf, + (void **)&va_image_data); + if (status != VA_STATUS_SUCCESS) { + Error(_("video/vaapi: can't map the image: %s\n"), + vaErrorStr(status)); + return; + } + + for (u = 0; u < decoder->Image->data_size; ++u) { + if (u < decoder->Image->offsets[1]) { + va_image_data[u] = 0x00; // Y + } else if (u % 2 == 0) { + va_image_data[u] = 0x80; // U + } else { +#ifdef DEBUG + // make black surface visible + va_image_data[u] = 0xFF; // V +#else + va_image_data[u] = 0x80; // V +#endif + } + } + + if (vaUnmapBuffer(VaDisplay, decoder->Image->buf) != VA_STATUS_SUCCESS) { + Error(_("video/vaapi: can't unmap the image!\n")); + } + + if (decoder->GetPutImage) { + status = + vaPutImage(VaDisplay, decoder->BlackSurface, decoder->Image->image_id, 0, 0, VideoWindowWidth, - VideoWindowHeight, 0, 0, VideoWindowWidth, VideoWindowHeight) - != VA_STATUS_SUCCESS) { - Error(_("video/vaapi: can't put image!\n")); + VideoWindowHeight, 0, 0, VideoWindowWidth, VideoWindowHeight); + if (status != VA_STATUS_SUCCESS) { + Error(_("video/vaapi: can't put image!\n")); + } + } else { + // FIXME: PutImage isn't always supported + Debug(3, + "video/vaapi: put image not supported, alternative path not written\n"); } + #ifdef DEBUG start = GetMsTicks(); #endif