annotate mp3lib/test.c @ 31169:ac84149bbdaf

Retry reading even if we hit eof before. This allows playing growing files even with a large cache.
author reimar
date Wed, 26 May 2010 18:23:43 +0000
parents fee09b258e8a
children 1c789a1ad0f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30452
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
1 /*
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
2 * This file is part of MPlayer.
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
3 *
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
5 * it under the terms of the GNU General Public License as published by
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
7 * (at your option) any later version.
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
8 *
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
12 * GNU General Public License for more details.
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
13 *
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
14 * You should have received a copy of the GNU General Public License along
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
fee09b258e8a Add missing license headers to test programs for external libraries.
diego
parents: 29717
diff changeset
17 */
814
13805b1ca0f7 dump to file
arpi_esp
parents: 788
diff changeset
18
13805b1ca0f7 dump to file
arpi_esp
parents: 788
diff changeset
19 #define DUMP_PCM
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
20
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
21 #include <stdio.h>
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
22 #include <stdlib.h>
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
23
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
24 #include <unistd.h>
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
25 #include <sys/time.h>
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
26
26203
0d255d03016f #include config.h before all other headers.
diego
parents: 16989
diff changeset
27 #include "config.h"
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
28 #include "mp3lib/mp3.h"
16989
e7a129082fda Unify include paths, -I.. is in CFLAGS.
diego
parents: 10372
diff changeset
29 #include "cpudetect.h"
10372
17554a75a654 getcpucaps support
alex
parents: 826
diff changeset
30
28232
8df85ad26746 Add missing 'void' keyword to parameterless function declarations.
diego
parents: 27341
diff changeset
31 static inline unsigned int GetTimer(void){
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
32 struct timeval tv;
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
33 struct timezone tz;
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
34 // float s;
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
35 gettimeofday(&tv,&tz);
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
36 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
29717
afc8b80eb027 cosmetics: Remove some pointless parentheses from return calls.
diego
parents: 29263
diff changeset
37 return tv.tv_sec * 1000000 + tv.tv_usec;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
38 }
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
39
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
40 static FILE* mp3file=NULL;
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
41
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
42 int mplayer_audio_read(char *buf,int size){
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
43 return fread(buf,1,size,mp3file);
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
44 }
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
45
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
46 #define BUFFLEN 4608
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
47 static unsigned char buffer[BUFFLEN];
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
48
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
49 int main(int argc,char* argv[]){
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
50 int len;
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
51 int total=0;
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
52 unsigned int time1;
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
53 float length;
814
13805b1ca0f7 dump to file
arpi_esp
parents: 788
diff changeset
54 #ifdef DUMP_PCM
13805b1ca0f7 dump to file
arpi_esp
parents: 788
diff changeset
55 FILE *f=NULL;
13805b1ca0f7 dump to file
arpi_esp
parents: 788
diff changeset
56 f=fopen("test.pcm","wb");
13805b1ca0f7 dump to file
arpi_esp
parents: 788
diff changeset
57 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
58
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
59 mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb");
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
60 if(!mp3file){ printf("file not found\n"); exit(1); }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
61
10372
17554a75a654 getcpucaps support
alex
parents: 826
diff changeset
62 GetCpuCaps(&gCpuCaps);
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
63
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
64 // MPEG Audio:
27341
e7c989f7a7c9 Start unifying names of internal preprocessor directives.
diego
parents: 26504
diff changeset
65 #ifdef CONFIG_FAKE_MONO
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
66 MP3_Init(0);
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
67 #else
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
68 MP3_Init();
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
69 #endif
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
70 MP3_samplerate=MP3_channels=0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
71
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
72 time1=GetTimer();
814
13805b1ca0f7 dump to file
arpi_esp
parents: 788
diff changeset
73 while((len=MP3_DecodeFrame(buffer,-1))>0 && total<2000000){
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
74 total+=len;
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
75 // play it
814
13805b1ca0f7 dump to file
arpi_esp
parents: 788
diff changeset
76 #ifdef DUMP_PCM
13805b1ca0f7 dump to file
arpi_esp
parents: 788
diff changeset
77 fwrite(buffer,len,1,f);
13805b1ca0f7 dump to file
arpi_esp
parents: 788
diff changeset
78 #endif
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
79 //putchar('.');fflush(stdout);
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
80 }
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
81 time1=GetTimer()-time1;
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
82 length=(float)total/(float)(MP3_samplerate*MP3_channels*2);
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
83 printf("\nDecoding time: %8.6f\n",(float)time1*0.000001f);
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
84 printf("Uncompressed size: %d bytes (%8.3f secs)\n",total,length);
10372
17554a75a654 getcpucaps support
alex
parents: 826
diff changeset
85 printf("CPU usage at normal playback: %5.2f %%\n",time1*0.0001f/length);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28232
diff changeset
86
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
87 fclose(mp3file);
26502
b3661a203f8b Add return statement, fixes the warning:
diego
parents: 26501
diff changeset
88 return 0;
788
214ea3f02d13 test.c added for benchmarking
arpi_esp
parents:
diff changeset
89 }