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
cc7556b5
Commit
cc7556b5
authored
Jan 30, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
兼容把SPS PPS IDR打包在一起的帧
parent
7ba81499
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
86 行增加
和
12 行删除
+86
-12
ZLToolKit
+1
-1
src/Extension/H264.cpp
+26
-0
src/Extension/H264.h
+59
-11
没有找到文件。
ZLToolKit
@
8c1a0f88
Subproject commit
5573789f4ec0546f8788bc7be3d564de6e1365d6
Subproject commit
8c1a0f88a0b8e332c3eaf04dbb9a8f2402b267ba
src/Extension/H264.cpp
查看文件 @
cc7556b5
...
@@ -51,6 +51,32 @@ bool getAVCInfo(const char * sps,int sps_len,int &iVideoWidth, int &iVideoHeight
...
@@ -51,6 +51,32 @@ bool getAVCInfo(const char * sps,int sps_len,int &iVideoWidth, int &iVideoHeight
return
true
;
return
true
;
}
}
const
char
*
memfind
(
const
char
*
buf
,
int
len
,
const
char
*
subbuf
,
int
sublen
)
{
for
(
auto
i
=
0
;
i
<
len
-
sublen
;
++
i
)
{
if
(
memcmp
(
buf
+
i
,
subbuf
,
sublen
)
==
0
)
{
return
buf
+
i
;
}
}
return
NULL
;
}
void
splitH264
(
const
char
*
ptr
,
int
len
,
const
std
::
function
<
void
(
const
char
*
,
int
)
>
&
cb
)
{
auto
nal
=
ptr
;
auto
end
=
ptr
+
len
;
while
(
true
)
{
auto
next_nal
=
memfind
(
nal
+
3
,
end
-
nal
-
3
,
"\x0\x0\x1"
,
3
);
if
(
next_nal
){
cb
(
nal
,
next_nal
-
nal
);
nal
=
next_nal
;
continue
;
}
cb
(
nal
,
end
-
nal
);
break
;
}
}
}
//namespace mediakit
}
//namespace mediakit
src/Extension/H264.h
查看文件 @
cc7556b5
...
@@ -38,6 +38,7 @@ namespace mediakit{
...
@@ -38,6 +38,7 @@ namespace mediakit{
bool
getAVCInfo
(
const
string
&
strSps
,
int
&
iVideoWidth
,
int
&
iVideoHeight
,
float
&
iVideoFps
);
bool
getAVCInfo
(
const
string
&
strSps
,
int
&
iVideoWidth
,
int
&
iVideoHeight
,
float
&
iVideoFps
);
bool
getAVCInfo
(
const
char
*
sps
,
int
sps_len
,
int
&
iVideoWidth
,
int
&
iVideoHeight
,
float
&
iVideoFps
);
bool
getAVCInfo
(
const
char
*
sps
,
int
sps_len
,
int
&
iVideoWidth
,
int
&
iVideoHeight
,
float
&
iVideoFps
);
void
splitH264
(
const
char
*
ptr
,
int
len
,
const
std
::
function
<
void
(
const
char
*
,
int
)
>
&
cb
);
/**
/**
* 264帧类
* 264帧类
...
@@ -116,6 +117,20 @@ public:
...
@@ -116,6 +117,20 @@ public:
}
}
};
};
class
H264FrameSubFrame
:
public
H264FrameNoCopyAble
{
public
:
typedef
std
::
shared_ptr
<
H264FrameSubFrame
>
Ptr
;
H264FrameSubFrame
(
const
Frame
::
Ptr
&
strongRef
,
char
*
ptr
,
uint32_t
size
,
uint32_t
stamp
,
int
prefixeSize
)
:
H264FrameNoCopyAble
(
ptr
,
size
,
stamp
,
prefixeSize
){
_strongRef
=
strongRef
;
}
private
:
Frame
::
Ptr
_strongRef
;
};
/**
/**
* 264视频通道
* 264视频通道
...
@@ -204,12 +219,55 @@ public:
...
@@ -204,12 +219,55 @@ public:
return
!
_sps
.
empty
()
&&
!
_pps
.
empty
();
return
!
_sps
.
empty
()
&&
!
_pps
.
empty
();
}
}
/**
* 输入数据帧,并获取sps pps
* @param frame 数据帧
*/
void
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
{
int
type
=
H264_TYPE
(
*
((
uint8_t
*
)
frame
->
data
()
+
frame
->
prefixSize
()));
if
(
type
==
H264Frame
::
NAL_SPS
){
//有些设备会把SPS PPS IDR帧当做一个帧打包,所以我们要split一下
bool
first_frame
=
true
;
splitH264
(
frame
->
data
()
+
frame
->
prefixSize
(),
frame
->
size
()
-
frame
->
prefixSize
(),
[
&
](
const
char
*
ptr
,
int
len
){
if
(
first_frame
){
H264FrameSubFrame
::
Ptr
sub_frame
=
std
::
make_shared
<
H264FrameSubFrame
>
(
frame
,
frame
->
data
(),
len
+
frame
->
prefixSize
(),
frame
->
stamp
(),
frame
->
prefixSize
());
inputFrame_l
(
sub_frame
);
first_frame
=
false
;
}
else
{
H264FrameSubFrame
::
Ptr
sub_frame
=
std
::
make_shared
<
H264FrameSubFrame
>
(
frame
,
(
char
*
)
ptr
,
len
,
frame
->
stamp
(),
3
);
inputFrame_l
(
sub_frame
);
}
});
}
else
{
inputFrame_l
(
frame
);
}
}
private
:
/**
* 解析sps获取宽高fps
*/
void
onReady
(){
getAVCInfo
(
_sps
,
_width
,
_height
,
_fps
);
}
Track
::
Ptr
clone
()
override
{
return
std
::
make_shared
<
std
::
remove_reference
<
decltype
(
*
this
)
>::
type
>
(
*
this
);
}
/**
/**
* 输入数据帧,并获取sps pps
* 输入数据帧,并获取sps pps
* @param frame 数据帧
* @param frame 数据帧
*/
*/
void
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
{
void
inputFrame
_l
(
const
Frame
::
Ptr
&
frame
)
{
int
type
=
H264_TYPE
(
*
((
uint8_t
*
)
frame
->
data
()
+
frame
->
prefixSize
()));
int
type
=
H264_TYPE
(
*
((
uint8_t
*
)
frame
->
data
()
+
frame
->
prefixSize
()));
switch
(
type
){
switch
(
type
){
case
H264Frame
:
:
NAL_SPS
:
{
case
H264Frame
:
:
NAL_SPS
:
{
...
@@ -272,16 +330,6 @@ public:
...
@@ -272,16 +330,6 @@ public:
}
}
}
}
private
:
private
:
/**
* 解析sps获取宽高fps
*/
void
onReady
(){
getAVCInfo
(
_sps
,
_width
,
_height
,
_fps
);
}
Track
::
Ptr
clone
()
override
{
return
std
::
make_shared
<
std
::
remove_reference
<
decltype
(
*
this
)
>::
type
>
(
*
this
);
}
private
:
string
_sps
;
string
_sps
;
string
_pps
;
string
_pps
;
int
_width
=
0
;
int
_width
=
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论