예제 #1
0
 public MusicMediaSession(AudioFormat sourceAudioFormat, IPEndPoint destination) : base(new MediaEndPoints {
     AudioSource = new EmptyAudioSource()
 })
 {
     SetDestination(SDPMediaTypesEnum.audio, destination, null);
     AudioExtrasSource.SetAudioSourceFormat(sourceAudioFormat);
     AudioExtrasSource.SetSource(AudioSourcesEnum.Music);
     _mediaStream = new MediaStreamTrack(SDPMediaTypesEnum.audio, true, AudioLocalTrack.Capabilities);
 }
예제 #2
0
        public VoIPMediaSession(
            MediaEndPoints mediaEndPoint,
            IPAddress bindAddress = null,
            int bindPort          = 0,
            VideoTestPatternSource testPatternSource = null)
            : base(false, false, false, bindAddress, bindPort)
        {
            if (mediaEndPoint == null)
            {
                throw new ArgumentNullException("mediaEndPoint", "The media end point parameter cannot be null.");
            }

            Media = mediaEndPoint;

            // The audio extras source is used for on-hold music.
            _audioExtrasSource = new AudioExtrasSource();
            _audioExtrasSource.OnAudioSourceEncodedSample += SendAudio;

            // Wire up the audio and video sample event handlers.
            if (Media.AudioSource != null)
            {
                var audioTrack = new MediaStreamTrack(mediaEndPoint.AudioSource.GetAudioSourceFormats());
                base.addTrack(audioTrack);
                Media.AudioSource.OnAudioSourceEncodedSample += base.SendAudio;
            }

            if (Media.VideoSource != null)
            {
                var videoTrack = new MediaStreamTrack(mediaEndPoint.VideoSource.GetVideoSourceFormats());
                base.addTrack(videoTrack);
                Media.VideoSource.OnVideoSourceEncodedSample += base.SendVideo;
                Media.VideoSource.OnVideoSourceError         += VideoSource_OnVideoSourceError;

                if (testPatternSource != null)
                {
                    // The test pattern source is used as failover if the webcam initialisation fails.
                    // It's also used as the video stream if the call is put on hold.
                    _videoTestPatternSource = testPatternSource;
                    _videoTestPatternSource.OnVideoSourceEncodedSample += base.SendVideo;
                    //_videoTestPatternSource.OnVideoSourceRawSample += Media.VideoSource.ExternalVideoSourceRawSample;
                }
            }

            if (Media.VideoSink != null)
            {
                Media.VideoSink.OnVideoSinkDecodedSample += VideoSinkSampleReady;
                base.OnVideoFrameReceived += Media.VideoSink.GotVideoFrame;
            }

            if (Media.AudioSink != null)
            {
                base.OnRtpPacketReceived += RtpMediaPacketReceived;
            }

            base.OnAudioFormatsNegotiated += AudioFormatsNegotiated;
            base.OnVideoFormatsNegotiated += VideoFormatsNegotiated;
        }
        public AudioSendOnlyMediaSession(
            IPAddress bindAddress = null,
            int bindPort          = 0)
            : base(false, false, false, bindAddress, bindPort)
        {
            // The audio extras source is used for on-hold music.
            AudioExtrasSource = new AudioExtrasSource(new AudioEncoder(), new AudioSourceOptions {
                AudioSource = AudioSourcesEnum.Silence
            });
            AudioExtrasSource.OnAudioSourceEncodedSample += SendAudio;

            base.OnAudioFormatsNegotiated += AudioFormatsNegotiated;
        }
        public AudioSendOnlyMediaSession(
            IPAddress bindAddress = null,
            int bindPort          = 0)
            : base(false, false, false, bindAddress, bindPort)
        {
            // The audio extras source is used for on-hold music.
            AudioExtrasSource = new AudioExtrasSource(new AudioEncoder(), new AudioSourceOptions {
                AudioSource = AudioSourcesEnum.Music
            });
            AudioExtrasSource.OnAudioSourceEncodedSample += SendAudio;

            base.OnAudioFormatsNegotiated += AudioFormatsNegotiated;

            var audioTrack = new MediaStreamTrack(AudioExtrasSource.GetAudioSourceFormats());

            base.addTrack(audioTrack);
        }
예제 #5
0
 public async Task SendAudioFile(string fileToPlay)
 {
     await AudioExtrasSource.SendAudioFromStream(
         new FileStream(fileToPlay, FileMode.Open, FileAccess.Read, FileShare.Read),
         AudioSamplingRatesEnum.Rate8KHz);
 }