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

[Bug] Xamarin.iOS delegate AVAudioSinkNodeReceiverHandler gives strange reference to AudioBuffers #17575

Closed
jfversluis opened this issue Feb 20, 2023 · 4 comments · Fixed by #17785
Labels
bug If an issue is a bug or a pull request a bug fix
Milestone

Comments

@jfversluis
Copy link
Member


Issue moved from xamarin/Xamarin.Forms#15694


From @Grubleren on Thursday, February 16, 2023 11:05:32 AM

I am trying to use the iOS sink node as in the following example
Visual Studio 2022 17.4.4
Remote connection to Mac

using System;
using System.Runtime.InteropServices;
using System.Threading;
using Foundation;
using AudioToolbox;
using AVFoundation;
using UIKit;

void SomeFunc()
        {
           var  engine = new AVAudioEngine();
            var inputNode = engine.InputNode;
            var inputFormat = inputNode.GetBusOutputFormat(0);
            var handler = new AVAudioSinkNodeReceiverHandler(SinkHandler);   
            var sinkNode = new AVAudioSinkNode(handler); 
            engine.AttachNode(sinkNode);
            engine.Connect(inputNode, sinkNode, inputFormat);
            NSError error;
            engine.StartAndReturnError(out error);
        }

 int SinkHandler(AudioTimeStamp ts, uint n, ref AudioBuffers buffers)
        {
                    int nCh = buffers.Count;
                    for (int i = 0; i < nCh; i++)
                    {
                        var f = buffers[i].Data;
                        Marshal.Copy(f, data, 0, (int)n);
                    }

            return 0;
        }

The program crash since buffers is not a valid reference to AudioBuffers. Also it is strange to use a ref parameter in the delegate
AVAudioSinkNodeReceiverHandler. I cannot find a way to make it work

@ghost
Copy link

ghost commented Feb 21, 2023

Hi @jfversluis. We have added the "need-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/xamarin/xamarin-macios/blob/main/docs/bug-repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@rolfbjarne rolfbjarne added this to the Future milestone Feb 22, 2023
@ghost
Copy link

ghost commented Mar 1, 2023

Hi @jfversluis. Due to inactivity, we will be closing this issue. Please feel free to re-open this issue if the issue persists. For enhanced visibility, if over 7 days have passed, please open a new issue and link this issue there. Thank you.

@ghost ghost closed this as completed Mar 1, 2023
@Grubleren
Copy link

I have made the repository https://github.com/Grubleren/TestSinkHandler, that clearly demonstrate the problem. Just run the solution.

@rolfbjarne rolfbjarne reopened this Mar 13, 2023
@rolfbjarne rolfbjarne added need-attention An issue requires our attention/response and removed need-repro Waiting for a test case before the bug can be investigated labels Mar 13, 2023
@rolfbjarne rolfbjarne added bug If an issue is a bug or a pull request a bug fix and removed need-attention An issue requires our attention/response labels Mar 14, 2023
@rolfbjarne
Copy link
Member

Thanks, I can reproduce it, and a fix is in progress.

rolfbjarne added a commit that referenced this issue Apr 20, 2023
…ctor. Fixes #17575. (#17785)

The callback to the AVAudioSinkNode constructor was declared incorrectly, and
if used, the app would crash at runtime.

This fix does a few things:

* Creates an overload with callback signature that matches the native API
  (using IntPtrs).
* Writes a custom version for the broken callback signature to make it work
  (and this overload is obsoleted, and removed in XAMCORE_5_0).
* Adds a third overload with the ideal signature.
* Adds tests.

Fixes #17575.
@ghost ghost locked as resolved and limited conversation to collaborators May 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug If an issue is a bug or a pull request a bug fix
Projects
None yet
3 participants