mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-26 15:02:56 +02:00
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 is contained in:
@@ -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<OpenThreads::Mutex> 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);
|
||||
|
@@ -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<t_channel_id, CStreamInstance*> streammap_pair_t;
|
||||
|
Reference in New Issue
Block a user