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
122122 #endif
123123 return DNN_SUCCESS;
124124 }
125+
126+DNNAsyncStatusType 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
2424 #ifndef AVFILTER_DNN_DNN_BACKEND_COMMON_H
2525 #define AVFILTER_DNN_DNN_BACKEND_COMMON_H
2626
27+#include "queue.h"
2728 #include "../dnn_interface.h"
2829 #include "libavutil/thread.h"
2930
@@ -122,4 +123,18 @@ DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module); · 92 unmodified lines
122123 */
123124 DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module);
124125
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+ */
138+DNNAsyncStatusType ff_dnn_get_async_result_common(Queue *task_queue, AVFrame **in, AVFrame **out);
139+
125140 #endif
libavfilter/dnn/dnn_backend_openvino.c+1−17
@@ -32,7 +32,6 @@ · 31 unmodified lines
3232 #include "libavutil/avstring.h"
3333 #include "libavutil/detection_bbox.h"
3434 #include "../internal.h"
35−#include "queue.h"
3635 #include "safe_queue.h"
3736 #include <c_api/ie_c_api.h>
3837 #include "dnn_backend_common.h"
@@ -883,22 +882,7 @@ DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, DNNExecBasePa · 844 unmodified lines
883882 DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out)
884883 {
885884 OVModel *ov_model = model->model;
886− TaskItem *task = ff_queue_peek_front(ov_model->task_queue);
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;
885+ return ff_dnn_get_async_result_common(ov_model->task_queue, in, out);
902886 }
903887
904888 DNNReturnType ff_dnn_flush_ov(const DNNModel *model)
libavfilter/dnn/queue.h+1−0
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1919 */
2020
21+#include <stddef.h>
2122
2223 #ifndef AVFILTER_DNN_QUEUE_H
2324 #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