raspberrypi / linux

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/
Other
11.23k stars 5.02k forks source link

lost frames/incomplete draining in bcm2835-v4l2-codec.c #5059

Open fduncanh opened 2 years ago

fduncanh commented 2 years ago

Describe the bug

There are two (related?) bugs in driver bcm2835-v4l2-codec.c working with the GStreamer-1.21 (current development) Video4Linux2 plugin where VIDIOC_DQBUF does not dequeue a few frames that were previously successfully queued to the driver by VIDIOC_QBUF. The bugs are associated with Caps renegotiations.

  1. If the initial frame of the h264 bitstream starts with a SPS NAL, a Caps renegotiation is triggered. Frames 0,1,2... are successfully queued by VIDIOC_QBUF in gst_v4l2_allocator_qbuf in the OUTPUT thread (gst_v4l2_video_dec_handle_frame) but only frames x, x+1, x+2 ,... (where x is variable between frame 2 and frame 5, maybe a race condition) are dequeued by VIDIOC_DQBUF in gst_v4l2_allocator_dqbuf in the CAPTURE thread (gst_v4l2_video_dec_loop).

  2. If a midstream frame with a SPS NAL is detected, and triggers CAPS renegotiation, CMD_STOP is sent to the decoder by gst_v4l2_video_dec_finish, and all pending frames should be drained by VIDIOC_DQBUF in gst_v4l2_allocator_dqbuf, but sometimes (not always) the decoder sends V4L2_BUF_FLAG_LAST prematurely, and a few frames are left un-dequeued. With the test video clip provided here, where a number of midstream Caps renegotiations occur, the number of "lost frames" is different in each event (but does not seem to vary each time the video is played, unlike 1.)

This has been discussed (a bit confusedly, on my part) at

https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2518

https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2517

(These suggested GStreamer Merge Requests are cosmetic attempts to reduce the level of warning messages, not to fix the underlying bug which appears to be a bcm2835-v4l2-codec.c driver bug.)

Steps to reproduce the behaviour

Use the latest https://gitlab.freedesktop.org/gstreamer/gstreamer GStreamer code, built with latest meson 0.62.2 and ninja 1.11.0. (On Raspberry Pi OS Bullseye 64bit Lite, some difficulties due to presence of remnants of deprecated dispmanx require meson build -Dgst-plugins-base:gl_winsys=egl to successfully build GStreamer, as the default gl_winsys=auto incorrectly detects dispmanx)

Use the pipeline

#!/bin/sh
gst-launch-1.0 filesrc location=$1 ! video/x-h264 ! h264parse ! capssetter caps="video/x-h264, colorimetry=bt709" ! v4l2h264dec ! v4l2convert ! kmssink sync=false

where $1 is the test h264 video clip https://gitlab.freedesktop.org/gstreamer/gstreamer/uploads/f98eab8fe15d2f03df3001febdc63cf6/videodump.h264

By adding code to monitor the timestamp in V4l2 buffers as they are queued (VIDIOC_QBUF) and dequeued (VIDIOC_DQBUF) by the gstv4l2allocator, and checking pending frames before and after draining, I get the following frame history:

Frame history   (sample video videodump.h264 has 713 frames 0-712):

1.    0-113  Landscape     lost first few frames : 0-x,  x can be 2,3 or 4   last frames OK without loss.
2.  114-269  Portrait      lost last 6 frames  : 264-269
3.  270-453  Landscape     lost last 3 frames  : 451-453
4.  454-559  Portrait      lost last 6 frames  : 554-559
5.  560-712  Landscape     lost last 2 frames  : 711-712

Symptom:
segment  1:  Landscape  first frame dequeued by VIDIOC_DQBUF = x+1 (should be 0), last frame dequeued 113.
segment  2:  Portrait   first frame dequeued by VIDIOC_DQBUF = 114, last frame dequeued 263 (should be 269)
segment  3:  Landscape  first frame dequeued by VIDIOC_DQBUF = 270, last frame dequeued 450 (should be 453)
segment  4:  Portrait   first frame dequeued by VIDIOC_DQBUF = 454, last frame dequeued 553 (should be 559)
segment  5:  Landscape  first frame dequeued by VIDIOC_DQBUF = 560, last frame dequeued 710 (should be 712)

Note: CMD_STOP is also sent to start draining when EOS after frame 712 is detected.

The GStreamer code uses "Garbage Collection" to drop any pending frame that is more than 100 frames older than the current frame being rendered, with an un-hideable warning message for each of these "lost frames".

Device (s)

Raspberry Pi 4 Mod. B

System

$cat /etc/rpi-issue
Raspberry Pi reference 2022-04-04
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 27a8050c3c06e567c794620394a8c2d74262a516, stage2

$vcgencmd version
Mar 24 2022 13:19:26 
Copyright (c) 2012 Broadcom
version e5a963efa66a1974127860b42e913d2374139ff5 (clean) (release) (start)

$uname -a
Linux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux

$lsmod
Module                  Size  Used by
cmac                   16384  3
algif_hash             20480  1
aes_arm64              16384  3
algif_skcipher         20480  1
af_alg                 32768  6 algif_hash,algif_skcipher
bnep                   28672  2
hci_uart               49152  1
btbcm                  28672  1 hci_uart
bluetooth             450560  26 hci_uart,btbcm,bnep
ecdh_generic           16384  2 bluetooth
ecc                    36864  1 ecdh_generic
8021q                  32768  0
garp                   16384  1 8021q
stp                    20480  1 garp
llc                    20480  2 stp,garp
snd_soc_hdmi_codec     20480  2
joydev                 24576  0
brcmfmac              331776  0
brcmutil               24576  1 brcmfmac
bcm2835_codec          49152  0
bcm2835_v4l2           45056  0
vc4                   303104  6
bcm2835_isp            32768  0
cfg80211              864256  1 brcmfmac
cec                    53248  1 vc4
v3d                    86016  0
rfkill                 36864  6 bluetooth,cfg80211
bcm2835_mmal_vchiq     36864  3 bcm2835_codec,bcm2835_v4l2,bcm2835_isp
gpu_sched              40960  1 v3d
drm_kms_helper        282624  3 vc4
v4l2_mem2mem           40960  1 bcm2835_codec
raspberrypi_hwmon      16384  0
videobuf2_dma_contig    24576  2 bcm2835_codec,bcm2835_isp
videobuf2_vmalloc      20480  1 bcm2835_v4l2
videobuf2_memops       20480  2 videobuf2_vmalloc,videobuf2_dma_contig
videobuf2_v4l2         32768  4 bcm2835_codec,bcm2835_v4l2,v4l2_mem2mem,bcm2835_isp
videobuf2_common       65536  8 bcm2835_codec,videobuf2_vmalloc,videobuf2_dma_contig,videobuf2_v4l2,bcm2835_v4l2,v4l2_mem2mem,videobuf2_memops,bcm2835_isp
snd_soc_core          253952  2 vc4,snd_soc_hdmi_codec
i2c_brcmstb            16384  0
snd_compress           20480  1 snd_soc_core
snd_bcm2835            24576  1
snd_pcm_dmaengine      20480  1 snd_soc_core
videodev              262144  6 bcm2835_codec,videobuf2_v4l2,bcm2835_v4l2,videobuf2_common,v4l2_mem2mem,bcm2835_isp
snd_pcm               135168  5 snd_bcm2835,snd_soc_hdmi_codec,snd_compress,snd_soc_core,snd_pcm_dmaengine
mc                     57344  6 videodev,bcm2835_codec,videobuf2_v4l2,videobuf2_common,v4l2_mem2mem,bcm2835_isp
snd_timer              36864  1 snd_pcm
vc_sm_cma              36864  2 bcm2835_mmal_vchiq,bcm2835_isp
rpivid_mem             16384  0
snd                   102400  12 snd_bcm2835,snd_soc_hdmi_codec,snd_timer,snd_compress,snd_soc_core,snd_pcm
nvmem_rmem             16384  0
syscopyarea            16384  1 drm_kms_helper
sysfillrect            16384  1 drm_kms_helper
sysimgblt              16384  1 drm_kms_helper
fb_sys_fops            16384  1 drm_kms_helper
uio_pdrv_genirq        16384  0
uio                    24576  1 uio_pdrv_genirq
drm                   573440  5 gpu_sched,drm_kms_helper,v3d,vc4
fuse                  135168  1
drm_panel_orientation_quirks    24576  1 drm
backlight              20480  2 drm_kms_helper,drm
ip_tables              32768  0
x_tables               45056  1 ip_tables
ipv6                  552960  42

