Search in sources :

Example 16 with Output

use of org.red5.io.amf3.Output in project red5-server-common by Red5.

the class PlayEngine method start.

/**
 * Start stream
 */
public void start() {
    if (log.isDebugEnabled()) {
        log.debug("start - subscriber stream state: {}", (subscriberStream != null ? subscriberStream.getState() : null));
    }
    switch(subscriberStream.getState()) {
        case UNINIT:
            // allow start if uninitialized and change state to stopped
            subscriberStream.setState(StreamState.STOPPED);
            IMessageOutput out = consumerService.getConsumerOutput(subscriberStream);
            if (msgOutReference.compareAndSet(null, out)) {
                out.subscribe(this, null);
            } else if (log.isDebugEnabled()) {
                log.debug("Message output was already set for stream: {}", subscriberStream);
            }
            break;
        default:
            throw new IllegalStateException(String.format("Cannot start in current state: %s", subscriberStream.getState()));
    }
}
Also used : IMessageOutput(org.red5.server.messaging.IMessageOutput)

Example 17 with Output

use of org.red5.io.amf3.Output in project red5-server-common by Red5.

the class PlayEngine method sendOnPlayStatus.

/**
 * 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);
}
Also used : RTMPMessage(org.red5.server.stream.message.RTMPMessage) ObjectMap(org.red5.io.utils.ObjectMap) Notify(org.red5.server.net.rtmp.event.Notify) Output(org.red5.io.amf.Output) IMessageOutput(org.red5.server.messaging.IMessageOutput) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 18 with Output

use of org.red5.io.amf3.Output in project red5-io by Red5.

the class MessageSerializationTest method serializeAndDeserialize.

private <T> T serializeAndDeserialize(T obj, Class<T> type) {
    IoBuffer data = IoBuffer.allocate(0);
    data.setAutoExpand(true);
    Output output = new Output(data);
    output.enforceAMF3();
    Serializer.serialize(output, obj);
    Input input = new Input(data.flip());
    input.enforceAMF3();
    Object result = Deserializer.deserialize(input, type);
    return type.cast(result);
}
Also used : Input(org.red5.io.amf3.Input) Output(org.red5.io.amf3.Output) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 19 with Output

use of org.red5.io.amf3.Output in project red5-server by Red5.

the class CuePointInjectionTest method injectCuePoint.

/**
 * Injects metadata (Cue Points) into a tag
 *
 * @param cue
 * @param writer
 * @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);
}
Also used : MetaCue(org.red5.io.flv.meta.MetaCue) IMetaCue(org.red5.io.flv.meta.IMetaCue) Output(org.red5.io.amf.Output) IMetaCue(org.red5.io.flv.meta.IMetaCue) Tag(org.red5.io.flv.impl.Tag) ITag(org.red5.io.ITag) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 20 with Output

use of org.red5.io.amf3.Output in project red5-server by Red5.

the class ServerStream method saveAs.

/**
 * {@inheritDoc}
 */
public void saveAs(String name, boolean isAppend) throws IOException {
    // one recording listener at a time via this entry point
    if (recordingListener == null) {
        IScope scope = getScope();
        // create a recording listener
        IRecordingListener listener = (IRecordingListener) ScopeUtils.getScopeService(scope, IRecordingListener.class, RecordingListener.class);
        // initialize the listener
        if (listener.init(scope, name, isAppend)) {
            // get decoder info if it exists for the stream
            IStreamCodecInfo codecInfo = getCodecInfo();
            log.debug("Codec info: {}", codecInfo);
            if (codecInfo instanceof StreamCodecInfo) {
                StreamCodecInfo info = (StreamCodecInfo) codecInfo;
                IVideoStreamCodec videoCodec = info.getVideoCodec();
                log.debug("Video codec: {}", videoCodec);
                if (videoCodec != null) {
                    // check for decoder configuration to send
                    IoBuffer config = videoCodec.getDecoderConfiguration();
                    if (config != null) {
                        log.debug("Decoder configuration is available for {}", videoCodec.getName());
                        VideoData videoConf = new VideoData(config.asReadOnlyBuffer());
                        try {
                            log.debug("Setting decoder configuration for recording");
                            listener.getFileConsumer().setVideoDecoderConfiguration(videoConf);
                        } finally {
                            videoConf.release();
                        }
                    }
                } else {
                    log.debug("Could not initialize stream output, videoCodec is null.");
                }
                IAudioStreamCodec audioCodec = info.getAudioCodec();
                log.debug("Audio codec: {}", audioCodec);
                if (audioCodec != null) {
                    // check for decoder configuration to send
                    IoBuffer config = audioCodec.getDecoderConfiguration();
                    if (config != null) {
                        log.debug("Decoder configuration is available for {}", audioCodec.getName());
                        AudioData audioConf = new AudioData(config.asReadOnlyBuffer());
                        try {
                            log.debug("Setting decoder configuration for recording");
                            listener.getFileConsumer().setAudioDecoderConfiguration(audioConf);
                        } finally {
                            audioConf.release();
                        }
                    }
                } else {
                    log.debug("No decoder configuration available, audioCodec is null.");
                }
            }
            // set as primary listener
            recordingListener = new WeakReference<>(listener);
            // add as a listener
            addStreamListener(listener);
            // start the listener thread
            listener.start();
        } else {
            log.warn("Recording listener failed to initialize for stream: {}", name);
        }
    } else {
        log.info("Recording listener already exists for stream: {}", name);
    }
}
Also used : AudioData(org.red5.server.net.rtmp.event.AudioData) VideoData(org.red5.server.net.rtmp.event.VideoData) IScope(org.red5.server.api.scope.IScope) IStreamCodecInfo(org.red5.codec.IStreamCodecInfo) IStreamCodecInfo(org.red5.codec.IStreamCodecInfo) StreamCodecInfo(org.red5.codec.StreamCodecInfo) IVideoStreamCodec(org.red5.codec.IVideoStreamCodec) IoBuffer(org.apache.mina.core.buffer.IoBuffer) IAudioStreamCodec(org.red5.codec.IAudioStreamCodec)

Aggregations

IoBuffer (org.apache.mina.core.buffer.IoBuffer)21 Output (org.red5.io.amf.Output)18 HashMap (java.util.HashMap)9 ITag (org.red5.io.ITag)8 Tag (org.red5.io.flv.impl.Tag)7 IOException (java.io.IOException)5 IMessageOutput (org.red5.server.messaging.IMessageOutput)5 Map (java.util.Map)4 StatusObject (org.red5.server.net.rtmp.status.StatusObject)4 File (java.io.File)3 ByteBuffer (java.nio.ByteBuffer)3 Output (org.red5.io.amf3.Output)3 Output (org.red5.io.object.Output)3 RTMPConnection (org.red5.server.net.rtmp.RTMPConnection)3 Notify (org.red5.server.net.rtmp.event.Notify)3 ArrayList (java.util.ArrayList)2 BeanMap (org.apache.commons.beanutils.BeanMap)2 IAudioStreamCodec (org.red5.codec.IAudioStreamCodec)2 IStreamCodecInfo (org.red5.codec.IStreamCodecInfo)2 IVideoStreamCodec (org.red5.codec.IVideoStreamCodec)2