pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 <stdio.h> |
| 12 | |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 13 | #include <fstream> |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 14 | #include <map> |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 15 | #include <memory> |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 17 | #include "absl/flags/flag.h" |
| 18 | #include "absl/flags/parse.h" |
philipel | 525891a | 2022-10-03 14:54:09 +0200 | [diff] [blame] | 19 | #include "api/field_trials.h" |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 20 | #include "api/media_types.h" |
Danil Chapovalov | 83bbe91 | 2019-08-07 12:24:53 +0200 | [diff] [blame] | 21 | #include "api/rtc_event_log/rtc_event_log.h" |
Sergey Silkin | 626f7ff | 2019-09-12 10:51:19 +0200 | [diff] [blame] | 22 | #include "api/task_queue/default_task_queue_factory.h" |
Danil Chapovalov | 99b71df | 2018-10-26 15:57:48 +0200 | [diff] [blame] | 23 | #include "api/test/video/function_video_decoder_factory.h" |
Ilya Nikolaevskiy | 33aaa35 | 2020-01-21 13:38:19 +0100 | [diff] [blame] | 24 | #include "api/transport/field_trial_based_config.h" |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 25 | #include "api/units/timestamp.h" |
Philipp Hancke | fae4fb1 | 2021-01-26 18:05:56 +0100 | [diff] [blame] | 26 | #include "api/video/video_codec_type.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "api/video_codecs/video_decoder.h" |
| 28 | #include "call/call.h" |
| 29 | #include "common_video/libyuv/include/webrtc_libyuv.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 30 | #include "media/engine/internal_decoder_factory.h" |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 31 | #include "modules/rtp_rtcp/include/rtp_header_extension_map.h" |
Danil Chapovalov | 76a35d9 | 2021-06-08 12:30:46 +0200 | [diff] [blame] | 32 | #include "modules/rtp_rtcp/source/rtp_packet.h" |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 33 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
philipel | 6cbb468 | 2022-09-30 17:23:04 +0200 | [diff] [blame] | 34 | #include "modules/rtp_rtcp/source/rtp_util.h" |
Philipp Hancke | fae4fb1 | 2021-01-26 18:05:56 +0100 | [diff] [blame] | 35 | #include "modules/video_coding/utility/ivf_file_writer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 36 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 37 | #include "rtc_base/string_to_number.h" |
Sam Zackrisson | b45bdb5 | 2018-10-02 16:25:59 +0200 | [diff] [blame] | 38 | #include "rtc_base/strings/json.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 39 | #include "rtc_base/time_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 40 | #include "system_wrappers/include/clock.h" |
| 41 | #include "system_wrappers/include/sleep.h" |
Benjamin Wright | 8efafdf | 2019-01-11 10:48:42 -0800 | [diff] [blame] | 42 | #include "test/call_config_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 43 | #include "test/call_test.h" |
| 44 | #include "test/encoder_settings.h" |
| 45 | #include "test/fake_decoder.h" |
| 46 | #include "test/gtest.h" |
| 47 | #include "test/null_transport.h" |
| 48 | #include "test/rtp_file_reader.h" |
| 49 | #include "test/run_loop.h" |
| 50 | #include "test/run_test.h" |
Sebastian Jansson | f1f363f | 2018-08-13 14:24:58 +0200 | [diff] [blame] | 51 | #include "test/test_video_capturer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 52 | #include "test/testsupport/frame_writer.h" |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 53 | #include "test/time_controller/simulated_time_controller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 54 | #include "test/video_renderer.h" |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 55 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 56 | // Flag for payload type. |
| 57 | ABSL_FLAG(int, |
| 58 | media_payload_type, |
| 59 | webrtc::test::CallTest::kPayloadTypeVP8, |
| 60 | "Media payload type"); |
| 61 | |
| 62 | // Flag for RED payload type. |
| 63 | ABSL_FLAG(int, |
| 64 | red_payload_type, |
| 65 | webrtc::test::CallTest::kRedPayloadType, |
| 66 | "RED payload type"); |
| 67 | |
| 68 | // Flag for ULPFEC payload type. |
| 69 | ABSL_FLAG(int, |
| 70 | ulpfec_payload_type, |
| 71 | webrtc::test::CallTest::kUlpfecPayloadType, |
| 72 | "ULPFEC payload type"); |
| 73 | |
Philipp Hancke | 1c951ec | 2022-05-25 10:44:22 +0200 | [diff] [blame] | 74 | // Flag for FLEXFEC payload type. |
| 75 | ABSL_FLAG(int, |
| 76 | flexfec_payload_type, |
| 77 | webrtc::test::CallTest::kFlexfecPayloadType, |
| 78 | "FLEXFEC payload type"); |
| 79 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 80 | ABSL_FLAG(int, |
| 81 | media_payload_type_rtx, |
| 82 | webrtc::test::CallTest::kSendRtxPayloadType, |
| 83 | "Media over RTX payload type"); |
| 84 | |
| 85 | ABSL_FLAG(int, |
| 86 | red_payload_type_rtx, |
| 87 | webrtc::test::CallTest::kRtxRedPayloadType, |
| 88 | "RED over RTX payload type"); |
| 89 | |
Philipp Hancke | c060ce4 | 2021-03-15 13:15:59 +0100 | [diff] [blame] | 90 | // Flag for SSRC and RTX SSRC. |
| 91 | ABSL_FLAG(uint32_t, |
| 92 | ssrc, |
| 93 | webrtc::test::CallTest::kVideoSendSsrcs[0], |
| 94 | "Incoming SSRC"); |
| 95 | ABSL_FLAG(uint32_t, |
| 96 | ssrc_rtx, |
| 97 | webrtc::test::CallTest::kSendRtxSsrcs[0], |
| 98 | "Incoming RTX SSRC"); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 99 | |
Philipp Hancke | 1c951ec | 2022-05-25 10:44:22 +0200 | [diff] [blame] | 100 | ABSL_FLAG(uint32_t, |
| 101 | ssrc_flexfec, |
| 102 | webrtc::test::CallTest::kFlexfecSendSsrc, |
| 103 | "Incoming FLEXFEC SSRC"); |
| 104 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 105 | // Flag for abs-send-time id. |
| 106 | ABSL_FLAG(int, abs_send_time_id, -1, "RTP extension ID for abs-send-time"); |
| 107 | |
| 108 | // Flag for transmission-offset id. |
| 109 | ABSL_FLAG(int, |
| 110 | transmission_offset_id, |
| 111 | -1, |
| 112 | "RTP extension ID for transmission-offset"); |
| 113 | |
| 114 | // Flag for rtpdump input file. |
| 115 | ABSL_FLAG(std::string, input_file, "", "input file"); |
| 116 | |
| 117 | ABSL_FLAG(std::string, config_file, "", "config file"); |
| 118 | |
| 119 | // Flag for raw output files. |
| 120 | ABSL_FLAG(std::string, |
| 121 | out_base, |
| 122 | "", |
| 123 | "Basename (excluding .jpg) for raw output"); |
| 124 | |
| 125 | ABSL_FLAG(std::string, |
| 126 | decoder_bitstream_filename, |
| 127 | "", |
| 128 | "Decoder bitstream output file"); |
| 129 | |
Philipp Hancke | fae4fb1 | 2021-01-26 18:05:56 +0100 | [diff] [blame] | 130 | ABSL_FLAG(std::string, decoder_ivf_filename, "", "Decoder ivf output file"); |
| 131 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 132 | // Flag for video codec. |
| 133 | ABSL_FLAG(std::string, codec, "VP8", "Video codec"); |
| 134 | |
Philipp Hancke | f3a687a | 2021-03-15 12:04:39 +0100 | [diff] [blame] | 135 | // Flags for rtp start and stop timestamp. |
| 136 | ABSL_FLAG(uint32_t, |
| 137 | start_timestamp, |
| 138 | 0, |
| 139 | "RTP start timestamp, packets with smaller timestamp will be ignored " |
| 140 | "(no wraparound)"); |
| 141 | ABSL_FLAG(uint32_t, |
| 142 | stop_timestamp, |
| 143 | 4294967295, |
| 144 | "RTP stop timestamp, packets with larger timestamp will be ignored " |
| 145 | "(no wraparound)"); |
| 146 | |
Jonathan Lennox | 03df29c | 2021-07-13 12:41:31 -0400 | [diff] [blame] | 147 | // Flags for render window width and height |
| 148 | ABSL_FLAG(uint32_t, render_width, 640, "Width of render window"); |
| 149 | ABSL_FLAG(uint32_t, render_height, 480, "Height of render window"); |
| 150 | |
philipel | 525891a | 2022-10-03 14:54:09 +0200 | [diff] [blame] | 151 | ABSL_FLAG( |
| 152 | std::string, |
| 153 | force_fieldtrials, |
| 154 | "", |
| 155 | "Field trials control experimental feature code which can be forced. " |
| 156 | "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enabled/" |
| 157 | " will assign the group Enable to field trial WebRTC-FooFeature. Multiple " |
| 158 | "trials are separated by \"/\""); |
| 159 | |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 160 | ABSL_FLAG(bool, simulated_time, false, "Run in simulated time"); |
| 161 | |
philipel | f16fc05 | 2022-10-04 08:09:45 +0200 | [diff] [blame] | 162 | ABSL_FLAG(bool, disable_preview, false, "Disable decoded video preview."); |
| 163 | |
philipel | c11b0fe | 2022-10-04 08:10:20 +0200 | [diff] [blame] | 164 | ABSL_FLAG(bool, disable_decoding, false, "Disable video decoding."); |
| 165 | |
philipel | 720bc4d | 2022-10-18 08:51:17 +0200 | [diff] [blame] | 166 | ABSL_FLAG(int, |
| 167 | extend_run_time_duration, |
| 168 | 0, |
| 169 | "Extends the run time of the receiving client after the last RTP " |
| 170 | "packet has been delivered. Typically useful to let the last few " |
| 171 | "frames be decoded and rendered. Duration given in seconds."); |
| 172 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 173 | namespace { |
philipel | 05f4822 | 2022-10-03 09:19:55 +0200 | [diff] [blame] | 174 | bool ValidatePayloadType(int32_t payload_type) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 175 | return payload_type > 0 && payload_type <= 127; |
| 176 | } |
| 177 | |
philipel | 05f4822 | 2022-10-03 09:19:55 +0200 | [diff] [blame] | 178 | bool ValidateOptionalPayloadType(int32_t payload_type) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 179 | return payload_type == -1 || ValidatePayloadType(payload_type); |
| 180 | } |
| 181 | |
philipel | 05f4822 | 2022-10-03 09:19:55 +0200 | [diff] [blame] | 182 | bool ValidateRtpHeaderExtensionId(int32_t extension_id) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 183 | return extension_id >= -1 && extension_id < 15; |
| 184 | } |
| 185 | |
| 186 | bool ValidateInputFilenameNotEmpty(const std::string& string) { |
| 187 | return !string.empty(); |
| 188 | } |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 189 | } // namespace |
| 190 | |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 191 | namespace webrtc { |
philipel | 05f4822 | 2022-10-03 09:19:55 +0200 | [diff] [blame] | 192 | namespace { |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 193 | |
philipel | 05f4822 | 2022-10-03 09:19:55 +0200 | [diff] [blame] | 194 | const uint32_t kReceiverLocalSsrc = 0x123456; |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 195 | |
philipel | f16fc05 | 2022-10-04 08:09:45 +0200 | [diff] [blame] | 196 | class NullRenderer : public rtc::VideoSinkInterface<VideoFrame> { |
| 197 | public: |
| 198 | void OnFrame(const VideoFrame& frame) override {} |
| 199 | }; |
| 200 | |
nisse | 7ade7b3 | 2016-03-23 04:48:10 -0700 | [diff] [blame] | 201 | class FileRenderPassthrough : public rtc::VideoSinkInterface<VideoFrame> { |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 202 | public: |
nisse | 7ade7b3 | 2016-03-23 04:48:10 -0700 | [diff] [blame] | 203 | FileRenderPassthrough(const std::string& basename, |
| 204 | rtc::VideoSinkInterface<VideoFrame>* renderer) |
philipel | 99b6345 | 2017-08-25 07:24:21 -0700 | [diff] [blame] | 205 | : basename_(basename), renderer_(renderer), file_(nullptr), count_(0) {} |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 206 | |
Mirko Bonadei | fe055c1 | 2019-01-29 22:53:28 +0100 | [diff] [blame] | 207 | ~FileRenderPassthrough() override { |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 208 | if (file_) |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 209 | fclose(file_); |
| 210 | } |
| 211 | |
| 212 | private: |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 213 | void OnFrame(const VideoFrame& video_frame) override { |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 214 | if (renderer_) |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 215 | renderer_->OnFrame(video_frame); |
philipel | 99b6345 | 2017-08-25 07:24:21 -0700 | [diff] [blame] | 216 | |
pbos | bb36fdf | 2015-07-09 07:48:14 -0700 | [diff] [blame] | 217 | if (basename_.empty()) |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 218 | return; |
philipel | 99b6345 | 2017-08-25 07:24:21 -0700 | [diff] [blame] | 219 | |
| 220 | std::stringstream filename; |
| 221 | filename << basename_ << count_++ << "_" << video_frame.timestamp() |
| 222 | << ".jpg"; |
| 223 | |
philipel | 99b6345 | 2017-08-25 07:24:21 -0700 | [diff] [blame] | 224 | test::JpegFrameWriter frame_writer(filename.str()); |
| 225 | RTC_CHECK(frame_writer.WriteFrame(video_frame, 100)); |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | const std::string basename_; |
nisse | 7ade7b3 | 2016-03-23 04:48:10 -0700 | [diff] [blame] | 229 | rtc::VideoSinkInterface<VideoFrame>* const renderer_; |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 230 | FILE* file_; |
| 231 | size_t count_; |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 232 | }; |
| 233 | |
Niels Möller | f88a22c | 2018-06-19 17:05:03 +0200 | [diff] [blame] | 234 | class DecoderBitstreamFileWriter : public test::FakeDecoder { |
stefan@webrtc.org | 48ac226 | 2015-03-02 16:18:56 +0000 | [diff] [blame] | 235 | public: |
| 236 | explicit DecoderBitstreamFileWriter(const char* filename) |
| 237 | : file_(fopen(filename, "wb")) { |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 238 | RTC_DCHECK(file_); |
stefan@webrtc.org | 48ac226 | 2015-03-02 16:18:56 +0000 | [diff] [blame] | 239 | } |
Mirko Bonadei | fe055c1 | 2019-01-29 22:53:28 +0100 | [diff] [blame] | 240 | ~DecoderBitstreamFileWriter() override { fclose(file_); } |
stefan@webrtc.org | 48ac226 | 2015-03-02 16:18:56 +0000 | [diff] [blame] | 241 | |
Niels Möller | f88a22c | 2018-06-19 17:05:03 +0200 | [diff] [blame] | 242 | int32_t Decode(const EncodedImage& encoded_frame, |
Benjamin Wright | 8efafdf | 2019-01-11 10:48:42 -0800 | [diff] [blame] | 243 | bool /* missing_frames */, |
Benjamin Wright | 8efafdf | 2019-01-11 10:48:42 -0800 | [diff] [blame] | 244 | int64_t /* render_time_ms */) override { |
Niels Möller | 77536a2 | 2019-01-15 08:50:01 +0100 | [diff] [blame] | 245 | if (fwrite(encoded_frame.data(), 1, encoded_frame.size(), file_) < |
| 246 | encoded_frame.size()) { |
Niels Möller | f88a22c | 2018-06-19 17:05:03 +0200 | [diff] [blame] | 247 | RTC_LOG_ERR(LS_ERROR) << "fwrite of encoded frame failed."; |
| 248 | return WEBRTC_VIDEO_CODEC_ERROR; |
| 249 | } |
| 250 | return WEBRTC_VIDEO_CODEC_OK; |
stefan@webrtc.org | 48ac226 | 2015-03-02 16:18:56 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | private: |
| 254 | FILE* file_; |
| 255 | }; |
| 256 | |
Philipp Hancke | fae4fb1 | 2021-01-26 18:05:56 +0100 | [diff] [blame] | 257 | class DecoderIvfFileWriter : public test::FakeDecoder { |
| 258 | public: |
| 259 | explicit DecoderIvfFileWriter(const char* filename, const std::string& codec) |
| 260 | : file_writer_( |
| 261 | IvfFileWriter::Wrap(FileWrapper::OpenWriteOnly(filename), 0)) { |
| 262 | RTC_DCHECK(file_writer_.get()); |
| 263 | if (codec == "VP8") { |
| 264 | video_codec_type_ = VideoCodecType::kVideoCodecVP8; |
| 265 | } else if (codec == "VP9") { |
| 266 | video_codec_type_ = VideoCodecType::kVideoCodecVP9; |
| 267 | } else if (codec == "H264") { |
| 268 | video_codec_type_ = VideoCodecType::kVideoCodecH264; |
Philipp Hancke | de7fcff | 2022-05-12 18:13:16 +0200 | [diff] [blame] | 269 | } else if (codec == "AV1") { |
| 270 | video_codec_type_ = VideoCodecType::kVideoCodecAV1; |
Philipp Hancke | fae4fb1 | 2021-01-26 18:05:56 +0100 | [diff] [blame] | 271 | } else { |
| 272 | RTC_LOG(LS_ERROR) << "Unsupported video codec " << codec; |
Artem Titov | d325196 | 2021-11-15 16:57:07 +0100 | [diff] [blame] | 273 | RTC_DCHECK_NOTREACHED(); |
Philipp Hancke | fae4fb1 | 2021-01-26 18:05:56 +0100 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | ~DecoderIvfFileWriter() override { file_writer_->Close(); } |
| 277 | |
| 278 | int32_t Decode(const EncodedImage& encoded_frame, |
| 279 | bool /* missing_frames */, |
| 280 | int64_t render_time_ms) override { |
| 281 | if (!file_writer_->WriteFrame(encoded_frame, video_codec_type_)) { |
| 282 | return WEBRTC_VIDEO_CODEC_ERROR; |
| 283 | } |
| 284 | return WEBRTC_VIDEO_CODEC_OK; |
| 285 | } |
| 286 | |
| 287 | private: |
| 288 | std::unique_ptr<IvfFileWriter> file_writer_; |
| 289 | VideoCodecType video_codec_type_; |
| 290 | }; |
| 291 | |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 292 | // Holds all the shared memory structures required for a receive stream. This |
| 293 | // structure is used to prevent members being deallocated before the replay |
| 294 | // has been finished. |
| 295 | struct StreamState { |
| 296 | test::NullTransport transport; |
| 297 | std::vector<std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>>> sinks; |
| 298 | std::vector<VideoReceiveStreamInterface*> receive_streams; |
| 299 | std::vector<FlexfecReceiveStream*> flexfec_streams; |
| 300 | std::unique_ptr<VideoDecoderFactory> decoder_factory; |
| 301 | }; |
| 302 | |
| 303 | // Loads multiple configurations from the provided configuration file. |
| 304 | std::unique_ptr<StreamState> ConfigureFromFile(const std::string& config_path, |
| 305 | Call* call) { |
| 306 | auto stream_state = std::make_unique<StreamState>(); |
| 307 | // Parse the configuration file. |
| 308 | std::ifstream config_file(config_path); |
| 309 | std::stringstream raw_json_buffer; |
| 310 | raw_json_buffer << config_file.rdbuf(); |
| 311 | std::string raw_json = raw_json_buffer.str(); |
| 312 | Json::CharReaderBuilder builder; |
| 313 | Json::Value json_configs; |
| 314 | std::string error_message; |
| 315 | std::unique_ptr<Json::CharReader> json_reader(builder.newCharReader()); |
| 316 | if (!json_reader->parse(raw_json.data(), raw_json.data() + raw_json.size(), |
| 317 | &json_configs, &error_message)) { |
| 318 | fprintf(stderr, "Error parsing JSON config\n"); |
| 319 | fprintf(stderr, "%s\n", error_message.c_str()); |
| 320 | return nullptr; |
| 321 | } |
| 322 | |
philipel | c11b0fe | 2022-10-04 08:10:20 +0200 | [diff] [blame] | 323 | if (absl::GetFlag(FLAGS_disable_decoding)) { |
| 324 | stream_state->decoder_factory = |
| 325 | std::make_unique<test::FunctionVideoDecoderFactory>( |
| 326 | []() { return std::make_unique<test::FakeDecoder>(); }); |
| 327 | } else { |
| 328 | stream_state->decoder_factory = std::make_unique<InternalDecoderFactory>(); |
| 329 | } |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 330 | size_t config_count = 0; |
| 331 | for (const auto& json : json_configs) { |
| 332 | // Create the configuration and parse the JSON into the config. |
| 333 | auto receive_config = |
| 334 | ParseVideoReceiveStreamJsonConfig(&(stream_state->transport), json); |
| 335 | // Instantiate the underlying decoder. |
| 336 | for (auto& decoder : receive_config.decoders) { |
| 337 | decoder = test::CreateMatchingDecoder(decoder.payload_type, |
| 338 | decoder.video_format.name); |
| 339 | } |
| 340 | // Create a window for this config. |
| 341 | std::stringstream window_title; |
| 342 | window_title << "Playback Video (" << config_count++ << ")"; |
philipel | f16fc05 | 2022-10-04 08:09:45 +0200 | [diff] [blame] | 343 | if (absl::GetFlag(FLAGS_disable_preview)) { |
| 344 | stream_state->sinks.emplace_back(std::make_unique<NullRenderer>()); |
| 345 | } else { |
| 346 | stream_state->sinks.emplace_back(test::VideoRenderer::Create( |
| 347 | window_title.str().c_str(), absl::GetFlag(FLAGS_render_width), |
| 348 | absl::GetFlag(FLAGS_render_height))); |
| 349 | } |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 350 | // Create a receive stream for this config. |
| 351 | receive_config.renderer = stream_state->sinks.back().get(); |
| 352 | receive_config.decoder_factory = stream_state->decoder_factory.get(); |
| 353 | stream_state->receive_streams.emplace_back( |
| 354 | call->CreateVideoReceiveStream(std::move(receive_config))); |
| 355 | } |
| 356 | return stream_state; |
| 357 | } |
| 358 | |
| 359 | // Loads the base configuration from flags passed in on the commandline. |
| 360 | std::unique_ptr<StreamState> ConfigureFromFlags( |
| 361 | const std::string& rtp_dump_path, |
| 362 | Call* call) { |
| 363 | auto stream_state = std::make_unique<StreamState>(); |
| 364 | // Create the video renderers. We must add both to the stream state to keep |
| 365 | // them from deallocating. |
| 366 | std::stringstream window_title; |
| 367 | window_title << "Playback Video (" << rtp_dump_path << ")"; |
philipel | f16fc05 | 2022-10-04 08:09:45 +0200 | [diff] [blame] | 368 | std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>> playback_video; |
| 369 | if (absl::GetFlag(FLAGS_disable_preview)) { |
| 370 | playback_video = std::make_unique<NullRenderer>(); |
| 371 | } else { |
| 372 | playback_video.reset(test::VideoRenderer::Create( |
| 373 | window_title.str().c_str(), absl::GetFlag(FLAGS_render_width), |
| 374 | absl::GetFlag(FLAGS_render_height))); |
| 375 | } |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 376 | auto file_passthrough = std::make_unique<FileRenderPassthrough>( |
| 377 | absl::GetFlag(FLAGS_out_base), playback_video.get()); |
| 378 | stream_state->sinks.push_back(std::move(playback_video)); |
| 379 | stream_state->sinks.push_back(std::move(file_passthrough)); |
| 380 | // Setup the configuration from the flags. |
| 381 | VideoReceiveStreamInterface::Config receive_config( |
| 382 | &(stream_state->transport)); |
| 383 | receive_config.rtp.remote_ssrc = absl::GetFlag(FLAGS_ssrc); |
| 384 | receive_config.rtp.local_ssrc = kReceiverLocalSsrc; |
| 385 | receive_config.rtp.rtx_ssrc = absl::GetFlag(FLAGS_ssrc_rtx); |
| 386 | receive_config.rtp.rtx_associated_payload_types[absl::GetFlag( |
| 387 | FLAGS_media_payload_type_rtx)] = absl::GetFlag(FLAGS_media_payload_type); |
| 388 | receive_config.rtp |
| 389 | .rtx_associated_payload_types[absl::GetFlag(FLAGS_red_payload_type_rtx)] = |
| 390 | absl::GetFlag(FLAGS_red_payload_type); |
| 391 | receive_config.rtp.ulpfec_payload_type = |
| 392 | absl::GetFlag(FLAGS_ulpfec_payload_type); |
| 393 | receive_config.rtp.red_payload_type = absl::GetFlag(FLAGS_red_payload_type); |
| 394 | receive_config.rtp.nack.rtp_history_ms = 1000; |
| 395 | |
| 396 | if (absl::GetFlag(FLAGS_flexfec_payload_type) != -1) { |
| 397 | receive_config.rtp.protected_by_flexfec = true; |
philipel | faaa57b | 2022-10-03 14:53:20 +0200 | [diff] [blame] | 398 | FlexfecReceiveStream::Config flexfec_config(&(stream_state->transport)); |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 399 | flexfec_config.payload_type = absl::GetFlag(FLAGS_flexfec_payload_type); |
| 400 | flexfec_config.protected_media_ssrcs.push_back(absl::GetFlag(FLAGS_ssrc)); |
| 401 | flexfec_config.rtp.remote_ssrc = absl::GetFlag(FLAGS_ssrc_flexfec); |
| 402 | FlexfecReceiveStream* flexfec_stream = |
| 403 | call->CreateFlexfecReceiveStream(flexfec_config); |
| 404 | receive_config.rtp.packet_sink_ = flexfec_stream; |
| 405 | stream_state->flexfec_streams.push_back(flexfec_stream); |
| 406 | } |
| 407 | |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 408 | receive_config.renderer = stream_state->sinks.back().get(); |
| 409 | |
| 410 | // Setup the receiving stream |
| 411 | VideoReceiveStreamInterface::Decoder decoder; |
| 412 | decoder = test::CreateMatchingDecoder(absl::GetFlag(FLAGS_media_payload_type), |
| 413 | absl::GetFlag(FLAGS_codec)); |
| 414 | if (!absl::GetFlag(FLAGS_decoder_bitstream_filename).empty()) { |
| 415 | // Replace decoder with file writer if we're writing the bitstream to a |
| 416 | // file instead. |
| 417 | stream_state->decoder_factory = |
| 418 | std::make_unique<test::FunctionVideoDecoderFactory>([]() { |
| 419 | return std::make_unique<DecoderBitstreamFileWriter>( |
| 420 | absl::GetFlag(FLAGS_decoder_bitstream_filename).c_str()); |
| 421 | }); |
| 422 | } else if (!absl::GetFlag(FLAGS_decoder_ivf_filename).empty()) { |
| 423 | // Replace decoder with file writer if we're writing the ivf to a |
| 424 | // file instead. |
| 425 | stream_state->decoder_factory = |
| 426 | std::make_unique<test::FunctionVideoDecoderFactory>([]() { |
| 427 | return std::make_unique<DecoderIvfFileWriter>( |
| 428 | absl::GetFlag(FLAGS_decoder_ivf_filename).c_str(), |
| 429 | absl::GetFlag(FLAGS_codec)); |
| 430 | }); |
philipel | c11b0fe | 2022-10-04 08:10:20 +0200 | [diff] [blame] | 431 | } else if (absl::GetFlag(FLAGS_disable_decoding)) { |
| 432 | stream_state->decoder_factory = |
| 433 | std::make_unique<test::FunctionVideoDecoderFactory>( |
| 434 | []() { return std::make_unique<test::FakeDecoder>(); }); |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 435 | } else { |
| 436 | stream_state->decoder_factory = std::make_unique<InternalDecoderFactory>(); |
| 437 | } |
| 438 | receive_config.decoder_factory = stream_state->decoder_factory.get(); |
| 439 | receive_config.decoders.push_back(decoder); |
| 440 | |
| 441 | stream_state->receive_streams.emplace_back( |
| 442 | call->CreateVideoReceiveStream(std::move(receive_config))); |
| 443 | return stream_state; |
| 444 | } |
| 445 | |
| 446 | std::unique_ptr<test::RtpFileReader> CreateRtpReader( |
| 447 | const std::string& rtp_dump_path) { |
| 448 | std::unique_ptr<test::RtpFileReader> rtp_reader(test::RtpFileReader::Create( |
| 449 | test::RtpFileReader::kRtpDump, rtp_dump_path)); |
| 450 | if (!rtp_reader) { |
| 451 | rtp_reader.reset( |
| 452 | test::RtpFileReader::Create(test::RtpFileReader::kPcap, rtp_dump_path)); |
| 453 | if (!rtp_reader) { |
| 454 | fprintf(stderr, |
| 455 | "Couldn't open input file as either a rtpdump or .pcap. Note " |
| 456 | "that .pcapng is not supported.\nTrying to interpret the file as " |
| 457 | "length/packet interleaved.\n"); |
| 458 | rtp_reader.reset(test::RtpFileReader::Create( |
| 459 | test::RtpFileReader::kLengthPacketInterleaved, rtp_dump_path)); |
| 460 | if (!rtp_reader) { |
| 461 | fprintf(stderr, |
| 462 | "Unable to open input file with any supported format\n"); |
| 463 | return nullptr; |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | return rtp_reader; |
| 468 | } |
| 469 | |
| 470 | // The RtpReplayer is responsible for parsing the configuration provided by |
| 471 | // the user, setting up the windows, receive streams and decoders and then |
| 472 | // replaying the provided RTP dump. |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 473 | class RtpReplayer final { |
| 474 | public: |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 475 | RtpReplayer(absl::string_view replay_config_path, |
| 476 | absl::string_view rtp_dump_path, |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 477 | std::unique_ptr<FieldTrialsView> field_trials, |
| 478 | bool simulated_time) |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 479 | : replay_config_path_(replay_config_path), |
| 480 | rtp_dump_path_(rtp_dump_path), |
| 481 | field_trials_(std::move(field_trials)), |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 482 | rtp_reader_(CreateRtpReader(rtp_dump_path_)) { |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 483 | TaskQueueFactory* task_queue_factory; |
| 484 | if (simulated_time) { |
| 485 | time_sim_ = std::make_unique<GlobalSimulatedTimeController>( |
| 486 | Timestamp::Millis(1 << 30)); |
| 487 | task_queue_factory = time_sim_->GetTaskQueueFactory(); |
| 488 | } else { |
| 489 | task_queue_factory_ = CreateDefaultTaskQueueFactory(field_trials_.get()), |
| 490 | task_queue_factory = task_queue_factory_.get(); |
| 491 | } |
| 492 | worker_thread_ = |
| 493 | std::make_unique<rtc::TaskQueue>(task_queue_factory->CreateTaskQueue( |
| 494 | "worker_thread", TaskQueueFactory::Priority::NORMAL)); |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 495 | rtc::Event event; |
| 496 | worker_thread_->PostTask([&]() { |
| 497 | Call::Config call_config(&event_log_); |
| 498 | call_config.trials = field_trials_.get(); |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 499 | call_config.task_queue_factory = task_queue_factory; |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 500 | call_.reset(Call::Create(call_config)); |
| 501 | |
| 502 | // Creation of the streams must happen inside a task queue because it is |
| 503 | // resued as a worker thread. |
| 504 | if (replay_config_path_.empty()) { |
| 505 | stream_state_ = ConfigureFromFlags(rtp_dump_path_, call_.get()); |
| 506 | } else { |
| 507 | stream_state_ = ConfigureFromFile(replay_config_path_, call_.get()); |
| 508 | } |
| 509 | event.Set(); |
| 510 | }); |
| 511 | event.Wait(/*give_up_after=*/TimeDelta::Seconds(10)); |
| 512 | |
| 513 | RTC_CHECK(stream_state_); |
| 514 | RTC_CHECK(rtp_reader_); |
| 515 | } |
| 516 | |
| 517 | ~RtpReplayer() { |
| 518 | // Destruction of streams and the call must happen on the same thread as |
| 519 | // their creation. |
| 520 | rtc::Event event; |
| 521 | worker_thread_->PostTask([&]() { |
| 522 | for (const auto& receive_stream : stream_state_->receive_streams) { |
| 523 | call_->DestroyVideoReceiveStream(receive_stream); |
| 524 | } |
| 525 | for (const auto& flexfec_stream : stream_state_->flexfec_streams) { |
| 526 | call_->DestroyFlexfecReceiveStream(flexfec_stream); |
| 527 | } |
| 528 | call_.reset(); |
| 529 | event.Set(); |
| 530 | }); |
| 531 | event.Wait(/*give_up_after=*/TimeDelta::Seconds(10)); |
| 532 | } |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 533 | |
| 534 | void Run() { |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 535 | rtc::Event event; |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 536 | worker_thread_->PostTask([&]() { |
Ilya Nikolaevskiy | 6a64690 | 2020-12-11 11:07:01 +0100 | [diff] [blame] | 537 | // Start replaying the provided stream now that it has been configured. |
| 538 | // VideoReceiveStreams must be started on the same thread as they were |
| 539 | // created on. |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 540 | for (const auto& receive_stream : stream_state_->receive_streams) { |
Ilya Nikolaevskiy | 6a64690 | 2020-12-11 11:07:01 +0100 | [diff] [blame] | 541 | receive_stream->Start(); |
| 542 | } |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 543 | event.Set(); |
Danil Chapovalov | 5286dcf | 2022-07-18 17:04:56 +0200 | [diff] [blame] | 544 | }); |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 545 | event.Wait(/*give_up_after=*/TimeDelta::Seconds(10)); |
Ilya Nikolaevskiy | 6a64690 | 2020-12-11 11:07:01 +0100 | [diff] [blame] | 546 | |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 547 | ReplayPackets(); |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 548 | } |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 549 | |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 550 | private: |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 551 | void ReplayPackets() { |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 552 | enum class Result { kOk, kUnknownSsrc, kParsingFailed }; |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 553 | int64_t replay_start_ms = -1; |
| 554 | int num_packets = 0; |
| 555 | std::map<uint32_t, int> unknown_packets; |
Ilya Nikolaevskiy | 6a64690 | 2020-12-11 11:07:01 +0100 | [diff] [blame] | 556 | rtc::Event event(/*manual_reset=*/false, /*initially_signalled=*/false); |
Philipp Hancke | f3a687a | 2021-03-15 12:04:39 +0100 | [diff] [blame] | 557 | uint32_t start_timestamp = absl::GetFlag(FLAGS_start_timestamp); |
| 558 | uint32_t stop_timestamp = absl::GetFlag(FLAGS_stop_timestamp); |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 559 | |
| 560 | RtpHeaderExtensionMap extensions; |
| 561 | if (absl::GetFlag(FLAGS_transmission_offset_id) != -1) { |
| 562 | extensions.RegisterByUri(absl::GetFlag(FLAGS_transmission_offset_id), |
| 563 | RtpExtension::kTimestampOffsetUri); |
| 564 | } |
| 565 | if (absl::GetFlag(FLAGS_abs_send_time_id) != -1) { |
| 566 | extensions.RegisterByUri(absl::GetFlag(FLAGS_abs_send_time_id), |
| 567 | RtpExtension::kAbsSendTimeUri); |
| 568 | } |
| 569 | |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 570 | while (true) { |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 571 | int64_t now_ms = CurrentTimeMs(); |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 572 | if (replay_start_ms == -1) { |
| 573 | replay_start_ms = now_ms; |
| 574 | } |
philipel | 02f0396 | 2018-01-11 17:28:35 +0100 | [diff] [blame] | 575 | |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 576 | test::RtpPacket packet; |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 577 | if (!rtp_reader_->NextPacket(&packet)) { |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 578 | break; |
| 579 | } |
philipel | 0c29813 | 2022-12-30 11:45:22 +0100 | [diff] [blame] | 580 | rtc::CopyOnWriteBuffer packet_buffer( |
| 581 | packet.original_length > 0 ? packet.original_length : packet.length); |
| 582 | memcpy(packet_buffer.MutableData(), packet.data, packet.length); |
| 583 | if (packet.length < packet.original_length) { |
| 584 | // Only the RTP header was recorded in the RTP dump, payload is not |
| 585 | // known and and padding length is not known, zero the payload and |
| 586 | // clear the padding bit. |
| 587 | memset(packet_buffer.MutableData() + packet.length, 0, |
| 588 | packet.original_length - packet.length); |
| 589 | packet_buffer.MutableData()[0] &= ~0x20; |
| 590 | } |
Danil Chapovalov | 76a35d9 | 2021-06-08 12:30:46 +0200 | [diff] [blame] | 591 | RtpPacket header; |
| 592 | header.Parse(packet_buffer); |
| 593 | if (header.Timestamp() < start_timestamp || |
| 594 | header.Timestamp() > stop_timestamp) { |
Philipp Hancke | f3a687a | 2021-03-15 12:04:39 +0100 | [diff] [blame] | 595 | continue; |
| 596 | } |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 597 | |
| 598 | int64_t deliver_in_ms = replay_start_ms + packet.time_ms - now_ms; |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 599 | SleepOrAdvanceTime(deliver_in_ms); |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 600 | |
| 601 | ++num_packets; |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 602 | |
| 603 | Result result = Result::kOk; |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 604 | worker_thread_->PostTask([&]() { |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 605 | if (IsRtcpPacket(packet_buffer)) { |
| 606 | call_->Receiver()->DeliverRtcpPacket(std::move(packet_buffer)); |
| 607 | } |
| 608 | RtpPacketReceived received_packet(&extensions, |
| 609 | Timestamp::Millis(CurrentTimeMs())); |
| 610 | if (!received_packet.Parse(std::move(packet_buffer))) { |
| 611 | result = Result::kParsingFailed; |
| 612 | return; |
| 613 | } |
| 614 | call_->Receiver()->DeliverRtpPacket( |
| 615 | MediaType::VIDEO, received_packet, |
| 616 | [&result](const RtpPacketReceived& parsed_packet) -> bool { |
| 617 | result = Result::kUnknownSsrc; |
| 618 | // No point in trying to demux again. |
| 619 | return false; |
| 620 | }); |
Ilya Nikolaevskiy | 6a64690 | 2020-12-11 11:07:01 +0100 | [diff] [blame] | 621 | event.Set(); |
Danil Chapovalov | 5286dcf | 2022-07-18 17:04:56 +0200 | [diff] [blame] | 622 | }); |
Markus Handell | 2cfc1af | 2022-08-19 08:16:48 +0000 | [diff] [blame] | 623 | event.Wait(/*give_up_after=*/TimeDelta::Seconds(10)); |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 624 | |
Ilya Nikolaevskiy | 6a64690 | 2020-12-11 11:07:01 +0100 | [diff] [blame] | 625 | switch (result) { |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 626 | case Result::kOk: |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 627 | break; |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 628 | case Result::kUnknownSsrc: { |
Danil Chapovalov | 76a35d9 | 2021-06-08 12:30:46 +0200 | [diff] [blame] | 629 | if (unknown_packets[header.Ssrc()] == 0) |
| 630 | fprintf(stderr, "Unknown SSRC: %u!\n", header.Ssrc()); |
| 631 | ++unknown_packets[header.Ssrc()]; |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 632 | break; |
| 633 | } |
Per K | bdf30c8 | 2023-01-18 09:49:28 +0100 | [diff] [blame] | 634 | case Result::kParsingFailed: { |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 635 | fprintf(stderr, |
| 636 | "Packet error, corrupt packets or incorrect setup?\n"); |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 637 | fprintf(stderr, "Packet len=%zu pt=%u seq=%u ts=%u ssrc=0x%8x\n", |
Danil Chapovalov | 76a35d9 | 2021-06-08 12:30:46 +0200 | [diff] [blame] | 638 | packet.length, header.PayloadType(), header.SequenceNumber(), |
| 639 | header.Timestamp(), header.Ssrc()); |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 640 | break; |
| 641 | } |
philipp.hancke | 7b58960 | 2017-01-26 04:54:04 -0800 | [diff] [blame] | 642 | } |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 643 | } |
philipel | 720bc4d | 2022-10-18 08:51:17 +0200 | [diff] [blame] | 644 | // Note that even when `extend_run_time_duration` is zero |
| 645 | // `SleepOrAdvanceTime` should still be called in order to process the last |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 646 | // delivered packet when running in simulated time. |
philipel | 720bc4d | 2022-10-18 08:51:17 +0200 | [diff] [blame] | 647 | SleepOrAdvanceTime(absl::GetFlag(FLAGS_extend_run_time_duration) * 1000); |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 648 | |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 649 | fprintf(stderr, "num_packets: %d\n", num_packets); |
| 650 | |
| 651 | for (std::map<uint32_t, int>::const_iterator it = unknown_packets.begin(); |
| 652 | it != unknown_packets.end(); ++it) { |
| 653 | fprintf(stderr, "Packets for unknown ssrc '%u': %d\n", it->first, |
| 654 | it->second); |
| 655 | } |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 656 | } |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 657 | |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 658 | int64_t CurrentTimeMs() { |
| 659 | return time_sim_ ? time_sim_->GetClock()->TimeInMilliseconds() |
| 660 | : rtc::TimeMillis(); |
| 661 | } |
| 662 | |
| 663 | void SleepOrAdvanceTime(int64_t duration_ms) { |
| 664 | if (time_sim_) { |
| 665 | time_sim_->AdvanceTime(TimeDelta::Millis(duration_ms)); |
| 666 | } else if (duration_ms > 0) { |
| 667 | SleepMs(duration_ms); |
| 668 | } |
| 669 | } |
| 670 | |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 671 | const std::string replay_config_path_; |
| 672 | const std::string rtp_dump_path_; |
philipel | faaa57b | 2022-10-03 14:53:20 +0200 | [diff] [blame] | 673 | RtcEventLogNull event_log_; |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 674 | std::unique_ptr<FieldTrialsView> field_trials_; |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 675 | std::unique_ptr<GlobalSimulatedTimeController> time_sim_; |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 676 | std::unique_ptr<TaskQueueFactory> task_queue_factory_; |
| 677 | std::unique_ptr<rtc::TaskQueue> worker_thread_; |
philipel | 2671e24 | 2022-10-03 13:59:07 +0200 | [diff] [blame] | 678 | std::unique_ptr<Call> call_; |
| 679 | std::unique_ptr<test::RtpFileReader> rtp_reader_; |
| 680 | std::unique_ptr<StreamState> stream_state_; |
| 681 | }; |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 682 | |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 683 | void RtpReplay() { |
philipel | 525891a | 2022-10-03 14:54:09 +0200 | [diff] [blame] | 684 | RtpReplayer replayer( |
| 685 | absl::GetFlag(FLAGS_config_file), absl::GetFlag(FLAGS_input_file), |
philipel | 4426c47 | 2022-10-03 17:28:55 +0200 | [diff] [blame] | 686 | std::make_unique<FieldTrials>(absl::GetFlag(FLAGS_force_fieldtrials)), |
| 687 | absl::GetFlag(FLAGS_simulated_time)); |
philipel | 5f55137 | 2022-10-03 11:56:58 +0200 | [diff] [blame] | 688 | replayer.Run(); |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 689 | } |
Benjamin Wright | 90ab76d | 2018-08-23 11:33:29 -0700 | [diff] [blame] | 690 | |
philipel | 05f4822 | 2022-10-03 09:19:55 +0200 | [diff] [blame] | 691 | } // namespace |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 692 | } // namespace webrtc |
| 693 | |
| 694 | int main(int argc, char* argv[]) { |
| 695 | ::testing::InitGoogleTest(&argc, argv); |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 696 | absl::ParseCommandLine(argc, argv); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 697 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 698 | RTC_CHECK(ValidatePayloadType(absl::GetFlag(FLAGS_media_payload_type))); |
| 699 | RTC_CHECK(ValidatePayloadType(absl::GetFlag(FLAGS_media_payload_type_rtx))); |
| 700 | RTC_CHECK(ValidateOptionalPayloadType(absl::GetFlag(FLAGS_red_payload_type))); |
philipel | 752968e | 2017-12-05 12:40:28 +0100 | [diff] [blame] | 701 | RTC_CHECK( |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 702 | ValidateOptionalPayloadType(absl::GetFlag(FLAGS_red_payload_type_rtx))); |
philipel | 752968e | 2017-12-05 12:40:28 +0100 | [diff] [blame] | 703 | RTC_CHECK( |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 704 | ValidateOptionalPayloadType(absl::GetFlag(FLAGS_ulpfec_payload_type))); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 705 | RTC_CHECK( |
Philipp Hancke | 1c951ec | 2022-05-25 10:44:22 +0200 | [diff] [blame] | 706 | ValidateOptionalPayloadType(absl::GetFlag(FLAGS_flexfec_payload_type))); |
| 707 | RTC_CHECK( |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 708 | ValidateRtpHeaderExtensionId(absl::GetFlag(FLAGS_abs_send_time_id))); |
| 709 | RTC_CHECK(ValidateRtpHeaderExtensionId( |
| 710 | absl::GetFlag(FLAGS_transmission_offset_id))); |
| 711 | RTC_CHECK(ValidateInputFilenameNotEmpty(absl::GetFlag(FLAGS_input_file))); |
philipel | 720bc4d | 2022-10-18 08:51:17 +0200 | [diff] [blame] | 712 | RTC_CHECK_GE(absl::GetFlag(FLAGS_extend_run_time_duration), 0); |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 713 | |
Philipp Hancke | 07b7dec | 2020-07-28 12:34:48 +0200 | [diff] [blame] | 714 | rtc::ThreadManager::Instance()->WrapCurrentThread(); |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 715 | webrtc::test::RunTest(webrtc::RtpReplay); |
| 716 | return 0; |
| 717 | } |