159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ------------------------------------------------------------------ 259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Copyright (C) 1998-2009 PacketVideo 359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Licensed under the Apache License, Version 2.0 (the "License"); 559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * you may not use this file except in compliance with the License. 659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * You may obtain a copy of the License at 759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * http://www.apache.org/licenses/LICENSE-2.0 959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * 1059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * Unless required by applicable law or agreed to in writing, software 1159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * distributed under the License is distributed on an "AS IS" BASIS, 1259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 1359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * express or implied. 1459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * See the License for the specific language governing permissions 1559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * and limitations under the License. 1659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong * ------------------------------------------------------------------- 1759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong */ 1859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4def.h" 1959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4lib_int.h" 2059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "mp4enc_lib.h" 2159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "bitstream_io.h" 2259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#include "m4venc_oscl.h" 2359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 2459f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeShortHeader(BitstreamEncVideo *stream, Vop *currVop); 2559f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeVOPHeader(BitstreamEncVideo *stream, Vol *currVol, Vop *currVop); 2659f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeGOVHeader(BitstreamEncVideo *stream, UInt seconds); 2759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 2859f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeVop_BXRC(VideoEncData *video); 2959f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeVop_NoME(VideoEncData *video); 3059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 3159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 3259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Function : DecodeVop() */ 3359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Date : 08/23/2000 */ 3459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Purpose : Encode VOP Header */ 3559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* In/out : */ 3659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Return : */ 3759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Modified : */ 3859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 3959f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeVop(VideoEncData *video) 4059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 4159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 4259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PV_STATUS status; 4359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int currLayer = video->currLayer; 4459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vol *currVol = video->vol[currLayer]; 4559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vop *currVop = video->currVop; 4659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong// BitstreamEncVideo *stream=video->bitstream1; 4759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar *Mode = video->headerInfo.Mode; 4859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rateControl **rc = video->rc; 4959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong// UInt time=0; 5059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 5159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*******************/ 5259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Initialize mode */ 5359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*******************/ 5459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 5559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong switch (currVop->predictionType) 5659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 5759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong case I_VOP: 5859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong M4VENC_MEMSET(Mode, MODE_INTRA, sizeof(UChar)*currVol->nTotalMB); 5959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong break; 6059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong case P_VOP: 6159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong M4VENC_MEMSET(Mode, MODE_INTER, sizeof(UChar)*currVol->nTotalMB); 6259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong break; 6359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong case B_VOP: 6459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*M4VENC_MEMSET(Mode, MODE_INTER_B,sizeof(UChar)*nTotalMB);*/ 6559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return PV_FAIL; 6659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong default: 6759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return PV_FAIL; 6859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 6959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*********************/ 7159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Motion Estimation */ 7259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* compute MVs, scene change detection, edge padding, */ 7359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* intra refresh, compute block activity */ 7459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*********************/ 7559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong MotionEstimation(video); /* do ME for the whole frame */ 7659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 7759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /***************************/ 7859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* rate Control (assign QP) */ 7959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* 4/11/01, clean-up, and put into a separate function */ 8059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /***************************/ 8159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = RC_VopQPSetting(video, rc); 8259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (status == PV_FAIL) 8359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return PV_FAIL; 8459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 8559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /**********************/ 8659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Encode VOP */ 8759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /**********************/ 8859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (video->slice_coding) /* end here */ 8959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 9059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* initialize state variable for slice-based APIs */ 9159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->totalSAD = 0; 9259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->mbnum = 0; 9359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->sliceNo[0] = 0; 9459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->numIntra = 0; 9559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->offset = 0; 9659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->end_of_buf = 0; 9759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->hp_guess = -1; 9859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 9959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 10059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 10159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeVop_NoME(video); 10259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 10359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /******************************/ 10459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* rate control (update stat) */ 10559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* 6/2/01 separate function */ 10659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /******************************/ 10759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 10859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong RC_VopUpdateStat(video, rc[currLayer]); 10959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 11159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 11259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 11359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 11459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Function : EncodeVop_NoME() */ 11559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Date : 08/28/2001 */ 11659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* History : */ 11759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Purpose : EncodeVop without motion est. */ 11859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* In/out : */ 11959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Return : */ 12059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Modified : */ 12159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* */ 12259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 12359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 12459f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeVop_NoME(VideoEncData *video) 12559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 12659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vop *currVop = video->currVop; 12759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vol *currVol = video->vol[video->currLayer]; 12859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamEncVideo *stream = video->bitstream1; 12959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int time = 0; /* follows EncodeVop value */ 13059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PV_STATUS status = PV_SUCCESS; 13159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 13259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVol->shortVideoHeader) /* Short Video Header = 1 */ 13359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 13459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 13559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeShortHeader(stream, currVop); /* Encode Short Header */ 13659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 13759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->header_bits = BitstreamGetPos(stream); /* Header Bits */ 13859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 13959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeFrameCombinedMode(video); 14059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 14159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 14259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef H263_ONLY 14359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* Short Video Header = 0 */ 14459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 14559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 14659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVol->GOVStart && currVop->predictionType == I_VOP) 14759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeGOVHeader(stream, time); /* Encode GOV Header */ 14859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 14959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeVOPHeader(stream, currVol, currVop); /* Encode VOP Header */ 15059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 15159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->header_bits = BitstreamGetPos(stream); /* Header Bits */ 15259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 15359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->vopCoded) 15459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 15559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (!currVol->scalability) 15659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 15759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVol->dataPartitioning) 15859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 15959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeFrameDataPartMode(video); /* Encode Data Partitioning Mode VOP */ 16059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 16159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 16259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 16359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeFrameCombinedMode(video); /* Encode Combined Mode VOP */ 16459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 16559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 16659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 16759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeFrameCombinedMode(video); /* Encode Combined Mode VOP */ 16859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 16959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* Vop Not coded */ 17059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 17159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 17259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 17359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 17459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 17559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif /* H263_ONLY */ 17659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 17759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 17859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 17959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 18059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef NO_SLICE_ENCODE 18159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 18259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Function : EncodeSlice() */ 18359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Date : 04/19/2002 */ 18459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* History : */ 18559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Purpose : Encode one slice. */ 18659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* In/out : */ 18759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Return : */ 18859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Modified : */ 18959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* */ 19059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 19159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 19259f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeSlice(VideoEncData *video) 19359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 19459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vop *currVop = video->currVop; 19559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int currLayer = video->currLayer; 19659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vol *currVol = video->vol[currLayer]; 19759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamEncVideo *stream = video->bitstream1; /* different from frame-based */ 19859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int time = 0; /* follows EncodeVop value */ 19959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PV_STATUS status = PV_SUCCESS; 20059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong rateControl **rc = video->rc; 20159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 20259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVol->shortVideoHeader) /* Short Video Header = 1 */ 20359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 20459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 20559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (video->mbnum == 0) 20659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 20759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeShortHeader(stream, currVop); /* Encode Short Header */ 20859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 20959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->header_bits = BitstreamGetPos(stream); /* Header Bits */ 21059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 21159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 21259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeSliceCombinedMode(video); 21359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 21459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 21559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef H263_ONLY 21659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* Short Video Header = 0 */ 21759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 21859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 21959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (video->mbnum == 0) 22059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 22159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVol->GOVStart) 22259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeGOVHeader(stream, time); /* Encode GOV Header */ 22359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 22459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeVOPHeader(stream, currVol, currVop); /* Encode VOP Header */ 22559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 22659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong video->header_bits = BitstreamGetPos(stream); /* Header Bits */ 22759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 22859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 22959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->vopCoded) 23059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 23159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (!currVol->scalability) 23259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 23359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVol->dataPartitioning) 23459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 23559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeSliceDataPartMode(video); /* Encode Data Partitioning Mode VOP */ 23659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 23759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 23859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 23959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeSliceCombinedMode(video); /* Encode Combined Mode VOP */ 24059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 24159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 24259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 24359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = EncodeSliceCombinedMode(video); /* Encode Combined Mode VOP */ 24459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 24559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else /* Vop Not coded */ 24659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 24759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 24859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 24959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 25059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 25159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif /* H263_ONLY */ 25259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (video->mbnum >= currVol->nTotalMB && status != PV_END_OF_BUF) /* end of Vop */ 25359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 25459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /******************************/ 25559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* rate control (update stat) */ 25659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* 6/2/01 separate function */ 25759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /******************************/ 25859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 25959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = RC_VopUpdateStat(video, rc[currLayer]); 26059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 26159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 26359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 26559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif /* NO_SLICE_ENCODE */ 26659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 26759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef H263_ONLY 26859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 26959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Function : EncodeGOVHeader() */ 27059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Date : 08/23/2000 */ 27159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Purpose : Encode GOV Header */ 27259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* In/out : */ 27359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Return : */ 27459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Modified : */ 27559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 27659f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeGOVHeader(BitstreamEncVideo *stream, UInt seconds) 27759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 27859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PV_STATUS status; 27959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong// int temp; 28059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UInt tmpvar; 28159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 28259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /********************************/ 28359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* Group_of_VideoObjectPlane() */ 28459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /********************************/ 28559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 28659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutGT16Bits(stream, 32, GROUP_START_CODE); 28759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* time_code */ 28859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmpvar = seconds / 3600; 28959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 5, tmpvar); /* Hours*/ 29059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 29159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmpvar = (seconds - tmpvar * 3600) / 60; 29259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 6, tmpvar); /* Minutes*/ 29359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 29459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 1); /* Marker*/ 29559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 29659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmpvar = seconds % 60; 29759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 6, tmpvar); /* Seconds*/ 29859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 29959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 1); /* closed_gov */ 30059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 0); /* broken_link */ 30159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*temp =*/ 30259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamMpeg4ByteAlignStuffing(stream); /* Byte align GOV Header */ 30359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 30459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 30559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 30659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 30759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifdef ALLOW_VOP_NOT_CODED 30859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 30959f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeVopNotCoded(VideoEncData *video, UChar *bstream, Int *size, ULong modTime) 31059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 31159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PV_STATUS status; 31259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vol *currVol = video->vol[0]; 31359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vop *currVop = video->currVop; 31459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamEncVideo *stream = currVol->stream; 31559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UInt frameTick; 31659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Int timeInc; 31759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 31859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong stream->bitstreamBuffer = bstream; 31959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong stream->bufferSize = *size; 32059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamEncReset(stream); 32159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 32259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutGT16Bits(stream, 32, VOP_START_CODE); /*Start Code for VOP*/ 32359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 2, P_VOP);/* VOP Coding Type*/ 32459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 32559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong frameTick = (Int)(((double)(modTime - video->modTimeRef) * currVol->timeIncrementResolution + 500) / 1000); 32659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong timeInc = frameTick - video->refTick[0]; 32759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (timeInc >= currVol->timeIncrementResolution) 32859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 32959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong timeInc -= currVol->timeIncrementResolution; 33059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 1); 33159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* do not update refTick and modTimeRef yet, do it after encoding!! */ 33259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 33359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 0); 33459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 1); /* marker bit */ 33559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, currVol->nbitsTimeIncRes, timeInc); /* vop_time_increment */ 33659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 1); /* marker bit */ 33759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 0); /* vop_coded bit */ 33859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamMpeg4ByteAlignStuffing(stream); 33959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 34059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 34159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 34259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif 34359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 34459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 34559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Function : EncodeVOPHeader() */ 34659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Date : 08/23/2000 */ 34759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Purpose : Encode VOP Header */ 34859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* In/out : */ 34959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Return : */ 35059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Modified : */ 35159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 35259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 35359f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeVOPHeader(BitstreamEncVideo *stream, Vol *currVol, Vop *currVop) 35459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 35559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PV_STATUS status; 35659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong //int temp; 35759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 35859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int MTB = currVol->moduloTimeBase; 35959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /************************/ 36059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* VideoObjectPlane() */ 36159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /************************/ 36259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 36359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutGT16Bits(stream, 32, VOP_START_CODE); /*Start Code for VOP*/ 36459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 2, currVop->predictionType);/* VOP Coding Type*/ 36559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 36659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong currVol->prevModuloTimeBase = currVol->moduloTimeBase; 36759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 36859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong while (MTB) 36959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 37059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 1); 37159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong MTB--; 37259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 37359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 0); 37459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 37559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 1); /* marker bit */ 37659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, currVol->nbitsTimeIncRes, currVop->timeInc); /* vop_time_increment */ 37759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 1); /* marker bit */ 37859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, currVop->vopCoded); /* vop_coded bit */ 37959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->vopCoded == 0) 38059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 38159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*temp =*/ 38259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamMpeg4ByteAlignStuffing(stream); /* Byte align VOP Header */ 38359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 38459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 38559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->predictionType == P_VOP) 38659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, currVop->roundingType); /* vop_rounding_type */ 38759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 38859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 3, currVop->intraDCVlcThr); /* intra_dc_vlc_thr */ 38959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 5, currVop->quantizer); /* vop_quant */ 39059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 39159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->predictionType != I_VOP) 39259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 3, currVop->fcodeForward); /* vop_fcode_forward */ 39359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->predictionType == B_VOP) 39459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 3, currVop->fcodeBackward);/* vop_fcode_backward */ 39559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 39659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVol->scalability) 39759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* enhancement_type = 0 */ 39859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 2, currVop->refSelectCode); /* ref_select_code */ 39959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 40059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 40159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 40259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif /* H263_ONLY */ 40359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 40459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Function : EncodeShortHeader() */ 40559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Date : 08/23/2000 */ 40659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Purpose : Encode VOP Header */ 40759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* In/out : */ 40859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Return : */ 40959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Modified : */ 41059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 41159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 41259f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeShortHeader(BitstreamEncVideo *stream, Vop *currVop) 41359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 41459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 41559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong PV_STATUS status; 41659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 41759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutGT16Bits(stream, 22, SHORT_VIDEO_START_MARKER); /* Short_video_start_marker */ 41859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 8, currVop->temporalRef); /* temporal_reference */ 41959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 1); /* marker bit */ 42059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 0); /* zero bit */ 42159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 0); /* split_screen_indicator=0*/ 42259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 0); /* document_camera_indicator=0*/ 42359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 0); /* full_picture_freeze_release=0*/ 42459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 42559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong switch (currVop->width) 42659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 42759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong case 128: 42859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->height == 96) 42959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 3, 1); /* source_format = 1 */ 43059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 43159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 43259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = PV_FAIL; 43359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 43459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 43559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong break; 43659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 43759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong case 176: 43859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->height == 144) 43959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 3, 2); /* source_format = 2 */ 44059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 44159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 44259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = PV_FAIL; 44359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 44459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 44559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong break; 44659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 44759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong case 352: 44859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->height == 288) 44959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 3, 3); /* source_format = 3 */ 45059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 45159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 45259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = PV_FAIL; 45359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 45459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 45559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong break; 45659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 45759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong case 704: 45859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->height == 576) 45959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 3, 4); /* source_format = 4 */ 46059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 46159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 46259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = PV_FAIL; 46359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 46459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 46559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong break; 46659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 46759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong case 1408: 46859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->height == 1152) 46959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 3, 5); /* source_format = 5 */ 47059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 47159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 47259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = PV_FAIL; 47359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 47459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 47559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong break; 47659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 47759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong default: 47859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = PV_FAIL; 47959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 48059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 48159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 48259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 48359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, currVop->predictionType); /* picture_coding type */ 48459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 4, 0); /* four_reserved_zero_bits */ 48559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPutBits(stream, 5, currVop->quantizer); /* vop_quant*/ 48659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 0); /* zero_bit*/ 48759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong status = BitstreamPut1Bits(stream, 0); /* pei=0 */ 48859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 48959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return status; 49059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 49159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 49259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef H263_ONLY 49359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 49459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Function : EncodeVideoPacketHeader() */ 49559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Date : 09/05/2000 */ 49659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* History : */ 49759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Purpose : Encode a frame of MPEG4 bitstream in Combined mode. */ 49859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* In/out : */ 49959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Return : */ 50059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Modified : 04/25/2002 */ 50159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* Add bitstream structure as input argument */ 50259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* */ 50359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong/* ======================================================================== */ 50459f566c4ec3dfc097ad8163523e522280b27e5c3James DongPV_STATUS EncodeVideoPacketHeader(VideoEncData *video, int MB_number, 50559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int quant_scale, Int insert) 50659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong{ 50759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong// PV_STATUS status=PV_SUCCESS; 50859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong int fcode; 50959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vop *currVop = video->currVop; 51059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong Vol *currVol = video->vol[video->currLayer]; 51159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamEncVideo *bs, tmp; 51259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong UChar buffer[30]; 51359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 51459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (insert) /* insert packet header to the beginning of bs1 */ 51559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 51659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp.bitstreamBuffer = buffer; /* use temporary buffer */ 51759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong tmp.bufferSize = 30; 51859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamEncReset(&tmp); 51959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong bs = &tmp; 52059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 52159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 52259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong bs = video->bitstream1; 52359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 52459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 52559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->predictionType == I_VOP) 52659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPutGT16Bits(bs, 17, 1); /* resync_marker I_VOP */ 52759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else if (currVop->predictionType == P_VOP) 52859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 52959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong fcode = currVop->fcodeForward; 53059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPutGT16Bits(bs, 16 + fcode, 1); /* resync_marker P_VOP */ 53159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 53259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 53359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong else 53459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 53559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong fcode = currVop->fcodeForward; 53659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->fcodeBackward > fcode) 53759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong fcode = currVop->fcodeBackward; 53859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPutGT16Bits(bs, 16 + fcode, 1); /* resync_marker B_VOP */ 53959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 54059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 54159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPutBits(bs, currVol->nBitsForMBID, MB_number); /* resync_marker */ 54259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPutBits(bs, 5, quant_scale); /* quant_scale */ 54359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPut1Bits(bs, 0); /* header_extension_code = 0 */ 54459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 54559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (0) /* header_extension_code = 1 */ 54659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong { 54759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /* NEED modulo_time_base code here ... default 0x01 belo*/ 54859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*status =*/ 54959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPut1Bits(bs, 1); 55059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*status = */ 55159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPut1Bits(bs, 0); 55259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 55359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*status = */ 55459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPut1Bits(bs, 1); /* marker bit */ 55559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*status = */ 55659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPutBits(bs, currVol->nbitsTimeIncRes, currVop->timeInc); /* vop_time_increment */ 55759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*status = */ 55859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPut1Bits(bs, 1); /* marker bit */ 55959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 56059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*status = */ 56159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPutBits(bs, 2, currVop->predictionType);/* VOP Coding Type*/ 56259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 56359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*status = */ 56459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPutBits(bs, 3, currVop->intraDCVlcThr); /* intra_dc_vlc_thr */ 56559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 56659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->predictionType != I_VOP) 56759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*status = */ BitstreamPutBits(bs, 3, currVop->fcodeForward); 56859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (currVop->predictionType == B_VOP) 56959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong /*status = */ BitstreamPutBits(bs, 3, currVop->fcodeBackward); 57059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong } 57159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#ifndef NO_SLICE_ENCODE 57259f566c4ec3dfc097ad8163523e522280b27e5c3James Dong if (insert) 57359f566c4ec3dfc097ad8163523e522280b27e5c3James Dong BitstreamPrependPacket(video->bitstream1, bs); 57459f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif 57559f566c4ec3dfc097ad8163523e522280b27e5c3James Dong return PV_SUCCESS; 57659f566c4ec3dfc097ad8163523e522280b27e5c3James Dong} 57759f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 57859f566c4ec3dfc097ad8163523e522280b27e5c3James Dong#endif /* H263_ONLY */ 57959f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 58059f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 58159f566c4ec3dfc097ad8163523e522280b27e5c3James Dong 582