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
68926b4a
Commit
68926b4a
authored
Dec 04, 2020
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持bitrate
parent
42679cdf
隐藏空白字符变更
内嵌
并排
正在显示
23 个修改的文件
包含
104 行增加
和
52 行删除
+104
-52
src/Common/MediaSource.cpp
+5
-2
src/Common/MediaSource.h
+2
-2
src/Extension/AAC.cpp
+2
-1
src/Extension/AAC.h
+5
-3
src/Extension/G711.cpp
+1
-1
src/Extension/G711.h
+5
-2
src/Extension/H264.cpp
+1
-1
src/Extension/H264.h
+5
-3
src/Extension/H265.cpp
+1
-1
src/Extension/H265.h
+5
-3
src/Extension/Opus.cpp
+2
-1
src/Extension/Opus.h
+5
-2
src/Extension/Track.h
+18
-10
src/FMP4/FMP4MediaSource.h
+1
-1
src/Record/HlsMediaSource.h
+1
-1
src/Rtmp/Rtmp.cpp
+8
-4
src/Rtmp/Rtmp.h
+2
-2
src/Rtmp/RtmpDemuxer.cpp
+18
-6
src/Rtmp/RtmpDemuxer.h
+2
-2
src/Rtmp/RtmpMediaSource.h
+2
-2
src/Rtsp/RtspDemuxer.cpp
+11
-0
src/Rtsp/RtspMediaSource.h
+1
-1
src/TS/TSMediaSource.h
+1
-1
没有找到文件。
src/Common/MediaSource.cpp
查看文件 @
68926b4a
...
@@ -68,8 +68,11 @@ const string& MediaSource::getId() const {
...
@@ -68,8 +68,11 @@ const string& MediaSource::getId() const {
return
_stream_id
;
return
_stream_id
;
}
}
int
MediaSource
::
getBytesSpeed
(){
int
MediaSource
::
getBytesSpeed
(
TrackType
type
){
return
_speed
.
getSpeed
();
if
(
type
==
TrackInvalid
){
return
_speed
[
TrackVideo
].
getSpeed
()
+
_speed
[
TrackAudio
].
getSpeed
();
}
return
_speed
[
type
].
getSpeed
();
}
}
uint64_t
MediaSource
::
getCreateStamp
()
const
{
uint64_t
MediaSource
::
getCreateStamp
()
const
{
...
...
src/Common/MediaSource.h
查看文件 @
68926b4a
...
@@ -220,7 +220,7 @@ public:
...
@@ -220,7 +220,7 @@ public:
virtual
void
setTimeStamp
(
uint32_t
stamp
)
{};
virtual
void
setTimeStamp
(
uint32_t
stamp
)
{};
// 获取数据速率,单位bytes/s
// 获取数据速率,单位bytes/s
int
getBytesSpeed
();
int
getBytesSpeed
(
TrackType
type
=
TrackInvalid
);
// 获取流创建GMT unix时间戳,单位秒
// 获取流创建GMT unix时间戳,单位秒
uint64_t
getCreateStamp
()
const
;
uint64_t
getCreateStamp
()
const
;
// 获取流上线时间,单位秒
// 获取流上线时间,单位秒
...
@@ -286,7 +286,7 @@ private:
...
@@ -286,7 +286,7 @@ private:
void
emitEvent
(
bool
regist
);
void
emitEvent
(
bool
regist
);
protected
:
protected
:
BytesSpeed
_speed
;
BytesSpeed
_speed
[
TrackMax
]
;
private
:
private
:
time_t
_create_stamp
;
time_t
_create_stamp
;
...
...
src/Extension/AAC.cpp
查看文件 @
68926b4a
...
@@ -185,7 +185,7 @@ Sdp::Ptr AACTrack::getSdp() {
...
@@ -185,7 +185,7 @@ Sdp::Ptr AACTrack::getSdp() {
WarnL
<<
getCodecName
()
<<
" Track未准备好"
;
WarnL
<<
getCodecName
()
<<
" Track未准备好"
;
return
nullptr
;
return
nullptr
;
}
}
return
std
::
make_shared
<
AACSdp
>
(
getAacCfg
(),
getAudioSampleRate
(),
getAudioChannel
()
);
return
std
::
make_shared
<
AACSdp
>
(
getAacCfg
(),
getAudioSampleRate
(),
getAudioChannel
(),
getBitRate
()
/
1024
);
}
}
}
//
namespace
mediakit
}
//
namespace
mediakit
\ No newline at end of file
src/Extension/AAC.h
查看文件 @
68926b4a
...
@@ -177,10 +177,12 @@ public:
...
@@ -177,10 +177,12 @@ public:
AACSdp
(
const
string
&
aac_cfg
,
AACSdp
(
const
string
&
aac_cfg
,
int
sample_rate
,
int
sample_rate
,
int
channels
,
int
channels
,
int
payload_type
=
9
8
,
int
bitrate
=
12
8
,
int
bitrate
=
12
8
)
:
Sdp
(
sample_rate
,
payload_type
){
int
payload_type
=
9
8
)
:
Sdp
(
sample_rate
,
payload_type
){
_printer
<<
"m=audio 0 RTP/AVP "
<<
payload_type
<<
"
\r\n
"
;
_printer
<<
"m=audio 0 RTP/AVP "
<<
payload_type
<<
"
\r\n
"
;
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
if
(
bitrate
)
{
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
}
_printer
<<
"a=rtpmap:"
<<
payload_type
<<
" MPEG4-GENERIC/"
<<
sample_rate
<<
"/"
<<
channels
<<
"
\r\n
"
;
_printer
<<
"a=rtpmap:"
<<
payload_type
<<
" MPEG4-GENERIC/"
<<
sample_rate
<<
"/"
<<
channels
<<
"
\r\n
"
;
string
configStr
;
string
configStr
;
...
...
src/Extension/G711.cpp
查看文件 @
68926b4a
...
@@ -17,7 +17,7 @@ Sdp::Ptr G711Track::getSdp() {
...
@@ -17,7 +17,7 @@ Sdp::Ptr G711Track::getSdp() {
WarnL
<<
getCodecName
()
<<
" Track未准备好"
;
WarnL
<<
getCodecName
()
<<
" Track未准备好"
;
return
nullptr
;
return
nullptr
;
}
}
return
std
::
make_shared
<
G711Sdp
>
(
getCodecId
(),
getAudioSampleRate
(),
getAudioChannel
());
return
std
::
make_shared
<
G711Sdp
>
(
getCodecId
(),
getAudioSampleRate
(),
getAudioChannel
()
,
getBitRate
()
/
1024
);
}
}
}
//namespace mediakit
}
//namespace mediakit
...
...
src/Extension/G711.h
查看文件 @
68926b4a
...
@@ -48,9 +48,12 @@ public:
...
@@ -48,9 +48,12 @@ public:
G711Sdp
(
CodecId
codecId
,
G711Sdp
(
CodecId
codecId
,
int
sample_rate
,
int
sample_rate
,
int
channels
,
int
channels
,
int
payload_type
=
9
8
,
int
bitrate
=
12
8
,
int
bitrate
=
12
8
)
:
Sdp
(
sample_rate
,
payload_type
),
_codecId
(
codecId
){
int
payload_type
=
9
8
)
:
Sdp
(
sample_rate
,
payload_type
),
_codecId
(
codecId
){
_printer
<<
"m=audio 0 RTP/AVP "
<<
payload_type
<<
"
\r\n
"
;
_printer
<<
"m=audio 0 RTP/AVP "
<<
payload_type
<<
"
\r\n
"
;
if
(
bitrate
)
{
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
}
_printer
<<
"a=rtpmap:"
<<
payload_type
<<
(
codecId
==
CodecG711A
?
" PCMA/"
:
" PCMU/"
)
<<
sample_rate
<<
"/"
<<
channels
<<
"
\r\n
"
;
_printer
<<
"a=rtpmap:"
<<
payload_type
<<
(
codecId
==
CodecG711A
?
" PCMA/"
:
" PCMU/"
)
<<
sample_rate
<<
"/"
<<
channels
<<
"
\r\n
"
;
_printer
<<
"a=control:trackID="
<<
(
int
)
TrackAudio
<<
"
\r\n
"
;
_printer
<<
"a=control:trackID="
<<
(
int
)
TrackAudio
<<
"
\r\n
"
;
}
}
...
...
src/Extension/H264.cpp
查看文件 @
68926b4a
...
@@ -123,7 +123,7 @@ Sdp::Ptr H264Track::getSdp() {
...
@@ -123,7 +123,7 @@ Sdp::Ptr H264Track::getSdp() {
WarnL
<<
getCodecName
()
<<
" Track未准备好"
;
WarnL
<<
getCodecName
()
<<
" Track未准备好"
;
return
nullptr
;
return
nullptr
;
}
}
return
std
::
make_shared
<
H264Sdp
>
(
getSps
(),
getPps
()
);
return
std
::
make_shared
<
H264Sdp
>
(
getSps
(),
getPps
(),
getBitRate
()
/
1024
);
}
}
}
//namespace mediakit
}
//namespace mediakit
...
...
src/Extension/H264.h
查看文件 @
68926b4a
...
@@ -292,11 +292,13 @@ public:
...
@@ -292,11 +292,13 @@ public:
*/
*/
H264Sdp
(
const
string
&
strSPS
,
H264Sdp
(
const
string
&
strSPS
,
const
string
&
strPPS
,
const
string
&
strPPS
,
int
payload_type
=
96
,
int
bitrate
=
4000
,
int
bitrate
=
4000
)
:
Sdp
(
90000
,
payload_type
)
{
int
payload_type
=
96
)
:
Sdp
(
90000
,
payload_type
)
{
//视频通道
//视频通道
_printer
<<
"m=video 0 RTP/AVP "
<<
payload_type
<<
"
\r\n
"
;
_printer
<<
"m=video 0 RTP/AVP "
<<
payload_type
<<
"
\r\n
"
;
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
if
(
bitrate
)
{
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
}
_printer
<<
"a=rtpmap:"
<<
payload_type
<<
" H264/"
<<
90000
<<
"
\r\n
"
;
_printer
<<
"a=rtpmap:"
<<
payload_type
<<
" H264/"
<<
90000
<<
"
\r\n
"
;
_printer
<<
"a=fmtp:"
<<
payload_type
<<
" packetization-mode=1; profile-level-id="
;
_printer
<<
"a=fmtp:"
<<
payload_type
<<
" packetization-mode=1; profile-level-id="
;
...
...
src/Extension/H265.cpp
查看文件 @
68926b4a
...
@@ -55,7 +55,7 @@ Sdp::Ptr H265Track::getSdp() {
...
@@ -55,7 +55,7 @@ Sdp::Ptr H265Track::getSdp() {
WarnL
<<
getCodecName
()
<<
" Track未准备好"
;
WarnL
<<
getCodecName
()
<<
" Track未准备好"
;
return
nullptr
;
return
nullptr
;
}
}
return
std
::
make_shared
<
H265Sdp
>
(
getVps
(),
getSps
(),
getPps
()
);
return
std
::
make_shared
<
H265Sdp
>
(
getVps
(),
getSps
(),
getPps
(),
getBitRate
()
/
1024
);
}
}
}
//namespace mediakit
}
//namespace mediakit
src/Extension/H265.h
查看文件 @
68926b4a
...
@@ -321,11 +321,13 @@ public:
...
@@ -321,11 +321,13 @@ public:
H265Sdp
(
const
string
&
strVPS
,
H265Sdp
(
const
string
&
strVPS
,
const
string
&
strSPS
,
const
string
&
strSPS
,
const
string
&
strPPS
,
const
string
&
strPPS
,
int
payload_type
=
96
,
int
bitrate
=
4000
,
int
bitrate
=
4000
)
:
Sdp
(
90000
,
payload_type
)
{
int
payload_type
=
96
)
:
Sdp
(
90000
,
payload_type
)
{
//视频通道
//视频通道
_printer
<<
"m=video 0 RTP/AVP "
<<
payload_type
<<
"
\r\n
"
;
_printer
<<
"m=video 0 RTP/AVP "
<<
payload_type
<<
"
\r\n
"
;
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
if
(
bitrate
)
{
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
}
_printer
<<
"a=rtpmap:"
<<
payload_type
<<
" H265/"
<<
90000
<<
"
\r\n
"
;
_printer
<<
"a=rtpmap:"
<<
payload_type
<<
" H265/"
<<
90000
<<
"
\r\n
"
;
_printer
<<
"a=fmtp:"
<<
payload_type
<<
" "
;
_printer
<<
"a=fmtp:"
<<
payload_type
<<
" "
;
_printer
<<
"sprop-vps="
;
_printer
<<
"sprop-vps="
;
...
...
src/Extension/Opus.cpp
查看文件 @
68926b4a
...
@@ -17,7 +17,7 @@ Sdp::Ptr OpusTrack::getSdp() {
...
@@ -17,7 +17,7 @@ Sdp::Ptr OpusTrack::getSdp() {
WarnL
<<
getCodecName
()
<<
" Track未准备好"
;
WarnL
<<
getCodecName
()
<<
" Track未准备好"
;
return
nullptr
;
return
nullptr
;
}
}
return
std
::
make_shared
<
OpusSdp
>
(
getAudioSampleRate
(),
getAudioChannel
());
return
std
::
make_shared
<
OpusSdp
>
(
getAudioSampleRate
(),
getAudioChannel
()
,
getBitRate
()
/
1024
);
}
}
}
//
namespace
mediakit
}
//
namespace
mediakit
\ No newline at end of file
src/Extension/Opus.h
查看文件 @
68926b4a
...
@@ -46,9 +46,12 @@ public:
...
@@ -46,9 +46,12 @@ public:
*/
*/
OpusSdp
(
int
sample_rate
,
OpusSdp
(
int
sample_rate
,
int
channels
,
int
channels
,
int
payload_type
=
9
8
,
int
bitrate
=
12
8
,
int
bitrate
=
12
8
)
:
Sdp
(
sample_rate
,
payload_type
){
int
payload_type
=
9
8
)
:
Sdp
(
sample_rate
,
payload_type
){
_printer
<<
"m=audio 0 RTP/AVP "
<<
payload_type
<<
"
\r\n
"
;
_printer
<<
"m=audio 0 RTP/AVP "
<<
payload_type
<<
"
\r\n
"
;
if
(
bitrate
)
{
_printer
<<
"b=AS:"
<<
bitrate
<<
"
\r\n
"
;
}
_printer
<<
"a=rtpmap:"
<<
payload_type
<<
" opus/"
<<
sample_rate
<<
"/"
<<
channels
<<
"
\r\n
"
;
_printer
<<
"a=rtpmap:"
<<
payload_type
<<
" opus/"
<<
sample_rate
<<
"/"
<<
channels
<<
"
\r\n
"
;
_printer
<<
"a=control:trackID="
<<
(
int
)
TrackAudio
<<
"
\r\n
"
;
_printer
<<
"a=control:trackID="
<<
(
int
)
TrackAudio
<<
"
\r\n
"
;
}
}
...
...
src/Extension/Track.h
查看文件 @
68926b4a
...
@@ -32,7 +32,6 @@ public:
...
@@ -32,7 +32,6 @@ public:
/**
/**
* 是否准备好,准备好才能获取譬如sps pps等信息
* 是否准备好,准备好才能获取譬如sps pps等信息
* @return
*/
*/
virtual
bool
ready
()
=
0
;
virtual
bool
ready
()
=
0
;
...
@@ -40,7 +39,6 @@ public:
...
@@ -40,7 +39,6 @@ public:
* 克隆接口,用于复制本对象用
* 克隆接口,用于复制本对象用
* 在调用该接口时只会复制派生类的信息
* 在调用该接口时只会复制派生类的信息
* 环形缓存和代理关系不能拷贝,否则会关系紊乱
* 环形缓存和代理关系不能拷贝,否则会关系紊乱
* @return
*/
*/
virtual
Track
::
Ptr
clone
()
=
0
;
virtual
Track
::
Ptr
clone
()
=
0
;
...
@@ -51,11 +49,27 @@ public:
...
@@ -51,11 +49,27 @@ public:
virtual
Sdp
::
Ptr
getSdp
()
=
0
;
virtual
Sdp
::
Ptr
getSdp
()
=
0
;
/**
/**
* 返回比特率
* @return 比特率
*/
virtual
int
getBitRate
()
const
{
return
_bit_rate
;
}
/**
* 设置比特率
* @param bit_rate 比特率
*/
virtual
void
setBitRate
(
int
bit_rate
)
{
_bit_rate
=
bit_rate
;
}
/**
* 复制拷贝,只能拷贝派生类的信息,
* 复制拷贝,只能拷贝派生类的信息,
* 环形缓存和代理关系不能拷贝,否则会关系紊乱
* 环形缓存和代理关系不能拷贝,否则会关系紊乱
* @param that
*/
*/
Track
(
const
Track
&
that
){}
Track
(
const
Track
&
that
){
_bit_rate
=
that
.
_bit_rate
;
}
private
:
int
_bit_rate
=
0
;
};
};
/**
/**
...
@@ -67,19 +81,16 @@ public:
...
@@ -67,19 +81,16 @@ public:
/**
/**
* 返回视频高度
* 返回视频高度
* @return
*/
*/
virtual
int
getVideoHeight
()
const
{
return
0
;};
virtual
int
getVideoHeight
()
const
{
return
0
;};
/**
/**
* 返回视频宽度
* 返回视频宽度
* @return
*/
*/
virtual
int
getVideoWidth
()
const
{
return
0
;};
virtual
int
getVideoWidth
()
const
{
return
0
;};
/**
/**
* 返回视频fps
* 返回视频fps
* @return
*/
*/
virtual
float
getVideoFps
()
const
{
return
0
;};
virtual
float
getVideoFps
()
const
{
return
0
;};
};
};
...
@@ -93,19 +104,16 @@ public:
...
@@ -93,19 +104,16 @@ public:
/**
/**
* 返回音频采样率
* 返回音频采样率
* @return
*/
*/
virtual
int
getAudioSampleRate
()
const
{
return
0
;};
virtual
int
getAudioSampleRate
()
const
{
return
0
;};
/**
/**
* 返回音频采样位数,一般为16或8
* 返回音频采样位数,一般为16或8
* @return
*/
*/
virtual
int
getAudioSampleBit
()
const
{
return
0
;};
virtual
int
getAudioSampleBit
()
const
{
return
0
;};
/**
/**
* 返回音频通道数
* 返回音频通道数
* @return
*/
*/
virtual
int
getAudioChannel
()
const
{
return
0
;};
virtual
int
getAudioChannel
()
const
{
return
0
;};
};
};
...
...
src/FMP4/FMP4MediaSource.h
查看文件 @
68926b4a
...
@@ -88,7 +88,7 @@ public:
...
@@ -88,7 +88,7 @@ public:
if
(
key
)
{
if
(
key
)
{
_have_video
=
true
;
_have_video
=
true
;
}
}
_speed
+=
packet
->
size
();
_speed
[
TrackVideo
]
+=
packet
->
size
();
auto
stamp
=
packet
->
time_stamp
;
auto
stamp
=
packet
->
time_stamp
;
PacketCache
<
FMP4Packet
>::
inputPacket
(
stamp
,
true
,
std
::
move
(
packet
),
key
);
PacketCache
<
FMP4Packet
>::
inputPacket
(
stamp
,
true
,
std
::
move
(
packet
),
key
);
}
}
...
...
src/Record/HlsMediaSource.h
查看文件 @
68926b4a
...
@@ -80,7 +80,7 @@ public:
...
@@ -80,7 +80,7 @@ public:
}
}
void
onSegmentSize
(
uint64_t
bytes
)
{
void
onSegmentSize
(
uint64_t
bytes
)
{
_speed
+=
bytes
;
_speed
[
TrackVideo
]
+=
bytes
;
}
}
private
:
private
:
...
...
src/Rtmp/Rtmp.cpp
查看文件 @
68926b4a
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
#include "Extension/Factory.h"
#include "Extension/Factory.h"
namespace
mediakit
{
namespace
mediakit
{
VideoMeta
::
VideoMeta
(
const
VideoTrack
::
Ptr
&
video
,
int
datarate
){
VideoMeta
::
VideoMeta
(
const
VideoTrack
::
Ptr
&
video
){
if
(
video
->
getVideoWidth
()
>
0
){
if
(
video
->
getVideoWidth
()
>
0
){
_metadata
.
set
(
"width"
,
video
->
getVideoWidth
());
_metadata
.
set
(
"width"
,
video
->
getVideoWidth
());
}
}
...
@@ -22,13 +22,17 @@ VideoMeta::VideoMeta(const VideoTrack::Ptr &video,int datarate ){
...
@@ -22,13 +22,17 @@ VideoMeta::VideoMeta(const VideoTrack::Ptr &video,int datarate ){
if
(
video
->
getVideoFps
()
>
0
){
if
(
video
->
getVideoFps
()
>
0
){
_metadata
.
set
(
"framerate"
,
video
->
getVideoFps
());
_metadata
.
set
(
"framerate"
,
video
->
getVideoFps
());
}
}
_metadata
.
set
(
"videodatarate"
,
datarate
);
if
(
video
->
getBitRate
())
{
_metadata
.
set
(
"videodatarate"
,
video
->
getBitRate
()
/
1024
);
}
_codecId
=
video
->
getCodecId
();
_codecId
=
video
->
getCodecId
();
_metadata
.
set
(
"videocodecid"
,
Factory
::
getAmfByCodecId
(
_codecId
));
_metadata
.
set
(
"videocodecid"
,
Factory
::
getAmfByCodecId
(
_codecId
));
}
}
AudioMeta
::
AudioMeta
(
const
AudioTrack
::
Ptr
&
audio
,
int
datarate
){
AudioMeta
::
AudioMeta
(
const
AudioTrack
::
Ptr
&
audio
){
_metadata
.
set
(
"audiodatarate"
,
datarate
);
if
(
audio
->
getBitRate
())
{
_metadata
.
set
(
"audiodatarate"
,
audio
->
getBitRate
()
/
1024
);
}
if
(
audio
->
getAudioSampleRate
()
>
0
){
if
(
audio
->
getAudioSampleRate
()
>
0
){
_metadata
.
set
(
"audiosamplerate"
,
audio
->
getAudioSampleRate
());
_metadata
.
set
(
"audiosamplerate"
,
audio
->
getAudioSampleRate
());
}
}
...
...
src/Rtmp/Rtmp.h
查看文件 @
68926b4a
...
@@ -261,7 +261,7 @@ class VideoMeta : public Metadata{
...
@@ -261,7 +261,7 @@ class VideoMeta : public Metadata{
public
:
public
:
typedef
std
::
shared_ptr
<
VideoMeta
>
Ptr
;
typedef
std
::
shared_ptr
<
VideoMeta
>
Ptr
;
VideoMeta
(
const
VideoTrack
::
Ptr
&
video
,
int
datarate
=
5000
);
VideoMeta
(
const
VideoTrack
::
Ptr
&
video
);
virtual
~
VideoMeta
(){}
virtual
~
VideoMeta
(){}
CodecId
getCodecId
()
const
override
{
CodecId
getCodecId
()
const
override
{
...
@@ -275,7 +275,7 @@ class AudioMeta : public Metadata{
...
@@ -275,7 +275,7 @@ class AudioMeta : public Metadata{
public
:
public
:
typedef
std
::
shared_ptr
<
AudioMeta
>
Ptr
;
typedef
std
::
shared_ptr
<
AudioMeta
>
Ptr
;
AudioMeta
(
const
AudioTrack
::
Ptr
&
audio
,
int
datarate
=
160
);
AudioMeta
(
const
AudioTrack
::
Ptr
&
audio
);
virtual
~
AudioMeta
(){}
virtual
~
AudioMeta
(){}
...
...
src/Rtmp/RtmpDemuxer.cpp
查看文件 @
68926b4a
...
@@ -19,6 +19,8 @@ bool RtmpDemuxer::loadMetaData(const AMFValue &val){
...
@@ -19,6 +19,8 @@ bool RtmpDemuxer::loadMetaData(const AMFValue &val){
int
audiosamplerate
=
0
;
int
audiosamplerate
=
0
;
int
audiochannels
=
0
;
int
audiochannels
=
0
;
int
audiosamplesize
=
0
;
int
audiosamplesize
=
0
;
int
videodatarate
=
0
;
int
audiodatarate
=
0
;
const
AMFValue
*
audiocodecid
=
nullptr
;
const
AMFValue
*
audiocodecid
=
nullptr
;
const
AMFValue
*
videocodecid
=
nullptr
;
const
AMFValue
*
videocodecid
=
nullptr
;
val
.
object_for_each
([
&
](
const
string
&
key
,
const
AMFValue
&
val
)
{
val
.
object_for_each
([
&
](
const
string
&
key
,
const
AMFValue
&
val
)
{
...
@@ -48,16 +50,24 @@ bool RtmpDemuxer::loadMetaData(const AMFValue &val){
...
@@ -48,16 +50,24 @@ bool RtmpDemuxer::loadMetaData(const AMFValue &val){
audiocodecid
=
&
val
;
audiocodecid
=
&
val
;
return
;
return
;
}
}
if
(
key
==
"audiodatarate"
)
{
audiodatarate
=
val
.
as_integer
();
return
;
}
if
(
key
==
"videodatarate"
)
{
videodatarate
=
val
.
as_integer
();
return
;
}
});
});
if
(
videocodecid
)
{
if
(
videocodecid
)
{
//有视频
//有视频
ret
=
true
;
ret
=
true
;
makeVideoTrack
(
*
videocodecid
);
makeVideoTrack
(
*
videocodecid
,
videodatarate
*
1024
);
}
}
if
(
audiocodecid
)
{
if
(
audiocodecid
)
{
//有音频
//有音频
ret
=
true
;
ret
=
true
;
makeAudioTrack
(
*
audiocodecid
,
audiosamplerate
,
audiochannels
,
audiosamplesize
);
makeAudioTrack
(
*
audiocodecid
,
audiosamplerate
,
audiochannels
,
audiosamplesize
,
audiodatarate
*
1024
);
}
}
}
catch
(
std
::
exception
&
ex
)
{
}
catch
(
std
::
exception
&
ex
)
{
WarnL
<<
ex
.
what
();
WarnL
<<
ex
.
what
();
...
@@ -71,7 +81,7 @@ void RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
...
@@ -71,7 +81,7 @@ void RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
if
(
!
_try_get_video_track
)
{
if
(
!
_try_get_video_track
)
{
_try_get_video_track
=
true
;
_try_get_video_track
=
true
;
auto
codec
=
AMFValue
(
pkt
->
getMediaType
());
auto
codec
=
AMFValue
(
pkt
->
getMediaType
());
makeVideoTrack
(
codec
);
makeVideoTrack
(
codec
,
0
);
}
}
if
(
_video_rtmp_decoder
)
{
if
(
_video_rtmp_decoder
)
{
_video_rtmp_decoder
->
inputRtmp
(
pkt
);
_video_rtmp_decoder
->
inputRtmp
(
pkt
);
...
@@ -83,7 +93,7 @@ void RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
...
@@ -83,7 +93,7 @@ void RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
if
(
!
_try_get_audio_track
)
{
if
(
!
_try_get_audio_track
)
{
_try_get_audio_track
=
true
;
_try_get_audio_track
=
true
;
auto
codec
=
AMFValue
(
pkt
->
getMediaType
());
auto
codec
=
AMFValue
(
pkt
->
getMediaType
());
makeAudioTrack
(
codec
,
pkt
->
getAudioSampleRate
(),
pkt
->
getAudioChannel
(),
pkt
->
getAudioSampleBit
());
makeAudioTrack
(
codec
,
pkt
->
getAudioSampleRate
(),
pkt
->
getAudioChannel
(),
pkt
->
getAudioSampleBit
()
,
0
);
}
}
if
(
_audio_rtmp_decoder
)
{
if
(
_audio_rtmp_decoder
)
{
_audio_rtmp_decoder
->
inputRtmp
(
pkt
);
_audio_rtmp_decoder
->
inputRtmp
(
pkt
);
...
@@ -94,10 +104,11 @@ void RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
...
@@ -94,10 +104,11 @@ void RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) {
}
}
}
}
void
RtmpDemuxer
::
makeVideoTrack
(
const
AMFValue
&
videoCodec
)
{
void
RtmpDemuxer
::
makeVideoTrack
(
const
AMFValue
&
videoCodec
,
int
bit_rate
)
{
//生成Track对象
//生成Track对象
_videoTrack
=
dynamic_pointer_cast
<
VideoTrack
>
(
Factory
::
getVideoTrackByAmf
(
videoCodec
));
_videoTrack
=
dynamic_pointer_cast
<
VideoTrack
>
(
Factory
::
getVideoTrackByAmf
(
videoCodec
));
if
(
_videoTrack
)
{
if
(
_videoTrack
)
{
_videoTrack
->
setBitRate
(
bit_rate
);
//生成rtmpCodec对象以便解码rtmp
//生成rtmpCodec对象以便解码rtmp
_video_rtmp_decoder
=
Factory
::
getRtmpCodecByTrack
(
_videoTrack
,
false
);
_video_rtmp_decoder
=
Factory
::
getRtmpCodecByTrack
(
_videoTrack
,
false
);
if
(
_video_rtmp_decoder
)
{
if
(
_video_rtmp_decoder
)
{
...
@@ -112,10 +123,11 @@ void RtmpDemuxer::makeVideoTrack(const AMFValue &videoCodec) {
...
@@ -112,10 +123,11 @@ void RtmpDemuxer::makeVideoTrack(const AMFValue &videoCodec) {
}
}
}
}
void
RtmpDemuxer
::
makeAudioTrack
(
const
AMFValue
&
audioCodec
,
int
sample_rate
,
int
channels
,
int
sample_bit
)
{
void
RtmpDemuxer
::
makeAudioTrack
(
const
AMFValue
&
audioCodec
,
int
sample_rate
,
int
channels
,
int
sample_bit
,
int
bit_rate
)
{
//生成Track对象
//生成Track对象
_audioTrack
=
dynamic_pointer_cast
<
AudioTrack
>
(
Factory
::
getAudioTrackByAmf
(
audioCodec
,
sample_rate
,
channels
,
sample_bit
));
_audioTrack
=
dynamic_pointer_cast
<
AudioTrack
>
(
Factory
::
getAudioTrackByAmf
(
audioCodec
,
sample_rate
,
channels
,
sample_bit
));
if
(
_audioTrack
)
{
if
(
_audioTrack
)
{
_audioTrack
->
setBitRate
(
bit_rate
);
//生成rtmpCodec对象以便解码rtmp
//生成rtmpCodec对象以便解码rtmp
_audio_rtmp_decoder
=
Factory
::
getRtmpCodecByTrack
(
_audioTrack
,
false
);
_audio_rtmp_decoder
=
Factory
::
getRtmpCodecByTrack
(
_audioTrack
,
false
);
if
(
_audio_rtmp_decoder
)
{
if
(
_audio_rtmp_decoder
)
{
...
...
src/Rtmp/RtmpDemuxer.h
查看文件 @
68926b4a
...
@@ -39,8 +39,8 @@ public:
...
@@ -39,8 +39,8 @@ public:
void
inputRtmp
(
const
RtmpPacket
::
Ptr
&
pkt
);
void
inputRtmp
(
const
RtmpPacket
::
Ptr
&
pkt
);
private
:
private
:
void
makeVideoTrack
(
const
AMFValue
&
val
);
void
makeVideoTrack
(
const
AMFValue
&
val
,
int
bit_rate
);
void
makeAudioTrack
(
const
AMFValue
&
val
,
int
sample_rate
,
int
channels
,
int
sample_bit
);
void
makeAudioTrack
(
const
AMFValue
&
val
,
int
sample_rate
,
int
channels
,
int
sample_bit
,
int
bit_rate
);
private
:
private
:
bool
_try_get_video_track
=
false
;
bool
_try_get_video_track
=
false
;
...
...
src/Rtmp/RtmpMediaSource.h
查看文件 @
68926b4a
...
@@ -119,7 +119,8 @@ public:
...
@@ -119,7 +119,8 @@ public:
* @param pkt rtmp包
* @param pkt rtmp包
*/
*/
void
onWrite
(
RtmpPacket
::
Ptr
pkt
,
bool
=
true
)
override
{
void
onWrite
(
RtmpPacket
::
Ptr
pkt
,
bool
=
true
)
override
{
_speed
+=
pkt
->
size
();
bool
is_video
=
pkt
->
type_id
==
MSG_VIDEO
;
_speed
[
is_video
?
TrackVideo
:
TrackAudio
]
+=
pkt
->
size
();
//保存当前时间戳
//保存当前时间戳
switch
(
pkt
->
type_id
)
{
switch
(
pkt
->
type_id
)
{
case
MSG_VIDEO
:
_track_stamps
[
TrackVideo
]
=
pkt
->
time_stamp
,
_have_video
=
true
;
break
;
case
MSG_VIDEO
:
_track_stamps
[
TrackVideo
]
=
pkt
->
time_stamp
,
_have_video
=
true
;
break
;
...
@@ -153,7 +154,6 @@ public:
...
@@ -153,7 +154,6 @@ public:
}
}
}
}
bool
key
=
pkt
->
isVideoKeyFrame
();
bool
key
=
pkt
->
isVideoKeyFrame
();
bool
is_video
=
pkt
->
type_id
==
MSG_VIDEO
;
auto
stamp
=
pkt
->
time_stamp
;
auto
stamp
=
pkt
->
time_stamp
;
PacketCache
<
RtmpPacket
>::
inputPacket
(
stamp
,
is_video
,
std
::
move
(
pkt
),
key
);
PacketCache
<
RtmpPacket
>::
inputPacket
(
stamp
,
is_video
,
std
::
move
(
pkt
),
key
);
}
}
...
...
src/Rtsp/RtspDemuxer.cpp
查看文件 @
68926b4a
...
@@ -63,11 +63,21 @@ bool RtspDemuxer::inputRtp(const RtpPacket::Ptr & rtp) {
...
@@ -63,11 +63,21 @@ bool RtspDemuxer::inputRtp(const RtpPacket::Ptr & rtp) {
}
}
}
}
static
void
setBitRate
(
const
SdpTrack
::
Ptr
&
sdp
,
const
Track
::
Ptr
&
track
){
if
(
!
sdp
->
_b
.
empty
())
{
int
data_rate
=
0
;
sscanf
(
sdp
->
_b
.
data
(),
"AS:%d"
,
&
data_rate
);
if
(
data_rate
)
{
track
->
setBitRate
(
data_rate
*
1024
);
}
}
}
void
RtspDemuxer
::
makeAudioTrack
(
const
SdpTrack
::
Ptr
&
audio
)
{
void
RtspDemuxer
::
makeAudioTrack
(
const
SdpTrack
::
Ptr
&
audio
)
{
//生成Track对象
//生成Track对象
_audioTrack
=
dynamic_pointer_cast
<
AudioTrack
>
(
Factory
::
getTrackBySdp
(
audio
));
_audioTrack
=
dynamic_pointer_cast
<
AudioTrack
>
(
Factory
::
getTrackBySdp
(
audio
));
if
(
_audioTrack
){
if
(
_audioTrack
){
setBitRate
(
audio
,
_audioTrack
);
//生成RtpCodec对象以便解码rtp
//生成RtpCodec对象以便解码rtp
_audioRtpDecoder
=
Factory
::
getRtpDecoderByTrack
(
_audioTrack
);
_audioRtpDecoder
=
Factory
::
getRtpDecoderByTrack
(
_audioTrack
);
if
(
_audioRtpDecoder
){
if
(
_audioRtpDecoder
){
...
@@ -85,6 +95,7 @@ void RtspDemuxer::makeVideoTrack(const SdpTrack::Ptr &video) {
...
@@ -85,6 +95,7 @@ void RtspDemuxer::makeVideoTrack(const SdpTrack::Ptr &video) {
//生成Track对象
//生成Track对象
_videoTrack
=
dynamic_pointer_cast
<
VideoTrack
>
(
Factory
::
getTrackBySdp
(
video
));
_videoTrack
=
dynamic_pointer_cast
<
VideoTrack
>
(
Factory
::
getTrackBySdp
(
video
));
if
(
_videoTrack
){
if
(
_videoTrack
){
setBitRate
(
video
,
_videoTrack
);
//生成RtpCodec对象以便解码rtp
//生成RtpCodec对象以便解码rtp
_videoRtpDecoder
=
Factory
::
getRtpDecoderByTrack
(
_videoTrack
);
_videoRtpDecoder
=
Factory
::
getRtpDecoderByTrack
(
_videoTrack
);
if
(
_videoRtpDecoder
){
if
(
_videoRtpDecoder
){
...
...
src/Rtsp/RtspMediaSource.h
查看文件 @
68926b4a
...
@@ -157,7 +157,7 @@ public:
...
@@ -157,7 +157,7 @@ public:
* @param keyPos 该包是否为关键帧的第一个包
* @param keyPos 该包是否为关键帧的第一个包
*/
*/
void
onWrite
(
RtpPacket
::
Ptr
rtp
,
bool
keyPos
)
override
{
void
onWrite
(
RtpPacket
::
Ptr
rtp
,
bool
keyPos
)
override
{
_speed
+=
rtp
->
size
();
_speed
[
rtp
->
type
]
+=
rtp
->
size
();
assert
(
rtp
->
type
>=
0
&&
rtp
->
type
<
TrackMax
);
assert
(
rtp
->
type
>=
0
&&
rtp
->
type
<
TrackMax
);
auto
&
track
=
_tracks
[
rtp
->
type
];
auto
&
track
=
_tracks
[
rtp
->
type
];
if
(
track
)
{
if
(
track
)
{
...
...
src/TS/TSMediaSource.h
查看文件 @
68926b4a
...
@@ -65,7 +65,7 @@ public:
...
@@ -65,7 +65,7 @@ public:
* @param key 是否为关键帧第一个包
* @param key 是否为关键帧第一个包
*/
*/
void
onWrite
(
TSPacket
::
Ptr
packet
,
bool
key
)
override
{
void
onWrite
(
TSPacket
::
Ptr
packet
,
bool
key
)
override
{
_speed
+=
packet
->
size
();
_speed
[
TrackVideo
]
+=
packet
->
size
();
if
(
!
_ring
)
{
if
(
!
_ring
)
{
createRing
();
createRing
();
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论