gstreamer_core/gst/gstpoll.c
branchRCL_3
changeset 29 567bb019e3e3
parent 0 0e761a78d257
child 30 7e817e7e631c
equal deleted inserted replaced
6:9b2c3c7a1a9c 29:567bb019e3e3
    66 #include <sys/poll.h>
    66 #include <sys/poll.h>
    67 #endif
    67 #endif
    68 #include <sys/time.h>
    68 #include <sys/time.h>
    69 #endif
    69 #endif
    70 
    70 
       
    71 #include "gst_private.h"
       
    72 
    71 #include <sys/types.h>
    73 #include <sys/types.h>
    72 
    74 
    73 #ifdef HAVE_UNISTD_H
    75 #ifdef HAVE_UNISTD_H
    74 #include <unistd.h>
    76 #include <unistd.h>
    75 #endif
    77 #endif
    86 #include <sys/socket.h>
    88 #include <sys/socket.h>
    87 #endif
    89 #endif
    88 
    90 
    89 /* OS/X needs this because of bad headers */
    91 /* OS/X needs this because of bad headers */
    90 #include <string.h>
    92 #include <string.h>
    91 
       
    92 #include "gst_private.h"
       
    93 
    93 
    94 #include "gstpoll.h"
    94 #include "gstpoll.h"
    95 
    95 
    96 #ifdef __SYMBIAN32__
    96 #ifdef __SYMBIAN32__
    97 #include <glib_global.h>
    97 #include <glib_global.h>
   110 #endif
   110 #endif
   111 #ifndef G_OS_WIN32
   111 #ifndef G_OS_WIN32
   112 /* the poll/select call is also performed on a control socket, that way
   112 /* the poll/select call is also performed on a control socket, that way
   113  * we can send special commands to control it
   113  * we can send special commands to control it
   114  */
   114  */
   115 #define SEND_COMMAND(set, command)                   \
   115 /* FIXME: Shouldn't we check or return the return value
       
   116  * of write()?
       
   117  */
       
   118 #define SEND_COMMAND(set, command, result)           \
   116 G_STMT_START {                                       \
   119 G_STMT_START {                                       \
   117   unsigned char c = command;                         \
   120   unsigned char c = command;                         \
   118   write (set->control_write_fd.fd, &c, 1);           \
   121   result = write (set->control_write_fd.fd, &c, 1);  \
       
   122   if (result > 0)                                    \
       
   123     set->control_pending++;                          \
   119 } G_STMT_END
   124 } G_STMT_END
   120 
   125 
   121 #define READ_COMMAND(set, command, res)              \
   126 #define READ_COMMAND(set, command, res)                \
   122 G_STMT_START {                                       \
   127 G_STMT_START {                                         \
   123   res = read (set->control_read_fd.fd, &command, 1); \
   128   if (set->control_pending > 0) {                      \
       
   129     res = read (set->control_read_fd.fd, &command, 1); \
       
   130     if (res == 1)                                      \
       
   131       set->control_pending--;                          \
       
   132   } else                                               \
       
   133     res = 0;                                           \
   124 } G_STMT_END
   134 } G_STMT_END
   125 
   135 
   126 #define GST_POLL_CMD_WAKEUP  'W'        /* restart the poll/select call */
   136 #define GST_POLL_CMD_WAKEUP  'W'        /* restart the poll/select call */
   127 
   137 
   128 #else /* G_OS_WIN32 */
   138 #else /* G_OS_WIN32 */
   158 #ifndef G_OS_WIN32
   168 #ifndef G_OS_WIN32
   159   GstPollFD control_read_fd;
   169   GstPollFD control_read_fd;
   160   GstPollFD control_write_fd;
   170   GstPollFD control_write_fd;
   161 #else
   171 #else
   162   GArray *active_fds_ignored;
   172   GArray *active_fds_ignored;
   163 
       
   164   GArray *events;
   173   GArray *events;
   165   GArray *active_events;
   174   GArray *active_events;
   166 
   175 
   167   HANDLE wakeup_event;
   176   HANDLE wakeup_event;
   168 #endif
   177 #endif
   169 
   178 
   170   gboolean controllable;
   179   gboolean controllable;
   171   gboolean new_controllable;
   180   gboolean new_controllable;
   172   gboolean waiting;
   181   guint waiting;
       
   182   guint control_pending;
   173   gboolean flushing;
   183   gboolean flushing;
       
   184   gboolean timer;
   174 };
   185 };
   175 
   186 
   176 static gint
   187 static gint
   177 find_index (GArray * array, GstPollFD * fd)
   188 find_index (GArray * array, GstPollFD * fd)
   178 {
   189 {
   296 
   307 
   297   FD_ZERO (readfds);
   308   FD_ZERO (readfds);
   298   FD_ZERO (writefds);
   309   FD_ZERO (writefds);
   299 
   310 
   300   g_mutex_lock (set->lock);
   311   g_mutex_lock (set->lock);
   301   
   312 
   302   for (i = 0; i < set->active_fds->len; i++) {
   313   for (i = 0; i < set->active_fds->len; i++) {
   303 #ifndef __SYMBIAN32__ 
   314 #ifndef __SYMBIAN32__ 
   304     struct pollfd *pfd = &g_array_index (set->fds, struct pollfd, i);
   315     struct pollfd *pfd = &g_array_index (set->fds, struct pollfd, i);
   305 #else    
   316 #else    
   306     GPollFD *pfd = &g_array_index (set->fds, GPollFD, i);
   317     GPollFD *pfd = &g_array_index (set->fds, GPollFD, i);
   314       if (pfd->fd > max_fd)
   325       if (pfd->fd > max_fd)
   315         max_fd = pfd->fd;
   326         max_fd = pfd->fd;
   316     }
   327     }
   317   }
   328   }
   318 
   329 
   319     g_mutex_unlock (set->lock);
   330   g_mutex_unlock (set->lock);
   320 
       
   321 
   331 
   322   return max_fd;
   332   return max_fd;
   323 }
   333 }
   324 
   334 
   325 static void
   335 static void
   500 
   510 
   501  GstPoll *gst_poll_new (gboolean controllable)
   511  GstPoll *gst_poll_new (gboolean controllable)
   502 {
   512 {
   503   GstPoll *nset;
   513   GstPoll *nset;
   504 
   514 
   505   nset = g_new0 (GstPoll, 1);
   515   nset = g_slice_new0 (GstPoll);
   506   nset->lock = g_mutex_new ();
   516   nset->lock = g_mutex_new ();
   507 #ifndef G_OS_WIN32
   517 #ifndef G_OS_WIN32
   508   nset->mode = GST_POLL_MODE_AUTO;
   518   nset->mode = GST_POLL_MODE_AUTO;
   509   //rj nset->fds = g_array_new (FALSE, FALSE, sizeof (struct pollfd));
   519   //rj nset->fds = g_array_new (FALSE, FALSE, sizeof (struct pollfd));
   510   //rj nset->active_fds = g_array_new (FALSE, FALSE, sizeof (struct pollfd));
   520   //rj nset->active_fds = g_array_new (FALSE, FALSE, sizeof (struct pollfd));
   535     return NULL;
   545     return NULL;
   536   }
   546   }
   537 }
   547 }
   538 
   548 
   539 /**
   549 /**
       
   550  * gst_poll_new_timer:
       
   551  *
       
   552  * Create a new poll object that can be used for scheduling cancellable
       
   553  * timeouts.
       
   554  *
       
   555  * A timeout is performed with gst_poll_wait(). Multiple timeouts can be
       
   556  * performed from different threads. 
       
   557  *
       
   558  * Returns: a new #GstPoll, or %NULL in case of an error. Free with
       
   559  * gst_poll_free().
       
   560  *
       
   561  * Since: 0.10.23
       
   562  */
       
   563 #ifdef __SYMBIAN32__
       
   564 EXPORT_C
       
   565 #endif
       
   566  
       
   567 GstPoll *
       
   568 gst_poll_new_timer (void)
       
   569 {
       
   570   GstPoll *poll;
       
   571 
       
   572   /* make a new controllable poll set */
       
   573   if (!(poll = gst_poll_new (TRUE)))
       
   574     goto done;
       
   575 
       
   576   /* we are a timer */
       
   577   poll->timer = TRUE;
       
   578 
       
   579 done:
       
   580   return poll;
       
   581 }
       
   582 
       
   583 /**
   540  * gst_poll_free:
   584  * gst_poll_free:
   541  * @set: a file descriptor set.
   585  * @set: a file descriptor set.
   542  *
   586  *
   543  * Free a file descriptor set.
   587  * Free a file descriptor set.
   544  *
   588  *
   573 #endif
   617 #endif
   574 
   618 
   575   g_array_free (set->active_fds, TRUE);
   619   g_array_free (set->active_fds, TRUE);
   576   g_array_free (set->fds, TRUE);
   620   g_array_free (set->fds, TRUE);
   577   g_mutex_free (set->lock);
   621   g_mutex_free (set->lock);
   578   g_free (set);
   622   g_slice_free (GstPoll, set);
   579 }
   623 }
   580 
   624 
   581 /**
   625 /**
   582  * gst_poll_fd_init:
   626  * gst_poll_fd_init:
   583  * @fd: a #GstPollFD
   627  * @fd: a #GstPollFD
   754     if (active)
   798     if (active)
   755       pfd->events |= POLLOUT;
   799       pfd->events |= POLLOUT;
   756     else
   800     else
   757       pfd->events &= ~POLLOUT;
   801       pfd->events &= ~POLLOUT;
   758 #else
   802 #else
   759     gst_poll_update_winsock_event_mask (set, idx, FD_WRITE, active);
   803     gst_poll_update_winsock_event_mask (set, idx, FD_WRITE | FD_CONNECT,
       
   804         active);
   760 #endif
   805 #endif
   761   }
   806   }
   762 
   807 
   763   g_mutex_unlock (set->lock);
   808   g_mutex_unlock (set->lock);
   764 
   809 
   810  * Since: 0.10.18
   855  * Since: 0.10.18
   811  */
   856  */
   812 #ifdef __SYMBIAN32__
   857 #ifdef __SYMBIAN32__
   813 EXPORT_C
   858 EXPORT_C
   814 #endif
   859 #endif
   815  gboolean gst_poll_fd_ctl_read (GstPoll * set, GstPollFD * fd, gboolean active)
   860 
       
   861 gboolean
       
   862 gst_poll_fd_ctl_read (GstPoll * set, GstPollFD * fd, gboolean active)
   816 {
   863 {
   817   gboolean ret;
   864   gboolean ret;
   818 
   865 
   819   g_return_val_if_fail (set != NULL, FALSE);
   866   g_return_val_if_fail (set != NULL, FALSE);
   820   g_return_val_if_fail (fd != NULL, FALSE);
   867   g_return_val_if_fail (fd != NULL, FALSE);
   847  */
   894  */
   848 #ifdef __SYMBIAN32__
   895 #ifdef __SYMBIAN32__
   849 EXPORT_C
   896 EXPORT_C
   850 #endif
   897 #endif
   851 
   898 
   852  void gst_poll_fd_ignored (GstPoll * set, GstPollFD * fd)
   899 void
       
   900 gst_poll_fd_ignored (GstPoll * set, GstPollFD * fd)
   853 {
   901 {
   854 #ifdef G_OS_WIN32
   902 #ifdef G_OS_WIN32
   855   gint idx;
   903   gint idx;
   856 
   904 
   857   g_return_if_fail (set != NULL);
   905   g_return_if_fail (set != NULL);
   884  */
   932  */
   885 #ifdef __SYMBIAN32__
   933 #ifdef __SYMBIAN32__
   886 EXPORT_C
   934 EXPORT_C
   887 #endif
   935 #endif
   888 
   936 
   889  gboolean gst_poll_fd_has_closed (const GstPoll * set, GstPollFD * fd)
   937 gboolean
       
   938 gst_poll_fd_has_closed (const GstPoll * set, GstPollFD * fd)
   890 {
   939 {
   891   gboolean res = FALSE;
   940   gboolean res = FALSE;
   892   gint idx;
   941   gint idx;
   893 
   942 
   894   g_return_val_if_fail (set != NULL, FALSE);
   943   g_return_val_if_fail (set != NULL, FALSE);
   957     WinsockFd *wfd = &g_array_index (set->active_fds, WinsockFd, idx);
  1006     WinsockFd *wfd = &g_array_index (set->active_fds, WinsockFd, idx);
   958 
  1007 
   959     res = (wfd->events.iErrorCode[FD_CLOSE_BIT] != 0) ||
  1008     res = (wfd->events.iErrorCode[FD_CLOSE_BIT] != 0) ||
   960         (wfd->events.iErrorCode[FD_READ_BIT] != 0) ||
  1009         (wfd->events.iErrorCode[FD_READ_BIT] != 0) ||
   961         (wfd->events.iErrorCode[FD_WRITE_BIT] != 0) ||
  1010         (wfd->events.iErrorCode[FD_WRITE_BIT] != 0) ||
   962         (wfd->events.iErrorCode[FD_ACCEPT_BIT] != 0);
  1011         (wfd->events.iErrorCode[FD_ACCEPT_BIT] != 0) ||
       
  1012         (wfd->events.iErrorCode[FD_CONNECT_BIT] != 0);
   963 #endif
  1013 #endif
   964   }
  1014   }
   965 
  1015 
   966   g_mutex_unlock (set->lock);
  1016   g_mutex_unlock (set->lock);
   967 
  1017 
  1004  */
  1054  */
  1005 #ifdef __SYMBIAN32__
  1055 #ifdef __SYMBIAN32__
  1006 EXPORT_C
  1056 EXPORT_C
  1007 #endif
  1057 #endif
  1008 
  1058 
  1009 gboolean gst_poll_fd_can_read (const GstPoll * set, GstPollFD * fd)
  1059 gboolean
       
  1060 gst_poll_fd_can_read (const GstPoll * set, GstPollFD * fd)
  1010 {
  1061 {
  1011   gboolean res = FALSE;
  1062   gboolean res = FALSE;
  1012 
  1063 
  1013   g_return_val_if_fail (set != NULL, FALSE);
  1064   g_return_val_if_fail (set != NULL, FALSE);
  1014   g_return_val_if_fail (fd != NULL, FALSE);
  1065   g_return_val_if_fail (fd != NULL, FALSE);
  1036  */
  1087  */
  1037 #ifdef __SYMBIAN32__
  1088 #ifdef __SYMBIAN32__
  1038 EXPORT_C
  1089 EXPORT_C
  1039 #endif
  1090 #endif
  1040 
  1091 
  1041 gboolean gst_poll_fd_can_write (const GstPoll * set, GstPollFD * fd)
  1092 gboolean
       
  1093 gst_poll_fd_can_write (const GstPoll * set, GstPollFD * fd)
  1042 {
  1094 {
  1043   gboolean res = FALSE;
  1095   gboolean res = FALSE;
  1044   gint idx;
  1096   gint idx;
  1045 
  1097 
  1046   g_return_val_if_fail (set != NULL, FALSE);
  1098   g_return_val_if_fail (set != NULL, FALSE);
  1111  * @timeout: a timeout in nanoseconds.
  1163  * @timeout: a timeout in nanoseconds.
  1112  *
  1164  *
  1113  * Wait for activity on the file descriptors in @set. This function waits up to
  1165  * Wait for activity on the file descriptors in @set. This function waits up to
  1114  * the specified @timeout.  A timeout of #GST_CLOCK_TIME_NONE waits forever.
  1166  * the specified @timeout.  A timeout of #GST_CLOCK_TIME_NONE waits forever.
  1115  *
  1167  *
  1116  * When this function is called from multiple threads, -1 will be returned with
  1168  * For #GstPoll objects created with gst_poll_new(), this function can only be
  1117  * errno set to EPERM.
  1169  * called from a single thread at a time.  If called from multiple threads,
       
  1170  * -1 will be returned with errno set to EPERM.
       
  1171  *
       
  1172  * This is not true for timer #GstPoll objects created with
       
  1173  * gst_poll_new_timer(), where it is allowed to have multiple threads waiting
       
  1174  * simultaneously.
  1118  *
  1175  *
  1119  * Returns: The number of #GstPollFD in @set that have activity or 0 when no
  1176  * Returns: The number of #GstPollFD in @set that have activity or 0 when no
  1120  * activity was detected after @timeout. If an error occurs, -1 is returned
  1177  * activity was detected after @timeout. If an error occurs, -1 is returned
  1121  * and errno is set.
  1178  * and errno is set.
  1122  *
  1179  *
  1124  */
  1181  */
  1125 #ifdef __SYMBIAN32__
  1182 #ifdef __SYMBIAN32__
  1126 EXPORT_C
  1183 EXPORT_C
  1127 #endif
  1184 #endif
  1128 
  1185 
  1129 gint gst_poll_wait (GstPoll * set, GstClockTime timeout)
  1186 gint
       
  1187 gst_poll_wait (GstPoll * set, GstClockTime timeout)
  1130 {
  1188 {
  1131   gboolean restarting;
  1189   gboolean restarting;
  1132   int res = -1;
  1190   int res;
  1133 
  1191 
  1134   g_return_val_if_fail (set != NULL, -1);
  1192   g_return_val_if_fail (set != NULL, -1);
  1135 
  1193 
  1136   g_mutex_lock (set->lock);
  1194   g_mutex_lock (set->lock);
  1137 
  1195 
  1138   /* we cannot wait from multiple threads */
  1196   /* we cannot wait from multiple threads unless we are a timer */
  1139   if (set->waiting)
  1197   if (G_UNLIKELY (set->waiting > 0 && !set->timer))
  1140     goto already_waiting;
  1198     goto already_waiting;
  1141 
  1199 
  1142   /* flushing, exit immediatly */
  1200   /* flushing, exit immediatly */
  1143   if (set->flushing)
  1201   if (G_UNLIKELY (set->flushing))
  1144     goto flushing;
  1202     goto flushing;
  1145 
  1203 
  1146   set->waiting = TRUE;
  1204   /* add one more waiter */
       
  1205   set->waiting++;
  1147 
  1206 
  1148   do {
  1207   do {
  1149     GstPollMode mode;
  1208     GstPollMode mode;
  1150 
  1209 
  1151     res = -1;
  1210     res = -1;
  1238             GST_TIME_TO_TIMEVAL (timeout, tv);
  1297             GST_TIME_TO_TIMEVAL (timeout, tv);
  1239             tvptr = &tv;
  1298             tvptr = &tv;
  1240           } else {
  1299           } else {
  1241             tvptr = NULL;
  1300             tvptr = NULL;
  1242           }
  1301           }
  1243 //temporary  fix for multifdsink  
  1302 	  
  1244           FD_ZERO(&excepfds);
  1303           FD_ZERO(&excepfds);
  1245          
  1304          
  1246         if( max_fd != -1)
  1305         if( max_fd != -1)
  1247          {
  1306          {
  1248           if( ! FD_ISSET(max_fd,&readfds))
  1307           if( ! FD_ISSET(max_fd,&readfds))
  1330       }
  1389       }
  1331     }
  1390     }
  1332 
  1391 
  1333     g_mutex_lock (set->lock);
  1392     g_mutex_lock (set->lock);
  1334 
  1393 
  1335     gst_poll_check_ctrl_commands (set, res, &restarting);
  1394     if (!set->timer)
       
  1395       gst_poll_check_ctrl_commands (set, res, &restarting);
  1336 
  1396 
  1337     /* update the controllable state if needed */
  1397     /* update the controllable state if needed */
  1338     set->controllable = set->new_controllable;
  1398     set->controllable = set->new_controllable;
  1339 
  1399 
  1340     if (set->flushing) {
  1400     if (G_UNLIKELY (set->flushing)) {
  1341       /* we got woken up and we are flushing, we need to stop */
  1401       /* we got woken up and we are flushing, we need to stop */
  1342       errno = EBUSY;
  1402       errno = EBUSY;
  1343       res = -1;
  1403       res = -1;
  1344       break;
  1404       break;
  1345     }
  1405     }
  1346   } while (restarting);
  1406   } while (G_UNLIKELY (restarting));
  1347 
  1407 
  1348   set->waiting = FALSE;
  1408   set->waiting--;
  1349 
  1409 
  1350   g_mutex_unlock (set->lock);
  1410   g_mutex_unlock (set->lock);
  1351 
  1411 
  1352   return res;
  1412   return res;
  1353 
  1413 
  1365     return -1;
  1425     return -1;
  1366   }
  1426   }
  1367 #ifdef G_OS_WIN32
  1427 #ifdef G_OS_WIN32
  1368 winsock_error:
  1428 winsock_error:
  1369   {
  1429   {
       
  1430     set->waiting--;
  1370     g_mutex_unlock (set->lock);
  1431     g_mutex_unlock (set->lock);
  1371     return -1;
  1432     return -1;
  1372   }
  1433   }
  1373 #endif
  1434 #endif
  1374 }
  1435 }
  1388  */
  1449  */
  1389 #ifdef __SYMBIAN32__
  1450 #ifdef __SYMBIAN32__
  1390 EXPORT_C
  1451 EXPORT_C
  1391 #endif
  1452 #endif
  1392 
  1453 
  1393 gboolean gst_poll_set_controllable (GstPoll * set, gboolean controllable)
  1454 gboolean
       
  1455 gst_poll_set_controllable (GstPoll * set, gboolean controllable)
  1394 {
  1456 {
  1395   g_return_val_if_fail (set != NULL, FALSE);
  1457   g_return_val_if_fail (set != NULL, FALSE);
  1396 
  1458 
  1397   g_mutex_lock (set->lock);
  1459   g_mutex_lock (set->lock);
  1398 
  1460 
  1401     gint control_sock[2];
  1463     gint control_sock[2];
  1402 /* rj
  1464 /* rj
  1403     if (socketpair (PF_UNIX, SOCK_STREAM, 0, control_sock) < 0)
  1465     if (socketpair (PF_UNIX, SOCK_STREAM, 0, control_sock) < 0)
  1404       goto no_socket_pair;
  1466       goto no_socket_pair;
  1405 */
  1467 */
       
  1468     pipe(control_sock);
  1406     fcntl (control_sock[0], F_SETFL, O_NONBLOCK);
  1469     fcntl (control_sock[0], F_SETFL, O_NONBLOCK);
  1407     fcntl (control_sock[1], F_SETFL, O_NONBLOCK);
  1470     fcntl (control_sock[1], F_SETFL, O_NONBLOCK);
  1408 
  1471 
  1409     set->control_read_fd.fd = control_sock[0];
  1472     set->control_read_fd.fd = control_sock[0];
  1410     set->control_write_fd.fd = control_sock[1];
  1473     set->control_write_fd.fd = control_sock[1];
  1416     gst_poll_fd_ctl_read_unlocked (set, &set->control_read_fd, controllable);
  1479     gst_poll_fd_ctl_read_unlocked (set, &set->control_read_fd, controllable);
  1417 #endif
  1480 #endif
  1418 
  1481 
  1419   /* delay the change of the controllable state if we are waiting */
  1482   /* delay the change of the controllable state if we are waiting */
  1420   set->new_controllable = controllable;
  1483   set->new_controllable = controllable;
  1421   if (!set->waiting)
  1484   if (set->waiting == 0)
  1422     set->controllable = controllable;
  1485     set->controllable = controllable;
  1423 
  1486 
  1424   g_mutex_unlock (set->lock);
  1487   g_mutex_unlock (set->lock);
  1425 
  1488 
  1426   return TRUE;
  1489   return TRUE;
  1448  */
  1511  */
  1449 #ifdef __SYMBIAN32__
  1512 #ifdef __SYMBIAN32__
  1450 EXPORT_C
  1513 EXPORT_C
  1451 #endif
  1514 #endif
  1452 
  1515 
  1453 void gst_poll_restart (GstPoll * set)
  1516 void
       
  1517 gst_poll_restart (GstPoll * set)
  1454 {
  1518 {
  1455   g_return_if_fail (set != NULL);
  1519   g_return_if_fail (set != NULL);
  1456 
  1520 
  1457   g_mutex_lock (set->lock);
  1521   g_mutex_lock (set->lock);
  1458 
  1522 
  1459   if (set->controllable && set->waiting) {
  1523   if (set->controllable && set->waiting > 0) {
  1460 #ifndef G_OS_WIN32
  1524 #ifndef G_OS_WIN32
       
  1525     gint result;
       
  1526 
  1461     /* if we are waiting, we can send the command, else we do not have to
  1527     /* if we are waiting, we can send the command, else we do not have to
  1462      * bother, future calls will automatically pick up the new fdset */
  1528      * bother, future calls will automatically pick up the new fdset */
  1463     SEND_COMMAND (set, GST_POLL_CMD_WAKEUP);
  1529     SEND_COMMAND (set, GST_POLL_CMD_WAKEUP, result);
  1464 #else
  1530 #else
  1465     SetEvent (set->wakeup_event);
  1531     SetEvent (set->wakeup_event);
  1466 #endif
  1532 #endif
  1467   }
  1533   }
  1468 
  1534 
  1483  */
  1549  */
  1484 #ifdef __SYMBIAN32__
  1550 #ifdef __SYMBIAN32__
  1485 EXPORT_C
  1551 EXPORT_C
  1486 #endif
  1552 #endif
  1487 
  1553 
  1488 void gst_poll_set_flushing (GstPoll * set, gboolean flushing)
  1554 void
       
  1555 gst_poll_set_flushing (GstPoll * set, gboolean flushing)
  1489 {
  1556 {
  1490   g_return_if_fail (set != NULL);
  1557   g_return_if_fail (set != NULL);
  1491 
  1558 
  1492   g_mutex_lock (set->lock);
  1559   g_mutex_lock (set->lock);
  1493 
  1560 
  1494   /* update the new state first */
  1561   /* update the new state first */
  1495   set->flushing = flushing;
  1562   set->flushing = flushing;
  1496 
  1563 
  1497   if (flushing && set->controllable && set->waiting) {
  1564   if (flushing && set->controllable && set->waiting > 0) {
  1498     /* we are flushing, controllable and waiting, wake up the waiter. When we
  1565     /* we are flushing, controllable and waiting, wake up the waiter. When we
  1499      * stop the flushing operation we don't clear the wakeup fd here, this will
  1566      * stop the flushing operation we don't clear the wakeup fd here, this will
  1500      * happen in the _wait() thread. */
  1567      * happen in the _wait() thread. */
  1501 #ifndef G_OS_WIN32
  1568 #ifndef G_OS_WIN32
  1502     SEND_COMMAND (set, GST_POLL_CMD_WAKEUP);
  1569     gint result;
       
  1570 
       
  1571     SEND_COMMAND (set, GST_POLL_CMD_WAKEUP, result);
  1503 #else
  1572 #else
  1504     SetEvent (set->wakeup_event);
  1573     SetEvent (set->wakeup_event);
  1505 #endif
  1574 #endif
  1506   }
  1575   }
  1507 
  1576 
  1508   g_mutex_unlock (set->lock);
  1577   g_mutex_unlock (set->lock);
  1509 }
  1578 }
       
  1579 
       
  1580 /**
       
  1581  * gst_poll_write_control:
       
  1582  * @set: a #GstPoll.
       
  1583  *
       
  1584  * Write a byte to the control socket of the controllable @set.
       
  1585  * This function is mostly useful for timer #GstPoll objects created with
       
  1586  * gst_poll_new_timer(). 
       
  1587  *
       
  1588  * It will make any current and future gst_poll_wait() function return with
       
  1589  * 1, meaning the control socket is set. After an equal amount of calls to
       
  1590  * gst_poll_read_control() have been performed, calls to gst_poll_wait() will
       
  1591  * block again until their timeout expired.
       
  1592  *
       
  1593  * Returns: %TRUE on success. %FALSE when @set is not controllable or when the
       
  1594  * byte could not be written.
       
  1595  *
       
  1596  * Since: 0.10.23
       
  1597  */
       
  1598 #ifdef __SYMBIAN32__
       
  1599 EXPORT_C
       
  1600 #endif
       
  1601 
       
  1602 gboolean
       
  1603 gst_poll_write_control (GstPoll * set)
       
  1604 {
       
  1605   gboolean res = FALSE;
       
  1606 
       
  1607   g_return_val_if_fail (set != NULL, FALSE);
       
  1608 
       
  1609   g_mutex_lock (set->lock);
       
  1610   if (set->controllable) {
       
  1611 #ifndef G_OS_WIN32
       
  1612     gint result;
       
  1613 
       
  1614     SEND_COMMAND (set, GST_POLL_CMD_WAKEUP, result);
       
  1615     res = (result > 0);
       
  1616 #else
       
  1617     res = SetEvent (set->wakeup_event);
       
  1618 #endif
       
  1619   }
       
  1620   g_mutex_unlock (set->lock);
       
  1621 
       
  1622   return res;
       
  1623 }
       
  1624 
       
  1625 /**
       
  1626  * gst_poll_read_control:
       
  1627  * @set: a #GstPoll.
       
  1628  *
       
  1629  * Read a byte from the control socket of the controllable @set.
       
  1630  * This function is mostly useful for timer #GstPoll objects created with
       
  1631  * gst_poll_new_timer(). 
       
  1632  *
       
  1633  * Returns: %TRUE on success. %FALSE when @set is not controllable or when there
       
  1634  * was no byte to read.
       
  1635  *
       
  1636  * Since: 0.10.23
       
  1637  */
       
  1638 #ifdef __SYMBIAN32__
       
  1639 EXPORT_C
       
  1640 #endif
       
  1641 
       
  1642 gboolean
       
  1643 gst_poll_read_control (GstPoll * set)
       
  1644 {
       
  1645   gboolean res = FALSE;
       
  1646 
       
  1647   g_return_val_if_fail (set != NULL, FALSE);
       
  1648 
       
  1649   g_mutex_lock (set->lock);
       
  1650   if (set->controllable) {
       
  1651 #ifndef G_OS_WIN32
       
  1652     guchar cmd;
       
  1653     gint result;
       
  1654     READ_COMMAND (set, cmd, result);
       
  1655     res = (result > 0);
       
  1656 #else
       
  1657     res = ResetEvent (set->wakeup_event);
       
  1658 #endif
       
  1659   }
       
  1660   g_mutex_unlock (set->lock);
       
  1661 
       
  1662   return res;
       
  1663 }