Skip to content

Commit

Permalink
Re-Implement Proto and fix memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hansel committed Apr 16, 2016
1 parent 18393a4 commit 147b750
Show file tree
Hide file tree
Showing 4 changed files with 2,507 additions and 8 deletions.
40 changes: 32 additions & 8 deletions HyperionScreenCap/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public partial class Form1 : Form
{
static string hyperionServerIP = ConfigurationManager.AppSettings["hyperionServerIP"];
static int hyperionServerJsonPort = int.Parse(ConfigurationManager.AppSettings["hyperionServerJsonPort"]);
static int hyperionMessagePriority = int.Parse(ConfigurationManager.AppSettings["hyperionMessagePriority"]);
static int hyperionMessageDuration = int.Parse(ConfigurationManager.AppSettings["hyperionMessageDuration"]);
static public int hyperionMessagePriority = int.Parse(ConfigurationManager.AppSettings["hyperionMessagePriority"]);
static public int hyperionMessageDuration = int.Parse(ConfigurationManager.AppSettings["hyperionMessageDuration"]);
static public int hyperionWidth = int.Parse(ConfigurationManager.AppSettings["width"]);
static public int hyperionHeight = int.Parse(ConfigurationManager.AppSettings["height"]);
static public int captureInterval = int.Parse(ConfigurationManager.AppSettings["captureInterval"]);
static public int monitorIndex = int.Parse(ConfigurationManager.AppSettings["monitorIndex"]);
static int hyperionServerProtoPort = int.Parse(ConfigurationManager.AppSettings["hyperionServerProtoPort"]);
static string protocol = ConfigurationManager.AppSettings["protocol"];

static DxScreenCapture d;

Expand All @@ -45,8 +47,18 @@ public Form1()
trayIcon.Visible = true;

d = new DxScreenCapture();
connectToServer(hyperionServerIP, hyperionServerJsonPort);
if (Connected())

if (protocol == "json")
{
connectToServer(hyperionServerIP, hyperionServerJsonPort);
}
else if(protocol == "proto")
{
protoClient = new ProtoClient();
protoClient.Init(hyperionServerIP, hyperionServerProtoPort, hyperionMessagePriority);
}

if (Connected() || protoClient.isConnected())
{
Notifications.Info("Connected to Hyperion!");

Expand Down Expand Up @@ -101,18 +113,29 @@ static void capture()
try
{
Surface s = d.CaptureScreen();

DataRectangle dr = s.LockRectangle(LockFlags.None);
DataStream gs = dr.Data;

var x = removeAlpha(gs);

s.UnlockRectangle();
s.Dispose();
gs.Dispose();

var y = Convert.ToBase64String(x);
setImage(y, hyperionMessagePriority, hyperionMessageDuration);
y = null;

if (protocol == "json")
{
var y = Convert.ToBase64String(x);
setImage(y, hyperionMessagePriority, hyperionMessageDuration);
y = null;
}
else if (protocol == "proto")
{
protoClient.SendImage(x, null);
}


}
catch (Exception ex)
{
Expand Down Expand Up @@ -167,6 +190,7 @@ static byte[] resizeImageArray(DataStream ia, int factor)
#region TcpClient

static TcpClient hyperionServer;
static ProtoClient protoClient;
static NetworkStream serverStream;
static StreamWriter sendToServer;
static StreamReader readFromServer;
Expand Down
Loading

0 comments on commit 147b750

Please sign in to comment.