Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
9c646d13
Commit
9c646d13
authored
4 years ago
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善预设截图相关逻辑
parent
cecfe7ba
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
18 行删除
+21
-18
server/WebApi.cpp
+21
-18
没有找到文件。
server/WebApi.cpp
查看文件 @
9c646d13
...
...
@@ -821,13 +821,31 @@ void installWebApi() {
val
[
"data"
][
"paths"
]
=
paths
;
});
GET_CONFIG
(
string
,
snap_root
,
API
::
kSnapRoot
);
static
auto
responseSnap
=
[](
const
string
&
snap_path
,
const
HttpSession
::
KeyValue
&
headerIn
,
const
HttpSession
::
HttpResponseInvoker
&
invoker
)
{
StrCaseMap
headerOut
;
struct
stat
statbuf
=
{
0
};
GET_CONFIG
(
string
,
defaultSnap
,
API
::
kDefaultSnap
);
if
(
!
(
stat
(
snap_path
.
data
(),
&
statbuf
)
==
0
&&
statbuf
.
st_size
!=
0
)
&&
!
defaultSnap
.
empty
())
{
//空文件且设置了预设图,则返回预设图片(也就是FFmpeg生成截图中空档期的默认图片)
const_cast
<
string
&>
(
snap_path
)
=
File
::
absolutePath
(
defaultSnap
,
""
);
headerOut
[
"Content-Type"
]
=
HttpFileManager
::
getContentType
(
snap_path
.
data
());
}
else
{
//之前生成的截图文件,我们默认为jpeg格式
headerOut
[
"Content-Type"
]
=
HttpFileManager
::
getContentType
(
".jpeg"
);
}
//返回图片给http客户端
invoker
.
responseFile
(
headerIn
,
headerOut
,
snap_path
);
};
//获取截图缓存或者实时截图
//http://127.0.0.1/index/api/getSnap?url=rtmp://127.0.0.1/record/robot.mp4&timeout_sec=10&expire_sec=3
api_regist2
(
"/index/api/getSnap"
,
[](
API_ARGS2
){
CHECK_SECRET
();
CHECK_ARGS
(
"url"
,
"timeout_sec"
,
"expire_sec"
);
GET_CONFIG
(
string
,
snap_root
,
API
::
kSnapRoot
);
int
expire_sec
=
allArgs
[
"expire_sec"
];
auto
scan_path
=
File
::
absolutePath
(
MD5
(
allArgs
[
"url"
]).
hexdigest
(),
snap_root
)
+
"/"
;
string
snap_path
;
...
...
@@ -851,19 +869,7 @@ void installWebApi() {
});
if
(
!
snap_path
.
empty
()){
StrCaseMap
headerOut
;
struct
stat
statbuf
=
{
0
};
GET_CONFIG
(
string
,
defaultSnap
,
API
::
kDefaultSnap
);
if
(
!
defaultSnap
.
empty
()
&&
!
(
stat
(
snap_path
.
data
(),
&
statbuf
)
==
0
&&
statbuf
.
st_size
!=
0
))
{
//空文件,则返回预设图片(也就是FFmpeg生成截图中空档期的默认图片)
snap_path
=
File
::
absolutePath
(
defaultSnap
,
""
);
headerOut
[
"Content-Type"
]
=
HttpFileManager
::
getContentType
(
snap_path
.
data
());
}
else
{
//之前生成的截图文件,我们默认为jpeg格式
headerOut
[
"Content-Type"
]
=
HttpFileManager
::
getContentType
(
".jpeg"
);
}
//返回图片给http客户端
invoker
.
responseFile
(
headerIn
,
headerOut
,
snap_path
);
responseSnap
(
snap_path
,
headerIn
,
invoker
);
return
;
}
...
...
@@ -883,10 +889,7 @@ void installWebApi() {
//生成截图失败,可能残留空文件
File
::
delete_file
(
snap_path
.
data
());
}
StrCaseMap
headerOut
;
headerOut
[
"Content-Type"
]
=
HttpFileManager
::
getContentType
(
".jpeg"
);
invoker
.
responseFile
(
headerIn
,
headerOut
,
snap_path
);
responseSnap
(
snap_path
,
headerIn
,
invoker
);
});
});
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论