📄 header.c
字号:
else if (!mpeg2dec->custom_fbuf) { int i = 0; // KKHV while (mpeg2dec->alloc_index < 3) { mpeg2_fbuf_t * fbuf; int y_size, uv_size; fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf); fbuf->id = NULL; y_size = decoder->stride_frame * mpeg2dec->sequence.height; uv_size = y_size >> (2 - decoder->chroma_format); #ifndef MAE_HW fbuf->buf[0] = (uint8_t *) mpeg2_malloc (y_size, MPEG2_ALLOC_YUV); fbuf->buf[1] = (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV); fbuf->buf[2] = (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);#else if(mpeg2dec->bUseMAE) { decoder->pYUVOut[i][0] = (unsigned char *)get_yuv_buffer(i); if (decoder->pYUVOut[i][0] == NULL) { printf("\n Decoder : ERROR : could not allocate frame memory #%d\n", i); exit (EXIT_FAILURE); } decoder->pYUVOut[i][1] = (unsigned char *)(decoder->pYUVOut[i][0] + y_size); decoder->pYUVOut[i][2] = (unsigned char *)(decoder->pYUVOut[i][1] + uv_size); // We'll ovewrite the original fbuf with our own memory from the kernel space. fbuf->buf[0] = (uint8_t *)decoder->pYUVOut[i][0]; fbuf->buf[1] = (uint8_t *)decoder->pYUVOut[i][1]; fbuf->buf[2] = (uint8_t *)decoder->pYUVOut[i][2];#ifndef MAE_HW memset (fbuf->buf[0], 0, y_size + 2*uv_size);#endif //#ifndef MAE_HW i++; } else // REF Mode { fbuf->buf[0] = (uint8_t *) mpeg2_malloc (y_size, MPEG2_ALLOC_YUV); fbuf->buf[1] = (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV); fbuf->buf[2] = (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV); }#endif } mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE)); } if (decoder->bAllocated == 0) { int iDiv = 2; iDiv = (decoder->chroma_format == 1) ? 1 : 2;#ifndef MAE_HW // $PP decoder->pYOut = (unsigned char*)malloc(sizeof(unsigned char) * decoder->height * decoder->width); if (decoder->pYOut == NULL) { printf("\n C Model : ERROR : could not allocate frame memory"); exit (EXIT_FAILURE); } else memset (decoder->pYOut, 0, sizeof(unsigned char) * decoder->height * decoder->width); decoder->pCbOut = (unsigned char*)malloc(sizeof(unsigned char) * decoder->height/iDiv * decoder->width/2); if (decoder->pCbOut == NULL) { printf("\n C Model : ERROR : could not allocate frame memory"); exit (EXIT_FAILURE); } else memset (decoder->pCbOut, 0, sizeof(unsigned char) * decoder->height/iDiv * decoder->width/2); decoder->pCrOut = (unsigned char*)malloc(sizeof(unsigned char) * decoder->height/iDiv * decoder->width/2); if (decoder->pCrOut == NULL) { printf("\n C Model : ERROR : could not allocate frame memory"); exit (EXIT_FAILURE); } else memset (decoder->pCrOut, 0, sizeof(unsigned char) * decoder->height/iDiv * decoder->width/2);#else if(mpeg2dec->bUseMAE) { // Nothing to do } else { decoder->pYOut = (unsigned char*)malloc(sizeof(unsigned char) * decoder->height * decoder->width); if (decoder->pYOut == NULL) { printf("\n C Model : ERROR : could not allocate frame memory"); exit (EXIT_FAILURE); } else memset (decoder->pYOut, 0, sizeof(unsigned char) * decoder->height * decoder->width); decoder->pCbOut = (unsigned char*)malloc(sizeof(unsigned char) * decoder->height/iDiv * decoder->width/2); if (decoder->pCbOut == NULL) { printf("\n C Model : ERROR : could not allocate frame memory"); exit (EXIT_FAILURE); } else memset (decoder->pCbOut, 0, sizeof(unsigned char) * decoder->height/iDiv * decoder->width/2); decoder->pCrOut = (unsigned char*)malloc(sizeof(unsigned char) * decoder->height/iDiv * decoder->width/2); if (decoder->pCrOut == NULL) { printf("\n C Model : ERROR : could not allocate frame memory"); exit (EXIT_FAILURE); } else memset (decoder->pCrOut, 0, sizeof(unsigned char) * decoder->height/iDiv * decoder->width/2); }#endif decoder->bAllocated = 1; } } else {#ifdef MAE_HW // At this point, we are sure that this is a interlaced frame. Before we start processing the first slice of the second field, // set the topfield length. pWrapContext->interlacing_on = 1; pWrapContext->topfield_length = pWrapContext->desc_size;#endif decoder->second_field = 1; mpeg2dec->picture++; /* second field picture */ // $PP mpeg2dec->info.uiFrameCount++; mpeg2dec->decoder.iMBCount = 0; *(mpeg2dec->picture) = mpeg2dec->new_picture; mpeg2dec->info.current_picture_2nd = mpeg2dec->picture; if (low_delay || decoder->coding_type == B_TYPE) mpeg2dec->info.display_picture_2nd = mpeg2dec->picture; } info_user_data (mpeg2dec);}static int copyright_ext (mpeg2dec_t * mpeg2dec){ return 0;}static int quant_matrix_ext (mpeg2dec_t * mpeg2dec){ uint8_t * buffer = mpeg2dec->chunk_start; int i, j; for (i = 0; i < 4; i++) { if (buffer[0] & (8 >> i)) { for (j = 0; j < 64; j++) // $PP mpeg2dec->MAE_New_Quant_Matrix[i][my_mpeg2_scan_norm[j]] = mpeg2dec->new_quantizer_matrix[i][mpeg2_scan_norm[j]] = (buffer[j] << (i+5)) | (buffer[j+1] >> (3-i)); mpeg2dec->copy_matrix |= 1 << i; buffer += 64; } } return 0;}int mpeg2_header_extension (mpeg2dec_t * mpeg2dec){ static int (* parser[]) (mpeg2dec_t *) = { 0, sequence_ext, sequence_display_ext, quant_matrix_ext, copyright_ext, 0, 0, picture_display_ext, picture_coding_ext }; int ext, ext_bit; ext = mpeg2dec->chunk_start[0] >> 4; ext_bit = 1 << ext; if (!(mpeg2dec->ext_state & ext_bit)) return 0; /* ignore illegal extensions */ mpeg2dec->ext_state &= ~ext_bit; return parser[ext] (mpeg2dec);}int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec){ mpeg2dec->user_data_len += mpeg2dec->chunk_ptr - 1 - mpeg2dec->chunk_start; mpeg2dec->chunk_start = mpeg2dec->chunk_ptr - 1; return 0;}static void prescale (mpeg2dec_t * mpeg2dec, int index){ static int non_linear_scale [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72, 80, 88, 96, 104, 112 }; int i, j, k; mpeg2_decoder_t * decoder = &(mpeg2dec->decoder); if (mpeg2dec->scaled[index] != mpeg2dec->q_scale_type) { mpeg2dec->scaled[index] = mpeg2dec->q_scale_type; for (i = 0; i < 32; i++) { k = mpeg2dec->q_scale_type ? non_linear_scale[i] : (i << 1); for (j = 0; j < 64; j++) decoder->quantizer_prescale[index][i][j] = k * mpeg2dec->quantizer_matrix[index][j]; } }}#if defined(MAE_HW) && !defined(USE_CMODELIF)mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec){ mpeg2_decoder_t * decoder = &(mpeg2dec->decoder); unsigned int state = mpeg2dec->state; mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0; mpeg2dec->state = ((mpeg2dec->picture->nb_fields > 1 || mpeg2dec->state == STATE_PICTURE_2ND) ? STATE_SLICE : STATE_SLICE_1ST); if (mpeg2dec->decoder.coding_type != D_TYPE) { prescale (mpeg2dec, 0); if (decoder->chroma_quantizer[0] == decoder->quantizer_prescale[2]) prescale (mpeg2dec, 2); if (mpeg2dec->decoder.coding_type != I_TYPE) { prescale (mpeg2dec, 1); if (decoder->chroma_quantizer[1] == decoder->quantizer_prescale[3]) prescale (mpeg2dec, 3); } } if (!(mpeg2dec->nb_decode_slices)) mpeg2dec->picture->flags |= PIC_FLAG_SKIP; else if (mpeg2dec->convert_start) { mpeg2dec->convert_start (decoder->convert_id, mpeg2dec->fbuf[0], mpeg2dec->picture, mpeg2dec->info.gop); mpeg2_init_fbuf (&(mpeg2dec->decoder)); } else {#ifdef MAE_HW // Reset the DMV flag at the beginning of each frame / field // This flag will get set later if we encounter a DMV macroblock in this frame / field nDMVUpdate = nDMVUpdate1 = nDMVUpdate2 = 0;#endif mpeg2_init_fbuf (&(mpeg2dec->decoder)); } mpeg2dec->action = NULL; return (mpeg2_state_t)-1;}#else /* !MAE_HW || USE_CMODELIF */mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec){ mpeg2_decoder_t * decoder = &(mpeg2dec->decoder); unsigned int state = mpeg2dec->state; mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0; mpeg2dec->state = ((mpeg2dec->picture->nb_fields > 1 || mpeg2dec->state == STATE_PICTURE_2ND) ? STATE_SLICE : STATE_SLICE_1ST); if (mpeg2dec->decoder.coding_type != D_TYPE) { prescale (mpeg2dec, 0); if (decoder->chroma_quantizer[0] == decoder->quantizer_prescale[2]) prescale (mpeg2dec, 2); if (mpeg2dec->decoder.coding_type != I_TYPE) { prescale (mpeg2dec, 1); if (decoder->chroma_quantizer[1] == decoder->quantizer_prescale[3]) prescale (mpeg2dec, 3); } } if (!(mpeg2dec->nb_decode_slices)) mpeg2dec->picture->flags |= PIC_FLAG_SKIP; else if (mpeg2dec->convert_start) { mpeg2dec->convert_start (decoder->convert_id, mpeg2dec->fbuf[0], mpeg2dec->picture, mpeg2dec->info.gop); if (mpeg2dec->decoder.coding_type == B_TYPE) { mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->yuv_buf[2], mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1], mpeg2dec->yuv_buf[mpeg2dec->yuv_index]); } else { mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1], mpeg2dec->yuv_buf[mpeg2dec->yuv_index], mpeg2dec->yuv_buf[mpeg2dec->yuv_index]); if (mpeg2dec->state == STATE_SLICE) mpeg2dec->yuv_index ^= 1; } } else { int b_type; b_type = (mpeg2dec->decoder.coding_type == B_TYPE);#ifdef MAE_HW if(mpeg2dec->bUseMAE) { mpeg2_fbuf_t * fbuf; int y_size, uv_size; // Reset the DMV flag at the beginning of each frame / field // This flag will get set later if we encounter a DMV macroblock in this frame / field#ifndef USE_CMODELIF nDMVUpdate = nDMVUpdate1 = nDMVUpdate2 = 0;#endif #ifdef USE_CMODELIF y_size = decoder->width * decoder->height; uv_size = y_size >> (2 - decoder->chroma_format); fbuf = mpeg2dec->fbuf[0]; //printf("Initial address of buffer %x\n",fbuf->buf[0]); // The driver uses 4 YUV buffers. We use only 3 in the decoder. // These buffers HAVE TO BE dynamically obtained from the driver. if ((state != STATE_PICTURE_2ND)) { fbuf->buf[0] = (unsigned char *)get_cur_buffer(); // Y pointer } //printf("\nCurrent buffer %x\n",fbuf->buf[0]); if (fbuf->buf[0] == NULL) { printf("\n Decoder : ERROR : could not allocate current YUV buffer\n"); exit (EXIT_FAILURE); } fbuf->buf[1] = fbuf->buf[0] + y_size; // U pointer fbuf->buf[2] = fbuf->buf[1] + uv_size; // V pointer#endif }#endif // ifdef MAE_HW mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->fbuf[0]->buf, mpeg2dec->fbuf[b_type + 1]->buf, mpeg2dec->fbuf[b_type]->buf); } mpeg2dec->action = NULL; return (mpeg2_state_t)-1;}#endifstatic mpeg2_state_t seek_sequence (mpeg2dec_t * mpeg2dec){ mpeg2_reset_info (&(mpeg2dec->info)); mpeg2dec->info.sequence = NULL; mpeg2dec->info.gop = NULL; mpeg2_header_state_init (mpeg2dec); mpeg2dec->action = mpeg2_seek_header; return mpeg2_seek_header (mpeg2dec);}mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec){ mpeg2_picture_t * picture; int b_type; b_type = (mpeg2dec->decoder.coding_type == B_TYPE); picture = mpeg2dec->pictures; if ((mpeg2dec->picture >= picture + 2) ^ b_type) picture = mpeg2dec->pictures + 2; mpeg2_reset_info (&(mpeg2dec->info)); if (!(mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) { mpeg2dec->info.display_picture = picture; if (picture->nb_fields == 1) mpeg2dec->info.display_picture_2nd = picture + 1; mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[b_type]; if (!mpeg2dec->convert) mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type + 1]; } else if (!mpeg2dec->convert) mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type]; mpeg2dec->action = seek_sequence; return STATE_END;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -