/** * Push message through pipe * * @param pipe Pipe * @param message Message to push * @throws IOException if message could not be written */ public synchronized void pushMessage(IPipe pipe, IMessage message) throws IOException { if (message instanceof ResetMessage) { startTimestamp = -1; offset += lastTimestamp; return; } else if (message instanceof StatusMessage) { return; } if (!(message instanceof RTMPMessage)) { return; } if (writer == null) { init(); } RTMPMessage rtmpMsg = (RTMPMessage) message; final IRTMPEvent msg = rtmpMsg.getBody(); if (startTimestamp == -1) { startTimestamp = msg.getTimestamp(); } // if we're dealing with a FlexStreamSend IRTMPEvent, this avoids relative timestamp // calculations int timestamp = msg.getTimestamp(); if (!(msg instanceof FlexStreamSend)) { timestamp -= startTimestamp; lastTimestamp = timestamp; } if (timestamp < 0) { log.warn("Skipping message with negative timestamp."); return; } ITag tag = new Tag(); tag.setDataType(msg.getDataType()); // Always add offset since it's needed for "append" publish mode // It adds on disk flv file duration // Search for "offset" in this class constructor tag.setTimestamp(timestamp + offset); if (msg instanceof IStreamData) { IoBuffer data = ((IStreamData) msg).getData().asReadOnlyBuffer(); tag.setBodySize(data.limit()); tag.setBody(data); } try { writer.writeTag(tag); } catch (IOException e) { log.error("error writing tag", e); throw e; } }
/** Reset */ private synchronized void uninit() { if (writer != null) { writer.close(); writer = null; } }