-
Notifications
You must be signed in to change notification settings - Fork 119
/
camera_main.py
executable file
·73 lines (64 loc) · 2.19 KB
/
camera_main.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
"""An example of how to setup and start an Accessory.
This is:
1. Create the Accessory object you want.
2. Add it to an AccessoryDriver, which will advertise it on the local network,
setup a server to answer client queries, etc.
"""
import logging
import signal
from pyhap.accessory_driver import AccessoryDriver
from pyhap import camera, util
logging.basicConfig(level=logging.INFO, format="[%(module)s] %(message)s")
# Specify the audio and video configuration that your device can support
# The HAP client will choose from these when negotiating a session.
options = {
"video": {
"codec": {
"profiles": [
camera.VIDEO_CODEC_PARAM_PROFILE_ID_TYPES["BASELINE"],
camera.VIDEO_CODEC_PARAM_PROFILE_ID_TYPES["MAIN"],
camera.VIDEO_CODEC_PARAM_PROFILE_ID_TYPES["HIGH"]
],
"levels": [
camera.VIDEO_CODEC_PARAM_LEVEL_TYPES['TYPE3_1'],
camera.VIDEO_CODEC_PARAM_LEVEL_TYPES['TYPE3_2'],
camera.VIDEO_CODEC_PARAM_LEVEL_TYPES['TYPE4_0'],
],
},
"resolutions": [
# Width, Height, framerate
[320, 240, 15], # Required for Apple Watch
[1024, 768, 30],
[640, 480, 30],
[640, 360, 30],
[480, 360, 30],
[480, 270, 30],
[320, 240, 30],
[320, 180, 30],
],
},
"audio": {
"codecs": [
{
'type': 'OPUS',
'samplerate': 24,
},
{
'type': 'AAC-eld',
'samplerate': 16
}
],
},
"srtp": True,
# hard code the address if auto-detection does not work as desired: e.g. "192.168.1.226"
"address": util.get_local_address(),
}
# Start the accessory on port 51826
driver = AccessoryDriver(port=51826)
acc = camera.Camera(options, driver, "Camera")
driver.add_accessory(accessory=acc)
# We want KeyboardInterrupts and SIGTERM (terminate) to be handled by the driver itself,
# so that it can gracefully stop the accessory, server and advertising.
signal.signal(signal.SIGTERM, driver.signal_handler)
# Start it!
driver.start()