~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/dc/rvc/application-rvc.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # application-rvc.tcl --
  2 #
  3 #       This is basically a Vic with the GUI in an SDS service.  It provides
  4 #       the SDS GUI for the cameras, vcr, etc.
  5 #
  6 # Copyright (c) 2000-2002 The Regents of the University of California.
  7 # All rights reserved.
  8 #
  9 # Redistribution and use in source and binary forms, with or without
 10 # modification, are permitted provided that the following conditions are met:
 11 #
 12 # A. Redistributions of source code must retain the above copyright notice,
 13 #    this list of conditions and the following disclaimer.
 14 # B. Redistributions in binary form must reproduce the above copyright notice,
 15 #    this list of conditions and the following disclaimer in the documentation
 16 #    and/or other materials provided with the distribution.
 17 # C. Neither the names of the copyright holders nor the names of its
 18 #    contributors may be used to endorse or promote products derived from this
 19 #    software without specific prior written permission.
 20 #
 21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 24 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31 
 32 import RTPApplication
 33 import RvcAgent
 34 import RvcObserver
 35 import VideoPipeline
 36 import CSdsService
 37 import CServiceManager
 38 import CService
 39 
 40 import 405Client
 41 
 42 global g_app
 43 
 44 #
 45 # Code for RvcApplication
 46 #
 47 
 48 Class RvcApplication -superclass RTPApplication
 49 
 50 RvcApplication instproc InitArgs { options } {
 51     $options register_option -d defaultDevice
 52     $options register_option -t defaultTTL
 53     $options register_option -s serverPort
 54     $options register_option -f videoFormat
 55     $options register_option -b videoBandwidth
 56     $options register_option -q videoQuality
 57     $options register_option -p videoInputPort
 58     $options register_option -F frameRate
 59     $options register_option -n norm
 60     $options register_option -l loopback
 61 
 62     # for the service discovery service
 63     $options register_option -sa optServiceAddress
 64     $options register_option -sp optServicePort
 65     $options register_option -st optServiceTTL
 66 
 67     # for the service discovery service
 68     $options register_option -rp optComPort
 69 
 70     # for the service discovery service
 71     $options register_option -as autoStart
 72     $options register_option -amx useAmx
 73 
 74     # for amxd 
 75     $options register_option -ah amxHost
 76     $options register_option -ap amxPort
 77 
 78     # for the configuration file
 79     $options register_option -cf optConfigFile
 80 }
 81 
 82 RvcApplication instproc InitResources { options } {
 83     $options add_default defaultTTL 16
 84     $options add_default serverPort 8888
 85     $options add_default videoFormat jpeg
 86     $options add_default videoBandwidth 524288
 87     $options add_default videoQuality 85
 88     $options add_default videoInputPort "Composite1"
 89     $options add_default frameRate 15
 90     $options add_default norm ntsc
 91     $options add_default loopback 0
 92 
 93     # for the service discovery service
 94     $options add_default optServiceAddress "224.4.6.8"
 95     $options add_default optServicePort "12344"
 96     $options add_default optServiceTTL "16"
 97 
 98     $options add_default amxHost "htsr2.bmrc.berkeley.edu"
 99     $options add_default amxPort "6901"
100     $options add_default aCamHost "htsr2.bmrc.berkeley.edu"
101     $options add_default aCamPort "6906"
102     $options add_default sCamHost "htsr2.bmrc.berkeley.edu"
103     $options add_default sCamPort "6905"
104 
105     # for the service discovery service
106     $options add_default optComPort "11408"
107 
108     # for amx
109     $options add_default useAmx "yes"
110 
111     # file name for configuration file
112     $options add_default optConfigFile ".rvcconfig"
113 }
114 
115 RvcApplication private LoadConfigFile { } {
116     $self instvar m_lConfig
117 
118     set options [$self options]
119     set szConfigFileName [$options get_option optConfigFile]
120 
121     if {[catch {open $szConfigFileName "r"} fileConfig]} {
122         puts stderr "ERROR: rvc ([info hostname]): Unable to open config file $szConfigFileName"
123         exit
124     }
125     set fileConfig [open $szConfigFileName "r"]
126 
127     # get the host name to pick out which configuration to get
128     set hostname [info hostname]
129     set shorthostname [lindex [split $hostname .] 0]
130 
131     # need this indirection because [ and ] are special in both tcl and regex
132     set openBracket "\["
133     set closeBracket "\]"
134 
135     # set the two patterns up to be used later
136     set pattern "\\$openBracket"
137     append pattern $hostname
138     append pattern "\\$closeBracket"
139     set shortpattern "\\$openBracket"
140     append shortpattern $shorthostname
141     append shortpattern "\\$closeBracket"
142 
143     set pattern2 "\\$openBracket"
144     append pattern2 "*"
145     append pattern2 "\\$closeBracket"
146 
147     # go through each line of the config file
148     while { [gets $fileConfig szLine] >= 0 } {
149         set szLine [string trim $szLine]
150 
151         # get to the correct section
152         if { ![string match $pattern $szLine] && ![string match $shortpattern $szLine] } {
153             continue
154         }
155 
156         # now we're at the right section
157         while { [gets $fileConfig szSectionLine] >= 0 } {
158             set szSectionLine [string trim $szSectionLine]
159 
160             # check that it's not an empty line
161             if {$szSectionLine == ""} {
162                 continue
163             }
164 
165             # if we hit the next section then just return
166             if { [string match $pattern2 $szSectionLine] } {
167                 break
168             }
169 
170             # otherwise it's a section line
171             set lLine [split $szSectionLine =]
172             set index [string trim [lindex $lLine 0]]
173             set value [string trim [lindex $lLine 1]]
174             set aConfig($index) $value
175 
176             # Since some of the parameters from config file is
177             # the same as command line arguments (e.g. FORMAT 
178             # and -videoFormat), we override the default value
179             # of command line arguments with the values from 
180             # config file.  This is to maintain consistency 
181             # as some of the routines (such as the constructor
182             # for RvcAgent) reads value from command line arguments
183             # and not from config file.
184 
185             $self update_defaults $options $index $value
186         }
187 
188         break
189     }
190 
191     close $fileConfig
192 
193     set m_lConfig [array get aConfig]
194 
195 #    puts "config = $m_lConfig"
196 }
197 
198 
199 #-----------------------------------------------------------------------------
200 #
201 # RvcApplication instproc update_defaults { options key value }
202 #
203 # Input:
204 #   options - the Configuration object associated with this object
205 #             (obtained thru [$self options]
206 #   key, value - a key value pair from rvc's configuration file.
207 #
208 # Description:
209 #   This is used to override the default values passed in via
210 #   command line arguments, it is to maintain consistency because
211 #   some routines read values from command line arguments and not
212 #   from the configuration file.  It is called everytime a key-value
213 #   pair is read from the configuration file.
214 #
215 #-----------------------------------------------------------------------------
216 
217 RvcApplication instproc update_defaults { options key value } {
218     switch -exact $key {
219         DEVICE {
220             $options add_default defaultDevice $value   
221         } 
222         FORMAT {
223             $options add_default videoFormat $value     
224         } 
225         QUALITY {
226             $options add_default videoQuality $value    
227         }
228         PORT {
229             $options add_default videoInputPort $value  
230         }
231         FPS {
232             $options add_default frameRate $value       
233         }
234         BPS {
235             $options add_default videoBandwidth $value  
236         }
237         NORM {
238             $options add_default norm $value    
239         }
240         AMX_PORT {
241             $options add_default amxPort $value 
242         }
243         AMX_HOST {
244             $options add_default amxHost $value 
245         }
246         AUD_CAM_PORT {
247             $options add_default aCamPort $value        
248         }
249         AUD_CAM_HOST {
250             $options add_default aCamHost $value        
251         }
252         SPK_CAM_PORT {
253             $options add_default sCamPort $value        
254         }
255         SPK_CAM_HOST {
256             $options add_default sCamHost $value        
257         }
258     }
259 } 
260 
261 
262 #-----------------------------------------------------------------------------
263 #
264 # RvcApplication InitAMX
265 #
266 # Input:
267 #   amxdHost, amxdPort - the host and port of amxd.  (This could be "" if
268 #      they are not initialized by command line args or configuration file)
269 #
270 # Description:
271 #   Create a new Dp client to talk to amxd.  Then tell amxd to switch
272 #   input to value specified in the configuration file.
273 #
274 #-----------------------------------------------------------------------------
275 RvcApplication instproc InitAMX {} {
276     $self instvar m_405
277     $self instvar m_lConfig
278 
279     array set aConfig $m_lConfig
280 
281     set amxHost [$self get_option amxHost]
282     set amxPort [$self get_option amxPort]
283     set aCamHost [$self get_option aCamHost]
284     set aCamPort [$self get_option aCamPort]
285     set sCamHost [$self get_option sCamHost]
286     set sCamPort [$self get_option sCamPort]
287 
288     if {$amxHost == "" || $amxPort == ""} {
289         puts stderr "WARNING: rvc ([info hostname]): No AMX host/port specified."
290         return
291     }
292     set m_405 [new 405Client $amxHost $amxPort $aCamHost $aCamPort $sCamHost $sCamPort]
293     set callback "$self ProcessAmxMsg"
294 
295     # FIXME - this is an ugly hack that works (for now) to get htsr or htsr2
296     #   from the hostname, won't work if things ever change
297     set hostname [info hostname]
298     set parts [split $hostname "."]
299     set shortHostname [lindex $parts 0]
300     set filter [$self GetFilter $shortHostname]
301     $m_405 callback_register $callback $filter
302     $m_405 callback_enable $callback
303 
304     $self AMXSwitch $aConfig(AMX_SWITCH_STATE)
305 }
306 
307 RvcApplication instproc init { argv } {
308     $self next rvc
309 
310     # set some member variables
311     $self instvar m_agent
312     $self instvar m_observer
313     $self instvar m_lConfig
314     $self instvar m_switchReal
315     $self instvar m_cameraMoveButtonPressed
316 
317     set m_agent 0
318     set m_observer 0
319     set m_switchReal 0
320     set m_cameraMoveButtonPressed 0
321 
322     # Initiailization of variables and resources.
323     set options [$self options]
324     $self InitArgs $options
325     $self InitResources $options
326 
327     $options load_preferences "rtp rvc"
328     set argv [$options parse_args $argv]
329 
330     # load the configuration file
331     $self LoadConfigFile
332 
333     # create the sds session object
334     set inetServiceAddr [$options get_option optServiceAddress]
335     set iServicePort [$options get_option optServicePort]
336     set iServiceTTL [$options get_option optServiceTTL]
337 
338     $self instvar m_sdsService
339     set m_sdsService [new CSdsService $self $inetServiceAddr $iServicePort \
340             $iServicePort $iServiceTTL]
341 
342     # setup the service objects
343     $self instvar m_serviceManager
344     $self instvar m_service
345 
346     set iPort [$options get_option optComPort]
347     if {[catch {new CServiceManager "ServiceApp" "Video" $iPort} m_serviceManager]} {
348         puts stderr "ERROR: rvc ([info hostname]): Unable to create server socket on port $iPort"
349         exit
350     }
351     $m_serviceManager Attach $self
352 
353     # setup the amx stuff if we have to
354     array set aConfig $m_lConfig
355 
356     # Try to initialize AMX, if successful, m_405 will be set to a new
357     # 405Client.
358     set useAmx [$self get_option useAmx]
359     if {$useAmx == "1" || $useAmx == "yes"} {
360         $self InitAMX 
361     }
362 
363     puts "rvc ([info hostname]): Initialization done"
364 }
365 
366 ##############################################################################
367 #
368 # RvcApplication instproc NewConnection { service } {
369 #
370 # Input:
371 # service - the new service that got connected
372 #
373 # Output:
374 # 1 - if handling this service
375 # 0 - otherwise
376 #
377 # Description:
378 # A call back function for the service manager.  This function will be called
379 # when a new connection has just been noticed by the service manager
380 #
381 ##############################################################################
382 RvcApplication instproc NewConnection { service } {
383 
384     $service MapMessage "QUIT" $self "CloseService"
385     $service MapMessage "SYN_START" $self "SynStart"
386 
387     return 1
388 }
389 
390 ##############################################################################
391 #
392 # RvcApplication instproc SynStart { service arguments } {
393 #
394 # Input:
395 # service - the service object that called this function
396 # arguments - the arguments that are passed to this funct from remote caller
397 #
398 # Output:
399 # none
400 #
401 # Description:
402 #
403 ##############################################################################
404 RvcApplication instproc SynStart { service arguments } {
405     $self instvar m_agent
406     $self instvar m_observer
407     $self instvar m_serviceManager
408     $self instvar m_service
409     $self instvar m_lConfig
410     array set aConfig $m_lConfig
411 
412     set options [$self options]
413     # if these are valid then we're already being used
414     if { $m_agent != 0 || $m_observer != 0 } {
415         delete $service 
416         return
417     }
418 
419     set inetMStudioAddr [lindex $arguments 0]
420     set iMStudioPort [lindex $arguments 1]
421 
422     set m_observer [new RvcObserver $self]
423     set m_agent [new RvcAgent $self "$inetMStudioAddr/$iMStudioPort"]
424 
425     # set the parameters then start sending the multicast stream
426     $m_agent set_fmt [$options get_option videoFormat]
427     if [info exists aConfig(DEVICE)] {
428         set device [$m_agent get_device_by_name $aConfig(DEVICE)]
429         if {$device != "" && $device != [$m_agent current_device]} {
430             $m_agent set_device $device
431         }
432     }
433     $m_agent set_inport [$options get_option videoInputPort]
434     $m_agent set_norm [$options get_option norm]
435     $m_agent start
436     $m_agent set_fps [$options get_option frameRate]
437     $m_agent set_bps [$options get_option videoBandwidth]
438     $m_agent set_quality $aConfig(QUALITY)
439 
440 
441     # now connect to the client with the souce id
442     set inetAddr [lindex $arguments 2]
443     set iPort [lindex $arguments 3]
444     set iSourceId [$m_agent get_local_srcid]
445 
446     if {[catch {$m_serviceManager NewService $inetAddr $iPort "VideoService" $iSourceId} m_service]} {
447         puts "ERROR: rvc: Unable to create new service at $inetAddr $iPort. Bye."
448         puts "ERROR: rvc: This could happen if you run rvc on the same host as dc."
449         puts "ERROR: rvc: $m_service"
450         exit
451     }
452 
453     # set up the mapping for this service
454     $m_service MapMessage "CLOSE_LINK" $self "CloseService"
455     $m_service MapMessage "GET_UI_CONTROL" $self "GetUIControl"
456     $m_service MapMessage "DEVICE" $self "Device"
457     $m_service MapMessage "PORT" $self "Port"
458     $m_service MapMessage "FORMAT" $self "Format"
459     $m_service MapMessage "FPS" $self "FrameRate"
460     $m_service MapMessage "TOGGLE_RN" $self "ToggleRn"
461     $m_service MapMessage "GET_INFO" $self GetInfo
462 
463     # Full Intra-frame request
464     $m_service MapMessage "FIR" $self "FIR"
465 
466     set useAmx [$self get_option useAmx]
467     if {$useAmx == "1" || $useAmx == "yes"} {
468         $m_service MapMessage "AMX_SWITCH" $self "RemoteAMXSwitch"
469         $m_service MapMessage "AMX_CAMERA_CONTROL" $self "AMXCameraControl"
470         $m_service MapMessage "AMX_VCR_CONTROL" $self "AMXVCRControl"
471     }
472 }
473 
474 ##############################################################################
475 #
476 # RvcApplication instproc CloseService { service arguments }
477 #
478 # Input:
479 # service - the service object that called this function
480 # arguments - the arguments that are passed to this funct from remote caller
481 #
482 # Output:
483 # none
484 #
485 # Description:
486 # Need to close the service - ie. stop sending out the video and shutdown
487 # everything and wait until the next client comes
488 #
489 ##############################################################################
490 RvcApplication instproc CloseService { service arguments } {
491     $self instvar m_agent
492     $self instvar m_observer
493 
494     if {$m_agent != 0} {
495         $m_agent stop
496         $m_agent detach_observer $m_observer
497         delete $m_agent
498         delete $m_observer
499 
500         set m_agent 0
501         set m_observer 0
502     }
503 
504     puts stderr "rvc ([info hostname]): Exit."
505     exit
506 }
507 
508 
509 RvcApplication instproc GetUIControl { service arguments } {
510     $self instvar m_agent
511     $self instvar m_405
512 
513     # for unique variable names
514     set cmd "regsub -all -- {\\\.} \$winFrame {_} __name \n"
515 
516     append cmd { 
517         frame $winFrame.enc 
518         frame $winFrame.cam 
519         set __f [$self get_option smallfont]
520         label $winFrame.enc.l -text Encoder -font $__f
521         pack  $winFrame.enc.l -side left -fill y
522         label $winFrame.cam.l -text Camera -font $__f
523         pack  $winFrame.cam.l -side left -fill y
524         pack  $winFrame.enc 
525         pack  $winFrame.cam 
526     }
527     set cmd "$cmd [$self FrameRateCommand]"
528     set cmd "$cmd [$self FormatCommand]"
529     set cmd "$cmd [$self InPortCommand]"
530     set cmd "$cmd [$self InDeviceCommand]"
531 
532     # 
533     # Only creates UI for controlling AMX if we successfully 
534     # contacted amxd.
535     #
536     set useAmx [$self get_option useAmx]
537     if {$useAmx == "1" || $useAmx == "yes"} {
538         if {[$m_405 isConnectedToAMX]} {
539             set cmd "$cmd [$self AMXCommand] \n"
540             set cmd "$cmd [$self DeviceCommand] \n"
541         }
542     }
543     append cmd {
544         pack  $winFrame.enc $winFrame.cam -side top
545     }
546 
547     $service Send CONTROL_UI $cmd
548 }
549 
550 ##############################################################################
551 #
552 # RvcApplication private InPortCommand { } {
553 # RvcApplication private InDeviceCommand { } {
554 # RvcApplication private InSignalCommand { } {
555 #
556 # Input:
557 # none
558 #
559 # Output:
560 # the Tk commands that create GUI for choosing difference capture 
561 # card, input ports and signal type
562 #
563 ##############################################################################
564 RvcApplication instproc InDeviceCommand { } {
565     $self instvar m_agent
566     set w \$winFrame.enc.menubInDevice
567 
568     set cmd ""
569     append cmd {
570         menubutton $winFrame.enc.mdev -font $__f -text Device -menu $winFrame.enc.mdev.menu -relief raised 
571         pack $winFrame.enc.mdev -expand 1 -side right -fill y
572         global dev$__name
573         set dev$__name } [$m_agent current_device] {
574         set __menuDEV [menu $winFrame.enc.mdev.menu]
575         }
576     foreach d [$m_agent input_devices] {
577 
578         set cmd "$cmd \$__menuDEV add radio -label \"[$d nickname]\" \
579                 -variable dev\$__name -font \$__f -value \"[$d nickname]\" \
580                 -command \"\$service Send DEVICE [$d nickname]\" \n"
581 
582     }
583     return $cmd
584 }
585 
586 RvcApplication instproc InPortCommand { } {
587     $self instvar m_agent
588     set cmd ""
589     append cmd {
590         set __f [$self get_option smallfont]
591         menubutton $winFrame.enc.mport -text "Port" -menu $winFrame.enc.mport.menu -relief raised -font $__f
592         pack $winFrame.enc.mport -expand 1 -side right -fill y
593         global port$__name
594         set port$__name } [$m_agent current_inport] {
595         set __menuPORT [menu $winFrame.enc.mport.menu] 
596         }
597     foreach p [$m_agent current_inport_list] {
598         set cmd "$cmd \$__menuPORT add radio -label $p \
599                 -variable port\$__name -font \$__f -value $p \
600                 -command \"\$service Send PORT $p\" \n"
601     }
602     return $cmd
603 }
604 
605 
606 RvcApplication instproc FrameRateCommand { } {
607     $self instvar m_agent
608     set cmd ""
609     append cmd {
610         global fps$__name
611         frame $winFrame.enc.fps -relief ridge
612         scale $winFrame.enc.fps.s -relief raised -variable fps$__name -from 1 -to 30 \
613             -orient horiz -state active -font $__f -showvalue no -highlightthickness 1 -length 70
614         label $winFrame.enc.fps.l -textvariable fps$__name -font $__f -width 2
615         set fps$__name } [$m_agent current_fps] {
616         button $winFrame.enc.fps.b -text "< set fps" -font $__f -command "$service Send FPS \$fps$__name"
617         pack $winFrame.enc.fps -side right 
618         pack $winFrame.enc.fps.s $winFrame.enc.fps.l $winFrame.enc.fps.b -side left 
619     }
620     return $cmd
621 }
622 
623 
624 
625 RvcApplication instproc RNCommand { } {
626     # create a menu button for the format
627     return {
628         button $winFrame.butRN -text "Real" \
629             -relief raised -font $__f -command "$service Send TOGGLE_RN"
630         pack $winFrame.butRN -expand 1 -side right -fill y
631     }
632 }
633 
634 RvcApplication instproc FormatCommand { } {
635     $self instvar m_agent
636 
637     set cmd ""
638     # create a menu button for the format
639     append cmd {
640         menubutton $winFrame.enc.mfmt -text Format -menu $winFrame.enc.mfmt.menu -relief raised -font $__f
641         pack $winFrame.enc.mfmt -expand 1 -side right -fill y
642 
643         global format$__name
644         set format$__name } [$m_agent current_fmt] {
645         set __menuFMT [menu $winFrame.enc.mfmt.menu] 
646     }
647 
648     set format_list { h261 jpeg }
649 
650     foreach format $format_list {
651         set cmd "$cmd \$__menuFMT add radio -label $format \
652                 -variable format\$__name -font \$__f -value $format \
653                 -command \"\$service Send FORMAT $format\" \n"
654     }
655 
656     return $cmd
657 }
658 
659 RvcApplication instproc AMXCommand { } {
660     $self instvar m_lConfig
661     array set aConfig $m_lConfig
662 
663     # first make the switch button
664     set cmd ""
665     append cmd {
666         set __w $winFrame.cam.menubSwitch
667         menubutton $__w -font $__f -text "Input.."  -menu ${__w}.menu -relief raised
668         pack $__w -expand 1 -side left
669     }
670     # create the switch menu
671     append cmd {
672         global switch$__name
673         set switch$__name } $aConfig(AMX_SWITCH_STATE) {
674         set __menuSWITCH [menu ${__w}.menu]
675     }
676 
677     # input_list is a list of (label,value) pair
678     set input_list {
679         {Wide Camera}  wideCamera
680         {Speaker Camera} speakerCamera
681         {Audience Camera} audienceCamera
682         {Front PC} frontPC
683         {Laptop} laptop
684         {Elmo} elmo
685         {Front VCR} frontVCR
686         {Rack VCR} rackVCR
687         {Liveboard} liveboard
688         {MBone PC} mbonePC
689         {SGI} sgiPC
690     }
691     foreach {label value} $input_list {
692         set cmd "$cmd \$__menuSWITCH add radio -font \$__f -label \"$label\"\
693                 -variable switch\$__name -value $value \
694                 -command \"\$service Send AMX_SWITCH $value\" \n"
695     }
696 
697     return $cmd
698 }
699 
700 RvcApplication instproc DeviceCommand { } {
701     $self instvar m_lConfig
702     array set aConfig $m_lConfig
703 
704     set cmd ""
705 
706     switch -exact -- $aConfig(AMX_SWITCH_STATE) {
707         speakerCamera -
708         audienceCamera {
709 
710             # put in a frame for the pan button
711             append cmd {
712                 set f [$self get_option smallfont]
713                 frame $winFrame.cam.framePan
714                 pack $winFrame.cam.framePan -side right
715                 }
716 
717             # put in the up down left right zin and zout buttons
718 
719             # the commented out sections are the old interface, where pushing
720             #   the button caused a small pulse movement in that direction
721             # now, you hold down the button to start motion, and release when
722             #   you want it to stop
723 #           set cmd "$cmd button \$winFrame.cam.framePan.right -text Right \
724 #                   -command \"\$service Send AMX_CAMERA_CONTROL right\" \n"
725             append cmd {
726                 set __w $winFrame.cam.framePan.right
727                 button $__w -font $__f -text ">"
728                 pack $__w -side right -fill y
729                 bind $__w <Button-1> "$service Send AMX_CAMERA_CONTROL {start right}"
730                 bind $__w <ButtonRelease-1> "$service Send AMX_CAMERA_CONTROL stop"
731 
732                 frame $winFrame.cam.framePan.updown
733                 pack $winFrame.cam.framePan.updown -side right
734 
735                 set __w $winFrame.cam.framePan.updown.up
736                 button $__w -font $__f -text "^"
737                 pack $__w -fill x -side top
738                 bind $__w <Button-1> "$service Send AMX_CAMERA_CONTROL {start up}"
739                 bind $__w <ButtonRelease-1> "$service Send AMX_CAMERA_CONTROL stop"
740 
741                 set __w $winFrame.cam.framePan.updown.down
742                 button $__w -font $__f -text "v"
743                 pack $__w -side bottom
744                 bind $__w <Button-1> "$service Send AMX_CAMERA_CONTROL {start down}"
745                 bind $__w <ButtonRelease-1> "$service Send AMX_CAMERA_CONTROL stop"
746 
747                 set __w $winFrame.cam.framePan.left
748                 button $__w -font $__f -text "<"
749                 pack $__w -side right -fill y
750                 bind $__w <Button-1> "$service Send AMX_CAMERA_CONTROL {start left}"
751                 bind $__w <ButtonRelease-1> "$service Send AMX_CAMERA_CONTROL stop"
752             }
753 
754             append cmd {
755                 set __w $winFrame.cam.framePan.zinout
756                 frame $__w
757                 pack $__w -side right 
758                 button ${__w}.in -font $__f -text "zoom in" 
759                 pack ${__w}.in -fill x -side top
760                 bind ${__w}.in <Button-1> "$service Send AMX_CAMERA_CONTROL {start in}"
761                 bind ${__w}.in <ButtonRelease-1> "$service Send AMX_CAMERA_CONTROL stop"
762 
763                 button ${__w}.out -font $__f -text "zoom out"
764                 pack ${__w}.out -side bottom
765                 bind ${__w}.out <Button-1> "$service Send AMX_CAMERA_CONTROL {start out}"
766                 bind ${__w}.out <ButtonRelease-1> "$service Send AMX_CAMERA_CONTROL stop"
767             }
768 
769             # create a menu button for extra effects
770             append cmd {
771                 set __w $winFrame.cam.framePan.finout
772                 frame $__w
773                 pack $__w -side right
774                 button ${__w}.in -font $__f -text "fade in" -command "$service Send AMX_CAMERA_CONTROL {fade in}"
775                 pack ${__w}.in -fill x -side top
776 
777                 button ${__w}.out -font $__f -text "fade out" -command "$service Send AMX_CAMERA_CONTROL {fade out}"
778                 pack ${__w}.out -side bottom
779             }
780         }
781         frontVCR -
782         rackVCR {
783             # put in the power, pause, stop, rewind, forward, play
784             # and record buttons
785             append cmd {
786                 frame $winFrame.cam.frameVCR
787                 pack $winFrame.cam.frameVCR -side right
788 
789                 frame $winFrame.cam.frameVCR.0
790                 pack $winFrame.cam.frameVCR.0 -side right
791 
792                 button $winFrame.cam.frameVCR.0.ff -font $__f -text ">>" \
793                         -command "$service Send AMX_VCR_CONTROL ffwd"
794                 pack $winFrame.cam.frameVCR.0.ff -fill x -side top
795 
796                 button $winFrame.cam.frameVCR.0.rec -font $__f -text Rec \
797                         -command "$service Send AMX_VCR_CONTROL rec"
798                 pack $winFrame.cam.frameVCR.0.rec -side bottom -fill x
799 
800                 frame $winFrame.cam.frameVCR.1
801                 pack $winFrame.cam.frameVCR.1 -side right
802 
803                 button $winFrame.cam.frameVCR.1.play -font $__f -text ">" \
804                         -command "$service Send AMX_VCR_CONTROL play"
805                 pack $winFrame.cam.frameVCR.1.play -side top -fill x
806 
807                 button $winFrame.cam.frameVCR.1.stop -font $__f -text Stop \
808                         -command "$service Send AMX_VCR_CONTROL stop"
809                 pack $winFrame.cam.frameVCR.1.stop -side bottom -fill x
810 
811                 frame $winFrame.cam.frameVCR.2
812                 pack $winFrame.cam.frameVCR.2 -side right
813 
814                 button $winFrame.cam.frameVCR.2.rr -font $__f -text "<<" \
815                         -command "$service Send AMX_VCR_CONTROL rew"
816                 pack $winFrame.cam.frameVCR.2.rr -side top -fill x
817 
818                 button $winFrame.cam.frameVCR.2.pause -font $__f -text "||" \
819                         -command "$service Send AMX_VCR_CONTROL pause"
820                 pack $winFrame.cam.frameVCR.2.pause -side bottom -fill x
821 
822                 button $winFrame.cam.frameVCR.power -font $__f -text Power \
823                         -command "$service Send AMX_VCR_CONTROL power"
824                 pack $winFrame.cam.frameVCR.power -side right -fill y
825             }
826         }
827 
828         elmo {
829         }
830 
831         wideCamera -
832         laptop -
833         liveboard -
834         sgiPC -
835         mbonePC -
836         frontPC {
837         }
838 
839     }
840 
841     return $cmd
842 }
843 
844 RvcApplication instproc Device { service args } {
845     $self instvar m_agent m_service
846     set device [$m_agent get_device_by_name $args]
847     if {$device != "" && $device != [$m_agent current_device]} {
848         $m_agent set_device $device
849         $self GetUIControl $m_service 0
850     } else {
851         puts stderr "Device is $device"
852     }
853 }
854 
855 RvcApplication instproc Port { service port } {
856     $self instvar m_agent
857     $m_agent set_inport $port
858 }
859 
860 RvcApplication instproc Format { service arguments } {
861 #    puts "format changing to $arguments"
862 
863     $self instvar m_agent
864     $m_agent set_fmt $arguments
865 }
866 
867 
868 RvcApplication instproc FrameRate { service arguments } {
869 #    puts "format changing to $arguments"
870 
871     $self instvar m_agent
872     $m_agent set_fps $arguments
873 }
874 
875 
876 #RvcApplication instproc Signal { service arguments } {
877 #    puts "format changing to $arguments"
878 #
879 #    $self instvar m_agent
880 #    $m_agent set_signal $arguments
881 #}
882 
883 
884 RvcApplication public RemoteAMXSwitch { service target } {
885     $self instvar m_service
886 
887     # do the switch
888     $self AMXSwitch $target
889 
890     # now update the user interface for the client
891     $self GetUIControl $m_service 0
892 }
893 
894 # the string argument to UPDATE_INFO is put in the DC display
895 RvcApplication public GetInfo { service } {
896     $self instvar m_switchReal
897 
898     if {$m_switchReal} {
899         $service Send UPDATE_INFO "RealNetworks Following"
900     } else {
901         $service Send UPDATE_INFO ""
902     }
903 }
904 
905 RvcApplication public ToggleRn { service } {
906     $self instvar m_service m_switchReal
907 
908     if {$m_switchReal} {
909         set m_switchReal 0
910     } else {
911         set m_switchReal 1
912     }
913 
914     # update the UI
915     $self GetInfo $m_service
916 }
917 
918 RvcApplication public AMXSwitch { target } {
919     $self instvar m_405
920     $self instvar m_lConfig
921     $self instvar m_switchReal
922     array set aConfig $m_lConfig
923 
924     set matrix $aConfig(AMX_OUTPUT_SWITCH)
925 
926     if {$m_switchReal} {
927         $m_405 matrix_switchVideoStream $target realNetworks
928     }
929 
930     # matrix is the output, target is the input
931     # use the amxd matrix library
932     $m_405 matrix_switchVideoStream $target $matrix
933 
934 
935     set aConfig(AMX_SWITCH_STATE) $target
936     set m_lConfig [array get aConfig]
937 }
938 
939 RvcApplication public AMXCameraControl { service argument } {
940     $self instvar m_405
941     $self instvar m_lConfig
942     $self instvar m_cameraMoveButtonPressed
943     array set aConfig $m_lConfig
944 
945     # make sure that the switch is switched to the camera view
946     switch -exact -- $aConfig(AMX_SWITCH_STATE) {
947         audienceCamera {
948             set cam "audience"
949         }
950         speakerCamera {
951             set cam "speaker"
952         }
953         default { return }
954     }
955 
956     set arg [lindex $argument 0]
957 
958     switch -exact -- $arg {
959         in -
960         out -
961         left -
962         right -
963         up -
964         down {
965             $m_405 camera_pulseMove $cam $argument
966         }
967         start {
968             set arg2 [lindex $argument 1]
969             switch -exact -- $arg2 {
970                 up -
971                 down -
972                 left -
973                 right -
974                 in -
975                 out {
976                     set m_cameraMoveButtonPressed 1
977                     $m_405 camera_startMove $cam $arg2
978                 }
979                 default {
980                     return
981                 }
982             }
983         }
984         stop {
985             set m_cameraMoveButtonPressed 0
986             $m_405 camera_stopMove $cam
987         }
988         fade {
989             set arg2 [lindex $argument 1]
990             switch -exact -- $arg2 {
991                 in {
992                     $m_405 camera_fadeIn $cam
993                 }
994                 out {
995                     $m_405 camera_fadeOut $cam
996                 }
997             }
998         }
999         default {
1000             puts stdout "amxcameracontrol: urecognized argument is $argument"
1001             return
1002         }
1003     }
1004 
1005 
1006 }
1007 
1008 RvcApplication public AMXVCRControl { service argument } {
1009     $self instvar m_405
1010     $self instvar m_lConfig
1011     array set aConfig $m_lConfig
1012 
1013     # make sure that the switch is switched to the vcr
1014     # give a vcr number if it is a vcr otherwise just return
1015     switch -exact -- $aConfig(AMX_SWITCH_STATE) {
1016         frontVCR {
1017             $m_405 vcr_doFunction front $argument
1018         }
1019         rackVCR {
1020             $m_405 vcr_doFunction rack $argument
1021         }
1022         default {
1023             return
1024         }
1025     }
1026 }
1027 
1028 ##############################################################################
1029 #
1030 # RvcApplication public GetSdsServiceData { } {
1031 #
1032 # Input:
1033 # none
1034 #
1035 # Output:
1036 # the data that the will go out to the sds system
1037 #
1038 # Description:
1039 # This is a callback function for the service discovery system.  Need to
1040 # return the data that will go out to the sds system.  So far there are
1041 # three fields with their values
1042 #
1043 ##############################################################################
1044 RvcApplication public GetSdsServiceData { } {
1045     $self instvar m_lConfig
1046 
1047     set options [$self options]
1048     set iComPort [$options get_option optComPort]