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.
116 lines
4.6 KiB
116 lines
4.6 KiB
<?php
|
|
|
|
define ("ADD_ENCODER_SOURCE_IDX", 0);
|
|
define ("ADD_STREAM_PROXY_IDX", 1);
|
|
define ("CLOSE_STREAM_IDX", 2);
|
|
define ("DEL_ENCODER_SOURCE_IDX", 3);
|
|
define ("DEL_STREAM_PROXY_IDX", 4);
|
|
define ("LIST_SESSIONS_IDX", 5);
|
|
define ("LIST_API_IDX", 6);
|
|
define ("LIST_MEDIA_IDX", 7);
|
|
define ("GET_SERVER_CONFIG_IDX", 8);
|
|
define ("GET_LOAD_STATS_IDX", 9);
|
|
define ("GET_WORK_LOAD_STATS_IDX", 10);
|
|
define ("KICK_SESSION_IDX", 11);
|
|
define ("RESTART_SERVER_IDX", 12);
|
|
define ("SET_SERVER_CONFIG_IDX", 13);
|
|
define ("FETCH_STREAM_TCP", 0);
|
|
define ("FETCH_STREAM_UDP", 1);
|
|
define ("FETCH_STREAM_MULTICAST", 2);
|
|
define ("ZL_DEFAULT_VHOST", '__defaultVhost__');
|
|
|
|
class zlMediaServer{
|
|
var $_secret = '';
|
|
var $_addressREST = '';
|
|
var $_addressPort = 8081;
|
|
var $_accessURL = array();
|
|
function __construct($Secret){
|
|
$this->_secret = $Secret;
|
|
$this->_addressREST = '127.0.0.1';
|
|
$this->_accessURL[] = "/index/api/addFFmpegSource";
|
|
$this->_accessURL[] = "/index/api/addStreamProxy";
|
|
$this->_accessURL[] = "/index/api/close_stream";
|
|
$this->_accessURL[] = "/index/api/delFFmepgSource";
|
|
$this->_accessURL[] = "/index/api/delStreamProxy";
|
|
$this->_accessURL[] = "/index/api/getAllSession";
|
|
$this->_accessURL[] = "/index/api/getApiList";
|
|
$this->_accessURL[] = "/index/api/getMediaList";
|
|
$this->_accessURL[] = "/index/api/getServerConfig";
|
|
$this->_accessURL[] = "/index/api/getThreadsLoad";
|
|
$this->_accessURL[] = "/index/api/getWorkThreadsLoad";
|
|
$this->_accessURL[] = "/index/api/kick_session";
|
|
$this->_accessURL[] = "/index/api/restartServer";
|
|
$this->_accessURL[] = "/index/api/setServerConfig";
|
|
}
|
|
function __destruct(){
|
|
}
|
|
public function setAccessPointREST( $address ){
|
|
$this->_addressREST = $address;
|
|
}
|
|
private function composeURL( $idx ){
|
|
return "http://" . $this->_addressREST . ':' . $this->_addressPort . $this->_accessURL[$idx] . '?secret=' . $this->_secret;
|
|
}
|
|
public function getServerConfig(){
|
|
$pack['secret'] = $this->_secret;
|
|
$ch = curl_init();
|
|
curl_setopt( $ch, CURLOPT_URL, $this->composeURL( GET_SERVER_CONFIG_IDX ) );
|
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
|
curl_setopt( $ch, CURLOPT_HEADER, 0);
|
|
curl_setopt( $ch, CURLOPT_POST, 1);
|
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) );
|
|
$output = curl_exec( $ch );
|
|
curl_close( $ch );
|
|
$AN = json_decode( $output );
|
|
echo "Returned Transfer: " . $output ."\n\n";
|
|
}
|
|
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 ){
|
|
$pack['secret'] = $this->_secret;
|
|
$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;
|
|
$ch = curl_init();
|
|
curl_setopt( $ch, CURLOPT_URL, $this->composeURL( ADD_STREAM_PROXY_IDX ) . $Params );
|
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
|
curl_setopt( $ch, CURLOPT_HEADER, 0);
|
|
curl_setopt( $ch, CURLOPT_POST, 1);
|
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) );
|
|
$output = curl_exec( $ch );
|
|
curl_close( $ch );
|
|
$AN = json_decode( $output );
|
|
print_r( $AN );
|
|
if( $AN->code == 0 ) {
|
|
$RK = substr( $AN->data->key, strlen( ZL_DEFAULT_VHOST . '/' ));
|
|
return $RK;
|
|
};
|
|
return '';
|
|
}
|
|
public function delStreamProxy( $key ){
|
|
$pack['secret'] = $this->_secret;
|
|
$Params = '&key=' . urlencode( ZL_DEFAULT_VHOST . '/' . $key );
|
|
$ch = curl_init();
|
|
curl_setopt( $ch, CURLOPT_URL, $this->composeURL( DEL_STREAM_PROXY_IDX ) . $Params );
|
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
|
curl_setopt( $ch, CURLOPT_HEADER, 0);
|
|
curl_setopt( $ch, CURLOPT_POST, 1);
|
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) );
|
|
$output = curl_exec( $ch );
|
|
curl_close( $ch );
|
|
$AN = json_decode( $output );
|
|
print_r( $AN );
|
|
if( $AN->code == 0 ){
|
|
return $AN->data->flag;
|
|
};
|
|
return false;
|
|
}
|
|
public function listMedia(){
|
|
$pack['secret'] = $this->_secret;
|
|
$ch = curl_init();
|
|
curl_setopt( $ch, CURLOPT_URL, $this->composeURL( LIST_MEDIA_IDX ) );
|
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
|
curl_setopt( $ch, CURLOPT_HEADER, 0);
|
|
curl_setopt( $ch, CURLOPT_POST, 1);
|
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) );
|
|
$output = curl_exec( $ch );
|
|
curl_close( $ch );
|
|
echo "Returned Transfer: " . $output ."\n\n";
|
|
}
|
|
}
|
|
?>
|