Esempio n. 1
0
        public void StartCall(string strRemoteJID)
        {
            /// Start up our mic and speaker, start up our mixer
            /// 
            if (m_bCallActive == true)
                return;


            if (addresses.Length <= 0)
                throw new Exception("No IP addresses on System");

            int nPort = GetNextPort();
            IPEndPoint ep = new IPEndPoint(addresses[0], nPort);

            source = new AudioStreamSource();

            /// may need a lock here to make sure we have this session added to our list before the xmpp response gets back, though this should be many times faster than network traffic
            MediaSession = new JingleMediaSession(strRemoteJID, ep, App.XMPPClient);
            MediaSession.UseStun = true;
            MediaSession.AudioRTPStream.UseInternalTimersForPacketPushPull = false;
            MediaSession.ClearAllPayloads();

            MediaSession.AddKnownAudioPayload(KnownAudioPayload.G722_40); // Only g711, speex can't be encoded real time on the xoom (oops, this is the windows phone, we'll have to try that later)

            MediaSession.SendInitiateSession();
        }
Esempio n. 2
0
        public void StartCall(string strRemoteJID)
        {
            /// Start up our mic and speaker, start up our mixer
            ///
            if (m_bCallActive == true)
            {
                Console.WriteLine("Cal active return");
                return;
            }


            if (addresses.Length <= 0)
            {
                throw new Exception("No IP addresses on System");
            }

            int        nPort = GetNextPort();
            IPEndPoint ep    = new IPEndPoint(addresses[0], nPort);

            source = new AudioStreamSource();

            /// may need a lock here to make sure we have this session added to our list before the xmpp response gets back, though this should be many times faster than network traffic
            MediaSession         = new JingleMediaSession(strRemoteJID, ep, App.XMPPClient);
            MediaSession.UseStun = true;
            MediaSession.AudioRTPStream.UseInternalTimersForPacketPushPull = false;
            MediaSession.ClearAllPayloads();

            MediaSession.AddKnownAudioPayload(KnownAudioPayload.G722_40); // Only g711, speex can't be encoded real time on the xoom (oops, this is the windows phone, we'll have to try that later)

            Console.WriteLine(MediaSession.SendInitiateSession());
        }
Esempio n. 3
0
        public void StartCall()
        {
            //stream init
            IsCallActive = true;
            stream.Start(remote, 50, 50);
            source = new AudioStreamSource();


            //stream start recv
            SpeakerThread      = new Thread(new ThreadStart(SpeakerThreadFunction));
            SpeakerThread.Name = "Speaker Thread";
            SpeakerThread.Start();

            MicrophoneThread      = new Thread(new ThreadStart(MicrophoneThreadFunction));
            MicrophoneThread.Name = "Microphone Thread";
            MicrophoneThread.Start();
        }
Esempio n. 4
0
        public void StartCall()
        {
            //stream init
            IsCallActive = true;
            stream.Start(remote, 50, 50);
            source = new AudioStreamSource();
            Log("Stream Initialised");

            //stream start recv
            SpeakerThread = new Thread(new ThreadStart(SpeakerThreadFunction));
            SpeakerThread.Name = "Speaker Thread";
            SpeakerThread.Start();

            MicrophoneThread = new Thread(new ThreadStart(MicrophoneThreadFunction));
            MicrophoneThread.Name = "Microphone Thread";
            MicrophoneThread.Start();
        }
