2017-10-09 22:11:01 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2017-09-27 16:20:30 +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.
|
2017-04-01 16:35:56 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef SRC_RTSP_RTPBROADCASTER_H_
|
|
|
|
|
#define SRC_RTSP_RTPBROADCASTER_H_
|
2017-04-25 11:35:41 +08:00
|
|
|
|
|
2017-08-09 18:39:30 +08:00
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#include <mutex>
|
2017-04-25 11:35:41 +08:00
|
|
|
|
#include <memory>
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#include <unordered_set>
|
2017-04-25 11:35:41 +08:00
|
|
|
|
#include <unordered_map>
|
2017-05-02 17:15:12 +08:00
|
|
|
|
#include "Common/config.h"
|
2017-04-25 11:35:41 +08:00
|
|
|
|
#include "RtspMediaSource.h"
|
|
|
|
|
#include "Util/mini.h"
|
|
|
|
|
#include "Network/Socket.h"
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
using namespace std;
|
2018-10-24 17:17:55 +08:00
|
|
|
|
using namespace toolkit;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit{
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
class MultiCastAddressMaker
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-03-20 11:51:24 +08:00
|
|
|
|
static MultiCastAddressMaker &Instance();
|
2018-07-03 17:10:11 +08:00
|
|
|
|
|
2020-03-20 11:51:24 +08:00
|
|
|
|
static bool isMultiCastAddress(uint32_t iAddr){
|
|
|
|
|
static uint32_t addrMin = mINI::Instance()[MultiCast::kAddrMin].as<uint32_t>();
|
|
|
|
|
static uint32_t addrMax = mINI::Instance()[MultiCast::kAddrMax].as<uint32_t>();
|
|
|
|
|
return iAddr >= addrMin && iAddr <= addrMax;
|
|
|
|
|
}
|
|
|
|
|
static string toString(uint32_t iAddr){
|
|
|
|
|
iAddr = htonl(iAddr);
|
2020-04-23 16:14:24 +08:00
|
|
|
|
return SockUtil::inet_ntoa((struct in_addr &)(iAddr));
|
2020-03-20 11:51:24 +08:00
|
|
|
|
}
|
|
|
|
|
virtual ~MultiCastAddressMaker(){}
|
|
|
|
|
std::shared_ptr<uint32_t> obtain(uint32_t iTry = 10);
|
2017-04-01 16:35:56 +08:00
|
|
|
|
private:
|
2020-03-20 11:51:24 +08:00
|
|
|
|
MultiCastAddressMaker(){};
|
|
|
|
|
void release(uint32_t iAddr);
|
|
|
|
|
uint32_t _iAddr = 0;
|
|
|
|
|
recursive_mutex _mtx;
|
|
|
|
|
unordered_set<uint32_t> _setBadAddr;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
};
|
2019-08-22 16:25:19 +08:00
|
|
|
|
class RtpMultiCaster {
|
2017-04-01 16:35:56 +08:00
|
|
|
|
public:
|
2020-03-20 11:51:24 +08:00
|
|
|
|
typedef std::shared_ptr<RtpMultiCaster> Ptr;
|
|
|
|
|
typedef function<void()> onDetach;
|
|
|
|
|
virtual ~RtpMultiCaster();
|
|
|
|
|
static Ptr get(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream);
|
|
|
|
|
void setDetachCB(void *listener,const onDetach &cb);
|
|
|
|
|
uint16_t getPort(TrackType trackType);
|
|
|
|
|
string getIP();
|
2017-04-01 16:35:56 +08:00
|
|
|
|
private:
|
2020-03-20 11:51:24 +08:00
|
|
|
|
static recursive_mutex g_mtx;
|
|
|
|
|
static unordered_map<string , weak_ptr<RtpMultiCaster> > g_mapBroadCaster;
|
|
|
|
|
static Ptr make(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream);
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2020-03-20 11:51:24 +08:00
|
|
|
|
std::shared_ptr<uint32_t> _multiAddr;
|
|
|
|
|
recursive_mutex _mtx;
|
|
|
|
|
unordered_map<void * , onDetach > _mapDetach;
|
|
|
|
|
RtspMediaSource::RingType::RingReader::Ptr _pReader;
|
|
|
|
|
Socket::Ptr _apUdpSock[2];
|
|
|
|
|
struct sockaddr_in _aPeerUdpAddr[2];
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2020-03-20 11:51:24 +08:00
|
|
|
|
RtpMultiCaster(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream);
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
}//namespace mediakit
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
#endif /* SRC_RTSP_RTPBROADCASTER_H_ */
|