]> granicus.if.org Git - handbrake/commitdiff
RB 502/partial clip transcode fix
authorhandbrake <no-reply@handbrake.fr>
Mon, 20 May 2013 20:32:49 +0000 (20:32 +0000)
committerhandbrake <no-reply@handbrake.fr>
Mon, 20 May 2013 20:32:49 +0000 (20:32 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/qsv@5492 b64f7644-9d1e-0410-96f1-a4d463321fa5

contrib/ffmpeg/A00-qsv.patch
libhb/enc_qsv.c
libhb/qsv_filter.c
libhb/sync.c

index b2ddca6fbb3389dc430e5d2a5e32cf4b2b6e5837..391205d6b00c303d3249ab41edaa4d62d4814289 100755 (executable)
@@ -78,8 +78,8 @@ diff -Naur ../../libav-v9.3/libavcodec/Makefile ./libavcodec/Makefile
  OBJS-$(CONFIG_H264_VDA_HWACCEL)        += vda_h264.o
 diff -Naur ../../libav-v9.3/libavcodec/qsv.c ./libavcodec/qsv.c
 --- ../../libav-v9.3/libavcodec/qsv.c  1970-01-01 01:00:00.000000000 +0100
-+++ ./libavcodec/qsv.c 2013-05-15 17:13:43.317341393 +0200
-@@ -0,0 +1,621 @@
++++ ./libavcodec/qsv.c 2013-05-19 14:46:43.248504511 +0200
+@@ -0,0 +1,645 @@
 +/* ********************************************************************* *\
 +
 +Copyright (C) 2013 Intel Corporation.  All rights reserved.
@@ -256,6 +256,7 @@ diff -Naur ../../libav-v9.3/libavcodec/qsv.c ./libavcodec/qsv.c
 +{
 +    if ((*stage)->out.sync) {
 +        *(*stage)->out.sync->p_sync = 0;
++        if( (*stage)->out.sync->in_use > 0 )
 +        ff_qsv_atomic_dec(&(*stage)->out.sync->in_use);
 +        (*stage)->out.sync = 0;
 +    }
@@ -701,10 +702,34 @@ diff -Naur ../../libav-v9.3/libavcodec/qsv.c ./libavcodec/qsv.c
 +        MFXClose(mfx_session);
 +    return sts;
 +}
++
++void av_qsv_wait_on_sync(av_qsv_context *qsv, av_qsv_stage *stage)
++{
++    int iter = 0;
++    mfxStatus sts = MFX_ERR_NONE;
++    if( stage )
++        if(*stage->out.sync->p_sync){
++            while(1){
++                iter++;
++                sts = MFXVideoCORE_SyncOperation(qsv->mfx_session,*stage->out.sync->p_sync, AV_QSV_SYNC_TIME_DEFAULT);
++                if(MFX_WRN_IN_EXECUTION == sts){
++
++                    if(iter>20)
++                        AV_QSV_DEBUG_ASSERT(1, "Sync failed");
++
++                    av_qsv_sleep(10);
++                    continue;
++                }
++                AV_QSV_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
++                break;
++            }
++        }
++}
+\ No newline at end of file
 diff -Naur ../../libav-v9.3/libavcodec/qsv.h ./libavcodec/qsv.h
 --- ../../libav-v9.3/libavcodec/qsv.h  1970-01-01 01:00:00.000000000 +0100
-+++ ./libavcodec/qsv.h 2013-05-15 17:13:43.321341889 +0200
-@@ -0,0 +1,493 @@
++++ ./libavcodec/qsv.h 2013-05-19 14:46:43.249504634 +0200
+@@ -0,0 +1,494 @@
 +/* ********************************************************************* *\
 +
 +Copyright (C) 2013 Intel Corporation.  All rights reserved.
@@ -1163,6 +1188,7 @@ diff -Naur ../../libav-v9.3/libavcodec/qsv.h ./libavcodec/qsv.h
 +int av_qsv_get_free_encode_task(av_qsv_list *);
 +
 +int av_is_qsv_available(mfxIMPL, mfxVersion *);
++void av_qsv_wait_on_sync(av_qsv_context *, av_qsv_stage *);
 +
 +void av_qsv_add_context_usage(av_qsv_context *, int);
 +
@@ -1200,7 +1226,7 @@ diff -Naur ../../libav-v9.3/libavcodec/qsv.h ./libavcodec/qsv.h
 +#endif                          //AVCODEC_QSV_H
 diff -Naur ../../libav-v9.3/libavcodec/qsv_h264.c ./libavcodec/qsv_h264.c
 --- ../../libav-v9.3/libavcodec/qsv_h264.c     1970-01-01 01:00:00.000000000 +0100
-+++ ./libavcodec/qsv_h264.c    2013-05-15 17:13:43.320341765 +0200
++++ ./libavcodec/qsv_h264.c    2013-05-19 14:46:43.248504511 +0200
 @@ -0,0 +1,959 @@
 +/* ********************************************************************* *\
 +
@@ -2163,7 +2189,7 @@ diff -Naur ../../libav-v9.3/libavcodec/qsv_h264.c ./libavcodec/qsv_h264.c
 +};
 diff -Naur ../../libav-v9.3/libavcodec/qsv_h264.h ./libavcodec/qsv_h264.h
 --- ../../libav-v9.3/libavcodec/qsv_h264.h     1970-01-01 01:00:00.000000000 +0100
-+++ ./libavcodec/qsv_h264.h    2013-05-15 17:13:43.335343623 +0200
++++ ./libavcodec/qsv_h264.h    2013-05-19 14:46:43.261506110 +0200
 @@ -0,0 +1,64 @@
 +/* ********************************************************************* *\
 +
index 327256ce08dc43d85839205b1e42a975532f998e..8aa7d5069153553515a6e4748d8737bba1f0452f 100644 (file)
@@ -865,23 +865,7 @@ int encqsvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
 
         // only here we need to wait on operation been completed, therefore SyncOperation is used,
         // after this step - we continue to work with bitstream, muxing ...
-        if(*stage->out.sync->p_sync){
-            int iter = 0;
-            while(1){
-                iter++;
-                sts = MFXVideoCORE_SyncOperation(qsv->mfx_session,*stage->out.sync->p_sync, AV_QSV_SYNC_TIME_DEFAULT); // Synchronize. Wait until frame processing is ready, also care about MFX_WRN_IN_EXECUTION
-                if(MFX_WRN_IN_EXECUTION == sts){
-
-                    //normally, should be here
-                    if(iter>20)
-                        DEBUG_ASSERT(1, "Sync failed within encode.");
-
-                    av_qsv_sleep(10);
-                    continue;
-                }
-                AV_QSV_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
-                break;
-            }
+        av_qsv_wait_on_sync( qsv,stage );
 
         if(task->bs->DataLength>0){
                 av_qsv_flush_stages( qsv->pipes, &this_pipe );
@@ -943,7 +927,6 @@ int encqsvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
                 pv->frames_out++;
             }
         }
-    }
     }while(is_end);
 
 
index 7b294ddd6356e5f39a891a35571562ff43a65a1c..299f698fdffb5014b2ed5cfa9cf124ba22d56132 100644 (file)
@@ -605,24 +605,8 @@ static int hb_qsv_filter_work( hb_filter_object_t * filter,
                     av_qsv_stage* stage = av_qsv_get_last_stage( out->qsv_details.qsv_atom );
                     mfxFrameSurface1 *work_surface = stage->out.p_surface;
 
-                    if(stage->out.sync && *stage->out.sync->p_sync){
-                        int iter = 0;
-                        while(1){
-                            iter++;
-                            sts = MFXVideoCORE_SyncOperation(qsv->mfx_session,*stage->out.sync->p_sync, AV_QSV_SYNC_TIME_DEFAULT);
-                            if(MFX_WRN_IN_EXECUTION == sts){
-
-                                //normally, should be here
-                                if(iter>20)
-                                    DEBUG_ASSERT(1, "Sync failed within encode.");
-
-                                av_qsv_sleep(10);
-                                continue;
-                            }
-                            AV_QSV_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
-                            break;
-                        }
-                    }
+                    av_qsv_wait_on_sync( qsv,stage );
+
                     av_qsv_space *qsv_vpp = pv->vpp_space;
                     int64_t duration  = ((double)qsv_vpp->m_mfxVideoParam.vpp.Out.FrameRateExtD/(double)qsv_vpp->m_mfxVideoParam.vpp.Out.FrameRateExtN ) * 90000.;
                     out->s.start = work_surface->Data.TimeStamp;
index 3e88c40e5279d6ae30507c18c30f330014ebf0e5..09524830390a0f5e947ca63f7404c87c0e14209f 100644 (file)
@@ -343,6 +343,29 @@ int syncVideoWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
             hb_unlock( pv->common->mutex );
 
             UpdateSearchState( w, next_start );
+
+            // as we drop prepared decode, we need to reclaim resources
+            if( job && job->vcodec == HB_VCODEC_QSV_H264 && job->qsv )
+            {
+                hb_buffer_t *buf = next;
+                av_qsv_list* received_item = buf->qsv_details.qsv_atom;
+                av_qsv_context *qsv = job->qsv;
+
+                if( received_item && qsv )
+                {
+                    av_qsv_stage *stage = av_qsv_get_last_stage(received_item);
+                    if( stage )
+                    {
+                        av_qsv_wait_on_sync( qsv,stage );
+
+                        if( stage->out.sync->in_use > 0 )
+                            ff_qsv_atomic_dec(&stage->out.sync->in_use);
+                        if( stage->out.p_surface->Data.Locked > 0 )
+                            ff_qsv_atomic_dec(&stage->out.p_surface->Data.Locked);
+                    }
+                    av_qsv_flush_stages( qsv->pipes, &received_item );
+                }
+            }
             hb_buffer_close( &next );
 
             return HB_WORK_OK;