Building WebRTC libraries for Android

January 25, 2015

WebRTC (Web Real-Time Communication) is a JavaScript API to support Audio/Video/Data communication between web application clients – e.t. making each browser into Skype-like video conferencing endpoint. At this time (January 2015) it still not yet fully standardized and supported mostly by Chrome (Google) and  Firefox (Mozilla) but not by IE (Microsoft) or Opera (Apple) .

Support for mobile browsers on Android had been introduced just recently and still not available on Android 4.x which run majority of devices in use. Fortunately,  WebRTC offers a way to build a native WebRTC application on Android ( as well as on iOS). Indeed, WebRTC core is written in C and includes a binding layer for JavaScript. Similar binding had been written for  Android Java and few code examples are offered as part of WebRTC open source code.

Get ARM-ready libraries.

Unfortunately, WebRTC build process is quite tedious and require special building tools on Linux host. So I decided to pre-build WebRTC libraries to share with those who have no patience to build themself (see details of building process below).

You can get  WebRTCDemo and AppRTCDemo source code and its ARM-build binary libraries from GitHub now. Those projects are ready to be modified and recompiled in any environment with appropriate Android SDK set up ( compilation required platform >21 , e.t. Android 5.0 LOLLIPOP, but application can run on Android 4.x as well). I’ll try to keep up with WebRTC development and try re-build those projects at least once a month.

 WebRTC native code building process.

This is useful for you only if you decide to rebuild WebRTC native libraries for Android. The process based on excellent blogs by Simon & Orcaman, with some additions found in the recent code.

First of all you need Ubuntu host – I setup a naked distribution of Ubuntu 14.04 LTS on top of VirtualBox.  Installation process itself is straight forward one, but install, don’t forget to instal VirtualBox additions (see good instructions) – makes your life much simpler.

And then execute:

# assuming we are starting from "virgin" Ubuntu installation
sudo apt-get install git
sudo apt-get install g++
sudo apt-get install subversion
sudo apt-get install git-svn
sudo apt-get install openjdk-7-jdk
sudo apt-get install ant
sudo apt-get install lib32stdc++6 lib32z1
#
# get google build tools
#
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"
#
# we'll need Java
#
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
#
# now we are setting our target for compilation
#
export GYP_DEFINES="OS=android"
#
# New home for WebCRT
#
mkdir WebCRT
cd WebCRT
#
# Time to pull sources ( including all dependencies derived from chromium project)
# will take quite a time
#
fetch webrtc_android
#
# Now time to build
#
cd src
#
# setup Android cross compiler build environment
#
. build/android/envsetup.sh
export GYP_DEFINES="build_with_chromium=0  $GYP_DEFINES"
export GYP_DEFINES="build_with_libjingle=1 $GYP_DEFINES"
export GYP_DEFINES="libjingle_java=1 $GYP_DEFINES"
# send WEBRTC_LOGGING to Android's logcat
export GYP_DEFINES="enable_tracing=1 $GYP_DEFINES"
#
# Generate .ninja files
#
gclient runhooks
#
# and now is an actual build....
#

#
# Build AppRTCDemo application – demonstrates interoperability of native Android
# client and Chrome JavaScript client.
# source code / project root : src/talk/examples/android/
# resulting APK : src/out/Debug/AppRTCDemo-debug.apk
#
ninja -C out/Debug AppRTCDemo

#
# Build WebRTCDemo application – exchange video+audio between two
# android clients.
# source code / project root : src/webrtc/examples/android/media_demo/
# resulting APK : src/out/Debug/WebRTCDemo-debug.apk
#
ninja -C out/Debug WebRTCDemo

References:

  1. Official WebRTC Android page
  2. AppRTCDemo application build and run instructions 
  3. WebRTCDemo application build and run instructions
  4. Source code of WebRTC Java wrapper
  5. WebRTC Build Scripts

Video chat SDK for Android

January 5, 2015

After inheriting an old outdated and broken intercom, I spend quite a time looking to repair or replace it. To my surprise, all available on the market (a) overpriced (b) designed like no progress happens last 10 years… So “buy/build” dilemma has an obvious answer – BUILD IT (more on Android Intercom specification)…

Starting a new project is always exciting, as well as challenging. As we build our success on the shoulders of giants, no way I waste time on low level Audio/Video transmission of call protocols ( especially considering that i build one of first such solutions 20 years ago 😉

So , here is a list of available “Video chat” SDKs available for Android integration:

 Name Description  open/pricing ?  protocols  
 Linphone multi-platform SIP Phone  Open source & Free  SIP Offers a fully open SDK with media streaming, full SIP protocol
and large number of codecs.
Commercial support and dual licensing available.No good documentation on the website – need efforts to build and understand…
 WebRTC Web based video streaming protocol Open source & Free  WebRTC
 ooVoo  multi-party video-communication app close source & pay-for-service ( advertisement or   $0.005/min)  WebRTC  very large user base
OpenTok/tokbox clouse source & pay-for-service ($0.005/min)  WebRTC
 Quickblox The cross platform app for instant messaging, video and voice calling. simple http streaming
 OVX/OpenClove Real-time In-App Communications for HTML/WebRTC, iOS, and Android
with multi-party, recording, streaming, and advanced features
 WebRTC
 C2Call close and freemium
 IceLink by Frozen Mountains  libraries for JavaScript, Android, iOS, Java, Mac, Mono, .NET, .NET Compact, Unity, Windows 8, Windows Phone, Xamarin.Android and Xamarin.iOS.  free limited  version/ commercial SDK for purchase  WebRTC

 

 

Tags

Small MySql hack for MacOS

December 12, 2014
Where is my mysql.sock file located ?Apparently, OS X moved MySql local socket file from typical Linux location (/var/mysql/mysql.sock) location to one in temporary directory (/tmp/mysql.sock).

If you are moving you application from Linux ( or for example debugging Linux bound PHP website) do the following :

mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Setting up PHP for local debugging

Once we activated Apache we can install Eclipse and configure PHP for local debug

Installing Eclipse

Eclipse is a most powerful IDE ever made by mankind… As long as you know your way around… Its power is coming from variety of toolkits, plugins, extensions and so on – making it extremely complicated to navigate and find your way if you lost… Lets’ install only basic configuration suitable to develop & debug Java and PHP applications

Adding PHP support

For PHP support, install “PDT” – “PHP Development Toolkit”.  Go to Help->”Install New Software”

To check if your Eclipse already have PDT installed,  go to Help->Installation Details. It list all installed components: in our example – Java IDE ( installed with base Eclipse installation) and PHP add-on

Configure PHP debugger

Install Zend Debugger

Zend Debugger is a free part of otherwise commercial product (‘Studio”) that compete with Eclipse. It maybe one of the reasons why installation of debugger is not streamlined. Also, checking some legacy websites, you may realise that instructions WHERE to download are may differ from time to time.. At the time of writing , most updated information on Zend Debugger installation is available at http://files.zend.com/help/Zend-Studio/zend-studio.htm#installing_the_zend_debugger.htm 
Notes on architecture ( to understand better configuration details): Zend Debugger is PHP extension library to be stored in same place as other PHP extensions on the SERVER host – the one where PHP script is actually executed ( as we setting up configuration for local debug – it will be the same one, but all techniques are similar for remote debug as well). PHP configuration has to be updated with location of the extension library and list of permitted clients to connect ( you don’t want to allow everyone to see website intestinals, aren’t you?) . When you start debug session under PDT, it will connect to Zend Debugger and do all magic of debugging..  
Debugger installation and setup – step by step
0.) “Who moved my cheese”… Apparently freshly installed/upgraded MacOS host does not have php.ini 😉 It has to be located in /etc/php.ini, but instead i found only /etc/php.ini.default. So , first item of business is to 

sudo cp /private/etc/php.ini.default /private/etc/php.ini

and restart apache.
in you website root directory (/Library/WebServer/Documents if you not using virtual hosts) create file info.php with single line
<?php phpinfo(); ?>

fire your browser to get this file and check results. 
First we check “Loaded Configuration File” – it has to be /etc/php.ini ( if empty, it mean that you missed previous step).
Second search for “extension_dir” and note its value – it is where we’ll copy Zend Debugger. On my host its value is “/usr/lib/php/extensions/no-debug-non-zts-20121212″
Same result you can get by running in command line
php -i|grep extension_dir

1.)  download “Zend Studio Web Debugger” from http://www.zend.com/en/products/studio/downloads#Mac%20OS  and open archive. It includes

ZendDebugger (depends on php version) and dummy file used for testing. Check your PHP version with “php -v” ( i have 5.514) and copy appropriate ZendDebugger.so file to extension directory discovered above. In my case it is

sudo cp ~/Downloads/ZendDebugger-darwin10.7-x86_64/php-5.5.x/ZendDebugger.so /usr/lib/php/extensions/no-debug-non-zts-20121212

copy dummy.php file into your web server root directory

sudo cp ~/Downloads/ZendDebugger-darwin10.7-x86_64/dummy.php /Library/WebServer/Documents/

