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

Open Mash Cross Reference
mash/tcl/net/rtp.tcl

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

  1 # rtp.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  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/net/rtp.tcl,v 1.22 2004/05/27 00:13:54 larry Exp $
 32 
 33 
 34 #
 35 # A simple OTcl class that provides helper methods for
 36 # various RTP utility operations.
 37 #
 38 Class RTP
 39 
 40 #
 41 # A variant of the RTP helper class for video.  Because
 42 # the payload type spaces for audio and video can overlap,
 43 # we need to specialize this class.  (Note however that while
 44 # no such overlap currently exists, this probably won't hold
 45 # in the future as the static payload types get used up.)
 46 #
 47 Class RTP/Video -superclass RTP
 48 
 49 #
 50 # A variant of the RTP helper class for audio.  Because
 51 # the payload type spaces for audio and video can overlap,
 52 # we need to specialize this class.  (Note however that while
 53 # no such overlap currently exists, this probably won't hold
 54 # in the future as the static payload types get used up.)
 55 #
 56 Class RTP/Audio -superclass RTP
 57 
 58 RTP private init {} {
 59         eval $self next
 60         $self instvar rtp_ptoa_
 61         set rtp_ptoa_(-1) ""
 62 }
 63 
 64 RTP/Audio set default_ptoa_(0) pcm
 65 RTP/Audio set default_ptoa_(1) celp
 66 RTP/Audio set default_ptoa_(2) g721
 67 RTP/Audio set default_ptoa_(3) gsm
 68 RTP/Audio set default_ptoa_(5) dvi
 69 RTP/Audio set default_ptoa_(6) dvi
 70 RTP/Audio set default_ptoa_(7) lpc
 71 RTP/Audio set default_ptoa_(8) pcma
 72 RTP/Audio set default_ptoa_(9) g722
 73 RTP/Audio set default_ptoa_(10) lin16
 74 RTP/Audio set default_ptoa_(11) lin16
 75 RTP/Audio set default_ptoa_(14) mpa
 76 RTP/Audio set default_ptoa_(15) g728
 77 
 78 RTP/Video set default_ptoa_(21) pvh
 79 RTP/Video set default_ptoa_(25) cellb
 80 RTP/Video set default_ptoa_(26) jpeg
 81 RTP/Video set default_ptoa_(27) cuseeme
 82 RTP/Video set default_ptoa_(28) nv
 83 RTP/Video set default_ptoa_(29) picw
 84 RTP/Video set default_ptoa_(30) cpv
 85 RTP/Video set default_ptoa_(31) h261
 86 RTP/Video set default_ptoa_(32) mpeg
 87 RTP/Video set default_ptoa_(33) mpegs
 88 RTP/Video set default_ptoa_(42) h263+
 89 RTP/Video set default_ptoa_(34) h263
 90 RTP/Video set default_ptoa_(35) mpeg4
 91 
 92 RTP/Audio set default_ptoa_(126) mp3
 93 
 94 #FIXME
 95 RTP/Video set default_ptoa_(127) h261v1
 96 
 97 #FIXME - The following is needed for psvp support. Should find some
 98 #      way of doing this without coding it here.
 99 RTP/Video set default_ptoa_(50) sc
