Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp378730ima; Wed, 24 Oct 2018 02:53:24 -0700 (PDT) X-Google-Smtp-Source: AJdET5c7PT1YOu/UU7oPuVTONVA5b6lkijq1IYP8vyBGrVpniHGFdZkCGCxu0zKP6hlHUfPnddgq X-Received: by 2002:a63:2c8a:: with SMTP id s132-v6mr1835249pgs.73.1540374804020; Wed, 24 Oct 2018 02:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540374803; cv=none; d=google.com; s=arc-20160816; b=xg1YrOqUezuEzlHXn+c2GwWQvN426Ii5tz0jWqrx5RALVP58BF5FUyO16bn8Q83ip2 ili0WcsHLPjp/9omXP7uZqXzGUSDxLskODbqwWj6hr5/LxKNhxFKTCvGqSBYqn391HqE x8ftRcEZTJ+ZuEG9vGezfhewVHOr1dsPnTijIWRJo5PAcFNs9VWd9JfN+w8jXBQs/pPX 42XKNdqZDLtTJmDqJX/ZIunDYOv/FY8BTYaD9D9qUE3LzG+q2uZaIKPXAsy9NjaVhQQE 942cBNhoobH6ShDfW7MssZ0xlf5Vte8bbIKbuIblwcA9IBDsCQ7VzIxB/lBFTq4/Thml +YdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Q7TzIqVAmDH4oNP1d8vwfz6q0EvFg2xkljZBwXyLQXo=; b=oRwlt7lx7Hwt0ZYk6ShQBZEv5ZkySMWZkTUXfzeiMYIDRMu1LYAxLObvMN2poaKrFJ kCB5YhwsU6FNqXSAFYhIh/HDRpFLClgk6cl73EZmdhRASTfMf2aG6tD0ABaWhO/vWuTH Fwu5BuF7NFcrCKV+Bz5APGHbJwiGlXwko4Q/VvefyS9Y46fpqpXfy+R1i2vDycgc3vga z2hRiReWxypkDQ5Z8T9pLc937dtplNSNQs8XY8YUOvzMj7Q8ZifJBeUBYxb90EpNEluE hB8SaZizT8YY3UbuWOxU5OgDhZSOj0BJfrM0A76tnyR9SYVyA6t5yIQAq7hPbqDsOaer I34g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p20-v6si4132940pgm.192.2018.10.24.02.53.08; Wed, 24 Oct 2018 02:53:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727149AbeJXSUE (ORCPT + 99 others); Wed, 24 Oct 2018 14:20:04 -0400 Received: from lb3-smtp-cloud9.xs4all.net ([194.109.24.30]:59080 "EHLO lb3-smtp-cloud9.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726301AbeJXSUE (ORCPT ); Wed, 24 Oct 2018 14:20:04 -0400 Received: from [10.101.224.151] ([185.7.230.215]) by smtp-cloud9.xs4all.net with ESMTPA id FFq3g9j1TSskCFFq8gXDhF; Wed, 24 Oct 2018 11:52:37 +0200 Subject: Re: [RFC] Stateless codecs: how to refer to reference frames To: Alexandre Courbot Cc: Tomasz Figa , Paul Kocialkowski , Mauro Carvalho Chehab , Pawel Osciak , Linux Media Mailing List , LKML References: <20181019080928.208446-1-acourbot@chromium.org> From: Hans Verkuil Message-ID: <515520e4-51d6-e4bb-138a-84453ea6e189@xs4all.nl> Date: Wed, 24 Oct 2018 10:52:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfBUe66sk+kZOUBWXzWFoJPJlmyXDme7Gdft76fzxZ6sgASHM862q2looN/5oZy0wMt0M+FWSeSoHaJDUaBWgysR65r+k7cHsMiSYIp9W6+1JCrd6IIO1 OzxhtLqmCRMEQBILNLJmbvWoBdJqpu8PyCtT44/vhA468/c8TlygKogBOBsJZEKsA/jZp7mvPk+8zfVez2hbHIcYl/UU9qIExjwEkCb47XM/9k4xjg1H/Hzk Y1DsL8x1RqwKajz/YIE8y4GVRVqLymWcxPmnSg8AYYXZvpwDQWxb1RsFMto7C+sCNKNsiyAqKvnSXx9J2m3HW2DnTAu3AG6YVuIaXtDc5wSb6qYEPW/Q8Q3m d6KGOhjd1SAKQILNAwjHjrhWi8nQkW249pgpSgfKDAy9zU7J5Iw= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org HI Alexandre, On 10/24/2018 10:16 AM, Alexandre Courbot wrote: > Hi Hans, > > On Fri, Oct 19, 2018 at 6:40 PM Hans Verkuil wrote: >> >> From Alexandre's '[RFC PATCH v3] media: docs-rst: Document m2m stateless >> video decoder interface': >> >> On 10/19/18 10:09, Alexandre Courbot wrote: >>> Two points being currently discussed have not been changed in this >>> revision due to lack of better idea. Of course this is open to change: >> >> >> >>> * The other hot topic is the use of capture buffer indexes in order to >>> reference frames. I understand the concerns, but I doesn't seem like >>> we have come with a better proposal so far - and since capture buffers >>> are essentially well, frames, using their buffer index to directly >>> reference them doesn't sound too inappropriate to me. There is also >>> the restriction that drivers must return capture buffers in queue >>> order. Do we have any concrete example where this scenario would not >>> work? >> >> I'll stick to decoders in describing the issue. Stateless encoders probably >> do not have this issue. >> >> To recap: the application provides a buffer with compressed data to the >> decoder. After the request is finished the application can dequeue the >> decompressed frame from the capture queue. >> >> In order to decompress the decoder needs to access previously decoded >> reference frames. The request passed to the decoder contained state >> information containing the buffer index (or indices) of capture buffers >> that contain the reference frame(s). >> >> This approach puts restrictions on the framework and the application: >> >> 1) It assumes that the application can predict the capture indices. >> This works as long as there is a simple relationship between the >> buffer passed to the decoder and the buffer you get back. >> >> But that may not be true for future codecs. And what if one buffer >> produces multiple capture buffers? (E.g. if you want to get back >> decompressed slices instead of full frames to reduce output latency). >> >> This API should be designed to be future-proof (within reason of course), >> and I am not at all convinced that future codecs will be just as easy >> to predict. >> >> 2) It assumes that neither drivers nor applications mess with the buffers. >> One case that might happen today is if the DMA fails and a buffer is >> returned marked ERROR and the DMA is retried with the next buffer. There >> is nothing in the spec that prevents you from doing that, but it will mess >> up the capture index numbering. And does the application always know in >> what order capture buffers are queued? Perhaps there are two threads: one >> queueing buffers with compressed data, and the other dequeueing the >> decompressed buffers, and they are running mostly independently. >> >> >> I believe that assuming that you can always predict the indices of the >> capture queue is dangerous and asking for problems in the future. >> >> >> I am very much in favor of using a dedicated cookie. The application sets >> it for the compressed buffer and the driver copies it to the uncompressed >> capture buffer. It keeps track of the association between capture index >> and cookie. If a compressed buffer decompresses into multiple capture >> buffers, then they will all be associated with the same cookie, so >> that simplifies how you refer to reference frames if they are split >> over multiple buffers. >> >> The codec controls refer to reference frames by cookie(s). > > So as discussed yesterday, I understand your issue with using buffer > indexes. The cookie idea sounds like it could work, but I'm afraid you > could still run into issues when you don't have buffer symmetry. > > For instance, imagine that the compressed buffer contains 2 frames > worth of data. In this case, the 2 dequeued capture buffers would > carry the same cookie, making it impossible to reference either frame > unambiguously. But this is a stateless codec, so each compressed buffer contains only one frame. That's the responsibility of the bitstream parser to ensure that. The whole idea of the stateless codec is that you supply only one frame at a time to the codec. If someone indeed puts multiple frames into a single buffer, then the behavior is likely undefined. Does anyone have any idea what would happen with the cedrus driver in that case? This is actually a good test. Anyway, I would consider this an application bug. Garbage in, garbage out. > > There may also be a similar, yet simpler solution already in place > that we can use. The v4l2_buffer structure contains a "sequence" > member, that is supposed to sequentially count the delivered frames. The sequence field suffers from exactly the same problems as the buffer index: it doesn't work if one compressed frame results in multiple capture buffers (one for each slice), since the sequence number will be increased for each capture buffer. Also if capture buffers are marked as error for some reason, the sequence number is also incremented for that buffer, again making it impossible to predict in userspace what the sequence counter will be. > What if we used this field in the same spirit as your cookie? > Userspace would just need to keep count of the number of frames sent > to the driver in order to accurately predict which sequence number a > given frame is going to carry. Then the driver/framework just needs to > associate the last sequence number of each buffer so it can find the > reference frames, and we have an way to refer every frame. Would that > work? We would need to make sure that error buffers are returned for > every frame that fails (otherwise the counter could deviate between > kernel and user-space), but if we take care of that it seems to me > that this would stand, while being simpler and taking advantage of an > already existing field. > So no, this wouldn't work. I don't want this 'accurately predict' method: it is inherently fragile. Regards, Hans