Menu

[r331]: / trunk / framework / OSMF / org / osmf / net / MulticastNetLoader.as  Maximize  Restore  History

Download this file

181 lines (163 with data), 5.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*****************************************************
*
* Copyright 2009 Adobe Systems Incorporated. All Rights Reserved.
*
*****************************************************
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
*
* The Initial Developer of the Original Code is Adobe Systems Incorporated.
* Portions created by Adobe Systems Incorporated are Copyright (C) 2009 Adobe Systems
* Incorporated. All Rights Reserved.
*
*****************************************************/
package org.osmf.net
{
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import org.osmf.media.MediaResourceBase;
import org.osmf.media.URLResource;
import org.osmf.traits.LoadState;
import org.osmf.traits.LoadTrait;
CONFIG::FLASH_10_1
{
import flash.net.NetGroup;
}
CONFIG::LOGGING
{
import org.osmf.logging.Logger;
import org.osmf.logging.Log;
}
/**
* Extends NetLoader to provide
* loading support for multicast video playback using RTMFP protocol.
*
* <p> MulticastNetLoader expects the media resource to be a StreamingURLResource,
* in which groupspec and streamName are specified.</p>
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion OSMF 1.5
*/
public class MulticastNetLoader extends NetLoader
{
/**
* @private
* @inheritDoc
**/
public function MulticastNetLoader(factory:NetConnectionFactoryBase=null)
{
var newFactory:NetConnectionFactory;
if (factory == null)
{
newFactory = new NetConnectionFactory();
newFactory.timeout = 60000;
}
super((factory != null)? factory: newFactory);
}
/**
* @private
*
* MulticastNetLoader returns true if the resource is an instance of StreamingURLResource with
* both groupspec and streamName set.
*
* @param resource The URL of the source media.
* @return Returns <code>true</code> for resouces of type StreamingURLResource.
* @inheritDoc
**/
override public function canHandleResource(resource:MediaResourceBase):Boolean
{
var rs:MulticastResource = resource as MulticastResource;
return rs != null &&
rs.groupspec != null &&
rs.groupspec.length > 0 &&
rs.streamName != null &&
rs.streamName.length > 0;
}
/**
* @private
* @inheritDoc
**/
override protected function createNetStream(connection:NetConnection, resource:URLResource):NetStream
{
var rs:MulticastResource = resource as MulticastResource;
CONFIG::LOGGING
{
logger.info("Creating multicast NetStream with groupspec " + rs.groupspec);
}
var ns:NetStream = new NetStream(connection, rs.groupspec);
CONFIG::LOGGING
{
if (ns != null)
{
logger.info("Multicast NetStream created.");
}
}
return ns;
}
/**
* Things become a little complex here. For multicast, the first time user will encounter a
* pop up dialog box for Peer Assited Network setting. The user may choose either to allow and deny.
* Also, the user may choose to remember the decision. If the user chooses to "allow", the client
* can proceed to receive multicast contents. Otherwise, the client cannot proceed.
*
* In terms of OSMF and Flex classes, OSMF should not proceed until it receives either
* "NetGroup.Connect.Success" or "NetStream.Connect.Success". Otherwise, multicast will not work and
* any attempt to access net stream or net group will incur exception (RTE).
*
* Therefore, the code here takes this scenario into consideration and wait for the "NetGroup.Connect.Success"
* before it proceeds.
*
* @private
**/
CONFIG::FLASH_10_1
{
override protected function processCreationComplete(connection:NetConnection, loadTrait:LoadTrait, factory:NetConnectionFactoryBase = null):void
{
var netLoadTrait:NetStreamLoadTrait = loadTrait as NetStreamLoadTrait;
var multicastResource:MulticastResource = netLoadTrait.resource as MulticastResource;
connection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
var netGroup:NetGroup = new NetGroup(connection, multicastResource.groupspec);
function onNetStatus(event:NetStatusEvent):void
{
switch(event.info.code)
{
case "NetGroup.Connect.Success":
connection.removeEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
netLoadTrait.netGroup = netGroup;
doProcessCreationComplete(connection, loadTrait, factory);
break;
case "NetGroup.Connect.Failed":
case "NetGroup.Connect.Rejected":
connection.removeEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
updateLoadTrait(loadTrait, LoadState.LOAD_ERROR);
break;
}
}
}
}
/**
* Help the enclosed onNetStatus function to call super.processCreationComplete.
*
* @private
*/
private function doProcessCreationComplete(connection:NetConnection, loadTrait:LoadTrait, factory:NetConnectionFactoryBase = null):void
{
super.processCreationComplete(connection, loadTrait, factory);
}
CONFIG::LOGGING
{
private static var logger:Logger = org.osmf.logging.Log.getLogger("org.osmf.net.multicast.MulticastNetLoader");
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.