Merge branch 'master' of Z:/Work/HEVC_encoder into fador

Conflicts:
	.gitignore
This commit is contained in:
Marko Viitanen 2013-09-09 12:11:09 +03:00
commit dce892dce8
6 changed files with 144 additions and 14 deletions

8
.gitignore vendored
View file

@ -1,5 +1,9 @@
# Build files
/bin
/build
/doxygen
# Generated documentation
/doxygen_html
# Other files
*.exe

View file

@ -103,8 +103,8 @@ void bitstream_clear_buffer(bitstream* stream)
/*!
\brief Put bits to bitstream
\param stream pointer bitstream to put the data
\param data pointer to actual data
\param bits number of bits to write
\param data input data
\param bits number of bits to write from data to stream
*/
void bitstream_put(bitstream* stream, uint32_t data, uint8_t bits)
{

View file

@ -51,6 +51,7 @@ cabac_ctx g_cMVPIdxSCModel[2];
void init_contexts(encoder_control *encoder, int8_t SLICE)
{
uint16_t i;
/* Initialize contexts */
/* ToDo: add P/B slice */
ctx_init(&g_cCUMergeFlagExtSCModel, encoder->QP, INIT_MERGE_FLAG_EXT[SLICE][0]);

View file

@ -34,6 +34,9 @@
int16_t g_lambda_cost[55];
uint32_t* g_auiSigLastScan[3][7];
/* Local functions. */
static void add_checksum(encoder_control* encoder);
void initSigLastScan(uint32_t* pBuffD, uint32_t* pBuffH, uint32_t* pBuffV, int32_t iWidth, int32_t iHeight)
{
uint32_t uiNumScanPos = iWidth * iWidth;
@ -269,21 +272,21 @@ void encode_one_frame(encoder_control* encoder)
encode_vid_parameter_set(encoder);
bitstream_align(encoder->stream);
bitstream_flush(encoder->stream);
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 0, NAL_VID_PARAMETER_SET, 0);
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 0, NAL_VPS_NUT, 0);
bitstream_clear_buffer(encoder->stream);
/* Sequence Parameter Set (SPS) */
encode_seq_parameter_set(encoder);
bitstream_align(encoder->stream);
bitstream_flush(encoder->stream);
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 0, NAL_SEQ_PARAMETER_SET, 0);
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 0, NAL_SPS_NUT, 0);
bitstream_clear_buffer(encoder->stream);
/* Picture Parameter Set (PPS) */
encode_pic_parameter_set(encoder);
bitstream_align(encoder->stream);
bitstream_flush(encoder->stream);
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 0, NAL_PIC_PARAMETER_SET, 0);
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 0, NAL_PPS_NUT, 0);
bitstream_clear_buffer(encoder->stream);
/* First slice is IDR */
@ -370,6 +373,8 @@ void encode_one_frame(encoder_control* encoder)
filter_deblock(encoder);
}
/* Calculate checksum */
add_checksum(encoder);
/* Clear prediction data */
/* ToDo: store as reference data */
@ -380,6 +385,37 @@ void encode_one_frame(encoder_control* encoder)
}
/*!
\brief Add a checksum SEI message to the bitstream.
\param encoder The encoder.
\returns Void
*/
static void add_checksum(encoder_control* encoder)
{
unsigned char checksum[3][16];
uint32_t checksum_val;
unsigned int i;
picture_checksum(&(encoder->in.cur_pic), checksum);
WRITE_U(encoder->stream, 132, 8, "sei_type");
WRITE_U(encoder->stream, 13, 8, "size");
WRITE_U(encoder->stream, 2, 8, "hash_type"); /* 2 = checksum*/
for (i = 0; i < 3; ++i) {
/* Pack bits into a single 32 bit uint instead of pushing them one byte at a time. */
checksum_val = (checksum[i][0] << 24) + (checksum[i][1] << 16) + (checksum[i][2] << 8) + (checksum[i][3]);
WRITE_U(encoder->stream, checksum_val, 32, 'picture_checksum');
}
bitstream_align(encoder->stream);
bitstream_flush(encoder->stream);
nal_write(encoder->output, encoder->stream->buffer, encoder->stream->buffer_pos, 0, NAL_SUFFIT_SEI_NUT, 0);
bitstream_clear_buffer(encoder->stream);
}
void encode_pic_parameter_set(encoder_control* encoder)
{
#ifdef _DEBUG

View file

@ -86,3 +86,49 @@ void nal_write(FILE* output, uint8_t* buffer, uint32_t buffer_len, uint8_t nal_r
}
}
/*!
\brief Calculate checksum for one color of the picture.
\param data Beginning of the pixel data for the picture.
\param height Height of the picture.
\param width Width of the picture.
\param stride Width of one row in the pixel array.
\returns Void
*/
static void array_checksum(uint8_t* data, const int height, const int width, const int stride, unsigned char checksum_out[])
{
unsigned char mask;
unsigned int checksum = 0;
int y, x;
for (y = 0; y < height; ++y) {
for (x = 0; x < width; ++x) {
mask = (x & 0xff) ^ (y & 0xff) ^ (x >> 8) ^ (y >> 8);
checksum += (data[(y * stride) + x] & 0xff) ^ mask;
checksum &= 0xffffffff;
}
}
/* Unpack uint into byte-array.*/
checksum_out[0] = (checksum >> 24) & 0xff;
checksum_out[1] = (checksum >> 16) & 0xff;
checksum_out[2] = (checksum >> 8) & 0xff;
checksum_out[3] = (checksum) & 0xff;
}
/*!
\brief Calculate checksums for all colors of the picture.
\param pic The picture that checksum is calculated for.
\param checksum_out Result of the calculation.
\returns Void
*/
void picture_checksum(const picture* pic, unsigned char checksum_out[][16])
{
int stride = pic->width; /* ToDo: != width, if there is a luma margin. */
array_checksum(pic->yRecData, pic->height, pic->width, pic->width, checksum_out[0]);
/* The number of chroma pixels is half that of luma. */
array_checksum(pic->uRecData, pic->height >> 1, pic->width >> 1, pic->width >> 1, checksum_out[1]);
array_checksum(pic->vRecData, pic->height >> 1, pic->width >> 1, pic->width >> 1, checksum_out[2]);
}