Logs

No response

Additional context

ndufresne's suggestion is: "Perhaps the driver author implemented both legacy and specced drain, but forgot to skip the empty buffer if the drain was triggered by cmd_stop. This is easier to fix in the driver."

When the draining ends prematurely at e.g., frame 450 instead of 453, after the 450 buffer is DQBUF'ed with timestamp 450 000 000 000 nsec (450 sec), an empty buffer with flag V4L2_BUF_FLAG_LAST set, and timestamp 450 003 333 000, is DQBUF'ed instead of 451. The same thing, with 450 replaced by 113, 263, 553, 710 happens every time CMD_STOP is sent. Note that the case 113 does NOT lose any frames, so this seems correct behavior, except for lost frames.

6by9 commented 2 years ago

(Having some woes building GStreamer as FFmpeg wants atomic operations that aren't supported by the normal Raspberry Pi OS gcc. https://trac.ffmpeg.org/ticket/9275 and https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=2f0a214a6202516b4dda2bb22b6b3ac20e465d6d)

AFAIK the codec should be flushing the buffers back. CMD_STOP passes an EOS flag into the codec, and that should be returned when the codec has emptied the internal FIFOs. I'll have to look at logging once I have a build.

6by9 commented 2 years ago

Enabling the driver logging via module parameter debug set to 5, I get the logging:

GST_Codec$ grep -e op_buffer_cb -e "Submitted ip" gst_log.txt | grep pts
[17041.593876] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 20498, pts 0, flags 0004
[17041.594897] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 980, pts 1000000, flags 0004
[17041.596588] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 8592, pts 2000000, flags 0004
[17041.596801] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 4672, pts 3000000, flags 0004
[17041.597194] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5374, pts 4000000, flags 0004
[17041.597383] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 773, pts 5000000, flags 0004
[17041.597579] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 2027, pts 6000000, flags 0004
[17041.598159] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 18775, pts 7000000, flags 0004
[17041.598678] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 19807, pts 8000000, flags 0004
[17041.599773] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 22906, pts 9000000, flags 0004
[17041.600248] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 11876, pts 10000000, flags 0004
[17041.602150] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 21747, pts 11000000, flags 0004
[17041.603063] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 45931, pts 12000000, flags 0004
[17041.603374] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 23400, pts 13000000, flags 0004
[17041.605035] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 25903, pts 14000000, flags 0004
[17041.605519] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 24510, pts 15000000, flags 0004
[17041.607394] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 24000, pts 16000000, flags 0004
[17041.610997] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 24867, pts 17000000, flags 0004
[17041.613986] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fc9f5d98, length:96, flags 0000, pts -9223372036854775808

This is the format change event

[17041.624836] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:e091a542, length:2350080, flags 0004, pts 0
[17041.630610] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2fcc7b2c, length:2350080, flags 0004, pts 1000000
[17041.636910] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:17c9ff30, length:2350080, flags 0004, pts 2000000
[17041.642241] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:317a2701, length:2350080, flags 0004, pts 3000000
[17041.647626] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:52ba8b1c, length:2350080, flags 0004, pts 4000000
[17041.672197] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 78170, pts 18000000, flags 0004
[17041.676909] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 5000000
[17041.683134] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 6000000
[17041.685595] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 100821, pts 19000000, flags 0004
[17041.688676] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 7000000
[17041.693962] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 8000000
[17041.699693] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 9000000
[17041.704039] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 105847, pts 20000000, flags 0004
[17041.711825] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 108889, pts 21000000, flags 0004
[17041.717334] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 113313, pts 22000000, flags 0004
[17041.719292] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 101767, pts 23000000, flags 0004
[17041.721872] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 92820, pts 24000000, flags 0004
[17041.723837] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 121786, pts 25000000, flags 0004
[17041.726785] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 116313, pts 26000000, flags 0004
[17041.728354] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 95225, pts 27000000, flags 0004
[17041.729463] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 83321, pts 28000000, flags 0004
[17041.730470] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 78553, pts 29000000, flags 0004
[17041.731811] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 63947, pts 30000000, flags 0004
[17041.732792] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 58970, pts 31000000, flags 0004
[17041.733686] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 57364, pts 32000000, flags 0004
[17041.733985] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 36699, pts 33000000, flags 0004
[17041.734835] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 33192, pts 34000000, flags 0004
[17041.735126] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 31110, pts 35000000, flags 0004
[17041.739489] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 30951, pts 36000000, flags 0004
[17041.739930] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 27607, pts 37000000, flags 0004
[17041.741539] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 23171, pts 38000000, flags 0004
[17041.742053] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 21473, pts 39000000, flags 0004
[17041.745551] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 20634, pts 40000000, flags 0004
[17041.746590] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 25402, pts 41000000, flags 0004
[17041.747539] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 23366, pts 42000000, flags 0004
[17041.747988] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 22113, pts 43000000, flags 0004
[17041.748667] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 23563, pts 44000000, flags 0004
[17041.751673] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 25029, pts 45000000, flags 0004
[17041.752201] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 21931, pts 46000000, flags 0004
[17041.752711] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 22784, pts 47000000, flags 0004
[17041.758925] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 23300, pts 48000000, flags 0004
[17041.759525] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 22316, pts 49000000, flags 0004
[17041.759835] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 27475, pts 50000000, flags 0004
[17041.760329] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 27468, pts 51000000, flags 0004
[17041.760893] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 20978, pts 52000000, flags 0004
[17041.766599] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 22851, pts 53000000, flags 0004
[17041.767184] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 24903, pts 54000000, flags 0004
[17041.767767] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 23052, pts 55000000, flags 0004
[17041.768063] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 26138, pts 56000000, flags 0004
[17041.768562] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 24045, pts 57000000, flags 0004
[17041.793464] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 10000000
[17041.807978] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 25079, pts 58000000, flags 0004
[17041.808592] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 29452, pts 59000000, flags 0004
[17041.809749] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 46735, pts 60000000, flags 0004
[17041.810669] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 52881, pts 61000000, flags 0004
[17041.827608] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 11000000
[17041.860214] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 12000000
[17041.893646] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 13000000
[17041.909404] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 78551, pts 62000000, flags 0004
[17041.914640] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 79970, pts 63000000, flags 0004
[17041.927157] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 14000000
[17041.941524] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 52727, pts 64000000, flags 0004
[17041.946439] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 51737, pts 65000000, flags 0004
[17041.960464] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 15000000
[17041.973985] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 53091, pts 66000000, flags 0004
[17041.977025] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 42230, pts 67000000, flags 0004
[17041.993754] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 16000000
[17042.005497] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 53035, pts 68000000, flags 0004
[17042.009163] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 43922, pts 69000000, flags 0004
[17042.011462] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 48440, pts 70000000, flags 0004
[17042.028832] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 17000000
[17042.039913] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 49023, pts 71000000, flags 0004
[17042.043363] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 44715, pts 72000000, flags 0004
[17042.060616] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 18000000
[17042.071606] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 53751, pts 73000000, flags 0004
[17042.073548] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 48448, pts 74000000, flags 0004
[17042.078919] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 58377, pts 75000000, flags 0004
[17042.093985] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 19000000
[17042.107183] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 62768, pts 76000000, flags 0004
[17042.110995] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 76098, pts 77000000, flags 0004
[17042.127423] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 20000000
[17042.142890] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 94359, pts 78000000, flags 0004
[17042.160773] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 21000000
[17042.172236] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 94731, pts 79000000, flags 0004
[17042.194040] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 22000000
[17042.206787] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 85574, pts 80000000, flags 0004
[17042.228502] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 23000000
[17042.247761] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 98356, pts 81000000, flags 0004
[17042.253063] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 80078, pts 82000000, flags 0004
[17042.261567] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 24000000
[17042.286493] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 74659, pts 83000000, flags 0004
[17042.291563] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 72353, pts 84000000, flags 0004
[17042.296597] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 25000000
[17042.328531] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 71393, pts 85000000, flags 0004
[17042.330212] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 26000000
[17042.349107] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 71017, pts 86000000, flags 0004
[17042.353806] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 69735, pts 87000000, flags 0004
[17042.361716] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 27000000
[17042.379897] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 65030, pts 88000000, flags 0004
[17042.393515] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 28000000
[17042.430015] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 29000000
[17042.462473] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 30000000
[17042.497314] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 31000000
[17042.517500] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 59509, pts 89000000, flags 0004
[17042.530838] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 32000000
[17042.564034] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 33000000
[17042.584845] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 62063, pts 90000000, flags 0004
[17042.597506] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 34000000
[17042.631025] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 35000000
[17042.664419] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 36000000
[17042.685003] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 53689, pts 91000000, flags 0004
[17042.697816] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 37000000
[17042.731098] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 38000000
[17042.753901] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 33625, pts 92000000, flags 0004
[17042.764399] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 39000000
[17042.797752] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 40000000
[17042.831183] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 41000000
[17042.864449] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 42000000
[17042.897976] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 43000000
[17042.922460] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 95852, pts 93000000, flags 0004
[17042.923119] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 38959, pts 94000000, flags 0004
[17042.931380] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 44000000
[17042.964681] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 45000000
[17042.987372] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 31046, pts 95000000, flags 0004
[17042.988251] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 25125, pts 96000000, flags 0004
[17042.998141] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 46000000
[17043.031489] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 47000000
[17043.064872] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 48000000
[17043.098257] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 49000000
[17043.119864] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 21822, pts 97000000, flags 0004
[17043.120663] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 19846, pts 98000000, flags 0004
[17043.121142] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 17821, pts 99000000, flags 0004
[17043.131587] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 50000000
[17043.164993] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 51000000
[17043.198409] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 52000000
[17043.231801] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 53000000
[17043.254759] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 18108, pts 100000000, flags 0004
[17043.255198] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 18613, pts 101000000, flags 0004
[17043.256022] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 18937, pts 102000000, flags 0004
[17043.256520] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 18990, pts 103000000, flags 0004
[17043.263535] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 54000000
[17043.265039] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 17951, pts 104000000, flags 0004
[17043.265568] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 18477, pts 105000000, flags 0004
[17043.298056] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 18126, pts 106000000, flags 0004
[17043.298499] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 16655, pts 107000000, flags 0004
[17043.298515] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 55000000
[17043.299641] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 15899, pts 108000000, flags 0004
[17043.300071] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 16590, pts 109000000, flags 0004
[17043.319274] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 16743, pts 110000000, flags 0004
[17043.320070] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 15942, pts 111000000, flags 0004
[17043.320496] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 15936, pts 112000000, flags 0004
[17043.320863] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 16957, pts 113000000, flags 0004
[17043.331887] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 56000000
[17043.364204] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 57000000
[17043.397651] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 58000000
[17043.431015] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 59000000
[17043.466275] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 60000000
[17043.499565] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 61000000
[17043.532917] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 62000000
[17043.565600] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 63000000
[17043.599020] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 64000000
[17043.632404] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 65000000
[17043.665825] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 66000000
[17043.699081] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 67000000
[17043.732470] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 68000000
[17043.765892] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 69000000
[17043.799235] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 70000000
[17043.832701] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 71000000
[17043.865999] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 72000000
[17043.899390] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 73000000
[17043.932888] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 74000000
[17043.966263] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 75000000
[17043.999633] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 76000000
[17044.033061] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 77000000
[17044.067817] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 78000000
[17044.096698] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 79000000
[17044.133108] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 80000000
[17044.167980] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 81000000
[17044.199895] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 82000000
[17044.233298] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 83000000
[17044.268254] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 84000000
[17044.299994] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 85000000
[17044.333422] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 86000000
[17044.366756] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 87000000
[17044.400286] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 88000000
[17044.433510] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 89000000
[17044.466958] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 90000000
[17044.500463] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 91000000
[17044.532296] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 92000000
[17044.567103] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 93000000
[17044.600538] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 94000000
[17044.633814] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 95000000
[17044.668418] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 96000000
[17044.697505] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 97000000
[17044.730889] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 98000000
[17044.767439] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 99000000
[17044.797648] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 100000000
[17044.831020] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 101000000
[17044.864504] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 102000000
[17044.900949] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 103000000
[17044.932621] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 104000000
[17044.967910] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 105000000
[17045.001185] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 106000000
[17045.032796] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 107000000
[17045.067876] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 108000000
[17045.101256] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:2350080, flags 0004, pts 109000000
[17045.132936] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:2350080, flags 0004, pts 110000000
[17045.168002] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:2350080, flags 0004, pts 111000000
[17045.201290] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:2350080, flags 0004, pts 112000000
[17045.234686] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fd3609f2, length:2350080, flags 0004, pts 113000000
[17045.260250] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:0, flags 0001, pts 113033333

This is the EOS flag back. From the full logs I get [17045.260321] bcm2835-codec bcm2835-codec: op_buffer_cb: done 115 output buffers The input side had reported [17043.349899] bcm2835-codec bcm2835-codec: ip_buffer_cb: done 114 input buffers so this has decoded and delivered all the buffers (plus the EOS buffer). The logs also show that all the PTS values match up.

[17045.363273] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:80393b2c, length:0, flags 0000, pts -9223372036854775808
[17045.363363] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:b53a40a3, length:0, flags 0000, pts -9223372036854775808
[17045.363416] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:8b4ac413, length:0, flags 0000, pts -9223372036854775808
[17045.363496] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c9c04209, length:0, flags 0000, pts -9223372036854775808

Internal flush of the buffers that were queued with the codec, hence length 0 and dummy pts.

[17045.474004] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 19659, pts 114000000, flags 0004
[17045.475220] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1528, pts 115000000, flags 0004
[17045.475425] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 16842, pts 116000000, flags 0004
[17045.476755] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 21963, pts 117000000, flags 0004
[17045.477777] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 33832, pts 118000000, flags 0004
[17045.479700] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 45426, pts 119000000, flags 0004
[17045.481877] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 55462, pts 120000000, flags 0004
[17045.485425] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 65566, pts 121000000, flags 0004
[17045.488940] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 79702, pts 122000000, flags 0004
[17045.491581] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 78050, pts 123000000, flags 0004
[17045.494063] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 70470, pts 124000000, flags 0004
[17045.496003] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 60780, pts 125000000, flags 0004
[17045.497997] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 48883, pts 126000000, flags 0004
[17045.498804] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 37440, pts 127000000, flags 0004
[17045.499910] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 11659, pts 128000000, flags 0004
[17045.500926] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 8167, pts 129000000, flags 0004
[17045.501474] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 6576, pts 130000000, flags 0004
[17045.501788] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5469, pts 131000000, flags 0004
[17045.504821] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:edd0c65b, length:1357824, flags 0004, pts 114000000
[17045.506320] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5120, pts 132000000, flags 0004
[17045.506873] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5341, pts 133000000, flags 0004
[17045.510677] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:023ead59, length:1357824, flags 0004, pts 115000000
[17045.511373] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5919, pts 134000000, flags 0004
[17045.513527] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 6265, pts 135000000, flags 0004
[17045.514959] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:22175fc1, length:1357824, flags 0004, pts 116000000
[17045.518162] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:374af6f3, length:1357824, flags 0004, pts 117000000
[17045.521709] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fe87b074, length:1357824, flags 0004, pts 118000000
[17045.522890] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 6046, pts 136000000, flags 0004
[17045.523361] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 6717, pts 137000000, flags 0004
[17045.524403] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 6846, pts 138000000, flags 0004
[17045.524837] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 6862, pts 139000000, flags 0004
[17045.525186] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 6835, pts 140000000, flags 0004
[17045.525536] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 6127, pts 141000000, flags 0004
[17045.525854] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 6276, pts 142000000, flags 0004
[17045.526142] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5490, pts 143000000, flags 0004
[17045.527685] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 4917, pts 144000000, flags 0004
[17045.528206] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 4596, pts 145000000, flags 0004
[17045.532558] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004

Hello, what's this very large buffer with a very odd looking pts doing in here? FFprobe doesn't identify a frame in there (sizes differ by 6, probably due to start codes).

size=5484 (pts 143000000)
size=4911 (pts 144000000)
size=4590 (pts 145000000)
size=4823 (pts 146000000)
size=5386 (pts 147000000)
size=5673 (pts 148000000)
[17045.534318] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 4829, pts 146000000, flags 0004
[17045.534929] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5392, pts 147000000, flags 0004
[17045.539067] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:5338e836, length:1536000, flags 0004, pts 3294966
[17045.540144] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5679, pts 148000000, flags 0004
[17045.540473] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 4920, pts 149000000, flags 0004
[17045.543921] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5102, pts 150000000, flags 0004
[17045.544100] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:edd0c65b, length:1357824, flags 0004, pts 119000000

We produced an output for this weird pts

[17045.544686] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5071, pts 151000000, flags 0004
[17045.545072] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5035, pts 152000000, flags 0004
[17045.545425] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 5444, pts 153000000, flags 0004
[17045.551507] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 4921, pts 154000000, flags 0004
[17045.556297] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 239537, pts 155000000, flags 0004
[17045.558373] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 28332, pts 156000000, flags 0004
[17045.564445] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 63906, pts 157000000, flags 0004
[17045.566289] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 76054, pts 158000000, flags 0004
[17045.567755] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 74635, pts 159000000, flags 0004
[17045.569038] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 72530, pts 160000000, flags 0004
[17045.570089] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 80272, pts 161000000, flags 0004
[17045.571740] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 76307, pts 162000000, flags 0004
[17045.572994] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 76194, pts 163000000, flags 0004
[17045.574003] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 75773, pts 164000000, flags 0004
[17045.574983] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 75984, pts 165000000, flags 0004
[17045.575997] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 78431, pts 166000000, flags 0004
[17045.577246] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 72860, pts 167000000, flags 0004
[17045.580564] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 80206, pts 168000000, flags 0004
[17045.582177] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 78119, pts 169000000, flags 0004
[17045.583170] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004

Another large buffer and weird pts. Again FFprobe -show_packets doesn't list it

size=80200 (pts 168000000)
size=78113 (pts 169000000)
size=73097 (pts 170000000)
size=80790 (pts 171000000)
size=78110 (pts 172000000)
6by9 commented 2 years ago
[17045.583382] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 73103, pts 170000000, flags 0004
[17045.585082] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 80796, pts 171000000, flags 0004
[17045.586080] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 78116, pts 172000000, flags 0004
[17045.586289] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2d8c0ce1, length:1536000, flags 0004, pts 3294966
[17045.587495] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 73168, pts 173000000, flags 0004
[17045.590786] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 80491, pts 174000000, flags 0004
[17045.591164] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:023ead59, length:1357824, flags 0004, pts 120000000
[17045.595300] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 77832, pts 175000000, flags 0004
[17045.598032] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 73003, pts 176000000, flags 0004
[17045.600246] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 81389, pts 177000000, flags 0004
[17045.603872] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 78655, pts 178000000, flags 0004
[17045.608750] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 73825, pts 179000000, flags 0004
[17045.612039] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 82356, pts 180000000, flags 0004
[17045.612177] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.615004] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:63c66d76, length:1536000, flags 0004, pts 3294966

We now get a load of op_buffer_cb back for pts 3294966, implying that the input buffer had multiple frames inside it. (Whilst we want one NAL per frame, we don't enforce it and will decode all data given to us)

[17045.615710] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 77376, pts 181000000, flags 0004
[17045.619199] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:22175fc1, length:1357824, flags 0004, pts 121000000
[17045.620677] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 72939, pts 182000000, flags 0004
[17045.623939] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 81206, pts 183000000, flags 0004
[17045.628350] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 79052, pts 184000000, flags 0004
[17045.644710] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.647518] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:e0d4f601, length:1536000, flags 0004, pts 3294966
[17045.651526] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:374af6f3, length:1357824, flags 0004, pts 122000000
[17045.678776] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.681569] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:5338e836, length:1536000, flags 0004, pts 3294966
[17045.687101] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fe87b074, length:1357824, flags 0004, pts 123000000
[17045.697962] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 73762, pts 185000000, flags 0004
[17045.711568] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.714365] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2d8c0ce1, length:1536000, flags 0004, pts 3294966
[17045.718404] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:edd0c65b, length:1357824, flags 0004, pts 124000000
[17045.745043] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.747843] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:63c66d76, length:1536000, flags 0004, pts 3294966
[17045.751911] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:023ead59, length:1357824, flags 0004, pts 125000000
[17045.779080] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.781877] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:e0d4f601, length:1536000, flags 0004, pts 3294966
[17045.786590] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:22175fc1, length:1357824, flags 0004, pts 126000000
[17045.811849] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.814642] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:5338e836, length:1536000, flags 0004, pts 3294966
[17045.818617] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:374af6f3, length:1357824, flags 0004, pts 127000000
[17045.845128] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.847932] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2d8c0ce1, length:1536000, flags 0004, pts 3294966
[17045.851930] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fe87b074, length:1357824, flags 0004, pts 128000000
[17045.879109] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.881902] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:63c66d76, length:1536000, flags 0004, pts 3294966
[17045.885840] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:edd0c65b, length:1357824, flags 0004, pts 129000000
[17045.912063] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.914855] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:e0d4f601, length:1536000, flags 0004, pts 3294966
[17045.918822] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:023ead59, length:1357824, flags 0004, pts 130000000
[17045.945344] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.948144] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:5338e836, length:1536000, flags 0004, pts 3294966
[17045.952219] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:22175fc1, length:1357824, flags 0004, pts 131000000
[17045.978563] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17045.981350] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2d8c0ce1, length:1536000, flags 0004, pts 3294966
[17045.985279] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:374af6f3, length:1357824, flags 0004, pts 132000000
[17046.012340] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.015136] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:63c66d76, length:1536000, flags 0004, pts 3294966
[17046.019115] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fe87b074, length:1357824, flags 0004, pts 133000000
[17046.045288] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.048092] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:e0d4f601, length:1536000, flags 0004, pts 3294966
[17046.052066] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:edd0c65b, length:1357824, flags 0004, pts 134000000
[17046.062440] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 81216, pts 186000000, flags 0004
[17046.078735] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.081524] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:5338e836, length:1536000, flags 0004, pts 3294966
[17046.085523] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:023ead59, length:1357824, flags 0004, pts 135000000
[17046.112323] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.115116] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2d8c0ce1, length:1536000, flags 0004, pts 3294966
[17046.119172] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:22175fc1, length:1357824, flags 0004, pts 136000000
[17046.145491] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.148294] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:63c66d76, length:1536000, flags 0004, pts 3294966
[17046.152367] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:374af6f3, length:1357824, flags 0004, pts 137000000
[17046.178825] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.181613] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:e0d4f601, length:1536000, flags 0004, pts 3294966
[17046.185565] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fe87b074, length:1357824, flags 0004, pts 138000000
[17046.212444] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.215233] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:5338e836, length:1536000, flags 0004, pts 3294966
[17046.219206] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:edd0c65b, length:1357824, flags 0004, pts 139000000
[17046.246048] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.251323] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2d8c0ce1, length:1536000, flags 0004, pts 3294966
[17046.255133] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:023ead59, length:1357824, flags 0004, pts 140000000
[17046.280115] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.284701] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:63c66d76, length:1536000, flags 0004, pts 3294966
[17046.288444] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:22175fc1, length:1357824, flags 0004, pts 141000000
[17046.313538] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.318136] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:e0d4f601, length:1536000, flags 0004, pts 3294966
[17046.321906] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:374af6f3, length:1357824, flags 0004, pts 142000000
[17046.347117] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.351626] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:5338e836, length:1536000, flags 0004, pts 3294966
[17046.355286] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fe87b074, length:1357824, flags 0004, pts 143000000
[17046.379781] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.384270] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2d8c0ce1, length:1536000, flags 0004, pts 3294966
[17046.389499] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:edd0c65b, length:1357824, flags 0004, pts 144000000
[17046.413445] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.417933] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:63c66d76, length:1536000, flags 0004, pts 3294966
[17046.421627] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:023ead59, length:1357824, flags 0004, pts 145000000
[17046.447395] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.451897] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:e0d4f601, length:1536000, flags 0004, pts 3294966
[17046.457265] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:22175fc1, length:1357824, flags 0004, pts 146000000
[17046.474526] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 78858, pts 187000000, flags 0004
[17046.479802] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 73934, pts 188000000, flags 0004
[17046.480772] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.485263] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:5338e836, length:1536000, flags 0004, pts 3294966
[17046.485979] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 81145, pts 189000000, flags 0004
[17046.488988] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:374af6f3, length:1357824, flags 0004, pts 147000000
[17046.493683] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 78934, pts 190000000, flags 0004
[17046.504507] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 73853, pts 191000000, flags 0004
[17046.514003] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.518510] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2d8c0ce1, length:1536000, flags 0004, pts 3294966
[17046.522212] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:fe87b074, length:1357824, flags 0004, pts 148000000
[17046.538377] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 80944, pts 192000000, flags 0004
[17046.547922] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 1347840, pts 3294966, flags 0004
[17046.552430] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:63c66d76, length:1536000, flags 0004, pts 3294966
[17046.556092] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:edd0c65b, length:1357824, flags 0004, pts 149000000
[17046.571907] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 79336, pts 193000000, flags 0004
[17046.582325] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:023ead59, length:1357824, flags 0004, pts 150000000
[17046.585840] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:e0d4f601, length:0, flags 0000, pts -9223372036854775808
[17046.585917] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:5338e836, length:0, flags 0000, pts -9223372036854775808
[17046.585962] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2d8c0ce1, length:0, flags 0000, pts -9223372036854775808

