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
d8a11734
Commit
d8a11734
authored
Oct 29, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DevChannle对象替换成MultiMediaSourceMuxer对象
parent
3bf1a9fd
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
35 行增加
和
37 行删除
+35
-37
src/MediaFile/MediaReader.cpp
+8
-8
src/MediaFile/MediaReader.h
+14
-16
src/Player/PlayerProxy.cpp
+12
-12
src/Player/PlayerProxy.h
+1
-1
没有找到文件。
src/MediaFile/MediaReader.cpp
查看文件 @
d8a11734
...
...
@@ -127,15 +127,15 @@ MediaReader::MediaReader(const string &strVhost,const string &strApp, const stri
}
_iDuration
=
MAX
(
_video_ms
,
_audio_ms
);
_
pChn
.
reset
(
new
DevChannel
(
strVhost
.
data
(),
strApp
.
data
(),
strId
.
data
(),
_iDuration
/
1000.0
,
false
,
false
));
_
mediaMuxer
.
reset
(
new
MultiMediaSourceMuxer
(
strVhost
.
data
(),
strApp
.
data
(),
strId
.
data
(),
_iDuration
/
1000.0
,
false
,
false
));
if
(
_audio_trId
!=
MP4_INVALID_TRACK_ID
)
{
AACTrack
::
Ptr
track
=
std
::
make_shared
<
AACTrack
>
(
_strAacCfg
);
_
pChn
->
addTrack
(
track
);
_
mediaMuxer
->
addTrack
(
track
);
}
if
(
_video_trId
!=
MP4_INVALID_TRACK_ID
)
{
H264Track
::
Ptr
track
=
std
::
make_shared
<
H264Track
>
(
_strSps
,
_strPps
);
_
pChn
->
addTrack
(
track
);
_
mediaMuxer
->
addTrack
(
track
);
}
}
...
...
@@ -155,7 +155,7 @@ void MediaReader::startReadMP4() {
AsyncTaskThread
::
Instance
().
DoTaskDelay
(
reinterpret_cast
<
uint64_t
>
(
this
),
sampleMS
,
[
strongSelf
](){
return
strongSelf
->
readSample
();
});
_
pChn
->
setListener
(
strongSelf
);
_
mediaMuxer
->
setListener
(
strongSelf
);
}
bool
MediaReader
::
seekTo
(
uint32_t
ui32Stamp
){
seek
(
ui32Stamp
);
...
...
@@ -171,7 +171,7 @@ bool MediaReader::readSample(int iTimeInc) {
lock_guard
<
recursive_mutex
>
lck
(
_mtx
);
auto
bFlag0
=
readVideoSample
(
iTimeInc
);
//数据没读完
auto
bFlag1
=
readAudioSample
(
iTimeInc
);
//数据没读完
auto
bFlag2
=
_
pChn
->
readerCount
()
>
0
;
//读取者大于0
auto
bFlag2
=
_
mediaMuxer
->
readerCount
()
>
0
;
//读取者大于0
if
((
bFlag0
||
bFlag1
)
&&
bFlag2
){
_alive
.
resetTime
();
}
...
...
@@ -236,11 +236,11 @@ inline bool MediaReader::readAudioSample(int iTimeInc) {
}
inline
void
MediaReader
::
writeH264
(
uint8_t
*
pucData
,
int
iLen
,
uint32_t
uiStamp
)
{
_
pChn
->
inputFrame
(
std
::
make_shared
<
H264FrameNoCopyAble
>
((
char
*
)
pucData
,
iLen
,
uiStamp
));
_
mediaMuxer
->
inputFrame
(
std
::
make_shared
<
H264FrameNoCopyAble
>
((
char
*
)
pucData
,
iLen
,
uiStamp
));
}
inline
void
MediaReader
::
writeAAC
(
uint8_t
*
pucData
,
int
iLen
,
uint32_t
uiStamp
)
{
_
pChn
->
inputFrame
(
std
::
make_shared
<
AACFrameNoCopyAble
>
((
char
*
)
pucData
,
iLen
,
uiStamp
));
_
mediaMuxer
->
inputFrame
(
std
::
make_shared
<
AACFrameNoCopyAble
>
((
char
*
)
pucData
,
iLen
,
uiStamp
));
}
inline
MP4SampleId
MediaReader
::
getVideoSampleId
(
int
iTimeInc
)
{
...
...
@@ -287,7 +287,7 @@ void MediaReader::seek(uint32_t iSeekTime,bool bReStart){
setSeekTime
(
iSeekTime
);
}
}
_
pChn
->
setTimeStamp
(
_iSeekTime
);
_
mediaMuxer
->
setTimeStamp
(
_iSeekTime
);
if
(
bReStart
){
AsyncTaskThread
::
Instance
().
CancelTask
(
reinterpret_cast
<
uint64_t
>
(
this
));
...
...
src/MediaFile/MediaReader.h
查看文件 @
d8a11734
...
...
@@ -47,9 +47,21 @@ public:
public
:
bool
seekTo
(
uint32_t
ui32Stamp
)
override
;
bool
close
()
override
;
private
:
#ifdef ENABLE_MP4V2
private
:
void
seek
(
uint32_t
iSeekTime
,
bool
bReStart
=
true
);
inline
void
setSeekTime
(
uint32_t
iSeekTime
);
inline
uint32_t
getVideoCurrentTime
();
void
startReadMP4
();
inline
MP4SampleId
getVideoSampleId
(
int
iTimeInc
=
0
);
inline
MP4SampleId
getAudioSampleId
(
int
iTimeInc
=
0
);
bool
readSample
(
int
iTimeInc
=
0
);
inline
bool
readVideoSample
(
int
iTimeInc
=
0
);
inline
bool
readAudioSample
(
int
iTimeInc
=
0
);
inline
void
writeH264
(
uint8_t
*
pucData
,
int
iLen
,
uint32_t
uiStamp
);
inline
void
writeAAC
(
uint8_t
*
pucData
,
int
iLen
,
uint32_t
uiStamp
);
private
:
MP4FileHandle
_hMP4File
=
MP4_INVALID_FILE_HANDLE
;
MP4TrackId
_video_trId
=
MP4_INVALID_TRACK_ID
;
uint32_t
_video_ms
=
0
;
...
...
@@ -72,7 +84,7 @@ private:
AACFrame
_adts
;
int
_iDuration
=
0
;
DevChannel
::
Ptr
_pChn
;
MultiMediaSourceMuxer
::
Ptr
_mediaMuxer
;
MP4SampleId
_video_current
=
0
;
MP4SampleId
_audio_current
=
0
;
std
::
shared_ptr
<
uint8_t
>
_pcVideoSample
;
...
...
@@ -81,20 +93,6 @@ private:
Ticker
_ticker
;
Ticker
_alive
;
recursive_mutex
_mtx
;
void
seek
(
uint32_t
iSeekTime
,
bool
bReStart
=
true
);
inline
void
setSeekTime
(
uint32_t
iSeekTime
);
inline
uint32_t
getVideoCurrentTime
();
void
startReadMP4
();
inline
MP4SampleId
getVideoSampleId
(
int
iTimeInc
=
0
);
inline
MP4SampleId
getAudioSampleId
(
int
iTimeInc
=
0
);
bool
readSample
(
int
iTimeInc
=
0
);
inline
bool
readVideoSample
(
int
iTimeInc
=
0
);
inline
bool
readAudioSample
(
int
iTimeInc
=
0
);
inline
void
writeH264
(
uint8_t
*
pucData
,
int
iLen
,
uint32_t
uiStamp
);
inline
void
writeAAC
(
uint8_t
*
pucData
,
int
iLen
,
uint32_t
uiStamp
);
#endif //ENABLE_MP4V2
};
...
...
src/Player/PlayerProxy.cpp
查看文件 @
d8a11734
...
...
@@ -99,12 +99,12 @@ void PlayerProxy::play(const char* strUrl) {
if
(
!
strongSelf
)
{
return
;
}
if
(
strongSelf
->
_
pChn
)
{
if
(
strongSelf
->
_
mediaMuxer
)
{
auto
tracks
=
strongSelf
->
getTracks
();
for
(
auto
&
track
:
tracks
){
track
->
delDelegate
(
strongSelf
->
_
pChn
.
get
());
track
->
delDelegate
(
strongSelf
->
_
mediaMuxer
.
get
());
}
strongSelf
->
_
pChn
.
reset
();
strongSelf
->
_
mediaMuxer
.
reset
();
}
//播放异常中断,延时重试播放
if
(
*
piFailedCnt
<
strongSelf
->
_iRetryCount
||
strongSelf
->
_iRetryCount
<
0
)
{
...
...
@@ -142,7 +142,7 @@ bool PlayerProxy::close() {
executor
->
async_first
([
weakSlef
]()
{
auto
stronSelf
=
weakSlef
.
lock
();
if
(
stronSelf
)
{
stronSelf
->
_
pChn
.
reset
();
stronSelf
->
_
mediaMuxer
.
reset
();
stronSelf
->
teardown
();
}
});
...
...
@@ -174,32 +174,32 @@ private:
};
void
PlayerProxy
::
onPlaySuccess
()
{
_
pChn
.
reset
(
new
DevChannel
(
_strVhost
.
data
(),
_strApp
.
data
(),
_strSrc
.
data
(),
getDuration
(),
_bEnableHls
,
_bEnableMp4
));
_
pChn
->
setListener
(
shared_from_this
());
_
mediaMuxer
.
reset
(
new
MultiMediaSourceMuxer
(
_strVhost
.
data
(),
_strApp
.
data
(),
_strSrc
.
data
(),
getDuration
(),
_bEnableHls
,
_bEnableMp4
));
_
mediaMuxer
->
setListener
(
shared_from_this
());
auto
videoTrack
=
getTrack
(
TrackVideo
);
if
(
videoTrack
){
//添加视频
_
pChn
->
addTrack
(
videoTrack
);
_
mediaMuxer
->
addTrack
(
videoTrack
);
//视频数据写入_pChn
videoTrack
->
addDelegate
(
_
pChn
);
videoTrack
->
addDelegate
(
_
mediaMuxer
);
}
auto
audioTrack
=
getTrack
(
TrackAudio
);
if
(
audioTrack
){
//添加音频
_
pChn
->
addTrack
(
audioTrack
);
_
mediaMuxer
->
addTrack
(
audioTrack
);
//音频数据写入_pChn
audioTrack
->
addDelegate
(
_
pChn
);
audioTrack
->
addDelegate
(
_
mediaMuxer
);
}
else
if
(
videoTrack
){
//没有音频信息,产生一个静音音频
MuteAudioMaker
::
Ptr
audioMaker
=
std
::
make_shared
<
MuteAudioMaker
>
();
//videoTrack把数据写入MuteAudioMaker
videoTrack
->
addDelegate
(
audioMaker
);
//添加一个静音Track至_pChn
_
pChn
->
addTrack
(
std
::
make_shared
<
AACTrack
>
());
_
mediaMuxer
->
addTrack
(
std
::
make_shared
<
AACTrack
>
());
//MuteAudioMaker生成静音音频然后写入_pChn;
audioMaker
->
addDelegate
(
_
pChn
);
audioMaker
->
addDelegate
(
_
mediaMuxer
);
}
}
...
...
src/Player/PlayerProxy.h
查看文件 @
d8a11734
...
...
@@ -64,7 +64,7 @@ private:
bool
_bEnableHls
;
bool
_bEnableMp4
;
int
_iRetryCount
;
DevChannel
::
Ptr
_pChn
;
MultiMediaSourceMuxer
::
Ptr
_mediaMuxer
;
string
_strVhost
;
string
_strApp
;
string
_strSrc
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论