mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-23 11:47:57 +00:00
openal fix for windows to hybernate
This commit is contained in:
parent
ed44b818fc
commit
94b0a83f0b
@ -51,6 +51,7 @@ bool _checkALError() {
|
||||
}
|
||||
|
||||
void audioInit() {
|
||||
uint64 ms = getms();
|
||||
if (audioDevice) return;
|
||||
|
||||
audioDevice = alcOpenDevice(NULL);
|
||||
@ -148,6 +149,8 @@ void audioInit() {
|
||||
if (!_checkALError()) return audioFinish();
|
||||
|
||||
voicemsgs = new VoiceMessages();
|
||||
alcSuspendContext(audioContext);
|
||||
LOG(("Audio init time: %1").arg(getms() - ms));
|
||||
}
|
||||
|
||||
bool audioWorks() {
|
||||
@ -157,7 +160,9 @@ bool audioWorks() {
|
||||
void audioPlayNotify() {
|
||||
if (!audioWorks()) return;
|
||||
|
||||
audioVoice()->processContext();
|
||||
alSourcePlay(notifySource);
|
||||
emit audioVoice()->faderOnTimer();
|
||||
}
|
||||
|
||||
void audioFinish() {
|
||||
@ -307,6 +312,7 @@ void VoiceMessages::pauseresume() {
|
||||
updateCurrentStarted();
|
||||
}
|
||||
_data[_current].state = VoiceMessageResuming;
|
||||
processContext();
|
||||
alSourcePlay(_data[_current].source);
|
||||
break;
|
||||
case VoiceMessageStarting:
|
||||
@ -328,15 +334,25 @@ void VoiceMessages::currentState(AudioData **audio, VoiceMessageState *state, in
|
||||
if (duration) *duration = _data[_current].duration;
|
||||
}
|
||||
|
||||
void VoiceMessages::processContext() {
|
||||
_fader->processContext();
|
||||
}
|
||||
|
||||
VoiceMessages *audioVoice() {
|
||||
return voicemsgs;
|
||||
}
|
||||
|
||||
VoiceMessagesFader::VoiceMessagesFader(QThread *thread) : _timer(this) {
|
||||
VoiceMessagesFader::VoiceMessagesFader(QThread *thread) : _timer(this), _suspendFlag(false) {
|
||||
moveToThread(thread);
|
||||
_timer.moveToThread(thread);
|
||||
_suspendTimer.moveToThread(thread);
|
||||
|
||||
_timer.setSingleShot(true);
|
||||
connect(&_timer, SIGNAL(timeout()), this, SLOT(onTimer()));
|
||||
|
||||
_suspendTimer.setSingleShot(true);
|
||||
connect(&_suspendTimer, SIGNAL(timeout()), this, SLOT(onSuspendTimer()));
|
||||
connect(this, SIGNAL(stopSuspend()), this, SLOT(onSuspendTimerStop()), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void VoiceMessagesFader::onInit() {
|
||||
@ -403,7 +419,6 @@ void VoiceMessagesFader::onTimer() {
|
||||
b = a;
|
||||
}
|
||||
alSourcef(m.source, AL_GAIN, newGain);
|
||||
LOG(("Now volume is: %1").arg(newGain));
|
||||
}
|
||||
} else if (playing && (state == AL_PLAYING || !m.loading)) {
|
||||
if (state != AL_PLAYING) {
|
||||
@ -428,13 +443,44 @@ void VoiceMessagesFader::onTimer() {
|
||||
if (fading) hasFading = true;
|
||||
}
|
||||
}
|
||||
if (!hasPlaying) {
|
||||
ALint state = AL_INITIAL;
|
||||
alGetSourcei(notifySource, AL_SOURCE_STATE, &state);
|
||||
if (_checkALError() && state == AL_PLAYING) {
|
||||
hasPlaying = true;
|
||||
}
|
||||
}
|
||||
if (hasFading) {
|
||||
_timer.start(AudioFadeTimeout);
|
||||
processContext();
|
||||
} else if (hasPlaying) {
|
||||
_timer.start(AudioCheckPositionTimeout);
|
||||
processContext();
|
||||
} else {
|
||||
QMutexLocker lock(&_suspendMutex);
|
||||
_suspendFlag = true;
|
||||
_suspendTimer.start(AudioSuspendTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
void VoiceMessagesFader::onSuspendTimer() {
|
||||
QMutexLocker lock(&_suspendMutex);
|
||||
if (_suspendFlag) {
|
||||
alcSuspendContext(audioContext);
|
||||
}
|
||||
}
|
||||
|
||||
void VoiceMessagesFader::onSuspendTimerStop() {
|
||||
if (_suspendTimer.isActive()) _suspendTimer.stop();
|
||||
}
|
||||
|
||||
void VoiceMessagesFader::processContext() {
|
||||
QMutexLocker lock(&_suspendMutex);
|
||||
_suspendFlag = false;
|
||||
emit stopSuspend();
|
||||
alcProcessContext(audioContext);
|
||||
}
|
||||
|
||||
struct VoiceMessagesLoader::Loader {
|
||||
QString fname;
|
||||
QByteArray data;
|
||||
@ -681,6 +727,7 @@ void VoiceMessagesLoader::onLoad(AudioData *audio) {
|
||||
alGetSourcei(m.source, AL_SOURCE_STATE, &state);
|
||||
if (_checkALError()) {
|
||||
if (state != AL_PLAYING) {
|
||||
voice->processContext();
|
||||
alSourcePlay(m.source);
|
||||
emit needToCheck();
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
void pauseresume();
|
||||
|
||||
void currentState(AudioData **audio, VoiceMessageState *state = 0, int64 *position = 0, int64 *duration = 0);
|
||||
void processContext();
|
||||
|
||||
~VoiceMessages();
|
||||
|
||||
@ -112,6 +113,7 @@ class VoiceMessagesFader : public QObject {
|
||||
public:
|
||||
|
||||
VoiceMessagesFader(QThread *thread);
|
||||
void processContext();
|
||||
|
||||
signals:
|
||||
|
||||
@ -120,14 +122,20 @@ signals:
|
||||
void audioStopped(AudioData *audio);
|
||||
void needToPreload(AudioData *audio);
|
||||
|
||||
void stopSuspend();
|
||||
|
||||
public slots:
|
||||
|
||||
void onInit();
|
||||
void onTimer();
|
||||
void onSuspendTimer();
|
||||
void onSuspendTimerStop();
|
||||
|
||||
private:
|
||||
|
||||
QTimer _timer;
|
||||
QTimer _timer, _suspendTimer;
|
||||
QMutex _suspendMutex;
|
||||
bool _suspendFlag;
|
||||
|
||||
};
|
||||
|
||||
|
@ -86,9 +86,10 @@ enum {
|
||||
AudioVoiceMsgChannels = 2, // stereo
|
||||
AudioVoiceMsgBufferSize = 1024 * 1024, // 1 Mb buffers
|
||||
AudioVoiceMsgInMemory = 1024 * 1024, // 1 Mb audio is hold in memory and auto loaded
|
||||
AudioSuspendTimeout = 3000, // suspend in 3 secs after playing is over
|
||||
|
||||
StickerInMemory = 256 * 1024, // 128 Kb stickers hold in memory, auto loaded and displayed inline
|
||||
StickerMaxSize = 1280, // 1024x1024 is a max image size for sticker
|
||||
StickerMaxSize = 2048, // 2048x2048 is a max image size for sticker
|
||||
|
||||
MediaViewImageSizeLimit = 100 * 1024 * 1024, // show up to 100mb jpg/png/gif docs in app
|
||||
MaxZoomLevel = 7, // x8
|
||||
|
3771
Telegram/_openal_patch/Alc/ALc.c
Normal file
3771
Telegram/_openal_patch/Alc/ALc.c
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user