1 # agent-video-psvp.tcl --
2 #
3 # This file contains the Video agent used by many psvp mechanisms.
4 #
5 # Copyright (c) 1998-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
33 Class PsvpVideoAgent -superclass VideoAgent
34
35 PsvpVideoAgent instproc init {spec} {
36 eval $self next $self $spec;
37 set local_src [$self local];
38 if {$local_src != ""} {
39 $local_src handler [new Module/VideoDecoder/Null];
40 }
41 }
42
43 PsvpVideoAgent instproc get_source_by_id srcid {
44 $self instvar sources_;
45
46 if {$srcid == "*"} {
47 foreach s $sources_ {
48 if {$s != [$self local]} {
49 set d [$s handler];
50 if {$d != ""} {
51 if {[$d info class] == "Module/VideoDecoder/Null"} {
52 return $s;
53 }
54 }
55 }
56 }
57 } else {
58 foreach s $sources_ {
59 if {$srcid == [$s srcid]} {
60 return $s;
61 }
62 }
63 }
64 return "";
65 }
66
67 PsvpVideoAgent instproc delete_decoder decoder {
68 $self instvar decoders_;
69
70 set idx [lsearch $decoders_ $decoder];
71 if {$idx == -1} {
72 return;
73 }
74
75 set src [$decoder set src_];
76
77 lreplace $decoders_ $idx $idx "";
78
79 set null_decoder [$self create_decoder $src];
80
81 $src handler $null_decoder;
82 lappend decoders_ $null_decoder;
83 }
84
85 PsvpVideoAgent instproc set_create_decoder_callback {srcid cmd} {
86 $self instvar callbacks_;
87
88 set callbacks_($srcid) $cmd;
89 }
90
91 PsvpVideoAgent instproc set_src_decoder {src decoder} {
92 $self instvar decoders_ sources_;
93
94 if {[lsearch $sources_ $src] == -1} {
95 return;
96 }
97
98 $decoder set agent_ $self;
99 $decoder set src_ $src;
100
101 set old_decoder [$src handler];
102
103 if {$old_decoder != ""} {
104 delete $old_decoder;
105 set idx [lsearch $decoders_ $old_decoder];
106 if {$idx != -1} {
107 set decoders_ [lreplace $decoders_ $idx $idx];
108 }
109 }
110
111 $src handler $decoder;
112
113 lappend decoders_ $decoder;
114
115 }
116
117 PsvpVideoAgent instproc create_decoder src {
118 $self instvar callbacks_;
119 set d [$src handler];
120 if {$d != ""} {
121 delete $d
122 }
123
124 set id [$src srcid];
125
126 if {![info exists callbacks_($id)]} {
127 if {[info exists callbacks_(*)]} {
128 set decoder [eval $callbacks_(*) $src];
129 unset callbacks_(*);
130 } else {
131 set decoder [new Module/VideoDecoder/Null];
132 }
133 } else {
134 set decoder [eval $callbacks_($id) $src];
135 unset callbacks_($id);
136 }
137
138 $decoder set agent_ $self;
139 $decoder set src_ $src;
140
141 return $decoder;
142 }
143
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.