ZLMediaKit/src/Rtsp/RtpMultiCaster.h

71 lines
2.0 KiB
C++
Raw Normal View History

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/xia-chu/ZLMediaKit).
2017-09-27 16:20:30 +08:00
*
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-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 {
2017-04-01 16:35:56 +08:00
public:
~MultiCastAddressMaker() {}
static MultiCastAddressMaker& Instance();
static bool isMultiCastAddress(uint32_t addr);
static string toString(uint32_t addr);
std::shared_ptr<uint32_t> obtain(uint32_t max_try = 10);
2018-07-03 17:10:11 +08:00
2017-04-01 16:35:56 +08:00
private:
MultiCastAddressMaker() {};
void release(uint32_t addr);
private:
uint32_t _addr = 0;
2020-03-20 11:51:24 +08:00
recursive_mutex _mtx;
unordered_set<uint32_t> _used_addr;
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;
~RtpMultiCaster();
static Ptr get(SocketHelper &helper, const string &local_ip, const string &vhost, const string &app, const string &stream);
2020-03-20 11:51:24 +08:00
void setDetachCB(void *listener,const onDetach &cb);
2017-04-01 16:35:56 +08:00
string getMultiCasterIP();
uint16_t getMultiCasterPort(TrackType trackType);
2017-04-01 16:35:56 +08:00
private:
RtpMultiCaster(SocketHelper &helper, const string &local_ip, const string &vhost, const string &app, const string &stream);
2017-04-01 16:35:56 +08:00
private:
recursive_mutex _mtx;
Socket::Ptr _udp_sock[2];
std::shared_ptr<uint32_t> _multicast_ip;
unordered_map<void * , onDetach > _detach_map;
RtspMediaSource::RingType::RingReader::Ptr _rtp_reader;
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_ */