ZLMediaKit/src/Rtp/RtpSelector.h

92 lines
2.6 KiB
C++
Raw Normal View History

2019-12-05 19:20:12 +08:00
/*
2020-04-04 20:30:09 +08:00
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
2019-12-06 11:54:10 +08:00
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
2020-04-04 20:30:09 +08:00
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
2019-12-06 11:54:10 +08:00
*/
2019-12-05 19:20:12 +08:00
2019-12-06 11:54:10 +08:00
#ifndef ZLMEDIAKIT_RTPSELECTOR_H
#define ZLMEDIAKIT_RTPSELECTOR_H
2019-12-05 19:20:12 +08:00
2019-12-06 11:54:10 +08:00
#if defined(ENABLE_RTPPROXY)
#include <stdint.h>
2019-12-05 19:20:12 +08:00
#include <mutex>
#include <unordered_map>
#include "RtpProcess.h"
2020-02-28 16:25:14 +08:00
#include "Common/MediaSource.h"
2019-12-05 19:20:12 +08:00
2019-12-06 11:54:10 +08:00
namespace mediakit{
2019-12-05 19:20:12 +08:00
2020-02-28 16:25:14 +08:00
class RtpSelector;
class RtpProcessHelper : public MediaSourceEvent , public std::enable_shared_from_this<RtpProcessHelper> {
public:
typedef std::shared_ptr<RtpProcessHelper> Ptr;
RtpProcessHelper(const string &stream_id, const weak_ptr<RtpSelector > &parent);
2020-02-28 16:25:14 +08:00
~RtpProcessHelper();
void attachEvent();
RtpProcess::Ptr & getProcess();
2020-02-28 16:25:14 +08:00
protected:
// 通知其停止推流
bool close(MediaSource &sender,bool force) override;
// 观看总人数
int totalReaderCount(MediaSource &sender) override;
2020-02-28 16:25:14 +08:00
private:
weak_ptr<RtpSelector > _parent;
RtpProcess::Ptr _process;
string _stream_id;
2020-02-28 16:25:14 +08:00
};
2019-12-05 19:20:12 +08:00
class RtpSelector : public std::enable_shared_from_this<RtpSelector>{
public:
RtpSelector();
~RtpSelector();
2020-02-23 12:16:20 +08:00
static bool getSSRC(const char *data,int data_len, uint32_t &ssrc);
static RtpSelector &Instance();
2020-07-08 09:36:10 +08:00
/**
* rtp流ssrc分流
* @param sock socket
* @param data
* @param data_len
* @param addr rtp流源地址
* @param dts_out dts
* @return
*/
bool inputRtp(const Socket::Ptr &sock, const char *data, int data_len,
const struct sockaddr *addr, uint32_t *dts_out = nullptr);
2020-07-08 09:36:10 +08:00
/**
* rtp处理器
* @param stream_id id
* @param makeNew
* @return rtp处理器
*/
RtpProcess::Ptr getProcess(const string &stream_id, bool makeNew);
2020-07-08 09:36:10 +08:00
/**
* rtp处理器
* @param stream_id id
* @param ptr rtp处理器指针
*/
void delProcess(const string &stream_id, const RtpProcess *ptr);
2019-12-05 19:20:12 +08:00
private:
void onManager();
2020-03-05 11:36:31 +08:00
void createTimer();
2019-12-05 19:20:12 +08:00
private:
unordered_map<string,RtpProcessHelper::Ptr> _map_rtp_process;
2019-12-05 19:20:12 +08:00
recursive_mutex _mtx_map;
2020-03-05 11:36:31 +08:00
Timer::Ptr _timer;
2019-12-05 19:20:12 +08:00
};
2019-12-06 11:54:10 +08:00
}//namespace mediakit
#endif//defined(ENABLE_RTPPROXY)
#endif //ZLMEDIAKIT_RTPSELECTOR_H