⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sequence.c

📁 Nokia H.264/AVC Encoder/Decoder Usage Manual
💻 C
📖 第 1 页 / 共 4 页
字号:
/*COPYRIGHT, LICENSE AND WARRANTY INFORMATIONThis software module has been originally developed by Nokia Corporation. Provided that a person, entity or a company willing to use the Software (hereinafter Licensee) comply with all the terms and conditions of this Statement and subject to the limitations set forth in this Statement Nokia grants to such Licensee a non-exclusive, sub-licensable, worldwide, limited license under copyrights owned by Nokia to use the Software for the sole purpose of creating, manufacturing, selling, marketing, or  distributing (including the right to make modifications to the Software) a fully compliant decoder implementation (hereinafter "Decoder") of ITU-T Recommendation H.264 / ISO/IEC International Standard 14496-10 and an encoder implementation producing output that is decodable with the Decoder.Nokia retains the ownership of copyrights to the Software. There is no patent nor other intellectual property right of Nokia licensed under this Statement (except the copyright license above). Licensee hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if patent licenses  are required, it is their responsibility to acquire the license before utilizing the Software.The license by Nokia is subject to that the Licensee grants to Nokia the non-exclusive, worldwide, royalty-free, perpetual and irrevocable covenant that the Licensee(s) shall not bring a suit before any court or administrative agency or otherwise assert a claim for infringement under the Licensee intellectual property rights that, but for a license, would be infringed by the Software against     (a)  Nokia or Nokia's Affiliate; or     (b)  other recipient of a license and covenant not to sue with respect         to the Software from Nokia; or    (c)  contractor, customer or distributor of a party listed above in a         or b,  which suit or claim is related to the Software or use thereof.The Licensee(s) further agrees to grant a reciprocal license to Nokia (as granted by Nokia to the Licensee(s) on the modifications made by Licensee(s) to the Software. THE SOFTWARE IS PROVIDED "AS IS" AND THE ORIGINAL DEVELOPER DISCLAIMS ANY AND ALL WARRANTIES WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. THOSE INTENDING TO USE THE SOFTWARE ARE EXPRESSLY ADVISED THAT ITS USE MAY INFRINGE EXISTING PATENTS AND BE SUBJECT TO ROYALTY PAYMENTS TO PATENT OWNERS. ANYONE USING THE SOFTWARE ON THE BASIS OF THIS LICENSE AGREES TO OBTAIN THE NECESSARY PERMISSIONS FROM ANY AND ALL APPLICABLE PATENT OWNERS FOR SUCH USE.IN NO EVENT SHALL THE ORIGINAL DEVELOPER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.This copyright, license and warranty information notice must be retained in all copies and derivative works of the Software or substantial portions thereof.*/#include <string.h>#include "nccglob.h"#include "globals.h"#include "bitbuffer.h"#include "vld.h"#include "framebuffer.h"#include "avcdecoder.h"#include "parameterset.h"#include "loopfilter.h"#include "dpb.h"#include "sequence.h"#ifdef ERROR_CONCEALMENT#include "sei.h"#include "errorconcealment.h"#endif#define SEQ_OK                      0#define SEQ_ERROR                  -1#define SEQ_ERR_MEM                -2#define SEQ_ERR_GAPS_IN_FRAME_NUM  -3#define SEQ_ERR_DPB_CORRUPTED      -4/* * Definitions of NAL types */#define NAL_TYPE_UNSPECIFIED      0#define NAL_TYPE_CODED_SLICE      1#define NAL_TYPE_CODED_SLICE_P_A  2#define NAL_TYPE_CODED_SLICE_P_B  3#define NAL_TYPE_CODED_SLICE_P_C  4#define NAL_TYPE_CODED_SLICE_IDR  5#define NAL_TYPE_SEI              6#define NAL_TYPE_SPS              7#define NAL_TYPE_PPS              8#define NAL_TYPE_PIC_DELIMITER    9#define NAL_TYPE_END_SEQ          10#define NAL_TYPE_END_STREAM       11#define NAL_TYPE_FILLER_DATA      12/*  * Definitions of SEI types */#define SEI_TYPE_SCENE_INFO       9/* The number of AVC levels */#define NUM_LEVELS  15/* These fields are defined in Annex A of the standard */typedef struct _level_s {  int levelNumber;  int32 maxMBPS;  int32 maxFS;  int32 maxDPB;  int32 maxBR;  int32 maxCPB;  int maxVmvR;  int minCR;  int maxMvsPer2Mb;} level_s;/* Parameters for all levels */static const level_s levelArray[NUM_LEVELS] = {  {10,   1485,    99,   152064,     64,    175,  64, 2, 32},  {11,   3000,   396,   345600,    192,    500, 128, 2, 32},  {12,   6000,   396,   912384,    384,   1000, 128, 2, 32},  {13,  11880,   396,   912384,    768,   2000, 128, 2, 32},  {20,  11880,   396,   912384,   2000,   2000, 128, 2, 32},  {21,  19800,   792,  1824768,   4000,   4000, 256, 2, 32},  {22,  20250,  1620,  3110400,   4000,   4000, 256, 2, 32},  {30,  40500,  1620,  3110400,  10000,  10000, 256, 2, 32},  {31, 108000,  3600,  6912000,  14000,  14000, 512, 4, 16},  {32, 216000,  5120,  7864320,  20000,  20000, 512, 4, 16},  {40, 245760,  8192, 12582912,  20000,  25000, 512, 4, 16},  {41, 245760,  8192, 12582912,  50000,  62500, 512, 2, 16},  {42, 491520,  8192, 12582912,  50000,  62500, 512, 2, 16},  {50, 589824, 22080, 42393600, 135000, 135000, 512, 2, 16},  {51, 983040, 36864, 70778880, 240000, 240000, 512, 2, 16}};#ifdef CHECK_MV_RANGEint maxVerticalMvRange;#endif/* * getLevel: * * Parameters: *      levelNumber         Level number * * Function: *      Return parameters for level based on level number. * *  Return: *      Pointer to level or 0 if level does not exist */static const level_s *getLevel(int levelNumber){  int i;  for (i = 0; i < NUM_LEVELS; i++) {    if (levelArray[i].levelNumber == levelNumber)      return &levelArray[i];  }  deb1f(stderr, "Unknown level: %i.\n", levelNumber);  return 0;}/* * setLower4Bits: * * Parameters: *      value               the destination to store the 4 bits *      bits                the 4 bits to be copied * * Function: *      Assign the value to the lowest 4 bits * *  Return: *      - */#define setLower4Bits(value, bits) (value) = ((value) & ~0xF) | ((bits))/* * * avcdOpen: * * Parameters: *      - * * Function: *      Open AVC decoder. *       * Returns: *      Pointer to initialized avcdDecoder_t object */avcdDecoder_t *avcdOpen(int ecAlg){  sequence_s *seq;  /*   * Allocate sequence object   */  if ((seq = (sequence_s *)nccMalloc(sizeof(sequence_s))) == NULL)    return NULL;  memset(seq, 0, sizeof(sequence_s));  seq->isFirstSliceOfSeq       = 1;  seq->unusedShortTermFrameNum = -1;#ifdef DECODE_ACCESS_UNITS  seq->decResult = AVCD_OK;#endif  /*   * Open slices   */  if ((seq->currSlice = sliceOpen()) == NULL)    return NULL;  if ((seq->nextSlice = sliceOpen()) == NULL)    return NULL;  /*   * Open dpb   */  if ((seq->dpb = dpbOpen()) == NULL)    return NULL;  /*   * Open bitbuffer   */  if ((seq->bitbuf = bibOpen()) == NULL)    return NULL;#ifdef ERROR_CONCEALMENT  /*    * Open scene info SEI   */  if ((seq->currSceneInfo = seiSceneOpen()) == NULL)    return NULL;  if ((seq->prevSceneInfo = seiSceneOpen()) == NULL)    return NULL;  seq->hasSceneInfo = 0;  seq->sceneInfoDecoded = 0;    /* Select the error concealment alg. */  seq->ecAlg = ecAlg;  #endif   return seq;}/* * * avcdClose: * * Parameters: *      seq                   Sequence object * * Function: *      Close sequence. *       * Returns: *      - */void avcdClose(avcdDecoder_t *dec){  sequence_s *seq = (sequence_s *)dec;  /* Close current frame */  frmClose(seq->recoBuf, seq->mbData);  /* Close decoded picture buffer */  dpbClose(seq->dpb);  /* Close bitbuffer */  bibClose(seq->bitbuf);  /* Close parameter sets */  psCloseParametersSets(seq->spsList, seq->ppsList);  /* Close slices */  sliceClose(seq->currSlice);  sliceClose(seq->nextSlice);#ifdef ERROR_CONCEALMENT  /* Close SEIs */  seiSceneClose(seq->currSceneInfo);  seiSceneClose(seq->prevSceneInfo);#endif  nccFree(seq);}/* * * slidingWindowDecRefPicMarking: * * Parameters: *      seq                   Sequence object * * Function: *      Sliding window decoded reference picture marking. Reference pictures *      in dpb are marked based on first in first out principle. *       * Returns: *      SEQ_OK for no error, negative value for error */static int slidingWindowDecRefPicMarking(sequence_s *seq){  dpb_s *dpb;  int numRefPics;  dpb = seq->dpb;  numRefPics = dpb->numShortTermPics + dpb->numLongTermPics;  /* If dpb contains maximum number of reference pitures allowed, short */  /*  term reference picture with lowest picture number is removed.     */  if (numRefPics == dpb->maxNumRefFrames) {    if (dpb->numShortTermPics == 0) {      deb0f(stderr, "numShortTerm must be greater than zero\n");      return SEQ_ERR_DPB_CORRUPTED;    }    dpbMarkLowestShortTermPicAsNonRef(dpb);  }  return SEQ_OK;}/* * * adaptiveDecRefPicMarking: * * Parameters: *      seq                   Sequence object * * Function: *      Adaptive decoded reference picture marking. Reference pictures in dpb *      are marked based on memory management command operations that were *      decoded in slice header earlier. *       * Returns: *      SEQ_OK for no error, SEQ_ERR_DPB_CORRUPTED for error in DPB */static int adaptiveDecRefPicMarking(sequence_s *seq){  dpb_s *dpb;  sliceMMCO_s *mmcoCmdList;  int32 currPicNum, picNumX;  int i;  dpb = seq->dpb;  currPicNum = seq->currSlice->frame_num;  mmcoCmdList = seq->currSlice->mmcoCmdList;  i = 0;  do {    switch (mmcoCmdList[i].memory_management_control_operation) {      case 1:        picNumX = currPicNum - (mmcoCmdList[i].difference_of_pic_nums_minus1 + 1);        if (dpbMarkShortTermPicAsNonRef(dpb, picNumX) < 0)          return SEQ_ERR_DPB_CORRUPTED;        break;      case 2:        if (dpbMarkLongTermPicAsNonRef(dpb, mmcoCmdList[i].long_term_pic_num) < 0)          return SEQ_ERR_DPB_CORRUPTED;        break;      case 3:        picNumX = currPicNum - (mmcoCmdList[i].difference_of_pic_nums_minus1 + 1);        if (dpbMarkShortTermPicAsLongTerm(dpb, picNumX, mmcoCmdList[i].long_term_frame_idx) < 0)          return SEQ_ERR_DPB_CORRUPTED;        break;      case 4:        dpbSetMaxLongTermFrameIdx(dpb, mmcoCmdList[i].max_long_term_frame_idx_plus1);        break;      case 5:        dpbMarkAllPicsAsNonRef(dpb);        dpb->maxLongTermFrameIdx = -1;        break;      case 6:        /* To avoid duplicate of longTermFrmIdx */        dpbVerifyLongTermFrmIdx(dpb, mmcoCmdList[i].long_term_frame_idx);        seq->recoBuf->refType        = FRM_LONG_TERM_PIC;        seq->recoBuf->longTermFrmIdx = mmcoCmdList[i].long_term_frame_idx;        break;    }    i++;  } while (mmcoCmdList[i].memory_management_control_operation != 0 && i < MAX_NUM_OF_MMCO_OPS);  return SEQ_OK;}/* * * decRefPicMarking: * * Parameters: *      seq                   Sequence object * * Function: *      Decoded reference picture marking. Reference pictures in dpb are marked *      differently depending on whether current picture is IDR picture or not *      and whether it is reference picture or non-reference picture. *      If current picture is non-IDR reference picture, reference pictures are *      marked with either sliding window marking process or adaptive marking *      process depending on the adaptiveRefPicMarkingModeFlag flag. *       * Returns: *      - */static int decRefPicMarking(sequence_s *seq){  slice_s *slice;  frmBuf_s *recoBuf;  slice = seq->currSlice;  recoBuf = seq->recoBuf;  recoBuf->refType  = FRM_SHORT_TERM_PIC;  recoBuf->frameNum = slice->frame_num;  recoBuf->hasMMCO5 = slice->picHasMMCO5;  recoBuf->isIDR    = slice->isIDR;  if (slice->isIDR) {    recoBuf->idrPicID = slice->idr_pic_id;    /* All reference frames are marked as non-reference frames */    dpbMarkAllPicsAsNonRef(seq->dpb);    /* Set reference type for current picture */    if (!slice->long_term_reference_flag) {      seq->dpb->maxLongTermFrameIdx = -1;    }    else {      recoBuf->refType         = FRM_LONG_TERM_PIC;      recoBuf->longTermFrmIdx  = 0;      seq->dpb->maxLongTermFrameIdx = 0;    }  }  else if (slice->nalRefIdc != 0) {    if (!slice->adaptive_ref_pic_marking_mode_flag)      return slidingWindowDecRefPicMarking(seq);    else      return adaptiveDecRefPicMarking(seq);  }  else    recoBuf->refType  = FRM_NON_REF_PIC;  return SEQ_OK;} /* * * buildSliceGroups: * * Parameters: *      seq                   Sequence object *      slice                 Slice object *      sps                   Sequence parameter set *      pps                   Picture parameter set * * Function: *      Build slice group map. Syntax elements for slice groups are *      in active picture parameter set. *       * Returns: *      - * */static void buildSliceGroups(sequence_s* seq, slice_s *slice,                             seq_parameter_set_s *sps, pic_parameter_set_s *pps){  int xTopLeft, yTopLeft;  int xBottomRight, yBottomRight;  int x, y;  int leftBound, topBound;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -