stream 을 188 바이트씩 읽어들이면 너무 늦습니다. 좀 빨리 받을수있는 방법이 없을까요
이플
질문 제목 : stream 을 188 바이트씩 읽어들이면 너무 늦습니다. 좀 빨리 받을수있는 방법이 없을까요?질문 요약 :안녕하세요.
이번에 dvb 스펙에서 각각 테이블을 출력해주는 간단한 프로그램을 만들려고 하는데요.
우선 stream을 읽어들이는 것은 가능하지만 188바이트씩 읽어들여서 그런지 너무 느린감이 있습니다.
188바이트씩 읽어서 출력은 해주는데 만약 PAT 테이블에서 값을 읽어들일려면 stream에서 어디에 있는지
찾을려면 찾는데 너무 시간이 걸립니다.
좀 빨리 찾을수있는 방법이 있으면 도와주세요.
소스 코드는 인터넷에 있느느것을 참고하여 했습니다.(거의 비슷하지만요.)질문 내용 :
#include stdio.h
#include errno.h
#define TS_BYTE_NUM 188
int read_next_ts_packet(unsigned char * buf, FILE * fd);
int main(int argc, char *argv[])
{
unsigned char buf[TS_BYTE_NUM];
char hexval[3];
int i, t;
long offset;
FILE * fd;
char cmd;
int cc;
if (argc != 2)
{
printf(Usage: tsreader filename\n);
return -1;
}
// file open
fd = fopen(argv[1], r);
if(!fd)
{
perror(fopen failed..);
return -1;
}
while(fd != EOF)
{
read_next_ts_packet(buf, fd);
for(i=0; i 188 ;i++)
{
if( buf[i]==0x47 && buf[i+1]==0x40 && buf[i+2]==0x00)
{
printf(TABLE ID : %02X \n, buf[i]);
printf(TABLE PID : %02X \n, buf[i+2]);
printf(PAT TABLE \n );
}
printf([%02x] , buf[i]);
if ( (i % 15) == 14 && i != 0)
{
printf(\n);
}
}
printf(\n);
}
return 0;
}
int read_next_ts_packet(unsigned char * buf, FILE * fd)
{
int readno;
// reading one ts packet (188 byte)
readno = fread(buf, TS_BYTE_NUM, 1, fd);
if(readno != 1)
{
if(feof(fd))
{
printf(file reached to end\n);
return -1;
}
else
{
perror(fread failed..);
return -1;
}
}
return readno;
}