From 5ee5ef6ab2a81e805e293815a657cb74fa46b569 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 30 Apr 2020 10:57:03 +0800 Subject: [PATCH] For #307, support publish RTC with passing opus. 4.0.24 --- README.md | 1 + trunk/src/app/srs_app_rtc_conn.cpp | 29 +++++++++++++++++++++++---- trunk/src/app/srs_app_source.cpp | 11 +++++++++- trunk/src/app/srs_app_source.hpp | 3 +++ trunk/src/core/srs_core_version4.hpp | 2 +- trunk/src/kernel/srs_kernel_codec.cpp | 2 +- trunk/src/kernel/srs_kernel_flv.hpp | 2 ++ 7 files changed, 43 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6f3e07ae3..1c490f621 100755 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ For previous versions, please read: ## V4 changes +* v4.0, 2020-04-30, For [#307][bug #307], support publish RTC with passing opus. 4.0.24 * v4.0, 2020-04-14, For [#307][bug #307], support sendmmsg, GSO and reuseport. 4.0.23 * v4.0, 2020-04-05, For [#307][bug #307], SRTP ASM only works with openssl-1.0, auto detect it. 4.0.22 * v4.0, 2020-04-04, Merge RTC and GB28181, with bugs fixed. 4.0.21 diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index 34223e367..5c1458d9d 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -769,6 +769,7 @@ srs_error_t SrsRtcSenderThread::cycle() SrsConsumer* consumer = NULL; SrsAutoFree(SrsConsumer, consumer); + // TODO: FIXME: Dumps the SPS/PPS from gop cache, without other frames. if ((err = source->create_consumer(NULL, consumer)) != srs_success) { return srs_error_wrap(err, "rtc create consumer, source url=%s", req->get_stream_url().c_str()); } @@ -1967,8 +1968,26 @@ srs_error_t SrsRtcPublisher::collect_audio_frame() for (size_t j = 0; j < frames.size(); ++j) { SrsRtpSharedPacket* pkt = frames[j]; - - // TODO: FIXME: Write audio frame to source. + + if (pkt->rtp_payload_size() > 0) { + SrsMessageHeader header; + header.message_type = RTMP_MSG_AudioMessage; + // TODO: FIXME: Maybe the tbn is not 90k. + header.timestamp = pkt->rtp_header.get_timestamp() / 90; + + SrsSharedPtrMessage msg; + // TODO: FIXME: Check error. + msg.create(&header, NULL, 0); + + SrsSample sample; + sample.size = pkt->rtp_payload_size(); + sample.bytes = new char[sample.size]; + memcpy((void*)sample.bytes, pkt->rtp_payload(), sample.size); + msg.set_extra_payloads(&sample, 1); + + // TODO: FIXME: Check error. + source->on_rtc_audio(&msg); + } srs_freep(pkt); } @@ -2103,11 +2122,12 @@ srs_error_t SrsRtcPublisher::collect_video_frame() stream->write_string(pps); SrsMessageHeader header; - header.message_type = 9; + header.message_type = RTMP_MSG_VideoMessage; // TODO: FIXME: Maybe the tbn is not 90k. header.timestamp = timestamp / 90; SrsCommonMessage* shared_video = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, shared_video); + // TODO: FIXME: Check error. shared_video->create(&header, reinterpret_cast(video_header), stream->pos()); srs_error_t e = source->on_video(shared_video); if (e != srs_success) { @@ -2130,11 +2150,12 @@ srs_error_t SrsRtcPublisher::collect_video_frame() frame_buffer[4] = 0x00; SrsMessageHeader header; - header.message_type = 9; + header.message_type = RTMP_MSG_VideoMessage; // TODO: FIXME: Maybe the tbn is not 90k. header.timestamp = timestamp / 90; SrsCommonMessage* shared_video = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, shared_video); + // TODO: FIXME: Check error. shared_video->create(&header, reinterpret_cast(frame_buffer), frame_buffer_index); srs_error_t e = source->on_video(shared_video); if (e != srs_success) { diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 989abbb12..d87c65f97 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -1030,7 +1030,8 @@ srs_error_t SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio) srs_error_t err = srs_success; SrsSharedPtrMessage* msg = shared_audio; - + + // TODO: FIXME: Support parsing OPUS for RTC. if ((err = format->on_audio(msg)) != srs_success) { return srs_error_wrap(err, "format consume audio"); } @@ -1058,6 +1059,7 @@ srs_error_t SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio) } #ifdef SRS_RTC + // TODO: FIXME: Support parsing OPUS for 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); @@ -2761,4 +2763,11 @@ void SrsSource::request_keyframe() rtc_publisher->request_keyframe(); } } + +srs_error_t SrsSource::on_rtc_audio(SrsSharedPtrMessage* audio) +{ + // TODO: FIXME: Merge with on_audio. + // TODO: FIXME: Print key information. + return on_audio_imp(audio); +} #endif diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index 278fcf15e..ac2bad45c 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -613,10 +613,12 @@ public: virtual bool can_publish(bool is_edge); virtual srs_error_t on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); public: + // TODO: FIXME: Use SrsSharedPtrMessage instead. virtual srs_error_t on_audio(SrsCommonMessage* audio); private: virtual srs_error_t on_audio_imp(SrsSharedPtrMessage* audio); public: + // TODO: FIXME: Use SrsSharedPtrMessage instead. virtual srs_error_t on_video(SrsCommonMessage* video); private: virtual srs_error_t on_video_imp(SrsSharedPtrMessage* video); @@ -658,6 +660,7 @@ public: void request_keyframe(); void set_rtc_publisher(SrsRtcPublisher* v) { rtc_publisher = v; } // When got RTC audio message, which is encoded in opus. + // TODO: FIXME: Merge with on_audio. srs_error_t on_rtc_audio(SrsSharedPtrMessage* audio); #endif }; diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index e47dfdc68..abaee8484 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION4_HPP #define SRS_CORE_VERSION4_HPP -#define SRS_VERSION4_REVISION 23 +#define SRS_VERSION4_REVISION 24 #endif diff --git a/trunk/src/kernel/srs_kernel_codec.cpp b/trunk/src/kernel/srs_kernel_codec.cpp index e0789c236..26a3ffdde 100644 --- a/trunk/src/kernel/srs_kernel_codec.cpp +++ b/trunk/src/kernel/srs_kernel_codec.cpp @@ -603,7 +603,7 @@ srs_error_t SrsFormat::on_audio(int64_t timestamp, char* data, int size) srs_error_t err = srs_success; if (!data || size <= 0) { - srs_trace("no audio present, ignore it."); + srs_info("no audio present, ignore it."); return err; } diff --git a/trunk/src/kernel/srs_kernel_flv.hpp b/trunk/src/kernel/srs_kernel_flv.hpp index f92ad6655..80d3ce542 100644 --- a/trunk/src/kernel/srs_kernel_flv.hpp +++ b/trunk/src/kernel/srs_kernel_flv.hpp @@ -158,6 +158,7 @@ public: // 1byte. // One byte field to represent the message type. A range of type IDs // (1-7) are reserved for protocol control messages. + // For example, RTMP_MSG_AudioMessage or RTMP_MSG_VideoMessage. int8_t message_type; // 4bytes. // Four-byte field that identifies the stream of the message. These @@ -245,6 +246,7 @@ public: // 1byte. // One byte field to represent the message type. A range of type IDs // (1-7) are reserved for protocol control messages. + // For example, RTMP_MSG_AudioMessage or RTMP_MSG_VideoMessage. int8_t message_type; // Get the perfered cid(chunk stream id) which sendout over. // set at decoding, and canbe used for directly send message,