init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
140
Telegram/SourceFiles/media/audio/media_audio_track.h
Normal file
140
Telegram/SourceFiles/media/audio/media_audio_track.h
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
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 "base/timer.h"
|
||||
#include "base/bytes.h"
|
||||
#include "webrtc/webrtc_device_resolver.h"
|
||||
|
||||
namespace Core {
|
||||
class FileLocation;
|
||||
} // namespace Core
|
||||
|
||||
namespace Media {
|
||||
namespace Audio {
|
||||
|
||||
class Instance;
|
||||
|
||||
class Track {
|
||||
public:
|
||||
Track(not_null<Instance*> instance);
|
||||
|
||||
void samplePeakEach(crl::time peakDuration);
|
||||
|
||||
void fillFromData(bytes::vector &&data);
|
||||
void fillFromFile(const Core::FileLocation &location);
|
||||
void fillFromFile(const QString &filePath);
|
||||
|
||||
void playOnce(float64 volumeOverride = -1) {
|
||||
playWithLooping(false, volumeOverride);
|
||||
}
|
||||
void playInLoop(float64 volumeOverride = -1) {
|
||||
playWithLooping(true, volumeOverride);
|
||||
}
|
||||
|
||||
bool isLooping() const {
|
||||
return _looping;
|
||||
}
|
||||
bool isActive() const {
|
||||
return _active;
|
||||
}
|
||||
bool failed() const {
|
||||
return _failed;
|
||||
}
|
||||
|
||||
int64 getLengthMs() const {
|
||||
return _lengthMs;
|
||||
}
|
||||
float64 getPeakValue(crl::time when) const;
|
||||
|
||||
void detachFromDevice();
|
||||
void reattachToDevice();
|
||||
void updateState();
|
||||
|
||||
~Track();
|
||||
|
||||
private:
|
||||
void finish();
|
||||
void ensureSourceCreated();
|
||||
void playWithLooping(bool looping, float64 volumeOverride);
|
||||
|
||||
not_null<Instance*> _instance;
|
||||
|
||||
bool _failed = false;
|
||||
bool _active = false;
|
||||
bool _looping = false;
|
||||
float64 _volume = 1.;
|
||||
|
||||
int64 _samplesCount = 0;
|
||||
int32 _sampleRate = 0;
|
||||
bytes::vector _samples;
|
||||
|
||||
crl::time _peakDurationMs = 0;
|
||||
int _peakEachPosition = 0;
|
||||
std::vector<uint16> _peaks;
|
||||
uint16 _peakValueMin = 0;
|
||||
uint16 _peakValueMax = 0;
|
||||
|
||||
crl::time _lengthMs = 0;
|
||||
crl::time _stateUpdatedAt = 0;
|
||||
|
||||
int32 _alFormat = 0;
|
||||
int64 _alPosition = 0;
|
||||
uint32 _alSource = 0;
|
||||
uint32 _alBuffer = 0;
|
||||
|
||||
};
|
||||
|
||||
class Instance {
|
||||
public:
|
||||
// Thread: Main.
|
||||
Instance();
|
||||
|
||||
// Thread: Any. Must be locked: AudioMutex.
|
||||
[[nodiscard]] Webrtc::DeviceResolvedId playbackDeviceId() const;
|
||||
|
||||
// Thread: Main.
|
||||
[[nodiscard]] Webrtc::DeviceResolvedId captureDeviceId() const;
|
||||
|
||||
[[nodiscard]] std::unique_ptr<Track> createTrack();
|
||||
|
||||
void detachTracks();
|
||||
void reattachTracks();
|
||||
bool hasActiveTracks() const;
|
||||
|
||||
void scheduleDetachFromDevice();
|
||||
void scheduleDetachIfNotUsed();
|
||||
void stopDetachIfNotUsed();
|
||||
|
||||
~Instance();
|
||||
|
||||
private:
|
||||
friend class Track;
|
||||
void registerTrack(Track *track);
|
||||
void unregisterTrack(Track *track);
|
||||
void trackStarted(Track *track);
|
||||
void trackFinished(Track *track);
|
||||
|
||||
private:
|
||||
std::set<Track*> _tracks;
|
||||
Webrtc::DeviceResolver _playbackDeviceId;
|
||||
Webrtc::DeviceResolver _captureDeviceId;
|
||||
|
||||
base::Timer _updateTimer;
|
||||
|
||||
base::Timer _detachFromDeviceTimer;
|
||||
bool _detachFromDeviceForce = false;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
};
|
||||
|
||||
[[nodiscard]] Instance &Current();
|
||||
|
||||
} // namespace Audio
|
||||
} // namespace Media
|
||||
Reference in New Issue
Block a user