The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
[UWP]Issue with Audio Graph playback while sending voice over UDP. RRS feed

  • Question

  • I am currently using Audio Graph to record and playback voice call from microphone. I run Audio Graph in Singleton and calls will create its own node in this Graph instance. Everything works fine when it's a 1 - 1 conversation. But when another call got accepted, I got an exception: "Too many queue frames" in adding new frame to Frame Input Node.

    My graph code

    private async Task InitAudioGraphAsync()
            {
                AudioGraphSettings settings = new AudioGraphSettings(AudioRenderCategory.Media);
                settings.DesiredSamplesPerQuantum = 882;
                settings.QuantumSizeSelectionMode = QuantumSizeSelectionMode.ClosestToDesired;
                CreateAudioGraphResult result = await AudioGraph.CreateAsync(settings);
                if (result.Status != AudioGraphCreationStatus.Success)
                {
                    _logger.Error("AudioGraph creation error: " + result.Status.ToString());
                    return;
                }
                Graph = result.Graph;
    
                Graph.UnrecoverableErrorOccurred += AudioGraphOnUnrecoverableErrorOccurredAsync;
    
                CreateAudioDeviceOutputNodeResult deviceOutputNodeResult = await Graph.CreateDeviceOutputNodeAsync();
                DeviceOutputNode = deviceOutputNodeResult.DeviceOutputNode;
                DeviceOutputNode.Start();
    
                Graph.Start();
                
            }

    UDP Server:

    private async Task StartWithDatagramSocketAsync(DatagramSocket server)
            {
                try
                {
                    await _udpService.StartServerAsync(_dipCall.GetLocalPort().ToString());
                    _dipCall.LogInfo(Name, "Start call");
                    server.MessageReceived += ServerOnMessageReceived;
                }
                catch (Exception exception)
                {
                    _logger.Error(Name + " got " + exception.Message);
                }
            }
    
            private void ServerOnMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
            {
                var reader = args.GetDataReader();
                byte[] data = new byte[reader.UnconsumedBufferLength];
                reader.ReadBytes(data);
    
                try
                {
                    //AudioFrame frame = new AudioFrame((uint)data.Length);
                    AudioFrame frame = new AudioFrame((uint)data.Length);
    
                    using (AudioBuffer buffer = frame.LockBuffer(AudioBufferAccessMode.Write))
                    {
    
                        using (Windows.Foundation.IMemoryBufferReference reference = buffer.CreateReference())
                        {
                            unsafe
                            {
                                byte* dataInBytes;
                                uint capacityInBytes;
                                // float* dataInFloat;
    
                                // Get the buffer from the AudioFrame
                                ((IMemoryBufferByteAccess)reference).GetBuffer(out dataInBytes, out capacityInBytes);
                                                                 
                                fixed (byte* buf = data)
                                {
                                    for (int i = 0; i < buffer.Length; i++)
                                    {
                                        dataInBytes[i] = buf[i];
                                    }
                                }
                            }
                        }
                    }
                    //_queue.Enqueue(frame);
                    _frameInputNode.AddFrame(frame);
                }
                catch (Exception e)
                {
                    throw;
                }
            }

    And Audio Graph handle playback:

    private async void StartPlayingAsync()
            {
                AudioEncodingProperties nodeEncodingProperties = _voiceHandler.Graph.EncodingProperties;
                _frameInputNode = _voiceHandler.Graph.CreateFrameInputNode(nodeEncodingProperties);
    
                // Initialize the Frame Input Node in the stopped state
                _frameInputNode.Stop();
    
                // Hook up an event handler so we can start generating samples when needed
                // This event is triggered when the node is required to provide data
                // frameInputNode.QuantumStarted += OnQuantumStarted;
    
                
                _frameInputNode.AddOutgoingConnection(_voiceHandler.DeviceOutputNode);
                //_frameInputNode.QuantumStarted += OnQuantumStarted;
                _frameInputNode.Start();
            }


    Monday, October 7, 2019 4:40 AM

All replies

  • Could you show more detail about  another call got accepted, I could not reproduce this issue with above code.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 7, 2019 9:59 AM