mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 11:24:05 +00:00
Separated context related functions and arrays to context.h/.c
This commit is contained in:
parent
d5d0846e92
commit
14fed8bac7
|
@ -83,6 +83,7 @@
|
|||
<ClCompile Include="..\..\src\bitstream.c" />
|
||||
<ClCompile Include="..\..\src\cabac.c" />
|
||||
<ClCompile Include="..\..\src\config.c" />
|
||||
<ClCompile Include="..\..\src\context.c" />
|
||||
<ClCompile Include="..\..\src\encmain.c" />
|
||||
<ClCompile Include="..\..\src\encoder.c" />
|
||||
<ClCompile Include="..\..\src\intra.c" />
|
||||
|
@ -94,6 +95,7 @@
|
|||
<ClInclude Include="..\..\src\bitstream.h" />
|
||||
<ClInclude Include="..\..\src\cabac.h" />
|
||||
<ClInclude Include="..\..\src\config.h" />
|
||||
<ClInclude Include="..\..\src\context.h" />
|
||||
<ClInclude Include="..\..\src\encoder.h" />
|
||||
<ClInclude Include="..\..\src\global.h" />
|
||||
<ClInclude Include="..\..\src\intra.h" />
|
||||
|
|
|
@ -42,6 +42,9 @@
|
|||
<ClCompile Include="..\..\src\transform.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\context.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\global.h">
|
||||
|
@ -71,5 +74,8 @@
|
|||
<ClInclude Include="..\..\src\transform.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\context.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
40
src/cabac.c
40
src/cabac.c
|
@ -209,9 +209,9 @@ void cabac_write(cabac_data* data)
|
|||
|
||||
void cabac_encodeFlush(cabac_data* data, uint8_t end )
|
||||
{
|
||||
data->uiRange = 2;
|
||||
data->uiRange -= 2;
|
||||
|
||||
data->uiLow += 2;
|
||||
data->uiLow += data->uiRange;
|
||||
data->uiLow <<= 7;
|
||||
data->uiRange = 2 << 7;
|
||||
data->bitsLeft -= 7;
|
||||
|
@ -221,10 +221,10 @@ void cabac_encodeFlush(cabac_data* data, uint8_t end )
|
|||
}
|
||||
cabac_finish(data);
|
||||
|
||||
if(!end)
|
||||
{
|
||||
bitstream_put(data->stream,1,1);
|
||||
}
|
||||
bitstream_put(data->stream,1,1);
|
||||
bitstream_align(data->stream);
|
||||
|
||||
cabac_start(data);
|
||||
}
|
||||
|
||||
void cabac_finish(cabac_data* data)
|
||||
|
@ -344,31 +344,3 @@ void cabac_encodeBinsEP(cabac_data* data, uint32_t binValues, int numBins )
|
|||
cabac_write(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cabac_encoderflush(cabac_data* data, uint8_t end)
|
||||
{
|
||||
cabac_encodeBinTrm(data,1);
|
||||
cabac_finish(data);
|
||||
bitstream_put(data->stream,1,1);
|
||||
|
||||
cabac_start(data);
|
||||
|
||||
|
||||
data->uiRange = 2;
|
||||
|
||||
data->uiLow += 2;
|
||||
data->uiLow <<= 7;
|
||||
data->uiRange = 2 << 7;
|
||||
data->bitsLeft -= 7;
|
||||
if(data->bitsLeft < 12)
|
||||
{
|
||||
cabac_write(data);
|
||||
}
|
||||
cabac_finish(data);
|
||||
|
||||
if(!end)
|
||||
{
|
||||
bitstream_put(data->stream, 1, 1 ); // stop bit
|
||||
}
|
||||
}
|
|
@ -61,11 +61,11 @@ void cabac_encodeBin(cabac_data* data, uint32_t binValue );
|
|||
void cabac_encodeFlush(cabac_data* data, uint8_t end );
|
||||
void cabac_encodeBinEP(cabac_data* data, uint32_t binValue );
|
||||
void cabac_encodeBinsEP(cabac_data* data, uint32_t binValues, int numBins );
|
||||
void cabac_encodeBinTrm(cabac_data* data, uint8_t binValue );
|
||||
void cabac_write(cabac_data* data);
|
||||
void cabac_finish(cabac_data* data);
|
||||
void cabac_flush(cabac_data* data);
|
||||
void cabac_encoderflush(cabac_data* data, uint8_t end);
|
||||
void cabac_encodeBinTrm(cabac_data* data, uint8_t binValue );
|
||||
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
|
191
src/context.c
Normal file
191
src/context.c
Normal file
|
@ -0,0 +1,191 @@
|
|||
/**
|
||||
* Part of HEVC Encoder
|
||||
* By Marko Viitanen ( fador at iki.fi ), Tampere University of Technology, Department of Computer Systems.
|
||||
*/
|
||||
|
||||
/*! \file context.c
|
||||
\brief Functions for context derication
|
||||
\author Marko Viitanen
|
||||
\date 2012-08
|
||||
This file contains context derivation functions
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "global.h"
|
||||
#include "config.h"
|
||||
#include "encoder.h"
|
||||
#include "cabac.h"
|
||||
#include "context.h"
|
||||
|
||||
/* CONTEXTS */
|
||||
/* ToDo: move somewhere else */
|
||||
cabac_ctx *SplitFlagSCModel;
|
||||
cabac_ctx g_SplitFlagSCModel[3]; /*<! \brief split flag context models */
|
||||
cabac_ctx g_IntraModeSCModel; /*<! \brief intra mode context models */
|
||||
cabac_ctx g_ChromaPredSCModel[2];
|
||||
cabac_ctx g_TransSubdivSCModel[4]; /*<! \brief intra mode context models */
|
||||
cabac_ctx g_QtCbfSCModelY[3];
|
||||
cabac_ctx g_QtCbfSCModelU[3];
|
||||
//cabac_ctx g_QtCbfSCModelV[3];
|
||||
cabac_ctx g_PartSizeSCModel;
|
||||
cabac_ctx g_CUSigCoeffGroupSCModel[4];
|
||||
cabac_ctx g_CUSigSCModel_luma[24];
|
||||
cabac_ctx g_CUSigSCModel_chroma[24];
|
||||
cabac_ctx g_CuCtxLastY_luma[15];
|
||||
cabac_ctx g_CuCtxLastY_chroma[15];
|
||||
cabac_ctx g_CuCtxLastX_luma[15];
|
||||
cabac_ctx g_CuCtxLastX_chroma[15];
|
||||
cabac_ctx g_CUOneSCModel_luma[24];
|
||||
|
||||
|
||||
void init_contexts(encoder_control *encoder)
|
||||
{
|
||||
uint16_t i;
|
||||
/* Initialize contexts */
|
||||
/* ToDo: add P/B slice */
|
||||
ctx_init(&g_SplitFlagSCModel[0], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][0]);
|
||||
ctx_init(&g_SplitFlagSCModel[1], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][1]);
|
||||
ctx_init(&g_SplitFlagSCModel[2], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][2]);
|
||||
|
||||
ctx_init(&g_IntraModeSCModel, encoder->QP, INIT_INTRA_PRED_MODE[SLICE_I]);
|
||||
|
||||
ctx_init(&g_ChromaPredSCModel[0], encoder->QP, INIT_CHROMA_PRED_MODE[SLICE_I][0]);
|
||||
ctx_init(&g_ChromaPredSCModel[1], encoder->QP, INIT_CHROMA_PRED_MODE[SLICE_I][1]);
|
||||
|
||||
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
ctx_init(&g_TransSubdivSCModel[i], encoder->QP, INIT_TRANS_SUBDIV_FLAG[SLICE_I][i]);
|
||||
ctx_init(&g_CUSigCoeffGroupSCModel[i], encoder->QP, INIT_SIG_CG_FLAG[SLICE_I][i]);
|
||||
}
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
ctx_init(&g_QtCbfSCModelY[i], encoder->QP, INIT_QT_CBF[SLICE_I][i]);
|
||||
ctx_init(&g_QtCbfSCModelU[i], encoder->QP, INIT_QT_CBF[SLICE_I][i+3]);
|
||||
//cxt_init(&g_QtCbfSCModelV[i], encoder->QP, INIT_QT_CBF[SLICE_I][i]);
|
||||
}
|
||||
for(i = 0; i < 15; i++)
|
||||
{
|
||||
ctx_init(&g_CuCtxLastY_luma[i], encoder->QP, INIT_LAST[SLICE_I][i] );
|
||||
ctx_init(&g_CuCtxLastX_luma[i], encoder->QP, INIT_LAST[SLICE_I][i] );
|
||||
|
||||
ctx_init(&g_CuCtxLastY_chroma[i], encoder->QP, INIT_LAST[SLICE_I][i+15] );
|
||||
ctx_init(&g_CuCtxLastX_chroma[i], encoder->QP, INIT_LAST[SLICE_I][i+15] );
|
||||
}
|
||||
|
||||
for(i = 0; i < 24; i++)
|
||||
{
|
||||
ctx_init(&g_CUOneSCModel_luma[i], encoder->QP, INIT_ONE_FLAG[SLICE_I][i]);
|
||||
|
||||
ctx_init(&g_CUSigSCModel_luma[i], encoder->QP, INIT_SIG_FLAG[SLICE_I][i]);
|
||||
if(i < 21)
|
||||
{
|
||||
ctx_init(&g_CUSigSCModel_chroma[i], encoder->QP, INIT_SIG_FLAG[SLICE_I][i+24]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//uint8_t get_context_coeff_abs_significant_flag(uint8_t
|
||||
|
||||
|
||||
/** Pattern decision for context derivation process of significant_coeff_flag
|
||||
* \param sigCoeffGroupFlag pointer to prior coded significant coeff group
|
||||
* \param posXCG column of current coefficient group
|
||||
* \param posYCG row of current coefficient group
|
||||
* \param width width of the block
|
||||
* \param height height of the block
|
||||
* \returns pattern for current coefficient group
|
||||
*/
|
||||
/*
|
||||
Int TComTrQuant::calcPatternSigCtx( const UInt* sigCoeffGroupFlag, UInt posXCG, UInt posYCG, Int width, Int height )
|
||||
{
|
||||
if( width == 4 && height == 4 ) return -1;
|
||||
|
||||
UInt sigRight = 0;
|
||||
UInt sigLower = 0;
|
||||
|
||||
width >>= 2;
|
||||
height >>= 2;
|
||||
if( posXCG < width - 1 )
|
||||
{
|
||||
sigRight = (sigCoeffGroupFlag[ posYCG * width + posXCG + 1 ] != 0);
|
||||
}
|
||||
if (posYCG < height - 1 )
|
||||
{
|
||||
sigLower = (sigCoeffGroupFlag[ (posYCG + 1 ) * width + posXCG ] != 0);
|
||||
}
|
||||
return sigRight + (sigLower<<1);
|
||||
}
|
||||
*/
|
||||
|
||||
/** Context derivation process of coeff_abs_significant_flag
|
||||
* \param patternSigCtx pattern for current coefficient group
|
||||
* \param posX column of current scan position
|
||||
* \param posY row of current scan position
|
||||
* \param blockType log2 value of block size if square block, or 4 otherwise
|
||||
* \param width width of the block
|
||||
* \param height height of the block
|
||||
* \param textureType texture type (TEXT_LUMA...)
|
||||
* \returns ctxInc for current scan position
|
||||
*/
|
||||
/*
|
||||
Int TComTrQuant::getSigCtxInc (
|
||||
Int patternSigCtx,
|
||||
UInt scanIdx,
|
||||
Int posX,
|
||||
Int posY,
|
||||
Int blockType,
|
||||
Int width
|
||||
,Int height
|
||||
,TextType textureType
|
||||
)
|
||||
{
|
||||
const Int ctxIndMap[16] =
|
||||
{
|
||||
0, 1, 4, 5,
|
||||
2, 3, 4, 5,
|
||||
6, 6, 8, 8,
|
||||
7, 7, 8, 8
|
||||
};
|
||||
|
||||
if( posX + posY == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( blockType == 2 )
|
||||
{
|
||||
return ctxIndMap[ 4 * posY + posX ];
|
||||
}
|
||||
|
||||
Int offset = blockType == 3 ? (scanIdx==SCAN_DIAG ? 9 : 15) : (textureType == TEXT_LUMA ? 21 : 12);
|
||||
|
||||
|
||||
Int posXinSubset = posX-((posX>>2)<<2);
|
||||
Int posYinSubset = posY-((posY>>2)<<2);
|
||||
Int cnt = 0;
|
||||
if(patternSigCtx==0)
|
||||
{
|
||||
cnt = posXinSubset+posYinSubset<=2 ? (posXinSubset+posYinSubset==0 ? 2 : 1) : 0;
|
||||
}
|
||||
else if(patternSigCtx==1)
|
||||
{
|
||||
cnt = posYinSubset<=1 ? (posYinSubset==0 ? 2 : 1) : 0;
|
||||
}
|
||||
else if(patternSigCtx==2)
|
||||
{
|
||||
cnt = posXinSubset<=1 ? (posXinSubset==0 ? 2 : 1) : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cnt = 2;
|
||||
}
|
||||
|
||||
return (( textureType == TEXT_LUMA && ((posX>>2) + (posY>>2)) > 0 ) ? 3 : 0) + offset + cnt;
|
||||
}
|
||||
*/
|
101
src/context.h
Normal file
101
src/context.h
Normal file
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
* HEVC Encoder
|
||||
* - Marko Viitanen ( fador at iki.fi ), Tampere University of Technology, Department of Computer Systems.
|
||||
*/
|
||||
|
||||
/*! \file context.h
|
||||
\brief Context
|
||||
\author Marko Viitanen
|
||||
\date 2012-08
|
||||
|
||||
Context derivation function headers
|
||||
*/
|
||||
#ifndef __CONTEXT_H
|
||||
#define __CONTEXT_H
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void init_contexts(encoder_control *encoder);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* CONTEXTS */
|
||||
extern cabac_ctx *SplitFlagSCModel;
|
||||
extern cabac_ctx g_SplitFlagSCModel[3];
|
||||
extern cabac_ctx g_IntraModeSCModel;
|
||||
extern cabac_ctx g_ChromaPredSCModel[2];
|
||||
extern cabac_ctx g_TransSubdivSCModel[4];
|
||||
extern cabac_ctx g_QtCbfSCModelY[3];
|
||||
extern cabac_ctx g_QtCbfSCModelU[3];
|
||||
extern cabac_ctx g_PartSizeSCModel;
|
||||
extern cabac_ctx g_CUSigCoeffGroupSCModel[4];
|
||||
extern cabac_ctx g_CUSigSCModel_luma[24];
|
||||
extern cabac_ctx g_CUSigSCModel_chroma[24];
|
||||
extern cabac_ctx g_CuCtxLastY_luma[15];
|
||||
extern cabac_ctx g_CuCtxLastY_chroma[15];
|
||||
extern cabac_ctx g_CuCtxLastX_luma[15];
|
||||
extern cabac_ctx g_CuCtxLastX_chroma[15];
|
||||
extern cabac_ctx g_CUOneSCModel_luma[24];
|
||||
|
||||
static const uint8_t INIT_SPLIT_FLAG[3][3] =
|
||||
{ { 107, 139, 126 },
|
||||
{ 107, 139, 126 },
|
||||
{ 139, 141, 157 } };
|
||||
|
||||
static const uint8_t INIT_INTRA_PRED_MODE[3] = { 183,154,184 };
|
||||
|
||||
static const uint8_t INIT_CHROMA_PRED_MODE[3][2] = { { 152, 139 }, { 152, 139 }, { 63, 139 } };
|
||||
|
||||
#define CNU 154
|
||||
static const uint8_t INIT_TRANS_SUBDIV_FLAG[3][4] =
|
||||
{
|
||||
{ CNU, 153, 138, 138 },
|
||||
{ CNU, 124, 138, 94 },
|
||||
{ CNU, 224, 167, 122 }
|
||||
};
|
||||
|
||||
static const uint8_t INIT_QT_CBF[3][6] =
|
||||
{
|
||||
{ 153, 111, CNU, 149, 92, 167 },
|
||||
{ 153, 111, CNU, 149, 107, 167 },
|
||||
{ 111, 141, CNU, 94, 138, 182 }
|
||||
};
|
||||
|
||||
static const uint8_t INIT_SIG_CG_FLAG[3][4] =
|
||||
{ { 121, 140, 61, 154 }, { 121, 140, 61, 154 }, { 91, 171, 134, 141 } };
|
||||
|
||||
static const uint8_t INIT_SIG_FLAG[3][45] =
|
||||
{{170,154,139,153,139,123,123, 63,124,153,153,152,152,152,137,152,137,137,166,183,140,136,153,
|
||||
154,170,153,138,138,122,121,122,121,167,153,167,136,121,122,136,121,122, 91,151,183,140,},
|
||||
|
||||
{155,154,139,153,139,123,123, 63,153,153,153,152,152,152,137,152,137,122,166,183,140,136,153,
|
||||
154,170,153,123,123,107,121,107,121,167,153,167,136,149,107,136,121,122, 91,151,183,140,},
|
||||
|
||||
{111,111,125,110,110, 94,124,108,124,139,139,139,168,124,138,124,138,107,107,125,141,179,153,
|
||||
125,140,139,182,182,152,136,152,136,153,182,137,149,192,152,224,136, 31,136,136,139,111,} };
|
||||
|
||||
static const uint8_t INIT_LAST[3][30] =
|
||||
{
|
||||
{ 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, 79,
|
||||
108, 123, 93, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU },
|
||||
{ 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, 94,
|
||||
108, 123, 108, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU },
|
||||
{ 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, 79,
|
||||
108, 123, 63, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU }
|
||||
};
|
||||
|
||||
static const uint8_t INIT_ONE_FLAG[3][24] =
|
||||
{
|
||||
{154,196,167,167,154,152,167,182,182,134,149,136,153,121,136,122,169,208,166,167,154,152,167,182},
|
||||
{154,196,196,167,154,152,167,182,182,134,149,136,153,121,136,137,169,194,166,167,154,167,137,182},
|
||||
{140, 92,137,138,140,152,138,139,153, 74,149, 92,139,107,122,152,140,179,166,182,140,227,122,197}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
136
src/encoder.c
136
src/encoder.c
|
@ -24,6 +24,7 @@
|
|||
#include "cabac.h"
|
||||
#include "picture.h"
|
||||
#include "nal.h"
|
||||
#include "context.h"
|
||||
|
||||
void init_encoder_control(encoder_control* control,bitstream* output)
|
||||
{
|
||||
|
@ -159,6 +160,7 @@ void encode_pic_parameter_set(encoder_control* encoder)
|
|||
|
||||
void encode_seq_parameter_set(encoder_control* encoder)
|
||||
{
|
||||
int i;
|
||||
#ifdef _DEBUG
|
||||
printf("=========== Sequence Parameter Set ID: 0 ===========\n");
|
||||
#endif
|
||||
|
@ -216,7 +218,11 @@ void encode_seq_parameter_set(encoder_control* encoder)
|
|||
WRITE_UE(encoder->stream, 0, "num_short_term_ref_pic_sets");
|
||||
//WRITE_U(encoder->stream, 0, 1, "inter_ref_pic_set_prediction_flag");
|
||||
WRITE_U(encoder->stream, 0, 1, "long_term_ref_pics_present_flag");
|
||||
WRITE_U(encoder->stream, 0, 1, "sps_temporal_mvp_enable_flag");
|
||||
WRITE_U(encoder->stream, 0, 1, "sps_temporal_mvp_enable_flag");
|
||||
for(i = 0; i < MAX_DEPTH; i++)
|
||||
{
|
||||
WRITE_U(encoder->stream, 0, 1, "AMVP modeflag");
|
||||
}
|
||||
WRITE_U(encoder->stream, 0, 1, "sps_extension_flag");
|
||||
}
|
||||
|
||||
|
@ -235,8 +241,6 @@ void encode_vid_parameter_set(encoder_control* encoder)
|
|||
WRITE_UE(encoder->stream, 0, "vps_max_latency_increase");
|
||||
|
||||
WRITE_U(encoder->stream, 0, 1, "vps_extension_flag");
|
||||
|
||||
|
||||
}
|
||||
|
||||
void encode_slice_header(encoder_control* encoder)
|
||||
|
@ -267,7 +271,7 @@ void encode_slice_header(encoder_control* encoder)
|
|||
//WRITE_UE(encoder->stream, encoder->frame&3, "idr_pic_id");
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
WRITE_U(encoder->stream, encoder->frame+1, 8, "pic_order_cnt_lsb");
|
||||
WRITE_U(encoder->stream, 1, 1, "short_term_ref_pic_set_sps_flag");
|
||||
//WRITE_U(encoder->stream, 1, 1, "inter_ref_pic_set_prediction_flag");
|
||||
|
@ -283,75 +287,17 @@ void encode_slice_header(encoder_control* encoder)
|
|||
WRITE_U(encoder->stream, 1, 1, "alignment");
|
||||
}
|
||||
|
||||
/* CONTEXTS */
|
||||
/* ToDo: move somewhere else */
|
||||
cabac_ctx *SplitFlagSCModel;
|
||||
cabac_ctx g_SplitFlagSCModel[3]; /*<! \brief split flag context models */
|
||||
cabac_ctx g_IntraModeSCModel; /*<! \brief intra mode context models */
|
||||
cabac_ctx g_ChromaPredSCModel[2];
|
||||
cabac_ctx g_TransSubdivSCModel[4]; /*<! \brief intra mode context models */
|
||||
cabac_ctx g_QtCbfSCModelY[3];
|
||||
cabac_ctx g_QtCbfSCModelU[3];
|
||||
//cabac_ctx g_QtCbfSCModelV[3];
|
||||
cabac_ctx g_PartSizeSCModel;
|
||||
cabac_ctx g_CUSigCoeffGroupSCModel[4];
|
||||
cabac_ctx g_CUSigSCModel_luma[24];
|
||||
cabac_ctx g_CUSigSCModel_chroma[24];
|
||||
cabac_ctx g_CuCtxLastY_luma[15];
|
||||
cabac_ctx g_CuCtxLastY_chroma[15];
|
||||
cabac_ctx g_CuCtxLastX_luma[15];
|
||||
cabac_ctx g_CuCtxLastX_chroma[15];
|
||||
cabac_ctx g_CUOneSCModel_luma[24];
|
||||
|
||||
|
||||
|
||||
void encode_slice_data(encoder_control* encoder)
|
||||
{
|
||||
uint16_t xCtb,yCtb,i;
|
||||
/* Initialize contexts */
|
||||
/* ToDo: add P/B slice */
|
||||
ctx_init(&g_SplitFlagSCModel[0], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][0]);
|
||||
ctx_init(&g_SplitFlagSCModel[1], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][1]);
|
||||
ctx_init(&g_SplitFlagSCModel[2], encoder->QP, INIT_SPLIT_FLAG[SLICE_I][2]);
|
||||
uint16_t xCtb,yCtb;
|
||||
|
||||
ctx_init(&g_IntraModeSCModel, encoder->QP, INIT_INTRA_PRED_MODE[SLICE_I]);
|
||||
init_contexts(encoder);
|
||||
|
||||
ctx_init(&g_ChromaPredSCModel[0], encoder->QP, INIT_CHROMA_PRED_MODE[SLICE_I][0]);
|
||||
ctx_init(&g_ChromaPredSCModel[1], encoder->QP, INIT_CHROMA_PRED_MODE[SLICE_I][1]);
|
||||
|
||||
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
ctx_init(&g_TransSubdivSCModel[i], encoder->QP, INIT_TRANS_SUBDIV_FLAG[SLICE_I][i]);
|
||||
ctx_init(&g_CUSigCoeffGroupSCModel[i], encoder->QP, INIT_SIG_CG_FLAG[SLICE_I][i]);
|
||||
}
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
ctx_init(&g_QtCbfSCModelY[i], encoder->QP, INIT_QT_CBF[SLICE_I][i]);
|
||||
ctx_init(&g_QtCbfSCModelU[i], encoder->QP, INIT_QT_CBF[SLICE_I][i+3]);
|
||||
//cxt_init(&g_QtCbfSCModelV[i], encoder->QP, INIT_QT_CBF[SLICE_I][i]);
|
||||
}
|
||||
for(i = 0; i < 15; i++)
|
||||
{
|
||||
ctx_init(&g_CuCtxLastY_luma[i], encoder->QP, INIT_LAST[SLICE_I][i] );
|
||||
ctx_init(&g_CuCtxLastX_luma[i], encoder->QP, INIT_LAST[SLICE_I][i] );
|
||||
|
||||
ctx_init(&g_CuCtxLastY_chroma[i], encoder->QP, INIT_LAST[SLICE_I][i+15] );
|
||||
ctx_init(&g_CuCtxLastX_chroma[i], encoder->QP, INIT_LAST[SLICE_I][i+15] );
|
||||
}
|
||||
|
||||
for(i = 0; i < 24; i++)
|
||||
{
|
||||
ctx_init(&g_CUOneSCModel_luma[i], encoder->QP, INIT_ONE_FLAG[SLICE_I][i]);
|
||||
|
||||
ctx_init(&g_CUSigSCModel_luma[i], encoder->QP, INIT_SIG_FLAG[SLICE_I][i]);
|
||||
if(i < 21)
|
||||
{
|
||||
ctx_init(&g_CUSigSCModel_chroma[i], encoder->QP, INIT_SIG_FLAG[SLICE_I][i+24]);
|
||||
}
|
||||
}
|
||||
|
||||
encoder->in.cur_pic.CU[1][0].type = CU_INTRA;
|
||||
encoder->in.cur_pic.CU[1][2].type = CU_INTRA;
|
||||
//encoder->in.cur_pic.CU[1][2].type = CU_INTRA;
|
||||
//encoder->in.cur_pic.CU[1][3].type = CU_INTRA;
|
||||
|
||||
/* Loop through every LCU in the slice */
|
||||
for(yCtb = 0; yCtb < encoder->in.height_in_LCU; yCtb++)
|
||||
|
@ -379,6 +325,9 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
|
|||
int i,x,y;
|
||||
uint8_t split_flag = (depth!=1)?1:0;
|
||||
uint8_t split_model = 0;
|
||||
uint8_t border_x = (encoder->in.width+1)<((xCtb>>(MAX_DEPTH-depth))+1)*(LCU_WIDTH>>depth);
|
||||
uint8_t border_y = (encoder->in.height+1)<((yCtb>>(MAX_DEPTH-depth))+1)*(LCU_WIDTH>>depth);
|
||||
uint8_t border = border_x | border_y;
|
||||
|
||||
/* Get left and top block split_flags and if they are present and true, increase model number */
|
||||
if(xCtb > 0 && GET_SPLITDATA(&(encoder->in.cur_pic.CU[depth][(xCtb>>(MAX_DEPTH-depth))-1+(yCtb>>(MAX_DEPTH-depth))*(encoder->in.width_in_LCU<<MAX_DEPTH)])) == 1)
|
||||
|
@ -389,21 +338,34 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
|
|||
{
|
||||
split_model++;
|
||||
}
|
||||
cabac.ctx = &g_SplitFlagSCModel[split_model];
|
||||
|
||||
|
||||
/* When not in MAX_DEPTH, insert split flag and split the blocks if needed */
|
||||
if(depth != MAX_DEPTH)
|
||||
if(depth != MAX_DEPTH || border)
|
||||
{
|
||||
SET_SPLITDATA(&(encoder->in.cur_pic.CU[depth][(xCtb>>(MAX_DEPTH-depth))+(yCtb>>(MAX_DEPTH-depth))*(encoder->in.width_in_LCU<<MAX_DEPTH)]),split_flag);
|
||||
CABAC_BIN(&cabac, split_flag, "SplitFlag");
|
||||
cabac.ctx = &g_SplitFlagSCModel[split_model];
|
||||
//Implisit split flag when on border
|
||||
if(!border)
|
||||
{
|
||||
CABAC_BIN(&cabac, split_flag, "SplitFlag");
|
||||
}
|
||||
if(split_flag)
|
||||
{
|
||||
/* Split blocks and remember to change x and y block positions */
|
||||
uint8_t change = 1<<(MAX_DEPTH-1-depth);
|
||||
encode_coding_tree(encoder,xCtb,yCtb,depth+1);
|
||||
encode_coding_tree(encoder,xCtb+change,yCtb,depth+1);
|
||||
encode_coding_tree(encoder,xCtb,yCtb+change,depth+1);
|
||||
encode_coding_tree(encoder,xCtb+change,yCtb+change,depth+1);
|
||||
if(!border_x)
|
||||
{
|
||||
encode_coding_tree(encoder,xCtb+change,yCtb,depth+1);
|
||||
}
|
||||
if(!border_y)
|
||||
{
|
||||
encode_coding_tree(encoder,xCtb,yCtb+change,depth+1);
|
||||
}
|
||||
if(!border)
|
||||
{
|
||||
encode_coding_tree(encoder,xCtb+change,yCtb+change,depth+1);
|
||||
}
|
||||
/* We don't need to do anything else here */
|
||||
return;
|
||||
}
|
||||
|
@ -422,7 +384,7 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
|
|||
//If MODE_INTRA
|
||||
//cabac.ctx = &PCMFlagSCModel;
|
||||
/* Code IPCM block */
|
||||
if(1)//encoder->in.cur_pic.CU[depth][(xCtb>>(MAX_DEPTH-depth))+(yCtb>>(MAX_DEPTH-depth))*(encoder->in.width_in_LCU<<MAX_DEPTH)].type <= CU_PCM)
|
||||
if(encoder->in.cur_pic.CU[depth][(xCtb>>(MAX_DEPTH-depth))+(yCtb>>(MAX_DEPTH-depth))*(encoder->in.width_in_LCU<<MAX_DEPTH)].type <= CU_PCM)
|
||||
{
|
||||
cabac_encodeBinTrm(&cabac, 1); /* IPCMFlag == 1 */
|
||||
//printf("\tIPCMFlag = 1\n");
|
||||
|
@ -480,8 +442,11 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
|
|||
*/
|
||||
CABAC_BINS_EP(&cabac, 0, 5, "intraPredMode");
|
||||
|
||||
cabac.ctx = &g_ChromaPredSCModel[0];
|
||||
CABAC_BIN(&cabac,0,"IntraPredChroma");
|
||||
if(encoder->in.video_format != FORMAT_400)
|
||||
{
|
||||
cabac.ctx = &g_ChromaPredSCModel[0];
|
||||
CABAC_BIN(&cabac,0,"IntraPredChroma");
|
||||
}
|
||||
|
||||
/* Coeff */
|
||||
/* Transform tree */
|
||||
|
@ -498,13 +463,16 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
|
|||
*/
|
||||
CbY = 1; /* Let's pretend we have luma coefficients */
|
||||
|
||||
/* Non-zero chroma U Tcoeffs */
|
||||
cabac.ctx = &g_QtCbfSCModelU[0];
|
||||
CABAC_BIN(&cabac,CbU,"cbf_chroma_u");
|
||||
if(encoder->in.video_format != FORMAT_400)
|
||||
{
|
||||
/* Non-zero chroma U Tcoeffs */
|
||||
cabac.ctx = &g_QtCbfSCModelU[0];
|
||||
CABAC_BIN(&cabac,CbU,"cbf_chroma_u");
|
||||
|
||||
/* Non-zero chroma V Tcoeffs */
|
||||
/* Using the same ctx as before */
|
||||
CABAC_BIN(&cabac,CbV,"cbf_chroma_v");
|
||||
/* Non-zero chroma V Tcoeffs */
|
||||
/* Using the same ctx as before */
|
||||
CABAC_BIN(&cabac,CbV,"cbf_chroma_v");
|
||||
}
|
||||
|
||||
/* Non-zero luma Tcoeffs */
|
||||
cabac.ctx = &g_QtCbfSCModelY[1];
|
||||
|
@ -528,6 +496,8 @@ void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, ui
|
|||
CABAC_BIN(&cabac,1,"significant_coeff_flag");
|
||||
}
|
||||
|
||||
/*UInt uiSigCoeffGroupFlag[ MLS_GRP_NUM ];
|
||||
::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM );*/
|
||||
/* n = 15 .. 0 coeff_abs_level_greater1_flag[ n ] */
|
||||
|
||||
/* coeff_abs_level_greater2_flag[ firstGreater1CoeffIdx] */
|
||||
|
|
|
@ -67,60 +67,6 @@ void encode_slice_header(encoder_control* encoder);
|
|||
void encode_coding_tree(encoder_control* encoder,uint16_t xCtb,uint16_t yCtb, uint8_t depth);
|
||||
void encode_lastSignificantXY(encoder_control* encoder,uint8_t lastpos_x, uint8_t lastpos_y, uint8_t width, uint8_t height, uint8_t type, uint8_t scan);
|
||||
|
||||
static const uint8_t INIT_SPLIT_FLAG[3][3] =
|
||||
{ { 107, 139, 126 },
|
||||
{ 107, 139, 126 },
|
||||
{ 139, 141, 157 } };
|
||||
|
||||
static const uint8_t INIT_INTRA_PRED_MODE[3] = { 183,154,184 };
|
||||
|
||||
static const uint8_t INIT_CHROMA_PRED_MODE[3][2] = { { 152, 139 }, { 152, 139 }, { 63, 139 } };
|
||||
|
||||
#define CNU 154
|
||||
static const uint8_t INIT_TRANS_SUBDIV_FLAG[3][4] =
|
||||
{
|
||||
{ CNU, 153, 138, 138 },
|
||||
{ CNU, 124, 138, 94 },
|
||||
{ CNU, 224, 167, 122 }
|
||||
};
|
||||
|
||||
static const uint8_t INIT_QT_CBF[3][6] =
|
||||
{
|
||||
{ 153, 111, CNU, 149, 92, 167 },
|
||||
{ 153, 111, CNU, 149, 107, 167 },
|
||||
{ 111, 141, CNU, 94, 138, 182 }
|
||||
};
|
||||
|
||||
static const uint8_t INIT_SIG_CG_FLAG[3][4] =
|
||||
{ { 121, 140, 61, 154 }, { 121, 140, 61, 154 }, { 91, 171, 134, 141 } };
|
||||
|
||||
static const uint8_t INIT_SIG_FLAG[3][45] =
|
||||
{{170,154,139,153,139,123,123, 63,124,153,153,152,152,152,137,152,137,137,166,183,140,136,153,
|
||||
154,170,153,138,138,122,121,122,121,167,153,167,136,121,122,136,121,122, 91,151,183,140,},
|
||||
|
||||
{155,154,139,153,139,123,123, 63,153,153,153,152,152,152,137,152,137,122,166,183,140,136,153,
|
||||
154,170,153,123,123,107,121,107,121,167,153,167,136,149,107,136,121,122, 91,151,183,140,},
|
||||
|
||||
{111,111,125,110,110, 94,124,108,124,139,139,139,168,124,138,124,138,107,107,125,141,179,153,
|
||||
125,140,139,182,182,152,136,152,136,153,182,137,149,192,152,224,136, 31,136,136,139,111,} };
|
||||
|
||||
static const uint8_t INIT_LAST[3][30] =
|
||||
{
|
||||
{ 125, 110, 124, 110, 95, 94, 125, 111, 111, 79, 125, 126, 111, 111, 79,
|
||||
108, 123, 93, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU },
|
||||
{ 125, 110, 94, 110, 95, 79, 125, 111, 110, 78, 110, 111, 111, 95, 94,
|
||||
108, 123, 108, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU },
|
||||
{ 110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, 79,
|
||||
108, 123, 63, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU, CNU }
|
||||
};
|
||||
|
||||
static const uint8_t INIT_ONE_FLAG[3][24] =
|
||||
{
|
||||
{154,196,167,167,154,152,167,182,182,134,149,136,153,121,136,122,169,208,166,167,154,152,167,182},
|
||||
{154,196,196,167,154,152,167,182,182,134,149,136,153,121,136,137,169,194,166,167,154,167,137,182},
|
||||
{140, 92,137,138,140,152,138,139,153, 74,149, 92,139,107,122,152,140,179,166,182,140,227,122,197}
|
||||
};
|
||||
|
||||
static uint8_t* g_auiSigLastScan[4][7];
|
||||
|
||||
static const uint8_t g_uiGroupIdx[ 32 ] = {0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9};
|
||||
|
|
Loading…
Reference in a new issue