2.) Modify PHP configuration settings (/private/etc/php.ini) to activate debugger extension – add following 2 lines to the end:

zend_extension = /usr/lib/php/extensions/no-debug-non-zts-20121212/ZendDebugger.sozend_debugger.allow_hosts = 127.0.0.1

don’t forget to restart apache to activate new configuration

3.) Now is a good time to test if our configuration works: first open in http://localhost/info.php – you will see a new “Zend Debugger” section.

Now we can go back to Eclipse and check debugger here as well..
In your project , open “Debug as -> Debugger Configuration” and go to Debugger tab:

Click on “text” – if configuration right, you’ll see “Successful” message..

All set – happy debugging!

P.S.Some useful documentation also can be found at 

http://files.zend.com/help/Zend-Studio/zend-studio.htm#installing_the_zend_debugger.htm

Apache in the Land of Mac

November 15, 2014
The first challenge I faced was configuration of Apache (HHTP server). It is coming as part of OS X but not activated by default. Yosemite (10.10) is coming with Apache/2.4.9 , Mavericks (10.9) with Apache/2.2.26

Command and Control

The first confusion was when I tried starting httpd with classical “init.d” approach – look, mom, OS X don’t have init.d..

Instead of Linux tricks, OS X is using (RTFM!) a native apache utility

apachectl

To start HTTP server:

sudo apachectl start

and as expected , to stop

sudo apachectl stop

Another useful command test all configuration files and report on error

apachectl configtest

and test virtual host configuration with

apachectl -S

server configuration files located at  /etc/apache2 ( or actually at /private/etc/apache2 but “private” can be dropped as etc is linked back)

Alternative is to use launch daemon – actual Mac replacement for init.d

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Some additional info on launchd and launchctl. TBD

Start on boot

To setup HTTPD running automatically on Mac boot ( it is not by default)

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

not flag “-w” which made this load permanent (e.t. autostart on reboot). To disable autostart , unload httpd daemon with

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Configuration

Enable PHP

in config file /etc/apache2/httpd.conf  uncoment line 
LoadModule php5_module libexec/apache2/libphp5.so

Enable User directory

If you’d like to classical unix http://localhost/~userdirectory functionality, uncomment following lines in /etc/apache2/httpd.conf 

LoadModule userdir_module libexec/apache2/mod_userdir.so
Include /private/etc/apache2/extra/httpd-userdir.conf 

Userdirectory located by default at /Users/username/Sites/. You probably will get 403 access denied error – fix it using those recommendations.

Enable Rewrite rules

in config file /etc/apache2/httpd.conf  uncoment line
LoadModule rewrite_module libexec/apache2/mod_rewrite.so

Enable Alias subdirectory

IMPORTNAT NOTE: Apache 2.4 introduced major changes in authorisation configuration – check details at http://httpd.apache.org/docs/2.4/upgrading.html#run-time (wasted time after upgrading OSX as it also upgrades Apache version)

Particularly, when moving from Apache 2.2 replace “allow all” construct

Order allow,deny
Allow from all

with new declaration

Require all granted

for example, to allow http://localhost/foo add /etc/apache2/other/foo.cfg file

Alias /foo /Users/stas/Sandbox/foo
<Directory “/Users/stas/Sandbox/foo”>
    Options Indexes FollowSymLinks Includes ExecCGI  
    AllowOverride all  
    Require all granted
    AddType application/x-httpd-php .php
</Directory>

Enable Virtual hosts on localhost

usually it is a best way to debug your web application locally – instead of www.foo.com, create local domain “foo.local”, build  virtual host and debug as you would with a real application.

Step 0 : in configuration file /etc/apache2/httpd.conf uncomment lines

LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

Step 1 : create a new DNS entry
add new entry into the /etc/hosts file – see last line (first 3 lines are standard)

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost 
127.0.0.1       foo.local

Step 2: create virtual host definition

<VirtualHost *:80>
    ServerAdmin webmaster@foo.local
    DocumentRoot “/Users/stas/Sandbox/foo”
    ServerName foo.local
    ServerAlias www.foo.local
    ErrorLog “/private/var/log/apache2/foo.local-error_log”
    CustomLog “/private/var/log/apache2/foo.local-access_log” common
</VirtualHost>


note: DocumentRoot must to point to directory with appropriate permissions – like one used in subdirectory example above. Otherwise you’ll receive “forbidden” error on access…

see also http://coolestguidesontheplanet.com/set-virtual-hosts-apache-mac-osx-10-10-yosemite/

Enable localhost server with virtual hosts

Setting up virtual hosts has one drawback -you will lose http://localhost ;-(
to restore it back, add one more virtual host definition:

