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
4ce1a25f
Commit
4ce1a25f
authored
Sep 20, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复MP4解复用时不写入adts头的问题
parent
071d0a9f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
21 行删除
+30
-21
src/Record/MP4Demuxer.cpp
+30
-21
没有找到文件。
src/Record/MP4Demuxer.cpp
查看文件 @
4ce1a25f
...
...
@@ -160,6 +160,8 @@ struct Context{
BufferRaw
::
Ptr
buffer
;
};
#define DATA_OFFSET ADTS_HEADER_LEN
Frame
::
Ptr
MP4Demuxer
::
readFrame
(
bool
&
keyFrame
,
bool
&
eof
)
{
keyFrame
=
false
;
eof
=
false
;
...
...
@@ -174,9 +176,9 @@ Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame, bool &eof) {
static
mov_onalloc
mov_onalloc
=
[](
void
*
param
,
int
bytes
)
->
void
*
{
Context
*
ctx
=
(
Context
*
)
param
;
ctx
->
buffer
=
ctx
->
thiz
->
_buffer_pool
.
obtain
();
ctx
->
buffer
->
setCapacity
(
bytes
+
1
);
ctx
->
buffer
->
setSize
(
bytes
);
return
ctx
->
buffer
->
data
();
ctx
->
buffer
->
setCapacity
(
bytes
+
DATA_OFFSET
+
1
);
ctx
->
buffer
->
setSize
(
bytes
+
DATA_OFFSET
);
return
ctx
->
buffer
->
data
()
+
DATA_OFFSET
;
};
Context
ctx
=
{
this
,
0
};
...
...
@@ -204,11 +206,11 @@ template <typename Parent>
class
FrameWrapper
:
public
Parent
{
public
:
~
FrameWrapper
()
=
default
;
FrameWrapper
(
const
Buffer
::
Ptr
&
buf
,
int64_t
pts
,
int64_t
dts
,
int
prefix
)
:
Parent
(
buf
->
data
(),
buf
->
size
()
,
dts
,
pts
,
prefix
){
FrameWrapper
(
const
Buffer
::
Ptr
&
buf
,
int64_t
pts
,
int64_t
dts
,
int
prefix
,
int
offset
)
:
Parent
(
buf
->
data
()
+
offset
,
buf
->
size
()
-
offset
,
dts
,
pts
,
prefix
){
_buf
=
buf
;
}
FrameWrapper
(
CodecId
codec
,
const
Buffer
::
Ptr
&
buf
,
int64_t
pts
,
int64_t
dts
,
int
prefix
)
:
Parent
(
codec
,
buf
->
data
(),
buf
->
size
()
,
dts
,
pts
,
prefix
){
FrameWrapper
(
const
Buffer
::
Ptr
&
buf
,
int64_t
pts
,
int64_t
dts
,
int
prefix
,
int
offset
,
CodecId
codec
)
:
Parent
(
codec
,
buf
->
data
()
+
offset
,
buf
->
size
()
-
offset
,
dts
,
pts
,
prefix
){
_buf
=
buf
;
}
...
...
@@ -224,37 +226,44 @@ Frame::Ptr MP4Demuxer::makeFrame(uint32_t track_id, const Buffer::Ptr &buf, int6
if
(
it
==
_track_to_codec
.
end
())
{
return
nullptr
;
}
auto
numBytes
=
buf
->
size
()
;
auto
pBytes
=
buf
->
data
()
;
auto
bytes
=
buf
->
size
()
-
DATA_OFFSET
;
auto
data
=
buf
->
data
()
+
DATA_OFFSET
;
auto
codec
=
it
->
second
->
getCodecId
();
switch
(
codec
)
{
case
CodecH264
:
case
CodecH265
:
{
uint32_t
iO
ffset
=
0
;
while
(
iOffset
<
numB
ytes
)
{
uint32_t
iFrameL
en
;
memcpy
(
&
iFrameLen
,
pBytes
+
iO
ffset
,
4
);
iFrameLen
=
ntohl
(
iFrameL
en
);
if
(
iFrameLen
+
iOffset
+
4
>
numB
ytes
)
{
uint32_t
o
ffset
=
0
;
while
(
offset
<
b
ytes
)
{
uint32_t
frame_l
en
;
memcpy
(
&
frame_len
,
data
+
o
ffset
,
4
);
frame_len
=
ntohl
(
frame_l
en
);
if
(
frame_len
+
offset
+
4
>
b
ytes
)
{
return
nullptr
;
}
memcpy
(
pBytes
+
iO
ffset
,
"\x0\x0\x0\x1"
,
4
);
iOffset
+=
(
iFrameL
en
+
4
);
memcpy
(
data
+
o
ffset
,
"\x0\x0\x0\x1"
,
4
);
offset
+=
(
frame_l
en
+
4
);
}
if
(
codec
==
CodecH264
)
{
return
std
::
make_shared
<
FrameWrapper
<
H264FrameNoCacheAble
>
>
(
buf
,
pts
,
dts
,
4
);
return
std
::
make_shared
<
FrameWrapper
<
H264FrameNoCacheAble
>
>
(
buf
,
pts
,
dts
,
4
,
DATA_OFFSET
);
}
return
std
::
make_shared
<
FrameWrapper
<
H265FrameNoCacheAble
>
>
(
buf
,
pts
,
dts
,
4
);
return
std
::
make_shared
<
FrameWrapper
<
H265FrameNoCacheAble
>
>
(
buf
,
pts
,
dts
,
4
,
DATA_OFFSET
);
}
case
CodecAAC
:
{
AACTrack
::
Ptr
track
=
dynamic_pointer_cast
<
AACTrack
>
(
it
->
second
);
assert
(
track
);
//加上adts头
dumpAacConfig
(
track
->
getAacCfg
(),
buf
->
size
()
-
DATA_OFFSET
,
(
uint8_t
*
)
buf
->
data
()
+
(
DATA_OFFSET
-
ADTS_HEADER_LEN
),
ADTS_HEADER_LEN
);
return
std
::
make_shared
<
FrameWrapper
<
FrameFromPtr
>
>
(
buf
,
pts
,
dts
,
ADTS_HEADER_LEN
,
DATA_OFFSET
-
ADTS_HEADER_LEN
,
codec
);
}
case
CodecOpus
:
case
CodecAAC
:
case
CodecG711A
:
case
CodecG711U
:
{
return
std
::
make_shared
<
FrameWrapper
<
FrameFromPtr
>
>
(
codec
,
buf
,
pts
,
dts
,
0
);
return
std
::
make_shared
<
FrameWrapper
<
FrameFromPtr
>
>
(
buf
,
pts
,
dts
,
0
,
DATA_OFFSET
,
codec
);
}
default
:
return
nullptr
;
default
:
return
nullptr
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论