| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 <stdio.h> | 11 #include <stdio.h> |
| 12 | 12 |
| 13 #include <map> | 13 #include <map> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <sstream> | 15 #include <sstream> |
| 16 | 16 |
| 17 #include "gflags/gflags.h" | |
| 18 #include "webrtc/api/video_codecs/video_decoder.h" | 17 #include "webrtc/api/video_codecs/video_decoder.h" |
| 19 #include "webrtc/call/call.h" | 18 #include "webrtc/call/call.h" |
| 20 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 21 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 20 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
| 22 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 21 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
| 23 #include "webrtc/rtc_base/checks.h" | 22 #include "webrtc/rtc_base/checks.h" |
| 23 #include "webrtc/rtc_base/flags.h" |
| 24 #include "webrtc/rtc_base/string_to_number.h" |
| 24 #include "webrtc/system_wrappers/include/clock.h" | 25 #include "webrtc/system_wrappers/include/clock.h" |
| 25 #include "webrtc/system_wrappers/include/sleep.h" | 26 #include "webrtc/system_wrappers/include/sleep.h" |
| 26 #include "webrtc/test/call_test.h" | 27 #include "webrtc/test/call_test.h" |
| 27 #include "webrtc/test/encoder_settings.h" | 28 #include "webrtc/test/encoder_settings.h" |
| 28 #include "webrtc/test/fake_decoder.h" | 29 #include "webrtc/test/fake_decoder.h" |
| 29 #include "webrtc/test/gtest.h" | 30 #include "webrtc/test/gtest.h" |
| 30 #include "webrtc/test/null_transport.h" | 31 #include "webrtc/test/null_transport.h" |
| 31 #include "webrtc/test/rtp_file_reader.h" | 32 #include "webrtc/test/rtp_file_reader.h" |
| 32 #include "webrtc/test/run_loop.h" | 33 #include "webrtc/test/run_loop.h" |
| 33 #include "webrtc/test/run_test.h" | 34 #include "webrtc/test/run_test.h" |
| 34 #include "webrtc/test/testsupport/frame_writer.h" | 35 #include "webrtc/test/testsupport/frame_writer.h" |
| 35 #include "webrtc/test/video_capturer.h" | 36 #include "webrtc/test/video_capturer.h" |
| 36 #include "webrtc/test/video_renderer.h" | 37 #include "webrtc/test/video_renderer.h" |
| 37 #include "webrtc/typedefs.h" | 38 #include "webrtc/typedefs.h" |
| 38 | 39 |
| 40 namespace { |
| 41 |
| 42 static bool ValidatePayloadType(int32_t payload_type) { |
| 43 return payload_type > 0 && payload_type <= 127; |
| 44 } |
| 45 |
| 46 static bool ValidateSsrc(const char* ssrc_string) { |
| 47 return rtc::StringToNumber<uint32_t>(ssrc_string).has_value(); |
| 48 } |
| 49 |
| 50 static bool ValidateOptionalPayloadType(int32_t payload_type) { |
| 51 return payload_type == -1 || ValidatePayloadType(payload_type); |
| 52 } |
| 53 |
| 54 static bool ValidateRtpHeaderExtensionId(int32_t extension_id) { |
| 55 return extension_id >= -1 && extension_id < 15; |
| 56 } |
| 57 |
| 58 bool ValidateInputFilenameNotEmpty(const std::string& string) { |
| 59 return !string.empty(); |
| 60 } |
| 61 |
| 62 } // namespace |
| 63 |
| 39 namespace webrtc { | 64 namespace webrtc { |
| 40 namespace flags { | 65 namespace flags { |
| 41 | 66 |
| 42 // TODO(pbos): Multiple receivers. | 67 // TODO(pbos): Multiple receivers. |
| 43 | 68 |
| 44 // Flag for payload type. | 69 // Flag for payload type. |
| 45 static bool ValidatePayloadType(const char* flagname, int32_t payload_type) { | 70 DEFINE_int(payload_type, test::CallTest::kPayloadTypeVP8, "Payload type"); |
| 46 return payload_type > 0 && payload_type <= 127; | 71 static int PayloadType() { return static_cast<int>(FLAG_payload_type); } |
| 72 |
| 73 DEFINE_int(payload_type_rtx, |
| 74 test::CallTest::kSendRtxPayloadType, |
| 75 "RTX payload type"); |
| 76 static int PayloadTypeRtx() { |
| 77 return static_cast<int>(FLAG_payload_type_rtx); |
| 47 } | 78 } |
| 48 DEFINE_int32(payload_type, test::CallTest::kPayloadTypeVP8, "Payload type"); | |
| 49 static int PayloadType() { return static_cast<int>(FLAGS_payload_type); } | |
| 50 static const bool payload_dummy = | |
| 51 google::RegisterFlagValidator(&FLAGS_payload_type, &ValidatePayloadType); | |
| 52 | |
| 53 DEFINE_int32(payload_type_rtx, | |
| 54 test::CallTest::kSendRtxPayloadType, | |
| 55 "RTX payload type"); | |
| 56 static int PayloadTypeRtx() { | |
| 57 return static_cast<int>(FLAGS_payload_type_rtx); | |
| 58 } | |
| 59 static const bool payload_rtx_dummy = | |
| 60 google::RegisterFlagValidator(&FLAGS_payload_type_rtx, | |
| 61 &ValidatePayloadType); | |
| 62 | 79 |
| 63 // Flag for SSRC. | 80 // Flag for SSRC. |
| 64 static bool ValidateSsrc(const char* flagname, uint64_t ssrc) { | 81 const std::string& DefaultSsrc() { |
| 65 return ssrc > 0 && ssrc <= 0xFFFFFFFFu; | 82 static const std::string ssrc = std::to_string( |
| 83 test::CallTest::kVideoSendSsrcs[0]); |
| 84 return ssrc; |
| 85 } |
| 86 DEFINE_string(ssrc, DefaultSsrc().c_str(), "Incoming SSRC"); |
| 87 static uint32_t Ssrc() { |
| 88 return rtc::StringToNumber<uint32_t>(FLAG_ssrc).value(); |
| 66 } | 89 } |
| 67 | 90 |
| 68 DEFINE_uint64(ssrc, test::CallTest::kVideoSendSsrcs[0], "Incoming SSRC"); | 91 const std::string& DefaultSsrcRtx() { |
| 69 static uint32_t Ssrc() { return static_cast<uint32_t>(FLAGS_ssrc); } | 92 static const std::string ssrc_rtx = std::to_string( |
| 70 static const bool ssrc_dummy = | 93 test::CallTest::kSendRtxSsrcs[0]); |
| 71 google::RegisterFlagValidator(&FLAGS_ssrc, &ValidateSsrc); | 94 return ssrc_rtx; |
| 72 | 95 } |
| 73 DEFINE_uint64(ssrc_rtx, test::CallTest::kSendRtxSsrcs[0], "Incoming RTX SSRC"); | 96 DEFINE_string(ssrc_rtx, DefaultSsrcRtx().c_str(), "Incoming RTX SSRC"); |
| 74 static uint32_t SsrcRtx() { | 97 static uint32_t SsrcRtx() { |
| 75 return static_cast<uint32_t>(FLAGS_ssrc_rtx); | 98 return rtc::StringToNumber<uint32_t>(FLAG_ssrc_rtx).value(); |
| 76 } | |
| 77 static const bool ssrc_rtx_dummy = | |
| 78 google::RegisterFlagValidator(&FLAGS_ssrc_rtx, &ValidateSsrc); | |
| 79 | |
| 80 static bool ValidateOptionalPayloadType(const char* flagname, | |
| 81 int32_t payload_type) { | |
| 82 return payload_type == -1 || ValidatePayloadType(flagname, payload_type); | |
| 83 } | 99 } |
| 84 | 100 |
| 85 // Flag for RED payload type. | 101 // Flag for RED payload type. |
| 86 DEFINE_int32(red_payload_type, -1, "RED payload type"); | 102 DEFINE_int(red_payload_type, -1, "RED payload type"); |
| 87 static int RedPayloadType() { | 103 static int RedPayloadType() { |
| 88 return static_cast<int>(FLAGS_red_payload_type); | 104 return static_cast<int>(FLAG_red_payload_type); |
| 89 } | 105 } |
| 90 static const bool red_dummy = | |
| 91 google::RegisterFlagValidator(&FLAGS_red_payload_type, | |
| 92 &ValidateOptionalPayloadType); | |
| 93 | 106 |
| 94 // Flag for ULPFEC payload type. | 107 // Flag for ULPFEC payload type. |
| 95 DEFINE_int32(fec_payload_type, -1, "ULPFEC payload type"); | 108 DEFINE_int(fec_payload_type, -1, "ULPFEC payload type"); |
| 96 static int FecPayloadType() { | 109 static int FecPayloadType() { |
| 97 return static_cast<int>(FLAGS_fec_payload_type); | 110 return static_cast<int>(FLAG_fec_payload_type); |
| 98 } | 111 } |
| 99 static const bool fec_dummy = | |
| 100 google::RegisterFlagValidator(&FLAGS_fec_payload_type, | |
| 101 &ValidateOptionalPayloadType); | |
| 102 | 112 |
| 103 // Flag for abs-send-time id. | 113 // Flag for abs-send-time id. |
| 104 static bool ValidateRtpHeaderExtensionId(const char* flagname, | 114 DEFINE_int(abs_send_time_id, -1, "RTP extension ID for abs-send-time"); |
| 105 int32_t extension_id) { | 115 static int AbsSendTimeId() { return static_cast<int>(FLAG_abs_send_time_id); } |
| 106 return extension_id >= -1 || extension_id < 15; | |
| 107 } | |
| 108 DEFINE_int32(abs_send_time_id, -1, "RTP extension ID for abs-send-time"); | |
| 109 static int AbsSendTimeId() { return static_cast<int>(FLAGS_abs_send_time_id); } | |
| 110 static const bool abs_send_time_dummy = | |
| 111 google::RegisterFlagValidator(&FLAGS_abs_send_time_id, | |
| 112 &ValidateRtpHeaderExtensionId); | |
| 113 | 116 |
| 114 // Flag for transmission-offset id. | 117 // Flag for transmission-offset id. |
| 115 DEFINE_int32(transmission_offset_id, | 118 DEFINE_int(transmission_offset_id, |
| 116 -1, | 119 -1, |
| 117 "RTP extension ID for transmission-offset"); | 120 "RTP extension ID for transmission-offset"); |
| 118 static int TransmissionOffsetId() { | 121 static int TransmissionOffsetId() { |
| 119 return static_cast<int>(FLAGS_transmission_offset_id); | 122 return static_cast<int>(FLAG_transmission_offset_id); |
| 120 } | 123 } |
| 121 static const bool timestamp_offset_dummy = | |
| 122 google::RegisterFlagValidator(&FLAGS_transmission_offset_id, | |
| 123 &ValidateRtpHeaderExtensionId); | |
| 124 | 124 |
| 125 // Flag for rtpdump input file. | 125 // Flag for rtpdump input file. |
| 126 bool ValidateInputFilenameNotEmpty(const char* flagname, | |
| 127 const std::string& string) { | |
| 128 return !string.empty(); | |
| 129 } | |
| 130 | |
| 131 DEFINE_string(input_file, "", "input file"); | 126 DEFINE_string(input_file, "", "input file"); |
| 132 static std::string InputFile() { | 127 static std::string InputFile() { |
| 133 return static_cast<std::string>(FLAGS_input_file); | 128 return static_cast<std::string>(FLAG_input_file); |
| 134 } | 129 } |
| 135 static const bool input_file_dummy = | |
| 136 google::RegisterFlagValidator(&FLAGS_input_file, | |
| 137 &ValidateInputFilenameNotEmpty); | |
| 138 | 130 |
| 139 // Flag for raw output files. | 131 // Flag for raw output files. |
| 140 DEFINE_string(out_base, "", "Basename (excluding .jpg) for raw output"); | 132 DEFINE_string(out_base, "", "Basename (excluding .jpg) for raw output"); |
| 141 static std::string OutBase() { | 133 static std::string OutBase() { |
| 142 return static_cast<std::string>(FLAGS_out_base); | 134 return static_cast<std::string>(FLAG_out_base); |
| 143 } | 135 } |
| 144 | 136 |
| 145 DEFINE_string(decoder_bitstream_filename, "", "Decoder bitstream output file"); | 137 DEFINE_string(decoder_bitstream_filename, "", "Decoder bitstream output file"); |
| 146 static std::string DecoderBitstreamFilename() { | 138 static std::string DecoderBitstreamFilename() { |
| 147 return static_cast<std::string>(FLAGS_decoder_bitstream_filename); | 139 return static_cast<std::string>(FLAG_decoder_bitstream_filename); |
| 148 } | 140 } |
| 149 | 141 |
| 150 // Flag for video codec. | 142 // Flag for video codec. |
| 151 DEFINE_string(codec, "VP8", "Video codec"); | 143 DEFINE_string(codec, "VP8", "Video codec"); |
| 152 static std::string Codec() { return static_cast<std::string>(FLAGS_codec); } | 144 static std::string Codec() { return static_cast<std::string>(FLAG_codec); } |
| 153 | 145 |
| 146 DEFINE_bool(help, false, "Print this message."); |
| 154 } // namespace flags | 147 } // namespace flags |
| 155 | 148 |
| 156 static const uint32_t kReceiverLocalSsrc = 0x123456; | 149 static const uint32_t kReceiverLocalSsrc = 0x123456; |
| 157 | 150 |
| 158 class FileRenderPassthrough : public rtc::VideoSinkInterface<VideoFrame> { | 151 class FileRenderPassthrough : public rtc::VideoSinkInterface<VideoFrame> { |
| 159 public: | 152 public: |
| 160 FileRenderPassthrough(const std::string& basename, | 153 FileRenderPassthrough(const std::string& basename, |
| 161 rtc::VideoSinkInterface<VideoFrame>* renderer) | 154 rtc::VideoSinkInterface<VideoFrame>* renderer) |
| 162 : basename_(basename), renderer_(renderer), file_(nullptr), count_(0) {} | 155 : basename_(basename), renderer_(renderer), file_(nullptr), count_(0) {} |
| 163 | 156 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 316 } |
| 324 | 317 |
| 325 call->DestroyVideoReceiveStream(receive_stream); | 318 call->DestroyVideoReceiveStream(receive_stream); |
| 326 | 319 |
| 327 delete decoder.decoder; | 320 delete decoder.decoder; |
| 328 } | 321 } |
| 329 } // namespace webrtc | 322 } // namespace webrtc |
| 330 | 323 |
| 331 int main(int argc, char* argv[]) { | 324 int main(int argc, char* argv[]) { |
| 332 ::testing::InitGoogleTest(&argc, argv); | 325 ::testing::InitGoogleTest(&argc, argv); |
| 333 google::ParseCommandLineFlags(&argc, &argv, true); | 326 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { |
| 327 return 1; |
| 328 } |
| 329 if (webrtc::flags::FLAG_help) { |
| 330 rtc::FlagList::Print(nullptr, false); |
| 331 return 0; |
| 332 } |
| 333 |
| 334 RTC_CHECK(ValidatePayloadType(webrtc::flags::FLAG_payload_type)); |
| 335 RTC_CHECK(ValidatePayloadType(webrtc::flags::FLAG_payload_type_rtx)); |
| 336 RTC_CHECK(ValidateSsrc(webrtc::flags::FLAG_ssrc)); |
| 337 RTC_CHECK(ValidateSsrc(webrtc::flags::FLAG_ssrc_rtx)); |
| 338 RTC_CHECK(ValidateOptionalPayloadType(webrtc::flags::FLAG_red_payload_type)); |
| 339 RTC_CHECK(ValidateOptionalPayloadType(webrtc::flags::FLAG_fec_payload_type)); |
| 340 RTC_CHECK(ValidateRtpHeaderExtensionId(webrtc::flags::FLAG_abs_send_time_id)); |
| 341 RTC_CHECK(ValidateRtpHeaderExtensionId( |
| 342 webrtc::flags::FLAG_transmission_offset_id)); |
| 343 RTC_CHECK(ValidateInputFilenameNotEmpty(webrtc::flags::FLAG_input_file)); |
| 334 | 344 |
| 335 webrtc::test::RunTest(webrtc::RtpReplay); | 345 webrtc::test::RunTest(webrtc::RtpReplay); |
| 336 return 0; | 346 return 0; |
| 337 } | 347 } |
| OLD | NEW |