summaryrefslogtreecommitdiffstats
path: root/Telegram/SourceFiles/media/audio/media_audio_loaders.h
blob: 220d338efc3617a64f4dc19898e4fc8b592ad688 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.

For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once

#include "media/audio/media_audio.h"
#include "media/audio/media_child_ffmpeg_loader.h"

class AudioPlayerLoader;
class ChildFFMpegLoader;

namespace Media {
namespace Player {

class Loaders : public QObject {
	Q_OBJECT

public:
	Loaders(QThread *thread);
	void feedFromExternal(ExternalSoundPart &&part);
	void forceToBufferExternal(const AudioMsgId &audioId);
	~Loaders();

Q_SIGNALS:
	void error(const AudioMsgId &audio);
	void needToCheck();

public Q_SLOTS:
	void onInit();

	void onStart(const AudioMsgId &audio, qint64 positionMs);
	void onLoad(const AudioMsgId &audio);
	void onCancel(const AudioMsgId &audio);

private:
	void videoSoundAdded();

	AudioMsgId _audio, _song, _video;
	std::unique_ptr<AudioPlayerLoader> _audioLoader;
	std::unique_ptr<AudioPlayerLoader> _songLoader;
	std::unique_ptr<AudioPlayerLoader> _videoLoader;

	QMutex _fromExternalMutex;
	base::flat_map<
		AudioMsgId,
		std::deque<FFmpeg::Packet>> _fromExternalQueues;
	base::flat_set<AudioMsgId> _fromExternalForceToBuffer;
	SingleQueuedInvokation _fromExternalNotify;

	void emitError(AudioMsgId::Type type);
	AudioMsgId clear(AudioMsgId::Type type);
	void setStoppedState(Mixer::Track *m, State state = State::Stopped);

	enum SetupError {
		SetupErrorAtStart = 0,
		SetupErrorNotPlaying = 1,
		SetupErrorLoadedFull = 2,
		SetupNoErrorStarted = 3,
	};
	void loadData(AudioMsgId audio, crl::time positionMs = 0);
	AudioPlayerLoader *setupLoader(
		const AudioMsgId &audio,
		SetupError &err,
		crl::time positionMs);
	Mixer::Track *checkLoader(AudioMsgId::Type type);

};

} // namespace Player
} // namespace Media