Advertisement
Guest User

Untitled

a guest
May 11th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. sudo apt-get install twinkle
  2.  
  3. sudo apt-get install linphone
  4.  
  5. import linphone
  6. import logging
  7. import signal
  8. import time
  9.  
  10. class SecurityCamera:
  11. def __init__(self, username='', password='', whitelist=[], camera='', snd_capture='', snd_playback=''):
  12. self.quit = False
  13. self.whitelist = whitelist
  14. callbacks = {
  15. 'call_state_changed': self.call_state_changed,
  16. }
  17.  
  18. # Configure the linphone core
  19. logging.basicConfig(level=logging.INFO)
  20. signal.signal(signal.SIGINT, self.signal_handler)
  21. linphone.set_log_handler(self.log_handler)
  22. self.core = linphone.Core.new(callbacks, None, None)
  23. self.core.max_calls = 1
  24. self.core.echo_cancellation_enabled = False
  25. self.core.video_capture_enabled = True
  26. self.core.video_display_enabled = False
  27. self.core.stun_server = 'stun.linphone.org'
  28. self.core.firewall_policy = linphone.FirewallPolicy.PolicyUseIce
  29. if len(camera):
  30. self.core.video_device = camera
  31. if len(snd_capture):
  32. self.core.capture_device = snd_capture
  33. if len(snd_playback):
  34. self.core.playback_device = snd_playback
  35.  
  36. # Only enable PCMU and PCMA audio codecs
  37. for codec in self.core.audio_codecs:
  38. if codec.mime_type == "PCMA" or codec.mime_type == "PCMU":
  39. self.core.enable_payload_type(codec, True)
  40. else:
  41. self.core.enable_payload_type(codec, False)
  42.  
  43. # Only enable VP8 video codec
  44. for codec in self.core.video_codecs:
  45. if codec.mime_type == "VP8":
  46. self.core.enable_payload_type(codec, True)
  47. else:
  48. self.core.enable_payload_type(codec, False)
  49.  
  50. self.configure_sip_account(username, password)
  51.  
  52. def signal_handler(self, signal, frame):
  53. self.core.terminate_all_calls()
  54. self.quit = True
  55.  
  56. def log_handler(self, level, msg):
  57. method = getattr(logging, level)
  58. method(msg)
  59.  
  60. def call_state_changed(self, core, call, state, message):
  61. if state == linphone.CallState.IncomingReceived:
  62. if call.remote_address.as_string_uri_only() in self.whitelist:
  63. params = core.create_call_params(call)
  64. core.accept_call_with_params(call, params)
  65. else:
  66. core.decline_call(call, linphone.Reason.Declined)
  67. chat_room = core.get_chat_room_from_uri(self.whitelist[0])
  68. msg = chat_room.create_message(call.remote_address_as_string + ' tried to call')
  69. chat_room.send_chat_message(msg)
  70.  
  71. def configure_sip_account(self, username, password):
  72. # Configure the SIP account
  73. proxy_cfg = self.core.create_proxy_config()
  74. proxy_cfg.identity = 'sip:{username}@sip.linphone.org'.format(username=username)
  75. proxy_cfg.server_addr = 'sip:sip.linphone.org;transport=tls'
  76. proxy_cfg.register_enabled = True
  77. self.core.add_proxy_config(proxy_cfg)
  78. auth_info = self.core.create_auth_info(username, None, password, None, None, 'sip.linphone.org')
  79. self.core.add_auth_info(auth_info)
  80.  
  81. def run(self):
  82. while not self.quit:
  83. self.core.iterate()
  84. time.sleep(0.03)
  85.  
  86. def main():
  87. cam = SecurityCamera(username='raspberry', password='pi', whitelist=['sip:trusteduser@sip.linphone.org'], camera='V4L2: /dev/video0', snd_capture='ALSA: USB Device 0x46d:0x825')
  88. cam.run()
  89.  
  90. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement