Comcast / gots

MPEG Transport Stream handling in Go
Other
308 stars 88 forks source link

Continuously read packets from multicast udp stream and extract data #153

Closed maximk-1 closed 3 years ago

maximk-1 commented 3 years ago

Hi. Is it possible to continuously read packets from multicast udp stream and extract data, ex. for scte35 logging?

LimitlessEarth commented 3 years ago

Hello, Yes. Here is some pseudo code that shows roughly what you would do

pkt := &packet.Packet{}

accumulator := libpacket.NewAccumulator(scte35.SCTE35AccumulatorDoneFunc)

for {
    bytesRead, err = socket.Read(readBuf)
    if err != nil {
        return err
    }

    for pi = 0; pi < (bytesRead / packet.PacketSize); pi++ {
        copy(pkt[:], readBuf[pi*packet.PacketSize:(pi+1)*packet.PacketSize])

        _, err := accumulator.WritePacket(pkt)
        if err == gots.ErrAccumulatorDone {
            message, err := scte35.NewSCTE35(accumulator.Bytes())
            if err == nil {
                fmt.Println(message)
            }
            accumulator.Reset()
        }
    }
}

I would recommend more error checking but that the basics of it.

I'm going to close this because it is a question, not an issue.

LimitlessEarth commented 3 years ago

Other errors you could check are: