ps rtp推流接口(startSendRtp)支持推送本地mp4录像

This commit is contained in:
ziyue 2021-10-21 10:21:52 +08:00
parent a25e1d6021
commit 4067f2beb6
4 changed files with 18 additions and 16 deletions

View File

@ -1329,6 +1329,12 @@
"value": "0",
"description": "指定tcp/udp客户端使用的本地端口0时为随机端口该参数非必选参数不传时为随机端口。",
"disabled": true
},
{
"key": "from_mp4",
"value": "0",
"description": "是否推送本地MP4录像该参数非必选参数",
"disabled": true
}
]
}

View File

@ -967,7 +967,7 @@ void installWebApi() {
CHECK_SECRET();
CHECK_ARGS("vhost", "app", "stream", "ssrc", "dst_url", "dst_port", "is_udp");
auto src = MediaSource::find(allArgs["vhost"], allArgs["app"], allArgs["stream"]);
auto src = MediaSource::find(allArgs["vhost"], allArgs["app"], allArgs["stream"], allArgs["from_mp4"].as<int>());
if (!src) {
throw ApiRetException("该媒体流不存在", API::OtherFailed);
}

View File

@ -288,7 +288,7 @@ void MediaSource::for_each_media(const function<void(const Ptr &src)> &cb,
}
}
static MediaSource::Ptr find_l(const string &schema, const string &vhost_in, const string &app, const string &id, bool create_new) {
static MediaSource::Ptr find_l(const string &schema, const string &vhost_in, const string &app, const string &id, bool from_mp4) {
string vhost = vhost_in;
GET_CONFIG(bool,enableVhost,General::kEnableVhost);
if(vhost.empty() || !enableVhost){
@ -303,7 +303,7 @@ static MediaSource::Ptr find_l(const string &schema, const string &vhost_in, con
MediaSource::Ptr ret;
MediaSource::for_each_media([&](const MediaSource::Ptr &src) { ret = std::move(const_cast<MediaSource::Ptr &>(src)); }, schema, vhost, app, id);
if(!ret && create_new && schema != HLS_SCHEMA){
if(!ret && from_mp4 && schema != HLS_SCHEMA){
//未查找媒体源则读取mp4创建一个
//播放hls不触发mp4点播(因为HLS也可以用于录像不是纯粹的直播)
ret = MediaSource::createFromMP4(schema, vhost, app, id);
@ -387,20 +387,20 @@ void MediaSource::findAsync(const MediaInfo &info, const std::shared_ptr<Session
return findAsync_l(info, session, true, cb);
}
MediaSource::Ptr MediaSource::find(const string &schema, const string &vhost, const string &app, const string &id) {
return find_l(schema, vhost, app, id, false);
MediaSource::Ptr MediaSource::find(const string &schema, const string &vhost, const string &app, const string &id, bool from_mp4) {
return find_l(schema, vhost, app, id, from_mp4);
}
MediaSource::Ptr MediaSource::find(const string &vhost, const string &app, const string &stream_id){
auto src = MediaSource::find(RTMP_SCHEMA, vhost, app, stream_id);
MediaSource::Ptr MediaSource::find(const string &vhost, const string &app, const string &stream_id, bool from_mp4) {
auto src = MediaSource::find(RTMP_SCHEMA, vhost, app, stream_id, from_mp4);
if (src) {
return src;
}
src = MediaSource::find(RTSP_SCHEMA, vhost, app, stream_id);
src = MediaSource::find(RTSP_SCHEMA, vhost, app, stream_id, from_mp4);
if (src) {
return src;
}
return MediaSource::find(HLS_SCHEMA, vhost, app, stream_id);
return MediaSource::find(HLS_SCHEMA, vhost, app, stream_id, from_mp4);
}
void MediaSource::emitEvent(bool regist){

View File

@ -275,19 +275,15 @@ public:
////////////////static方法查找或生成MediaSource////////////////
// 同步查找流
static Ptr find(const string &schema, const string &vhost, const string &app, const string &id);
static Ptr find(const string &schema, const string &vhost, const string &app, const string &id, bool from_mp4 = false);
// 忽略类型同步查找流可能返回rtmp/rtsp/hls类型
static Ptr find(const string &vhost, const string &app, const string &stream_id);
static Ptr find(const string &vhost, const string &app, const string &stream_id, bool from_mp4 = false);
// 异步查找流
static void findAsync(const MediaInfo &info, const std::shared_ptr<Session> &session, const function<void(const Ptr &src)> &cb);
// 遍历所有流
static void for_each_media(const function<void(const Ptr &src)> &cb,
const string &schema = "",
const string &vhost = "",
const string &app = "",
const string &stream = "");
static void for_each_media(const function<void(const Ptr &src)> &cb, const string &schema = "", const string &vhost = "", const string &app = "", const string &stream = "");
// 从mp4文件生成MediaSource
static MediaSource::Ptr createFromMP4(const string &schema, const string &vhost, const string &app, const string &stream, const string &file_path = "", bool check_app = true);