KPipewire

pipewirebaseencodedstream.h
1/*
2 SPDX-FileCopyrightText: 2022 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#pragma once
8
9#include <QObject>
10
11#include <kpipewire_export.h>
12
13struct Fraction;
14struct PipeWireEncodedStreamPrivate;
15class PipeWireProduce;
16
17class KPIPEWIRE_EXPORT PipeWireBaseEncodedStream : public QObject
18{
19 Q_OBJECT
20 /// Specify the pipewire node id that we want to record
21 Q_PROPERTY(uint nodeId READ nodeId WRITE setNodeId NOTIFY nodeIdChanged)
22 /**
23 * Specifies the file descriptor we are connected to, if none 0 will be returned
24 *
25 * Transfers the ownership of the fd, will close it when it's done with it.
26 */
27 Q_PROPERTY(uint fd READ fd WRITE setFd NOTIFY fdChanged)
28 Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
29 Q_PROPERTY(State state READ state NOTIFY stateChanged)
30 Q_PROPERTY(Encoder encoder READ encoder WRITE setEncoder NOTIFY encoderChanged)
31
32public:
33 enum Encoder {
34 NoEncoder,
35 VP8,
36 VP9,
37 H264Main,
38 H264Baseline,
39 };
40 Q_ENUM(Encoder)
41
42 PipeWireBaseEncodedStream(QObject *parent = nullptr);
43 ~PipeWireBaseEncodedStream() override;
44
45 void setNodeId(uint nodeId);
46 uint nodeId() const;
47
48 void setFd(uint fd);
49 uint fd() const;
50
51 Fraction maxFramerate() const;
52 void setMaxFramerate(const Fraction &framerate);
53 void setMaxFramerate(quint32 numerator, quint32 denominator = 1);
54
55 /**
56 * Defines how many frames are kept in the encoding buffer.
57 * New frames after the buffer is full will be dropped.
58 *
59 * This needs to be high enough for intra-frame analysis.
60 * The default value is 50.
61 *
62 * There is a minimum value of 3.
63 */
64 void setMaxPendingFrames(int maxBufferSize);
65 int maxBufferSize() const;
66
67 bool isActive() const;
68 void setActive(bool active);
69
70 /**
71 * The quality used for encoding.
72 */
73 std::optional<quint8> quality() const;
74 /**
75 * Set the quality to use for encoding.
76 *
77 * This uses a range of 0-100 as a percentage, with 0 being lowest quality
78 * and 100 being highest. This is internally converted to a value relevant to
79 * the encoder.
80 *
81 * @param quality The quality level to use.
82 */
83 void setQuality(quint8 quality);
84
85 enum State {
86 Idle, //< ready to get started
87 Recording, //< actively recording
88 Rendering, //< recording is over but there are still frames being processed.
89 };
91 State state() const;
92
93 /**
94 * Set the FFmpeg @p encoder that will be used to create the video
95 *
96 * They can be inspected using:
97 * ffmpeg -encoders | grep "^ V"
98 */
99 void setEncoder(Encoder encoder);
100 Encoder encoder() const;
101
102 /// Returns the encoders that are tested to work, sorted by preference
103 QList<PipeWireBaseEncodedStream::Encoder> suggestedEncoders() const;
104
105 enum EncodingPreference {
106 NoPreference, ///< Default settings, good for most usecases
107 Quality, ///< A bit slower than default, but more consistent bitrate, use for high quality
108 Speed, ///< Encode as fast as possible and use zerolatency tune, good for streaming
109 Size, ///< Slowest encoding but reduces the size of the file
110 };
111 Q_ENUM(EncodingPreference);
112 void setEncodingPreference(EncodingPreference profile);
113
115 void activeChanged(bool active);
116 void nodeIdChanged(uint nodeId);
117 void fdChanged(uint fd);
118 void errorFound(const QString &error);
119 void maxFramerateChanged();
120 void maxPendingFramesChanged();
121 void stateChanged();
122 void encoderChanged();
123
124protected:
125 virtual std::unique_ptr<PipeWireProduce> makeProduce() = 0;
126 EncodingPreference encodingPreference();
127
128 void refresh();
130};
Q_ENUM(...)
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.