From patchwork Wed Aug 30 19:09:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 4912 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp808503jao; Wed, 30 Aug 2017 12:17:21 -0700 (PDT) X-Google-Smtp-Source: ADKCNb4mbqouaXoi3lU01atbVN7XG2MEY/VKm9e7oSylCp2Nn3iLLPWUyQBr94o2uoB+1mNF0/pq X-Received: by 10.223.176.138 with SMTP id i10mr1632587wra.222.1504120641798; Wed, 30 Aug 2017 12:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504120641; cv=none; d=google.com; s=arc-20160816; b=C/306vNRGNT/ZxrUnanJyIUoL131z/x4qu1GGWKf0O6q4rlurkBuxFrPuZ41lO2q2n 2WnoiFInwEUDbatE8a/G53KXwrYEhWKqEBHqSYFVG9aSBT4khootXGobu3dSsodqHwL3 4RGJ+8ECoypTg6wxXdYo9WCqEsQ186bCA/i3RQ4/tDy2jzrsGauhYC45MN57ONJUkd7j hsbIMdM9izu7j8XAiFAAxz/3OyQjNzWXU3E5JKUJKNLhTzdKqs0upFqIsV4vzSr2oT2v r6JUcoAG4I2jrhYmmhwJEBW0Wed26QabFYVF+k68SFAgwx6U/xrXQ/PnRTvTtAsdHsbg tIiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-language:mime-version:user-agent:date :message-id:from:to:dkim-signature:delivered-to :arc-authentication-results; bh=T/BFWUBtfRtfZsX9gP4S4ZJyPbvSnpI6TOZXS3n8mRA=; b=YSWLRmFRsDbQg5GEN5BOCGS1vikDeHejN3Ck9BNi47lCvGAGRGxxaeGVBPgj+hCIfd l/03LGCn4W5SptrzeGoptO1gZ1NMY9nDz0sc41ceNMo+Lhnjt7BcIjR+n4xhC4mghq/E hbGP5hg7E0xGPfvw56zMv9fep1MKyHQ+GtgqTDiONCDD5TfnEoNtkO/xO0Z/FBaNK5Xx qVB5+pwutAiaIyv8l/53bgZ7Ys6E4odseAK3uGWIO+foRUvDCKo1LC1xBIjIDP08Ufod eGKOXuuHgOPMBCXOQIMqPaGJ4zBrT2HdDoqGrLtuoWxoZ8JbeMfXFkmvBouKM09x6Irg aaxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=vHmZJNyo; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k1si4811560wrf.61.2017.08.30.12.17.21; Wed, 30 Aug 2017 12:17:21 -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=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=vHmZJNyo; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 60367689F79; Wed, 30 Aug 2017 22:17:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 24084680225 for ; Wed, 30 Aug 2017 22:17:12 +0300 (EEST) Received: by mail-wm0-f47.google.com with SMTP id u126so15715094wmg.1 for ; Wed, 30 Aug 2017 12:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=UPNLU3iwTROkqzb8dcEXZ2KCHD57R/V1Kx0AQ/f5TZs=; b=vHmZJNyoZtqURQ/dWvuOAT7jQ7Wth4QDp2rMtE7QdU/0sKApmyYoIZ/c7DkIw4P/Zi ccn/ToFOQ6EFVSV6qvYBix5d7gLKM0quRkzUKZiU2Ib7WGWtE41IKxHnesRJNqATfCCR L/0VG6LLlJJpbsX2bYNzKVF94BsGESCZ7DDKB8ewRCgGOu6tGOn5L9alXJ9yyxX7RvOe vDOHKDDi6M0inqidBMGzUAKnJY2vulsB8d97MKKrFEBmyQta+r/oOiD/uyBrHhP6tOca lUNn/Itd7UoYUJzI3YLigkc0p28uetSBv9jo+e5DxHo/5EsuGayQ3ThmX6Wr3rknlfhT pclw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=UPNLU3iwTROkqzb8dcEXZ2KCHD57R/V1Kx0AQ/f5TZs=; b=t5SoDanBqB6oL95me7QNZLVgbkjWd1FXKkzoX5VidEGU2XGNC+Pv8JPmiw1vygRPC+ m+BA5OFY4gce45yZAugKJ+otgKZqJoiIkMA7iyPPwOspalgzFrj871jwtNhS0P6LD1fn XsGQ0phc4cLVft+3majYSb9KHHooCHBzvkECccoF6i6PXN8k6v28aYqP9GqNynVbb6a9 Z2AdJZNJU3P3i0oLjGcVPhovWtV+pRCp7m/7qnuqvRCudDk+UWkNFLbq1UqCNTeCTuOg aslmXsKd7Iju5SMC19j+Q/8IWuEcZ66auBm5zYIFDN0IVjpg04IxDqQJIyUKQo/KReLu OPyQ== X-Gm-Message-State: AHYfb5gSfsrXiqo8zNSMZ8reb2PugRUYHK2XRHNVn6XGd0jZ+Gp6k8V2 Bl0B0tQMIMpBCYnAaZw= X-Received: by 10.28.70.3 with SMTP id t3mr1904728wma.57.1504120178658; Wed, 30 Aug 2017 12:09:38 -0700 (PDT) Received: from [192.168.0.9] (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id 74sm4288940wrk.3.2017.08.30.12.09.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Aug 2017 12:09:38 -0700 (PDT) To: FFmpeg development discussions and patches From: Mark Thompson Message-ID: <19d1faff-6281-f56c-ed31-86f8c09d8ed4@jkqxz.net> Date: Wed, 30 Aug 2017 20:09:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] nvenc: Don't segfault on close if no cuda is available X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- """ Cannot load libcuda.so.1 Thread 1 "ffmpeg_g" received signal SIGSEGV, Segmentation fault. 0x000055555657cd59 in ff_nvenc_encode_close (avctx=0x5555578ed920) at src/libavcodec/nvenc.c:1337 1337 cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context); """ This only fixes the segfaults - some of the other stuff might want to be gated as well? libavcodec/nvenc.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 8c4fd31fec..5586a8901f 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1334,10 +1334,12 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx) CUcontext dummy; int i; - cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context); - if (cu_res != CUDA_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n"); - return AVERROR_EXTERNAL; + if (dl_fn->cuda_dl) { + cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context); + if (cu_res != CUDA_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n"); + return AVERROR_EXTERNAL; + } } /* the encoder has to be flushed before it can be closed */ @@ -1381,14 +1383,16 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx) p_nvenc->nvEncDestroyEncoder(ctx->nvencoder); ctx->nvencoder = NULL; - cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy); - if (cu_res != CUDA_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n"); - return AVERROR_EXTERNAL; - } + if (dl_fn->cuda_dl) { + cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy); + if (cu_res != CUDA_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n"); + return AVERROR_EXTERNAL; + } - if (ctx->cu_context_internal) - dl_fn->cuda_dl->cuCtxDestroy(ctx->cu_context_internal); + if (ctx->cu_context_internal) + dl_fn->cuda_dl->cuCtxDestroy(ctx->cu_context_internal); + } ctx->cu_context = ctx->cu_context_internal = NULL; nvenc_free_functions(&dl_fn->nvenc_dl);