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

Demuxer: emit an error in case of unknown data packets and EOF #32

Merged
merged 1 commit into from
Oct 1, 2021
Merged

Demuxer: emit an error in case of unknown data packets and EOF #32

merged 1 commit into from
Oct 1, 2021

Conversation

aler9
Copy link
Contributor

@aler9 aler9 commented Sep 30, 2021

Fixes #26

Fixes bluenviron/mediamtx#558

At the moment, demuxer's NextData() returns (nil, nil) when the stream is finished (EOF), there are TS packets in the queue but they're unknown data packets (not PSI or PES).

This is due to the fact that err is overridden by a call to parseData(), that sets it to nil unless there's a parse error.

In my opinion, the function:

  • should return (nil, ErrNoMorePackets) in case there are TS packets with payload in the queue but they can't be parsed.
  • should return (data, nil) in case the TS packets in the queue are known data packets

This patch fixes the issue.

@coveralls
Copy link

coveralls commented Sep 30, 2021

Coverage Status

Coverage increased (+0.04%) to 77.211% when pulling 473f66c on aler9:patch-demuxer-finalpackets into ddb96a7 on asticode:master.

@aler9 aler9 changed the title Demuxer: emit an error in case of no packets and incomplete PES Demuxer: emit an error in case of incomplete PES packet and EOF Sep 30, 2021
@aler9 aler9 changed the title Demuxer: emit an error in case of incomplete PES packet and EOF Demuxer: emit an error in case of non-data packets and EOF Sep 30, 2021
@aler9 aler9 changed the title Demuxer: emit an error in case of non-data packets and EOF Demuxer: emit an error in case of unknown data packets and EOF Sep 30, 2021
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.

Nice catch!

demuxer.go Outdated Show resolved Hide resolved
// We need to silence this error as there may be some incomplete data here
// We still want to try to parse all packets, in case final data is complete
continue
}

// Update data
if d = dmx.updateData(ds); d != nil {
err = nil
Copy link
Owner

Choose a reason for hiding this comment

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

Why are you resetting err here? 🤔

imho we still want to return an ErrNoMorePackets here so that the developer knows the end of stream has been reached.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm not sure about this, in my opinion a read function should return either (data, nil) or (nil, error) - in this case, even if we reset the error, it reappears at the next function call and makes the function return (nil, error)

Copy link
Owner

Choose a reason for hiding this comment

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

I agree with you 👍

demuxer_test.go Outdated Show resolved Hide resolved
At the moment, the demuxer returns (nil, nil) when the stream
is finished, there are TS packets in the queue but they're
unknown data packets.

This patch makes the demuxer emit (nil, ErrNoMorePackets).
@asticode asticode merged commit 473f66c into asticode:master Oct 1, 2021
@asticode
Copy link
Owner

asticode commented Oct 1, 2021

FYI I've created a v1.10.0 tag

@aler9 aler9 deleted the patch-demuxer-finalpackets branch October 1, 2021 11:56
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.

crash when proxing HLS demuxer.NextData returns (nil, nil) on unknown data types
3 participants