add MediaTuple

This commit is contained in:
Johnny
2023-05-25 16:23:24 +08:00
committed by 夏楚
parent f4ee607feb
commit 0232caf068
41 changed files with 242 additions and 273 deletions

View File

@@ -46,12 +46,7 @@ public:
* @param stream_id 流id
* @param ring_size 可以设置固定的环形缓冲大小0则自适应
*/
RtmpMediaSource(const std::string &vhost,
const std::string &app,
const std::string &stream_id,
int ring_size = RTMP_GOP_SIZE) :
MediaSource(RTMP_SCHEMA, vhost, app, stream_id), _ring_size(ring_size) {
}
RtmpMediaSource(const MediaTuple& tuple, int ring_size = RTMP_GOP_SIZE): MediaSource(RTMP_SCHEMA, tuple), _ring_size(ring_size) {}
~RtmpMediaSource() override { flush(); }

View File

@@ -63,7 +63,7 @@ void RtmpMediaSource::onWrite(RtmpPacket::Ptr pkt, bool /*= true*/)
}
RtmpMediaSourceImp::RtmpMediaSourceImp(const std::string &vhost, const std::string &app, const std::string &id, int ringSize) : RtmpMediaSource(vhost, app, id, ringSize)
RtmpMediaSourceImp::RtmpMediaSourceImp(const MediaTuple& tuple, int ringSize) : RtmpMediaSource(tuple, ringSize)
{
_demuxer = std::make_shared<RtmpDemuxer>();
_demuxer->setTrackListener(this);
@@ -99,7 +99,7 @@ void RtmpMediaSourceImp::setProtocolOption(const ProtocolOption &option)
_option = option;
//不重复生成rtmp协议
_option.enable_rtmp = false;
_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<RtmpMediaSourceImp>(shared_from_this()));
//让_muxer对象拦截一部分事件(比如说录像相关事件)

View File

@@ -35,7 +35,7 @@ public:
* @param id 流id
* @param ringSize 环形缓存大小
*/
RtmpMediaSourceImp(const std::string &vhost, const std::string &app, const std::string &id, int ringSize = RTMP_GOP_SIZE);
RtmpMediaSourceImp(const MediaTuple& tuple, int ringSize = RTMP_GOP_SIZE);
~RtmpMediaSourceImp() override = default;

View File

@@ -21,13 +21,11 @@ class RtmpMediaSourceMuxer final : public RtmpMuxer, public MediaSourceEventInte
public:
using Ptr = std::shared_ptr<RtmpMediaSourceMuxer>;
RtmpMediaSourceMuxer(const std::string &vhost,
const std::string &strApp,
const std::string &strId,
RtmpMediaSourceMuxer(const MediaTuple& tuple,
const ProtocolOption &option,
const TitleMeta::Ptr &title = nullptr) : RtmpMuxer(title) {
_option = option;
_media_src = std::make_shared<RtmpMediaSource>(vhost, strApp, strId);
_media_src = std::make_shared<RtmpMediaSource>(tuple);
getRtmpRing()->setDelegate(_media_src);
}

View File

@@ -84,7 +84,7 @@ void RtmpSession::onCmd_connect(AMFDecoder &dec) {
auto tc_url = params["tcUrl"].as_string();
if (tc_url.empty()) {
// defaultVhost:默认vhost
tc_url = string(RTMP_SCHEMA) + "://" + DEFAULT_VHOST + "/" + _media_info._app;
tc_url = string(RTMP_SCHEMA) + "://" + DEFAULT_VHOST + "/" + _media_info.app;
} else {
auto pos = tc_url.rfind('?');
if (pos != string::npos) {
@@ -94,9 +94,9 @@ void RtmpSession::onCmd_connect(AMFDecoder &dec) {
}
// 初步解析只用于获取vhost信息
_media_info.parse(tc_url);
_media_info._schema = RTMP_SCHEMA;
_media_info.schema = RTMP_SCHEMA;
// 赋值rtmp app
_media_info._app = params["app"].as_string();
_media_info.app = params["app"].as_string();
bool ok = true; //(app == APP_NAME);
AMFValue version(AMF_OBJECT);
@@ -109,7 +109,7 @@ void RtmpSession::onCmd_connect(AMFDecoder &dec) {
status.set("objectEncoding", params["objectEncoding"]);
sendReply(ok ? "_result" : "_error", version, status);
if (!ok) {
throw std::runtime_error("Unsupported application: " + _media_info._app);
throw std::runtime_error("Unsupported application: " + _media_info.app);
}
AMFEncoder invoke;
@@ -132,9 +132,9 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
}));
dec.load<AMFValue>();/* NULL */
// 赋值为rtmp stream id 信息
_media_info._streamid = getStreamId(dec.load<std::string>());
_media_info.stream = getStreamId(dec.load<std::string>());
// 再解析url切割url为app/stream_id (不一定符合rtmp url切割规范)
_media_info.parse(_media_info._schema + "://" + _media_info._vhost + '/' + _media_info._app + '/' + _media_info._streamid);
_media_info.parse(_media_info.getUrl());
auto now_stream_index = _now_stream_index;
auto on_res = [this, token, now_stream_index](const string &err, const ProtocolOption &option) {
@@ -149,7 +149,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
}
assert(!_push_src);
auto src = MediaSource::find(RTMP_SCHEMA, _media_info._vhost, _media_info._app, _media_info._streamid);
auto src = MediaSource::find(RTMP_SCHEMA, _media_info.vhost, _media_info.app, _media_info.stream);
auto push_failed = (bool)src;
while (src) {
@@ -180,7 +180,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
}
if (!_push_src) {
_push_src = std::make_shared<RtmpMediaSourceImp>(_media_info._vhost, _media_info._app, _media_info._streamid);
_push_src = std::make_shared<RtmpMediaSourceImp>(_media_info);
//获取所有权
_push_src_ownership = _push_src->getOwnership();
_push_src->setProtocolOption(option);
@@ -196,7 +196,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
setSocketFlags();
};
if(_media_info._app.empty() || _media_info._streamid.empty()){
if(_media_info.app.empty() || _media_info.stream.empty()){
//不允许莫名其妙的推流url
on_res("rtmp推流url非法", ProtocolOption());
return;
@@ -256,7 +256,7 @@ void RtmpSession::sendPlayResponse(const string &err, const RtmpMediaSource::Ptr
sendStatus({ "level", (ok ? "status" : "error"),
"code", (ok ? "NetStream.Play.Reset" : (auth_success ? "NetStream.Play.StreamNotFound" : "NetStream.Play.BadAuth")),
"description", (ok ? "Resetting and playing." : (auth_success ? "No such stream." : err.data())),
"details", _media_info._streamid,
"details", _media_info.stream,
"clientid", "0" });
if (!ok) {
@@ -270,7 +270,7 @@ void RtmpSession::sendPlayResponse(const string &err, const RtmpMediaSource::Ptr
sendStatus({ "level", "status",
"code", "NetStream.Play.Start",
"description", "Started playing." ,
"details", _media_info._streamid,
"details", _media_info.stream,
"clientid", "0"});
// |RtmpSampleAccess(true, true)
@@ -289,7 +289,7 @@ void RtmpSession::sendPlayResponse(const string &err, const RtmpMediaSource::Ptr
sendStatus({ "level", "status",
"code", "NetStream.Play.PublishNotify",
"description", "Now published." ,
"details", _media_info._streamid,
"details", _media_info.stream,
"clientid", "0"});
auto &metadata = src->getMetaData();
@@ -433,9 +433,9 @@ string RtmpSession::getStreamId(const string &str){
void RtmpSession::onCmd_play(AMFDecoder &dec) {
dec.load<AMFValue>(); /* NULL */
// 赋值为rtmp stream id 信息
_media_info._streamid = getStreamId(dec.load<std::string>());
_media_info.stream = getStreamId(dec.load<std::string>());
// 再解析url切割url为app/stream_id (不一定符合rtmp url切割规范)
_media_info.parse(_media_info._schema + "://" + _media_info._vhost + '/' + _media_info._app + '/' + _media_info._streamid);
_media_info.parse(_media_info.getUrl());
doPlay(dec);
}
@@ -589,7 +589,7 @@ MediaOriginType RtmpSession::getOriginType(MediaSource &sender) const{
}
string RtmpSession::getOriginUrl(MediaSource &sender) const {
return _media_info._full_url;
return _media_info.full_url;
}
std::shared_ptr<SockInfo> RtmpSession::getOriginSock(MediaSource &sender) const {