mirror of
https://github.com/LX3JL/xlxd.git
synced 2025-12-06 07:42:01 +01:00
Second patch in the improve-shutdown series. This replaces blocking
sleeps with the use of condition variables for signaling thread
shutdown. The details are:
(1) Create CSimpleCondition class to provide a very basic (simple)
condition variable that can be used in situations where external
mutex control is not required, i.e., the class contains both a
managed mutex and condition variable. Instances of this class
can be used for basic signaling, and waiters can specify user
defined predicates.
(2) Replace instances of large sleeps in worker threads with use of
CSimpleCondition. This allows for very quick response times from
worker threads when a shutdown has been initiated.
(3) Change stop thread booleans to atomic_bool.
(4) Fixes small whitespace discprencies.
111 lines
3.1 KiB
C++
111 lines
3.1 KiB
C++
//
|
|
// ctranscoder.h
|
|
// xlxd
|
|
//
|
|
// Created by Jean-Luc Deltombe (LX3JL) on 13/04/2017.
|
|
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
|
//
|
|
// ----------------------------------------------------------------------------
|
|
// This file is part of xlxd.
|
|
//
|
|
// xlxd is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// xlxd is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
// ----------------------------------------------------------------------------
|
|
|
|
#ifndef ctranscoder_h
|
|
#define ctranscoder_h
|
|
|
|
#include "csemaphore.h"
|
|
#include "ccodecstream.h"
|
|
#include "cudpsocket.h"
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
// define
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
// class
|
|
|
|
class CPacketStream;
|
|
|
|
class CTranscoder
|
|
{
|
|
public:
|
|
// constructor
|
|
CTranscoder();
|
|
|
|
// destructor
|
|
virtual ~CTranscoder();
|
|
|
|
// initialization
|
|
bool Init(void);
|
|
void Close(void);
|
|
|
|
// locks
|
|
void Lock(void) { m_Mutex.lock(); }
|
|
void Unlock(void) { m_Mutex.unlock(); }
|
|
|
|
// status
|
|
bool IsConnected(void) const { return m_bConnected; }
|
|
|
|
// manage streams
|
|
CCodecStream *GetStream(CPacketStream *, uint8);
|
|
void ReleaseStream(CCodecStream *);
|
|
|
|
// task
|
|
static void Thread(CTranscoder *);
|
|
void Task(void);
|
|
|
|
protected:
|
|
// keepalive helpers
|
|
void HandleKeepalives(void);
|
|
|
|
// packet decoding helpers
|
|
bool IsValidKeepAlivePacket(const CBuffer &);
|
|
bool IsValidStreamDescrPacket(const CBuffer &, uint16 *, uint16 *);
|
|
bool IsValidNoStreamAvailablePacket(const CBuffer&);
|
|
|
|
// packet encoding helpers
|
|
void EncodeKeepAlivePacket(CBuffer *);
|
|
void EncodeOpenstreamPacket(CBuffer *, uint8, uint8);
|
|
void EncodeClosestreamPacket(CBuffer *, uint16);
|
|
|
|
protected:
|
|
// streams
|
|
std::mutex m_Mutex;
|
|
std::vector<CCodecStream *> m_Streams;
|
|
|
|
// sync objects for Openstream
|
|
CSemaphore m_SemaphoreOpenStream;
|
|
bool m_bStreamOpened;
|
|
uint16 m_StreamidOpenStream;
|
|
uint16 m_PortOpenStream;
|
|
|
|
// thread
|
|
std::atomic_bool m_bStopThread;
|
|
std::thread *m_pThread;
|
|
|
|
// socket
|
|
CIp m_Ip;
|
|
CUdpSocket m_Socket;
|
|
bool m_bConnected;
|
|
|
|
// time
|
|
CTimePoint m_LastKeepaliveTime;
|
|
CTimePoint m_LastActivityTime;
|
|
};
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
#endif /* ctranscoder_h */
|