summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2018-07-26 17:37:34 +0200
committerJan Ekström <jeebjp@gmail.com>2018-10-01 20:20:25 +0300
commit6d61c5f68a5b1faaaf5a38080c690e35bd31858c (patch)
tree605a525d17bcf83bd2519916de66602f573738ae
parent9f6147a56f85533d7ba09e529356197136d43b19 (diff)
downloadmpv-6d61c5f68a5b1faaaf5a38080c690e35bd31858c.tar.bz2
mpv-6d61c5f68a5b1faaaf5a38080c690e35bd31858c.tar.xz
encode: fix AVPacket deinitialization logic
Since this function is called with packets on the stack, trying to free them makes no sense. Instead, it should unref (which is what `av_interleaved_write_frame` does anyway, rather than freeing). Also, the calling code tried unreffing the packet a second time, even after it was "freed" by the callee in the failure case - and after ownership was taken over by `av_interleaved_write_frame` in the successful case. Both of these cases were wrong.
-rw-r--r--common/encode_lavc.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/common/encode_lavc.c b/common/encode_lavc.c
index d8e875c58f..7cf18750cc 100644
--- a/common/encode_lavc.c
+++ b/common/encode_lavc.c
@@ -436,7 +436,7 @@ done:
return dst;
}
-// Write a packet. Callee will create new pkt refs as needed.
+// Write a packet. This will take over ownership of `pkt`
static void encode_lavc_add_packet(struct mux_stream *dst, AVPacket *pkt)
{
struct encode_lavc_context *ctx = dst->ctx;
@@ -476,6 +476,7 @@ static void encode_lavc_add_packet(struct mux_stream *dst, AVPacket *pkt)
if (av_interleaved_write_frame(p->muxer, pkt) < 0) {
MP_ERR(p, "Writing packet failed.\n");
p->failed = true;
+ pkt = NULL;
goto done;
}
@@ -483,7 +484,8 @@ static void encode_lavc_add_packet(struct mux_stream *dst, AVPacket *pkt)
done:
pthread_mutex_unlock(&ctx->lock);
- av_packet_free(&pkt);
+ if (pkt)
+ av_packet_unref(pkt);
}
void encode_lavc_discontinuity(struct encode_lavc_context *ctx)
@@ -949,7 +951,6 @@ bool encoder_encode(struct encoder_context *p, AVFrame *frame)
break;
encode_lavc_add_packet(p->mux_stream, &packet);
- av_packet_unref(&packet);
}
return true;