int MakeKaraokebutton1callback(int butno,int i,void *Tmp) { /*********************************** butno : selected item (1 to max_item) i : Index of Widget (0 to max_widgets-1) Tmp : Pointer to DIALOG ***********************************/ DIALOG *D;DIN *B; char FileName[500]; int n,ret =0; DIT *T; D = (DIALOG *)Tmp; B = (DIN *)kgGetWidget(Tmp,i); T = (DIT *)kgGetNamedWidget(Tmp,"KaraokeTextBox1"); FileName[0]='\0'; strcpy(FileName,kgGetString(T,0)); kgFolderBrowser(NULL,100,100,FileName,"*"); CheckMedia(FileName); if(Minfo.Audio !=0 ) { kgSetString(T,0,FileName); kgUpdateWidget(T); kgUpdateOn(Tmp); } return ret; }
/** * For driver use only. * * @return */ uint8_t BulkOnly::Poll() { //uint8_t rcode = 0; if(!bPollEnable) return 0; if((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L) { CheckMedia(); } //rcode = 0; return 0; }
/** * For driver use only. * * @return */ uint8_t BulkOnly::Poll() { //uint8_t rcode = 0; if (!bPollEnable) return 0; if (qNextPollTime <= millis()) { CheckMedia(); } //rcode = 0; return 0; }
int main(int argc, const char *argv[]) { if ( argc > 1) { std::string fname = argv[1]; CheckMedia(0, 0, fname); } }
/** * * @param parent (not used) * @param port (not used) * @param lowspeed true if device is low speed * @return 0 for success */ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) { uint8_t rcode; uint8_t num_of_conf = epInfo[1].epAddr; // number of configurations epInfo[1].epAddr = 0; USBTRACE("MS Init\r\n"); AddressPool &addrPool = pUsb->GetAddressPool(); UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; // Assign new address to the device delay(2000); rcode = pUsb->setAddr(0, 0, bAddress); if(rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:", rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if(rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for(uint8_t i = 0; i < num_of_conf; i++) { ConfigDescParser< USB_CLASS_MASS_STORAGE, MASS_SUBCLASS_SCSI, MASS_PROTO_BBB, CP_MASK_COMPARE_CLASS | CP_MASK_COMPARE_SUBCLASS | CP_MASK_COMPARE_PROTOCOL > BulkOnlyParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &BulkOnlyParser); if(rcode) goto FailGetConfDescr; if(bNumEP > 1) break; } if(bNumEP < 3) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Conf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if(rcode) goto FailSetConfDescr; //Linux does a 1sec delay after this. delay(1000); rcode = GetMaxLUN(&bMaxLUN); if(rcode) goto FailGetMaxLUN; if(bMaxLUN >= MASS_MAX_SUPPORTED_LUN) bMaxLUN = MASS_MAX_SUPPORTED_LUN - 1; ErrorMessage<uint8_t > (PSTR("MaxLUN"), bMaxLUN); delay(1000); // Delay a bit for slow firmware. for(uint8_t lun = 0; lun <= bMaxLUN; lun++) { InquiryResponse response; rcode = Inquiry(lun, sizeof (InquiryResponse), (uint8_t*) & response); if(rcode) { ErrorMessage<uint8_t > (PSTR("Inquiry"), rcode); } else { #if 0 printf("LUN %i `", lun); uint8_t *buf = response.VendorID; for(int i = 0; i < 28; i++) printf("%c", buf[i]); printf("'\r\nQualifier %1.1X ", response.PeripheralQualifier); printf("Device type %2.2X ", response.DeviceType); printf("RMB %1.1X ", response.Removable); printf("SSCS %1.1X ", response.SCCS); uint8_t sv = response.Version; printf("SCSI version %2.2X\r\nDevice conforms to ", sv); switch(sv) { case 0: printf("No specific"); break; case 1: printf("ANSI X3.131-1986 (ANSI 1)"); break; case 2: printf("ANSI X3.131-1994 (ANSI 2)"); break; case 3: printf("ANSI INCITS 301-1997 (SPC)"); break; case 4: printf("ANSI INCITS 351-2001 (SPC-2)"); break; case 5: printf("ANSI INCITS 408-2005 (SPC-4)"); break; case 6: printf("T10/1731-D (SPC-4)"); break; default: printf("unknown"); } printf(" standards.\r\n"); #endif uint8_t tries = 0xf0; while((rcode = TestUnitReady(lun))) { if(rcode == 0x08) break; // break on no media, this is OK to do. // try to lock media and spin up if(tries < 14) { LockMedia(lun, 1); MediaCTL(lun, 1); // I actually have a USB stick that needs this! } else delay(2 * (tries + 1)); tries++; if(!tries) break; } if(!rcode) { delay(1000); LUNOk[lun] = CheckLUN(lun); if(!LUNOk[lun]) LUNOk[lun] = CheckLUN(lun); } } } CheckMedia(); rcode = OnInit(); if(rcode) goto FailOnInit; #ifdef DEBUG_USB_HOST USBTRACE("MS configured\r\n\r\n"); #endif bPollEnable = true; //USBTRACE("Poll enabled\r\n"); return 0; FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: #ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); goto Fail; #endif FailGetMaxLUN: #ifdef DEBUG_USB_HOST USBTRACE("GetMaxLUN:"); goto Fail; #endif //#ifdef DEBUG_USB_HOST //FailInvalidSectorSize: // USBTRACE("Sector Size is NOT VALID: "); // goto Fail; //#endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); #endif #ifdef DEBUG_USB_HOST Fail: NotifyFail(rcode); #endif Release(); return rcode; }
int ConvertToKaraoke( CONVDATA *cn) { int pid,status,id,Qty; char Folder[500]; Dlink *L; CONVDATA Cn; MEDIAINFO *mpt; Cn= *cn; #if 1 if ((pid=fork())==0) { char command[10000],File[500],options[5000],Fifo[500],Qstr[100]; double Asec,Msec; if(pipe(Jpipe) < 0) exit(0); if(pipe(Jstat) < 0) exit(0); sprintf(GrabFileName,"Making karaoke to : %-s\n",Cn.outfile); CheckMedia(Cn.audiofile); Esec = Minfo.TotSec; MonPipe = Jpipe[0]; if( fork()==0) { close(Jpipe[1]); close(Jstat[0]); RunMonitorJoin(NULL); exit(0); } close(Jpipe[0]); close(Jstat[1]); switch(Cn.Quality) { case 1: strcpy(Qstr," -aq 0"); break; case 2: strcpy(Qstr," -aq 2"); break; default: case 3: strcpy(Qstr," -aq 4"); break; } sprintf(options,"!c01" "Converting to karaoke may take time!! Pl. be patient...\n"); write(Jpipe[1],options,strlen(options)); sprintf(options,"Esec: %lf\n",Esec); write(Jpipe[1],options,strlen(options)); if(kgSearchString (Cn.outfile,(char *)".mp3")>=0 ) { sprintf(command,"kgffmpeg -vn -i \"%-s\" " "-af \"pan=stereo|c0=c0+-1*c1|c1=c1+-1*c0\" -y -c:a libmp3lame -ac 2 " " %-s -t %lf \"%-s\" ", Cn.audiofile ,Qstr,Esec,Cn.outfile); } else { if(kgSearchString (Cn.outfile,(char *)".aac")>=0 ) { sprintf(command,"kgffmpeg -vn -i \"%-s\" " " -af \"pan=stereo|c0=c0+-1*c1|c1=c0+-1*c1\"-y -ac 2 -c:a libfdk_aac " " -t %lf \"%-s\" ", Cn.audiofile ,Esec,Cn.outfile); } else { sprintf(command,"kgffmpeg -vn -i \"%-s\" " "-af \"pan=stereo|c0=c0+-1*c1|c1=c0+-1*c1\" -y -ac 2 " " %-s -t %lf \"%-s\" ", Cn.audiofile ,Qstr,Esec,Cn.outfile); } } // printf("%s\n",command); runfunction(command,ProcessToPipe,kgffmpeg); close(Jpipe[1]); exit(0); } else { waitpid(pid,&status,0); } #endif }
int ConvertToMp3_o( CONVDATA *cn) { int pid,status; CONVDATA Cn; Cn= *cn; Ssec= cn->StartSec; Esec= cn->EndSec; if(!CheckMedia(cn->infile)){ return 0; } if(Esec < 0) { cn->EndSec = Minfo.TotSec +Esec; Esec= cn->EndSec; } if(Esec > Minfo.TotSec) { cn->EndSec = Minfo.TotSec ; Esec= cn->EndSec; } strcpy(GrabFileName,cn->outfile); if ((pid=fork())==0) { char command[500],Fifo[100],options[100]; sprintf(Fifo,"/tmp/Fifo%-d",getpid()); mkfifo(Fifo,0600); if ((pid=fork())==0) { options[0] ='\0'; if(fabs(cn->Enhfac-1.0)> 0.1) { switch(cn->VolEnh) { case 1: sprintf(options," --scale-l %lf ",cn->Enhfac); break; case 2: sprintf(options," --scale-r %lf ",cn->Enhfac); break; case 3: sprintf(options," --scale %lf ",cn->Enhfac); break; } } switch(cn->Quality) { case 1: strcat(options," -V0 -q 0 "); break; case 2: strcat(options," -V2 -q 2 "); break; case 3: strcat(options," -V4 -q 4 "); break; } sprintf(command,"kglame --quiet %-s %-s \"%-s\"",options,Fifo,Cn.outfile); // printf("%s\n",command); runfunction(command,NULL,kgLame); // fprintf(stderr,"Lame over\n"); exit(0); } else { options[0] ='\0'; if(cn->FullRange != 1) { int sh,sm,ss,smil,secs,eh,em,es,emil; float frac; secs = cn->StartSec; smil = (cn->StartSec - secs)*1000; ss = secs%60; secs = secs/60; sm = secs%60; sh = secs/60; if(cn->EndSec <=cn->StartSec ) cn->EndSec=0; secs = cn->EndSec-cn->StartSec; emil = (cn->EndSec-cn->StartSec -secs)*1000; es = secs%60; secs = secs/60; em = secs%60; eh = secs/60; if(cn->EndSec > 0) { sprintf(options," -ss %-d:%-d:%-d.%-d -endpos %-d:%-d:%-d.%-d", sh,sm,ss,smil,eh,em,es,emil); } else { sprintf(options," -ss %-d:%-d:%-d.%-d ", sh,sm,ss,smil); } } sprintf(command,"Mplayer -vo null -ao pcm:file=%-s %s \"%-s\"", Fifo,options,Cn.infile); // printf("%s\n",command); runfunction(command,ProcessMp3Conversion,Mplayer); // close(open(Fifo,O_RDONLY)); // fprintf(stderr,"Removing Fifo\n"); remove(Fifo); waitpid(pid,&status,0); } exit(0); } else { waitpid(pid,&status,0); } }
int ConvertToMp3( CONVDATA *cn) { int pid,status; CONVDATA Cn; Cn= *cn; Ssec= cn->StartSec; Esec= cn->EndSec; if(!CheckMedia(cn->infile)){ return 0; } if(Esec < 0) { cn->EndSec = Minfo.TotSec +Esec; Esec= cn->EndSec; } if(Esec > Minfo.TotSec) { cn->EndSec = Minfo.TotSec ; Esec= cn->EndSec; } strcpy(GrabFileName,cn->outfile); if ((pid=fork())==0) { char command[500],Str1[100],Str2[100],options[100],Qstr[100]; options[0] ='\0'; Qstr[0]='\0'; sprintf(Str1,"Quality as original\n"); if((kgSearchString(Cn.outfile,(char *)".mp3")>= 0)|| (kgSearchString(Cn.outfile,(char *)".MP3")>= 0)) { switch(cn->Quality) { case 1: strcat(Qstr," -aq 0 "); sprintf(Str1,"Quality Very Good\n"); break; case 2: strcat(Qstr," -aq 2 "); sprintf(Str1,"Quality Good\n"); break; case 3: strcat(Qstr," -aq 4 "); sprintf(Str1,"Quality Normal\n"); break; } } if((kgSearchString(Cn.outfile,(char *)".aac")>= 0)) { sprintf(Qstr," -c:a libfdk_aac "); } sprintf(Str2,"Volume as original\n"); if(fabs(cn->Enhfac-1.0)> 0.1) { switch(cn->VolEnh) { case 1: sprintf(Str2," -af \"pan=stereo|c0=%-lf*c0|c1=c1\" %s" ,cn->Enhfac,Qstr); strcpy(Qstr,Str2); sprintf(Str2,"Volume left:%6.2lf right: normal\n",cn->Enhfac); break; case 2: sprintf(Str2," -af \"pan=stereo|c0=c0|c1=%-lf*c1\" %s" ,cn->Enhfac,Qstr); strcpy(Qstr,Str2); sprintf(Str2,"Volume left: normal right: %6.2lf\n",cn->Enhfac); break; case 3: sprintf(Str2," -af \"pan=stereo|c0=%-lf*c0|c1=%-lf*c1\" %s" ,cn->Enhfac,cn->Enhfac,Qstr); strcpy(Qstr,Str2); sprintf(Str2,"Volume left: %6.2lf right: %6.2lf\n", cn->Enhfac,cn->Enhfac); break; } } if(cn->FullRange != 1) { int sh,sm,ss,smil,secs,eh,em,es,emil; float frac; secs = cn->StartSec; smil = (cn->StartSec - secs)*1000; ss = secs%60; secs = secs/60; sm = secs%60; sh = secs/60; if(cn->EndSec <=cn->StartSec ) cn->EndSec=0; secs = cn->EndSec-cn->StartSec; emil = (cn->EndSec-cn->StartSec -secs)*1000; es = secs%60; secs = secs/60; em = secs%60; eh = secs/60; } if(pipe(Jpipe) < 0) exit(0); if(pipe(Jstat) < 0) exit(0); MonPipe = Jpipe[0]; if( fork()==0) { close(Jpipe[1]); close(Jstat[0]); RunMonitorJoin(NULL); exit(0); } close(Jpipe[0]); close(Jstat[1]); if(cn->EndSec > 0) { sprintf(options,"Esec: %f\n",(float)(Esec-Cn.StartSec)); write(Jpipe[1],options,strlen(options)); sprintf(options,"Converted Media Length: %f\n", (float)(Esec-Cn.StartSec)); write(Jpipe[1],options,strlen(options)); sprintf(command,"kgffmpeg -i \"%-s\" -vn -t %-8.2lf -ss %-8.2lf -ac 2 %s -y \"%-s\"", Cn.infile,Esec-Cn.StartSec,Cn.StartSec,Qstr,Cn.outfile); } else { sprintf(options,"Esec: %f\n",(float)(Minfo.TotSec-Cn.StartSec)); sprintf(options,"Converted Media Length: %f\n", (float)(Minfo.TotSec-Cn.StartSec)); write(Jpipe[1],options,strlen(options)); sprintf(command,"kgffmpeg -i \"%-s\" -vn -ss %-8.2lf -ac 2 %s -y \"%-s\"", Cn.infile,Cn.StartSec,Qstr,Cn.outfile); } // printf("%s\n",command); write(Jpipe[1],Str1,strlen(Str1)); write(Jpipe[1],Str2,strlen(Str2)); sprintf(Str1,"!c01Output format is selected as per file extension\n"); write(Jpipe[1],Str1,strlen(Str1)); sprintf(Str1,"!c01If CUT and JOIN is planned !z54!c04.wav/.flac!c01!z45 is better\n"); write(Jpipe[1],Str1,strlen(Str1)); runfunction(command, ProcessToPipe ,kgffmpeg); // close(open(Fifo,O_RDONLY)); // fprintf(stderr,"Removing Fifo\n"); exit(0); } else { waitpid(pid,&status,0); } }
/** * * @param parent (not used) * @param port (not used) * @param lowspeed true if device is low speed * @return 0 for success */ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) { uint8_t rcode; uint8_t num_of_conf = epInfo[1].epAddr; // number of configurations epInfo[1].epAddr = 0; USBTRACE("MS Init\r\n"); AddressPool &addrPool = pUsb->GetAddressPool(); UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; // Assign new address to the device delay(2000); rcode = pUsb->setAddr(0, 0, bAddress); if (rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:", rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for (uint8_t i = 0; i < num_of_conf; i++) { ConfigDescParser< USB_CLASS_MASS_STORAGE, MASS_SUBCLASS_SCSI, MASS_PROTO_BBB, CP_MASK_COMPARE_CLASS | CP_MASK_COMPARE_SUBCLASS | CP_MASK_COMPARE_PROTOCOL > BulkOnlyParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &BulkOnlyParser); if (rcode) goto FailGetConfDescr; if (bNumEP > 1) break; } // for if (bNumEP < 3) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Conf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if (rcode) goto FailSetConfDescr; //Linux does a 1sec delay after this. delay(1000); rcode = GetMaxLUN(&bMaxLUN); if (rcode) goto FailGetMaxLUN; if (bMaxLUN >= MASS_MAX_SUPPORTED_LUN) bMaxLUN = MASS_MAX_SUPPORTED_LUN - 1; ErrorMessage<uint8_t > (PSTR("MaxLUN"), bMaxLUN); delay(1000); // Delay a bit for slow firmware. //bTheLUN = bMaxLUN; for (uint8_t lun = 0; lun <= bMaxLUN; lun++) { InquiryResponse response; rcode = Inquiry(lun, sizeof (InquiryResponse), (uint8_t*) & response); if (rcode) { ErrorMessage<uint8_t > (PSTR("Inquiry"), rcode); } else { uint8_t tries = 0xf0; while (rcode = TestUnitReady(lun)) { if (rcode == 0x08) break; // break on no media, this is OK to do. // try to lock media and spin up if (tries < 14) { LockMedia(lun, 1); MediaCTL(lun, 1); // I actually have a USB stick that needs this! } else delay(2 * (tries + 1)); tries++; if (!tries) break; } if (!rcode) { delay(1000); LUNOk[lun] = CheckLUN(lun); if (!LUNOk[lun]) LUNOk[lun] = CheckLUN(lun); } } } #if 0 { bool good; for (uint8_t i = 1; i == 0; i++) { good = false; CheckMedia(); for (uint8_t lun = 0; lun <= bMaxLUN; lun++) good |= LUNOk[lun]; if (good) break; delay(118); // 255 loops =~ 30 seconds to allow for spin up, as per SCSI spec. } } #else CheckMedia(); #endif rcode = OnInit(); if (rcode) goto FailOnInit; USBTRACE("MS configured\r\n\r\n"); bPollEnable = true; //USBTRACE("Poll enabled\r\n"); return 0; FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: #ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); goto Fail; #endif FailGetMaxLUN: #ifdef DEBUG_USB_HOST USBTRACE("GetMaxLUN:"); goto Fail; #endif FailInvalidSectorSize: #ifdef DEBUG_USB_HOST USBTRACE("Sector Size is NOT VALID: "); goto Fail; #endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); #endif Fail: #ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); return rcode; }