1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-24 15:04:20 +00:00
srs/trunk/src/kernel/srs_kernel_rtp.hpp

107 lines
3.2 KiB
C++
Raw Normal View History

2020-03-13 12:35:07 +00:00
/**
* The MIT License (MIT)
*
* Copyright (c) 2013-2020 Winlin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_KERNEL_RTP_HPP
#define SRS_KERNEL_RTP_HPP
#include <srs_core.hpp>
#include <string>
2020-04-08 06:45:26 +00:00
const int kRtpHeaderFixedSize = 12;
const uint8_t kRtpMarker = 0x80;
class SrsBuffer;
class SrsRtpHeader
{
private:
bool padding;
bool extension;
uint8_t cc;
bool marker;
uint8_t payload_type;
uint16_t sequence;
int64_t timestamp;
uint32_t ssrc;
uint32_t csrc[15];
uint16_t extension_length;
// TODO:extension field.
public:
SrsRtpHeader();
virtual ~SrsRtpHeader();
SrsRtpHeader(const SrsRtpHeader& rhs);
SrsRtpHeader& operator=(const SrsRtpHeader& rhs);
public:
srs_error_t decode(SrsBuffer* stream);
srs_error_t encode(SrsBuffer* stream);
public:
size_t header_size();
public:
void set_marker(bool marker);
bool get_marker() const { return marker; }
void set_payload_type(uint8_t payload_type);
uint8_t get_payload_type() const { return payload_type; }
void set_sequence(uint16_t sequence);
uint16_t get_sequence() const { return sequence; }
void set_timestamp(int64_t timestamp);
int64_t get_timestamp() const { return timestamp; }
void set_ssrc(uint32_t ssrc);
uint32_t get_ssrc() const { return ssrc; }
};
2020-03-18 00:45:20 +00:00
2020-03-13 12:35:07 +00:00
class SrsRtpSharedPacket
{
private:
2020-04-08 06:45:26 +00:00
class SrsRtpSharedPacketPayload
{
public:
// Rtp packet buffer, include rtp header and payload.
char* payload;
int size;
int shared_count;
public:
SrsRtpSharedPacketPayload();
virtual ~SrsRtpSharedPacketPayload();
};
2020-03-13 12:35:07 +00:00
private:
2020-04-08 06:45:26 +00:00
SrsRtpSharedPacketPayload* payload_ptr;
2020-03-13 12:35:07 +00:00
public:
2020-04-08 06:45:26 +00:00
SrsRtpHeader rtp_header;
char* payload;
int size;
2020-03-13 12:35:07 +00:00
public:
SrsRtpSharedPacket();
virtual ~SrsRtpSharedPacket();
public:
2020-04-08 06:45:26 +00:00
srs_error_t create(int64_t timestamp, uint16_t sequence, uint32_t ssrc, uint16_t payload_type, char* payload, int size);
2020-03-13 12:35:07 +00:00
SrsRtpSharedPacket* copy();
2020-04-08 06:45:26 +00:00
// Interface to modify rtp header
2020-03-18 00:45:20 +00:00
public:
2020-04-08 06:45:26 +00:00
srs_error_t modify_rtp_header_marker(bool marker);
srs_error_t modify_rtp_header_ssrc(uint32_t ssrc);
srs_error_t modify_rtp_header_payload_type(uint8_t payload_type);
2020-03-13 12:35:07 +00:00
};
#endif