#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 "symbol.h"
#include "context_ini.h"
#include "enc_statistics.h"
#include "ratectl.h"
#include "me_epzs.h"
#include "wp.h"
#include "slice.h"
#include "rdoq.h"
#include "wp_mcprec.h"
#include "q_offsets.h"
#include "conformance.h"
#include "quant4x4.h"
#include "quant8x8.h"
#include "quantChroma.h"

Go to the source code of this file.
Functions | |
| static Slice * | malloc_slice () |
| static void | free_slice (Slice *slice) |
| static void | set_ref_pic_num () |
| void | init_ref_pic_list_reordering (Slice *currSlice) |
| static int | start_slice (Slice *currSlice, StatParameters *cur_stats) |
| void | create_slice_nalus (Slice *currSlice) |
| static int | terminate_slice (Slice *currSlice, int lastslice, StatParameters *cur_stats) |
| int | encode_one_slice (int SliceGroupId, Picture *pic, int TotalCodedMBs) |
| int | encode_one_slice_MBAFF (int SliceGroupId, Picture *pic, int TotalCodedMBs) |
| void | init_slice (Slice **currSlice, int start_mb_addr) |
| static void | free_nal_unit (Picture *pic) |
| void | free_slice_list (Picture *currPic) |
| void | poc_ref_pic_reorder_frame (Slice *currSlice, StorablePicture **list, unsigned num_ref_idx_lX_active, int *reordering_of_pic_nums_idc, int *abs_diff_pic_num_minus1, int *long_term_pic_idx, int list_no) |
| void | poc_ref_pic_reorder_field (Slice *currSlice, StorablePicture **list, unsigned num_ref_idx_lX_active, int *reordering_of_pic_nums_idc, int *abs_diff_pic_num_minus1, int *long_term_pic_idx, int list_no) |
| void | UpdateMELambda (ImageParameters *img) |
| void | SetLambda (int j, int qp, double lambda_scale) |
| void | SetLagrangianMultipliersOn () |
| void | SetLagrangianMultipliersOff () |
Variables | |
| ColocatedParams * | Co_located |
| StorablePicture ** | listX [6] |
| const int | QP2QUANT [40] |
Definition in file slice.c.
| void create_slice_nalus | ( | Slice * | currSlice | ) |
This creates a NAL unit structures for all data partition of the slice.
Definition at line 153 of file slice.c.
References AllocNALU(), datapartition::bitstream, Bitstream::buffer_size, ImageParameters::currentPicture, NALU_t::forbidden_bit, Slice::max_part_nr, ImageParameters::nal_reference_idc, NALU_t::nal_reference_idc, datapartition::nal_unit, NALU_t::nal_unit_type, Slice::partArr, InputParameters::partition_mode, Slice::start_mb_nr, NALU_t::startcodeprefix_len, and Bitstream::write_flag.
Referenced by terminate_slice().

| int encode_one_slice | ( | int | SliceGroupId, | |
| Picture * | pic, | |||
| int | TotalCodedMBs | |||
| ) |
Encodes one slice.
Go back to the previous MB to recode it
Definition at line 283 of file slice.c.
References ImageParameters::AdaptiveRounding, InputParameters::AdaptRndPeriod, CalculateOffset8Param(), CalculateOffsetParam(), change_plane_JV(), ImageParameters::checkref, ImageParameters::cod_counter, ImageParameters::colour_plane_id, ImageParameters::current_mb_nr, end_macroblock(), error(), errortext, ET_SIZE, FmoGetNextMBNr(), FmoGetPreviousMBNr(), ImageParameters::frameOffsetAvail, init_quant_4x4(), init_quant_8x8(), init_quant_Chroma(), init_slice(), ImageParameters::masterQP, ImageParameters::nal_reference_idc, next_macroblock(), ImageParameters::NumberofCodedMacroBlocks, ImageParameters::PicSizeInMbs, macroblock::qp, ImageParameters::qp, InputParameters::RCEnable, InputParameters::rdopt, InputParameters::RestrictRef, start_macroblock(), start_slice(), storable_picture::stats, ImageParameters::SumFrameQP, Slice::symbol_mode, terminate_slice(), InputParameters::Transform8x8Mode, ImageParameters::type, InputParameters::UseRDOQuant, InputParameters::WPIterMC, and write_macroblock().
Referenced by code_a_plane().

