result_sink.h (1383B)
1 /* 2 * Copyright (c) 2011 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 #ifndef MODULES_AUDIO_CODING_NETEQ_TEST_RESULT_SINK_H_ 12 #define MODULES_AUDIO_CODING_NETEQ_TEST_RESULT_SINK_H_ 13 14 #include <cstdio> 15 #include <memory> 16 17 #include "absl/strings/string_view.h" 18 #include "api/neteq/neteq.h" 19 #include "rtc_base/message_digest.h" 20 21 namespace webrtc { 22 23 class ResultSink { 24 public: 25 explicit ResultSink(absl::string_view output_file); 26 ~ResultSink(); 27 28 template <typename T> 29 void AddResult(const T* test_results, size_t length); 30 31 void AddResult(const NetEqNetworkStatistics& stats); 32 33 void VerifyChecksum(absl::string_view ref_check_sum); 34 35 private: 36 FILE* output_fp_; 37 std::unique_ptr<MessageDigest> digest_; 38 }; 39 40 template <typename T> 41 void ResultSink::AddResult(const T* test_results, size_t length) { 42 if (output_fp_) { 43 ASSERT_EQ(length, fwrite(test_results, sizeof(T), length, output_fp_)); 44 } 45 digest_->Update(test_results, sizeof(T) * length); 46 } 47 48 } // namespace webrtc 49 #endif // MODULES_AUDIO_CODING_NETEQ_TEST_RESULT_SINK_H_