Example #1
0
	InputFile *CreateInputFile(uint32 flags) {
		VDInputFileWAV *pf = new_nothrow VDInputFileWAV;

		if (!pf)
			throw MyMemoryError();

		return pf;
	}
Example #2
0
IVDMediaOutputStream *VDAVIOutputSegmented::createAudioStream() {
	VDAVIOutputSegmentedAudioStream *pStream = new_nothrow VDAVIOutputSegmentedAudioStream(this);
	if (!pStream)
		throw MyMemoryError();

	if (!mpFirstAudioStream)
		mpFirstAudioStream = pStream;

	return pStream;
}
Example #3
0
AVIStripeIndexLookup::AVIStripeIndexLookup(IAVIReadStream *pasIndex) {
	index_table		= NULL;

	try {
		AVIStripeIndexEntry *asieptr;
		LONG lStart, lCur, lEnd;

		if (-1 == (lStart = (long)pasIndex->Start())
			|| -1 == (lEnd = (long)pasIndex->End()))

			throw MyError("Stripe index: can't get start/end of index stream");

		ProgressDialog pd(NULL, "AVI Striped Import Filter", "Reading stripe index", lEnd-lStart, true);

		pd.setValueFormat("Frame %ld/%ld");

		index_table_size = lEnd - lStart;

		if (!(index_table = new AVIStripeIndexEntry[index_table_size]))
			throw MyMemoryError();

		asieptr = index_table;

		pasIndex->BeginStreaming(lStart, lEnd, 100000);

		lCur = lStart;

		while(lCur < lEnd) {
			HRESULT err;
			LONG lActualBytes, lActualSamples;

			err = pasIndex->Read(lCur, lEnd-lCur, asieptr, sizeof(AVIStripeIndexEntry)*(lEnd-lCur), &lActualBytes, &lActualSamples);

			if (err == AVIERR_OK && !lActualSamples)
				err = AVIERR_FILEREAD;

			if (err != AVIERR_OK) throw MyAVIError("AVIStripeIndex",err);

			if ((size_t)lActualBytes != lActualSamples * sizeof(AVIStripeIndexEntry))
				throw MyError("Stripe index: bad index marks! (not 16 bytes)");

			lCur += lActualSamples;
			asieptr += lActualSamples;

			pd.advance(lCur);
			pd.check();
		}

		pasIndex->EndStreaming();

	} catch(...) {
		delete index_table;
		throw;
	}
}
Example #4
0
VEffectBlur::VEffectBlur(const VBitmap *vbm) {
	int i;

	for(i=0; i<3; i++)
		if (!(rows[i] = new Pixel32[vbm->w])) {
			while(--i>=0)
				delete rows[i];

			throw MyMemoryError();
		}
}
Example #5
0
void AVIStripeSystem::_construct(int nStripes) {
	int i;

	this->nStripes = nStripes;

	if (!(stripe = new AVIStripe *[nStripes]))
		throw MyMemoryError();

	for(i=0; i<nStripes; i++)
		stripe[i] = NULL;
}
Example #6
0
void AVIOutputFile::setSegmentHintBlock(bool fIsFinal, const char *pszNextPath, int cbBlock) {
	if (!pSegmentHint)
		if (!(pSegmentHint = new char[cbBlock]))
			throw MyMemoryError();

	cbSegmentHint = cbBlock;

	memset(pSegmentHint, 0, cbBlock);

	pSegmentHint[0] = !fIsFinal;
	if (pszNextPath)
		strcpy(pSegmentHint+1, pszNextPath);
}
Example #7
0
void VDChunkedBuffer::AllocChunk() {
	if (mFreeChunks.empty()) {
		mFreeChunks.push_back(ChunkInfo());

		ChunkInfo& ci = mFreeChunks.back();
		ci.mpChunk		= VDFile::AllocUnbuffer(mChunkSize);
		if (!ci.mpChunk)
			throw MyMemoryError();
		ci.mChunkSize	= mChunkSize;
	}

	mActiveChunks.splice(mActiveChunks.end(), mFreeChunks, mFreeChunks.begin());
}
Example #8
0
void VDNORETURN vdallocator_base::throw_oom() {
	throw MyMemoryError();
}
Example #9
0
void JobCreateScript(JobScriptOutput& output, const DubOptions *opt, bool bIncludeEditList = true, bool bIncludeTextInfo = true) {
	char *mem= NULL;
	char buf[4096];
	long l;

	int audioSourceMode = g_project->GetAudioSourceMode();

	switch(audioSourceMode) {

	case kVDAudioSourceMode_External:
		{
			const VDStringA& encodedFileName = VDEncodeScriptString(VDStringW(g_szInputWAVFile));
			const VDStringA& encodedDriverName = VDEncodeScriptString(VDTextWToU8(g_project->GetAudioSourceDriverName(), -1));

			// check if we have options to write out
			const InputFileOptions *opts = g_project->GetAudioSourceOptions();
			if (opts) {
				int l;
				char buf[256];

				l = opts->write(buf, (sizeof buf)/7*3);

				if (l) {
					membase64(buf+l, (char *)buf, l);

					output.addf("VirtualDub.audio.SetSource(\"%s\", \"%s\", \"%s\");", encodedFileName.c_str(), encodedDriverName.c_str(), buf+l);
					break;
				}
			}

			// no options
			output.addf("VirtualDub.audio.SetSource(\"%s\", \"%s\");", encodedFileName.c_str(), encodedDriverName.c_str());
		}
		break;

	default:
		if (audioSourceMode >= kVDAudioSourceMode_Source) {
			int index = audioSourceMode - kVDAudioSourceMode_Source;

			if (!index)
				output.addf("VirtualDub.audio.SetSource(1);");
			else
				output.addf("VirtualDub.audio.SetSource(1,%d);", index);
			break;
		}
		// fall through
	case kVDAudioSourceMode_None:
		output.addf("VirtualDub.audio.SetSource(0);");
		break;
	
	}

	output.addf("VirtualDub.audio.SetMode(%d);", opt->audio.mode);

	output.addf("VirtualDub.audio.SetInterleave(%d,%d,%d,%d,%d);",
			opt->audio.enabled,
			opt->audio.preload,
			opt->audio.interval,
			opt->audio.is_ms,
			opt->audio.offset);

	output.addf("VirtualDub.audio.SetClipMode(%d,%d);",
			opt->audio.fStartAudio,
			opt->audio.fEndAudio);

	output.addf("VirtualDub.audio.SetConversion(%d,%d,%d,0,%d);",
			opt->audio.new_rate,
			opt->audio.newPrecision,
			opt->audio.newChannels,
			opt->audio.fHighQuality);

	if (opt->audio.mVolume >= 0.0f)
		output.addf("VirtualDub.audio.SetVolume(%d);", VDRoundToInt(256.0f * opt->audio.mVolume));
	else
		output.addf("VirtualDub.audio.SetVolume();");

	if (g_ACompressionFormat) {
		if (g_ACompressionFormat->mExtraSize) {
			mem = (char *)allocmem(((g_ACompressionFormat->mExtraSize+2)/3)*4 + 1);
			if (!mem) throw MyMemoryError();

			membase64(mem, (char *)(g_ACompressionFormat+1), g_ACompressionFormat->mExtraSize);
			output.addf("VirtualDub.audio.SetCompressionWithHint(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");"
						,g_ACompressionFormat->mTag
						,g_ACompressionFormat->mSamplingRate
						,g_ACompressionFormat->mChannels
						,g_ACompressionFormat->mSampleBits
						,g_ACompressionFormat->mDataRate
						,g_ACompressionFormat->mBlockSize
						,g_ACompressionFormat->mExtraSize
						,mem
						,VDEncodeScriptString(g_ACompressionFormatHint).c_str()
						);

			freemem(mem);
		} else
			output.addf("VirtualDub.audio.SetCompressionWithHint(%d,%d,%d,%d,%d,%d,\"%s\");"
						,g_ACompressionFormat->mTag
						,g_ACompressionFormat->mSamplingRate
						,g_ACompressionFormat->mChannels
						,g_ACompressionFormat->mSampleBits
						,g_ACompressionFormat->mDataRate
						,g_ACompressionFormat->mBlockSize
						,VDEncodeScriptString(g_ACompressionFormatHint).c_str()
						);
	} else
		output.addf("VirtualDub.audio.SetCompression();");

	output.addf("VirtualDub.audio.EnableFilterGraph(%d);", opt->audio.bUseAudioFilterGraph);

	output.addf("VirtualDub.video.SetInputFormat(%d);", opt->video.mInputFormat);
	output.addf("VirtualDub.video.SetOutputFormat(%d);", opt->video.mOutputFormat);

	output.addf("VirtualDub.video.SetMode(%d);", opt->video.mode);
	output.addf("VirtualDub.video.SetSmartRendering(%d);", opt->video.mbUseSmartRendering);
	output.addf("VirtualDub.video.SetPreserveEmptyFrames(%d);", opt->video.mbPreserveEmptyFrames);

	output.addf("VirtualDub.video.SetFrameRate2(%u,%u,%d);",
			opt->video.mFrameRateAdjustHi,
			opt->video.mFrameRateAdjustLo,
			opt->video.frameRateDecimation);

	if (opt->video.frameRateTargetLo) {
		output.addf("VirtualDub.video.SetTargetFrameRate(%u,%u);",
				opt->video.frameRateTargetHi,
				opt->video.frameRateTargetLo);
	}

	output.addf("VirtualDub.video.SetIVTC(0, 0, 0, 0);");

	if ((g_Vcompression.dwFlags & ICMF_COMPVARS_VALID) && g_Vcompression.fccHandler) {
		output.addf("VirtualDub.video.SetCompression(0x%08lx,%d,%d,%d);",
				g_Vcompression.fccHandler,
				g_Vcompression.lKey,
				g_Vcompression.lQ,
				g_Vcompression.lDataRate);

		l = ICGetStateSize(g_Vcompression.hic);

		if (l>0) {
			mem = (char *)allocmem(l + ((l+2)/3)*4 + 1);
			if (!mem) throw MyMemoryError();

			if (ICGetState(g_Vcompression.hic, mem, l)<0) {
				freemem(mem);
//				throw MyError("Bad state data returned from compressor");

				// Fine then, be that way.  Stupid Pinnacle DV200 driver.
				mem = NULL;
			}

			if (mem) {
				membase64(mem+l, mem, l);
				// urk... Windows Media 9 VCM uses a very large configuration struct (~7K pre-BASE64).
				sprintf(buf, "VirtualDub.video.SetCompData(%d,\"", l);

				VDStringA line(buf);
				line += (mem+l);
				line += "\");";
				output.adds(line.c_str());
				freemem(mem);
			}
		}

	} else
		output.addf("VirtualDub.video.SetCompression();");

	output.addf("VirtualDub.video.filters.Clear();");

	// Add video filters

	FilterInstance *fa = (FilterInstance *)g_listFA.tail.next, *fa_next;
	int iFilter = 0;

	while(fa_next = (FilterInstance *)fa->next) {
		output.addf("VirtualDub.video.filters.Add(\"%s\");", strCify(fa->GetName()));

		if (fa->IsCroppingEnabled()) {
			const vdrect32& cropInsets = fa->GetCropInsets();

			output.addf("VirtualDub.video.filters.instance[%d].SetClipping(%d,%d,%d,%d%s);"
						, iFilter
						, cropInsets.left
						, cropInsets.top
						, cropInsets.right
						, cropInsets.bottom
						, fa->IsPreciseCroppingEnabled() ? "" : ",0"
						);
		}

		VDStringA scriptStr;
		if (fa->GetScriptString(scriptStr))
			output.addf("VirtualDub.video.filters.instance[%d].%s;", iFilter, scriptStr.c_str());

		if (!fa->IsEnabled())
			output.addf("VirtualDub.video.filters.instance[%d].SetEnabled(false);", iFilter);

		VDParameterCurve *pc = fa->GetAlphaParameterCurve();
		if (pc) {
			output.addf("declare curve = VirtualDub.video.filters.instance[%d].AddOpacityCurve();", iFilter);

			const VDParameterCurve::PointList& pts = pc->Points();
			for(VDParameterCurve::PointList::const_iterator it(pts.begin()), itEnd(pts.end()); it!=itEnd; ++it) {
				const VDParameterCurvePoint& pt = *it;

				output.addf("curve.AddPoint(%g, %g, %d);", pt.mX, pt.mY, pt.mbLinear);
			}
		}

		++iFilter;
		fa = fa_next;
	}

	// Add audio filters

	{
		VDAudioFilterGraph::FilterList::const_iterator it(g_audioFilterGraph.mFilters.begin()), itEnd(g_audioFilterGraph.mFilters.end());
		int connidx = 0;
		int srcfilt = 0;

		output.addf("VirtualDub.audio.filters.Clear();");

		for(; it!=itEnd; ++it, ++srcfilt) {
			const VDAudioFilterGraph::FilterEntry& fe = *it;

			output.addf("VirtualDub.audio.filters.Add(\"%s\");", strCify(VDTextWToU8(fe.mFilterName).c_str()));

			for(unsigned i=0; i<fe.mInputPins; ++i) {
				const VDAudioFilterGraph::FilterConnection& conn = g_audioFilterGraph.mConnections[connidx++];
				output.addf("VirtualDub.audio.filters.Connect(%d, %d, %d, %d);", conn.filt, conn.pin, srcfilt, i);
			}

			VDPluginConfig::const_iterator itc(fe.mConfig.begin()), itcEnd(fe.mConfig.end());

			for(; itc!=itcEnd; ++itc) {
				const unsigned idx = (*itc).first;
				const VDPluginConfigVariant& var = (*itc).second;

				switch(var.GetType()) {
				case VDPluginConfigVariant::kTypeU32:
					output.addf("VirtualDub.audio.filters.instance[%d].SetInt(%d, %d);", srcfilt, idx, var.GetU32());
					break;
				case VDPluginConfigVariant::kTypeS32:
					output.addf("VirtualDub.audio.filters.instance[%d].SetInt(%d, %d);", srcfilt, idx, var.GetS32());
					break;
				case VDPluginConfigVariant::kTypeU64:
					output.addf("VirtualDub.audio.filters.instance[%d].SetLong(%d, %I64d);", srcfilt, idx, var.GetU64());
					break;
				case VDPluginConfigVariant::kTypeS64:
					output.addf("VirtualDub.audio.filters.instance[%d].SetLong(%d, %I64d);", srcfilt, idx, var.GetS64());
					break;
				case VDPluginConfigVariant::kTypeDouble:
					output.addf("VirtualDub.audio.filters.instance[%d].SetDouble(%d, %g);", srcfilt, idx, var.GetDouble());
					break;
				case VDPluginConfigVariant::kTypeAStr:
					output.addf("VirtualDub.audio.filters.instance[%d].SetString(%d, \"%s\");", srcfilt, idx, strCify(VDTextWToU8(VDTextAToW(var.GetAStr())).c_str()));
					break;
				case VDPluginConfigVariant::kTypeWStr:
					output.addf("VirtualDub.audio.filters.instance[%d].SetString(%d, \"%s\");", srcfilt, idx, strCify(VDTextWToU8(var.GetWStr(), -1).c_str()));
					break;
				case VDPluginConfigVariant::kTypeBlock:
					output.addf("VirtualDub.audio.filters.instance[%d].SetBlock(%d, %d, \"%s\");", srcfilt, idx, var.GetBlockLen(), VDEncodeBase64A(var.GetBlockPtr(), var.GetBlockLen()).c_str());
					break;
				}
			}
		}
	}

	// Add subset information

	if (bIncludeEditList) {
		const FrameSubset& fs = g_project->GetTimeline().GetSubset();

		output.addf("VirtualDub.subset.Clear();");

		for(FrameSubset::const_iterator it(fs.begin()), itEnd(fs.end()); it!=itEnd; ++it)
			output.addf("VirtualDub.subset.Add%sRange(%I64d,%I64d);", it->bMask ? "Masked" : "", it->start, it->len);

		// Note that this must be AFTER the subset (we used to place it before, which was a bug).
		if (g_project->IsSelectionPresent()) {
			output.addf("VirtualDub.video.SetRangeFrames(%I64d,%I64d);",
				g_project->GetSelectionStartFrame(),
				g_project->GetSelectionEndFrame());
		} else {
			output.addf("VirtualDub.video.SetRange();");
		}
	}

	// Add text information
	if (bIncludeTextInfo) {
		typedef std::list<std::pair<uint32, VDStringA> > tTextInfo;
		const tTextInfo& textInfo = g_project->GetTextInfo();

		output.addf("VirtualDub.project.ClearTextInfo();");
		for(tTextInfo::const_iterator it(textInfo.begin()), itEnd(textInfo.end()); it!=itEnd; ++it) {
			char buf[5]={0};
			
			memcpy(buf, &(*it).first, 4);

			output.addf("VirtualDub.project.AddTextInfo(\"%s\", \"%s\");", buf, VDEncodeScriptString((*it).second).c_str());
		}
	}
}
Example #10
0
BOOL AVIOutputFile::_init(const char *szFile, LONG xSize, LONG ySize, BOOL videoIn, BOOL audioIn, BOOL audio2In, LONG bufferSize, BOOL is_interleaved, bool fThreaded) {
	AVISUPERINDEX asi={0};
	struct _avisuperindex_entry asie_dumb[MAX_SUPERINDEX_ENTRIES];

	fLimitTo4Gb = IsFilenameOnFATVolume(szFile);

	if (audio2In) {
		if (!audio2Out) return FALSE;
	} else {
		delete audio2Out;
		audio2Out = NULL;
	}

	if (audioIn) {
		if (!audioOut) return FALSE;
	} else {
		delete audioOut;
		audioOut = NULL;
	}

	if (!videoOut) return FALSE;

	// Allocate indexes

	if (!(index = new AVIIndex())) return FALSE;

	if (fExtendedAVI) {
		if (!(index_audio2 = new AVIIndex())) return FALSE;
		if (!(index_audio = new AVIIndex())) return FALSE;
		if (!(index_video = new AVIIndex())) return FALSE;
	}

	// Initialize main AVI header (avih)

	memset(&avihdr, 0, sizeof avihdr);
	avihdr.dwMicroSecPerFrame		= MulDivUnsigned(videoOut->streamInfo.dwScale, 1000000U, videoOut->streamInfo.dwRate);
	avihdr.dwMaxBytesPerSec			= 0;
	avihdr.dwPaddingGranularity		= 0;
	avihdr.dwFlags					= AVIF_HASINDEX | (is_interleaved ? AVIF_ISINTERLEAVED : 0);
	avihdr.dwTotalFrames			= videoOut->streamInfo.dwLength;
	avihdr.dwInitialFrames			= 0;
	avihdr.dwStreams				= audio2In ? 3: (audioIn ? 2 : 1);
	avihdr.dwSuggestedBufferSize	= 0;
	avihdr.dwWidth					= xSize;
	avihdr.dwHeight					= ySize;

	// Initialize file

	if (!fCaching) {

		hFile = CreateFile(szFile, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);

		if (INVALID_HANDLE_VALUE == hFile)
			throw MyWin32Error("%s: %%s", GetLastError(), szME);

		if (!(fastIO = new FastWriteStream(szFile, bufferSize, lChunkSize ? lChunkSize : bufferSize/2, fThreaded)))
			throw MyMemoryError();
	} else {
		hFile = CreateFile(szFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_WRITE_THROUGH, NULL);

		if (INVALID_HANDLE_VALUE == hFile)
			throw MyWin32Error("%s: %%s", GetLastError(), szME);
	}

	i64FilePosition = 0;

	////////// Initialize the first 'AVI ' chunk //////////

	__int64 hdrl_pos;
	__int64 odml_pos;

	DWORD dw[64];

	// start RIFF chunk

	dw[0]	= FOURCC_RIFF;
	dw[1]	= 0;
	dw[2]	= formtypeAVI;

	_writeHdr(dw, 12);

	// start header chunk

	hdrl_pos = _beginList(listtypeAVIHEADER);

	// write out main AVI header

	main_hdr_pos = _writeHdrChunk(ckidAVIMAINHDR, &avihdr, sizeof avihdr);

	_RPT1(0,"Main header is at %08lx\n", main_hdr_pos);


	// start video stream headers

	strl_pos = _beginList(listtypeSTREAMHEADER);

	// write out video stream header and format

	video_hdr_pos	= _writeHdrChunk(ckidSTREAMHEADER, &videoOut->streamInfo, sizeof videoOut->streamInfo);
	_writeHdrChunk(ckidSTREAMFORMAT, videoOut->getFormat(), videoOut->getFormatLen());

	_RPT1(0,"Video header is at %08lx\n", video_hdr_pos);

	// write out video superindex (but make it a JUNK chunk for now).

	if (fExtendedAVI) {
		memset(asie_dumb, 0, sizeof asie_dumb);
		video_indx_pos = _getPosition();
		asi.fcc = ckidAVIPADDING;
		asi.cb = (sizeof asi)-8 + MAX_SUPERINDEX_ENTRIES*sizeof(_avisuperindex_entry);
		_writeHdr(&asi, sizeof asi);
		_writeHdr(asie_dumb, MAX_SUPERINDEX_ENTRIES*sizeof(_avisuperindex_entry));
	}

	// finish video stream header

	_closeList(strl_pos);

	videoOut->streamInfo.dwSuggestedBufferSize = 0;

	// if there is audio...

	if (audioIn) {
		// start audio stream headers

		strl_pos = _beginList(listtypeSTREAMHEADER);

		// write out audio stream header and format

		audio_hdr_pos	= _writeHdrChunk(ckidSTREAMHEADER, &audioOut->streamInfo, sizeof audioOut->streamInfo);
		audio_format_pos = _writeHdrChunk(ckidSTREAMFORMAT, audioOut->getFormat(), audioOut->getFormatLen());

		_RPT1(0,"Audio header is at %08lx\n", audio_hdr_pos);

		// write out audio superindex (but make it a JUNK chunk for now).

		if (fExtendedAVI) {
			audio_indx_pos = _getPosition();
			asi.fcc = ckidAVIPADDING;
			asi.cb = (sizeof asi)-8 + MAX_SUPERINDEX_ENTRIES*sizeof(_avisuperindex_entry);
			_writeHdr(&asi, sizeof asi);
			_writeHdr(asie_dumb, MAX_SUPERINDEX_ENTRIES*sizeof(_avisuperindex_entry));
		}

		// finish audio stream header

		_closeList(strl_pos);

		audioOut->streamInfo.dwSuggestedBufferSize = 0;
	}

// if there is a second audio...

	if (audio2In) {
		// start audio stream headers

		strl_pos = _beginList(listtypeSTREAMHEADER);

		// write out audio stream header and format

		audio2_hdr_pos	= _writeHdrChunk(ckidSTREAMHEADER, &audio2Out->streamInfo, sizeof audio2Out->streamInfo);
		audio2_format_pos = _writeHdrChunk(ckidSTREAMFORMAT, audio2Out->getFormat(), audio2Out->getFormatLen());

		_RPT1(0,"Audio2 header is at %08lx\n", audio2_hdr_pos);

		// write out audio superindex (but make it a JUNK chunk for now).

		if (fExtendedAVI) {
			audio2_indx_pos = _getPosition();
			asi.fcc = ckidAVIPADDING;
			asi.cb = (sizeof asi)-8 + MAX_SUPERINDEX_ENTRIES*sizeof(_avisuperindex_entry);
			_writeHdr(&asi, sizeof asi);
			_writeHdr(asie_dumb, MAX_SUPERINDEX_ENTRIES*sizeof(_avisuperindex_entry));
		}

		// finish audio stream header

		_closeList(strl_pos);

		audio2Out->streamInfo.dwSuggestedBufferSize = 0;
	}


	// write out dmlh header (indicates real # of frames)

	if (fExtendedAVI) {
		odml_pos = _beginList('lmdo');

		memset(dw, 0, sizeof dw);
		dmlh_pos = _writeHdrChunk('hlmd', dw, 62*4);

		_closeList(odml_pos);
	}

	// write out segment hint block

	if (pSegmentHint)
		seghint_pos = _writeHdrChunk('mges', pSegmentHint, cbSegmentHint);

	_closeList(hdrl_pos);
//	_flushHdr();

	// pad out to a multiple of 2048 bytes
	//
	// WARNING: ActiveMovie/WMP can't handle a trailing JUNK chunk in hdrl
	//			if an extended index is in use.  It says the file format
	//			is invalid!

	{
		char *s;
		long pad;

		pad = (2048 - ((_getPosition()+8)&2047))&2047;

		if (pad) {
			if (!(s = (char *)allocmem(pad)))
				return FALSE;

			memset(s,0,pad);

			if (pad > 80)
				sprintf(s, "VirtualDub build %d/%s", version_num,
#ifdef _DEBUG
		"debug"
#else
		"release"
#endif
				);

			_writeHdrChunk(ckidAVIPADDING, s, pad);

			freemem(s);
		}

//		// If we are using a fast path, sync the fast path to the slow path

//		if (fastIO)
//			fastIO->Seek(i64FilePosition);
	}

	if (fastIO)
//		fastIO->FlushStart();
		fastIO->Put(pHeaderBlock, nHeaderLen);
	else
		_flushHdr();

	// If we're using the fast path, we're aligned to a sector boundary.
	// Write out the 12 header bytes.

	_openXblock();


	{
		DWORD dwLo, dwHi;

		dwLo = GetFileSize(hFile, &dwHi);

		if (dwLo != 0xFFFFFFFF || GetLastError()==NO_ERROR)
			i64EndOfFile = dwLo | ((__int64)dwHi << 32);
		else
			i64EndOfFile = 0;
	}

	fInitComplete = true;

	return TRUE;
}
Example #11
0
static void VDFilterCallbackThrowExceptMemory() {
	throw MyMemoryError();
}
Example #12
0
AVIStripeSystem::AVIStripeSystem(const char *szFile) {
	FILE *f = NULL;

	stripe = NULL;

	try {
		char linebuf[512];
		int stripe_cnt, cur;
		int lineno = 2;
		char *s, *t;

		// Type of lines we are trying to parse:
		//
		//	0   i   131072     65536      e:\capture_master.avi
		//	0   v   4194304    1048576   "e:\capture video stripe 1.avi"
		//  -1  v	1048576    524288    "i:\capture video stripe 2.avi"


		f = fopen(szFile, "r");
		if (!f) throw MyError("Couldn't open stripe definition file \"%s\"", szFile);

		if (!get_line(linebuf, sizeof linebuf, f))
				throw MyError("Failure reading first line of stripe def file");

		if (1!=sscanf(linebuf, " %d \n", &stripe_cnt))
			throw MyError("First line of stripe definition file must contain stripe count");

		if (stripe_cnt<=0)
			throw MyError("Invalid number of stripes (%d)", stripe_cnt);

		_construct(stripe_cnt);

		for(cur=0; cur<stripe_cnt; cur++) {
			int iPri, iName;
			long lBuffer, lChunk;
			char cMode[2];
			int match_count;

			if (!get_line(linebuf, sizeof linebuf, f))
				throw MyError("Failure reading stripe definition file");

			match_count = sscanf(linebuf, " %d %1s %ld %ld %n", &iPri, cMode, &lBuffer, &lChunk, &iName);

			if (match_count != 4)
				throw MyError("Stripe definition parse error: line %d", lineno);

			t = s = linebuf + iName;
			if (*s=='"') {
				++s, ++t;
				while(*t && *t!='\n' && *t!='"') ++t;
			} else
				while(*t && *t!='\n' && !isspace((unsigned char)*t)) ++t;

			if (t<=s)
				throw MyError("Stripe definition parse error: line %d -- no stripe filename!", lineno);

			switch(tolower(cMode[0])) {
			case 'm':	cMode[0] = AVIStripe::MODE_MASTER; break;
			case 'i':	cMode[0] = AVIStripe::MODE_INDEX; break;
			case 'v':	cMode[0] = AVIStripe::MODE_VIDEO; break;
			case 'a':	cMode[0] = AVIStripe::MODE_AUDIO; break;
			case 'b':	cMode[0] = AVIStripe::MODE_BOTH; break;
			default:
				throw MyError("Invalid stripe mode '%c'", cMode[0]);
			};

			// Allocate a stripe structure and copy the data into it

			if (!(stripe[cur] = new(t+1-s) AVIStripe))
				throw MyMemoryError();

			*t=0;

			stripe[cur]->lBufferSize = lBuffer;
			stripe[cur]->lChunkSize	= lChunk;
			stripe[cur]->iNameLen	= t+1-s;
			stripe[cur]->cStripeMode	= cMode[0];
			stripe[cur]->scPriority	= (signed char)iPri;
			strcpy(stripe[cur]->szName, s);

			++lineno;
		}
	} catch(...) {
		if (f) fclose(f);
		_destruct();
		throw;
	}
	fclose(f);
}
Example #13
0
const void *VideoSourceImages::streamGetFrame(const void *inputBuffer, uint32 data_len, bool is_preroll, VDPosition frame_num, VDPosition target_sample) {
	// We may get a zero-byte frame if we already have the image.

	if (!data_len)
		return getFrameBuffer();

	int w, h;
	bool bHasAlpha;

	bool bIsPNG = false;
	bool bIsJPG = false;
	bool bIsBMP = false;
	bool bIsIFF = false;
	bool bIsTGA = false;

	bIsPNG = VDDecodePNGHeader(inputBuffer, data_len, w, h, bHasAlpha);
	if (!bIsPNG) {
		bIsJPG = VDIsJPEGHeader(inputBuffer, data_len);
		if (!bIsJPG) {
			bIsBMP = DecodeBMPHeader(inputBuffer, data_len, w, h, bHasAlpha);
			if (!bIsBMP) {
				bIsIFF = VDIsMayaIFFHeader(inputBuffer, data_len);
				if (!bIsIFF)
					bIsTGA = DecodeTGAHeader(inputBuffer, data_len, w, h, bHasAlpha);
			}
		}
	}

	if (!bIsBMP && !bIsTGA && !bIsJPG && !bIsPNG && !bIsIFF)
		throw MyError("Image file must be in PNG, Windows BMP, truecolor TARGA format, MayaIFF, or sequential JPEG format.");

	if (bIsJPG) {
		if (!mpJPEGDecoder)
			mpJPEGDecoder = VDCreateJPEGDecoder();
		mpJPEGDecoder->Begin(inputBuffer, data_len);
		mpJPEGDecoder->DecodeHeader(w, h);
	}

	VDPixmap pxIFF;
	if (bIsIFF) {
		if (!mpIFFDecoder)
			mpIFFDecoder = VDCreateImageDecoderIFF();
		pxIFF = mpIFFDecoder->Decode(inputBuffer, data_len);
		w = pxIFF.w;
		h = pxIFF.h;
	}

	// Check image header.

	VDAVIBitmapInfoHeader *pFormat = getImageFormat();

	if (getFrameBuffer()) {
		if (w != pFormat->biWidth || h != pFormat->biHeight) {
			vdfastvector<wchar_t> errBuf;

			throw MyError("Image \"%ls\" (%dx%d) doesn't match the image dimensions of the first image (%dx%d)."
					, mpParent->ComputeFilename(errBuf, frame_num), w, h, pFormat->biWidth, pFormat->biHeight);
		}

	} else {
		if (!AllocFrameBuffer(w * h * 4))
			throw MyMemoryError();

		pFormat->biSize				= sizeof(BITMAPINFOHEADER);
		pFormat->biWidth			= w;
		pFormat->biHeight			= h;
		pFormat->biPlanes			= 1;
		pFormat->biCompression		= 0xFFFFFFFFUL;
		pFormat->biBitCount			= 0;
		pFormat->biSizeImage		= 0;
		pFormat->biXPelsPerMeter	= 0;
		pFormat->biYPelsPerMeter	= 0;
		pFormat->biClrUsed			= 0;
		pFormat->biClrImportant		= 0;

		// special case for initial read in constructor

		return NULL;
	}

	if (bIsJPG) {
		int format;

		switch(mvbFrameBuffer.depth) {
		case 16:	format = IVDJPEGDecoder::kFormatXRGB1555;	break;
		case 24:	format = IVDJPEGDecoder::kFormatRGB888;		break;
		case 32:	format = IVDJPEGDecoder::kFormatXRGB8888;	break;
		}

		mpJPEGDecoder->DecodeImage((char *)mvbFrameBuffer.data + mvbFrameBuffer.pitch * (mvbFrameBuffer.h - 1), -mvbFrameBuffer.pitch, format);
		mpJPEGDecoder->End();
	}

	if (bIsIFF)
		VDPixmapBlt(getTargetFormat(), pxIFF);

	if (bIsBMP)
		DecodeBMP(inputBuffer, data_len, mvbFrameBuffer);
	if (bIsTGA)
		DecodeTGA(inputBuffer, data_len, mvbFrameBuffer);
	if (bIsPNG) {
		if (!mpPNGDecoder)
			mpPNGDecoder = VDCreateImageDecoderPNG();

		PNGDecodeError err = mpPNGDecoder->Decode(inputBuffer, data_len);

		if (err) {
			if (err == kPNGDecodeOutOfMemory)
				throw MyMemoryError();

			vdfastvector<wchar_t> errBuf;

			throw MyError("Error decoding \"%ls\": %ls\n", mpParent->ComputeFilename(errBuf, frame_num), VDLoadString(0, kVDST_PNGDecodeErrors, err));
		}

		VDPixmapBlt(VDAsPixmap(mvbFrameBuffer), mpPNGDecoder->GetFrameBuffer());
	}

	mCachedFrame = frame_num;

	return mpFrameBuffer;
}
Example #14
0
IVDMediaOutputStream *AVIOutputNull::createVideoStream() {
	videoOut = new_nothrow AVIVideoNullOutputStream;
	if (!videoOut)
		throw MyMemoryError();
	return videoOut;
}