mmal callback what happends on overflow?
Hello,
mmal(h.264) gives a callback, the user copy the data and so on.
What happends if the callback is not served fast enough?
Lets say there there is a halft frame in the buffer it and 2 frames are missed.
Does mmal keep the second half of the frame, just skip new input frames?
Or is it possible that this data gets dropped?
I have streams with h264 artifacts and after the i-frame count in this broken streams always 2 frames missing.
I never seen errors in the jpeg output, its too not a camera problem(purple), the error is too over the Annotation.
Means its in the h264 encoding stage not in something before that.
mmal(h.264) gives a callback, the user copy the data and so on.
What happends if the callback is not served fast enough?
Lets say there there is a halft frame in the buffer it and 2 frames are missed.
Does mmal keep the second half of the frame, just skip new input frames?
Or is it possible that this data gets dropped?
I have streams with h264 artifacts and after the i-frame count in this broken streams always 2 frames missing.
I never seen errors in the jpeg output, its too not a camera problem(purple), the error is too over the Annotation.
Means its in the h264 encoding stage not in something before that.
- 6by9
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 18476
- Joined: Wed Dec 04, 2013 11:27 am
Re: mmal callback what happends on overflow?
H264 encode via a connection from the camera component?
video_encode will not drop frames. It'll fill internal FIFOs, and eventually get to a point where it refuses to accept input (all input buffers are in use typically).
If the camera component is starved of buffers to store the sensor's data in because it can't get rid of the output data (eg because video_encode is holding on to them all to encode), then new frames from the sensor will be dropped.
Are you passing the H264 buffers into a container? video_encode will split larger frames between multiple buffers, with the MMAL_BUFFER_HEADER_FLAG_FRAME_END flag only on the last buffer making up the frame. All buffers need to be passed to the container writer to make the frame.
video_encode will not drop frames. It'll fill internal FIFOs, and eventually get to a point where it refuses to accept input (all input buffers are in use typically).
If the camera component is starved of buffers to store the sensor's data in because it can't get rid of the output data (eg because video_encode is holding on to them all to encode), then new frames from the sensor will be dropped.
Are you passing the H264 buffers into a container? video_encode will split larger frames between multiple buffers, with the MMAL_BUFFER_HEADER_FLAG_FRAME_END flag only on the last buffer making up the frame. All buffers need to be passed to the container writer to make the frame.
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.
Re: mmal callback what happends on overflow?
Yes with the HQ Camera
status = mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_ENCODER, &h264encoder);
mmal_format_copy(h264encoder->output[0]->format, h264encoder->input[0]->format);
h264encoder->output[0]->format->encoding = MMAL_ENCODING_H264;
source: https://github.com/roberttidey/userland ... aspiMCam.c
The Buffer system had Bugs, it copyed sometimes the complete cycle buffer over to file. Means too old stuff
that does not belong into the file(stuff before the 1st I-Frame) and then trashed the Video. This is fixed.
But the other stuff look well to me, i had no other explain why the video is sometimes (about 1 of 80) broken
on the beginning. I even took only the last 2 I-Frames, to be sure nothing could be overwritten by a huge
Frame for example. I increase the h264 Buffersize to 512kbyte, tryed MinimiseFrag.
Its stuff from the Buffer, after it goes to file there is never a error beyond 2s.
Depending on the Intra Setting its on Frame 13-16, Frame 16 is a I-Frame and fix it again.
The Program use ineffective Logging, it open/write/close for every Single entry. And that from php and gcc to SD Card. I assume this can sometimes take longer as a Video Frame. There is logging on Motion
Detection but no logging while Video goes to File.
status = mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_ENCODER, &h264encoder);
mmal_format_copy(h264encoder->output[0]->format, h264encoder->input[0]->format);
h264encoder->output[0]->format->encoding = MMAL_ENCODING_H264;
source: https://github.com/roberttidey/userland ... aspiMCam.c
The Buffer system had Bugs, it copyed sometimes the complete cycle buffer over to file. Means too old stuff
that does not belong into the file(stuff before the 1st I-Frame) and then trashed the Video. This is fixed.
But the other stuff look well to me, i had no other explain why the video is sometimes (about 1 of 80) broken
on the beginning. I even took only the last 2 I-Frames, to be sure nothing could be overwritten by a huge
Frame for example. I increase the h264 Buffersize to 512kbyte, tryed MinimiseFrag.
Its stuff from the Buffer, after it goes to file there is never a error beyond 2s.
Depending on the Intra Setting its on Frame 13-16, Frame 16 is a I-Frame and fix it again.
The Program use ineffective Logging, it open/write/close for every Single entry. And that from php and gcc to SD Card. I assume this can sometimes take longer as a Video Frame. There is logging on Motion
Detection but no logging while Video goes to File.
Re: mmal callback what happends on overflow?
Reduced Logging, seems really not the Problem.
But mmal calls the callback and its running as a seperate task? Means it leave the other stuff running.
-If the Program tells the callback stop buffering it may still doing the buffering cause already beyond the if(){
-The Program seek(1) in the new file to the space needed for the stuff it is there NOW, but the callback still fill the
buffer.
-Buffering is stopped, Callback writes to the file at pos(1)
-Video is stopped
-Program writes the buffer from 0 up to pos(1), but buffer was not finished, bytes missing.
This race condition would explain it.
But mmal calls the callback and its running as a seperate task? Means it leave the other stuff running.
-If the Program tells the callback stop buffering it may still doing the buffering cause already beyond the if(){
-The Program seek(1) in the new file to the space needed for the stuff it is there NOW, but the callback still fill the
buffer.
-Buffering is stopped, Callback writes to the file at pos(1)
-Video is stopped
-Program writes the buffer from 0 up to pos(1), but buffer was not finished, bytes missing.
This race condition would explain it.
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