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-01-02 17:22:13 +00:00
|
|
|
#include "media/media_audio_ffmpeg_loader.h"
|
2016-07-05 17:44:02 +00:00
|
|
|
|
|
|
|
struct VideoSoundData {
|
|
|
|
AVCodecContext *context = 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;
|
2016-07-05 17:44:02 +00:00
|
|
|
~VideoSoundData();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VideoSoundPart {
|
|
|
|
AVPacket *packet = nullptr;
|
2017-05-18 20:18:59 +00:00
|
|
|
AudioMsgId audio;
|
|
|
|
uint32 playId = 0;
|
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
|
|
|
|
// variable (e.g. inside QQueue), a compile warning is emited.
|
|
|
|
// 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
|
|
|
|
2017-12-10 08:52:38 +00:00
|
|
|
bool open(TimeMs 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:
|
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
|
|
|
|
|
|
|
};
|