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/typedefs.h" 21 22namespace webrtc { 23namespace test { 24 25class AudioChecksum : public AudioSink { 26 public: 27 AudioChecksum() : finished_(false) {} 28 29 bool WriteArray(const int16_t* audio, size_t num_samples) override { 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 54 RTC_DISALLOW_COPY_AND_ASSIGN(AudioChecksum); 55}; 56 57} // namespace test 58} // namespace webrtc 59#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_AUDIO_CHECKSUM_H_ 60