提交 1eac4633 authored 作者: autulin's avatar autulin

1.绑定本地端口

2.视频预览优化
上级 6e09bf98
......@@ -23,6 +23,7 @@ public class DemoActivity extends AppCompatActivity implements
private Button mButton;
private SurfaceView mSurfaceView;
private RelativeLayout bottomLayout;
private MediaRecorderNative mMediaRecorder;
private MediaOutput mediaOutput;
......@@ -92,6 +93,7 @@ public class DemoActivity extends AppCompatActivity implements
private void initView() {
mButton = findViewById(R.id.start_btn);
mSurfaceView = findViewById(R.id.record_preview);
bottomLayout = findViewById(R.id.bottom_lt);
}
/**
......@@ -102,14 +104,15 @@ public class DemoActivity extends AppCompatActivity implements
mMediaRecorder.setOnErrorListener(this);
mMediaRecorder.setOnPreparedListener(this);
// mMediaRecorder.setCameraFront();
// mMediaRecorder.setCameraFront(); // 设置前置摄像头
// 设置输出
// String fileName = String.valueOf(System.currentTimeMillis());
// String fileName = "tttttt";
// mediaOutput = mMediaRecorder.setFileOutPut(fileName); //输出到文件,这里demo是/sdcard/pstest/tttttt.ps
int ssrc = 1;
mediaOutput = mMediaRecorder.setUdpOutPut("10.210.100.76", 8888, ssrc);
// mediaOutput = mMediaRecorder.setUdpOutPut("10.210.100.69", 8888, ssrc);
mediaOutput = mMediaRecorder.setTcpOutPut("10.210.100.69", 8888,8088, ssrc);
mMediaRecorder.setSurfaceHolder(mSurfaceView.getHolder());
mMediaRecorder.prepare();
......@@ -120,8 +123,10 @@ public class DemoActivity extends AppCompatActivity implements
*/
private void initSurfaceView() {
final int w = DeviceUtils.getScreenWidth(this);
// 避免摄像头的转换,只取上面h部分
((RelativeLayout.LayoutParams)bottomLayout.getLayoutParams()).topMargin = (int) (w / (MediaRecorderBase.SMALL_VIDEO_HEIGHT / (MediaRecorderBase.SMALL_VIDEO_WIDTH * 1.0f)));
int width = w;
int height = (int) (w * ((MediaRecorderBase.mSupportedPreviewWidth * 1.0f) / MediaRecorderBase.SMALL_VIDEO_HEIGHT));
int height = (int) (w * (MediaRecorderBase.mSupportedPreviewWidth * 1.0f)) / MediaRecorderBase.SMALL_VIDEO_HEIGHT;
Log.e("debug", "initSurfaceView: w=" + width + ",h=" + height);
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mSurfaceView
.getLayoutParams();
......
......@@ -12,17 +12,23 @@
android:layout_height="match_parent" />
</FrameLayout>
<RelativeLayout
android:id="@+id/bottom_lt"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/start_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:text="开始录制"/>
</RelativeLayout>
<Button
android:id="@+id/start_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:text="开始录制"/>
</RelativeLayout>
\ No newline at end of file
......@@ -10,12 +10,12 @@ GB28181_sender::GB28181_sender(UserArguments *arg) : args(arg) {}
int GB28181_sender::initSender() {
switch (args->outType) {
case 0: // udp
LOGE("ip:%s, port:%d, out_type:%d", args->ip_addr, args->port, args->outType);
initSocket(args->ip_addr, args->port);
LOGE("ip:%s, remotePort:%d, out_type:%d", args->ip_addr, args->remotePort, args->outType);
initSocket(args->ip_addr, args->remotePort, args->localPort);
break;
case 1: // tcp
LOGE("ip:%s, port:%d, out_type:%d", args->ip_addr, args->port, args->outType);
initSocket(args->ip_addr, args->port);
LOGE("ip:%s, remotePort:%d, localPort:%d out_type:%d", args->ip_addr, args->remotePort, args->localPort, args->outType);
initSocket(args->ip_addr, args->remotePort, args->localPort);
break;
case 2: // file
//打开ps文件
......@@ -108,7 +108,7 @@ int GB28181_sender::closeSender() {
return n;
}
int GB28181_sender::initSocket(char *hostname, int port) {
int GB28181_sender::initSocket(char *hostname, int port, int localPort) {
switch (args->outType) {
case 0: // udp
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
......@@ -143,6 +143,18 @@ int GB28181_sender::initSocket(char *hostname, int port) {
serverlen = sizeof(serveraddr);
if (args->outType == 1) { // tcp
if (args->localPort != 0) {
struct sockaddr_in client_addr;
bzero((char *) &client_addr, sizeof(client_addr));
client_addr.sin_family = AF_INET;
client_addr.sin_addr.s_addr = INADDR_ANY;
client_addr.sin_port = htons(args->localPort);
int ret = bind(sockfd, (struct sockaddr *) &client_addr, sizeof(client_addr));
if ( ret < 0){
LOGE("ERROR local bind.(%d)", ret);
return ret;
}
}
int ret = connect(sockfd, (const sockaddr *) &serveraddr, serverlen);
if (ret < 0){
LOGE("ERROR connect.(%d)", ret);
......
......@@ -46,7 +46,7 @@ private:
struct sockaddr_in serveraddr;
int serverlen;
int initSocket(char* hostname, int port);
int initSocket(char* hostname, int port, int localPort);
ssize_t sendData(uint8_t * buf, int len);
int closeSocket();
......
......@@ -28,7 +28,7 @@ Java_com_autulin_gb28181library_JNIBridge_getFFmpegConfig(JNIEnv *env, jclass ty
extern "C"
JNIEXPORT jint JNICALL
Java_com_autulin_gb28181library_JNIBridge_initMuxer(JNIEnv *env, jclass type, jstring ip_,
jint port, jint outType,
jint remote_port, jint local_port, jint outType,
jstring mediaBasePath_, jstring mediaName_,
jint filter, jint in_width, jint in_height,
jint out_width, jint out_height, jint frameRate,
......@@ -42,7 +42,8 @@ Java_com_autulin_gb28181library_JNIBridge_initMuxer(JNIEnv *env, jclass type, js
arguments->ip_addr = (char *) malloc(strlen(ip) + 1);
strcpy(arguments->ip_addr, ip);
arguments->port = port;
arguments->remotePort = remote_port;
arguments->localPort = local_port;
arguments->outType = outType;
arguments->ssrc = ssrc;
arguments->queue_max = queue_max;
......
......@@ -7,7 +7,8 @@
class JNIHandler;
typedef struct UserArguments {
char *ip_addr;
int port;
int remotePort;
int localPort;
int outType;
char *media_path; //合成后的MP4储存地址
int in_width; //输出宽度
......
......@@ -53,7 +53,8 @@ public class JNIBridge {
*/
public static native int initMuxer(
String ip,
int port,
int remotePort,
int localPort,
int outType,
String mediaBasePath,
String mediaName,
......
......@@ -7,6 +7,7 @@ public class MediaOutput {
private String outputName;
private int outputType;
private int ssrc;
private int localPort = 0;
public MediaOutput(String ip, int port, String outputDir, String outputName, int outputType, int ssrc) {
this.ip = ip;
......@@ -17,6 +18,16 @@ public class MediaOutput {
this.ssrc = ssrc;
}
public MediaOutput(String ip, int port, int localPort, 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;
this.localPort = localPort;
}
public String getIp() {
return ip;
}
......@@ -64,4 +75,12 @@ public class MediaOutput {
public void setSsrc(int ssrc) {
this.ssrc = ssrc;
}
public int getLocalPort() {
return localPort;
}
public void setLocalPort(int localPort) {
this.localPort = localPort;
}
}
......@@ -727,8 +727,8 @@ public abstract class MediaRecorderBase implements Callback, PreviewCallback, IM
this.mFrameRateCmd= String.format(" -r %d",rate);
}
public MediaOutput setTcpOutPut(String ip, int port, int ssrc) {
mediaOutput = new MediaOutput(ip, port, "", "", JNIBridge.TCP, ssrc);
public MediaOutput setTcpOutPut(String ip, int remotePort, int localPort, int ssrc) {
mediaOutput = new MediaOutput(ip, remotePort, localPort, "", "", JNIBridge.TCP, ssrc);
return mediaOutput;
}
......
......@@ -75,6 +75,7 @@ public class MediaRecorderNative extends MediaRecorderBase implements MediaRecor
JNIBridge.initMuxer(
mediaOutput.getIp(),
mediaOutput.getPort(),
mediaOutput.getLocalPort(),
mediaOutput.getOutputType(),
mediaOutput.getOutputDir(),
mediaOutput.getOutputName(),
......
......@@ -13,8 +13,8 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Wed Sep 12 17:58:18 CST 2018
systemProp.https.proxyPort=1080
systemProp.http.proxyHost=127.0.0.1
org.gradle.jvmargs=-Xmx1536m
systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080
#systemProp.https.proxyPort=1080
#systemProp.http.proxyHost=127.0.0.1
org.gradle.jvmargs=-Xmx2048m -DsocksProxyHost\=127.0.0.1 -DsocksProxyPort\=1080
#systemProp.https.proxyHost=127.0.0.1
#systemProp.http.proxyPort=1080
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论