⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 EM8511s中使用的avi播放器
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	if (errorcode == AVI_DEMUX_ERROR_NO_ERROR)	{		KeyFramesOnly = direction;		// flush mpeg decoder		pMpegDecoder->Stop ();				deinit_buffer_pool (&BPavi);		deinit_buffer_pool (&BPpcm);		deinit_buffer_pool (&BPscan);		init_buffer_pool (&BPavi, avi_buffer, AVI_BUFFERSIZE, AVI_NBUFFERS);		init_buffer_pool (&BPpcm, pcm_buffer, PCM_BUFFERSIZE, PCM_NBUFFERS);		init_buffer_pool (&BPscan, mp43pending_buffer, 1024*128, N_MP43_SCAN_BUFFER);		if (direction == 0)		{			// seek to the current key frame position			// this is important because avi_seek will initialize			// audioTime, videoTime, and aviTime0 to the correct values			RMuint32 t = KeyFramesPosition * currentScale / currentRate;			DEBUGMSG (1, ("seek to %d seconds\n", t));			return avi_seek (t);		}		pMpegDecoder->PlayIFrame ();		// set the initial video time		aviFrameCounter = 0; 		videoTime = aviStartupDelay;			aviTime0 = 1;		DEBUGMSG (1, ("videoTime = %lu\n", (RMuint32)videoTime));		DEBUGMSG (1, ("aviTime0  = %lu\n", (RMuint32)aviTime0));		// send an initial VOL header		RMuint32 length, i;		RMint32 idx = find_free_buffer (&BPavi, 0);		ASSERT (idx >= 0);		RMuint8 *p = (RMuint8 *)get_buffer_address (&BPavi, idx);		length = BPavi.buffers_size;		if (msmpeg4v3)		{			DEBUGMSG (1, ("create a vol header (key frames only)\n"));			VOLHdrLength = MP43_DSI_Generator (VOLHdr, currentScale, currentRate, currentWidth, currentHeight);			addref_buffer (&BPavi.B[idx]);			ASSERT (i);			memcpy (p, VOLHdr, VOLHdrLength);			mpegerr = pMpegDecoder->WriteMpegVideo (p, VOLHdrLength, &BPavi.B[idx], 0, 0, 0);			ASSERT (mpegerr == MPEG_DECODER_ERROR_NO_ERROR);			if (mpegerr == MPEG_DECODER_ERROR_NO_ROOM)			{				release_buffer (&BPavi.B[idx]);			}		}		else		{			// there should always be a vol header at frame 0			pAVIDemux->GetFrame (0, p, &length);			p += 8;			RMuint8 *pVOLHdr = p;			// find the vol header			for (i=0; i<length-4; i++)			{				if ((p[0] == 0x00) && 					(p[1] == 0x00) &&					(p[2] == 0x01) &&					(p[3] == 0xb6))				{					ASSERT (pMpegDecoder);					ASSERT (i);					if (i)					{						MPEG_DECODER_ERROR mpegerr;						DEBUGMSG (1, ("sending volheader: %d bytes\n", i));						addref_buffer (&BPavi.B[idx]);						ASSERT (i);						mpegerr = pMpegDecoder->WriteMpegVideo (pVOLHdr, i, &BPavi.B[idx], 0, 0, 0);						ASSERT (mpegerr == MPEG_DECODER_ERROR_NO_ERROR);						if (mpegerr == MPEG_DECODER_ERROR_NO_ROOM)						{							release_buffer (&BPavi.B[idx]);						}					}					break;				}				p++;								}				}	}	else	{		DEBUGMSG (1, ("pAVIDemux->KeyFramesOnly (%d) failed: %d\n", (RMint32)direction, (RMint32)errorcode));		return -1;	}	return 0;}static RMuint32 avisubtitle_info (RMint32 msg, void *info, void *context){	// here is where we should print out the text on the screen	// you can do it anywhere on the screen you like, I just happen	// to put it at (24, 100)	switch (msg)	{	case AVISUBTITLE_MSG_TEXT_OUT:		DEBUGMSG (1, ((char *)info));		pMpegDecoder->RenderText ((char *)info, 0xffff00, 24, 100, 320-40, 240-100);		break;	case AVISUBTITLE_MSG_ERASE_TEXT:		DEBUGMSG (1, ("\n\n"));		pMpegDecoder->RenderText (0, 0xffff00, 24, 100, 320-40, 240-100);		break;	}	return 0;}// main entry point into the programint main (int argc, char *argv[]){	int loop_count, loop_enable = 0;	DEBUGMSG (1, ("sample avi player\n"));	if (argc < 2)	{		printf ("usage: aviplay <filename>\n");		return 0;	}	if (argc > 2)	{		loop_enable = atoi (argv[2]);		printf ("loop_enable = %d\n", loop_enable);	}	loadmodule ("/khwl.o");	loadmodule ("/irdrv.o");	loop_count = 0;#ifdef USE_FATFS_LIB	mountfatfs ();#endif	initinput ();	init_buffer_pool (&BPscan, mp43pending_buffer, 1024*128, N_MP43_SCAN_BUFFER);loop_again:	DEBUGMSG (1, ("loop_count = %d\n", loop_count));	pMpegDecoder = (MpegDecoder *) new MpegDecoder;	ASSERT (pMpegDecoder);	pMpegDecoder->Init ();	// ntsc	pMpegDecoder->SetupDisplay (1);		pMpegDecoder->Stop ();	pMpegDecoder->Pause ();	// create the avi subtitle decoder	pAVISubtitle = (AVISubtitle *)new AVISubtitle;	ASSERT (pAVISubtitle);	AVISUBTITLE_ERROR err;	AVISUBTITLE_CALLBACK_TABLE callbacktable;	callbacktable.context = 0;	callbacktable.fclose = my_fclose;	callbacktable.fopen = my_fopen;	callbacktable.fread = my_fread;	callbacktable.fseek = my_fseek2;	callbacktable.ftell = my_ftell;	callbacktable.info = avisubtitle_info;	if (pAVISubtitle)	{		RMint8 subtitlename[512];		RMint8 *ptxt;		err = pAVISubtitle->InitCallbackTable (&callbacktable);		ASSERT (err == AVISUBTITLE_ERROR_NO_ERROR);		strcpy (subtitlename, argv[1]);		ptxt = subtitlename + strlen (subtitlename);		while (*ptxt != '.')		{			ptxt--;		}		ptxt++;		strcpy (ptxt, "srt");		DEBUGMSG (1, ("SUBTITLE file: %s\n", subtitlename));		err = pAVISubtitle->Init (subtitlename);		DEBUGMSG ((err != AVISUBTITLE_ERROR_NO_ERROR), ("SUBTITLE file %s does not exist\n", subtitlename));	}	// create the avi demux	pAVIDemux = (AVIDemux *) new AVIDemux;	ASSERT (pAVIDemux);	if (pAVIDemux)	{				pMpegDecoder->RenderText (0, 0, 0, 0, 320, 240);		pMpegDecoder->RenderText ("LOADING ...", 0xffff00, 32, 100, 320-32, 240-100);		AVI_CALLBACK_TABLE callback_table;		callback_table.context = &BPavi;		// saved context information for application		callback_table.fopen = my_fopen;		callback_table.fread = my_fread;		callback_table.ftell = my_ftell;		callback_table.fseek = my_fseek;		callback_table.fclose = my_fclose;		callback_table.addref = my_addref;		callback_table.release = my_release;		callback_table.info = avi_info;		callback_table.getbuffer = avi_getAVI;		callback_table.putChunk = avi_putChunk;		callback_table.loading = avi_loading;		callback_table.gettimems = avi_gettime;		init_buffer_pool (&BPavi, avi_buffer, AVI_BUFFERSIZE, AVI_NBUFFERS);		video_stream_count = 0;		audio_stream_count = 0;		avi_stream_count = 0;		selected_audio_stream[0] = 0xff;		selected_audio_stream[1] = 0xff;		selected_audio_stream[2] = 0;		selected_audio_stream_format = 0;		pAVIDemux->Init ();		pAVIDemux->InitCallbackTable (&callback_table);		if (pAVIDemux->DemuxFile (argv[1]) != AVI_DEMUX_ERROR_NO_ERROR)		{			DEBUGMSG (1, ("pAVIDemux->DemuxFile (%s) failed\n", argv[1]));			delete pAVIDemux;			pAVIDemux = 0;			deinit_buffer_pool (&BPavi);		}			// do we support the current fourcc?		if (IsFOURCCSupported (currentFOURCC) == 0)		{			DEBUGMSG (1, ("not supported FOURCC\n"));					delete pAVIDemux;			pAVIDemux = 0;			deinit_buffer_pool (&BPavi);		}				if ((pAVIDemux == 0) && (pMP3BufferDecoder))		{			pMP3BufferDecoder->DecodeBufferEnd ();			delete pMP3BufferDecoder;			pMP3BufferDecoder = 0;			deinit_buffer_pool (&BPpcm);					}		pMpegDecoder->RenderText (0, 0, 0, 0, 320, 240);		pMpegDecoder->Stop ();		pMpegDecoder->Play ();	}	else	{		DEBUGMSG (1, ("AVIDemux object creation failed\n"));		exitinput ();		return -1;	}	if (pAVIDemux == 0)	{		exitinput ();		return -1;	}	// demux!	int input, i = 0, done = 0;	RMint64 t, stc;	if (IsFOURCCSupported (currentFOURCC) == 0)		done = 1;	// send an initial vol header if msmpeg4v3	if (msmpeg4v3 && !done)	{		MPEG_DECODER_ERROR mpegerr;		DEBUGMSG (1, ("create a vol header (start)\n"));		VOLHdrLength = MP43_DSI_Generator (VOLHdr, currentScale, currentRate, currentWidth, currentHeight);		mpegerr = pMpegDecoder->WriteMpegVideo ((RMuint8 *)VOLHdr, VOLHdrLength, 0, 0, 0, 0);		ASSERT (mpegerr == MPEG_DECODER_ERROR_NO_ERROR);		// initialize the mp43 scanning library		RMint32 err;		MP43Scanner.width = currentWidth;		MP43Scanner.height = currentHeight;		MP43Scanner.iRate = currentRate;		MP43Scanner.iScale = currentScale;		MP43Scanner.buffer = mp43scan_buffer;				err = MP43_filter_init (&MP43Scanner);		ASSERT (err == FILTER_OK);		mp43scan_status = 0;	}	RMint32 paused = 0;	RMint32 keyframesonly = 0;	RMint64 currentTime = 0;	DEBUGMSG (1, ("pAVIDemux->DemuxFile () ok, starting demux ...\n"));	while (!done)	{		if (!paused)		{			if (pAVIDemux->Schedule () == AVI_DEMUX_ERROR_FILE_DONE)			{				DEBUGMSG (1, ("AVI_DEMUX_ERROR_FILE_DONE\n"));				// actually this is not a good way to handle EOF,				// the proper way would be to wait until the stc				// has passed the last cts (if in normal play mode),				// or wait a bit if in key frame only mode				sleep (5);				break;			}		}		if (saved_input)		{			input = saved_input;			saved_input = 0;		}		else		{			input = getinput ();		}		switch (input)		{		case INPUT_STOP:			DEBUGMSG (1, ("INPUT_STOP\n"));			done = 1;			break;		case INPUT_NEXT:			DEBUGMSG (1, ("INPUT_NEXT\n"));			// skip 30 seconds forward			pMpegDecoder->GetSTC (&stc, 1);			t = (int)(stc + 30);			if (KeyFramesOnly)				t = KeyFramesPosition * currentScale / currentRate;			DEBUGMSG (1, ("seek to %d seconds\n", t));			if (avi_seek ((int)t) == 0)			{				DEBUGMSG (1, ("seek succeeded\n"));								}			else			{				DEBUGMSG (1, ("seek failed\n"));			}			break;		case INPUT_PREV:			DEBUGMSG (1, ("INPUT_PREV\n"));			// skip 30 seconds forward			pMpegDecoder->GetSTC (&stc, 1);			t = (int)(stc - 30);			if (t < 0)				t = 0;			if (KeyFramesOnly)				t = KeyFramesPosition * currentScale / currentRate;			DEBUGMSG (1, ("seek to %d seconds\n", t));			if (avi_seek (t) == 0)			{				DEBUGMSG (1, ("seek succeeded\n"));			}			else			{				DEBUGMSG (1, ("seek failed\n"));			}			break;		case INPUT_FWD:			DEBUGMSG (1, ("INPUT_FWD\n"));			// > 0 means forward			if (avi_keyframesonly (1) == 0)			{				DEBUGMSG (1, ("avi_keyframesonly (1) succeeded\n"));				keyframesonly = 1;			}			else			{				DEBUGMSG (1, ("avi_keyframesonly (1) failed\n"));			}			break;		case INPUT_REV:			DEBUGMSG (1, ("INPUT_REV\n"));			// < 0 means backward			if (avi_keyframesonly (-1) == 0)			{				DEBUGMSG (1, ("avi_keyframesonly (-1) succeeded\n"));				keyframesonly = 1;			}			else			{				DEBUGMSG (1, ("avi_keyframesonly (-1) succeeded\n"));			}			break;		case INPUT_PAUSE:			DEBUGMSG (1, ("INPUT_PAUSE\n"));			pMpegDecoder->Pause ();			paused = 1;			break;		case INPUT_PLAY:			DEBUGMSG (1, ("INPUT_PLAY\n"));			if (paused)			{				pMpegDecoder->Play ();				paused = 0;			}			else			{				if (avi_keyframesonly (0) == 0)				{					DEBUGMSG (1, ("avi_keyframesonly (0) succeeded\n"));					keyframesonly = 0;				}				else				{					DEBUGMSG (1, ("avi_keyframesonly (0) failed\n"));				}			}			break;		}		if (keyframesonly == 0)		{			RMint64 t = 0;			pMpegDecoder->GetSTC (&t, 1);			if (pAVISubtitle)				pAVISubtitle->Schedule (t);			if (t != currentTime)			{				RMint8 text[64];				currentTime = t;				RMint64 hours = currentTime / 3600;				RMint64 minutes = (currentTime - hours * 3600) / 60;				RMint64 seconds = currentTime - hours*3600 - minutes*60;				pMpegDecoder->GetSTC (&t, aviTimeScale);				DEBUGMSG (1, ("time: (%d) %02d:%02d:%02d\n", (RMint32)t, (RMint32)hours, (RMint32)minutes, (RMint32)seconds));			}		}	}	if (pAVIDemux)	{		delete pAVIDemux;		pAVIDemux = 0;		deinit_buffer_pool (&BPavi);	}	if (pMP3BufferDecoder)	{		pMP3BufferDecoder->DecodeBufferEnd ();		delete pMP3BufferDecoder;		pMP3BufferDecoder = 0;		deinit_buffer_pool (&BPpcm);				}	if (pAVISubtitle)	{		delete pAVISubtitle;		pAVISubtitle = 0;	}	pMpegDecoder->Stop ();	pMpegDecoder->Exit ();	delete pMpegDecoder;	if (msmpeg4v3)	{		RMint32 err;		err = MP43_filter_exit (&MP43Scanner);		ASSERT (err == FILTER_OK);	}	loop_count++;	if (loop_enable)		goto loop_again;	deinit_buffer_pool (&BPscan);	exitinput ();	return 0;}

⌨️ 快捷键说明

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