Hello,
On 12/21/2013 05:05 AM, Marc Giger wrote:
> I'm using the javacpp ffmpeg presets and have implemented custom I/O via the avio_alloc_context which works fine so far.
> Now I need multiple I/O streams and therefore also independent callback handlers for each stream.
> I'm aware of the limitation that just one callback handler can be used at the same time and also
> read in this forum that so called C++ functors may be used to circumvent this limitation.
Yes, that works for C++, but FFmpeg is C, so that's not going to work.
The way to work around that at the moment is by declaring multiple
allocate() methods, and use a different one for each of the instances of
the FunctionPointer, for example:
public static class Read_packet_Pointer_BytePointer_int extends
FunctionPointer {
static { Loader.load(); }
protected native void allocate();
protected native void allocate2();
protected native void allocate3();
protected native void allocate4();
protected native void allocate5();
protected native void allocate6();
// etc
public native int call(Pointer opaque, @Cast("uint8_t*")
BytePointer buf, int buf_size);
}
And then in your code (I think those could still be anonymous classes):
public static class FirstStreamRead extends
Read_packet_Pointer_BytePointer_int {
FirstStreamRead() { allocate(); }
public int call(Pointer opaque, BytePointer buf, int buf_size) {
return 0;
}
}
public static class SecondStreamRead extends
Read_packet_Pointer_BytePointer_int {
SecondStreamRead() { allocate2(); }
public int call(Pointer opaque, BytePointer buf, int buf_size) {
return 0;
}
}
// etc
The Parser doesn't generate those, for now, but I guess it's something
we could add...
Actually, I think the correct name for that is "function object", as
mentioned here for example:
http://www.cplusplus.com/reference/functional/
Samuel