1 # ive-video-agent.tcl --
2 #
3 # Video agent for indiva video encoder.
4 #
5 # Copyright (c) 1996-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 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/indiva/services/ive/ive-video-agent.tcl,v 1.5 2004/02/16 18:23:45 weitsang Exp $
32 #
33 import VideoAgent
34 import VideoPipeline
35 Class IVEVideoAgent -superclass VideoAgent
36
37 IVEVideoAgent instproc init { app spec dev port fmt } {
38 puts "$dev $port $fmt"
39 $self next $app $spec
40
41 $self instvar pipeline_
42 set pipeline_ [new VideoPipeline $self]
43
44 set device_list [$pipeline_ input_devices]
45 # if $dev is empty, use first available device.
46 if {$dev == ""} {
47 set device [lindex $device_list 0]
48 }
49 set device ""
50 foreach d $device_list {
51 if {[$d pathname] == $dev} {
52 set device $d
53 }
54 }
55 if {$device == ""} {
56 puts "Cannot open device $device. Good bye."
57 exit
58 }
59
60 set port_list [$device get_attribute port]
61 if {$port == ""} {
62 set port [lindex $port_list 0]
63 }
64 if {[lsearch $port_list $port] == -1} {
65 puts "Cannot open port $port on [$device nickname]([$device pathname]). Good bye."
66 exit
67 }
68
69 # $self app_loopback 0
70 # $self net_loopback 0
71
72 $pipeline_ release_device
73 $pipeline_ set_port $port
74 $pipeline_ select $device $fmt
75 }
76
77 IVEVideoAgent instproc create_decoder { src } {
78 # FIXME : someone might deleted this decoder?
79 # $self instvar decoder_
80 #if ![info exists decoder_] {
81 # set decoder_ [new Module/VideoDecoder/Null]
82 # }
83 return [new Module/VideoDecoder/Null]
84 # return $decoder_
85 }
86
87 IVEVideoAgent instproc pipeline { } {
88 $self instvar pipeline_
89 return $pipeline_
90 }
91
92 IVEVideoAgent instproc start { } {
93 $self instvar pipeline_
94 $pipeline_ start
95
96 }
97
98 IVEVideoAgent instproc set_fps { fps } {
99 $self instvar pipeline_
100 $pipeline_ set_fps $fps
101 }
102
103 IVEVideoAgent instproc set_bps { bps } {
104 $self instvar pipeline_
105 $pipeline_ set_bps $bps
106 }
107
108 IVEVideoAgent instproc set_quality { q } {
109 $self instvar pipeline_
110 $pipeline_ set_quality $q
111 }
112
113 IVEVideoAgent instproc set_fmt { fmt } {
114 $self instvar pipeline_ titler_
115 $pipeline_ set_fmt $fmt
116
117 # If titling is on, need to retarget titler
118 if [info exists titler_] {
119 $self title on
120 }
121 }
122
123
124 IVEVideoAgent instproc add_destination { dest } {
125 $self instvar pipeline_ sessions_ netmgr_
126 set encoder [$pipeline_ set encoder_]
127 set sessions_($dest) [$self create_session]
128 $sessions_($dest) sm $self
129 set ab [new AddressBlock $dest]
130 set netmgr_($dest) [new NetworkManager $ab $sessions_($dest) $self]
131 $encoder add_target $sessions_($dest)
132 $self app_loopback 0
133 delete $ab
134 }
135
136
137 IVEVideoAgent instproc delete_destination { dest } {
138 $self instvar netmgr_ sessions_ pipeline_
139 set encoder [$pipeline_ set encoder_]
140 $encoder del_target $sessions_($dest)
141 delete $sessions_($dest)
142 delete $netmgr_($dest)
143 }
144
145
146 IVEVideoAgent instproc title {option args} {
147 $self instvar pipeline_ titler_ title_
148 switch $option {
149 "on" {
150 if {[catch {$pipeline_ set encoder_} encoder]} {
151 return
152 }
153 set csss [$encoder frame-format]
154 set titler_ [new Module/VideoEffect/Titling $csss]
155 if {[info exists title_]} {
156 $titler_ set-title $title_ 24 Arial
157 }
158 $titler_ target $encoder
159 [$pipeline_ set tap_] target $titler_ $encoder
160 }
161 "off" {
162 if ![info exists titler_] {
163 # Not on in the first place!
164 return
165 }
166 if {[catch {$pipeline_ set encoder_} encoder]} {
167 return
168 }
169 [$pipeline_ set tap_] target $encoder $encoder
170 delete $titler_
171 unset titler_
172 }
173 "set" {
174 set length [llength $args]
175 set title_ [lrange $args 0 [expr {$length-3}]]
176 set size [lindex $args [expr {$length-2}]]
177 set name [lindex $args [expr {$length-1}]]
178 if [info exists titler_] {
179 if {$title_ == ""} {
180 $self title off
181 } else {
182 $titler_ set-title $title_ $size $name
183 }
184 } else {
185 $self title on
186 }
187 }
188 }
189 }
190
191 IVEVideoAgent instproc reset_spec { dest } {
192 $self instvar pipeline_
193 puts "reset $dest"
194 $self next $dest
195 if [info exists pipeline_] {
196 $pipeline_ switch_session $self
197 }
198 }
199
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.