Hi,

this is a little more thourough and less ridicolous patch as
alternative for your WIP patch 1. I think this is safer alternative.
There are probably similar frame threading decoding dead locks in other
mpegenccontext based decoders. So your pthread_frame fix is probably
still a good idea.
For release branches I prefer this though.

Janne

---8<---

MpegEncContext based decoders are only fully initialized after the
ff_thread_get_buffer() call. If an decoding error occurs before the
first ff_thread_get_buffer() call the decoder is left in state which
causes dead locks in frame threaded decoding.

CC: [email protected]
---
 libavcodec/rv34.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 0c36348..4dd154c 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1635,22 +1635,24 @@ int ff_rv34_decode_frame(AVCodecContext *avctx,
     }else
         slice_count = avctx->slice_count;
 
+#define ERR_INVALIDDATA(msg)                          \
+    av_log(avctx, AV_LOG_ERROR, msg);                 \
+    if (!s->linesize) s->context_initialized = 0;     \
+    return AVERROR_INVALIDDATA;
+
     //parse first slice header to check whether this frame can be decoded
     if(get_slice_offset(avctx, slices_hdr, 0) < 0 ||
        get_slice_offset(avctx, slices_hdr, 0) > buf_size){
-        av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n");
-        return AVERROR_INVALIDDATA;
+        ERR_INVALIDDATA("Slice offset is invalid\n");
     }
     init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, 0), 
(buf_size-get_slice_offset(avctx, slices_hdr, 0))*8);
     if(r->parse_slice_header(r, &r->s.gb, &si) < 0 || si.start){
-        av_log(avctx, AV_LOG_ERROR, "First slice header is incorrect\n");
-        return AVERROR_INVALIDDATA;
+        ERR_INVALIDDATA("First slice header is incorrect\n");
     }
     if ((!s->last_picture_ptr || !s->last_picture_ptr->f->data[0]) &&
         si.type == AV_PICTURE_TYPE_B) {
-        av_log(avctx, AV_LOG_ERROR, "Invalid decoder state: B-frame without "
-               "reference data.\n");
-        return AVERROR_INVALIDDATA;
+        ERR_INVALIDDATA("Invalid decoder state: B-frame without reference "
+                        "data.\n");
     }
     if(   (avctx->skip_frame >= AVDISCARD_NONREF && si.type==AV_PICTURE_TYPE_B)
        || (avctx->skip_frame >= AVDISCARD_NONKEY && si.type!=AV_PICTURE_TYPE_I)
-- 
2.0.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to