OLD | NEW |
(Empty) | |
| 1 //#include "webrtc/common_types.h" |
| 2 |
| 3 // #include <chrono> |
| 4 // #include <thread> |
| 5 |
| 6 #include "testing/gmock/include/gmock/gmock.h" |
| 7 #include "webrtc/voice_engine/include/voe_base.h" |
| 8 #include "webrtc/voice_engine/include/voe_file.h" |
| 9 #include "webrtc/system_wrappers/include/sleep.h" |
| 10 // #include "webrtc/common_types.h" |
| 11 // #include "webrtc/voice_engine/channel_manager.h" |
| 12 // #include "webrtc/voice_engine/channel.h" |
| 13 #include "webrtc/modules/utility/include/file_player.h" |
| 14 |
| 15 #include "webrtc/voice_engine/include/voe_base.h" |
| 16 |
| 17 #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer.h
" |
| 18 #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_d
efines.h" |
| 19 |
| 20 #include <iostream> |
| 21 #include <fstream> |
| 22 |
| 23 #include "webrtc/modules/utility/include/process_thread.h" |
| 24 |
| 25 #include "webrtc/system_wrappers/include/trace.h" |
| 26 #include "webrtc/base/logging.h" |
| 27 |
| 28 namespace webrtc { |
| 29 |
| 30 namespace { |
| 31 |
| 32 using c_string = const char*; |
| 33 |
| 34 c_string river_1 = "down_to_pray_other_selection_mono_32kHz_pcm.raw", |
| 35 river_2 = "down_to_pray_selection_mono_32kHz_pcm.raw"; |
| 36 |
| 37 // file_name = "recorded_16kHz.pcm", |
| 38 // file_name2 = "one_two_three_16kHz_16bit_mono.pcm", |
| 39 // file_name3 = "alpha_beta_gamma_16kHz_16bit_mono.pcm", |
| 40 // file_name4 = "az_buky_vedy_16kHz_16bit_mono.pcm", |
| 41 c_string output_file = |
| 42 "output_river_32kHz_mono_pcm.raw"; //"outfile_mixed_16kHz_mono.pcm"; |
| 43 |
| 44 void FillAudioFrame(const int16_t* audio_buffer, |
| 45 AudioFrame* output, |
| 46 uint32_t sample_rate_hz) { |
| 47 int id = 0; |
| 48 uint32_t timestamp = 0; |
| 49 size_t num_channels = 1; |
| 50 size_t samples_per_channel = sample_rate_hz / 1000 * 10 * num_channels; |
| 51 |
| 52 output->UpdateFrame(id, timestamp, audio_buffer, samples_per_channel, |
| 53 sample_rate_hz, AudioFrame::kNormalSpeech, |
| 54 AudioFrame::kVadActive, num_channels); |
| 55 } |
| 56 |
| 57 class MyMixerParticipant : public MixerParticipant { |
| 58 public: |
| 59 MyMixerParticipant(const char* file_name, FileFormats format) |
| 60 : is_done_(false), fp_(FilePlayer::CreateFilePlayer(0, format)) { |
| 61 switch (format) { |
| 62 case kFileFormatPcm16kHzFile: |
| 63 frequency_ = 16000; |
| 64 break; |
| 65 case kFileFormatPcm8kHzFile: |
| 66 frequency_ = 8000; |
| 67 break; |
| 68 case kFileFormatPcm32kHzFile: |
| 69 frequency_ = 32000; |
| 70 break; |
| 71 default: |
| 72 RTC_CHECK(false); |
| 73 } |
| 74 |
| 75 if (fp_->StartPlayingFile(file_name, |
| 76 true, // loop |
| 77 0, // start pos |
| 78 1.0, // volume scaling |
| 79 0 // notification time in ms, 0 = no notification |
| 80 ) == -1) { |
| 81 RTC_CHECK(false); |
| 82 } |
| 83 } |
| 84 |
| 85 int32_t NeededFrequency(int32_t id) const { return frequency_; } |
| 86 |
| 87 bool is_done() { return is_done_; } |
| 88 |
| 89 AudioFrameInfo GetAudioFrameWithMuted(int32_t id, AudioFrame* audio_frame) { |
| 90 size_t length_in_samples; |
| 91 if (fp_->Get10msAudioFromFile(buffer_, length_in_samples, frequency_) == |
| 92 -1) { |
| 93 is_done_ = true; |
| 94 return AudioFrameInfo::kError; |
| 95 } |
| 96 FillAudioFrame(buffer_, audio_frame, frequency_); |
| 97 return AudioFrameInfo::kNormal; |
| 98 } |
| 99 |
| 100 ~MyMixerParticipant() { FilePlayer::DestroyFilePlayer(fp_); } |
| 101 |
| 102 private: |
| 103 bool is_done_; |
| 104 FilePlayer* fp_; |
| 105 int16_t buffer_[640]; |
| 106 uint32_t frequency_; |
| 107 }; |
| 108 |
| 109 class MyAudioMixerOutputReceiver : public AudioMixerOutputReceiver { |
| 110 public: |
| 111 MyAudioMixerOutputReceiver(const char* file_name) |
| 112 : out_file_(file_name, std::ios::out | std::ios::binary) { |
| 113 WEBRTC_TRACE(kTraceStream, kTraceVoice, 12345, "recv::recv(file_name=%s)", |
| 114 file_name); |
| 115 |
| 116 LOG(LS_WARNING) << "recv::recv, file_name = " << file_name << "\n"; |
| 117 } |
| 118 |
| 119 virtual void NewMixedAudio(const int32_t id, |
| 120 const AudioFrame& generalAudioFrame, |
| 121 const AudioFrame** uniqueAudioFrames, |
| 122 const uint32_t size) { |
| 123 size_t size_of_data = sizeof(int16_t) * |
| 124 generalAudioFrame.samples_per_channel_ * |
| 125 generalAudioFrame.num_channels_; |
| 126 |
| 127 // LOG(LS_WARNING) << "recv::newMixedAudio, size_of_data = " << size_of_data |
| 128 // << "\n"; |
| 129 |
| 130 // do something with the frame... |
| 131 out_file_.write(reinterpret_cast<const char*>(generalAudioFrame.data_), |
| 132 size_of_data); |
| 133 } |
| 134 |
| 135 ~MyAudioMixerOutputReceiver() { out_file_.close(); } |
| 136 |
| 137 private: |
| 138 std::ofstream out_file_; |
| 139 }; |
| 140 } |
| 141 |
| 142 TEST(AudioConferenceMixer, PlayBackFile) { |
| 143 VoiceEngine* m_voe = VoiceEngine::Create(); |
| 144 VoEFile* file = VoEFile::GetInterface(m_voe); |
| 145 VoEBase* base = VoEBase::GetInterface(m_voe); |
| 146 |
| 147 base->Init(); |
| 148 |
| 149 MyMixerParticipant mmp(river_1, kFileFormatPcm32kHzFile); |
| 150 MyMixerParticipant mmp2(river_2, kFileFormatPcm32kHzFile); |
| 151 // MyMixerParticipant mmp3(file_name3, kFileFormatPcm16kHzFile); |
| 152 // MyMixerParticipant mmp4(file_name4, kFileFormatPcm16kHzFile); |
| 153 // MyMixerParticipant mmp3(file_name2, kFileFormatPcm16kHzFile); |
| 154 // MyMixerParticipant mmp4(file_name2, kFileFormatPcm16kHzFile); |
| 155 MyAudioMixerOutputReceiver mamop(output_file); |
| 156 |
| 157 AudioConferenceMixer* acm = AudioConferenceMixer::Create(0); |
| 158 acm->RegisterMixedStreamCallback(&mamop); |
| 159 acm->SetMixabilityStatus(&mmp, true); |
| 160 acm->SetMixabilityStatus(&mmp2, true); |
| 161 // acm->SetMixabilityStatus(&mmp3, true); |
| 162 // acm->SetMixabilityStatus(&mmp4, true); |
| 163 |
| 164 std::unique_ptr<ProcessThread> my_new_process_thread = |
| 165 ProcessThread::Create("my-new-process-thread"); |
| 166 |
| 167 my_new_process_thread->RegisterModule(acm); |
| 168 my_new_process_thread->Start(); |
| 169 SleepMs(60000); |
| 170 my_new_process_thread->Stop(); |
| 171 |
| 172 int ch = base->CreateChannel(); |
| 173 base->StartPlayout(ch); |
| 174 file->StartPlayingFileLocally(ch, output_file, false, |
| 175 kFileFormatPcm32kHzFile); |
| 176 |
| 177 // SleepMs(1000); |
| 178 |
| 179 file->StopPlayingFileLocally(ch); |
| 180 |
| 181 base->Terminate(); |
| 182 base->Release(); |
| 183 file->Release(); |
| 184 VoiceEngine::Delete(m_voe); |
| 185 } |
| 186 } |
OLD | NEW |