-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclock.go
222 lines (168 loc) · 4.67 KB
/
clock.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// 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.h>
#include <interface/mmal/mmal_clock.h>
extern MMAL_CLOCK_EVENT_T clock_event_init(uint32_t id) {
MMAL_CLOCK_EVENT_T event;
event.id = id;
event.magic = MMAL_CLOCK_EVENT_MAGIC;
event.buffer = NULL;
event.padding0 = 0;
// event.data = union{0};
event.padding1 = 0;
return event;
}
*/
import "C"
import (
"bytes"
"encoding/binary"
)
var (
// Clock event magic
ClockEventMagic = FourCC('C', 'K', 'L', 'M')
// Clock reference update
ClockEventReference = FourCC('C', 'R', 'E', 'F')
// Clock state update
ClockEventActive = FourCC('C', 'A', 'C', 'T')
// Clock scale update
ClockEventScale = FourCC('C', 'S', 'C', 'A')
// Clock media-time update
ClockEventTime = FourCC('C', 'T', 'I', 'M')
// Clock update threshold
ClockEventUpdateThreshold = FourCC('C', 'U', 'T', 'H')
// Clock discontinuity threshold
ClockEventDiscontThreshold = FourCC('C', 'D', 'T', 'H')
// Clock request threshold
ClockEventRequestThreshold = FourCC('C', 'R', 'T', 'H')
// Buffer statistics
ClockEventInputBufferInfo = FourCC('C', 'I', 'B', 'I')
ClockEventOutputBufferInfo = FourCC('C', 'O', 'B', 'I')
// Clock latency setting
ClockEventLatency = FourCC('C', 'L', 'A', 'T')
// Clock event not valid
ClockEventInvalid = 0
)
type ClockUpdateThreshold struct {
c C.MMAL_CLOCK_UPDATE_THRESHOLD_T
}
func (c ClockUpdateThreshold) ThreshouldLower() int64 {
return int64(c.c.threshold_lower)
}
func (c ClockUpdateThreshold) ThreshouldUpper() int64 {
return int64(c.c.threshold_upper)
}
type ClockDiscontThreshold struct {
c C.MMAL_CLOCK_DISCONT_THRESHOLD_T
}
func (c ClockDiscontThreshold) Threshold() int64 {
return int64(c.c.threshold)
}
func (c ClockDiscontThreshold) Duration() int64 {
return int64(c.c.duration)
}
type ClockRequestThreshold struct {
c C.MMAL_CLOCK_REQUEST_THRESHOLD_T
}
func (c ClockRequestThreshold) Threshold() int64 {
return int64(c.c.threshold)
}
func (c ClockRequestThreshold) ThresholdEnable() bool {
return BoolT(c.c.threshold_enable) != BoolT(0)
}
type ClockBufferInfo struct {
c C.MMAL_CLOCK_BUFFER_INFO_T
}
func (c ClockBufferInfo) TimeStamp() int64 {
return int64(c.c.time_stamp)
}
func (c ClockBufferInfo) ArrivalTime() int64 {
return int64(c.c.arrival_time)
}
type ClockLatency struct {
c C.MMAL_CLOCK_LATENCY_T
}
func (c ClockLatency) Target() int64 {
return int64(c.c.target)
}
func (c ClockLatency) AttackPeriod() int64 {
return int64(c.c.attack_period)
}
func (c ClockLatency) AttackRate() int64 {
return int64(c.c.attack_rate)
}
type ClockEvent struct {
c C.MMAL_CLOCK_EVENT_T
}
func (c ClockEvent) ID() uint32 {
return uint32(c.c.id)
}
func (c ClockEvent) Magic() uint32 {
return uint32(c.c.magic)
}
func (c ClockEvent) Buffer() BufferHeader {
return BufferHeader{c.c.buffer}
}
func (c ClockEvent) Padding0() uint32 {
return uint32(c.c.padding0)
}
func (c ClockEvent) Data() *ClockEventData {
buf := bytes.NewBuffer(c.c.data[:])
var ptr *ClockEventData
err := binary.Read(buf, binary.LittleEndian, &ptr)
if err != nil {
return nil
}
return ptr
}
func (c ClockEvent) Padding1() uint64 {
return uint64(c.c.padding1)
}
func ClockEventInit(id uint32) ClockEvent {
return ClockEvent{C.clock_event_init(C.uint32_t(id))}
}
type ClockEventData struct {
// used either for clock reference or clock stateg
enable C.MMAL_BOOL_T
// new clock scaleg
scale C.MMAL_RATIONAL_T
// new media-timeg
mediaTime C.int64_t
// media-time update thresholdg
updateThreshold C.MMAL_CLOCK_UPDATE_THRESHOLD_T
// media-time discontinuity thresholdg
discontThreshold C.MMAL_CLOCK_DISCONT_THRESHOLD_T
// client callback request thresholdg
requestThreshold C.MMAL_CLOCK_REQUEST_THRESHOLD_T
// input/output buffer informationg
buffer C.MMAL_CLOCK_BUFFER_INFO_T
// clock latency settingg
latency C.MMAL_CLOCK_LATENCY_T
}
func (c ClockEventData) Enable() bool {
return BoolT(c.enable) != BoolT(0)
}
func (c ClockEventData) Scale() Rational {
return Rational{c.scale}
}
func (c ClockEventData) MediaTime() int64 {
return int64(c.mediaTime)
}
func (c ClockEventData) UpdateThreshold() ClockUpdateThreshold {
return ClockUpdateThreshold{c.updateThreshold}
}
func (c ClockEventData) DiscontThreshold() ClockDiscontThreshold {
return ClockDiscontThreshold{c.discontThreshold}
}
func (c ClockEventData) RequestThreshold() ClockRequestThreshold {
return ClockRequestThreshold{c.requestThreshold}
}
func (c ClockEventData) Buffer() ClockBufferInfo {
return ClockBufferInfo{c.buffer}
}
func (c ClockEventData) Latency() ClockLatency {
return ClockLatency{c.latency}
}