Esempio n. 1
0
    void _CreateRTPCamera(int streamsCount)
    {
        MultipleNetworkCameraSource c;

        if (_cameraSource != null)
        {
            _cameraSource.Close();
        }
        _cameraSource = (c = new MultipleNetworkCameraSource());

        string profileType = Configuration.CamSettings.streamCodec == CameraConfigurations.EStreamCodec.Ovrvision ? "Ovrvision" : "None";

        _InitCameraRenderers();

        /*if(Configuration.CamSettings.CameraType==CameraConfigurations.ECameraType.WebCamera)
         *      c.StreamsCount = 2;
         * else c.StreamsCount = 1;*/
        c.SeparateStreams = Configuration.CamSettings.SeparateStreams;
        c.CameraStreams   = Configuration.CamSettings.CameraStreams;
        c.StreamsCount    = streamsCount;
        c.TargetNode      = gameObject;
        c.port            = Settings.Instance.GetPortValue("VideoPort", 0);
        c.RobotConnector  = RobotConnector;
        c.Init(_robotIfo, profileType);
        if (OnCameraSourceCreated != null)
        {
            OnCameraSourceCreated(this, _cameraSource);
        }


        _cameraSource.GetBaseTexture().OnFrameGrabbed += OnFrameGrabbed;
        m_grabbedFrames = 0;

        if (Debugger)
        {
            Debugger.RemoveDebugElement(_cameraDebugElem);;
            _cameraDebugElem = new DebugCameraCaptureElement(_cameraSource.GetBaseTexture());
            Debugger.AddDebugElement(_cameraDebugElem);;
        }

        //request netvalue port
        if (RobotConnector.Connector.RobotCommunicator != null)
        {
            RobotConnector.Connector.RobotCommunicator.SetData("", "NetValuePort", ServiceName + "," + RobotConnector.Connector.DataCommunicator.GetPort().ToString(), false, false);
        }
    }
    void Init()
    {
        CameraType = Settings.Instance.RobotSettings.ReadValue ("Camera", "Source", CameraType.ToString ())=="Local"?CameraSourceType.Local:CameraSourceType.Remote;
        if(CameraType==CameraSourceType.Local)
        {
            LocalWebcameraSource c;
            _cameraSource = (c=new LocalWebcameraSource());
            c.LeftInputCamera = Settings.Instance.RobotSettings.ReadValue ("Camera", "Left", 0);
            c.RightInputCamera = Settings.Instance.RobotSettings.ReadValue ("Camera", "Right", 1);
            c.Init();
        }else
        {
            MultipleNetworkCameraSource c;
            _cameraSource = (c=new MultipleNetworkCameraSource());
            c.StreamsCount=2;
            c.TargetNode=gameObject;
            c.Init();
        }

        if (AudioSupport) {
            _audioPlayer = new GstMultipleNetworkAudioPlayer ();
            _audioStreamer = gameObject.AddComponent<GstNetworkAudioStreamer> ();
            _audioStreamer.SetChannels(1);
            _audioStreamer.CreateStream();
        }

        EyeName[] eyes = new EyeName[]{EyeName.RightEye,EyeName.LeftEye};
        TelubeeCameraRenderer[] Targets = new TelubeeCameraRenderer[]{TargetEyeRight,TargetEyeLeft};
        if (OculusCamera != null)
        {
            Camera[] cams = new Camera[] { OculusCamera.rightEyeCamera, OculusCamera.leftEyeCamera };
        //	Vector2[] pixelShift = new Vector2[] { Configuration.CamSettings.PixelShiftRight,Configuration.CamSettings.PixelShiftLeft};
            for (int c = 0; c < cams.Length; ++c)
            {
                int i = (int)eyes[c];
                cams[i].backgroundColor=Color.black;

            //	CreateMesh ((EyeName)i);
                TelubeeCameraRenderer r = Targets[i];
                if(r==null)
                    r=cams[i].gameObject.AddComponent<TelubeeCameraRenderer>();
                r.Mat = Object.Instantiate(TargetMaterial);
                r.DisplayCamera=cams[i];
                r.Src = this;
                r.CamSource = _cameraSource;

                r.CreateMesh(eyes[c]);

                _camRenderer[i]=r;

                if (i == 0)
                {
                    r._RenderPlane.layer=LayerMask.NameToLayer("RightEye");
                }
                else
                {
                    r._RenderPlane.layer=LayerMask.NameToLayer("LeftEye");
                }
                if(Targets[i]==null)
                {
                    r._RenderPlane.transform.parent = cams[i].transform;
                    r._RenderPlane.transform.localRotation=Quaternion.identity;
                    r._RenderPlane.transform.localPosition=new Vector3(0,0,1);
                }
            }
        }

        _videoValues=new NetValueObject();
        if (ParameterController != null)
            ParameterController.TargetValueObject = _videoValues;
    }
 public override void PostInit()
 {
     _texture = (_eyes.CameraSource as MultipleNetworkCameraSource);
 }
    public void SetRemoteHost(string IP,RobotConnector.TargetPorts ports)
    {
        _remoteHostIP = IP;
        /*
        MultipleNetworkCameraSource c;
        _cameraSource = (c=new MultipleNetworkCameraSource());
        c.TargetNode=gameObject;
        c.Host = IP;
        c.port = port;
        c.Init();*/
        if(this.CameraType==CameraSourceType.Remote)
        {

            if (_cameraSource != null) {
                _cameraSource.Close();
                _cameraSource=null;
            }
            MultipleNetworkCameraSource c;
            _cameraSource = (c = new MultipleNetworkCameraSource ());
            c.StreamsCount = 2;
            c.TargetNode = gameObject;
            c.Host = IP;
            c.port = Settings.Instance.GetPortValue("VideoPort",0);
            c.Init ();

            _cameraSource.GetBaseTexture ().OnFrameGrabbed += OnFrameGrabbed;
            m_grabbedFrames=0;

            //disable the renderes until we video stream starts
            //_camRenderer[0].Disable();
            //_camRenderer[1].Disable();

            _videoPorts=new uint[2]{0,0};
            _videoPorts[0]=c.Texture.Player.GetVideoPort(0);
            _videoPorts[1]=c.Texture.Player.GetVideoPort(1);
            RobotConnector.Connector.SendData("VideoPorts",_videoPorts[0].ToString()+","+_videoPorts[1].ToString(),true);

            if(_audioPlayer!=null)
            {
                int port= Settings.Instance.GetPortValue("AudioPort",0);
                _audioPlayer.SetIP(IP,0,false);
                _audioPlayer.CreateStream();
                _audioPlayer.Play();
                _audioPort=_audioPlayer.GetAudioPort();
                RobotConnector.Connector.SendData("AudioPort",_audioPort.ToString(),true);
            }

            if(_audioStreamer!=null)
            {
                _audioStreamer.SetIP(IP,7010,false);//port should be dynamically assigned from remote side
                _audioStreamer.Stream();
            }
            for(int i=0;i<2;++i)
                _camRenderer[i].CamSource=_cameraSource;
            if (Debugger) {
                Debugger.RemoveDebugElement(_cameraDebugElem);;
                _cameraDebugElem=new DebugCameraCaptureElement(_cameraSource.GetBaseTexture());
                Debugger.AddDebugElement(_cameraDebugElem);;
            }
        }

        {
            //request camera settings
            RobotConnector.Connector.SendData("CameraParameters","",false);

            //request netvalue port
            RobotConnector.Connector.RobotCommunicator.SetData ("NetValuePort", "AVStreamServiceModule,"+RobotConnector.Connector.DataCommunicator.Port.ToString(), false,false);
        }
    }