GDB - the simple, yet elegant debugger

The GDB or the GNU Debugger has by far been the most simplest to learn, use and yet its elegance in terms of what it can do to help out is amazing. Even the most complex of debugging IDEs use GDB internally. One such example is the Data Display Debugger under Linux. Another IDE that can use GDB is Eclipse.

Here the most common commands are presented in the form of a quick reference card:

Read this document on Scribd: gdb-refcard

Technorati : , , , , ,

Digital Set Top Fundamentals Whitepaper

I found this interesting paper by B.Sundareshan on the open architecture and interoperability issues concerning a Digital Set Top Box. Though I was expecting to read specifically about these topics, the paper also covers a general overview of what an STB is made of and what in essence defines an STB in a very simplistic manner. I have tried to contact the author, but could not succeed because his contact details are missing in the document. I am producing the same whitepaper here for educational purposes and would gladly credit the author for his work.


It is worth noting that the paper talks about the following:

  • Types of data transmission
  • Modulation techniques for these transmissions
  • Open architecture and interoperability across networks
  • Major components of a typical STB
  • Interactivity using modems/cable modems on STBs
  • Front ends and switchable front ends
  • CA modules with EMM and ECMs
  • Kernel and Loader applications for over the air downloads
  • Drivers and middleware (subscriber applications)
  • EPG
  • Enhanced and Interactive mode TV applications
  • MHP reference model running on Java JVM
  • Internet access using STBs and MHP
  • Open Cable Digital STB architecture
  • Open Cable Application Platform (OCAP)

You must read this paper completely if you don’t want to miss out on important elements of an STB architecture.

Technorati : , , , , , , , , , , , , , , , , , , , , , , ,

Fred’s C++ notes: A must read sequence of good C++ examples

I was going through Fred’s C++ site for an example of string streams. This was for a basic requirement of putting in any value into a string, such as a float or an integer, or even more complex values.


#include <iostream>
#include <sstream>
using namespace std;
. . .
ostringstream outs;  // Declare an output string stream.
. . .
outs << sqrt(2.0);   // Convert value into a string.
s = outs.str();      // Get the created string from the output stream.

This example was so simple, yet conveyed the point. The square root of 2.0 was stored into a string stream designated as outs. One could then always get back the string value from ‘outs’ as and when required. If the ostringstream class were not to be there, you can only imagine what pain one has to go through using itoa or its equivalents such as the sprintf command, etc to get the same job done!

For those who would like to know more about these examples, please do read through this CHM help file which has a compilation of all Fred’s works until now (with his prior permission)

Hi Srikanth,

I don’t have any PowerPoint slides — sorry. You are free to use my online notes in any way you want. I’m glad you find them useful.

Yours, Fred.

Do click here to get access to Fred’s programming tricks and techniques. You won’t leave the site unhappy I promise!

Technorati : , , , , , , , ,

DVB service information

We have all heard of the term Digital Video Broadcasting or DVB which refers to the means by which live or recorded digital media content is transmitted to individual homes. This obviously involves the following:

  1. Preparation of the media at transmitter end
  2. Applying security or conditional access parameters to this media
  3. Attaching specific information about the media being transmitted
  4. Sending this data through a delivery channel such as terrestial or satellite or cable
  5. Receiver side processing of the data to provide decrypted content to user

The item (3) above refers to information about the channels, the programmes in the channels and this is called service information in technical terms. This presentation bears relevance to how the Service Information or SI is transmitted along with video and audio data in DVB.

It is preferred that you watch the presentation in full screen mode.

Technorati Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Trees - they are the same even in real life!

I was researching a bit on trees, and found this useful presentation on Binary Trees. Though it also has a mention of N-Ary trees, the real crux of N-Ary trees can be found in books by O’Rielly. I shall speak about this a bit later, but for now I’ ll leave you with this presentation:

(courtesy and copyrighted by Rick Mercer)


Technorati Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Codecs and container formats

I found this snippet from the Video-LAN-Streaming HowTo document about Muxers and Codecs which clearly explains the possible video encoding formats, the container formats, the differences between container formats and codecs, etc. I am reproducing it here for reference and better understanding:

