2016-07-05 17:44:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-07-05 17:44:02 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-03-27 12:16:00 +00:00
|
|
|
#include "base/bytes.h"
|
2020-10-13 16:43:18 +00:00
|
|
|
#include "core/file_location.h"
|
2019-02-28 21:03:25 +00:00
|
|
|
#include "media/streaming/media_streaming_utility.h"
|
2018-03-27 12:16:00 +00:00
|
|
|
|
2019-02-28 21:03:25 +00:00
|
|
|
namespace Media {
|
2017-05-18 20:18:59 +00:00
|
|
|
|
2016-07-05 17:44:02 +00:00
|
|
|
class AudioPlayerLoader {
|
|
|
|
public:
|
2018-03-27 12:16:00 +00:00
|
|
|
AudioPlayerLoader(
|
2020-10-13 16:43:18 +00:00
|
|
|
const Core::FileLocation &file,
|
2018-03-27 12:16:00 +00:00
|
|
|
const QByteArray &data,
|
|
|
|
bytes::vector &&buffer);
|
2016-07-05 17:44:02 +00:00
|
|
|
virtual ~AudioPlayerLoader();
|
|
|
|
|
2020-10-13 16:43:18 +00:00
|
|
|
virtual bool check(const Core::FileLocation &file, const QByteArray &data);
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
virtual bool open(crl::time positionMs) = 0;
|
2017-05-03 13:01:15 +00:00
|
|
|
virtual int64 samplesCount() = 0;
|
2018-01-02 16:18:53 +00:00
|
|
|
virtual int samplesFrequency() = 0;
|
|
|
|
virtual int format() = 0;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
enum class ReadResult {
|
|
|
|
Error,
|
|
|
|
NotYet,
|
|
|
|
Ok,
|
|
|
|
Wait,
|
2016-07-05 17:44:22 +00:00
|
|
|
EndOfFile,
|
2016-07-05 17:44:02 +00:00
|
|
|
};
|
2019-02-28 21:03:25 +00:00
|
|
|
virtual ReadResult readMore(
|
|
|
|
QByteArray &samples,
|
|
|
|
int64 &samplesCount) = 0;
|
2019-06-26 15:04:38 +00:00
|
|
|
virtual void enqueuePackets(std::deque<FFmpeg::Packet> &&packets) {
|
2017-05-18 20:18:59 +00:00
|
|
|
Unexpected("enqueuePackets() call on not ChildFFMpegLoader.");
|
|
|
|
}
|
2019-02-21 13:40:09 +00:00
|
|
|
virtual void setForceToBuffer(bool force) {
|
|
|
|
Unexpected("setForceToBuffer() call on not ChildFFMpegLoader.");
|
|
|
|
}
|
|
|
|
virtual bool forceToBuffer() const {
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2019-02-28 21:03:25 +00:00
|
|
|
void saveDecodedSamples(
|
|
|
|
not_null<QByteArray*> samples,
|
|
|
|
not_null<int64*> samplesCount);
|
|
|
|
void takeSavedDecodedSamples(
|
|
|
|
not_null<QByteArray*> samples,
|
|
|
|
not_null<int64*> samplesCount);
|
2016-07-05 17:44:02 +00:00
|
|
|
bool holdsSavedDecodedSamples() const;
|
|
|
|
|
|
|
|
protected:
|
2020-10-13 16:43:18 +00:00
|
|
|
Core::FileLocation _file;
|
2017-05-03 11:36:39 +00:00
|
|
|
bool _access = false;
|
|
|
|
QByteArray _data;
|
2018-03-27 12:16:00 +00:00
|
|
|
bytes::vector _bytes;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2017-05-03 11:36:39 +00:00
|
|
|
QFile _f;
|
|
|
|
int _dataPos = 0;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
bool openFile();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QByteArray _savedSamples;
|
|
|
|
int64 _savedSamplesCount = 0;
|
|
|
|
bool _holdsSavedSamples = false;
|
|
|
|
|
|
|
|
};
|
2019-02-28 21:03:25 +00:00
|
|
|
|
|
|
|
} // namespace Media
|