Looking at the QBUF/DQBUF logging by setting dev_debug to 0x0b, it doesn't show a QBUF with these weird timestamps, so I'm now puzzled as to how our call to v4l2_m2m_buf_remove in device_run is giving us such a weird buffer. Those queues are all handled by the v4l2_m2m framework. It's as if we have two independent decodes happening at once, as the odd PTS values are also of size 1536000 bytes instead of 1357824 bytes. I also have two independent counts of the number of output buffers

6by9 commented 2 years ago

(Sorry for splitting the above in 2 - Github did a funny, and it won't allow me to attach the logs either at the moment)

6by9 commented 2 years ago

Doh, v4l2convert is using the same bcm2835-codec code as v4l2h264dec. That explains the multiple instances that don't show up in /dev/video10's V4L2 logging, as v4l2convert uses /dev/video12.

Dropping v4l2convert works initially as both v4l2h264dec and kmssink can handle NV12, but it then throws a wobbler when the resolution change comes along.

pi@raspberrypi:~ $ gst-launch-1.0  -vvv filesrc location=videodump.h264 ! video/x-h264 ! h264parse ! capssetter caps="video/x-h264, colorimetry=bt709" ! v4l2h264dec ! kmssink sync=false
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/GstKMSSink:kmssink0: display-width = 1280
/GstPipeline:pipeline0/GstKMSSink:kmssink0: display-height = 800
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:src: caps = video/x-h264, width=(int)1440, height=(int)1080, framerate=(fraction)0/1, coded-picture-structure=(string)frame, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)1:3:5:1, parsed=(boolean)true, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)high, level=(string)4.2
/GstPipeline:pipeline0/GstCapsSetter:capssetter0.GstPad:src: caps = video/x-h264, width=(int)1440, height=(int)1080, framerate=(fraction)0/1, coded-picture-structure=(string)frame, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)bt709, parsed=(boolean)true, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)high, level=(string)4.2
/GstPipeline:pipeline0/v4l2h264dec:v4l2h264dec0.GstPad:sink: caps = video/x-h264, width=(int)1440, height=(int)1080, framerate=(fraction)0/1, coded-picture-structure=(string)frame, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)bt709, parsed=(boolean)true, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)high, level=(string)4.2
/GstPipeline:pipeline0/GstCapsSetter:capssetter0.GstPad:sink: caps = video/x-h264, width=(int)1440, height=(int)1080, framerate=(fraction)0/1, coded-picture-structure=(string)frame, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)1:3:5:1, parsed=(boolean)true, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)high, level=(string)4.2
/GstPipeline:pipeline0/v4l2h264dec:v4l2h264dec0.GstPad:src: caps = video/x-raw, format=(string)NV12, width=(int)1440, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt601, framerate=(fraction)0/1
/GstPipeline:pipeline0/GstKMSSink:kmssink0.GstPad:sink: caps = video/x-raw, format=(string)NV12, width=(int)1440, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt601, framerate=(fraction)0/1
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
Redistribute latency...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:src: caps = video/x-h264, width=(int)810, height=(int)1080, framerate=(fraction)0/1, coded-picture-structure=(string)frame, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)1:3:5:1, parsed=(boolean)true, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)high, level=(string)4.1
/GstPipeline:pipeline0/GstCapsSetter:capssetter0.GstPad:src: caps = video/x-h264, width=(int)810, height=(int)1080, framerate=(fraction)0/1, coded-picture-structure=(string)frame, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)bt709, parsed=(boolean)true, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)high, level=(string)4.1
0:00:00.0 / 99:99:99.
** (gst-launch-1.0:11233): WARNING **: 16:33:46.543: v4l2h264dec0: Too old frames, bug in decoder -- please file a bug
0:00:00.0 / 99:99:99.
** (gst-launch-1.0:11233): WARNING **: 16:33:46.576: v4l2h264dec0: Too old frames, bug in decoder -- please file a bug
** (gst-launch-1.0:11233): WARNING **: 16:33:46.610: v4l2h264dec0: Too old frames, bug in decoder -- please file a bug
** (gst-launch-1.0:11233): WARNING **: 16:33:46.643: v4l2h264dec0: Too old frames, bug in decoder -- please file a bug
0:00:00.0 / 99:99:99.
** (gst-launch-1.0:11233): WARNING **: 16:33:46.676: v4l2h264dec0: Too old frames, bug in decoder -- please file a bug
/GstPipeline:pipeline0/v4l2h264dec:v4l2h264dec0.GstPad:sink: caps = video/x-h264, width=(int)810, height=(int)1080, framerate=(fraction)0/1, coded-picture-structure=(string)frame, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)bt709, parsed=(boolean)true, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)high, level=(string)4.1
/GstPipeline:pipeline0/GstCapsSetter:capssetter0.GstPad:sink: caps = video/x-h264, width=(int)810, height=(int)1080, framerate=(fraction)0/1, coded-picture-structure=(string)frame, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)1:3:5:1, parsed=(boolean)true, stream-format=(string)byte-stream, alignment=(string)au, profile=(string)high, level=(string)4.1
0:00:04.932192754 11233  0x2138040 ERROR           v4l2videodec gstv4l2videodec.c:633:gst_v4l2_video_dec_setup_capture:<v4l2h264dec0> not negotiated
0:00:04.932738242 11233  0x2138040 ERROR           v4l2videodec gstv4l2videodec.c:794:gst_v4l2_video_dec_handle_frame:<v4l2h264dec0> setup capture fail
0:00:04.932840755 11233  0x2138040 ERROR           v4l2videodec gstv4l2videodec.c:898:gst_v4l2_video_dec_handle_frame:<v4l2h264dec0> not negotiated
ERROR: from element /GstPipeline:pipeline0/GstH264Parse:h264parse0: Internal data stream error.
Additional debug info:
../subprojects/gstreamer/libs/gst/base/gstbaseparse.c(3681): gst_base_parse_loop (): /GstPipeline:pipeline0/GstH264Parse:h264parse0:
streaming stopped, reason not-negotiated (-4)
Execution ended after 0:00:03.672763335
Setting pipeline to NULL ...
Freeing pipeline ...

