#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"
Go to the source code of this file.
Functions | |
static Slice * | malloc_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) |
Definition in file slice.c.
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().
static void CAVLC_init | ( | Slice * | currSlice | ) | [static] |
Initializes the p_Img->nz_coeff.
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().
int encode_one_slice | ( | ImageParameters * | p_Img, | |
InputParameters * | p_Inp, | |||
int | SliceGroupId, | |||
int | TotalCodedMBs | |||
) |
Encodes one slice.
Go back to the previous MB to recode it
Definition at line 417 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, end_encode_one_macroblock(), end_macroblock(), error(), errortext, ET_SIZE, FmoGetNextMBNr(), FmoGetPreviousMBNr(), init_quant_4x4(), init_quant_8x8(), init_quant_Chroma(), init_slice(), img_par::masterQP, next_macroblock(), macroblock::qp, img_par::qp, inp_par_enc::RCEnable, slice::rddata_trellis_curr, slice::slice_type, start_macroblock(), start_slice(), terminate_slice(), inp_par_enc::WPIterMC, and write_macroblock().
Referenced by code_a_plane().
int encode_one_slice_MBAFF | ( | ImageParameters * | p_Img, | |
InputParameters * | p_Inp, | |||
int | SliceGroupId, | |||
int | TotalCodedMBs | |||
) |
Encodes one slice (MBAFF Frame).
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().
static void free_mem_bipred_mv | ( | short ******* | bipred_mv | ) | [static] |
Free memory from mv.
Definition at line 156 of file slice.c.
References free_mem7Dshort().
Referenced by free_slice().
static void free_mem_mv | ( | short ****** | mv | ) | [static] |
Free memory from mv.
Definition at line 142 of file slice.c.
References free_mem6Dshort().
Referenced by free_slice().
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().
static void free_slice | ( | Slice * | currSlice | ) | [static] |
Memory frees of the Slice structure and of its dependent data structures.
currSlice | Slice to be freed |
Definition at line 1582 of file slice.c.
References slice::all_mv, slice::bipred_mv, inp_par_enc::BiPredMotionEstimation, clear_rdopt(), slice::cofAC, slice::cofDC, delete_contexts_MotionInfo(), delete_contexts_TextureInfo(), slice::direct_pdir, slice::direct_ref_idx, free_colocated(), free_mem2D(), free_mem3D(), free_mem3Dint(), free_mem3Dpel(), free_mem3Dshort(), free_mem4Dmv(), free_mem4Dpel(), free_mem4Dshort(), free_mem_ACcoeff(), free_mem_bipred_mv(), free_mem_DCcoeff(), free_mem_mv(), slice::max_part_nr, slice::mb_ores, slice::mb_pred, slice::mb_rres, img_par::MbaffFrameFlag, inp_par_enc::MbInterlace, slice::mot_ctx, slice::mpr_16x16, slice::mpr_4x4, slice::mpr_8x8, slice::partArr, slice::rddata_trellis_curr, slice::slice_type, Bitstream::streamBuffer, slice::tex_ctx, slice::wbp_weight, inp_par_enc::WeightedBiprediction, inp_par_enc::WeightedPrediction, slice::wp_offset, and slice::wp_weight.
Referenced by free_slice_list().
void free_slice_list | ( | Picture * | currPic | ) |
Memory frees of all Slice structures and of its dependent data structures.
Definition at line 1556 of file slice.c.
References free_nal_unit(), and free_slice().
Referenced by encode_one_frame(), and free_picture().
static int get_mem_bipred_mv | ( | Slice * | currSlice, | |
short ******** | bipred_mv | |||
) | [static] |
Allocate memory for bipredictive mv.
Definition at line 127 of file slice.c.
References get_mem7Dshort(), and slice::max_num_references.
Referenced by init_slice().
static int get_mem_mv | ( | Slice * | currSlice, | |
short ******* | mv | |||
) | [static] |
Allocate memory for mv.
Definition at line 109 of file slice.c.
References get_mem6Dshort(), and slice::max_num_references.
Referenced by init_slice().
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.
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().
static Slice * malloc_slice | ( | ImageParameters * | p_Img, | |
InputParameters * | p_Inp | |||
) | [static] |
Allocates a slice structure along with its dependent data structures.
Definition at line 1425 of file slice.c.
References assignSE2partition, Bitstream::buffer_size, create_contexts_MotionInfo(), create_contexts_TextureInfo(), img_par::currentPicture, get_mem3Dshort(), get_mem4Dshort(), slice::max_part_nr, slice::mot_ctx, no_mem_exit(), slice::num_mb, datapartition::p_Inp, slice::partArr, inp_par_enc::partition_mode, inp_par_enc::slice_argument, inp_par_enc::slice_mode, Bitstream::streamBuffer, inp_par_enc::symbol_mode, slice::tex_ctx, slice::wbp_weight, inp_par_enc::WeightedBiprediction, inp_par_enc::WeightedPrediction, slice::wp_offset, and slice::wp_weight.
Referenced by init_slice().
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).
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().
static int terminate_slice | ( | Macroblock * | currMB, | |
int | lastslice, | |||
StatParameters * | cur_stats | |||
) | [static] |
This function terminates a slice (but doesn't write it out), the old terminate_slice (0).
Definition at line 337 of file slice.c.
References addCabacZeroWords(), arienco_done_encoding(), Bitstream::bits_to_go, nalu_t::buf, Bitstream::byte_buf, Bitstream::byte_pos, create_slice_nalus(), EPZSStructDelete(), free_ref_pic_list_reordering_buffer(), nalu_t::len, slice::max_part_nr, macroblock::p_Img, macroblock::p_slice, slice::partArr, RBSPtoEBSP(), set_pic_bin_count(), slice::slice_type, SODBtoRBSP(), Bitstream::streamBuffer, and Bitstream::write_flag.
Referenced by encode_one_slice(), and encode_one_slice_MBAFF().