-
Notifications
You must be signed in to change notification settings - Fork 0
fix: recover CEC and guard inactive source for DP > HDMI Adaptors #2
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
Draft
xXJSONDeruloXx
wants to merge
1
commit into
main
Choose a base branch
from
active-source-guard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+45
−34
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,10 @@ use crate::{ArcDevice, AsyncDevicePoller}; | |
|
|
||
| const LOG_ADDR_RETRIES: i32 = 20; | ||
| const WAKE_TRIES: i32 = 2; | ||
| const ACTIVE_SOURCE_DELAY: Duration = Duration::from_millis(100); | ||
| const WAKE_DELAY: Duration = Duration::from_millis(1000); | ||
| const RESUME_TRIES: i32 = 5; | ||
| const RESUME_DELAY: Duration = Duration::from_millis(1000); | ||
| const REPLY_RETRIES: i32 = 4; | ||
|
|
||
| type CallbackFut<'a> = Box<dyn Future<Output = Result<()>> + Send + 'a>; | ||
|
|
@@ -465,6 +468,7 @@ impl DeviceTask { | |
| async fn wake(&mut self) -> Result<()> { | ||
| self.device.lock().await.wake(false, false).await?; | ||
| self.awaiting_wake = true; | ||
| sleep(ACTIVE_SOURCE_DELAY).await; | ||
| for _ in 0..WAKE_TRIES { | ||
| let result = self.device.lock().await.set_active_source(None).await; | ||
| match result { | ||
|
|
@@ -505,13 +509,46 @@ impl DeviceTask { | |
| Ok(()) | ||
| } | ||
|
|
||
| async fn recover_after_resume(&mut self) { | ||
| for attempt in 1..=RESUME_TRIES { | ||
| match self | ||
| .system | ||
| .lock() | ||
| .await | ||
| .configure_dev(self.device.clone(), self.connector.as_ref()) | ||
| .await | ||
| { | ||
| Ok(connector) => { | ||
| self.connector = connector; | ||
| if self | ||
| .device | ||
| .lock() | ||
| .await | ||
| .poll_address(LogicalAddress::Tv) | ||
| .await | ||
| .is_ok() | ||
| { | ||
| return; | ||
| } | ||
| } | ||
| Err(err) => { | ||
| warn!("Failed to recover device after resume (attempt {attempt}): {err}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably only log if all of the retries fail. |
||
| } | ||
| } | ||
| if attempt < RESUME_TRIES { | ||
| sleep(RESUME_DELAY).await; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async fn handle_system_message(&mut self, message: SystemMessage) -> Result<()> { | ||
| match message { | ||
| SystemMessage::Wake { | ||
| wake_tv, | ||
| from_standby, | ||
| } => { | ||
| if from_standby { | ||
| self.recover_after_resume().await; | ||
| let device = self.device.clone(); | ||
| self.with_logical_address(Box::new(|_| { | ||
| Box::new(async move { | ||
|
|
@@ -550,10 +587,10 @@ impl DeviceTask { | |
| } | ||
| SystemMessage::Standby { standby_tv, force } => { | ||
| let device = self.device.lock().await; | ||
| let address = device.get_physical_address().await?; | ||
| if force || (self.active && standby_tv) { | ||
| device.standby(LogicalAddress::Tv).await?; | ||
| } else { | ||
| } else if self.active { | ||
| let address = device.get_physical_address().await?; | ||
| device | ||
| .tx_message(&Message::InactiveSource { address }, LogicalAddress::Tv) | ||
| .await?; | ||
|
|
@@ -987,15 +1024,6 @@ mod test { | |
| .await | ||
| .unwrap(); | ||
| } | ||
| assert_eq!( | ||
| rx_message(&test.dev).await.unwrap(), | ||
| ( | ||
| Message::InactiveSource { | ||
| address: PhysicalAddress::from(0x1000) | ||
| }, | ||
| LogicalAddress::Tv | ||
| ) | ||
| ); | ||
| assert!(rx_message(&test.dev).await.is_none()); | ||
| } | ||
|
|
||
|
|
@@ -1798,7 +1826,7 @@ mod test { | |
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_wake_from_standby_deferred() { | ||
| async fn test_wake_from_standby_reconfigures() { | ||
| let test = setup_basic_test().await.unwrap(); | ||
|
|
||
| let interface: InterfaceRef<CecDevice> = test | ||
|
|
@@ -1832,27 +1860,6 @@ mod test { | |
| .unwrap(); | ||
| } | ||
|
|
||
| assert_eq!(rx_message(&test.dev).await, None); | ||
|
|
||
| { | ||
| let dev = interface.get_mut().await; | ||
| dev.device | ||
| .lock() | ||
| .await | ||
| .set_logical_addresses(&[LogicalAddressType::Playback]) | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!( | ||
| dev.device | ||
| .lock() | ||
| .await | ||
| .get_logical_addresses() | ||
| .await | ||
| .unwrap(), | ||
| &[LogicalAddress::PlaybackDevice1] | ||
| ); | ||
| } | ||
|
|
||
| assert_eq!( | ||
| rx_message(&test.dev).await.unwrap(), | ||
| ( | ||
|
|
@@ -1862,6 +1869,10 @@ mod test { | |
| LogicalAddress::Broadcast | ||
| ) | ||
| ); | ||
| assert_eq!( | ||
| test.dev.lock().await.get_logical_addresses().await.unwrap(), | ||
| &[LogicalAddress::PlaybackDevice1] | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this behave if we wake while not connected to the TV then connect later?