1 # imgr-service.tcl --
2 #
3 # Objects responsible for launching various services in Indiva.
4 #
5 # Copyright (c) 1996-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/indiva/imgr/imgr-action.tcl,v 1.3 2003/06/10 19:44:15 harlanyu Exp $
32
33 import IMgrASCP
34 import IMgrASCP/RunAlways
35 import IMgrASCP/RunOnce
36
37 Class IMgrAction
38
39 Class IMgrAction/Encode -superclass IMgrAction
40
41 IMgrAction/Encode proc get_offer { mgr graph flow froms to {arguments ""} } {
42 MashLog info "Encode::get_offer"
43
44 set hostlist ""
45 foreach from $froms {
46 set node [$graph get_node $from]
47 if {$node != ""} {
48 set host [$node hostname]
49 if {[lsearch $hostlist $host] == -1} {
50 lappend hostlist $host
51 }
52 set id [$node get_attribute id]
53 } else {
54 MashLog warn "WARNING: $from has an empty node"
55 }
56 }
57
58 set fmt ""
59 set args [split [string trimright [string trimleft $arguments "{"] "}"] " "]
60 foreach {key value} $args {
61 switch -exact -- $key {
62 -fmt { set fmt $value }
63 }
64 }
65
66 set precond "hostname:$hostlist"
67 switch [$node get_attribute type] {
68 audio {
69 if {$id == "LML33" && $fmt == "L16"} {
70 set location "urn:irtp"
71 }
72 else {
73 set location "urn:iae"
74 }
75 }
76 default {
77 if {$id == "LML33" && $fmt == "mjpeg"} {
78 set location "urn:irtp"
79 }
80 else {
81 set location "urn:ive"
82 }
83 }
84 }
85
86 set ascp [new IMgrASCP $flow "dontcare" $to $location $precond ""]
87 $ascp on_timeout append "
88 $flow abort TIMEOUT
89 MashLog info timeout
90 delete $ascp
91 #return -code error -errorcode TIMEOUT
92 "
93 set agent_id [$ascp request start -block]
94 delete $ascp
95
96 set sender [lindex [split $agent_id "@:"] 1]
97
98 # Find a path that passes through the sender, with highest priority.
99 set moblist ""
100 foreach name $froms {
101 set mob [$graph get_node $name]
102 if {[$mob hostname] == $sender} {
103 lappend moblist "$mob [$mob priority]"
104 }
105 }
106 set moblist [lsort -index 1 -increasing -real $moblist]
107 set mob [lindex [lindex $moblist 0] 0]
108
109 return [$mob name]
110 }
111
112 IMgrAction/Encode proc start_service { mgr graph ctrl flow from to {arguments ""}} {
113
114 set to_node [$graph get_node $to]
115 set fmt [$to_node get_attribute fmt]
116 set fps [$to_node get_attribute fps]
117 set bps [$to_node get_attribute bps]
118 set quality [$to_node get_attribute q]
119
120 set from_node [$graph get_node $from]
121 set norm [$from_node get_attribute norm]
122 set type [$from_node get_attribute type]
123 set id [$from_node get_attribute id]
124 set name ""
125
126 set parent_id [[$from_node get_parent] get_attribute id]
127
128 # arguments may overwrite default from session.
129 foreach {key value} $arguments {
130 switch -exact -- $key {
131 -fmt { set fmt $value }
132 -size { set size $value }
133 -fps { set fps $value }
134 -bps { set bps $value }
135 -name { set name $value }
136 default { error "unknown encode option :$arguments" }
137 }
138 }
139
140 MashLog info "Encode::start_service: fmt = $fmt, id = $id, parentid = [[$from_node get_parent] get_attribute id]"
141
142 MashLog info "Encode::start_service: host = [$from_node get_attribute hostname], addr = [$to_node get_attribute addr], port = [$to_node get_attribute port]"
143
144 if {$type == "audio"} {
145 if {$fmt == "L16" && ($id == "LML33" || $parent_id == "LML33")} {
146 set stream_info [$ctrl start [$from_node get_attribute hostname] audio server 0 [$to_node get_attribute addr] [$to_node get_attribute port]]
147 } else {
148 set stream_info [$ctrl start [$to_node spec] $id]
149 }
150 } else {
151 if {$fmt == "mjpeg" && ($id == "LML33" || $parent_id == "LML33")} {
152 set stream_info [$ctrl start [$from_node get_attribute hostname] video server 0 [$to_node get_attribute addr] [$to_node get_attribute port]]
153 } else {
154 set stream_info [$ctrl start [$to_node spec] $fmt $norm $quality $fps $bps]
155 }
156 # Reset type so that mkrtp creates stream with type "video"
157 # instead of "composite" etc.
158 set type video
159 }
160 # A stream is created by $ctrl. Create at stream object in INDIVA namespace.
161 set cname [lindex $stream_info 0]
162 set ssrc [lindex $stream_info 1]
163 if {$name == ""} {
164 # if user passed in a name, we should use it instead of cname.
165 # Otherwise, we use cname.
166 set name $cname
167 }
168 set dest [$mgr mkrtp $to/$name -type $type -cname $cname -ssrc $ssrc]
169 if {$dest == ""} {
170 # a stream with the same name already exists.
171 if [string match $name "*.rtp"] {
172 return $name
173 } else {
174 return $name.rtp
175 }
176 }
177
178 # Update graph with necessary information for resource management.
179 set mob [$graph get_node $dest]
180 if {$mob == ""} {
181 error "destination $dest is invalid."
182 }
183 $mob on_destroy append "$mgr delete_flow $flow"
184
185 # What to do when the service timeout?
186 # - rm the target mob, which causes the resources to be freed
187 # (because of the on_destroy callback.)
188 # - reroute the service.
189 # - we make sure that the new destination has the same name
190 # as the old one, by passing in cname.
191 if {[lsearch $arguments -name] == -1} {
192 lappend arguments "-name $name"
193 }
194
195 set ascp [$mgr get_ascp $from $to]
196 $ascp on_service_expire remove "$mgr rm *"
197 $ascp on_service_expire remove "$mgr create_flow *"
198 $ascp on_service_expire append "$mgr rm $dest"
199 $ascp on_service_expire append "$mgr create_flow [$flow client] [$flow src] [$flow dest] $arguments"
200
201 $ascp on_timeout append "
202 if !\[catch {eof [$flow client]}\] {
203 dp_RPC [$flow client] error timeout
204 }
205 delete $ascp
206 "
207
208 return $dest
209 }
210
211 IMgrAction/Encode proc create_servent { mgr graph port_name target {args ""}} {
212 set fmt ""
213 set args [split [string trimright [string trimleft $args "{"] "}"] " "]
214 foreach {key value} $args {
215 switch -exact -- $key {
216 -fmt { set fmt $value }
217 }
218 }
219
220 set target_node [$graph get_node $target]
221 set target_ip [$target_node get_attribute addr]
222 set target_port [$target_node get_attribute port]
223
224 set port_node [$graph get_node $port_name]
225 set dev_node [$port_node device]
226 set dev_name [$dev_node name]
227 set precond "hostname:[$dev_node get_attribute hostname]"
228
229 MashLog info "Encode::create_servent: fmt = $fmt, id = [$dev_node get_attribute id], type = [$port_node get_attribute type]"
230
231 if {[$port_node get_attribute type] == "audio"} {
232 if {[$dev_node get_attribute id] == "LML33" && $fmt == "L16"} {
233 set arguments "-hostaddress [$dev_node get_attribute hostname]\n"
234 append arguments "-mediatype audio\n"
235 append arguments "-servicemode server\n"
236 append arguments "-multicastaddr $target_ip\n"
237 append arguments "-multicastport $target_port\n"
238 set location "urn:irtp"
239 } else {
240 set arguments "-dev \"[$port_node get_attribute id]\"\n"
241 set location "urn:iae"
242 }
243 } else { #video
244 if {[$dev_node get_attribute id] == "LML33" && $fmt == "mjpeg"} {
245 set arguments "-hostaddress [$dev_node get_attribute hostname]\n"
246 append arguments "-mediatype video\n"
247 append arguments "-servicemode server\n"
248 append arguments "-multicastaddr $target_ip\n"
249 append arguments "-multicastport $target_port\n"
250 set location "urn:irtp"
251 } else {
252 set arguments "-port \"[$port_node get_attribute id]\"\n"
253 append arguments "-dev \"[$dev_node get_attribute path]\"\n"
254 set location "urn:ive"
255 }
256 }
257 append arguments "-imgr [info hostname]:[$mgr port]\n"
258 set ascp [new IMgrASCP "" "" "" $location $precond $arguments]
259 $ascp launch_now start -block
260 $ascp on_timeout append "
261 MashLog info timeout
262 delete $ascp
263 #return -code error -errorcode TIMEOUT
264 "
265 return $ascp
266 }
267
268 IMgrAction/Encode proc redir_service { mgr graph ctrl flow from to {arguments ""}} {
269 MashLog info "Encode::redir_service"
270
271 return [$self start_service $mgr $graph $ctrl $flow $from $to $arguments]
272 }
273
274 IMgrAction/Encode proc split_service { mgr graph ctrl oldflow newflow from to {arguments ""} } {
275 MashLog info "Encode::split_service"
276
277 set node [$graph get_node $to]
278 set type [$node get_attribute type]
279 set stream_info [$ctrl split [$node spec]]
280
281 # A stream is created by $ctrl. Create a stream object in INDIVA namespace.
282 set cname [lindex $stream_info 0]
283 set ssrc [lindex $stream_info 1]
284 set dest [$mgr mkrtp $to/$cname -type $type -cname $cname -ssrc $ssrc]
285
286 # Update graph with necessary information for resource management.
287 set mob [$graph get_node $dest]
288 if {$mob == ""} {
289 error "destination $dest is invalid."
290 }
291 $mob on_destroy append "$mgr delete_flow $newflow"
292
293 return $dest
294 }
295
296
297 Class IMgrAction/None -superclass IMgrAction
298
299 IMgrAction/None proc get_offer { mgr graph flow froms to {arguments ""}} {
300 return [lindex $froms 0]
301 }
302
303 IMgrAction/None proc start_service { mgr graph ctrl flow froms to {arguments ""}} {
304 return
305 }
306
307 IMgrAction/None proc create_servent { mgr graph device_name port_name {args ""}} {
308 return
309 }
310
311 IMgrAction/None proc redir_service { mgr graph ctrl flow from to {arguments ""} } {
312 return
313 }
314
315 IMgrAction/None proc split_service { mgr graph ctrl oldflow newflow from to {arguments ""} } {
316 return
317 }
318
319
320 Class IMgrAction/Switch -superclass IMgrAction
321 IMgrAction/Switch proc start_service { mgr graph ctrl flow from to {arguments ""}} {
322 set type [$mgr info $to -type]
323 set in [$mgr info $from -portid]
324 set out [$mgr info $to -portid]
325 MashLog info "rpc: switch $type $in $out"
326 $ctrl start $type $in $out
327 MashLog info "rpc: done."
328
329 return $to
330 }
331
332 IMgrAction/Switch proc create_servent {mgr graph device_name port_name {args ""}} {
333 set hostname [$mgr info $device_name -hostname]
334 set arguments "-id [$mgr info $device_name -id]\n"
335 append arguments "-dev [$mgr info $device_name -path]\n"
336
337 return [$mgr rexec irs -args $arguments -host $hostname]
338 }
339
340 IMgrAction/Switch proc redir_service { mgr graph ctrl flow from to {arguments ""}} {
341 set type [$mgr info $to -type]
342 set in [$mgr info $from -portid]
343 set out [$mgr info $to -portid]
344 MashLog info "rpc: switch $type $in $out"
345 $ctrl start $type $in $out
346 MashLog info "rpc: done."
347 }
348
349 IMgrAction/Switch proc split_service { mgr graph ctrl oldflow newflow from to {arguments ""} } {
350 eval $self redir_service $mgr $graph $ctrl $oldflow $from $to $arguments
351 }
352
353
354 Class IMgrAction/Capture -superclass IMgrAction
355 IMgrAction/Capture proc get_offer { mgr graph flow froms to {arguments ""} } {
356 return [lindex $froms 0]
357 }
358
359 IMgrAction/Capture proc start_service { mgr graph ctrl flow froms to {arguments ""} } {
360 return
361 }
362
363 IMgrAction/Capture proc create_servent { mgr graph device_name port_name {args ""} } {
364 return
365 }
366
367 IMgrAction/Capture proc redir_service { mgr graph ctrl flow from to {arguments ""} } {
368 return
369 }
370
371 IMgrAction/Capture proc split_service { mgr graph ctrl oldflow newflow from to {arguments ""} } {
372 return
373 }
374
375
376 Class IMgrAction/Kaleido -superclass IMgrAction
377 IMgrAction/Kaleido proc get_offer { mgr graph flow froms to {arguments ""} } {
378 return [lindex $froms 0]
379 }
380
381 IMgrAction/Kaleido proc start_service { mgr graph ctrl flow from to {arguments ""}} {
382 return
383 }
384
385 IMgrAction/Kaleido proc create_servent { mgr graph device_name port_name {args ""} } {
386 set hostname [$mgr info $device_name -hostname]
387 set arguments "-dev [$mgr info $device_name -path]"
388 return [$mgr rexec "ikld" -host $hostname -args $arguments]
389 }
390
391 IMgrAction/Kaleido proc redir_service { mgr graph ctrl flow from to {arguments ""} } {
392 return
393 }
394
395 IMgrAction/Kaleido proc split_service { mgr graph ctrl oldflow newflow from to {arguments ""} } {
396 return
397 }
398
399
400 Class IMgrAction/Forward -superclass IMgrAction
401 IMgrAction/Forward proc get_offer { mgr graph flow froms to {arguments ""} } {
402 return [lindex $froms 0]
403 }
404
405 IMgrAction/Forward proc start_service { mgr graph ctrl flow from to {arguments ""}} {
406 set src_node [$graph get_node $from]
407 set src_sess [$src_node get_parent]
408 set src_ssrc [$src_node get_attribute ssrc]
409 set type [$src_sess get_attribute type]
410 set src_spec [$src_sess spec]
411
412 set dest_node [$graph get_node $to]
413 set dest_spec [$dest_node spec]
414
415 set rtpinfo [$ctrl start $src_spec $dest_spec $src_ssrc]
416 set cname [lindex $rtpinfo 0]
417 set ssrc [lindex $rtpinfo 1]
418 set dest [$mgr mkrtp $to/$cname -type $type -cname $cname -ssrc $ssrc]
419 set mob [$graph get_node $dest]
420 $mob on_destroy append "$mgr delete_flow $flow"
421 return $dest
422 }
423
424 IMgrAction/Forward proc create_servent { mgr graph src dest {args ""} } {
425 return [$mgr rexec ifwd -restart 1]
426 }
427
428 IMgrAction/Forward proc redir_service { mgr graph ctrl flow from to {arguments ""} } {
429 return
430 }
431
432 IMgrAction/Forward proc split_service { mgr graph ctrl oldflow newflow from to {arguments ""} } {
433 return
434 }
435
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.