public synchronized void start(String publishName, String publishMode, Object[] params) {
    setState(CONNECTING);
    this.publishName = publishName;
    this.publishMode = publishMode;
    rtmpClient = new RTMPClient();

    Map<String, Object> defParams = rtmpClient.makeDefaultConnectionParams(host, port, app);
    rtmpClient.connect(host, port, defParams, this, params);
  }
 public synchronized void pushMessage(IMessage message) throws IOException {
   if (getState() >= PUBLISHED && message instanceof RTMPMessage) {
     RTMPMessage rtmpMsg = (RTMPMessage) message;
     rtmpClient.publishStreamData(streamId, rtmpMsg);
   } else {
     frameBuffer.add(message);
   }
 }
 public synchronized void resultReceived(IPendingServiceCall call) {
   if ("connect".equals(call.getServiceMethodName())) {
     setState(STREAM_CREATING);
     rtmpClient.createStream(this);
   } else if ("createStream".equals(call.getServiceMethodName())) {
     setState(PUBLISHING);
     Object result = call.getResult();
     if (result instanceof Integer) {
       Integer streamIdInt = (Integer) result;
       streamId = streamIdInt.intValue();
       rtmpClient.publish(streamIdInt.intValue(), publishName, publishMode, this);
     } else {
       rtmpClient.disconnect();
       setState(STOPPED);
     }
   }
 }
 public synchronized void onStreamEvent(Notify notify) {
   ObjectMap<?, ?> map = (ObjectMap<?, ?>) notify.getCall().getArguments()[0];
   String code = (String) map.get("code");
   if (StatusCodes.NS_PUBLISH_START.equals(code)) {
     setState(PUBLISHED);
     while (frameBuffer.size() > 0) {
       rtmpClient.publishStreamData(streamId, frameBuffer.remove(0));
     }
   }
 }
 public synchronized void stop() {
   if (getState() >= STREAM_CREATING) {
     rtmpClient.disconnect();
   }
   setState(STOPPED);
 }