2023-05-31 17:41:14 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// 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 (
|
2023-06-11 00:10:55 +08:00
|
|
|
"github.com/energye/energy/v2/cef/internal/def"
|
2023-05-31 18:00:34 +08:00
|
|
|
"github.com/energye/energy/v2/common/imports"
|
2023-05-31 17:41:14 +08:00
|
|
|
"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
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefAudioHandlerRef_Create).Call(uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
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
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefAudioHandler_OnGetAudioParameters).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefAudioHandler) SetOnAudioStreamStarted(fn onAudioStreamStarted) {
|
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefAudioHandler_OnAudioStreamStarted).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefAudioHandler) SetOnAudioStreamPacket(fn onAudioStreamPacket) {
|
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefAudioHandler_OnAudioStreamPacket).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefAudioHandler) SetOnAudioStreamStopped(fn onAudioStreamStopped) {
|
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefAudioHandler_OnAudioStreamStopped).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefAudioHandler) SetOnAudioStreamError(fn onAudioStreamError) {
|
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefAudioHandler_OnAudioStreamError).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ************************** 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
|
|
|
|
})
|
|
|
|
}
|