<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>roman10</title>
	<atom:link href="http://www.roman10.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.roman10.net</link>
	<description>A Journey to Software Craftsmanship</description>
	<lastBuildDate>Fri, 17 May 2013 13:00:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>Android Property Animation Overview</title>
		<link>http://www.roman10.net/android-property-animation-overview/</link>
		<comments>http://www.roman10.net/android-property-animation-overview/#comments</comments>
		<pubDate>Sun, 12 May 2013 02:02:19 +0000</pubDate>
		<dc:creator>roman10</dc:creator>
				<category><![CDATA[Animation]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.roman10.net/?p=1060</guid>
		<description><![CDATA[</p> <p>Property animation is introduced in Android 3.0 Honeycomb. A whole new set of APIs comes with the android.animation package (The view animation is exposed through android.view.animation package), which makes animation in Android more flexible and powerful. </p> <p>1. Limitation of View Animation System</p> <p>The property animation system is introduced to tackle the limitations of [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>Property animation is introduced in Android 3.0 Honeycomb. A whole new set of APIs comes with the android.animation package (The view animation is exposed through android.view.animation package), which makes animation in Android more flexible and powerful.  </p>
<p><strong>1. Limitation of View Animation System</strong></p>
<p>The property animation system is introduced to tackle the limitations of the view animation systems in pre-3.0 Android as described below. </p>
<p>Firstly, we can only animate views. This is enough most of the times since animation manipulates the GUI, which consists of views. However, there are times we want to animate non-view objects or properties, then we are on our own. For example, if we have a custom view implemented by drawing a few drawables on canvas and we want to animate the individual drawable, we won’t be able to use the view animation system.  </p>
<p>Secondly, the animation is constrained to position, size, rotation etc. Properties like background color is not supported by the view animation system.  </p>
<p>Thirdly, the view animation system only updates where the view is drawn, but not the view itself. This can cause issues sometimes. For example, if we animate a button to move outside of current screen, after the animation ends, the button is not shown on screen, but we can still click the button’s original location to trigger click event. This is because the location of the button is not changed, though its not drawn on the screen. In this case, we’ll need to write additional code to make sure the button behave properly.  </p>
<p><strong>2. The android.animation package</strong></p>
<p>The property animation system APIs are exposed by the android.animation package. The hierarchy of the main classes in the package is as below.<img style="display: block; float: none; margin-left: auto; margin-right: auto" height="266" src="https://lh5.googleusercontent.com/VIzxgzHnxn-p-6BQqazQO-CtiatZsAHp3anCNa8XG1eW_ST-_Vfd8zBHsnVl6fB7a_gbgRzjDMIIFxJygc1V9RBlHsaZSsv74hDKeKAJeE9b_8IjAHfDDjwh" width="367"/> </p>
<p align="center"><em>Fig 1. android.animation class hierarchy</em></p>
<p><strong><em>ValueAnimator</em></strong>: it is the core the property animation system. There’re two steps to animate a property, including calculating the animated values and assign the values to the property of the animated object. The ValueAnimator can handle the first part but not the second.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto" height="278" src="https://lh5.googleusercontent.com/ja7620wtLOYYJOzjiCgoL0oSctUCylTUUpfABT_9KPSSvvd97d-ocZanVxNurdH0Vthg0hYp8_y63z7opoiqELsiDuTr6NR1-22Izm4nxHNMCs2mGbbuqSO9" width="279"/></p>
<p align="center"><em>Fig 2. ValueAnimator class</em> </p>
<p>The class allows us to specify a time interpolator to control the speed and type evaluator to control the animation values. We’ll cover more about those in future posts.  </p>
<p><strong><em>ObjectAnimator</em></strong>: it’s a subclass of ValueAnimator, which handles both steps of the property animation for us. In other words, it updates the target property value when calculating the animated values.  </p>
<p><strong><em>AnimatorSet</em></strong>: it provides interfaces to group animations together. We can play animations together, sequentially, one after another, etc.  </p>
<p><strong><em>TimeAnimator</em></strong>: This class is introduced in API level 16 (Android 4.1 Jelly Bean). It provides a simple callback mechanism with the TimeAnimator.TimeListener interface. All animators in the system is synchronized by Android system animation frame event. TimeAnimator allows us to get notified with the animation frame event through the TimeListener interface. The method onTimeUpdate will be triggered with the TimeAnimator instance, the total animation time elapsed since the animator started and the time elapsed since preview frame, in milliseconds.  </p>
<p><strong>3. NineOldAndroids Library</strong>  </p>
<p>NineOldAndroids is an amazing library which enables property animation all the way back to Android 1.0. Well, not everything of property animation, but most of it. (e.g. layout animation is left out.) </p>
<p>In order to support the property animation, the library use a wrapper class named AnimatorProxy to wrap a view. The wrapper class facilitates modification of post-3.0 view properties on pre-3.0 platforms and draw the view property.  </p>
<p><strong>References:</strong> </p>
<p>1. NineOldAndroids: <a href="http://nineoldandroids.com/">http://nineoldandroids.com/</a> </p>
<p>2. Google Developer Blog, Animation in Honeycomb: <a href="http://android-developers.blogspot.sg/2011/02/animation-in-honeycomb.html">http://android-developers.blogspot.sg/2011/02/animation-in-honeycomb.html</a> </p>
<p>3. Android API Guides, Property Animation: <a href="http://developer.android.com/guide/topics/graphics/prop-animation.html">http://developer.android.com/guide/topics/graphics/prop-animation.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.roman10.net/android-property-animation-overview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android NDK Cookbook Published</title>
		<link>http://www.roman10.net/android-ndk-cookbook-published/</link>
		<comments>http://www.roman10.net/android-ndk-cookbook-published/#comments</comments>
		<pubDate>Tue, 02 Apr 2013 14:46:52 +0000</pubDate>
		<dc:creator>roman10</dc:creator>
				<category><![CDATA[My Publication]]></category>

		<guid isPermaLink="false">http://www.roman10.net/?p=1057</guid>
		<description><![CDATA[<p>Note: Android NDK Cookbook ebook 40% discount with promotion code MREANC40 at <a href="http://www.packtpub.com/android-native-development-kit-cookbook/book">Packt Publishing</a>. The promotion code is valid until 15th June.</p> <p>Finally, my first book <a href="http://www.packtpub.com/android-native-development-kit-cookbook/book" target="_blank">Android Native Development Kit (NDK) Cookbook</a> is published. I started writing this book from Jun 2012, and the book is published on Mar 26 2013. It’s almost 10 [...]]]></description>
			<content:encoded><![CDATA[<p>Note: Android NDK Cookbook ebook 40% discount with promotion code MREANC40 at <a href="http://www.packtpub.com/android-native-development-kit-cookbook/book">Packt Publishing</a>. The promotion code is valid until 15th June.</p>
<p>Finally, my first book <a href="http://www.packtpub.com/android-native-development-kit-cookbook/book" target="_blank">Android Native Development Kit (NDK) Cookbook</a> is published. I started writing this book from Jun 2012, and the book is published on Mar 26 2013. It’s almost 10 months.</p>
<p>It takes lots of effort to write a book. I wrote lots of sample code; I read a few books to understand certain topics better; the drafts were polished again and again. The reviewers and the editors from the publisher (<a href="http://www.packtpub.com/" target="_blank">Packt Publishing</a>) also spent lots of time reviewing and editing the drafts.</p>
<p><a href="http://www.packtpub.com/android-native-development-kit-cookbook/book" target="_blank"><img style="display: block; float: none; margin-left: auto; margin-right: auto; border: 0px;" title="1505OT" src="http://www.roman10.net/wp-content/uploads/2013/04/1505OT.jpg" alt="1505OT" width="179" height="217" border="0" /></a></p>
<p>The book consists of 11 chapters, divided into 4 parts. Chapter 1 ~ 3 covers the basics, including NDK environment set up, JNI, and NDK build and debug techniques. Chapter 4 ~ 7 introduces various Android NDK libraries, including OpenGL ES 1.x and 2.0, native application library, multithread API, jnigraphics, OpenSL ES, OpenMAX AL etc. Chapter 8 ~ 9 talks about how to port existing libraries and applications to Android with NDK. Chapter 10 ~ 11 discusses how to write multimedia apps and games with Android NDK. Chapter 10 and 11 are available online only to keep the number of pages no more than expected number.</p>
<p>Chapter 8 is a sample chapter available online. One can take a look at the chapter <a href="http://www.packtpub.com/sites/default/files/9781849691505_Chapter_08.pdf?utm_source=packtpub&amp;utm_medium=free&amp;utm_campaign=pdf" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.roman10.net/android-ndk-cookbook-published/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Record WAVE Audio on Android</title>
		<link>http://www.roman10.net/record-wave-audio-on-android/</link>
		<comments>http://www.roman10.net/record-wave-audio-on-android/#comments</comments>
		<pubDate>Tue, 19 Mar 2013 14:55:06 +0000</pubDate>
		<dc:creator>roman10</dc:creator>
				<category><![CDATA[Android Tutorial]]></category>
		<category><![CDATA[API illustrated]]></category>
		<category><![CDATA[Digital Audio Processing]]></category>
		<category><![CDATA[Digital Signal Processing]]></category>
		<category><![CDATA[Multimedia API]]></category>

		<guid isPermaLink="false">http://www.roman10.net/?p=1053</guid>
		<description><![CDATA[<p>This post discusses how to record raw audio (PCM) and save it to wave file on Android. If you’re not familiar with WAVE audio file format, please refer to a previous post, <a href="http://www.roman10.net/wave-audio-file-format/" target="_blank">WAVE Audio File Format</a>. </p> <p>The post is a follow up post for <a href="http://www.roman10.net/record-pcm-audio-on-android/" target="_blank">Record PCM Audio on Android</a>. The [...]]]></description>
			<content:encoded><![CDATA[<p>This post discusses how to record raw audio (PCM) and save it to wave file on Android. If you’re not familiar with WAVE audio file format, please refer to a previous post, <a href="http://www.roman10.net/wave-audio-file-format/" target="_blank">WAVE Audio File Format</a>. </p>
<p>The post is a follow up post for <a href="http://www.roman10.net/record-pcm-audio-on-android/" target="_blank">Record PCM Audio on Android</a>. The code and working principle are similar. It is strongly suggested you read it first. </p>
<p>WAVE file is used to store PCM data, with 44-byte header. Recording WAVE audio is equivalent to recording PCM audio and adding the 44-byte header in front. </p>
<p>We used a RandomAccessFile to write the data. We first write 44-byte header. Because some fields are not known until we finish the recording, we simply write zeros. This is shown as below.</p>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">randomAccessWriter = <span style="color: #0000ff">new</span> RandomAccessFile(filePath, <span style="color: #006080">"rw"</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">randomAccessWriter.setLength(0); <span style="color: #008000">// Set file length to 0, to prevent unexpected behavior in case the file already existed</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">randomAccessWriter.writeBytes(<span style="color: #006080">"RIFF"</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">randomAccessWriter.writeInt(0); <span style="color: #008000">// Final file size not known yet, write 0 </span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">randomAccessWriter.writeBytes(<span style="color: #006080">"WAVE"</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">randomAccessWriter.writeBytes(<span style="color: #006080">"fmt "</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">randomAccessWriter.writeInt(Integer.reverseBytes(16)); <span style="color: #008000">// Sub-chunk size, 16 for PCM</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">randomAccessWriter.writeShort(Short.reverseBytes((<span style="color: #0000ff">short</span>) 1)); <span style="color: #008000">// AudioFormat, 1 for PCM</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">randomAccessWriter.writeShort(Short.reverseBytes(nChannels));<span style="color: #008000">// Number of channels, 1 for mono, 2 for stereo</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">randomAccessWriter.writeInt(Integer.reverseBytes(sRate)); <span style="color: #008000">// Sample rate</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">randomAccessWriter.writeInt(Integer.reverseBytes(sRate*nChannels*mBitsPersample/8)); <span style="color: #008000">// Byte rate, SampleRate*NumberOfChannels*mBitsPersample/8</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">randomAccessWriter.writeShort(Short.reverseBytes((<span style="color: #0000ff">short</span>)(nChannels*mBitsPersample/8))); <span style="color: #008000">// Block align, NumberOfChannels*mBitsPersample/8</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">randomAccessWriter.writeShort(Short.reverseBytes(mBitsPersample)); <span style="color: #008000">// Bits per sample</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">randomAccessWriter.writeBytes(<span style="color: #006080">"data"</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">randomAccessWriter.writeInt(0); // Data chunk size not known yet, write 0</pre>
<p><!--CRLF--></div>
</div>
<p>We then write the PCM data. This is discussed in detail in post <a href="http://www.roman10.net/record-pcm-audio-on-android/" target="_blank">Record PCM Audio on Android</a>. </p>
<p>After the recording is done, we seek to the header and update a few header fields. This is shown as below.</p>
</p>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">audioRecorder.stop();</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">try</span> {</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    randomAccessWriter.seek(4); <span style="color: #008000">// Write size to RIFF header</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    randomAccessWriter.writeInt(Integer.reverseBytes(36+payloadSize));</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    randomAccessWriter.seek(40); <span style="color: #008000">// Write size to Subchunk2Size field</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    randomAccessWriter.writeInt(Integer.reverseBytes(payloadSize));</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    randomAccessWriter.close();</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">} <span style="color: #0000ff">catch</span>(IOException e) {</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">    Log.e(WavAudioRecorder.<span style="color: #0000ff">class</span>.getName(), <span style="color: #006080">"I/O exception occured while closing output file"</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">    state = State.ERROR;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">}</pre>
<p><!--CRLF--></div>
</div>
<p>For the complete source code, one can refer to <a href="https://github.com/roman10/roman10-android-tutorial/tree/master/AndroidWaveRecorder" target="_blank">my github Android tutorial project</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.roman10.net/record-wave-audio-on-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Record PCM Audio on Android</title>
		<link>http://www.roman10.net/record-pcm-audio-on-android/</link>
		<comments>http://www.roman10.net/record-pcm-audio-on-android/#comments</comments>
		<pubDate>Sun, 10 Mar 2013 12:57:04 +0000</pubDate>
		<dc:creator>roman10</dc:creator>
				<category><![CDATA[Digital Audio Processing]]></category>
		<category><![CDATA[Multimedia API]]></category>

		<guid isPermaLink="false">http://www.roman10.net/?p=1051</guid>
		<description><![CDATA[<p>This post discusses how to record PCM audio on Android with the android.media.AudioRecord class. If you’re not familiar with PCM, please read a previous post <a href="http://www.roman10.net/pcm-audio-format/" target="_blank">PCM Audio Format</a>. </p> <p>For the source code, please refer to <a href="https://github.com/roman10/roman10-android-tutorial/tree/master/AndroidPCMRecorder" target="_blank">AndroidPCMRecorder</a>. </p> <p>1. State Transition</p> <p>The source code records the PCM audio with PcmAudioRecorder.java, which [...]]]></description>
			<content:encoded><![CDATA[<p>This post discusses how to record PCM audio on Android with the android.media.AudioRecord class. If you’re not familiar with PCM, please read a previous post <a href="http://www.roman10.net/pcm-audio-format/" target="_blank">PCM Audio Format</a>. </p>
<p>For the source code, please refer to <a href="https://github.com/roman10/roman10-android-tutorial/tree/master/AndroidPCMRecorder" target="_blank">AndroidPCMRecorder</a>. </p>
<p><strong>1. State Transition</strong></p>
<p>The source code records the PCM audio with PcmAudioRecorder.java, which uses Android AudioRecord internally. Similar to the Android MediaRecorder class, PcmAudioRecorder follows a simple state machine as shown below.</p>
<p><a href="http://www.roman10.net/wp-content/uploads/2013/03/Untitleddrawing.jpg"><img title="Untitled drawing" style="border-right: 0px; border-top: 0px; display: block; float: none; margin-left: auto; border-left: 0px; margin-right: auto; border-bottom: 0px" height="414" alt="Untitled drawing" src="http://www.roman10.net/wp-content/uploads/2013/03/Untitleddrawing_thumb.jpg" width="591" border="0"/></a></p>
<p align="center">Figure 1. State Transition of PcmAudioRecorder Class</p>
<p align="left">As indicated in the diagram, we initialize a PcmAudioRecorder class by either calling the getInstance static method or the constructor to get into INITIALIZING state. We can then set the output file path and call prepare to get into PERPARED state. We can then start recording by calling&nbsp; start method and finally call stop to stop the recording. At any state except ERROR, we can call reset to get back to INITIALIZING state. When we’re done with recording, we can call release to discard the PcmAudioRecorder object. </p>
<p><strong>2. Filling the Buffer with Data and Write to File</strong></p>
<p> One particular part of the code requires a bit attention is the updateListener. We register the listener with the AudioRecord object using setRecordPositionUpdateListener method. The listener is an interface with two abstract methods, namely onMarkerReached and onPeriodicNotification. We implemented the onPeriodicNotification method to pull the audio data from AudioRecord object and save it to the output file. </p>
<p>In order for the listener to work, we need to specify the notification period by calling AudioRecord.setPositionNotificationPeriod(int) to specify how frequently we want the listener to be triggered and pull data. The method accepts a single argument, which indicates the update period in number of frames. This leads us to next section. </p>
<p><strong>3. Frame vs Sample</strong></p>
<p>For PCM audio, a frame consists of the set of samples from all channels at a given point of time. In other words, the number of frames in a second is equal to sample rate. </p>
<p>However, when the audio is compressed (encoded further to mp3, aac etc.), a frame consists of compressed data for a whole series of samples with additional, non-sample data. For such audio formats, the sample rate and sample size refer to data after decoded to PCM, and it’s completely different from frame rate and frame size. </p>
<p>In our sample code, we set the update period for setPositionNotificationPeriod as number of frames in every 100 millisecond, therefore the listener will be triggered every 100 milliseconds, and we can pull data and update the recording file every 100 milliseconds. </p>
<p>Note that source code is modified based on <a href="http://i-liger.com/sites/default/files/ExtAudioRecorder.java" target="_blank">ExtAudioRecorder.java</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.roman10.net/record-pcm-audio-on-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WAVE Audio File Format</title>
		<link>http://www.roman10.net/wave-audio-file-format/</link>
		<comments>http://www.roman10.net/wave-audio-file-format/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 14:35:38 +0000</pubDate>
		<dc:creator>roman10</dc:creator>
				<category><![CDATA[Digital Audio Processing]]></category>
		<category><![CDATA[Digital Signal Processing]]></category>
		<category><![CDATA[Multimedia Basics]]></category>

		<guid isPermaLink="false">http://www.roman10.net/?p=1047</guid>
		<description><![CDATA[<p>WAV (Waveform Audio File Format, also known as WAVE) is a commonly used audio file format for storing raw audio samples on Windows. It follows the RIFF (Resource Interchange File Format) generic format. </p> <p>0. The Format </p> <p>A wave file is a RIFF file with a “WAVE” chunk. The WAVE chunk consists of two [...]]]></description>
			<content:encoded><![CDATA[<p><strong>WAV</strong> (<strong>Waveform Audio File Format</strong>, also known as <strong>WAVE</strong>) is a commonly used audio file format for storing raw audio samples on Windows. It follows the <strong>RIFF</strong> (<strong>Resource Interchange File Format</strong>) generic format.  </p>
<p><strong>0. The Format</strong> </p>
<p>A wave file is a RIFF file with a “WAVE” chunk. The WAVE chunk consists of two subchunks, namely “fmt ” and “data”. (Note that there’s a space in “fmt ”). Below we list out the meanings of each field in a WAVE file.</p>
<table style="width: 100%; height: 1184px" cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr>
<td valign="top" width="104">
<p><strong>field</strong></p>
</td>
<td valign="top" width="92">
<p><strong>length</strong></p>
</td>
<td valign="top" width="66">
<p><strong>endian</strong></p>
</td>
<td valign="top" width="198">
<p><strong>Note</strong></p>
</td>
<td valign="top" width="123"></td>
</tr>
<tr>
<td valign="top" width="104">
<p>Chunk Tag</p>
</td>
<td valign="top" width="92">
<p>4</p>
</td>
<td valign="top" width="66">
<p>big</p>
</td>
<td valign="top" width="198">
<p>“RIFF”</p>
</td>
<td valign="top" width="123">
<p>RIFF chunk descriptor</p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>Chunk Size</p>
</td>
<td valign="top" width="92">
<p>4</p>
</td>
<td valign="top" width="66">
<p>little</p>
</td>
<td valign="top" width="198"></td>
</tr>
<tr>
<td valign="top" width="104">
<p>type </p>
<p>&#8212;&#8212;-</p>
</td>
<td valign="top" width="92">
<p>4 </p>
<p>&#8212;&#8212;</p>
</td>
<td valign="top" width="66">
<p>big </p>
<p>&#8212;&#8212;</p>
</td>
<td valign="top" width="198">
<p>“WAVE” </p>
<p>&#8212;&#8212;&#8212;</p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>subchunk id (fmt )</p>
</td>
<td valign="top" width="92">
<p>4</p>
</td>
<td valign="top" width="66">
<p>big</p>
</td>
<td valign="top" width="198">
<p>“fmt ”</p>
</td>
<td valign="top" width="123">
<p>fmt subchunk: format information about the audio data </p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>subchunk size</p>
</td>
<td valign="top" width="92">
<p>4</p>
</td>
<td valign="top" width="66">
<p>little</p>
</td>
<td valign="top" width="198"></td>
</tr>
<tr>
<td valign="top" width="104">
<p>audio format</p>
</td>
<td valign="top" width="92">
<p>2</p>
</td>
<td valign="top" width="66">
<p>little</p>
</td>
<td valign="top" width="198">
<p>1=&gt;PCM, other values =&gt; data compressed</p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>num of channels</p>
</td>
<td valign="top" width="92">
<p>2</p>
</td>
<td valign="top" width="66">
<p>little</p>
</td>
<td valign="top" width="198">
<p>1=&gt; mono, 2=&gt;stereo</p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>sample rate</p>
</td>
<td valign="top" width="92">
<p>4</p>
</td>
<td valign="top" width="66">
<p>little</p>
</td>
<td valign="top" width="198">
<p>8000, 16000, 22050, 44100 etc.</p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>byte rate</p>
</td>
<td valign="top" width="92">
<p>4</p>
</td>
<td valign="top" width="66">
<p>little</p>
</td>
<td valign="top" width="198">
<p>Sample rate*num of channels*bits per sample/8</p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>block align </p>
</td>
<td valign="top" width="92">
<p>2</p>
</td>
<td valign="top" width="66">
<p>little</p>
</td>
<td valign="top" width="198">
<p>num of channels*bits per sample/8</p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>bits per sample </p>
<p>&#8212;&#8212;</p>
</td>
<td valign="top" width="92">
<p>2 </p>
<p>&nbsp; </p>
<p>&#8212;&#8212;-</p>
</td>
<td valign="top" width="66">
<p>little </p>
<p>&nbsp; </p>
<p>&#8212;&#8212;</p>
</td>
<td valign="top" width="198">
<p>8=&gt;8bits, 16=&gt;16bits </p>
<p>&nbsp; </p>
<p>&#8212;&#8212;&#8212;&#8211;</p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>subchunk id (data)</p>
</td>
<td valign="top" width="92">
<p>4</p>
</td>
<td valign="top" width="66">
<p>big</p>
</td>
<td valign="top" width="198">
<p>“data”</p>
</td>
<td valign="top" width="123">
<p>Data subchunk: contains the raw audio data</p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>subchunk size</p>
</td>
<td valign="top" width="92">
<p>4</p>
</td>
<td valign="top" width="66">
<p>little</p>
</td>
<td valign="top" width="198">
<p>Num of samples * num of channels * bits per sample/8</p>
</td>
</tr>
<tr>
<td valign="top" width="104">
<p>data</p>
</td>
<td valign="top" width="92"></td>
<td valign="top" width="66">
<p>little</p>
</td>
<td valign="top" width="198">
<p>Audio data</p>
</td>
</tr>
</tbody>
</table>
<p>Note that there’re totally 44 bytes (12 + 24 + 8) before the actual audio data. </p>
<p><strong>1. Byte-by-Byte example</strong> </p>
<p>Below is a screenshot of a wave file shown in vim hex mode. We’ll go through the bytes one by one. </p>
<p><a href="http://www.roman10.net/wp-content/uploads/2013/03/wave.jpg"><img title="wave" style="border-right: 0px; border-top: 0px; display: block; float: none; margin-left: auto; border-left: 0px; margin-right: auto; border-bottom: 0px" height="504" alt="wave" src="http://www.roman10.net/wp-content/uploads/2013/03/wave_thumb.jpg" width="539" border="0"/></a></p>
<p align="center"><strong>Figure 1. Bytes of a wave file recorded on Android</strong>&nbsp; </p>
<p><em>5249 4646</em>: RIFF</p>
<p><em>74d8 0400</em>: 04d874 = 317556 bytes. I used &#8220;ls -l test.wav&#8221; to get the file size as 317564 bytes, which is equal to 317556 + 4 (size field) + 4 (RIFF field). </p>
<p><em>5741 5645</em>: WAVE</p>
<p><em>666d 7420</em>: fmt&lt;I&#8217;m a space&gt;</p>
<p><em>1000 0000</em>: 00000010 = 16 bytes.</p>
<p><em>0100</em>: 0001, which corresponds to PCM, values other than 1 indicate data is compressed.</p>
<p><em>0100</em>: 0001, only one channel.</p>
<p><em>44ac 0000</em>: 0000 ac44 = 44100, the sample rate is 44100Hz.</p>
<p><em>8858 0100</em>: 0001 5888 = 88200 = sample rate * number of channel * bits per sample/8 = 44100 * 1 * 16 / 8 = 44100 * 2</p>
<p><em>0200</em>: 0002, block align. 02 = number of channel * bits per sample / 8 = 1 * 16 / 8 = 2</p>
<p><em>1000</em>: 0010 = 16, bits per sample</p>
<p><em>6461 7461</em>: data</p>
<p><em>50d8 0400</em>: 0004 d850 = 317520, data size. 317520 + 44 (total header bytes) = 317564, which matches with the total file size obtained using &#8220;ls -al&#8221;.</p>
<p><strong>References:</strong></p>
<p>1. wikipedia page WAVE: <a href="http://en.wikipedia.org/wiki/WAV">http://en.wikipedia.org/wiki/WAV</a></p>
<p>2. WAVE PCM soundfile format: <a href="https://ccrma.stanford.edu/courses/422/projects/WaveFormat/">https://ccrma.stanford.edu/courses/422/projects/WaveFormat/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.roman10.net/wave-audio-file-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android Video2Gif Released</title>
		<link>http://www.roman10.net/android-video2gif-released/</link>
		<comments>http://www.roman10.net/android-video2gif-released/#comments</comments>
		<pubDate>Sun, 03 Mar 2013 02:59:25 +0000</pubDate>
		<dc:creator>roman10</dc:creator>
				<category><![CDATA[Android Apps]]></category>
		<category><![CDATA[Video2Gif]]></category>

		<guid isPermaLink="false">http://www.roman10.net/?p=1043</guid>
		<description><![CDATA[<p>Several months ago, my friend asks my help to convert a video to an animated gif so it can be shared on a social network. I googled a little bit and managed to do it with a few command line tools on Linux. It’s not difficult but it can be troublesome, especially for non-tech people. [...]]]></description>
			<content:encoded><![CDATA[<p>Several months ago, my friend asks my help to convert a video to an animated gif so it can be shared on a social network. I googled a little bit and managed to do it with a few command line tools on Linux. It’s not difficult but it can be troublesome, especially for non-tech people. <br />Then I searched for Android gif making apps. There are plenty of them, but none are made for converting video to gif. I decided to write one. <br />I got busy with my new job and a few other stuff, the development is delayed. When I resume, there’s already an app that does video to gif, and it takes the “video to gif” app name. <img src='http://www.roman10.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <br />So here is the app, <a href="https://play.google.com/store/apps/details?id=roman10.video.videotogif">Android Video2Gif</a>. You can convert a video to gif by three clicks.
<ol>
<li>click a video from Videos tab or Browser tab, this goes to video extract screen. </li>
<li>click extract on top right corner of the screen, this might take a while to sample frames from the video. After it’s done, it goes to gif edit screen. </li>
<li>click ok to start gif generation.</li>
</ol>
<p>Below are a few screenshots.</p>
<p><a href="http://www.roman10.net/wp-content/uploads/2013/03/sc.jpg"><img title="sc" style="border-right: 0px; border-top: 0px; display: block; float: none; margin-left: auto; border-left: 0px; margin-right: auto; border-bottom: 0px" height="289" alt="sc" src="http://www.roman10.net/wp-content/uploads/2013/03/sc_thumb.jpg" width="518" border="0"/></a></p>
<p align="center">Pic 1. Video2Gif Screenshots </p>
<p>The app is still in beta, so I expect there will be issues on some devices. As always, all feedback are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.roman10.net/android-video2gif-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Selective Decoding and the Source Code</title>
		<link>http://www.roman10.net/selective-decoding-and-the-source-code/</link>
		<comments>http://www.roman10.net/selective-decoding-and-the-source-code/#comments</comments>
		<pubDate>Wed, 05 Dec 2012 06:28:19 +0000</pubDate>
		<dc:creator>roman10</dc:creator>
				<category><![CDATA[Selective Decoding]]></category>

		<guid isPermaLink="false">http://www.roman10.net/?p=1036</guid>
		<description><![CDATA[<p>This is follow up post on Selective Decoding, my master thesis project. You can get the main idea of selective decoding at <a href="http://www.roman10.net/selective-decodingmy-master-thesis-project/">previous post</a>. This post simply provides some resources related to the project. </p> <p>I’ve upload two videos to YouTube demonstrating how selective decoding works. </p> Selective Decoding without Zoom Selective Decoding with [...]]]></description>
			<content:encoded><![CDATA[<p>This is follow up post on Selective Decoding, my master thesis project. You can get the main idea of selective decoding at <a href="http://www.roman10.net/selective-decodingmy-master-thesis-project/">previous post</a>. This post simply provides some resources related to the project. </p>
<p>I’ve upload two videos to YouTube demonstrating how selective decoding works. </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:6ed141a6-6209-4b11-a5e4-743b2965e18b" class="wlWriterEditableSmartContent">
<div><object width="448" height="252"><param name="movie" value="http://www.youtube.com/v/tbLuPFvZ-uQ?hl=en&amp;hd=1"></param><embed src="http://www.youtube.com/v/tbLuPFvZ-uQ?hl=en&amp;hd=1" type="application/x-shockwave-flash" width="448" height="252"></embed></object></div>
<div style="width:448px;clear:both;font-size:.8em">Selective Decoding without Zoom</div>
</div>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:69fcab1e-1e30-463c-a3d9-78f9995a4ee8" class="wlWriterEditableSmartContent">
<div><object width="448" height="252"><param name="movie" value="http://www.youtube.com/v/oiFwJQT26ro?hl=en&amp;hd=1"></param><embed src="http://www.youtube.com/v/oiFwJQT26ro?hl=en&amp;hd=1" type="application/x-shockwave-flash" width="448" height="252"></embed></object></div>
<div style="width:448px;clear:both;font-size:.8em">Selective Decoding with Zoom</div>
</div>
<p>The source code for the Android player is available at github. You can find it at <a href="https://github.com/roman10/AndZop">https://github.com/roman10/AndZop</a>. Note that there are multiple branches, with the master branch containing the stable code and other branches having various experiments I did. </p>
<p>There is a research paper about selective decoding, available at <a href="http://www.comp.nus.edu.sg/~ooiwt/papers/pcm12-zoomable.pdf">http://www.comp.nus.edu.sg/~ooiwt/papers/pcm12-zoomable.pdf</a>. If you want more detailed info, you can refer to my master thesis at <a href="http://www.roman10.net/src/thesis.pdf">http://www.roman10.net/src/thesis.pdf</a>. </p>
<p>This project is part of the jiku project. There’re lots of other interesting stuff going on under the jiku project. We can refer to <a href="http://liubei.ddns.comp.nus.edu.sg/jiku/">http://liubei.ddns.comp.nus.edu.sg/jiku/</a> for more information.&nbsp; </p>
]]></content:encoded>
			<wfw:commentRss>http://www.roman10.net/selective-decoding-and-the-source-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selenium: Reuse the HTTP Session in Firefox Browser</title>
		<link>http://www.roman10.net/selenium-reuse-the-http-session-in-firefox-browser/</link>
		<comments>http://www.roman10.net/selenium-reuse-the-http-session-in-firefox-browser/#comments</comments>
		<pubDate>Wed, 05 Dec 2012 02:58:51 +0000</pubDate>
		<dc:creator>roman10</dc:creator>
				<category><![CDATA[Machinery]]></category>

		<guid isPermaLink="false">http://www.roman10.net/?p=1034</guid>
		<description><![CDATA[<p>Selenium is a browser automation framework, which can be used for automating web application testing, crawling web pages etc. For a quick start guide, one can refer to <a href="http://code.google.com/p/selenium/wiki/GettingStarted">http://code.google.com/p/selenium/wiki/GettingStarted</a>. </p> <p>This post gives an example of reusing an existing HTTP session in firefox browser with Selenium. The example is based on Selenium version 2.26.0. [...]]]></description>
			<content:encoded><![CDATA[<p>Selenium is a browser automation framework, which can be used for automating web application testing, crawling web pages etc. For a quick start guide, one can refer to <a href="http://code.google.com/p/selenium/wiki/GettingStarted">http://code.google.com/p/selenium/wiki/GettingStarted</a>. </p>
<p>This post gives an example of reusing an existing HTTP session in firefox browser with Selenium. The example is based on Selenium version 2.26.0. </p>
<p>The basic idea is to check if there’s an existing Firefox browser started by Selenium, if so, we simply connect to it and reuse the browser session. </p>
<p>Below is an example of using the same Firefox browser session for requesting 10 pages from Google Play. Note that the code does not work for existing Firefox browser window not started by Selenium. </p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">import</span> java.io.IOException;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">import</span> java.net.InetSocketAddress;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">import</span> java.net.Socket;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">import</span> java.net.URL;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">import</span> org.openqa.selenium.WebDriver;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">import</span> org.openqa.selenium.firefox.FirefoxDriver;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">import</span> org.openqa.selenium.remote.DesiredCapabilities;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">import</span> org.openqa.selenium.remote.RemoteWebDriver;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> FirefoxDriverReuseExample {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> String ROOT_URL = <span style="color: #006080">"https://play.google.com/store/apps/details?id="</span>;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> String[] appIds = <span style="color: #0000ff">new</span> String[]{</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #006080">"roman10.media.converter"</span>,</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #006080">"Apna.LiveIndianTV"</span>,</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #006080">"app.fastfacebook.com"</span>,</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #006080">"app.FinalFutureSMS"</span>,</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #006080">"app.freepumpkintoss"</span>,</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #006080">"app.indianfinancemarketnews"</span>,</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #006080">"app.onetouchdrawLite"</span>,</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #006080">"app.visualjapan.pachisegu"</span>,</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #006080">"appinapp.mgong.proj.mannerlock"</span>,</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #006080">"appinventor.ai_giovannigemma2.origilale"</span></pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    };</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    </pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> retrieveAllUrls() {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        WebDriver driver = null;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">int</span> cnt = 0;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">boolean</span> isRunning = false;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; appIds.length; ++i) {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            String url = ROOT_URL + appIds[i];</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            <span style="color: #0000ff">try</span> {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">//see if the web driver is running</span></pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #0000ff">final</span> Socket s = <span style="color: #0000ff">new</span> Socket();</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                s.connect(<span style="color: #0000ff">new</span> InetSocketAddress(<span style="color: #006080">"localhost"</span>, 7055)); </pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                s.close(); </pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                isRunning = true; </pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            } <span style="color: #0000ff">catch</span> (IOException io) {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                isRunning = false;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            }</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            <span style="color: #0000ff">if</span> (!isRunning) {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">//start a new session</span></pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                driver = <span style="color: #0000ff">new</span> FirefoxDriver();</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                driver.get(url);</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                String pageSource = driver.getPageSource();</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                System.out.println(pageSource);</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                cnt++;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            } <span style="color: #0000ff">else</span> {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">//reuse the existing session</span></pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #0000ff">try</span> {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    <span style="color: #0000ff">if</span> (null == driver) {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                        <span style="color: #008000">//if not initialized yet, connect</span></pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                        driver = <span style="color: #0000ff">new</span> RemoteWebDriver(<span style="color: #0000ff">new</span> URL(<span style="color: #006080">"http://localhost:7055/hub"</span>), DesiredCapabilities.firefox()); </pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    }</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    driver.get(url);</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    String pageSource = driver.getPageSource();</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    System.out.println(pageSource);</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    cnt++;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                } <span style="color: #0000ff">catch</span> (Exception e) {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    e.printStackTrace();</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                }</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            }</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        }</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        System.out.println(<span style="color: #006080">"Total No. of requests and responses: "</span> + cnt);</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    }</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    </pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> main(String[] args) {</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        retrieveAllUrls();</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    }</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre>
<p><!--CRLF--></div>
</div>
<p>Note that I used the selenium-server-standalone-2.26.0.jar as referenced library for the code. It can be found at <a href="http://code.google.com/p/selenium/downloads/list">http://code.google.com/p/selenium/downloads/list</a>. </p>
<p><strong>References:</strong></p>
<p>Selenium project page: <a href="http://code.google.com/p/selenium/">http://code.google.com/p/selenium/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.roman10.net/selenium-reuse-the-http-session-in-firefox-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PCM Audio Format</title>
		<link>http://www.roman10.net/pcm-audio-format/</link>
		<comments>http://www.roman10.net/pcm-audio-format/#comments</comments>
		<pubDate>Fri, 30 Nov 2012 07:35:11 +0000</pubDate>
		<dc:creator>roman10</dc:creator>
				<category><![CDATA[Digital Audio Processing]]></category>
		<category><![CDATA[Digital Signal Processing]]></category>

		<guid isPermaLink="false">http://www.roman10.net/?p=1032</guid>
		<description><![CDATA[<p>Pulse Code Modulation (PCM) is a method to represent sampled analog signals in digital form, which is the standard form for digital audio representation in computers. In order to convert an analog signal to PCM, two steps are required. sampling: the magnitude of the analog signal are sampled regularly at uniform intervals. quantization: the value [...]]]></description>
			<content:encoded><![CDATA[<p>Pulse Code Modulation (PCM) is a method to represent sampled analog signals in digital form, which is the standard form for digital audio representation in computers. In order to convert an analog signal to PCM, two steps are required.
<ul>
<li>sampling: the magnitude of the analog signal are sampled regularly at uniform intervals.</li>
<li>quantization: the value of each sample is rounded to the nearest value expressible by the bits allowed for each sample. </li>
</ul>
<p><strong>Two Basic Properties</strong> </p>
<p>Two basic properties determines how well a PCM sequence can represent the original signal.
<ul>
<li>sampling rate: the number of samples taken in a second</li>
<li>bit depth: the number of bits used to represent each sample, which determines the number of values each sample can take (e.g. 8 bits =&gt; 2^8 = 256 values)</li>
</ul>
<p><strong>PCM Types</strong>
<ul>
<li>Linear PCM: The straightforward method of PCM. The samples are taken linearly and represented on a linear scale (as opposed to Logarithmic PCM etc.). It is an uncompressed format, which can be compressed by different audio codec. When we talk about PCM, we’re generally referring to Linear PCM. </li>
<li>Logarithmic PCM: the amplitudes of samples are represented in logarithmic form. There are two major variants of log PCM, mu-law (u-law) and A-law. </li>
<li>Differential PCM (DPCM): sample value is encoded as difference from its previous sample value. This could reduce number of bits required for an audio sample. </li>
<li>Adaptive DPCM (ADPCM): the size of quantization step is varied so that the required bandwidth can be further reduced for a given signal-to-noise ratio. </li>
</ul>
<p><strong>Audio File Formats Support LPCM</strong></p>
<p>LPCM audio is usually stored in aiff (.aiff, .aif, .aifc), wav (.wav, .wave), au (.au, .snd), and raw (.raw, .pcm) audio files. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.roman10.net/pcm-audio-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Intro to ELF File Format&#8211;Part 2 Sections and Segments</title>
		<link>http://www.roman10.net/an-intro-to-elf-file-formatpart-2-sections-and-segments/</link>
		<comments>http://www.roman10.net/an-intro-to-elf-file-formatpart-2-sections-and-segments/#comments</comments>
		<pubDate>Wed, 28 Nov 2012 06:09:21 +0000</pubDate>
		<dc:creator>roman10</dc:creator>
				<category><![CDATA[Compilers and Related]]></category>
		<category><![CDATA[ELF]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.roman10.net/?p=1028</guid>
		<description><![CDATA[<p>This is a follow up post of the <a href="http://www.roman10.net/an-intro-to-elf-file-formatpart-1-file-types-and-dual-views/" target="_blank">Part 1 An Intro to ELF File Format</a>. </p> <p>Sections</p> <p>We’ve seen the section headers in section header table above, now we discuss sections in detail. </p> <p>Below are a list of commonly seen section types.&#160; (Note that this is not a complete list)</p> NULL: [...]]]></description>
			<content:encoded><![CDATA[<p>This is a follow up post of the <a href="http://www.roman10.net/an-intro-to-elf-file-formatpart-1-file-types-and-dual-views/" target="_blank">Part 1 An Intro to ELF File Format</a>. </p>
<p><strong>Sections</strong></p>
<p>We’ve seen the section headers in section header table above, now we discuss sections in detail. </p>
<p>Below are a list of commonly seen section types.&nbsp; (Note that this is not a complete list)</p>
<ul>
<li><strong><em>NULL</em></strong>: this marks the section header as inactive. It does not have an associated section.  </li>
<li><strong><em>PROGBITS</em></strong>: program content, including code, data, debugging info etc.  </li>
<li><strong><em>SYMTAB</em></strong> and <strong><em>DYNSYM</em></strong>: the section holds a symbol table. SYMTAB provides symbols for link editing and dynamic linking. DYNSYM holds only a minimal set of dynamic linking symbols.  </li>
<li><strong><em>STRTAB</em></strong>: holds a string table.  </li>
<li><strong><em>RELA</em></strong>: relocation entries with explicit addends.  </li>
<li><strong><em>REL</em></strong>: relocation entries without explicit addends.  </li>
<li><strong><em>DYNAMIC</em></strong>: information for dynamic linking.  </li>
<li><strong><em>HASH</em></strong>: holds a symbol hash table for looking up the symbol in a ELF file quickly.  </li>
<li><strong><em>NOTE</em></strong>: information that marks the file.  </li>
<li><strong><em>NOBITS</em></strong>: like PROGBITS, but without occupying space in the file. Used for BSS data allocated at program load time.</li>
</ul>
<p>We can see the section type from the section header screenshots above. For example, the .interp is a section of type PROGBITS. </p>
<p>Sections also have flags associated with them. Below is a list of commonly seen flags. </p>
<ul>
<li><strong><em>WRITE</em></strong> (W): the section contains data that is writable when loaded.  </li>
<li><strong><em>ALLOC</em></strong> (A): the section occupies memory when the program is loaded.  </li>
<li><strong><em>EXECINSTR</em></strong> (X): the section contains executable machine code.  </li>
<li><strong><em>MERGE</em></strong> (M): the data in the section may be merged to eliminate duplication.  </li>
<li><strong><em>STRINGS</em></strong> (S): the data in the section contain null-terminated character strings. </li>
</ul>
<p>Below is a list of commonly seen sections. </p>
<table border="2" cellspacing="0" cellpadding="0" width="599">
<tbody>
<tr>
<td valign="top" width="106">
<p><b><font color="#000000" size="1">Name</font></b></p>
</td>
<td valign="top" width="97">
<p><b><font color="#000000" size="1">Type</font></b></p>
</td>
<td valign="top" width="128">
<p><b><font color="#000000" size="1">Attributes</font></b></p>
</td>
<td valign="top" width="264">
<p><b><font color="#000000" size="1">Notes</font></b></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.bss</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">NOBITS</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC and WRITE</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">holds uninitialized data. The system initializes the data with zeros before the program starts to run. </font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.comment</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">PROGBITS</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">MERGE and STRINGS</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">some remarks about the file</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.data</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">PROGBITS</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC and WRITE</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">holds initialized data. </font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.debug</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">PROGBITS</font></p>
</td>
<td valign="top" width="128"><font color="#000000" size="1"></font></td>
<td valign="top" width="264">
<p><font color="#000000" size="1">holds information for symbolic debugging</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.dynamic</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">DYNAMIC</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC (WRITE, processor specific)</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">holds dynamic linking info. </font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.dynstr</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">STRTAB</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">strings needed by dynamic linking, most commonly the names associated with dynamic linking symbol table entries</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.dynsym</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">DYNSYM</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">symbol table for dynamic linking</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.fini</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">PROGBITS</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC and EXEC</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">process termination code</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.got</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">PROGBITS</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC and WRITE</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">Global Offset Table (GOT). </font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.hash</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">HASH</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">symbol hash table</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.init</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">PROGBITS</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC and EXEC</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">process initialization code</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.interp</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">PROGBITS</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC on if file has a loadable segment that includes relocation</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">path name of a program interpreter. </font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.note</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">NOTE</font></p>
</td>
<td valign="top" width="128"><font color="#000000" size="1"></font></td>
<td valign="top" width="264"><font color="#000000" size="1"></font></td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.plt</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">PROGBITS</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC and EXEC</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">Procedure Linkage Table (PLT)</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.rel&lt;name&gt;</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">REL</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC on if file has a loadable segment that includes relocation</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">relocation info, &lt;name&gt; indicates the section to which the relocations apply</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.rela&lt;name&gt;</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">RELA</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC on if file has a loadable segment that includes relocation</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">relocation info, &lt;name&gt; indicates the section to which the relocations apply</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.rodata</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">PROGBITS</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">read-only data</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.shstrtab</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">STRTAB</font></p>
</td>
<td valign="top" width="128"><font color="#000000" size="1"></font></td>
<td valign="top" width="264">
<p><font color="#000000" size="1">section names</font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.strtab</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">STRTAB</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC on if the file has a loadable segment that includes the symbol string table</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">strings. Most commonly the strings that represent the names associated with symbol table entries. </font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.symtab</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">SYMTAB</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC on if file has a loadable segment that includes the symbol table</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">symbol table. </font></p>
</td>
</tr>
<tr>
<td valign="top" width="106">
<p><font color="#000000" size="1">.text</font></p>
</td>
<td valign="top" width="97">
<p><font color="#000000" size="1">PROGBITS</font></p>
</td>
<td valign="top" width="128">
<p><font color="#000000" size="1">ALLOC and EXEC</font></p>
</td>
<td valign="top" width="264">
<p><font color="#000000" size="1">executable code of a program</font></p>
</td>
</tr>
</tbody>
</table>
<p><strong>Segments</strong></p>
<p>Executable and shared object ELF files statically represent programs. A system needs to use these files to create dynamic representation (process image) in order to execute the program. A process image consists of segments which holds text, data ,stack etc created from the segments in ELF files. </p>
<p>We can get various information about segments of ELF file from its program headers. Below is a screenshot of program headers in test executable file. </p>
<blockquote><p>$ readelf -l test</p>
</blockquote>
<p><img src="https://lh6.googleusercontent.com/5LFJ2hEnm9Iqt-QmTmoBQPutr_JA_lZdchmivEyNZEIrbcEkY6IroxnwI125gCzgnzt0HVDcjAloRcdpKV2J_jYB099MYFxWzHjuotPHZEA3iJcbMtQ" width="516" height="366"/></p>
<p>Each record has several fields.</p>
<ul>
<li><strong><em>Type</em></strong>: the segment type.  </li>
<li><strong><em>Offset</em></strong>: the location of the first byte of the segment with respect to the beginning of the file  </li>
<li><strong><em>VirtAddr</em></strong>: the virtual address of the first byte of the segment in memory  </li>
<li><strong><em>PhysAddr</em></strong>: only make sure on systems where physical addressing is relevant.  </li>
<li><strong><em>FileSiz</em></strong>: segment size in number of bytes in file image of the segment  </li>
<li><strong><em>MemSiz</em></strong>: segment size in number of bytes in memory image of the segment.  </li>
<li><strong><em>Flg</em></strong>: flags  </li>
<li><strong><em>Align</em></strong>: memory alignment. Values 0 or 1 means no alignment is needed. Otherwise, VirtAddr%Align == Offset%Align</li>
</ul>
<p>Below is a list of commonly seen segment types in ELF files.
<ul>
<li><strong><em>NULL</em></strong>: unused  </li>
<li><strong><em>LOAD</em></strong>: a loadable segment.  </li>
<li><strong><em>DYNAMIC</em></strong>: dynamic linking info  </li>
<li><strong><em>INTERP</em></strong>: the segment specifies the path to an interpreter. If present, must proceed any loadable segment.  </li>
<li><strong><em>NOTE</em></strong>: location and size of auxiliary info.  </li>
<li><strong><em>PHDR</em></strong>: specifies the size and location of the program header itself, both in file image and memory image of the program. </li>
</ul>
<p>A segment consists of one or more sections. The two most commonly seen segments are the text segment and the data segment (both are of LOAD type). </p>
<p>A text segment contains read-only instructions and data. It usually includes the following sections: .text, .rodata, .hash, .dynsym, .dynstr, .plt, .rel.got. In the screenshot above, the third entry (with LOAD type) is a text segment. </p>
<p>A data segment contains writable data and instructions. It usually includes the following sections: .data, .dynamic, .got, .bss. In the screenshot above, the fourth entry (with LOAD type) is a text segment. </p>
<p><strong>References: </strong></p>
<p>1. System V Application Binary Interface, Apr 2001 <a href="http://refspecs.linuxbase.org/elf/gabi4+/contents.html">http://refspecs.linuxbase.org/elf/gabi4+/contents.html</a></p>
<p>2. The ELF Object File Format: Introduction. 1995. <a href="http://www.linuxjournal.com/article/1059?page=0,0">http://www.linuxjournal.com/article/1059?page=0,0</a></p>
<p>3. The ELF Object File Format by Dissection. 1995. <a href="http://www.linuxjournal.com/article/1060">http://www.linuxjournal.com/article/1060</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.roman10.net/an-intro-to-elf-file-formatpart-2-sections-and-segments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
