mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-31 19:12:17 +00:00
Fixed clang false warning on deprecated field of AVPacket.
This commit is contained in:
parent
49f6431fca
commit
92f15a9ad3
@ -34,7 +34,7 @@ void AudioPlayerLoaders::feedFromVideo(VideoSoundPart &&part) {
|
|||||||
{
|
{
|
||||||
QMutexLocker lock(&_fromVideoMutex);
|
QMutexLocker lock(&_fromVideoMutex);
|
||||||
if (_fromVideoPlayId == part.videoPlayId) {
|
if (_fromVideoPlayId == part.videoPlayId) {
|
||||||
_fromVideoQueue.enqueue(*part.packet);
|
_fromVideoQueue.enqueue(FFMpeg::dataWrapFromPacket(*part.packet));
|
||||||
invoke = true;
|
invoke = true;
|
||||||
} else {
|
} else {
|
||||||
FFMpeg::freePacket(part.packet);
|
FFMpeg::freePacket(part.packet);
|
||||||
@ -76,7 +76,9 @@ AudioPlayerLoaders::~AudioPlayerLoaders() {
|
|||||||
|
|
||||||
void AudioPlayerLoaders::clearFromVideoQueue() {
|
void AudioPlayerLoaders::clearFromVideoQueue() {
|
||||||
auto queue = createAndSwap(_fromVideoQueue);
|
auto queue = createAndSwap(_fromVideoQueue);
|
||||||
for (auto &packet : queue) {
|
for (auto &packetData : queue) {
|
||||||
|
AVPacket packet;
|
||||||
|
FFMpeg::packetFromDataWrap(packet, packetData);
|
||||||
FFMpeg::freePacket(&packet);
|
FFMpeg::freePacket(&packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|||||||
|
|
||||||
#include "media/media_child_ffmpeg_loader.h"
|
#include "media/media_child_ffmpeg_loader.h"
|
||||||
#include "media/media_audio.h"
|
#include "media/media_audio.h"
|
||||||
|
#include "media/media_child_ffmpeg_loader.h"
|
||||||
extern "C" {
|
|
||||||
#include <libavcodec/avcodec.h>
|
|
||||||
#include <libavformat/avformat.h>
|
|
||||||
#include <libavutil/opt.h>
|
|
||||||
#include <libswresample/swresample.h>
|
|
||||||
} // extern "C"
|
|
||||||
|
|
||||||
class AudioPlayerLoader;
|
class AudioPlayerLoader;
|
||||||
class ChildFFMpegLoader;
|
class ChildFFMpegLoader;
|
||||||
@ -65,7 +59,7 @@ private:
|
|||||||
|
|
||||||
QMutex _fromVideoMutex;
|
QMutex _fromVideoMutex;
|
||||||
uint64 _fromVideoPlayId;
|
uint64 _fromVideoPlayId;
|
||||||
QQueue<AVPacket> _fromVideoQueue;
|
QQueue<FFMpeg::AVPacketDataWrap> _fromVideoQueue;
|
||||||
SingleDelayedCall _fromVideoNotify;
|
SingleDelayedCall _fromVideoNotify;
|
||||||
|
|
||||||
void emitError(AudioMsgId::Type type);
|
void emitError(AudioMsgId::Type type);
|
||||||
|
@ -120,7 +120,10 @@ AudioPlayerLoader::ReadResult ChildFFMpegLoader::readMore(QByteArray &result, in
|
|||||||
av_frame_unref(_frame);
|
av_frame_unref(_frame);
|
||||||
int got_frame = 0;
|
int got_frame = 0;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
auto packet = _queue.dequeue();
|
|
||||||
|
AVPacket packet;
|
||||||
|
FFMpeg::packetFromDataWrap(packet, _queue.dequeue());
|
||||||
|
|
||||||
_eofReached = FFMpeg::isNullPacket(packet);
|
_eofReached = FFMpeg::isNullPacket(packet);
|
||||||
if (_eofReached) {
|
if (_eofReached) {
|
||||||
return ReadResult::EndOfFile;
|
return ReadResult::EndOfFile;
|
||||||
@ -172,14 +175,16 @@ AudioPlayerLoader::ReadResult ChildFFMpegLoader::readMore(QByteArray &result, in
|
|||||||
return ReadResult::Ok;
|
return ReadResult::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChildFFMpegLoader::enqueuePackets(QQueue<AVPacket> &packets) {
|
void ChildFFMpegLoader::enqueuePackets(QQueue<FFMpeg::AVPacketDataWrap> &packets) {
|
||||||
_queue += std_::move(packets);
|
_queue += std_::move(packets);
|
||||||
packets.clear();
|
packets.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
ChildFFMpegLoader::~ChildFFMpegLoader() {
|
ChildFFMpegLoader::~ChildFFMpegLoader() {
|
||||||
auto queue = createAndSwap(_queue);
|
auto queue = createAndSwap(_queue);
|
||||||
for (auto &packet : queue) {
|
for (auto &packetData : queue) {
|
||||||
|
AVPacket packet;
|
||||||
|
FFMpeg::packetFromDataWrap(packet, packetData);
|
||||||
FFMpeg::freePacket(&packet);
|
FFMpeg::freePacket(&packet);
|
||||||
}
|
}
|
||||||
if (_swrContext) swr_free(&_swrContext);
|
if (_swrContext) swr_free(&_swrContext);
|
||||||
|
@ -45,6 +45,24 @@ struct VideoSoundPart {
|
|||||||
|
|
||||||
namespace FFMpeg {
|
namespace FFMpeg {
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool isNullPacket(const AVPacket &packet) {
|
inline bool isNullPacket(const AVPacket &packet) {
|
||||||
return packet.data == nullptr && packet.size == 0;
|
return packet.data == nullptr && packet.size == 0;
|
||||||
}
|
}
|
||||||
@ -84,7 +102,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReadResult readMore(QByteArray &result, int64 &samplesAdded) override;
|
ReadResult readMore(QByteArray &result, int64 &samplesAdded) override;
|
||||||
void enqueuePackets(QQueue<AVPacket> &packets);
|
void enqueuePackets(QQueue<FFMpeg::AVPacketDataWrap> &packets);
|
||||||
|
|
||||||
uint64 playId() const {
|
uint64 playId() const {
|
||||||
return _videoPlayId;
|
return _videoPlayId;
|
||||||
@ -111,6 +129,6 @@ private:
|
|||||||
AVFrame *_frame = nullptr;
|
AVFrame *_frame = nullptr;
|
||||||
|
|
||||||
SwrContext *_swrContext = nullptr;
|
SwrContext *_swrContext = nullptr;
|
||||||
QQueue<AVPacket> _queue;
|
QQueue<FFMpeg::AVPacketDataWrap> _queue;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -56,12 +56,13 @@ ReaderImplementation::ReadResult FFMpegReaderImplementation::readNextFrame() {
|
|||||||
startPacket();
|
startPacket();
|
||||||
|
|
||||||
int got_frame = 0;
|
int got_frame = 0;
|
||||||
int decoded = 0;
|
|
||||||
auto packet = &_packetNull;
|
auto packet = &_packetNull;
|
||||||
|
AVPacket tempPacket;
|
||||||
if (!_packetQueue.isEmpty()) {
|
if (!_packetQueue.isEmpty()) {
|
||||||
packet = &_packetQueue.head();
|
FFMpeg::packetFromDataWrap(tempPacket, _packetQueue.head());
|
||||||
decoded = packet->size;
|
packet = &tempPacket;
|
||||||
}
|
}
|
||||||
|
int decoded = packet->size;
|
||||||
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
if ((res = avcodec_decode_video2(_codecContext, _frame, &got_frame, packet)) < 0) {
|
if ((res = avcodec_decode_video2(_codecContext, _frame, &got_frame, packet)) < 0) {
|
||||||
@ -427,7 +428,7 @@ void FFMpegReaderImplementation::processPacket(AVPacket *packet) {
|
|||||||
_lastReadPacketMs = countPacketMs(packet);
|
_lastReadPacketMs = countPacketMs(packet);
|
||||||
|
|
||||||
if (videoPacket) {
|
if (videoPacket) {
|
||||||
_packetQueue.enqueue(*packet);
|
_packetQueue.enqueue(FFMpeg::dataWrapFromPacket(*packet));
|
||||||
} else if (audioPacket) {
|
} else if (audioPacket) {
|
||||||
// queue packet to audio player
|
// queue packet to audio player
|
||||||
VideoSoundPart part;
|
VideoSoundPart part;
|
||||||
@ -457,18 +458,22 @@ FFMpegReaderImplementation::PacketResult FFMpegReaderImplementation::readAndProc
|
|||||||
|
|
||||||
void FFMpegReaderImplementation::startPacket() {
|
void FFMpegReaderImplementation::startPacket() {
|
||||||
if (!_packetStarted && !_packetQueue.isEmpty()) {
|
if (!_packetStarted && !_packetQueue.isEmpty()) {
|
||||||
_packetStartedSize = _packetQueue.head().size;
|
AVPacket packet;
|
||||||
_packetStartedData = _packetQueue.head().data;
|
FFMpeg::packetFromDataWrap(packet, _packetQueue.head());
|
||||||
|
_packetStartedSize = packet.size;
|
||||||
|
_packetStartedData = packet.data;
|
||||||
_packetStarted = true;
|
_packetStarted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FFMpegReaderImplementation::finishPacket() {
|
void FFMpegReaderImplementation::finishPacket() {
|
||||||
if (_packetStarted) {
|
if (_packetStarted) {
|
||||||
_packetQueue.head().size = _packetStartedSize;
|
AVPacket packet;
|
||||||
_packetQueue.head().data = _packetStartedData;
|
FFMpeg::packetFromDataWrap(packet, _packetQueue.head());
|
||||||
|
packet.size = _packetStartedSize;
|
||||||
|
packet.data = _packetStartedData;
|
||||||
_packetStarted = false;
|
_packetStarted = false;
|
||||||
av_packet_unref(&_packetQueue.head());
|
av_packet_unref(&packet);
|
||||||
_packetQueue.dequeue();
|
_packetQueue.dequeue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -476,7 +481,9 @@ void FFMpegReaderImplementation::finishPacket() {
|
|||||||
void FFMpegReaderImplementation::clearPacketQueue() {
|
void FFMpegReaderImplementation::clearPacketQueue() {
|
||||||
finishPacket();
|
finishPacket();
|
||||||
auto packets = createAndSwap(_packetQueue);
|
auto packets = createAndSwap(_packetQueue);
|
||||||
for (auto &packet : packets) {
|
for (auto &packetData : packets) {
|
||||||
|
AVPacket packet;
|
||||||
|
FFMpeg::packetFromDataWrap(packet, packetData);
|
||||||
av_packet_unref(&packet);
|
av_packet_unref(&packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,13 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <libavcodec/avcodec.h>
|
|
||||||
#include <libavformat/avformat.h>
|
|
||||||
#include <libavutil/opt.h>
|
|
||||||
#include <libswscale/swscale.h>
|
#include <libswscale/swscale.h>
|
||||||
}
|
|
||||||
|
} // extern "C"
|
||||||
|
|
||||||
#include "media/media_clip_implementation.h"
|
#include "media/media_clip_implementation.h"
|
||||||
|
#include "media/media_child_ffmpeg_loader.h"
|
||||||
struct VideoSoundData;
|
|
||||||
|
|
||||||
namespace Media {
|
namespace Media {
|
||||||
namespace Clip {
|
namespace Clip {
|
||||||
@ -96,7 +94,7 @@ private:
|
|||||||
uint64 _playId = 0;
|
uint64 _playId = 0;
|
||||||
int64 _lastReadPacketMs = 0;
|
int64 _lastReadPacketMs = 0;
|
||||||
|
|
||||||
QQueue<AVPacket> _packetQueue;
|
QQueue<FFMpeg::AVPacketDataWrap> _packetQueue;
|
||||||
AVPacket _packetNull; // for final decoding
|
AVPacket _packetNull; // for final decoding
|
||||||
int _packetStartedSize = 0;
|
int _packetStartedSize = 0;
|
||||||
uint8_t *_packetStartedData = nullptr;
|
uint8_t *_packetStartedData = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user