ref: 7996b424b3ec858adcf6507c424bc5e06773e3fa
parent: 721b071f9ec209ead60c7c0ddf993e6e495f8b24
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Feb 22 10:53:08 EST 2021
ivf/h264: repeat sps/pps on every key frame
--- a/ivf.c
+++ b/ivf.c
@@ -38,11 +38,11 @@
}
}
- return Bwrite(out, p, sz) != sz ? -1 : 0;
+ return sz > 0 ? (Bwrite(out, p, sz) != sz ? -1 : 0) : 0;
}
int
-ivfpacket(Biobuf *out, Packetctx *ctx, Packet *p, int np, uvlong ts)
+ivfpacket(Biobuf *out, Packetctx *ctx, Packet *p, int np, uvlong ts, int key)
{
u8int d[0x20], *x, *y, *e;
int i, n, len;
@@ -127,9 +127,10 @@
werrstr("sps out of range");
goto err;
}
- memmove(x+4, y, len);
- if(ivfframe(out, x, 4+len, 0, 0) != 0)
- goto err;
+ ctx->ps[ctx->nps].p = malloc(4+len);
+ memmove(ctx->ps[ctx->nps].p, x, 4);
+ memmove(ctx->ps[ctx->nps].p+4, y, len);
+ ctx->ps[ctx->nps++].n = 4+len;
ctx->frid++;
y += len;
}
@@ -142,9 +143,10 @@
werrstr("pps out of range");
goto err;
}
- memmove(x+4, y, len);
- if(ivfframe(out, x, 4+len, 0, 0) != 0)
- goto err;
+ ctx->ps[ctx->nps].p = malloc(4+len);
+ memmove(ctx->ps[ctx->nps].p, x, 4);
+ memmove(ctx->ps[ctx->nps].p+4, y, len);
+ ctx->ps[ctx->nps++].n = 4+len;
ctx->frid++;
y += len;
}
@@ -151,6 +153,10 @@
}
}
+ if(key && ctx->fmt == FmtAvc1){
+ for(i = 0; i < ctx->nps; i++)
+ ivfframe(out, ctx->ps[i].p, ctx->ps[i].n, 0, 0);
+ }
if(ivfframe(out, p->data, p->sz, ts, ctx->fmt == FmtAvc1) != 0)
goto err;
ctx->frid++;