From 6130a55e6c2035aa8fe86640f89c6df8875e2ee7 Mon Sep 17 00:00:00 2001 From: xufuji456 Date: Tue, 6 Sep 2022 15:46:34 +0800 Subject: [PATCH] Feature: reuse packet --- app/src/main/cpp/audio_resample.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/app/src/main/cpp/audio_resample.cpp b/app/src/main/cpp/audio_resample.cpp index da330df..7798ca2 100644 --- a/app/src/main/cpp/audio_resample.cpp +++ b/app/src/main/cpp/audio_resample.cpp @@ -35,6 +35,10 @@ extern "C" { /* Global timestamp for the audio frames. */ static int64_t pts = 0; +static AVPacket input_packet; + +static AVPacket output_packet; + /** * Open an input file and the required decoder. * @@ -201,16 +205,6 @@ cleanup: return error < 0 ? error : AVERROR_EXIT; } -/** - * Initialize one data packet for reading or writing. - * @param packet Packet to be initialized - */ -static void init_packet(AVPacket *packet) { - av_init_packet(packet); - packet->data = nullptr; - packet->size = 0; -} - /** * Initialize one audio frame for reading from the input file. * @@ -288,8 +282,6 @@ static int decode_audio_frame(AVFrame *frame, AVCodecContext *input_codec_context, int *data_present, int *finished) { int error; - AVPacket input_packet; - init_packet(&input_packet); if ((error = av_read_frame(input_format_context, &input_packet)) < 0) { if (error == AVERROR_EOF) @@ -496,8 +488,6 @@ static int encode_audio_frame(AVFrame *frame, AVCodecContext *output_codec_context, int *data_present) { int error; - AVPacket output_packet; - init_packet(&output_packet); /* Set a timestamp based on the sample rate for the container. */ if (frame) {