mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Remove dead code
This commit is contained in:
parent
c7b88e08e9
commit
d8cf9b64c8
2 changed files with 46 additions and 171 deletions
|
@ -246,8 +246,6 @@ SrsRtcSource::SrsRtcSource()
|
||||||
|
|
||||||
req = NULL;
|
req = NULL;
|
||||||
bridger_ = new SrsRtcFromRtmpBridger(this);
|
bridger_ = new SrsRtcFromRtmpBridger(this);
|
||||||
format = new SrsRtmpFormat();
|
|
||||||
meta = new SrsMetaCache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcSource::~SrsRtcSource()
|
SrsRtcSource::~SrsRtcSource()
|
||||||
|
@ -258,8 +256,6 @@ SrsRtcSource::~SrsRtcSource()
|
||||||
|
|
||||||
srs_freep(req);
|
srs_freep(req);
|
||||||
srs_freep(bridger_);
|
srs_freep(bridger_);
|
||||||
srs_freep(format);
|
|
||||||
srs_freep(meta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcSource::initialize(SrsRequest* r)
|
srs_error_t SrsRtcSource::initialize(SrsRequest* r)
|
||||||
|
@ -272,10 +268,6 @@ srs_error_t SrsRtcSource::initialize(SrsRequest* r)
|
||||||
return srs_error_wrap(err, "bridge initialize");
|
return srs_error_wrap(err, "bridge initialize");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = format->initialize()) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "format initialize");
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,11 +317,6 @@ ISrsSourceBridger* SrsRtcSource::bridger()
|
||||||
return bridger_;
|
return bridger_;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsMetaCache* SrsRtcSource::cached_meta()
|
|
||||||
{
|
|
||||||
return meta;
|
|
||||||
}
|
|
||||||
|
|
||||||
srs_error_t SrsRtcSource::create_consumer(SrsRtcConsumer*& consumer)
|
srs_error_t SrsRtcSource::create_consumer(SrsRtcConsumer*& consumer)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
@ -381,10 +368,6 @@ srs_error_t SrsRtcSource::on_publish()
|
||||||
return srs_error_wrap(err, "source id change");
|
return srs_error_wrap(err, "source id change");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the metadata cache, to make VLC happy when disable/enable stream.
|
|
||||||
// @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448
|
|
||||||
meta->clear();
|
|
||||||
|
|
||||||
// TODO: FIXME: Handle by statistic.
|
// TODO: FIXME: Handle by statistic.
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -397,11 +380,6 @@ void SrsRtcSource::on_unpublish()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the metadata cache, to make VLC happy when disable/enable stream.
|
|
||||||
// @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448
|
|
||||||
meta->update_previous_vsh();
|
|
||||||
meta->update_previous_ash();
|
|
||||||
|
|
||||||
srs_trace("cleanup when unpublish");
|
srs_trace("cleanup when unpublish");
|
||||||
|
|
||||||
_can_publish = true;
|
_can_publish = true;
|
||||||
|
@ -434,103 +412,6 @@ srs_error_t SrsRtcSource::on_rtp(SrsRtpPacket2* pkt)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcSource::on_audio_imp(SrsSharedPtrMessage* msg)
|
|
||||||
{
|
|
||||||
srs_error_t err = srs_success;
|
|
||||||
|
|
||||||
for (int i = 0; i < (int)consumers.size(); i++) {
|
|
||||||
SrsRtcConsumer* consumer = consumers.at(i);
|
|
||||||
if ((err = consumer->enqueue(msg, true, SrsRtmpJitterAlgorithmOFF)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "consume message");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
srs_error_t SrsRtcSource::on_video(SrsCommonMessage* shared_video)
|
|
||||||
{
|
|
||||||
srs_error_t err = srs_success;
|
|
||||||
|
|
||||||
// convert shared_video to msg, user should not use shared_video again.
|
|
||||||
// the payload is transfer to msg, and set to NULL in shared_video.
|
|
||||||
SrsSharedPtrMessage msg;
|
|
||||||
if ((err = msg.create(shared_video)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "create message");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_sequence_header = SrsFlvVideo::sh(msg.payload, msg.size);
|
|
||||||
if (is_sequence_header && (err = meta->update_vsh(&msg)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "meta update video");
|
|
||||||
}
|
|
||||||
|
|
||||||
// user can disable the sps parse to workaround when parse sps failed.
|
|
||||||
// @see https://github.com/ossrs/srs/issues/474
|
|
||||||
if (is_sequence_header) {
|
|
||||||
format->avc_parse_sps = _srs_config->get_parse_sps(req->vhost);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((err = format->on_video(&msg)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "format consume video");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((err = filter(&msg, format)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "filter video");
|
|
||||||
}
|
|
||||||
|
|
||||||
// directly process the video message.
|
|
||||||
return on_video_imp(&msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
srs_error_t SrsRtcSource::on_video_imp(SrsSharedPtrMessage* msg)
|
|
||||||
{
|
|
||||||
srs_error_t err = srs_success;
|
|
||||||
|
|
||||||
// copy to all consumer
|
|
||||||
for (int i = 0; i < (int)consumers.size(); i++) {
|
|
||||||
SrsRtcConsumer* consumer = consumers.at(i);
|
|
||||||
if ((err = consumer->enqueue(msg, true, SrsRtmpJitterAlgorithmOFF)) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "consume video");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
srs_error_t SrsRtcSource::filter(SrsSharedPtrMessage* shared_frame, SrsFormat* format)
|
|
||||||
{
|
|
||||||
srs_error_t err = srs_success;
|
|
||||||
|
|
||||||
// If IDR, we will insert SPS/PPS before IDR frame.
|
|
||||||
if (format->video && format->video->has_idr) {
|
|
||||||
shared_frame->set_has_idr(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update samples to shared frame.
|
|
||||||
for (int i = 0; i < format->video->nb_samples; ++i) {
|
|
||||||
SrsSample* sample = &format->video->samples[i];
|
|
||||||
|
|
||||||
// Because RTC does not support B-frame, so we will drop them.
|
|
||||||
// TODO: Drop B-frame in better way, which not cause picture corruption.
|
|
||||||
if (true) {
|
|
||||||
if ((err = sample->parse_bframe()) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "parse bframe");
|
|
||||||
}
|
|
||||||
if (sample->bframe) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (format->video->nb_samples <= 0) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
shared_frame->set_samples(format->video->samples, format->video->nb_samples);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
SrsRtcFromRtmpBridger::SrsRtcFromRtmpBridger(SrsRtcSource* source)
|
SrsRtcFromRtmpBridger::SrsRtcFromRtmpBridger(SrsRtcSource* source)
|
||||||
{
|
{
|
||||||
req = NULL;
|
req = NULL;
|
||||||
|
@ -540,12 +421,14 @@ SrsRtcFromRtmpBridger::SrsRtcFromRtmpBridger(SrsRtcSource* source)
|
||||||
discard_aac = false;
|
discard_aac = false;
|
||||||
discard_bframe = false;
|
discard_bframe = false;
|
||||||
merge_nalus = false;
|
merge_nalus = false;
|
||||||
|
meta = new SrsMetaCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcFromRtmpBridger::~SrsRtcFromRtmpBridger()
|
SrsRtcFromRtmpBridger::~SrsRtcFromRtmpBridger()
|
||||||
{
|
{
|
||||||
srs_freep(format);
|
srs_freep(format);
|
||||||
srs_freep(codec);
|
srs_freep(codec);
|
||||||
|
srs_freep(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcFromRtmpBridger::initialize(SrsRequest* r)
|
srs_error_t SrsRtcFromRtmpBridger::initialize(SrsRequest* r)
|
||||||
|
@ -581,6 +464,10 @@ srs_error_t SrsRtcFromRtmpBridger::on_publish()
|
||||||
return srs_error_wrap(err, "source publish");
|
return srs_error_wrap(err, "source publish");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the metadata cache, to make VLC happy when disable/enable stream.
|
||||||
|
// @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448
|
||||||
|
meta->clear();
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,6 +475,11 @@ void SrsRtcFromRtmpBridger::on_unpublish()
|
||||||
{
|
{
|
||||||
// TODO: FIXME: Should sync with bridger?
|
// TODO: FIXME: Should sync with bridger?
|
||||||
source_->on_unpublish();
|
source_->on_unpublish();
|
||||||
|
|
||||||
|
// Reset the metadata cache, to make VLC happy when disable/enable stream.
|
||||||
|
// @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448
|
||||||
|
meta->update_previous_vsh();
|
||||||
|
meta->update_previous_ash();
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcFromRtmpBridger::on_audio(SrsSharedPtrMessage* msg)
|
srs_error_t SrsRtcFromRtmpBridger::on_audio(SrsSharedPtrMessage* msg)
|
||||||
|
@ -720,7 +612,6 @@ srs_error_t SrsRtcFromRtmpBridger::on_video(SrsSharedPtrMessage* msg)
|
||||||
|
|
||||||
// cache the sequence header if h264
|
// cache the sequence header if h264
|
||||||
bool is_sequence_header = SrsFlvVideo::sh(msg->payload, msg->size);
|
bool is_sequence_header = SrsFlvVideo::sh(msg->payload, msg->size);
|
||||||
SrsMetaCache* meta = source_->cached_meta();
|
|
||||||
if (is_sequence_header && (err = meta->update_vsh(msg)) != srs_success) {
|
if (is_sequence_header && (err = meta->update_vsh(msg)) != srs_success) {
|
||||||
return srs_error_wrap(err, "meta update video");
|
return srs_error_wrap(err, "meta update video");
|
||||||
}
|
}
|
||||||
|
@ -733,40 +624,6 @@ srs_error_t SrsRtcFromRtmpBridger::on_video(SrsSharedPtrMessage* msg)
|
||||||
return srs_error_wrap(err, "filter video");
|
return srs_error_wrap(err, "filter video");
|
||||||
}
|
}
|
||||||
|
|
||||||
return source_->on_video_imp(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
srs_error_t SrsRtcFromRtmpBridger::filter(SrsSharedPtrMessage* msg, SrsFormat* format)
|
|
||||||
{
|
|
||||||
srs_error_t err = srs_success;
|
|
||||||
|
|
||||||
// If IDR, we will insert SPS/PPS before IDR frame.
|
|
||||||
if (format->video && format->video->has_idr) {
|
|
||||||
msg->set_has_idr(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update samples to shared frame.
|
|
||||||
for (int i = 0; i < format->video->nb_samples; ++i) {
|
|
||||||
SrsSample* sample = &format->video->samples[i];
|
|
||||||
|
|
||||||
// Because RTC does not support B-frame, so we will drop them.
|
|
||||||
// TODO: Drop B-frame in better way, which not cause picture corruption.
|
|
||||||
if (discard_bframe) {
|
|
||||||
if ((err = sample->parse_bframe()) != srs_success) {
|
|
||||||
return srs_error_wrap(err, "parse bframe");
|
|
||||||
}
|
|
||||||
if (sample->bframe) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (format->video->nb_samples <= 0) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: FIXME: Directly covert samples to RTP packets.
|
|
||||||
msg->set_samples(format->video->samples, format->video->nb_samples);
|
|
||||||
int nn_samples = format->video->nb_samples;
|
int nn_samples = format->video->nb_samples;
|
||||||
|
|
||||||
// Well, for each IDR, we append a SPS/PPS before it, which is packaged in STAP-A.
|
// Well, for each IDR, we append a SPS/PPS before it, which is packaged in STAP-A.
|
||||||
|
@ -819,15 +676,45 @@ srs_error_t SrsRtcFromRtmpBridger::filter(SrsSharedPtrMessage* msg, SrsFormat* f
|
||||||
return consume_packets(pkts);
|
return consume_packets(pkts);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcFromRtmpBridger::package_stap_a(SrsRtcSource* source, SrsSharedPtrMessage* msg, SrsRtpPacket2** ppkt)
|
srs_error_t SrsRtcFromRtmpBridger::filter(SrsSharedPtrMessage* msg, SrsFormat* format)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsMetaCache* meta = source->cached_meta();
|
// If IDR, we will insert SPS/PPS before IDR frame.
|
||||||
if (!meta) {
|
if (format->video && format->video->has_idr) {
|
||||||
|
msg->set_has_idr(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update samples to shared frame.
|
||||||
|
for (int i = 0; i < format->video->nb_samples; ++i) {
|
||||||
|
SrsSample* sample = &format->video->samples[i];
|
||||||
|
|
||||||
|
// Because RTC does not support B-frame, so we will drop them.
|
||||||
|
// TODO: Drop B-frame in better way, which not cause picture corruption.
|
||||||
|
if (discard_bframe) {
|
||||||
|
if ((err = sample->parse_bframe()) != srs_success) {
|
||||||
|
return srs_error_wrap(err, "parse bframe");
|
||||||
|
}
|
||||||
|
if (sample->bframe) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format->video->nb_samples <= 0) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: FIXME: Directly covert samples to RTP packets.
|
||||||
|
msg->set_samples(format->video->samples, format->video->nb_samples);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
srs_error_t SrsRtcFromRtmpBridger::package_stap_a(SrsRtcSource* source, SrsSharedPtrMessage* msg, SrsRtpPacket2** ppkt)
|
||||||
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsFormat* format = meta->vsh_format();
|
SrsFormat* format = meta->vsh_format();
|
||||||
if (!format || !format->vcodec) {
|
if (!format || !format->vcodec) {
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -107,8 +107,6 @@ private:
|
||||||
SrsRtcPublisher* rtc_publisher_;
|
SrsRtcPublisher* rtc_publisher_;
|
||||||
// Transmux RTMP to RTC.
|
// Transmux RTMP to RTC.
|
||||||
SrsRtcFromRtmpBridger* bridger_;
|
SrsRtcFromRtmpBridger* bridger_;
|
||||||
// The metadata cache.
|
|
||||||
SrsMetaCache* meta;
|
|
||||||
private:
|
private:
|
||||||
// To delivery stream to clients.
|
// To delivery stream to clients.
|
||||||
std::vector<SrsRtcConsumer*> consumers;
|
std::vector<SrsRtcConsumer*> consumers;
|
||||||
|
@ -128,8 +126,6 @@ public:
|
||||||
virtual int pre_source_id();
|
virtual int pre_source_id();
|
||||||
// Get the bridger.
|
// Get the bridger.
|
||||||
ISrsSourceBridger* bridger();
|
ISrsSourceBridger* bridger();
|
||||||
// For RTC, we need to package SPS/PPS(in cached meta) before each IDR.
|
|
||||||
SrsMetaCache* cached_meta();
|
|
||||||
public:
|
public:
|
||||||
// Create consumer
|
// Create consumer
|
||||||
// @param consumer, output the create consumer.
|
// @param consumer, output the create consumer.
|
||||||
|
@ -152,16 +148,6 @@ public:
|
||||||
void set_rtc_publisher(SrsRtcPublisher* v);
|
void set_rtc_publisher(SrsRtcPublisher* v);
|
||||||
// Consume the shared RTP packet, user must free it.
|
// Consume the shared RTP packet, user must free it.
|
||||||
srs_error_t on_rtp(SrsRtpPacket2* pkt);
|
srs_error_t on_rtp(SrsRtpPacket2* pkt);
|
||||||
virtual srs_error_t on_audio_imp(SrsSharedPtrMessage* audio);
|
|
||||||
// When got RTC audio message, which is encoded in opus.
|
|
||||||
// TODO: FIXME: Merge with on_audio.
|
|
||||||
virtual srs_error_t on_video(SrsCommonMessage* video);
|
|
||||||
virtual srs_error_t on_video_imp(SrsSharedPtrMessage* video);
|
|
||||||
private:
|
|
||||||
// The format, codec information.
|
|
||||||
// TODO: FIXME: Remove it.
|
|
||||||
SrsRtmpFormat* format;
|
|
||||||
srs_error_t filter(SrsSharedPtrMessage* shared_video, SrsFormat* format);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsRtcFromRtmpBridger : public ISrsSourceBridger
|
class SrsRtcFromRtmpBridger : public ISrsSourceBridger
|
||||||
|
@ -171,6 +157,8 @@ private:
|
||||||
SrsRtcSource* source_;
|
SrsRtcSource* source_;
|
||||||
// The format, codec information.
|
// The format, codec information.
|
||||||
SrsRtmpFormat* format;
|
SrsRtmpFormat* format;
|
||||||
|
// The metadata cache.
|
||||||
|
SrsMetaCache* meta;
|
||||||
private:
|
private:
|
||||||
bool discard_aac;
|
bool discard_aac;
|
||||||
SrsAudioRecode* codec;
|
SrsAudioRecode* codec;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue