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
96061f1d
Commit
96061f1d
authored
Jan 24, 2022
by
ziyue
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix_rtc_g711_play' of github.com:ZLMediaKit/ZLMediaKit
parents
0ae9a8c8
341459fb
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
106 行增加
和
3 行删除
+106
-3
src/Extension/Factory.cpp
+7
-2
src/Extension/G711Rtp.cpp
+47
-0
src/Extension/G711Rtp.h
+51
-0
webrtc/WebRtcPlayer.cpp
+1
-1
没有找到文件。
src/Extension/Factory.cpp
查看文件 @
96061f1d
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include "AACRtp.h"
#include "AACRtp.h"
#include "H265Rtp.h"
#include "H265Rtp.h"
#include "CommonRtp.h"
#include "CommonRtp.h"
#include "G711Rtp.h"
#include "Opus.h"
#include "Opus.h"
#include "G711.h"
#include "G711.h"
#include "L16.h"
#include "L16.h"
...
@@ -119,9 +120,13 @@ RtpCodec::Ptr Factory::getRtpEncoderBySdp(const Sdp::Ptr &sdp) {
...
@@ -119,9 +120,13 @@ RtpCodec::Ptr Factory::getRtpEncoderBySdp(const Sdp::Ptr &sdp) {
case
CodecH265
:
return
std
::
make_shared
<
H265RtpEncoder
>
(
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
);
case
CodecH265
:
return
std
::
make_shared
<
H265RtpEncoder
>
(
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
);
case
CodecAAC
:
return
std
::
make_shared
<
AACRtpEncoder
>
(
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
);
case
CodecAAC
:
return
std
::
make_shared
<
AACRtpEncoder
>
(
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
);
case
CodecL16
:
case
CodecL16
:
case
CodecOpus
:
case
CodecOpus
:
return
std
::
make_shared
<
CommonRtpEncoder
>
(
codec_id
,
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
);
case
CodecG711A
:
case
CodecG711A
:
case
CodecG711U
:
return
std
::
make_shared
<
CommonRtpEncoder
>
(
codec_id
,
ssrc
,
mtu
,
sample_rate
,
pt
,
interleaved
);
case
CodecG711U
:
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
<
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
0 → 100644
查看文件 @
96061f1d
#include "G711Rtp.h"
G711RtpEncoder
::
G711RtpEncoder
(
CodecId
codec
,
uint32_t
ssrc
,
uint32_t
mtu_size
,
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
)
{
_cache_frame
=
FrameImp
::
create
();
_cache_frame
->
_codec_id
=
codec
;
_channels
=
channels
;
}
bool
G711RtpEncoder
::
inputFrame
(
const
Frame
::
Ptr
&
frame
){
auto
dur
=
(
_cache_frame
->
size
()
-
_cache_frame
->
prefixSize
())
/
(
8
*
_channels
);
auto
next_pts
=
_cache_frame
->
pts
()
+
dur
;
if
(
next_pts
==
0
){
_cache_frame
->
_pts
=
frame
->
pts
();
}
else
{
if
((
next_pts
+
20
)
<
frame
->
pts
()){
// 有丢包超过20ms
_cache_frame
->
_pts
=
frame
->
pts
()
-
dur
;
}
}
_cache_frame
->
_buffer
.
append
(
frame
->
data
()
+
frame
->
prefixSize
(),
frame
->
size
()
-
frame
->
prefixSize
());
auto
stamp
=
_cache_frame
->
pts
();
auto
ptr
=
_cache_frame
->
data
()
+
_cache_frame
->
prefixSize
();
auto
len
=
_cache_frame
->
size
()
-
_cache_frame
->
prefixSize
();
auto
remain_size
=
len
;
auto
max_size
=
160
*
_channels
;
//20 ms per rtp
int
n
=
0
;
bool
mark
=
false
;
while
(
remain_size
>=
max_size
)
{
size_t
rtp_size
;
if
(
remain_size
>=
max_size
)
{
rtp_size
=
max_size
;
}
else
{
break
;
}
n
++
;
stamp
+=
20
;
RtpCodec
::
inputRtp
(
makeRtp
(
getTrackType
(),
ptr
,
rtp_size
,
mark
,
stamp
),
false
);
ptr
+=
rtp_size
;
remain_size
-=
rtp_size
;
}
_cache_frame
->
_buffer
.
erase
(
0
,
n
*
max_size
);
_cache_frame
->
_pts
+=
20
*
n
;
return
len
>
0
;
}
\ No newline at end of file
src/Extension/G711Rtp.h
0 → 100644
查看文件 @
96061f1d
/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
*
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#ifndef ZLMEDIAKIT_G711RTP_H
#define ZLMEDIAKIT_G711RTP_H
#include "Frame.h"
#include "CommonRtp.h"
#include "Rtsp/RtpCodec.h"
namespace
mediakit
{
/**
* G711 rtp编码类
*/
class
G711RtpEncoder
:
public
CommonRtpDecoder
,
public
RtpInfo
{
public
:
typedef
std
::
shared_ptr
<
G711RtpEncoder
>
Ptr
;
~
G711RtpEncoder
()
override
{}
/**
* 构造函数
* @param codec 编码类型
* @param ssrc ssrc
* @param mtu_size mtu 大小
* @param sample_rate 采样率
* @param payload_type pt类型
* @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
);
/**
* 输入帧数据并编码成rtp
*/
bool
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
;
private
:
FrameImp
::
Ptr
_cache_frame
;
uint32_t
_channels
=
1
;
};
}
//namespace mediakit
#endif //ZLMEDIAKIT_G711RTP_H
webrtc/WebRtcPlayer.cpp
查看文件 @
96061f1d
...
@@ -43,6 +43,7 @@ void WebRtcPlayer::onStartWebRTC() {
...
@@ -43,6 +43,7 @@ void WebRtcPlayer::onStartWebRTC() {
}
}
size_t
i
=
0
;
size_t
i
=
0
;
pkt
->
for_each
([
&
](
const
RtpPacket
::
Ptr
&
rtp
)
{
pkt
->
for_each
([
&
](
const
RtpPacket
::
Ptr
&
rtp
)
{
//TraceL<<"send track type:"<<rtp->type<<" ts:"<<rtp->getStamp()<<" ntp:"<<rtp->ntp_stamp<<" size:"<<rtp->getPayloadSize()<<" i:"<<i;
strongSelf
->
onSendRtp
(
rtp
,
++
i
==
pkt
->
size
());
strongSelf
->
onSendRtp
(
rtp
,
++
i
==
pkt
->
size
());
});
});
});
});
...
@@ -57,7 +58,6 @@ void WebRtcPlayer::onStartWebRTC() {
...
@@ -57,7 +58,6 @@ void WebRtcPlayer::onStartWebRTC() {
//使用完毕后,释放强引用,这样确保推流器断开后能及时注销媒体
//使用完毕后,释放强引用,这样确保推流器断开后能及时注销媒体
_play_src
=
nullptr
;
_play_src
=
nullptr
;
}
}
void
WebRtcPlayer
::
onDestory
()
{
void
WebRtcPlayer
::
onDestory
()
{
WebRtcTransportImp
::
onDestory
();
WebRtcTransportImp
::
onDestory
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论