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.
This commit is contained in:
2025-03-10 19:42:31 +01:00
parent afe0b116c0
commit df3574bad5

View File

@@ -113,49 +113,36 @@ bool CStreamInstance::Stop()
running = false; running = false;
return (OpenThreads::Thread::join() == 0); return (OpenThreads::Thread::join() == 0);
} }
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(61, 1, 100) #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(61, 1, 100)
bool CStreamInstance::Send(ssize_t r, const unsigned char *_buf) bool CStreamInstance::Send(ssize_t r, const unsigned char *_buf)
#else #else
bool CStreamInstance::Send(ssize_t r, unsigned char * _buf) bool CStreamInstance::Send(ssize_t r, unsigned char * _buf)
#endif #endif
{ {
// lock fds for thread-safety // OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
stream_fds_t cfds; stream_fds_t cfds;
mutex.lock(); mutex.lock();
cfds = fds; cfds = fds;
mutex.unlock(); mutex.unlock();
int flags = 0;
int flags = 0; if (cfds.size() > 1)
if (cfds.size() > 1) flags = MSG_DONTWAIT;
flags = MSG_DONTWAIT; for (stream_fds_t::iterator it = cfds.begin(); it != cfds.end(); ++it) {
int i = 10;
// iterate through all client sockets const unsigned char *b = _buf ? _buf : buf;
for (auto it = cfds.begin(); it != cfds.end(); ++it) ssize_t count = r;
{ do {
int i = 10; int ret = send(*it, b, count, flags);
if (ret > 0) {
// use a const pointer here to avoid conversion errors b += ret;
const unsigned char *b = _buf ? _buf : buf; count -= ret;
ssize_t count = r; }
} while ((count > 0) && (i-- > 0));
do if (count)
{ printf("send err, fd %d: (%zd from %zd)\n", *it, r-count, r);
// 'send' takes a const void*, so no cast needed }
int ret = send(*it, b, count, flags); return true;
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;
} }
void CStreamInstance::Close() void CStreamInstance::Close()