📄 slice.c
字号:
/*
***********************************************************************
* COPYRIGHT AND WARRANTY INFORMATION
*
* Copyright 2003, Advanced Audio Video Coding Standard, Part II
*
* DISCLAIMER OF WARRANTY
*
* These software programs are available to the users without any
* license fee or royalty on an "as is" basis. The AVS disclaims
* any and all warranties, whether express, implied, or statutory,
* including any implied warranties of merchantability or of fitness
* for a particular purpose. In no event shall the contributors or
* the AVS be liable for any incidental, punitive, or consequential
* damages of any kind whatsoever arising from the use of this program.
*
* This disclaimer of warranty extends to the user of this program
* and user's customers, employees, agents, transferees, successors,
* and assigns.
*
* The AVS does not represent or warrant that the program furnished
* hereunder 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 is available from the AVS Web site at
* http://www.avs.org.cn
*
* THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY.
************************************************************************
*/
/*
*************************************************************************************
* 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
// 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;
//////////////////////////////////////////////////////////////////////////
//---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);
if (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);
}
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()
if (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;
img->top_bot = 1; //Yulj 2004.07.20
while (end_of_picture == FALSE) // loop over macroblocks
{
set_MB_parameters (CurrentMbNumber);
if (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)))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -