Build Media Center PC using Raspberry Pi

Raspberry Pi is a credit card sized computer built using Broadcom SOC (system on chip) created by Raspberry Pi foundation. It costs $35 for model B board which has 700 MHz ARM CPU, 512 MB RAM, 2 USB2 ports, 1 HDMI port ,1 RCA video port,Ethernet and audio port. It has SD card for installing Linux distribution.

Here is screenshot of Raspberry Pi board


There are number of Linux distribution that target Raspberry Pi , including distribution to run Media Center software.

In this post I will talked about how I built my media center pc using Raspberry Pi and OpenELEC ( open embedded Linux entertainment center ) Linux distribution.

OpenELEC is a small Linux distribution with complete XBMC media center software. Compared to Raspbmc which is another Linux based media center distribution , OpenELEC is very small around 80MB in size. Because OpenELEC distribution  packages only software necessary for media center it is small and fast compared to Raspbmc.

Here is the screenshot of my Raspberry Pi board with all necessary connection .(HDMI connection to monitor, micro usb power connection, Ethernet connection and USB keyboard and mouse).

2012-12-27 19.55.18

Creating bootable SD image

Before powering up the board , you need download OpenELEC distribution from the OpenELEC website. Make sure that you download image which as RPi-arm name in it,  example : OpenELEC-RPi.arm-devel-20121124031454-r12577.tar.bz2

To create bootable OpenELEC image on SD card you can Windows/Mac/Linux OS workstation with SD card reader. Here are the steps to create SD image on Ubuntu 12.10 .

1. Unzip and un-tar OpenELEC to some folder ,

2. Insert 2GB blank SD card to your machine.

3. Execute create_sdcard shell script from OpenELEC folder with device path of the SD card.


linux-vm:~/OpenELEC-RPi.arm$ ./create_sdcard  /dev/sdb

4. Once step 3  completes without any errors, SD card will have bootable OpenELEC image.

5. Now insert SD card to Raspberry Pi board and power up.

6. You will see the boot screen with OpenELEC and Raspberry Pi logo.

2012-12-28 11.34.03

7. After while you see familiar XBMC media center interface.

2012-12-28 11.35.00

8. Now you navigate the menu using keyboard and add your data source where you stored your media collection.

OpenELEC supports UPnP, DLNA,NFS,CIFS,SMB,FTP,SFTP and others file sharing protocols. Using these you should be able to browse the media collection stored on your PC , MAC, Linux or NAS box.

You can also connect your USB2 hard drive to Raspberry Pi and browse media collection from OpenELEC.  OpenELEC supports hard drive formatted using NTFS ,FAT/FAT32 and other Linux file system formats.

Once you have contents you play any audio/video/photo formats.

OpenELEC also supports Apple AirPlay as target. You can enable this from settings menu. Once enabled , you can stream photo and video from you IOS device( iPhone ,iPad ,iPod touch and MAC computers )  to OpenELEC connected device ( TV or monitor )

In the next blog post I will explore installing Java 8 on Raspberry Pi and running Java FX application.


1. Raspberry Pi : Main Raspberry Pi website.

2. OpenELEC : Open Embedded  Linux media center website.

3. OpenELEC on Raspberry Pi :  Instructions to install OpenELEC on Raspberry Pi

4. XBMC : XBMC wiki page .

5. Raspbmc :  Raspberry Pi media center distribution based with XBMC software.

6. Run Java Application on Raspberry Pi. Oracle TechNet article for installing Java on Raspberry Pi

7. Raspberry Pi accessories :  Collection of Raspberry Pi compatible accessories.

Programming in modern C++ with C++ 11

If you are following C++ lately you might have herd of C++ 11. C++ 11 is new revision to C++ standard approved in 2011. It offers significant improvements in both the language and the library. It include features such lambda functions/expression, range based for loop, uniform initialization, automatic type deduction, variadic templates and many more.
On the library side changes include regular expressions, atomic operations, threading (futures and promises), and tuples. Even though some of these feature exits for while in boost library now it is part of C++ standard hence it will be available from all compiler vendors (GCC,VC++ and CLANG).

With these improvements , programming in C++ 11 is as easy as in Java or C#.

In this blog post I will cover some of features I have explored in C++11.

1. Automatic Type deduction with ‘auto’

With C++ 11 , you can declare variable or object without specifying its specific type by using ‘auto’ keyword. This is especially useful if you are working with templates or lambda functions where actual type can be hard to write but compiler can infer from the expression. This feature is similar to c# var keyword

auto count  = 10; // compiler infer count type has int

vector wordCount = { 10,20,30,40 };

auto pos = wordCount.begin() ; //  compiler infer pos has vector::iteraror type.

// compiler infer the squareFunction is lambda function with integer input and integer return type.
auto squareFunction = [] (int x) -> int
                      { return x*x; };

// other example is iterating over any C++ containers using ranged based for loop
for(auto wordC : wordCount )


2. Uniform initialization and Initializer list

This feature allows initialize any type (custom or built-in) using single common syntax. Following examples shows initializing built-in primitive types, containers and custom object using braces syntax

int count = { 10 };

double tempratureRange []  = {32.7,46.9,40.6,67.1,12.8 };

vector days = { "sunday","monday","tuesday",
map<string,vector> phoneList = { {"Joe",{"222-456-234","222-111-555"}},
                                        } ;
CustomType ct = {1,2,3,4,5,6};

for(auto day : days )

for(auto & phone : phoneList )
  for(auto & num : phone.second )
       cout<<num<<" , ";

3. Lambda functions/expression

This feature allows creating anonymous functions that can be passed/returned from another function. This feature used along with C++ generic function/algorithms allows writing short snippet of code inline to perform operation on C++ containers.

[] {
     cout<<"Hello from lambda"<<endl; }(); // square function auto squareFunction = [] (int x) -> int
                         { return x*x; };

vector values = {1,2,3,4,5};

for_each(values.begin(),values.end() , [&values] ( int n ) {
                                      if ( n % 2 == 0 )
                                         cout<<" is even number"<<endl;
                                         cout<<" is odd numnber"<<endl;

4. Range based for loops

This feature makes iterating over collection using simple syntax. It works with all standard containers

vector days = { "sunday","monday","tuesday",
map<string,vector> phoneList = { {"Joe",{"222-456-234","222-111-555"}},
                                        } ;
// iterating over vector
for(auto day : days )

// iterating over map
for(auto & phone : phoneList )
    for(auto & num : phone.second )
        cout<<num<<" , ";

5. Variadic templates.

This feature allows users to write template class or function that can take variable number of types. For example writing type safe printf style function: See Wikipedia article . This feature will be more useful for library authors. Tuples are implemented using variadic templates as tuple can take multiple arguments of various types.

6. Tuples and Raw string literals

Tuples are ordered list of elements, many of the functional programming languages have this feature. Basically it allows to pass/return multiple values to/from function as single unit without creating separate custom type to do the same.

Example: to parse tcp host details to separate hostname and port.

tuple<string,string> ParseTcpHostDetails(const string & tcpHost)
   string host = tcpHost.substr(0,tcpHost.find_first_of(':'));
   string port = tcpHost.substr(tcpHost.find_first_of(':')+1);
   return make_tuple(host,port);
int main(int argc,char* argv[])
   auto parsedValue = ParseTcpHostDetails("");
   string host = std::get(parsedValue);
   string port = std::get(parsedValue);

Raw string literals allows to write character strings where escape character are not processed. A raw string literal starts with R”( and ends in )”

string uncPath = "\\\\servername\\sharepath";
string uncPathWithRawStringLiterals = R"(\\servername\sharepath)";

7.  Threading support ( async,futures and promises )

These features collectively help in writing concurrent application in a standard way on different OS platforms.

async allows launching task that can be executed on background thread, future allows waiting for the task to complete and wait for the result

int main(int argc ,char* arv[])
  std::future result1(std::async( [] () {
     cout<<"["<<std::this_thread::get_id()<<"] Inside long running task .. "<<endl;


All samples programs are compiled on Ubuntu 12.10 with GCC 4.7.2 compiler with -std=c++0x switch.

// sample c++ file for compilation with proper header include
// use 'g++ -g -std=c++0x -o Sample Sample.cxx' compiler options
using namespace std;
int main(int argc,char * argv[])

return 0;

In future blog posts I will write about remaining C++ 11 features such as

  • Decltypes
  • Move constructor & Delegating Constructors
  • Move semantics
  • New ways of making a Class non copy able and assignable using keyword
  • New smart pointer classes
  • More thread/async/future/promise examples


1. isocpp website provides all the news , articles ,videos and blogs related to C++.

2. C++ 11 FAQ by Bjarne Stroustrup.

3. podcast :Excellent C++ 11 podcast on software engineering radio with Scott Meyers.

4. Future of C++ : Build 2012 Talk by Herb Sutter.