Tuesday, March 7, 2017

Enabling AMR WB Codec in Linphone

AMRWB codec is by default disabled in linphone as these are not free codecs. AMRWB widely used libraries are opencoreamr (for decoding) and Vo amr (for encode). Below given the steps to enable the AMRWB in the build process.

./prepare.py --debug -DENABLE_NON_FREE_CODECS=ON -DENABLE_AMRWB=OFF&& make

this command forces the non free codec AMRWB to be included in the build process. Once the prepare.py command start execution, it can be noted like below in the build console.

[ 50%] Completed 'EP_ms2'
[ 52%] Built target EP_ms2
[ 52%] Forcing build for 'EP_opencoreamr'
[ 53%] Performing build step for 'EP_opencoreamr'
[ 41%] Built target opencore-amrwb
[100%] Built target opencore-amrnb
[ 54%] Performing install step for 'EP_opencoreamr'
[ 41%] Built target opencore-amrwb
[100%] Built target opencore-amrnb
Install the project...
-- Install configuration: "Debug"
-- Installing: /Users/rr/linphone-iphone/liblinphone-sdk/arm64-apple-darwin.ios/lib/libopencore-amrnb.a
-- Installing: /Users/rr/linphone-iphone/liblinphone-sdk/arm64-apple-darwin.ios/lib/libopencore-amrwb.a
[ 54%] Completed 'EP_opencoreamr'
[ 56%] Built target EP_opencoreamr
[ 56%] Performing configure step for 'EP_voamrwbenc'
loading initial cache file /Users/rr/linphone-iphone/WORK/ios-arm64//tmp/EP_voamrwbenc/EP_voamrwbenc-cache-Debug.cmake
-- Using sysroot path: /Users/rr/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk
-- Using sdk version: 10.2
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/rr/linphone-iphone/WORK/ios-arm64/Build/voamrwbenc
[ 56%] Forcing build for 'EP_voamrwbenc'
[ 57%] Performing build step for 'EP_voamrwbenc'
[100%] Built target vo-amrwbenc
[ 57%] Performing install step for 'EP_voamrwbenc'
[100%] Built target vo-amrwbenc
Install the project...
-- Install configuration: "Debug"
[ 58%] Completed 'EP_voamrwbenc'
[ 60%] Built target EP_voamrwbenc
[ 61%] Performing configure step for 'EP_msamr'
loading initial cache file /Users/rr/linphone-iphone/WORK/ios-arm64//tmp/EP_msamr/EP_msamr-cache-Debug.cmake
-- Using sysroot path: /Users/rr/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk
-- Using sdk version: 10.2
-- Setting install rpath to /Users/rr/linphone-iphone/liblinphone-sdk/arm64-apple-darwin.ios/lib
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/rr/linphone-iphone/WORK/ios-arm64/Build/msamr
[ 62%] Forcing build for 'EP_msamr'
[ 62%] Performing build step for 'EP_msamr'
Scanning dependencies of target msamr-static
[ 33%] Building C object src/CMakeFiles/msamr-static.dir/amrwb.c.o
[ 66%] Linking C static library libmsamr.a
[100%] Built target msamr-static
[ 62%] Performing install step for 'EP_msamr'
[100%] Built target msamr-static
Install the project...
-- Install configuration: "Debug"
-- Installing: /Users/rr/linphone-iphone/liblinphone-sdk/arm64-apple-darwin.ios/lib/mediastreamer/plugins/libmsamr.a
[ 63%] Completed 'EP_msamr'
[ 65%] Built target EP_msamr


In the above process, it builds the opencore AMR decoder and VO AME encoder. Also the media streamer plugin for the AMR is built.

the final library feels can be found under liblinphone-sdk

[x86_64 arm64 armv7] Mixing libopencore-amrnb.a in liblinphone-sdk/apple-darwin/lib/libopencore-amrnb.a
[x86_64 arm64 armv7] Mixing libopencore-amrwb.a in liblinphone-sdk/apple-darwin/lib/libopencore-amrwb.a

