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-06-22 14:48:52 +02:00
|
|
|
|
2017-06-18 19:32:20 +02:00
|
|
|
#include "AudioOutputPHP.h"
|
|
|
|
#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-06-19 15:39:45 +02:00
|
|
|
AudioOutputPHP::AudioOutputPHP(Php::Value callbacks){
|
|
|
|
startMethod = callbacks["start"];
|
|
|
|
stopMethod = callbacks["stop"];
|
|
|
|
configureMethod = callbacks["configure"];
|
|
|
|
getLevelMethod = callbacks["get_level"];
|
2017-06-23 22:41:23 +02:00
|
|
|
call = callbacks["call"];
|
2017-06-18 19:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioOutputPHP::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels){
|
2017-06-23 22:41:23 +02:00
|
|
|
configureMethod(static_cast<VoIP*> call, (int32_t)sampleRate, (int32_t)bitsPerSample, (int32_t)channels);
|
2017-06-19 15:39:45 +02:00
|
|
|
}
|
2017-06-18 19:32:20 +02:00
|
|
|
|
2017-06-19 15:39:45 +02:00
|
|
|
void AudioOutputPHP::Start(){
|
|
|
|
if(running)
|
|
|
|
return;
|
|
|
|
running = true;
|
2017-06-23 22:41:23 +02:00
|
|
|
startMethod(static_cast<VoIP*> call);
|
2017-06-19 15:39:45 +02:00
|
|
|
}
|
2017-06-18 19:32:20 +02:00
|
|
|
|
2017-06-19 15:39:45 +02:00
|
|
|
void AudioOutputPHP::Stop(){
|
|
|
|
if(!running)
|
|
|
|
return;
|
2017-06-23 22:41:23 +02:00
|
|
|
stopMethod(static_cast<VoIP*> call);
|
2017-06-19 15:39:45 +02:00
|
|
|
running = false;
|
2017-06-18 19:32:20 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 15:39:45 +02:00
|
|
|
bool AudioOutputPHP::IsPlaying(){
|
|
|
|
return running;
|
|
|
|
}
|
2017-06-18 19:32:20 +02:00
|
|
|
|
2017-06-19 15:39:45 +02:00
|
|
|
float AudioOutputPHP::GetLevel(){
|
2017-06-23 22:41:23 +02:00
|
|
|
return (double)getLevelMethod(static_cast<VoIP*> call);
|
2017-06-19 15:39:45 +02:00
|
|
|
}
|
2017-06-18 19:32:20 +02:00
|
|
|
|
2017-06-19 15:39:45 +02:00
|
|
|
Php::Value AudioOutputPHP::readFrames() {
|
|
|
|
unsigned char* buf;
|
|
|
|
InvokeCallback(buf, 960*2);
|
|
|
|
return buf;
|
2017-06-18 19:32:20 +02:00
|
|
|
}
|