[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: some questions



Hi -

The Tcl script was an example, you don't have to do anything with this
code, per se. I would look into Module/Framer/MPG and see where it calls
the method to actually transmit the data over the network.  Rather than
send the data, you can put the buffer/packet on a queue.  You can
implement the queue in C++ if you want.  So, your code puts
buffers/packets on the queue at a particular rate -
you should compute this given the bitrate of the data stream.  

Now, you need a separate method/function analogous to dosend. This
method might be written in Otcl.  Let's call the routine paced_send. 
This routine takes a packet off the queue and sends it, assuming a
packet exists, and then puts a callback to itself on the "after" event
queue.  Again, the time period and possibly the number of packets to
send each time period should be computed from the bitrate of the data
stream.

Your application will start the process by putting a paced_send on the
"after" event queue and starting the grabbing process.

You're right that you can call the Tcl code from C++ using evalf.  You
can also call the C++ code from Tcl - you probably want to call a
routine to remove an item from the queue which is written in C++ from
Otcl.  The C++ routine will have to return a Tcl value which could just
be the object reference (i.e., a string of the form o_NNN) for the
packet/buffer that should be passed to the transmission/send network
abstraction.

Eric Machinick knows how to call between C++ and Tcl and vice-versa, so
he or Tim can help you with this part of the code.

Do you understand?  When are you going to work on this -- next week,
maybe late monday or tuesday?  Let us know and Tim and I will try to
help you.
	Larry

Peter Chang wrote:
> 
> Hi larry,
>         I under the code that you've written (since I'm somewhat familiar with
> tcl) but I'm kinda confused on how I integrate this into my code.  So right
> now I have VideoCapture/File/MPG object calling a function Grab (in C++).
> This basically grabs data from the encoding hardware and then called
> target_->recv() notifying the Module/Framer/MPG that it is sending it some
> data.  That's how things are now.
>         I guess my first question is about "q".  So am I actually maintaining data
> withint tcl??  Is it actually keeping track of the actual memory I'm storing?
>         Given this written code I was thinking about this:  so I'm supposed to
> call loadq from grab() (where I currently call target_->recv()).  Then I
> can pass loadq (provided I make a simple change of loadq taking a
> parameter) the a piece of the buffer I just got from the hardware.  Loadq
> will then somehow take this data and put it into q.  Before all this I
> would make a call to dosend which will basically try to deque every x
> milliseconds.  Assuming all that:
>         1)  do you konw how to call tcl commands within grab() (c++)??  I'm not
> really too familar on the tclcl stuff although I have a hunch it has
> something to do wtih Tcl_Eval or tcl.evalf..or actually i think I can find
> out a way to manipulate tcl variables in C.  So is this what I'm supposed
> to do?  basically call loadq instead of directly calling recv in
> Module/Framer/MPG (which directly tries to send it through the net)?
>         2)  in deque it appears that i have to actually SEND the packet.  So does
> this mean I should write a send() function that is call in the tcl script?
> So right now grab() immediately calls target_->recv() which is really part
> of the Module/Framer/MPG class.  so should i just call recv from within the
> tcl script (in deque)?
> 
>         Given my (this) understanding of how to use this I wonder if I would have
> to make small changes to loadq.  One I don't really udnerstand  your
> foreach command in it but I suppose that was for testing.  Also given that
> I call it continuously in grab I should remove the "after 10000 loadq" line
> correct?
> 
>         Please make any comments you feel like making..thanks.
> 
> -Peter
> 
> ># Leaky bucket simulation
> ># Code to demonstrate paced sending of packets
> >
> ># We keep a queue, tcl array "q", with two pointers:
> >#      "enq" - index to next open slot to enter item
> >#      "deq" - index of next slot to dequeue item from
> ># if $enq==$deq, the queue is empty.  A full queue has
> ># ($enq+1)==$deq.  The queue size is specified by QSIZE
> >#
> ># The queue abstraction is implemented by the functions:
> >#      isfull - is the queue full?
> >#      advance - move the queue index mod the size of the queue
> >#      enq(msg) - add $msg to the queue
> >#      deq - removes the first item in the queue and returns it
> >
> ># The paced transmission is implemented by the two functions
> >#      loadq - add N items to the queue
> >#      dosend - callback function that sends one message from the queue
> ># Notice that the queue is loaded every 10 seconds with 8 items
> ># that are then sent at 1 second intervals.
> >
> >set QSIZE 10
> >set enq 0
> >set deq 0
> >set lenq 0
> >
> >proc isfull {} {
> >  global enq deq lenq
> >  set lenq [advance $enq]
> >  if {$lenq==$deq} {
> >    return 1
> >  }
> >  return 0
> >}
> >
> >proc advance {x} {
> >  global QSIZE
> >  incr x
> >  if {$x==$QSIZE} {
> >    set x 0
> >  }
> >  return $x
> >}
> >
> >proc enque {msg} {
> >  global enq q
> >  if {[isfull]} {
> >    puts stdout "DROP: $msg"
> >    return
> >  }
> >  set q($enq) $msg
> >  set enq [advance $enq]
> >}
> >
> >proc deque {} {
> >  global q enq deq
> >  if {$enq==$deq} {
> >    puts stdout "UNDERFLOW"
> >    return
> >  }
> >  puts -nonewline stdout "SEND: "
> >  puts -nonewline stdout [clock format [clock seconds] -format "%T"]
> >  puts stdout "$q($deq)"
> >  set deq [advance $deq]
> >}
> >
> >proc loadq {} {
> >  foreach i {1 2 3 4 5 6 7 8} {
> >    enque $i
> >  }
> >  after 10000 loadq
> >}
> >
> >proc dosend {} {
> >  deque
> >  after 1000 dosend
> >}

-- 
Professor Lawrence A. Rowe          Internet:  Rowe@BMRC.Berkeley.EDU
Computer Science Division - EECS       Phone: 510-642-5117
University of California, Berkeley       Fax: 510-642-5615
Berkeley, CA 94720-1776            URL: http://bmrc.berkeley.edu/~larry