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