slice.c File Reference

generate the slice header, setup the bit buffer for slices, and generates the slice NALU(s) More...

#include "contributors.h"
#include <math.h>
#include <float.h>
#include "global.h"
#include "header.h"
#include "nal.h"
#include "rtp.h"
#include "fmo.h"
#include "vlc.h"
#include "image.h"
#include "cabac.h"
#include "biariencode.h"
#include "elements.h"
#include "macroblock.h"
#include "memalloc.h"
#include "symbol.h"
#include "context_ini.h"
#include "enc_statistics.h"
#include "ratectl.h"
#include "me_epzs.h"
#include "me_epzs_int.h"
#include "wp.h"
#include "slice.h"
#include "rdoq.h"
#include "wp_mcprec.h"
#include "q_offsets.h"
#include "conformance.h"
#include "list_reorder.h"
#include "md_common.h"
#include "mmco.h"
#include "mv_search.h"
#include "quant4x4.h"
#include "quant8x8.h"
#include "quantChroma.h"
#include "rdopt.h"
#include "rdopt_coding_state.h"

Include dependency graph for slice.c:

Go to the source code of this file.

Functions

static Slicemalloc_slice (ImageParameters *p_Img, InputParameters *p_Inp)
static void free_slice (Slice *currSlice)
static void set_ref_pic_num (Slice *currSlice)
int allocate_block_mem (Slice *currSlice)
void free_block_mem (Slice *currSlice)
static void CAVLC_init (Slice *currSlice)
static int get_mem_mv (Slice *currSlice, short *******mv)
static int get_mem_bipred_mv (Slice *currSlice, short ********bipred_mv)
static void free_mem_mv (short ******mv)
static void free_mem_bipred_mv (short *******bipred_mv)
static int alloc_rddata (Slice *currSlice, RD_DATA *rd_data)
static void free_rddata (Slice *currSlice, RD_DATA *rd_data)
static int start_slice (Slice *currSlice, StatParameters *cur_stats)
void create_slice_nalus (Slice *currSlice)
static int terminate_slice (Macroblock *currMB, int lastslice, StatParameters *cur_stats)
int encode_one_slice (ImageParameters *p_Img, InputParameters *p_Inp, int SliceGroupId, int TotalCodedMBs)
int encode_one_slice_MBAFF (ImageParameters *p_Img, InputParameters *p_Inp, int SliceGroupId, int TotalCodedMBs)
static void setup_cabac (Slice *currSlice, char *listXsize)
static void setup_cavlc (Slice *currSlice, char *listXsize)
void init_slice (ImageParameters *p_Img, InputParameters *p_Inp, Slice **currSlice, int start_mb_addr)
static void free_nal_unit (Picture *pic)
void free_slice_list (Picture *currPic)
void UpdateMELambda (ImageParameters *p_Img, InputParameters *p_Inp)
void SetLambda (ImageParameters *p_Img, InputParameters *p_Inp, int j, int qp, double lambda_scale)
void SetLagrangianMultipliersOn (ImageParameters *p_Img, InputParameters *p_Inp)
void SetLagrangianMultipliersOff (ImageParameters *p_Img, InputParameters *p_Inp)


Detailed Description

generate the slice header, setup the bit buffer for slices, and generates the slice NALU(s)

slice.c

Author:
Main contributors (see contributors.h for copyright, address and affiliation details)

Definition in file slice.c.


Function Documentation

int allocate_block_mem ( Slice currSlice  ) 

convert from H.263 QP to H.264 quant given by: quant=pow(2,QP/6)

Definition at line 64 of file slice.c.

References get_mem2Dint(), get_mem4Dint(), slice::tblk16x16, and slice::tblk4x4.

Referenced by init_slice().

Here is the call graph for this function:

static void CAVLC_init ( Slice currSlice  )  [static]

Initializes the p_Img->nz_coeff.

Input:
none
Output:
none \ side effects sets omg->nz_coef[][][][] to -1

Definition at line 94 of file slice.c.

References img_par::nz_coeff.

Referenced by start_slice().

void create_slice_nalus ( Slice currSlice  ) 

This creates a NAL unit structures for all data partition of the slice.

Definition at line 274 of file slice.c.

References AllocNALU(), Bitstream::buffer_size, nalu_t::forbidden_bit, slice::max_part_nr, slice::nal_reference_idc, nalu_t::nal_reference_idc, nalu_t::nal_unit_type, slice::partArr, nalu_t::startcodeprefix_len, and Bitstream::write_flag.

Referenced by terminate_slice().

Here is the call graph for this function:

