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

Remove pts adjustments in stream #42399

Merged
merged 5 commits into from
Nov 16, 2020

Conversation

uvjustin
Copy link
Contributor

@uvjustin uvjustin commented Oct 26, 2020

Proposed change

Adjusting the incoming packet DTS/PTS of the audio and video streams to start from 0 based on the first packet of each stream received seems to be unnecessary for the hls segments and starting both from 0 may actually cause a slightly inaccurate A/V sync, as there might be a slight offset between the audio and video segments. Assuming the input audio and video streams are consistent, we can just use the original DTS/PTS values of the input streams. This PR removes the DTS/PTS adjustments in the stream worker and makes the peek_first_pts function slightly more readable.
In recorder, we still need to adjust the dts/pts to 0 for the video stream, but we should also use a common basis for adjustment for the audio stream to avoid the minor A/V sync issue.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @hunterjm, mind taking a look at this pull request as its been labeled with an integration (stream) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@uvjustin uvjustin force-pushed the remove-pts-adjustment-stream branch from 932aef6 to e13ea3c Compare October 26, 2020 13:21
@uvjustin uvjustin marked this pull request as draft October 26, 2020 18:18
@uvjustin uvjustin marked this pull request as ready for review October 27, 2020 01:36

for segment in segments:
# Open segment
source = av.open(segment.segment, "r", format=container_format)
Copy link
Member

@hunterjm hunterjm Oct 27, 2020

Choose a reason for hiding this comment

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

Does this work? I believe the reason I had to add the seek in the first place is because after initial muxing the pointer in the BytesIO was at the end, so when calling av.open it didn't read the stream properly.

Copy link
Contributor Author

@uvjustin uvjustin Oct 27, 2020

Choose a reason for hiding this comment

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

Hmm, this seems to work on my end. Maybe you can test it out when you get a chance? That said, there does seem to be a fair amount of seemingly random stuff we have in the component that's actually there for good reason :-)
Edit: Given that you remember that we need it we should be extra careful about it. You told me the same thing about the monotonic dts check, and we ended up getting endless complaints about a few warning messages...

Copy link
Member

@hunterjm hunterjm Oct 27, 2020

Choose a reason for hiding this comment

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

It's possible it was added back when I wasn't closing the output container (which PyAV didn't allow you to do until a recent version bump). Now that we are, it's entirely possible that the act of closing the stream resets it automatically.
edit: I can try to test later tonight to make sure.

@colormodzz

This comment has been minimized.

Copy link
Member

@hunterjm hunterjm left a comment

Choose a reason for hiding this comment

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

Verified locally. Looks good.

@hunterjm hunterjm merged commit 414f167 into home-assistant:dev Nov 16, 2020
@balloob balloob added this to the 0.118.0 milestone Nov 16, 2020
balloob pushed a commit that referenced this pull request Nov 16, 2020
* Remove unnecessary pts adjustments

* Add comments

* Use -inf for initial last_dts to be more clear

* Use video first_pts as common adjuster in recorder

* Remove seek(0) before av.open
KJonline pushed a commit to Pyhass/core that referenced this pull request Nov 17, 2020
* 'dev' of https://github.com/home-assistant/core: (77 commits)
  Fix kodi media_player unavailable at start (home-assistant#41714)
  Add an option to template delay_on/off in template binary sensor (home-assistant#43259)
  Bump hatasmota to 0.0.31 (home-assistant#43319)
  Update cloud integration to 0.38.0 (home-assistant#43314)
  Add progress translation key to hassfest (home-assistant#43311)
  Bump codecov/codecov-action from v1.0.14 to v1.0.15 (home-assistant#43304)
  Improvement to allow parsing of station ID in vasttrafik integration. Addresses home-assistant#34851 (home-assistant#43136)
  Abort vizio discovery flow without unique ID (home-assistant#43303)
  Update directv to 0.4.0 (home-assistant#43302)
  Add notification binary_sensor to Plugwise integration (home-assistant#41473)
  [ci skip] Translation update
  Bump bimmer_connected to 0.7.13 (home-assistant#43294)
  Bump aioguardian to 1.0.4 (home-assistant#43299)
  Refactor how entities are created for homekit_controller services (home-assistant#43242)
  Updated frontend to 20201111.1 (home-assistant#43298)
  Update pytradfri to 7.0.4 (home-assistant#43297)
  Remove pts adjustments in stream (home-assistant#42399)
  Fix Enigma2 available entity property (home-assistant#43292)
  Make MQTT climate return PRESET_NONE when no preset is set (home-assistant#43257)
  Bump env_canada to 0.2.4, fix config validation (home-assistant#43251)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants