Skip to content

Instantly share code, notes, and snippets.

@troy-lamerton
Last active March 17, 2019 22:56
Show Gist options
  • Save troy-lamerton/978bd2d3e0d6c405ea5c02a24fe932e8 to your computer and use it in GitHub Desktop.
Save troy-lamerton/978bd2d3e0d6c405ea5c02a24fe932e8 to your computer and use it in GitHub Desktop.
// Pass the callback to the modified Client Start method
public void Initialize(SWIGTYPE_p_f_p_void_p_q_const__char_p_q_const__char_p_short_int_int_int_int__void receivedAudio) {
if (_initialized)
return;
VxClient.Instance.Start(receivedAudio);
_initialized = true;
}
/*
This file has the callback which should receive audio data
*/
public class CommandProcessor : MonoBehaviour
// ...
delegate void AudioReceivedDelegate(Action cb, char[] a, char[] b, short c, int d, int e, int f, int g);
private void OnAudioDataCallback(Action cb, char[] a, char[] b, short c, int d, int e, int f, int g) {
throw new NotImplementedException();
}
IAsyncResult BeginBuildClient(Uri webService, AsyncCallback callback)
{
if (String.IsNullOrEmpty(webService.ToString())) throw new ArgumentNullException("webService", "Specify a non-null argument.");
var result = new AsyncResult<Client>(callback);
var audioReceivedCallback = new SWIGTYPE_p_f_p_void_p_q_const__char_p_q_const__char_p_short_int_int_int_int__void(
Marshal.GetFunctionPointerForDelegate(new AudioReceivedDelegate(OnAudioDataCallback)), true);
_client.Initialize(audioReceivedCallback);
// ...
}
// ...
}
public void Start(SWIGTYPE_p_f_p_void_p_q_const__char_p_q_const__char_p_short_int_int_int_int__void receivedAudio) {
if (_startCount > 0) {
++_startCount;
return;
}
VivoxDebug.Instance.debugLocation = 0;
vx_sdk_config_t config = new vx_sdk_config_t();
VivoxCoreInstance.vx_get_default_config(config);
config.initial_log_level = (vx_log_level)2;
// set the audio received callback
config.pf_on_audio_unit_before_recv_audio_rendered = receivedAudio;
int status = VivoxCoreInstance.Initialize(config);
if (status != 0)
throw new VivoxApiException(status);
MessagePump.Instance.MainLoopRun += InstanceOnMainLoopRun;
++_startCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment