2009年2月24日 星期二

popen and mmap

轉載

http://groups.google.com/group/comp.os.linux.development.system/browse_thread/thread/113038b65f4d3257

On Sat, 24 Jan 2009 12:32:40 -0800 (PST) spasmous2 <spasm...@gmail.com> wrote:
| I want to pipe the output of a system utility to a C program I'm
| writing. I tried popen() and it works nicely. The return type is a
| FILE* which I would like to map to memory using mmap() in the
| following way:
|
|    file = popen(command,"r");
|
|    data = (char*)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fileno
| (file), 0);
|
| However the mmap command returns an error 'No such device', which I
| looked up to mean 'The fildes parameter does not refer to a *TYPE2
| stream file (*STMF) in the "root" (/), QOpenSys, or user-defined file
| systems.'
|
| I am unsure really what this means - do you know if it's a deal
| breaker or is there a solution?

You've been told by another followup that you cannot mmap a pipe.  The reason
you cannot do this is because a pipe is not data storage that can be accessed
by random position.  In an extreme way, a tape could be, but even it does not
work that way with existing drivers.  A pipe is a _sequential_ data stream
produced by the writing of another program.


If you want random memory access to data from another program, what you want
is a shared mapping between these programs.  There are a couple ways to do
that between processes.  Or you could use threads (if willing to spend time
to understand the complexities of threads).

以上的意思是說mmap不能用在任何streaming的應用

殘念


2009年2月18日 星期三

PXA255 uboot

patch uboot

+===================================================================
+--- u-boot-1.1.6.orig/board/pxa255_idp/memsetup.S
++++ u-boot-1.1.6/board/pxa255_idp/memsetup.S
+@@ -41,8 +41,8 @@ DRAM_SIZE: .long CFG_DRAM_SIZE
+ /*
+ * Memory setup
+ */
+-.globl memsetup
+-memsetup:
++.globl lowlevel_init
++lowlevel_init:
+
+ mov r10, lr
+
+Index: u-boot-1.1.6/include/configs/pxa255_idp.h
+===================================================================
+--- u-boot-1.1.6.orig/include/configs/pxa255_idp.h
++++ u-boot-1.1.6/include/configs/pxa255_idp.h
+@@ -41,7 +41,7 @@
+ * If we are developing, we might want to start armboot from ram
+ * so we MUST NOT initialize critical regs like mem-timing ...
+ */
+-#define CONFIG_INIT_CRITICAL /* undef for developing */
++#undef CONFIG_INIT_CRITICAL /* undef for developing */
+
+ /*
+ * define the following to enable debug blinks. A debug blink function
============================================================

CROSS_COMPILE=arm-linux-uclibc-

make pxa255_idp_config
make all





2009年2月16日 星期一

mipsel linux mplayer

Download MPlayer-1.0rc2

偶只想要decoder,所以拿掉encoder

./configure --enable-cross-compile --target=mips-linux --cc=mipsel-linux-uclibc-gcc --host-cc=gcc --disable-mencoder

make

然後錯誤出現囉

修改libavutil/internal.h
加入以下function


#if !HAVE_LLRINT
static av_always_inline long long llrint(double x)
{
return rint(x);
}
#endif /* HAVE_LLRINT */

#if !HAVE_LRINT
static av_always_inline long int lrint(double x)
{
return rint(x);
}
#endif /* HAVE_LRINT */

#if !HAVE_ROUND
static av_always_inline double round(double x)
{
return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
}
#endif /* HAVE_ROUND */

#if !HAVE_ROUNDF
static av_always_inline float roundf(float x)
{
return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
}
#endif /* HAVE_ROUNDF */

#if !HAVE_TRUNCF
static av_always_inline float truncf(float x)
{
return (x > 0) ? floor(x) : ceil(x);
}
#endif /* HAVE_TRUNCF */


降樣子就OK囉

mipsel-linux-uclibc-strip mplayer

將mplayer丟到target上執行

video out to framebuffer & no sound
./mplayer -vo fbdev -nosound 0001.AVI

允許丟棄frame
./mplayer -vo fbdev -nosound -framedrop ./鐵鉆山老二-43.29.mpeg

rescale to 320x240 frame rate 5, -ni是在處理不正確的avi format
./mplayer -vf scale=320:240 -fps 5 -zoom -vo fbdev -nosound -ni ./luna.avi

./mplayer -vo fbdev -nosound ./32.70_0002.wmv

連WMV都可以play,真是讚啊

Internet radio
./mplayer -playlist ../tunein-station-4.pls


