2011年1月6日星期四

Time in Linux programming

Kernel measures the passage of the time in three different ways:

  1. Wall time ---> measuring absolute time
  2. Process time
  3. Monotonic time ---> calculating relative time

    Unix systems represent absolute time as the number of elapsed seconds since the epoch, which is defined as 00:00:00 UTC on the morning of 1 January 1970.
    SO, even absolute time is, at a low level, relative time.

    The following table shows some useful functions for uing time:
Name second Microsecond Nanosecond
Getting the current time of day time() gettimeofday() clock_gettime()
Setting the current time of day stime() settimeofday() clock_settime()
Sleeping sleep() usleep() nanosleep()

Now Microsoft, ipod nano are in my mind, are these names from here? So interesting.

With a 32-bit long type, time_t will let us have the Y2K mess all over again --- in 2038!

and "Come 22:14:07 on Monday, 18 January 2038, most systems and software will be 64-bit." said Robert Love. Will these happen, let's go and see.

POSIX Clocks have four of the linux standard time source:

  • CLOCK_MONOTONIC
  • CLOCK_PROCESS_CPUTIME_ID
  • CLOCK_REALTIME
  • CLOCK_THREAD_CPUTIME_ID

Tuning the system clock

example by a Makefile

make looks at the file modification timestamps of the source file versus the object file. If the source file is newer than the object file, make rebuilds the source file into an updated object file. If the source file is not newer than the object, however, no action is taken

2011年1月4日星期二

pulseaudio module-detect analyse

source code path:
src/modules/module-detect.c

1. run this function: "int pa__init(pa_module*m)"
"pa_bool_t just_one = FALSE;" allow more than 1 devices

function pa_modargs_new
in "pulsecore/modargs.c".
"modargs.c" analyse the input args, get the args' value such as: "u32, bool, s32..." and store in pa_hashmap list.

for ALSA,OSS,SOLARIS, each has different device node, so the have different codes.
and for WIN32, it does nothing except load module "module-waveout"

There only analyse ALSA.

#ifdef HAVE_ALSA--> use for alsa
2. "detect_alsa" function:

read info from this file "/proc/asound/devices", to get the device info.
("/dev/sndstat", "/proc/sndstat", "/proc/asound/oss/sndstat" these 3 for OSS)
in my PC, the file is:

------------>
2: : timer
3: : sequencer
4: [ 0- 1]: digital audio playback
5: [ 0- 0]: digital audio playback
6: [ 0- 0]: digital audio capture
7: [ 0- 2]: hardware dependent
8: [ 0] : control
<------------

The file above tells that my PC have one control channel, two PCM playback devices (DAC's), a PCM capture device (ADC's), a hardware dependent device, a MIDI sequencer, and a timer.

This function "sscanf(line, " %*i: [%u- %u]: ", &device, &subdevice)" is so insteresting.

3. Use funtion: "pa_module_load()" to load: "module-alsa-sink", "module-alsa-source" the two modules.

The end: unload the "module-detect" itself.

Gstreamer basic Knowledge 2nd

This is my second time to read GStreamer Application Development Manual

Record something important


  • Element:

    Element is an object that can send and/or receive data, also is the most important class of objects in GStreamer
Type Details Number of pads
Source elements do not accept data, only generate data a source pad
Filters and filter-like elements operate the data at least one input and one output pads
Sink elements accept data and do not produce anything a sink pad
  • Create an element(two methods)
    1. gst_element_factory_make
    2. gst_element_factory_find + gst_element_factory_create

    • gst_init has to be called frist
    • When you don’t need the element anymore, you need to unref it using gst_object_unref ()

      The following example isthe simplest way to create an element using gst_element_factory_make
      #include <gst/gst.h>
      int main (int argc, char *argv[])
      {
       GstElement *element;
       /* init GStreamer */
       gst_init (&argc, &argv);
       /* create element */
       element = gst_element_factory_make ("fakesrc", "source");
       if (!element) {
        g_print ("Failed to create element of type ’fakesrc’\n");
        return -1;
       }
       gst_object_unref (GST_OBJECT (element));
       return 0;
      }
      

  • Pad:

    Pad is element’s input or output

    A pad can have any of three availabilities:always, sometimes and on request

  • Bin & Pipeline:

    A bin is a container elements

    A pipeline is a special subtype of a bin that allows scheduling of the containing elements

  • Bus:

    A bus is a simple system that takes care of forwarding messages from the pipeline threads to an application in its own thread context

    Every pipeline contains a bus by default

  • Use a bus(two methods)
    1. Run a main loop and attach some kind of watch to the bus using gst_bus_add_watch () or gst_bus_add_signal_watch ()
    2. Get the messages on the bus using gst_bus_peek () and/or gst_bus_poll ()

      Message types:
Name Details
Error, warning and information notifications those are used by elements if a message should be shown to the user about the state of the pipeline
End-of-stream notification emitted when the stream has ended
Tags emitted when metadata was found in the stream
State-changes emitted after a successful state change
Buffering emitted during caching of network-streams
Element messages these are special messages that are unique to certain elements and usually represent additional features
Application-specific messages any information on those can be extracted by getting the message |structure (see above) and reading its fields
  • Buffers & Events:

    The data flowing through a pipeline consists of a combination of buffers and events
    • Buffers contain the actual media data
    • Events contain control information, such as seeking information and end-of-stream notifiers

  • A buffer consists:
Number Name Description
1 Poniter A pointer to a piece of memory
2 Size The size of the memory
3 Timestamp A timestamp for the buffer
4 refcount A refcount that indicates how many elements are using this buffer, This refcount will be used to destroy the buffer when no element has a reference to it
5 Flags Buffer flags

Get more information here