winlin

Merge branch 'srs.master'

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<actionScriptProperties analytics="false" mainApplicationPath="srs_reuse_conn.as" projectUUID="ccfd5c0a-9963-467a-8739-75ac79faaef5" version="10">
<compiler additionalCompilerArguments="-locale en_US" autoRSLOrdering="true" copyDependentFiles="true" fteInMXComponents="false" generateAccessible="true" htmlExpressInstall="true" htmlGenerate="false" htmlHistoryManagement="true" htmlPlayerVersionCheck="true" includeNetmonSwc="false" outputFolderPath="release" removeUnusedRSL="true" sourceFolderPath="src" strict="true" targetPlayerVersion="0.0.0" useApolloConfig="false" useDebugRSLSwfs="true" verifyDigests="true" warn="true">
<compilerSourcePath/>
<libraryPath defaultLinkType="0">
<libraryPathEntry kind="4" path="">
<excludedEntries>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_charts.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="1" linkType="1" path="${PROJECT_FRAMEWORKS}/locale/{locale}"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/advancedgrids.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/qtp.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_air.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/charts.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/framework.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/mx/mx.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/netmon.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/sparkskins.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/rpc.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/videoPlayer.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/qtp_air.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/datavisualization.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark_dmv.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/flash-integration.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_dmv.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_flashflexkit.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_agent.swc" useDefaultLinkType="false"/>
</excludedEntries>
</libraryPathEntry>
<libraryPathEntry kind="3" linkType="1" path="FlashCS5UI.swc" useDefaultLinkType="false"/>
</libraryPath>
<sourceAttachmentPath/>
</compiler>
<applications>
<application path="srs_reuse_conn.as"/>
</applications>
<modules/>
<buildCSSFiles/>
<flashCatalyst validateFlashCatalystCompatibility="false"/>
</actionScriptProperties>
... ...
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>srs_reuse_conn</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.adobe.flexbuilder.project.flexbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.adobe.flexbuilder.project.actionscriptnature</nature>
</natures>
</projectDescription>
... ...
#Sat Nov 22 18:40:22 CST 2014
eclipse.preferences.version=1
encoding/<project>=utf-8
... ...
package
{
import fl.controls.Button;
import fl.controls.TextInput;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
[SWF(backgroundColor="0xEEEEEE",frameRate="30",width="1024",height="576")]
public class srs_reuse_conn extends Sprite
{
public function srs_reuse_conn()
{
if (stage) {
onAddedToStage(null);
} else {
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
}
private function onAddedToStage(evt:Event):void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var txtUrl:TextInput = new TextInput();
var btnConn:Button = new Button();
var btnPlay:Button = new Button();
txtUrl.x = 10;
txtUrl.y = 10;
txtUrl.width = 400;
txtUrl.text = "rtmp://dev/live/livestream";
addChild(txtUrl);
btnConn.label = "Connect";
btnConn.x = txtUrl.x + txtUrl.width + 10;
btnConn.y = txtUrl.y;
btnConn.width = 100;
addChild(btnConn);
btnPlay.label = "Play";
btnPlay.x = btnConn.x + btnConn.width + 10;
btnPlay.y = btnConn.y;
btnPlay.width = 100;
addChild(btnPlay);
var video:Video = new Video();
video.x = txtUrl.x;
video.y = txtUrl.y + txtUrl.height + 10;
addChild(video);
var conn:NetConnection = null;
var stream:NetStream = null;
var tcUrl:Function = function():String {
var url:String = txtUrl.text;
return url.substr(0, url.lastIndexOf("/"));
}
var streamName:Function = function():String {
var url:String = txtUrl.text;
return url.substr(tcUrl().length + 1);
}
var closeConnection:Function = function():void {
if (stream) {
stream.close();
stream = null;
}
if (conn) {
conn.close();
conn = null;
}
btnConn.label = "Connect";
btnPlay.visible = false;
};
btnPlay.visible = false;
btnConn.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
if (btnConn.label == "Connect") {
conn = new NetConnection();
conn.client = {
onBWDone: function():void{}
};
conn.addEventListener(NetStatusEvent.NET_STATUS, function(ne:NetStatusEvent):void {
if (ne.info.code == "NetConnection.Connect.Success") {
btnPlay.visible = true;
} else if (ne.info.code == "NetConnection.Connect.Closed") {
closeConnection();
}
trace(ne.info.code);
});
conn.connect(tcUrl());
btnConn.label = "Close";
} else {
closeConnection();
}
});
btnPlay.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
if (stream) {
stream.close();
stream = null;
}
stream = new NetStream(conn);
stream.client = {
onMetaData: function(metadata:Object):void {
video.width = metadata.width;
video.height = metadata.height;
}
};
video.attachNetStream(stream);
stream.play(streamName());
});
}
}
}
\ No newline at end of file
... ...
... ... @@ -54,6 +54,11 @@ bool SrsRecvThread::empty()
return queue.empty();
}
int SrsRecvThread::size()
{
return (int)queue.size();
}
SrsMessage* SrsRecvThread::pump()
{
srs_assert(!queue.empty());
... ... @@ -79,6 +84,15 @@ int SrsRecvThread::cycle()
{
int ret = ERROR_SUCCESS;
// we only recv one message and then process it,
// for the message may cause the thread to stop,
// when stop, the thread is freed, so the messages
// are dropped.
if (!queue.empty()) {
st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
return ret;
}
SrsMessage* msg = NULL;
if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {
... ... @@ -93,6 +107,10 @@ int SrsRecvThread::cycle()
}
srs_verbose("play loop recv message. ret=%d", ret);
// put into queue, the send thread will get and process it,
// @see SrsRtmpConn::process_play_control_msg
queue.push_back(msg);
return ret;
}
... ...
... ... @@ -54,6 +54,7 @@ public:
virtual ~SrsRecvThread();
public:
virtual bool empty();
virtual int size();
virtual SrsMessage* pump();
public:
virtual int start();
... ...
... ... @@ -514,6 +514,11 @@ int SrsRtmpConn::playing(SrsSource* source)
// stop isolate recv thread
trd.stop();
// warn for the message is dropped.
if (!trd.empty()) {
srs_warn("drop the received %d messages", trd.size());
}
return ret;
}
... ... @@ -549,7 +554,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsRecvThread* trd)
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
while (!trd->empty()) {
SrsMessage* msg = trd->pump();
srs_warn("pump client message to process.");
srs_verbose("pump client message to process.");
if ((ret = process_play_control_msg(consumer, msg)) != ERROR_SUCCESS) {
if (!srs_is_system_control_error(ret)) {
... ...