-
Notifications
You must be signed in to change notification settings - Fork 0
/
libavutil_threadmessage.go
159 lines (135 loc) · 5.1 KB
/
libavutil_threadmessage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package ffmpeg
//#cgo pkg-config: libavutil
//#include "libavutil/threadmessage.h"
import "C"
import (
"syscall"
"unsafe"
)
type AVThreadMessageQueue struct {
}
type AVThreadMessageFlags int32
const (
AV_THREAD_MESSAGE_NONBLOCK AVThreadMessageFlags = 1 + iota
)
/**
* Allocate a new message queue.
*
* @param mq pointer to the message queue
* @param nelem maximum number of elements in the queue
* @param elsize size of each element in the queue
* @return >=0 for success; <0 for error, in particular AVERROR(ENOSYS) if
* lavu was built without thread support
*/
func Av_thread_message_queue_alloc(mq **AVThreadMessageQueue,
nelem uint32,
elsize uint32) int32 {
return int32(C.av_thread_message_queue_alloc(
(**C.struct_AVThreadMessageQueue)(unsafe.Pointer(mq)), C.unsigned(nelem),
C.unsigned(elsize)))
}
/**
* Free a message queue.
*
* The message queue must no longer be in use by another thread.
*/
func Av_thread_message_queue_free(mq **AVThreadMessageQueue) {
C.av_thread_message_queue_free(
(**C.struct_AVThreadMessageQueue)(unsafe.Pointer(mq)))
}
/**
* Send a message on the queue.
*/
func Av_thread_message_queue_send(mq *AVThreadMessageQueue,
msg unsafe.Pointer,
flags uint32) int32 {
return int32(C.av_thread_message_queue_send(
(*C.struct_AVThreadMessageQueue)(unsafe.Pointer(mq)), msg,
C.unsigned(flags)))
}
/**
* Receive a message from the queue.
*/
func Av_thread_message_queue_recv(mq *AVThreadMessageQueue,
msg unsafe.Pointer,
flags uint32) int32 {
return int32(C.av_thread_message_queue_recv(
(*C.struct_AVThreadMessageQueue)(unsafe.Pointer(mq)), msg,
C.unsigned(flags)))
}
/**
* Set the sending error code.
*
* If the error code is set to non-zero, av_thread_message_queue_send() will
* return it immediately. Conventional values, such as AVERROR_EOF or
* AVERROR(EAGAIN), can be used to cause the sending thread to stop or
* suspend its operation.
*/
func Av_thread_message_queue_set_err_send(mq *AVThreadMessageQueue,
err int32) {
C.av_thread_message_queue_set_err_send(
(*C.struct_AVThreadMessageQueue)(unsafe.Pointer(mq)), C.int(err))
}
/**
* Set the receiving error code.
*
* If the error code is set to non-zero, av_thread_message_queue_recv() will
* return it immediately when there are no longer available messages.
* Conventional values, such as AVERROR_EOF or AVERROR(EAGAIN), can be used
* to cause the receiving thread to stop or suspend its operation.
*/
func Av_thread_message_queue_set_err_recv(mq *AVThreadMessageQueue,
err int32) {
C.av_thread_message_queue_set_err_recv(
(*C.struct_AVThreadMessageQueue)(unsafe.Pointer(mq)), C.int(err))
}
/**
* Set the optional free message callback function which will be called if an
* operation is removing messages from the queue.
*/
func Av_thread_message_queue_set_free_func(mq *AVThreadMessageQueue,
free_func func(msg unsafe.Pointer) ) {
cb1 := syscall.NewCallbackCDecl(free_func)
C.av_thread_message_queue_set_free_func(
(*C.struct_AVThreadMessageQueue)(unsafe.Pointer(mq)),
(*[0]byte)(unsafe.Pointer(cb1)))
}
/**
* Return the current number of messages in the queue.
*
* @return the current number of messages or AVERROR(ENOSYS) if lavu was built
* without thread support
*/
func Av_thread_message_queue_nb_elems(mq *AVThreadMessageQueue) int32 {
return int32(C.av_thread_message_queue_nb_elems(
(*C.struct_AVThreadMessageQueue)(unsafe.Pointer(mq))))
}
/**
* Flush the message queue
*
* This function is mostly equivalent to reading and free-ing every message
* except that it will be done in a single operation (no lock/unlock between
* reads).
*/
func Av_thread_message_flush(mq *AVThreadMessageQueue) {
C.av_thread_message_flush((*C.struct_AVThreadMessageQueue)(unsafe.Pointer(mq)))
}