Using videoconvert works, so there's something odd in requiring a conversion.

fduncanh commented 2 years ago

Looking at your buffer len output I see that all frames are 6 bytes bigger than the sum of their NALs in the test video bitstream, but I see in the GST_DEBUG=7 output from GStreamer that h264parse inserts an AUD into the bitstream at the end of each frame, and gstreamer agrees with the sizes reported by bcm2835-codec for the VIDIOC_QBUF.


GST_Codec$ grep -e op_buffer_cb -e "Submitted ip" gst_log.txt | grep pts
[17041.593876] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 20498, pts 0, flags 0004
[17041.594897] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 980, pts 1000000, flags 0004
[17041.596588] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 8592, pts 2000000, flags 0004
[17041.596801] bcm2835-codec bcm2835-codec: device_run: Submitted ip buffer len 4672, pts 3000000, flags 0004
fduncanh commented 2 years ago

As noted in the bug report, there are two distinct issues: the (1) why the the first few frames after the initial frame with SPS never get dequeued by VIDIOC_DQBUF, and (2) why (except maybe the first time CMD_STOP is sent) a few frame are left pending aftre the draining finishes (VIDIOC_DQBUF sends what seems to be a premature eos signal.)

I have a second test video with no midstream SPS changes, which shows only error (1), and drains all frames correctly the first time CMD_STOP is send, this time at the end of the video. This is only 2 examples, so I don't know if it is always the case that the first draining works and subsequent ones are incomplete.

