-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: 1# added RTSP related tutorials (添加RTSP相关教程); 2# upgrade to v1.…
…4.0 (版本升级到v1.4.0);
- Loading branch information
1 parent
8a5edec
commit 8e725f6
Showing
13 changed files
with
1,007 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/test/java/com/github/xingshuangs/iot/protocol/rtsp/service/DemoRtspFMp4ProxyTcpSync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...test/java/com/github/xingshuangs/iot/protocol/rtsp/service/DemoRtspFMp4ProxyUdpAsync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/com/github/xingshuangs/iot/protocol/rtsp/service/DemoRtspTcpAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...est/java/com/github/xingshuangs/iot/protocol/rtsp/service/DemoRtspTcpNoAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/test/java/com/github/xingshuangs/iot/protocol/rtsp/service/DemoRtspUdpAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.