📄 asfdemux_callback.c
字号:
apply_dvi_hdmi_audio_options(context->dcc_info, &(context->audio_opt[i]), 0, FALSE, FALSE, FALSE); }#ifndef WITH_MONO if (! context->disp_opt->configure_outports) apply_hdcp(context->dcc_info, context->disp_opt);#endif } #endif context->audio_decoder_initialized = TRUE; return RM_OK;}static RMbool SwitchAudio(struct asf_context *pSendContext, RMuint32 Media_Object_Number){ RMDBGLOG((ENABLE, "got audio stream change command\n")); pSendContext->dcc_info->state = RM_PLAYING; if ((pSendContext->dcc_info->selectAudioStream > (RMint32)pSendContext->audioStreams) || (pSendContext->dcc_info->selectAudioStream == 0) || (pSendContext->audioStreams <= 1) || (pSendContext->dcc_info->selectAudioStream == (RMint32)pSendContext->audio_stream_index)) { RMDBGLOG((ENABLE, "audio stream change ignored (total audioStreams %lu, selected %ld, current %lu)\n", pSendContext->audioStreams, pSendContext->dcc_info->selectAudioStream, pSendContext->audio_stream_index)); return FALSE; } asf_Stop(pSendContext, RM_DEVICES_AUDIO); if (pSendContext->isWMAPRO) { if (pSendContext->vDecoder != NULL) { RMDBGLOG((ENABLE, "close wmapro decoder\n")); RMWMAProVDecoderClose(pSendContext->vDecoder); RMDBGLOG((ENABLE, "open wmapro decoder\n")); RMWMAProVDecoderOpen(pSendContext->vDecoder); } else RMDBGLOG((ENABLE, "no wmapro decoder created!\n")); } pSendContext->dcc_info->state = RM_PLAYING; pSendContext->audio_decoder_initialized = FALSE; pSendContext->prev_audio_media_object_number = Media_Object_Number; RMDBGLOG((ENABLE, "total audio streams %lu\n", pSendContext->audioStreams)); if (pSendContext->dcc_info->selectAudioStream == -1) { RMuint32 i; for (i = 0; i < pSendContext->audioStreams ; i++) { if (pSendContext->audioStreamTable[i] != (RMuint32) pSendContext->audio_stream_index) break; } RMDBGLOG((ENABLE, "current stream %lu, switch to %lu\n", pSendContext->audio_stream_index, pSendContext->audioStreamTable[i])); pSendContext->audio_stream_index = pSendContext->audioStreamTable[i]; } else { RMDBGLOG((ENABLE, "current stream %lu, switch to %lu\n", pSendContext->audio_stream_index, pSendContext->dcc_info->selectAudioStream)); pSendContext->audio_stream_index = pSendContext->dcc_info->selectAudioStream; } if (RM_PSM_GetState(pSendContext->PSMcontext, &(pSendContext->dcc_info)) != RM_PSM_Stopped) asf_Play(pSendContext, RM_DEVICES_AUDIO, 0); return TRUE;}static void play_Payload2(void *context, unsigned char Stream_Number, unsigned char *buf, unsigned long size, unsigned long bytes_left, unsigned char Is_Key_Frame, unsigned long Media_Object_Number, unsigned char Media_Object_Number_valid, unsigned long Presentation_Time, unsigned char Presentation_Time_valid, unsigned long Offset_Into_Media_Object){ struct asf_context *pSendContext = (struct asf_context *) context; struct emhwlib_info Info = {0,}; struct emhwlib_info *pInfo = NULL; RMuint32 size_info = 0; //struct RUABufferPool *pDMA_audio; RMint32 diff; #define DELTA_PTS 100 // 1 sec #define CONTIGUOUS_LENGHT 0x100000 // 1 MB/* RMuint32 e = 0;*/ RMbool SetPTS = FALSE; RMbool SendPTS = FALSE; RMbool SendData = FALSE; RMuint32 PrevMON = 0; RMuint32 decoder = 0; RMuint8 dataType=RM_STREAM_AUDIO; //RMbool ptsAlreadyScaled = FALSE; // dummy init RMbool *seeking = &(pSendContext->SeekVideo); RMuint32 *previousMON = &(pSendContext->PrevVideoMON); enum RM_PSM_State PlaybackStatus = RM_PSM_GetState(pSendContext->PSMcontext, &(pSendContext->dcc_info)); RMuint32 dumpedFrameSize = 0; if (Stream_Number == pSendContext->video_stream_index) dataType = RM_STREAM_VIDEO; else if (Stream_Number == pSendContext->audio_stream_index) dataType = RM_STREAM_AUDIO; else goto return_from_callback; /* #### Begin CARDEA code #### */ /** Add physical buffer address to cardea interface **/ /** Flush buffer from cache before passing to cardealib **/ if ( (pSendContext->cardea_context != NULL ) && (should_decrypt(pSendContext->cardea_context))) { RMuint32 buf_phys; RMstatus status; status = RUAGetPhysicalAddress(pSendContext->pDMA, buf, size, &buf_phys); if ( RMFAILED(status)) { fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); RMDBGLOG((ENABLE,"Error getting CARDEA data buffer physical addr\n")); goto return_from_callback; } status = RUACleanCache( pSendContext->pDMA, buf, size ); if ( RMFAILED(status)) { fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); RMDBGLOG((ENABLE,"Error flusing CARDEA data buffer from cache\n")); goto return_from_callback; } status = RUAInvalidateCache( pSendContext->pDMA, buf, size ); if ( RMFAILED(status)) { fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); RMDBGLOG((ENABLE,"Error flusing CARDEA data buffer from cache\n")); goto return_from_callback; }#if (EM86XX_CHIP == EM86XX_CHIPID_TANGO2) status = decrypt_cardea_sample(pSendContext->cardea_context, Stream_Number, Media_Object_Number, buf_phys, buf, size);#else status = decrypt_cardea_sample(pSendContext->cardea_context, Stream_Number, Media_Object_Number, buf, size);#endif if (RMFAILED(status)) { fprintf( stderr, "%s:%d\n", __FILE__, __LINE__ ); RMDBGLOG((ENABLE,"Error decrypting CARDEA data\n")); goto return_from_callback; } } /* #### End CARDEA code #### */ if ((!pSendContext->VideoStreamFound) && (pSendContext->SendVideoData)) { RMDBGLOG((ENABLE, ">> no video stream found, disable video\n")); pSendContext->SendVideoData = FALSE; if (pSendContext->linear_playback) { RMDBGLOG((ENABLE, "seek not supported, disable trickmodes\n")); pSendContext->dcc_info->RM_PSM_commands &= ~RM_PSM_ENABLE_SPEED; pSendContext->dcc_info->RM_PSM_commands &= ~RM_PSM_ENABLE_FASTER; pSendContext->dcc_info->RM_PSM_commands &= ~RM_PSM_ENABLE_SLOWER; } } if ((!pSendContext->AudioStreamFound) && (pSendContext->SendAudioData)) { RMDBGLOG((ENABLE, ">> no audio stream found, disable audio\n")); pSendContext->SendAudioData = FALSE; } if (pSendContext->drmError != 0) { RMDBGLOG((ENABLE, "there was a decryption error, callback ignored\n")); goto return_from_callback; } if ((pSendContext->isContentEncrypted) && (bytes_left != 0)) RMDBGLOG((ENABLE, "non aligned read, offset %ld!\n", bytes_left)); RMDBGLOG((PAYLOADDBG,"ST:%02d,MON:%04d, (valid %ld), Key:%01d,time:%05d.%03d,(valid %ld), size:%05d, left:%05d, offset:%05d \n", (int)Stream_Number, (int)Media_Object_Number, (int)Media_Object_Number_valid, (int)Is_Key_Frame, (int)(Presentation_Time/1000), (int)(Presentation_Time%1000), (int)Presentation_Time_valid, (int)size, (int)bytes_left, (int)Offset_Into_Media_Object)); if (Stream_Number == pSendContext->video_stream_index) dataType = RM_STREAM_VIDEO; else if (Stream_Number == pSendContext->audio_stream_index) dataType = RM_STREAM_AUDIO; else goto return_from_callback; if (pSendContext->ignoreCallback) { if ((pSendContext->actions.cmd == RM_QUIT) && (!pSendContext->actions.cmdProcessed)) { RMDBGLOG((ENABLE, "callback called when 'quit' command was issued\n")); goto return_from_callback; } if ((PlaybackStatus == RM_PSM_Stopped) && (pSendContext->actions.cmdProcessed)) { RMDBGLOG((ENABLE, "callback called when 'stop' command was issued\n")); goto return_from_callback; } if ((pSendContext->actions.cmd == RM_STOP_SEEK_ZERO) && (!pSendContext->actions.cmdProcessed)) { RMDBGLOG((ENABLE, "callback called when 'seekzero' command was issued\n")); goto return_from_callback; } if (((PlaybackStatus == RM_PSM_IForward) || (PlaybackStatus == RM_PSM_IRewind)) && (pSendContext->actions.cmdProcessed)) { RMDBGLOG((ENABLE, "callback called when 'iframe' command was issued\n")); goto return_from_callback; } if ((pSendContext->actions.cmd == RM_SEEK) && (!pSendContext->actions.cmdProcessed)) { RMDBGLOG((ENABLE, "callback called when 'seek' command was issued\n")); goto return_from_callback; } if ((PlaybackStatus != RM_PSM_Playing) && (PlaybackStatus != RM_PSM_Paused) && (dataType == RM_STREAM_AUDIO)) { RMDBGLOG((ENABLE, "audio callback when trickmodes were initiated, skip payload\n")); goto return_from_callback; } if ((PlaybackStatus != RM_PSM_Playing) && (dataType == RM_STREAM_VIDEO)) { RMDBGLOG((ENABLE, "video callback when trickmodes were initiated, send payload\n")); goto send_payload; } // we should not get to this point under any circumstances RMDBGLOG((ENABLE, "********** ignoring Callback!! *********\n")); RMDBGLOG((ENABLE, "playstat %lu, cmd %lu, cmdprocessed %lu\n", PlaybackStatus, pSendContext->actions.cmd, pSendContext->actions.cmdProcessed)); goto return_from_callback; } send_payload: // Decrypt packet, if necessary if (pSendContext->isContentEncrypted) { if ((pSendContext->drmError = WMDRM_decrypt_packet(buf, size)) != 0) { RMASFVDemuxSetDRMError(pSendContext->vASFDemux, pSendContext->drmError); fprintf(stderr, "DECRYPTION FAILED\n"); goto return_from_callback; } } /* adjust PTS if necessary */ if ((pSendContext->PrerollSET) && (pSendContext->Preroll)) { RMDBGLOG((DISABLE, "pts %llu, adjusted pts %llu\n", (RMuint64)Presentation_Time, (RMuint64)Presentation_Time - pSendContext->Preroll)); if ((RMuint32) pSendContext->Preroll > Presentation_Time) { RMDBGLOG((ENABLE, "Skipping packets with negative PTS\n")); goto return_from_callback; } else Presentation_Time -= (RMuint32)pSendContext->Preroll; } /* wait for first IFrame, some streams dont start with a IFrame!! */ if ((!pSendContext->firstIFrame) && (dataType == RM_STREAM_VIDEO)) { if ((Is_Key_Frame) && (Offset_Into_Media_Object == 0)) { fprintf(stderr, ">> first IFrame found, start sending video. MON(%lu), Stream(%lu)\n", (RMuint32)Media_Object_Number, (RMuint32)Stream_Number); pSendContext->firstIFrame = TRUE; } else { fprintf(stderr, "waiting for first IFrame, skipping MON(%lu) Stream(%lu) \n", (RMuint32)Media_Object_Number, (RMuint32)Stream_Number); goto return_from_callback; } } /* accurate audio seek, required for WMA FFWD trickmode */ if (dataType == RM_STREAM_AUDIO) { if (pSendContext->accurateAudioSeekTo > (RMuint64)Presentation_Time) { RMDBGLOG((ENABLE, "skipping audio %lu < %llu\n", Presentation_Time, pSendContext->accurateAudioSeekTo)); goto return_from_callback; } else if (pSendContext->accurateAudioSeekTo != 0) { RMDBGLOG((ENABLE, "start sending audio %lu\n", Presentation_Time)); pSendContext->accurateAudioSeekTo = 0; } } switch (dataType) { case RM_STREAM_VIDEO: if (!pSendContext->SendVideoData) goto return_from_callback; SendPTS = pSendContext->SendVideoPts; PrevMON = pSendContext->prev_video_media_object_number; pSendContext->VideoByteCounter += size; pSendContext->prev_video_media_object_number = Media_Object_Number; decoder = pSendContext->dcc_info->video_decoder; SendData = TRUE; seeking = &(pSendContext->SeekVideo); previousMON = &(pSendContext->PrevVideoMON);#ifdef CHECK_BUFFER_4_VIDEO { RMint32 avpts_diff; pSendContext->video_pts = Presentation_Time; avpts_diff = (RMint32)pSendContext->video_pts - (RMint32)pSendContext->audio_pts; if((RMuint32)abs(avpts_diff) > pSendContext->max_avpts_diff && pSendContext->audio_pts) { pSendContext->max_avpts_diff = abs(avpts_diff); printf("Max_AVPTS_DIFF = %ld\n", avpts_diff); } }#endif break; case RM_STREAM_AUDIO: if (!pSendContext->audio_parameters[pSendContext->audio_stream_index].enabled) goto return_from_callback; SendPTS = pSendContext->SendAudioPts; PrevMON = pSendContext->prev_audio_media_object_number; decoder = 0; //pSendContext->dcc_info->audio_decoder; if (!pSendContext->isWMAPRO) pSendContext->AudioByteCounter += size; pSendContext->prev_audio_media_object_number = Media_Object_Number; Is_Key_Frame = 1; /* audio payload doesnt set the keyframe flag, so we must force it to one, see "if (*seeking)" below */ seeking = &(pSendContext->SeekAudio); previousMON = &(pSendContext->PrevAudioMON); if (((PlaybackStatus == RM_PSM_Playing) || (PlaybackStatus == RM_PSM_Paused) || (PlaybackStatus == RM_PSM_Prebuffering) || (pSendContext->sendAudioTrickmode)) && (!pSendContext->isWMAPRO)) SendData = TRUE; else SendData = FALSE; #ifdef CHECK_BUFFER_4_VIDEO { RMint32 avpts_diff; pSendContext->audio_pts = Presentation_Time; avpts_diff = (RMint32)pSendContext->video_pts - (RMint32)pSendContext->audio_pts; if((RMuint32)abs(avpts_diff) > pSendContext->max_avpts_diff && pSendContext->video_pts) { pSendContext->max_avpts_diff = abs(avpts_diff); printf("Max_AVPTS_DIFF = %ld\n", avpts_diff); } }#endif if (PlaybackStatus == RM_PSM_Playing) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -