0236f317d832d3918916c7de89a78c13433ef66c
[my-code/mp3db.git] / mp3read.c
1 /* read mp3 info, hackbard */
2
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <string.h>
9 #include <errno.h>
10
11 #define MAX_READ 1024
12 #define MAX_FILENAME 32
13 #define MAX_VER_ID 64
14
15 /*
16 info:
17 http://www.dv.co.yu/mpgscript/mpeghdr.htm
18 */
19
20 int main (int argc,char **argv)
21 {
22  int file_fd,exit,count;
23  unsigned char buf;
24  unsigned char header[3];
25  char mpeg_ver_id[MAX_VER_ID];
26  char filename[MAX_FILENAME];
27
28  strcpy(filename,argv[1]);
29
30  if((file_fd=open(filename,O_RDONLY))<=0) {
31   puts("open failed");
32   return -23;
33  }
34
35  count=0;
36  exit=0;
37  while(!exit) {
38   printf("count=%d\n",count++);
39   read(file_fd,&buf,1);
40   if(buf==0xff) {
41    read(file_fd,&buf,1);
42    if(buf>=0xe0) {
43     puts("got frame header:");
44     exit=1;
45     header[0]=buf;
46     read(file_fd,header+1,2);
47
48     printf("debug: %x%x%x \n",header[0],header[1],header[2]);
49   
50     if(((header[0]&0x18)>>3)==0x00) strcpy(mpeg_ver_id,"MPEG Version 2.5");
51     else if(((header[0]&0x18)>>3)==0x10) strcpy(mpeg_ver_id,"MPEG Version 2 (ISO/IEC 13818-3)");
52     else if(((header[0]&0x18)>>3)==0x11) strcpy(mpeg_ver_id,"MPEG Version 1 (ISO/IEC 11172-3)");
53     else strcpy(mpeg_ver_id,"unknown");
54
55     printf("version: %s\n",mpeg_ver_id);
56    }
57   }
58  }
59
60  close(file_fd);
61  
62  puts("");
63  puts("done");
64  
65  return 23;
66 }
67
68
69