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

Open Mash Cross Reference
mash/tcl/net/agent-rtp-simple.tcl

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

  1 # agent-rtp-simple.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  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 RTPAgent
 32 
 33 # We inherit from RTPAgent so that when a new source is discovered, the
 34 #   activate call does the right stuff
 35 #
 36 # The idea is that we can create a simple RTP agent that can get audio or
 37 #   video packets, and we can give it the Tcl/C++ split objects to attach to
 38 #   that will be passed the RTP and RTCP packets
 39 #
 40 # This makes it easy to grab all the data or rtcp packets from a specified
 41 #   multicast address and have them sent to your handlers
 42 #
 43 # I wasn't able to find a class that already existed that allows this, though
 44 #   you'd think there would be....
 45 #
 46 # A simple use is:
 47 #
 48 #    set dHandler [new Module/DXXX]
 49 #    set cHandler [new Module/CXXX]
 50 #    set agent [new RTPSimpleAgent audio 233.1.1.1/9000 $dHandler $cHandler]
 51 #
 52 #    DXXX and CXXX are split objects that are derived from a PacketModule, such
 53 #       as Module/VideoDecoder/Null
 54 #
 55 #    DXXX must call pb->release() on the packet in it's recv() call (or an
 56 #       object that is passed the packet must call it)
 57 #
 58 #    This will set up an agent that looks for RTP packets on the 233.1.1.1/9000
 59 #       multicast address and when it receives data packets, will call the
 60 #       dHandler's recv() function.  RTCP packets received will be passed on
 61 #       to the cHandler through its recv() function.
 62 #
 63 #
 64 Class RTPSimpleAgent -superclass RTPAgent
 65 
 66 
 67 # type = "audio" or "video"
 68 # addr = addr/port string
 69 #
 70 # We don't really need to differentiate the type of session;
 71 #   the audio, video, etc sessions don't filter out other types of packets
 72 #
 73 # Apparently, the Session/RTP is a virtual class that should not be directly
 74 #   instantiated; not sure why, since the AudioSession class is just the
 75 #   RtpSession class.  As a result, we pass in the type to the constructor
 76 RTPSimpleAgent instproc init { type addr dataHandler controlHandler} {
 77     $self instvar dataHandler_ controlHandler_ type_
 78 
 79     set type_ $type
 80     if {$type_ != "audio" && $type_ != "video"} {
 81         puts stderr "RTPSimpleAgent::create_session: warning, invalid type \"$type_\" specified, defaulting to audio; valid values are \[audio, video\]"
 82         set type_ "audio"
 83     }
 84 
 85     set dataHandler_ $dataHandler
 86     set controlHandler_ $controlHandler
 87 
 88 #    puts stdout "RTPSimpleAgent::init: addr=$addr"
 89 
 90     set ab [new AddressBlock $addr]
 91     eval $self next $ab
 92 }
 93 
 94 RTPSimpleAgent instproc destroy {} {
 95         $self next
 96 }
 97 
 98 RTPSimpleAgent instproc create_session {} {
 99     $self instvar type_
100 #    puts stdout "RTPSimpleAgent::create_session: called"
101 
102     switch -exact -- $type_ {
103         audio {
104             set session [new Session/RTP/Audio]
105         }
106         video {
107             set session [new Session/RTP/Video]
108         }
109         default {
110             set session [new Session/RTP/Audio]
111         }
112     }
113 
114     return $session
115 }
116 
117 
118 
119 # Override RTP agent's default method.
120 # Called from C++ (through Source/RTP) when we start
121 # actively receiving data pkts from the given source.
122 
123 RTPSimpleAgent instproc activate src {
124     $self instvar dataHandler_ controlHandler_
125 
126 #    puts stdout "RTPSimpleAgent::activate [$src getid]"
127 #    puts stdout [format "%s %x" "src is $src; ssrc=0x" [$src ssrc]]
128 #    puts stdout "addr is [$src addr]"
129 
130     if {$dataHandler_ != ""} {
131         $src data-handler $dataHandler_
132     } else {
133         # this works for audio too, because it just releases the packet
134         $src data-handler [new Module/VideoDecoder/Null]
135         # there needs to be a data handler attached, to call release on the
136         #   packets, also, the source expects there to be one attached, or it
137         #   will seg fault!
138     }
139 
140     if {$controlHandler_ != ""} {
141         $src ctrl-handler $controlHandler_
142     }
143 
144     $self next $src
145 }
146 
147 RTPSimpleAgent instproc deactivate src {
148     #puts "RTPSimpleAgent deactivate"
149     $self next $src
150 }
151 
152 

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