[FFmpeg-devel] lavc/samidec: don't error on empty packets

Submitted by Rodger Combs on Dec. 1, 2018, 3:10 a.m.

Details

Message ID 20181201031006.94174-1-rodger.combs@gmail.com
State New
Headers show

Commit Message

Rodger Combs Dec. 1, 2018, 3:10 a.m.
No change to output; just prevents error spam
---
 libavcodec/samidec.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavcodec/samidec.c b/libavcodec/samidec.c
index e32f238c62..7ea67b5597 100644
--- a/libavcodec/samidec.c
+++ b/libavcodec/samidec.c
@@ -38,6 +38,7 @@  typedef struct {
     int readorder;
 } SAMIContext;
 
+// Returns 1 if valid content was decoded; 0 if none; <0 if error
 static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
 {
     SAMIContext *sami = avctx->priv_data;
@@ -84,7 +85,7 @@  static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
         while (av_isspace(*p))
             p++;
         if (!strncmp(p, "&nbsp;", 6)) {
-            ret = -1;
+            ret = 0;
             goto end;
         }
 
@@ -126,6 +127,8 @@  static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
         goto end;
     av_bprintf(&sami->full, "%s", sami->encoded_content.str);
 
+    ret = 1;
+
 end:
     av_free(dupsrc);
     return ret;
@@ -142,10 +145,12 @@  static int sami_decode_frame(AVCodecContext *avctx,
         int ret = sami_paragraph_to_ass(avctx, ptr);
         if (ret < 0)
             return ret;
-        // TODO: pass escaped sami->encoded_source.str as source
-        ret = ff_ass_add_rect(sub, sami->full.str, sami->readorder++, 0, NULL, NULL);
-        if (ret < 0)
-            return ret;
+        if (ret > 0) {
+            // TODO: pass escaped sami->encoded_source.str as source
+            ret = ff_ass_add_rect(sub, sami->full.str, sami->readorder++, 0, NULL, NULL);
+            if (ret < 0)
+                return ret;
+        }
     }
     *got_sub_ptr = sub->num_rects > 0;
     return avpkt->size;