📄 decode.c
字号:
stride = mpeg2dec->convert (MPEG2_CONVERT_STRIDE, NULL, &(mpeg2dec->sequence), stride, mpeg2_accels, mpeg2dec->convert_arg, &convert_init); mpeg2dec->convert_id_size = convert_init.id_size; mpeg2dec->convert_stride = stride; } return stride;}void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[3], void * id){ mpeg2_fbuf_t * fbuf; if (mpeg2dec->custom_fbuf) { if (mpeg2dec->state == STATE_SEQUENCE) { mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1]; mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0]; } mpeg2_set_fbuf (mpeg2dec, (mpeg2dec->decoder.coding_type == PIC_FLAG_CODING_TYPE_B)); fbuf = mpeg2dec->fbuf[0]; } else { fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index].fbuf); mpeg2dec->alloc_index_user = ++mpeg2dec->alloc_index; } fbuf->buf[0] = buf[0]; fbuf->buf[1] = buf[1]; fbuf->buf[2] = buf[2]; fbuf->id = id; // @@@ libmpeg2 patch - begin // HACK! FIXME! At first I frame, copy pointers to prediction frame too! if (mpeg2dec->custom_fbuf && !mpeg2dec->fbuf[1]->buf[0]){ mpeg2dec->fbuf[1]->buf[0]=buf[0]; mpeg2dec->fbuf[1]->buf[1]=buf[1]; mpeg2dec->fbuf[1]->buf[2]=buf[2]; mpeg2dec->fbuf[1]->id=NULL; } // @@@ libmpeg2 patch - end}void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf){ mpeg2dec->custom_fbuf = custom_fbuf;}void mpeg2_skip (mpeg2dec_t * mpeg2dec, int skip){ mpeg2dec->first_decode_slice = 1; mpeg2dec->nb_decode_slices = skip ? 0 : (0xb0 - 1);}void mpeg2_slice_region (mpeg2dec_t * mpeg2dec, int start, int end){ start = (start < 1) ? 1 : (start > 0xb0) ? 0xb0 : start; end = (end < start) ? start : (end > 0xb0) ? 0xb0 : end; mpeg2dec->first_decode_slice = start; mpeg2dec->nb_decode_slices = end - start;}void mpeg2_tag_picture (mpeg2dec_t * mpeg2dec, uint32_t tag, uint32_t tag2){ mpeg2dec->tag_previous = mpeg2dec->tag_current; mpeg2dec->tag2_previous = mpeg2dec->tag2_current; mpeg2dec->tag_current = tag; mpeg2dec->tag2_current = tag2; mpeg2dec->num_tags++; mpeg2dec->bytes_since_tag = 0;}#ifdef NO_PERFuint32_t mpeg2_accel (uint32_t accel){ if (!mpeg2_accels) { if (accel & MPEG2_ACCEL_DETECT) accel |= mpeg2_detect_accel (); mpeg2_accels = accel |= MPEG2_ACCEL_DETECT; mpeg2_cpu_state_init (accel); mpeg2_idct_init (accel); mpeg2_mc_init (accel); } return mpeg2_accels & ~MPEG2_ACCEL_DETECT;}#endif //#ifdef NO_PERFvoid mpeg2_reset (mpeg2dec_t * mpeg2dec, int full_reset){ mpeg2dec->buf_start = mpeg2dec->buf_end = NULL; mpeg2dec->num_tags = 0; mpeg2dec->shift = 0xffffff00; mpeg2dec->code = 0xb4; mpeg2dec->action = mpeg2_seek_header; mpeg2dec->state = STATE_INVALID; mpeg2dec->first = 1; mpeg2dec->decoder.uiWaitForIFrame = 1; /* HWG050505+ for improved PTS interpolation */ mpeg2dec->decoder.tCurrentPTS = mpeg2dec->decoder.uiTemporalOffset = mpeg2dec->decoder.uiTemporalNum = 0; mpeg2dec->decoder.uiGOPCount = 0; mpeg2dec->decoder.uiMaxTemporal=0; mpeg2dec->decoder.uiActualFramePeriod=33<<FRAMEPERIOD_SCALE; /* default to 33 ms */ mpeg2dec->decoder.tNewPTS = 0; mpeg2dec->decoder.bNewPTS = 0; mpeg2dec->decoder.iTemporalAtNewPTS = 0; mpeg2dec->decoder.uiFramesSinceNewPTS = 0; mpeg2dec->decoder.tPTSLastSync = 0; mpeg2dec->decoder.bSyncedPTS = 0; mpeg2dec->decoder.iTemporalAtSyncPTS = 0; mpeg2dec->decoder.uiFramesSincePTSSync = 0; mpeg2dec->decoder.uiGOPsSincePTSSync = 0; mpeg2dec->decoder.uiSkipFrameCount = 0; mpeg2dec->decoder.uiSkipIFrames = 1; /* initialize to 1 for all I frames */ mpeg2dec->decoder.uiIFramesProcessed = 0; mpeg2dec->decoder.uiPFramesProcessed = 0; mpeg2dec->decoder.uiBFramesProcessed = 0; /* HWG050505- */ mpeg2_reset_info(&(mpeg2dec->info)); mpeg2dec->info.gop = NULL; mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0; if (full_reset) { mpeg2dec->info.sequence = NULL; mpeg2_header_state_init (mpeg2dec); }}mpeg2dec_t * mpeg2_init (unsigned char bUseMAE, unsigned char bDumpFiles, unsigned char bDumpFinal, unsigned long ulVideoOff){ mpeg2dec_t * mpeg2dec; APIPRINTF((M_TEXT("mpeg2_init()\n"))); #ifdef NO_PERF mpeg2_accel (MPEG2_ACCEL_DETECT);#endif //#ifdef NO_PERF mpeg2dec = (mpeg2dec_t *) mpeg2_malloc (sizeof (mpeg2dec_t), MPEG2_ALLOC_MPEG2DEC); if (mpeg2dec == NULL) return NULL; #ifdef MAE_HW#if defined(USE_CMODELIF) Call_cmodel_init_global();#else open_mae_driver();#endif #if !defined(UNDER_CE) && defined(MAE_RENDERER) mpeg2dec->ulVideoOff = ulVideoOff;#endif // assign C Model flag (obtained from command line) mpeg2dec->bUseMAE = mpeg2dec->decoder.bUseMAE = bUseMAE; mpeg2dec->bDumpFiles = mpeg2dec->decoder.bDumpFiles = bDumpFiles; mpeg2dec->bDumpFinal = mpeg2dec->decoder.bDumpFinal = bDumpFinal; // Set the file dumping mask#ifdef NO_PERF Set_Print_Flag ( (bDumpFiles ? DUMP_ALL : NO_DUMP_ALL) | (bDumpFinal ? DUMP_FINAL : 0) );#endif //#ifdef NO_PERF#else /* !MAE_HW */ /* not using MAE */ mpeg2dec->bUseMAE = mpeg2dec->decoder.bUseMAE = 0; mpeg2dec->bDumpFiles = mpeg2dec->decoder.bDumpFiles = 0; mpeg2dec->bDumpFinal = mpeg2dec->decoder.bDumpFinal = 0;#endif /* !MAE_HW */ #ifdef MAE_HW if(bUseMAE) { mpeg2dec->decoder.pYUVOut[0][0] = mpeg2dec->decoder.pYUVOut[0][1] = mpeg2dec->decoder.pYUVOut[0][2] = mpeg2dec->decoder.pYUVOut[1][0] = mpeg2dec->decoder.pYUVOut[1][1] = mpeg2dec->decoder.pYUVOut[1][2] = mpeg2dec->decoder.pYUVOut[2][0] = mpeg2dec->decoder.pYUVOut[2][1] = mpeg2dec->decoder.pYUVOut[2][2] = NULL; } else { mpeg2dec->decoder.pYOut = mpeg2dec->decoder.pCbOut = mpeg2dec->decoder.pCrOut = NULL; }#else mpeg2dec->decoder.pYOut = mpeg2dec->decoder.pCbOut = mpeg2dec->decoder.pCrOut = NULL;#endif mpeg2dec->decoder.bAllocated = 0; memset (mpeg2dec->decoder.DCTblock, 0, 64 * sizeof (int16_t)); memset (mpeg2dec->quantizer_matrix, 0, 4 * 64 * sizeof (uint8_t)); mpeg2dec->chunk_buffer = (uint8_t *) mpeg2_malloc (BUFFER_SIZE + 4, MPEG2_ALLOC_CHUNK); mpeg2dec->sequence.width = (unsigned)-1; mpeg2_reset (mpeg2dec, 1); /* MAE specific state variables */#if defined(MAE_HW) pWrapContext = NULL;#endif mpeg2dec->decoder.ulSpecial = 0; mpeg2dec->decoder.ulOkToSubmit = 0; mpeg2dec->decoder.ulSubmitCalled = 1; /* 1 since no outstanding submit buffer held */ mpeg2dec->decoder.ulDebugFlag = 0; mpeg2dec->decoder.uiPrevTnum = 0xFFFF; /* The first temporal number may be 0, so set something else */ mpeg2dec->decoder.ulInitDisplay = 0; // $PP mpeg2dec->decoder.uiSpeed = 0; /* unspecified */ mpeg2dec->decoder.uiDecodeMode = DECODE_NORMAL; mpeg2dec->decoder.bNewDecodeMode = 0; mpeg2dec->decoder.uiNewDecodeMode = DECODE_NORMAL; mpeg2dec->decoder.uiNewSpeed = 0; /* unspecified */ mpeg2dec->decoder.bFlushing = 0; mpeg2dec->decoder.bDiscon = 1; mpeg2dec->decoder.uiOkToDecode = 1; mpeg2dec->decoder.iMBCount = 0; mpeg2dec->decoder.uiTemporalNum = 0; //initialize to 0 mpeg2dec->decoder.uiSkipFrameCount = 0; mpeg2dec->decoder.uiSkipIFrames = 1; /* initialize to 1 for all I frames */ #ifdef NO_PERF //if (bDumpFiles || bDumpFinal) // mpeg2_slice = mpeg2_slice_dump; //else mpeg2_slice = mpeg2_slice_no_dump;#else mpeg2_slice = mpeg2_slice_no_dump;#endif //#ifdef NO_PERF #ifdef MAE_HW memset (&local_header, 0, sizeof(local_header));#endif return mpeg2dec;}void mpeg2_close (mpeg2dec_t * mpeg2dec){ APIPRINTF((M_TEXT("mpeg2_close()\n")));#ifdef MAE_HW if (!mpeg2dec->decoder.ulSubmitCalled && pWrapContext) { DPRINTF((M_TEXT("mpeg2_close() Dummy submit\n"))); pWrapContext->dummysubmit = 1; WrapSubmitMBs(); mpeg2dec->decoder.ulSubmitCalled=1; pWrapContext = NULL; }#endif mpeg2_header_state_init (mpeg2dec); mpeg2_free (mpeg2dec->chunk_buffer); // $PP if (mpeg2dec->decoder.bAllocated) {#ifndef MAE_HW#ifdef NO_PERF free(mpeg2dec->decoder.pYOut); mpeg2dec->decoder.pYOut=NULL; free(mpeg2dec->decoder.pCbOut); mpeg2dec->decoder.pCbOut = NULL; free(mpeg2dec->decoder.pCrOut); mpeg2dec->decoder.pCrOut = NULL;#endif //#ifdef NO_PERF#else if(mpeg2dec->bUseMAE) { // Nothing to do } else {#ifdef NO_PERF mpeg2dec->decoder.pYOut = (unsigned char*) MAEFree (mpeg2dec->decoder.pYOut); mpeg2dec->decoder.pCbOut = (unsigned char*) MAEFree (mpeg2dec->decoder.pCbOut); mpeg2dec->decoder.pCrOut = (unsigned char*) MAEFree (mpeg2dec->decoder.pCrOut);#endif //#ifdef NO_PERF }#endif } mpeg2dec->decoder.ulSubmitCalled = 1; mpeg2dec->decoder.ulSpecial = 0; mpeg2dec->decoder.ulOkToSubmit = 0; mpeg2dec->decoder.ulDebugFlag = 0; mpeg2dec->decoder.uiPrevTnum = 0xFFFF; mpeg2dec->decoder.ulInitDisplay = 0; #ifdef MAE_HW close_mae_driver();#endif mpeg2_free (mpeg2dec);}/* mpeg2_setskipmode()** Request the decoder to skip frames (when I Frame only mode still can't keep up)*/void mpeg2_setskipmode (mpeg2dec_t * mpeg2dec, unsigned int uiSkipIFrames){ DPRINTF((M_TEXT("mpeg2_setskipmode(skip=%d)\n"), uiSkipIFrames)); mpeg2dec->decoder.uiSkipIFrames = uiSkipIFrames; mpeg2dec->decoder.uiSkipFrameCount = 0; }/* mpeg2_getskipmode()** Get the current skip mode (number of I Frames being skipped to keep up)*/unsigned int mpeg2_getskipmode (mpeg2dec_t * mpeg2dec){ return mpeg2dec->decoder.uiSkipIFrames;}/* mpeg2_setmode()** Request the decoder go into a new Decode mode (DECODE_NORMAL, DECODE_I_ONLY, etc.)*/void mpeg2_setmode (mpeg2dec_t * mpeg2dec, mpeg2_decode_mode_t uiMode, unsigned int uiSpeed){ APIPRINTF((M_TEXT("mpeg2_setmode(mode=%d, speed=0x%X)\n"), uiMode, uiSpeed)); mpeg2dec->decoder.uiNewDecodeMode = uiMode; mpeg2dec->decoder.uiNewSpeed = uiSpeed; mpeg2dec->decoder.bNewDecodeMode = 1;}/* mpeg2_getmode()** Get the current decode mode.*/mpeg2_decode_mode_t mpeg2_getmode (mpeg2dec_t * mpeg2dec){ return mpeg2dec->decoder.uiDecodeMode;}/* set the timestamp (in millisecs) */void mpeg2_settimestamp (mpeg2dec_t * mpeg2dec, mpeg_time_t tPTS){ APIPRINTF((M_TEXT("mpeg2_settimestamp(%d)\n"), (int)tPTS)); mpeg2dec->decoder.tNewPTS = tPTS; /* HWG050505+ for improved PTS interpolation */ mpeg2dec->decoder.bNewPTS = 1; mpeg2dec->decoder.iTemporalAtNewPTS = -1; /* unknown */ mpeg2dec->decoder.uiFramesSinceNewPTS = 0; /* HWG050505- */}/* get the timestamp (in millisecs) */int mpeg2_gettimestamp (mpeg2dec_t * mpeg2dec, mpeg_time_t *ptPTS){ if (ptPTS) *ptPTS=mpeg2dec->decoder.tCurrentPTS; return(1); /* 0=failed 1=success */}/* mpeg2_setdiscontinuity()** set the decode discontinuity and enable/disable Flushing state*/void mpeg2_setdiscontinuity (mpeg2dec_t * mpeg2dec, unsigned int bDiscon){ APIPRINTF((M_TEXT("mpeg2_setdiscontinuity(%d)\n"), bDiscon)); mpeg2dec->decoder.bDiscon = bDiscon; if (bDiscon) { mpeg2dec->decoder.tNewPTS = 0; mpeg2dec->decoder.iTemporalAtNewPTS = 0; mpeg2dec->decoder.uiFramesSinceNewPTS = 0; }}/* mpeg2_setflush()** enable/disable Flushing state*/void mpeg2_setflush (mpeg2dec_t * mpeg2dec, unsigned int bFlushing){ APIPRINTF((M_TEXT("mpeg2_setflush(%d)\n"), bFlushing)); mpeg2dec->decoder.bFlushing = bFlushing; if (mpeg2dec->decoder.bFlushing && mpeg2dec->decoder.ulSubmitCalled) { /* HWG - since all Submits are completed, we can reset Flushing flag imediately */ DPRINTF((M_TEXT("mpeg2_setflush() clearing bFlushing (no outstanding submits)\n"))); mpeg2dec->decoder.bFlushing = 0; }}void mpeg2_frame_stats (mpeg2dec_t * mpeg2dec){ // at the start of each frame, set MacroBlock count to 0 mpeg2dec->decoder.iMBCount = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -