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

2010年12月29日星期三

basic git command

git is the fast version control system


Now I am studying how to use git

  • Here are the commands for common using:

  1. Use git clone to check out sources. i.e. Download pulseaudio sources:

    
    
    
  2. Use git status to show your working tree status

    
    
  3. Use git pull to update the codes to the newest version

    
    
  4. Add or edit your file

  5. Commit your new file

    
    
  6. Push your change to remote repository

    
    

  • Here is a sample to generate a patch

    
    

2010年12月28日星期二

android gstreamer debug information can not work

在android上面做一些gstreamer的工作
尝试显示出gstreamer自己的调试信息
在android模拟器上面运行:

gst-launch-0.10 --gst-debug-level=1 audiotestsrc ! audioflingersink

结果显示:

Could not open converter from 'ASCII' to 'UTF-8'

调试发现:libiconv在android上面已经移除了

在gconvert.c g_convert()中添加了以上代码自己转换,将ASCII 转换成 UTF-8,debug 消息就可以打印出来了

//--> allen add for testing
printf("allen in gconvert.c g_convert() %s %d\n", str, len);
gsize retval;
gchar *utf;
gsize utfmax;
if (len < 0)
{
 len = strlen (str);
}
utfmax = 2 * (len + 1);
printf("utfmax: %d\n", utfmax);
utf = g_malloc (utfmax);
for (retval = 0; *str && utfmax > 1; utfmax -= 2, retval += 2)
{
 *(utf + retval/2) = *(str + retval/2);
 *(utf + retval/2 + 1) = 0;
}
if (utfmax > 0)
{
 *utf = *str;
 ++retval;
}
if (bytes_read)
 *bytes_read = len + 1;
if (bytes_written)
 *bytes_written = retval;
 printf("allen in gconvert.c g_convert() %s %d\n", utf, utfmax);
 return utf;
 //<--end

ubuntu qq for linux自动关闭的问题解决方法


ubuntu 10.04还是存在这个问题 哎
下面解决的办法:
1. 在终端输入命令代码:sudo vim /usr/bin/qq
2. 在打开的qq配置文件中,在#!bin/sh下面一行,cd /usr/share/tencent/qq/前面一行的位置插入代码:
export GDK_NATIVE_WINDOWS=true
3. 最终修改后的QQ脚本配置文件如下,保存关闭即可。
#!/bin/sh
export GDK_NATIVE_WINDOWS=true
cd /usr/share/tencent/qq/
./qq
 4. 重启QQ,qq不再自动退出和关闭了。

devkit8000,android,NFS boot

NFS boot

  • Follow the steps to boot the board using NFS
  1. Setup host machine as NFS server (optional)
    • If you want to setup a new NFS server, do this step

    • Add one line in /etc/exports:
      /nfsroot  *(rw,no_root_squash,sync)
      
    • Then restart NFS server
      $ sudo /etc/init.d/nfs-kernel-server restart
  2. Build Kernel for NFS boot
    • make sure your kernel enable these options for NFS boot:
      [*] Networking support  --->
            Networking options  --->
            [*]   IP: kernel level autoconfiguration
            [*]   IP: DHCP support
        
            File systems  --->
            [*] Network File Systems  --->
               <*>   NFS client support
                  [*]     NFS client support for NFS version 3
                  [*]     NFS client support for the NFSv3 ACL protocol extension
                  [*]     NFS client support for NFS version 4 (EXPERIMENTAL)
                  [*]     Root file system on NFS
      
    • Build kernel:
  3. Copy kernel to the TFTP server's root
    • We also have a TFTP server on the test machine, the TFTP server's root path is: /mydroid/tftpboot
    • Put kernel file to the TFTP server's root path
    • uImage is the name of the kernel file you just built out
      
      
  4. Prepare the rootfs
    • Put the files to the NFS root path
    • Use android for example, we build the file system first, then do the commands:
  5. Set the boot parameters to kernel for the frist time, before it run 'autoboot'
    • serverip is the IP address of your NFS server
    • for example, our NFS server ip here is 10.126.34.43
  6. Boot
    • Just restart the board
    • The same as normal boot, Enjoy!