From bb8894aaf934b3af4d44cf54e860510fe4d615b3 Mon Sep 17 00:00:00 2001
From: Tianhao Liu <tianhao.liu@intel.com>
Date: Thu, 7 Jun 2018 09:34:11 +0800
Subject: [PATCH] libs: decoder: release VA buffers after vaEndPicture

This change is due a problem decoding JPEGs with Intel's media-driver:
no image was generated.

This patch relases the VA buffers after vaEndPicture() is called,
and not before (after vaRenderPicture()).

https://bugzilla.gnome.org/show_bug.cgi?id=796505

Upstream-Status: Backport [https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/commit/bb8894aaf934b3af4d44cf54e860510fe4d615b3]
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
---
 gst-libs/gst/vaapi/gstvaapidecoder_objects.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_objects.c b/gst-libs/gst/vaapi/gstvaapidecoder_objects.c
index 20d4f55..2dd4c27 100644
--- a/gst-libs/gst/vaapi/gstvaapidecoder_objects.c
+++ b/gst-libs/gst/vaapi/gstvaapidecoder_objects.c
@@ -304,12 +304,17 @@ gst_vaapi_picture_decode (GstVaapiPicture * picture)
     status = vaRenderPicture (va_display, va_context, va_buffers, 2);
     if (!vaapi_check_status (status, "vaRenderPicture()"))
       return FALSE;
+  }
+
+  status = vaEndPicture (va_display, va_context);
+
+  for (i = 0; i < picture->slices->len; i++) {
+    GstVaapiSlice *const slice = g_ptr_array_index (picture->slices, i);
 
     vaapi_destroy_buffer (va_display, &slice->param_id);
     vaapi_destroy_buffer (va_display, &slice->data_id);
   }
 
-  status = vaEndPicture (va_display, va_context);
   if (!vaapi_check_status (status, "vaEndPicture()"))
     return FALSE;
   return TRUE;
-- 
2.7.4

