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 WebP,
40 Gif,
41 };
42 Q_ENUM(Encoder)
43
44 PipeWireBaseEncodedStream(QObject *parent = nullptr);
45 ~PipeWireBaseEncodedStream() override;
46
47 void setNodeId(uint nodeId);
48 uint nodeId() const;
49
50 void setFd(uint fd);
51 uint fd() const;
52
53 Fraction maxFramerate() const;
54 void setMaxFramerate(const Fraction &framerate);
55 void setMaxFramerate(quint32 numerator, quint32 denominator = 1);
56
57 /**
58 * Defines how many frames are kept in the encoding buffer.
59 * New frames after the buffer is full will be dropped.
60 *
61 * This needs to be high enough for intra-frame analysis.
62 * The default value is 50.
63 *
64 * There is a minimum value of 3.
65 */
66 void setMaxPendingFrames(int maxBufferSize);
67 int maxBufferSize() const;
68
69 bool isActive() const;
70 void setActive(bool active);
71
72 /**
73 * The quality used for encoding.
74 */
75 std::optional<quint8> quality() const;
76 /**
77 * Set the quality to use for encoding.
78 *
79 * This uses a range of 0-100 as a percentage, with 0 being lowest quality
80 * and 100 being highest. This is internally converted to a value relevant to
81 * the encoder.
82 *
83 * @param quality The quality level to use.
84 */
85 void setQuality(quint8 quality);
86
87 enum State {
88 Idle, //< ready to get started
89 Recording, //< actively recording
90 Rendering, //< recording is over but there are still frames being processed.
91 };
93 State state() const;
94
95 /**
96 * Set the FFmpeg @p encoder that will be used to create the video
97 *
98 * They can be inspected using:
99 * ffmpeg -encoders | grep "^ V"
100 */
101 void setEncoder(Encoder encoder);
102 Encoder encoder() const;
103
104 /// Returns the encoders that are tested to work, sorted by preference
105 QList<PipeWireBaseEncodedStream::Encoder> suggestedEncoders() const;
106
107 enum EncodingPreference {
108 NoPreference, ///< Default settings, good for most usecases
109 Quality, ///< A bit slower than default, but more consistent bitrate, use for high quality
110 Speed, ///< Encode as fast as possible and use zerolatency tune, good for streaming
111 Size, ///< Slowest encoding but reduces the size of the file
112 };
113 Q_ENUM(EncodingPreference);
114 void setEncodingPreference(EncodingPreference profile);
115
117 void activeChanged(bool active);
118 void nodeIdChanged(uint nodeId);
119 void fdChanged(uint fd);
120 void errorFound(const QString &error);
121 void maxFramerateChanged();
122 void maxPendingFramesChanged();
123 void stateChanged();
124 void encoderChanged();
125
126protected:
127 virtual std::unique_ptr<PipeWireProduce> makeProduce() = 0;
128 EncodingPreference encodingPreference();
129
130 void refresh();
132};
Q_ENUM(...)
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:20 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.