diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index fdf9b7f2..d0bddeb3 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -14,6 +14,7 @@ #include "Util/File.h" #include "System.h" #include "Thread/WorkThreadPool.h" +#include "Network/sockutil.h" namespace FFmpeg { #define FFmpeg_FIELD "ffmpeg." @@ -45,6 +46,18 @@ FFmpegSource::~FFmpegSource() { DebugL; } +static bool is_local_ip(const string &ip){ + if (ip == "127.0.0.1" || ip == "localhost") { + return true; + } + auto ips = SockUtil::getInterfaceList(); + for (auto &obj : ips) { + if (ip == obj["ip"]) { + return true; + } + } + return false; +} void FFmpegSource::play(const string &src_url,const string &dst_url,int timeout_ms,const onPlay &cb) { GET_CONFIG(string,ffmpeg_bin,FFmpeg::kBin); @@ -60,7 +73,7 @@ void FFmpegSource::play(const string &src_url,const string &dst_url,int timeout_ _process.run(cmd,ffmpeg_log.empty() ? "" : File::absolutePath("",ffmpeg_log)); InfoL << cmd; - if(_media_info._host == "127.0.0.1"){ + if (is_local_ip(_media_info._host)) { //推流给自己的,通过判断流是否注册上来判断是否正常 if(_media_info._schema != RTSP_SCHEMA && _media_info._schema != RTMP_SCHEMA){ cb(SockException(Err_other,"本服务只支持rtmp/rtsp推流")); @@ -179,7 +192,7 @@ void FFmpegSource::startTimer(int timeout_ms) { //自身已经销毁 return false; } - if (strongSelf->_media_info._host == "127.0.0.1") { + if (is_local_ip(strongSelf->_media_info._host)) { //推流给自己的,我们通过检查是否已经注册来判断FFmpeg是否工作正常 strongSelf->findAsync(0, [&](const MediaSource::Ptr &src) { //同步查找流