poll: Add check if can read event API
Need check if can read event of buffer for video decoder based on
V4L2 driver. Add the API for it.
https://bugzilla.gnome.org/show_bug.cgi?id=752962
Upstream status: pending
Signed-off-by: Song Bing bing.song@nxp.com
diff --git a/gst/gstpoll.c b/gst/gstpoll.c
index fd672ed..084f6f7 100644
--- a/gst/gstpoll.c
+++ b/gst/gstpoll.c
@@ -1242,6 +1242,58 @@
return res;
}
+static gboolean
+gst_poll_fd_can_read_pri_unlocked (const GstPoll * set, GstPollFD * fd)
+{
+ gboolean res = FALSE;
+ gint idx;
+
+ idx = find_index (set->active_fds, fd);
+ if (idx >= 0) {
+#ifndef G_OS_WIN32
+ struct pollfd *pfd = &g_array_index (set->active_fds, struct pollfd, idx);
+
+ res = (pfd->revents & POLLPRI) != 0;
+#else
+ WinsockFd *wfd = &g_array_index (set->active_fds, WinsockFd, idx);
+
+ res = (wfd->events.lNetworkEvents & FD_ACCEPT) != 0;
+#endif
+ } else {
+ GST_WARNING ("%p: couldn't find fd !", set);
+ }
+ GST_DEBUG ("%p: fd (fd:%d, idx:%d) %d", set, fd->fd, fd->idx, res);
+
+ return res;
+}
+
+/**
+ * gst_poll_fd_can_read_pri:
+ * @set: a file descriptor set.
+ * @fd: a file descriptor.
+ *
+ * Check if @fd in @set has data to be read.
+ *
+ * Returns: %TRUE if the descriptor has data to be read.
+ */
+gboolean
+gst_poll_fd_can_read_pri (const GstPoll * set, GstPollFD * fd)
+{
+ gboolean res = FALSE;
+
+ g_return_val_if_fail (set != NULL, FALSE);
+ g_return_val_if_fail (fd != NULL, FALSE);
+ g_return_val_if_fail (fd->fd >= 0, FALSE);
+
+ g_mutex_lock (&((GstPoll *) set)->lock);
+
+ res = gst_poll_fd_can_read_pri_unlocked (set, fd);
+
+ g_mutex_unlock (&((GstPoll *) set)->lock);
+
+ return res;
+}
+
/**
* gst_poll_fd_can_write:
* @set: a file descriptor set.
diff --git a/gst/gstpoll.h b/gst/gstpoll.h
index ef6dcea..0513648 100644
--- a/gst/gstpoll.h
+++ b/gst/gstpoll.h
@@ -79,6 +79,7 @@
gboolean gst_poll_fd_has_closed (const GstPoll *set, GstPollFD *fd);
gboolean gst_poll_fd_has_error (const GstPoll *set, GstPollFD *fd);
gboolean gst_poll_fd_can_read (const GstPoll *set, GstPollFD *fd);
+gboolean gst_poll_fd_can_read_pri (const GstPoll *set, GstPollFD *fd);
gboolean gst_poll_fd_can_write (const GstPoll *set, GstPollFD *fd);
gint gst_poll_wait (GstPoll *set, GstClockTime timeout);