From e59a48003635af44ba2259c1033cfdf9e1dd5e54 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 16 Feb 2023 17:45:15 +0000 Subject: [PATCH] Investigate deprecated avcodec_decode_audio4 --- src/audioomx.cc | 43 +++++++++++++++++++++++++++++++++++++++++-- src/audioomx.h | 2 ++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/audioomx.cc b/src/audioomx.cc index dfa1d7e..1492455 100644 --- a/src/audioomx.cc +++ b/src/audioomx.cc @@ -2138,9 +2138,20 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, if ((int)gotframesize <= incoming_paket_libav.size) { if (gotframesize>0) incoming_paket_libav.size=gotframesize; - // FIXME deprecated + + // FIXME + // avcodec_decode_audio4 is deprecated + // DO_NOT_USE() works, but assumes all decoded data is returned + // in the first call to avcodec_receive_frame which is + // definitely bad code. + // This all needs reworking to handle this properly. + // Leaving DO_NOT_USE in the code in case we have to switch to it len = avcodec_decode_audio4(current_context, decode_frame_libav, &gotta, &incoming_paket_libav); + + //len = DO_NOT_USE(current_context, decode_frame_libav, + // &gotta, &incoming_paket_libav); + } else { //LogNT::getInstance()->debug(TAG, "FRAME:E {} {}",gotframesize,incoming_paket_libav.size); gotta=0; @@ -2382,7 +2393,7 @@ void AudioOMX::ResetTimeOffsets() vw->ResetTimeOffsets(); } - +// FIXME int AudioOMX::badMinimumFunction(u4 a, int b) { printf("MIN: P1: %u, P2: %i\n", a, b); @@ -2390,3 +2401,31 @@ int AudioOMX::badMinimumFunction(u4 a, int b) if (a > b) return b; else return a; } + +int AudioOMX::DO_NOT_USE(AVCodecContext* avctx, // used - sent to avcodec_send_packet + AVFrame* frame, // used - object for receive to write to + int* got_frame_ptr, // out param + const AVPacket* avpkt) // used - sent to avcodec_send_packet +{ + // Set this to error here. Any error point returns -9999 and *got_frame_ptr = 0 + *got_frame_ptr = 0; // Replicate old API behaviour + + int sendReturn = avcodec_send_packet(avctx, avpkt); + if (sendReturn < 0) return -9999; // error, shouldn't happen, just crash out. + + // Don't use this code + // avcodec_receive_frame needs to be called multiple times + // to ensure reception of all decoded data + int recReturn = avcodec_receive_frame(avctx, frame); + if (recReturn == 0) // success + { + // set got_frame_ptr to 1, this is the old behaviour + *got_frame_ptr = 1; + // return number of bytes consumed + // guessing here that the calling code only ever supplies whole packets + return avpkt->size; + } + + // error + return -9999; // no idea. looks like calling code checks got_frame_ptr +} diff --git a/src/audioomx.h b/src/audioomx.h index 9e4146d..a82b1db 100644 --- a/src/audioomx.h +++ b/src/audioomx.h @@ -199,6 +199,8 @@ class AudioOMX : public Audio int badMinimumFunction(u4 a, int b); + + int DO_NOT_USE(AVCodecContext* avctx, AVFrame* frame, int* got_frame_ptr, const AVPacket* avpkt); }; #endif -- 2.39.5