What is a codec ?
To fully understand the VideoLAN solution, you must understand the difference between a codec and a container format A codec is a compression algorithm, used to reduce the size of a stream. There are audio codecs and video codecs.MPEG-1, MPEG-2, MPEG-4, Vorbis, DivX, … are codecs
What is a container format ?
To start off, think of a container format as a standard shipping box. You get a box in the mail and you think, "Cool! What’s inside." You don’t really care about the box itself, you care about what’s in that box. The problem? You can’t see into the box. So what do you do? You get a knife and cut it open.
A container format follows this same basic idea. It contains one or several streams already encoded by codecs. Very often, there is an audio stream and a video one. AVI, Ogg, MOV, ASF, MP4 … are container formats. The streams contained can be encoded using different codecs. In a perfect world, you could put any codec in any container format. Unfortunately, there are some incompatibilities. You can find a matrix of possible codecs and container formats on the features page (http://www.videolan.org/streaming/features.html)
Encoding a video
This is the first step where you are going to create the shipping box. First you need to encode your file. That means that a file, wheter it is an audio, video file, is compressed to another format that normally takes up less physical drive space than the previous format. Common video encoding methods are DivX, MPEG-1, MPEG-2, MPEG-4 … most common audio encoding method is MP3 or ogg-vorbis. Then you have to mux (or multiplex). This means basically a process where separate parts of the video (or streams) are joined together into one file.
Playing a video
Now that you have your box, you need to open it before to see the content. That’s exactly what VLC will do. To decode a stream, VLC first demuxes it. This means that it reads the container format and separates audio, video, and subtitles, if any. Demuxing files doesn’t weaken the video nor audio quality, it doesn’t do anything for these data streams, it justs simply saves them into separate files, each containing one element of the original file. Then, each of these are passed decoders that do the mathematical processing to decompress the streams.
There is a particular thing about MPEG:
MPEG is a codec. There are several versions of it, called MPEG-1, MPEG-2, MPEG-4, …
MPEG is also a container format, sometimes refered to as MPEG System. There are several types of MPEG: ES, PS, and TS.
When you play an MPEG video from a DVD, for instance, the MPEG stream is actually composed of several streams (called Elementary Streams, ES): there is one stream for video, one for audio, another for subtitles, and so on. These different streams are mixed together into a single Program Stream (PS). So, the .VOB files you can find in a DVD are actually MPEG-PS files. But this PS format is not adapted for streaming video through a network or by satellite, for instance. So, another format called Transport Stream (TS) was designed for streaming MPEG videos through such channels.

Technorati Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Using current time of day to timestamp execution logs

I keep coming back to timers these days as my work is involving their usage heavily :-). The latest was a requirement by me for knowing a current time for timestamping a certain sequence of logs. I found this program at a sourceforge website, which just wonderfully and blissfully did what I wanted …

Here is the small tiny program for reference:

/* C routine: sample gettimeofday with time in milliseconds
   mmc mchirico@users.sourceforge.net

   Downloads:
   http://prdownloads.sourceforge.net/cpearls/date_calc.tar.gz?download

*/
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>

int mainvoid
{
  char buffer[30]
  struct timeval tv

  time_t curtime

  gettimeofday&tv, NULL
  curtime=tv.tv_sec

  strftimebuffer,30,"%m-%d-%Y  %T.",localtime&curtime
  printf"%s%ld’n",buffer,tv.tv_usec

  return 0

}

My execution logs looked something like this:

RESULT : EName:[02-25-2008 15:26:50.MS: 520548] Sub : –[1]– EvID : –[1]– Pub : –[0×9163788]– PName : –[pub1]–
RESULT : EName:[02-25-2008 15:26:50.MS: 520708] Sub : –[1]– EvID : –[1]– Pub : –[0×91638d0]– PName : –[pub2]–
RESULT : EName:[02-25-2008 15:26:50.MS: 520799] Sub : –[1]– EvID : –[1]– Pub : –[0×91639f8]– PName : –[pub3]–

tm to epoch time conversion

Linux provides a friendly way of entering time in terms of details such as day month year, seconds, hours, minutes etc. The structure in question is called "tm" and is as shown below:

struct tm
{
int tm_sec;
int tm_min;
int tm_hour;

int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
}

However for comparisons, this time has to be further converted to the standard UNIX EPOCH time discussed in earlier articles. So for this, a function called mktime does this necessary conversion and provides a result in the form time_t which is in effect an epoch time. Two epoch times can be compared with relational operators (<, >, = =, !=) and we can decide which of the two input times is greater than the other or lesser than that other, etc.

An example from the opengroup is provided here for reference

What day of the week is July 4, 2001?


#include <stdio.h>
#include <time.h>

struct tm time_str;

char daybuf[20];

int main(void)
{
    time_str.tm_year = 2001 - 1900;
    time_str.tm_mon = 7 - 1;
    time_str.tm_mday = 4;
    time_str.tm_hour = 0;
    time_str.tm_min = 0;
    time_str.tm_sec = 1;
    time_str.tm_isdst = -1;
    if (mktime(&time_str) == -1)
        (void)puts("-unknown-");
    else {
        (void)strftime(daybuf, sizeof(daybuf), "%A", &time_str);
        (void)puts(daybuf);
    }
    return 0;
}

Its worthy to note here that the call can return a value if -1 (casted to time_t) if in case the resultant output cannot be expressed in the form of an epoch time.

You can try out the function mktime with a few input examples for the struct tm, on your own, to see the results for yourself. Try some invalid values as well. Technorati Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

