/** * @name Reset delle variabili Decoder * * Questa funzione inizializza le variabili necessarie in fase di riproduzione per il decoder */ void resetMp3(char * song) { if (buffer!=NULL) {freeMp3();} int err; int channels, encoding; long rate; /* Inizialize */ mpg123_init(); mh = mpg123_new(NULL, &err); buffer_size = mpg123_outblock(mh); buffer = (unsigned char*) malloc(buffer_size * sizeof(unsigned char)); /* open the file and get the decoding format */ mpg123_open(mh,song); mpg123_getformat(mh, &rate, &channels, &encoding); /* set the output format and open the output device */ int bits=(mpg123_encsize(encoding) * BITS); initAudioDev(bits,rate,channels); }
int main(int argc, char** argv) { char *outfilename = "outfile"; int reclength= -1; // reclength in secs char c; ///////////////////////////////////////////////////// // CHECKING AND INTERPRETING COMMAND LINE SWITCHES ///////////////////////////////////////////////////// printf("\n*********************************************************************\n"); printf("\n FFV1rec based on nuppelrec by Roman Hochleitner"); printf("\n version "_VERSION_"\n"); printf("\n*********************************************************************\n"); quiet = 0; avcodec_init(); avcodec_register_all(); recordaudio = 1; memset(&ainfo,0,sizeof(ainfo)); ainfo.frequency=44100; tzone.tz_minuteswest=-60; // whatever tzone.tz_dsttime=0; now.tv_sec=0; // reset now.tv_usec=0; // reset parseRcFile(); while ((c=getopt(argc,argv,"d:b:M:q:l:c:C:S:W:H:t:NTV:A:a:srf:pnb:x:y:zQ2")) != -1) { switch(c) { case '2': do_split=1;break; case 'b': ainfo.frequency=atoi(optarg);break; case 'q': info.quality = atoi(optarg); break; case 'd': if(!(info.keydist = atoi(optarg))) info.keydist=1; break; case 'M': info.me = atoi(optarg); break; case 'S': info.channel = atoi(optarg); break; case 'W': info.width = atoi(optarg); break; case 'H': info.height = atoi(optarg); break; case 't': drec = atof(optarg); break; case 'x': videomegs = atoi(optarg); break; case 'C': if(!FFV1_selectByName(optarg)) { printf("\n cannot find this codec\n"); exit(0); };break; case 'y': audiomegs = atoi(optarg); break; case 'p': info.ntsc = 0; break; case 'n': info.ntsc = 1; break; case 's': info.ntsc = 0; info.secam=1; break; case 'f': info.frequency = atof(optarg); break; case 'z': recordaudio = 0;printf("\n Audio disabled\n"); break; case 'A': audiodevice = optarg; break; case 'V': videodevice = optarg; break; case 'Q': quiet = 1; break; case 'h': usage(); break; default: usage(); } } if (optind==argc) usage(); else outfilename=argv[optind]; if (drec != -1.0) { reclength = (int)(drec*60); } if(info.width==0) { info.width=352; } if(info.height==0) { if(info.ntsc) info.height=240; else info.height=288; } ///////////////////////////////////////////// // CALCULATE BUFFER SIZES ///////////////////////////////////////////// video_buffer_size=(info.height*info.width*3)>>1 ; if (videomegs == -1) { if (info.width>=480 || info.height>288) { videomegs = 64; //drRocket -> helps megs for big ones } else { videomegs = 14; // normally we don't need more than that } } video_buffer_count = (videomegs*1024*1024)/video_buffer_size; // we have to detect audio_buffer_size, too before initshm() // or we crash horribly later, if no audio is recorded we // don't change the value of 16384 if (recordaudio) { if (!audioDevPreinit(audiodevice,&ainfo)) { fprintf(stderr,"error: could not detect audio blocksize, audio recording disabled\n"); recordaudio = 0; } } if (audiomegs==-1) audiomegs=2; if (ainfo.bufferSize!=0) audio_buffer_count = (audiomegs*1000*1000)/ainfo.bufferSize; else audio_buffer_count = 1; fprintf(stderr, "we are using %dx%ldB video (frame-) buffers and\n %dx%ldB audio blocks\n audio fq=%ld\n", video_buffer_count, video_buffer_size, audio_buffer_count, ainfo.bufferSize, ainfo.frequency ); initBuffers(); ///////////////////////////////////////////// // NOW START WRITER/ENCODER PROCESS ///////////////////////////////////////////// writeInit(&info); PTHR *wr; wr=(PTHR *)&write_process; pthread_create(&pid_write,0,wr,outfilename); /////////////////////////// // now save the start time gettimeofday(&stm, &tzone); // #ifndef TESTINPUT ///////////////////////////////////////////// // NOW START AUDIO RECORDER ///////////////////////////////////////////// if (recordaudio) { printf("Initializing audio...\n"); if(! initAudioDev(audiodevice,&ainfo)) { fprintf(stderr, "cannot initialize audio!\n"); exit(-1); } PTHR *aud; aud=(PTHR *)&captureAudioDev; pthread_create(&pid_audio,0,aud,NULL); } else { printf("No audio.\n"); } // #endif ///////////////////////////////////////////// // NOW START VIDEO RECORDER ///////////////////////////////////////////// // only root can do this if (getuid()==0) nice(-10); if( !initVideoDev(videodevice, &info )) { printf(" Cannot init video input\n"); exit(0); } captureVideoDev(); return 0; }