-
Notifications
You must be signed in to change notification settings - Fork 34
/
bus.go
91 lines (69 loc) · 1.59 KB
/
bus.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
package gst
/*
#cgo pkg-config: gstreamer-1.0
#include "gst.h"
*/
import "C"
import (
"fmt"
"runtime"
"time"
)
type Bus struct {
C *C.GstBus
}
func (b *Bus) Pop() (message *Message) {
CGstMessage := C.gst_bus_pop(b.C)
message = &Message{
C: CGstMessage,
}
runtime.SetFinalizer(message, func(message *Message) {
C.gst_message_unref(message.C)
})
return
}
func (b *Bus) PopTimed() (message *Message, err error) {
var timeNone int64 = C.GST_CLOCK_TIME_NONE
CGstMessage := C.gst_bus_timed_pop(b.C, C.ulonglong(timeNone))
if CGstMessage == nil {
// Timeout hit, no message
err = fmt.Errorf("no message in bus")
return
}
message = &Message{
C: CGstMessage,
}
runtime.SetFinalizer(message, func(message *Message) {
C.gst_message_unref(message.C)
})
return
}
func (b *Bus) Pull(messageType MessageType) (message *Message) {
CGstMessage := C.gst_bus_poll(b.C, C.GstMessageType(messageType), 18446744073709551615)
if CGstMessage == nil {
return nil
}
message = &Message{
C: CGstMessage,
}
runtime.SetFinalizer(message, func(message *Message) {
C.gst_message_unref(message.C)
})
return
}
func (b *Bus) TimedPopFiltered(timeout time.Duration, messageType MessageType) (message *Message) {
CGstMessage := C.gst_bus_timed_pop_filtered(b.C, C.GstClockTime(uint64(timeout)), C.GstMessageType(messageType))
if CGstMessage == nil {
return nil
}
message = &Message{
C: CGstMessage,
}
runtime.SetFinalizer(message, func(message *Message) {
C.gst_message_unref(message.C)
})
return
}
func (b *Bus) HavePending() bool {
return C.gst_bus_have_pending(b.C) != 0
}