Prevent App/Process Termination by Android OS

本文探讨了如何防止Android应用在后台运行时被系统终止的方法。通过将应用置于通知栏中,可以确保即使在切换到其他应用时,该应用也不会被系统视为可释放资源而被关闭。这种方式类似于音乐播放器等应用的做法。

Is there a way to prevent an app or process from being terminated by the Android OS due to the OS's attempt to free up resources?



The app needs to put itself in the Notifications bar in order to keep from getting killed when it's in the background. This is what apps like Music or Pandora do in order to keep playing music and not get killed when they are backgrounded. See below.


References:
[2]
android-developers.blogspot.com

#define _CRT_SECURE_NO_WARNINGS #define DECODING_TIME_TEST 1 #include "com_typedef.h" #include "app_util.h" #include "app_args.h" #include "dec_def.h" #if SVAC_NAL #include "com_svac_nal.h" #endif #if LINUX #include <execinfo.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> void handler(int sig) { void *array[10]; size_t size; // get void*'s for all entries on the stack size = backtrace(array, 10); // print out all the frames to stderr fprintf(stderr, "Error: signal %d:\n", sig); backtrace_symbols_fd(array, size, STDERR_FILENO); exit(1); } #endif #if MULTI_LAYER_FRAMEWORK int g_CountDOICyCleTime[MAX_LAYER]; // number to count the DOI cycle time. int g_DOIPrev[MAX_LAYER]; // the doi of previous frm. #else int g_CountDOICyCleTime; // number to count the DOI cycle time. int g_DOIPrev; // the doi of previous frm. #endif #define VERBOSE_FRAME VERBOSE_1 #define MAX_BS_BUF (32*1024*1024) /* byte */ static char op_fname_inp[256] = "\0"; #if MULTI_LAYER_FRAMEWORK static char op_fname_out[MAX_LAYER][256] = { "\0", "\0"}; #else static char op_fname_out[256] = "\0"; #endif static int op_max_frm_num = 0; static int op_use_pic_signature = 0; static int op_clip_org_size = 0; static int op_bit_depth_output_cfg = 0; static int op_bit_depth_output = 0; #if CU_LEVEL_PRIVACY static int op_user_permission = 0; #endif #if LIBVC_ON static char op_fname_inp_libpics[256] = "\0"; /* bitstream of libpics */ static char op_fname_out_libpics[256] = "\0"; /* reconstructed yuv of libpics */ #endif #if LIB_PIC_ERR_TOL unsigned int bs_real_size = 0; #endif typedef enum _STATES { STATE_DECODING, STATE_BUMPING #if LIB_PIC_ERR_TOL , STATE_LIBPIC_COLLECTING #endif } STATES; typedef enum _OP_FLAGS { OP_FLAG_FNAME_INP, OP_FLAG_FNAME_OUT, #if MULTI_LAYER_FRAMEWORK OP_FLAG_FNAME_OUT1, #endif OP_FLAG_MAX_FRM_NUM, OP_FLAG_USE_PIC_SIGN, OP_FLAG_CLIP_ORG_SIZE, OP_FLAG_OUT_BIT_DEPTH, #if CU_LEVEL_PRIVACY OP_USER_PERMISSION, #endif OP_FLAG_VERBOSE, #if LIBVC_ON OP_FLAG_FNAME_INP_LIBPICS, OP_FLAG_FNAME_OUT_LIBPICS, #endif OP_FLAG_MAX } OP_FLAGS; static int op_flag[OP_FLAG_MAX] = {0}; static COM_ARGS_OPTION options[] = \ { { 'i', "input", ARGS_TYPE_STRING | ARGS_TYPE_MANDATORY, &op_flag[OP_FLAG_FNAME_INP], op_fname_inp, "file name of input bitstream"}, #if MULTI_LAYER_FRAMEWORK { 'o', "output", ARGS_TYPE_STRING, &op_flag[OP_FLAG_FNAME_OUT], op_fname_out[0],"file name of decoded output" }, { 'e', "output1", ARGS_TYPE_STRING, &op_flag[OP_FLAG_FNAME_OUT1], op_fname_out[1],"file name of decoded output" }, #else { 'o', "output", ARGS_TYPE_STRING, &op_flag[OP_FLAG_FNAME_OUT], op_fname_out,"file name of decoded output" }, #endif { 'f', "frames", ARGS_TYPE_INTEGER, &op_flag[OP_FLAG_MAX_FRM_NUM], &op_max_frm_num,"maximum number of frames to be decoded" }, { 's', "signature", COM_ARGS_VAL_TYPE_NONE, &op_flag[OP_FLAG_USE_PIC_SIGN], &op_use_pic_signature,"conformance check using picture signature (HASH)" }, { 'c', "clip_org_size", COM_ARGS_VAL_TYPE_NONE, &op_flag[OP_FLAG_CLIP_ORG_SIZE], &op_clip_org_size,"clip the output size to the original size (the input size at the encoder side)" }, { COM_ARGS_NO_KEY, "output_bit_depth", ARGS_TYPE_INTEGER, &op_flag[OP_FLAG_OUT_BIT_DEPTH], &op_bit_depth_output_cfg, "output bitdepth : 8 / 10 (default: internal bitdepth)" }, #if CU_LEVEL_PRIVACY { 'u', "user_permission", ARGS_TYPE_INTEGER , &op_flag[OP_USER_PERMISSION], &op_user_permission, "decoder user permission: 0 / 1 (default: 0)" }, #endif { 'v', "verbose", ARGS_TYPE_INTEGER, &op_flag[OP_FLAG_VERBOSE], &op_verbose, "verbose level\n" "\t 0: no message\n" "\t 1: frame-level messages (default)\n" "\t 2: all messages\n" }, #if LIBVC_ON { COM_ARGS_NO_KEY, "input_libpics", ARGS_TYPE_STRING, &op_flag[OP_FLAG_FNAME_INP_LIBPICS], op_fname_inp_libpics, "file name of input libpics bitstream" }, { COM_ARGS_NO_KEY, "output_libpics", ARGS_TYPE_STRING, &op_flag[OP_FLAG_FNAME_OUT_LIBPICS], op_fname_out_libpics, "file name of decoded libpics output" }, #endif { 0, "", COM_ARGS_VAL_TYPE_NONE, NULL, NULL, "" } /* termination */ }; #define NUM_ARG_OPTION ((int)(sizeof(options)/sizeof(options[0]))-1) static void print_usage(void) { int i; char str[1024]; v0print("< Usage >\n"); for(i=0; i<NUM_ARG_OPTION; i++) { if(com_args_get_help(options, i, str) < 0) return; v0print("%s\n", str); } } static int xFindNextStartCode(FILE * fp, int * ruiPacketSize, unsigned char *pucBuffer) { unsigned int uiDummy = 0; char bEndOfStream = 0; size_t ret = 0; #if SVAC_NAL ret = fread(&uiDummy, 1, 3, fp); if (ret != 3) { return -1; } #else ret = fread(&uiDummy, 1, 2, fp); if (ret != 2) { return -1; } #endif if (feof(fp)) { return -1; } assert(0 == uiDummy); ret = fread(&uiDummy, 1, 1, fp); if (ret != 1) { return -1; } if (feof(fp)) { return -1; } assert(1 == uiDummy); int iNextStartCodeBytes = 0; unsigned int iBytesRead = 0; unsigned int uiZeros = 0; unsigned char pucBuffer_Temp[16]; int iBytesRead_Temp = 0; #if SVAC_NAL pucBuffer[iBytesRead++] = 0x00; #endif pucBuffer[iBytesRead++] = 0x00; pucBuffer[iBytesRead++] = 0x00; pucBuffer[iBytesRead++] = 0x01; while (1) { unsigned char ucByte = 0; ret = fread(&ucByte, 1, 1, fp); if (feof(fp)) { iNextStartCodeBytes = 0; bEndOfStream = 1; break; } pucBuffer[iBytesRead++] = ucByte; if (1 < ucByte) { uiZeros = 0; } else if (0 == ucByte) { uiZeros++; } else if (uiZeros > 1) { iBytesRead_Temp = 0; pucBuffer_Temp[iBytesRead_Temp] = ucByte; iBytesRead_Temp++; ret = fread(&ucByte, 1, 1, fp); if (ret != 1) { return -1; } pucBuffer_Temp[iBytesRead_Temp] = ucByte; pucBuffer[iBytesRead++] = ucByte; iBytesRead_Temp++; #if SVAC_NAL if (pucBuffer_Temp[0] == 0x01 && ( pucBuffer_Temp[1] == SVAC_SPS #if SVAC_SECURITY_PARAM_SET || pucBuffer_Temp[1] == SVAC_SEC_PS #endif #if SVAC_AUTHENTICATION || pucBuffer_Temp[1] == SVAC_AUTH_DATA #endif #if HLS_OPT_PPS || pucBuffer_Temp[1] == SVAC_PPS || pucBuffer_Temp[1] == SVAC_PH || (pucBuffer[4] == SVAC_PH && (pucBuffer_Temp[1] == SVAC_IDR || pucBuffer_Temp[1] == SVAC_NON_RAP || pucBuffer_Temp[1] == SVAC_RAP_I #if LIB_PIC_MIXBIN #if DISPLAY_L_NAL_TYPE || pucBuffer_Temp[1] == SVAC_CRR_L || pucBuffer_Temp[1] == SVAC_CRR_DP || pucBuffer_Temp[1] == SVAC_CRR_RL #if LIB_PIC_ERR_TOL || pucBuffer_Temp[1] == SVAC_CRR_DL #endif )) || ((pucBuffer_Temp[1] == SVAC_CRR_L #if LIB_PIC_ERR_TOL || pucBuffer_Temp[1] == SVAC_CRR_DL #endif || pucBuffer_Temp[1] == SVAC_EOS || pucBuffer_Temp[1] == SVAC_EOCVS #else || pucBuffer_Temp[1] == SVAC_CRR_L || pucBuffer_Temp[1] == SVAC_CRR_RL)) || ((pucBuffer_Temp[1] == SVAC_CRR_L #endif #endif )) #else || pucBuffer_Temp[1] == SVAC_PPS || (pucBuffer[4] == SVAC_PPS && (pucBuffer_Temp[1] == SVAC_IDR || pucBuffer_Temp[1] == SVAC_NON_IDR #if LIB_PIC_MIXBIN || pucBuffer_Temp[1] == SVAC_CRR_L || pucBuffer_Temp[1] == SVAC_CRR_RL)) || ((pucBuffer_Temp[1] == SVAC_CRR_L #endif )) #endif ) ) #else if( pucBuffer_Temp[0] == 0x01 && (pucBuffer_Temp[1] == 0xb3 || pucBuffer_Temp[1] == 0xb6 || pucBuffer_Temp[1] == 0xb0 || pucBuffer_Temp[1] == 0x00 || pucBuffer_Temp[1] == 0xb1) ) #endif { #if SVAC_NAL iNextStartCodeBytes = 3 + 1 + 1; #else iNextStartCodeBytes = 2 + 1 + 1; #endif uiZeros = 0; break; } else { uiZeros = 0; iNextStartCodeBytes = 0;// 2 + 1 + 1; } } else { uiZeros = 0; } } *ruiPacketSize = iBytesRead - iNextStartCodeBytes; if (bEndOfStream) { return 0; } if (fseek(fp, -1 * iNextStartCodeBytes, SEEK_CUR) != 0) { printf("file seek failed!\n"); }; #if SVAC_NAL ret = fread(&uiDummy, 1, 4, fp); if (ret != 4) { return -1; } assert(0x01000000 == uiDummy); fseek(fp, -4, SEEK_CUR); #endif return 0; } static unsigned int initParsingConvertPayloadToRBSP(const unsigned int uiBytesRead, unsigned char* pBuffer, unsigned char* pBuffer2 #if CU_LEVEL_PRIVACY , unsigned char * bs_buf3,int *privacy_size #endif ) { unsigned int uiZeroCount = 0; unsigned int uiBytesReadOffset = 0; #if !NAL unsigned int uiBitsReadOffset = 0; #endif const unsigned char *pucRead = pBuffer; unsigned char *pucWrite = pBuffer2; unsigned int uiWriteOffset = uiBytesReadOffset; unsigned char ucCurByte = pucRead[uiBytesReadOffset]; #if CU_LEVEL_PRIVACY unsigned char *pucWrite_privacy = bs_buf3; unsigned int uiWriteOffset_temp0 = 0; unsigned int uiWriteOffset_temp1 = 0; unsigned int privacy = 0; unsigned int patch_flag = 1; #endif for (uiBytesReadOffset = 0; uiBytesReadOffset < uiBytesRead; uiBytesReadOffset++) { ucCurByte = pucRead[uiBytesReadOffset]; #if CU_LEVEL_PRIVACY if (patch_flag == 0 && pucRead[uiBytesReadOffset] == 0 && pucRead[uiBytesReadOffset + 1] == 0 && pucRead[uiBytesReadOffset + 2] == 0 && pucRead[uiBytesReadOffset + 3] == 1 && pucRead[uiBytesReadOffset + 4] == SVAC_PRIVACY) { uiWriteOffset_temp0 = uiWriteOffset; pucWrite = bs_buf3; uiWriteOffset = uiWriteOffset_temp1; privacy = 1; } if (pucRead[uiBytesReadOffset] == 0 && pucRead[uiBytesReadOffset + 1] == 0 && pucRead[uiBytesReadOffset + 2] == 0 && pucRead[uiBytesReadOffset + 3] == 1 && (pucRead[uiBytesReadOffset + 4] == SVAC_CRR_DP || pucRead[uiBytesReadOffset + 4] == SVAC_CRR_DL || pucRead[uiBytesReadOffset + 4] == SVAC_CRR_L || pucRead[uiBytesReadOffset + 4] == SVAC_CRR_RL || pucRead[uiBytesReadOffset + 4] == SVAC_IDR || pucRead[uiBytesReadOffset + 4] == SVAC_RAP_I || pucRead[uiBytesReadOffset + 4] == SVAC_NON_RAP)) { if (privacy == 1) { uiWriteOffset_temp1 = uiWriteOffset; uiWriteOffset = uiWriteOffset_temp0; } pucWrite = pBuffer2; privacy = 0; patch_flag = 0; } #endif #if NAL if (2 <= uiZeroCount && 0x03 == pucRead[uiBytesReadOffset]) { if (uiBytesReadOffset >= uiBytesRead) { break; } uiZeroCount = 0; uiBytesReadOffset++; ucCurByte = pucRead[uiBytesReadOffset]; pucWrite[uiWriteOffset] = pucRead[uiBytesReadOffset]; } else if (2 <= uiZeroCount && 0x00 == pucRead[uiBytesReadOffset]) { if (uiBytesReadOffset >= uiBytesRead) { break; } assert(pucRead[uiBytesReadOffset + 1] == 1); uiZeroCount = 0; uiBytesReadOffset++; ucCurByte = pucRead[uiBytesReadOffset]; pucWrite[uiWriteOffset] = pucRead[uiBytesReadOffset]; } else if (2 <= uiZeroCount && 0x02 == pucRead[uiBytesReadOffset]) { assert(0); } #else if (2 <= uiZeroCount && 0x02 == pucRead[uiBytesReadOffset]) { pucWrite[uiWriteOffset] = ((pucRead[uiBytesReadOffset] >> 2) << (uiBitsReadOffset + 2)); uiBitsReadOffset += 2; uiZeroCount = 0; if (uiBitsReadOffset >= 8) { uiBitsReadOffset = 0; continue; } if (uiBytesReadOffset >= uiBytesRead) { break; } } #endif else if (2 <= uiZeroCount && 0x01 == pucRead[uiBytesReadOffset]) { #if !NAL uiBitsReadOffset = 0; #endif pucWrite[uiWriteOffset] = pucRead[uiBytesReadOffset]; } else { #if NAL pucWrite[uiWriteOffset] = pucRead[uiBytesReadOffset]; #else pucWrite[uiWriteOffset] = (pucRead[uiBytesReadOffset] << uiBitsReadOffset); #endif } #if !NAL if (uiBytesReadOffset + 1 < uiBytesRead) { pucWrite[uiWriteOffset] |= (pucRead[uiBytesReadOffset + 1] >> (8 - uiBitsReadOffset)); } #endif uiWriteOffset++; if (0x00 == ucCurByte) { uiZeroCount++; } else { uiZeroCount = 0; } } #if CU_LEVEL_PRIVACY if (privacy == 1) { privacy_size[0] = uiWriteOffset; uiWriteOffset_temp1 = uiWriteOffset; } else { uiWriteOffset_temp0 = uiWriteOffset; privacy_size[0] = uiWriteOffset_temp1; } //uiWriteOffset = uiWriteOffset_temp0 + uiWriteOffset_temp1; //// th just clear the remaining bits in the buffer //for (unsigned int ui = uiWriteOffset; ui < uiBytesRead; ui++) //{ // pBuffer2[uiWriteOffset_temp0++] = 0; // bs_buf3[uiWriteOffset_temp1++] = 0; //} uiWriteOffset = uiWriteOffset_temp0; #else // th just clear the remaining bits in the buffer for (unsigned int ui = uiWriteOffset; ui < uiBytesRead; ui++) { pucWrite[ui] = 0; } #endif memcpy(pBuffer, pBuffer2, uiWriteOffset); pBuffer[uiWriteOffset] = 0x00; pBuffer[uiWriteOffset + 1] = 0x00; pBuffer[uiWriteOffset + 2] = 0x01; #if FIX_DEAD_LOOP pBuffer[uiWriteOffset + 3] = 0x00; #endif #if LIB_PIC_ERR_TOL bs_real_size = uiWriteOffset + 4; #endif return uiBytesRead; } static int read_a_bs(FILE * fp, int * pos, unsigned char * bs_buf, unsigned char * bs_buf2 #if CU_LEVEL_PRIVACY , unsigned char * bs_buf3,int *bs_buf3_size #endif #if SVAC_UD_MD5_STREAM , COM_BITB * bitb #endif ) { int read_size, bs_size; unsigned char b = 0; bs_size = 0; read_size = 0; if (!fseek(fp, *pos, SEEK_SET)) { int ret = 0; ret = xFindNextStartCode(fp, &bs_size, bs_buf); if (ret == -1) { v2print("End of file\n"); return -1; } #if SVAC_UD_MD5_STREAM memcpy(bitb->addr3, bs_buf, bs_size); bitb->addr3 = (unsigned char *)bitb->addr3 + (unsigned int)bs_size; assert(((u8 *)bitb->addr3 - (u8 *)bitb->addr3_beg) <= MAX_BS_BUF); #endif read_size = initParsingConvertPayloadToRBSP(bs_size, bs_buf, bs_buf2 #if CU_LEVEL_PRIVACY , bs_buf3, bs_buf3_size #endif ); } else { v0print("Cannot seek bitstream!\n"); return -1; } return read_size; } static int print_stat(DEC_STAT * stat, int ret) { #if LIBVC_ON char *stype = NULL; #else char stype = 0; #endif int i, j; if(COM_SUCCEEDED(ret)) { if (stat->ctype == COM_CT_SLICE || stat->ctype == COM_CT_PICTURE) { #if LIBVC_ON if (stat->is_RLpic_flag) { stype = "RL"; } else { switch (stat->stype) { case COM_ST_I: stype = "I"; break; case COM_ST_P: stype = "P"; break; case COM_ST_B: stype = "B"; break; #if SVAC_NAL case COM_ST_IDR: stype = "IDR"; break; case COM_ST_CRA: stype = "CRA"; break; #endif case COM_ST_UNKNOWN: default: stype = "U"; break; } } #else switch (stat->stype) { case COM_ST_I: stype = 'I'; break; case COM_ST_P: stype = 'P'; break; case COM_ST_B: stype = 'B'; break; case COM_ST_UNKNOWN: default: stype = 'U'; break; } #endif } if(stat->ctype == COM_CT_SLICE) { #if LIBVC_ON v1print("%2s-slice", stype); #else v1print("%c-slice", stype); #endif v1print(" (poc=%d) ", (int)stat->poc); #if TSVC_OPT v1print("(temporal_id = %d)", (int)stat->temporal_id); #endif } #if TSVC_OPT else if (stat->ctype == COM_CT_SIGN) { v1print("sei message\n"); printf(" num_of_temporal_level %d\n", stat->temporal_layer_num); for (int i = 0; i < stat->temporal_layer_num; i++) { printf(" temporal_fps %d ", stat->temporal_fps[i]); printf(" temporal_bitrate_low %d ", stat->temporal_bitrate_low[i]); printf(" temporal_bitrate_up %d \n", stat->temporal_bitrate_up[i]); } } #endif else if(stat->ctype == COM_CT_SQH) { #if HLS_OPT_PPS v1print("SPS"); #else v1print("Sequence header"); #endif #if PRINT_SQH_PARAM_DEC printf( "\n*** HLS Params: bitDep %d", stat->internal_bit_depth ); #if PHASE_2_PROFILE printf(" profile 0x%x", stat->profile_id); #endif #if CFG_LEVEL_ID printf(" level_id 0x%x", stat->level_id); #endif #if ENHANCE_TSPCM printf("\n*** Intra tools: TSCPM %d Enhance_TSCPM %d IPF %d IntraDT %d IPCM %d", (stat->intra_tools >> 0) & 0x1, (stat->intra_tools >> 1) & 0x1, (stat->intra_tools >> 2) & 0x1, (stat->intra_tools >> 3) & 0x1, (stat->intra_tools >> 4) & 0x1); #if MIPF printf(" MIPF %d", (stat->intra_tools >> 5) & 0x1); #endif #else printf( "\n*** Intra tools: TSCPM %d IPF %d IntraDT %d IPCM %d", (stat->intra_tools >> 0) & 0x1, (stat->intra_tools >> 1) & 0x1, (stat->intra_tools >> 2) & 0x1, (stat->intra_tools >> 3) & 0x1 ); #if MIPF printf(" MIPF %d", (stat->intra_tools >> 4) & 0x1); #endif #endif #if PMC || EPMC printf(" PMC %d", (stat->intra_tools >> 6) & 0x1); #endif #if IPF_CHROMA printf(" IPF_CHROMA %d", (stat->intra_tools >> 7) & 0x01); #endif #if IIP printf(" IIP %d", (stat->intra_tools >> 8) & 0x01); #endif #if SAWP printf(" SAWP %d", (stat->intra_tools >> 9) & 0x01); #endif // SAWP #if AWP printf("\n*** Inter tools: AFFINE %d AMVR %d UMVE %d EMVR %d SMVD %d AWP %d HMVP %d ", (stat->inter_tools >> 0) & 0x1, (stat->inter_tools >> 1) & 0x1, (stat->inter_tools >> 2) & 0x1, (stat->inter_tools >> 3) & 0x1, (stat->inter_tools >> 4) & 0x1, (stat->inter_tools >> 5) & 0x1, (stat->inter_tools >> 10) & 0xf); #else printf( "\n*** Inter tools: AFFINE %d AMVR %d UMVE %d EMVR %d SMVD %d HMVP %d ", (stat->inter_tools >> 0) & 0x1, (stat->inter_tools >> 1) & 0x1, (stat->inter_tools >> 2) & 0x1, (stat->inter_tools >> 3) & 0x1, (stat->inter_tools >> 4) & 0x1, (stat->inter_tools >> 10) & 0xf ); #endif printf( "\n*** Trans tools: NSST %d PBT %d ", (stat->trans_tools >> 0) & 0x1, (stat->trans_tools >> 1) & 0x1 ); printf("\n*** Filter tools: SAO %d ALF %d ", (stat->filte_tools >> 0) & 0x1, (stat->filte_tools >> 1) & 0x1); printf( "\n*** SCC tools: "); #if FIMC printf( " FIMC %d ", (stat->scc_tools >> 0) & 0x1); #endif #if IBC_BVP printf(" HBVP %d ", (stat->scc_tools >> 1) & 0xf); #endif #endif } #if HLS_OPT_PPS else if (stat->ctype == COM_CT_PPS) { v1print("PPS"); #if HLS_OPT_PPS printf(" pps_id %d", stat->pps_id); #endif } #endif else if (stat->ctype == COM_CT_PICTURE) { #if LIBVC_ON v1print("%2s-picture header", stype); #else v1print("%c-picture header", stype); #endif #if HLS_OPT_PPS printf(" pic_pps_id %d", stat->pic_pps_id); #endif } else if( stat->ctype == COM_CT_SEQ_END ) { v1print( "video_sequence_end_code" ); } #if LIB_PIC_MIXBIN else if (stat->ctype == COM_CT_CRR_SLICE_IMCOPLETE || stat->ctype == COM_CT_CRR_SLICE) { v0print("L-slice"); #if LIBPIC_DISPLAY if (!stat->is_dp_crr) #endif v1print(" (patch_idx=%d) ", (int)stat->patch_idx); } #endif #if SVAC_SECURITY_PARAM_SET else if (stat->ctype == COM_CT_SEC_PARA_SET) { v1print("security parameter set"); } #endif #if SVAC_AUTHENTICATION else if (stat->ctype == COM_CT_AUTH) { v1print("authentication data"); } #endif else { v0print("Unknown bitstream"); } if (stat->ctype == COM_CT_SLICE) { for (i = 0; i < 2; i++) { #if LIBVC_ON if (stat->is_RLpic_flag) { v1print("[Lib%d ", i); } else #endif { v1print("[L%d ", i); } #if MULTI_LAYER_FRAMEWORK for (j = 0; j < stat->refpic_num[i]; j++) { if (stat->reflib[i][j] == 1) v1print("LIB"); if (stat->reflib[i][j] == 2) v1print("(l%d)", stat->reflayer[i][j]); v1print("%d ", stat->refpic[i][j]); } #else for (j = 0; j < stat->refpic_num[i]; j++) v1print("%d ", stat->refpic[i][j]); #endif v1print("] "); } } if (ret == COM_OK) { v1print("\n"); } else if(ret == COM_OK_FRM_DELAYED) { v1print("->Frame delayed\n"); } else if(ret == COM_OK_DIM_CHANGED) { v1print("->Resolution changed\n"); } else { v1print("->Unknown OK code = %d\n", ret); } } else { v0print("Decoding error = %d\n", ret); } return 0; } static int set_extra_config(DEC id) { int ret, size, value; if(op_use_pic_signature) { value = 1; size = 4; ret = dec_config(id, DEC_CFG_SET_USE_PIC_SIGNATURE, &value, &size); if(COM_FAILED(ret)) { v0print("failed to set config for picture signature\n"); return -1; } } #if CU_LEVEL_PRIVACY if (op_user_permission) { value = 1; size = 4; ret = dec_config(id, DEC_CFG_SET_USER_PERMISSION, &value, &size); if (COM_FAILED(ret)) { v0print("failed to set config for picture signature\n"); return -1; } } #endif return 0; } static int write_dec_img(DEC id, char * fname, COM_IMGB * img, int bit_depth_internal) { COM_IMGB* imgb_t = NULL; if (imgb_t == NULL) { imgb_t = imgb_alloc(img->width[0], img->height[0], COM_COLORSPACE_YUV420, bit_depth_internal); if (imgb_t == NULL) { v0print("failed to allocate temporay image buffer\n"); return -1; } } if (op_bit_depth_output_cfg == 0) { op_bit_depth_output = bit_depth_internal; } else { op_bit_depth_output = op_bit_depth_output_cfg; } imgb_cpy_conv_rec(imgb_t, img, op_bit_depth_output, bit_depth_internal); DEC_CTX *ctx = (DEC_CTX *)id; int dec_width = imgb_t->width[0]; int dec_height = imgb_t->height[0]; if (op_clip_org_size) { #if MULTI_LAYER_FRAMEWORK dec_width = ctx->info.sqh.horizontal_size[ctx->layer_id]; dec_height = ctx->info.sqh.vertical_size[ctx->layer_id]; #else dec_width = ctx->info.sqh.horizontal_size; dec_height = ctx->info.sqh.vertical_size; #endif } #if LIBVC_ON if (imgb_write(fname, imgb_t, op_bit_depth_output, dec_width, dec_height)) return -1; #else if (imgb_write(op_fname_out, img, dec_width, dec_height)) return -1; #endif if (imgb_t) { imgb_free(imgb_t); } return COM_OK; } #if LIBVC_ON void set_livcdata_dec(DEC id_lib, LibVCData *libvc_data) { DEC_CTX * tmp_ctx = (DEC_CTX *)id_lib; tmp_ctx->dpm.libvc_data = libvc_data; } int decode_libpics(DEC_CDSC * cdsc, LibVCData* libvc_data) { STATES state_lib = STATE_DECODING; unsigned char * bs_buf_lib = NULL; unsigned char * bs_buf_lib2 = NULL; DEC id_lib = NULL; COM_BITB bitb_lib; COM_IMGB * imgb_lib; DEC_STAT stat_lib; int ret; COM_CLK clk_beg_lib, clk_tot_lib; int bs_cnt_lib, pic_cnt_lib; int bs_size_lib, bs_read_pos_lib = 0; int width_lib, height_lib; FILE * fp_bs_lib = NULL; #if LINUX signal(SIGSEGV, handler); // install our handler #endif #if DECODING_TIME_TEST clk_beg_lib = com_clk_get(); #endif /* open input bitstream */ fp_bs_lib = fopen(op_fname_inp_libpics, "rb"); if (fp_bs_lib == NULL) { v0print("ERROR: cannot open libpics bitstream file = %s\n", op_fname_inp_libpics); print_usage(); return -1; } if (op_flag[OP_FLAG_FNAME_OUT_LIBPICS]) { /* remove decoded file contents if exists */ FILE * fp; fp = fopen(op_fname_out_libpics, "wb"); if (fp == NULL) { v0print("ERROR: cannot create a decoded libpics file\n"); print_usage(); return -1; } fclose(fp); } bs_buf_lib = malloc(MAX_BS_BUF); if (bs_buf_lib == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } bs_buf_lib2 = malloc(MAX_BS_BUF); if (bs_buf_lib2 == NULL) { v0print("ERROR: cannot allocate bit buffer, size2=%d\n", MAX_BS_BUF); return -1; } #if CU_LEVEL_PRIVACY unsigned char *bs_buf_lib3 = malloc(MAX_BS_BUF); if (bs_buf_lib3 == NULL) { v0print("ERROR: cannot allocate bit buffer, size2=%d\n", MAX_BS_BUF); return -1; } #endif #if SVAC_UD_MD5_STREAM unsigned char * bs_buf4 = NULL; unsigned char * bs_buf5 = NULL; bs_buf5 = malloc(MAX_BS_BUF); if (bs_buf5 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } bitb_lib.addr3 = bs_buf5; bitb_lib.addr3_beg = bs_buf5; bs_buf4 = malloc(MAX_BS_BUF); if (bs_buf4 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } unsigned char * buf4_p = bs_buf4; unsigned char * buf4_beg = bs_buf4; #endif id_lib = dec_create(cdsc, NULL); if (id_lib == NULL) { v0print("ERROR: cannot create decoder\n"); return -1; } set_livcdata_dec(id_lib, libvc_data); if (set_extra_config(id_lib)) { v0print("ERROR: cannot set extra configurations\n"); return -1; } pic_cnt_lib = 0; clk_tot_lib = 0; bs_cnt_lib = 0; width_lib = height_lib = 0; #if CU_LEVEL_PRIVACY int bs_buf3_size = 0; #endif while (1) { if (state_lib == STATE_DECODING) { bs_size_lib = read_a_bs(fp_bs_lib, &bs_read_pos_lib, bs_buf_lib, bs_buf_lib2 #if CU_LEVEL_PRIVACY , bs_buf_lib3, &bs_buf3_size #endif #if SVAC_UD_MD5_STREAM , &bitb_lib #endif ); if (bs_size_lib <= 0) { state_lib = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } bs_read_pos_lib += (bs_size_lib); bitb_lib.addr = bs_buf_lib; bitb_lib.ssize = bs_size_lib; bitb_lib.bsize = MAX_BS_BUF; #if CU_LEVEL_PRIVACY bitb_lib.addr2 = bs_buf_lib3; bitb_lib.ssize2 = bs_buf3_size; #endif #if !DECODING_TIME_TEST clk_beg_lib = com_clk_get(); #endif /* main decoding block */ ret = dec_cnk((DEC_CTX *)id_lib, &bitb_lib, &stat_lib); if (COM_FAILED(ret)) { v0print("failed to decode bitstream\n"); return -1; } #if !DECODING_TIME_TEST clk_tot_lib += com_clk_from(clk_beg_lib); #endif } if (stat_lib.fnum >= 0 || state_lib == STATE_BUMPING) { ret = dec_pull_frm((DEC_CTX *)id_lib, &imgb_lib, state_lib); if (ret == COM_ERR_UNEXPECTED) { v1print("bumping process completed\n"); goto END; } else if (COM_FAILED(ret)) { v0print("failed to pull the decoded image\n"); return -1; } } else { imgb_lib = NULL; } if (imgb_lib) { width_lib = imgb_lib->width[0]; height_lib = imgb_lib->height[0]; if (op_flag[OP_FLAG_FNAME_OUT_LIBPICS]) { write_dec_img(id_lib, op_fname_out_libpics, imgb_lib, ((DEC_CTX *)id_lib)->info.bit_depth_internal); } imgb_lib->release(imgb_lib); pic_cnt_lib++; } } END: #if DECODING_TIME_TEST clk_tot_lib += com_clk_from(clk_beg_lib); #endif libvc_data->num_lib_pic = pic_cnt_lib; #if CU_LEVEL_PRIVACY if (bs_buf_lib3) { free(bs_buf_lib3); bs_buf_lib3 = NULL; } #endif if (id_lib) dec_delete(id_lib); if (fp_bs_lib) fclose(fp_bs_lib); if (bs_buf_lib) free(bs_buf_lib); return 0; } #endif int main(int argc, const char **argv) { FILE *fp = fopen("dec_decode_cu.log", "w"); if (fp) fclose(fp); STATES state = STATE_DECODING; unsigned char * bs_buf = NULL; unsigned char * bs_buf2 = NULL; #if SVAC_UD_MD5_STREAM unsigned char * bs_buf4 = NULL; unsigned char * bs_buf5 = NULL; #endif #if MULTI_LAYER_FRAMEWORK DEC id[MAX_LAYER] = { NULL, NULL }; DEC_CDSC cdsc[MAX_LAYER]; #else DEC id = NULL; DEC_CDSC cdsc; #endif COM_BITB bitb; COM_IMGB * imgb; DEC_STAT stat; int ret; COM_CLK clk_beg, clk_tot; int bs_cnt, pic_cnt; int bs_size = 0, bs_read_pos = 0; int width, height; FILE * fp_bs = NULL; #if LIB_PIC_ERR_TOL int libpic_num_patch = 0; int *libpic_bs_size = NULL; unsigned char * libpic_bs_buf = NULL; int num_nalu = 0; int collect_libpic_state = 0; unsigned int libpic_addr = 0; #endif #if SVAC_AI_SEG_EXT fp_seg = fopen("dec_aiseg.bin", "wb"); #endif #if ENC_DEC_TRACE fp_trace = NULL; #endif #if CU_LEVEL_PRIVACY unsigned int libpic_addr_privacy = 0; int *libpic_bs_size_privacy = NULL; unsigned char * libpic_bs_buf_privacy = NULL; int num_nalu_privacy = 0; #endif #if LINUX signal(SIGSEGV, handler); // install our handler #endif #if DECODING_TIME_TEST clk_beg = com_clk_get(); #endif /* parse options */ ret = com_args_parse_all(argc, argv, options); if(ret != 0) { if(ret > 0) v0print("-%c argument should be set\n", ret); print_usage(); return -1; } /* open input bitstream */ fp_bs = fopen(op_fname_inp, "rb"); if(fp_bs == NULL) { v0print("ERROR: cannot open bitstream file = %s\n", op_fname_inp); print_usage(); return -1; } if(op_flag[OP_FLAG_FNAME_OUT]) { /* remove decoded file contents if exists */ FILE * fp; #if MULTI_LAYER_FRAMEWORK fp = fopen(op_fname_out[0], "wb"); #else fp = fopen(op_fname_out, "wb"); #endif if(fp == NULL) { v0print("ERROR: cannot create a decoded file\n"); print_usage(); return -1; } fclose(fp); } #if MULTI_LAYER_FRAMEWORK if (op_flag[OP_FLAG_FNAME_OUT1]) { /* remove decoded file contents if exists */ FILE* fp; fp = fopen(op_fname_out[1], "wb"); if (fp == NULL) { v0print("ERROR: cannot create a EL decoded file\n"); print_usage(); return -1; } fclose(fp); } #endif bs_buf = malloc(MAX_BS_BUF); if(bs_buf == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } bs_buf2 = malloc(MAX_BS_BUF); if (bs_buf2 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } #if SVAC_UD_MD5_STREAM bs_buf5 = malloc(MAX_BS_BUF); if (bs_buf5 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } bitb.addr3 = bs_buf5; bitb.addr3_beg = bs_buf5; bs_buf4 = malloc(MAX_BS_BUF); if (bs_buf4 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } unsigned char * buf4_p = bs_buf4; unsigned char * buf4_beg = bs_buf4; #endif #if CU_LEVEL_PRIVACY unsigned char *bs_buf3 = malloc(MAX_BS_BUF); if (bs_buf3 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } #endif #if LIBVC_ON #if MULTI_LAYER_FRAMEWORK LibVCData libvc_data[MAX_LAYER]; for (int i = 0; i < MAX_LAYER; i++) { init_libvcdata(&libvc_data[i]); } #else LibVCData libvc_data; init_libvcdata(&libvc_data); #endif if (op_flag[OP_FLAG_FNAME_INP_LIBPICS]) { #if MULTI_LAYER_FRAMEWORK int err; for (int i = 0; i < MAX_LAYER; i++) { err = decode_libpics(&cdsc[i], &libvc_data[i]); if (err) { v0print("Error when decode lib pic!"); return -1; } libvc_data[i].is_libpic_prepared = 1; } #else int err = decode_libpics(&cdsc, &libvc_data); if (err) { v0print("Error when decode lib pic!"); return -1; } libvc_data.is_libpic_prepared = 1; #endif } #endif #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { id[i] = dec_create(&cdsc[i], NULL); dec_setlayer(id[i],i); if (id[i] == NULL) { v0print("ERROR: cannot create decoder\n"); return -1; } } #else id = dec_create(&cdsc, NULL); if(id == NULL) { v0print("ERROR: cannot create decoder\n"); return -1; } #endif #if LIBVC_ON #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { set_livcdata_dec(id[i], &libvc_data[i]); } #else set_livcdata_dec(id, &libvc_data); #endif #endif #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { if (set_extra_config(id[i])) { v0print("ERROR: cannot set extra configurations\n"); return -1; } } #else if (set_extra_config(id)) { v0print("ERROR: cannot set extra configurations\n"); return -1; } #endif pic_cnt = 0; clk_tot = 0; bs_cnt = 0; width = height = 0; #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { g_CountDOICyCleTime[i] = 0; // initialized the number . g_DOIPrev[i] = 0; } #else g_CountDOICyCleTime = 0; // initialized the number . g_DOIPrev = 0; #endif #if CU_LEVEL_PRIVACY int bs_buf3_size = 0; #endif while (1) { #if MULTI_LAYER_FRAMEWORK int nal_layer_id = 0; #endif if (state == STATE_DECODING) { bs_size = read_a_bs(fp_bs, &bs_read_pos, bs_buf, bs_buf2 #if CU_LEVEL_PRIVACY , bs_buf3, &bs_buf3_size #endif #if SVAC_UD_MD5_STREAM , &bitb #endif ); if (bs_size <= 0) { state = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } bs_read_pos += bs_size; bitb.addr = bs_buf; #if CU_LEVEL_PRIVACY bitb.addr2 = bs_buf3; bitb.ssize2 = bs_buf3_size; bitb.ssize = bs_size - bs_buf3_size; #else bitb.ssize = bs_size; #endif bitb.bsize = MAX_BS_BUF; #if MULTI_LAYER_FRAMEWORK nal_layer_id = (bs_buf[4] >> 1) & 0x07; if (nal_layer_id == 0) { v1print("BL---[%4d]-th BS (%07dbytes) --> ", bs_cnt++, bs_size); } else { v1print("EL---[%4d]-th BS (%07dbytes) --> ", bs_cnt++, bs_size); } #else v1print("[%4d]-th BS (%07dbytes) --> ", bs_cnt++, bs_size); #endif #if LIB_PIC_ERR_TOL #if SVAC_PROGRESSIVE // 7 6 5 4 3 & 2 // temporal_nesting library_picture_enable library_stream duplicate_sqh library_picture_mode_index int library_picture_enable = bs_buf[7] & 0x40; int library_stream_flag = bs_buf[7] & 0x20; int library_picture_mode_index = (bs_buf[7] >> 2) & 3; #else // 7 6 5 4 3 2 1 & 0 // progressive_sequence field_coded_sequence temporal_nesting library_picture_enable library_stream duplicate_sqh library_picture_mode_index int library_picture_enable = bs_buf[7] & 0x10; int library_picture_enable_flag = bs_buf[7] & 8; #if EMULATION_PREVENT_BUGFIX int library_picture_mode_index = bs_buf[7] & 3; #else int library_picture_mode_index = ((bs_buf[7] & 1) << 1) + (bs_buf[8] >> 7); #endif #endif if (bs_buf[3] == SVAC_SPS && library_stream_flag && library_picture_mode_index == 0) { if (libpic_bs_buf == NULL) { libpic_bs_buf = malloc(MAX_BS_BUF); if (libpic_bs_buf == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } } if (libpic_bs_size == NULL) { libpic_bs_size = malloc(sizeof(int) * 260); if (libpic_bs_size == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } } #if CU_LEVEL_PRIVACY if (libpic_bs_buf_privacy == NULL) { libpic_bs_buf_privacy = malloc(MAX_BS_BUF); if (libpic_bs_buf_privacy == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } } if (libpic_bs_size_privacy == NULL) { libpic_bs_size_privacy = malloc(sizeof(int) * 260); if (libpic_bs_size_privacy == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } } num_nalu_privacy = 0; #endif memcpy(libpic_bs_buf, bs_buf, bs_real_size); state = STATE_LIBPIC_COLLECTING; libpic_bs_size[0] = bs_real_size; collect_libpic_state = 1; num_nalu = 1; libpic_addr = bs_real_size; #if SVAC_UD_MD5_STREAM unsigned int tmp_bs_size = (unsigned int)((unsigned char *)bitb.addr3 - (unsigned char *)bitb.addr3_beg); memcpy(buf4_p, bitb.addr3_beg, tmp_bs_size); buf4_p = buf4_p + tmp_bs_size; bitb.addr3 = (unsigned char *)bitb.addr3_beg; #endif continue; } else if (bs_buf[3] == SVAC_SPS && library_picture_enable && library_stream_flag == 0 && library_picture_mode_index == 0) { libpic_addr = 0; #if CU_LEVEL_PRIVACY libpic_addr_privacy = 0; #endif #if SVAC_UD_MD5_STREAM bitb.addr3_beg = buf4_beg; buf4_beg = bs_buf5; unsigned char * tmp_p = buf4_p; buf4_p = bitb.addr3; bitb.addr3 = tmp_p; #endif for (int i = 0; i < num_nalu; i++) { #if !DECODING_TIME_TEST clk_beg = com_clk_get(); #endif /* main decoding block */ bitb.addr = libpic_bs_buf + libpic_addr; bitb.ssize = libpic_bs_size[i] - 4; bitb.bsize = MAX_BS_BUF; libpic_addr += libpic_bs_size[i]; #if CU_LEVEL_PRIVACY if (i >= num_nalu - num_nalu_privacy) { bitb.addr2 = libpic_bs_buf_privacy + libpic_addr_privacy; bitb.ssize2 = libpic_bs_size_privacy[i - num_nalu + num_nalu_privacy] + 4 ; libpic_addr_privacy += libpic_bs_size_privacy[i - num_nalu + num_nalu_privacy]; } #endif #if MULTI_LAYER_FRAMEWORK ret = dec_cnk((DEC_CTX*)id[0], &bitb, &stat); #else ret = dec_cnk((DEC_CTX*)id, &bitb, &stat); #endif if (stat.ctype == COM_CT_SEQ_END) { state = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } if (COM_FAILED(ret)) { v0print("failed to decode bitstream\n"); return -1; } #if !DECODING_TIME_TEST clk_tot += com_clk_from(clk_beg); #endif print_stat(&stat, ret); } #if SVAC_UD_MD5_STREAM bitb.addr3_beg = buf4_beg; bitb.addr3 = buf4_p; buf4_beg = bs_buf4; buf4_p = bs_buf4; #endif num_nalu = 0; libpic_addr = 0; bitb.addr = bs_buf; bitb.ssize = bs_size; bitb.bsize = MAX_BS_BUF; } #endif #if !DECODING_TIME_TEST clk_beg = com_clk_get(); #endif /* main decoding block */ #if MULTI_LAYER_FRAMEWORK if (nal_layer_id == 0) { DEC_CTX* ctx_t = (DEC_CTX*)id[0]; ctx_t->ctx_e = id[1]; ret = dec_cnk((DEC_CTX*)id[0], &bitb, &stat); } else { DEC_CTX* ctx_e = (DEC_CTX*)id[nal_layer_id]; assert(ctx_e->layer_id == nal_layer_id); if (!ctx_e->init_sps_pps) { DEC_CTX* ctx_b = (DEC_CTX*)id[0]; ctx_e->ctx_b =id[ctx_b->info.sqh.ref_layer_id[nal_layer_id]]; COM_SQH* sqh_e = &ctx_e->info.sqh; COM_SQH* sqh_b = &ctx_b->info.sqh; memcpy(sqh_e, sqh_b, sizeof(COM_SQH)); COM_PIC_PARA_SET* pps_e = &ctx_e->info.pps[0]; memcpy(pps_e, ctx_b->info.pps, sizeof(COM_PIC_PARA_SET)); #if LIBVC_ON ctx_e->dpm.libvc_data->is_libpic_processing = sqh_b->library_stream_flag; ctx_e->dpm.libvc_data->library_picture_enable_flag = sqh_b->library_picture_enable_flag; #endif #if HIGH_LEVEL_PRIVACY COM_PRIVACY* pri_e = &ctx_e->ctx_privacy_data; COM_PRIVACY* pri_b = &ctx_b->ctx_privacy_data; memcpy(pri_e, pri_b, sizeof(COM_PRIVACY)); #endif } ret = dec_cnk((DEC_CTX*)id[nal_layer_id], &bitb, &stat); } #else ret = dec_cnk((DEC_CTX*)id, &bitb, &stat); #endif if (stat.ctype == COM_CT_SEQ_END) { state = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } if (COM_FAILED(ret)) { v0print("failed to decode bitstream\n"); return -1; } #if !DECODING_TIME_TEST clk_tot += com_clk_from(clk_beg); #endif print_stat(&stat, ret); } #if LIB_PIC_ERR_TOL if (state == STATE_LIBPIC_COLLECTING) { bs_size = read_a_bs(fp_bs, &bs_read_pos, bs_buf, bs_buf2 #if CU_LEVEL_PRIVACY , bs_buf3, &bs_buf3_size #endif #if SVAC_UD_MD5_STREAM , &bitb #endif ); if (bs_size <= 0) { state = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } bs_read_pos += bs_size; bitb.addr = bs_buf; bitb.ssize = bs_size; bitb.bsize = MAX_BS_BUF; #if CU_LEVEL_PRIVACY bitb.addr2 = bs_buf3; bitb.ssize2 = bs_buf3_size; #endif v1print("[%4d]-th BS (%07dbytes) --> ", bs_cnt++, bs_size); if (bs_buf[3] == SVAC_PPS && collect_libpic_state == 1) { memcpy(libpic_bs_buf + libpic_addr, bs_buf, bs_real_size); libpic_bs_size[num_nalu++] = bs_real_size; collect_libpic_state = 2; libpic_addr += bs_real_size; #if SVAC_UD_MD5_STREAM unsigned int tmp_bs_size = (unsigned int)((unsigned char *)bitb.addr3 - (unsigned char *)bitb.addr3_beg); memcpy(buf4_p, bitb.addr3_beg, tmp_bs_size); buf4_p = buf4_p + tmp_bs_size; bitb.addr3 = (unsigned char *)bitb.addr3_beg; #endif continue; } else if (bs_buf[3] == SVAC_PH && collect_libpic_state == 2) { memcpy(libpic_bs_buf + libpic_addr, bs_buf, bs_real_size); libpic_bs_size[num_nalu++] = bs_real_size; collect_libpic_state = 3; libpic_addr += bs_real_size; #if SVAC_UD_MD5_STREAM unsigned int tmp_bs_size = (unsigned int)((unsigned char *)bitb.addr3 - (unsigned char *)bitb.addr3_beg); memcpy(buf4_p, bitb.addr3_beg, tmp_bs_size); buf4_p = buf4_p + tmp_bs_size; bitb.addr3 = (unsigned char *)bitb.addr3_beg; #endif continue; } else if (bs_buf[3] == SVAC_CRR_DL) { memcpy(libpic_bs_buf + libpic_addr, bs_buf, bs_real_size); libpic_bs_size[num_nalu++] = bs_real_size; assert(collect_libpic_state == 3 || collect_libpic_state == 4); libpic_addr += bs_real_size; #if SVAC_UD_MD5_STREAM unsigned int tmp_bs_size = (unsigned int)((unsigned char *)bitb.addr3 - (unsigned char *)bitb.addr3_beg); memcpy(buf4_p, bitb.addr3_beg, tmp_bs_size); buf4_p = buf4_p + tmp_bs_size; bitb.addr3 = (unsigned char *)bitb.addr3_beg; #endif #if CU_LEVEL_PRIVACY memcpy(libpic_bs_buf_privacy + libpic_addr_privacy, bs_buf3, bs_buf3_size); libpic_bs_size_privacy[num_nalu_privacy++] = bs_buf3_size; libpic_addr_privacy += bs_buf3_size; #endif if (collect_libpic_state == 3) collect_libpic_state = 4; else if (collect_libpic_state == 4) { state = STATE_DECODING; } continue; } else if (bs_buf[3] == SVAC_CRR_L) { memcpy(libpic_bs_buf + libpic_addr, bs_buf, bs_real_size); libpic_bs_size[num_nalu++] = bs_real_size; assert(collect_libpic_state == 3 || collect_libpic_state == 4); libpic_addr += bs_real_size; #if CU_LEVEL_PRIVACY memcpy(libpic_bs_buf_privacy + libpic_addr_privacy, bs_buf3, bs_buf3_size); libpic_bs_size_privacy[num_nalu_privacy++] = bs_buf3_size; libpic_addr_privacy += bs_buf3_size; #endif #if SVAC_UD_MD5_STREAM unsigned int tmp_bs_size = (unsigned int)((unsigned char *)bitb.addr3 - (unsigned char *)bitb.addr3_beg); memcpy(buf4_p, bitb.addr3_beg, tmp_bs_size); buf4_p = buf4_p + tmp_bs_size; bitb.addr3 = (unsigned char *)bitb.addr3_beg; #endif if (collect_libpic_state == 3) { state = STATE_DECODING; } continue; } else if (bs_buf[3] == SVAC_SPS && (bs_buf[7] & 16) && (bs_buf[7] & 8) == 0) { v0print("ERROR: not recieve enough libpic NALU\n"); return -1; } #if !DECODING_TIME_TEST clk_beg = com_clk_get(); #endif /* main decoding block */ #if MULTI_LAYER_FRAMEWORK ret = dec_cnk((DEC_CTX*)id[0], &bitb, &stat); #else ret = dec_cnk((DEC_CTX*)id, &bitb, &stat); #endif if (stat.ctype == COM_CT_SEQ_END) { state = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } if (COM_FAILED(ret)) { v0print("failed to decode bitstream\n"); return -1; } #if !DECODING_TIME_TEST clk_tot += com_clk_from(clk_beg); #endif print_stat(&stat, ret); } #endif if (stat.fnum >= 0 || state == STATE_BUMPING) { #if MULTI_LAYER_FRAMEWORK ret = dec_pull_frm((DEC_CTX*)id[nal_layer_id], &imgb, state); #else ret = dec_pull_frm((DEC_CTX*)id, &imgb, state); #endif if (ret == COM_ERR_UNEXPECTED) { v1print("bumping process completed\n"); if (bs_size <= 0) { goto END; } else { state = STATE_DECODING; } } else if (COM_FAILED(ret)) { v0print("failed to pull the decoded image\n"); return -1; } } else { imgb = NULL; } if (imgb) { width = imgb->width[0]; height = imgb->height[0]; #if LIB_PIC_MIXBIN #if MULTI_LAYER_FRAMEWORK if (!((DEC_CTX*)id[0])->info.sqh.library_stream_flag #else if (!((DEC_CTX*)id)->info.sqh.library_stream_flag #endif #if LIBPIC_DISPLAY #if MULTI_LAYER_FRAMEWORK || (((DEC_CTX*)id[0])->info.sqh.library_stream_flag && ((DEC_CTX*)id[0])->info.sqh.library_picture_mode_index == 1) #else || (((DEC_CTX*)id)->info.sqh.library_stream_flag && ((DEC_CTX*)id)->info.sqh.library_picture_mode_index == 1) #endif #endif ) { #endif #if MULTI_LAYER_FRAMEWORK if (op_flag[OP_FLAG_FNAME_OUT] && nal_layer_id == 0) { write_dec_img(id[0], op_fname_out[0], imgb, ((DEC_CTX*)id[0])->info.bit_depth_internal); } if (op_flag[OP_FLAG_FNAME_OUT1] && nal_layer_id == 1) { write_dec_img(id[1], op_fname_out[1], imgb, ((DEC_CTX*)id[1])->info.bit_depth_internal); } #else if (op_flag[OP_FLAG_FNAME_OUT]) { write_dec_img(id, op_fname_out, imgb, ((DEC_CTX*)id)->info.bit_depth_internal); } #endif imgb->release(imgb); pic_cnt++; #if LIB_PIC_MIXBIN } else if (op_flag[OP_FLAG_FNAME_OUT_LIBPICS]) { #if MULTI_LAYER_FRAMEWORK write_dec_img(id[0], op_fname_out_libpics, imgb, ((DEC_CTX*)id[0])->info.bit_depth_internal); #else write_dec_img(id, op_fname_out_libpics, imgb, ((DEC_CTX*)id)->info.bit_depth_internal); #endif } #endif } } END: #if DECODING_TIME_TEST clk_tot += com_clk_from(clk_beg); #endif v1print("===========================================================\n"); v1print("Resolution (decoding) = %d x %d\n", width, height); #if MULTI_LAYER_FRAMEWORK v1print("BL Resolution (output) = %d x %d\n", ((DEC_CTX*)id[0])->info.sqh.horizontal_size[0], ((DEC_CTX*)id[0])->info.sqh.vertical_size[0]); v1print("EL1 Resolution (output) = %d x %d\n", ((DEC_CTX*)id[0])->info.sqh.horizontal_size[1], ((DEC_CTX*)id[0])->info.sqh.vertical_size[1]); #else v1print("Resolution (output) = %d x %d\n", ((DEC_CTX *)id)->info.sqh.horizontal_size, ((DEC_CTX *)id)->info.sqh.vertical_size); #endif v1print("Processed BS count = %d\n", bs_cnt); v1print("Decoded frame count = %d\n", pic_cnt); if(pic_cnt > 0) { v1print("total decoding time = %d msec,", (int)com_clk_msec(clk_tot)); v1print(" %.3f sec\n", (float)(com_clk_msec(clk_tot) /1000.0)); v1print("Average decoding time for a frame = %d msec\n", (int)com_clk_msec(clk_tot)/pic_cnt); v1print("Average decoding speed = %.3f frames/sec\n", ((float)pic_cnt*1000)/((float)com_clk_msec(clk_tot))); } v1print("===========================================================\n"); if (op_flag[OP_FLAG_USE_PIC_SIGN] && pic_cnt > 0) { v1print("Decode Match: 1 (HASH)\n"); #if SVAC_UD_MD5_STREAM #if MULTI_LAYER_FRAMEWORK if (((DEC_CTX *)id[0])->stream_sign_check_flag) #else if (((DEC_CTX *)id)->stream_sign_check_flag) #endif v1print("Stream Decode Match: 1 (HASH)\n"); #endif v1print("===========================================================\n"); } #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { if (id[i]) dec_delete(id[i]); } #else if(id) dec_delete(id); #endif if(fp_bs) fclose(fp_bs); if(bs_buf) free(bs_buf); if (bs_buf2) { free(bs_buf2); bs_buf2 = NULL; } #if CU_LEVEL_PRIVACY if (bs_buf3) { free(bs_buf3); bs_buf3 = NULL; } #endif #if SVAC_UD_MD5_STREAM if (bs_buf5) { free(bs_buf5); bs_buf5 = NULL; } if (bs_buf4) { free(bs_buf4); bs_buf4 = NULL; } #endif #if LIBVC_ON #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { delete_libvcdata(&libvc_data[i]); } #else delete_libvcdata(&libvc_data); #endif #endif #if ENC_DEC_TRACE if( fp_trace ) { fclose( fp_trace ); fp_trace = NULL; } #endif #if SVAC_AI_SEG_EXT if (fp_seg) { fclose(fp_seg); fp_seg = NULL; } #endif return 0; }解释这个代码的逻辑关系
07-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值