[x86_64 arm64 armv7] Mixing libmsamr.a in liblinphone-sdk/apple-darwin/lib/mediastreamer/plugins/libmsamr.a

Great, thats it, it is built.

references:
http://linphone.org/

What if Chromium download fails?

Running client sync itself gives this warning.

+---------------------------------------------------------------------+
| NOTICE: This sync of Chromium will take a long time as several      |
|         gigabytes of data are downloaded. If this is your initial   |
|         sync and it's interrupted, try running 'gclient sync' again.|
|         If that fails, wipe everything clean and start over again.  |
+---------------------------------------------------------------------+
Running "gclient sync --force --revision src@316b880c55452eb694a27ba4d1aa9e74ec9ef342 -v --gclientfile .gclient.tmp --delete_unversioned_trees --reset --upstream --deps=mac,ios,mac" in /Users/rr/WebRTC/one/WebRTC/src/chromium
Looking for .gclient.tmp starting from /Users/rr/WebRTC/one/WebRTC/src/chromium

Loaded .gclient config in /Users/rr/Desktop/WebRTC/WebRTC/src/chromium:
solutions = [{
  'name': 'src',
  'url': 'https://chromium.googlesource.com/chromium/src.git',
  'deps_file': '.DEPS.git',
  'managed': False,
  'custom_deps': {
    # Skip syncing some large dependencies WebRTC will never need.
    'src/chrome/tools/test/reference_build/chrome_linux': None,
    'src/chrome/tools/test/reference_build/chrome_mac': None,
    'src/chrome/tools/test/reference_build/chrome_win': None,
    'src/native_client': None,
    'src/third_party/cld_2/src': None,
    'src/third_party/hunspell_dictionaries': None,
    'src/third_party/liblouis/src': None,
    'src/third_party/pdfium': None,
    'src/third_party/skia': None,
    'src/third_party/trace-viewer': None,
    'src/third_party/webrtc': None,
  },
  'safesync_url': ''
}]

Monday, March 6, 2017

The three magical steps building Unix based distribution

With all credits to the original writer of the blog, this blog is just a summary of my understanding. The original blog link can be found at the reference section in this blog.

Whenever a Unix based distribution is built, it follows the standard three step procedure, which is below.

./configure
make
make install

There are three distinct steps in this process:

1. Configure the software
The configure script is responsible for getting ready to build the software on your specific system. It makes sure all of the dependencies for the rest of the build and install process are available, and finds out whatever it needs to know to use those dependencies.


Unix programs are often written in C, so we’ll usually need a C compiler to build them. In these cases the configure script will establish that your system does indeed have a C compiler, and find out what it’s called and where to find it.

2. Build the software
Once configure has done its job, we can invoke make to build the software. This runs a series of tasks defined in a Makefile to build the finished program from its source code.

The tarball you download usually doesn’t include a finished Makefile. Instead it comes with a template called Makefile.in and the configure script produces a customised Makefile specific to your system.

3. Install the software

Now that the software is built and ready to run, the files can be copied to their final destinations. The make install command will copy the built program, and its libraries and documentation, to the correct locations.

This usually means that the program’s binary will be copied to a directory on your PATH, the program’s manual page will be copied to a directory on your MANPATH, and any other files it depends on will be safely stored in the appropriate place.

Since the install step is also defined in the Makefile, where the software is installed can change based on options passed to the configure script, or things the configure script discovered about your system.

Depending on where the software is being installed, you might need escalated permissions for this step so you can copy files to system directories. Using sudo will often do the trick.


NOTE: Who make these files?

Programs that are built in this way have usually been packaged using a suite of programs collectively referred to as autotools. This suite includes autoconf, automake, and many other programs, all of which work together to make the life of a software maintainer significantly easier. The end user doesn’t see these tools, but they take the pain out of setting up an install process that will run consistently on many different flavours of Unix.

references:
https://robots.thoughtbot.com/the-magic-behind-configure-make-make-install

How Does the build flow in linux look like?


This is a simple elegant diagram i could get from the search. 



references
http://stackoverflow.com/questions/10999549/how-do-i-create-a-configure-script


