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;
|
2020-07-07 10:01:12 +08:00
|
|
|
|
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-07-07 10:01:12 +08:00
|
|
|
|
|
2020-02-28 16:25:14 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
// 通知其停止推流
|
|
|
|
|
|
bool close(MediaSource &sender,bool force) override;
|
|
|
|
|
|
// 观看总人数
|
|
|
|
|
|
int totalReaderCount(MediaSource &sender) override;
|
2020-07-07 10:01:12 +08:00
|
|
|
|
|
2020-02-28 16:25:14 +08:00
|
|
|
|
private:
|
|
|
|
|
|
weak_ptr<RtpSelector > _parent;
|
|
|
|
|
|
RtpProcess::Ptr _process;
|
2020-07-07 10:01:12 +08:00
|
|
|
|
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);
|
2020-07-07 10:01:12 +08:00
|
|
|
|
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,
|
2020-07-07 10:01:12 +08:00
|
|
|
|
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处理器
|
|
|
|
|
|
*/
|
2020-07-07 10:01:12 +08:00
|
|
|
|
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处理器指针
|
|
|
|
|
|
*/
|
2020-07-07 10:01:12 +08:00
|
|
|
|
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();
|
2020-07-07 10:01:12 +08:00
|
|
|
|
|
2019-12-05 19:20:12 +08:00
|
|
|
|
private:
|
2020-07-07 10:01:12 +08:00
|
|
|
|
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
|