Skip to content

Commit

Permalink
docs: 1# added RTSP related tutorials (添加RTSP相关教程); 2# upgrade to v1.…
Browse files Browse the repository at this point in the history
…4.0 (版本升级到v1.4.0);
  • Loading branch information
xingshuangs committed Jun 20, 2023
1 parent 8a5edec commit 8e725f6
Show file tree
Hide file tree
Showing 13 changed files with 1,007 additions and 13 deletions.
14 changes: 9 additions & 5 deletions README-CN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IOT-COMMUNICATION

[![Maven-v1.3.0](https://img.shields.io/badge/Maven-v1.3.0-brightgreen)](https://mvnrepository.com/artifact/com.github.xingshuangs/iot-communication)
[![Maven-v1.4.0](https://img.shields.io/badge/Maven-v1.4.0-brightgreen)](https://mvnrepository.com/artifact/com.github.xingshuangs/iot-communication)
![Language-java8](https://img.shields.io/badge/Language-java8-blue)
![Idea-2022.02.03](https://img.shields.io/badge/Idea-2022.02.03-lightgrey)
![CopyRight-Oscura](https://img.shields.io/badge/CopyRight-Oscura-yellow)
Expand All @@ -14,9 +14,11 @@

目前它只是一个物联网通信的工具,包含

- 西门子S7通信协议;
- ModbusTCP通信协议;
- 基础字节数组解析转换工具;
- 西门子S7通信协议
- ModbusTCP通信协议
- RTSP、RTCP、RTP、H264协议
- MP4 (FMP4) 协议
- 基础字节数组解析转换工具

## 使用指南

Expand All @@ -28,7 +30,7 @@
<dependency>
<groupId>com.github.xingshuangs</groupId>
<artifactId>iot-communication</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</dependency>
```

Expand All @@ -55,6 +57,8 @@ class Demo {

- [西门子S7通信协议](./tutorial/README-S7-CN.md)
- [ModbusTCP通信协议](./tutorial/README-Modbus-CN.md)
- [RTSP/RTCP/RTP/H264协议](./tutorial/README-RTSP-CN.md)
- [WEB视频监控](./tutorial/README-WebVideo-CN.md)
- [字节数据解析转换工具](./tutorial/README-ByteArray-CN.md)

## 联系方式
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IOT-COMMUNICATION

[![Maven-v1.3.0](https://img.shields.io/badge/Maven-v1.3.0-brightgreen)](https://mvnrepository.com/artifact/com.github.xingshuangs/iot-communication)
[![Maven-v1.4.0](https://img.shields.io/badge/Maven-v1.4.0-brightgreen)](https://mvnrepository.com/artifact/com.github.xingshuangs/iot-communication)
![Language-java8](https://img.shields.io/badge/Language-java8-blue)
![Idea-2022.02.03](https://img.shields.io/badge/Idea-2022.02.03-lightgrey)
![CopyRight-Oscura](https://img.shields.io/badge/CopyRight-Oscura-yellow)
Expand All @@ -16,6 +16,8 @@ Now, it is a tool for iot communication, it includes

- Siemens S7 protocol.
- ModbusTCP protocol.
- RTSP, RTCP, RTP, H264 protocol.
- MP4 (FMP4) protocol.
- Parse byte array data.

## Getting Started
Expand All @@ -28,7 +30,7 @@ Add the dependency to pom.xml in the JAVA project.
<dependency>
<groupId>com.github.xingshuangs</groupId>
<artifactId>iot-communication</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</dependency>
```

Expand All @@ -55,6 +57,8 @@ class Demo {

- [Siemens S7 Protocol Tutorial.](./tutorial/README-S7-EN.md)
- [ModbusTCP Protocol Tutorial.](./tutorial/README-Modbus-EN.md)
- [RTSP/RTCP/RTP/H264 Protocol Tutorial](./tutorial/README-RTSP-EN.md)
- [WEB Video Monitor Tutorial](./tutorial/README-WebVideo-EN.md)
- [Tool for Byte Array Data Parse Tutorial.](./tutorial/README-ByteArray-EN.md)

## Contact
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<groupId>com.github.xingshuangs</groupId>
<artifactId>iot-communication</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
<packaging>jar</packaging>

<name>iot-communication</name>
<description>iot-communication is a tool 目前支持S7、ModbusTCP通信协议、字节数据转换</description>
<description>iot-communication is a tool 目前支持S7、ModbusTCP通信协议、字节数据转换、RTSP视频监控</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.github.xingshuangs.iot.protocol.rtsp.service;


import com.github.xingshuangs.iot.protocol.rtsp.authentication.DigestAuthenticator;
import com.github.xingshuangs.iot.protocol.rtsp.authentication.UsernamePasswordCredential;
import com.github.xingshuangs.iot.protocol.rtsp.enums.ERtspTransportProtocol;

import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
* @author xingshuang
*/
public class DemoRtspFMp4ProxyTcpSync {

public static void main(String[] args) {
// rtsp的摄像头地址
URI uri = URI.create("rtsp://192.168.3.1:554/h264/ch1/main/av_stream");
// 身份认证
UsernamePasswordCredential credential = new UsernamePasswordCredential("admin", "123456");
DigestAuthenticator authenticator = new DigestAuthenticator(credential);
// 构建RTSP客户端对象,此处采用TCP的通信方式
RtspClient client = new RtspClient(uri, authenticator, ERtspTransportProtocol.TCP);
// 构建FMp4代理,此处采用同步方式
RtspFMp4Proxy proxy = new RtspFMp4Proxy(client);
// 设置FMP4数据接收事件
proxy.onFmp4DataHandle(x -> {
// *****编写处理数据业务*****
System.out.println(x.length);
});
// 设置编解码格式数据事件
proxy.onCodecHandle(x->{
// *****编写处理数据业务*****
System.out.println(x);
});
// 采用异步的形式关闭,由于是测试示例,写在启动前面
CompletableFuture.runAsync(() -> {
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
proxy.stop();
});
// 启动,返回异步执行对象
CompletableFuture<Void> future = proxy.start();
// 循环等待结束
while (!future.isDone()) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.github.xingshuangs.iot.protocol.rtsp.service;


import com.github.xingshuangs.iot.protocol.rtsp.authentication.DigestAuthenticator;
import com.github.xingshuangs.iot.protocol.rtsp.authentication.UsernamePasswordCredential;
import com.github.xingshuangs.iot.protocol.rtsp.enums.ERtspTransportProtocol;

import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
* @author xingshuang
*/
public class DemoRtspFMp4ProxyUdpAsync {

public static void main(String[] args) {
// rtsp的摄像头地址
URI uri = URI.create("rtsp://192.168.3.1:554/h264/ch1/main/av_stream");
// 身份认证
UsernamePasswordCredential credential = new UsernamePasswordCredential("admin", "123456");
DigestAuthenticator authenticator = new DigestAuthenticator(credential);
// 构建RTSP客户端对象,此处采用UDP的通信方式
RtspClient client = new RtspClient(uri, authenticator, ERtspTransportProtocol.UDP);
// 构建FMp4代理,此处采用异步方式
RtspFMp4Proxy proxy = new RtspFMp4Proxy(client, true);
// 设置FMP4数据接收事件
proxy.onFmp4DataHandle(x -> {
// *****编写处理数据业务*****
System.out.println(x.length);
});
// 设置编解码格式数据事件
proxy.onCodecHandle(x->{
// *****编写处理数据业务*****
System.out.println(x);
});
// 采用异步的形式关闭,由于是测试示例,写在启动前面
CompletableFuture.runAsync(() -> {
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
proxy.stop();
});
// 启动,返回异步执行对象
CompletableFuture<Void> future = proxy.start();
// 循环等待结束
while (!future.isDone()) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.github.xingshuangs.iot.protocol.rtsp.service;


import com.github.xingshuangs.iot.protocol.rtp.model.frame.H264VideoFrame;
import com.github.xingshuangs.iot.protocol.rtsp.authentication.DigestAuthenticator;
import com.github.xingshuangs.iot.protocol.rtsp.authentication.UsernamePasswordCredential;

import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
* @author xingshuang
*/
public class DemoRtspTcpAuthenticator {

public static void main(String[] args) {
// rtsp的摄像头地址
URI uri = URI.create("rtsp://192.168.3.1:554/h264/ch1/main/av_stream");
// 身份认证
UsernamePasswordCredential credential = new UsernamePasswordCredential("admin", "123456");
DigestAuthenticator authenticator = new DigestAuthenticator(credential);
// 构建RTSP客户端对象
RtspClient client = new RtspClient(uri, authenticator);
// 设置RTSP交互过程信息打印,若不需要则可以不设置
client.onCommCallback(System.out::println);
// 设置接收的视频数据帧事件
client.onFrameHandle(x -> {
H264VideoFrame f = (H264VideoFrame) x;
System.out.println(f.getFrameType() + ", " + f.getNaluType() + ", " + f.getTimestamp() + ", " + f.getFrameSegment().length);
});
// 采用异步的形式关闭,由于是测试示例,写在启动前面
CompletableFuture.runAsync(() -> {
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
client.stop();
});
// 启动,返回异步执行对象
CompletableFuture<Void> future = client.start();
// 循环等待结束
while (!future.isDone()) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.github.xingshuangs.iot.protocol.rtsp.service;


import com.github.xingshuangs.iot.protocol.rtp.model.frame.H264VideoFrame;

import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
* @author xingshuang
*/
public class DemoRtspTcpNoAuthenticator {

public static void main(String[] args) {
// rtsp的地址
URI uri = URI.create("rtsp://127.0.0.1:8554/11");
// 构建RTSP客户端对象
RtspClient client = new RtspClient(uri);
// 设置RTSP交互过程信息打印,若不需要则可以不设置
client.onCommCallback(System.out::println);
// 设置接收的视频数据帧事件
client.onFrameHandle(x -> {
H264VideoFrame f = (H264VideoFrame) x;
System.out.println(f.getFrameType() + ", " + f.getNaluType() + ", " + f.getTimestamp() + ", " + f.getFrameSegment().length);
});
// 采用异步的形式关闭,由于是测试示例,写在启动前面
CompletableFuture.runAsync(() -> {
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
client.stop();
});
// 启动,返回异步执行对象
CompletableFuture<Void> future = client.start();
// 循环等待结束
while (!future.isDone()) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.github.xingshuangs.iot.protocol.rtsp.service;


import com.github.xingshuangs.iot.protocol.rtp.model.frame.H264VideoFrame;
import com.github.xingshuangs.iot.protocol.rtsp.authentication.DigestAuthenticator;
import com.github.xingshuangs.iot.protocol.rtsp.authentication.UsernamePasswordCredential;
import com.github.xingshuangs.iot.protocol.rtsp.enums.ERtspTransportProtocol;

import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
* @author xingshuang
*/
public class DemoRtspUdpAuthenticator {

public static void main(String[] args) {
// rtsp的摄像头地址
URI uri = URI.create("rtsp://192.168.3.1:554/h264/ch1/main/av_stream");
// 身份认证
UsernamePasswordCredential credential = new UsernamePasswordCredential("admin", "123456");
DigestAuthenticator authenticator = new DigestAuthenticator(credential);
// 构建RTSP客户端对象
RtspClient client = new RtspClient(uri, authenticator, ERtspTransportProtocol.UDP);
// 设置RTSP交互过程信息打印,若不需要则可以不设置
client.onCommCallback(System.out::println);
// 设置接收的视频数据帧事件
client.onFrameHandle(x -> {
H264VideoFrame f = (H264VideoFrame) x;
System.out.println(f.getFrameType() + ", " + f.getNaluType() + ", " + f.getTimestamp() + ", " + f.getFrameSegment().length);
});
// 采用异步的形式关闭,由于是测试示例,写在启动前面
CompletableFuture.runAsync(() -> {
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
client.stop();
});
// 启动,返回异步执行对象
CompletableFuture<Void> future = client.start();
// 循环等待结束
while (!future.isDone()) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public void connectTcp() {
client.onCommCallback(log::info);
client.onFrameHandle(x -> {
H264VideoFrame f = (H264VideoFrame) x;
// ByteReadBuff buff = ByteReadBuff.newInstance(f.getFrameSegment());
// byte[] bytes = f.getFrameSegment().length > 10 ? buff.getBytes(10) : buff.getBytes();
// log.debug(HexUtil.toHexString(bytes));
log.debug(f.getFrameType() + ", " + f.getNaluType() + ", " + f.getTimestamp() + ", " + f.getFrameSegment().length);
});
CompletableFuture.runAsync(() -> {
Expand Down Expand Up @@ -104,6 +101,5 @@ public void connectUdpWithoutAuthenticator() {
throw new RuntimeException(e);
}
}

}
}
Loading

0 comments on commit 8e725f6

Please sign in to comment.