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"
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
struct VideoSoundData {
|
|
|
|
AVCodecContext *context = nullptr;
|
2019-02-17 11:08:29 +00:00
|
|
|
AVFrame *frame = nullptr;
|
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
|
|
|
~VideoSoundData();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VideoSoundPart {
|
2019-02-13 18:10:18 +00:00
|
|
|
const AVPacket *packet = nullptr;
|
2017-05-18 20:18:59 +00:00
|
|
|
AudioMsgId audio;
|
2016-07-05 17:44:02 +00:00
|
|
|
};
|
|
|
|
|
2016-07-05 17:44:22 +00:00
|
|
|
namespace FFMpeg {
|
|
|
|
|
2016-07-19 16:02:39 +00:00
|
|
|
// AVPacket has a deprecated field, so when you copy an AVPacket
|
2019-02-13 18:10:18 +00:00
|
|
|
// variable (e.g. inside QQueue), a compile warning is emitted.
|
2016-07-19 16:02:39 +00:00
|
|
|
// We wrap full AVPacket data in a new AVPacketDataWrap struct.
|
|
|
|
// All other fields are copied from AVPacket without modifications.
|
|
|
|
struct AVPacketDataWrap {
|
|
|
|
char __data[sizeof(AVPacket)];
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void packetFromDataWrap(AVPacket &packet, const AVPacketDataWrap &data) {
|
|
|
|
memcpy(&packet, &data, sizeof(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline AVPacketDataWrap dataWrapFromPacket(const AVPacket &packet) {
|
|
|
|
AVPacketDataWrap data;
|
|
|
|
memcpy(&data, &packet, sizeof(data));
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2016-07-05 17:44:22 +00:00
|
|
|
inline bool isNullPacket(const AVPacket &packet) {
|
|
|
|
return packet.data == nullptr && packet.size == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isNullPacket(const AVPacket *packet) {
|
|
|
|
return isNullPacket(*packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void freePacket(AVPacket *packet) {
|
|
|
|
if (!isNullPacket(packet)) {
|
|
|
|
av_packet_unref(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace FFMpeg
|
|
|
|
|
2018-01-02 17:22:13 +00:00
|
|
|
class ChildFFMpegLoader : public AbstractAudioFFMpegLoader {
|
2016-07-05 17:44:02 +00:00
|
|
|
public:
|
2017-05-18 20:18:59 +00:00
|
|
|
ChildFFMpegLoader(std::unique_ptr<VideoSoundData> &&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;
|
2017-05-18 20:18:59 +00:00
|
|
|
void enqueuePackets(QQueue<FFMpeg::AVPacketDataWrap> &packets) 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);
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<VideoSoundData> _parentData;
|
2016-07-19 16:02:39 +00:00
|
|
|
QQueue<FFMpeg::AVPacketDataWrap> _queue;
|
2018-01-02 17:22:13 +00:00
|
|
|
bool _eofReached = false;
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
};
|