X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Faudio_encoder.cpp;fp=nageru%2Faudio_encoder.cpp;h=e683265c67f17485937fd4d7393538825f0649cc;hb=2f92c975a3cf9f4803a58267fd2a12765e34a69e;hp=126e0e2dce19ef40f0406bea7a3d4abed120c731;hpb=79da5a221c1109e6ae536b68c5bfc2dfb4ee725b;p=nageru diff --git a/nageru/audio_encoder.cpp b/nageru/audio_encoder.cpp index 126e0e2..e683265 100644 --- a/nageru/audio_encoder.cpp +++ b/nageru/audio_encoder.cpp @@ -135,18 +135,16 @@ void AudioEncoder::encode_audio_one_frame(const float *audio, size_t num_samples } 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 { @@ -171,18 +169,16 @@ void AudioEncoder::encode_last_audio() 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 {