/**
   * 返回当前录像的会话ID.
   *
   * @param client
   * @param alarm
   * @return
   */
  public String startAlarmRecord(MonitorClient client, AlarmRecord alarm) {
    Date startTime = new Date();
    String path =
        getSavePath(startTime, client.info.uuid, alarm.user, alarm.alarmCode, alarm.channelId);
    alarm.videoPath = path;
    alarm.generatePK();

    int ch = 0;
    try {
      ch = Integer.parseInt(alarm.channelId);
    } catch (Exception e) {
    }

    alarm.recorder = new FileVideoRecorder(new File(rootPath, path), MonitorChannel.MAIN_VIDEO, ch);

    log.info(String.format("Start record, sid:%s, path:%s", alarm.uuid, alarm.videoPath));
    client.route.addDestination(alarm.recorder);
    client.realPlay(ch, MonitorChannel.MAIN_VIDEO);
    storage.save(alarm);

    runningRecorder.put(alarm.uuid, alarm);

    return alarm.uuid;

    // return alarm.uuid;
  }
  public String startManualRecord(MonitorClient client, String user) {
    AlarmRecord alarm = new AlarmRecord();
    alarm.user = user;
    alarm.baseStation = client.info.uuid;
    alarm.startTime = new Date();
    alarm.alarmCode = "none";

    return startAlarmRecord(client, alarm);
  }
  public void stoptRecord(String sid) {
    AlarmRecord alarm = runningRecorder.get(sid);
    if (alarm != null) {
      alarm.recorder.close();
      alarm.endTime = new Date();
      storage.save(alarm);

      runningRecorder.remove(sid);
      log.info(String.format("Closed record, sid:%s", alarm.uuid));
    } else {
      log.warn("Try to stop record, but Not found session by id " + sid);
    }
  }
  /** 关闭超时的录像。 */
  protected void closeTimeOutRecord() {
    Collection<String> xx = new ArrayList<String>();
    xx.addAll(runningRecorder.keySet());

    long startTime = System.currentTimeMillis() - 60 * 1000 * alarmTimeOut;
    AlarmRecord alarm = null;
    for (String k : xx) {
      alarm = runningRecorder.get(k);
      if (alarm != null && alarm.startTime.getTime() < startTime) {
        alarm.alarmStatus = "2";
        stoptRecord(k);
      }
    }
  }