2016-07-05 17:44:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-07-05 17:44:02 +00:00
|
|
|
*/
|
|
|
|
#include "media/media_audio_loaders.h"
|
|
|
|
|
|
|
|
#include "media/media_audio.h"
|
|
|
|
#include "media/media_audio_ffmpeg_loader.h"
|
|
|
|
#include "media/media_child_ffmpeg_loader.h"
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace Player {
|
|
|
|
|
2017-04-06 16:49:42 +00:00
|
|
|
Loaders::Loaders(QThread *thread) : _fromVideoNotify([this] { videoSoundAdded(); }) {
|
2016-07-05 17:44:02 +00:00
|
|
|
moveToThread(thread);
|
2017-04-15 17:32:14 +00:00
|
|
|
_fromVideoNotify.moveToThread(thread);
|
2016-10-12 19:34:25 +00:00
|
|
|
connect(thread, SIGNAL(started()), this, SLOT(onInit()));
|
|
|
|
connect(thread, SIGNAL(finished()), this, SLOT(deleteLater()));
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
void Loaders::feedFromVideo(VideoSoundPart &&part) {
|
2017-05-18 20:18:59 +00:00
|
|
|
auto invoke = false;
|
2016-07-05 17:44:02 +00:00
|
|
|
{
|
|
|
|
QMutexLocker lock(&_fromVideoMutex);
|
2017-05-18 20:18:59 +00:00
|
|
|
_fromVideoQueues[part.audio].enqueue(FFMpeg::dataWrapFromPacket(*part.packet));
|
|
|
|
invoke = true;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
if (invoke) {
|
|
|
|
_fromVideoNotify.call();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-06 16:49:42 +00:00
|
|
|
void Loaders::videoSoundAdded() {
|
2017-05-18 20:18:59 +00:00
|
|
|
auto waitingAndAdded = false;
|
|
|
|
auto queues = decltype(_fromVideoQueues)();
|
2016-07-05 17:44:02 +00:00
|
|
|
{
|
|
|
|
QMutexLocker lock(&_fromVideoMutex);
|
2017-05-18 20:18:59 +00:00
|
|
|
queues = base::take(_fromVideoQueues);
|
|
|
|
}
|
|
|
|
auto tryLoader = [this](auto &audio, auto &loader, auto &it) {
|
|
|
|
if (audio == it.key() && loader) {
|
|
|
|
loader->enqueuePackets(it.value());
|
|
|
|
if (loader->holdsSavedDecodedSamples()) {
|
|
|
|
onLoad(audio);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
for (auto i = queues.begin(), e = queues.end(); i != e; ++i) {
|
|
|
|
if (!tryLoader(_audio, _audioLoader, i)
|
|
|
|
&& !tryLoader(_song, _songLoader, i)
|
|
|
|
&& !tryLoader(_video, _videoLoader, i)) {
|
|
|
|
for (auto &packetData : i.value()) {
|
|
|
|
AVPacket packet;
|
|
|
|
FFMpeg::packetFromDataWrap(packet, packetData);
|
|
|
|
FFMpeg::freePacket(&packet);
|
|
|
|
}
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (waitingAndAdded) {
|
|
|
|
onLoad(_video);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
Loaders::~Loaders() {
|
2016-07-05 17:44:02 +00:00
|
|
|
QMutexLocker lock(&_fromVideoMutex);
|
|
|
|
clearFromVideoQueue();
|
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
void Loaders::clearFromVideoQueue() {
|
2017-05-18 20:18:59 +00:00
|
|
|
auto queues = base::take(_fromVideoQueues);
|
|
|
|
for (auto &queue : queues) {
|
|
|
|
for (auto &packetData : queue) {
|
|
|
|
AVPacket packet;
|
|
|
|
FFMpeg::packetFromDataWrap(packet, packetData);
|
|
|
|
FFMpeg::freePacket(&packet);
|
|
|
|
}
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
void Loaders::onInit() {
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
void Loaders::onStart(const AudioMsgId &audio, qint64 position) {
|
2016-07-05 17:44:02 +00:00
|
|
|
auto type = audio.type();
|
|
|
|
clear(type);
|
|
|
|
{
|
|
|
|
QMutexLocker lock(internal::audioPlayerMutex());
|
2017-01-19 08:24:43 +00:00
|
|
|
if (!mixer()) return;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
auto track = mixer()->trackForType(type);
|
|
|
|
if (!track) return;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
track->loading = true;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loadData(audio, position);
|
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
AudioMsgId Loaders::clear(AudioMsgId::Type type) {
|
2016-07-05 17:44:02 +00:00
|
|
|
AudioMsgId result;
|
|
|
|
switch (type) {
|
|
|
|
case AudioMsgId::Type::Voice: std::swap(result, _audio); _audioLoader = nullptr; break;
|
|
|
|
case AudioMsgId::Type::Song: std::swap(result, _song); _songLoader = nullptr; break;
|
|
|
|
case AudioMsgId::Type::Video: std::swap(result, _video); _videoLoader = nullptr; break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
void Loaders::setStoppedState(Mixer::Track *track, State state) {
|
2017-05-23 14:04:59 +00:00
|
|
|
mixer()->setStoppedState(track, state);
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
void Loaders::emitError(AudioMsgId::Type type) {
|
2016-07-05 17:44:02 +00:00
|
|
|
emit error(clear(type));
|
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
void Loaders::onLoad(const AudioMsgId &audio) {
|
2016-07-05 17:44:02 +00:00
|
|
|
loadData(audio, 0);
|
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
void Loaders::loadData(AudioMsgId audio, qint64 position) {
|
2017-01-24 21:24:39 +00:00
|
|
|
auto err = SetupNoErrorStarted;
|
2016-07-05 17:44:02 +00:00
|
|
|
auto type = audio.type();
|
2017-01-24 21:24:39 +00:00
|
|
|
auto l = setupLoader(audio, err, position);
|
2016-07-05 17:44:02 +00:00
|
|
|
if (!l) {
|
|
|
|
if (err == SetupErrorAtStart) {
|
|
|
|
emitError(type);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
auto started = (err == SetupNoErrorStarted);
|
|
|
|
auto finished = false;
|
|
|
|
auto waiting = false;
|
|
|
|
auto errAtStart = started;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
QByteArray samples;
|
|
|
|
int64 samplesCount = 0;
|
|
|
|
if (l->holdsSavedDecodedSamples()) {
|
|
|
|
l->takeSavedDecodedSamples(&samples, &samplesCount);
|
|
|
|
}
|
|
|
|
while (samples.size() < AudioVoiceMsgBufferSize) {
|
|
|
|
auto res = l->readMore(samples, samplesCount);
|
|
|
|
using Result = AudioPlayerLoader::ReadResult;
|
|
|
|
if (res == Result::Error) {
|
|
|
|
if (errAtStart) {
|
|
|
|
{
|
|
|
|
QMutexLocker lock(internal::audioPlayerMutex());
|
2017-01-24 21:24:39 +00:00
|
|
|
if (auto track = checkLoader(type)) {
|
|
|
|
track->state.state = State::StoppedAtStart;
|
|
|
|
}
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
emitError(type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
finished = true;
|
|
|
|
break;
|
2016-07-05 17:44:22 +00:00
|
|
|
} else if (res == Result::EndOfFile) {
|
|
|
|
finished = true;
|
|
|
|
break;
|
2016-07-05 17:44:02 +00:00
|
|
|
} else if (res == Result::Ok) {
|
|
|
|
errAtStart = false;
|
|
|
|
} else if (res == Result::Wait) {
|
2016-07-05 17:44:22 +00:00
|
|
|
waiting = (samples.size() < AudioVoiceMsgBufferSize);
|
2016-07-05 17:44:02 +00:00
|
|
|
if (waiting) {
|
|
|
|
l->saveDecodedSamples(&samples, &samplesCount);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMutexLocker lock(internal::audioPlayerMutex());
|
|
|
|
if (!checkLoader(type)) {
|
|
|
|
clear(type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QMutexLocker lock(internal::audioPlayerMutex());
|
2017-01-24 21:24:39 +00:00
|
|
|
auto track = checkLoader(type);
|
|
|
|
if (!track) {
|
2016-07-05 17:44:02 +00:00
|
|
|
clear(type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (started) {
|
2017-05-03 11:36:39 +00:00
|
|
|
Audio::AttachToDevice();
|
2017-01-24 21:24:39 +00:00
|
|
|
|
|
|
|
track->started();
|
|
|
|
if (!internal::audioCheckError()) {
|
|
|
|
setStoppedState(track, State::StoppedAtStart);
|
|
|
|
emitError(type);
|
|
|
|
return;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
track->bufferedPosition = position;
|
|
|
|
track->state.position = position;
|
|
|
|
track->fadeStartPosition = position;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
track->format = l->format();
|
2017-05-03 13:01:15 +00:00
|
|
|
track->frequency = l->samplesFrequency();
|
2017-01-24 21:24:39 +00:00
|
|
|
}
|
|
|
|
if (samplesCount) {
|
|
|
|
track->ensureStreamCreated();
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
auto bufferIndex = track->getNotQueuedBufferIndex();
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
if (!internal::audioCheckError()) {
|
|
|
|
setStoppedState(track, State::StoppedAtError);
|
|
|
|
emitError(type);
|
|
|
|
return;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
if (bufferIndex < 0) { // No free buffers, wait.
|
|
|
|
l->saveDecodedSamples(&samples, &samplesCount);
|
|
|
|
return;
|
|
|
|
}
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
track->bufferSamples[bufferIndex] = samples;
|
|
|
|
track->samplesCount[bufferIndex] = samplesCount;
|
|
|
|
track->bufferedLength += samplesCount;
|
|
|
|
alBufferData(track->stream.buffers[bufferIndex], track->format, samples.constData(), samples.size(), track->frequency);
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
alSourceQueueBuffers(track->stream.source, 1, track->stream.buffers + bufferIndex);
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
if (!internal::audioCheckError()) {
|
2017-01-24 21:24:39 +00:00
|
|
|
setStoppedState(track, State::StoppedAtError);
|
2016-07-05 17:44:02 +00:00
|
|
|
emitError(type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (waiting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
finished = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (finished) {
|
2017-01-24 21:24:39 +00:00
|
|
|
track->loaded = true;
|
2017-05-03 13:01:15 +00:00
|
|
|
track->state.length = track->bufferedPosition + track->bufferedLength;
|
2016-07-05 17:44:02 +00:00
|
|
|
clear(type);
|
|
|
|
}
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
track->loading = false;
|
|
|
|
if (track->state.state == State::Resuming || track->state.state == State::Playing || track->state.state == State::Starting) {
|
2016-07-05 17:44:02 +00:00
|
|
|
ALint state = AL_INITIAL;
|
2017-01-24 21:24:39 +00:00
|
|
|
alGetSourcei(track->stream.source, AL_SOURCE_STATE, &state);
|
2016-07-05 17:44:02 +00:00
|
|
|
if (internal::audioCheckError()) {
|
|
|
|
if (state != AL_PLAYING) {
|
2017-01-24 21:24:39 +00:00
|
|
|
if (state == AL_STOPPED && !internal::CheckAudioDeviceConnected()) {
|
|
|
|
return;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
2017-01-24 21:24:39 +00:00
|
|
|
|
|
|
|
alSourcef(track->stream.source, AL_GAIN, ComputeVolume(type));
|
2016-07-05 17:44:02 +00:00
|
|
|
if (!internal::audioCheckError()) {
|
2017-01-24 21:24:39 +00:00
|
|
|
setStoppedState(track, State::StoppedAtError);
|
2016-07-05 17:44:02 +00:00
|
|
|
emitError(type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
alSourcePlay(track->stream.source);
|
2016-07-05 17:44:02 +00:00
|
|
|
if (!internal::audioCheckError()) {
|
2017-01-24 21:24:39 +00:00
|
|
|
setStoppedState(track, State::StoppedAtError);
|
2016-07-05 17:44:02 +00:00
|
|
|
emitError(type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit needToCheck();
|
|
|
|
}
|
|
|
|
} else {
|
2017-01-24 21:24:39 +00:00
|
|
|
setStoppedState(track, State::StoppedAtError);
|
2016-07-05 17:44:02 +00:00
|
|
|
emitError(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
AudioPlayerLoader *Loaders::setupLoader(const AudioMsgId &audio, SetupError &err, qint64 &position) {
|
2016-07-05 17:44:02 +00:00
|
|
|
err = SetupErrorAtStart;
|
|
|
|
QMutexLocker lock(internal::audioPlayerMutex());
|
2017-01-19 08:24:43 +00:00
|
|
|
if (!mixer()) return nullptr;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
auto track = mixer()->trackForType(audio.type());
|
|
|
|
if (!track || track->state.id != audio || !track->loading) {
|
2016-07-05 17:44:02 +00:00
|
|
|
emit error(audio);
|
|
|
|
LOG(("Audio Error: trying to load part of audio, that is not current at the moment"));
|
|
|
|
err = SetupErrorNotPlaying;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isGoodId = false;
|
|
|
|
AudioPlayerLoader *l = nullptr;
|
|
|
|
switch (audio.type()) {
|
|
|
|
case AudioMsgId::Type::Voice: l = _audioLoader.get(); isGoodId = (_audio == audio); break;
|
|
|
|
case AudioMsgId::Type::Song: l = _songLoader.get(); isGoodId = (_song == audio); break;
|
2016-07-05 17:44:22 +00:00
|
|
|
case AudioMsgId::Type::Video: l = _videoLoader.get(); isGoodId = (_video == audio); break;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
if (l && (!isGoodId || !l->check(track->file, track->data))) {
|
2016-07-05 17:44:02 +00:00
|
|
|
clear(audio.type());
|
2016-07-05 17:44:22 +00:00
|
|
|
l = nullptr;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!l) {
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<AudioPlayerLoader> *loader = nullptr;
|
2016-07-05 17:44:02 +00:00
|
|
|
switch (audio.type()) {
|
|
|
|
case AudioMsgId::Type::Voice: _audio = audio; loader = &_audioLoader; break;
|
|
|
|
case AudioMsgId::Type::Song: _song = audio; loader = &_songLoader; break;
|
2017-05-18 20:18:59 +00:00
|
|
|
case AudioMsgId::Type::Video: _video = audio; loader = &_videoLoader; break;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 20:18:59 +00:00
|
|
|
if (audio.playId()) {
|
2017-01-24 21:24:39 +00:00
|
|
|
if (!track->videoData) {
|
2017-05-18 20:18:59 +00:00
|
|
|
clear(audio.type());
|
2017-01-24 21:24:39 +00:00
|
|
|
track->state.state = State::StoppedAtError;
|
2016-07-05 17:44:22 +00:00
|
|
|
emit error(audio);
|
|
|
|
LOG(("Audio Error: video sound data not ready"));
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-05-18 20:18:59 +00:00
|
|
|
*loader = std::make_unique<ChildFFMpegLoader>(std::move(track->videoData));
|
2016-07-05 17:44:02 +00:00
|
|
|
} else {
|
2017-05-03 11:36:39 +00:00
|
|
|
*loader = std::make_unique<FFMpegLoader>(track->file, track->data, base::byte_vector());
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
2017-05-18 20:18:59 +00:00
|
|
|
l = loader->get();
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
if (!l->open(position)) {
|
2017-01-24 21:24:39 +00:00
|
|
|
track->state.state = State::StoppedAtStart;
|
2016-07-05 17:44:02 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-05-03 13:01:15 +00:00
|
|
|
auto length = l->samplesCount();
|
|
|
|
if (length <= 0) {
|
2017-01-24 21:24:39 +00:00
|
|
|
track->state.state = State::StoppedAtStart;
|
2016-07-05 17:44:02 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-05-03 13:01:15 +00:00
|
|
|
track->state.length = length;
|
|
|
|
track->state.frequency = l->samplesFrequency();
|
2017-01-24 21:24:39 +00:00
|
|
|
if (!track->state.frequency) track->state.frequency = kDefaultFrequency;
|
2016-07-05 17:44:02 +00:00
|
|
|
err = SetupNoErrorStarted;
|
2017-01-24 21:24:39 +00:00
|
|
|
} else if (track->loaded) {
|
|
|
|
err = SetupErrorLoadedFull;
|
|
|
|
LOG(("Audio Error: trying to load part of audio, that is already loaded to the end"));
|
|
|
|
return nullptr;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
Mixer::Track *Loaders::checkLoader(AudioMsgId::Type type) {
|
2017-01-19 08:24:43 +00:00
|
|
|
if (!mixer()) return nullptr;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
auto track = mixer()->trackForType(type);
|
|
|
|
auto isGoodId = false;
|
2016-07-05 17:44:02 +00:00
|
|
|
AudioPlayerLoader *l = nullptr;
|
|
|
|
switch (type) {
|
2017-01-24 21:24:39 +00:00
|
|
|
case AudioMsgId::Type::Voice: l = _audioLoader.get(); isGoodId = (track->state.id == _audio); break;
|
|
|
|
case AudioMsgId::Type::Song: l = _songLoader.get(); isGoodId = (track->state.id == _song); break;
|
|
|
|
case AudioMsgId::Type::Video: l = _videoLoader.get(); isGoodId = (track->state.id == _video); break;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
2017-01-24 21:24:39 +00:00
|
|
|
if (!l || !track) return nullptr;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
if (!isGoodId || !track->loading || !l->check(track->file, track->data)) {
|
2016-07-05 17:44:02 +00:00
|
|
|
LOG(("Audio Error: playing changed while loading"));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
return track;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 08:24:43 +00:00
|
|
|
void Loaders::onCancel(const AudioMsgId &audio) {
|
2016-07-05 17:44:02 +00:00
|
|
|
switch (audio.type()) {
|
|
|
|
case AudioMsgId::Type::Voice: if (_audio == audio) clear(audio.type()); break;
|
|
|
|
case AudioMsgId::Type::Song: if (_song == audio) clear(audio.type()); break;
|
|
|
|
case AudioMsgId::Type::Video: if (_video == audio) clear(audio.type()); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMutexLocker lock(internal::audioPlayerMutex());
|
2017-01-19 08:24:43 +00:00
|
|
|
if (!mixer()) return;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-01-24 21:24:39 +00:00
|
|
|
for (auto i = 0; i != kTogetherLimit; ++i) {
|
|
|
|
auto track = mixer()->trackForType(audio.type(), i);
|
|
|
|
if (track->state.id == audio) {
|
|
|
|
track->loading = false;
|
2016-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-19 08:24:43 +00:00
|
|
|
|
|
|
|
} // namespace Player
|
|
|
|
} // namespace Media
|