av_image_fill_plane_sizes ulong_array4 does not get filled (because not passed as ref/out)
- [x] bug report
-
What is the current behavior? "out" array parameters passed as array without ref/out or out modifier don't seem towork. For example av_image_fill_plane_sizes
-
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem:
[Test]
public void TestFfmpegAutoGenArrayResults()
{
ffmpeg.RootPath = AutoDetectBinaryLibraryFolder();
AVPixelFormat pixelFormat = AVPixelFormat.AV_PIX_FMT_BGRA;
int w = 640, h = 480;
//get line sizes. That works, because parameter linesizes is ref parameter:
int_array4 linesizes = new int_array4();
ffmpeg.av_image_fill_linesizes(ref linesizes, pixelFormat, w).ThrowExceptionIfFFmpegError();
Assert.That(linesizes[0] == w * 4); //OK
//for some funny reason av_image_fill_plane_sizes needs long array rather than int array for line sizes.
//as noted here https://ffmpeg.org/doxygen/trunk/group__lavu__picture.html#ga58cffc1b2c32f1f186144e81176128eb
var longLineSizes = new long_array4
{ [0] = linesizes[0], [1] = linesizes[1], [2] = linesizes[2], [3] = linesizes[3] };
//get sizes. That does not work, because parameter sizes is passed by value and array is not copied back by
//marshaller it seems
ulong_array4 sizes = new ulong_array4();
ffmpeg.av_image_fill_plane_sizes(sizes, pixelFormat, h, longLineSizes).ThrowExceptionIfFFmpegError();
Assert.That(sizes[0] > 0); // fails
}
-
What is the expected behavior? ffmpeg.av_image_fill_plane_sizes should change content of the sizes array
-
Please tell us about your environment: Windows X64,
- version: FFmpeg.Autogen5.0 Nuget Packate
- Other information I think this is similar to #182. And it's not limited to Mac, behaviour on windows it is the same. IMHO "OUT" array parameters need to be passed by ref. ("out" is technically possible, but would need manual validation how the parameter is used). If I create an overload with ref, thinkgs work fine. Other than that: great library! Thank you very much for making it!
Thank you for the analysis. I'll take it over from here - have do tipple check my myself int av_image_fill_plane_sizes(size_t size[4], enum AVPixelFormat pix_fmt, int height, const ptrdiff_t linesizes[4]); as original declaration includes const and seems it used to be a problem before.
Could you please check/test - ffmpeg_abstractions branch. I do think it should fix the problem as I forced ref for any none const array.
Forming new way of API here https://github.com/Ruslan-B/FFmpeg.AutoGen/issues/210 - all none const array parameters are ref now.
tested, works like a charm now!
Closed to yearly but okay. I'll do all preparations to migrate to new packages completely.
I thought getting up and seeing the open issue list decreased by 30% from 6 to 4 makes for a good morning :-)
The abstraction stuff is already published on nuget.org, you are aware of that? I think that's a bit confusing because FFmpeg.AutoGen 5.1.1 uses the old fixed array structs, while FFmpeg.AutoGen.Abstractions 5.1.1 uses the new ones. So unifying them with a new 5.1.2 version number might be a good thing.