快速入门:入门 - IoT Edge 上的实时视频分析Quickstart: Get started - Live Video Analytics on IoT Edge

本快速入门将引导你完成开始使用 IoT Edge 上的实时视频分析的步骤。This quickstart walks you through the steps to get started with Live Video Analytics on IoT Edge. 它将 Azure VM 用作 IoT Edge 设备。It uses an Azure VM as an IoT Edge device. 它还使用模拟的实时视频流。It also uses a simulated live video stream.

完成设置步骤后,你将能通过媒体图运行模拟实时视频流,该媒体图可检测和报告该流中的任何运动。After completing the setup steps, you'll be able to run a simulated live video stream through a media graph that detects and reports any motion in that stream. 下图显示了该媒体图的图形表示形式。The following diagram graphically represents that media graph.

基于运动检测的实时视频分析

先决条件Prerequisites

  • 具有活动订阅的 Azure 帐户。An Azure account that has an active subscription. 如果没有帐户,可以创建试用帐户Create an account for trial if you don't already have one.
  • 开发计算机上的 Visual Studio CodeVisual Studio Code on your development machine. 请确保具有 Azure IoT Tools 扩展Make sure you have the Azure IoT Tools extension.
  • 确保开发计算机连接到的网络允许经由端口 5671 的高级消息队列协议协议 (AMQP)。Make sure the network that your development machine is connected to permits Advanced Message Queueing Protocol (AMQP) over port 5671. 此设置使 Azure IoT Tools 可以与 Azure IoT 中心通信。This setup enables Azure IoT Tools to communicate with Azure IoT Hub.

提示

安装 Azure IoT Tools 扩展时,系统可能会提示你安装 Docker。You might be prompted to install Docker while you're installing the Azure IoT Tools extension. 可以忽略此提示。Feel free to ignore the prompt.

设置 Azure 资源Set up Azure resources

本教程需要以下 Azure 资源:This tutorial requires the following Azure resources:

  • IoT 中心IoT Hub
  • 存储帐户Storage account
  • Azure 媒体服务帐户Azure Media Services account
  • Azure 中的 Linux VM,已安装 IoT Edge 运行时A Linux VM in Azure, with IoT Edge runtime installed

在本快速入门中,我们建议你使用实时视频分析资源设置脚本在 Azure 订阅中部署所需资源。For this quickstart, we recommend that you use the Live Video Analytics resources setup script to deploy the required resources in your Azure subscription. 为此,请执行下列步骤:To do so, follow these steps:

  1. 运行以下 Bash 命令。Run the following Bash command.

    bash -c "$(curl -sL https://aka.ms/lva-edge/setup-resources-for-samples)"
    

如果脚本成功完成,你应该可在订阅中看到所有所需资源。If the script finishes successfully, you should see all of the required resources in your subscription. 在脚本输出中,资源表会列出 IoT 中心名称。In the script output, a table of resources lists the IoT hub name. 查找资源类型 Microsoft.Devices/IotHubs,并记下名称。Look for the resource type Microsoft.Devices/IotHubs, and note down the name. 下一步骤需要用到此名称。You'll need this name in the next step.

该脚本也会生成一些配置文件。The script also generates a few configuration files. 稍后在快速入门中需要用到这些文件。You'll need these files later in the quickstart.

在边缘设备上部署模块Deploy modules on your edge device

运行以下命令。Run the following command.

az iot edge set-modules --hub-name <iot-hub-name> --device-id lva-sample-device --content edge-deployment/deployment.amd64.json

