org.red5.io.amf.Output Java Examples

The following examples show how to use org.red5.io.amf.Output. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AxisTest.java    From red5-rtsp-restreamer with Apache License 2.0 6 votes vote down vote up
public Notify getMetaDataEvent() {

		IoBuffer buf = IoBuffer.allocate(1024);
		buf.setAutoExpand(true);
		Output out = new Output(buf);
		out.writeString("onMetaData");

		Map<Object, Object> props = new HashMap<Object, Object>();
		props.put("width", 160);
		props.put("height", 120);
		props.put("framerate", 15);
		props.put("videocodecid", 7);
		props.put("canSeekToEnd", false);
		out.writeMap(props);
		buf.flip();

		return new Notify(buf);
	}
 
Example #2
Source File: ClientBroadcastStream.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/**
 * Notifies handler on stream broadcast start
 */
private void notifyBroadcastStart() {
    IStreamAwareScopeHandler handler = getStreamAwareHandler();
    if (handler != null) {
        try {
            handler.streamBroadcastStart(this);
        } catch (Throwable t) {
            log.error("Error in notifyBroadcastStart", t);
        }
    }
    // send metadata for creation and start dates
    IoBuffer buf = IoBuffer.allocate(256);
    buf.setAutoExpand(true);
    Output out = new Output(buf);
    out.writeString("onMetaData");
    Map<Object, Object> params = new HashMap<>();
    Calendar cal = GregorianCalendar.getInstance();
    cal.setTimeInMillis(creationTime);
    params.put("creationdate", ZonedDateTime.ofInstant(cal.toInstant(), ZoneId.of("UTC")).format(DateTimeFormatter.ISO_INSTANT));
    cal.setTimeInMillis(startTime);
    params.put("startdate", ZonedDateTime.ofInstant(cal.toInstant(), ZoneId.of("UTC")).format(DateTimeFormatter.ISO_INSTANT));
    if (log.isDebugEnabled()) {
        log.debug("Params: {}", params);
    }
    out.writeMap(params);
    buf.flip();
    Notify notify = new Notify(buf);
    notify.setAction("onMetaData");
    notify.setHeader(new Header());
    notify.getHeader().setDataType(Notify.TYPE_STREAM_METADATA);
    notify.getHeader().setStreamId(0);
    notify.setTimestamp(0);
    dispatchEvent(notify);
}
 
Example #3
Source File: PlayEngine.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/**
 * Sends an onPlayStatus message.
 * 
 * http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/NetDataEvent.html
 * 
 * @param code
 * @param duration
 * @param bytes
 */
private void sendOnPlayStatus(String code, int duration, long bytes) {
    if (log.isDebugEnabled()) {
        log.debug("Sending onPlayStatus - code: {} duration: {} bytes: {}", code, duration, bytes);
    }
    // create the buffer
    IoBuffer buf = IoBuffer.allocate(102);
    buf.setAutoExpand(true);
    Output out = new Output(buf);
    out.writeString("onPlayStatus");
    ObjectMap<Object, Object> args = new ObjectMap<>();
    args.put("code", code);
    args.put("level", Status.STATUS);
    args.put("duration", duration);
    args.put("bytes", bytes);
    String name = currentItem.get().getName();
    if (StatusCodes.NS_PLAY_TRANSITION_COMPLETE.equals(code)) {
        args.put("clientId", streamId);
        args.put("details", name);
        args.put("description", String.format("Transitioned to %s", name));
        args.put("isFastPlay", false);
    }
    out.writeObject(args);
    buf.flip();
    Notify event = new Notify(buf, "onPlayStatus");
    if (lastMessageTs > 0) {
        event.setTimestamp(lastMessageTs);
    } else {
        event.setTimestamp(0);
    }
    RTMPMessage msg = RTMPMessage.build(event);
    doPushMessage(msg);
}
 
Example #4
Source File: M4AReader.java    From red5-io with Apache License 2.0 5 votes vote down vote up
/**
 * Create tag for metadata event.
 *
 * @return Metadata event tag
 */
ITag createFileMeta() {
    log.debug("Creating onMetaData");
    // Create tag for onMetaData event
    IoBuffer buf = IoBuffer.allocate(1024);
    buf.setAutoExpand(true);
    Output out = new Output(buf);
    out.writeString("onMetaData");
    Map<Object, Object> props = new HashMap<Object, Object>();
    // Duration property
    props.put("duration", ((double) duration / (double) timeScale));

    // Audio codec id - watch for mp3 instead of aac
    props.put("audiocodecid", audioCodecId);
    props.put("aacaot", audioCodecType);
    props.put("audiosamplerate", audioTimeScale);
    props.put("audiochannels", audioChannels);
    props.put("canSeekToEnd", false);
    out.writeMap(props);
    buf.flip();

    //now that all the meta properties are done, update the duration
    duration = Math.round(duration * 1000d);

    ITag result = new Tag(IoConstants.TYPE_METADATA, 0, buf.limit(), null, 0);
    result.setBody(buf);
    return result;
}
 
