From 309aafe3513af2c53439cb0ea105a39156547acb Mon Sep 17 00:00:00 2001 From: "Piotr (Peter) Slatala" Date: Tue, 15 Jan 2019 14:24:34 -0800 Subject: [PATCH] Add 'AudioPacket' notification to media transport interface. So far, base channel was only notifying about 'first audio packet' when RTP was used, and it never notified about it when media_transport interface was used. This change adds a sigslot to notify about a new media packet to the media transport interface. Bug: webrtc:9719 Change-Id: Ie9230c407f35b1aaa71ba71008ac34ba8869e2d4 Reviewed-on: https://webrtc-review.googlesource.com/c/117249 Reviewed-by: Anton Sukhanov Reviewed-by: Steve Anton Reviewed-by: Niels Moller Commit-Queue: Peter Slatala Cr-Commit-Position: refs/heads/master@{#26282} --- api/media_transport_interface.cc | 6 ++++++ api/media_transport_interface.h | 21 ++++++++++++++++++++- pc/channel.cc | 19 ++++++++++++++++++- pc/channel.h | 20 +++++++++++++++----- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/api/media_transport_interface.cc b/api/media_transport_interface.cc index ccdcb91688..b5eaa89475 100644 --- a/api/media_transport_interface.cc +++ b/api/media_transport_interface.cc @@ -157,6 +157,9 @@ MediaTransportFactory::CreateMediaTransport( return std::unique_ptr(nullptr); } +MediaTransportInterface::MediaTransportInterface() = default; +MediaTransportInterface::~MediaTransportInterface() = default; + void MediaTransportInterface::SetKeyFrameRequestCallback( MediaTransportKeyFrameRequestCallback* callback) {} @@ -168,6 +171,9 @@ MediaTransportInterface::GetLatestTargetTransferRate() { void MediaTransportInterface::SetNetworkChangeCallback( MediaTransportNetworkChangeCallback* callback) {} +void MediaTransportInterface::SetFirstAudioPacketReceivedObserver( + AudioPacketReceivedObserver* observer) {} + void MediaTransportInterface::AddTargetTransferRateObserver( TargetTransferRateObserver* observer) {} void MediaTransportInterface::RemoveTargetTransferRateObserver( diff --git a/api/media_transport_interface.h b/api/media_transport_interface.h index ee1b8e3a0f..a440860ffc 100644 --- a/api/media_transport_interface.h +++ b/api/media_transport_interface.h @@ -40,6 +40,15 @@ namespace webrtc { class RtcEventLog; +class AudioPacketReceivedObserver { + public: + virtual ~AudioPacketReceivedObserver() = default; + + // Invoked for the first received audio packet on a given channel id. + // It will be invoked once for each channel id. + virtual void OnFirstAudioPacketReceived(int64_t channel_id) = 0; +}; + // A collection of settings for creation of media transport. struct MediaTransportSettings final { MediaTransportSettings(); @@ -352,7 +361,8 @@ class DataChannelSink { // and receiving bandwidth estimate update from congestion control. class MediaTransportInterface { public: - virtual ~MediaTransportInterface() = default; + MediaTransportInterface(); + virtual ~MediaTransportInterface(); // Start asynchronous send of audio frame. The status returned by this method // only pertains to the synchronous operations (e.g. @@ -399,6 +409,15 @@ class MediaTransportInterface { virtual void RemoveTargetTransferRateObserver( TargetTransferRateObserver* observer); + // Sets audio packets observer, which gets informed about incoming audio + // packets. Before destruction, the observer must be unregistered by setting + // nullptr. + // + // This method may be temporary, when the multiplexer is implemented (or + // multiplexer may use it to demultiplex channel ids). + virtual void SetFirstAudioPacketReceivedObserver( + AudioPacketReceivedObserver* observer); + // Intended for receive side. AddRttObserver registers an observer to be // called for each RTT measurement, typically once per ACK. Before media // transport is destructed the observer must be unregistered. diff --git a/pc/channel.cc b/pc/channel.cc index 793f1eec56..d26a5113d4 100644 --- a/pc/channel.cc +++ b/pc/channel.cc @@ -744,6 +744,9 @@ VoiceChannel::VoiceChannel(rtc::Thread* worker_thread, crypto_options) {} VoiceChannel::~VoiceChannel() { + if (media_transport()) { + media_transport()->SetFirstAudioPacketReceivedObserver(nullptr); + } TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); // this can't be done in the base class, since it calls a virtual DisableMedia_w(); @@ -762,6 +765,19 @@ void BaseChannel::OnNetworkRouteChanged( OnNetworkRouteChanged(absl::make_optional(network_route)); } +void VoiceChannel::Init_w(webrtc::RtpTransportInternal* rtp_transport, + webrtc::MediaTransportInterface* media_transport) { + BaseChannel::Init_w(rtp_transport, media_transport); + if (BaseChannel::media_transport()) { + this->media_transport()->SetFirstAudioPacketReceivedObserver(this); + } +} + +void VoiceChannel::OnFirstAudioPacketReceived(int64_t channel_id) { + has_received_packet_ = true; + signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FIRSTPACKETRECEIVED); +} + void VoiceChannel::UpdateMediaSendRecvState_w() { // Render incoming data if we're the active call, and we have the local // content. We receive data on the default channel and multiplexed streams. @@ -1034,7 +1050,8 @@ RtpDataChannel::~RtpDataChannel() { Deinit(); } -void RtpDataChannel::Init_w(webrtc::RtpTransportInternal* rtp_transport) { +void RtpDataChannel::Init_w(webrtc::RtpTransportInternal* rtp_transport, + webrtc::MediaTransportInterface* media_transport) { BaseChannel::Init_w(rtp_transport, /*media_transport=*/nullptr); media_channel()->SignalDataReceived.connect(this, &RtpDataChannel::OnDataReceived); diff --git a/pc/channel.h b/pc/channel.h index 09836b2709..227c593312 100644 --- a/pc/channel.h +++ b/pc/channel.h @@ -20,6 +20,7 @@ #include "api/call/audio_sink.h" #include "api/jsep.h" +#include "api/media_transport_interface.h" #include "api/rtp_receiver_interface.h" #include "api/video/video_sink_interface.h" #include "api/video/video_source_interface.h" @@ -87,8 +88,8 @@ class BaseChannel : public ChannelInterface, bool srtp_required, webrtc::CryptoOptions crypto_options); virtual ~BaseChannel(); - void Init_w(webrtc::RtpTransportInternal* rtp_transport, - webrtc::MediaTransportInterface* media_transport); + virtual void Init_w(webrtc::RtpTransportInternal* rtp_transport, + webrtc::MediaTransportInterface* media_transport); // Deinit may be called multiple times and is simply ignored if it's already // done. @@ -292,6 +293,8 @@ class BaseChannel : public ChannelInterface, bool RegisterRtpDemuxerSink(); + bool has_received_packet_ = false; + private: bool ConnectToRtpTransport(); void DisconnectFromRtpTransport(); @@ -301,6 +304,7 @@ class BaseChannel : public ChannelInterface, // MediaTransportNetworkChangeCallback override. void OnNetworkRouteChanged(const rtc::NetworkRoute& network_route) override; + rtc::Thread* const worker_thread_; rtc::Thread* const network_thread_; rtc::Thread* const signaling_thread_; @@ -323,7 +327,6 @@ class BaseChannel : public ChannelInterface, std::vector > rtcp_socket_options_; bool writable_ = false; bool was_ever_writable_ = false; - bool has_received_packet_ = false; const bool srtp_required_ = true; webrtc::CryptoOptions crypto_options_; @@ -346,7 +349,8 @@ class BaseChannel : public ChannelInterface, // VoiceChannel is a specialization that adds support for early media, DTMF, // and input/output level monitoring. -class VoiceChannel : public BaseChannel { +class VoiceChannel : public BaseChannel, + public webrtc::AudioPacketReceivedObserver { public: VoiceChannel(rtc::Thread* worker_thread, rtc::Thread* network_thread, @@ -366,6 +370,8 @@ class VoiceChannel : public BaseChannel { cricket::MediaType media_type() const override { return cricket::MEDIA_TYPE_AUDIO; } + void Init_w(webrtc::RtpTransportInternal* rtp_transport, + webrtc::MediaTransportInterface* media_transport) override; private: // overrides from BaseChannel @@ -377,6 +383,8 @@ class VoiceChannel : public BaseChannel { webrtc::SdpType type, std::string* error_desc) override; + void OnFirstAudioPacketReceived(int64_t channel_id) override; + // Last AudioSendParameters sent down to the media_channel() via // SetSendParameters. AudioSendParameters last_send_params_; @@ -443,7 +451,9 @@ class RtpDataChannel : public BaseChannel { DtlsTransportInternal* rtcp_dtls_transport, rtc::PacketTransportInternal* rtp_packet_transport, rtc::PacketTransportInternal* rtcp_packet_transport); - void Init_w(webrtc::RtpTransportInternal* rtp_transport); + void Init_w( + webrtc::RtpTransportInternal* rtp_transport, + webrtc::MediaTransportInterface* media_transport = nullptr) override; virtual bool SendData(const SendDataParams& params, const rtc::CopyOnWriteBuffer& payload,