summaryrefslogtreecommitdiff
path: root/libavfilter/dnn/dnn_io_proc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavfilter/dnn/dnn_io_proc.c')
-rw-r--r--libavfilter/dnn/dnn_io_proc.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/libavfilter/dnn/dnn_io_proc.c b/libavfilter/dnn/dnn_io_proc.c
index bee1423342..e104cc5064 100644
--- a/libavfilter/dnn/dnn_io_proc.c
+++ b/libavfilter/dnn/dnn_io_proc.c
@@ -21,6 +21,7 @@
#include "dnn_io_proc.h"
#include "libavutil/imgutils.h"
#include "libswscale/swscale.h"
+#include "libavutil/avassert.h"
DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx)
{
@@ -92,7 +93,7 @@ DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *l
return DNN_SUCCESS;
}
-DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx)
+static DNNReturnType proc_from_frame_to_dnn_frameprocessing(AVFrame *frame, DNNData *input, void *log_ctx)
{
struct SwsContext *sws_ctx;
int bytewidth = av_image_get_linesize(frame->format, frame->width, 0);
@@ -163,3 +164,56 @@ DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *lo
return DNN_SUCCESS;
}
+
+static enum AVPixelFormat get_pixel_format(DNNData *data)
+{
+ if (data->dt == DNN_UINT8 && data->order == DCO_BGR) {
+ return AV_PIX_FMT_BGR24;
+ }
+
+ av_assert0(!"not supported yet.\n");
+ return AV_PIX_FMT_BGR24;
+}
+
+static DNNReturnType proc_from_frame_to_dnn_analytics(AVFrame *frame, DNNData *input, void *log_ctx)
+{
+ struct SwsContext *sws_ctx;
+ int linesizes[4];
+ enum AVPixelFormat fmt = get_pixel_format(input);
+ sws_ctx = sws_getContext(frame->width, frame->height, frame->format,
+ input->width, input->height, fmt,
+ SWS_FAST_BILINEAR, NULL, NULL, NULL);
+ if (!sws_ctx) {
+ av_log(log_ctx, AV_LOG_ERROR, "Impossible to create scale context for the conversion "
+ "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
+ av_get_pix_fmt_name(frame->format), frame->width, frame->height,
+ av_get_pix_fmt_name(fmt), input->width, input->height);
+ return DNN_ERROR;
+ }
+
+ if (av_image_fill_linesizes(linesizes, fmt, input->width) < 0) {
+ av_log(log_ctx, AV_LOG_ERROR, "unable to get linesizes with av_image_fill_linesizes");
+ sws_freeContext(sws_ctx);
+ return DNN_ERROR;
+ }
+
+ sws_scale(sws_ctx, (const uint8_t *const *)frame->data, frame->linesize, 0, frame->height,
+ (uint8_t *const *)(&input->data), linesizes);
+
+ sws_freeContext(sws_ctx);
+ return DNN_SUCCESS;
+}
+
+DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, DNNFunctionType func_type, void *log_ctx)
+{
+ switch (func_type)
+ {
+ case DFT_PROCESS_FRAME:
+ return proc_from_frame_to_dnn_frameprocessing(frame, input, log_ctx);
+ case DFT_ANALYTICS_DETECT:
+ return proc_from_frame_to_dnn_analytics(frame, input, log_ctx);
+ default:
+ avpriv_report_missing_feature(log_ctx, "model function type %d", func_type);
+ return DNN_ERROR;
+ }
+}