Example #5
Source File: MetaService.java    From red5-io with Apache License 2.0 5 votes vote down vote up
/**
 * Injects metadata (other than Cue points) into a tag
 * 
 * @param meta
 *            Metadata
 * @param tag
 *            Tag
 * @return New tag with injected metadata
 */
private static ITag injectMetaData(IMetaData<?, ?> meta, ITag tag) {
    IoBuffer bb = IoBuffer.allocate(1000);
    bb.setAutoExpand(true);
    Output out = new Output(bb);
    Serializer.serialize(out, "onMetaData");
    Serializer.serialize(out, meta);
    IoBuffer tmpBody = out.buf().flip();
    int tmpBodySize = out.buf().limit();
    int tmpPreviousTagSize = tag.getPreviousTagSize();
    return new Tag(IoConstants.TYPE_METADATA, 0, tmpBodySize, tmpBody, tmpPreviousTagSize);
}
 
Example #6
Source File: MetaService.java    From red5-io with Apache License 2.0 5 votes vote down vote up
/**
 * Injects metadata (Cue Points) into a tag
 * 
 * @param meta
 *            Metadata (cue points)
 * @param tag
 *            Tag
 * @return ITag tag New tag with injected metadata
 */
private static ITag injectMetaCue(IMetaCue meta, ITag tag) {
    // IMeta meta = (MetaCue) cue;
    Output out = new Output(IoBuffer.allocate(1000));
    Serializer.serialize(out, "onCuePoint");
    Serializer.serialize(out, meta);

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

    return new Tag(IoConstants.TYPE_METADATA, tmpTimestamp, tmpBodySize, tmpBody, tmpPreviousTagSize);
}
 
Example #7
Source File: MetaService.java    From red5-io with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void writeMetaData(IMetaData<?, ?> metaData) {
    IMetaCue meta = (MetaCue<?, ?>) metaData;
    Output out = new Output(IoBuffer.allocate(1000));
    Serializer.serialize(out, "onCuePoint");
    Serializer.serialize(out, meta);
}
 
Example #8
Source File: AMFIOTest.java    From red5-io with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
void setupIO() {
    buf = IoBuffer.allocate(0); // 1kb
    buf.setAutoExpand(true);
    in = new Input(buf);
    out = new Output(buf);
}
 
Example #9
Source File: MP3Reader.java    From red5-io with Apache License 2.0 4 votes vote down vote up
/**
 * Creates file metadata object
 * 
 * @return Tag
 */
private ITag createFileMeta() {
    log.debug("createFileMeta");
    // create tag for onMetaData event
    IoBuffer in = IoBuffer.allocate(1024);
    in.setAutoExpand(true);
    Output out = new Output(in);
    out.writeString("onMetaData");
    Map<Object, Object> props = new HashMap<Object, Object>();
    props.put("audiocodecid", IoConstants.FLAG_FORMAT_MP3);
    props.put("canSeekToEnd", true);
    // set id3 meta data if it exists
    if (metaData != null) {
        if (metaData.artist != null) {
            props.put("artist", metaData.artist);
        }
        if (metaData.album != null) {
            props.put("album", metaData.album);
        }
        if (metaData.songName != null) {
            props.put("songName", metaData.songName);
        }
        if (metaData.genre != null) {
            props.put("genre", metaData.genre);
        }
        if (metaData.year != null) {
            props.put("year", metaData.year);
        }
        if (metaData.track != null) {
            props.put("track", metaData.track);
        }
        if (metaData.comment != null) {
            props.put("comment", metaData.comment);
        }
        if (metaData.duration != null) {
            props.put("duration", metaData.duration);
        }
        if (metaData.channels != null) {
            props.put("channels", metaData.channels);
        }
        if (metaData.sampleRate != null) {
            props.put("samplerate", metaData.sampleRate);
        }
        if (metaData.hasCoverImage()) {
            Map<Object, Object> covr = new HashMap<>(1);
            covr.put("covr", new Object[] { metaData.getCovr() });
            props.put("tags", covr);
        }
        //clear meta for gc
        metaData = null;
    }
    log.debug("Metadata properties map: {}", props);
    // check for duration
    if (!props.containsKey("duration")) {
        // generate it from framemeta
        if (frameMeta != null) {
            props.put("duration", frameMeta.timestamps[frameMeta.timestamps.length - 1] / 1000.0);
        } else {
            log.debug("Frame meta was null");
        }
    }
    // set datarate
    if (dataRate > 0) {
        props.put("audiodatarate", dataRate);
    }
    out.writeMap(props);
    in.flip();
    // meta-data
    ITag result = new Tag(IoConstants.TYPE_METADATA, 0, in.limit(), null, prevSize);
    result.setBody(in);
    return result;
}
 
Example #10
Source File: StatusObjectService.java    From red5-server-common with Apache License 2.0 2 votes vote down vote up
/**
 * Serializes status object
 * 
 * @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);
}