From 02bffc2c52c78f5f634cb926589ef2efeac5591c Mon Sep 17 00:00:00 2001
From: wanggang <76527413@qq.com>
Date: Thu, 15 Apr 2021 10:57:52 +0800
Subject: [PATCH] 2.0
Former-commit-id: 7ba33121043ff12377f6445ccf1cd0e1da0f8301
Former-commit-id: 3d0e13a1678d38114437306f38eb22a426881489
---
projects/Infrastructure/Infrastructure.csproj | 22 ++++----
.../IoT.Shared/Application/Models/DataKeys.cs | 7 ++-
projects/IoT.Shared/IoT.Shared.csproj | 4 +-
.../Onvif/Controllers/OnvifController.cs | 9 ++++
.../DeviceServices/Onvif/OnvifService.cs | 54 ++++++++++++++-----
projects/IoTNode/IoTNode.csproj | 2 +-
projects/WebMVC/WebMVC.csproj | 2 +-
projects/WebSPA/WebSPA.csproj | 2 +-
.../publish/conf/srs/conf/srs.dev.conf | 52 +++++++++---------
9 files changed, 99 insertions(+), 55 deletions(-)
diff --git a/projects/Infrastructure/Infrastructure.csproj b/projects/Infrastructure/Infrastructure.csproj
index 794aae79..672d2b96 100644
--- a/projects/Infrastructure/Infrastructure.csproj
+++ b/projects/Infrastructure/Infrastructure.csproj
@@ -10,17 +10,17 @@
-
+
-
-
-
+
+
+
-
-
+
+
-
-
+
+
@@ -36,14 +36,14 @@
-
-
+
+
-
+
diff --git a/projects/IoT.Shared/Application/Models/DataKeys.cs b/projects/IoT.Shared/Application/Models/DataKeys.cs
index 555c8832..032746e1 100644
--- a/projects/IoT.Shared/Application/Models/DataKeys.cs
+++ b/projects/IoT.Shared/Application/Models/DataKeys.cs
@@ -116,10 +116,13 @@ namespace IoT.Shared.Application.Models
[IoTDataConfig(IoTDataType.Info ,hide: true)]
[Display(Name = "设备地址")]
DeviceUrl,
- [Display(Name = "Profiles")]
[IoTDataConfig(IoTDataType.Info, hide: true)]
+ [Display(Name = "媒体地址")]
+ MediaUrl,
+ [Display(Name = "Profiles")]
+ [IoTDataConfig(IoTDataType.Info,valueType:IoTValueType.Object)]
Profiles,
- [IoTDataConfig(IoTDataType.Info, hide: true)]
+ [IoTDataConfig(IoTDataType.Data)]
[Display(Name = "ProfileToken")]
ProfileToken,
[IoTDataConfig(IoTDataType.Info, hide: true)]
diff --git a/projects/IoT.Shared/IoT.Shared.csproj b/projects/IoT.Shared/IoT.Shared.csproj
index e4ae5f1b..364b2228 100644
--- a/projects/IoT.Shared/IoT.Shared.csproj
+++ b/projects/IoT.Shared/IoT.Shared.csproj
@@ -6,9 +6,7 @@
1.1.0.0
-
-
-
+
diff --git a/projects/IoTNode/DeviceServices/Onvif/Controllers/OnvifController.cs b/projects/IoTNode/DeviceServices/Onvif/Controllers/OnvifController.cs
index 19ffce29..687b60fb 100644
--- a/projects/IoTNode/DeviceServices/Onvif/Controllers/OnvifController.cs
+++ b/projects/IoTNode/DeviceServices/Onvif/Controllers/OnvifController.cs
@@ -113,6 +113,15 @@ namespace IoTNode.Controllers
});
}
+ [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("切换")]
+ public ApiResponse ChangeToken([SwaggerParameter("设备编号"), Required] string number, [SwaggerParameter("ProfileToken"), Required] string token)
+ {
+ return this.AsyncAction(() =>
+ {
+ this._deviceService.ChangeToken(number, token);
+ });
+ }
+
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("开始录制")]
public ApiResponse StartRecord([SwaggerParameter("设备编号"), Required] string number)
{
diff --git a/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs b/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs
index 95af0d68..452217b3 100644
--- a/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs
+++ b/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs
@@ -150,7 +150,7 @@ namespace IoTNode.DeviceServices.Onvif
}
deviceRepo.SaveChanges();
this.UpdateIoTData(device.Id, DataKeys.DeviceUrl, ipCamera.DeviceUrl);
- this.UpdateIoTData(device.Id, DataKeys.DeviceUrl, ipCamera.DeviceUrl);
+ this.UpdateIoTData(device.Id, DataKeys.MediaUrl, ipCamera.MediaUrl);
this.UpdateIoTData(device.Id, DataKeys.PtzAddress, ipCamera.PTZAddress);
this.UpdateIoTData(device.Id, DataKeys.Ptz3DZoomSupport, ipCamera.Ptz3DZoomSupport ? "1" : "0");
@@ -190,19 +190,12 @@ namespace IoTNode.DeviceServices.Onvif
{
if (ipCamera.Profiles.Count > 0)
{
- var tokens = ipCamera.Profiles.Select(o => $"{o.Token}:{o.Width}x{o.Height}").ToList();
- this.UpdateIoTData(device.Id, DataKeys.Profiles, string.Join(',', tokens));
+ var tokens = ipCamera.Profiles.ToJson();
+ this.UpdateIoTData(device.Id, DataKeys.Profiles, tokens);
var token = this.GetIoTDataValue(device.Id, DataKeys.ProfileToken);
- if (string.IsNullOrEmpty(token))
- {
- token = ipCamera.Profiles.First().Token;
- }
- else
+ if (string.IsNullOrEmpty(token)|| !ipCamera.Profiles.Any(o => o.Token == token))
{
- if (!ipCamera.Profiles.Any(o => o.Token == token))
- {
- token = ipCamera.Profiles.First().Token;
- }
+ token = (ipCamera.Profiles.FirstOrDefault(o=>o.Width==1280)??ipCamera.Profiles.First()).Token;
}
if (needAuth)
{
@@ -524,6 +517,43 @@ namespace IoTNode.DeviceServices.Onvif
return result;
}
+ public void ChangeToken(string id,string token)
+ {
+ var device = this.GetIoTDevice(id);
+ if (device != null)
+ {
+ using var scope = _applicationServices.CreateScope();
+ var repo = scope.ServiceProvider.GetRequiredService>();
+ var profiles = this.GetIoTDataValue(device.Id,DataKeys.Profiles);
+ if (!string.IsNullOrEmpty(profiles))
+ {
+ var tokens = profiles.FromJson>();
+ if(tokens.Any(o=>o.Token==token))
+ {
+ var currentToken = this.GetIoTDataValue(device.Id, DataKeys.ProfileToken);
+ if (!string.IsNullOrEmpty(currentToken) && currentToken != token)
+ {
+ this.UpdateIoTData(device.Id, DataKeys.ProfileToken, token);
+ var deviceUrl = this.GetIoTDataValue(device.Id, DataKeys.DeviceUrl);
+ var mediaUrl = this.GetIoTDataValue(device.Id, DataKeys.MediaUrl);
+ if (!string.IsNullOrEmpty(deviceUrl) && !string.IsNullOrEmpty(mediaUrl))
+ {
+ var streamUriXml = this._onvifDeviceManagement.GetStreamUri(deviceUrl, mediaUrl, device.UserName, device.Password, token);
+ var snapshotUri = this._onvifDeviceManagement.GetSnapshotUri(deviceUrl, mediaUrl, device.UserName, device.Password, token);
+ var ipCamera = new IPCamera { StreamUriXml = streamUriXml, SnapshotUriXml = snapshotUri };
+ ipCamera.ParseStreamUri();
+ ipCamera.ParseSnapshotUri();
+ this.UpdateIoTData(device.Id, DataKeys.StreamUri, ipCamera.StreamUri);
+ this.UpdateIoTData(device.Id, DataKeys.SnapshotUri, ipCamera.SnapshotUri);
+ this.SetPush(device.Number, false);
+ this.SetPush(device.Number, true);
+ }
+ }
+ }
+ }
+ }
+ }
+
public void ZoomIn(string id, float speed)
{
this.Move(id, speed, 0, 0);
diff --git a/projects/IoTNode/IoTNode.csproj b/projects/IoTNode/IoTNode.csproj
index 2560dd43..a135fb2e 100644
--- a/projects/IoTNode/IoTNode.csproj
+++ b/projects/IoTNode/IoTNode.csproj
@@ -7,7 +7,7 @@
1.1.1.1
-
+
diff --git a/projects/WebMVC/WebMVC.csproj b/projects/WebMVC/WebMVC.csproj
index 95796451..70603134 100644
--- a/projects/WebMVC/WebMVC.csproj
+++ b/projects/WebMVC/WebMVC.csproj
@@ -13,6 +13,6 @@
-
+
\ No newline at end of file
diff --git a/projects/WebSPA/WebSPA.csproj b/projects/WebSPA/WebSPA.csproj
index dcf5f298..a62cc621 100644
--- a/projects/WebSPA/WebSPA.csproj
+++ b/projects/WebSPA/WebSPA.csproj
@@ -6,6 +6,6 @@
-
+
\ No newline at end of file
diff --git a/publish/src/linux-x64/publish/conf/srs/conf/srs.dev.conf b/publish/src/linux-x64/publish/conf/srs/conf/srs.dev.conf
index e55f73ef..dbda3adf 100644
--- a/publish/src/linux-x64/publish/conf/srs/conf/srs.dev.conf
+++ b/publish/src/linux-x64/publish/conf/srs/conf/srs.dev.conf
@@ -22,9 +22,9 @@ stats {
network 0;
disk sda sdb xvda xvdb;
}
-rtc_server {
- enabled on;
- listen 8000;
+rtc_server{
+ enabled on;
+ listen 8000;
candidate *;
}
vhost __defaultVhost__ {
@@ -32,11 +32,12 @@ vhost __defaultVhost__ {
enabled on;
bframe discard;
}
- tcp_nodelay on min_latency on;
+ tcp_nodelay on
+ min_latency on;
play {
- gop_cache off;
- queue_length 10;
- mw_latency 100;
+ gop_cache off;
+ queue_length 10;
+ mw_latency 100;
}
publish {
mr off;
@@ -59,23 +60,26 @@ vhost __defaultVhost__ {
output ./objs/nginx/html/[app]/[stream].png;
}
engine ff {
- enabled off;
- vfilter;
- vcodec libx264;
- vbitrate 500;
- vfps 25;
- vwidth 768;
- vheight 320;
- vthreads 12;
- vprofile main;
- vpreset medium;
- vparams;
- acodec libfdk_aac;
- abitrate 70;
- asample_rate 44100;
- achannels 2;
- aparams;
- output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
+ enabled off;
+ vfilter {
+ }
+ vcodec libx264;
+ vbitrate 500;
+ vfps 25;
+ vwidth 768;
+ vheight 320;
+ vthreads 12;
+ vprofile main;
+ vpreset medium;
+ vparams {
+ }
+ acodec libfdk_aac;
+ abitrate 70;
+ asample_rate 44100;
+ achannels 2;
+ aparams {
+ }
+ output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
}
}
http_remux {