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
d04761c2
Commit
d04761c2
authored
Nov 01, 2022
by
ziyue
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'FrameDispatcher_addDelegate_refactor' of github.com:mtdxc/ZLMediaKit
parents
bfe118d9
dde35254
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
54 行增加
和
46 行删除
+54
-46
Android/app/src/main/cpp/native-lib.cpp
+4
-4
README_en.md
+2
-2
api/source/mk_track.cpp
+1
-3
player/test_player.cpp
+2
-4
src/Common/MediaSink.cpp
+6
-6
src/Extension/Frame.cpp
+34
-0
src/Extension/Frame.h
+1
-23
src/Player/PlayerBase.cpp
+2
-2
src/Rtp/GB28181Process.cpp
+2
-2
没有找到文件。
Android/app/src/main/cpp/native-lib.cpp
查看文件 @
d04761c2
...
...
@@ -232,18 +232,18 @@ JNI_API(jlong, createMediaPlayer, jstring url, jobject callback){
auto
viedoTrack
=
strongPlayer
->
getTrack
(
TrackVideo
);
if
(
viedoTrack
)
{
viedoTrack
->
addDelegate
(
std
::
make_shared
<
FrameWriterInterfaceHelper
>
(
[
globalWeakRef
](
const
Frame
::
Ptr
&
frame
)
{
viedoTrack
->
addDelegate
([
globalWeakRef
](
const
Frame
::
Ptr
&
frame
)
{
emitEvent
((
jobject
)
globalWeakRef
,
"onData"
,
"(L"
MediaFrameSign
";)V"
,
makeJavaFrame
(
env
,
frame
));
return
true
;
})
)
;
});
}
auto
audioTrack
=
strongPlayer
->
getTrack
(
TrackAudio
);
if
(
audioTrack
)
{
audioTrack
->
addDelegate
(
std
::
make_shared
<
FrameWriterInterfaceHelper
>
(
[
globalWeakRef
](
const
Frame
::
Ptr
&
frame
)
{
audioTrack
->
addDelegate
([
globalWeakRef
](
const
Frame
::
Ptr
&
frame
)
{
emitEvent
((
jobject
)
globalWeakRef
,
"onData"
,
"(L"
MediaFrameSign
";)V"
,
makeJavaFrame
(
env
,
frame
));
return
true
;
})
)
;
});
}
});
...
...
README_en.md
查看文件 @
d04761c2
...
...
@@ -213,9 +213,9 @@ git submodule update --init
WarnL << "none video Track!";
return;
}
viedoTrack->addDelegate(
std::make_shared<FrameWriterInterfaceHelper>(
[](const Frame::Ptr &frame) {
viedoTrack->addDelegate([](const Frame::Ptr &frame) {
//please decode video here
})
)
;
});
});
player->setOnShutdown([](const SockException &ex) {
...
...
api/source/mk_track.cpp
查看文件 @
d04761c2
...
...
@@ -115,12 +115,10 @@ API_EXPORT int API_CALL mk_track_bit_rate(mk_track track) {
API_EXPORT
void
*
API_CALL
mk_track_add_delegate
(
mk_track
track
,
on_mk_frame_out
cb
,
void
*
user_data
)
{
assert
(
track
&&
cb
);
auto
delegate
=
std
::
make_shared
<
FrameWriterInterfaceHelper
>
([
cb
,
user_data
](
const
Frame
::
Ptr
&
frame
)
{
return
(
*
((
Track
::
Ptr
*
)
track
))
->
addDelegate
([
cb
,
user_data
](
const
Frame
::
Ptr
&
frame
)
{
cb
(
user_data
,
(
mk_frame
)
&
frame
);
return
true
;
});
(
*
((
Track
::
Ptr
*
)
track
))
->
addDelegate
(
delegate
);
return
delegate
.
get
();
}
API_EXPORT
void
API_CALL
mk_track_del_delegate
(
mk_track
track
,
void
*
tag
)
{
...
...
player/test_player.cpp
查看文件 @
d04761c2
...
...
@@ -83,10 +83,9 @@ int main(int argc, char *argv[]) {
return
true
;
});
});
auto
delegate
=
std
::
make_shared
<
FrameWriterInterfaceHelper
>
([
decoder
](
const
Frame
::
Ptr
&
frame
)
{
videoTrack
->
addDelegate
([
decoder
](
const
Frame
::
Ptr
&
frame
)
{
return
decoder
->
inputFrame
(
frame
,
false
,
true
);
});
videoTrack
->
addDelegate
(
delegate
);
}
if
(
audioTrack
)
{
...
...
@@ -105,10 +104,9 @@ int main(int argc, char *argv[]) {
auto
len
=
pcm
->
get
()
->
nb_samples
*
pcm
->
get
()
->
channels
*
av_get_bytes_per_sample
((
enum
AVSampleFormat
)
pcm
->
get
()
->
format
);
audio_player
->
playPCM
((
const
char
*
)
(
pcm
->
get
()
->
data
[
0
]),
MIN
(
len
,
frame
->
get
()
->
linesize
[
0
]));
});
au
to
audio_delegate
=
std
::
make_shared
<
FrameWriterInterfaceHelper
>
(
[
decoder
](
const
Frame
::
Ptr
&
frame
)
{
au
dioTrack
->
addDelegate
(
[
decoder
](
const
Frame
::
Ptr
&
frame
)
{
return
decoder
->
inputFrame
(
frame
,
false
,
true
);
});
audioTrack
->
addDelegate
(
audio_delegate
);
}
});
...
...
src/Common/MediaSink.cpp
查看文件 @
d04761c2
...
...
@@ -37,7 +37,7 @@ bool MediaSink::addTrack(const Track::Ptr &track_in) {
};
_ticker
.
resetTime
();
track
->
addDelegate
(
std
::
make_shared
<
FrameWriterInterfaceHelper
>
(
[
this
](
const
Frame
::
Ptr
&
frame
)
{
track
->
addDelegate
([
this
](
const
Frame
::
Ptr
&
frame
)
{
if
(
_all_track_ready
)
{
return
onTrackFrame
(
frame
);
}
...
...
@@ -52,7 +52,7 @@ bool MediaSink::addTrack(const Track::Ptr &track_in) {
//还有Track未就绪,先缓存之
frame_unread
.
emplace_back
(
Frame
::
getCacheAbleFrame
(
frame
));
return
true
;
})
)
;
});
return
true
;
}
...
...
@@ -247,13 +247,13 @@ bool MediaSink::addMuteAudioTrack() {
}
auto
audio
=
std
::
make_shared
<
AACTrack
>
(
makeAacConfig
(
MUTE_ADTS_DATA
,
ADTS_HEADER_LEN
));
_track_map
[
audio
->
getTrackType
()]
=
std
::
make_pair
(
audio
,
true
);
audio
->
addDelegate
(
std
::
make_shared
<
FrameWriterInterfaceHelper
>
(
[
this
](
const
Frame
::
Ptr
&
frame
)
{
audio
->
addDelegate
([
this
](
const
Frame
::
Ptr
&
frame
)
{
return
onTrackFrame
(
frame
);
})
)
;
});
_mute_audio_maker
=
std
::
make_shared
<
MuteAudioMaker
>
();
_mute_audio_maker
->
addDelegate
(
std
::
make_shared
<
FrameWriterInterfaceHelper
>
(
[
audio
](
const
Frame
::
Ptr
&
frame
)
{
_mute_audio_maker
->
addDelegate
([
audio
](
const
Frame
::
Ptr
&
frame
)
{
return
audio
->
inputFrame
(
frame
);
})
)
;
});
onTrackReady
(
audio
);
TraceL
<<
"mute aac track added"
;
return
true
;
...
...
src/Extension/Frame.cpp
查看文件 @
d04761c2
...
...
@@ -210,5 +210,39 @@ void FrameMerger::flush() {
}
clear
();
}
/**
* 写帧接口转function,辅助类
*/
class
FrameWriterInterfaceHelper
:
public
FrameWriterInterface
{
public
:
typedef
std
::
shared_ptr
<
FrameWriterInterfaceHelper
>
Ptr
;
typedef
std
::
function
<
bool
(
const
Frame
::
Ptr
&
frame
)
>
onWriteFrame
;
/**
* inputFrame后触发onWriteFrame回调
*/
FrameWriterInterfaceHelper
(
const
onWriteFrame
&
cb
){
_writeCallback
=
cb
;
}
virtual
~
FrameWriterInterfaceHelper
(){}
/**
* 写入帧数据
*/
bool
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
{
return
_writeCallback
(
frame
);
}
private
:
onWriteFrame
_writeCallback
;
};
FrameWriterInterface
*
FrameDispatcher
::
addDelegate
(
const
std
::
function
<
bool
(
const
Frame
::
Ptr
&
frame
)
>
&
cb
)
{
auto
delegate
=
std
::
make_shared
<
FrameWriterInterfaceHelper
>
(
cb
);
std
::
lock_guard
<
std
::
mutex
>
lck
(
_mtx
);
_delegates
.
emplace
(
delegate
.
get
(),
delegate
);
return
delegate
.
get
();
}
}
//namespace mediakit
src/Extension/Frame.h
查看文件 @
d04761c2
...
...
@@ -279,29 +279,6 @@ public:
};
/**
* 写帧接口转function,辅助类
*/
class
FrameWriterInterfaceHelper
:
public
FrameWriterInterface
{
public
:
typedef
std
::
shared_ptr
<
FrameWriterInterfaceHelper
>
Ptr
;
typedef
std
::
function
<
bool
(
const
Frame
::
Ptr
&
frame
)
>
onWriteFrame
;
/**
* inputFrame后触发onWriteFrame回调
*/
FrameWriterInterfaceHelper
(
const
onWriteFrame
&
cb
)
{
_writeCallback
=
cb
;
}
virtual
~
FrameWriterInterfaceHelper
()
=
default
;
/**
* 写入帧数据
*/
bool
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
{
return
_writeCallback
(
frame
);
}
private
:
onWriteFrame
_writeCallback
;
};
/**
* 支持代理转发的帧环形缓存
*/
class
FrameDispatcher
:
public
FrameWriterInterface
{
...
...
@@ -318,6 +295,7 @@ public:
_delegates
.
emplace
(
delegate
.
get
(),
delegate
);
}
FrameWriterInterface
*
addDelegate
(
const
std
::
function
<
bool
(
const
Frame
::
Ptr
&
frame
)
>
&
cb
);
/**
* 删除代理
*/
...
...
src/Player/PlayerBase.cpp
查看文件 @
d04761c2
...
...
@@ -112,9 +112,9 @@ bool Demuxer::addTrack(const Track::Ptr &track) {
}
if
(
_sink
->
addTrack
(
track
))
{
track
->
addDelegate
(
std
::
make_shared
<
FrameWriterInterfaceHelper
>
(
[
this
](
const
Frame
::
Ptr
&
frame
)
{
track
->
addDelegate
([
this
](
const
Frame
::
Ptr
&
frame
)
{
return
_sink
->
inputFrame
(
frame
);
})
)
;
});
return
true
;
}
return
false
;
...
...
src/Rtp/GB28181Process.cpp
查看文件 @
d04761c2
...
...
@@ -136,10 +136,10 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
}
}
// 设置frame回调
_rtp_decoder
[
pt
]
->
addDelegate
(
std
::
make_shared
<
FrameWriterInterfaceHelper
>
(
[
this
](
const
Frame
::
Ptr
&
frame
)
{
_rtp_decoder
[
pt
]
->
addDelegate
([
this
](
const
Frame
::
Ptr
&
frame
)
{
onRtpDecode
(
frame
);
return
true
;
})
)
;
});
}
return
ref
->
inputRtp
(
TrackVideo
,
(
unsigned
char
*
)
data
,
data_len
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论