From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTP id 2555C40FE9
	for <ffmpegdev@gitmailbox.com>; Sun,  2 Jan 2022 16:41:18 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C700668B11E;
	Sun,  2 Jan 2022 18:41:15 +0200 (EET)
Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com
 [209.85.219.45])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7125068B11E
 for <ffmpeg-devel@ffmpeg.org>; Sun,  2 Jan 2022 18:41:09 +0200 (EET)
Received: by mail-qv1-f45.google.com with SMTP id q4so28971482qvh.9
 for <ffmpeg-devel@ffmpeg.org>; Sun, 02 Jan 2022 08:41:09 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=date:from:to:cc:subject:message-id:references:mime-version
 :content-disposition:in-reply-to;
 bh=QpqMJtDxcKAzm09MoIcKS2HRLBT+1L7H/4OrpWA586U=;
 b=eykuboxyendxLc0kpK4o3HDD32djW3++TlESn+HTCE7dqrexix6W9eBTl4bTfsmpnN
 dYTAfsAiYFdlzPmPFojlQyNBFblPLZg5Gb/Iqwl2GXhZZ/NE1XOqcjjjENFi+Yn0Bq+j
 f4auAQy1AUBIcvX375DtVV3X/jCfZstnvK1zJd+Qn7TD52eBF3RqAV68DLF9XcKa+jrF
 0T53bZA3ZmIu7brgfcNteFgEXR9pZ9m7xLd76hH/zcF45skWYcAbvKa9KaCXGmcSiv7J
 Cd4L8w8efnE8gkx7kWFsEE5JI1T8Cz0YBrzRlzo7TrktqqQ6zozjaxmAWtWzvMqtKcGp
 dFKQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:date:from:to:cc:subject:message-id:references
 :mime-version:content-disposition:in-reply-to;
 bh=QpqMJtDxcKAzm09MoIcKS2HRLBT+1L7H/4OrpWA586U=;
 b=Mg8okQeWEcgeIXRntFKAM7A3jDkqthubiR8fZcqtNOxCygqtcAhBPTah9JDEMiMDzS
 GjKbGBKHLtTZiD9CeCbngDva/OZHpbdapjFE2SSU7wJgEGSrT6C/Z/qk4a0vwXqtHhpv
 mk5NhIACyho7mz3y8+YbXvjKZ2vAT2qQ2PLFLy480yoKBDt6pVLaSndif31evRn70mAE
 oNEqdFfM5pE8hhadH3lgvVDaABzIcLLq+CfkggV5GdNdpJn4sT6xgNDfCN+jd1+Snc2Z
 no6xj4W+hwnovhQj1wXB5g4WbK54AQ7+0RebBIUmkf5KeN+mjogsl9JxAbgtKkuujFJt
 FDEQ==
X-Gm-Message-State: AOAM53326dLdUZhUk4rZEi/tT6iBQQY6f8ThKBoe7WX5bYB0ntOFWp2v
 gFHzxIFr5muRDQvJXghflrXMfANwxOo=
X-Google-Smtp-Source: ABdhPJyAHM1Yi0aTxFUa3JMEvE8syvscGK+v7m/xPL81/Uo91/9xYC1UJLThKE3Uf2g3pyD9Oma7QA==
X-Received: by 2002:a05:6214:daf:: with SMTP id
 h15mr38855962qvh.9.1641141667693; 
 Sun, 02 Jan 2022 08:41:07 -0800 (PST)
Received: from jackie (pool-108-20-185-127.bstnma.fios.verizon.net.
 [108.20.185.127])
 by smtp.gmail.com with ESMTPSA id u11sm28124497qtw.29.2022.01.02.08.41.07
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 02 Jan 2022 08:41:07 -0800 (PST)
Date: Sun, 2 Jan 2022 11:41:06 -0500
From: Andriy Gelman <andriy.gelman@gmail.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Message-ID: <20220102164106.ptu4eet7rmwla7bg@jackie>
References: <20210819085533.1174-1-ming.qian@nxp.com>
 <20210819085533.1174-2-ming.qian@nxp.com>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <20210819085533.1174-2-ming.qian@nxp.com>
Subject: Re: [FFmpeg-devel] [PATCH v4 2/3] avcodec/v4l2_context: resume the
 decoding process after source change event received.
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Ming Qian <ming.qian@nxp.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20220102164106.ptu4eet7rmwla7bg@jackie/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

On Thu, 19. Aug 16:55, Ming Qian wrote:
> client need to resume the decoding process
> after it dequeues the source change event.
> no matter what's the return value of v4l2_resolution_changed().
> if the client doesn't resume the decoding process,
> the decoder may keep waiting
> 
> in documentation of v4l2 stateful decoder, we can see the following
> description:
> 	The client must continue the sequence as described below to
> 	continue the decoding process.
> 	1.  Dequeue the source change event.
> 		Important
> 		A source change triggers an implicit decoder drain,
> 		similar to the explicit Drain sequence. The decoder is
> 		stopped after it completes. The decoding process must be
> 		resumed with either a pair of calls to
> 		VIDIOC_STREAMOFF() and VIDIOC_STREAMON() on the CAPTURE
> 		queue, or a call to VIDIOC_DECODER_CMD() with the
> 		V4L2_DEC_CMD_START command.
> 	2.  Continue with the Capture Setup sequence.

