xref: /aosp_15_r20/external/webrtc/modules/audio_coding/neteq/test/result_sink.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 #include <string>
17 
18 #include "absl/strings/string_view.h"
19 #include "api/neteq/neteq.h"
20 #include "rtc_base/message_digest.h"
21 
22 namespace webrtc {
23 
24 class ResultSink {
25  public:
26   explicit ResultSink(absl::string_view output_file);
27   ~ResultSink();
28 
29   template <typename T>
30   void AddResult(const T* test_results, size_t length);
31 
32   void AddResult(const NetEqNetworkStatistics& stats);
33 
34   void VerifyChecksum(absl::string_view ref_check_sum);
35 
36  private:
37   FILE* output_fp_;
38   std::unique_ptr<rtc::MessageDigest> digest_;
39 };
40 
41 template <typename T>
AddResult(const T * test_results,size_t length)42 void ResultSink::AddResult(const T* test_results, size_t length) {
43   if (output_fp_) {
44     ASSERT_EQ(length, fwrite(test_results, sizeof(T), length, output_fp_));
45   }
46   digest_->Update(test_results, sizeof(T) * length);
47 }
48 
49 }  // namespace webrtc
50 #endif  // MODULES_AUDIO_CODING_NETEQ_TEST_RESULT_SINK_H_
51