| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QFFMPEGCODECCONTEXT_P_H |
| 5 | #define QFFMPEGCODECCONTEXT_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtFFmpegMediaPluginImpl/private/qffmpeg_p.h> |
| 19 | #include <QtFFmpegMediaPluginImpl/private/qffmpeghwaccel_p.h> |
| 20 | #include <QtFFmpegMediaPluginImpl/private/qffmpegtime_p.h> |
| 21 | |
| 22 | #include <QtCore/qshareddata.h> |
| 23 | #include <QtCore/private/qexpected_p.h> |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | class QPlaybackOptions; |
| 28 | |
| 29 | namespace QFFmpeg { |
| 30 | |
| 31 | class CodecContext |
| 32 | { |
| 33 | struct Data : QSharedData |
| 34 | { |
| 35 | Data(AVCodecContextUPtr context, AVStream *avStream, AVFormatContext *formatContext, |
| 36 | std::unique_ptr<QFFmpeg::HWAccel> hwAccel); |
| 37 | AVCodecContextUPtr context; |
| 38 | AVStream *stream = nullptr; |
| 39 | AVFormatContext *formatContext = nullptr; |
| 40 | AVRational pixelAspectRatio = { .num: 0, .den: 1 }; |
| 41 | std::unique_ptr<QFFmpeg::HWAccel> hwAccel; |
| 42 | }; |
| 43 | |
| 44 | public: |
| 45 | static q23::expected<CodecContext, QString> create(AVStream *stream, AVFormatContext *formatContext, |
| 46 | const QPlaybackOptions &options); |
| 47 | |
| 48 | AVRational pixelAspectRatio(AVFrame *frame) const; |
| 49 | |
| 50 | AVCodecContext *context() const { return d->context.get(); } |
| 51 | AVStream *stream() const { return d->stream; } |
| 52 | uint streamIndex() const { return d->stream->index; } |
| 53 | HWAccel *hwAccel() const { return d->hwAccel.get(); } |
| 54 | TrackDuration toTrackDuration(AVStreamDuration duration) const |
| 55 | { |
| 56 | return QFFmpeg::toTrackDuration(streamDuration: duration, avStream: d->stream); |
| 57 | } |
| 58 | |
| 59 | TrackPosition toTrackPosition(AVStreamPosition streamPosition) const |
| 60 | { |
| 61 | return QFFmpeg::toTrackPosition(streamPosition, avStream: d->stream, formatContext: d->formatContext); |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | enum VideoCodecCreationPolicy { |
| 66 | Hw, |
| 67 | Sw, |
| 68 | }; |
| 69 | |
| 70 | static q23::expected<CodecContext, QString> create(AVStream *stream, AVFormatContext *formatContext, |
| 71 | const QPlaybackOptions &playbackOptions, |
| 72 | VideoCodecCreationPolicy videoCodecPolicy); |
| 73 | CodecContext(Data *data) : d(data) { } |
| 74 | QExplicitlySharedDataPointer<Data> d; |
| 75 | }; |
| 76 | |
| 77 | } // namespace QFFmpeg |
| 78 | |
| 79 | QT_END_NAMESPACE |
| 80 | |
| 81 | #endif // QFFMPEGCODECCONTEXT_P_H |
| 82 | |