此命令会将以下模块部署到边缘设备(在此例中为 Linux VM)。This command deploys the following modules to the edge device, which is the Linux VM in this case.

  • IoT Edge 上的实时视频分析(模块名称为 lvaEdgeLive Video Analytics on IoT Edge (module name lvaEdge)
  • 实时流式处理协议 (RTSP) 模拟器(模块名称为 rtspsimReal-Time Streaming Protocol (RTSP) simulator (module name rtspsim)

RTSP 模拟器模块使用视频文件模拟实时视频流,该文件已在运行实时视频分析资源设置脚本时复制到边缘设备。The RTSP simulator module simulates a live video stream by using a video file that was copied to your edge device when you ran the Live Video Analytics resources setup script.

现在已部署模块,但没有媒体图处于活动状态。Now the modules are deployed, but no media graphs are active.

配置 Azure IoT Tools 扩展Configure the Azure IoT Tools extension

按照以下说明使用 Azure IoT Tools 扩展连接到 IoT 中心。Follow these instructions to connect to your IoT hub by using the Azure IoT Tools extension.

  1. 在 Visual Studio Code 中选择“视图” > “资源管理器”。In Visual Studio Code, select View > Explorer. 或是选择 Ctrl+Shift+E。Or select Ctrl+Shift+E.
  2. 在“资源管理器”选项卡的左下角,选择“Azure IoT 中心”。In the lower-left corner of the Explorer tab, select Azure IoT Hub.
  3. 选择“更多选项”图标以查看上下文菜单。Select the More Options icon to see the context menu. 然后选择“设置 IoT 中心连接字符串”。Then select Set IoT Hub Connection String.
  4. 输入框出现时,在其中输入 IoT 中心连接字符串。When an input box appears, enter your IoT Hub connection string. 可以从 appsettings.json 中获取连接字符串。You can get the connection string from appsettings.json.

如果连接成功,边缘设备列表随即显示。If the connection succeeds, the list of edge devices appears. 应该会看到至少一个设备,名为 lva-sample-device。You should see at least one device named lva-sample-device. 现在你可以管理 IoT Edge 设备,并通过上下文菜单与 Azure IoT 中心进行交互。You can now manage your IoT Edge devices and interact with Azure IoT Hub through the context menu. 若有查看部署在边缘设备上的模块,请在“lva-sample-device”下,展开“模块”节点。To view the modules deployed on the edge device, under lva-sample-device, expand the Modules node.

lva-sample-device 节点

使用直接方法调用Use direct method calls

可以通过调用直接方法来使用该模块分析实时视频流。You can use the module to analyze live video streams by invoking direct methods. 有关详细信息,请参阅 IoT Edge上的实时视频分析的直接方法For more information, see Direct methods for Live Video Analytics on IoT Edge.

调用 GraphTopologyListInvoke GraphTopologyList

若有枚举模块中的所有图形拓扑To enumerate all of the graph topologies in the module:

  1. 在 Visual Studio Code 中,右键单击“lvaEdge”模块,然后选择“调用模块直接方法”。In the Visual Studio Code, right-click the lvaEdge module and select Invoke Module Direct Method.

  2. 在出现的框中,输入 GraphTopologyList。In the box that appears, enter GraphTopologyList.

  3. 复制以下 JSON 有效负载,然后粘贴到框中。Copy the following JSON payload and then paste it in the box. 然后选择 Enter 键。Then select the Enter key.

    {
        "@apiVersion" : "1.0"
    }
    

    几秒钟内,“输出”窗口会显示以下响应。Within a few seconds, the OUTPUT window shows the following response.

    [DirectMethod] Invoking Direct Method [GraphTopologyList] to [lva-sample-device/lvaEdge] ...
    [DirectMethod] Response from [lva-sample-device/lvaEdge]:
    {
      "status": 200,
      "payload": {
        "value": []
      }
    }
    

    由于没有创建图形拓扑,所以预期会出现此响应。This response is expected because no graph topologies have been created.

调用 GraphTopologySetInvoke GraphTopologySet

通过与调用 GraphTopologyList 相同的步骤,可以调用 GraphTopologySet 以设置图形拓扑By using the steps for invoking GraphTopologyList, you can invoke GraphTopologySet to set a graph topology. 使用以下 JSON 作为有效负载。Use the following JSON as the payload.

{
    "@apiVersion": "1.0",
    "name": "MotionDetection",
    "properties": {
        "description": "Analyzing live video to detect motion and emit events",
        "parameters": [
            {
                "name": "rtspUserName",
                "type": "String",
                "description": "rtsp source user name.",
                "default": "dummyUserName"
            },
            {
                "name": "rtspPassword",
                "type": "String",
                "description": "rtsp source password.",
                "default": "dummyPassword"
            },
            {
                "name": "rtspUrl",
                "type": "String",
                "description": "rtsp Url"
            }
        ],
        "sources": [
            {
                "@type": "#Microsoft.Media.MediaGraphRtspSource",
                "name": "rtspSource",
                "endpoint": {
                    "@type": "#Microsoft.Media.MediaGraphUnsecuredEndpoint",
                    "url": "${rtspUrl}",
                    "credentials": {
                        "@type": "#Microsoft.Media.MediaGraphUsernamePasswordCredentials",
                        "username": "${rtspUserName}",
                        "password": "${rtspPassword}"
                    }
                }
            }
        ],
        "processors": [
            {
                "@type": "#Microsoft.Media.MediaGraphMotionDetectionProcessor",
                "name": "motionDetection",
                "sensitivity": "medium",
                "inputs": [
                    {
                        "nodeName": "rtspSource"
                    }
                ]
            }
        ],
        "sinks": [
            {
                "@type": "#Microsoft.Media.MediaGraphIoTHubMessageSink",
                "name": "hubSink",
                "hubOutputName": "inferenceOutput",
                "inputs": [
                    {
                        "nodeName": "motionDetection"
                    }
                ]
            }
        ]
    }
}

此 JSON 有效负载创建定义三个参数的图形拓扑。This JSON payload creates a graph topology that defines three parameters. 其中两个参数具有默认值。Two of those parameters have default values. 拓扑具有一个源(RTSP 源)节点、一个处理器(运动检测处理器)节点和一个接收器(IoT 中心接收器)节点。The topology has one source (RTSP source) node, one processor (motion detection processor) node, and one sink (IoT Hub sink) node.

几秒钟内,“输出”窗口中显示以下响应。Within a few seconds, you see the following response in the OUTPUT window.

[DirectMethod] Invoking Direct Method [GraphTopologySet] to [lva-sample-device/lvaEdge] ...
[DirectMethod] Response from [lva-sample-device/lvaEdge]:
{
  "status": 201,
  "payload": {
    "systemData": {
      "createdAt": "2020-05-19T07:41:34.507Z",
      "lastModifiedAt": "2020-05-19T07:41:34.507Z"
    },
    "name": "MotionDetection",
    "properties": {
      "description": "Analyzing live video to detect motion and emit events",
      "parameters": [
        {
          "name": "rtspUserName",
          "type": "String",
          "description": "rtsp source user name.",
          "default": "dummyUserName"
        },
        {
          "name": "rtspPassword",
          "type": "String",
          "description": "rtsp source password.",
          "default": "dummyPassword"
        },
        {
          "name": "rtspUrl",
          "type": "String",
          "description": "rtsp Url"
        }
      ],
      "sources": [
        {
          "@type": "#Microsoft.Media.MediaGraphRtspSource",
          "name": "rtspSource",
          "transport": "Tcp",
          "endpoint": {
            "@type": "#Microsoft.Media.MediaGraphUnsecuredEndpoint",
            "url": "${rtspUrl}",
            "credentials": {
              "@type": "#Microsoft.Media.MediaGraphUsernamePasswordCredentials",
              "username": "${rtspUserName}"
            }
          }
        }
      ],
      "processors": [
        {
          "@type": "#Microsoft.Media.MediaGraphMotionDetectionProcessor",
          "sensitivity": "medium",
          "name": "motionDetection",
          "inputs": [
            {
              "nodeName": "rtspSource",
              "outputSelectors": []
            }
          ]
        }
      ],
      "sinks": [
        {
          "@type": "#Microsoft.Media.MediaGraphIoTHubMessageSink",
          "hubOutputName": "inferenceOutput",
          "name": "hubSink",
          "inputs": [
            {
              "nodeName": "motionDetection",
              "outputSelectors": []
            }
          ]
        }
      ]
    }
  }
}

返回的状态为 201。The returned status is 201. 此状态指示已创建了新拓扑。This status indicates that a new topology was created.

请尝试以下后续步骤:Try the following next steps:

  1. 再次调用 GraphTopologySetInvoke GraphTopologySet again. 返回的状态代码为 200。The returned status code is 200. 此代码指示已成功更新现有拓扑。This code indicates that an existing topology was successfully updated.
  2. 再次调用 GraphTopologySet,但更改描述字符串。Invoke GraphTopologySet again, but change the description string. 返回的状态代码为 200,且描述已更新为新值。The returned status code is 200, and the description is updated to the new value.
  3. 调用 GraphTopologyList,如前一部分所述。Invoke GraphTopologyList as outlined in the previous section. 现在,你可以在返回的有效负载中查看 MotionDetection 拓扑。Now you can see the MotionDetection topology in the returned payload.

调用 GraphTopologyGetInvoke GraphTopologyGet

使用以下有效负载调用 GraphTopologyGetInvoke GraphTopologyGet by using the following payload.

{
    "@apiVersion" : "1.0",
    "name" : "MotionDetection"
}

几秒钟内,“输出”窗口中显示以下响应:Within a few seconds, you see the following response in the OUTPUT window:

[DirectMethod] Invoking Direct Method [GraphTopologyGet] to [lva-sample-device/lvaEdge] ...
[DirectMethod] Response from [lva-sample-device/lvaEdge]:
{
  "status": 200,
  "payload": {
    "systemData": {
      "createdAt": "2020-05-19T07:41:34.507Z",
      "lastModifiedAt": "2020-05-19T07:41:34.507Z"
    },
    "name": "MotionDetection",
    "properties": {
      "description": "Analyzing live video to detect motion and emit events",
      "parameters": [
        {
          "name": "rtspUserName",
          "type": "String",
          "description": "rtsp source user name.",
          "default": "dummyUserName"
        },
        {
          "name": "rtspPassword",
          "type": "String",
          "description": "rtsp source password.",
          "default": "dummyPassword"
        },
        {
          "name": "rtspUrl",
          "type": "String",
          "description": "rtsp Url"
        }
      ],
      "sources": [
        {
          "@type": "#Microsoft.Media.MediaGraphRtspSource",
          "name": "rtspSource",
          "transport": "Tcp",
          "endpoint": {
            "@type": "#Microsoft.Media.MediaGraphUnsecuredEndpoint",
            "url": "${rtspUrl}",
            "credentials": {
              "@type": "#Microsoft.Media.MediaGraphUsernamePasswordCredentials",
              "username": "${rtspUserName}"
            }
          }
        }
      ],
      "processors": [
        {
          "@type": "#Microsoft.Media.MediaGraphMotionDetectionProcessor",
          "sensitivity": "medium",
          "name": "motionDetection",
          "inputs": [
            {
              "nodeName": "rtspSource",
              "outputSelectors": []
            }
          ]
        }
      ],
      "sinks": [
        {
          "@type": "#Microsoft.Media.MediaGraphIoTHubMessageSink",
          "hubOutputName": "inferenceOutput",
          "name": "hubSink",
          "inputs": [
            {
              "nodeName": "motionDetection",
              "outputSelectors": []
            }
          ]
        }
      ]
    }
  }
}

在响应有效负载中,请注意以下详细信息:In the response payload, notice these details:

  • 状态代码为 200,表示成功。The status code is 200, indicating success.
  • 有效负载包含 created 时间戳和 lastModified 时间戳。The payload includes the created time stamp and the lastModified time stamp.

调用 GraphInstanceSetInvoke GraphInstanceSet

创建引用上述图形拓扑的图形实例。Create a graph instance that references the preceding graph topology. 图形实例允许你使用相同图形拓扑分析来自许多照相机的实时视频流。Graph instances let you analyze live video streams from many cameras by using the same graph topology. 有关详细信息,请参阅媒体图拓扑和实例For more information, see Media graph topologies and instances.

使用以下有效负载调用直接方法 GraphInstanceSetInvoke the direct method GraphInstanceSet by using the following payload.

{
    "@apiVersion" : "1.0",
    "name" : "Sample-Graph-1",
    "properties" : {
        "topologyName" : "MotionDetection",
        "description" : "Sample graph description",
        "parameters" : [
            { "name" : "rtspUrl", "value" : "rtsp://rtspsim:554/media/camera-300s.mkv" }
        ]
    }
}

请注意,此有效负载:Notice that this payload:

  • 指定需要为其创建实例的拓扑名称 (MotionDetection)。Specifies the topology name (MotionDetection) for which the instance needs to be created.
  • 包含 rtspUrl(它在图形拓扑有效负载中没有默认值)的参数值。Contains a parameter value for rtspUrl, which didn't have a default value in the graph topology payload.

几秒钟内,“输出”窗口中显示以下响应:Within few seconds, you see the following response in the OUTPUT window:

[DirectMethod] Invoking Direct Method [GraphInstanceSet] to [lva-sample-device/lvaEdge] ...
[DirectMethod] Response from [lva-sample-device/lvaEdge]:
{
  "status": 201,
  "payload": {
    "name": "Sample-Graph-1",
    "properties": {
      "created": "2020-05-19T07:44:33.868Z",
      "lastModified": "2020-05-19T07:44:33.868Z",
      "state": "Inactive",
      "description": "Sample graph description",
      "topologyName": "MotionDetection",
      "parameters": [
        {
          "name": "rtspUrl",
          "value": "rtsp://rtspsim:554/media/camera-300s.mkv"
        }
      ]
    }
  }
}

在响应有效负载中,请注意:In the response payload, notice that:

  • 状态代码为 201,指示已创建新实例。The status code is 201, indicating a new instance was created.
  • 状态为 Inactive,指示图形实例已创建但未激活。The state is Inactive, indicating that the graph instance was created but not activated. 有关详细信息,请参阅媒体图状态For more information, see Media graph states.

请尝试以下后续步骤:Try the following next steps:

  1. 使用相同有效负载再次调用 GraphInstanceSetInvoke GraphInstanceSet again by using the same payload. 请注意,返回的状态代码为 200。Notice that the returned status code is 200.
  2. 再次调用 GraphInstanceSet,但使用不同描述。Invoke GraphInstanceSet again, but use a different description. 请注意响应有效负载中更新的描述,指示图形实例已成功更新。Notice the updated description in the response payload, indicating that the graph instance was successfully updated.
  3. 调用 GraphInstanceSet,但将名称更改为 Sample-Graph-2Invoke GraphInstanceSet, but change the name to Sample-Graph-2. 在响应有效负载中,请注意新创建的图形实例(即状态代码 201)。In the response payload, notice the newly created graph instance (that is, status code 201).

调用 GraphInstanceActivateInvoke GraphInstanceActivate

现在激活图形实例,以通过模块启动实时视频流。Now activate the graph instance to start the flow of live video through the module. 使用以下有效负载调用直接方法 GraphInstanceActivateInvoke the direct method GraphInstanceActivate by using the following payload.

{
    "@apiVersion" : "1.0",
    "name" : "Sample-Graph-1"
}

几秒钟内,“输出”窗口中显示以下响应。Within a few seconds, you see the following response in the OUTPUT window.

[DirectMethod] Invoking Direct Method [GraphInstanceActivate] to [lva-sample-device/lvaEdge] ...
[DirectMethod] Response from [lva-sample-device/lvaEdge]:
{
  "status": 200,
  "payload": null
}

状态代码 200 指示图形实例已成功激活。The status code of 200 indicates that the graph instance was successfully activated.

调用 GraphInstanceGetInvoke GraphInstanceGet

现在使用以下有效负载调用直接方法 GraphInstanceGetNow invoke the direct method GraphInstanceGet by using the following payload.

 {
     "@apiVersion" : "1.0",
     "name" : "Sample-Graph-1"
 }

几秒钟内,“输出”窗口中显示以下响应。Within a few seconds, you see the following response in the OUTPUT window.

[DirectMethod] Invoking Direct Method [GraphInstanceGet] to [lva-sample-device/lvaEdge] ...
[DirectMethod] Response from [lva-sample-device/lvaEdge]:
{
  "status": 200,
  "payload": {
    "name": "Sample-Graph-1",
    "properties": {
      "created": "2020-05-19T07:44:33.868Z",
      "lastModified": "2020-05-19T07:44:33.868Z",
      "state": "Active",
      "description": "graph description",
      "topologyName": "MotionDetection",
      "parameters": [
        {
          "name": "rtspUrl",
          "value": "rtsp://rtspsim:554/media/camera-300s.mkv"
        }
      ]
    }
  }
}

在响应有效负载中,请注意以下详细信息:In the response payload, notice the following details:

  • 状态代码为 200,表示成功。The status code is 200, indicating success.
  • 状态为 Active,表示图形实例现在处于活动状态。The state is Active, indicating the graph instance is now active.

观察结果Observe results

创建和激活的图形实例使用运动检测处理器节点来检测传入实时视频流中的运动。The graph instance that we have created and activated uses the motion detection processor node to detect motion in the incoming live video stream. 它会将事件发送到 IoT 中心接收器节点。It sends events to the IoT Hub sink node. 这些事件会中继到 IoT Edge 中心。These events are relayed to IoT Edge Hub.

若要观察结果,请遵循以下步骤。To observe the results, follow these steps.

  1. 在 Visual Studio Code 中,打开“资源管理器”窗格。In Visual Studio Code, open the Explorer pane. 在左下角,查找“Azure IoT 中心”。In the lower-left corner, look for Azure IoT Hub.

  2. 展开“设备”节点。Expand the Devices node.

  3. 右键单击“lva-sample-device”,然后选择“开始监视内置事件监视” 。Right-click lva-sample-device and then select Start Monitoring Built-in Event Monitoring.

    开始监视 IoT 中心事件

“输出”窗口显示以下消息:The OUTPUT window displays the following message:

[IoTHubMonitor] [7:44:33 AM] Message received from [lva-sample-device/lvaEdge]:
{
    "body": {
    "timestamp": 143005362606360,
    "inferences": [
        {
        "type": "motion",
        "motion": {
            "box": {
            "l": 0.828452,
            "t": 0.455224,
            "w": 0.1,
            "h": 0.088889
            }
        }
        },
        {
        "type": "motion",
        "motion": {
            "box": {
            "l": 0.661088,
            "t": 0.597015,
            "w": 0.0625,
            "h": 0.051852
            }
        }
        }
    ]
    },
    "applicationProperties": {
    "topic": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.media/mediaservices/{amsAccountName}",
    "subject": "/graphInstances/Sample-Graph-1/processors/motionDetection",
    "eventType": "Microsoft.Media.Graph.Analytics.Inference",
    "eventTime": "2020-05-19T07:45:34.404Z",
    "dataVersion": "1.0"
    }
}

请注意以下详细信息:Notice these details:

  • 该消息包含 body 部分和 applicationProperties 部分。The message contains a body section and an applicationProperties section. 有关详细信息,请参阅创建和读取 IoT 中心消息For more information, see Create and read IoT Hub messages.
  • applicationProperties 中,subject 引用生成消息的 MediaGraph 中的节点。In applicationProperties, subject references the node in the MediaGraph from which the message was generated. 在本例中,该消息来自运动检测处理器。In this case, the message originates from the motion detection processor.
  • applicationProperties 中的 eventType 指示此事件是分析事件。In applicationProperties, eventType indicates that this event is an analytics event.
  • eventTime 值为事件发生的时间。The eventTime value is the time when the event occurred.
  • body 部分包含有关分析事件的数据。The body section contains data about the analytics event. 在本例中,该事件是推理事件,因此正文包含 timestampinferences 数据。In this case, the event is an inference event, so the body contains timestamp and inferences data.
  • inferences 部分指示 typemotionThe inferences section indicates that the type is motion. 它提供有关 motion 事件的附加数据。It provides additional data about the motion event.

如果让媒体图运行一段时间,你会在“输出”窗口中看到以下消息。If you let the media graph run for a while, you see the following message in the OUTPUT window.

[IoTHubMonitor] [7:47:45 AM] Message received from [lva-sample-device/lvaEdge]:
{
  "body": {
    "sdp": "SDP:\nv=0\r\no=- 1588948185746703 1 IN IP4 172.xx.xx.xx\r\ns=Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server\r\ni=media/camera-300s.mkv\r\nt=0 0\r\na=tool:LIVE555 Streaming Media v2020.04.12\r\na=type:broadcast\r\na=control:*\r\na=range:npt=0-300.000\r\na=x-qt-text-nam:Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server\r\na=x-qt-text-inf:media/camera-300s.mkv\r\nm=video 0 RTP/AVP 96\r\nc=IN IP4 0.0.0.0\r\nb=AS:500\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1;profile-level-id=4D0029;sprop-parameter-sets={SPS}\r\na=control:track1\r\n"
  },
  "applicationProperties": {
    "dataVersion": "1.0",
    "topic": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/<my-resource-group>/providers/microsoft.media/mediaservices/<ams-account-name>",
    "subject": "/graphInstances/Sample-Graph-1/sources/rtspSource",
    "eventType": "Microsoft.Media.Graph.Diagnostics.MediaSessionEstablished",
    "eventTime": "2020-05-19T07:47:45.747Z"
  }
}

在此消息中,请注意以下详细信息:In this message, notice the following details:

  • applicationProperties 中的 subject 指示消息是从媒体图中的 RTSP 源节点生成的。In applicationProperties, subject indicates that the message was generated from the RTSP source node in the media graph.
  • applicationProperties 中的 eventType 指示此事件是诊断事件。In applicationProperties, eventType indicates that this event is diagnostic.
  • body 包含有关诊断事件的数据。The body contains data about the diagnostic event. 在本例中,消息包含正文,因为事件是 MediaSessionEstablishedIn this case, the message contains the body because the event is MediaSessionEstablished.

调用其他直接方法进行清理Invoke additional direct methods to clean up

调用直接方法以便先停用图形实例,然后删除它。Invoke direct methods to first deactivate the graph instance and then delete it.

调用 GraphInstanceDeactivateInvoke GraphInstanceDeactivate

使用以下有效负载调用直接方法 GraphInstanceDeactivateInvoke the direct method GraphInstanceDeactivate by using the following payload.

{
    "@apiVersion" : "1.0",
    "name" : "Sample-Graph-1"
}

几秒钟内,“输出”窗口中显示以下响应:Within a few seconds, you see the following response in the OUTPUT window:

[DirectMethod] Invoking Direct Method [GraphInstanceDeactivate] to [lva-sample-device/lvaEdge] ...
[DirectMethod] Response from [lva-sample-device/lvaEdge]:
{
  "status": 200,
  "payload": null
}

状态代码 200 指示图形实例已成功停用。The status code of 200 indicates that the graph instance was successfully deactivated.

接下来,尝试按本文前面所示来调用 GraphInstanceGetNext, try to invoke GraphInstanceGet as indicated previously in this article. 观察 state 值。Observe the state value.

调用 GraphInstanceDeleteInvoke GraphInstanceDelete

使用以下有效负载调用直接方法 GraphInstanceDeleteInvoke the direct method GraphInstanceDelete by using the following payload.

{
    "@apiVersion" : "1.0",
    "name" : "Sample-Graph-1"
}

几秒钟内,“输出”窗口中显示以下响应:Within a few seconds, you see the following response in the OUTPUT window:

[DirectMethod] Invoking Direct Method [GraphInstanceDelete] to [lva-sample-device/lvaEdge] ...
[DirectMethod] Response from [lva-sample-device/lvaEdge]:
{
  "status": 200,
  "payload": null
}

状态代码 200 指示图形实例已成功删除。A status code of 200 indicates that the graph instance was successfully deleted.

调用 GraphTopologyDeleteInvoke GraphTopologyDelete

使用以下有效负载调用直接方法 GraphTopologyDeleteInvoke the direct method GraphTopologyDelete by using the following payload.

{
    "@apiVersion" : "1.0",
    "name" : "MotionDetection"
}

几秒钟内,“输出”窗口中显示以下响应。Within a few seconds, you see the following response in the OUTPUT window.

[DirectMethod] Invoking Direct Method [GraphTopologyDelete] to [lva-sample-device/lvaEdge] ...
[DirectMethod] Response from [lva-sample-device/lvaEdge]:
{
  "status": 200,
  "payload": null
}

状态代码 200 指示图形拓扑已成功删除。A status code of 200 indicates that the graph topology was successfully deleted.

请尝试以下后续步骤:Try the following next steps:

  1. 调用 GraphTopologyList,并观察到模块不包含图形拓扑。Invoke GraphTopologyList and observe that the module contains no graph topologies.
  2. 使用与 GraphTopologyList 相同的有效负载调用 GraphInstanceListInvoke GraphInstanceList by using the same payload as GraphTopologyList. 观察到未枚举任何图形实例。Observe that no graph instances are enumerated.

清理资源Clean up resources

如果不打算继续使用此应用程序,请删除本快速入门中创建的资源。If you're not going to continue to use this application, delete the resources you created in this quickstart.

后续步骤Next steps