Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp889784pxb; Fri, 22 Apr 2022 13:32:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7MP0eqWpNvllyFJeGm2L0HKD0c9ZAhGLwGt074WhbHGsxyjCAJS4bPsCSVpSoKFi3/Bhd X-Received: by 2002:a63:eb0d:0:b0:3a2:ced0:31ef with SMTP id t13-20020a63eb0d000000b003a2ced031efmr5342280pgh.594.1650659538130; Fri, 22 Apr 2022 13:32:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650659538; cv=none; d=google.com; s=arc-20160816; b=RMM04zAIHfLiW/eL7Yy/6U4FWrHiz9F3lY94mL7m0BIOu6KEzywCGvTzJiyw47pANG m0c31eudZIRHWUe3nN855VpX7KDhj9pma35Jidmod8qxHJ/3rqRCZZNRETKkrg63jkE6 XEkqdoI5Qopt+aJykKIDuqVOO+JCJnqfwEwZzybBQQV9oRlCfER+l+GV08Rh0C7tzohg vxW1aDgP58AuHeVYUgJeVpKnk0l9FenZ/iWJwVnt45mSTYX2XTY+eMi9gS5/8RKbmh5+ VCGNrlI64T8envcqWj9HdK/syt0MAeS7xSFm3Ih7mhT/rqLC5eYuSBGq9LAD5Ot92wx7 IcCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=EXy96DuCS6O9bjeXHYxqles7M/EKq/uqaqaCiu7YpGo=; b=zXw1/Y1/nXdZup8nGiVrkgMYq//yp0NXJJbtlk7ZOUx/fQu7jjrLnRsIgnccO+NVpg faJSxo8VAGu2GOxqw7rofPzjYbYEtWu2DU3cdYGndCn1+L3NzDoPS5e0so1GQCSnHYMG oRyUWpMEKoWTcNtxD4okEemQy/SCt5I/r4vd3/kgEqd4SCPQAMVSVoXTCGV2dyfuFM7I stApM3LURsdhhbTybNrEmbOdoW0APFkphe3025dt3/a+7dpeHiHVP7asF0V5dgsjbxsS aq2S2lBaefzyCEgtpEnISYYOGl1Cj5Cp77CGDNJqBUveyszO3ykSJufY9MGU3usyiTr2 VppA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o12-20020a63920c000000b003816043f10bsi9564417pgd.768.2022.04.22.13.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:32:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3A8E11171E0; Fri, 22 Apr 2022 12:18:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444872AbiDVHe5 (ORCPT + 99 others); Fri, 22 Apr 2022 03:34:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386165AbiDVHe4 (ORCPT ); Fri, 22 Apr 2022 03:34:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A03D2515B0; Fri, 22 Apr 2022 00:32:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 50547B82A89; Fri, 22 Apr 2022 07:32:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4AD7C385A4; Fri, 22 Apr 2022 07:31:59 +0000 (UTC) Message-ID: <43bba7a4-4eae-9e36-a1ae-60e3ffe30491@xs4all.nl> Date: Fri, 22 Apr 2022 09:31:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v3 11/24] media: v4l2: Reorder field reflist Content-Language: en-US To: Nicolas Dufresne , Mauro Carvalho Chehab Cc: kernel@collabora.com, linux-kernel@vger.kernel.org, Sebastian Fricke , linux-media@vger.kernel.org References: <20220405204426.259074-1-nicolas.dufresne@collabora.com> <20220405204426.259074-12-nicolas.dufresne@collabora.com> From: Hans Verkuil In-Reply-To: <20220405204426.259074-12-nicolas.dufresne@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/04/2022 22:44, Nicolas Dufresne wrote: > As per spec, the field reflist requires interleaving top and bottom > field in a specific way that does not fit inside the sort operation. > The process consist of alternating references parity, starting with > a reference of the same parity as the current picture. This > processs is done twice, once for short term references and a second > time for the long term references. > > Signed-off-by: Nicolas Dufresne > Reviewed-by: Sebastian Fricke > --- > drivers/media/v4l2-core/v4l2-h264.c | 42 +++++++++++++++++++++++++++++ > 1 file changed, 42 insertions(+) > > diff --git a/drivers/media/v4l2-core/v4l2-h264.c b/drivers/media/v4l2-core/v4l2-h264.c > index 7e1eba03099a..d2d1f3bed7e8 100644 > --- a/drivers/media/v4l2-core/v4l2-h264.c > +++ b/drivers/media/v4l2-core/v4l2-h264.c > @@ -244,6 +244,40 @@ static int v4l2_h264_b1_ref_list_cmp(const void *ptra, const void *ptrb, > return poca < pocb ? -1 : 1; > } > > +/* > + * The references need to be reordered so that references are alternating > + * between top and bottom field references starting with the current picture > + * parity. This has to be * done for short term and long term references ^ Spurious *. Regards, Hans > + * separately. > + */ > +static void reorder_field_reflist(const struct v4l2_h264_reflist_builder *b, > + struct v4l2_h264_reference *reflist) > +{ > + struct v4l2_h264_reference tmplist[V4L2_H264_REF_LIST_LEN]; > + u8 lt, i = 0, j = 0, k = 0; > + > + memcpy(tmplist, reflist, sizeof(tmplist[0]) * b->num_valid); > + > + for (lt = 0; lt <= 1; lt++) { > + do { > + for (; i < b->num_valid && b->refs[tmplist[i].index].longterm == lt; i++) { > + if (tmplist[i].fields == b->cur_pic_fields) { > + reflist[k++] = tmplist[i++]; > + break; > + } > + } > + > + for (; j < b->num_valid && b->refs[tmplist[j].index].longterm == lt; j++) { > + if (tmplist[j].fields != b->cur_pic_fields) { > + reflist[k++] = tmplist[j++]; > + break; > + } > + } > + } while ((i < b->num_valid && b->refs[tmplist[i].index].longterm == lt) || > + (j < b->num_valid && b->refs[tmplist[j].index].longterm == lt)); > + } > +} > + > static char ref_type_to_char (u8 ref_type) > { > switch (ref_type) { > @@ -346,6 +380,9 @@ v4l2_h264_build_p_ref_list(const struct v4l2_h264_reflist_builder *builder, > sort_r(reflist, builder->num_valid, sizeof(*reflist), > v4l2_h264_p_ref_list_cmp, NULL, builder); > > + if (builder->cur_pic_fields != V4L2_H264_FRAME_REF) > + reorder_field_reflist(builder, reflist); > + > print_ref_list_p(builder, reflist); > } > EXPORT_SYMBOL_GPL(v4l2_h264_build_p_ref_list); > @@ -379,6 +416,11 @@ v4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder, > sort_r(b1_reflist, builder->num_valid, sizeof(*b1_reflist), > v4l2_h264_b1_ref_list_cmp, NULL, builder); > > + if (builder->cur_pic_fields != V4L2_H264_FRAME_REF) { > + reorder_field_reflist(builder, b0_reflist); > + reorder_field_reflist(builder, b1_reflist); > + } > + > if (builder->num_valid > 1 && > !memcmp(b1_reflist, b0_reflist, builder->num_valid)) > swap(b1_reflist[0], b1_reflist[1]);