1 GstPoll基本概念

  • GstPoll 类似于 fd_set(与 select() 一起使用)或 struct pollfd 数组(与 poll() 一起使用),用于跟踪文件描述符。一旦通过 gst_poll_new 创建,这个集合就可以用来等待文件描述符变为可读和/或可写。通过在创建集合时(或稍后调用 gst_poll_set_controllable)为 controllable 标志指定 TRUE,可以使这种等待受控。

  • 新的文件描述符通过 gst_poll_add_fd 添加到集合中,并通过 gst_poll_remove_fd 移除。控制哪些文件描述符应该等待变为可读和/或可写是通过使用 gst_poll_fd_ctl_read、gst_poll_fd_ctl_write 和 gst_poll_fd_ctl_pri 来完成的。

  • 使用 gst_poll_wait 等待文件描述符实际变为可读和/或可写,或者在没有文件描述符及时可用时超时。通过调用 gst_poll_restart 和 gst_poll_set_flushing 可以控制等待。

  • 一旦等待了文件描述符集合,就可以使用 gst_poll_fd_has_closed 来查看文件描述符是否已关闭,使用 gst_poll_fd_has_error 来查看它是否产生了错误,使用 gst_poll_fd_can_read 来查看是否可以从文件描述符中读取,以及使用 gst_poll_fd_can_write 来查看是否可以写入文件描述符。

2 GstPoll类型结构

2.1 GstPoll类型注册宏定义

没有注册GType类型

2.2 GstPoll类型相关枚举

2.2.1 GstPollMode

/* filename: gstpoll.c */
typedef enum
{
  GST_POLL_MODE_AUTO,
  GST_POLL_MODE_SELECT,
  GST_POLL_MODE_PSELECT,
  GST_POLL_MODE_POLL,
  GST_POLL_MODE_PPOLL,
  GST_POLL_MODE_WINDOWS
} GstPollMode;

2.3 GstPoll相关结构体

2.3.1 GstPollFD

一个文件描述符对象

/* filename: gstpoll.h */
typedef struct {
  int fd;

  /*< private >*/
  gint idx;
} GstPollFD;

2.3.2 GstPoll

/* filename: gstpoll.c */
struct _GstPoll
{
  GstPollMode mode;

  GMutex lock;
  /* array of fds, always written to and read from with lock */
  GArray *fds;
  /* array of active fds, only written to from the waiting thread with the
   * lock and read from with the lock or without the lock from the waiting
   * thread */
  GArray *active_fds;

  GstPollFD control_read_fd;
  GstPollFD control_write_fd;

  /* 是否有可控制等待(多线程中,中断GstPoll等待,中断堵塞) */
  gboolean controllable;
  gint waiting;
  gint control_pending;
  gint flushing;
  gboolean timer;
  gint rebuild;
};

3 GstPoll对象相关函数