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

📄 decodeiff.c

📁 jm61 的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
  bitptr += sym.len;

  sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length );
  sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
  pp->pictureID = sym.value1;
  currSlice->picture_id = img->tr = sym.value1;
  buf->frame_bitoffset += sym.len;
  bitptr += sym.len;

  sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length );
  sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
  pp->sliceType = sym.value1;
  switch (sym.value1)
  {
  //! Potential BUG: do we need to distinguish between INTER_IMG_MULT and INTER_IMG?
  //!    similar with B_IMG_! and B_IMG_MULT
  //! also: need to define Slice types for SP images
  //! see VCEG-N72r1 for the Slice types, which are mapped here to img->type
  case 0:
    img->type = INTER_IMG;
    break;
  case 1:
    img->type = B_IMG;
    break;
  case 2:
    img->type = SP_IMG;
    break;
  case 3:
    img->type = currSlice->picture_type = INTRA_IMG;
    break;
  case 4:
    img->type = currSlice->picture_type = SI_IMG;
  default:
    printf ("Panic: unknown Slice type %d, conceal by loosing slice\n", pp->sliceType);
    currSlice->ei_flag = 1;
  }  
  buf->frame_bitoffset += sym.len;
  bitptr += sym.len;

  sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
  sym.mapping(sym.len, sym.inf, &(img->disposable_flag), &(sym.value2));
  buf->frame_bitoffset += sym.len;
  bitptr+=sym.len;

  if(img->type==INTER_IMG)
  {
    sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
    sym.mapping(sym.len, sym.inf, &(img->num_ref_pic_active_fwd), &(sym.value2));
    buf->frame_bitoffset += sym.len;
    bitptr+=sym.len;
    img->num_ref_pic_active_fwd++;
  }
  else if(img->type==B_IMG)
  {
 
    sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
    sym.mapping(sym.len, sym.inf, &(img->num_ref_pic_active_fwd), &(sym.value2));
    buf->frame_bitoffset += sym.len;
    bitptr+=sym.len;
    img->num_ref_pic_active_fwd++;

    sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
    sym.mapping(sym.len, sym.inf, &(img->num_ref_pic_active_bwd), &(sym.value2));
    buf->frame_bitoffset += sym.len;
    bitptr+=sym.len;
    img->num_ref_pic_active_bwd++;
  }

  if (img->type <= INTRA_IMG || img->type >= SP_IMG || !img->disposable_flag) 
  {
    if (img->structure == FRAME)
    {     
      if(img->tr <last_imgtr_frm) 
        modulo_ctr_frm++;
      
      last_imgtr_frm = img->tr;
      img->tr_frm = img->tr + (256*modulo_ctr_frm);
    }
    else
    {
      if(img->tr <last_imgtr_fld) 
        modulo_ctr_fld++;
      
      last_imgtr_fld = img->tr;
      img->tr_fld = img->tr + (256*modulo_ctr_fld);
    }
  }
  else
  {
    if (img->structure == FRAME)
    {     
      if(img->tr <last_imgtr_frm_b) 
        modulo_ctr_frm_b++;
      
      last_imgtr_frm_b = img->tr;
      img->tr_frm = img->tr + (256*modulo_ctr_frm_b);
    }
    else
    {
      if(img->tr <last_imgtr_fld_b) 
        modulo_ctr_fld_b++;
      
      last_imgtr_fld_b = img->tr;
      img->tr_fld = img->tr + (256*modulo_ctr_fld_b);
    }
  }
  if(img->type != B_IMG) {
    img->pstruct_next_P = img->structure;
    if(img->structure == TOP_FIELD)
    {
      img->imgtr_last_P = img->imgtr_next_P;
      img->imgtr_next_P = img->tr_fld;
    }
    else if(img->structure == FRAME)
    {
      img->imgtr_last_P = img->imgtr_next_P;
      img->imgtr_next_P = 2*img->tr_frm;
    }
  }
  
  if(img->type==B_IMG)
  {
    if(img->disposable_flag==0) 
    {
      if(img->structure == TOP_FIELD)
      {
        img->imgtr_last_P = img->imgtr_next_P;
        img->imgtr_next_P = img->tr_fld;
      }
      else if(img->structure == FRAME)
      {
        img->imgtr_last_P = img->imgtr_next_P;
        img->imgtr_next_P = 2*img->tr_frm;
      }
    }
  }

  img->mb_frame_field_flag = 0;

  if (img->structure == 3)
    img->mb_frame_field_flag = 1;

  sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length );
  sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
  pp->firstMBInSliceX = sym.value1;
  buf->frame_bitoffset += sym.len;
  bitptr += sym.len;

  sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length );
  sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
  pp->firstMBInSliceY = sym.value1;
  buf->frame_bitoffset += sym.len;
  bitptr += sym.len;

  currSlice->start_mb_nr = pp->firstMBInSliceY * box_ps.pictureWidthInMBs + pp->firstMBInSliceX;
  
  if ( img->type == B_IMG)
  {
    sym.len = GetfixedSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length,1 );
    img->direct_type= pp->directType = sym.inf ;
    buf->frame_bitoffset += sym.len;
    bitptr += sym.len;
  }
  


  sym.mapping = linfo_dquant;
  sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length );
  sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
  pp->initialQP = sym.value1 + (MAX_QP - MIN_QP + 1)/2;
  currSlice->qp = img->qp = pp->initialQP;
  buf->frame_bitoffset += sym.len;
  bitptr += sym.len;
  if ( img->type == SP_IMG || img->type == SI_IMG)
  {
    if ( img->type != SI_IMG )
    {
      sym.len = GetfixedSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length,1 );
      img->sp_switch=sym.inf ;
      buf->frame_bitoffset += sym.len;
      bitptr += sym.len;
    }
    sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length );
    sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
    img->qpsp = sym.value1 + (MAX_QP - MIN_QP + 1)/2;
    buf->frame_bitoffset += sym.len;
    bitptr += sym.len;
  }

  if (inp->LFParametersFlag)
  {
    sym.len = GetfixedSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length,1 );
    currSlice->LFDisableIdc = sym.inf;
    buf->frame_bitoffset += sym.len;
    bitptr+=1;

    if (!currSlice->LFDisableIdc)
    {
      sym.mapping = linfo_dquant;
      sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length );
      sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
      currSlice->LFAlphaC0Offset = sym.value1 << 1;
      buf->frame_bitoffset += sym.len;
      bitptr+=sym.len;

      sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &sym.inf, buf->bitstream_length );
      sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
      currSlice->LFBetaOffset = sym.value1 << 1;
      buf->frame_bitoffset += sym.len;
      bitptr+=sym.len;
    }
  }

  sym.mapping = linfo;        // Mapping rule: Simple code number to len/info
  // Multi-Picture Buffering Syntax, Feb 27, 2002
  // RPSF: Reference Picture Selection Flags
  sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
  sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
  buf->frame_bitoffset += sym.len;
  bitptr+=sym.len;

  // PN: Picture Number
  sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
  sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
  buf->frame_bitoffset += sym.len;
  bitptr+=sym.len;
  img->pn=sym.value1;

  // Tian Dong: payloadType 8 is IDERP packet, in which PN is reset,
  // so a PN gap is expected. Be sure not try to fill such a gap.
  if ( pp->payloadType != PAYLOAD_TYPE_IDERP ) fill_PN_gap(img);
  // Tian Dong: The following condition will ensure the buffer reset will
  // not be done before the successive B frames are decoded.
  if ( pp->payloadType == PAYLOAD_TYPE_IDERP && fb != NULL && frm != NULL )
  {
    reset_buffers();
    frm->picbuf_short[0]->used=0;
    frm->picbuf_short[0]->picID=-1;
    frm->picbuf_short[0]->lt_picID=-1;
    frm->short_used=0;
  }

  // RPSL: Reference picture selection layer
  sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
  sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
  buf->frame_bitoffset += sym.len;
  bitptr+=sym.len;

  if (sym.value1)
  {
    // read Reference Picture Selection Layer
    // free old buffer content
    while (img->currentSlice->rmpni_buffer)
    { 
      tmp_rmpni=img->currentSlice->rmpni_buffer;
 
      img->currentSlice->rmpni_buffer=tmp_rmpni->Next;
      free (tmp_rmpni);
    } 
    done=0;
    // if P or B frame RMPNI

    if ((img->type==INTER_IMG)||(img->type==B_IMG)||(img->type==SP_IMG))
    {
      do
      {
    
        sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
        sym.mapping(sym.len, sym.inf, &tmp1, &(sym.value2));
        buf->frame_bitoffset += sym.len;
        bitptr+=sym.len;


        // check for illegal values
        if ((tmp1<0)||(tmp1>3))
          error ("Invalid RMPNI operation specified",400);

        if (tmp1!=3)
        {
          tmp_rmpni=(RMPNIbuffer_t*)calloc (1,sizeof (RMPNIbuffer_t));
          tmp_rmpni->Next=NULL;
          tmp_rmpni->RMPNI=tmp1;

          // get the additional parameter
          sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
          sym.mapping(sym.len, sym.inf, &(tmp_rmpni->Data), &(sym.value2));
          buf->frame_bitoffset += sym.len;
          bitptr+=sym.len;

          // add RMPNI to list
          if (img->currentSlice->rmpni_buffer==NULL) 
          {
            img->currentSlice->rmpni_buffer=tmp_rmpni;
          }
          else
          {
            tmp_rmpni2=img->currentSlice->rmpni_buffer;
            while (tmp_rmpni2->Next!=NULL) 
              tmp_rmpni2=tmp_rmpni2->Next;
            tmp_rmpni2->Next=tmp_rmpni;
          }
        } else
        {
          // free temporary memory (no need to save end loop operation)
          done=1;
        }
      } while (!done);
    }
  }

  // RBPT 
  sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
  sym.mapping(sym.len, sym.inf, &(sym.value1), &(sym.value2));
  buf->frame_bitoffset += sym.len;
  bitptr+=sym.len;

  // free old buffer content
  while (img->mmco_buffer)
  { 
    tmp_mmco=img->mmco_buffer;

    img->mmco_buffer=tmp_mmco->Next;
    free (tmp_mmco);
  } 
  
  // read Memory Management Control Operation
  if (sym.value1)
  {
    // read Memory Management Control Operation 
    do
    {

      tmp_mmco=(MMCObuffer_t*)calloc (1,sizeof (MMCObuffer_t));
      tmp_mmco->Next=NULL;
    
      sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
      sym.mapping(sym.len, sym.inf, &(tmp_mmco->MMCO), &(sym.value2));
      buf->frame_bitoffset += sym.len;
      bitptr+=sym.len;

      switch (tmp_mmco->MMCO)
      {
      case 0:
      case 5:
        break;
      case 1:
        sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
        sym.mapping(sym.len, sym.inf, &(tmp_mmco->DPN), &(sym.value2));
        buf->frame_bitoffset += sym.len;
        bitptr+=sym.len;
        break;
      case 2:
        sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
        sym.mapping(sym.len, sym.inf, &(tmp_mmco->LPIN), &(sym.value2));
        buf->frame_bitoffset += sym.len;
        bitptr+=sym.len;
        break;
      case 3:
        sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
        sym.mapping(sym.len, sym.inf, &(tmp_mmco->DPN), &(sym.value2));
        buf->frame_bitoffset += sym.len;
        bitptr+=sym.len;
        sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
        sym.mapping(sym.len, sym.inf, &(tmp_mmco->LPIN), &(sym.value2));
        buf->frame_bitoffset += sym.len;
        bitptr+=sym.len;
        break;
      case 4:
        sym.len = GetVLCSymbol( buf->streamBuffer, buf->frame_bitoffset, &(sym.inf), buf->bitstream_length );
        sym.mapping(sym.len, sym.inf, &(tmp_mmco->MLIP1), &(sym.value2));
        buf->frame_bitoffset += sym.len;
        bitptr+=sym.len;
        break;
      default:
        error ("Invalid MMCO operation specified",400);
        break;
      }

      // add MMCO to list
      if (img->mmco_buffer==NULL) 
      {
        img->mmco_buffer=tmp_mmco;
      }
      else
      {
        tmp_mmco2=img->mmco_buffer;
        while (tmp_mmco2->Next!=NULL) tmp_mmco2=tmp_mmco2->Next;
        tmp_mmco2->Next=tmp_mmco;
      }
      
    }while (tmp_mmco->MMCO!=0);
  }
}

/*!
 ************************************************************************
 * \brief
 *      read the payload data
 * \return
 *      0, if success
 *      -1, otherwise
 * \param img
 *      image pointer
 * \param inp
 *      input parameter pointer
 * \param pp
 *      corresponding payloadinfo
 * \param fp
 *      input file pointer
 ************************************************************************
 */
int rdOnePayload( struct img_par *img, struct inp_par* inp, PayloadInfo *pp, FILE* fp )
{
  int *read_len;        
  Slice* currSlice = img->currentSlice;
  Bitstream* currStream = currSlice->partArr[0].bitstream;
  byte* buf = currStream->streamBuffer;
  DecodingEnvironmentPtr dep = &((currSlice->partArr[0]).de_cabac);

  currStream->frame_bitoffset = 0;
  currStream->code_len = 0;
  fseek( fp, box_atm.currPayloadOffset, SEEK_SET );
  memset( buf, 0, MAX_CODED_FRAME_SIZE );
  if ( pp->payloadSize == fread( buf, 1, (unsigned int)pp->payloadSize, fp ) )
  {
    currStream->bitstream_length = (int)pp->payloadSize;
    box_atm.currPayloadOffset += (long)pp->payloadSize;

⌨️ 快捷键说明

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