168 |
} |
} |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
/* **************************************************************** |
173 |
|
NIC 28.06.2002 |
174 |
|
riscritta la 'decoder_create' per cambiarne l'interfaccia e poterla |
175 |
|
usare nella dll caricata dall'IM1 player |
176 |
|
IM1_decoder_create(XVID_DEC_PARAM * param,XVID_DEC_FRAME * frame) |
177 |
|
**************************************************************** */ |
178 |
|
//XVID_DEC_FRAME * frame |
179 |
|
|
180 |
|
int |
181 |
|
IM1_decoder_create(XVID_DEC_PARAM * param,XVID_DEC_FRAME * frame) |
182 |
|
{ |
183 |
|
DECODER *dec; |
184 |
|
Bitstream bs; |
185 |
|
uint32_t rounding; |
186 |
|
uint32_t quant; |
187 |
|
uint32_t fcode_forward; |
188 |
|
uint32_t fcode_backward; |
189 |
|
uint32_t intra_dc_threshold; |
190 |
|
|
191 |
|
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
192 |
|
if (dec == NULL) { |
193 |
|
return XVID_ERR_MEMORY; |
194 |
|
} |
195 |
|
param->handle = dec; |
196 |
|
|
197 |
|
|
198 |
|
BitstreamInit(&bs, frame->bitstream, frame->length);//NIC |
199 |
|
|
200 |
|
//NIC |
201 |
|
BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward, |
202 |
|
&fcode_backward, &intra_dc_threshold); |
203 |
|
|
204 |
|
|
205 |
|
param->width = dec->width; //NIC added |
206 |
|
param->height = dec->height; //NIC added |
207 |
|
//dec->width = param->width; //NIC commentate |
208 |
|
//dec->height = param->height; //NIC commentate |
209 |
|
|
210 |
|
dec->mb_width = (dec->width + 15) / 16; |
211 |
|
dec->mb_height = (dec->height + 15) / 16; |
212 |
|
|
213 |
|
dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE; |
214 |
|
dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE; |
215 |
|
dec->low_delay = 0; |
216 |
|
|
217 |
|
if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) { |
218 |
|
xvid_free(dec); |
219 |
|
return XVID_ERR_MEMORY; |
220 |
|
} |
221 |
|
|
222 |
|
if (image_create(&dec->refn[0], dec->edged_width, dec->edged_height)) { |
223 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
224 |
|
xvid_free(dec); |
225 |
|
return XVID_ERR_MEMORY; |
226 |
|
} |
227 |
|
// add by chenm001 <chenm001@163.com> |
228 |
|
// for support B-frame to reference last 2 frame |
229 |
|
if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) { |
230 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
231 |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
232 |
|
xvid_free(dec); |
233 |
|
return XVID_ERR_MEMORY; |
234 |
|
} |
235 |
|
if (image_create(&dec->refn[2], dec->edged_width, dec->edged_height)) { |
236 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
237 |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
238 |
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
239 |
|
xvid_free(dec); |
240 |
|
return XVID_ERR_MEMORY; |
241 |
|
} |
242 |
|
|
243 |
|
dec->mbs = |
244 |
|
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
245 |
|
CACHE_LINE); |
246 |
|
if (dec->mbs == NULL) { |
247 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
248 |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
249 |
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
250 |
|
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
251 |
|
xvid_free(dec); |
252 |
|
return XVID_ERR_MEMORY; |
253 |
|
} |
254 |
|
|
255 |
|
memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
256 |
|
|
257 |
|
// add by chenm001 <chenm001@163.com> |
258 |
|
// for skip MB flag |
259 |
|
dec->last_mbs = |
260 |
|
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
261 |
|
CACHE_LINE); |
262 |
|
if (dec->last_mbs == NULL) { |
263 |
|
xvid_free(dec->mbs); |
264 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
265 |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
266 |
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
267 |
|
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
268 |
|
xvid_free(dec); |
269 |
|
return XVID_ERR_MEMORY; |
270 |
|
} |
271 |
|
|
272 |
|
memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
273 |
|
|
274 |
|
init_timer(); |
275 |
|
|
276 |
|
// add by chenm001 <chenm001@163.com> |
277 |
|
// for support B-frame to save reference frame's time |
278 |
|
dec->frames = -1; |
279 |
|
dec->time = dec->time_base = dec->last_time_base = 0; |
280 |
|
|
281 |
|
return XVID_ERR_OK; |
282 |
|
} |
283 |
|
/* **************************************************************** |
284 |
|
END NIC |
285 |
|
**************************************************************** */ |
286 |
|
|
287 |
int |
int |
288 |
decoder_destroy(DECODER * dec) |
decoder_destroy(DECODER * dec) |
289 |
{ |
{ |
1359 |
case P_VOP: |
case P_VOP: |
1360 |
decoder_pframe(dec, &bs, rounding, quant, fcode_forward, |
decoder_pframe(dec, &bs, rounding, quant, fcode_forward, |
1361 |
intra_dc_threshold); |
intra_dc_threshold); |
1362 |
|
printf("P_VOP Time=%ld\n",dec->time); |
1363 |
DEBUG1("P_VOP Time=", dec->time); |
DEBUG1("P_VOP Time=", dec->time); |
1364 |
break; |
break; |
1365 |
|
|
1366 |
case I_VOP: |
case I_VOP: |
1367 |
decoder_iframe(dec, &bs, quant, intra_dc_threshold); |
decoder_iframe(dec, &bs, quant, intra_dc_threshold); |
1368 |
|
printf("I_VOP Time=%ld\n",dec->time); |
1369 |
DEBUG1("I_VOP Time=", dec->time); |
DEBUG1("I_VOP Time=", dec->time); |
1370 |
break; |
break; |
1371 |
|
|
1372 |
case B_VOP: |
case B_VOP: |
1373 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1374 |
if (dec->time_pp > dec->time_bp) { |
if (dec->time_pp > dec->time_bp) { |
1375 |
|
printf("I_VOP Time=%ld\n",dec->time); |
1376 |
DEBUG1("B_VOP Time=", dec->time); |
DEBUG1("B_VOP Time=", dec->time); |
1377 |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
1378 |
} else { |
} else { |
1379 |
DEBUG("broken B-frame!"); |
DEBUG("broken B-frame!"); |
1380 |
} |
} |
1381 |
#else |
#else |
1382 |
|
printf("Che minchia ne so\n"); |
1383 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1384 |
#endif |
#endif |
1385 |
break; |
break; |
1387 |
case N_VOP: // vop not coded |
case N_VOP: // vop not coded |
1388 |
// when low_delay==0, N_VOP's should interpolate between the past and future frames |
// when low_delay==0, N_VOP's should interpolate between the past and future frames |
1389 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1390 |
|
printf("N_VOP vop not coded\n"); |
1391 |
break; |
break; |
1392 |
|
|
1393 |
default: |
default: |