Lines Matching refs:video

138 Int DetermineCodingLayer(VideoEncData *video, Int *nLayer, ULong modTime);
139 void DetermineVopType(VideoEncData *video, Int currLayer);
140 Int UpdateSkipNextFrame(VideoEncData *video, ULong *modTime, Int *size, PV_STATUS status);
141 Bool SetProfile_BufferSize(VideoEncData *video, float delay, Int bInitialized);
200 VideoEncData *video;
227 video = (VideoEncData *)M4VENC_MALLOC(sizeof(VideoEncData)); /* allocate memory for encData */
229 if (video == NULL)
232 M4VENC_MEMSET(video, 0, sizeof(VideoEncData));
234 encoderControl->videoEncoderData = (void *) video; /* set up pointer in VideoEncData structure */
236 video->encParams = (VideoEncParams *)M4VENC_MALLOC(sizeof(VideoEncParams));
237 if (video->encParams == NULL)
240 M4VENC_MEMSET(video->encParams, 0, sizeof(VideoEncParams));
242 encParams = video->encParams;
452 // video->FrameRate = 30000/(float)1001; /* fix it to 29.97 fps */
454 video->FrameRate = timeIncRes / ((float)timeInc);
578 if (video->encParams->RC_Type == CBR_1 || video->encParams->RC_Type == CBR_2 || video->encParams->RC_Type == CBR_LOWDELAY) /* if CBR */
581 if (video->encParams->NoFrameSkip_Enabled == PV_ON ||
582 video->encParams->NoPreSkip_Enabled == PV_ON) /* don't allow frame skip*/
586 else if (video->encParams->RC_Type == CONSTANT_Q) /* constant_Q */
588 video->encParams->NoFrameSkip_Enabled = PV_ON; /* no frame skip */
589 video->encParams->NoPreSkip_Enabled = PV_ON; /* no frame skip */
595 if (video->encParams->NoFrameSkip_Enabled == PV_ON) /* if no frame skip */
597 video->encParams->FineFrameSkip_Enabled = PV_OFF;
607 nLayers = video->encParams->nLayers; /* Number of Layers to be encoded */
612 temp_w = video->encParams->LayerWidth[idx];
613 temp_h = video->encParams->LayerHeight[idx];
627 /* Check if the video size and framerate(MBsPerSec) are vald */
628 mbsPerSec = (Int)(nTotalMB * video->encParams->LayerFrameRate[idx]);
629 if (mbsPerSec > video->encParams->LayerMaxMbsPerSec[idx]) status = PV_FALSE;
635 if (video->encParams->RC_Type == CBR_LOWDELAY) video->encParams->VBV_delay = 0.5; /* For CBR_LOWDELAY, we set 0.5sec buffer */
636 status = SetProfile_BufferSize(video, video->encParams->VBV_delay, 1);
644 if (video == NULL) goto CLEAN_UP;
647 video->videoEncControls = encoderControl;
649 //video->currLayer = 0; /* Set current Layer to 0 */
650 //video->currFrameNo = 0; /* Set current frame Number to 0 */
651 video->nextModTime = 0;
652 video->nextEncIVop = 0; /* Sets up very first frame to be I-VOP! */
653 video->numVopsInGOP = 0; /* counter for Vops in Gop, 2/8/01 */
655 //video->frameRate = video->encParams->LayerFrameRate[0]; /* Set current layer frame rate */
657 video->QPMB = (UChar *) M4VENC_MALLOC(nTotalMB * sizeof(UChar)); /* Memory for MB quantizers */
658 if (video->QPMB == NULL) goto CLEAN_UP;
661 video->headerInfo.Mode = (UChar *) M4VENC_MALLOC(sizeof(UChar) * nTotalMB); /* Memory for MB Modes */
662 if (video->headerInfo.Mode == NULL) goto CLEAN_UP;
663 video->headerInfo.CBP = (UChar *) M4VENC_MALLOC(sizeof(UChar) * nTotalMB); /* Memory for CBP (Y and C) of each MB */
664 if (video->headerInfo.CBP == NULL) goto CLEAN_UP;
671 video->mot = (MOT **)M4VENC_MALLOC(sizeof(MOT *) * nTotalMB);
672 if (video->mot == NULL) goto CLEAN_UP;
676 video->mot[idx] = (MOT *)M4VENC_MALLOC(sizeof(MOT) * 8);
677 if (video->mot[idx] == NULL)
683 video->intraArray = (UChar *)M4VENC_MALLOC(sizeof(UChar) * nTotalMB);
684 if (video->intraArray == NULL) goto CLEAN_UP;
686 video->sliceNo = (UChar *) M4VENC_MALLOC(nTotalMB); /* Memory for Slice Numbers */
687 if (video->sliceNo == NULL) goto CLEAN_UP;
696 video->predDC = (typeDCStore *) M4VENC_MALLOC(nTotalMB * sizeof(typeDCStore));
697 if (video->predDC == NULL) goto CLEAN_UP;
699 if (!video->encParams->H263_Enabled)
704 video->predDCAC_col = (typeDCACStore *) M4VENC_MALLOC(((max_width >> 4) + 1) * sizeof(typeDCACStore));
705 if (video->predDCAC_col == NULL) goto CLEAN_UP;
709 video->predDCAC_row = video->predDCAC_col + 1; /* ACDC */
714 video->acPredFlag = (Int *) M4VENC_MALLOC(nTotalMB * sizeof(Int)); /* Memory for acPredFlag */
715 if (video->acPredFlag == NULL) goto CLEAN_UP;
718 video->outputMB = (MacroBlock *) M4VENC_MALLOC(sizeof(MacroBlock)); /* Allocating macroblock space */
719 if (video->outputMB == NULL) goto CLEAN_UP;
720 M4VENC_MEMSET(video->outputMB->block[0], 0, (sizeof(Short) << 6)*6);
722 M4VENC_MEMSET(video->dataBlock, 0, sizeof(Short) << 7);
725 video->bitstream1 = BitStreamCreateEnc(2 * 4096); /*allocate working stream 1*/
726 if (video->bitstream1 == NULL) goto CLEAN_UP;
727 video->bitstream2 = BitStreamCreateEnc(2 * 4096); /*allocate working stream 2*/
728 if (video->bitstream2 == NULL) goto CLEAN_UP;
729 video->bitstream3 = BitStreamCreateEnc(2 * 4096); /*allocate working stream 3*/
730 if (video->bitstream3 == NULL) goto CLEAN_UP;
737 video->oBSize = encParams->BufferSize[0] >> 3;
741 video->oBSize = PV_MAX((encParams->BufferSize[0] >> 3), (encParams->BufferSize[1] >> 3));
744 if (video->oBSize > DEFAULT_OVERRUN_BUFFER_SIZE || encParams->RC_Type == CONSTANT_Q) // set limit
746 video->oBSize = DEFAULT_OVERRUN_BUFFER_SIZE;
748 video->overrunBuffer = (UChar*) M4VENC_MALLOC(sizeof(UChar) * video->oBSize);
749 if (video->overrunBuffer == NULL) goto CLEAN_UP;
752 video->currVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Current VOP */
753 if (video->currVop == NULL) goto CLEAN_UP;
756 if (video->encParams->H263_Enabled) /* make it conditional 11/28/05 */
776 video->currVop->allChan = video->currVop->yChan = (PIXEL *)M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for currVop Y */
777 if (video->currVop->yChan == NULL) goto CLEAN_UP;
778 video->currVop->uChan = video->currVop->yChan + size;/* Memory for currVop U */
779 video->currVop->vChan = video->currVop->uChan + (size >> 2);/* Memory for currVop V */
784 video->currVop->yChan += offset; /* offset to the origin.*/
785 video->currVop->uChan += (offset >> 2) + 4;
786 video->currVop->vChan += (offset >> 2) + 4;
789 video->forwardRefVop = video->currVop; /* Initialize forwardRefVop */
790 video->backwardRefVop = video->currVop; /* Initialize backwardRefVop */
792 video->prevBaseVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Previous Base Vop */
793 if (video->prevBaseVop == NULL) goto CLEAN_UP;
794 video->prevBaseVop->allChan = video->prevBaseVop->yChan = (PIXEL *) M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for prevBaseVop Y */
795 if (video->prevBaseVop->yChan == NULL) goto CLEAN_UP;
796 video->prevBaseVop->uChan = video->prevBaseVop->yChan + size; /* Memory for prevBaseVop U */
797 video->prevBaseVop->vChan = video->prevBaseVop->uChan + (size >> 2); /* Memory for prevBaseVop V */
801 video->prevBaseVop->yChan += offset; /* offset to the origin.*/
802 video->prevBaseVop->uChan += (offset >> 2) + 4;
803 video->prevBaseVop->vChan += (offset >> 2) + 4;
809 video->nextBaseVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Next Base Vop */
810 if (video->nextBaseVop == NULL) goto CLEAN_UP;
811 video->nextBaseVop->allChan = video->nextBaseVop->yChan = (PIXEL *) M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for nextBaseVop Y */
812 if (video->nextBaseVop->yChan == NULL) goto CLEAN_UP;
813 video->nextBaseVop->uChan = video->nextBaseVop->yChan + size; /* Memory for nextBaseVop U */
814 video->nextBaseVop->vChan = video->nextBaseVop->uChan + (size >> 2); /* Memory for nextBaseVop V */
818 video->nextBaseVop->yChan += offset; /* offset to the origin.*/
819 video->nextBaseVop->uChan += (offset >> 2) + 4;
820 video->nextBaseVop->vChan += (offset >> 2) + 4;
826 video->prevEnhanceVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Previous Enhancement Vop */
827 if (video->prevEnhanceVop == NULL) goto CLEAN_UP;
828 video->prevEnhanceVop->allChan = video->prevEnhanceVop->yChan = (PIXEL *) M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for Previous Ehancement Y */
829 if (video->prevEnhanceVop->yChan == NULL) goto CLEAN_UP;
830 video->prevEnhanceVop->uChan = video->prevEnhanceVop->yChan + size; /* Memory for Previous Enhancement U */
831 video->prevEnhanceVop->vChan = video->prevEnhanceVop->uChan + (size >> 2); /* Memory for Previous Enhancement V */
835 video->prevEnhanceVop->yChan += offset; /* offset to the origin.*/
836 video->prevEnhanceVop->uChan += (offset >> 2) + 4;
837 video->prevEnhanceVop->vChan += (offset >> 2) + 4;
841 video->numberOfLayers = nLayers; /* Number of Layers */
842 video->sumMAD = 0;
848 video->pMP[idx] = (MultiPass *)M4VENC_MALLOC(sizeof(MultiPass));
849 if (video->pMP[idx] == NULL) goto CLEAN_UP;
850 M4VENC_MEMSET(video->pMP[idx], 0, sizeof(MultiPass));
852 video->pMP[idx]->encoded_frames = -1; /* forget about the very first I frame */
856 video->pMP[idx]->pRDSamples = (RDInfo **)M4VENC_MALLOC(30 * sizeof(RDInfo *));
857 if (video->pMP[idx]->pRDSamples == NULL) goto CLEAN_UP;
860 video->pMP[idx]->pRDSamples[i] = (RDInfo *)M4VENC_MALLOC(32 * sizeof(RDInfo));
861 if (video->pMP[idx]->pRDSamples[i] == NULL) goto CLEAN_UP;
862 for (j = 0; j < 32; j++) M4VENC_MEMSET(&(video->pMP[idx]->pRDSamples[i][j]), 0, sizeof(RDInfo));
864 video->pMP[idx]->frameRange = (Int)(video->encParams->LayerFrameRate[idx] * 1.0); /* 1.0s time frame*/
865 video->pMP[idx]->frameRange = PV_MAX(video->pMP[idx]->frameRange, 5);
866 video->pMP[idx]->frameRange = PV_MIN(video->pMP[idx]->frameRange, 30);
868 video->pMP[idx]->framePos = -1;
877 video->vol = (Vol **)M4VENC_MALLOC(nLayers * sizeof(Vol *)); /* Memory for VOL pointers */
880 if (video->vol == NULL) goto CLEAN_UP;
884 video->volInitialize[idx] = 1;
885 video->refTick[idx] = 0;
886 video->relLayerCodeTime[idx] = 1000;
887 video->vol[idx] = (Vol *)M4VENC_MALLOC(sizeof(Vol));
888 if (video->vol[idx] == NULL) goto CLEAN_UP;
890 pVol = video->vol[idx];
891 pEncParams = video->encParams;
893 M4VENC_MEMSET(video->vol[idx], 0, sizeof(Vol));
898 pVol->timeIncrementResolution = video->encParams->TimeIncrementRes;
1049 if (video->encParams->RC_Type != CONSTANT_Q)
1053 video->rc[idx] =
1056 if (video->rc[idx] == NULL) goto CLEAN_UP;
1058 M4VENC_MEMSET(video->rc[idx], 0, sizeof(rateControl));
1060 if (PV_SUCCESS != RC_Initialize(video))
1071 video->functionPointer = (FuncPtr*) M4VENC_MALLOC(sizeof(FuncPtr));
1072 if (video->functionPointer == NULL) goto CLEAN_UP;
1074 video->functionPointer->ComputeMBSum = &ComputeMBSum_C;
1075 video->functionPointer->SAD_MB_HalfPel[0] = NULL;
1076 video->functionPointer->SAD_MB_HalfPel[1] = &SAD_MB_HalfPel_Cxh;
1077 video->functionPointer->SAD_MB_HalfPel[2] = &SAD_MB_HalfPel_Cyh;
1078 video->functionPointer->SAD_MB_HalfPel[3] = &SAD_MB_HalfPel_Cxhyh;
1081 video->functionPointer->SAD_Blk_HalfPel = &SAD_Blk_HalfPel_C;
1082 video->functionPointer->SAD_Block = &SAD_Block_C;
1084 video->functionPointer->SAD_Macroblock = &SAD_Macroblock_C;
1085 video->functionPointer->ChooseMode = &ChooseMode_C;
1086 video->functionPointer->GetHalfPelMBRegion = &GetHalfPelMBRegion_C;
1087 // video->functionPointer->SAD_MB_PADDING = &SAD_MB_PADDING; /* 4/21/01 */
1114 VideoEncData *video = (VideoEncData *)encoderControl->videoEncoderData;
1125 video->encParams->rc[0]->totalFrameNumber);
1148 if (video != NULL)
1151 if (video->QPMB) M4VENC_FREE(video->QPMB);
1152 if (video->headerInfo.Mode)M4VENC_FREE(video->headerInfo.Mode);
1153 if (video->headerInfo.CBP)M4VENC_FREE(video->headerInfo.CBP);
1156 if (video->mot)
1158 nTotalMB = video->vol[0]->nTotalMB;
1159 for (idx = 1; idx < video->currLayer; idx++)
1160 if (video->vol[idx]->nTotalMB > nTotalMB)
1161 nTotalMB = video->vol[idx]->nTotalMB;
1164 if (video->mot[idx])
1165 M4VENC_FREE(video->mot[idx]);
1167 M4VENC_FREE(video->mot);
1170 if (video->intraArray) M4VENC_FREE(video->intraArray);
1172 if (video->sliceNo)M4VENC_FREE(video->sliceNo);
1173 if (video->acPredFlag)M4VENC_FREE(video->acPredFlag);
1174 // if(video->predDCAC)M4VENC_FREE(video->predDCAC);
1175 if (video->predDC) M4VENC_FREE(video->predDC);
1176 video->predDCAC_row = NULL;
1177 if (video->predDCAC_col) M4VENC_FREE(video->predDCAC_col);
1178 if (video->outputMB)M4VENC_FREE(video->outputMB);
1180 if (video->bitstream1)BitstreamCloseEnc(video->bitstream1);
1181 if (video->bitstream2)BitstreamCloseEnc(video->bitstream2);
1182 if (video->bitstream3)BitstreamCloseEnc(video->bitstream3);
1184 if (video->overrunBuffer) M4VENC_FREE(video->overrunBuffer);
1186 max_width = video->encParams->LayerWidth[0];
1188 if (video->encParams->H263_Enabled)
1197 if (video->currVop)
1199 if (video->currVop->allChan)
1201 M4VENC_FREE(video->currVop->allChan);
1203 M4VENC_FREE(video->currVop);
1206 if (video->nextBaseVop)
1208 if (video->nextBaseVop->allChan)
1210 M4VENC_FREE(video->nextBaseVop->allChan);
1212 M4VENC_FREE(video->nextBaseVop);
1215 if (video->prevBaseVop)
1217 if (video->prevBaseVop->allChan)
1219 M4VENC_FREE(video->prevBaseVop->allChan);
1221 M4VENC_FREE(video->prevBaseVop);
1223 if (video->prevEnhanceVop)
1225 if (video->prevEnhanceVop->allChan)
1227 M4VENC_FREE(video->prevEnhanceVop->allChan);
1229 M4VENC_FREE(video->prevEnhanceVop);
1233 for (idx = 0; idx < video->encParams->nLayers; idx++)
1235 if (video->pMP[idx])
1237 if (video->pMP[idx]->pRDSamples)
1241 if (video->pMP[idx]->pRDSamples[i])
1242 M4VENC_FREE(video->pMP[idx]->pRDSamples[i]);
1244 M4VENC_FREE(video->pMP[idx]->pRDSamples);
1247 M4VENC_MEMSET(video->pMP[idx], 0, sizeof(MultiPass));
1248 M4VENC_FREE(video->pMP[idx]);
1253 if (video->vol)
1255 for (idx = 0; idx < video->encParams->nLayers; idx++)
1257 if (video->vol[idx])
1259 if (video->vol[idx]->stream)
1260 M4VENC_FREE(video->vol[idx]->stream);
1261 M4VENC_FREE(video->vol[idx]);
1264 M4VENC_FREE(video->vol);
1272 if (video->encParams->RC_Type != CONSTANT_Q)
1274 RC_Cleanup(video->rc, video->encParams->nLayers);
1276 for (idx = 0; idx < video->encParams->nLayers; idx++)
1278 if (video->rc[idx])
1279 M4VENC_FREE(video->rc[idx]);
1283 if (video->functionPointer) M4VENC_FREE(video->functionPointer);
1287 if (video->encParams)
1289 M4VENC_FREE(video->encParams);
1292 M4VENC_FREE(video);
1293 encoderControl->videoEncoderData = NULL; /* video */
1356 VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
1357 Int currLayer = video->currLayer;
1358 Vol *currVol = video->vol[currLayer];
1360 if (currVol->stream->bitstreamBuffer != video->overrunBuffer) // not used
1365 return video->overrunBuffer;
1374 /* Purpose : Encode video frame and return bitstream */
1387 VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
1388 VideoEncParams *encParams = video->encParams;
1413 if (video->volInitialize[0]) /* first vol to code */
1415 video->nextModTime = video->modTimeRef = ((modTime) - ((modTime) % 1000));
1418 encodeVop = DetermineCodingLayer(video, nLayer, modTime);
1433 *nextModTime = video->nextModTime;
1436 if (video->vol[0]->shortVideoHeader) /* Short Video Header = 1 */
1444 EncodeVopNotCoded(video, bstream, size, modTime);
1445 *size = video->vol[0]->stream->byteCount;
1461 currVol = video->vol[currLayer];
1465 BitstreamSetOverrunBuffer(currVol->stream, video->overrunBuffer, video->oBSize, video);
1471 if (video->volInitialize[currLayer])
1473 video->currVop->timeInc = 0;
1474 video->prevBaseVop->timeInc = 0;
1475 if (!video->encParams->GetVolHeader[currLayer])
1491 video->input = vid_in; /* point to the frame input */
1500 DetermineVopType(video, currLayer);
1505 video->currVop->volID = currVol->volID;
1506 video->currVop->width = width_16;
1507 video->currVop->height = height_16;
1508 if (video->encParams->H263_Enabled) /* 11/28/05 */
1510 video->currVop->pitch = width_16;
1514 video->currVop->pitch = width_16 + 32;
1516 video->currVop->timeInc = currVol->timeIncrement;
1517 video->currVop->vopCoded = 1;
1518 video->currVop->roundingType = 0;
1519 video->currVop->intraDCVlcThr = encParams->IntraDCVlcThr;
1523 || random_val[rand_idx] || video->volInitialize[currLayer]
1527 tempForwRefVop = video->forwardRefVop; /* keep initial state */
1530 video->forwardRefVop = video->prevBaseVop;
1531 video->forwardRefVop->refSelectCode = 1;
1536 tempForwRefVop = video->forwardRefVop; /* keep initial state */
1539 video->forwardRefVop = video->prevEnhanceVop;
1540 video->forwardRefVop->refSelectCode = 0;
1546 video->currVop->refSelectCode = video->forwardRefVop->refSelectCode;
1547 video->currVop->gobNumber = 0;
1548 video->currVop->gobFrameID = video->currVop->predictionType;
1549 video->currVop->temporalRef = (modTime * 30 / 1001) % 256;
1551 video->currVop->temporalInterval = 0;
1553 if (video->currVop->predictionType == I_VOP)
1554 video->currVop->quantizer = encParams->InitQuantIvop[currLayer];
1556 video->currVop->quantizer = encParams->InitQuantPvop[currLayer];
1562 video->slice_coding = 0;
1564 pv_status = EncodeVop(video);
1566 if (video->currVop->predictionType == I_VOP)
1569 printf(" P-VOP (ref.%d)", video->forwardRefVop->refSelectCode);
1575 *nLayer = UpdateSkipNextFrame(video, nextModTime, size, pv_status);
1581 video->forwardRefVop = tempForwRefVop; /* For P-Vop base only */
1582 video->forwardRefVop->refSelectCode = tempRefSelCode;
1589 if ((currLayer == 0) && (encParams->IntraPeriod > 0) && (video->currVop->predictionType == I_VOP))
1590 video->nextEncIVop = encParams->IntraPeriod;
1596 video->hintTrackInfo.MTB = 1;
1598 video->hintTrackInfo.MTB = 0;
1599 video->hintTrackInfo.LayerID = (UChar)currVol->volID;
1600 video->hintTrackInfo.CodeType = (UChar)video->currVop->predictionType;
1601 video->hintTrackInfo.RefSelCode = (UChar)video->currVop->refSelectCode;
1612 vid_out->yChan = video->currVop->yChan;
1613 vid_out->uChan = video->currVop->uChan;
1614 vid_out->vChan = video->currVop->vChan;
1615 if (video->encParams->H263_Enabled)
1617 vid_out->height = video->currVop->height; /* padded height */
1618 vid_out->pitch = video->currVop->width; /* padded width */
1622 vid_out->height = video->currVop->height + 32; /* padded height */
1623 vid_out->pitch = video->currVop->width + 32; /* padded width */
1625 //video_out->timestamp = video->modTime;
1626 vid_out->timestamp = (ULong)(((video->prevFrameNum[currLayer] * 1000) / encParams->LayerFrameRate[currLayer]) + video->modTimeRef + 0.5);
1641 temp = video->prevBaseVop;
1642 video->prevBaseVop = video->currVop;
1643 video->prevBaseVop->padded = 0; /* not padded */
1644 video->currVop = temp;
1645 video->forwardRefVop = video->prevBaseVop; /* For P-Vop base only */
1646 video->forwardRefVop->refSelectCode = 1;
1650 temp = video->prevEnhanceVop;
1651 video->prevEnhanceVop = video->currVop;
1652 video->prevEnhanceVop->padded = 0; /* not padded */
1653 video->currVop = temp;
1654 video->forwardRefVop = video->prevEnhanceVop;
1655 video->forwardRefVop->refSelectCode = 0;
1661 if (video->volInitialize[currLayer])
1662 video->volInitialize[currLayer] = 0;
1671 /* Purpose : Enter a video frame and perform front-end time check plus ME */
1680 VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
1681 VideoEncParams *encParams = video->encParams;
1701 video->modTime = modTime;
1705 if (video->volInitialize[0]) /* first vol to code */
1707 video->nextModTime = video->modTimeRef = ((modTime) - ((modTime) % 1000));
1711 encodeVop = DetermineCodingLayer(video, nLayer, modTime);
1727 *nextModTime = video->nextModTime;;
1735 currVol = video->vol[currLayer];
1743 if (video->volInitialize[currLayer])
1745 video->currVop->timeInc = 0;
1746 video->prevBaseVop->timeInc = 0;
1761 video->input = vid_in; /* point to the frame input */
1770 DetermineVopType(video, currLayer);
1775 video->currVop->volID = currVol->volID;
1776 video->currVop->width = width_16;
1777 video->currVop->height = height_16;
1778 if (video->encParams->H263_Enabled) /* 11/28/05 */
1780 video->currVop->pitch = width_16;
1784 video->currVop->pitch = width_16 + 32;
1786 video->currVop->timeInc = currVol->timeIncrement;
1787 video->currVop->vopCoded = 1;
1788 video->currVop->roundingType = 0;
1789 video->currVop->intraDCVlcThr = encParams->IntraDCVlcThr;
1793 || random_val[rand_idx] || video->volInitialize[currLayer]
1797 video->tempForwRefVop = video->forwardRefVop; /* keep initial state */
1798 if (video->tempForwRefVop != NULL) video->tempRefSelCode = video->tempForwRefVop->refSelectCode;
1800 video->forwardRefVop = video->prevBaseVop;
1801 video->forwardRefVop->refSelectCode = 1;
1806 video->tempForwRefVop = video->forwardRefVop; /* keep initial state */
1807 if (video->tempForwRefVop != NULL) video->tempRefSelCode = video->tempForwRefVop->refSelectCode;
1809 video->forwardRefVop = video->prevEnhanceVop;
1810 video->forwardRefVop->refSelectCode = 0;
1816 video->currVop->refSelectCode = video->forwardRefVop->refSelectCode;
1817 video->currVop->gobNumber = 0;
1818 video->currVop->gobFrameID = video->currVop->predictionType;
1819 video->currVop->temporalRef = ((modTime) * 30 / 1001) % 256;
1821 video->currVop->temporalInterval = 0;
1823 if (video->currVop->predictionType == I_VOP)
1824 video->currVop->quantizer = encParams->InitQuantIvop[currLayer];
1826 video->currVop->quantizer = encParams->InitQuantPvop[currLayer];
1831 video->slice_coding = 1;
1834 EncodeVop(video);
1837 if (video->currVop->predictionType == I_VOP)
1840 printf(" P-VOP (ref.%d)", video->forwardRefVop->refSelectCode);
1845 video->hintTrackInfo.MTB = 1;
1847 video->hintTrackInfo.MTB = 0;
1849 video->hintTrackInfo.LayerID = (UChar)currVol->volID;
1850 video->hintTrackInfo.CodeType = (UChar)video->currVop->predictionType;
1851 video->hintTrackInfo.RefSelCode = (UChar)video->currVop->refSelectCode;
1871 VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
1872 VideoEncParams *encParams = video->encParams;
1877 Int currLayer = video->currLayer;
1884 currVol = video->vol[currLayer];
1893 if (video->volInitialize[currLayer])
1895 if (!video->encParams->GetVolHeader[currLayer])
1902 pv_status = EncodeSlice(video);
1906 if (video->mbnum >= currVol->nTotalMB && !video->end_of_buf)
1913 pre_skip = UpdateSkipNextFrame(video, nextModTime, size, pv_status); /* modified such that no pre-skipped */
1921 video->forwardRefVop = video->tempForwRefVop; /* For P-Vop base only */
1922 video->forwardRefVop->refSelectCode = video->tempRefSelCode;
1929 if ((currLayer == 0) && (encParams->IntraPeriod > 0) && (video->currVop->predictionType == I_VOP))
1930 video->nextEncIVop = encParams->IntraPeriod;
1935 vid_out->yChan = video->currVop->yChan;
1936 vid_out->uChan = video->currVop->uChan;
1937 vid_out->vChan = video->currVop->vChan;
1938 if (video->encParams->H263_Enabled)
1940 vid_out->height = video->currVop->height; /* padded height */
1941 vid_out->pitch = video->currVop->width; /* padded width */
1945 vid_out->height = video->currVop->height + 32; /* padded height */
1946 vid_out->pitch = video->currVop->width + 32; /* padded width */
1948 //vid_out->timestamp = video->modTime;
1949 vid_out->timestamp = (ULong)(((video->prevFrameNum[currLayer] * 1000) / encParams->LayerFrameRate[currLayer]) + video->modTimeRef + 0.5);
1959 temp = video->prevBaseVop;
1960 video->prevBaseVop = video->currVop;
1961 video->prevBaseVop->padded = 0; /* not padded */
1962 video->currVop = temp;
1963 video->forwardRefVop = video->prevBaseVop; /* For P-Vop base only */
1964 video->forwardRefVop->refSelectCode = 1;
1968 temp = video->prevEnhanceVop;
1969 video->prevEnhanceVop = video->currVop;
1970 video->prevEnhanceVop->padded = 0; /* not padded */
1971 video->currVop = temp;
1972 video->forwardRefVop = video->prevEnhanceVop;
1973 video->forwardRefVop->refSelectCode = 0;
1986 if (video->volInitialize[currLayer])
1987 video->volInitialize[currLayer] = 0;
2077 VideoEncData* video;
2080 video = (VideoEncData *)encCtrl->videoEncoderData;
2086 if (video->encParams->ProfileLevel[0] == profile_level_code[i])
2097 if (video->encParams->ProfileLevel[0] == scalable_profile_level_code[i])
2434 VideoEncData *video = (VideoEncData *)encoderControl->videoEncoderData;
2435 Vol *currVol = video->vol[video->currLayer];
2438 BitstreamEncVideo *stream = video->bitstream1;
2455 status = BitstreamPutBits(stream, 8, video->encParams->ProfileLevel[video->currLayer]);
2463 status = BitstreamPutBits(stream, 4, 0x01); /* visual object Type == "video ID" */
2464 status = BitstreamPut1Bits(stream, 0x00); /* no video signal type */
2484 if (video->currLayer == 0)
2599 VideoEncData *video = (VideoEncData *)encoderControl->videoEncoderData;
2600 Vol *currVol = video->vol[video->currLayer];
2620 Int DetermineCodingLayer(VideoEncData *video, Int *nLayer, ULong modTime)
2622 Vol **vol = video->vol;
2623 VideoEncParams *encParams = video->encParams;
2625 UInt modTimeRef = video->modTimeRef;
2639 if (modTime - video->nextModTime > ((ULong)(-1)) >> 1) /* next time wrapped around */
2642 video->relLayerCodeTime[i] -= 1000;
2643 video->nextEncIVop--; /* number of Vops in highest layer resolution. */
2644 video->numVopsInGOP++;
2649 if (video->volInitialize[i])
2651 video->prevFrameNum[i] = frameNum[i] - 1;
2653 else if (frameNum[i] <= video->prevFrameNum[i])
2662 srcFrameInterval = 1000 / video->FrameRate;
2664 video->nextModTime = nextFrmModTime - (ULong)(srcFrameInterval / 2.) - 1; /* between current and next frame */
2669 if (video->nextModTime - modTime < (ULong)delta) /* need to move nextModTime further. */
2671 video->nextModTime += ((delta - video->nextModTime + modTime)); /* empirical formula */
2685 vol[i]->timeIncrement = frameTick - video->refTick[i];
2696 if (video->relLayerCodeTime[i] <= 0) /* no skipping */
2699 video->currLayer = *nLayer = i;
2700 video->relLayerCodeTime[i] += 1000;
2704 frameInc = (frameNum[i] - video->prevFrameNum[i]);
2709 video->nextEncIVop -= extra_skip;
2710 video->numVopsInGOP += extra_skip;
2713 RC_UpdateBuffer(video, i, extra_skip);
2719 video->prevFrameNum[i] = frameNum[i];
2725 video->relLayerCodeTime[i] -= 1000;
2728 vol[i]->timeIncrement = frameTick - video->refTick[i];
2730 if (video->relLayerCodeTime[i] <= 0) /* time to encode base */
2734 video->currLayer = *nLayer = i;
2735 video->relLayerCodeTime[i] +=
2748 if (video->volInitialize[i])
2749 video->prevFrameNum[i] = frameNum[i] - 1;
2752 frameInc = (frameNum[i] - video->prevFrameNum[i]);
2759 RC_UpdateBuffer(video, i, extra_skip);
2763 video->prevFrameNum[i] = frameNum[i];
2785 void DetermineVopType(VideoEncData *video, Int currLayer)
2787 VideoEncParams *encParams = video->encParams;
2788 // Vol *currVol = video->vol[currLayer];
2792 if (video->currLayer > 0)
2793 video->currVop->predictionType = P_VOP;
2796 video->currVop->predictionType = I_VOP;
2797 if (video->numVopsInGOP >= 132)
2798 video->numVopsInGOP = 0;
2805 if (encParams->RC_Type == CONSTANT_Q || video->rc[currLayer]->skip_next_frame != -1)
2806 video->currVop->predictionType = P_VOP;
2808 if (video->currLayer == 0)
2810 if (/*video->numVopsInGOP>=132 || */video->volInitialize[currLayer])
2812 video->currVop->predictionType = I_VOP;
2813 video->numVopsInGOP = 0; /* force INTRA update every 132 base frames*/
2814 video->nextEncIVop = 1;
2816 else if (video->nextEncIVop == 0 || video->currVop->predictionType == I_VOP)
2818 video->numVopsInGOP = 0;
2819 video->nextEncIVop = 1;
2827 if (encParams->RC_Type == CONSTANT_Q || video->rc[currLayer]->skip_next_frame != -1)
2828 video->currVop->predictionType = P_VOP;
2832 if (video->nextEncIVop <= 0 || video->currVop->predictionType == I_VOP)
2834 video->nextEncIVop = encParams->IntraPeriod;
2835 video->currVop->predictionType = I_VOP;
2836 video->numVopsInGOP = 0;
2855 Int UpdateSkipNextFrame(VideoEncData *video, ULong *modTime, Int *size, PV_STATUS status)
2857 Int currLayer = video->currLayer;
2859 VideoEncParams *encParams = video->encParams;
2861 Vol *currVol = video->vol[currLayer];
2862 Vol **vol = video->vol;
2870 if (video->volInitialize[0] && currLayer == 0) /* always encode the first frame */
2872 RC_ResetSkipNextFrame(video, currLayer);
2877 if (RC_GetSkipNextFrame(video, currLayer) < 0 || status == PV_END_OF_BUF) /* Skip Current Frame */
2892 *modTime = video->nextModTime;
2897 /*if((encParams->IntraPeriod>0) && (video->currVop->predictionType == I_VOP))
2898 video->nextEncIVop = 0; commented out by 06/05/01 */
2901 else if ((num_skip = RC_GetSkipNextFrame(video, currLayer)) > 0)
2912 if (video->relLayerCodeTime[i] <= 1000)
2921 video->relLayerCodeTime[i] += (num_skip + extra_skip) *
2929 video->refTick[currLayer] += vol[currLayer]->prevModuloTimeBase * vol[currLayer]->timeIncrementResolution;
2935 if (((encParams->IntraPeriod != 0) /*&& (video->currVop->predictionType==I_VOP)*/) ||
2936 ((encParams->IntraPeriod == 0) && (video->numVopsInGOP == 0)))
2938 newRefTick = video->refTick[0];
2942 if (video->refTick[i] < newRefTick)
2943 newRefTick = video->refTick[i];
2959 video->modTimeRef += deltaModTime;
2962 video->prevFrameNum[i] -= (UInt)(deltaModTime * encParams->LayerFrameRate[i]) / 1000;
2963 video->refTick[i] -= newRefTick;
2969 *modTime = video->nextModTime;
2980 /* Purpose : Set profile and video buffer size, copied from Jim's code */
2982 /* to reset profile and video buffer size */
2989 Bool SetProfile_BufferSize(VideoEncData *video, float delay, Int bInitialized)
2996 Int nLayers = video->encParams->nLayers; /* Number of Layers to be encoded */
3015 index = video->encParams->profile_table_index;
3021 temp_w = video->encParams->LayerWidth[idx];
3022 temp_h = video->encParams->LayerHeight[idx];
3032 upper_bound_ratio = (video->encParams->RC_Type == CBR_LOWDELAY ? (float)5.0 : (float)UPPER_BOUND_RATIO);
3036 base_bitrate = video->encParams->LayerBitRate[0];
3037 if (video->encParams->LayerMaxBitRate[0] != 0) /* video->encParams->LayerMaxBitRate[0] == 0 means it has not been set */
3039 base_bitrate = PV_MAX(base_bitrate, video->encParams->LayerMaxBitRate[0]);
3043 video->encParams->LayerMaxBitRate[0] = profile_level_max_bitrate[index];
3046 base_framerate = video->encParams->LayerFrameRate[0];
3047 if (video->encParams->LayerMaxFrameRate[0] != 0)
3049 base_framerate = PV_MAX(base_framerate, video->encParams->LayerMaxFrameRate[0]);
3053 video->encParams->LayerMaxFrameRate[0] = (float)profile_level_max_mbsPerSec[index] / nTotalMB;
3056 base_packet_size = video->encParams->ResyncPacketsize;
3074 total_bitrate = video->encParams->LayerBitRate[1];
3075 if (video->encParams->LayerMaxBitRate[1] != 0)
3077 total_bitrate = PV_MIN(total_bitrate, video->encParams->LayerMaxBitRate[1]);
3081 video->encParams->LayerMaxBitRate[1] = scalable_profile_level_max_bitrate[index];
3084 total_framerate = video->encParams->LayerFrameRate[1];
3085 if (video->encParams->LayerMaxFrameRate[1] != 0)
3087 total_framerate = PV_MIN(total_framerate, video->encParams->LayerMaxFrameRate[1]);
3091 video->encParams->LayerMaxFrameRate[1] = (float)scalable_profile_level_max_mbsPerSec[index] / nTotalMB;
3094 total_packet_size = video->encParams->ResyncPacketsize;
3118 video->encParams->BufferSize[0] = base_VBV_size;
3120 video->encParams->BufferSize[1] = enhance_VBV_size;
3138 width16 = ((video->encParams->LayerWidth[0] + 15) >> 4) << 4;
3139 height16 = ((video->encParams->LayerHeight[0] + 15) >> 4) << 4;
3140 if (video->encParams->H263_Enabled)
3152 video->encParams->maxFrameSize = k * 16384;
3163 if (!video->encParams->H263_Enabled &&
3164 (video->encParams->IntraDCVlcThr != 0 || video->encParams->SearchRange > 16))
3179 base_VBV_size <= (video->encParams->H263_Enabled ? (Int)(k*16384 + 4*(float)profile_level_max_bitrate[i]*1001.0 / 30000.0) :
3193 video->encParams->ProfileLevel[0] = profile_level_code[i];
3194 video->encParams->BufferSize[0] = base_VBV_size;
3196 if (video->encParams->LayerMaxBitRate[0] == 0)
3197 video->encParams->LayerMaxBitRate[0] = profile_level_max_bitrate[i];
3199 if (video->encParams->LayerMaxFrameRate[0] == 0)
3200 video->encParams->LayerMaxFrameRate[0] = PV_MIN(30, (float)profile_level_max_mbsPerSec[i] / nTotalMB);
3203 if (video->encParams->H263_Enabled)
3204 video->encParams->BufferSize[0] = (Int)(k * 16384 + 4 * (float)profile_level_max_bitrate[i] * 1001.0 / 30000.0);
3273 video->encParams->ProfileLevel[0] = profile_level_code[j];
3274 video->encParams->ProfileLevel[1] = scalable_profile_level_code[i];
3275 video->encParams->BufferSize[0] = base_VBV_size;
3276 video->encParams->BufferSize[1] = enhance_VBV_size;
3278 if (video->encParams->LayerMaxBitRate[0] == 0)
3279 video->encParams->LayerMaxBitRate[0] = profile_level_max_bitrate[j];
3281 if (video->encParams->LayerMaxBitRate[1] == 0)
3282 video->encParams->LayerMaxBitRate[1] = scalable_profile_level_max_bitrate[i];
3284 if (video->encParams->LayerMaxFrameRate[0] == 0)
3285 video->encParams->LayerMaxFrameRate[0] = PV_MIN(30, (float)profile_level_max_mbsPerSec[j] / nTotalMB);
3287 if (video->encParams->LayerMaxFrameRate[1] == 0)
3288 video->encParams->LayerMaxFrameRate[1] = PV_MIN(30, (float)scalable_profile_level_max_mbsPerSec[i] / nTotalMB);
3294 if (!video->encParams->H263_Enabled && (video->encParams->ProfileLevel[0] == 0x08)) /* SPL0 restriction*/
3297 if(video->encParams->ACDCPrediction == TRUE && MB-based rate control)