コード例 #1
0
        private void startCall()
        {
            int ret = 0;

            if (enableVoice)
            {
                startVoiceEngine();
            }

            if (enableVideo)
            {
                if (enableVideoSend)
                {
                    // camera and preview surface
                    svLocal = ViERenderer.CreateLocalRenderer(this);
                }

                channel = viEAndroidJavaAPI.CreateChannel(voiceChannel);
                ret     = viEAndroidJavaAPI.SetLocalReceiver(channel, receivePortVideo);
                ret     = viEAndroidJavaAPI.SetSendDestination(channel, destinationPortVideo, RemoteIPString);

                if (enableVideoReceive)
                {
                    if (renderType == RenderType.OPENGL)
                    {
                        Log.Verbose(TAG, "Create OpenGL Render");
                        remoteSurfaceView = ViERenderer.CreateRenderer(this, true);
                    }
                    else if (renderType == RenderType.SURFACE)
                    {
                        Log.Verbose(TAG, "Create SurfaceView Render");
                        remoteSurfaceView = ViERenderer.CreateRenderer(this, false);
                    }
                    else if (renderType == RenderType.MEDIACODEC)
                    {
                        Log.Verbose(TAG, "Create MediaCodec Decoder/Renderer");
                        remoteSurfaceView = new SurfaceView(this);
                    }

                    if (mLlRemoteSurface != null)
                    {
                        mLlRemoteSurface.AddView(remoteSurfaceView);
                    }

                    if (renderType == RenderType.MEDIACODEC)
                    {
                        ret = viEAndroidJavaAPI.SetExternalMediaCodecDecoderRenderer(channel, remoteSurfaceView);
                    }
                    else
                    {
                        ret = viEAndroidJavaAPI.AddRemoteRenderer(channel, remoteSurfaceView);
                    }

                    ret = viEAndroidJavaAPI.SetReceiveCodec(channel, codecType, INIT_BITRATE, codecSizeWidth, codecSizeHeight, RECEIVE_CODEC_FRAMERATE);
                    ret = viEAndroidJavaAPI.StartRender(channel);
                    ret = viEAndroidJavaAPI.StartReceive(channel);
                }

                if (enableVideoSend)
                {
                    ret = viEAndroidJavaAPI.SetSendCodec(channel, codecType, INIT_BITRATE, codecSizeWidth, codecSizeHeight, SEND_CODEC_FRAMERATE);
                    int camId = viEAndroidJavaAPI.StartCamera(channel, usingFrontCamera ? 1 : 0);

                    if (camId >= 0)
                    {
                        cameraId = camId;
                        compensateCameraRotation();
                    }
                    else
                    {
                        ret = camId;
                    }
                    ret = viEAndroidJavaAPI.StartSend(channel);
                }

                // TODO(leozwang): Add more options besides PLI, currently use pli
                // as the default. Also check return value.
                ret = viEAndroidJavaAPI.EnablePLI(channel, true);
                ret = viEAndroidJavaAPI.EnableNACK(channel, enableNack);
                ret = viEAndroidJavaAPI.SetCallback(channel, this);

                if (enableVideoSend)
                {
                    if (mLlLocalSurface != null)
                    {
                        mLlLocalSurface.AddView(svLocal);
                    }
                }

                isStatsOn = cbStats.Checked;
                if (isStatsOn)
                {
                    addStatusView();
                }
                else
                {
                    removeStatusView();
                }

                viERunning = true;
            }
        }
コード例 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Java.Lang.JavaSystem.LoadLibrary("z_shared");
            Java.Lang.JavaSystem.LoadLibrary("openpeer");

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            LinearLayout localViewLayout         = FindViewById <LinearLayout> (Resource.Id.myLocalViewLinearLayout);
            LinearLayout remoteViewLayout        = FindViewById <LinearLayout> (Resource.Id.myRemoteViewLinearLayout);
            Button       mediaControlButton      = FindViewById <Button> (Resource.Id.myMediaControlButton);
            Button       audioOutputButton       = FindViewById <Button> (Resource.Id.myAudioOutputButton);
            EditText     remoteIPAddressEditText = FindViewById <EditText> (Resource.Id.myRemoteIPAddressEditText);

            localView = ViERenderer.CreateLocalRenderer(this);
            localViewLayout.AddView(localView);

            remoteView = ViERenderer.CreateRenderer(this, true);
            remoteViewLayout.AddView(remoteView);

            OPMediaEngine.Init(Android.App.Application.Context);
            mediaEngine = OPTestMediaEngine.TestInstance;
            if (useFrontCamera)
            {
                mediaEngine.CameraType = CameraTypes.CameraTypeFront;
            }
            else
            {
                mediaEngine.CameraType = CameraTypes.CameraTypeBack;
            }
            mediaEngine.SetEcEnabled(Java.Lang.Boolean.True);
            mediaEngine.SetAgcEnabled(Java.Lang.Boolean.True);
            mediaEngine.SetNsEnabled(Java.Lang.Boolean.False);
            mediaEngine.SetNsEnabled(Java.Lang.Boolean.False);
            mediaEngine.MuteEnabled             = Java.Lang.Boolean.False;
            mediaEngine.LoudspeakerEnabled      = Java.Lang.Boolean.False;
            mediaEngine.ContinuousVideoCapture  = Java.Lang.Boolean.True;
            mediaEngine.DefaultVideoOrientation = VideoOrientations.VideoOrientationPortrait;
            mediaEngine.RecordVideoOrientation  = VideoOrientations.VideoOrientationLandscapeRight;
            mediaEngine.FaceDetection           = Java.Lang.Boolean.False;
            mediaEngine.SetChannelRenderView(remoteView);

            mediaControlButton.Text = string.Format("Start Video Capture");
            audioOutputButton.Text  = string.Format("Speakerphone");

            mediaControlButton.Click += delegate {
                switch (mediaEngineStatus)
                {
                case 0:
                    mediaEngine.StartVideoCapture();
                    mediaControlButton.Text = string.Format("Start Media Channel");
                    mediaEngineStatus++;
                    break;

                case 1:
                    mediaEngine.ReceiverAddress = remoteIPAddressEditText.Text;
                    mediaEngine.StartVoice();
                    mediaEngine.StartVideoChannel();
                    mediaControlButton.Text = string.Format("Stop Media Channel");
                    mediaEngineStatus++;
                    break;

                case 2:
                    mediaEngine.StopVoice();
                    mediaEngine.StopVideoChannel();
                    mediaControlButton.Text = string.Format("Stop Video Capture");
                    mediaEngineStatus++;
                    break;

                case 3:
                    mediaEngine.StopVideoCapture();
                    mediaControlButton.Text = string.Format("Start Video Capture");
                    mediaEngineStatus       = 0;
                    break;

                default:
                    break;
                }
            };

            audioOutputButton.Click += delegate {
                if (speakerphoneEnabled)
                {
                    mediaEngine.LoudspeakerEnabled = Java.Lang.Boolean.False;
                    audioOutputButton.Text         = string.Format("Speakerphone");
                }
                else
                {
                    mediaEngine.LoudspeakerEnabled = Java.Lang.Boolean.True;
                    audioOutputButton.Text         = string.Format("Ear Speaker");
                }
                speakerphoneEnabled = !speakerphoneEnabled;
            };
        }