package org.red5.server.stream;
/*
* RED5 Open Source Flash Server - http://code.google.com/p/red5/
*
* Copyright (c) 2006-2010 by respective authors (see below). All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 2.1 of the License, or (at your option) any later
* version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.mina.core.buffer.IoBuffer;
import org.red5.io.amf.Output;
import org.red5.io.object.Serializer;
import org.red5.logging.Red5LoggerFactory;
import org.red5.server.api.IScope;
import org.red5.server.api.scheduling.IScheduledJob;
import org.red5.server.api.scheduling.ISchedulingService;
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.api.stream.IPlayItem;
import org.red5.server.api.stream.IPlaylistSubscriberStream;
import org.red5.server.api.stream.IStreamCodecInfo;
import org.red5.server.api.stream.ISubscriberStream;
import org.red5.server.api.stream.IVideoStreamCodec;
import org.red5.server.api.stream.OperationNotSupportedException;
import org.red5.server.api.stream.StreamState;
import org.red5.server.messaging.AbstractMessage;
import org.red5.server.messaging.IFilter;
import org.red5.server.messaging.IMessage;
import org.red5.server.messaging.IMessageComponent;
import org.red5.server.messaging.IMessageInput;
import org.red5.server.messaging.IMessageOutput;
import org.red5.server.messaging.IPassive;
import org.red5.server.messaging.IPipe;
import org.red5.server.messaging.IPipeConnectionListener;
import org.red5.server.messaging.IProvider;
import org.red5.server.messaging.IPushableConsumer;
import org.red5.server.messaging.OOBControlMessage;
import org.red5.server.messaging.PipeConnectionEvent;
import org.red5.server.net.rtmp.event.Aggregate;
import org.red5.server.net.rtmp.event.AudioData;
import org.red5.server.net.rtmp.event.IRTMPEvent;
import org.red5.server.net.rtmp.event.Notify;
import org.red5.server.net.rtmp.event.Ping;
import org.red5.server.net.rtmp.event.VideoData;
import org.red5.server.net.rtmp.event.VideoData.FrameType;
import org.red5.server.net.rtmp.message.Constants;
import org.red5.server.net.rtmp.message.Header;
import org.red5.server.net.rtmp.status.Status;
import org.red5.server.net.rtmp.status.StatusCodes;
import org.red5.server.stream.codec.StreamCodecInfo;
import org.red5.server.stream.message.RTMPMessage;
import org.red5.server.stream.message.ResetMessage;
import org.red5.server.stream.message.StatusMessage;
import org.slf4j.Logger;
/**
* A play engine for playing an IPlayItem.
*
* @author The Red5 Project (red5@osflash.org)
* @author Steven Gong
* @author Paul Gregoire (mondain@gmail.com)
* @author Dan Rossi
* @author Tiago Daniel Jacobs (tiago@imdt.com.br)
*/
public final class PlayEngine implements IFilter, IPushableConsumer, IPipeConnectionListener {
private static final Logger log = Red5LoggerFactory.getLogger(PlayEngine.class);
private IMessageInput msgIn;
private IMessageOutput msgOut;
private final ISubscriberStream subscriberStream;
private ISchedulingService schedulingService;
private IConsumerService consumerService;
private IProviderService providerService;
private int streamId;
/**
* Receive video?
*/
private boolean receiveVideo = true;
/**
* Receive audio?
*/
private boolean receiveAudio = true;
private boolean pullMode;
private String waitLiveJob;
private boolean waiting;
/**
* timestamp of first sent packet
*/
private int streamStartTS;
private IPlayItem currentItem;
private RTMPMessage pendingMessage;
/**
* Interval in ms to check for buffer underruns in VOD streams.
*/
private int bufferCheckInterval = 0;
/**
* Number of pending messages at which a <code>NetStream.Play.InsufficientBW</code>
* message is generated for VOD streams.
*/
private int underrunTrigger = 10;
/**
* threshold for number of pending video frames
*/
private int maxPendingVideoFramesThreshold = 10;
/**
* if we have more than 1 pending video frames, but less than maxPendingVideoFrames,
* continue sending until there are this many sequential frames with more than 1
* pending
*/
private int maxSequentialPendingVideoFrames = 10;
/**
* the number of sequential video frames with > 0 pending frames
*/
private int numSequentialPendingVideoFrames = 0;
/**
* State machine for video frame dropping in live streams
*/
private IFrameDropper videoFrameDropper = new VideoFrameDropper();
private int timestampOffset = 0;
/**
* Timestamp of the last message sent to the client.
*/
private int lastMessageTs = -1;
/**
* Number of bytes sent.
*/
private AtomicLong bytesSent = new AtomicLong(0);
/**
* Start time of stream playback.
* It's not a time when the stream is being played but
* the time when the stream should be played if it's played
* from the very beginning.
* Eg. A stream is played at timestamp 5s on 1:00:05. The
* playbackStart is 1:00:00.
*/
private long playbackStart;
/**
* Scheduled future job that makes sure messages are sent to the client.
*/
private volatile ScheduledFuture<?> pullAndPushFuture = null;
/**
* Monitor to guard setup and teardown of pull/push thread.
*/
private Object pullAndPushMonitor = new Object();
/**
* Monitor guarding completion of a given push/pull run.
* Used to wait for job cancellation to finish.
*/
private Object doingPullMonitor = new Object();
/**
* Offset in ms the stream started.
*/
private int streamOffset;
/**
* Timestamp when buffer should be checked for underruns next.
*/
private long nextCheckBufferUnderrun;
/**
* Send blank audio packet next?
*/
private boolean sendBlankAudio;
/**
* decision: 0 for Live, 1 for File, 2 for Wait, 3 for N/A
*/
private int playDecision = 3;
/**
* List of pending operations
*/
private LinkedList<Runnable> pendingOperations = null;
/**
* Constructs a new PlayEngine.
*/
private PlayEngine(Builder builder) {
subscriberStream = builder.subscriberStream;
schedulingService = builder.schedulingService;
consumerService = builder.consumerService;
providerService = builder.providerService;
//
streamId = subscriberStream.getStreamId();
pendingOperations = new LinkedList<Runnable>();
}
/**
* Builder pattern
*/
public final static class Builder {
//Required for play engine
private ISubscriberStream subscriberStream;
//Required for play engine
private ISchedulingService schedulingService;
//Required for play engine
private IConsumerService consumerService;
//Required for play engine
private IProviderService providerService;
public Builder(ISubscriberStream subscriberStream, ISchedulingService schedulingService, IConsumerService consumerService, IProviderService providerService) {
this.subscriberStream = subscriberStream;
this.schedulingService = schedulingService;
this.consumerService = consumerService;
this.providerService = providerService;
}
public PlayEngine build() {
return new PlayEngine(this);
}
}
public void setBufferCheckInterval(int bufferCheckInterval) {
this.bufferCheckInterval = bufferCheckInterval;
}
public void setUnderru
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Red5项目部署到tomcat (1236个子文件)
PlayEngine.class 35KB
MP4Reader.class 27KB
MultiThreadedApplicationAdapter.class 27KB
RTMPProtocolEncoder.class 27KB
RTMPProtocolDecoder.class 26KB
RTMPConnection.class 24KB
Scope.class 23KB
ClientBroadcastStream.class 23KB
BaseRTMPClientHandler.class 21KB
RTMPHandler.class 21KB
ServerStream.class 20KB
Input.class 20KB
SharedObjectScope.class 19KB
MP4Atom.class 17KB
M4AReader.class 17KB
StreamService.class 16KB
PlaylistSubscriberStream.class 16KB
Output.class 16KB
SharedObject.class 15KB
FLVReader.class 15KB
Input.class 15KB
FileConsumer.class 15KB
MP3Reader.class 15KB
FlexMessagingService.class 14KB
FilePersistence.class 14KB
RTMPTServlet.class 13KB
Output.class 13KB
DSRemotingClient.class 13KB
ClassLoaderBuilder.class 13KB
RemotingConnection.class 13KB
RemotingClient.class 12KB
JMXAgent.class 12KB
ClientSharedObject.class 12KB
ConversionUtils.class 12KB
FileUtil.class 11KB
HexDump.class 10KB
BaseRTMPHandler.class 10KB
Installer.class 10KB
RTMPHandshake.class 10KB
ContextLoader.class 10KB
AMFGatewayServlet.class 10KB
RTMPTClientConnector.class 10KB
BaseConnection.class 10KB
MetaService.class 9KB
ProviderService.class 9KB
OutboundHandshake.class 9KB
SingleItemSubscriberStream.class 9KB
Server.class 9KB
TrafficShapingFilter.class 9KB
Context.class 8KB
RTMPMinaIoHandler.class 8KB
Client.class 8KB
EdgeRTMPHandler.class 8KB
OriginMRTMPHandler.class 8KB
ConnectionConsumer.class 8KB
EhCacheImpl.class 8KB
RTMPMinaTransport.class 8KB
AbstractMessage.class 8KB
FLVWriter.class 8KB
RTMP.class 8KB
ByteArray.class 8KB
RemotingProtocolEncoder.class 8KB
AbstractPipe.class 8KB
RTMPMinaConnection.class 8KB
WarLoaderServlet.class 8KB
Aggregate.class 8KB
InboundHandshake.class 8KB
DebugProxyHandler.class 8KB
Serializer.class 7KB
ServiceInvoker.class 7KB
FileProvider.class 7KB
QuartzSchedulingService.class 7KB
ScopeUtils.class 7KB
RemotingProtocolDecoder.class 7KB
PlayEngine$3.class 7KB
BaseRTMPTConnection.class 7KB
MRTMPMinaTransport.class 7KB
WebScope.class 7KB
FileKeyFrameMetaCache.class 7KB
XmlRpcScopeStatistics.class 7KB
CacheImpl.class 6KB
StatusObjectService.class 6KB
FLV.class 6KB
ServerClientDetection.class 6KB
ServiceUtils.class 6KB
EdgeMRTMPHandler.class 6KB
MRTMPProtocolDecoder.class 6KB
StreamingProxy.class 6KB
AttributeStore.class 6KB
RecordSet.class 6KB
Stax2DomBuilder.class 6KB
Notify.class 6KB
RTMPSMinaIoHandler.class 6KB
VideoData.class 6KB
SharedObjectMessage.class 6KB
JMXFactory.class 6KB
GroovyScriptFactory.class 6KB
RTMPEIoFilter.class 5KB
BroadcastScope.class 5KB
UnsignedLong.class 5KB
共 1236 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
- yan-yangyangyang2016-04-21很好奥,不过不是最新的,现在csdn有最新的代码了,还是谢谢你
- star2452014-06-24集成到tomcat中能进行调试了
- 黑罗仔仔2015-12-08环境为myeclipse,如果是eclipse需要稍作修改文件,拿来就能用,适合初学者,不亏!
- 一再落魄街中2018-04-22集成到tomcat中能进行调试了
小婵秋
- 粉丝: 77
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功