| Index: webrtc/modules/audio_mixer/test/alex_new_fancy_test.cc
|
| diff --git a/webrtc/modules/audio_mixer/test/alex_new_fancy_test.cc b/webrtc/modules/audio_mixer/test/alex_new_fancy_test.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a757ee85caf4af352509fdb5388692bd2b84f7a2
|
| --- /dev/null
|
| +++ b/webrtc/modules/audio_mixer/test/alex_new_fancy_test.cc
|
| @@ -0,0 +1,186 @@
|
| +//#include "webrtc/common_types.h"
|
| +
|
| +// #include <chrono>
|
| +// #include <thread>
|
| +
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "webrtc/voice_engine/include/voe_base.h"
|
| +#include "webrtc/voice_engine/include/voe_file.h"
|
| +#include "webrtc/system_wrappers/include/sleep.h"
|
| +// #include "webrtc/common_types.h"
|
| +// #include "webrtc/voice_engine/channel_manager.h"
|
| +// #include "webrtc/voice_engine/channel.h"
|
| +#include "webrtc/modules/utility/include/file_player.h"
|
| +
|
| +#include "webrtc/voice_engine/include/voe_base.h"
|
| +
|
| +#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer.h"
|
| +#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h"
|
| +
|
| +#include <iostream>
|
| +#include <fstream>
|
| +
|
| +#include "webrtc/modules/utility/include/process_thread.h"
|
| +
|
| +#include "webrtc/system_wrappers/include/trace.h"
|
| +#include "webrtc/base/logging.h"
|
| +
|
| +namespace webrtc {
|
| +
|
| +namespace {
|
| +
|
| +using c_string = const char*;
|
| +
|
| +c_string river_1 = "down_to_pray_other_selection_mono_32kHz_pcm.raw",
|
| + river_2 = "down_to_pray_selection_mono_32kHz_pcm.raw";
|
| +
|
| +// file_name = "recorded_16kHz.pcm",
|
| +// file_name2 = "one_two_three_16kHz_16bit_mono.pcm",
|
| +// file_name3 = "alpha_beta_gamma_16kHz_16bit_mono.pcm",
|
| +// file_name4 = "az_buky_vedy_16kHz_16bit_mono.pcm",
|
| +c_string output_file =
|
| + "output_river_32kHz_mono_pcm.raw"; //"outfile_mixed_16kHz_mono.pcm";
|
| +
|
| +void FillAudioFrame(const int16_t* audio_buffer,
|
| + AudioFrame* output,
|
| + uint32_t sample_rate_hz) {
|
| + int id = 0;
|
| + uint32_t timestamp = 0;
|
| + size_t num_channels = 1;
|
| + size_t samples_per_channel = sample_rate_hz / 1000 * 10 * num_channels;
|
| +
|
| + output->UpdateFrame(id, timestamp, audio_buffer, samples_per_channel,
|
| + sample_rate_hz, AudioFrame::kNormalSpeech,
|
| + AudioFrame::kVadActive, num_channels);
|
| +}
|
| +
|
| +class MyMixerParticipant : public MixerParticipant {
|
| + public:
|
| + MyMixerParticipant(const char* file_name, FileFormats format)
|
| + : is_done_(false), fp_(FilePlayer::CreateFilePlayer(0, format)) {
|
| + switch (format) {
|
| + case kFileFormatPcm16kHzFile:
|
| + frequency_ = 16000;
|
| + break;
|
| + case kFileFormatPcm8kHzFile:
|
| + frequency_ = 8000;
|
| + break;
|
| + case kFileFormatPcm32kHzFile:
|
| + frequency_ = 32000;
|
| + break;
|
| + default:
|
| + RTC_CHECK(false);
|
| + }
|
| +
|
| + if (fp_->StartPlayingFile(file_name,
|
| + true, // loop
|
| + 0, // start pos
|
| + 1.0, // volume scaling
|
| + 0 // notification time in ms, 0 = no notification
|
| + ) == -1) {
|
| + RTC_CHECK(false);
|
| + }
|
| + }
|
| +
|
| + int32_t NeededFrequency(int32_t id) const { return frequency_; }
|
| +
|
| + bool is_done() { return is_done_; }
|
| +
|
| + AudioFrameInfo GetAudioFrameWithMuted(int32_t id, AudioFrame* audio_frame) {
|
| + size_t length_in_samples;
|
| + if (fp_->Get10msAudioFromFile(buffer_, length_in_samples, frequency_) ==
|
| + -1) {
|
| + is_done_ = true;
|
| + return AudioFrameInfo::kError;
|
| + }
|
| + FillAudioFrame(buffer_, audio_frame, frequency_);
|
| + return AudioFrameInfo::kNormal;
|
| + }
|
| +
|
| + ~MyMixerParticipant() { FilePlayer::DestroyFilePlayer(fp_); }
|
| +
|
| + private:
|
| + bool is_done_;
|
| + FilePlayer* fp_;
|
| + int16_t buffer_[640];
|
| + uint32_t frequency_;
|
| +};
|
| +
|
| +class MyAudioMixerOutputReceiver : public AudioMixerOutputReceiver {
|
| + public:
|
| + MyAudioMixerOutputReceiver(const char* file_name)
|
| + : out_file_(file_name, std::ios::out | std::ios::binary) {
|
| + WEBRTC_TRACE(kTraceStream, kTraceVoice, 12345, "recv::recv(file_name=%s)",
|
| + file_name);
|
| +
|
| + LOG(LS_WARNING) << "recv::recv, file_name = " << file_name << "\n";
|
| + }
|
| +
|
| + virtual void NewMixedAudio(const int32_t id,
|
| + const AudioFrame& generalAudioFrame,
|
| + const AudioFrame** uniqueAudioFrames,
|
| + const uint32_t size) {
|
| + size_t size_of_data = sizeof(int16_t) *
|
| + generalAudioFrame.samples_per_channel_ *
|
| + generalAudioFrame.num_channels_;
|
| +
|
| + // LOG(LS_WARNING) << "recv::newMixedAudio, size_of_data = " << size_of_data
|
| + // << "\n";
|
| +
|
| + // do something with the frame...
|
| + out_file_.write(reinterpret_cast<const char*>(generalAudioFrame.data_),
|
| + size_of_data);
|
| + }
|
| +
|
| + ~MyAudioMixerOutputReceiver() { out_file_.close(); }
|
| +
|
| + private:
|
| + std::ofstream out_file_;
|
| +};
|
| +}
|
| +
|
| +TEST(AudioConferenceMixer, PlayBackFile) {
|
| + VoiceEngine* m_voe = VoiceEngine::Create();
|
| + VoEFile* file = VoEFile::GetInterface(m_voe);
|
| + VoEBase* base = VoEBase::GetInterface(m_voe);
|
| +
|
| + base->Init();
|
| +
|
| + MyMixerParticipant mmp(river_1, kFileFormatPcm32kHzFile);
|
| + MyMixerParticipant mmp2(river_2, kFileFormatPcm32kHzFile);
|
| + // MyMixerParticipant mmp3(file_name3, kFileFormatPcm16kHzFile);
|
| + // MyMixerParticipant mmp4(file_name4, kFileFormatPcm16kHzFile);
|
| + // MyMixerParticipant mmp3(file_name2, kFileFormatPcm16kHzFile);
|
| + // MyMixerParticipant mmp4(file_name2, kFileFormatPcm16kHzFile);
|
| + MyAudioMixerOutputReceiver mamop(output_file);
|
| +
|
| + AudioConferenceMixer* acm = AudioConferenceMixer::Create(0);
|
| + acm->RegisterMixedStreamCallback(&mamop);
|
| + acm->SetMixabilityStatus(&mmp, true);
|
| + acm->SetMixabilityStatus(&mmp2, true);
|
| + // acm->SetMixabilityStatus(&mmp3, true);
|
| + // acm->SetMixabilityStatus(&mmp4, true);
|
| +
|
| + std::unique_ptr<ProcessThread> my_new_process_thread =
|
| + ProcessThread::Create("my-new-process-thread");
|
| +
|
| + my_new_process_thread->RegisterModule(acm);
|
| + my_new_process_thread->Start();
|
| + SleepMs(60000);
|
| + my_new_process_thread->Stop();
|
| +
|
| + int ch = base->CreateChannel();
|
| + base->StartPlayout(ch);
|
| + file->StartPlayingFileLocally(ch, output_file, false,
|
| + kFileFormatPcm32kHzFile);
|
| +
|
| + // SleepMs(1000);
|
| +
|
| + file->StopPlayingFileLocally(ch);
|
| +
|
| + base->Terminate();
|
| + base->Release();
|
| + file->Release();
|
| + VoiceEngine::Delete(m_voe);
|
| +}
|
| +}
|
|
|