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.

115 lines
4.6 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, $strim_id, $rtsp_ena = 0, $rtmp_ena = 0, $hls_ena = 1, $recode_ena = 0, $rtp_type = FETCH_STREAM_UDP, $vhost=ZL_DEFAULT_VHOST ){
  65. $pack['secret'] = $this->_secret;
  66. $Params = '&vhost=' . urlencode( $vhost ) . '&app=' . urlencode( $appname ) . '&stream=' . $strim_id . '&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. $RK = substr( $AN->data->key, strlen( ZL_DEFAULT_VHOST . '/' ));
  79. return $RK;
  80. };
  81. return '';
  82. }
  83. public function delStreamProxy( $key ){
  84. $pack['secret'] = $this->_secret;
  85. $Params = '&key=' . urlencode( ZL_DEFAULT_VHOST . '/' . $key );
  86. $ch = curl_init();
  87. curl_setopt( $ch, CURLOPT_URL, $this->composeURL( DEL_STREAM_PROXY_IDX ) . $Params );
  88. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  89. curl_setopt( $ch, CURLOPT_HEADER, 0);
  90. curl_setopt( $ch, CURLOPT_POST, 1);
  91. curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) );
  92. $output = curl_exec( $ch );
  93. curl_close( $ch );
  94. $AN = json_decode( $output );
  95. print_r( $AN );
  96. if( $AN->code == 0 ){
  97. return $AN->data->flag;
  98. };
  99. return false;
  100. }
  101. public function listMedia(){
  102. $pack['secret'] = $this->_secret;
  103. $ch = curl_init();
  104. curl_setopt( $ch, CURLOPT_URL, $this->composeURL( LIST_MEDIA_IDX ) );
  105. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  106. curl_setopt( $ch, CURLOPT_HEADER, 0);
  107. curl_setopt( $ch, CURLOPT_POST, 1);
  108. curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) );
  109. $output = curl_exec( $ch );
  110. curl_close( $ch );
  111. echo "Returned Transfer: " . $output ."\n\n";
  112. }
  113. }
  114. ?>