Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp220342ima; Tue, 5 Feb 2019 21:52:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IYgivB+Gl8BmZyizVMdEqfw84GgFUlHNfz37InBq/Na8KbVbJQAzG7geuTEl/QeTFcV4qIk X-Received: by 2002:a17:902:2a26:: with SMTP id i35mr5323908plb.321.1549432327028; Tue, 05 Feb 2019 21:52:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549432327; cv=none; d=google.com; s=arc-20160816; b=0JS1WYszHU7KIvPFoOqP5jWpc4Q5USI8KHoMZqFoKlzTTaU9VbkVPfZF6xnYfBV2FZ +XgyF9P+UZMEHbNAiPNwKzIEwnUy2KfYHYKetYi7IjU/HJtCSppabd5TtiPpA+Dh07fO Dz4RhAHeVDlmV/0hqXlDSsV9BNyg461A0YBTZ3NfUsah7B920KnJbX9Hz1cZTItzBNCc 6SWkWoNruIaWMeBpAjx+IUmvuXnpTJNzvRYwV7p8zEpuLZB8rLznYqRlOXkQJnp+ymL7 EyPat+BYfgsorRueg6dvoX655+dFLvCtte9Ru6mVjnyDmMt5mfzZP7GJvADAx82nZeye TOHQ== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=GzL1/yoVnlK9gzmhGqxtVB2GrivOTPBo3lckvKCTeZ8=; b=qM6iOp1Pg8JTVH0TRT2roWn1y1hrC/+15IRTvPAEzbjjdfykFWlmsz/Bq2MWeerFbQ nsYI5fBcmypNZPAUV4ObHrn6vsw4V+U0JU4v7V8EIDXDc4nIrKidqvma5Nz51WdtDPCG bgoVwvh3Sj6dTSBEPjwvuV87fdA67mOzbuyCwOn0NKxuRebcCMfVPexdFWy72CdZLSkv NchETYdleThKdSMj0QKu7pNYTr2r7mOzB7KwH+SmIe3YjxaAXoTsww4BMOQI6mRzCs9z LoIEoEEYWdz3zir2yQYdE+Xi9dCHxO4nxH87faG9N1+AiFVrf0uRhFYS+yEEzWAeYVA4 NZqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JjgzroOf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e192si5239141pfc.28.2019.02.05.21.51.16; Tue, 05 Feb 2019 21:52:07 -0800 (PST) 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; dkim=pass header.i=@chromium.org header.s=google header.b=JjgzroOf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727103AbfBFFgI (ORCPT + 99 others); Wed, 6 Feb 2019 00:36:08 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:36872 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725897AbfBFFgI (ORCPT ); Wed, 6 Feb 2019 00:36:08 -0500 Received: by mail-ot1-f66.google.com with SMTP id s13so10019403otq.4 for ; Tue, 05 Feb 2019 21:36:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=GzL1/yoVnlK9gzmhGqxtVB2GrivOTPBo3lckvKCTeZ8=; b=JjgzroOfUjmMNmeYVUeD9IDXmZ6HWFiyFh42PinbNTGsYAR2msHrPRHjRDI1fyMan8 FYRlBwB+RLsBBSocMRZLRYq8+97zbth9eq85ONHdzarotXDFQ29cvLCU7cuIbSlIskhV ZpfRAleQJaOY7P3Vyds9QEvnMdQ9TyalxkOwI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=GzL1/yoVnlK9gzmhGqxtVB2GrivOTPBo3lckvKCTeZ8=; b=KE7Gh3RowQxmWQ7+FLq2KDAR5eAVotkelbpXIN/qhUvDzjRTvyUCjBL/tBZftUlA3m DIQiI5HSmme5/ZVND4UGLKSoybgZeBI9Yu62Dw20mNxcJAlYNsw1T01RGak3wWcj3SUR uLHzJcLLQuuDkoC+NUA3L5oamyzdkoEdwM+oFQHl+JaeNnjyvdD2Yv8Op2Fz/j2itCSa 2iXkehu6v9D9UcT9tX8t0lBPTgykE3smzKEoQhz5EdKjrE0pIuJHC6y75nUfmOIygk4z epmyxC+EB3v5qFadz6UpTujo7ywmJ4wyJKlh+KRvir95vhrIYV3x1yragHjX5X+Yq2Ti nUqA== X-Gm-Message-State: AHQUAuae1pu9eLhLekbU0ZlWF5SvZvwhaPS2RYmKvJWKq1be1HhwPtpa 1IuzuAE94fJz3qF7NucTAWbi9Ed3kNhvuQ== X-Received: by 2002:a9d:2184:: with SMTP id s4mr4985519otb.46.1549431366993; Tue, 05 Feb 2019 21:36:06 -0800 (PST) Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com. [209.85.210.46]) by smtp.gmail.com with ESMTPSA id 102sm9407759otj.65.2019.02.05.21.36.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Feb 2019 21:36:04 -0800 (PST) Received: by mail-ot1-f46.google.com with SMTP id u16so9977781otk.8 for ; Tue, 05 Feb 2019 21:36:04 -0800 (PST) X-Received: by 2002:a54:468b:: with SMTP id k11mr1698100oic.346.1549431363551; Tue, 05 Feb 2019 21:36:03 -0800 (PST) MIME-Version: 1.0 References: <20181022144901.113852-1-tfiga@chromium.org> <20181022144901.113852-2-tfiga@chromium.org> <9b7c1385-d482-6e92-2222-2daa835dbc91@xs4all.nl> <3ea3bf5bf9904ce877142c41f595207752172d27.camel@ndufresne.ca> In-Reply-To: From: Tomasz Figa Date: Wed, 6 Feb 2019 14:35:51 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] media: docs-rst: Document memory-to-memory video decoder interface To: Nicolas Dufresne Cc: Hans Verkuil , Linux Media Mailing List , Linux Kernel Mailing List , Mauro Carvalho Chehab , Pawel Osciak , Alexandre Courbot , Kamil Debski , Andrzej Hajda , Kyungmin Park , Jeongtae Park , Philipp Zabel , =?UTF-8?B?VGlmZmFueSBMaW4gKOael+aFp+ePiik=?= , =?UTF-8?B?QW5kcmV3LUNUIENoZW4gKOmZs+aZuui/qik=?= , Stanimir Varbanov , Todor Tomov , Paul Kocialkowski , Laurent Pinchart , dave.stevenson@raspberrypi.org, Ezequiel Garcia , Maxime Jourdan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 30, 2019 at 1:02 PM Nicolas Dufresne wro= te: > > Le vendredi 25 janvier 2019 =C3=A0 12:27 +0900, Tomasz Figa a =C3=A9crit = : > > On Fri, Jan 25, 2019 at 4:55 AM Nicolas Dufresne = wrote: > > > Le jeudi 24 janvier 2019 =C3=A0 18:06 +0900, Tomasz Figa a =C3=A9crit= : > > > > > Actually I just realized the last point might not even be achieva= ble > > > > > for some of the decoders (s5p-mfc, mtk-vcodec), as they don't rep= ort > > > > > which frame originates from which bitstream buffer and the driver= just > > > > > picks the most recently consumed OUTPUT buffer to copy the timest= amp > > > > > from. (s5p-mfc actually "forgets" to set the timestamp in some ca= ses > > > > > too...) > > > > > > > > > > I need to think a bit more about this. > > > > > > > > Actually I misread the code. Both s5p-mfc and mtk-vcodec seem to > > > > correctly match the buffers. > > > > > > Ok good, since otherwise it would have been a regression in MFC drive= r. > > > This timestamp passing thing could in theory be made optional though, > > > it lives under some COPY_TIMESTAMP kind of flag. What that means thou= gh > > > is that a driver without such a capability would need to signal dropp= ed > > > frames using some other mean. > > > > > > In userspace, the main use is to match the produced frame against a > > > userspace specific list of frames. At least this seems to be the case > > > in Gst and Chromium, since the userspace list contains a superset of > > > the metadata found in the v4l2_buffer. > > > > > > Now, using the produced timestamp, userspace can deduce frame that th= e > > > driver should have produced but didn't (could be a deadline case code= c, > > > or simply the frames where corrupted). It's quite normal for a codec = to > > > just keep parsing until it finally find something it can decode. > > > > > > That's at least one way to do it, but there is other possible > > > mechanism. The sequence number could be used, or even producing buffe= rs > > > with the ERROR flag set. What matters is just to give userspace a way > > > to clear these frames, which would simply grow userspace memory usage > > > over time. > > > > Is it just me or we were missing some consistent error handling then? > > > > I feel like the drivers should definitely return the bitstream buffers > > with the ERROR flag, if there is a decode failure of data in the > > buffer. Still, that could become more complicated if there is more > > than 1 frame in that piece of bitstream, but only 1 frame is corrupted > > (or whatever). > > I agree, but it might be more difficult then it looks (even FFMPEG does > not do that). I believe the code that is processing the bitstream in > stateful codecs is mostly unrelated from the code actually doing the > decoding. So what might happen is that the decoding part will never > actually allocate a buffer for the skipped / corrupted part of the > bitstream. Also, the notion of a skipped frame is not always evident in > when parsing H264 or HEVC NALs. There is still a full page of text just > to explain how to detect that start of a new frame. Right. I don't think we can guarantee that we can always correlate the errors with exact buffers and so I phrased the paragraph about errors in v3 in a bit more conservative way: See the snapshot hosted by Hans (thanks!): https://hverkuil.home.xs4all.nl/codec-api/uapi/v4l/dev-decoder.html#decodin= g > > Yet, it would be interesting to study the firmwares we have and see > what they provide that would help making decode errors more explicit. > Agreed. > > > > Another case is when the bitstream, even if corrupted, is still enough > > to produce some output. My intuition tells me that such CAPTURE buffer > > should be then returned with the ERROR flag. That wouldn't still be > > enough for any more sophisticated userspace error concealment, but > > could still let the userspace know to perhaps drop the frame. > > You mean if a frame was concealed (typically the frame was decoded from > a closed by reference instead of the expected reference). That is > something signalled by FFPEG. We should document this possibility. I > actually have something implemented in GStreamer. Basically if we have > the ERROR flag with a payload size smaller then expected, I drop the > frame and produce a drop event message, while if I have a frame with > ERROR flag but of the right payload size, I assume it is corrupted, and > simply flag it as corrupted, leaving to the application the decision to > display it or not. This is a case that used to happen with some UVC > cameras (though some have been fixed, and the UVC camera should drop > smaller payload size buffers now). I think it's a behavior that makes the most sense indeed. Technically one could also consider the case of 0 < bytesused < sizeimage, which could mean that only a part of the frame is in the buffer. An application could try to blend it with previous frame using some concealing algorithms. I haven't seen an app that could do such thing, though. Best regards, Tomasz