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
bc583e80
Commit
bc583e80
authored
Jan 24, 2022
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
合并pr: #1391
parent
96061f1d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
35 行增加
和
27 行删除
+35
-27
src/Extension/Factory.cpp
+4
-3
src/Extension/G711Rtp.cpp
+24
-18
src/Extension/G711Rtp.h
+7
-6
没有找到文件。
src/Extension/Factory.cpp
查看文件 @
bc583e80
...
@@ -122,11 +122,12 @@ RtpCodec::Ptr Factory::getRtpEncoderBySdp(const Sdp::Ptr &sdp) {
...
@@ -122,11 +122,12 @@ RtpCodec::Ptr Factory::getRtpEncoderBySdp(const Sdp::Ptr &sdp) {
case
CodecL16
:
case
CodecL16
:
case
CodecOpus
:
return
std
::
make_shared
<
CommonRtpEncoder
>
(
codec_id
,
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
);
case
CodecOpus
:
return
std
::
make_shared
<
CommonRtpEncoder
>
(
codec_id
,
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
);
case
CodecG711A
:
case
CodecG711A
:
case
CodecG711U
:
case
CodecG711U
:
{
if
(
pt
==
Rtsp
::
PT_PCMA
||
pt
==
Rtsp
::
PT_PCMU
)
{
if
(
pt
==
Rtsp
::
PT_PCMA
||
pt
==
Rtsp
::
PT_PCMU
)
{
return
std
::
make_shared
<
G711RtpEncoder
>
(
codec_id
,
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
,
1
);
return
std
::
make_shared
<
G711RtpEncoder
>
(
codec_id
,
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
,
1
);
}
}
return
std
::
make_shared
<
CommonRtpEncoder
>
(
codec_id
,
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
);
return
std
::
make_shared
<
CommonRtpEncoder
>
(
codec_id
,
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
);
}
default
:
WarnL
<<
"暂不支持该CodecId:"
<<
codec_id
;
return
nullptr
;
default
:
WarnL
<<
"暂不支持该CodecId:"
<<
codec_id
;
return
nullptr
;
}
}
}
}
...
...
src/Extension/G711Rtp.cpp
查看文件 @
bc583e80
#include "G711Rtp.h"
#include "G711Rtp.h"
G711RtpEncoder
::
G711RtpEncoder
(
CodecId
codec
,
uint32_t
ssrc
,
uint32_t
mtu_size
,
namespace
mediakit
{
uint32_t
sample_rate
,
uint8_t
payload_type
,
uint8_t
interleaved
,
uint32_t
channels
)
:
CommonRtpDecoder
(
codec
),
RtpInfo
(
ssrc
,
mtu_size
,
sample_rate
,
payload_type
,
interleaved
)
{
G711RtpEncoder
::
G711RtpEncoder
(
_cache_frame
=
FrameImp
::
create
();
CodecId
codec
,
uint32_t
ssrc
,
uint32_t
mtu_size
,
uint32_t
sample_rate
,
uint8_t
payload_type
,
uint8_t
interleaved
,
_cache_frame
->
_codec_id
=
codec
;
uint32_t
channels
)
_channels
=
channels
;
:
CommonRtpDecoder
(
codec
)
,
RtpInfo
(
ssrc
,
mtu_size
,
sample_rate
,
payload_type
,
interleaved
)
{
_cache_frame
=
FrameImp
::
create
();
_cache_frame
->
_codec_id
=
codec
;
_channels
=
channels
;
}
}
bool
G711RtpEncoder
::
inputFrame
(
const
Frame
::
Ptr
&
frame
){
bool
G711RtpEncoder
::
inputFrame
(
const
Frame
::
Ptr
&
frame
)
{
auto
dur
=
(
_cache_frame
->
size
()
-
_cache_frame
->
prefixSize
())
/
(
8
*
_channels
);
auto
dur
=
(
_cache_frame
->
size
()
-
_cache_frame
->
prefixSize
())
/
(
8
*
_channels
);
auto
next_pts
=
_cache_frame
->
pts
()
+
dur
;
auto
next_pts
=
_cache_frame
->
pts
()
+
dur
;
if
(
next_pts
==
0
)
{
if
(
next_pts
==
0
)
{
_cache_frame
->
_pts
=
frame
->
pts
();
_cache_frame
->
_pts
=
frame
->
pts
();
}
else
{
}
else
{
if
((
next_pts
+
20
)
<
frame
->
pts
()){
// 有丢包超过20ms
if
((
next_pts
+
20
)
<
frame
->
pts
())
{
// 有丢包超过20ms
_cache_frame
->
_pts
=
frame
->
pts
()
-
dur
;
_cache_frame
->
_pts
=
frame
->
pts
()
-
dur
;
}
}
}
}
_cache_frame
->
_buffer
.
append
(
frame
->
data
()
+
frame
->
prefixSize
(),
frame
->
size
()
-
frame
->
prefixSize
());
_cache_frame
->
_buffer
.
append
(
frame
->
data
()
+
frame
->
prefixSize
(),
frame
->
size
()
-
frame
->
prefixSize
());
auto
stamp
=
_cache_frame
->
pts
();
auto
stamp
=
_cache_frame
->
pts
();
auto
ptr
=
_cache_frame
->
data
()
+
_cache_frame
->
prefixSize
();
auto
ptr
=
_cache_frame
->
data
()
+
_cache_frame
->
prefixSize
();
auto
len
=
_cache_frame
->
size
()
-
_cache_frame
->
prefixSize
();
auto
len
=
_cache_frame
->
size
()
-
_cache_frame
->
prefixSize
();
auto
remain_size
=
len
;
auto
remain_size
=
len
;
auto
max_size
=
160
*
_channels
;
//20 ms per rtp
auto
max_size
=
160
*
_channels
;
// 20 ms per rtp
int
n
=
0
;
int
n
=
0
;
bool
mark
=
false
;
bool
mark
=
false
;
while
(
remain_size
>=
max_size
)
{
while
(
remain_size
>=
max_size
)
{
...
@@ -40,7 +44,9 @@ bool G711RtpEncoder::inputFrame(const Frame::Ptr &frame){
...
@@ -40,7 +44,9 @@ bool G711RtpEncoder::inputFrame(const Frame::Ptr &frame){
ptr
+=
rtp_size
;
ptr
+=
rtp_size
;
remain_size
-=
rtp_size
;
remain_size
-=
rtp_size
;
}
}
_cache_frame
->
_buffer
.
erase
(
0
,
n
*
max_size
);
_cache_frame
->
_buffer
.
erase
(
0
,
n
*
max_size
);
_cache_frame
->
_pts
+=
20
*
n
;
_cache_frame
->
_pts
+=
20
*
n
;
return
len
>
0
;
return
len
>
0
;
}
}
\ No newline at end of file
}
//
namespace
mediakit
\ No newline at end of file
src/Extension/G711Rtp.h
查看文件 @
bc583e80
...
@@ -15,17 +15,16 @@
...
@@ -15,17 +15,16 @@
#include "CommonRtp.h"
#include "CommonRtp.h"
#include "Rtsp/RtpCodec.h"
#include "Rtsp/RtpCodec.h"
namespace
mediakit
{
namespace
mediakit
{
/**
/**
* G711 rtp编码类
* G711 rtp编码类
*/
*/
class
G711RtpEncoder
:
public
CommonRtpDecoder
,
public
RtpInfo
{
class
G711RtpEncoder
:
public
CommonRtpDecoder
,
public
RtpInfo
{
public
:
public
:
typedef
std
::
shared_ptr
<
G711RtpEncoder
>
Ptr
;
using
Ptr
=
std
::
shared_ptr
<
G711RtpEncoder
>
;
~
G711RtpEncoder
()
override
{}
~
G711RtpEncoder
()
override
=
default
;
/**
/**
* 构造函数
* 构造函数
...
@@ -36,15 +35,17 @@ public:
...
@@ -36,15 +35,17 @@ public:
* @param payload_type pt类型
* @param payload_type pt类型
* @param interleaved rtsp interleaved 值
* @param interleaved rtsp interleaved 值
*/
*/
G711RtpEncoder
(
CodecId
codec
,
uint32_t
ssrc
,
uint32_t
mtu_size
,
uint32_t
sample_rate
,
uint8_t
payload_type
,
uint8_t
interleaved
,
uint32_t
channels
);
G711RtpEncoder
(
CodecId
codec
,
uint32_t
ssrc
,
uint32_t
mtu_size
,
uint32_t
sample_rate
,
uint8_t
payload_type
,
uint8_t
interleaved
,
uint32_t
channels
);
/**
/**
* 输入帧数据并编码成rtp
* 输入帧数据并编码成rtp
*/
*/
bool
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
;
bool
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
;
private
:
private
:
FrameImp
::
Ptr
_cache_frame
;
uint32_t
_channels
=
1
;
uint32_t
_channels
=
1
;
FrameImp
::
Ptr
_cache_frame
;
};
};
}
//namespace mediakit
}
//namespace mediakit
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论