Exemplo n.º 1
0
static void sequence_header()
{
  int i;
  int pos;

  pos = ld->Bitcnt;
  horizontal_size             = Get_Bits(12);
  vertical_size               = Get_Bits(12);
  aspect_ratio_information    = Get_Bits(4);
  frame_rate_code             = Get_Bits(4);
  bit_rate_value              = Get_Bits(18);
  marker_bit("sequence_header()");
  vbv_buffer_size             = Get_Bits(10);
  constrained_parameters_flag = Get_Bits(1);

  if((ld->load_intra_quantizer_matrix = Get_Bits(1)))
  {
    for (i=0; i<64; i++)
      ld->intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
  }
  else
  {
    for (i=0; i<64; i++)
      ld->intra_quantizer_matrix[i] = default_intra_quantizer_matrix[i];
  }

  if((ld->load_non_intra_quantizer_matrix = Get_Bits(1)))
  {
    for (i=0; i<64; i++)
      ld->non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
  }
  else
  {
    for (i=0; i<64; i++)
      ld->non_intra_quantizer_matrix[i] = 16;
  }

  /* copy luminance to chrominance matrices */
  for (i=0; i<64; i++)
  {
    ld->chroma_intra_quantizer_matrix[i] =
      ld->intra_quantizer_matrix[i];

    ld->chroma_non_intra_quantizer_matrix[i] =
      ld->non_intra_quantizer_matrix[i];
  }

#ifdef VERBOSE
  if (Verbose_Flag > NO_LAYER)
  {
    printf("sequence header (byte %d)\n",(pos>>3)-4);
    if (Verbose_Flag > SEQUENCE_LAYER)
    {
      printf("  horizontal_size=%d\n",horizontal_size);
      printf("  vertical_size=%d\n",vertical_size);
      printf("  aspect_ratio_information=%d\n",aspect_ratio_information);
      printf("  frame_rate_code=%d",frame_rate_code);
      printf("  bit_rate_value=%d\n",bit_rate_value);
      printf("  vbv_buffer_size=%d\n",vbv_buffer_size);
      printf("  constrained_parameters_flag=%d\n",constrained_parameters_flag);
      printf("  load_intra_quantizer_matrix=%d\n",ld->load_intra_quantizer_matrix);
      printf("  load_non_intra_quantizer_matrix=%d\n",ld->load_non_intra_quantizer_matrix);
    }
  }
Exemplo n.º 2
0
// Open function modified by Donald Graft as part of fix for dropped frames and random frame access.
int CMPEG2Decoder::Open(const char *path)
{
	char buf[2048], *buf_p;

	Choose_Prediction(this->fastMC);

	char ID[80], PASS[80] = "DGIndexProjectFile16";
	DWORD i, j, size, code, type, tff, rff, film, ntsc, gop, top, bottom, mapping;
	int repeat_on, repeat_off, repeat_init;
	int vob_id, cell_id;
	__int64 position;
    int HadI;

	CMPEG2Decoder* out = this;

	out->VF_File = fopen(path, "r");
	if (fgets(ID, 79, out->VF_File)==NULL)
		return 1;
	if (strstr(ID, "DGIndexProjectFile") == NULL)
		return 5;
	if (strncmp(ID, PASS, 20))
		return 2;

	fscanf(out->VF_File, "%d\n", &File_Limit);
	i = File_Limit;
	while (i)
	{
		Infilename[File_Limit-i] = (char*)aligned_malloc(_MAX_PATH, 16);
		fgets(Infilename[File_Limit-i], _MAX_PATH - 1, out->VF_File);
		// Strip newline.
		Infilename[File_Limit-i][strlen(Infilename[File_Limit-i])-1] = 0;
		if (PathIsRelative(Infilename[File_Limit-i]))
		{
			char *p, d2v_stem[_MAX_PATH], open_path[_MAX_PATH];

			if (PathIsRelative(path))
			{
				GetCurrentDirectory(_MAX_PATH, d2v_stem);
				if (*(d2v_stem + strlen(d2v_stem) - 1) != '\\')
					strcat(d2v_stem, "\\");
				strcat(d2v_stem, path);
			}
			else
			{
				strcpy(d2v_stem, path);
			}
			p = d2v_stem + strlen(d2v_stem);
			while (*p != '\\' && p != d2v_stem) p--;
			if (p != d2v_stem)
			{
				p[1] = 0;
				strcat(d2v_stem, Infilename[File_Limit-i]);
				PathCanonicalize(open_path, d2v_stem);
				if ((Infile[File_Limit-i] = _open(open_path, _O_RDONLY | _O_BINARY))==-1)
					return 3;
			}
			else
			{
				// This should never happen because the code should guarantee that d2v_stem has a '\' character.
				return 3;
			}
		}
		else
		{
			if ((Infile[File_Limit-i] = _open(Infilename[File_Limit-i], _O_RDONLY | _O_BINARY))==-1)
				return 3;
		}
		i--;
	}

	fscanf(out->VF_File, "\nStream_Type=%d\n", &SystemStream_Flag);
	if (SystemStream_Flag == 2)
	{
		fscanf(out->VF_File, "MPEG2_Transport_PID=%x,%x,%x\n",
			   &MPEG2_Transport_VideoPID, &MPEG2_Transport_AudioPID, &MPEG2_Transport_PCRPID);
		fscanf(out->VF_File, "Transport_Packet_Size=%d\n", &TransportPacketSize);
	}
	fscanf(out->VF_File, "MPEG_Type=%d\n", &mpeg_type);
	fscanf(out->VF_File, "iDCT_Algorithm=%d\n", &IDCT_Flag);

	switch (IDCT_Flag)
	{
		case IDCT_MMX:
			idctFunc = MMX_IDCT;
			break;

		case IDCT_SSEMMX:
			idctFunc = SSEMMX_IDCT;
			if (!cpu.ssemmx)
			{
				IDCT_Flag = IDCT_MMX;
				idctFunc = MMX_IDCT;
			}
			break;

		case IDCT_FPU:
			if (!fpuinit) 
			{
				Initialize_FPU_IDCT();
				fpuinit = true;
			}
			idctFunc = FPU_IDCT;
			break;

		case IDCT_REF:
			if (!refinit) 
			{
				refinit = true;
			}
			idctFunc = REF_IDCT;
			break;

		case IDCT_SSE2MMX:
			idctFunc = SSE2MMX_IDCT;
			if (!cpu.sse2mmx)
			{
				IDCT_Flag = IDCT_SSEMMX;
				idctFunc = SSEMMX_IDCT;
				if (!cpu.ssemmx)
				{
					IDCT_Flag = IDCT_MMX;
					idctFunc = MMX_IDCT;
				}
			}
			break;
		
		case IDCT_SKALSSE:
			idctFunc = Skl_IDct16_Sparse_SSE; //Skl_IDct16_SSE;
			if (!cpu.ssemmx)
			{
				IDCT_Flag = IDCT_MMX;
				idctFunc = MMX_IDCT;
			}
			break;

		case IDCT_SIMPLEIDCT:
			idctFunc = simple_idct_mmx;
			if (!cpu.ssemmx)
			{
				IDCT_Flag = IDCT_MMX;
				idctFunc = MMX_IDCT;
			}
			break;
	}

	File_Flag = 0;
	_lseeki64(Infile[0], 0, SEEK_SET);
	Initialize_Buffer();

	do
	{
		if (Fault_Flag == OUT_OF_BITS) return 4;
		next_start_code();
		code = Get_Bits(32);
	}
	while (code!=SEQUENCE_HEADER_CODE);

	sequence_header();

	mb_width = (horizontal_size+15)/16;
	mb_height = progressive_sequence ? (vertical_size+15)/16 : 2*((vertical_size+31)/32);

	QP = (int*)aligned_malloc(sizeof(int)*mb_width*mb_height, 32);
	backwardQP = (int*)aligned_malloc(sizeof(int)*mb_width*mb_height, 32);
	auxQP = (int*)aligned_malloc(sizeof(int)*mb_width*mb_height, 32);

	Coded_Picture_Width = 16 * mb_width;
	Coded_Picture_Height = 16 * mb_height;

	Chroma_Width = (chroma_format==CHROMA444) ? Coded_Picture_Width : Coded_Picture_Width>>1;
	Chroma_Height = (chroma_format!=CHROMA420) ? Coded_Picture_Height : Coded_Picture_Height>>1;

	block_count = ChromaFormat[chroma_format];

	for (i=0; i<8; i++)
	{
		p_block[i] = (short *)aligned_malloc(sizeof(short)*64 + 64, 32);
		block[i]   = (short *)((long)p_block[i] + 64 - (long)p_block[i]%64);
	}

	for (i=0; i<3; i++)
	{
		if (i==0)
			size = Coded_Picture_Width * Coded_Picture_Height;
		else
			size = Chroma_Width * Chroma_Height;

		backward_reference_frame[i] = (unsigned char*)aligned_malloc(2*size+4096, 32);  //>>> cheap safety bump
		forward_reference_frame[i] = (unsigned char*)aligned_malloc(2*size+4096, 32);
		auxframe[i] = (unsigned char*)aligned_malloc(2*size+4096, 32);
	}

	fscanf(out->VF_File, "YUVRGB_Scale=%d\n", &pc_scale);

	fscanf(out->VF_File, "Luminance_Filter=%d,%d\n", &i, &j);
	if (i==0 && j==0)
		Luminance_Flag = 0;
	else
	{
		Luminance_Flag = 1;
		InitializeLuminanceFilter(i, j);
	}

	fscanf(out->VF_File, "Clipping=%d,%d,%d,%d\n", 
		   &Clip_Left, &Clip_Right, &Clip_Top, &Clip_Bottom);
	fscanf(out->VF_File, "Aspect_Ratio=%s\n", Aspect_Ratio);
	fscanf(out->VF_File, "Picture_Size=%dx%d\n", &D2V_Width, &D2V_Height);

	Clip_Width = Coded_Picture_Width;
	Clip_Height = Coded_Picture_Height;

	if (upConv > 0 && chroma_format == 1)
	{
		// these are labeled u422 and v422, but I'm only using them as a temporary
		// storage place for YV12 chroma before upsampling to 4:2:2 so that's why its
		// /4 and not /2  --  (tritical - 1/05/2005)
		int tpitch = (((Chroma_Width+15)>>4)<<4); // mod 16 chroma pitch needed to work with YV12PICTs
		u422 = (unsigned char*)aligned_malloc((tpitch * Coded_Picture_Height / 2)+2048, 32);
		v422 = (unsigned char*)aligned_malloc((tpitch * Coded_Picture_Height / 2)+2048, 32);
		auxFrame1 = create_YV12PICT(Coded_Picture_Height,Coded_Picture_Width,chroma_format+1);
		auxFrame2 = create_YV12PICT(Coded_Picture_Height,Coded_Picture_Width,chroma_format+1);
	}