Package org.red5.io.amf

Examples of org.red5.io.amf.Output


    }

    private void sendOnPlayStatus(String code, int duration, long bytes) {
      ByteBuffer buf = ByteBuffer.allocate(1024);
      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);
      out.writeMap(props, new Serializer());
      buf.flip();

      IRTMPEvent event = new Notify(buf);
      if (lastMessage != null) {
        int timestamp = lastMessage.getTimestamp();
View Full Code Here


     */
  private void writeMetadataTag(double duration, Integer videoCodecId, Integer audioCodecId) throws IOException {
    metaPosition = channel.position();
    ByteBuffer buf = ByteBuffer.allocate(1024);
    buf.setAutoExpand(true);
    Output out = new Output(buf);
    out.writeString("onMetaData");
    Map<Object, Object> params = new HashMap<Object, Object>();
    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

     */
    private ITag createFileMeta() {
    // Create tag for onMetaData event
    ByteBuffer buf = ByteBuffer.allocate(1024);
    buf.setAutoExpand(true);
    Output out = new Output(buf);
    out.writeString("onMetaData");
    Map<Object, Object> props = new HashMap<Object, Object>();
    props.put("duration", frameMeta.timestamps[frameMeta.timestamps.length - 1] / 1000.0);
    props.put("audiocodecid", IoConstants.FLAG_FORMAT_MP3);
    if (dataRate > 0) {
      props.put("audiodatarate", dataRate);
    }
    props.put("canSeekToEnd", true);
    out.writeMap(props, new Serializer());
    buf.flip();

    ITag result = new Tag(IoConstants.TYPE_METADATA, 0, buf.limit(), null,
        prevSize);
    result.setBody(buf);
View Full Code Here

  private ITag injectMetaData(IMetaData meta, ITag tag) {

    ByteBuffer bb = ByteBuffer.allocate(1000);
    bb.setAutoExpand(true);

    Output out = new Output(bb);
    Serializer ser = new Serializer();
    ser.serialize(out, "onMetaData");
    ser.serialize(out, meta);

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

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

   * @return ITag tag New tag with injected metadata
   */
  private ITag injectMetaCue(IMetaCue meta, ITag tag) {

    // IMeta meta = (MetaCue) cue;
    Output out = new Output(ByteBuffer.allocate(1000));
    Serializer ser = new Serializer();
    ser.serialize(out, "onCuePoint");
    ser.serialize(out, meta);

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

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

  /**
   * {@inheritDoc}
   */
  public void writeMetaData(IMetaData metaData) {
    IMetaCue meta = (MetaCue) metaData;
    Output out = new Output(ByteBuffer.allocate(1000));
    serializer.serialize(out, "onCuePoint");
    serializer.serialize(out, meta);

  }
View Full Code Here

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

     */
    private ITag createFileMeta() {
    // Create tag for onMetaData event
    ByteBuffer buf = ByteBuffer.allocate(1024);
    buf.setAutoExpand(true);
    Output out = new Output(buf);

        // Duration property
    out.writeString("onMetaData");
    Map<Object, Object> props = new HashMap<Object, Object>();
    props.put("duration", duration / 1000.0);
    if (firstVideoTag != -1) {
      long old = getCurrentPosition();
      setCurrentPosition(firstVideoTag);
      readTagHeader();
      fillBuffer(1);
      byte frametype = in.get();
            // Video codec id
      props.put("videocodecid", frametype & MASK_VIDEO_CODEC);
      setCurrentPosition(old);
    }
    if (firstAudioTag != -1) {
      long old = getCurrentPosition();
      setCurrentPosition(firstAudioTag);
      readTagHeader();
      fillBuffer(1);
      byte frametype = in.get();
            // Audio codec id
            props.put("audiocodecid", (frametype & MASK_SOUND_FORMAT) >> 4);
      setCurrentPosition(old);
    }
    props.put("canSeekToEnd", true);
    out.writeMap(props, new Serializer());
    buf.flip();

    ITag result = new Tag(IoConstants.TYPE_METADATA, 0, buf.limit(), null,
        0);
    result.setBody(buf);
View Full Code Here

      Output.putString(result, header.name);
      result.put(header.required ? (byte) 0x01 : (byte) 0x00);

      ByteBuffer tmp = ByteBuffer.allocate(1024);
      tmp.setAutoExpand(true);
      Output tmpOut = new Output(tmp);
      Serializer tmpSer = new Serializer();
      tmpSer.serialize(tmpOut, header.data);
      tmp.flip();
      // Size of header data
      result.putInt(tmp.limit());
      // Header data
      result.put(tmp);
      tmp.release();
      tmp = null;
    }
    // One body
    result.putShort((short) 1);

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

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

    // Serialize parameters
    ByteBuffer tmp = ByteBuffer.allocate(1024);
    tmp.setAutoExpand(true);
    Output tmpOut = new Output(tmp);
    tmpOut.writeArray(params, new Serializer());
    tmp.flip();

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

  /** {@inheritDoc} */
    public ByteBuffer encode(ProtocolState state, Object message) throws Exception {
    RemotingPacket resp = (RemotingPacket) message;
    ByteBuffer buf = ByteBuffer.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();
    synchronized (headers) {
      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.getName());
        serializer.serialize(output, param);
      }
      headers.clear();
    }
   
    buf.putShort((short) resp.getCalls().size()); // write the number of bodies
    for (RemotingCall call: resp.getCalls()) {
      if (log.isDebugEnabled()) {
        log.debug("Call");
      }
      Output.putString(buf, call.getClientResponse());
      if (!call.isMessaging) {
        Output.putString(buf, "null");
      } else {
        Output.putString(buf, "");
      }
      buf.putInt(-1);
      if (log.isDebugEnabled()) {
        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

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.