Пример #1
0
 /**
  * 更新信号流信息
  * @name update
  * @access public
  * @author lijiaying
  * @category hogesoft
  * @copyright hogesoft
  * @param $id int 频道信号ID
  * @param $s_name string 信号名称
  * @param $ch_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 $update_time int 更新时间
  * @param $audio_temp tinyint 临时变量
  * @param $audio_only tinyint 同步频道音频设置参数
  * @return $info['id'] int 频道信号ID
  * @include tvie_api.php
  */
 function update()
 {
     $id = $stream_id = intval($this->input['id']);
     if (!$id) {
         $this->errorOutput('未传入频道信号ID');
     }
     $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']);
     $sql = "SELECT * FROM " . DB_PREFIX . "stream WHERE id = " . $id;
     $stream = $this->db->query_first($sql);
     $stream_other_info = unserialize($stream['other_info']);
     $input_info = $stream_other_info;
     if (!empty($input_info)) {
         $input_name = $input_name_index = $input_info_index = array();
         foreach ($input_info as $k => $v) {
             $input_name[] = $v['name'];
             $input_name_index[$v['name']] = $v['name'];
             $input_info_index[$v['name']] = $v;
         }
     }
     $ch_id = $stream['ch_id'];
     $s_status = $stream['s_status'];
     if (is_array($this->input['counts']) && $this->input['counts']) {
         $streams_info = $tpl_uri = $tpl_name = $tpl_name_index = array();
         for ($i = 0; $i < count($this->input['counts']); $i++) {
             $streams_info[$i]['id'] = urldecode($this->input['id_' . $i]);
             $streams_info[$i]['name'] = urldecode($this->input['name_' . $i]);
             if (!$streams_info[$i]['name']) {
                 $this->errorOutput('输出标识不能为空');
             }
             $streams_info[$i]['ch_name'] = urldecode($this->input['ch_name_hidden']);
             $streams_info[$i]['uri'] = urldecode($this->input['uri_' . $i]);
             if (!$streams_info[$i]['uri']) {
                 $this->errorOutput('来源地址不能为空');
             }
             $streams_info[$i]['bitrate'] = $this->input['bitrate_' . $i];
             $streams_info[$i]['backstore'][] = 'flv';
             $streams_info[$i]['audio_only'] = $this->input['audio_only'] ? intval($this->input['audio_only']) : 0;
             $streams_info[$i]['wait_relay'] = $this->input['wait_relay'] ? intval($this->input['wait_relay']) : 0;
             $streams_info[$i]['recover_cache'] = 1;
             $streams_info[$i]['drm'] = 0;
             $streams_info[$i]['source_name'] = 'tvie-live-encoder';
             $tpl_uri[] = urldecode($this->input['uri_' . $i]);
             $tpl_name[] = urldecode($this->input['name_' . $i]);
             $tpl_name_index[urldecode($this->input['name_' . $i])] = urldecode($this->input['name_' . $i]);
         }
     }
     if (empty($streams_info)) {
         $this->errorOutput('数据不完整,请重新填写!');
     }
     //新增信号
     $add_diff = @array_diff($tpl_name, $input_name);
     //删除信号
     $del_diff = @array_diff($input_name, $tpl_name);
     $del_diff_index = @array_diff($input_name_index, $tpl_name_index);
     //更新信号
     $update_inter = @array_intersect($tpl_name, $input_name);
     if ($this->settings['tvie']['open']) {
         include CUR_CONF_PATH . 'lib/tvie_api.php';
         $up_tvie = new TVie_api($this->settings['tvie']['up_stream_server']);
         $ret_channel = $up_tvie->update_channel($s_name, $save_time, $live_delay, $ch_id);
         if (!$ret_channel['message'] == 'Updated') {
             $this->errorOutput('媒体服务器更新失败');
         }
         foreach ($streams_info as $k => $v) {
             if ($add_diff[$k] == $v['name']) {
                 //添加信号流
                 if (is_array($v['backstore'])) {
                     $backstore = implode(',', $v['backstore']);
                 } else {
                     $backstore = $v['backstore'];
                 }
                 $ret_stream = $up_tvie->create_channel_stream($v['name'], $v['recover_cache'], $v['source_name'], $v['uri'], $v['drm'], 'flv', $v['wait_relay'], $v['audio_only'], $v['bitrate'], $ch_id);
                 if (!$ret_stream['stream_id']) {
                     $this->errorOutput('媒体服务器添加信号流失败');
                 }
                 $other_info[$k] = array('id' => $ret_stream['stream_id'], 'name' => $v['name'], 'ch_name' => $v['ch_name'], 'uri' => $v['uri'], 'recover_cache' => $v['recover_cache'], 'source_name' => $v['source_name'], 'drm' => 0, 'backstore' => $v['backstore'], 'wait_relay' => $v['wait_relay'], 'audio_only' => $v['audio_only'], 'bitrate' => $v['bitrate']);
                 if ($ret_stream['stream_id']) {
                     if ($s_status) {
                         $up_tvie->stop_stream($ret_stream['stream_id']);
                         $up_tvie->start_stream($ret_stream['stream_id']);
                     } else {
                         $up_tvie->start_stream($ret_stream['stream_id']);
                         $up_tvie->stop_stream($ret_stream['stream_id']);
                     }
                 }
             } else {
                 //更新信号流
                 if (is_array($v['backstore'])) {
                     $backstore = implode(',', $v['backstore']);
                 } else {
                     $backstore = $v['backstore'];
                 }
                 $ret_stream = $up_tvie->update_channel_stream($v['id'], 0, 'flv', 1, $v['uri'], $v['audio_only'], $v['wait_relay'], $v['source_name']);
                 if ($ret_stream['message'] != 'Modified') {
                     $this->errorOutput('媒体服务器更新信号流失败');
                 }
                 if ($ret_stream['message'] == 'Modified') {
                     $other_info[$k] = array('id' => $v['id'], 'name' => $v['name'], 'ch_name' => $v['ch_name'], 'uri' => $v['uri'], 'recover_cache' => $v['recover_cache'], 'source_name' => $v['source_name'], 'drm' => $v['drm'], 'backstore' => $v['backstore'], 'wait_relay' => $v['wait_relay'], 'audio_only' => $v['audio_only'], 'bitrate' => $v['bitrate']);
                 } else {
                     if ($update_inter[$k] == $v['name']) {
                         $other_info[$k] = array('id' => $input_info_index[$v['name']]['id'], 'name' => $input_info_index[$v['name']]['name'], 'ch_name' => $input_info_index[$v['name']]['ch_name'], 'uri' => $input_info_index[$v['name']]['uri'], 'recover_cache' => $input_info_index[$v['name']]['recover_cache'], 'source_name' => $input_info_index[$v['name']]['source_name'], 'drm' => $input_info_index[$v['name']]['drm'], 'backstore' => $input_info_index[$v['name']]['backstore'], 'wait_relay' => $input_info_index[$v['name']]['wait_relay'], 'audio_only' => $input_info_index[$v['name']]['audio_only'], 'bitrate' => $input_info_index[$v['name']]['bitrate']);
                     }
                 }
             }
         }
         //删除输入输出流
         if (!empty($input_info)) {
             foreach ($input_info as $k => $v) {
                 if ($del_diff[$k] == $v['name']) {
                     $ret_del = $up_tvie->delete_stream($v['id']);
                     //删除流信息
                 }
             }
         }
     }
     $info = array('s_name' => $s_name, 'uri' => serialize($tpl_uri), 's_status' => $s_status, 'other_info' => serialize($other_info), 'update_time' => TIMENOW);
     $sql = "UPDATE " . DB_PREFIX . "stream SET ";
     $space = "";
     foreach ($info as $key => $value) {
         $sql .= $space . $key . "=" . "'" . $value . "'";
         $space = ",";
     }
     $sql .= " WHERE id=" . $id;
     $this->db->query($sql);
     //同步频道音频设置
     if ($this->input['audio_temp']) {
         if ($this->input['audio_only']) {
             $channelSql = "UPDATE " . DB_PREFIX . "channel SET audio_only=1 WHERE stream_id IN(" . $id . ")";
             $this->db->query($channelSql);
         } else {
             $channelSql = "UPDATE " . DB_PREFIX . "channel SET audio_only=0 WHERE stream_id IN(" . $id . ")";
             $this->db->query($channelSql);
         }
     }
     $info['id'] = $id;
     //start
     //获取频道相关信息
     $channelStreamInfo = $this->getChannelStreamInfo($stream_id);
     if (!empty($channelStreamInfo)) {
         $out_tvie = new TVie_api($this->settings['tvie']['stream_server']);
         foreach ($channelStreamInfo as $k => $channel) {
             //channel_stream
             if (!empty($channel['channel_stream'])) {
                 foreach ($channel['channel_stream'] as $kk => $vv) {
                     if ($del_diff_index[$kk] == $kk) {
                         //延时层
                         $ret_delay = $up_tvie->delete_stream($vv['delay_stream_id']);
                         //切播层
                         if ($ret_delay['message'] == 'Handled') {
                             $ret_chg = $up_tvie->delete_stream($vv['chg_stream_id']);
                         }
                         //输出层
                         if ($ret_chg['message'] == 'Handled') {
                             $ret_out = $out_tvie->delete_stream($vv['out_stream_id']);
                         }
                         //本地
                         if ($ret_out['message'] == 'Handled') {
                             $sql = "DELETE FROM " . DB_PREFIX . "channel_stream WHERE id = " . $vv['id'];
                             $this->db->query($sql);
                         }
                     }
                 }
             }
             //channel
             $channel_id[$k] = '';
             if ($channel['stream_info_all_index']) {
                 foreach ($channel['stream_info_all_index'] as $kk => $vv) {
                     if ($del_diff_index[$kk] == $kk) {
                         $channel_id[$k] = $channel['id'];
                         unset($channel['stream_info_all_index'][$kk]);
                     }
                     if ($del_diff_index[$kk] == $channel['main_stream_name']) {
                         $main_stream_name_flag = 1;
                     }
                 }
                 if (!empty($channel['stream_info_all_index'])) {
                     $stream_info_all = array();
                     foreach ($channel['stream_info_all_index'] as $v) {
                         $stream_info_all[] = $v;
                     }
                 }
                 if ($main_stream_name_flag) {
                     $main_stream_name = '';
                 } else {
                     $main_stream_name = $channel['main_stream_name'];
                 }
             }
             if ($channel_id[$k]) {
                 $sql = "UPDATE " . DB_PREFIX . "channel SET stream_info_all = '" . serialize($stream_info_all) . "', main_stream_name = '" . $main_stream_name . "' WHERE id = " . $channel_id[$k];
                 $this->db->query($sql);
             }
         }
     }
     //end
     $this->setXmlNode('stream', 'info');
     $this->addItem($info['id']);
     $this->output();
 }
