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
from concurrent.futures import ThreadPoolExecutor
from tornado.concurrent import run_on_executor
from API.handlers import APIHandler
from API.schema import api
import errors
class AudioAPI(APIHandler):
"""REST interface to the Box
"""
executor = ThreadPoolExecutor(1)
def __init__(self, extra):
"""Init
"""
super(AudioAPI, self).__init__(extra)
self.server = extra["server"]
self.project_manager = extra["project_manager"]
self.output_manager = extra["output_manager"]
@api(name="ListSources",
endpoint="audio.list_sources",
description="Lists audio sources",
result={
"type": "object",
"properties":
{
"audio_sources": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"$ref": "AudioSourceName"
},
"support_delay": {
"type": "boolean"
},
"layouts": {
"type": "array",
"items": {
"$ref": "AudioSourceLayout"
}
}
}
}
}
},
"minProperties": 1
}
)
@run_on_executor
def list_sources(self, parameters):
sources = []
project_audio_sources = self.project_manager.list_audio_sources()
for source_name in project_audio_sources:
sources.append({
"name": source_name,
"support_delay": project_audio_sources[source_name]["input"]
in self.project_manager.AUDIO_INPUTS_SUPPORTING_DELAY,
"layouts": project_audio_sources[source_name]["layouts"]})
return {"audio_sources": sources}
@api(name="GetSource",
endpoint="audio.get_source",
description="Gets current audio source",
result={
"type": "object",
"properties":
{
"source": {
"$ref": "AudioSourceName"
},
"layout": {
"$ref": "AudioSourceLayout"
}
},
}
)
@run_on_executor
def get_source(self, parameters):
return {"source": self.project_manager.get_audio_source(), "layout": self.project_manager.get_audio_layout()}
@api(name="SetSource",
endpoint="audio.set_source",
description="Sets the current audio source",
parameters={
"type": "object",
"properties":
{
"source": {
"$ref": "AudioSourceName"
},
"layout": {
"$ref": "AudioSourceLayout"
}
},
"required": ["source", "layout"]
}
)
@run_on_executor
def set_source(self, parameters):
# setting the video mode is forbidden while broadcasting or recording
if self.output_manager.has_ongoing_critical_output():
raise errors.AudioSourceChangeForbiddenError(
"audio source cannot be changed (critical output is ongoing)")
self.project_manager.set_audio_source(str(parameters.get("source")), str(parameters.get("layout")))
self.server.reset()
@api(name="GetAudioDelay",
endpoint="audio.get_delay",
description="Gets the current delay for the specified source",
parameters={
"type": "object",
"properties":
{
"source": {
"$ref": "AudioSourceName"
}
},
"minProperties": 1
},
result={
"type": "object",
"properties":
{
"delay": {
"type": "number",
"description": "The audio delay in seconds"
}
}
}
)
@run_on_executor
def get_delay(self, parameters):
return {"delay": self.project_manager.get_audio_delay(str(parameters.get("source")))}
@api(name="SetAudioDelay",
endpoint="audio.set_delay",
description="Sets the current audio delay for the specified source",
parameters={
"type": "object",
"properties":
{
"source": {
"$ref": "AudioSourceName"
},
"delay": {
"type": "number",
"minimum": -1.0,
"maximum": 1.0,
"description": "The audio delay in seconds"
}
}
}
)
@run_on_executor
def set_delay(self, parameters):
self.project_manager.set_audio_delay(str(parameters.get("source")), parameters.get("delay"))