Package org.red5.io.amf

Examples of org.red5.io.amf.Output


     */
  private void writeMetadataTag(double duration, Integer videoCodecId, Integer audioCodecId) throws IOException {
    metaPosition = channel.position();
    IoBuffer buf = IoBuffer.allocate(1024);
    buf.setAutoExpand(true);
    Output out = new Output(buf);
    out.writeString("onMetaData");
    Map<Object, Object> params = new HashMap<Object, Object>(4);
    params.put("duration", duration);
    if (videoCodecId != null) {
      params.put("videocodecid", videoCodecId.intValue());
    }
    if (audioCodecId != null) {
      params.put("audiocodecid", audioCodecId.intValue());
    }
    params.put("canSeekToEnd", true);
    out.writeMap(params, new Serializer());
    buf.flip();

    if (fileMetaSize == 0) {
      fileMetaSize = buf.limit();
    }
View Full Code Here


   * @param out                 Byte buffer for output object
   * @param statusObject        Status object to serialize
   */
  public void serializeStatusObject(IoBuffer out, StatusObject statusObject) {
    Map<?, ?> statusMap = new BeanMap(statusObject);
    Output output = new Output(out);
    Serializer.serialize(output, statusMap);
  }
View Full Code Here

    for (RemotingHeader header : hdr) {
      Output.putString(result, header.name);
      result.put(header.required ? (byte) 0x01 : (byte) 0x00);
      IoBuffer tmp = IoBuffer.allocate(1024);
      tmp.setAutoExpand(true);
      Output tmpOut = new Output(tmp);
      Serializer.serialize(tmpOut, header.data);
      tmp.flip();
      // Size of header data
      result.putInt(tmp.limit());
      // Header data
      result.put(tmp);
      tmp.free();
      tmp = null;
    }
    // One body
    result.putShort((short) 1);

    // Method name
    Output.putString(result, method);

    // Client callback for response
    Output.putString(result, "");

    // Serialize parameters
    IoBuffer tmp = IoBuffer.allocate(1024);
    tmp.setAutoExpand(true);
    Output tmpOut = new Output(tmp);

    //if the params are null send the NULL AMF type
    //this should fix APPSERVER-296
    if (params == null) {
      tmpOut.writeNull();
    } else {
      tmpOut.writeArray(params);
    }
    tmp.flip();

    // Store size and parameters
    result.putInt(tmp.limit());
View Full Code Here

   */
  public IoBuffer encode(Object message) throws Exception {
    RemotingPacket resp = (RemotingPacket) message;
    IoBuffer buf = IoBuffer.allocate(1024);
    buf.setAutoExpand(true);
    Output output;
    if (resp.getEncoding() == Encoding.AMF0) {
      buf.putShort((short) 0); // encoded using AMF0
    } else {
      buf.putShort((short) 3); // encoded using AMF3
    }

    IRemotingConnection conn = (IRemotingConnection) Red5.getConnectionLocal();
    Collection<IRemotingHeader> headers = conn.getHeaders();
    buf.putShort((short) headers.size()); // write the header count
    if (resp.getEncoding() == Encoding.AMF0) {
      output = new Output(buf);
    } else {
      output = new org.red5.io.amf3.Output(buf);
    }
    for (IRemotingHeader header : headers) {
      Output.putString(buf, IRemotingHeader.PERSISTENT_HEADER);
      output.writeBoolean(false);
      Map<String, Object> param = new HashMap<String, Object>();
      param.put("name", header.getName());
      param.put("mustUnderstand", header.getMustUnderstand() ? Boolean.TRUE : Boolean.FALSE);
      param.put("data", header.getValue());
      Serializer.serialize(output, param);
    }
    headers.clear();

    buf.putShort((short) resp.getCalls().size()); // write the number of bodies
    for (RemotingCall call : resp.getCalls()) {
      log.debug("Call");
      Output.putString(buf, call.getClientResponse());
      if (!call.isMessaging) {
        Output.putString(buf, "null");
      } else {
        Output.putString(buf, "");
      }
      buf.putInt(-1);
      log.info("result: {}", call.getResult());
      if (call.isAMF3) {
        output = new org.red5.io.amf3.Output(buf);
      } else {
        output = new Output(buf);
      }
      Object result = call.getClientResult();
      if (!call.isSuccess()) {
        if (call.isMessaging && !(result instanceof ErrorMessage)) {
          // Generate proper error result for the Flex messaging client
View Full Code Here

   * @param tag
   * @return ITag tag
   */
  private ITag injectCuePoint(Object cue, ITag tag) {
    IMetaCue cp = (MetaCue<?, ?>) cue;
    Output out = new Output(IoBuffer.allocate(1000));
    Serializer.serialize(out, "onCuePoint");
    Serializer.serialize(out, cp);

    IoBuffer tmpBody = out.buf().flip();
    int tmpBodySize = out.buf().limit();
    //int tmpPreviousTagSize = tag.getPreviousTagSize();
    int tmpTimestamp = getTimeInMilliseconds(cp);

    //return new Tag(tmpDataType, tmpTimestamp, tmpBodySize, tmpBody, tmpPreviousTagSize);
    return new Tag(IoConstants.TYPE_METADATA, tmpTimestamp, tmpBodySize, tmpBody, 0);
View Full Code Here

   * @return ITag tag
   */
  private ITag injectMetaData(Object cue, ITag tag) {

    IMetaCue cp = (MetaCue<?, ?>) cue;
    Output out = new Output(IoBuffer.allocate(1000));
    Serializer.serialize(out, "onCuePoint");
    Serializer.serialize(out, cp);

    IoBuffer tmpBody = out.buf().flip();
    int tmpBodySize = out.buf().limit();
    int tmpPreviousTagSize = tag.getPreviousTagSize();
    byte tmpDataType = IoConstants.TYPE_METADATA;
    int tmpTimestamp = getTimeInMilliseconds(cp);

    return new Tag(tmpDataType, tmpTimestamp, tmpBodySize, tmpBody, tmpPreviousTagSize);
View Full Code Here

        }
        log.debug("Dataframe: {} params: {}", onCueOrOnMeta, params.toString());

        IoBuffer buf = IoBuffer.allocate(1024);
        buf.setAutoExpand(true);
        Output out = new Output(buf);
        out.writeString(onCueOrOnMeta);
        out.writeMap(params);

        buf.flip();
        return new Notify(buf);
      } else if ("onFI".equals(setData)) {
        // the onFI request contains 2 items relative to the publishing client application
View Full Code Here

   * @param bytes
   */
  private void sendOnPlayStatus(String code, int duration, long bytes) {
    IoBuffer buf = IoBuffer.allocate(255);
    buf.setAutoExpand(true);
    Output out = new Output(buf);
    out.writeString("onPlayStatus");
    Map<Object, Object> props = new HashMap<Object, Object>();
    props.put("code", code);
    props.put("level", "status");
    props.put("duration", duration);
    props.put("bytes", bytes);
    if (StatusCodes.NS_PLAY_TRANSITION_COMPLETE.equals(code)) {
      props.put("details", currentItem.getName());
      props.put("description", String.format("Transitioned to %s", currentItem.getName()));
      props.put("clientId", streamId);
      props.put("isFastPlay", false);
    }
    out.writeMap(props);
    buf.flip();

    IRTMPEvent event = new Notify(buf);
    if (lastMessageTs > 0) {
      event.setTimestamp(lastMessageTs);
View Full Code Here

          // We likely also need the original file size when writing object
          initialSize += (int) file.length();
        }
        buf = IoBuffer.allocate(initialSize);
        buf.setAutoExpand(true);
        Output out = new Output(buf);
        out.writeString(object.getClass().getName());
        object.serialize(out);
        buf.flip();

        FileOutputStream output = new FileOutputStream(file.getAbsolutePath());
        ServletUtils.copy(buf.asInputStream(), output);
View Full Code Here

        }
      }
      buf = ByteBuffer.allocate(initialSize);
      try {
        buf.setAutoExpand(true);
        Output out = new Output(buf);
        out.writeString(object.getClass().getName());
        object.serialize(out);
        buf.flip();

        FileOutputStream output = new FileOutputStream(resFile
            .getFile().getAbsolutePath());
View Full Code Here

TOP

Related Classes of org.red5.io.amf.Output

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.