Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qffmpegmuxer.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 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#include "qffmpegmuxer_p.h"
5#include <QtCore/qloggingcategory.h>
6
8
9namespace QFFmpeg {
10
11static Q_LOGGING_CATEGORY(qLcFFmpegMuxer, "qt.multimedia.ffmpeg.muxer");
12
13Muxer::Muxer(RecordingEngine *encoder) : m_encoder(encoder)
14{
16}
17
19{
20 {
21 QMutexLocker locker = lockLoopData();
22 m_packetQueue.push(std::move(packet));
23 }
24
25 // qCDebug(qLcFFmpegEncoder) << "Muxer::addPacket" << packet->pts << packet->stream_index;
26 dataReady();
27}
28
29AVPacketUPtr Muxer::takePacket()
30{
31 QMutexLocker locker = lockLoopData();
32 return dequeueIfPossible(m_packetQueue);
33}
34
36{
37 qCDebug(qLcFFmpegMuxer) << "Muxer::init started thread.";
38}
39
41{
42 while (!m_packetQueue.empty())
43 processOne();
44}
45
47{
48 return !m_packetQueue.empty();
49}
50
52{
53 auto packet = takePacket();
54 // qCDebug(qLcFFmpegEncoder) << "writing packet to file" << packet->pts << packet->duration <<
55 // packet->stream_index;
56
57 // the function takes ownership for the packet
58 av_interleaved_write_frame(m_encoder->avFormatContext(), packet.release());
59}
60
61} // namespace QFFmpeg
62
QMutexLocker< QMutex > lockLoopData() const
Locks the loop data mutex.
void dataReady()
Wake thread from sleep and process data until hasData() returns false.
void cleanup() override
Called on this thread before thread exits.
Muxer(RecordingEngine *encoder)
void init() override
Called on this thread when thread starts.
void processOne() override
Process one work item.
void addPacket(AVPacketUPtr packet)
bool hasData() const override
Must return true when data is available for processing.
\inmodule QtCore
Definition qmutex.h:313
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:127
T dequeueIfPossible(std::queue< T > &queue)
std::unique_ptr< AVPacket, AVDeleter< decltype(&av_packet_free), &av_packet_free > > AVPacketUPtr
Definition qffmpeg_p.h:141
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31