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()));
}
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations