115 lines
3.1 KiB
C++
115 lines
3.1 KiB
C++
#ifndef F2B5C47C_73F6_4CFD_A4D6_9C8A1CFB55F5
|
|
#define F2B5C47C_73F6_4CFD_A4D6_9C8A1CFB55F5
|
|
/*
|
|
*******************************************************************************
|
|
* INCLUDE
|
|
*******************************************************************************
|
|
*/
|
|
#include "../core/Muxer.h"
|
|
#include "util/ClassAssistant.h"
|
|
#include <sdk/include/sockutil.h>
|
|
#include <media-server/librtmp/rtmp-client.h>
|
|
#include <media-server/libflv/flv-muxer.h>
|
|
|
|
/*
|
|
*******************************************************************************
|
|
* MACROS
|
|
*******************************************************************************
|
|
*/
|
|
#define TRACE_VIDEO_FRAME_RATE (0)
|
|
|
|
namespace Video
|
|
{
|
|
namespace MediaServer
|
|
{
|
|
/*
|
|
*******************************************************************************
|
|
* CLASS DECLARE
|
|
*******************************************************************************
|
|
*/
|
|
class RTMPMuxer: public Core::Muxer
|
|
{
|
|
private:
|
|
class Stream
|
|
{
|
|
public:
|
|
using Ptr = Poco::SharedPtr<Stream>;
|
|
|
|
public:
|
|
Stream(const std::string& name, Core::CodecID codecID, Core::PacketQueue::Ptr pQueue);
|
|
~Stream();
|
|
|
|
public:
|
|
bool operator<(const Stream& other);
|
|
|
|
const std::string name() const;
|
|
|
|
Core::PacketQueue::Ptr queue();
|
|
Core::SerialCodeWatcher& serialCodeWatcher();
|
|
Core::CodecID codecID() const;
|
|
|
|
int muxer(flv_muxer_t* muxer, const void* data, size_t bytes, uint32_t pts, uint32_t dts);
|
|
|
|
PROPERTY_DECLARE(Timeline, uint64_t, 0, public, public);
|
|
|
|
private:
|
|
const std::string _name;
|
|
Core::CodecID _codecID;
|
|
Core::PacketQueue::Ptr _pQueue;
|
|
Core::SerialCodeWatcher _serialCodeWatcher;
|
|
int (*_pMuxerMethod)(flv_muxer_t*, const void*, size_t, uint32_t, uint32_t);
|
|
};
|
|
|
|
public:
|
|
RTMPMuxer(const std::string& url);
|
|
~RTMPMuxer();
|
|
|
|
protected:
|
|
void connect() override;
|
|
void mux() override;
|
|
void disconnect() override;
|
|
|
|
protected:
|
|
void drainInput();
|
|
const int getCodecID(Core::CodecID id);
|
|
static int clientSend(void* param, const void* header, size_t len, const void* data, size_t bytes);
|
|
static int muxerHandler(void* param, int type, const void* data, size_t bytes, uint32_t timestamp);
|
|
|
|
private:
|
|
socket_t _socket;
|
|
rtmp_client_t* _pClient;
|
|
flv_muxer_t* _pMuxer;
|
|
std::vector<Stream::Ptr> _streams;
|
|
#if (TRACE_VIDEO_FRAME_RATE)
|
|
int count = 0;
|
|
uint64_t timeline = 0;
|
|
#endif
|
|
};
|
|
|
|
inline bool RTMPMuxer::Stream::operator<(const Stream& other)
|
|
{
|
|
return _Timeline < other._Timeline;
|
|
}
|
|
|
|
inline const std::string RTMPMuxer::Stream::name() const
|
|
{
|
|
return _name;
|
|
}
|
|
|
|
inline Core::PacketQueue::Ptr RTMPMuxer::Stream::queue()
|
|
{
|
|
return _pQueue;
|
|
}
|
|
|
|
inline Core::SerialCodeWatcher& RTMPMuxer::Stream::serialCodeWatcher()
|
|
{
|
|
return _serialCodeWatcher;
|
|
}
|
|
|
|
inline Core::CodecID RTMPMuxer::Stream::codecID() const
|
|
{
|
|
return _codecID;
|
|
}
|
|
}
|
|
}
|
|
#endif
|