正在显示
9 个修改的文件
包含
209 行增加
和
1 行删除
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| 2 | +<actionScriptProperties analytics="false" mainApplicationPath="srs_reuse_conn.as" projectUUID="ccfd5c0a-9963-467a-8739-75ac79faaef5" version="10"> | ||
| 3 | + <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"> | ||
| 4 | + <compilerSourcePath/> | ||
| 5 | + <libraryPath defaultLinkType="0"> | ||
| 6 | + <libraryPathEntry kind="4" path=""> | ||
| 7 | + <excludedEntries> | ||
| 8 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_charts.swc" useDefaultLinkType="false"/> | ||
| 9 | + <libraryPathEntry kind="1" linkType="1" path="${PROJECT_FRAMEWORKS}/locale/{locale}"/> | ||
| 10 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/advancedgrids.swc" useDefaultLinkType="false"/> | ||
| 11 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/qtp.swc" useDefaultLinkType="false"/> | ||
| 12 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_air.swc" useDefaultLinkType="false"/> | ||
| 13 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/charts.swc" useDefaultLinkType="false"/> | ||
| 14 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/framework.swc" useDefaultLinkType="false"/> | ||
| 15 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/mx/mx.swc" useDefaultLinkType="false"/> | ||
| 16 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/netmon.swc" useDefaultLinkType="false"/> | ||
| 17 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark.swc" useDefaultLinkType="false"/> | ||
| 18 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/sparkskins.swc" useDefaultLinkType="false"/> | ||
| 19 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/rpc.swc" useDefaultLinkType="false"/> | ||
| 20 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/videoPlayer.swc" useDefaultLinkType="false"/> | ||
| 21 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/qtp_air.swc" useDefaultLinkType="false"/> | ||
| 22 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/datavisualization.swc" useDefaultLinkType="false"/> | ||
| 23 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark_dmv.swc" useDefaultLinkType="false"/> | ||
| 24 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation.swc" useDefaultLinkType="false"/> | ||
| 25 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/flash-integration.swc" useDefaultLinkType="false"/> | ||
| 26 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_dmv.swc" useDefaultLinkType="false"/> | ||
| 27 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_flashflexkit.swc" useDefaultLinkType="false"/> | ||
| 28 | + <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_agent.swc" useDefaultLinkType="false"/> | ||
| 29 | + </excludedEntries> | ||
| 30 | + </libraryPathEntry> | ||
| 31 | + <libraryPathEntry kind="3" linkType="1" path="FlashCS5UI.swc" useDefaultLinkType="false"/> | ||
| 32 | + </libraryPath> | ||
| 33 | + <sourceAttachmentPath/> | ||
| 34 | + </compiler> | ||
| 35 | + <applications> | ||
| 36 | + <application path="srs_reuse_conn.as"/> | ||
| 37 | + </applications> | ||
| 38 | + <modules/> | ||
| 39 | + <buildCSSFiles/> | ||
| 40 | + <flashCatalyst validateFlashCatalystCompatibility="false"/> | ||
| 41 | +</actionScriptProperties> |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<projectDescription> | ||
| 3 | + <name>srs_reuse_conn</name> | ||
| 4 | + <comment></comment> | ||
| 5 | + <projects> | ||
| 6 | + </projects> | ||
| 7 | + <buildSpec> | ||
| 8 | + <buildCommand> | ||
| 9 | + <name>com.adobe.flexbuilder.project.flexbuilder</name> | ||
| 10 | + <arguments> | ||
| 11 | + </arguments> | ||
| 12 | + </buildCommand> | ||
| 13 | + </buildSpec> | ||
| 14 | + <natures> | ||
| 15 | + <nature>com.adobe.flexbuilder.project.actionscriptnature</nature> | ||
| 16 | + </natures> | ||
| 17 | +</projectDescription> |
不能预览此文件类型
不能预览此文件类型
| 1 | +package | ||
| 2 | +{ | ||
| 3 | + import fl.controls.Button; | ||
| 4 | + import fl.controls.TextInput; | ||
| 5 | + | ||
| 6 | + import flash.display.Sprite; | ||
| 7 | + import flash.display.StageAlign; | ||
| 8 | + import flash.display.StageScaleMode; | ||
| 9 | + import flash.events.Event; | ||
| 10 | + import flash.events.MouseEvent; | ||
| 11 | + import flash.events.NetStatusEvent; | ||
| 12 | + import flash.media.Video; | ||
| 13 | + import flash.net.NetConnection; | ||
| 14 | + import flash.net.NetStream; | ||
| 15 | + | ||
| 16 | + [SWF(backgroundColor="0xEEEEEE",frameRate="30",width="1024",height="576")] | ||
| 17 | + public class srs_reuse_conn extends Sprite | ||
| 18 | + { | ||
| 19 | + public function srs_reuse_conn() | ||
| 20 | + { | ||
| 21 | + if (stage) { | ||
| 22 | + onAddedToStage(null); | ||
| 23 | + } else { | ||
| 24 | + addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + private function onAddedToStage(evt:Event):void | ||
| 29 | + { | ||
| 30 | + stage.align = StageAlign.TOP_LEFT; | ||
| 31 | + stage.scaleMode = StageScaleMode.NO_SCALE; | ||
| 32 | + | ||
| 33 | + var txtUrl:TextInput = new TextInput(); | ||
| 34 | + var btnConn:Button = new Button(); | ||
| 35 | + var btnPlay:Button = new Button(); | ||
| 36 | + | ||
| 37 | + txtUrl.x = 10; | ||
| 38 | + txtUrl.y = 10; | ||
| 39 | + txtUrl.width = 400; | ||
| 40 | + txtUrl.text = "rtmp://dev/live/livestream"; | ||
| 41 | + addChild(txtUrl); | ||
| 42 | + | ||
| 43 | + btnConn.label = "Connect"; | ||
| 44 | + btnConn.x = txtUrl.x + txtUrl.width + 10; | ||
| 45 | + btnConn.y = txtUrl.y; | ||
| 46 | + btnConn.width = 100; | ||
| 47 | + addChild(btnConn); | ||
| 48 | + | ||
| 49 | + btnPlay.label = "Play"; | ||
| 50 | + btnPlay.x = btnConn.x + btnConn.width + 10; | ||
| 51 | + btnPlay.y = btnConn.y; | ||
| 52 | + btnPlay.width = 100; | ||
| 53 | + addChild(btnPlay); | ||
| 54 | + | ||
| 55 | + var video:Video = new Video(); | ||
| 56 | + video.x = txtUrl.x; | ||
| 57 | + video.y = txtUrl.y + txtUrl.height + 10; | ||
| 58 | + addChild(video); | ||
| 59 | + | ||
| 60 | + var conn:NetConnection = null; | ||
| 61 | + var stream:NetStream = null; | ||
| 62 | + | ||
| 63 | + var tcUrl:Function = function():String { | ||
| 64 | + var url:String = txtUrl.text; | ||
| 65 | + return url.substr(0, url.lastIndexOf("/")); | ||
| 66 | + } | ||
| 67 | + var streamName:Function = function():String { | ||
| 68 | + var url:String = txtUrl.text; | ||
| 69 | + return url.substr(tcUrl().length + 1); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + var closeConnection:Function = function():void { | ||
| 73 | + if (stream) { | ||
| 74 | + stream.close(); | ||
| 75 | + stream = null; | ||
| 76 | + } | ||
| 77 | + if (conn) { | ||
| 78 | + conn.close(); | ||
| 79 | + conn = null; | ||
| 80 | + } | ||
| 81 | + btnConn.label = "Connect"; | ||
| 82 | + btnPlay.visible = false; | ||
| 83 | + }; | ||
| 84 | + | ||
| 85 | + btnPlay.visible = false; | ||
| 86 | + btnConn.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void { | ||
| 87 | + if (btnConn.label == "Connect") { | ||
| 88 | + conn = new NetConnection(); | ||
| 89 | + conn.client = { | ||
| 90 | + onBWDone: function():void{} | ||
| 91 | + }; | ||
| 92 | + conn.addEventListener(NetStatusEvent.NET_STATUS, function(ne:NetStatusEvent):void { | ||
| 93 | + if (ne.info.code == "NetConnection.Connect.Success") { | ||
| 94 | + btnPlay.visible = true; | ||
| 95 | + } else if (ne.info.code == "NetConnection.Connect.Closed") { | ||
| 96 | + closeConnection(); | ||
| 97 | + } | ||
| 98 | + trace(ne.info.code); | ||
| 99 | + }); | ||
| 100 | + conn.connect(tcUrl()); | ||
| 101 | + btnConn.label = "Close"; | ||
| 102 | + } else { | ||
| 103 | + closeConnection(); | ||
| 104 | + } | ||
| 105 | + }); | ||
| 106 | + btnPlay.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void { | ||
| 107 | + if (stream) { | ||
| 108 | + stream.close(); | ||
| 109 | + stream = null; | ||
| 110 | + } | ||
| 111 | + stream = new NetStream(conn); | ||
| 112 | + stream.client = { | ||
| 113 | + onMetaData: function(metadata:Object):void { | ||
| 114 | + video.width = metadata.width; | ||
| 115 | + video.height = metadata.height; | ||
| 116 | + } | ||
| 117 | + }; | ||
| 118 | + video.attachNetStream(stream); | ||
| 119 | + stream.play(streamName()); | ||
| 120 | + }); | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | +} |
| @@ -54,6 +54,11 @@ bool SrsRecvThread::empty() | @@ -54,6 +54,11 @@ bool SrsRecvThread::empty() | ||
| 54 | return queue.empty(); | 54 | return queue.empty(); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | +int SrsRecvThread::size() | ||
| 58 | +{ | ||
| 59 | + return (int)queue.size(); | ||
| 60 | +} | ||
| 61 | + | ||
| 57 | SrsMessage* SrsRecvThread::pump() | 62 | SrsMessage* SrsRecvThread::pump() |
| 58 | { | 63 | { |
| 59 | srs_assert(!queue.empty()); | 64 | srs_assert(!queue.empty()); |
| @@ -79,6 +84,15 @@ int SrsRecvThread::cycle() | @@ -79,6 +84,15 @@ int SrsRecvThread::cycle() | ||
| 79 | { | 84 | { |
| 80 | int ret = ERROR_SUCCESS; | 85 | int ret = ERROR_SUCCESS; |
| 81 | 86 | ||
| 87 | + // we only recv one message and then process it, | ||
| 88 | + // for the message may cause the thread to stop, | ||
| 89 | + // when stop, the thread is freed, so the messages | ||
| 90 | + // are dropped. | ||
| 91 | + if (!queue.empty()) { | ||
| 92 | + st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); | ||
| 93 | + return ret; | ||
| 94 | + } | ||
| 95 | + | ||
| 82 | SrsMessage* msg = NULL; | 96 | SrsMessage* msg = NULL; |
| 83 | 97 | ||
| 84 | if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) { | 98 | if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) { |
| @@ -93,6 +107,10 @@ int SrsRecvThread::cycle() | @@ -93,6 +107,10 @@ int SrsRecvThread::cycle() | ||
| 93 | } | 107 | } |
| 94 | srs_verbose("play loop recv message. ret=%d", ret); | 108 | srs_verbose("play loop recv message. ret=%d", ret); |
| 95 | 109 | ||
| 110 | + // put into queue, the send thread will get and process it, | ||
| 111 | + // @see SrsRtmpConn::process_play_control_msg | ||
| 112 | + queue.push_back(msg); | ||
| 113 | + | ||
| 96 | return ret; | 114 | return ret; |
| 97 | } | 115 | } |
| 98 | 116 |
| @@ -54,6 +54,7 @@ public: | @@ -54,6 +54,7 @@ public: | ||
| 54 | virtual ~SrsRecvThread(); | 54 | virtual ~SrsRecvThread(); |
| 55 | public: | 55 | public: |
| 56 | virtual bool empty(); | 56 | virtual bool empty(); |
| 57 | + virtual int size(); | ||
| 57 | virtual SrsMessage* pump(); | 58 | virtual SrsMessage* pump(); |
| 58 | public: | 59 | public: |
| 59 | virtual int start(); | 60 | virtual int start(); |
| @@ -514,6 +514,11 @@ int SrsRtmpConn::playing(SrsSource* source) | @@ -514,6 +514,11 @@ int SrsRtmpConn::playing(SrsSource* source) | ||
| 514 | // stop isolate recv thread | 514 | // stop isolate recv thread |
| 515 | trd.stop(); | 515 | trd.stop(); |
| 516 | 516 | ||
| 517 | + // warn for the message is dropped. | ||
| 518 | + if (!trd.empty()) { | ||
| 519 | + srs_warn("drop the received %d messages", trd.size()); | ||
| 520 | + } | ||
| 521 | + | ||
| 517 | return ret; | 522 | return ret; |
| 518 | } | 523 | } |
| 519 | 524 | ||
| @@ -549,7 +554,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsRecvThread* trd) | @@ -549,7 +554,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsRecvThread* trd) | ||
| 549 | // @see: https://github.com/winlinvip/simple-rtmp-server/issues/217 | 554 | // @see: https://github.com/winlinvip/simple-rtmp-server/issues/217 |
| 550 | while (!trd->empty()) { | 555 | while (!trd->empty()) { |
| 551 | SrsMessage* msg = trd->pump(); | 556 | SrsMessage* msg = trd->pump(); |
| 552 | - srs_warn("pump client message to process."); | 557 | + srs_verbose("pump client message to process."); |
| 553 | 558 | ||
| 554 | if ((ret = process_play_control_msg(consumer, msg)) != ERROR_SUCCESS) { | 559 | if ((ret = process_play_control_msg(consumer, msg)) != ERROR_SUCCESS) { |
| 555 | if (!srs_is_system_control_error(ret)) { | 560 | if (!srs_is_system_control_error(ret)) { |
-
请 注册 或 登录 后发表评论