Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVIOInterruptCB code example #49

Open
niclasastrom opened this issue Oct 6, 2024 · 1 comment
Open

AVIOInterruptCB code example #49

niclasastrom opened this issue Oct 6, 2024 · 1 comment

Comments

@niclasastrom
Copy link

Hi!

I'm struggling to set up an AVIOInterruptCB function, and I can't find a working example.
I use .NET6 and FFmpeg.Autogen 6.1

Can someone please share a working code example?

Kind regards,
Niclas

@Sophisticated-IS
Copy link

Sophisticated-IS commented Oct 10, 2024

Hi, this one made by myself. But I still have problem of unsubscription and making nullable the callback pointer. Because for me it is does not work and delegate function is calling forever while there are IO operations until AvFormatContext is completely disposed(freed)/ I have not found any possibility how to free or reassign pointer to delegate so it won't be called any more.
Ofc, this not work context->interrupt_callback.callback.Pointer = IntPtr.Zero; Also if I free my delegate app just will crush with EngineExecutionError.

Simple Example:
Version 6.1.0.1

`public unsafe class InterruptingAvFormatContext : IDisposable
{
private readonly CancellationToken _token;
private GCHandle _gcHandle;

public InterruptingAvFormatContext(AVFormatContext* context, CancellationToken token)
{
    _token = token;

    AVIOInterruptCB_callback interruptDelegate = Interrupt_IO;
    _gcHandle = GCHandle.Alloc(interruptDelegate);

    context->interrupt_callback = new()
    {
        callback = interruptDelegate,
        opaque = null
    };
}

private int Interrupt_IO(void* opaque)
{
    return _token.IsCancellationRequested? 1:0;
}

public void Dispose()
{
    if (_gcHandle.IsAllocated)
    {
        _gcHandle.Free();    
    }
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants