示例#1
0
文件: tvie.php 项目: h3len/Project
 private function get_tvie_channel_byid($channel_id)
 {
     if (!$this->settings['tvie']['open']) {
         return;
     }
     include CUR_CONF_PATH . 'lib/tvie_api.php';
     $tvie_api = new TVie_api($this->settings['tvie']['up_stream_server']);
     $ret = $tvie_api->get_channel_by_id($channel_id);
     $stream = array();
     $this->setXmlNode('stream', 'info');
     if (is_array($ret['channel'])) {
         foreach ($ret['channel'] as $key => $value) {
             $this->addItem($value);
         }
     }
     $this->output();
 }
示例#2
0
 /**
  * 创建频道 (当tvie为open时开始创建,创建顺序:延时层-->切播层-->输出层-->本地)
  * @name create
  * @access public
  * @author lijiaying
  * @category hogesoft
  * @copyright hogesoft
  * @param $name string 频道名称
  * @param $code string 台号
  * @param $code_2 string 台号(修改用)
  * @param $logo string 台标
  * @param $stream_id int 信号ID
  * @param $delay_id int 延时层ID
  * @param $chg_id int 切播层ID
  * @param $ch_id int 输出层ID
  * @param $save_time int 回看时间(小时)
  * @param $live_delay int 延时时间 (分钟)
  * @param $is_live tinyint 是否播控 (1-是 0-否)
  * @param $stream_name string 流名称	not null
  * @param $main_stream_name string 主信号名称
  * @param $beibo string 备播信号  (暂最多支持2个)
  * @param $uri_in_num tinyint 输入流数目
  * @param $uri_out_num tinyint 输出流数目
  * @param $level tinyint 频道层数
  * @param $open_ts tinyint 是否支持手机流 (1-是 0-否)
  * @param $record_time int 自动收录节目时间偏差设置 (±30秒 大于30秒就等于30秒,小于-30秒就等于-30秒)
  * @param $audio_only tinyint 记录是否是音频 (1-是 0-否 )
  * @param $create_time int 创建时间
  * @param $update_time int 更新时间
  * @param $ip string 创建者ip
  * @param $channel_id int 频道ID
  * @param $delay_stream_id int 延时层流ID
  * @param $chg_stream_id int 切播层流ID
  * @param $out_stream_id int 输出层流ID
  * @param $stream_name string 流名称
  * @param $out_stream_name string 输出流名称
  * @param $is_main tinyint 是否主流 (1-是 0-否)
  * @param $bitrate int 码流
  * @param $flag_stream 标识(单流改为多流)
  * @param $drm tyinint 防盗链设置 (1-启用  0-关闭)	
  * @param $logo_info array logo素材信息
  * @return $ret['id'] int 频道ID
  * @include tvie_api.php
  */
 public function create()
 {
     $name = urldecode($this->input['name']);
     if (!$name) {
         $this->errorOutput('频道名称不能为空!');
     }
     $code = urldecode($this->input['code']);
     if (!$code) {
         $this->errorOutput('台号不能为空!');
     }
     $stream_id = $this->input['stream_id'] ? intval($this->input['stream_id']) : 0;
     $save_time = $this->input['save_time'] ? intval($this->input['save_time']) : 0;
     //回看时间
     $live_delay = $this->input['live_delay'] ? intval($this->input['live_delay']) : 0;
     //延时时间
     $is_live = intval($this->input['is_live']);
     //是否播控    1表示有播控  0表示无播控
     $drm = intval($this->input['drm']);
     //防盗链设置
     $stream_name = $this->input['stream_name'];
     if (!$stream_name) {
         $this->errorOutput('至少为频道选择一条流');
     }
     $main_stream_name = $this->input['main_stream_name'];
     if ($this->input['beibo']) {
         if ($is_live && count($this->input['beibo']) > 2) {
             $this->errorOutput('最多两个备播信号,请重新选择!');
         }
         foreach ($this->input['beibo'] as $value) {
             $beibo_key_value = explode('#', urldecode($value));
             $beibo[$beibo_key_value[0]] = $beibo_key_value[1];
         }
         $beibo = serialize($beibo);
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "stream WHERE id=" . $stream_id;
     $streams = $this->db->query_first($sql);
     if (!$streams) {
         $this->errorOutput('所选信号不存在,请重新选择');
     }
     $other_info = unserialize($streams['other_info']);
     if (!$other_info) {
         $this->errorOutput('所选信号没有信号流');
     }
     $stream_name_arr = array();
     foreach ($other_info as $v) {
         $stream_name_arr[$v['name']] = $v;
     }
     $stream_info = array();
     foreach ($stream_name as $n) {
         if ($stream_name_arr[$n]) {
             $stream_info[] = $stream_name_arr[$n];
         }
     }
     if (!$stream_info) {
         $this->errorOutput('所选流不存在或已被删除');
     }
     //输入流的数目
     $uri_in_num = count($stream_name);
     //层数目
     if ($uri_in_num > 1) {
         $level = 1;
     } else {
         if (!$is_live) {
             $level = 1;
         } elseif (!$live_delay) {
             $level = 2;
         } else {
             $level = 3;
         }
     }
     //选择流与选择信号流的差集
     $diff_stream_name = array_diff($stream_name_arr, $stream_name);
     //开启tvie
     if ($this->settings['tvie']['open']) {
         include CUR_CONF_PATH . 'lib/tvie_api.php';
         $delay_tvie = new TVie_api($this->settings['tvie']['up_stream_server']);
         $delay_type = 'normal_virtual';
         $chg_tvie = $delay_tvie;
         $out_tvie = new TVie_api($this->settings['tvie']['stream_server']);
         $first_stream = $stream_info[0];
         //获取主信号流
         unset($stream_info[0]);
         $delay_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $first_stream['name']), 'channels', 'tvie://');
         if (is_array($first_stream['backstore'])) {
             $backstore = implode(',', $first_stream['backstore']);
         } else {
             $backstore = $first_stream['backstore'];
         }
         //32创建延时层
         $delay_channel = $delay_tvie->create_channel('delay_' . $code, $name, $streams['server_id'], 1, $live_delay, $delay_type, $first_stream['name'], $first_stream['recover_cache'], $first_stream['source_name'], $delay_stream_uri, $first_stream['bitrate'], $first_stream['drm'], $first_stream['wait_relay'], $backstore);
         $delay_channel_id = $delay_channel['channel_id'];
         if (!$delay_channel_id) {
             $this->errorOutput('频道创建失败,原因:' . serialize($delay_channel) . $delay_channel['message'] . $delay_channel['errors']);
         }
         $ret_delay_channel_info = $delay_tvie->get_channel_by_id($delay_channel_id);
         $ret_delay_stream_info = $ret_delay_channel_info['channel']['streams'];
         $first_delay_stream_id = $ret_delay_stream_info[0]['id'];
         //延时层创建流
         $stream_ids = array('delay_stream_id' => array($first_stream['name'] => $first_delay_stream_id));
         if ($stream_info) {
             foreach ($stream_info as $key => $value) {
                 $delay_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name']), 'channels', 'tvie://');
                 if (is_array($value['backstore'])) {
                     $backstore = implode(',', $value['backstore']);
                 } else {
                     $backstore = $value['backstore'];
                 }
                 $ret_delay_stream = $delay_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $delay_uri, $value['drm'], $backstore, $value['wait_relay'], 0, $value['bitrate'], $delay_channel_id);
                 if ($ret_delay_stream['stream_id']) {
                     $stream_ids['delay_stream_id'][$value['name']] = $ret_delay_stream['stream_id'];
                 }
             }
         }
         //创建切播层
         $chg_type = 'normal_virtual';
         if (!$live_delay) {
             //没有延时,上游流地址直接是信号流地址
             $chg_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $first_stream['name']));
         } else {
             //有延时,上游流地址延迟层流地址
             $chg_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'delay_' . $code, 'stream_name' => $first_stream['name']));
         }
         if (is_array($first_stream['backstore'])) {
             $backstore = implode(',', $first_stream['backstore']);
         } else {
             $backstore = $first_stream['backstore'];
         }
         //32创建切播层
         $chg_channel = $chg_tvie->create_channel('chg_' . $code, $name, $streams['server_id'], 0, 0, $chg_type, $first_stream['name'], $first_stream['recover_cache'], $first_stream['source_name'], $chg_stream_uri, $first_stream['bitrate'], $first_stream['drm'], $first_stream['wait_relay'], $backstore);
         $chg_channel_id = $chg_channel['channel_id'];
         if (!$chg_channel_id) {
             $delay_tvie->delete_channel($delay_channel_id);
             $this->errorOutput('频道创建失败,原因:' . $chg_channel['message'] . $chg_channel['errors']);
         }
         $ret_chg_channel_info = $chg_tvie->get_channel_by_id($chg_channel_id);
         $ret_chg_stream_info = $ret_chg_channel_info['channel']['streams'];
         $first_chg_stream_id = $ret_chg_stream_info[0]['id'];
         $stream_ids['chg_stream_id'][$first_stream['name']] = $first_chg_stream_id;
         //创建切播层流
         $chg_url = array();
         foreach ($stream_info as $key => $value) {
             if (!$live_delay) {
                 //没有延时,上游流地址直接是信号流地址
                 $chg_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name']), 'channels', 'tvie://');
                 $chg_uri_http = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name']));
             } else {
                 //有延迟,上游流地址是延迟层流地址
                 $chg_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'delay_' . $code, 'stream_name' => $value['name']), 'channels', 'tvie://');
                 $chg_uri_http = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'delay_' . $code, 'stream_name' => $value['name']));
             }
             $chg_url['tvie'][] = $chg_uri;
             $chg_url['http'][] = $chg_uri_http;
             if (is_array($value['backstore'])) {
                 $backstore = implode(',', $value['backstore']);
             } else {
                 $backstore = $value['backstore'];
             }
             $ret_chg_stream = $chg_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $chg_uri_http, $value['drm'], $backstore, $value['wait_relay'], 0, $value['bitrate'], $chg_channel_id);
             if ($ret_chg_stream['stream_id']) {
                 $stream_ids['chg_stream_id'][$value['name']] = $ret_chg_stream['stream_id'];
             }
         }
         //32延时层或者切播层创建成功后,再向21创建输出层
         $out_type = 'normal_virtual';
         if (!$is_live) {
             //无切播层,直接信号流地址
             $out_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $first_stream['name']), 'channels', 'tvie://');
         } else {
             //有切播层,切播层流地址
             $out_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'chg_' . $code, 'stream_name' => $first_stream['name']), 'channels', 'tvie://');
         }
         if ($this->input['open_ts']) {
             $first_stream['backstore'] = array(0 => 'flv', 1 => 'ts');
         }
         if (is_array($first_stream['backstore'])) {
             $backstore = implode(',', $first_stream['backstore']);
         } else {
             $backstore = $first_stream['backstore'];
         }
         $out_live_delay = $live_delay;
         if ($level != 1) {
             $out_live_delay = 0;
         } else {
             if (!$save_time) {
                 $save_time = 1;
             }
         }
         //创建频道
         $out_channel = $out_tvie->create_channel($code, $name, $streams['server_id'], $save_time, $out_live_delay, $out_type, $first_stream['name'], $first_stream['recover_cache'], $first_stream['source_name'], $out_stream_uri, $first_stream['bitrate'], $drm, $first_stream['wait_relay'], $backstore);
         $out_channel_id = $out_channel['channel_id'];
         //返回频道id
         if (!$out_channel_id) {
             //删除切播层、延时层
             $delay_tvie->delete_channel($delay_channel_id);
             $chg_tvie->delete_channel($chg_channel_id);
             $this->errorOutput('频道创建失败,原因:' . $out_channel['message'] . $out_channel['errors']);
         }
         $ret_out_channel_info = $out_tvie->get_channel_by_id($out_channel_id);
         $ret_out_stream_info = $ret_out_channel_info['channel']['streams'];
         $first_out_stream_id = $ret_out_stream_info[0]['id'];
         $stream_ids['out_stream_id'][$first_stream['name']] = $first_out_stream_id;
         //创建输出层流
         foreach ($stream_info as $key => $value) {
             if (!$is_live) {
                 //无切播层,直接信号流地址
                 $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name']), 'channels', 'tvie://');
             } else {
                 //有切播层,切播层流地址
                 $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'chg_' . $code, 'stream_name' => $value['name']), 'channels', 'tvie://');
             }
             if ($this->input['open_ts']) {
                 $value['backstore'] = array(0 => 'flv', 1 => 'ts');
             }
             if (is_array($value['backstore'])) {
                 $backstore = implode(',', $value['backstore']);
             } else {
                 $backstore = $value['backstore'];
             }
             $ret_out_stream = $out_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $out_uri, $drm, $backstore, $value['wait_relay'], 0, $value['bitrate'], $out_channel_id);
             if ($ret_out_stream['stream_id']) {
                 $stream_ids['out_stream_id'][$value['name']] = $ret_out_stream['stream_id'];
             }
         }
     }
     //录制节目时间偏差设置
     if ($this->input['record_time'] >= 0) {
         if ($this->input['record_time'] > 30) {
             $record_time = 30;
         } else {
             $record_time = $this->input['record_time'];
         }
     } else {
         if ($this->input['record_time'] < -30) {
             $record_time = -30;
         } else {
             $record_time = $this->input['record_time'];
         }
     }
     $info = array('user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'code' => $code, 'code_2' => $code, 'name' => $name, 'delay_id' => $delay_channel_id, 'chg_id' => $chg_channel_id, 'ch_id' => $out_channel_id, 'is_live' => $is_live, 'drm' => $drm, 'open_ts' => $this->input['open_ts'], 'uri_in_num' => $uri_in_num, 'uri_out_num' => $uri_out_num, 'save_time' => $save_time ? $save_time : 0, 'live_delay' => $live_delay ? $live_delay : 0, 'stream_display_name' => $streams['s_name'], 'stream_mark' => $streams['ch_name'], 'level' => $level, 'beibo' => $beibo, 'stream_id' => $stream_id, 'main_stream_name' => $main_stream_name[0], 'stream_info_all' => serialize($stream_name), 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip(), 'record_time' => $record_time, 'audio_only' => $first_stream['audio_only']);
     $createsql = "INSERT INTO " . DB_PREFIX . "channel SET ";
     $space = "";
     foreach ($info as $key => $value) {
         $createsql .= $space . $key . "=" . "'" . $value . "'";
         $space = ",";
     }
     $ret = array();
     $this->db->query($createsql);
     $ret['id'] = $this->db->insert_id();
     //插入排序id
     //插入工作量统计
     $statistic = new statistic();
     $statistics_data = array('content_id' => $ret['id'], 'contentfather_id' => '', 'type' => 'insert', 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'app_uniqueid' => APP_UNIQUEID, 'module_uniqueid' => MODULE_UNIQUEID, 'before_data' => '', 'last_data' => $name, 'num' => 1);
     $statistic->insert_record($statistics_data);
     if ($_FILES['files']['tmp_name']) {
         include_once ROOT_PATH . 'lib/class/material.class.php';
         $this->mMaterial = new material();
         $file['Filedata'] = $_FILES['files'];
         $material = $this->mMaterial->addMaterial($file, $ret['id'], intval($this->input['mmid']), 'img4');
         $logo_info['id'] = $material['id'];
         $logo_info['type'] = $material['type'];
         $logo_info['server_mark'] = $material['server_mark'];
         $logo_info['filepath'] = $material['filepath'];
         $logo_info['name'] = $material['name'];
         $logo_info['filename'] = $material['filename'];
         $logo_info['url'] = $material['url'];
     }
     $sql = "UPDATE " . DB_PREFIX . "channel SET order_id = " . $ret['id'] . ", logo_info = '" . serialize($logo_info) . "' WHERE id=" . $ret['id'];
     $this->db->query($sql);
     //流信息
     $stream_info[] = $first_stream;
     $i = 0;
     $stream_num = count($stream_info) - 1;
     foreach ($stream_info as $k => $v) {
         $main_stream_info = array('channel_id' => $ret['id'], 'stream_id' => $stream_id, 'delay_stream_id' => $stream_ids['delay_stream_id'][$v['name']], 'chg_stream_id' => $stream_ids['chg_stream_id'][$v['name']], 'out_stream_id' => $stream_ids['out_stream_id'][$v['name']], 'stream_name' => $v['name'], 'out_stream_name' => $v['name'], 'is_main' => $main_stream_name[0] == $v['name'] ? 1 : 0, 'bitrate' => $v['bitrate'], 'flag_stream' => '', 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip());
         $cresql = "INSERT INTO " . DB_PREFIX . "channel_stream SET ";
         $space = "";
         foreach ($main_stream_info as $key => $value) {
             $cresql .= $space . $key . "=" . "'" . $value . "'";
             $space = ",";
         }
         $this->db->query($cresql);
         $i++;
     }
     $this->setXmlNode('channel', 'info');
     $this->addItem($ret['id']);
     $this->output();
 }
示例#3
0
 /**
  * 信号流状态 (1-启动 0-停止)
  * @name stream_status
  * @access public
  * @author lijiaying
  * @category hogesoft
  * @copyright hogesoft
  * @param $id int 频道ID
  * @return $tip array (stream_status:1-->启动, 2-->停止, 0-->操作失败)
  * @include tvie_api.php
  */
 public function stream_status()
 {
     $id = intval($this->input['id']);
     if (!$id) {
         $this->errorOutput('未传入频道信号ID');
     }
     $sql = "SELECT ch_id,s_status FROM " . DB_PREFIX . "stream WHERE id=" . $id;
     $ret = $this->db->query_first($sql);
     $ch_id = $ret['ch_id'];
     $status = $ret['s_status'];
     if ($this->settings['tvie']['open']) {
         include CUR_CONF_PATH . 'lib/tvie_api.php';
         $tvie_api = new TVie_api($this->settings['tvie']['up_stream_server']);
         $channel_info = $tvie_api->get_channel_by_id($ch_id);
         //查询的频道信息
         $stream_info = $channel_info['channel']['streams'];
     }
     $new_status = "";
     if (!$status) {
         $sql = "UPDATE " . DB_PREFIX . "stream SET s_status = 1 WHERE id=" . $id;
         if ($stream_info) {
             foreach ($stream_info as $key => $value) {
                 $ret_stream = $tvie_api->start_stream($value['id']);
             }
             if ($ret_stream['message'] == 'Handled') {
                 $new_status = 1;
             } else {
                 $new_status = 0;
             }
         }
     } else {
         $sql = "UPDATE " . DB_PREFIX . "stream SET s_status = 0 WHERE id=" . $id;
         if ($stream_info) {
             foreach ($stream_info as $key => $value) {
                 $ret_stream = $tvie_api->stop_stream($value['id']);
             }
             if ($ret_stream['message'] == 'Handled') {
                 $new_status = 2;
             } else {
                 $new_status = 0;
             }
         }
     }
     if ($this->db->query($sql)) {
         $tip = array('stream_status' => $new_status);
         $this->addItem($tip);
         $this->output();
     } else {
         $this->errorOutput();
     }
 }
