250
252
_videos[ref]._aviheader->getFlags (rewind, &flags);
254
// Optimize for resample FPS*************************
255
// If we are in the same segment, look if it is better to decode
256
// From where we are or to seek the previous intra
257
if ((seg == _lastseg))
259
if(rewind<_lastframe && relframe>_lastframe) // we have a better position to go from
261
for (uint32_t i = _lastframe+1; i <relframe; i++)
264
_videos[ref]._aviheader->getFlags (i, &flags);
265
// Skip B frames, there can be a lot of them
266
if((flags&AVI_B_FRAME)) continue;
268
if(!decodeCache(i,ref, result))
270
printf("Editor: Cannot read ip frame %lu\n",relframe);
273
result=cache->getFreeImage();
278
// Optimize for resample FPS*************************
253
281
// IP seen is the last P (or I) before the frame we seek
254
for (uint32_t i = rewind; i <relframe; i++)
284
for (uint32_t i = rewind; i <relframe; i++)
257
_videos[ref]._aviheader->getFlags (i, &flags);
258
// Skip B frames, there can be a lot of them
259
if((flags&AVI_B_FRAME)) continue;
287
_videos[ref]._aviheader->getFlags (i, &flags);
288
// Skip B frames, there can be a lot of them
289
if((flags&AVI_B_FRAME)) continue;
261
if(!decodeCache(i,ref, result))
263
printf("Editor: Cannot read ip frame %lu\n",relframe);
266
result=cache->getFreeImage();
291
if(!decodeCache(i,ref, result))
293
printf("Editor: Cannot read ip frame %lu\n",relframe);
296
result=cache->getFreeImage();
269
299
// Time to decode our frame
270
300
// if it is not a B, just decode it
271
301
// it it is a B, the usual stuff
343
377
printf ("\nEditor: last decoding failed.%ld)\n", frame );
346
ADM_assert(_imageBuffer);
380
ADM_assert(_imageBuffer);
382
// if len is 0 then take the previous image
385
refOnly=_videos[seg].decoder->dontcopy(); // can we skip one memcpy ?
387
if(!len & refOnly & !frame) // Size is null = no image and we only got a pointer
388
// copy the previous one
392
uint32_t page=_imageBuffer->_width*_imageBuffer->_height;
393
memset(YPLANE(image),0,page);
394
memset(UPLANE(image),128,page>>2);
395
memset(VPLANE(image),128,page>>2);
397
image->flags=AVI_KEY_FRAME;
399
image->flags=AVI_P_FRAME;
406
{ // This is only an empty Shell
407
tmpImage=new ADMImage(_imageBuffer->_width,_imageBuffer->_height,1);
408
ww=_imageBuffer->_width & 0xfffff0;
409
left=_imageBuffer->_width & 0xf;
414
tmpImage=_imageBuffer;
415
ww=_imageBuffer->_width;
347
419
// Do pp, and use imageBuffer as intermediate buffer
348
if (!_videos[seg].decoder->uncompress (compBuffer, _imageBuffer, len, &flags))
420
if (!_videos[seg].decoder->uncompress (compBuffer, tmpImage, len, &flags))
350
422
printf ("\nEditor: Last Decoding2 failed for frame %lu\n",frame);
354
if(!_imageBuffer->quant || !_imageBuffer->_qStride)
357
image->duplicate(_imageBuffer);
426
if(!tmpImage->quant || !tmpImage->_qStride)
429
image->duplicate(tmpImage);
358
430
cache->updateFrameNum(image,frame);
431
if(refOnly) delete tmpImage;
359
432
aprintf("EdCache: No quant avail\n");
363
436
// 1 compute average quant
366
for(uint32_t z=0;z<_imageBuffer->_qSize;z++)
440
image->copyInfo(tmpImage);
441
//image->copyQuantInfo(tmpImage);
443
// Do postprocessing if any
444
for(uint32_t z=0;z<tmpImage->_qSize;z++)
368
qz=(int)_imageBuffer->quant[z];
446
qz=(int)tmpImage->quant[z];
371
sumit+=(_imageBuffer->_qSize-1);
449
sumit+=(tmpImage->_qSize-1);
373
451
sum=(float)sumit;
374
sum/=_imageBuffer->_qSize;
452
sum/=tmpImage->_qSize;
375
453
if(sum>31) sum=31;
378
_imageBuffer->_Qp=(uint32_t)floor(sum);
457
tmpImage->_Qp=image->_Qp=(uint32_t)floor(sum);
380
459
// Pp deactivated ?
381
460
if(!_pp.postProcType || !_pp.postProcStrength)
383
image->duplicate(_imageBuffer);
463
image->duplicate(tmpImage);
384
464
cache->updateFrameNum(image,frame);
465
if(refOnly) delete tmpImage;
385
466
aprintf("EdCache: Postproc disabled\n");
390
471
#warning FIXME should be FF_I_TYPE/B/P
391
if(_imageBuffer->flags & AVI_KEY_FRAME) type=1;
392
else if(_imageBuffer->flags & AVI_B_FRAME) type=3;
472
if(tmpImage->flags & AVI_KEY_FRAME) type=1;
473
else if(tmpImage->flags & AVI_B_FRAME) type=3;
395
476
// we do postproc !
402
483
getVideoInfo(&_info);
403
iBuff[0]= YPLANE((_imageBuffer));
406
iBuff[1]= UPLANE((_imageBuffer));
407
iBuff[2]= VPLANE((_imageBuffer));
411
iBuff[2]= UPLANE((_imageBuffer));
412
iBuff[1]= VPLANE((_imageBuffer));
414
oBuff[0]= YPLANE(image);
415
oBuff[1]= UPLANE(image);
416
oBuff[2]= VPLANE(image);
418
strideTab[0]=strideTab2[0]=_info.width;
419
strideTab[1]=strideTab2[1]=_info.width>>1;
420
strideTab[2]=strideTab2[2]=_info.width>>1;
486
iBuff[0]= tmpImage->_planes[0];
487
iBuff[1]= tmpImage->_planes[1];
488
iBuff[2]= tmpImage->_planes[2];
490
strideTab2[0]=_info.width;
491
strideTab2[1]=_info.width>>1;
492
strideTab2[2]=_info.width>>1;
494
strideTab[0]=tmpImage->_planeStride[0];
495
strideTab[1]=tmpImage->_planeStride[1];
496
strideTab[2]=tmpImage->_planeStride[2];
501
iBuff[0]= YPLANE((tmpImage));
502
iBuff[1]= UPLANE((tmpImage));
503
iBuff[2]= VPLANE((tmpImage));
507
strideTab[0]=strideTab2[0]=_info.width;
508
strideTab[1]=strideTab2[1]=_info.width>>1;
509
strideTab[2]=strideTab2[2]=_info.width>>1;
511
oBuff[0]= YPLANE(image);
512
oBuff[1]= UPLANE(image);
513
oBuff[2]= VPLANE(image);
429
(int8_t *)(_imageBuffer->quant),
430
_imageBuffer->_qStride,
522
(int8_t *)(tmpImage->quant),
433
526
type); // img type
435
image->copyInfo(_imageBuffer);
528
If there is a chroma block that needs padding
529
(width not multiple of 16) while postprocessing,
530
we process up to the nearest 16 multiple and
531
just copy luma & chroma info that was left over
536
uint32_t stridein,strideout,right;
537
right=_info.width-left;
539
dst=YPLANE(image)+right;
540
src=tmpImage->_planes[0]+right;
541
stridein=tmpImage->_planeStride[0];
542
strideout=_info.width;
543
for(uint32_t y=_info.height;y>0;y--)
545
memcpy(dst,src,left);
553
dst=UPLANE(image)+right;
554
src=tmpImage->_planes[1]+right;
555
stridein=tmpImage->_planeStride[1];
556
strideout=_info.width>>1;
557
for(uint32_t y=_info.height>>1;y>0;y--)
559
memcpy(dst,src,left);
564
dst=VPLANE(image)+right;
565
src=tmpImage->_planes[2]+right;
566
stridein=tmpImage->_planeStride[2];
567
strideout=_info.width>>1;
568
for(uint32_t y=_info.height>>1;y>0;y--)
570
memcpy(dst,src,left);
579
if(refOnly) delete tmpImage;
436
580
cache->updateFrameNum(image,frame);
437
581
aprintf("EdCache: Postproc done\n");