blob: 0445141096f211e61fd4e527fd110dc809925cc3 [file] [log] [blame]
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_CHECKSUM_H_
12#define MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_CHECKSUM_H_
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000013
14#include <string>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_coding/neteq/tools/audio_sink.h"
17#include "rtc_base/constructormagic.h"
18#include "rtc_base/md5digest.h"
19#include "rtc_base/stringencode.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020020#include "typedefs.h" // NOLINT(build/include)
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000021
22namespace webrtc {
23namespace test {
24
25class AudioChecksum : public AudioSink {
26 public:
27 AudioChecksum() : finished_(false) {}
28
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000029 bool WriteArray(const int16_t* audio, size_t num_samples) override {
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000030 if (finished_)
31 return false;
32
33#ifndef WEBRTC_ARCH_LITTLE_ENDIAN
34#error "Big-endian gives a different checksum"
35#endif
36 checksum_.Update(audio, num_samples * sizeof(*audio));
37 return true;
38 }
39
40 // Finalizes the computations, and returns the checksum.
41 std::string Finish() {
42 if (!finished_) {
43 finished_ = true;
44 checksum_.Finish(checksum_result_, rtc::Md5Digest::kSize);
45 }
46 return rtc::hex_encode(checksum_result_, rtc::Md5Digest::kSize);
47 }
48
49 private:
50 rtc::Md5Digest checksum_;
51 char checksum_result_[rtc::Md5Digest::kSize];
52 bool finished_;
53
henrikg3c089d72015-09-16 05:37:44 -070054 RTC_DISALLOW_COPY_AND_ASSIGN(AudioChecksum);
henrik.lundin@webrtc.org496a9842014-06-19 10:02:11 +000055};
56
57} // namespace test
58} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020059#endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_CHECKSUM_H_