Wednesday, July 30, 2014

WebRTC an overview

WebRTC is a free open project that enables web browsers with Real Time Communication capabilities via simple Javascript APIs. The WebRTC components have been optimised to best serve this purpose.

The WebRTC initiative is a project supported by Google, Mozilla and Opera. The webpage given in reference is initiated by Google Chrome team.

Below are few terms we should be familiar on the WebRTC front.



Web App
This is the component which is a web application enabled with audio and video capabilities powered by the web APIs for real time communication.

Web API
This is the set of APIs which is used by the web developer to make real time chat applications

WebRTC native C++ API
This is the API layer which enables browser makers to easily implement the Web API proposal.

Transport / Session
The session components are built by re-using components from lib jingle, without using or requiring the xmpp/jingle protocol.

RTP Stack
A network stack for RTP, real time protocol

STUN/ICE
A component which allows calls to make use of STUN or ICE mechanisms to establish connection across various types of networks.

Session Mananagement
An abstract session layer, allowing calls setup and management layer. This leaves protocol implementation decision to the application developer.

Voice Engine
VoiceEngine is the framework for the audio media chain, from the sound card to the networks.

iSAC, iBLC, Opus
iSAC : A sideband and super sideband audio codec for VoIP and streaming audio. iSAC uses 16khz or 32 KHz sampling frequency with an adaptive and variable bit rate of 12 to 52 kbps

iLBC: A narrowband speech codec for VoIP and streaming audio. Uses 8KHz sampling frequency with a bit rate of 15.2 kbps for 20 ms frames and 13.33 kbps for 30ms frames.

Opus: Supports constant and variable nitrate encoding from 6Kbp/s to 510 kbit/s frame sizes from 2.5ms to 60ms and various sampling rates from 8KHz (with 4KHZ bandwidth) )to 48KHz (with 20KHz bandwidth where entire hearing range of human auditory system can be reproduced.)

NetEQ for voice
A dynamic jitter buffer and error concealment algorithm used for concealing the negative effects of network jitter and packet loss. This keeps latency as low as possible while ensuring high audio quality.

Acoustic Echo Canceller(AEC)
AEC is a software based signal processing component that removes in real time the echo resulting from audio being played out coming into the active microphone.

Noice Reduction (NR)
The NR component is software based signal processing component that removes certain types of background noise usually with VoIP. (Hiss, fan noise etc)

Video Engine
Video engine is a framework video media chain for video. from camera to network, and from network to the screen.

VP8
Video codec from the WebM project. Well suited for RTC as it is designed for low latency.

Video Jitter buffer
Dynamic jitter buffer for video. Helps conceal the effects of jitter and packet loss on overall video quality.

Image enhancements
This component removes the video noise from the image captured by the webcam.

References:

Thursday, July 24, 2014

The Hopper Dis-assembler


The hopper disassembler can be found here http://hopperapp.com/download.html 

Hopper is a tool that will assist developer in static analysis of the binary file.
The demo version is quite good for some initial investigation of the binary. 

the idea of hopper is that it accepts a set of bytes and coverts into something readable by humans

There are various types that can be used in hopper. they are below 

data : an area is set to data type when Hopper thinks that it is an area that represents a constant, like an array of int for instance 
ASCII : a NULL terminated C string 
code : an instruction 
procedure: a byte receive this type once it has been determined that it is part of a method that has been successfully reconstructed by Hopper. 
undefined : this is an area that have not been explored by Hopper. 

As soon as an executable is loaded, one can manually change the type, by using either they keyboard, or the toolbar on the top of the window. 

D | A | C | P | U

Navigating through the file
An executable is split up into smaller piece of data called segments and sections. 

When OS loads an executable, some part of it get loaded to system memory. Each continuous piece of the file mapped into memory is called segments. These segments are splitted into smaller parts called sections which will receive various access properties. 

The hopper allows user to name an address so that the piece of code can be identified using the label within the binary file. 

The tool provides a Navigation bar which shows up the colour scheme. blue for code, yellow for procedure, green for ASCII strings, purple for data, grey for undefined. 

There is an inspector component which shows below main components 

1. Instruction Encoding -> This component display the bytes of the current instruction. If the current processor is having multiple CPU types, user will see popup menu which lets the user to change the CPU modes at the current address. Different cpu types are ARM And Thumb. 

Format: This component is used to change the display format of the operand of an instruction 

Comment : This component allows user to add comment at a given address. 

Colors and Tags: This component allows user to associate tags to addresses, block of procedure, or procedure itself. 

References: This is very important component. This shows all the references one instruction can have to other instructions or a piece of data. User can even add own reference too if hopper analysis did not add a reference. 


Procedure: This component contains information on the current procedure. 

References:

Tuesday, July 22, 2014

iOS Core Plot Library

Application needs to create an instance of CPTGraphHostingView which is hosting the graph view. In this class, there is hostedGraph which is an instance of CPTGraph which is a generic interface. In this case, we can have the CPTXYGraph  instance which is Bar chart kind of graph. 

    CPTXYGraph *barChart = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
    barGraph.hostedGraph             = barChart;
    barGraph.allowPinchScaling = NO;
    
    barChart.paddingLeft   = 35.0;
    barChart.paddingTop    = 20.0;
    barChart.paddingRight  = 20.0;

