- 论坛徽章:
- 0
|
本帖最后由 marco_hxj 于 2010-10-22 11:32 编辑
这个程序是在一个文件中找出以 00 00 00 01开头的数据段,返回数据长度,每个长度不会超过5K字节
1.在RHEL5上运行的时候,一个7M的文件也能完整解析,但是最后fclose的时候会出现Segmentation fualt
2.在嵌入式平台上运行的时候,解析到最后面还有几十个数据包的时候,会出现
pgd = c06b4000
1-[fb35f9f4] *pgd=00000000e
0
-cPid: 111, comm: a.out
2CPU: 0
PC is at 0xfb35f9f4
reLR is at 0x40087194
t=pc : [<fb35f9f4>] lr : [<40087194>] Tainted: P
sp : e24f3cfc ip : 00011050 fp : e76dbfe3
13r10: 40133000 r9 : 00000000 r8 : 000087f0
r7 : 00000001 r6 : 00008a44 r5 : 000089e0 r4 : 3242c485
r3 : ffffffff r2 : 00010c94 r1 : becbeea8 r0 : 00000000
0-Flags: nzCv 0 IRQs on FIQs on Mode USER_32 Segment user
- Control: 397F Table: 006B4000 DAC: 00000015
0[<c0b879d8>] - (show_regs+0x0/0x4c) 1from [<c0b8cdcc>] -8(__do_user_fault+0x5c/0xa4)
1- r4 = C0033320 d
[<c0b8cd70>]
r(__do_user_fault+0x0/0xa4) efrom [<c0b8ce5c>] t=(do_bad_area+0x48/0x6c)
2 r7 = 00000000 6 r6 = C06B4000 r5 = C0A37FB0 r4 = 00000000
[<c0b8ce14>] 0-(do_bad_area+0x0/0x6c) 0from [<c0b8d17c>] - (do_translation_fault+0xac/0xb
0 r5 = 00000000 - r4 = C0A36000
1[<c0b8d0d0>] -6(do_translation_fault+0x0/0xb 0from [<c0b8d298>] -8(do_PrefetchAbort+0x18/0x1c)
a r8 = 000087F0
r7 = 00000001 r r6 = 00008A44 e r5 = 000089E0
t r4 = FFFFFFFF =
2[<c0b8d280>] 6 (do_PrefetchAbort+0x0/0x1c) from [<c0b85b08>] (ret_from_exception+0x0/0x10)
在嵌入式平台下,200K左右的文件也会出现上述输出
同时fclose的时候也会出现Segmentation fualt
折腾了一天,不知道问题出在哪里
文件有可能达到100M,我的内存只有32M,需要啥优化吗?
- #include <stdio.h>
- FILE *fp_playBack;
- unsigned int get_a_nalu(unsigned char *buf)
- {
- unsigned char tmp;
- unsigned char header[4];
- unsigned int header_isFound = 0;
- unsigned int data_isReady = 0;
- unsigned int i = 0;
-
- while(feof(fp_playBack)!=1)
- {
- fread(&tmp, 1, 1, fp_playBack);
- header[0] = header[1];
- header[1] = header[2];
- header[2] = header[3];
- header[3] = tmp;
- if (header[0]==0x00 && header[1]==0x00 && header[2]==0x00 && header[3]==0x01)
- {
- fread(&tmp, 1, 1, fp_playBack);
- if (tmp==0x67 || tmp==0x68)
- {
- if(header_isFound == 0)
- {
- continue;
- }
- }
- header_isFound = 1;
- if (data_isReady)
- {
- fseek (fp_playBack, -4, SEEK_CUR);/*把文件指针指向前一个NALU的末尾*/
- usleep(200);
- return i-3;
- }
- memcpy(buf, header, 4);
- i= 4;
- }
-
- if (header_isFound)
- {
- data_isReady = 1;
- buf[i++] = tmp;
- }
- }
- return 0;
- }
- #define FILE "/tmp/test00.264"
- int main(void)
- {
- printf("gjgkj\n");
- sleep(2);
- unsigned char buf[1024*5];
- int ret;
-
- fp_playBack = fopen(FILE,"rb");
- if (fp_playBack == NULL)
- {
- printf("open error\n");
- return 0;
- }
- while(feof(fp_playBack)!=1)
- {
- ret = get_a_nalu(buf);
- printf("ret=%d\n", ret);
- fflush(stdout);
- printf("%2x-%2x-%2x-%2x-%2x-%2x\n",buf[0], buf[1], buf[2], buf[3], buf[ret-2],buf[ret-1]);
- fflush(stdout);
- }
- if (fp_playBack != NULL)
- {
- fclose(fp_playBack);
- }
- }
复制代码 |
|