managing ptz cameras using elixir and the phoenix framework
TRANSCRIPT
Manage PTZ Cameras with Phoenix
José C García-Sacristán
@jgsacristan
“Phoenix is a framework for building HTML5 apps, API backends and distributed systems to take on the modern Web.”
“Written in Elixir, you get beautiful syntax, productive tooling and a fast runtime”
2 million connections per server
400 million users, 30 engineers
Erlang
• Created in 1986
- Windows in 1985
- Linux in 1991
• Handles 50% of the worlds telecom traffic
• Reported 99.9999999% availability (nine nines)
Elixir
Elixir is a functional, concurrent, general-purpose programming language that runs on the Erlang virtual machine (BEAM). Elixir builds on top of Erlang to provide distributed, fault-tolerant, soft real-time, non-stop applications but also extends it to support metaprogramming with macros and polymorphism via protocols.
Productivity in Phoenix
• Short term productivity
- Documentation / Guides / Generators
- Eliminates trivial choices
• Long term productivity
- Maintainability
- Introspection
Easy installation
• $mix local.hex
• $ mix archive.installhttps://github.com/phoenixframework/phoenix/releases/download/v1.0.2/phoenix_new-1.0.2.ez
• $mix phoenix.new my_app
Endpoints
Routers
Controllers
Generators
$ mix phoenix.gen.html
$ mix phoenix.gen.json
$ mix phoenix.gen.channel
Views & Templates
• Precompiled. Fast
• Views render templates.
• Views serve as a presentation layer
• Beyond HTML
Performance
Robust Concurrency Model
• “processes” – extreme lightweight units of concurrency
• Garbage collection is per process
- No global pauses
• Load balances on IO and CPU
Channels
Trivial realtime communication for connected devices
But there is more ..
• Form builders
• Static build tools with ES6 by default
• Live reloading
• First class test tools
• Packages via hex.pm (+2MM downloads)
Applications
• Package and run our code
• Can be started and stopped as a unit
• Provide unified configuration
• Hold processes and state in the supervision tree
:observer.start
:observer.start
• The ONVIF specification defines a common protocol for the exchange of information between network video devices including automatic device discovery, video streaming and intelligence metadata.
Onvif Specification
Based on relevant Web Services standards including security and IP configuration requirements. Areas covered:• IP configuration• Device discovery• Device management• Media configuration• Real time viewing• Event handling• PTZ camera control• Video analytics• Security
http://www.onvif.org/onvif/ver20/util/operationIndex.html
Integration with evercam-media
Problems:
• Poor SOAP support in Erlang/Elixir.
• WS-Security not implemented.
• SOAP operations return XML.
• evercam-media needs JSON responses.
Integration with evercam-media
Solution:
• HTTPotion for HTTP requests
Integration with evercam-media
Solution:
• HTTPotion for HTTP requests
• Own implementation of SOAP Envelope and WS-Security headers.
Integration with evercam-media
Solution:
• HTTPotion for HTTP requests
• Own implementation of SOAP Envelope and WS-Security headers.
• Own implementation of XML to Elixir Map transformations using Erlang xmerl library
Integration with evercam-media
• Definition of needed operations using onvif_client methods.
Integration with evercam-media
• Definition of needed operations using onvif_client methods.
• Add REST routes to web/router.ex
Integration with evercam-media
• Definition of needed operations using onvif_client methods.
• Add REST routes to web/router.ex
• Implement controllers that will invoke ONVIF operations and return the responses as Elixir Map structures.
Integration with evercam-media
• Definition of needed operations using onvif_client methods.
• Add REST routes to web/router.ex
• Implement controllers that will invoke ONVIF operations and return the responses as Elixir Map structures.
• Phoenix translate these Maps into JSON structures without the need of extra coding
Demo