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
510d908b
Commit
510d908b
authored
Jun 21, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rtp服务器支持opus推流
parent
c90f3488
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
51 行增加
和
27 行删除
+51
-27
src/Rtp/GB28181Process.cpp
+51
-27
没有找到文件。
src/Rtp/GB28181Process.cpp
查看文件 @
510d908b
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#include "Extension/CommonRtp.h"
#include "Extension/CommonRtp.h"
#include "Extension/H264Rtp.h"
#include "Extension/H264Rtp.h"
#include "Extension/Factory.h"
#include "Extension/Factory.h"
#include "Extension/Opus.h"
namespace
mediakit
{
namespace
mediakit
{
...
@@ -26,15 +27,16 @@ static inline bool checkTS(const uint8_t *packet, size_t bytes){
...
@@ -26,15 +27,16 @@ static inline bool checkTS(const uint8_t *packet, size_t bytes){
class
RtpReceiverImp
:
public
RtpReceiver
{
class
RtpReceiverImp
:
public
RtpReceiver
{
public
:
public
:
using
Ptr
=
std
::
shared_ptr
<
RtpReceiverImp
>
;
using
Ptr
=
std
::
shared_ptr
<
RtpReceiverImp
>
;
RtpReceiverImp
(
function
<
void
(
RtpPacket
::
Ptr
rtp
)
>
cb
,
function
<
void
(
const
RtpPacket
::
Ptr
&
rtp
)
>
cb_before
=
nullptr
){
RtpReceiverImp
(
int
sample_rate
,
function
<
void
(
RtpPacket
::
Ptr
rtp
)
>
cb
,
function
<
void
(
const
RtpPacket
::
Ptr
&
rtp
)
>
cb_before
=
nullptr
){
_sample_rate
=
sample_rate
;
_on_sort
=
std
::
move
(
cb
);
_on_sort
=
std
::
move
(
cb
);
_on_before_sort
=
std
::
move
(
cb_before
);
_on_before_sort
=
std
::
move
(
cb_before
);
}
}
~
RtpReceiverImp
()
override
=
default
;
~
RtpReceiverImp
()
override
=
default
;
bool
inputRtp
(
TrackType
type
,
int
samplerate
,
uint8_t
*
ptr
,
size_t
len
){
bool
inputRtp
(
TrackType
type
,
uint8_t
*
ptr
,
size_t
len
){
return
handleOneRtp
((
int
)
type
,
type
,
sample
rate
,
ptr
,
len
);
return
handleOneRtp
((
int
)
type
,
type
,
_sample_
rate
,
ptr
,
len
);
}
}
protected
:
protected
:
...
@@ -49,6 +51,7 @@ protected:
...
@@ -49,6 +51,7 @@ protected:
}
}
private
:
private
:
int
_sample_rate
;
function
<
void
(
RtpPacket
::
Ptr
rtp
)
>
_on_sort
;
function
<
void
(
RtpPacket
::
Ptr
rtp
)
>
_on_sort
;
function
<
void
(
const
RtpPacket
::
Ptr
&
rtp
)
>
_on_before_sort
;
function
<
void
(
const
RtpPacket
::
Ptr
&
rtp
)
>
_on_before_sort
;
};
};
...
@@ -63,49 +66,66 @@ GB28181Process::GB28181Process(const MediaInfo &media_info, MediaSinkInterface *
...
@@ -63,49 +66,66 @@ GB28181Process::GB28181Process(const MediaInfo &media_info, MediaSinkInterface *
GB28181Process
::~
GB28181Process
()
{}
GB28181Process
::~
GB28181Process
()
{}
void
GB28181Process
::
onRtpSorted
(
RtpPacket
::
Ptr
rtp
)
{
_rtp_decoder
[
rtp
->
getHeader
()
->
pt
]
->
inputRtp
(
rtp
,
false
);
}
bool
GB28181Process
::
inputRtp
(
bool
,
const
char
*
data
,
size_t
data_len
)
{
bool
GB28181Process
::
inputRtp
(
bool
,
const
char
*
data
,
size_t
data_len
)
{
RtpHeader
*
header
=
(
RtpHeader
*
)
data
;
RtpHeader
*
header
=
(
RtpHeader
*
)
data
;
auto
&
ref
=
_rtp_receiver
[
header
->
pt
];
auto
pt
=
header
->
pt
;
auto
&
ref
=
_rtp_receiver
[
pt
];
if
(
!
ref
)
{
if
(
!
ref
)
{
ref
=
std
::
make_shared
<
RtpReceiverImp
>
([
this
](
RtpPacket
::
Ptr
rtp
)
{
if
(
_rtp_receiver
.
size
()
>
2
)
{
//防止pt类型太多导致内存溢出
throw
std
::
invalid_argument
(
"rtp pt类型不得超过2种!"
);
}
switch
(
pt
)
{
case
100
:
{
//opus负载
ref
=
std
::
make_shared
<
RtpReceiverImp
>
(
48000
,[
this
](
RtpPacket
::
Ptr
rtp
)
{
onRtpSorted
(
std
::
move
(
rtp
));
onRtpSorted
(
std
::
move
(
rtp
));
});
});
auto
track
=
std
::
make_shared
<
OpusTrack
>
();
_interface
->
addTrack
(
track
);
_rtp_decoder
[
pt
]
=
Factory
::
getRtpDecoderByTrack
(
track
);
break
;
}
}
return
ref
->
inputRtp
(
TrackVideo
,
RtpPayload
::
getClockRate
(
header
->
pt
),
(
unsigned
char
*
)
data
,
data_len
);
}
void
GB28181Process
::
onRtpSorted
(
RtpPacket
::
Ptr
rtp
)
{
auto
pt
=
rtp
->
getHeader
()
->
pt
;
auto
&
ref
=
_rtp_decoder
[
pt
];
if
(
!
ref
)
{
switch
(
pt
)
{
case
99
:
{
case
99
:
{
//H265负载
//H265负载
ref
=
std
::
make_shared
<
RtpReceiverImp
>
(
90000
,[
this
](
RtpPacket
::
Ptr
rtp
)
{
onRtpSorted
(
std
::
move
(
rtp
));
});
auto
track
=
std
::
make_shared
<
H265Track
>
();
auto
track
=
std
::
make_shared
<
H265Track
>
();
_interface
->
addTrack
(
track
);
_interface
->
addTrack
(
track
);
ref
=
Factory
::
getRtpDecoderByTrack
(
track
);
_rtp_decoder
[
pt
]
=
Factory
::
getRtpDecoderByTrack
(
track
);
break
;
break
;
}
}
case
98
:
{
case
98
:
{
//H264负载
//H264负载
ref
=
std
::
make_shared
<
RtpReceiverImp
>
(
90000
,[
this
](
RtpPacket
::
Ptr
rtp
)
{
onRtpSorted
(
std
::
move
(
rtp
));
});
auto
track
=
std
::
make_shared
<
H264Track
>
();
auto
track
=
std
::
make_shared
<
H264Track
>
();
_interface
->
addTrack
(
track
);
_interface
->
addTrack
(
track
);
ref
=
Factory
::
getRtpDecoderByTrack
(
track
);
_rtp_decoder
[
pt
]
=
Factory
::
getRtpDecoderByTrack
(
track
);
break
;
}
case
0
:
{
//CodecG711U
auto
track
=
std
::
make_shared
<
G711Track
>
(
CodecG711U
,
8000
,
1
,
16
);
_interface
->
addTrack
(
track
);
ref
=
Factory
::
getRtpDecoderByTrack
(
track
);
break
;
break
;
}
}
case
0
:
//CodecG711U
case
8
:
{
case
8
:
{
//CodecG711A
//CodecG711A
auto
track
=
std
::
make_shared
<
G711Track
>
(
CodecG711A
,
8000
,
1
,
16
);
ref
=
std
::
make_shared
<
RtpReceiverImp
>
(
8000
,[
this
](
RtpPacket
::
Ptr
rtp
)
{
onRtpSorted
(
std
::
move
(
rtp
));
});
auto
track
=
std
::
make_shared
<
G711Track
>
(
pt
==
0
?
CodecG711U
:
CodecG711A
,
8000
,
1
,
16
);
_interface
->
addTrack
(
track
);
_interface
->
addTrack
(
track
);
ref
=
Factory
::
getRtpDecoderByTrack
(
track
);
_rtp_decoder
[
pt
]
=
Factory
::
getRtpDecoderByTrack
(
track
);
break
;
break
;
}
}
...
@@ -113,8 +133,13 @@ void GB28181Process::onRtpSorted(RtpPacket::Ptr rtp) {
...
@@ -113,8 +133,13 @@ void GB28181Process::onRtpSorted(RtpPacket::Ptr rtp) {
if
(
pt
!=
33
&&
pt
!=
96
)
{
if
(
pt
!=
33
&&
pt
!=
96
)
{
WarnL
<<
"rtp payload type未识别("
<<
(
int
)
pt
<<
"),已按ts或ps负载处理"
;
WarnL
<<
"rtp payload type未识别("
<<
(
int
)
pt
<<
"),已按ts或ps负载处理"
;
}
}
ref
=
std
::
make_shared
<
RtpReceiverImp
>
(
90000
,[
this
](
RtpPacket
::
Ptr
rtp
)
{
onRtpSorted
(
std
::
move
(
rtp
));
});
//ts或ps负载
//ts或ps负载
ref
=
std
::
make_shared
<
CommonRtpDecoder
>
(
CodecInvalid
,
32
*
1024
);
_rtp_decoder
[
pt
]
=
std
::
make_shared
<
CommonRtpDecoder
>
(
CodecInvalid
,
32
*
1024
);
//设置dump目录
//设置dump目录
GET_CONFIG
(
string
,
dump_dir
,
RtpProxy
::
kDumpDir
);
GET_CONFIG
(
string
,
dump_dir
,
RtpProxy
::
kDumpDir
);
if
(
!
dump_dir
.
empty
())
{
if
(
!
dump_dir
.
empty
())
{
...
@@ -130,13 +155,12 @@ void GB28181Process::onRtpSorted(RtpPacket::Ptr rtp) {
...
@@ -130,13 +155,12 @@ void GB28181Process::onRtpSorted(RtpPacket::Ptr rtp) {
}
}
//设置frame回调
//设置frame回调
ref
->
addDelegate
(
std
::
make_shared
<
FrameWriterInterfaceHelper
>
([
this
](
const
Frame
::
Ptr
&
frame
)
{
_rtp_decoder
[
pt
]
->
addDelegate
(
std
::
make_shared
<
FrameWriterInterfaceHelper
>
([
this
](
const
Frame
::
Ptr
&
frame
)
{
onRtpDecode
(
frame
);
onRtpDecode
(
frame
);
}));
}));
}
}
//解码rtp
return
ref
->
inputRtp
(
TrackVideo
,
(
unsigned
char
*
)
data
,
data_len
);
ref
->
inputRtp
(
rtp
,
false
);
}
}
const
char
*
GB28181Process
::
onSearchPacketTail
(
const
char
*
packet
,
size_t
bytes
){
const
char
*
GB28181Process
::
onSearchPacketTail
(
const
char
*
packet
,
size_t
bytes
){
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论