threadmessage.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public License
  6. * as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVUTIL_THREADMESSAGE_H
  19. #define AVUTIL_THREADMESSAGE_H
  20. typedef struct AVThreadMessageQueue AVThreadMessageQueue;
  21. typedef enum AVThreadMessageFlags {
  22. /**
  23. * Perform non-blocking operation.
  24. * If this flag is set, send and recv operations are non-blocking and
  25. * return AVERROR(EAGAIN) immediately if they can not proceed.
  26. */
  27. AV_THREAD_MESSAGE_NONBLOCK = 1,
  28. } AVThreadMessageFlags;
  29. /**
  30. * Allocate a new message queue.
  31. *
  32. * @param mq pointer to the message queue
  33. * @param nelem maximum number of elements in the queue
  34. * @param elsize size of each element in the queue
  35. * @return >=0 for success; <0 for error, in particular AVERROR(ENOSYS) if
  36. * lavu was built without thread support
  37. */
  38. int av_thread_message_queue_alloc(AVThreadMessageQueue **mq,
  39. unsigned nelem,
  40. unsigned elsize);
  41. /**
  42. * Free a message queue.
  43. *
  44. * The message queue must no longer be in use by another thread.
  45. */
  46. void av_thread_message_queue_free(AVThreadMessageQueue **mq);
  47. /**
  48. * Send a message on the queue.
  49. */
  50. int av_thread_message_queue_send(AVThreadMessageQueue *mq,
  51. void *msg,
  52. unsigned flags);
  53. /**
  54. * Receive a message from the queue.
  55. */
  56. int av_thread_message_queue_recv(AVThreadMessageQueue *mq,
  57. void *msg,
  58. unsigned flags);
  59. /**
  60. * Set the sending error code.
  61. *
  62. * If the error code is set to non-zero, av_thread_message_queue_send() will
  63. * return it immediately. Conventional values, such as AVERROR_EOF or
  64. * AVERROR(EAGAIN), can be used to cause the sending thread to stop or
  65. * suspend its operation.
  66. */
  67. void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq,
  68. int err);
  69. /**
  70. * Set the receiving error code.
  71. *
  72. * If the error code is set to non-zero, av_thread_message_queue_recv() will
  73. * return it immediately when there are no longer available messages.
  74. * Conventional values, such as AVERROR_EOF or AVERROR(EAGAIN), can be used
  75. * to cause the receiving thread to stop or suspend its operation.
  76. */
  77. void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
  78. int err);
  79. /**
  80. * Set the optional free message callback function which will be called if an
  81. * operation is removing messages from the queue.
  82. */
  83. void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
  84. void (*free_func)(void *msg));
  85. /**
  86. * Return the current number of messages in the queue.
  87. *
  88. * @return the current number of messages or AVERROR(ENOSYS) if lavu was built
  89. * without thread support
  90. */
  91. int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq);
  92. /**
  93. * Flush the message queue
  94. *
  95. * This function is mostly equivalent to reading and free-ing every message
  96. * except that it will be done in a single operation (no lock/unlock between
  97. * reads).
  98. */
  99. void av_thread_message_flush(AVThreadMessageQueue *mq);
  100. #endif /* AVUTIL_THREADMESSAGE_H */