示例#4
0
 /**
  * 信号流状态 (1-启动 0-停止)
  * @name stream_state
  * @access public
  * @author lijiaying
  * @category hogesoft
  * @copyright hogesoft
  * @param $id int 频道ID
  * @return $tip array (status:1-->启动, 2-->停止, 0-->操作失败)
  * @include tvie_api.php
  */
 public function stream_state()
 {
     $id = intval($this->input['id']);
     if (!$id) {
         $this->errorOutput('该频道不存在或已被删除');
     } else {
         $updsql = "UPDATE " . DB_PREFIX . "channel SET chg2_stream_id=" . 0 . " WHERE id=" . $id;
         $this->db->query($updsql);
     }
     $sql = "SELECT delay_id,chg_id,ch_id,stream_state,level,uri_in_num FROM " . DB_PREFIX . "channel WHERE id=" . $id;
     $ret = $this->db->query_first($sql);
     $delay_id = $ret['delay_id'];
     $chg_id = $ret['chg_id'];
     $out_id = $ret['ch_id'];
     $stream_state = $ret['stream_state'];
     $level = $ret['level'];
     $uri_in_num = $ret['uri_in_num'];
     if ($this->settings['tvie']['open']) {
         include CUR_CONF_PATH . 'lib/tvie_api.php';
         //延时层
         $delay_tvie = new TVie_api($this->settings['tvie']['up_stream_server']);
         $delay_channel_info = $delay_tvie->get_channel_by_id($delay_id);
         $delay_stream_info = $delay_channel_info['channel']['streams'];
         //切播层
         $chg_tvie = $delay_tvie;
         $chg_channel_info = $chg_tvie->get_channel_by_id($chg_id);
         $chg_stream_info = $chg_channel_info['channel']['streams'];
         //输出层
         $out_tvie = new TVie_api($this->settings['tvie']['stream_server']);
         $out_channel_info = $out_tvie->get_channel_by_id($out_id);
         $out_stream_info = $out_channel_info['channel']['streams'];
     }
     $new_stream_state = "";
     if (!$stream_state) {
         $sql = "UPDATE " . DB_PREFIX . "channel SET stream_state = 1 WHERE id=" . $id;
         if ($level == 2 && $chg_stream_info) {
             foreach ($chg_stream_info as $value) {
                 $ret_chg = $chg_tvie->start_stream($value['id']);
             }
         }
         if ($level == 3 && $delay_stream_info && $chg_stream_info) {
             foreach ($delay_stream_info as $value) {
                 $ret_delay = $delay_tvie->start_stream($value['id']);
             }
             foreach ($chg_stream_info as $value) {
                 $ret_chg = $chg_tvie->start_stream($value['id']);
             }
         }
         if ($out_stream_info) {
             foreach ($out_stream_info as $value) {
                 $ret_out = $out_tvie->start_stream($value['id']);
             }
         }
         if ($ret_delay['message'] == 'Handled' || $ret_chg['message'] == 'Handled' || $ret_out['message'] == 'Handled') {
             $new_stream_state = 1;
         } else {
             $new_stream_state = 0;
         }
     } else {
         $sql = "UPDATE " . DB_PREFIX . "channel SET stream_state = 0 WHERE id=" . $id;
         if ($level == 2 && $chg_stream_info) {
             foreach ($chg_stream_info as $value) {
                 $ret_chg = $chg_tvie->stop_stream($value['id']);
             }
         }
         if ($level == 3 && $delay_stream_info && $chg_stream_info) {
             foreach ($delay_stream_info as $value) {
                 $ret_delay = $delay_tvie->stop_stream($value['id']);
             }
             foreach ($chg_stream_info as $value) {
                 $ret_chg = $chg_tvie->stop_stream($value['id']);
             }
         }
         if ($out_stream_info) {
             foreach ($out_stream_info as $value) {
                 $ret_out = $out_tvie->stop_stream($value['id']);
             }
         }
         if ($ret_delay['message'] == 'Handled' || $ret_chg['message'] == 'Handled' || $ret_out['message'] == 'Handled') {
             $new_stream_state = 2;
         } else {
             $new_stream_state = 0;
         }
     }
     if ($this->db->query($sql)) {
         $tip = array('status' => $new_stream_state);
         $this->addItem($tip);
         $this->output();
     } else {
         $this->errorOutput();
     }
 }
