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

Solve the the issue of non-DVB transport stream(TS) which using the PID, 0x10~0x1F, as the PIDs of the video/audio streams of program #54

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

Conversation

jlnieh
Copy link

@jlnieh jlnieh commented Oct 13, 2023

Scenario

We got the sample transport stream from IPTV source, which using the PID 0x10 as the program PID, 0x11 as the video stream PID, and 0x12 as the audio stream PID. The transport stream would cause the PSI checksum error, while we tried to use the demux to get NextData() of the stream.

ISO Standard

According to the Table 2-3 -- PID table of the standard ISO/IEC 13818-1:2007, the PID range 0x0010~0x1FFE may be assigned as network PID, program map PID, elementary_PID, or for other purposes.

table2-3

Changes

  1. Use existed struct programMap to setup the locks of the PIDs which used in the program already
  2. While demux parseData(), use the locks to avoid the used PIDs of elementary streams to be identified as PSI table.

…0x1F as the PID of the video/audio streams of programs
@asticode
Copy link
Owner

Which type of content are you demuxing (you say non-DVB, but what's the exact type?) and how can we identify it as non-DVB?

@jlnieh
Copy link
Author

jlnieh commented Oct 17, 2023

Which type of content are you demuxing (you say non-DVB, but what's the exact type?) and how can we identify it as non-DVB?

I believe it is following the ATSC standard or just the IPTV transport stream which does not use those DVB metadata, NIT or SDT. It is not easy to identify the transport stream is following which standard, since both DVB and ATSC standards have their own specific PIDs for their system tables . I would suggest

  1. add one more option to NewDemuxer to let user/developer to choose the TS standard, like the tool, streamXpert, OR
  2. in this case, we could demux the transport stream based on the PAT and known PMT to identify those PIDs, 0x0010~0x001F, is used or locked by one known program/service, OR
  3. in parsePSIData(), if we got the table ID, which is not reasonable, for example the table ID 0x00 is coming with the non-zero PID, we should stop and fall back to identify this PID is non-PSI and may parse it as the PES or some kind of private data in the following packets.

@asticode
Copy link
Owner

OK thanks for the clarification 👍

In that case I would rather you add a new elementaryStreamMap, similar to programMap but separated from it. You can use the same function names.

…sed by known elementary streams of programs in PMT tables
@jlnieh
Copy link
Author

jlnieh commented Oct 24, 2023

Updated to add a new elementaryStreamMap. Please check.

}

// setLocked sets a new stream id to the elementary stream
func (m elementaryStreamMap) setLocked(pid, number uint16) {
Copy link
Owner

Choose a reason for hiding this comment

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

Could you rename Locked to Unlocked in all 3 functions?

The idea is to let the developer know the function is not locking any mutex while manipulating the map which is really unsafe.

pids = append(pids, i)
}
}
assert.Equal(t, []int{0, 16, 17, 18, 19, 20, 30, 31}, pids)
pm.setUnlocked(uint16(1), uint16(0))
assert.True(t, isPSIPayload(uint16(1), pm))
assert.True(t, isPSIPayload(uint16(1), pm, esm))
Copy link
Owner

Choose a reason for hiding this comment

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

Could you add a test using esm.setUnlocked() like it was done with pm.setUnlocked(uint16(1), uint16(0)) above?

@@ -64,7 +65,7 @@ func TestParseData(t *testing.T) {
Payload: p[33:],
},
}
ds, err = parseData(ps, nil, pm)
ds, err = parseData(ps, nil, pm, esm)
Copy link
Owner

Choose a reason for hiding this comment

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

Could you add a test using esm.setUnlocked() like it was done with pm.setUnlocked(uint16(256), uint16(1)) above?

@@ -34,6 +34,7 @@ type Demuxer struct {
packetBuffer *packetBuffer
packetPool *packetPool
programMap *programMap
streamMap *elementaryStreamMap
Copy link
Owner

Choose a reason for hiding this comment

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

Could you order fields alphabetically?

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.

None yet

2 participants