Data Flow
To help you understand the data structure transfer process between plugins, the following procedure uses an image as the input and describes the data transfer process in detail based on the code. For details about the data structure and function declaration, see API Reference (C++).
Figure 1 Data structure transfer process
- Create a variable MxstDataInput for storing the input image and use the ReadFile function to read the image data to the variable dataBuffer.
MxStream::MxstDataInput dataBuffer; APP_ERROR ret = ReadFile("./test.jpg", dataBuffer); - Create a stream management object MxStreamManager, initialize the object, and load the pipeline file.
MxStreamManager *mxStreamManager = new MxStream::MxStreamManager(); ret = mxStreamManager->InitManager(); string streamsConfig = "detection.pipeline"; // The detection.pipeline file can contain one or more service streams. APP_ERROR ret = mxStreamManager->CreateMultipleStreams(streamsConfig); // The method for processing multiple service streams is used.
- Use the SendData function to pass the input data to the image obtaining module.
ret = mxStreamManager->SendData(streamName, inPluginId, dataBuffer); // streamName is the name of the service stream in the pipeline file. inPluginId indicates the input port number, corresponding to the input element number.
- Process data in the Process function of each plugin.
- Receive the buffer data of the previous plugin and the metadata mounted to the buffer.
MxpiFrame inputMxpiFrame = GetHostDataInfo(*mxpiBuffer); // If the data is on the device, call the GetDeviceDataInfo function. MxpiMetadataManager mxpiMetadataManager(*mxpiBuffer); // Create a metadata manager object. shared_ptr<void> metadata = mxpiMetadataManager.GetMetadata("keyName"); // Obtain the metadata mounted to the buffer based on the key name. keyName is the name of the previous plugin. - Process the service logic.
DataProcess(inputMxpiFrame, metadata, outputMetadata); // Data processing functions implemented in the plugin, such as decoding, resizing, and inference. mxpiMetadataManager.AddMetadata("pluginName", outputMetadata); // Mount outputMetadata data to the buffer. keyName is usually pluginName of the current plugin. - Send buffer data to the next plugin.
SendData(inPlugin, *mxpiBuffer); // Call the SendData method of MxPluginBase to send data to the next plugin.
- Receive the buffer data of the previous plugin and the metadata mounted to the buffer.
- Use the GetResult function to obtain the output result of the last plugin.
MxStream::MxstDataOutput* output = mxStreamManager->GetResult(streamName, outPluginId); // outPluginId indicates the output port number, corresponding to the output element number.
Parent topic: Basic Development