?? play_video_checksum.c
字號:
/* * * Copyright (c) Sigma Designs, Inc. 2002-2006. All rights reserved. * *//** @file play_video_checksum.c @brief Application to calculate checksum of frames decoded from video decoder. @author Julien Soulier, Michael Uman @ingroup dccsamplecode*/#include "sample_os.h"//#define SEND_IBC#define ALLOW_OS_CODE 1#include <libgen.h>#include "../dcc/include/dcc.h"#include "../rmlibcw/include/rmfile.h"#include "common.h"#include "bcc.h"#include "checksum.h"#define COMMON_TIMEOUT_US (TIMEOUT_10MS)#define DMA_BUFFER_SIZE_LOG2 15#define DMA_BUFFER_COUNT 32#define REPACK_SIZE (4096)#define VIDEO_FIFO_SIZE (1024*1024)#define XFER_FIFO_COUNT (1024) // 32#define KEYFLAGS (SET_KEY_DISPLAY | SET_KEY_PLAYBACK | SET_KEY_DEBUG)#define ALLOW_OS_CODE 1#define MAXHEADERSIZE 4095#define RM_DEVICES_STC 0x1#define RM_DEVICES_VIDEO 0x2#define DEBUG ENABLE#define START_IN_IFRAME_MODE 0#ifdef SEND_IBC#define HARDCODE_BYTECOUNT 0x100000#endif#if 0#define SENDDBG ENABLE#define CRCDBG ENABLE#else#define SENDDBG DISABLE#define CRCDBG DISABLE#endif#define ENABLE_MONITOR 0// CHECKSUM OPTIONS#define DO_SAVE 1#define DO_CRC32 1//#define DO_DUMP 1#define WAIT_FOR_KEY 1#define DO_LINEAR_BUFFER 1#define USE_WAITEOS 1#define DO_CAPTURE 1//#define INIT_DISPLAY_CONSUMER 1#define SAVEPATH "SAVEYUV"//#define HANDLE_DISPLAY_STATUS 1/* 0 the decoder will remember the seqHeader, 1 we must store it locally and resend it (trickmodes not supported) */#define STORE_SEQ_HEADER_LOCALLY 0 #ifdef USE_WAITEOSstatic RMuint32 NTimes = 0;#endifstatic struct playback_cmdline *play_opt;static struct video_cmdline *video_opt;static struct display_cmdline *disp_opt;static RMascii crcLogFilename[1024];struct video_context { struct RUABufferPool *pDMA; RMbool FirstSystemTimeStamp; RMuint32 FirstPTS; struct dcc_context *dcc_info; struct RM_PSM_Context *PSMcontext; RMfile f_bitstream; RMint64 fileSize; RMbool video_decoder_initialized; RMbool initVideo; RMbool trickMode; RMbool iframeMode; RMbool ResyncTimer; RMuint64 lastSTC; RMuint64 lastVideoPTS; RMuint64 lastDecoded; RMbool highSpeedIFrameMode; RMuint32 highSpeedIFrameSpeed; RMbool bcc_enabled; struct bcc *pbcc; RMuint32 prebuf_level; RMuint32 byte_counter; RMbool monitor; RMuint32 bitrate; RMuint64 meanBitrate; RMuint32 meanCount; RMuint64 last_video_pts;};#ifdef DO_CAPTUREint get_picture(struct dcc_context *pSendContext);#endif#ifdef DO_DUMPvoid dump(RMuint8* data, RMuint32 size);#endif#ifdef DO_SAVE//void save_frame(int count, RMuint8* pLuma, RMuint8* pChroma, RMuint32 luma_size, RMuint32 chroma_size); void save_frame(int count, RMuint8* pLuma, RMuint32 luma_w, RMuint32 luma_h, RMuint32 luma_width, RMuint8* pChroma, RMuint32 chroma_w, RMuint32 chroma_h, RMuint32 chroma_width);#endifvoid extract_buffer(struct video_context *pSendContext, RMuint32 address, RMuint32 w, RMuint32 h, RMuint32 total_width, RMuint32 size);RMstatus WaitForEOSWithCommand2(struct RM_PSM_Context *PSMcontext, struct dcc_context *dcc_info_array[], struct RM_PSM_Actions *pActions, RMuint32 eos_bit_field);RMstatus WaitForFrames(struct video_context *pSendContext); void compute_crclog_filename(RMascii* bsFilename, RMascii* logFilename);#define GET_DATA_FIFO_INFO(pRUA, ModuleId) \ { \ struct DataFIFOInfo DataFIFOInfo; \ RMreal fullness; \ RUAGetProperty(pRUA, ModuleId, RMGenericPropertyID_DataFIFOInfo, &DataFIFOInfo, sizeof(DataFIFOInfo)); \ fullness = (RMreal)((100./DataFIFOInfo.Size)*DataFIFOInfo.Readable); \ fprintf(stderr, "Data %lx: st=%08lx sz=%ld wr=%ld rd=%ld --> f : %.02f\n", ModuleId, DataFIFOInfo.StartAddress, \ DataFIFOInfo.Size, DataFIFOInfo.Writable, DataFIFOInfo.Readable, fullness); \ } \#define GET_XFER_FIFO_INFO(pRUA, ModuleId) \ { \ struct XferFIFOInfo_type XferFIFOInfo; \ RMreal fullness; \ RUAGetProperty(pRUA, ModuleId, RMGenericPropertyID_XferFIFOInfo, &XferFIFOInfo, sizeof(XferFIFOInfo)); \ fullness = (RMreal)((100./XferFIFOInfo.Size)*XferFIFOInfo.Readable); \ fprintf(stderr, "XFER %lx: st=%08lx sz=%ld wr=%ld rd=%ld er=%lx --> f : %.02f \n", ModuleId, XferFIFOInfo.StartAddress, \ XferFIFOInfo.Size, XferFIFOInfo.Writable, XferFIFOInfo.Readable, XferFIFOInfo.Erasable, fullness); \ }#define MONITOR_INTERVAL_US 250000static void monitor(struct video_context *context, RMbool alwaysShow){ /* the bitrate reading of this probe is accurate only if the blocking call is RUASendData */ struct timeval now; static struct timeval last; static int first = 1; RMuint64 elapsed; RMuint64 ptime; struct dcc_context *dcc_info = context->dcc_info; gettimeofday(&now, NULL); elapsed = (now.tv_sec - last.tv_sec) * 1000000; elapsed += (now.tv_usec - last.tv_usec); if (elapsed > MONITOR_INTERVAL_US || first || alwaysShow){ RMuint64 bitrate = (RMuint64)context->bitrate * 1000000; bitrate /= elapsed; context->meanBitrate += bitrate; context->meanCount++; DCCSTCGetTime(dcc_info->pStcSource, &ptime, 90000); fprintf(stderr, "\n*****************************\n"); fprintf(stderr, "STC = %llu (%llu secs)\n", ptime, (ptime/90000)); /* sample code to get fifo info */ fprintf(stderr, "Video :\n"); GET_DATA_FIFO_INFO(dcc_info->pRUA, dcc_info->video_decoder); GET_XFER_FIFO_INFO(dcc_info->pRUA, dcc_info->video_decoder); fprintf(stderr, "bitrate: mean %llu bit/sec, pseudo-instantaneus %llu bit/sec (%lu bytes/%llu us)\n", context->meanBitrate / context->meanCount, bitrate, context->bitrate >> 3, elapsed); fprintf(stderr, "*****************************\n"); gettimeofday(&last, NULL); first = 0; context->bitrate = 0; fflush(stderr); } return;}static RMuint32 trickBuffersToSend = 0;static RMuint32 trickSizeToSend = 0;static RMuint32 trickBuffersSent = 0;static struct RM_PSM_Actions actions;#define PROCESS_KEY(release, getkey) \do { \ RMDBGLOG((DISABLE, "process_key\n")); \ if (getkey) { \ FSMstate = RM_PSM_GetState(context.PSMcontext, &(context.dcc_info)); \ if ((FSMstate == RM_PSM_Stopped) || (FSMstate == RM_PSM_Paused)) { \ switch (play_opt->disk_ctrl_state) { \ case DISK_CONTROL_STATE_DISABLE: \ case DISK_CONTROL_STATE_SLEEPING: \ break; \ case DISK_CONTROL_STATE_RUNNING: \ if(play_opt->disk_ctrl_callback && play_opt->disk_ctrl_callback(DISK_CONTROL_ACTION_SLEEP) == RM_OK) \ play_opt->disk_ctrl_state = DISK_CONTROL_STATE_SLEEPING; \ break; \ } \ } \ err = process_command(context.PSMcontext, &(context.dcc_info), &actions); \ if (RMFAILED(err)) { \ fprintf(stderr, "Error while processing key %d\n", err); \ goto cleanup; \ } \ } \ if (((RM_PSM_GetState(context.PSMcontext, &(context.dcc_info)) == RM_PSM_Slow) || \ (RM_PSM_GetState(context.PSMcontext, &(context.dcc_info)) == RM_PSM_Fast) || \ (RM_PSM_GetState(context.PSMcontext, &(context.dcc_info)) == RM_PSM_NextPic)) && \ (actions.cmdProcessed) && (!context.trickMode)) { \ RMDBGLOG((ENABLE, ">> trick mode\n")); \ if (release) { \ RUAReleaseBuffer(pDMA, buf); \ buf = NULL; \ } \ context.trickMode = TRUE; \ context.FirstSystemTimeStamp = TRUE; \ } \ if (actions.toDoActions & RM_PSM_FLUSH_VIDEO) { \ RMDBGLOG((ENABLE, "flushVIDEO\n")); \ Stop(&context, RM_DEVICES_VIDEO); \ context.video_decoder_initialized = FALSE; \ context.initVideo = TRUE; \ actions.toDoActions &= ~RM_PSM_FLUSH_VIDEO; \ } \ if (actions.toDoActions & RM_PSM_FIRST_PTS) { \ RMDBGLOG((ENABLE, "firstPTS\n")); \ context.FirstSystemTimeStamp = TRUE; \ actions.toDoActions &= ~RM_PSM_FIRST_PTS; \ } \ if (actions.toDoActions & RM_PSM_RESYNC_TIMER) { \ RMDBGLOG((ENABLE, "resyncTimer\n")); \ context.ResyncTimer = TRUE; \ actions.toDoActions &= ~RM_PSM_RESYNC_TIMER; \ } \ if (actions.performedActions & RM_PSM_VIDEO_STOPPED) { \ RMDBGLOG((ENABLE, "video stopped\n")); \ context.video_decoder_initialized = FALSE; \ context.initVideo = TRUE; \ actions.performedActions &= ~RM_PSM_VIDEO_STOPPED; \ /* needed for no dram copy version on standalone */ \ err = RUAResetPool(pDMA); \ if (RMFAILED(err)) { \ RMDBGLOG((ENABLE, "Error cannot reset dmapool\n")); \ goto cleanup; \ } \ } \ if (actions.performedActions & RM_PSM_STC_STOPPED) { \ RMDBGLOG((ENABLE, "stc stopped\n")); \ actions.performedActions &= ~RM_PSM_STC_STOPPED; \ } \ if (actions.toDoActions & RM_PSM_DEMUX_IFRAME) { \ RMDBGLOG((ENABLE, "demuxIFrame\n")); \ Play(&context, RM_DEVICES_VIDEO, DCCVideoPlayIFrame); \ context.iframeMode = TRUE; \ actions.toDoActions &= ~RM_PSM_DEMUX_IFRAME; \ } \ if (actions.toDoActions & RM_PSM_DEMUX_NORMAL) { \ RMDBGLOG((ENABLE, "demuxNormal\n")); \ context.iframeMode = FALSE; \ RMDBGLOG((ENABLE, "flushing fifos\n")); \ Stop(&context, RM_DEVICES_VIDEO); \ Play(&context, RM_DEVICES_VIDEO, DCCVideoPlayFwd); \ context.highSpeedIFrameMode = FALSE; \ actions.toDoActions &= ~RM_PSM_DEMUX_NORMAL; \ } \ if ((RM_PSM_GetState(context.PSMcontext, &(context.dcc_info)) == RM_PSM_Playing) && \ (context.trickMode)) { \ RMDBGLOG((ENABLE, "got play after trickmode\n")); \ if (release) { \ RUAReleaseBuffer(pDMA, buf); \ buf = NULL; \ } \ context.trickMode = FALSE; \ } \ if ((RM_PSM_GetState(context.PSMcontext, &(context.dcc_info)) == RM_PSM_Stopped) && (actions.cmdProcessed)) { \ RMDBGLOG((ENABLE,"Got stop command\n")); \ if (release) { \ RUAReleaseBuffer(pDMA, buf); \ buf = NULL; \ } \ context.trickMode = FALSE; \ context.iframeMode = FALSE; \ context.highSpeedIFrameMode = FALSE; \ context.video_decoder_initialized = FALSE; \ context.initVideo = TRUE; \ context.byte_counter = 0; \ goto mainloop_no_seek; \ } \ if ((actions.cmd == RM_QUIT) && (!actions.cmdProcessed)) { \ RMDBGLOG((ENABLE, "Got quit command\n")); \ if (release) { \ RUAReleaseBuffer(pDMA, buf); \ buf = NULL; \ } \ goto cleanup; \ } \ if ((actions.cmd == RM_STOP_SEEK_ZERO) && (!actions.cmdProcessed)) { \ RMDBGLOG((ENABLE,"Got stop seek zero command\n")); \ Stop(&context, RM_DEVICES_VIDEO | RM_DEVICES_STC); \ RM_PSM_SetState(context.PSMcontext, &(context.dcc_info), RM_PSM_Stopped); \ if (release) { \ RUAReleaseBuffer(pDMA, buf); \ buf = NULL; \ } \ context.trickMode = FALSE; \ context.iframeMode = FALSE; \ context.highSpeedIFrameMode = FALSE; \ context.video_decoder_initialized = FALSE; \ context.initVideo = TRUE; \ goto mainloop; \ } \ if ((actions.cmd == RM_SEEK) && (!actions.cmdProcessed)){ \ RMDBGLOG((ENABLE,"Got seek command\n")); \ if (release) { \ RUAReleaseBuffer(pDMA, buf); \ buf = NULL; \ } \ if (dcc_info.seek_supported) \ seek(&context, context.dcc_info->seek_time); \ else \ fprintf(stderr, "Unsuported command\n"); \ context.trickMode = FALSE; \ context.iframeMode = FALSE; \ context.highSpeedIFrameMode = FALSE; \ RM_PSM_SetState(context.PSMcontext, &(context.dcc_info), RM_PSM_Playing); \ goto mainloop_no_seek; \ } \ computeSpeed(&context); \ if (context.monitor) \ monitor(&context, FALSE); \} while(0)static RMstatus computeSpeed(struct video_context *pSendContext);static RMuint64 round_int_div(RMuint64 numerator, RMuint32 divisor) { RMuint64 temp; temp = numerator / divisor; if ((numerator % divisor) * 2 > divisor) temp++; return temp;}#ifndef WITH_MONOstatic void show_usage(char *progname){ show_playback_options(); show_display_options(); show_video_options(); fprintf(stderr, "--------------------------------\n"); fprintf(stderr, "Minimum cmd line: %s <file name>\n", progname); fprintf(stderr, "--------------------------------\n"); exit(1);}static void parse_cmdline(int argc, char *argv[]){ int i; RMstatus err; if (argc < 2) show_usage(argv[0]); i = 1; while ((argc > i)) { if (argv[i][0] != '-') { if (play_opt->filename == NULL) { play_opt->filename = argv[i]; i++; } else show_usage(argv[0]); } else { err = parse_playback_cmdline(argc, argv, &i, play_opt); if (err == RM_ERROR) show_usage(argv[0]); if (err != RM_PENDING) continue; err = parse_display_cmdline(argc, argv, &i, disp_opt); if (err == RM_ERROR) show_usage(argv[0]); if (err != RM_PENDING) continue; err = parse_video_cmdline(argc, argv, &i, video_opt); if (RMFAILED(err)) show_usage(argv[0]); } } if (play_opt->filename == NULL) show_usage(argv[0]);}#endif //WITH_MONOstatic RMstatus WaitForEOS(struct video_context *pSendContext, struct RM_PSM_Actions *pActions){ RMuint32 eos_bit_field = 0; if (pSendContext == NULL || pActions == NULL) return RM_ERROR;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -