0

I am learning to understand the how v4l2_based drivers work, and subsequently system calls as well. As a part of that working on decoder driver. So I need to take the buffer data out after the qbuf system-call after it is getting transferred to the vb2_bufffer from v4l2_buffer. I am required to dump data after qbuf as there is no decoder involved by calculating the size I can verify my system call is working. I have developed a driver which have all the required system call, but because there is no secific hardware decoder is there can't check woth playback. Please do suggest other ideas to debug as well.

just for referance : https://elixir.bootlin.com/linux/v6.10/source/drivers/media/common/videobuf2/videobuf2-core.c#L1799

I tried dumping the data in qbuf using the following method but it is not working it seems.

in qbuf system call taken out vb(vb2_buffer) from vq(vb2_queue) using one function buffer = vb2_plane_vaddr (). and calculated size using size = vb2_plane_size() using the above passed size and buffer, passed it to a file_saver_function()


void save_buffer_to_file(const char *filename, void *buffer, size_t size) {
 struct file *file;
 mm_segment_t old_fs;
 loff_t pos = 0;
 printk(KERN_INFO " >> Saving buffer of size %d \n", size);
 if (!buffer || size == 0) {
 printk(KERN_ERR "save_buffer_to_file: Invalid buffer or size\n");
 return;
 }
 old_fs = get_fs();
 set_fs(KERNEL_DS);
 file = filp_open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
 if (IS_ERR(file)) {
 printk(KERN_ERR "save_buffer_to_file: Failed to open file %s\n", filename);
 set_fs(old_fs);
 return;
 }
 kernel_write(file, buffer, size, &pos);
 filp_close(file, NULL);
 set_fs(old_fs);
}

But not getting the expected results.

I am very new to kernel/driver world, I am trying my best to learn and understand things as fast as I can. If I am missing any details which is making my question confusing please do tell.

asked Jul 22, 2024 at 5:32
4
  • I'm not the one to answer about Video4Linux drivers, but while you wait... (1) Please clarify (from your settings) what the buffer data's format s supposed to be. Did you get raw RGB or raw YUV buffer returned from the driver's capture? (2) Does your saved file (one frame's buffer) show as pixels on the Pixpeep site, where if the RGB setting does not work then try instead selecting I420 etc etc .. (3) Video just means "sequence of pictures", is it possible you only get multiple bitmaps that need encoding into an actual video format like MP4? Commented Jul 22, 2024 at 10:44
  • point 1: YUV format point 2 : I am not allowed to upload from my system so not able to check, though can confirm on streameye it is not showing much pixel, what I understand is I have saved raw buffer data which has no related data like timeline etc. 3 . I am not sure about bitmaps much but surely that is possible that it needs further encoding. Commented Jul 30, 2024 at 12:56
  • (1) Can you find out if YUV means YUV444p or YUV420p? You'll need that info later when encoding. (2) If you can run StreamEye does that mean you can run another tool such as FFmpeg? If yes, install it and try this command on a saved frame buffer (you save a buffer as it is given, but use extension .yuv in the file name). Use -framerate 1 for testing. Use correct width/height for your buffer. Not clear if your YUV format is actually yuv420p10le or something else. Commented Aug 1, 2024 at 10:47
  • PS: What is your definition of "playable file"? If you want to play in software like VLC or a web browser, then the YUV data will have to be written into MP4 (using FFmpeg or HandBrake or such tools). If you just want to preview inside your own app then simply use a YUV_to_RGB converter function on the buffer data then display the output RGB as pixels in your app or new window. I don't do pixel displaying in C so cannot advise about that part.. Commented Aug 1, 2024 at 10:47

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.