shithub: treason

Download patch

ref: dd0fde6262de2b1be2d49a6414c99e203d2a21b8
parent: a005abe2701b878770544e2e09f41ab9e2a399e7
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Dec 16 05:23:46 EST 2020

h264: better error reporting, move reorder reset into a function

--- a/decoder_h264.c
+++ b/decoder_h264.c
@@ -1,4 +1,5 @@
 #include <decoder/core/inc/decoder.h>
+#include <decoder/core/inc/manage_dec_ref.h>
 #include <thread.h>
 #include "frame.h"
 #include "stream.h"
@@ -22,7 +23,6 @@
 	SPictInfo pics[16];
 	int npics;
 	int lastgopremain;
-	int lastbuffered;
 	int lastwritten;
 	int lbufpicind;
 	int minpoc;
@@ -71,7 +71,6 @@
 			a->pics[i].uiDecodingTimeStamp = ts;
 			a->ctx.pLastDecPicInfo->pPreviousDecodedPictureInDpb->iRefCount++;
 			a->pics[i].bLastGOP = false;
-			a->lastbuffered = i;
 			a->info.iBufferStatus = 0;
 			a->npics++;
 			if(i > a->lbufpicind)
@@ -155,6 +154,48 @@
 }
 
 static void
+resetreorder(Aux *a, int full)
+{
+	int i;
+
+	a->npics = 0;
+	a->lastgopremain = 0;
+	a->lastwritten = IMinInt32;
+	a->minpoc = IMinInt32;
+	a->picind = 0;
+	for(i = 0; i < (full ? nelem(a->pics) : (a->lbufpicind+1)); i++){
+		a->pics[i].bLastGOP = false;
+		a->pics[i].iPOC = IMinInt32;
+	}
+	a->lbufpicind = 0;
+}
+
+static char *
+err2s(int err)
+{
+	static char t[256];
+	char *s, *e;
+
+	t[0] = t[1] = 0;
+	s = t;
+	e = t+sizeof(t);
+	if(err & dsFramePending)       s = seprint(s, e, "|FramePending");
+	if(err & dsRefLost)            s = seprint(s, e, "|RefLost");
+	if(err & dsBitstreamError)     s = seprint(s, e, "|BitstreamError");
+	if(err & dsDepLayerLost)       s = seprint(s, e, "|DepLayerLost");
+	if(err & dsNoParamSets)        s = seprint(s, e, "|NoParamSets");
+	if(err & dsDataErrorConcealed) s = seprint(s, e, "|DataErrorConcealed");
+	if(err & dsRefListNullPtrs)    s = seprint(s, e, "|RefListNullPtrs");
+	if(err & dsInvalidArgument)    s = seprint(s, e, "|InvalidArgument");
+	if(err & dsInitialOptExpected) s = seprint(s, e, "|InitialOptExpected");
+	if(err & dsOutOfMemory)        s = seprint(s, e, "|OutOfMemory");
+	if(err & dsDstBufNeedExpan)    s = seprint(s, e, "|DstBufNeedExpan");
+	USED(s);
+
+	return t+1;
+}
+
+static void
 decode(void *x)
 {
 	uvlong lasttimestamp;
@@ -172,7 +213,7 @@
 	start = nanosec();
 	for(res = 0, framenum = 0; res >= 0 && (res = Sread(d->s, &sf)) == 0 && sf.sz > 0; framenum++){
 		if((res = WelsDecodeBs(&a->ctx, sf.buf, sf.sz, a->data, &a->info, nil)) != 0){
-			werrstr("frame %llud: decoder error %#x", framenum, res);
+			werrstr("%s on frame %llud", err2s(res), framenum);
 			break;
 		}
 		if(a->info.iBufferStatus == 0)
@@ -213,6 +254,8 @@
 		fprint(2, "h264: %r\n");
 
 	/* FIXME the frames are finished but there might still be left-overs */
+	resetreorder(a, 0);
+	WelsResetRefPic(&a->ctx);
 
 done:
 	WelsEndDecoder(&a->ctx);
@@ -228,7 +271,7 @@
 h264open(Decoder *d)
 {
 	Aux *a;
-	int res, i;
+	int res;
 
 	a = calloc(1, sizeof(*a));
 	a->ctx.pLastDecPicInfo = &a->pic;
@@ -241,13 +284,10 @@
 	a->ctx.pParam = calloc(1, sizeof(SDecodingParam));
 	a->ctx.pParam->sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
 
-    a->minpoc = IMinInt32;
-    a->lastwritten = IMinInt32;
-    for(i = 0; i < nelem(a->pics); i++)
-      a->pics[i].iPOC = IMinInt32;
+	resetreorder(a, 1);
 
 	if((res = WelsInitDecoder(&a->ctx, &a->logctx)) != 0){
-		werrstr("WelsInitDecoder: %d", res);
+		werrstr("WelsInitDecoder: %s", err2s(res));
 		free(a);
 		return -1;
 	}