blob: 8480a0a3dbd337864d669071eac097cae46db684
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 | |
19 | #ifndef AVUTIL_THREADMESSAGE_H |
20 | #define AVUTIL_THREADMESSAGE_H |
21 | |
22 | typedef struct AVThreadMessageQueue AVThreadMessageQueue; |
23 | |
24 | typedef enum AVThreadMessageFlags { |
25 | |
26 | /** |
27 | * Perform non-blocking operation. |
28 | * If this flag is set, send and recv operations are non-blocking and |
29 | * return AVERROR(EAGAIN) immediately if they can not proceed. |
30 | */ |
31 | AV_THREAD_MESSAGE_NONBLOCK = 1, |
32 | |
33 | } AVThreadMessageFlags; |
34 | |
35 | /** |
36 | * Allocate a new message queue. |
37 | * |
38 | * @param mq pointer to the message queue |
39 | * @param nelem maximum number of elements in the queue |
40 | * @param elsize size of each element in the queue |
41 | * @return >=0 for success; <0 for error, in particular AVERROR(ENOSYS) if |
42 | * lavu was built without thread support |
43 | */ |
44 | int av_thread_message_queue_alloc(AVThreadMessageQueue **mq, |
45 | unsigned nelem, |
46 | unsigned elsize); |
47 | |
48 | /** |
49 | * Free a message queue. |
50 | * |
51 | * The message queue must no longer be in use by another thread. |
52 | */ |
53 | void av_thread_message_queue_free(AVThreadMessageQueue **mq); |
54 | |
55 | /** |
56 | * Send a message on the queue. |
57 | */ |
58 | int av_thread_message_queue_send(AVThreadMessageQueue *mq, |
59 | void *msg, |
60 | unsigned flags); |
61 | |
62 | /** |
63 | * Receive a message from the queue. |
64 | */ |
65 | int av_thread_message_queue_recv(AVThreadMessageQueue *mq, |
66 | void *msg, |
67 | unsigned flags); |
68 | |
69 | /** |
70 | * Set the sending 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_send(AVThreadMessageQueue *mq, |
78 | 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, |
89 | int err); |
90 | |
91 | /** |
92 | * Set the optional free message callback function which will be called if an |
93 | * operation is removing messages from the queue. |
94 | */ |
95 | void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq, |
96 | void (*free_func)(void *msg)); |
97 | |
98 | /** |
99 | * Flush the message queue |
100 | * |
101 | * This function is mostly equivalent to reading and free-ing every message |
102 | * except that it will be done in a single operation (no lock/unlock between |
103 | * reads). |
104 | */ |
105 | void av_thread_message_flush(AVThreadMessageQueue *mq); |
106 | |
107 | #endif /* AVUTIL_THREADMESSAGE_H */ |
108 |