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

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

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

  1 # agent-rvc.tcl --
  2 #
  3 #       Derived from VideoAgent; used to transmit the video onto the network
  4 #
  5 # Copyright (c) 2000-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 VideoAgent
 32 import Observer
 33 import VideoPipeline
 34 
 35 #
 36 # Code for RvcObserver
 37 #
 38 Class RvcObserver -superclass Observer
 39 
 40 RvcObserver instproc init {app} {
 41 
 42     $self next
 43 
 44     $self instvar app_
 45 
 46     set app_ $app
 47 }
 48 
 49 #
 50 # Code for RvcAgent
 51 #
 52 Class RvcAgent -superclass VideoAgent
 53 
 54 RvcAgent instproc init {app spec} {
 55     $self next $app $spec
 56 
 57     $self instvar decoder_
 58 
 59     #
 60     # Make a single Null VideoDecoder for all to share.
 61     #
 62     set decoder_ [new Module/VideoDecoder/Null]
 63 
 64     #
 65     # Setup pipeline and stuff for capture.
 66     #
 67     $self instvar pipeline_
 68 
 69     set pipeline_ [new VideoPipeline $self]
 70 
 71     #
 72     # Setup stuff for formats and qualities for the grabber.
 73     #
 74     $self instvar device_
 75     set device_ "none"
 76 
 77     $self instvar qval_
 78     set qval_(h261) 95
 79     set qval_(nv) 80
 80     set qval_(nvdct) 80
 81     set qval_(pvh) 60
 82     set qval_(jpeg) 95
 83 
 84     #
 85     # Setup the default formats.
 86     #
 87     $self instvar devfmt_
 88 
 89     set videoFormat [$self get_option videoFormat]
 90     if { $videoFormat == "h.261" } {
 91         set videoFormat h261
 92     }
 93 
 94     set qval_($videoFormat) [$self get_option videoQuality]
 95 
 96     foreach d [$pipeline_ input_devices] {
 97         set fmtList [$pipeline_ available_formats $d]
 98 
 99         #
100         # if videoFormat is part of fmtList, use it, otherwise
101         # use the first format in the list.
102         #
103         if {[lsearch -exact $fmtList $videoFormat] >= 0} {
104             set devfmt_($d) $videoFormat
105         } else {
106             set devfmt_($d) [lindex $fmtList 0]
107         }
108 
109     }
110 
111     #
112     # Setup the default ports.
113     #
114     $self instvar devport_
115 
116     set videoPort [$self get_option videoInputPort]
117 
118     foreach d [$pipeline_ input_devices] {
119         set portList [$d get_attribute port]
120         if [inList $videoPort $portList] {
121             set devport_($d) $videoPort
122         } else {
123             set devport_($d) [lindex $portList 0]
124         }
125     }
126 
127     $self select_initial_device
128 
129     #
130     # Do frame rate and bit rates.
131     #
132     $self instvar fps_ bps_
133 
134     set fps_ [$self get_option frameRate]
135     set bps_ [$self get_option videoBandwidth]
136 
137     $self set_fps $fps_
138     $self set_bps $bps_
139 }
140 
141 
142 RvcAgent instproc trigger_fir {} {
143     $self instvar pipeline_
144     $pipeline_ send_full_intra_frame
145 }
146 
147 
148 RvcAgent instproc destroy {} {
149     $self instvar decoder_
150     $self instvar pipeline_
151 
152     delete $decoder_ 
153 
154     $pipeline_ release_device
155     delete $pipeline_ 
156 }
157 
158 RvcAgent instproc current_inport_list {} {
159 
160     return [[$self current_device] get_attribute port]
161 }
162 
163 RvcAgent instproc current_fps {} {
164     $self instvar fps_
165     return $fps_
166 }
167 
168 RvcAgent instproc current_bps {} {
169     $self instvar bps_
170     return $bps_
171 }
172 
173 RvcAgent instproc current_device {} {
174     $self instvar device_
175     return $device_
176 }
177 
178 RvcAgent instproc current_fmt {} {
179     $self instvar device_ devfmt_
180     return $devfmt_($device_)
181 }
182 
183 RvcAgent instproc current_inport {} {
184     $self instvar device_ devport_
185     return $devport_($device_)
186 }
187 
188 RvcAgent instproc select_initial_device {} {
189     $self instvar pipeline_ device_ devfmt_
190     set L [$pipeline_ input_devices]
191     set d [$self get_option defaultDevice]
192 
193     foreach v $L {
194         if { [$v nickname] == "$d" && \
195                 [$v attributes] != "disabled" } {
196             $self set_device $v
197             return
198         }
199     }
200 
201     #
202     # Otherwise select the first available one.
203     #
204     set device [lindex $L 0]
205     $self set_device $device
206 }
207 
208 RvcAgent instproc set_fps fps {
209     $self instvar pipeline_ fps_
210 
211     set fps_ $fps
212     return [$pipeline_ set_fps $fps_]
213 }
214 
215 RvcAgent instproc set_bps bps {
216     $self instvar pipeline_ bps_
217 
218     $self local_bandwidth $bps
219 
220     set bps_ $bps
221     $pipeline_ set_bps $bps_
222 
223     return [$pipeline_ set_bps $bps_]
224 }
225 
226 RvcAgent instproc set_fmt fmt {
227     $self instvar device_ devport_
228 
229     return [$self select_device $device_ $fmt $devport_($device_)]
230 }
231 
232 RvcAgent instproc get_device_by_name deviceName {
233     $self instvar pipeline_
234     foreach d [$pipeline_ input_devices] {
235         if {[$d nickname] == $deviceName} {
236             return $d
237         }
238     }
239     return ""
240 }
241 
242 RvcAgent instproc set_device device {
243     $self instvar devfmt_ devport_
244 
245     return [$self select_device $device $devfmt_($device) $devport_($device)]
246 }
247 
248 RvcAgent instproc set_inport inport {
249     $self instvar pipeline_ devport_ device_
250     set devport_($device_) $inport
251     $pipeline_ set_port $inport
252 }
253 
254 
255 RvcAgent instproc set_norm norm {
256     $self instvar pipeline_ device_ 
257     # $self instvar norm_
258     # set norm_ $norm
259 
260     #
261     # if the input $norm is supported by the current device, set it.
262     # otherwise, warn and ignore the input. 
263     #
264     if {[lsearch -exact [$device_ get_attribute norm] $norm] >= 0} {
265         $pipeline_ set_norm $norm
266     } else {
267         puts "WARNING: unsupported NORM $norm.  Supported values are [$device_ get_attribute norm]"
268     }
269 }
270 
271 
272 RvcAgent instproc select_device {device fmt port} {
273     $self instvar device_ pipeline_ devfmt_ devport_
274 
275     set running [$self running]
276  
277     #
278     # If nothing changes, just return.  (This could happen 
279     # at the beginning when RvcAgent is created.)
280     #
281     if {$device_ == $device && $devfmt_($device_) == $fmt &&
282         $devport_($device_) == $port} {
283         return
284         }
285 
286     # Set new state.
287     set device_ $device
288     set devfmt_($device) $fmt
289     set devport_($device) $port
290 
291     $pipeline_ release_device
292     $pipeline_ select $device_ $devfmt_($device)
293 
294     $self instvar qval_
295 
296     if [info exists qval_($fmt)] {
297         $self set_quality $qval_($fmt)
298     }
299 
300     # Norm of devices gets reset everytime a device is release.  
301     # If set_norm have been called on a device before, call it 
302     # again (possibly on a different device).
303     #if [info exists norm_] {
304     #   $self set_norm $norm_
305     #}
306 
307     $pipeline_ set_port $port
308 
309     if $running {
310         $self start
311     } 
312 }
313 
314 RvcAgent instproc set_quality q {
315     $self instvar qval_ device_ devfmt_
316 
317     if [info exists qval_($devfmt_($device_))] {
318         set qval_($devfmt_($device_)) $q
319 
320         $self instvar pipeline_
321         $pipeline_ set_quality $qval_($devfmt_($device_))
322     }
323 }
324 
325 RvcAgent instproc current_quality {} {
326     $self instvar qval_ device_ devfmt_
327 
328     if [info exists qval_($devfmt_($device_))] {
329         return $qval_($devfmt_($device_))
330     }
331     return 0
332 }
333 
334 RvcAgent instproc input_devices {} {
335     $self instvar pipeline_
336 
337     return [$pipeline_ input_devices]
338 }
339 
340 RvcAgent instproc start {} {
341 #    puts "rvc agent start got here"
342 
343     $self instvar pipeline_
344 
345     # turn off loopback.
346     $self app_loopback 0
347 
348     # We might still need to loopback to the network, in case 
349     # we are running a receiver at the same host.  However, this
350     # is turned off by default.
351     set options [$self options]
352     $self net_loopback [$options get_option loopback]
353 
354     return [$pipeline_ start]
355 }
356 
357 RvcAgent instproc stop {} {
358     $self instvar pipeline_
359 
360     return [$pipeline_ stop]
361 }
362 
363 RvcAgent instproc running {} {
364     $self instvar pipeline_
365 
366     return [$pipeline_ running]
367 }
368 
369 #
370 # Don't create real decoders, since we don't care
371 # about other sources!
372 #
373 RvcAgent instproc create_decoder src {
374 
375     $self instvar decoder_
376 
377     #puts "create_decoder called on $src"
378     #puts "create_decoder called on [$src srcid]"
379 
380     # decoder_ is a Null VideoDecoder.
381     return $decoder_
382 }
383 
384 

~ [ 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.