Beispiel #1
0
 /**
  * 获取频道信息
  * Enter description here ...
  * @param string $channel_ids
  */
 public function get_live($channel_ids)
 {
     include_once ROOT_PATH . 'lib/class/live.class.php';
     $newLive = new live();
     $channel_tmp = $newLive->getChannelInfoById(array('id' => $channel_ids, 'is_stream' => 1, 'live' => 1, 'is_sys' => -1));
     return $channel_tmp;
 }
Beispiel #2
0
 /**
  * 显示录播节目单
  */
 function show()
 {
     $sql = "SELECT * FROM " . DB_PREFIX . "server_config WHERE 1 AND state=1";
     $q = $this->db->query($sql);
     $server_config = array();
     while ($row = $this->db->fetch_array($q)) {
         $server_config[$row['id']] = $row;
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "program_record WHERE is_record=0 and start_time < " . (strtotime(date('Y-m-d', TIMENOW)) + 86399);
     $record_info = $channel_info = $item_info = array();
     $q = $this->db->query($sql);
     while ($row = $this->db->fetch_array($q)) {
         $channel_info[$row['channel_id']] = $row['channel_id'];
         $item_info[$row['item']] = $row['item'];
         $record_info[] = $row;
     }
     if (empty($record_info)) {
         return '';
     }
     $channel = array();
     if (!empty($channel_info)) {
         $channel_ids = implode(',', $channel_info);
         include_once ROOT_PATH . 'lib/class/live.class.php';
         $newLive = new live();
         $channel_tmp = $newLive->getChannelInfoById(array('id' => $channel_ids, 'is_stream' => 1, 'live' => 1, 'is_sys' => -1, 'fetch_live' => 1));
         foreach ($channel_tmp as $k => $v) {
             $channel[$v['id']] = $v;
         }
         if (empty($channel)) {
             return '';
         }
     }
     if (!empty($item_info)) {
         include_once ROOT_PATH . 'lib/class/livmedia.class.php';
         $livmedia = new livmedia();
         $item_info = $livmedia->getAutoItem();
     }
     include_once ROOT_PATH . 'lib/class/program.class.php';
     $program_plan = new program();
     foreach ($record_info as $k => $row) {
         if (empty($server_config[$row['server_id']])) {
             continue;
         }
         $check_server = $this->checkServer($server_config[$row['server_id']]['host'] . ':' . $server_config[$row['server_id']]['port'] . $server_config[$row['server_id']]['dir']);
         if (!$check_server) {
             continue;
         }
         $channel_tmp = $channel[$row['channel_id']];
         $row['code'] = $channel_tmp['code'];
         $row['name'] = $channel_tmp['name'];
         $row['is_audio'] = $channel_tmp['is_audio'];
         $row['save_time'] = $channel_tmp['time_shift'];
         $row['main_stream_name'] = $channel_tmp['main_stream_name'];
         $row['stream_state'] = $channel_tmp['status'];
         $row['record_time'] = $channel_tmp['record_time'];
         $row['stream_id'] = $channel_tmp['stream_id'];
         $row['sort_name'] = $row['item'] > 0 ? $item_info[$row['item']]['name'] : '';
         $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($program_plan->get_program_plan($ret['channel_id'], $ret['starttime'], $ret['endtime']));
         $ret['title'] = base64_encode(json_encode(trim($program ? $program : '精彩节目')));
         $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'];
         if (empty($channel_tmp['record_stream'])) {
             continue;
         }
         $ret['stream'] = $channel_tmp['record_uri'] ? $channel_tmp['record_uri'] : $channel_tmp['record_stream'][0]['output_url_rtmp'];
         $callback = $this->settings['App_program_record']['protocol'] . $this->settings['App_program_record']['host'] . '/' . $this->settings['App_program_record']['dir'] . 'admin/record_callback.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['is_audio'] = $row['is_audio'];
         $ret['extend'] = base64_encode(json_encode(array('_user_id' => $row['user_id'], '_user_name' => $row['user_name'], 'org_id' => $row['org_id'], 'force_codec' => $row['force_codec'], 'source' => $row['name'], 'callback_extra' => $row['callback_extra'])));
         if (!$row['stream_state']) {
             $ret = array('errortext' => '视频流未开启!');
             $str = 'ID-' . $row['id'] . ($ret['errortext'] ? $ret['errortext'] : '录制成功');
             $this->tips($str, TIMENOW);
         } else {
             switch ($row['is_record']) {
                 case 0:
                     //录制未进行提交
                     $this->curl = new curl($server_config[$row['server_id']]['host'] . ':' . $server_config[$row['server_id']]['port'], $server_config[$row['server_id']]['dir']);
                     $this->curl->setSubmitType('get');
                     $this->curl->initPostData();
                     $this->curl->addRequestData('action', 'INSERT');
                     $this->curl->addRequestData('url', $ret['stream']);
                     $this->curl->addRequestData('callback', $callback);
                     //urlencode
                     //$this->curl->addRequestData('startTime', $ret['starttime']-1);
                     $this->curl->addRequestData('duration', $row['toff']);
                     $this->curl->addRequestData('uploadFile', '0');
                     $this->curl->addRequestData('app', 'live');
                     $this->curl->addRequestData('streamname', $channel_tmp['code'] . '_' . $channel_tmp['main_stream_name']);
                     $this->curl->addRequestData('html', 1);
                     $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;
                             $ret['id'] = -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->record->addLogs($log_data);
                         $this->update_queue($conid, $log_id);
                     } else {
                         $week_day = unserialize($row['week_day']);
                         $select_curl = new curl($server_config[$row['server_id']]['host'] . ':' . $server_config[$row['server_id']]['port'], $server_config[$row['server_id']]['dir']);
                         $select_curl->setSubmitType('get');
                         $select_curl->initPostData();
                         $select_curl->addRequestData('action', 'SELECT');
                         $select_curl->addRequestData('id', $row['id']);
                         $select_record = $this->curl->request('');
                         $select_array = xml2Array($select_record);
                         if (is_array($select_array)) {
                             if (!$select_array['result']) {
                                 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);
                                 }
                             } else {
                             }
                         }
                         $log_data['text'] = $ret['errortext'];
                         $log_data['state'] = 2;
                         $log_id = $this->record->addLogs($log_data);
                         $this->update_queue($conid, $log_id);
                     }
                     $str = 'ID-' . $row['id'] . ($ret['errortext'] ? $ret['errortext'] : '录制成功');
                     $this->tips($str, TIMENOW);
                     break;
                 case 1:
                     //正在录制,录制超时,只处理周期性的录制超时
                     if ($row['start_time'] + $row['toff'] < TIMENOW - 120) {
                         $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);
                             $str = 'ID-' . $row['id'] . '录制超时处理成功';
                             $this->tips($str, TIMENOW);
                         }
                     }
                     break;
             }
         }
     }
 }