Home | History | Annotate | Download | only in src

Lines Matching refs:video

131 Int DetermineCodingLayer(VideoEncData *video, Int *nLayer, ULong modTime);
132 void DetermineVopType(VideoEncData *video, Int currLayer);
133 Int UpdateSkipNextFrame(VideoEncData *video, ULong *modTime, Int *size, PV_STATUS status);
134 Bool SetProfile_BufferSize(VideoEncData *video, float delay, Int bInitialized);
193 VideoEncData *video;
220 video = (VideoEncData *)M4VENC_MALLOC(sizeof(VideoEncData)); /* allocate memory for encData */
222 if (video == NULL)
225 M4VENC_MEMSET(video, 0, sizeof(VideoEncData));
227 encoderControl->videoEncoderData = (void *) video; /* set up pointer in VideoEncData structure */
229 video->encParams = (VideoEncParams *)M4VENC_MALLOC(sizeof(VideoEncParams));
230 if (video->encParams == NULL)
233 M4VENC_MEMSET(video->encParams, 0, sizeof(VideoEncParams));
235 encParams = video->encParams;
445 // video->FrameRate = 30000/(float)1001; /* fix it to 29.97 fps */
447 video->FrameRate = timeIncRes / ((float)timeInc);
571 if (video->encParams->RC_Type == CBR_1 || video->encParams->RC_Type == CBR_2 || video->encParams->RC_Type == CBR_LOWDELAY) /* if CBR */
574 if (video->encParams->NoFrameSkip_Enabled == PV_ON ||
575 video->encParams->NoPreSkip_Enabled == PV_ON) /* don't allow frame skip*/
579 else if (video->encParams->RC_Type == CONSTANT_Q) /* constant_Q */
581 video->encParams->NoFrameSkip_Enabled = PV_ON; /* no frame skip */
582 video->encParams->NoPreSkip_Enabled = PV_ON; /* no frame skip */
588 if (video->encParams->NoFrameSkip_Enabled == PV_ON) /* if no frame skip */
590 video->encParams->FineFrameSkip_Enabled = PV_OFF;
600 nLayers = video->encParams->nLayers; /* Number of Layers to be encoded */
605 temp_w = video->encParams->LayerWidth[idx];
606 temp_h = video->encParams->LayerHeight[idx];
616 /* Check if the video size and framerate(MBsPerSec) are vald */
617 mbsPerSec = (Int)(nTotalMB * video->encParams->LayerFrameRate[idx]);
618 if (mbsPerSec > video->encParams->LayerMaxMbsPerSec[idx]) status = PV_FALSE;
622 /* Set Profile and Video Buffer Size for each layer */
624 if (video->encParams->RC_Type == CBR_LOWDELAY) video->encParams->VBV_delay = 0.5; /* For CBR_LOWDELAY, we set 0.5sec buffer */
625 status = SetProfile_BufferSize(video, video->encParams->VBV_delay, 1);
633 if (video == NULL) goto CLEAN_UP;
636 video->videoEncControls = encoderControl;
638 //video->currLayer = 0; /* Set current Layer to 0 */
639 //video->currFrameNo = 0; /* Set current frame Number to 0 */
640 video->nextModTime = 0;
641 video->nextEncIVop = 0; /* Sets up very first frame to be I-VOP! */
642 video->numVopsInGOP = 0; /* counter for Vops in Gop, 2/8/01 */
644 //video->frameRate = video->encParams->LayerFrameRate[0]; /* Set current layer frame rate */
646 video->QPMB = (UChar *) M4VENC_MALLOC(nTotalMB * sizeof(UChar)); /* Memory for MB quantizers */
647 if (video->QPMB == NULL) goto CLEAN_UP;
650 video->headerInfo.Mode = (UChar *) M4VENC_MALLOC(sizeof(UChar) * nTotalMB); /* Memory for MB Modes */
651 if (video->headerInfo.Mode == NULL) goto CLEAN_UP;
652 video->headerInfo.CBP = (UChar *) M4VENC_MALLOC(sizeof(UChar) * nTotalMB); /* Memory for CBP (Y and C) of each MB */
653 if (video->headerInfo.CBP == NULL) goto CLEAN_UP;
657 video->mot = (MOT **)M4VENC_MALLOC(sizeof(MOT *) * nTotalMB);
658 if (video->mot == NULL) goto CLEAN_UP;
662 video->mot[idx] = (MOT *)M4VENC_MALLOC(sizeof(MOT) * 8);
663 if (video->mot[idx] == NULL)
669 video->intraArray = (UChar *)M4VENC_MALLOC(sizeof(UChar) * nTotalMB);
670 if (video->intraArray == NULL) goto CLEAN_UP;
672 video->sliceNo = (UChar *) M4VENC_MALLOC(nTotalMB); /* Memory for Slice Numbers */
673 if (video->sliceNo == NULL) goto CLEAN_UP;
679 video->predDC = (typeDCStore *) M4VENC_MALLOC(nTotalMB * sizeof(typeDCStore));
680 if (video->predDC == NULL) goto CLEAN_UP;
682 if (!video->encParams->H263_Enabled)
684 video->predDCAC_col = (typeDCACStore *) M4VENC_MALLOC(((max_width >> 4) + 1) * sizeof(typeDCACStore));
685 if (video->predDCAC_col == NULL) goto CLEAN_UP;
689 video->predDCAC_row = video->predDCAC_col + 1; /* ACDC */
691 video->acPredFlag = (Int *) M4VENC_MALLOC(nTotalMB * sizeof(Int)); /* Memory for acPredFlag */
692 if (video->acPredFlag == NULL) goto CLEAN_UP;
695 video->outputMB = (MacroBlock *) M4VENC_MALLOC(sizeof(MacroBlock)); /* Allocating macroblock space */
696 if (video->outputMB == NULL) goto CLEAN_UP;
697 M4VENC_MEMSET(video->outputMB->block[0], 0, (sizeof(Short) << 6)*6);
699 M4VENC_MEMSET(video->dataBlock, 0, sizeof(Short) << 7);
702 video->bitstream1 = BitStreamCreateEnc(2 * 4096); /*allocate working stream 1*/
703 if (video->bitstream1 == NULL) goto CLEAN_UP;
704 video->bitstream2 = BitStreamCreateEnc(2 * 4096); /*allocate working stream 2*/
705 if (video->bitstream2 == NULL) goto CLEAN_UP;
706 video->bitstream3 = BitStreamCreateEnc(2 * 4096); /*allocate working stream 3*/
707 if (video->bitstream3 == NULL) goto CLEAN_UP;
714 video->oBSize = encParams->BufferSize[0] >> 3;
718 video->oBSize = PV_MAX((encParams->BufferSize[0] >> 3), (encParams->BufferSize[1] >> 3));
721 if (video->oBSize > DEFAULT_OVERRUN_BUFFER_SIZE || encParams->RC_Type == CONSTANT_Q) // set limit
723 video->oBSize = DEFAULT_OVERRUN_BUFFER_SIZE;
725 video->overrunBuffer = (UChar*) M4VENC_MALLOC(sizeof(UChar) * video->oBSize);
726 if (video->overrunBuffer == NULL) goto CLEAN_UP;
729 video->currVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Current VOP */
730 if (video->currVop == NULL) goto CLEAN_UP;
733 if (video->encParams->H263_Enabled) /* make it conditional 11/28/05 */
746 video->currVop->yChan = (PIXEL *)M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for currVop Y */
747 if (video->currVop->yChan == NULL) goto CLEAN_UP;
748 video->currVop->uChan = video->currVop->yChan + size;/* Memory for currVop U */
749 video->currVop->vChan = video->currVop->uChan + (size >> 2);/* Memory for currVop V */
754 video->currVop->yChan += offset; /* offset to the origin.*/
755 video->currVop->uChan += (offset >> 2) + 4;
756 video->currVop->vChan += (offset >> 2) + 4;
759 video->forwardRefVop = video->currVop; /* Initialize forwardRefVop */
760 video->backwardRefVop = video->currVop; /* Initialize backwardRefVop */
762 video->prevBaseVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Previous Base Vop */
763 if (video->prevBaseVop == NULL) goto CLEAN_UP;
764 video->prevBaseVop->yChan = (PIXEL *) M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for prevBaseVop Y */
765 if (video->prevBaseVop->yChan == NULL) goto CLEAN_UP;
766 video->prevBaseVop->uChan = video->prevBaseVop->yChan + size; /* Memory for prevBaseVop U */
767 video->prevBaseVop->vChan = video->prevBaseVop->uChan + (size >> 2); /* Memory for prevBaseVop V */
771 video->prevBaseVop->yChan += offset; /* offset to the origin.*/
772 video->prevBaseVop->uChan += (offset >> 2) + 4;
773 video->prevBaseVop->vChan += (offset >> 2) + 4;
779 video->nextBaseVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Next Base Vop */
780 if (video->nextBaseVop == NULL) goto CLEAN_UP;
781 video->nextBaseVop->yChan = (PIXEL *) M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for nextBaseVop Y */
782 if (video->nextBaseVop->yChan == NULL) goto CLEAN_UP;
783 video->nextBaseVop->uChan = video->nextBaseVop->yChan + size; /* Memory for nextBaseVop U */
784 video->nextBaseVop->vChan = video->nextBaseVop->uChan + (size >> 2); /* Memory for nextBaseVop V */
788 video->nextBaseVop->yChan += offset; /* offset to the origin.*/
789 video->nextBaseVop->uChan += (offset >> 2) + 4;
790 video->nextBaseVop->vChan += (offset >> 2) + 4;
796 video->prevEnhanceVop = (Vop *) M4VENC_MALLOC(sizeof(Vop)); /* Memory for Previous Enhancement Vop */
797 if (video->prevEnhanceVop == NULL) goto CLEAN_UP;
798 video->prevEnhanceVop->yChan = (PIXEL *) M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for Previous Ehancement Y */
799 if (video->prevEnhanceVop->yChan == NULL) goto CLEAN_UP;
800 video->prevEnhanceVop->uChan = video->prevEnhanceVop->yChan + size; /* Memory for Previous Enhancement U */
801 video->prevEnhanceVop->vChan = video->prevEnhanceVop->uChan + (size >> 2); /* Memory for Previous Enhancement V */
805 video->prevEnhanceVop->yChan += offset; /* offset to the origin.*/
806 video->prevEnhanceVop->uChan += (offset >> 2) + 4;
807 video->prevEnhanceVop->vChan += (offset >> 2) + 4;
811 video->numberOfLayers = nLayers; /* Number of Layers */
812 video->sumMAD = 0;
818 video->pMP[idx] = (MultiPass *)M4VENC_MALLOC(sizeof(MultiPass));
819 if (video->pMP[idx] == NULL) goto CLEAN_UP;
820 M4VENC_MEMSET(video->pMP[idx], 0, sizeof(MultiPass));
822 video->pMP[idx]->encoded_frames = -1; /* forget about the very first I frame */
826 video->pMP[idx]->pRDSamples = (RDInfo **)M4VENC_MALLOC(30 * sizeof(RDInfo *));
827 if (video->pMP[idx]->pRDSamples == NULL) goto CLEAN_UP;
830 video->pMP[idx]->pRDSamples[i] = (RDInfo *)M4VENC_MALLOC(32 * sizeof(RDInfo));
831 if (video->pMP[idx]->pRDSamples[i] == NULL) goto CLEAN_UP;
832 for (j = 0; j < 32; j++) M4VENC_MEMSET(&(video->pMP[idx]->pRDSamples[i][j]), 0, sizeof(RDInfo));
834 video->pMP[idx]->frameRange = (Int)(video->encParams->LayerFrameRate[idx] * 1.0); /* 1.0s time frame*/
835 video->pMP[idx]->frameRange = PV_MAX(video->pMP[idx]->frameRange, 5);
836 video->pMP[idx]->frameRange = PV_MIN(video->pMP[idx]->frameRange, 30);
838 video->pMP[idx]->framePos = -1;
844 video->vol = (Vol **)M4VENC_MALLOC(nLayers * sizeof(Vol *)); /* Memory for VOL pointers */
847 if (video->vol == NULL) goto CLEAN_UP;
851 video->volInitialize[idx] = 1;
852 video->refTick[idx] = 0;
853 video->relLayerCodeTime[idx] = 1000;
854 video->vol[idx] = (Vol *)M4VENC_MALLOC(sizeof(Vol));
855 if (video->vol[idx] == NULL) goto CLEAN_UP;
857 pVol = video->vol[idx];
858 pEncParams = video->encParams;
860 M4VENC_MEMSET(video->vol[idx], 0, sizeof(Vol));
865 pVol->timeIncrementResolution = video->encParams->TimeIncrementRes;
1016 if (video->encParams->RC_Type != CONSTANT_Q)
1020 video->rc[idx] =
1023 if (video->rc[idx] == NULL) goto CLEAN_UP;
1025 M4VENC_MEMSET(video->rc[idx], 0, sizeof(rateControl));
1027 if (PV_SUCCESS != RC_Initialize(video))
1038 video->functionPointer = (FuncPtr*) M4VENC_MALLOC(sizeof(FuncPtr));
1039 if (video->functionPointer == NULL) goto CLEAN_UP;
1041 video->functionPointer->ComputeMBSum = &ComputeMBSum_C;
1042 video->functionPointer->SAD_MB_HalfPel[0] = NULL;
1043 video->functionPointer->SAD_MB_HalfPel[1] = &SAD_MB_HalfPel_Cxh;
1044 video->functionPointer->SAD_MB_HalfPel[2] = &SAD_MB_HalfPel_Cyh;
1045 video->functionPointer->SAD_MB_HalfPel[3] = &SAD_MB_HalfPel_Cxhyh;
1048 video->functionPointer->SAD_Blk_HalfPel = &SAD_Blk_HalfPel_C;
1049 video->functionPointer->SAD_Block = &SAD_Block_C;
1051 video->functionPointer->SAD_Macroblock = &SAD_Macroblock_C;
1052 video->functionPointer->ChooseMode = &ChooseMode_C;
1053 video->functionPointer->GetHalfPelMBRegion = &GetHalfPelMBRegion_C;
1054 // video->functionPointer->SAD_MB_PADDING = &SAD_MB_PADDING; /* 4/21/01 */
1081 VideoEncData *video = (VideoEncData *)encoderControl->videoEncoderData;
1092 video->encParams->rc[0]->totalFrameNumber);
1115 if (video != NULL)
1118 if (video->QPMB) M4VENC_FREE(video->QPMB);
1119 if (video->headerInfo.Mode)M4VENC_FREE(video->headerInfo.Mode);
1120 if (video->headerInfo.CBP)M4VENC_FREE(video->headerInfo.CBP);
1123 if (video->mot)
1125 nTotalMB = video->vol[0]->nTotalMB;
1126 for (idx = 1; idx < video->currLayer; idx++)
1127 if (video->vol[idx]->nTotalMB > nTotalMB)
1128 nTotalMB = video->vol[idx]->nTotalMB;
1131 if (video->mot[idx])
1132 M4VENC_FREE(video->mot[idx]);
1134 M4VENC_FREE(video->mot);
1137 if (video->intraArray) M4VENC_FREE(video->intraArray);
1139 if (video->sliceNo)M4VENC_FREE(video->sliceNo);
1140 if (video->acPredFlag)M4VENC_FREE(video->acPredFlag);
1141 // if(video->predDCAC)M4VENC_FREE(video->predDCAC);
1142 if (video->predDC) M4VENC_FREE(video->predDC);
1143 video->predDCAC_row = NULL;
1144 if (video->predDCAC_col) M4VENC_FREE(video->predDCAC_col);
1145 if (video->outputMB)M4VENC_FREE(video->outputMB);
1147 if (video->bitstream1)BitstreamCloseEnc(video->bitstream1);
1148 if (video->bitstream2)BitstreamCloseEnc(video->bitstream2);
1149 if (video->bitstream3)BitstreamCloseEnc(video->bitstream3);
1151 if (video->overrunBuffer) M4VENC_FREE(video->overrunBuffer);
1153 max_width = video->encParams->LayerWidth[0];
1155 if (video->encParams->H263_Enabled)
1164 if (video->currVop)
1166 if (video->currVop->yChan)
1168 video->currVop->yChan -= offset;
1169 M4VENC_FREE(video->currVop->yChan);
1171 M4VENC_FREE(video->currVop);
1174 if (video->nextBaseVop)
1176 if (video->nextBaseVop->yChan)
1178 video->nextBaseVop->yChan -= offset;
1179 M4VENC_FREE(video->nextBaseVop->yChan);
1181 M4VENC_FREE(video->nextBaseVop);
1184 if (video->prevBaseVop)
1186 if (video->prevBaseVop->yChan)
1188 video->prevBaseVop->yChan -= offset;
1189 M4VENC_FREE(video->prevBaseVop->yChan);
1191 M4VENC_FREE(video->prevBaseVop);
1193 if (video->prevEnhanceVop)
1195 if (video->prevEnhanceVop->yChan)
1197 video->prevEnhanceVop->yChan -= offset;
1198 M4VENC_FREE(video->prevEnhanceVop->yChan);
1200 M4VENC_FREE(video->prevEnhanceVop);
1204 for (idx = 0; idx < video->encParams->nLayers; idx++)
1206 if (video->pMP[idx])
1208 if (video->pMP[idx]->pRDSamples)
1212 if (video->pMP[idx]->pRDSamples[i])
1213 M4VENC_FREE(video->pMP[idx]->pRDSamples[i]);
1215 M4VENC_FREE(video->pMP[idx]->pRDSamples);
1218 M4VENC_MEMSET(video->pMP[idx], 0, sizeof(MultiPass));
1219 M4VENC_FREE(video->pMP[idx]);
1224 if (video->vol)
1226 for (idx = 0; idx < video->encParams->nLayers; idx++)
1228 if (video->vol[idx])
1230 if (video->vol[idx]->stream)
1231 M4VENC_FREE(video->vol[idx]->stream);
1232 M4VENC_FREE(video->vol[idx]);
1235 M4VENC_FREE(video->vol);
1243 if (video->encParams->RC_Type != CONSTANT_Q)
1245 RC_Cleanup(video->rc, video->encParams->nLayers);
1247 for (idx = 0; idx < video->encParams->nLayers; idx++)
1249 if (video->rc[idx])
1250 M4VENC_FREE(video->rc[idx]);
1254 if (video->functionPointer) M4VENC_FREE(video->functionPointer);
1258 if (video->encParams)
1260 M4VENC_FREE(video->encParams);
1263 M4VENC_FREE(video);
1264 encoderControl->videoEncoderData = NULL; /* video */
1327 VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
1328 Int currLayer = video->currLayer;
1329 Vol *currVol = video->vol[currLayer];
1331 if (currVol->stream->bitstreamBuffer != video->overrunBuffer) // not used
1336 return video->overrunBuffer;
1345 /* Purpose : Encode video frame and return bitstream */
1358 VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
1359 VideoEncParams *encParams = video->encParams;
1384 if (video->volInitialize[0]) /* first vol to code */
1386 video->nextModTime = video->modTimeRef = ((modTime) - ((modTime) % 1000));
1389 encodeVop = DetermineCodingLayer(video, nLayer, modTime);
1404 *nextModTime = video->nextModTime;
1407 if (video->vol[0]->shortVideoHeader) /* Short Video Header = 1 */
1415 EncodeVopNotCoded(video, bstream, size, modTime);
1416 *size = video->vol[0]->stream->byteCount;
1432 currVol = video->vol[currLayer];
1436 BitstreamSetOverrunBuffer(currVol->stream, video->overrunBuffer, video->oBSize, video);
1442 if (video->volInitialize[currLayer])
1444 video->currVop->timeInc = 0;
1445 video->prevBaseVop->timeInc = 0;
1446 if (!video->encParams->GetVolHeader[currLayer])
1451 /* Copy Input Video Frame to Internal Video Buffer */
1462 video->input = vid_in; /* point to the frame input */
1471 DetermineVopType(video, currLayer);
1476 video->currVop->volID = currVol->volID;
1477 video->currVop->width = width_16;
1478 video->currVop->height = height_16;
1479 if (video->encParams->H263_Enabled) /* 11/28/05 */
1481 video->currVop->pitch = width_16;
1485 video->currVop->pitch = width_16 + 32;
1487 video->currVop->timeInc = currVol->timeIncrement;
1488 video->currVop->vopCoded = 1;
1489 video->currVop->roundingType = 0;
1490 video->currVop->intraDCVlcThr = encParams->IntraDCVlcThr;
1494 || random_val[rand_idx] || video->volInitialize[currLayer]
1498 tempForwRefVop = video->forwardRefVop; /* keep initial state */
1501 video->forwardRefVop = video->prevBaseVop;
1502 video->forwardRefVop->refSelectCode = 1;
1507 tempForwRefVop = video->forwardRefVop; /* keep initial state */
1510 video->forwardRefVop = video->prevEnhanceVop;
1511 video->forwardRefVop->refSelectCode = 0;
1517 video->currVop->refSelectCode = video->forwardRefVop->refSelectCode;
1518 video->currVop->gobNumber = 0;
1519 video->currVop->gobFrameID = video->currVop->predictionType;
1520 video->currVop->temporalRef = (modTime * 30 / 1001) % 256;
1522 video->currVop->temporalInterval = 0;
1524 if (video->currVop->predictionType == I_VOP)
1525 video->currVop->quantizer = encParams->InitQuantIvop[currLayer];
1527 video->currVop->quantizer = encParams->InitQuantPvop[currLayer];
1533 video->slice_coding = 0;
1535 pv_status = EncodeVop(video);
1537 if (video->currVop->predictionType == I_VOP)
1540 printf(" P-VOP (ref.%d)", video->forwardRefVop->refSelectCode);
1546 *nLayer = UpdateSkipNextFrame(video, nextModTime, size, pv_status);
1552 video->forwardRefVop = tempForwRefVop; /* For P-Vop base only */
1553 video->forwardRefVop->refSelectCode = tempRefSelCode;
1560 if ((currLayer == 0) && (encParams->IntraPeriod > 0) && (video->currVop->predictionType == I_VOP))
1561 video->nextEncIVop = encParams->IntraPeriod;
1567 video->hintTrackInfo.MTB = 1;
1569 video->hintTrackInfo.MTB = 0;
1570 video->hintTrackInfo.LayerID = (UChar)currVol->volID;
1571 video->hintTrackInfo.CodeType = (UChar)video->currVop->predictionType;
1572 video->hintTrackInfo.RefSelCode = (UChar)video->currVop->refSelectCode;
1581 /* Copy Reconstructed Buffer to Output Video Frame Buffer */
1583 vid_out->yChan = video->currVop->yChan;
1584 vid_out->uChan = video->currVop->uChan;
1585 vid_out->vChan = video->currVop->vChan;
1586 if (video->encParams->H263_Enabled)
1588 vid_out->height = video->currVop->height; /* padded height */
1589 vid_out->pitch = video->currVop->width; /* padded width */
1593 vid_out->height = video->currVop->height + 32; /* padded height */
1594 vid_out->pitch = video->currVop->width + 32; /* padded width */
1596 //video_out->timestamp = video->modTime;
1597 vid_out->timestamp = (ULong)(((video->prevFrameNum[currLayer] * 1000) / encParams->LayerFrameRate[currLayer]) + video->modTimeRef + 0.5);
1612 temp = video->prevBaseVop;
1613 video->prevBaseVop = video->currVop;
1614 video->prevBaseVop->padded = 0; /* not padded */
1615 video->currVop = temp;
1616 video->forwardRefVop = video->prevBaseVop; /* For P-Vop base only */
1617 video->forwardRefVop->refSelectCode = 1;
1621 temp = video->prevEnhanceVop;
1622 video->prevEnhanceVop = video->currVop;
1623 video->prevEnhanceVop->padded = 0; /* not padded */
1624 video->currVop = temp;
1625 video->forwardRefVop = video->prevEnhanceVop;
1626 video->forwardRefVop->refSelectCode = 0;
1632 if (video->volInitialize[currLayer])
1633 video->volInitialize[currLayer] = 0;
1642 /* Purpose : Enter a video frame and perform front-end time check plus ME */
1651 VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
1652 VideoEncParams *encParams = video->encParams;
1672 video->modTime = modTime;
1676 if (video->volInitialize[0]) /* first vol to code */
1678 video->nextModTime = video->modTimeRef = ((modTime) - ((modTime) % 1000));
1682 encodeVop = DetermineCodingLayer(video, nLayer, modTime);
1698 *nextModTime = video->nextModTime;;
1706 currVol = video->vol[currLayer];
1714 if (video->volInitialize[currLayer])
1716 video->currVop->timeInc = 0;
1717 video->prevBaseVop->timeInc = 0;
1721 /* Copy Input Video Frame to Internal Video Buffer */
1732 video->input = vid_in; /* point to the frame input */
1741 DetermineVopType(video, currLayer);
1746 video->currVop->volID = currVol->volID;
1747 video->currVop->width = width_16;
1748 video->currVop->height = height_16;
1749 if (video->encParams->H263_Enabled) /* 11/28/05 */
1751 video->currVop->pitch = width_16;
1755 video->currVop->pitch = width_16 + 32;
1757 video->currVop->timeInc = currVol->timeIncrement;
1758 video->currVop->vopCoded = 1;
1759 video->currVop->roundingType = 0;
1760 video->currVop->intraDCVlcThr = encParams->IntraDCVlcThr;
1764 video->volInitialize[currLayer]
1768 video->tempForwRefVop = video->forwardRefVop; /* keep initial state */
1769 if (video->tempForwRefVop != NULL) video->tempRefSelCode = video->tempForwRefVop->refSelectCode;
1771 video->forwardRefVop = video->prevBaseVop;
1772 video->forwardRefVop->refSelectCode = 1;
1777 video->tempForwRefVop = video->forwardRefVop; /* keep initial state */
1778 if (video->tempForwRefVop != NULL) video->tempRefSelCode = video->tempForwRefVop->refSelectCode;
1780 video->forwardRefVop = video->prevEnhanceVop;
1781 video->forwardRefVop->refSelectCode = 0;
1787 video->currVop->refSelectCode = video->forwardRefVop->refSelectCode;
1788 video->currVop->gobNumber = 0;
1789 video->currVop->gobFrameID = video->currVop->predictionType;
1790 video->currVop->temporalRef = ((modTime) * 30 / 1001) % 256;
1792 video->currVop->temporalInterval = 0;
1794 if (video->currVop->predictionType == I_VOP)
1795 video->currVop->quantizer = encParams->InitQuantIvop[currLayer];
1797 video->currVop->quantizer = encParams->InitQuantPvop[currLayer];
1802 video->slice_coding = 1;
1805 EncodeVop(video);
1808 if (video->currVop->predictionType == I_VOP)
1811 printf(" P-VOP (ref.%d)", video->forwardRefVop->refSelectCode);
1816 video->hintTrackInfo.MTB = 1;
1818 video->hintTrackInfo.MTB = 0;
1820 video->hintTrackInfo.LayerID = (UChar)currVol->volID;
1821 video->hintTrackInfo.CodeType = (UChar)video->currVop->predictionType;
1822 video->hintTrackInfo.RefSelCode = (UChar)video->currVop->refSelectCode;
1842 VideoEncData *video = (VideoEncData *)encCtrl->videoEncoderData;
1843 VideoEncParams *encParams = video->encParams;
1848 Int currLayer = video->currLayer;
1855 currVol = video->vol[currLayer];
1864 if (video->volInitialize[currLayer])
1866 if (!video->encParams->GetVolHeader[currLayer])
1873 pv_status = EncodeSlice(video);
1877 if (video->mbnum >= currVol->nTotalMB && !video->end_of_buf)
1884 pre_skip = UpdateSkipNextFrame(video, nextModTime, size, pv_status); /* modified such that no pre-skipped */
1892 video->forwardRefVop = video->tempForwRefVop; /* For P-Vop base only */
1893 video->forwardRefVop->refSelectCode = video->tempRefSelCode;
1900 if ((currLayer == 0) && (encParams->IntraPeriod > 0) && (video->currVop->predictionType == I_VOP))
1901 video->nextEncIVop = encParams->IntraPeriod;
1904 /* Copy Reconstructed Buffer to Output Video Frame Buffer */
1906 vid_out->yChan = video->currVop->yChan;
1907 vid_out->uChan = video->currVop->uChan;
1908 vid_out->vChan = video->currVop->vChan;
1909 if (video->encParams->H263_Enabled)
1911 vid_out->height = video->currVop->height; /* padded height */
1912 vid_out->pitch = video->currVop->width; /* padded width */
1916 vid_out->height = video->currVop->height + 32; /* padded height */
1917 vid_out->pitch = video->currVop->width + 32; /* padded width */
1919 //vid_out->timestamp = video->modTime;
1920 vid_out->timestamp = (ULong)(((video->prevFrameNum[currLayer] * 1000) / encParams->LayerFrameRate[currLayer]) + video->modTimeRef + 0.5);
1930 temp = video->prevBaseVop;
1931 video->prevBaseVop = video->currVop;
1932 video->prevBaseVop->padded = 0; /* not padded */
1933 video->currVop = temp;
1934 video->forwardRefVop = video->prevBaseVop; /* For P-Vop base only */
1935 video->forwardRefVop->refSelectCode = 1;
1939 temp = video->prevEnhanceVop;
1940 video->prevEnhanceVop = video->currVop;
1941 video->prevEnhanceVop->padded = 0; /* not padded */
1942 video->currVop = temp;
1943 video->forwardRefVop = video->prevEnhanceVop;
1944 video->forwardRefVop->refSelectCode = 0;
1957 if (video->volInitialize[currLayer])
1958 video->volInitialize[currLayer] = 0;
2048 VideoEncData* video;
2051 video = (VideoEncData *)encCtrl->videoEncoderData;
2057 if (video->encParams->ProfileLevel[0] == profile_level_code[i])
2068 if (video->encParams->ProfileLevel[0] == scalable_profile_level_code[i])
2405 VideoEncData *video = (VideoEncData *)encoderControl->videoEncoderData;
2406 Vol *currVol = video->vol[video->currLayer];
2409 BitstreamEncVideo *stream = video->bitstream1;
2419 /* Short Video Header or M4V */
2426 status = BitstreamPutBits(stream, 8, video->encParams->ProfileLevel[video->currLayer]);
2434 status = BitstreamPutBits(stream, 4, 0x01); /* visual object Type == "video ID" */
2435 status = BitstreamPut1Bits(stream, 0x00); /* no video signal type */
2442 status = BitstreamPutBits(stream, 5, 0x00);/* Video ID = 0 */
2450 { /* M4V else Short Video Header */
2455 if (video->currLayer == 0)
2456 status = BitstreamPutBits(stream, 8, 0x01);/* Video Object Type Indication = 1 ... Simple Object Type */
2458 status = BitstreamPutBits(stream, 8, 0x02);/* Video Object Type Indication = 2 ... Simple Scalable Object Type */
2570 VideoEncData *video = (VideoEncData *)encoderControl->videoEncoderData;
2571 Vol *currVol = video->vol[video->currLayer];
2591 Int DetermineCodingLayer(VideoEncData *video, Int *nLayer, ULong modTime)
2593 Vol **vol = video->vol;
2594 VideoEncParams *encParams = video->encParams;
2596 UInt modTimeRef = video->modTimeRef;
2610 if (modTime - video->nextModTime > ((ULong)(-1)) >> 1) /* next time wrapped around */
2613 video->relLayerCodeTime[i] -= 1000;
2614 video->nextEncIVop--; /* number of Vops in highest layer resolution. */
2615 video->numVopsInGOP++;
2620 if (video->volInitialize[i])
2622 video->prevFrameNum[i] = frameNum[i] - 1;
2624 else if (frameNum[i] <= video->prevFrameNum[i])
2633 srcFrameInterval = 1000 / video->FrameRate;
2635 video->nextModTime = nextFrmModTime - (ULong)(srcFrameInterval / 2.) - 1; /* between current and next frame */
2640 if (video->nextModTime - modTime < (ULong)delta) /* need to move nextModTime further. */
2642 video->nextModTime += ((delta - video->nextModTime + modTime)); /* empirical formula */
2656 vol[i]->timeIncrement = frameTick - video->refTick[i];
2667 if (video->relLayerCodeTime[i] <= 0) /* no skipping */
2670 video->currLayer = *nLayer = i;
2671 video->relLayerCodeTime[i] += 1000;
2675 frameInc = (frameNum[i] - video->prevFrameNum[i]);
2680 video->nextEncIVop -= extra_skip;
2681 video->numVopsInGOP += extra_skip;
2684 RC_UpdateBuffer(video, i, extra_skip);
2690 video->prevFrameNum[i] = frameNum[i];
2696 video->relLayerCodeTime[i] -= 1000;
2699 vol[i]->timeIncrement = frameTick - video->refTick[i];
2701 if (video->relLayerCodeTime[i] <= 0) /* time to encode base */
2705 video->currLayer = *nLayer = i;
2706 video->relLayerCodeTime[i] +=
2719 if (video->volInitialize[i])
2720 video->prevFrameNum[i] = frameNum[i] - 1;
2723 frameInc = (frameNum[i] - video->prevFrameNum[i]);
2730 RC_UpdateBuffer(video, i, extra_skip);
2734 video->prevFrameNum[i] = frameNum[i];
2756 void DetermineVopType(VideoEncData *video, Int currLayer)
2758 VideoEncParams *encParams = video->encParams;
2759 // Vol *currVol = video->vol[currLayer];
2763 if (video->currLayer > 0)
2764 video->currVop->predictionType = P_VOP;
2767 video->currVop->predictionType = I_VOP;
2768 if (video->numVopsInGOP >= 132)
2769 video->numVopsInGOP = 0;
2776 if (encParams->RC_Type == CONSTANT_Q || video->rc[currLayer]->skip_next_frame != -1)
2777 video->currVop->predictionType = P_VOP;
2779 if (video->currLayer == 0)
2781 if (/*video->numVopsInGOP>=132 || */video->volInitialize[currLayer])
2783 video->currVop->predictionType = I_VOP;
2784 video->numVopsInGOP = 0; /* force INTRA update every 132 base frames*/
2785 video->nextEncIVop = 1;
2787 else if (video->nextEncIVop == 0 || video->currVop->predictionType == I_VOP)
2789 video->numVopsInGOP = 0;
2790 video->nextEncIVop = 1;
2798 if (encParams->RC_Type == CONSTANT_Q || video->rc[currLayer]->skip_next_frame != -1)
2799 video->currVop->predictionType = P_VOP;
2803 if (video->nextEncIVop <= 0 || video->currVop->predictionType == I_VOP)
2805 video->nextEncIVop = encParams->IntraPeriod;
2806 video->currVop->predictionType = I_VOP;
2807 video->numVopsInGOP = 0;
2826 Int UpdateSkipNextFrame(VideoEncData *video, ULong *modTime, Int *size, PV_STATUS status)
2828 Int currLayer = video->currLayer;
2830 VideoEncParams *encParams = video->encParams;
2832 Vol *currVol = video->vol[currLayer];
2833 Vol **vol = video->vol;
2841 if (video->volInitialize[0] && currLayer == 0) /* always encode the first frame */
2843 RC_ResetSkipNextFrame(video, currLayer);
2848 if (RC_GetSkipNextFrame(video, currLayer) < 0 || status == PV_END_OF_BUF) /* Skip Current Frame */
2863 *modTime = video->nextModTime;
2868 /*if((encParams->IntraPeriod>0) && (video->currVop->predictionType == I_VOP))
2869 video->nextEncIVop = 0; commented out by 06/05/01 */
2872 else if ((num_skip = RC_GetSkipNextFrame(video, currLayer)) > 0)
2883 if (video->relLayerCodeTime[i] <= 1000)
2892 video->relLayerCodeTime[i] += (num_skip + extra_skip) *
2900 video->refTick[currLayer] += vol[currLayer]->prevModuloTimeBase * vol[currLayer]->timeIncrementResolution;
2906 if (((encParams->IntraPeriod != 0) /*&& (video->currVop->predictionType==I_VOP)*/) ||
2907 ((encParams->IntraPeriod == 0) && (video->numVopsInGOP == 0)))
2909 newRefTick = video->refTick[0];
2913 if (video->refTick[i] < newRefTick)
2914 newRefTick = video->refTick[i];
2930 video->modTimeRef += deltaModTime;
2933 video->prevFrameNum[i] -= (UInt)(deltaModTime * encParams->LayerFrameRate[i]) / 1000;
2934 video->refTick[i] -= newRefTick;
2940 *modTime = video->nextModTime;
2951 /* Purpose : Set profile and video buffer size, copied from Jim's code */
2953 /* to reset profile and video buffer size */
2960 Bool SetProfile_BufferSize(VideoEncData *video, float delay, Int bInitialized)
2967 Int nLayers = video->encParams->nLayers; /* Number of Layers to be encoded */
2986 index = video->encParams->profile_table_index;
2992 temp_w = video->encParams->LayerWidth[idx];
2993 temp_h = video->encParams->LayerHeight[idx];
3003 upper_bound_ratio = (video->encParams->RC_Type == CBR_LOWDELAY ? (float)5.0 : (float)UPPER_BOUND_RATIO);
3007 base_bitrate = video->encParams->LayerBitRate[0];
3008 if (video->encParams->LayerMaxBitRate[0] != 0) /* video->encParams->LayerMaxBitRate[0] == 0 means it has not been set */
3010 base_bitrate = PV_MAX(base_bitrate, video->encParams->LayerMaxBitRate[0]);
3014 video->encParams->LayerMaxBitRate[0] = profile_level_max_bitrate[index];
3017 base_framerate = video->encParams->LayerFrameRate[0];
3018 if (video->encParams->LayerMaxFrameRate[0] != 0)
3020 base_framerate = PV_MAX(base_framerate, video->encParams->LayerMaxFrameRate[0]);
3024 video->encParams->LayerMaxFrameRate[0] = (float)profile_level_max_mbsPerSec[index] / nTotalMB;
3027 base_packet_size = video->encParams->ResyncPacketsize;
3045 total_bitrate = video->encParams->LayerBitRate[1];
3046 if (video->encParams->LayerMaxBitRate[1] != 0)
3048 total_bitrate = PV_MIN(total_bitrate, video->encParams->LayerMaxBitRate[1]);
3052 video->encParams->LayerMaxBitRate[1] = scalable_profile_level_max_bitrate[index];
3055 total_framerate = video->encParams->LayerFrameRate[1];
3056 if (video->encParams->LayerMaxFrameRate[1] != 0)
3058 total_framerate = PV_MIN(total_framerate, video->encParams->LayerMaxFrameRate[1]);
3062 video->encParams->LayerMaxFrameRate[1] = (float)scalable_profile_level_max_mbsPerSec[index] / nTotalMB;
3065 total_packet_size = video->encParams->ResyncPacketsize;
3089 video->encParams->BufferSize[0] = base_VBV_size;
3091 video->encParams->BufferSize[1] = enhance_VBV_size;
3109 width16 = ((video->encParams->LayerWidth[0] + 15) >> 4) << 4;
3110 height16 = ((video->encParams->LayerHeight[0] + 15) >> 4) << 4;
3111 if (video->encParams->H263_Enabled)
3123 video->encParams->maxFrameSize = k * 16384;
3134 if (!video->encParams->H263_Enabled &&
3135 (video->encParams->IntraDCVlcThr != 0 || video->encParams->SearchRange > 16))
3150 base_VBV_size <= (video->encParams->H263_Enabled ? (Int)(k*16384 + 4*(float)profile_level_max_bitrate[i]*1001.0 / 30000.0) :
3164 video->encParams->ProfileLevel[0] = profile_level_code[i];
3165 video->encParams->BufferSize[0] = base_VBV_size;
3167 if (video->encParams->LayerMaxBitRate[0] == 0)
3168 video->encParams->LayerMaxBitRate[0] = profile_level_max_bitrate[i];
3170 if (video->encParams->LayerMaxFrameRate[0] == 0)
3171 video->encParams->LayerMaxFrameRate[0] = PV_MIN(30, (float)profile_level_max_mbsPerSec[i] / nTotalMB);
3174 if (video->encParams->H263_Enabled)
3175 video->encParams->BufferSize[0] = (Int)(k * 16384 + 4 * (float)profile_level_max_bitrate[i] * 1001.0 / 30000.0);
3244 video->encParams->ProfileLevel[0] = profile_level_code[j];
3245 video->encParams->ProfileLevel[1] = scalable_profile_level_code[i];
3246 video->encParams->BufferSize[0] = base_VBV_size;
3247 video->encParams->BufferSize[1] = enhance_VBV_size;
3249 if (video->encParams->LayerMaxBitRate[0] == 0)
3250 video->encParams->LayerMaxBitRate[0] = profile_level_max_bitrate[j];
3252 if (video->encParams->LayerMaxBitRate[1] == 0)
3253 video->encParams->LayerMaxBitRate[1] = scalable_profile_level_max_bitrate[i];
3255 if (video->encParams->LayerMaxFrameRate[0] == 0)
3256 video->encParams->LayerMaxFrameRate[0] = PV_MIN(30, (float)profile_level_max_mbsPerSec[j] / nTotalMB);
3258 if (video->encParams->LayerMaxFrameRate[1] == 0)
3259 video->encParams->LayerMaxFrameRate[1] = PV_MIN(30, (float)scalable_profile_level_max_mbsPerSec[i] / nTotalMB);
3265 if (!video->encParams->H263_Enabled && (video->encParams->ProfileLevel[0] == 0x08)) /* SPL0 restriction*/
3268 if(video->encParams->ACDCPrediction == TRUE && MB-based rate control)