-
Notifications
You must be signed in to change notification settings - Fork 22
/
types_audio_handler.go
136 lines (118 loc) · 3.85 KB
/
types_audio_handler.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
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package cef
import (
"github.com/energye/energy/v2/cef/internal/def"
"github.com/energye/energy/v2/common/imports"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/api"
"unsafe"
)
// ************************** creates ************************** //
// AudioHandlerRef -> ICefAudioHandler
var AudioHandlerRef audioHandler
type audioHandler uintptr
func (*audioHandler) New() *ICefAudioHandler {
var result uintptr
imports.Proc(def.CefAudioHandlerRef_Create).Call(uintptr(unsafe.Pointer(&result)))
if result != 0 {
return &ICefAudioHandler{instance: unsafe.Pointer(result)}
}
return nil
}
// ************************** impl ************************** //
// Instance 实例
func (m *ICefAudioHandler) Instance() uintptr {
if m == nil {
return 0
}
return uintptr(m.instance)
}
func (m *ICefAudioHandler) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
func (m *ICefAudioHandler) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
return m.instance != nil
}
func (m *ICefAudioHandler) SetOnGetAudioParameters(fn onGetAudioParameters) {
if !m.IsValid() {
return
}
imports.Proc(def.CefAudioHandler_OnGetAudioParameters).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefAudioHandler) SetOnAudioStreamStarted(fn onAudioStreamStarted) {
if !m.IsValid() {
return
}
imports.Proc(def.CefAudioHandler_OnAudioStreamStarted).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefAudioHandler) SetOnAudioStreamPacket(fn onAudioStreamPacket) {
if !m.IsValid() {
return
}
imports.Proc(def.CefAudioHandler_OnAudioStreamPacket).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefAudioHandler) SetOnAudioStreamStopped(fn onAudioStreamStopped) {
if !m.IsValid() {
return
}
imports.Proc(def.CefAudioHandler_OnAudioStreamStopped).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefAudioHandler) SetOnAudioStreamError(fn onAudioStreamError) {
if !m.IsValid() {
return
}
imports.Proc(def.CefAudioHandler_OnAudioStreamError).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
// ************************** events ************************** //
type onGetAudioParameters func(browser *ICefBrowser, params *TCefAudioParameters) bool
type onAudioStreamStarted func(browser *ICefBrowser, params *TCefAudioParameters, channels int32)
type onAudioStreamPacket func(browser *ICefBrowser, data *uintptr, frames int32, pts int64)
type onAudioStreamStopped func(browser *ICefBrowser)
type onAudioStreamError func(browser *ICefBrowser, message string)
func init() {
lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool {
getPtr := func(i int) unsafe.Pointer {
return unsafe.Pointer(getVal(i))
}
switch fn.(type) {
case onGetAudioParameters:
browse := &ICefBrowser{instance: getPtr(0)}
params := (*TCefAudioParameters)(getPtr(1))
result := (*bool)(getPtr(2))
*result = fn.(onGetAudioParameters)(browse, params)
case onAudioStreamStarted:
browse := &ICefBrowser{instance: getPtr(0)}
params := (*TCefAudioParameters)(getPtr(1))
fn.(onAudioStreamStarted)(browse, params, int32(getVal(2)))
case onAudioStreamPacket:
browse := &ICefBrowser{instance: getPtr(0)}
data := (*uintptr)(getPtr(1))
frames := int32(getVal(2))
pts := *(*int64)(getPtr(3))
fn.(onAudioStreamPacket)(browse, data, frames, pts)
case onAudioStreamStopped:
browse := &ICefBrowser{instance: getPtr(0)}
fn.(onAudioStreamStopped)(browse)
case onAudioStreamError:
browse := &ICefBrowser{instance: getPtr(0)}
fn.(onAudioStreamError)(browse, api.GoStr(getVal(1)))
default:
return false
}
return true
})
}