// load agora engine public void loadEngine() { // start sdk logAPICall("initializeEngine"); if (mRtcEngine != null) { logAPICall("Engine exists. Please unload it first!"); return; } // init engine mRtcEngine = IRtcEngine.getEngine(mVendorKey); videoRawDataManager = VideoRawDataManager.GetInstance(mRtcEngine); mRtcEngine.EnableVideo(); mRtcEngine.EnableVideoObserver(); mRtcEngine.SetLogFile("/sdcard/test.agora.zhang/agora_sdk.log"); mRtcEngine.SetParameters("{\"rtc.log_filter\": 65535}"); mRtcEngine.SetVideoProfile(VIDEO_PROFILE_TYPE.VIDEO_PROFILE_PORTRAIT_480P_6, true); audioPlaybackDeviceManager = AudioPlaybackDeviceManager.GetInstance(mRtcEngine); audioRecordingoDeviceManager = AudioRecordingDeviceManager.GetInstance(mRtcEngine); videoDeviceManager = VideoDeviceManager.GetInstance(mRtcEngine); metaDataObserver = MetadataObserver.GetInstance(mRtcEngine); packetObserver = PacketObserver.GetInstance(mRtcEngine); audioRawDataManager = AudioRawDataManager.GetInstance(mRtcEngine); videoRawDataManager = VideoRawDataManager.GetInstance(mRtcEngine); // enable log mRtcEngine.SetLogFilter(LOG_FILTER.DEBUG | LOG_FILTER.INFO | LOG_FILTER.WARNING | LOG_FILTER.ERROR | LOG_FILTER.CRITICAL); }
void JoinChannel() { _audioRawDataManager = AudioRawDataManager.GetInstance(mRtcEngine); _audioRawDataManager.RegisterAudioRawDataObserver(); mRtcEngine.SetParameter("che.audio.external_render", true); mRtcEngine.JoinChannelByKey(TOKEN, CHANNEL_NAME, "", 0); }
void OnApplicationQuit() { Debug.Log("OnApplicationQuit"); if (mRtcEngine != null) { mRtcEngine.LeaveChannel(); mRtcEngine.DisableVideoObserver(); if (_audioRawDataManager != null) { AudioRawDataManager.ReleaseInstance(); } IRtcEngine.Destroy(); } }
public void Initialize() { _rtcEngine = IRtcEngine.QueryEngine(); if (_rtcEngine != null) { _audioRawDataManager = AudioRawDataManager.GetInstance(_rtcEngine); _initialized = true; } else { _initialized = false; } }
void SetupAudio(AudioSource aud, string clipName) { _audioRawDataManager = AudioRawDataManager.GetInstance(mRtcEngine); Debug.Assert(_audioRawDataManager.RegisterAudioRawDataObserver() == 0, "Error registering audio rawdata observer!"); mRtcEngine.SetParameter("che.audio.external_render", true); var bufferLength = SAMPLE_RATE / PULL_FREQ_PER_SEC * CHANNEL * 1000; // 10-sec-length buffer audioBuffer = new RingBuffer <float>(bufferLength); _audioClip = AudioClip.Create(clipName, CLIP_SAMPLES, CHANNEL, SAMPLE_RATE, true, OnAudioRead); aud.clip = _audioClip; aud.loop = true; aud.Play(); }
void StartPullAudioFrame(AudioSource aud, string clipName) { _audioRawDataManager = AudioRawDataManager.GetInstance(mRtcEngine); var bufferLength = SAMPLE_RATE / PULL_FREQ_PER_SEC * CHANNEL * 1000; // 10-sec-length buffer audioBuffer = new RingBuffer <float>(bufferLength); _pullAudioFrameThread = new Thread(PullAudioFrameThread); _pullAudioFrameThread.Start(); _audioClip = AudioClip.Create(clipName, SAMPLE_RATE / PULL_FREQ_PER_SEC * CHANNEL, CHANNEL, SAMPLE_RATE, true, OnAudioRead); aud.clip = _audioClip; aud.loop = true; aud.Play(); }
public void initAgoraEngine() { Debug.Log("init agora engine"); mRtcEngine = IRtcEngine.GetEngine(appId); audioRawDataManager = AudioRawDataManager.GetInstance(mRtcEngine); audioRawDataManager.SetOnMixedAudioFrameCallback(OnMixedAudioFrameHandler); audioRawDataManager.SetOnPlaybackAudioFrameBeforeMixingCallback(OnPlaybackAudioFrameBeforeMixingHandler); audioRawDataManager.SetOnPlaybackAudioFrameCallback(OnPlaybackAudioFrameHandler); audioRawDataManager.SetOnRecordAudioFrameCallback(OnRecordAudioFrameHandler); // mRtcEngine.SetLogFilter(LOG_FILTER.INFO); // mRtcEngine.setLogFile("path_to_file_unity.log"); //mRtcEngine.EnableDualStreamMode(true); mRtcEngine.SetClientRole(CLIENT_ROLE.BROADCASTER); //mRtcEngine.SetChannelProfile(CHANNEL_PROFILE.GAME_FREE_MODE); mDataStreamId = GameState.Instance.mRtcEngine.CreateDataStream(true, true); mRtcEngine.OnJoinChannelSuccess += (string channelName, uint uid, int elapsed) => { string joinSuccessMessage = string.Format(debugTag + "joinChannel callback uid: {0}, channel: {1}, version: {2}", uid, channelName, IRtcEngine.GetSdkVersion()); //Debug.Log(joinSuccessMessage); Debug.Log("OnJoinChannelSuccess " + uid); UDID = uid; createCharacter(uid, true); GameState.Instance.PushState(EGameState.ChatRoomState); PopupManager.Instance.showLoadingPopUp(false); }; //mRtcEngine.EnableVideo(); //mRtcEngine.EnableVideoObserver(); mRtcEngine.OnLeaveChannel += (RtcStats stats) => { string leaveChannelMessage = string.Format(debugTag + "onLeaveChannel callback duration {0}, tx: {1}, rx: {2}, tx kbps: {3}, rx kbps: {4}", stats.duration, stats.txBytes, stats.rxBytes, stats.txKBitRate, stats.rxKBitRate); //Debug.Log(leaveChannelMessage); //reloadEngine(); audioRawDataManager.UnRegisteAudioRawDataObserver(); }; mRtcEngine.OnUserJoined += (uint uid, int elapsed) => { string userJoinedMessage = string.Format(debugTag + "onUserJoined callback uid {0} {1}", uid, elapsed); //Debug.Log(userJoinedMessage); Debug.Log("on user joined " + uid); //remote client //GameManager.Instance.createAvatar(uid, string.Empty); NetworkCharacter character = createCharacter(uid); if (lipSyncSolution == ELipSyncSolution.SalsaSolution) { int samplerate = 44100; clipTemp = AudioClip.Create("clipTemp", samplerate * 2, 1, samplerate, false); character.audioSource.clip = clipTemp; character.audioSource.loop = true; character.salsaComponent.audioSrc = character.audioSource; character.salsaComponent.SetAudioClip(character.audioSource.clip); character.audioSource.Play(); //character.salsaComponent.Play(); //character.audioSource.clip = clipTemp; //character.audioSource.Play(); //character.salsaComponent.audioClip = clipTemp; character.salsaComponent.Play(); } }; mRtcEngine.OnUserOffline += (uint uid, USER_OFFLINE_REASON reason) => { string userOfflineMessage = string.Format(debugTag + "onUserOffline callback uid {0} {1}", uid, reason); //Debug.Log(userOfflineMessage); NetworkCharacter character = getCharacterFromID(uid); Destroy(character.gameObject); GameManager.Instance.UserLeaveChannel(uid); }; mRtcEngine.OnVolumeIndication += (AudioVolumeInfo[] speakers, int speakerNumber, int totalVolume) => { if (speakerNumber == 0 || speakers == null) { //Debug.Log(string.Format(debugTag + "onVolumeIndication only local {0}", totalVolume)); } for (int idx = 0; idx < speakerNumber; idx++) { string volumeIndicationMessage = string.Format(debugTag + "{0} onVolumeIndication {1} {2}", speakerNumber, speakers[idx].uid, speakers[idx].volume); //Debug.Log(volumeIndicationMessage); } }; mRtcEngine.OnStreamMessageError += (uint userId, int streamId, int code, int missed, int cached) => { Debug.Log("OnStreamMessageError " + code); }; mRtcEngine.OnStreamMessage += (uint uid, int streamId, string data, int length) => { NetworkCharacter networkCharacter = getCharacterFromID(uid); Debug.Log("receive OnStreamMessage"); networkCharacter.ReceiveLipsyncMessage(data); }; mRtcEngine.OnUserMuted += (uint uid, bool muted) => { string userMutedMessage = string.Format(debugTag + "onUserMuted callback uid {0} {1}", uid, muted); //Debug.Log(userMutedMessage); }; mRtcEngine.OnWarning += (int warn, string msg) => { string description = IRtcEngine.GetErrorDescription(warn); string warningMessage = string.Format(debugTag + "onWarning callback {0} {1} {2}", warn, msg, description); //Debug.Log(warningMessage); }; mRtcEngine.OnError += (int error, string msg) => { string description = IRtcEngine.GetErrorDescription(error); string errorMessage = string.Format(debugTag + "onError callback {0} {1} {2}", error, msg, description); //Debug.Log(errorMessage); }; mRtcEngine.OnRtcStats += (RtcStats stats) => { string rtcStatsMessage = string.Format(debugTag + "onRtcStats callback duration {0}, tx: {1}, rx: {2}, tx kbps: {3}, rx kbps: {4}, tx(a) kbps: {5}, rx(a) kbps: {6} users {7}", stats.duration, stats.txBytes, stats.rxBytes, stats.txKBitRate, stats.rxKBitRate, stats.txAudioKBitRate, stats.rxAudioKBitRate, stats.users); //Debug.Log(rtcStatsMessage); int lengthOfMixingFile = mRtcEngine.GetAudioMixingDuration(); int currentTs = mRtcEngine.GetAudioMixingCurrentPosition(); //string mixingMessage = string.Format(debugTag + "Mixing File Meta {0}, {1}", lengthOfMixingFile, currentTs); // Debug.Log(mixingMessage); }; mRtcEngine.OnAudioRouteChanged += (AUDIO_ROUTE route) => { //string routeMessage = string.Format(debugTag + "onAudioRouteChanged {0}", route); //Debug.Log(routeMessage); }; mRtcEngine.OnRequestToken += () => { string requestKeyMessage = string.Format(debugTag + "OnRequestToken"); //Debug.Log(requestKeyMessage); }; mRtcEngine.OnConnectionInterrupted += () => { string interruptedMessage = string.Format(debugTag + "OnConnectionInterrupted"); //Debug.Log(interruptedMessage); }; mRtcEngine.OnConnectionLost += () => { string lostMessage = string.Format(debugTag + "OnConnectionLost"); //Debug.Log(lostMessage); }; }