1
/**************************************************************************
3
This software module was originally developed by
8
in the course of development of the MPEG-4 Video (ISO/IEC 14496-2) standard.
9
This software module is an implementation of a part of one or more MPEG-4
10
Video (ISO/IEC 14496-2) tools as specified by the MPEG-4 Video (ISO/IEC
13
ISO/IEC gives users of the MPEG-4 Video (ISO/IEC 14496-2) standard free
14
license to this software module or modifications thereof for use in hardware
15
or software products claiming conformance to the MPEG-4 Video (ISO/IEC
18
Those intending to use this software module in hardware or software products
19
are advised that its use may infringe existing patents. The original
20
developer of this software module and his/her company, the subsequent
21
editors and their companies, and ISO/IEC have no liability for use of this
22
software module or modifications thereof in an implementation. Copyright is
23
not released for non MPEG-4 Video (ISO/IEC 14496-2) standard conforming
26
NTT retains full right to use the code for his/her own
27
purpose, assign or donate the code to a third party and to inhibit third
28
parties from using the code for non MPEG-4 Video (ISO/IEC 14496-2) standard
29
conforming products. This copyright notice must be included in all copies or
40
Implementation of the CNewPredEncoder class.
44
**************************************************************************/
49
static char BASED_CODE THIS_FILE[] = __FILE__;
60
#include "bitstrm.hpp"
61
#include "newpred.hpp"
64
CNewPredEncoder::CNewPredEncoder() : CNewPred()
66
m_enumWho = NP_ENCODER;
69
CNewPredEncoder::~CNewPredEncoder()
71
endNEWPREDcnt( m_pNewPredControl );
74
void CNewPredEncoder::SetObject (
80
char* pchSlicePointParam,
81
Bool bNewpredSegmentType,
84
CVOPU8YUVBA* pNPvopcRefQ0,
85
CVOPU8YUVBA* pNPvopcRefQ1,
91
m_iNumBitsVopID = iNumBitsTimeIncr + NUMBITS_VOP_ID_PLUS;
92
if( m_iNumBitsVopID > NP_MAX_NUMBITS_VOP_ID )
93
m_iNumBitsVopID = NP_MAX_NUMBITS_VOP_ID;
96
m_iNPNumMBX = m_iWidth/MB_SIZE;
97
m_iNPNumMBY = m_iHeight/MB_SIZE;
99
m_iNumBuffEnc = ENC_BUFCNT;
100
m_bNewPredSegmentType = bNewpredSegmentType;
103
m_bShapeOnly = bShapeOnly;
105
m_pNPvopcRefQ0 = pNPvopcRefQ0; // set reference picture memory
106
m_pNPvopcRefQ1 = pNPvopcRefQ1; // set original picture memory
108
m_rctNPFrameY = rctNPFrameY;
109
m_rctNPFrameUV = rctNPFrameUV;
111
Int iHeightUV = iHeight/(MB_SIZE/BLOCK_SIZE);
112
Int iWidthUV = iWidth/(MB_SIZE/BLOCK_SIZE);
114
if (m_bShapeOnly == FALSE) {
115
m_pchNewPredRefY = new PixelC[(2*EXPANDY_REF_FRAME+iWidth)*(2*EXPANDY_REF_FRAME+iHeight)];
116
m_pchNewPredRefU = new PixelC[(2*EXPANDUV_REF_FRAME+iWidthUV)*(2*EXPANDUV_REF_FRAME+iHeightUV)];
117
m_pchNewPredRefV = new PixelC[(2*EXPANDUV_REF_FRAME+iWidthUV)*(2*EXPANDUV_REF_FRAME+iHeightUV)];
120
GetSlicePoint(pchSlicePointParam);
122
m_pNewPredControl = initNEWPREDcnt( uiVOId );
123
sprintf( refname, "%s", pchRefname);
127
Int CNewPredEncoder::SetVPData (
130
int *md_iNumBitsVopID,
131
int *md_iVopID4Prediction_Indication,
132
int *md_iVopID4Prediction
136
static int CurrentSlice = 0;
142
m_iVopID4Prediction = m_pNewPredControl->ref[CurrentSlice];
144
iPut += m_iNumBitsVopID;
145
if((m_iVopID - 1) == m_iVopID4Prediction || m_iVopID4Prediction == 0)
146
m_iVopID4Prediction_Indication = 0;
148
m_iVopID4Prediction_Indication = 1;
150
iPut += NUMBITS_VOP_ID_FOR_PREDICTION_INDICATION;
151
if( m_iVopID4Prediction_Indication )
153
iPut += m_iNumBitsVopID;
158
if (m_bNewPredSegmentType == 0)
160
m_iVopID4Prediction = m_pNewPredControl->ref[CurrentSlice];
161
iPut += m_iNumBitsVopID;
163
if((m_iVopID - 1) == m_iVopID4Prediction || m_iVopID4Prediction == 0)
164
m_iVopID4Prediction_Indication = 0;
166
m_iVopID4Prediction_Indication = 1;
168
iPut += NUMBITS_VOP_ID_FOR_PREDICTION_INDICATION;
169
if( m_iVopID4Prediction_Indication )
171
iPut += m_iNumBitsVopID;
176
*md_iVopID = m_iVopID;
177
*md_iNumBitsVopID = m_iNumBitsVopID;
178
*md_iVopID4Prediction_Indication = m_iVopID4Prediction_Indication;
179
*md_iVopID4Prediction = m_iVopID4Prediction;
183
/* move from newpred.cpp */
184
void CNewPredEncoder::load_ref_ind()
197
memset(m_pNewPredControl->ref_tbl, 0x00, 0x800*MAX_NumGOB*sizeof(int));
199
if( (read_file = fopen(refname,"r")) == NULL ) {
201
"Unable to open Ref_Indication_file: %s\n",
206
while( !feof(read_file) ) {
210
if( fgets(buf,256,read_file) == 0 )
212
fprintf( stderr, "Read error!! : %s\n", refname );
217
check_comment( buf );
219
if( check_space(buf)!=0 ) {
220
fgets( buf,256,read_file );
225
dtp = strtok( buf, " \t\n" );
226
frameNo = atoi( dtp );
228
while( (dtp = strtok(NULL, " \t\n")) != NULL ) {
229
int_dt = atoi( dtp );
231
if( int_dt < 0 || int_dt > count + 1 ) {
235
if(int_dt > (int)~(0xffffffff<<m_iNumBitsVopID)) {
239
m_pNewPredControl->ref_tbl[count][i++] = int_dt;
240
if( i >= MAX_NumGOB )
244
if( err_flag != 0 || i > (m_iHeight/MB_SIZE) )
247
"Error reference frame table: %s(%d Line)\n", refname, line );
255
fgets( buf, 256, read_file );
263
NEWPREDcnt* CNewPredEncoder::initNEWPREDcnt( UInt uiVO_id)
266
NEWPREDcnt* newpredCnt;
268
newpredCnt = (NEWPREDcnt *) malloc(sizeof (NEWPREDcnt));
269
memset(newpredCnt, 0, sizeof(NEWPREDcnt));
272
for( i = 0; i < NP_MAX_NUMSLICE; i++ ) {
273
if( m_piSlicePoint[i] < 0 )
279
newpredCnt->NPRefBuf = (NEWPRED_buf***)aalloc(m_iNumSlice,m_iNumBuffEnc,sizeof(NEWPRED_buf*));
280
if (newpredCnt->NPRefBuf == NULL) {
281
fprintf(stderr, "initNEWPREDcnt: ERROR Memory allocate error(NEWPRED_buf)\n");
284
newpredCnt->ref = new int[m_iNumSlice];
285
if (newpredCnt->ref == NULL) {
286
fprintf(stderr, "initNEWPREDcnt: ERROR Memory allocate error(ref)\n");
289
memset(newpredCnt->ref, 0, sizeof(int)*m_iNumSlice);
291
Int *iY = new int[m_iNumSlice];
292
m_iHMBNum = new int[m_iNumSlice];
294
for (i= 0; (i < m_iNumSlice); i++) {
295
if (i+1 < m_iNumSlice) {
296
iY[i] = *(m_piSlicePoint + i+1) - *(m_piSlicePoint + i);
298
iY[i] = (m_iNPNumMBX*m_iNPNumMBY) - *(m_piSlicePoint + i);
300
m_iHMBNum[i] = iY[i] / m_iNPNumMBX;
302
if (m_iHMBNum[i] == 0)
307
for (i= 0; (i < m_iNumSlice) && (*(m_piSlicePoint + i) >= 0); i++) {
308
Int iWidthUV = m_iWidth/(MB_SIZE/BLOCK_SIZE);
309
Int iHeightUV = (MB_SIZE * m_iHMBNum[i])/(MB_SIZE/BLOCK_SIZE);
311
for (j= 0; j<m_iNumBuffEnc; j++) {
312
newpredCnt->NPRefBuf[i][j] = new NEWPRED_buf;
313
if (newpredCnt->NPRefBuf[i][j] == NULL) {
314
fprintf(stderr, "initNEWPREDcnt: ERROR Memory allocate error(NEWPRED_buf)\n");
318
newpredCnt->NPRefBuf[i][j]->vop_id = 0;
320
newpredCnt->NPRefBuf[i][j]->iSizeY = (2*EXPANDY_REF_FRAME+m_iWidth)*(MB_SIZE* m_iHMBNum[i]);
321
newpredCnt->NPRefBuf[i][j]->iSizeUV = (EXPANDY_REF_FRAME+iWidthUV)* iHeightUV;
323
newpredCnt->NPRefBuf[i][j]->iSlice = i;
325
newpredCnt->NPRefBuf[i][j]->pdata.pchY = new PixelC[newpredCnt->NPRefBuf[i][j]->iSizeY];
326
if (newpredCnt->NPRefBuf[i][j]->pdata.pchY == NULL) {
327
fprintf(stderr, "initNEWPREDcnt: ERROR Memory allocate error(pchY)\n");
330
newpredCnt->NPRefBuf[i][j]->pdata.pchU = new PixelC[newpredCnt->NPRefBuf[i][j]->iSizeUV];
331
if (newpredCnt->NPRefBuf[i][j]->pdata.pchU == NULL) {
332
fprintf(stderr, "initNEWPREDcnt: ERROR Memory allocate error(pchU)\n");
335
newpredCnt->NPRefBuf[i][j]->pdata.pchV = new PixelC[newpredCnt->NPRefBuf[i][j]->iSizeUV];
336
if (newpredCnt->NPRefBuf[i][j]->pdata.pchV == NULL) {
337
fprintf(stderr, "initNEWPREDcnt: ERROR Memory allocate error(pchV)\n");
341
memset(newpredCnt->NPRefBuf[i][j]->pdata.pchY, 0, newpredCnt->NPRefBuf[i][j]->iSizeY);
342
memset(newpredCnt->NPRefBuf[i][j]->pdata.pchU, 0, newpredCnt->NPRefBuf[i][j]->iSizeUV);
343
memset(newpredCnt->NPRefBuf[i][j]->pdata.pchV, 0, newpredCnt->NPRefBuf[i][j]->iSizeUV);
350
void CNewPredEncoder::endNEWPREDcnt( NEWPREDcnt* newpredCnt )
355
for (i= 0; (i < m_iNumSlice) && (*(m_piSlicePoint + i) >= 0); i++) {
357
for (j= 0; j<m_iNumBuffEnc; j++) {
358
delete newpredCnt->NPRefBuf[i][j]->pdata.pchY;
359
delete newpredCnt->NPRefBuf[i][j]->pdata.pchU;
360
delete newpredCnt->NPRefBuf[i][j]->pdata.pchV;
361
delete newpredCnt->NPRefBuf[i][j];
365
delete []newpredCnt->ref;
367
if (newpredCnt->NPRefBuf != NULL) {
368
afree((int**)(newpredCnt->NPRefBuf));
376
void CNewPredEncoder::makeNextRef(
377
NEWPREDcnt* newpredCnt,
380
static int count=m_iNumSlice-1;
381
if (m_iVopID == 0 && slice_no == 0)
382
count = m_iNumSlice-1;
385
newpredCnt->ref[slice_no] = newpredCnt->ref_tbl[((count/m_iNumSlice)+1)-2][slice_no];
389
void CNewPredEncoder::makeNextBuf(
390
NEWPREDcnt* newpredCnt,
394
m_pShiftBufTmp = newpredCnt->NPRefBuf[slice_no];
395
shiftBuffer(vop_id, m_iNumBuffEnc);