2012年7月30日 星期一

Visual Studio Crash Windows when Profiling

當在用 Visual Studio 試著 profile FAAC 的效率時
出現了bluescreen : STOP 0x0000004A
IRQL_GT_ZERO_AT_SYSTEM_SERVICE
而這是我在 Mac Mini (2011) 上還未出現過的現象

經過了Google 一番 終於解決了這個問題
原因是 Visual Studio 2008 SP1 Team System Profiler 在Nehalem或者之後的CPU 用sampling profiler 會hang, 因為當時 Nehalem還沒上市, 而profiler 的 driver (VsPerfDrv90.sys) 是跟 CPU硬體息息相關的.

解決方法很簡單,只要下載 KB958842 Hotfix 並安裝後就ok

http://archive.msdn.microsoft.com/KB958842

compile FAAC in MIPS

在 Project libmp4v2_st  mpeg4ip_win32.h 中
Error:
沒有 errno.h
沒有 io.h
沒有 fcntl.h
沒有 sys/types.h
沒有 sys/stat.h
沒有 sys/timeb.h


沒有 vsnprintf_s  改成 _vsnprintf
沒有 printf_s 及 fprintf_s 改成 printf  及 fprintf
沒有 ERANGE EACCES EINVAL --> 從 WIN32 errno.h copy


Project  faac  input.c
沒有 O_BINARY 用 _O_BINARY
沒有 perror()
沒有 rewind() 用fseek( sndf->f, 0, SEEK_SET); 取代

main.c
沒有 SetConsoleTitle()

mp4file.cpp
沒有 GetTempFileNameA() 要改成 GetTempFileNameW()
沒有 remove() 跟 rename()


getopt.c
沒有 getenv()


need_for_win32.c
沒有 sys/timeb.h so 沒有 _ftime() 所以要改寫 gettimeofday


mp4util.c
沒有 strerror()


Link 時會出現

fatal error LNK1112: module machine type 'mips' conflicts with target machine type 'x86'


在 project faac 的 Link 額外選項 把/Machine:i386 刪掉


會出現 沒有 WinMainCRTStartup 錯誤

fuck!
WIN32 的 entry point 是 wmainCRTStartup 或 mainCRTStartup 
而 WINCE 的 entry point 是 mainWCRTStartup 或 mainACRTStartup
http://msdn.microsoft.com/en-us/library/f9t8842e(v=vs.80).aspx


沒有 _ntohl , link WS2.lib


Link Error:
(In faacgui)

unresolved external symbol:

DragAcceptFiles
沒有WM_DROPFILES


發現 faac, mp4creator(mp4muxer) 用的都是 libmp4v2

2012年7月23日 星期一

Port LAME MP3 Encoder to MIPS WINCE

DL LAME 3.99.5
基本上打開 vc9_lame.sln  就可以build 了,但是這是 Windows 版本

選擇 solution platform
改成 STANDARDSDK_500 (MIPS)
copy from WIN32


基本上
從Windows porting 到 WINCE 會遇到下列問題

1. WINCE 沒有
signal.h
errno.h
fcntl.h
io.h

沒有
sys/types.h
sys/stat.h
sys/timeb.h

沒有
SetPriorityClass(), ftime()

沒定義 _IOFBF, 其值為0

2. 要定義 _MIPS_,  跟 STRSAFE_NO_DEPRECATE

STDIN_FILENO, STDOUT_FILENO。STDERR_FILENO
http://checko.blogspot.tw/2006/03/file-and-stream-stdin-and-stdinfileno.html
http://www.mail-archive.com/dev@apr.apache.org/msg18982.html
http://forum.soft32.com/pda/Porting-app-GetStdHandle-ftopict51244.html

3. 最好定義 _WIN32_WCE, Link Subsystem 要指定為WINDOWSCE

在 build LAME 時 會出現一個 warning
 'strdup' undefined; assuming extern returning int
把 strdup 改成 _strdup 就好了

4. mpglib & libmp3lame 容易過關
但是frontend 的 lame.exe 部份就要修改
lametime.c 沒有 clock(), time(),
parse.c 沒有 FindFirstFileA 要改成 FindFirstFileW

沒有 SetPriorityClass(),  WINCE 是直接 map 248-255 這8個 (0 最高255最低)
Windows 是6個Priority Class 7個 Priority Level
6 * 7 = 42 種組合 map 到 0-31 priority ( 0 最低)


5. 沒有 stdint.h 這個檔案是c99 相關的, VS2008 (包含)以前的版本都不支援,(VS2008 C99 支援很差?) 在Visual Studio 2010 的版本,放在 \vc\include 下

6. 有 setvbuf 卻沒有定義 _IOFBF _IONBF ...



最後有一堆 Linking Error

因為用 wmain 所 entry point 要設成 mainWCRTStartup


Windows CE supports the following CRT entry points:
  • mainACRTStartup for applications that define the main function
  • mainWCRTStartup for applications that define the wmain function
  • WinMainCRTStartup for applications that define the WinMain function
  • wWinMainCRTStartup for applications that define the wWinMain function
  • _DllMainCRTStartup for DLLs
沒有 _wgetenv, GetConsoleOutputCP
沒有 powf, log10f 改成 pow, log10
沒有 time(), 因為被 preprocessor 改成 _time64()

lame_get_file_size 的問題
需要在 FILE* 和 HANDLE 之間轉換
_get_osfhandle  可以把 file descriptor 轉成 file handle
_fileno 可以把 file pointer (FILE*) 轉成 file descriptor

但是
在WINCE下沒有 _get_osfhandle