Refactor RTC function names

pull/1753/head
winlin 5 years ago
parent 583ae52df8
commit 99f9f566ba

@ -940,7 +940,7 @@ srs_error_t SrsRtcSenderThread::messages_to_packets(
for (int i = 0; i < nn_extra_payloads; i++) {
SrsSample* sample = msg->extra_payloads() + i;
if ((err = packet_opus(sample, packets, msg->nn_max_extra_payloads())) != srs_success) {
if ((err = package_opus(sample, packets, msg->nn_max_extra_payloads())) != srs_success) {
return srs_error_wrap(err, "opus package");
}
}
@ -952,14 +952,14 @@ srs_error_t SrsRtcSenderThread::messages_to_packets(
// Well, for each IDR, we append a SPS/PPS before it, which is packaged in STAP-A.
if (msg->has_idr()) {
if ((err = packet_stap_a(source, msg, packets)) != srs_success) {
if ((err = package_stap_a(source, msg, packets)) != srs_success) {
return srs_error_wrap(err, "packet stap-a");
}
}
// If merge Nalus, we pcakges all NALUs(samples) as one NALU, in a RTP or FUA packet.
if (packets.should_merge_nalus && nn_samples > 1) {
if ((err = packet_nalus(msg, packets)) != srs_success) {
if ((err = package_nalus(msg, packets)) != srs_success) {
return srs_error_wrap(err, "packet stap-a");
}
continue;
@ -976,11 +976,11 @@ srs_error_t SrsRtcSenderThread::messages_to_packets(
}
if (sample->size <= kRtpMaxPayloadSize) {
if ((err = packet_single_nalu(msg, sample, packets)) != srs_success) {
if ((err = package_single_nalu(msg, sample, packets)) != srs_success) {
return srs_error_wrap(err, "packet single nalu");
}
} else {
if ((err = packet_fu_a(msg, sample, kRtpMaxPayloadSize, packets)) != srs_success) {
if ((err = package_fu_a(msg, sample, kRtpMaxPayloadSize, packets)) != srs_success) {
return srs_error_wrap(err, "packet fu-a");
}
}
@ -1263,7 +1263,7 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsRtcPackets& packets)
return err;
}
srs_error_t SrsRtcSenderThread::packet_nalus(SrsSharedPtrMessage* msg, SrsRtcPackets& packets)
srs_error_t SrsRtcSenderThread::package_nalus(SrsSharedPtrMessage* msg, SrsRtcPackets& packets)
{
srs_error_t err = srs_success;
@ -1353,7 +1353,7 @@ srs_error_t SrsRtcSenderThread::packet_nalus(SrsSharedPtrMessage* msg, SrsRtcPac
return err;
}
srs_error_t SrsRtcSenderThread::packet_opus(SrsSample* sample, SrsRtcPackets& packets, int nn_max_payload)
srs_error_t SrsRtcSenderThread::package_opus(SrsSample* sample, SrsRtcPackets& packets, int nn_max_payload)
{
srs_error_t err = srs_success;
@ -1389,7 +1389,7 @@ srs_error_t SrsRtcSenderThread::packet_opus(SrsSample* sample, SrsRtcPackets& pa
return err;
}
srs_error_t SrsRtcSenderThread::packet_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, SrsRtcPackets& packets)
srs_error_t SrsRtcSenderThread::package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, SrsRtcPackets& packets)
{
srs_error_t err = srs_success;
@ -1430,7 +1430,7 @@ srs_error_t SrsRtcSenderThread::packet_fu_a(SrsSharedPtrMessage* msg, SrsSample*
}
// Single NAL Unit Packet @see https://tools.ietf.org/html/rfc6184#section-5.6
srs_error_t SrsRtcSenderThread::packet_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, SrsRtcPackets& packets)
srs_error_t SrsRtcSenderThread::package_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, SrsRtcPackets& packets)
{
srs_error_t err = srs_success;
@ -1450,7 +1450,7 @@ srs_error_t SrsRtcSenderThread::packet_single_nalu(SrsSharedPtrMessage* msg, Srs
return err;
}
srs_error_t SrsRtcSenderThread::packet_stap_a(SrsSource* source, SrsSharedPtrMessage* msg, SrsRtcPackets& packets)
srs_error_t SrsRtcSenderThread::package_stap_a(SrsSource* source, SrsSharedPtrMessage* msg, SrsRtcPackets& packets)
{
srs_error_t err = srs_success;
@ -1569,27 +1569,6 @@ srs_error_t SrsRtcPublisher::initialize(SrsUdpMuxSocket* skt, uint32_t vssrc, ui
return err;
}
srs_error_t SrsRtcPublisher::on_rtp(SrsUdpMuxSocket* skt, char* buf, int nb_buf)
{
srs_error_t err = srs_success;
SrsRtpSharedPacket* pkt = new SrsRtpSharedPacket();
SrsAutoFree(SrsRtpSharedPacket, pkt);
if ((err = pkt->decode(buf, nb_buf)) != srs_success) {
return srs_error_wrap(err, "rtp packet decode failed");
}
uint32_t ssrc = pkt->rtp_header.get_ssrc();
if (ssrc == audio_ssrc) {
return on_audio(skt, pkt);
} else if (ssrc == video_ssrc) {
return on_video(skt, pkt);
}
return srs_error_new(ERROR_RTC_RTP, "unknown ssrc=%u", ssrc);
}
srs_error_t SrsRtcPublisher::on_rtcp_sender_report(char* buf, int nb_buf, SrsUdpMuxSocket* skt)
{
srs_error_t err = srs_success;
@ -1933,6 +1912,27 @@ srs_error_t SrsRtcPublisher::send_rtcp_fb_pli(SrsUdpMuxSocket* skt, uint32_t ssr
return err;
}
srs_error_t SrsRtcPublisher::on_rtp(SrsUdpMuxSocket* skt, char* buf, int nb_buf)
{
srs_error_t err = srs_success;
SrsRtpSharedPacket* pkt = new SrsRtpSharedPacket();
SrsAutoFree(SrsRtpSharedPacket, pkt);
if ((err = pkt->decode(buf, nb_buf)) != srs_success) {
return srs_error_wrap(err, "rtp packet decode failed");
}
uint32_t ssrc = pkt->rtp_header.get_ssrc();
if (ssrc == audio_ssrc) {
return on_audio(skt, pkt);
} else if (ssrc == video_ssrc) {
return on_video(skt, pkt);
}
return srs_error_new(ERROR_RTC_RTP, "unknown ssrc=%u", ssrc);
}
srs_error_t SrsRtcPublisher::on_audio(SrsUdpMuxSocket* skt, SrsRtpSharedPacket* pkt)
{
srs_error_t err = srs_success;
@ -1959,19 +1959,18 @@ srs_error_t SrsRtcPublisher::collect_audio_frame()
{
srs_error_t err = srs_success;
std::vector<std::vector<SrsRtpSharedPacket*> > frames;
rtp_audio_queue->collect_frames(frames);
std::vector<std::vector<SrsRtpSharedPacket*> > framess;
rtp_audio_queue->collect_frames(framess);
for (size_t i = 0; i < frames.size(); ++i) {
if (!frames[i].empty()) {
srs_verbose("collect %d audio frames, seq range %u,%u",
frames.size(), frames[i].front()->rtp_header.get_sequence(), frames[i].back()->rtp_header.get_sequence());
}
for (size_t i = 0; i < framess.size(); ++i) {
vector<SrsRtpSharedPacket*> frames = framess[i];
// TODO: FIXME: Write audio frame to source.
for (size_t j = 0; j < frames.size(); ++j) {
SrsRtpSharedPacket* pkt = frames[j];
// TODO: FIXME: Write audio frame to source.
for (size_t n = 0; n < frames[i].size(); ++n) {
srs_freep(frames[i][n]);
srs_freep(pkt);
}
}

@ -246,12 +246,12 @@ private:
srs_error_t send_packets(SrsRtcPackets& packets);
srs_error_t send_packets_gso(SrsRtcPackets& packets);
private:
srs_error_t packet_opus(SrsSample* sample, SrsRtcPackets& packets, int nn_max_payload);
srs_error_t package_opus(SrsSample* sample, SrsRtcPackets& packets, int nn_max_payload);
private:
srs_error_t packet_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, SrsRtcPackets& packets);
srs_error_t packet_nalus(SrsSharedPtrMessage* msg, SrsRtcPackets& packets);
srs_error_t packet_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, SrsRtcPackets& packets);
srs_error_t packet_stap_a(SrsSource* source, SrsSharedPtrMessage* msg, SrsRtcPackets& packets);
srs_error_t package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, SrsRtcPackets& packets);
srs_error_t package_nalus(SrsSharedPtrMessage* msg, SrsRtcPackets& packets);
srs_error_t package_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, SrsRtcPackets& packets);
srs_error_t package_stap_a(SrsSource* source, SrsSharedPtrMessage* msg, SrsRtcPackets& packets);
};
class SrsRtcPublisher : virtual public ISrsHourGlass
@ -282,7 +282,6 @@ public:
virtual ~SrsRtcPublisher();
public:
srs_error_t initialize(SrsUdpMuxSocket* skt, uint32_t vssrc, uint32_t assrc, SrsRequest* req);
srs_error_t on_rtp(SrsUdpMuxSocket* skt, char* buf, int nb_buf);
srs_error_t on_rtcp_sender_report(char* buf, int nb_buf, SrsUdpMuxSocket* skt);
srs_error_t on_rtcp_xr(char* buf, int nb_buf, SrsUdpMuxSocket* skt);
private:
@ -290,12 +289,12 @@ private:
srs_error_t send_rtcp_rr(SrsUdpMuxSocket* skt, uint32_t ssrc, SrsRtpQueue* rtp_queue);
srs_error_t send_rtcp_xr_rrtr(SrsUdpMuxSocket* skt, uint32_t ssrc);
srs_error_t send_rtcp_fb_pli(SrsUdpMuxSocket* skt, uint32_t ssrc);
public:
srs_error_t on_rtp(SrsUdpMuxSocket* skt, char* buf, int nb_buf);
private:
srs_error_t on_audio(SrsUdpMuxSocket* skt, SrsRtpSharedPacket* pkt);
srs_error_t collect_audio_frame();
private:
srs_error_t on_video(SrsUdpMuxSocket* skt, SrsRtpSharedPacket* pkt);
private:
srs_error_t collect_video_frame();
public:
void update_sendonly_socket(SrsUdpMuxSocket* skt);

@ -657,6 +657,8 @@ public:
// TODO: FIXME: Maybe we should only response for the new clients.
void request_keyframe();
void set_rtc_publisher(SrsRtcPublisher* v) { rtc_publisher = v; }
// When got RTC audio message, which is encoded in opus.
srs_error_t on_rtc_audio(SrsSharedPtrMessage* audio);
#endif
};

Loading…
Cancel
Save