Fix remaining API issues and borrow conflicts
- Rename display param to target_display to avoid tracing conflict - Refactor session loop to avoid holding borrow across handle_message
This commit is contained in:
@@ -55,7 +55,7 @@ impl DxgiCapturer {
|
|||||||
|
|
||||||
/// Create D3D device and output duplication
|
/// Create D3D device and output duplication
|
||||||
fn create_duplication(
|
fn create_duplication(
|
||||||
display: &Display,
|
target_display: &Display,
|
||||||
) -> Result<(ID3D11Device, ID3D11DeviceContext, IDXGIOutputDuplication, DXGI_OUTDUPL_DESC)> {
|
) -> Result<(ID3D11Device, ID3D11DeviceContext, IDXGIOutputDuplication, DXGI_OUTDUPL_DESC)> {
|
||||||
unsafe {
|
unsafe {
|
||||||
// Create DXGI factory
|
// Create DXGI factory
|
||||||
@@ -63,7 +63,7 @@ impl DxgiCapturer {
|
|||||||
.context("Failed to create DXGI factory")?;
|
.context("Failed to create DXGI factory")?;
|
||||||
|
|
||||||
// Find the adapter and output for this display
|
// Find the adapter and output for this display
|
||||||
let (adapter, output) = Self::find_adapter_output(&factory, display)?;
|
let (adapter, output) = Self::find_adapter_output(&factory, target_display)?;
|
||||||
|
|
||||||
// Create D3D11 device
|
// Create D3D11 device
|
||||||
let mut device: Option<ID3D11Device> = None;
|
let mut device: Option<ID3D11Device> = None;
|
||||||
@@ -100,7 +100,7 @@ impl DxgiCapturer {
|
|||||||
"Created DXGI duplication: {}x{}, display: {}",
|
"Created DXGI duplication: {}x{}, display: {}",
|
||||||
desc.ModeDesc.Width,
|
desc.ModeDesc.Width,
|
||||||
desc.ModeDesc.Height,
|
desc.ModeDesc.Height,
|
||||||
&display.name
|
target_display.name
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok((device, context, duplication, desc))
|
Ok((device, context, duplication, desc))
|
||||||
|
|||||||
@@ -59,8 +59,9 @@ impl SessionManager {
|
|||||||
|
|
||||||
/// Run the session main loop
|
/// Run the session main loop
|
||||||
pub async fn run(&mut self) -> Result<()> {
|
pub async fn run(&mut self) -> Result<()> {
|
||||||
let transport = self.transport.as_mut()
|
if self.transport.is_none() {
|
||||||
.ok_or_else(|| anyhow::anyhow!("Not connected"))?;
|
anyhow::bail!("Not connected");
|
||||||
|
}
|
||||||
|
|
||||||
self.state = SessionState::Active;
|
self.state = SessionState::Active;
|
||||||
|
|
||||||
@@ -91,7 +92,17 @@ impl SessionManager {
|
|||||||
// Main loop
|
// Main loop
|
||||||
loop {
|
loop {
|
||||||
// Check for incoming messages (non-blocking)
|
// Check for incoming messages (non-blocking)
|
||||||
while let Some(msg) = transport.try_recv()? {
|
// Collect messages first, then release borrow before handling
|
||||||
|
let messages: Vec<Message> = {
|
||||||
|
let transport = self.transport.as_mut().unwrap();
|
||||||
|
let mut msgs = Vec::new();
|
||||||
|
while let Some(msg) = transport.try_recv()? {
|
||||||
|
msgs.push(msg);
|
||||||
|
}
|
||||||
|
msgs
|
||||||
|
};
|
||||||
|
|
||||||
|
for msg in messages {
|
||||||
self.handle_message(&mut input, msg)?;
|
self.handle_message(&mut input, msg)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +118,7 @@ impl SessionManager {
|
|||||||
let msg = Message {
|
let msg = Message {
|
||||||
payload: Some(message::Payload::VideoFrame(encoded.frame)),
|
payload: Some(message::Payload::VideoFrame(encoded.frame)),
|
||||||
};
|
};
|
||||||
|
let transport = self.transport.as_mut().unwrap();
|
||||||
transport.send(msg).await?;
|
transport.send(msg).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user