lavc/qsv: skip the packet if decoding failure.

Message ID 1516611181-14636-1-git-send-email-ruiling.song@intel.com
State New
Headers show
Series
  • lavc/qsv: skip the packet if decoding failure.
Related show

Commit Message

Ruiling Song Jan. 22, 2018, 8:53 a.m.
MediaSDK may fail to decode some frame, just skip it.
Otherwise, it will keep decoding the failure packet repeatedly
without processing any packet afterwards.

Signed-off-by: Ruiling, Song <ruiling.song@intel.com>
---
 libavcodec/qsvdec_h2645.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Ruiling Song Jan. 24, 2018, 2:08 a.m. | #1
> -----Original Message-----
> From: libav-devel [mailto:libav-devel-bounces@libav.org] On Behalf Of Maxym
> Dmytrychenko
> Sent: Monday, January 22, 2018 6:43 PM
> To: libav development <libav-devel@libav.org>
> Cc: Ruiling@oboro.libav.org
> Subject: Re: [libav-devel] [PATCH] lavc/qsv: skip the packet if decoding failure.
> 
> would be av_packet_unref() more appropriate ?
Thanks for your comment. In fact, I am not sure on this, may be av_packet_unref() a little bit more clear?
I think they are functionally almost the same for this case. If I am wrong, please correct me.
But I am ok on using av_packet_unref() instead of "forcing size to zero and unref it next-time the function was called".
I will send a new version very soon.

Ruiling

> 
> On Mon, Jan 22, 2018 at 9:53 AM, Ruiling, Song <ruiling.song@intel.com>
> wrote:
> 
> > MediaSDK may fail to decode some frame, just skip it.
> > Otherwise, it will keep decoding the failure packet repeatedly
> > without processing any packet afterwards.
> >
> > Signed-off-by: Ruiling, Song <ruiling.song@intel.com>
> > ---
> >  libavcodec/qsvdec_h2645.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
> > index 83880dc..aa8746d 100644
> > --- a/libavcodec/qsvdec_h2645.c
> > +++ b/libavcodec/qsvdec_h2645.c
> > @@ -153,8 +153,12 @@ static int qsv_decode_frame(AVCodecContext *avctx,
> > void *data,
> >          }
> >
> >          ret = ff_qsv_process_data(avctx, &s->qsv, frame, got_frame,
> > &s->buffer_pkt);
> > -        if (ret < 0)
> > -            return ret;
> > +        if (ret < 0){
> > +             /* force the buffer_pkt's size to 0 when failed to decode
> > the packet,
> > +                otherwise, the decoder will keep decoding the failure
> > packet. */
> > +             s->buffer_pkt.size = 0;
> > +             return ret;
> > +        }
> >
> >          s->buffer_pkt.size -= ret;
> >          s->buffer_pkt.data += ret;
> > --
> > 2.7.4
> >
> > _______________________________________________
> > libav-devel mailing list
> > libav-devel@libav.org
> > https://lists.libav.org/mailman/listinfo/libav-devel
> _______________________________________________
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel

Patch

diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
index 83880dc..aa8746d 100644
--- a/libavcodec/qsvdec_h2645.c
+++ b/libavcodec/qsvdec_h2645.c
@@ -153,8 +153,12 @@  static int qsv_decode_frame(AVCodecContext *avctx, void *data,
         }
 
         ret = ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt);
-        if (ret < 0)
-            return ret;
+        if (ret < 0){
+             /* force the buffer_pkt's size to 0 when failed to decode the packet,
+                otherwise, the decoder will keep decoding the failure packet. */
+             s->buffer_pkt.size = 0;
+             return ret;
+        }
 
         s->buffer_pkt.size -= ret;
         s->buffer_pkt.data += ret;