multiend_call.h (3469B)
1 /* 2 * Copyright (c) 2017 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_PROCESSING_TEST_CONVERSATIONAL_SPEECH_MULTIEND_CALL_H_ 12 #define MODULES_AUDIO_PROCESSING_TEST_CONVERSATIONAL_SPEECH_MULTIEND_CALL_H_ 13 14 #include <stddef.h> 15 16 #include <map> 17 #include <memory> 18 #include <set> 19 #include <string> 20 #include <vector> 21 22 #include "absl/strings/string_view.h" 23 #include "api/array_view.h" 24 #include "modules/audio_processing/test/conversational_speech/timing.h" 25 #include "modules/audio_processing/test/conversational_speech/wavreader_abstract_factory.h" 26 #include "modules/audio_processing/test/conversational_speech/wavreader_interface.h" 27 28 namespace webrtc { 29 namespace test { 30 namespace conversational_speech { 31 32 class MultiEndCall { 33 public: 34 struct SpeakingTurn { 35 // Constructor required in order to use std::vector::emplace_back(). 36 SpeakingTurn(absl::string_view new_speaker_name, 37 absl::string_view new_audiotrack_file_name, 38 size_t new_begin, 39 size_t new_end, 40 int gain) 41 : speaker_name(new_speaker_name), 42 audiotrack_file_name(new_audiotrack_file_name), 43 begin(new_begin), 44 end(new_end), 45 gain(gain) {} 46 std::string speaker_name; 47 std::string audiotrack_file_name; 48 size_t begin; 49 size_t end; 50 int gain; 51 }; 52 53 MultiEndCall( 54 ArrayView<const Turn> timing, 55 absl::string_view audiotracks_path, 56 std::unique_ptr<WavReaderAbstractFactory> wavreader_abstract_factory); 57 ~MultiEndCall(); 58 59 MultiEndCall(const MultiEndCall&) = delete; 60 MultiEndCall& operator=(const MultiEndCall&) = delete; 61 62 const std::set<std::string>& speaker_names() const { return speaker_names_; } 63 const std::map<std::string, std::unique_ptr<WavReaderInterface>>& 64 audiotrack_readers() const { 65 return audiotrack_readers_; 66 } 67 bool valid() const { return valid_; } 68 int sample_rate() const { return sample_rate_hz_; } 69 size_t total_duration_samples() const { return total_duration_samples_; } 70 const std::vector<SpeakingTurn>& speaking_turns() const { 71 return speaking_turns_; 72 } 73 74 private: 75 // Finds unique speaker names. 76 void FindSpeakerNames(); 77 78 // Creates one WavReader instance for each unique audiotrack. It returns false 79 // if the audio tracks do not have the same sample rate or if they are not 80 // mono. 81 bool CreateAudioTrackReaders(); 82 83 // Validates the speaking turns timing information. Accepts cross-talk, but 84 // only up to 2 speakers. Rejects unordered turns and self cross-talk. 85 bool CheckTiming(); 86 87 ArrayView<const Turn> timing_; 88 std::string audiotracks_path_; 89 std::unique_ptr<WavReaderAbstractFactory> wavreader_abstract_factory_; 90 std::set<std::string> speaker_names_; 91 std::map<std::string, std::unique_ptr<WavReaderInterface>> 92 audiotrack_readers_; 93 bool valid_; 94 int sample_rate_hz_; 95 size_t total_duration_samples_; 96 std::vector<SpeakingTurn> speaking_turns_; 97 }; 98 99 } // namespace conversational_speech 100 } // namespace test 101 } // namespace webrtc 102 103 #endif // MODULES_AUDIO_PROCESSING_TEST_CONVERSATIONAL_SPEECH_MULTIEND_CALL_H_