vlc | branch: master | Steve Lhomme <rob...@videolabs.io> | Mon Nov 20 14:42:10 
2017 +0100| [300800f9673dc556cebacffcf0d55677e164f89e] | committer: Steve Lhomme

qsv: clean the picture enqueuing code

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=300800f9673dc556cebacffcf0d55677e164f89e
---

 modules/codec/qsv.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/modules/codec/qsv.c b/modules/codec/qsv.c
index 6808e578f7..0226c3a1d3 100644
--- a/modules/codec/qsv.c
+++ b/modules/codec/qsv.c
@@ -753,12 +753,14 @@ static block_t *qsv_synchronize_block(encoder_t *enc, 
async_task_t *task)
     return block;
 }
 
-static void qsv_queue_encode_picture(encoder_t *enc, async_task_t *task,
-                                     picture_t *pic)
+static void qsv_queue_encode_picture(encoder_t *enc, picture_t *pic)
 {
     encoder_sys_t *sys = enc->p_sys;
     mfxStatus sts;
     mfxFrameSurface1 *frame = NULL;
+    async_task_t *task = calloc(1, sizeof(*task));
+    if (unlikely(task == NULL))
+        return;
 
     if (!(task->syncp = calloc(1, sizeof(*task->syncp)))) {
         msg_Err(enc, "Unable to allocate syncpoint for encoder output");
@@ -792,6 +794,15 @@ static void qsv_queue_encode_picture(encoder_t *enc, 
async_task_t *task,
     task->bs.MaxLength = task->block->i_buffer;
     task->bs.Data = task->block->p_buffer;
 
+    if (!(task->syncp = calloc(1, sizeof(*task->syncp)))) {
+        msg_Err(enc, "Unable to allocate syncpoint for encoder output");
+        goto done;
+    }
+
+    if (qsv_frame) {
+        surf = &qsv_frame->surface;
+    }
+
     for (;;) {
         sts = MFXVideoENCODE_EncodeFrameAsync(sys->session, 0, frame, 
&task->bs, task->syncp);
         if (sts != MFX_WRN_DEVICE_BUSY && sts != MFX_WRN_IN_EXECUTION)
@@ -828,22 +839,18 @@ static block_t *Encode(encoder_t *this, picture_t *pic)
 {
     encoder_t     *enc = (encoder_t *)this;
     encoder_sys_t *sys = enc->p_sys;
-    async_task_t  *task = NULL;
     block_t       *block = NULL;
 
-    task = calloc(1, sizeof(*task));
-    if (likely(task != NULL))
+    qsv_queue_encode_picture( enc, pic );
+
+    if ( async_task_t_fifo_GetCount(&sys->packets) == sys->async_depth ||
+         (!pic && async_task_t_fifo_GetCount(&sys->packets)))
     {
-        qsv_queue_encode_picture( enc, task, pic );
-
-        if ( async_task_t_fifo_GetCount(&sys->packets) == sys->async_depth ||
-             (!pic && async_task_t_fifo_GetCount(&sys->packets)))
-        {
-            assert(async_task_t_fifo_Show(&sys->packets)->syncp != 0);
-            task = async_task_t_fifo_Get(&sys->packets);
-            block = qsv_synchronize_block( enc, task );
-            free(task);
-        }
+        assert(async_task_t_fifo_Show(&sys->packets)->syncp != 0);
+        async_task_t *task = async_task_t_fifo_Get(&sys->packets);
+        block = qsv_synchronize_block( enc, task );
+        free(task->syncp);
+        free(task);
     }
 
     return block;

_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to