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

📄 play_vdemux.c

📁 Sample code for use on smp 863x processor.
💻 C
📖 第 1 页 / 共 5 页
字号:
		Stop(&context, RM_DEVICES_AUDIO | RM_DEVICES_VIDEO | RM_DEVICES_STC, DCCStopMode_LastFrame); \		context.isIFrameMode = FALSE;				\		context.FirstSystemTimeStamp = TRUE;			\		context.ignoreCallback = FALSE;				\		if (release) {						\			if (context.repack_sample) {			\				RMDBGLOG((ENABLE, "release audio buffers\n")); \				release_repacked_buffers(&context, REPACK_ALL); \			}						\			else  {						\				RMDBGLOG((ENABLE, "release a buffer\n")); \				RUAReleaseBuffer(pDMA, buf);		\				buf = NULL;				\			}						\		}							\		goto mainloop_no_seek;					\	}								\	if ((actions.cmd == RM_DUALMODE_CHANGE) && (!actions.cmdProcessed)) { \		RMDBGLOG((ENABLE, "got dualmode change\n"));		\		fprintf(stderr, "Changing DualMode to :");		\		switch(audio_opt->OutputDualMode) {								\		case DualMode_LeftMono:										\			fprintf(stderr, " RightMono\n");							\			audio_opt->OutputDualMode = DualMode_RightMono;						\			break;											\		case DualMode_RightMono:									\			fprintf(stderr, " MixMono\n");								\			audio_opt->OutputDualMode = DualMode_MixMono;						\			break;											\		case DualMode_MixMono:										\			fprintf(stderr, " Stereo\n");								\			audio_opt->OutputDualMode = DualMode_Stereo;						\			break;											\		case DualMode_Stereo:										\			fprintf(stderr, " LeftMono\n");								\			audio_opt->OutputDualMode = DualMode_LeftMono;						\			break;											\		default:											\			fprintf(stderr, " Unknown dual mode\n");						\			break;											\		}												\		err = apply_audio_decoder_options_onthefly(&dcc_info,audio_opt);				\		if (RMFAILED(err)) {										\			fprintf(stderr, "Error applying audio decoder options on the fly %d\n", err);		\		}												\	}													\} while (0)#define PROCESS_KEY_INSIDE_FUNCTION()					\do	{								\	RMstatus err;							\	enum RM_PSM_State PlaybackStatus;				\									\	RMDBGLOG((KEYDBG, "processkey_inside_function\n"));		\	err = process_command(pSendContext->PSMcontext, &(pSendContext->dcc_info), &actions); \	if (RMFAILED(err)) {						\		RMDBGLOG((ENABLE, "Error while processing key %d\n", err)); \		goto return_from_callback;				\	}								\	PlaybackStatus = RM_PSM_GetState(pSendContext->PSMcontext, &(pSendContext->dcc_info)); \	if (actions.toDoActions & RM_PSM_RESYNC_TIMER) {		\		RMDBGLOG((ENABLE, "resyncTimer\n"));			\		SyncTimerWithDecoderPTS(pSendContext);			\		actions.toDoActions &= ~RM_PSM_RESYNC_TIMER;		\	}								\	if ((actions.cmd == RM_QUIT) && (!actions.cmdProcessed)) {	\		RMDBGLOG((ENABLE, "quit during callback\n"));		\		pSendContext->ignoreCallback = TRUE;			\		if (manutest == TRUE)                                   \		    manutest_res = RM_QUIT;                             \		goto return_from_callback;				\	} 								\	if ((manutest == TRUE) && (actions.cmd == RM_MANU_QUIT_OK) && (!actions.cmdProcessed)) {	\		RMDBGLOG((ENABLE, "quit during callback\n"));		\		pSendContext->ignoreCallback = TRUE;			\		if (manutest == TRUE)                                   \		    manutest_res = RM_MANU_QUIT_OK;                     \		goto return_from_callback;				\	} 								\	if ((PlaybackStatus == RM_PSM_Stopped) && (actions.cmdProcessed)) { \		RMDBGLOG((ENABLE, "stop during callback\n"));		\		pSendContext->ignoreCallback = TRUE;			\		goto return_from_callback;				\	}								\	if ((actions.cmd == RM_STOP_SEEK_ZERO) && (!actions.cmdProcessed)) { \		RMDBGLOG((ENABLE, "seekzero during callback\n"));	\		pSendContext->ignoreCallback = TRUE;			\		goto return_from_callback;				\	}								\	if ((actions.cmd == RM_SEEK) && (!actions.cmdProcessed)){	\		RMDBGLOG((ENABLE, "seek during callback\n"));		\		pSendContext->ignoreCallback = TRUE;			\		goto return_from_callback;				\	}								\	if (((PlaybackStatus == RM_PSM_IForward) ||			\	    (PlaybackStatus == RM_PSM_IRewind)) && (actions.cmdProcessed)) {	\		RMDBGLOG((ENABLE, "iframe trick during callback\n"));	\		pSendContext->ignoreCallback = TRUE;			\		goto return_from_callback;				\	}								\	if (((PlaybackStatus == RM_PSM_Slow) ||		\	     (PlaybackStatus == RM_PSM_Fast)) && (actions.cmdProcessed)) { \		RMDBGLOG((ENABLE,"trickmodes during callback\n"));	\		pSendContext->isTrickMode = TRUE;			\		pSendContext->ignoreCallback = FALSE;			\	}								\} while(0)static RMstatus Stop(struct demux_context * pSendContext, RMuint32 devices, enum DCCStopMode mode){	RMstatus err = RM_OK;	struct dcc_context *dcc_info = pSendContext->dcc_info;		if (devices & RM_DEVICES_VIDEO) {		if (pSendContext->dcc_info->pVideoSource) {			RMDBGLOG((ENABLE, "STOP: video decoder\n"));			err = DCCStopVideoSource(dcc_info->pVideoSource, mode);			if (RMFAILED(err)){				RMDBGLOG((ENABLE, "Error stopping video source %d\n", err));				return err;			}			pSendContext->initVideo = TRUE;		}	}	if (devices & RM_DEVICES_AUDIO) {		if (pSendContext->dcc_info->pAudioSource) {			RMDBGLOG((ENABLE, "STOP: audio decoder\n"));			err = DCCStopAudioSource(dcc_info->pAudioSource);			if (RMFAILED(err)){				RMDBGLOG((ENABLE,"Error stopping audio source %d\n", err));				return err;			}		}	}	if ((devices & RM_DEVICES_AUDIO) && (devices & RM_DEVICES_VIDEO)) {		pSendContext->FirstSystemTimeStamp = TRUE;	}	if (devices & RM_DEVICES_STC) {		RMDBGLOG((ENABLE, "STOP: stc\n"));		DCCSTCStop(dcc_info->pStcSource);	}	return err;}static RMstatus Play(struct demux_context * pSendContext, RMuint32 devices, enum DCCVideoPlayCommand mode){	RMstatus err = RM_OK;	struct dcc_context *dcc_info = pSendContext->dcc_info;		if (devices & RM_DEVICES_STC) {		RMDBGLOG((ENABLE, "PLAY: stc\n"));		DCCSTCPlay(dcc_info->pStcSource);	}	if (devices & RM_DEVICES_VIDEO) {		if (pSendContext->dcc_info->pVideoSource) {			if (pSendContext->initVideo) {				RMbool keep_sequence = TRUE;				RMDBGLOG((ENABLE, "PLAY: initDecoder\n"));				err = RUASetProperty(pSendContext->dcc_info->pRUA, pSendContext->dcc_info->video_decoder, RMVideoDecoderPropertyID_StorePreviousVideoHeader, &keep_sequence, sizeof(keep_sequence), 0);				if (RMFAILED(err)) {					RMDBGLOG((ENABLE, "Error setting video decoder to keep sequence header on Stop %d\n", err));					return err;				}				pSendContext->initVideo = FALSE;			}			RMDBGLOG((ENABLE, "PLAY: video decoder %s\n", (mode == DCCVideoPlayIFrame ? "(iframe)":"")));			err = DCCPlayVideoSource(pSendContext->dcc_info->pVideoSource, mode);			if (RMFAILED(err)) {				RMDBGLOG((ENABLE, "Cannot play video decoder %d\n", err));				return err;			}		}	}	if (devices & RM_DEVICES_AUDIO) {		if (pSendContext->dcc_info->pAudioSource) {			RMDBGLOG((ENABLE, "PLAY: audio decoder\n"));			err = DCCPlayAudioSource(dcc_info->pAudioSource);			if (RMFAILED(err)) {				RMDBGLOG((ENABLE, "Cannot play video decoder %d\n", err));				return err;			}		}	}	return err;}// used for prebufferingstatic RMstatus Pause(struct demux_context * pSendContext, RMuint32 devices){	RMstatus err = RM_OK;		if (devices & RM_DEVICES_VIDEO) {		if (pSendContext->dcc_info->pVideoSource) {			RMDBGLOG((ENABLE, "PAUSE: video decoder\n"));			err = DCCPauseVideoSource(pSendContext->dcc_info->pVideoSource);			if (RMFAILED(err)) {				RMDBGLOG((ENABLE, "Cannot pause video decoder %d\n", err));				return err;			}		}	}	if (devices & RM_DEVICES_AUDIO) {		if (pSendContext->dcc_info->pAudioSource) {			RMDBGLOG((ENABLE, "PAUSE: audio decoder\n"));			err = DCCPauseAudioSource(pSendContext->dcc_info->pAudioSource);			if (RMFAILED(err)) {				RMDBGLOG((ENABLE, "Cannot pause video decoder %d\n", err));				return err;			}		}	}	if (devices & RM_DEVICES_STC) {		RMDBGLOG((ENABLE, "PAUSE: stc\n"));		DCCSTCStop(pSendContext->dcc_info->pStcSource);	}	return err;}static RMstatus SyncTimerWithDecoderPTS(struct demux_context *pSendContext){	RMuint64 videoPTS;	RMuint64 CurrentSTC;	RMstatus err = RM_OK;	RMuint32 timeScale;	/* we have to obtain the timeScale because in mpeg4 elementary 	   streams, the time scale is not guaranteed to be 90KHz 	*/	DCCSTCGetTimeResolution(pSendContext->dcc_info->pStcSource, DCC_Video, &timeScale);	DCCSTCGetTime(pSendContext->dcc_info->pStcSource, &CurrentSTC, timeScale);	err = RUAGetProperty(pSendContext->pRUA, pSendContext->dcc_info->SurfaceID, RMGenericPropertyID_CurrentDisplayPTS, &videoPTS, sizeof(videoPTS));	if (err != RM_OK) {		RMDBGLOG((ENABLE, "error %d while getting CurrentDisplayPTS\n", err));		return err;	}	/* for MPEG1/2, timeScale 90000, videoPTS unit is 45000 always,	   for MPEG4, timeScale is the same than videoPTS unit.	   Note however, that we're just checking the value of timeScale, so	   if we're in MPEG4 and timeScale 90000, this wont work. Also note that	   this happens with elementary streams which are to be handled by	   play_video not play_demux. 	*/	if (timeScale == 90000)		videoPTS *= 2;		RMDBGLOG((ENABLE, ">> resync timer (%llu) with videoDecoder current PTS (%llu), unit %lu\n", CurrentSTC, videoPTS, timeScale));	DCCSTCSetTime(pSendContext->dcc_info->pStcSource, videoPTS, timeScale);#ifdef PTS_DISCONTINUITY_DETECTION	pSendContext->fakePrevPts = TRUE;#endif	return RM_OK;	}static RMbool check_prebuf_state(struct demux_context *pSendContext, RMuint32 buffersize){	RMbool quit_prebuf;	enum RM_PSM_State PlaybackStatus = RM_PSM_GetState(pSendContext->PSMcontext, &(pSendContext->dcc_info));		if (PlaybackStatus != RM_PSM_Prebuffering)		return FALSE;	/* if fail in getbuffer/senddata force quitting prebuffering state */	quit_prebuf = ((buffersize == 0) || ((play_opt->prebuf_max > 0) && (pSendContext->prebufferedBytes >= play_opt->prebuf_max))) ? TRUE : FALSE;	pSendContext->prebufferedBytes += buffersize;//fprintf( stderr, "0x%lx \n", (long unsigned int)(pSendContext->prebufferedBytes) );			if (quit_prebuf) {		RMDBGLOG((ENABLE, "exit prebuffering state, enter play state (bufsize %lu, prebuffered %lu)\n", buffersize, pSendContext->prebufferedBytes));		if (manutest != TRUE)			fprintf(stderr, "now playing\n");		RM_PSM_SetState(pSendContext->PSMcontext, &(pSendContext->dcc_info), RM_PSM_Playing);		DCCSTCSetTime(pSendContext->dcc_info->pStcSource, pSendContext->realFirstPTS, 90000);		Play(pSendContext, RM_DEVICES_STC | RM_DEVICES_VIDEO | RM_DEVICES_AUDIO, DCCVideoPlayFwd);		pSendContext->prebufferedBytes = 0;		return TRUE;	}	return FALSE;}static void flush_repacked_sample(void *context){	struct demux_context *pSendContext = (struct demux_context *) context;	RMuint8 *send_buffer = (RMuint8 *) NULL;	RMuint32 send_length = 0;	RMuint32 decoder;	struct emhwlib_info Info;	/* flush video data */	if ( ! play_opt->send_video)		goto flush_audio;	if (pSendContext->video_repack_buf == NULL)		goto flush_audio;	decoder = pSendContext->dcc_info->video_decoder;	send_buffer = pSendContext->video_repack_buf + pSendContext->video_repack_offset;	send_length = pSendContext->video_repack_size;	Info.ValidFields = (pSendContext->video_repack_pts_valid) ? TIME_STAMP_INFO : 0;	Info.TimeStamp = pSendContext->video_repack_pts;	while (RUASendData(pSendContext->pRUA, decoder, pSendContext->pDMA, send_buffer, send_length, (void*)&Info, sizeof(Info)) != RM_OK) {		struct RUAEvent e;		PROCESS_KEY_INSIDE_FUNCTION();		e.ModuleID = decoder;		e.Mask = RUAEVENT_XFER_FIFO_READY;		RUAWaitForMultipleEvents(pSendContext->pRUA, &e, 1, SENDDATA_TIMEOUT_US, NULL);	}	RUAReleaseBuffer(pSendContext->pDMA, send_buffer);		 flush_audio:	/* flush audio data */	if ( ! play_opt->send_audio)		goto flush_spu;	if (pSendContext->audio_repack_buf == NULL)		goto flush_spu;	if (pSendContext->isTrickMode)		goto flush_spu;		decoder = pSendContext->dcc_info->audio_decoder;	send_buffer = pSendContext->audio_repack_buf + pSendContext->audio_repack_offset;	send_length = pSendContext->audio_repack_size;	Info.ValidFields = (pSendContext->audio_repack_pts_valid) ? TIME_STAMP_INFO : 0;	Info.TimeStamp = pSendContext->audio_repack_pts;	while (RUASendData(pSendContext->pRUA, decoder, pSendContext->pDMA, send_buffer, send_length, (void*)&Info, sizeof(Info)) != RM_OK) {		struct RUAEvent e;				PROCESS_KEY_INSIDE_FUNCTION();		e.ModuleID = decoder;		e.Mask = RUAEVENT_XFER_FIFO_READY;		RUAWaitForMultipleEvents(pSendContext->pRUA, &e, 1, SENDDATA_TIMEOUT_US, NULL);	}	RUAReleaseBuffer(pSendContext->pDMA, send_buffer);	 flush_spu:	/* flush spu data */	if ( ! play_opt->send_spu)		return;#ifdef	ENABLE_SPU_OP	if (! pSendContext->enable_spu) {		return;	}#else	return;#endif	if (pSendContext->spu_repack_buf == NULL)		return;	decoder = pSendContext->dcc_info->spu_decoder;	send_buffer = pSendContext->spu_repack_buf + pSendContext->spu_repack_offset;	send_length = pSendContext->spu_repack_size;	Info.ValidFields = (pSendContext->spu_repack_pts_valid) ? TIME_STAMP_INFO : 0;	Info.TimeStamp = pSendContext->spu_repack_pts;

⌨️ 快捷键说明

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