/// <summary>
        /// Initializes a new instance of the <see cref="BotMediaStream" /> class.
        /// </summary>
        /// <param name="mediaSession">he media session.</param>
        /// <param name="callId">The call identity</param>
        /// <param name="logger">The logger.</param>
        /// <param name="eventPublisher">Event Publisher</param>
        /// <param name="settings">Azure settings</param>
        /// <exception cref="InvalidOperationException">A mediaSession needs to have at least an audioSocket</exception>
        public BotMediaStream(
            ILocalMediaSession mediaSession,
            string callId,
            IGraphLogger logger,
            IEventPublisher eventPublisher,
            IAzureSettings settings
            )
            : base(logger)
        {
            ArgumentVerifier.ThrowOnNullArgument(mediaSession, nameof(mediaSession));
            ArgumentVerifier.ThrowOnNullArgument(logger, nameof(logger));
            ArgumentVerifier.ThrowOnNullArgument(settings, nameof(settings));

            this.participants = new List <IParticipant>();

            _eventPublisher = eventPublisher;
            _callId         = callId;
            _mediaStream    = new MediaStream(
                settings,
                logger,
                mediaSession.MediaSessionId.ToString()
                );

            // Subscribe to the audio media.
            this._audioSocket = mediaSession.AudioSocket;
            if (this._audioSocket == null)
            {
                throw new InvalidOperationException("A mediaSession needs to have at least an audioSocket");
            }

            this._audioSocket.AudioMediaReceived += this.OnAudioMediaReceived;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BotMediaStream"/> class.
        /// </summary>
        /// <param name="mediaSession">The media session.</param>
        /// <param name="logger">Graph logger.</param>
        /// <exception cref="InvalidOperationException">Throws when no audio socket is passed in.</exception>
        public BotMediaStream(ILocalMediaSession mediaSession, IGraphLogger logger)
        {
            ArgumentVerifier.ThrowOnNullArgument(mediaSession, "mediaSession");

            this.mediaSession              = mediaSession;
            this.logger                    = logger;
            this.audioSendStatusActive     = new TaskCompletionSource <bool>();
            this.videoSendStatusActive     = new TaskCompletionSource <bool>();
            this.startVideoPlayerCompleted = new TaskCompletionSource <bool>();

            this.audioSocket = this.mediaSession.AudioSocket;
            if (this.audioSocket == null)
            {
                throw new InvalidOperationException("A mediaSession needs to have at least an audioSocket");
            }

            this.audioSocket.AudioSendStatusChanged += this.OnAudioSendStatusChanged;

            this.mainVideoSocket = this.mediaSession.VideoSockets?.FirstOrDefault();
            if (this.mainVideoSocket != null)
            {
                this.mainVideoSocket.VideoSendStatusChanged += this.OnVideoSendStatusChanged;
                this.mainVideoSocket.VideoKeyFrameNeeded    += this.OnVideoKeyFrameNeeded;
            }

            this.videoSockets = this.mediaSession.VideoSockets?.ToList();

            this.vbssSocket = this.mediaSession.VbssSocket;
            if (this.vbssSocket != null)
            {
                this.vbssSocket.VideoSendStatusChanged += this.OnVbssSocketSendStatusChanged;
            }

            var ignoreTask = this.StartAudioVideoFramePlayerAsync().ForgetAndLogExceptionAsync(this.logger, "Failed to start the player");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BotMediaStream"/> class.
        /// </summary>
        /// <param name="mediaSession">The media session.</param>
        /// <param name="logger">Graph logger.</param>
        /// <exception cref="InvalidOperationException">Throws when no audio socket is passed in.</exception>
        public BotMediaStream(ILocalMediaSession mediaSession, IGraphLogger logger)
            : base(logger)
        {
            ArgumentVerifier.ThrowOnNullArgument(mediaSession, nameof(mediaSession));
            ArgumentVerifier.ThrowOnNullArgument(logger, nameof(logger));

            this.mediaSession = mediaSession;

            // Subscribe to the audio media.
            this.audioSocket = mediaSession.AudioSocket;
            if (this.audioSocket == null)
            {
                throw new InvalidOperationException("A mediaSession needs to have at least an audioSocket");
            }

            this.audioSocket.AudioMediaReceived += this.OnAudioMediaReceived;

            // Subscribe to the video media.
            this.videoSockets = this.mediaSession.VideoSockets?.ToList();
            if (this.videoSockets?.Any() == true)
            {
                this.videoSockets.ForEach(videoSocket => videoSocket.VideoMediaReceived += this.OnVideoMediaReceived);
            }

            // Subscribe to the VBSS media.
            this.vbssSocket = this.mediaSession.VbssSocket;
            if (this.vbssSocket != null)
            {
                this.mediaSession.VbssSocket.VideoMediaReceived += this.OnVbssMediaReceived;
            }
        }
Beispiel #4
0
        public async Task Invoke(HttpContext context, IAudioSocket audio)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (audio == null)
            {
                throw new ArgumentNullException(nameof(audio));
            }

            if (context.WebSockets.IsWebSocketRequest)
            {
                var conversationId = context.Request.Headers["ConversationId"].ToString();
                var speaker        = context.Request.Headers["SpeakerType"].ToString();
                var speakerType    = (SpeakerType)Enum.Parse(typeof(SpeakerType), speaker);

                using var socket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(true);

                await audio.ReceiveAsync(socket, conversationId, speakerType).ConfigureAwait(false);
            }
            else
            {
                await next(context).ConfigureAwait(false);
            }
        }
        public BPSKModem(int baudRate)
        {
            // check baud rate, サンプリングレート範囲 8k ~ 44k sps よって、2k ~ 11k bps -> 2400から9600bpsまで対応
            if (baudRate < 1200 || baudRate > 9600)
            {
                throw new ArgumentOutOfRangeException("baud rate", baudRate, String.Format("baud rate should be within 2400 to 9600 bps."));
            }
            _baudRate = baudRate;

            // setting sampling period to the signal tracer
            com.ReinforceLab.SignalTrace.TracerFactory.SamplingPeriod = 1.0 / _baudRate / _samplePerCycle;

            _samplingRate = (_baudRate * _samplePerCycle);
            _socket       = new OpenALSocket(_samplingRate, (_samplingRate * _sampleDuration) * 4 / 1000);
            _demodulator  = new BPSKDemodulator();
            _modulator    = new BPSKModulator();
            _dataRecovery = new ClockDataRecovery(_SyncChar);

            _audioSignal = SignalTrace.TracerFactory.CreateRecorder("Input audio");
            _demodSignal = SignalTrace.TracerFactory.CreateRecorder("Demod sig");
        }