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
|
|
|
|
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/audio/media_audio_ffmpeg_loader.h"
|
2019-02-28 21:03:25 +00:00
|
|
|
#include "media/streaming/media_streaming_utility.h"
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2019-02-28 21:03:25 +00:00
|
|
|
namespace Media {
|
|
|
|
|
|
|
|
struct ExternalSoundData {
|
2019-06-26 15:04:38 +00:00
|
|
|
FFmpeg::CodecPointer codec;
|
|
|
|
FFmpeg::FramePointer frame;
|
2017-01-24 21:24:39 +00:00
|
|
|
int32 frequency = Media::Player::kDefaultFrequency;
|
2017-05-18 20:18:59 +00:00
|
|
|
int64 length = 0;
|
2019-02-21 09:17:25 +00:00
|
|
|
float64 speed = 1.; // 0.5 <= speed <= 2.
|
2016-07-05 17:44:02 +00:00
|
|
|
};
|
|
|
|
|
2019-02-28 21:03:25 +00:00
|
|
|
struct ExternalSoundPart {
|
2017-05-18 20:18:59 +00:00
|
|
|
AudioMsgId audio;
|
2019-06-26 15:04:38 +00:00
|
|
|
FFmpeg::Packet packet;
|
2016-07-05 17:44:02 +00:00
|
|
|
};
|
|
|
|
|
2018-01-02 17:22:13 +00:00
|
|
|
class ChildFFMpegLoader : public AbstractAudioFFMpegLoader {
|
2016-07-05 17:44:02 +00:00
|
|
|
public:
|
2019-02-28 21:03:25 +00:00
|
|
|
ChildFFMpegLoader(std::unique_ptr<ExternalSoundData> &&data);
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
bool open(crl::time positionMs) override;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
bool check(const FileLocation &file, const QByteArray &data) override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadResult readMore(QByteArray &result, int64 &samplesAdded) override;
|
2019-06-26 15:04:38 +00:00
|
|
|
void enqueuePackets(std::deque<FFmpeg::Packet> &&packets) override;
|
2019-02-21 13:40:09 +00:00
|
|
|
void setForceToBuffer(bool force) override;
|
|
|
|
bool forceToBuffer() const override;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
2016-07-05 17:44:22 +00:00
|
|
|
bool eofReached() const {
|
|
|
|
return _eofReached;
|
|
|
|
}
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
~ChildFFMpegLoader();
|
|
|
|
|
|
|
|
private:
|
2019-02-17 11:08:29 +00:00
|
|
|
// Streaming player reads first frame by itself and provides it together
|
|
|
|
// with the codec context. So we first read data from this frame and
|
|
|
|
// only after that we try to read next packets.
|
|
|
|
ReadResult readFromInitialFrame(
|
|
|
|
QByteArray &result,
|
|
|
|
int64 &samplesAdded);
|
|
|
|
|
2019-02-28 21:03:25 +00:00
|
|
|
std::unique_ptr<ExternalSoundData> _parentData;
|
2019-06-26 15:04:38 +00:00
|
|
|
std::deque<FFmpeg::Packet> _queue;
|
2019-02-21 13:40:09 +00:00
|
|
|
bool _forceToBuffer = false;
|
2018-01-02 17:22:13 +00:00
|
|
|
bool _eofReached = false;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
};
|
2019-02-28 21:03:25 +00:00
|
|
|
|
|
|
|
} // namespace Media
|