tdesktop/Telegram/SourceFiles/media/audio/media_child_ffmpeg_loader.h

63 lines
1.6 KiB
C
Raw Normal View History

/*
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_ffmpeg_loader.h"
2019-02-28 21:03:25 +00:00
#include "media/streaming/media_streaming_utility.h"
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;
crl::time duration = 0;
float64 speed = 1.; // 0.5 <= speed <= 2.
};
2019-02-28 21:03:25 +00:00
struct ExternalSoundPart {
AudioMsgId audio;
gsl::span<FFmpeg::Packet> packets;
};
class ChildFFMpegLoader : public AbstractAudioFFMpegLoader {
public:
2019-02-28 21:03:25 +00:00
ChildFFMpegLoader(std::unique_ptr<ExternalSoundData> &&data);
bool open(crl::time positionMs, float64 speed = 1.) override;
bool check(const Core::FileLocation &file, const QByteArray &data) override {
return true;
}
2023-03-06 09:51:37 +00:00
ReadResult readMore() override;
2019-06-26 15:04:38 +00:00
void enqueuePackets(std::deque<FFmpeg::Packet> &&packets) override;
void setForceToBuffer(bool force) override;
bool forceToBuffer() const override;
bool eofReached() const {
return _eofReached;
}
~ChildFFMpegLoader();
private:
// 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.
2023-03-06 09:51:37 +00:00
ReadResult readFromInitialFrame();
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;
bool _forceToBuffer = false;
bool _eofReached = false;
bool _readTillEnd = false;
};
2019-02-28 21:03:25 +00:00
} // namespace Media