RTC: Refactor source to accept RTP audio packet.

pull/1804/head
winlin 5 years ago
parent 377128f4e9
commit 588d17c09d

@ -2174,7 +2174,7 @@ srs_error_t SrsRtcPublisher::on_audio_frame(SrsRtpPacket2* frame)
msg.set_extra_payloads(&sample, 1);
// TODO: FIXME: Check error.
source->on_rtc_audio(&msg);
source->on_audio_imp(&msg);
if (nn_audio_frames++ == 0) {
SrsRtpHeader* h = &frame->rtp_header;

@ -34,6 +34,7 @@
#include <srs_protocol_format.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_app_rtc_codec.hpp>
#include <srs_kernel_rtc_rtp.hpp>
const int kChannel = 2;
const int kSamplerate = 48000;
@ -436,11 +437,25 @@ void SrsRtcSource::set_rtc_publisher(SrsRtcPublisher* v)
rtc_publisher_ = v;
}
srs_error_t SrsRtcSource::on_rtc_audio(SrsSharedPtrMessage* audio)
srs_error_t SrsRtcSource::on_audio_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 message");
}
}
return err;
}
srs_error_t SrsRtcSource::on_audio2(SrsRtpPacket2* pkt)
{
// TODO: FIXME: Merge with on_audio.
// TODO: FIXME: Print key information.
return on_audio_imp(audio);
srs_error_t err = srs_success;
return err;
}
srs_error_t SrsRtcSource::on_video(SrsCommonMessage* shared_video)
@ -477,21 +492,6 @@ srs_error_t SrsRtcSource::on_video(SrsCommonMessage* shared_video)
return on_video_imp(&msg);
}
srs_error_t SrsRtcSource::on_audio_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 message");
}
}
return err;
}
srs_error_t SrsRtcSource::on_video_imp(SrsSharedPtrMessage* msg)
{
srs_error_t err = srs_success;
@ -634,14 +634,14 @@ srs_error_t SrsRtcFromRtmpBridger::on_audio(SrsSharedPtrMessage* msg)
}
if (adts_audio) {
err = transcode(msg, adts_audio, nn_adts_audio);
err = transcode(adts_audio, nn_adts_audio);
srs_freep(adts_audio);
}
return source_->on_audio_imp(msg);
return err;
}
srs_error_t SrsRtcFromRtmpBridger::transcode(SrsSharedPtrMessage* msg, char* adts_audio, int nn_adts_audio)
srs_error_t SrsRtcFromRtmpBridger::transcode(char* adts_audio, int nn_adts_audio)
{
srs_error_t err = srs_success;
@ -684,10 +684,22 @@ srs_error_t SrsRtcFromRtmpBridger::transcode(SrsSharedPtrMessage* msg, char* adt
memcpy(p->bytes, opus_payloads[i], p->size);
nn_max_extra_payload = srs_max(nn_max_extra_payload, p->size);
}
msg->set_extra_payloads(samples, nn_opus_packets);
msg->set_max_extra_payload(nn_max_extra_payload);
SrsRtpPacket2* packet = new SrsRtpPacket2();
packet->rtp_header.set_marker(true);
SrsRtpRawPayload* raw = packet->reuse_raw();
raw->payload = new char[p->size];
raw->nn_payload = p->size;
memcpy(raw->payload, opus_payloads[i], p->size);
// When free the RTP packet, should free the bytes allocated here.
packet->original_bytes = raw->payload;
if ((err = source_->on_audio2(packet)) != srs_success) {
return srs_error_wrap(err, "consume opus");
}
}
return err;
}

@ -42,6 +42,7 @@ class SrsMessageArray;
class SrsRtcSource;
class SrsRtcFromRtmpBridger;
class SrsAudioRecode;
class SrsRtpPacket2;
class SrsRtcConsumer : public ISrsConsumerQueue
{
@ -163,11 +164,11 @@ public:
// Get and set the publisher, passed to consumer to process requests such as PLI.
SrsRtcPublisher* rtc_publisher();
void set_rtc_publisher(SrsRtcPublisher* v);
virtual srs_error_t on_audio_imp(SrsSharedPtrMessage* audio);
srs_error_t on_audio2(SrsRtpPacket2* pkt);
// When got RTC audio message, which is encoded in opus.
// TODO: FIXME: Merge with on_audio.
srs_error_t on_rtc_audio(SrsSharedPtrMessage* audio);
virtual srs_error_t on_video(SrsCommonMessage* video);
virtual srs_error_t on_audio_imp(SrsSharedPtrMessage* audio);
virtual srs_error_t on_video_imp(SrsSharedPtrMessage* video);
private:
// The format, codec information.
@ -196,7 +197,7 @@ public:
virtual void on_unpublish();
virtual srs_error_t on_audio(SrsSharedPtrMessage* audio);
private:
srs_error_t transcode(SrsSharedPtrMessage* shared_audio, char* adts_audio, int nn_adts_audio);
srs_error_t transcode(char* adts_audio, int nn_adts_audio);
public:
virtual srs_error_t on_video(SrsSharedPtrMessage* video);
private:

@ -304,6 +304,7 @@ private:
// The reference count
int shared_count;
#ifdef SRS_RTC
// TODO: FIXME: Remove it.
public:
// For RTC video, we need to know the NALU structures,
// because the RTP STAP-A or FU-A based on NALU.

@ -119,7 +119,7 @@ public:
public:
// The first byte as nalu type, for video decoder only.
SrsAvcNaluType nalu_type;
// The original bytes for decoder only, we will free it.
// The original bytes for decoder or bridger only, we will free it.
char* original_bytes;
// Fast cache for performance.
private:

Loading…
Cancel
Save