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
53ba766c
Commit
53ba766c
authored
Oct 31, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提炼rtp打包代码
parent
addf90b8
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
82 行增加
和
108 行删除
+82
-108
src/RtspMuxer/AACRtpCodec.cpp
+2
-34
src/RtspMuxer/H264RtpCodec.cpp
+6
-39
src/RtspMuxer/H264RtpCodec.h
+1
-1
src/RtspMuxer/H265RtpCodec.cpp
+2
-32
src/RtspMuxer/RtpCodec.cpp
+68
-0
src/RtspMuxer/RtpCodec.h
+3
-2
没有找到文件。
src/RtspMuxer/AACRtpCodec.cpp
查看文件 @
53ba766c
...
...
@@ -71,40 +71,8 @@ void AACRtpEncoder::inputFrame(const Frame::Ptr &frame) {
}
}
void
AACRtpEncoder
::
makeAACRtp
(
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
)
{
uint16_t
u16RtpLen
=
uiLen
+
12
;
uint32_t
ts
=
htonl
((
_ui32SampleRate
/
1000
)
*
uiStamp
);
uint16_t
sq
=
htons
(
_ui16Sequence
);
uint32_t
sc
=
htonl
(
_ui32Ssrc
);
auto
pRtppkt
=
ResourcePoolHelper
<
RtpPacket
>::
obtainObj
();
auto
&
rtppkt
=
*
pRtppkt
;
unsigned
char
*
pucRtp
=
rtppkt
.
payload
;
pucRtp
[
0
]
=
'$'
;
pucRtp
[
1
]
=
_ui8Interleaved
;
pucRtp
[
2
]
=
u16RtpLen
>>
8
;
pucRtp
[
3
]
=
u16RtpLen
&
0x00FF
;
pucRtp
[
4
]
=
0x80
;
pucRtp
[
5
]
=
(
bMark
<<
7
)
|
_ui8PlayloadType
;
memcpy
(
&
pucRtp
[
6
],
&
sq
,
2
);
memcpy
(
&
pucRtp
[
8
],
&
ts
,
4
);
//ssrc
memcpy
(
&
pucRtp
[
12
],
&
sc
,
4
);
//playload
memcpy
(
&
pucRtp
[
16
],
pData
,
uiLen
);
rtppkt
.
PT
=
_ui8PlayloadType
;
rtppkt
.
interleaved
=
_ui8Interleaved
;
rtppkt
.
mark
=
bMark
;
rtppkt
.
length
=
uiLen
+
16
;
rtppkt
.
sequence
=
_ui16Sequence
;
rtppkt
.
timeStamp
=
uiStamp
;
rtppkt
.
ssrc
=
_ui32Ssrc
;
rtppkt
.
type
=
TrackAudio
;
rtppkt
.
offset
=
16
;
RtpCodec
::
inputRtp
(
pRtppkt
,
false
);
_ui16Sequence
++
;
_ui32TimeStamp
=
uiStamp
;
void
AACRtpEncoder
::
makeAACRtp
(
const
void
*
data
,
unsigned
int
len
,
bool
mark
,
uint32_t
uiStamp
)
{
RtpCodec
::
inputRtp
(
makeRtp
(
getTrackType
(),
data
,
len
,
mark
,
uiStamp
),
false
);
}
/////////////////////////////////////////////////////////////////////////////////////
...
...
src/RtspMuxer/H264RtpCodec.cpp
查看文件 @
53ba766c
...
...
@@ -184,6 +184,7 @@ void H264RtpEncoder::inputFrame(const Frame::Ptr &frame) {
auto
pcData
=
frame
->
data
()
+
frame
->
prefixSize
();
auto
uiStamp
=
frame
->
stamp
();
auto
iLen
=
frame
->
size
()
-
frame
->
prefixSize
();
unsigned
char
naluType
=
H264_TYPE
(
pcData
[
0
]);
//获取NALU的5bit 帧类型
uiStamp
%=
cycleMS
;
int
iSize
=
_ui32MtuSize
-
2
;
...
...
@@ -192,8 +193,6 @@ void H264RtpEncoder::inputFrame(const Frame::Ptr &frame) {
const
unsigned
char
s_e_r_Mid
=
0x00
;
const
unsigned
char
s_e_r_End
=
0x40
;
//获取帧头数据,1byte
unsigned
char
naluType
=
H264_TYPE
(
pcData
[
0
]);
//获取NALU的5bit 帧类型
unsigned
char
nal_ref_idc
=
*
((
unsigned
char
*
)
pcData
)
&
0x60
;
//获取NALU的2bit 帧重要程度 00 可以丢 11不能丢
//nal_ref_idc = 0x60;
//组装FU-A帧头数据 2byte
...
...
@@ -219,48 +218,15 @@ void H264RtpEncoder::inputFrame(const Frame::Ptr &frame) {
memcpy
(
_aucSectionBuf
+
1
,
&
s_e_r_type
,
1
);
memcpy
(
_aucSectionBuf
+
2
,
(
unsigned
char
*
)
pcData
+
nOffset
,
iSize
);
nOffset
+=
iSize
;
makeH264Rtp
(
_aucSectionBuf
,
iSize
+
2
,
mark
,
uiStamp
);
makeH264Rtp
(
naluType
,
_aucSectionBuf
,
iSize
+
2
,
mark
,
uiStamp
);
}
}
else
{
makeH264Rtp
(
pcData
,
iLen
,
true
,
uiStamp
);
makeH264Rtp
(
naluType
,
pcData
,
iLen
,
true
,
uiStamp
);
}
}
void
H264RtpEncoder
::
makeH264Rtp
(
const
void
*
data
,
unsigned
int
len
,
bool
mark
,
uint32_t
uiStamp
)
{
uint16_t
ui16RtpLen
=
len
+
12
;
uint32_t
ts
=
htonl
((
_ui32SampleRate
/
1000
)
*
uiStamp
);
uint16_t
sq
=
htons
(
_ui16Sequence
);
uint32_t
sc
=
htonl
(
_ui32Ssrc
);
auto
rtppkt
=
ResourcePoolHelper
<
RtpPacket
>::
obtainObj
();
unsigned
char
*
pucRtp
=
rtppkt
->
payload
;
pucRtp
[
0
]
=
'$'
;
pucRtp
[
1
]
=
_ui8Interleaved
;
pucRtp
[
2
]
=
ui16RtpLen
>>
8
;
pucRtp
[
3
]
=
ui16RtpLen
&
0x00FF
;
pucRtp
[
4
]
=
0x80
;
pucRtp
[
5
]
=
(
mark
<<
7
)
|
_ui8PlayloadType
;
memcpy
(
&
pucRtp
[
6
],
&
sq
,
2
);
memcpy
(
&
pucRtp
[
8
],
&
ts
,
4
);
//ssrc
memcpy
(
&
pucRtp
[
12
],
&
sc
,
4
);
//playload
memcpy
(
&
pucRtp
[
16
],
data
,
len
);
rtppkt
->
PT
=
_ui8PlayloadType
;
rtppkt
->
interleaved
=
_ui8Interleaved
;
rtppkt
->
mark
=
mark
;
rtppkt
->
length
=
len
+
16
;
rtppkt
->
sequence
=
_ui16Sequence
;
rtppkt
->
timeStamp
=
uiStamp
;
rtppkt
->
ssrc
=
_ui32Ssrc
;
rtppkt
->
type
=
TrackVideo
;
rtppkt
->
offset
=
16
;
uint8_t
type
=
H264_TYPE
(((
uint8_t
*
)
(
data
))[
0
]);
RtpCodec
::
inputRtp
(
rtppkt
,
type
==
H264Frame
::
NAL_SPS
);
_ui16Sequence
++
;
_ui32TimeStamp
=
uiStamp
;
void
H264RtpEncoder
::
makeH264Rtp
(
int
nal_type
,
const
void
*
data
,
unsigned
int
len
,
bool
mark
,
uint32_t
uiStamp
)
{
RtpCodec
::
inputRtp
(
makeRtp
(
getTrackType
(),
data
,
len
,
mark
,
uiStamp
),
nal_type
==
H264Frame
::
NAL_SPS
);
}
}
//
namespace
mediakit
\ No newline at end of file
src/RtspMuxer/H264RtpCodec.h
查看文件 @
53ba766c
...
...
@@ -93,7 +93,7 @@ public:
*/
void
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
;
private
:
void
makeH264Rtp
(
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
);
void
makeH264Rtp
(
int
nal_type
,
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
);
private
:
unsigned
char
_aucSectionBuf
[
1600
];
};
...
...
src/RtspMuxer/H265RtpCodec.cpp
查看文件 @
53ba766c
...
...
@@ -210,38 +210,7 @@ void H265RtpEncoder::inputFrame(const Frame::Ptr &frame) {
}
void
H265RtpEncoder
::
makeH265Rtp
(
int
nal_type
,
const
void
*
data
,
unsigned
int
len
,
bool
mark
,
uint32_t
uiStamp
)
{
uint16_t
ui16RtpLen
=
len
+
12
;
uint32_t
ts
=
htonl
((
_ui32SampleRate
/
1000
)
*
uiStamp
);
uint16_t
sq
=
htons
(
_ui16Sequence
);
uint32_t
sc
=
htonl
(
_ui32Ssrc
);
auto
rtppkt
=
ResourcePoolHelper
<
RtpPacket
>::
obtainObj
();
unsigned
char
*
pucRtp
=
rtppkt
->
payload
;
pucRtp
[
0
]
=
'$'
;
pucRtp
[
1
]
=
_ui8Interleaved
;
pucRtp
[
2
]
=
ui16RtpLen
>>
8
;
pucRtp
[
3
]
=
ui16RtpLen
&
0x00FF
;
pucRtp
[
4
]
=
0x80
;
pucRtp
[
5
]
=
(
mark
<<
7
)
|
_ui8PlayloadType
;
memcpy
(
&
pucRtp
[
6
],
&
sq
,
2
);
memcpy
(
&
pucRtp
[
8
],
&
ts
,
4
);
//ssrc
memcpy
(
&
pucRtp
[
12
],
&
sc
,
4
);
//playload
memcpy
(
&
pucRtp
[
16
],
data
,
len
);
rtppkt
->
PT
=
_ui8PlayloadType
;
rtppkt
->
interleaved
=
_ui8Interleaved
;
rtppkt
->
mark
=
mark
;
rtppkt
->
length
=
len
+
16
;
rtppkt
->
sequence
=
_ui16Sequence
;
rtppkt
->
timeStamp
=
uiStamp
;
rtppkt
->
ssrc
=
_ui32Ssrc
;
rtppkt
->
type
=
TrackVideo
;
rtppkt
->
offset
=
16
;
RtpCodec
::
inputRtp
(
rtppkt
,
nal_type
==
H265Frame
::
NAL_VPS
);
_ui16Sequence
++
;
_ui32TimeStamp
=
uiStamp
;
RtpCodec
::
inputRtp
(
makeRtp
(
getTrackType
(),
data
,
len
,
mark
,
uiStamp
),
nal_type
==
H265Frame
::
NAL_VPS
);
}
}
//
namespace
mediakit
\ No newline at end of file
src/RtspMuxer/RtpCodec.cpp
0 → 100644
查看文件 @
53ba766c
/*
* MIT License
*
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "RtpCodec.h"
namespace
mediakit
{
RtpPacket
::
Ptr
RtpInfo
::
makeRtp
(
TrackType
type
,
const
void
*
data
,
unsigned
int
len
,
bool
mark
,
uint32_t
uiStamp
)
{
uint16_t
ui16RtpLen
=
len
+
12
;
uint32_t
ts
=
htonl
((
_ui32SampleRate
/
1000
)
*
uiStamp
);
uint16_t
sq
=
htons
(
_ui16Sequence
);
uint32_t
sc
=
htonl
(
_ui32Ssrc
);
auto
rtppkt
=
ResourcePoolHelper
<
RtpPacket
>::
obtainObj
();
unsigned
char
*
pucRtp
=
rtppkt
->
payload
;
pucRtp
[
0
]
=
'$'
;
pucRtp
[
1
]
=
_ui8Interleaved
;
pucRtp
[
2
]
=
ui16RtpLen
>>
8
;
pucRtp
[
3
]
=
ui16RtpLen
&
0x00FF
;
pucRtp
[
4
]
=
0x80
;
pucRtp
[
5
]
=
(
mark
<<
7
)
|
_ui8PlayloadType
;
memcpy
(
&
pucRtp
[
6
],
&
sq
,
2
);
memcpy
(
&
pucRtp
[
8
],
&
ts
,
4
);
//ssrc
memcpy
(
&
pucRtp
[
12
],
&
sc
,
4
);
//playload
memcpy
(
&
pucRtp
[
16
],
data
,
len
);
rtppkt
->
PT
=
_ui8PlayloadType
;
rtppkt
->
interleaved
=
_ui8Interleaved
;
rtppkt
->
mark
=
mark
;
rtppkt
->
length
=
len
+
16
;
rtppkt
->
sequence
=
_ui16Sequence
;
rtppkt
->
timeStamp
=
uiStamp
;
rtppkt
->
ssrc
=
_ui32Ssrc
;
rtppkt
->
type
=
type
;
rtppkt
->
offset
=
16
;
_ui16Sequence
++
;
_ui32TimeStamp
=
uiStamp
;
return
rtppkt
;
}
}
//namespace mediakit
src/RtspMuxer/RtpCodec.h
查看文件 @
53ba766c
...
...
@@ -107,7 +107,7 @@ protected:
};
class
RtpInfo
{
class
RtpInfo
:
public
ResourcePoolHelper
<
RtpPacket
>
{
public
:
typedef
std
::
shared_ptr
<
RtpInfo
>
Ptr
;
...
...
@@ -153,6 +153,7 @@ public:
uint32_t
getMtuSize
()
const
{
return
_ui32MtuSize
;
}
RtpPacket
::
Ptr
makeRtp
(
TrackType
type
,
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
);
protected
:
uint32_t
_ui32Ssrc
;
uint32_t
_ui32SampleRate
;
...
...
@@ -163,7 +164,7 @@ protected:
uint32_t
_ui32TimeStamp
=
0
;
};
class
RtpCodec
:
public
RtpRing
,
public
FrameRingInterfaceDelegate
,
public
CodecInfo
,
public
ResourcePoolHelper
<
RtpPacket
>
{
class
RtpCodec
:
public
RtpRing
,
public
FrameRingInterfaceDelegate
,
public
CodecInfo
{
public
:
typedef
std
::
shared_ptr
<
RtpCodec
>
Ptr
;
RtpCodec
(){}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论