示例#5
0
 /**
  * 
  * Enter description here ...
  */
 function up_stream_create()
 {
     //开启
     $gGlobalConfig['tvie'] = array('open' => '1', 'up_stream_server' => array('client' => 'hoolo', 'outhost' => 'live1.hoolo.tv', 'api_server_name' => '192.168.33.44', 'read_token' => '8k30f1p6u9yf9vou1lqc', 'write_token' => 'ld2b5thbvanukhkq80md', 'liveport' => '11105'), 'stream_server' => array('client' => 'hoolo', 'outhost' => 'live2.hoolo.tv', 'api_server_name' => '192.168.33.14', 'read_token' => '123456789', 'write_token' => '987654321', 'liveport' => '11105', 'append_host' => 'live3.hoolo.tv,live4.hoolo.tv'));
     if ($this->settings['tvie']['open']) {
         include CUR_CONF_PATH . 'lib/tvie_api.php';
         $up_tvie = new TVie_api($gGlobalConfig['tvie']['up_stream_server']);
         $up_channels = $up_tvie->get_all_channels();
         print_r($gGlobalConfig['tvie']['up_stream_server']);
         print_r($up_channels);
         //上游频道信息
         $up_channels = $up_channels['channels'];
         $up_ch_ids = array();
         if ($up_channels) {
             foreach ($up_channels as $key => $value) {
                 if ($value['type'] == 'live') {
                     $up_ch_ids[] = $value['id'];
                 }
             }
         }
         //本地频道id
         $sql = "select ch_id from " . DB_PREFIX . "stream ";
         $q = $this->db->query($sql);
         $ch_ids = array();
         while ($row = $this->db->fetch_array($q)) {
             $ch_ids[] = $row['ch_id'];
         }
         $offset_ch_id = array_diff($up_ch_ids, $ch_ids);
         //	上游频道id与本地频道id差集
         if (!$offset_ch_id) {
             $this->addItem('error');
         }
         if (is_array($offset_ch_id) && $offset_ch_id) {
             foreach ($offset_ch_id as $ch_id) {
                 $up_channel_info = $up_tvie->get_channel_by_id($ch_id);
                 $up_channel_info = $up_channel_info['channel'];
                 $streams = $up_channel_info['streams'];
                 $server_id = $up_channel_info['server_id'];
                 $type = $up_channel_info['type'];
                 if ($streams && is_array($streams)) {
                     $uri_arr = array();
                     $other_info = array();
                     foreach ($streams as $key => $value) {
                         $uri_arr[] = $value['uri'];
                         $other_info[] = array('id' => $value['id'], 'name' => $value['name'], 'uri' => $value['uri'], 'recover_cache' => $value['recover_cache'], 'source_name' => $value['source_name'], 'drm' => $value['drm'], 'backstore' => 'flv', 'wait_relay' => $value['wait_relay'], 'audio_only' => $value['audio_only'], 'bitrate' => $value['bitrate']);
                     }
                 }
                 $info = array('ch_id' => $ch_id, 's_name' => $up_channel_info['display_name'], 'ch_name' => $up_channel_info['channel_name'], 'uri' => serialize($uri_arr), 'type' => $type, 'other_info' => serialize($other_info), 'server_id' => $this->input['server_id'] ? $this->input['server_id'] : $server_id, 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip());
                 if ($info) {
                     $sql = "INSERT INTO " . DB_PREFIX . "stream SET ";
                     $space = "";
                     foreach ($info as $key => $value) {
                         $sql .= $space . $key . "=" . "'" . $value . "'";
                         $space = ",";
                     }
                     $this->db->query($sql);
                 }
                 $info['id'] = $this->db->insert_id();
                 $this->setXmlNode('stream', 'info');
                 $this->addItem($info);
             }
         }
         $this->output();
     }
 }
