inac
Posts: 19
Joined: Thu Nov 16, 2017 3:58 pm

rawcam and corrupted trailer

Mon Feb 18, 2019 4:46 pm

I’m trying to get my custom camera to work. The path I use is [rawcam] -> [isp] -> [image_encoder]. RAW12

My port parameters are

Code: Select all

*************** Port parameters ***************
CAM Out                                        ->  [  ISP In      -   ISP out  ]  ->  [ Encoder In    - Encoder out  ]
type                                   OUTPUT  ->       INPUT     -      OUTPUT   ->        INPUT     -     OUTPUT  
enabled                                    1   ->           1     -           1   ->            1     -          1 
format->type                               3   ->           3     -           3   ->            3     -          3 
format->encoding                        pR12   ->        pR12     -        I420   ->         I420     -       JPEG 
format->es->video->width                3968   ->        3968     -        3968   ->         3968     -          0 
format->es->video->height               3040   ->        3040     -        3040   ->         3040     -          0 
format->es->video->crop->width          3968   ->        3968     -        3968   ->         3968     -          0 
format->es->video->crop->height         3040   ->        3040     -        3040   ->         3040     -          0 
format->extradata_size                     0   ->           0     -           0   ->            0     -          0 
format->extradata                          0   ->           0     -           0   ->            0     -          0 
buffer_num                                 4   ->           4     -           1   ->            1     -          1 
buffer_size                         18094080   ->    18094080     -    18094080   ->     18094080     -   12062720 
buffer_num_min                             4   ->           1     -           1   ->            1     -          1 
buffer_size_min                     18094080   ->    18094080     -    18094080   ->     18094080     -   12062720 
buffer_num_recommended                     4   ->           1     -           1   ->            1     -          1 
buffer_size_recommended             18094080   ->    18094080     -    18094080   ->     18094080     -   12062720 

The path is giving correct images but it crashes. When I look at the

Code: Select all

sudo /opt/vc/bin/vcdbg reloc

I get a corrupt trailer.

Code: Select all

Relocatable heap version 4 found at 0x20000000
total space allocated is 492M, with 492M relocatable, 0 legacy and 0 offline
0 legacy blocks of size 2359296

free list at 0x3ebffda0
439M free memory in 2 free block(s)
largest free block is 439M bytes

0x20000000: free 439M
[   8] 0x3b6b2480: used  17M (refcount 0 lock count 0, size 18094080, align   32, data 0x3b6b24a0, d1rual) 'ril.rawcam:out:0(pR12)'
0x3b6b2480: corrupt trailer (space 1431655680 != 18094145)
0x3c7f3cc0: corrupt entry (space 0x55edbd55)
resynced at 0x3ebeed60 (skipped 37728416 bytes)
[   2] 0x3ebeed60: used  16K (refcount 1 lock count 0, size    16384, align   32, data 0x3ebeed80, d0ruAl) 'audioplus_tmp_buf'
[   1] 0x3ebf2da0: used 4.0K (refcount 1 lock count 0, size        0, align 4096, data 0x3ebf3000, d1rual) 'camera fast alloc arena'
[   3] 0x3ebf3dc0: used  47K (refcount 1 lock count 0, size    48483, align    1, data 0x3ebf3de0, d0rual) 'dt_blob'
0x3ebffb80: free 576
[   5] 0x3ebffdc0: used  576 (refcount 1 lock count 0, size      512, align    4, data 0x3ebffde0, d0rual) 'ILCS VC buffer pool'
heap corruption detected
small allocs not requested

When I only comment out the following line

Code: Select all

    output->format->es->video.crop.width = roi.width;
    output->format->es->video.crop.height = roi.height;
    //output->format->es->video.width = VCOS_ALIGN_UP(roi.width, 16);
    output->format->es->video.height = VCOS_ALIGN_UP(roi.height, 16);

I get strange port parameters at the video->width.

Code: Select all

