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

📄 slice.c

📁 avs-s最新代码,包括编码器和解码器源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*****************************************************************************
* COPYRIGHT AND WARRANTY INFORMATION
*
* Copyright 2003, Advanced Audio Video Coding Standard, Part II
*
* DISCLAIMER OF WARRANTY
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations under
* the License.
*                     
* THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY.
* The AVS Working Group doesn't represent or warrant that the programs
* furnished here under are free of infringement of any third-party patents.
* Commercial implementations of AVS, including shareware, may be
* subject to royalty fees to patent holders. Information regarding
* the AVS patent policy for standardization procedure is available at 
* AVS Web site http://www.avs.org.cn. Patent Licensing is outside
* of AVS Working Group.
*
* The Original Code is Reference Software for China National Standard 
* GB/T 20090.2-2006 (short for AVS-P2 or AVS Video) at version RM52J.
*
* The Initial Developer of the Original Code is Video subgroup of AVS
* Workinggroup (Audio and Video coding Standard Working Group of China).
* Contributors:   Guoping Li,    Siwei Ma,    Jian Lou,    Qiang Wang , 
*   Jianwen Chen,Haiwu Zhao,  Xiaozhen Zheng, Junhao Zheng, Zhiming Wang
* 
******************************************************************************
*/



/*
*************************************************************************************
* File name: 
* Function: 
*
*************************************************************************************
*/

#include "contributors.h"

#include <string.h>
#include <math.h>
#include <time.h>
#include <sys/timeb.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

#include "global.h"
#include "header.h"
#include "bitstream.h"
#include "vlc.h"
#include "image.h"
#include "rdopt_coding_state.h"
#include "loopfilter.h"

/*
*************************************************************************
* Function:This function terminates a slice
* Input:
* Output:
* Return: 0 if OK,                                                         \n
      1 in case of error
* Attention:                                                  by jlzheng
*************************************************************************
*/

int start_slice()
{
  Bitstream *currStream;
    
  currStream = currBitStream;

   if(((img->picture_structure && img->current_mb_nr!=0))||((!img->picture_structure)&&(img->current_mb_nr_fld!=0)))
     Demulate(currStream,current_slice_bytepos);                  //qhg 20060327  for de-emulation

  if (currStream->bits_to_go!=8) //   hzjia 2004-08-20 
  {
	  
	  currStream->byte_buf <<= currStream->bits_to_go;
	  currStream->byte_buf |= ( 1 << (currStream->bits_to_go - 1) );
	  
	  currStream->streamBuffer[currStream->byte_pos++] = currStream->byte_buf;
	  currStream->bits_to_go = 8;
	  currStream->byte_buf = 0;
  } 
   else		// cjw 20060321 
  {
	  currStream->streamBuffer[currStream->byte_pos++] = 0x80;
	  currStream->bits_to_go = 8;
	  currStream->byte_buf = 0; 
  }
  
   //qhg 20060327 for de-emulation 
  current_slice_bytepos=currStream->byte_pos;  

  return 0;   
}

/*
*************************************************************************
* Function:This function terminates a picture
* Input:
* Output:
* Return: 0 if OK,                                                         \n
      1 in case of error
* Attention:
*************************************************************************
*/

int terminate_picture()
{
  Bitstream *currStream;
    
  currStream = currBitStream;
 
//////////////////////////////////////////////////////////////////////////
    Demulate(currStream,current_slice_bytepos);                    //qhg 20060327 
//////////////////////////////////////////////////////////////////////////


  //---deleted by Yulj 2004.07.16
	// '10..' should be filled even if currStream is bytealign. 
  //if (currStream->bits_to_go==8)  
  //  return 0;
   
  currStream->byte_buf <<= currStream->bits_to_go;
  currStream->byte_buf |= (1 << (currStream->bits_to_go - 1) );    // Yulj 2004.07.16
  
  currStream->streamBuffer[currStream->byte_pos++] = currStream->byte_buf;
  currStream->bits_to_go = 8;
  currStream->byte_buf = 0;
  
  return 0;   
}

/*
*************************************************************************
* Function:Encodes one slice
* Input:
* Output:
* Return: the number of coded MBs in the SLice 
* Attention:                                    
*************************************************************************
*/
void picture_data(Picture *pic)
{
  Boolean end_of_picture = FALSE;
  int CurrentMbNumber=0;
  int MBRowSize = img->width / MB_BLOCK_SIZE;         // jlzheng 7.1
	int slice_nr = 0;
	int slice_qp = img->qp;
	int len;
	
        
    bot_field_mb_nr = -1;	//Xiaozhen Zheng, HiSilicon, 20070327
	while (end_of_picture == FALSE) // loop over macroblocks
	{
		set_MB_parameters (CurrentMbNumber);
		
		//added by mz, 2008.04
		if((input->slice_set_enable ||(!input->slice_set_enable&&input->slice_row_nr)) && (img->current_mb_nr==0
			||(img->current_mb_nr>0 && img->mb_data[img->current_mb_nr].slice_nr != img->mb_data[img->current_mb_nr-1].slice_nr)))
		{
			   // slice header start     jlzheng 7.1
			   start_slice (); 
			   img->current_slice_qp = img->qp;
			   img->current_slice_start_mb = img->current_mb_nr;
               len = SliceHeader(slice_nr, slice_qp);  
			   stat->bit_slice += len;  
			   slice_nr++; 
			   // slcie header end
		}
		   
		   start_macroblock ();
		   encode_one_macroblock ();
		   write_one_macroblock (1);
		   terminate_macroblock (&end_of_picture);
		   proceed2nextMacroblock ();
		   CurrentMbNumber++;
		   
	}
	
	terminate_picture ();
	
	DeblockFrame (img, imgY, imgUV);

#ifdef BACKGROUND
	{
		int j;
		int i;
		if(img->type == INTER_IMG && img->typeb == BP_IMG){
			for(j = 0; j < img->height/8; j++)
				for(i = 0; i < img->width/8; i++)
					refFrArr[j][i] = -1;
		}
			
	}
#endif

}


void top_field(Picture *pic)
{
	Boolean end_of_picture = FALSE;
	int CurrentMbNumber=0;
	int MBRowSize = img->width / MB_BLOCK_SIZE;
	int slice_nr =0;
	int slice_qp = img->qp;
	int len;

	img->top_bot = 0;  // Yulj 2004.07.20
	bot_field_mb_nr = -1;	//Xiaozhen Zheng, HiSilicon, 20070327
	while (end_of_picture == FALSE) // loop over macroblocks
	{
		set_MB_parameters (CurrentMbNumber);
		
		img->current_mb_nr_fld = img->current_mb_nr; //qhg 20060327 for de-emulation
							     //img->current_mb_nr_fld is used in start_slice()
		//added by mz, 2008.04
		if((input->slice_set_enable ||(!input->slice_set_enable&&input->slice_row_nr)) && (img->current_mb_nr==0
			||(img->current_mb_nr>0 && img->mb_data[img->current_mb_nr].slice_nr != img->mb_data[img->current_mb_nr-1].slice_nr)))
		{
			// slice header start jlzheng 7.1
			start_slice ();  
			img->current_slice_qp = img->qp;
			img->current_slice_start_mb = img->current_mb_nr;
			len = SliceHeader(slice_nr, slice_qp);
			stat->bit_slice += len;
			slice_nr++;
			// slice header end
		}
		
		//img->current_mb_nr_fld = img->current_mb_nr;  //delete by qhg 20060327 for de-emulation
		start_macroblock ();
		encode_one_macroblock ();
		write_one_macroblock (1);
		terminate_macroblock (&end_of_picture);
		proceed2nextMacroblock ();
		CurrentMbNumber++;
	}
	
	DeblockFrame (img, imgY, imgUV);

	

	bot_field_mb_nr = img->current_mb_nr;	// record the last mb index in the top field,	Xiaozhen Zheng HiSilicon, 20070327

	//rate control
	pic->bits_per_picture = 8 * (currBitStream->byte_pos);
}

void bot_field(Picture *pic)
{
	Boolean end_of_picture = FALSE;
	int CurrentMbNumber=0;
	int MBRowSize = img->width / MB_BLOCK_SIZE;
	int slice_nr =0;
	int slice_qp = img->qp;
	int len;
	

⌨️ 快捷键说明

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