Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

69 camera endpoint #77

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
0ba0b38
WIP on camera feed
Jul 27, 2016
e91a235
V1 WIP of stacking cameras to render screenshot
Jul 30, 2016
3b5e74e
List all cameras when updating for research and debugging
Jul 30, 2016
dc8c7ff
Cleanup CameraCapture code
Jul 31, 2016
995b949
Add debugging for Current Camera Mode
Jul 31, 2016
f7bf70d
Additional cleanup of CameraCapture
Jul 31, 2016
107c299
Refactor CameraCapture to be more adaptive
Jul 31, 2016
222bb4d
Skip UIVectorCamera when rendering
Jul 31, 2016
49dd928
Make CameraSnapshots namespace
Jul 31, 2016
c843f0d
Abstract rendering camera snapshots into SnapshotRenderer
Jul 31, 2016
2be0fb2
Rename CameraCapture to CurrentFlightCameraCapture
Jul 31, 2016
349d0c3
WIP: IVACameraCapture
Jul 31, 2016
989da10
WIP: Getting info from RasterPropMonitor External cameras
Aug 3, 2016
9b824ce
WIP: Flesh out RasterPropMonitor Camera container and managers
Aug 4, 2016
4b0ecfd
Remove RPM camera when part is destroyed
Aug 4, 2016
05dff66
Abstract Camera duplication + rendering into CameraCapture
Aug 4, 2016
8a1a6a1
Update RasterPropMonitor to subclass CameraCapture
Aug 4, 2016
58f5fdb
Comment out spurious debugging to reduce noise
Aug 4, 2016
1102512
WIP progress on rendering RPM cameras
Aug 5, 2016
5de7dc8
Fix Camera container naming prefix, FOV for nearfield cameras, debugging
Aug 6, 2016
ba941ef
Fix rendering of RasterPropMonitor Cameras
Aug 6, 2016
2706a59
Remove spurious debugging in CameraResponsibility
Aug 6, 2016
ee43126
Add cameraType() method to CameraCapture
Aug 6, 2016
515cf3f
fix typo with cameraType method in CameraCapture
Aug 6, 2016
357c962
Return list of cameras at /telemachus/cameras endpoint
Aug 6, 2016
0c66232
Setup Camera list and camera image retrieval endpoints
Aug 6, 2016
05ae5ed
Render camera images as JPEG, increase image resolution
Aug 6, 2016
1d8cccc
Abstract method to generate camera manager name into public static me…
Aug 7, 2016
1a2ded7
Fix removing cameras, keep mapping of vessel cameras
Aug 7, 2016
b9eb244
Have RasterPropMonitorCameras add/remove themselves on vessel change
Aug 7, 2016
36c3979
Remove Spurious logging, setup performance testing
Aug 7, 2016
4a6075f
WIP: Refactoring Camera Snapshot engine for performance
Aug 7, 2016
cd910ae
Remove spurious debugging to improve performance in WIP
Aug 7, 2016
e41a775
remove previously active cameras when updating
Aug 7, 2016
b132eb6
Cleanup from WIP
Aug 7, 2016
d86d8cc
Refactor CameraCapture to use more performant version
Aug 7, 2016
887d49b
Destroy CameraCapture Unity object when camera is removed from manager
Aug 7, 2016
b49a17c
Revert "Destroy CameraCapture Unity object when camera is removed fro…
Aug 7, 2016
37ce54f
Return result of processImateRequest to halt Telemachus chain
Aug 8, 2016
01dca5a
Wrap camera update & render with mutex
Aug 8, 2016
57e7429
Setup yield structure for rendering, fix bug with active cameras
Aug 8, 2016
3f66ba1
Disable a unity cameras until needed again
Aug 8, 2016
3bddc8a
Actually render image in delayed render task
Aug 8, 2016
78c3061
Make CameraManager responsible for Flightcam
Aug 8, 2016
4ff4c2e
Offset camera snapshot rendering to reduce stutte
Aug 8, 2016
8ddf736
Disable debug comment to check delay math
Aug 8, 2016
78bb2dc
Always set camera settings before snapshot render
Aug 9, 2016
dc1af89
Revert "Always set camera settings before snapshot render"
Aug 9, 2016
f8ee982
Revert "Revert "Always set camera settings before snapshot render""
Aug 9, 2016
a08fb41
Revert "Revert "Revert "Always set camera settings before snapshot re…
Aug 9, 2016
da53cae
Add very verbose debugging for cameras
Aug 9, 2016
107eb97
Fix adjustment of Galaxy/scaled cameras for RPM
Aug 9, 2016
c997121
Improve performance of RPM camera repositioning
Aug 9, 2016
39a06ad
Turn off very verbose camera details during update
Aug 9, 2016
2212509
Don't enable cameras, render them in corouting
Aug 10, 2016
ad62ebd
Update IOPageResponsibility.cs
johnmknight Aug 11, 2016
41553f1
Merge pull request #72 from johnmknight/patch-1
tcannonfodder Aug 12, 2016
405bbe3
Fix content type for text files
Aug 12, 2016
79cd1e3
Fix content type handler for JSON files
Aug 12, 2016
9aaabf6
Make Camera Endpoint Compatible with NGROK
Sep 29, 2016
30e6ea7
Merge remote-tracking branch 'refs/remotes/origin/master' into 69-cam…
Mar 23, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Parts/ThirdPartyParts/rpm-camera-support.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This patch file adds support for RasterPropMonitor cameras

@PART[JSIPrimitiveExternalCamera]
{
MODULE
{
name = RasterPropMonitorCamera
}
}
8 changes: 8 additions & 0 deletions Telemachus/Telemachus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="src\CameraSnapshots\CameraCapture.cs" />
<Compile Include="src\CameraSnapshots\IVACameraCapture.cs" />
<Compile Include="src\CameraSnapshots\CurrentFlightCameraCapture.cs" />
<Compile Include="src\CameraSnapshots\RasterPropMonitorCamera.cs" />
<Compile Include="src\CameraSnapshots\RasterPropMonitorCameraCapture.cs" />
<Compile Include="src\CameraSnapshots\CameraCaptureManager.cs" />
<Compile Include="src\CameraSnapshots\SnapshotRenderer.cs" />
<Compile Include="src\DataLinkFormatters.cs" />
<Compile Include="src\DataLinkHandlers.cs" />
<Compile Include="src\CameraResponsibility.cs" />
<Compile Include="src\DataLinkResponsibility.cs" />
<Compile Include="src\ElseResponsibility.cs" />
<Compile Include="src\IOPageResponsibility.cs" />
Expand Down
177 changes: 177 additions & 0 deletions Telemachus/src/CameraResponsibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
//Author: Richard Bunt
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading;
using System.Reflection;
using WebSocketSharp.Net;
using WebSocketSharp;
using UnityEngine;
using System.Collections;
using Telemachus.CameraSnapshots;
using System.Text.RegularExpressions;

namespace Telemachus
{
public class CameraResponsibility : IHTTPRequestResponder
{
/// The page prefix that this class handles
public const String PAGE_PREFIX = "/telemachus/cameras";
public const String CAMERA_LIST_ENDPOINT = PAGE_PREFIX;
public const String NGROK_ORIGINAL_HOST_HEADER = "X-Original-Host";
protected Regex _cameraNameEndpointRegex;
protected Regex cameraNameEndpointRegex
{
get
{
if (_cameraNameEndpointRegex == null)
{
_cameraNameEndpointRegex = new Regex(Regex.Escape(PAGE_PREFIX) + "\\/(.+)");
}

return _cameraNameEndpointRegex;
}
}

/// The KSP API to use to access variable data
private IKSPAPI kspAPI = null;

private UpLinkDownLinkRate dataRates = null;



#region Initialisation

public CameraResponsibility(IKSPAPI kspAPI, UpLinkDownLinkRate rateTracker)
{
this.kspAPI = kspAPI;
dataRates = rateTracker;
}

public void setCameraCapture()
{
//PluginLogger.debug("START CAMERA CATPURE");

//PluginLogger.debug("CAM CAMPTURE CREATED");
}

#endregion

private static Dictionary<string,object> splitArguments(string argstring)
{
var ret = new Dictionary<string, object>();
if (argstring.StartsWith("?")) argstring = argstring.Substring(1);

foreach (var part in argstring.Split('&'))
{
var subParts = part.Split('=');
if (subParts.Length != 2) continue;
var keyName = UnityEngine.WWW.UnEscapeURL(subParts[0]);
var apiName = UnityEngine.WWW.UnEscapeURL(subParts[1]);
ret[keyName] = apiName;
}
return ret;
}

private static IDictionary<string, object> parseJSONBody(string jsonBody)
{
return (IDictionary<string, object>)SimpleJson.SimpleJson.DeserializeObject(jsonBody);
}

public string cameraURL(HttpListenerRequest request, CameraCapture camera)
{
String hostname = "";
if (request.Headers.Contains(NGROK_ORIGINAL_HOST_HEADER))
{
hostname = request.Headers[NGROK_ORIGINAL_HOST_HEADER];
}
else
{
hostname = request.UserHostName;
}

return request.Url.Scheme + "://" + hostname + PAGE_PREFIX + "/" + UnityEngine.WWW.EscapeURL(camera.cameraManagerName());
}

public bool processCameraManagerIndex(HttpListenerRequest request, HttpListenerResponse response)
{
if (GameObject.Find("CurrentFlightCameraCapture") == null)
{
//PluginLogger.debug("REBUILDING CAMERA CAPTURE");
this.setCameraCapture();
}

var jsonObject = new List<Dictionary<string, object>>();

foreach(KeyValuePair<string, CameraCapture> cameraKVP in CameraCaptureManager.classedInstance.cameras)
{
var jsonData = new Dictionary<string, object>();
jsonData["name"] = cameraKVP.Value.cameraManagerName();
jsonData["type"] = cameraKVP.Value.cameraType();
jsonData["url"] = cameraURL(request, cameraKVP.Value);

jsonObject.Add(jsonData);
}

byte[] jsonBytes = Encoding.UTF8.GetBytes(SimpleJson.SimpleJson.SerializeObject(jsonObject));

response.ContentEncoding = Encoding.UTF8;
response.ContentType = "application/json";
response.WriteContent(jsonBytes);
dataRates.SendDataToClient(jsonBytes.Length);

return true;
}

public bool processCameraImageRequest(string cameraName, HttpListenerRequest request, HttpListenerResponse response)
{
cameraName = cameraName.ToLower();
if (!CameraCaptureManager.classedInstance.cameras.ContainsKey(cameraName))
{
response.StatusCode = 404;
return true;
}

CameraCapture camera = CameraCaptureManager.classedInstance.cameras[cameraName];
//PluginLogger.debug("RENDERING SAVED CAMERA: "+ camera.cameraManagerName());
if (camera.didRender)
{
response.ContentEncoding = Encoding.UTF8;
response.ContentType = "image/jpeg";
response.WriteContent(camera.imageBytes);
dataRates.SendDataToClient(camera.imageBytes.Length);
}
else
{
response.StatusCode = 503;
}

return true;
}

public bool process(HttpListenerRequest request, HttpListenerResponse response)
{
//PluginLogger.debug(request.Url.AbsolutePath.TrimEnd('/'));
//PluginLogger.debug(String.Join(",", CameraCaptureManager.classedInstance.cameras.Keys.ToArray()));
//PluginLogger.debug("FLIGHT CAMERA: " + this.cameraCaptureTest);
if (request.Url.AbsolutePath.TrimEnd('/').ToLower() == CAMERA_LIST_ENDPOINT)
{
// Work out how big this request was
long byteCount = request.RawUrl.Length + request.ContentLength64;
// Don't count headers + request.Headers.AllKeys.Sum(x => x.Length + request.Headers[x].Length + 1);
dataRates.RecieveDataFromClient(Convert.ToInt32(byteCount));

return processCameraManagerIndex(request, response);
} else if (cameraNameEndpointRegex.IsMatch(request.Url.AbsolutePath))
{
Match match = cameraNameEndpointRegex.Match(request.Url.AbsolutePath);
string cameraName = UnityEngine.WWW.UnEscapeURL(match.Groups[1].Value);
//PluginLogger.debug("GET CAMERA: " + cameraName);
return processCameraImageRequest(cameraName, request, response);
}

return false;
}
}
}
Loading