rtppkt.h

来自「symbian 下的helix player源代码」· C头文件 代码 · 共 689 行 · 第 1/2 页

H
689
字号
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: rtppkt.h,v 1.7.8.1 2004/07/09 02:04:29 hubbe Exp $
 * 
 * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL") in which case the provisions of the GPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the GPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the GPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the GPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the
 * portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */
#ifndef	PMC_PREDEFINED_TYPES
#define	PMC_PREDEFINED_TYPES

typedef char*	pmc_string;

struct buffer {
	 UINT32	len;
	 INT8*	data;
};
#endif/*PMC_PREDEFINED_TYPES*/


/* $Id: rtppkt.h,v 1.7.8.1 2004/07/09 02:04:29 hubbe Exp $ */

#ifndef _RTPPKT_H_
#define _RTPPKT_H_

// op-codes
const int RTP_OP_PACKETFLAGS = 1;   // opcode datalength = 1
const int RTP_OP_ASMRULES = 2;	    // packs asm_flags/asm_rule instead
				    // of op_code_data

// flags for opcode RTP_OP_PACKETFLAGS
const int RTP_FLAG_LASTPACKET = 0x00000001;	// last packet in stream
const int RTP_FLAG_KEYFRAME =   0x00000002;	// keyframe packet

// RTCP types
const int RTCP_SR 	= 200;
const int RTCP_RR 	= 201;
const int RTCP_SDES 	= 202;
const int RTCP_BYE 	= 203;
const int RTCP_APP 	= 204;

// SDES item types
const int SDES_CNAME	= 1;
const int SDES_NAME	= 2;
const int SDES_EMAIL	= 3;
const int SDES_PHONE	= 4;
const int SDES_LOC	= 5;
const int SDES_TOOL	= 6;
const int SDES_NOTE	= 7;
const int SDES_PRIV	= 8;

// APP tiem Types
const int APP_EOS	= 1;
const int APP_BUFINFO	= 2;

#include "bufnum.h"
#include "hxinline.h"

class RTPPacketBase
{
public:
    UINT8*	pack(UINT8* buf, UINT32 &len);
    UINT8*	unpack(UINT8* buf, UINT32 len);
    const UINT32	static_size() {return 20;}

    UINT8	version_flag;
    UINT8	padding_flag;
    UINT8	extension_flag;
    UINT8	csrc_len;
    UINT8	marker_flag;
    UINT8	payload;
    INT16	seq_no;
    INT32	timestamp;
    INT32	ssrc;
    INT32	*csrc;
    INT16	op_code;
    INT16	op_code_data_length;
    INT16	asm_flags;
    INT16	asm_rule;
    INT32	*op_code_data;
    buffer	data;
};

class ReceptionReport
{
public:
    UINT8*	pack(UINT8* buf, UINT32 &len);
    UINT8*	unpack(UINT8* buf, UINT32 len);
    static const UINT32	static_size() {return 24;}

    UINT32	ssrc;
    UINT8	fraction;
    UINT32	lost;
    UINT32	last_seq;
    UINT32	jitter;
    UINT32	lsr;
    UINT32	dlsr;
};

class SDESItem
{
public:
    UINT8*	pack(UINT8* buf, UINT32 &len);
    UINT8*	unpack(UINT8* buf, UINT32 len);
    const UINT32	static_size() {return 2;}

    UINT8	sdes_type;
    UINT8	length;
    UINT8	*data;
};

class APPItem
{
public:
    UINT8*	pack(UINT8* buf, UINT32 &len);
    UINT8*	unpack(UINT8* buf, UINT32 len);
    const UINT32	static_size() {return 23;}

    UINT8	app_type;
    UINT8	packet_sent;
    UINT16	seq_no;
    UINT32	timestamp;
    UINT32	lowest_timestamp;
    UINT32	highest_timestamp;
    UINT32	bytes_buffered;
    UINT32	padding0;
};

class RTCPPacketBase
{
public:
    UINT8*	pack(UINT8* buf, UINT32 &len);
    UINT8*	unpack(UINT8* buf, UINT32 len);
    const UINT32	static_size() {return 40;}

    UINT8	version_flag;
    UINT8	padding_flag;
    UINT8	count;
    UINT8	packet_type;
    UINT16	length;
    UINT32	sr_ssrc;
    UINT32	ntp_sec;
    UINT32	ntp_frac;
    UINT32	rtp_ts;
    UINT32	psent;
    UINT32	osent;
    ReceptionReport	*sr_data;
    UINT32	rr_ssrc;
    ReceptionReport	*rr_data;
    UINT8	*sdes_data;
    UINT32	*bye_src;
    UINT32	app_ssrc;
    UINT8	app_name[4];
    UINT8	*app_data;
};



#if defined (_DEFINE_INLINE)
HX_INLINE UINT8*
RTPPacketBase::pack(UINT8* buf, UINT32 &len)
{
    UINT8* off = buf;

    {
	*off &= ~0xc0; *off |= (version_flag&0x3)<<6;
    }
    {*off &= ~(1<<5); *off |= (padding_flag&1)<<5;}
    {*off &= ~(1<<4); *off |= (extension_flag&1)<<4;}
    {
	*off &= ~0xf; *off++ |= csrc_len&0xf;                       
    }
    {*off &= ~(1<<7); *off |= (marker_flag&1)<<7;}
    {
	*off &= ~0x7f; *off++ |= payload&0x7f;
    }
    {*off++ = (UINT8) (seq_no>>8); *off++ = (UINT8) (seq_no);}
    {
	*off++ = (UINT8) (timestamp>>24); *off++ = (UINT8) (timestamp>>16); *off++ = (UINT8) (timestamp>>8); *off++ = (UINT8) (timestamp);
    }
    {
	*off++ = (UINT8) (ssrc>>24); *off++ = (UINT8) (ssrc>>16); *off++ = (UINT8) (ssrc>>8); *off++ = (UINT8) (ssrc);
    }
    if ((csrc_len > 0))
    {
      {for (int i = 0;  i < csrc_len; i++)
	  {
	      *off++ = (UINT8) (csrc[i]>>24); *off++ = (UINT8) (csrc[i]>>16); *off++ = (UINT8) (csrc[i]>>8); *off++ = (UINT8) (csrc[i]);
	  }
      }
    }
    if ((extension_flag == 1))
    {
      {*off++ = (UINT8) (op_code>>8); *off++ = (UINT8) (op_code);}
      {*off++ = (UINT8) (op_code_data_length>>8); *off++ = (UINT8) (op_code_data_length);}
      if ((op_code == 2))
      {
	{*off++ = (UINT8) (asm_flags>>8); *off++ = (UINT8) (asm_flags);}
	{*off++ = (UINT8) (asm_rule>>8); *off++ = (UINT8) (asm_rule);}
      }
      else
      {
	{for (int i = 0;  i < op_code_data_length; i++)
	    {
		*off++ = (UINT8) (op_code_data[i]>>24); *off++ = (UINT8) (op_code_data[i]>>16); *off++ = (UINT8) (op_code_data[i]>>8); *off++ = (UINT8) (op_code_data[i]);
	    }
	}
      }
    }
    {
	memcpy(off, data.data, data.len); off += data.len; /* Flawfinder: ignore */
    }
    len = off-buf;
    return off;
}

HX_INLINE UINT8*
RTPPacketBase::unpack(UINT8* buf, UINT32 len)
{
    if (!buf || !len)
	return 0;
    UINT8* off = buf;

    {
	version_flag  = (*off&0xc0)>>6;
    }
    padding_flag = (*off>>5)&1;
    extension_flag = (*off>>4)&1;
    {
	csrc_len  = *off++&0xf;
    }
    marker_flag = (*off>>7)&1;
    {
	payload  = *off++&0x7f;
    }
    {seq_no = *off++<<8; seq_no |= *off++;}
    {
	timestamp = GetDwordFromBufAndInc(off);
    }
    {
	ssrc = GetDwordFromBufAndInc(off);
    }
    if ((csrc_len > 0))
    {
      {
	  csrc = new INT32[csrc_len];
	  for (int i = 0;  i < csrc_len; i++)
	  {
	      csrc[i] = GetDwordFromBufAndInc(off);
	  }
      }
    }
    if ((extension_flag == 1))
    {
      {op_code = *off++<<8; op_code |= *off++;}
      {op_code_data_length = *off++<<8; op_code_data_length |= *off++;}
      if ((op_code == 2))
      {
	{asm_flags = *off++<<8; asm_flags |= *off++;}
	{asm_rule = *off++<<8; asm_rule |= *off++;}
      }
      else
      {
	{
	    op_code_data = new INT32[op_code_data_length];
	    for (int i = 0;  i < op_code_data_length; i++)
	    {
		op_code_data[i] = GetDwordFromBufAndInc(off);
	    }
	}
      }
    }
    {
	data.len = len - (off - buf);
	if (off-buf+data.len > (int)len)
	    return 0;
	data.data = (INT8 *)off; off += data.len;
    }
    return off;
}

HX_INLINE UINT8*
ReceptionReport::pack(UINT8* buf, UINT32 &len)
{
    UINT8* off = buf;

    {
	*off++ = (UINT8) (ssrc>>24); *off++ = (UINT8) (ssrc>>16); *off++ = (UINT8) (ssrc>>8); *off++ = (UINT8) (ssrc);
    }
    {
	*off++ = (UINT8) (fraction);
    }
    {
	*off++ = (UINT8) (lost>>16);
	*off++ = (UINT8) (lost>>8);
	*off++ = (UINT8) (lost);
    }
    {
	*off++ = (UINT8) (last_seq>>24); *off++ = (UINT8) (last_seq>>16); *off++ = (UINT8) (last_seq>>8); *off++ = (UINT8) (last_seq);
    }
    {
	*off++ = (UINT8) (jitter>>24); *off++ = (UINT8) (jitter>>16); *off++ = (UINT8) (jitter>>8); *off++ = (UINT8) (jitter);
    }
    {
	*off++ = (UINT8) (lsr>>24); *off++ = (UINT8) (lsr>>16); *off++ = (UINT8) (lsr>>8); *off++ = (UINT8) (lsr);

⌨️ 快捷键说明

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