cedarx_result_e libcedarx_decoder_decode_stream(int force) { vresult_e res; cedarx_result_e result; cedarx_decoder_t* decoder = cedarx_decoder; if ((!decoder) || (!decoder->ve) || (!decoder->vbv)) return CEDARX_RESULT_NO_INIT; if (!force) { if (vbv_check_stream_frame(decoder->vbv) < 0) return CEDARX_RESULT_VBV_BUFFER_EMPTY; } res = libve_decode(0, 0, 0, decoder->ve); switch (res) { case VRESULT_OK: case VRESULT_FRAME_DECODED: case VRESULT_KEYFRAME_DECODED: result = CEDARX_RESULT_OK; break; case VRESULT_NO_FRAME_BUFFER: printf("Warning: There are not more framebuffer!\n"); result = CEDARX_RESULT_NO_FRAME_BUFFER; break; case VRESULT_NO_BITSTREAM: printf("Warning: There are not more bitstream!\n"); result = CEDARX_RESULT_VBV_BUFFER_EMPTY; break; default: printf("Error: Decode failed(%d), try to reset decoder!\n", res); libve_reset(0, decoder->ve); return CEDARX_RESULT_VE_FAILED; } return result; }
static s32 vdecoder_decode(cedarv_decoder_t* p) { vresult_e vresult; #if (DECODE_FREE_RUN == 0) u64 video_time; #endif video_decoder_t* decoder; if(p == NULL) return CEDARV_RESULT_ERR_INVALID_PARAM; decoder = (video_decoder_t*)p; if(decoder->mode_switched) { libve_reset(0, decoder->ve); vbv_reset(decoder->vbv); if(p->free_vbs_buffer_sem != NULL) p->free_vbs_buffer_sem(p->cedarx_cookie); if(decoder->fbm != NULL) { fbm_flush(decoder->fbm); if(p->release_frame_buffer_sem != NULL) p->release_frame_buffer_sem(p->cedarx_cookie); } decoder->mode_switched = 0; return CEDARV_RESULT_NO_BITSTREAM; } if(decoder->status == CEDARV_STATUS_BACKWARD || decoder->status == CEDARV_STATUS_FORWARD) { vresult = libve_decode(1, 0, 0, decoder->ve); } else { if(decoder->stream_info.format == STREAM_FORMAT_H264 && decoder->display_already_begin == 0) { //* for H264, when decoding the first data unit containing PPS, we have to promise //* there is more than one bitstream frame for decoding. //* that is because the decoder uses the start code of the second bitstream frame //* to judge PPS end. if(vbv_get_stream_num(decoder->vbv) < 2) return CEDARV_RESULT_NO_BITSTREAM; } if(decoder->status == CEDARV_STATUS_PREVIEW) { vresult = libve_decode(1, 0, 0, decoder->ve); } else { #if (DECODE_FREE_RUN == 0) video_time = esMODS_MIoctrl(vdrv_com->avsync, DRV_AVS_CMD_GET_VID_TIME, DRV_AVS_TIME_TOTAL, 0); video_time *= 1000; vresult = libve_decode(0, 1, video_time, decoder->ve); #else vresult = libve_decode(0, 0, 0, decoder->ve); #endif } } if(vresult == VRESULT_OK) { return CEDARV_RESULT_OK; } else if(vresult == VRESULT_FRAME_DECODED) { return CEDARV_RESULT_FRAME_DECODED; } else if(vresult == VRESULT_KEYFRAME_DECODED) { if(decoder->status == CEDARV_STATUS_BACKWARD || decoder->status == CEDARV_STATUS_FORWARD || decoder->status == CEDARV_STATUS_PREVIEW) { libve_reset(1, decoder->ve); } return CEDARV_RESULT_KEYFRAME_DECODED; } else if(vresult == VRESULT_NO_FRAME_BUFFER) { return CEDARV_RESULT_NO_FRAME_BUFFER; } else if(vresult == VRESULT_NO_BITSTREAM) { return CEDARV_RESULT_NO_BITSTREAM; } else if(vresult == VRESULT_ERR_NO_MEMORY) { return CEDARV_RESULT_ERR_NO_MEMORY; } else if( vresult == VRESULT_ERR_UNSUPPORTED) { return CEDARV_RESULT_ERR_UNSUPPORTED; } else if(vresult == VRESULT_ERR_LIBRARY_NOT_OPEN) { return CEDARV_RESULT_ERR_FAIL; } else { return CEDARV_RESULT_OK; } }