mfxStatus QSV_Encoder_Internal::Open(qsv_param_t * pParams)
{
	mfxStatus sts = MFX_ERR_NONE;

	if (m_bUseD3D11)
		// Use D3D11 surface
		sts = Initialize(m_impl, m_ver, &m_session, &m_mfxAllocator);
	else
		// Use system memory
		sts = Initialize(m_impl, m_ver, &m_session, NULL);

	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	m_pmfxENC = new MFXVideoENCODE(m_session);

	InitParams(pParams);

	sts = m_pmfxENC->Query(&m_mfxEncParams, &m_mfxEncParams);
	MSDK_IGNORE_MFX_STS(sts, MFX_WRN_INCOMPATIBLE_VIDEO_PARAM);
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	sts = AllocateSurfaces();
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	sts = m_pmfxENC->Init(&m_mfxEncParams);
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	sts = GetVideoParam();
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	sts = InitBitstream();
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	return sts;
}
Exemplo n.º 2
0
/* Merge Shape Bitstream into main bit stream */
Void CVTCEncoder::
MergeEnhShapeBitstream()
{
  if(ShapeBitstream==NULL) {
    fprintf(stderr,"EnhShapeBitStream Not Available\n");
    exit(1);
  }
  InitBitstream(0,ShapeBitstream);
  BitStreamMerge(ShapeBitstreamLength, ShapeBitstream);
 
  free(ShapeBitstream->bs);
  free(ShapeBitstream);
  ShapeBitstream = NULL;
}
mfxStatus QSV_Encoder_Internal::Open(qsv_param_t * pParams)
{
	mfxStatus sts = MFX_ERR_NONE;
	
	InitParams(pParams);

	sts = m_pmfxENC->Query(&m_mfxEncParams, &m_mfxEncParams);
	MSDK_IGNORE_MFX_STS(sts, MFX_WRN_INCOMPATIBLE_VIDEO_PARAM);
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	sts = AllocateSurfaces();
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	sts = m_pmfxENC->Init(&m_mfxEncParams);
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	sts = GetVideoParam();
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	sts = InitBitstream();
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	return sts;
}
Exemplo n.º 4
0
Int CVTCEncoder::
ShapeEnhEnCoding(UChar *LowShape,	 /* shape mask in the lower layer */
		 UChar *HalfShape, /* shape mask in the half-higher layer */
			UChar *CurShape, /* shape mask in the current layer */
			Int object_width,  /* object_width in the current layer */
			Int object_height,/* object_height in the current layer */
			FILTER *filter)
{
    Int i, j, k, l, p, q, x, y, x2, y2;
    Int bab_type, ret;
	Int scan_order; // SAIT_PDAM : ADDED by D.-S. Cho (Samsung AIT) 

    Int width2		= object_width,
	height2		= object_height,
	width		= width2 >> 1,
	height		= height2 >> 1;
    Int NB = (object_width >= 1024 || object_height >=1024)? 6:
      (object_width >=512|| object_height >=512)?5:4;
    Int mborder		= MBORDER,
    	mblks           = NB,
	mbsize          = 1<<mblks,		/* bab size in the current layer : 16 */
	mbsize_ext      = mbsize+(mborder<<1);  /* bordered bab size in the current layer: 20 */
 
    Int border		= BORDER,
    	blks            = mblks-1,
	bsize           = 1<<blks,		/* bab size in the lower layer : 8 */
	bsize_ext       = bsize+(border<<1);	/* bordered bab size in the lower layer: 8 */
 
    Int blkx            = (object_width+mbsize-1)/mbsize,
	blky            = (object_height+mbsize-1)/mbsize;
    //    static int first=0;
    //    Int cnt_mode0=0, cnt_mode1=0, cnt_mode2=0, cnt_total=0;
    
    UInt prob;

    UChar *lower_bab;			/* alpha block in the lower layer */
    UChar *bordered_lower_bab;		/* bordered alpha block in the lower layer */

    UChar *half_bab;			/* alpha block in the half-higher layer */
    UChar *bordered_half_bab;		/* bordered alpha block in the half-higher layer */
 
    
    UChar *curr_bab;			/* alpha mb in the current layer */
    UChar *bordered_curr_bab;		/* bordered alpha mb in the current layer */

    ArCoder       ar_coder;

	ShapeBitstream=NULL;
	ShapeBitstreamLength=0;
    /*-- Memory allocation ---------------------------------------------------------*/
    lower_bab = (UChar *) calloc(bsize*bsize, sizeof(UChar));
    bordered_lower_bab = (UChar *) calloc(bsize_ext*bsize_ext, sizeof(UChar));

    half_bab = (UChar *) calloc(bsize*mbsize, sizeof(UChar));
    bordered_half_bab = (UChar *) calloc(bsize_ext*mbsize_ext, sizeof(UChar));

    curr_bab = (UChar *) calloc(mbsize*mbsize, sizeof(UChar));
    bordered_curr_bab = (UChar *) calloc(mbsize_ext*mbsize_ext, sizeof(UChar));

    /*-- Initialize the shape bitstream --------------------------------------------*/
    ShapeBitstream = (BSS *)malloc(sizeof(BSS));
    if(ShapeBitstream==NULL) {
      fprintf(stderr,"Memory allocation failed\n");
      return Error;
    }
    ShapeBitstream->bs = (UChar *)malloc(sizeof(UChar)*object_width*object_height);
    if(ShapeBitstream->bs==NULL) {
      fprintf(stderr,"Memory allocation failed\n");
      return Error;
    }

    /*-- Clear the output buffer ---------------------------------------------------*/
    memset(ShapeBitstream->bs, (UChar )0, object_width*object_height);
    InitBitstream(1,ShapeBitstream);

    /*-- Encode the Enhancement Layer ------------------------------------------------*/
/*     fprintf(stderr,"-- Encode the BAB in the enhancement layer !\n"); */

    StartArCoder_Still(&ar_coder);  

    for ( j=y=y2=0; j<blky; j++, y+=bsize, y2+=mbsize ) 
    {
      for ( i=x=x2=0; i<blkx; i++, x+=bsize, x2+=mbsize ) 
      {
	/*-- Initialize BABs --*/
	q = y2*width2;
        for ( l=p=0; l<mbsize; l++, q+=width2 ) {
          for ( k=0; k<mbsize; k++, p++ ) {
	      if( y2+l < height2 && x2+k < width2)
                curr_bab[p]= (CurShape[ q+x2+k ] != 0);
	      else
                curr_bab[p]= 0;
	  }
	}


	q = y2*width;
        for ( l=p=0; l<mbsize; l++, q+=width ) {
          for ( k=0; k<bsize; k++, p++ ) {
	      if( y2+l < height2 && x+k < width)
                half_bab[p]= (HalfShape[ q+x+k ] != 0);
	      else
                half_bab[p]= 0;
	  }
	}


	q = y*width;
	for ( l=p=0; l<bsize; l++, q+=width ) {
	  for ( k=0; k<bsize; k++, p++ ) {
              if(  y+l < height && x+k < width )
                lower_bab[p] = (LowShape[ q+x+k ] != 0);
              else
                lower_bab[p] = 0;

          }
	}

	AddBorderToBABs(LowShape, HalfShape, CurShape,
			lower_bab, half_bab, curr_bab,
			bordered_lower_bab, bordered_half_bab,
			bordered_curr_bab,
			object_width, object_height,
			i, j, mbsize, blkx);

	scan_order = DecideScanOrder(bordered_lower_bab, mbsize); // SAIT_PDAM: ADDED by D.-S.Cho (Samsung AIT) 
	
	bab_type = DecideBABtype(bordered_lower_bab, bordered_half_bab,
				 bordered_curr_bab, mbsize,
				 scan_order // SAIT_PDAM ADDED by D.-S.Cho (Samsung AIT) 
				 );
	if(filter->DWT_Class==DWT_ODD_SYMMETRIC){
	  prob=scalable_bab_type_prob[0];
	} else if(filter->DWT_Class==DWT_EVEN_SYMMETRIC) {
	  prob=scalable_bab_type_prob[1];
	} else {
	  fprintf(stderr,"Error: filter type in ShapeEnhEncoding()!\n");
	  exit(0);
	}
	ArCodeSymbol_Still(&ar_coder, ShapeBitstream, bab_type, prob);

	/* Encode mask pixel values in the enhancement layer */
	ret = ShapeEnhContentEncode(bordered_lower_bab, 
				    bordered_half_bab,
				    bordered_curr_bab, 
				    bab_type,
					scan_order, // SAIT_PDAM: ADDED by D.-S.Cho (Samsung AIT)
				    mbsize, 
				    filter,
				    ShapeBitstream,	
				    &ar_coder);
	if( ret == Error )
	{
          fprintf(stderr,"\n SI arithmetic coding Error !\n");
          return  Error;
        }
      }
    }

    StopArCoder_Still(&ar_coder,ShapeBitstream);

    ShapeBitstreamLength = ShapeBitstream -> cnt;

    /*-- Memory free ---------------------------------------------------------*/
 
    free(lower_bab);
    free(bordered_lower_bab);
    free(half_bab);
    free(bordered_half_bab);
    free(curr_bab);
    free(bordered_curr_bab);

    return ( ShapeBitstreamLength );
}