}
for ( ;; ) { // Termination condition within loop.
- AVPacket pkt;
- av_init_packet(&pkt);
- pkt.data = nullptr;
- pkt.size = 0;
- int err = avcodec_receive_packet(ctx, &pkt);
+ AVPacketWithDeleter pkt = av_packet_alloc_unique();
+ pkt->data = nullptr;
+ pkt->size = 0;
+ int err = avcodec_receive_packet(ctx, pkt.get());
if (err == 0) {
- pkt.stream_index = 1;
- pkt.flags = 0;
+ pkt->stream_index = 1;
+ pkt->flags = 0;
for (Mux *mux : muxes) {
- mux->add_packet(pkt, pkt.pts, pkt.dts);
+ mux->add_packet(*pkt, pkt->pts, pkt->dts);
}
- av_packet_unref(&pkt);
} else if (err == AVERROR(EAGAIN)) {
break;
} else {
if (ctx->codec->capabilities & AV_CODEC_CAP_DELAY) {
// Collect any delayed frames.
for ( ;; ) {
- AVPacket pkt;
- av_init_packet(&pkt);
- pkt.data = nullptr;
- pkt.size = 0;
- int err = avcodec_receive_packet(ctx, &pkt);
+ AVPacketWithDeleter pkt = av_packet_alloc_unique();
+ pkt->data = nullptr;
+ pkt->size = 0;
+ int err = avcodec_receive_packet(ctx, pkt.get());
if (err == 0) {
- pkt.stream_index = 1;
- pkt.flags = 0;
+ pkt->stream_index = 1;
+ pkt->flags = 0;
for (Mux *mux : muxes) {
- mux->add_packet(pkt, pkt.pts, pkt.dts);
+ mux->add_packet(*pkt, pkt->pts, pkt->dts);
}
- av_packet_unref(&pkt);
} else if (err == AVERROR_EOF) {
break;
} else {