KPipewire

pipewireencodedstream.cpp
1/*
2 SPDX-FileCopyrightText: 2023 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#include "pipewireencodedstream.h"
8#include "pipewireencodedstream_p.h"
9#include "pipewireproduce_p.h"
10#include <QDebug>
11
12extern "C" {
13#include <libavcodec/packet.h>
14}
15
16class PipeWirePacketPrivate
17{
18public:
19 PipeWirePacketPrivate(bool isKey, const QByteArray &data)
20 : isKey(isKey)
21 , data(data)
22 {
23 }
24
25 const bool isKey;
26 const QByteArray data;
27};
28
29PipeWireEncodedStream::Packet::Packet(bool isKey, const QByteArray &data)
30 : d(std::make_shared<PipeWirePacketPrivate>(isKey, data))
31{
32}
33
34QByteArray PipeWireEncodedStream::Packet::data() const
35{
36 return d->data;
37}
38
39bool PipeWireEncodedStream::Packet::isKeyFrame() const
40{
41 return d->isKey;
42}
43
44PipeWireEncodeProduce::PipeWireEncodeProduce(PipeWireBaseEncodedStream::Encoder encoder,
45 uint nodeId,
46 uint fd,
47 const Fraction &framerate,
48 PipeWireEncodedStream *stream)
49 : PipeWireProduce(encoder, nodeId, fd, framerate)
50 , m_encodedStream(stream)
51{
52}
53
54void PipeWireEncodeProduce::processPacket(AVPacket *packet)
55{
56 if (!packet) {
57 return;
58 }
59
60 Q_EMIT newPacket(PipeWireEncodedStream::Packet(packet->flags & AV_PKT_FLAG_KEY, QByteArray(reinterpret_cast<char *>(packet->data), packet->size)));
61}
62
63void PipeWireEncodeProduce::processFrame(const PipeWireFrame &frame)
64{
65 if (m_size != m_stream->size()) {
66 m_size = m_stream->size();
67 Q_EMIT m_encodedStream->sizeChanged(m_size);
68 }
69
70 PipeWireProduce::processFrame(frame);
71 if (frame.cursor && m_cursor != *frame.cursor) {
72 m_cursor = *frame.cursor;
73 Q_EMIT m_encodedStream->cursorChanged(m_cursor);
74 }
75}
76
77PipeWireEncodedStream::PipeWireEncodedStream(QObject *parent)
78 : PipeWireBaseEncodedStream(parent)
79{
80}
81
82PipeWireEncodedStream::~PipeWireEncodedStream() = default;
83
84std::unique_ptr<PipeWireProduce> PipeWireEncodedStream::makeProduce()
85{
86 auto produce = new PipeWireEncodeProduce(encoder(), nodeId(), fd(), maxFramerate(), this);
87 connect(produce, &PipeWireEncodeProduce::newPacket, this, &PipeWireEncodedStream::newPacket);
88 connect(this, &PipeWireEncodedStream::maxFramerateChanged, produce, [this, produce]() {
89 produce->setMaxFramerate(maxFramerate());
90 });
91 return std::unique_ptr<PipeWireProduce>(produce);
92}
93
94#include "moc_pipewireencodedstream_p.cpp"
95
96#include "moc_pipewireencodedstream.cpp"
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
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.