Example #1
0
        /// <summary>
        /// This is setting the media used for this call.
        /// </summary>
        public void Configure()
        {
            //STEP2: configure media devices
            MediaConfig mediaConfig = new MediaConfig();

            if (_Sender)
            {
                //sender is sending audio and video
                mediaConfig.Audio = true;
                mediaConfig.Video = true;

                //We ask for 320x240 (should work fine
                //even on the weakest systems)
                //note that not all devices can actually
                //deliver the resolution we ask for
                mediaConfig.IdealWidth  = 320;
                mediaConfig.IdealHeight = 240;
            }
            else
            {
                //set to false to avoid
                //echo & multiple calls trying to access the same camera
                mediaConfig.Audio = false;
                mediaConfig.Video = false;
            }

            mCall.Configure(mediaConfig);
            mState = SimpleCallState.Config;
            Log("Configure media devices");
        }
Example #2
0
        private void Call_CallEvent(object sender, CallEventArgs args)
        {
            if (args.Type == CallEventType.ConfigurationComplete)
            {
                //STEP3: configuration completed -> try calling
                Call();
            }
            else if (args.Type == CallEventType.ConfigurationFailed)
            {
                Error("Accessing audio / video failed");
            }
            else if (args.Type == CallEventType.ConnectionFailed)
            {
                Error("ConnectionFailed");
            }
            else if (args.Type == CallEventType.ListeningFailed)
            {
                Error("ListeningFailed");
            }
            else if (args.Type == CallEventType.CallAccepted)
            {
                //STEP5: We are connected
                mState = SimpleCallState.InCall;
                Log("Connection established");
            }
            else if (args.Type == CallEventType.CallEnded)
            {
                mState = SimpleCallState.Ended;
                Log("Call ended.");
            }
            else if (args.Type == CallEventType.FrameUpdate)
            {
                //STEP6: until the end of the call we receive frames here
                //Note that this is being called after Configure already for local frames even before
                //a connection is established!
                //This is triggered each video frame for local and remote video images
                FrameUpdateEventArgs frameArgs = args as FrameUpdateEventArgs;


                if (frameArgs.ConnectionId == ConnectionId.INVALID)
                {
                    bool textureCreated = UnityMediaHelper.UpdateRawImage(_LocalImage, frameArgs.Frame);
                    if (textureCreated)
                    {
                        Texture2D tex = _LocalImage.texture as Texture2D;
                        Log("Local Texture(s) created " + tex.width + "x" + tex.height + " format: " + frameArgs.Frame.Format);
                    }
                }
                else
                {
                    bool textureCreated = UnityMediaHelper.UpdateRawImage(_RemoteImage, frameArgs.Frame);
                    if (textureCreated)
                    {
                        Texture2D tex = _RemoteImage.texture as Texture2D;
                        Log("Remote Texture(s) created " + tex.width + "x" + tex.height + " format: " + frameArgs.Frame.Format);
                    }
                }
            }
        }
Example #3
0
 private void Error(string errormsg)
 {
     if (_Sender)
     {
         Debug.LogError("Sender: Error during state " + mState + ": " + errormsg);
     }
     else
     {
         Debug.LogError("Receiver: Error during state " + mState + ": " + errormsg);
     }
     mState = SimpleCallState.Error;
 }
Example #4
0
        private void Call()
        {
            string address = Application.productName + "_SimpleCall";

            if (_Sender)
            {
                //STEP4: Sender calls (outgoing connection)
                mCall.Call(address);
            }
            else
            {
                //STEP4: Receiver listens (waiting for incoming connection)
                mCall.Listen(address);
            }
            mState = SimpleCallState.Calling;
        }
Example #5
0
        private void Call_CallEvent(object sender, CallEventArgs args)
        {
            if (args.Type == CallEventType.ConfigurationComplete)
            {
                //STEP3: configuration completed -> try calling
                Call();
            }
            else if (args.Type == CallEventType.ConfigurationFailed)
            {
                Error("Accessing audio / video failed");
            }
            else if (args.Type == CallEventType.ConnectionFailed)
            {
                Error("ConnectionFailed");
            }
            else if (args.Type == CallEventType.ListeningFailed)
            {
                Error("ListeningFailed");
            }
            else if (args.Type == CallEventType.CallAccepted)
            {
                //STEP5: We are connected
                mState = SimpleCallState.InCall;
                Log("Connection established");
            }
            else if (args.Type == CallEventType.CallEnded)
            {
                mState = SimpleCallState.Ended;
                Log("Call ended.");
            }
            else if (args.Type == CallEventType.FrameUpdate)
            {
                //STEP6: until the end of the call we receive frames here
                //Note that this is being called after Configure already for local frames even before
                //a connection is established!
                //This is triggered each video frame for local and remote video images
                FrameUpdateEventArgs frameArgs = args as FrameUpdateEventArgs;


                if (frameArgs.ConnectionId == ConnectionId.INVALID)
                {
                    //invalid connection id means this is a local frame
                    //copy the raw pixels into a unity texture
                    bool textureCreated = UnityMediaHelper.UpdateTexture(ref mLocalVideo, frameArgs.Frame, frameArgs.Format);
                    if (textureCreated)
                    {
                        if (_LocalImage != null)
                        {
                            _LocalImage.texture = mLocalVideo;
                        }
                        Log("Local Texture created " + frameArgs.Frame.Width + "x" + frameArgs.Frame.Height + " format: " + frameArgs.Format);
                    }
                }
                else
                {
                    //remote frame. For conference calls we would get multiple remote frames with different id's
                    bool textureCreated = UnityMediaHelper.UpdateTexture(ref mRemoteVideo, frameArgs.Frame, frameArgs.Format);
                    if (textureCreated)
                    {
                        if (_RemoteImage != null)
                        {
                            _RemoteImage.texture = mRemoteVideo;
                        }
                        Log("Remote Texture created " + frameArgs.Frame.Width + "x" + frameArgs.Frame.Height + " format: " + frameArgs.Format);
                    }
                }
            }
        }