The year 2038 time problem

So we all thought only Y2k and Y3k could cause problems in the world of computing? What about Y2.038k ?? Whats great about this date? Lets have a look. The rest of this article is as quoted by Roger M. Wilcox.

What’s so special about 2038?

Early UNIX programmers had quite a sense of humor. In their documentation for the tunefs utility, a command-line program that fine-tuned the file system on the machine’s hard disk, a note at the end reads "You can tune a file system, but you can’t tune a fish." A later generation of UNIX authors, fearful that stuffy, humorless corporate drones would remove this cherished pun, added a programmer’s comment inside the documentation’s source code that read, "Take this out and a UNIX demon will dog your steps until the time_t’s wrap around!"

On January 19, 2038, that is precisely what’s going to happen.

For the uninitiated, time_t is a data type used by C and C++ programs to represent dates and times internally. (You Windows programmers out there might also recognize it as the basis for the CTime and CTimeSpan classes in MFC.) time_t is actually just an integer, a whole number, that counts the number of seconds since January 1, 1970 at 12:00 AM Greenwich Mean Time. A time_t value of 0 would be 12:00:00 AM (exactly midnight) 1-Jan-1970, a time_t value of 1 would be 12:00:01 AM (one second after midnight) 1-Jan-1970, etc.. Since one year lasts for a little over 31 000 000 seconds, the time_t representation of January 1, 1971 is about 31 000 000, the time_t representation for January 1, 1972 is about 62 000 000, et cetera.

If you’re confused, here are some example times and their exact time_t representations:

Date & time time_t representation
1-Jan-1970, 12:00:00 AM GMT 0
1-Jan-1970, 12:00:01 AM GMT 1
1-Jan-1970, 12:01:00 AM GMT 60
1-Jan-1970, 01:00:00 AM GMT 3 600
2-Jan-1970, 12:00:00 AM GMT 86 400
3-Jan-1970, 12:00:00 AM GMT 172 800
1-Feb-1970, 12:00:00 AM GMT 2 678 400
1-Mar-1970, 12:00:00 AM GMT 5 097 600
1-Jan-1971, 12:00:00 AM GMT 31 536 000
1-Jan-1972, 12:00:00 AM GMT 63 072 000
1-Jan-2003, 12:00:00 AM GMT 1 041 379 200
1-Jan-2038, 12:00:00 AM GMT 2 145 916 800
19-Jan-2038, 03:14:07 AM GMT 2 147 483 647

By the year 2038, the time_t representation for the current time will be over 2 140 000 000. And that’s the problem. A modern 32-bit computer stores a "signed integer" data type, such as time_t, in 32 bits. The first of these bits is used for the positive/negative sign of the integer, while the remaining 31 bits are used to store the number itself. The highest number these 31 data bits can store works out to exactly 2 147 483 647. A time_t value of this exact number, 2 147 483 647, represents January 19, 2038, at 7 seconds past 3:14 AM Greenwich Mean Time. So, at 3:14:07 AM GMT on that fateful day, every time_t used in a 32-bit C or C++ program will reach its upper limit.

One second later, on 19-January-2038 at 3:14:08 AM GMT, disaster strikes.

To know more about this problem and continue reading further, click here.

Technorati Tags: , , , , , , , , , , , , , , , ,

Usage of timers - what you need to know about them?

I had written an earlier article on Timers in Linux. In this article I share with you a slideshow on what is possible with timers and what is not achievable, so that you may clearly understand how timers can be used during system programming under a linux host or linux target based environment.


The following points are worth noting about timers:

  1. The time is stored relative to a certain date in history (Jan 1, 1970), so when you read the time, its always a number relative to this date. This is called EPOCH time or the UNIX EPOCH time.
  2. Each process is allocated one timer, this is called per process timer.
  3. iTimers which are of three types: REAL, VIRTUAL and PROF
  4. how to initialize countdown timers and use them
  5. iTimerVal and timeval structures
  6. it_interval, it_value, tv_sec, tv_usec variables and their possible values
  7. using the signal handler function to handle timer expiry signals
  8. how to set signal handlers while using timers
  9. types of signals that can be sent to process or across processes (SIGALRM)

So its now easy for you to write a small timer program in linux and compile it using the following :

gcc timer_example.c p-o timer_example

run it using

./timer_example

and check your logs to see if the timers did expire properly! As you would be aware the timer is a per process timer which means within a process, if you require timeouts at different intervals it has to be an enhancement over a single timer. So you could expire a single timer every say 1 second or 10 milliseconds or whatever value you want (at a granular level) and provide a specific interrupt to the process or other processes every "N" seconds or milliseconds where "N" is a multiple of the it_value variable within the timeval structure.

Try it out yourself and be rest assured it ll work like a charm.

Technorati Tags: , , , , , , , , , , , , , , , , , , ,

Close
E-mail It