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

📄 marker2.c

📁 h261协议的h261编码码,lib_261.h里面提供了详细的接口和说明.
💻 C
字号:
/*************************************************************
Copyright (C) 1990, 1991, 1993 Andy C. Hung, all rights reserved.
PUBLIC DOMAIN LICENSE: Stanford University Portable Video Research
Group. If you use this software, you agree to the following: This
program package is purely experimental, and is licensed "as is".
Permission is granted to use, modify, and distribute this program
without charge for any purpose, provided this license/ disclaimer
notice appears in the copies.  No warranty or maintenance is given,
either expressed or implied.  In no event shall the author(s) be
liable to you or a third party for any special, incidental,
consequential, or other damages, arising out of the use or inability
to use the program for any purpose (or the loss of data), even if we
have been advised of such possibilities.  Any public reference or
advertisement of this source code should refer to it as the Portable
Video Research Group (PVRG) code, and not by any author(s) (or
Stanford University) name.
*************************************************************/
/*
************************************************************
marker.c

This file contains most of the marker information.

************************************************************
*/

/*LABEL marker.c */

#include <stdlib.h>
#include "globals2.h"
#include "marker2.h"

/*PUBLIC*/

//extern void WritePictureHeader_en();
extern void ReadPictureHeader2();
//extern void WriteGOBHeader_en();
extern int ReadHeaderHeader2();
extern void ReadHeaderTrailer2();
extern void ReadGOBHeader2();
//extern void WriteMBHeader_en();
extern int ReadMBHeader2();

/*PRIVATE*/

extern int TemporalReference2;
extern int PType2;
extern int Type22;
extern int MType2;
extern int GQuant2;
extern int MQuant2;
extern int MVDH2;
extern int MVDV2;
extern int CBP2;
extern int ParityEnable2;
extern int PSpareEnable2;
extern int GSpareEnable2;
extern int Parity2;
extern int PSpare2;
extern int GSpare2;
extern int GRead2;
extern int MBA2;
extern int LastMBA2;

extern int LastMVDV2;
extern int LastMVDH2;

extern int LastMType2;

extern int QuantMType2[];
extern int CBPMType2[];
extern int MFMType2[];


extern FSTORE *CFS2;

extern int bit_set_mask2[];
extern int extend_mask2[];

extern DHUFF *MBADHuff2;
extern DHUFF *MVDDHuff2;
extern DHUFF *CBPDHuff2;
extern DHUFF *T3DHuff2;

extern EHUFF *MBAEHuff2;
extern EHUFF *MVDEHuff2;
extern EHUFF *CBPEHuff2;
extern EHUFF *T3EHuff2;

extern int NumberBitsCoded2;

int MacroAttributeBits2=0;
int MotionVectorBits2=0;

/*START*/
/*BFUNC

WritePictureHeader_en() writes the header of picture out to the stream.
One of these is necessary before every frame is transmitted.

EFUNC*/

//void WritePictureHeader_en()
//{
//  BEGIN("WritePictureHeader_en");
//
//  mputv_en(PSC_LENGTH,PSC);
//  mputv_en(5,TemporalReference2);
////#ifdef VERSION_1_0
////  mputv_en(13,PType2);
////  if (ParityEnable2)
////    {
////      mputb_en(1);
////      mputv_en(8,ParityFS(CFS2));
////    }
////  else
////    mputb_en(0);  /* No Parity2 */
////  if (PSpareEnable2)
////    {
////      mputb_en(1);
////      mputv_en(16,PSpare2);
////    }
////  else
////    mputb_en(0);  /* No Spare */
////#else
//  mputv_en(6,PType2);
//  if (PSpareEnable2)
//    {
//      mputb_en(1);
//      mputv_en(8,PSpare2);
//    }
//  mputb_en(0);  /* No Spare */
////#endif
//}

/*BFUNC

ReadPictureHeader2() reads the header off of the stream. It assumes
that the first PSC has already been read in. (Necessary to tell the
difference between a new picture and another GOB.)

EFUNC*/

