?[package:][type:]na
public static final int editText1=0x7f080002;
public static final int hostTextView=0x7f080000;
public static final int statusButton=0x7f080001;
- public static final int videoView=0x7f080003;
}
public static final class layout {
public static final int activity_connection=0x7f030000;
@@ -113,7 +112,7 @@ or to a theme attribute in the form "?[package:][type:]na
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
- @attr name com.limelight:buttonBarButtonStyle
+ @attr name android:buttonBarButtonStyle
*/
public static final int ButtonBarContainerTheme_buttonBarButtonStyle = 1;
/**
@@ -123,7 +122,7 @@ or to a theme attribute in the form "?[package:][type:]na
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
- @attr name com.limelight:buttonBarStyle
+ @attr name android:buttonBarStyle
*/
public static final int ButtonBarContainerTheme_buttonBarStyle = 0;
};
diff --git a/res/layout/activity_connection.xml b/res/layout/activity_connection.xml
index a291bb75..b2b265b8 100644
--- a/res/layout/activity_connection.xml
+++ b/res/layout/activity_connection.xml
@@ -17,7 +17,7 @@
android:layout_marginTop="60dp"
android:ems="10"
android:hint="255.255.255.255"
- android:textSize="100dp" >
+ android:textSize="50dp" >
diff --git a/src/com/limelight/Connection.java b/src/com/limelight/Connection.java
index 66f91ac0..747e41f5 100644
--- a/src/com/limelight/Connection.java
+++ b/src/com/limelight/Connection.java
@@ -1,17 +1,12 @@
package com.limelight;
-import java.io.IOException;
-
-import org.xmlpull.v1.XmlPullParserException;
-
-import com.limelight.nvstream.NvConnection;
-
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
+import android.content.Intent;
import android.content.SharedPreferences;
public class Connection extends Activity {
@@ -20,7 +15,7 @@ public class Connection extends Activity {
private SharedPreferences prefs;
private static final String DEFAULT_HOST = "141.213.191.238";
- public static final String HOST_KEY = "hostText";
+ public static final String HOST_KEY = "hostKey";
@Override
@@ -32,7 +27,7 @@ public class Connection extends Activity {
public void onPause() {
SharedPreferences.Editor editor = prefs.edit();
- editor.putString(this.HOST_KEY, this.hostText.toString());
+ editor.putString(Connection.HOST_KEY, this.hostText.toString());
editor.apply();
super.onPause();
@@ -53,22 +48,15 @@ public class Connection extends Activity {
this.hostText = (TextView) findViewById(R.id.hostTextView);
prefs = getPreferences(0);
- this.hostText.setText(prefs.getString(this.HOST_KEY, this.DEFAULT_HOST));
+ this.hostText.setText(prefs.getString(Connection.HOST_KEY, Connection.DEFAULT_HOST));
this.statusButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
- try {
- new NvConnection(Connection.this.statusButton.getText().toString()).doShit();
- } catch (XmlPullParserException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ Intent intent = new Intent(Connection.this, Game.class);
+ intent.putExtra("host", Connection.this.hostText.getText().toString());
+ Connection.this.startActivity(intent);
}
-
});
}
diff --git a/src/com/limelight/Game.java b/src/com/limelight/Game.java
index 638bcc69..3a3b772b 100644
--- a/src/com/limelight/Game.java
+++ b/src/com/limelight/Game.java
@@ -1,6 +1,8 @@
package com.limelight;
import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import org.xmlpull.v1.XmlPullParserException;
@@ -18,44 +20,19 @@ import android.widget.VideoView;
public class Game extends Activity {
- private VideoView vv;
- private MediaController mc;
private short inputMap = 0x0000;
+ private NvConnection conn;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_game);
+
OuyaController.init(this);
- new Thread(new Runnable() {
-
- @Override
- public void run() {
- try {
- new NvConnection("141.213.191.238").doShit();
- } catch (XmlPullParserException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- }).start();
-
- setContentView(R.layout.activity_game);
-
- /*vv = (VideoView) findViewById(R.id.videoView);
-
- mc = new MediaController(this);
- mc.setAnchorView(vv);
-
- Uri video = Uri.parse("rtsp://141.213.191.236:47902/nvstream");
- vv.setMediaController(mc);
- vv.setVideoURI(video);
-
- vv.start();*/
+ conn = new NvConnection(Game.this.getIntent().getStringExtra("host"), Game.this);
+ conn.start();
}
@Override
@@ -187,7 +164,6 @@ public class Game extends Activity {
}
private void sendInputPacket() {
- NvInputPacket inputPacket = new NvInputPacket(inputMap, (byte)0, (byte)0, (byte)0, (byte)0);
-
+ conn.sendControllerInput(inputMap, (byte)0, (byte)0, (byte)0, (byte)0);
}
}
diff --git a/src/com/limelight/nvstream/NvAudioStream.java b/src/com/limelight/nvstream/NvAudioStream.java
index d34f915b..15bcee0f 100644
--- a/src/com/limelight/nvstream/NvAudioStream.java
+++ b/src/com/limelight/nvstream/NvAudioStream.java
@@ -3,11 +3,7 @@ package com.limelight.nvstream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
-import java.net.InetAddress;
import java.net.SocketException;
-import java.net.UnknownHostException;
-
-import android.net.rtp.AudioCodec;
import android.net.rtp.AudioGroup;
import android.net.rtp.AudioStream;
diff --git a/src/com/limelight/nvstream/NvConnection.java b/src/com/limelight/nvstream/NvConnection.java
index 0ad0b132..1b74191b 100644
--- a/src/com/limelight/nvstream/NvConnection.java
+++ b/src/com/limelight/nvstream/NvConnection.java
@@ -1,79 +1,133 @@
package com.limelight.nvstream;
import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
import org.xmlpull.v1.XmlPullParserException;
+import android.app.Activity;
+import android.widget.Toast;
+
+import com.limelight.Game;
import com.limelight.nvstream.input.NvController;
public class NvConnection {
private String host;
+ private Activity activity;
- public NvConnection(String host)
+ private NvControl controlStream;
+ private NvController inputStream;
+
+ private ThreadPoolExecutor threadPool;
+
+ public NvConnection(String host, Activity activity)
{
this.host = host;
+ this.activity = activity;
+ this.threadPool = new ThreadPoolExecutor(1, 1, Long.MAX_VALUE, TimeUnit.DAYS, new LinkedBlockingQueue());
+ }
+
+ public void start()
+ {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ host = InetAddress.getByName(host).toString().substring(1);
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ displayToast(e.getMessage());
+ return;
+ }
+
+ try {
+ startSteamBigPicture();
+ performHandshake();
+ beginControlStream();
+ startController();
+ } catch (XmlPullParserException e) {
+ e.printStackTrace();
+ displayToast(e.getMessage());
+ } catch (IOException e) {
+ e.printStackTrace();
+ displayToast(e.getMessage());
+ }
+ }
+ }).start();
}
- private void delay(int ms)
+ public void sendControllerInput(final short buttonFlags,
+ final byte leftTrigger, final byte rightTrigger,
+ final short leftStick, final short rightStick)
{
- try {
- Thread.sleep(ms);
- } catch (InterruptedException e) {
+ threadPool.execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ inputStream.sendControllerInput(buttonFlags, leftTrigger, rightTrigger, leftStick, rightStick);
+ } catch (IOException e) {
+ e.printStackTrace();
+ displayToast(e.getMessage());
+ }
+ }
+ });
+ }
+
+ private void displayToast(final String message)
+ {
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(activity, message, Toast.LENGTH_LONG).show();
+ }
+ });
+ }
+
+ private void startSteamBigPicture() throws XmlPullParserException, IOException
+ {
+ NvHttp h = new NvHttp(host, "b0:ee:45:57:5d:5f");
+
+ if (!h.getPairState())
+ {
+ displayToast("Device not paired with computer");
return;
}
+
+ int sessionId = h.getSessionId();
+ int appId = h.getSteamAppId(sessionId);
+
+ System.out.println("Starting game session");
+ int gameSession = h.launchApp(sessionId, appId);
+ System.out.println("Started game session: "+gameSession);
+ }
+
+ private void performHandshake() throws UnknownHostException, IOException
+ {
+ System.out.println("Starting handshake");
+ NvHandshake.performHandshake(host);
+ System.out.println("Handshake complete");
+ }
+
+ private void beginControlStream() throws UnknownHostException, IOException
+ {
+ controlStream = new NvControl(host);
+
+ System.out.println("Starting control");
+ controlStream.beginControl();
+ }
+
+ private void startController() throws UnknownHostException, IOException
+ {
+ System.out.println("Starting input");
+ inputStream = new NvController(host);
}
public void doShit() throws XmlPullParserException, IOException
{
- NvHttp h = new NvHttp(host, "b0:ee:45:57:5d:5f");
-
- System.out.println("Begin Shield Action");
- System.out.println(h.getAppVersion());
- System.out.println(h.getPairState());
-
- int sessionId = h.getSessionId();
- System.out.println("Session ID: "+sessionId);
- int appId = h.getSteamAppId(sessionId);
- System.out.println("Steam app ID: "+appId);
- int gameSession = h.launchApp(sessionId, appId);
- System.out.println("Started game session: "+gameSession);
-
- System.out.println("Starting handshake");
- NvHandshake.performHandshake(host);
- System.out.println("Handshake complete");
-
- NvControl nvC = new NvControl(host);
-
- System.out.println("Starting control");
- nvC.beginControl();
-
- System.out.println("Startup controller");
- NvController controller = new NvController(host);
-
- // Wait 3 seconds to start input
- delay(3000);
-
- System.out.println("Beginning controller input");
- controller.sendLeftButton();
- delay(100);
- controller.clearButtons();
- delay(250);
- controller.sendRightButton();
- delay(100);
- controller.clearButtons();
- delay(250);
- controller.sendRightButton();
- delay(100);
- controller.clearButtons();
- delay(250);
- controller.sendRightButton();
- delay(100);
- controller.clearButtons();
- delay(250);
- controller.sendLeftButton();
- delay(100);
- controller.clearButtons();
-
new NvAudioStream().start();
new NvVideoStream().start(host);
}
diff --git a/src/com/limelight/nvstream/input/NvController.java b/src/com/limelight/nvstream/input/NvController.java
index 1b63aa3d..dbef5c13 100644
--- a/src/com/limelight/nvstream/input/NvController.java
+++ b/src/com/limelight/nvstream/input/NvController.java
@@ -4,9 +4,6 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
public class NvController {
@@ -21,21 +18,9 @@ public class NvController {
out = s.getOutputStream();
}
- // Example
- public void sendLeftButton() throws IOException
+ public void sendControllerInput(short buttonFlags, byte leftTrigger, byte rightTrigger, short leftStick, short rightStick) throws IOException
{
- out.write(new NvInputPacket(NvInputPacket.LEFT_FLAG, (byte)0, (byte)0, (short)0, (short)0).toWire());
- }
-
- // Example
- public void sendRightButton() throws IOException
- {
- out.write(new NvInputPacket(NvInputPacket.RIGHT_FLAG, (byte)0, (byte)0, (short)0, (short)0).toWire());
- }
-
- // Example
- public void clearButtons() throws IOException
- {
- out.write(new NvInputPacket((short)0, (byte)0, (byte)0, (short)0, (short)0).toWire());
+ out.write(new NvInputPacket(buttonFlags, leftTrigger, rightTrigger, leftStick, rightStick).toWire());
+ out.flush();
}
}