Possibly it might be easier to find why the draining procedure is (sometimes) incomplete. - error 2.

6by9 commented 2 years ago

Hmm

[ 2329.864376] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:71c9e5ab, length:96, flags 0000, pts -9223372036854775808
[ 2329.864391] bcm2835-codec bcm2835-codec: handle_fmt_changed: Format changed: buff size min 2350080, rec 2350080, buff num min 1, rec 1
[ 2329.864399] bcm2835-codec bcm2835-codec: handle_fmt_changed: Format changed to 1440x1088, crop 1440x1080, colourspace 49464A59
[ 2329.864408] bcm2835-codec bcm2835-codec: handle_fmt_changed: Format was 1440x1088, crop 1440x1080
[ 2329.868208] bcm2835-codec bcm2835-codec: handle_fmt_changed: interlace mode 0, v4l2 field 1
[ 2329.869272] video10: VIDIOC_DQEVENT: type=0x5, pending=0, sequence=0, id=0, timestamp=2329.812584024
[ 2329.870342] bcm2835-codec bcm2835-codec: bcm2835_codec_stop_streaming: type: 9 - return buffers
[ 2329.872925] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:c5dcfecd, length:2350080, flags 0004, pts 0
[ 2329.872952] bcm2835-codec bcm2835-codec: op_buffer_cb: length 2350080, flags 4, idx 0
[ 2329.872971] bcm2835-codec bcm2835-codec: op_buffer_cb: done 1 output buffers
[ 2329.879341] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:7cf24288, length:2350080, flags 0004, pts 1000000
[ 2329.879353] bcm2835-codec bcm2835-codec: op_buffer_cb: length 2350080, flags 4, idx 1
[ 2329.879363] bcm2835-codec bcm2835-codec: op_buffer_cb: done 2 output buffers
[ 2329.884457] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:67d70acc, length:2350080, flags 0004, pts 2000000
[ 2329.884467] bcm2835-codec bcm2835-codec: op_buffer_cb: length 2350080, flags 4, idx 2
[ 2329.884479] bcm2835-codec bcm2835-codec: op_buffer_cb: done 3 output buffers
[ 2329.889868] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:2c1be03d, length:2350080, flags 0004, pts 3000000
[ 2329.889894] bcm2835-codec bcm2835-codec: op_buffer_cb: length 2350080, flags 4, idx 3
[ 2329.889906] bcm2835-codec bcm2835-codec: op_buffer_cb: done 4 output buffers
[ 2329.895564] bcm2835-codec bcm2835-codec: op_buffer_cb: status:0, buf:e5e42683, length:2350080, flags 0004, pts 4000000
[ 2329.895574] bcm2835-codec bcm2835-codec: op_buffer_cb: length 2350080, flags 4, idx 4
[ 2329.895583] bcm2835-codec bcm2835-codec: op_buffer_cb: done 5 output buffers
[ 2329.895946] bcm2835-codec bcm2835-codec: bcm2835_codec_stop_streaming: done
[ 2329.895961] video10: VIDIOC_STREAMOFF: type=vid-cap-mplane
[ 2329.896123] bcm2835-codec bcm2835-codec: bcm2835_codec_buffer_cleanup: ctx:6d83b1f8, vb e07e2688
[ 2329.896137] bcm2835-codec bcm2835-codec: bcm2835_codec_buffer_cleanup: ctx:6d83b1f8, vb aef92a4f
[ 2329.896147] bcm2835-codec bcm2835-codec: bcm2835_codec_buffer_cleanup: ctx:6d83b1f8, vb 5b653572
[ 2329.896156] bcm2835-codec bcm2835-codec: bcm2835_codec_buffer_cleanup: ctx:6d83b1f8, vb 615df263
[ 2329.896165] bcm2835-codec bcm2835-codec: bcm2835_codec_buffer_cleanup: ctx:6d83b1f8, vb 7f0296d7
[ 2329.896180] video10: VIDIOC_REQBUFS: count=0, type=vid-cap-mplane, memory=mmap