| int encode_one_slice_MBAFF | ( | int | SliceGroupId, | |
| Picture * | pic, | |||
| 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 415 of file slice.c.
References ImageParameters::AdaptiveRounding, InputParameters::AdaptRndPeriod, ImageParameters::BasicUnit, ImageParameters::bot_MB, ImageParameters::buf_cycle, CalculateOffset8Param(), CalculateOffsetParam(), change_plane_JV(), ImageParameters::checkref, ImageParameters::cod_counter, ImageParameters::colour_plane_id, copy_rdopt_data(), ImageParameters::current_mb_nr, end_macroblock(), error(), errortext, ET_SIZE, ImageParameters::field_mode, FmoGetLastCodedMBOfSliceGroup(), FmoGetNextMBNr(), FmoGetPreviousMBNr(), FmoMB2SliceGroup(), init_quant_4x4(), init_quant_8x8(), init_quant_Chroma(), init_slice(), ImageParameters::masterQP, InputParameters::MbInterlace, MBPairIsField, RD_DATA::min_rdcost, next_macroblock(), InputParameters::num_ref_frames, ImageParameters::num_ref_idx_l0_active, ImageParameters::NumberofCodedMacroBlocks, ImageParameters::PicSizeInMbs, macroblock::qp, ImageParameters::qp, rc_copy_generic(), rc_copy_quadratic(), InputParameters::RCEnable, InputParameters::RCUpdateMode, rddata_bot_field_mb, rddata_bot_frame_mb, InputParameters::rdopt, InputParameters::RestrictRef, start_macroblock(), start_slice(), storable_picture::stats, ImageParameters::SumFrameQP, Slice::symbol_mode, terminate_slice(), ImageParameters::top_field, InputParameters::Transform8x8Mode, ImageParameters::type, update_mv_limits(), write_macroblock(), ImageParameters::write_macroblock, and ImageParameters::write_mbaff_frame.
Referenced by code_a_plane().

| static void free_nal_unit | ( | Picture * | pic | ) | [static] |
This function frees nal units.
Definition at line 1132 of file slice.c.
References datapartition::bitstream, FreeNALU(), Slice::max_part_nr, datapartition::nal_unit, Slice::partArr, and Bitstream::write_flag.
Referenced by free_slice_list().

| static void free_slice | ( | Slice * | slice | ) | [static] |
Memory frees of the Slice structure and of its dependent data structures.
| slice,: | Slice to be freed |
Definition at line 1196 of file slice.c.
References datapartition::bitstream, delete_contexts_MotionInfo(), delete_contexts_TextureInfo(), Slice::max_part_nr, Slice::mot_ctx, Slice::partArr, Bitstream::streamBuffer, Slice::symbol_mode, and Slice::tex_ctx.
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 1170 of file slice.c.
References free_nal_unit(), and free_slice().
Referenced by encode_one_frame(), and free_picture().

| void init_ref_pic_list_reordering | ( | Slice * | currSlice | ) |
init_ref_pic_list_reordering initializations should go here
Definition at line 74 of file slice.c.
References Slice::ref_pic_list_reordering_flag_l0, and Slice::ref_pic_list_reordering_flag_l1.
Referenced by init_slice().
| void init_slice | ( | 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 767 of file slice.c.
References alloc_ref_pic_list_reordering_buffer(), InputParameters::B_List0_refs, InputParameters::B_List1_refs, Bitstream::bits_to_go, datapartition::bitstream, Bitstream::byte_buf, Bitstream::byte_pos, ImageParameters::colour_plane_id, compute_colocated(), compute_colocated_JV(), ImageParameters::current_mb_nr, ImageParameters::currentPicture, ImageParameters::currentSlice, dummy_slice_too_big(), InputParameters::EnableOpenGOP, EPZSSliceInit(), error(), ImageParameters::frame_no, ImageParameters::frame_num, InputParameters::GenerateMultiplePPS, init_lists(), init_mbaff_lists(), init_rdoq_slice(), init_ref_pic_list_reordering(), InitWP(), ImageParameters::last_valid_reference, malloc_slice(), ImageParameters::MbaffFrameFlag, ImageParameters::nal_reference_idc, ImageParameters::num_ref_idx_l0_active, ImageParameters::num_ref_idx_l1_active, ImageParameters::number, InputParameters::NumRefPrimary, storable_picture::p_curr_img, storable_picture::p_curr_img_sub, storable_picture::p_img, storable_picture::p_img_sub, InputParameters::P_List0_refs, Slice::picture_id, poc_based_ref_management_field_pic(), poc_based_ref_management_frame_pic(), poc_ref_pic_reorder_field(), poc_ref_pic_reorder_frame(), InputParameters::PocMemoryManagement, ImageParameters::qp, InputParameters::RDPictureDecision, InputParameters::redundant_pic_flag, decoded_picture_buffer::ref_frames_in_buffer, InputParameters::ReferenceReorder, reorder_ref_pic_list(), InputParameters::SearchMode, set_ref_pic_num(), ImageParameters::structure, ImageParameters::ThisPOC, ImageParameters::type, InputParameters::UseRDOQuant, InputParameters::WPMCPrecFullRef, InputParameters::WPMCPrecision, wpxAdaptRefNum(), wpxReorderLists(), writeB8_typeInfo_CABAC(), writeCBP_CABAC(), writeCBP_VLC(), writeCIPredMode_CABAC(), writeDquant_CABAC(), writeFieldModeInfo_CABAC(), writeIntraPredMode_CABAC(), writeIntraPredMode_CAVLC(), writeMB_transform_size_CABAC(), writeMB_typeInfo_CABAC(), writeMVD_CABAC(), writeRefFrame_CABAC(), writeSE_Dummy(), writeSE_Flag(), writeSE_invFlag(), writeSE_SVLC(), and writeSE_UVLC().
Referenced by encode_one_slice(), and encode_one_slice_MBAFF().

| static Slice * malloc_slice | ( | ) | [static] |
Allocates a slice structure along with its dependent data structures.
Definition at line 1051 of file slice.c.
References assignSE2partition, ImageParameters::bitdepth_chroma, ImageParameters::bitdepth_luma, datapartition::bitstream, Bitstream::buffer_size, create_contexts_MotionInfo(), create_contexts_TextureInfo(), ImageParameters::currentPicture, ImageParameters::FrameSizeInMbs, Slice::max_part_nr, Slice::mot_ctx, no_mem_exit(), Slice::num_mb, Slice::partArr, InputParameters::partition_mode, InputParameters::slice_argument, InputParameters::slice_mode, Bitstream::streamBuffer, InputParameters::symbol_mode, Slice::symbol_mode, and Slice::tex_ctx.
Referenced by init_slice().

| void poc_ref_pic_reorder_field | ( | Slice * | currSlice, | |
| StorablePicture ** | list, | |||
| unsigned | num_ref_idx_lX_active, | |||
| int * | reordering_of_pic_nums_idc, | |||
| int * | abs_diff_pic_num_minus1, | |||
| int * | long_term_pic_idx, | |||
| int | list_no | |||
| ) |
decide reference picture reordering, Field only
Definition at line 1452 of file slice.c.
References frame_store::bottom_field, ImageParameters::frame_num, decoded_picture_buffer::fs_ref, storable_picture::is_long_term, frame_store::is_used, storable_picture::pic_num, storable_picture::poc, decoded_picture_buffer::ref_frames_in_buffer, Slice::ref_pic_list_reordering_flag_l0, Slice::ref_pic_list_reordering_flag_l1, ImageParameters::structure, frame_store::top_field, and storable_picture::used_for_reference.
Referenced by init_slice().
| void poc_ref_pic_reorder_frame | ( | Slice * | currSlice, | |
| StorablePicture ** | list, | |||
| unsigned | num_ref_idx_lX_active, | |||
| int * | reordering_of_pic_nums_idc, | |||
| int * | abs_diff_pic_num_minus1, | |||
| int * | long_term_pic_idx, | |||
| int | list_no | |||
| ) |
decide reference picture reordering, Frame only
Definition at line 1284 of file slice.c.
References frame_store::frame, ImageParameters::frame_num, decoded_picture_buffer::fs_ref, storable_picture::is_long_term, frame_store::is_used, storable_picture::pic_num, storable_picture::poc, decoded_picture_buffer::ref_frames_in_buffer, Slice::ref_pic_list_reordering_flag_l0, Slice::ref_pic_list_reordering_flag_l1, storable_picture::used_for_reference, and InputParameters::WPMCPrecision.
Referenced by init_slice(), and wpxReorderLists().
| static void set_ref_pic_num | ( | ) | [static] |
need to add field ref_pic_num that handles field pair.
Definition at line 1237 of file slice.c.
References storable_picture::bottom_poc, storable_picture::bottom_ref_pic_num, storable_picture::frame_poc, storable_picture::frm_ref_pic_num, storable_picture::poc, storable_picture::ref_pic_num, ImageParameters::structure, storable_picture::structure, storable_picture::top_poc, and storable_picture::top_ref_pic_num.
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 94 of file slice.c.
References arienco_reset_EC(), arienco_start_encoding(), Bitstream::bits_to_go, Bitstream::byte_pos, CAVLC_init(), ImageParameters::currentPicture, ImageParameters::frame_no, PAR_DP_1, Slice::partArr, Partition_BC_Header(), InputParameters::partition_mode, RTPUpdateTimestamp(), SliceHeader(), Bitstream::streamBuffer, Slice::symbol_mode, Bitstream::write_flag, and writeVlcByteAlign().
Referenced by encode_one_slice(), and encode_one_slice_MBAFF().

| static int terminate_slice | ( | Slice * | currSlice, | |
| 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 216 of file slice.c.
References addCabacZeroWords(), arienco_done_encoding(), macroblock::bitcounter, Bitstream::bits_to_go, NALU_t::buf, Bitstream::byte_buf, Bitstream::byte_pos, ImageParameters::bytes_in_picture, create_slice_nalus(), ImageParameters::current_mb_nr, EncodingEnvironment::Ebits_to_go, free_ref_pic_list_reordering_buffer(), NALU_t::len, Slice::max_part_nr, ImageParameters::mb_data, Slice::partArr, RBSPtoEBSP(), set_pic_bin_count(), SODBtoRBSP(), Bitstream::streamBuffer, Slice::symbol_mode, ImageParameters::type, and Bitstream::write_flag.
Referenced by encode_one_slice(), and encode_one_slice_MBAFF().

| const int QP2QUANT[40] |