View file

@ -13,18 +13,61 @@
#ifndef __NAL_H
#define __NAL_H
enum { NAL_TRAIL_N = 0, NAL_TRAIL_R = 1,
/*!
* \brief NAL unit type codes
*
* These are the nal_unit_type codes from Table 7-1 ITU-T H.265 v1.0.
* The type codes have been prefixed with "NAL_".
*/
enum {
NAL_TRAIL_N = 0,
NAL_TRAIL_R = 1,
NAL_TSA_N = 2,
NAL_TSA_R = 3,
NAL_STSA_N = 4,
NAL_STSA_R = 5,
NAL_RADL_N = 6,
NAL_RADL_R = 7,
NAL_RASL_N = 8,
NAL_RASL_R = 9,
// Reserved RSV_VCL_ N/R 10-15
NAL_BLA_W_LP = 16,
NAL_BLA_W_RADL = 17,
NAL_BLA_N_LP = 18,
NAL_IDR_W_RADL = 19, NAL_IDR_N_LP = 10,
NAL_IDR_W_RADL = 19,
NAL_IDR_N_LP = 20,
NAL_CRA_NUT = 21,
// Reserved RSV_IRAP_VCL 22-23
NAL_RSV_IRAP_VCL23 = 23,
/* Parameter sets */
NAL_VID_PARAMETER_SET = 32, NAL_SEQ_PARAMETER_SET = 33, NAL_PIC_PARAMETER_SET = 34
// Reserved RSV_VCL 24-31
NAL_VPS_NUT = 32,
NAL_SPS_NUT = 33,
NAL_PPS_NUT = 34,
AUD_NUT = 35,
EOS_NUT = 36,
EOB_NUT = 37,
FD_NUT = 38,
PREFIX_SEI_NUT = 39,
NAL_SUFFIT_SEI_NUT = 40,
// Reserved RSV_NVCL 41-47
// Unspecified UNSPEC 48-63
};
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 picture_checksum(const picture* pic, unsigned char* checksum_out);
#endif