-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice.go
More file actions
83 lines (70 loc) · 2.54 KB
/
device.go
File metadata and controls
83 lines (70 loc) · 2.54 KB
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
// Code generated by idiomgen. DO NOT EDIT.
package camera
import (
"unsafe"
capi "github.com/AndroidGoLab/ndk/capi/camera"
)
// Device wraps the NDK ACameraDevice handle.
type Device struct {
ptr *capi.ACameraDevice
}
// cptr returns the underlying C pointer, or nil if h is nil.
// This allows passing optional (nullable) handle parameters to capi functions.
func (h *Device) cptr() *capi.ACameraDevice {
if h == nil {
return nil
}
return h.ptr
}
// Close releases the underlying NDK handle.
func (h *Device) Close() error {
if h.ptr == nil {
return nil
}
err := result(capi.ACameraDevice_close(h.ptr))
h.ptr = nil
return err
}
// NewDeviceFromPointer wraps a raw ACameraDevice pointer.
func NewDeviceFromPointer(ptr unsafe.Pointer) *Device {
return &Device{ptr: (*capi.ACameraDevice)(ptr)}
}
// Pointer returns the underlying pointer as unsafe.Pointer.
func (h *Device) Pointer() unsafe.Pointer {
return unsafe.Pointer(h.ptr)
}
// UintPtr returns the underlying pointer as a uintptr.
// This is useful for interop with gomobile bind, golang.org/x/mobile,
// gioui.org, and other packages that represent native handles as uintptr.
func (h *Device) UintPtr() uintptr {
return uintptr(unsafe.Pointer(h.ptr))
}
// NewDeviceFromUintPtr wraps a uintptr as a Device.
// The caller must ensure ptr points to a valid ACameraDevice.
func NewDeviceFromUintPtr(ptr uintptr) *Device {
return &Device{ptr: (*capi.ACameraDevice)(unsafe.Pointer(ptr))}
}
// CreateCaptureRequest creates a new CaptureRequest from this Device.
func (h *Device) CreateCaptureRequest(templateID TemplateType) (*CaptureRequest, error) {
var ptr *capi.ACaptureRequest
if err := result(capi.ACameraDevice_createCaptureRequest(h.ptr, capi.ACameraDevice_request_template(templateID), &ptr)); err != nil {
return nil, err
}
return &CaptureRequest{ptr: ptr}, nil
}
// CreateCaptureSession creates a new CaptureSession from this Device.
func (h *Device) CreateCaptureSession(outputs *SessionOutputContainer, cbs SessionStateCallbacks) (*CaptureSession, error) {
cbID := capi.BridgeRegisterSessionStateCallbacks(cbs)
var cbsC capi.ACameraCaptureSession_stateCallbacks
capi.BridgeInitSessionStateCallbacks(&cbsC, cbID)
var ptr *capi.ACameraCaptureSession
if err := result(capi.ACameraDevice_createCaptureSession(h.ptr, outputs.cptr(), &cbsC, &ptr)); err != nil {
capi.BridgeUnregisterSessionStateCallbacks(cbID)
return nil, err
}
return &CaptureSession{ptr: ptr}, nil
}
// GetID returns the value directly.
func (h *Device) GetID() string {
return (string)(capi.ACameraDevice_getId(h.ptr))
}