So they have been decoded already (presumably the output buffer was of an appropriate size), but because it's doing a flush in stop_streaming, they're being discarded. I thought I'd been through this loop before. Presumably the CAPTURE queue format has been set to the format, so the buffers are of an appropriate size. That's a quick one to fix in the firmware.

I wonder if error 2 is similar. I'm investigating.

fduncanh commented 2 years ago

So they have been decoded already (presumably the output buffer was of an appropriate size), but because it's doing a flush in stop_streaming, they're being discarded. I thought I'd been through this loop before. Presumably the CAPTURE queue format has been set to the format, so the buffers are of an appropriate size. That's a quick one to fix in the firmware.

I wonder if error 2 is similar. I'm investigating.

error 2. is in frames VIDIOC_QBUF'ed BEFORE the frame with a new SPS. A strange thing is that it did not happen the first time CMD_STOP was sent, but happened in all the subsequent ones, in the two example videos I studied. I'll create and check a few more samples to see if this is just an accident.

fduncanh commented 2 years ago

@6by9

I tested with 3 more examples. For error 2.

In each case the first CMD_STOP draining works perfectly. If the last pending frame is e.g. 209, the last VIDIOC_DQBUF returns an empty buffer with ts = 209 033 333 000 and the V4L2_BUF_FLAG_LAST flag set, terminating the drain.

All later CMD_STOP events leave some undrained frames. The number lost seems to be correlated with the frame size in bytes which is varying between smaller and bigger as the image changes between portrait and landscape at fixed pixel height.

This seems to suggest something in the firmware is left unreset after a drain finishes, and affects subsequent drainings?