int encode_one_slice ( ImageParameters p_Img,
InputParameters p_Inp,
int  SliceGroupId,
int  TotalCodedMBs 
)

int encode_one_slice_MBAFF ( ImageParameters p_Img,
InputParameters p_Inp,
int  SliceGroupId,
int  TotalCodedMBs 
)

Encodes one slice (MBAFF Frame).

returns the number of coded MBs in the SLice

This following ugly code breaks slices, at least for a slice mode that accumulates a certain number of bits into one slice. The suggested algorithm is as follows:

SaveState (Bitstream, stats, etc. etc.); BitsForThisMBPairInFrameMode = CodeMB (Upper, FRAME_MODE) + CodeMB (Lower, FRAME_MODE); DistortionForThisMBPairInFrameMode = CalculateDistortion(Upper) + CalculateDistortion (Lower); RestoreState(); BitsForThisMBPairInFieldMode = CodeMB (Upper, FIELD_MODE) + CodeMB (Lower, FIELD_MODE); DistortionForThisMBPairInFrameMode = CalculateDistortion(Upper) + CalculateDistortion (Lower); FrameFieldMode = Decision (...) RestoreState() if (FrameFieldMode == FRAME) { CodeMB (Upper, FRAME); CodeMB (Lower, FRAME); } else { CodeMB (Upper FIELD); CodeMB (Lower, FIELD); }

