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
0063571f
Commit
0063571f
authored
Dec 29, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决hls中断恢复时播放器计数不准确的问题
parent
7e1e3678
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
43 行增加
和
26 行删除
+43
-26
src/Http/HttpFileManager.cpp
+7
-7
src/Record/HlsMediaSource.cpp
+10
-3
src/Record/HlsMediaSource.h
+26
-16
没有找到文件。
src/Http/HttpFileManager.cpp
查看文件 @
0063571f
...
...
@@ -258,13 +258,13 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
auto
lck
=
cookie
->
getLock
();
auto
accessErr
=
(
*
cookie
)[
kAccessErrKey
].
get
<
string
>
();
auto
cookiePath
=
(
*
cookie
)[
kCookiePathKey
].
get
<
string
>
();
auto
is_hls
=
(
*
cookie
)[
kAccessHls
].
get
<
bool
>
();
auto
cookie_
is_hls
=
(
*
cookie
)[
kAccessHls
].
get
<
bool
>
();
if
(
path
.
find
(
cookiePath
)
==
0
)
{
//上次cookie是限定本目录
if
(
accessErr
.
empty
())
{
//上次鉴权成功
if
(
is_hls
){
//如果播放的是hls,那么刷新hls的cookie
if
(
cookie_
is_hls
){
//如果播放的是hls,那么刷新hls的cookie
(获取ts文件也会刷新)
cookie
->
updateTime
();
cookie_from_header
=
false
;
}
...
...
@@ -284,8 +284,8 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
bool
is_hls
=
mediaInfo
.
_schema
==
HLS_SCHEMA
;
//该用户从来未获取过cookie,这个时候我们广播是否允许该用户访问该http目录
HttpSession
::
HttpAccessPathInvoker
accessPathInvoker
=
[
callback
,
uid
,
path
,
is_dir
,
is_hls
,
mediaInfo
]
(
const
string
&
errMsg
,
const
string
&
cookie_path_in
,
int
cookieLifeSecond
)
{
HttpSession
::
HttpAccessPathInvoker
accessPathInvoker
=
[
callback
,
uid
,
path
,
is_dir
,
is_hls
,
mediaInfo
]
(
const
string
&
errMsg
,
const
string
&
cookie_path_in
,
int
cookieLifeSecond
)
{
HttpServerCookie
::
Ptr
cookie
;
if
(
cookieLifeSecond
)
{
//本次鉴权设置了有效期,我们把鉴权结果缓存在cookie中
...
...
@@ -388,13 +388,13 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
return
;
}
auto
response_file
=
[](
const
HttpServerCookie
::
Ptr
&
cookie
,
const
HttpFileManager
::
invoker
&
cb
,
const
string
&
strFile
,
const
Parser
&
parser
)
{
auto
response_file
=
[
file_exist
](
const
HttpServerCookie
::
Ptr
&
cookie
,
const
HttpFileManager
::
invoker
&
cb
,
const
string
&
strFile
,
const
Parser
&
parser
)
{
StrCaseMap
httpHeader
;
if
(
cookie
)
{
httpHeader
[
"Set-Cookie"
]
=
cookie
->
getCookie
((
*
cookie
)[
kCookiePathKey
].
get
<
string
>
());
}
HttpSession
::
HttpResponseInvoker
invoker
=
[
&
](
const
string
&
codeOut
,
const
StrCaseMap
&
headerOut
,
const
HttpBody
::
Ptr
&
body
)
{
if
(
cookie
)
{
if
(
cookie
&&
file_exist
)
{
cookie
->
getLock
();
auto
is_hls
=
(
*
cookie
)[
kAccessHls
].
get
<
bool
>
();
if
(
is_hls
)
{
...
...
src/Record/HlsMediaSource.cpp
查看文件 @
0063571f
...
...
@@ -30,22 +30,29 @@ namespace mediakit{
HlsCookieData
::
HlsCookieData
(
const
MediaInfo
&
info
)
{
_info
=
info
;
_added
=
std
::
make_shared
<
bool
>
(
false
);
addReaderCount
();
}
void
HlsCookieData
::
addReaderCount
(){
if
(
!
_added
){
if
(
!
*
_added
){
auto
src
=
dynamic_pointer_cast
<
HlsMediaSource
>
(
MediaSource
::
find
(
HLS_SCHEMA
,
_info
.
_vhost
,
_info
.
_app
,
_info
.
_streamid
));
if
(
src
){
src
->
modifyReaderCount
(
true
);
_added
=
true
;
*
_added
=
true
;
_src
=
src
;
_ring_reader
=
src
->
getRing
()
->
attach
(
EventPollerPool
::
Instance
().
getPoller
());
auto
added
=
_added
;
_ring_reader
->
setDetachCB
([
added
](){
//HlsMediaSource已经销毁
*
added
=
false
;
});
}
}
}
HlsCookieData
::~
HlsCookieData
()
{
if
(
_added
)
{
if
(
*
_added
)
{
auto
src
=
_src
.
lock
();
if
(
src
)
{
src
->
modifyReaderCount
(
false
);
...
...
src/Record/HlsMediaSource.h
查看文件 @
0063571f
...
...
@@ -31,33 +31,26 @@
#include "Common/MediaSource.h"
namespace
mediakit
{
class
HlsMediaSource
;
class
HlsCookieData
{
public
:
HlsCookieData
(
const
MediaInfo
&
info
);
~
HlsCookieData
();
void
addByteUsage
(
uint64_t
bytes
);
private
:
void
addReaderCount
();
private
:
uint64_t
_bytes
=
0
;
MediaInfo
_info
;
bool
_added
=
false
;
weak_ptr
<
HlsMediaSource
>
_src
;
Ticker
_ticker
;
};
class
HlsMediaSource
:
public
MediaSource
{
public
:
friend
class
HlsCookieData
;
typedef
RingBuffer
<
string
>
RingType
;
typedef
std
::
shared_ptr
<
HlsMediaSource
>
Ptr
;
HlsMediaSource
(
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream_id
)
:
MediaSource
(
HLS_SCHEMA
,
vhost
,
app
,
stream_id
){
_readerCount
=
0
;
_ring
=
std
::
make_shared
<
RingType
>
();
}
virtual
~
HlsMediaSource
()
=
default
;
/**
* 获取媒体源的环形缓冲
*/
const
RingType
::
Ptr
&
getRing
()
const
{
return
_ring
;
}
/**
* 获取播放器个数
* @return
*/
...
...
@@ -93,6 +86,23 @@ private:
private
:
atomic_int
_readerCount
;
bool
_registed
=
false
;
RingType
::
Ptr
_ring
;
};
class
HlsCookieData
{
public
:
HlsCookieData
(
const
MediaInfo
&
info
);
~
HlsCookieData
();
void
addByteUsage
(
uint64_t
bytes
);
private
:
void
addReaderCount
();
private
:
uint64_t
_bytes
=
0
;
MediaInfo
_info
;
std
::
shared_ptr
<
bool
>
_added
;
weak_ptr
<
HlsMediaSource
>
_src
;
Ticker
_ticker
;
HlsMediaSource
::
RingType
::
RingReader
::
Ptr
_ring_reader
;
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论