blob: 92997678366ac9f55704d3489c30cda3b8f591a7 [file] [log] [blame]
Holger Hans Peter Freyther3fab3fd2012-05-18 18:54:11 +02001"
2Simple UDP replay from the state files
3"
4
5PackageLoader fileInPackage: #Sockets.
6
7Eval [
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]