commit 4152b910ddd8edb11f6b47406340d5c2c698788d
Author: Guangxin.Xu <Guangxin.Xu@intel.com>
Date:   Tue Jul 30 14:05:39 2013 +0800

    send last frame from output adapter to decoder
    
    Signed-off-by: Guangxin.Xu <Guangxin.Xu@intel.com>

diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c
index e91bbdd..6811fae 100644
--- a/gst/vaapi/gstvaapidecode.c
+++ b/gst/vaapi/gstvaapidecode.c
@@ -408,6 +408,10 @@ gst_vaapidecode_finish(GstVideoDecoder *vdec)
     GstVaapiDecode * const decode = GST_VAAPIDECODE(vdec);
     GstVaapiDecoderStatus status;
 
+    /* if there are something in GstVideoDecoder's output adapter, send them to decoder*/
+    if (decode->bytes_added_to_frame)
+        gst_video_decoder_have_frame(vdec);
+
     status = gst_vaapi_decoder_flush(decode->decoder);
     if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
         goto error_flush;
@@ -590,6 +594,9 @@ gst_vaapidecode_reset_full(GstVaapiDecode *decode, GstCaps *caps, gboolean hard)
         if (codec == gst_vaapi_decoder_get_codec(decode->decoder))
             return TRUE;
     }
+    /* reset output adapter bytes counter*/
+    decode->bytes_added_to_frame = 0;
+
 
     gst_vaapidecode_destroy(decode);
     return gst_vaapidecode_create(decode, caps);
@@ -678,10 +685,14 @@ gst_vaapidecode_parse(GstVideoDecoder *vdec,
 
     switch (status) {
     case GST_VAAPI_DECODER_STATUS_SUCCESS:
-        if (got_unit_size > 0)
+        if (got_unit_size > 0) {
             gst_video_decoder_add_to_frame(vdec, got_unit_size);
-        if (got_frame)
+            decode->bytes_added_to_frame += got_unit_size;
+        }
+        if (got_frame) {
             ret = gst_video_decoder_have_frame(vdec);
+            decode->bytes_added_to_frame = 0;
+        }
         else
             ret = GST_FLOW_OK;
         break;
@@ -863,6 +874,7 @@ gst_vaapidecode_init(GstVaapiDecode *decode)
     decode->allowed_caps        = NULL;
     decode->render_time_base    = 0;
     decode->last_buffer_time    = 0;
+    decode->bytes_added_to_frame = 0;
 
     g_mutex_init(&decode->decoder_mutex);
     g_cond_init(&decode->decoder_ready);
diff --git a/gst/vaapi/gstvaapidecode.h b/gst/vaapi/gstvaapidecode.h
index 05b7769..0d8a261 100644
--- a/gst/vaapi/gstvaapidecode.h
+++ b/gst/vaapi/gstvaapidecode.h
@@ -76,6 +76,7 @@ struct _GstVaapiDecode {
     GstCaps            *allowed_caps;
     gint64              render_time_base;
     GstClockTime        last_buffer_time;
+    gint                bytes_added_to_frame;
 };
 
 struct _GstVaapiDecodeClass {
