diff options
Diffstat (limited to 'src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder_p.h')
-rw-r--r-- | src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder_p.h | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder_p.h b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder_p.h new file mode 100644 index 000000000..af57730f2 --- /dev/null +++ b/src/plugins/multimedia/ffmpeg/recordingengine/qffmpegvideoframeencoder_p.h @@ -0,0 +1,93 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#ifndef QFFMPEGVIDEOFRAMEENCODER_P_H +#define QFFMPEGVIDEOFRAMEENCODER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qffmpeghwaccel_p.h" +#include "private/qplatformmediarecorder_p.h" + +QT_BEGIN_NAMESPACE + +class QMediaEncoderSettings; + +namespace QFFmpeg { + +class VideoFrameEncoder +{ +public: + static std::unique_ptr<VideoFrameEncoder> create(const QMediaEncoderSettings &encoderSettings, + const QSize &sourceSize, + QtVideo::Rotation sourceRotation, + qreal sourceFrameRate, + AVPixelFormat sourceFormat, + AVPixelFormat sourceSWFormat, + AVFormatContext *formatContext); + + ~VideoFrameEncoder(); + + bool open(); + + AVPixelFormat sourceFormat() const { return m_sourceFormat; } + AVPixelFormat targetFormat() const { return m_targetFormat; } + + qint64 getPts(qint64 ms) const; + + const AVRational &getTimeBase() const; + + int sendFrame(AVFrameUPtr frame); + AVPacketUPtr retrievePacket(); + + const QMediaEncoderSettings &settings() { return m_settings; } + +private: + VideoFrameEncoder() = default; + + bool updateSourceFormatAndSize(const AVFrame *frame); + + void updateConversions(); + + bool initCodec(); + + bool initTargetFormats(); + + bool initCodecContext(AVFormatContext *formatContext); + +private: + QMediaEncoderSettings m_settings; + QSize m_sourceSize; + QtVideo::Rotation m_sourceRotation = QtVideo::Rotation::None; + + std::unique_ptr<HWAccel> m_accel; + const AVCodec *m_codec = nullptr; + AVStream *m_stream = nullptr; + AVCodecContextUPtr m_codecContext; + std::unique_ptr<SwsContext, decltype(&sws_freeContext)> m_converter = { nullptr, + &sws_freeContext }; + AVPixelFormat m_sourceFormat = AV_PIX_FMT_NONE; + AVPixelFormat m_sourceSWFormat = AV_PIX_FMT_NONE; + AVPixelFormat m_targetFormat = AV_PIX_FMT_NONE; + AVPixelFormat m_targetSWFormat = AV_PIX_FMT_NONE; + bool m_downloadFromHW = false; + bool m_uploadToHW = false; + + AVRational m_codecFrameRate = { 0, 1 }; + + int64_t m_prevPacketDts = AV_NOPTS_VALUE; + int64_t m_packetDtsOffset = 0; +}; +} + +QT_END_NAMESPACE + +#endif |