From ce2bd112686dc87d548d6d9b0bd92c692f856b52 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 15 Aug 2022 15:59:24 +0000 Subject: [PATCH] Remove obsolete min(). But... Keep in AudioOMX as badMinimumFunction(). There is a broken usage that needs investigating. --- src/audioomx.cc | 59 +++++++++++++++++++++++++++++++++++++-------- src/audioomx.h | 2 ++ src/defines.h | 1 - src/demuxerts.cc | 2 +- src/util.cc | 7 ------ src/util.h | 3 --- src/wpictureview.cc | 4 +-- src/wtextbox.cc | 4 +-- 8 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/audioomx.cc b/src/audioomx.cc index ece2aa7..4cc0438 100644 --- a/src/audioomx.cc +++ b/src/audioomx.cc @@ -1996,8 +1996,8 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, } } // so everything is fine now do a memcpy - int cancopy=min(haveToCopy,cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen); - memcpy(cur_input_buf_omx->pBuffer+cur_input_buf_omx->nFilledLen,buffer+mpacket.pos_buffer+*samplepos,cancopy); + int cancopy = std::min(haveToCopy, cur_input_buf_omx->nAllocLen-cur_input_buf_omx->nFilledLen); + memcpy(cur_input_buf_omx->pBuffer + cur_input_buf_omx->nFilledLen, buffer + mpacket.pos_buffer + *samplepos, cancopy); haveToCopy-=cancopy; cur_input_buf_omx->nFilledLen+=cancopy; *samplepos+=cancopy; @@ -2057,9 +2057,9 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, incoming_paket_libav.data =(uint8_t*) decompress_buffer; memcpy(decompress_buffer+decompress_buffer_filled, buffer+mpacket.pos_buffer+*samplepos, - min(haveToCopy,decompress_buffer_size-decompress_buffer_filled)); + std::min(haveToCopy,decompress_buffer_size-decompress_buffer_filled)); incoming_paket_libav.size = decompress_buffer_filled - +min(haveToCopy,decompress_buffer_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); } else { incoming_paket_libav.data =(uint8_t*) buffer+mpacket.pos_buffer+*samplepos; @@ -2165,12 +2165,42 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, if (decompress_buffer_filled) { // reset to normal decoding if (len>0) { - //LogNT::getInstance()->debug(TAG,"saved audio: {}",len); - haveToCopy -= min(len-decompress_buffer_filled,0); - *samplepos += min(len-decompress_buffer_filled,0); + // 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); + haveToCopy -= result; + *samplepos += result; + + abort(); // When does this run? + + + // 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 { + } + else + { framesize=haveToCopy; } incoming_paket_libav.data =(uint8_t*) buffer+mpacket.pos_buffer+*samplepos; @@ -2309,9 +2339,9 @@ u4 AudioOMX::DeliverMediaPacket(MediaPacket mpacket, const u1* buffer, 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); - memcpy(decompress_buffer,incoming_paket_libav.data,min(haveToCopy,decompress_buffer_size)); + memcpy(decompress_buffer,incoming_paket_libav.data, std::min(haveToCopy,decompress_buffer_size)); - decompress_buffer_filled=min(haveToCopy,decompress_buffer_size); + decompress_buffer_filled=std::min(haveToCopy,decompress_buffer_size); } @@ -2347,3 +2377,12 @@ void AudioOMX::ResetTimeOffsets() VideoOMX* vw = dynamic_cast(Video::getInstance()); 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; +} diff --git a/src/audioomx.h b/src/audioomx.h index c36314c..9e4146d 100644 --- a/src/audioomx.h +++ b/src/audioomx.h @@ -197,6 +197,8 @@ class AudioOMX : public Audio char L_VPE_OMX_AUDIO_REND[128]; + + int badMinimumFunction(u4 a, int b); }; #endif diff --git a/src/defines.h b/src/defines.h index 3b0951b..3e6e806 100644 --- a/src/defines.h +++ b/src/defines.h @@ -92,7 +92,6 @@ int getClockRealTime(struct timespec *tp); #else - int min(u4, int); /*#ifdef _MIPS_ARCH #define Surface_TYPE SurfaceDirectFB #else diff --git a/src/demuxerts.cc b/src/demuxerts.cc index 2ec0ef1..715cfc6 100644 --- a/src/demuxerts.cc +++ b/src/demuxerts.cc @@ -964,7 +964,7 @@ u4 DemuxerTS::stripAudio(u1* buf, u4 len) //it has to be adapted continue; } readpos += (TS_SIZE - datalen); - u4 towrite=min(datalen,len-readpos); + u4 towrite=std::min(datalen,toi4(len-readpos)); if (pid == vID) { if (payload) { if (started) { diff --git a/src/util.cc b/src/util.cc index c98526d..92d4a1c 100644 --- a/src/util.cc +++ b/src/util.cc @@ -121,13 +121,6 @@ u8 ntohll(u8 a) */ - -int min(u4 a, int b) -{ - if (a > b) return b; - else return a; -} - i8 getTimeMS() { struct timespec ts; diff --git a/src/util.h b/src/util.h index bc75c4d..5be86e3 100644 --- a/src/util.h +++ b/src/util.h @@ -33,7 +33,4 @@ i8 getTimeMS(); //u8 htonll(u8 a); //u8 ntohll(u8 a); -[[deprecated]] -int min(u4 a, int b); - #endif diff --git a/src/wpictureview.cc b/src/wpictureview.cc index 423c587..87d312f 100644 --- a/src/wpictureview.cc +++ b/src/wpictureview.cc @@ -193,12 +193,12 @@ bool WPictureView::mouseAndroidScroll(int x, int y, int /* sx */, int sy) { int change = -sy / 120; if (change < 0) { - int rel_change = min(cur_scroll_line, -change); + int rel_change = std::min(cur_scroll_line, tou4(-change)); cur_scroll_line -= rel_change; rem_scroll_line += rel_change; } else if (change > 0) { - int rel_change = min(rem_scroll_line, change); + int rel_change = std::min(rem_scroll_line, tou4(change)); cur_scroll_line += rel_change; rem_scroll_line -= rel_change; } diff --git a/src/wtextbox.cc b/src/wtextbox.cc index 8d6eec4..7a53073 100644 --- a/src/wtextbox.cc +++ b/src/wtextbox.cc @@ -125,13 +125,13 @@ bool WTextbox::mouseAndroidScroll(int x, int y, int /* sx */, int sy) int change = -sy /120; if (change < 0) { - int rel_change = min(cur_scroll_line, -change); + int rel_change = std::min(cur_scroll_line, tou4(-change)); cur_scroll_line-=rel_change; rem_scroll_line+=rel_change; } else if (change > 0) { - int rel_change = min(rem_scroll_line, change); + int rel_change = std::min(rem_scroll_line, tou4(change)); cur_scroll_line += rel_change; rem_scroll_line -= rel_change; } -- 2.39.5