AMR codec - some number facts.

AMR is a compression format to optimize speech coding consisting of multi-rate narrowband speech codecs. AMR files can be recorded with mobile phones. To accomplish random access or synchronization of audio and video the 3GPP format can be utilized. AMR uses ACELP, DTX, VAD, and CNG to code the 160 20-millisecond samples contained in each frame. AMR files are used for voice recording though the format is usually converted into other files for use and distribution.

AMR is capable of encoding 200-3400 Hz signals from 4.75 to 12.2 kbit/s with quality starting at 7.4 kbit/s. Adopted in 1999 by 3GPP, this method is used by GSM and UMTS, using link adaptation to choose from the 8 different bit rates. AMR optimizes link adaptation with the best codec available in order to be utilized with radio channel and capacity requirements. This is only possible if a good connection is provided to prevent the loss of the audio’s quality.

http://samplephotovideo.com/2015/12/download-amr-adaptive-multi-rate-codec-file/

A look at the GNU build System

This article mentioned in references is an awesome place for getting idea of how the GNU build system works

1. How to build executable from available open source software packages
2. How the whole system works for generating scripts and makefiles, which are the basic infrastructure for building and installing software executables. 

Below are the three golden steps in the GNU system to build and install the software 

1. ./configure => finds out the local environment, check whether packages required are already installed and if everything OK, then write the make files. 
2. make => make build  the binary executables
3. sudo make install => make install installs the executable. 

Below diagram gives good idea of which are the files and processes involved in the build process. 

Below are few more commands that may be useful 

make check => this can be given between make and make install and this runs a set of regression tests assuming these were included in the software by the developers 
 make clean => removes all the files made by make and make check but not the files written by the configure. 
make distclean => If the intent was to remove the files written by configure as well as start fresh. 
make maintainer-clean => it removes all the files that make distclean removes and also removes the files that developer has automatically generated using the GNU build system. 
make uninstall => uninstalls the software 
make dist => makes the compressed archive distribution package 
make distcheck => makes the distribution, unpacks in a sub directory configures, makes the executables and runs the regression test suites to check if everything is OK. 

Now lets see what are the pre-requites for GNU build system. 

- the system should have GNU gcc compiler
- GNU make 
- GNU m4 macro processor version 1.4.5 or above 
- GNU tar programs 
- autoconf, automake, libtool 

Functions of Autoconf
A GNU package may be distributed as source code and it should be possible to make executable under various Posix like systems. This means a developer will have to write make files for each of the platform adapted to it. This is a gigantic task and the Autoconf tool simplifies it. Autoconf tool generate configure (shell script to create make files) adapted to the system in which it has to run. Autoconf tool takes text files configure.ac (former name, configure.in) The configure.ac contains macros to check a system for features that a software package might use. autoconf invokes the m4 macro processor to generate the configure the script. 

Functions of Automake 
Automaker is a tool for generating the file Makefile.in from a template file Makefile.am 

Functions of Autoheader 
auto header program scans the configure.ac and generates the file config.h.in containing info about all the preprocessor macros that need to be defined. 

aclocal program creates the file aclocal.m4 containing the macro definitions required by autoconf. 

references:

Building Opencore AMR decoder

Download the source distribution from the link http://sourceforge.net/projects/opencore-amr/files/opencore-amr/
(at this writing the version number is 0.1.4)

Extract to the file system and make using the below commands For e.g

./configure --prefix=/Users/retheeshravi/Downloads/opencore-amr-0.1.4/rrbld
make && make install

This builds the libopencore-amrwb.a & libopencore-amrnb.a files inside the /rrbld/lib folder.

To make the AMR test code, need to do the below
Move to the folder below and execute the Make command
/opencore-amr-0.1.4/test/

Make

This produces amr-nb and amr-wb executables.

/amrnb-dec sample_amr.amr sample_wav.wav

the file present at this link seems to be narrowband one.

http://samplephotovideo.com/2015/12/download-amr-adaptive-multi-rate-codec-file/

references:

http://sourceforge.net/projects/opencore-amr/files/opencore-amr/