2016-07-05 17:44:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
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
|
|
|
|
|
|
|
};
|