void ReadPictureHeader2()
{
  BEGIN("ReadPictureHeader2");

  TemporalReference2 = mgetv2(5);

//#ifdef VERSION_1_0
//  PType2 = mgetv2(13);
//  if (mgetb2())
//    {
//      ParityEnable2 = 1;
//      Parity2 = mgetv2(8);
//    }
//  else
//    ParityEnable2 = 0;
//  if (mgetb2())
//    {
//      PSpareEnable2=1;
//      PSpare2 = mgetv2(16);
//    }
//  else
//    PSpareEnable2 = 0;
//#else
  PType2 = mgetv2(6);
  for(PSpareEnable2 = 0;mgetb2();)
    {
      PSpareEnable2=1;
      PSpare2 = mgetv2(8);
    }
//#endif
}

/*BFUNC

WriteGOBHeader_en() writes a GOB out to the stream.

EFUNC*/

//void WriteGOBHeader_en()
//{
//  BEGIN("WriteGOBHeader_en");
//
//  mputv_en(GBSC_LENGTH,GBSC);
//  mputv_en(4,GRead2+1);
////#ifdef VERSION_1_0
////  mputv_en(6,Type22);
////#endif
//  mputv_en(5,GQuant2);
////#ifdef VERSION_1_0
////  if (GSpareEnable2)
////    {
////      mputb_en(1);
////      mputv_en(16,GSpare2);
////    }
////  else
////    mputb_en(0);
////#else
//  if (GSpareEnable2)
//    {
//      mputb_en(1);
//      mputv_en(8,GSpare2);
//    }
//  mputb_en(0);
////#endif
//}

/*BFUNC

ReadHeaderTrailer2() reads the trailer of the PSC or GBSC code. It is
used to determine whether it is just a GOB or a new picture.

EFUNC*/

void ReadHeaderTrailer2()
{
  BEGIN("ReadHeaderTrailer2");

  GRead2 = mgetv2(4)-1;
}

/*BFUNC

ReadHeaderHeader2() reads the header header off of the stream. This is
a precursor to the GOB read or the PSC read. It returns -1 on error.

EFUNC*/

int ReadHeaderHeader2()
{
  BEGIN("ReadHeaderHeader2");
  int input;

  if ((input = mgetv2(GBSC_LENGTH)) != GBSC)
    {
      if (seof2()==0)
	{
	  WHEREAMI();
	  printf("Illegal GOB Start Code. Read: %d\n",input);
	}
      return(-1);
    }
  return(0);
}


/*BFUNC

ReadGOBHeader2() reads the GOB information off of the stream. We assume
that the first bits have been read in by ReadHeaderHeader2... or some
such routine.

EFUNC*/

void ReadGOBHeader2()
{
	BEGIN("ReadGOBHeader2");
    
//#ifdef VERSION_1_0
//	Type22 = mgetv2(6);
//#endif
	GQuant2 = mgetv2(5);

//#ifdef VERSION_1_0
//	if (mgetb2())
//	{
//		GSpareEnable2 = 1;
//		GSpare2 = mgetv2(16);
//	}
//	else
//		GSpareEnable2=0;
//#else
	for(GSpareEnable2=0;mgetb2();)
	{
		GSpareEnable2 = 1;
        
		GSpare2 = mgetv2(8);
	}
//#endif
}

/*BFUNC

WriteMBHeader_en() writes a macro-block out to the stream.

EFUNC*/

