Monthly Archives: November 2015

Wowza REST APIs and HTTP Providers

This article show the different ways to make calls to Wowza Media Engine from external applications and environments for various purposes  such as getting server status , listeners , connections , applications and its streams etc .

HTTP Providers

HTTP Providers are Java classes that are configured on a per-virtual host basis.


Some pre packaged HTTP providers that return data in XML  :

1. HTTPConnectionCountsXML

Returns connection information like Vhost , application , application instance , message in bytes rate , message out byte rates etc.


Screenshot from 2015-11-24 20:23:51

2. HTTPConnectionInfo
Returns detailed connection information such as



3. HTTPServerVersion

Returns the Wowza Media Server version and build number. It’s the default HTTP Provider on port 1935.

url : http://%5Bwowza-ip-address%5D:1935

Wowza Streaming Engine 4 Monthly Edition 4.1.1 build13180

4. HTTPLiveStreamRecord

gets the web interface to record online streams

url : http://%5Bwowza-ip-address%5D:8086/livestreamrecord

Screenshot from 2015-11-24 20:22:16

5. HTTPServerInfoXML

Returns server and connection information

url :http://%5Bwowza-ip-address%5D:8086/serverinfo

Screenshot from 2015-11-24 20:34:08


6. HTTPClientAccessPolicy .

It is used for fetching the Microsoft Silverlight clientaccesspolicy.xml from the conf folder.

7. HTTPCrossdomain

To get the Adobe Flash crossdomain.xml file from [install-dir]/conf folder.


Dynamic method for generating adaptive bitrate manifests and playlists from SMIL data.


The Stream Manager returns all applications and their stream in web interface.

url http://%5Bwowza-ip-address%5D:8086/streammanager).


Screenshot from 2015-11-24 20:38:32

10 .HTTPTranscoderThumbnail

Returns a bitmap image from the source stream being transcoded.

url: http://%5Bwowza-ip-address%5D:8086/transcoderthumbnail?application=%5Bapplication-name%5D&streamname=%5Bstream-name%5D&format=%5Bjpeg or png]&size=[widthxheight]

Each HTTP provider can be configured with different request filter and authentication method ( none , basic , digest).  We can even create our own substitutes for the HTTP providers as defined in the next section .

extending HTTProvider2Base

The following code snippet describes the process of creating a Wowza Web services that return a json containing all the values .

Imports to build a HTTP provider

import com.wowza.wms.application.*;
import com.wowza.wms.vhost.*;
import com.wowza.wms.http.*;
import com.wowza.wms.httpstreamer.model.*;

//since we want to return in json format

import org.json.simple.JSONObject;

The class declaration is as folllows

public class DCWS extends HTTProvider2Base



The code to extract application names


