-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
944 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from homekit import AccessoryServer | ||
from homekit.model import CameraAccessory, ManagedRTPStreamService, MicrophoneService | ||
from homekit.model.characteristics.rtp_stream.setup_endpoints import Address, IPVersion | ||
from homekit.model.characteristics.rtp_stream.supported_audio_stream_configuration import \ | ||
SupportedAudioStreamConfiguration, AudioCodecConfiguration, AudioCodecType, AudioCodecParameters, BitRate, \ | ||
SampleRate | ||
from homekit.model.characteristics.rtp_stream.supported_rtp_configuration import SupportedRTPConfiguration, \ | ||
CameraSRTPCryptoSuite | ||
from homekit.model.characteristics.rtp_stream.supported_video_stream_configuration import \ | ||
SupportedVideoStreamConfiguration, VideoCodecConfiguration, VideoCodecParameters, H264Profile, H264Level, \ | ||
VideoAttributes | ||
|
||
if __name__ == '__main__': | ||
try: | ||
httpd = AccessoryServer('demoserver.json') | ||
|
||
accessory = CameraAccessory('Testkamera', 'wiomoc', 'Demoserver', '0001', '0.1') | ||
|
||
|
||
# accessory.set_get_image_snapshot_callback( | ||
# lambda f: open('cam-preview.jpg', 'rb').read()) | ||
|
||
class StreamHandler: | ||
def __init__(self, controller_address, srtp_params_video): | ||
self.srtp_params_video = srtp_params_video | ||
self.controller_address = controller_address | ||
self.ffmpeg_process = None | ||
|
||
def on_start(self, attrs): | ||
import subprocess | ||
import base64 | ||
|
||
self.ffmpeg_process = subprocess.Popen( | ||
['ffmpeg', '-re', | ||
'-f', 'avfoundation', | ||
'-r', '30.000030', '-i', 'FaceTime HD-Kamera (integriert)', '-threads', '0', | ||
'-vcodec', 'libx264', '-an', '-pix_fmt', 'yuv420p', | ||
'-r', str(attrs.attributes.frame_rate), | ||
'-f', 'rawvideo', '-tune', 'zerolatency', '-vf', | ||
f'scale={attrs.attributes.width}:{attrs.attributes.height}', | ||
'-b:v', '300k', '-bufsize', '300k', | ||
'-payload_type', '99', '-ssrc', '32', '-f', 'rtp', | ||
'-srtp_out_suite', 'AES_CM_128_HMAC_SHA1_80', | ||
'-srtp_out_params', base64.b64encode( | ||
self.srtp_params_video.master_key + self.srtp_params_video.master_salt).decode('ascii'), | ||
f'srtp://{self.controller_address.ip_address}:{self.controller_address.video_rtp_port}' | ||
f'?rtcpport={self.controller_address.video_rtp_port}&localrtcpport={self.controller_address.video_rtp_port}' | ||
'&pkt_size=1378' | ||
]) | ||
|
||
def on_end(self): | ||
if self.ffmpeg_process is not None: | ||
self.ffmpeg_process.terminate() | ||
|
||
def get_ssrc(self): | ||
return (32, 32) | ||
|
||
def get_address(self): | ||
return Address(IPVersion.IPV4, httpd.data.ip, self.controller_address.video_rtp_port, | ||
self.controller_address.audio_rtp_port) | ||
|
||
|
||
stream_service = ManagedRTPStreamService( | ||
StreamHandler, | ||
SupportedRTPConfiguration( | ||
[ | ||
CameraSRTPCryptoSuite.AES_CM_128_HMAC_SHA1_80, | ||
]), | ||
SupportedVideoStreamConfiguration( | ||
VideoCodecConfiguration( | ||
VideoCodecParameters( | ||
[H264Profile.CONSTRAINED_BASELINE_PROFILE, H264Profile.MAIN_PROFILE, H264Profile.HIGH_PROFILE], | ||
[H264Level.L_3_1, H264Level.L_3_2, H264Level.L_4] | ||
), [ | ||
VideoAttributes(1920, 1080, 30), | ||
VideoAttributes(320, 240, 15), | ||
VideoAttributes(1280, 960, 30), | ||
VideoAttributes(1280, 720, 30), | ||
VideoAttributes(1280, 768, 30), | ||
VideoAttributes(640, 480, 30), | ||
VideoAttributes(640, 360, 30) | ||
])), | ||
SupportedAudioStreamConfiguration([ | ||
AudioCodecConfiguration(AudioCodecType.OPUS, | ||
AudioCodecParameters(1, BitRate.VARIABLE, SampleRate.KHZ_24)), | ||
AudioCodecConfiguration(AudioCodecType.AAC_ELD, | ||
AudioCodecParameters(1, BitRate.VARIABLE, SampleRate.KHZ_16)) | ||
], 0)) | ||
accessory.services.append(stream_service) | ||
microphone_service = MicrophoneService() | ||
accessory.services.append(microphone_service) | ||
httpd.accessories.add_accessory(accessory) | ||
|
||
httpd.publish_device() | ||
print('published device and start serving') | ||
httpd.serve_forever() | ||
except KeyboardInterrupt: | ||
print('unpublish device') | ||
httpd.unpublish_device() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# | ||
# Copyright 2018 Joachim Lusiardi | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
from homekit.model.characteristics import CharacteristicsTypes, CharacteristicFormats, CharacteristicPermissions, \ | ||
AbstractCharacteristic | ||
|
||
|
||
class MicrophoneMuteCharacteristic(AbstractCharacteristic): | ||
""" | ||
Defined on page 157 | ||
""" | ||
|
||
def __init__(self, iid): | ||
AbstractCharacteristic.__init__(self, iid, CharacteristicsTypes.MUTE, CharacteristicFormats.bool) | ||
self.description = 'Mute microphone (on/off)' | ||
self.perms = [CharacteristicPermissions.paired_write, CharacteristicPermissions.paired_read, | ||
CharacteristicPermissions.events] | ||
self.value = False | ||
|
||
|
||
class MicrophoneMuteCharacteristicMixin(object): | ||
def __init__(self, iid): | ||
self._muteCharacteristic = MicrophoneMuteCharacteristic(iid) | ||
self.characteristics.append(self._muteCharacteristic) | ||
|
||
def set_mute_set_callback(self, callback): | ||
self._muteCharacteristic.set_set_value_callback(callback) | ||
|
||
def set_mute_get_callback(self, callback): | ||
self._muteCharacteristic.set_get_value_callback(callback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# Copyright 2018 Joachim Lusiardi | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
__all__ = [ | ||
'SelectedRTPStreamConfigurationCharacteristicMixin', | ||
'SelectedRTPStreamConfigurationCharacteristic', 'SetupEndpointsCharacteristicMixin', | ||
'SetupEndpointsCharacteristic', 'StreamingStatusCharacteristicMixin', | ||
'StreamingStatusCharacteristic', 'SupportedRTPConfigurationCharacteristic', | ||
'SupportedVideoStreamConfigurationCharacteristic', 'SupportedAudioStreamConfigurationCharacteristic' | ||
] | ||
|
||
from homekit.model.characteristics.rtp_stream.supported_video_stream_configuration import \ | ||
SupportedVideoStreamConfigurationCharacteristic | ||
from homekit.model.characteristics.rtp_stream.supported_rtp_configuration import \ | ||
SupportedRTPConfigurationCharacteristic | ||
from homekit.model.characteristics.rtp_stream.streaming_status import StreamingStatusCharacteristicMixin, \ | ||
StreamingStatusCharacteristic | ||
from homekit.model.characteristics.rtp_stream.supported_audio_stream_configuration import \ | ||
SupportedAudioStreamConfigurationCharacteristic | ||
from homekit.model.characteristics.rtp_stream.selected_rtp_stream_configuration import \ | ||
SelectedRTPStreamConfigurationCharacteristic, SelectedRTPStreamConfigurationCharacteristicMixin | ||
from homekit.model.characteristics.rtp_stream.setup_endpoints import \ | ||
SetupEndpointsCharacteristic, SetupEndpointsCharacteristicMixin |
Oops, something went wrong.