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"
|
|
|
|
|
2017-05-18 20:18:59 +00:00
|
|
|
namespace FFMpeg {
|
|
|
|
struct AVPacketDataWrap;
|
|
|
|
} // namespace FFMpeg
|
|
|
|
|
2016-07-05 17:44:02 +00:00
|
|
|
class AudioPlayerLoader {
|
|
|
|
public:
|
2018-03-27 12:16:00 +00:00
|
|
|
AudioPlayerLoader(
|
|
|
|
const FileLocation &file,
|
|
|
|
const QByteArray &data,
|
|
|
|
bytes::vector &&buffer);
|
2016-07-05 17:44:02 +00:00
|
|
|
virtual ~AudioPlayerLoader();
|
|
|
|
|
|
|
|
virtual bool check(const FileLocation &file, const QByteArray &data);
|
|
|
|
|
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
|
|
|
};
|
|
|
|
virtual ReadResult readMore(QByteArray &samples, int64 &samplesCount) = 0;
|
2017-05-18 20:18:59 +00:00
|
|
|
virtual void enqueuePackets(QQueue<FFMpeg::AVPacketDataWrap> &packets) {
|
|
|
|
Unexpected("enqueuePackets() call on not ChildFFMpegLoader.");
|
|
|
|
}
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
void saveDecodedSamples(QByteArray *samples, int64 *samplesCount);
|
|
|
|
void takeSavedDecodedSamples(QByteArray *samples, int64 *samplesCount);
|
|
|
|
bool holdsSavedDecodedSamples() const;
|
|
|
|
|
|
|
|
protected:
|
2017-05-03 11:36:39 +00:00
|
|
|
FileLocation _file;
|
|
|
|
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;
|
|
|
|
|
|
|
|
};
|