Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
4.4 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. define ("ADD_ENCODER_SOURCE_IDX", 0);
  3. define ("ADD_STREAM_PROXY_IDX", 1);
  4. define ("CLOSE_STREAM_IDX", 2);
  5. define ("DEL_ENCODER_SOURCE_IDX", 3);
  6. define ("DEL_STREAM_PROXY_IDX", 4);
  7. define ("LIST_SESSIONS_IDX", 5);
  8. define ("LIST_API_IDX", 6);
  9. define ("LIST_MEDIA_IDX", 7);
  10. define ("GET_SERVER_CONFIG_IDX", 8);
  11. define ("GET_LOAD_STATS_IDX", 9);
  12. define ("GET_WORK_LOAD_STATS_IDX", 10);
  13. define ("KICK_SESSION_IDX", 11);
  14. define ("RESTART_SERVER_IDX", 12);
  15. define ("SET_SERVER_CONFIG_IDX", 13);
  16. define ("FETCH_STREAM_TCP", 0);
  17. define ("FETCH_STREAM_UDP", 1);
  18. define ("FETCH_STREAM_MULTICAST", 2);
  19. define ("ZL_DEFAULT_VHOST", '__defaultVhost__');
  20. class zlMediaServer{
  21. var $_secret = '';
  22. var $_addressREST = '';
  23. var $_addressPort = 8081;
  24. var $_accessURL = array();
  25. function __construct($Secret){
  26. $this->_secret = $Secret;
  27. $this->_addressREST = '127.0.0.1';
  28. $this->_accessURL[] = "/index/api/addFFmpegSource";
  29. $this->_accessURL[] = "/index/api/addStreamProxy";
  30. $this->_accessURL[] = "/index/api/close_stream";
  31. $this->_accessURL[] = "/index/api/delFFmepgSource";
  32. $this->_accessURL[] = "/index/api/delStreamProxy";
  33. $this->_accessURL[] = "/index/api/getAllSession";
  34. $this->_accessURL[] = "/index/api/getApiList";
  35. $this->_accessURL[] = "/index/api/getMediaList";
  36. $this->_accessURL[] = "/index/api/getServerConfig";
  37. $this->_accessURL[] = "/index/api/getThreadsLoad";
  38. $this->_accessURL[] = "/index/api/getWorkThreadsLoad";
  39. $this->_accessURL[] = "/index/api/kick_session";
  40. $this->_accessURL[] = "/index/api/restartServer";
  41. $this->_accessURL[] = "/index/api/setServerConfig";
  42. }
  43. function __destruct(){
  44. }
  45. public function setAccessPointREST( $address ){
  46. $this->_addressREST = $address;
  47. }
  48. private function composeURL( $idx ){
  49. return "http://" . $this->_addressREST . ':' . $this->_addressPort . $this->_accessURL[$idx] . '?secret=' . $this->_secret;
  50. }
  51. public function getServerConfig(){
  52. $pack['secret'] = $this->_secret;
  53. $ch = curl_init();
  54. curl_setopt( $ch, CURLOPT_URL, $this->composeURL( GET_SERVER_CONFIG_IDX ) );
  55. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  56. curl_setopt( $ch, CURLOPT_HEADER, 0);
  57. curl_setopt( $ch, CURLOPT_POST, 1);
  58. curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) );
  59. $output = curl_exec( $ch );
  60. curl_close( $ch );
  61. $AN = json_decode( $output );
  62. echo "Returned Transfer: " . $output ."\n\n";
  63. }
  64. public function addStreamProxy( $src, $appname, $rtsp_ena = 0, $rtmp_ena = 0, $hls_ena = 1, $recode_ena = 0, $rtp_type = FETCH_STREAM_TCP, $vhost=ZL_DEFAULT_VHOST ){
  65. $pack['secret'] = $this->_secret;
  66. $Params = '&vhost=' . urlencode( $vhost ) . '&app=' . urlencode( $appname ) . '&stream=0&url=' . $src . '&enable_rtsp=' . $rtsp_ena . '&enable_rtmp=' . $rtmp_ena . '&enable_hls=' . $hls_ena . '&enable_mp4=' . $recode_ena . '&rtp_type=' . $rtp_type;
  67. $ch = curl_init();
  68. curl_setopt( $ch, CURLOPT_URL, $this->composeURL( ADD_STREAM_PROXY_IDX ) . $Params );
  69. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  70. curl_setopt( $ch, CURLOPT_HEADER, 0);
  71. curl_setopt( $ch, CURLOPT_POST, 1);
  72. curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) );
  73. $output = curl_exec( $ch );
  74. curl_close( $ch );
  75. $AN = json_decode( $output );
  76. print_r( $AN );
  77. if( $AN->code == 0 ) {
  78. return $AN->data->key;
  79. };
  80. return '';
  81. }
  82. public function delStreamProxy( $key ){
  83. $pack['secret'] = $this->_secret;
  84. $Params = '&key=' . urlencode( $key );
  85. $ch = curl_init();
  86. curl_setopt( $ch, CURLOPT_URL, $this->composeURL( ADD_STREAM_PROXY_IDX ) . $Params );
  87. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  88. curl_setopt( $ch, CURLOPT_HEADER, 0);
  89. curl_setopt( $ch, CURLOPT_POST, 1);
  90. curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) );
  91. $output = curl_exec( $ch );
  92. curl_close( $ch );
  93. $AN = json_decode( $output );
  94. if( $AN['code'] == 0 ){
  95. return $AN['data']['flag'];
  96. };
  97. return false;
  98. }
  99. public function listMedia(){
  100. $pack['secret'] = $this->_secret;
  101. $ch = curl_init();
  102. curl_setopt( $ch, CURLOPT_URL, $this->composeURL( LIST_MEDIA_IDX ) );
  103. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  104. curl_setopt( $ch, CURLOPT_HEADER, 0);
  105. curl_setopt( $ch, CURLOPT_POST, 1);
  106. curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) );
  107. $output = curl_exec( $ch );
  108. curl_close( $ch );
  109. echo "Returned Transfer: " . $output ."\n\n";
  110. }
  111. }
  112. ?>