⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sr1.c

📁 自己移植的linux下的流媒体播放器原代码,支持mms协议,支持ftp和http协议.
💻 C
📖 第 1 页 / 共 2 页
字号:
  bsbufold = bsbuf;  bsbuf = bsspace[bsnum]+512;  bsnum = (bsnum + 1) & 1;  if( mp3_read(bsbuf,size) != size) return 0; // broken frame  bitindex = 0;  wordpointer = (unsigned char *) bsbuf;  bitsleft=8*size;  return 1;}/***************************************************************** * read next frame     return number of frames read. */LOCAL int read_frame(struct frame *fr){  unsigned long newhead;  unsigned char hbuf[8];  int skipped,resyncpos;  int frames=0;resync:  skipped=MP3_fpos;  resyncpos=MP3_fpos;  set_pointer(512);  fsizeold=fr->framesize;       /* for Layer3 */  if(!stream_head_read(hbuf,&newhead)) return 0;  if(!decode_header(fr,newhead)){    // invalid header! try to resync stream!#ifdef DEBUG_RESYNC    printf("ReSync: searching for a valid header...  (pos=%X)\n",MP3_fpos);#endifretry1:    while(!decode_header(fr,newhead)){      if(!stream_head_shift(hbuf,&newhead)) return 0;    }    resyncpos=MP3_fpos-4;    // found valid header#ifdef DEBUG_RESYNC    printf("ReSync: found valid hdr at %X  fsize=%ld  ",resyncpos,fr->framesize);#endif    if(!stream_read_frame_body(fr->framesize)) return 0; // read body    set_pointer(512);    fsizeold=fr->framesize;       /* for Layer3 */    if(!stream_head_read(hbuf,&newhead)) return 0;    if(!decode_header(fr,newhead)){      // invalid hdr! go back...#ifdef DEBUG_RESYNC      printf("INVALID\n");#endif//      mp3_seek(resyncpos+1);      if(!stream_head_read(hbuf,&newhead)) return 0;      goto retry1;    }#ifdef DEBUG_RESYNC    printf("OK!\n");    ++frames;#endif  }  skipped=resyncpos-skipped;//  if(skipped && !MP3_resync) printf("\r%d bad bytes skipped  (resync at 0x%X)                          \n",skipped,resyncpos);//  printf("%8X [%08X] %d %d (%d)%s%s\n",MP3_fpos-4,newhead,fr->framesize,fr->mode,fr->mode_ext,fr->error_protection?" CRC":"",fr->padding?" PAD":"");  /* read main data into memory */  if(!stream_read_frame_body(fr->framesize)){    printf("\nBroken frame at 0x%X                                                  \n",resyncpos);    return 0;  }  ++frames;  if(MP3_resync){    MP3_resync=0;    if(frames==1) goto resync;  }  return frames;}static int _has_mmx = 0;  // used by layer2.c, layer3.c to pre-scale coeffs#include "layer2.c"#include "layer3.c"#include "layer1.c"/******************************************************************************//*           PUBLIC FUNCTIONS                  *//******************************************************************************//* It's hidden from gcc in assembler */extern void dct64_MMX(real *, real *, real *);extern void dct64_MMX_3dnow(real *, real *, real *);extern void dct64_MMX_3dnowex(real *, real *, real *);void (*dct64_MMX_func)(real *, real *, real *);#include "../cpudetect.h"// Init decoder tables.  Call first, once!#ifdef USE_FAKE_MONOvoid MP3_Init(int fakemono){#elsevoid MP3_Init(){#endif//gCpuCaps.hasMMX=gCpuCaps.hasMMX2=gCpuCaps.hasSSE=0; // for testing!    _has_mmx = 0;    dct36_func = dct36;    make_decode_tables(outscale);#ifdef CAN_COMPILE_X86_ASM    if (gCpuCaps.hasMMX)    {	_has_mmx = 1;	make_decode_tables_MMX(outscale);	mp_msg(MSGT_DECAUDIO,MSGL_V,"mp3lib: made decode tables with MMX optimization\n");	synth_func = synth_1to1_MMX;    }    if (gCpuCaps.has3DNowExt)    {	dct36_func=dct36_3dnowex;	dct64_MMX_func= (gCpuCaps.hasMMX2) ? dct64_MMX_3dnowex : dct64_MMX_3dnow;	mp_msg(MSGT_DECAUDIO,MSGL_V,"mp3lib: using 3DNow!Ex optimized decore!\n");    }    else    if (gCpuCaps.has3DNow)    {	dct36_func = dct36_3dnow;	dct64_MMX_func = dct64_MMX_3dnow;	mp_msg(MSGT_DECAUDIO,MSGL_V,"mp3lib: using 3DNow! optimized decore!\n");    }    else    if (gCpuCaps.hasMMX)    {	dct64_MMX_func = dct64_MMX;	mp_msg(MSGT_DECAUDIO,MSGL_V,"mp3lib: using MMX optimized decore!\n");    }    else    if (gCpuCaps.cpuType >= CPUTYPE_I586)    {	synth_func = synth_1to1_pent;	mp_msg(MSGT_DECAUDIO,MSGL_V,"mp3lib: using Pentium optimized decore!\n");    }    else#endif    {	synth_func = NULL; /* use default c version */	mp_msg(MSGT_DECAUDIO,MSGL_V,"mp3lib: using generic C decore!\n");    }#ifdef USE_FAKE_MONO    if (fakemono == 1)        fr.synth=synth_1to1_l;    else if (fakemono == 2)        fr.synth=synth_1to1_r;    else        fr.synth=synth_1to1;#else    fr.synth=synth_1to1;#endif    fr.synth_mono=synth_1to1_mono2stereo;    fr.down_sample=0;    fr.down_sample_sblimit = SBLIMIT>>(fr.down_sample);    init_layer2();    init_layer3(fr.down_sample_sblimit);    mp_msg(MSGT_DECAUDIO,MSGL_V,"MP3lib: init layer2&3 finished, tables done\n");}#if 0void MP3_Close(){  MP3_eof=1;  if(mp3_file) fclose(mp3_file);  mp3_file=NULL;}// Open a file, init buffers. Call once per file!int MP3_Open(char *filename,int buffsize){  MP3_eof=1;   // lock decoding  MP3_pause=1; // lock playing  if(mp3_file) MP3_Close(); // close prev. file  MP3_frames=0;  mp3_file=fopen(filename,"rb");//  printf("MP3_Open: file='%s'",filename);//  if(!mp3_file){ printf(" not found!\n"); return 0;} else printf("Ok!\n");  if(!mp3_file) return 0;  MP3_filesize=MP3_PrintTAG();  fseek(mp3_file,0,SEEK_SET);  MP3_InitBuffers(buffsize);  if(!tables_done_flag) MP3_Init();  MP3_eof=0;  // allow decoding  MP3_pause=0; // allow playing  return MP3_filesize;}#endif// Read & decode a single frame. Called by sound driver.int MP3_DecodeFrame(unsigned char *hova,short single){   pcm_sample = hova;   pcm_point = 0;   if(!read_frame(&fr))return(0);   if(single==-2){ set_pointer(512); return(1); }   if(fr.error_protection) getbits(16); /* skip crc */   fr.single=single;   switch(fr.lay){     case 2: do_layer2(&fr,single);break;     case 3: do_layer3(&fr,single);break;     case 1: do_layer1(&fr,single);break;     default:         return 0;	// unsupported   }//   ++MP3_frames;   return(pcm_point?pcm_point:2);}// Prints last frame header in ascii.void MP3_PrintHeader(){        static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" };        static char *layers[4] = { "???" , "I", "II", "III" };        mp_msg(MSGT_DECAUDIO,MSGL_V,"\rMPEG %s, Layer %s, %ld Hz %d kbit %s, BPF: %ld\n",                fr.mpeg25 ? "2.5" : (fr.lsf ? "2.0" : "1.0"),                layers[fr.lay],freqs[fr.sampling_frequency],    tabsel_123[fr.lsf][fr.lay-1][fr.bitrate_index],                modes[fr.mode],fr.framesize+4);        mp_msg(MSGT_DECAUDIO,MSGL_V,"Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d\n",                fr.stereo,fr.copyright?"Yes":"No",                fr.original?"Yes":"No",fr.error_protection?"Yes":"No",                fr.emphasis);}#if 0#include "genre.h"// Read & print ID3 TAG. Do not call when playing!!!  returns filesize.int MP3_PrintTAG(){        struct id3tag {                char tag[3];                char title[30];                char artist[30];                char album[30];                char year[4];                char comment[30];                unsigned char genre;        };        struct id3tag tag;        char title[31]={0,};        char artist[31]={0,};        char album[31]={0,};        char year[5]={0,};        char comment[31]={0,};        char genre[31]={0,};  int fsize;  int ret;  fseek(mp3_file,0,SEEK_END);  fsize=ftell(mp3_file);  if(fseek(mp3_file,-128,SEEK_END)) return fsize;  ret=fread(&tag,128,1,mp3_file);  if(ret!=1 || tag.tag[0]!='T' || tag.tag[1]!='A' || tag.tag[2]!='G') return fsize;        strncpy(title,tag.title,30);        strncpy(artist,tag.artist,30);        strncpy(album,tag.album,30);        strncpy(year,tag.year,4);        strncpy(comment,tag.comment,30);        if ( tag.genre <= sizeof(genre_table)/sizeof(*genre_table) ) {                strncpy(genre, genre_table[tag.genre], 30);        } else {                strncpy(genre,"Unknown",30);        }//      printf("\n");        printf("Title  : %30s  Artist: %s\n",title,artist);        printf("Album  : %30s  Year  : %4s\n",album,year);        printf("Comment: %30s  Genre : %s\n",comment,genre);        printf("\n");  return fsize-128;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -