abort();
}
- resampler = swr_alloc_set_opts(nullptr,
- /*out_ch_layout=*/AV_CH_LAYOUT_STEREO,
- /*out_sample_fmt=*/ctx->sample_fmt,
- /*out_sample_rate=*/OUTPUT_FREQUENCY,
- /*in_ch_layout=*/AV_CH_LAYOUT_STEREO,
- /*in_sample_fmt=*/AV_SAMPLE_FMT_FLT,
- /*in_sample_rate=*/OUTPUT_FREQUENCY,
- /*log_offset=*/0,
- /*log_ctx=*/nullptr);
- if (resampler == nullptr) {
+ resampler = nullptr;
+ int ok = swr_alloc_set_opts2(&resampler,
+ /*out_ch_layout=*/&ctx->ch_layout,
+ /*out_sample_fmt=*/ctx->sample_fmt,
+ /*out_sample_rate=*/OUTPUT_FREQUENCY,
+ /*in_ch_layout=*/&ctx->ch_layout,
+ /*in_sample_fmt=*/AV_SAMPLE_FMT_FLT,
+ /*in_sample_rate=*/OUTPUT_FREQUENCY,
+ /*log_offset=*/0,
+ /*log_ctx=*/nullptr);
+ if (ok != 0) {
fprintf(stderr, "Allocating resampler failed.\n");
abort();
}
}
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 {