drmModePageFlip with interlaced frame
I am working on interlaced PAL video playback on RPI4. Everything looks good but i cant understand which field (upper or lower) page_flip_handler belongs to.
Prototype of that function:
has frame parameter which in my case is sequence of odd:
I did a tests with two framebuffers. First has normal bars in upper fields and h-flipped bars in lower fields. Second has h-flipped bars in upper fields and normal bars in lower fields. So sequential displaying of that two framebuffer would produce either normal bars on CVBS output or horizontally flipped. it depends on initial phase which i trying to find (calculate) from frame parameter of page_flip_handler
may be somebody know how to get which field of interlaced frame is currently displaying or how to get scanout position from userspace?
i am using RPI4 with latest bookworm:
Prototype of that function:
Code: Select all
static void page_flip_handler(int fd, unsigned int frame,
unsigned int sec, unsigned int usec, void *data)- * ...
* 278009
* 278011
* ...
- * ...
* 273372
* 273374
* ...
I did a tests with two framebuffers. First has normal bars in upper fields and h-flipped bars in lower fields. Second has h-flipped bars in upper fields and normal bars in lower fields. So sequential displaying of that two framebuffer would produce either normal bars on CVBS output or horizontally flipped. it depends on initial phase which i trying to find (calculate) from frame parameter of page_flip_handler
may be somebody know how to get which field of interlaced frame is currently displaying or how to get scanout position from userspace?
i am using RPI4 with latest bookworm:
Code: Select all
Linux rpi4 6.12.34+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.34-1+rpt1~bookworm (2025年06月26日) aarch64 GNU/Linux
- dom
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 8472
- Joined: Wed Aug 17, 2011 7:41 pm
Re: drmModePageFlip with interlaced frame
On a pi5:
bit15 should show odd/even field.
On a Pi4:
bit27 should show odd/even field.
The bit means:
Now this is very hacky - 6by9 may have a better idea if this is available through DRM api.
Code: Select all
$ cat /sys/kernel/debug/dri/axi:gpu/hvs_regs | grep SCALER6D_DISP0_STATUS
SCALER6D_DISP0_STATUS = 0x008c43e9
On a Pi4:
Code: Select all
$ cat /sys/kernel/debug/dri/gpu/hvs_regs | grep SCALER_DISPSTAT0
SCALER_DISPSTAT0 = 0xa011c3bf
The bit means:
Code: Select all
1 = Current frame is the ODD field (lines 1, 3, 5, etc.).
0 = Current frame is the EVEN field (lines 0, 2, 4, etc.) or interlace mode is not enabled.
- 6by9
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 18476
- Joined: Wed Dec 04, 2013 11:27 am
Re: drmModePageFlip with interlaced frame
Not really. Most DRM devs considers interlacing as a dead technology. I don't think they even specify whether the page flips should happen at field or frame rate (part of the reason we had the discrepancy with Pi5/RP1 running at frame rate vs Pi0-4/vc4 being at field rate).
AIUI Scanout position is independent of interlacing - the HVS will read and generate all lines for the frame on every field, and then the pixel valve throws away the wrong lines for this field.
Within the kernel DRM APIs there is a get_scanout_position call, but I don't believe that gets exposed to userspace. It looks to only be used for timestamping vblank events.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
- 6by9
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 18476
- Joined: Wed Dec 04, 2013 11:27 am
Re: drmModePageFlip with interlaced frame
Note that this will only be valid for HDMI producing interlaced output. The HVS isn't involved in the composite output on Pi5.dom wrote: ↑Thu Sep 04, 2025 12:39 pmOn a pi5:bit15 should show odd/even field.Code: Select all
$ cat /sys/kernel/debug/dri/axi:gpu/hvs_regs | grep SCALER6D_DISP0_STATUS SCALER6D_DISP0_STATUS = 0x008c43e9
The register name also varies between the C1 and D0 stepping. Grepping for "_DISP0_STATUS" should give you the correct answer on either.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
- njh
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 600
- Joined: Wed Aug 09, 2017 2:07 pm
Re: drmModePageFlip with interlaced frame
Just to confuse everyone: From the next OS release, the Pi5 Composite output will also be able to update at field rate. DPI has been able to do this for a while too. Although their drivers do "know" which field is being displayed, they have no way of telling anybody.6by9 wrote: ↑Thu Sep 04, 2025 3:29 pmNot really. Most DRM devs considers interlacing as a dead technology. I don't think they even specify whether the page flips should happen at field or frame rate (part of the reason we had the discrepancy with Pi5/RP1 running at frame rate vs Pi0-4/vc4 being at field rate).
Re: drmModePageFlip with interlaced frame
Many thanks for info, but bit27 of SCALER_DISPSTAT0 is always zero in my case (RPI4, PAL CVBS output, kernel 6.12.34+rpt-rpi-v8).
I read SCALER_DISPSTAT0 on each page_flip_handler callback :
and in bash loop (with 5 miliseconds delay):
and in all cases, interesting bit is 0
may be i misguide you: i am trying to output CVBS (analogue PAL) signal but not HDMI
I read SCALER_DISPSTAT0 on each page_flip_handler callback :
Code: Select all
....
! [2025年09月06日 14:52:09.330] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x1020C000
! [2025年09月06日 14:52:09.350] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x10274000
! [2025年09月06日 14:52:09.370] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x1013C000
! [2025年09月06日 14:52:09.390] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x101A4000
! [2025年09月06日 14:52:09.410] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x1020C000
! [2025年09月06日 14:52:09.430] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x10274000
! [2025年09月06日 14:52:09.450] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x1013C000
! [2025年09月06日 14:52:09.470] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x101A4000
! [2025年09月06日 14:52:09.490] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x1020C000
! [2025年09月06日 14:52:09.510] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x10274000
! [2025年09月06日 14:52:09.530] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x1013C000
! [2025年09月06日 14:52:09.550] drm_output_current_field_rpi4:65: SCALER_DISPSTAT0=0x101A4000
....
Code: Select all
....
SCALER_DISPSTAT0 = 0x1020c000
SCALER_DISPSTAT0 = 0x10274000
SCALER_DISPSTAT0 = 0x10274000
SCALER_DISPSTAT0 = 0x1013c000
SCALER_DISPSTAT0 = 0x101a4000
SCALER_DISPSTAT0 = 0x1020c000
SCALER_DISPSTAT0 = 0x1020c000
SCALER_DISPSTAT0 = 0x10274000
SCALER_DISPSTAT0 = 0x1013c000
SCALER_DISPSTAT0 = 0x101a4000
SCALER_DISPSTAT0 = 0x101a4000
....
may be i misguide you: i am trying to output CVBS (analogue PAL) signal but not HDMI
Re: drmModePageFlip with interlaced frame
Thanks!
SCALER_DISPSTAT1 did a job for CVBS output.
It would be nice to get bit27 at frame argument of page_flip_handler but current approach works.
SCALER_DISPSTAT1 did a job for CVBS output.
It would be nice to get bit27 at frame argument of page_flip_handler but current approach works.
Re: drmModePageFlip with interlaced frame
i did a tests on RPI5.
i am working with CVBS (analog PAL) output.
signal present but no glue how to get current output field information of CVBS output on RPI5.
hvs_regs of axi:gpu remains unchanged:
i suspect it happens because on Pi5 the analogue video output is driven from RP1 and i use /dev/dri/by-path/platform-1f00144000.vec-card DRM device.
its debug sys directory:
does not contains any regs file.
any way to get current output field information of CVBS output on RPI5 ?
i am working with CVBS (analog PAL) output.
signal present but no glue how to get current output field information of CVBS output on RPI5.
hvs_regs of axi:gpu remains unchanged:
Code: Select all
demo@dev-rpi5-1:~ $ cat /sys/kernel/debug/dri/axi:gpu/hvs_regs | grep _STATUS
SCALER6_FETCHER_STATUS = 0x00000000
SCALER6_FETCH_STATUS = 0x00000000
SCALER6_DISP0_STATUS = 0x00400000
SCALER6_DISP1_STATUS = 0x00400000
SCALER6_DISP2_STATUS = 0x00400000
SCALER6_DL_STATUS = 0x00000000its debug sys directory:
Code: Select all
demo@dev-rpi5-1:~ $ ls -als /sys/kernel/debug/dri/1f00144000.vec
total 0
0 drwxr-xr-x 5 root root 0 Sep 10 21:49 .
0 drwxr-xr-x 5 root root 0 Jun 26 17:58 ..
0 -r--r--r-- 1 root root 0 Sep 10 21:49 clients
0 drwxr-xr-x 2 root root 0 Sep 10 21:49 Composite-1
0 drwxr-xr-x 2 root root 0 Sep 10 21:49 crtc-0
0 drwxr-xr-x 2 root root 0 Sep 10 21:49 encoder-0
0 -r--r--r-- 1 root root 0 Sep 10 21:49 framebuffer
0 -r--r--r-- 1 root root 0 Sep 10 21:49 gem_names
0 -r--r--r-- 1 root root 0 Sep 10 21:49 internal_clients
0 -r--r--r-- 1 root root 0 Sep 10 21:49 name
0 -r--r--r-- 1 root root 0 Sep 10 21:49 state
any way to get current output field information of CVBS output on RPI5 ?
Code: Select all
Linux dev-rpi5-1 6.12.45-v8-16k+ #1903 SMP PREEMPT Fri Sep 5 14:18:54 BST 2025 aarch64 GNU/Linux- njh
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 600
- Joined: Wed Aug 09, 2017 2:07 pm
Re: drmModePageFlip with interlaced frame
No. With earlier kernels, the issue is moot: You always get top-then-bottom (25fps update).*
With very recent kernels (like the one you have), there's a flag inside the driver which flips about 32 lines into each field, but it's not user-visible.
If it was desperately needed and in the absence of any standard API for it, I suppose it could be exposed using debugfs...
*for PAL anyway. I suspect NTSC is the other way around, for more or less bogus reasons to do with line numbering conventions.
Re: drmModePageFlip with interlaced frame
would it correct to say that:
current kernel on RPI5 does not allow to field sync source interlaced framebuffers with CVBS (analogue video output) framebuffers ?
current kernel on RPI5 does not allow to field sync source interlaced framebuffers with CVBS (analogue video output) framebuffers ?
IMHO that is correct approach, you have either frame-based or field-based output/control.No. With earlier kernels, the issue is moot: You always get top-then-bottom (25fps update)
- njh
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 600
- Joined: Wed Aug 09, 2017 2:07 pm
Re: drmModePageFlip with interlaced frame
The timing of your post is a little unfortunate...
We've had multiple requests for Raspberry Pi 5 CVBS to support 50fps/60fps update (as it did on Pi 0-4). Arguably, the VBI event should be per-field, and we should allow but not mandate a page-flip for each one. And I only quite recently worked out how to implement this!
But I can see this is a problem when you need to scan out already-interlaced content. AFAIK nobody has raised this before.
Perhaps the best solution would be for us to try to make the sequence numbers behave consistently for fields, if possible. We'd need to figure out how those get from the driver to libdrm and see if we can fix them up when e.g. a mode change follows an odd number of fields. A module parameter is another option (to get back the old behaviour on RP1 VEC; I haven't looked at how feasible it would be for VC4).
We've had multiple requests for Raspberry Pi 5 CVBS to support 50fps/60fps update (as it did on Pi 0-4). Arguably, the VBI event should be per-field, and we should allow but not mandate a page-flip for each one. And I only quite recently worked out how to implement this!
But I can see this is a problem when you need to scan out already-interlaced content. AFAIK nobody has raised this before.
Perhaps the best solution would be for us to try to make the sequence numbers behave consistently for fields, if possible. We'd need to figure out how those get from the driver to libdrm and see if we can fix them up when e.g. a mode change follows an odd number of fields. A module parameter is another option (to get back the old behaviour on RP1 VEC; I haven't looked at how feasible it would be for VC4).
- 6by9
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 18476
- Joined: Wed Dec 04, 2013 11:27 am
Re: drmModePageFlip with interlaced frame
I don't believe DRM has ever supported being able to directly output an interlaced framebuffer to an interlaced display, and certainly not a line interleaved one as typically comes out of most codecs (certainly the Pi HW decoder gives line interleaved).
Doing so has many constraints (eg absolutely no scaling) that makes it too specialised. I guess a single field at a time could work, but requires extra work to generate it.
It doesn't help that most of the DRM devs generally don't care much for interlacing.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
- njh
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 600
- Joined: Wed Aug 09, 2017 2:07 pm
Re: drmModePageFlip with interlaced frame
Here's a potential workaround you could use. It's not great, but should work on any Raspberry Pi model for both HDMI and Composite:
Say you want to display interlaced frames Ab, Cd, Ef, Gh etc.
Then at field-rate, submit frame buffers containing Ab, Cb, Cd, Ed, Ef, Gf, Gh.
Depending on luck it will either display bCdEfGh or AbCdEfG (20ms delayed). Either way, it should be correctly interlaced.
Say you want to display interlaced frames Ab, Cd, Ef, Gh etc.
Then at field-rate, submit frame buffers containing Ab, Cb, Cd, Ed, Ef, Gf, Gh.
Depending on luck it will either display bCdEfGh or AbCdEfG (20ms delayed). Either way, it should be correctly interlaced.
Re: drmModePageFlip with interlaced frame
it is not a workaround but hack. similar hack was 20 years ago with SD video.
i actually started with specific test that in a case of initial phase (lucky case it related to first field) display either normal bars or horizontally flipped.
workaround is to produce 2 progressive frames from one interlaced frame. first have upper fields from origin and lower fields interpolated, but second frames has lower fields origin but upper fields interpolated.
but it better have a solution, at least to know which filed page_flip_handler belongs to. solution for RPI4 with registers works.
i actually started with specific test that in a case of initial phase (lucky case it related to first field) display either normal bars or horizontally flipped.
workaround is to produce 2 progressive frames from one interlaced frame. first have upper fields from origin and lower fields interpolated, but second frames has lower fields origin but upper fields interpolated.
but it better have a solution, at least to know which filed page_flip_handler belongs to. solution for RPI4 with registers works.
Return to "Graphics programming"
Jump to
- Community
- General discussion
- Announcements
- Other languages
- Deutsch
- Español
- Français
- Italiano
- Nederlands
- 日本語
- Polski
- Português
- Русский
- Türkçe
- User groups and events
- Raspberry Pi Official Magazine
- Using the Raspberry Pi
- Beginners
- Troubleshooting
- Advanced users
- Assistive technology and accessibility
- Education
- Picademy
- Teaching and learning resources
- Staffroom, classroom and projects
- Astro Pi
- Mathematica
- High Altitude Balloon
- Weather station
- Programming
- C/C++
- Java
- Python
- Scratch
- Other programming languages
- Windows 10 for IoT
- Wolfram Language
- Bare metal, Assembly language
- Graphics programming
- OpenGLES
- OpenVG
- OpenMAX
- General programming discussion
- Projects
- Networking and servers
- Automation, sensing and robotics
- Graphics, sound and multimedia
- Other projects
- Media centres
- Gaming
- AIY Projects
- Hardware and peripherals
- Camera board
- Compute Module
- Official Display
- HATs and other add-ons
- Device Tree
- Interfacing (DSI, CSI, I2C, etc.)
- Keyboard computers (400, 500, 500+)
- Raspberry Pi Pico
- General
- SDK
- MicroPython
- Other RP2040 boards
- Zephyr
- Rust
- AI Accelerator
- AI Camera - IMX500
- Hailo
- Software
- Raspberry Pi OS
- Raspberry Pi Connect
- Raspberry Pi Desktop for PC and Mac
- Beta testing
- Other
- Android
- Debian
- FreeBSD
- Gentoo
- Linux Kernel
- NetBSD
- openSUSE
- Plan 9
- Puppy
- Arch
- Pidora / Fedora
- RISCOS
- Ubuntu
- Ye Olde Pi Shoppe
- For sale
- Wanted
- Off topic
- Off topic discussion