We can also apply a theme for the graph using the below statements 

 CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainBlackTheme];
    [barChart applyTheme:theme];
    
    barChart.plotAreaFrame.masksToBorder = NO;
    barChart.plotAreaFrame.borderLineStyle = nil;

The Axis style can be set like below     

CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
    majorGridLineStyle.lineWidth            = 0.1;
    majorGridLineStyle.lineColor            = [[CPTColor whiteColor] col


We can give the Axis labels like this below 

CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[months objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
        newLabel.tickLocation = [tickLocation decimalValue];
        newLabel.offset       = x.labelOffset + x.majorTickLength;
        [customLabels addObject:newLabel];

 x.axisLabels = [NSSet setWithArray:customLabels];

Now we can draw each of the bar like in the below code

CPTBarPlot *barPlot = [[CPTBarPlot alloc] init];
    barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:87/255.0 green:142/255.0 blue:242/255.0 alpha:1.0]];
    barPlot.dataSource      = self;
    barPlot.barCornerRadius = 2.0f;
    barPlot.delegate        = self;
    barPlot.lineStyle = barLineStyle;
    barPlot.baseValue = CPTDecimalFromFloat(0.0f);

Application needs to implement the methods of CPTPlotDataSource so that the bar is supplied with the data 
The only mandatory method is 
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot;

Other methods such as below are optional in the API
-(NSArray *)numbersForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange;
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx;
-(double *)doublesForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange;
-(double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx;
-(CPTNumericData *)dataForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange;
-(CPTNumericData *)dataForPlot:(CPTPlot *)plot recordIndexRange:(NSRange)indexRange;
-(NSArray *)dataLabelsForPlot:(CPTPlot *)plot recordIndexRange:(NSRange)indexRange;

-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)idx;

references:
http://www.raywenderlich.com/13269/how-to-draw-graphs-with-core-plot-part-1

Sunday, July 20, 2014

Android : List view


Android has ListView and ExpandableListView classes capable of displaying scrollable list of items. The ExpandableListView supports a scrollable list of items. 
An Adapter manages the data model and adapts to the individual rows in the list view. An Adapter extends the BaseAdapter class. 
Every line in the list view consists of a layout and application can choose the complexity of it. 

Adapters 

An Adapter manages the data model and adapts to the individual rows in the list view. An adapter extends the BaseAdapter class. The Adapter would inflate the layout for each row in its getView method and assign data to the individual views in the row. 
The Adapter is assigned to the ListView via the setAdapter method in the ListView object. 

the default normal adapters provided by the system are ArrayAdapters and CursorAdapter 

A sample of ListView with ArrayAdapter 

- First of all make the layout in the xml like below 
android:id="+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

By default if Application provides a simple array adapter, each element n the array adapter array will be taken as the row item and display it in the list view 

Applications can create a list view row with own layout. A sample given below which shows an image view and a text view in a row 

android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
/>
android:id="+id/textview"
/>

After this, in the code, the below can be done 

String[] values = new String[]{"Android" , "iPhone", "WindowsMobile", "Blackberrty" , "WebOS" };
ArrayAdapter adapter = new ArrayAdapter (this, R.layout.rowlayout, R.id.label, values);
setLlistAdapter (adapter)

Application can create an Own adapter as well. Below sample code shows the 

extends from the Simple Adapter such as array adapter overrider the getView method 

public class MySimpleCustomAdapter extends ArrayAdapter
{
private final Context context; 
private final String[] values;
public MySimpleCustomAdapter (Context context, String[] values)
{
super(context, R.layout.rowlayout, values);
this.context = context; 
this.values = values;
}
@override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflator inflator = (LayoutInflator) context.getSystemService(Context.LAYOUT_INFLATOR_SERVICE);
View rowView  = inflator.inflate(R.layout.rowLayout,parent,false);
TextView tview = (TExtView)rowView.findViewById(R.id.label);
ImageView view = (ImageView) rowView.findViewById(R.id.imageview);
tview.setText(values[position]);
view.setImageResource(R.drawble.mycustomimage);
}
}

references: 

Saturday, July 19, 2014

JIRA Integration via REST APIs

The main step in JIRA integration is authentication. JIRA provides mainly three methods for authentication 

1. Simple mechanism 

In this method, application passes the username and password as a plain text to the network layer. Based on whether it is http or https, the data is sent to the server unencrypted or encrypted. 

below is a sample curl command that demonstrate this. 


curl -v -u myusername:mypassword  https://examplejira.atlassian.net/rest/api/latest/search?jql=project=TWCIOS&startAt=0&maxResults=200

2. Supplying Basic auth headers. 
In this mechanism, application passes the Authorization header to the network layer. Authorizaton header is constructed by Base64 encoding the username:password combination. 

For e.g.  

curl -D- -X GET -H "Authorization: Basic VHlwZSAob3IgcGFzdGUpIGhlcmUuLi4=" -H "Content-Type: application/json" "http://kelpie9:8081/rest/api/2/issue/QA-31"

