henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_CHECKSUM_H_ |
| 12 | #define MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_CHECKSUM_H_ |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #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 Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 20 | #include "typedefs.h" // NOLINT(build/include) |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | namespace test { |
| 24 | |
| 25 | class AudioChecksum : public AudioSink { |
| 26 | public: |
| 27 | AudioChecksum() : finished_(false) {} |
| 28 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 29 | bool WriteArray(const int16_t* audio, size_t num_samples) override { |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 30 | 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 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 54 | RTC_DISALLOW_COPY_AND_ASSIGN(AudioChecksum); |
henrik.lundin@webrtc.org | 496a984 | 2014-06-19 10:02:11 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // namespace test |
| 58 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 59 | #endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_CHECKSUM_H_ |