Esempio n. 5
0
        public void SpeakerThreadFunction()
        {
            source = new AudioStreamSource();
               TimeSpan tsPTime = TimeSpan.FromMilliseconds(stream.PTimeReceive);
            int nSamplesPerPacket = stream.AudioCodec.AudioFormat.CalculateNumberOfSamplesForDuration(tsPTime);
            int nBytesPerPacket = nSamplesPerPacket * stream.AudioCodec.AudioFormat.BytesPerSample;
            byte[] bDummySample = new byte[nBytesPerPacket];
            source.PacketSize = nBytesPerPacket;
            stream.IncomingRTPPacketBuffer.InitialPacketQueueMinimumSize = 4;
            stream.IncomingRTPPacketBuffer.PacketSizeShiftMax = 10;
            int nMsTook = 0;

               Deployment.Current.Dispatcher.BeginInvoke(new EventHandler(SafeStartMediaElement), null, null);
            //       while (true) { }
            /// Get first packet... have to wait for our rtp buffer to fill
            byte[] bData = stream.WaitNextPacketSample(true, stream.PTimeReceive * 5, out nMsTook);
            if ((bData != null) && (bData.Length > 0))
            {
                source.Write(bData);
            }

            DateTime dtNextPacketExpected = DateTime.Now + tsPTime;

            System.Diagnostics.Stopwatch WaitPacketWatch = new System.Diagnostics.Stopwatch();
            int nDeficit = 0;
            while (IsCallActive == true)
            {
                bData = stream.WaitNextPacketSample(true, stream.PTimeReceive, out nMsTook);
                if ((bData != null) && (bData.Length > 0))
                {
                    source.Write(bData);
                }

                TimeSpan tsRemaining = dtNextPacketExpected - DateTime.Now;
                int nMsRemaining = (int)tsRemaining.TotalMilliseconds;
                if (nMsRemaining > 0)
                {
                    nMsRemaining += nDeficit;
                    if (nMsRemaining > 0)
                        System.Threading.Thread.Sleep(nMsRemaining);
                    else
                    {
                        nDeficit = nMsRemaining;
                    }
                }
                else
                    nDeficit += nMsRemaining;

                dtNextPacketExpected += tsPTime;
            }

              Deployment.Current.Dispatcher.BeginInvoke(new EventHandler(SafeStopMediaElement), null, null);
        }
Esempio n. 6
0
        public void SpeakerThreadFunction()
        {
            source = new AudioStreamSource();
            TimeSpan tsPTime           = TimeSpan.FromMilliseconds(stream.PTimeReceive);
            int      nSamplesPerPacket = stream.AudioCodec.AudioFormat.CalculateNumberOfSamplesForDuration(tsPTime);
            int      nBytesPerPacket   = nSamplesPerPacket * stream.AudioCodec.AudioFormat.BytesPerSample;

            byte[] bDummySample = new byte[nBytesPerPacket];
            source.PacketSize = nBytesPerPacket;
            stream.IncomingRTPPacketBuffer.InitialPacketQueueMinimumSize = 4;
            stream.IncomingRTPPacketBuffer.PacketSizeShiftMax            = 10;
            int nMsTook = 0;


            Deployment.Current.Dispatcher.BeginInvoke(new EventHandler(SafeStartMediaElement), null, null);
            //       while (true) { }
            /// Get first packet... have to wait for our rtp buffer to fill
            byte[] bData = stream.WaitNextPacketSample(true, stream.PTimeReceive * 5, out nMsTook);
            if ((bData != null) && (bData.Length > 0))
            {
                source.Write(bData);
            }


            DateTime dtNextPacketExpected = DateTime.Now + tsPTime;

            System.Diagnostics.Stopwatch WaitPacketWatch = new System.Diagnostics.Stopwatch();
            int nDeficit = 0;

            while (IsCallActive == true)
            {
                bData = stream.WaitNextPacketSample(true, stream.PTimeReceive, out nMsTook);
                if ((bData != null) && (bData.Length > 0))
                {
                    source.Write(bData);
                }

                TimeSpan tsRemaining  = dtNextPacketExpected - DateTime.Now;
                int      nMsRemaining = (int)tsRemaining.TotalMilliseconds;
                if (nMsRemaining > 0)
                {
                    nMsRemaining += nDeficit;
                    if (nMsRemaining > 0)
                    {
                        System.Threading.Thread.Sleep(nMsRemaining);
                    }
                    else
                    {
                        nDeficit = nMsRemaining;
                    }
                }
                else
                {
                    nDeficit += nMsRemaining;
                }

                dtNextPacketExpected += tsPTime;
            }



            Deployment.Current.Dispatcher.BeginInvoke(new EventHandler(SafeStopMediaElement), null, null);
        }