2018-03-20 11:28:13 +08:00
|
|
|
|
//
|
2017-12-01 11:42:49 +08:00
|
|
|
|
// Created by xzl on 2017/12/1.
|
|
|
|
|
//
|
|
|
|
|
|
2019-05-31 09:06:30 +08:00
|
|
|
|
#ifndef SRC_SHELL_SHELLCMD_H_
|
|
|
|
|
#define SRC_SHELL_SHELLCMD_H_
|
|
|
|
|
|
2017-12-01 11:42:49 +08:00
|
|
|
|
#include "Util/CMD.h"
|
2018-02-08 17:24:42 +08:00
|
|
|
|
#include "Common/MediaSource.h"
|
2018-10-24 17:17:55 +08:00
|
|
|
|
using namespace toolkit;
|
2017-12-01 11:42:49 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit {
|
2017-12-01 11:42:49 +08:00
|
|
|
|
|
2018-02-08 17:24:42 +08:00
|
|
|
|
|
|
|
|
|
class CMD_media: public CMD {
|
2017-12-01 11:42:49 +08:00
|
|
|
|
public:
|
2018-02-08 17:24:42 +08:00
|
|
|
|
CMD_media(){
|
|
|
|
|
_parser.reset(new OptionParser([](const std::shared_ptr<ostream> &stream,mINI &ini){
|
2019-12-03 16:10:02 +08:00
|
|
|
|
MediaSource::for_each_media([&](const MediaSource::Ptr &media){
|
|
|
|
|
if(!ini["schema"].empty() && ini["schema"] != media->getSchema()){
|
2018-02-08 17:24:42 +08:00
|
|
|
|
//筛选协议不匹配
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-03 16:10:02 +08:00
|
|
|
|
if(!ini["vhost"].empty() && ini["vhost"] != media->getVhost()){
|
2018-02-08 17:24:42 +08:00
|
|
|
|
//筛选虚拟主机不匹配
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-03 16:10:02 +08:00
|
|
|
|
if(!ini["app"].empty() && ini["app"] != media->getApp()){
|
2018-02-08 17:24:42 +08:00
|
|
|
|
//筛选应用名不匹配
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-03 16:10:02 +08:00
|
|
|
|
if(!ini["stream"].empty() && ini["stream"] != media->getId()){
|
2018-02-08 17:24:42 +08:00
|
|
|
|
//流id不匹配
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(ini.find("list") != ini.end()){
|
|
|
|
|
//列出源
|
|
|
|
|
(*stream) << "\t"
|
2019-12-03 16:10:02 +08:00
|
|
|
|
<< media->getSchema() << "/"
|
|
|
|
|
<< media->getVhost() << "/"
|
|
|
|
|
<< media->getApp() << "/"
|
|
|
|
|
<< media->getId()
|
2018-02-08 17:24:42 +08:00
|
|
|
|
<< "\r\n";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-03 16:10:02 +08:00
|
|
|
|
EventPollerPool::Instance().getPoller()->async([ini,media,stream](){
|
2019-05-28 10:02:12 +08:00
|
|
|
|
if(ini.find("kick") != ini.end()){
|
|
|
|
|
//踢出源
|
|
|
|
|
do{
|
|
|
|
|
if(!media) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(!media->close(true)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
(*stream) << "\t踢出成功:"
|
2019-12-03 16:10:02 +08:00
|
|
|
|
<< media->getSchema() << "/"
|
|
|
|
|
<< media->getVhost() << "/"
|
|
|
|
|
<< media->getApp() << "/"
|
|
|
|
|
<< media->getId()
|
2019-05-28 10:02:12 +08:00
|
|
|
|
<< "\r\n";
|
|
|
|
|
return;
|
|
|
|
|
}while(0);
|
|
|
|
|
(*stream) << "\t踢出失败:"
|
2019-12-03 16:10:02 +08:00
|
|
|
|
<< media->getSchema() << "/"
|
|
|
|
|
<< media->getVhost() << "/"
|
|
|
|
|
<< media->getApp() << "/"
|
|
|
|
|
<< media->getId()
|
2018-02-08 17:24:42 +08:00
|
|
|
|
<< "\r\n";
|
2019-05-28 10:02:12 +08:00
|
|
|
|
}
|
|
|
|
|
},false);
|
|
|
|
|
|
2018-02-08 17:24:42 +08:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
(*_parser) << Option('k', "kick", Option::ArgNone,nullptr,false, "踢出媒体源", nullptr);
|
|
|
|
|
(*_parser) << Option('l', "list", Option::ArgNone,nullptr,false, "列出媒体源", nullptr);
|
|
|
|
|
(*_parser) << Option('S', "schema", Option::ArgRequired,nullptr,false, "协议筛选", nullptr);
|
|
|
|
|
(*_parser) << Option('v', "vhost", Option::ArgRequired,nullptr,false, "虚拟主机筛选", nullptr);
|
|
|
|
|
(*_parser) << Option('a', "app", Option::ArgRequired,nullptr,false, "应用名筛选", nullptr);
|
|
|
|
|
(*_parser) << Option('s', "stream", Option::ArgRequired,nullptr,false, "流id筛选", nullptr);
|
2017-12-01 11:42:49 +08:00
|
|
|
|
}
|
2018-02-08 17:24:42 +08:00
|
|
|
|
virtual ~CMD_media() {}
|
2017-12-01 11:42:49 +08:00
|
|
|
|
const char *description() const override {
|
2018-02-08 17:24:42 +08:00
|
|
|
|
return "媒体源相关操作.";
|
2017-12-01 11:42:49 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-31 09:06:30 +08:00
|
|
|
|
} /* namespace mediakit */
|
2019-05-27 18:39:43 +08:00
|
|
|
|
|
2019-05-31 09:06:30 +08:00
|
|
|
|
#endif //SRC_SHELL_SHELLCMD_H_
|