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,48 +113,35 @@ 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
// OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
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)
{
for (stream_fds_t::iterator 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
do {
int ret = send(*it, b, count, flags);
if (ret > 0)
{
b += ret; // move pointer further
count -= ret; // reduce remaining bytes
if (ret > 0) {
b += ret;
count -= ret;
}
} 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);
printf("send err, fd %d: (%zd from %zd)\n", *it, r-count, r);
}
return true;
}