本文整理汇总了Java中org.red5.server.net.rtmp.message.Header类的典型用法代码示例。如果您正苦于以下问题:Java Header类的具体用法?Java Header怎么用?Java Header使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Header类属于org.red5.server.net.rtmp.message包,在下文中一共展示了Header类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHeaderType
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/**
* Determine type of header to use.
*
* @param header RTMP message header
* @param lastHeader Previous header
* @return Header type to use
*/
private byte getHeaderType(final Header header, final Header lastHeader) {
//int lastFullTs = ((RTMPConnection) Red5.getConnectionLocal()).getState().getLastFullTimestampWritten(header.getChannelId());
if (lastHeader == null || header.getStreamId() != lastHeader.getStreamId() || header.getTimer() < lastHeader.getTimer()) {
// new header mark if header for another stream
return HEADER_NEW;
} else if (header.getSize() != lastHeader.getSize() || header.getDataType() != lastHeader.getDataType()) {
// same source header if last header data type or size differ
return HEADER_SAME_SOURCE;
} else if (header.getTimer() != lastHeader.getTimer()) {
// timer change marker if there's time gap between header time stamps
return HEADER_TIMER_CHANGE;
}
// continue encoding
return HEADER_CONTINUE;
}
示例2: write
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/**
* Writes packet from event data to RTMP connection and stream id.
*
* @param event
* Event data
* @param streamId
* Stream id
*/
private void write(IRTMPEvent event, Number streamId) {
log.trace("write to stream id: {} channel: {}", streamId, id);
final Header header = new Header();
final Packet packet = new Packet(header, event);
// set the channel id
header.setChannelId(id);
int ts = event.getTimestamp();
if (ts != 0) {
header.setTimer(event.getTimestamp());
}
header.setStreamId(streamId);
header.setDataType(event.getDataType());
// should use RTMPConnection specific method..
//log.trace("Connection type for write: {}", connection.getClass().getName());
connection.write(packet);
}
示例3: messageReceived
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void messageReceived(IoSession session, Object in) {
if (log.isDebugEnabled()) {
if (in instanceof IoBuffer) {
log.debug("Handskake");
return;
}
try {
final Packet packet = (Packet) in;
final Object message = packet.getMessage();
final Header source = packet.getHeader();
log.debug("{}", source);
log.debug("{}", message);
} catch (RuntimeException e) {
log.error("Exception", e);
}
}
}
示例4: onSharedObject
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void onSharedObject(RTMPConnection conn, Channel channel, Header source, SharedObjectMessage object) {
log.trace("onSharedObject");
ClientSharedObject so = sharedObjects.get(object.getName());
if (so != null) {
if (so.isPersistent() == object.isPersistent()) {
log.debug("Received SO request: {}", object);
so.dispatchEvent(object);
} else {
log.error("Ignoring request for wrong-persistent SO: {}", object);
}
} else {
log.error("Ignoring request for non-existend SO: {}", object);
}
}
示例5: onCommand
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
@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");
}
}
}
示例6: onCommand
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
@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");
}
}
}
示例7: write
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/**
* Writes packet from event data to RTMP connection and stream id.
*
* @param event Event data
* @param streamId Stream id
*/
private void write(IRTMPEvent event, int streamId) {
log.trace("write channel: {} stream id: {}", id, streamId);
final Header header = new Header();
final Packet packet = new Packet(header, event);
header.setChannelId(id);
int ts = event.getTimestamp();
if (ts != 0) {
header.setTimer(event.getTimestamp());
} else {
// TODO may need to add generated timestamps at some point
// int timestamp = connection.getTimer();
// header.setTimerBase(timestamp);
// event.setTimestamp(timestamp);
}
header.setStreamId(streamId);
header.setDataType(event.getDataType());
// should use RTMPConnection specific method..
//log.trace("Connection type for write: {}", connection.getClass().getName());
connection.write(packet);
}
示例8: onChunkSize
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void onChunkSize(RTMPConnection conn, Channel channel, Header source, ChunkSize chunkSize) {
for (IClientStream stream : conn.getStreams()) {
if (stream instanceof IClientBroadcastStream) {
IClientBroadcastStream bs = (IClientBroadcastStream) stream;
IBroadcastScope scope = bs.getScope().getBroadcastScope(bs.getPublishedName());
if (scope == null) {
continue;
}
OOBControlMessage setChunkSize = new OOBControlMessage();
setChunkSize.setTarget("ClientBroadcastStream");
setChunkSize.setServiceName("chunkSize");
if (setChunkSize.getServiceParamMap() == null) {
setChunkSize.setServiceParamMap(new HashMap<String, Object>());
}
setChunkSize.getServiceParamMap().put("chunkSize", chunkSize.getSize());
scope.sendOOBControlMessage((IConsumer) null, setChunkSize);
log.debug("Sending chunksize {} to {}", chunkSize, bs.getProvider());
}
}
}
示例9: messageReceived
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void messageReceived(IoSession session, Object in) {
if (log.isDebugEnabled()) {
if (in instanceof IoBuffer) {
log.debug("Handskake");
return;
}
try {
final Packet packet = (Packet) in;
final Object message = packet.getMessage();
final Header source = packet.getHeader();
log.debug("{}", source);
log.debug("{}", message);
} catch (RuntimeException e) {
log.error("Exception", e);
}
}
}
示例10: buildVideoFrame
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/**
* Builds a video frame (non-config).
*
* <pre>
* flv tagged h264 encoded bytes resemble this sequence: 23 01 00 00 00 00 00 00 02 09 16 00 00 00 15 06 00...
* |--Header--|--Presentation offset--|--Size of packet + 1 --|--Encoded data
* 0x17 0x01 0x0 0x0 0x0 0x00 0x00 0x00 0x02 0x0916 bytes of data
* </pre>
*
* @param timestamp
* @param frameSize
* @return
*/
private static VideoData buildVideoFrame(int timestamp, int frameSize) {
log.debug("buildVideoFrame - slice count: {}", frameSlices.size());
// determine if the set of slices are of IDR type
boolean isIdr = (frameSlices.getFirst()[4] & 0x1f) == 7; // (SPS will actual be the first slice, if its an IDR set)
// size the flv video data array
IoBuffer framedData = IoBuffer.allocate(frameSize + 5 + 1); // 5 bytes header and 1 byte trailer
framedData.setAutoExpand(true);
log.debug("Frame data initial size: {}", framedData.limit());
// write prefix bytes
framedData.put((byte) (isIdr ? 0x17 : 0x27)); // 0x10 - key frame; 0x07 - H264_CODEC_ID
framedData.put((byte) 0x01); // 0: AVC sequence header; 1: AVC NALU; 2: AVC end of sequence
// presentation off set
framedData.put((byte) 0);
framedData.put((byte) 0);
framedData.put((byte) 0);
// copy in encoded bytes
for (byte[] frame : frameSlices) {
framedData.put(frame);
}
// write end byte
framedData.put((byte) 0);
// flip it
framedData.flip();
log.debug("Frame data final size: {}", framedData.limit());
// create the video data obj
VideoData video = new VideoData(framedData);
video.setHeader(new Header());
video.getHeader().setTimer((int) timestamp);
video.setTimestamp((int) timestamp);
return video;
}
示例11: notifyBroadcastStart
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/**
* 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);
}
示例12: calculateHeaderSize
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/**
* Calculate number of bytes necessary to encode the header.
*
* @param header
* RTMP message header
* @param lastHeader
* Previous header
* @return Calculated size
*/
private int calculateHeaderSize(final Header header, final Header lastHeader) {
final byte headerType = getHeaderType(header, lastHeader);
int channelIdAdd = 0;
int channelId = header.getChannelId();
if (channelId > 320) {
channelIdAdd = 2;
} else if (channelId > 63) {
channelIdAdd = 1;
}
return RTMPUtils.getHeaderLength(headerType) + channelIdAdd;
}
示例13: onChunkSize
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void onChunkSize(RTMPConnection conn, Channel channel, Header source, ChunkSize chunkSize) {
int requestedChunkSize = chunkSize.getSize();
log.debug("Chunk size: {}", requestedChunkSize);
// set chunk size on the connection
RTMP state = conn.getState();
// set only the read chunk size since it came from the client
state.setReadChunkSize(requestedChunkSize);
//state.setWriteChunkSize(requestedChunkSize);
// set on each of the streams
for (IClientStream stream : conn.getStreams()) {
if (stream instanceof IClientBroadcastStream) {
IClientBroadcastStream bs = (IClientBroadcastStream) stream;
IBroadcastScope scope = bs.getScope().getBroadcastScope(bs.getPublishedName());
if (scope == null) {
continue;
}
OOBControlMessage setChunkSize = new OOBControlMessage();
setChunkSize.setTarget("ClientBroadcastStream");
setChunkSize.setServiceName("chunkSize");
if (setChunkSize.getServiceParamMap() == null) {
setChunkSize.setServiceParamMap(new HashMap<String, Object>());
}
setChunkSize.getServiceParamMap().put("chunkSize", requestedChunkSize);
scope.sendOOBControlMessage((IConsumer) null, setChunkSize);
log.debug("Sending chunksize {} to {}", chunkSize, bs.getProvider());
}
}
}
示例14: onPing
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void onPing(RTMPConnection conn, Channel channel, Header source, Ping ping) {
switch (ping.getEventType()) {
case Ping.CLIENT_BUFFER:
SetBuffer setBuffer = (SetBuffer) ping;
// get the stream id
int streamId = setBuffer.getStreamId();
// get requested buffer size in milliseconds
int buffer = setBuffer.getBufferLength();
log.debug("Client sent a buffer size: {} ms for stream id: {}", buffer, streamId);
IClientStream stream = null;
if (streamId != 0) {
// The client wants to set the buffer time
stream = conn.getStreamById(streamId);
if (stream != null) {
stream.setClientBufferDuration(buffer);
log.trace("Stream type: {}", stream.getClass().getName());
}
}
//catch-all to make sure buffer size is set
if (stream == null) {
// Remember buffer time until stream is created
conn.rememberStreamBufferDuration(streamId, buffer);
log.debug("Remembering client buffer on stream: {}", buffer);
}
break;
case Ping.PONG_SERVER:
// This is the response to an IConnection.ping request
conn.pingReceived(ping);
break;
default:
log.warn("Unhandled ping: {}", ping);
}
}
示例15: getAVCDecoderConfig
import org.red5.server.net.rtmp.message.Header; //导入依赖的package包/类
public IRTMPEvent getAVCDecoderConfig() {
IoBuffer buffV = IoBuffer.allocate(_pCodecSetup.length);
buffV.setAutoExpand(true);
for (int p = 0; p < _pCodecSetup.length; p++)
buffV.put((byte) _pCodecSetup[p]);
buffV.flip();
buffV.position(0);
IRTMPEvent video = new VideoData(buffV);
video.setHeader(new Header());
return video;
}