Skip to content

Commit

Permalink
Control GUI is also OK.
Browse files Browse the repository at this point in the history
Signed-off-by: Zhou Chang <[email protected]>
  • Loading branch information
Teaonly committed Oct 14, 2014
1 parent 3b6efd6 commit 34a5a0c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 12 deletions.
7 changes: 6 additions & 1 deletion assets/css/mystyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ h1.logo {
margin-top: 12px;
}

.video-controls {
margin-top: 5px;
margin-bottom: 0px;
}

.video-container {
box-sizing: border-box;
position: relative;
margin-top: 10px;
margin-top: -5px;
}

.video-player {
Expand Down
12 changes: 8 additions & 4 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ <h1 class="logo">Wifi Camera:</h1>
</div>
</div>

<div class="video-controls">
<div class="span-info">
<span id="spanInfo">Conneting...</span>
<div class="video-controls toolbar">

<button class="btn btn-default" id="btnPlay" >Play</button>

<div class="span-info pull-right">
<span id="spanInfo"></span>
</div>

</div>

<div class="video-container">
Expand All @@ -37,7 +41,7 @@ <h1 class="logo">Wifi Camera:</h1>
</div><!-- end container for captions and video -->

<br>
<p class="pull-right">&copy; 2014 BeginVision, Inc.</p>
<p class="pull-right"><a href="https://github.com/etutunkina/android-eye">Fork from Github</a></p>
</div>


Expand Down
54 changes: 47 additions & 7 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ var config = {};
config.streamingPort = 8088;

var mediaSocket = null;

var player = null;
var myState = 0; // -1: error; 0: idle; 1: wainting; 2: palying

var streamer = {};
streamer.onOpen = function() {

};

streamer.onMessage = function(evt) {
if ( myState != 2) {
myState = 2;
$("#spanInfo").html("Playing...");
}
var blob = evt.data;
if ( blob.slice !== undefined) {
var media = new TeaMedia(blob, function() {
player.playMedia(media);
}.bind(this) );
}
};

streamer.onClose = function() {

alert("Mobile is disconnected!");
$("#btnPlay").prop('disabled', true);
$("#spanInfo").html("Please relaod...");
};

// like main function in C
$(document).ready(function() {

var connect = function() {
var myHost = window.location.hostname;
var wsURL = "ws://" + window.location.hostname + ":" + config.streamingPort;
mediaSocket = new WebSocket(wsURL);
Expand All @@ -34,4 +36,42 @@ $(document).ready(function() {
mediaSocket.onopen = streamer.onOpen;
mediaSocket.onmessage = streamer.onMessage;
mediaSocket.onclose = streamer.onClose;

$("#spanInfo").html("Connected, waiting for media..");
};

// like main function in C
$(document).ready(function() {
//$("#btnPlay").prop('disabled', false);

$("#btnPlay").click( function() {
if( myState == 0) {
myState = 1;
$("#btnPlay").html("Stop")
$("#spanInfo").html("Connecting...");

$.ajax({
url: "/cgi/query",
type: "get",
cache: false,
success: function(ret) {
console.log(ret);
var result = JSON.parse(ret);
if ( result["state"] === "ok") {
connect();
} else {
alert("Mobile is busy!");
location.reload();
}
},
error: function() {
alert("Mobile is error");
location.reload();
},
});
} else if (myState != -1) {
location.reload();
}
});

});
20 changes: 20 additions & 0 deletions src/teaonly/droideye/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ private boolean initWebServer() {
if ( ipAddr != null ) {
try{
webServer = new TeaServer(8080, this);
webServer.registerCGI("/cgi/query", doQuery);
}catch (IOException e){
webServer = null;
}
Expand Down Expand Up @@ -285,6 +286,25 @@ private void doVideoEncode(byte[] frame) {
executor.execute(videoTask);
};


private TeaServer.CommonGatewayInterface doQuery = new TeaServer.CommonGatewayInterface () {
@Override
public String run(Properties parms) {
String ret = "";
if ( streamingServer.inStreaming == true ) {
ret = "{\"state\": \"busy\"}";
} else {
ret = "{\"state\": \"ok\"}";
}
return ret;
}

@Override
public InputStream streaming(Properties parms) {
return null;
}
};

private class VideoEncodingTask implements Runnable {
private byte[] resultNal = new byte[1024*1024];
private byte[] videoHeader = new byte[8];
Expand Down

0 comments on commit 34a5a0c

Please sign in to comment.