123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- using ManageLiteAV;
- using System;
- using Vinno.FIS.TRTCClient.Common.Log;
- using static Vinno.FIS.TRTCClient.TRTCPusher;
- namespace Vinno.FIS.TRTCClient
- {
- internal class CameraDetector : ITRTCCloudCallback, IDisposable
- {
- private ITRTCCloud _tRTCCloud;
- private ITXDeviceManager _deviceManager;
- public event EventHandler<TRTCDeviceInfo> DeviceUpdated;
- public CameraDetector()
- {
- _tRTCCloud = ITRTCCloud.getTRTCShareInstance();
- _deviceManager = _tRTCCloud.getDeviceManager();
- _tRTCCloud.addCallback(this);
- }
- /// <summary>
- /// Get the Correct Id
- /// </summary>
- /// <param name="type"></param>
- /// <param name="deviceId"></param>
- /// <returns></returns>
- public string GetCorrectId(HardwareType type, string deviceId)
- {
- if (string.IsNullOrEmpty(deviceId))
- {
- return string.Empty;
- }
- TRTCDeviceType trtcDeviceType = TRTCDeviceType.TXMediaDeviceTypeUnknown;
- switch (type)
- {
- case HardwareType.Camera:
- trtcDeviceType = TRTCDeviceType.TXMediaDeviceTypeCamera;
- break;
- case HardwareType.Mic:
- trtcDeviceType = TRTCDeviceType.TXMediaDeviceTypeMic;
- break;
- case HardwareType.Speaker:
- trtcDeviceType = TRTCDeviceType.TXMediaDeviceTypeSpeaker;
- break;
- }
- var hardwareList = _deviceManager.getDevicesList(trtcDeviceType);
- try
- {
- var count = hardwareList.getCount();
- for (uint i = 0; i < count; i++)
- {
- var id = hardwareList.getDevicePID(i);
- if (deviceId.Contains(id) || id.Contains(deviceId))
- {
- return id;
- }
- }
- }
- finally
- {
- hardwareList.release();
- }
- return string.Empty;
- }
- public void onSpeedTest(TRTCSpeedTestResult currentResult, uint finishedCount, uint totalCount)
- {
- }
- public void onTestMicVolume(uint volume)
- {
- }
- public void onTestSpeakerVolume(uint volume)
- {
- }
- public void Dispose()
- {
- if (_tRTCCloud != null)
- {
- _tRTCCloud.removeCallback(this);
- _deviceManager = null;
- _tRTCCloud = null;
- }
- }
- #region Unused
- public void onAudioDeviceCaptureVolumeChanged(uint volume, bool muted)
- {
- // throw new NotImplementedException();
- }
- public void onAudioDevicePlayoutVolumeChanged(uint volume, bool muted)
- {
- // throw new NotImplementedException();
- }
- public void onAudioEffectFinished(int effectId, int code)
- {
- // throw new NotImplementedException();
- }
- public void onCameraDidReady()
- {
- Logger.WriteLineInfo("onCameraDidReady Invoke");
- }
- public void onConnectionLost()
- {
- // throw new NotImplementedException();
- }
- public void onConnectionRecovery()
- {
- // throw new NotImplementedException();
- }
- public void onConnectOtherRoom(string userId, TXLiteAVError errCode, string errMsg)
- {
- // throw new NotImplementedException();
- }
- public void onDeviceChange(string deviceId, TRTCDeviceType type, TRTCDeviceState state)
- {
- Logger.WriteLineInfo($"Camera Detector DeviceChange:{deviceId},type:{type},state:{state}");
- if (type == TRTCDeviceType.TXMediaDeviceTypeCamera)
- {
- DeviceUpdated?.Invoke(this, new TRTCDeviceInfo(deviceId, type, state));
- }
- }
- public void onDisconnectOtherRoom(TXLiteAVError errCode, string errMsg)
- {
- //throw new NotImplementedException();
- }
- public void onEnterRoom(int result)
- {
- //throw new NotImplementedException();
- }
- public void onError(TXLiteAVError errCode, string errMsg, IntPtr arg)
- {
- //throw new NotImplementedException();
- }
- public void onExitRoom(int reason)
- {
- //throw new NotImplementedException();
- }
- public void onFirstAudioFrame(string userId)
- {
- // throw new NotImplementedException();
- }
- public void onFirstVideoFrame(string userId, TRTCVideoStreamType streamType, int width, int height)
- {
- // throw new NotImplementedException();
- }
- public void onMicDidReady()
- {
- // throw new NotImplementedException();
- }
- public void onMissCustomCmdMsg(string userId, int cmdId, int errCode, int missed)
- {
- // throw new NotImplementedException();
- }
- public void onNetworkQuality(TRTCQualityInfo localQuality, TRTCQualityInfo[] remoteQuality, uint remoteQualityCount)
- {
- // throw new NotImplementedException();
- }
- public void onPlayBGMBegin(TXLiteAVError errCode)
- {
- // throw new NotImplementedException();
- }
- public void onPlayBGMComplete(TXLiteAVError errCode)
- {
- // throw new NotImplementedException();
- }
- public void onPlayBGMProgress(uint progressMS, uint durationMS)
- {
- // throw new NotImplementedException();
- }
- public void onRecvCustomCmdMsg(string userId, int cmdID, uint seq, byte[] msg, uint msgSize)
- {
- // throw new NotImplementedException();
- }
- public void onRecvSEIMsg(string userId, byte[] message, uint msgSize)
- {
- // throw new NotImplementedException();
- }
- public void onRemoteUserEnterRoom(string userId)
- {
- // throw new NotImplementedException();
- }
- public void onRemoteUserLeaveRoom(string userId, int reason)
- {
- // throw new NotImplementedException();
- }
- public void onScreenCaptureCovered()
- {
- // throw new NotImplementedException();
- }
- public void onScreenCapturePaused(int reason)
- {
- // throw new NotImplementedException();
- }
- public void onScreenCaptureResumed(int reason)
- {
- // throw new NotImplementedException();
- }
- public void onScreenCaptureStarted()
- {
- // throw new NotImplementedException();
- }
- public void onScreenCaptureStoped(int reason)
- {
- // throw new NotImplementedException();
- }
- public void onSendFirstLocalAudioFrame()
- {
- // throw new NotImplementedException();
- }
- public void onSendFirstLocalVideoFrame(TRTCVideoStreamType streamType)
- {
- // throw new NotImplementedException();
- }
- public void onSetMixTranscodingConfig(int errCode, string errMsg)
- {
- //throw new NotImplementedException();
- }
- public void onStartPublishCDNStream(int errCode, string errMsg)
- {
- // throw new NotImplementedException();
- }
- public void onStartPublishing(int errCode, string errMsg)
- {
- // throw new NotImplementedException();
- }
- public void onStatistics(TRTCStatistics statis)
- {
- //throw new NotImplementedException();
- }
- public void onStopPublishCDNStream(int errCode, string errMsg)
- {
- // throw new NotImplementedException();
- }
- public void onStopPublishing(int errCode, string errMsg)
- {
- // throw new NotImplementedException();
- }
- public void onSwitchRole(TXLiteAVError errCode, string errMsg)
- {
- // throw new NotImplementedException();
- }
- public void onSwitchRoom(TXLiteAVError errCode, string errMsg)
- {
- // throw new NotImplementedException();
- }
- public void onTryToReconnect()
- {
- // throw new NotImplementedException();
- }
- public void onUserAudioAvailable(string userId, bool available)
- {
- // throw new NotImplementedException();
- }
- public void onUserEnter(string userId)
- {
- // throw new NotImplementedException();
- }
- public void onUserExit(string userId, int reason)
- {
- // throw new NotImplementedException();
- }
- public void onUserSubStreamAvailable(string userId, bool available)
- {
- // throw new NotImplementedException();
- }
- public void onUserVideoAvailable(string userId, bool available)
- {
- // throw new NotImplementedException();
- }
- public void onUserVoiceVolume(TRTCVolumeInfo[] userVolumes, uint userVolumesCount, uint totalVolume)
- {
- // throw new NotImplementedException();
- }
- public void onWarning(TXLiteAVWarning warningCode, string warningMsg, IntPtr arg)
- {
- // throw new NotImplementedException();
- }
- #endregion Unused
- }
- }
|