Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
29ec8fc8
提交
29ec8fc8
authored
8月 13, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
60169a54
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
44 行增加
和
48 行删除
+44
-48
common.hpp
opencv-motion-detect/inc/common.hpp
+44
-48
没有找到文件。
opencv-motion-detect/inc/common.hpp
浏览文件 @
29ec8fc8
...
@@ -29,7 +29,7 @@ namespace AVPacketSerializer {
...
@@ -29,7 +29,7 @@ namespace AVPacketSerializer {
//data
//data
char
mark_s
[]
=
PS_MARK_S
;
char
mark_s
[]
=
PS_MARK_S
;
char
mark_e
[]
=
PS_MARK_E
;
char
mark_e
[]
=
PS_MARK_E
;
int
wholeSize
=
s
izeof
(
mark_s
)
-
1
+
sizeof
(
pkt
.
size
)
+
pkt
.
size
;
int
wholeSize
=
s
trlen
(
PS_MARK_S
)
+
sizeof
(
pkt
.
size
)
+
pkt
.
size
;
//side data
//side data
wholeSize
+=
sizeof
(
pkt
.
side_data_elems
);
wholeSize
+=
sizeof
(
pkt
.
side_data_elems
);
if
(
pkt
.
side_data_elems
!=
0
)
{
if
(
pkt
.
side_data_elems
!=
0
)
{
...
@@ -39,11 +39,11 @@ namespace AVPacketSerializer {
...
@@ -39,11 +39,11 @@ namespace AVPacketSerializer {
}
}
// 4 + 8: wholeSize + DEADBEAF
// 4 + 8: wholeSize + DEADBEAF
wholeSize
+=
sizeof
(
pkt
.
pts
)
*
5
+
sizeof
(
pkt
.
flags
)
+
sizeof
(
pkt
.
stream_index
)
+
sizeof
(
wholeSize
)
+
s
izeof
(
mark_e
)
-
1
;
wholeSize
+=
sizeof
(
pkt
.
pts
)
*
5
+
sizeof
(
pkt
.
flags
)
+
sizeof
(
pkt
.
stream_index
)
+
sizeof
(
wholeSize
)
+
s
trlen
(
PS_MARK_E
)
;
*
bytes
=
(
char
*
)
malloc
(
wholeSize
);
*
bytes
=
(
char
*
)
malloc
(
wholeSize
);
memcpy
((
*
bytes
)
+
cnt
,
mark_s
,
s
izeof
(
mark_s
)
-
1
);
memcpy
((
*
bytes
)
+
cnt
,
mark_s
,
s
trlen
(
PS_MARK_S
)
);
cnt
+=
s
izeof
(
mark_s
)
-
1
;
cnt
+=
s
trlen
(
PS_MARK_S
)
;
// data
// data
memcpy
((
*
bytes
)
+
cnt
,
&
(
pkt
.
size
),
sizeof
(
pkt
.
size
));
memcpy
((
*
bytes
)
+
cnt
,
&
(
pkt
.
size
),
sizeof
(
pkt
.
size
));
cnt
+=
sizeof
(
pkt
.
size
);
cnt
+=
sizeof
(
pkt
.
size
);
...
@@ -80,8 +80,8 @@ namespace AVPacketSerializer {
...
@@ -80,8 +80,8 @@ namespace AVPacketSerializer {
cnt
+=
sizeof
(
pkt
.
stream_index
);
cnt
+=
sizeof
(
pkt
.
stream_index
);
memcpy
((
*
bytes
)
+
cnt
,
&
wholeSize
,
sizeof
(
wholeSize
));
memcpy
((
*
bytes
)
+
cnt
,
&
wholeSize
,
sizeof
(
wholeSize
));
cnt
+=
sizeof
(
wholeSize
);
cnt
+=
sizeof
(
wholeSize
);
memcpy
((
*
bytes
)
+
cnt
,
mark_e
,
s
izeof
(
mark_e
)
-
1
);
memcpy
((
*
bytes
)
+
cnt
,
mark_e
,
s
trlen
(
PS_MARK_E
)
);
cnt
+=
s
izeof
(
mark_e
)
-
1
;
cnt
+=
s
trlen
(
PS_MARK_E
)
;
av_log_set_level
(
AV_LOG_DEBUG
);
av_log_set_level
(
AV_LOG_DEBUG
);
assert
(
cnt
==
wholeSize
);
assert
(
cnt
==
wholeSize
);
av_log
(
NULL
,
AV_LOG_DEBUG
,
"
\n\n\n
pkt origin size %d, serialized size: %d, elems:%d
\n\n\n
"
,
pkt
.
size
,
wholeSize
,
pkt
.
side_data_elems
);
av_log
(
NULL
,
AV_LOG_DEBUG
,
"
\n\n\n
pkt origin size %d, serialized size: %d, elems:%d
\n\n\n
"
,
pkt
.
size
,
wholeSize
,
pkt
.
side_data_elems
);
...
@@ -95,12 +95,12 @@ namespace AVPacketSerializer {
...
@@ -95,12 +95,12 @@ namespace AVPacketSerializer {
int
got
=
0
;
int
got
=
0
;
char
mark_s
[]
=
PS_MARK_S
;
char
mark_s
[]
=
PS_MARK_S
;
char
mark_e
[]
=
PS_MARK_E
;
char
mark_e
[]
=
PS_MARK_E
;
if
(
memcmp
(
mark_e
,
bytes
+
len
-
s
izeof
(
mark_e
)
+
1
,
sizeof
(
mark_e
)
-
1
)
!=
0
||
memcmp
(
mark_s
,
bytes
,
sizeof
(
mark_s
)
-
1
))
{
if
(
memcmp
(
mark_e
,
bytes
+
len
-
s
trlen
(
PS_MARK_E
),
strlen
(
PS_MARK_E
))
!=
0
||
memcmp
(
mark_s
,
bytes
,
strlen
(
PS_MARK_S
)
))
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"invalid packet"
);
av_log
(
NULL
,
AV_LOG_ERROR
,
"invalid packet"
);
return
-
1
;
return
-
1
;
}
}
//skip mark_s
//skip mark_s
got
+=
s
izeof
(
mark_s
)
-
1
;
got
+=
s
trlen
(
PS_MARK_S
)
;
memcpy
(
&
(
pkt
->
size
),
bytes
+
got
,
sizeof
(
pkt
->
size
));
memcpy
(
&
(
pkt
->
size
),
bytes
+
got
,
sizeof
(
pkt
->
size
));
got
+=
sizeof
(
pkt
->
size
);
got
+=
sizeof
(
pkt
->
size
);
av_new_packet
(
pkt
,
pkt
->
size
);
av_new_packet
(
pkt
,
pkt
->
size
);
...
@@ -148,50 +148,46 @@ void mqPacketFree(void *data, void*hint) {
...
@@ -148,50 +148,46 @@ void mqPacketFree(void *data, void*hint) {
}
}
namespace
AVFormatCtxSerializer
{
namespace
AVFormatCtxSerializer
{
struct
AVFormatCtx
{
int
_encode
(
AVFormatContext
*
ctx
,
char
**
bytes
)
{
AVFormatCtx
()
{}
;
int
ret
=
0
;
AVFormatCtx
(
char
*
bytes
,
int
len
)
{
int
wholeSize
=
0
;
_decode
(
bytes
,
len
)
;
int
got
=
0
;
}
char
mark_s
[]
=
PS_MARK_S
;
char
mark_e
[]
=
PS_MARK_E
;
AVFormatCtx
(
AVFormatContext
*
pCtx
)
:
pCtx
(
pCtx
)
{
// calc total size
}
wholeSize
+=
strlen
(
PS_MARK_S
);
// num streams
~
AVFormatCtx
()
{
wholeSize
+=
sizeof
(
ctx
->
nb_streams
);
}
wholeSize
+=
sizeof
(
ctx
->
nb_streams
);
for
(
int
i
=
0
;
i
<
ctx
->
nb_streams
;
i
++
)
{
int
toBytes
(
char
**
bytes
)
{
wholeSize
+=
sizeof
(
AVStream
);
return
_encode
(
pCtx
,
byte
s
);
wholeSize
+=
sizeof
(
AVCodecParameter
s
);
}
}
wholeSize
+=
sizeof
(
wholeSize
);
int
fromBytes
(
char
*
bytes
,
int
len
)
{
wholeSize
+=
strlen
(
PS_MARK_E
);
return
_decode
(
bytes
,
len
);
// alloc memory
*
bytes
=
(
char
*
)
malloc
(
wholeSize
);
// populate
memcpy
((
*
bytes
)
+
got
,
PS_MARK_S
,
strlen
(
PS_MARK_S
));
got
+=
strlen
(
PS_MARK_S
);
memcpy
((
*
bytes
)
+
got
,
(
void
*
)
&
(
ctx
->
nb_streams
),
sizeof
(
ctx
->
nb_streams
));
got
+=
sizeof
(
ctx
->
nb_streams
);
for
(
int
i
=
0
;
i
<
ctx
->
nb_streams
;
i
++
)
{
//
memcpy
((
*
bytes
)
+
got
,
ctx
->
streams
[
i
],
sizeof
(
AVStream
));
got
+=
sizeof
(
AVStream
);
//
memcpy
((
*
bytes
)
+
got
,
ctx
->
streams
[
i
]
->
codecpar
,
sizeof
(
AVCodecParameters
));
got
+=
sizeof
(
AVCodecParameters
);
}
}
memcpy
((
*
bytes
)
+
got
,
&
wholeSize
,
sizeof
(
wholeSize
));
private
:
int
nb_streams
;
}
AVStream
*
streams
=
NULL
;
AVFormatContext
*
pCtx
=
NULL
;
int
_encode
(
AVFormatContext
*
ctx
,
char
**
bytes
)
{
int
ret
=
0
;
int
wholeSize
=
0
;
int
got
=
0
;
char
mark_s
[]
=
PS_MARK_S
;
char
mark_e
[]
=
PS_MARK_E
;
wholeSize
+=
sizeof
(
mark_s
)
-
1
;
// num streams
wholeSize
+=
sizeof
(
pCtx
->
nb_streams
);
for
(
int
i
=
0
;
i
<
pCtx
->
nb_streams
;
i
++
)
{
wholeSize
+=
sizeof
(
AVStream
);
}
wholeSize
+=
sizeof
(
wholeSize
);
}
int
_decode
(
char
*
bytes
,
int
len
)
{
int
_decode
(
char
*
bytes
,
int
len
)
{
}
}
};
}
}
#endif
#endif
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论