# ./mplayer -vo fbdev -nosound -framedrop 五分山20080921-小黑-Skorpion001.mpeg
MPlayer 1.0rc2-3.4.6 (C) 2000-2007 MPlayer Team
CPU: SGI MIPS

Playing 五分山20080921-小黑-Skorpion001.mpeg.
MPEG-PS file format detected.
VIDEO:  MPEG1  352x240  (aspect 12)  29.970 fps  1152.0 kbps (144.0 kbyte/s)
==========================================================================
Opening video decoder: [mpegpes] MPEG 1/2 Video passthrough
VDec: vo config request - 352 x 240 (preferred colorspace: Mpeg PES)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
The selected video_out device is incompatible with this codec.
Try appending the scale filter to your filter list,
e.g. -vf spp,scale instead of -vf spp.
VDecoder init failed :(
Opening video decoder: [libmpeg2] MPEG 1/2 Video decoder libmpeg2-v0.4.0b
Selected video codec: [mpeg12] vfm: libmpeg2 (MPEG-1 or 2 (libmpeg2))
==========================================================================
Audio: no sound
Starting playback...
VDec: vo config request - 352 x 240 (preferred colorspace: Planar YV12)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is 1.30:1 - prescaling to correct movie aspect.
[swscaler @ 0xaa7440]No accelerated colorspace conversion found
[swscaler @ 0xaa7440]SwScaler: using unscaled yuv420p -> bgr565 special converter
VO: [fbdev] 352x240 => 352x270 BGR 16-bit
V:  10.5 296/296 105% 74%  0.0% 0 0                                                                    

如果使用libmad
執行時加上 -ac mad

Reference

http://amoi.it168.com/blog.php?tid=321580

http://www.oppo.com/index.php?q=oppoblog/view/11752

http://people.bath.ac.uk/enpsgp/floating_point.html

http://cha.homeip.net/blog/archives/2008/03/mplayerffmpeg.html

http://blog.chinaunix.net/u1/34961/showart_494026.html


2008年12月24日 星期三

nano-X JPEG display problem

1.畫面顯示只有256色

Disable fast jpeg

include/device.h

#define FASTJPEG 0  /* =1 fot temp quick jpeg 8bpp*/

2.載入大檔案時 nano-X 結束.

# /tmp/nxview /phone/media/picture/DSC_0251.JPG
Improper call to JPEG library in state 202
nxclient: lost connection to Nano-X server

Trace之後發現是memory不夠了,malloc失敗.
之後nano-X操作jpeglib的程序有問題

engine/image_jpeg.c

int
GdDecodeJPEG(buffer_t * src, PMWIMAGEHDR pimage, PSD psd, MWBOOL fast_grayscale)
{
.....
.....
.....
    /* Step 5: Start decompressor */
    jpeg_start_decompress (&cinfo);

    /* Step 6: while (scan lines remain to be read) */
    while(cinfo.output_scanline < cinfo.output_height) {
        JSAMPROW rowptr[1];
        rowptr[0] = (JSAMPROW)(pimage->imagebits +
            cinfo.output_scanline * pimage->pitch);
        jpeg_read_scanlines (&cinfo, rowptr, 1);
    }
    ret = 1;
#if 1 /*Modify by Steve*/ <<--改到這裡就OK啦
  /* Step 7: Finish decompression */
  jpeg_finish_decompress (&cinfo);
#endif
err:
#if 0 /*Modify by Steve*/ <<--就是這裡囉
    /* Step 7: Finish decompression */
    jpeg_finish_decompress (&cinfo);
#endif
    /* Step 8: Release JPEG decompression object */
    jpeg_destroy_decompress (&cinfo);

    /* May want to check to see whether any corrupt-data
     * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
     */
    return ret;
}
#endif /* MW_FEATURE_IMAGES && defined(HAVE_JPEG_SUPPORT)*/

3.圖檔太大會因為memory不夠而無法顯示

解決方式是在jepglib decompress 時作 scaling

engine/image_jpeg.c

int
GdDecodeJPEG(buffer_t * src, PMWIMAGEHDR pimage, PSD psd, MWBOOL fast_grayscale)
{
.....
.....
.....

    jpeg_calc_output_dimensions(&cinfo);

#if 1
  int wfac, hfac, fac;
  wfac = cinfo.output_width / psd->xres;
  hfac = cinfo.output_height / psd->yres;
  fac = wfac;
  if(fac > hfac)
    fac = hfac;
  if(fac > 8) fac = 8;  /* 1/8 */
  else if(fac > 4)  fac = 4;  /* 1/4 */
  else if(fac > 2)  fac = 2;  /* 1/2 */
  else fac = 1; /*No scaling*/

  cinfo.scale_num = 1;
  cinfo.scale_denom = fac;
  cinfo.dct_method = JDCT_FASTEST;
  cinfo.do_fancy_upsampling = FALSE;

  jpeg_calc_output_dimensions(&cinfo);
#endif

.....
.....
.....
}
#endif /* MW_FEATURE_IMAGES && defined(HAVE_JPEG_SUPPORT)*/



2008年12月23日 星期二

Redirect printf to file

#include <stdio.h>
#include <stdlib.h>

  FILE *fp;
  fp = freopen("/tmp/dock.log", "w", stdout);

  printf("printf to /tmp/dock.log ...\n");

  fclose(fp);

2008年12月10日 星期三

nano-X Window Manager

nano-X並沒有自動處理視窗在screen繪圖的動作,例如A視窗有部份區域與B視窗重疊,當A視窗結束消失,B視窗被A視窗覆蓋的部份會是一片空白.

在nano-X上實作一個Window Manager才能解決上述的問題.
nano-X中的nanowm可作為參考.

nano-X 提供了Graphic UI所需要的基礎功能,大致上可分為

1.操作繪圖區域
GrNewWindow
GrNewPixmap
GrMapWindow
GrUnmapWindow
GrReparentWindow
GrCopyArea
GrClearArea
2.繪圖物件 Graphic Context
GrNewGC
GrCopyGC
GrForeground
GrBackground
GrSetGCFont
3.繪圖工具
GrLine
GrRect
GrPoly
GrFillRect
GrFillPoly
4.繪圖區域狀態管理,回報視窗顯示,子視窗狀態更新等
GrCheckNextEvent

實做Window Manager之前必須了解的事情
0.視窗具有父子階層的關係,子視窗的x,y軸位置是相對於父視窗.父視窗的大小範圍就是子視窗的可視繪圖範圍
1.GR_ROOT_WINDOW_ID代表系統中最底層的視窗即root window,可當作桌面來看待.
2.視窗分為兩種Container Window與Client Window,
Container Window其父視窗為root window.
Client window其父視窗為Container Window.
3.Window Manager需要處理視窗Event.
此功能為實做Window Manager最重要的部份.關係到視窗的正確顯示.

GR_EVENT_TYPE_EXPOSURE :
視窗需要重繪.


GR_EVENT_TYPE_CHLD_UPDATE :
子視窗狀態改變了.
若子視窗隱藏(unmap),父視窗為Container Window則重繪父視窗.









2008年12月5日 星期五

軟體開發文章

閱讀他人的程式碼(1)─讀懂程式碼,使心法皆為我所用

http://www.ithome.com.tw/itadm/article.php?c=47717

不會寫程式但是在做系統分析 有沒有不會寫程式卻在做系統分析的? [精華]

http://funp.com/push/index.php?tag=%E7%A8%8B%E5%BC%8F&hot=&stars=1&page=11#p=81693


強化程式可讀性,以提升開發的效率

http://www.ithome.com.tw/itadm/article.php?c=52029


管理者要懂得如何用嘴巴寫程式

http://www.ithome.com.tw/itadm/article.php?c=51771


註解不是換句話說,是補程式的不足

http://www.ithome.com.tw/itadm/article.php?c=51597


打造穩固程式碼,先從思路方向著手

http://www.ithome.com.tw/itadm/article.php?c=51397


當程式人「晉升」至管理階級

http://www.ithome.com.tw/itadm/article.php?c=51133


程式設計的2大面向:演算和架構


http://www.ithome.com.tw/itadm/article.php?c=49841

GUI的開發瓶頸

http://www.ithome.com.tw/itadm/article.php?c=49436


漫談程式碼的相依性 (1)時時關注類別的相依程度、持續改善

http://www.ithome.com.tw/itadm/article.php?c=49179

程式碼的演化之路(1)持續讓程式碼保持進步的能力

http://www.ithome.com.tw/itadm/article.php?c=48746


程式設計2.0 (1)善用優質網站資源,快速上手新技術

http://www.ithome.com.tw/itadm/article.php?c=47405

物件導向程式設計常見的錯誤(1)抽離作用重複的程式碼,重構品質

http://www.ithome.com.tw/itadm/article.php?c=45745


物件導向與封裝

http://www.ithome.com.tw/itadm/article.php?c=45903