multimedia/client/qt_gl_/yuvgl/media/AudioPlayer.cpp

92 lines
2.2 KiB
C++
Raw Normal View History

2020-06-04 15:28:45 +00:00
#include "AudioPlayer.h"
#include "Debuger.h"
#include "utils.h"
AudioPlayer::AudioPlayer(int index)
{
mStatus = RUNNING;
PaError err = Pa_Initialize();
if (err != paNoError) {
Debuger::Debug(L"init stream error\r\n");
mStatus = FAIL;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
PaDeviceIndex iNumDevices = Pa_GetDeviceCount();
if (iNumDevices < 0)
{
}
for (int i = 0; i < iNumDevices; i++)
{
const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(i);
Debuger::Debug(L"index %d %d %d \r\n",i,
deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels); //<2F><>ӡ<EFBFBD><EFBFBD><E8B1B8>
}
mOutputParameters.device = index;
mOutputParameters.channelCount = 2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ
mOutputParameters.sampleFormat = paInt16;
mOutputParameters.suggestedLatency = Pa_GetDeviceInfo(mOutputParameters.device)->defaultLowOutputLatency;
mOutputParameters.hostApiSpecificStreamInfo = NULL;
err = Pa_OpenStream(&mOutStream, NULL, &mOutputParameters, 44100, 1024,
paFramesPerBufferUnspecified, NULL, NULL);
if (err != paNoError) {
Debuger::Debug(L"open output stream error\r\n");
mStatus = FAIL;
goto end;
}
err = Pa_StartStream(mOutStream);
if (err != paNoError) {
Debuger::Debug(L"start stream error\r\n");
mStatus = FAIL;
}
end:
return;
}
vector<AudioPlayer::SpeakerInfo> AudioPlayer::EnumSpeakers()
{
vector<AudioPlayer::SpeakerInfo> ret;
PaError err = Pa_Initialize();
if (err != paNoError) {
Debuger::Debug(L"init stream error\r\n");
mStatus = FAIL;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
PaDeviceIndex iNumDevices = Pa_GetDeviceCount();
if (iNumDevices <= 0)
{
return ret;
}
for (int i = 0; i < iNumDevices; i++)
{
SpeakerInfo ins;
ins.index = i;
const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(i);
if(nullptr != deviceInfo)
if (deviceInfo->maxOutputChannels > 0) {
//ins.name = char2wchar(deviceInfo->name);
ret.push_back(ins);
}
}
return ret;
}
int AudioPlayer::Play(uint8_t * data, uint16_t num)
{
PaError err;
if (mStatus == RUNNING) {
err = Pa_WriteStream(mOutStream, data, num);
if (paNoError != err) {
return -1;
}
}
else {
return -1;
}
return 0;
}
int AudioPlayer::OnAudioDecode(uint8_t * dat, uint16_t size)
{
return this->Play(dat, 1024);
return 0;
}