1*1b4853f5SAndroid Build Coastguard Worker // Copyright 2024 The ChromiumOS Authors 2*1b4853f5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*1b4853f5SAndroid Build Coastguard Worker // found in the LICENSE file. 4*1b4853f5SAndroid Build Coastguard Worker 5*1b4853f5SAndroid Build Coastguard Worker use std::os::fd::BorrowedFd; 6*1b4853f5SAndroid Build Coastguard Worker 7*1b4853f5SAndroid Build Coastguard Worker /// Trait allowing sessions of a device to signal when they have an event pending. 8*1b4853f5SAndroid Build Coastguard Worker /// 9*1b4853f5SAndroid Build Coastguard Worker /// The worker that runs a `V4l2ProxyDevice` typically polls on file descriptors for available 10*1b4853f5SAndroid Build Coastguard Worker /// CAPTURE buffers and outstanding session events. However V4L2's poll logic returns with the 11*1b4853f5SAndroid Build Coastguard Worker /// `POLLERR` flag if a CAPTURE queue is polled while not streaming or if zero CAPTURE buffers have 12*1b4853f5SAndroid Build Coastguard Worker /// been queued. To avoid this, the device needs to disable polling when this would happen, and 13*1b4853f5SAndroid Build Coastguard Worker /// re-enable it when conditions are adequate. 14*1b4853f5SAndroid Build Coastguard Worker /// 15*1b4853f5SAndroid Build Coastguard Worker /// If the worker does not need such a feature, `()` can be passed as a no-op type that implements 16*1b4853f5SAndroid Build Coastguard Worker /// this interface. 17*1b4853f5SAndroid Build Coastguard Worker pub trait SessionPoller: Clone { 18*1b4853f5SAndroid Build Coastguard Worker /// Add a newly created `session` to be polled. 19*1b4853f5SAndroid Build Coastguard Worker /// 20*1b4853f5SAndroid Build Coastguard Worker /// The `session` FD must signal that it is readable if there are events pending for the 21*1b4853f5SAndroid Build Coastguard Worker /// session. add_session(&self, session: BorrowedFd, session_id: u32) -> Result<(), i32>22*1b4853f5SAndroid Build Coastguard Worker fn add_session(&self, session: BorrowedFd, session_id: u32) -> Result<(), i32>; 23*1b4853f5SAndroid Build Coastguard Worker /// Stop polling all activity on `session`. remove_session(&self, session: BorrowedFd)24*1b4853f5SAndroid Build Coastguard Worker fn remove_session(&self, session: BorrowedFd); 25*1b4853f5SAndroid Build Coastguard Worker } 26*1b4853f5SAndroid Build Coastguard Worker 27*1b4853f5SAndroid Build Coastguard Worker /// No-op implementation of `SessionPoller`. This should only be used when using 28*1b4853f5SAndroid Build Coastguard Worker /// `VirtioMediaDeviceRunner` with a device that doesn't need to be polled, otherwise the methods 29*1b4853f5SAndroid Build Coastguard Worker /// might be called, which will make the program panic. 30*1b4853f5SAndroid Build Coastguard Worker impl SessionPoller for () { add_session(&self, _session: BorrowedFd, _session_id: u32) -> Result<(), i32>31*1b4853f5SAndroid Build Coastguard Worker fn add_session(&self, _session: BorrowedFd, _session_id: u32) -> Result<(), i32> { 32*1b4853f5SAndroid Build Coastguard Worker panic!("this device needs a proper SessionPoller - aborting") 33*1b4853f5SAndroid Build Coastguard Worker } 34*1b4853f5SAndroid Build Coastguard Worker remove_session(&self, _session: BorrowedFd)35*1b4853f5SAndroid Build Coastguard Worker fn remove_session(&self, _session: BorrowedFd) { 36*1b4853f5SAndroid Build Coastguard Worker panic!("this device needs a proper SessionPoller - aborting") 37*1b4853f5SAndroid Build Coastguard Worker } 38*1b4853f5SAndroid Build Coastguard Worker } 39