Bitstream fixes to enable HM7.0 combatibility

This commit is contained in:
Marko Viitanen 2012-06-06 13:42:02 +03:00
parent aaa6f59cef
commit 38cd4bd429
4 changed files with 30 additions and 19 deletions

View file

@ -88,8 +88,14 @@ void bitstream_init(bitstream* stream)
void bitstream_alloc(bitstream* stream, uint32_t alloc) void bitstream_alloc(bitstream* stream, uint32_t alloc)
{ {
stream->buffer = (uint8_t*)malloc(alloc); stream->buffer = (uint8_t*)malloc(alloc);
stream->bufferlen = alloc;
//Clear just to be sure //Clear just to be sure
memset(stream->buffer,0,alloc); bitstream_clear_buffer(stream);
}
void bitstream_clear_buffer(bitstream* stream)
{
memset(stream->buffer,0,stream->bufferlen);
stream->buffer_pos = 0; stream->buffer_pos = 0;
} }
@ -139,8 +145,6 @@ void bitstream_put(bitstream* stream, uint32_t data, uint8_t bits)
stream->cur_bit = 0; stream->cur_bit = 0;
if(stream->cur_byte==32) if(stream->cur_byte==32)
{ {
//We only have bytes 0..31
stream->cur_byte--;
//Flush data out //Flush data out
bitstream_flush(stream); bitstream_flush(stream);
} }
@ -152,9 +156,6 @@ void bitstream_put(bitstream* stream, uint32_t data, uint8_t bits)
stream->data[stream->cur_byte] |= (data<<(bitsleft-bits)); stream->data[stream->cur_byte] |= (data<<(bitsleft-bits));
stream->cur_bit+=bits; stream->cur_bit+=bits;
} }
} }
/* /*
@ -193,7 +194,7 @@ void bitstream_flush(bitstream* stream)
if(stream->cur_byte) if(stream->cur_byte)
{ {
/* Handle endianness issue */ /* Handle endianness issue */
for(i = 0; i < stream->cur_byte+1; i++) for(i = 0; i < stream->cur_byte; i++)
{ {
/* "network" is big-endian */ /* "network" is big-endian */
correct_endian = htonl(stream->data[i]); correct_endian = htonl(stream->data[i]);

View file

@ -17,6 +17,7 @@ typedef struct
FILE* output; FILE* output;
uint8_t* buffer; uint8_t* buffer;
uint32_t buffer_pos; uint32_t buffer_pos;
uint32_t bufferlen;
} bitstream; } bitstream;
typedef struct typedef struct
@ -30,6 +31,7 @@ extern bitTable *g_exp_table;
int floorLog2(unsigned int n); int floorLog2(unsigned int n);
void bitstream_alloc(bitstream* stream, uint32_t alloc); void bitstream_alloc(bitstream* stream, uint32_t alloc);
void bitstream_clear_buffer(bitstream* stream);
void bitstream_init(bitstream* stream); void bitstream_init(bitstream* stream);
void bitstream_put(bitstream* stream, uint32_t data, uint8_t bits); void bitstream_put(bitstream* stream, uint32_t data, uint8_t bits);
/* /*

View file

@ -52,6 +52,8 @@ void encode_one_frame(encoder_control* encoder)
bitstream_flush(encoder->stream); bitstream_flush(encoder->stream);
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 1, NAL_SEQ_PARAMETER_SET, 0); nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 1, NAL_SEQ_PARAMETER_SET, 0);
bitstream_clear_buffer(encoder->stream);
encode_pic_parameter_set(encoder); encode_pic_parameter_set(encoder);
bitstream_align(encoder->stream); bitstream_align(encoder->stream);
bitstream_flush(encoder->stream); bitstream_flush(encoder->stream);
@ -72,8 +74,12 @@ void encode_pic_parameter_set(encoder_control* encoder)
WRITE_U(encoder->stream, 0, 1, "sign_data_hiding_flag"); WRITE_U(encoder->stream, 0, 1, "sign_data_hiding_flag");
WRITE_U(encoder->stream, 0, 1, "cabac_init_present_flag"); WRITE_U(encoder->stream, 0, 1, "cabac_init_present_flag");
WRITE_U(encoder->stream, 0, 3, "num_ref_idx_l0_default_active_minus1");
WRITE_U(encoder->stream, 0, 3, "num_ref_idx_l1_default_active_minus1");
/*
WRITE_UE(encoder->stream, 0, "num_ref_idx_l0_default_active_minus1"); WRITE_UE(encoder->stream, 0, "num_ref_idx_l0_default_active_minus1");
WRITE_UE(encoder->stream, 0, "num_ref_idx_l1_default_active_minus1"); WRITE_UE(encoder->stream, 0, "num_ref_idx_l1_default_active_minus1");
*/
WRITE_SE(encoder->stream, 0, "pic_init_qp_minus26"); WRITE_SE(encoder->stream, 0, "pic_init_qp_minus26");
WRITE_U(encoder->stream, 0, 1, "constrained_intra_pred_flag"); WRITE_U(encoder->stream, 0, 1, "constrained_intra_pred_flag");
@ -134,15 +140,15 @@ void encode_seq_parameter_set(encoder_control* encoder)
WRITE_UE(encoder->stream, 0, "log2_min_transform_block_size_minus2"); WRITE_UE(encoder->stream, 0, "log2_min_transform_block_size_minus2");
WRITE_UE(encoder->stream, 3, "log2_diff_max_min_transform_block_size"); WRITE_UE(encoder->stream, 3, "log2_diff_max_min_transform_block_size");
WRITE_U(encoder->stream, 0, 1, "unknown_flag");
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");
WRITE_U(encoder->stream, 0, 1, "deblocking_filter_in_aps_enabled_flag"); WRITE_U(encoder->stream, 0, 1, "deblocking_filter_in_aps_enabled_flag");
WRITE_U(encoder->stream, 0, 1, "seq_loop_filter_across_slices_enabled_flag"); WRITE_U(encoder->stream, 0, 1, "seq_loop_filter_across_slices_enabled_flag");
WRITE_U(encoder->stream, 0, 1, "asymmetric_motion_partitions_enabled_flag"); WRITE_U(encoder->stream, 0, 1, "asymmetric_motion_partitions_enabled_flag");

View file

@ -27,9 +27,9 @@ void nal_write(FILE* output, uint8_t* buffer, uint32_t buffer_len, uint8_t nal_r
uint8_t byte; uint8_t byte;
uint32_t i; uint32_t i;
uint8_t zerocount=0; uint8_t zerocount=0;
uint8_t emulation_prevention_three_byte = 0x03; const uint8_t emulation_prevention_three_byte = 0x03;
uint8_t start_code_prefix_one_3bytes = 0x01; const uint8_t start_code_prefix_one_3bytes = 0x01;
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);
@ -59,10 +59,12 @@ void nal_write(FILE* output, uint8_t* buffer, uint32_t buffer_len, uint8_t nal_r
else else
zerocount = 0; zerocount = 0;
/* Write the actual data */
fwrite(&buffer[i], 1, 1, output); fwrite(&buffer[i], 1, 1, output);
} }
//If last byte was 0, add emulation_prevention_three_byte //If last byte was 0, add emulation_prevention_three_byte
//if(buffer[buffer_len-1] == 0) if(buffer[buffer_len-1] == 0)
// fwrite(&emulation_prevention_three_byte, 1, 1, output); fwrite(&emulation_prevention_three_byte, 1, 1, output);
} }