© Jan Newmarch 2017

Jan Newmarch, Raspberry Pi GPU Audio Video Programming , 10.1007/978-1-4842-2472-4_1

1. Introduction to the Raspberry Pi

Jan Newmarch

(1)Oakleigh, Victoria, Australia

Electronic supplementary material

The online version of this chapter (doi:10.​1007/​978-1-4842-2472-4_​1) contains supplementary material, which is available to authorized users.

The Raspberry Pi (RPi) is a low-cost Linux computer developed with the intention of improving the background of students entering university computer science courses by giving them a good, cheap environment in which to play. And it does! In fact, I’ve got a bunch of colleagues at work, well into middle age, who have leapt upon it to play with. So far their kids haven’t found out, though....

Introduction

The RPi is a small, single-board computer developed originally for the purpose of teaching computer science in schools. It uses a system on a chip (SoC) and is characterized by a small form factor, low power, not much RAM, limited inputs and outputs, and disk storage provided either by an SD card or by external storage using a USB port.

There is a growing ecosystem of such computers, and sites such as Element14 Single Board Computers Line Card ( https://www.element14.com/community/docs/DOC-55875?ICID=sbc-featured-products ) and Wikipedia ( http://en.wikipedia.org/wiki/Single-board_computer ) list many of them.

Now this doesn’t seem very exciting, but nevertheless the RPi has captured the imagination (and the pockets!), with more than ten million sold. In fact, Amazon lists more than 1,000 books related to the RPi.

So, what is it? Well, it is a single-board computer, about the size of a credit card. There are a series of models beginning with the Raspberry Pi 1 released in 2012 to the Model 3 Model B released in 2016 and the Pi Zero.

The Model B has 512 MB RAM, two USB ports, and an Ethernet port. It has HDMI and analog audio and video outputs. The RPi FAQ states that the models currently available are the Pi 2 Model B, the Pi 3 Model B, the Pi Zero, and the Pi 1 Model B+ and A+. The following is from the FAQ at www.raspberrypi.org/faqs :

The Model A+ is the low-cost variant of the Raspberry Pi. It has 256 MB RAM, one USB port, 40 GPIO pins, and no Ethernet port. The Model B+ is the final revision of the original Raspberry Pi. It has 512 MB RAM (twice as much as the A+), four USB ports, 40 GPIO pins, and an Ethernet port. In February 2015, it was superseded by the Pi 2 Model B, the second generation of the Raspberry Pi. The Pi 2 shares many specs with the Pi 1 B+, but it uses a 900 MHz quad-core ARM Cortex-A7 CPU and has 1 GB RAM. The Pi 2 is completely compatible with first-generation boards and is the model we recommend for use in schools, due to its flexibility for the learner. The Pi 3 Model B was launched in February 2016; it uses a 1.2 GHz 64-bit quad-core ARM Cortex-A53 CPU, has 1 GB RAM, integrated 802.11n wireless LAN, and Bluetooth 4.1. Finally, thePi Zerois half the size of a Model A+, with a 1 GHz single-core CPU and 512 MB RAM, and mini-HDMI and USB On-the-Go ports.

Figure 1-1 shows what the RPi looks like graphically, and Figure 1-2 shows what it looks like in real life.

A435266_1_En_1_Fig1_HTML.jpg
Figure 1-1. Raspberry Pi Model 3B ( https://www.element14.com/community )

For its target audience, this is a wonderful computer. Its price point means that if it breaks, well, you just get another one. It runs a full-blown Linux system (the RPi 3B can run a very stripped down version “IoT” version of Windows) and can be used in a huge variety of situations (including as an array of RPis to build a supercomputer or hooked up to sensors as a participant in the Internet of Things). But if you want to use a single RPi for heavy-duty computation, well, it sucks. The following is from Wikipedia:

On theCPU levelthe performance of the RPi 2 is similar to a 300 MHz Pentium II of 1997–1999. The RPi 3 is substantially better but still not a world-shaker.

The GPU, on the other hand, is quite reasonable. The following is from the RPi FAQ:

The GPU is capable of 1 Gpixel/s, 1.5 Gtexel/s, or 24 GFLOPs of general-purpose compute and features a bunch of texture filtering and DMA infrastructure.

The GPU provides Open GL ES 2.0, hardware-accelerated OpenVG, and 1080p30 H.264 high-profile encode and decode.

Now this isn’t top-of-the-range GPU performance. A review of the NVidia GTX 980 gave 72 gigapixels per second, but then that single graphics card is ten times the cost of the whole RPi!

From the point of view of this book, an important factor is that while the CPU has changed in the different models, the GPU has remained the same. That means programs written to the GPU will run unchanged across all the different models.

A number of Linux images are available from the Raspberry Pi site, and others are being developed elsewhere. I use the Debian-based Raspbian image, which essentially comes in two forms: with or without a GUI. It doesn’t matter which one you use since in this book you will write directly to the GPU and bypass any running window system.

ELinux.org maintains a list of RPi distributions. There are many standard Linux distros included, such as Fedora, Debian, Arch, SUSE, Gentoo, and others. The RPi has gained traction as a media center based on the XBMC media center, and this is represented by distros such as OSMC (formerly Raspbmc) and OpenElec.

It doesn’t really matter which distro you use or even whether you use the X Window System or a command line. You will be bypassing those for this book.

There don’t seem to be any books that go into detail about the Broadcom VideoCore GPU used on the RPi, besides several tutorials and a set of examples from Broadcom. I bumped into a need to do this kind of programming while trying to turn the RPi into a karaoke machine: with the CPU busting its gut rendering MIDI files, there was nothing left for showing images such as karaoke lyrics except for the GPU, and nothing really to tell me how to do it.

This book scratches my itch. Since I’ve had to learn a lot about RPi GPU programming , I might as well share it. Let’s be honest: much of this is about sharing the pain. What started as a side issue turned into a full-blown project of its own, and this stuff is hard.

I will cover OpenGL ES, OpenMAX, and OpenVG. Along the way I will cover some Dispmanx. A version of the full OpenGL has just been released in beta, but this book will not cover that.

If you can’t program in C, then go away. If you can’t do concurrent programming using threads, then you will probably get glassy-eyed at various points. You need to be able to read formal specifications and pay attention to all the finicky details or your application won’t work. And you will need to spend a lot of time experimenting and working through unexplained “features,” buggy behavior, and not-yet-implemented core elements. Get used to staring at your screen in a totally bemused fashion, with a debugger running and the specification open on one side and a half-dozen web sites open on the other. I’ve found that a good bottle of red wine helps, not with the programming but for handling the frustration!

Programming Style

There are many different C programming styles that can be adopted. Regrettably this book uses most of them. I have taken code and specifications from the following places:

  • The OpenMAX specification

  • The OpenGL ES specification

  • The OpenVG specification

  • The OpenGL ES Programming Guide

  • The Broadcom IL Client library

My preferred brace style for C programming is the “one true brace” with the opening brace on the same line as its conditional statement , as shown here:

if (x) {
       ...
}

The IL Client library uses the Allman style (brace on a new line), as shown here:

if (x)
{
        ...
}

The Programming Guide uses the Whitesmiths style (brace on a new line, indented), as shown here:

if (x)
    {
        ...
    }

For variable names, I prefer delimiting words with an underscore (_), as in my_vbl, though after many years of Java programming, I am also happy with CamelCase (myVbl). The IL Client library uses _ separation; the Programming Guide uses CamelCase.

The OpenMAX specification uses a simplified form of Hungarian notation for struct field types such as pNativeRender but prefixes all function calls with OMX_, and the struct names themselves are all uppercase such as OMX_AUDIO_PORTDEFINITIONTYPE.

The OpenGL ES specification uses CamelCase for its function names, all beginning with gl such as glValidateProgram.

It isn’t possible to get one consistent style throughout the book, so I haven’t even tried for this edition. Please be tolerant.

Conclusion

This chapter has given you a brief overview of the RPi and what this book will attempt to cover.

Resources

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset