1 # agent-studio.tcl --
2 #
3 # Derived from VideoAgent. DcStudioAgent takes video packets and
4 # uses the PacketSplitter, sending one packet to a decoder and the
5 # other to a PacketSwitcher for (possible) broadcasting.
6 #
7 # Copyright (c) 2000-2002 The Regents of the University of California.
8 # All rights reserved.
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions are met:
12 #
13 # A. Redistributions of source code must retain the above copyright notice,
14 # this list of conditions and the following disclaimer.
15 # B. Redistributions in binary form must reproduce the above copyright notice,
16 # this list of conditions and the following disclaimer in the documentation
17 # and/or other materials provided with the distribution.
18 # C. Neither the names of the copyright holders nor the names of its
19 # contributors may be used to endorse or promote products derived from this
20 # software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
23 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
26 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 import VideoAgent
34
35 #-----------------------------------------------------------------------------
36 # Class:
37 # DcStudioAgent
38 #
39 # Description:
40 # Derived from VideoAgent. DcStudioAgent takes video packets and
41 # uses the PacketSplitter, sending one packet to a decoder and the
42 # other to a PacketSwitcher for (possible) broadcasting.
43 #
44 # Members:
45 # splitter_ -- an array PackerSplitter for copying packets to two
46 # destinations. Indexed by Source/RTP objects.
47 # switcher_ -- the Module/RTPSwitcher object.
48 #-----------------------------------------------------------------------------
49 Class DcStudioAgent -superclass VideoAgent
50
51 #-----------------------------------------------------------------------------
52 # Method:
53 # DcStudioAgent init
54 #
55 # Arguments:
56 # dcApp -- the Application object for DC
57 # inetAddr,iPort,iTTL -- mcast specification of the studio video session
58 # packetSwitcher -- a Module/RTPSwitcher object.
59 #
60 # Description:
61 # Set members according to the input values and call constructor for
62 # VideoAgent. Initialize the splitter to "".
63 #
64 #-----------------------------------------------------------------------------
65 DcStudioAgent instproc init {dcApp inetAddr iPort iTTL packetSwitcher} {
66 $self next $dcApp "$inetAddr/$iPort//$iTTL"
67 $self instvar switcher_
68
69 set switcher_ $packetSwitcher
70 }
71
72
73 #-----------------------------------------------------------------------------
74 # Method:
75 # DcStudioAgent create_decoder
76 #
77 # Arguments:
78 # src -- the Source/RTP object which we want to process/decode.
79 #
80 # Description:
81 # This overrides VideoAgent's create_decoder{}, which creates a
82 # decoder, and returns it so that it is used as the data-handler of
83 # $src in activate{} and reactivate{}. Here, we want the data
84 # handler of $src to be the splitter instead, so we return $splitter_.
85 # We also initialize (or re-initialize) both targets of the splitter.
86 #
87 #-----------------------------------------------------------------------------
88 DcStudioAgent instproc create_decoder {src} {
89 $self instvar switcher_ splitter_
90
91 #
92 # This method could be call when a new source is detected,
93 # or when an existing source change its format. If it is
94 # the latter, we do not need to create a splitter again.
95 #
96 if {![info exists splitter_($src)]} {
97 set splitter_($src) [new Module/PacketSplitter]
98 }
99
100 # This will actually create the decoder.
101 set decoder [$self next $src]
102
103 #
104 # FIXME: This is nasty. We're storing the decoder object
105 # in the Sourcre/RTP object. This is so that the
106 # handler is the splitter but the code for rendering
107 # and stuff can still find the decoder (normally,
108 # it is assumed that the data-handler for Source/RTP object
109 # is the decoder, but this isn't the case here!)
110 #
111 # THIS MEANS YOU HAVE TO BE CAREFUL. Everywhere a decoder is
112 # assumed to be a Source/RTP's data handler, you have to do
113 # a set decoder to get the actual decoder object.
114 #
115 $src set decoder_ $decoder
116
117 $splitter_($src) target $decoder
118 $splitter_($src) target2 $switcher_
119
120 return $splitter_($src)
121 }
122
123
124 #-----------------------------------------------------------------------------
125 # Method:
126 # DcStudioAgent reactivate
127 #
128 # Arguments:
129 # src -- the Source/RTP object which we want to process/decode.
130 #
131 # Description:
132 # We need to override VideoAgent's reactivate{} here since the
133 # data-handler for $src is not a decoder as VideoAgent expects,
134 # but is a packet splitter instead.
135 #
136 # It removes the current decoder for $src, creates a new decoder,
137 # and returns the splitter.
138 #
139 # NOTE: This return value is not used. (?)
140 #
141 #-----------------------------------------------------------------------------
142 DcStudioAgent instproc reactivate {src} {
143
144 $self instvar splitter_
145
146 #
147 # Delete current decoder if it exists
148 #
149 set old_decoder [$splitter_($src) target]
150 if {$old_decoder != ""} {
151 delete $old_decoder
152 }
153
154 #
155 # Replace current_decoder in the decoder list.
156 #
157 $self instvar decoders_
158 set k [lsearch -exact $decoders_ $old_decoder]
159 set decoders_ [lreplace $decoders_ $k $k]
160
161 #
162 # This will create the decoder and add it as
163 # first target of $splitter_
164 #
165 $self create_decoder $src
166
167
168 lappend decoders_ [$splitter_($src) target]
169 return $splitter_($src)
170 }
171
172
173 #-----------------------------------------------------------------------------
174 # Method:
175 # DcStudioAgent switch_src
176 #
177 # Arguments:
178 # src -- the Source/RTP object which we want to switch
179 #
180 # Description:
181 # Set the input source id of the switcher to $src.
182 #-----------------------------------------------------------------------------
183 DcStudioAgent instproc switch_src {src} {
184 $self instvar switcher_
185 $switcher_ set isrcid_ [$src srcid]
186 }
187
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.