示例#6
0
 /**
  * 创建频道信号
  * @name create
  * @access public
  * @author lijiaying
  * @category hogesoft
  * @copyright hogesoft
  * @param $ch_name string 信号名称
  * @param $s_name string 信号标识
  * @param $save_time int 回看时间 (小时)
  * @param $live_delay int 延时时间 (分钟)
  * @param $uri string 信号流地址
  * @param $name string 流名称
  * @param $bitrate int 码流
  * @param $backstore array 支持格式(flv,ts)
  * @param $audio_only tinyint 是否音频 (1-是 0-否)
  * @param $wait_relay tinyint 是否推送 (1-是 0-否)
  * @param $other_info string 流信息
  * @param $server_id int 服务器ID
  * @param $create_time int 创建时间
  * @param $update_time int 更新时间
  * @param $ip string 创建者IP
  * @return $info['id'] int 频道信号ID
  * @include tvie_api.php
  */
 function create()
 {
     $ch_name = urldecode($this->input['ch_name']);
     //信号名称
     if (!ch_name) {
         $this->errorOutput('信号名称的不能为空,请重新填写!');
     }
     $s_name = urldecode($this->input['s_name']);
     //信号标识
     if (!$s_name) {
         $this->errorOutput('信号标识的不能为空,请重新填写!');
     }
     $save_time = intval($this->input['save_time']);
     //回看(小时)
     $live_delay = intval($this->input['live_delay']);
     //延时(分钟)
     $type = 'live';
     $recover_cache = 1;
     $source_name = 'tvie-live-encoder';
     $streams_info = $uri_arr = array();
     if (is_array($this->input['counts']) && $this->input['counts']) {
         for ($i = 0; $i < count($this->input['counts']); $i++) {
             $streams_info[$i]['name'] = urldecode($this->input['name_' . $i]);
             $streams_info[$i]['uri'] = urldecode($this->input['uri_' . $i]);
             if (!$streams_info[$i]['name']) {
                 $this->errorOutput('输出标识不能为空');
             }
             if (!$streams_info[$i]['uri']) {
                 $this->errorOutput('来源地址不能为空');
             }
             $streams_info[$i]['bitrate'] = $this->input['bitrate_' . $i];
             $streams_info[$i]['backstore'][] = $this->input['flv_' . $i];
             $streams_info[$i]['backstore'][] = $this->input['ts_' . $i];
             $streams_info[$i]['audio_only'] = $this->input['audio_only'] ? $this->input['audio_only'] : 0;
             $streams_info[$i]['wait_relay'] = $this->input['wait_relay'] ? $this->input['wait_relay'] : 0;
             $uri_arr[] = urldecode($this->input['uri_' . $i]);
         }
     }
     //开启
     if ($this->settings['tvie']['open']) {
         include CUR_CONF_PATH . 'lib/tvie_api.php';
         $up_tvie = new TVie_api($this->settings['tvie']['up_stream_server']);
         $servers = $up_tvie->get_all_servers();
         //获取媒体服务器ID
         if (!$servers) {
             $this->errorOutput("网络延时");
         }
         if (is_array($streams_info[0]['backstore'])) {
             $backstore = implode(',', $streams_info[0]['backstore']);
         } else {
             $backstore = $streams_info[0]['backstore'];
         }
         //创建直播频道
         $ret_channel = $up_tvie->create_channel($ch_name, $s_name, $servers['items'][0]['id'], $save_time, $live_delay, $type, $streams_info[0]['name'], $recover_cache, $source_name, $streams_info[0]['uri'], urldecode($this->input['bitrate']), 0, $streams_info[0]['wait_relay'], 'flv');
         $ch_id = $ret_channel['channel_id'];
         //返回虚拟频道id
         if (!$ch_id) {
             $this->errorOutput('媒体服务器数据异常');
         }
         $ret_channel_info = $up_tvie->get_channel_by_id($ch_id);
         $ret_stream_info = $ret_channel_info['channel']['streams'];
         $first_stream_id = $ret_stream_info[0]['id'];
         if (!$first_stream_id) {
             $this->errorOutput('媒体服务器创建信号流失败');
         }
         //创建流
         foreach ($streams_info as $key => $value) {
             $ret = $up_tvie->create_channel_stream($value['name'], $recover_cache, $source_name, $value['uri'], 0, 'flv', $value['wait_relay'], $value['audio_only'], $value['bitrate'], $ch_id);
             if (!$ret['stream_id']) {
                 $this->errorOutput('媒体服务器创建信号失败');
             }
             $backstore = array(0 => 'flv');
             $other_info[$key] = array('id' => $key == 0 ? $first_stream_id : $ret['stream_id'], 'name' => $value['name'], 'ch_name' => $ch_name, 'uri' => $value['uri'], 'recover_cache' => $recover_cache, 'source_name' => $source_name, 'drm' => 0, 'backstore' => $backstore, 'wait_relay' => $value['wait_relay'], 'audio_only' => $value['audio_only'], 'bitrate' => $value['bitrate']);
         }
     } else {
         $this->errorOutput('媒体服务器未启动');
     }
     $info = array('ch_id' => $ch_id, 's_name' => $s_name, 'ch_name' => $ch_name, 'uri' => serialize($uri_arr), 'type' => $type, 'save_time' => $save_time, 'live_delay' => $live_delay, 'other_info' => serialize($other_info), 'server_id' => $this->input['server_id'] ? intval($this->input['server_id']) : $servers['items'][0]['id'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip());
     $sql = "INSERT INTO " . DB_PREFIX . "stream SET ";
     $space = "";
     foreach ($info as $key => $value) {
         $sql .= $space . $key . "=" . "'" . $value . "'";
         $space = ",";
     }
     $this->db->query($sql);
     $info['id'] = $this->db->insert_id();
     $this->setXmlNode('stream', 'info');
     $this->addItem($info['id']);
     $this->output();
 }