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 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_CHECKSUM_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_CHECKSUM_H_ 13 14 #include <string> 15 16 #include "webrtc/base/constructormagic.h" 17 #include "webrtc/base/md5digest.h" 18 #include "webrtc/base/stringencode.h" 19 #include "webrtc/modules/audio_coding/neteq/tools/audio_sink.h" 20 #include "webrtc/system_wrappers/interface/compile_assert.h" 21 #include "webrtc/typedefs.h" 22 23 namespace webrtc { 24 namespace test { 25 26 class AudioChecksum : public AudioSink { 27 public: 28 AudioChecksum() : finished_(false) {} 29 30 virtual bool WriteArray(const int16_t* audio, size_t num_samples) OVERRIDE { 31 if (finished_) 32 return false; 33 34 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN 35 #error "Big-endian gives a different checksum" 36 #endif 37 checksum_.Update(audio, num_samples * sizeof(*audio)); 38 return true; 39 } 40 41 // Finalizes the computations, and returns the checksum. 42 std::string Finish() { 43 if (!finished_) { 44 finished_ = true; 45 checksum_.Finish(checksum_result_, rtc::Md5Digest::kSize); 46 } 47 return rtc::hex_encode(checksum_result_, rtc::Md5Digest::kSize); 48 } 49 50 private: 51 rtc::Md5Digest checksum_; 52 char checksum_result_[rtc::Md5Digest::kSize]; 53 bool finished_; 54 55 DISALLOW_COPY_AND_ASSIGN(AudioChecksum); 56 }; 57 58 } // namespace test 59 } // namespace webrtc 60 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_CHECKSUM_H_ 61