2012年10月31日 星期三

WINCE 7 Platform Builder: Cannot set an empty string on sourceFile

在安裝新的WinCE 7 之後,迫不及待地想make 新的Au1200 Image, 裝好 BSP之後 ( 指定folder 要從\WINCE600 變成 \WINCE700 或者手動 copy 整個目錄到 Platform )。 ( BSP解開的目錄 不能含有空白字元)

在 New Project --> RMI BSP -->  ... --> 之後 到最後一步 finish
就出現了視窗,寫著 Cannot set an empty string on sourceFile

搜尋這段字串 找到了一個韓國網站
又靠著Google大神偉大的翻譯 終於解決了問題

問題源由如下

The cause of this and the platform.regis platform.bib.
Usually well below two files, but 

IF XXX
ENDIF XXX 

IF XXX
ENDIF XXX!

Sometimes, several statements in the ENDIF; (semicolon) if there are attached.
For example, ENDIF ; BSP_NOKEYBD! And the same.



意思就是說 通常問題出在 platform.reg  platform.bib


IF XXX
ENDIF XXX 

IF XXX
ENDIF XXX!



在 ENDIF 之後 不能有 ; ( semicolon )
如  ENDIF ; BSP_NOKEYBD!
把 ; 去掉就 ok了


韓國人真是厲害!


platform\db1200\sources.cmn
public\common\oak\misc\makefile.def

再來遇到 assemble cache.s 時出現錯誤 /QMmips2 跟 /QMmips32 不能共用
修改 platform/db1200/sources.cmn
CDEFINES=$(CDEFINES) /QMmips32 
把 /QMmips32 拿掉就行了

再來就是 DB1200 Driver 裡的 WAVEMDD
在 wavemdd.h 中 把一些MACRO undefined 掉

#if _WIN32_WCE == 0x700
#define FUNC_WMDD(a)
#define HEXPARAM(a)
#define DECPARAM(a)
#define INTMSG(a)
#endif


再來就是 USB20\EHCI

2012年8月14日 星期二

H.264 Elementary Stream 格式解析

格式詳述在 ISO 14996-10 (Annex B)和 rfc3984
00 00 00 01 67   
前五個byte 為 NAL Unit

bit 1  -- forbidden zero, 必須為0
bit 2-3  nal_ref_idc
bit 3-8 nal unit type


42 00 29 F4 02 80 2D 88 00 00 00
後面11個byte 為 sequence parameter set

00 00 00 01 68 CE 0B C8
再後面8個byte 為 picture parameter set

註: 要研究H.264 elementary stream 格式的話
有個 stream analyzer 會比較好用

可以試試 Elecard Stream Analyzer Demo ( Elecard StreamEye Studio)

http://www.rosoo.net/a/200912/8056.html

NAL 的格式在 14496-10  7.3
http://www.360doc.com/content/09/0429/11/59579_3309616.shtml

RBSP 是 Raw Byte Sequence Payload 的縮寫

以一段 H.264 Elementary Stream 來舉例
其架構如下
 SPS (Sequence Parameter Set, 00 00 00 01 67 ...) -->
PPS ( Picture Parameter Set, 00 00 00 01 68 ... ) -->
H.264 I Slice ( 00 00 00 01 65 )  -->
H.264 P Slice ( 00 00 00 01 41 )


I Slice ( 00 00 00 01 65, Unit Type 5 ) 是
Coded slice of an IDR picture, slice_layer_without_partitioning_rbsp( )
P Slice ( 00 00 00 01 41, Unit Type 1 ) 是

Coded slice of a non-IDR picture, slice_layer_without_partitioning_rbsp( )



instantaneous decoding refresh (IDR) picture: A coded picture containing only slices with I or SI slice types
that causes the decoding process to mark all reference pictures as "unused for reference" immediately after
decoding the IDR picture. After the decoding of an IDR picture all following coded pictures in decoding order
can be decoded without inter prediction from any picture decoded prior to the IDR picture. The first picture of
each coded video sequence is an IDR picture.



H264 Sequence Parameter Set  by Elecard Stream Analyzer

profile_idc = 66
constraint_set0_flag = 0
constraint_set1_flag = 0
constraint_set2_flag = 0
constraint_set3_flag = 0
reserved_zero_4bits = 0
level_idc = 41
seq_parameter_set_id = 0
log2_max_frame_num_minus4 = 0
pic_order_cnt_type = 0
     log2_max_pic_order_cnt_lsb_minus4 = 0
num_ref_frames = 1
gap


Useful info:
要把 little endian 轉 big endian 在VC 可以用
_byteswap_ulong
http://stackoverflow.com/questions/105252/how-do-i-convert-between-big-endian-and-little-endian-values-in-c

使用 libmp4v2

出現 error

[h264 @ 0xd39480]non-existing PPS 0 referenced
[h264 @ 0xd39480]decode_slice_header error
[h264 @ 0xd39480]no frame!


根據以上提示以及跟正常 mp4 比對後
發現在 avcc 中沒有 PPS ( Picture Parameter Sequence )
在加上 MP4AddH264SequenceParameterSet()
及 MP4AddH264PictureParameterSet() 後 就可以正常播放

avcc 格式
01 42 00 29 FF E1 00 0C 67 42 00 29 F4 02 80 2D 88 00 00 00
01 00 04 68 CE 0B C8


aligned(8) class AVCDecoderConfigurationRecord {
unsigned int(8) configurationVersion = 1;
unsigned int(8) AVCProfileIndication;
unsigned int(8) profile_compatibility;
unsigned int(8) AVCLevelIndication;
bit(6) reserved = ‘111111’b;
unsigned int(2) lengthSizeMinusOne;
bit(3) reserved = ‘111’b;
unsigned int(5) numOfSequenceParameterSets;
for (i=0; i< numOfSequenceParameterSets; i++) {
unsigned int(16) sequenceParameterSetLength ;
bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit;
}
unsigned int(8) numOfPictureParameterSets;
for (i=0; i< numOfPictureParameterSets; i++) {
unsigned int(16) pictureParameterSetLength;
bit(8*pictureParameterSetLength) pictureParameterSetNALUnit;
}
}


good MP4 article
http://www.cnblogs.com/haibindev/archive/2011/10/17/2214518.html


AAC 解碼 & mux

要查14496-3 subpart 4
還有 13818-7

raw_data_block() 在

Table 12

raw_data_block()
{
while ((id = id_syn_ele) != ID_END) { 3 uimsbf
switch (id) {
case ID_SCE: single_channel_element();
break;
case ID_CPE: channel_pair_element();
break;
case ID_CCE: coupling_channel_element();
break;
case ID_LFE: lfe_channel_element();
break;
case ID_DSE: data_stream_element();
break;
case ID_PCE: program_config_element();
break;
case ID_FIL: fill_element();
}
}
byte_alignment();
}

Table 36

Table 36 – Syntaxtic element identification
ID name encoding Abbreviation Syntactic Element
ID_SCE 0x0 SCE single_channel_element()
ID_CPE 0x1 CPE channel_pair_element()
ID_CCE 0x2 CCE coupling_channel_element()
ID_LFE 0x3 LFE lfe_channel_element()
ID_DSE 0x4 DSE data_stream_element()
ID_PCE 0x5 PCE program_config_element()
ID_FIL 0x6 FIL fill_element()
ID_END 0x7 TERM



channel_pair_element()
{
element_instance_tag; 4 uimsbf
common_window; 1 uimsbf
if ( common_window ) {
ics_info();
ms_mask_present; 2 uimsbf
if (ms_mask_present == 1) {
for (g = 0; g < num_window_groups; g++) {
for (sfb = 0; sfb < max_sfb; sfb++) {
ms_used[g][sfb]; 1 uimsbf
}
}
}
}
individual_channel_stream(common_window);
individual_channel_stream(common_window);
}


Data Example
前三個都是 0x21 0x4F 0xFE

http://honwsn.itpub.net/post/41648/497237

http://mp4tech.net/document/audiocomp/0000207.asp


上例中有2个mdat,一个是视频内容、另一个音频内容。对于h264, aac编码的媒体来说,其视频mdat中内容是nal,对于音频来说,其内容为aac的一帧。mdat中的帧依次存放,每个帧的位置、时间、长度都由moov中的信息指定。可以看出,mdat是很好组建的,这种Box只含有数据。
http://blog.csdn.net/iamshaofa/article/details/7859244
http://blog.csdn.net/yukuilongqq/article/details/7732009



2012年8月13日 星期一

AVCDecoderConfigurationRecord


AVCDecoderConfigurationRecord


14496-15
aligned(8) class AVCDecoderConfigurationRecord {
unsigned int(8) configurationVersion = 1;
unsigned int(8) AVCProfileIndication;
unsigned int(8) profile_compatibility;
unsigned int(8) AVCLevelIndication;
bit(6) reserved = ‘111111’b;
unsigned int(2) lengthSizeMinusOne;
bit(3) reserved = ‘111’b;
unsigned int(5) numOfSequenceParameterSets;
for (i=0; i< numOfSequenceParameterSets; i++) {
unsigned int(16) sequenceParameterSetLength ;
bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit;
}
unsigned int(8) numOfPictureParameterSets;
for (i=0; i< numOfPictureParameterSets; i++) {
unsigned int(16) pictureParameterSetLength;
bit(8*pictureParameterSetLength) pictureParameterSetNALUnit;
}
}

其中 AVCProfileIndication 要查 14496-10
profile_idc
Base Profile 為  66  ( 0x42)
Main Profile 為 77  (0x4D)
Extended Profile 為 88 (0x58)


Level 0x29 為 41 ==> 4.1

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