⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image.c

📁 此code含H.264解码需要的 lib和 src
💻 C
📖 第 1 页 / 共 5 页
字号:
				data = ref_picture->pic_mem_idx; 
				write_reg(0xd0|0x01, data|0x010000);
				
				// ref_pic_chroma_addr_0
				data = (ref_picture->pic_mem_idx); 
				write_reg(0x1d0|0x01, data|0x020000);
			}
		}		
    }
	
	
	/******************* ref_list1 *******************/
	if (listXsize[1] > 0) 
	{
		// ref_list_refresh_1
		write_reg(0xd4, 0x1);
		write_reg(0xd4, 0x0);
        
		for(j=0; j<listXsize[1]; j++)			
		{
			ref_picture = listX[1][j];
			
			// poc_bottom_field_1, poc_top_field_1
			switch(ref_picture->structure) 
			{
			case FRAME:
				// why top_poc and bottom_poc treated as such?
				data = ref_picture->bottom_poc * 2 + 1;
				write_reg(0x1c4, data);
				
				data = ref_picture->top_poc * 2;
				write_reg(0x1c8, data);
				break;
			case TOP_FIELD:
				data = ref_picture->top_poc * 2;
				write_reg(0x1c4, data);
				write_reg(0x1c8, data);
				break;
			default:
				data = ref_picture->bottom_poc * 2 + 1;
				write_reg(0x1c4, data);
				write_reg(0x1c8, data);
				break;
			}
			
			// ref_pic_parameter_1
			field_pic_flag = !(ref_picture->coded_frame);
			bottom_field_flag = (ref_picture->structure == BOTTOM_FIELD);
			
			data = (ref_picture->pic_num         & 0xffff)      | 
			 	   ((ref_picture->MbaffFrameFlag & 0x01) << 16) | 
				   (bottom_field_flag << 17) |
				   (field_pic_flag << 18) |
				   ((ref_picture->is_long_term   & 0x01) << 19);
			write_reg(0x1cc, data);
			
			// ref_pic_luma_addr_1
			if( ref_picture->pic_mem_idx >= 0 )
			{
				data = ref_picture->pic_mem_idx; 
				write_reg(0x3d0|0x01, data|0x010000);
				
				// ref_pic_chroma_addr_1
				data = ref_picture->pic_mem_idx; 
				write_reg(0x4d0|0x01, data|0x020000);
			}
		}		
    }
	
	
	if (img->type == B_SLICE) 
	{        
		write_reg(0xb0, dec_picture->top_poc);
        write_reg(0xb4, dec_picture->bottom_poc);

		col_picture = listX[1][0];
		
		if( col_picture->pic_mem_idx >= 0 )
		{
			data = col_picture->pic_mem_idx;
			if (dec_picture->structure == FRAME) 
			{
				write_reg(0xb8|0x01, data|0x030000);
				write_reg(0xbc|0x01, (data+1)|0x030000);
			}
			else
			{
				write_reg(dec_picture->structure == TOP_FIELD ? 0xb8 : 0xbc, data);
			}
		}
        
		// col_picture's ff_address.
		if (col_picture->MbaffFrameFlag) 
		{
			data = col_picture->pic_mem_idx;		
			write_reg(0xf4|0x01, data|0x040000);
		}

		// col_ref_list_refresh_0
        data = 0;
		data = ((dec_picture->poc == dec_picture->top_poc)    << 16)  
			 | ((abs(dec_picture->poc - col_picture->top_poc) < abs(dec_picture->poc - col_picture->bottom_poc)) << 24);	   
        
//		if (col_picture->slice_type == I_SLICE) 
//		{
//			data |= (1 << 8);
//			write_reg(0xd8, data);
//		}
//		else
		{
			write_reg(0xd8, data|1);
			write_reg(0xd8, data|0);

			if (dec_picture->structure == FRAME && col_picture->structure != FRAME) 
			{
				count = max(col_picture->top_field->PastlistXsize0, col_picture->bottom_field->PastlistXsize0);
				for(j=0; j<count; j++)
				{
					write_reg(0x2c4, col_picture->bottom_field->PastlistX0[j].poc_bottom_field);
                    write_reg(0x2c8, col_picture->top_field->PastlistX0[j].poc_top_field);
					write_reg(0x2cc, col_picture->top_field->PastlistX0[j].ref_pic_parameter);
				}

				count = max(col_picture->top_field->PastlistXsize1, col_picture->bottom_field->PastlistXsize1);				
				for(j=0; j<count; j++)
				{
					write_reg(0x3c4, col_picture->bottom_field->PastlistX1[j].poc_bottom_field);
                    write_reg(0x3c8, col_picture->top_field->PastlistX1[j].poc_top_field);
					write_reg(0x3cc, col_picture->top_field->PastlistX1[j].ref_pic_parameter);
				}
			}
			else
			{
				for(j=0; j<col_picture->PastlistXsize0; j++)
				{
					write_reg(0x2c4, col_picture->PastlistX0[j].poc_bottom_field);
                    write_reg(0x2c8, col_picture->PastlistX0[j].poc_top_field);
					write_reg(0x2cc, col_picture->PastlistX0[j].ref_pic_parameter);
				}
				for(j=0; j<col_picture->PastlistXsize1; j++)
				{
					write_reg(0x3c4, col_picture->PastlistX1[j].poc_bottom_field);
                    write_reg(0x3c8, col_picture->PastlistX1[j].poc_top_field);
					write_reg(0x3cc, col_picture->PastlistX1[j].ref_pic_parameter);
				}
			}
		}
	}
	
	return;
}

/*!
 ************************************************************************
 * \brief
 *    Reads new slice from bit_stream
 ************************************************************************
 */
//int read_new_slice()
//{
//  NALU_t *nalu = AllocNALU(MAX_CODED_FRAME_SIZE);
//  int current_header = 0;
//  int ret;
//  int BitsUsedByHeader;
//  Slice *currSlice = img->currentSlice;
//  Bitstream *currStream;
//
//  int slice_id_a, slice_id_b, slice_id_c;
//  int redundant_pic_cnt_b, redundant_pic_cnt_c;
//  long ftell_position;
//
//  while (1)
//  {
//    ftell_position = ftell(bits);
//
//    if (input->FileFormat == PAR_OF_ANNEXB)
//      ret=GetAnnexbNALU (nalu);
//    else
//      ret=GetRTPNALU (nalu);
//
//    //In some cases, zero_byte shall be present. If current NALU is a VCL NALU, we can't tell
//    //whether it is the first VCL NALU at this point, so only non-VCL NAL unit is checked here.
//    CheckZeroByteNonVCL(nalu, &ret);
//
//    NALUtoRBSP(nalu);
//
//    if (ret < 0)
//      printf ("Error while getting the NALU in file format %s, exit\n", input->FileFormat==PAR_OF_ANNEXB?"Annex B":"RTP");
//    if (ret == 0)
//    {
//      FreeNALU(nalu);
//      return EOS;
//    }
//
//    // Got a NALU
//    if (nalu->forbidden_bit)
//    {
//      printf ("Found NALU w/ forbidden_bit set, bit error?  Let's try...\n");
//    }
//
//	fprintf(img->fpinfo, "\n\n");
//	fprintf(img->fpinfo, "nal_unit_type %d\n", nalu->nal_unit_type);
//
//    switch (nalu->nal_unit_type)
//    {  
//      case NALU_TYPE_SLICE:
//      case NALU_TYPE_IDR:       
//        if (img->recovery_point || nalu->nal_unit_type == NALU_TYPE_IDR)
//        {
//          if (img->recovery_point_found == 0)
//          {
//            if (nalu->nal_unit_type != NALU_TYPE_IDR)
//            {
//              printf("Warning: Decoding does not start with an IDR picture.\n");
//              non_conforming_stream = 1;
//            }
//            else
//              non_conforming_stream = 0;
//          }
//          img->recovery_point_found = 1;
//        }
//
//        if (img->recovery_point_found == 0)
//            break;
//
//        img->idr_flag = (nalu->nal_unit_type == NALU_TYPE_IDR);
//        img->nal_reference_idc = nalu->nal_reference_idc;
//        currSlice->dp_mode = PAR_DP_1;
//        currSlice->max_part_nr = 1;
//        currSlice->ei_flag = 0;
//        currStream = currSlice->partArr[0].bitstream;
//        currStream->ei_flag = 0;
//        currStream->frame_bitoffset = currStream->read_len = 0;
//        memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
//        currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);
//
//        // Some syntax of the Slice Header depends on the parameter set, which depends on
//        // the parameter set ID of the SLice header.  Hence, read the pic_parameter_set_id
//        // of the slice header first, then setup the active parameter sets, and then read
//        // the rest of the slice header
//        BitsUsedByHeader = FirstPartOfSliceHeader();
//        UseParameterSet (currSlice->pic_parameter_set_id);
//        BitsUsedByHeader+= RestOfSliceHeader ();
//
//        FmoInit (active_pps, active_sps);
//
//        AssignQuantParam (active_pps, active_sps);
//
//        // if primary slice is replaced with redundant slice, set the correct image type
////        if(img->redundant_pic_cnt && Is_primary_correct==0 && Is_redundant_correct)
////        {
////          dec_picture->slice_type=img->type;
////        }
//
//        if(is_new_picture())
//        {
//          init_picture(img, input);
//
//          current_header = SOP;
//          //check zero_byte if it is also the first NAL unit in the access unit
//          CheckZeroByteVCL(nalu, &ret);
//        }
//        else
//          current_header = SOS;
//
//        init_lists(img->type, img->currentSlice->structure);
//        reorder_lists (img->type, img->currentSlice);
//
//        if (img->structure==FRAME)
//        {
//          init_mbaff_lists();
//        }
//	
//        // From here on, active_sps, active_pps and the slice header are valid
//        if (img->MbaffFrameFlag)
//          img->current_mb_nr = currSlice->start_mb_nr << 1;
//        else
//          img->current_mb_nr = currSlice->start_mb_nr;
//
//        if (active_pps->entropy_coding_mode_flag)
//        {
//          int ByteStartPosition = currStream->frame_bitoffset/8;
//          if (currStream->frame_bitoffset%8 != 0)
//          {
//            ByteStartPosition++;
//          }
//          arideco_start_decoding (&currSlice->partArr[0].de_cabac, currStream->streamBuffer, ByteStartPosition, &currStream->read_len, img->type);
//        }
//// printf ("read_new_slice: returning %s\n", current_header == SOP?"SOP":"SOS");
//        FreeNALU(nalu);
//        img->recovery_point = 0;
//        return current_header;
//        break;
//      case NALU_TYPE_DPA:
//        // read DP_A
//        img->idr_flag          = (nalu->nal_unit_type == NALU_TYPE_IDR);
//        if (img->idr_flag)
//        {
//          printf ("Data partiton A cannot have idr_flag set, trying anyway \n");
//        }
//        img->nal_reference_idc = nalu->nal_reference_idc;
//        currSlice->dp_mode     = PAR_DP_3;
//        currSlice->max_part_nr = 3;
//        currSlice->ei_flag     = 0;
//        currStream             = currSlice->partArr[0].bitstream;
//        currStream->ei_flag    = 0;
//        currStream->frame_bitoffset = currStream->read_len = 0;
//        memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
//        currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);
//
//        BitsUsedByHeader     = FirstPartOfSliceHeader();
//        UseParameterSet (currSlice->pic_parameter_set_id);
//        BitsUsedByHeader    += RestOfSliceHeader ();
//
//        FmoInit (active_pps, active_sps);
//
//        if(is_new_picture())
//        {
//          init_picture(img, input);
//          current_header = SOP;
//          CheckZeroByteVCL(nalu, &ret);
//        }
//        else
//          current_header = SOS;
//
//        init_lists(img->type, img->currentSlice->structure);
//        reorder_lists (img->type, img->currentSlice);
//
//        if (img->structure==FRAME)
//        {
//          init_mbaff_lists();
//        }
//
//        // From here on, active_sps, active_pps and the slice header are valid
//        if (img->MbaffFrameFlag)
//          img->current_mb_nr = currSlice->start_mb_nr << 1;
//        else
//          img->current_mb_nr = currSlice->start_mb_nr;
//
//        // Now I need to read the slice ID, which depends on the value of
//        // redundant_pic_cnt_present_flag
//
//        slice_id_a  = ue_v("NALU: DP_A slice_id", currStream);
//
//        if (active_pps->entropy_coding_mode_flag)
//          error ("received data partition with CABAC, this is not allowed", 500);
//
//        // continue with reading next DP
//        ftell_position = ftell(bits);
//        if (input->FileFormat == PAR_OF_ANNEXB)
//          ret=GetAnnexbNALU (nalu);
//        else
//          ret=GetRTPNALU (nalu);
//
//        CheckZeroByteNonVCL(nalu, &ret);
//        NALUtoRBSP(nalu);
//
//        if (ret < 0)
//          printf ("Error while getting the NALU in file format %s, exit\n", input->FileFormat==PAR_OF_ANNEXB?"Annex B":"RTP");
//        if (ret == 0)
//        {
//          FreeNALU(nalu);
//          return current_header;
//        }
//
//        if ( NALU_TYPE_DPB == nalu->nal_unit_type)
//        {
//          // we got a DPB
//          currStream             = currSlice->partArr[1].bitstream;
//          currStream->ei_flag    = 0;
//          currStream->frame_bitoffset = currStream->read_len = 0;
//
//          memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1);
//          currStream->code_len = currStream->bitstream_length = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);
//
//          slice_id_b  = ue_v("NALU: DP_B slice_id", currStream);
//
//          if (slice_id_b != slice_id_a)
//          {
//            printf ("got a data partition B which does not match DP_A\n");
//            // KS: needs error handling !!!
//          }
//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -