AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
4.21k stars 344 forks source link

MPEG TS output doesn't appear to continue sending PAT and PMT #1052

Open brilthor opened 4 months ago

brilthor commented 4 months ago

When pulling a TS output stream (http://go2rtc:1984/api/stream.ts?src=hdpvr) it looks like the PAT and PMT only get sent at the start as opposed to at least every 100ms.

I took a dive into the code and it looks like

func (m *Muxer) GetHeader() []byte {
    bw := bits.NewWriter(nil)
    m.writePAT(bw)
    m.writePMT(bw)
    return bw.Bytes()
}

is the only time the writePAT and writePMT get called and that in turn is only called at the initial consumer response:

func (c *Consumer) WriteTo(wr io.Writer) (int64, error) {
    b := c.muxer.GetHeader()
    if _, err := wr.Write(b); err != nil {
        return 0, err
    }

    return c.wr.WriteTo(wr)
}

this appears to be backed up by analyzing the output:

===============================================================================
|  TABLES & SECTIONS ANALYSIS REPORT                                          |
|=============================================================================|
|  PID: 0x0000 (0)                                                       PAT  |
|-----------------------------------------------------------------------------|
|  0x00 (0, PAT)                                                              |
|      Repetition: ...... 0  pkt  Section cnt: ....... 55                     |
|      Min repet.: ...... 0  pkt                                              |
|      Max repet.: ...... 0  pkt                                              |
|-----------------------------------------------------------------------------|
|  0x00 (0, PAT), TID ext: 0x0001 (1)                                         |
|      Repetition: ...... 0  pkt  Section cnt: ........ 1                     |
|      Min repet.: ...... 0  pkt  Table cnt: .......... 1                     |
|      Max repet.: ...... 0  pkt  Version: ............ 0                     |
|=============================================================================|
|  PID: 0x1000 (4096)                                                    PMT  |
|  Service: 0x0001 (1) (unknown)                                              |
|-----------------------------------------------------------------------------|
|  0x00 (0, PAT)                                                              |
|      Repetition: ...... 0  pkt  Section cnt: ....... 52                     |
|      Min repet.: ...... 0  pkt                                              |
|      Max repet.: ...... 0  pkt                                              |
|-----------------------------------------------------------------------------|
|  0x02 (2, PMT), TID ext: 0x0001 (1)                                         |
|      Repetition: ...... 0  pkt  Section cnt: ........ 1                     |
|      Min repet.: ...... 0  pkt  Table cnt: .......... 1                     |
|      Max repet.: ...... 0  pkt  Version: ............ 0                     |
===============================================================================

vs from an ATSC TS via hdhr

===============================================================================
|  TABLES & SECTIONS ANALYSIS REPORT                                          |
|=============================================================================|
|  PID: 0x0000 (0)                                                       PAT  |
|-----------------------------------------------------------------------------|
|  0x00 (0, PAT), TID ext: 0x4329 (17193)                                     |
|      Repetition: ...... 74  ms  Section cnt: ...... 135                     |
|      Min repet.: ....... 0  ms  Table cnt: ........ 135                     |
|      Max repet.: ...... 76  ms  Version: ............ 0                     |
|=============================================================================|
|  PID: 0x0030 (48)                                                      PMT  |
|  Service: 0x0003 (3) (unknown)                                              |
|-----------------------------------------------------------------------------|
|  0x02 (2, PMT), TID ext: 0x0003 (3)                                         |
|      Repetition: ..... 375  ms  Section cnt: ....... 27                     |
|      Min repet.: ..... 373  ms  Table cnt: ......... 27                     |
|      Max repet.: ..... 378  ms  Version: ........... 26                     |
===============================================================================
AlexxIT commented 4 months ago

Which software need to send PAT and PMT regularly? Go2rtc implements a modern version of stream handling.

brilthor commented 4 months ago

I came across the issue while trying to debug why tvheadend was saying it was an failed scan / invalid stream