org.red5.server.net.rtmp.event.Notify Java Examples
The following examples show how to use
org.red5.server.net.rtmp.event.Notify.
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: RTMPTClientTest.java From red5-client with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") protected void onCommand(RTMPConnection conn, Channel channel, Header header, Notify notify) { super.onCommand(conn, channel, header, notify); System.out.println("onInvoke, header = " + header.toString()); System.out.println("onInvoke, notify = " + notify.toString()); Object obj = notify.getCall().getArguments().length > 0 ? notify.getCall().getArguments()[0] : null; if (obj instanceof Map) { Map<String, String> map = (Map<String, String>) obj; String code = map.get("code"); if (StatusCodes.NS_PLAY_STOP.equals(code)) { synchronized (RTMPTClientTest.class) { finished = true; RTMPTClientTest.class.notifyAll(); } disconnect(); System.out.println("Disconnected"); } } }
Example #2
Source File: RTMPTSClientTest.java From red5-client with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") protected void onCommand(RTMPConnection conn, Channel channel, Header header, Notify notify) { super.onCommand(conn, channel, header, notify); System.out.println("onInvoke, header = " + header.toString()); System.out.println("onInvoke, notify = " + notify.toString()); Object obj = notify.getCall().getArguments().length > 0 ? notify.getCall().getArguments()[0] : null; if (obj instanceof Map) { Map<String, String> map = (Map<String, String>) obj; String code = map.get("code"); if (StatusCodes.NS_PLAY_STOP.equals(code)) { synchronized (RTMPTSClientTest.class) { finished = true; RTMPTSClientTest.class.notifyAll(); } disconnect(); System.out.println("Disconnected"); } } }
Example #3
Source File: RTMPClientProtocolDecoderTest.java From red5-client with Apache License 2.0 | 6 votes |
@Test public void testDecodeBufferExTS() { //log.debug("\testDecodeBufferExTS"); RTMPProtocolDecoder dec = new RTMPProtocolDecoder(); RTMPConnection conn = new RTMPMinaConnection(); Red5.setConnectionLocal(conn); RTMP rtmp = conn.getState(); rtmp.setState(RTMP.STATE_CONNECTED); // lastHeader: Header [streamId=1, channelId=4, dataType=18, timerBase=0, timerDelta=0, size=309, extended=false] // get the local decode state RTMPDecodeState state = conn.getDecoderState(); // meta and audio 4x chunks IoBuffer in = IoBuffer.wrap(IOUtils.hexStringToByteArray( "04000000000135120100000002000d40736574446174614672616d6502000a6f6e4d65746144617461080000000d00086475726174696f6e0040d518000000000000057769647468004064000000000000000668656967687400405e000000000000000d766964656f64617461726174650040686a000000000000096672616d657261746500403900000000c40000000c766964656f636f6465636964004000000000000000000d617564696f6461746172617465000000000000000000000f617564696f73616d706c65726174650040d5888000000000000f617564696f73616d706c6573697a65004030000000000000000673746572656f0100000c617564696f636f6465636964004000c40000000000000007656e636f64657202000d4c61766635362e31352e313032000866696c6573697a650000000000000000000000090400000000006908010000002afff340c400104002e62d4110009080200830107ea04cfa810710e0987f820ec130fc401897c1c0c70ff502008020eea04c1f0fe7fcb9fc10ff90d107c1f82008021feb07c1c04010041c20f89c1fff6b6edad93d99d8da6cd42a08e459095589d4b5fb9a4e679a1f4400001a00006a082afff342c41a19c91f225d89300055a47640c62cee7ccc85c08c42cadb6b56daebe65989f78c3ef3cfbd694ac0c34aa855ee0598a031f0a0686212d43631a4c59a926383c2d5201c5e9b7377")); Packet packet = null; do { packet = dec.decodePacket(conn, state, in); } while (packet == null); assertNotNull(packet); assertTrue(packet.getMessage() instanceof Notify); do { packet = dec.decodePacket(conn, state, in); } while (packet == null); assertNotNull(packet); assertTrue(packet.getMessage() instanceof AudioData); }
Example #4
Source File: StreamingProxy.java From red5-client with Apache License 2.0 | 6 votes |
@Override public void onStreamEvent(Notify notify) { log.debug("onStreamEvent: {}", notify); ObjectMap<?, ?> map = (ObjectMap<?, ?>) notify.getCall().getArguments()[0]; String code = (String) map.get("code"); log.debug("<:{}", code); if (StatusCodes.NS_PUBLISH_START.equals(code)) { setState(StreamState.PUBLISHED); IMessage message = null; while ((message = frameBuffer.poll()) != null) { rtmpClient.publishStreamData(streamId, message); } } else if (StatusCodes.NS_UNPUBLISHED_SUCCESS.equals(code)) { setState(StreamState.UNPUBLISHED); } }
Example #5
Source File: AxisTest.java From red5-rtsp-restreamer with Apache License 2.0 | 6 votes |
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 #6
Source File: BandwidthChecker.java From red5-rtsp-restreamer with Apache License 2.0 | 6 votes |
public void packetReceived(IBroadcastStream arg0, IStreamPacket packet) { if (done) { arg0.removeStreamListener(this); return; } messages = Red5.getConnectionLocal().getWrittenMessages() + Red5.getConnectionLocal().getReadMessages(); bytesUp = Red5.getConnectionLocal().getReadBytes(); bytesDown = Red5.getConnectionLocal().getWrittenBytes(); if (packet instanceof Notify) { endpoint().invoke("onBWChunk", new Object[] { chunk }); chunks++; // Input reader = new Input(((Notify)packet).getData()); // reader.readDataType();//string // String method=reader.readString(null); // reader.readDataType();//object // Map invokeData= (Map) reader.readMap(new Deserializer(), null); // System.out.println(method+""+invokeData.get("data").toString()); } }
Example #7
Source File: RTMPProtocolDecoder.java From red5-server-common with Apache License 2.0 | 6 votes |
/** * Sets incoming connection parameters and / or returns encoded parameters for use in a call. * * @param in * @param notify * @param input * @return parameters array */ private Object[] handleParameters(IoBuffer in, Notify notify, Input input) { Object[] params = new Object[] {}; List<Object> paramList = new ArrayList<>(); final Object obj = Deserializer.deserialize(input, Object.class); if (obj instanceof Map) { // Before the actual parameters we sometimes (connect) get a map of parameters, this is usually null, but if set should be // passed to the connection object. @SuppressWarnings("unchecked") final Map<String, Object> connParams = (Map<String, Object>) obj; notify.setConnectionParams(connParams); } else if (obj != null) { paramList.add(obj); } while (in.hasRemaining()) { paramList.add(Deserializer.deserialize(input, Object.class)); } params = paramList.toArray(); if (log.isDebugEnabled()) { log.debug("Num params: {}", paramList.size()); for (int i = 0; i < params.length; i++) { log.debug(" > {}: {}", i, params[i]); } } return params; }
Example #8
Source File: PlayEngine.java From red5-server-common with Apache License 2.0 | 5 votes |
/** * 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 #9
Source File: ClientTest.java From red5-client with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected void onCommand(RTMPConnection conn, Channel channel, Header header, Notify notify) { super.onCommand(conn, channel, header, notify); System.out.println("onInvoke - header: " + header.toString() + " notify: " + notify.toString()); Object obj = notify.getCall().getArguments().length > 0 ? notify.getCall().getArguments()[0] : null; if (obj instanceof Map) { Map<String, String> map = (Map<String, String>) obj; String code = map.get("code"); if (StatusCodes.NS_PLAY_STOP.equals(code)) { finished = true; disconnect(); System.out.println("Disconnected"); } } }
Example #10
Source File: ICYStream.java From red5-rtsp-restreamer with Apache License 2.0 | 5 votes |
public Notify getMetaData() { if (_metaDataEvent != null) { return _metaDataEvent; } return null; }
Example #11
Source File: AbstractStream.java From red5-server-common with Apache License 2.0 | 5 votes |
/** * Returns a copy of the metadata for the associated stream, if it exists. * * @return stream meta data */ public Notify getMetaData() { Notify md = metaData.get(); if (md != null) { try { return md.duplicate(); } catch (Exception e) { } } return md; }
Example #12
Source File: ClientBroadcastStream.java From red5-server-common with Apache License 2.0 | 5 votes |
/** * 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 #13
Source File: BaseRTMPHandler.java From red5-server-common with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ public void messageReceived(RTMPConnection conn, Packet packet) throws Exception { log.trace("messageReceived connection: {}", conn.getSessionId()); if (conn != null) { IRTMPEvent message = null; try { message = packet.getMessage(); final Header header = packet.getHeader(); final Number streamId = header.getStreamId(); final Channel channel = conn.getChannel(header.getChannelId()); final IClientStream stream = conn.getStreamById(streamId); if (log.isTraceEnabled()) { log.trace("Message received - header: {}", header); } // set stream id on the connection conn.setStreamId(streamId); // increase number of received messages conn.messageReceived(); // set the source of the message message.setSource(conn); // process based on data type final byte headerDataType = header.getDataType(); if (log.isTraceEnabled()) { log.trace("Header / message data type: {}", headerDataType); } switch (headerDataType) { case TYPE_AGGREGATE: log.debug("Aggregate type data - header timer: {} size: {}", header.getTimer(), header.getSize()); case TYPE_AUDIO_DATA: case TYPE_VIDEO_DATA: // mark the event as from a live source // log.trace("Marking message as originating from a Live source"); message.setSourceType(Constants.SOURCE_TYPE_LIVE); // NOTE: If we respond to "publish" with "NetStream.Publish.BadName", // the client sends a few stream packets before stopping. We need to ignore them if (stream != null) { ((IEventDispatcher) stream).dispatchEvent(message); } break; case TYPE_FLEX_SHARED_OBJECT: case TYPE_SHARED_OBJECT: onSharedObject(conn, channel, header, (SharedObjectMessage) message); break; case TYPE_INVOKE: case TYPE_FLEX_MESSAGE: onCommand(conn, channel, header, (Invoke) message); IPendingServiceCall call = ((Invoke) message).getCall(); if (message.getHeader().getStreamId().intValue() != 0 && call.getServiceName() == null && StreamAction.PUBLISH.equals(call.getServiceMethodName())) { if (stream != null) { // Only dispatch if stream really was created ((IEventDispatcher) stream).dispatchEvent(message); } } break; case TYPE_NOTIFY: // like an invoke, but does not return anything and has a invoke / transaction id of 0 case TYPE_FLEX_STREAM_SEND: if (((Notify) message).getData() != null && stream != null) { // Stream metadata ((IEventDispatcher) stream).dispatchEvent(message); } else { onCommand(conn, channel, header, (Notify) message); } break; case TYPE_PING: onPing(conn, channel, header, (Ping) message); break; case TYPE_BYTES_READ: onStreamBytesRead(conn, channel, header, (BytesRead) message); break; case TYPE_CHUNK_SIZE: onChunkSize(conn, channel, header, (ChunkSize) message); break; case Constants.TYPE_CLIENT_BANDWIDTH: // onBWDone / peer bw log.debug("Client bandwidth: {}", message); onClientBandwidth(conn, channel, (ClientBW) message); break; case Constants.TYPE_SERVER_BANDWIDTH: // window ack size log.debug("Server bandwidth: {}", message); onServerBandwidth(conn, channel, (ServerBW) message); break; default: log.debug("Unknown type: {}", header.getDataType()); } if (message instanceof Unknown) { log.info("Message type unknown: {}", message); } } catch (Throwable t) { log.error("Exception", t); } // XXX this may be causing 'missing' data if previous methods are not making copies before buffering etc.. if (message != null) { message.release(); } } }
Example #14
Source File: RTMPProtocolEncoder.java From red5-server-common with Apache License 2.0 | 4 votes |
public IoBuffer encodeStreamMetadata(Notify metaData) { final IoBuffer result = metaData.getData(); return result; }
Example #15
Source File: RTMPProtocolEncoder.java From red5-server-common with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ public IoBuffer encodeNotify(Notify notify) { return encodeCommand(notify); }
Example #16
Source File: RTMPProtocolEncoder.java From red5-server-common with Apache License 2.0 | 4 votes |
/** * Encode message. * * @param header * RTMP message header * @param message * RTMP message (event) * @return Encoded message data */ public IoBuffer encodeMessage(Header header, IRTMPEvent message) { IServiceCall call = null; switch (header.getDataType()) { case TYPE_CHUNK_SIZE: return encodeChunkSize((ChunkSize) message); case TYPE_INVOKE: log.trace("Invoke {}", message); call = ((Invoke) message).getCall(); if (call != null) { log.debug("{}", call.toString()); Object[] args = call.getArguments(); if (args != null && args.length > 0) { Object a0 = args[0]; if (a0 instanceof Status) { Status status = (Status) a0; //code: NetStream.Seek.Notify if (StatusCodes.NS_SEEK_NOTIFY.equals(status.getCode())) { //desc: Seeking 25000 (stream ID: 1). int seekTime = Integer.valueOf(status.getDescription().split(" ")[1]); log.trace("Seek to time: {}", seekTime); // TODO make sure this works on stream ids > 1 //audio and video channels int[] channels = new int[] { 5, 6 }; //if its a seek notification, reset the "mapping" for audio (5) and video (6) RTMP rtmp = ((RTMPConnection) Red5.getConnectionLocal()).getState(); for (int channelId : channels) { LiveTimestampMapping mapping = rtmp.getLastTimestampMapping(channelId); if (mapping != null) { long timestamp = mapping.getClockStartTime() + (seekTime & 0xFFFFFFFFL); log.trace("Setting last stream time to: {}", timestamp); mapping.setLastStreamTime(timestamp); } else { log.trace("No ts mapping for channel id: {}", channelId); } } } } } } return encodeInvoke((Invoke) message); case TYPE_NOTIFY: log.trace("Notify {}", message); call = ((Notify) message).getCall(); if (call == null) { return encodeStreamMetadata((Notify) message); } else { return encodeNotify((Notify) message); } case TYPE_PING: if (message instanceof SetBuffer) { return encodePing((SetBuffer) message); } else if (message instanceof SWFResponse) { return encodePing((SWFResponse) message); } else { return encodePing((Ping) message); } case TYPE_BYTES_READ: return encodeBytesRead((BytesRead) message); case TYPE_AGGREGATE: log.trace("Encode aggregate message"); return encodeAggregate((Aggregate) message); case TYPE_AUDIO_DATA: log.trace("Encode audio message"); return encodeAudioData((AudioData) message); case TYPE_VIDEO_DATA: log.trace("Encode video message"); return encodeVideoData((VideoData) message); case TYPE_FLEX_SHARED_OBJECT: return encodeFlexSharedObject((ISharedObjectMessage) message); case TYPE_SHARED_OBJECT: return encodeSharedObject((ISharedObjectMessage) message); case TYPE_SERVER_BANDWIDTH: return encodeServerBW((ServerBW) message); case TYPE_CLIENT_BANDWIDTH: return encodeClientBW((ClientBW) message); case TYPE_FLEX_MESSAGE: return encodeFlexMessage((FlexMessage) message); case TYPE_FLEX_STREAM_SEND: return encodeFlexStreamSend((FlexStreamSend) message); default: log.warn("Unknown object type: {}", header.getDataType()); } return null; }
Example #17
Source File: RTMPClientTest.java From red5-client with Apache License 2.0 | 4 votes |
@Test public void test26() throws InterruptedException { client.setStreamEventHandler(new INetStreamEventHandler() { @Override public void onStreamEvent(Notify notify) { log.info("ClientStream.dispachEvent: {}", notify); } }); client.setServiceProvider(new ClientMethodHander()); client.setConnectionClosedHandler(new Runnable() { @Override public void run() { System.out.println("Connection closed"); } }); client.setExceptionHandler(new ClientExceptionHandler() { @Override public void handleException(Throwable throwable) { throwable.printStackTrace(); } }); IPendingServiceCallback connectCallback = new IPendingServiceCallback() { @Override public void resultReceived(IPendingServiceCall call) { log.info("connectCallback"); ObjectMap<?, ?> map = (ObjectMap<?, ?>) call.getResult(); String code = (String) map.get("code"); log.info("Response code: {}", code); if ("NetConnection.Connect.Rejected".equals(code)) { System.out.printf("Rejected: %s\n", map.get("description")); client.disconnect(); } else if ("NetConnection.Connect.Success".equals(code)) { // 1. Wait for onBWDone timer.schedule(new BandwidthStatusTask(), 2000L); } } }; /* * client.connect("localhost", 1935, "live/remote/0586e318-6277-11e3-adc2-22000a1d91fe", new IPendingServiceCallback() { * @Override public void resultReceived(IPendingServiceCall result) { System.out.println("resultReceived: " + result); ObjectMap<?, ?> map = (ObjectMap<?, ?>) result.getResult(); * String code = (String) map.get("code"); System.out.printf("Response code: %s\n", code); if ("NetConnection.Connect.Rejected".equals(code)) { System.out.printf("Rejected: %s\n", * map.get("description")); client.disconnect(); } else if ("NetConnection.Connect.Success".equals(code)) { System.out.println("success: " + result.isSuccess()); ArrayList<Object> * list = new ArrayList<>(); list.add(new Object[] { "fujifilm-x100s-video-test-1080p-full-hd-hdmp4_720.mp4" }); list.add(new Object[] { * "canon-500d-test-video-720-hd-30-fr-hdmp4_720.mp4" }); Object[] params = { "64", "cc-video-processed/", list }; //Object[] params = { "64", "cc-video-processed/" }; * client.invoke("loadPlaylist", params, new IPendingServiceCallback() { * @Override public void resultReceived(IPendingServiceCall result) { System.out.println(result); } }); } } }); */ client.connect("localhost", 1935, "vod", connectCallback); do { try { Thread.sleep(10000); } catch (InterruptedException e) { } } while (!client.conn.isClosed()); log.debug("Client not connected"); timer.cancel(); log.info("Exit"); }
Example #18
Source File: RTMPProtocolEncoder.java From red5-server-common with Apache License 2.0 | 3 votes |
/** * Encode notification event. * * @param invoke * Notification event * @return Encoded event data */ protected IoBuffer encodeCommand(Notify invoke) { IoBuffer out = IoBuffer.allocate(1024); out.setAutoExpand(true); encodeCommand(out, invoke); return out; }
Example #19
Source File: IEventEncoder.java From red5-server-common with Apache License 2.0 | 2 votes |
/** * Encodes Notify event to byte buffer. * * @param notify * Notify event * @return Byte buffer */ public abstract IoBuffer encodeNotify(Notify notify);
Example #20
Source File: ICYStream.java From red5-rtsp-restreamer with Apache License 2.0 | 2 votes |
public void setMetaDataEvent(Notify event) { _metaDataEvent = event; }
Example #21
Source File: IBroadcastStream.java From red5-server-common with Apache License 2.0 | 2 votes |
/** * Returns the metadata for the associated stream, if it exists. * * @return stream meta data */ public Notify getMetaData();
Example #22
Source File: AbstractStream.java From red5-server-common with Apache License 2.0 | 2 votes |
/** * Set the metadata. * * @param metaData * stream meta data */ public void setMetaData(Notify metaData) { this.metaData.set(metaData); }
Example #23
Source File: INetStreamEventHandler.java From red5-client with Apache License 2.0 | votes |
void onStreamEvent(Notify notify);