Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Media] Ava sdk update #18359

Merged
merged 35 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cd6487b
added lva sdk package
hivyas Nov 17, 2020
9b01c04
Merge remote-tracking branch 'upstream/master'
hivyas Dec 11, 2020
9297d4f
updating ci file
hivyas Dec 11, 2020
40a1827
Merge remote-tracking branch 'upstream/master'
hivyas Dec 15, 2020
9e71cfe
Merge remote-tracking branch 'upstream/master'
hivyas Jan 6, 2021
dbeed32
Merge remote-tracking branch 'upstream/master'
hivyas Jan 8, 2021
e667530
fixing confict\
hivyas Mar 24, 2021
f102840
deleteing folder
hivyas Mar 24, 2021
d9d30e3
Merge remote-tracking branch 'upstream/master'
hivyas Mar 24, 2021
75e7827
regenerated and renamed to pipeline terminology
hivyas Mar 25, 2021
db5306e
changing package name
hivyas Apr 15, 2021
8c372e5
changed package name
hivyas Apr 16, 2021
bd53b5a
changing name
hivyas Apr 27, 2021
82e6962
Merge branch 'master' into lvaSdkUpdate
hivyas Apr 29, 2021
db59141
restoring old lva sdk
hivyas Apr 29, 2021
5edd22e
Merge branch 'lvaSdkUpdate' of https://github.com/hivyas/azure-sdk-fo…
hivyas Apr 29, 2021
96a47bb
restored old lva sdk autorest.md
hivyas Apr 29, 2021
e6a89f5
ignoring nspkg readme
hivyas Apr 29, 2021
6a85c74
removing nspkg from dev_requirements
hivyas Apr 29, 2021
dba64bc
rebasing
hivyas Apr 29, 2021
eeff79b
rebasing
hivyas Apr 29, 2021
200bc69
adding back deleted file
hivyas Apr 29, 2021
7dc0b69
corectin nspkg
hivyas Apr 29, 2021
d0c54e7
updating readme
hivyas May 7, 2021
ea6f2de
fixing broken link
hivyas May 7, 2021
d6ed32c
removing media-nspkg from ci file
hivyas May 7, 2021
952dc26
removing old terminology
hivyas May 11, 2021
73d6ac9
generated path is 3 parts
hivyas May 12, 2021
c8831a7
rebasing with master
hivyas May 13, 2021
b7c18bd
updating namespace name
hivyas May 13, 2021
62b94e8
reverting old sdk folder'
hivyas May 13, 2021
8c9dc34
removing video-nspkg
hivyas May 13, 2021
45fa708
fixing linting issue
hivyas May 13, 2021
f222b0d
addressing pr comments
hivyas May 13, 2021
6610202
pr comments
hivyas May 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sdk/videoanalyzer/azure-media-videoanalyzer-edge/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Release History

---

## 1.0.0b1 (2021-01-13)

Initial release
5 changes: 5 additions & 0 deletions sdk/videoanalyzer/azure-media-videoanalyzer-edge/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
recursive-include tests *.py
include *.md
include azure/__init__.py
include azure/media/__init__.py
recursive-include samples *.py *.md
155 changes: 155 additions & 0 deletions sdk/videoanalyzer/azure-media-videoanalyzer-edge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Azure Video Analyzer Edge for IoT Edge client library for Python

Azure Video Analyzer on IoT Edge provides a platform to build intelligent video applications that span the edge and the cloud. The platform offers the capability to capture, record, and analyze live video along with publishing the results, video and video analytics, to Azure services in the cloud or the edge. It is designed to be an extensible platform, enabling you to connect different video analysis edge modules (such as Cognitive services containers, custom edge modules built by you with open-source machine learning models or custom models trained with your own data) to it and use them to analyze live video without worrying about the complexity of building and running a live video pipeline.

Use the client library for Video Analyzer on IoT Edge to:

