继续操作前请注册或者登录。
胡斌

parse get_cam ok

正在显示 1 个修改的文件 包含 116 行增加142 行删除
@@ -140,6 +140,7 @@ a:active { @@ -140,6 +140,7 @@ a:active {
140 var url = ""; 140 var url = "";
141 var output; 141 var output;
142 var wsState = "idle"; 142 var wsState = "idle";
  143 + var websocket;
143 144
144 function testWebSocket() 145 function testWebSocket()
145 { 146 {
@@ -162,7 +163,7 @@ a:active { @@ -162,7 +163,7 @@ a:active {
162 writeToScreen("DISCONNECTED"); 163 writeToScreen("DISCONNECTED");
163 wsState = "idle"; 164 wsState = "idle";
164 } 165 }
165 - 166 +
166 function onMessage(evt) 167 function onMessage(evt)
167 { 168 {
168 if(typeof(evt.data)=="string"){ 169 if(typeof(evt.data)=="string"){
@@ -172,44 +173,91 @@ a:active { @@ -172,44 +173,91 @@ a:active {
172 writeToScreen('<span style="color: blue;">receive binary</span>'); 173 writeToScreen('<span style="color: blue;">receive binary</span>');
173 var reader = new FileReader(); 174 var reader = new FileReader();
174 reader.onload = function(evt){ 175 reader.onload = function(evt){
175 - if(evt.target.readyState == FileReader.DONE){  
176 -  
177 - var buffer = evt.target.result;  
178 -  
179 - writeToScreen('<span style="color: blue;">receive string ' + buffer.byteLength +'</span>');  
180 - var result = new Uint16Array(buffer, 0, 1);  
181 - var byte_order = new Uint8Array(buffer, 2, 1);  
182 - var data_len = new Uint32Array(buffer, 4, 1);  
183 - var data = new Uint8Array(buffer, 8, buffer.byteLength - 8);  
184 - var data_sting = new TextDecoder("utf-8").decode(data)  
185 - writeToScreen('<span style="color: blue;">RESPONSE: ' + data_sting + ' </span>');  
186 - }  
187 - } 176 + if(evt.target.readyState == FileReader.DONE){
  177 + var dv = new DataView(evt.target.result);
  178 + writeToScreen('<span style="color: blue;">receive string ' + dv.byteLength +'</span>');
  179 + var result = dv.getUint16(0, true);
  180 + var byte_order = dv.getUint8(2, true);
  181 + var data_len = dv.getUint32(4, true);
  182 +
  183 + if(result == 83){
  184 + if(data_len > 4){
  185 + var cam_num = dv.getUint32(8, true);
  186 + var offset = 12;
  187 + for(var i=0;i<cam_num; i++){
  188 + var cam_name_len = dv.getUint32(offset, true);
  189 + offset += 4;
  190 + var cam_name = new Uint8Array(evt.target.result, offset , cam_name_len - 1);
  191 + offset += cam_name_len;
  192 + var data_sting = new TextDecoder("utf-8").decode(cam_name);
  193 + writeToScreen('<span style="color: blue;">Camera: ' + i + " " + data_sting + ' </span>');
  194 + }
  195 + }
  196 + }
  197 + else{
  198 + var data_sting = new TextDecoder("utf-8").decode(data);
  199 + writeToScreen('<span style="color: blue;">RESPONSE: ' + data_sting + ' </span>');
  200 + }
  201 + }
  202 + }
188 reader.readAsArrayBuffer(evt.data); 203 reader.readAsArrayBuffer(evt.data);
189 } 204 }
190 - websocket.close();  
191 - } 205 + }
192 206
193 function onError(evt) 207 function onError(evt)
194 { 208 {
195 writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data); 209 writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
196 } 210 }
197 211
198 - function doSend(message) 212 + function doSendWSCmd(wsCmd)
199 { 213 {
200 - writeToScreen("SENT: " + message);  
201 - var cmd_type = 54;//get mic volume  
202 - var cmd_buf_len = 2 + 1*2 + 4; 214 + writeToScreen("SENT: " + wsCmd.name);
  215 +
  216 + var cmd_buf_len = 2 + 1*2 + 4 + wsCmd.data_len;
203 var buffer = new ArrayBuffer(cmd_buf_len); 217 var buffer = new ArrayBuffer(cmd_buf_len);
204 var cmd = new Uint16Array(buffer, 0, 1); 218 var cmd = new Uint16Array(buffer, 0, 1);
205 var byte_order = new Uint8Array(buffer, 2, 1); 219 var byte_order = new Uint8Array(buffer, 2, 1);
206 var data_len = new Uint32Array(buffer, 4, 1); 220 var data_len = new Uint32Array(buffer, 4, 1);
207 - cmd[0] = cmd_type; 221 +
  222 + cmd[0] = wsCmd.type;
208 byte_order[0] = 0; 223 byte_order[0] = 0;
209 - data_len[0] = 0; 224 + data_len[0] = wsCmd.data_len;
  225 +/*
  226 + var byteBuffer = new Uint8Array(buffer);
  227 + var dv = new DataView(buffer);
  228 +
  229 + dv.setUint16(0, wsCmd.type);
  230 + dv.setUint8(2, 1);
  231 + dv.setUint32(1, wsCmd.data_len);*/
210 232
  233 + if(wsCmd.data_len > 0){
  234 + var data_buf = new Uint8Array(buffer, 8, wsCmd.data_len);
  235 + for(var i=0;i< wsCmd.data_len; i++){
  236 + data_buf[i] = wsCmd.data[i];
  237 + }
  238 + }
  239 +
211 websocket.send(buffer); 240 websocket.send(buffer);
212 } 241 }
  242 +
  243 + function onTestClick(obj)
  244 + {
  245 + writeToScreen(obj.id);
  246 + var cmd = new Object();
  247 + cmd.data_len = 0;
  248 + cmd.data = "";
  249 + cmd.name = obj.id;
  250 + if(obj.id == "ss_start"){
  251 + cmd.type = 6;
  252 + }
  253 + else if(obj.id == "ss_stop"){
  254 + cmd.type = 7;
  255 + }
  256 + else if(obj.id == "get_cam"){
  257 + cmd.type = 41;
  258 + }
  259 + doSendWSCmd(cmd);
  260 + }
213 261
214 function writeToScreen(message) 262 function writeToScreen(message)
215 { 263 {
@@ -265,7 +313,7 @@ a:active { @@ -265,7 +313,7 @@ a:active {
265 queryParameters['idx'] = getUrlParam('idx'); 313 queryParameters['idx'] = getUrlParam('idx');
266 314
267 if( queryParameters['source'] == "" ) 315 if( queryParameters['source'] == "" )
268 - queryParameters['source'] = "rtmp://localhost/vod/mp4:sample1_500kbps.f4v"; 316 + queryParameters['source'] = "rtmp://localhost/live/ss";
269 317
270 if( queryParameters['type'] == "" ) 318 if( queryParameters['type'] == "" )
271 queryParameters['type'] = "recorded"; 319 queryParameters['type'] = "recorded";
@@ -378,7 +426,7 @@ a:active { @@ -378,7 +426,7 @@ a:active {
378 { 426 {
379 output.innerHTML = ""; 427 output.innerHTML = "";
380 } 428 }
381 - 429 +
382 initialise(); 430 initialise();
383 431
384 </script> 432 </script>
@@ -444,127 +492,69 @@ a:active { @@ -444,127 +492,69 @@ a:active {
444 <td width="359" height="186" background="images/upperright_03.gif"><table width="358" border="0" cellspacing="0" cellpadding="0"> 492 <td width="359" height="186" background="images/upperright_03.gif"><table width="358" border="0" cellspacing="0" cellpadding="0">
445 <tr> 493 <tr>
446 <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td> 494 <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
447 - <td width="323"><span class="style75">SELECT A VIDEO FROM THE LIST BELOW</span></td> 495 + <td width="323"><span class="style75">click on following buttons to test liveserver method</span></td>
448 </tr> 496 </tr>
449 <tr> 497 <tr>
450 - <td colspan="3"><img src="images/spacer.gif" width="20" height="5" /></td>  
451 - </tr>  
452 - <tr>  
453 - <td colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>  
454 - <td><span class="style75">SOURCE: /applications/vod/media</span></td> 498 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  499 + <td colspan="3"><button type="button" id="ss_start" onclick="onTestClick(this)">ss_start</button></td>
455 </tr> 500 </tr>
456 <tr> 501 <tr>
457 - <td colspan="3"><img src="images/spacer.gif" width="20" height="5" /></td>  
458 - </tr>  
459 - <tr>  
460 - <td><img src="images/spacer.gif" width="20" height="10" /></td>  
461 - <td id="sel1"><span class="style74">&gt;</span></td>  
462 - <td id="td1" class="style76"><a href="demo.html?source=rtmp://localhost/vod/mp4:sample1_150kbps.f4v&type=recorded&idx=1">sample1_150kbps.f4v</a></td> 502 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  503 + <td colspan="3"><button type="button" id="ss_stop" onclick="javascript:onTestClick(this);">ss_stop</button></td>
463 </tr> 504 </tr>
464 - <tr>  
465 - <td colspan="3"><img src="images/spacer.gif" width="20" height="10" /></td>  
466 - </tr>  
467 - <tr>  
468 - <td><img src="images/spacer.gif" width="15" height="5" /></td>  
469 - <td id="sel2"><span class="style74">&gt;</span></td>  
470 - <td class="style76" id="td2"> <a href="demo.html?source=rtmp://localhost/vod/mp4:sample1_500kbps.f4v&type=recorded&idx=2">sample1_500kbps.f4v</a></td> 505 + <tr>
  506 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  507 + <td colspan="3"><button type="button" id="ds_start" onclick="javascript:onTestClick(this);">ds_start</button></td>
471 </tr> 508 </tr>
472 - <tr>  
473 - <td colspan="3"><img src="images/spacer.gif" width="20" height="5" /></td>  
474 - </tr>  
475 - <tr>  
476 - <td><img src="images/spacer.gif" width="20" height="10" /></td>  
477 - <td id="sel3"><span class="style74">&gt;</span></td>  
478 - <td id="td3" class="style76"><a href="demo.html?source=rtmp://localhost/vod/mp4:sample1_700kbps.f4v&type=recorded&idx=3">sample1_700kbps.f4v</a></td> 509 + <tr>
  510 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  511 + <td colspan="3"><button type="button" id="ds_stop" onclick="javascript:onTestClick(this);">ds_stop</button></td>
479 </tr> 512 </tr>
480 - <tr>  
481 - <td colspan="3"><img src="images/spacer.gif" width="20" height="5" /></td>  
482 - </tr>  
483 - <tr>  
484 - <td><img src="images/spacer.gif" width="20" height="10" /></td>  
485 - <td id="sel4"><span class="style74">&gt;</span></td>  
486 - <td id="td4" class="style76"><a href="demo.html?source=rtmp://localhost/vod/mp4:sample1_1000kbps.f4v&type=recorded&idx=4">sample1_1000kbps.f4v</a></td> 513 + <tr>
  514 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  515 + <td colspan="3"><button type="button" id="get_mic" onclick="javascript:onTestClick(this);">get_mic</button></td>
487 </tr> 516 </tr>
488 - <tr>  
489 - <td colspan="3"><img src="images/spacer.gif" width="20" height="5" /></td>  
490 - </tr>  
491 - <tr>  
492 - <td><img src="images/spacer.gif" width="20" height="10" /></td>  
493 - <td id="sel5"><span class="style74">&gt;</span></td>  
494 - <td id="td5" class="style76"><a href="demo.html?source=rtmp://localhost/vod/mp4:sample1_1500kbps.f4v&type=recorded&idx=5">sample1_1500kbps.f4v</a></td> 517 + <tr>
  518 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  519 + <td colspan="3"><button type="button" id="aud_start" onclick="javascript:onTestClick(this);">aud_start</button></td>
495 </tr> 520 </tr>
496 - <tr>  
497 - <td colspan="3"><img src="images/spacer.gif" width="20" height="5" /></td>  
498 - </tr>  
499 - <tr>  
500 - <td><img src="images/spacer.gif" width="20" height="10" /></td>  
501 - <td id="sel6"><span class="style74">&gt;</span></td>  
502 - <td id="td6" class="style76"><a href="demo.html?source=rtmp://localhost/vod/sample&type=recorded&idx=6">sample.flv</a></td> 521 + <tr>
  522 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  523 + <td colspan="3"><button type="button" id="aud_stop" onclick="javascript:onTestClick(this);">aud_stop</button></td>
503 </tr> 524 </tr>
504 - </table></td>  
505 - </tr>  
506 - <tr>  
507 - <td width="359" height="114" background="images/middleright_05.gif"><table width="358" border="0" cellspacing="0" cellpadding="0">  
508 - <tr>  
509 - <td colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>  
510 - <td width="323" class="style75">SOURCE: /webroot/vod</td> 525 + <tr>
  526 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  527 + <td colspan="3"><button type="button" id="mov_start" onclick="javascript:onTestClick(this);">mov_start</button></td>
511 </tr> 528 </tr>
512 - <tr>  
513 - <td colspan="2"><img src="images/spacer.gif" width="20" height="5" /></td>  
514 - </tr>  
515 - <tr>  
516 - <td><img src="images/spacer.gif" width="20" height="10" /></td>  
517 - <td id="sel7"><span class="style74">&gt;</span></td>  
518 - <td id="td7" class="style76"><a href="demo.html?source=hds_sample1_manifest.f4m&type=recorded&idx=7" title="Only works when viewed from localhost.">hds_sample1_manifest.f4m</a></td> 529 + <tr>
  530 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  531 + <td colspan="3"><button type="button" id="mov_stop" onclick="javascript:onTestClick(this);">mov_stop</button></td>
519 </tr> 532 </tr>
520 - <tr>  
521 - <td colspan="2"><img src="images/spacer.gif" width="20" height="5" /></td>  
522 - </tr>  
523 - <tr>  
524 - </tr><tr>  
525 - <td><img src="images/spacer.gif" width="20" height="10" /></td>  
526 - <td id="sel8"><span class="style74">&gt;</span></td>  
527 - <td id="td8" class="style76"><a href="demo.html?source=rtmp_sample1_manifest.f4m&type=recorded&idx=8" title="Only works when viewed from localhost.">rtmp_sample1_manifest.f4m</a></td> 533 + <tr>
  534 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  535 + <td colspan="3"><button type="button" id="get_cam" onclick="javascript:onTestClick(this);">get_cam</button></td>
528 </tr> 536 </tr>
529 - <tr>  
530 - <td colspan="2"><img src="images/spacer.gif" width="20" height="5" /></td>  
531 - </tr>  
532 - <tr>  
533 - <td><img src="images/spacer.gif" width="20" height="10" /></td>  
534 - <td id="sel9"><span class="style74">&gt;</span></td>  
535 - <td id="td9" class="style76"><a href="demo.html?source=http://localhost/vod/sample2_1000kbps.f4v&type=recorded&idx=9">sample2_1000kbps.f4v (http progressive)</a></td> 537 + <tr>
  538 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  539 + <td colspan="3"><button type="button" id="cam_start" onclick="javascript:onTestClick(this);">cam_start</button></td>
536 </tr> 540 </tr>
537 - <tr>  
538 - <td colspan="2"><img src="images/spacer.gif" width="20" height="5" /></td>  
539 - </tr>  
540 - <tr>  
541 - <td><img src="images/spacer.gif" width="20" height="10" /></td>  
542 - <td id="sel10"><span class="style74">&gt;</span></td>  
543 - <td id="td10" class="style76"><a href="demo.html?source=rtmp://localhost/vod/mp4:sample2_1000kbps.f4v&type=recorded&idx=10">sample2_1000kbps.f4v (rtmp)</a></td> 541 + <tr>
  542 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  543 + <td colspan="3"><button type="button" id="cam_stop" onclick="javascript:onTestClick(this);">cam_stop</button></td>
544 </tr> 544 </tr>
545 -  
546 -  
547 - </table></td>  
548 - </tr>  
549 - <tr>  
550 - <td width="359" height="77" background="images/lowerright_07.gif"><table width="358" border="0" cellspacing="0" cellpadding="0">  
551 -  
552 - <tr>  
553 - <td colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>  
554 - <td width="322" class="style75">SOURCE: /applications/live</td> 545 + <tr>
  546 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  547 + <td colspan="3"><button type="button" id="start_push" onclick="javascript:onTestClick(this);">start_push</button></td>
555 </tr> 548 </tr>
556 - <tr>  
557 - <td colspan="2"><img src="images/spacer.gif" width="20" height="5" /></td>  
558 - </tr>  
559 - <tr>  
560 - <td><img src="images/spacer.gif" width="20" height="10" /></td>  
561 - <td id="sel11"><span class="style74">&gt;</span></td>  
562 - <td id="td11" class="style76"><a href="demo.html?source=rtmp://localhost/live/livestream&type=live&idx=11">livestream</a></td> 549 + <tr>
  550 + <td width="35" colspan="2"><img src="images/spacer.gif" width="20" height="10" /></td>
  551 + <td colspan="3"><button type="button" id="stop_push" onclick="javascript:onTestClick(this);">stop_push</button></td>
563 </tr> 552 </tr>
564 </table></td> 553 </table></td>
565 </tr> 554 </tr>
566 - </table></td> 555 + </td>
567 </tr> 556 </tr>
  557 + </tr>
568 </table></td> 558 </table></td>
569 </tr> 559 </tr>
570 </table></td> 560 </table></td>
@@ -572,8 +562,7 @@ a:active { @@ -572,8 +562,7 @@ a:active {
572 </tr> 562 </tr>
573 </table></td> 563 </table></td>
574 </tr> 564 </tr>
575 -  
576 - </table></td> 565 + </table></td>
577 </tr> 566 </tr>
578 </table></td> 567 </table></td>
579 </tr> 568 </tr>
@@ -608,21 +597,6 @@ a:active { @@ -608,21 +597,6 @@ a:active {
608 <td width="42%" align="left"><table width="100" border="0" cellspacing="0" cellpadding="0"> 597 <td width="42%" align="left"><table width="100" border="0" cellspacing="0" cellpadding="0">
609 <tr> 598 <tr>
610 <td width="5%" align="left"><img src="images/spacer.gif" width="10" height="10" /></td> 599 <td width="5%" align="left"><img src="images/spacer.gif" width="10" height="10" /></td>
611 - <td width="7%" align="left"><table width="0" >  
612 - <tr>  
613 - <td align="left"><div align="center">  
614 - <input type="checkbox" name="checkbox" id="vodCheckbox" checked onclick="checkbox('vod');" />  
615 - </div></td>  
616 - </tr>  
617 - </table></td>  
618 - <td width="2%" align="left"><img src="images/spacer.gif" width="10" height="10" /></td>  
619 - <td width="6%" align="left"><div align="center"><span class="style31">VOD</span></div></td>  
620 - <td width="5%" align="left"><img src="images/spacer.gif" width="10" height="10" /></td>  
621 - <td width="5%" align="left"><div align="center">  
622 - <input type="checkbox" name="checkbox2" id="liveCheckbox" onclick="checkbox('live');" />  
623 - </div></td>  
624 - <td width="2%" align="left"><img src="images/spacer.gif" width="10" height="10" /></td>  
625 - <td width="6%" align="left"><span class="style31">LIVE</span></td>  
626 <td width="5%" align="left"><img src="images/spacer.gif" width="10" height="10" /></td> 600 <td width="5%" align="left"><img src="images/spacer.gif" width="10" height="10" /></td>
627 <td width="27%" align="left"><a id="playBtn" onclick="javascript:playStream();"><img src="images/playstream_10.gif" width="104" height="25" /></a></td> 601 <td width="27%" align="left"><a id="playBtn" onclick="javascript:playStream();"><img src="images/playstream_10.gif" width="104" height="25" /></a></td>
628 <td align="left">&nbsp;</td> 602 <td align="left">&nbsp;</td>