-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraw_transactions.go
More file actions
164 lines (139 loc) · 4.14 KB
/
raw_transactions.go
File metadata and controls
164 lines (139 loc) · 4.14 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
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
package camera
import (
"context"
"fmt"
fwkDevice "github.com/AndroidGoLab/binder/android/frameworks/cameraservice/device"
"github.com/AndroidGoLab/binder/binder"
"github.com/AndroidGoLab/binder/parcel"
)
// CreateStreamWithSurface creates a camera stream with the given IGBP
// stub as the surface. Uses raw parcel I/O because the generated proxy
// does not handle the native Surface/IGBP binder embedding.
func CreateStreamWithSurface(
ctx context.Context,
deviceUser fwkDevice.ICameraDeviceUser,
transport binder.Transport,
igbpStub *binder.StubBinder,
width int32,
height int32,
) (int32, error) {
data := parcel.New()
data.WriteInterfaceToken(fwkDevice.DescriptorICameraDeviceUser)
data.WriteInt32(1) // non-null OutputConfiguration
headerPos := parcel.WriteParcelableHeader(data)
data.WriteInt32(0) // windowHandles: empty array
data.WriteInt32(0) // rotation: R0
data.WriteInt32(-1) // windowGroupId: NONE
data.WriteString16("")
data.WriteInt32(width)
data.WriteInt32(height)
data.WriteBool(false) // isDeferred
// surfaces: array of 1.
data.WriteInt32(1)
data.WriteInt32(1) // non-null
// view::Surface::writeToParcel
data.WriteString16("GoCamera")
data.WriteInt32(0) // isSingleBuffered
data.WriteUint32(0x62717565) // USE_BUFFER_QUEUE
binder.WriteBinderToParcel(ctx, data, igbpStub, transport)
data.WriteNullStrongBinder() // surfaceControlHandle: null
parcel.WriteParcelableFooter(data, headerPos)
reply, err := deviceUser.AsBinder().Transact(
ctx,
fwkDevice.TransactionICameraDeviceUserCreateStream,
0,
data,
)
if err != nil {
return 0, fmt.Errorf("transaction: %w", err)
}
defer reply.Recycle()
if err = binder.ReadStatus(reply); err != nil {
return 0, fmt.Errorf("status: %w", err)
}
streamId, err := reply.ReadInt32()
if err != nil {
return 0, fmt.Errorf("readStreamId: %w", err)
}
return streamId, nil
}
// CreateDefaultRequest calls CreateDefaultRequest using raw parcel I/O.
func CreateDefaultRequest(
ctx context.Context,
deviceUser fwkDevice.ICameraDeviceUser,
templateId fwkDevice.TemplateId,
) ([]byte, error) {
data := parcel.New()
data.WriteInterfaceToken(fwkDevice.DescriptorICameraDeviceUser)
data.WriteInt32(int32(templateId))
reply, err := deviceUser.AsBinder().Transact(
ctx,
fwkDevice.TransactionICameraDeviceUserCreateDefaultRequest,
0,
data,
)
if err != nil {
return nil, fmt.Errorf("transaction: %w", err)
}
defer reply.Recycle()
if err = binder.ReadStatus(reply); err != nil {
return nil, fmt.Errorf("status: %w", err)
}
nullInd, err := reply.ReadInt32()
if err != nil {
return nil, fmt.Errorf("null indicator: %w", err)
}
if nullInd == 0 {
return nil, fmt.Errorf("null metadata")
}
endPos, err := parcel.ReadParcelableHeader(reply)
if err != nil {
return nil, fmt.Errorf("parcelable header: %w", err)
}
metadataBytes, err := reply.ReadByteArray()
if err != nil {
return nil, fmt.Errorf("ReadByteArray: %w", err)
}
parcel.SkipToParcelableEnd(reply, endPos)
return metadataBytes, nil
}
// SubmitRequest sends a SubmitRequestList using raw parcel I/O.
func SubmitRequest(
ctx context.Context,
deviceUser fwkDevice.ICameraDeviceUser,
captureReq fwkDevice.CaptureRequest,
isRepeating bool,
) (fwkDevice.SubmitInfo, error) {
var result fwkDevice.SubmitInfo
data := parcel.New()
data.WriteInterfaceToken(fwkDevice.DescriptorICameraDeviceUser)
data.WriteInt32(1) // requestList: array of 1
data.WriteInt32(1) // non-null indicator
if err := captureReq.MarshalParcel(data); err != nil {
return result, fmt.Errorf("marshal: %w", err)
}
data.WriteBool(isRepeating)
reply, err := deviceUser.AsBinder().Transact(
ctx,
fwkDevice.TransactionICameraDeviceUserSubmitRequestList,
0,
data,
)
if err != nil {
return result, fmt.Errorf("transaction: %w", err)
}
defer reply.Recycle()
if err = binder.ReadStatus(reply); err != nil {
return result, fmt.Errorf("status: %w", err)
}
nullInd, err := reply.ReadInt32()
if err != nil {
return result, fmt.Errorf("null indicator: %w", err)
}
if nullInd != 0 {
if err = result.UnmarshalParcel(reply); err != nil {
return result, fmt.Errorf("unmarshal SubmitInfo: %w", err)
}
}
return result, nil
}