OLD | NEW |
| (Empty) |
1 /* | |
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 | |
16 namespace webrtc { | |
17 | |
18 std::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 | |
25 std::string FlexfecReceiveStream::Config::ToString() const { | |
26 std::stringstream ss; | |
27 ss << "{payload_type: " << payload_type; | |
28 ss << ", remote_ssrc: " << remote_ssrc; | |
29 ss << ", local_ssrc: " << local_ssrc; | |
30 ss << ", protected_media_ssrcs: ["; | |
31 size_t i = 0; | |
32 for (; i + 1 < protected_media_ssrcs.size(); ++i) | |
33 ss << protected_media_ssrcs[i] << ", "; | |
34 if (!protected_media_ssrcs.empty()) | |
35 ss << protected_media_ssrcs[i]; | |
36 ss << "], transport_cc: " << (transport_cc ? "on" : "off"); | |
37 ss << ", extensions: ["; | |
38 i = 0; | |
39 for (; i + 1 < extensions.size(); ++i) | |
40 ss << extensions[i].ToString() << ", "; | |
41 if (!extensions.empty()) | |
42 ss << extensions[i].ToString(); | |
43 ss << "]}"; | |
44 return ss.str(); | |
45 } | |
46 | |
47 namespace { | |
48 | |
49 // TODO(brandtr): Update this function when we support multistream protection. | |
50 std::unique_ptr<FlexfecReceiver> MaybeCreateFlexfecReceiver( | |
51 const FlexfecReceiveStream::Config& config, | |
52 RecoveredPacketReceiver* recovered_packet_callback) { | |
53 if (config.payload_type < 0) { | |
54 LOG(LS_WARNING) << "Invalid FlexFEC payload type given. " | |
55 << "This FlexfecReceiveStream will therefore be useless."; | |
56 return nullptr; | |
57 } | |
58 RTC_DCHECK_GE(config.payload_type, 0); | |
59 RTC_DCHECK_LE(config.payload_type, 127); | |
60 if (config.remote_ssrc == 0) { | |
61 LOG(LS_WARNING) << "Invalid FlexFEC SSRC given. " | |
62 << "This FlexfecReceiveStream will therefore be useless."; | |
63 return nullptr; | |
64 } | |
65 if (config.protected_media_ssrcs.empty()) { | |
66 LOG(LS_WARNING) << "No protected media SSRC supplied. " | |
67 << "This FlexfecReceiveStream will therefore be useless."; | |
68 return nullptr; | |
69 } | |
70 | |
71 if (config.protected_media_ssrcs.size() > 1) { | |
72 LOG(LS_WARNING) | |
73 << "The supplied FlexfecConfig contained multiple protected " | |
74 "media streams, but our implementation currently only " | |
75 "supports protecting a single media stream. " | |
76 "To avoid confusion, disabling FlexFEC completely."; | |
77 return nullptr; | |
78 } | |
79 RTC_DCHECK_EQ(1U, config.protected_media_ssrcs.size()); | |
80 return std::unique_ptr<FlexfecReceiver>( | |
81 new FlexfecReceiver(config.remote_ssrc, config.protected_media_ssrcs[0], | |
82 recovered_packet_callback)); | |
83 } | |
84 | |
85 } // namespace | |
86 | |
87 namespace internal { | |
88 | |
89 FlexfecReceiveStream::FlexfecReceiveStream( | |
90 const Config& config, | |
91 RecoveredPacketReceiver* recovered_packet_callback) | |
92 : started_(false), | |
93 config_(config), | |
94 receiver_( | |
95 MaybeCreateFlexfecReceiver(config_, recovered_packet_callback)) { | |
96 LOG(LS_INFO) << "FlexfecReceiveStream: " << config_.ToString(); | |
97 } | |
98 | |
99 FlexfecReceiveStream::~FlexfecReceiveStream() { | |
100 LOG(LS_INFO) << "~FlexfecReceiveStream: " << config_.ToString(); | |
101 Stop(); | |
102 } | |
103 | |
104 bool FlexfecReceiveStream::AddAndProcessReceivedPacket(const uint8_t* packet, | |
105 size_t packet_length) { | |
106 { | |
107 rtc::CritScope cs(&crit_); | |
108 if (!started_) | |
109 return false; | |
110 } | |
111 if (!receiver_) | |
112 return false; | |
113 return receiver_->AddAndProcessReceivedPacket(packet, packet_length); | |
114 } | |
115 | |
116 void FlexfecReceiveStream::Start() { | |
117 rtc::CritScope cs(&crit_); | |
118 started_ = true; | |
119 } | |
120 | |
121 void FlexfecReceiveStream::Stop() { | |
122 rtc::CritScope cs(&crit_); | |
123 started_ = false; | |
124 } | |
125 | |
126 // TODO(brandtr): Implement this member function when we have designed the | |
127 // stats for FlexFEC. | |
128 FlexfecReceiveStream::Stats FlexfecReceiveStream::GetStats() const { | |
129 return webrtc::FlexfecReceiveStream::Stats(); | |
130 } | |
131 | |
132 } // namespace internal | |
133 | |
134 } // namespace webrtc | |
OLD | NEW |