blob: e3b3345f365252966ac97f07c70694a5a544cb4d [file] [log] [blame]
brandtr76648da2016-10-20 04:54:48 -07001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/call/flexfec_receive_stream.h"
12
13#include "webrtc/base/checks.h"
14#include "webrtc/base/logging.h"
15
16namespace webrtc {
17
18std::string FlexfecReceiveStream::Stats::ToString(int64_t time_ms) const {
19 std::stringstream ss;
20 ss << "FlexfecReceiveStream stats: " << time_ms
21 << ", {flexfec_bitrate_bps: " << flexfec_bitrate_bps << "}";
22 return ss.str();
23}
24
25namespace {
26
27// TODO(brandtr): Update this function when we support multistream protection.
28std::unique_ptr<FlexfecReceiver> MaybeUpdateConfigAndCreateFlexfecReceiver(
29 FlexfecReceiveStream::Config* config,
30 RecoveredPacketReceiver* recovered_packet_callback) {
31 if (config->protected_media_ssrcs.empty()) {
32 LOG(LS_ERROR) << "No protected media SSRC supplied. "
33 << "This FlexfecReceiveStream will therefore be useless.";
34 return nullptr;
35 } else if (config->protected_media_ssrcs.size() > 1) {
36 LOG(LS_WARNING)
37 << "The supplied FlexfecConfig contained multiple protected "
38 "media streams, but our implementation currently only "
39 "supports protecting a single media stream. This "
40 "FlexfecReceiveStream will therefore only accept media "
41 "packets from the first supplied media stream, with SSRC "
42 << config->protected_media_ssrcs[0] << ".";
43 config->protected_media_ssrcs.resize(1);
44 }
45 return FlexfecReceiver::Create(config->flexfec_ssrc,
46 config->protected_media_ssrcs[0],
47 recovered_packet_callback);
48}
49
50} // namespace
51
52namespace internal {
53
54FlexfecReceiveStream::FlexfecReceiveStream(
55 Config configuration,
56 RecoveredPacketReceiver* recovered_packet_callback)
57 : started_(false),
58 config_(configuration),
59 receiver_(MaybeUpdateConfigAndCreateFlexfecReceiver(
60 &config_,
61 recovered_packet_callback)) {
62 LOG(LS_INFO) << "FlexfecReceiveStream: " << config_.ToString();
63}
64
65FlexfecReceiveStream::~FlexfecReceiveStream() {
66 LOG(LS_INFO) << "~FlexfecReceiveStream: " << config_.ToString();
67 Stop();
68}
69
70bool FlexfecReceiveStream::AddAndProcessReceivedPacket(const uint8_t* packet,
71 size_t packet_length) {
72 {
73 rtc::CritScope cs(&crit_);
74 if (!started_)
75 return false;
76 }
77 if (!receiver_)
78 return false;
79 return receiver_->AddAndProcessReceivedPacket(packet, packet_length);
80}
81
82void FlexfecReceiveStream::Start() {
83 rtc::CritScope cs(&crit_);
84 started_ = true;
85}
86
87void FlexfecReceiveStream::Stop() {
88 rtc::CritScope cs(&crit_);
89 started_ = false;
90}
91
92// TODO(brandtr): Implement this member function when we have designed the
93// stats for FlexFEC.
94FlexfecReceiveStream::Stats FlexfecReceiveStream::GetStats() const {
95 return webrtc::FlexfecReceiveStream::Stats();
96}
97
98} // namespace internal
99
100} // namespace webrtc