/// <summary> /// Initializes a new instance of the <see cref="SerializableAudioMediaBuffer" /> class. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="participants">The participants.</param> public SerializableAudioMediaBuffer(AudioMediaBuffer buffer, List <IParticipant> participants) { this.participants = participants; Length = buffer.Length; ActiveSpeakers = buffer.ActiveSpeakers; IsSilence = buffer.IsSilence; Timestamp = buffer.Timestamp; if (Length > 0) { Buffer = new byte[Length]; Marshal.Copy(buffer.Data, Buffer, 0, (int)Length); } if (buffer.UnmixedAudioBuffers != null) { SerializableUnmixedAudioBuffers = new SerializableUnmixedAudioBuffer[buffer.UnmixedAudioBuffers.Length]; for (var i = 0; i < buffer.UnmixedAudioBuffers.Length; i++) { if (buffer.UnmixedAudioBuffers[i].Length > 0) { var speakerId = buffer.UnmixedAudioBuffers[i].ActiveSpeakerId; var unmixedAudioBuffer = new SerializableUnmixedAudioBuffer(buffer.UnmixedAudioBuffers[i], _getParticipantFromMSI(speakerId)); SerializableUnmixedAudioBuffers[i] = unmixedAudioBuffer; } } } }
public AudioSendBuffer(AudioMediaBuffer mediaBuffer, AudioFormat format, ulong timeStamp) { IntPtr unmanagedBuffer = Marshal.AllocHGlobal((int)mediaBuffer.Length); CopyMemory(unmanagedBuffer, mediaBuffer.Data, (uint)mediaBuffer.Length); Data = unmanagedBuffer; Length = mediaBuffer.Length; AudioFormat = format; Timestamp = (long)timeStamp; }
/// <summary> /// Appends the audio buffer. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="participants">The participants.</param> public async Task AppendAudioBuffer(AudioMediaBuffer buffer, List <IParticipant> participants) { if (!_isRunning) { await _start(); } try { await _buffer.SendAsync(new SerializableAudioMediaBuffer(buffer, participants), _tokenSource.Token).ConfigureAwait(false); } catch (TaskCanceledException e) { _buffer?.Complete(); _logger.Error(e, "Cannot enqueue because queuing operation has been cancelled"); } }