OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/video_coding/test/vcm_payload_sink_factory.h" | 11 #include "webrtc/modules/video_coding/test/vcm_payload_sink_factory.h" |
12 | 12 |
13 #include <assert.h> | |
14 | |
15 #include <algorithm> | 13 #include <algorithm> |
16 | 14 |
| 15 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
19 #include "webrtc/modules/video_coding/test/test_util.h" | 18 #include "webrtc/modules/video_coding/test/test_util.h" |
20 #include "webrtc/system_wrappers/include/clock.h" | 19 #include "webrtc/system_wrappers/include/clock.h" |
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 20 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 namespace rtpplayer { | 23 namespace rtpplayer { |
25 | 24 |
26 class VcmPayloadSinkFactory::VcmPayloadSink : public PayloadSinkInterface, | 25 class VcmPayloadSinkFactory::VcmPayloadSink : public PayloadSinkInterface, |
27 public VCMPacketRequestCallback { | 26 public VCMPacketRequestCallback { |
28 public: | 27 public: |
29 VcmPayloadSink(VcmPayloadSinkFactory* factory, | 28 VcmPayloadSink(VcmPayloadSinkFactory* factory, |
30 RtpStreamInterface* stream, | 29 RtpStreamInterface* stream, |
31 std::unique_ptr<VideoCodingModule>* vcm, | 30 std::unique_ptr<VideoCodingModule> vcm, |
32 std::unique_ptr<FileOutputFrameReceiver>* frame_receiver) | 31 std::unique_ptr<FileOutputFrameReceiver> frame_receiver) |
33 : factory_(factory), stream_(stream), vcm_(), frame_receiver_() { | 32 : factory_(factory), |
34 assert(factory); | 33 stream_(stream), |
35 assert(stream); | 34 vcm_(std::move(vcm)), |
36 assert(vcm); | 35 frame_receiver_(std::move(frame_receiver)) { |
37 assert(vcm->get()); | 36 RTC_DCHECK(factory); |
38 assert(frame_receiver); | 37 RTC_DCHECK(stream); |
39 assert(frame_receiver->get()); | 38 RTC_DCHECK(vcm_); |
40 vcm_.swap(*vcm); | 39 RTC_DCHECK(frame_receiver_); |
41 frame_receiver_.swap(*frame_receiver); | |
42 vcm_->RegisterPacketRequestCallback(this); | 40 vcm_->RegisterPacketRequestCallback(this); |
43 vcm_->RegisterReceiveCallback(frame_receiver_.get()); | 41 vcm_->RegisterReceiveCallback(frame_receiver_.get()); |
44 } | 42 } |
45 | 43 |
46 virtual ~VcmPayloadSink() { factory_->Remove(this); } | 44 ~VcmPayloadSink() override { factory_->Remove(this); } |
47 | 45 |
48 // PayloadSinkInterface | 46 // PayloadSinkInterface |
49 int32_t OnReceivedPayloadData(const uint8_t* payload_data, | 47 int32_t OnReceivedPayloadData(const uint8_t* payload_data, |
50 size_t payload_size, | 48 size_t payload_size, |
51 const WebRtcRTPHeader* rtp_header) override { | 49 const WebRtcRTPHeader* rtp_header) override { |
52 return vcm_->IncomingPacket(payload_data, payload_size, *rtp_header); | 50 return vcm_->IncomingPacket(payload_data, payload_size, *rtp_header); |
53 } | 51 } |
54 | 52 |
55 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override { | 53 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override { |
56 // We currently don't handle FEC. | 54 // We currently don't handle FEC. |
(...skipping 22 matching lines...) Expand all Loading... |
79 } | 77 } |
80 return true; | 78 return true; |
81 } | 79 } |
82 | 80 |
83 bool Decode() { | 81 bool Decode() { |
84 vcm_->Decode(10000); | 82 vcm_->Decode(10000); |
85 return true; | 83 return true; |
86 } | 84 } |
87 | 85 |
88 private: | 86 private: |
89 VcmPayloadSinkFactory* factory_; | 87 VcmPayloadSinkFactory* const factory_; |
90 RtpStreamInterface* stream_; | 88 RtpStreamInterface* const stream_; |
91 std::unique_ptr<VideoCodingModule> vcm_; | 89 std::unique_ptr<VideoCodingModule> vcm_; |
92 std::unique_ptr<FileOutputFrameReceiver> frame_receiver_; | 90 std::unique_ptr<FileOutputFrameReceiver> frame_receiver_; |
93 | 91 |
94 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(VcmPayloadSink); | 92 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(VcmPayloadSink); |
95 }; | 93 }; |
96 | 94 |
97 VcmPayloadSinkFactory::VcmPayloadSinkFactory( | 95 VcmPayloadSinkFactory::VcmPayloadSinkFactory( |
98 const std::string& base_out_filename, | 96 const std::string& base_out_filename, |
99 Clock* clock, | 97 Clock* clock, |
100 bool protection_enabled, | 98 bool protection_enabled, |
101 VCMVideoProtection protection_method, | 99 VCMVideoProtection protection_method, |
102 int64_t rtt_ms, | 100 int64_t rtt_ms, |
103 uint32_t render_delay_ms, | 101 uint32_t render_delay_ms, |
104 uint32_t min_playout_delay_ms) | 102 uint32_t min_playout_delay_ms) |
105 : base_out_filename_(base_out_filename), | 103 : base_out_filename_(base_out_filename), |
106 clock_(clock), | 104 clock_(clock), |
107 protection_enabled_(protection_enabled), | 105 protection_enabled_(protection_enabled), |
108 protection_method_(protection_method), | 106 protection_method_(protection_method), |
109 rtt_ms_(rtt_ms), | 107 rtt_ms_(rtt_ms), |
110 render_delay_ms_(render_delay_ms), | 108 render_delay_ms_(render_delay_ms), |
111 min_playout_delay_ms_(min_playout_delay_ms), | 109 min_playout_delay_ms_(min_playout_delay_ms), |
112 null_event_factory_(new NullEventFactory()), | 110 null_event_factory_(new NullEventFactory()), |
113 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | 111 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
114 sinks_() { | 112 sinks_() { |
115 assert(clock); | 113 RTC_DCHECK(clock); |
116 assert(crit_sect_.get()); | 114 RTC_DCHECK(crit_sect_.get()); |
117 } | 115 } |
118 | 116 |
119 VcmPayloadSinkFactory::~VcmPayloadSinkFactory() { | 117 VcmPayloadSinkFactory::~VcmPayloadSinkFactory() { |
120 assert(sinks_.empty()); | 118 RTC_DCHECK(sinks_.empty()); |
121 } | 119 } |
122 | 120 |
123 PayloadSinkInterface* VcmPayloadSinkFactory::Create( | 121 PayloadSinkInterface* VcmPayloadSinkFactory::Create( |
124 RtpStreamInterface* stream) { | 122 RtpStreamInterface* stream) { |
125 assert(stream); | 123 RTC_DCHECK(stream); |
126 CriticalSectionScoped cs(crit_sect_.get()); | 124 CriticalSectionScoped cs(crit_sect_.get()); |
127 | 125 |
128 std::unique_ptr<VideoCodingModule> vcm( | 126 std::unique_ptr<VideoCodingModule> vcm( |
129 VideoCodingModule::Create(clock_, null_event_factory_.get())); | 127 VideoCodingModule::Create(clock_, null_event_factory_.get())); |
130 if (vcm.get() == NULL) { | 128 if (vcm.get() == NULL) { |
131 return NULL; | 129 return NULL; |
132 } | 130 } |
133 | 131 |
134 const PayloadTypes& plt = stream->payload_types(); | 132 const PayloadTypes& plt = stream->payload_types(); |
135 for (PayloadTypesIterator it = plt.begin(); it != plt.end(); ++it) { | 133 for (PayloadTypesIterator it = plt.begin(); it != plt.end(); ++it) { |
136 if (it->codec_type() != kVideoCodecULPFEC && | 134 if (it->codec_type() != kVideoCodecULPFEC && |
137 it->codec_type() != kVideoCodecRED) { | 135 it->codec_type() != kVideoCodecRED) { |
138 VideoCodec codec; | 136 VideoCodec codec; |
139 VideoCodingModule::Codec(it->codec_type(), &codec); | 137 VideoCodingModule::Codec(it->codec_type(), &codec); |
140 codec.plType = it->payload_type(); | 138 codec.plType = it->payload_type(); |
141 if (vcm->RegisterReceiveCodec(&codec, 1) < 0) { | 139 if (vcm->RegisterReceiveCodec(&codec, 1) < 0) { |
142 return NULL; | 140 return NULL; |
143 } | 141 } |
144 } | 142 } |
145 } | 143 } |
146 | 144 |
147 vcm->SetChannelParameters(0, 0, rtt_ms_); | 145 vcm->SetChannelParameters(0, 0, rtt_ms_); |
148 vcm->SetVideoProtection(protection_method_, protection_enabled_); | 146 vcm->SetVideoProtection(protection_method_, protection_enabled_); |
149 vcm->SetRenderDelay(render_delay_ms_); | 147 vcm->SetRenderDelay(render_delay_ms_); |
150 vcm->SetMinimumPlayoutDelay(min_playout_delay_ms_); | 148 vcm->SetMinimumPlayoutDelay(min_playout_delay_ms_); |
151 vcm->SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, 0); | 149 vcm->SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, 0); |
152 | 150 |
153 std::unique_ptr<FileOutputFrameReceiver> frame_receiver( | 151 std::unique_ptr<FileOutputFrameReceiver> frame_receiver( |
154 new FileOutputFrameReceiver(base_out_filename_, stream->ssrc())); | 152 new FileOutputFrameReceiver(base_out_filename_, stream->ssrc())); |
155 std::unique_ptr<VcmPayloadSink> sink( | 153 std::unique_ptr<VcmPayloadSink> sink(new VcmPayloadSink( |
156 new VcmPayloadSink(this, stream, &vcm, &frame_receiver)); | 154 this, stream, std::move(vcm), std::move(frame_receiver))); |
157 | 155 |
158 sinks_.push_back(sink.get()); | 156 sinks_.push_back(sink.get()); |
159 return sink.release(); | 157 return sink.release(); |
160 } | 158 } |
161 | 159 |
162 int VcmPayloadSinkFactory::DecodeAndProcessAll(bool decode_dual_frame) { | 160 int VcmPayloadSinkFactory::DecodeAndProcessAll(bool decode_dual_frame) { |
163 CriticalSectionScoped cs(crit_sect_.get()); | 161 CriticalSectionScoped cs(crit_sect_.get()); |
164 assert(clock_); | 162 RTC_DCHECK(clock_); |
165 bool should_decode = (clock_->TimeInMilliseconds() % 5) == 0; | 163 bool should_decode = (clock_->TimeInMilliseconds() % 5) == 0; |
166 for (Sinks::iterator it = sinks_.begin(); it != sinks_.end(); ++it) { | 164 for (Sinks::iterator it = sinks_.begin(); it != sinks_.end(); ++it) { |
167 if ((*it)->DecodeAndProcess(should_decode, decode_dual_frame) < 0) { | 165 if ((*it)->DecodeAndProcess(should_decode, decode_dual_frame) < 0) { |
168 return -1; | 166 return -1; |
169 } | 167 } |
170 } | 168 } |
171 return 0; | 169 return 0; |
172 } | 170 } |
173 | 171 |
174 bool VcmPayloadSinkFactory::ProcessAll() { | 172 bool VcmPayloadSinkFactory::ProcessAll() { |
(...skipping 10 matching lines...) Expand all Loading... |
185 CriticalSectionScoped cs(crit_sect_.get()); | 183 CriticalSectionScoped cs(crit_sect_.get()); |
186 for (Sinks::iterator it = sinks_.begin(); it != sinks_.end(); ++it) { | 184 for (Sinks::iterator it = sinks_.begin(); it != sinks_.end(); ++it) { |
187 if (!(*it)->Decode()) { | 185 if (!(*it)->Decode()) { |
188 return false; | 186 return false; |
189 } | 187 } |
190 } | 188 } |
191 return true; | 189 return true; |
192 } | 190 } |
193 | 191 |
194 void VcmPayloadSinkFactory::Remove(VcmPayloadSink* sink) { | 192 void VcmPayloadSinkFactory::Remove(VcmPayloadSink* sink) { |
195 assert(sink); | 193 RTC_DCHECK(sink); |
196 CriticalSectionScoped cs(crit_sect_.get()); | 194 CriticalSectionScoped cs(crit_sect_.get()); |
197 Sinks::iterator it = std::find(sinks_.begin(), sinks_.end(), sink); | 195 Sinks::iterator it = std::find(sinks_.begin(), sinks_.end(), sink); |
198 assert(it != sinks_.end()); | 196 RTC_DCHECK(it != sinks_.end()); |
199 sinks_.erase(it); | 197 sinks_.erase(it); |
200 } | 198 } |
201 | 199 |
202 } // namespace rtpplayer | 200 } // namespace rtpplayer |
203 } // namespace webrtc | 201 } // namespace webrtc |
OLD | NEW |