result_sink.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #ifndef MODULES_AUDIO_CODING_NETEQ_TEST_RESULT_SINK_H_
  11. #define MODULES_AUDIO_CODING_NETEQ_TEST_RESULT_SINK_H_
  12. #include <cstdio>
  13. #include <memory>
  14. #include <string>
  15. #include "api/neteq/neteq.h"
  16. #include "modules/rtp_rtcp/include/rtcp_statistics.h"
  17. #include "rtc_base/message_digest.h"
  18. namespace webrtc {
  19. class ResultSink {
  20. public:
  21. explicit ResultSink(const std::string& output_file);
  22. ~ResultSink();
  23. template <typename T>
  24. void AddResult(const T* test_results, size_t length);
  25. void AddResult(const NetEqNetworkStatistics& stats);
  26. void AddResult(const RtcpStatistics& stats);
  27. void VerifyChecksum(const std::string& ref_check_sum);
  28. private:
  29. FILE* output_fp_;
  30. std::unique_ptr<rtc::MessageDigest> digest_;
  31. };
  32. template <typename T>
  33. void ResultSink::AddResult(const T* test_results, size_t length) {
  34. if (output_fp_) {
  35. ASSERT_EQ(length, fwrite(test_results, sizeof(T), length, output_fp_));
  36. }
  37. digest_->Update(test_results, sizeof(T) * length);
  38. }
  39. } // namespace webrtc
  40. #endif // MODULES_AUDIO_CODING_NETEQ_TEST_RESULT_SINK_H_