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

Merge remote-tracking branch 'srs/feature/codec' into feature/rtc_audio

This commit is contained in:
bepartofyou 2020-03-22 19:55:29 +08:00
commit 766da5188b
733 changed files with 190816 additions and 105 deletions

View file

@ -384,6 +384,7 @@ srs_error_t SrsAudioRecode::initialize()
return err;
}
// TODO: FIXME: Rename to transcode.
srs_error_t SrsAudioRecode::recode(SrsSample *pkt, char **buf, int *buf_len, int &n)
{
srs_error_t err = srs_success;

View file

@ -3486,7 +3486,7 @@ srs_error_t SrsConfig::check_normal_config()
&& n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file"
&& n != "max_connections" && n != "daemon" && n != "heartbeat"
&& n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
&& n != "http_server" && n != "stream_caster" && n != "rtc" && n != "srt_server"
&& n != "http_server" && n != "stream_caster" && n != "rtc_server" && n != "srt_server"
&& n != "utc_time" && n != "work_dir" && n != "asprocess"
&& n != "ff_log_level" && n != "grace_final_wait" && n != "force_grace_quit"
&& n != "grace_start_wait" && n != "empty_ip_ok" && n != "disable_daemon_for_docker"
@ -3673,7 +3673,7 @@ srs_error_t SrsConfig::check_normal_config()
&& n != "play" && n != "publish" && n != "cluster"
&& n != "security" && n != "http_remux" && n != "dash"
&& n != "http_static" && n != "hds" && n != "exec"
&& n != "in_ack_size" && n != "out_ack_size") {
&& n != "in_ack_size" && n != "out_ack_size" && n != "rtc") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.%s", n.c_str());
}
// for each sub directives of vhost.
@ -3819,6 +3819,13 @@ srs_error_t SrsConfig::check_normal_config()
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.bandcheck.%s of %s", m.c_str(), vhost->arg0().c_str());
}
}
} else if (n == "rtc") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name;
if (m != "enabled" && m != "bframe" && m != "aac") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.rtc.%s of %s", m.c_str(), vhost->arg0().c_str());
}
}
}
}
}
@ -4266,13 +4273,13 @@ int SrsConfig::get_stream_caster_rtp_port_max(SrsConfDirective* conf)
return ::atoi(conf->arg0().c_str());
}
int SrsConfig::get_rtc_enabled()
int SrsConfig::get_rtc_server_enabled()
{
SrsConfDirective* conf = root->get("rtc");
return get_rtc_enabled(conf);
SrsConfDirective* conf = root->get("rtc_server");
return get_rtc_server_enabled(conf);
}
bool SrsConfig::get_rtc_enabled(SrsConfDirective* conf)
bool SrsConfig::get_rtc_server_enabled(SrsConfDirective* conf)
{
static bool DEFAULT = false;
@ -4288,11 +4295,11 @@ bool SrsConfig::get_rtc_enabled(SrsConfDirective* conf)
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
int SrsConfig::get_rtc_listen()
int SrsConfig::get_rtc_server_listen()
{
static int DEFAULT = 8000;
SrsConfDirective* conf = root->get("rtc");
SrsConfDirective* conf = root->get("rtc_server");
if (!conf) {
return DEFAULT;
}
@ -4305,11 +4312,11 @@ int SrsConfig::get_rtc_listen()
return ::atoi(conf->arg0().c_str());
}
std::string SrsConfig::get_rtc_candidates()
std::string SrsConfig::get_rtc_server_candidates()
{
static string DEFAULT = "*";
SrsConfDirective* conf = root->get("rtc");
SrsConfDirective* conf = root->get("rtc_server");
if (!conf) {
return DEFAULT;
}
@ -4332,6 +4339,66 @@ std::string SrsConfig::get_rtc_candidates()
return (conf->arg0().c_str());
}
SrsConfDirective* SrsConfig::get_rtc(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
return conf? conf->get("rtc") : NULL;
}
bool SrsConfig::get_rtc_enabled(string vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_rtc_bframe_discard(string vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("bframe");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0() == "discard";
}
bool SrsConfig::get_rtc_aac_discard(string vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("aac");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0() == "discard";
}
SrsConfDirective* SrsConfig::get_vhost(string vhost, bool try_default_vhost)
{
srs_assert(root);

View file

@ -501,10 +501,15 @@ public:
// rtc section
public:
virtual int get_rtc_enabled();
virtual bool get_rtc_enabled(SrsConfDirective* conf);
virtual int get_rtc_listen();
virtual std::string get_rtc_candidates();
virtual int get_rtc_server_enabled();
virtual bool get_rtc_server_enabled(SrsConfDirective* conf);
virtual int get_rtc_server_listen();
virtual std::string get_rtc_server_candidates();
SrsConfDirective* get_rtc(std::string vhost);
bool get_rtc_enabled(std::string vhost);
bool get_rtc_bframe_discard(std::string vhost);
bool get_rtc_aac_discard(std::string vhost);
// vhost specified section
public:

View file

@ -46,7 +46,9 @@ using namespace std;
#include <srs_protocol_amf0.hpp>
#include <srs_protocol_utility.hpp>
#include <srs_app_coworkers.hpp>
#ifdef SRS_AUTO_RTC
#include <srs_app_rtc_conn.hpp>
#endif
srs_error_t srs_api_response_jsonp(ISrsHttpResponseWriter* w, string callback, string data)
{
@ -781,6 +783,7 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
return srs_api_response(w, r, obj->dumps());
}
#ifdef SRS_AUTO_RTC
SrsGoApiSdp::SrsGoApiSdp(SrsRtcServer* rtc_svr)
{
rtc_server = rtc_svr;
@ -887,6 +890,7 @@ srs_error_t SrsGoApiSdp::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
request.stream = stream_name;
SrsSdp local_sdp;
// TODO: FIXME: Maybe need a better name?
// TODO: FIXME: When server enabled, but vhost disabled, should report error.
SrsRtcSession* rtc_session = rtc_server->create_rtc_session(request, remote_sdp, local_sdp);
string local_sdp_str = "";
@ -906,6 +910,7 @@ srs_error_t SrsGoApiSdp::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
return err;
}
#endif
SrsGoApiClients::SrsGoApiClients()
{

View file

@ -166,6 +166,7 @@ public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
#ifdef SRS_AUTO_RTC
class SrsGoApiSdp : public ISrsHttpHandler
{
private:
@ -178,6 +179,7 @@ public:
private:
virtual srs_error_t do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, SrsJsonObject* res);
};
#endif
class SrsGoApiClients : public ISrsHttpHandler
{

View file

@ -21,7 +21,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_app_rtp.hpp>
#include <srs_app_rtc.hpp>
#include <sys/types.h>
#include <sys/stat.h>
@ -49,6 +49,7 @@ using namespace std;
#include <srs_app_utility.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_protocol_format.hpp>
#include <srs_rtmp_stack.hpp>
#include <openssl/rand.h>
#include <srs_app_audio_recode.hpp>
@ -94,6 +95,7 @@ srs_error_t aac_raw_append_adts_header(SrsSharedPtrMessage* shared_audio, SrsFor
SrsRtpMuxer::SrsRtpMuxer()
{
sequence = 0;
discard_bframe = false;
}
SrsRtpMuxer::~SrsRtpMuxer()
@ -139,9 +141,10 @@ srs_error_t SrsRtpMuxer::frame_to_packet(SrsSharedPtrMessage* shared_frame, SrsF
}
srs_verbose("nal_type=%d, slice type=%d", nal_type, slice_type);
// TODO: Use config to determine how to process B frame
if (slice_type == SrsAvcSliceTypeB || slice_type == SrsAvcSliceTypeB1) {
continue;
if (discard_bframe) {
continue;
}
}
}
@ -219,11 +222,8 @@ srs_error_t SrsRtpMuxer::packet_fu_a(SrsSharedPtrMessage* shared_frame, SrsForma
p += packet_size;
nb_left -= packet_size;
srs_verbose("rtp fu-a nalu, size=%u, seq=%u, timestamp=%lu, ssrc=%u, payloadtype=%u, rtp header=%s, payload=%s",
sample->size, sequence, (shared_frame->timestamp * 90), kVideoSSRC, kH264PayloadType,
srs_string_dumps_hex(stream->data(), 12).c_str(),
srs_string_dumps_hex(stream->data() + 12, stream->pos() - 12).c_str());
srs_verbose("rtp fu-a nalu, size=%u, seq=%u, timestamp=%lu, ssrc=%u, payloadtype=%u",
sample->size, sequence, (shared_frame->timestamp * 90), kVideoSSRC, kH264PayloadType);
SrsRtpSharedPacket* rtp_shared_pkt = new SrsRtpSharedPacket();
rtp_shared_pkt->create((shared_frame->timestamp * 90), sequence++, kVideoSSRC, kH264PayloadType, stream->data(), stream->pos());
@ -264,11 +264,8 @@ srs_error_t SrsRtpMuxer::packet_single_nalu(SrsSharedPtrMessage* shared_frame, S
stream->write_bytes(sample->bytes, sample->size);
srs_verbose("sample=%s", srs_string_dumps_hex(sample->bytes, sample->size).c_str());
srs_verbose("rtp single nalu, size=%u, seq=%u, timestamp=%lu, ssrc=%u, payloadtype=%u, rtp header=%s, payload=%s",
sample->size, sequence, (shared_frame->timestamp * 90), kVideoSSRC, kH264PayloadType,
srs_string_dumps_hex(stream->data(), 12).c_str(),
srs_string_dumps_hex(stream->data() + 12, stream->pos() - 12).c_str());
srs_verbose("rtp single nalu, size=%u, seq=%u, timestamp=%lu, ssrc=%u, payloadtype=%u",
sample->size, sequence, (shared_frame->timestamp * 90), kVideoSSRC, kH264PayloadType);
SrsRtpSharedPacket* rtp_shared_pkt = new SrsRtpSharedPacket();
rtp_shared_pkt->create((shared_frame->timestamp * 90), sequence++, kVideoSSRC, kH264PayloadType, stream->data(), stream->pos());
@ -315,10 +312,8 @@ srs_error_t SrsRtpMuxer::packet_stap_a(const string &sps, const string& pps, Srs
stream->write_2bytes(pps.size());
stream->write_bytes((char*)pps.data(), pps.size());
srs_verbose("rtp stap-a nalu, size=%u, seq=%u, timestamp=%lu, ssrc=%u, payloadtype=%u, rtp header=%s, payload=%s",
(sps.size() + pps.size()), sequence, (shared_frame->timestamp * 90), kVideoSSRC, kH264PayloadType,
srs_string_dumps_hex(stream->data(), 12).c_str(),
srs_string_dumps_hex(stream->data() + 12, stream->pos() - 12).c_str());
srs_verbose("rtp stap-a nalu, size=%u, seq=%u, timestamp=%lu, ssrc=%u, payloadtype=%u",
(sps.size() + pps.size()), sequence, (shared_frame->timestamp * 90), kVideoSSRC, kH264PayloadType);
SrsRtpSharedPacket* rtp_shared_pkt = new SrsRtpSharedPacket();
rtp_shared_pkt->create((shared_frame->timestamp * 90), sequence++, kVideoSSRC, kH264PayloadType, stream->data(), stream->pos());
@ -407,6 +402,7 @@ srs_error_t SrsRtpOpusMuxer::packet_opus(SrsSharedPtrMessage* shared_frame, SrsS
stream->write_2bytes(sequence);
// timestamp
stream->write_4bytes(int32_t(timestamp));
// TODO: FIXME: Why 960? Need Refactoring?
timestamp += 960;
// ssrc
stream->write_4bytes(int32_t(kAudioSSRC));
@ -426,7 +422,7 @@ srs_error_t SrsRtpOpusMuxer::packet_opus(SrsSharedPtrMessage* shared_frame, SrsS
return err;
}
SrsRtp::SrsRtp()
SrsRtc::SrsRtc()
{
req = NULL;
hub = NULL;
@ -434,14 +430,16 @@ SrsRtp::SrsRtp()
enabled = false;
disposable = false;
last_update_time = 0;
discard_aac = false;
}
SrsRtp::~SrsRtp()
SrsRtc::~SrsRtc()
{
srs_freep(rtp_h264_muxer);
}
void SrsRtp::dispose()
void SrsRtc::dispose()
{
if (enabled) {
on_unpublish();
@ -449,14 +447,14 @@ void SrsRtp::dispose()
}
// TODO: FIXME: Dead code?
srs_error_t SrsRtp::cycle()
srs_error_t SrsRtc::cycle()
{
srs_error_t err = srs_success;
return err;
}
srs_error_t SrsRtp::initialize(SrsOriginHub* h, SrsRequest* r)
srs_error_t SrsRtc::initialize(SrsOriginHub* h, SrsRequest* r)
{
srs_error_t err = srs_success;
@ -464,6 +462,9 @@ srs_error_t SrsRtp::initialize(SrsOriginHub* h, SrsRequest* r)
req = r;
rtp_h264_muxer = new SrsRtpMuxer();
rtp_h264_muxer->discard_bframe = _srs_config->get_rtc_bframe_discard(req->vhost);
// TODO: FIXME: Support reload and log it.
discard_aac = _srs_config->get_rtc_aac_discard(req->vhost);
rtp_opus_muxer = new SrsRtpOpusMuxer();
if (!rtp_opus_muxer) {
@ -473,7 +474,7 @@ srs_error_t SrsRtp::initialize(SrsOriginHub* h, SrsRequest* r)
return rtp_opus_muxer->initialize();
}
srs_error_t SrsRtp::on_publish()
srs_error_t SrsRtc::on_publish()
{
srs_error_t err = srs_success;
@ -484,6 +485,10 @@ srs_error_t SrsRtp::on_publish()
if (enabled) {
return err;
}
if (!_srs_config->get_rtc_enabled(req->vhost)) {
return err;
}
// if enabled, open the muxer.
enabled = true;
@ -494,7 +499,7 @@ srs_error_t SrsRtp::on_publish()
return err;
}
void SrsRtp::on_unpublish()
void SrsRtc::on_unpublish()
{
// support multiple unpublish.
if (!enabled) {
@ -504,7 +509,7 @@ void SrsRtp::on_unpublish()
enabled = false;
}
srs_error_t SrsRtp::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)
srs_error_t SrsRtc::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)
{
srs_error_t err = srs_success;
@ -526,6 +531,11 @@ srs_error_t SrsRtp::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* forma
if (acodec != SrsAudioCodecIdAAC && acodec != SrsAudioCodecIdMP3) {
return err;
}
// When drop aac audio packet, never transcode.
if (discard_aac && acodec == SrsAudioCodecIdAAC) {
return err;
}
// ignore sequence header
srs_assert(format->audio);
@ -543,7 +553,7 @@ srs_error_t SrsRtp::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* forma
return err;
}
srs_error_t SrsRtp::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format)
srs_error_t SrsRtc::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format)
{
srs_error_t err = srs_success;

View file

@ -21,8 +21,8 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_APP_RTP_HPP
#define SRS_APP_RTP_HPP
#ifndef SRS_APP_RTC_HPP
#define SRS_APP_RTC_HPP
#include <srs_core.hpp>
@ -62,12 +62,15 @@ const int kArrayBuffer = 4096;
const uint32_t kAudioSSRC = 3233846890;
const uint32_t kVideoSSRC = 3233846889;
// TODO: Define interface class like ISrsRtpMuxer to support SrsRtpOpusMuxer and so on.
class SrsRtpMuxer
{
private:
uint16_t sequence;
std::string sps;
std::string pps;
public:
bool discard_bframe;
public:
SrsRtpMuxer();
virtual ~SrsRtpMuxer();
@ -79,9 +82,11 @@ private:
srs_error_t packet_stap_a(const std::string &sps, const std::string& pps, SrsSharedPtrMessage* shared_frame, std::vector<SrsRtpSharedPacket*>& rtp_packet_vec);
};
// TODO: FIXME: It's not a muxer, but a transcoder.
class SrsRtpOpusMuxer
{
private:
// TODO: FIXME: How to handle timestamp overflow?
uint32_t timestamp;
uint16_t sequence;
SrsAudioRecode* transcode;
@ -95,19 +100,20 @@ private:
srs_error_t packet_opus(SrsSharedPtrMessage* shared_frame, SrsSample* sample, std::vector<SrsRtpSharedPacket*>& rtp_packet_vec);
};
class SrsRtp
class SrsRtc
{
private:
SrsRequest* req;
bool enabled;
bool disposable;
bool discard_aac;
srs_utime_t last_update_time;
SrsRtpMuxer* rtp_h264_muxer;
SrsRtpOpusMuxer* rtp_opus_muxer;
SrsOriginHub* hub;
public:
SrsRtp();
virtual ~SrsRtp();
SrsRtc();
virtual ~SrsRtc();
public:
virtual void dispose();
virtual srs_error_t cycle();

View file

@ -46,7 +46,7 @@ using namespace std;
#include <srs_app_dtls.hpp>
#include <srs_app_utility.hpp>
#include <srs_app_config.hpp>
#include <srs_app_rtp.hpp>
#include <srs_app_rtc.hpp>
#include <srs_app_source.hpp>
#include <srs_app_server.hpp>
#include <srs_service_utility.hpp>
@ -101,7 +101,7 @@ std::vector<std::string> SrsCandidate::get_candidate_ips()
{
std::vector<std::string> candidate_ips;
string candidate = _srs_config->get_rtc_candidates();
string candidate = _srs_config->get_rtc_server_candidates();
if (candidate == "*" || candidate == "0.0.0.0") {
std::vector<std::string> tmp = srs_get_local_ips();
for (int i = 0; i < (int)tmp.size(); ++i) {
@ -189,7 +189,7 @@ srs_error_t SrsSdp::encode(string& sdp_str)
std::vector<string> candidate_ips = SrsCandidate::get_candidate_ips();
for (int i = 0; i < (int)candidate_ips.size(); ++i) {
ostringstream os;
os << "a=candidate:10 1 udp 2115783679 " << candidate_ips[i] << " " << _srs_config->get_rtc_listen() <<" typ host generation 0\\r\\n";
os << "a=candidate:10 1 udp 2115783679 " << candidate_ips[i] << " " << _srs_config->get_rtc_server_listen() <<" typ host generation 0\\r\\n";
candidate_lines += os.str();
}
@ -1179,11 +1179,11 @@ srs_error_t SrsRtcServer::listen_udp()
{
srs_error_t err = srs_success;
if (!_srs_config->get_rtc_enabled()) {
if (!_srs_config->get_rtc_server_enabled()) {
return err;
}
int port = _srs_config->get_rtc_listen();
int port = _srs_config->get_rtc_server_listen();
if (port <= 0) {
return srs_error_new(ERROR_RTC_PORT, "invalid port=%d", port);
}

View file

@ -33,7 +33,6 @@ using namespace std;
#include <srs_kernel_codec.hpp>
#include <srs_kernel_rtp.hpp>
#include <srs_app_hls.hpp>
#include <srs_app_rtp.hpp>
#include <srs_app_forward.hpp>
#include <srs_app_config.hpp>
#include <srs_app_encoder.hpp>
@ -51,6 +50,9 @@ using namespace std;
#include <srs_app_ng_exec.hpp>
#include <srs_app_dash.hpp>
#include <srs_protocol_format.hpp>
#ifdef SRS_AUTO_RTC
#include <srs_app_rtc.hpp>
#endif
#define CONST_MAX_JITTER_MS 250
#define CONST_MAX_JITTER_MS_NEG -250
@ -816,6 +818,7 @@ SrsSharedPtrMessage* SrsMixQueue::pop()
return msg;
}
#ifdef SRS_AUTO_RTC
SrsRtpPacketQueue::SrsRtpPacketQueue()
{
}
@ -864,6 +867,7 @@ SrsRtpSharedPacket* SrsRtpPacketQueue::find(const uint16_t& sequence)
return pkt;
}
#endif
SrsOriginHub::SrsOriginHub()
{
@ -875,7 +879,9 @@ SrsOriginHub::SrsOriginHub()
dash = new SrsDash();
dvr = new SrsDvr();
encoder = new SrsEncoder();
rtp = new SrsRtp();
#ifdef SRS_AUTO_RTC
rtc = new SrsRtc();
#endif
#ifdef SRS_AUTO_HDS
hds = new SrsHds();
#endif
@ -919,10 +925,12 @@ srs_error_t SrsOriginHub::initialize(SrsSource* s, SrsRequest* r)
if ((err = format->initialize()) != srs_success) {
return srs_error_wrap(err, "format initialize");
}
if ((err = rtp->initialize(this, req)) != srs_success) {
return srs_error_wrap(err, "rtp initialize");
#ifdef SRS_AUTO_RTC
if ((err = rtc->initialize(this, req)) != srs_success) {
return srs_error_wrap(err, "rtc initialize");
}
#endif
if ((err = hls->initialize(this, req)) != srs_success) {
return srs_error_wrap(err, "hls initialize");
@ -1022,11 +1030,13 @@ srs_error_t SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio)
srs_flv_srates[c->sound_rate]);
}
if ((err = rtp->on_audio(msg, format)) != srs_success) {
srs_warn("rtp: ignore audio error %s", srs_error_desc(err).c_str());
#ifdef SRS_AUTO_RTC
if ((err = rtc->on_audio(msg, format)) != srs_success) {
srs_warn("rtc: ignore audio error %s", srs_error_desc(err).c_str());
srs_error_reset(err);
rtp->on_unpublish();
rtc->on_unpublish();
}
#endif
if ((err = hls->on_audio(msg, format)) != srs_success) {
// apply the error strategy for hls.
@ -1121,17 +1131,19 @@ srs_error_t SrsOriginHub::on_video(SrsSharedPtrMessage* shared_video, bool is_se
return err;
}
#ifdef SRS_AUTO_RTC
// Parse RTMP message to RTP packets, in FU-A if too large.
if ((err = rtp->on_video(msg, format)) != srs_success) {
if ((err = rtc->on_video(msg, format)) != srs_success) {
// TODO: We should support more strategies.
srs_warn("rtp: ignore video error %s", srs_error_desc(err).c_str());
srs_warn("rtc: ignore video error %s", srs_error_desc(err).c_str());
srs_error_reset(err);
rtp->on_unpublish();
rtc->on_unpublish();
}
// TODO: FIXME: Refactor to move to rtp?
// Save the RTP packets for find_rtp_packet() to rtx or restore it.
source->rtp_queue->push(msg->rtp_packets);
#endif
if ((err = hls->on_video(msg, format)) != srs_success) {
// TODO: We should support more strategies.
@ -1200,10 +1212,12 @@ srs_error_t SrsOriginHub::on_publish()
if ((err = encoder->on_publish(req)) != srs_success) {
return srs_error_wrap(err, "encoder publish");
}
if ((err = rtp->on_publish()) != srs_success) {
return srs_error_wrap(err, "rtp publish");
#ifdef SRS_AUTO_RTC
if ((err = rtc->on_publish()) != srs_success) {
return srs_error_wrap(err, "rtc publish");
}
#endif
if ((err = hls->on_publish()) != srs_success) {
return srs_error_wrap(err, "hls publish");
@ -1242,7 +1256,9 @@ void SrsOriginHub::on_unpublish()
destroy_forwarders();
encoder->on_unpublish();
rtp->on_unpublish();
#ifdef SRS_AUTO_RTC
rtc->on_unpublish();
#endif
hls->on_unpublish();
dash->on_unpublish();
dvr->on_unpublish();
@ -1904,7 +1920,9 @@ SrsSource::SrsSource()
jitter_algorithm = SrsRtmpJitterAlgorithmOFF;
mix_correct = false;
mix_queue = new SrsMixQueue();
#ifdef SRS_AUTO_RTC
rtp_queue = new SrsRtpPacketQueue();
#endif
_can_publish = true;
_pre_source_id = _source_id = -1;
@ -1934,7 +1952,9 @@ SrsSource::~SrsSource()
srs_freep(hub);
srs_freep(meta);
srs_freep(mix_queue);
#ifdef SRS_AUTO_RTC
srs_freep(rtp_queue);
#endif
srs_freep(play_edge);
srs_freep(publish_edge);
@ -2692,7 +2712,9 @@ string SrsSource::get_curr_origin()
return play_edge->get_curr_origin();
}
#ifdef SRS_AUTO_RTC
SrsRtpSharedPacket* SrsSource::find_rtp_packet(const uint16_t& seq)
{
return rtp_queue->find(seq);
}
#endif

View file

@ -54,7 +54,7 @@ class SrsNgExec;
class SrsConnection;
class SrsMessageHeader;
class SrsHls;
class SrsRtp;
class SrsRtc;
class SrsDvr;
class SrsDash;
class SrsEncoder;
@ -325,6 +325,7 @@ public:
virtual SrsSharedPtrMessage* pop();
};
#ifdef SRS_AUTO_RTC
// To find the RTP packet for RTX or restore.
class SrsRtpPacketQueue
{
@ -347,6 +348,7 @@ public:
void insert(const uint16_t& sequence, SrsRtpSharedPacket* pkt);
SrsRtpSharedPacket* find(const uint16_t& sequence);
};
#endif
// The hub for origin is a collection of utilities for origin only,
// For example, DVR, HLS, Forward and Transcode are only available for origin,
@ -360,8 +362,10 @@ private:
private:
// The format, codec information.
SrsRtmpFormat* format;
// rtp handler
SrsRtp* rtp;
#ifdef SRS_AUTO_RTC
// rtc handler
SrsRtc* rtc;
#endif
// hls handler.
SrsHls* hls;
// The DASH encoder.
@ -534,8 +538,10 @@ private:
bool mix_correct;
// The mix queue to implements the mix correct algorithm.
SrsMixQueue* mix_queue;
#ifdef SRS_AUTO_RTC
// rtp packet queue
SrsRtpPacketQueue* rtp_queue;
#endif
// For play, whether enabled atc.
// The atc(use absolute time and donot adjust time),
// directly use msg time and donot adjust if atc is true,
@ -625,8 +631,10 @@ public:
public:
virtual std::string get_curr_origin();
public:
#ifdef SRS_AUTO_RTC
// Find rtp packet by sequence
SrsRtpSharedPacket* find_rtp_packet(const uint16_t& seq);
#endif
};
#endif

View file

@ -36,11 +36,13 @@ using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_file.hpp>
#include <srs_kernel_rtp.hpp>
#include <srs_kernel_codec.hpp>
#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()
{
@ -230,9 +232,11 @@ SrsSharedPtrMessage::~SrsSharedPtrMessage()
}
}
#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)
@ -351,17 +355,21 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
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()
{

View file

@ -288,7 +288,10 @@ public:
// 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
{
@ -344,7 +347,9 @@ public:
// @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

@ -50,7 +50,9 @@ using namespace std;
#include <srs_core_autofree.hpp>
#include <srs_kernel_file.hpp>
#include <srs_app_hybrid.hpp>
#ifdef SRS_AUTO_RTC
#include <srs_app_rtc_conn.hpp>
#endif
#ifdef SRS_AUTO_SRT
#include <srt_server.hpp>
@ -449,7 +451,9 @@ srs_error_t run_hybrid_server()
_srs_hybrid->register_server(new SrtServerAdapter());
#endif
#ifdef SRS_AUTO_RTC
_srs_hybrid->register_server(new RtcServerAdapter());
#endif
// Do some system initialize.
if ((err = _srs_hybrid->initialize()) != srs_success) {