Do proper activity transitions. Send controller input to the streaming PC.

This commit is contained in:
Cameron Gutman 2013-09-21 20:40:38 -04:00
parent f9785b9dec
commit aa4376f3d7
8 changed files with 135 additions and 140 deletions

View File

@ -19,6 +19,11 @@
<activity
android:name="com.limelight.Connection"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.limelight.Game"
@ -29,15 +34,7 @@
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.limelight.Connection" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="com.limelight.RelayService"></service>
</application>
</manifest>

View File

@ -38,7 +38,6 @@ or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>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 "<code>?[<i>package</i>:][<i>type</i>:]<i>na
<p>Must be a reference to another resource, in the form "<code>@[+][<i>package</i>:]<i>type</i>:<i>name</i></code>"
or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>".
@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 "<code>?[<i>package</i>:][<i>type</i>:]<i>na
<p>Must be a reference to another resource, in the form "<code>@[+][<i>package</i>:]<i>type</i>:<i>name</i></code>"
or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>".
@attr name com.limelight:buttonBarStyle
@attr name android:buttonBarStyle
*/
public static final int ButtonBarContainerTheme_buttonBarStyle = 0;
};

View File

@ -17,7 +17,7 @@
android:layout_marginTop="60dp"
android:ems="10"
android:hint="255.255.255.255"
android:textSize="100dp" >
android:textSize="50dp" >
<requestFocus />
</EditText>

View File

@ -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);
}
});
}

View File

@ -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);
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);
OuyaController.init(this);
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);
}
}

View File

@ -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;

View File

@ -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<Runnable>());
}
private void delay(int ms)
public void start()
{
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
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();
}
public void sendControllerInput(final short buttonFlags,
final byte leftTrigger, final byte rightTrigger,
final short leftStick, final short rightStick)
{
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);
}

View File

@ -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();
}
}