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

📄 play_multiple_audio.c

📁 Sample code for use on smp 863x processor.
💻 C
📖 第 1 页 / 共 5 页
字号:
			try_decode_wmapro(pSendContext, FALSE); 			RMDBGLOG((WMAPRODBG, "WMAPRO fifo too small\n")); 			  		} 		 		buf_info = (struct wmapro_buffer_info *) wr1;   		buf_info->ptr = buf;   		buf_info->size = size; 		buf_info->new_buffer = TRUE; 		buf_info->Info = Info; 		buf_info->Stream_Number = Stream_Number; 		buf_info->Media_Object_Number = Media_Object_Number; 		buf_info->fSendPTS = 1; 		RUAAcquireBuffer(pSendContext->pDMA, buf); 		RMDBGLOG((WMAPRODBG, "Insert address %p into WMAPRO fifo size(%lu), valid(%lu) pts(%llu)\n", buf, size, Info.ValidFields, Info.TimeStamp)); 		RMfifo_incr_write_ptr(pSendContext->wmapro_fifo, sizeof(struct wmapro_buffer_info)); 		 		try_decode_wmapro(pSendContext, FALSE);  	} callback_end:	/*************************************************************************************/	/* video debug stuff */	/*************************************************************************************/	if (dataType == RM_STREAM_VIDEO) {		if (Media_Object_Number_valid && (Media_Object_Number != PrevMON)) {						pSendContext->video_frame_counter++;		}		if(pSendContext->ContiguousVideoLength == 0)			pSendContext->video_time_start = get_ustime();		pSendContext->ContiguousVideoLength +=size;		if(pSendContext->ContiguousVideoLength > CONTIGUOUS_LENGHT) {			pSendContext->video_time_end = get_ustime();			//RMDBGLOG((ENABLE, "pSendContext->ContiguousVideoLength 0x%08lx = %8lldus\n", pSendContext->ContiguousVideoLength, pSendContext->video_time_end - pSendContext->video_time_start));		}		pSendContext->ContiguousAudioLength = 0;		{			RMstatus err;			err = dump_data_into_file(asf_play_opt, RMVDEMUX_VIDEO, buf, size, Presentation_Time, Presentation_Time_valid, 0);			if (RMFAILED(err)) {				RMDBGLOG((ENABLE, "Cannot dump data %d\n", err));				goto return_from_callback;			}		}	}	/* audio debug stuff */	if (dataType == RM_STREAM_AUDIO) {		if (Media_Object_Number_valid && (Media_Object_Number != PrevMON)) {			//RMDBGLOG((ENABLE, "\nFrame counter = %d, size = %d\n",(int)pSendContext->audio_frame_counter, (int)size));			//fflush(stdout);			pSendContext->audio_frame_counter++;		}		//RMDBGLOG((ENABLE, "audio = %ld\n", size)); 		if(pSendContext->ContiguousVideoLength == 0)			pSendContext->audio_time_start = get_ustime();		pSendContext->ContiguousAudioLength = 0;		pSendContext->ContiguousAudioLength +=size;		if(pSendContext->ContiguousAudioLength > CONTIGUOUS_LENGHT) {			pSendContext->audio_time_end = get_ustime();			//RMDBGLOG((ENABLE, "pSendContext->ContiguousAudioLength 0x%08lx = %8lldus\n", pSendContext->ContiguousAudioLength, pSendContext->audio_time_end - pSendContext->audio_time_start));		}		pSendContext->ContiguousVideoLength = 0;			err = dump_data_into_file(asf_play_opt, RMVDEMUX_AUDIO, buf, size, Presentation_Time, Presentation_Time_valid, 0);			if (RMFAILED(err)) {				RMDBGLOG((ENABLE, "Cannot dump data %d\n", err));				goto return_from_callback;			}	}	return; return_from_callback:	RMDBGLOG((PAYLOADDBG,"dropped ST:%02d,MON:%04d,Key:%01d,time:%05d.%03d,size:%05d,left:%05d\n",		  (int)Stream_Number,		  (int)Media_Object_Number,		  (int)Is_Key_Frame,		  (int)(Presentation_Time/1000),		  (int)(Presentation_Time%1000),		  (int)size,		  (int)bytes_left));	if ((Is_Key_Frame) && (dataType == RM_STREAM_VIDEO)) {		RMDBGLOG((SENDDBG, "dropped a keyframe! ST:%02d,MON:%04d,Key:%01d,time:%05d.%03d,size:%05d,left:%05d\n",		  (int)Stream_Number,		  (int)Media_Object_Number,		  (int)Is_Key_Frame,		  (int)(Presentation_Time/1000),		  (int)(Presentation_Time%1000),		  (int)size,		  (int)bytes_left));	}	return;}static RMstatus asfStop(struct asf_context *pSendContext, RMuint32 devices){	RMstatus err = RM_OK;		if (devices & RM_DEVICES_STC) {		RMDBGLOG((ENABLE, "STOP: stc\n"));		DCCSTCStop(pSendContext->dcc_info->pStcSource);	}	if (devices & RM_DEVICES_VIDEO) {		if (pSendContext->SendVideoData) {			RMDBGLOG((ENABLE, "STOP: video decoder\n"));			err = DCCStopVideoSource(pSendContext->dcc_info->pVideoSource, DCCStopMode_LastFrame);			if (RMFAILED(err)){				RMDBGLOG((ENABLE, "Error stopping video source %d\n", err));				return err;			}			pSendContext->video_decoder_initialized = FALSE;		}	}	if (devices & RM_DEVICES_AUDIO) {		if (pSendContext->SendAudioData) {			RMDBGLOG((ENABLE, "STOP: audio decoder\n"));			err = DCCStopAudioSource(pSendContext->dcc_info->pAudioSource);			if (RMFAILED(err)){				RMDBGLOG((ENABLE,"Error stopping audio source %d\n", err));				return err;			}			pSendContext->audio_decoder_initialized = FALSE;		}	}	if ((devices & RM_DEVICES_AUDIO) && (devices & RM_DEVICES_VIDEO)) {		pSendContext->FirstSystemTimeStamp = TRUE;	}	return err;}static RMstatus asfPlay(struct asf_context * pSendContext, RMuint32 devices, enum DCCVideoPlayCommand mode){	RMstatus err = RM_OK;		if (devices & RM_DEVICES_STC) {		RMDBGLOG((ENABLE, "PLAY: stc\n"));		DCCSTCPlay(pSendContext->dcc_info->pStcSource);	}	if (devices & RM_DEVICES_AUDIO) {		if (pSendContext->SendAudioData) {			err = initAudioDecoder(pSendContext);			if (err != RM_OK) {				RMDBGLOG((ENABLE, "error during audio init\n"));				return err;			}			RMDBGLOG((ENABLE, "PLAY: audio decoder\n"));			err = DCCPlayAudioSource(pSendContext->dcc_info->pAudioSource);			if (RMFAILED(err)) {				RMDBGLOG((ENABLE, "Cannot play video decoder %d\n", err));				return err;			}		}	}	return err;}static RMstatus readBitstream(struct asf_context *pSendContext, RMuint8 *buffer, RMuint32 *bytesRead){	RMstatus status;	RMuint64 position;	RMuint32 size, packet;	RMuint32 count;	RMuint32 buffersize;	RMuint32 alignedPacket;	buffersize = (1 << ASF_DMA_BUFFER_SIZE_LOG2);	/* The Microsoft Janus DRM requires ASF data packets to be contiguous for decryption.	 * If the file is Janus encrypted, an integer multiple of ASF data packets will be	 * read into the RUA buffer (i.e. the read size is truncated).  If the file is not	 * Janus encrypted, the entire RUA buffer will be filled. */	if (pSendContext && pSendContext->asf_packetSize && pSendContext->isContentEncrypted) {		/* In case we play the file completely sequentially, the		 * asf_packetSize is not known at the first read, since we		 * haven't parsed the stream yet, so use default size if		 * asf_packetSize == 0 */		alignedPacket = (buffersize/pSendContext->asf_packetSize)*pSendContext->asf_packetSize;		buffersize = alignedPacket;					if ((1 << ASF_DMA_BUFFER_SIZE_LOG2) < pSendContext->asf_packetSize) {				RMDBGLOG((ENABLE, "** Read Buffers too small\n"));				return RM_ERROR;		}	}	       	if (pSendContext->dcc_info->state == RM_PLAYING_TRICKMODE) {		if ((pSendContext->dcc_info->trickmode_id == RM_TRICKMODE_FWD_IFRAME) || 		    (pSendContext->dcc_info->trickmode_id == RM_TRICKMODE_RWD_IFRAME)) {			if (pSendContext->IFrameSize == 0) {				RMuint32 sizeToRead;				status = RMASFVDemuxGetNextIFrame(pSendContext->vASFDemux, &position, &size, &packet);				if (status != RM_OK)					return status;								RMSeekFile(pSendContext->f_bitstream, position, RM_FILE_SEEK_START);				pSendContext->IFrameFSMState = RMasfIFrameFSM_Init;				pSendContext->IFrameSize = size;				sizeToRead = RMmin(buffersize, size);				status = RMReadFile(pSendContext->f_bitstream, buffer, sizeToRead, &count);								pSendContext->IFrameSize -= (RMint32)count;				if (pSendContext->IFrameSize <= 0)					pSendContext->IFrameSize = 0;				RMDBGLOG((TRICKDBG, "filled buffer with %lu bytes, should read %lu, left %lu\n", 					  count, sizeToRead, pSendContext->IFrameSize));			}			else {				RMuint32 sizeToRead = RMmin(buffersize, (RMuint32)pSendContext->IFrameSize);								status = RMReadFile(pSendContext->f_bitstream, buffer, sizeToRead, &count);				pSendContext->IFrameSize -= (RMint32)count;				if (pSendContext->IFrameSize <= 0)					pSendContext->IFrameSize = 0;				RMDBGLOG((TRICKDBG, "filled buffer with %lu bytes, should read %lu, left %lu\n", 					  count, sizeToRead, pSendContext->IFrameSize));			}						}		else if (pSendContext->isAudioOnlyFile)			return RM_SKIP_DATA;		else			status = RMReadFile(pSendContext->f_bitstream, buffer, buffersize, &count);	} else {		status = RMReadFile(pSendContext->f_bitstream, buffer, buffersize, &count);	}	*bytesRead = count;	RMDBGLOG((DISABLE, "buf: %02x %02x %02x %02x %02x %02x %02x %02x \n", 		  buffer[0],		  buffer[1],		  buffer[2],		  buffer[3],		  buffer[4],		  buffer[5],		  buffer[6],		  buffer[7]));	return status;	}/** * Setup the video decoder, according to the given context * * @param pSendContext - context to use for the setup * @return RM_OK on sucess */static RMstatus setup_audio_decoder(struct asf_context *pSendContext){	struct DCCAudioProfile audio_profile;	struct DCCAudioSource *pAudioSource = NULL;	struct RUABufferPool *pDMAuncompressed;	RMstatus err;	if (pSendContext == NULL)		return RM_ERROR;	RMDBGLOG((ENABLE, "*** setup_audio_decoder ***\n"));	audio_profile.BitstreamFIFOSize = ASF_AUDIO_FIFO_SIZE; 	audio_profile.XferFIFOCount = AUDIO_XFER_FIFO_COUNT;	audio_profile.DemuxProgramID = pSendContext->DemuxProgramID;	audio_profile.AudioEngineID = asf_audio_opt->AudioEngineID;	audio_profile.AudioDecoderID = asf_audio_opt->AudioDecoderID; // Jacques: not sure...	audio_profile.STCID = pSendContext->STCID;	RMDBGLOG((ENABLE, "opening audio source\n"));	err = DCCOpenAudioDecoderSource(pSendContext->dcc_info->pDCC, &audio_profile, &pAudioSource);	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "Cannot open audio decoder %d\n", err));		return RM_ERROR;	}	pSendContext->dcc_info->pAudioSource = pAudioSource;	if (pSendContext->compressed_audio) {		RMDBGLOG((ENABLE, "opening WMAPro DMApool\n"));		err = RUAOpenPool(pSendContext->dcc_info->pRUA, 0,				AUDIO_DMA_BUFFER_COUNT, AUDIO_DMA_BUFFER_SIZE_LOG2, 				RUA_POOL_DIRECTION_SEND, &pDMAuncompressed);		if (RMFAILED(err)) {			RMDBGLOG((ENABLE, "Error: cannot open dmapool for compressed audio - %d\n", err));			return RM_ERROR;		}		pSendContext->pDMAuncompressed = pDMAuncompressed;	}		RMDBGLOG((ENABLE, "get audio decoder info\n"));	err = DCCGetAudioDecoderSourceInfo(pAudioSource, 			&(pSendContext->dcc_info->audio_decoder), 			&(pSendContext->dcc_info->audio_engine), 			&(pSendContext->dcc_info->audio_timer));	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "Error getting audio decoder source information %d\n", err));		return RM_ERROR;	}	if (pSendContext->compressed_audio) {		if(pSendContext->vDecoder == (void *)NULL) {			RMDBGLOG((ENABLE,"******** using RMF's WMAPRO decoder ********\n"));			err = RMCreateWMAProVDecoder(&(pSendContext->vDecoder));			if (err != RM_OK) {				RMDBGLOG((ENABLE,"error: cant create wmaproVdecoder!\n"));				return RM_ERROR;			}						err = RMWMAProVDecoderOpen(pSendContext->vDecoder);			if (err != RM_OK) {				RMDBGLOG((ENABLE,"error: cant open wmaproVdecoder!\n"));				return RM_ERROR;			}		}	}	return RM_OK;}	//----------WMAstruct struct_context {	struct RUABufferPool *pDMA;	struct RUABufferPool *pPCMXDMA[9];	RMbool FirstSystemTimeStamp;	RMuint32 FirstPTS;	struct dcc_context *dcc_info;	RMfile		f_bitstream;	RMfile		f_pcmxbitstream[9];  RMuint8   pcmx_mode[9];  RMuint8   pcmx_bps[9];  RMuint8   pcmx_endian[9];  RMint32   pcmx_gain[9];  RMreal   pcmx_panx[9];  RMreal   pcmx_pany[9];  RMbool    nodata[9];  RMuint32  PCMXfcnt[9];  	RMint64		fileSize;	RMbool		audio_decoder_initialized;	RMbool		trickMode;	RMuint32	audio_vop_tir;	RMuint64	Duration;	RMuint64	lastSTC;	RMuint32	id;	RMuint32	Ntimes;	RMuint8		*buf;	RMbool		buffer_used;	RMuint32	byte_counter;	RMuint32	file_offset;	RMstatus	status;	RMuint32	cmd;	RMuint32	cmd_ex;};/////////////////////////////Support Multiple Audio Decoder PlayBackRMuint32 task_count = 0;static struct struct_context	context[MAX_TASK_COUNT];  //Task list similar to ply_mul_videostatic struct dcc_context	    dcc_info[MAX_TASK_COUNT] = { {0, }, {0, } };

⌨️ 快捷键说明

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