From c9a5e08cf98bde0c58001eaa38f008882a3b3977 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 13 May 2020 17:14:03 +0100 Subject: [PATCH] Switch from deprecated libavresample to libswresample. Some AudioOMX CWFs --- GNUmakefile | 4 +-- audioomx.cc | 91 ++++++++++++++++++++++++++++++++--------------------- audioomx.h | 4 +-- 3 files changed, 60 insertions(+), 39 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 8b8579f..9e367fb 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -57,7 +57,7 @@ LDFLAGS = -fuse-ld=gold $(PICTURES) vomp_options += -DIPV4 -DIPV6 LIBPATHS = -L/opt/vc/lib -L/usr/lib/arm-linux-gnueabihf -LIBS = -lpthread -lrt -lbrcmEGL -lbrcmOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil -lavresample +LIBS = -lpthread -lrt -lbrcmEGL -lbrcmOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil -lswresample LIBS += -ldl -lfontconfig -lfreetype -lMagick++-6.Q16 OBJECTS = $(OBJ_COMMON) $(OBJ_RASPBERRY) CROSSLIBS = @@ -74,7 +74,7 @@ CXX=arm-linux-gnueabihf-g++ LD=arm-linux-gnueabihf-g++ LDFLAGS = $(PICTURES) -Xlinker --sysroot=$(CROSSROOT) -Xlinker --rpath-link=$(CROSSROOT)/usr/lib/gcc/arm-linux-gnueabihf/8 -Xlinker --rpath-link=$(CROSSROOT)/usr/lib/arm-linux-gnueabihf -Xlinker --rpath-link=$(CROSSROOT)/lib/arm-linux-gnueabihf -Xlinker --rpath-link=$(CROSSROOT)/opt/vc/lib LIBPATHS = -L$(CROSSROOT)/usr/lib/gcc/arm-linux-gnueabihf/8 -L$(CROSSROOT)/opt/vc/lib -L$(CROSSROOT)/lib -L$(CROSSROOT)/usr/lib -L$(CROSSROOT)/lib/arm-linux-gnueabihf -L$(CROSSROOT)/usr/lib/arm-linux-gnueabihf -L$(CROSSROOT)/usr/local/lib -LIBS = -lpthread -lrt -lbrcmEGL -lbrcmOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil -lavresample +LIBS = -lpthread -lrt -lbrcmEGL -lbrcmOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil -lswresample LIBS += -ldl -lfontconfig -lfreetype -lMagick++-6.Q16 -lm OBJECTS = $(OBJ_COMMON) $(OBJ_RASPBERRY) CROSSLIBS = diff --git a/audioomx.cc b/audioomx.cc index 22ade65..7ad4d32 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -500,38 +500,34 @@ bool AudioOMX::addOptionsToPanes(int panenumber,Options *options,WOptionPane* pa } - - - - -OMX_ERRORTYPE AudioOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp,OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer){ - - //Log::getInstance()->log("Audio", Log::NOTICE, "EmptyBufferDone"); - AudioOMX* audio = static_cast(getInstance()); - audio->ReturnEmptyOMXBuffer(buffer); - return OMX_ErrorNone; +OMX_ERRORTYPE AudioOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE /* hcomp */, OMX_IN OMX_PTR /* appdata */, OMX_IN OMX_BUFFERHEADERTYPE* buffer) +{ + //Log::getInstance()->log("Audio", Log::NOTICE, "EmptyBufferDone"); + AudioOMX* audio = static_cast(getInstance()); + audio->ReturnEmptyOMXBuffer(buffer); + return OMX_ErrorNone; } -void AudioOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer){ - input_bufs_omx_mutex.lock(); - //Log::getInstance()->log("Audio", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size()); - input_bufs_omx_free.push_back(buffer); - //Log::getInstance()->log("Audio", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size()); - input_bufs_omx_mutex.unlock(); - VideoOMX* video = static_cast(Video::getInstance()); - video->signalOmx(); +void AudioOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer) +{ + input_bufs_omx_mutex.lock(); + //Log::getInstance()->log("Audio", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size()); + input_bufs_omx_free.push_back(buffer); + //Log::getInstance()->log("Audio", Log::NOTICE, "ReturnEmptyOMXBuffer %d",input_bufs_omx_free.size()); + input_bufs_omx_mutex.unlock(); + VideoOMX* video = static_cast(Video::getInstance()); + video->signalOmx(); } - OMX_ERRORTYPE AudioOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata,OMX_IN OMX_BUFFERHEADERTYPE* buffer) { - Log::getInstance()->log("Audio", Log::NOTICE, "FillBufferDone"); - VideoOMX* video = static_cast(Video::getInstance()); - video->signalOmx(); - return OMX_ErrorNone; +OMX_ERRORTYPE AudioOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE /* hcomp */, OMX_IN OMX_PTR /* appdata */, OMX_IN OMX_BUFFERHEADERTYPE* /* buffer */) +{ + Log::getInstance()->log("Audio", Log::NOTICE, "FillBufferDone"); + VideoOMX* video = static_cast(Video::getInstance()); + video->signalOmx(); + return OMX_ErrorNone; } - - -int AudioOMX::setStreamType(UCHAR type) +int AudioOMX::setStreamType(UCHAR /* type */) { if (!initted) return 0; @@ -891,7 +887,7 @@ int AudioOMX::InitDecoderLibAV() return 0; } - resam_con_libav = avresample_alloc_context(); + resam_con_libav = swr_alloc(); if (resam_con_libav == NULL) { Log::getInstance()->log("Audio", Log::DEBUG, "Alloc resample context failed"); @@ -941,7 +937,7 @@ void AudioOMX::DeinitDecoderLibAV() { av_free(mp23codec_context_libav); mp23codec_context_libav = NULL; - avresample_free(&resam_con_libav); + swr_free(&resam_con_libav); resam_con_libav=NULL; @@ -1733,7 +1729,7 @@ unsigned int AudioOMX::AdvanceAacLatmAudioSync(const UCHAR *data,unsigned int si } -void AudioOMX::PrepareMediaSample(const MediaPacketList& mplist,UINT samplepos) +void AudioOMX::PrepareMediaSample(const MediaPacketList& mplist, UINT /* samplepos */) { packet = mplist.front(); } @@ -2256,16 +2252,41 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const UCHAR* buffer, //Log::getInstance()->log("Audio", Log::ERR,"AV resampledata %d %d %d %d",current_context->channels,current_context->sample_rate,current_context->sample_fmt,current_context->channel_layout); //Log::getInstance()->log("Audio", Log::ERR,"AV resampledata2 %d %d %d",decode_frame_libav->sample_rate,decode_frame_libav->format,decode_frame_libav->channel_layout); - int ret=avresample_open(resam_con_libav); + int ret = swr_init(resam_con_libav); if (ret<0) { Log::getInstance()->log("Audio", Log::ERR,"Opening AV resample failed %d",ret); } else { uint8_t *output=cur_input_buf_omx->pBuffer + cur_input_buf_omx->nFilledLen; - - avresample_convert(resam_con_libav, &output, - dsize, decode_frame_libav->nb_samples, - decode_frame_libav->extended_data, decode_frame_libav->linesize[0], decode_frame_libav->nb_samples); - avresample_close(resam_con_libav); +/* + * old docs: + avresample_convert ( AVAudioResampleContext * avr, + uint8_t ** output, + int out_plane_size, + int out_samples, + uint8_t *const * input, + int in_plane_size, + int in_samples + ) + + old call: + avresample_convert(resam_con_libav, + &output, dsize, decode_frame_libav->nb_samples, + decode_frame_libav->extended_data, decode_frame_libav->linesize[0], decode_frame_libav->nb_samples); + + new docs: + swr_convert ( struct SwrContext * s, + uint8_t ** out, + int out_count, + const uint8_t ** in, + int in_count + ) + new call: + */ + //Log::getInstance()->log("AudioOMX", Log::DEBUG, "Calling swr_convert"); + + swr_convert(resam_con_libav, &output, decode_frame_libav->nb_samples, (const uint8_t**)decode_frame_libav->extended_data, decode_frame_libav->nb_samples); + + swr_close(resam_con_libav); } //Log::getInstance()->log("Audio", Log::DEBUG,"memcpy out"); diff --git a/audioomx.h b/audioomx.h index ae3c2b8..556f0f1 100644 --- a/audioomx.h +++ b/audioomx.h @@ -29,7 +29,7 @@ extern "C" { #include #include -#include +#include } #include "defines.h" @@ -180,7 +180,7 @@ class AudioOMX : public Audio AVCodecContext *mp23codec_context_libav; AVPacket incoming_paket_libav; AVFrame *decode_frame_libav; - AVAudioResampleContext *resam_con_libav; + SwrContext* resam_con_libav; UCHAR * decompress_buffer; -- 2.39.5