// Returns the size of filename (64bit) u64 GetSize(const std::string &filename) { if (!Exists(filename)) { WARN_LOG(COMMON, "GetSize: failed %s: No such file", filename.c_str()); return 0; } if (IsDirectory(filename)) { WARN_LOG(COMMON, "GetSize: failed %s: is a directory", filename.c_str()); return 0; } struct stat64 buf; #ifdef _WIN32 if (_tstat64(UTF8ToTStr(filename).c_str(), &buf) == 0) #else if (stat64(filename.c_str(), &buf) == 0) #endif { DEBUG_LOG(COMMON, "GetSize: %s: %lld", filename.c_str(), (long long)buf.st_size); return buf.st_size; } ERROR_LOG(COMMON, "GetSize: Stat failed %s: %s", filename.c_str(), GetLastErrorMsg()); return 0; }
// Returns the size of filename (64bit) u64 GetSize(const std::string &filename) { if (!Exists(filename)) { LOG_ERROR(Common_Filesystem, "failed %s: No such file", filename.c_str()); return 0; } if (IsDirectory(filename)) { LOG_ERROR(Common_Filesystem, "failed %s: is a directory", filename.c_str()); return 0; } struct stat64 buf; #ifdef _WIN32 if (_tstat64(Common::UTF8ToTStr(filename).c_str(), &buf) == 0) #else if (stat64(filename.c_str(), &buf) == 0) #endif { LOG_TRACE(Common_Filesystem, "%s: %lld", filename.c_str(), (long long)buf.st_size); return buf.st_size; } LOG_ERROR(Common_Filesystem, "Stat failed %s: %s", filename.c_str(), GetLastErrorMsg()); return 0; }
int CGitStatus::GetStatus(const CString &gitdir, const CString &path, git_wc_status_kind *status, BOOL IsFull, BOOL IsRecursive , FIll_STATUS_CALLBACK callback , void *pData) { int result; __int64 time; bool dir; git_wc_status_kind dirstatus = git_wc_status_none; if (status) { g_Git.GetFileModifyTime(path, &time, &dir); if(path.IsEmpty()) result = _tstat64( gitdir, &buf ); else result = _tstat64( gitdir+_T("\\")+path, &buf ); if(result) return -1; if(buf.st_mode & _S_IFDIR) { if(!path.IsEmpty()) { if( path.Right(1) != _T("\\")) path += _T("\\"); } int len = path.GetLength(); for (int i = 0; i < size(); i++) { if (at(i).m_FileName.GetLength() > len) { if (at(i).m_FileName.Left(len) == path) { if(!IsFull) { *status = git_wc_status_normal; if(callback) callback(gitdir + _T("\\") + path, *status, pData); return 0; } else { result = _tstat64(gitdir + _T("\\") + at(i).m_FileName, &buf); if (result) continue; *status = git_wc_status_none; GetFileStatus(gitdir, at(i).m_FileName, status, buf, callback, pData); if (*status != git_wc_status_none) { if (dirstatus == git_wc_status_none) { dirstatus = git_wc_status_normal; } if (*status != git_wc_status_normal) { dirstatus = git_wc_status_modified; } } } } } } if (dirstatus != git_wc_status_none) { *status = dirstatus; } else { *status = git_wc_status_unversioned; } if(callback) callback(gitdir + _T("\\") + path, *status, pData); return 0; } else { GetFileStatus(gitdir, path, status, buf, callback, pData); } } return 0; }
//================================================================================================ // // PerformPrevRelUpdates() // // - Called by Main_OnInitDialog() // /// <summary> /// Checks the version of the last time we ran, and if that number falls within certain ranges /// we'll do some release-specific cleanup. /// </summary> // void PerformPrevRelUpdates(HWND _hwnd) { int prevRelease = g_config.LastVersionRun; if (prevRelease == PB_VER_BUILDNUM) { TRACEW("[mainproc] [PerformPrevRelUpdates] no version change, so no updates to perform"); return; } if (prevRelease > PB_VER_BUILDNUM) { TRACEW("[mainproc] [PerformPrevRelUpdates] WARNING: Downgrade detected!"); return; } //-------------------------------------------------- // Update PG hosted lists to iblocklist if (prevRelease < 134) { TRACEW("[mainproc] [PerformPrevRelUpdates] Checking for old peerguardian-hosted lists, and updating any found to iblocklist.com-hosted ones"); vector<DynamicList> tempList; // check each list in configured lists for(vector<DynamicList>::size_type i = 0; i < g_config.DynamicLists.size(); ++i) { // if it's a peerguardian list DynamicList *list = &(g_config.DynamicLists[i]); if (list->Url.find(_T("http://peerguardian.sourceforge.net/lists/")) != string::npos) { // swap it out tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates] found old URL: [%1%]")) % list->Url ); TRACEBUFW(strBuf); if (list->Url.find(_T("ads.php")) != string::npos) { // http://list.iblocklist.com/?list=bt_ads TRACEW("[mainproc] [PerformPrevRelUpdates] - replacing ads.php list with bt_ads"); //list->Url = _T("http://list.iblocklist.com/?list=bt_ads"); DynamicList newList = *list; newList.Url = _T("http://list.iblocklist.com/lists/bluetack/ads-trackers-and-bad-pr0n"); tempList.push_back(newList); } else if (list->Url.find(_T("edu.php")) != string::npos) { // http://list.iblocklist.com/?list=bt_edu TRACEW("[mainproc] [PerformPrevRelUpdates] - replacing edu.php list with bt_edu"); //list->Url = _T("http://list.iblocklist.com/?list=bt_edu"); DynamicList newList = *list; newList.Url = _T("http://list.iblocklist.com/lists/bluetack/edu"); tempList.push_back(newList); } else if (list->Url.find(_T("p2p.php")) != string::npos) { // http://list.iblocklist.com/?list=bt_level1 TRACEW("[mainproc] [PerformPrevRelUpdates] - replacing p2p.php list with bt_level1"); //list->Url = _T("http://list.iblocklist.com/?list=bt_level1"); DynamicList newList = *list; newList.Url = _T("http://list.iblocklist.com/lists/bluetack/level-1"); tempList.push_back(newList); } else if (list->Url.find(_T("spy.php")) != string::npos) { // http://list.iblocklist.com/?list=bt_spyware TRACEW("[mainproc] [PerformPrevRelUpdates] - replacing spy.php list with bt_spyware"); //list->Url = _T("http://list.iblocklist.com/?list=bt_spyware"); DynamicList newList = *list; newList.Url = _T("http://list.iblocklist.com/lists/bluetack/spyware"); tempList.push_back(newList); } else if (list->Url.find(_T("gov.php")) != string::npos) { // remove list TRACEW("[mainproc] [PerformPrevRelUpdates] - removing gov list"); } else { TRACEE("[mainproc] [PerformPrevRelUpdates] ERROR: Unknown PG2 list!!"); } } else { TRACED("[mainproc] [PerformPrevRelUpdates] found non-PG2 URL"); DynamicList newList = *list; tempList.push_back(newList); } } // Rebuild list if we need to remove Gov list. Also, check for duplicates. g_config.DynamicLists.clear(); for(vector<DynamicList>::size_type i = 0; i < tempList.size(); ++i) { if (std::find(g_config.DynamicLists.begin(), g_config.DynamicLists.end(), tempList[i]) == g_config.DynamicLists.end()) { g_config.DynamicLists.push_back(tempList[i]); } } } //-------------------------------------------------- // Update old list-names to new ones // Now that iblocklist.com has support for some "friendly" URLs for lists, we can migrate people // away from the slow, unreliable bluetack.co.uk servers and over to iblocklist. We're checking // against any of the bluetack URLs from our old dropdown list, and changing 'em over. Same // thing for any of the old naming-scheme iblocklist URLs. We're also removing the bluetack // "trojan" list, since it resolves to an unusable file and there is no iblocklist equivalent. if (prevRelease < 268) { TRACEW("[mainproc] [PerformPrevRelUpdates] Checking for old-URL lists, and migrating them to the new naming scheme (r268)"); int result = MessageBox(_hwnd, IDS_PREVREL268TEXT, IDS_PREVREL, MB_ICONINFORMATION|MB_YESNO); if (result == IDNO) { TRACEI("[mainproc] [PerformPrevRelUpdates] user clicked No"); } else if (result == IDYES) { TRACEI("[mainproc] [PerformPrevRelUpdates] user clicked Yes"); vector<DynamicList> tempList; ListUrls listUrls; listUrls.Init(); // check each list in configured lists for(vector<DynamicList>::size_type i = 0; i < g_config.DynamicLists.size(); ++i) { DynamicList *list = &(g_config.DynamicLists[i]); LISTNAME listId = listUrls.FindListNum(list->Url); if (listId != LISTNAME_COUNT) { DynamicList newList = *list; newList.Url = listUrls.GetBestUrl(listId); tempList.push_back(newList); if (newList.Url.compare(list->Url) == 0) { tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates] - found no better list url than [%1%]")) % list->Url.c_str() ); TRACEBUFW(strBuf); } else { tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates] - migrated list from [%1%] to [%2%]")) % list->Url.c_str() % newList.Url.c_str() ); TRACEBUFW(strBuf); } } else if (list->Url.compare(_T("http://www.bluetack.co.uk/config/trojan.zip")) == 0) { TRACEW("[mainproc] [PerformPrevRelUpdates] - removing no-longer-existant bt trojan"); } else { tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates] - found unknown list url [%1%], copying over as-is")) % list->Url.c_str() ); TRACEBUFW(strBuf); DynamicList newList = *list; tempList.push_back(newList); } } // Rebuild list, checking for duplicates. g_config.DynamicLists.clear(); for(vector<DynamicList>::size_type i = 0; i < tempList.size(); ++i) { if (std::find(g_config.DynamicLists.begin(), g_config.DynamicLists.end(), tempList[i]) == g_config.DynamicLists.end()) { g_config.DynamicLists.push_back(tempList[i]); } } } } //-------------------------------------------------- // Update max history.db size from old default of 0 (unlimited) to 100 MB if (prevRelease < 341) { TRACEW("[mainproc] [PerformPrevRelUpdates] Checking for old History defaults of 0, and migrating it to the new default of 100 MB (r341)"); if (g_config.CleanupType == None && g_config.MaxHistorySize > 0) { TRACEW("[mainproc] [PerformPrevRelUpdates] CleanupType = None, updating it to Delete every 7 Days"); MessageBox(_hwnd, IDS_PREVREL341TEXT_DEL, IDS_PREVREL, MB_ICONINFORMATION|MB_OK); g_config.CleanupType = Delete; g_config.CleanupInterval = 7; g_config.Save(); } else if (g_config.MaxHistorySize == 0 && g_config.CleanupType != None) { TRACEW("[mainproc] [PerformPrevRelUpdates] Max history.db size 0 ('unlimited'), updating it to 100 MB"); MessageBox(_hwnd, IDS_PREVREL341TEXT_MAX, IDS_PREVREL, MB_ICONINFORMATION|MB_OK); g_config.MaxHistorySize = 100 * 1000000; // g_config.MaxHistory is in bytes... g_config.Save(); } else if (g_config.MaxHistorySize == 0 && g_config.CleanupType == None) { TRACEW("[mainproc] [PerformPrevRelUpdates] Changing history.db max size to 100 MB, and CleaupType to Delete every 7 days"); MessageBox(_hwnd, IDS_PREVREL341TEXT_BOTH, IDS_PREVREL, MB_ICONINFORMATION|MB_OK); g_config.CleanupType = Delete; g_config.CleanupInterval = 7; g_config.MaxHistorySize = 100 * 1000000; // g_config.MaxHistory is in bytes... g_config.Save(); } else { TRACEW("[mainproc] [PerformPrevRelUpdates] Not changing config"); tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates] Max history.db size (%1%) ")) % g_config.MaxHistorySize ); g_tlog.LogMessage(strBuf, TRACELOG_LEVEL_WARNING); } } //-------------------------------------------------- // Update Bluetack Webexploit/Forumspam merged list to new individual lists, and cw_bogon list // to the most frequently updated one, cidr_bogon if (prevRelease < 411) { TRACEW("[mainproc] [PerformPrevRelUpdates] Checking for Bluetack Webexploit/Forumspam, cr_bogon, or default lists (r411)"); vector<DynamicList> tempList; ListUrls listUrls; listUrls.Init(); // check each list in configured lists for(vector<DynamicList>::size_type i = 0; i < g_config.DynamicLists.size(); ++i) { DynamicList *list = &(g_config.DynamicLists[i]); LISTNAME listId = listUrls.FindListNum(list->Url); if (listId == LISTNAME_BT_WEBEX_FSPAM) { TRACEW("[mainproc] [PerformPrevRelUpdates] Updating Bluetack Webexploit/Forumspam merged list to new individual lists"); MessageBox(_hwnd, IDS_PREVREL411TEXT_WEBEX, IDS_PREVREL, MB_ICONINFORMATION|MB_OK); DynamicList * newList = new DynamicList; newList->Url = listUrls.GetBestUrl(LISTNAME_BT_WEBEXPLOIT); newList->Enabled = list->Enabled; newList->Description = listUrls.GetListDesc(LISTNAME_BT_WEBEXPLOIT); tempList.push_back(*newList); DynamicList * newList2 = new DynamicList; newList2->Url = listUrls.GetBestUrl(LISTNAME_BT_FORUMSPAM); newList2->Enabled = list->Enabled; newList2->Description = listUrls.GetListDesc(LISTNAME_BT_FORUMSPAM); tempList.push_back(*newList2); } else if (listId == LISTNAME_CW_BOGON) { TRACEW("[mainproc] [PerformPrevRelUpdates] Updating CW Bogon list to CIDR Bogon"); MessageBox(_hwnd, IDS_PREVREL411TEXT_BOGON, IDS_PREVREL, MB_ICONINFORMATION|MB_OK); DynamicList * newList = new DynamicList; newList->Url = listUrls.GetBestUrl(LISTNAME_CIDR_BOGON); newList->Enabled = list->Enabled; newList->Description = listUrls.GetListDesc(LISTNAME_CIDR_BOGON); tempList.push_back(*newList); } else if ( listId == LISTNAME_BT_LEVEL1 || listId == LISTNAME_BT_ADS || listId == LISTNAME_BT_SPY || listId == LISTNAME_BT_EDU ) { // Make sure Default Lists are set to Block, not Allow. This will also take care // of any misconfigured PG2 lists, and is especially important since the PeerBlock // List Manager has no easy way to set lists to Block instead of Allow, nor will // it show you that it's an Allow list. if (list->Type == List::Allow) { tstring strBuf = boost::str(tformat(_T("[mainproc] [PerformPrevRelUpdates] Updating list:[%1%] from type:[Allow] to type:[Block]")) % list->Description ); TRACEBUFW(strBuf); DynamicList * newList = new DynamicList; newList->Url = list->Url; newList->Enabled = list->Enabled; newList->Description = list->Description; newList->Type = List::Block; tempList.push_back(*newList); } else { tempList.push_back(*list); } } else { // not LISTNAME_BT_WEBEX_FSPAM, LISTNAME_CIDR_BOGON, or a default list tempList.push_back(*list); } } // Rebuild list, checking for duplicates. g_config.DynamicLists.clear(); for(vector<DynamicList>::size_type i = 0; i < tempList.size(); ++i) { if (std::find(g_config.DynamicLists.begin(), g_config.DynamicLists.end(), tempList[i]) == g_config.DynamicLists.end()) { g_config.DynamicLists.push_back(tempList[i]); } } } // end of webex/forumspam update (r411) //-------------------------------------------------- // Delete history.db if it's too large if (prevRelease < 454) { // check for filesize of history.db TRACEI("[mainproc] [PerformPrevRelUpdates] checking size of history.db (r454)"); struct _stat64 fileStat; path history_file = path::base_dir()/_T("history.db"); int ret = _tstat64( history_file.c_str(), &fileStat ); if (ret == 0) { // if it's too-large, delete it outright if (fileStat.st_size > g_config.MaxHistorySize*1.5) // 150 MB, by default { TRACEW("[mainproc] [PerformPrevRelUpdates] Too-large history.db file detected!"); path::remove(history_file); TRACEW("[mainproc] [PerformPrevRelUpdates] Deleted history.db"); } } } // end of delete too-large history.db (r454) //-------------------------------------------------- // Remove I-Blocklist Subscription URL params if present, add them to peerblock.conf instead if (prevRelease < 653) { TRACEW("[mainproc] [PerformPrevRelUpdates] Checking for I-Blocklist Subscription list URL params (r653)"); ListUrls listUrls; listUrls.Init(); tstring username; tstring pin; // check each list in configured lists for(vector<DynamicList>::size_type i = 0; i < g_config.DynamicLists.size(); ++i) { DynamicList *list = &(g_config.DynamicLists[i]); if (string::npos != list->Url.find(_T("http://list.iblocklist.com/?list="))) { // split url up into tokens size_t start = 0; size_t end = 0; map<tstring, tstring> params; start = list->Url.find(_T("?")) + 1; while (string::npos != end && string::npos != start) { end = list->Url.find(_T("&"), start); tstring paramSet = list->Url.substr(start, (end == string::npos) ? string::npos : end - start); start = (end > (string::npos - 1) ) ? string::npos : end + 1; size_t eqPos = 0; eqPos = paramSet.find(_T("=")); if (string::npos != eqPos) { tstring key = paramSet.substr(0, eqPos); tstring val = paramSet.substr(eqPos + 1); params[key] = val; } } if (params.find(_T("username")) != params.end()) { username = params.at(_T("username")); } if (params.find(_T("id")) != params.end()) { username = params.at(_T("id")); } if (params.find(_T("pin")) != params.end()) { pin = params.at(_T("pin")); } // sanity-check, make sure we didn't screw up and lost the list-param if (params.find(_T("list")) != params.end()) { list->Url = tstring(_T("http://list.iblocklist.com/?list=")) + params.at(_T("list")); } } else if (string::npos != list->Url.find(_T("http://list.iblocklist.com/lists/"))) { // split url up into tokens size_t urlRootEndPos = 0; size_t start = 0; size_t end = 0; map<tstring, tstring> params; urlRootEndPos = list->Url.find(_T("?")); if (string::npos != urlRootEndPos) { // we've got some params here start = urlRootEndPos + 1; while (string::npos != end && string::npos != start) { end = list->Url.find(_T("&"), start); tstring paramSet = list->Url.substr(start, (end == string::npos) ? string::npos : end - start); start = (end > (string::npos - 1) ) ? string::npos : end + 1; size_t eqPos = 0; eqPos = paramSet.find(_T("=")); if (string::npos != eqPos) { tstring key = paramSet.substr(0, eqPos); tstring val = paramSet.substr(eqPos + 1); params[key] = val; } } if (params.find(_T("username")) != params.end()) { username = params.at(_T("username")); } if (params.find(_T("id")) != params.end()) { username = params.at(_T("id")); } if (params.find(_T("pin")) != params.end()) { pin = params.at(_T("pin")); } // strip away all params from this URL, since none are applicable any longer list->Url = list->Url.substr(0, urlRootEndPos); } } } // if we have a username (id) and pin, save them to config, and remove them from here if (!username.empty() && !pin.empty()) { g_config.IblUsername = username; g_config.IblPin = pin; g_config.Save(); } } // end of i-blocklist subscription list-url param cleanup (r653) //-------------------------------------------------- // Inform user about I-Blocklist's list-update limit if (prevRelease < 681) { TRACEI("[mainproc] [PerformPrevRelUpdates] displaying info about I-Blocklist list-update limits (r681)"); MessageBox(_hwnd, IDS_PREVREL681TEXT, IDS_PREVREL, MB_ICONINFORMATION|MB_OK); } // end of i-blocklist list-update limit info (r681) }; // End of PerformPrevRelUpdates()
int _tmain(int argc, _TCHAR* argv[]) { int nChannelCount; int nSampleRate; int nBitrate=128000; int nBitsPerSample=16; int nChannelMode=2; //0-Multichannel, 1-Mono, 2-Stereo, 3-IS, 4-PS, 5-DC int bMPEG4AAC=9; // Let the encoder choice: with enc_aacplus.dll 1.24 was 4 but with 1.26 was MPEG2 int mp4mode = 0; int bNoPS = 0; int bRawPCM = 0; int bSpeech = 0; int bPNS = 0; int nType=1; //0- he, 1 - lc, 2 - he-high, 3-PS DWORD dwBytesRead; _TCHAR szTempDir[MAX_PATH]; char szTempName[MAX_PATH]; char lpPathBuffer[BUFSIZE]; _TCHAR * strOutputFileName = NULL; _TCHAR * strInputFileName = NULL; FILE* hInput=NULL; FILE* hOutput=NULL; wavHeader wav; _tsetlocale(LC_ALL, _T("")); if(argc<2) { showUsage(argv[0]); return ERROR_INSUFFICIENT_ARGS; } strInputFileName = argv[1]; strOutputFileName = argv[2]; // let's parse command line for(int i=3;i<argc;++i) { if(0==_tcscmp(_T("--rawpcm"), argv[i])) { nSampleRate=_tstoi(argv[++i]); nChannelCount=_tstoi(argv[++i]); nBitsPerSample=_tstoi(argv[++i]); bRawPCM=1; continue; } if(0==_tcscmp(_T("--mono"), argv[i])) { nChannelMode=1; continue; } if(0==_tcscmp(_T("--ps"), argv[i])) { bNoPS=1; nType=0; //nChannelMode=4; assigned only if bitrate <=56000 continue; } if(0==_tcscmp(_T("--is"), argv[i])) { nChannelMode=3; continue; } if(0==_tcscmp(_T("--dc"), argv[i])) { nChannelMode=5; continue; } if(0==_tcscmp(_T("--he"), argv[i])) { nType=0; continue; } if(0==_tcscmp(_T("--lc"), argv[i])) { nType=1; continue; } if(0==_tcscmp(_T("--high"), argv[i])) { nType=2; continue; } if(0==_tcscmp(_T("--br"), argv[i])) { nBitrate=_tstoi(argv[++i]); continue; } if(0==_tcscmp(_T("--mpeg2aac"), argv[i])) { bMPEG4AAC=0; continue; } if(0==_tcscmp(_T("--mpeg4aac"), argv[i])) { bMPEG4AAC=1; continue; } if(0==_tcscmp(_T("--speech"), argv[i])) { bSpeech=1; continue; } if(0==_tcscmp(_T("--pns"), argv[i])) { bPNS=1; continue; } } showLogo(); int bStdIn = 0==_tcscmp(_T("-"), strInputFileName)?1:0; // let's open WAV file if(bStdIn) { #ifdef WIN32 setmode(fileno(stdin), O_BINARY); #endif hInput = stdin; } else { hInput = _tfopen(strInputFileName,_T("rb")); } if(!hInput) { printf("Can't open input file!\n"); return ERROR_CANNOT_OPEN_INFILE; }; if(0==bRawPCM) { // let's read WAV HEADER memset(&wav, 0, sizeof(wav)); if(fread(&wav, 1, sizeof(wav), hInput)!=sizeof(wav)) { // Can't read wav header fclose(hInput); printf("Input file must be WAV PCM!\n"); return ERROR_CANNOT_LOAD_DECODER; } if( wav.chunkid!=0x46464952 || wav.rifftype!=0x45564157 || wav.fmt!=0x20746D66 || wav.fmtsize!=0x00000010 || wav.bps!=16 || (wav.srate!=32000 && wav.srate!=44100 && wav.srate!=48000 ) || wav.ccode!=0x0001) { // unsupported or invalid wav format fclose(hInput); printf("Invalid or unsuppored WAV file format (must be 16 bit PCM)\n"); return ERROR_INCOMPATABLE_DECODER; } nBitsPerSample = wav.bps; nChannelCount = wav.nch; nSampleRate = wav.srate; } int bitrates[3][6] = { { //he - mono, stereo, 6ch 8000, 64000, 16000, 128000, 96000, 213335 }, { //lc - mono, stereo, 6ch 8000, 160000, 16000, 320000, 160000, 320000 }, { //hi - mono, stereo, 6ch 64000, 160000, 96000, 256000, 8000, 256000 } }; int maxBitrate=0; int minBitrate=0; switch(nChannelCount) { case 1: minBitrate = bitrates[nType][0]; maxBitrate = bitrates[nType][1]; break; case 2: minBitrate = bitrates[nType][2]; maxBitrate = bitrates[nType][3]; break; default: minBitrate = bitrates[nType][4]; maxBitrate = bitrates[nType][5]; break; } const _TCHAR* channelModes[] = {_T("Multichannel"), _T("Mono"), _T("Stereo"), _T("Independant Stereo"), _T("Parametric Stereo"), _T("Dual Channels")}; const _TCHAR* codecName[] = {_T("HE-AAC"),_T("LC-AAC"),_T("HE-AAC High"),_T("HE-AAC+PS")}; const _TCHAR* BooleanResult[] = {_T("No"), _T("Yes")}; nBitrate = min(max(minBitrate, nBitrate), maxBitrate); nChannelMode = 1==nChannelCount ? 1:((2==nChannelCount) ? ( (nBitrate<=56000 && 0==nType && 1==bNoPS) ? 4:nChannelMode):0); if (4==nChannelMode)// only for printf nType=3; // just to be sure that we have the correct mode _TCHAR *ext = PathFindExtension(strOutputFileName); if(ext) { if(!_tcsicmp(ext,_T(".m4a")) || !_tcsicmp(ext,_T(".mp4"))) mp4mode = 1; } // let's write used config: _tprintf(_T("\nInput file: %s\nOutput file: %s\nSampleRate: %d\nChannelCount: %d\nBitsPerSample: %d\nBitrate: %d\nChannelMode: %s\nEngine: %s\nTune For Speech: %s\nPNS: %s\nMP4 Output: %s\n"), strInputFileName, strOutputFileName, nSampleRate, nChannelCount,nBitsPerSample , nBitrate, channelModes[nChannelMode], codecName[nType], BooleanResult[bSpeech?1:0], BooleanResult[bPNS?1:0], BooleanResult[mp4mode?1:0]); fflush(stdout); if (4==nChannelMode) //back nType=0; //create temp file name #ifdef UNICODE _TCHAR tempFileW[MAX_PATH]; #endif GetTempPath( MAX_PATH, // length of the buffer szTempDir); // buffer for path #ifdef UNICODE GetTempFileName(szTempDir, // directory for temp files NULL, // temp file name prefix 0, // create unique name tempFileW); // buffer for name wcstombs_s(NULL,szTempName,MAX_PATH,tempFileW,(MAX_PATH)*sizeof(_TCHAR)); #else GetTempFileName(szTempDir, // directory for temp files NULL, // temp file name prefix 0, // create unique name szTempName); // buffer for name #endif AudioCoder * encoder=NULL; AudioCoder *(*finishAudio3)(_TCHAR *fn, AudioCoder *c)=NULL; void (*prepareToFinish)(_TCHAR *filename, AudioCoder *coder)=NULL; AudioCoder* (*createAudio3)(int nch, int srate, int bps, unsigned int srct, unsigned int *outt, char *configfile)=NULL; HMODULE encplug = LoadLibrary(_T("enc_aacplus.dll")); if(NULL == encplug) { fclose(hInput); printf("Can't find enc_aacplus.dll!\n"); return ERROR_CANNOT_LOAD_ENCODER; } *(void **)&createAudio3 = (void *)GetProcAddress(encplug, "CreateAudio3"); if( NULL == createAudio3) { FreeLibrary(encplug); fclose(hInput); printf("Can't find CreateAudio3 in enc_aacplus.dll!\n"); return ERROR_CANNOT_LOAD_DECODER; } #ifdef UNICODE *(void **)&finishAudio3=(void *)GetProcAddress(encplug,"FinishAudio3W"); *(void **)&prepareToFinish=(void *)GetProcAddress(encplug,"PrepareToFinishW"); #else *(void **)&finishAudio3=(void *)GetProcAddress(encplug,"FinishAudio3"); *(void **)&prepareToFinish=(void *)GetProcAddress(encplug,"PrepareToFinish"); #endif { //const char* codecSection[] = {"audio_aacplus","audio_aac","audio_aacplushigh"}; FILE * tmp = fopen(szTempName,"wt"); fprintf(tmp, "[audio%s_aac%s]\nsamplerate=%u\nchannelmode=%u\nbitrate=%u\nv2enable=1\nbitstream=%i\nsignallingmode=0\nspeech=%i\npns=%i\n", mp4mode?"_mp4":"",1==nType?"":2==nType?"plushigh":"plus", nSampleRate, nChannelMode, nBitrate, bMPEG4AAC?5:0, bSpeech?1:0, bPNS?1:0); fclose(tmp); unsigned int outt = 0; if (1==nType) outt = mp4mode ? mmioFOURCC('M','4','A',' ') : mmioFOURCC('A','A','C','r'); else if (2==nType) outt = mp4mode ? mmioFOURCC('M','4','A','H') : mmioFOURCC('A','A','C','H'); else outt = mp4mode ? mmioFOURCC('M','4','A','+') : mmioFOURCC('A','A','C','P'); encoder=createAudio3(nChannelCount,nSampleRate, nBitsPerSample ,mmioFOURCC('P','C','M',' '),&outt,szTempName); DeleteFileA(szTempName); } if(NULL==encoder) { FreeLibrary(encplug); fclose(hInput); printf("Can't create encoder!\n"); return ERROR_CANNOT_OPEN_ENCODER; } hOutput = _tfopen(strOutputFileName, _T("wb")); if (!hOutput) { delete encoder; FreeLibrary(encplug); fclose(hInput); printf("Can't create output file!\n"); return ERROR_CANNOT_OPEN_OUTFILE; } // encode printf("Encoding..."); int toRead = (2*nChannelCount*2*1024); toRead = (sizeof(lpPathBuffer)/toRead)*toRead; while(0!=(dwBytesRead = fread(lpPathBuffer, 1, toRead, hInput))) { _encode(hOutput, encoder, dwBytesRead, lpPathBuffer, bMPEG4AAC); } printf("\rFinalizing..."); // finalize encoding if(prepareToFinish) prepareToFinish(strOutputFileName,encoder); _finalize(hOutput, encoder, lpPathBuffer, bMPEG4AAC); fclose(hOutput); if (finishAudio3) finishAudio3(strOutputFileName,encoder); fclose(hInput); delete encoder; FreeLibrary(encplug); if(mp4mode) { struct __stat64 statbuf; if(!_tstat64(strOutputFileName,&statbuf)) { if(!_tfopen_s(&hOutput,strOutputFileName,_T("r+b"))) { optimizeAtoms(hOutput,statbuf.st_size); } if(hOutput) fclose(hOutput); } } // shut down printf("\rDone \n"); return TRANSCODE_FINISHED_OK; }