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 QFFMPEGCODEC_P_H |
5 | #define QFFMPEGCODEC_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 "qshareddata.h" |
19 | #include "qqueue.h" |
20 | #include "private/qmultimediautils_p.h" |
21 | #include "qffmpeg_p.h" |
22 | #include "qffmpeghwaccel_p.h" |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | namespace QFFmpeg { |
27 | |
28 | class Codec |
29 | { |
30 | struct Data |
31 | { |
32 | Data(AVCodecContextUPtr context, AVStream *stream, AVFormatContext *formatContext, |
33 | std::unique_ptr<QFFmpeg::HWAccel> hwAccel); |
34 | QAtomicInt ref; |
35 | AVCodecContextUPtr context; |
36 | AVStream *stream = nullptr; |
37 | AVRational pixelAspectRatio = { .num: 0, .den: 1 }; |
38 | std::unique_ptr<QFFmpeg::HWAccel> hwAccel; |
39 | }; |
40 | |
41 | public: |
42 | static QMaybe<Codec> create(AVStream *stream, AVFormatContext *formatContext); |
43 | |
44 | AVRational pixelAspectRatio(AVFrame *frame) const; |
45 | |
46 | AVCodecContext *context() const { return d->context.get(); } |
47 | AVStream *stream() const { return d->stream; } |
48 | uint streamIndex() const { return d->stream->index; } |
49 | HWAccel *hwAccel() const { return d->hwAccel.get(); } |
50 | qint64 toMs(qint64 ts) const { return timeStampMs(ts, base: d->stream->time_base).value_or(u: 0); } |
51 | qint64 toUs(qint64 ts) const { return timeStampUs(ts, base: d->stream->time_base).value_or(u: 0); } |
52 | |
53 | private: |
54 | enum VideoCodecCreationPolicy { |
55 | Hw, |
56 | Sw, |
57 | }; |
58 | |
59 | static QMaybe<Codec> create(AVStream *stream, AVFormatContext *formatContext, |
60 | VideoCodecCreationPolicy videoCodecPolicy); |
61 | Codec(Data *data) : d(data) { } |
62 | QExplicitlySharedDataPointer<Data> d; |
63 | }; |
64 | |
65 | } // namespace QFFmpeg |
66 | |
67 | QT_END_NAMESPACE |
68 | |
69 | #endif // QFFMPEGCODEC_P_H |
70 | |