mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-03 00:47:34 +08:00
add MediaTuple
This commit is contained in:
@@ -42,11 +42,7 @@ public:
|
||||
* @param stream_id 流id
|
||||
* @param ring_size 可以设置固定的环形缓冲大小,0则自适应
|
||||
*/
|
||||
RtspMediaSource(const std::string &vhost,
|
||||
const std::string &app,
|
||||
const std::string &stream_id,
|
||||
int ring_size = RTP_GOP_SIZE) :
|
||||
MediaSource(RTSP_SCHEMA, vhost, app, stream_id), _ring_size(ring_size) {}
|
||||
RtspMediaSource(const MediaTuple& tuple, int ring_size = RTP_GOP_SIZE): MediaSource(RTSP_SCHEMA, tuple), _ring_size(ring_size) {}
|
||||
|
||||
~RtspMediaSource() override { flush(); }
|
||||
|
||||
@@ -76,7 +72,7 @@ public:
|
||||
return _sdp;
|
||||
}
|
||||
|
||||
virtual RtspMediaSource::Ptr Clone(const std::string& stream) {
|
||||
virtual RtspMediaSource::Ptr clone(const std::string& stream) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,8 +74,7 @@ void RtspMediaSource::onWrite(RtpPacket::Ptr rtp, bool keyPos) {
|
||||
PacketCache<RtpPacket>::inputPacket(stamp, is_video, std::move(rtp), keyPos);
|
||||
}
|
||||
|
||||
RtspMediaSourceImp::RtspMediaSourceImp(const std::string &vhost, const std::string &app, const std::string &id, int ringSize)
|
||||
: RtspMediaSource(vhost, app, id, ringSize)
|
||||
RtspMediaSourceImp::RtspMediaSourceImp(const MediaTuple& tuple, int ringSize): RtspMediaSource(tuple, ringSize)
|
||||
{
|
||||
_demuxer = std::make_shared<RtspDemuxer>();
|
||||
_demuxer->setTrackListener(this);
|
||||
@@ -114,7 +113,7 @@ void RtspMediaSourceImp::setProtocolOption(const ProtocolOption &option)
|
||||
//导致rtc无法播放,所以在rtsp推流rtc播放时,建议关闭直接代理模式
|
||||
_option = option;
|
||||
_option.enable_rtsp = !direct_proxy;
|
||||
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), getApp(), getId(), _demuxer->getDuration(), _option);
|
||||
_muxer = std::make_shared<MultiMediaSourceMuxer>(_tuple, _demuxer->getDuration(), _option);
|
||||
_muxer->setMediaListener(getListener());
|
||||
_muxer->setTrackListener(std::static_pointer_cast<RtspMediaSourceImp>(shared_from_this()));
|
||||
//让_muxer对象拦截一部分事件(比如说录像相关事件)
|
||||
@@ -126,8 +125,10 @@ void RtspMediaSourceImp::setProtocolOption(const ProtocolOption &option)
|
||||
}
|
||||
}
|
||||
|
||||
RtspMediaSource::Ptr RtspMediaSourceImp::Clone(const std::string &stream) {
|
||||
auto src_imp = std::make_shared<RtspMediaSourceImp>(getVhost(), getApp(), stream);
|
||||
RtspMediaSource::Ptr RtspMediaSourceImp::clone(const std::string &stream) {
|
||||
auto tuple = _tuple;
|
||||
tuple.stream = stream;
|
||||
auto src_imp = std::make_shared<RtspMediaSourceImp>(tuple);
|
||||
src_imp->setSdp(getSdp());
|
||||
src_imp->setProtocolOption(getProtocolOption());
|
||||
return src_imp;
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
* @param id 流id
|
||||
* @param ringSize 环形缓存大小
|
||||
*/
|
||||
RtspMediaSourceImp(const std::string &vhost, const std::string &app, const std::string &id, int ringSize = RTP_GOP_SIZE);
|
||||
RtspMediaSourceImp(const MediaTuple& tuple, int ringSize = RTP_GOP_SIZE);
|
||||
|
||||
~RtspMediaSourceImp() override = default;
|
||||
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
RtspMediaSource::Ptr Clone(const std::string& stream) override;
|
||||
RtspMediaSource::Ptr clone(const std::string& stream) override;
|
||||
private:
|
||||
bool _all_track_ready = false;
|
||||
ProtocolOption _option;
|
||||
|
||||
@@ -21,13 +21,11 @@ class RtspMediaSourceMuxer final : public RtspMuxer, public MediaSourceEventInte
|
||||
public:
|
||||
using Ptr = std::shared_ptr<RtspMediaSourceMuxer>;
|
||||
|
||||
RtspMediaSourceMuxer(const std::string &vhost,
|
||||
const std::string &strApp,
|
||||
const std::string &strId,
|
||||
RtspMediaSourceMuxer(const MediaTuple& tuple,
|
||||
const ProtocolOption &option,
|
||||
const TitleSdp::Ptr &title = nullptr) : RtspMuxer(title) {
|
||||
_option = option;
|
||||
_media_src = std::make_shared<RtspMediaSource>(vhost,strApp,strId);
|
||||
_media_src = std::make_shared<RtspMediaSource>(tuple);
|
||||
getRtpRing()->setDelegate(_media_src);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ void RtspSession::onWholeRtspPacket(Parser &parser) {
|
||||
if (_content_base.empty() && method != "GET") {
|
||||
_content_base = parser.Url();
|
||||
_media_info.parse(parser.FullUrl());
|
||||
_media_info._schema = RTSP_SCHEMA;
|
||||
_media_info.schema = RTSP_SCHEMA;
|
||||
}
|
||||
|
||||
using rtsp_request_handler = void (RtspSession::*)(const Parser &parser);
|
||||
@@ -208,7 +208,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
|
||||
_media_info.parse(full_url);
|
||||
}
|
||||
|
||||
if (_media_info._app.empty() || _media_info._streamid.empty()) {
|
||||
if (_media_info.app.empty() || _media_info.stream.empty()) {
|
||||
//推流rtsp url必须最少两级(rtsp://host/app/stream_id),不允许莫名其妙的推流url
|
||||
static constexpr auto err = "rtsp推流url非法,最少确保两级rtsp url";
|
||||
sendRtspResponse("403 Forbidden", {"Content-Type", "text/plain"}, err);
|
||||
@@ -223,7 +223,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
|
||||
}
|
||||
|
||||
assert(!_push_src);
|
||||
auto src = MediaSource::find(RTSP_SCHEMA, _media_info._vhost, _media_info._app, _media_info._streamid);
|
||||
auto src = MediaSource::find(RTSP_SCHEMA, _media_info.vhost, _media_info.app, _media_info.stream);
|
||||
auto push_failed = (bool)src;
|
||||
|
||||
while (src) {
|
||||
@@ -266,7 +266,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
|
||||
}
|
||||
|
||||
if (!_push_src) {
|
||||
_push_src = std::make_shared<RtspMediaSourceImp>(_media_info._vhost, _media_info._app, _media_info._streamid);
|
||||
_push_src = std::make_shared<RtspMediaSourceImp>(_media_info);
|
||||
//获取所有权
|
||||
_push_src_ownership = _push_src->getOwnership();
|
||||
_push_src->setProtocolOption(option);
|
||||
@@ -717,7 +717,7 @@ void RtspSession::handleReq_Setup(const Parser &parser) {
|
||||
break;
|
||||
case Rtsp::RTP_MULTICAST: {
|
||||
if(!_multicaster){
|
||||
_multicaster = RtpMultiCaster::get(*this, get_local_ip(), _media_info._vhost, _media_info._app, _media_info._streamid, _multicast_ip, _multicast_video_port, _multicast_audio_port);
|
||||
_multicaster = RtpMultiCaster::get(*this, get_local_ip(), _media_info.vhost, _media_info.app, _media_info.stream, _multicast_ip, _multicast_video_port, _multicast_audio_port);
|
||||
if (!_multicaster) {
|
||||
send_NotAcceptable();
|
||||
throw SockException(Err_shutdown, "can not get a available udp multicast socket");
|
||||
@@ -1145,7 +1145,7 @@ MediaOriginType RtspSession::getOriginType(MediaSource &sender) const{
|
||||
}
|
||||
|
||||
string RtspSession::getOriginUrl(MediaSource &sender) const {
|
||||
return _media_info._full_url;
|
||||
return _media_info.full_url;
|
||||
}
|
||||
|
||||
std::shared_ptr<SockInfo> RtspSession::getOriginSock(MediaSource &sender) const {
|
||||
|
||||
Reference in New Issue
Block a user