@@ -783,7 +783,7 @@ void vb2_queue_release(struct vb2_queue *q)
783783EXPORT_SYMBOL_GPL (vb2_queue_release );
784784
785785/**
786- * vb2_poll () - implements poll userspace operation
786+ * vb2_core_poll () - implements poll userspace operation
787787 * @q: videobuf2 queue
788788 * @file: file argument passed to the poll file operation handler
789789 * @wait: wait argument passed to the poll file operation handler
@@ -795,33 +795,20 @@ EXPORT_SYMBOL_GPL(vb2_queue_release);
795795 * For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor
796796 * will be reported as available for writing.
797797 *
798- * If the driver uses struct v4l2_fh, then vb2_poll() will also check for any
799- * pending events.
800- *
801798 * The return values from this function are intended to be directly returned
802799 * from poll handler in driver.
803800 */
804- unsigned int vb2_poll (struct vb2_queue * q , struct file * file , poll_table * wait )
801+ unsigned int vb2_core_poll (struct vb2_queue * q , struct file * file ,
802+ poll_table * wait )
805803{
806- struct video_device * vfd = video_devdata (file );
807804 unsigned long req_events = poll_requested_events (wait );
808805 struct vb2_buffer * vb = NULL ;
809- unsigned int res = 0 ;
810806 unsigned long flags ;
811807
812- if (test_bit (V4L2_FL_USES_V4L2_FH , & vfd -> flags )) {
813- struct v4l2_fh * fh = file -> private_data ;
814-
815- if (v4l2_event_pending (fh ))
816- res = POLLPRI ;
817- else if (req_events & POLLPRI )
818- poll_wait (file , & fh -> wait , wait );
819- }
820-
821808 if (!q -> is_output && !(req_events & (POLLIN | POLLRDNORM )))
822- return res ;
809+ return 0 ;
823810 if (q -> is_output && !(req_events & (POLLOUT | POLLWRNORM )))
824- return res ;
811+ return 0 ;
825812
826813 /*
827814 * Start file I/O emulator only if streaming API has not been used yet.
@@ -830,16 +817,16 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
830817 if (!q -> is_output && (q -> io_modes & VB2_READ ) &&
831818 (req_events & (POLLIN | POLLRDNORM ))) {
832819 if (__vb2_init_fileio (q , 1 ))
833- return res | POLLERR ;
820+ return POLLERR ;
834821 }
835822 if (q -> is_output && (q -> io_modes & VB2_WRITE ) &&
836823 (req_events & (POLLOUT | POLLWRNORM ))) {
837824 if (__vb2_init_fileio (q , 0 ))
838- return res | POLLERR ;
825+ return POLLERR ;
839826 /*
840827 * Write to OUTPUT queue can be done immediately.
841828 */
842- return res | POLLOUT | POLLWRNORM ;
829+ return POLLOUT | POLLWRNORM ;
843830 }
844831 }
845832
@@ -848,29 +835,22 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
848835 * error flag is set.
849836 */
850837 if (!vb2_is_streaming (q ) || q -> error )
851- return res | POLLERR ;
852- /*
853- * For compatibility with vb1: if QBUF hasn't been called yet, then
854- * return POLLERR as well. This only affects capture queues, output
855- * queues will always initialize waiting_for_buffers to false.
856- */
857- if (q -> waiting_for_buffers )
858- return res | POLLERR ;
838+ return POLLERR ;
859839
860840 /*
861841 * For output streams you can call write() as long as there are fewer
862842 * buffers queued than there are buffers available.
863843 */
864844 if (q -> is_output && q -> fileio && q -> queued_count < q -> num_buffers )
865- return res | POLLOUT | POLLWRNORM ;
845+ return POLLOUT | POLLWRNORM ;
866846
867847 if (list_empty (& q -> done_list )) {
868848 /*
869849 * If the last buffer was dequeued from a capture queue,
870850 * return immediately. DQBUF will return -EPIPE.
871851 */
872852 if (q -> last_buffer_dequeued )
873- return res | POLLIN | POLLRDNORM ;
853+ return POLLIN | POLLRDNORM ;
874854
875855 poll_wait (file , & q -> done_wq , wait );
876856 }
@@ -887,10 +867,55 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
887867 if (vb && (vb -> state == VB2_BUF_STATE_DONE
888868 || vb -> state == VB2_BUF_STATE_ERROR )) {
889869 return (q -> is_output ) ?
890- res | POLLOUT | POLLWRNORM :
891- res | POLLIN | POLLRDNORM ;
870+ POLLOUT | POLLWRNORM :
871+ POLLIN | POLLRDNORM ;
892872 }
893- return res ;
873+ return 0 ;
874+ }
875+
876+ /**
877+ * vb2_poll() - implements poll userspace operation
878+ * @q: videobuf2 queue
879+ * @file: file argument passed to the poll file operation handler
880+ * @wait: wait argument passed to the poll file operation handler
881+ *
882+ * This function implements poll file operation handler for a driver.
883+ * For CAPTURE queues, if a buffer is ready to be dequeued, the userspace will
884+ * be informed that the file descriptor of a video device is available for
885+ * reading.
886+ * For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor
887+ * will be reported as available for writing.
888+ *
889+ * If the driver uses struct v4l2_fh, then vb2_poll() will also check for any
890+ * pending events.
891+ *
892+ * The return values from this function are intended to be directly returned
893+ * from poll handler in driver.
894+ */
895+ unsigned int vb2_poll (struct vb2_queue * q , struct file * file , poll_table * wait )
896+ {
897+ struct video_device * vfd = video_devdata (file );
898+ unsigned long req_events = poll_requested_events (wait );
899+ unsigned int res = 0 ;
900+
901+ if (test_bit (V4L2_FL_USES_V4L2_FH , & vfd -> flags )) {
902+ struct v4l2_fh * fh = file -> private_data ;
903+
904+ if (v4l2_event_pending (fh ))
905+ res = POLLPRI ;
906+ else if (req_events & POLLPRI )
907+ poll_wait (file , & fh -> wait , wait );
908+ }
909+
910+ /*
911+ * For compatibility with vb1: if QBUF hasn't been called yet, then
912+ * return POLLERR as well. This only affects capture queues, output
913+ * queues will always initialize waiting_for_buffers to false.
914+ */
915+ if (q -> waiting_for_buffers && (req_events & (POLLIN | POLLRDNORM )))
916+ return POLLERR ;
917+
918+ return res | vb2_core_poll (q , file , wait );
894919}
895920EXPORT_SYMBOL_GPL (vb2_poll );
896921
0 commit comments