📄 play_multiple_audio.c
字号:
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;} /* play_Payload */static RMstatus asfStop(struct asf_context *pSendContext, RMuint32 devices){ RMstatus err = RM_OK; if (devices & RM_DEVICES_STC) { RMDBGLOG((ENABLE, "STOP: stc\n"));// DCCStopDemuxTask(context->dcc_info->pDemuxTask); 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; // Jacques: not sure... audio_profile.AudioDecoderID = asf_audio_opt->AudioDecoderID; 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;}#if (TMP_FIX_MIX_WEIGHT_KEYS)static void mixer_set_weight_index(int decoder, int step){ RMDBGLOG((ENABLE, "mixer_set_weight_index, step=%d\n", step)); if (step < 0) { RMuint32 ch; RMuint32 abs_step = -step; for (ch = 0; ch < 8; ch++) (weight[decoder][ch] > abs_step) ? weight[decoder][ch] -= abs_step : 0; } else { RMuint32 ch; RMASSERT((step < 100)); for (ch = 0; ch < 8; ch++) (weight[decoder][ch] < (RMuint32)(100 - step)) ? weight[decoder][ch] += step : 100; }}static void mixer_set_weight(int decoder){ RMuint32 *sweight = weight[decoder]; RMuint32 *pMixerValue = &cmdblock.MixerValue_ch0; RMuint32 ch = 0; RMDBGLOG((ENABLE, "mixer_set_weight, decoder=%d\n", decoder)); for (ch = 0; ch < 8; ch++) { RMASSERT((sweight[ch] > 0)); RMASSERT((sweight[ch] <= 100)); *pMixerValue++ = (RMuint32)0x10000000 / (RMuint32)100 * sweight[ch] ; } RUASetProperty( pdcc_info[decoder]->pRUA, pdcc_info[decoder]->audio_decoder, RMAudioDecoderPropertyID_MixerWeight, &cmdblock, sizeof(cmdblock), 0);}#endif // TMP_FIX_MIX_WEIGHT_KEYSstatic RMstatus OpenPCMXAudioDecoderSource (struct DCC *pDCC, struct DCCAudioProfile *dcc_profile, struct DCCAudioSource **ppAudioSource){ struct AudioDecoder_DRAMSizePCMX_in_type dram_in; struct AudioDecoder_DRAMSizePCMX_out_type dram_out; struct AudioDecoder_OpenPCMX_type profile; RMuint32 audio_decoder, audio_engine; RMuint32 nb_audio_engines, nb_audio_decoders; RMuint32 temp; RMstatus err; RMuint32 tmp; /* ************************* */ RMuint32 sample_rate; struct AudioEngine_Volume_type volume; /* ************************* */ *ppAudioSource = (struct DCCAudioSource *) RMMalloc(sizeof(struct DCCAudioSource)); if (*ppAudioSource == NULL) { RMDBGLOG((ENABLE, "ERROR: could not allocate 0x%08lX bytes in system memory %lu!\n", sizeof(struct DCCAudioSource))); return RM_FATALOUTOFMEMORY; } RMMemset((void*)(*ppAudioSource), 0, sizeof(struct DCCAudioSource)); (*ppAudioSource)->pRUA = pDCC->pRUA; // Get number of audio engines and audio decoders temp = AudioEngine; err = RUAExchangeProperty(pDCC->pRUA, Enumerator, RMEnumeratorPropertyID_CategoryIDToNumberOfInstances, &temp, sizeof(temp), &nb_audio_engines, sizeof(nb_audio_engines)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "Error getting property RMEnumeratorPropertyID_CategoryIDToNumberOfInstances %s\n", RMstatusToString(err))); return err; } else { if (dcc_profile->AudioEngineID < nb_audio_engines) RMDBGLOG((ENABLE, "Number of audio engines: %d%s\n", (int) nb_audio_engines)); else { RMDBGLOG((ENABLE, "Error: audio engine index %d out of range!!! Should be < %d\n", (int) dcc_profile->AudioEngineID, (int) nb_audio_engines)); err = RM_PARAMETER_OUT_OF_RANGE; return err; } } temp = AudioDecoder; err = RUAExchangeProperty(pDCC->pRUA, Enumerator, RMEnumeratorPropertyID_CategoryIDToNumberOfInstances, &temp, sizeof(temp), &nb_audio_decoders, sizeof(nb_audio_decoders)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "Error getting property RMEnumeratorPropertyID_CategoryIDToNumberOfInstances %s\n", RMstatusToString(err))); return err; } else { if (dcc_profile->AudioDecoderID < (nb_audio_decoders / nb_audio_engines)) RMDBGLOG((ENABLE, "Number of audio decoders: %d%s\n", (int) nb_audio_decoders));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -