| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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/rtp_player.h" | 11 #include "webrtc/modules/video_coding/test/rtp_player.h" |
| 12 | 12 |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 | 14 |
| 15 #include <map> | 15 #include <map> |
| 16 #include <memory> |
| 16 | 17 |
| 17 #include "webrtc/base/scoped_ptr.h" | |
| 18 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 18 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
| 19 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" | 19 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
| 20 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 20 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
| 21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 22 #include "webrtc/modules/video_coding/internal_defines.h" | 22 #include "webrtc/modules/video_coding/internal_defines.h" |
| 23 #include "webrtc/modules/video_coding/test/test_util.h" | 23 #include "webrtc/modules/video_coding/test/test_util.h" |
| 24 #include "webrtc/system_wrappers/include/clock.h" | 24 #include "webrtc/system_wrappers/include/clock.h" |
| 25 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 25 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 26 #include "webrtc/test/rtp_file_reader.h" | 26 #include "webrtc/test/rtp_file_reader.h" |
| 27 | 27 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 const uint8_t* data() const { return data_.get(); } | 57 const uint8_t* data() const { return data_.get(); } |
| 58 size_t length() const { return length_; } | 58 size_t length() const { return length_; } |
| 59 int64_t resend_time_ms() const { return resend_time_ms_; } | 59 int64_t resend_time_ms() const { return resend_time_ms_; } |
| 60 void set_resend_time_ms(int64_t timeMs) { resend_time_ms_ = timeMs; } | 60 void set_resend_time_ms(int64_t timeMs) { resend_time_ms_ = timeMs; } |
| 61 uint32_t ssrc() const { return ssrc_; } | 61 uint32_t ssrc() const { return ssrc_; } |
| 62 uint16_t seq_num() const { return seq_num_; } | 62 uint16_t seq_num() const { return seq_num_; } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 rtc::scoped_ptr<uint8_t[]> data_; | 65 std::unique_ptr<uint8_t[]> data_; |
| 66 size_t length_; | 66 size_t length_; |
| 67 int64_t resend_time_ms_; | 67 int64_t resend_time_ms_; |
| 68 uint32_t ssrc_; | 68 uint32_t ssrc_; |
| 69 uint16_t seq_num_; | 69 uint16_t seq_num_; |
| 70 | 70 |
| 71 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RawRtpPacket); | 71 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RawRtpPacket); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 class LostPackets { | 74 class LostPackets { |
| 75 public: | 75 public: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 printf("%u, ", (*it)->seq_num()); | 170 printf("%u, ", (*it)->seq_num()); |
| 171 } | 171 } |
| 172 printf("\n"); | 172 printf("\n"); |
| 173 } | 173 } |
| 174 | 174 |
| 175 private: | 175 private: |
| 176 typedef std::vector<RawRtpPacket*> RtpPacketList; | 176 typedef std::vector<RawRtpPacket*> RtpPacketList; |
| 177 typedef RtpPacketList::iterator RtpPacketIterator; | 177 typedef RtpPacketList::iterator RtpPacketIterator; |
| 178 typedef RtpPacketList::const_iterator ConstRtpPacketIterator; | 178 typedef RtpPacketList::const_iterator ConstRtpPacketIterator; |
| 179 | 179 |
| 180 rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_; | 180 std::unique_ptr<CriticalSectionWrapper> crit_sect_; |
| 181 FILE* debug_file_; | 181 FILE* debug_file_; |
| 182 int loss_count_; | 182 int loss_count_; |
| 183 RtpPacketList packets_; | 183 RtpPacketList packets_; |
| 184 Clock* clock_; | 184 Clock* clock_; |
| 185 int64_t rtt_ms_; | 185 int64_t rtt_ms_; |
| 186 | 186 |
| 187 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(LostPackets); | 187 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(LostPackets); |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 class SsrcHandlers { | 190 class SsrcHandlers { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 203 handlers_.erase(handlers_.begin()); | 203 handlers_.erase(handlers_.begin()); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 int RegisterSsrc(uint32_t ssrc, LostPackets* lost_packets, Clock* clock) { | 207 int RegisterSsrc(uint32_t ssrc, LostPackets* lost_packets, Clock* clock) { |
| 208 if (handlers_.count(ssrc) > 0) { | 208 if (handlers_.count(ssrc) > 0) { |
| 209 return 0; | 209 return 0; |
| 210 } | 210 } |
| 211 DEBUG_LOG1("Registering handler for ssrc=%08x", ssrc); | 211 DEBUG_LOG1("Registering handler for ssrc=%08x", ssrc); |
| 212 | 212 |
| 213 rtc::scoped_ptr<Handler> handler( | 213 std::unique_ptr<Handler> handler( |
| 214 new Handler(ssrc, payload_types_, lost_packets)); | 214 new Handler(ssrc, payload_types_, lost_packets)); |
| 215 handler->payload_sink_.reset(payload_sink_factory_->Create(handler.get())); | 215 handler->payload_sink_.reset(payload_sink_factory_->Create(handler.get())); |
| 216 if (handler->payload_sink_.get() == NULL) { | 216 if (handler->payload_sink_.get() == NULL) { |
| 217 return -1; | 217 return -1; |
| 218 } | 218 } |
| 219 | 219 |
| 220 RtpRtcp::Configuration configuration; | 220 RtpRtcp::Configuration configuration; |
| 221 configuration.clock = clock; | 221 configuration.clock = clock; |
| 222 configuration.audio = false; | 222 configuration.audio = false; |
| 223 handler->rtp_module_.reset(RtpReceiver::CreateVideoReceiver( | 223 handler->rtp_module_.reset(RtpReceiver::CreateVideoReceiver( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 uint16_t length) { | 285 uint16_t length) { |
| 286 assert(sequence_numbers); | 286 assert(sequence_numbers); |
| 287 for (uint16_t i = 0; i < length; i++) { | 287 for (uint16_t i = 0; i < length; i++) { |
| 288 lost_packets_->SetResendTime(ssrc_, sequence_numbers[i]); | 288 lost_packets_->SetResendTime(ssrc_, sequence_numbers[i]); |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 | 291 |
| 292 virtual uint32_t ssrc() const { return ssrc_; } | 292 virtual uint32_t ssrc() const { return ssrc_; } |
| 293 virtual const PayloadTypes& payload_types() const { return payload_types_; } | 293 virtual const PayloadTypes& payload_types() const { return payload_types_; } |
| 294 | 294 |
| 295 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser_; | 295 std::unique_ptr<RtpHeaderParser> rtp_header_parser_; |
| 296 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_; | 296 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_; |
| 297 rtc::scoped_ptr<RtpReceiver> rtp_module_; | 297 std::unique_ptr<RtpReceiver> rtp_module_; |
| 298 rtc::scoped_ptr<PayloadSinkInterface> payload_sink_; | 298 std::unique_ptr<PayloadSinkInterface> payload_sink_; |
| 299 | 299 |
| 300 private: | 300 private: |
| 301 uint32_t ssrc_; | 301 uint32_t ssrc_; |
| 302 const PayloadTypes& payload_types_; | 302 const PayloadTypes& payload_types_; |
| 303 LostPackets* lost_packets_; | 303 LostPackets* lost_packets_; |
| 304 | 304 |
| 305 RTC_DISALLOW_COPY_AND_ASSIGN(Handler); | 305 RTC_DISALLOW_COPY_AND_ASSIGN(Handler); |
| 306 }; | 306 }; |
| 307 | 307 |
| 308 typedef std::map<uint32_t, Handler*> HandlerMap; | 308 typedef std::map<uint32_t, Handler*> HandlerMap; |
| 309 typedef std::map<uint32_t, Handler*>::iterator HandlerMapIt; | 309 typedef std::map<uint32_t, Handler*>::iterator HandlerMapIt; |
| 310 | 310 |
| 311 PayloadSinkFactoryInterface* payload_sink_factory_; | 311 PayloadSinkFactoryInterface* payload_sink_factory_; |
| 312 PayloadTypes payload_types_; | 312 PayloadTypes payload_types_; |
| 313 HandlerMap handlers_; | 313 HandlerMap handlers_; |
| 314 | 314 |
| 315 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SsrcHandlers); | 315 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SsrcHandlers); |
| 316 }; | 316 }; |
| 317 | 317 |
| 318 class RtpPlayerImpl : public RtpPlayerInterface { | 318 class RtpPlayerImpl : public RtpPlayerInterface { |
| 319 public: | 319 public: |
| 320 RtpPlayerImpl(PayloadSinkFactoryInterface* payload_sink_factory, | 320 RtpPlayerImpl(PayloadSinkFactoryInterface* payload_sink_factory, |
| 321 const PayloadTypes& payload_types, | 321 const PayloadTypes& payload_types, |
| 322 Clock* clock, | 322 Clock* clock, |
| 323 rtc::scoped_ptr<test::RtpFileReader>* packet_source, | 323 std::unique_ptr<test::RtpFileReader>* packet_source, |
| 324 float loss_rate, | 324 float loss_rate, |
| 325 int64_t rtt_ms, | 325 int64_t rtt_ms, |
| 326 bool reordering) | 326 bool reordering) |
| 327 : ssrc_handlers_(payload_sink_factory, payload_types), | 327 : ssrc_handlers_(payload_sink_factory, payload_types), |
| 328 clock_(clock), | 328 clock_(clock), |
| 329 next_rtp_time_(0), | 329 next_rtp_time_(0), |
| 330 first_packet_(true), | 330 first_packet_(true), |
| 331 first_packet_rtp_time_(0), | 331 first_packet_rtp_time_(0), |
| 332 first_packet_time_ms_(0), | 332 first_packet_time_ms_(0), |
| 333 loss_rate_(loss_rate), | 333 loss_rate_(loss_rate), |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 virtual void Print() const { | 412 virtual void Print() const { |
| 413 printf("Resent packets: %u\n", resend_packet_count_); | 413 printf("Resent packets: %u\n", resend_packet_count_); |
| 414 lost_packets_.Print(); | 414 lost_packets_.Print(); |
| 415 } | 415 } |
| 416 | 416 |
| 417 private: | 417 private: |
| 418 int SendPacket(const uint8_t* data, size_t length) { | 418 int SendPacket(const uint8_t* data, size_t length) { |
| 419 assert(data); | 419 assert(data); |
| 420 assert(length > 0); | 420 assert(length > 0); |
| 421 | 421 |
| 422 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser( | 422 std::unique_ptr<RtpHeaderParser> rtp_header_parser( |
| 423 RtpHeaderParser::Create()); | 423 RtpHeaderParser::Create()); |
| 424 if (!rtp_header_parser->IsRtcp(data, length)) { | 424 if (!rtp_header_parser->IsRtcp(data, length)) { |
| 425 RTPHeader header; | 425 RTPHeader header; |
| 426 if (!rtp_header_parser->Parse(data, length, &header)) { | 426 if (!rtp_header_parser->Parse(data, length, &header)) { |
| 427 return -1; | 427 return -1; |
| 428 } | 428 } |
| 429 uint32_t ssrc = header.ssrc; | 429 uint32_t ssrc = header.ssrc; |
| 430 if (ssrc_handlers_.RegisterSsrc(ssrc, &lost_packets_, clock_) < 0) { | 430 if (ssrc_handlers_.RegisterSsrc(ssrc, &lost_packets_, clock_) < 0) { |
| 431 DEBUG_LOG1("Unable to register ssrc: %d", ssrc); | 431 DEBUG_LOG1("Unable to register ssrc: %d", ssrc); |
| 432 return -1; | 432 return -1; |
| 433 } | 433 } |
| 434 | 434 |
| 435 if (no_loss_startup_ > 0) { | 435 if (no_loss_startup_ > 0) { |
| 436 no_loss_startup_--; | 436 no_loss_startup_--; |
| 437 } else if ((rand() + 1.0) / (RAND_MAX + 1.0) < loss_rate_) { // NOLINT | 437 } else if ((rand() + 1.0) / (RAND_MAX + 1.0) < loss_rate_) { // NOLINT |
| 438 uint16_t seq_num = header.sequenceNumber; | 438 uint16_t seq_num = header.sequenceNumber; |
| 439 lost_packets_.AddPacket(new RawRtpPacket(data, length, ssrc, seq_num)); | 439 lost_packets_.AddPacket(new RawRtpPacket(data, length, ssrc, seq_num)); |
| 440 DEBUG_LOG1("Dropped packet: %d!", header.header.sequenceNumber); | 440 DEBUG_LOG1("Dropped packet: %d!", header.header.sequenceNumber); |
| 441 return 0; | 441 return 0; |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 | 444 |
| 445 ssrc_handlers_.IncomingPacket(data, length); | 445 ssrc_handlers_.IncomingPacket(data, length); |
| 446 return 1; | 446 return 1; |
| 447 } | 447 } |
| 448 | 448 |
| 449 SsrcHandlers ssrc_handlers_; | 449 SsrcHandlers ssrc_handlers_; |
| 450 Clock* clock_; | 450 Clock* clock_; |
| 451 rtc::scoped_ptr<test::RtpFileReader> packet_source_; | 451 std::unique_ptr<test::RtpFileReader> packet_source_; |
| 452 test::RtpPacket next_packet_; | 452 test::RtpPacket next_packet_; |
| 453 uint32_t next_rtp_time_; | 453 uint32_t next_rtp_time_; |
| 454 bool first_packet_; | 454 bool first_packet_; |
| 455 int64_t first_packet_rtp_time_; | 455 int64_t first_packet_rtp_time_; |
| 456 int64_t first_packet_time_ms_; | 456 int64_t first_packet_time_ms_; |
| 457 float loss_rate_; | 457 float loss_rate_; |
| 458 LostPackets lost_packets_; | 458 LostPackets lost_packets_; |
| 459 uint32_t resend_packet_count_; | 459 uint32_t resend_packet_count_; |
| 460 uint32_t no_loss_startup_; | 460 uint32_t no_loss_startup_; |
| 461 bool end_of_file_; | 461 bool end_of_file_; |
| 462 bool reordering_; | 462 bool reordering_; |
| 463 rtc::scoped_ptr<RawRtpPacket> reorder_buffer_; | 463 std::unique_ptr<RawRtpPacket> reorder_buffer_; |
| 464 | 464 |
| 465 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtpPlayerImpl); | 465 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtpPlayerImpl); |
| 466 }; | 466 }; |
| 467 | 467 |
| 468 RtpPlayerInterface* Create(const std::string& input_filename, | 468 RtpPlayerInterface* Create(const std::string& input_filename, |
| 469 PayloadSinkFactoryInterface* payload_sink_factory, | 469 PayloadSinkFactoryInterface* payload_sink_factory, |
| 470 Clock* clock, | 470 Clock* clock, |
| 471 const PayloadTypes& payload_types, | 471 const PayloadTypes& payload_types, |
| 472 float loss_rate, | 472 float loss_rate, |
| 473 int64_t rtt_ms, | 473 int64_t rtt_ms, |
| 474 bool reordering) { | 474 bool reordering) { |
| 475 rtc::scoped_ptr<test::RtpFileReader> packet_source( | 475 std::unique_ptr<test::RtpFileReader> packet_source( |
| 476 test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, | 476 test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, |
| 477 input_filename)); | 477 input_filename)); |
| 478 if (packet_source.get() == NULL) { | 478 if (packet_source.get() == NULL) { |
| 479 packet_source.reset(test::RtpFileReader::Create(test::RtpFileReader::kPcap, | 479 packet_source.reset(test::RtpFileReader::Create(test::RtpFileReader::kPcap, |
| 480 input_filename)); | 480 input_filename)); |
| 481 if (packet_source.get() == NULL) { | 481 if (packet_source.get() == NULL) { |
| 482 return NULL; | 482 return NULL; |
| 483 } | 483 } |
| 484 } | 484 } |
| 485 | 485 |
| 486 rtc::scoped_ptr<RtpPlayerImpl> impl( | 486 std::unique_ptr<RtpPlayerImpl> impl( |
| 487 new RtpPlayerImpl(payload_sink_factory, payload_types, clock, | 487 new RtpPlayerImpl(payload_sink_factory, payload_types, clock, |
| 488 &packet_source, loss_rate, rtt_ms, reordering)); | 488 &packet_source, loss_rate, rtt_ms, reordering)); |
| 489 return impl.release(); | 489 return impl.release(); |
| 490 } | 490 } |
| 491 } // namespace rtpplayer | 491 } // namespace rtpplayer |
| 492 } // namespace webrtc | 492 } // namespace webrtc |
| OLD | NEW |