| 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 <QtMultimedia/private/qmaybe_p.h> | 
| 23 | #include <QtCore/qshareddata.h> | 
| 24 |  | 
| 25 | QT_BEGIN_NAMESPACE | 
| 26 |  | 
| 27 | namespace QFFmpeg { | 
| 28 |  | 
| 29 | class CodecContext | 
| 30 | { | 
| 31 |     struct Data : QSharedData | 
| 32 |     { | 
| 33 |         Data(AVCodecContextUPtr context, AVStream *avStream, AVFormatContext *formatContext, | 
| 34 |              std::unique_ptr<QFFmpeg::HWAccel> hwAccel); | 
| 35 |         AVCodecContextUPtr context; | 
| 36 |         AVStream *stream = nullptr; | 
| 37 |         AVFormatContext *formatContext = nullptr; | 
| 38 |         AVRational pixelAspectRatio = { .num: 0, .den: 1 }; | 
| 39 |         std::unique_ptr<QFFmpeg::HWAccel> hwAccel; | 
| 40 |     }; | 
| 41 |  | 
| 42 | public: | 
| 43 |     static QMaybe<CodecContext> create(AVStream *stream, AVFormatContext *formatContext); | 
| 44 |  | 
| 45 |     AVRational pixelAspectRatio(AVFrame *frame) const; | 
| 46 |  | 
| 47 |     AVCodecContext *context() const { return d->context.get(); } | 
| 48 |     AVStream *stream() const { return d->stream; } | 
| 49 |     uint streamIndex() const { return d->stream->index; } | 
| 50 |     HWAccel *hwAccel() const { return d->hwAccel.get(); } | 
| 51 |     TrackDuration toTrackDuration(AVStreamDuration duration) const | 
| 52 |     { | 
| 53 |         return QFFmpeg::toTrackDuration(streamDuration: duration, avStream: d->stream); | 
| 54 |     } | 
| 55 |  | 
| 56 |     TrackPosition toTrackPosition(AVStreamPosition streamPosition) const | 
| 57 |     { | 
| 58 |         return QFFmpeg::toTrackPosition(streamPosition, avStream: d->stream, formatContext: d->formatContext); | 
| 59 |     } | 
| 60 |  | 
| 61 | private: | 
| 62 |     enum VideoCodecCreationPolicy { | 
| 63 |         Hw, | 
| 64 |         Sw, | 
| 65 |     }; | 
| 66 |  | 
| 67 |     static QMaybe<CodecContext> create(AVStream *stream, AVFormatContext *formatContext, | 
| 68 |                                        VideoCodecCreationPolicy videoCodecPolicy); | 
| 69 |     CodecContext(Data *data) : d(data) { } | 
| 70 |     QExplicitlySharedDataPointer<Data> d; | 
| 71 | }; | 
| 72 |  | 
| 73 | } // namespace QFFmpeg | 
| 74 |  | 
| 75 | QT_END_NAMESPACE | 
| 76 |  | 
| 77 | #endif // QFFMPEGCODECCONTEXT_P_H | 
| 78 |  |