Debian Codegraph @

src/videoframe.hpp

raw
1 /*
2 * This file is part of Bino, a 3D video player.
3 *
4 * Copyright (C) 2022, 2023, 2024, 2025
5 * Martin Lambers <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #pragma once
22
23 #include <QtCore>
24 #include <QVideoFrame>
25 #include <QImage>
26
27 #include "modes.hpp"
28
29
30 class VideoFrame
31 {
32 Q_DECLARE_TR_FUNCTIONS(VideoFrame)
33
34 public:
35 // The pixel data can be represented in one of three ways:
36 // 1. mapped data, via bytesPerLine and mappedBits
37 // 2. copied data, via bytesPerLine and bits
38 // 3. as a fallback: QImage
39 // The QImage fallback is used when the frame pixel format or some other
40 // of its properties cannot be handled in our texture upload / color conversion
41 // pipeline. In that case, we let the frame convert itself to QImage and convert
42 // that to a fallback pixel format that can always be handled.
43 // The mapped data is the preferred option since it is the fastest. On single-process
44 // instances, it is all we need.
45 // The copied data is used to represent mapped data after it has been serialized on the
46 // main process and deserialized on a child process.
47 enum Storage {
48 Storage_Mapped, // mapped data
49 Storage_Copied, // copied data
50 Storage_Image // QImage
51 };
52
53 enum ColorSpace {
54 // see shader-color.frag.glsl
55 CS_BT601 = 1,
56 CS_BT709 = 2,
57 CS_AdobeRgb = 3,
58 CS_BT2020 = 4
59 };
60
61 enum ColorTransfer {
62 // see shader-color.frag.glsl
63 CT_NOOP = 1,
64 CT_ST2084 = 2,
65 CT_STD_B67 = 3
66 };
67
68 /* This is a shallow copy of the original QVideoFrame: */
69 QVideoFrame qframe;
70 /* The input mode of this frame: */
71 InputMode inputMode;
72 /* The surround mode of this frame: */
73 SurroundMode surroundMode;
74 /* The subtitle: */
75 QString subtitle;
76 /* The following can mirror the data of QVideoFrame: */
77 int width;
78 int height;
79 float aspectRatio;
80 enum Storage storage;
81 // for mapped and copied data:
82 QVideoFrameFormat::PixelFormat pixelFormat;
83 bool colorRangeSmall;
84 enum ColorSpace colorSpace;
85 enum ColorTransfer colorTransfer;
86 float masteringWhite;
87 int planeCount; // 1-3
88 int bytesPerLine[3];
89 int bytesPerPlane[3];
90 // for mapped data:
91 uchar* mappedBits[3];
92 // for copied data:
93 std::vector<uchar> bits[3];
94 // for QImage data:
95 QImage image;
96
97 VideoFrame();
98
99 bool isValid() const;
100 void update(InputMode im, SurroundMode ts, const QVideoFrame& frame, bool newSrc);
101 void reUpdate();
102 void invalidate();
103 };
104
105 QDataStream &operator<<(QDataStream& ds, const VideoFrame& frame);
106 QDataStream &operator>>(QDataStream& ds, VideoFrame& frame);