Service Stream Data Interconnection APIs

Data Flow of SendData-GetResult

The SendData API is used to send image data to the appsrc element. inPluginId specifies the appsrc ID. appsrc sends the data to other elements in the pipeline for processing. The processing result is sent to the appsink element. The GetResult API is used to obtain the appsink data. outPluginId specifies the appsink ID.

This set of APIs can be used when there is no appsrc or appsink element (that is, no external input data is required or no API is called to obtain the result). For example, when appsrc is changed to mxpi_rtspsrc for video stream obtaining, SendData is not required to send data, and the output result can be obtained by calling GetResult or GetResultSP. For details about the sample code, see SendData-GetResult Sample Code.

  • When multiple threads call the SendData API at the same time, the sequence of the results obtained by the GetResult API is uncertain. The SendData API supports multiple appsrc input elements, and the GetResult API supports multiple appsink output elements.
  • The data returned by the GetResultSP API is of the smart pointer type. You do not need to manage the memory. For details, see GetResultSP.
Figure 1 Data Flow of SendData-GetResult

Data Flow of SendDataWithUniqueId-GetResultWithUniqueId

SendDataWithUniqueId is used to send image data to the appsrc element. inPluginId (fixed to 0 currently) specifies the appsrc ID and the integer uniqueId is returned to the user. appsrc sends the data to the pipeline for processing and saves the processing result in outputMap using uniqueId as the key. The GetResultWithUniqueId API or GetResultWithUniqueIdSP API is used to obtain the inference result corresponding to SendDataWithUniqueId from outputMap based on key uniqueId. For details about the sample code, see SendDataWithUniqueId-GetResultWithUniqueId Sample Code.

  • SendDataWithUniqueId and GetResultWithUniqueId support only one appsrc element and one appsink element in the stream.
  • The data returned by the GetResultWithUniqueIdSP API is of the smart pointer type. You do not need to manage the memory. For details, see GetResultWithUniqueIdSP.
Figure 2 Data flow of SendDataWithUniqueId-GetResultWithUniqueId

Data Flow of SendMultiDataWithUniqueId-GetMultiResultWithUniqueId

SendMultiDataWithUniqueId is used to send image data to the appsrc element. inPluginId (fixed to 0 currently) specifies the appsrc ID and the integer uniqueId is returned to the user. appsrc sends the data to the pipeline for processing and saves the processing result in outputMap using uniqueId as the key. The GetMultiResultWithUniqueId API or GetMultiResultWithUniqueIdSP API is used to obtain the inference result corresponding to SendMultiDataWithUniqueId from outputMap based on key uniqueId. For details about the sample code, see Sample Code of SendMultiDataWithUniqueId-GetMultiResultWithUniqueId.

  • SendMultiDataWithUniqueId and GetMultiResultWithUniqueId support only one appsrc element and one appsink element in the stream.
  • The data returned by the GetMultiResultWithUniqueIdSP API is of the smart pointer type. You do not need to manage the memory. For details, see 14.4.2.1.18-GetMultiResultWithUniqueIdSP.
  • Only C++ APIs are supported.
Figure 3 Data Flow of SendMultiDataWithUniqueId-GetMultiResultWithUniqueId

Data Flow of SendProtobuf-GetProtobuf

The SendProtobuf API is used to send the protobuf data and key to the appsrc element in batches or one by one. The key is used to mount the protobuf data to the metadata and used to obtain the data required by elements. inPluginId specifies the appsrc number. appsrc sends data to other elements for processing. After processing the data, the element saves the processing result to the metadata using the element name as key. Finally, the element result is obtained from the metadata by using the GetProtobuf API. After a group of keys are entered, the protobuf data corresponding to the keys can be obtained.

This set of APIs can be used when there is no appsrc or appsink element (that is, no external input data is required or no API is called to obtain the result). For example, when appsrc is changed to the mxpi_rtspsrc element for video stream obtaining, SendProtobuf is not required to send data, and the output result can be obtained by calling GetProtobuf. For details about the sample code, see SendProtobuf-GetProtobuf Sample Code.

When multiple threads call the SendProtobuf API at the same time, the sequence of the results obtained by GetProtobuf is uncertain. The SendProtobuf API supports multiple appsrc input elements, and the GetProtobuf API supports multiple appsink output elements.

Figure 4 Data Flow of SendProtobuf-GetProtobuf

API Comparison

API

Input Data Type

Output Data Type

Whether the Input and Output Are in Order

Whether MIMO Are Supported

Whether the API Must Be Used in Pairing

Application Scenario

SendData-GetResult

Image

Serialization result and protobuf

No

Yes

No

Supports single-thread output in order or multi-thread output out of order

SendDataWithUniqueId-GetDataWithUniqueId

Image

Serialization result

Yes

No

Yes

Supports single-thread or multi-thread input and output in order For example, when an inference service is created, requests are sent from different clients concurrently.

SendMultiDataWithUniqueId-GetMultiResultWithUniqueId

Multiple images

Serialization result

Yes

No

Yes

Supports multi-image input at a time and single-thread or multi-thread input and output in order For example, when an inference service is created, requests are sent from different clients concurrently.

SendProtobuf-GetProtobuf

protobuf

protobuf

No

Yes

No

Supports single-thread output in order or multi-thread output out of order