📄 rtp.c
字号:
}
}
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 == img->type==B_IMG)
{
img->direct_type=sh->Direct_type;
}
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->slice_group_change_cycle = sh->slice_group_change_cycle; //JVT-D097
}
/*!
*****************************************************************************
*
* \brief
* Function returns the next header type (SOS SOP, EOS)
* p-> and sh-> are filled. p-> does not need memory for payload and packet
*
* \return
*
* Side effects:
*
* \date
* 27 October, 2001
*
* \author
* Stephan Wenger stewe@cs.tu-berlin.de
*****************************************************************************/
int RTPGetFollowingSliceHeader (struct img_par *img, RTPpacket_t *p, RTPSliceHeader_t *sh)
{
long int Filepos;
int TotalPackLen;
int done=0;
int intime=0;
Slice *currSlice = img->currentSlice;
// static unsigned int old_seq=0; // avoid warnings. mwi
// static int first=0; // avoid warnings. mwi
// static int i=2; // avoid warnings. mwi
RTPpacket_t *newp, *nextp;
RTPSliceHeader_t *nextsh;
assert (p != NULL);
assert (sh != NULL);
newp = alloca (sizeof (RTPpacket_t));
newp->packet = alloca (MAXRTPPACKETSIZE);
newp->payload = alloca(MAXRTPPAYLOADLEN);
nextp=alloca (sizeof (RTPpacket_t));
nextsh=alloca(sizeof (RTPSliceHeader_t));
Filepos = ftell (bits);
while (!done)
{
if (4 != fread (&TotalPackLen,1, 4, bits))
{
fseek (bits, Filepos, SEEK_SET);
return EOS; // EOF inidication
}
if (4 != fread (&intime, 1, 4, bits))
{
fseek (bits, Filepos, SEEK_SET);
printf ("RTPGetFollowingSliceHeader: File corruption, could not read Timestamp\n");
return EOS;
}
newp->packlen = TotalPackLen;
assert (newp->packlen < MAXRTPPACKETSIZE);
if (newp->packlen != fread (newp->packet, 1, newp->packlen, bits))
{
fseek (bits, Filepos, SEEK_SET);
return EOS; // EOF inidication
}
DecomposeRTPpacket (newp);
if (newp->payload [0] == 0 || newp->payload[0] == 1) // Full Slice or Partition A
done = 1;
}
fseek (bits, Filepos, SEEK_SET);
p->cc = newp->cc;
p->m = newp->m;
p->p = newp->p;
p->pt = newp->pt;
p->seq = newp->seq;
p->ssrc = newp->ssrc;
p->timestamp = newp->timestamp;
p->v = newp->v;
p->x = newp->x;
//! This code fragment made the assumtion of a fixed frame rate with no fixed frames
//! It is commented out, because I believe that such an assumption is unrealistic in
//! real world environments, and the resulting gains in error concealment quality
//! should not be part of the reference code. I don't believe it does do much harm
//! to keep it from a functional point-of-view. StW, 06.07.02
/*
if (p->seq != old_seq+i)
currSlice->next_eiflag =1;
else
{
currSlice->next_eiflag =0;
old_seq=p->seq;
}
if(!first)
{
first=1;
i=1;
}
*/
RTPInterpretSliceHeader (&newp->payload[1], newp->packlen, newp->payload[0]==0?0:1, sh, img);
if(currSlice->picture_id != sh->PictureID)
return (SOP);
else
return (SOS);
}
/*!
************************************************************************
* \brief
* Input file containing Partition structures
* \return
* TRUE if a startcode follows (meaning that all symbols are used). \n
* FALSE otherwise.
************************************************************************/
int RTP_startcode_follows(struct img_par *img, struct inp_par *inp)
{
Slice *currSlice = img->currentSlice;
int dp_Nr = assignSE2partition[currSlice->dp_mode][SE_MBTYPE];
DataPartition *dP = &(currSlice->partArr[dp_Nr]);
Bitstream *currStream = dP->bitstream;
byte *buf = currStream->streamBuffer;
int frame_bitoffset = currStream->frame_bitoffset;
int info;
assert (0==1);
// if (currStream->ei_flag)
// {
//printf ("ei_flag set, img->current_mb_nr %d, currSlice->last_mb_nr %d\n", img->current_mb_nr, currSlice->last_mb_nr);
// return (img->current_mb_nr == currSlice->last_mb_nr);
// }
// else
{
if (-1 == GetVLCSymbol (buf, frame_bitoffset, &info, currStream->bitstream_length))
return TRUE;
else
return FALSE;
}
}
/*!
************************************************************************
* \brief
* read next UVLC codeword from SLICE-partition and
* map the corresponding syntax element
* Add Errorconceilment if necessary
************************************************************************
*/
int readSyntaxElement_RTP(SyntaxElement *sym, struct img_par *img, struct inp_par *inp, struct datapartition *dP)
{
Bitstream *currStream = dP->bitstream;
if (RTP_symbols_available(currStream)) // check on existing elements in partition
{
RTP_get_symbol(img, inp, dP, sym, currStream);
}
else
{
set_ec_flag(sym->type); // otherwise set error concealment flag
}
get_concealed_element(sym);
sym->mapping(sym->len,sym->inf,&(sym->value1),&(sym->value2));
#if TRACE
tracebits(sym->tracestring, sym->len, sym->inf, sym->value1, sym->value2);
#endif
return 1;
}
/*!
************************************************************************
* \brief
* checks if thererare symbols to read in the
* appropriate partition
************************************************************************
*/
int RTP_symbols_available (Bitstream *currStream)
{
byte *buf = currStream->streamBuffer;
int frame_bitoffset = currStream->frame_bitoffset;
int info;
if (currStream->ei_flag) {
//printf ("RTP_symbols_available returns FALSE: ei_flag set\n");
return FALSE;
}
if (-1 == GetVLCSymbol (buf, frame_bitoffset, &info, currStream->bitstream_length))
{
//printf ("RTP_symbols_available returns FALSE, no more symbols\nframe_bitoffset %d, bitstream_length %d read_len %d\n", currStream->frame_bitoffset, currStream->bitstream_length, currStream->read_len);
return FALSE;
}
else
return TRUE;
};
/*!
************************************************************************
* \brief
* gets info and len of symbol
************************************************************************
*/
void RTP_get_symbol(struct img_par *img, struct inp_par *inp, struct datapartition *dP, SyntaxElement *sym, Bitstream *currStream)
{
int frame_bitoffset = currStream->frame_bitoffset;
byte *buf = currStream->streamBuffer;
int BitstreamLengthInBytes = currStream->bitstream_length;
sym->len = GetVLCSymbol (buf, frame_bitoffset, &(sym->inf), BitstreamLengthInBytes);
currStream->frame_bitoffset += sym->len;
}
/*!
************************************************************************
* \brief
* Interprets a parameter set packet
************************************************************************
*/
#define EXPECT_ATTR 0
#define EXPECT_PARSET_LIST 1
#define EXPECT_PARSET_NO 2
#define EXPECT_STRUCTNAME 3
#define EXPECT_STRUCTVAL_INT 4
#define EXPECT_STRUCTVAL_STRING 5
#define EXPECT_STRUCTVAL_INT_LIST 6
#define INTERPRET_COPY 100
#define INTERPRET_ENTROPY_CODING 101
#define INTERPRET_MOTION_RESOLUTION 102
#define INTERPRET_INTRA_PREDICTION 103
#define INTERPRET_PARTITIONING_TYPE 104
#define INTERPRET_FMOMAP 105
int RTPInterpretParameterSetPacket (char *buf, int buflen)
{
// The dumbest possible parser that updates the parameter set variables
// static to this module
int bufp = 0;
int state = EXPECT_ATTR;
int interpreter;
int minus, number;
int ps;
char s[MAX_PARAMETER_STRINGLEN];
void *destin;
while (bufp < buflen)
{
// printf ("%d\t%d\t %c%c%c%c%c%c%c%c ", bufp, state, buf[bufp], buf[bufp+1], buf[bufp+2], buf[bufp+3], buf[bufp+4], buf[bufp+5], buf[bufp+6], buf[bufp+7], buf[bufp+8], buf[bufp+9]);
switch (state)
{
case EXPECT_ATTR:
if (buf[bufp] == '\004') // Found UNIX EOF, this is the end marker
{
ParSet[ps].Valid = 1;
return 0;
}
if (strncmp ("a=H26L ", &buf[bufp], 7))
{
printf ("Parsing error EXPECT_ATTR in Header Packet: position %d, packet %s\n",
bufp, &buf[bufp]);
return -1;
}
bufp += 7;
state = EXPECT_PARSET_LIST;
break;
case EXPECT_PARSET_LIST:
if (buf[bufp] != '(')
{
printf ("Parsing error EXPECT_PARSET in Header Packet: position %d, packet %s\n",
bufp, &buf[bufp]);
return -2;
}
bufp++;
state = EXPECT_PARSET_NO;
break;
case EXPECT_PARSET_NO:
number = 0;
minus = 1;
if (buf[bufp] == '-')
{
minus = -1;
bufp++;
}
while (isdigit (buf[bufp]))
number = number * 10 + ( (int)buf[bufp++] - (int) '0');
if (buf[bufp] == ',')
{
printf ("Update of more than one prameter set not yet supported\n");
return -1;
}
if (buf[bufp] != ')')
{
printf ("Parsing error NO PARSET LISTEND in Header Packet: position %d, packet %s\n",
bufp, &buf[bufp]);
return -1;
}
if (minus > 0) // not negative
ps = number;
bufp+= 2; // skip ) and blank
state = EXPECT_STRUCTNAME;
break;
case EXPECT_STRUCTNAME:
if (1 != sscanf (&buf[bufp], "%100s", s)) // Note the 100, which si MAX_PARAMETER_STRLEN
{
printf ("Parsing error EXPECT STRUCTNAME STRING in Header packet: position %d, packet %s\n",
bufp, &buf[bufp]);
return -1;
}
bufp += strlen (s);
bufp++; // Skip the blank
if (!strncmp (s, "MaxPicID", MAX_PARAMETER_STRINGLEN))
{
state = EXPECT_STRUCTVAL_INT;
interpreter = INTERPRET_COPY;
destin = &ParSet[ps].MaxPicID;
break;
}
if (!strncmp (s, "BufCycle", MAX_PARAMETER_STRINGLEN))
{
state = EXPECT_STRUCTVAL_INT;
interpreter = INTERPRET_COPY;
destin = &ParSet[ps].BufCycle;
break;
}
if (!strncmp (s, "MaxPn", MAX_PARAMETER_STRINGLEN))
{
state = EXPECT_STRUCTVAL_INT;
interpreter = INTERPRET_COPY;
destin = &ParSet[ps].BufCycle;
break;
}
if (!strncmp (s, "UseMultpred", MAX_PARAMETER_STRINGLEN))
{
state = EXPECT_STRUCTVAL_INT;
interpreter = INTERPRET_COPY;
destin = &ParSet[ps].UseMultpred;
break;
}
if (!strncmp (s, "PixAspectRatioX", MAX_PARAMETER_STRINGLEN))
{
state = EXPECT_STRUCTVAL_INT;
interpreter = INTERPRET_COPY;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -