diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn index 3b93673604..8eeccb3a05 100644 --- a/webrtc/api/BUILD.gn +++ b/webrtc/api/BUILD.gn @@ -21,7 +21,6 @@ group("api") { rtc_source_set("call_api") { sources = [ "call/audio_sink.h", - "call/flexfec_receive_stream.h", ] deps = [ diff --git a/webrtc/api/call/flexfec_receive_stream.h b/webrtc/api/call/flexfec_receive_stream.h deleted file mode 100644 index 64b1d5903f..0000000000 --- a/webrtc/api/call/flexfec_receive_stream.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_API_CALL_FLEXFEC_RECEIVE_STREAM_H_ -#define WEBRTC_API_CALL_FLEXFEC_RECEIVE_STREAM_H_ - -#include -#include - -#include "webrtc/api/call/transport.h" -#include "webrtc/config.h" - -namespace webrtc { - -// WORK IN PROGRESS! -// This class is under development and it is not yet intended for use outside -// of WebRTC. -// -// TODO(brandtr): Remove this comment when FlexFEC is ready for public use. - -class FlexfecReceiveStream { - public: - struct Stats { - std::string ToString(int64_t time_ms) const; - - // TODO(brandtr): Add appropriate stats here. - int flexfec_bitrate_bps; - }; - - struct Config { - std::string ToString() const; - - // Payload type for FlexFEC. - int payload_type = -1; - - // SSRC for FlexFEC stream to be received. - uint32_t remote_ssrc = 0; - - // Vector containing a single element, corresponding to the SSRC of the - // media stream being protected by this FlexFEC stream. The vector MUST have - // size 1. - // - // TODO(brandtr): Update comment above when we support multistream - // protection. - std::vector protected_media_ssrcs; - - // SSRC for RTCP reports to be sent. - uint32_t local_ssrc = 0; - - // What RTCP mode to use in the reports. - RtcpMode rtcp_mode = RtcpMode::kCompound; - - // Transport for outgoing RTCP packets. - Transport* rtcp_send_transport = nullptr; - - // |transport_cc| is true whenever the send-side BWE RTCP feedback message - // has been negotiated. This is a prerequisite for enabling send-side BWE. - bool transport_cc = false; - - // RTP header extensions that have been negotiated for this track. - std::vector extensions; - }; - - // Starts stream activity. - // When a stream is active, it can receive and process packets. - virtual void Start() = 0; - // Stops stream activity. - // When a stream is stopped, it can't receive nor process packets. - virtual void Stop() = 0; - - virtual Stats GetStats() const = 0; - - protected: - virtual ~FlexfecReceiveStream() = default; -}; - -} // namespace webrtc - -#endif // WEBRTC_API_CALL_FLEXFEC_RECEIVE_STREAM_H_ diff --git a/webrtc/call/BUILD.gn b/webrtc/call/BUILD.gn index 5572941f30..4a32385348 100644 --- a/webrtc/call/BUILD.gn +++ b/webrtc/call/BUILD.gn @@ -15,6 +15,7 @@ rtc_source_set("call_interfaces") { "audio_send_stream.h", "audio_state.h", "call.h", + "flexfec_receive_stream.h", ] } @@ -22,8 +23,8 @@ rtc_static_library("call") { sources = [ "bitrate_allocator.cc", "call.cc", - "flexfec_receive_stream.cc", - "flexfec_receive_stream.h", + "flexfec_receive_stream_impl.cc", + "flexfec_receive_stream_impl.h", ] if (!build_with_chromium && is_clang) { diff --git a/webrtc/call/call.cc b/webrtc/call/call.cc index 20daba88df..1c4b7b2a71 100644 --- a/webrtc/call/call.cc +++ b/webrtc/call/call.cc @@ -30,7 +30,7 @@ #include "webrtc/base/trace_event.h" #include "webrtc/call/bitrate_allocator.h" #include "webrtc/call/call.h" -#include "webrtc/call/flexfec_receive_stream.h" +#include "webrtc/call/flexfec_receive_stream_impl.h" #include "webrtc/config.h" #include "webrtc/logging/rtc_event_log/rtc_event_log.h" #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" @@ -91,10 +91,10 @@ class Call : public webrtc::Call, void DestroyVideoReceiveStream( webrtc::VideoReceiveStream* receive_stream) override; - webrtc::FlexfecReceiveStream* CreateFlexfecReceiveStream( - const webrtc::FlexfecReceiveStream::Config& config) override; + FlexfecReceiveStream* CreateFlexfecReceiveStream( + const FlexfecReceiveStream::Config& config) override; void DestroyFlexfecReceiveStream( - webrtc::FlexfecReceiveStream* receive_stream) override; + FlexfecReceiveStream* receive_stream) override; Stats GetStats() const override; @@ -183,11 +183,11 @@ class Call : public webrtc::Call, GUARDED_BY(receive_crit_); // Each media stream could conceivably be protected by multiple FlexFEC // streams. - std::multimap flexfec_receive_ssrcs_media_ - GUARDED_BY(receive_crit_); - std::map flexfec_receive_ssrcs_protection_ - GUARDED_BY(receive_crit_); - std::set flexfec_receive_streams_ + std::multimap + flexfec_receive_ssrcs_media_ GUARDED_BY(receive_crit_); + std::map + flexfec_receive_ssrcs_protection_ GUARDED_BY(receive_crit_); + std::set flexfec_receive_streams_ GUARDED_BY(receive_crit_); std::map sync_stream_mapping_ GUARDED_BY(receive_crit_); @@ -655,11 +655,12 @@ void Call::DestroyVideoReceiveStream( delete receive_stream_impl; } -webrtc::FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( - const webrtc::FlexfecReceiveStream::Config& config) { +FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( + const FlexfecReceiveStream::Config& config) { TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream"); RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); - FlexfecReceiveStream* receive_stream = new FlexfecReceiveStream(config, this); + FlexfecReceiveStreamImpl* receive_stream = + new FlexfecReceiveStreamImpl(config, this); { WriteLockScoped write_lock(*receive_crit_); @@ -674,18 +675,18 @@ webrtc::FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( return receive_stream; } -void Call::DestroyFlexfecReceiveStream( - webrtc::FlexfecReceiveStream* receive_stream) { +void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) { TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream"); RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); RTC_DCHECK(receive_stream != nullptr); - // There exist no other derived classes of webrtc::FlexfecReceiveStream, + // There exist no other derived classes of FlexfecReceiveStream, // so this downcast is safe. - FlexfecReceiveStream* receive_stream_impl = - static_cast(receive_stream); + FlexfecReceiveStreamImpl* receive_stream_impl = + static_cast(receive_stream); { WriteLockScoped write_lock(*receive_crit_); - // Remove all SSRCs pointing to the FlexfecReceiveStream to be destroyed. + // Remove all SSRCs pointing to the FlexfecReceiveStreamImpl to be + // destroyed. auto media_it = flexfec_receive_ssrcs_media_.begin(); while (media_it != flexfec_receive_ssrcs_media_.end()) { if (media_it->second == receive_stream_impl) diff --git a/webrtc/call/call.h b/webrtc/call/call.h index a9de18dacc..fdb6cff785 100644 --- a/webrtc/call/call.h +++ b/webrtc/call/call.h @@ -13,13 +13,13 @@ #include #include -#include "webrtc/api/call/flexfec_receive_stream.h" #include "webrtc/base/networkroute.h" #include "webrtc/base/platform_file.h" #include "webrtc/base/socket.h" #include "webrtc/call/audio_receive_stream.h" #include "webrtc/call/audio_send_stream.h" #include "webrtc/call/audio_state.h" +#include "webrtc/call/flexfec_receive_stream.h" #include "webrtc/common_types.h" #include "webrtc/video_receive_stream.h" #include "webrtc/video_send_stream.h" diff --git a/webrtc/call/flexfec_receive_stream.h b/webrtc/call/flexfec_receive_stream.h index 384a94d1d5..83b212bad6 100644 --- a/webrtc/call/flexfec_receive_stream.h +++ b/webrtc/call/flexfec_receive_stream.h @@ -11,41 +11,70 @@ #ifndef WEBRTC_CALL_FLEXFEC_RECEIVE_STREAM_H_ #define WEBRTC_CALL_FLEXFEC_RECEIVE_STREAM_H_ -#include #include +#include -#include "webrtc/api/call/flexfec_receive_stream.h" -#include "webrtc/base/basictypes.h" -#include "webrtc/base/criticalsection.h" -#include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" +#include "webrtc/api/call/transport.h" +#include "webrtc/config.h" namespace webrtc { -namespace internal { - -class FlexfecReceiveStream : public webrtc::FlexfecReceiveStream { +class FlexfecReceiveStream { public: - FlexfecReceiveStream(const Config& config, - RecoveredPacketReceiver* recovered_packet_callback); - ~FlexfecReceiveStream(); + struct Stats { + std::string ToString(int64_t time_ms) const; - bool AddAndProcessReceivedPacket(const uint8_t* packet, size_t length); + // TODO(brandtr): Add appropriate stats here. + int flexfec_bitrate_bps; + }; - // Implements webrtc::FlexfecReceiveStream. - void Start() override; - void Stop() override; - Stats GetStats() const override; + struct Config { + std::string ToString() const; - private: - rtc::CriticalSection crit_; - bool started_ GUARDED_BY(crit_); + // Payload type for FlexFEC. + int payload_type = -1; - const Config config_; - const std::unique_ptr receiver_; + // SSRC for FlexFEC stream to be received. + uint32_t remote_ssrc = 0; + + // Vector containing a single element, corresponding to the SSRC of the + // media stream being protected by this FlexFEC stream. The vector MUST have + // size 1. + // + // TODO(brandtr): Update comment above when we support multistream + // protection. + std::vector protected_media_ssrcs; + + // SSRC for RTCP reports to be sent. + uint32_t local_ssrc = 0; + + // What RTCP mode to use in the reports. + RtcpMode rtcp_mode = RtcpMode::kCompound; + + // Transport for outgoing RTCP packets. + Transport* rtcp_send_transport = nullptr; + + // |transport_cc| is true whenever the send-side BWE RTCP feedback message + // has been negotiated. This is a prerequisite for enabling send-side BWE. + bool transport_cc = false; + + // RTP header extensions that have been negotiated for this track. + std::vector extensions; + }; + + // Starts stream activity. + // When a stream is active, it can receive and process packets. + virtual void Start() = 0; + // Stops stream activity. + // When a stream is stopped, it can't receive nor process packets. + virtual void Stop() = 0; + + virtual Stats GetStats() const = 0; + + protected: + virtual ~FlexfecReceiveStream() = default; }; -} // namespace internal - } // namespace webrtc #endif // WEBRTC_CALL_FLEXFEC_RECEIVE_STREAM_H_ diff --git a/webrtc/call/flexfec_receive_stream.cc b/webrtc/call/flexfec_receive_stream_impl.cc similarity index 84% rename from webrtc/call/flexfec_receive_stream.cc rename to webrtc/call/flexfec_receive_stream_impl.cc index 61a31418cc..e0e49c1a2e 100644 --- a/webrtc/call/flexfec_receive_stream.cc +++ b/webrtc/call/flexfec_receive_stream_impl.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/call/flexfec_receive_stream.h" +#include "webrtc/call/flexfec_receive_stream_impl.h" #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" @@ -84,25 +84,24 @@ std::unique_ptr MaybeCreateFlexfecReceiver( } // namespace -namespace internal { - -FlexfecReceiveStream::FlexfecReceiveStream( +FlexfecReceiveStreamImpl::FlexfecReceiveStreamImpl( const Config& config, RecoveredPacketReceiver* recovered_packet_callback) : started_(false), config_(config), receiver_( MaybeCreateFlexfecReceiver(config_, recovered_packet_callback)) { - LOG(LS_INFO) << "FlexfecReceiveStream: " << config_.ToString(); + LOG(LS_INFO) << "FlexfecReceiveStreamImpl: " << config_.ToString(); } -FlexfecReceiveStream::~FlexfecReceiveStream() { - LOG(LS_INFO) << "~FlexfecReceiveStream: " << config_.ToString(); +FlexfecReceiveStreamImpl::~FlexfecReceiveStreamImpl() { + LOG(LS_INFO) << "~FlexfecReceiveStreamImpl: " << config_.ToString(); Stop(); } -bool FlexfecReceiveStream::AddAndProcessReceivedPacket(const uint8_t* packet, - size_t packet_length) { +bool FlexfecReceiveStreamImpl::AddAndProcessReceivedPacket( + const uint8_t* packet, + size_t packet_length) { { rtc::CritScope cs(&crit_); if (!started_) @@ -113,22 +112,20 @@ bool FlexfecReceiveStream::AddAndProcessReceivedPacket(const uint8_t* packet, return receiver_->AddAndProcessReceivedPacket(packet, packet_length); } -void FlexfecReceiveStream::Start() { +void FlexfecReceiveStreamImpl::Start() { rtc::CritScope cs(&crit_); started_ = true; } -void FlexfecReceiveStream::Stop() { +void FlexfecReceiveStreamImpl::Stop() { rtc::CritScope cs(&crit_); started_ = false; } // TODO(brandtr): Implement this member function when we have designed the // stats for FlexFEC. -FlexfecReceiveStream::Stats FlexfecReceiveStream::GetStats() const { - return webrtc::FlexfecReceiveStream::Stats(); +FlexfecReceiveStreamImpl::Stats FlexfecReceiveStreamImpl::GetStats() const { + return FlexfecReceiveStream::Stats(); } -} // namespace internal - } // namespace webrtc diff --git a/webrtc/call/flexfec_receive_stream_impl.h b/webrtc/call/flexfec_receive_stream_impl.h new file mode 100644 index 0000000000..79c6cc0687 --- /dev/null +++ b/webrtc/call/flexfec_receive_stream_impl.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_CALL_FLEXFEC_RECEIVE_STREAM_IMPL_H_ +#define WEBRTC_CALL_FLEXFEC_RECEIVE_STREAM_IMPL_H_ + +#include +#include + +#include "webrtc/base/basictypes.h" +#include "webrtc/base/criticalsection.h" +#include "webrtc/call/flexfec_receive_stream.h" +#include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" + +namespace webrtc { + +class FlexfecReceiveStreamImpl : public FlexfecReceiveStream { + public: + FlexfecReceiveStreamImpl(const Config& config, + RecoveredPacketReceiver* recovered_packet_callback); + ~FlexfecReceiveStreamImpl() override; + + bool AddAndProcessReceivedPacket(const uint8_t* packet, size_t length); + + // Implements FlexfecReceiveStream. + void Start() override; + void Stop() override; + Stats GetStats() const override; + + private: + rtc::CriticalSection crit_; + bool started_ GUARDED_BY(crit_); + + const Config config_; + const std::unique_ptr receiver_; +}; + +} // namespace webrtc + +#endif // WEBRTC_CALL_FLEXFEC_RECEIVE_STREAM_IMPL_H_ diff --git a/webrtc/call/flexfec_receive_stream_unittest.cc b/webrtc/call/flexfec_receive_stream_unittest.cc index 68f2a2d020..314d9c0efe 100644 --- a/webrtc/call/flexfec_receive_stream_unittest.cc +++ b/webrtc/call/flexfec_receive_stream_unittest.cc @@ -9,7 +9,7 @@ */ #include "webrtc/base/basictypes.h" -#include "webrtc/call/flexfec_receive_stream.h" +#include "webrtc/call/flexfec_receive_stream_impl.h" #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" #include "webrtc/modules/rtp_rtcp/source/byte_io.h" #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" @@ -25,7 +25,7 @@ TEST(FlexfecReceiveStreamTest, ConstructDestruct) { config.protected_media_ssrcs = {912512}; MockRecoveredPacketReceiver callback; - internal::FlexfecReceiveStream receive_stream(config, &callback); + FlexfecReceiveStreamImpl receive_stream(config, &callback); } TEST(FlexfecReceiveStreamTest, StartStop) { @@ -34,7 +34,7 @@ TEST(FlexfecReceiveStreamTest, StartStop) { config.remote_ssrc = 1652392; config.protected_media_ssrcs = {23300443}; MockRecoveredPacketReceiver callback; - internal::FlexfecReceiveStream receive_stream(config, &callback); + FlexfecReceiveStreamImpl receive_stream(config, &callback); receive_stream.Start(); receive_stream.Stop(); @@ -46,7 +46,7 @@ TEST(FlexfecReceiveStreamTest, DoesNotProcessPacketWhenNoMediaSsrcGiven) { config.remote_ssrc = 424223; config.protected_media_ssrcs = {}; MockRecoveredPacketReceiver callback; - internal::FlexfecReceiveStream receive_stream(config, &callback); + FlexfecReceiveStreamImpl receive_stream(config, &callback); const uint8_t packet[] = {0x00, 0x11, 0x22, 0x33}; const size_t packet_length = sizeof(packet); @@ -99,8 +99,7 @@ TEST(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) { config.protected_media_ssrcs = { ByteReader::ReadBigEndian(kMediaSsrc)}; testing::StrictMock recovered_packet_receiver; - internal::FlexfecReceiveStream receive_stream(config, - &recovered_packet_receiver); + FlexfecReceiveStreamImpl receive_stream(config, &recovered_packet_receiver); // Do not call back before being started. receive_stream.AddAndProcessReceivedPacket(kFlexfecPacket, diff --git a/webrtc/media/engine/fakewebrtccall.h b/webrtc/media/engine/fakewebrtccall.h index e7c7d4f740..dc0c1da8e0 100644 --- a/webrtc/media/engine/fakewebrtccall.h +++ b/webrtc/media/engine/fakewebrtccall.h @@ -29,6 +29,7 @@ #include "webrtc/call/audio_receive_stream.h" #include "webrtc/call/audio_send_stream.h" #include "webrtc/call/call.h" +#include "webrtc/call/flexfec_receive_stream.h" #include "webrtc/video_frame.h" #include "webrtc/video_receive_stream.h" #include "webrtc/video_send_stream.h"