From df3574bad593008071835c274b464510282ff666 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Mon, 10 Mar 2025 19:42:31 +0100 Subject: [PATCH] streamts: Fix const-correctness issues in Send() and write_packet() - Change Send() parameter from unsigned char* to const unsigned char*. - Update write_packet() to accept const uint8_t*. - Fix invalid conversion error with GCC 14. Confirmed working by building generic neutrino with GCC 14. --- src/driver/streamts.cpp | 61 ++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/src/driver/streamts.cpp b/src/driver/streamts.cpp index 8c6e19094..eb4115fe7 100644 --- a/src/driver/streamts.cpp +++ b/src/driver/streamts.cpp @@ -113,49 +113,36 @@ bool CStreamInstance::Stop() running = false; return (OpenThreads::Thread::join() == 0); } + #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(61, 1, 100) bool CStreamInstance::Send(ssize_t r, const unsigned char *_buf) #else bool CStreamInstance::Send(ssize_t r, unsigned char * _buf) #endif { - // lock fds for thread-safety - stream_fds_t cfds; - mutex.lock(); - cfds = fds; - mutex.unlock(); - - int flags = 0; - if (cfds.size() > 1) - flags = MSG_DONTWAIT; - - // iterate through all client sockets - for (auto it = cfds.begin(); it != cfds.end(); ++it) - { - int i = 10; - - // use a const pointer here to avoid conversion errors - const unsigned char *b = _buf ? _buf : buf; - ssize_t count = r; - - do - { - // 'send' takes a const void*, so no cast needed - int ret = send(*it, b, count, flags); - if (ret > 0) - { - b += ret; // move pointer further - count -= ret; // reduce remaining bytes - } - } while ((count > 0) && (i-- > 0)); - - // if count didn't drop to zero, there was some error - if (count) - printf("CStreamInstance::%s: send error, fd %d: (%zd from %zd)\n", __FUNCTION__, *it, r - count, r); - - } - - return true; + // OpenThreads::ScopedLock m_lock(mutex); + stream_fds_t cfds; + mutex.lock(); + cfds = fds; + mutex.unlock(); + int flags = 0; + if (cfds.size() > 1) + flags = MSG_DONTWAIT; + for (stream_fds_t::iterator it = cfds.begin(); it != cfds.end(); ++it) { + int i = 10; + const unsigned char *b = _buf ? _buf : buf; + ssize_t count = r; + do { + int ret = send(*it, b, count, flags); + if (ret > 0) { + b += ret; + count -= ret; + } + } while ((count > 0) && (i-- > 0)); + if (count) + printf("send err, fd %d: (%zd from %zd)\n", *it, r-count, r); + } + return true; } void CStreamInstance::Close()