[3/3,WIP] pthread_frame: fix rv40 threaded decode of clip starting with a bframe

Message ID 1407964439-21283-4-git-send-email-stebbins@jetheaddev.com
State New
Headers show

Commit Message

John Stebbins Aug. 13, 2014, 9:13 p.m.
Finish setting thread state, even if there is an error returned by
update_context_from_thread.
---
 libavcodec/pthread_frame.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

Comments

Luca Barbato Aug. 13, 2014, 10:55 p.m. | #1
On 13/08/14 23:13, John Stebbins wrote:
> Finish setting thread state, even if there is an error returned by
> update_context_from_thread.
> ---
>  libavcodec/pthread_frame.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 

Seems the best solution but I hadn't looked at the setup code so it is a
seems.

lu
John Stebbins Aug. 15, 2014, 3:11 p.m. | #2
On 08/13/2014 03:55 PM, Luca Barbato wrote:
> On 13/08/14 23:13, John Stebbins wrote:
>> Finish setting thread state, even if there is an error returned by
>> update_context_from_thread.
>> ---
>>  libavcodec/pthread_frame.c | 11 +++--------
>>  1 file changed, 3 insertions(+), 8 deletions(-)
>>
> Seems the best solution but I hadn't looked at the setup code so it is a
> seems.
>
> lu
>

Are there any other opinions about these alternatives to fix this rv40 issue?  The pthread_frame patch is also my
favorite and was the first solution I came up with.  It seems to fix a more general problem with the thread state.

Patch

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index a658f3e..c3846bb 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -298,6 +298,7 @@  static int submit_packet(PerThreadContext *p, AVPacket *avpkt)
     FrameThreadContext *fctx = p->parent;
     PerThreadContext *prev_thread = fctx->prev_thread;
     const AVCodec *codec = p->avctx->codec;
+    int err = 0;
 
     if (!avpkt->size && !(codec->capabilities & CODEC_CAP_DELAY)) return 0;
 
@@ -306,7 +307,6 @@  static int submit_packet(PerThreadContext *p, AVPacket *avpkt)
     release_delayed_buffers(p);
 
     if (prev_thread) {
-        int err;
         if (prev_thread->state == STATE_SETTING_UP) {
             pthread_mutex_lock(&prev_thread->progress_mutex);
             while (prev_thread->state == STATE_SETTING_UP)
@@ -315,10 +315,6 @@  static int submit_packet(PerThreadContext *p, AVPacket *avpkt)
         }
 
         err = update_context_from_thread(p->avctx, prev_thread->avctx, 0);
-        if (err) {
-            pthread_mutex_unlock(&p->mutex);
-            return err;
-        }
     }
 
     av_packet_unref(&p->avpkt);
@@ -358,7 +354,7 @@  FF_ENABLE_DEPRECATION_WARNINGS
     fctx->prev_thread = p;
     fctx->next_decoding++;
 
-    return 0;
+    return err;
 }
 
 int ff_thread_decode_frame(AVCodecContext *avctx,
@@ -374,6 +370,7 @@  int ff_thread_decode_frame(AVCodecContext *avctx,
      * Submit a packet to the next decoding thread.
      */
 
+    if (fctx->next_decoding >= avctx->thread_count) fctx->next_decoding = 0;
     p = &fctx->threads[fctx->next_decoding];
     err = update_context_from_user(p->avctx, avctx);
     if (err) return err;
@@ -426,8 +423,6 @@  int ff_thread_decode_frame(AVCodecContext *avctx,
 
     update_context_from_thread(avctx, p->avctx, 1);
 
-    if (fctx->next_decoding >= avctx->thread_count) fctx->next_decoding = 0;
-
     fctx->next_finished = finished;
 
     /* return the size of the consumed packet if no error occurred */