blob: cfb66bb4da09123fca456ac23c9bc708d52e661b [file] [log] [blame]
Holger Hans Peter Freyther602559f2012-08-05 09:27:20 +02001"
2Simple UDP replay from the state files
3"
4
5PackageLoader fileInPackage: #Sockets.
6
7Object subclass: RTPReplay [
8 | filename |
9 RTPReplay class >> on: aFile [
10 ^ self new
11 file: aFile; yourself
12 ]
13
14 file: aFile [
15 filename := aFile
16 ]
17
18 streamAudio: aHost port: aPort [
19 | file last_time last_image udp_send socket dest |
20
21 last_time := nil.
22 last_image := nil.
23 file := FileStream open: filename.
24
25 "Send the payload"
26 dest := Sockets.SocketAddress byName: aHost.
27 socket := Sockets.DatagramSocket new.
28 udp_send := [:payload | | datagram |
29 datagram := Sockets.Datagram data: payload contents address: dest port: aPort.
30 socket nextPut: datagram
31 ].
32
33 [file atEnd] whileFalse: [
34 | lineStream time data now_image |
35 lineStream := file nextLine readStream.
36
37 "Read the time, skip the blank, parse the data"
38 time := Number readFrom: lineStream.
39 lineStream skip: 1.
40
41 data := WriteStream on: (ByteArray new: 30).
42 [lineStream atEnd] whileFalse: [
43 | hex |
44 hex := lineStream next: 2.
45 data nextPut: (Number readFrom: hex readStream radix: 16).
46 ].
47
48 last_time isNil
49 ifTrue: [
50 "First time, send it right now"
51 last_time := time.
52 last_image := Time millisecondClockValue.
53 udp_send value: data.
54 ]
55 ifFalse: [
56 | wait_image new_image_time |
57
58 "How long to wait?"
59 wait_image := last_image + ((time - last_time) * 1000).
60 [ wait_image > Time millisecondClockValue ] whileTrue: [].
61
62 udp_send value: data.
63 last_time := time.
64 last_image := wait_image.
65 ]
66 ]
67 ]
68]
69