Move FlexfecReceiveStream from api/call/ to call/.

Also rename internal::FlexfecReceiveStream to FlexfecReceiveStreamImpl.

BUG=webrtc:6849

Review-Url: https://codereview.webrtc.org/2561123002
Cr-Commit-Position: refs/heads/master@{#15666}
This commit is contained in:
brandtr 2016-12-19 01:13:46 -08:00 committed by Commit bot
parent 9d7ea0920c
commit 7250b398a1
10 changed files with 140 additions and 152 deletions

View File

@ -21,7 +21,6 @@ group("api") {
rtc_source_set("call_api") {
sources = [
"call/audio_sink.h",
"call/flexfec_receive_stream.h",
]
deps = [

View File

@ -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 <string>
#include <vector>
#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<uint32_t> 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<RtpExtension> 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_

View File

@ -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) {

View File

@ -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<uint32_t, FlexfecReceiveStream*> flexfec_receive_ssrcs_media_
GUARDED_BY(receive_crit_);
std::map<uint32_t, FlexfecReceiveStream*> flexfec_receive_ssrcs_protection_
GUARDED_BY(receive_crit_);
std::set<FlexfecReceiveStream*> flexfec_receive_streams_
std::multimap<uint32_t, FlexfecReceiveStreamImpl*>
flexfec_receive_ssrcs_media_ GUARDED_BY(receive_crit_);
std::map<uint32_t, FlexfecReceiveStreamImpl*>
flexfec_receive_ssrcs_protection_ GUARDED_BY(receive_crit_);
std::set<FlexfecReceiveStreamImpl*> flexfec_receive_streams_
GUARDED_BY(receive_crit_);
std::map<std::string, AudioReceiveStream*> 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<FlexfecReceiveStream*>(receive_stream);
FlexfecReceiveStreamImpl* receive_stream_impl =
static_cast<FlexfecReceiveStreamImpl*>(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)

View File

@ -13,13 +13,13 @@
#include <string>
#include <vector>
#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"

View File

@ -11,41 +11,70 @@
#ifndef WEBRTC_CALL_FLEXFEC_RECEIVE_STREAM_H_
#define WEBRTC_CALL_FLEXFEC_RECEIVE_STREAM_H_
#include <memory>
#include <string>
#include <vector>
#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<FlexfecReceiver> 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<uint32_t> 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<RtpExtension> 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_

View File

@ -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<FlexfecReceiver> 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

View File

@ -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 <memory>
#include <string>
#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<FlexfecReceiver> receiver_;
};
} // namespace webrtc
#endif // WEBRTC_CALL_FLEXFEC_RECEIVE_STREAM_IMPL_H_

View File

@ -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<uint32_t>::ReadBigEndian(kMediaSsrc)};
testing::StrictMock<MockRecoveredPacketReceiver> 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,

View File

@ -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"