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

Open Mash Cross Reference
mash/tcl/dc/dc/ui-dcvideo.tcl

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

  1 # ui-dcvideo.tcl --
  2 #
  3 #       Stuff for providing the service-specific UI that accompanies
  4 #       video sources when in the preview or broadcast pane.
  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 DcVideoWidget
 33 import DragNDrop
 34 
 35 Class CDcUIVideo
 36 
 37 CDcUIVideo public init { uiMain winFrame source service} {
 38     # member variables
 39     $self instvar m_uiMain
 40     $self instvar m_winFrame
 41 
 42     $self instvar m_source
 43     $self instvar m_service
 44     $self instvar m_font
 45 
 46     # store away input
 47     set m_uiMain $uiMain
 48     set m_winFrame $winFrame
 49 
 50     set m_source $source
 51     set m_service $service
 52 
 53     set m_font [$self get_option smallfont]
 54 }
 55 
 56 CDcUIVideo public destroy { } {
 57     $self instvar m_source
 58     $self instvar m_service
 59     $self instvar m_vwVideo
 60     $self instvar m_winFrame
 61 
 62     # unmap the ui update message
 63     if { $m_service != 0 } {
 64         # unmap the old get_ui_control message
 65         $m_service UnmapMessage "CONTROL_UI" $self "ControlUI"
 66         $m_service UnmapMessage "UPDATE_CONTROL_UI" $self "UpdateControlUI"
 67         $m_service UnmapMessage "UPDATE_INFO" $self "UpdateInfo"
 68     }
 69 
 70     # detach the video
 71     $m_vwVideo detach-decoder $m_source
 72 
 73     # destroy the window
 74     destroy $m_winFrame.frame.video
 75     destroy $m_winFrame.frame.control
 76     destroy $m_winFrame.frame.info
 77     destroy $m_winFrame.frame
 78 
 79     $self next
 80 }
 81 
 82 CDcUIVideo private BuildUI {} {
 83     $self instvar m_uiMain
 84     $self instvar m_winFrame
 85     $self instvar m_source
 86     $self instvar m_font
 87 
 88     # set up the frame for the video and the controls
 89     frame $m_winFrame.frame -relief raised -borderwidth 3
 90     pack $m_winFrame.frame -side top
 91 
 92     frame $m_winFrame.frame.video
 93     pack $m_winFrame.frame.video -side top
 94 
 95     frame $m_winFrame.frame.control -relief ridge -borderwidth 2
 96     pack $m_winFrame.frame.control -side top -fill x
 97 
 98     # This needs to be created after the video has started since
 99     # it uses m_vwVideo.
100 
101     frame $m_winFrame.frame.info -relief ridge -borderwidth 2
102     pack $m_winFrame.frame.info -side bottom -fill x
103 
104     # it will be filled in later by calling GET_INFO
105     label $m_winFrame.frame.info.label -text "" -font $m_font -relief ridge
106 
107     checkbutton $m_winFrame.frame.info.slow$self -text "low refresh rate" \
108         -font $m_font -indicatoron true -command "$self ToggleSlow"
109 
110     pack $m_winFrame.frame.info.label $m_winFrame.frame.info.slow$self -side left
111 
112     # start the video and controls
113     $self StartVideo
114     $self StartControl
115 
116 
117 }
118 
119 
120 CDcUIVideo public ToggleSlow { } {
121     $self instvar m_vwVideo
122     if {![info exists m_vwVideo]} {
123         return
124     }
125     if {[$m_vwVideo is-slow]} {
126         $m_vwVideo set_normal
127     } else {
128         $m_vwVideo set_slow
129     }
130 }
131 
132 
133 CDcUIVideo public SwitchVideo { source } {
134     $self instvar m_uiMain
135     $self instvar m_source
136     $self instvar m_vwVideo
137     $self instvar m_winFrame
138 
139     # detach the video
140     # $m_vwVideo detach-decoder $m_source
141     $m_vwVideo detach-decoder $m_source
142 
143     # now attach the new video
144     set m_source $source
145     $m_vwVideo attach-decoder $m_source [$m_uiMain set m_ColorModel] 0
146 
147     #switch frame color
148     set srcidtemp [$m_source srcid]
149     set r [expr $srcidtemp % 4096]
150     set srcidtemp [expr $srcidtemp / 7]
151     set g [expr $srcidtemp % 4096]
152     set srcidtemp [expr $srcidtemp / 11]
153     set b [expr $srcidtemp % 4096]
154     set color [format "#%03x%03x%03x" $r $g $b]
155     $m_winFrame.frame configure -background $color
156 
157     #change the label
158     set hostaddr [$m_source addr]
159     set hostname [lookup_host_name $hostaddr]
160     set hostname [string tolower $hostname]
161     $m_winFrame.frame.info.label configure -text "$hostname"
162 }
163 
164 
165 CDcUIVideo public StartVideo { } {
166     $self instvar m_winFrame
167     $self instvar m_uiMain
168     $self instvar m_source
169 
170     # set the color for the frame
171     # FIXME - this is just weird and doesn't work all that great
172     #  it would be better to have several distinct colors and keep
173     #  track of which ones are available
174     expr srand([$m_source srcid])
175     set r [expr int(rand() * 4096)]
176     set g [expr int(rand() * 4096)]
177     set b [expr int(rand() * 4096)]
178     set color [format "#%03x%03x%03x" $r $g $b]
179     $m_winFrame.frame configure -background $color
180 
181     # create the new preview window
182     $self instvar m_vwVideo
183 
184     set m_vwVideo [new DcVideoWidget $m_winFrame.frame.video.video 352 288]
185     pack $m_winFrame.frame.video.video -side top -fill both -expand 1
186 
187     # attach it to the source
188     $m_vwVideo attach-decoder $m_source [$m_uiMain set m_ColorModel] 0
189 }
190 
191 CDcUIVideo public StartControl { } {
192     $self instvar m_service
193     $self instvar m_winFrame
194 
195     # FIXME - this doesn't seem to be supported anymore so comment it out
196     #     it seems like a good idea though....
197 
198     # ok put in the main menu stuff, like remote window
199     #menubutton $m_winFrame.frame.control.menubutton -text "Win" -menu $m_winFrame.frame.control.menubutton.menu -relief raised
200     #pack $m_winFrame.frame.control.menubutton -side right -fill y
201 
202     #set winMenu [menu $m_winFrame.frame.control.menubutton.menu]
203     #$winMenu add command -label "Remove" -command "$self RemoveSelf"
204 
205     # if there's no service then just return
206     if { $m_service == 0 } {
207         return
208     }
209 
210     # otherwise try to get the service control ui
211 
212     # add the control window with nothing so update ui can destroy it
213     frame $m_winFrame.frame.control.serviceFrame
214     pack $m_winFrame.frame.control.serviceFrame -side right -fill y
215 
216     $self ControlUI $m_service 0
217     $self InfoUI $m_service
218 
219     # add the final frame to fill up the rest of the space
220     frame $m_winFrame.frame.control.filler -relief raised -borderwidth 2
221     pack $m_winFrame.frame.control.filler -side left -expand 1 -fill both
222 
223 
224     # register this object to get update messages
225     $m_service MapMessage "CONTROL_UI" $self "ControlUI"
226     $m_service MapMessage "UPDATE_CONTROL_UI" $self "UpdateControlUI"
227     $m_service MapMessage "UPDATE_INFO" $self "UpdateInfo"
228 }
229 
230 CDcUIVideo public SwitchService { service } {
231     $self instvar m_service
232 
233     # clear out the control panel
234     $self ControlUI $m_service ""
235 
236     # unmap the ui update message
237     if { $m_service != 0 } {
238         # unmap the old get_ui_control message
239         $m_service UnmapMessage "CONTROL_UI" $self "ControlUI"
240         $m_service UnmapMessage "UPDATE_CONTROL_UI" $self "UpdateControlUI"
241         $m_service UnmapMessage "UPDATE_INFO" $self "UpdateInfo"
242     }
243 
244     # map the new service
245     set m_service $service
246 
247     # map the new service and get the latest ui
248     if { $m_service != 0 } {
249         $m_service MapMessage "CONTROL_UI" $self "ControlUI"
250         $m_service MapMessage "UPDATE_CONTROL_UI" $self "UpdateControlUI"
251         $m_service MapMessage "UPDATE_INFO" $self "UpdateInfo"
252         $self ControlUI $m_service 0
253         $self InfoUI $m_service
254         $m_service Send "FIR"
255     }
256 }
257 
258 CDcUIVideo public InfoUI {service} {
259     $self instvar m_service
260 
261     $m_service Send "GET_INFO"
262 }
263 
264 CDcUIVideo public ControlUI { service uiCommands } {
265     $self instvar m_winFrame
266     $self instvar m_service
267 
268     # now check if the uiCommands is good
269     # this function can be called either by the remote service
270     # or local precedure call.  If it's local then the uiCommand
271     # will be set to 0 otherwise it's assumed to be the correct
272     # commands
273     if { $uiCommands == 0 } {
274         set uiCommands [$m_service Send "GET_UI_CONTROL" ""]
275         return
276     }
277 
278     # first destroy what we had before
279     destroy $m_winFrame.frame.control.serviceFrame
280 
281     # the name winFrame is really important here
282     # the commands that you get will assume that there
283     # is a variable called winFrame to add control into
284     # also it will assume that service has the service
285     # object to send the control information to
286 
287     set service $m_service
288     set winFrame [frame $m_winFrame.frame.control.serviceFrame]
289     pack $m_winFrame.frame.control.serviceFrame -side right
290 
291     eval $uiCommands
292 }
293 
294 
295 ##############################################################################
296 #
297 # CReplayProxyApplication private UpdateControlUI { service arguments }
298 #
299 # Input:
300 # service - the service that called this function
301 # arguments - the ui commands that will be evaluated to update the ui
302 #
303 # Output:
304 # none
305 #
306 # Description:
307 # it is called whenever we need to update the ui of the controls.
308 # the differnce from this func and Control UI is that, this doesn't
309 # destroy the window before the function is called.
310 #
311 ##############################################################################
312 CDcUIVideo public UpdateControlUI { service uiCommands } {
313     $self instvar m_winFrame
314     $self instvar m_service
315 
316     # now check if the uiCommands is good
317     # this function can be called either by the remote service
318     # or local precedure call.  If it's local then the uiCommand
319     # will be set to 0 otherwise it's assumed to be the correct
320     # commands
321     if { $uiCommands == 0 } {
322         set uiCommands [$m_service Send "UPDATE_CONTROL_UI" ""]
323         return
324     }
325 
326     # the name winFrame is really important here
327     # the commands that you get will assume that there
328     # is a variable called winFrame to add control into
329     # also it will assume that service has the service
330     # object to send the control information to
331     set service $m_service
332     set winFrame $m_winFrame.frame.control.serviceFrame
333 
334     eval $uiCommands
335 }
336 
337 
338 CDcUIVideo public UpdateInfo { service newInfo } {
339     $self instvar m_winFrame
340     $self instvar m_service
341     $self instvar m_source
342 
343     # FIXME - can also do [$m_source getid], [$m_source ssrc],
344     #   [$m_source srcid] to get info
345     set hostaddr [$m_source addr]
346     set hostname [lookup_host_name $hostaddr]
347     set hostname [string tolower $hostname]
348     # FIXME - limit the length
349     $m_winFrame.frame.info.label configure -text "$hostname: $newInfo"
350 }
351 
352 
353 #-----------------------------------------------------------------------------
354 #
355 # CDcUIVideo GetSource
356 # CDcUIVideo GetVideoWidget
357 #
358 # Description:
359 #   Return the source, and the videowidget attached to this object respectively.
360 #
361 #-----------------------------------------------------------------------------
362 CDcUIVideo public GetSource { } {
363     $self instvar m_source
364     return $m_source
365 }
366 
367 
368 CDcUIVideo public GetVideoWidget { } {
369     $self instvar m_vwVideo
370     return $m_vwVideo 
371 }
372 

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

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.