History

lavfi/dnn: Common Function to Get Async Result in DNN Backends

This commits refactors the get async result function for common use in all three backends.

Shubhanshu Saxena committed 5 years ago

Commit c7165781 parent 86f0a4f4 files · +37 −17Browse files

Showing the changes to libavfilter (4 of 4 files). Show all

Unified · Split

4 files
  1. libavfilter/dnn/dnn_backend_common.c +20 −0
  2. libavfilter/dnn/dnn_backend_common.h +15 −0
  3. libavfilter/dnn/dnn_backend_openvino.c +1 −17
  4. libavfilter/dnn/queue.h +1 −0
libavfilter/dnn/dnn_backend_common.c+20−0
@@ -122,3 +122,23 @@ DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_ · 121 unmodified lines
122#endif122#endif
123 return DNN_SUCCESS;123 return DNN_SUCCESS;
124}124}
125
126DNNAsyncStatusType ff_dnn_get_async_result_common(Queue *task_queue, AVFrame **in, AVFrame **out)
127{
128 TaskItem *task = ff_queue_peek_front(task_queue);
129
130 if (!task) {
131 return DAST_EMPTY_QUEUE;
132 }
133
134 if (task->inference_done != task->inference_todo) {
135 return DAST_NOT_READY;
136 }
137
138 *in = task->in_frame;
139 *out = task->out_frame;
140 ff_queue_pop_front(task_queue);
141 av_freep(&task);
142
143 return DAST_SUCCESS;
144}
libavfilter/dnn/dnn_backend_common.h+15−0
@@ -24,6 +24,7 @@ · 23 unmodified lines
24#ifndef AVFILTER_DNN_DNN_BACKEND_COMMON_H24#ifndef AVFILTER_DNN_DNN_BACKEND_COMMON_H
25#define AVFILTER_DNN_DNN_BACKEND_COMMON_H25#define AVFILTER_DNN_DNN_BACKEND_COMMON_H
26 26
27#include "queue.h"
27#include "../dnn_interface.h"28#include "../dnn_interface.h"
28#include "libavutil/thread.h"29#include "libavutil/thread.h"
29 30
@@ -122,4 +123,18 @@ DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module); · 92 unmodified lines
122 */123 */
123DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module);124DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module);
124 125
126/**
127 * Extract input and output frame from the Task Queue after
128 * asynchronous inference.
129 *
130 * @param task_queue pointer to the task queue of the backend
131 * @param in double pointer to the input frame
132 * @param out double pointer to the output frame
133 *
134 * @retval DAST_EMPTY_QUEUE if task queue is empty
135 * @retval DAST_NOT_READY if inference not completed yet.
136 * @retval DAST_SUCCESS if result successfully extracted
137 */
138DNNAsyncStatusType ff_dnn_get_async_result_common(Queue *task_queue, AVFrame **in, AVFrame **out);
139
125#endif140#endif
libavfilter/dnn/dnn_backend_openvino.c+1−17
@@ -32,7 +32,6 @@ · 31 unmodified lines
32#include "libavutil/avstring.h"32#include "libavutil/avstring.h"
33#include "libavutil/detection_bbox.h"33#include "libavutil/detection_bbox.h"
34#include "../internal.h"34#include "../internal.h"
35#include "queue.h"
36#include "safe_queue.h"35#include "safe_queue.h"
37#include <c_api/ie_c_api.h>36#include <c_api/ie_c_api.h>
38#include "dnn_backend_common.h"37#include "dnn_backend_common.h"
@@ -883,22 +882,7 @@ DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, DNNExecBasePa · 844 unmodified lines
883DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out)882DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out)
884{883{
885 OVModel *ov_model = model->model;884 OVModel *ov_model = model->model;
886 TaskItem *task = ff_queue_peek_front(ov_model->task_queue);885 return ff_dnn_get_async_result_common(ov_model->task_queue, in, out);
887
888 if (!task) {
889 return DAST_EMPTY_QUEUE;
890 }
891
892 if (task->inference_done != task->inference_todo) {
893 return DAST_NOT_READY;
894 }
895
896 *in = task->in_frame;
897 *out = task->out_frame;
898 ff_queue_pop_front(ov_model->task_queue);
899 av_freep(&task);
900
901 return DAST_SUCCESS;
902}886}
903 887
904DNNReturnType ff_dnn_flush_ov(const DNNModel *model)888DNNReturnType ff_dnn_flush_ov(const DNNModel *model)
libavfilter/dnn/queue.h+1−0
@@ -18,6 +18,7 @@ · 17 unmodified lines
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */19 */
20 20
21#include <stddef.h>
21 22
22#ifndef AVFILTER_DNN_QUEUE_H23#ifndef AVFILTER_DNN_QUEUE_H
23#define AVFILTER_DNN_QUEUE_H24#define AVFILTER_DNN_QUEUE_H

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t