Please also add that this fixes decoding of
https://streams.videolan.org/ffmpeg/incoming/720p60.mp4 on RPi4.

> 
> Signed-off-by: Ming Qian <ming.qian@nxp.com>
> ---
>  libavcodec/v4l2_context.c | 52 ++++++++++++++++++++++++---------------
>  1 file changed, 32 insertions(+), 20 deletions(-)
> 
> diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
> index dda5157698c3..b08f0015c2e5 100644
> --- a/libavcodec/v4l2_context.c
> +++ b/libavcodec/v4l2_context.c
> @@ -153,6 +153,21 @@ static inline void v4l2_save_to_context(V4L2Context* ctx, struct v4l2_format_upd
>      }
>  }
>  
> +static int v4l2_start_decode(V4L2Context *ctx)
> +{
> +    struct v4l2_decoder_cmd cmd = {
> +        .cmd = V4L2_DEC_CMD_START,
> +        .flags = 0,
> +    };
> +    int ret;
> +
> +    ret = ioctl(ctx_to_m2mctx(ctx)->fd, VIDIOC_DECODER_CMD, &cmd);
> +    if (ret)
> +        return AVERROR(errno);
> +
> +    return 0;
> +}
> +
>  /**
>   * handle resolution change event and end of stream event
>   * returns 1 if reinit was successful, negative if it failed
> @@ -163,7 +178,7 @@ static int v4l2_handle_event(V4L2Context *ctx)
>      V4L2m2mContext *s = ctx_to_m2mctx(ctx);
>      struct v4l2_format cap_fmt = s->capture.format;
>      struct v4l2_event evt = { 0 };
> -    int reinit, ret;
> +    int ret;
>  
>      ret = ioctl(s->fd, VIDIOC_DQEVENT, &evt);
>      if (ret < 0) {
> @@ -185,35 +200,29 @@ static int v4l2_handle_event(V4L2Context *ctx)
>          return 0;
>      }
>  
> -    reinit = v4l2_resolution_changed(&s->capture, &cap_fmt);
> -    if (reinit) {
> +    if (v4l2_resolution_changed(&s->capture, &cap_fmt)) {
>          s->capture.height = v4l2_get_height(&cap_fmt);
>          s->capture.width = v4l2_get_width(&cap_fmt);
>          s->capture.sample_aspect_ratio = v4l2_get_sar(&s->capture);

> +    } else {
> +        v4l2_start_decode(ctx);
> +        return 0;
>      }

You can minimize the diff just by adding this part and the
definition for v4l2_start_decode(). Then have a separate commit that cleans up
and removes the reinit variable.

>  
> -    if (reinit)
> -        s->reinit = 1;
> +    s->reinit = 1;
>  
> -    if (reinit) {
> -        if (s->avctx)
> -            ret = ff_set_dimensions(s->avctx, s->capture.width, s->capture.height);
> -        if (ret < 0)
> -            av_log(logger(ctx), AV_LOG_WARNING, "update avcodec height and width\n");
> +    if (s->avctx)
> +        ret = ff_set_dimensions(s->avctx, s->capture.width, s->capture.height);
> +    if (ret < 0)
> +        av_log(logger(ctx), AV_LOG_WARNING, "update avcodec height and width\n");
>  
> -        ret = ff_v4l2_m2m_codec_reinit(s);
> -        if (ret) {
> -            av_log(logger(ctx), AV_LOG_ERROR, "v4l2_m2m_codec_reinit\n");
> -            return AVERROR(EINVAL);
> -        }
> -        goto reinit_run;
> +    ret = ff_v4l2_m2m_codec_reinit(s);
> +    if (ret) {
> +        av_log(logger(ctx), AV_LOG_ERROR, "v4l2_m2m_codec_reinit\n");
> +        return AVERROR(EINVAL);
>      }
>  
> -    /* dummy event received */
> -    return 0;
> -
>      /* reinit executed */
> -reinit_run:
>      return 1;
>  }
>  
> @@ -551,6 +560,9 @@ int ff_v4l2_context_set_status(V4L2Context* ctx, uint32_t cmd)
>      int type = ctx->type;
>      int ret;

>  
> +    if (ctx->streamon == (cmd == VIDIOC_STREAMON))
> +        return 0;
> +

This change looks unrelated.

>      ret = ioctl(ctx_to_m2mctx(ctx)->fd, cmd, &type);
>      if (ret < 0)
>          return AVERROR(errno);

Thanks,
-- 
Andriy
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".