From abb840b48c019cfe8c85037d1585261f2eb44b86 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sat, 21 Dec 2024 22:14:13 +0100 Subject: [PATCH] Refactor: Adjust `Send` and `write_packet` methods for compatibility with newer FFmpeg versions - Added conditional compilation for `LIBAVFORMAT_VERSION_INT` to handle differences in FFmpeg API versions. - Updated `Send` method to use `const unsigned char*` for compatibility - Refactored `write_packet` to use `const uint8_t*` for consistency with the newer FFmpeg API. Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/36566bbeba1124fba9ce9efa00b693f9b1abd093 Author: Thilo Graf Date: 2024-12-21 (Sat, 21 Dec 2024) Origin message was: ------------------ Refactor: Adjust `Send` and `write_packet` methods for compatibility with newer FFmpeg versions - Added conditional compilation for `LIBAVFORMAT_VERSION_INT` to handle differences in FFmpeg API versions. - Updated `Send` method to use `const unsigned char*` for compatibility - Refactored `write_packet` to use `const uint8_t*` for consistency with the newer FFmpeg API. ------------------ This commit was generated by Migit --- src/driver/streamts.cpp | 41 +++++++++++++++++++++++++++++++---------- src/driver/streamts.h | 13 ++++++++++--- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/driver/streamts.cpp b/src/driver/streamts.cpp index 6baa0be70..bb0e856b7 100644 --- a/src/driver/streamts.cpp +++ b/src/driver/streamts.cpp @@ -113,31 +113,48 @@ bool CStreamInstance::Stop() running = false; return (OpenThreads::Thread::join() == 0); } - -bool CStreamInstance::Send(ssize_t r, unsigned char * _buf) +#if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(59, 27, 100) +bool CStreamInstance::Send(ssize_t r, const unsigned char *_buf) +#else +bool CStreamInstance::Send(ssize_t r, unsigned char * _buf) +#endif { - //OpenThreads::ScopedLock m_lock(mutex); + // 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; - for (stream_fds_t::iterator it = cfds.begin(); it != cfds.end(); ++it) { + + // iterate through all client sockets + for (auto it = cfds.begin(); it != cfds.end(); ++it) + { int i = 10; - unsigned char *b = _buf ? _buf : buf; + + // use a const pointer here to avoid conversion errors + const unsigned char *b = _buf ? _buf : buf; ssize_t count = r; - do { + + do + { + // 'send' takes a const void*, so no cast needed int ret = send(*it, b, count, flags); - if (ret > 0) { - b += ret; - count -= ret; + 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("send err, fd %d: (%zd from %zd)\n", *it, r-count, r); + printf("CStreamInstance::%s: send error, fd %d: (%zd from %zd)\n", __FUNCTION__, *it, r - count, r); + } + return true; } @@ -803,7 +820,11 @@ CStreamStream::~CStreamStream() Close(); } +#if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(59, 27, 100) +int CStreamStream::write_packet(void *opaque, const uint8_t *buffer, int buf_size) +#else int CStreamStream::write_packet(void *opaque, uint8_t *buffer, int buf_size) +#endif { CStreamStream * st = (CStreamStream *) opaque; st->Send(buf_size, buffer); diff --git a/src/driver/streamts.h b/src/driver/streamts.h index 33221f0b7..5d43d2b4b 100644 --- a/src/driver/streamts.h +++ b/src/driver/streamts.h @@ -54,8 +54,11 @@ class CStreamInstance : public OpenThreads::Thread t_channel_id channel_id; stream_pids_t pids; stream_fds_t fds; - - virtual bool Send(ssize_t r, unsigned char * _buf = NULL); +#if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(59, 27, 100) + virtual bool Send(ssize_t r, const unsigned char * _buf = NULL); +#else + virtual bool Send(ssize_t r, unsigned char * _buf = NULL); +#endif virtual void Close(); virtual void run(); friend class CStreamManager; @@ -99,7 +102,11 @@ class CStreamStream : public CStreamInstance bool Stop(); static int Interrupt(void * data); - static int write_packet(void *opaque, uint8_t *buf, int buf_size); +#if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(59, 27, 100) + static int write_packet(void *opaque, const uint8_t *buffer, int buf_size); +#else + static int write_packet(void *opaque, uint8_t *buffer, int buf_size); +#endif }; typedef std::pair streammap_pair_t;