From patchwork Fri May 7 11:00:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 27648 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp417341iof; Fri, 7 May 2021 04:00:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxU90s3jhVpC3k/TKpJGz4flzgiWcvCQiDaqphRiq9+0cmKfy+Lhz0VmKXNgNUlPs5RJ8V3 X-Received: by 2002:aa7:c349:: with SMTP id j9mr10503850edr.230.1620385238041; Fri, 07 May 2021 04:00:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620385238; cv=none; d=google.com; s=arc-20160816; b=BObIRN2qXDlrFHp7Jnkz6H/2gJZUFO0knleXPK3yQpHgAFlVe/5pqMjYFa9bKyTC/5 HGHXX2mLvG+RLmWdkCQSp3CYubqoqXIuWp34x1Oxae3fwXIcQaePjSwzgDkLLpxlk0MF znJtyuqKNDMnL/sPSM0fQzz01ESkDNTBPIZ69VuYtViWfK/8BPHzjI7+FjOB/y3orOcp VAvU9HH5F/JLlB2pdS+juwCnLiWX2BcsL7bBaB2UPEd8R19W6BC7mnnJJr34SZgbrf92 vAoHJksYqn1XElePPev4/z1OY6eI2wJi8bAhBzO3unEPlfyHoWJTBuyy0meT6skbwsqb C5/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=x8L6/PfeJOfuSBYxuRIO58Z7c4OWIIgOoiOEj3w9Mzc=; b=I5s7fetuUXqffINaFh+EEmBk4vrDs1/d8KXGHOnlZ+2QCNpPHb3tlnXz8b0736tiYV uYgM8bk/VJhFH+sMw2a9dAxBqNzEkVqvyin/8MzEcBus1vwJm1NPLAqzKBJUnGkworWK VNKuCSAhQuHnnuxXlOsWkp+6frORkZlrmIKkus+DeejOntMbCgzY+1NEtfHsi6XhjZrV svMmRzGEEl09bFLxqPn/Oqpv5USMb/TudcAYqcEC/PPJXPI8PCMl032sgQmpvGUI5HkQ X1EFN/UwEYhFDbglSLHsxE1dhFFy81CGOHjLbrB3tsWqJN+g6PoKq5lc6ZbrAsqMzMmv 5Lgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=jdIWhFcV; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ds10si6353971ejc.415.2021.05.07.04.00.37; Fri, 07 May 2021 04:00:38 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=jdIWhFcV; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4CCA5680372; Fri, 7 May 2021 14:00:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D4AC368033C for ; Fri, 7 May 2021 14:00:25 +0300 (EEST) Received: by mail-pf1-f176.google.com with SMTP id i190so7295540pfc.12 for ; Fri, 07 May 2021 04:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rLjyxxKlCtWHcRkeLAylknbFYcgOmbvB8EGlSPBUDEo=; b=jdIWhFcVRyG42P7ZU076E3WDP+S2ESmO3ywYI3EE56CpNzZPeSNVYajDUgWsXaBIIL gpzAy/smiV+dvc5STce/YGfPtpJVCOLfbSRQ410KfRK5j2vEIJvG1Pm42lhKamfn6SbU CQV/IYbHHwKBnlQX5wX6Akln0QHAqwxmIsTop9B3YDOS/5YgpKdPncMXlh0puZYUJMi0 KLyCXLR9Db+GKypaGa+dqeBM+UNBHaSF8WtvkuuFyUJc4CTtwLSXWA6WhQjK5xS1zVop usU+qsauL2LfHXfb426H0zHAFpr/t38841Fw0m9Wvn4k8fcjS+9nmY67AFdJESfdqOb/ aDQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rLjyxxKlCtWHcRkeLAylknbFYcgOmbvB8EGlSPBUDEo=; b=YztdfT8IDhRndGkJ0gr5vZuHashEkxUYv00uAjvd/WX7e+/aOmmSaQSDy3aubLNKQE BNwI8elqF+dAPJ6ODNlVjdkI8IQPhcYOS5NxUOyehLkavJPZgYUXA3vdVAhjUh2vC6vI czRvxZ0CEs0ARfOB5SV6Vyiey6Y71KIRRoNgmYUh6Oc22YIsjxHVoPwtwQpnSP1+5wi7 HmEdhNSt6csKe48krZMJ/JjQZiFnofUL/uUehj2nuBXGDc59ZaAImYpOMSi0Fdot6S8m Sbx8tL7jVqlyj9Iwdbxpa043MakQt7MENEHV7Gf/X9VGKKPjzdpFYJ1ZZoKfYPLze7pM Pnhg== X-Gm-Message-State: AOAM533SagjsMNNBU+mDo1Hw/GXP43KQ4jf33sONWhFojISbggpCuocE rgpHG3WiQyEDuIHaNL8/7BTBCd612Ws= X-Received: by 2002:aa7:8e85:0:b029:28f:2620:957e with SMTP id a5-20020aa78e850000b029028f2620957emr9769165pfr.40.1620385223719; Fri, 07 May 2021 04:00:23 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id k38sm4462629pgi.73.2021.05.07.04.00.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 May 2021 04:00:23 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 May 2021 19:00:15 +0800 Message-Id: <1620385216-31085-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1620350584-21215-1-git-send-email-lance.lmwang@gmail.com> References: <1620350584-21215-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v2 1/2] avfilter/dnn/dnn_backend_tf: fix cross library usage X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /UlVWAkHBvWc From: Limin Wang duplicate ff_hex_to_data() function from avformat and rename it to hex_to_data() as static function. Signed-off-by: Limin Wang --- libavfilter/dnn/dnn_backend_tf.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_tf.c b/libavfilter/dnn/dnn_backend_tf.c index 03fe310..eb11cb5 100644 --- a/libavfilter/dnn/dnn_backend_tf.c +++ b/libavfilter/dnn/dnn_backend_tf.c @@ -28,8 +28,8 @@ #include "dnn_backend_native_layer_conv2d.h" #include "dnn_backend_native_layer_depth2space.h" #include "libavformat/avio.h" -#include "libavformat/internal.h" #include "libavutil/avassert.h" +#include "libavutil/avstring.h" #include "../internal.h" #include "dnn_backend_native_layer_pad.h" #include "dnn_backend_native_layer_maximum.h" @@ -195,6 +195,38 @@ static DNNReturnType get_output_tf(void *model, const char *input_name, int inpu return ret; } +#define SPACE_CHARS " \t\r\n" +static int hex_to_data(uint8_t *data, int data_size, const char *p) +{ + int c, len, v; + + len = 0; + v = 1; + for (;;) { + p += strspn(p, SPACE_CHARS); + if (*p == '\0') + break; + c = av_toupper((unsigned char) *p++); + if (c >= '0' && c <= '9') + c = c - '0'; + else if (c >= 'A' && c <= 'F') + c = c - 'A' + 10; + else + break; + v = (v << 4) | c; + if (v & 0x100) { + if (data) { + if (len >= data_size) + return -1; + data[len] = v; + } + len++; + v = 1; + } + } + return len; +} + static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename) { TFContext *ctx = &tf_model->ctx; @@ -219,14 +251,14 @@ static DNNReturnType load_tf_model(TFModel *tf_model, const char *model_filename return DNN_ERROR; } config = tf_model->ctx.options.sess_config + 2; - sess_config_length = ff_hex_to_data(NULL, config); + sess_config_length = hex_to_data(NULL, 0, config); sess_config = av_mallocz(sess_config_length + AV_INPUT_BUFFER_PADDING_SIZE); if (!sess_config) { av_log(ctx, AV_LOG_ERROR, "failed to allocate memory\n"); return DNN_ERROR; } - ff_hex_to_data(sess_config, config); + hex_to_data(sess_config, sess_config_length, config); } graph_def = read_graph(model_filename);