예제 #1
0
파일: server.cpp 프로젝트: KGE-INC/modplus
void ActivateFrameServerDialog(HWND hwnd) {
	static wchar_t fileFilters[]=
		L"VirtualDub AVIFile signpost (*.vdr,*.avi)\0"		L"*.vdr;*.avi\0"
		L"All files\0"										L"*.*\0"
		;

	char szServerName[128];

	if (!InitServerDLL()) return;

	if (!DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SERVER_SETUP), hwnd, FrameServerSetupDlgProc, (LPARAM)szServerName))
		return;

	try {
		vdrefptr<Frameserver> fs(new Frameserver(inputVideoAVI, inputAudio, hwnd, &g_dubOpts, g_project->GetTimeline().GetSubset()));

		const VDStringW fname(VDGetSaveFileName(kFileDialog_Signpost, (VDGUIHandle)hwnd, L"Save .VDR signpost for AVIFile handler", fileFilters, g_prefs.main.fAttachExtension ? L"vdr" : NULL, 0, 0));

		if (!fname.empty()) {
			long buf[5];
			char sname[128];
			int slen;

			ivdsl->GetComputerName(sname);
			strcat(sname,"/");
			strcat(sname,szServerName);
			slen = strlen(sname);
			slen += slen&1;

			buf[0] = 'FFIR';
			buf[1] = slen+12;
			buf[2] = 'MRDV';
			buf[3] = 'HTAP';
			buf[4] = slen;

			VDFile file(fname.c_str(), nsVDFile::kWrite | nsVDFile::kDenyRead | nsVDFile::kCreateAlways);

			file.write(buf, 20);
			file.write(sname, strlen(sname));
			if (strlen(sname) & 1)
				file.write("", 1);

			file.close();
		}

		VDDEBUG("Attempting to initialize frameserver...\n");

		fs->Go(ivdsl, szServerName);

		VDDEBUG("Frameserver exit.\n");

	} catch(const MyError& e) {
		e.post(hwnd, "Frameserver error");
	}
}
예제 #2
0
bool VDUIJobControlDialog::OnMenuHit(uint32 id) {
	static const wchar_t fileFilters[]=
		L"VirtualDub job list (*.jobs)\0"			L"*.jobs\0"
		L"VirtualDub script (*.syl, *.vdscript)\0"	L"*.syl;*.vdscript\0"
		L"All files (*.*)\0"						L"*.*\0";

	try {
		switch(id) {

			case ID_FILE_LOADJOBLIST:
				{
					VDStringW filename(VDGetLoadFileName(kFileDialog_JobList, (VDGUIHandle)mhdlg, L"Load job list", fileFilters, NULL));

					if (!filename.empty())
						g_VDJobQueue.ListLoad(filename.c_str(), false);
				}
				break;

			case ID_FILE_SAVEJOBLIST:
				{
					VDStringW filename(VDGetSaveFileName(kFileDialog_JobList, (VDGUIHandle)mhdlg, L"Save job list", fileFilters, NULL));

					if (!filename.empty())
						g_VDJobQueue.Flush(filename.c_str());
				}
				break;

			case ID_FILE_USELOCALJOBQUEUE:
				if (g_VDJobQueue.IsRunInProgress())
					MessageBox(mhdlg, "Cannot switch job queues while a job is in progress.", g_szError, MB_ICONERROR | MB_OK);
				else
					g_VDJobQueue.SetJobFilePath(NULL, false, false);
				break;

			case ID_FILE_USEREMOTEJOBQUEUE:
				if (g_VDJobQueue.IsRunInProgress())
					MessageBox(mhdlg, "Cannot switch job queues while a job is in progress.", g_szError, MB_ICONERROR | MB_OK);
				else {
					const VDFileDialogOption opts[]={
						{ VDFileDialogOption::kConfirmFile, 0, NULL, 0, 0},
						{0}
					};

					int optvals[]={ false };

					VDStringW filename(VDGetSaveFileName(kFileDialog_JobList, (VDGUIHandle)mhdlg, L"Use shared job list", fileFilters, NULL, opts, optvals));

					if (!filename.empty()) {
						if (!_wcsicmp(filename.c_str(), g_VDJobQueue.GetDefaultJobFilePath())) {
							DWORD res = MessageBox(mhdlg,
								"Using the same job file that is normally used for local job queue operation is not recommended as "
								"it can cause job queue corruption.\n"
								"\n"
								"Are you sure you want to use this file for the remote queue too?",
								"VirtualDub Warning",
								MB_ICONEXCLAMATION | MB_YESNO);

							if (res != IDYES)
								break;
						}

						g_VDJobQueue.SetJobFilePath(filename.c_str(), true, true);
					}
				}
				break;

			case ID_EDIT_CLEARLIST:
				if (IDOK != MessageBox(mhdlg, "Really clear job list?", "VirtualDub job system", MB_OKCANCEL | MB_ICONEXCLAMATION))
					break;

				g_VDJobQueue.ListClear(false);
				break;

			case ID_EDIT_DELETEDONEJOBS:
				for(uint32 i=0; i<g_VDJobQueue.ListSize();) {
					VDJob *vdj = g_VDJobQueue.ListGet(i);

					if (vdj->GetState() == VDJob::kStateCompleted) {
						g_VDJobQueue.Delete(vdj, false);
						delete vdj;
					} else
						++i;
				}

				break;

			case ID_EDIT_FAILEDTOWAITING:
				g_VDJobQueue.Transform(VDJob::kStateAborted, VDJob::kStateWaiting);
				g_VDJobQueue.Transform(VDJob::kStateError, VDJob::kStateWaiting);
				break;

			case ID_EDIT_WAITINGTOPOSTPONED:
				g_VDJobQueue.Transform(VDJob::kStateWaiting, VDJob::kStatePostponed);
				break;

			case ID_EDIT_POSTPONEDTOWAITING:
				g_VDJobQueue.Transform(VDJob::kStatePostponed, VDJob::kStateWaiting);
				break;

			case ID_EDIT_DONETOWAITING:
				g_VDJobQueue.Transform(VDJob::kStateCompleted, VDJob::kStateWaiting);
				break;

			case ID_EDIT_PROCESSDIRECTORY:
				JobProcessDirectory(mhdlg);
				break;

			case ID_WHENFINISHED_DONOTHING:
				{
					VDRegistryAppKey appKey("");

					appKey.setBool(g_szRegKeyShutdownWhenFinished, false);
				}
				break;

			case ID_WHENFINISHED_SHUTDOWN:
				{
					VDRegistryAppKey appKey("");

					appKey.setBool(g_szRegKeyShutdownWhenFinished, true);
					appKey.setInt(g_szRegKeyShutdownMode, 0);
				}
				break;

			case ID_WHENFINISHED_HIBERNATE:
				{
					VDRegistryAppKey appKey("");

					appKey.setBool(g_szRegKeyShutdownWhenFinished, true);
					appKey.setInt(g_szRegKeyShutdownMode, 1);
				}
				break;
			case ID_WHENFINISHED_SLEEP:
				{
					VDRegistryAppKey appKey("");

					appKey.setBool(g_szRegKeyShutdownWhenFinished, true);
					appKey.setInt(g_szRegKeyShutdownMode, 2);
				}
				break;
		}
	} catch(const MyError& e) {
		e.post(mhdlg, "Job system error");
	}

	return true;
}
예제 #3
0
void VDCreateTestPal8Video(VDGUIHandle h) {
	CPUEnableExtensions(CPUCheckForExtensions());

	try {
		tVDInputDrivers inputDrivers;
		std::vector<int> xlat;

		VDGetInputDrivers(inputDrivers, IVDInputDriver::kF_Video);

		const VDStringW filter(VDMakeInputDriverFileFilter(inputDrivers, xlat));

		const VDFileDialogOption opt[]={
			{ VDFileDialogOption::kSelectedFilter },
			0
		};

		int optval[1]={0};

		const VDStringW srcfile(VDGetLoadFileName('pl8s', h, L"Choose source file", filter.c_str(), NULL, opt, optval));

		if (srcfile.empty())
			return;

		IVDInputDriver *pDrv;
		int filtidx = xlat[optval[0] - 1];
		if (filtidx < 0)
			pDrv = VDAutoselectInputDriverForFile(srcfile.c_str(), IVDInputDriver::kF_Video);
		else {
			tVDInputDrivers::iterator itDrv(inputDrivers.begin());
			std::advance(itDrv, filtidx);

			pDrv = *itDrv;
		}

		vdrefptr<InputFile> pIF(pDrv->CreateInputFile(0));

		pIF->Init(srcfile.c_str());

		const VDStringW dstfile(VDGetSaveFileName('pl8d', h, L"Choose destination 8-bit file", L"Audio-video interleaved (*.avi)\0*.avi\0All files\0*.*", L"avi", NULL, NULL));
		if (dstfile.empty())
			return;

		vdrefptr<IVDVideoSource> pVS;
		pIF->GetVideoSource(0, ~pVS);
		IVDStreamSource *pVSS = pVS->asStream();
		const VDPosition frames = pVSS->getLength();

		if (!pVS->setTargetFormat(nsVDPixmap::kPixFormat_XRGB8888))
			throw MyError("Cannot set decompression format to 32-bit.");

		vdautoptr<IVDMediaOutputAVIFile> pOut(VDCreateMediaOutputAVIFile());

		IVDMediaOutputStream *pVSOut = pOut->createVideoStream();

		const VDPixmap& pxsrc = pVS->getTargetFormat();
		const uint32 rowbytes = (pxsrc.w+3) & ~3;

		AVIStreamHeader_fixed hdr;

		hdr.fccType		= 'sdiv';
		hdr.fccHandler	= 0;
		hdr.dwFlags		= 0;
		hdr.wPriority	= 0;
		hdr.wLanguage	= 0;
		hdr.dwScale		= pVSS->getStreamInfo().dwScale;
		hdr.dwRate		= pVSS->getStreamInfo().dwRate;
		hdr.dwStart		= 0;
		hdr.dwLength	= 0;
		hdr.dwInitialFrames = 0;
		hdr.dwSuggestedBufferSize = 0;
		hdr.dwQuality = -1;
		hdr.dwSampleSize = 0;
		hdr.rcFrame.left	= 0;
		hdr.rcFrame.top		= 0;
		hdr.rcFrame.right	= (short)pxsrc.w;
		hdr.rcFrame.bottom	= (short)pxsrc.h;

		pVSOut->setStreamInfo(hdr);

		vdstructex<BITMAPINFOHEADER> bih;

		bih.resize(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*252);

		bih->biSize = sizeof(BITMAPINFOHEADER);
		bih->biWidth = pxsrc.w;
		bih->biHeight = pxsrc.h;
		bih->biPlanes = 1;
		bih->biBitCount = 8;
		bih->biCompression = BI_RGB;
		bih->biSizeImage = rowbytes*pxsrc.h;
		bih->biXPelsPerMeter = 0;
		bih->biYPelsPerMeter = 0;
		bih->biClrUsed = 252;
		bih->biClrImportant = 252;

		RGBQUAD *pal = (RGBQUAD *)((char *)bih.data() + sizeof(BITMAPINFOHEADER));
		for(int i=0; i<252; ++i) {
			pal[i].rgbRed		= (BYTE)((i/42)*51);
			pal[i].rgbGreen		= (BYTE)((((i/6)%7)*85)>>1);
			pal[i].rgbBlue		= (BYTE)((i%6)*51);
			pal[i].rgbReserved	= 0;
		}

		pVSOut->setFormat(bih.data(), bih.size());

		pOut->init(dstfile.c_str());

		ProgressDialog dlg((HWND)h, "Processing video stream", "Palettizing frames", (long)frames, true);

		vdblock<uint8> outbuf(rowbytes * pxsrc.h);

		const vdpixsize w = pxsrc.w;
		const vdpixsize h = pxsrc.h;

		try {
			for(uint32 frame=0; frame<frames; ++frame) {
				pVS->getFrame(frame);

				const uint8 *src = (const uint8 *)pxsrc.data;
				ptrdiff_t srcpitch = pxsrc.pitch;
				uint8 *dst = &outbuf[rowbytes * (pxsrc.h - 1)];

				for(int y=0; y<h; ++y) {
					const uint8 *dr = ditherred[y & 15];
					const uint8 *dg = dithergrn[y & 15];
					const uint8 *db = ditherblu[y & 15];

					for(int x=0; x<w; ++x) {
						const uint8 b = (uint8)((((src[0] * 1286)>>8) + dr[x&15]) >> 8);
						const uint8 g = (uint8)((((src[1] * 1543)>>8) + dg[x&15]) >> 8);
						const uint8 r = (uint8)((((src[2] * 1286)>>8) + db[x&15]) >> 8);
						src += 4;

						dst[x] = (uint8)(r*42 + g*6 + b);
					}

					vdptrstep(dst, -(ptrdiff_t)rowbytes);
					vdptrstep(src, srcpitch - w*4);
				}

				pVSOut->write(AVIOutputStream::kFlagKeyFrame, outbuf.data(), outbuf.size(), 1);

				dlg.advance(frame);
				dlg.check();
			}
		} catch(const MyUserAbortError&) {
		}

		pVSOut->flush();
		pOut->finalize();

	} catch(const MyError& e) {
		e.post((HWND)h, g_szError);
	}
}