vdiggrab.c

来自「来自网络的iaxclient的协议栈源码」· C语言 代码 · 共 859 行 · 第 1/2 页

C
859
字号
					// system to use as a mask					(RgnHandle)NULL,					0, // flags					// accuracy in decompression					codecHighQuality,					// compressor identifier or special					// identifiers ie. bestSpeedCodec					bestSpeedCodec)))						//anyCodec); //bestSpeedCodec);	{		fprintf(stderr, "DecompressSequenceBeginS err=%d\n", err);	}	return err;}OSErrvdgDecompressionSequenceWhen(VdigGrab* pVdg,		Ptr theData,		long dataSize){	OSErr err;	CodecFlags	ignore = 0;	if ((err = DecompressSequenceFrameWhen(			pVdg->dstImageSeq, // sequence ID returned by DecompressSequenceBegin			theData,  // pointer to compressed image data			dataSize, // size of the buffer			0,        // in flags			&ignore,  // out flags			NULL,     // async completion proc			NULL )))		fprintf(stderr, "DecompressSequenceFrameWhen err=%d\n", err);	return err;}OSErrvdgDecompressionSequenceEnd( VdigGrab* pVdg ){	OSErr err;	if (!pVdg->dstImageSeq)	{		fprintf(stderr, "vdgDecompressionSequenceEnd NULL sequence\n");		err = qtParamErr;		goto endFunc;	}	if ((err = CDSequenceEnd(pVdg->dstImageSeq)))	{		fprintf(stderr, "CDSequenceEnd err=%d\n", err);		goto endFunc;	}	pVdg->dstImageSeq = 0;endFunc:	return err;}OSErrvdgStopGrabbing(VdigGrab* pVdg){	OSErr err;	if ( !pVdg->vdCompInst )		return 0;	if ((err = VDSetCompressionOnOff( pVdg->vdCompInst, 0)))	{		fprintf(stderr, "VDSetCompressionOnOff err=%d\n", err);	}	if ((err = vdgDecompressionSequenceEnd(pVdg)))	{		fprintf(stderr, "vdgDecompressionSequenceEnd err=%d\n", err);	}	pVdg->isGrabbing = 0;	return err;}boolvdgIsGrabbing(VdigGrab* pVdg){	return pVdg->isGrabbing;}OSErrvdgIdle(VdigGrab* pVdg, int*  pIsUpdated){	OSErr err;	UInt8		queuedFrameCount;	Ptr		theData;	long		dataSize;	UInt8		similarity;	TimeRecord	time;	*pIsUpdated = 0;	// should be while?	if ( !(err = vdgPoll( pVdg,					&queuedFrameCount,					&theData,					&dataSize,					&similarity,					&time))			&& queuedFrameCount)	{		*pIsUpdated = 1;		// Decompress the sequence		if ((err = vdgDecompressionSequenceWhen(pVdg, theData, dataSize)))		{			fprintf(stderr, "vdgDecompressionSequenceWhen err=%d\n", err);			//goto endFunc;		}		// return the buffer		if ((err = vdgReleaseBuffer(pVdg, theData)))		{			fprintf(stderr, "vdgReleaseBuffer err=%d\n", err);			//goto endFunc;		}	}	if (err)	{		fprintf(stderr, "vdgPoll err=%d\n", err);		goto endFunc;	}endFunc:	return err;}OSErrvdgPoll(VdigGrab* pVdg,		UInt8*		pQueuedFrameCount,		Ptr*		pTheData,		long*		pDataSize,		UInt8*		pSimilarity,		TimeRecord*	pTime ){	OSErr err;	if (!pVdg->isGrabbing)	{		fprintf(stderr, "vdgGetFrame error: not grabbing\n");		err = qtParamErr;		goto endFunc;	}	if ((err = VDCompressDone(pVdg->vdCompInst,					pQueuedFrameCount,					pTheData,					pDataSize,					pSimilarity,					pTime)))	{		fprintf(stderr, "vdgGetFrame error: not grabbing\n");		goto endFunc;	}	// Overlapped grabbing	if (*pQueuedFrameCount)	{		if ((err = VDCompressOneFrameAsync(pVdg->vdCompInst)))		{			fprintf(stderr, "VDCompressOneFrameAsync err=%d\n", err);			goto endFunc;		}	}endFunc:	return err;}OSErrvdgReleaseBuffer(VdigGrab*   pVdg, Ptr theData){	OSErr err;	if ((err = VDReleaseCompressBuffer(pVdg->vdCompInst, theData)))		fprintf(stderr, "VDReleaseCompressBuffer err=%d\n", err);	return err;}OSErrvdgUninit(VdigGrab* pVdg){	OSErr err = noErr;	if (pVdg->vdImageDesc)	{		DisposeHandle((Handle)pVdg->vdImageDesc);		pVdg->vdImageDesc = nil;	}	if (pVdg->vdCompInst)	{		if ((err = CloseComponent(pVdg->vdCompInst)))			fprintf(stderr, "CloseComponent err=%d\n", err);		pVdg->vdCompInst = nil;	}	if (pVdg->sgchanVideo)	{		if ((err = SGDisposeChannel(pVdg->seqGrab, pVdg->sgchanVideo)))			fprintf(stderr, "SGDisposeChannel err=%d\n", err);		pVdg->sgchanVideo = nil;	}	if (pVdg->seqGrab)	{		if ((err = CloseComponent(pVdg->seqGrab)))			fprintf(stderr, "CloseComponent err=%d\n", err);		pVdg->seqGrab = nil;	}	ExitMovies();	return err;}voidvdgDelete(VdigGrab* pVdg){	if (!pVdg)	{		fprintf(stderr, "vdgDelete NULL pointer\n");		return;	}	free(pVdg);}OSErrvdgGetSettings(VdigGrab* pVdg){	OSErr err;	// Extract information from the SG	if ((err = SGGetVideoCompressor(pVdg->sgchanVideo,					&pVdg->cpDepth,					&pVdg->cpCompressor,					&pVdg->cpSpatialQuality,					&pVdg->cpTemporalQuality,					&pVdg->cpKeyFrameRate)))	{		fprintf(stderr, "SGGetVideoCompressor err=%d\n", err);		goto endFunc;	}	if ((err = SGGetFrameRate(pVdg->sgchanVideo, &pVdg->cpFrameRate)))	{		fprintf(stderr, "SGGetFrameRate err=%d\n", err);		goto endFunc;	}	// Get the selected vdig from the SG	if (!(pVdg->vdCompInst = SGGetVideoDigitizerComponent(pVdg->sgchanVideo)))	{		fprintf(stderr, "SGGetVideoDigitizerComponent error\n");		goto endFunc;	}endFunc:	return err;}// --------------------// MakeSequenceGrabber  (adapted from Apple mung sample)//SeqGrabComponentMakeSequenceGrabber(WindowRef pWindow){	SeqGrabComponent seqGrab = NULL;	OSErr err = noErr;	// open the default sequence grabber	if (!(seqGrab = OpenDefaultComponent(SeqGrabComponentType, 0)))	{		fprintf(stderr, "OpenDefaultComponent failed to open the default sequence grabber.\n");		goto endFunc;	}	// initialize the default sequence grabber component	if ((err = SGInitialize(seqGrab)))	{		fprintf(stderr, "SGInitialize err=%d\n", err);		goto endFunc;	}	// This should be defaulted to the current port according to QT doco	if ((err = SGSetGWorld(seqGrab, GetWindowPort(pWindow), NULL)))	{		fprintf(stderr, "SGSetGWorld err=%d\n", err);		goto endFunc;	}	// specify the destination data reference for a record operation	// tell it we're not making a movie	// if the flag seqGrabDontMakeMovie is used, the sequence grabber still calls	// your data function, but does not write any data to the movie file	// writeType will always be set to seqGrabWriteAppend	if ((err = SGSetDataRef(seqGrab, 0, 0, seqGrabDontMakeMovie)))	{		fprintf(stderr, "SGSetGWorld err=%d\n", err);		goto endFunc;	}endFunc:	if (err && (seqGrab != NULL))	{ // clean up on failure		CloseComponent(seqGrab);		seqGrab = NULL;	}	return seqGrab;}// --------------------// MakeSequenceGrabChannel (adapted from Apple mung sample)//OSErrMakeSequenceGrabChannel(SeqGrabComponent seqGrab, SGChannel* psgchanVideo){	long  flags = 0;	OSErr err = noErr;	if ((err = SGNewChannel(seqGrab, VideoMediaType, psgchanVideo)))	{		if ( err != couldntGetRequiredComponent )			fprintf(stderr, "SGNewChannel err=%d\n", err);		goto endFunc;	}	//err = SGSetChannelBounds(*sgchanVideo, rect);	// set usage for new video channel to avoid playthrough	// note we don't set seqGrabPlayDuringRecord	if ((err = SGSetChannelUsage(*psgchanVideo, flags | seqGrabRecord)))	{		fprintf(stderr, "SGSetChannelUsage err=%d\n", err);		goto endFunc;	}endFunc:	if ((err != noErr) && psgchanVideo)	{		// clean up on failure		SGDisposeChannel(seqGrab, *psgchanVideo);		*psgchanVideo = NULL;	}	return err;}// From QT sample code// Declaration of a typical application-defined functionBoolean MySGModalFilterProc (		DialogPtr            theDialog,		const EventRecord    *theEvent,		short                *itemHit,		long                 refCon ){	// Ordinarily, if we had multiple windows we cared about, we'd handle	// updating them in here, but since we don't, we'll just clear out	// any update events meant for us	Boolean handled = false;	if ((theEvent->what == updateEvt) &&			((WindowPtr) theEvent->message == (WindowPtr) refCon))	{		BeginUpdate ((WindowPtr) refCon);		EndUpdate ((WindowPtr) refCon);		handled = true;	}	return handled;}OSErrcreateOffscreenGWorld(GWorldPtr* pGWorldPtr,		OSType pixelFormat,		Rect* pBounds){	OSErr err;	CGrafPtr theOldPort;	GDHandle theOldDevice;	// create an offscreen GWorld	if ((err = QTNewGWorld(pGWorldPtr,           // returned GWorld					pixelFormat, // pixel format					pBounds,     // bounds					0,           // color table					NULL,        // GDHandle					0)))         // flags	{		fprintf(stderr, "QTNewGWorld: err=%d\n", err);		goto endFunc;	}	// lock the pixmap and make sure it's locked because	// we can't decompress into an unlocked PixMap	if (!LockPixels(GetGWorldPixMap(*pGWorldPtr)))		fprintf(stderr, "createOffscreenGWorld: Can't lock pixels!\n");	GetGWorld(&theOldPort, &theOldDevice);	SetGWorld(*pGWorldPtr, NULL);	EraseRect(pBounds);	SetGWorld(theOldPort, theOldDevice);endFunc:	return err;}voiddisposeOffscreenGWorld(GWorldPtr gworld){	UnlockPixels(GetGWorldPixMap(gworld));	DisposeGWorld(gworld);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?