/// <summary> /// Starts the connection by calling into Limelight Common /// </summary> private async Task StartConnection() { NvHttp nv = null; await SetStateText("Resolving hostname..."); try { nv = new NvHttp(selected.IpAddress); } catch (ArgumentNullException) { stageFailureText = "Error resolving hostname"; ConnectionFailed(); } XmlQuery launchApp; // Launch Steam await SetStateText("Launching Steam"); try { launchApp = new XmlQuery(nv.baseUrl + "/launch?uniqueid=" + nv.GetDeviceName() + "&appid=" + selected.steamID); } catch (Exception) { Debug.WriteLine("Can't find steam"); stageFailureText = "Error launching Steam"; ConnectionFailed(); return; } // Set up callbacks LimelightStreamConfiguration streamConfig = new LimelightStreamConfiguration(frameWidth, frameHeight, 30, 10000, 1024); // TODO a magic number. Get FPS from the settings LimelightDecoderRenderer drCallbacks = new LimelightDecoderRenderer(DrSetup, DrStart, DrStop, DrRelease, DrSubmitDecodeUnit); LimelightAudioRenderer arCallbacks = new LimelightAudioRenderer(ArInit, ArStart, ArStop, ArRelease, ArPlaySample); LimelightConnectionListener clCallbacks = new LimelightConnectionListener(ClStageStarting, ClStageComplete, ClStageFailed, ClConnectionStarted, ClConnectionTerminated, ClDisplayMessage, ClDisplayTransientMessage); // Call into Common to start the connection Debug.WriteLine("Starting connection"); uint addr = 0; //uint addr = (uint)nv.resolvedHost.ToString(); // TODO how to get the addr as a uint LimelightCommonRuntimeComponent.StartConnection(addr, streamConfig, clCallbacks, drCallbacks, arCallbacks); if (stageFailureText != null) { Debug.WriteLine("Stage failed"); ConnectionFailed(); return; } else { ConnectionSuccess(); } }
/// <summary> /// Starts the connection by calling into Limelight Common /// </summary> private async Task StartConnection(LimelightStreamConfiguration streamConfig) { NvHttp nv = null; await SetStateText("Resolving hostname..."); try { nv = new NvHttp(selected.IpAddress); } catch (ArgumentNullException) { stageFailureText = "Error resolving hostname"; ConnectionFailed(); return; } try { await nv.ServerIPAddress(); } catch (Exception) { stageFailureText = "Error resolving hostname"; ConnectionFailed(); return; } // Set up callbacks LimelightDecoderRenderer drCallbacks = new LimelightDecoderRenderer(DrSetup, DrStart, DrStop, DrRelease, DrSubmitDecodeUnit); LimelightAudioRenderer arCallbacks = new LimelightAudioRenderer(ArInit, ArStart, ArStop, ArRelease, ArPlaySample); LimelightConnectionListener clCallbacks = new LimelightConnectionListener(ClStageStarting, ClStageComplete, ClStageFailed, ClConnectionStarted, ClConnectionTerminated, ClDisplayMessage, ClDisplayTransientMessage); XmlQuery launchApp; // Launch Steam await SetStateText("Launching Steam"); try { launchApp = StartOrResumeApp(nv, streamConfig); } catch (Exception) { Debug.WriteLine("Can't find steam"); stageFailureText = "Error launching Steam"; ConnectionFailed(); return; } // Call into Common to start the connection Debug.WriteLine("Starting connection"); Regex r = new Regex(@"^(?<octet1>\d+).(?<octet2>\d+).(?<octet3>\d+).(?<octet4>\d+)"); Match m = r.Match(selected.IpAddress); uint addr = (uint)(Convert.ToByte(m.Groups["octet4"].Value) << 24 | Convert.ToByte(m.Groups["octet3"].Value) << 16 | Convert.ToByte(m.Groups["octet2"].Value) << 8 | Convert.ToByte(m.Groups["octet1"].Value)); LimelightCommonRuntimeComponent.StartConnection(addr, streamConfig, clCallbacks, drCallbacks, arCallbacks); if (stageFailureText != null) { Debug.WriteLine("Stage failed"); ConnectionFailed(); return; } else { ConnectionSuccess(); } }
/// <summary> /// Event handler for Background Worker's doWork event. /// </summary> private void bwDoWork(object sender, DoWorkEventArgs e) { Debug.WriteLine("Doing work"); String hostNameString = (String)PhoneApplicationService.Current.State["host"]; // Resolve the host name to an IP address string. Dispatcher.BeginInvoke(new Action(() => setStateText("Resolving hostname..."))); ResolveHostName(hostNameString); stopWaitHandle.WaitOne(); // Set up callbacks LimelightStreamConfiguration streamConfig = new LimelightStreamConfiguration(frameWidth, frameHeight, 30); // TODO a magic number. Get FPS from the settings LimelightDecoderRenderer drCallbacks = new LimelightDecoderRenderer(DrSetup, DrStart, DrStop, DrRelease, DrSubmitDecodeUnit); LimelightAudioRenderer arCallbacks = new LimelightAudioRenderer(ArInit, ArStart, ArStop, ArRelease, ArPlaySample); LimelightConnectionListener clCallbacks = new LimelightConnectionListener(ClStageStarting, ClStageComplete, ClStageFailed, ClConnectionStarted, ClConnectionTerminated, ClDisplayMessage, ClDisplayTransientMessage); // Call into Common to start the connection Debug.WriteLine("Starting connection"); LimelightCommonRuntimeComponent.StartConnection((uint)resolvedHost.Address, streamConfig, clCallbacks, drCallbacks, arCallbacks); // If one of the stages failed, tell the background worker to cancel if(stageFailureText != null) { Debug.WriteLine("Stage failed - background worker cancelled"); e.Cancel = true; } }