Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp960056iob; Fri, 13 May 2022 17:46:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9bdaE91MbIoMEjmMGZAxuKu9+oyX+glwbaZlhRUaZLVBoZJjHVfvmMDQnohAlynRk3q1y X-Received: by 2002:a05:6000:1f0e:b0:20c:4fde:7e20 with SMTP id bv14-20020a0560001f0e00b0020c4fde7e20mr5820841wrb.532.1652489211741; Fri, 13 May 2022 17:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652489211; cv=none; d=google.com; s=arc-20160816; b=y5oShjgP9H3pCgcZD5P1paaar5ruW+E6UfkPNY6Ct7DVNUj19g/OI0N6RxtuMHRpPQ +WC3uBspZ7Hw2/uR7Qod2LCF5bw/V+JcMgA8QjYCSgKuT9D4vZHi2gnbJxNMOPlPFRwA IchVuBj+CM5emy5oayotEqwW8QB7r4PC9nHXKG8+NsY6spA1H/vKLDXypSphOT5iNiW4 4iBQbJ3SNEh5OiHJi3y89vbvdSDakHmCIfBlSzGTKhk9vyVhP4J777EgOjC03lAeOsKJ dK0B448QP9HG/F65Apv1+OYvoH3OXcPSVDzSzNlQW30xjS/mLcxzNo9zBfIMVjcD02d7 tySg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eq85JgnGyhFng6oSFA5my8ghAbj+0A8Y7mhwbjvVUTA=; b=Ck3XT5vZyvwlOHzxjnF1liQwVfrV2eZ2ejzYhDDwgNN3EjBOKJ4BUqmlAsnhbj5X+C 2eXbi4GeZy/G9NPhfEOzgbSodk3VXCZulAKWM5k1Ft+jjMFW3pIpXB8ExXk11wbpxrYz K/+bo08swrEDuk034kZUwRq9hIdMP1tI0KjSecbbq2sl2LJkzTWUZ9TyiZ597ef9rZ2P 6rbmZzoI9X8b7UVtOrdQQA+6e9ENH+9DSNWI4X0Cyv3p3jpNj+38ehkZNgrEWR6/O+oy E/IB4xL0rOj1fWFcB6YrnHLRnVD+WFlKg78qIlXpEcxxigdn3rLOg4WS71qCsDZWV0I5 cMPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=gmo23fQj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t12-20020adff04c000000b00205dc88c0ffsi3387359wro.148.2022.05.13.17.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 17:46:51 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=gmo23fQj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B1E01331CD0; Fri, 13 May 2022 16:25:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384316AbiEMUbu (ORCPT + 99 others); Fri, 13 May 2022 16:31:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384378AbiEMUab (ORCPT ); Fri, 13 May 2022 16:30:31 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16ED777F2A; Fri, 13 May 2022 13:29:54 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: nicolas) with ESMTPSA id 3BABA1F46487 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1652473784; bh=Vra7LsHrOdEcIBqrM9/POp0obwO6NMVDgAU9FK3KQ+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gmo23fQjBPdo8JI2PkxYjwweogzgLdG9a6DK5ZGB7V0mALSFfrt6uM7yGvSvWQN+Q wKLB4aEsWy8x+sa0pHUzht0n0LKknstj8zHIpLKVjQ+4RUwm7PYUUHrLLSBxIUa/Ej 1Osb0d5oxmLWR+FNXMuK620GHgPilmibWDp1bBOPZKU2JYYDMXK+VGl5J/3GBXgokd CbT49FvIEIIvU6D1rUquPOfLAXPBremmRGaIBDF9V8mo5H1/XBYoxcPZIYdqbeIp61 eaMNmj3+eMp+NHCRLdF9PUIBgbAkukPwo3WYXTZfVBbYlKKqlTlDPSm5kYK0mKqG+T yBnN7/oW1yq2Q== From: Nicolas Dufresne To: Mauro Carvalho Chehab Cc: nicolas@ndufresne.ca, linux-media@vger.kernel.org, Sebastian Fricke , Hans Verkuil , linux-kernel@vger.kernel.org Subject: [PATCH v5 07/20] media: v4l2: Reorder field reflist Date: Fri, 13 May 2022 16:29:09 -0400 Message-Id: <20220513202922.13846-8-nicolas.dufresne@collabora.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220513202922.13846-1-nicolas.dufresne@collabora.com> References: <20220513202922.13846-1-nicolas.dufresne@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=no 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 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 Signed-off-by: Hans Verkuil --- 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 fe215035d9e8..72bd64f65198 100644 --- a/drivers/media/v4l2-core/v4l2-h264.c +++ b/drivers/media/v4l2-core/v4l2-h264.c @@ -250,6 +250,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 + * 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) { @@ -360,6 +394,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); @@ -393,6 +430,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]); -- 2.34.3