summaryrefslogtreecommitdiffstats
path: root/openbsc/contrib/rtp/rtp_replay.st
blob: 7e73e93a3aab7c95aa8cb94fd01a30d7856d756a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"
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.
                ]
        ]
    ]
]

Eval [
    | replay |

    replay := RTPReplay on: 'rtp_ssrc6976010.240.240.1_to_10.240.240.50.state'.

    Transcript nextPutAll: 'Going to stream now'; nl.
    replay streamAudio: '127.0.0.1' port: 4000.
]