Пример #2
0
 /**
  * 更新频道数据 (若改变流信息则删除后重新创建流信息)
  * @name update
  * @access public
  * @author lijiaying
  * @category hogesoft
  * @copyright hogesoft
  * @param $name string 频道名称
  * @param $logo string 台标
  * @param $stream_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 $update_time int 更新时间
  * @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
  */
 function update()
 {
     $id = intval($this->input['id']);
     if (!$id) {
         $this->errorOutput('频道id不存在或已被删除');
     }
     $name = urldecode($this->input['name']);
     if (!$name) {
         $this->errorOutput('频道名称不能为空!');
     }
     $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'];
     //输入流的数目
     $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;
         }
     }
     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 . "channel WHERE id=" . $id;
     $channel_info = $this->db->query_first($sql);
     $code = $channel_info['code_2'];
     $stream_id = $channel_info['stream_id'];
     if ($stream_id != intval($this->input['stream_id'])) {
         $stream_id = intval($this->input['stream_id']);
     }
     $delay_id = $channel_info['delay_id'];
     $chg_id = $channel_info['chg_id'];
     $out_id = $channel_info['ch_id'];
     //		$level = $channel_info['level'];
     //频道流信息
     $sql = "SELECT * FROM " . DB_PREFIX . "channel_stream WHERE channel_id IN(" . $id . ") ";
     //ORDER BY id DESC";
     $q = $this->db->query($sql);
     $channel_stream = $channel_stream_withkey = $channel_stream_name = array();
     while ($row = $this->db->fetch_array($q)) {
         $channel_stream[] = $row;
         $channel_stream_withkey[$row['stream_name']] = $row;
         $channel_stream_name[] = $row['stream_name'];
     }
     //信号信息
     $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 组成的数据
     $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];
         }
     }
     //模板和channel_stream 组成的数据
     $stream_name_arr_new = array();
     foreach ($channel_stream as $v) {
         $stream_name_arr_new[$v['stream_name']] = $v;
     }
     $stream_info_new = array();
     foreach ($stream_name as $n) {
         if ($stream_name_arr_new[$n]) {
             $stream_info_new[] = $stream_name_arr_new[$n];
         }
     }
     //模板流名称和channel_stream差集
     if ($uri_in_num < intval($channel_info['uri_in_num'])) {
         $input_channel_stream_diff = array_diff($channel_stream_name, $stream_name);
     } else {
         $input_channel_stream_diff = array_diff($stream_name, $channel_stream_name);
     }
     $diff_stream_info = array();
     foreach ($channel_stream as $v) {
         foreach ($input_channel_stream_diff as $vv) {
             if ($v['stream_name'] == $vv) {
                 $diff_stream_info[] = $v;
             }
         }
     }
     //模板、stream差集  组成的新数据
     $diff_stream_info_other = array();
     foreach ($stream_info as $v) {
         foreach ($input_channel_stream_diff as $vv) {
             if ($v['name'] == $vv) {
                 $diff_stream_info_other[] = $v;
             }
         }
     }
     //channel_stream、模板 	 差集
     $channel_stream_diff = array_diff($channel_stream_name, $stream_name);
     $del_channel_stream = array();
     foreach ($channel_stream as $v) {
         foreach ($channel_stream_diff as $vv) {
             if ($v['stream_name'] == $vv) {
                 $del_channel_stream[$v['stream_name']] = $v;
             }
         }
     }
     if (!$stream_info) {
         $this->errorOutput('所选流不存在或已被删除');
     }
     //开启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']);
         //层数为   1
         if ($level == 1) {
             //只更新输出层
             $out_ret_channel = $out_tvie->update_channel($name, $save_time, $live_delay, $out_id);
             /* 	if($out_ret_channel['message'] != 'Updated')
             		 	{
             		 		$this->errorOutput('频道更新失败,原因:' . $out_ret_channel['message'] . $out_ret_channel['errors']);
             		 	}*/
             if ($channel_info['stream_id'] != intval($this->input['stream_id'])) {
                 //改变主信号时,删除原有的信号以及流地址
                 foreach ($channel_stream as $value) {
                     $delay_ret_stream = $delay_tvie->delete_stream($value['delay_stream_id']);
                     $chg_ret_stream = $chg_tvie->delete_stream($value['chg_stream_id']);
                     $out_ret_stream = $out_tvie->delete_stream($value['out_stream_id']);
                     $sql = "DELETE FROM " . DB_PREFIX . "channel_stream WHERE out_stream_id=" . $value['out_stream_id'];
                     $this->db->query($sql);
                 }
                 //创建新的流地址
                 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://');
                     $chg_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'delay_' . $channel_info['code_2'], 'stream_name' => $value['name']));
                     $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], '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'];
                     }
                     $delay_create_stream = $delay_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $delay_uri, $value['drm'], 'flv', $value['wait_relay'], 0, $value['bitrate'], $delay_id);
                     $chg_create_stream = $chg_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $chg_uri, $value['drm'], 'flv', $value['wait_relay'], 0, $value['bitrate'], $chg_id);
                     $out_create_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_id);
                     if ($channel_info['stream_state']) {
                         $out_tvie->stop_stream($out_create_stream['stream_id']);
                         $out_tvie->start_stream($out_create_stream['stream_id']);
                     } else {
                         $out_tvie->start_stream($out_create_stream['stream_id']);
                         $out_tvie->stop_stream($out_create_stream['stream_id']);
                     }
                     /*if(!$out_create_stream['stream_id'])
                     		{
                     			$this->errorOutput('更新频道失败,原因:'.$out_create_stream['message']);
                     		}*/
                     if ($out_create_stream['stream_id']) {
                         //返回创建成功后的流信息
                         if ($main_stream_name[0] == $value['name']) {
                             $is_main = 1;
                         } else {
                             $is_main = 0;
                         }
                         $channel_stream_info = array('channel_id' => $id, 'stream_id' => $stream_id, 'delay_stream_id' => $delay_create_stream['stream_id'], 'chg_stream_id' => $chg_create_stream['stream_id'], 'out_stream_id' => $out_create_stream['stream_id'], 'stream_name' => $value['name'], 'out_stream_name' => $value['name'], 'is_main' => $is_main, 'bitrate' => $value['bitrate'], 'flag_stream' => '', 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip());
                         $cresql = "INSERT INTO " . DB_PREFIX . "channel_stream SET ";
                         $space = "";
                         foreach ($channel_stream_info as $k => $v) {
                             $cresql .= $space . $k . "=" . "'" . $v . "'";
                             $space = ",";
                         }
                         $this->db->query($cresql);
                     }
                 }
             } else {
                 if ($stream_info_new) {
                     if ($input_channel_stream_diff) {
                         //有差集   删除被剔除的流信息 (暂时只支持删除)$del_channel_stream
                         if ($diff_stream_info) {
                             foreach ($diff_stream_info as $value) {
                                 $delay_ret_stream = $delay_tvie->delete_stream($value['delay_stream_id']);
                                 $chg_ret_stream = $chg_tvie->delete_stream($value['chg_stream_id']);
                                 $out_ret_stream = $out_tvie->delete_stream($value['out_stream_id']);
                                 $sql = "DELETE FROM " . DB_PREFIX . "channel_stream WHERE out_stream_id=" . $value['out_stream_id'];
                                 $this->db->query($sql);
                             }
                         } else {
                             foreach ($del_channel_stream as $value) {
                                 $delay_ret_stream = $delay_tvie->delete_stream($value['delay_stream_id']);
                                 $chg_ret_stream = $chg_tvie->delete_stream($value['chg_stream_id']);
                                 $out_ret_stream = $out_tvie->delete_stream($value['out_stream_id']);
                                 $sql = "DELETE FROM " . DB_PREFIX . "channel_stream WHERE out_stream_id=" . $value['out_stream_id'];
                                 $this->db->query($sql);
                             }
                         }
                         //更新主信号
                         foreach ($stream_info_new as $value) {
                             if ($main_stream_name[0] == $value['stream_name']) {
                                 $is_main = 1;
                                 $sql = "UPDATE " . DB_PREFIX . "channel_stream SET is_main=" . $is_main . " WHERE channel_id=" . $id . " AND stream_name='" . $main_stream_name[0] . "'";
                                 $this->db->query($sql);
                             } else {
                                 $is_main = 0;
                                 $sql = "UPDATE " . DB_PREFIX . "channel_stream SET is_main=" . $is_main . " WHERE channel_id=" . $id . " AND stream_name='" . $value['stream_name'] . "'";
                                 $this->db->query($sql);
                             }
                         }
                     } else {
                         //无信号流改变时数据
                         $channel_stream_merge = array();
                         foreach ($stream_name_arr as $key => $value) {
                             $channel_stream_merge[$key] = array_merge($stream_name_arr[$key], $channel_stream_withkey[$key]);
                         }
                         //没有差集   更新流信息
                         foreach ($channel_stream_merge as $value) {
                             //流地址
                             $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], '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'];
                             }
                             $out_update_stream = $out_tvie->update_channel_stream($value['out_stream_id'], $drm, $backstore, $value['recover_cache'], $out_uri, 0, $value['wait_relay'], $value['source_name']);
                             if ($channel_info['stream_state']) {
                                 $out_tvie->stop_stream($value['out_stream_id']);
                                 $out_tvie->start_stream($value['out_stream_id']);
                             } else {
                                 $out_tvie->start_stream($value['out_stream_id']);
                                 $out_tvie->stop_stream($value['out_stream_id']);
                             }
                             //更新channel_stream
                             if ($main_stream_name[0] == $value['name']) {
                                 $is_main = 1;
                                 $sql = "UPDATE " . DB_PREFIX . "channel_stream SET is_main=" . $is_main . " WHERE channel_id=" . $id . " AND stream_name='" . $main_stream_name[0] . "'";
                                 $this->db->query($sql);
                             } else {
                                 $is_main = 0;
                                 $sql = "UPDATE " . DB_PREFIX . "channel_stream SET is_main=" . $is_main . " WHERE channel_id=" . $id . " AND stream_name='" . $value['name'] . "'";
                                 $this->db->query($sql);
                             }
                         }
                     }
                 } else {
                     //流名称全换的情况下,删除原有的
                     foreach ($channel_stream as $value) {
                         $delay_ret_stream = $delay_tvie->delete_stream($value['delay_stream_id']);
                         $chg_ret_stream = $chg_tvie->delete_stream($value['chg_stream_id']);
                         $out_ret_stream = $out_tvie->delete_stream($value['out_stream_id']);
                         $sql = "DELETE FROM " . DB_PREFIX . "channel_stream WHERE out_stream_id=" . $value['out_stream_id'];
                         $this->db->query($sql);
                     }
                 }
                 if ($input_channel_stream_diff && $diff_stream_info_other) {
                     //有差集	  添加流信息(暂时只支持添加信息)
                     foreach ($diff_stream_info_other as $value) {
                         //上游流地址   直接是信号流地址
                         $delay_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name']), 'channels', 'tvie://');
                         $chg_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'delay_' . $channel_info['code_2'], 'stream_name' => $value['name']));
                         $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], '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'];
                         }
                         $delay_create_stream = $delay_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $delay_uri, $value['drm'], 'flv', $value['wait_relay'], 0, $value['bitrate'], $delay_id);
                         $chg_create_stream = $chg_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $chg_uri, $value['drm'], 'flv', $value['wait_relay'], 0, $value['bitrate'], $chg_id);
                         $out_create_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_id);
                         if ($channel_info['stream_state']) {
                             $out_tvie->stop_stream($out_create_stream['stream_id']);
                             $out_tvie->start_stream($out_create_stream['stream_id']);
                         } else {
                             $out_tvie->start_stream($out_create_stream['stream_id']);
                             $out_tvie->stop_stream($out_create_stream['stream_id']);
                         }
                         /*if(!$out_create_stream['stream_id'])
                         		{
                         			$this->errorOutput('更新频道失败,原因:'.$out_create_stream['message']);
                         		}*/
                         if ($out_create_stream['stream_id']) {
                             if ($main_stream_name[0] == $value['name']) {
                                 $is_main = 1;
                             } else {
                                 $is_main = 0;
                             }
                             //返回创建成功后的流信息
                             $channel_stream_info = array('channel_id' => $id, 'stream_id' => $stream_id, 'delay_stream_id' => $delay_create_stream['stream_id'], 'chg_stream_id' => $chg_create_stream['stream_id'], 'out_stream_id' => $out_create_stream['stream_id'], 'stream_name' => $value['name'], 'out_stream_name' => $value['name'], 'is_main' => $is_main, 'bitrate' => $value['bitrate'], 'flag_stream' => '', 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip());
                             $cresql = "INSERT INTO " . DB_PREFIX . "channel_stream SET ";
                             $space = "";
                             foreach ($channel_stream_info as $k => $v) {
                                 $cresql .= $space . $k . "=" . "'" . $v . "'";
                                 $space = ",";
                             }
                             $this->db->query($cresql);
                         }
                     }
                 } else {
                     foreach ($stream_info as $value) {
                         //上游流地址   直接是信号流地址
                         $delay_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name']), 'channels', 'tvie://');
                         $chg_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'delay_' . $channel_info['code_2'], 'stream_name' => $value['name']));
                         $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], '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'];
                         }
                         $delay_create_stream = $delay_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $delay_uri, $value['drm'], 'flv', $value['wait_relay'], 0, $value['bitrate'], $delay_id);
                         $chg_create_stream = $chg_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $chg_uri, $value['drm'], 'flv', $value['wait_relay'], 0, $value['bitrate'], $chg_id);
                         $out_create_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_id);
                         if ($channel_info['stream_state']) {
                             $out_tvie->stop_stream($out_create_stream['stream_id']);
                             $out_tvie->start_stream($out_create_stream['stream_id']);
                         } else {
                             $out_tvie->start_stream($out_create_stream['stream_id']);
                             $out_tvie->stop_stream($out_create_stream['stream_id']);
                         }
                         /*if(!$out_create_stream['stream_id'])
                         		{
                         			$this->errorOutput('更新频道失败,原因:'.$out_create_stream['message']);
                         		}*/
                         if ($out_create_stream['stream_id']) {
                             if ($main_stream_name[0] == $value['name']) {
                                 $is_main = 1;
                             } else {
                                 $is_main = 0;
                             }
                             //返回创建成功后的流信息
                             $channel_stream_info = array('channel_id' => $id, 'stream_id' => $stream_id, 'delay_stream_id' => $delay_create_stream['stream_id'], 'chg_stream_id' => $chg_create_stream['stream_id'], 'out_stream_id' => $out_create_stream['stream_id'], 'stream_name' => $value['name'], 'out_stream_name' => $value['name'], 'is_main' => $is_main, 'bitrate' => $value['bitrate'], 'flag_stream' => '', 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip());
                             $cresql = "INSERT INTO " . DB_PREFIX . "channel_stream SET ";
                             $space = "";
                             foreach ($channel_stream_info as $k => $v) {
                                 $cresql .= $space . $k . "=" . "'" . $v . "'";
                                 $space = ",";
                             }
                             $this->db->query($cresql);
                         }
                     }
                 }
             }
         }
         //层数为   2    ,跟新切播层、输出层
         if ($level == 2) {
             if ($input_channel_stream_diff) {
                 //有差集   删除被剔除的流信息
                 if (count($diff_stream_info) > 1) {
                     unset($diff_stream_info[0]);
                     //保留一条数据用作更新
                 }
                 foreach ($diff_stream_info as $value) {
                     $delay_ret_stream = $delay_tvie->delete_stream($value['delay_stream_id']);
                     $chg_ret_stream = $chg_tvie->delete_stream($value['chg_stream_id']);
                     $out_ret_stream = $out_tvie->delete_stream($value['out_stream_id']);
                     $sql = "DELETE FROM " . DB_PREFIX . "channel_stream WHERE out_stream_id=" . $value['out_stream_id'];
                     $this->db->query($sql);
                 }
             }
             if ($input_channel_stream_diff) {
                 //流名称改变后组成新数据
                 $channel_stream_2 = array();
                 foreach ($stream_info as $key => $value) {
                     $channel_stream_2[$key] = array_merge($stream_info[$key], $channel_stream[$key]);
                 }
             } else {
                 //other_info与channel_stream组成的数据
                 $channel_stream_2 = array();
                 foreach ($stream_info as $key => $value) {
                     $channel_stream_2[$key] = array_merge($stream_info[$key], $stream_info_new[$key]);
                 }
             }
             //更新切播层
             $chg_ret_channel = $chg_tvie->update_channel($name, 1, $live_delay, $chg_id);
             //更新切播层流
             foreach ($channel_stream_2 as $key => $value) {
                 //流地址
                 $chg_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name']));
                 if (is_array($value['backstore'])) {
                     $backstore = implode(',', $value['backstore']);
                 } else {
                     $backstore = $value['backstore'];
                 }
                 $chg_update_stream = $chg_tvie->update_channel_stream($value['chg_stream_id'], $value['drm'], $backstore, $value['recover_cache'], $chg_uri, 0, $value['wait_relay'], $value['source_name']);
                 if ($channel_info['stream_state']) {
                     $chg_tvie->stop_stream($value['chg_stream_id']);
                     $chg_tvie->start_stream($value['chg_stream_id']);
                 } else {
                     $chg_tvie->start_stream($value['chg_stream_id']);
                     $chg_tvie->stop_stream($value['chg_stream_id']);
                 }
             }
             //更新输出层
             $out_ret_channel = $out_tvie->update_channel($name, $save_time, $live_delay, $out_id);
             //更新输出层流
             foreach ($channel_stream_2 as $key => $value) {
                 //流地址
                 $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'chg_' . $channel_info['code_2'], 'stream_name' => $channel_stream[0]['out_stream_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'];
                 }
                 $out_update_stream = $out_tvie->update_channel_stream($value['out_stream_id'], $drm, $backstore, $value['recover_cache'], $out_uri, 0, $value['wait_relay'], $value['source_name']);
                 if ($channel_info['stream_state']) {
                     $out_tvie->stop_stream($value['out_stream_id']);
                     $out_tvie->start_stream($value['out_stream_id']);
                 } else {
                     $out_tvie->start_stream($value['out_stream_id']);
                     $out_tvie->stop_stream($value['out_stream_id']);
                 }
                 //更新channel_stream
                 $channel_stream_info = array('stream_id' => $stream_id, 'stream_name' => $value['name'], 'is_main' => 1, 'bitrate' => $value['bitrate'], 'flag_stream' => '', 'update_time' => TIMENOW);
                 $sql = "UPDATE " . DB_PREFIX . "channel_stream SET ";
                 $space = "";
                 $sql_extra = "";
                 foreach ($channel_stream_info as $k => $v) {
                     if ($v) {
                         $sql_extra .= $space . $k . "=" . "'" . $v . "'";
                         $space = ",";
                     }
                 }
                 if ($sql_extra) {
                     $sql .= $sql_extra . " WHERE channel_id=" . $id;
                     $this->db->query($sql);
                 }
             }
         }
         //更新延时层、切播层、输出层
         if ($level == 3) {
             if ($input_channel_stream_diff) {
                 //有差集   删除被剔除的流信息
                 if (count($diff_stream_info) > 1) {
                     unset($diff_stream_info[0]);
                     //保留一条数据用作更新
                 }
                 foreach ($diff_stream_info as $value) {
                     $delay_ret_stream = $delay_tvie->delete_stream($value['delay_stream_id']);
                     $chg_ret_stream = $chg_tvie->delete_stream($value['chg_stream_id']);
                     $out_ret_stream = $out_tvie->delete_stream($value['out_stream_id']);
                     $sql = "DELETE FROM " . DB_PREFIX . "channel_stream WHERE out_stream_id=" . $value['out_stream_id'];
                     $this->db->query($sql);
                 }
             }
             if ($input_channel_stream_diff) {
                 //流名称改变后组成新数据
                 $channel_stream_2 = array();
                 foreach ($stream_info as $key => $value) {
                     $channel_stream_2[$key] = array_merge($stream_info[$key], $channel_stream[$key]);
                 }
             } else {
                 //other_info与channel_stream组成的数据
                 $channel_stream_2 = array();
                 foreach ($stream_info as $key => $value) {
                     $channel_stream_2[$key] = array_merge($stream_info[$key], $stream_info_new[$key]);
                 }
             }
             //更新延时层
             $delay_ret_channel = $delay_tvie->update_channel($name, 1, $live_delay, $delay_id);
             //更新延时层流
             foreach ($channel_stream_2 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'];
                 }
                 $delay_update_stream = $delay_tvie->update_channel_stream($value['delay_stream_id'], $value['drm'], $backstore, $value['recover_cache'], $delay_uri, 0, $value['wait_relay'], $value['source_name']);
                 if ($channel_info['stream_state']) {
                     $delay_tvie->stop_stream($value['delay_stream_id']);
                     $delay_tvie->start_stream($value['delay_stream_id']);
                 } else {
                     $delay_tvie->start_stream($value['delay_stream_id']);
                     $delay_tvie->stop_stream($value['delay_stream_id']);
                 }
             }
             //更新切播层
             $chg_ret_channel = $chg_tvie->update_channel($name, 1, $live_delay, $chg_id);
             //更新切播层流
             foreach ($channel_stream_2 as $key => $value) {
                 //流地址
                 $chg_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'delay_' . $channel_info['code_2'], 'stream_name' => $channel_stream[0]['out_stream_name']));
                 if (is_array($value['backstore'])) {
                     $backstore = implode(',', $value['backstore']);
                 } else {
                     $backstore = $value['backstore'];
                 }
                 $chg_update_stream = $chg_tvie->update_channel_stream($value['chg_stream_id'], $value['drm'], $backstore, $value['recover_cache'], $chg_uri, 0, $value['wait_relay'], $value['source_name']);
                 if ($channel_info['stream_state']) {
                     $chg_tvie->stop_stream($value['chg_stream_id']);
                     $chg_tvie->start_stream($value['chg_stream_id']);
                 } else {
                     $chg_tvie->start_stream($value['chg_stream_id']);
                     $chg_tvie->stop_stream($value['chg_stream_id']);
                 }
             }
             //更新输出层
             $out_ret_channel = $out_tvie->update_channel($name, $save_time, $live_delay, $out_id);
             //更新输出层流
             foreach ($channel_stream_2 as $key => $value) {
                 //流地址
                 $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'chg_' . $channel_info['code_2'], 'stream_name' => $channel_stream[0]['out_stream_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'];
                 }
                 $out_update_stream = $out_tvie->update_channel_stream($value['out_stream_id'], $drm, $backstore, $value['recover_cache'], $out_uri, 0, $value['wait_relay'], $value['source_name']);
                 if ($channel_info['stream_state']) {
                     $out_tvie->stop_stream($value['out_stream_id']);
                     $out_tvie->start_stream($value['out_stream_id']);
                 } else {
                     $out_tvie->start_stream($value['out_stream_id']);
                     $out_tvie->stop_stream($value['out_stream_id']);
                 }
                 //更新channel_stream
                 $channel_stream_info = array('stream_id' => $stream_id, 'stream_name' => $value['name'], 'is_main' => 1, 'bitrate' => $value['bitrate'], 'flag_stream' => '', 'update_time' => TIMENOW);
                 $sql = "UPDATE " . DB_PREFIX . "channel_stream SET ";
                 $space = "";
                 $sql_extra = "";
                 foreach ($channel_stream_info as $k => $v) {
                     if ($v) {
                         $sql_extra .= $space . $k . "=" . "'" . $v . "'";
                         $space = ",";
                     }
                 }
                 if ($sql_extra) {
                     $sql .= $sql_extra . " WHERE channel_id=" . $id;
                     $this->db->query($sql);
                 }
             }
         }
     }
     //录制节目时间偏差设置
     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('name' => $name, 'save_time' => $save_time ? $save_time : '00', 'live_delay' => $live_delay ? $live_delay : '00', 'stream_id' => $stream_id, 'is_live' => $is_live ? $is_live : '00', 'drm' => $drm ? $drm : '00', 'uri_in_num' => $uri_in_num, 'stream_info_all' => serialize($stream_name), 'main_stream_name' => $main_stream_name[0], 'stream_display_name' => $streams['s_name'], 'stream_mark' => $streams['ch_name'], 'level' => $level, 'beibo' => $beibo, 'open_ts' => $this->input['open_ts'] ? intval($this->input['open_ts']) : '00', 'update_time' => TIMENOW, 'record_time' => $record_time ? $record_time : '00', 'audio_only' => $stream_info[0]['audio_only'] ? $stream_info[0]['audio_only'] : $channel_stream_2['audio_only']);
     $sql = "UPDATE " . DB_PREFIX . "channel SET ";
     $space = "";
     $sql_extra = "";
     foreach ($info as $key => $value) {
         if ($value) {
             $sql_extra .= $space . $key . "=" . "'" . $value . "'";
             $space = ",";
         }
     }
     if ($sql_extra) {
         $sql .= $sql_extra . " WHERE id=" . $id;
         $this->db->query($sql);
     }
     //插入工作量统计
     $statistic = new statistic();
     $statistics_data = array('content_id' => $id, 'contentfather_id' => '', 'type' => 'update', 'user_id' => $channel_info['user_id'], 'user_name' => $channel_info['user_name'], 'app_uniqueid' => APP_UNIQUEID, 'module_uniqueid' => MODULE_UNIQUEID, 'before_data' => '', 'last_data' => $name, 'num' => 1);
     $statistic->insert_record($statistics_data);
     $ret['id'] = $id;
     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');
         if (!empty($material)) {
             $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 logo_info = '" . serialize($logo_info) . "' WHERE id=" . $id;
             $this->db->query($sql);
         }
     }
     $this->setXmlNode('channel', 'info');
     $this->addItem($ret['id']);
     $this->output();
 }