Beispiel #1
0
 function update()
 {
     if ($this->mNeedCheckIn && !$this->prms['manage']) {
         $this->errorOutput(NO_OPRATION_PRIVILEGE);
     }
     $id = intval($this->input['id']);
     if (!$id) {
         $this->errorOutput('未传入ID');
     }
     $field = 'id, s_name, ch_name, uri, s_status, other_info, type, stream_count';
     $stream = $this->mStream->get_stream_by_id($id, $field);
     if (empty($stream)) {
         $this->errorOutput('该条信号不存在或已被删除');
     }
     $stream_count = count($this->input['counts']);
     //服务器信息
     $server_id = intval($this->input['server_id']);
     if ($server_id) {
         $self_count = $stream['stream_count'];
         $server_info = $this->mServerConfig->get_server_info($server_id, $id);
         if ($server_info == -1) {
             $this->errorOutput('该服务器信息不存在或已被删除');
         } else {
             if ($server_info == -2) {
                 $this->errorOutput('该服务器已经无法再添加信号,请选择其他服务器');
             }
         }
         if ($stream_count > $server_info['over_count'] && $server_info != 1) {
             $offset_count = $stream_count - $server_info['over_count'];
             $this->errorOutput('已经超过该服务器信号的最大数目 [ ' . $offset_count . ' ] 条,请选择其他服务器!');
         }
     }
     //是否是文件形成的流 1-是 0-否
     $type = intval($this->input['type']);
     if (is_array($this->input['counts']) && $this->input['counts']) {
         $streams_info = $tpl_uri = $tpl_name = $tpl_name_index = $source_name = array();
         for ($i = 0; $i < $stream_count; $i++) {
             if (!$type) {
                 unset($this->input['source_name_' . $i]);
                 unset($this->input['backup_title_' . $i]);
             } else {
                 unset($this->input['uri_' . $i]);
             }
             $streams_info[$i]['id'] = trim($this->input['id_' . $i]);
             $streams_info[$i]['name'] = trim($this->input['name_' . $i]);
             if (!hg_check_string(trim($this->input['name_' . $i]))) {
                 $this->errorOutput('输出标识只包含字母数字下划线');
             }
             $streams_info[$i]['ch_name'] = trim($this->input['ch_name_hidden']);
             $streams_info[$i]['uri'] = trim($this->input['uri_' . $i]);
             if (!trim($this->input['uri_' . $i]) && !isset($this->input['source_name_' . $i]) && !$type) {
                 $this->errorOutput('来源地址不能为空');
             }
             $streams_info[$i]['bitrate'] = $this->input['bitrate_' . $i];
             $streams_info[$i]['backstore'] = '';
             $streams_info[$i]['audio_only'] = intval($this->input['audio_only']);
             $streams_info[$i]['wait_relay'] = intval($this->input['wait_relay']);
             $streams_info[$i]['recover_cache'] = '';
             $streams_info[$i]['drm'] = '';
             $streams_info[$i]['source_name'] = $this->input['source_name_' . $i] ? $this->input['source_name_' . $i] : '';
             $streams_info[$i]['source_id'] = $this->input['source_id_' . $i] ? $this->input['source_id_' . $i] : '';
             $streams_info[$i]['chg_stream_id'] = $this->input['chg_stream_id_' . $i] ? $this->input['chg_stream_id_' . $i] : '';
             $streams_info[$i]['backup_title'] = $this->input['backup_title_' . $i] ? $this->input['backup_title_' . $i] : '';
             $tpl_uri[] = trim($this->input['uri_' . $i]);
             $tpl_name[] = trim($this->input['name_' . $i]);
             $tpl_name_index[trim($this->input['name_' . $i])] = trim($this->input['name_' . $i]);
             if ($type && !$this->input['source_name_' . $i]) {
                 $this->errorOutput('请为输出标识 [' . trim($this->input['name_' . $i]) . '] 选择备播文件');
             }
             if ($this->input['source_name_' . $i]) {
                 $source_name[] = $this->input['source_name_' . $i];
             }
         }
     }
     $tpl_name_counts = @array_count_values($tpl_name);
     if (!empty($tpl_name_counts)) {
         foreach ($tpl_name_counts as $v) {
             if ($v > 1) {
                 $this->errorOutput('输出标识不能重复');
             }
         }
     }
     $info = $this->mStream->update($id, $streams_info, $tpl_uri, $tpl_name, $tpl_name_index, $source_name, $type, $stream_count, $server_info['server_info'], $stream);
     switch ($info) {
         case -55:
             $this->errorOutput('媒体服务器未启动');
             break;
         case -17:
             $this->errorOutput('媒体服务器数据添加失败');
             break;
         case 0:
             $this->errorOutput('创建失败');
             break;
         default:
             break;
     }
     $this->addItem($info);
     $this->output();
 }
Beispiel #2
0
 public function update()
 {
     if ($this->mNeedCheckIn && !$this->prms['manage']) {
         $this->errorOutput(NO_OPRATION_PRIVILEGE);
     }
     $id = intval($this->input['id']);
     if (!$id) {
         $this->errorOutput('未传入频道ID');
     }
     $name = trim($this->input['name']);
     if (!$name) {
         $this->errorOutput('频道名称不能为空');
     }
     $code = trim($this->input['code']);
     if (!$code) {
         $this->errorOutput('台号不能为空');
     }
     if (!hg_check_string($code)) {
         $this->errorOutput('台号只包含字母数字下划线');
     }
     if ($code != trim($this->input['code2']) && !$this->mChannels->check_channelCode($code)) {
         $this->errorOutput('[' . $code . '] 台号已存在!');
     }
     $stream_id = intval($this->input['stream_id']);
     if (!$stream_id) {
         $this->errorOutput('请选择流信息');
     }
     if (count($this->input['stream_name']) < 1) {
         $this->errorOutput('至少选择一个信号!');
     }
     //直播频道
     $channel_field = ' code, stream_id, ch_id, save_time, live_delay, drm, open_ts, stream_state, column_id, column_url, expand_id, server_id ';
     $channel_info = $this->mChannels->get_channel_by_id($id, $channel_field);
     if (empty($channel_info)) {
         $this->errorOutput('该频道不存在或已被删除');
     }
     //备播信号
     $stream_field = ' id, s_name, ch_name, other_info, type, server_id ';
     $stream_info = $this->mChannels->get_stream_by_id($stream_id, $stream_field);
     if (empty($stream_info)) {
         $this->errorOutput('选择的信号不存在或已被删除');
     }
     //服务器配置
     $server_id = $stream_info['server_id'];
     if ($server_id) {
         $server_info = $this->mServerConfig->get_server_info($server_id, '', $id);
         if ($server_info == -1) {
             $this->errorOutput('该服务器信息不存在或已被删除');
         } else {
             if ($server_info == -2) {
                 $this->errorOutput('该服务器已经无法再添加信号,请选择其他服务器');
             }
         }
         $stream_count = count($this->input['stream_name']);
         if ($stream_count > $server_info['over_count']) {
             $offset_count = $stream_count - $server_info['over_count'];
             $this->errorOutput('已经超过该服务器信号的最大数目 [ ' . $offset_count . ' ] 条,请选择其他服务器!');
         }
     }
     //时移时间
     $save_time = intval($this->input['save_time']);
     if ($save_time > $this->settings['max_save_time']) {
         $save_time = $this->settings['max_save_time'];
     }
     //延时时间
     $live_delay = intval($this->input['live_delay']);
     if ($live_delay > $this->settings['max_live_delay']) {
         $live_delay = $this->settings['max_live_delay'];
     }
     $add_info = array('stream_name' => $this->input['stream_name'], 'open_ts' => intval($this->input['open_ts']), 'save_time' => $save_time, 'live_delay' => $live_delay, 'drm' => intval($this->input['drm']), 'code' => $code, 'name' => $name, 'column_id' => trim($this->input['column_id']), 'record_server_id' => intval($this->input['record_server_id']));
     $info = $this->mChannels->update($id, $add_info, $channel_info, $stream_info, $server_info);
     if ($info['head']) {
         $this->errorOutput($info['head']['title']);
     }
     switch ($info) {
         case -55:
             $this->errorOutput('媒体服务器未启动');
             break;
         case -20:
             $this->errorOutput('更新时移输出层应用失败');
             break;
         case -200:
             $this->errorOutput('更新直播输出层应用失败');
             break;
         case 0:
             $this->errorOutput('更新失败');
             break;
         default:
             break;
     }
     $this->addItem($info);
     $this->output();
 }
Beispiel #3
0
 public function update()
 {
     $id = intval($this->input['id']);
     $name = trim($this->input['name']);
     $code = trim($this->input['code']);
     //	$server_id 			= intval($this->input['server_id']);
     //	$main_stream_name 	= $this->input['main_stream_name'];
     $stream_name = $this->input['stream_name'];
     $stream_id = $this->input['stream_id'];
     $url = $this->input['url'];
     $bitrate = $this->input['bitrate'];
     $is_control = intval($this->input['is_control']);
     //$is_mobile_phone	= intval($this->input['is_mobile_phone']);
     $is_audio = intval($this->input['is_audio']);
     $is_push = intval($this->input['is_push']);
     //	$drm				= intval($this->input['drm']);
     $time_shift = intval($this->input['time_shift']);
     //	$delay				= intval($this->input['delay']);
     //	$record_time_diff	= intval($this->input['record_time_diff']);
     $is_default = intval($this->input['is_default']);
     //	$column_id 			= trim($this->input['column_id']);
     $_appid = $this->input['_appid'];
     $_appname = $this->input['_appname'];
     if (!$id) {
         $this->errorOutput('ID不能为空');
     }
     if (!$name) {
         $this->errorOutput('频道名称不能为空');
     }
     if (!$code) {
         $this->errorOutput('台号不能为空');
     }
     if (!hg_check_string($code)) {
         $this->errorOutput('台号只能包含字母数字');
     }
     $ret_code = $this->mChannel->check_channel_code($code, $id);
     if (!empty($ret_code)) {
         $this->errorOutput('[' . $code . '] 台号已存在!');
     }
     //录制时间
     /*
     if ($time_shift > $this->settings['max_time_shift'])
     {
     	$time_shift = $this->settings['max_time_shift'];
     }
     
     //延时时间
     if ($delay > $this->settings['max_delay'])
     {
     	$delay = $this->settings['max_delay'];
     }
     */
     //关联输出标识的来源地址
     //$url_index = $stream_url = array();
     $channel_stream = array();
     $core_count = count($stream_name);
     //$bitrates = array();
     for ($i = 0; $i < $core_count; $i++) {
         if (!trim($stream_name[$i])) {
             $this->errorOutput('输出标识不能为空');
         }
         if ($i > 0 && $stream_name[0] == $stream_name[$i]) {
             $this->errorOutput('输出标识不能重复');
         }
         if (!hg_check_string($stream_name[$i])) {
             $this->errorOutput('输出标识只能包含字母数字');
         }
         if (!trim($url[$i])) {
             $this->errorOutput('信号流地址不能为空');
         }
         if (!trim($bitrate[$i])) {
             $this->errorOutput('码流不可以为空');
         }
         /*
         if ($i == $is_default)
         {
         	$is_default_stream = $stream_name[$i];
         }
         $url_index[$stream_name[$i]] 	= trim($url[$i]);
         $stream_url[$i]['stream_name'] 	= trim($stream_name[$i]);
         if($main_stream_name == $stream_url[$i]['stream_name'])
         {
         	$main_stream_url = $url[$i];
         }
         $stream_url[$i]['url'] 			= trim($url[$i]);
         $bitrates[$stream_name[$i]]		= intval($bitrate[$i]);
         */
         $channel_stream[$i] = array('stream_name' => $stream_name[$i], 'url' => $url[$i], 'bitrate' => intval($bitrate[$i]), 'is_main' => $is_default == $i ? 1 : 0, 'order_id' => $i);
     }
     $main_stream_name = $stream_name[$is_default];
     $main_stream_url = $url[$is_default];
     $stream_count = $core_count;
     $level = 1;
     /*
     if ($delay)
     {
     	$stream_count = $stream_count + $core_count;
     	$level = $level + 1;
     }
     
     if ($is_control)
     {
     	$stream_count = $stream_count + $core_count;
     	$level = $level + 1;
     }
     
     if ($delay || $is_control)
     {
     	$stream_count = $stream_count + $core_count;
     	$level = $level + 1;
     }
     */
     $channel_info = $this->mChannel->get_channel_by_id($id, 1);
     if ($channel_info['code'] != $code) {
         $this->errorOutput("频道号无法修改");
     }
     if (empty($channel_info)) {
         $this->errorOutput('该频道不存在或已被删除');
     }
     $schedule_control = unserialize($channel_info['schedule_control']);
     #####节点权限检测数据收集
     if ($this->user['group_type'] > MAX_ADMIN_TYPE) {
         $_node_ids = '';
         if ($channel_info['node_id']) {
             $_node_ids = $channel_info['node_id'];
         }
         if ($this->input['node_id']) {
             $_node_ids = $_node_ids ? $_node_ids . ',' . $this->input['node_id'] : $this->input['node_id'];
         }
         if ($_node_ids) {
             $sql = 'SELECT id, parents FROM ' . DB_PREFIX . 'channel_node WHERE id IN(' . $_node_ids . ')';
             $query = $this->db->query($sql);
             $nodes = array();
             while ($row = $this->db->fetch_array($query)) {
                 $nodes['nodes'][$row['id']] = $row['parents'];
             }
         }
     }
     #####节点权限
     $nodes['id'] = $id;
     $nodes['user_id'] = $channel_info['user_id'];
     $nodes['org_id'] = $channel_info['org_id'];
     $nodes['column_id'] = $this->input['column_id'];
     $nodes['published_column_id'] = '';
     //	$nodes['weight'] = $nodes['weight'];
     $ori_column_id = array();
     if (is_array($channel_info['column_id'])) {
         $ori_column_id = array_keys($channel_info['column_id']);
         $nodes['published_column_id'] = implode(',', $ori_column_id);
     }
     $this->verify_content_prms($nodes);
     ########权限#########
     $server_id = $channel_info['server_id'];
     /*
     		$channel_stream = $channel_info['channel_stream'];
     		$applicationId	= $channel_info['application_id'];
     		$stream_name_db	= $channel_info['stream_name'];
     		
     		$is_live 	= $channel_info['is_live'];
     		$is_record  = $channel_info['is_record'];
     		$is_push	= $channel_info['is_push'];
     		
     		//信号数据重新组合
     		
     		//模板stream_name 、 数据库stream_name 差集
     		
     		//delete
     		$stream_name_diff_db_tpl = array_diff($stream_name_db, $stream_name);
     		
     		//create
     		$stream_name_diff_tpl_db = array_diff($stream_name, $stream_name_db);
     		
     		//update
     		$stream_name_inter_db_tpl = array_intersect($stream_name_db, $stream_name);
     		
     		$channel_stream_delete = $channel_stream_create = $channel_stream_update = array();
     		
     		if (!empty($channel_stream))
     		{
     			foreach ($channel_stream AS $v)
     			{
     				foreach ($stream_name_diff_db_tpl AS $vv)
     				{
     					if ($vv == $v['stream_name'])
     					{
     						$channel_stream_delete[] = $v;
     					}
     				}
     				
     				foreach ($stream_name_inter_db_tpl AS $kk => $vv)
     				{
     					if ($vv == $v['stream_name'])
     					{
     						if ($vv == $is_default_stream)
     						{
     							$is_default = 1;
     						}
     						else
     						{
     							$is_default = 0;
     						}
     						$v['is_default'] = $is_default;
     						$v['url'] = $url_index[$v['stream_name']];
     						$v['bitrate'] = $bitrates[$v['stream_name']];
     						$channel_stream_update[] = $v;
     					}
     				}
     			}
     		}
     		foreach ($stream_name_diff_tpl_db AS $kk => $vv)
     		{
     			if ($vv == $stream_name[$kk])
     			{
     				if ($vv == $is_default_stream)
     				{
     					$is_default = 1;
     				}
     				else
     				{
     					$is_default = 0;
     				}
     				$channel_stream_create[] = array(
     					'channel_id'	=> $id,
     					'stream_name'	=> $vv,
     					'is_default'	=> $is_default,
     					'url'			=> $url_index[$vv],
     					'bitrate'		=> $bitrates[$vv],
     				);
     			}
     		}
     
     		//检查是否需要更新wowza服务器数据
     		$is_update_wowza = 0;
     		if ($channel_info['code'] != $code || $channel_info['is_audio'] != $is_audio || $channel_info['is_control'] != $is_control
     			|| $channel_info['delay'] != $delay || $channel_info['is_mobile_phone'] != $is_mobile_phone || $channel_info['time_shift'] != $time_shift
     		)
     		{
     			$is_update_wowza = 1;
     		}
     		
     		foreach ($stream_url AS $k => $v)
     		{
     			if ($channel_stream[$k]['stream_name'] != $v['stream_name'] || $channel_stream[$k]['url'] != $v['url'] || $channel_stream[$k]['bitrate'] != $v['bitrate'] )
     			{
     				$is_update_wowza = 1;
     			}
     		}
     
     		//服务器配置
     * 
     */
     $server_info = $this->mServerConfig->get_server_config_by_id($server_id);
     if (empty($server_info)) {
         $this->errorOutput('该直播服务器不存在或已被删除');
     }
     //服务器状态
     if (!$server_info['status']) {
         $this->errorOutput('该服务器未审核');
     }
     $type = $server_info['type'] ? $server_info['type'] : 'wowza';
     //$super_token = $server_info['super_token'];
     /*
     if ($is_update_wowza)
     {
     	//服务器最大信号数目
     	$counts 	  = $server_info['counts'] ? $server_info['counts'] : $this->settings['wowza']['counts'];
     	//已用信号数目
     	$_stream_count = $this->mChannel->get_stream_count($server_id, $id);
     	//剩余信号数目
     	$over_count   = $counts - ($_stream_count + $stream_count);
     	
     	if ($over_count < 0)
     	{
     		$this->errorOutput('信号数目已超过该服务器数目限制, 已超出 ' . abs($over_count) . ' 条');
     	}
     	
     	$server_info = $this->mChannel->get_server_info($server_info);
     	
     	$host			= $server_info['host'];
     	$input_dir  	= $server_info['input_dir'];
     	$output_dir 	= $server_info['output_dir'];
     	$wowzaip_input 	= $server_info['wowzaip_input'];
     	
     	$live_host		= $server_info['live_host'];
     	$record_host	= $server_info['record_host'];
     	
     	//检测流媒体服务器是否正常
     	$function = 'media_server_' . $type;
     	$ret_media_server = $this->$function($server_info, $super_token);
     	
     	if (!$ret_media_server['core_server'])
     	{
     		$this->errorOutput($type . '主控服务器未启动');
     	}
     	
     	if ($live_host && !$ret_media_server['live_server'])
     	{
     		$this->errorOutput($type . '直播服务器未启动');
     	}
     	
     	if ($record_host && !$ret_media_server['record_server'])
     	{
     		$this->errorOutput($type . '录制服务器未启动');
     	}
     	
     	if ($type == 'wowza')
     	{	
     		$applicationType = 1;
     		if ($is_mobile_phone)
     		{
     			$applicationType = 3;
     		}
     		
     		$application_data = array(
     			'action'	=> 'update',
     			'id'		=> $applicationId,
     			'name'		=> $code,
     			'length'	=> $time_shift * 3600,
     			'drm'		=> $drm,
     			'type'		=> $applicationType,
     		);
     		
     		$ret_application = $this->mLivemms->outputApplicationOperate($host, $output_dir, $application_data);
     		
     		if (!$ret_application['result'])
     		{
     			$this->errorOutput('主控输出层应用更新失败');
     		}
     		
     		//直播
     		if ($live_host)
     		{
     			$application_data['length'] = 0;
     			
     			if (!$is_live)
     			{
     				$application_data['action'] = 'insert';
     			}
     			
     			$ret_application = $this->mLivemms->outputApplicationOperate($live_host, $output_dir, $application_data);
     				
     			if (!$ret_application['result'])
     			{
     				$this->errorOutput('直播输出层应用更新失败');
     			}
     		}
     		
     		//录制
     		if ($record_host)
     		{
     			$application_data['length'] = 0;
     			
     			if (!$is_record)
     			{
     				$application_data['action'] = 'insert';
     			}
     			
     			$ret_application = $this->mLivemms->outputApplicationOperate($record_host, $output_dir, $application_data);
     			
     			if (!$ret_application['result'])
     			{
     				$this->errorOutput('录制输出层应用更新失败');
     			}
     		}
     	}
     	
     	//delete
     	foreach ($channel_stream_delete AS $v)
     	{
     		$v['code'] 			= $channel_info['code'];
     		$v['delay'] 		= $channel_info['delay'];
     		$v['is_control'] 	= $channel_info['is_control'];
     		$v['is_live'] 		= $channel_info['is_live'];
     		$v['is_record'] 	= $channel_info['is_record'];
     		
     		$function = 'stream_operate_' . $type;
     		$this->$function($server_info, $v, 'delete');
     	}
     
     	//update
     	$ret_input_id_update = $ret_delay_id_update = $ret_change_id_update = $ret_output_id_update = $ret_live_output_id_update = $ret_record_output_id_update = $channel_stream_info_update = array();
     	
     	foreach ($channel_stream_update AS $k => $v)
     	{
     		$v['code'] 			= $channel_info['code'];
     		$v['db_delay'] 		= $channel_info['delay'];
     		$v['db_is_control'] = $channel_info['is_control'];
     		$v['delay'] 		= $delay;
     		$v['is_control'] 	= $is_control;
     		$v['is_live'] 		= $channel_info['is_live'];
     		$v['is_record'] 	= $channel_info['is_record'];
     		$v['status'] 		= $channel_info['status'];
     		$v['applicationId'] 		= $channel_info['application_id'];
     		$v['time_shift'] 	= $time_shift;
     		
     		$function = 'edit_stream_' . $type;
     		$edit_stream = $this->$function($server_info, $v);
     		
     		$ret_input_id_update[$k]  = $edit_stream['ret_input_id'];
     		$ret_delay_id_update[$k]  = $edit_stream['ret_delay_id'];
     		$ret_change_id_update[$k] = $edit_stream['ret_change_id'];
     		$ret_output_id_update[$k] = $edit_stream['ret_output_id'];
     		
     		$ret_live_output_id_update[$k]   = $edit_stream['ret_live_output_id'];
     		$ret_record_output_id_update[$k] = $edit_stream['ret_record_output_id'];
     		
     		if (!$ret_output_id_update)
     		{
     			continue;
     		}
     		
     		//直播
     		if ($live_host && !$ret_live_output_id_update)
     		{
     			continue;
     		}
     		
     		//录制
     		if ($record_host && !$ret_record_output_id_update)
     		{
     			continue;
     		}
     		
     		$channel_stream_info_update[$k] = array(
     			'id'			=> $v['id'],
     			'stream_name'	=> $v['stream_name'],
     			'url'			=> $v['url'],
     			'is_default'			=> $v['is_default'],
     			'input_id'		=> $ret_input_id_update[$k],
     			'delay_id'		=> $ret_delay_id_update[$k],
     			'change_id'		=> $ret_change_id_update[$k],
     			'output_id'		=> $ret_output_id_update[$k],
     			'bitrate'		=> $v['bitrate'],
     			'is_main'		=> ($main_stream_name == $v['stream_name']) ? 1 : 0,
     		);
     	}
     	
     	//create
     	$ret_input_id = $ret_delay_id = $ret_change_id = $ret_output_id = $channel_stream_info = array();
     	$ret_live_output_id = $ret_record_output_id = array();
     	foreach ($channel_stream_create AS $k => $v)
     	{
     		$_channel_stream = array(
     			'url'				=> $v['url'],
     			'delay'				=> $delay,
     			'is_control'		=> $is_control,
     			'is_push'			=> $is_push,
     			'applicationId'		=> $applicationId,
     			'stream_name'		=> $v['stream_name'],
     			'is_default'		=> $v['is_default'],
     			'code'				=> $code,
     			'time_shift'		=> $time_shift,
     			'status'			=> $channel_info['status'],
     		);
     		
     		$function = 'set_stream_' . $type;
     		$set_stream = $this->$function($server_info, $_channel_stream, true);
     			
     		$ret_input_id[$k]  = $set_stream['ret_input_id'];
     		$ret_delay_id[$k]  = $set_stream['ret_delay_id'];
     		$ret_change_id[$k] = $set_stream['ret_change_id'];
     		$ret_output_id[$k] = $set_stream['ret_output_id'];
     		
     		$ret_live_output_id[$k]   = $set_stream['ret_live_output_id'];
     		$ret_record_output_id[$k] = $set_stream['ret_record_output_id'];
     		
     		$channel_stream_info[$k] = array(
     			'stream_name'	=> $v['stream_name'],
     			'url'			=> $v['url'],
     			'input_id'		=> $ret_input_id[$k],
     			'delay_id'		=> $ret_delay_id[$k],
     			'change_id'		=> $ret_change_id[$k],
     			'output_id'		=> $ret_output_id[$k],
     			'bitrate'		=> $v['bitrate'],
     			'is_main'		=> ($main_stream_name == $v['stream_name']) ? 1 : 0,
     		);
     	}
     	
     	//如果创建过程中有失败,则删除以创建好的
     	$tmp_delete = 0;
     	for ($j = 0; $j < count($channel_stream_create); $j ++)
     	{
     		if (!$ret_output_id[$j])
     		{
     			$tmp_delete = 1;
     		}
     		
     		//直播
     		if ($live_host && !$ret_live_output_id[$j])
     		{
     			$tmp_delete = 1;
     		}
     		
     		//录制
     		if ($record_host && !$ret_record_output_id[$j])
     		{
     			$tmp_delete = 1;
     		}
     	}
     	
     	if ($tmp_delete)
     	{
     		for ($i = 0; $i < count($channel_stream_create); $i ++)
     		{
     			$_channel_stream = $channel_stream_info[$i];
     			$_channel_stream['code'] 	   	= $code;
     			$_channel_stream['is_control'] 	= $is_control;
     			$_channel_stream['delay'] 		= $delay;
     			$_channel_stream['is_live'] 	= $is_live;
     			$_channel_stream['is_record'] 	= $is_record;
     			
     			$function = 'stream_operate_' . $type;
     			$this->$function($server_info, $_channel_stream, 'delete');
     		}
     		
     		$this->errorOutput('流媒体服务器新增信号创建失败');
     	}
     	
     	if ($live_host)
     	{
     		$is_live = 1;
     		foreach ($ret_live_output_id_update AS $v)
     		{
     			if (!$v)
     			{
     				$is_live = 0;
     				$this->errorOutput('更新直播服务器信号失败');
     			}
     		}
     	}
     	
     	if ($record_host)
     	{
     		$is_record = 1;
     		foreach ($ret_record_output_id_update AS $v)
     		{
     			if (!$v)
     			{
     				$is_record = 0;
     				$this->errorOutput('更新录制服务器信号失败');
     			}
     		}
     	}
     }
     */
     $data = array('id' => $id, 'name' => $name, 'main_stream_name' => $main_stream_name, 'stream_name' => serialize($stream_name), 'stream_count' => $stream_count, 'core_count' => $core_count, 'application_id' => $applicationId, 'time_shift' => $time_shift, 'is_audio' => $is_audio, 'is_push' => $is_push, 'is_control' => $is_control, 'record_time_diff' => $record_time_diff, 'server_id' => $server_id, 'status' => $type == 'wowza' ? $is_update_wowza ? 0 : 1 : $channel_info['status'], 'can_record' => 1, 'record_uri' => $this->input['record_uri']);
     //发布开始
     //$data['column_id'] = $this->mPublishColumn->get_columnname_by_ids('id,name', $column_id);
     //$data['column_id'] = $data['column_id'] ? serialize($data['column_id']) : '';
     //发布结束
     //去除播控
     if (!$is_control && $this->settings['schedule_control_wowza']['is_wowza'] && $schedule_control) {
         //本需要删除wowza中的流和数据 现只对nginx操作
     }
     //如果不存在创建播控和串联单两层输出
     if ($is_control && $this->settings['schedule_control_wowza']['is_wowza'] && !$schedule_control) {
         $schedule_control = array();
         $_schedule_control_data = array('url' => $main_stream_url, 'type' => $is_push, 'action' => 'insert');
         if (!($schedule_control = $this->create_schedule_control($_schedule_control_data))) {
             $this->errorOutput("创建播控层[或串联单层]失败");
         }
         //同步数据至串联单的channel_server
         $this->schedule_syn_channel_server($schedule_control, $id);
         $data['schedule_control'] = serialize($schedule_control);
     }
     //如果修改了流地址 只需修改底流
     $from_control_stream = '';
     if ($is_control && $this->settings['schedule_control_wowza']['is_wowza'] && $schedule_control) {
         if (count($channel_stream) > 1) {
             $this->errorOutput("多码流不支持播空和串联单");
         }
         $_schedule_control_data = array('url' => $main_stream_url, 'type' => $is_push, 'action' => 'update', 'id' => $schedule_control['schedule']['stream_id']);
         $host = $this->settings['schedule_control_wowza']['host'];
         $inputdir = $outputdir = $this->settings['schedule_control_wowza']['inputdir'];
         $ret = $this->mLivemms->inputStreamOperate($host, $inputdir, $_schedule_control_data);
         if (!$ret['result']) {
             $this->errorOutput("wowza更新失败");
         }
         $ret = $this->mLivemms->inputStreamOperate($host, $inputdir, array('action' => 'start', 'id' => $_schedule_control_data['id']));
         if (!$ret['result']) {
             $this->errorOutput("流启动失败");
         }
         $from_control_stream = "rtmp://" . str_replace(':8086', '', $this->settings['schedule_control_wowza']['host']) . "/input/" . $schedule_control['control']['output_id'] . ".output";
     }
     /******************** 检查TS目录存储 *************************/
     include CUR_CONF_PATH . 'lib/' . $type . '.live.php';
     $server = new m2oLive();
     //查出所有使用该直播配置的信号流占用的存储
     $sql = "SELECT c_s.bitrate,c_s.channel_id,c.time_shift FROM " . DB_PREFIX . "channel_stream c_s \r\n\t\t\t\tLEFT JOIN " . DB_PREFIX . "channel c ON c_s.channel_id = c.id \r\n\t\t\t\tWHERE c.server_id = " . $server_id;
     $q = $this->db->query($sql);
     $used_size = 0;
     while ($row = $this->db->fetch_array($q)) {
         if ($row['channel_id'] != $id) {
             $used_size += $row['bitrate'] * $row['time_shift'] * 3600;
         }
     }
     //新添加的信号流所需的存储
     $bitrate = 0;
     if (is_array($channel_stream)) {
         foreach ($channel_stream as $k => $v) {
             $bitrate += $v['bitrate'];
         }
     }
     //所需存储总数 (存储单位b, 码流单位kbps)
     $needsize = (3600 * $time_shift * $bitrate + $used_size) * 1024;
     //取主、备配置
     $sql = "SELECT host,input_dir,hls_path,fid FROM " . DB_PREFIX . "server_config WHERE id = " . $server_id . " OR fid = " . $server_id;
     $query = $this->db->query($sql);
     $query_b = $query;
     while ($row = $this->db->fetch_array($query)) {
         $row_b[] = $row;
         $init_data = array('host' => $row['host'], 'dir' => $row['input_dir']);
         $server->init_env($init_data);
         if (!$server->check_ts_path(array('needsize' => $needsize, 'hls_path' => $row['hls_path']))) {
             $this->errorOutput('主机' . $init_data['host'] . '所设置的TS目录存储不足');
         }
     }
     /**************************************************************/
     //入本地库
     $ret = $this->mChannel->update($data);
     if (!$ret['id']) {
         $this->errorOutput('更新失败');
     }
     $init_data = array('host' => $server_info['host'], 'dir' => $server_info['input_dir']);
     $main_stream_url_db = '';
     if (is_array($channel_info['channel_stream'])) {
         foreach ($channel_info['channel_stream'] as $val) {
             if ($val['is_main']) {
                 $main_stream_url_db = $val['url'];
             }
         }
     }
     //$this->errorOutput(var_export($main_stream_url_db,1));
     //include(CUR_CONF_PATH . 'lib/' . $type . '.live.php');
     //$server = new m2oLive();
     //$update_data = array('url'=>$main_stream_url,'name'=>$code . '_' . $main_stream_name);
     //$db_data = array('url'=>$main_stream_url_db, 'name'=>$code . '_' . $main_stream_name);
     //$this->errorOutput(var_export(array_diff($update_data, $db_data),1).'a');
     /*
     $is_update_server = false;
     if($channel_stream)
     {
     	$streams_in_db = array();
     	$streams_in_form = array();
     	foreach($channel_stream as $k=>$v)
     	{
     		$streams_in_db[] = $code . '_' . $v['stream_name'];
     	}
     	foreach ($channel_info['channel_stream'] as $val)
     	{
     		$streams_in_form[] = $code . '_' . $val['stream_name'];
     	}
     	if(array_diff($streams_in_db, $streams_in_form) || array_diff($streams_in_form, $streams_in_db))
     	{
     		$is_update_server = true;
     	}
     }
     */
     //向直播服务器发送数据库信息数据以及设置流、设置时移目录
     foreach ($row_b as $kee => $vaa) {
         $init_data = array('host' => $vaa['host'], 'dir' => $vaa['input_dir']);
         $server->init_env($init_data);
         if (is_array($channel_info['channel_stream']) && $channel_info['channel_stream']) {
             foreach ($channel_info['channel_stream'] as $val) {
                 $server->delete(array('url' => $from_control_stream ? $from_control_stream : $v['url'], 'name' => build_nginx_stream_name($code, $val['stream_name'])));
             }
         }
         $this->db->query("DELETE FROM " . DB_PREFIX . "channel_stream WHERE channel_id IN (" . $id . ")");
         if (is_array($channel_stream) && $channel_stream) {
             foreach ($channel_stream as $k => $v) {
                 $v['channel_id'] = $id;
                 $v['is_default'] = 0;
                 if ($k == $is_default) {
                     $v['is_default'] = 1;
                 }
                 $create_data = array('url' => $from_control_stream ? $from_control_stream : $v['url'], 'name' => build_nginx_stream_name($code, $v['stream_name']), 'playlen' => $time_shift, 'mysql_table' => $vaa['fid'] ? DB_PREFIX . $channel_info['table_name'] . '_1' : DB_PREFIX . $channel_info['table_name']);
                 if (!$is_push) {
                     if (!$server->create($create_data)) {
                         $this->errorOutput("服务器更新流失败,请稍后更新重试");
                     }
                 }
                 $this->mChannel->channel_stream_create($v);
                 //设置时移
                 if (!$server->set_timeshift_length($create_data)) {
                     $this->errorOutput("设置时移失败");
                 }
                 //设置时移目录
                 $path_data = array('app' => 'live', 'name' => $create_data['name'], 'hls_path' => $vaa['hls_path']);
                 if (!$server->set_timeshift_path($path_data)) {
                     $this->errorOutput('设置时移目录失败');
                 }
             }
         }
     }
     /*
     //更新标记
     $affected_rows = $ret['affected_rows'];
     
     //频道信号delete
     foreach ($channel_stream_delete AS $v)
     {
     	$ret_channel_stream = $this->mChannel->channel_stream_delete($v['id']);
     	
     	if (!$ret_channel_stream)
     	{
     		continue;
     	}
     	
     	if ($ret_channel_stream['affected_rows'])
     	{
     		$affected_rows = $ret_channel_stream['affected_rows'];
     	}
     }
     //频道信号update
     foreach ($channel_stream_info_update AS $v)
     {
     	$ret_channel_stream = $this->mChannel->channel_stream_update($v);
     	
     	if (!$ret_channel_stream)
     	{
     		continue;
     	}
     
     	if ($ret_channel_stream['affected_rows'])
     	{
     		$affected_rows = $ret_channel_stream['affected_rows'];
     	}
     }
     */
     //频道信号create
     /*
     //更新排序id
     if (!empty($channel_stream_info))
     {
     	$channel_stream = $this->mChannel->get_channel_stream_by_channel_id($id);
     }
     
     $update_order = array();
     foreach ($stream_name AS $k => $v)
     {
     	foreach ($channel_stream AS $kk => $vv)
     	{
     		if ($v == $vv['stream_name'])
     		{
     			$update_order[$k]['id'] 	  = $vv['id'];
     			$update_order[$k]['order_id'] = $k;
     		}
     	}
     }
     
     foreach ($update_order AS $v)
     {
     	$ret_channel_stream = $this->mChannel->channel_stream_update($v);
     	
     	if (!$ret_channel_stream)
     	{
     		continue;
     	}
     
     	if ($ret_channel_stream['affected_rows'])
     	{
     		$affected_rows = $ret_channel_stream['affected_rows'];
     	}
     }
     */
     //长方形logo
     if ($_FILES['logo_rectangle']['tmp_name']) {
         $logo_rectangle = $this->mChannel->add_material($_FILES['logo_rectangle'], $id);
     }
     $data['logo_rectangle'] = $logo_rectangle ? serialize($logo_rectangle) : '';
     //方形logo
     if ($_FILES['logo_square']['tmp_name']) {
         $logo_square = $this->mChannel->add_material($_FILES['logo_square'], $id);
     }
     $data['logo_square'] = $logo_square ? serialize($logo_square) : '';
     /*
     //音频logo
     if ($_FILES['logo_audio']['tmp_name'])
     {
     	$logo_audio = $this->mChannel->add_material($_FILES['logo_audio'], $id);
     }
     
     $data['logo_audio'] = $logo_audio ? serialize($logo_audio) : '';
     */
     //多客户端logo
     if (!empty($_FILES['client_logo']) || $channel_info['client_logo']) {
         $client_logo = array();
         foreach ($_FILES['client_logo'] as $k => $v) {
             ${$k} = $v;
             foreach (${$k} as $kk => $vv) {
                 $client_logo[$kk][$k] = $vv;
             }
         }
         $_client_logo = array();
         foreach ($_appid as $appid) {
             if ($client_logo[$appid]) {
                 $_client_logo[$appid] = $this->mChannel->add_material($client_logo[$appid], $id);
                 $_client_logo[$appid]['appid'] = $_appid[$appid];
                 $_client_logo[$appid]['appname'] = $_appname[$appid];
             } else {
                 $_client_logo[$appid] = $channel_info['client_logo'][$appid];
                 if (!$channel_info['client_logo'][$appid]) {
                     unset($_client_logo[$appid]);
                 }
             }
         }
     }
     $data['client_logo'] = $_client_logo ? serialize($_client_logo) : '';
     //更新 长方形logo、方形logo、多客户端logo、音频logo
     $update_data = array('id' => $id);
     if ($data['logo_rectangle']) {
         $update_data['logo_rectangle'] = $data['logo_rectangle'];
     }
     if ($data['logo_square']) {
         $update_data['logo_square'] = $data['logo_square'];
     }
     /*
     if ($data['logo_audio'])
     {
     	$update_data['logo_audio'] = $data['logo_audio'];
     }
     */
     if ($data['client_logo']) {
         $update_data['client_logo'] = $data['client_logo'];
     }
     if ($channel_info['client_logo'] && empty($_appid)) {
         $data['client_logo'] = $channel_info['client_logo'];
         $update_data['client_logo'] = '';
     }
     if ($channel_info['logo_audio'] && !$is_audio) {
         $data['logo_audio'] = $channel_info['logo_audio'];
         $update_data['logo_audio'] = '';
     }
     //更新数据
     if ($data['logo_rectangle'] || $data['logo_square'] || $data['client_logo'] || $data['logo_audio']) {
         $ret_logo = $this->mChannel->update($update_data);
         $affected_rows = $ret_logo['affected_rows'];
     }
     /*
     //发布开始
     if ($ret['id'])
     {
     	//更改文章后发布的栏目
     	$ret['column_id'] = unserialize($ret['column_id']);
     	$new_column_id = array();
     	if(is_array($ret['column_id']))
     	{
     		$new_column_id = array_keys($ret['column_id']);
     	}
     	
     	if(!empty($channel_info['expand_id']))   //已经发布过,对比修改先后栏目
     	{
     		$del_column = array_diff($ori_column_id,$new_column_id);
     		if(!empty($del_column))
     		{
     			$this->publish_insert_query($data['id'], 'delete',$del_column);
     		}
     		$add_column = array_diff($new_column_id,$ori_column_id);
     		if(!empty($add_column))
     		{
     			$this->publish_insert_query($data['id'], 'insert',$add_column);
     		}
     		$same_column = array_intersect($ori_column_id,$new_column_id);
     		if(!empty($same_column))
     		{
     			$this->publish_insert_query($data['id'], 'update',$same_column);
     		}
     	}
     	else 							//未发布,直接插入
     	{
     		$op = "insert";
     		$this->publish_insert_query($data['id'],$op);
     	}
     	//发布结束
     }
     */
     $m3u8file = DATA_DIR . $data['code'] . '/playlist.m3u8';
     @unlink($m3u8file);
     //记录日志
     if (true) {
         $user_data = array('id' => $id, 'update_time' => TIMENOW, 'update_org_id' => $this->user['org_id'], 'update_user_id' => $this->user['user_id'], 'update_user_name' => $this->user['user_name'], 'update_appid' => $this->user['appid'], 'update_appname' => $this->user['display_name'], 'update_ip' => hg_getip());
         $ret_user = $this->mChannel->update($user_data);
         $this->mChannel->cache_channel($data['code']);
         if (!empty($ret_user)) {
             unset($ret_user['id']);
             foreach ($ret_user as $k => $v) {
                 $data[$k] = $v;
             }
         }
         $pre_data = $channel_info;
         $this->addLogs('更新直播频道', $pre_data, $data, $data['name'], $data['id']);
     }
     $this->addItem($ret);
     $this->output();
 }