*************** Port parameters ***************
CAM Out                                        ->  [  ISP In      -   ISP out  ]  ->  [ Encoder In    - Encoder out  ]
type                                   OUTPUT  ->       INPUT     -      OUTPUT   ->        INPUT     -     OUTPUT  
enabled                                    1   ->           1     -           1   ->            1     -          1 
format->type                               3   ->           3     -           3   ->            3     -          3 
format->encoding                        pR12   ->        pR12     -        I420   ->         I420     -       JPEG 
format->es->video->width                   0   ->           0     -        3968   ->         3968     -          0 
format->es->video->height               3040   ->        3040     -        3040   ->         3040     -          0 
format->es->video->crop->width          3968   ->        3968     -        3968   ->         3968     -          0 
format->es->video->crop->height         3040   ->        3040     -        3040   ->         3040     -          0 
format->extradata_size                     0   ->           0     -           0   ->            0     -          0 
format->extradata                          0   ->           0     -           0   ->            0     -          0 
buffer_num                                 4   ->           4     -           1   ->            1     -          1 
buffer_size                         18094080   ->    18094080     -    18094080   ->     18094080     -   12062720 
buffer_num_min                             4   ->           1     -           1   ->            1     -          1 
buffer_size_min                            0   ->    18094080     -    18094080   ->     18094080     -   12062720 
buffer_num_recommended                     4   ->           1     -           1   ->            1     -          1 
buffer_size_recommended                    0   ->    18094080     -    18094080   ->     18094080     -   12062720

And reboot the RPi. Then running the program again the corrupted trailer is gone.

Code: Select all

Relocatable heap version 4 found at 0x20000000
total space allocated is 492M, with 492M relocatable, 0 legacy and 0 offline
0 legacy blocks of size 2359296

free list at 0x3ebffda0
490M free memory in 2 free block(s)
largest free block is 490M bytes

0x20000000: free 490M
[   4] 0x3ea76d40: used 1.5M (refcount 1 lock count 8, size  1536000, align 4096, data 0x3ea77000, d1rual) 'ARM FB'
[   2] 0x3ebeed60: used  16K (refcount 1 lock count 0, size    16384, align   32, data 0x3ebeed80, d0ruAl) 'audioplus_tmp_buf'
[   1] 0x3ebf2da0: used 4.0K (refcount 1 lock count 0, size        0, align 4096, data 0x3ebf3000, d1rual) 'camera fast alloc arena'
[   3] 0x3ebf3dc0: used  47K (refcount 1 lock count 0, size    48483, align    1, data 0x3ebf3de0, d0rual) 'dt_blob'
0x3ebffb80: free 576
[   5] 0x3ebffdc0: used  576 (refcount 1 lock count 0, size      512, align    4, data 0x3ebffde0, d0rual) 'ILCS VC buffer pool'
small allocs not requested

But I get empty black images.

Why is this happening and how can I debug?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7026
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: rawcam and corrupted trailer

Tue Feb 19, 2019 2:11 pm

The CSI2 receiver peripheral takes a start and an end address, so should never exceed those bounds. Indeed it can work in a circular buffer mode where it'll return back to the start should the amount of data exceed the buffer size - that mode hasn't been tested for a VERY long time, so I couldn't say whether it reliably works. It's not used with rawcam anyway as we only signal when the whole buffer is complete.

In your "normal" situation, I'd say that the CSI2 source is sending more than 3040 lines of data, and it is managing to overflow the buffer. Add a couple of lines to format->es->video->height and it'll probably be happy as you've added padding to the buffer should it overrun.
The frame is signalled as "complete" when the "frame end" short packet is received on the CSI2 bus, therefore it doesn't actually matter what format->es->video->[crop.]height are set to beyond setting up buffer sizes and telling downstream components.

Setting output->format->es->video.width to 0 is a nonsense configuration, and I'm surprised it allowed you to in the mmal_port_format_commit.
You've set the stride (the address increment between one line to the next) to 0, therefore it'll start writing line 1 to memory at the start of the buffer, and then increment so line 2 starts at "start + 1*stride", which is still start if stride = 0. I suspect that the first line of your "black" image has data in it, and then the rest is uninitialised and happens to be 0.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

inac
Posts: 19
Joined: Thu Nov 16, 2017 3:58 pm

Re: rawcam and corrupted trailer

Wed Feb 27, 2019 3:49 pm

Thanks! That give a nice view what's going on. Apparently the camera gives a few lines more out than we set.

Return to “Camera board”