Linking with FFmpeg

H. S. Teoh hsteoh at quickfur.ath.cx
Sun Jan 6 07:27:20 PST 2013


On Sun, Jan 06, 2013 at 10:48:25AM +0100, MrOrdinaire wrote:
> Hi,
> 
> I am working on D bindings for FFmpeg. I am trying to port the
> official examples of FFmpeg to D so that the bindings can be tested.
> 
> My question is how this function declaration is written in D.
> int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
>                    int w, int h, enum AVPixelFormat pix_fmt, int
> align);
> 
> My best guess is the following.
> extern(C) int av_image_alloc(ref uint8_t[4] *pointers, ref int[4]
> linesizes,
>                              int w, int h, AVPixelFormat pix_fmt,
> int align_);

The first parameter should be: uint8_t* pointers, and you need to call
it like this:

	uint8_t[4] pointers;
	int[4] linesizes;
	auto ret = av_image_alloc(pointers.ptr, linesizes.ptr, ...);

To make it D-friendly, you might want to consider using a wrapper
function that takes ref uint8_t[4] and ref int[4] instead.


> However, calling this would give nonsense value for the array passed
> as linesizes. I don't know how to look at the variable passed as
> pointers yet.
[...]

Just write *ptr to dereference a pointer. You can also take advantage of
D's auto-dereferencing:

	struct S {
		int val = 123;
	}
	S s;
	S* ptr = &s;
	writeln(s.val);		// prints 123
	writeln(ptr.val);	// also prints 123 (ptr is automatically
				// dereferenced)

Finally, please note that in D, the * in pointer types associate with
the _type_ rather than the variable name (as in C/C++), so you should
always write "int* x,y" instead of "int *x, *y". Similarly, an array of
pointers is written as "int*[] arr", whereas writing "int[]* arr" is
actually declaring a pointer to an array. (In D, pointers and arrays are
not the same thing.)


T

-- 
I don't trust computers, I've spent too long programming to think that
they can get anything right. -- James Miller


More information about the Digitalmars-d-learn mailing list