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
ce44694a
Commit
ce44694a
authored
Nov 17, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化rtsp/rtmp源生成成功率
parent
e0920536
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
5 行删除
+32
-5
src/Common/MediaSink.cpp
+27
-3
src/Common/MediaSink.h
+5
-2
没有找到文件。
src/Common/MediaSink.cpp
查看文件 @
ce44694a
...
...
@@ -25,6 +25,8 @@
*/
#include "MediaSink.h"
//最多等待未初始化的Track 10秒,超时之后会忽略未初始化的Track
#define MAX_WAIT_MS 10000
namespace
mediakit
{
...
...
@@ -53,6 +55,7 @@ void MediaSink::addTrack(const Track::Ptr &track_in) {
}
else
{
_allTrackReady
=
false
;
_trackReadyCallback
[
codec_id
]
=
lam
;
_ticker
.
resetTime
();
}
}
...
...
@@ -64,8 +67,9 @@ void MediaSink::inputFrame(const Frame::Ptr &frame) {
return
;
}
it
->
second
->
inputFrame
(
frame
);
if
(
!
_allTrackReady
&&
!
_trackReadyCallback
.
empty
()
&&
it
->
second
->
ready
()){
//Track由未就绪状态装换成就绪状态,我们就
生成sdp以及rtp编码器
//Track由未就绪状态装换成就绪状态,我们就
触发onTrackReady回调
auto
it_callback
=
_trackReadyCallback
.
find
(
codec_id
);
if
(
it_callback
!=
_trackReadyCallback
.
end
()){
it_callback
->
second
();
...
...
@@ -73,22 +77,42 @@ void MediaSink::inputFrame(const Frame::Ptr &frame) {
}
}
if
(
!
_allTrackReady
&&
_trackReadyCallback
.
empty
(
)){
if
(
!
_allTrackReady
&&
(
_trackReadyCallback
.
empty
()
||
_ticker
.
elapsedTime
()
>
MAX_WAIT_MS
)){
_allTrackReady
=
true
;
if
(
!
_trackReadyCallback
.
empty
()){
//这是超时强制忽略未准备好的Track
_trackReadyCallback
.
clear
();
//移除未准备好的Track
for
(
auto
it
=
_track_map
.
begin
()
;
it
!=
_track_map
.
end
()
;
){
if
(
!
it
->
second
->
ready
()){
it
=
_track_map
.
erase
(
it
);
continue
;
}
++
it
;
}
}
if
(
!
_track_map
.
empty
()){
//最少有一个有效的Track
onAllTrackReady
();
}
}
}
bool
MediaSink
::
isAllTrackReady
()
const
{
return
_allTrackReady
;
}
Track
::
Ptr
MediaSink
::
getTrack
(
TrackType
type
)
const
{
Track
::
Ptr
MediaSink
::
getTrack
(
TrackType
type
,
bool
trackReady
)
const
{
lock_guard
<
recursive_mutex
>
lck
(
_mtx
);
for
(
auto
&
pr
:
_track_map
){
if
(
pr
.
second
->
getTrackType
()
==
type
){
if
(
!
trackReady
){
return
pr
.
second
;
}
return
pr
.
second
->
ready
()
?
pr
.
second
:
nullptr
;
}
}
return
nullptr
;
}
...
...
src/Common/MediaSink.h
查看文件 @
ce44694a
...
...
@@ -29,6 +29,7 @@
#include <mutex>
#include <memory>
#include "Util/TimeTicker.h"
#include "Extension/Frame.h"
#include "Extension/Track.h"
...
...
@@ -70,10 +71,11 @@ public:
/**
* 获取特定类型的Track
* @param type
* @param type track类型
* @param trackReady 是否获取已经准备好的Track
* @return
*/
Track
::
Ptr
getTrack
(
TrackType
type
)
const
;
Track
::
Ptr
getTrack
(
TrackType
type
,
bool
trackReady
=
true
)
const
;
protected
:
/**
* 某track已经准备好,其ready()状态返回true,
...
...
@@ -97,6 +99,7 @@ private:
map
<
int
,
Track
::
Ptr
>
_track_map
;
map
<
int
,
function
<
void
()
>
>
_trackReadyCallback
;
bool
_allTrackReady
=
false
;
Ticker
_ticker
;
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论