mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 19:24:06 +00:00
More work on the slice encoding, trying to send some dummy data
This commit is contained in:
parent
e3e54ea06c
commit
953c04d896
|
@ -14,10 +14,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "cabac.h"
|
|
||||||
#include "bitstream.h"
|
#include "bitstream.h"
|
||||||
|
#include "cabac.h"
|
||||||
|
|
||||||
const uint8_t g_aucNextStateMPS[ 128 ] =
|
|
||||||
|
const uint8_t g_aucNextStateMPS[ 128 ] =
|
||||||
{
|
{
|
||||||
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||||
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
|
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
|
||||||
|
|
|
@ -13,10 +13,6 @@
|
||||||
#ifndef __CABAC_H
|
#ifndef __CABAC_H
|
||||||
#define __CABAC_H
|
#define __CABAC_H
|
||||||
|
|
||||||
#include "bitstream.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern const uint8_t g_aucNextStateMPS[ 128 ];
|
extern const uint8_t g_aucNextStateMPS[ 128 ];
|
||||||
extern const uint8_t g_aucNextStateLPS[ 128 ];
|
extern const uint8_t g_aucNextStateLPS[ 128 ];
|
||||||
extern const uint32_t g_entropyBits[128];
|
extern const uint32_t g_entropyBits[128];
|
||||||
|
@ -30,6 +26,7 @@ typedef struct
|
||||||
uint8_t ucState;
|
uint8_t ucState;
|
||||||
uint32_t binsCoded;
|
uint32_t binsCoded;
|
||||||
} cabac_ctx;
|
} cabac_ctx;
|
||||||
|
|
||||||
#define CTX_STATE(ctx) (ctx.ucState>>1)
|
#define CTX_STATE(ctx) (ctx.ucState>>1)
|
||||||
#define CTX_MPS(ctx) (ctx.ucState&1)
|
#define CTX_MPS(ctx) (ctx.ucState&1)
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,13 @@ void init_encoder_input(encoder_input* input,FILE* inputfile, uint32_t width, ui
|
||||||
input->width = width;
|
input->width = width;
|
||||||
input->height = height;
|
input->height = height;
|
||||||
|
|
||||||
|
input->height_in_LCU = height / LCU_WIDTH;
|
||||||
|
input->width_in_LCU = width / LCU_WIDTH;
|
||||||
|
if(input->height_in_LCU * LCU_WIDTH < height)
|
||||||
|
input->height_in_LCU++;
|
||||||
|
if(input->width_in_LCU * LCU_WIDTH < width)
|
||||||
|
input->width_in_LCU++;
|
||||||
|
|
||||||
input->cur_pic.width = width;
|
input->cur_pic.width = width;
|
||||||
input->cur_pic.height = height;
|
input->cur_pic.height = height;
|
||||||
input->cur_pic.referenced = 0;
|
input->cur_pic.referenced = 0;
|
||||||
|
@ -59,8 +66,20 @@ void encode_one_frame(encoder_control* encoder)
|
||||||
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 1, NAL_PIC_PARAMETER_SET, 0);
|
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 1, NAL_PIC_PARAMETER_SET, 0);
|
||||||
bitstream_clear_buffer(encoder->stream);
|
bitstream_clear_buffer(encoder->stream);
|
||||||
|
|
||||||
|
|
||||||
encode_slice_header(encoder);
|
encode_slice_header(encoder);
|
||||||
encode_slice_data(encoder);
|
encode_slice_data(encoder);
|
||||||
|
cabac_flush(&cabac);
|
||||||
|
bitstream_align(encoder->stream);
|
||||||
|
bitstream_flush(encoder->stream);
|
||||||
|
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 0, NAL_IDR_SLICE, 0);
|
||||||
|
bitstream_clear_buffer(encoder->stream);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
encode_slice_header(encoder);
|
||||||
|
encode_slice_data(encoder);
|
||||||
|
cabac_flush(&cabac);
|
||||||
bitstream_align(encoder->stream);
|
bitstream_align(encoder->stream);
|
||||||
bitstream_flush(encoder->stream);
|
bitstream_flush(encoder->stream);
|
||||||
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 0, NAL_IDR_SLICE, 0);
|
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 0, NAL_IDR_SLICE, 0);
|
||||||
|
@ -116,7 +135,9 @@ void encode_seq_parameter_set(encoder_control* encoder)
|
||||||
WRITE_U(encoder->stream, 0, 1, "pic_cropping_flag");
|
WRITE_U(encoder->stream, 0, 1, "pic_cropping_flag");
|
||||||
WRITE_UE(encoder->stream, 0, "bit_depth_luma_minus8");
|
WRITE_UE(encoder->stream, 0, "bit_depth_luma_minus8");
|
||||||
WRITE_UE(encoder->stream, 0, "bit_depth_chroma_minus8");
|
WRITE_UE(encoder->stream, 0, "bit_depth_chroma_minus8");
|
||||||
WRITE_U(encoder->stream, 0, 1, "pcm_enabled_flag");
|
WRITE_U(encoder->stream, 1, 1, "pcm_enabled_flag");
|
||||||
|
WRITE_U(encoder->stream, 7, 4, "pcm_bit_depth_luma_minus1");
|
||||||
|
WRITE_U(encoder->stream, 7, 4, "pcm_bit_depth_chroma_minus1");
|
||||||
WRITE_U(encoder->stream, 0, 1, "qpprime_y_zero_transquant_bypass_flag");
|
WRITE_U(encoder->stream, 0, 1, "qpprime_y_zero_transquant_bypass_flag");
|
||||||
WRITE_UE(encoder->stream, 0, "log2_max_pic_order_cnt_lsb_minus4");
|
WRITE_UE(encoder->stream, 0, "log2_max_pic_order_cnt_lsb_minus4");
|
||||||
WRITE_UE(encoder->stream, 0, "max_dec_pic_buffering");
|
WRITE_UE(encoder->stream, 0, "max_dec_pic_buffering");
|
||||||
|
@ -131,15 +152,16 @@ void encode_seq_parameter_set(encoder_control* encoder)
|
||||||
//If log2MinCUSize == 3
|
//If log2MinCUSize == 3
|
||||||
WRITE_U(encoder->stream, 0, 1, "DisInter4x4");
|
WRITE_U(encoder->stream, 0, 1, "DisInter4x4");
|
||||||
|
|
||||||
/* //IF PCM
|
//IF PCM
|
||||||
{
|
{
|
||||||
WRITE_UE(encoder->stream, 0, "log2_min_pcm_coding_block_size_minus3");
|
WRITE_UE(encoder->stream, 0, "log2_min_pcm_coding_block_size_minus3");
|
||||||
WRITE_UE(encoder->stream, 0, "log2_diff_max_min_pcm_coding_block_size");
|
WRITE_UE(encoder->stream, 0, "log2_diff_max_min_pcm_coding_block_size");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
WRITE_UE(encoder->stream, 2, "max_transform_hierarchy_depth_inter");
|
WRITE_UE(encoder->stream, 2, "max_transform_hierarchy_depth_inter");
|
||||||
WRITE_UE(encoder->stream, 2, "max_transform_hierarchy_depth_intra");
|
WRITE_UE(encoder->stream, 2, "max_transform_hierarchy_depth_intra");
|
||||||
|
|
||||||
WRITE_U(encoder->stream, 0, 1, "scaling_list_enable_flag");
|
WRITE_U(encoder->stream, 0, 1, "scaling_list_enable_flag");
|
||||||
WRITE_U(encoder->stream, 0, 1, "chroma_pred_from_luma_enabled_flag");
|
WRITE_U(encoder->stream, 0, 1, "chroma_pred_from_luma_enabled_flag");
|
||||||
WRITE_U(encoder->stream, 0, 1, "transform_skip_enabled_flag");
|
WRITE_U(encoder->stream, 0, 1, "transform_skip_enabled_flag");
|
||||||
|
@ -149,6 +171,9 @@ void encode_seq_parameter_set(encoder_control* encoder)
|
||||||
WRITE_U(encoder->stream, 0, 1, "nsrqt_enabled_flag");
|
WRITE_U(encoder->stream, 0, 1, "nsrqt_enabled_flag");
|
||||||
WRITE_U(encoder->stream, 0, 1, "sample_adaptive_offset_enabled_flag");
|
WRITE_U(encoder->stream, 0, 1, "sample_adaptive_offset_enabled_flag");
|
||||||
WRITE_U(encoder->stream, 0, 1, "adaptive_loop_filter_enabled_flag");
|
WRITE_U(encoder->stream, 0, 1, "adaptive_loop_filter_enabled_flag");
|
||||||
|
//IF PCM
|
||||||
|
WRITE_U(encoder->stream, 0, 1, "pcm_loop_filter_disable_flag");
|
||||||
|
//endif
|
||||||
WRITE_U(encoder->stream, 0, 1, "temporal_id_nesting_flag");
|
WRITE_U(encoder->stream, 0, 1, "temporal_id_nesting_flag");
|
||||||
WRITE_UE(encoder->stream, 0, "num_short_term_ref_pic_sets");
|
WRITE_UE(encoder->stream, 0, "num_short_term_ref_pic_sets");
|
||||||
WRITE_U(encoder->stream, 0, 1, "long_term_ref_pics_present_flag");
|
WRITE_U(encoder->stream, 0, 1, "long_term_ref_pics_present_flag");
|
||||||
|
@ -158,6 +183,9 @@ void encode_seq_parameter_set(encoder_control* encoder)
|
||||||
|
|
||||||
void encode_slice_header(encoder_control* encoder)
|
void encode_slice_header(encoder_control* encoder)
|
||||||
{
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("=========== Slice ===========\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
WRITE_U(encoder->stream, 1, 1, "first_slice_in_pic_flag");
|
WRITE_U(encoder->stream, 1, 1, "first_slice_in_pic_flag");
|
||||||
WRITE_UE(encoder->stream, SLICE_I, "slice_type");
|
WRITE_UE(encoder->stream, SLICE_I, "slice_type");
|
||||||
|
@ -181,12 +209,45 @@ void encode_slice_header(encoder_control* encoder)
|
||||||
/*
|
/*
|
||||||
Skip unpresent flags */
|
Skip unpresent flags */
|
||||||
// if !entropy_slice_flag
|
// if !entropy_slice_flag
|
||||||
WRITE_UE(encoder->stream, 0, "slice_qp_delta");
|
WRITE_UE(encoder->stream, 0, "slice_qp_delta");
|
||||||
|
WRITE_UE(encoder->stream, 0, "5_minus_max_num_merge_cand");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cabac_ctx SplitFlagSCModel;
|
||||||
|
|
||||||
void encode_slice_data(encoder_control* encoder)
|
void encode_slice_data(encoder_control* encoder)
|
||||||
{
|
{
|
||||||
uint16_t xCtb,yCtb;
|
uint16_t xCtb,yCtb;
|
||||||
|
cxt_init(&SplitFlagSCModel, 26, 0);
|
||||||
|
cxt_init(&cabac.ctx, 26, 0);
|
||||||
|
for(yCtb = 0; yCtb < encoder->in.height_in_LCU; yCtb++)
|
||||||
|
{
|
||||||
|
for(xCtb = 0; xCtb < encoder->in.width_in_LCU; xCtb++)
|
||||||
|
{
|
||||||
|
uint8_t depth = 0;
|
||||||
|
encode_coding_tree(encoder, xCtb,yCtb, depth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, uint8_t depth)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Split flag
|
||||||
|
cabac_encodeBin(&cabac, 5);
|
||||||
|
|
||||||
|
/* coding_unit( x0, y0, log2CbSize ) */
|
||||||
|
/* prediction_unit 2Nx2N*/
|
||||||
|
//If MODE_INTRA
|
||||||
|
|
||||||
|
//endif
|
||||||
|
|
||||||
|
/* end prediction unit */
|
||||||
|
cabac_encodeBin(&cabac, 0); //prev_intra_luma_pred_flag
|
||||||
|
|
||||||
|
cabac_encodeBin(&cabac, 1); //rem_intra_luma_pred_mode
|
||||||
|
|
||||||
|
/* end coding_unit */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
#ifndef _ENCODER_H
|
#ifndef _ENCODER_H
|
||||||
#define _ENCODER_H
|
#define _ENCODER_H
|
||||||
|
|
||||||
#include "bitstream.h"
|
|
||||||
#include "picture.h"
|
#include "picture.h"
|
||||||
|
#include "bitstream.h"
|
||||||
|
|
||||||
typedef struct encoder_control;
|
typedef struct encoder_control;
|
||||||
|
|
||||||
|
@ -58,5 +58,6 @@ void encode_seq_parameter_set(encoder_control* encoder);
|
||||||
void encode_pic_parameter_set(encoder_control* encoder);
|
void encode_pic_parameter_set(encoder_control* encoder);
|
||||||
void encode_slice_data(encoder_control* encoder);
|
void encode_slice_data(encoder_control* encoder);
|
||||||
void encode_slice_header(encoder_control* encoder);
|
void encode_slice_header(encoder_control* encoder);
|
||||||
|
void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, uint8_t depth);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -23,7 +23,7 @@
|
||||||
#define MAX(a,b) (((a)<(b))?(b):(a))
|
#define MAX(a,b) (((a)<(b))?(b):(a))
|
||||||
#define MIN(a,b) (((a)>(b))?(b):(a))
|
#define MIN(a,b) (((a)>(b))?(b):(a))
|
||||||
|
|
||||||
#define LCU 64 /*!< Largest Coding Unit */
|
#define LCU_WIDTH 64 /*!< Largest Coding Unit */
|
||||||
|
|
||||||
#define VERSION_STRING "0.1 "
|
#define VERSION_STRING "0.1 "
|
||||||
#define VERSION 0.1
|
#define VERSION 0.1
|
||||||
|
@ -43,5 +43,4 @@
|
||||||
#define MODE_NONE 15
|
#define MODE_NONE 15
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -17,9 +17,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "encoder.h"
|
#include "bitstream.h"
|
||||||
#include "cabac.h"
|
|
||||||
#include "picture.h"
|
#include "picture.h"
|
||||||
|
#include "cabac.h"
|
||||||
|
#include "encoder.h"
|
||||||
|
|
||||||
|
|
||||||
#include "nal.h"
|
#include "nal.h"
|
||||||
|
|
||||||
void nal_write(FILE* output, uint8_t* buffer, uint32_t buffer_len, uint8_t nal_ref, uint8_t nal_type, uint8_t temporal_id)
|
void nal_write(FILE* output, uint8_t* buffer, uint32_t buffer_len, uint8_t nal_ref, uint8_t nal_type, uint8_t temporal_id)
|
||||||
|
@ -32,7 +35,7 @@ void nal_write(FILE* output, uint8_t* buffer, uint32_t buffer_len, uint8_t nal_r
|
||||||
const uint8_t zero = 0x00;
|
const uint8_t zero = 0x00;
|
||||||
|
|
||||||
//start_code_prefix_one_3bytes
|
//start_code_prefix_one_3bytes
|
||||||
fwrite(&zero, 1, 1, output);
|
//fwrite(&zero, 1, 1, output);
|
||||||
fwrite(&zero, 1, 1, output);
|
fwrite(&zero, 1, 1, output);
|
||||||
fwrite(&zero, 1, 1, output);
|
fwrite(&zero, 1, 1, output);
|
||||||
fwrite(&start_code_prefix_one_3bytes, 1, 1, output);
|
fwrite(&start_code_prefix_one_3bytes, 1, 1, output);
|
||||||
|
|
|
@ -10,7 +10,11 @@
|
||||||
|
|
||||||
NAL function headers
|
NAL function headers
|
||||||
*/
|
*/
|
||||||
|
#ifndef __NAL_H
|
||||||
|
#define __NAL_H
|
||||||
|
|
||||||
enum { NAL_IDR_SLICE = 5, NAL_SEQ_PARAMETER_SET = 7, NAL_PIC_PARAMETER_SET = 8 };
|
enum { NAL_IDR_SLICE = 0x45, NAL_SEQ_PARAMETER_SET = 7, NAL_PIC_PARAMETER_SET = 8 };
|
||||||
|
|
||||||
void nal_write(FILE* output, uint8_t* buffer, uint32_t buffer_len, uint8_t nal_ref, uint8_t nal_type, uint8_t temporal_id);
|
void nal_write(FILE* output, uint8_t* buffer, uint32_t buffer_len, uint8_t nal_ref, uint8_t nal_type, uint8_t temporal_id);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue