1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Merge branch 'feature/rtc' into develop

This commit is contained in:
winlin 2020-03-22 18:53:39 +08:00
commit caf7e9e6ea
771 changed files with 201217 additions and 105 deletions

View file

@ -398,6 +398,24 @@ enum SrsAvcNaluType
};
std::string srs_avc_nalu2str(SrsAvcNaluType nalu_type);
/**
* Table 7-6 Name association to slice_type
* ISO_IEC_14496-10-AVC-2012.pdf, page 105.
*/
enum SrsAvcSliceType
{
SrsAvcSliceTypeP = 0,
SrsAvcSliceTypeB = 1,
SrsAvcSliceTypeI = 2,
SrsAvcSliceTypeSP = 3,
SrsAvcSliceTypeSI = 4,
SrsAvcSliceTypeP1 = 5,
SrsAvcSliceTypeB1 = 6,
SrsAvcSliceTypeI1 = 7,
SrsAvcSliceTypeSP1 = 8,
SrsAvcSliceTypeSI1 = 9,
};
/**
* the avc payload format, must be ibmf or annexb format.
* we guess by annexb first, then ibmf for the first time,

View file

@ -69,14 +69,14 @@ std::string SrsCplxError::description() {
if (desc.empty()) {
stringstream ss;
ss << "code=" << code;
SrsCplxError* next = this;
while (next) {
ss << " : " << next->msg;
next = next->wrapped;
}
ss << endl;
next = this;
while (next) {
ss << "thread [" << getpid() << "][" << next->cid << "]: "
@ -89,13 +89,29 @@ std::string SrsCplxError::description() {
ss << endl;
}
}
desc = ss.str();
}
return desc;
}
std::string SrsCplxError::summary() {
if (_summary.empty()) {
stringstream ss;
SrsCplxError* next = this;
while (next) {
ss << " : " << next->msg;
next = next->wrapped;
}
_summary = ss.str();
}
return _summary;
}
SrsCplxError* SrsCplxError::create(const char* func, const char* file, int line, int code, const char* fmt, ...) {
int rerrno = (int)errno;
@ -178,6 +194,11 @@ string SrsCplxError::description(SrsCplxError* err)
return err? err->description() : "Success";
}
string SrsCplxError::summary(SrsCplxError* err)
{
return err? err->summary() : "Success";
}
int SrsCplxError::error_code(SrsCplxError* err)
{
return err? err->code : ERROR_SUCCESS;

View file

@ -325,6 +325,28 @@
#define ERROR_BASE64_DECODE 4039
#define ERROR_HTTP_STREAM_EOF 4040
///////////////////////////////////////////////////////
// RTC protocol error.
///////////////////////////////////////////////////////
#define ERROR_RTC_PORT 5000
#define ERROR_RTP_PACKET_CREATE 5001
#define ERROR_OpenSslCreateSSL 5002
#define ERROR_OpenSslBIOReset 5003
#define ERROR_OpenSslBIOWrite 5004
#define ERROR_OpenSslBIONew 5005
#define ERROR_RTC_RTP 5006
#define ERROR_RTC_RTCP 5007
#define ERROR_RTC_STUN 5008
#define ERROR_RTC_DTLS 5009
#define ERROR_RTC_UDP 5010
#define ERROR_RTC_RTP_MUXER 5011
#define ERROR_RTC_SDP_DECODE 5012
#define ERROR_RTC_SRTP_INIT 5013
#define ERROR_RTC_SRTP_PROTECT 5014
#define ERROR_RTC_SRTP_UNPROTECT 5015
#define ERROR_RTC_RTCP_CHECK 5016
#define ERROR_RTC_SOURCE_CHECK 5017
///////////////////////////////////////////////////////
// HTTP API error.
///////////////////////////////////////////////////////
@ -364,18 +386,21 @@ private:
int rerrno;
std::string desc;
std::string _summary;
private:
SrsCplxError();
public:
virtual ~SrsCplxError();
private:
virtual std::string description();
virtual std::string summary();
public:
static SrsCplxError* create(const char* func, const char* file, int line, int code, const char* fmt, ...);
static SrsCplxError* wrap(const char* func, const char* file, int line, SrsCplxError* err, const char* fmt, ...);
static SrsCplxError* success();
static SrsCplxError* copy(SrsCplxError* from);
static std::string description(SrsCplxError* err);
static std::string summary(SrsCplxError* err);
static int error_code(SrsCplxError* err);
};
@ -385,6 +410,7 @@ public:
#define srs_error_wrap(err, fmt, ...) SrsCplxError::wrap(__FUNCTION__, __FILE__, __LINE__, err, fmt, ##__VA_ARGS__)
#define srs_error_copy(err) SrsCplxError::copy(err)
#define srs_error_desc(err) SrsCplxError::description(err)
#define srs_error_summary(err) SrsCplxError::summary(err)
#define srs_error_code(err) SrsCplxError::error_code(err)
#define srs_error_reset(err) srs_freep(err); err = srs_success

View file

@ -40,6 +40,9 @@ using namespace std;
#include <srs_kernel_utility.hpp>
#include <srs_core_mem_watch.hpp>
#include <srs_core_autofree.hpp>
#ifdef SRS_AUTO_RTC
#include <srs_kernel_rtp.hpp>
#endif
SrsMessageHeader::SrsMessageHeader()
{
@ -228,6 +231,12 @@ SrsSharedPtrMessage::~SrsSharedPtrMessage()
ptr->shared_count--;
}
}
#ifdef SRS_AUTO_RTC
for (int i = 0; i < (int)rtp_packets.size(); ++i) {
srs_freep(rtp_packets[i]);
}
#endif
}
srs_error_t SrsSharedPtrMessage::create(SrsCommonMessage* msg)
@ -345,10 +354,23 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
copy->stream_id = stream_id;
copy->payload = ptr->payload;
copy->size = ptr->size;
#ifdef SRS_AUTO_RTC
for (int i = 0; i < (int)rtp_packets.size(); ++i) {
copy->rtp_packets.push_back(rtp_packets[i]->copy());
}
#endif
return copy;
}
#ifdef SRS_AUTO_RTC
void SrsSharedPtrMessage::set_rtp_packets(const std::vector<SrsRtpSharedPacket*>& pkts)
{
rtp_packets = pkts;
}
#endif
SrsFlvTransmuxer::SrsFlvTransmuxer()
{
writer = NULL;

View file

@ -27,6 +27,7 @@
#include <srs_core.hpp>
#include <string>
#include <vector>
// For srs-librtmp, @see https://github.com/ossrs/srs/issues/213
#ifndef _WIN32
@ -38,6 +39,7 @@ class ISrsWriter;
class ISrsReader;
class SrsFileReader;
class SrsPacket;
class SrsRtpSharedPacket;
#define SRS_FLV_TAG_HEADER_SIZE 11
#define SRS_FLV_PREVIOUS_TAG_SIZE 4
@ -285,6 +287,11 @@ public:
// @remark, not all message payload can be decoded to packet. for example,
// video/audio packet use raw bytes, no video/audio packet.
char* payload;
#ifdef SRS_AUTO_RTC
std::vector<SrsRtpSharedPacket*> rtp_packets;
#endif
private:
class SrsSharedPtrPayload
{
@ -339,6 +346,10 @@ public:
// copy current shared ptr message, use ref-count.
// @remark, assert object is created.
virtual SrsSharedPtrMessage* copy();
public:
#ifdef SRS_AUTO_RTC
virtual void set_rtp_packets(const std::vector<SrsRtpSharedPacket*>& pkts);
#endif
};
// Transmux RTMP packets to FLV stream.

View file

@ -0,0 +1,128 @@
/**
* 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.
*/
#include <srs_kernel_rtp.hpp>
#include <fcntl.h>
#include <sstream>
using namespace std;
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_utility.hpp>
SrsRtpSharedPacket::SrsRtpSharedPacketPayload::SrsRtpSharedPacketPayload()
{
payload = NULL;
size = 0;
shared_count = 0;
}
SrsRtpSharedPacket::SrsRtpSharedPacketPayload::~SrsRtpSharedPacketPayload()
{
srs_freepa(payload);
}
SrsRtpSharedPacket::SrsRtpSharedPacket()
{
payload_ptr = NULL;
payload = NULL;
size = 0;
timestamp = -1;
sequence = 0;
ssrc = 0;
payload_type = 0;
}
SrsRtpSharedPacket::~SrsRtpSharedPacket()
{
if (payload_ptr) {
if (payload_ptr->shared_count == 0) {
srs_freep(payload_ptr);
} else {
--payload_ptr->shared_count;
}
}
}
srs_error_t SrsRtpSharedPacket::create(int64_t t, uint16_t seq, uint32_t sc, uint16_t pt, char* p, int s)
{
srs_error_t err = srs_success;
if (size < 0) {
return srs_error_new(ERROR_RTP_PACKET_CREATE, "create packet size=%d", size);
}
srs_assert(!payload_ptr);
timestamp = t;
sequence = seq;
ssrc = sc;
payload_type = pt;
payload_ptr = new SrsRtpSharedPacketPayload();
payload_ptr->payload = p;
payload_ptr->size = s;
payload = payload_ptr->payload;
size = payload_ptr->size;
return err;
}
SrsRtpSharedPacket* SrsRtpSharedPacket::copy()
{
SrsRtpSharedPacket* copy = new SrsRtpSharedPacket();
copy->payload_ptr = payload_ptr;
payload_ptr->shared_count++;
copy->payload = payload;
copy->size = size;
copy->timestamp = timestamp;
copy->sequence = sequence;
copy->ssrc = ssrc;
copy->payload_type = payload_type;
return copy;
}
srs_error_t SrsRtpSharedPacket::set_marker(bool marker)
{
srs_error_t err = srs_success;
if (payload_ptr == NULL || payload_ptr->payload == NULL || payload_ptr->size < 1) {
return srs_error_new(ERROR_RTC_RTP_MUXER, "rtp payload incorrect");
}
if (marker) {
payload_ptr->payload[1] |= kMarker;
} else {
payload_ptr->payload[1] &= (~kMarker);
}
return err;
}

View file

@ -0,0 +1,67 @@
/**
* 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>
const uint8_t kMarker = 0x80;
class SrsRtpSharedPacket
{
private:
class SrsRtpSharedPacketPayload
{
public:
char* payload;
int size;
int shared_count;
public:
SrsRtpSharedPacketPayload();
virtual ~SrsRtpSharedPacketPayload();
};
private:
SrsRtpSharedPacketPayload* payload_ptr;
public:
char* payload;
int size;
public:
int64_t timestamp;
uint16_t sequence;
uint32_t ssrc;
uint16_t payload_type;
public:
SrsRtpSharedPacket();
virtual ~SrsRtpSharedPacket();
public:
srs_error_t create(int64_t t, uint16_t seq, uint32_t sc, uint16_t pt, char* p, int s);
SrsRtpSharedPacket* copy();
// interface to modify rtp header
public:
srs_error_t set_marker(bool marker);
};
#endif