| 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 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 FileRenderPassthrough(const std::string& basename, | 141 FileRenderPassthrough(const std::string& basename, |
| 142 rtc::VideoSinkInterface<VideoFrame>* renderer) | 142 rtc::VideoSinkInterface<VideoFrame>* renderer) |
| 143 : basename_(basename), | 143 : basename_(basename), |
| 144 renderer_(renderer), | 144 renderer_(renderer), |
| 145 file_(nullptr), | 145 file_(nullptr), |
| 146 count_(0), | 146 count_(0), |
| 147 last_width_(0), | 147 last_width_(0), |
| 148 last_height_(0) {} | 148 last_height_(0) {} |
| 149 | 149 |
| 150 ~FileRenderPassthrough() { | 150 ~FileRenderPassthrough() { |
| 151 if (file_ != nullptr) | 151 if (file_) |
| 152 fclose(file_); | 152 fclose(file_); |
| 153 } | 153 } |
| 154 | 154 |
| 155 private: | 155 private: |
| 156 void OnFrame(const VideoFrame& video_frame) override { | 156 void OnFrame(const VideoFrame& video_frame) override { |
| 157 if (renderer_ != nullptr) | 157 if (renderer_) |
| 158 renderer_->OnFrame(video_frame); | 158 renderer_->OnFrame(video_frame); |
| 159 if (basename_.empty()) | 159 if (basename_.empty()) |
| 160 return; | 160 return; |
| 161 if (last_width_ != video_frame.width() || | 161 if (last_width_ != video_frame.width() || |
| 162 last_height_ != video_frame.height()) { | 162 last_height_ != video_frame.height()) { |
| 163 if (file_ != nullptr) | 163 if (file_) |
| 164 fclose(file_); | 164 fclose(file_); |
| 165 std::stringstream filename; | 165 std::stringstream filename; |
| 166 filename << basename_; | 166 filename << basename_; |
| 167 if (++count_ > 1) | 167 if (++count_ > 1) |
| 168 filename << '-' << count_; | 168 filename << '-' << count_; |
| 169 filename << '_' << video_frame.width() << 'x' << video_frame.height() | 169 filename << '_' << video_frame.width() << 'x' << video_frame.height() |
| 170 << ".yuv"; | 170 << ".yuv"; |
| 171 file_ = fopen(filename.str().c_str(), "wb"); | 171 file_ = fopen(filename.str().c_str(), "wb"); |
| 172 if (file_ == nullptr) { | 172 if (!file_) { |
| 173 fprintf(stderr, | 173 fprintf(stderr, |
| 174 "Couldn't open file for writing: %s\n", | 174 "Couldn't open file for writing: %s\n", |
| 175 filename.str().c_str()); | 175 filename.str().c_str()); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 last_width_ = video_frame.width(); | 178 last_width_ = video_frame.width(); |
| 179 last_height_ = video_frame.height(); | 179 last_height_ = video_frame.height(); |
| 180 if (file_ == nullptr) | 180 if (!file_) |
| 181 return; | 181 return; |
| 182 PrintVideoFrame(video_frame, file_); | 182 PrintVideoFrame(video_frame, file_); |
| 183 } | 183 } |
| 184 | 184 |
| 185 const std::string basename_; | 185 const std::string basename_; |
| 186 rtc::VideoSinkInterface<VideoFrame>* const renderer_; | 186 rtc::VideoSinkInterface<VideoFrame>* const renderer_; |
| 187 FILE* file_; | 187 FILE* file_; |
| 188 size_t count_; | 188 size_t count_; |
| 189 int last_width_; | 189 int last_width_; |
| 190 int last_height_; | 190 int last_height_; |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 class DecoderBitstreamFileWriter : public EncodedFrameObserver { | 193 class DecoderBitstreamFileWriter : public EncodedFrameObserver { |
| 194 public: | 194 public: |
| 195 explicit DecoderBitstreamFileWriter(const char* filename) | 195 explicit DecoderBitstreamFileWriter(const char* filename) |
| 196 : file_(fopen(filename, "wb")) { | 196 : file_(fopen(filename, "wb")) { |
| 197 RTC_DCHECK(file_ != nullptr); | 197 RTC_DCHECK(file_); |
| 198 } | 198 } |
| 199 ~DecoderBitstreamFileWriter() { fclose(file_); } | 199 ~DecoderBitstreamFileWriter() { fclose(file_); } |
| 200 | 200 |
| 201 virtual void EncodedFrameCallback(const EncodedFrame& encoded_frame) { | 201 virtual void EncodedFrameCallback(const EncodedFrame& encoded_frame) { |
| 202 fwrite(encoded_frame.data_, 1, encoded_frame.length_, file_); | 202 fwrite(encoded_frame.data_, 1, encoded_frame.length_, file_); |
| 203 } | 203 } |
| 204 | 204 |
| 205 private: | 205 private: |
| 206 FILE* file_; | 206 FILE* file_; |
| 207 }; | 207 }; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 delete decoder.decoder; | 248 delete decoder.decoder; |
| 249 decoder.decoder = new test::FakeNullDecoder(); | 249 decoder.decoder = new test::FakeNullDecoder(); |
| 250 } | 250 } |
| 251 receive_config.decoders.push_back(decoder); | 251 receive_config.decoders.push_back(decoder); |
| 252 | 252 |
| 253 VideoReceiveStream* receive_stream = | 253 VideoReceiveStream* receive_stream = |
| 254 call->CreateVideoReceiveStream(receive_config); | 254 call->CreateVideoReceiveStream(receive_config); |
| 255 | 255 |
| 256 std::unique_ptr<test::RtpFileReader> rtp_reader(test::RtpFileReader::Create( | 256 std::unique_ptr<test::RtpFileReader> rtp_reader(test::RtpFileReader::Create( |
| 257 test::RtpFileReader::kRtpDump, flags::InputFile())); | 257 test::RtpFileReader::kRtpDump, flags::InputFile())); |
| 258 if (rtp_reader.get() == nullptr) { | 258 if (!rtp_reader) { |
| 259 rtp_reader.reset(test::RtpFileReader::Create(test::RtpFileReader::kPcap, | 259 rtp_reader.reset(test::RtpFileReader::Create(test::RtpFileReader::kPcap, |
| 260 flags::InputFile())); | 260 flags::InputFile())); |
| 261 if (rtp_reader.get() == nullptr) { | 261 if (!rtp_reader) { |
| 262 fprintf(stderr, | 262 fprintf(stderr, |
| 263 "Couldn't open input file as either a rtpdump or .pcap. Note " | 263 "Couldn't open input file as either a rtpdump or .pcap. Note " |
| 264 "that .pcapng is not supported.\nTrying to interpret the file as " | 264 "that .pcapng is not supported.\nTrying to interpret the file as " |
| 265 "length/packet interleaved.\n"); | 265 "length/packet interleaved.\n"); |
| 266 rtp_reader.reset(test::RtpFileReader::Create( | 266 rtp_reader.reset(test::RtpFileReader::Create( |
| 267 test::RtpFileReader::kLengthPacketInterleaved, flags::InputFile())); | 267 test::RtpFileReader::kLengthPacketInterleaved, flags::InputFile())); |
| 268 if (rtp_reader.get() == nullptr) { | 268 if (!rtp_reader) { |
| 269 fprintf(stderr, | 269 fprintf(stderr, |
| 270 "Unable to open input file with any supported format\n"); | 270 "Unable to open input file with any supported format\n"); |
| 271 return; | 271 return; |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 receive_stream->Start(); | 275 receive_stream->Start(); |
| 276 | 276 |
| 277 uint32_t last_time_ms = 0; | 277 uint32_t last_time_ms = 0; |
| 278 int num_packets = 0; | 278 int num_packets = 0; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } | 319 } |
| 320 } // namespace webrtc | 320 } // namespace webrtc |
| 321 | 321 |
| 322 int main(int argc, char* argv[]) { | 322 int main(int argc, char* argv[]) { |
| 323 ::testing::InitGoogleTest(&argc, argv); | 323 ::testing::InitGoogleTest(&argc, argv); |
| 324 google::ParseCommandLineFlags(&argc, &argv, true); | 324 google::ParseCommandLineFlags(&argc, &argv, true); |
| 325 | 325 |
| 326 webrtc::test::RunTest(webrtc::RtpReplay); | 326 webrtc::test::RunTest(webrtc::RtpReplay); |
| 327 return 0; | 327 return 0; |
| 328 } | 328 } |
| OLD | NEW |