Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
GB28181Android
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
规范查询wiki:
http://gitlab.anweitech.com/root/AW-Project-Manage/wikis/pages
Open sidebar
Administrator
GB28181Android
Commits
ed6a66cd
提交
ed6a66cd
authored
9月 19, 2018
作者:
autulin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
大改造之使用新的API来完成读写分离,但是仍旧拯救不了性能
上级
e6b27d10
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
80 行增加
和
25 行删除
+80
-25
GB28181_sender.cpp
gb28181library/src/main/cpp/GB28181_sender.cpp
+40
-9
GB28181_sender.h
gb28181library/src/main/cpp/GB28181_sender.h
+1
-1
gb28181_muxer.cpp
gb28181library/src/main/cpp/gb28181_muxer.cpp
+0
-0
gb28181_muxer.h
gb28181library/src/main/cpp/gb28181_muxer.h
+9
-0
native-lib.cpp
gb28181library/src/main/cpp/native-lib.cpp
+2
-3
user_arguments.h
gb28181library/src/main/cpp/user_arguments.h
+1
-2
DemoActivity.java
...rc/main/java/com/autulin/gb28181library/DemoActivity.java
+3
-2
JNIBridge.java
...y/src/main/java/com/autulin/gb28181library/JNIBridge.java
+2
-1
MediaOutput.java
...src/main/java/com/autulin/gb28181library/MediaOutput.java
+11
-1
MediaRecorderBase.java
...in/java/com/autulin/gb28181library/MediaRecorderBase.java
+5
-5
MediaRecorderNative.java
.../java/com/autulin/gb28181library/MediaRecorderNative.java
+6
-1
没有找到文件。
gb28181library/src/main/cpp/GB28181_sender.cpp
浏览文件 @
ed6a66cd
...
...
@@ -46,15 +46,15 @@ void *GB28181_sender::processSend(void *obj) {
uint16_t
len
=
bytes2short
(
pkt_buf
);
uint64_t
t1
=
getCurrentTime
();
// char strBuf[16];
// sprintf(strBuf, "get pkt len: %d", len);
int
n
;
ssize_t
n
;
switch
(
gb28181Sender
->
args
->
outType
)
{
case
0
:
// udp
n
=
gb28181Sender
->
sendData
(
pkt_buf
+
2
,
len
);
LOG
E
(
"[sender]get pkt len: %d. sent %
d. (queue left size: %d)"
,
len
,
n
,
gb28181Sender
->
pkt_queue
.
size
());
LOG
I
(
"[sender][udp]get pkt len: %d. sent %l
d. (queue left size: %d)"
,
len
,
n
,
gb28181Sender
->
pkt_queue
.
size
());
break
;
case
1
:
// tcp
n
=
gb28181Sender
->
sendData
(
pkt_buf
,
len
+
2
);
LOGI
(
"[sender][tcp]get pkt len: %d. sent %ld. (queue left size: %d)"
,
len
,
n
,
gb28181Sender
->
pkt_queue
.
size
());
break
;
case
2
:
// file
gb28181Sender
->
fout
.
write
((
const
char
*
)
(
pkt_buf
+
2
),
len
);
...
...
@@ -104,13 +104,23 @@ int GB28181_sender::closeSender() {
}
int
GB28181_sender
::
initSocket
(
char
*
hostname
,
int
port
)
{
//todo
sockfd
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
);
switch
(
args
->
outType
)
{
case
0
:
// udp
sockfd
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
);
break
;
case
1
:
// tcp
sockfd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
break
;
default
:
sockfd
=
-
99
;
}
if
(
sockfd
<
0
){
LOGE
(
"ERROR opening socket
"
);
LOGE
(
"ERROR opening socket
.(%d)"
,
sockfd
);
return
sockfd
;
}
// 域名解析相关
// struct hostent *server;
// server = gethostbyname(hostname);
// if (server == NULL) {
...
...
@@ -127,11 +137,32 @@ int GB28181_sender::initSocket(char *hostname, int port) {
serveraddr
.
sin_port
=
htons
(
port
);
serverlen
=
sizeof
(
serveraddr
);
if
(
args
->
outType
==
1
)
{
// tcp
int
ret
=
connect
(
sockfd
,
(
const
sockaddr
*
)
&
serveraddr
,
serverlen
);
if
(
ret
<
0
){
LOGE
(
"ERROR connect.(%d)"
,
ret
);
return
ret
;
}
}
return
0
;
}
int
GB28181_sender
::
sendData
(
uint8_t
*
buf
,
int
len
)
{
int
n
=
sendto
(
sockfd
,
buf
,
len
,
0
,
(
const
sockaddr
*
)
&
serveraddr
,
serverlen
);
ssize_t
GB28181_sender
::
sendData
(
uint8_t
*
buf
,
int
len
)
{
ssize_t
n
=
0
;
switch
(
args
->
outType
)
{
case
0
:
// udp
n
=
sendto
(
sockfd
,
buf
,
len
,
0
,
(
const
sockaddr
*
)
&
serveraddr
,
serverlen
);
break
;
case
1
:
// tcp
n
=
send
(
sockfd
,
buf
,
len
,
0
);
break
;
default
:
return
-
1
;
}
if
(
n
<
0
)
{
LOGE
(
"send error.(%ld)"
,
n
);
}
return
n
;
}
...
...
gb28181library/src/main/cpp/GB28181_sender.h
浏览文件 @
ed6a66cd
...
...
@@ -47,7 +47,7 @@ private:
int
serverlen
;
int
initSocket
(
char
*
hostname
,
int
port
);
in
t
sendData
(
uint8_t
*
buf
,
int
len
);
ssize_
t
sendData
(
uint8_t
*
buf
,
int
len
);
int
closeSocket
();
...
...
gb28181library/src/main/cpp/gb28181_muxer.cpp
浏览文件 @
ed6a66cd
差异被折叠。
点击展开。
gb28181library/src/main/cpp/gb28181_muxer.h
浏览文件 @
ed6a66cd
...
...
@@ -21,6 +21,7 @@ public:
int
initMuxer
();
static
void
*
startMux
(
void
*
obj
);
static
void
*
startEncode
(
void
*
obj
);
int
sendVideoFrame
(
uint8_t
*
buf
);
...
...
@@ -43,6 +44,7 @@ private:
GB28181_sender
*
gb28181Sender
;
int
is_end
=
START_STATE
;
int
is_release
=
RELEASE_FALSE
;
threadsafe_queue
<
AVFrame
*>
vFrame_queue
;
threadsafe_queue
<
uint8_t
*>
video_queue
;
threadsafe_queue
<
uint8_t
*>
audio_queue
;
AVFormatContext
*
pFormatCtx
;
...
...
@@ -61,6 +63,13 @@ private:
int64_t
startTime
=
0
;
int
in_y_size
;
//合成相关的参数
int
g711aFrameLen
=
0
;
int64_t
lastPts
=
0
;
int64_t
frameAppend
=
0
;
int
scrPerFrame
;
int
muxCnt
=
0
;
int
mux
(
GB28181Muxer
*
gb28181Muxer
);
AVFrame
*
genFrame
(
uint8_t
*
rawData
);
};
...
...
gb28181library/src/main/cpp/native-lib.cpp
浏览文件 @
ed6a66cd
...
...
@@ -32,7 +32,7 @@ Java_com_autulin_gb28181library_JNIBridge_initMuxer(JNIEnv *env, jclass type, js
jstring
mediaBasePath_
,
jstring
mediaName_
,
jint
filter
,
jint
in_width
,
jint
in_height
,
jint
out_width
,
jint
out_height
,
jint
frameRate
,
jlong
bit_rate
,
jint
audioFrameLen
)
{
jlong
bit_rate
,
jint
audioFrameLen
,
jint
ssrc
)
{
const
char
*
ip
=
env
->
GetStringUTFChars
(
ip_
,
0
);
const
char
*
mediaBasePath
=
env
->
GetStringUTFChars
(
mediaBasePath_
,
0
);
const
char
*
mediaName
=
env
->
GetStringUTFChars
(
mediaName_
,
0
);
...
...
@@ -44,8 +44,7 @@ Java_com_autulin_gb28181library_JNIBridge_initMuxer(JNIEnv *env, jclass type, js
strcpy
(
arguments
->
ip_addr
,
ip
);
arguments
->
port
=
port
;
arguments
->
outType
=
outType
;
arguments
->
media_base_path
=
mediaBasePath
;
arguments
->
media_name
=
mediaName
;
arguments
->
ssrc
=
ssrc
;
size_t
m_path_size
=
strlen
(
mediaBasePath
)
+
strlen
(
mediaName
)
+
strlen
(
MEDIA_FORMAT
)
+
1
;
arguments
->
media_path
=
(
char
*
)
malloc
(
m_path_size
+
1
);
...
...
gb28181library/src/main/cpp/user_arguments.h
浏览文件 @
ed6a66cd
...
...
@@ -9,8 +9,6 @@ typedef struct UserArguments {
char
*
ip_addr
;
int
port
;
int
outType
;
const
char
*
media_base_path
;
//文件储存地址
const
char
*
media_name
;
// 文件命令前缀
char
*
media_path
;
//合成后的MP4储存地址
int
in_width
;
//输出宽度
int
in_height
;
//输入高度
...
...
@@ -20,6 +18,7 @@ typedef struct UserArguments {
int64_t
video_bit_rate
;
//视频比特率控制
int
v_custom_format
;
//一些滤镜操作控制
int
a_frame_len
;
int
ssrc
;
JNIEnv
*
env
;
//env全局指针
JavaVM
*
javaVM
;
//jvm指针
jclass
java_class
;
//java接口类的calss对象
...
...
gb28181library/src/main/java/com/autulin/gb28181library/DemoActivity.java
浏览文件 @
ed6a66cd
...
...
@@ -119,8 +119,9 @@ public class DemoActivity extends AppCompatActivity implements
// 设置输出
// String fileName = String.valueOf(System.currentTimeMillis());
String
fileName
=
"tttttt"
;
// mediaOutput = mMediaRecorder.setFileOutPut(fileName); //输出到文件,这里demo是/sdcard/DCIM/pstest/tttttt.ps
mediaOutput
=
mMediaRecorder
.
setUdpOutPut
(
"10.112.181.160"
,
8888
);
mediaOutput
=
mMediaRecorder
.
setFileOutPut
(
fileName
);
//输出到文件,这里demo是/sdcard/DCIM/pstest/tttttt.ps
// int ssrc = 1;
// mediaOutput = mMediaRecorder.setUdpOutPut("10.112.181.160", 8888, ssrc);
mMediaRecorder
.
setSurfaceHolder
(
mSurfaceView
.
getHolder
());
mMediaRecorder
.
prepare
();
...
...
gb28181library/src/main/java/com/autulin/gb28181library/JNIBridge.java
浏览文件 @
ed6a66cd
...
...
@@ -64,7 +64,8 @@ public class JNIBridge {
int
out_height
,
int
frameRate
,
long
bit_rate
,
int
audioFrameLen
int
audioFrameLen
,
int
ssrc
);
public
static
native
int
sendOneVideoFrame
(
byte
[]
data
);
...
...
gb28181library/src/main/java/com/autulin/gb28181library/MediaOutput.java
浏览文件 @
ed6a66cd
...
...
@@ -6,13 +6,15 @@ public class MediaOutput {
private
String
outputDir
;
private
String
outputName
;
private
int
outputType
;
private
int
ssrc
;
public
MediaOutput
(
String
ip
,
int
port
,
String
outputDir
,
String
outputName
,
int
outputType
)
{
public
MediaOutput
(
String
ip
,
int
port
,
String
outputDir
,
String
outputName
,
int
outputType
,
int
ssrc
)
{
this
.
ip
=
ip
;
this
.
port
=
port
;
this
.
outputDir
=
outputDir
;
this
.
outputName
=
outputName
;
this
.
outputType
=
outputType
;
this
.
ssrc
=
ssrc
;
}
public
String
getIp
()
{
...
...
@@ -54,4 +56,12 @@ public class MediaOutput {
public
void
setOutputType
(
int
outputType
)
{
this
.
outputType
=
outputType
;
}
public
int
getSsrc
()
{
return
ssrc
;
}
public
void
setSsrc
(
int
ssrc
)
{
this
.
ssrc
=
ssrc
;
}
}
gb28181library/src/main/java/com/autulin/gb28181library/MediaRecorderBase.java
浏览文件 @
ed6a66cd
...
...
@@ -712,13 +712,13 @@ public abstract class MediaRecorderBase implements Callback, PreviewCallback, IM
this
.
mFrameRateCmd
=
String
.
format
(
" -r %d"
,
rate
);
}
public
MediaOutput
setTcpOutPut
(
String
ip
,
int
port
)
{
mediaOutput
=
new
MediaOutput
(
ip
,
port
,
""
,
""
,
JNIBridge
.
TCP
);
public
MediaOutput
setTcpOutPut
(
String
ip
,
int
port
,
int
ssrc
)
{
mediaOutput
=
new
MediaOutput
(
ip
,
port
,
""
,
""
,
JNIBridge
.
TCP
,
ssrc
);
return
mediaOutput
;
}
public
MediaOutput
setUdpOutPut
(
String
ip
,
int
port
)
{
mediaOutput
=
new
MediaOutput
(
ip
,
port
,
""
,
""
,
JNIBridge
.
UDP
);
public
MediaOutput
setUdpOutPut
(
String
ip
,
int
port
,
int
ssrc
)
{
mediaOutput
=
new
MediaOutput
(
ip
,
port
,
""
,
""
,
JNIBridge
.
UDP
,
ssrc
);
return
mediaOutput
;
}
...
...
@@ -741,7 +741,7 @@ public abstract class MediaRecorderBase implements Callback, PreviewCallback, IM
if
(!
file
.
exists
())
{
file
.
mkdirs
();
}
mediaOutput
=
new
MediaOutput
(
""
,
0
,
path
,
fileName
,
JNIBridge
.
FILE
);
mediaOutput
=
new
MediaOutput
(
""
,
0
,
path
,
fileName
,
JNIBridge
.
FILE
,
0
);
return
mediaOutput
;
}
}
gb28181library/src/main/java/com/autulin/gb28181library/MediaRecorderNative.java
浏览文件 @
ed6a66cd
...
...
@@ -16,12 +16,16 @@ public class MediaRecorderNative extends MediaRecorderBase implements MediaRecor
JNIBridge
.
endMux
();
}
long
t
=
System
.
currentTimeMillis
();
/**
* 视频数据回调
*/
@Override
public
void
onPreviewFrame
(
byte
[]
data
,
Camera
camera
)
{
if
(
mRecording
)
{
long
nt
=
System
.
currentTimeMillis
();
Log
.
e
(
"now"
,
"onPreviewFrame: "
+
nt
+
", div:"
+
(
nt
-
t
));
t
=
nt
;
JNIBridge
.
sendOneVideoFrame
(
data
);
mPreviewFrameCallCount
++;
}
...
...
@@ -81,7 +85,8 @@ public class MediaRecorderNative extends MediaRecorderBase implements MediaRecor
SMALL_VIDEO_HEIGHT
,
mFrameRate
,
mVideoBitrate
,
mAudioCollector
.
getFrameLen
()
mAudioCollector
.
getFrameLen
(),
mediaOutput
.
getSsrc
()
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论