Holger Hans Peter Freyther | 3fab3fd | 2012-05-18 18:54:11 +0200 | [diff] [blame^] | 1 | " |
| 2 | Simple UDP replay from the state files |
| 3 | " |
| 4 | |
| 5 | PackageLoader fileInPackage: #Sockets. |
| 6 | |
| 7 | Eval [ |
| 8 | | last_time last_image udp_send socket dest | |
| 9 | |
| 10 | last_time := nil. |
| 11 | last_image := nil. |
| 12 | file := FileStream open: 'rtp_ssrc13529910.240.240.1_to_10.240.240.50.state'. |
| 13 | |
| 14 | "Send the payload" |
| 15 | dest := Sockets.SocketAddress byName: '127.0.0.1'. |
| 16 | socket := Sockets.DatagramSocket new. |
| 17 | udp_send := [:payload | | datagram | |
| 18 | datagram := Sockets.Datagram data: payload contents address: dest port: 4000. |
| 19 | socket nextPut: datagram |
| 20 | ]. |
| 21 | |
| 22 | [file atEnd] whileFalse: [ |
| 23 | | lineStream time data now_image | |
| 24 | lineStream := file nextLine readStream. |
| 25 | |
| 26 | "Read the time, skip the blank, parse the data" |
| 27 | time := Number readFrom: lineStream. |
| 28 | lineStream skip: 1. |
| 29 | |
| 30 | data := WriteStream on: (ByteArray new: 30). |
| 31 | [lineStream atEnd] whileFalse: [ |
| 32 | | hex | |
| 33 | hex := lineStream next: 2. |
| 34 | data nextPut: (Number readFrom: hex readStream radix: 16). |
| 35 | ]. |
| 36 | |
| 37 | last_time isNil |
| 38 | ifTrue: [ |
| 39 | "First time, send it right now" |
| 40 | last_time := time. |
| 41 | last_image := Time millisecondClockValue. |
| 42 | udp_send value: data. |
| 43 | ] |
| 44 | ifFalse: [ |
| 45 | | wait_image new_image_time | |
| 46 | |
| 47 | "How long to wait?" |
| 48 | wait_image := last_image + ((time - last_time) * 1000). |
| 49 | [ wait_image > Time millisecondClockValue ] whileTrue: []. |
| 50 | |
| 51 | udp_send value: data. |
| 52 | last_time := time. |
| 53 | last_image := wait_image. |
| 54 | ] |
| 55 | ]. |
| 56 | ] |