1 # al-megaclient.tcl --
2 #
3 # FIXME: This file needs a description here.
4 #
5 # Copyright (c) 1998-2002 The Regents of the University of California.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # A. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # B. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # C. Neither the names of the copyright holders nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #
31 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/mega/al-megaclient.tcl,v 1.12 2002/02/03 04:27:39 lim Exp $
32
33 import AnnounceListenManager/AS/Client RTP/Audio RTP/Video MeGa
34
35 # FIXME this needs more work
36
37 Class AnnounceListenManager/AS/Client/MeGa \
38 -superclass { AnnounceListenManager/AS/Client MeGa }
39
40 Class AnnounceListenManager/AS/Client/MeGa/Audio \
41 -superclass { AnnounceListenManager/AS/Client/MeGa RTP/Audio }
42 Class AnnounceListenManager/AS/Client/MeGa/Video \
43 -superclass { AnnounceListenManager/AS/Client/MeGa RTP/Video }
44
45 AnnounceListenManager/AS/Client/MeGa instproc init { agent spec bw toolname media sname sspec rportspec ofmt srv_loc } {
46 set spec [MeGa ctrlchan $media $spec]
47 $self next $spec $bw $srv_loc
48
49 $self instvar agent_ toolname_ sname_ sspec_ media_ rportspec_ ofmt_
50 set toolname_ $toolname
51 set media_ $media
52 set sname_ $sname
53 set sspec_ $sspec
54 set rportspec_ $rportspec
55 set ofmt_ $ofmt
56 set agent_ $agent
57
58 $self instvar srv_inst_
59 [$self get_timer] threshold 15000
60 set srv_inst_ [$self service_instance]
61 }
62
63 # Annoyingly, when we change the data address we want mega to listen to,
64 # it doesn't notice the change. As a temporary solution, we change the
65 # service instance so that a new gateway gets created.
66 AnnounceListenManager/AS/Client/MeGa instproc reset_spec {sspec} {
67 $self instvar sspec_ srv_inst_ index_
68
69 set sspec_ $sspec
70 set rand [random]
71 # index_ is used by agent_instance and service_instance
72 set index_ $rand
73 set srv_inst_ [$self service_instance]
74
75 }
76
77 AnnounceListenManager/AS/Client/MeGa instproc recv_msg { atype aspec addr srv_name srv_loc srv_inst ssg_port msg } {
78 if { $atype != "srv" } {
79 return
80 }
81 $self instvar agent_ srv_inst_
82
83 # Is this our instance?
84 if { $srv_inst_ != $srv_inst } {
85 return
86 }
87
88 # FIXME This can be structured differently
89 $self instvar sdp_
90 set msg [$sdp_ parse $msg]
91 if { $msg == "" } {
92 return
93 }
94 if [$agent_ have_network] {
95 set addr [$agent_ session-addr]
96 set sport [$agent_ session-sport]
97 set rport [$agent_ session-rport]
98 set ttl [$agent_ session-ttl]
99 set curspec $addr/$sport:$rport/$ttl
100 } else {
101 set curspec ""
102 set ttl -1
103 }
104 # set noshare [$msg have_attr noshare]
105 # Media record per output session in a gateway announcement
106 set media [$msg set allmedia_]
107 $self instvar media_ rportspec_
108 foreach mrec [$msg set allmedia_] {
109 # ignore the global record
110 if [$mrec have_attr global] {
111 continue
112 }
113 set tmp [split [$mrec set caddr_] /]
114 set laddr [lindex $tmp 0]
115 set lttl [lindex $tmp 1]
116 set pspec [split [$mrec set port_] :]
117 set sport [lindex $pspec 0]
118 set rport [lindex $pspec 1]
119 set myrport [lindex [split $rportspec_ :] 0]
120
121 # If it's a multicast session and we want multicast
122 # or a unicast session directed at us, join it if we
123 # are not already joined.
124 if { ([in_multicast $laddr] && $myrport == 0) || \
125 ($laddr == [localaddr] && $sport == $myrport) } {
126 if { ![in_multicast $laddr] } {
127 set laddr [$msg set createaddr_]
128 }
129 # swap rport and sport
130 set newspec $laddr/$rport:$sport/$lttl
131 if { $newspec != $curspec } {
132 set fmt [$mrec set fmt_]
133 set fmt [$self format_name $fmt]
134 if { $fmt == "" } {
135 set fmt null
136 }
137 $agent_ reset_spec \
138 $laddr/$rport:$sport/$fmt/$lttl
139
140 $self send_announcement
141 }
142 delete $msg
143 return
144 }
145 }
146 delete $msg
147 }
148
149 AnnounceListenManager/AS/Client/MeGa private format_name { fmt } {
150 return ""
151 }
152
153 AnnounceListenManager/AS/Client/MeGa/Audio private format_name { fmt } {
154 return [$self rtp_type $fmt]
155 }
156
157 AnnounceListenManager/AS/Client/MeGa/Video private format_name { fmt } {
158 return [$self rtp_type $fmt]
159 }
160
161 AnnounceListenManager/AS/Client/MeGa instproc register { atype aspec addr srv_name srv_inst msg } {
162 }
163
164 AnnounceListenManager/AS/Client/MeGa instproc unregister { atype aspec addr srv_name srv_inst msg } {
165 }
166
167
168 AnnounceListenManager/AS/Client/MeGa public agent_data {} {
169 $self instvar id1_ id2_ agent_ media_ agent_ sname_ sspec_ \
170 toolname_ rportspec_ ofmt_
171
172 set o "v=0"
173 set n "o=client [pid] 0 IN IP4 [localaddr]"
174 set o $o\n$n
175 set n "s=$sname_"
176 set o $o\n$n
177 set n "c=IN IP4 $sspec_"
178 set o $o\n$n
179
180 if { $media_ == "video" } {
181 # scuba controlled session
182 set n "b=AS:[$agent_ set sessionbw_]"
183 puts "!!SESSIONBW $n"
184 set o $o\n$n
185 set n "t=0 0"
186 set o $o\n$n
187 if { [$self get_option localScubaScope] != "" } {
188 set n "a=localscuba"
189 set o $o\n$n
190 }
191 } else {
192 set n "t=0 0"
193 set o $o\n$n
194 }
195
196 set n "a=tool:$toolname_"
197 set o $o\n$n
198 # for now all we do is no share
199 # set n "a=noshare"
200 # set o $o\n$n
201 set fmt [$self format_num $ofmt_]
202 set rportspec [split $rportspec_ :]
203 set rport [lindex $rportspec 0]
204 set n "m=$media_ $rport RTP/AVP $fmt"
205 set o $o\n$n
206
207 if [$agent_ have_network] {
208 set addr [$agent_ session-addr]
209 set sport [$agent_ session-sport]
210 set rport [$agent_ session-rport]
211 set ttl [$agent_ session-ttl]
212 set n "c=IN IP4 $addr/$sport:$rport/$ttl"
213 } else {
214 set n "c=IN IP4 none"
215 }
216 set o $o\n$n
217
218 return $o
219 }
220
221 AnnounceListenManager/AS/Client/MeGa private format_num { fmt } {
222 return -1
223 }
224
225 AnnounceListenManager/AS/Client/MeGa/Video private format_num { fmt } {
226 return [$self rtp_fmt_number $fmt]
227 }
228 AnnounceListenManager/AS/Client/MeGa/Audio private format_num { fmt } {
229 return [$self rtp_fmt_number $fmt]
230 }
231
232 AnnounceListenManager/AS/Client/MeGa instproc service_name {} {
233 return MeGa
234 }
235
236 # A unique id that identifies the instance completely. If it's multicast,
237 # it won't we unique. If it's unicast, it better be unique across all clients.
238 AnnounceListenManager/AS/Client/MeGa instproc service_instance {} {
239 $self instvar sname_ rportspec_ media_ index_
240
241 set o $sname_:$media_
242 set rportspec [split $rportspec_ :]
243 set rport [lindex $rportspec 0]
244 if { $rport != 0 } {
245 # unicast
246 set o $o:[localaddr]/$rport
247 if {[info exists index_]} {
248 set o $o:$index_
249 }
250 }
251 return $o
252 }
253
254 AnnounceListenManager/AS/Client/MeGa instproc agent_instance {} {
255 $self instvar index_
256 if {[info exists index_]} {
257 return "[pid]@[lookup_host_name [localaddr]]:$index_"
258 } else {
259
260 return "[pid]@[lookup_host_name [localaddr]]"
261 }
262
263 }
264
265 AnnounceListenManager/AS/Client/MeGa instproc ssg_port {} {
266 $self instvar rportspec_
267 set rportspec [split $rportspec_ :]
268 set rport [lindex $rportspec 0]
269 if { $rport != 0 } {
270 return [lindex $rportspec 1]
271 } else {
272 return "-"
273 }
274 }
275
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.