From 678e011afb7c0756a7ec2f12fc9d7d17fdec3a8c Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 15 Aug 2020 09:49:56 +0800 Subject: [PATCH] =?UTF-8?q?FFmpeg=E6=8B=89=E6=B5=81=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=98=B2=E5=91=86=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/FFmpegSource.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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) { //同步查找流