-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
port.go
187 lines (150 loc) · 3.81 KB
/
port.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright 2017 The go-mmal Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mmal
/*
#include <interface/mmal/mmal_port.h>
*/
import "C"
import "unsafe"
type PortType C.MMAL_PORT_TYPE_T
const (
PortTypeUnknown PortType = iota
PortTypeControl
PortTypeInput
PortTypeOutput
PortTypeClock
PortTypeInvalid = 0xffffffff
)
const (
PortCapabilityPassthrough = 0x01
PortCapabilityAllocation = 0x02
PortCapabilitySupportsEventFormatChange = 0x04
)
type Port struct {
c *C.MMAL_PORT_T
}
func (p Port) Priv() PortPrivateType {
return PortPrivateType{p.c.priv}
}
func (p Port) Name() string {
return C.GoString(p.c.name)
}
func (p Port) Type() PortType {
return PortType(p.c._type)
}
func (p Port) Index() uint16 {
return uint16(p.c.index)
}
func (p Port) IndexAll() uint16 {
return uint16(p.c.index_all)
}
func (p Port) IsEnabled() uint32 {
return uint32(p.c.is_enabled)
}
func (p Port) Format() EsFormat {
return EsFormat{p.c.format}
}
func (p Port) BufferNumMin() uint32 {
return uint32(p.c.buffer_num_min)
}
func (p Port) BufferSizeMin() uint32 {
return uint32(p.c.buffer_size_min)
}
func (p Port) BufferAlignmentMin() uint32 {
return uint32(p.c.buffer_alignment_min)
}
func (p Port) BufferNumRecommended() uint32 {
return uint32(p.c.buffer_num_recommended)
}
func (p Port) BufferSizeRecommended() uint32 {
return uint32(p.c.buffer_size_recommended)
}
func (p Port) BufferNum() uint32 {
return uint32(p.c.buffer_num)
}
func (p Port) BufferSize() uint32 {
return uint32(p.c.buffer_size)
}
func (p Port) Component() ComponentType {
return ComponentType{p.c.component}
}
type PortUserdataType struct {
c *C.struct_MMAL_PORT_USERDATA_T
}
func (p Port) Userdata() PortUserdataType {
return PortUserdataType{p.c.userdata}
}
func (p Port) Capabilities() uint32 {
return uint32(p.c.capabilities)
}
func PortFormatCommit(port *Port) error {
if err := Status(C.mmal_port_format_commit(port.c)); err != Success {
return err
}
return nil
}
type PortBHCBType C.MMAL_PORT_BH_CB_T
func PortEnable(port Port, cb PortBHCBType) error {
if err := Status(C.mmal_port_enable(port.c, cb)); err != Success {
return err
}
return nil
}
func PortDisable(port *Port) error {
if err := Status(C.mmal_port_disable(port.c)); err != Success {
return err
}
return nil
}
func PortFlush(port *Port) error {
if err := Status(C.mmal_port_flush(port.c)); err != Success {
return err
}
return nil
}
func PortParameterSet(port *Port, param ParameterHeader) error {
if err := Status(C.mmal_port_parameter_set(port.c, ¶m.c)); err != Success {
return err
}
return nil
}
func PortParameterGet(port *Port, param ParameterHeader) error {
if err := Status(C.mmal_port_parameter_get(port.c, ¶m.c)); err != Success {
return err
}
return nil
}
func PortSendBuffer(port *Port, buffer BufferHeader) error {
if err := Status(C.mmal_port_send_buffer(port.c, buffer.c)); err != Success {
return err
}
return nil
}
func PortConnect(port, otherPort *Port) error {
if err := Status(C.mmal_port_connect(port.c, otherPort.c)); err != Success {
return err
}
return nil
}
func PortDisconnect(port *Port) error {
if err := Status(C.mmal_port_disconnect(port.c)); err != Success {
return err
}
return nil
}
// TODO(zchee): return type (*C.uint8)
func PortPayloadAlloc(port *Port, payloadSize uint32) unsafe.Pointer {
res := C.mmal_port_payload_alloc(port.c, C.uint32_t(payloadSize))
return unsafe.Pointer(res)
}
func PortPayloadFree(port *Port, payload *uint8) {
p := C.uint8_t(*payload)
C.mmal_port_payload_free(port.c, &p)
}
func PortEventGet(port *Port, buffer *BufferHeader, event uint32) error {
if err := Status(C.mmal_port_event_get(port.c, &buffer.c, C.uint32_t(event))); err != Success {
return err
}
return nil
}