From patchwork Mon Jul 9 15:48:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Gorzel X-Patchwork-Id: 9655 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp2647716jad; Mon, 9 Jul 2018 08:48:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdad7omfecUG3fcTzAZrpcChvGj0Rcpo4htg0c2ArxAurQsjUewSWEkL1Auy98vC99DtmPv X-Received: by 2002:a5d:4b50:: with SMTP id w16-v6mr14864421wrs.87.1531151298851; Mon, 09 Jul 2018 08:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531151298; cv=none; d=google.com; s=arc-20160816; b=DGKhr9klxBWsxkqVe4t6Xx3hsPF4Ey8RCYN3CbzuZF2rhPr0A7bqn6g64iKOEMAMuV 3m1iMVzQR3W1lrQPkzGfhtyAKVlEJvckvmOOm99GADuaMbuAPrOR+snWo9lx8rCvxMek qWGvrQEdiaeUii0KVsKVU7OFepSdoLBkBynp7EPv9TBsG6gLO+fMjZzUr++7Ld60zacY Cg0pmfNfYJ8UXS5SZGVox3Ik0BFL870teif7HD/qNLfOxDsOr9jnqgGjfGE4seYZNrlX q9fATnF7UKK0s4qJ7WFtVOleDfM88cBiCsR10Xe3zcm+5W9UAG/dIl/j+cuU09VX8HAF YxyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:from:references:message-id :in-reply-to:date:mime-version:dkim-signature:delivered-to :arc-authentication-results; bh=rhYEMcYJXDHvxxrmtXpvNWYFaup1oXcuKSXM7kaSIX8=; b=rF5VN81ntfGi0avOITJzEqDGLzYmx5Jx7bNziL7O3wuLvNqDZc5y1p1/LEVAvm0Q0Y Qla2JfiGmOuPfYtdcbzieYK5ygqLqQNeYiuBubfcYiBEVY60ftalMBVZaJPIKWcr/XYK IlPi1+y0O6JfSZ3DAeHMKCNDzTHv+0JCA37r2d1h+pH5jWnYR6XIDWdKAu5Onh6JS8V6 UxntP9g74tbDaOD7LnqA6bklelNNugpl1S7PDysXZMx2676ckdTujCFcZjXg8sGddD+j NTCvRgTNQI3VdyB+C5bwc3JuaRXpiW6ZKC19SS2+j+psmrv47sZQCQHEoYXqllheSo0S Becw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=Mn6cChsm; 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 r20-v6si14324565wrc.42.2018.07.09.08.48.18; Mon, 09 Jul 2018 08:48:18 -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=@google.com header.s=20161025 header.b=Mn6cChsm; 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 8823868A42C; Mon, 9 Jul 2018 18:48:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw0-f201.google.com (mail-yw0-f201.google.com [209.85.161.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A1DD4689C8D for ; Mon, 9 Jul 2018 18:48:03 +0300 (EEST) Received: by mail-yw0-f201.google.com with SMTP id r144-v6so9202586ywg.9 for ; Mon, 09 Jul 2018 08:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc:content-transfer-encoding; bh=j96l7jDEeEG3b/y+lqGYO4iIEYJTuRmmFbSESpF5R5w=; b=Mn6cChsm5AReQz7hDeCb5cLWjoeyzdVa49cA2D34/6lY4uRO7E6EeVlDvhjov2j4df Duk6TikDdpQuhC8NHjPEqpfHs/7uKywectTRL/mCBIlFtoLwhmF4meOqIth5jwvS8XTW fTzR/u0pWLTqzyQVBZaNW3t9TTe8ddk+Uu9A//6KnNP2W2ZK84ET/qXgPZ12vqyEpq4l U2233ie3OmfDNSPRB/fTy3jIO8Y1pDuueuHFUQusA2qbTJMxxIma+IYWjeGYkjdQKRIc EZN7UFubhwsU2oNe50IOfemLeuRrUQEWZicco7fmiKZBjOHP1nS2fJ3wlGF3eeyY0mnZ GA3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc:content-transfer-encoding; bh=j96l7jDEeEG3b/y+lqGYO4iIEYJTuRmmFbSESpF5R5w=; b=cDmTdymX0xRC4mdvGNKXL2VahBM+mJEtww8jrRHRY1eBKDC9/WdX3uf9EDdXm0F5bq o/kyEjyvsb+0qK/nw0ZRm0W2aMLzRvHMsNc//U+WwpoB7KeSGUBivcmiYNujSe0FJsl6 eGoVUIqhPFeD65S6hev+Fy3LlWeb/0ltBzErG7dQdAyvF5OIPpnC6X3isSi75gJDgv21 H94EUd5jyUUAbYkfl6/fzrt4EYkesEGOu57WTrxNSnL/0+N3wJMiDvBfktA3HF/ow6S/ pLs7q/S1LeZKTwoJBxxtjbp3h+s6JrHiBv9XQTTHAOUwPuH80O0eyqaiWbMJPdsUbmQg U8XA== X-Gm-Message-State: APt69E02Y4+xXYFBuhfyKDwr3gtI1izp7TCG4b29bZTBTcwG6vP+AanA 1PElOV5ZiJAvKtKUjrcGrtkPFw1y/2RssHsVwQKpe5ZAsmpzYYcYgtdmIMPdG0ofypHwBtMClto 3vMfOJP4nnBQZwdrPHB97I9wziOX9iV+NyszFRfA8iN7GLCmC3H6dA++Jj4mND5w= MIME-Version: 1.0 X-Received: by 2002:a81:56:: with SMTP id 83-v6mr6152193ywa.68.1531151288931; Mon, 09 Jul 2018 08:48:08 -0700 (PDT) Date: Mon, 9 Jul 2018 16:48:02 +0100 In-Reply-To: Message-Id: <20180709154802.42505-1-gorzel@google.com> References: X-Mailer: git-send-email 2.18.0.203.gfac676dfb9-goog From: Marcin Gorzel To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] Use channel count if channel layout is undefined 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 Cc: Marcin Gorzel Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Rematrixing supports up to 64 channels but there is only a limited number of channel layouts defined. Currently, in/out channel count is obtained from the channel layout so if the channel layout is undefined (e.g. for 9, 10, 11 channels etc.) the in/out channel count will be 0 and the rematrixing will fail. This change adds a check if the channel layout is non-zero, and if not, prefers to use the in|out_ch_count instead. This seems to be related to ticket #6790. --- libavcodec/utils.c | 1 + libswresample/rematrix.c | 18 ++++++++++++------ libswresample/swresample.c | 10 ++++++++++ libswresample/x86/rematrix_init.c | 8 ++++++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 59d41ccbb6..728f2b3355 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -674,6 +674,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code av_freep(&avctx->subtitle_header); if (avctx->channels > FF_SANE_NB_CHANNELS) { + av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d.\n", avctx->channels); ret = AVERROR(EINVAL); goto free_and_end; } diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 8227730056..8c9fbf3804 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -69,10 +69,12 @@ int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride) return AVERROR(EINVAL); memset(s->matrix, 0, sizeof(s->matrix)); memset(s->matrix_flt, 0, sizeof(s->matrix_flt)); - nb_in = (s->user_in_ch_count > 0) ? s->user_in_ch_count : - av_get_channel_layout_nb_channels(s->user_in_ch_layout); - nb_out = (s->user_out_ch_count > 0) ? s->user_out_ch_count : - av_get_channel_layout_nb_channels(s->user_out_ch_layout); + nb_in = s->user_in_ch_layout != 0 + ? av_get_channel_layout_nb_channels(s->user_in_ch_layout) + : s->user_in_ch_count; + nb_out = s->user_out_ch_layout != 0 + ? av_get_channel_layout_nb_channels(s->user_out_ch_layout) + : s->user_out_ch_count; for (out = 0; out < nb_out; out++) { for (in = 0; in < nb_in; in++) s->matrix_flt[out][in] = s->matrix[out][in] = matrix[in]; @@ -384,8 +386,12 @@ av_cold static int auto_matrix(SwrContext *s) av_cold int swri_rematrix_init(SwrContext *s){ int i, j; - int nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout); - int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout); + int nb_in = s->in_ch_layout != 0 + ? av_get_channel_layout_nb_channels(s->in_ch_layout) + : s->user_in_ch_count; + int nb_out = s->out_ch_layout != 0 + ? av_get_channel_layout_nb_channels(s->out_ch_layout) + : s->user_out_ch_count; s->mix_any_f = NULL; diff --git a/libswresample/swresample.c b/libswresample/swresample.c index 5bd39caac4..ecb9d97bc9 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -168,6 +168,16 @@ av_cold int swr_init(struct SwrContext *s){ s-> in.ch_count = s-> user_in_ch_count; s->used_ch_count = s->user_used_ch_count; + if(s->user_out_ch_count > SWR_CH_MAX) { + av_log(s, AV_LOG_ERROR, "Output channel count %d is unsupported.\n", s->user_out_ch_count); + return AVERROR(EINVAL); + } + + if(s->user_in_ch_count > SWR_CH_MAX) { + av_log(s, AV_LOG_ERROR, "Input channel count %d is unsupported.\n", s->user_in_ch_count); + return AVERROR(EINVAL); + } + s-> in_ch_layout = s-> user_in_ch_layout; s->out_ch_layout = s->user_out_ch_layout; diff --git a/libswresample/x86/rematrix_init.c b/libswresample/x86/rematrix_init.c index d71b41a73e..a6ae074926 100644 --- a/libswresample/x86/rematrix_init.c +++ b/libswresample/x86/rematrix_init.c @@ -33,8 +33,12 @@ D(int16, sse2) av_cold int swri_rematrix_init_x86(struct SwrContext *s){ #if HAVE_X86ASM int mm_flags = av_get_cpu_flags(); - int nb_in = av_get_channel_layout_nb_channels(s->in_ch_layout); - int nb_out = av_get_channel_layout_nb_channels(s->out_ch_layout); + int nb_in = s->in_ch_layout != 0 + ? av_get_channel_layout_nb_channels(s->in_ch_layout) + : s->user_in_ch_count; + int nb_out = s->out_ch_layout != 0 + ? av_get_channel_layout_nb_channels(s->out_ch_layout) + : s->user_out_ch_count; int num = nb_in * nb_out; int i,j;