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
c25ff640
Commit
c25ff640
authored
Dec 24, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HLS: hls播放解决播放下一个切片导致数据丢失的bug: #1294
parent
0bf75529
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
119 行增加
和
104 行删除
+119
-104
src/Http/HlsPlayer.cpp
+75
-73
src/Http/HlsPlayer.h
+1
-2
src/Http/HttpTSPlayer.cpp
+17
-16
src/Http/HttpTSPlayer.h
+26
-13
没有找到文件。
src/Http/HlsPlayer.cpp
查看文件 @
c25ff640
差异被折叠。
点击展开。
src/Http/HlsPlayer.h
查看文件 @
c25ff640
...
...
@@ -96,7 +96,7 @@ private:
private
:
void
playDelay
();
float
delaySecond
();
void
playNextTs
(
bool
force
=
false
);
void
playNextTs
();
void
teardown_l
(
const
SockException
&
ex
);
void
play_l
();
void
onPacket_l
(
const
char
*
data
,
size_t
len
);
...
...
@@ -112,7 +112,6 @@ private:
private
:
bool
_is_m3u8
=
false
;
bool
_first
=
true
;
bool
_waiting_response
=
false
;
int64_t
_last_sequence
=
-
1
;
string
_m3u8
;
Timer
::
Ptr
_timer
;
...
...
src/Http/HttpTSPlayer.cpp
查看文件 @
c25ff640
...
...
@@ -9,24 +9,23 @@
*/
#include "HttpTSPlayer.h"
namespace
mediakit
{
HttpTSPlayer
::
HttpTSPlayer
(
const
EventPoller
::
Ptr
&
poller
,
bool
split_ts
){
HttpTSPlayer
::
HttpTSPlayer
(
const
EventPoller
::
Ptr
&
poller
,
bool
split_ts
)
{
_split_ts
=
split_ts
;
_segment
.
setOnSegment
([
this
](
const
char
*
data
,
size_t
len
)
{
onPacket
(
data
,
len
);
});
setPoller
(
poller
?
poller
:
EventPollerPool
::
Instance
().
getPoller
());
}
HttpTSPlayer
::~
HttpTSPlayer
()
{}
ssize_t
HttpTSPlayer
::
onResponseHeader
(
const
string
&
status
,
const
HttpClient
::
HttpHeader
&
headers
)
{
ssize_t
HttpTSPlayer
::
onResponseHeader
(
const
string
&
status
,
const
HttpClient
::
HttpHeader
&
header
)
{
_status
=
status
;
if
(
status
!=
"200"
&&
status
!=
"206"
)
{
//http状态码不符合预期
shutdown
(
SockException
(
Err_other
,
StrPrinter
<<
"bad http status code:"
+
status
));
return
0
;
}
auto
content_type
=
const_cast
<
HttpClient
::
HttpHeader
&>
(
header
s
)[
"Content-Type"
];
auto
content_type
=
const_cast
<
HttpClient
::
HttpHeader
&>
(
header
)[
"Content-Type"
];
if
(
content_type
.
find
(
"video/mp2t"
)
==
0
||
content_type
.
find
(
"video/mpeg"
)
==
0
)
{
_is_ts_content
=
true
;
}
...
...
@@ -35,11 +34,11 @@ ssize_t HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::H
return
-
1
;
}
void
HttpTSPlayer
::
onResponseBody
(
const
char
*
buf
,
size_t
size
,
size_t
recved
Size
,
size_t
totalS
ize
)
{
void
HttpTSPlayer
::
onResponseBody
(
const
char
*
buf
,
size_t
size
,
size_t
recved
_size
,
size_t
total_s
ize
)
{
if
(
_status
!=
"200"
&&
_status
!=
"206"
)
{
return
;
}
if
(
recved
S
ize
==
size
)
{
if
(
recved
_s
ize
==
size
)
{
//开始接收数据
if
(
buf
[
0
]
==
TS_SYNC_BYTE
)
{
//这是ts头
...
...
@@ -57,14 +56,16 @@ void HttpTSPlayer::onResponseBody(const char *buf, size_t size, size_t recvedSiz
}
void
HttpTSPlayer
::
onResponseCompleted
()
{
//接收完毕
shutdown
(
SockException
(
Err_success
,
"play completed"
));
emitOnComplete
(
SockException
(
Err_success
,
"play completed"
));
}
void
HttpTSPlayer
::
onDisconnect
(
const
SockException
&
ex
)
{
if
(
_on_disconnect
)
{
_on_disconnect
(
ex
);
_on_disconnect
=
nullptr
;
emitOnComplete
(
ex
);
}
void
HttpTSPlayer
::
emitOnComplete
(
const
SockException
&
ex
)
{
if
(
_on_complete
)
{
_on_complete
(
ex
);
}
}
...
...
@@ -74,12 +75,12 @@ void HttpTSPlayer::onPacket(const char *data, size_t len) {
}
}
void
HttpTSPlayer
::
setOn
Disconnect
(
const
HttpTSPlayer
::
onShutdown
&
cb
)
{
_on_
disconnect
=
cb
;
void
HttpTSPlayer
::
setOn
Complete
(
onComplete
cb
)
{
_on_
complete
=
std
::
move
(
cb
)
;
}
void
HttpTSPlayer
::
setOnPacket
(
const
TSSegment
::
onSegment
&
cb
)
{
_on_segment
=
cb
;
void
HttpTSPlayer
::
setOnPacket
(
TSSegment
::
onSegment
cb
)
{
_on_segment
=
std
::
move
(
cb
)
;
}
}
//namespace mediakit
src/Http/HttpTSPlayer.h
查看文件 @
c25ff640
...
...
@@ -14,34 +14,47 @@
#include "Http/HttpDownloader.h"
#include "Player/MediaPlayer.h"
#include "Rtp/TSDecoder.h"
using
namespace
toolkit
;
namespace
mediakit
{
//http-ts播发器,未实现ts解复用
class
HttpTSPlayer
:
public
HttpClientImp
{
class
HttpTSPlayer
:
public
HttpClientImp
{
public
:
typedef
function
<
void
(
const
SockException
&
)
>
onShutdown
;
typedef
std
::
shared_ptr
<
HttpTSPlayer
>
Ptr
;
using
Ptr
=
std
::
shared_ptr
<
HttpTSPlayer
>
;
using
onComplete
=
std
::
function
<
void
(
const
SockException
&
)
>
;
HttpTSPlayer
(
const
EventPoller
::
Ptr
&
poller
=
nullptr
,
bool
split_ts
=
true
);
~
HttpTSPlayer
()
override
;
~
HttpTSPlayer
()
override
=
default
;
/**
* 设置下载完毕或异常断开回调
*/
void
setOnComplete
(
onComplete
cb
);
/
/设置异常断开回调
void
setOnDisconnect
(
const
onShutdown
&
cb
);
//设置接收ts包回调
void
setOnPacket
(
const
TSSegment
::
onSegment
&
cb
);
/
**
* 设置接收ts包回调
*/
void
setOnPacket
(
TSSegment
::
onSegment
cb
);
protected
:
///HttpClient override///
ssize_t
onResponseHeader
(
const
string
&
status
,
const
HttpHeader
&
headers
)
override
;
void
onResponseBody
(
const
char
*
buf
,
size_t
size
,
size_t
recvedSize
,
size_t
totalS
ize
)
override
;
ssize_t
onResponseHeader
(
const
string
&
status
,
const
HttpHeader
&
header
)
override
;
void
onResponseBody
(
const
char
*
buf
,
size_t
size
,
size_t
recved_size
,
size_t
total_s
ize
)
override
;
void
onResponseCompleted
()
override
;
void
onDisconnect
(
const
SockException
&
ex
)
override
;
void
onDisconnect
(
const
SockException
&
ex
)
override
;
//收到ts包
protected
:
/**
* 收到ts数据
*/
virtual
void
onPacket
(
const
char
*
data
,
size_t
len
);
private
:
void
emitOnComplete
(
const
SockException
&
ex
);
private
:
//是否为mpegts负载
bool
_is_ts_content
=
false
;
//第一个包是否为ts包
...
...
@@ -50,7 +63,7 @@ private:
bool
_split_ts
;
string
_status
;
TSSegment
_segment
;
on
Shutdown
_on_disconnect
;
on
Complete
_on_complete
;
TSSegment
::
onSegment
_on_segment
;
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论