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 module ffmpeg.libavutil.threadmessage; 19 extern (C) @nogc nothrow: 20 21 struct AVThreadMessageQueue; 22 23 enum AVThreadMessageFlags 24 { 25 /** 26 * Perform non-blocking operation. 27 * If this flag is set, send and recv operations are non-blocking and 28 * return AVERROR(EAGAIN) immediately if they can not proceed. 29 */ 30 AV_THREAD_MESSAGE_NONBLOCK = 1 31 } 32 33 /** 34 * Allocate a new message queue. 35 * 36 * @param mq pointer to the message queue 37 * @param nelem maximum number of elements in the queue 38 * @param elsize size of each element in the queue 39 * @return >=0 for success; <0 for error, in particular AVERROR(ENOSYS) if 40 * lavu was built without thread support 41 */ 42 int av_thread_message_queue_alloc ( 43 AVThreadMessageQueue** mq, 44 uint nelem, 45 uint elsize); 46 47 /** 48 * Free a message queue. 49 * 50 * The message queue must no longer be in use by another thread. 51 */ 52 void av_thread_message_queue_free (AVThreadMessageQueue** mq); 53 54 /** 55 * Send a message on the queue. 56 */ 57 int av_thread_message_queue_send ( 58 AVThreadMessageQueue* mq, 59 void* msg, 60 uint flags); 61 62 /** 63 * Receive a message from the queue. 64 */ 65 int av_thread_message_queue_recv ( 66 AVThreadMessageQueue* mq, 67 void* msg, 68 uint flags); 69 70 /** 71 * Set the sending error code. 72 * 73 * If the error code is set to non-zero, av_thread_message_queue_send() will 74 * return it immediately. Conventional values, such as AVERROR_EOF or 75 * AVERROR(EAGAIN), can be used to cause the sending thread to stop or 76 * suspend its operation. 77 */ 78 void av_thread_message_queue_set_err_send (AVThreadMessageQueue* mq, int err); 79 80 /** 81 * Set the receiving error code. 82 * 83 * If the error code is set to non-zero, av_thread_message_queue_recv() will 84 * return it immediately when there are no longer available messages. 85 * Conventional values, such as AVERROR_EOF or AVERROR(EAGAIN), can be used 86 * to cause the receiving thread to stop or suspend its operation. 87 */ 88 void av_thread_message_queue_set_err_recv (AVThreadMessageQueue* mq, int err); 89 90 /** 91 * Set the optional free message callback function which will be called if an 92 * operation is removing messages from the queue. 93 */ 94 void av_thread_message_queue_set_free_func ( 95 AVThreadMessageQueue* mq, 96 void function (void* msg) free_func); 97 98 /** 99 * Return the current number of messages in the queue. 100 * 101 * @return the current number of messages or AVERROR(ENOSYS) if lavu was built 102 * without thread support 103 */ 104 int av_thread_message_queue_nb_elems (AVThreadMessageQueue* mq); 105 106 /** 107 * Flush the message queue 108 * 109 * This function is mostly equivalent to reading and free-ing every message 110 * except that it will be done in a single operation (no lock/unlock between 111 * reads). 112 */ 113 void av_thread_message_flush (AVThreadMessageQueue* mq); 114 115 /* AVUTIL_THREADMESSAGE_H */