- Simplify interactions with the [Microsoft Azure IoT SDKs](https://github.com/azure/azure-iot-sdks)
- Programmatically construct pipeline topologies and live pipelines

[Package (PyPI)][package] | [Product documentation][doc_product] | [Direct methods][doc_direct_methods] | [Pipelines][doc_pipelines] | [Source code][source] | [Samples][samples]

## Getting started

### Install the package

Install the Video Analyzer client library for Python with pip:

```bash
pip install azure-media-videoanalyzer-edge
```

### Prerequisites

- Python 2.7, or 3.6 or later is required to use this package.
- You need an active [Azure subscription][azure_sub], and a [IoT device connection string][iot_device_connection_string] to use this package.
- To interact with Azure IoT Hub you will need to run `pip install azure-iot-hub`
- You will need to use the version of the SDK that corresponds to the version of the Video Analyzer Edge module you are using.

| SDK | Video Analyzer Edge Module |
|---|---|
| 1.0.0b1 | 2.0 |

### Creating a pipline topology and making requests

Please visit the [Examples](#examples) for starter code.

## Key concepts

### Pipeline Topology vs Live Pipeline Instance

A _pipeline topology_ is a blueprint or template for instantiating live pipelines. It defines the parameters of the pipeline using placeholders as values for them. A _live pipeline_ references a pipeline topology and specifies the parameters. This way you are able to have multiple live pipelines referencing the same topology but with different values for parameters. For more information please visit [pipeline topologies and live pipelines][doc_pipelines].

### CloudToDeviceMethod

The `CloudToDeviceMethod` is part of the [azure-iot-hub SDk][iot-hub-sdk]. This method allows you to communicate one way notifications to a device in your IoT hub. In our case, we want to communicate various direct methods such as `PipelineTopologySetRequest` and `PipelineTopologyGetRequest`. To use `CloudToDeviceMethod` you need to pass in two parameters: `method_name` and `payload`.

The first parameter, `method_name`, is the name of the direct method request you are sending. Make sure to use each method's predefined `method_name` property. For example, `PipelineTopologySetRequest.method_name`.

The second parameter, `payload`, sends the entire serialization of the pipeline topology request. For example, `PipelineTopologySetRequest.serialize()`

## Examples

### Creating a pipeline topology

To create a pipeline topology you need to define parameters, sources, and sinks.

```python
#Parameters
user_name_param = ParameterDeclaration(name="rtspUserName",type="String",default="dummyusername")
password_param = ParameterDeclaration(name="rtspPassword",type="SecretString",default="dummypassword")
url_param = ParameterDeclaration(name="rtspUrl",type="String",default="rtsp://www.sample.com")
hub_param = ParameterDeclaration(name="hubSinkOutputName",type="String")

#Source and Sink
source = RtspSource(name="rtspSource", endpoint=UnsecuredEndpoint(url="${rtspUrl}",credentials=UsernamePasswordCredentials(username="${rtspUserName}",password="${rtspPassword}")))
node = NodeInput(node_name="rtspSource")
sink = IotHubMessageSink("msgSink", nodeInput, "${hubSinkOutputName}")

pipeline_topology_properties = PipelineTopologyProperties()
pipeline_topology_properties.parameters = [user_name_param, password_param, url_param, hub_param]
pipeline_topology_properties.sources = [source]
pipeline_topology_properties.sinks = [sink]
pipeline_topology = PipelineTopology(name=pipeline_topology_name,properties=pipeline_topology_properties)

```

### Creating a live pipeline

To create a live pipeline, you need to have an existing pipeline topology.

```python
url_param = ParameterDefinition(name="rtspUrl", value=pipeline_url)
pass_param = ParameterDefinition(name="rtspPassword", value='testpass')
live_pipeline_properties = LivePipelineProperties(description="Sample pipeline description", topology_name=pipeline_topology_name, parameters=[url_param])

live_pipeline = LivePipeline(name=live_pipeline_name, properties=live_pipeline_properties)

```

### Invoking a pipeline topology method request

To invoke a pipeline topology method on your device you need to first define the request using the Video Analyzer SDK, then send that method request using the IoT SDK's `CloudToDeviceMethod`.

```python
set_method_request = PipelineTopologySetRequest(pipeline_topology=pipeline_topology)
direct_method = CloudToDeviceMethod(method_name=set_method_request.method_name, payload=set_method_request.serialize())
registry_manager = IoTHubRegistryManager(connection_string)

registry_manager.invoke_device_module_method(device_id, module_d, direct_method)
```

To try different pipeline topologies with the SDK, please see the official [Samples][samples].

## Troubleshooting

- When sending a method request using the IoT Hub's `CloudToDeviceMethod` remember to not type in the method request name directly. Instead use `[MethodRequestName.method_name]`
- Make sure to serialize the entire method request before passing it to `CloudToDeviceMethod`

## Next steps

- [Samples][samples]
- [Azure IoT Device SDK][iot-device-sdk]
- [Azure IoTHub Service SDK][iot-hub-sdk]

## Contributing

This project welcomes contributions and suggestions. Most contributions require
you to agree to a Contributor License Agreement (CLA) declaring that you have
the right to, and actually do, grant us the rights to use your contribution.
For details, visit https://cla.microsoft.com.

If you encounter any issues, please open an issue on our [Github][github-page-issues].

When you submit a pull request, a CLA-bot will automatically determine whether
you need to provide a CLA and decorate the PR appropriately (e.g., label,
comment). Simply follow the instructions provided by the bot. You will only
need to do this once across all repos using our CLA.

This project has adopted the
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
see the Code of Conduct FAQ or contact [email protected] with any
additional questions or comments.

<!-- LINKS -->
[azure_cli]: https://docs.microsoft.com/cli/azure
[azure_sub]: https://azure.microsoft.com/free/

[cla]: https://cla.microsoft.com
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[coc_contact]: mailto:[email protected]

[package]: TODO://link-to-published-package
[source]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/videoanalyzer
[samples]: https://github.com/Azure-Samples/live-video-analytics-iot-edge-python

[doc_direct_methods]: TODO://link
[doc_pipelines]: TODO://link
[doc_product]: TODO://link

[iot-device-sdk]: https://pypi.org/project/azure-iot-device/
[iot-hub-sdk]: https://pypi.org/project/azure-iot-hub/
[iot_device_connection_string]: TODO://link

[github-page-issues]: https://github.com/Azure/azure-sdk-for-python/issues
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------

__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------
from ._generated.models import *
from ._generated import models
from ._version import VERSION

__version__ = VERSION
__all__ = models.__all__

def _OverrideTopologySetRequestSerialize(self):
topology_body = PipelineTopologySetRequestBody(name=self.pipeline_topology.name)
topology_body.system_data = self.pipeline_topology.system_data
topology_body.properties = self.pipeline_topology.properties

return topology_body.serialize()

PipelineTopologySetRequest.serialize = _OverrideTopologySetRequestSerialize

def _OverrideInstanceSetRequestSerialize(self):
live_pipeline_body = LivePipelineSetRequestBody(name=self.live_pipeline.name)
live_pipeline_body.system_data = self.live_pipeline.system_data
live_pipeline_body.properties = self.live_pipeline.properties

return live_pipeline_body.serialize()

LivePipelineSetRequest.serialize = _OverrideInstanceSetRequestSerialize
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

VERSION = "1.0"
Loading