Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp506115imm; Wed, 8 Aug 2018 00:21:45 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyMH6vVdlqIJ65Gp1E71fTjwGsMvp7qHqYerm91MhWS+ZhBQ0RSp4pJtsxkJbaeLzNLBtsO X-Received: by 2002:a62:569c:: with SMTP id h28-v6mr1644560pfj.201.1533712905438; Wed, 08 Aug 2018 00:21:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533712905; cv=none; d=google.com; s=arc-20160816; b=RIeDNK3H9N+MzuJCRGvmjjdzJv/ltZt50bU5QaxqwQegmFpXPN8f/h4a/7474uPIM+ Ss8awFwzRQAV5oQEpvDAfx9O1FVriTb7UznhF0ukQ8G0IgV/oAntW7P/h/bnKYLkbrXb iwgRBHmXeJcyCS8s1/MULAwWPkOJR+XsuZwBXDyA7VUTR91Z6EY5J9GRRMM6FGXJyz43 qAk2Aijtx8us5aEgkY1qlEbBqzx8SGh9bzOxYorDA1udiBKtIZf+K8nF88coqDfBEhGh +KAgeI6dX2fXntfclymV765iSetv31KdiRoyU9ib6qzwvxY1o9RQLhYaUhLxoMUMWSVp Mrew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:arc-authentication-results; bh=czEHjLzOXBmQdK8sNq/Exr2qJBtLl0c7TAVDEeQTxPc=; b=SP6kKMDfKq5VL8+ZRB3An/ih+nHRlSIaP+SQ+OvVkB4P9UT7cI5CgxICiBhe6F/hZ0 etWYG5jrDECIUhiCL64RljmVJ8F3seihTMZjqT+De5W47JnaRrA/QJofMB88JThx2Avb 5jhHHqDKQB4rlbCVTF2aPWa5cvtCbx/XXmYaDU1kychH8JeHonNhR7oR5I2gwK13XajA K/6zHzfOOA5JXWeot3KxKavJ41pBUC+SglIktzb6PtBKQEr5Plo+IUoMPlWrLILcsIwJ FPh6eXJkjioONH26iM00kOfH43L5+9UX1kBwzo41rBFckp9zw8w5JzvudTNk1j3eptzh 2cqA== 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 1-v6si168901plw.509.2018.08.08.00.21.30; Wed, 08 Aug 2018 00:21:45 -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 S1727052AbeHHJhi (ORCPT + 99 others); Wed, 8 Aug 2018 05:37:38 -0400 Received: from smtp09.smtpout.orange.fr ([80.12.242.131]:28874 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbeHHJhi (ORCPT ); Wed, 8 Aug 2018 05:37:38 -0400 Received: from mail-qt0-f178.google.com ([209.85.216.178]) by mwinf5d44 with ME id LXKD1y00A3rXJPD03XKD2y; Wed, 08 Aug 2018 09:19:14 +0200 X-ME-Helo: mail-qt0-f178.google.com X-ME-Auth: bWF4aS5qb3VyZGFuQHdhbmFkb28uZnI= X-ME-Date: Wed, 08 Aug 2018 09:19:14 +0200 X-ME-IP: 209.85.216.178 Received: by mail-qt0-f178.google.com with SMTP id n6-v6so1356785qtl.4; Wed, 08 Aug 2018 00:19:13 -0700 (PDT) X-Gm-Message-State: AOUpUlHp0KbgH2Zr/Stl5oCp1E0Vp0+I4WwvDcnDsSdRBIK6sVHTwsHD HB2uHsIaYk3ZRTnmD1bOrVv+S79wV904t3U31Pw= X-Received: by 2002:aed:3e47:: with SMTP id m7-v6mr1641147qtf.210.1533712753065; Wed, 08 Aug 2018 00:19:13 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:aed:278a:0:0:0:0:0 with HTTP; Wed, 8 Aug 2018 00:19:12 -0700 (PDT) In-Reply-To: References: <20180724140621.59624-1-tfiga@chromium.org> <20180724140621.59624-2-tfiga@chromium.org> <37a8faea-a226-2d52-36d4-f9df194623cc@xs4all.nl> From: Maxime Jourdan Date: Wed, 8 Aug 2018 09:19:12 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] media: docs-rst: Document memory-to-memory video decoder interface To: Tomasz Figa Cc: Maxime Jourdan , Hans Verkuil , Linux Media Mailing List , Linux Kernel Mailing List , Stanimir Varbanov , Mauro Carvalho Chehab , Pawel Osciak , Alexandre Courbot , kamil@wypas.org, a.hajda@samsung.com, Kyungmin Park , jtp.park@samsung.com, Philipp Zabel , =?UTF-8?B?VGlmZmFueSBMaW4gKOael+aFp+ePiik=?= , =?UTF-8?B?QW5kcmV3LUNUIENoZW4gKOmZs+aZuui/qik=?= , todor.tomov@linaro.org, nicolas@ndufresne.ca, Paul Kocialkowski , Laurent Pinchart , dave.stevenson@raspberrypi.org, Ezequiel Garcia Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-08-08 5:07 GMT+02:00 Tomasz Figa : > On Wed, Aug 8, 2018 at 4:11 AM Maxime Jourdan wrote: >> >> 2018-08-07 9:13 GMT+02:00 Hans Verkuil : >> > On 07/26/2018 12:20 PM, Tomasz Figa wrote: >> >> Hi Hans, >> >> >> >> On Wed, Jul 25, 2018 at 8:59 PM Hans Verkuil wrote: >> >>>> + >> >>>> +14. Call :c:func:`VIDIOC_STREAMON` to initiate decoding frames. >> >>>> + >> >>>> +Decoding >> >>>> +======== >> >>>> + >> >>>> +This state is reached after a successful initialization sequence. In this >> >>>> +state, client queues and dequeues buffers to both queues via >> >>>> +:c:func:`VIDIOC_QBUF` and :c:func:`VIDIOC_DQBUF`, following standard >> >>>> +semantics. >> >>>> + >> >>>> +Both queues operate independently, following standard behavior of V4L2 >> >>>> +buffer queues and memory-to-memory devices. In addition, the order of >> >>>> +decoded frames dequeued from ``CAPTURE`` queue may differ from the order of >> >>>> +queuing coded frames to ``OUTPUT`` queue, due to properties of selected >> >>>> +coded format, e.g. frame reordering. The client must not assume any direct >> >>>> +relationship between ``CAPTURE`` and ``OUTPUT`` buffers, other than >> >>>> +reported by :c:type:`v4l2_buffer` ``timestamp`` field. >> >>> >> >>> Is there a relationship between capture and output buffers w.r.t. the timestamp >> >>> field? I am not aware that there is one. >> >> >> >> I believe the decoder was expected to copy the timestamp of matching >> >> OUTPUT buffer to respective CAPTURE buffer. Both s5p-mfc and coda seem >> >> to be implementing it this way. I guess it might be a good idea to >> >> specify this more explicitly. >> > >> > What about an output buffer producing multiple capture buffers? Or the case >> > where the encoded bitstream of a frame starts at one output buffer and ends >> > at another? What happens if you have B frames and the order of the capture >> > buffers is different from the output buffers? >> > >> > In other words, for codecs there is no clear 1-to-1 relationship between an >> > output buffer and a capture buffer. And we never defined what the 'copy timestamp' >> > behavior should be in that case or if it even makes sense. >> > >> > Regards, >> > >> > Hans >> >> As it is done right now in userspace (FFmpeg, GStreamer) and most (if >> not all?) drivers, it's a 1:1 between OUTPUT and CAPTURE. The only >> thing that changes is the ordering since OUTPUT buffers are in >> decoding order while CAPTURE buffers are in presentation order. > > If I understood it correctly, there is a feature in VP9 that lets one > frame repeat several times, which would make one OUTPUT buffer produce > multiple CAPTURE buffers. > > Moreover, V4L2_PIX_FMT_H264 is actually defined to be a byte stream, > without any need for framing, and yes, there are drivers that follow > this definition correctly (s5p-mfc and, AFAIR, coda). In that case, > one OUTPUT buffer can have arbitrary amount of bitstream and lead to > multiple CAPTURE frames being produced. I can see from the code and your answer to Hans that in such case, all CAPTURE buffers will share the single OUTPUT timestamp. Does this mean that at the end of the day, userspace disregards the CAPTURE timestamps since you have the display order guarantee ? If so, how do you reconstruct the proper PTS on such buffers ? Do you have them saved from prior demuxing ? >> >> This almost always implies some timestamping kung-fu to match the >> OUTPUT timestamps with the corresponding CAPTURE timestamps. It's >> often done indirectly by the firmware on some platforms (rpi comes to >> mind iirc). > > I don't think there is an upstream driver for it, is there? (If not, > are you aware of any work towards it?) You're right, it's not upstream but it is in a relatively good shape at https://github.com/6by9/linux/commits/rpi-4.14.y-v4l2-codec >> >> The current constructions also imply one video packet per OUTPUT >> buffer. If a video packet is too big to fit in a buffer, FFmpeg will >> crop that packet to the maximum buffer size and will discard the >> remaining packet data. GStreamer will abort the decoding. This is >> unfortunately one of the shortcomings of having fixed-size buffers. >> And if they were to split the packet in multiple buffers, then some >> drivers in their current state wouldn't be able to handle the >> timestamping issues and/or x:1 OUTPUT:CAPTURE buffer numbers. > > In Chromium, we just allocate OUTPUT buffers big enough to be really > unlikely for a single frame not to fit inside [1]. Obviously it's a > waste of memory, for formats which normally have just single frames > inside buffers, but it seems to work in practice. > > [1] https://cs.chromium.org/chromium/src/media/gpu/v4l2/v4l2_video_decode_accelerator.h?rcl=3468d5a59e00bcb2c2e946a30694e6057fd9ab21&l=118 Right. As long as you don't need many OUTPUT buffers it's not that big a deal. [snip] >> > + For hardware known to be mishandling seeks to a non-resume point, >> > + e.g. by returning corrupted decoded frames, the driver must be able >> > + to handle such seeks without a crash or any fatal decode error. >> >> This is unfortunately my case, apart from parsing the bitstream >> manually - which is a no-no -, there is no way to know when I'll be >> writing in an IDR frame to the HW bitstream parser. I think it would >> be much preferable that the client starts sending in an IDR frame for >> sure. > > Most of the hardware, which have upstream drivers, deal with this > correctly and there is existing user space that relies on this, so we > cannot simply add such requirement. However, when sending your driver > upstream, feel free to include a patch that adds a read-only control > that tells the user space that it needs to do seeks to resume points. > Obviously this will work only with user space aware of this > requirement, but I don't think we can do anything better here. > Makes sense >> > + To achieve instantaneous seek, the client may restart streaming on >> > + ``CAPTURE`` queue to discard decoded, but not yet dequeued buffers. >> >> Overall, I think Drain followed by V4L2_DEC_CMD_START is a more >> applicable scenario for seeking. >> Heck, simply starting to queue buffers at the seek - starting with an >> IDR - without doing any kind of streamon/off or cmd_start(stop) will >> do the trick. > > Why do you think so? > > For a seek, as expected by a typical device user, the result should be > discarding anything already queued and just start decoding new frames > as soon as possible. > > Actually, this section doesn't describe any specific sequence, just > possible ways to do a seek using existing primitives. Fair enough Regards, Maxime