ziutek / dvb

DVB/MPEG-TS library (pure Go)
BSD 3-Clause "New" or "Revised" License
99 stars 17 forks source link

Another Example please. #15

Open TVforME opened 2 weeks ago

TVforME commented 2 weeks ago

Could we have another example for use of PAT and PMT Please?

I have a USB stick DVB-T tuner working and streaming to UDP using the example dvbdd/main.go

I've managed to list all programs using PMT.go (example attached) which lists the serviceID and PMT PID for that service. Now I need to use the PMT PID to list all the PID's associated with that service?

I boing a similar thing to pat.Update(d, true) using pmt.Update(d) however the for loop crashes and I get panic with panic: section length should be >= 8

I'm clueless how to return all the PID's for the service? (PCR_PID, VIDEO_PID and AUDIO_PID's)

Any working code would be great help from the dvb gurus..

In addition, when passing more than 2 Pids to setfilter() r, filter := setFilter(demuxPath, "", []int16{123, 124, 135}) anything after the second PID is ignored?

Is this a bug?

Below is what I have so far and returns the first service in the MPTS.

    r, patFilter := setFilter(demuxPath, "", []int16{0x00})
    defer patFilter.Close()

    rp := ts.PktReaderAsReplacer{R: r}

    // Read and parse the PAT
    var pat psi.PAT
    d := psi.NewSectionDecoder(rp, true)

    fmt.Println("Reading PAT...")
    for {
        if err := pat.Update(d, true); err != nil {
            fmt.Printf("Error reading PAT: %v\n", err)
            os.Exit(1)
        }
        if pat.Version() != -1 {
            break
        }
    }

    // Print the PAT and select the first valid service
    fmt.Println("Program Association Table (PAT):")
    pl := pat.ProgramList()
    var firstServiceID uint16
    var firstPMTPID int16

    for !pl.IsEmpty() {
        progID, pmtPID, remaining := pl.Pop()
        if progID != 0 {
            firstServiceID = progID
            firstPMTPID = pmtPID

            break
        }
        pl = remaining
    }

    if firstPMTPID == ts.NullPid {
        fmt.Printf("No valid PMT found in PAT.\n")
        os.Exit(1)
    }

    fmt.Printf("Selected Service ID: %d, PMT PID: %d\n", firstServiceID, firstPMTPID)