public JSONObject listChannels(){

JSONObject obj=new JSONObject();

//get params from virtual host and iterate through it
List<String> vhostNames = VHostSingleton.getVHostNames();
Iterator<String> iter = vhostNames.iterator();
while (iter.hasNext())
String vhostName =;
IVHost vhost = (IVHost)VHostSingleton.getInstance(vhostName);
List<String> appNames = vhost.getApplicationNames();
Iterator<String> appNameIterator = appNames.iterator();

int i=0;
while (appNameIterator.hasNext())
String applicationName =;

try {
String key = "channel"+ (++i);
obj.put(key, URLEncoder.encode(applicationName, "UTF-8"));

catch (UnsupportedEncodingException e) {
return obj;



The code which responds to HTTP request



Ref :

WebGL , Three.js and WebRTC

For the last couple of weeks , I have been working on the concept of rendering 3D graphics on WebRTC media stream using different JavaScript libraries as part of a Virtual Reality project .

What is Augmented Reality ?

Augmented reality (AR) is viewing a real-world environment with elements that are supplemented by computer-generated sensory inputs such as sound, video, graphics , location etc.

How is it diff. from Virtual Reality ?

Virtual Reality – replaces the real world with simulated one , user is isolated from real life , Examples – Oculus Rift & Kinect

Augmented Reality – blending of virtual reality and real life , user interacts with real world through digital overlays , Examples – Google glass & Holo Lens

Methods for rendering augmented Reality

  • Computer Vision
  • Object Recognition
  • Eye Tracking
  • Face Detection and substitution
  • Emotion and gesture picker
  • Edge Detection

web based Augmented Reality solution

Components for a Web base  end to end AR solution

Web :

WebRTC getusermedia
Web Speech API
HTML5 canvas
sensor API

H/w :

Graphics driver
microphone and camera

3D :

Geometry and Math Utilities
3D Model Loaders and models
Lights, Materials,Shaders, Particles,


  • Web based Real Time communications
  • Definition for browser’s media stream and data
  • Awaiting more standardization , on a API level at the W3C and at the protocol level at the IETF.
  • Enable browser to browser applications for voice calling, video chat and P2P file sharing without plugins.
  • Enables web browsers with Real-Time Communications (RTC) capabilities
  • MIT : Free, open project

Code snippet for WebRTC API

1.To begin with WebRTC we first need to validate that the browser has permission to access the webcam.

<video id="webcam" autoplay width="640" height="480"></video>
  1. Find out if the user’s browser can use the getUserMedia API.
function hasGetUserMedia() {
	return !!(navigator.webkitGetUserMedia);
  1. Get the stream from the user’s webcam.
var video = $('#webcam')[0];
if (navigator.webkitGetUserMedia) {
			{audio:true, video:true},
			function(stream) { video.src = window.webkitURL.createObjectURL(stream);  },
			function(e) {	alert('Webcam error!', e); }

Screenshot AppRTC

Augmented Reality in WebRTC Browser - Google Slides



  • Web Graphics Library
  • JavaScript API for rendering interactive 2D and 3D computer graphics in browser
  • no plugins
  • uses GPU ( Graphics Processing Unit ) acceleration
  • can mix with other HTML elements
  • uses the HTML5 canvas element and is accessed using Document Object Model interfaces
  • cross platform , works on all major Desktop and mobile browsers

WebGL Development

To get started you should know about :

  • GLSL, the shading language used by OpenGL and WebGL
  • Matrix computation to set up transformations
  • Vertex buffers to hold data about vertex positions, normals, colors, and textures
  • matrix math to animate shapes

Cleary WebGL is bit tough given the amount of careful coding , mapping and shading it requires .

Proceeding to some JS libraries that can make 3D easy for us .








  • MIT license
  • javascript 3D engine ie ( WebGL + more)
  • started a year ago
  • under active development
  • no dependencies or installation

3D space with webcam input as texture

Display the video as a plane which can be viewed from various angles in a given background landscape. Credits for code :

1.Use code from slide 10 to get user’s webcam input through getUserMedia

  1. Make a Screen , camera and renderer as previously described

  2. Give orbital CONTROLS for viewing the media plane from all angles

	controls = new THREE.OrbitControls( camera, renderer.domElement );
  1. Add point LIGHT to scene

  2. Make the FLOOR with an image texture

	var floorTexture = new THREE.ImageUtils.loadTexture( 'imageURL.jpg' );
	floorTexture.wrapS = floorTexture.wrapT = THREE.RepeatWrapping;
	floorTexture.repeat.set( 10, 10 );
	var floorMaterial = new THREE.MeshBasicMaterial({map: floorTexture, side: THREE.DoubleSide});
	var floorGeometry = new THREE.PlaneGeometry(1000, 1000, 10, 10);
	var floor = new THREE.Mesh(floorGeometry, floorMaterial);
	floor.position.y = -0.5;
	floor.rotation.x = Math.PI / 2;

6. Add Fog

scene.fog = new THREE.FogExp2( 0x9999ff, 0.00025 );

7.Add video Image Context and Texture.

video = document.getElementById( 'monitor' ); 
videoImage = document.getElementById( 'videoImage' ); 
videoImageContext = videoImage.getContext( '2d' ); 
videoImageContext.fillStyle = '#000000'; 
videoImageContext.fillRect( 0, 0, videoImage.width, videoImage.height ); 
videoTexture = new THREE.Texture( videoImage ); 
videoTexture.minFilter = THREE.LinearFilter; 
videoTexture.magFilter = THREE.LinearFilter; 
var movieMaterial=new THREE.MeshBasicMaterial({map:videoTexture,overdraw:true,side:THREE.DoubleSide}); 
var movieGeometry = new THREE.PlaneGeometry( 100, 100, 1, 1 ); 
var movieScreen = new THREE.Mesh( movieGeometry, movieMaterial ); 
  1. Set camera position
  1. Define the render function
    videoImageContext.drawImage( video, 0, 0, videoImage.width, videoImage.height );
    renderer.render( scene, camera );
  1. Animation
   requestAnimationFrame( animate );


Augmented Reality in WebRTC Browser - Google Slides (4)



IOT Survillance with Arduino + Rpi + WebRTC

“ The Internet of Things (IoT) is the network of physical objects or “things” embedded with electronics, software, sensors and connectivity to enable it to achieve greater value and service by exchanging data with the manufacturer, operator and/or other connected devices. “ – wikipedia

Smart TV , mobiles , CCTV cams and other few things are already connected to the Internet.So whether we’ve known it or not, the “Internet of Things” is already here. But , number of these interconnections is on the rise and need to controlled , monitored and optimized .

IOT areas where media streaming capabilities of

  • Home automation
  • Targeted marketing
  • Wildlife and environment
  • Manufacturing
  • Smart Grid /  real-time energy optimization.
  • Connected logistics
  • Augmented reality
  • Ubiquitous computing (ubicomp) / BYOD
  • Healthcare
  • Transportation / connected car

This post describes the process of creating a Arduino based IOT control setup over Internet. The features of this application are

  1. Cheap and more customized solution to specific use cases
  2. Recycled components
  3. No patented or proprietary protocols
  4. Easy person-to-machine and machine-to-machine comm.
  5. Can be integrated with other modules like Recording , Multiplexing , transcoding .

Requirements :

Hardware requirements

  1. Rpi as communication hub to internet
  2. ultrasonic sensors to detect obstruction in field of view
  3. camera module of Rpi or standrad webcam
  4. Motion Sensors
  5. Buzzer
  6. mic
  7. flash lights connected via relay drivers to rpi

Software requirements

  1. open CV ( image processing)
  2. Simple CV ( face recognition )
  3. motion
  4. webrtc for media live streaming in case of remote monitoring


Screenshot from 2015-11-10 22:02:25

Screenshot from 2015-11-11 11:22:09

WebRTC communication and media streaming setup

Screenshot from 2015-11-11 11:31:30

Raspberry Pi Communication Modules



Ethernet wires can connect rpi to a another machine such as  laptop  from which it can be connected via terminal or using remote desktop accessing software’s such as tightvnc .


Undoubtedly Ethernet offers the fastest speed, lowest latency and no  data loss due to wireless interference problems however it is as the price of being immobile , as its is a wired connection and shifting disrupts the connection .

Cat-5e cable and  Cat-6e cable can offer upto  1 Gb/s and  10 Gb/s respecctively .

Wifi or IEEE 802.11  wifi

Wi-Fi was launched in the year 1997. Victor Hayes is known as father of Wi-Fi.

There are various standards and adoptions for IEEE802.11 like 802.11ac, 802.11n, 802.11g, and 802.11b which can offer maximum speeds of 866.7 Mbit/s , 150 Mbit/s  ,  54 Mbit/s and 11 Mbit/s respectively , however consumes more power than Bluetoooth .

Image Wifi hotspot


Image Wifi USB


Image Wifi module Rpi

Wifi -direct can even reach upto 250mbps of data transferring rate at  2.4, 3.6 and 5 GHz frequency . Range is around 100m .

BLE / Bluetooth ble

Bleutooth was launched in 1994 as a wireless communication alternative to RS232 by  Ericsson . Now it is handled by Special Interest group  for Bluetooth.


Bluetooth 4.0 can do data transfer rates to be upto 25mbps  at 2.4GHz frequency  while maximum range being 30 m .


This section refers to the data provider by the network of a telecom carrier company such as Airtel , Tata Docomo etc in India . 2G capabilities


Majorly the technology behind the differnt generation of telecom is as follows
2G – GSM 900, GSM 1800 – 14.4 kbps
3G – UMTS 2100 – 3.1 Mbps
4G – LTE 850 (5), LTE 1800 (3), LTE 2300 (40) – 100 Mbps

The carries frquency varries from 200 KH , 5 MHz , 15 MHz recpectively


Short for Near Field Communication . NFC uses electromagnetic induction between two loop antennae in smart devices to exchange information.
It uses unlicensed radio frequency ISM band of 13.56 MHz with data trabsfer rate of about 106 to 424 kbit/s.Unlike bluetooth it is a point to point communication .

Audio / Video Streaming

First enable the rpi camera support from the boot screen


One can choose between the following ways to be able to stream data from a Rpi

  1. Motion

To start motion detection edit motion.cong file

$ vi /etc/motion/motion.conf

Although the it starts detecting motion automatically we can modify few properties like

# Threshold for number of changed pixels in an image that
# triggers motion detection (default: 1500)
threshold 1500
# Detect motion in predefined areas (1 – 9). Areas are numbered like that: 1 2 3
# A script (on_area_detected) is started immediately when motion is 4 5 6
# detected in one of the given areas, but only once during an event. 7 8 9
# One or more areas can be specified with this option. Take care: This option
# does NOT restrict detection to these areas! (Default: not defined)
; area_detect value

# Picture frames must contain motion at least the specified number of frames
# in a row before they are detected as true motion. At the default of 1, all
# motion is detected. Valid range: 1 to thousands, recommended 1-5
minimum_motion_frames 1

# Specifies the number of pre-captured (buffered) pictures from before motion
# was detected that will be output at motion detection.
# Recommended range: 0 to 5 (default: 0)
# Do not use large values! Large values will cause Motion to skip video frames and
# cause unsmooth movies. To smooth movies use larger values of post_capture instead.
pre_capture 10

# Number of frames to capture after motion is no longer detected (default: 0)
post_capture 10

# Event Gap is the seconds of no motion detection that triggers the end of an event.
# An event is defined as a series of motion images taken within a short timeframe.
# Recommended value is 60 seconds (Default). The value -1 is allowed and disables
# events causing all Motion to be written to one single movie file and no pre_capture.
# If set to 0, motion is running in gapless mode. Movies don’t have gaps anymore. An
# event ends right after no more motion is detected and post_capture is over.
event_gap 60

# Maximum length in seconds of a movie
# When value is exceeded a new movie file is created. (Default: 0 = infinite)
#max_movie_time 0
max_mpeg_time 240

# Always save images even if there was no motion (default: off)
emulate_motion off
To beep when motion is detected
Note: Motion never beeps when running in daemon mode.
quiet off

To draw a identifiable area where motion is deceted
# Set the look and style of the locate box if enabled.
# Valid values: box, redbox, cross, redcross (default: box)
# Set to ‘box’ will draw the traditional box.
# Set to ‘redbox’ will draw a red box.
# Set to ‘cross’ will draw a little cross to mark center.

locate_motion_style box


2.WebRTC ( rpi model 2 onwards)

In terminal:

$ curl | sudo apt-key add -
add this to /etc/apt/sources.list : 
deb wheezy main 

or simply run

wget &amp;amp;amp;&amp;amp;amp; sudo apt-key add ./lrkey.asc


Update the repos

 $ sudo apt-get update

Now install uv4l and supported software

 $ sudo apt-get install uv4l uv4l-raspicam

If you want the driver to be loaded at boot, also install this optional package:

 $ sudo apt-get install uv4l-raspicam-extras


Most importantly install the uv4l server and the WebRTC extension for the Streaming Server

 $ sudo apt-get install uv4l-webrtc

Screenshot from 2016-06-19 15-24-00

Type uv4l –help for getting  list of options for core , streaming , fine tuning , logging etc

start the service using following command

sudo service uv4l_raspicam start

Screenshot from 2016-06-19 15-41-10

Open web
http://<rpi ip address>:8080/conference

Screenshot from 2016-06-19 15-41-34

Once the media capture and stream is established it is important to decide the stream methodology such as relay through a centralized media server or mesh streaming network as in webrtc p2p.

Click on any of the given options to see a incoming media stream from rpi

For example

Webrtc :

http://<rpi_ip&gt;:8080/stream/webrtc  gives incoming Webrtc media stream.


http://<rpi_ip&gt;:8080/stream/video.mjpeg gives mjpeg


The default server config is

  • basic HTTP/HTTPS authentication: disabled
  • underlying video device node: /dev/video0
  • current connections: 1, queued: 0, total handled: 11
  • max. simultaneous streams allowed: 3, max. threads: 5
  • raw HTTP/HTTPS video streams in MJPEG, JPEG (continuous stills) and H264 formats – if supported – are available under the /stream/video.mjpeg, /stream/video.jpeg, and /stream/video.h264URL paths respectively

Note : https is required if you want to have a outgoing video from your computer to rpi as browser mandates secure origin but https is not required for an incoming video stream so you can easily view the rpi genrated webrtc video without being on https .


Bluetooth Low Energy on Adafruit Arduino

Lately as I develop and realize few IOT use-cases , I have concluded that BLE ( Bluetooth Low Energy) , also known as Bluetooth smart , is a very good choice as it runs for longer periods of time with smaller power sources.

What is BLE ?

This is the version 4.0+ of Bluetooth which is aimed as building the communication network for IOT ( Internet of things ) . Like classic Bluetooth it utilizes the 2.4 Ghz band and performs in dual-mode. Also both the models use Gaussian frequency shift modulation for data transmission.

How is BLE different from classic Bluetooth ?

Power and Life : BLE provided better bit rate with lesser power consumption( 0.01W to 0.1W) than classic bluetooth technology ( 1 W). Channel : While Classic Bluetooth uses 79 1-MHz channels , BLE has 40 2-MHz channels

How can one make use of BLE in IOT ?

If you have a usecase that needs implementation than high changes are it needs 3 basic components: 1. End devices such as machines , automated doors , surveillance systems , metering systems etc This is where BLE can be used to transmit realtime data quickly to central controller

  1. Central control hub to control the end points and communicate to server This has to be a bridge between BLE devices and internet to put all the gathered information on the cloud for analysis and logic processing.
  2. User provisioning system or Graphical interface to who stats , status , control options etc . This is also a critical component as the user needs to have a way of controlling the operation without physically going to the machines . Although the system can very much work without given a pre-programmed operation .

*References *

you can learn more about bluetooth form these links

Simple Adafruit Bluefruit Bluetooth LE UART android app

This is the first and the most basic example of using BLE.


Key concepts for BLE programming

GATT ( Generic Attribute Profile) : The bluetooth Special Interest Group ( SIG ) defines many profile for low energy devices.  GATT is also an profile for sending and receiving short data in low energy devices .

ATT (Attribute Protocol ) : Each attribute is uniquely identified by a Universally Unique Identifier (UUID), which is a standardized 128-bit format for a string ID. The attributes transported by ATT are formatted as characteristics and services

BLE activity class

While defining the Bluetooth LE UART acttivity class we must extend the BluetoothGattCallback parent class and implement the BluetoothAdapter.LeScanCallback interface .

Then define the public data values for the device such as UUID of the UART , TX and RX. Also the UUID for the UART BTLE client characteristic which is necessary for notifications .UUIDs for the Device Information service and associated characeristics such as Manufacture , Model , hardware , software .

set the adapter to BluetoothAdapter.getDefaultAdapter()

we can define some callbacks in an interface , This enables BLE UART client to be notified of UART actions .

 public interface Callback {
 public void onConnected(BluetoothLeUart uart);
 public void onConnectFailed(BluetoothLeUart uart);
 public void onDisconnected(BluetoothLeUart uart);
 public void onReceive(BluetoothLeUart uart, BluetoothGattCharacteristic rx);
 public void onDeviceFound(BluetoothDevice device);
 public void onDeviceInfoAvailable();

For scanning the available devices , call adapter.startLeScan(this) . This will Start scanning for BLE UART devices. Registered callback’s onDeviceFound method will be called when devices are found during scanning. Similarly call adapter.stopLeScan(this) to stop the device scan .

we may also define Handlers for BluetoothGatt and LeScan events such as ,

1. onLeScan

Stop if the device doesn’t have the UART service

        if (!parseUUIDs(scanRecord).contains(UART_UUID)) {

Notify registered callbacks of found device.


connect to device

	gatt = device.connectGatt(context, true, this);

2. onConnectionStateChange

super.onConnectionStateChange(gatt, status, newState);

we can check the state through BluetoothGatt.STATE_CONNECTED and status of connection through BluetoothGatt.GATT_SUCCESS.
Further more we can check if the service was found on the device through gatt.discoverServices()
If any of the above conndition were not checked we can call connectFailure() which signifies that connection was a failure and reset cinnection state through

        rx = null;
        tx = null;

Simillarlily if state was BluetoothGatt.STATE_DISCONNECTED then notify callbacks of disconnection.
3. onServicesDiscovered
super.onServicesDiscovered(gatt, status);

notify connection failure if service discivery failed

status == BluetoothGatt.GATT_FAILURE

Save reference to each UART characteristic.

        tx = gatt.getService(UART_UUID).getCharacteristic(TX_UUID);
        rx = gatt.getService(UART_UUID).getCharacteristic(RX_UUID);

Save reference to each DIS characteristic.

        disManuf = gatt.getService(DIS_UUID).getCharacteristic(DIS_MANUF_UUID);
        disModel = gatt.getService(DIS_UUID).getCharacteristic(DIS_MODEL_UUID);
        disHWRev = gatt.getService(DIS_UUID).getCharacteristic(DIS_HWREV_UUID);
        disSWRev = gatt.getService(DIS_UUID).getCharacteristic(DIS_SWREV_UUID);

Add device information characteristics to the read queue . These need to be queued because we have to wait for the response to the first read request before a second one can be processed


Request a dummy read to get the device information queue going


Setup notifications on RX characteristic changes (i.e. data received).

First call setCharacteristicNotification to enable notification

gatt.setCharacteristicNotification(rx, true)

Stop if the characteristic notification setup failed.

Next update the RX characteristic’s client descriptor to enable notifications

BluetoothGattDescriptor desc = rx.getDescriptor(CLIENT_UUID)

Stop if the RX characteristic desc has no client descriptor ie null or if the client descriptor could not be written.

Notify of connection completion.


3. onCharacteristicChanged

        super.onCharacteristicChanged(gatt, characteristic);
        notifyOnReceive(this, characteristic);

4. onCharacteristicRead

	super.onCharacteristicRead(gatt, characteristic, status);

Check if there is anything left in the queue

            BluetoothGattCharacteristic nextRequest = readQueue.poll();

if nextRequest is not null ie it has items more Send a read request for the next item in the queue


else We’ve reached the end of the queue so set the flags and make the callback

                disAvailable = true;

5. onCharacteristicWrite

	super.onCharacteristicWrite(gatt, characteristic, status);

android manifest file

1. Declare the Bluetooth permission to perform connection and data transfer over bluetooth

<uses-permission android:name=”android.permission.BLUETOOTH”/>

2. To initiate device discovery or manipulate Bluetooth settings, you must also declare the BLUETOOTH_ADMIN permission.

<uses-permission android:name=”android.permission.BLUETOOTH_ADMIN”/>

3. To declare that your app is available to BLE-capable devices only.

<uses-feature android:name=”android.hardware.bluetooth_le” android:required=”true”/>


Android studio screenshots 

I have used Adafruit Bluefruit LE UART Friend – Bluetooth Low Energy (BLE) device . More details about this can be found here .

The circuit for a BLE Arduino is as follows :

This application has more modules than the previous simple read and write application . It can work in 4 modes namely

  1. Info
  2. UART
  3. Controller
  4. Beacon

The circuit arrangement is shown in following pictures :

The edited source code of the android application is on the github repo :

screenshots of the Android application

The controller mode


We can connect a android phone in adb mode to android studio and monitor the realtime network , memory and other stats.

See the connection and communication entities form the android device monitor logcat

The code of this application is derived from

More information about Bluefruit LE the device can be obtained form