public function show() { $channel_id = $this->input['channel_id']; $channel_code = $this->input['channel_code']; if (!$channel_id && !$channel_code) { $this->errorOutput('未传入频道ID'); } $suffix = 'live.m3u8'; if ($this->input['source']) { $cond = " AND t1.open_ts=1 "; if ($this->input['source'] == 2) { $suffix = 'live.mp4'; } } $sql = "SELECT t1.*, t2.core_in_host, t2.core_out_port, \r\n\t\t\t\t\tt2.is_dvr_output, t2.dvr_in_host, t2.dvr_out_port, \r\n\t\t\t\t\tt2.is_live_output, t2.live_in_host, t2.live_out_port \r\n\t\t\t\tFROM " . DB_PREFIX . "channel t1"; $sql .= " LEFT JOIN " . DB_PREFIX . "server_config t2 ON t2.id = t1.server_id "; if ($channel_id == 'latest') { $sql .= " WHERE 1 " . $cond . " AND t1.stream_state "; $sql .= " ORDER BY t1.id DESC LIMIT 1"; } else { if ($channel_id) { $ucond = " t1.id=" . intval($channel_id); } else { $ucond = " t1.code='" . $channel_code . "'"; } $sql .= " WHERE " . $ucond . $cond; } $channel_info = $this->db->query_first($sql); $channel_id = $channel_info['id']; $imgsize = $this->input['imgsize'] ? $this->input['imgsize'] : '450x341'; $info = array(); if (is_array($channel_info)) { $info['id'] = $channel_info['id']; $info['channel']['name'] = $channel_info['name']; $info['channel']['drm'] = $channel_info['drm']; $info['channel']['logo'] = array(); if ($channel_info['logo_info']) { $channel_info['logo_info'] = unserialize($channel_info['logo_info']); $info['channel']['logo']['rectangle']['host'] = $channel_info['logo_info']['host']; $info['channel']['logo']['rectangle']['dir'] = $channel_info['logo_info']['dir']; $info['channel']['logo']['rectangle']['filepath'] = $channel_info['logo_info']['filepath']; $info['channel']['logo']['rectangle']['filename'] = $channel_info['logo_info']['filename']; $info['channel']['logo']['rectangle']['url'] = $channel_info['logo_info']['url']; } if ($channel_info['logo_mobile_info']) { $channel_info['logo_mobile_info'] = unserialize($channel_info['logo_mobile_info']); $info['channel']['logo']['square']['host'] = $channel_info['logo_mobile_info']['host']; $info['channel']['logo']['square']['dir'] = $channel_info['logo_mobile_info']['dir']; $info['channel']['logo']['square']['filepath'] = $channel_info['logo_mobile_info']['filepath']; $info['channel']['logo']['square']['filename'] = $channel_info['logo_mobile_info']['filename']; $info['channel']['logo']['square']['url'] = $channel_info['logo_mobile_info']['url']; } //live $info['channel']['snap'] = array('host' => MMS_CONTROL_LIST_PREVIEWIMG_URL, 'dir' => '', 'filepath' => date('Y') . '/' . date('m') . '/', 'filename' => 'live_' . $channel_info['id'] . '.png?time=' . TIMENOW); $info['channel']['audio_only'] = $channel_info['audio_only']; if ($channel_info['audio_only']) { $info['channel']['snap'] = $info['channel']['logo']['square']; } $sql = "SELECT id,theme,start_time FROM " . DB_PREFIX . 'program WHERE channel_id =' . $channel_id . ' '; $sql .= ' AND start_time >= ' . TIMENOW . ' LIMIT 2'; $programq = $this->db->query($sql); $program = array(); while ($r = $this->db->fetch_array($programq)) { $program[$r['start_time']] = $r['theme']; } ksort($program); $p = array(); foreach ($program as $theme) { $p[] = $theme; } $info['channel']['cur_program'] = $p[0] ? $p[0] : '精彩节目'; $info['channel']['next_program'] = $p[1] ? $p[1] : '精彩节目'; //$info['ad'][] = array(); $sql = "select * from " . DB_PREFIX . "channel_stream where channel_id=" . $channel_id; $main_stream = $this->db->query($sql); $streams = array(); while ($r = $this->db->fetch_array($main_stream)) { /* if ($r['bitrate']) { $streams[$r['bitrate']] = array( 'url' => hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $channel_info['code'], 'stream_name' => $r['out_stream_name'])), 'bit' => $r['bitrate'] ); } else { */ if ($channel_info['core_in_host']) { if ($channel_info['is_dvr_output']) { $wowzaip = $channel_info['dvr_in_host'] . ':' . $channel_info['dvr_out_port']; } else { $wowzaip = $channel_info['core_in_host'] . ':' . $channel_info['core_out_port']; } } else { if ($this->settings['wowza']['dvr_output_server']) { $wowzaip = $this->settings['wowza']['dvr_output_server']['host'] . ':' . $this->settings['wowza']['out_port']; } else { $wowzaip = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['out_port']; } } $dvr_suffix = $this->settings['wowza']['dvr_output']['suffix']; //live if ($this->mLive) { if ($channel_info['is_live_output']) { $_wowzaip = $channel_info['live_in_host'] . ':' . $channel_info['live_out_port']; } else { $_wowzaip = $this->settings['wowza']['live_output_server']['host'] . ':' . $this->settings['wowza']['out_port']; } $live_suffix = $this->settings['wowza']['live_output']['suffix']; } $m3u8 = ''; if ($channel_info['open_ts']) { //live if ($this->mLive) { $livem3u8 = hg_streamUrl($_wowzaip, $channel_info['code'], $r['out_stream_name'] . $live_suffix, 'm3u8', TIMENOW - 30000 . '000', 'dvr'); } $m3u8 = hg_streamUrl($wowzaip, $channel_info['code'], $r['out_stream_name'] . $dvr_suffix, 'm3u8', TIMENOW - 30000 . '000', 'dvr'); } //live if ($this->mLive) { $_liveurl = hg_streamUrl($_wowzaip, $channel_info['code'], $r['out_stream_name'] . $live_suffix, 'flv'); } $_url = hg_streamUrl($wowzaip, $channel_info['code'], $r['out_stream_name'] . $dvr_suffix, 'flv'); $streams[] = array('live' => $_liveurl, 'livem3u8' => $livem3u8, 'url' => $_url, 'm3u8' => $m3u8, 'bit' => $r['bitrate']); /* } */ } if ($streams) { krsort($streams); foreach ($streams as $key => $value) { $info['stream'][] = $value; } } if ($channel_info['tvieurl']) { $info['tviestream'][] = array('live' => $channel_info['tvieurl'], 'livem3u8' => '', 'url' => $channel_info['tvieurl'], 'm3u8' => '', 'bit' => $channel_info['bitrate']); } } $this->addItem($info); $this->output(); }
/** * 切播 * Enter description here ... * @param unknown_type $channel_id * @param unknown_type $stream_id * @param unknown_type $chg_type */ public function emergency_change($channel_id, $stream_id, $chg_type, $live_back, $user) { $sql = "SELECT * FROM " . DB_PREFIX . "channel WHERE id = " . $channel_id; $channel_info = $this->db->query_first($sql); if (empty($channel_info)) { return -13; //该频道不存在或者已被删除 } if (!$channel_info['stream_state']) { return -14; //频道输出流未启动 } $server_id = $channel_info['server_id']; if ($server_id) { $server_info = $this->mServerConfig->get_server_config_by_id($server_id); $server_output = $this->mServerConfig->get_server_output_by_id($server_id); } if ($server_info['core_in_host']) { $host = $server_info['core_in_host'] . ':' . $server_info['core_in_port']; $apidir_input = $server_info['input_dir']; $apidir_output = $server_info['output_dir']; $wowzaip = $server_info['core_in_host']; } else { $host = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['core_input_server']['port']; $apidir_input = $this->settings['wowza']['core_input_server']['input_dir']; $apidir_output = $this->settings['wowza']['core_input_server']['output_dir']; $wowzaip = $this->settings['wowza']['core_input_server']['host']; } $ret_select = $this->mLivemms->outputApplicationSelect($host, $apidir_output); if (!$ret_select) { return -55; //切播服务器未开启 } //返回上一次切播的信息 $chg2_stream_id = $channel_info['chg2_stream_id'] ? $channel_info['chg2_stream_id'] : $channel_info['stream_id']; if ($channel_info['chg_type'] == 'stream') { $sql = "SELECT s_name, ch_name, id, other_info, type FROM " . DB_PREFIX . "stream WHERE id = " . $chg2_stream_id; $prev_stream = $this->db->query_first($sql); if ($prev_stream['other_info']) { $prev_other_info = @unserialize($prev_stream['other_info']); // $prev['name'] = $prev_stream['s_name']; $prev['name'] = $prev_stream['ch_name']; $prev['stream_id'] = $prev_stream['id']; $suffix_input = !$prev_stream['type'] ? $this->settings['wowza']['input']['suffix'] : $this->settings['wowza']['list']['suffix']; $prev['stream_url'] = hg_streamUrl($wowzaip, $this->settings['wowza']['input']['app_name'], $prev_other_info['input'][0]['id'] . $suffix_input); } } else { if ($channel_info['chg_type'] == 'file') { $sql = "SELECT id, title, fileid FROM " . DB_PREFIX . "backup WHERE id = " . $chg2_stream_id; $prev_backup_info = $this->db->query_first($sql); if ($prev_backup_info['fileid']) { $prev['name'] = $prev_backup_info['title']; $prev['stream_id'] = $prev_backup_info['id']; $prev['stream_url'] = hg_streamUrl($wowzaip, $this->settings['wowza']['backup']['app_name'], $this->settings['wowza']['backup']['prefix'] . $this->settings['wowza']['backup']['midfix'] . $prev_backup_info['fileid'] . $this->settings['wowza']['backup']['suffix']); } } } $prev['chg_type'] = $channel_info['chg_type']; //再次切播同一备播信号或者备播文件 返回信息 if ($channel_info['chg2_stream_id'] == $stream_id) { $ret = array('prev' => $prev); return $ret; } $sql = "SELECT * FROM " . DB_PREFIX . "channel_stream WHERE channel_id = " . $channel_id . " ORDER BY id ASC"; $q = $this->db->query($sql); $channel_stream_info = $channel_stream_info_index = array(); while ($row = $this->db->fetch_array($q)) { $channel_stream_info[] = $row; $channel_stream_info_index[$row['stream_name']] = $row; } if (empty($channel_stream_info_index)) { return -15; //频道信号流不存在 } if ($chg_type == 'stream') { $sql = "SELECT * FROM " . DB_PREFIX . "stream WHERE id = " . $stream_id; $stream_info = $this->db->query_first($sql); if (empty($stream_info)) { return -16; //该信号不存在或已被删除 } // $stream_name = $stream_info['s_name']; $stream_name = $stream_info['ch_name']; if (!$stream_info['s_status']) { return -17; //该信号流未启动 } $other_info = unserialize($stream_info['other_info']); if (!empty($other_info)) { $input_info = $other_info['input']; $input_info_index = array(); foreach ($other_info['input'] as $k => $v) { $input_info_index[$v['name']] = $v; } } } //修正串联单 $notify = 0; if ($live_back == 'live_back') { $notify = 1; } if ($channel_info['stream_id'] == $stream_id && $chg_type == 'stream') { if (!empty($channel_stream_info_index)) { foreach ($channel_stream_info_index as $k => $v) { if (!$channel_info['live_delay']) { $sourceId = $input_info_index[$k]['id']; $sourceType = !$stream_info['type'] ? 1 : 3; } else { $sourceId = $v['delay_stream_id']; $sourceType = 2; } $chgId = $v['chg_stream_id']; if (!$chgId) { $msg = array(0 => '未能获取切播层ID'); return $msg; } $ret_chg = $this->mLivemms->inputChgStreamChange($host, $apidir_input, $chgId, $sourceId, $sourceType, $notify); if (!$ret_chg['result']) { $msg = array(-1 => '无法连接切播服务', 0 => '切播失败'); return $ret_chg['result']; } if ($channel_info['list_fileid'] && $channel_info['chg_type'] == 'file') { $ret_fileListDelete = $this->mLivemms->inputFileListDelete($host, $apidir_input, $channel_info['list_fileid']); } } $up_data = array('id' => $channel_id, 'chg2_stream_id' => 0, 'chg2_stream_name' => 0, 'chg_type' => 'stream', 'list_fileid' => 0); $sql_ = "SELECT id,chg2_stream_id,chg2_stream_name,chg_type,list_fileid FROM " . DB_PREFIX . "channel WHERE id = " . $channel_id; $pre_data = $this->db->query_first($sql_); $sql = "UPDATE " . DB_PREFIX . "channel SET chg2_stream_id=0, chg2_stream_name=0, chg_type='stream', list_fileid=0 WHERE id=" . $channel_id; $this->db->query($sql); $chg_type = 'stream'; $ret = array('msg' => $ret_chg, 'stream_id' => $stream_id, 'stream_name' => $stream_name, 'chg_type' => $chg_type, 'prev' => $prev); $ret['live_back'] = $notify ? 1 : 0; //记录日志 $this->channelChgLog($channel_id, $channel_info['name'], 'live', $stream_id, $stream_name, $chg_type, $user); return $ret; } return false; } else { if ($chg_type == 'file') { $sql = "SELECT title, videofilename, fileid FROM " . DB_PREFIX . "backup WHERE id = " . $stream_id; $backup_info = $this->db->query_first($sql); $stream_name = $backup_info['title']; if (!$backup_info['fileid']) { return -18; //备播文件不存在或已损坏 } //形成一条文件流 /* $ret_list = $this->mLivmms->inputFileListInsert($backup_info['fileid']); if (!$ret_list['result']) { return -19; //文件流形成失败 } $list_fileid = $ret_list['list']['id']; if (!$list_fileid) { return -20; } $sourceId = $list_fileid; */ $sourceId = $backup_info['fileid']; $sourceType = 4; } else { $sourceId = array(); foreach ($channel_stream_info as $k => $v) { if ($input_info[$k]['id']) { $input_id = $input_info[$k]['id']; } else { $input_id = $input_info[0]['id']; } $sourceId[] = $input_id; } $sourceType = !$stream_info['type'] ? 1 : 3; } foreach ($channel_stream_info as $k => $v) { $chgId = $v['chg_stream_id']; if ($chg_type == 'file') { $ret_chg = $this->mLivemms->inputChgStreamChange($host, $apidir_input, $chgId, $sourceId, $sourceType, $notify); } else { $ret_chg = $this->mLivemms->inputChgStreamChange($host, $apidir_input, $chgId, $sourceId[$k], $sourceType, $notify); } if (!$ret_chg['result']) { $msg = array(-1 => '无法连接切播服务', 0 => '切播失败'); return $ret_chg['result']; } } $sql_ = "SELECT id,chg2_stream_id,chg2_stream_name FROM " . DB_PREFIX . "channel WHERE id = " . $channel_id; $pre_data = $this->db->query_first($sql_); $up_data = array(); $up_data = array('id' => $channel_id, 'chg2_stream_id' => $stream_id, 'chg2_stream_name' => $stream_name, 'chg_type' => $chg_type); if ($ret_chg['result']) { // $sql = "UPDATE " . DB_PREFIX . "channel SET chg2_stream_id=" . $stream_id . ", chg2_stream_name='" . $stream_name . "', chg_type='" . $chg_type . "', list_fileid = " . intval($list_fileid) . " WHERE id=" . $channel_id; $sql = "UPDATE " . DB_PREFIX . "channel SET chg2_stream_id=" . $stream_id . ", chg2_stream_name='" . $stream_name . "', chg_type='" . $chg_type . "' WHERE id=" . $channel_id; $this->db->query($sql); $ret = array('msg' => $ret_chg, 'stream_id' => $stream_id, 'stream_name' => $stream_name, 'chg_type' => $chg_type, 'prev' => $prev); $ret['live_back'] = $notify ? 1 : 0; //记录日志 $this->channelChgLog($channel_id, $channel_info['name'], 'chg', $stream_id, $stream_name, $chg_type, $user); $this->addLogs('切播', $pre_data, $up_data, '', '', $channel_info['name']); return $ret; } return false; } }
/** * 显示录播节目单 */ function show() { $sql = "SELECT c.code, c.name,c.save_time,c.main_stream_name,c.stream_state,c.record_time,c.stream_id, pr.*,vs.sort_name\n\t\t\t\t\tFROM " . DB_PREFIX . "program_record pr \n\t\t\t\t\tLEFT JOIN " . DB_PREFIX . "channel c \n\t\t\t\t\t\tON pr.channel_id=c.id \n\t\t\t\t\tLEFT JOIN " . DB_PREFIX . "vod_sort vs \n\t\t\t\t\t\tON pr.item=vs.id\n\t\t\t\tWHERE is_record=0 and (pr.start_time) > " . strtotime(date('Y-m-d', TIMENOW)) . " and pr.start_time < " . (strtotime(date('Y-m-d', TIMENOW)) + 86399); $q = $this->db->query($sql); while ($row = $this->db->fetch_array($q)) { $return = array(); if (!$row['channel_id']) { continue; } $ret = $log_data = array(); $ret['id'] = $log_data['id'] = $row['id']; $ret['channel_id'] = $log_data['channel_id'] = $row['channel_id']; $ret['name'] = rawurlencode($row['name']); $ret['startTime'] = date('YmdHis', $row['start_time'] + $row['record_time'] - 1); $row['toff'] = $row['toff'] + 2; $program = $row['title'] ? $row['title'] : trim($this->program_plan($ret['channel_id'], $ret['starttime'], $ret['endtime'])); $ret['title'] = $log_data['title'] = rawurlencode(trim($program ? $program : '精彩节目')); $log_data['start_time'] = $row['start_time']; $log_data['toff'] = $row['toff']; $log_data['week_day'] = $row['week_day']; $log_data['item'] = $row['item']; $log_data['columnid'] = $row['columnid']; $log_data['column_name'] = $row['column_name']; $log_data['ip'] = $row['ip']; //$ret['starttime'] = $row['start_time']+$row['record_time']; //$ret['toff'] = $row['toff']; //live if ($this->mLive) { $ret['stream'] = hg_streamUrl($this->settings['mms']['_output']['wowzaip'], $row['code'], $row['main_stream_name'] . $this->settings['mms']['_output']['suffix']); } else { $ret['stream'] = hg_streamUrl($this->settings['mms']['output']['wowzaip'], $row['code'], $row['main_stream_name'] . $this->settings['mms']['output']['suffix']); } //$callback = $this->settings['App_mediaserver']['protocol'] . $this->settings['App_mediaserver']['host'] . '/' . $this->settings['App_mediaserver']['dir'] . 'admin/create.php?appid=' . $this->input['appid'] . '&appkey=' . $this->input['appkey'] . '&vod_leixing=3&auth=' . $this->settings['vodapi']['token'] . '&channel_id=' . $row['channel_id']; $callback = $this->settings['App_mediaserver']['protocol'] . $this->settings['App_mediaserver']['host'] . '/' . $this->settings['App_mediaserver']['dir'] . 'admin/record_callback_old.php'; $ret['vod_sort_id'] = $row['item']; $ret['week_flag'] = $row['week_day'] ? 1 : 0; $ret['column_id'] = $row['columnid'] ? $row['columnid'] : 0; $ret['audit_auto'] = $row['audit_auto'] ? 2 : 0; $ret['exit_status'] = $row['audit_auto']; $ret['save_time'] = $row['save_time']; //$ret['delay_time'] = $row['live_delay'] * 60; $ret['source'] = $row['channel_id']; $ret['is_allow'] = $row['is_mark']; $ret['force_codec'] = $row['force_codec']; $sql = "select id, ch_name,other_info,s_status from " . DB_PREFIX . "stream where id=" . $row['stream_id']; $stream = $this->db->query_first($sql); if (!$row['stream_state']) { $ret = array('errortext' => '视频流未开启!'); } elseif (!$stream['s_status']) { $ret = array('errortext' => '视频上游流未开启!'); } else { /* $this->curl->setSubmitType('post'); $this->curl->setReturnFormat('json'); $this->curl->initPostData(); $this->curl->addRequestData('action', 'insert'); $this->curl->addRequestData('url', $ret['stream']); $this->curl->addRequestData('callback', urlencode($callback)); $this->curl->addRequestData('startTime', $ret['starttime']-1); $this->curl->addRequestData('duration', $row['toff']+1); */ $this->curl->setSubmitType('get'); $this->curl->initPostData(); $this->curl->addRequestData('action', 'INSERT'); $this->curl->addRequestData('url', $ret['stream']); $this->curl->addRequestData('callback', urlencode($callback)); //$this->curl->addRequestData('startTime', $ret['starttime']-1); $this->curl->addRequestData('duration', $row['toff']); $this->curl->addRequestData('uploadFile', '0'); $this->curl->addRequestData('appid', $this->input['appid']); $this->curl->addRequestData('appkey', $this->input['appkey']); foreach ($ret as $k => $v) { $this->curl->addRequestData($k, $v); } $ret = array(); $record_xml = $this->curl->request(''); $record_array = xml2Array($record_xml); if (is_array($record_array)) { $ret['id'] = $record_array['record']['id'] ? $record_array['record']['id'] : 0; if (!$record_array['result']) { $ret['errortext'] = '录制超时'; //报错 $ret['isError'] = 1; } else { $ret['errortext'] = '等待录制'; $ret['isError'] = 0; } } else { $ret['id'] = 0; $ret['errortext'] = '录制失败,无内容!'; $ret['isError'] = 1; } $is_record = $ret['id'] ? 1 : 0; $conid = $this->add_queue($row['id']); if (!$ret['isError']) { $sql_update = "UPDATE " . DB_PREFIX . "program_record SET is_out=0,conid=" . $conid . ",is_record=" . $is_record . " WHERE id=" . $row['id']; $this->db->query($sql_update); $log_data['text'] = $ret['errortext']; $log_data['state'] = $ret['isError'] ? 2 : 0; $log_id = $this->live->addLogs($log_data); $this->update_queue($conid, $log_id); } else { $week_day = unserialize($row['week_day']); if (is_array($week_day) && $week_day) { $week_now = date('N', $row['start_time']); $new_arr = array_flip($week_day); if (count($week_day) > $new_arr[$week_now] + 1) { $ks = $new_arr[$week_now] + 1; } else { $ks = 0; } $week_day = array_flip($new_arr); $next_week = $week_day[$ks] - $week_now > 0 ? $week_day[$ks] - $week_now : $week_day[$ks] - $week_now + 7; $start_time = $row['start_time'] + $next_week * 86400; $sql_update = "UPDATE " . DB_PREFIX . "program_record SET conid=0,is_record=0,start_time=" . $start_time . " WHERE id=" . $row['id']; $this->db->query($sql_update); } else { $sql_update = "UPDATE " . DB_PREFIX . "program_record SET is_out=1,conid=0,is_record=1 WHERE id=" . $row['id']; $this->db->query($sql_update); } $log_data['text'] = $ret['errortext']; $log_data['state'] = 2; $log_id = $this->live->addLogs($log_data); $this->update_queue($conid, $log_id); } } $str = 'ID-' . $row['id'] . ($ret['errortext'] ? $ret['errortext'] : '录制成功'); $this->tips($str, TIMENOW); } }
/** * 串联单显示 * @name show * @access public * @author lijiaying * @category hogesoft * @copyright hogesoft * @param $condition 检索条件 * @param $channel_id int 频道ID * @param $dates string 格式化日期(Y-m-d) * @return $channel_name string 频道名称 * @return $channel_id int 频道ID * @return $dates_api string 格式化日期(Y-m-d) * @return $uri string 频道输出流地址 * @return $change array 某天串联单信息内容 */ public function show() { $condition = $this->get_condition(); $channel_id = intval($this->input['channel_id']); if (!$channel_id) { $this->errorOutput('未传入频道ID'); } $dates = $this->input['dates'] ? urldecode($this->input['dates']) : date('Y-m-d'); $sql = "SELECT t1.name, t1.code, t1.audio_only, t1.server_id, t2.out_stream_name FROM " . DB_PREFIX . "channel t1 "; $sql .= " LEFT JOIN " . DB_PREFIX . "channel_stream t2 ON t1.id=t2.channel_id "; $sql .= " WHERE t1.id=" . $channel_id . " AND t2.is_main = 1 "; $channel_info = $this->db->query_first($sql); if (empty($channel_info)) { $this->errorOutput('该频道不存在或已被删除'); } //服务器配置 $server_id = $channel_info['server_id']; if ($server_id) { $server_info = $this->mServerConfig->get_server_config_by_id($server_id); } if ($server_info['core_in_host']) { if ($server_info['is_dvr_output']) { $host = $server_info['dvr_in_host'] . ':' . $server_info['dvr_in_port']; $wowzaip = $server_info['dvr_in_host'] . ':' . $server_info['dvr_out_port']; } else { $host = $server_info['core_in_host'] . ':' . $server_info['core_in_port']; $wowzaip = $server_info['core_in_host'] . ':' . $server_info['core_out_port']; } $apidir_output = $server_info['output_dir']; } else { if ($this->settings['dvr_output_server']) { $host = $this->settings['wowza']['dvr_output_server']['host'] . ':' . $this->settings['wowza']['dvr_output_server']['port']; $apidir_output = $this->settings['wowza']['dvr_output_server']['output_dir']; $wowzaip = $this->settings['wowza']['dvr_output_server']['host'] . ':' . $this->settings['wowza']['out_port']; } else { $host = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['core_input_server']['port']; $apidir_output = $this->settings['wowza']['core_input_server']['output_dir']; $wowzaip = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['out_port']; } } $suffix = $this->settings['wowza']['dvr_output']['suffix']; if ($this->mLive) { if ($server_info['is_live_output']) { $host = $server_info['live_in_host'] . ':' . $server_info['live_in_port']; $apidir_output = $server_info['output_dir']; $wowzaip = $server_info['live_in_host'] . ':' . $server_info['live_out_port']; } else { $host = $this->settings['wowza']['live_output_server']['host'] . ':' . $this->settings['wowza']['live_output_server']['port']; $apidir_output = $this->settings['wowza']['live_output_server']['output_dir']; $wowzaip = $this->settings['wowza']['live_output_server']['host'] . ':' . $this->settings['wowza']['out_port']; } $suffix = $this->settings['wowza']['live_output']['suffix']; } $uri = hg_streamUrl($wowzaip, $channel_info['code'], $channel_info['out_stream_name'] . $suffix, 'flv'); $ret_ntpTime = $this->mLivemms->outputNtpTime($host, $apidir_output); $this->addItem_withkey('channel_name', $channel_info['name']); $this->addItem_withkey('channel_id', $channel_id); $this->addItem_withkey('server_id', $server_id); $this->addItem_withkey('dates_api', $dates); $this->addItem_withkey('uri', $uri); $this->addItem_withkey('audio_only', $channel_info['audio_only']); if ($ret_ntpTime['result']) { $ntpTime = $ret_ntpTime['ntp']['utc']; $ntpTime = ceil($ntpTime / 1000); $ntpYmdhis = date('Y-m-d H:i:s', $ntpTime); $ntpHis = date('H:i:s', $ntpTime); } else { $ntpYmdhis = date('Y-m-d H:i:s', TIMENOW); $ntpHis = date('H:i:s', TIMENOW); } $this->addItem_withkey('ntpYmdhis', $ntpYmdhis); $this->addItem_withkey('ntpHis', $ntpHis); $change = array(); $start = strtotime($dates . " 00:00:00"); $end = strtotime($dates . " 23:59:59"); $com_time = 0; $today = date('Y-m-d', TIMENOW); $last_week_day = date('Y-m-d', strtotime($today) + (7 - date('N', strtotime($today))) * 86400); $change_plan = $this->getPlan($channel_id, $dates); if ($dates >= $today && $dates <= $last_week_day) { $change_plan = $this->getPlan($channel_id, $dates); } else { $change_plan = array(); } $sql = "SELECT * FROM " . DB_PREFIX . "channel_chg_plan "; $sql .= " WHERE channel_id=" . $channel_id . " AND dates='" . $dates . "'" . $condition . " ORDER BY change_time ASC "; $q = $this->db->query($sql); while ($row = $this->db->fetch_array($q)) { if (!$com_time && $row['change_time'] > $start) { $plan = $this->verify_plan($change_plan, $start, $row['change_time']); if ($plan) { foreach ($plan as $k => $v) { $change[] = $v; } } else { $change[] = $this->getInfo($start, $row['change_time'], $dates); } } if ($com_time && $com_time != $row['change_time']) { $plan = $this->verify_plan($change_plan, $com_time, $row['change_time']); if ($plan) { foreach ($plan as $k => $v) { $change[] = $v; } } else { $change[] = $this->getInfo($com_time, $row['change_time'], $dates); } } $row['plan_status'] = $row['change_time'] < TIMENOW ? 1 : 0; $row['end_time'] = date('H:i:s', $row['change_time'] + $row['toff']); $row['start_time'] = date('H:i:s', $row['change_time']); $row['e_time'] = date('H:i:s', $row['program_start_time'] + $row['toff']); $row['s_time'] = date('m-d H:i:s', $row['program_start_time']); if ($row['program_start_time']) { $row['program_end_time'] = date('Y-m-d H:i:s', $row['program_start_time'] + $row['toff']); $row['program_start_time'] = date('Y-m-d H:i:s', $row['program_start_time']); } if ($row['file_toff']) { $row['file_toff'] = time_format($row['file_toff']); } else { unset($row['file_toff']); } $row['start'] = date("H:i:s", $row['change_time']); $row['end'] = date("H:i:s", $row['change_time'] + $row['toff']); $com_time = $row['change_time'] + $row['toff']; $change[] = $row; } if ($com_time && $com_time < $end) { $plan = $this->verify_plan($change_plan, $com_time, $end); if ($plan) { foreach ($plan as $k => $v) { $change[] = $v; } } else { // $change[] = $this->getInfo($com_time,$end,$dates); } } if (empty($change)) { $change = array(); $start = strtotime($dates . " 00:00:00"); $end = strtotime($dates . " 23:59:59"); $com_time = 0; foreach ($change_plan as $k => $v) { if (!$com_time && $v['change_time'] > $start) { $change[] = $this->getInfo($start, $v['change_time'], $dates); } if ($com_time && $com_time != $v['change_time']) { $change[] = $this->getInfo($com_time, $v['change_time'], $dates); } $v['start'] = date("H:i", $v['change_time']); $v['end'] = date("H:i", $v['change_time'] + $v['toff']); $com_time = $v['change_time'] + $v['toff']; $change[] = $v; } } $this->addItem($change); $this->output(); }
public function update($id, $add_info, $channel, $stream_info, $server) { $stream_id = $stream_info['id']; $server_info = $server['server_info']; // if ($server_info['core_in_host']) { //主控 $core_host_input = $server_info['core_in_host'] . ':' . $server_info['core_in_port']; $core_apidir_input = $server_info['input_dir']; //时移 if ($server_info['is_dvr_output']) { $dvr_host_output = $server_info['dvr_in_host'] . ':' . $server_info['dvr_in_port']; } else { $dvr_host_output = $core_host_input; } $dvr_apidir_output = $server_info['output_dir']; } else { //主控 $core_host_input = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['core_input_server']['port']; $core_apidir_input = $this->settings['wowza']['core_input_server']['input_dir']; //时移 if ($this->settings['wowza']['dvr_output_server']) { $dvr_host_output = $this->settings['wowza']['dvr_output_server']['host'] . ':' . $this->settings['wowza']['dvr_output_server']['port']; } else { $dvr_host_output = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['core_input_server']['port']; } $dvr_apidir_output = $this->settings['wowza']['core_input_server']['output_dir']; } if ($this->mLive) { if ($server_info['is_live_output']) { $live_host_output = $server_info['live_in_host'] . ':' . $server_info['live_in_port']; $live_apidir_output = $server_info['output_dir']; } else { $live_host_output = $this->settings['wowza']['live_output_server']['host'] . ':' . $this->settings['wowza']['live_output_server']['port']; $live_apidir_output = $this->settings['wowza']['live_output_server']['output_dir']; } } // $ret_select = $this->mLivemms->outputApplicationSelect($dvr_host_output, $dvr_apidir_output); if (!$ret_select) { return -55; //媒体服务器未启动 } $tpl_stream_name = $add_info['stream_name']; $tpl_stream_name_index = array(); if (!empty($tpl_stream_name)) { foreach ($tpl_stream_name as $k => $v) { $tpl_stream_name_index[$v] = $v; } } $stream_state = $channel['stream_state']; $sql = "SELECT * FROM " . DB_PREFIX . "channel_stream WHERE channel_id = " . $id . " ORDER BY id ASC"; $q = $this->db->query($sql); $channel_stream_name = $channel_stream_info = $channel_stream_info_index = $channel_stream_name_index = array(); while ($row = $this->db->fetch_array($q)) { $channel_stream_info[] = $row; $channel_stream_name[] = $row['stream_name']; $channel_stream_info_index[$row['stream_name']] = $row; $channel_stream_name_index[$row['stream_name']] = $row['stream_name']; } $type = $stream_info['type']; //是否是文件流 $stream_other_info = @unserialize($stream_info['other_info']); $input_info = $stream_other_info['input']; if (!empty($input_info)) { $input_stream_name = $input_stream_name_index = array(); foreach ($input_info as $k => $v) { $input_stream_name[] = $v['name']; $input_stream_name_index[$v['name']] = $v['name']; } } //input_info 和 channel_stream 差集 $diff_inputInfo_channelStream = @array_diff($input_stream_name, $channel_stream_name); //tpl_stream_name 和 input_info 差集 $diff_tpl_inputInfo_name = @array_diff($input_stream_name, $tpl_stream_name); $diff_tpl_inputInfo_name_index = @array_diff($input_stream_name_index, $tpl_stream_name_index); //tpl_stream_name 和 channel_stream 差集 $tpl_channelStream_name = @array_diff($tpl_stream_name, $channel_stream_name); $tpl_channelStream_name_index = @array_diff($tpl_stream_name_index, $channel_stream_name_index); if (empty($tpl_channelStream_name_index)) { $tpl_channelStream_name_index = @array_diff($channel_stream_name_index, $tpl_stream_name_index); } $channelStream_tpl_name_index = @array_diff($channel_stream_name_index, $tpl_stream_name_index); if (!empty($input_info)) { //信号流 频道信号 组合的数据 $inputInfo_channelStream_data = array(); $inputInfo_channelStream_tpl_data = array(); foreach ($input_info as $k => $v) { if (!empty($channel_stream_info)) { foreach ($channel_stream_info as $kk => $vv) { if ($v['name'] == $vv['stream_name']) { $inputInfo_channelStream_data[$k]['input'] = $v; $inputInfo_channelStream_data[$k]['channel_stream'] = $vv; } if ($v['name'] == $diff_inputInfo_channelStream[$k]) { $inputInfo_channelStream_data[$k]['input'] = $v; $inputInfo_channelStream_data[$k]['channel_stream'] = array(); } if ($vv['stream_name'] == $diff_tpl_inputInfo_name[$k]) { $inputInfo_channelStream_tpl_data[$k]['input'] = $v; $inputInfo_channelStream_tpl_data[$k]['channel_stream'] = $vv; } } } } } if (!empty($inputInfo_channelStream_data)) { //用于更新数据 $update_data = array(); foreach ($inputInfo_channelStream_data as $k => $v) { if ($tpl_stream_name[$k] == $v['input']['name']) { $update_data[$k] = $v; } } } if (empty($inputInfo_channelStream_data)) { $update_data = array(); if (!empty($input_info)) { foreach ($input_info as $k => $v) { if ($tpl_stream_name[$k] == $v['name']) { $update_data[$k]['input'] = $v; $update_data[$k]['channel_stream'] = array(); } } } } $outputType = 0; if ($add_info['open_ts']) { $outputType = 3; } else { $outputType = 1; } $length = $add_info['save_time'] * 3600; //时移时间 $delay = $add_info['live_delay']; //延时时间 $drm = $add_info['drm']; //防盗链 //输出层 // $appName_output = $channel['code']; $appName_output = $add_info['code']; if ($appName_output != $channel['code'] || $add_info['save_time'] != $channel['save_time'] || $add_info['open_ts'] != $channel['open_ts'] || $channel['drm'] != $add_info['drm']) { $ret_app_output = $this->mLivemms->outputApplicationUpdate($dvr_host_output, $dvr_apidir_output, $channel['ch_id'], $appName_output, $length, $drm, $outputType); if ($ret_app_output['head']) { return $ret_app_output; } if (!$ret_app_output['result']) { return -20; //时移输出层应用更新失败 } if ($channel['stream_state']) { $stream_state = 0; } //live if ($this->mLive) { $_ret_app_output = $this->mLivemms->outputApplicationUpdate($live_host_output, $live_apidir_output, $channel['ch_id'], $appName_output, 0, $drm, $outputType); if (!$_ret_app_output['result']) { return -200; //直播输出层应用更新失败 } } } //stream_id 不变的情况下 if ($stream_id == $channel['stream_id']) { if (!empty($inputInfo_channelStream_tpl_data)) { foreach ($inputInfo_channelStream_tpl_data as $k => $v) { //延时层 if ($channel['live_delay']) { $ret_delay = $this->mLivemms->inputDelayOperate($core_host_input, $core_apidir_input, 'delete', $v['channel_stream']['delay_stream_id']); } //切播层 $ret_chg = $this->mLivemms->inputChgStreamOperate($core_host_input, $core_apidir_input, 'delete', $v['channel_stream']['chg_stream_id']); //输出层 $ret_output = $this->mLivemms->outputStreamOperate($dvr_host_output, $dvr_apidir_output, 'delete', $v['channel_stream']['out_stream_id']); //live if ($this->mLive) { $_ret_output = $this->mLivemms->outputStreamOperate($live_host_output, $live_apidir_output, 'delete', $v['channel_stream']['out_stream_id']); } //删除channel_stream if ($ret_output['result']) { $sql = "DELETE FROM " . DB_PREFIX . "channel_stream WHERE id = " . $v['channel_stream']['id']; $this->db->query($sql); } } } } else { if (!empty($channel_stream_info_index)) { foreach ($channel_stream_info_index as $k => $v) { if ($tpl_channelStream_name_index[$k] == $v['stream_name'] || $diff_tpl_inputInfo_name_index[$k] == $v['stream_name'] || $channelStream_tpl_name_index[$k] == $v['stream_name']) { //延时层 if ($channel['live_delay']) { $ret_delay = $this->mLivemms->inputDelayOperate($core_host_input, $core_apidir_input, 'delete', $v['delay_stream_id']); } //切播层 $ret_chg = $this->mLivemms->inputChgStreamOperate($core_host_input, $core_apidir_input, 'delete', $v['chg_stream_id']); //输出层 $ret_output = $this->mLivemms->outputStreamOperate($dvr_host_output, $dvr_apidir_output, 'delete', $v['out_stream_id']); //live if ($this->mLive) { $_ret_output = $this->mLivemms->outputStreamOperate($live_host_output, $live_apidir_output, 'delete', $v['out_stream_id']); } //删除channel_stream if ($ret_output['result']) { $sql = "DELETE FROM " . DB_PREFIX . "channel_stream WHERE id = " . $v['id']; $this->db->query($sql); } } } } } //更新数据 if (!empty($update_data)) { $data_channel_stream = $ret_delay_id = $ret_chg_id = $ret_out_id = array(); foreach ($update_data as $k => $v) { if (empty($v['channel_stream'])) { if ($delay) { //延时层 $ret_delay = $this->mLivemms->inputDelayInsert($core_host_input, $core_apidir_input, $v['input']['id'], $delay); $ret_delay_id[$k] = $ret_delay['delay']['id']; if (!$ret_delay_id[$k]) { continue; } $sourceId = $ret_delay_id[$k]; $sourceType = 2; /* //重启流 if (!$channel['stream_state'] && $ret_delay_id[$k]) { $ret_stream_delay = $this->mLivmms->inputDelayOperate('stop', $ret_delay_id[$k]); } else { $ret_stream_delay = $this->mLivmms->inputDelayOperate('start', $ret_delay_id[$k]); } if (!$ret_stream_delay['result']) { continue; } */ } else { $sourceId = $v['input']['id']; $sourceType = !$type ? 1 : 3; } //切播层 $ret_chg = $this->mLivemms->inputChgStreamInsert($core_host_input, $core_apidir_input, $sourceId, $sourceType); $ret_chg_id[$k] = $ret_chg['output']['id']; if (!$ret_chg_id[$k]) { continue; } /* //重启流 if (!$channel['stream_state'] && $ret_chg_id[$k]) { $ret_stream_chg = $this->mLivmms->inputChgStreamOperate('stop', $ret_chg_id[$k]); } else { $ret_stream_chg = $this->mLivmms->inputChgStreamOperate('start', $ret_chg_id[$k]); } if (!$ret_stream_chg['result']) { continue; } */ //输出层 if ($server_info['core_in_host']) { $wowzaip_chg = $server_info['core_in_host'] . ':' . $server_info['core_out_port']; } else { $wowzaip_chg = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['out_port']; } $appName_chg = $this->settings['wowza']['chg']['app_name']; $streamName_chg = $ret_chg_id[$k] . $this->settings['wowza']['chg']['suffix']; $chg_url = hg_streamUrl($wowzaip_chg, $appName_chg, $streamName_chg); $ret_output = $this->mLivemms->outputStreamInsert($dvr_host_output, $dvr_apidir_output, 0, $channel['ch_id'], $v['input']['name'], $chg_url); $ret_out_id[$k] = $ret_output['stream']['id']; //live if ($this->mLive) { $_ret_output = $this->mLivemms->outputStreamInsert($live_host_output, $live_apidir_output, $ret_out_id[$k], $channel['ch_id'], $v['input']['name'], $chg_url); } if ($ret_output['result']) { /* //重启流 if (!$channel['stream_state'] && $ret_out_id[$k]) { $ret_stream_output = $this->mLivmms->outputStreamOperate('stop', $ret_out_id[$k]); } else { $ret_stream_output = $this->mLivmms->outputStreamOperate('start', $ret_out_id[$k]); } if (!$ret_stream_output['result']) { continue; } */ $data_channel_stream[$k] = array('channel_id' => $id, 'stream_id' => $stream_id, 'delay_stream_id' => $ret_delay_id[$k], 'chg_stream_id' => $ret_chg_id[$k], 'out_stream_id' => $ret_out_id[$k], 'stream_name' => $v['input']['name'], 'out_stream_name' => $v['input']['name'], 'is_main' => $k == 0 ? 1 : 0, 'bitrate' => $v['input']['bitrate'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip()); $sql = "INSERT INTO " . DB_PREFIX . "channel_stream SET "; $space = ""; foreach ($data_channel_stream[$k] as $key => $value) { $sql .= $space . $key . "=" . "'" . $value . "'"; $space = ","; } $this->db->query($sql); } } else { if ($delay) { //延时层 if ($delay == $channel['live_delay'] && $stream_id == $channel['stream_id']) { $ret_delay_id[$k] = $v['channel_stream']['delay_stream_id']; } else { if ($v['channel_stream']['delay_stream_id']) { $ret_delay_delete = $this->mLivemms->inputDelayOperate($core_host_input, $core_apidir_input, 'delete', $v['channel_stream']['delay_stream_id']); if (!$ret_delay_delete['result']) { continue; } } $ret_delay = $this->mLivemms->inputDelayInsert($core_host_input, $core_apidir_input, $v['input']['id'], $delay); $ret_delay_id[$k] = $ret_delay['delay']['id']; if (!$ret_delay_id[$k]) { continue; } /* //重启流 if (!$channel['stream_state'] && $ret_delay_id[$k]) { $ret_stream_delay = $this->mLivmms->inputDelayOperate('stop', $ret_delay_id[$k]); } else { $ret_stream_delay = $this->mLivmms->inputDelayOperate('start', $ret_delay_id[$k]); } if (!$ret_stream_delay['result']) { continue; } */ } /* //重启流 if (!$channel['stream_state'] && $ret_delay_id[$k]) { $ret_stream_delay = $this->mLivmms->inputDelayOperate('stop', $ret_delay_id[$k]); } else { $ret_stream_delay = $this->mLivmms->inputDelayOperate('start', $ret_delay_id[$k]); } if (!$ret_stream_delay['result']) { continue; } */ $sourceId = $ret_delay_id[$k]; $sourceType = 2; } else { //删除延时层 if ($channel['live_delay']) { if ($v['channel_stream']['delay_stream_id']) { $ret_delay_delete = $this->mLivemms->inputDelayOperate($core_host_input, $core_apidir_input, 'delete', $v['channel_stream']['delay_stream_id']); if (!$ret_delay_delete['result']) { continue; } } $ret_delay_id[$k] = 0; } $sourceId = $v['input']['id']; $sourceType = !$type ? 1 : 3; } //切播层 $chgId = $v['channel_stream']['chg_stream_id']; $ret_chg = $this->mLivemms->inputChgStreamUpdate($core_host_input, $core_apidir_input, $chgId, $sourceId, $sourceType); if (!$ret_chg['result']) { continue; } /* //重启流 if (!$channel['stream_state'] && $chgId) { $ret_stream_chg = $this->mLivmms->inputChgStreamOperate('stop', $chgId); } else { $ret_stream_chg = $this->mLivmms->inputChgStreamOperate('start', $chgId); } if (!$ret_stream_chg['result']) { continue; } */ //输出层 $ret_chg_id[$k] = $chgId; //输出层 if ($server_info['core_in_host']) { $wowzaip_chg = $server_info['core_in_host'] . ':' . $server_info['core_out_port']; } else { $wowzaip_chg = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['out_port']; } $appName_chg = $this->settings['wowza']['chg']['app_name']; $streamName_chg = $ret_chg_id[$k] . $this->settings['wowza']['chg']['suffix']; $chg_url = hg_streamUrl($wowzaip_chg, $appName_chg, $streamName_chg); $ret_output = $this->mLivemms->outputStreamUpdate($dvr_host_output, $dvr_apidir_output, $v['channel_stream']['out_stream_id'], $channel['ch_id'], $v['channel_stream']['stream_name'], $chg_url); //live if ($this->mLive) { $_ret_output = $this->mLivemms->outputStreamUpdate($live_host_output, $live_apidir_output, $v['channel_stream']['out_stream_id'], $channel['ch_id'], $v['channel_stream']['stream_name'], $chg_url); } if ($ret_output['result']) { /* //重启流 if (!$channel['stream_state'] && $v['channel_stream']['out_stream_id']) { $ret_stream_output = $this->mLivmms->outputStreamOperate('stop', $v['channel_stream']['out_stream_id']); } else { $ret_stream_output = $this->mLivmms->outputStreamOperate('start', $v['channel_stream']['out_stream_id']); } if (!$ret_stream_output['result']) { continue; } */ $data_channel_stream[$k] = array('stream_id' => $stream_id, 'delay_stream_id' => $ret_delay_id[$k] ? $ret_delay_id[$k] : '00', 'stream_name' => $v['channel_stream']['stream_name'], 'out_stream_name' => $v['channel_stream']['stream_name'], 'is_main' => $k == 0 ? 1 : 0, 'bitrate' => $v['channel_stream']['bitrate'], 'update_time' => TIMENOW); $sql = "UPDATE " . DB_PREFIX . "channel_stream SET "; $space = ""; $sql_extra = ""; foreach ($data_channel_stream[$k] as $key => $value) { if ($value) { $sql_extra .= $space . $key . "=" . "'" . $value . "'"; $space = ","; } } if ($sql_extra) { $sql .= $sql_extra . " WHERE id=" . $v['channel_stream']['id']; $this->db->query($sql); } } } } } $data = array('name' => $add_info['name'], 'code' => $add_info['code'], 'stream_state' => 0, 'drm' => $add_info['drm'], 'open_ts' => $add_info['open_ts'], 'uri_in_num' => count($tpl_stream_name), 'uri_out_num' => count($tpl_stream_name), 'save_time' => $add_info['save_time'], 'live_delay' => $add_info['live_delay'], 'stream_mark' => $stream_info['ch_name'], 'stream_id' => $stream_id, 'main_stream_name' => $tpl_stream_name[0], 'stream_info_all' => @serialize($tpl_stream_name), 'audio_only' => $input_info[0]['audio_only'], 'update_time' => TIMENOW); //发布开始 $channel['column_id'] = @unserialize($channel['column_id']); $ori_column_id = array(); if (is_array($channel['column_id'])) { $ori_column_id = @array_keys($channel['column_id']); } $data['column_id'] = $this->publish_column->get_columnname_by_ids('id,name', $add_info['column_id']); $data['column_id'] = serialize($data['column_id']); //发布结束 //获取发布前数据 $sql_ = "SELECT * FROM " . DB_PREFIX . "channel WHERE id = " . $id; $pre_data = $this->db->query_first($sql_); $sql = "UPDATE " . DB_PREFIX . "channel SET "; $space = ""; foreach ($data as $key => $value) { $sql .= $space . $key . "=" . "'" . $value . "'"; $space = ","; } $sql .= " WHERE id = " . $id; $this->db->query($sql); $data['id'] = $id; if ($_FILES['files']['tmp_name']) { $file['Filedata'] = $_FILES['files']; $material = $this->mMaterial->addMaterial($file, $data['id']); $logo_info['id'] = $material['id']; $logo_info['type'] = $material['type']; $logo_info['host'] = $material['host']; $logo_info['dir'] = $material['dir']; $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 = " . $data['id']; $this->db->query($sql); } if ($_FILES['files_mobile']['tmp_name']) { $file['Filedata'] = $_FILES['files_mobile']; $material_mobile = $this->mMaterial->addMaterial($file, $data['id']); $logo_mobile_info['id'] = $material_mobile['id']; $logo_mobile_info['type'] = $material_mobile['type']; $logo_mobile_info['host'] = $material_mobile['host']; $logo_mobile_info['dir'] = $material_mobile['dir']; $logo_mobile_info['filepath'] = $material_mobile['filepath']; $logo_mobile_info['name'] = $material_mobile['name']; $logo_mobile_info['filename'] = $material_mobile['filename']; $logo_mobile_info['url'] = $material_mobile['url']; $sql = "UPDATE " . DB_PREFIX . "channel SET logo_mobile_info = '" . serialize($logo_mobile_info) . "' WHERE id = " . $data['id']; $this->db->query($sql); } /* //重启application if (!$channel['stream_state']) { $this->mLivmms->outputApplicationOperate('stop', $channel['ch_id']); } else { $this->mLivmms->outputApplicationOperate('start', $channel['ch_id']); } */ if ($data['id']) { //发布开始 $sql = "SELECT * FROM " . DB_PREFIX . "channel WHERE id = " . $data['id']; $ret = $this->db->query_first($sql); //更改文章后发布的栏目 $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($ret['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); } //发布结束 $this->addLogs('更新直播频道', $pre_data, $data, '', '', $data['name']); return $data; } return false; }
public function show_opration() { $id = urldecode($this->input['id']); $info = $this->mStream->detail($id); if ($info['server_id']) { $server_id = $info['server_id']; $server_info = $this->mServerConfig->get_server_config_by_id($server_id); // $server_output = $this->mServerConfig->get_server_output_by_id($server_id); } $info['server_name'] = $server_info['name']; $info['stream_info'] = array(); if ($info['other_info']) { $stream_info = array(); foreach ($info['other_info']['input'] as $k => $v) { if ($server_info['core_in_host']) { $wowzaip = $server_info['core_in_host']; } else { $wowzaip = $this->settings['wowza']['core_input_server']['host']; } $suffix = !$info['type'] ? $this->settings['wowza']['input']['suffix'] : $this->settings['wowza']['list']['suffix']; $app_name = $this->settings['wowza']['input']['app_name']; $stream_info[$k]['id'] = $v['id']; $stream_info[$k]['name'] = $v['name']; $stream_info[$k]['input_url'] = $v['uri']; $stream_info[$k]['output_url'] = hg_streamUrl($wowzaip, $app_name, $v['id'] . $suffix); $stream_info[$k]['backup_name'] = $v['backup_title'] ? implode(',', $v['backup_title']) : ''; $stream_info[$k]['bitrate'] = $v['bitrate']; } } $info['stream_info'] = $stream_info; unset($info['other_info']); $this->addItem($info); $this->output(); }
function setSourceInfo($channel2_id, $type, $server_info) { $channel_id = $file_id = $stream_id = array(); foreach ($channel2_id as $i => $id) { if ($type[$i] == 2) { $file_id[] = $id; } elseif ($type[$i] == 4) { $stream_id[] = $id; } else { $channel_id[] = $id; } } if ($channel_id && $type[$i]) { $condition = " WHERE c.id IN(" . implode(',', $channel_id) . ")"; $sql = "SELECT c.id, c.code, c.stream_id, c.live_delay, s.other_info, s.type FROM " . DB_PREFIX . "channel c LEFT JOIN " . DB_PREFIX . "stream s ON c.stream_id=s.id " . $condition; $q = $this->db->query($sql); $channel = array(); while ($row = $this->db->fetch_array($q)) { $row['other_info'] = @unserialize($row['other_info']); $channel[$row['id']] = $row; } $sql = "SELECT id, channel_id, out_stream_name, delay_stream_id, chg_stream_id, out_stream_id, stream_name FROM " . DB_PREFIX . "channel_stream WHERE channel_id IN (" . implode(',', $channel_id) . ")"; $q = $this->db->query($sql); $channel_stream = array(); while ($row = $this->db->fetch_array($q)) { $channel_stream[$row['channel_id']]['channel_stream'][] = $row; } $channel_info = array(); if (!empty($channel)) { foreach ($channel as $k => $v) { if ($channel_stream[$k]) { $channel_info[$k] = @array_merge($channel[$k], $channel_stream[$k]); } else { $channel_info[$k] = $channel[$k]; } } } } //备播信号 if ($stream_id && $type[$i]) { $sql = "SELECT id, ch_name, type, audio_only, other_info FROM " . DB_PREFIX . "stream WHERE id IN (" . implode(',', $stream_id) . ")"; $q = $this->db->query($sql); $stream = array(); while ($row = $this->db->fetch_array($q)) { $row['other_info'] = unserialize($row['other_info']); $stream[$row['id']] = $row; } } if ($file_id) { $sql = "SELECT id, fileid, toff FROM " . DB_PREFIX . "backup WHERE id IN(" . implode(',', $file_id) . ")"; $f = $this->db->query($sql); $backup = array(); while ($row = $this->db->fetch_array($f)) { /* if ($row['fileid']) { $ret_list = $this->mLivmms->inputFileListInsert($row['fileid']); if (!$ret_list['result']) { continue; } $row['list_fileid'] = $ret_list['list']['id']; } */ $backup[$row['id']] = $row; } } foreach ($channel2_id as $i => $id) { if ($type[$i] == 2) { $this->mSourceId[$i] = $backup[$id]['fileid']; $this->mSourceType[$i] = 3; $this->mFileToff[$i] = $backup[$id]['toff']; } elseif ($type[$i] == 4) { $this->mSourceId[$i] = $stream[$id]['other_info']['input'][0]['id']; $this->mSourceType[$i] = $stream[$id]['type'] ? 3 : 1; } elseif ($type[$i] == 3) { if ($server_info['core_in_host']) { if ($server_info['is_dvr_output']) { $wowzaip = $server_info['dvr_in_host'] . ':' . $server_info['dvr_in_port']; } else { $wowzaip = $server_info['core_in_host'] . ':' . $server_info['core_in_port']; } } else { if ($this->settings['wowza']['dvr_output_server']) { $wowzaip = $this->settings['wowza']['dvr_output_server']['host'] . ':' . $this->settings['wowza']['out_port']; } else { $wowzaip = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['out_port']; } } $suffix = $this->settings['wowza']['dvr_output']['suffix']; $this->mSourceId[$i] = hg_streamUrl($wowzaip, $channel_info[$id]['code'], $channel_info[$id]['channel_stream'][0]['out_stream_name'] . $suffix, 'm3u8'); $this->mSourceType[$i] = 3; } else { if ($channel_info[$id]['live_delay']) { $this->mSourceId[$i] = $channel_info[$id]['channel_stream'][0]['delay_stream_id']; $this->mSourceType[$i] = 2; } else { $this->mSourceId[$i] = $channel_info[$id]['other_info']['input'][0]['id']; $this->mSourceType[$i] = 1; } $this->mFileToff[$i] = 0; } } return true; }
/** * 获取所有备播文件 * @name get_all_beibo_files * @access public * @author lijiaying * @category hogesoft * @copyright hogesoft * @return $r array 所有备播文件信息 */ public function get_all_beibo_files() { $sql = "SELECT * FROM " . DB_PREFIX . "backup WHERE 1 ORDER BY id DESC "; $q = $this->db->query($sql); while ($r = $this->db->fetch_array($q)) { $r['beibo_file_url'] = hg_streamUrl($this->settings['mms']['file']['wowzaip'], $this->settings['mms']['file']['appName'], $r['videofilename'], ''); if ($r['toff']) { if (intval($r['toff'] / 1000 / 60)) { $r['toff'] = intval($r['toff'] / 1000 / 60) . "'" . intval(($r['toff'] / 1000 / 60 - intval($r['toff'] / 1000 / 60)) * 60) . '"'; } else { $r['toff'] = intval($r['toff'] / 1000) . '"'; } } $r['img'] = SOURCE_THUMB_PATH . $r['img']; $this->addItem($r); } $this->output(); }
function show() { $id = $this->input['channel_id']; if ($id) { $condition = " AND id IN (" . $id . ")"; } $sql = "SELECT id, main_stream_name, code, server_id FROM " . DB_PREFIX . "channel "; $sql .= " WHERE stream_state=1 AND audio_only=0 " . $condition; $q = $this->db->query($sql); $channels = $server_id = array(); while ($r = $this->db->fetch_array($q)) { $server_id[] = $r['server_id']; $channels[$r['id']] = $r; } //服务器配置 if (!empty($server_id)) { $server_id = implode(',', @array_unique($server_id)); $server_infos = $this->mServerConfig->get_server_config($server_id); } $sql = "SELECT channel_id, out_stream_id, stream_name FROM " . DB_PREFIX . "channel_stream WHERE channel_id IN(" . implode(',', @array_keys($channels)) . ")"; $q = $this->db->query($sql); $streams = array(); while ($row = $this->db->fetch_array($q)) { $streams[$row['channel_id']][$row['stream_name']] = $row; } foreach ($channels as $k => $v) { $server_info = $server_infos[$v['server_id']]; if ($server_info['core_in_host']) { if ($server_info['is_dvr_output']) { $wowzaip = $server_info['dvr_in_host'] . ':' . $server_info['dvr_out_port']; } else { $wowzaip = $server_info['core_in_host'] . ':' . $server_info['core_out_port']; } } else { if ($this->settings['wowza']['dvr_output_server']) { $wowzaip = $this->settings['wowza']['dvr_output_server']['host'] . ':' . $this->settings['wowza']['out_port']; } else { $wowzaip = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['out_port']; } } $suffix = $this->settings['wowza']['dvr_output']['suffix']; if ($this->mLive) { if ($server_info['is_live_output']) { $wowzaip = $server_info['live_in_host'] . ':' . $server_info['live_out_port']; } else { $wowzaip = $this->settings['wowza']['live_output_server']['host'] . ':' . $this->settings['wowza']['out_port']; } $suffix = $this->settings['wowza']['live_output']['suffix']; } $streamurl = hg_streamUrl($wowzaip, $v['code'], $v['main_stream_name'] . $suffix); $this->mediaserver->initPostData(); $this->mediaserver->setSubmitType('post'); $this->mediaserver->addRequestData('channel_id', $k); $this->mediaserver->addRequestData('a', 'startsnap'); $this->mediaserver->addRequestData('stream_uri', $streamurl); $this->mediaserver->addRequestData('interval', $this->settings['channel_snap_interval']); $ret = $this->mediaserver->request('livesnap.php'); $this->additem($ret[0]); } $this->output(); }
/** * dvr检测接口 * 如果dvr不存在且流是开启的 则重启并且记录 * Enter description here ... */ function dvr_checked() { $channel_info = $this->mDvrCheckedLog->get_channel_stream_info(); $ret = array(); if (!empty($channel_info)) { $server_id = array(); foreach ($channel_info as $v) { $server_id[] = $v['server_id']; } //服务器配置 if (!empty($server_id)) { $server_id = implode(',', @array_unique($server_id)); $server_infos = $this->mServerConfig->get_server_config($server_id); } foreach ($channel_info as $v) { $server_info = $server_infos[$v['server_id']]; if ($server_info['core_in_host']) { if ($server_info['is_dvr_output']) { $wowzaip = $server_info['dvr_in_host'] . ':' . $server_info['dvr_out_port']; } else { $wowzaip = $server_info['core_in_host'] . ':' . $server_info['core_out_port']; } } else { if ($this->settings['wowza']['dvr_output_server']) { $wowzaip = $this->settings['wowza']['dvr_output_server']['host'] . ':' . $this->settings['wowza']['out_port']; } else { $wowzaip = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['out_port']; } } $suffix = $this->settings['wowza']['dvr_output']['suffix']; $v['out_url'] = $v['stream_name'] ? hg_streamUrl($wowzaip, $v['code'], $v['stream_name'] . $suffix, 'flv', '', 'dvr') : ''; $ret[$v['id']]['channel_id'] = $v['channel_id']; $ret[$v['id']]['name'] = $v['name']; $ret[$v['id']]['code'] = $v['code']; $ret[$v['id']]['stream_name'] = $v['stream_name']; $ret[$v['id']]['out_url'] = $v['out_url']; $ret[$v['id']]['status'] = 1; // $time = microtime(true); if (!$v['out_url']) { $ret[$v['id']]['status'] = 0; continue; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $v['out_url']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 2); curl_exec($ch); $head_info = curl_getinfo($ch); curl_close($ch); // $ret[$v['id']]['time'] = microtime(true) - $time; if ($head_info['http_code'] != 200) { if ($server_info['core_in_host']) { $host = $server_info['core_in_host'] . ':' . $server_info['core_in_port']; $apidir_input = $server_info['input_dir']; $apidir_output = $server_info['output_dir']; if ($server_info['is_dvr_output']) { $dvr_host = $server_info['dvr_in_host'] . ':' . $server_info['dvr_in_port']; } else { $dvr_host = $host; } } else { $host = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['core_input_server']['port']; $apidir_input = $this->settings['wowza']['core_input_server']['input_dir']; $apidir_output = $this->settings['wowza']['core_input_server']['output_dir']; if ($this->settings['dvr_output_server']) { $dvr_host = $this->settings['dvr_output_server']['host'] . ':' . $this->settings['dvr_output_server']['port']; } else { $dvr_host = $host; } } $ret[$v['id']]['status'] = 0; //停止 //延时层 if ($v['delay_stream_id']) { $ret_delay = $this->mLivemms->inputDelayOperate($host, $apidir_input, 'stop', $v['delay_stream_id']); } //切播层 if ($v['chg_stream_id']) { $ret_chg = $this->mLivemms->inputChgStreamOperate($host, $apidir_input, 'stop', $v['chg_stream_id']); } //输出层 if ($v['out_stream_id']) { $ret_output = $this->mLivemms->outputStreamOperate($dvr_host, $apidir_output, 'stop', $v['out_stream_id']); } sleep($this->settings['dvr_sleep_time']); //启动 //延时层 if ($v['delay_stream_id']) { $ret_delay = $this->mLivemms->inputDelayOperate($host, $apidir_input, 'start', $v['delay_stream_id']); } //切播层 if ($v['chg_stream_id']) { $ret_chg = $this->mLivemms->inputChgStreamOperate($host, $apidir_input, 'start', $v['chg_stream_id']); } //输出层 if ($v['out_stream_id']) { $ret_output = $this->mLivemms->outputStreamOperate($dvr_host, $apidir_output, 'start', $v['out_stream_id']); } //记录数据 $add_input = array('channel_stream_id' => $v['id'], 'channel_id' => $v['channel_id'], 'name' => $v['name'], 'code' => $v['code'], 'stream_id' => $v['stream_id'], 'server_id' => $v['server_id'], 'stream_name' => $v['stream_name'], 'delay_stream_id' => $v['delay_stream_id'], 'chg_stream_id' => $v['chg_stream_id'], 'out_stream_id' => $v['out_stream_id'], 'create_time' => TIMENOW); $ret_input = $this->mDvrCheckedLog->create($add_input); } } } $this->addItem($ret); $this->output(); }
function show() { $this->channel_id = $this->input['channel_id']; $sql = "SELECT t1.*, t2.core_in_host, t2.core_out_port, t2.is_dvr_output, t2.dvr_in_host, t2.dvr_out_port FROM " . DB_PREFIX . "channel t1 "; $sql .= " LEFT JOIN " . DB_PREFIX . "server_config t2 ON t2.id = t1.server_id "; if ($this->channel_id == 'latest') { $sql .= " WHERE 1 AND t1.stream_state "; $sql .= " ORDER BY t1.id DESC LIMIT 1"; } else { $sql .= " WHERE t1.id = " . intval($this->channel_id); } $channel_info = $this->db->query_first($sql); $this->channel_id = intval($channel_info['id']); if (!$this->channel_id) { $this->errorOutput(OBJECT_NULL); } $play_time = $this->input['play_time'] ? $this->input['play_time'] : 0; //是当前要播放的时间,我不想改了 $info = array(); if (!$channel_info) { $this->errorOutput(OBJECT_NULL); } if ($channel_info['logo_info']) { $channel_info['logo_info'] = @unserialize($channel_info['logo_info']); $channel_info['logo']['rectangle']['host'] = $channel_info['logo_info']['host']; $channel_info['logo']['rectangle']['dir'] = $channel_info['logo_info']['dir']; $channel_info['logo']['rectangle']['filepath'] = $channel_info['logo_info']['filepath']; $channel_info['logo']['rectangle']['filename'] = $channel_info['logo_info']['filename']; } if ($channel_info['logo_mobile_info']) { $channel_info['logo_mobile_info'] = @unserialize($channel_info['logo_mobile_info']); $channel_info['logo']['square']['host'] = $channel_info['logo_mobile_info']['host']; $channel_info['logo']['square']['dir'] = $channel_info['logo_mobile_info']['dir']; $channel_info['logo']['square']['filepath'] = $channel_info['logo_mobile_info']['filepath']; $channel_info['logo']['square']['filename'] = $channel_info['logo_mobile_info']['filename']; } if ($channel_info['core_in_host']) { if ($channel_info['is_dvr_output']) { $wowzaip = $channel_info['dvr_in_host'] . ':' . $channel_info['dvr_out_port']; } else { $wowzaip = $channel_info['core_in_host'] . ':' . $channel_info['core_out_port']; } } else { if ($this->settings['wowza']['dvr_output_server']) { $wowzaip = $this->settings['wowza']['dvr_output_server']['host'] . ':' . $this->settings['wowza']['out_port']; } else { $wowzaip = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['out_port']; } } $suffix = $this->settings['wowza']['dvr_output']['suffix']; $channel_info['m3u8'] = hg_streamUrl($wowzaip, $channel_info['code'], $channel_info['main_stream_name'] . $suffix, 'm3u8', '', 'dvr'); if (!isset($this->input['zone'])) { $dates = $this->input['dates'] ? urldecode($this->input['dates']) : date('Y-m-d'); if ($play_time) { $dates = date('Y-m-d', $play_time); } } else { $zone = intval($this->input['zone']); if ($zone) { $dates = date('Y-m-d', strtotime($zone . ' day')); } else { $dates = date('Y-m-d'); } } $this->play_time = $play_time; $sql = "select id,channel_id,start_time,toff,theme,subtopic,type_id,dates,weeks,describes from " . DB_PREFIX . "program where channel_id=" . $this->channel_id . " AND dates='" . $dates . "' ORDER BY start_time ASC "; $q = $this->db->query($sql); $this->m = 0; $program_plan = $this->getPlan($dates); $program = array(); $start = strtotime($dates . " 00:00:00"); $end = strtotime($dates . " 23:59:59"); $com_time = 0; while ($row = $this->db->fetch_array($q)) { $start_time = $row['start_time']; $end_time = $row['start_time'] + $row['toff']; $display = $lave_time = $now_play = $zhi_play = 0; if (!$com_time && $start_time > $start) { $plan = $this->verify_plan($program_plan, $start, $start_time); if ($plan) { foreach ($plan as $k => $v) { $program[] = $v; } } else { $program[] = $this->getInfo($start, $start_time, $dates); } } if ($com_time && $com_time != $start_time) { $plan = $this->verify_plan($program_plan, $com_time, $start_time); if ($plan) { foreach ($plan as $k => $v) { $program[] = $v; } } else { $program[] = $this->getInfo($com_time, $start_time, $dates); } } if ($start_time < TIMENOW) { $display = 1; } if ($start_time < TIMENOW && $end_time > TIMENOW) { $zhi_play = 1; $lave_time = $end_time - TIMENOW; if (!$this->m && !$play_time) { $now_play = $this->m = 1; } } if ($play_time && $start_time <= $play_time && $end_time > $play_time) { $now_play = 1; $lave_time = 0; } $row['start'] = date("H:i", $start_time); $row['end'] = date("H:i", $end_time); $row['zhi_play'] = $zhi_play; $row['now_play'] = $now_play; $row['display'] = $display; $row['lave_time'] = $lave_time; $row['is_program'] = 1; if (!$row['theme']) { $row['theme'] = '精彩节目'; } $row['stime'] = date("H:i", $start_time); $com_time = $end_time; $program[] = $row; } if ($com_time && $com_time < $end) { $plan = $this->verify_plan($program_plan, $com_time, $end); if ($plan) { foreach ($plan as $k => $v) { $program[] = $v; } } else { $program[] = $this->getInfo($com_time, $end, $dates); } } if (empty($program)) { $this->m = 0; $program = $this->copy_program($start, $end); } /* include(CUR_CONF_PATH . 'lib/program_screen.class.php'); $this->screen = new programScreen(); $cond = " AND channel_id=" . $this->channel_id . " AND date='" . $dates . "'"; $screen = $this->screen->show($cond); if(!empty($program) && !empty($screen)) //处理屏蔽节目 { foreach($program as $k => $v) { if(!$v['new']) { $start_time = $v['start_time']; $end_time = $v['start_time'] + $v['toff']; foreach($screen as $key => $value) { if($value['start_time'] == $start_time && ($value['start_time']+$value['toff']) == $end_time) { $program[$k]['screen_id'] = $value['id']; return false; } else { if($value['start_time'] >= $start_time && $value['start_time'] < $end_time) { $program[$k]['screen_id'] = $value['id']; } if($value['start_time'] < $start_time) { if(($value['start_time']+$value['toff']) > $start_time) { $program[$k]['screen_id'] = $value['id']; } } } } } } } */ //屏蔽节目 $orderby = " ORDER BY start_time ASC "; $shield = $this->mProgramShield->show($this->channel_id, $dates, '', $orderby); foreach ($program as $key => $value) { $value['is_shield'] = 0; $value['end_time'] = $value['start_time'] + $value['toff']; if ($value['start_time'] < TIMENOW - $channel_info['save_time'] * 3600) { $value['display'] = 0; } else { //屏蔽 if (!empty($shield)) { foreach ($shield as $v) { $v['end_time'] = $v['start_time'] + $v['toff']; if ($v['end_time'] >= $value['end_time'] && $v['start_time'] < $value['end_time'] || $v['start_time'] < $value['end_time'] && $v['start_time'] >= $value['start_time'] || $value['start_time'] >= $v['start_time'] && $value['start_time'] < $v['end_time']) { $value['is_shield'] = 1; } } } } $value['channel_name'] = $channel_info['name']; $value['channel_logo'] = $channel_info['logo']; $value['channel_id'] = $channel_info['id']; $value['m3u8'] = $channel_info['m3u8'] . '&starttime=' . $value['start_time'] . '000'; $value['livem3u8'] = $channel_info['m3u8']; $value['m3u8'] .= '&duration=' . $value['toff'] . '000'; $this->addItem($value); } $this->output(); }
public function getBackupInfo($condition, $offset, $count, $width = '40', $height = '30') { $limit = " LIMIT " . $offset . " , " . $count; $orderby = " ORDER BY id DESC "; $sql = "SELECT id, vodinfo_id, title, img, status, toff, fileid, server_id FROM " . DB_PREFIX . "backup "; $sql .= " WHERE 1 " . $condition . $orderby . $limit; $q = $this->db->query($sql); $backup_info = $server_id = array(); while ($row = $this->db->fetch_array($q)) { $row['toff_s'] = $row['toff'] / 1000; $row['toff'] = time_format($row['toff']); $row['img'] = @unserialize($row['img']); if ($row['img']) { $imgsize = $width . 'x' . $height . '/'; $row['img'] = hg_material_link($row['img']['host'], $row['img']['dir'], $row['img']['filepath'], $row['img']['filename'], $imgsize); } $server_id[] = $row['server_id']; $backup_info[$row['id']] = $row; } //服务器配置 if (!empty($server_id)) { $server_id = implode(',', @array_unique($server_id)); $server_infos = $this->mServerConfig->get_server_config($server_id); } $return = array(); if (!empty($backup_info)) { foreach ($backup_info as $v) { if ($v['fileid']) { $server_info = $server_infos[$v['server_id']]; if ($server_info['core_in_host']) { $wowzaip = $server_info['core_in_host']; } else { $wowzaip = $this->settings['wowza']['core_input_server']['host']; } $app_name = $this->settings['wowza']['backup']['app_name']; $prefix = $this->settings['wowza']['backup']['prefix']; $midfix = $this->settings['wowza']['backup']['midfix']; $suffix = $this->settings['wowza']['backup']['suffix']; $v['file_uri'] = hg_streamUrl($wowzaip, $app_name, $prefix . $midfix . $v['fileid'] . $suffix); } $return[] = $v; } } return $return; }
/** * 同步时移服务器、直播服务器信息 * Enter description here ... */ public function sync_channel() { $offset = $this->input['offset'] ? intval($this->input['offset']) : 0; $count = $this->input['count'] ? intval($this->input['count']) : 40; $channel_info = $this->mSync->get_channel_info($offset, $count); if (empty($channel_info)) { $this->errorOutput('直播频道不存在或已被删除'); } $ret_app_info = $ret_application_id = $_ret_application_id = array(); $ret_app_error = $ret_app_msg = $_ret_app_msg = array(); foreach ($channel_info as $channel_id => $channel) { //application //时移 $application_id = $channel['ch_id']; $appName_output = $channel['code']; $length = $channel['save_time'] * 3600; $delay = $channel['live_delay']; $drm = $channel['drm']; $type = $channel['type']; $outputType = 0; if ($channel['open_ts']) { $outputType = 3; } else { $outputType = 1; } $ret_app_output = $this->mLivmms->outputApplicationInsert($application_id, $appName_output, $length, $drm, $outputType); if (!$ret_app_output['result']) { $ret_app_msg[$channel_id]['name'] = $channel['name']; $ret_app_msg[$channel_id]['code'] = $channel['code']; continue; } $ret_application_id[$channel_id] = $ret_app_output['application']['id']; // $ret_application_id[$channel_id] = $application_id; //live if ($this->mLive) { $_ret_app_output = $this->mLivmms->_outputApplicationInsert($application_id, $appName_output, 0, $drm, $outputType); if (!$_ret_app_output['result']) { $_ret_app_msg[$channel_id]['name'] = $channel['name']; $_ret_app_msg[$channel_id]['code'] = $channel['code']; continue; } $_ret_application_id[$channel_id] = $_ret_app_output['application']['id']; // $_ret_application_id[$channel_id] = $application_id; } //stream foreach ($channel['other_info']['input'] as $input_info) { $ret_delay_id = $ret_chg_id = $ret_out_id = $_ret_out_id = array(); $ret_delay_id_msg = $ret_chg_id_msg = $ret_out_id_msg = $_ret_out_id_msg = array(); foreach ($channel['channel_stream'] as $k => $channel_stream) { if ($input_info['name'] == $channel_stream['stream_name']) { /* //延时层 if ($delay) { $ret_delay = $this->mLivmms->inputDelayInsert($channel_stream['delay_stream_id'], $input_info['id'], $delay); $ret_delay_id[$k] = $ret_delay['delay']['id']; // $ret_delay_id[$k] = $channel_stream['delay_stream_id']; if (!$ret_delay['result']) { $ret_delay_id_msg[$k]['id'] = $channel_stream['delay_stream_id']; $ret_delay_id_msg[$k]['name'] = $channel_stream['stream_name']; continue; } $sourceId = $ret_delay_id[$k]; $sourceType = 2; } else { $sourceId = $input_info['id']; $sourceType = !$type ? 1 : 3; } //切播层 $ret_chg = $this->mLivmms->inputChgStreamInsert($channel_stream['chg_stream_id'], $sourceId, $sourceType); if (!$ret_chg['result']) { $ret_chg_id_msg[$k]['id'] = $channel_stream['chg_stream_id']; $ret_chg_id_msg[$k]['name'] = $channel_stream['stream_name']; continue; } $ret_chg_id[$k] = $ret_chg['output']['id']; // $ret_chg_id[$k] = $channel_stream['chg_stream_id']; */ //时移输出层流 $wowzaip_chg = $this->settings['mms']['chg']['wowzaip']; $appName_chg = $this->settings['mms']['chg']['appName']; $streamName_chg = $channel_stream['chg_stream_id'] . $this->settings['mms']['chg']['suffix']; $output_url = hg_streamUrl($wowzaip_chg, $appName_chg, $streamName_chg); $ret_output = $this->mLivmms->outputStreamInsert($channel_stream['out_stream_id'], $application_id, $channel_stream['stream_name'], $output_url); if (!$ret_output['result']) { $ret_out_id_msg[$k]['id'] = $channel_stream['out_stream_id']; $ret_out_id_msg[$k]['name'] = $channel_stream['stream_name']; continue; } $ret_out_id[$k] = $ret_output['stream']['id']; // $ret_out_id[$k] = $channel_stream['out_stream_id']; //live if ($this->mLive) { $_ret_output = $this->mLivmms->_outputStreamInsert($channel_stream['out_stream_id'], $application_id, $channel_stream['stream_name'], $output_url); if (!$_ret_output['result']) { $_ret_out_id_msg[$k]['id'] = $channel_stream['out_stream_id']; $_ret_out_id_msg[$k]['name'] = $channel_stream['stream_name']; continue; } $_ret_out_id[$k] = $_ret_output['stream']['id']; // $_ret_out_id[$k] = $channel_stream['out_stream_id']; } } } } $ret_app_info[$channel_id]['name'] = $channel['name']; $ret_app_info[$channel_id]['code'] = $channel['code']; $ret_app_info[$channel_id]['output']['application_id'] = $ret_application_id[$channel_id]; $ret_app_info[$channel_id]['output']['delay_stream_id'] = $ret_delay_id; $ret_app_info[$channel_id]['output']['chg_stream_id'] = $ret_chg_id; $ret_app_info[$channel_id]['output']['out_stream_id'] = $ret_out_id; $ret_app_error[$channel_id]['output']['application'] = $ret_app_msg[$channel_id]; $ret_app_error[$channel_id]['output']['delay_stream'] = $ret_delay_id_msg; $ret_app_error[$channel_id]['output']['chg_stream'] = $ret_chg_id_msg; $ret_app_error[$channel_id]['output']['out_stream'] = $ret_out_id_msg; //live if ($this->mLive) { $ret_app_info[$channel_id]['_output']['application_id'] = $_ret_application_id[$channel_id]; $ret_app_info[$channel_id]['_output']['out_stream_id'] = $_ret_out_id; $ret_app_error[$channel_id]['_output']['application'] = $_ret_app_msg[$channel_id]; $ret_app_error[$channel_id]['_output']['out_stream'] = $_ret_out_id_msg; } } //返回添加失败信息 $msg = $_msg = ''; if (!empty($ret_app_error)) { foreach ($ret_app_error as $channel_id => $channel) { $msg .= $channel['output']['application']['name'] . '[' . $channel['output']['application']['code'] . ']'; if ($channel['output']['delay_stream']) { $msg .= '{ delay:'; foreach ($channel['output']['delay_stream'] as $k => $stream) { $msg .= $stream['name'] . ' '; } $msg .= '},'; } if ($channel['output']['chg_stream']) { $msg .= '{ chg:'; foreach ($channel['output']['chg_stream'] as $k => $stream) { $msg .= $stream['name'] . ' '; } $msg .= '},'; } if ($channel['output']['out_stream']) { $msg .= '{ out:'; foreach ($channel['output']['out_stream'] as $k => $stream) { $msg .= $stream['name'] . ' '; } $msg .= '},'; } //live if ($this->mLive) { $_msg .= $channel['_output']['application']['name'] . '[' . $channel['_output']['application']['code'] . ']'; if ($channel['_output']['out_stream']) { $_msg .= '{ out:'; foreach ($channel['_output']['out_stream'] as $k => $stream) { $_msg .= $stream['name'] . ' '; } $_msg .= '},'; } } } } //返回添加成功信息 $ret = $_ret = ''; if (!empty($ret_app_info)) { foreach ($ret_app_info as $channel_id => $channel) { $ret .= $channel['name'] . '[' . $channel['code'] . ']' . ' '; //live if ($this->mLive) { $_ret .= $channel['name'] . '[' . $channel['code'] . ']' . ' '; } } } $return = array('output' => array('msg' => $msg, 'ret' => $ret)); if ($this->mLive) { $return['_output'] = array('msg' => $_msg, 'ret' => $_ret); } $this->addItem($return); $this->output(); }
/** * 检测直播线路 * $input 输入 * $delay 延时 * $chg 切播 * $output 时移输出 * $dvr dvr * $_output 直播输出 * $m3u8 时移手机 * $_m3u8 直播手机 * Enter description here ... */ function channel_checked() { $channel_id = $this->input['channel_id']; if (!$channel_id) { $this->errorOutput('未传入频道id'); } $type = $this->input['type']; $offset = $this->input['offset'] ? intval($this->input['offset']) : 0; $count = $this->input['count'] ? intval($this->input['count']) : 40; $condition = ' AND t1.id IN (' . $channel_id . ')'; $channel_info = $this->mSync->get_channel_info($offset, $count, $condition); if (empty($channel_info)) { $this->errorOutput('频道不存在或已被删除'); } $ret_channel = array(); foreach ($channel_info as $channel_id => $channel) { foreach ($channel['other_info']['input'] as $input_info) { $ret_channel_stream[] = array(); foreach ($channel['channel_stream'] as $k => $channel_stream) { if ($input_info['name'] == $channel_stream['stream_name']) { $ret_channel_stream[$k]['stream_name'] = $channel_stream['stream_name']; $ret_channel_stream[$k]['input_stream_id'] = $input_info['id']; $ret_channel_stream[$k]['delay_stream_id'] = $channel_stream['delay_stream_id']; $ret_channel_stream[$k]['chg_stream_id'] = $channel_stream['chg_stream_id']; $ret_channel_stream[$k]['out_stream_id'] = $channel_stream['out_stream_id']; if (!empty($channel['server_info'])) { //输入 $wowzaip_input = $channel['server_info']['core_in_host']; //切播 $wowzaip_chg = $channel['server_info']['core_in_host'] . ':' . $channel['server_info']['core_out_port']; } else { $wowzaip_input = $this->settings['wowza']['core_input_server']['host']; $wowzaip_chg = $this->settings['wowza']['core_input_server']['host'] . ':' . $this->settings['wowza']['out_port']; } //延时 $wowzaip_delay = $wowzaip_input; //输出 $wowzaip_output = $wowzaip_chg; $app_name_input = $this->settings['wowza']['input']['app_name']; $suffix_input = $channel['type'] ? $this->settings['wowza']['list']['suffix'] : $this->settings['wowza']['input']['suffix']; $app_name_delay = $this->settings['wowza']['delay']['app_name']; $suffix_delay = $this->settings['wowza']['delay']['suffix']; $app_name_chg = $this->settings['wowza']['chg']['app_name']; $suffix_chg = $this->settings['wowza']['chg']['suffix']; $suffix_output = $this->settings['wowza']['dvr_output']['suffix']; //输入 $ret_channel_stream[$k]['input_url'] = ''; if (isset($this->input['input']) && $input_info['id']) { $ret_channel_stream[$k]['input_url'] = hg_streamUrl($wowzaip_input, $app_name_input, $input_info['id'] . $suffix_input); } //延时 $ret_channel_stream[$k]['delay_url'] = ''; if (isset($this->input['delay']) && $channel_stream['delay_stream_id']) { $ret_channel_stream[$k]['delay_url'] = hg_streamUrl($wowzaip_delay, $app_name_delay, $channel_stream['delay_stream_id'] . $suffix_delay); } //切播 $ret_channel_stream[$k]['chg_url'] = ''; if (isset($this->input['chg']) && $channel_stream['chg_stream_id']) { $ret_channel_stream[$k]['chg_url'] = hg_streamUrl($wowzaip_chg, $app_name_chg, $channel_stream['chg_stream_id'] . $suffix_chg); } //live $ret_channel_stream[$k]['_out_url'] = ''; if ($this->mLive) { if ($channel['server_info']['live_in_host']) { $_wowzaip_output = $channel['server_info']['live_in_host'] . ':' . $channel['server_info']['live_out_port']; } else { $_wowzaip_output = $this->settings['wowza']['live_output_server']['host'] . ':' . $this->settings['wowza']['out_port']; } $_suffix_output = $this->settings['wowza']['live_output']['suffix']; if (isset($this->input['_output']) && $channel_stream['out_stream_name']) { $ret_channel_stream[$k]['_out_url'] = hg_streamUrl($_wowzaip_output, $channel['code'], $channel_stream['out_stream_name'] . $_suffix_output, 'flv'); } } //输出 $ret_channel_stream[$k]['out_url'] = ''; if (isset($this->input['output']) && $channel_stream['out_stream_name']) { $ret_channel_stream[$k]['out_url'] = hg_streamUrl($wowzaip_output, $channel['code'], $channel_stream['out_stream_name'] . $suffix_output, 'flv'); } //dvr $ret_channel_stream[$k]['dvr_url'] = ''; if (isset($this->input['dvr']) && $channel_stream['out_stream_name']) { $ret_channel_stream[$k]['dvr_url'] = hg_streamUrl($wowzaip_output, $channel['code'], $channel_stream['out_stream_name'] . $suffix_output, 'flv', '', 'dvr'); } $ret_channel_stream[$k]['m3u8_url'] = ''; $ret_channel_stream[$k]['_m3u8_url'] = ''; if ($channel['open_ts']) { //live if ($this->mLive) { if (isset($this->input['_m3u8']) && $channel_stream['out_stream_name']) { $ret_channel_stream[$k]['_m3u8_url'] = hg_streamUrl($_wowzaip_output, $channel['code'], $channel_stream['out_stream_name'] . $_suffix_output, 'm3u8'); } } if (isset($this->input['m3u8']) && $channel_stream['out_stream_name']) { $ret_channel_stream[$k]['m3u8_url'] = hg_streamUrl($wowzaip_output, $channel['code'], $channel_stream['out_stream_name'] . $suffix_output, 'm3u8'); } } } } } $channel['channel_stream'] = $ret_channel_stream; unset($channel['other_info'], $channel['server_info']); $ret_channel[$channel_id] = $channel; } $this->addItem($ret_channel); $this->output(); }
public function getStreamInfo($condition, $offset, $count) { $limit = " LIMIT " . $offset . " , " . $count; $orderby = " ORDER BY id DESC "; $sql = "SELECT id, s_name, ch_name, s_status, audio_only, other_info, type, server_id FROM " . DB_PREFIX . "stream "; $sql .= ' WHERE 1 ' . $condition . $orderby . $limit; $q = $this->db->query($sql); $stream_info = $server_id = array(); while ($row = $this->db->fetch_array($q)) { $row['other_info'] = @unserialize($row['other_info']); $server_id[] = $row['server_id']; $stream_info[] = $row; } //服务器配置 if (!empty($server_id)) { $server_id = implode(',', @array_unique($server_id)); $server_infos = $this->mServerConfig->get_server_config($server_id); } $return = array(); if (!empty($stream_info)) { foreach ($stream_info as $v) { $server_info = $server_infos[$v['server_id']]; if ($v['other_info']) { $v['out_url'] = array(); foreach ($v['other_info']['input'] as $vv) { if ($server_info['core_in_host']) { $wowzaip = $server_info['core_in_host']; } else { $wowzaip = $this->settings['wowza']['core_input_server']['host']; } $suffix = !$v['type'] ? $this->settings['wowza']['input']['suffix'] : $this->settings['wowza']['list']['suffix']; $app_name = $this->settings['wowza']['input']['app_name']; $v['out_url'][] = hg_streamUrl($wowzaip, $app_name, $vv['id'] . $suffix); } } unset($v['other_info']); $return[$v['id']] = $v; } } return $return; }