INET Framework for OMNeT++/OMNEST
inet::rtp::RtpPacketSerializer Class Reference

Converts between RtpPacket and binary (network byte order) RTP packet. More...

#include <RtpPacketSerializer.h>

Inheritance diagram for inet::rtp::RtpPacketSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 RtpPacketSerializer ()
 
- Public Member Functions inherited from inet::FieldsChunkSerializer
virtual void serialize (MemoryOutputStream &stream, const Ptr< const Chunk > &chunk, b offset, b length) const override
 Serializes a chunk into a stream by writing the bytes representing the chunk at the end of the stream. More...
 
virtual const Ptr< Chunkdeserialize (MemoryInputStream &stream, const std::type_info &typeInfo) const override
 Deserializes a chunk from a stream by reading the bytes at the current position of the stream. More...
 

Protected Member Functions

virtual void serialize (MemoryOutputStream &stream, const Ptr< const Chunk > &chunk) const override
 Serializes a chunk into a stream by writing all bytes representing the chunk at the end of the stream. More...
 
virtual const Ptr< Chunkdeserialize (MemoryInputStream &stream) const override
 Deserializes a chunk from a stream by reading the bytes at the current position of the stream. More...
 

Additional Inherited Members

- Static Public Attributes inherited from inet::ChunkSerializer
static b totalSerializedLength = b(0)
 
static b totalDeserializedLength = b(0)
 

Detailed Description

Converts between RtpPacket and binary (network byte order) RTP packet.

Constructor & Destructor Documentation

◆ RtpPacketSerializer()

inet::rtp::RtpPacketSerializer::RtpPacketSerializer ( )
inline
24 : FieldsChunkSerializer() {}

Member Function Documentation

◆ deserialize()

const Ptr< Chunk > inet::rtp::RtpPacketSerializer::deserialize ( MemoryInputStream stream) const
overrideprotectedvirtual

Deserializes a chunk from a stream by reading the bytes at the current position of the stream.

The current stream position is updated according to the length of the returned chunk.

Implements inet::FieldsChunkSerializer.

36 {
37  auto rtpHeader = makeShared<RtpHeader>();
38  rtpHeader->setVersion(stream.readNBitsToUint64Be(2));
39  rtpHeader->setPaddingFlag(stream.readBit());
40  rtpHeader->setExtensionFlag(stream.readBit());
41  size_t csrcArraySize = stream.readUint4();
42  rtpHeader->setCsrcArraySize(csrcArraySize);
43  rtpHeader->setMarker(stream.readBit());
44  rtpHeader->setPayloadType(stream.readNBitsToUint64Be(7));
45  rtpHeader->setSequenceNumber(stream.readUint16Be());
46  rtpHeader->setTimeStamp(stream.readUint32Be());
47  rtpHeader->setSsrc(stream.readUint32Be());
48  for (size_t i = 0; i < csrcArraySize; ++i) {
49  rtpHeader->setCsrc(i, stream.readUint32Be());
50  }
51  rtpHeader->setChunkLength(B(12 + csrcArraySize * 4));
52  return rtpHeader;
53 }

◆ serialize()

void inet::rtp::RtpPacketSerializer::serialize ( MemoryOutputStream stream,
const Ptr< const Chunk > &  chunk 
) const
overrideprotectedvirtual

Serializes a chunk into a stream by writing all bytes representing the chunk at the end of the stream.

Implements inet::FieldsChunkSerializer.

18 {
19  const auto& rtpHeader = staticPtrCast<const RtpHeader>(chunk);
20  stream.writeNBitsOfUint64Be(rtpHeader->getVersion(), 2);
21  stream.writeBit(rtpHeader->getPaddingFlag());
22  stream.writeBit(rtpHeader->getExtensionFlag());
23  size_t csrcArraySize = rtpHeader->getCsrcArraySize();
24  stream.writeUint4(csrcArraySize);
25  stream.writeBit(rtpHeader->getMarker());
26  stream.writeNBitsOfUint64Be(rtpHeader->getPayloadType(), 7);
27  stream.writeUint16Be(rtpHeader->getSequenceNumber());
28  stream.writeUint32Be(rtpHeader->getTimeStamp());
29  stream.writeUint32Be(rtpHeader->getSsrc());
30  for (size_t i = 0; i < csrcArraySize; ++i) {
31  stream.writeUint32Be(rtpHeader->getCsrc(i));
32  }
33 }

The documentation for this class was generated from the following files:
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168