]> git.sesse.net Git - nageru/blobdiff - nageru/audio_encoder.cpp
IWYU-fix nageru/*.cpp.
[nageru] / nageru / audio_encoder.cpp
index 126e0e2dce19ef40f0406bea7a3d4abed120c731..9de20823b7b0609ccaffcce6ff53feb379a08bed 100644 (file)
@@ -1,6 +1,9 @@
 #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>
@@ -8,7 +11,6 @@ extern "C" {
 #include <libavutil/error.h>
 #include <libavutil/frame.h>
 #include <libavutil/mem.h>
-#include <libavutil/opt.h>
 #include <libavutil/rational.h>
 #include <libavutil/samplefmt.h>
 }
@@ -17,12 +19,13 @@ extern "C" {
 #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;
@@ -135,18 +138,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 +172,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 {