//void WriteMBHeader_en()
//{
//  BEGIN("WriteMBHeader_en");
//  int TempH,TempV,Start;
//  
//  Start=swtell_en();
//  if (!Encode_en(MBA2,MBAEHuff2))
//    {
//      WHEREAMI();
//      printf("Attempting to write an empty Huffman code.\n");
//      exit(ERROR_HUFFMAN_ENCODE);
//    }
//  if (!Encode_en(MType2,T3EHuff2))
//    {
//      WHEREAMI();
//      printf("Attempting to write an empty Huffman code.\n");
//      exit(ERROR_HUFFMAN_ENCODE);
//    }
//  if (QuantMType2[MType2])
//    mputv_en(5,MQuant2);
//
//  NumberBitsCoded2=0;
//  if (MFMType2[MType2])
//    {
//      if ((!MFMType2[LastMType2])||(MBA2!=1)||
//	  (LastMBA2==-1)||(LastMBA2==10)||(LastMBA2==21))
//	{
//	  if (!Encode_en(MVDH2&0x1f,MVDEHuff2)||
//	       !Encode_en(MVDV2&0x1f,MVDEHuff2))
//	    {
//	      WHEREAMI();
//	      printf("Cannot encode motion vectors.\n");
//	    }
//	}
//      else
//	{
//	  TempH = MVDH2 - LastMVDH2;
//	  if (TempH < -16) TempH += 32;
//	  if (TempH > 15) TempH -= 32;
//	  TempV = MVDV2 - LastMVDV2;
//	  if (TempV < -16) TempV += 32;
//	  if (TempV > 15) TempV -= 32;
//	  if (!Encode_en(TempH&0x1f,MVDEHuff2)||!Encode_en(TempV&0x1f,MVDEHuff2))
//	    {
//	      WHEREAMI();
//	      printf("Cannot encode motion vectors.\n");
//	    }
//	}
//      LastMVDV2 = MVDV2;
//      LastMVDH2 = MVDH2;
//    }
//  else
//    {
//      LastMVDV2=LastMVDH2=MVDV2=MVDH2=0; /* Redundant in most cases */
//    }
//
//  MotionVectorBits2+=NumberBitsCoded2;
//  if (CBPMType2[MType2])
//    {
//      if (!Encode_en(CBP2,CBPEHuff2))
//	{
//	  WHEREAMI();
//	  printf("CBP2 write error\n");
//	  exit(-1);
//	}
//    }
//  MacroAttributeBits2+=(swtell_en()-Start);
//}

/*BFUNC

ReadMBHeader2() reads the macroblock header from the stream.

EFUNC*/

int ReadMBHeader2()
{
  BEGIN("ReadMBHeader2");
  int ReadMVDH,ReadMVDV;

  do
    {
      MBA2 = Decode2(MBADHuff2);
	  //printf("MBA2 = %d\n",MBA2);
    }
  while(MBA2 == 34);  /* Get rid of stuff bits */
  if (MBA2 == 35) return(-1); /* Start of Picture Headers */

  LastMType2 = MType2;
  MType2 = Decode2(T3DHuff2);
  if (QuantMType2[MType2])
    MQuant2 = mgetv2(5);
  if (MFMType2[MType2])
    {
      if ((!MFMType2[LastMType2])||(MBA2!=1)||
	  (LastMBA2==-1)||(LastMBA2==10)||(LastMBA2==21))
	  {
	    MVDH2 = Decode2(MVDDHuff2);
	    if (MVDH2 & bit_set_mask2[4])
	      MVDH2 |= extend_mask2[4];
	    MVDV2 = Decode2(MVDDHuff2);
	    if (MVDV2 & bit_set_mask2[4])
	      MVDV2 |= extend_mask2[4];
	  }
      else
	{
	  ReadMVDH = Decode2(MVDDHuff2);
	  if (ReadMVDH & bit_set_mask2[4])
	    ReadMVDH |= extend_mask2[4];
	  MVDH2 += ReadMVDH;
	  
	  ReadMVDV = Decode2(MVDDHuff2);
	  if (ReadMVDV & bit_set_mask2[4])
	    ReadMVDV |= extend_mask2[4];
	  MVDV2 += ReadMVDV;

	  if (MVDH2 < -16) MVDH2 += 32;
	  if (MVDH2 > 15) MVDH2 -= 32;
	  if (MVDV2 < -16) MVDV2 += 32;
	  if (MVDV2 > 15) MVDV2 -= 32;
	}
    }
  else
    {
      MVDV2=MVDH2=0;  /* Theoretically redundant */
    }
  if (CBPMType2[MType2])
    CBP2 = Decode2(CBPDHuff2);
  return(0);
}

/*END*/

⌨️ 快捷键说明

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