This commits refactors the get async result function for common use in all three backends.
Showing the changes to libavfilter (4 of 4 files). Show all
Unified · Split
| @@ -122,3 +122,23 @@ DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_ · 121 unmodified lines | |||
| 122 | #endif | 122 | #endif |
| 123 | return DNN_SUCCESS; | 123 | return DNN_SUCCESS; |
| 124 | } | 124 | } |
| 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 | } | ||
| @@ -24,6 +24,7 @@ · 23 unmodified lines | |||
| 24 | #ifndef AVFILTER_DNN_DNN_BACKEND_COMMON_H | 24 | #ifndef AVFILTER_DNN_DNN_BACKEND_COMMON_H |
| 25 | #define AVFILTER_DNN_DNN_BACKEND_COMMON_H | 25 | #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 | */ |
| 123 | DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module); | 124 | DNNReturnType 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 | */ | ||
| 138 | DNNAsyncStatusType ff_dnn_get_async_result_common(Queue *task_queue, AVFrame **in, AVFrame **out); | ||
| 139 | |||
| 125 | #endif | 140 | #endif |
| @@ -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 | |||
| 883 | DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out) | 882 | DNNAsyncStatusType 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 | ||
| 904 | DNNReturnType ff_dnn_flush_ov(const DNNModel *model) | 888 | DNNReturnType ff_dnn_flush_ov(const DNNModel *model) |
| @@ -18,6 +18,7 @@ · 17 unmodified lines | |||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 18 | * 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_H | 23 | #ifndef AVFILTER_DNN_QUEUE_H |
| 23 | #define AVFILTER_DNN_QUEUE_H | 24 | #define AVFILTER_DNN_QUEUE_H |