#include "audio_encoder.h"
+#include "shared/ffmpeg_raii.h"
extern "C" {
+#include <libavcodec/codec.h>
+#include <libavcodec/codec_par.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswresample/swresample.h>
#include <libavutil/error.h>
#include <libavutil/frame.h>
#include <libavutil/mem.h>
-#include <libavutil/opt.h>
#include <libavutil/rational.h>
#include <libavutil/samplefmt.h>
}
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
-#include "defs.h"
#include "shared/mux.h"
+#include "shared/shared_defs.h"
#include "shared/timebase.h"
using namespace std;
}
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 {