Where VHlwZSAob3IgcGFzdGUpIGhlcmUuLi4= Is the base64 encoded value of myusername:my password 

OAuth based authentication 
For providing OAuth based authentication, the basic terminologies related to the OAuth authentication needs to be in mind, they are Consumer, Service Provider, request, token, access token. 

Step 1: 

The first step is to register a new consumer in JIRA. This is done through the application links administration screens in JIRA. When creating the application link, we can specify URL which can be a placeholder URL or a correct URL of the client. If the client can be reached via http url, select the General Application type. After the application link has been created, edit the configuration and go to the incoming authentication configuration screen and select OAUTH. Enter in this the public key and the consumer key which the client will use when making request to JIRA. 

After these configurations are done, press OK to ensure the authentication is enabled. 

Step 2: 

This step is about configuring the client. 
Client will require the following information to make authentication request in JIRA. 

request token url : JIRA_BASE_URL + "/plugins/servlet/oauth/request+token"
authorisation url : JIRA_BASE_URL + "/plugins/servlet/oauth/authorize
access token url : JIRA_BASE_URL + "/plugins/servlet/oauth/access-token 
oath sign type  : RSA-SHA1
consumer key : Key that is configured in step 1 

In short the above in for below 

1. Obtain a request token 
2. Authorize the request token 
3. Swap the request token with access token 

Step 3: 
Now having the access token, application can make the request to the specific REST JIRA APIs 


References: 

https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+OAuth+authentication
https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Basic+Authentication#JIRARESTAPIExample-BasicAuthentication-Authenticationchallenge

Sunday, July 13, 2014

Android : Compound Controls

If the Application requirement is to just group a certain already existing component and create it as a group, This is also possible in android and this is categorised as Compound Controls. 
There are already some components in System framework which does this. For e.g. Spinner, AutoCompleteTextView 

Below are the steps to create a CompoundControl 

1. The usual starting point is layout of some kind, so, create a class that extends the Layout. For e.g. LinearLayout. The layout can be nested inside to make complex compound components. Note that just like with an Activity, you can use either the declarative (XML based) approach to creating the contained components, or application can nest them programmatically in the code. 

2. In the constructor of the new class, take whatever parameters the superclass expects. and pass them through to the super contractor first. After this, the component component can set up other components those are readily available or other custom components. Note that application might also introduce own attributes and parameters into XML that can be pulled out and used by the new compound controls constructor. 

3. Compound controls can also have own listeners 

4. Compound controls can expose new properties and methods that may deem necessary for the functionality and usefulness of the component 

5. In case application is extending a layout, application don't need to override onDraw() or onMeasure methods since the layout will have default behavior that will likely just work fine. However, application can override it still would like to. 

6. The application can override other on… methods such as onKeyDown if required. 

There is a Compound component example given in the 

With this in mind, lets create a CardView similar to single card in Pinterest app. The card can have ImageView that contains the main image and Label Below it and a separator image, then an image in round shape for the profile picture and a label for description. The sample is List4.java and List6.java 

The List6.java class creates a SpeachView class as a compound class. This compound component is created programmatically. And holds two TextView components. 

The class is declared as extending the LinearLayout. Other methods such as onMeasure and onLayout are not overridden in this class, which means that it lets the system to layout the components within it. 

References: 


Android Custom View - A Look at LabelView class


The LabelView class demonstrates a Custom LabeView which draws the given text. This example doesn't load anything from a layout XML file, instead it paints the text. This is done by overriding the onDraw method like below 

@override 
protected void onDraw(Canvas canvas)
super.onDraw(canvas);
canvas.drawText(mText, getPaddingLeft(), getPaddingTop() - mAscent, mTextPaint);
}

Other  important functions is onMeasure, This function is important to let the parent know that how much amount of space this component require 

The implementation is like below 

@override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
setMeasuredDimension( measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)); 

the widthMeasureSpec and heightMeasureSpec are int values which is a package of multiple measure spec attributes for e.g. specMode, specSize, which can be extracted using the MeasureSpec class 

A Typical implementation is like below 

private int measureWidth (int measureSpec)
{
int result = 0; 
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if(specMode == MeasureSpec.EXACTLY)
{
//We were told how big it would be 
result  = specSize;
}
else 
{
result = (int) mTextPaint.measureText(mText) + getPaddingLeft() + getPaddingRight(); 
if(specMode == MeasureSpec.AT_MOST)
{
result  = Math.min(result, specSize);
}
}
return result; 
}

I decided to take this and layout in the Custom Layout engine i created. And below are few observations from this. 
As usual, came across the issue where style able is not present in the workspace i have. A workaround like this did solve the problem 

onMeasure, the individual views have been passed with MeasureSpec value as UNSPECIFIED for specMode.
Based on the passed in value, the LabelView class computed the measurable width and height. But since the layout was called with the 
absolute value, the view was still looking according to how the CardLayout wanted. 

However, tried to use the modified measured values by the LabelView which was returned like values 57 and 17 which was not sufficient to display the view
But it did work with a 20px more from the measured value. 

References: