1 # session-receiver.tcl --
2 #
3 # FIXME: This file needs a description here.
4 #
5 # Copyright (c) 2001-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 Import enable
32 import Application VideoAgent VideoWidget VisualFrame VEUserWindow
33
34 ######
35 #SessionReceiver
36 # This class receives and displays RTP streams of video as thumbnails from
37 # a single session. It creates the SessionReceiverSM which attaches to the
38 # VideoAgent and VisualFrame.
39 #
40
41 Class SessionReceiver -superclass Application
42
43 SessionReceiver instproc init {spec w} {
44 $self next sessionReceiver
45 $self instvar agent_ srcmgr_ w_ vframe_
46 global view
47 set agent_ [new VideoAgent $self $spec]
48 set w_ $w
49
50 if {$view == "vic"} {
51 frame $w_
52 }
53
54 if {![winfo exists $w_.sources]} {
55 set vframe_ [new VisualFrame $w_.sources]
56 }
57 set srcmgr_ [new SessionReceiverSM $agent_ $w_.sources $vframe_ $spec]
58 pack $w_.sources -expand true -fill both -side right
59 $agent_ attach $srcmgr_
60 $vframe_ attach_observer $srcmgr_
61 }
62
63 #
64 # Detaches the SessionReceiverSM from the VideoAgent and the VisualFrame.
65 #
66 SessionReceiver instproc detachAll {} {
67 $self instvar agent_ srcmgr_ vframe_
68 $agent_ detach $srcmgr_
69 $vframe_ detach_observer $srcmgr_
70 $srcmgr_ remove_active
71 }
72
73 #
74 # Destroys all the toplevel UserWindows that were originated from this
75 # session.
76 #
77 SessionReceiver instproc unpack_VEuw {} {
78 $self instvar srcmgr_
79 set source_list [$srcmgr_ source_list]
80 foreach source $source_list {
81 if {[winfo exists .vw$source]} {
82 set veuw [$source source_veUW]
83 $veuw destroy
84 }
85 }
86 }
87
88 ######
89 #SessionReceiverSM
90 # This is the source manager for the SessionReceiver, which is attached
91 # to the VideoAgent. It takes care of firing up SessionRecieverAS
92 # (active source) objects when they are needed.
93 #
94
95 Class SessionReceiverSM -superclass Observer
96
97 SessionReceiverSM instproc init {agent w vframe spec} {
98 ### w: .$view.$spec_window.sources
99
100 $self next
101 $self instvar agent_ target_ w_ label_ vframe_ source_list_ spec_
102 global active_sources
103
104 set w_ $w
105 set vframe_ $vframe
106 set agent_ $agent
107 set source_list_ ""
108 set target_ ""
109 set spec_ $spec
110 set active_sources($spec_) ""
111
112 set label_ $w_.label
113 label $label_ -text "Waiting for video..."
114 pack $label_ -anchor c -expand 1 -side left -fill both
115 }
116
117 #
118 # Waits for incoming video packets.
119 #
120 SessionReceiverSM instproc trigger_media {src} {
121 after idle "$self really_activate $src"
122 }
123
124 #
125 # When packets are received, it instantiates a new SessionReceiverAS and
126 # adds the active source to the source_list_.
127 #
128 SessionReceiverSM instproc really_activate {src} {
129 $self instvar frame_ decoder_ renderer_ vframe_ source_list_ w_
130 set as [new SessionReceiverAS $self $w_.$src $src $vframe_]
131 set source_list_ [concat $source_list_ $as]
132 }
133
134 #
135 # Adds the source to the grid and the array active_.
136 #
137 SessionReceiverSM instproc add_active {sras src} {
138 $self instvar active_ w_ label_ spec_
139 global active_sources
140
141 set active_sources($spec_) [concat $active_sources($spec_) $sras]
142 set active_($src) $sras
143 if { [array size active_] == 1 } {
144 pack forget $label_
145 pack $w_ -expand 1 -fill x -anchor n
146 }
147 }
148
149 #
150 # Removes the sources in this session by detaching the thumbnail.
151 #
152 SessionReceiverSM instproc remove_active {} {
153 $self instvar source_list_
154 foreach source $source_list_ {
155 $source detach_window [$source source_thumbnail]
156 }
157 }
158
159 #
160 # Returns the list of the active sources in this session.
161 #
162 SessionReceiverSM instproc source_list {} {
163 $self instvar source_list_
164 return $source_list_
165 }
166
167 ######
168 #SessionReceiverAS
169 # This active source object creates a thumbnail sized VideoWidget for
170 # it's source. The attach-thumbnail procedure calls the attach-decoder
171 # procedure, which creates the Renderer object to display the thumbnail.
172 #
173
174 Class SessionReceiverAS -superclass TkWindow
175
176 SessionReceiverAS instproc init {srsm w src vframe} {
177 ### w: $w_.$src
178
179 $self next $w
180 $srsm add_active $self $src
181 frame $w -relief groove
182 pack $w -side left
183
184 $self instvar srsm_ src_ vframe_ thumbnail_
185 set srsm_ $srsm
186 set src_ $src
187 set vframe_ $vframe
188
189 set stamp $w.stamp
190 frame $stamp -relief ridge -borderwidth 2
191 set video_widget_path $stamp.video
192 set thumbnail_ [new VideoWidget $video_widget_path 80 60]
193 $thumbnail_ set is_slow_ 0
194 $self attach_window $thumbnail_
195 pack $stamp.video -side left -anchor c -padx 2
196 pack $stamp -side left -fill y
197
198 bind $video_widget_path <ButtonPress-1> "$self select_thumbnail"
199 bind $video_widget_path <ButtonPress-3> "$self trigger_dropmenu"
200
201 }
202
203 #
204 # Attaches a decoder to the VideoWidget
205 #
206 SessionReceiverAS instproc attach_window {vw} {
207 $self instvar src_ vframe_
208 $vw attach-decoder $src_ [$vframe_ set colorModel_] true
209 }
210
211 #
212 # Detaches the decoder from the VideoWidget
213 #
214 SessionReceiverAS instproc detach_window {vw} {
215 $self instvar src_
216 $vw detach-decoder $src_
217 }
218
219 #
220 # If the user clicks on a thumbnail, it creates a larger video by
221 # instantiating a VEUserWindow if it doesn't already exist, or else
222 # destroy it.
223 #
224 SessionReceiverAS instproc select_thumbnail {} {
225 $self instvar srsm_ VEuw_
226 if {[winfo exists .vw$self]} {
227 $VEuw_ destroy
228 } else {
229 set VEuw_ [new VEUserWindow $srsm_ $self]
230 }
231 }
232
233 #
234 # Return the thumbnail of this source.
235 #
236 SessionReceiverAS instproc source_thumbnail {} {
237 $self instvar thumbnail_
238 return $thumbnail_
239 }
240
241 #
242 # Returns the veUserWindow of this source.
243 #
244 SessionReceiverAS instproc source_veUW {} {
245 $self instvar VEuw_
246 return $VEuw_
247 }
248
249 #
250 # Returns the src variable of the active source
251 #
252 SessionReceiverAS instproc get_src {} {
253 $self instvar $src_
254 return $src_
255 }
256
257
258 #
259 # When the user clicks the right mouse button on a thumbnail, this method
260 # is called to create a dropdown menu
261 #
262 SessionReceiverAS instproc trigger_dropmenu {} {
263 global videodrop
264 if {[winfo exists .videodrop]} {
265 tk_popup $videodrop \
266 [winfo pointerx .videodrop] [winfo pointery .videodrop]
267 } else {
268 set videodrop [menu .videodrop -tearoff 0]
269 $videodrop add command -label Exit
270 tk_popup $videodrop \
271 [winfo pointerx .videodrop] [winfo pointery .videodrop]
272 }
273 }
274
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.