From e08b23a76cf7c3a418071be86817af447ce7a6d7 Mon Sep 17 00:00:00 2001 From: Elliu <elliu@hashi.re> Date: Fri, 1 Sep 2023 18:55:15 +0200 Subject: [PATCH] Fix libav deprecated warnings --- src/Lib/AbstractMediaContext.hh | 2 +- src/Lib/Audio.cc | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Lib/AbstractMediaContext.hh b/src/Lib/AbstractMediaContext.hh index fef16001..1d99bd7b 100644 --- a/src/Lib/AbstractMediaContext.hh +++ b/src/Lib/AbstractMediaContext.hh @@ -84,7 +84,7 @@ protected: VIVY_LOG_CTOR() << "Codec: " << VIVY_LOG_QUOTED(codec->name) << ", id: " << codecId; VIVY_LOG_CTOR() << "Sample rate: " << codecParams->sample_rate; VIVY_LOG_CTOR() << "Bit rate: " << codecParams->bit_rate; - VIVY_LOG_CTOR() << "Channels: " << codecParams->channels; + VIVY_LOG_CTOR() << "Channels: " << codecParams->ch_layout.nb_channels; } public: diff --git a/src/Lib/Audio.cc b/src/Lib/Audio.cc index c308973a..bbe66844 100644 --- a/src/Lib/Audio.cc +++ b/src/Lib/Audio.cc @@ -31,9 +31,8 @@ AudioStream::AudioStream(const AVCodec *streamCodec, AVFormatContext *formatPtr, : Super(streamCodec, formatPtr, streamArg, index) { SwrContext *s = dataSwrContext.get(); - av_opt_set_int(s, "in_channel_count", codecContext->channels, 0); + av_opt_set_int(s, "in_channel_count", codecContext->ch_layout.nb_channels, 0); av_opt_set_int(s, "out_channel_count", 1, 0); - av_opt_set_int(s, "in_channel_layout", static_cast<int64_t>(codecContext->channel_layout), 0); av_opt_set_int(s, "out_channel_layout", AV_CH_LAYOUT_MONO, 0); av_opt_set_int(s, "in_sample_rate", codecContext->sample_rate, 0); av_opt_set_int(s, "out_sample_rate", resamplerSampleRate, 0); @@ -59,7 +58,7 @@ AudioStream::getProperties() const noexcept QJsonObject ret = Super::getProperties(); ret.insert("Sample rate", codecParams->sample_rate); ret.insert("Bit rate", static_cast<int>(codecParams->bit_rate)); - ret.insert("Channels", codecParams->channels); + ret.insert("Channels", codecParams->ch_layout.nb_channels); return ret; } @@ -71,19 +70,18 @@ AudioStream::decodeData() throw std::logic_error("audio stream is already resampled"); logDebug() << "Launch decoding of stream " << streamIndexInContext; - AVPacket packet; - av_init_packet(&packet); + AVPacket* packet = av_packet_alloc();; // Iterate through frames - while (av_read_frame(dataFormat, &packet) >= 0) { + while (av_read_frame(dataFormat, packet) >= 0) { // Only decode audio - if (packet.stream_index != streamIndexInContext) { - av_packet_unref(&packet); + if (packet->stream_index != streamIndexInContext) { + av_packet_unref(packet); continue; } // Decode one frame - int response = avcodec_send_packet(codecContext.get(), &packet); + int response = avcodec_send_packet(codecContext.get(), packet); if (response < 0) { throw std::runtime_error( QStringLiteral("error n°%1 while sending a packet to the decoder") @@ -135,7 +133,7 @@ AudioStream::decodeData() } dataDeleter(buffer); - av_packet_unref(&packet); + av_packet_unref(packet); } logDebug() << "Decoding data finished for stream " << streamIndexInContext << " with dataPtr " @@ -155,7 +153,7 @@ AudioStream::cleanUpData() noexcept int AudioStream::getChannels() const noexcept { - return codecContext->channels; + return codecContext->ch_layout.nb_channels; } // Get the sample rate -- GitLab