Skip to content

Commit dbcfa92

Browse files
authored
Update PTZ sample (#149)
## Purpose Update the ONVIF PTZ sample ## Does this introduce a breaking change? <!-- Mark one with an "x". --> ``` [ ] Yes [x] No ``` ## Pull Request Type What kind of change does this Pull Request introduce? <!-- Please check the one that applies to this PR using "x". --> ``` [ ] Bugfix [ ] Feature [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [x] Documentation content changes [x] Other...Sample ```
1 parent ea10e01 commit dbcfa92

File tree

578 files changed

+18892
-3562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

578 files changed

+18892
-3562
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<ItemGroup>
4-
<PackageReference Include="Azure.Iot.Operations.Mqtt" Version="0.9.*-*" />
5-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
4+
<PackageReference Include="Azure.Iot.Operations.Mqtt" Version="0.10.*-*" />
5+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta6.25358.103" />
66
</ItemGroup>
77

88
<ItemGroup>
@@ -12,10 +12,10 @@
1212

1313
<PropertyGroup>
1414
<OutputType>Exe</OutputType>
15-
<TargetFramework>net8.0</TargetFramework>
15+
<TargetFramework>net9.0</TargetFramework>
1616
<RootNamespace>Aio.Onvif.Connector.Ptz.Demo</RootNamespace>
1717
<ImplicitUsings>enable</ImplicitUsings>
1818
<Nullable>enable</Nullable>
1919
</PropertyGroup>
2020

21-
</Project>
21+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.2.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aio.Onvif.Connector.Ptz.Demo", "Aio.Onvif.Connector.Ptz.Demo.csproj", "{E3A56ECF-3EA4-F37C-EA48-CFCA3F94B8B5}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{E3A56ECF-3EA4-F37C-EA48-CFCA3F94B8B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{E3A56ECF-3EA4-F37C-EA48-CFCA3F94B8B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{E3A56ECF-3EA4-F37C-EA48-CFCA3F94B8B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{E3A56ECF-3EA4-F37C-EA48-CFCA3F94B8B5}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {F0EC5109-882E-4B80-8D57-05FDE5DB1B91}
23+
EndGlobalSection
24+
EndGlobal

samples/aio-onvif-connector-ptz-demo/Aio.Onvif.Connector.Ptz.Demo/OnvifMediaClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Aio.Onvif.Connector.Ptz.Demo;
66

77
public class OnvifMediaClient : Client
88
{
9-
public OnvifMediaClient(ApplicationContext applicationContext, IMqttPubSubClient mqttClient) : base(applicationContext, mqttClient)
9+
public OnvifMediaClient(ApplicationContext applicationContext, IMqttPubSubClient mqttClient, Dictionary<string, string> topicTokenMap) : base(applicationContext, mqttClient, topicTokenMap)
1010
{
1111
}
1212
}

samples/aio-onvif-connector-ptz-demo/Aio.Onvif.Connector.Ptz.Demo/OnvifPtzClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Aio.Onvif.Connector.Ptz.Demo;
77

88
public class OnvifPtzClient : Client
99
{
10-
public OnvifPtzClient(ApplicationContext applicationContext, IMqttPubSubClient mqttClient) : base(applicationContext, mqttClient)
10+
public OnvifPtzClient(ApplicationContext applicationContext, IMqttPubSubClient mqttClient, Dictionary<string, string> topicTokenMap) : base(applicationContext, mqttClient, topicTokenMap)
1111
{
1212
}
1313
}

samples/aio-onvif-connector-ptz-demo/Aio.Onvif.Connector.Ptz.Demo/Program.cs

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,33 @@
66
using MediaClient.Media;
77
using PtzClient.Ptz;
88

9-
var hostOption = new Option<string>(["--mqtt-host", "-h"], description: "The Hostname or IP of the MQTT Listener the demo connects to", getDefaultValue: () => "localhost");
10-
var portOption = new Option<int>(["--mqtt-port", "-p"], description: "The port of the MQTT Listener the demo connects to", getDefaultValue: () => 1883);
11-
var namespaceOption = new Option<string>(["--namespace", "-n"], description: "The Kubernetes namespace AIO is deployed to", getDefaultValue: () => "azure-iot-operations");
12-
var ptzAssetOption = new Option<string>(["--ptz-asset", "-pa"], description: "The name of the PTZ asset") { IsRequired = true };
13-
var mediaAssetOption = new Option<string>(["--media-asset", "-ma"], description: "The name of the media asset") { IsRequired = true };
14-
var modeOption = new Option<string>(["--mode", "-m"], description: "The method that should be used to move the camera", getDefaultValue: () => "relative").FromAmong("relative", "continuous");
15-
16-
var rootCommand = new RootCommand("AIO ONVIF Connector Demo");
17-
rootCommand.AddOption(hostOption);
18-
rootCommand.AddOption(portOption);
19-
rootCommand.AddOption(namespaceOption);
20-
rootCommand.AddOption(ptzAssetOption);
21-
rootCommand.AddOption(mediaAssetOption);
22-
rootCommand.AddOption(modeOption);
23-
24-
rootCommand.SetHandler(async (host, port, @namespace, ptzAsset, mediaAsset, mode) =>
9+
var hostOption = new Option<string>("--mqtt-host", "-h") { Description = "The Hostname or IP of the MQTT Listener the demo connects to", DefaultValueFactory = _ => "localhost" };
10+
var portOption = new Option<int>("--mqtt-port", "-p") { Description = "The port of the MQTT Listener the demo connects to", DefaultValueFactory = _ => 1883 };
11+
var namespaceOption = new Option<string>("--namespace", "-n") { Description = "The Kubernetes namespace AIO is deployed to", DefaultValueFactory = _ => "azure-iot-operations" };
12+
var assetOption = new Option<string>("--asset", "-a") { Description = "The name of the asset", Required = true };
13+
var modeOption = new Option<string>("--mode", "-m") { Description = "The method that should be used to move the camera", DefaultValueFactory = _ => "relative", }.AcceptOnlyFromAmong("relative", "continuous");
14+
15+
var rootCommand = new RootCommand("AIO ONVIF Connector Demo")
16+
{
17+
hostOption,
18+
portOption,
19+
namespaceOption,
20+
assetOption,
21+
modeOption
22+
};
23+
24+
rootCommand.SetAction(async parseResult =>
2525
{
26+
var host = parseResult.GetValue(hostOption) ?? throw new ArgumentNullException(nameof(hostOption), "MQTT host cannot be null");
27+
var port = parseResult.GetValue(portOption);
28+
var @namespace = parseResult.GetValue(namespaceOption) ?? throw new ArgumentNullException(nameof(namespaceOption), "Namespace cannot be null");
29+
var asset = parseResult.GetValue(assetOption) ?? throw new ArgumentNullException(nameof(assetOption), "Asset cannot be null");
30+
var mode = parseResult.GetValue(modeOption) ?? throw new ArgumentNullException(nameof(modeOption), "Mode cannot be null");
31+
2632
Console.WriteLine($"MQTT Host: {host}");
2733
Console.WriteLine($"MQTT Port: {port}");
2834
Console.WriteLine($"Namespace: {@namespace}");
29-
Console.WriteLine($"PTZ Asset: {ptzAsset}");
30-
Console.WriteLine($"Media Asset: {mediaAsset}");
35+
Console.WriteLine($"Asset: {asset}");
3136
Console.WriteLine($"Mode: {mode}");
3237

3338
var mqttClientTcpOptions = new MqttClientTcpOptions(host, port);
@@ -37,31 +42,35 @@
3742
var mqttSessionClient = new MqttSessionClient(new MqttSessionClientOptions());
3843
await mqttSessionClient.ConnectAsync(mqttClientOptions);
3944
var applicationContext = new ApplicationContext();
40-
var ptzClient = new OnvifPtzClient(applicationContext, mqttSessionClient);
41-
var mediaClient = new OnvifMediaClient(applicationContext, mqttSessionClient);
42-
43-
var profiles = await mediaClient.GetProfilesAsync(new Dictionary<string, string>
45+
var ptzClient = new OnvifPtzClient(applicationContext, mqttSessionClient, new Dictionary<string, string>
46+
{
47+
{ "namespace", @namespace },
48+
{ "asset", asset }
49+
});
50+
var mediaClient = new OnvifMediaClient(applicationContext, mqttSessionClient, new Dictionary<string, string>
4451
{
45-
{ "ex:namespace", @namespace },
46-
{ "ex:asset", mediaAsset }
52+
{ "namespace", @namespace },
53+
{ "asset", asset }
4754
});
48-
var profile = profiles.GetProfilesCommandResponse.Profiles.First();
55+
56+
var profiles = await mediaClient.GetProfilesAsync();
57+
var profile = profiles.Result.Profiles.First();
4958

5059
Console.WriteLine("Use arrow keys or WASD to move camera, Q to quit");
5160

5261
if (mode == "relative")
5362
{
54-
await StartRelativeMoveAsync(ptzClient, profile, @namespace, ptzAsset);
63+
await StartRelativeMoveAsync(ptzClient, profile, @namespace, asset);
5564
}
5665
else if (mode == "continuous")
5766
{
58-
await StartContinuousMoveAsync(ptzClient, profile, @namespace, ptzAsset);
67+
await StartContinuousMoveAsync(ptzClient, profile, @namespace, asset);
5968
}
6069

61-
await StartRelativeMoveAsync(ptzClient, profile, @namespace, ptzAsset);
62-
}, hostOption, portOption, namespaceOption, ptzAssetOption, mediaAssetOption, modeOption);
70+
await StartRelativeMoveAsync(ptzClient, profile, @namespace, asset);
71+
});
6372

64-
await rootCommand.InvokeAsync(args);
73+
await new CommandLineConfiguration(rootCommand).InvokeAsync(args);
6574

6675
async Task StartRelativeMoveAsync(OnvifPtzClient ptzClient, Profile profile, string @namespace, string ptzAssetName)
6776
{
@@ -109,11 +118,7 @@ async Task StartRelativeMoveAsync(OnvifPtzClient ptzClient, Profile profile, str
109118
}
110119
};
111120

112-
await ptzClient.RelativeMoveAsync(request, new Dictionary<string, string>
113-
{
114-
{ "ex:namespace", @namespace },
115-
{ "ex:asset", ptzAssetName }
116-
});
121+
await ptzClient.RelativeMoveAsync(request);
117122
}
118123
catch (Exception e)
119124
{
@@ -171,17 +176,9 @@ async Task StartContinuousMoveAsync(OnvifPtzClient ptzClient, Profile profile, s
171176
}
172177
};
173178

174-
await ptzClient.ContinuousMoveAsync(request, new Dictionary<string, string>
175-
{
176-
{ "ex:namespace", @namespace },
177-
{ "ex:asset", ptzAssetName }
178-
});
179+
await ptzClient.ContinuousMoveAsync(request);
179180
await Task.Delay(1000).ConfigureAwait(true);
180-
await ptzClient.StopAsync(new StopRequestPayload { Stop = new Stop { ProfileToken = profile.Token, PanTilt = true } }, new Dictionary<string, string>
181-
{
182-
{ "ex:namespace", @namespace },
183-
{ "ex:asset", ptzAssetName }
184-
});
181+
await ptzClient.StopAsync(new StopRequestPayload { Stop = new Stop { ProfileToken = profile.Token, PanTilt = true } });
185182
}
186183
catch (Exception e)
187184
{

samples/aio-onvif-connector-ptz-demo/MediaClient/BytesJsonConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
/* Code generated by Azure.Iot.Operations.ProtocolCompiler v0.9.0.0; DO NOT EDIT. */
4+
/* Code generated by Azure.Iot.Operations.ProtocolCompiler v0.10.0.0; DO NOT EDIT. */
55

66
namespace MediaClient
77
{
@@ -17,7 +17,7 @@ internal sealed class BytesJsonConverter : JsonConverter<byte[]>
1717
/// <inheritdoc/>
1818
public override byte[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
1919
{
20-
return Convert.FromBase64String(reader.GetString()!);
20+
return Convert.FromBase64String(reader.GetString() !);
2121
}
2222

2323
/// <inheritdoc/>

samples/aio-onvif-connector-ptz-demo/MediaClient/CombinedPrefixedReadOnlyDictionary.cs

Lines changed: 0 additions & 111 deletions
This file was deleted.

samples/aio-onvif-connector-ptz-demo/MediaClient/DateJsonConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
/* Code generated by Azure.Iot.Operations.ProtocolCompiler v0.9.0.0; DO NOT EDIT. */
4+
/* Code generated by Azure.Iot.Operations.ProtocolCompiler v0.10.0.0; DO NOT EDIT. */
55

66
namespace MediaClient
77
{
@@ -18,7 +18,7 @@ internal sealed class DateJsonConverter : JsonConverter<DateOnly>
1818
/// <inheritdoc/>
1919
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
2020
{
21-
return DateOnly.Parse(reader.GetString()!, CultureInfo.InvariantCulture);
21+
return DateOnly.Parse(reader.GetString() !, CultureInfo.InvariantCulture);
2222
}
2323

2424
/// <inheritdoc/>

samples/aio-onvif-connector-ptz-demo/MediaClient/DecimalJsonConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
/* Code generated by Azure.Iot.Operations.ProtocolCompiler v0.9.0.0; DO NOT EDIT. */
4+
/* Code generated by Azure.Iot.Operations.ProtocolCompiler v0.10.0.0; DO NOT EDIT. */
55

66
namespace MediaClient
77
{
@@ -18,7 +18,7 @@ internal sealed class DecimalJsonConverter : JsonConverter<DecimalString>
1818
/// <inheritdoc/>
1919
public override DecimalString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
2020
{
21-
return new DecimalString(reader.GetString()!);
21+
return new DecimalString(reader.GetString() !);
2222
}
2323

2424
/// <inheritdoc/>

0 commit comments

Comments
 (0)