100 
101 RTP/Audio public init args {
102         $self next
103         #
104         # Fill in the arrays that translates between RTP payload type
105         # numbers and representative strings.  ``ptoa'' stands for
106         # payload-type to ascii while ``atop'' stands for the converse.
107         # We do this setup in th eaudio subclass rather than in the
108         # RTP base class because the spec allows the audio and video
109         # payload type numbers to overlap.  (Note that the current spec
110         # does not include any such overlapping assignments because the
111         # allocation is still sparse.)
112         #
113         $class instvar default_ptoa_
114         $self instvar rtp_ptoa_ rtp_atop_
115         foreach p [array names default_ptoa_] {
116                 $self add_mapping $p $default_ptoa_($p)
117         }
118 
119         #FIXME this is done here rather than in the base class (RTP)
120         # since we want it to happen after defaults are set
121         foreach mapping [$self get_option rtpMap] {
122                 set l [split $mapping :]
123                 set pt [lindex $l 0]
124                 set fmt [lindex $l 1]
125                 $self add_mapping $pt $fmt
126         }
127 }
128 
129 RTP/Video public init args {
130         $self next
131         #
132         # Fill in the arrays that translates between RTP payload type
133         # numbers and representative strings.  ``ptoa'' stands for
134         # payload-type to ascii while ``atop'' stands for the converse.
135         # We do this setup in th eaudio subclass rather than in the
136         # RTP base class because the spec allows the audio and video
137         # payload type numbers to overlap.  (Note that the current spec
138         # does not include any such overlapping assignments because the
139         # allocation is still sparse.)
140         #
141         $class instvar default_ptoa_
142         $self instvar rtp_ptoa_ rtp_atop_
143         set rtp_ptoa_(-1) ""
144         foreach p [array names default_ptoa_] {
145                 set rtp_ptoa_($p) $default_ptoa_($p)
146                 set rtp_atop_($default_ptoa_($p)) $p
147         }
148 
149         #FIXME this is done here rather than in the base class (RTP)
150         # since we want it to happen after defaults are set
151         foreach mapping [$self get_option rtpMap] {
152                 set l [split $mapping :]
153                 set pt [lindex $l 0]
154                 set fmt [lindex $l 1]
155                 $self add_mapping $pt $fmt
156         }
157 
158         #
159         # Set up a table to map lower-case RTP format
160         # names into the suffix of the class name
161         # that encodes or decodes this type
162         #
163         $self instvar classmap_
164         set classmap_(pvh) PVH
165         set classmap_(h261) H261
166         set classmap_(h261v1) H261v1
167         set classmap_(nv) NV
168         set classmap_(cellb) CellB
169         set classmap_(jpeg) JPEG
170         set classmap_(mpeg4) MPEG4
171     set classmap_(h263+) H263+
172     set classmap_(h263) H263
173 
174         # Experimental stuff for psvp
175 
176         set classmap_(sc) SC
177 }
178 
179 #
180 # Return the suffix of the OTcl class name that
181 # supports the indicated RTP <i>format</i>.
182 # Assumes <i>format</i> is a well-known type.
183 #
184 RTP/Video public classmap type {
185         $self instvar classmap_
186         if [info exists classmap_($type)] {
187                 return $classmap_($type)
188         }
189         return "Null"
190 }
191 
192 #
193 # Add a mapping from RTP payload type <i>pt</i> to the
194 # format <i>fmt</i>.  The association becomes visible in
195 # subsequent calls to the <i>rtp_type</i> and
196 # <i>rtp_fmt_number</i> methods.
197 #
198 RTP public add_mapping {pt fmt} {
199         $self instvar rtp_ptoa_ rtp_atop_
200         set rtp_ptoa_($pt) $fmt
201         set rtp_atop_($fmt) $pt
202 }
203 
204 #
205 # Return the format name that corresponds to the RTP payload
206 # format type number given by <i>pt</i>.
207 #
208 RTP public rtp_type pt {
209         $self instvar rtp_ptoa_
210         if [info exists rtp_ptoa_($pt)] {
211                 return $rtp_ptoa_($pt)
212         } elseif { $pt < 0 }  {
213                 return ""
214         } else {
215                 return fmt-$pt
216         }
217 }
218 
219 #
220 # Return the RTP payload type number of the RTP format name
221 # given by <i>fmt</i>.
222 #
223 RTP public rtp_fmt_number fmt {
224         $self instvar rtp_atop_
225         if [info exists rtp_atop_($fmt)] {
226                 return $rtp_atop_($fmt)
227         } else {
228                 return -1
229         }
230 }
231 
232 #
233 # Return the RTP format name in current use by the
234 # RTP source object <i>src</i>.
235 #
236 RTP public rtp_format src {
237         $self instvar rtp_ptoa_
238         return [$self rtp_type [$src format]]
239 }
240 
241 #
242 # Return true if the two strings provide more or less the
243 # same informational content
244 #
245 RTP instproc cname_redundant { name cname } {
246         set ni [string first @ $name]
247         if { $ni < 0 } {
248                 return 0
249         }
250         set ci [string first @ $cname]
251         if { $ci < 0 } {
252                 return 0
253         }
254         if { [string compare \
255                 [string range $name 0 $ni] \
256                 [string range $cname 0 $ci]] == 0 } {
257                 return 1
258         }
259         return 0
260 }
261 
262 #
263 # Return a good string indentifier for the RTP source
264 # object <i>src</i>.  Tries to use the most descriptive
265 # RTCP SDES information first (e.g., name before cname
266 # before raw ip address).
267 #
268 RTP public rtp_representation src {
269         set fmt [$self rtp_format $src]
270         set name [$src sdes name]
271         set cname [$src sdes cname]
272         set addr [$src addr]
273         if { $name == "" } {
274                 if { $cname == "" } {
275                         set srcname $addr
276                         set srcinfo $addr/$fmt
277                 } else {
278                         set srcname $cname
279                         set srcinfo $addr/$fmt
280                 }
281         } elseif [$self cname_redundant $name $cname] {
282                 set srcname $name
283                 set srcinfo $addr/$fmt
284         } else {
285                 set srcname $name
286                 set srcinfo $cname/$fmt
287         }
288 
289         return "{$srcname} {$srcinfo}"
290 }
291 

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