<VirtualHost *:80>        ServerName localhost        DocumentRoot /Library/WebServer/Documents/</VirtualHost>

Troubleshooting

Log files located by default at /var/log/apache2/

Useful References

Finding your way in OS X Yosemite‎

November 12, 2014
This is a kind of confession – I quite often find myself lost on OS X configurations files, installed packages and so on.. And it is embarrassing… really embarrassing…

I started developing software in mid-80s, initially as a hobby, but eventually hobby somehow self-converted into my full-time profession. I started from Assembler 360 (on Soviet clone of IBM 360/370), then moved to Assemblers of IBM PC, following by kernel development for Windows and Linux, embedded systems, VoIP, video streaming, network analysis and many more cool applications/devices/systems…. Bottom line, have quite a baggage to brag about…

Until I got my first Mac – quite late, when it harder to teach old dog new tricks… Actually I was resisting for a while idea to move to Mac – close software, close hardware, no alternative but buy from a single vendor and soon..  But a resistance to Apple is futile – once you forced to work with Mac ( it was AirBook) for a week, you just can’t go back and start wonder how people can ever use anything else but Mac OS ;-).. The only problem is that “old tricks” ( Linux/Windows configurations experience) are often confuse my memory when I need to do something on the OS X, and somehow I think that some old dogs may face quite similar problems… So maybe making my embarrassment public, I can help a few lost souls as well…

Enough with an introduction… This will be a sub-blog about problems i faced while working with OS X, using it as development platform of various application – Java, PHP, C++

Environment (to be updated):
– MacBook Pro with Retina Display ( upgrade from original AirBook)
– OS X Yosemite (10.10)  (upgrade from original 10.7)
– some software installed with MacPort
– some software installed with Fink
– development environment – Eclipse (Luna – 4.4.1)
– Java – JDK 8u25

Expected topics:
– Who installed this shit – finding your way in OS X package managers.
– Configuration for local PHP development & testing
– Configuration for local web app development with Java
– Configuration for Android development ( including NDK debugging).

When Insults Had Class

May 19, 2007

“I didn’t attend the funeral, but I sent a nice letter saying I  approved of it.”
Mark Twain

“I have never killed a man, but I have read many obituaries  with great pleasure.”

Clarence Darrow

“He has all the virtues I dislike and none of the vices I admire.”
Winston Churchill

“A modest little person, with much to be modest about.”
Winston Churchill

“He has never been known to use a word that might send a reader  to the dictionary.”
William Faulkner (about Ernest Hemingway)

“Poor Faulkner. Does he really think big emotions come from big words?”
Ernest Hemingway (about William Faulkner)

“Thank you for sending me a copy of your book; I’ll waste no time
reading it.”
Moses

“He can compress the most words into the smallest idea of any man I
know.”
Abraham Lincoln

“I’ve had a perfectly wonderful evening. But this wasn’t it.”
Groucho Marx

“He has no enemies, but is intensely disliked by his friends.”
Oscar Wilde

“I am enclosing two tickets to the first night of my new play; bring a
friend…. if you have one
George Bernard Shaw to Winston Churchill

“Cannot possibly attend first night, will attend second… if there is
one.”
Winston Churchill, in response

“I feel so miserable without you; it’s almost like having you here.”
Stephen Bishop

“He is a self-made man and worships his creator.”
John Bright

“I’ve just learned about his illness. Let’s hope it’s nothing trivial.”
Irvin S. Cobb

“He is not only dull himself, he is the cause of dullness in others.”
Samuel Johnson

“He is simply a shiver looking for a spine to run up.”
Paul Keating

“He had delusions of adequacy.”
— Walter Kerr

“There’s nothing wrong with you that reincarnation won’t cure.”
Jack E. Leonard

“He has the attention span of a lightning bolt.”
Robert

“They never open their mouths without subtracting from the sum
of human knowledge.”
— Thomas Brackett Reed

“He inherited some good instincts from his Quaker forebears,
but by diligent hard work, he overcame them.”
James Reston (about Richard Nixon)

“In order to avoid being called a flirt, she always yielded easily.”
Charles, Count

“He loves nature in spite of what it did to him.”
Forrest Tucker

“Why do you sit there looking like an envelope without any address on
it?”
Mark Twain

“His mother should have thrown him away and kept the stork.”
Mae West

“Some cause happiness wherever they go; others, whenever they go.”
Oscar Wilde

“He uses statistics as a drunken man uses lamp-posts…
for support rather than illumination.”
Andrew Lang (1844-1912)

“He has Van Gogh’s ear for music.”
Billy Wilder