go2rtc icon indicating copy to clipboard operation
go2rtc copied to clipboard

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

Open brilthor opened this issue 10 months ago • 2 comments

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                     |
===============================================================================

brilthor avatar Apr 20 '24 02:04 brilthor

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

AlexxIT avatar Apr 20 '24 08:04 AlexxIT

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

brilthor avatar Apr 20 '24 15:04 brilthor