threadmessage.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_recv() will
  63. * return it immediately when there are no longer available messages.
  64. * Conventional values, such as AVERROR_EOF or AVERROR(EAGAIN), can be used
  65. * to cause the receiving thread to stop or 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_send() will
  73. * return it immediately. Conventional values, such as AVERROR_EOF or
  74. * AVERROR(EAGAIN), can be used to cause the sending thread to stop or
  75. * suspend its operation.
  76. */
  77. void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
  78. int err);
  79. #endif /* AVUTIL_THREADMESSAGE_H */