Open questions/issues: 1. CABAC/CA-VLC state: It seems that the CABAC/CA_VLC states are changed during the dummy encoding processes (for the R-D based selection), but that they are never reset, once the selection is made. I believe that this breaks the MB-adaptive frame/field coding. The necessary code for the state saves is readily available in macroblock.c, start_macroblock() and end_macroblock() (this code needs to be double checked that it works with CA-VLC as well 2. would it be an option to allocate Bitstreams with zero data in them (or copy the already generated bitstream) for the "test coding"?

Go back to the previous MB to recode it

Definition at line 554 of file slice.c.

References img_par::AdaptiveRounding, inp_par_enc::AdaptRndPeriod, CalculateOffset4x4Param(), CalculateOffset8x8Param(), change_plane_JV(), img_par::cod_counter, img_par::colour_plane_id, copy_rdopt_data(), end_encode_one_macroblock(), end_macroblock(), error(), errortext, ET_SIZE, img_par::field_mode, FmoGetLastCodedMBOfSliceGroup(), FmoGetNextMBNr(), FmoGetPreviousMBNr(), FmoMB2SliceGroup(), init_quant_4x4(), init_quant_8x8(), init_quant_Chroma(), init_slice(), img_par::masterQP, inp_par_enc::MbInterlace, img_par::MBPairIsField, next_macroblock(), inp_par_enc::num_ref_frames, macroblock::qp, img_par::qp, rc_copy_generic(), rc_copy_quadratic(), inp_par_enc::RCEnable, slice::slice_type, start_macroblock(), start_slice(), terminate_slice(), img_par::top_field, update_mv_limits(), and write_macroblock().

Referenced by code_a_plane().

Here is the call graph for this function:

static void free_mem_bipred_mv ( short *******  bipred_mv  )  [static]

Free memory from mv.

Input:
int****** mv

Definition at line 156 of file slice.c.

References free_mem7Dshort().

Referenced by free_slice().

Here is the call graph for this function:

static void free_mem_mv ( short ******  mv  )  [static]

Free memory from mv.

Input:
int****** mv

Definition at line 142 of file slice.c.

References free_mem6Dshort().

Referenced by free_slice().

Here is the call graph for this function:

static void free_nal_unit ( Picture *  pic  )  [static]

This function frees nal units.

Definition at line 1518 of file slice.c.

References FreeNALU(), slice::max_part_nr, slice::partArr, and Bitstream::write_flag.

Referenced by free_slice_list().

Here is the call graph for this function:

static void free_slice ( Slice currSlice  )  [static]

void free_slice_list ( Picture *  currPic  ) 

Memory frees of all Slice structures and of its dependent data structures.

Input:
Picture *currPic

Definition at line 1556 of file slice.c.

References free_nal_unit(), and free_slice().

Referenced by encode_one_frame(), and free_picture().

Here is the call graph for this function:

static int get_mem_bipred_mv ( Slice currSlice,
short ********  bipred_mv 
) [static]

Allocate memory for bipredictive mv.

Input:
Image Parameters ImageParameters *p_Img
int****** mv
Returns:
memory size in bytes

Definition at line 127 of file slice.c.

References get_mem7Dshort(), and slice::max_num_references.

Referenced by init_slice().

Here is the call graph for this function:

static int get_mem_mv ( Slice currSlice,
short *******  mv 
) [static]

Allocate memory for mv.

Input:
Image Parameters ImageParameters *p_Img
int****** mv
Returns:
memory size in bytes

Definition at line 109 of file slice.c.

References get_mem6Dshort(), and slice::max_num_references.

Referenced by init_slice().

Here is the call graph for this function:

void init_slice ( ImageParameters p_Img,
InputParameters p_Inp,
Slice **  currSlice,
int  start_mb_addr 
)

Initializes the parameters for a new slice and allocates the memory for the coded slice in the Picture structure.

Side effects:
Adds slice/partition header symbols to the symbol buffer increments Picture->no_slices, allocates memory for the slice, sets p_Img->currSlice

Definition at line 1058 of file slice.c.

References slice::all_mv, alloc_colocated(), allocate_block_mem(), inp_par_enc::B_List0_refs, inp_par_enc::B_List1_refs, slice::bipred_mv, inp_par_enc::BiPredMotionEstimation, Bitstream::bits_to_go, Bitstream::byte_buf, Bitstream::byte_pos, img_par::colour_plane_id, compute_colocated(), compute_colocated_JV(), img_par::currentPicture, img_par::currentSlice, img_par::direct_spatial_mv_pred_flag, dummy_slice_too_big(), inp_par_enc::EnableOpenGOP, EPZSSliceInit(), EPZSStructInit(), error(), img_par::frame_num, img_par::framepoc, Get_Direct_MV_Spatial_MBAFF(), Get_Direct_MV_Spatial_Normal(), Get_Direct_MV_Temporal(), get_mem2D(), get_mem3D(), get_mem3Dint(), get_mem3Dpel(), get_mem4Dmv(), get_mem4Dpel(), get_mem_ACcoeff(), get_mem_bipred_mv(), get_mem_DCcoeff(), get_mem_mv(), img_par::height, img_par::height_blk, init_coding_state_methods(), init_lists(), init_mbaff_lists(), init_rdopt(), init_rdoq_slice(), init_ref_pic_list_reordering(), InitWP(), malloc_slice(), img_par::max_num_references, img_par::MbaffFrameFlag, inp_par_enc::MbInterlace, no_mem_exit(), img_par::number, inp_par_enc::NumRefPrimary, storable_picture::p_curr_img, storable_picture::p_curr_img_sub, storable_picture::p_img, storable_picture::p_img_sub, inp_par_enc::P_List0_refs, inp_par_enc::partition_mode, poc_based_ref_management_field_pic(), poc_based_ref_management_frame_pic(), inp_par_enc::PocMemoryManagement, img_par::qp, slice::rddata_trellis_curr, inp_par_enc::RDPictureDecision, reorder_lists(), reorder_ref_pic_list(), set_ref_pic_num(), inp_par_enc::SetFirstAsLongTerm, SetMotionVectorsMBBSlice(), SetMotionVectorsMBPSlice(), img_par::structure, img_par::ThisPOC, img_par::width, img_par::width_blk, wp_mcprec_reorder_lists(), and wpxAdaptRefNum().

Referenced by encode_one_slice(), and encode_one_slice_MBAFF().

Here is the call graph for this function:

static Slice * malloc_slice ( ImageParameters p_Img,
InputParameters p_Inp 
) [static]

static void set_ref_pic_num ( Slice currSlice  )  [static]

need to add field ref_pic_num that handles field pair.

Definition at line 1700 of file slice.c.

Referenced by init_slice().

static int start_slice ( Slice currSlice,
StatParameters *  cur_stats 
) [static]

This function generates the slice (and partition) header(s).

Returns:
number of bits used for the slice (and partition) header(s)
Side effects:
Adds slice/partition header symbols to the symbol buffer increments Picture->no_slices, allocates memory for the slice, sets p_Img->currSlice

Initialize CABAC

Definition at line 213 of file slice.c.

References arienco_reset_EC(), arienco_start_encoding(), Bitstream::bits_to_go, Bitstream::byte_pos, CAVLC_init(), PAR_DP_1, slice::partArr, Partition_BC_Header(), RTPUpdateTimestamp(), SliceHeader(), Bitstream::streamBuffer, Bitstream::write_flag, and writeVlcByteAlign().

Referenced by encode_one_slice(), and encode_one_slice_MBAFF().

Here is the call graph for this function:

static int terminate_slice ( Macroblock currMB,
int  lastslice,
StatParameters *  cur_stats 
) [static]


Documentation generated with DoxyGen