2017-06-18 19:32:20 +02:00
|
|
|
//
|
|
|
|
// libtgvoip is free and unencumbered public domain software.
|
|
|
|
// For more information, see http://unlicense.org or the UNLICENSE file
|
|
|
|
// you should have received with this source code distribution.
|
|
|
|
//
|
|
|
|
|
2017-07-04 15:50:02 +02:00
|
|
|
#include "AudioInputModule.h"
|
2017-06-18 19:32:20 +02:00
|
|
|
#include <stdio.h>
|
2017-06-22 14:48:52 +02:00
|
|
|
#include "../libtgvoip/logging.h"
|
2017-06-18 19:32:20 +02:00
|
|
|
|
|
|
|
using namespace tgvoip;
|
|
|
|
using namespace tgvoip::audio;
|
|
|
|
|
2017-07-09 21:12:01 +02:00
|
|
|
AudioInputModule::AudioInputModule(std::string deviceID, void *controller)
|
|
|
|
{
|
2017-07-04 15:50:02 +02:00
|
|
|
wrapper = (VoIP *)((VoIPController *)controller)->implData;
|
2017-07-09 21:12:01 +02:00
|
|
|
wrapper->inputCreated = true;
|
2017-06-18 19:32:20 +02:00
|
|
|
}
|
|
|
|
|
2017-07-09 21:12:01 +02:00
|
|
|
AudioInputModule::~AudioInputModule()
|
|
|
|
{
|
|
|
|
wrapper->inputConfigured = false;
|
|
|
|
wrapper->inputCreated = false;
|
2017-06-18 19:32:20 +02:00
|
|
|
}
|
2017-06-28 21:02:15 +02:00
|
|
|
|
2017-07-09 21:12:01 +02:00
|
|
|
void AudioInputModule::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels)
|
|
|
|
{
|
|
|
|
wrapper->inputSampleNumber = 960;
|
|
|
|
wrapper->inputSampleRate = sampleRate;
|
|
|
|
wrapper->inputBitsPerSample = bitsPerSample;
|
|
|
|
wrapper->inputChannels = channels;
|
|
|
|
wrapper->inputSamplePeriod = 1 / sampleRate * 1000000;
|
|
|
|
wrapper->inputWritePeriod = 1 / sampleRate * wrapper->inputSampleNumber * 1000000;
|
|
|
|
wrapper->inputSampleSize = wrapper->inputSampleNumber * wrapper->inputChannels * wrapper->inputBitsPerSample / 8;
|
2017-06-28 21:02:15 +02:00
|
|
|
|
2017-07-09 21:12:01 +02:00
|
|
|
wrapper->inputConfigured = true;
|
2017-06-18 19:32:20 +02:00
|
|
|
}
|
|
|
|
|
2017-07-09 21:12:01 +02:00
|
|
|
void AudioInputModule::Start()
|
|
|
|
{
|
|
|
|
if (wrapper->inputRunning)
|
2017-06-19 15:39:45 +02:00
|
|
|
return;
|
2017-07-09 21:12:01 +02:00
|
|
|
wrapper->inputRunning = true;
|
2017-06-18 19:32:20 +02:00
|
|
|
}
|
|
|
|
|
2017-07-09 21:12:01 +02:00
|
|
|
void AudioInputModule::Stop()
|
|
|
|
{
|
|
|
|
wrapper->inputRunning = false;
|
2017-06-18 19:32:20 +02:00
|
|
|
}
|
2017-07-09 21:12:01 +02:00
|
|
|
bool AudioInputModule::writeSamples(unsigned char *data)
|
|
|
|
{
|
|
|
|
if (wrapper->inputRunning)
|
|
|
|
{
|
2017-06-28 21:02:15 +02:00
|
|
|
LOGE("STARTED");
|
2017-07-09 21:12:01 +02:00
|
|
|
InvokeCallback(data, wrapper->inputSampleSize);
|
2017-06-28 21:02:15 +02:00
|
|
|
return true;
|
2017-07-09 21:12:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-28 21:02:15 +02:00
|
|
|
LOGE("NOT STARTED");
|
|
|
|
return false;
|
2017-07-09 21:12:01 +02:00
|
|
|
}
|
2017-06-19 23:38:03 +02:00
|
|
|
}
|
2017-07-04 15:50:02 +02:00
|
|
|
|
2017-07-09 21:12:01 +02:00
|
|
|
void AudioInputModule::EnumerateDevices(std::vector<AudioInputDevice> &devs)
|
|
|
|
{
|
2017-07-04 15:50:02 +02:00
|
|
|
}
|