diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2012-08-05 09:27:20 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2012-08-05 09:27:20 +0200 |
commit | 602559fd9fa39015043ec6fa2a1f8d2c8e36d062 (patch) | |
tree | c37ceeeae88e9cf60eb19feafa07dc3b7a609fb7 /openbsc/contrib/rtp/rtp_replay_shared.st | |
parent | 4552d8061aced092ab2b2652b500b47b9e8516a6 (diff) |
contrib: Move the shared code into a new file
Diffstat (limited to 'openbsc/contrib/rtp/rtp_replay_shared.st')
-rw-r--r-- | openbsc/contrib/rtp/rtp_replay_shared.st | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/openbsc/contrib/rtp/rtp_replay_shared.st b/openbsc/contrib/rtp/rtp_replay_shared.st new file mode 100644 index 000000000..cfb66bb4d --- /dev/null +++ b/openbsc/contrib/rtp/rtp_replay_shared.st @@ -0,0 +1,69 @@ +" +Simple UDP replay from the state files +" + +PackageLoader fileInPackage: #Sockets. + +Object subclass: RTPReplay [ + | filename | + RTPReplay class >> on: aFile [ + ^ self new + file: aFile; yourself + ] + + file: aFile [ + filename := aFile + ] + + streamAudio: aHost port: aPort [ + | file last_time last_image udp_send socket dest | + + last_time := nil. + last_image := nil. + file := FileStream open: filename. + + "Send the payload" + dest := Sockets.SocketAddress byName: aHost. + socket := Sockets.DatagramSocket new. + udp_send := [:payload | | datagram | + datagram := Sockets.Datagram data: payload contents address: dest port: aPort. + socket nextPut: datagram + ]. + + [file atEnd] whileFalse: [ + | lineStream time data now_image | + lineStream := file nextLine readStream. + + "Read the time, skip the blank, parse the data" + time := Number readFrom: lineStream. + lineStream skip: 1. + + data := WriteStream on: (ByteArray new: 30). + [lineStream atEnd] whileFalse: [ + | hex | + hex := lineStream next: 2. + data nextPut: (Number readFrom: hex readStream radix: 16). + ]. + + last_time isNil + ifTrue: [ + "First time, send it right now" + last_time := time. + last_image := Time millisecondClockValue. + udp_send value: data. + ] + ifFalse: [ + | wait_image new_image_time | + + "How long to wait?" + wait_image := last_image + ((time - last_time) * 1000). + [ wait_image > Time millisecondClockValue ] whileTrue: []. + + udp_send value: data. + last_time := time. + last_image := wait_image. + ] + ] + ] +] + |