MS2TesterHelper.cs 8.08 KB
Newer Older
Ghislain MARY's avatar
Ghislain MARY committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
using MS2TesterTasks;
using BelledonneCommunications.Mediastreamer2.Tester;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation.Collections;

namespace ms2_tester.Helpers
{
    class MS2TesterHelper
    {
        public static bool RunInBackground { get; set; }

        public static async Task<OperationResult> InitVideo()
        {
            if (RunInBackground)
            {
                AppServiceHelper appServiceHelper = new AppServiceHelper();

                ValueSet message = new ValueSet();
                message[BackgroundOperation.NewBackgroundRequest] = (int)BackgroundRequest.InitVideo;

                ValueSet response = await appServiceHelper.SendMessageAsync(message);
                if (response != null)
                {
                    return ((OperationResult)(response[BackgroundOperation.Result]));
                }

                return OperationResult.Failed;
            }
            else
            {
                NativeTester.Instance.initVideo();
                return OperationResult.Succeeded;
            }
        }

        public static async Task<OperationResult> UninitVideo()
        {
            if (RunInBackground)
            {
                AppServiceHelper appServiceHelper = new AppServiceHelper();

                ValueSet message = new ValueSet();
                message[BackgroundOperation.NewBackgroundRequest] = (int)BackgroundRequest.UninitVideo;

                ValueSet response = await appServiceHelper.SendMessageAsync(message);
                if (response != null)
                {
                    return ((OperationResult)(response[BackgroundOperation.Result]));
                }

                return OperationResult.Failed;
            }
            else
            {
                NativeTester.Instance.uninitVideo();
                return OperationResult.Succeeded;
            }
        }

        public static async Task<List<String>> GetVideoDevices()
        {
            if (RunInBackground)
            {
                AppServiceHelper appServiceHelper = new AppServiceHelper();

                ValueSet message = new ValueSet();
                message[BackgroundOperation.NewBackgroundRequest] = (int)BackgroundRequest.GetVideoDevices;

                ValueSet response = await appServiceHelper.SendMessageAsync(message);
                if ((response != null) && ((OperationResult)(response[BackgroundOperation.Result]) == OperationResult.Succeeded))
                {
                    return ((IEnumerable<String>)response[BackgroundOperation.ReturnValue]).ToList<String>();
                }

                return null;
            }
            else
            {
                return NativeTester.Instance.VideoDevices.ToList();
            }
        }

87
        public static async Task<OperationResult> StartVideoStream(String videoSwapChainPanelName, String previewSwapChainPanelName, String camera, String codec, String videoSize, UInt32 frameRate, UInt32 bitRate, Boolean usePreviewStream)
Ghislain MARY's avatar
Ghislain MARY committed
88 89 90 91 92 93 94 95 96 97 98 99 100
        {
            if (RunInBackground)
            {
                AppServiceHelper appServiceHelper = new AppServiceHelper();

                ValueSet message = new ValueSet();
                message[StartVideoStreamArguments.VideoSwapChainPanelName.ToString()] = videoSwapChainPanelName;
                message[StartVideoStreamArguments.PreviewSwapChainPanelName.ToString()] = previewSwapChainPanelName;
                message[StartVideoStreamArguments.Camera.ToString()] = camera;
                message[StartVideoStreamArguments.Codec.ToString()] = codec;
                message[StartVideoStreamArguments.VideoSize.ToString()] = videoSize;
                message[StartVideoStreamArguments.FrameRate.ToString()] = frameRate;
                message[StartVideoStreamArguments.BitRate.ToString()] = bitRate;
101
                message[StartVideoStreamArguments.UsePreviewStream.ToString()] = usePreviewStream;
Ghislain MARY's avatar
Ghislain MARY committed
102 103 104 105 106 107 108 109 110 111 112 113
                message[BackgroundOperation.NewBackgroundRequest] = (int)BackgroundRequest.StartVideoStream;

                ValueSet response = await appServiceHelper.SendMessageAsync(message);
                if (response != null)
                {
                    return ((OperationResult)(response[BackgroundOperation.Result]));
                }

                return OperationResult.Failed;
            }
            else
            {
114
                NativeTester.Instance.startVideoStream(videoSwapChainPanelName, previewSwapChainPanelName, camera, codec, videoSize, frameRate, bitRate, usePreviewStream);
Ghislain MARY's avatar
Ghislain MARY committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
                return OperationResult.Succeeded;
            }
        }

        public static async Task<OperationResult> StopVideoStream()
        {
            if (RunInBackground)
            {
                AppServiceHelper appServiceHelper = new AppServiceHelper();

                ValueSet message = new ValueSet();
                message[BackgroundOperation.NewBackgroundRequest] = (int)BackgroundRequest.StopVideoStream;

                ValueSet response = await appServiceHelper.SendMessageAsync(message);
                if (response != null)
                {
                    return ((OperationResult)(response[BackgroundOperation.Result]));
                }

                return OperationResult.Failed;
            }
            else
            {
                NativeTester.Instance.stopVideoStream();
                return OperationResult.Succeeded;
            }
        }

        public static async Task<OperationResult> ChangeCamera(String camera)
        {
            if (RunInBackground)
            {
                AppServiceHelper appServiceHelper = new AppServiceHelper();

                ValueSet message = new ValueSet();
                message[ChangeCameraArguments.Camera.ToString()] = camera;
                message[BackgroundOperation.NewBackgroundRequest] = (int)BackgroundRequest.ChangeCamera;

                ValueSet response = await appServiceHelper.SendMessageAsync(message);
                if (response != null)
                {
                    return ((OperationResult)(response[BackgroundOperation.Result]));
                }

                return OperationResult.Failed;
            }
            else
            {
                NativeTester.Instance.changeCamera(camera);
                return OperationResult.Succeeded;
            }
        }

        public static async Task<int> GetOrientation()
        {
            if (RunInBackground)
            {
                AppServiceHelper appServiceHelper = new AppServiceHelper();

                ValueSet message = new ValueSet();
                message[BackgroundOperation.NewBackgroundRequest] = (int)BackgroundRequest.GetOrientation;

                ValueSet response = await appServiceHelper.SendMessageAsync(message);
                if ((response != null) && ((OperationResult)(response[BackgroundOperation.Result]) == OperationResult.Succeeded))
                {
                    return Convert.ToInt32(response[BackgroundOperation.ReturnValue]);
                }

                return 0;
            }
            else
            {
                return NativeTester.Instance.getOrientation();
            }
        }

        public static async Task<OperationResult> SetOrientation(int degrees)
        {
            if (RunInBackground)
            {
                AppServiceHelper appServiceHelper = new AppServiceHelper();

                ValueSet message = new ValueSet();
                message[SetOrientationArguments.Degrees.ToString()] = degrees;
                message[BackgroundOperation.NewBackgroundRequest] = (int)BackgroundRequest.SetOrientation;

                ValueSet response = await appServiceHelper.SendMessageAsync(message);
                if (response != null)
                {
                    return ((OperationResult)(response[BackgroundOperation.Result]));
                }

                return OperationResult.Failed;
            }
            else
            {
                NativeTester.Instance.setOrientation(degrees);
                return OperationResult.Succeeded;
            }
        }
    }
}