Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSI: parse multiple sections correctly #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tmm1
Copy link
Contributor

@tmm1 tmm1 commented Apr 7, 2021

cc #25

@coveralls
Copy link

coveralls commented Apr 7, 2021

Coverage Status

Coverage decreased (-76.6%) to 0.0% when pulling d1f8a96 on tmm1:psi-parse-multiple into 077af8e on asticode:master.

@@ -241,7 +243,7 @@ func parsePSISectionHeader(i *astikit.BytesIterator) (h *PSISectionHeader, offse
h.PrivateBit = bs[0]&0x40 > 0

// Section length
h.SectionLength = uint16(bs[0]&0xf)<<8 | uint16(bs[1])
h.SectionLength = uint16(bs[0]&3)<<8 | uint16(bs[1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that &3 is not correct here, it should be 0xf, since the specification says that section length is 12 bits long.

Screenshot 2021-04-07 at 16 01 37

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I always use this copy of spec: http://www.itu.int/rec/T-REC-H.222.0-201410-S/en

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On page 50 it says the section_length is only 10 bits:

section_length – This is a 12-bit field, the first two bits of which shall be '00'. The remaining 10 bits specify the number of bytes of the section, starting immediately following the section_length field, and including the CRC. The value in this field shall not exceed 1021 (0x3FD).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I missed that one. Can you please fix this one in muxer as well?

Copy link
Owner

@asticode asticode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I don't quite get why removing || tableID.isUnknown() would fix your issue here 🤔 Can you explain it a little bit?

data_psi.go Outdated
@@ -120,6 +120,9 @@ func parsePSIData(i *astikit.BytesIterator) (d *PSIData, err error) {
err = fmt.Errorf("astits: parsing PSI table failed: %w", err)
return
}
if stop {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just replace this by an else if?

@tmm1
Copy link
Contributor Author

tmm1 commented Apr 10, 2021

To be honest I don't quite get why removing || tableID.isUnknown() would fix your issue here 🤔 Can you explain it a little bit?

The issue was that when an unknown table was seen previously, parsing stopped altogether. This means that a known table later in the same packet (such as the program_map) was ignored altogether.

@asticode
Copy link
Owner

OK, got it. In that case, I feel like doing the following would better fix the problem and clean everything behind:

  1. Remove the shouldStopPSIParsing function
  2. Make sure the parsePSISectionHeader function returns stop and upon calling it, add an else if stop { return } (and hence remove the if shouldStopPSIParsing(s.Header.TableID) below)
  3. Replace this if with if tableID == PSITableIDNull directly
  4. Remove this function

What do you think?

@asticode asticode force-pushed the master branch 2 times, most recently from 106bbe5 to 0df190a Compare July 27, 2023 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants