-
Notifications
You must be signed in to change notification settings - Fork 0
/
PTPTypes.py
307 lines (274 loc) · 13 KB
/
PTPTypes.py
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# -LICENSE-START-
# Copyright (c) 2020 Blackmagic Design
#
# Permission is hereby granted, free of charge, to any person or organization
# obtaining a copy of the software and accompanying documentation covered by
# this license (the "Software") to use, reproduce, display, distribute,
# execute, and transmit the Software, and to prepare derivative works of the
# Software, and to permit third-parties to whom the Software is furnished to
# do so, all subject to the following:
#
# The copyright notices in the Software and this entire statement, including
# the above license grant, this restriction and the following disclaimer,
# must be included in all copies of the Software, in whole or in part, and
# all derivative works of the Software, unless such copies or derivative
# works are solely in the form of machine-executable object code generated by
# a source language processor.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
# FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# -LICENSE-END-
import fixedint
from BaseEnum import *
TransactionID = fixedint.UInt32
InterfaceClass = fixedint.UInt16
InterfaceSubClass = fixedint.UInt16
class PTPTypes:
# Data types
ptp_fixed_t = fixedint.Int16
kUSBInterfaceClass = InterfaceClass(0x06)
kUSBInterfaceSubClass = InterfaceSubClass(0x01)
kInvalidSessionId = 0
kMaxPacketSize = 1024
kContainerHeaderSize = 12
kMaxPayloadSize = kMaxPacketSize - kContainerHeaderSize
kInvalidCaptureTransactionId = TransactionID(0)
kIndependentEventTransactionId = TransactionID(0xFFFFFFFF)
kMaxCaptureTransactionId = TransactionID(0xFFFFFFFE)
def PTPFixedFromFloat(f):
return PTPTypes.ptp_fixed_t(f * 2048.0)
def PTPFloatFromFixed(f):
return float(f / 2048.0)
# For general information about PTP datacodes, see PIMA 15470, 5.2.1.
# PIMA 15470, 10.3, Table 18
OperationCodeType = fixedint.UInt16
class OperationCode(BaseEnum):
Undefined = OperationCodeType(0x1000)
GetDeviceInfo = OperationCodeType(0x1001)
OpenSession = OperationCodeType(0x1002)
CloseSession = OperationCodeType(0x1003)
GetStorageIDs = OperationCodeType(0x1004)
GetStorageInfo = OperationCodeType(0x1005)
GetNumObjects = OperationCodeType(0x1006)
GetObjectHandles = OperationCodeType(0x1007)
GetObjectInfo = OperationCodeType(0x1008)
GetObject = OperationCodeType(0x1009)
GetThumb = OperationCodeType(0x100A)
DeleteObject = OperationCodeType(0x100B)
SendObjectInfo = OperationCodeType(0x100C)
SendObject = OperationCodeType(0x100D)
InitiateCapture = OperationCodeType(0x100E)
FormatStore = OperationCodeType(0x100F)
ResetDevice = OperationCodeType(0x1010)
SelfTest = OperationCodeType(0x1011)
SetObjectProtection = OperationCodeType(0x1012)
PowerDown = OperationCodeType(0x1013)
GetDevicePropDesc = OperationCodeType(0x1014)
GetDevicePropValue = OperationCodeType(0x1015)
SetDevicePropValue = OperationCodeType(0x1016)
ResetDevicePropValue = OperationCodeType(0x1017)
TerminateOpenCapture = OperationCodeType(0x1018)
MoveObject = OperationCodeType(0x1019)
CopyObject = OperationCodeType(0x101A)
GetPartialObject = OperationCodeType(0x101B)
InitiateOpenCapture = OperationCodeType(0x101C)
# Operation Codes 0x101D - 0x8FFF are reserved.
VendorExtendedStart = OperationCodeType(0x9000)
CheckEvent = OperationCodeType(0x9001)
StartRecord = OperationCodeType(0x9010)
StopRecord = OperationCodeType(0x9011)
StillCapture = OperationCodeType(0x9012)
ChangeFocus = OperationCodeType(0x9013) # 0x1 (Inf -> Closest), 0x2 (Closest -> Inf)
InitiateAutoFocus = OperationCodeType(0x9014)
TerminateAutoFocus = OperationCodeType(0x9015)
EnableAutoExposure = OperationCodeType(0x9016)
DisableAutoExposure = OperationCodeType(0x9017)
EnableAutoWhiteBalance = OperationCodeType(0x9018)
DisableAutoWhiteBalance = OperationCodeType(0x9019)
# PIMA 15470, 11.2, Table 20
ResponseCodeType = fixedint.UInt16
class ResponseCode(BaseEnum):
Undefined = ResponseCodeType(0x2000)
OK = ResponseCodeType(0x2001)
GeneralError = ResponseCodeType(0x2002)
SessionNotOpen = ResponseCodeType(0x2003)
InvalidTransactionID = ResponseCodeType(0x2004)
OperationNotSupported = ResponseCodeType(0x2005)
ParameterNotSupported = ResponseCodeType(0x2006)
IncompleteTransfer = ResponseCodeType(0x2007)
InvalidStorageID = ResponseCodeType(0x2008)
InvalidObjectHandle = ResponseCodeType(0x2009)
DevicePropNotSupported = ResponseCodeType(0x200A)
InvalidObjectFormatCode = ResponseCodeType(0x200B)
StoreFull = ResponseCodeType(0x200C)
ObjectWriteProtected = ResponseCodeType(0x200D)
StoreReadOnly = ResponseCodeType(0x200E)
AccessDenied = ResponseCodeType(0x200F)
NoThumbnailPresent = ResponseCodeType(0x2010)
SelfTestFailed = ResponseCodeType(0x2011)
PartialDeletion = ResponseCodeType(0x2012)
StoreNotAvailable = ResponseCodeType(0x2013)
SpecificationByFormatUnsupported = ResponseCodeType(0x2014)
NoValidObjectInfo = ResponseCodeType(0x2015)
InvalidCodeFormat = ResponseCodeType(0x2016)
UnknownVendorCode = ResponseCodeType(0x2017)
CaptureAlreadyTerminated = ResponseCodeType(0x2018)
DeviceBusy = ResponseCodeType(0x2019)
InvalidParentObject = ResponseCodeType(0x201A)
InvalidDevicePropFormat = ResponseCodeType(0x201B)
InvalidDevicePropValue = ResponseCodeType(0x201C)
InvalidParameter = ResponseCodeType(0x201D)
SessionAlreadyOpen = ResponseCodeType(0x201E)
TransactionCancelled = ResponseCodeType(0x201F)
SpecificationOfDestinationUnsupported = ResponseCodeType(0x2020)
# Response Codes 0x2021 - 0x9FFF are reserved.
VendorExtendedStart = ResponseCodeType(0xA000)
# PIMA 15470, 6.2, Table 14
ObjectFormatCodeType = fixedint.UInt16
class ObjectFormatCode(BaseEnum):
Unspecified = ObjectFormatCodeType(0x0000)
UndefinedNonImage = ObjectFormatCodeType(0x3000) # Undefined non-image object
Association = ObjectFormatCodeType(0x3001) # Association (e.g. folder)
Script = ObjectFormatCodeType(0x3002) # Device-model-specific script
Executable = ObjectFormatCodeType(0x3003) # Device-model-specific binary executable
Text = ObjectFormatCodeType(0x3004) # Text file
HTML = ObjectFormatCodeType(0x3005) # HyperText Markup Language file (text)
DPOF = ObjectFormatCodeType(0x3006) # Digital Print Order Format file (text)
AIFF = ObjectFormatCodeType(0x3007) # Audio clip
WAV = ObjectFormatCodeType(0x3008) # Audio clip
MP3 = ObjectFormatCodeType(0x3009) # Audio clip
AVI = ObjectFormatCodeType(0x300A) # Video clip
MPEG = ObjectFormatCodeType(0x300B) # Video clip
ASF = ObjectFormatCodeType(0x300C) # Microsoft Advanced Streaming Format (video)
UndefinedImage = ObjectFormatCodeType(0x3800) # Unknown image object
JPEG = ObjectFormatCodeType(0x3801) # Exchangeable File Format, JEIDA standard
EP = ObjectFormatCodeType(0x3802) # Tag Image File Format for Electronic Photography
FlashPix = ObjectFormatCodeType(0x3803) # Structured Storage Image Format
BMP = ObjectFormatCodeType(0x3804) # Microsoft Windows Bitmap file
CIFF = ObjectFormatCodeType(0x3805) # Canon Camera Image File Format
Reserved1 = ObjectFormatCodeType(0x3806) # Reserved
GIF = ObjectFormatCodeType(0x3807) # Graphics Interchange Format
JFIF = ObjectFormatCodeType(0x3808) # JPEG File Interchange Format
PCD = ObjectFormatCodeType(0x3809) # PhotoCD Image Pac
PICT = ObjectFormatCodeType(0x380A) # Quickdraw Image Format
PNG = ObjectFormatCodeType(0x380B) # Portable Network Graphics
Reserved2 = ObjectFormatCodeType(0x380C) # Reserved
TIFF = ObjectFormatCodeType(0x380D) ## Tag Image File Format
IT = ObjectFormatCodeType(0x380E) # Tag Image File Format for Information Technology (graphic arts)
JP2 = ObjectFormatCodeType(0x380F) # JPEG2000 Baseline File Format
JPX = ObjectFormatCodeType(0x3810) # JPEG2000 Extended File Format
# Event Codes 0x3811 - 0xB000 are reserved.
VendorExtendedStart = ObjectFormatCodeType(0xB000)
# PIMA 15470, 12.4, Table 22.
EventCodeType = fixedint.UInt16
class EventCode(BaseEnum):
Undefined = EventCodeType(0x4000)
CancelTransaction = EventCodeType(0x4001)
ObjectAdded = EventCodeType(0x4002)
ObjectRemoved = EventCodeType(0x4003)
StoreAdded = EventCodeType(0x4004)
StoreRemoved = EventCodeType(0x4005)
DevicePropChanged = EventCodeType(0x4006)
ObjectInfoChanged = EventCodeType(0x4007)
DeviceInfoChanged = EventCodeType(0x4008)
RequestObjectTransfer = EventCodeType(0x4009)
StoreFull = EventCodeType(0x400A)
DeviceReset = EventCodeType(0x400B)
StorageInfoChanged = EventCodeType(0x400C)
CaptureComplete = EventCodeType(0x400D)
UnreportedStatus = EventCodeType(0x400E)
# Event Codes 0x400F - 0xBFFF are reserved.
VendorExtendedStart = EventCodeType(0xC000)
DevicePropDescChanged = EventCodeType(0xC001)
# PIMA 15470, 13.3.5, Table 26.
DevicePropCodeType = fixedint.UInt16
class DevicePropCode(BaseEnum):
Undefined = DevicePropCodeType(0x5000)
BatteryLevel = DevicePropCodeType(0x5001)
FunctionalMode = DevicePropCodeType(0x5002)
ImageSize = DevicePropCodeType(0x5003)
CompressionSetting = DevicePropCodeType(0x5004)
WhiteBalance = DevicePropCodeType(0x5005)
RGBGain = DevicePropCodeType(0x5006)
FNumber = DevicePropCodeType(0x5007)
FocalLength = DevicePropCodeType(0x5008)
FocusDistance = DevicePropCodeType(0x5009)
FocusMode = DevicePropCodeType(0x500A)
ExposureMeteringMode = DevicePropCodeType(0x500B)
FlashMode = DevicePropCodeType(0x500C)
ExposureTime = DevicePropCodeType(0x500D)
ExposureProgramMode = DevicePropCodeType(0x500E)
ExposureIndex = DevicePropCodeType(0x500F)
ExposureBiasCompensation = DevicePropCodeType(0x5010)
DateTime = DevicePropCodeType(0x5011)
CaptureDelay = DevicePropCodeType(0x5012)
StillCaptureMode = DevicePropCodeType(0x5013)
Contrast = DevicePropCodeType(0x5014)
Sharpness = DevicePropCodeType(0x5015)
DigitalZoom = DevicePropCodeType(0x5016)
EffectMode = DevicePropCodeType(0x5017)
BurstNumber = DevicePropCodeType(0x5018)
BurstInterval = DevicePropCodeType(0x5019)
TimelapseNumber = DevicePropCodeType(0x501A)
TimelapseInterval = DevicePropCodeType(0x501B)
FocusMeteringMode = DevicePropCodeType(0x501C)
UploadURL = DevicePropCodeType(0x501D)
Artist = DevicePropCodeType(0x501E)
CopyrightInfo = DevicePropCodeType(0x501F)
# DeviceProp Codes 0x5020 - 0xCFFF are reserved.
VendorExtendedStart = DevicePropCodeType(0xD000)
BMD_ShutterSpeed = DevicePropCodeType(0xD001)
BMD_ShutterAngle = DevicePropCodeType(0xD002)
BMD_FocusPosition = DevicePropCodeType(0xD003)
BMD_WhiteBalanceKelvin = DevicePropCodeType(0xD004)
BMD_WhiteBalanceTint = DevicePropCodeType(0xD005)
BMD_FrameRate = DevicePropCodeType(0xD006)
BMD_OffSpeedFrameRate = DevicePropCodeType(0xD007)
BMD_OffSpeedEnabled = DevicePropCodeType(0xD008)
BMD_ZoomPosition = DevicePropCodeType(0xD009)
BMD_RecordingState = DevicePropCodeType(0xD00A)
BMD_NDFilter = DevicePropCodeType(0xD00B)
# PIMA 15470, 5.3, Table 3.
DataTypeCodeType = fixedint.UInt16
class DataTypeCode(BaseEnum):
Undefined = DataTypeCodeType(0x0000)
# n-bit integers
Int8 = DataTypeCodeType(0x0001)
UInt8 = DataTypeCodeType(0x0002)
Int16 = DataTypeCodeType(0x0003)
UInt16 = DataTypeCodeType(0x0004)
Int32 = DataTypeCodeType(0x0005)
UInt32 = DataTypeCodeType(0x0006)
Int64 = DataTypeCodeType(0x0007)
UInt64 = DataTypeCodeType(0x0008)
Int128 = DataTypeCodeType(0x0009)
UInt128 = DataTypeCodeType(0x000A)
# Arrays of n-bit integers
Int8_Array = DataTypeCodeType(0x4001)
UInt8_Array = DataTypeCodeType(0x4002)
Int16_Array = DataTypeCodeType(0x4003)
UInt16_Array = DataTypeCodeType(0x4004)
Int32_Array = DataTypeCodeType(0x4005)
UInt32_Array = DataTypeCodeType(0x4006)
Int64_Array = DataTypeCodeType(0x4007)
UInt64_Array = DataTypeCodeType(0x4008)
Int128_Array = DataTypeCodeType(0x4009)
UInt128_Array = DataTypeCodeType(0x400A)
# Variable-length UCS2 String
String = DataTypeCodeType(0xFFFF)
# PIMA 15470, 13.3.3, Table 23.
DevicePropPermissionsType = fixedint.UInt8
class DevicePropPermissions(BaseEnum):
ReadOnly = DevicePropPermissionsType(0x00)
ReadWrite = DevicePropPermissionsType(0x01)
# PIMA 15470, 13.3.3, Table 23.
DevicePropFormType = fixedint.UInt8
class DevicePropForm(BaseEnum):
NONE = DevicePropFormType(0x00)
Range = DevicePropFormType(0x01)
Enum = DevicePropFormType(0x02)