fduncanh commented 2 years ago

@6by9 re: problem 1 (which does not involve CMD_STOP):

(Edited) so if I understand it, the issue is the extra colourspace info which makes the decoder want to drop the already-decoded frames even though their size is unchanged?

[87393.702235] bcm2835-codec bcm2835-codec: handle_fmt_changed: Format changed: buff size min 2350080, rec 2350080, buff num min 1, rec 1
[87393.702254] bcm2835-codec bcm2835-codec: handle_fmt_changed: Format changed to 1440x1088, crop 1440x1080, colourspace 49464A59
[87393.702265] bcm2835-codec bcm2835-codec: handle_fmt_changed: Format was 1440x1088, crop 1440x1080
fduncanh commented 2 years ago

@6by9 (Edited)

For error 2 (incomplete draining after the second and all subsequent CMD_STOPs) I've looked at the debug=5 output from bcm2835-codec and can't see any reason why EOS is signaled after frame 263 is dequeued instead of signalling it after frame 269, which is the last frame of the old format before frame 270 ( the first frame with the new format).

I couldn't see any obvious difference with the first CMD_STOP at frame 114, where draining works perfectly. The fact the the first draining always succeeds, while all later ones lose frames suggests that something in the driver/firmware might need reinitializing after each CMD_STOP? (this behavior was true in all the 5 test videos I looked at)

6by9 commented 2 years ago

This is fairly deep down in the codec code. It is reporting that it is idle a number of frames before it has actually processed everything, and therefore the EOS gets sent early.

I have a suspicion that it is triggering parsing once per buffer because we signal it as framed data. Where we get the header bytes in the same buffer as the I-frame we need multiple kicks, and those happening. It's taking a fair amount of digging to confirm this hypothesis though.

fduncanh commented 2 years ago

The strange thing is that the first CMD_STOP always seems to work perfectly, and all the subsequent ones send EOS early. This is in 6/6 examples. I could try more but it seems significant.

And seems to lose more frames when it is about to switch from a smaller (portrait) image to a larger one (Landscape) and less the other way. I need to see how systematic this is.

fduncanh commented 2 years ago

@6by9

To reduce the error mesage spamming, I got updates to gstreamer development branch(1.21) merged to cleanup all frames in groups of dropped frames dropped with a single g_warning each time one of these errors occurs. The two different errors now generate different error messages which now report how many frames were lost, and what range of system frame numbers were lost.

Here are the new error messages generated by the test video clip and pipeline I provided

** (gst-launch-1.0:147904): WARNING **: 00:52:36.960: v4l2h264dec0: 5 initial frames before frame 5 were not dequeued: bug in decoder -- please file a bug

** (gst-launch-1.0:147904): WARNING **: 00:52:45.715: v4l2h264dec0: 6 frames 264-269 left undrained after CMD_STOP, eos sent too early: bug in decoder -- please file a bug

** (gst-launch-1.0:147904): WARNING **: 00:52:51.881: v4l2h264dec0: 3 frames 451-453 left undrained after CMD_STOP, eos sent too early: bug in decoder -- please file a bug

** (gst-launch-1.0:147904): WARNING **: 00:52:55.380: v4l2h264dec0: 6 frames 554-559 left undrained after CMD_STOP, eos sent too early: bug in decoder -- please file a bug

** (gst-launch-1.0:147904): WARNING **: 00:53:00.497: v4l2h264dec0: 2 frames 711-712 left undrained after CMD_STOP, eos sent too early: bug in decoder -- please file a bug
popcornmix commented 2 years ago

The latest rpi-update firmware contains a potential fix for this issue.

6by9 commented 2 years ago

The latest rpi-update firmware contains a potential fix for this issue.

It's only a fix for the first error where a colourspace only change resulted in the initial buffers being lost. The second error is still being investigated.

fduncanh commented 2 years ago

@6by9 thanks for fixing the colorspace-only change issue!

It seems to me that the key clue in the unresolved incomplete-draining issue is that the first drain event always works perfectly, but all later ones somehow send eos too soon. Maybe something is left set after the first draining event that should have been unset? clearly some memory of earlier drainings seems to remain..

engnfrc commented 2 years ago

Are there any updates to this issue? It's been a while since the last update. I have a post on the RPi forums (https://forums.raspberrypi.com/viewtopic.php?p=2031719#p2031719) where I've been talking with @6by9 and an email out to the Gstreamer Devel Listserv gstreamer-devel@lists.freedesktop.org where I'm talking with Nicolas Dufresne (ndufresne) and would really like to find a resolution. It sounds like this issue may be a contributing factor?

engnfrc commented 2 years ago

Example pipeline that works with one make/model of camera, but not this camera (ELP-USBFHD01M): GST_DEBUG=*:4 GST_DEBUG_DUMP_DOT_DIR=$PWD/pipelines gst-launch-1.0 -e -vvv v4l2src device=/dev/videoHEL1 num-buffers=1 ! image/jpeg,width=1280,height=720,framerate=60/1 ! jpegparse ! identity name=identity_pre silent=false ! v4l2jpegdec ! identity name=identity_post silent=false ! filesink location=ELP-USBFHD01M_1frame.raw >ELP-USBFHD01M_1frame_raw.log 2>&1 0 00 00 376244185-gst-launch READY_PAUSED Pipeline - Raw.zip Pipeline - JPEG.zip

6by9 commented 2 years ago

Fix for issue 1 has been available for a while. Sorry, other priorities have stopped me looking at issue 2. It's still on the list, but as I've already said, the issue appears to be buried fairly well down in the codec code.

6by9 commented 2 years ago

I've just noticed that wasn't fduncanh asking for a status update.

This issue is ONLY related to video decode on resolution change with H264 (or MPEG4, H263, MPEG2, or VC-1 on Pi0-3) losing buffers. JPEG (or more accurately MJPEG in V4L2) goes through a different codec block and is going to be unrelated.

engnfrc commented 2 years ago

Thanks! Based on that feedback I will generate a new issue.

fduncanh commented 1 year ago

Hi @6by9, any chance that this "frames_left_undrained" issue (issue 2) is in the bcm2835_codec kernel driver, or will it be in the firmware?

Now that GStreamer 1.22 is out (which I wont be supplying v4l2 patches for, that also silence the warning, since v1.22 is fully fixed, at least to work with uxplay) this bug will produce a GStreamer error message each time the draining is incomplete.

(like this:)

WARNING ** 18:25:17.769: v4l2h264dec1: 2 frames 5135-5136 left undrained after CMD_STOP,  eos sent too early:  bug in decoder -- please file a bug
6by9 commented 1 year ago

any chance that this "frames_left_undrained" issue (issue 2) is in the bcm2835_codec kernel driver, or will it be in the firmware?

From previous digging I believe it is in the firmware, and fairly well buried down in the codec parsing code which I don't really know my way around.