From 081ebc05c3193ba1ce57ee7ea0e98a8d4776a238 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 6 Aug 2024 17:23:11 +0000 Subject: [PATCH] Reformatting, logger pointer, remove dead code/comments --- src/audio.h | 4 +- src/audioomx.cc | 914 ++++++++++++------------------------------------ src/audioomx.h | 60 ++-- 3 files changed, 261 insertions(+), 717 deletions(-) diff --git a/src/audio.h b/src/audio.h index e572721..b2f7a53 100644 --- a/src/audio.h +++ b/src/audio.h @@ -86,10 +86,10 @@ class Audio : public DrainTarget, public AbstractOption protected: static Audio* instance; - int initted; + int initted{}; u1 userMute; u1 systemMute; - u1 muted; + u1 muted{}; int volume; audio_volume Aoffset; diff --git a/src/audioomx.cc b/src/audioomx.cc index 853db9f..1fdc11a 100644 --- a/src/audioomx.cc +++ b/src/audioomx.cc @@ -38,43 +38,8 @@ static const char* TAG = "AudioOMX"; AudioOMX::AudioOMX() { - initted = 0; - streamType = 0; volume = 20; - muted = 0; lastAType = MPTYPE_MPEG_AUDIO; - - canpass_ac3 = false; - canpass_mp2 = false; - canpass_mp3 = false; - canpass_aac = false; - canpass_pcm_mch = false; - - prefered_ac3 = 0; //0 stereo PCM, 1 passthrough 2 Multichannel PCM - prefered_mp2 = 0; - prefered_mp3 = 0; - prefered_aac = 0; - hdmi = true; - - omx_running = false; - - omx_aud_rend/*dec*/ = 0; - cur_input_buf_omx = NULL; - - ac3codec_libav = NULL; - ac3codec_context_libav = NULL; - - mp23codec_libav = NULL; - mp23codec_context_libav = NULL; - - resam_con_libav = NULL; - - decompress_buffer = NULL; - decompress_buffer_size = 0; - decompress_buffer_filled = 0; - mp3sameheader = 0; - mp3sameheadercount = 0; - strcpy(L_VPE_OMX_AUDIO_REND, VPE_OMX_AUDIO_REND); } @@ -84,10 +49,9 @@ AudioOMX::~AudioOMX() int AudioOMX::init(u1 tstreamType) { - if (initted) - return 0; + if (initted) return 0; - initted = 1; + logger = LogNT::getInstance(); streamType = tstreamType; @@ -113,7 +77,7 @@ int AudioOMX::init(u1 tstreamType) if (ac3codec_libav == NULL) { - LogNT::getInstance()->debug(TAG, "Find libav ac3 decoder failed"); + logger->debug(TAG, "Find libav ac3 decoder failed"); return 0; } @@ -121,7 +85,7 @@ int AudioOMX::init(u1 tstreamType) if (mp23codec_libav == NULL) { - LogNT::getInstance()->debug(TAG, "Find libav mpeg audio decoder failed"); + logger->debug(TAG, "Find libav mpeg audio decoder failed"); return 0; } @@ -129,49 +93,42 @@ int AudioOMX::init(u1 tstreamType) if (aaclatmcodec_libav == NULL) { - LogNT::getInstance()->debug(TAG, "Find libav aac latm decoder failed"); + logger->debug(TAG, "Find libav aac latm decoder failed"); return 0; } int ret; - ret = vc_tv_hdmi_audio_supported( EDID_AudioFormat_eMPEG1, 2, EDID_AudioSampleRate_e48KHz, 0); - + ret = vc_tv_hdmi_audio_supported(EDID_AudioFormat_eMPEG1, 2, EDID_AudioSampleRate_e48KHz, 0); if (ret == 0) { - //canpass_mp2=true; - // not implemented - LogNT::getInstance()->info(TAG, "TV hdmi supports mpeg1 layer 1 and 2"); + // canpass_mp2=true; // not implemented + logger->info(TAG, "TV hdmi supports mpeg1 layer 1 and 2"); } - ret = vc_tv_hdmi_audio_supported( EDID_AudioFormat_eMP3, 2, EDID_AudioSampleRate_e48KHz, 0); - + ret = vc_tv_hdmi_audio_supported(EDID_AudioFormat_eMP3, 2, EDID_AudioSampleRate_e48KHz, 0); if (ret == 0) { - //canpass_mp3=true; - // not implemented - LogNT::getInstance()->info(TAG, "TV hdmi supports mpeg1 layer 3"); + // canpass_mp3=true; // not implemented + logger->info(TAG, "TV hdmi supports mpeg1 layer 3"); } - ret = vc_tv_hdmi_audio_supported( EDID_AudioFormat_eAC3, 6, EDID_AudioSampleRate_e48KHz, 0); - + ret = vc_tv_hdmi_audio_supported(EDID_AudioFormat_eAC3, 6, EDID_AudioSampleRate_e48KHz, 0); if (ret == 0) { canpass_ac3 = true; - LogNT::getInstance()->info(TAG, "TV hdmi supports AC3"); + logger->info(TAG, "TV hdmi supports AC3"); } - ret = vc_tv_hdmi_audio_supported( EDID_AudioFormat_eAAC, 6, EDID_AudioSampleRate_e48KHz, 0); - + ret = vc_tv_hdmi_audio_supported(EDID_AudioFormat_eAAC, 6, EDID_AudioSampleRate_e48KHz, 0); if (ret == 0) { - canpass_aac = true; - //not implemented - LogNT::getInstance()->info(TAG, "TV hdmi supports AAC"); + canpass_aac = true; // not implemented ? + logger->info(TAG, "TV hdmi supports AAC"); } canpass_pcm_mch = false; - + initted = 1; return 1; } @@ -183,223 +140,113 @@ int AudioOMX::initAllParams() int AudioOMX::shutdown() { if (!initted) return 0; - - initted = 0; - - LogNT::getInstance()->debug(TAG, "audio shutdown called"); + logger->debug(TAG, "audio shutdown called"); DeAllocateCodecsOMX(); - free(decompress_buffer); decompress_buffer = NULL; decompress_buffer_size = 0; decompress_buffer_filled = 0; - + initted = 0; return 1; } bool AudioOMX::loadOptionsFromServer(VDR* vdr) { - LogNT::getInstance()->debug(TAG, "AudioOMX config load"); - char* name = vdr->configLoad("AudioOMX", "AC3DecodingMode"); + logger->debug(TAG, "AudioOMX config load"); - if (name != NULL) + char* name = vdr->configLoad("AudioOMX", "AC3DecodingMode"); + if (name) { - if (STRCASECMP(name, "PCM") == 0) - { - prefered_ac3 = 0; - } - else if (STRCASECMP(name, "Passthrough") == 0) - { - prefered_ac3 = 1; - } - else if (STRCASECMP(name, "PCMMultichannel") == 0) - { - prefered_ac3 = 2; - } + if (STRCASECMP(name, "PCM") == 0) prefered_ac3 = 0; + else if (STRCASECMP(name, "Passthrough") == 0) prefered_ac3 = 1; + else if (STRCASECMP(name, "PCMMultichannel") == 0) prefered_ac3 = 2; delete[] name; } name = vdr->configLoad("AudioOMX", "Mp2DecodingMode"); - - if (name != NULL) + if (name) { - if (STRCASECMP(name, "PCM") == 0) - { - prefered_mp2 = 0; - } - else if (STRCASECMP(name, "Passthrough") == 0) - { - prefered_mp2 = 1; - } - else if (STRCASECMP(name, "PCMMultichannel") == 0) - { - prefered_mp2 = 2; - } + if (STRCASECMP(name, "PCM") == 0) prefered_mp2 = 0; + else if (STRCASECMP(name, "Passthrough") == 0) prefered_mp2 = 1; + else if (STRCASECMP(name, "PCMMultichannel") == 0) prefered_mp2 = 2; delete[] name; } name = vdr->configLoad("AudioOMX", "AACDecodingMode"); - - if (name != NULL) + if (name) { - if (STRCASECMP(name, "PCM") == 0) - { - prefered_aac = 0; - } - else if (STRCASECMP(name, "Passthrough") == 0) - { - prefered_aac = 1; - } - else if (STRCASECMP(name, "PCMMultichannel") == 0) - { - prefered_aac = 2; - } + if (STRCASECMP(name, "PCM") == 0) prefered_aac = 0; + else if (STRCASECMP(name, "Passthrough") == 0) prefered_aac = 1; + else if (STRCASECMP(name, "PCMMultichannel") == 0) prefered_aac = 2; delete[] name; } name = vdr->configLoad("AudioOMX", "Mp3DecodingMode"); - - if (name != NULL) + if (name) { - if (STRCASECMP(name, "PCM") == 0) - { - prefered_mp3 = 0; - } - else if (STRCASECMP(name, "Passthrough") == 0) - { - prefered_mp3 = 1; - } - else if (STRCASECMP(name, "PCMMultichannel") == 0) - { - prefered_mp3 = 2; - } + if (STRCASECMP(name, "PCM") == 0) prefered_mp3 = 0; + else if (STRCASECMP(name, "Passthrough") == 0) prefered_mp3 = 1; + else if (STRCASECMP(name, "PCMMultichannel") == 0) prefered_mp3 = 2; delete[] name; } name = vdr->configLoad("AudioOMX", "AudioOutput"); - - if (name != NULL) + if (name) { - if (STRCASECMP(name, "analog") == 0) - { - hdmi = false; - } - else if (STRCASECMP(name, "HDMI") == 0) - { - hdmi = true; - } + if (STRCASECMP(name, "analog") == 0) hdmi = false; + else if (STRCASECMP(name, "HDMI") == 0) hdmi = true; delete[] name; } - return true; - } bool AudioOMX::handleOptionChanges(Option* option) { - if (Audio::handleOptionChanges(option)) - return true; + if (Audio::handleOptionChanges(option)) return true; switch (option->id) { case 4: - { - if (STRCASECMP(option->options[option->userSetChoice], "analog") == 0) - { - hdmi = false; - } - else if (STRCASECMP(option->options[option->userSetChoice], "HDMI") - == 0) - { - hdmi = true; - } - + if (STRCASECMP(option->options[option->userSetChoice], "analog") == 0) hdmi = false; + else if (STRCASECMP(option->options[option->userSetChoice], "HDMI") == 0) hdmi = true; return true; - } - break; case 1: - { - if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) - { - prefered_ac3 = 0; - } - else if (STRCASECMP(option->options[option->userSetChoice], "Passthrough") == 0) - { - prefered_ac3 = 1; - } - else if (STRCASECMP(option->options[option->userSetChoice], "PCMMultichannel") == 0) - { - prefered_ac3 = 2; - } - } - break; + if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) prefered_ac3 = 0; + else if (STRCASECMP(option->options[option->userSetChoice], "Passthrough") == 0) prefered_ac3 = 1; + else if (STRCASECMP(option->options[option->userSetChoice], "PCMMultichannel") == 0) prefered_ac3 = 2; + return true; case 2: - { - if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) - { - prefered_mp2 = 0; - } - else if (STRCASECMP(option->options[option->userSetChoice], "Passthrough") == 0) - { - prefered_mp2 = 1; - } - else if (STRCASECMP(option->options[option->userSetChoice], "PCMMultichannel") == 0) - { - prefered_mp2 = 2; - } - } - break; + if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) prefered_mp2 = 0; + else if (STRCASECMP(option->options[option->userSetChoice], "Passthrough") == 0) prefered_mp2 = 1; + else if (STRCASECMP(option->options[option->userSetChoice], "PCMMultichannel") == 0) prefered_mp2 = 2; + return true; case 3: - { - if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) - { - prefered_mp3 = 0; - } - else if (STRCASECMP(option->options[option->userSetChoice], "Passthrough") == 0) - { - prefered_mp3 = 1; - } - else if (STRCASECMP(option->options[option->userSetChoice], "PCMMultichannel") == 0) - { - prefered_mp3 = 2; - } - } - break; + if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) prefered_mp3 = 0; + else if (STRCASECMP(option->options[option->userSetChoice], "Passthrough") == 0) prefered_mp3 = 1; + else if (STRCASECMP(option->options[option->userSetChoice], "PCMMultichannel") == 0) prefered_mp3 = 2; + return true; case 5: - { - if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) - { - prefered_aac = 0; - } - else if (STRCASECMP(option->options[option->userSetChoice], "Passthrough") == 0) - { - prefered_aac = 1; - } - else if (STRCASECMP(option->options[option->userSetChoice], "PCMMultichannel") == 0) - { - prefered_aac = 2; - } - } - break; + if (STRCASECMP(option->options[option->userSetChoice], "PCM") == 0) prefered_aac = 0; + else if (STRCASECMP(option->options[option->userSetChoice], "Passthrough") == 0) prefered_aac = 1; + else if (STRCASECMP(option->options[option->userSetChoice], "PCMMultichannel") == 0) prefered_aac = 2; + return true; } return false; - } bool AudioOMX::saveOptionstoServer() { - switch (prefered_ac3) { case 0: @@ -465,7 +312,6 @@ bool AudioOMX::saveOptionstoServer() else VDR::getInstance()->configSave("AudioOMX", "AudioOutput", "HDMI"); - return true; } @@ -486,8 +332,7 @@ bool AudioOMX::addOptionsToPanes(int panenumber, Options* options, WOptionPane* options->push_back(option); pane->addOptionLine(option); - - char** ac3opts = new char* [3]; + char** ac3opts = new char*[3]; int i = 0; ac3opts[i] = new char[strlen("PCM") + 1]; strcpy(ac3opts[i], "PCM"); @@ -583,7 +428,6 @@ bool AudioOMX::addOptionsToPanes(int panenumber, Options* options, WOptionPane* OMX_ERRORTYPE AudioOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE /* hcomp */, OMX_IN OMX_PTR /* appdata */, OMX_IN OMX_BUFFERHEADERTYPE* buffer) { - //LogNT::getInstance()->info(TAG, "EmptyBufferDone"); AudioOMX* audio = static_cast(getInstance()); audio->ReturnEmptyOMXBuffer(buffer); return OMX_ErrorNone; @@ -592,9 +436,7 @@ OMX_ERRORTYPE AudioOMX::EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE /* hcomp */, O void AudioOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer) { input_bufs_omx_mutex.lock(); - //LogNT::getInstance()->info(TAG, "ReturnEmptyOMXBuffer {}",input_bufs_omx_free.size()); input_bufs_omx_free.push_back(buffer); - //LogNT::getInstance()->info(TAG, "ReturnEmptyOMXBuffer {}",input_bufs_omx_free.size()); input_bufs_omx_mutex.unlock(); VideoOMX* video = static_cast(Video::getInstance()); video->signalOmx(); @@ -602,62 +444,31 @@ void AudioOMX::ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* buffer) OMX_ERRORTYPE AudioOMX::FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE /* hcomp */, OMX_IN OMX_PTR /* appdata */, OMX_IN OMX_BUFFERHEADERTYPE* /* buffer */) { - LogNT::getInstance()->info(TAG, "FillBufferDone"); VideoOMX* video = static_cast(Video::getInstance()); video->signalOmx(); return OMX_ErrorNone; } -int AudioOMX::setStreamType(u1 /* type */) -{ - if (!initted) return 0; - - // if (ioctl(fdAudio, AV_SET_AUD_STREAMTYPE, type) != 0) return 0; - return 1; -} - -int AudioOMX::setChannel() -{ - if (!initted) return 0; - - // if (ioctl(fdAudio, AV_SET_AUD_CHANNEL, 0) != 0) return 0; - return 1; -} - -int AudioOMX::setSource() -{ - if (!initted) return 0; - - // if (ioctl(fdAudio, AV_SET_AUD_SRC, 1) != 0) return 0; - return 1; -} - -int AudioOMX::sync() -{ - if (!initted) return 0; - - // if (ioctl(fdAudio, AV_SET_AUD_SYNC, 2) != 0) return 0; - return 1; -} +int AudioOMX::setStreamType(u1 /* type */) { return 1; } +int AudioOMX::setChannel() { return 1; } +int AudioOMX::setSource() { return 1; } +int AudioOMX::sync() { return 1; } int AudioOMX::play() { if (!initted) return 0; lastAType = MPTYPE_MPEG_AUDIO; - LogNT::getInstance()->debug(TAG, "enter play"); + logger->debug(TAG, "enter play"); static_cast(Video::getInstance())->interlaceSwitch4Demux(); // switch resolution if necessary - if (!AllocateCodecsOMX()) - { - return 0; - } + if (!AllocateCodecsOMX()) return 0; return 1; } -int AudioOMX::ChangeAudioDestination() //clock aka omx mutex needs to be locked +int AudioOMX::ChangeAudioDestination() // clock aka omx mutex needs to be locked { OMX_ERRORTYPE error; const char* destinations[] = {"local", "hdmi"}; @@ -672,12 +483,11 @@ int AudioOMX::ChangeAudioDestination() //clock aka omx mutex needs to be locked auddest.nVersion.nVersion = OMX_VERSION; strcpy((char*)auddest.sName, destinations[dest]); - LogNT::getInstance()->debug(TAG, "setting destination to: {}", auddest.sName); + logger->debug(TAG, "setting destination to: {}", auddest.sName); error = OMX_SetConfig(omx_aud_rend, OMX_IndexConfigBrcmAudioDestination, &auddest); - if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Init OMX_IndexConfigBrcmAudioDestination failed {:#x} {:#x} {}", error, omx_aud_rend, auddest.sName); + logger->debug(TAG, "Init OMX_IndexConfigBrcmAudioDestination failed {:#x} {:#x} {}", error, omx_aud_rend, auddest.sName); DeAllocateCodecsOMX(); return 0; } @@ -689,7 +499,7 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to { OMX_ERRORTYPE error; //Ok first fidle a working configuration - LogNT::getInstance()->debug(TAG, "ChangeAudioPortConfig"); + logger->debug(TAG, "ChangeAudioPortConfig"); OMX_AUDIO_CODINGTYPE encoding; @@ -716,8 +526,8 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to encoding = OMX_AUDIO_CodingPCM; } } + break; } - break; case MPTYPE_AAC_LATM: { @@ -727,7 +537,7 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to } else { - LogNT::getInstance()->debug(TAG, "ChangeAudioPortConfig debug {} {}", prefered_aac, canpass_aac); + logger->debug(TAG, "ChangeAudioPortConfig debug {} {}", prefered_aac, canpass_aac); if (prefered_aac == 1 && canpass_aac) { @@ -740,8 +550,8 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to encoding = OMX_AUDIO_CodingPCM; } } + break; } - break; case MPTYPE_AC3_PRE13: case MPTYPE_AC3: @@ -752,7 +562,7 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to } else { - LogNT::getInstance()->debug(TAG, "ChangeAudioPortConfig debug {} {}", prefered_ac3, canpass_ac3); + logger->debug(TAG, "ChangeAudioPortConfig debug {} {}", prefered_ac3, canpass_ac3); if (prefered_ac3 == 1 && canpass_ac3) { @@ -765,8 +575,8 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to encoding = OMX_AUDIO_CodingPCM; } } + break; } - break; case MPTYPE_MPEG_AUDIO_LAYER3: { @@ -787,9 +597,9 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to encoding = OMX_AUDIO_CodingPCM; } } + break; } - break; - }; + } } else { @@ -799,7 +609,6 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to } - /*OMX_CONFIG_BOOLEANTYPE booly; memset(&booly, 0, sizeof(booly)); booly.nSize = sizeof(booly); @@ -812,7 +621,7 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to error = OMX_SetParameter(omx_aud_dec, OMX_IndexParamBrcmDecoderPassThrough, &booly); if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, + logger->debug(TAG, "Init OMX_IndexParamBrcmDecoderPassThrough failed {:#x}", error); DeAllocateCodecsOMX(); return 0; @@ -826,32 +635,26 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to //video->CommandFinished(omx_aud_rend,OMX_CommandPortDisable,omx_rend_input_port); } - OMX_AUDIO_PARAM_PORTFORMATTYPE format; memset(&format, 0, sizeof(format)); format.nSize = sizeof(format); format.nVersion.nVersion = OMX_VERSION; format.nPortIndex = omx_rend_input_port; - error = OMX_GetParameter(omx_aud_rend, OMX_IndexParamAudioPortFormat, - &format); - + error = OMX_GetParameter(omx_aud_rend, OMX_IndexParamAudioPortFormat, &format); if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Get OMX_IndexParamAudioPortFormat failed {:#x} {}", error, omx_rend_input_port); + logger->debug(TAG, "Get OMX_IndexParamAudioPortFormat failed {:#x} {}", error, omx_rend_input_port); return 0; } - if (disport) - - LogNT::getInstance()->debug(TAG, "Get OMX_IndexParamAudioPortFormat returned {}", format.eEncoding ); + if (disport) logger->debug(TAG, "Get OMX_IndexParamAudioPortFormat returned {}", format.eEncoding); format.eEncoding = encoding; error = OMX_SetParameter(omx_aud_rend, OMX_IndexParamAudioPortFormat, &format); - if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Set OMX_IndexParamAudioPortFormat failed {:#x} {} {}", error, omx_rend_input_port, format.eEncoding); + logger->debug(TAG, "Set OMX_IndexParamAudioPortFormat failed {:#x} {} {}", error, omx_rend_input_port, format.eEncoding); //return 0; } @@ -879,11 +682,11 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Init OMX_IndexParamAudioPcm failed {:#x} {}", error, omx_rend_input_port); + logger->debug(TAG, "Init OMX_IndexParamAudioPcm failed {:#x} {}", error, omx_rend_input_port); return 0; } + break; } - break; case OMX_AUDIO_CodingDDP: { @@ -908,20 +711,19 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, + logger->debug(TAG, "Init OMX_IndexParamAudioDdp failed {:#x} {}", error, omx_rend_input_port); return 0; } + break; } - break; default: break; //Make compiler happy }; if (disport) { - //PrepareInputBufsOMX(false); video->EnablePort(omx_aud_rend, omx_rend_input_port, false); } @@ -936,7 +738,7 @@ int AudioOMX::InitDecoderLibAV() if (!ac3codec_context_libav) { - LogNT::getInstance()->debug(TAG, "Alloc avcodec for ac3 decoding context failed!"); + logger->debug(TAG, "Alloc avcodec for ac3 decoding context failed!"); return 0; } @@ -956,7 +758,7 @@ int AudioOMX::InitDecoderLibAV() if (avc_ret < 0) { - LogNT::getInstance()->debug(TAG, "Opening libav codec failed"); + logger->debug(TAG, "Opening libav codec failed"); libav_mutex.unlock(); return 0; } @@ -965,7 +767,7 @@ int AudioOMX::InitDecoderLibAV() if (!aaclatmcodec_context_libav) { - LogNT::getInstance()->debug(TAG, "Alloc avcodec for aac decoding context failed!"); + logger->debug(TAG, "Alloc avcodec for aac decoding context failed!"); return 0; } @@ -985,7 +787,7 @@ int AudioOMX::InitDecoderLibAV() if (avc_ret < 0) { - LogNT::getInstance()->debug(TAG, "Opening libav codec failed"); + logger->debug(TAG, "Opening libav codec failed"); libav_mutex.unlock(); return 0; } @@ -994,7 +796,7 @@ int AudioOMX::InitDecoderLibAV() if (!ac3codec_context_libav) { - LogNT::getInstance()->debug(TAG, "Alloc avcodec for mp23 decoding context failed!"); + logger->debug(TAG, "Alloc avcodec for mp23 decoding context failed!"); libav_mutex.unlock(); return 0; } @@ -1015,7 +817,7 @@ int AudioOMX::InitDecoderLibAV() if (avc_ret < 0) { - LogNT::getInstance()->debug(TAG, "Opening libav codec failed"); + logger->debug(TAG, "Opening libav codec failed"); libav_mutex.unlock(); return 0; } @@ -1024,7 +826,7 @@ int AudioOMX::InitDecoderLibAV() if (resam_con_libav == NULL) { - LogNT::getInstance()->debug(TAG, "Alloc resample context failed"); + logger->debug(TAG, "Alloc resample context failed"); return 0; } @@ -1081,7 +883,7 @@ int AudioOMX::AllocateCodecsOMX() OMX_ERRORTYPE error; static OMX_CALLBACKTYPE callbacks = {&VideoOMX::EventHandler_OMX, &EmptyBufferDone_OMX, &FillBufferDone_OMX}; - LogNT::getInstance()->info(TAG, "Allocate Codecs OMX"); + logger->info(TAG, "Allocate Codecs OMX"); //Clock, move later to audio VideoOMX* video = static_cast(Video::getInstance()); @@ -1109,7 +911,7 @@ int AudioOMX::AllocateCodecsOMX() if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Init OMX audio rend failed {:#x}", error); + logger->debug(TAG, "Init OMX audio rend failed {:#x}", error); video->UnlockClock(); DeAllocateCodecsOMX(); return 0; @@ -1126,7 +928,7 @@ int AudioOMX::AllocateCodecsOMX() if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Init OMX audio rend OMX_GetParameter failed {:#x}", error); + logger->debug(TAG, "Init OMX audio rend OMX_GetParameter failed {:#x}", error); video->UnlockClock(); DeAllocateCodecsOMX(); return 0; @@ -1138,7 +940,7 @@ int AudioOMX::AllocateCodecsOMX() if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Init OMX aud rend OMX_GetParameter failed {:#x}", error); + logger->debug(TAG, "Init OMX aud rend OMX_GetParameter failed {:#x}", error); video->UnlockClock(); DeAllocateCodecsOMX(); return 0; @@ -1147,60 +949,28 @@ int AudioOMX::AllocateCodecsOMX() // buggy return value omx_rend_clock_port = p_param.nStartPortNumber; - - - /* error=OMX_GetHandle(&omx_aud_dec,VPE_OMX_AUDIO_DECODER,NULL,&callbacks); - - if (error!=OMX_ErrorNone){ - LogNT::getInstance()->debug(TAG, "Init OMX audio decoder failed {:#x}", error); - video->UnlockClock(); - DeAllocateCodecsOMX(); - return 0; - } - - error=OMX_GetParameter(omx_aud_dec,OMX_IndexParamAudioInit,&p_param); - if (error!=OMX_ErrorNone){ - LogNT::getInstance()->debug(TAG, "Init OMX audio decoder OMX_GetParameter failed {:#x}", error); - video->UnlockClock(); - DeAllocateCodecsOMX(); - return 0; - } - omx_codec_input_port=p_param.nStartPortNumber; - omx_codec_output_port=p_param.nStartPortNumber+1; - - if (!video->DisablePort(omx_aud_dec,omx_codec_input_port) || !video->DisablePort(omx_aud_dec,omx_codec_output_port)) { - LogNT::getInstance()->debug(TAG, "Disable Ports OMX audio decoder failed"); - video->UnlockClock(); - DeAllocateCodecsOMX(); - return 0; - }*/ - - - if (!video->DisablePort(omx_aud_rend, omx_rend_input_port, true) ) + if (!video->DisablePort(omx_aud_rend, omx_rend_input_port, true)) { - LogNT::getInstance()->debug(TAG, "Disable Ports OMX audio rend failed {}", omx_rend_input_port); + logger->debug(TAG, "Disable Ports OMX audio rend failed {}", omx_rend_input_port); video->UnlockClock(); DeAllocateCodecsOMX(); return 0; } - if ( !video->DisablePort(omx_aud_rend, omx_rend_clock_port, true)) + if (!video->DisablePort(omx_aud_rend, omx_rend_clock_port, true)) { - LogNT::getInstance()->debug(TAG, - "Disable Ports OMX rend clock port failed {}", omx_rend_clock_port); + logger->debug(TAG, "Disable Ports OMX rend clock port failed {}", omx_rend_clock_port); video->UnlockClock(); DeAllocateCodecsOMX(); return 0; } - // Setup chain error = OMX_SetupTunnel(omx_clock, omx_clock_output_port, omx_aud_rend, omx_rend_clock_port); - if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel clock to rend failed {:#x} {} {}", error, omx_clock_output_port, omx_rend_clock_port); + logger->debug(TAG, "OMX_Setup tunnel clock to rend failed {:#x} {} {}", error, omx_clock_output_port, omx_rend_clock_port); video->UnlockClock(); DeAllocateCodecsOMX(); return 0; @@ -1208,7 +978,7 @@ int AudioOMX::AllocateCodecsOMX() if (!video->EnablePort(omx_clock, omx_clock_output_port, false) || !video->EnablePort(omx_aud_rend, omx_rend_clock_port, false)) { - LogNT::getInstance()->debug(TAG, "Enable Ports OMX clock rend failed"); + logger->debug(TAG, "Enable Ports OMX clock rend failed"); video->UnlockClock(); DeAllocateCodecsOMX(); return 0; @@ -1216,7 +986,7 @@ int AudioOMX::AllocateCodecsOMX() if (!video->ChangeComponentState(omx_aud_rend, OMX_StateIdle)) { - LogNT::getInstance()->debug(TAG, "aud_rend idle ChangeComponentState"); + logger->debug(TAG, "aud_rend idle ChangeComponentState"); video->UnlockClock(); DeAllocateCodecsOMX(); return 0; @@ -1238,18 +1008,12 @@ int AudioOMX::AllocateCodecsOMX() if (!ChangeAudioPortConfig(false)) { - LogNT::getInstance()->info(TAG, "Change AudioPortConfig failed"); + logger->info(TAG, "Change AudioPortConfig failed"); video->UnlockClock(); DeAllocateCodecsOMX(); return 0; } - /* if (!video->ChangeComponentState(omx_aud_dec,OMX_StateIdle)) { - LogNT::getInstance()->debug(TAG, "aud_dec ChangeComponentState"); - DeAllocateCodecsOMX(); - return 0; - }*/ - if (!PrepareInputBufsOMX(true)) { video->UnlockClock(); @@ -1257,32 +1021,9 @@ int AudioOMX::AllocateCodecsOMX() return 0; } - /* error=OMX_SetupTunnel(omx_aud_dec,omx_codec_output_port,omx_aud_rend,omx_rend_input_port); - if (error!=OMX_ErrorNone){ - LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel dec to render failed {:#x}", error); - video->UnlockClock(); - DeAllocateCodecsOMX(); - return 0; - }*/ - - /* if (!video->EnablePort(omx_aud_dec,omx_codec_output_port,false) || !video->EnablePort(omx_aud_rend,omx_rend_input_port,false) - ) { - LogNT::getInstance()->debug(TAG, "Enable Ports OMX codec rend failed"); - video->UnlockClock(); - DeAllocateCodecsOMX(); - return 0; - }*/ - - /* if ( !video->CommandFinished(omx_aud_dec,OMX_CommandPortEnable,omx_codec_output_port) - || !video->CommandFinished(omx_aud_rend,OMX_CommandPortEnable,omx_rend_input_port)) { - video->UnlockClock(); - DeAllocateCodecsOMX(); - return 0; - }*/ - if (!video->ChangeComponentState(omx_aud_rend, OMX_StateExecuting)) { - LogNT::getInstance()->debug(TAG, "omx_aud_rend ChangeComponentState Execute"); + logger->debug(TAG, "omx_aud_rend ChangeComponentState Execute"); video->UnlockClock(); DeAllocateCodecsOMX(); return 0; @@ -1296,11 +1037,11 @@ int AudioOMX::AllocateCodecsOMX() if (!video->setClockExecutingandRunning()) return 0; - LogNT::getInstance()->info(TAG, "Allocate Codecs OMX finished"); + logger->info(TAG, "Allocate Codecs OMX finished"); return 1; } -int AudioOMX::PrepareInputBufsOMX(bool setportdef) //needs to be called with locvke omx clock mutex +int AudioOMX::PrepareInputBufsOMX(bool setportdef) //needs to be called with locked omx clock mutex { VideoOMX* video = static_cast(Video::getInstance()); @@ -1315,7 +1056,7 @@ int AudioOMX::PrepareInputBufsOMX(bool setportdef) //needs to be called with loc if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Get OMX OMX_IndexParamPortDefinition failed {:#x}", error); + logger->debug(TAG, "Get OMX OMX_IndexParamPortDefinition failed {:#x}", error); } if (setportdef) @@ -1326,14 +1067,14 @@ int AudioOMX::PrepareInputBufsOMX(bool setportdef) //needs to be called with loc error = OMX_SetParameter(omx_aud_rend/*dec*/, OMX_IndexParamPortDefinition, &port_def_type); if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Set OMX OMX_IndexParamPortDefinition failed {:#x}", error); + logger->debug(TAG, "Set OMX OMX_IndexParamPortDefinition failed {:#x}", error); } } error = OMX_SendCommand(omx_aud_rend/*dec*/, OMX_CommandPortEnable, omx_rend_input_port/*codec*/, 0); if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Prepare Input bufs Send Command to enable port {:#x}", error); + logger->debug(TAG, "Prepare Input bufs Send Command to enable port {:#x}", error); return 0; } @@ -1346,7 +1087,7 @@ int AudioOMX::PrepareInputBufsOMX(bool setportdef) //needs to be called with loc if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Use OMX_AllocateBuffer failed {:#x}", error); + logger->debug(TAG, "Use OMX_AllocateBuffer failed {:#x}", error); input_bufs_omx_mutex.unlock(); return 0; } @@ -1382,7 +1123,7 @@ int AudioOMX::DestroyInputBufsOMX() //call with clock mutex locked if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Use OMX_FreeBuffer failed {:#x}", error); + logger->debug(TAG, "Use OMX_FreeBuffer failed {:#x}", error); input_bufs_omx_mutex.unlock(); return 0; } @@ -1397,8 +1138,6 @@ int AudioOMX::DestroyInputBufsOMX() //call with clock mutex locked int AudioOMX::DestroyInputBufsOMXwhilePlaying() //call with clock mutex locked { - //OMX_ERRORTYPE error; - cur_input_buf_omx = NULL; input_bufs_omx_mutex.lock(); @@ -1428,7 +1167,7 @@ int AudioOMX::DestroyInputBufsOMXwhilePlaying() //call with clock mutex locked } } - LogNT::getInstance()->debug(TAG, "DestroyInputBufsOMXwhilePlaying {} {}", input_bufs_omx_all.size(), input_bufs_omx_free.size()); + logger->debug(TAG, "DestroyInputBufsOMXwhilePlaying {} {}", input_bufs_omx_all.size(), input_bufs_omx_free.size()); input_bufs_omx_mutex.unlock(); return 1; } @@ -1438,9 +1177,9 @@ int AudioOMX::DeAllocateCodecsOMX() OMX_ERRORTYPE error; omx_running = false; VideoOMX* video = static_cast(Video::getInstance()); - LogNT::getInstance()->debug(TAG, "enter deallocatecodecsomx"); + logger->debug(TAG, "enter deallocatecodecsomx"); - LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 1"); + logger->debug(TAG, "deallocatecodecsomx mark 1"); if (cur_input_buf_omx) { @@ -1449,13 +1188,13 @@ int AudioOMX::DeAllocateCodecsOMX() if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "OMX_EmptyThisBuffer 6 failed {:#x}", error); + logger->debug(TAG, "OMX_EmptyThisBuffer 6 failed {:#x}", error); } cur_input_buf_omx = NULL; //write out old data } - LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 2"); + logger->debug(TAG, "deallocatecodecsomx mark 2"); video->LockClock(); @@ -1463,19 +1202,19 @@ int AudioOMX::DeAllocateCodecsOMX() { // first stop the omx elements /* if (!video->ChangeComponentState(omx_aud_dec,OMX_StateIdle)) { - LogNT::getInstance()->debug(TAG, "aud_dec ChangeComponentState"); + logger->debug(TAG, "aud_dec ChangeComponentState"); }*/ - LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 3"); + logger->debug(TAG, "deallocatecodecsomx mark 3"); video->UnlockClock(); - LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 4"); + logger->debug(TAG, "deallocatecodecsomx mark 4"); video->idleClock(); - LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 5"); + logger->debug(TAG, "deallocatecodecsomx mark 5"); video->LockClock(); if (!video->ChangeComponentState(omx_aud_rend, OMX_StateIdle)) { - LogNT::getInstance()->debug(TAG, "aud_rend ChangeComponentState"); + logger->debug(TAG, "aud_rend ChangeComponentState"); } // TODO proper deinit sequence @@ -1485,98 +1224,70 @@ int AudioOMX::DeAllocateCodecsOMX() if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "OMX_Flush rend in failed {:#x}", error); + logger->debug(TAG, "OMX_Flush rend in failed {:#x}", error); } - /* error=OMX_SendCommand(omx_aud_dec,OMX_CommandFlush, omx_codec_input_port, NULL); - if (error!=OMX_ErrorNone){ - LogNT::getInstance()->debug(TAG, "OMX_Flush codec out failed {:#x}", error); - - }*/ - - - /* if (!video->CommandFinished(omx_aud_dec,OMX_CommandFlush,omx_codec_input_port)) { - LogNT::getInstance()->debug(TAG, "flush cmd codec input failed"); - }*/ - - - error = OMX_SendCommand(omx_clock, OMX_CommandFlush, omx_clock_output_port, NULL); if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "OMX_Flush clock out failed {:#x}", error); + logger->debug(TAG, "OMX_Flush clock out failed {:#x}", error); } error = OMX_SendCommand(omx_aud_rend, OMX_CommandFlush, omx_rend_clock_port, NULL); if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "OMX_Flush rend clock failed {:#x}", error); + logger->debug(TAG, "OMX_Flush rend clock failed {:#x}", error); } - LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6"); + logger->debug(TAG, "deallocatecodecsomx mark 6"); if (!video->CommandFinished(omx_clock, OMX_CommandFlush, omx_clock_output_port) || !video->CommandFinished(omx_aud_rend, OMX_CommandFlush, omx_rend_clock_port)) { - LogNT::getInstance()->debug(TAG, "flush cmd clock shed failed"); + logger->debug(TAG, "flush cmd clock shed failed"); } DestroyInputBufsOMX(); //We have to make sure that no buffers are in use - LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 6a"); + logger->debug(TAG, "deallocatecodecsomx mark 6a"); DeinitDecoderLibAV(); - LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 7"); + logger->debug(TAG, "deallocatecodecsomx mark 7"); //todo flushing if (!video->DisablePort(omx_aud_rend, omx_rend_input_port, true)) { - LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 1"); + logger->debug(TAG, "Disable Tunnel Port failed 1"); } - /* if (!video->DisablePort(omx_aud_dec,omx_codec_output_port,true)) { - LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 6"); - } - - if (!video->DisablePort(omx_aud_dec,omx_codec_input_port,true)) { - LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 7"); - }*/ - - if (!video->DisablePort(omx_aud_rend, omx_rend_clock_port, true)) { - LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 4"); + logger->debug(TAG, "Disable Tunnel Port failed 4"); } if (!video->DisablePort(omx_clock, omx_clock_output_port, true)) { - LogNT::getInstance()->debug(TAG, "Disable Tunnel Port failed 5"); + logger->debug(TAG, "Disable Tunnel Port failed 5"); } - /* error=OMX_SetupTunnel(omx_aud_dec,omx_codec_output_port,NULL,NULL); - if (error!=OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error); - }*/ - error = OMX_SetupTunnel(omx_aud_rend, omx_rend_input_port, NULL, 0); if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error); + logger->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error); } error = OMX_SetupTunnel(omx_clock, omx_clock_output_port, NULL, 0); if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error); + logger->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error); } error = OMX_SetupTunnel(omx_aud_rend, omx_rend_clock_port, NULL, 0); if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error); + logger->debug(TAG, "OMX_Setup tunnel teardown failed {:#x}", error); } - LogNT::getInstance()->debug(TAG, "deallocatecodecsomx mark 8"); + logger->debug(TAG, "deallocatecodecsomx mark 8"); - //error=OMX_FreeHandle(omx_aud_dec); error = OMX_FreeHandle(omx_aud_rend); video->UnlockClock(); video->destroyClock(); @@ -1584,7 +1295,7 @@ int AudioOMX::DeAllocateCodecsOMX() if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "FreeHandle failed {}", error); + logger->debug(TAG, "FreeHandle failed {}", error); } } else @@ -1593,7 +1304,7 @@ int AudioOMX::DeAllocateCodecsOMX() DeinitDecoderLibAV(); } - LogNT::getInstance()->debug(TAG, "leave deallocate codecs OMX"); + logger->debug(TAG, "leave deallocate codecs OMX"); return 1; } @@ -1601,9 +1312,8 @@ int AudioOMX::stop() { if (!initted) return 0; - LogNT::getInstance()->debug(TAG, "Audio stop called"); + logger->debug(TAG, "Audio stop called"); DeAllocateCodecsOMX(); - //if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0; return 1; } @@ -1611,7 +1321,7 @@ int AudioOMX::mute() { if (!initted) return 0; - LogNT::getInstance()->debug(TAG, "MUTE MUTE MUTE"); + logger->debug(TAG, "MUTE MUTE MUTE"); VideoOMX* vw = static_cast(Video::getInstance()); vw->LockClock(); @@ -1624,11 +1334,9 @@ int AudioOMX::mute() amute.nPortIndex = omx_rend_input_port; amute.bMute = OMX_TRUE; OMX_ERRORTYPE error = OMX_SetParameter(omx_aud_rend, OMX_IndexConfigAudioMute, &amute); - if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, - "Set OMX_IndexConfigAudioMute failed {:#x} {}", error, omx_rend_input_port); + logger->debug(TAG, "Set OMX_IndexConfigAudioMute failed {:#x} {}", error, omx_rend_input_port); vw->UnlockClock(); return 0; } @@ -1644,7 +1352,7 @@ int AudioOMX::unMute() { if (!initted) return 0; - LogNT::getInstance()->debug(TAG, "MUTE OFF OFF OFF"); + logger->debug(TAG, "MUTE OFF OFF OFF"); VideoOMX* vw = static_cast(Video::getInstance()); vw->LockClock(); @@ -1660,7 +1368,7 @@ int AudioOMX::unMute() if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Set OMX_IndexConfigAudioMute failed {:#x} {}", error, omx_rend_input_port); + logger->debug(TAG, "Set OMX_IndexConfigAudioMute failed {:#x} {}", error, omx_rend_input_port); vw->UnlockClock(); return 0; } @@ -1694,13 +1402,9 @@ int AudioOMX::reset() { if (!initted) return 0; - LogNT::getInstance()->debug(TAG, "reset called"); + logger->debug(TAG, "reset called"); DeAllocateCodecsOMX(); - // if (ioctl(fdAudio, AV_SET_AUD_RESET, 0x11) != 0) return 0; - // LogNT::getInstance()->debug(TAG, "reset back"); - // if (ioctl(fdAudio, AV_SET_AUD_PLAY, 0) != 0) return 0; - doMuting(); return 1; } @@ -1733,7 +1437,7 @@ int AudioOMX::setVolume(int tvolume) if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Set OMX_IndexConfigAudioVolume failed {:#x} {}", error, omx_rend_input_port); + logger->debug(TAG, "Set OMX_IndexConfigAudioVolume failed {:#x} {}", error, omx_rend_input_port); vw->UnlockClock(); return 0; } @@ -1760,7 +1464,6 @@ unsigned int AudioOMX::AdvanceMpAudioSync(const u1* data, unsigned int size, uns //sanity check inspired by libav - const int sample_rates[4] = {44100, 48000, 32000, 0}; const short bitrate_tab[2][3][15] = { { { 0, 32, 64, 96, 128, 160, @@ -1788,11 +1491,11 @@ unsigned int AudioOMX::AdvanceMpAudioSync(const u1* data, unsigned int size, uns int mpeg2 = 0; int layer = 4 - ((data[atest + 1] & 0x06) >> 1); - if (layer == 4) {atest++; continue;} //sanity check + if (layer == 4) { atest++; continue; } //sanity check int bitrate_index = (data[atest + 2] & 0xf0) >> 4; - if (bitrate_index == 0x0f || bitrate_index == 0x0) {atest++; continue;} //sanity check + if (bitrate_index == 0x0f || bitrate_index == 0x0) { atest++; continue; } //sanity check int samplerate_index = (data[atest + 2] & 0x0C) >> 2; @@ -1845,8 +1548,8 @@ unsigned int AudioOMX::AdvanceMpAudioSync(const u1* data, unsigned int size, uns mp3sameheader = sameheadertest; - //LogNT::getInstance()->debug(TAG, "FRAME: {} {} {} {} {} {} {}",lsf,layer,bitrate_index,sample_rate,padding,temp_frame_size, frame_size); - //LogNT::getInstance()->debug(TAG, "FRAME DIAG: {:#x} {:#x} {:#x} {}",data[atest],data[atest+1],data[atest+2],mp3sameheadercount); + //logger->debug(TAG, "FRAME: {} {} {} {} {} {} {}",lsf,layer,bitrate_index,sample_rate,padding,temp_frame_size, frame_size); + //logger->debug(TAG, "FRAME DIAG: {:#x} {:#x} {:#x} {}",data[atest],data[atest+1],data[atest+2],mp3sameheadercount); if (mp3sameheadercount > 4) { @@ -1882,7 +1585,7 @@ unsigned int AudioOMX::AdvanceAc3AudioSync(const u1* data, unsigned int size, un unsigned char fscod = (code & 0xC0) >> 6; unsigned char frmsize = (code & 0x3f); - if (fscod != 0) LogNT::getInstance()->debug(TAG, "warning we only support 48 KHz sampling rate"); + if (fscod != 0) logger->debug(TAG, "warning we only support 48 KHz sampling rate"); *framesize = frm_size_tab[frmsize] * 2; return atest; // probably FrameSync @@ -1947,18 +1650,16 @@ long long AudioOMX::correctAudioLatency(long long pts, int addsamples, int srate audio_lat.nVersion.nVersion = OMX_VERSION; audio_lat.nPortIndex = omx_rend_input_port; - error = OMX_GetConfig(omx_aud_rend, OMX_IndexConfigAudioRenderingLatency, - &audio_lat); + error = OMX_GetConfig(omx_aud_rend, OMX_IndexConfigAudioRenderingLatency, &audio_lat); video->UnlockClock(); if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "Init OMX_IndexConfigAudioRenderingLatencyfailed {:#x} {}", error, omx_rend_input_port); + logger->debug(TAG, "Init OMX_IndexConfigAudioRenderingLatencyfailed {:#x} {}", error, omx_rend_input_port); return pts; // no correction in case of error } - /*LogNT::getInstance()->debug(TAG, "Current audio latency {}", - audio_lat.nU32);*/ + // logger->debug(TAG, "Current audio latency {}", audio_lat.nU32); long long workpts = 0; workpts += addsamples; @@ -1987,7 +1688,6 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl bool achange = false; OMX_ERRORTYPE error; - //Log *logger=Log::getInstance(); if (vw->InIframemode()) { samplepos = 0; @@ -1999,20 +1699,20 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl if (vw->isClockPaused()) return 0; //Block if we pause - //LogNT::getInstance()->debug(TAG, "DMP mark 1"); + //logger->debug(TAG, "DMP mark 1"); - //LogNT::getInstance()->debug(TAG, "DeliverMediaPacketOMX time {}",mpacket.presentation_time); + //logger->debug(TAG, "DeliverMediaPacketOMX time {}",mpacket.presentation_time); /* if (mpacket.synched && mpacket.presentation_time <= 0) { *samplepos = mpacket.length; firstsynched = false; lsync=true; - LogNT::getInstance()->debug(TAG, + logger->debug(TAG, "DeliverMediaPacketOMX Frameskip"); return mpacket.length; }*/ - //LogNT::getInstance()->debug(TAG, "DMP mark 2"); + //logger->debug(TAG, "DMP mark 2"); u4 headerstrip = 0; @@ -2024,11 +1724,7 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl if (cur_input_buf_omx) { error = vw->ProtOMXEmptyThisBuffer(omx_aud_rend/*dec*/, cur_input_buf_omx); - - if (error != OMX_ErrorNone) - { - LogNT::getInstance()->debug(TAG, "OMX_EmptyThisBuffer 1 failed {:#x}", error); - } + if (error != OMX_ErrorNone) logger->debug(TAG, "OMX_EmptyThisBuffer 1 failed {:#x}", error); cur_input_buf_omx = NULL; } @@ -2036,25 +1732,20 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl lsync = true; } - //LogNT::getInstance()->debug(TAG, "DMP mark 3"); + //logger->debug(TAG, "DMP mark 3"); if (mpacket.type != lastAType) //Format Change //Push data out ! { firstsynched = false; achange = true; mp3sameheader = 0; - LogNT::getInstance()->debug(TAG, "Notice audio type change {} {}", mpacket.type, lastAType); + logger->debug(TAG, "Notice audio type change {} {}", mpacket.type, lastAType); lastAType = mpacket.type; decompress_buffer_filled = 0; if (cur_input_buf_omx) { - error = vw->ProtOMXEmptyThisBuffer(omx_aud_rend/*dec*/, - cur_input_buf_omx); - - if (error != OMX_ErrorNone) - { - LogNT::getInstance()->debug(TAG, "OMX_EmptyThisBuffer 2 failed {:#x}", error); - } + error = vw->ProtOMXEmptyThisBuffer(omx_aud_rend/*dec*/, cur_input_buf_omx); + if (error != OMX_ErrorNone) logger->debug(TAG, "OMX_EmptyThisBuffer 2 failed {:#x}", error); cur_input_buf_omx = NULL; } @@ -2065,10 +1756,7 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype); vw->LockClock(); - if (!ChangeAudioPortConfig(true)) - { - LogNT::getInstance()->debug(TAG, "Changing audio port config failed", error); - } + if (!ChangeAudioPortConfig(true)) logger->debug(TAG, "Changing audio port config failed", error); vw->UnlockClock(); pthread_setcancelstate(oldcancelstate, NULL); @@ -2076,7 +1764,7 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl lsync = true; } - //LogNT::getInstance()->debug(TAG, "DMP mark 4"); + //logger->debug(TAG, "DMP mark 4"); /*Inspect PES-Header */ if (*samplepos == 0 && mpacket.type != MPTYPE_MPEG_AUDIO_LAYER3) //stripheader @@ -2097,7 +1785,7 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl if (error != OMX_ErrorNone) { - LogNT::getInstance()->debug(TAG, "OMX_EmptyThisBuffer 3 failed {:#x}", error); + logger->debug(TAG, "OMX_EmptyThisBuffer 3 failed {:#x}", error); } //vw->AdjustAudioPTS(correctAudioLatency(lastreftimeOMX,cur_input_buf_omx->nFilledLen/(2*2),48000)); @@ -2110,11 +1798,11 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl } else { - if (!firstsynched) // + if (!firstsynched) { *samplepos = mpacket.length;//if we have not processed at least one decompress_buffer_filled = 0; - //LogNT::getInstance()->debug(TAG, "DMP mark 5"); + //logger->debug(TAG, "DMP mark 5"); return mpacket.length;//synched packet ignore it! } } @@ -2127,8 +1815,8 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl if (input_bufs_omx_free.size() == 0) { input_bufs_omx_mutex.unlock(); - //LogNT::getInstance()->debug(TAG, "DMP mark 6"); - //LogNT::getInstance()->debug(TAG, "Deliver MediaPacket no free sample"); + //logger->debug(TAG, "DMP mark 6"); + //logger->debug(TAG, "Deliver MediaPacket no free sample"); return 0; // we do not have a free media sample } @@ -2140,20 +1828,19 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl input_bufs_omx_mutex.unlock(); } - //LogNT::getInstance()->debug(TAG, "DMP mark 7"); + //logger->debug(TAG, "DMP mark 7"); if (cur_input_buf_omx->nFilledLen == 0) //will only be changed on first packet { if (mpacket.synched) { - //LogNT::getInstance()->debug(TAG, - // "packet synched marker"); + //logger->debug(TAG, "packet synched marker"); - //lastreftimePTS=mpacket.pts; + // lastreftimePTS = mpacket.pts; if (omx_first_frame) // TODO time { cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_STARTTIME; - LogNT::getInstance()->debug(TAG, "Starttime"); + logger->debug(TAG, "Starttime"); omx_first_frame = false; } else @@ -2163,15 +1850,13 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl } lastreftimeOMX = mpacket.presentation_time; - //LogNT::getInstance()->debug(TAG, - // "Time code {} pts {} dts {}", lastreftimeOMX, mpacket.pts,mpacket.dts); + // logger->debug(TAG, "Time code {} pts {} dts {}", lastreftimeOMX, mpacket.pts,mpacket.dts); lastreftimePTS = mpacket.pts; cur_input_buf_omx->nTimeStamp = VideoOMX::intToOMXTicks(lastreftimeOMX / 10LL); // the clock component is faulty; } else { - // LogNT::getInstance()->debug(TAG, - // "packet NOT synched marker"); + // logger->debug(TAG, "packet NOT synched marker"); cur_input_buf_omx->nFlags = OMX_BUFFERFLAG_TIME_UNKNOWN; cur_input_buf_omx->nTimeStamp = VideoOMX::intToOMXTicks(0); } @@ -2184,7 +1869,7 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl } } - //LogNT::getInstance()->debug(TAG, "DMP mark 8"); + //logger->debug(TAG, "DMP mark 8"); if (*samplepos > mpacket.length) *samplepos = 0; //propably the thread got interrupted and sample is not valid any more! @@ -2194,7 +1879,7 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl { while (haveToCopy > 0) { - //LogNT::getInstance()->debug(TAG, "DMP mark 9"); + //logger->debug(TAG, "DMP mark 9"); if (lsync) { unsigned int gotframesize = 0; @@ -2204,23 +1889,17 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl { case MPTYPE_MPEG_AUDIO: case MPTYPE_MPEG_AUDIO_LAYER3: - { adv = AdvanceMpAudioSync(buffer + mpacket.pos_buffer + *samplepos, haveToCopy, &gotframesize); - } - break; + break; case MPTYPE_AC3: case MPTYPE_AC3_PRE13: - { adv = AdvanceAc3AudioSync(buffer + mpacket.pos_buffer + *samplepos, haveToCopy, &gotframesize); - } - break; + break; case MPTYPE_AAC_LATM: - { adv = AdvanceAacLatmAudioSync(buffer + mpacket.pos_buffer + *samplepos, haveToCopy, &gotframesize); - } - break; + break; } if (adv != (int)haveToCopy) @@ -2232,7 +1911,7 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl else { *samplepos = mpacket.length; //no ac3 sync byte - //LogNT::getInstance()->debug(TAG, "DMP mark 10"); + //logger->debug(TAG, "DMP mark 10"); return mpacket.length; } } @@ -2243,14 +1922,10 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl haveToCopy -= cancopy; cur_input_buf_omx->nFilledLen += cancopy; *samplepos += cancopy; - //LogNT::getInstance()->debug(TAG, "DMP mark 11"); + //logger->debug(TAG, "DMP mark 11"); error = vw->ProtOMXEmptyThisBuffer(omx_aud_rend/*dec*/, cur_input_buf_omx); - - if (error != OMX_ErrorNone) - { - LogNT::getInstance()->debug(TAG, "OMX_EmptyThisBuffer 5 failed {:#x}", error); - } + if (error != OMX_ErrorNone) logger->debug(TAG, "OMX_EmptyThisBuffer 5 failed {:#x}", error); cur_input_buf_omx = NULL; @@ -2262,7 +1937,7 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl if (input_bufs_omx_free.size() == 0) { input_bufs_omx_mutex.unlock(); - // LogNT::getInstance()->debug(TAG, "Deliver MediaPacket no free sample2"); + // logger->debug(TAG, "Deliver MediaPacket no free sample2"); return *samplepos; // we do not have a free media sample } @@ -2274,13 +1949,9 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl input_bufs_omx_free.pop_front(); input_bufs_omx_mutex.unlock(); } - - //LogNT::getInstance()->debug(TAG, "DMP mark 12"); - + //logger->debug(TAG, "DMP mark 12"); } - - //LogNT::getInstance()->debug(TAG, "DMP mark 13"); - + //logger->debug(TAG, "DMP mark 13"); } else { @@ -2295,34 +1966,29 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl { case MPTYPE_MPEG_AUDIO: case MPTYPE_MPEG_AUDIO_LAYER3: - { current_context = mp23codec_context_libav; - if (current_context->frame_size < 0) framesize = 1152; //Maximum framesize else framesize = current_context->frame_size; - } break; + break; case MPTYPE_AAC_LATM: - { current_context = aaclatmcodec_context_libav; - } break; + break; case MPTYPE_AC3: case MPTYPE_AC3_PRE13: - { current_context = ac3codec_context_libav; - } break; + break; } if (decompress_buffer_filled) // have a remaining paket { incoming_paket_libav.data = (uint8_t*) decompress_buffer; - memcpy(decompress_buffer + decompress_buffer_filled, - buffer + mpacket.pos_buffer + *samplepos, + memcpy(decompress_buffer + decompress_buffer_filled, buffer + mpacket.pos_buffer + *samplepos, std::min(haveToCopy, decompress_buffer_size - decompress_buffer_filled)); incoming_paket_libav.size = decompress_buffer_filled + std::min(haveToCopy, decompress_buffer_size - decompress_buffer_filled); - //LogNT::getInstance()->debug(TAG,"Use saved audio buffer {} {} {}",mpacket.type,decompress_buffer_filled,mpacket.synched); + //logger->debug(TAG,"Use saved audio buffer {} {} {}",mpacket.type,decompress_buffer_filled,mpacket.synched); } else { @@ -2330,12 +1996,12 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl incoming_paket_libav.size = haveToCopy; } - //LogNT::getInstance()->debug(TAG, "DMP mark 18"); + //logger->debug(TAG, "DMP mark 18"); while (haveToCopy > 0 && errcount < 3) { - //LogNT::getInstance()->debug(TAG,"libav in {} {}",framesize,current_context->frame_size); - //LogNT::getInstance()->debug(TAG, "libav in {} {}", + //logger->debug(TAG,"libav in {} {}",framesize,current_context->frame_size); + //logger->debug(TAG, "libav in {} {}", // framesize, current_context->frame_size); bool donotdecompress = false; @@ -2347,26 +2013,17 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl { case MPTYPE_MPEG_AUDIO: case MPTYPE_MPEG_AUDIO_LAYER3: - { - adv = AdvanceMpAudioSync(incoming_paket_libav.data, - incoming_paket_libav.size, &gotframesize); - } - break; + adv = AdvanceMpAudioSync(incoming_paket_libav.data, incoming_paket_libav.size, &gotframesize); + break; case MPTYPE_AC3: case MPTYPE_AC3_PRE13: - { - adv = AdvanceAc3AudioSync(incoming_paket_libav.data, - incoming_paket_libav.size, &gotframesize); - } - break; + adv = AdvanceAc3AudioSync(incoming_paket_libav.data, incoming_paket_libav.size, &gotframesize); + break; case MPTYPE_AAC_LATM: - { - adv = AdvanceAacLatmAudioSync(incoming_paket_libav.data, - incoming_paket_libav.size, &gotframesize); - } - break; + adv = AdvanceAacLatmAudioSync(incoming_paket_libav.data, incoming_paket_libav.size, &gotframesize); + break; } if (adv > 0 /*&& !decompress_buffer_filled*/) @@ -2378,10 +2035,10 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl /*if (current_context->frame_size>0) framesize=min(current_context->frame_size,haveToCopy); else*/ framesize = haveToCopy; - //LogNT::getInstance()->debug(TAG,"Advance by {} {} from {}",adv,mpacket.type,*samplepos ); + //logger->debug(TAG,"Advance by {} {} from {}",adv,mpacket.type,*samplepos ); if (haveToCopy <= 0) { - // LogNT::getInstance()->debug(TAG,"No sync code in packet remove {}",mpacket.type); + // logger->debug(TAG,"No sync code in packet remove {}",mpacket.type); *samplepos = mpacket.length; return mpacket.length; } @@ -2394,10 +2051,10 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl errcount = 100; // exit loop } - // else LogNT::getInstance()->debug(TAG,"Loop run"); + // else logger->debug(TAG,"Loop run"); } - //LogNT::getInstance()->debug(TAG, "DMP mark 19"); + //logger->debug(TAG, "DMP mark 19"); if (!donotdecompress) { int oldcancelstate; @@ -2407,15 +2064,14 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldcanceltype); libav_mutex.lock(); - if (!omx_running || !mp23codec_context_libav - || !ac3codec_context_libav) + if (!omx_running || !mp23codec_context_libav || !ac3codec_context_libav) { libav_mutex.unlock(); return *samplepos; } libav_mutex.unlock(); - // LogNT::getInstance()->debug(TAG,"libav out"); + // logger->debug(TAG,"libav out"); int save_size = incoming_paket_libav.size; if ((int)gotframesize <= incoming_paket_libav.size) @@ -2429,8 +2085,7 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl // 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 = 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); @@ -2438,18 +2093,17 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl } else { - //LogNT::getInstance()->debug(TAG, "FRAME:E {} {}",gotframesize,incoming_paket_libav.size); + //logger->debug(TAG, "FRAME:E {} {}",gotframesize,incoming_paket_libav.size); gotta = 0; len = 0; } - //LogNT::getInstance()->debug(TAG, "FRAME:T {}",len); + //logger->debug(TAG, "FRAME:T {}",len); incoming_paket_libav.size = save_size; - //LogNT::getInstance()->debug(TAG, "libav out1"); + //logger->debug(TAG, "libav out1"); pthread_setcancelstate(oldcancelstate, NULL); pthread_setcanceltype(oldcanceltype, NULL); pthread_testcancel(); - } else { @@ -2457,8 +2111,8 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl len = 0; } - //LogNT::getInstance()->debug(TAG, "libav out2"); - //LogNT::getInstance()->debug(TAG, "DMP mark 20"); + //logger->debug(TAG, "libav out2"); + //logger->debug(TAG, "DMP mark 20"); if (!omx_running) { libav_mutex.unlock(); @@ -2467,60 +2121,7 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl if (decompress_buffer_filled) // reset to normal decoding { - if (len > 0) - { - // FIXME - - // len is int - // decompress_buffer_filled is unsigned int - // so if decompress_buffer_filled > len, len can go negative. - - // Why would you use a min function with one of the values hard coded to zero? - // If param1 is positive the result is always 0. - // If param1 is negative the result is always param1. - // However, badMinimumFunction is and always was: int badMinimumFunction(u4 a, int b) - // .. which takes param1 as unsigned. So whatever param1 is, the result is always 0. - - // A guess is that the intention was to try to calculate a positive result, but if - // for some reason len-decompress_buffer_filled < 0, return 0. - // But for that you would use a max() function... - - //haveToCopy -= badMinimumFunction(len - decompress_buffer_filled, 0); - //*samplepos += badMinimumFunction(len - decompress_buffer_filled, 0); - - //int result = badMinimumFunction(len - decompress_buffer_filled, 0); - //LogNT::getInstance()->debug(TAG, "RESULT : {}", result); - //haveToCopy -= result; - //*samplepos += result; - - //abort(); // When does this run? - // 18 months later... This abort finally triggered. There now seems to be some channels which trigger this. - // It's when there's not enough data to decode. This particular bit of code is after this half block - // situation has occured, there is code above which glues the old saved data to new input and runs that - // through libav. This is the cleanup code after this has happened. But - as it was written it never did - // anything. haveToCopy and *samplepos were not moved. However - it works !! Why?? Is it leaking somehow? - // Removing the abort - // Removing the badMinimumFunction - // Commenting out the above lines which move haveToCopy and *samplepos - // Figure out in a future refactor if this needs further fixing - - - // len is always either 0 or the result of avcodec_decode_audio4(current_context, decode_frame_libav, &gotta, &incoming_paket_libav); - // the result of avcodec_decode_audio4 can be negative in case of error, but that is filtered out above - - // decompress_buffer_filled appears to be how much of the decompress buffer has already been written to. - // Presumably things can happen in multiple chunks. - - - //if (current_context->frame_size>0) framesize=min(current_context->frame_size,haveToCopy); - /*else*/ framesize = haveToCopy; - - } - else - { - framesize = haveToCopy; - } - + framesize = haveToCopy; incoming_paket_libav.data = (uint8_t*) buffer + mpacket.pos_buffer + *samplepos; errcount = 0; decompress_buffer_filled = 0; @@ -2543,14 +2144,13 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl } } - //LogNT::getInstance()->debug(TAG, "DMP mark 21"); + //logger->debug(TAG, "DMP mark 21"); incoming_paket_libav.size = framesize; if (gotta) { - //LogNT::getInstance()->debug(TAG, - // "Got a frame"); + //logger->debug(TAG, "Got a frame"); int dsize = av_samples_get_buffer_size(NULL, /*current_context->channels*/2, decode_frame_libav->nb_samples, @@ -2563,13 +2163,10 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl if ((cur_input_buf_omx->nFilledLen + dsize) > cur_input_buf_omx->nAllocLen) { // I doubt that this will ever happen - // LogNT::getInstance()->debug(TAG, + // logger->debug(TAG, // "P 2 Time code {} pts {}", lastreftimeOMX, mpacket.pts); error = vw->ProtOMXEmptyThisBuffer(omx_aud_rend/*dec*/, cur_input_buf_omx); - if (error != OMX_ErrorNone) - { - LogNT::getInstance()->debug(TAG, "OMX_EmptyThisBuffer 4 failed {:#x}", error); - } + if (error != OMX_ErrorNone) logger->debug(TAG, "OMX_EmptyThisBuffer 4 failed {:#x}", error); cur_input_buf_omx = NULL; @@ -2585,14 +2182,13 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl if (input_bufs_omx_free.size() == 0) { input_bufs_omx_mutex.unlock(); - // LogNT::getInstance()->debug(TAG, - // "Deliver MediaPacket no free sample"); + // logger->debug(TAG, "Deliver MediaPacket no free sample"); MILLISLEEP(5); - //LogNT::getInstance()->debug(TAG, "DMP mark22"); + //logger->debug(TAG, "DMP mark22"); if (!omx_running) return *samplepos; - //LogNT::getInstance()->debug(TAG, "DMP mark 23"); + //logger->debug(TAG, "DMP mark 23"); continue; } @@ -2610,99 +2206,64 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, u4* sampl } } - //LogNT::getInstance()->debug(TAG,"memcpy in {} {} {}" ,dsize,current_context->sample_rate,cur_input_buf_omx->nFilledLen); - + //logger->debug(TAG,"memcpy in {} {} {}" ,dsize,current_context->sample_rate,cur_input_buf_omx->nFilledLen); av_opt_set_int(resam_con_libav, "in_sample_rate", decode_frame_libav->sample_rate, 0); av_opt_set_int(resam_con_libav, "in_sample_fmt", decode_frame_libav->format, 0); av_opt_set_int(resam_con_libav, "in_channel_layout", decode_frame_libav->channel_layout, 0); - //LogNT::getInstance()->error(TAG, "AV resampledata {} {} {} {}",current_context->channels,current_context->sample_rate,current_context->sample_fmt,current_context->channel_layout); - //LogNT::getInstance()->error(TAG, "AV resampledata2 {} {} {}",decode_frame_libav->sample_rate,decode_frame_libav->format,decode_frame_libav->channel_layout); + //logger->error(TAG, "AV resampledata {} {} {} {}",current_context->channels,current_context->sample_rate,current_context->sample_fmt,current_context->channel_layout); + //logger->error(TAG, "AV resampledata2 {} {} {}",decode_frame_libav->sample_rate,decode_frame_libav->format,decode_frame_libav->channel_layout); int ret = swr_init(resam_con_libav); if (ret < 0) { - LogNT::getInstance()->error(TAG, "Opening AV resample failed {}", ret); + logger->error(TAG, "Opening AV resample failed {}", ret); } else { uint8_t* output = cur_input_buf_omx->pBuffer + cur_input_buf_omx->nFilledLen; - /* - * 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: - */ - //LogNT::getInstance()->debug(TAG, "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); } - //LogNT::getInstance()->debug(TAG,"memcpy out"); cur_input_buf_omx->nFilledLen += dsize; } else { - //LogNT::getInstance()->debug(TAG,"Incomplete mpeg frames in pes packet {} {}",incoming_paket_libav.size,mpacket.length); + //logger->debug(TAG,"Incomplete mpeg frames in pes packet {} {}",incoming_paket_libav.size,mpacket.length); /* uint8_t a1=incoming_paket_libav.data[0]; uint8_t a2=incoming_paket_libav.data[1]; uint8_t a3=incoming_paket_libav.data[2]; uint8_t a4=incoming_paket_libav.data[3];*/ - // LogNT::getInstance()->debug(TAG,"Header {:#x} {:#x} {:#x} {:#x}",a1,a2, + // logger->debug(TAG,"Header {:#x} {:#x} {:#x} {:#x}",a1,a2, // a3,a4); } - } - //LogNT::getInstance()->debug(TAG, "DMP mark 24"); + //logger->debug(TAG, "DMP mark 24"); decompress_buffer_filled = 0; if (haveToCopy) { - //LogNT::getInstance()->debug(TAG,"We can not decompress {} save for later {} {:#x} {:#x}",haveToCopy,mpacket.type,incoming_paket_libav.data,mpacket.pos_buffer); + //logger->debug(TAG,"We can not decompress {} save for later {} {:#x} {:#x}",haveToCopy,mpacket.type,incoming_paket_libav.data,mpacket.pos_buffer); memcpy(decompress_buffer, incoming_paket_libav.data, std::min(haveToCopy, decompress_buffer_size)); decompress_buffer_filled = std::min(haveToCopy, decompress_buffer_size); } if (cur_input_buf_omx->nFilledLen) { - //LogNT::getInstance()->debug(TAG, - // "P 3 Time code {} pts {}", lastreftimeOMX, mpacket.pts); + //logger->debug(TAG, "P 3 Time code {} pts {}", lastreftimeOMX, mpacket.pts); error = vw->ProtOMXEmptyThisBuffer(omx_aud_rend/*dec*/, cur_input_buf_omx); - if (error != OMX_ErrorNone) - { - LogNT::getInstance()->debug(TAG, "OMX_EmptyThisBuffer 5 failed {:#x}", error); - } + if (error != OMX_ErrorNone) logger->debug(TAG, "OMX_EmptyThisBuffer 5 failed {:#x}", error); //if (mpacket.synched) vw->AdjustAudioPTS(correctAudioLatency(lastreftimeOMX,cur_input_buf_omx->nFilledLen/(2*2),48000)); cur_input_buf_omx = NULL; } } - //LogNT::getInstance()->debug(TAG, "DMP mark 25"); + //logger->debug(TAG, "DMP mark 25"); *samplepos = mpacket.length; return mpacket.length; @@ -2720,16 +2281,6 @@ void AudioOMX::ResetTimeOffsets() vw->ResetTimeOffsets(); } -/* -int AudioOMX::badMinimumFunction(u4 a, int b) -{ - printf("MIN: P1: %u, P2: %i\n", a, 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 @@ -2759,3 +2310,4 @@ int AudioOMX::DO_NOT_USE(AVCodecContext* avctx, // used - sent to avcodec_sen // error return -9999; // no idea. looks like calling code checks got_frame_ptr } +//2762 diff --git a/src/audioomx.h b/src/audioomx.h index 45b4f49..5f277eb 100644 --- a/src/audioomx.h +++ b/src/audioomx.h @@ -96,45 +96,42 @@ class AudioOMX : public Audio bool handleOptionChanges(Option* option); private: + LogNT* logger; + int initAllParams(); - u1 streamType; + u1 streamType{}; u1 lastAType; bool firstsynched; MediaPacket packet; u4 packetpos; - bool hdmi; // use hdmi as audio output + bool hdmi{true}; // use hdmi as audio output bool passthrough; // use audio passthrough for the current audio type - bool canpass_aac; - bool canpass_ac3; - bool canpass_mp2; - bool canpass_mp3; - bool canpass_pcm_mch; - - int prefered_aac; - int prefered_ac3; //0 stereo PCM, 1 passthrough 2 Multichannel PCM - int prefered_mp2; - int prefered_mp3; + bool canpass_aac{}; + bool canpass_ac3{}; + bool canpass_mp2{}; + bool canpass_mp3{}; + bool canpass_pcm_mch{}; + int prefered_aac{}; + int prefered_ac3{}; //0 stereo PCM, 1 passthrough 2 Multichannel PCM + int prefered_mp2{}; + int prefered_mp3{}; static OMX_ERRORTYPE EmptyBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata, OMX_IN OMX_BUFFERHEADERTYPE* bulibaver); static OMX_ERRORTYPE FillBufferDone_OMX(OMX_IN OMX_HANDLETYPE hcomp, OMX_IN OMX_PTR appdata, OMX_IN OMX_BUFFERHEADERTYPE* bulibaver); - unsigned int AdvanceAc3AudioSync(const u1* data, unsigned int size, unsigned int* framesize); unsigned int AdvanceAacLatmAudioSync(const u1* data, unsigned int size, unsigned int* framesize); unsigned int AdvanceMpAudioSync(const u1* data, unsigned int size, unsigned int* framesize); void ReturnEmptyOMXBuffer(OMX_BUFFERHEADERTYPE* bulibaver); - // OMX_HANDLETYPE omx_aud_dec; - OMX_HANDLETYPE omx_aud_rend; + OMX_HANDLETYPE omx_aud_rend{}; OMX_HANDLETYPE omx_clock; - //OMX_U32 omx_codec_input_port; - //OMX_U32 omx_codec_output_port; OMX_U32 omx_rend_input_port; OMX_U32 omx_rend_clock_port; OMX_U32 omx_clock_output_port; @@ -142,7 +139,6 @@ class AudioOMX : public Audio long long lastreftimeOMX; u8 lastreftimePTS; - int AllocateCodecsOMX(); int DeAllocateCodecsOMX(); @@ -157,39 +153,35 @@ class AudioOMX : public Audio std::vector input_bufs_omx_all; std::list input_bufs_omx_free; std::mutex input_bufs_omx_mutex; - OMX_BUFFERHEADERTYPE* cur_input_buf_omx; + OMX_BUFFERHEADERTYPE* cur_input_buf_omx{}; - bool omx_running; + bool omx_running{}; bool omx_first_frame; std::mutex libav_mutex; AVCodec* aaclatmcodec_libav; AVCodecContext* aaclatmcodec_context_libav; - AVCodec* ac3codec_libav; - AVCodecContext* ac3codec_context_libav; - AVCodec* mp23codec_libav; - AVCodecContext* mp23codec_context_libav; + AVCodec* ac3codec_libav{}; + AVCodecContext* ac3codec_context_libav{}; + AVCodec* mp23codec_libav{}; + AVCodecContext* mp23codec_context_libav{}; AVPacket incoming_paket_libav; AVFrame* decode_frame_libav; - SwrContext* resam_con_libav; + SwrContext* resam_con_libav{}; - - u1* decompress_buffer; - unsigned int decompress_buffer_size; - unsigned int decompress_buffer_filled; + u1* decompress_buffer{}; + unsigned int decompress_buffer_size{}; + unsigned int decompress_buffer_filled{}; bool lsync; - unsigned int mp3sameheader; - int mp3sameheadercount; - + unsigned int mp3sameheader{}; + int mp3sameheadercount{}; int InitDecoderLibAV(); void DeinitDecoderLibAV(); char L_VPE_OMX_AUDIO_REND[128]; - // int badMinimumFunction(u4 a, int b); - int DO_NOT_USE(AVCodecContext* avctx, AVFrame* frame, int* got_frame_ptr, const AVPacket* avpkt); }; -- 2.39.5